diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-05-11 05:08:34 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-05-11 05:08:34 +0000 |
commit | 6de52b08a8859ba6a4363a0a61e8a2d1af09d85a (patch) | |
tree | 24ce725e4e7d3d9cccf2df15100cb13f9ca012dd | |
parent | 1322f13349b64287f663db5dfcdb49083cead1ea (diff) | |
parent | 2033451c902c6172ffc4ec34ea2370a5843e4b63 (diff) | |
download | av-aml_mpr_331112050.tar.gz |
Snap for 8570526 from 2033451c902c6172ffc4ec34ea2370a5843e4b63 to mainline-mediaprovider-releaseaml_mpr_331918000aml_mpr_331812020aml_mpr_331711020aml_mpr_331613010aml_mpr_331512020aml_mpr_331412040aml_mpr_331311080aml_mpr_331112050aml_mpr_331112030aml_mpr_331011070aml_mpr_330911040aml_mpr_330811020android13-mainline-mediaprovider-release
Change-Id: Ide6bec8c19b91b1d9d055fceebc004b773a1c0d4
-rw-r--r-- | Android.bp | 5 | ||||
-rw-r--r-- | METADATA | 3 | ||||
-rw-r--r-- | OWNERS | 7 | ||||
-rw-r--r-- | media/eco/Android.bp | 16 | ||||
-rw-r--r-- | media/eco/ECOC2Utils.cpp | 154 | ||||
-rw-r--r-- | media/eco/ECOServiceStatsProvider.cpp | 130 | ||||
-rw-r--r-- | media/eco/ECOSession.cpp | 4 | ||||
-rw-r--r-- | media/eco/OWNERS | 3 | ||||
-rw-r--r-- | media/eco/include/eco/ECOC2Utils.h | 49 | ||||
-rw-r--r-- | media/eco/include/eco/ECOServiceStatsProvider.h | 28 | ||||
-rw-r--r-- | media/eco/tests/Android.bp | 7 |
11 files changed, 384 insertions, 22 deletions
@@ -3,3 +3,8 @@ soong_namespace { "hardware/google/interfaces", ], } + +package { + // See: http://go/android-license-faq + default_applicable_licenses: ["Android-Apache-2.0"], +} diff --git a/METADATA b/METADATA new file mode 100644 index 0000000..d97975c --- /dev/null +++ b/METADATA @@ -0,0 +1,3 @@ +third_party { + license_type: NOTICE +} @@ -1,20 +1,13 @@ -chz@google.com -dwkang@google.com elaurent@google.com essick@google.com -hkuang@google.com hunga@google.com jmtrivi@google.com krocard@google.com lajos@google.com -marcone@google.com mnaganov@google.com -pawin@google.com philburk@google.com pmclean@google.com -rachad@google.com rago@google.com robertshih@google.com taklee@google.com -wjia@google.com wonsik@google.com diff --git a/media/eco/Android.bp b/media/eco/Android.bp index 0475861..18bc547 100644 --- a/media/eco/Android.bp +++ b/media/eco/Android.bp @@ -1,3 +1,8 @@ +package { + // See: http://go/android-license-faq + default_applicable_licenses: ["Android-Apache-2.0"], +} + filegroup { name: "libmedia_ecoservice_aidl", srcs: [ @@ -20,6 +25,8 @@ cc_library_shared { "ECOService.cpp", "ECOSession.cpp", "ECOUtils.cpp", + "ECOServiceStatsProvider.cpp", + "ECOC2Utils.cpp", ], aidl: { @@ -38,16 +45,19 @@ cc_library_shared { local_include_dirs: [ "include", ], + export_include_dirs: [ + "include", + ], shared_libs: [ "libbinder", "libcutils", "liblog", "libutils", + "libcodec2_hidl@1.0", ], - - export_include_dirs: [ - "include", + export_shared_lib_headers: [ + "libbinder", ], sanitize: { diff --git a/media/eco/ECOC2Utils.cpp b/media/eco/ECOC2Utils.cpp new file mode 100644 index 0000000..8952626 --- /dev/null +++ b/media/eco/ECOC2Utils.cpp @@ -0,0 +1,154 @@ +/* + * Copyright (C) 2020 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 "ECOC2Utils" +#include "eco/ECOC2Utils.h" + +namespace android { +namespace media { +namespace eco { + +int C2MediaType2ECOCodecType(std::shared_ptr<C2PortMediaTypeSetting::output> mediatype) { + std::string_view mime = mediatype->m.value; + if (!mime.compare("video/avc")) { + return CodecTypeAVC; + } else if (!mime.compare("video/hevc")) { + return CodecTypeHEVC; + } + return CodecTypeUnknown; +} + +int C2Profile2ECOProfile(C2Config::profile_t profile) { + switch (profile) { + case PROFILE_AVC_BASELINE: + return AVCProfileBaseline; + case PROFILE_AVC_CONSTRAINED_BASELINE: + return AVCProfileConstrainedBaseline; + case PROFILE_AVC_MAIN: + return AVCProfileMain; + case PROFILE_AVC_HIGH: + return AVCProfileHigh; + case PROFILE_HEVC_MAIN: + return HEVCProfileMain; + default: + return 0; + } +} + +int C2Level2ECOLevel(C2Config::level_t level) { + switch (level) { + case LEVEL_AVC_1: + return AVCLevel1; + case LEVEL_AVC_1B: + return AVCLevel1b; + case LEVEL_AVC_1_1: + return AVCLevel11; + case LEVEL_AVC_1_2: + return AVCLevel12; + case LEVEL_AVC_1_3: + return AVCLevel13; + case LEVEL_AVC_2: + return AVCLevel2; + case LEVEL_AVC_2_1: + return AVCLevel21; + case LEVEL_AVC_2_2: + return AVCLevel22; + case LEVEL_AVC_3: + return AVCLevel3; + case LEVEL_AVC_3_1: + return AVCLevel31; + case LEVEL_AVC_3_2: + return AVCLevel32; + case LEVEL_AVC_4 : + return AVCLevel4; + case LEVEL_AVC_4_1: + return AVCLevel41; + case LEVEL_AVC_5: + return AVCLevel5; + case LEVEL_AVC_5_1: + return AVCLevel51; + case LEVEL_AVC_5_2: + return AVCLevel52; + case LEVEL_AVC_6: + return AVCLevel6; + case LEVEL_AVC_6_1: + return AVCLevel61; + case LEVEL_AVC_6_2: + return AVCLevel62; + case LEVEL_HEVC_MAIN_1: + return HEVCMainTierLevel1; + case LEVEL_HEVC_MAIN_2: + return HEVCMainTierLevel2; + case LEVEL_HEVC_MAIN_2_1: + return HEVCMainTierLevel21; + case LEVEL_HEVC_MAIN_3: + return HEVCMainTierLevel3; + case LEVEL_HEVC_MAIN_3_1: + return HEVCMainTierLevel31; + case LEVEL_HEVC_MAIN_4: + return HEVCMainTierLevel4; + case LEVEL_HEVC_MAIN_4_1: + return HEVCMainTierLevel41; + case LEVEL_HEVC_MAIN_5: + return HEVCMainTierLevel5; + case LEVEL_HEVC_MAIN_5_1: + return HEVCMainTierLevel51; + case LEVEL_HEVC_MAIN_5_2: + return HEVCMainTierLevel52; + case LEVEL_HEVC_MAIN_6: + return HEVCMainTierLevel6; + case LEVEL_HEVC_MAIN_6_1: + return HEVCMainTierLevel61; + case LEVEL_HEVC_MAIN_6_2: + return HEVCMainTierLevel62; + case LEVEL_HEVC_HIGH_4: + return HEVCHighTierLevel4; + case LEVEL_HEVC_HIGH_4_1: + return HEVCHighTierLevel41; + case LEVEL_HEVC_HIGH_5 : + return HEVCHighTierLevel5; + case LEVEL_HEVC_HIGH_5_1: + return HEVCHighTierLevel51; + case LEVEL_HEVC_HIGH_5_2: + return HEVCHighTierLevel52; + case LEVEL_HEVC_HIGH_6: + return HEVCHighTierLevel6; + case LEVEL_HEVC_HIGH_6_1: + return HEVCHighTierLevel61; + case LEVEL_HEVC_HIGH_6_2: + return HEVCHighTierLevel62; + default: + return 0; + } +} + +int C2PictureType2ECOFrameType(C2Config::picture_type_t frametype) { + switch (frametype) { + case I_FRAME: + return FrameTypeI; + case P_FRAME: + return FrameTypeP; + case B_FRAME: + return FrameTypeB; + default: + return FrameTypeUnknown; + } +} + +} // namespace eco +} // namespace media +} // namespace android diff --git a/media/eco/ECOServiceStatsProvider.cpp b/media/eco/ECOServiceStatsProvider.cpp new file mode 100644 index 0000000..8ca7ef0 --- /dev/null +++ b/media/eco/ECOServiceStatsProvider.cpp @@ -0,0 +1,130 @@ +/* + * Copyright (C) 2020 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 "ECOServiceStatsProvider" +#include <eco/ECOServiceStatsProvider.h> + +namespace android { +namespace media { +namespace eco { + +ECOServiceStatsProvider::ECOServiceStatsProvider( + int32_t width, int32_t height, bool isCameraRecording, + android::sp<IECOSession>& session, const char* name) + : BnECOServiceStatsProvider(), + mWidth(width), + mHeight(height), + mIsCameraRecording(isCameraRecording), + mECOSession(session), + mProviderName(name) { + ALOGD("%s, construct with w: %d, h: %d, isCameraRecording: %d, ProviderName:%s", + __func__, width, height, isCameraRecording, name); +} + +Status ECOServiceStatsProvider::getType(int32_t* _aidl_return) { + *_aidl_return = STATS_PROVIDER_TYPE_VIDEO_ENCODER; + return Status::ok(); +} + +Status ECOServiceStatsProvider::getName(::android::String16* _aidl_return) { + *_aidl_return = String16(mProviderName); + return Status::ok(); +} + +Status ECOServiceStatsProvider::getECOSession(android::sp<::android::IBinder>* _aidl_return) { + *_aidl_return = IInterface::asBinder(mECOSession); + return Status::ok(); +} + +Status ECOServiceStatsProvider::isCameraRecording(bool* _aidl_return) { + *_aidl_return = mIsCameraRecording; + return Status::ok(); +} + +void ECOServiceStatsProvider::binderDied(const wp<IBinder>& /* who */) {} + +bool ECOServiceStatsProvider::updateStats(const ECOData& data) { + bool ret = false; + if (mECOSession) { + Status status = mECOSession->pushNewStats(data, &ret); + return ret; + } + return ret; +} + +bool ECOServiceStatsProvider::addProvider() { + bool ret = false; + if (mECOSession) { + ECOData providerConfig(ECOData::DATA_TYPE_STATS_PROVIDER_CONFIG, systemTime() / 1000); + mECOSession->addStatsProvider(this, providerConfig, &ret); + return ret; + } + return ret; +} + +bool ECOServiceStatsProvider::removeProvider() { + bool ret = false; + if (mECOSession) { + mECOSession->removeStatsProvider(this, &ret); + return ret; + } + return ret; +} + +android::sp<ECOServiceStatsProvider> ECOServiceStatsProvider::create( + int32_t width, int32_t height, bool isCameraRecording, const char* name) { + + android::sp<android::IServiceManager> sm = android::defaultServiceManager(); + android::sp<android::IBinder> binder = sm->getService(String16("media.ecoservice")); + + if (binder == nullptr) { + ALOGE("Failed to connect to ecoservice"); + return nullptr; + } + + android::sp<IECOService> service = android::interface_cast<IECOService>(binder); + ALOGI("Connected to ecoservice"); + + // Obtain the ECOSession and add the listener to the service. + android::sp<IECOSession> session = nullptr; + + service->obtainSession(width, height, isCameraRecording, &session); + + if (session == nullptr) { + ALOGE("Failed to obtain an ECO session"); + return nullptr; + } + ALOGI("Obtained an ECO session"); + + return new ECOServiceStatsProvider(width, height, isCameraRecording, session, name); +} + +float ECOServiceStatsProvider::getFramerate(int64_t currTimestamp) { + float framerate; + int64_t timeInterval = currTimestamp - mLastFrameTimestamp; + if (timeInterval == 0) { + framerate = 0.0; + } else { + framerate = 1E6 / (currTimestamp - mLastFrameTimestamp); + } + mLastFrameTimestamp = currTimestamp; + return framerate; +} + +} // namespace eco +} // namespace media +} // namespace android diff --git a/media/eco/ECOSession.cpp b/media/eco/ECOSession.cpp index a7b919f..ea5d552 100644 --- a/media/eco/ECOSession.cpp +++ b/media/eco/ECOSession.cpp @@ -53,10 +53,10 @@ using android::sp; // static sp<ECOSession> ECOSession::createECOSession(int32_t width, int32_t height, bool isCameraRecording) { - // Only support up to 720P. + // Only support up to 1080P. // TODO: Support the same resolution as in EAF. if (width <= 0 || height <= 0 || width > 5120 || height > 5120 || - width > 1280 * 720 / height) { + width > 1920 * 1080 / height) { ECOLOGE("Failed to create ECOSession with w: %d, h: %d, isCameraRecording: %d", width, height, isCameraRecording); return nullptr; diff --git a/media/eco/OWNERS b/media/eco/OWNERS index 2239c4f..73a70e2 100644 --- a/media/eco/OWNERS +++ b/media/eco/OWNERS @@ -1,2 +1 @@ -hkuang@google.com -derekpang@google.com
\ No newline at end of file +derekpang@google.com diff --git a/media/eco/include/eco/ECOC2Utils.h b/media/eco/include/eco/ECOC2Utils.h new file mode 100644 index 0000000..1cdf506 --- /dev/null +++ b/media/eco/include/eco/ECOC2Utils.h @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2020 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. + */ + +// Helper classes and functions to be used by provider and listener. +#ifndef ANDROID_MEDIA_ECO_C2UTILS_H_ +#define ANDROID_MEDIA_ECO_C2UTILS_H_ + +#include <cutils/atomic.h> +#include <utils/Errors.h> + +#include <C2Config.h> +#include "ECOData.h" +#include "ECODataKey.h" +#include "ECOServiceConstants.h" + +namespace android { +namespace media { +namespace eco { + +// Convert C2MediaType to ECOCodecType +extern int C2MediaType2ECOCodecType(std::shared_ptr<C2PortMediaTypeSetting::output> mediatype); + +// Convert C2Profile to ECOProfile +extern int C2Profile2ECOProfile(C2Config::profile_t profile); + +// Convert C2Level to ECOLevel +extern int C2Level2ECOLevel(C2Config::level_t level); + +// Convert C2PictureType to ECOFrameType +extern int C2PictureType2ECOFrameType(C2Config::picture_type_t frametype); + +} // namespace eco +} // namespace media +} // namespace android + +#endif // ANDROID_MEDIA_ECO_C2UTILS_H_ diff --git a/media/eco/include/eco/ECOServiceStatsProvider.h b/media/eco/include/eco/ECOServiceStatsProvider.h index a6e1586..ed0ca7d 100644 --- a/media/eco/include/eco/ECOServiceStatsProvider.h +++ b/media/eco/include/eco/ECOServiceStatsProvider.h @@ -19,6 +19,7 @@ #include <android/media/eco/BnECOServiceStatsProvider.h> #include <android/media/eco/IECOSession.h> +#include <android/media/eco/IECOService.h> #include <binder/BinderService.h> #include <condition_variable> @@ -27,6 +28,7 @@ #include <thread> #include "ECOData.h" +#include "ECOServiceConstants.h" namespace android { namespace media { @@ -43,20 +45,32 @@ class ECOServiceStatsProvider : public BinderService<IECOServiceStatsProvider>, friend class BinderService<IECOServiceStatsProvider>; public: - // Create a ECOServiceStatsProvider with specifed width, height and isCameraRecording. - ECOServiceStatsProvider(int32_t width, int32_t height, bool isCameraRecording); - virtual ~ECOServiceStatsProvider() {} - virtual Status getType(int32_t* _aidl_return) = 0; - virtual Status getName(::android::String16* _aidl_return) = 0; - virtual Status getECOSession(::android::sp<::android::IBinder>* _aidl_return) = 0; - virtual Status isCameraRecording(bool* _aidl_return) = 0; + virtual Status getType(int32_t* _aidl_return); + virtual Status getName(::android::String16* _aidl_return); + virtual Status getECOSession(::android::sp<::android::IBinder>* _aidl_return); + virtual Status isCameraRecording(bool* _aidl_return); // IBinder::DeathRecipient implementation virtual void binderDied(const wp<IBinder>& who); + bool updateStats(const ECOData& data); + bool addProvider(); + bool removeProvider(); + float getFramerate(int64_t currTimestamp); + static android::sp<ECOServiceStatsProvider> create( + int32_t width, int32_t height, bool isCameraRecording, const char* name); + private: + ECOServiceStatsProvider(int32_t width, int32_t height, bool isCameraRecording, + android::sp<IECOSession>& session, const char* name); + int32_t mWidth = 0; + int32_t mHeight = 0; + bool mIsCameraRecording = false; + android::sp<IECOSession> mECOSession = nullptr; + const char* mProviderName = nullptr; + int64_t mLastFrameTimestamp = 0; }; } // namespace eco diff --git a/media/eco/tests/Android.bp b/media/eco/tests/Android.bp index 6eb3015..70390cc 100644 --- a/media/eco/tests/Android.bp +++ b/media/eco/tests/Android.bp @@ -1,3 +1,8 @@ +package { + // See: http://go/android-license-faq + default_applicable_licenses: ["Android-Apache-2.0"], +} + cc_defaults{ name : "libmedia_ecoservice_tests_defaults", cflags : [ @@ -54,4 +59,4 @@ cc_test { "liblog", "libmedia_ecoservice", ], -}
\ No newline at end of file +} |