19762338dSopenharmony_ci/* 29762338dSopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd. 39762338dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 49762338dSopenharmony_ci * you may not use this file except in compliance with the License. 59762338dSopenharmony_ci * You may obtain a copy of the License at 69762338dSopenharmony_ci * 79762338dSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 89762338dSopenharmony_ci * 99762338dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 109762338dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 119762338dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 129762338dSopenharmony_ci * See the License for the specific language governing permissions and 139762338dSopenharmony_ci * limitations under the License. 149762338dSopenharmony_ci */ 159762338dSopenharmony_ci 169762338dSopenharmony_ci#include <OMX_Component.h> 179762338dSopenharmony_ci#include <OMX_Core.h> 189762338dSopenharmony_ci#include <OMX_Video.h> 199762338dSopenharmony_ci#include <OMX_VideoExt.h> 209762338dSopenharmony_ci#include <gtest/gtest.h> 219762338dSopenharmony_ci#include <hdf_log.h> 229762338dSopenharmony_ci#include <securec.h> 239762338dSopenharmony_ci#include <servmgr_hdi.h> 249762338dSopenharmony_ci#include <vector> 259762338dSopenharmony_ci#include <benchmark/benchmark.h> 269762338dSopenharmony_ci#include "codec_omx_ext.h" 279762338dSopenharmony_ci#include "v3_0/codec_callback_service.h" 289762338dSopenharmony_ci#include "v3_0/icodec_component.h" 299762338dSopenharmony_ci#include "v3_0/icodec_component_manager.h" 309762338dSopenharmony_ci#include "v1_0/display_composer_type.h" 319762338dSopenharmony_ci#include "v1_0/display_buffer_type.h" 329762338dSopenharmony_ci#include "v1_0/include/idisplay_buffer.h" 339762338dSopenharmony_ci 349762338dSopenharmony_ci#define HDF_LOG_TAG codec_hdi_test 359762338dSopenharmony_ci#define COMPONENTNUM 0 369762338dSopenharmony_ci#define TUNNELECOMP 1002 379762338dSopenharmony_ci#define TUNNELEDPORT 101 389762338dSopenharmony_ci 399762338dSopenharmony_ciusing namespace std; 409762338dSopenharmony_ciusing namespace testing::ext; 419762338dSopenharmony_ciusing OHOS::sptr; 429762338dSopenharmony_ciusing OHOS::HDI::Base::NativeBuffer; 439762338dSopenharmony_ciusing namespace OHOS::HDI::Codec::V3_0; 449762338dSopenharmony_ciusing namespace OHOS::HDI::Display::Buffer::V1_0; 459762338dSopenharmony_ciusing namespace OHOS::HDI::Display::Composer::V1_0; 469762338dSopenharmony_cinamespace { 479762338dSopenharmony_ciconstexpr int32_t WIDTH = 640; 489762338dSopenharmony_ci#ifdef SUPPORT_OMX 499762338dSopenharmony_ciconstexpr uint32_t MAX_ROLE_INDEX = 1000; 509762338dSopenharmony_ci#endif 519762338dSopenharmony_ciconstexpr int FD_DEFAULT = -1; 529762338dSopenharmony_ciconstexpr int64_t APP_DATA = 3; 539762338dSopenharmony_ciconstexpr int32_t HEIGHT = 480; 549762338dSopenharmony_ciconstexpr int32_t BUFFER_SIZE = WIDTH * HEIGHT * 3; 559762338dSopenharmony_ciconstexpr int32_t FRAMERATE = 30 << 16; 569762338dSopenharmony_ciconstexpr uint32_t BUFFER_ID_ERROR = 65000; 579762338dSopenharmony_cistatic IDisplayBuffer *gralloc_ = nullptr; 589762338dSopenharmony_cistatic sptr<ICodecComponent> component_ = nullptr; 599762338dSopenharmony_cistatic sptr<ICodecCallback> callback_ = nullptr; 609762338dSopenharmony_cistatic sptr<ICodecComponentManager> manager_ = nullptr; 619762338dSopenharmony_cistatic OHOS::HDI::Codec::V3_0::CodecVersionType version_; 629762338dSopenharmony_cistatic inline std::string compName_ = ""; 639762338dSopenharmony_ci 649762338dSopenharmony_ciclass CodecBenchmarkOmxTest : public benchmark::Fixture { 659762338dSopenharmony_cipublic: 669762338dSopenharmony_ci enum class PortIndex { PORT_INDEX_INPUT = 0, PORT_INDEX_OUTPUT = 1 }; 679762338dSopenharmony_ci template <typename T> 689762338dSopenharmony_ci void InitParam(T ¶m) 699762338dSopenharmony_ci { 709762338dSopenharmony_ci memset_s(¶m, sizeof(param), 0x0, sizeof(param)); 719762338dSopenharmony_ci param.nSize = sizeof(param); 729762338dSopenharmony_ci param.nVersion.nVersion = 1; 739762338dSopenharmony_ci } 749762338dSopenharmony_ci 759762338dSopenharmony_ci void InitOmxCodecBuffer(OmxCodecBuffer& buffer, CodecBufferType type) 769762338dSopenharmony_ci { 779762338dSopenharmony_ci buffer.bufferType = type; 789762338dSopenharmony_ci buffer.fenceFd = -1; 799762338dSopenharmony_ci buffer.version = version_; 809762338dSopenharmony_ci buffer.allocLen = BUFFER_SIZE; 819762338dSopenharmony_ci buffer.fd = FD_DEFAULT; 829762338dSopenharmony_ci buffer.bufferhandle = nullptr; 839762338dSopenharmony_ci buffer.pts = 0; 849762338dSopenharmony_ci buffer.flag = 0; 859762338dSopenharmony_ci buffer.size = sizeof(OmxCodecBuffer); 869762338dSopenharmony_ci buffer.type = READ_ONLY_TYPE; 879762338dSopenharmony_ci } 889762338dSopenharmony_ci 899762338dSopenharmony_ci void Init() 909762338dSopenharmony_ci { 919762338dSopenharmony_ci int32_t count = 0; 929762338dSopenharmony_ci (void)manager_->GetComponentNum(count); 939762338dSopenharmony_ci if (count > 0) { 949762338dSopenharmony_ci std::vector<CodecCompCapability> capList; 959762338dSopenharmony_ci auto err = manager_->GetComponentCapabilityList(capList, count); 969762338dSopenharmony_ci ASSERT_TRUE(err == HDF_SUCCESS); 979762338dSopenharmony_ci compName_ = capList[0].compName; 989762338dSopenharmony_ci } 999762338dSopenharmony_ci 1009762338dSopenharmony_ci if (manager_ == nullptr) { 1019762338dSopenharmony_ci return; 1029762338dSopenharmony_ci } 1039762338dSopenharmony_ci callback_ = new CodecCallbackService(); 1049762338dSopenharmony_ci if (callback_ == nullptr) { 1059762338dSopenharmony_ci return; 1069762338dSopenharmony_ci } 1079762338dSopenharmony_ci if (compName_.empty()) { 1089762338dSopenharmony_ci return; 1099762338dSopenharmony_ci } 1109762338dSopenharmony_ci 1119762338dSopenharmony_ci auto ret = manager_->CreateComponent(component_, componentId_, compName_.data(), 1129762338dSopenharmony_ci APP_DATA, callback_); 1139762338dSopenharmony_ci ASSERT_TRUE(component_ != nullptr); 1149762338dSopenharmony_ci if (ret != HDF_SUCCESS) { 1159762338dSopenharmony_ci return; 1169762338dSopenharmony_ci } 1179762338dSopenharmony_ci struct CompVerInfo verInfo; 1189762338dSopenharmony_ci ret = component_->GetComponentVersion(verInfo); 1199762338dSopenharmony_ci ASSERT_TRUE(component_ != nullptr); 1209762338dSopenharmony_ci if (ret != HDF_SUCCESS) { 1219762338dSopenharmony_ci return; 1229762338dSopenharmony_ci } 1239762338dSopenharmony_ci version_ = verInfo.compVersion; 1249762338dSopenharmony_ci return; 1259762338dSopenharmony_ci } 1269762338dSopenharmony_ci 1279762338dSopenharmony_ci void SetUp(benchmark::State &state) 1289762338dSopenharmony_ci { 1299762338dSopenharmony_ci manager_ = ICodecComponentManager::Get(); 1309762338dSopenharmony_ci gralloc_ = IDisplayBuffer::Get(); 1319762338dSopenharmony_ci Init(); 1329762338dSopenharmony_ci if (manager_ == nullptr) { 1339762338dSopenharmony_ci std::cout<<"GetCodecComponentManager ret nullptr"<<std::endl; 1349762338dSopenharmony_ci return; 1359762338dSopenharmony_ci } 1369762338dSopenharmony_ci } 1379762338dSopenharmony_ci 1389762338dSopenharmony_ci void TearDown(benchmark::State &state) 1399762338dSopenharmony_ci { 1409762338dSopenharmony_ci if (manager_ != nullptr && component_ != nullptr) { 1419762338dSopenharmony_ci manager_->DestroyComponent(componentId_); 1429762338dSopenharmony_ci } 1439762338dSopenharmony_ci component_ = nullptr; 1449762338dSopenharmony_ci callback_ = nullptr; 1459762338dSopenharmony_ci manager_ = nullptr; 1469762338dSopenharmony_ci gralloc_ = nullptr; 1479762338dSopenharmony_ci } 1489762338dSopenharmony_ci 1499762338dSopenharmony_cipublic: 1509762338dSopenharmony_ci uint32_t componentId_ = 0; 1519762338dSopenharmony_ci const static uint32_t inputIndex = static_cast<uint32_t>(PortIndex::PORT_INDEX_INPUT); 1529762338dSopenharmony_ci const static uint32_t outputIndex = static_cast<uint32_t>(PortIndex::PORT_INDEX_OUTPUT); 1539762338dSopenharmony_ci}; 1549762338dSopenharmony_ci 1559762338dSopenharmony_citemplate <typename T> 1569762338dSopenharmony_civoid ObjectToVector(T ¶m, std::vector<int8_t> &vec) 1579762338dSopenharmony_ci{ 1589762338dSopenharmony_ci int8_t *paramPointer = reinterpret_cast<int8_t *>(¶m); 1599762338dSopenharmony_ci vec.insert(vec.end(), paramPointer, paramPointer + sizeof(param)); 1609762338dSopenharmony_ci} 1619762338dSopenharmony_ci 1629762338dSopenharmony_ciBENCHMARK_F(CodecBenchmarkOmxTest, GetComponentVersion)(benchmark::State &state) 1639762338dSopenharmony_ci{ 1649762338dSopenharmony_ci ASSERT_TRUE(component_ != nullptr); 1659762338dSopenharmony_ci int32_t ret; 1669762338dSopenharmony_ci struct CompVerInfo verInfo; 1679762338dSopenharmony_ci for (auto _ : state) { 1689762338dSopenharmony_ci ret = component_->GetComponentVersion(verInfo); 1699762338dSopenharmony_ci } 1709762338dSopenharmony_ci ASSERT_EQ(ret, HDF_SUCCESS); 1719762338dSopenharmony_ci} 1729762338dSopenharmony_ci 1739762338dSopenharmony_ciBENCHMARK_REGISTER_F(CodecBenchmarkOmxTest, GetComponentVersion)-> 1749762338dSopenharmony_ci Iterations(100)->Repetitions(3)->ReportAggregatesOnly(); 1759762338dSopenharmony_ci 1769762338dSopenharmony_ciBENCHMARK_F(CodecBenchmarkOmxTest, GetParameter)(benchmark::State &state) 1779762338dSopenharmony_ci{ 1789762338dSopenharmony_ci ASSERT_TRUE(component_ != nullptr); 1799762338dSopenharmony_ci int32_t ret; 1809762338dSopenharmony_ci std::vector<int8_t> inParam; 1819762338dSopenharmony_ci std::vector <int8_t> outParam; 1829762338dSopenharmony_ci for (auto _ : state) { 1839762338dSopenharmony_ci ret = component_->GetParameter(OMX_IndexParamVideoPortFormat, inParam, outParam); 1849762338dSopenharmony_ci } 1859762338dSopenharmony_ci ASSERT_NE(ret, HDF_SUCCESS); 1869762338dSopenharmony_ci} 1879762338dSopenharmony_ci 1889762338dSopenharmony_ciBENCHMARK_REGISTER_F(CodecBenchmarkOmxTest, GetParameter)-> 1899762338dSopenharmony_ci Iterations(100)->Repetitions(3)->ReportAggregatesOnly(); 1909762338dSopenharmony_ci 1919762338dSopenharmony_ciBENCHMARK_F(CodecBenchmarkOmxTest, SetParameter)(benchmark::State &state) 1929762338dSopenharmony_ci{ 1939762338dSopenharmony_ci ASSERT_TRUE(component_ != nullptr); 1949762338dSopenharmony_ci int32_t ret; 1959762338dSopenharmony_ci OMX_VIDEO_PARAM_PORTFORMATTYPE param; 1969762338dSopenharmony_ci InitParam(param); 1979762338dSopenharmony_ci param.nPortIndex = inputIndex; 1989762338dSopenharmony_ci std::vector<int8_t> paramVec; 1999762338dSopenharmony_ci ObjectToVector(param, paramVec); 2009762338dSopenharmony_ci for (auto _ : state) { 2019762338dSopenharmony_ci ret = component_->SetParameter(OMX_IndexParamVideoPortFormat, paramVec); 2029762338dSopenharmony_ci } 2039762338dSopenharmony_ci ASSERT_EQ(ret, HDF_SUCCESS); 2049762338dSopenharmony_ci} 2059762338dSopenharmony_ci 2069762338dSopenharmony_ciBENCHMARK_REGISTER_F(CodecBenchmarkOmxTest, SetParameter)-> 2079762338dSopenharmony_ci Iterations(100)->Repetitions(3)->ReportAggregatesOnly(); 2089762338dSopenharmony_ci 2099762338dSopenharmony_ciBENCHMARK_F(CodecBenchmarkOmxTest, GetConfig)(benchmark::State &state) 2109762338dSopenharmony_ci{ 2119762338dSopenharmony_ci ASSERT_TRUE(component_ != nullptr); 2129762338dSopenharmony_ci int32_t ret; 2139762338dSopenharmony_ci OMX_VIDEO_CONFIG_BITRATETYPE param; 2149762338dSopenharmony_ci InitParam(param); 2159762338dSopenharmony_ci param.nPortIndex = outputIndex; 2169762338dSopenharmony_ci std::vector<int8_t> inParam; 2179762338dSopenharmony_ci ObjectToVector(param, inParam); 2189762338dSopenharmony_ci std::vector<int8_t> outParam; 2199762338dSopenharmony_ci for (auto _ : state) { 2209762338dSopenharmony_ci ret = component_->GetConfig(OMX_IndexConfigVideoBitrate, inParam, outParam); 2219762338dSopenharmony_ci } 2229762338dSopenharmony_ci ASSERT_EQ(ret, HDF_SUCCESS); 2239762338dSopenharmony_ci} 2249762338dSopenharmony_ci 2259762338dSopenharmony_ciBENCHMARK_REGISTER_F(CodecBenchmarkOmxTest, GetConfig)-> 2269762338dSopenharmony_ci Iterations(100)->Repetitions(3)->ReportAggregatesOnly(); 2279762338dSopenharmony_ci 2289762338dSopenharmony_ciBENCHMARK_F(CodecBenchmarkOmxTest, SetConfig)(benchmark::State &state) 2299762338dSopenharmony_ci{ 2309762338dSopenharmony_ci ASSERT_TRUE(component_ != nullptr); 2319762338dSopenharmony_ci int32_t ret; 2329762338dSopenharmony_ci OMX_VIDEO_CONFIG_BITRATETYPE param; 2339762338dSopenharmony_ci InitParam(param); 2349762338dSopenharmony_ci param.nPortIndex = inputIndex; 2359762338dSopenharmony_ci param.nEncodeBitrate = FRAMERATE; 2369762338dSopenharmony_ci std::vector<int8_t> inParam; 2379762338dSopenharmony_ci ObjectToVector(param, inParam); 2389762338dSopenharmony_ci for (auto _ : state) { 2399762338dSopenharmony_ci ret = component_->SetConfig(OMX_IndexConfigVideoBitrate, inParam); 2409762338dSopenharmony_ci } 2419762338dSopenharmony_ci ASSERT_NE(ret, HDF_SUCCESS); 2429762338dSopenharmony_ci} 2439762338dSopenharmony_ci 2449762338dSopenharmony_ciBENCHMARK_REGISTER_F(CodecBenchmarkOmxTest, SetConfig)-> 2459762338dSopenharmony_ci Iterations(100)->Repetitions(3)->ReportAggregatesOnly(); 2469762338dSopenharmony_ci 2479762338dSopenharmony_ciBENCHMARK_F(CodecBenchmarkOmxTest, GetExtensionIndex)(benchmark::State &state) 2489762338dSopenharmony_ci{ 2499762338dSopenharmony_ci ASSERT_TRUE(component_ != nullptr); 2509762338dSopenharmony_ci int32_t ret; 2519762338dSopenharmony_ci uint32_t indexType = 0; 2529762338dSopenharmony_ci for (auto _ : state) { 2539762338dSopenharmony_ci ret = component_->GetExtensionIndex("OMX.Topaz.index.param.extended_test", indexType); 2549762338dSopenharmony_ci } 2559762338dSopenharmony_ci ASSERT_NE(ret, HDF_SUCCESS); 2569762338dSopenharmony_ci} 2579762338dSopenharmony_ci 2589762338dSopenharmony_ciBENCHMARK_REGISTER_F(CodecBenchmarkOmxTest, GetExtensionIndex)-> 2599762338dSopenharmony_ci Iterations(100)->Repetitions(3)->ReportAggregatesOnly(); 2609762338dSopenharmony_ci 2619762338dSopenharmony_ciBENCHMARK_F(CodecBenchmarkOmxTest, GetState)(benchmark::State &state) 2629762338dSopenharmony_ci{ 2639762338dSopenharmony_ci ASSERT_TRUE(component_ != nullptr); 2649762338dSopenharmony_ci int32_t ret; 2659762338dSopenharmony_ci CodecStateType codecState =CODEC_STATE_INVALID; 2669762338dSopenharmony_ci for (auto _ : state) { 2679762338dSopenharmony_ci ret = component_->GetState(codecState); 2689762338dSopenharmony_ci } 2699762338dSopenharmony_ci ASSERT_EQ(codecState, CODEC_STATE_LOADED); 2709762338dSopenharmony_ci ASSERT_EQ(ret, HDF_SUCCESS); 2719762338dSopenharmony_ci} 2729762338dSopenharmony_ci 2739762338dSopenharmony_ciBENCHMARK_REGISTER_F(CodecBenchmarkOmxTest, GetState)-> 2749762338dSopenharmony_ci Iterations(100)->Repetitions(3)->ReportAggregatesOnly(); 2759762338dSopenharmony_ci 2769762338dSopenharmony_ci#ifdef SUPPORT_OMX 2779762338dSopenharmony_ciBENCHMARK_F(CodecBenchmarkOmxTest, ComponentTunnelRequest)(benchmark::State &state) 2789762338dSopenharmony_ci{ 2799762338dSopenharmony_ci ASSERT_TRUE(component_ != nullptr); 2809762338dSopenharmony_ci int32_t ret; 2819762338dSopenharmony_ci const int32_t tunneledComp = TUNNELECOMP; 2829762338dSopenharmony_ci const uint32_t tunneledPort = TUNNELEDPORT; 2839762338dSopenharmony_ci OHOS::HDI::Codec::V3_0::CodecTunnelSetupType tunnelSetup; 2849762338dSopenharmony_ci tunnelSetup.supplier = OHOS::HDI::Codec::V3_0::CODEC_BUFFER_SUPPLY_INPUT; 2859762338dSopenharmony_ci for (auto _ : state) { 2869762338dSopenharmony_ci ret = component_->ComponentTunnelRequest(outputIndex, tunneledComp, tunneledPort, 2879762338dSopenharmony_ci tunnelSetup, tunnelSetup); 2889762338dSopenharmony_ci } 2899762338dSopenharmony_ci ASSERT_NE(ret, HDF_SUCCESS); 2909762338dSopenharmony_ci} 2919762338dSopenharmony_ci 2929762338dSopenharmony_ciBENCHMARK_REGISTER_F(CodecBenchmarkOmxTest, ComponentTunnelRequest)-> 2939762338dSopenharmony_ci Iterations(100)->Repetitions(3)->ReportAggregatesOnly(); 2949762338dSopenharmony_ci#endif 2959762338dSopenharmony_ci 2969762338dSopenharmony_ciBENCHMARK_F(CodecBenchmarkOmxTest, SendCommand)(benchmark::State &state) 2979762338dSopenharmony_ci{ 2989762338dSopenharmony_ci std::vector<int8_t> cmdData; 2999762338dSopenharmony_ci int32_t ret; 3009762338dSopenharmony_ci for (auto _ : state) { 3019762338dSopenharmony_ci Init(); 3029762338dSopenharmony_ci ret = component_->SendCommand(CODEC_COMMAND_STATE_SET, CODEC_STATE_IDLE, cmdData); 3039762338dSopenharmony_ci manager_->DestroyComponent(componentId_); 3049762338dSopenharmony_ci if (manager_ != nullptr && component_ != nullptr) { 3059762338dSopenharmony_ci manager_->DestroyComponent(componentId_); 3069762338dSopenharmony_ci } 3079762338dSopenharmony_ci component_ = nullptr; 3089762338dSopenharmony_ci callback_ = nullptr; 3099762338dSopenharmony_ci } 3109762338dSopenharmony_ci ASSERT_EQ(ret, HDF_SUCCESS); 3119762338dSopenharmony_ci} 3129762338dSopenharmony_ci 3139762338dSopenharmony_ciBENCHMARK_REGISTER_F(CodecBenchmarkOmxTest, SendCommand)-> 3149762338dSopenharmony_ci Iterations(100)->Repetitions(3)->ReportAggregatesOnly(); 3159762338dSopenharmony_ci 3169762338dSopenharmony_ciBENCHMARK_F(CodecBenchmarkOmxTest, AllocateBuffer)(benchmark::State &state) 3179762338dSopenharmony_ci{ 3189762338dSopenharmony_ci ASSERT_TRUE(component_ != nullptr); 3199762338dSopenharmony_ci int32_t ret; 3209762338dSopenharmony_ci struct OmxCodecBuffer allocBuffer; 3219762338dSopenharmony_ci InitOmxCodecBuffer(allocBuffer, CODEC_BUFFER_TYPE_VIRTUAL_ADDR); 3229762338dSopenharmony_ci struct OmxCodecBuffer outBuffer; 3239762338dSopenharmony_ci for (auto _ : state) { 3249762338dSopenharmony_ci ret = component_->AllocateBuffer(inputIndex, allocBuffer, outBuffer); 3259762338dSopenharmony_ci } 3269762338dSopenharmony_ci ASSERT_NE(ret, HDF_SUCCESS); 3279762338dSopenharmony_ci} 3289762338dSopenharmony_ci 3299762338dSopenharmony_ciBENCHMARK_REGISTER_F(CodecBenchmarkOmxTest, AllocateBuffer)-> 3309762338dSopenharmony_ci Iterations(100)->Repetitions(3)->ReportAggregatesOnly(); 3319762338dSopenharmony_ci 3329762338dSopenharmony_ciBENCHMARK_F(CodecBenchmarkOmxTest, UseBuffer)(benchmark::State &state) 3339762338dSopenharmony_ci{ 3349762338dSopenharmony_ci ASSERT_TRUE(component_ != nullptr); 3359762338dSopenharmony_ci int32_t ret; 3369762338dSopenharmony_ci struct OmxCodecBuffer omxBuffer; 3379762338dSopenharmony_ci InitOmxCodecBuffer(omxBuffer, CODEC_BUFFER_TYPE_INVALID); 3389762338dSopenharmony_ci struct OmxCodecBuffer outBuffer; 3399762338dSopenharmony_ci for (auto _ : state) { 3409762338dSopenharmony_ci ret = component_->UseBuffer(inputIndex, omxBuffer, outBuffer); 3419762338dSopenharmony_ci } 3429762338dSopenharmony_ci ASSERT_NE(ret, HDF_SUCCESS); 3439762338dSopenharmony_ci} 3449762338dSopenharmony_ci 3459762338dSopenharmony_ciBENCHMARK_REGISTER_F(CodecBenchmarkOmxTest, UseBuffer)-> 3469762338dSopenharmony_ci Iterations(100)->Repetitions(3)->ReportAggregatesOnly(); 3479762338dSopenharmony_ci 3489762338dSopenharmony_ciBENCHMARK_F(CodecBenchmarkOmxTest, UseEglImage)(benchmark::State &state) 3499762338dSopenharmony_ci{ 3509762338dSopenharmony_ci ASSERT_TRUE(component_ != nullptr); 3519762338dSopenharmony_ci int32_t ret; 3529762338dSopenharmony_ci struct OmxCodecBuffer omxBuffer; 3539762338dSopenharmony_ci InitOmxCodecBuffer(omxBuffer, CODEC_BUFFER_TYPE_AVSHARE_MEM_FD); 3549762338dSopenharmony_ci auto eglImage = std::make_unique<int8_t[]>(BUFFER_SIZE); 3559762338dSopenharmony_ci ASSERT_TRUE(eglImage != nullptr); 3569762338dSopenharmony_ci std::vector<int8_t> eglImageVec; 3579762338dSopenharmony_ci eglImageVec.assign(eglImage.get(), eglImage.get() + BUFFER_SIZE); 3589762338dSopenharmony_ci struct OmxCodecBuffer outbuffer; 3599762338dSopenharmony_ci for (auto _ : state) { 3609762338dSopenharmony_ci ret = component_->UseEglImage(inputIndex, omxBuffer, outbuffer, eglImageVec); 3619762338dSopenharmony_ci } 3629762338dSopenharmony_ci ASSERT_NE(ret, HDF_SUCCESS); 3639762338dSopenharmony_ci eglImage = nullptr; 3649762338dSopenharmony_ci} 3659762338dSopenharmony_ci 3669762338dSopenharmony_ciBENCHMARK_REGISTER_F(CodecBenchmarkOmxTest, UseEglImage)-> 3679762338dSopenharmony_ci Iterations(100)->Repetitions(3)->ReportAggregatesOnly(); 3689762338dSopenharmony_ci 3699762338dSopenharmony_ciBENCHMARK_F(CodecBenchmarkOmxTest, FillThisBuffer)(benchmark::State &state) 3709762338dSopenharmony_ci{ 3719762338dSopenharmony_ci ASSERT_TRUE(component_ != nullptr); 3729762338dSopenharmony_ci int32_t ret; 3739762338dSopenharmony_ci struct OmxCodecBuffer omxBuffer; 3749762338dSopenharmony_ci InitOmxCodecBuffer(omxBuffer, CODEC_BUFFER_TYPE_AVSHARE_MEM_FD); 3759762338dSopenharmony_ci omxBuffer.bufferId = BUFFER_ID_ERROR; 3769762338dSopenharmony_ci for (auto _ : state) { 3779762338dSopenharmony_ci ret = component_->FillThisBuffer(omxBuffer); 3789762338dSopenharmony_ci } 3799762338dSopenharmony_ci ASSERT_NE(ret, HDF_SUCCESS); 3809762338dSopenharmony_ci} 3819762338dSopenharmony_ci 3829762338dSopenharmony_ciBENCHMARK_REGISTER_F(CodecBenchmarkOmxTest, FillThisBuffer)-> 3839762338dSopenharmony_ci Iterations(100)->Repetitions(3)->ReportAggregatesOnly(); 3849762338dSopenharmony_ci 3859762338dSopenharmony_ciBENCHMARK_F(CodecBenchmarkOmxTest, EmptyThisBuffer)(benchmark::State &state) 3869762338dSopenharmony_ci{ 3879762338dSopenharmony_ci ASSERT_TRUE(component_ != nullptr); 3889762338dSopenharmony_ci int32_t ret; 3899762338dSopenharmony_ci struct OmxCodecBuffer omxBuffer; 3909762338dSopenharmony_ci InitOmxCodecBuffer(omxBuffer, CODEC_BUFFER_TYPE_AVSHARE_MEM_FD); 3919762338dSopenharmony_ci omxBuffer.bufferId = BUFFER_ID_ERROR; 3929762338dSopenharmony_ci for (auto _ : state) { 3939762338dSopenharmony_ci ret = component_->EmptyThisBuffer(omxBuffer); 3949762338dSopenharmony_ci } 3959762338dSopenharmony_ci ASSERT_NE(ret, HDF_SUCCESS); 3969762338dSopenharmony_ci} 3979762338dSopenharmony_ci 3989762338dSopenharmony_ciBENCHMARK_REGISTER_F(CodecBenchmarkOmxTest, EmptyThisBuffer)-> 3999762338dSopenharmony_ci Iterations(100)->Repetitions(3)->ReportAggregatesOnly(); 4009762338dSopenharmony_ci 4019762338dSopenharmony_ciBENCHMARK_F(CodecBenchmarkOmxTest, SetCallbacks)(benchmark::State &state) 4029762338dSopenharmony_ci{ 4039762338dSopenharmony_ci ASSERT_TRUE(component_ != nullptr); 4049762338dSopenharmony_ci int32_t ret; 4059762338dSopenharmony_ci callback_ = new CodecCallbackService(); 4069762338dSopenharmony_ci ASSERT_TRUE(callback_ != nullptr); 4079762338dSopenharmony_ci for (auto _ : state) { 4089762338dSopenharmony_ci ret = component_->SetCallbacks(callback_, APP_DATA); 4099762338dSopenharmony_ci } 4109762338dSopenharmony_ci ASSERT_EQ(ret, HDF_SUCCESS); 4119762338dSopenharmony_ci} 4129762338dSopenharmony_ci 4139762338dSopenharmony_ciBENCHMARK_REGISTER_F(CodecBenchmarkOmxTest, SetCallbacks)-> 4149762338dSopenharmony_ci Iterations(100)->Repetitions(3)->ReportAggregatesOnly(); 4159762338dSopenharmony_ci 4169762338dSopenharmony_ci#ifdef SUPPORT_OMX 4179762338dSopenharmony_ciBENCHMARK_F(CodecBenchmarkOmxTest, ComponentRoleEnum)(benchmark::State &state) 4189762338dSopenharmony_ci{ 4199762338dSopenharmony_ci ASSERT_TRUE(component_ != nullptr); 4209762338dSopenharmony_ci int32_t ret; 4219762338dSopenharmony_ci std::vector<uint8_t> role; 4229762338dSopenharmony_ci for (auto _ : state) { 4239762338dSopenharmony_ci ret = component_->ComponentRoleEnum(role, MAX_ROLE_INDEX); 4249762338dSopenharmony_ci } 4259762338dSopenharmony_ci ASSERT_NE(ret, HDF_SUCCESS); 4269762338dSopenharmony_ci} 4279762338dSopenharmony_ci 4289762338dSopenharmony_ciBENCHMARK_REGISTER_F(CodecBenchmarkOmxTest, ComponentRoleEnum)-> 4299762338dSopenharmony_ci Iterations(100)->Repetitions(3)->ReportAggregatesOnly(); 4309762338dSopenharmony_ci#endif 4319762338dSopenharmony_ci 4329762338dSopenharmony_ciBENCHMARK_F(CodecBenchmarkOmxTest, FreeBuffer)(benchmark::State &state) 4339762338dSopenharmony_ci{ 4349762338dSopenharmony_ci ASSERT_TRUE(component_ != nullptr); 4359762338dSopenharmony_ci int32_t ret; 4369762338dSopenharmony_ci struct OmxCodecBuffer omxBuffer; 4379762338dSopenharmony_ci InitOmxCodecBuffer(omxBuffer, CODEC_BUFFER_TYPE_AVSHARE_MEM_FD); 4389762338dSopenharmony_ci omxBuffer.bufferId = BUFFER_ID_ERROR; 4399762338dSopenharmony_ci for (auto _ : state) { 4409762338dSopenharmony_ci ret = component_->FreeBuffer(outputIndex, omxBuffer); 4419762338dSopenharmony_ci } 4429762338dSopenharmony_ci ASSERT_NE(ret, HDF_SUCCESS); 4439762338dSopenharmony_ci} 4449762338dSopenharmony_ci 4459762338dSopenharmony_ciBENCHMARK_REGISTER_F(CodecBenchmarkOmxTest, FreeBuffer)-> 4469762338dSopenharmony_ci Iterations(100)->Repetitions(3)->ReportAggregatesOnly(); 4479762338dSopenharmony_ci 4489762338dSopenharmony_ci#ifdef SUPPORT_OMX 4499762338dSopenharmony_ciBENCHMARK_F(CodecBenchmarkOmxTest, ComponentDeInit)(benchmark::State &state) 4509762338dSopenharmony_ci{ 4519762338dSopenharmony_ci std::vector<int8_t> cmdData; 4529762338dSopenharmony_ci int32_t ret; 4539762338dSopenharmony_ci for (auto _ : state) { 4549762338dSopenharmony_ci Init(); 4559762338dSopenharmony_ci ret = component_->SendCommand(CODEC_COMMAND_STATE_SET, CODEC_STATE_LOADED, cmdData); 4569762338dSopenharmony_ci CodecStateType state = CODEC_STATE_INVALID; 4579762338dSopenharmony_ci do { 4589762338dSopenharmony_ci usleep(100); 4599762338dSopenharmony_ci ret = component_->GetState(state); 4609762338dSopenharmony_ci } while (state != CODEC_STATE_LOADED); 4619762338dSopenharmony_ci ret = component_->ComponentDeInit(); 4629762338dSopenharmony_ci if (manager_ != nullptr && component_ != nullptr) { 4639762338dSopenharmony_ci manager_->DestroyComponent(componentId_); 4649762338dSopenharmony_ci } 4659762338dSopenharmony_ci component_ = nullptr; 4669762338dSopenharmony_ci callback_ = nullptr; 4679762338dSopenharmony_ci } 4689762338dSopenharmony_ci ASSERT_EQ(ret, HDF_SUCCESS); 4699762338dSopenharmony_ci} 4709762338dSopenharmony_ci 4719762338dSopenharmony_ciBENCHMARK_REGISTER_F(CodecBenchmarkOmxTest, ComponentDeInit)-> 4729762338dSopenharmony_ci Iterations(100)->Repetitions(3)->ReportAggregatesOnly(); 4739762338dSopenharmony_ci#endif 4749762338dSopenharmony_ci} // namespace 4759762338dSopenharmony_ciBENCHMARK_MAIN(); 476