From 99e69716215cd0665379bc90d708f2ea8689831d Mon Sep 17 00:00:00 2001 From: Ruben Brunk Date: Tue, 26 May 2015 17:25:07 -0700 Subject: Track camera and flashlight usage in battery stats. Bug: 15986092 Change-Id: I9dc6828332e4091fd93bf2d82839e8e3862a2fc2 --- media/libstagefright/MediaCodec.cpp | 130 +----------------------------------- 1 file changed, 1 insertion(+), 129 deletions(-) (limited to 'media/libstagefright/MediaCodec.cpp') diff --git a/media/libstagefright/MediaCodec.cpp b/media/libstagefright/MediaCodec.cpp index 46c154d..c8dcef1 100644 --- a/media/libstagefright/MediaCodec.cpp +++ b/media/libstagefright/MediaCodec.cpp @@ -21,7 +21,6 @@ #include "include/avc_utils.h" #include "include/SoftwareRenderer.h" -#include #include #include #include @@ -47,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -107,134 +107,6 @@ private: DISALLOW_EVIL_CONSTRUCTORS(ResourceManagerClient); }; -struct MediaCodec::BatteryNotifier : public Singleton { - BatteryNotifier(); - virtual ~BatteryNotifier(); - - void noteStartVideo(); - void noteStopVideo(); - void noteStartAudio(); - void noteStopAudio(); - void onBatteryStatServiceDied(); - -private: - struct DeathNotifier : public IBinder::DeathRecipient { - DeathNotifier() {} - virtual void binderDied(const wp& /*who*/) { - BatteryNotifier::getInstance().onBatteryStatServiceDied(); - } - }; - - Mutex mLock; - int32_t mVideoRefCount; - int32_t mAudioRefCount; - sp mBatteryStatService; - sp mDeathNotifier; - - sp getBatteryService_l(); - - DISALLOW_EVIL_CONSTRUCTORS(BatteryNotifier); -}; - -ANDROID_SINGLETON_STATIC_INSTANCE(MediaCodec::BatteryNotifier) - -MediaCodec::BatteryNotifier::BatteryNotifier() : - mVideoRefCount(0), - mAudioRefCount(0) { -} - -sp MediaCodec::BatteryNotifier::getBatteryService_l() { - if (mBatteryStatService != NULL) { - return mBatteryStatService; - } - // get battery service from service manager - const sp sm(defaultServiceManager()); - if (sm != NULL) { - const String16 name("batterystats"); - mBatteryStatService = - interface_cast(sm->getService(name)); - if (mBatteryStatService == NULL) { - ALOGE("batterystats service unavailable!"); - return NULL; - } - mDeathNotifier = new DeathNotifier(); - IInterface::asBinder(mBatteryStatService)->linkToDeath(mDeathNotifier); - // notify start now if media already started - if (mVideoRefCount > 0) { - mBatteryStatService->noteStartVideo(AID_MEDIA); - } - if (mAudioRefCount > 0) { - mBatteryStatService->noteStartAudio(AID_MEDIA); - } - } - return mBatteryStatService; -} - -MediaCodec::BatteryNotifier::~BatteryNotifier() { - if (mDeathNotifier != NULL) { - IInterface::asBinder(mBatteryStatService)-> - unlinkToDeath(mDeathNotifier); - } -} - -void MediaCodec::BatteryNotifier::noteStartVideo() { - Mutex::Autolock _l(mLock); - sp batteryService = getBatteryService_l(); - if (mVideoRefCount == 0 && batteryService != NULL) { - batteryService->noteStartVideo(AID_MEDIA); - } - mVideoRefCount++; -} - -void MediaCodec::BatteryNotifier::noteStopVideo() { - Mutex::Autolock _l(mLock); - if (mVideoRefCount == 0) { - ALOGW("BatteryNotifier::noteStop(): video refcount is broken!"); - return; - } - - sp batteryService = getBatteryService_l(); - - mVideoRefCount--; - if (mVideoRefCount == 0 && batteryService != NULL) { - batteryService->noteStopVideo(AID_MEDIA); - } -} - -void MediaCodec::BatteryNotifier::noteStartAudio() { - Mutex::Autolock _l(mLock); - sp batteryService = getBatteryService_l(); - if (mAudioRefCount == 0 && batteryService != NULL) { - batteryService->noteStartAudio(AID_MEDIA); - } - mAudioRefCount++; -} - -void MediaCodec::BatteryNotifier::noteStopAudio() { - Mutex::Autolock _l(mLock); - if (mAudioRefCount == 0) { - ALOGW("BatteryNotifier::noteStop(): audio refcount is broken!"); - return; - } - - sp batteryService = getBatteryService_l(); - - mAudioRefCount--; - if (mAudioRefCount == 0 && batteryService != NULL) { - batteryService->noteStopAudio(AID_MEDIA); - } -} - -void MediaCodec::BatteryNotifier::onBatteryStatServiceDied() { - Mutex::Autolock _l(mLock); - mBatteryStatService.clear(); - mDeathNotifier.clear(); - // Do not reset mVideoRefCount and mAudioRefCount here. The ref - // counting is independent of the battery service availability. - // We need this if battery service becomes available after media - // started. -} - MediaCodec::ResourceManagerServiceProxy::ResourceManagerServiceProxy() { } -- cgit v1.1