diff options
author | Chong Zhang <chz@google.com> | 2014-07-23 00:10:22 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-07-23 00:10:22 +0000 |
commit | 5622ae2ccbe4ceb14dd74ff1327e7549db46f898 (patch) | |
tree | c37972a92f0662b41132c3fc3cc297ddb2df25ba /media | |
parent | c0568d56bf07234094f47498716f53ba9ec82801 (diff) | |
parent | ecc01ef05aea6b04aafc1b7d2d8f8519d0a8d928 (diff) | |
download | frameworks_av-5622ae2ccbe4ceb14dd74ff1327e7549db46f898.zip frameworks_av-5622ae2ccbe4ceb14dd74ff1327e7549db46f898.tar.gz frameworks_av-5622ae2ccbe4ceb14dd74ff1327e7549db46f898.tar.bz2 |
am ecc01ef0: Merge "update battery stats for video/audio" into lmp-dev
* commit 'ecc01ef05aea6b04aafc1b7d2d8f8519d0a8d928':
update battery stats for video/audio
Diffstat (limited to 'media')
-rw-r--r-- | media/libstagefright/MediaCodec.cpp | 115 |
1 files changed, 109 insertions, 6 deletions
diff --git a/media/libstagefright/MediaCodec.cpp b/media/libstagefright/MediaCodec.cpp index 7a9cb0b..15e062e 100644 --- a/media/libstagefright/MediaCodec.cpp +++ b/media/libstagefright/MediaCodec.cpp @@ -16,13 +16,13 @@ //#define LOG_NDEBUG 0 #define LOG_TAG "MediaCodec" -#include <utils/Log.h> #include <inttypes.h> -#include <media/stagefright/MediaCodec.h> - +#include "include/avc_utils.h" #include "include/SoftwareRenderer.h" +#include <binder/IBatteryStats.h> +#include <binder/IServiceManager.h> #include <gui/Surface.h> #include <media/ICrypto.h> #include <media/stagefright/foundation/ABuffer.h> @@ -32,16 +32,85 @@ #include <media/stagefright/foundation/hexdump.h> #include <media/stagefright/ACodec.h> #include <media/stagefright/BufferProducerWrapper.h> +#include <media/stagefright/MediaCodec.h> #include <media/stagefright/MediaCodecList.h> #include <media/stagefright/MediaDefs.h> #include <media/stagefright/MediaErrors.h> #include <media/stagefright/MetaData.h> #include <media/stagefright/NativeWindowWrapper.h> - -#include "include/avc_utils.h" +#include <private/android_filesystem_config.h> +#include <utils/Log.h> +#include <utils/Singleton.h> namespace android { +struct MediaCodec::BatteryNotifier : public Singleton<BatteryNotifier> { + BatteryNotifier(); + + void noteStartVideo(); + void noteStopVideo(); + void noteStartAudio(); + void noteStopAudio(); + +private: + int32_t mVideoRefCount; + int32_t mAudioRefCount; + sp<IBatteryStats> mBatteryStatService; +}; + +ANDROID_SINGLETON_STATIC_INSTANCE(MediaCodec::BatteryNotifier) + +MediaCodec::BatteryNotifier::BatteryNotifier() : + mVideoRefCount(0), + mAudioRefCount(0) { + // get battery service + const sp<IServiceManager> sm(defaultServiceManager()); + if (sm != NULL) { + const String16 name("batterystats"); + mBatteryStatService = interface_cast<IBatteryStats>(sm->getService(name)); + if (mBatteryStatService == NULL) { + ALOGE("batterystats service unavailable!"); + } + } +} + +void MediaCodec::BatteryNotifier::noteStartVideo() { + if (mVideoRefCount == 0 && mBatteryStatService != NULL) { + mBatteryStatService->noteStartVideo(AID_MEDIA); + } + mVideoRefCount++; +} + +void MediaCodec::BatteryNotifier::noteStopVideo() { + if (mVideoRefCount == 0) { + ALOGW("BatteryNotifier::noteStop(): video refcount is broken!"); + return; + } + + mVideoRefCount--; + if (mVideoRefCount == 0 && mBatteryStatService != NULL) { + mBatteryStatService->noteStopVideo(AID_MEDIA); + } +} + +void MediaCodec::BatteryNotifier::noteStartAudio() { + if (mAudioRefCount == 0 && mBatteryStatService != NULL) { + mBatteryStatService->noteStartAudio(AID_MEDIA); + } + mAudioRefCount++; +} + +void MediaCodec::BatteryNotifier::noteStopAudio() { + if (mAudioRefCount == 0) { + ALOGW("BatteryNotifier::noteStop(): audio refcount is broken!"); + return; + } + + mAudioRefCount--; + if (mAudioRefCount == 0 && mBatteryStatService != NULL) { + mBatteryStatService->noteStopAudio(AID_MEDIA); + } +} // static sp<MediaCodec> MediaCodec::CreateByType( const sp<ALooper> &looper, const char *mime, bool encoder) { @@ -71,6 +140,8 @@ MediaCodec::MediaCodec(const sp<ALooper> &looper) mReplyID(0), mFlags(0), mSoftRenderer(NULL), + mBatteryStatNotified(false), + mIsVideo(false), mDequeueInputTimeoutGeneration(0), mDequeueInputReplyID(0), mDequeueOutputTimeoutGeneration(0), @@ -756,7 +827,6 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) { case CodecBase::kWhatComponentConfigured: { CHECK_EQ(mState, CONFIGURING); - setState(CONFIGURED); // reset input surface flag mHaveInputSurface = false; @@ -764,6 +834,7 @@ void MediaCodec::onMessageReceived(const sp<AMessage> &msg) { CHECK(msg->findMessage("input-format", &mInputFormat)); CHECK(msg->findMessage("output-format", &mOutputFormat)); + setState(CONFIGURED); (new AMessage)->postReply(mReplyID); break; } @@ -1620,6 +1691,8 @@ void MediaCodec::setState(State newState) { mState = newState; cancelPendingDequeueOperations(); + + updateBatteryStat(); } void MediaCodec::returnBuffersToCodec() { @@ -2054,4 +2127,34 @@ status_t MediaCodec::amendOutputFormatWithCodecSpecificData( return OK; } +void MediaCodec::updateBatteryStat() { + if (mState == CONFIGURED && !mBatteryStatNotified) { + AString mime; + CHECK(mOutputFormat != NULL && + mOutputFormat->findString("mime", &mime)); + + mIsVideo = mime.startsWithIgnoreCase("video/"); + + BatteryNotifier& notifier(BatteryNotifier::getInstance()); + + if (mIsVideo) { + notifier.noteStartVideo(); + } else { + notifier.noteStartAudio(); + } + + mBatteryStatNotified = true; + } else if (mState == UNINITIALIZED && mBatteryStatNotified) { + BatteryNotifier& notifier(BatteryNotifier::getInstance()); + + if (mIsVideo) { + notifier.noteStopVideo(); + } else { + notifier.noteStopAudio(); + } + + mBatteryStatNotified = false; + } +} + } // namespace android |