diff options
author | Andy Hung <hunga@google.com> | 2014-12-23 00:27:46 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-12-23 00:27:46 +0000 |
commit | 0d19abb440c7e62e944efbeadf02299990f9a589 (patch) | |
tree | 77638d29013a8bae57a7232e4aa5ea71baadc341 | |
parent | f580806d893c4631f5324ff0af5c2db68a40ef42 (diff) | |
parent | f0e83644637bd05852c244df481f21a0d435ff66 (diff) | |
download | frameworks_av-0d19abb440c7e62e944efbeadf02299990f9a589.zip frameworks_av-0d19abb440c7e62e944efbeadf02299990f9a589.tar.gz frameworks_av-0d19abb440c7e62e944efbeadf02299990f9a589.tar.bz2 |
Merge "NuPlayer: Do not recreate AudioTrack if not needed" into lmp-mr1-dev
-rw-r--r-- | media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp | 29 | ||||
-rw-r--r-- | media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h | 10 |
2 files changed, 39 insertions, 0 deletions
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp index 2ea6d70..57fcfe5 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp +++ b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp @@ -39,6 +39,15 @@ namespace android { static const int64_t kOffloadPauseMaxUs = 10000000ll; // static +const NuPlayer::Renderer::PcmInfo NuPlayer::Renderer::AUDIO_PCMINFO_INITIALIZER = { + AUDIO_CHANNEL_NONE, + AUDIO_OUTPUT_FLAG_NONE, + AUDIO_FORMAT_INVALID, + 0, // mNumChannels + 0 // mSampleRate +}; + +// static const int64_t NuPlayer::Renderer::kMinPositionUpdateDelayUs = 100000ll; NuPlayer::Renderer::Renderer( @@ -76,6 +85,7 @@ NuPlayer::Renderer::Renderer( mAudioOffloadPauseTimeoutGeneration(0), mAudioOffloadTornDown(false), mCurrentOffloadInfo(AUDIO_INFO_INITIALIZER), + mCurrentPcmInfo(AUDIO_PCMINFO_INITIALIZER), mTotalBuffersQueued(0), mLastAudioBufferDrained(0) { } @@ -1442,6 +1452,8 @@ status_t NuPlayer::Renderer::onOpenAudioSink( // no change from previous configuration, everything ok. return OK; } + mCurrentPcmInfo = AUDIO_PCMINFO_INITIALIZER; + ALOGV("openAudioSink: try to open AudioSink in offload mode"); uint32_t offloadFlags = flags; offloadFlags |= AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD; @@ -1483,6 +1495,20 @@ status_t NuPlayer::Renderer::onOpenAudioSink( ALOGV("openAudioSink: open AudioSink in NON-offload mode"); uint32_t pcmFlags = flags; pcmFlags &= ~AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD; + + const PcmInfo info = { + (audio_channel_mask_t)channelMask, + (audio_output_flags_t)pcmFlags, + AUDIO_FORMAT_PCM_16_BIT, // TODO: change to audioFormat + numChannels, + sampleRate + }; + if (memcmp(&mCurrentPcmInfo, &info, sizeof(info)) == 0) { + ALOGV("openAudioSink: no change in pcm mode"); + // no change from previous configuration, everything ok. + return OK; + } + audioSinkChanged = true; mAudioSink->close(); mCurrentOffloadInfo = AUDIO_INFO_INITIALIZER; @@ -1497,8 +1523,10 @@ status_t NuPlayer::Renderer::onOpenAudioSink( (audio_output_flags_t)pcmFlags); if (err != OK) { ALOGW("openAudioSink: non offloaded open failed status: %d", err); + mCurrentPcmInfo = AUDIO_PCMINFO_INITIALIZER; return err; } + mCurrentPcmInfo = info; mAudioSink->start(); } if (audioSinkChanged) { @@ -1513,6 +1541,7 @@ status_t NuPlayer::Renderer::onOpenAudioSink( void NuPlayer::Renderer::onCloseAudioSink() { mAudioSink->close(); mCurrentOffloadInfo = AUDIO_INFO_INITIALIZER; + mCurrentPcmInfo = AUDIO_PCMINFO_INITIALIZER; } } // namespace android diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h index c6e3457..23907c8 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h +++ b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h @@ -181,6 +181,16 @@ private: bool mAudioOffloadTornDown; audio_offload_info_t mCurrentOffloadInfo; + struct PcmInfo { + audio_channel_mask_t mChannelMask; + audio_output_flags_t mFlags; + audio_format_t mFormat; + int32_t mNumChannels; + int32_t mSampleRate; + }; + PcmInfo mCurrentPcmInfo; + static const PcmInfo AUDIO_PCMINFO_INITIALIZER; + int32_t mTotalBuffersQueued; int32_t mLastAudioBufferDrained; |