diff options
author | Lajos Molnar <lajos@google.com> | 2015-02-10 04:13:46 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-02-10 04:13:46 +0000 |
commit | 0c11f31b610534754f48b40d0a6ccdd311d43fcf (patch) | |
tree | 820999bfaf641b43ac8d1118b702e406a6c778b7 /media | |
parent | 0c11001c58526cddc7f6135982f456fff6e34aeb (diff) | |
parent | 35d5af131c9d4962e935082f204ccd6a2130861c (diff) | |
download | frameworks_av-0c11f31b610534754f48b40d0a6ccdd311d43fcf.zip frameworks_av-0c11f31b610534754f48b40d0a6ccdd311d43fcf.tar.gz frameworks_av-0c11f31b610534754f48b40d0a6ccdd311d43fcf.tar.bz2 |
Merge "nuplayer: acquire wakelock during offload pause timeout" into lmp-mr1-dev
Diffstat (limited to 'media')
4 files changed, 122 insertions, 2 deletions
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp index 04e52b8..25225a8 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp +++ b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.cpp @@ -24,6 +24,7 @@ #include <media/stagefright/foundation/ADebug.h> #include <media/stagefright/foundation/AMessage.h> #include <media/stagefright/foundation/AUtils.h> +#include <media/stagefright/foundation/AWakeLock.h> #include <media/stagefright/MediaErrors.h> #include <media/stagefright/MetaData.h> #include <media/stagefright/Utils.h> @@ -87,7 +88,9 @@ NuPlayer::Renderer::Renderer( mCurrentOffloadInfo(AUDIO_INFO_INITIALIZER), mCurrentPcmInfo(AUDIO_PCMINFO_INITIALIZER), mTotalBuffersQueued(0), - mLastAudioBufferDrained(0) { + mLastAudioBufferDrained(0), + mWakeLock(new AWakeLock()) { + } NuPlayer::Renderer::~Renderer() { @@ -514,6 +517,7 @@ void NuPlayer::Renderer::onMessageReceived(const sp<AMessage> &msg) { } ALOGV("Audio Offload tear down due to pause timeout."); onAudioOffloadTearDown(kDueToTimeout); + mWakeLock->release(); break; } @@ -1385,6 +1389,7 @@ void NuPlayer::Renderer::onAudioOffloadTearDown(AudioOffloadTearDownReason reaso void NuPlayer::Renderer::startAudioOffloadPauseTimeout() { if (offloadingAudio()) { + mWakeLock->acquire(); sp<AMessage> msg = new AMessage(kWhatAudioOffloadPauseTimeout, id()); msg->setInt32("generation", mAudioOffloadPauseTimeoutGeneration); msg->post(kOffloadPauseMaxUs); @@ -1393,6 +1398,7 @@ void NuPlayer::Renderer::startAudioOffloadPauseTimeout() { void NuPlayer::Renderer::cancelAudioOffloadPauseTimeout() { if (offloadingAudio()) { + mWakeLock->release(true); ++mAudioOffloadPauseTimeoutGeneration; } } diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h index 98fc44d..003d1d0 100644 --- a/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h +++ b/media/libmediaplayerservice/nuplayer/NuPlayerRenderer.h @@ -23,6 +23,7 @@ namespace android { struct ABuffer; +class AWakeLock; struct VideoFrameScheduler; struct NuPlayer::Renderer : public AHandler { @@ -194,6 +195,8 @@ private: int32_t mTotalBuffersQueued; int32_t mLastAudioBufferDrained; + sp<AWakeLock> mWakeLock; + status_t getCurrentPositionOnLooper(int64_t *mediaUs); status_t getCurrentPositionOnLooper( int64_t *mediaUs, int64_t nowUs, bool allowPastQueuedVideo = false); diff --git a/media/libstagefright/foundation/AWakeLock.cpp b/media/libstagefright/foundation/AWakeLock.cpp new file mode 100644 index 0000000..88c4f6e --- /dev/null +++ b/media/libstagefright/foundation/AWakeLock.cpp @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +//#define LOG_NDEBUG 0 +#define LOG_TAG "AWakeLock" +#include <utils/Log.h> + +#include "ADebug.h" +#include "AWakeLock.h" + +#include <binder/IPCThreadState.h> +#include <binder/IServiceManager.h> +#include <powermanager/PowerManager.h> + + +namespace android { + +AWakeLock::AWakeLock() : + mPowerManager(NULL), + mWakeLockToken(NULL), + mWakeLockCount(0), + mDeathRecipient(new PMDeathRecipient(this)) {} + +AWakeLock::~AWakeLock() { + if (mPowerManager != NULL) { + sp<IBinder> binder = mPowerManager->asBinder(); + binder->unlinkToDeath(mDeathRecipient); + } + clearPowerManager(); +} + +bool AWakeLock::acquire() { + if (mWakeLockCount == 0) { + CHECK(mWakeLockToken == NULL); + if (mPowerManager == NULL) { + // use checkService() to avoid blocking if power service is not up yet + sp<IBinder> binder = + defaultServiceManager()->checkService(String16("power")); + if (binder == NULL) { + ALOGW("could not get the power manager service"); + } else { + mPowerManager = interface_cast<IPowerManager>(binder); + binder->linkToDeath(mDeathRecipient); + } + } + if (mPowerManager != NULL) { + sp<IBinder> binder = new BBinder(); + int64_t token = IPCThreadState::self()->clearCallingIdentity(); + status_t status = mPowerManager->acquireWakeLock( + POWERMANAGER_PARTIAL_WAKE_LOCK, + binder, String16("AWakeLock"), String16("media")); + IPCThreadState::self()->restoreCallingIdentity(token); + if (status == NO_ERROR) { + mWakeLockToken = binder; + mWakeLockCount++; + return true; + } + } + } else { + mWakeLockCount++; + return true; + } + return false; +} + +void AWakeLock::release(bool force) { + if (mWakeLockCount == 0) { + return; + } + if (force) { + // Force wakelock release below by setting reference count to 1. + mWakeLockCount = 1; + } + if (--mWakeLockCount == 0) { + CHECK(mWakeLockToken != NULL); + if (mPowerManager != NULL) { + int64_t token = IPCThreadState::self()->clearCallingIdentity(); + mPowerManager->releaseWakeLock(mWakeLockToken, 0 /* flags */); + IPCThreadState::self()->restoreCallingIdentity(token); + } + mWakeLockToken.clear(); + } +} + +void AWakeLock::clearPowerManager() { + release(true); + mPowerManager.clear(); +} + +void AWakeLock::PMDeathRecipient::binderDied(const wp<IBinder>& who __unused) { + if (mWakeLock != NULL) { + mWakeLock->clearPowerManager(); + } +} + +} // namespace android diff --git a/media/libstagefright/foundation/Android.mk b/media/libstagefright/foundation/Android.mk index c1dd6ce..08355c7 100644 --- a/media/libstagefright/foundation/Android.mk +++ b/media/libstagefright/foundation/Android.mk @@ -14,6 +14,7 @@ LOCAL_SRC_FILES:= \ ANetworkSession.cpp \ AString.cpp \ AStringUtils.cpp \ + AWakeLock.cpp \ ParsedMessage.cpp \ base64.cpp \ hexdump.cpp @@ -25,7 +26,8 @@ LOCAL_SHARED_LIBRARIES := \ libbinder \ libutils \ libcutils \ - liblog + liblog \ + libpowermanager LOCAL_CFLAGS += -Wno-multichar -Werror |