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

Commit 3279bde5 authored by Andreas Huber's avatar Andreas Huber Committed by Android (Google) Code Review
Browse files

Merge "Make sure the prefetcher is actively fetching data if we pause playback...

Merge "Make sure the prefetcher is actively fetching data if we pause playback due to cache underrun."
parents d78b7ad3 34ef0f32
Loading
Loading
Loading
Loading
+11 −0
Original line number Original line Diff line number Diff line
@@ -564,6 +564,12 @@ bool AwesomePlayer::getCachedDuration_l(int64_t *durationUs, bool *eos) {
    return false;
    return false;
}
}


void AwesomePlayer::ensureCacheIsFetching_l() {
    if (mCachedSource != NULL) {
        mCachedSource->resumeFetchingIfNecessary();
    }
}

void AwesomePlayer::onBufferingUpdate() {
void AwesomePlayer::onBufferingUpdate() {
    Mutex::Autolock autoLock(mLock);
    Mutex::Autolock autoLock(mLock);
    if (!mBufferingEventPending) {
    if (!mBufferingEventPending) {
@@ -606,6 +612,7 @@ void AwesomePlayer::onBufferingUpdate() {
                         kLowWaterMarkBytes);
                         kLowWaterMarkBytes);
                    mFlags |= CACHE_UNDERRUN;
                    mFlags |= CACHE_UNDERRUN;
                    pause_l();
                    pause_l();
                    ensureCacheIsFetching_l();
                    notifyListener_l(MEDIA_INFO, MEDIA_INFO_BUFFERING_START);
                    notifyListener_l(MEDIA_INFO, MEDIA_INFO_BUFFERING_START);
                } else if (eos || cachedDataRemaining > kHighWaterMarkBytes) {
                } else if (eos || cachedDataRemaining > kHighWaterMarkBytes) {
                    if (mFlags & CACHE_UNDERRUN) {
                    if (mFlags & CACHE_UNDERRUN) {
@@ -627,12 +634,16 @@ void AwesomePlayer::onBufferingUpdate() {
    int64_t cachedDurationUs;
    int64_t cachedDurationUs;
    bool eos;
    bool eos;
    if (getCachedDuration_l(&cachedDurationUs, &eos)) {
    if (getCachedDuration_l(&cachedDurationUs, &eos)) {
        LOGV("cachedDurationUs = %.2f secs, eos=%d",
             cachedDurationUs / 1E6, eos);

        if ((mFlags & PLAYING) && !eos
        if ((mFlags & PLAYING) && !eos
                && (cachedDurationUs < kLowWaterMarkUs)) {
                && (cachedDurationUs < kLowWaterMarkUs)) {
            LOGI("cache is running low (%.2f secs) , pausing.",
            LOGI("cache is running low (%.2f secs) , pausing.",
                 cachedDurationUs / 1E6);
                 cachedDurationUs / 1E6);
            mFlags |= CACHE_UNDERRUN;
            mFlags |= CACHE_UNDERRUN;
            pause_l();
            pause_l();
            ensureCacheIsFetching_l();
            notifyListener_l(MEDIA_INFO, MEDIA_INFO_BUFFERING_START);
            notifyListener_l(MEDIA_INFO, MEDIA_INFO_BUFFERING_START);
        } else if (eos || cachedDurationUs > kHighWaterMarkUs) {
        } else if (eos || cachedDurationUs > kHighWaterMarkUs) {
            if (mFlags & CACHE_UNDERRUN) {
            if (mFlags & CACHE_UNDERRUN) {
+11 −3
Original line number Original line Diff line number Diff line
@@ -325,14 +325,16 @@ void NuCachedSource2::onRead(const sp<AMessage> &msg) {
    mCondition.signal();
    mCondition.signal();
}
}


void NuCachedSource2::restartPrefetcherIfNecessary_l() {
void NuCachedSource2::restartPrefetcherIfNecessary_l(
        bool ignoreLowWaterThreshold) {
    static const size_t kGrayArea = 256 * 1024;
    static const size_t kGrayArea = 256 * 1024;


    if (mFetching || mFinalStatus != OK) {
    if (mFetching || mFinalStatus != OK) {
        return;
        return;
    }
    }


    if (mCacheOffset + mCache->totalSize() - mLastAccessPos
    if (!ignoreLowWaterThreshold
            && mCacheOffset + mCache->totalSize() - mLastAccessPos
                >= kLowWaterThreshold) {
                >= kLowWaterThreshold) {
        return;
        return;
    }
    }
@@ -510,6 +512,12 @@ void NuCachedSource2::onSuspend() {
    mSuspended = true;
    mSuspended = true;
}
}


void NuCachedSource2::resumeFetchingIfNecessary() {
    Mutex::Autolock autoLock(mLock);

    restartPrefetcherIfNecessary_l(true /* ignore low water threshold */);
}

DecryptHandle* NuCachedSource2::DrmInitialization(DrmManagerClient* client) {
DecryptHandle* NuCachedSource2::DrmInitialization(DrmManagerClient* client) {
    return mSource->DrmInitialization(client);
    return mSource->DrmInitialization(client);
}
}
+1 −0
Original line number Original line Diff line number Diff line
@@ -274,6 +274,7 @@ private:
    bool getBitrate(int64_t *bitrate);
    bool getBitrate(int64_t *bitrate);


    void finishSeekIfNecessary(int64_t videoTimeUs);
    void finishSeekIfNecessary(int64_t videoTimeUs);
    void ensureCacheIsFetching_l();


    AwesomePlayer(const AwesomePlayer &);
    AwesomePlayer(const AwesomePlayer &);
    AwesomePlayer &operator=(const AwesomePlayer &);
    AwesomePlayer &operator=(const AwesomePlayer &);
+3 −1
Original line number Original line Diff line number Diff line
@@ -47,6 +47,8 @@ struct NuCachedSource2 : public DataSource {
    void suspend();
    void suspend();
    void clearCacheAndResume();
    void clearCacheAndResume();


    void resumeFetchingIfNecessary();

protected:
protected:
    virtual ~NuCachedSource2();
    virtual ~NuCachedSource2();


@@ -96,7 +98,7 @@ private:
    status_t seekInternal_l(off_t offset);
    status_t seekInternal_l(off_t offset);


    size_t approxDataRemaining_l(bool *eos);
    size_t approxDataRemaining_l(bool *eos);
    void restartPrefetcherIfNecessary_l();
    void restartPrefetcherIfNecessary_l(bool ignoreLowWaterThreshold = false);


    DISALLOW_EVIL_CONSTRUCTORS(NuCachedSource2);
    DISALLOW_EVIL_CONSTRUCTORS(NuCachedSource2);
};
};