summaryrefslogtreecommitdiffstats
path: root/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
diff options
context:
space:
mode:
authorWei Jia <wjia@google.com>2015-07-13 17:58:11 -0700
committerWei Jia <wjia@google.com>2015-07-14 11:04:40 -0700
commite4d18c7f84186b935ac569d5919059c455edd390 (patch)
tree4b104c794772cc5461b08d8ffecee669b8b1720a /media/libmediaplayerservice/nuplayer/NuPlayer.cpp
parent4b33e0838fdb1b5e545449add02005916b512c99 (diff)
downloadframeworks_av-e4d18c7f84186b935ac569d5919059c455edd390.zip
frameworks_av-e4d18c7f84186b935ac569d5919059c455edd390.tar.gz
frameworks_av-e4d18c7f84186b935ac569d5919059c455edd390.tar.bz2
NuPlayer: determine audio mode before instantiating audio decoder.
Bug: 22460159 Change-Id: I334c6dc5e1163a462155d251eaa985ff5e3858e6
Diffstat (limited to 'media/libmediaplayerservice/nuplayer/NuPlayer.cpp')
-rw-r--r--media/libmediaplayerservice/nuplayer/NuPlayer.cpp59
1 files changed, 31 insertions, 28 deletions
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
index 4a1a34d..26b83bb 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayer.cpp
@@ -830,20 +830,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);
}
@@ -1104,20 +1090,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);
}
}
@@ -1449,6 +1421,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;
@@ -1490,6 +1492,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);