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

Commit 3a90ac19 authored by Wei Jia's avatar Wei Jia Committed by android-build-merger
Browse files

Merge "NuPlayer: allow audio tear down to restart with non-offload mode." into nyc-dev

am: eb130ab1

* commit 'eb130ab1':
  NuPlayer: allow audio tear down to restart with non-offload mode.

Change-Id: I635fdc421173d5ecc0a374736a7b18f9377c99ee
parents f834ca5e eb130ab1
Loading
Loading
Loading
Loading
+13 −8
Original line number Diff line number Diff line
@@ -1150,8 +1150,8 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) {
                }

                restartAudio(
                        positionUs, false /* forceNonOffload */,
                        reason == Renderer::kDueToError /* needsToCreateAudioDecoder */);
                        positionUs, reason == Renderer::kForceNonOffload /* forceNonOffload */,
                        reason != Renderer::kDueToTimeout /* needsToCreateAudioDecoder */);
            }
            break;
        }
@@ -1490,9 +1490,11 @@ void NuPlayer::closeAudioSink() {

void NuPlayer::restartAudio(
        int64_t currentPositionUs, bool forceNonOffload, bool needsToCreateAudioDecoder) {
    if (mAudioDecoder != NULL) {
        mAudioDecoder->pause();
        mAudioDecoder.clear();
        ++mAudioDecoderGeneration;
    }
    if (mFlushingAudio == FLUSHING_DECODER) {
        mFlushComplete[1 /* audio */][1 /* isDecoder */] = true;
        mFlushingAudio = FLUSHED;
@@ -1520,7 +1522,7 @@ void NuPlayer::restartAudio(
        mOffloadAudio = false;
    }
    if (needsToCreateAudioDecoder) {
        instantiateDecoder(true /* audio */, &mAudioDecoder);
        instantiateDecoder(true /* audio */, &mAudioDecoder, !forceNonOffload);
    }
}

@@ -1557,7 +1559,8 @@ void NuPlayer::determineAudioModeChange() {
    }
}

status_t NuPlayer::instantiateDecoder(bool audio, sp<DecoderBase> *decoder) {
status_t NuPlayer::instantiateDecoder(
        bool audio, sp<DecoderBase> *decoder, bool checkAudioModeChange) {
    // The audio decoder could be cleared by tear down. If still in shut down
    // process, no need to create a new audio decoder.
    if (*decoder != NULL || (audio && mFlushingAudio == SHUT_DOWN)) {
@@ -1605,7 +1608,9 @@ status_t NuPlayer::instantiateDecoder(bool audio, sp<DecoderBase> *decoder) {
        ++mAudioDecoderGeneration;
        notify->setInt32("generation", mAudioDecoderGeneration);

        if (checkAudioModeChange) {
            determineAudioModeChange();
        }
        if (mOffloadAudio) {
            mSource->setOffloadAudio(true /* offload */);

+3 −2
Original line number Diff line number Diff line
@@ -237,7 +237,8 @@ private:
            int64_t currentPositionUs, bool forceNonOffload, bool needsToCreateAudioDecoder);
    void determineAudioModeChange();

    status_t instantiateDecoder(bool audio, sp<DecoderBase> *decoder);
    status_t instantiateDecoder(
            bool audio, sp<DecoderBase> *decoder, bool checkAudioModeChange = true);

    status_t onInstantiateSecureDecoders();

+14 −6
Original line number Diff line number Diff line
@@ -647,7 +647,10 @@ void NuPlayer::Renderer::onMessageReceived(const sp<AMessage> &msg) {

        case kWhatAudioTearDown:
        {
            onAudioTearDown(kDueToError);
            int32_t reason;
            CHECK(msg->findInt32("reason", &reason));

            onAudioTearDown((AudioTearDownReason)reason);
            break;
        }

@@ -741,7 +744,7 @@ size_t NuPlayer::Renderer::AudioSinkCallback(
        case MediaPlayerBase::AudioSink::CB_EVENT_TEAR_DOWN:
        {
            ALOGV("AudioSink::CB_EVENT_TEAR_DOWN");
            me->notifyAudioTearDown();
            me->notifyAudioTearDown(kDueToError);
            break;
        }
    }
@@ -946,7 +949,7 @@ bool NuPlayer::Renderer::onDrainAudioQueue() {
                ALOGE("AudioSink write error(%zd) when writing %zu bytes", written, copy);
                // This can only happen when AudioSink was opened with doNotReconnect flag set to
                // true, in which case the NuPlayer will handle the reconnect.
                notifyAudioTearDown();
                notifyAudioTearDown(kDueToError);
            }
            break;
        }
@@ -1299,8 +1302,10 @@ void NuPlayer::Renderer::notifyEOS(bool audio, status_t finalResult, int64_t del
    notify->post(delayUs);
}

void NuPlayer::Renderer::notifyAudioTearDown() {
    (new AMessage(kWhatAudioTearDown, this))->post();
void NuPlayer::Renderer::notifyAudioTearDown(AudioTearDownReason reason) {
    sp<AMessage> msg = new AMessage(kWhatAudioTearDown, this);
    msg->setInt32("reason", reason);
    msg->post();
}

void NuPlayer::Renderer::onQueueBuffer(const sp<AMessage> &msg) {
@@ -1630,7 +1635,7 @@ void NuPlayer::Renderer::onResume() {
        status_t err = mAudioSink->start();
        if (err != OK) {
            ALOGE("cannot start AudioSink err %d", err);
            notifyAudioTearDown();
            notifyAudioTearDown(kDueToError);
        }
    }

@@ -1823,6 +1828,9 @@ status_t NuPlayer::Renderer::onOpenAudioSink(
                onDisableOffloadAudio();
                mCurrentOffloadInfo = AUDIO_INFO_INITIALIZER;
                ALOGV("openAudioSink: offload failed");
                if (offloadOnly) {
                    notifyAudioTearDown(kForceNonOffload);
                }
            } else {
                mUseAudioCallback = true;  // offload mode transfers data through callback
                ++mAudioDrainGeneration;  // discard pending kWhatDrainAudioQueue message.
+3 −2
Original line number Diff line number Diff line
@@ -92,8 +92,9 @@ struct NuPlayer::Renderer : public AHandler {
    };

    enum AudioTearDownReason {
        kDueToError = 0,
        kDueToError = 0,   // Could restart with either offload or non-offload.
        kDueToTimeout,
        kForceNonOffload,  // Restart only with non-offload.
    };

protected:
@@ -262,7 +263,7 @@ private:
    void notifyPosition();
    void notifyVideoLateBy(int64_t lateByUs);
    void notifyVideoRenderingStart();
    void notifyAudioTearDown();
    void notifyAudioTearDown(AudioTearDownReason reason);

    void flushQueue(List<QueueEntry> *queue);
    bool dropBufferIfStale(bool audio, const sp<AMessage> &msg);