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

Commit 1b09ce9b authored by ApurupaPattapu's avatar ApurupaPattapu Committed by Steve Kondik
Browse files

libstagefright: HTTP Streaming fixes



- Stop fetching on reaching EOS
- Disconnect datasource in player's reset
- Send buffering complete when seek is issued
  when player is in buffering state

Change-Id: If1650f02ffda10e0d8ca4a9c7fd0a5681d05e75e
Signed-off-by: default avatarjmeng <jmeng@codeaurora.org>
parent c10acef3
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -219,7 +219,8 @@ AwesomePlayer::AwesomePlayer()
      mLastVideoTimeUs(-1),
      mFrameDurationUs(kInitFrameDurationUs),
      mTextDriver(NULL),
      mIsFirstFrameAfterResume(false) {
      mIsFirstFrameAfterResume(false),
      mBufferingDone(false) {
    CHECK_EQ(mClient.connect(), (status_t)OK);

    DataSource::RegisterDefaultSniffers();
@@ -561,6 +562,9 @@ status_t AwesomePlayer::setDataSource_l(const sp<MediaExtractor> &extractor) {

void AwesomePlayer::reset() {
    Mutex::Autolock autoLock(mLock);
    if (mConnectingDataSource != NULL) {
        mConnectingDataSource->disconnect();
    }
    reset_l();
}

@@ -788,6 +792,8 @@ void AwesomePlayer::onBufferingUpdate() {

        if (eos) {
            if (finalStatus == ERROR_END_OF_STREAM) {
                ALOGV("End of Streaming, EOS Reached, Buffering is at 100 percent");
                mBufferingDone = true;
                notifyListener_l(MEDIA_BUFFERING_UPDATE, 100);
            }
            if (mFlags & PREPARING) {
@@ -803,6 +809,8 @@ void AwesomePlayer::onBufferingUpdate() {
                int percentage = 100.0 * (double)cachedDurationUs / mDurationUs;
                if (percentage > 100) {
                    percentage = 100;
                    ALOGV("Cache at 100%, Buffering Done ");
                    mBufferingDone = true;
                }

                notifyListener_l(MEDIA_BUFFERING_UPDATE, percentage);
@@ -844,6 +852,7 @@ void AwesomePlayer::onBufferingUpdate() {
        if (eos) {
            if (finalStatus == ERROR_END_OF_STREAM) {
                notifyListener_l(MEDIA_BUFFERING_UPDATE, 100);
                mBufferingDone = true;
            }
            if (mFlags & PREPARING) {
                ALOGV("cache has reached EOS, prepare is done.");
@@ -853,6 +862,7 @@ void AwesomePlayer::onBufferingUpdate() {
            int percentage = 100.0 * (double)cachedDurationUs / mDurationUs;
            if (percentage > 100) {
                percentage = 100;
                mBufferingDone = true;
            }

            notifyListener_l(MEDIA_BUFFERING_UPDATE, percentage);
@@ -888,8 +898,10 @@ void AwesomePlayer::onBufferingUpdate() {
        }
    }

    if (!mBufferingDone) {
        postBufferingEvent_l();
    }
}

void AwesomePlayer::sendCacheStats() {
    sp<MediaPlayerBase> listener = mListener.promote();
@@ -1535,6 +1547,7 @@ status_t AwesomePlayer::seekTo_l(int64_t timeUs) {
    if (mFlags & CACHE_UNDERRUN) {
        modifyFlags(CACHE_UNDERRUN, CLEAR);
        play_l();
        notifyListener_l(MEDIA_INFO, MEDIA_INFO_BUFFERING_END);
    }

    if ((mFlags & PLAYING) && mVideoSource != NULL && (mFlags & VIDEO_AT_EOS)) {
+16 −2
Original line number Diff line number Diff line
@@ -194,7 +194,8 @@ NuCachedSource2::NuCachedSource2(
      mHighwaterThresholdBytes(kDefaultHighWaterThreshold),
      mLowwaterThresholdBytes(kDefaultLowWaterThreshold),
      mKeepAliveIntervalUs(kDefaultKeepAliveIntervalUs),
      mDisconnectAtHighwatermark(disconnectAtHighwatermark) {
      mDisconnectAtHighwatermark(disconnectAtHighwatermark),
      mIsDownloadComplete(false) {
    // We are NOT going to support disconnect-at-highwatermark indefinitely
    // and we are not guaranteeing support for client-specified cache
    // parameters. Both of these are temporary measures to solve a specific
@@ -353,6 +354,7 @@ void NuCachedSource2::onFetch() {
    if (mFinalStatus != OK && mNumRetriesLeft == 0) {
        ALOGV("EOS reached, done prefetching for now");
        mFetching = false;
        mIsDownloadComplete = true;
    }

    bool keepAlive =
@@ -394,9 +396,13 @@ void NuCachedSource2::onFetch() {
        } else {
            delayUs = 0;
        }
    } else {
        if(mIsDownloadComplete) {
            return;
        } else {
            delayUs = 100000ll;
        }
    }

    (new AMessage(kWhatFetchMore, mReflector->id()))->post(delayUs);
}
@@ -542,6 +548,10 @@ ssize_t NuCachedSource2::readInternal(off64_t offset, void *data, size_t size) {
                false, // ignoreLowWaterThreshold
                true); // force
    }
    if (mFetching && mIsDownloadComplete) {
        mIsDownloadComplete = false;
        (new AMessage(kWhatFetchMore, mReflector->id()))->post();
    }

    if (offset < mCacheOffset
            || offset >= (off64_t)(mCacheOffset + mCache->totalSize())) {
@@ -610,6 +620,10 @@ void NuCachedSource2::resumeFetchingIfNecessary() {
    Mutex::Autolock autoLock(mLock);

    restartPrefetcherIfNecessary_l(true /* ignore low water threshold */);
    if(mFetching && mIsDownloadComplete) {
        mIsDownloadComplete = false;
        (new AMessage(kWhatFetchMore, mReflector->id()))->post();
    }
}

sp<DecryptHandle> NuCachedSource2::DrmInitialization(const char* mime) {
+2 −0
Original line number Diff line number Diff line
@@ -366,6 +366,8 @@ private:
        int64_t mSeekDelayStartUs;
    } mStats;

    bool mBufferingDone;

    status_t setVideoScalingMode(int32_t mode);
    status_t setVideoScalingMode_l(int32_t mode);
    status_t getTrackInfo(Parcel* reply) const;
+2 −0
Original line number Diff line number Diff line
@@ -115,6 +115,8 @@ private:

    bool mDisconnectAtHighwatermark;

    bool mIsDownloadComplete;

    void onMessageReceived(const sp<AMessage> &msg);
    void onFetch();
    void onRead(const sp<AMessage> &msg);