diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2019-05-01 03:03:19 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2019-05-01 03:03:19 +0000 |
commit | fbedd5647a9c40a8957edcf6787c656bfe4df68a (patch) | |
tree | d85e528a65afb690999947ae298fcab70135070c | |
parent | f0f13a04d19afe2bed87645f0c74e995dbe55477 (diff) | |
parent | 546bfe07fce6fa9712edb2fbfa6a983cd34021b1 (diff) | |
download | av-fbedd5647a9c40a8957edcf6787c656bfe4df68a.tar.gz |
Snap for 5519018 from 546bfe07fce6fa9712edb2fbfa6a983cd34021b1 to qt-release
Change-Id: I9a1f395510385cb4878470b3f050f2114cc1ffd9
-rw-r--r-- | media/eco/Android.bp | 1 | ||||
-rw-r--r-- | media/eco/ECODebug.cpp | 32 | ||||
-rw-r--r-- | media/eco/ECOService.cpp | 26 | ||||
-rw-r--r-- | media/eco/ECOSession.cpp | 87 | ||||
-rw-r--r-- | media/eco/ECOUtils.cpp | 4 | ||||
-rw-r--r-- | media/eco/include/eco/ECODebug.h | 24 | ||||
-rw-r--r-- | media/eco/include/eco/ECOService.h | 1 | ||||
-rw-r--r-- | media/eco/include/eco/ECOUtils.h | 6 |
8 files changed, 111 insertions, 70 deletions
diff --git a/media/eco/Android.bp b/media/eco/Android.bp index 1dce543..d4fcb01 100644 --- a/media/eco/Android.bp +++ b/media/eco/Android.bp @@ -9,6 +9,7 @@ name: "aidl/android/media/eco/IECOServiceStatsProvider.aidl", "aidl/android/media/eco/IECOServiceInfoListener.aidl", "ECOData.cpp", + "ECODebug.cpp", "ECOService.cpp", "ECOSession.cpp", "ECOUtils.cpp", diff --git a/media/eco/ECODebug.cpp b/media/eco/ECODebug.cpp new file mode 100644 index 0000000..5ed08ab --- /dev/null +++ b/media/eco/ECODebug.cpp @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2019 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. + */ + +#include "eco/ECODebug.h" + +namespace android { +namespace media { +namespace eco { + +uint32_t gECOLogLevel = 0; + +void updateLogLevel() { + gECOLogLevel = property_get_int32(kDebugLogsLevelProperty, 0); + ALOGI("ECOService log level is %d", gECOLogLevel); +} + +} // namespace eco +} // namespace media +} // namespace android diff --git a/media/eco/ECOService.cpp b/media/eco/ECOService.cpp index bc09d37..59ae868 100644 --- a/media/eco/ECOService.cpp +++ b/media/eco/ECOService.cpp @@ -38,28 +38,16 @@ namespace android { namespace media { namespace eco { -// ---------------------------------------------------------------------------- -// Logging support -- this is for debugging only -// Use "adb shell dumpsys media.ECOService -v 1" to change it. -volatile int32_t gLogLevel = 0; - -#define LOG1(...) ALOGD_IF(gLogLevel >= 1, __VA_ARGS__); -#define LOG2(...) ALOGD_IF(gLogLevel >= 2, __VA_ARGS__); - -static void setLogLevel(int level) { - android_atomic_write(level, &gLogLevel); -} - ECOService::ECOService() : BnECOService() { ALOGD("ECOService created"); - setLogLevel(10); + updateLogLevel(); } /*virtual*/ ::android::binder::Status ECOService::obtainSession( int32_t width, int32_t height, bool isCameraRecording, ::android::sp<::android::media::eco::IECOSession>* _aidl_return) { - ALOGI("ECOService::obtainSession w: %d, h: %d, isCameraRecording: %d", width, height, - isCameraRecording); + ECOLOGI("ECOService::obtainSession w: %d, h: %d, isCameraRecording: %d", width, height, + isCameraRecording); if (width <= 0) { return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "Width can not be <= 0"); @@ -75,7 +63,7 @@ ECOService::ECOService() : BnECOService() { SessionConfig newCfg(width, height, isCameraRecording); - ALOGD("session count before is %zu", mSessionConfigToSessionMap.size()); + ECOLOGD("session count before is %zu", mSessionConfigToSessionMap.size()); Mutex::Autolock lock(mServiceLock); bool foundSession = false; @@ -96,13 +84,13 @@ ECOService::ECOService() : BnECOService() { // Create a new session and add it to the record. *_aidl_return = ECOSession::createECOSession(width, height, isCameraRecording); if (*_aidl_return == nullptr) { - ALOGE("ECOService failed to create ECOSession w: %d, h: %d, isCameraRecording: %d", width, - height, isCameraRecording); + ECOLOGE("ECOService failed to create ECOSession w: %d, h: %d, isCameraRecording: %d", width, + height, isCameraRecording); return STATUS_ERROR(ERROR_UNSUPPORTED, "Failed to create eco session"); } // Insert the new session into the map. mSessionConfigToSessionMap[newCfg] = *_aidl_return; - ALOGD("session count after is %zu", mSessionConfigToSessionMap.size()); + ECOLOGD("session count after is %zu", mSessionConfigToSessionMap.size()); return binder::Status::ok(); } diff --git a/media/eco/ECOSession.cpp b/media/eco/ECOSession.cpp index d86ad5b..319bac5 100644 --- a/media/eco/ECOSession.cpp +++ b/media/eco/ECOSession.cpp @@ -55,9 +55,10 @@ sp<ECOSession> ECOSession::createECOSession(int32_t width, int32_t height, bool // Only support up to 720P and camera recording use case. // TODO(hkuang): Support the same resolution as in EAF. Also relax the isCameraRecording // as encoder may not konw it is from camera for some usage cases. - if (width > 1280 || height > 720 || width == 0 || height == 0 || isCameraRecording == false) { - ALOGE("Failed to create ECOSession with w: %d, h: %d, isCameraRecording: %d", width, height, - isCameraRecording); + if (width <= 0 || height <= 0 || width > 5120 || height > 5120 || width > 1280 * 720 / height || + isCameraRecording == false) { + ECOLOGE("Failed to create ECOSession with w: %d, h: %d, isCameraRecording: %d", width, + height, isCameraRecording); return nullptr; } return new ECOSession(width, height, isCameraRecording); @@ -72,8 +73,8 @@ ECOSession::ECOSession(int32_t width, int32_t height, bool isCameraRecording) mWidth(width), mHeight(height), mIsCameraRecording(isCameraRecording) { - ALOGI("ECOSession created with w: %d, h: %d, isCameraRecording: %d", mWidth, mHeight, - mIsCameraRecording); + ECOLOGI("ECOSession created with w: %d, h: %d, isCameraRecording: %d", mWidth, mHeight, + mIsCameraRecording); mThread = std::thread(startThread, this); } @@ -82,11 +83,11 @@ ECOSession::~ECOSession() { mStatsQueueWaitCV.notify_all(); if (mThread.joinable()) { - ALOGD("ECOSession: join the thread"); + ECOLOGD("ECOSession: join the thread"); mThread.join(); } - ALOGI("ECOSession destroyed with w: %d, h: %d, isCameraRecording: %d", mWidth, mHeight, - mIsCameraRecording); + ECOLOGI("ECOSession destroyed with w: %d, h: %d, isCameraRecording: %d", mWidth, mHeight, + mIsCameraRecording); } // static @@ -95,7 +96,7 @@ void ECOSession::startThread(ECOSession* session) { } void ECOSession::run() { - ALOGD("ECOSession: starting main thread"); + ECOLOGD("ECOSession: starting main thread"); while (!mStopThread) { std::unique_lock<std::mutex> runLock(mStatsQueueLock); @@ -109,19 +110,19 @@ void ECOSession::run() { } } - ALOGD("ECOSession: exiting main thread"); + ECOLOGD("ECOSession: exiting main thread"); } bool ECOSession::processStats(const ECOData& stats) { if (stats.getDataType() != ECOData::DATA_TYPE_STATS) { - ALOGE("Invalid stats. ECOData with type: %s", stats.getDataTypeString().c_str()); + ECOLOGE("Invalid stats. ECOData with type: %s", stats.getDataTypeString().c_str()); return false; } // Get the type of the stats. std::string statsType; if (stats.findString(KEY_STATS_TYPE, &statsType) != ECODataStatus::OK) { - ALOGE("Invalid stats ECOData without statsType"); + ECOLOGE("Invalid stats ECOData without statsType"); return false; } @@ -130,7 +131,7 @@ bool ECOSession::processStats(const ECOData& stats) { } else if (statsType.compare(VALUE_STATS_TYPE_FRAME) == 0) { RETURN_IF_ERROR(processFrameStats(stats)); } else { - ALOGE("processStats:: Failed to process stats as ECOData contains unknown stats type"); + ECOLOGE("processStats:: Failed to process stats as ECOData contains unknown stats type"); return false; } @@ -138,7 +139,7 @@ bool ECOSession::processStats(const ECOData& stats) { } bool ECOSession::processSessionStats(const ECOData& stats) { - ALOGV("processSessionStats"); + ECOLOGV("processSessionStats"); ECOData info(ECOData::DATA_TYPE_INFO, systemTime(SYSTEM_TIME_BOOTTIME)); info.setString(KEY_INFO_TYPE, VALUE_INFO_TYPE_SESSION); @@ -148,42 +149,42 @@ bool ECOSession::processSessionStats(const ECOData& stats) { ECOData::ECODataKeyValuePair entry = iter.next(); const std::string& key = entry.first; const ECOData::ECODataValueType value = entry.second; - ALOGV("Processing key: %s", key.c_str()); + ECOLOGV("Processing key: %s", key.c_str()); if (!key.compare(KEY_STATS_TYPE)) { // Skip the key KEY_STATS_TYPE as that has been parsed already. continue; } else if (!key.compare(ENCODER_TYPE)) { mCodecType = std::get<int32_t>(value); - ALOGV("codec type is %d", mCodecType); + ECOLOGV("codec type is %d", mCodecType); } else if (!key.compare(ENCODER_PROFILE)) { mCodecProfile = std::get<int32_t>(value); - ALOGV("codec profile is %d", mCodecProfile); + ECOLOGV("codec profile is %d", mCodecProfile); } else if (!key.compare(ENCODER_LEVEL)) { mCodecLevel = std::get<int32_t>(value); - ALOGV("codec level is %d", mCodecLevel); + ECOLOGV("codec level is %d", mCodecLevel); } else if (!key.compare(ENCODER_TARGET_BITRATE_BPS)) { mBitrateBps = std::get<int32_t>(value); - ALOGV("codec bitrate is %d", mBitrateBps); + ECOLOGV("codec bitrate is %d", mBitrateBps); } else if (!key.compare(ENCODER_KFI_FRAMES)) { mKeyFrameIntervalFrames = std::get<int32_t>(value); - ALOGV("codec kfi is %d", mKeyFrameIntervalFrames); + ECOLOGV("codec kfi is %d", mKeyFrameIntervalFrames); } else if (!key.compare(ENCODER_FRAMERATE_FPS)) { mFramerateFps = std::get<float>(value); - ALOGV("codec framerate is %f", mFramerateFps); + ECOLOGV("codec framerate is %f", mFramerateFps); } else if (!key.compare(ENCODER_INPUT_WIDTH)) { int32_t width = std::get<int32_t>(value); if (width != mWidth) { - ALOGW("Codec width: %d, expected: %d", width, mWidth); + ECOLOGW("Codec width: %d, expected: %d", width, mWidth); } - ALOGV("codec width is %d", width); + ECOLOGV("codec width is %d", width); } else if (!key.compare(ENCODER_INPUT_HEIGHT)) { int32_t height = std::get<int32_t>(value); if (height != mHeight) { - ALOGW("Codec height: %d, expected: %d", height, mHeight); + ECOLOGW("Codec height: %d, expected: %d", height, mHeight); } - ALOGV("codec height is %d", height); + ECOLOGV("codec height is %d", height); } else { - ALOGW("Unknown frame stats key %s from provider.", key.c_str()); + ECOLOGW("Unknown session stats key %s from provider.", key.c_str()); continue; } info.set(key, value); @@ -197,7 +198,7 @@ bool ECOSession::processSessionStats(const ECOData& stats) { } bool ECOSession::processFrameStats(const ECOData& stats) { - ALOGD("processFrameStats"); + ECOLOGD("processFrameStats"); bool needToNotifyListener = false; ECOData info(ECOData::DATA_TYPE_INFO, systemTime(SYSTEM_TIME_BOOTTIME)); @@ -208,7 +209,7 @@ bool ECOSession::processFrameStats(const ECOData& stats) { ECOData::ECODataKeyValuePair entry = iter.next(); const std::string& key = entry.first; const ECOData::ECODataValueType value = entry.second; - ALOGD("Processing %s key", key.c_str()); + ECOLOGD("Processing %s key", key.c_str()); // Only process the keys that are supported by ECOService 1.0. if (!key.compare(FRAME_NUM) || !key.compare(FRAME_PTS_US) || !key.compare(FRAME_TYPE) || @@ -242,7 +243,7 @@ bool ECOSession::processFrameStats(const ECOData& stats) { info.set(key, value); } else { - ALOGW("Unknown frame stats key %s from provider.", key.c_str()); + ECOLOGW("Unknown frame stats key %s from provider.", key.c_str()); } } @@ -259,11 +260,11 @@ Status ECOSession::addStatsProvider( ::android::String16 name; provider->getName(&name); - ALOGV("Try to add stats provider name: %s uid: %d pid %d", ::android::String8(name).string(), - IPCThreadState::self()->getCallingUid(), IPCThreadState::self()->getCallingPid()); + ECOLOGV("Try to add stats provider name: %s uid: %d pid %d", ::android::String8(name).string(), + IPCThreadState::self()->getCallingUid(), IPCThreadState::self()->getCallingPid()); if (provider == nullptr) { - ALOGE("%s: provider must not be null", __FUNCTION__); + ECOLOGE("%s: provider must not be null", __FUNCTION__); *status = false; return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "Null provider given to addStatsProvider"); } @@ -276,14 +277,14 @@ Status ECOSession::addStatsProvider( String8 errorMsg = String8::format( "ECOService 1.0 only supports one stats provider, current provider: %s", ::android::String8(name).string()); - ALOGE("%s", errorMsg.string()); + ECOLOGE("%s", errorMsg.string()); *status = false; return STATUS_ERROR(ERROR_ALREADY_EXISTS, errorMsg.string()); } // TODO: Handle the provider config. if (config.getDataType() != ECOData::DATA_TYPE_STATS_PROVIDER_CONFIG) { - ALOGE("Provider config is invalid"); + ECOLOGE("Provider config is invalid"); *status = false; return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "Provider config is invalid"); } @@ -314,26 +315,26 @@ Status ECOSession::addInfoListener( std::scoped_lock<std::mutex> lock(mSessionLock); if (mListener != nullptr) { - ALOGE("ECOService 1.0 only supports one listener"); + ECOLOGE("ECOService 1.0 only supports one listener"); *status = false; return STATUS_ERROR(ERROR_ALREADY_EXISTS, "ECOService 1.0 only supports one listener"); } if (listener == nullptr) { - ALOGE("%s: listener must not be null", __FUNCTION__); + ECOLOGE("%s: listener must not be null", __FUNCTION__); *status = false; return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "Null listener given to addInfoListener"); } if (config.getDataType() != ECOData::DATA_TYPE_INFO_LISTENER_CONFIG) { *status = false; - ALOGE("%s: listener config is invalid", __FUNCTION__); + ECOLOGE("%s: listener config is invalid", __FUNCTION__); return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "listener config is invalid"); } if (config.isEmpty()) { *status = false; - ALOGE("Listener must provide listening criterion"); + ECOLOGE("Listener must provide listening criterion"); return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "listener config is empty"); } @@ -345,15 +346,15 @@ Status ECOSession::addInfoListener( mListenerQpCondition.mQpBlocknessThreshold < ENCODER_MIN_QP || mListenerQpCondition.mQpBlocknessThreshold > ENCODER_MAX_QP) { *status = false; - ALOGE("%s: listener config is invalid", __FUNCTION__); + ECOLOGE("%s: listener config is invalid", __FUNCTION__); return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "listener config is not valid"); } ::android::String16 name; listener->getName(&name); - ALOGD("Info listener name: %s uid: %d pid %d", ::android::String8(name).string(), - IPCThreadState::self()->getCallingUid(), IPCThreadState::self()->getCallingPid()); + ECOLOGD("Info listener name: %s uid: %d pid %d", ::android::String8(name).string(), + IPCThreadState::self()->getCallingUid(), IPCThreadState::self()->getCallingPid()); mListener = listener; *status = true; @@ -375,7 +376,7 @@ Status ECOSession::removeInfoListener( } Status ECOSession::pushNewStats(const ::android::media::eco::ECOData& stats, bool*) { - ALOGV("ECOSession get new stats type: %s", stats.getDataTypeString().c_str()); + ECOLOGV("ECOSession get new stats type: %s", stats.getDataTypeString().c_str()); std::unique_lock<std::mutex> lock(mStatsQueueLock); mStatsQueue.push_back(stats); mStatsQueueWaitCV.notify_all(); @@ -407,7 +408,7 @@ Status ECOSession::getNumOfProviders(int32_t* _aidl_return) { } /*virtual*/ void ECOSession::binderDied(const wp<IBinder>& /*who*/) { - ALOGV("binderDied"); + ECOLOGV("binderDied"); } } // namespace eco diff --git a/media/eco/ECOUtils.cpp b/media/eco/ECOUtils.cpp index 533b731..c8edac4 100644 --- a/media/eco/ECOUtils.cpp +++ b/media/eco/ECOUtils.cpp @@ -32,7 +32,7 @@ ECOData SimpleEncoderConfig::toEcoData(ECOData::ECODatatype dataType) { data.setInt32(ENCODER_LEVEL, mLevel); data.setInt32(ENCODER_TARGET_BITRATE_BPS, mTargetBitrate); data.setInt32(ENCODER_KFI_FRAMES, mKeyFrameIntervalFrames); - data.setFloat(ENCODER_FRAMERATE_FPS, mFramerateFps); + data.setFloat(ENCODER_FRAMERATE_FPS, mFrameRateFps); return data; } @@ -41,7 +41,7 @@ ECOData SimpleEncodedFrameData::toEcoData(ECOData::ECODatatype dataType) { ECOData data(dataType, systemTime(SYSTEM_TIME_BOOTTIME)); data.setString(KEY_STATS_TYPE, VALUE_STATS_TYPE_FRAME); data.setInt32(FRAME_NUM, mFrameNum); - data.setInt32(FRAME_TYPE, mFrameType); + data.setInt8(FRAME_TYPE, mFrameType); data.setInt64(FRAME_PTS_US, mFramePtsUs); data.setInt32(FRAME_AVG_QP, mAvgQp); data.setInt32(FRAME_SIZE_BYTES, mFrameSizeBytes); diff --git a/media/eco/include/eco/ECODebug.h b/media/eco/include/eco/ECODebug.h index 904b639..1b25a33 100644 --- a/media/eco/include/eco/ECODebug.h +++ b/media/eco/include/eco/ECODebug.h @@ -18,6 +18,7 @@ #define ANDROID_MEDIA_ECO_DEBUG_H_ #include <cutils/atomic.h> +#include <cutils/properties.h> #include "ECOData.h" @@ -25,8 +26,27 @@ namespace android { namespace media { namespace eco { -// Convenience methods for constructing binder::Status objects for error returns +static const char* kDebugLogsLevelProperty = "media.ecoservice.log.level"; + +// A debug variable that should only be accessed by ECOService through updateLogLevel. It is rare +// that this variable will have race condition. But if so, it is ok as this is just for debugging. +extern uint32_t gECOLogLevel; + +enum ECOLogLevel : uint32_t { + ECO_MSGLEVEL_DEBUG = 0x01, ///< debug logs + ECO_MSGLEVEL_VERBOSE = 0x02, ///< very detailed logs + ECO_MSGLEVEL_ALL = 0x03, ///< both debug logs and detailed logs +}; + +#define ECOLOGV(format, args...) ALOGD_IF((gECOLogLevel & ECO_MSGLEVEL_VERBOSE), format, ##args) +#define ECOLOGD(format, args...) ALOGD_IF((gECOLogLevel & ECO_MSGLEVEL_DEBUG), format, ##args) +#define ECOLOGI(format, args...) ALOGI(format, ##args) +#define ECOLOGW(format, args...) ALOGW(format, ##args) +#define ECOLOGE(format, args...) ALOGE(format, ##args) +void updateLogLevel(); + +// Convenience methods for constructing binder::Status objects for error returns #define STATUS_ERROR(errorCode, errorString) \ binder::Status::fromServiceSpecificError( \ errorCode, String8::format("%s:%d: %s", __FUNCTION__, __LINE__, errorString)) @@ -36,8 +56,6 @@ namespace eco { errorCode, \ String8::format("%s:%d: " errorString, __FUNCTION__, __LINE__, __VA_ARGS__)) -// ---------------------------------------------------------------------------- - } // namespace eco } // namespace media } // namespace android diff --git a/media/eco/include/eco/ECOService.h b/media/eco/include/eco/ECOService.h index 3fa0535..d7c129d 100644 --- a/media/eco/include/eco/ECOService.h +++ b/media/eco/include/eco/ECOService.h @@ -23,6 +23,7 @@ #include <list> +#include "eco/ECODebug.h" #include "eco/ECOService.h" #include "eco/ECOSession.h" diff --git a/media/eco/include/eco/ECOUtils.h b/media/eco/include/eco/ECOUtils.h index f9fa129..e5bbfcc 100644 --- a/media/eco/include/eco/ECOUtils.h +++ b/media/eco/include/eco/ECOUtils.h @@ -60,7 +60,7 @@ struct SimpleEncoderConfig { int32_t mKeyFrameIntervalFrames; // Frame rate in frames per second. -1 means unavailable. - int32_t mFramerateFps; + float mFrameRateFps; SimpleEncoderConfig() : mEncoderName(""), @@ -69,7 +69,7 @@ struct SimpleEncoderConfig { mLevel(-1), mTargetBitrate(-1), mKeyFrameIntervalFrames(-1), - mFramerateFps(-1) {} + mFrameRateFps(-1) {} SimpleEncoderConfig(const std::string& name, int32_t codecType, int32_t profile, int32_t level, int32_t bitrate, int32_t kfi, float framerateFps) @@ -79,7 +79,7 @@ struct SimpleEncoderConfig { mLevel(level), mTargetBitrate(bitrate), mKeyFrameIntervalFrames(kfi), - mFramerateFps(framerateFps) {} + mFrameRateFps(framerateFps) {} // Convert this SimpleEncoderConfig to ECOData with dataType. ECOData toEcoData(ECOData::ECODatatype dataType); |