Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 19642c3b authored by Vikash Garodia's avatar Vikash Garodia Committed by Steve Kondik
Browse files

libstagefright: Customize AV sync behavior

Based on the property, whenever video decoder takes more time
for decoding and causing few consecutive frame drops to maintain
the AV sync, then disable AV sync till it recovers.

This change will avoid freeze whenever any video clips out side
of the supported spec are being played though audio and video
are out of sync.
This improves user experience

Change-Id: Ia4ee899ff2515684259b88f66af216871a7bd38c
parent 64434025
Loading
Loading
Loading
Loading
+31 −2
Original line number Diff line number Diff line
@@ -235,7 +235,8 @@ AwesomePlayer::AwesomePlayer()
      mOffloadAudio(false),
      mAudioTearDown(false),
      mReadRetry(false),
      mIsFirstFrameAfterResume(false) {
      mIsFirstFrameAfterResume(false),
      mCustomAVSync(false) {
    CHECK_EQ(mClient.connect(), (status_t)OK);

    DataSource::RegisterDefaultSniffers();
@@ -270,6 +271,7 @@ AwesomePlayer::AwesomePlayer()

#ifdef QCOM_HARDWARE
    mLateAVSyncMargin = ExtendedUtils::ShellProp::getMaxAVSyncLateMargin();
    mCustomAVSync = ExtendedUtils::ShellProp::isCustomAVSyncEnabled();
#else
    mLateAVSyncMargin = 40000;
#endif
@@ -2271,6 +2273,22 @@ void AwesomePlayer::onVideoEvent() {
                continue;
            }

#ifdef QCOM_HARDWARE
            if (mCustomAVSync) {
                int width = 0;
                int height = 0;
                sp<MetaData> meta = mVideoSource->getFormat();
                CHECK(meta->findInt32(kKeyWidth, &width));
                CHECK(meta->findInt32(kKeyHeight, &height));

                if (((height * width) >= (720 * 1280)) && (mStats.mConsecutiveFramesDropped >= 5) && !(mFlags & NO_AVSYNC))
                {
                    ALOGE("DISABLED AVSync as there are 5 consecutive frame drops");
                    modifyFlags(NO_AVSYNC,SET);
                }
            }
#endif

            break;
        }

@@ -2410,13 +2428,24 @@ void AwesomePlayer::onVideoEvent() {
            }
        }

#ifdef QCOM_HARDWARE
        if ((latenessUs < mLateAVSyncMargin) && (mFlags & NO_AVSYNC))
        {
            ALOGE("ENABLED AVSync as the video frames are intime with audio");
            modifyFlags(NO_AVSYNC,CLEAR);
        }
#endif

        if (latenessUs > mLateAVSyncMargin) {
            // We're more than 40ms late.
            ALOGV("we're late by %lld us (%.2f secs)",
                 latenessUs, latenessUs / 1E6);

            if ((!(mFlags & SLOW_DECODER_HACK)
                    || mSinceLastDropped > FRAME_DROP_FREQ)
                    || (mSinceLastDropped > FRAME_DROP_FREQ))
#ifdef QCOM_HARDWARE
                    && !(mFlags & NO_AVSYNC)
#endif
                    && !mDropFramesDisable)
            {
                ALOGV("we're late by %lld us (%.2f secs) dropping "
+13 −0
Original line number Diff line number Diff line
@@ -248,6 +248,15 @@ bool ExtendedUtils::ShellProp::isSmoothStreamingEnabled() {
    return false;
}

bool ExtendedUtils::ShellProp::isCustomAVSyncEnabled() {
    char prop[PROPERTY_VALUE_MAX] = {0};
    property_get("mm.enable.customavsync", prop, "0");
    if (!strncmp(prop, "true", 4) || atoi(prop)) {
        return true;
    }
    return false;
}

void ExtendedUtils::setBFrames(
        OMX_VIDEO_PARAM_MPEG4TYPE &mpeg4type, int32_t &numBFrames,
        const char* componentName) {
@@ -703,6 +712,10 @@ bool ExtendedUtils::ShellProp::isSmoothStreamingEnabled() {
    return false;
}

bool ExtendedUtils::ShellProp::isCustomAVSyncEnabled() {
    return false;
}

void ExtendedUtils::setBFrames(
        OMX_VIDEO_PARAM_MPEG4TYPE &mpeg4type, int32_t &numBFrames,
        const char* componentName) {
+3 −0
Original line number Diff line number Diff line
@@ -146,6 +146,8 @@ private:
        TEXTPLAYER_INITIALIZED  = 0x20000,

        SLOW_DECODER_HACK   = 0x40000,

        NO_AVSYNC   = 0x80000,
    };

    mutable Mutex mLock;
@@ -410,6 +412,7 @@ private:
    AwesomePlayer(const AwesomePlayer &);
    AwesomePlayer &operator=(const AwesomePlayer &);
    bool mReadRetry;
    bool mCustomAVSync;
};

}  // namespace android
+2 −0
Original line number Diff line number Diff line
@@ -100,6 +100,8 @@ struct ExtendedUtils {
        static bool isSmoothStreamingEnabled();

        static int64_t getMaxAVSyncLateMargin();

        static bool isCustomAVSyncEnabled();
    };

    //set B frames for MPEG4