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

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

Merge "Ensure that buffering updates eventually hit 100% after we download...

Merge "Ensure that buffering updates eventually hit 100% after we download everything." into gingerbread
parents d64f4a98 c23296ef
Loading
Loading
Loading
Loading
+19 −12
Original line number Diff line number Diff line
@@ -458,9 +458,15 @@ void AwesomePlayer::onBufferingUpdate() {
        return;
    }

    bool eos;
    size_t cachedDataRemaining = mCachedSource->approxDataRemaining(&eos);

    size_t lowWatermark = 400000;
    size_t highWatermark = 1000000;

    if (eos) {
        notifyListener_l(MEDIA_BUFFERING_UPDATE, 100);
    } else {
        off_t size;
        if (mDurationUs >= 0 && mCachedSource->getSize(&size) == OK) {
            int64_t bitrate = size * 8000000ll / mDurationUs;  // in bits/sec
@@ -468,16 +474,17 @@ void AwesomePlayer::onBufferingUpdate() {
            size_t cachedSize = mCachedSource->cachedSize();
            int64_t cachedDurationUs = cachedSize * 8000000ll / bitrate;

        double percentage = (double)cachedDurationUs / mDurationUs;
            int percentage = 100.0 * (double)cachedDurationUs / mDurationUs;
            if (percentage > 100) {
                percentage = 100;
            }

        notifyListener_l(MEDIA_BUFFERING_UPDATE, percentage * 100.0);
            notifyListener_l(MEDIA_BUFFERING_UPDATE, percentage);

            lowWatermark = 2 * bitrate / 8;  // 2 secs
            highWatermark = 10 * bitrate / 8;  // 10 secs
        }

    bool eos;
    size_t cachedDataRemaining = mCachedSource->approxDataRemaining(&eos);
    }

    if ((mFlags & PLAYING) && !eos && (cachedDataRemaining < lowWatermark)) {
        LOGI("cache is running low (< %d) , pausing.", lowWatermark);