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

Commit ec397549 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "NuPlayer: Implement pre-roll for poor network conditions"

parents 8f69004a 66d85472
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -546,10 +546,12 @@ void NuPlayer::GenericSource::cancelPollBuffering() {
    ++mPollBufferingGeneration;
}

void NuPlayer::GenericSource::notifyBufferingUpdate(int percentage) {
void NuPlayer::GenericSource::notifyBufferingUpdate(int percentage,
        int64_t durationUs) {
    sp<AMessage> msg = dupNotify();
    msg->setInt32("what", kWhatBufferingUpdate);
    msg->setInt32("percentage", percentage);
    msg->setInt64("duration", durationUs);
    msg->post();
}

@@ -579,7 +581,7 @@ void NuPlayer::GenericSource::onPollBuffering() {
    }

    if (finalStatus == ERROR_END_OF_STREAM) {
        notifyBufferingUpdate(100);
        notifyBufferingUpdate(100, 0);
        cancelPollBuffering();
        return;
    } else if (cachedDurationUs > 0ll && mDurationUs > 0ll) {
@@ -588,7 +590,7 @@ void NuPlayer::GenericSource::onPollBuffering() {
            percentage = 100;
        }

        notifyBufferingUpdate(percentage);
        notifyBufferingUpdate(percentage, cachedDurationUs);
    }

    schedulePollBuffering();
+1 −1
Original line number Diff line number Diff line
@@ -191,7 +191,7 @@ private:
    void schedulePollBuffering();
    void cancelPollBuffering();
    void onPollBuffering();
    void notifyBufferingUpdate(int percentage);
    void notifyBufferingUpdate(int percentage, int64_t durationUs);

    DISALLOW_EVIL_CONSTRUCTORS(GenericSource);
};
+31 −1
Original line number Diff line number Diff line
@@ -51,6 +51,9 @@

namespace android {

static int64_t kLowWaterMarkUs = 2000000ll;  // 2secs
static int64_t kHighWaterMarkUs = 5000000ll;  // 5secs

// TODO optimize buffer size for power consumption
// The offload read buffer size is 32 KB but 24 KB uses less power.
const size_t NuPlayer::kAggregateBufferSizeBytes = 24 * 1024;
@@ -172,7 +175,9 @@ NuPlayer::NuPlayer()
      mNumFramesTotal(0ll),
      mNumFramesDropped(0ll),
      mVideoScalingMode(NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW),
      mStarted(false) {
      mStarted(false),
      mBuffering(false),
      mPlaying(false) {

    clearFlushComplete();
    mPlayerExtendedStats = (PlayerExtendedStats *)ExtendedStats::Create(
@@ -675,6 +680,7 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
            }

            postScanSources();
            mPlaying = true;
            break;
        }

@@ -1027,6 +1033,7 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
                ALOGW("pause called when renderer is gone or not set");
            }
            PLAYER_STATS(profileStop, STATS_PROFILE_PAUSE);
            mPlaying = false;
            break;
        }

@@ -1047,6 +1054,7 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
            } else {
                ALOGW("resume called when renderer is gone or not set");
            }
            mPlaying = true;
            break;
        }

@@ -1930,6 +1938,8 @@ void NuPlayer::performReset() {
    }

    mStarted = false;
    mBuffering = false;
    mPlaying = false;
    PLAYER_STATS(notifyEOS);
    PLAYER_STATS(dump);
    PLAYER_STATS(reset);
@@ -2032,6 +2042,26 @@ void NuPlayer::onSourceNotify(const sp<AMessage> &msg) {
            int32_t percentage;
            CHECK(msg->findInt32("percentage", &percentage));

            int64_t durationUs = 0;
            msg->findInt64("duration", &durationUs);

            bool eos = mVideoEOS || mAudioEOS
                    || percentage == 100; // sources return 100% after EOS
            if (durationUs < kLowWaterMarkUs && mPlaying && !eos) {
                mBuffering = true;
                pause();
                notifyListener(MEDIA_INFO, MEDIA_INFO_BUFFERING_START, 0);
                ALOGI("cache running low (< %g secs)..pausing",
                        (double)durationUs / 1000000.0);
            } else if (eos || durationUs > kHighWaterMarkUs) {
                if (mBuffering && !mPlaying) {
                    resume();
                    ALOGI("cache has filled up..resuming");
                }
                notifyListener(MEDIA_INFO, MEDIA_INFO_BUFFERING_END, 0);
                mBuffering = false;
            }

            notifyListener(MEDIA_BUFFERING_UPDATE, percentage, 0);
            break;
        }
+2 −0
Original line number Diff line number Diff line
@@ -196,6 +196,8 @@ private:
    int32_t mVideoScalingMode;

    bool mStarted;
    bool mBuffering;
    bool mPlaying;

    inline const sp<Decoder> &getDecoder(bool audio) {
        return audio ? mAudioDecoder : mVideoDecoder;