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

Commit 0c6fcd90 authored by Deva Ramasubramanian's avatar Deva Ramasubramanian Committed by Steve Kondik
Browse files

libstagefright: Add support for files with short audio track and long

video track

- As is, if the audio track is shorter than the video track then
  playback ends when the audio track ends.  This change allows for the
  playback to continue until the video track ends as well.
- The inverse situation with the video track being shorter than the audio
  track is not supported by this change.

Change-Id: I146edb6e1ad1816fe6375d58b86375c88f685b93
CRs-Fixed: 255410
parent fd00237c
Loading
Loading
Loading
Loading
+33 −5
Original line number Diff line number Diff line
@@ -181,6 +181,11 @@ void AwesomeLocalRenderer::init(
AwesomePlayer::AwesomePlayer()
    : mQueueStarted(false),
      mTimeSource(NULL),
      mFallbackTimeSource(NULL),
      mAudioEOSOccurred(false),
      mVideoEOSOccurred(false),
      mVideoDurationUs(0),
      mAudioDurationUs(0),
      mVideoRendererIsPreview(false),
      mAudioPlayer(NULL),
      mFlags(0),
@@ -364,7 +369,9 @@ void AwesomePlayer::reset_l() {
    if (mTimeSource != mAudioPlayer) {
        delete mTimeSource;
    }
    mTimeSource = NULL;
    delete mFallbackTimeSource;

    mTimeSource = mFallbackTimeSource = NULL;

    delete mAudioPlayer;
    mAudioPlayer = NULL;
@@ -533,7 +540,9 @@ status_t AwesomePlayer::play_l() {
                }

                delete mTimeSource;
                delete mFallbackTimeSource;
                mTimeSource = mAudioPlayer;
                mFallbackTimeSource = new SystemTimeSource;

                deferredAudioSeek = true;

@@ -549,6 +558,12 @@ status_t AwesomePlayer::play_l() {

    if (mTimeSource == NULL && mAudioPlayer == NULL) {
        mTimeSource = new SystemTimeSource;
        /*
            Fallback timer isn't needed because for video only clip
            we don't need to worry about audio ending early or the
            system timer not being available
        */
        mFallbackTimeSource = NULL;
    }

    if (mVideoSource != NULL) {
@@ -709,6 +724,15 @@ status_t AwesomePlayer::seekTo_l(int64_t timeUs) {

    seekAudioIfNecessary_l();

    //Reset the Audio EOS occurred flag unless
    //we are still past the EOS even after the seek
    if (timeUs < mAudioDurationUs)
        mAudioEOSOccurred = false;

    //Ditto for Video EOS
    if (timeUs < mVideoDurationUs)
        mVideoEOSOccurred = false;

    if (!(mFlags & PLAYING)) {
        LOGV("seeking while paused, sending SEEK_COMPLETE notification"
             " immediately.");
@@ -723,7 +747,6 @@ status_t AwesomePlayer::seekTo_l(int64_t timeUs) {
void AwesomePlayer::seekAudioIfNecessary_l() {
    if (mSeeking && mVideoSource == NULL && mAudioPlayer != NULL) {
        mAudioPlayer->seekTo(mSeekTimeUs);

        mWatchForAudioSeekComplete = true;
        mWatchForAudioEOS = true;
        mSeekNotificationSent = false;
@@ -776,6 +799,7 @@ status_t AwesomePlayer::initAudioDecoder() {
            if (mDurationUs < 0 || durationUs > mDurationUs) {
                mDurationUs = durationUs;
            }
            mAudioDurationUs = durationUs;
        }

        status_t err = mAudioSource->start();
@@ -817,6 +841,7 @@ status_t AwesomePlayer::initVideoDecoder() {
            if (mDurationUs < 0 || durationUs > mDurationUs) {
                mDurationUs = durationUs;
            }
            mVideoDurationUs = durationUs;
        }

        CHECK(mVideoTrack->getFormat()->findInt32(kKeyWidth, &mVideoWidth));
@@ -923,7 +948,6 @@ void AwesomePlayer::onVideoEvent() {

    if (mFlags & FIRST_FRAME) {
        mFlags &= ~FIRST_FRAME;

        mTimeSourceDeltaUs = mTimeSource->getRealTimeUs() - timeUs;
    }

@@ -933,7 +957,8 @@ void AwesomePlayer::onVideoEvent() {
        mTimeSourceDeltaUs = realTimeUs - mediaTimeUs;
    }

    int64_t nowUs = mTimeSource->getRealTimeUs() - mTimeSourceDeltaUs;
    int64_t nowUs = (mAudioEOSOccurred ? mFallbackTimeSource : mTimeSource)->getRealTimeUs() - mTimeSourceDeltaUs;
    LOGV("using %s timesource", mAudioEOSOccurred ? "fallback" : "original");

    int64_t latenessUs = nowUs - timeUs;

@@ -1038,6 +1063,9 @@ void AwesomePlayer::onCheckAudioStatus() {
    status_t finalStatus;
    if (mWatchForAudioEOS && mAudioPlayer->reachedEOS(&finalStatus)) {
        mWatchForAudioEOS = false;
        mAudioEOSOccurred = true;

        if (mVideoEOSOccurred || mVideoSource == NULL)
            postStreamDoneEvent_l(finalStatus);
    }

+15 −1
Original line number Diff line number Diff line
@@ -111,7 +111,7 @@ private:
    sp<ISurface> mISurface;
    sp<MediaPlayerBase::AudioSink> mAudioSink;

    TimeSource *mTimeSource;
    TimeSource *mTimeSource, *mFallbackTimeSource;

    String8 mUri;
    KeyedVector<String8, String8> mUriHeaders;
@@ -127,6 +127,17 @@ private:
    sp<MediaSource> mAudioSource;
    AudioPlayer *mAudioPlayer;
    int64_t mDurationUs;
    /*
       The below two members are needed in case
       that the length of the audio track isn't
       the same as the length of the video track.
       We need to know (for seeking and a/v syncing)
       at what point the shorter track has ended.
       mDurationUs (and by extension getDuration())
       returns the larger duration of the two tracks.
    */
    int64_t mAudioDurationUs, mVideoDurationUs;


    uint32_t mFlags;
    uint32_t mExtractorFlags;
@@ -142,6 +153,9 @@ private:
    bool mWatchForAudioSeekComplete;
    bool mWatchForAudioEOS;

    bool mAudioEOSOccurred;
    bool mVideoEOSOccurred; //not used for now

    sp<TimedEventQueue::Event> mVideoEvent;
    bool mVideoEventPending;
    sp<TimedEventQueue::Event> mStreamDoneEvent;