diff options
author | Ronghua Wu <ronghuawu@google.com> | 2014-09-23 18:31:26 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-09-23 18:31:27 +0000 |
commit | 3cdd6b8c82f2c71054bdd767782fc78f501f8e62 (patch) | |
tree | 0453cbc22210497092b25289a72d1a67856198de /media | |
parent | ad5447f659043ce3e4b3719c6c18a254bee1dde2 (diff) | |
parent | f5b1db11734358d979a23a1ac4903872186ef60b (diff) | |
download | frameworks_av-3cdd6b8c82f2c71054bdd767782fc78f501f8e62.zip frameworks_av-3cdd6b8c82f2c71054bdd767782fc78f501f8e62.tar.gz frameworks_av-3cdd6b8c82f2c71054bdd767782fc78f501f8e62.tar.bz2 |
Merge "NuPlayer: add pause timeout event for offload audio." into lmp-dev
Diffstat (limited to 'media')
-rw-r--r-- | media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp | 40 | ||||
-rw-r--r-- | media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h | 7 |
2 files changed, 46 insertions, 1 deletions
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp index a8c8818..73ac057 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp +++ b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp @@ -32,6 +32,10 @@ namespace android { +// Maximum time in paused state when offloading audio decompression. When elapsed, the AudioSink +// is closed to allow the audio DSP to power down. +static const int64_t kOffloadPauseMaxUs = 60000000ll; + // static const int64_t NuPlayer::Renderer::kMinPositionUpdateDelayUs = 100000ll; @@ -61,7 +65,9 @@ NuPlayer::Renderer::Renderer( mVideoRenderingStartGeneration(0), mAudioRenderingStartGeneration(0), mLastPositionUpdateUs(-1ll), - mVideoLateByUs(0ll) { + mVideoLateByUs(0ll), + mAudioOffloadPauseTimeoutGeneration(0), + mAudioOffloadTornDown(false) { } NuPlayer::Renderer::~Renderer() { @@ -259,6 +265,17 @@ void NuPlayer::Renderer::onMessageReceived(const sp<AMessage> &msg) { break; } + case kWhatAudioOffloadPauseTimeout: + { + int32_t generation; + CHECK(msg->findInt32("generation", &generation)); + if (generation != mAudioOffloadPauseTimeoutGeneration) { + break; + } + onAudioOffloadTearDown(); + break; + } + default: TRESPASS(); break; @@ -951,6 +968,7 @@ void NuPlayer::Renderer::onPause() { if (mHasAudio) { mAudioSink->pause(); + startAudioOffloadPauseTimeout(); } ALOGV("now paused audio queue has %d entries, video has %d entries", @@ -963,6 +981,7 @@ void NuPlayer::Renderer::onResume() { } if (mHasAudio) { + cancelAudioOffloadPauseTimeout(); mAudioSink->start(); } @@ -1051,6 +1070,11 @@ int64_t NuPlayer::Renderer::getPlayedOutAudioDurationUs(int64_t nowUs) { } void NuPlayer::Renderer::onAudioOffloadTearDown() { + if (mAudioOffloadTornDown) { + return; + } + mAudioOffloadTornDown = true; + int64_t firstAudioTimeUs; { Mutex::Autolock autoLock(mLock); @@ -1069,5 +1093,19 @@ void NuPlayer::Renderer::onAudioOffloadTearDown() { notify->post(); } +void NuPlayer::Renderer::startAudioOffloadPauseTimeout() { + if (offloadingAudio()) { + sp<AMessage> msg = new AMessage(kWhatAudioOffloadPauseTimeout, id()); + msg->setInt32("generation", mAudioOffloadPauseTimeoutGeneration); + msg->post(kOffloadPauseMaxUs); + } +} + +void NuPlayer::Renderer::cancelAudioOffloadPauseTimeout() { + if (offloadingAudio()) { + ++mAudioOffloadPauseTimeoutGeneration; + } +} + } // namespace android diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h index e28071f..8e6112b 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h +++ b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h @@ -66,6 +66,7 @@ struct NuPlayer::Renderer : public AHandler { kWhatVideoRenderingStart = 'vdrd', kWhatMediaRenderingStart = 'mdrd', kWhatAudioOffloadTearDown = 'aOTD', + kWhatAudioOffloadPauseTimeout = 'aOPT', }; protected: @@ -132,6 +133,9 @@ private: int64_t mLastPositionUpdateUs; int64_t mVideoLateByUs; + int32_t mAudioOffloadPauseTimeoutGeneration; + bool mAudioOffloadTornDown; + size_t fillAudioBuffer(void *buffer, size_t size); bool onDrainAudioQueue(); @@ -168,6 +172,9 @@ private: bool offloadingAudio() const { return (mFlags & FLAG_OFFLOAD_AUDIO) != 0; } + void startAudioOffloadPauseTimeout(); + void cancelAudioOffloadPauseTimeout(); + DISALLOW_EVIL_CONSTRUCTORS(Renderer); }; |