diff options
author | Wei Jia <wjia@google.com> | 2015-07-14 18:31:34 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-07-14 18:31:35 +0000 |
commit | 495151d3f4c5f92f1d162efb32b636521c105df5 (patch) | |
tree | 27320a1e9d59b148c4f502fca5554867eed49c2e /media/libmediaplayerservice/nuplayer/NuPlayer.cpp | |
parent | 51d12c26628ab37b0fd58e08b6905652f8763225 (diff) | |
parent | e4d18c7f84186b935ac569d5919059c455edd390 (diff) | |
download | frameworks_av-495151d3f4c5f92f1d162efb32b636521c105df5.zip frameworks_av-495151d3f4c5f92f1d162efb32b636521c105df5.tar.gz frameworks_av-495151d3f4c5f92f1d162efb32b636521c105df5.tar.bz2 |
Merge "NuPlayer: determine audio mode before instantiating audio decoder." into mnc-dev
Diffstat (limited to 'media/libmediaplayerservice/nuplayer/NuPlayer.cpp')
-rw-r--r-- | media/libmediaplayerservice/nuplayer/NuPlayer.cpp | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp index 50a98d8..3e0ee08 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp +++ b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp @@ -837,20 +837,6 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { // Don't try to re-open audio sink if there's an existing decoder. if (mAudioSink != NULL && mAudioDecoder == NULL) { - sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */); - sp<AMessage> videoFormat = mSource->getFormat(false /* audio */); - audio_stream_type_t streamType = mAudioSink->getAudioStreamType(); - const bool hasVideo = (videoFormat != NULL); - const bool canOffload = canOffloadStream( - audioMeta, hasVideo, mSource->isStreaming(), streamType); - if (canOffload) { - if (!mOffloadAudio) { - mRenderer->signalEnableOffloadAudio(); - } - // open audio sink early under offload mode. - sp<AMessage> format = mSource->getFormat(true /*audio*/); - tryOpenAudioSinkForOffload(format, hasVideo); - } instantiateDecoder(true, &mAudioDecoder); } @@ -1111,20 +1097,6 @@ void NuPlayer::onMessageReceived(const sp<AMessage> &msg) { performSeek(positionUs); if (reason == Renderer::kDueToError) { - sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */); - sp<AMessage> videoFormat = mSource->getFormat(false /* audio */); - audio_stream_type_t streamType = mAudioSink->getAudioStreamType(); - const bool hasVideo = (videoFormat != NULL); - const bool canOffload = canOffloadStream( - audioMeta, hasVideo, mSource->isStreaming(), streamType); - if (canOffload) { - mRenderer->signalEnableOffloadAudio(); - sp<AMessage> format = mSource->getFormat(true /*audio*/); - tryOpenAudioSinkForOffload(format, hasVideo); - } else { - mRenderer->signalDisableOffloadAudio(); - mOffloadAudio = false; - } instantiateDecoder(true /* audio */, &mAudioDecoder); } } @@ -1456,6 +1428,36 @@ void NuPlayer::closeAudioSink() { mRenderer->closeAudioSink(); } +void NuPlayer::determineAudioModeChange() { + if (mSource == NULL || mAudioSink == NULL) { + return; + } + + if (mRenderer == NULL) { + ALOGW("No renderer can be used to determine audio mode. Use non-offload for safety."); + mOffloadAudio = false; + return; + } + + sp<MetaData> audioMeta = mSource->getFormatMeta(true /* audio */); + sp<AMessage> videoFormat = mSource->getFormat(false /* audio */); + audio_stream_type_t streamType = mAudioSink->getAudioStreamType(); + const bool hasVideo = (videoFormat != NULL); + const bool canOffload = canOffloadStream( + audioMeta, hasVideo, mSource->isStreaming(), streamType); + if (canOffload) { + if (!mOffloadAudio) { + mRenderer->signalEnableOffloadAudio(); + } + // open audio sink early under offload mode. + sp<AMessage> format = mSource->getFormat(true /*audio*/); + tryOpenAudioSinkForOffload(format, hasVideo); + } else { + mRenderer->signalDisableOffloadAudio(); + mOffloadAudio = false; + } +} + status_t NuPlayer::instantiateDecoder(bool audio, sp<DecoderBase> *decoder) { if (*decoder != NULL) { return OK; @@ -1497,6 +1499,7 @@ status_t NuPlayer::instantiateDecoder(bool audio, sp<DecoderBase> *decoder) { ++mAudioDecoderGeneration; notify->setInt32("generation", mAudioDecoderGeneration); + determineAudioModeChange(); if (mOffloadAudio) { const bool hasVideo = (mSource->getFormat(false /*audio */) != NULL); format->setInt32("has-video", hasVideo); |