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

Commit b7b23d3c authored by Andy Hung's avatar Andy Hung Committed by Android (Google) Code Review
Browse files

Merge "NuPlayerRenderer: Do not deliver audio too soon after stop"

parents e3318f94 b03dcb34
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -107,6 +107,7 @@ NuPlayer::Renderer::Renderer(
      mNotifyCompleteVideo(false),
      mSyncQueues(false),
      mPaused(false),
      mPauseDrainAudioAllowedUs(0),
      mVideoSampleReceived(false),
      mVideoRenderingStarted(false),
      mVideoRenderingStartGeneration(0),
@@ -645,6 +646,14 @@ void NuPlayer::Renderer::postDrainAudioQueue_l(int64_t delayUs) {
        return;
    }

    // FIXME: if paused, wait until AudioTrack stop() is complete before delivering data.
    if (mPaused) {
        const int64_t diffUs = mPauseDrainAudioAllowedUs - ALooper::GetNowUs();
        if (diffUs > delayUs) {
            delayUs = diffUs;
        }
    }

    mDrainAudioQueuePending = true;
    sp<AMessage> msg = new AMessage(kWhatDrainAudioQueue, this);
    msg->setInt32("drainGeneration", mAudioDrainGeneration);
@@ -1371,8 +1380,16 @@ void NuPlayer::Renderer::onFlush(const sp<AMessage> &msg) {
            mAudioSink->flush();
            // Call stop() to signal to the AudioSink to completely fill the
            // internal buffer before resuming playback.
            // FIXME: this is ignored after flush().
            mAudioSink->stop();
            if (!mPaused) {
            if (mPaused) {
                // Race condition: if renderer is paused and audio sink is stopped,
                // we need to make sure that the audio track buffer fully drains
                // before delivering data.
                // FIXME: remove this if we can detect if stop() is complete.
                const int delayUs = 2 * 50 * 1000; // (2 full mixer thread cycles at 50ms)
                mPauseDrainAudioAllowedUs = ALooper::GetNowUs() + delayUs;
            } else {
                mAudioSink->start();
            }
            mNumFramesWritten = 0;
+1 −0
Original line number Diff line number Diff line
@@ -171,6 +171,7 @@ private:

    // modified on only renderer's thread.
    bool mPaused;
    int64_t mPauseDrainAudioAllowedUs; // time when we can drain/deliver audio in pause mode.

    bool mVideoSampleReceived;
    bool mVideoRenderingStarted;