1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <OMX_Component.h> 17 #include <OMX_Core.h> 18 #include <OMX_Video.h> 19 #include <OMX_VideoExt.h> 20 #include <ashmem.h> 21 #include <buffer_handle.h> 22 #include <gtest/gtest.h> 23 #include <hdf_log.h> 24 #include <idisplay_gralloc.h> 25 #include <osal_mem.h> 26 #include <securec.h> 27 #include <servmgr_hdi.h> 28 #include "codec_callback_type_stub.h" 29 #include "codec_component_manager.h" 30 #include "codec_component_type.h" 31 #include "codec_omx_ext.h" 32 #include "hdf_io_service_if.h" 33 34 #define HDF_LOG_TAG codec_hdi_test 35 36 using namespace std; 37 using namespace testing::ext; 38 namespace { 39 constexpr int32_t WIDTH = 640; 40 constexpr int32_t HEIGHT = 480; 41 constexpr int32_t BUFFER_SIZE = WIDTH * HEIGHT * 3; 42 #ifndef SUPPORT_OMX 43 constexpr uint32_t MAX_ROLE_INDEX = 1000; 44 constexpr int32_t ROLE_LEN = 240; 45 #endif 46 constexpr int32_t FRAMERATE = 30 << 16; 47 constexpr uint32_t BUFFER_ID_ERROR = 65000; 48 class CodecHdiOmxTest : public testing::Test { 49 public: 50 enum class PortIndex { PORT_INDEX_INPUT = 0, PORT_INDEX_OUTPUT = 1 }; 51 struct BufferInfo { 52 std::shared_ptr<OmxCodecBuffer> omxBuffer; 53 std::shared_ptr<OHOS::Ashmem> sharedMem; 54 BufferHandle *bufferHandle; BufferInfo__anonf04ec9000111::CodecHdiOmxTest::BufferInfo55 BufferInfo() 56 { 57 omxBuffer = nullptr; 58 sharedMem = nullptr; 59 bufferHandle = nullptr; 60 } ~BufferInfo__anonf04ec9000111::CodecHdiOmxTest::BufferInfo61 ~BufferInfo() 62 { 63 omxBuffer = nullptr; 64 if (sharedMem != nullptr) { 65 sharedMem->UnmapAshmem(); 66 sharedMem->CloseAshmem(); 67 sharedMem = nullptr; 68 } 69 if (bufferHandle != nullptr && gralloc_ != nullptr) { 70 gralloc_->FreeMem(*bufferHandle); 71 bufferHandle = nullptr; 72 } 73 } 74 }; 75 template <typename T> InitParam(T & param)76 void InitParam(T ¶m) 77 { 78 memset_s(¶m, sizeof(param), 0x0, sizeof(param)); 79 param.nSize = sizeof(param); 80 param.nVersion = version_; 81 } 82 83 template <typename T> InitExtParam(T & param)84 void InitExtParam(T ¶m) 85 { 86 memset_s(¶m, sizeof(param), 0x0, sizeof(param)); 87 param.size = sizeof(param); 88 param.version = version_; 89 } 90 InitCodecBufferWithAshMem(enum PortIndex portIndex,int bufferSize,shared_ptr<OmxCodecBuffer> omxBuffer,shared_ptr<OHOS::Ashmem> sharedMem)91 void InitCodecBufferWithAshMem(enum PortIndex portIndex, int bufferSize, shared_ptr<OmxCodecBuffer> omxBuffer, 92 shared_ptr<OHOS::Ashmem> sharedMem) 93 { 94 omxBuffer->size = sizeof(OmxCodecBuffer); 95 omxBuffer->version = version_; 96 omxBuffer->bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD; 97 omxBuffer->bufferLen = sizeof(int); 98 omxBuffer->buffer = (uint8_t *)(uintptr_t)sharedMem->GetAshmemFd(); 99 omxBuffer->allocLen = bufferSize; 100 omxBuffer->fenceFd = -1; 101 omxBuffer->pts = 0; 102 omxBuffer->flag = 0; 103 if (portIndex == PortIndex::PORT_INDEX_INPUT) { 104 omxBuffer->type = READ_ONLY_TYPE; 105 sharedMem->MapReadAndWriteAshmem(); 106 } else { 107 omxBuffer->type = READ_WRITE_TYPE; 108 sharedMem->MapReadOnlyAshmem(); 109 } 110 } 111 UseBufferOnPort(enum PortIndex portIndex,int32_t bufferCount,int32_t bufferSize)112 bool UseBufferOnPort(enum PortIndex portIndex, int32_t bufferCount, int32_t bufferSize) 113 { 114 for (int i = 0; i < bufferCount; i++) { 115 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>(); 116 if (omxBuffer == nullptr) { 117 return false; 118 } 119 120 int fd = OHOS::AshmemCreate(0, bufferSize); 121 shared_ptr<OHOS::Ashmem> sharedMem = make_shared<OHOS::Ashmem>(fd, bufferSize); 122 if (sharedMem == nullptr) { 123 if (fd >= 0) { 124 close(fd); 125 fd = -1; 126 } 127 return false; 128 } 129 InitCodecBufferWithAshMem(portIndex, bufferSize, omxBuffer, sharedMem); 130 auto err = component_->UseBuffer(component_, (uint32_t)portIndex, omxBuffer.get()); 131 if (err != HDF_SUCCESS) { 132 sharedMem->UnmapAshmem(); 133 sharedMem->CloseAshmem(); 134 sharedMem = nullptr; 135 omxBuffer = nullptr; 136 return false; 137 } 138 omxBuffer->bufferLen = 0; 139 std::shared_ptr<BufferInfo> bufferInfo = std::make_shared<BufferInfo>(); 140 bufferInfo->omxBuffer = omxBuffer; 141 bufferInfo->sharedMem = sharedMem; 142 if (portIndex == PortIndex::PORT_INDEX_INPUT) { 143 inputBuffers_.emplace(std::make_pair(omxBuffer->bufferId, bufferInfo)); 144 } else { 145 outputBuffers_.emplace(std::make_pair(omxBuffer->bufferId, bufferInfo)); 146 } 147 } 148 return true; 149 } 150 FreeBufferOnPort(enum PortIndex portIndex)151 bool FreeBufferOnPort(enum PortIndex portIndex) 152 { 153 std::map<int32_t, std::shared_ptr<BufferInfo>> &buffer = inputBuffers_; 154 if (portIndex == PortIndex::PORT_INDEX_OUTPUT) { 155 buffer = outputBuffers_; 156 } 157 for (auto [bufferId, bufferInfo] : buffer) { 158 auto ret = component_->FreeBuffer(component_, (uint32_t)portIndex, bufferInfo->omxBuffer.get()); 159 if (ret != HDF_SUCCESS) { 160 return false; 161 } 162 } 163 buffer.clear(); 164 return true; 165 } SetUpTestCase()166 static void SetUpTestCase() 167 { 168 manager_ = GetCodecComponentManager(); 169 gralloc_ = OHOS::HDI::Display::V1_0::IDisplayGralloc::Get(); 170 if (manager_ == nullptr) { 171 std::cout<<"GetCodecComponentManager ret nullptr"<<std::endl; 172 return; 173 } 174 auto count = manager_->GetComponentNum(); 175 if (count > 0) { 176 CodecCompCapability *capList = (CodecCompCapability *)OsalMemAlloc(sizeof(CodecCompCapability) * count); 177 ASSERT_TRUE(capList != nullptr); 178 auto err = manager_->GetComponentCapabilityList(capList, count); 179 ASSERT_TRUE(err == HDF_SUCCESS); 180 compName_ = capList[0].compName; 181 OsalMemFree(capList); 182 capList = nullptr; 183 } 184 } TearDownTestCase()185 static void TearDownTestCase() 186 { 187 CodecComponentManagerRelease(); 188 manager_ = nullptr; 189 } SetUp()190 void SetUp() 191 { 192 if (manager_ == nullptr) { 193 return; 194 } 195 callback_ = CodecCallbackTypeStubGetInstance(); 196 if (callback_ == nullptr) { 197 return; 198 } 199 if (compName_.empty()) { 200 return; 201 } 202 203 auto ret = manager_->CreateComponent(&component_, &componentId_, compName_.data(), 204 reinterpret_cast<int64_t>(this), callback_); 205 if (ret != HDF_SUCCESS) { 206 return; 207 } 208 struct CompVerInfo verInfo; 209 ret = component_->GetComponentVersion(component_, &verInfo); 210 if (ret != HDF_SUCCESS) { 211 return; 212 } 213 version_ = verInfo.compVersion; 214 } TearDown()215 void TearDown() 216 { 217 if (manager_ != nullptr && component_ != nullptr) { 218 manager_->DestroyComponent(componentId_); 219 } 220 if (callback_ != nullptr) { 221 CodecCallbackTypeStubRelease(callback_); 222 callback_ = nullptr; 223 } 224 } 225 226 public: 227 struct CodecComponentType *component_ = nullptr; 228 uint32_t componentId_ = 0; 229 struct CodecCallbackType *callback_ = nullptr; 230 231 static inline struct CodecComponentManager *manager_ = nullptr; 232 static inline std::string compName_ = ""; 233 union OMX_VERSIONTYPE version_; 234 std::map<int32_t, std::shared_ptr<BufferInfo>> inputBuffers_; 235 std::map<int32_t, std::shared_ptr<BufferInfo>> outputBuffers_; 236 static inline OHOS::HDI::Display::V1_0::IDisplayGralloc *gralloc_ = nullptr; 237 }; 238 /** 239 * @tc.name HdfCodecHdiGetVersionTest_001 240 * @tc.number SUB_DriverSystem_CodecHdi_V2_0080 241 * @tc.desc Reads the version information of an open component 242 */ 243 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0080, Function | MediumTest | Level3) 244 { 245 ASSERT_TRUE(component_ != nullptr); 246 struct CompVerInfo verInfo; 247 auto ret = component_->GetComponentVersion(component_, &verInfo); 248 ASSERT_EQ(ret, HDF_SUCCESS); 249 } 250 #ifndef SUPPORT_OMX 251 /** 252 * @tc.name HdfCodecHdiGetVersionTest_002 253 * @tc.number SUB_DriverSystem_CodecHdi_V2_0090 254 * @tc.desc The input parameter is empty. GetComponentVersion is error. 255 */ 256 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0090, Function | MediumTest | Level3) 257 { 258 ASSERT_TRUE(component_ != nullptr); 259 auto ret = component_->GetComponentVersion(component_, nullptr); 260 ASSERT_NE(ret, HDF_SUCCESS); 261 } 262 /** 263 * @tc.name HdfCodecHdiGetParameterTest_003 264 * @tc.number SUB_DriverSystem_CodecHdi_V2_0100 265 * @tc.desc The input parameter structure pointer is null when the OMX_IndexParamVideoPortFormat parameter is read 266 */ 267 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0100, Function | MediumTest | Level3) 268 { 269 ASSERT_TRUE(component_ != nullptr); 270 CodecVideoPortFormatParam pixFormat; 271 InitExtParam(pixFormat); 272 pixFormat.portIndex = (uint32_t)PortIndex::PORT_INDEX_OUTPUT; 273 pixFormat.codecColorIndex = 0; 274 auto ret = component_->GetParameter(component_, OMX_IndexCodecVideoPortFormat, 275 reinterpret_cast<int8_t *>(&pixFormat), sizeof(pixFormat)); 276 ASSERT_EQ(ret, HDF_SUCCESS); 277 } 278 /** 279 * @tc.name HdfCodecHdiGetParameterTest_004 280 * @tc.number SUB_DriverSystem_CodecHdi_V2_0110 281 * @tc.desc The OMX_IndexParamVideoPortFormat parameter of the input port of the component is normally read 282 */ 283 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0110, Function | MediumTest | Level3) 284 { 285 ASSERT_TRUE(component_ != nullptr); 286 CodecVideoPortFormatParam pixFormat; 287 InitExtParam(pixFormat); 288 pixFormat.portIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT; 289 pixFormat.codecColorIndex = 0; 290 auto ret = component_->GetParameter(component_, OMX_IndexCodecVideoPortFormat, 291 reinterpret_cast<int8_t *>(&pixFormat), sizeof(pixFormat)); 292 ASSERT_EQ(ret, HDF_SUCCESS); 293 } 294 #endif 295 /** 296 * @tc.name HdfCodecHdiGetParameterTest_003 297 * @tc.number SUB_DriverSystem_CodecHdi_V2_0120 298 * @tc.desc The version information is not set for the input parameter. As a result, the parameter fails to be read 299 */ 300 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0120, Function | MediumTest | Level3) 301 { 302 ASSERT_TRUE(component_ != nullptr); 303 auto ret = component_->GetParameter(component_, OMX_IndexParamVideoPortFormat, nullptr, 0); 304 ASSERT_NE(ret, HDF_SUCCESS); 305 } 306 /** 307 * @tc.name HdfCodecHdiGetParameterTest_004 308 * @tc.number SUB_DriverSystem_CodecHdi_V2_0130 309 * @tc.desc The input parameter structure does not match the index. As a result, the parameter fails to be read 310 */ 311 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0130, Function | MediumTest | Level3) 312 { 313 ASSERT_TRUE(component_ != nullptr); 314 OMX_VIDEO_PARAM_PORTFORMATTYPE param; 315 InitParam(param); 316 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT; 317 param.eCompressionFormat = OMX_VIDEO_CodingAVC; 318 auto ret = component_->GetParameter(component_, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(¶m), 319 sizeof(param)); 320 ASSERT_EQ(ret, HDF_SUCCESS); 321 } 322 /** 323 * @tc.name HdfCodecHdiGetParameterTest_005 324 * @tc.number SUB_DriverSystem_CodecHdi_V2_0140 325 * @tc.desc The input parameter index is not supported. As a result, the parameter fails to be read 326 */ 327 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0140, Function | MediumTest | Level3) 328 { 329 ASSERT_TRUE(component_ != nullptr); 330 OMX_VIDEO_PARAM_PORTFORMATTYPE param; 331 memset_s(¶m, sizeof(param), 0, sizeof(param)); 332 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT; 333 param.eCompressionFormat = OMX_VIDEO_CodingAVC; 334 auto ret = component_->GetParameter(component_, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(¶m), 335 sizeof(param)); 336 ASSERT_NE(ret, HDF_SUCCESS); 337 } 338 /** 339 * @tc.name HdfCodecHdiGetParameterTest_006 340 * @tc.number SUB_DriverSystem_CodecHdi_V2_0150 341 * @tc.desc The input parameter prot is not supported. As a result, the parameter fails to be read 342 */ 343 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0150, Function | MediumTest | Level3) 344 { 345 ASSERT_TRUE(component_ != nullptr); 346 OMX_VIDEO_CONFIG_BITRATETYPE param; 347 InitParam(param); 348 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT; 349 auto ret = component_->GetParameter(component_, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(¶m), 350 sizeof(param)); 351 ASSERT_NE(ret, HDF_SUCCESS); 352 } 353 /** 354 * @tc.name HdfCodecHdiGetParameterTest_007 355 * @tc.number SUB_DriverSystem_CodecHdi_V2_0160 356 * @tc.desc The input parameter MX_IndexVideoStartUnused. As a result, the parameter fails to be read 357 */ 358 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0160, Function | MediumTest | Level3) 359 { 360 ASSERT_TRUE(component_ != nullptr); 361 OMX_VIDEO_CONFIG_BITRATETYPE param; 362 InitParam(param); 363 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT; 364 auto ret = component_->GetParameter(component_, OMX_IndexVideoStartUnused, reinterpret_cast<int8_t *>(¶m), 365 sizeof(param)); 366 ASSERT_NE(ret, HDF_SUCCESS); 367 } 368 /** 369 * @tc.name HdfCodecHdiSetParameterTest_001 370 * @tc.number SUB_DriverSystem_CodecHdi_V2_0170 371 * @tc.desc Setting the OMX_IndexParamVideoPortFormat Parameter of the Component Input Port 372 */ 373 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0170, Function | MediumTest | Level3) 374 { 375 ASSERT_TRUE(component_ != nullptr); 376 OMX_VIDEO_PARAM_PORTFORMATTYPE param; 377 InitParam(param); 378 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT; 379 auto ret = component_->SetParameter(component_, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(¶m), 380 sizeof(param)); 381 ASSERT_EQ(ret, HDF_SUCCESS); 382 } 383 /** 384 * @tc.name HdfCodecHdiSetParameterTest_002 385 * @tc.number SUB_DriverSystem_CodecHdi_V2_0180 386 * @tc.desc The input parameter version information is not set. As a result, the parameter setting fails 387 */ 388 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0180, Function | MediumTest | Level3) 389 { 390 ASSERT_TRUE(component_ != nullptr); 391 OMX_VIDEO_PARAM_PORTFORMATTYPE param; 392 memset_s(¶m, sizeof(param), 0, sizeof(param)); 393 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT; 394 auto ret = component_->SetParameter(component_, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(¶m), 395 sizeof(param)); 396 ASSERT_NE(ret, HDF_SUCCESS); 397 } 398 /** 399 * @tc.name HdfCodecHdiSetParameterTest_003 400 * @tc.number SUB_DriverSystem_CodecHdi_V2_0190 401 * @tc.desc The input parameter is null 402 */ 403 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0190, Function | MediumTest | Level3) 404 { 405 ASSERT_TRUE(component_ != nullptr); 406 auto ret = component_->SetParameter(component_, OMX_IndexParamVideoPortFormat, nullptr, 0); 407 ASSERT_NE(ret, HDF_SUCCESS); 408 } 409 /** 410 * @tc.name HdfCodecHdiSetParameterTest_004 411 * @tc.number SUB_DriverSystem_CodecHdi_V2_0200 412 * @tc.desc Parameter does not match index 413 */ 414 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0200, Function | MediumTest | Level3) 415 { 416 ASSERT_TRUE(component_ != nullptr); 417 OMX_VIDEO_CONFIG_BITRATETYPE param; 418 InitParam(param); 419 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT; 420 auto ret = component_->SetParameter(component_, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(¶m), 421 sizeof(param)); 422 ASSERT_NE(ret, HDF_SUCCESS); 423 } 424 /** 425 * @tc.name HdfCodecHdiSetParameterTest_005 426 * @tc.number SUB_DriverSystem_CodecHdi_V2_0210 427 * @tc.desc The parameter index is not supported 428 */ 429 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0210, Function | MediumTest | Level3) 430 { 431 ASSERT_TRUE(component_ != nullptr); 432 OMX_VIDEO_PARAM_PORTFORMATTYPE param; 433 InitParam(param); 434 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT; 435 auto ret = component_->SetParameter(component_, OMX_IndexVideoStartUnused, reinterpret_cast<int8_t *>(¶m), 436 sizeof(param)); 437 ASSERT_NE(ret, HDF_SUCCESS); 438 } 439 #ifndef SUPPORT_OMX 440 /** 441 * @tc.name HdfCodecHdiSetParameterTest_006 442 * @tc.number SUB_DriverSystem_CodecHdi_V2_0220 443 * @tc.desc 444 */ 445 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0220, Function | MediumTest | Level3) 446 { 447 ASSERT_TRUE(component_ != nullptr); 448 CodecVideoPortFormatParam pixFormat; 449 InitExtParam(pixFormat); 450 pixFormat.portIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT; 451 pixFormat.codecColorIndex = 0; 452 auto ret = component_->GetParameter(component_, OMX_IndexCodecVideoPortFormat, 453 reinterpret_cast<int8_t *>(&pixFormat), sizeof(pixFormat)); 454 ASSERT_EQ(ret, HDF_SUCCESS); 455 pixFormat.codecColorFormat = PIXEL_FMT_RGB_555; 456 ret = component_->SetParameter(component_, OMX_IndexCodecVideoPortFormat, reinterpret_cast<int8_t *>(&pixFormat), 457 sizeof(pixFormat)); 458 ASSERT_EQ(ret, HDF_SUCCESS); 459 } 460 #endif 461 /** 462 * @tc.name HdfCodecHdiGetConfigTest_001 463 * @tc.number SUB_DriverSystem_CodecHdi_V2_0230 464 * @tc.desc The configuration is read normally 465 */ 466 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0230, Function | MediumTest | Level3) 467 { 468 ASSERT_TRUE(component_ != nullptr); 469 OMX_VIDEO_CONFIG_BITRATETYPE param; 470 InitParam(param); 471 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_OUTPUT; 472 auto ret = component_->GetConfig(component_, OMX_IndexConfigVideoBitrate, reinterpret_cast<int8_t *>(¶m), 473 sizeof(param)); 474 ASSERT_EQ(ret, HDF_SUCCESS); 475 } 476 /** 477 * @tc.name HdfCodecHdiGetConfigTest_002 478 * @tc.number SUB_DriverSystem_CodecHdi_V2_0240 479 * @tc.desc Reading Unsupported Port Parameters 480 */ 481 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0240, Function | MediumTest | Level3) 482 { 483 ASSERT_TRUE(component_ != nullptr); 484 OMX_VIDEO_CONFIG_BITRATETYPE param; 485 InitParam(param); 486 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT; 487 auto ret = component_->GetConfig(component_, OMX_IndexConfigVideoBitrate, reinterpret_cast<int8_t *>(¶m), 488 sizeof(param)); 489 ASSERT_NE(ret, HDF_SUCCESS); 490 } 491 /** 492 * @tc.name HdfCodecHdiGetConfigTest_003 493 * @tc.number SUB_DriverSystem_CodecHdi_V2_0250 494 * @tc.desc The input parameter is a null pointer 495 */ 496 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0250, Function | MediumTest | Level3) 497 { 498 ASSERT_TRUE(component_ != nullptr); 499 auto ret = component_->GetConfig(component_, OMX_IndexConfigVideoBitrate, nullptr, 0); 500 ASSERT_NE(ret, HDF_SUCCESS); 501 } 502 /** 503 * @tc.name HdfCodecHdiGetConfigTest_004 504 * @tc.number SUB_DriverSystem_CodecHdi_V2_0260 505 * @tc.desc The input parameter index is not supported 506 */ 507 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0260, Function | MediumTest | Level3) 508 { 509 ASSERT_TRUE(component_ != nullptr); 510 OMX_VIDEO_CONFIG_BITRATETYPE param; 511 InitParam(param); 512 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_OUTPUT; 513 auto ret = 514 component_->GetConfig(component_, OMX_IndexVideoStartUnused, reinterpret_cast<int8_t *>(¶m), sizeof(param)); 515 ASSERT_NE(ret, HDF_SUCCESS); 516 } 517 /** 518 * @tc.name HdfCodecHdiSetConfigTest_001 519 * @tc.number SUB_DriverSystem_CodecHdi_V2_0270 520 * @tc.desc The configuration is successful 521 */ 522 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0270, Function | MediumTest | Level3) 523 { 524 ASSERT_TRUE(component_ != nullptr); 525 OMX_VIDEO_CONFIG_BITRATETYPE param; 526 InitParam(param); 527 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_OUTPUT; 528 param.nEncodeBitrate = FRAMERATE; 529 auto ret = component_->SetConfig(component_, OMX_IndexConfigVideoBitrate, reinterpret_cast<int8_t *>(¶m), 530 sizeof(param)); 531 ASSERT_EQ(ret, HDF_SUCCESS); 532 } 533 /** 534 * @tc.name HdfCodecHdiSetConfigTest_002 535 * @tc.number SUB_DriverSystem_CodecHdi_V2_0280 536 * @tc.desc Configure parameters. The port cannot be modified 537 */ 538 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0280, Function | MediumTest | Level3) 539 { 540 ASSERT_TRUE(component_ != nullptr); 541 OMX_VIDEO_CONFIG_BITRATETYPE param; 542 InitParam(param); 543 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT; 544 param.nEncodeBitrate = FRAMERATE; 545 auto ret = component_->SetConfig(component_, OMX_IndexConfigVideoBitrate, reinterpret_cast<int8_t *>(¶m), 546 sizeof(param)); 547 ASSERT_NE(ret, HDF_SUCCESS); 548 } 549 /** 550 * @tc.name HdfCodecHdiSetConfigTest_003 551 * @tc.number SUB_DriverSystem_CodecHdi_V2_0290 552 * @tc.desc The input parameter is a null poin 553 */ 554 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0290, Function | MediumTest | Level3) 555 { 556 ASSERT_TRUE(component_ != nullptr); 557 auto ret = component_->SetConfig(component_, OMX_IndexConfigVideoBitrate, nullptr, 0); 558 ASSERT_NE(ret, HDF_SUCCESS); 559 } 560 /** 561 * @tc.name HdfCodecHdiSetConfigTest_004 562 * @tc.number SUB_DriverSystem_CodecHdi_V2_0300 563 * @tc.desc The input parameter index is not supported 564 */ 565 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0300, Function | MediumTest | Level3) 566 { 567 ASSERT_TRUE(component_ != nullptr); 568 OMX_VIDEO_CONFIG_BITRATETYPE param; 569 InitParam(param); 570 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_OUTPUT; 571 auto ret = 572 component_->SetConfig(component_, OMX_IndexVideoStartUnused, reinterpret_cast<int8_t *>(¶m), sizeof(param)); 573 ASSERT_NE(ret, HDF_SUCCESS); 574 } 575 #ifndef SUPPORT_OMX 576 /** 577 * @tc.name HdfCodecHdiGetExtensionIndexTest_001 578 * @tc.number SUB_DriverSystem_CodecHdi_V2_0310 579 * @tc.desc Obtaining the extended index normally 580 */ 581 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0310, Function | MediumTest | Level3) 582 { 583 ASSERT_TRUE(component_ != nullptr); 584 OMX_INDEXTYPE indexType; 585 auto ret = 586 component_->GetExtensionIndex(component_, "OMX.Topaz.index.param.extended_video", (uint32_t *)&indexType); 587 ASSERT_EQ(ret, HDF_SUCCESS); 588 } 589 #endif 590 /** 591 * @tc.name HdfCodecHdiGetExtensionIndexTest_002 592 * @tc.number SUB_DriverSystem_CodecHdi_V2_0320 593 * @tc.desc The parameter name is null pointer 594 */ 595 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0320, Function | MediumTest | Level3) 596 { 597 ASSERT_TRUE(component_ != nullptr); 598 OMX_INDEXTYPE indexType; 599 auto ret = component_->GetExtensionIndex(component_, nullptr, (uint32_t *)&indexType); 600 ASSERT_NE(ret, HDF_SUCCESS); 601 } 602 /** 603 * @tc.name HdfCodecHdiGetExtensionIndexTest_003 604 * @tc.number SUB_DriverSystem_CodecHdi_V2_0330 605 * @tc.desc Unsupported parameter 606 */ 607 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0330, Function | MediumTest | Level3) 608 { 609 ASSERT_TRUE(component_ != nullptr); 610 OMX_INDEXTYPE indexType; 611 auto ret = component_->GetExtensionIndex(component_, "OMX.Topaz.index.param.extended_test", (uint32_t *)&indexType); 612 ASSERT_NE(ret, HDF_SUCCESS); 613 } 614 /** 615 * @tc.name HdfCodecHdiGetExtensionIndexTest_004 616 * @tc.number SUB_DriverSystem_CodecHdi_V2_0340 617 * @tc.desc Index is null pointer 618 */ 619 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0340, Function | MediumTest | Level3) 620 { 621 ASSERT_TRUE(component_ != nullptr); 622 auto ret = component_->GetExtensionIndex(component_, "OMX.Topaz.index.param.extended_video", nullptr); 623 ASSERT_NE(ret, HDF_SUCCESS); 624 } 625 /** 626 * @tc.name HdfCodecHdiGetStateTest_001 627 * @tc.number SUB_DriverSystem_CodecHdi_V2_0350 628 * @tc.desc Reads the current status of the component 629 */ 630 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0350, Function | MediumTest | Level3) 631 { 632 ASSERT_TRUE(component_ != nullptr); 633 OMX_STATETYPE state; 634 auto ret = component_->GetState(component_, &state); 635 ASSERT_EQ(state, OMX_StateLoaded); 636 ASSERT_EQ(ret, HDF_SUCCESS); 637 } 638 /** 639 * @tc.name HdfCodecHdiGetStateTest_002 640 * @tc.number SUB_DriverSystem_CodecHdi_V2_0360 641 * @tc.desc The input parameter is a null pointer 642 */ 643 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0360, Function | MediumTest | Level3) 644 { 645 ASSERT_TRUE(component_ != nullptr); 646 auto ret = component_->GetState(component_, nullptr); 647 ASSERT_NE(ret, HDF_SUCCESS); 648 } 649 #ifndef SUPPORT_OMX 650 /** 651 * @tc.name HdfCodecHdiTunnelRequestTest_001 652 * @tc.number SUB_DriverSystem_CodecHdi_V2_0370 653 * @tc.desc The interface is not supported 654 */ 655 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0370, Function | MediumTest | Level3) 656 { 657 ASSERT_TRUE(component_ != nullptr); 658 const int32_t tunneledComp = 1002; 659 const uint32_t tunneledPort = 101; 660 OMX_TUNNELSETUPTYPE tunnelSetup; 661 tunnelSetup.eSupplier = OMX_BufferSupplyInput; 662 663 auto ret = component_->ComponentTunnelRequest(component_, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, tunneledComp, 664 tunneledPort, &tunnelSetup); 665 ASSERT_NE(ret, HDF_SUCCESS); 666 } 667 #endif 668 /** 669 * @tc.name HdfCodecHdiLoadedToExecutingTest_001 670 * @tc.number SUB_DriverSystem_CodecHdi_V2_0380 671 * @tc.desc The status is changed to OMX_StateExecuting 672 */ 673 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0380, Function | MediumTest | Level3) 674 { 675 ASSERT_TRUE(component_ != nullptr); 676 auto ret = component_->SendCommand(component_, OMX_CommandStateSet, OMX_StateExecuting, nullptr, 0); 677 ASSERT_EQ(ret, HDF_SUCCESS); 678 } 679 /** 680 * @tc.name HdfCodecHdiAllocateBufferTest_001 681 * @tc.number SUB_DriverSystem_CodecHdi_V2_0390 682 * @tc.desc The input buffer type is CODEC_BUFFER_TYPE_INVALID 683 */ 684 struct OmxCodecBuffer allocBuffer; 685 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0390, Function | MediumTest | Level3) 686 { 687 ASSERT_TRUE(component_ != nullptr); 688 allocBuffer.bufferType = CODEC_BUFFER_TYPE_INVALID; 689 allocBuffer.fenceFd = -1; 690 allocBuffer.version = version_; 691 allocBuffer.allocLen = BUFFER_SIZE; 692 allocBuffer.buffer = 0; 693 allocBuffer.bufferLen = 0; 694 allocBuffer.pts = 0; 695 allocBuffer.flag = 0; 696 allocBuffer.type = READ_ONLY_TYPE; 697 auto ret = component_->AllocateBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_INPUT, &allocBuffer); 698 ASSERT_NE(ret, HDF_SUCCESS); 699 } 700 /** 701 * @tc.name HdfCodecHdiAllocateBufferTest_002 702 * @tc.number SUB_DriverSystem_CodecHdi_V2_0410 703 * @tc.desc The input buffer type is CODEC_BUFFER_TYPE_VIRTUAL_ADDR 704 */ 705 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0410, Function | MediumTest | Level3) 706 { 707 ASSERT_TRUE(component_ != nullptr); 708 allocBuffer.bufferType = CODEC_BUFFER_TYPE_VIRTUAL_ADDR; 709 auto ret = component_->AllocateBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_INPUT, &allocBuffer); 710 ASSERT_NE(ret, HDF_SUCCESS); 711 } 712 /** 713 * @tc.name HdfCodecHdiAllocateBufferTest_003 714 * @tc.number SUB_DriverSystem_CodecHdi_V2_0420 715 * @tc.desc The output buffer type is CODEC_BUFFER_TYPE_INVALID 716 */ 717 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0420, Function | MediumTest | Level3) 718 { 719 ASSERT_TRUE(component_ != nullptr); 720 allocBuffer.bufferType = CODEC_BUFFER_TYPE_INVALID; 721 auto ret = component_->AllocateBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, &allocBuffer); 722 ASSERT_NE(ret, HDF_SUCCESS); 723 } 724 /** 725 * @tc.name HdfCodecHdiAllocateBufferTest_004 726 * @tc.number SUB_DriverSystem_CodecHdi_V2_0430 727 * @tc.desc The output buffer type is CODEC_BUFFER_TYPE_VIRTUAL_ADDR 728 */ 729 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0430, Function | MediumTest | Level3) 730 { 731 ASSERT_TRUE(component_ != nullptr); 732 allocBuffer.bufferType = CODEC_BUFFER_TYPE_VIRTUAL_ADDR; 733 auto ret = component_->AllocateBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, &allocBuffer); 734 ASSERT_NE(ret, HDF_SUCCESS); 735 } 736 /** 737 * @tc.name HdfCodecHdiUseBufferTest_001 738 * @tc.number SUB_DriverSystem_CodecHdi_V2_0440 739 * @tc.desc The input buffer type is CODEC_BUFFER_TYPE_INVALID 740 */ 741 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0440, Function | MediumTest | Level3) 742 { 743 ASSERT_TRUE(component_ != nullptr); 744 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>(); 745 ASSERT_TRUE(omxBuffer != nullptr); 746 omxBuffer->size = sizeof(OmxCodecBuffer); 747 omxBuffer->version = version_; 748 omxBuffer->bufferType = CODEC_BUFFER_TYPE_INVALID; 749 omxBuffer->bufferLen = 0; 750 omxBuffer->buffer = nullptr; 751 omxBuffer->allocLen = 0; 752 omxBuffer->fenceFd = -1; 753 omxBuffer->pts = 0; 754 omxBuffer->flag = 0; 755 756 auto err = component_->UseBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_INPUT, omxBuffer.get()); 757 ASSERT_NE(err, HDF_SUCCESS); 758 } 759 /** 760 * @tc.name HdfCodecHdiUseBufferTest_002 761 * @tc.number SUB_DriverSystem_CodecHdi_V2_0450 762 * @tc.desc The output buffer type is CODEC_BUFFER_TYPE_INVALID 763 */ 764 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0450, Function | MediumTest | Level3) 765 { 766 ASSERT_TRUE(component_ != nullptr); 767 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>(); 768 ASSERT_TRUE(omxBuffer != nullptr); 769 omxBuffer->size = sizeof(OmxCodecBuffer); 770 omxBuffer->version = version_; 771 omxBuffer->bufferType = CODEC_BUFFER_TYPE_INVALID; 772 omxBuffer->bufferLen = 0; 773 omxBuffer->buffer = nullptr; 774 omxBuffer->allocLen = 0; 775 omxBuffer->fenceFd = -1; 776 omxBuffer->pts = 0; 777 omxBuffer->flag = 0; 778 779 auto err = component_->UseBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, omxBuffer.get()); 780 ASSERT_NE(err, HDF_SUCCESS); 781 } 782 /** 783 * @tc.name HdfCodecHdiUseBufferTest_003 784 * @tc.number SUB_DriverSystem_CodecHdi_V2_0460 785 * @tc.desc The input buffer type is CODEC_BUFFER_TYPE_VIRTUAL_ADDR 786 */ 787 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0460, Function | MediumTest | Level3) 788 { 789 ASSERT_TRUE(component_ != nullptr); 790 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>(); 791 ASSERT_TRUE(omxBuffer != nullptr); 792 omxBuffer->size = sizeof(OmxCodecBuffer); 793 omxBuffer->version = version_; 794 omxBuffer->bufferType = CODEC_BUFFER_TYPE_VIRTUAL_ADDR; 795 omxBuffer->bufferLen = 0; 796 omxBuffer->buffer = nullptr; 797 omxBuffer->allocLen = 0; 798 omxBuffer->fenceFd = -1; 799 omxBuffer->pts = 0; 800 omxBuffer->flag = 0; 801 802 auto err = component_->UseBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_INPUT, omxBuffer.get()); 803 ASSERT_NE(err, HDF_SUCCESS); 804 } 805 /** 806 * @tc.name HdfCodecHdiUseBufferTest_004 807 * @tc.number SUB_DriverSystem_CodecHdi_V2_0470 808 * @tc.desc The output buffer type is CODEC_BUFFER_TYPE_VIRTUAL_ADDR 809 */ 810 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0470, Function | MediumTest | Level3) 811 { 812 ASSERT_TRUE(component_ != nullptr); 813 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>(); 814 ASSERT_TRUE(omxBuffer != nullptr); 815 omxBuffer->size = sizeof(OmxCodecBuffer); 816 omxBuffer->version = version_; 817 omxBuffer->bufferType = CODEC_BUFFER_TYPE_VIRTUAL_ADDR; 818 omxBuffer->bufferLen = 0; 819 omxBuffer->buffer = nullptr; 820 omxBuffer->allocLen = 0; 821 omxBuffer->fenceFd = -1; 822 omxBuffer->pts = 0; 823 omxBuffer->flag = 0; 824 825 auto err = component_->UseBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, omxBuffer.get()); 826 ASSERT_NE(err, HDF_SUCCESS); 827 } 828 #ifndef SUPPORT_OMX 829 /** 830 * @tc.name HdfCodecHdiUseBufferTest_005 831 * @tc.number SUB_DriverSystem_CodecHdi_V2_0480 832 * @tc.desc The intput buffer type is CODEC_BUFFER_TYPE_AVSHARE_MEM_FD 833 */ 834 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0480, Function | MediumTest | Level3) 835 { 836 ASSERT_TRUE(component_ != nullptr); 837 OMX_PARAM_PORTDEFINITIONTYPE param; 838 InitParam(param); 839 param.nPortIndex = (OMX_U32)PortIndex::PORT_INDEX_INPUT; 840 auto err = component_->GetParameter(component_, OMX_IndexParamPortDefinition, (int8_t *)¶m, sizeof(param)); 841 ASSERT_EQ(err, HDF_SUCCESS); 842 843 int32_t bufferSize = param.nBufferSize; 844 int32_t bufferCount = param.nBufferCountActual; 845 auto ret = UseBufferOnPort(PortIndex::PORT_INDEX_INPUT, bufferCount, bufferSize); 846 ASSERT_TRUE(ret); 847 FreeBufferOnPort(PortIndex::PORT_INDEX_INPUT); 848 } 849 /** 850 * @tc.name HdfCodecHdiUseBufferTest_006 851 * @tc.number SUB_DriverSystem_CodecHdi_V2_0490 852 * @tc.desc The intput buffer type is CODEC_BUFFER_TYPE_HANDLE 853 */ 854 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0490, Function | MediumTest | Level3) 855 { 856 ASSERT_TRUE(component_ != nullptr); 857 auto err = component_->SendCommand(component_, OMX_CommandStateSet, OMX_StateIdle, NULL, 0); 858 ASSERT_EQ(err, HDF_SUCCESS); 859 AllocInfo alloc = {.width = WIDTH, 860 .height = HEIGHT, 861 .usage = HBM_USE_CPU_READ | HBM_USE_CPU_WRITE | HBM_USE_MEM_DMA, 862 .format = PIXEL_FMT_YCBCR_420_SP}; 863 ASSERT_TRUE(gralloc_ != nullptr); 864 BufferHandle *bufferHandle = nullptr; 865 err = gralloc_->AllocMem(alloc, bufferHandle); 866 ASSERT_EQ(err, DISPLAY_SUCCESS); 867 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>(); 868 ASSERT_TRUE(omxBuffer != nullptr); 869 omxBuffer->size = sizeof(OmxCodecBuffer); 870 omxBuffer->version = version_; 871 omxBuffer->bufferType = CODEC_BUFFER_TYPE_HANDLE; 872 omxBuffer->bufferLen = sizeof(BufferHandle); 873 omxBuffer->buffer = reinterpret_cast<uint8_t *>(bufferHandle); 874 omxBuffer->allocLen = sizeof(BufferHandle); 875 omxBuffer->fenceFd = -1; 876 omxBuffer->pts = 0; 877 omxBuffer->flag = 0; 878 879 err = component_->UseBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_INPUT, omxBuffer.get()); 880 if (err != HDF_SUCCESS) { 881 HDF_LOGE("%{public}s failed to UseBuffer with input port", __func__); 882 omxBuffer = nullptr; 883 } 884 ASSERT_EQ(err, HDF_SUCCESS); 885 omxBuffer->bufferLen = 0; 886 std::shared_ptr<BufferInfo> bufferInfo = std::make_shared<BufferInfo>(); 887 ASSERT_TRUE(bufferInfo != nullptr); 888 bufferInfo->omxBuffer = omxBuffer; 889 bufferInfo->bufferHandle = bufferHandle; 890 inputBuffers_.emplace(std::make_pair(omxBuffer->bufferId, bufferInfo)); 891 FreeBufferOnPort(PortIndex::PORT_INDEX_INPUT); 892 } 893 /** 894 * @tc.name HdfCodecHdiUseBufferTest_007 895 * @tc.number SUB_DriverSystem_CodecHdi_V2_0500 896 * @tc.desc The output buffer type is CODEC_BUFFER_TYPE_AVSHARE_MEM_FD 897 */ 898 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0500, Function | MediumTest | Level3) 899 { 900 ASSERT_TRUE(component_ != nullptr); 901 OMX_PARAM_PORTDEFINITIONTYPE param; 902 InitParam(param); 903 param.nPortIndex = (OMX_U32)PortIndex::PORT_INDEX_OUTPUT; 904 auto err = component_->GetParameter(component_, OMX_IndexParamPortDefinition, (int8_t *)¶m, sizeof(param)); 905 ASSERT_EQ(err, HDF_SUCCESS); 906 907 int32_t bufferSize = param.nBufferSize; 908 int32_t bufferCount = param.nBufferCountActual; 909 bool ret = UseBufferOnPort(PortIndex::PORT_INDEX_OUTPUT, bufferCount, bufferSize); 910 ASSERT_TRUE(ret); 911 ret = FreeBufferOnPort(PortIndex::PORT_INDEX_OUTPUT); 912 ASSERT_TRUE(ret); 913 } 914 /** 915 * @tc.name HdfCodecHdiUseBufferTest_008 916 * @tc.number SUB_DriverSystem_CodecHdi_V2_0510 917 * @tc.desc The output buffer type is CODEC_BUFFER_TYPE_DYNAMIC_HANDLE 918 */ 919 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0510, Function | MediumTest | Level3) 920 { 921 ASSERT_TRUE(component_ != nullptr); 922 auto err = component_->SendCommand(component_, OMX_CommandStateSet, OMX_StateIdle, NULL, 0); 923 ASSERT_EQ(err, HDF_SUCCESS); 924 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>(); 925 ASSERT_TRUE(omxBuffer != nullptr); 926 omxBuffer->size = sizeof(OmxCodecBuffer); 927 omxBuffer->version = version_; 928 omxBuffer->bufferType = CODEC_BUFFER_TYPE_DYNAMIC_HANDLE; 929 omxBuffer->bufferLen = 0; 930 omxBuffer->buffer = nullptr; 931 omxBuffer->allocLen = 0; 932 omxBuffer->fenceFd = -1; 933 omxBuffer->pts = 0; 934 omxBuffer->flag = 0; 935 936 err = component_->UseBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, omxBuffer.get()); 937 if (err != HDF_SUCCESS) { 938 HDF_LOGE("%{public}s failed to UseBuffer with input port", __func__); 939 omxBuffer = nullptr; 940 } 941 ASSERT_EQ(err, HDF_SUCCESS); 942 omxBuffer->bufferLen = 0; 943 std::shared_ptr<BufferInfo> bufferInfo = std::make_shared<BufferInfo>(); 944 ASSERT_TRUE(bufferInfo != nullptr); 945 bufferInfo->omxBuffer = omxBuffer; 946 outputBuffers_.emplace(std::make_pair(omxBuffer->bufferId, bufferInfo)); 947 FreeBufferOnPort(PortIndex::PORT_INDEX_OUTPUT); 948 } 949 /** 950 * @tc.name HdfCodecHdiUseBufferTest_009 951 * @tc.number SUB_DriverSystem_CodecHdi_V2_0520 952 * @tc.desc The input buffer is full 953 */ 954 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0520, Function | MediumTest | Level3) 955 { 956 ASSERT_TRUE(component_ != nullptr); 957 OMX_PARAM_PORTDEFINITIONTYPE param; 958 InitParam(param); 959 param.nPortIndex = (OMX_U32)PortIndex::PORT_INDEX_INPUT; 960 auto err = component_->GetParameter(component_, OMX_IndexParamPortDefinition, (int8_t *)¶m, sizeof(param)); 961 ASSERT_EQ(err, HDF_SUCCESS); 962 963 bool ret = UseBufferOnPort(PortIndex::PORT_INDEX_INPUT, param.nBufferCountActual, param.nBufferSize); 964 ASSERT_TRUE(ret); 965 ret = UseBufferOnPort(PortIndex::PORT_INDEX_INPUT, 1, param.nBufferSize); 966 FreeBufferOnPort(PortIndex::PORT_INDEX_INPUT); 967 ASSERT_FALSE(ret); 968 } 969 /** 970 * @tc.name HdfCodecHdiUseBufferTest_010 971 * @tc.number SUB_DriverSystem_CodecHdi_V2_0530 972 * @tc.desc The output buffer is full 973 */ 974 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0530, Function | MediumTest | Level3) 975 { 976 ASSERT_TRUE(component_ != nullptr); 977 OMX_PARAM_PORTDEFINITIONTYPE param; 978 InitParam(param); 979 param.nPortIndex = (OMX_U32)PortIndex::PORT_INDEX_OUTPUT; 980 auto err = component_->GetParameter(component_, OMX_IndexParamPortDefinition, (int8_t *)¶m, sizeof(param)); 981 ASSERT_EQ(err, HDF_SUCCESS); 982 bool ret = UseBufferOnPort(PortIndex::PORT_INDEX_OUTPUT, param.nBufferCountActual, param.nBufferSize); 983 ASSERT_TRUE(ret); 984 ret = UseBufferOnPort(PortIndex::PORT_INDEX_OUTPUT, 1, param.nBufferSize); 985 FreeBufferOnPort(PortIndex::PORT_INDEX_OUTPUT); 986 ASSERT_FALSE(ret); 987 } 988 #endif 989 /** 990 * @tc.name HdfCodecHdiAllocateBufferTest_005 991 * @tc.number SUB_DriverSystem_CodecHdi_V2_0540 992 * @tc.desc The input buffer is full 993 */ 994 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0540, Function | MediumTest | Level3) 995 { 996 ASSERT_TRUE(component_ != nullptr); 997 allocBuffer.bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD; 998 auto ret = component_->AllocateBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_INPUT, &allocBuffer); 999 ASSERT_NE(ret, HDF_SUCCESS); 1000 } 1001 /** 1002 * @tc.name HdfCodecHdiAllocateBufferTest_006 1003 * @tc.number SUB_DriverSystem_CodecHdi_V2_0550 1004 * @tc.desc The output buffer is full 1005 */ 1006 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0550, Function | MediumTest | Level3) 1007 { 1008 ASSERT_TRUE(component_ != nullptr); 1009 allocBuffer.bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD; 1010 auto ret = component_->AllocateBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, &allocBuffer); 1011 ASSERT_NE(ret, HDF_SUCCESS); 1012 } 1013 /** 1014 * @tc.name HdfCodecHdiUseEglImageTest_001 1015 * @tc.number SUB_DriverSystem_CodecHdi_V2_0560 1016 * @tc.desc The interface is invoked successfully. The OMX does not support this function 1017 */ 1018 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0560, Function | MediumTest | Level3) 1019 { 1020 ASSERT_TRUE(component_ != nullptr); 1021 struct OmxCodecBuffer buffer; 1022 buffer.fenceFd = -1; 1023 buffer.version = version_; 1024 buffer.bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD; 1025 buffer.allocLen = BUFFER_SIZE; 1026 buffer.buffer = 0; 1027 buffer.bufferLen = 0; 1028 buffer.pts = 0; 1029 buffer.flag = 0; 1030 buffer.type = READ_ONLY_TYPE; 1031 auto eglImage = std::make_unique<int8_t[]>(BUFFER_SIZE); 1032 ASSERT_TRUE(eglImage != nullptr); 1033 auto ret = component_->UseEglImage(component_, &buffer, (uint32_t)PortIndex::PORT_INDEX_INPUT, eglImage.get(), 1034 BUFFER_SIZE); 1035 ASSERT_NE(ret, HDF_SUCCESS); 1036 eglImage = nullptr; 1037 } 1038 #ifndef SUPPORT_OMX 1039 /** 1040 * @tc.name HdfCodecHdiFillThisBufferTest_001 1041 * @tc.number SUB_DriverSystem_CodecHdi_V2_0580 1042 * @tc.desc FillThisBuffer test 1043 */ 1044 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0580, Function | MediumTest | Level3) 1045 { 1046 ASSERT_TRUE(component_ != nullptr); 1047 auto err = component_->SendCommand(component_, OMX_CommandStateSet, OMX_StateIdle, NULL, 0); 1048 ASSERT_EQ(err, HDF_SUCCESS); 1049 OMX_PARAM_PORTDEFINITIONTYPE param; 1050 InitParam(param); 1051 param.nPortIndex = (OMX_U32)PortIndex::PORT_INDEX_INPUT; 1052 err = component_->GetParameter(component_, OMX_IndexParamPortDefinition, (int8_t *)¶m, sizeof(param)); 1053 ASSERT_EQ(err, HDF_SUCCESS); 1054 1055 bool ret = UseBufferOnPort(PortIndex::PORT_INDEX_INPUT, param.nBufferCountActual, param.nBufferSize); 1056 ASSERT_TRUE(ret); 1057 InitParam(param); 1058 param.nPortIndex = (OMX_U32)PortIndex::PORT_INDEX_OUTPUT; 1059 err = component_->GetParameter(component_, OMX_IndexParamPortDefinition, (int8_t *)¶m, sizeof(param)); 1060 ASSERT_EQ(err, HDF_SUCCESS); 1061 ret = UseBufferOnPort(PortIndex::PORT_INDEX_OUTPUT, param.nBufferCountActual, param.nBufferSize); 1062 ASSERT_TRUE(ret); 1063 err = component_->SendCommand(component_, OMX_CommandStateSet, OMX_StateExecuting, NULL, 0); 1064 1065 OMX_STATETYPE state = OMX_StateInvalid; 1066 do { 1067 usleep(10); 1068 auto ret = component_->GetState(component_, &state); 1069 ASSERT_EQ(ret, HDF_SUCCESS); 1070 } while (state != OMX_StateExecuting); 1071 1072 auto iter = outputBuffers_.begin(); 1073 if (iter != outputBuffers_.end()) { 1074 auto ret = component_->FillThisBuffer(component_, iter->second->omxBuffer.get()); 1075 ASSERT_EQ(ret, HDF_SUCCESS); 1076 } 1077 iter = inputBuffers_.begin(); 1078 if (iter != inputBuffers_.end()) { 1079 auto ret = component_->EmptyThisBuffer(component_, iter->second->omxBuffer.get()); 1080 ASSERT_EQ(ret, HDF_SUCCESS); 1081 } 1082 1083 err = component_->SendCommand(component_, OMX_CommandStateSet, OMX_StateIdle, nullptr, 0); 1084 FreeBufferOnPort(PortIndex::PORT_INDEX_INPUT); 1085 FreeBufferOnPort(PortIndex::PORT_INDEX_OUTPUT); 1086 1087 err = component_->SendCommand(component_, OMX_CommandStateSet, OMX_StateLoaded, nullptr, 0); 1088 do { 1089 usleep(10); 1090 auto ret = component_->GetState(component_, &state); 1091 ASSERT_EQ(ret, HDF_SUCCESS); 1092 } while (state != OMX_StateLoaded); 1093 component_->ComponentDeInit(component_); 1094 } 1095 #endif 1096 /** 1097 * @tc.name HdfCodecHdiFillThisBufferTest_002 1098 * @tc.number SUB_DriverSystem_CodecHdi_V2_0590 1099 * @tc.desc The buffer ID is incorrect 1100 */ 1101 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0590, Function | MediumTest | Level3) 1102 { 1103 ASSERT_TRUE(component_ != nullptr); 1104 allocBuffer.bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD; 1105 allocBuffer.fenceFd = -1; 1106 allocBuffer.version = version_; 1107 allocBuffer.allocLen = BUFFER_SIZE; 1108 allocBuffer.buffer = 0; 1109 allocBuffer.bufferLen = 0; 1110 allocBuffer.pts = 0; 1111 allocBuffer.flag = 0; 1112 allocBuffer.type = READ_ONLY_TYPE; 1113 allocBuffer.bufferId = BUFFER_ID_ERROR; 1114 auto ret = component_->FillThisBuffer(component_, &allocBuffer); 1115 ASSERT_NE(ret, HDF_SUCCESS); 1116 } 1117 /** 1118 * @tc.name HdfCodecHdiEmptyThisBufferTest_001 1119 * @tc.number SUB_DriverSystem_CodecHdi_V2_0600 1120 * @tc.desc EmptyThisBuffer test 1121 */ 1122 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0600, Function | MediumTest | Level3) 1123 { 1124 ASSERT_TRUE(component_ != nullptr); 1125 allocBuffer.bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD; 1126 allocBuffer.fenceFd = -1; 1127 allocBuffer.version = version_; 1128 allocBuffer.allocLen = BUFFER_SIZE; 1129 allocBuffer.buffer = 0; 1130 allocBuffer.bufferLen = 0; 1131 allocBuffer.pts = 0; 1132 allocBuffer.flag = 0; 1133 allocBuffer.type = READ_ONLY_TYPE; 1134 allocBuffer.bufferId = BUFFER_ID_ERROR; 1135 auto ret = component_->EmptyThisBuffer(component_, &allocBuffer); 1136 ASSERT_NE(ret, HDF_SUCCESS); 1137 } 1138 /** 1139 * @tc.name HdfCodecHdiSetCallbackTest_001 1140 * @tc.number SUB_DriverSystem_CodecHdi_V2_0620 1141 * @tc.desc Setting Component Callbacks 1142 */ 1143 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0620, Function | MediumTest | Level3) 1144 { 1145 ASSERT_TRUE(component_ != nullptr); 1146 if (callback_ != nullptr) { 1147 CodecCallbackTypeStubRelease(callback_); 1148 } 1149 callback_ = CodecCallbackTypeStubGetInstance(); 1150 ASSERT_TRUE(callback_ != nullptr); 1151 auto ret = component_->SetCallbacks(component_, callback_, (int64_t)this); 1152 ASSERT_EQ(ret, HDF_SUCCESS); 1153 } 1154 #ifndef SUPPORT_OMX 1155 /** 1156 * @tc.name HdfCodecHdiSetCallbackTest_002 1157 * @tc.number SUB_DriverSystem_CodecHdi_V2_0630 1158 * @tc.desc The callback pointer is null 1159 */ 1160 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0630, Function | MediumTest | Level3) 1161 { 1162 ASSERT_TRUE(component_ != nullptr); 1163 uint8_t role[ROLE_LEN] = {0}; 1164 auto ret = component_->ComponentRoleEnum(component_, role, ROLE_LEN, 0); 1165 ASSERT_EQ(ret, HDF_SUCCESS); 1166 } 1167 #endif 1168 /** 1169 * @tc.name HdfCodecHdiRoleEnumTest_001 1170 * @tc.number SUB_DriverSystem_CodecHdi_V2_0640 1171 * @tc.desc Obtaining Component Roles Based on Indexes 1172 */ 1173 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0640, Function | MediumTest | Level3) 1174 { 1175 ASSERT_TRUE(component_ != nullptr); 1176 auto ret = component_->ComponentRoleEnum(component_, nullptr, 0, 0); 1177 ASSERT_NE(ret, HDF_SUCCESS); 1178 } 1179 #ifndef SUPPORT_OMX 1180 /** 1181 * @tc.name HdfCodecHdiRoleEnumTest_002 1182 * @tc.number SUB_DriverSystem_CodecHdi_V2_0650 1183 * @tc.desc The role is null 1184 */ 1185 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0650, Function | MediumTest | Level3) 1186 { 1187 ASSERT_TRUE(component_ != nullptr); 1188 uint8_t role[ROLE_LEN] = {0}; 1189 auto ret = component_->ComponentRoleEnum(component_, role, ROLE_LEN, MAX_ROLE_INDEX); 1190 ASSERT_NE(ret, HDF_SUCCESS); 1191 } 1192 #endif 1193 /** 1194 * @tc.name HdfCodecHdiRoleEnumTest_003 1195 * @tc.number SUB_DriverSystem_CodecHdi_V2_0660 1196 * @tc.desc The index is too large 1197 */ 1198 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0660, Function | MediumTest | Level3) 1199 { 1200 ASSERT_TRUE(component_ != nullptr); 1201 auto ret = component_->SendCommand(component_, OMX_CommandStateSet, OMX_StateIdle, nullptr, 0); 1202 ASSERT_EQ(ret, HDF_SUCCESS); 1203 } 1204 /** 1205 * @tc.name HdfCodecHdiExecutingToIdleTest_001 1206 * @tc.number SUB_DriverSystem_CodecHdi_V2_0670 1207 * @tc.desc The component enters the OMX_Idle state 1208 */ 1209 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0670, Function | MediumTest | Level3) 1210 { 1211 ASSERT_TRUE(component_ != nullptr); 1212 allocBuffer.bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD; 1213 allocBuffer.fenceFd = -1; 1214 allocBuffer.version = version_; 1215 allocBuffer.allocLen = BUFFER_SIZE; 1216 allocBuffer.buffer = 0; 1217 allocBuffer.bufferLen = 0; 1218 allocBuffer.pts = 0; 1219 allocBuffer.flag = 0; 1220 allocBuffer.type = READ_ONLY_TYPE; 1221 allocBuffer.bufferId = BUFFER_ID_ERROR; 1222 auto ret = component_->FreeBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, &allocBuffer); 1223 ASSERT_NE(ret, HDF_SUCCESS); 1224 } 1225 #ifndef SUPPORT_OMX 1226 /** 1227 * @tc.name HdfCodecHdiFreeBufferTest_001 1228 * @tc.number SUB_DriverSystem_CodecHdi_V2_0680 1229 * @tc.desc The buffer ID of the output port is incorrect 1230 */ 1231 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0680, Function | MediumTest | Level3) 1232 { 1233 ASSERT_TRUE(component_ != nullptr); 1234 OMX_PARAM_PORTDEFINITIONTYPE param; 1235 InitParam(param); 1236 param.nPortIndex = (OMX_U32)PortIndex::PORT_INDEX_OUTPUT; 1237 auto err = component_->GetParameter(component_, OMX_IndexParamPortDefinition, (int8_t *)¶m, sizeof(param)); 1238 ASSERT_EQ(err, HDF_SUCCESS); 1239 1240 int32_t bufferSize = param.nBufferSize; 1241 int32_t bufferCount = param.nBufferCountActual; 1242 auto ret = UseBufferOnPort(PortIndex::PORT_INDEX_OUTPUT, bufferCount, bufferSize); 1243 ASSERT_TRUE(ret); 1244 ret = FreeBufferOnPort(PortIndex::PORT_INDEX_OUTPUT); 1245 ASSERT_TRUE(ret); 1246 } 1247 #endif 1248 /** 1249 * @tc.name HdfCodecHdiFreeBufferTest_002 1250 * @tc.number SUB_DriverSystem_CodecHdi_V2_0690 1251 * @tc.desc Test on normal release of the output port 1252 */ 1253 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0690, Function | MediumTest | Level3) 1254 { 1255 ASSERT_TRUE(component_ != nullptr); 1256 allocBuffer.bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD; 1257 allocBuffer.fenceFd = -1; 1258 allocBuffer.version = version_; 1259 allocBuffer.allocLen = BUFFER_SIZE; 1260 allocBuffer.buffer = 0; 1261 allocBuffer.bufferLen = 0; 1262 allocBuffer.pts = 0; 1263 allocBuffer.flag = 0; 1264 allocBuffer.type = READ_ONLY_TYPE; 1265 allocBuffer.bufferId = BUFFER_ID_ERROR; 1266 auto ret = component_->FreeBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_INPUT, &allocBuffer); 1267 ASSERT_NE(ret, HDF_SUCCESS); 1268 } 1269 #ifndef SUPPORT_OMX 1270 /** 1271 * @tc.name HdfCodecHdiFreeBufferTest_003 1272 * @tc.number SUB_DriverSystem_CodecHdi_V2_0700 1273 * @tc.desc The buffer ID of the input port is incorrect 1274 */ 1275 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0700, Function | MediumTest | Level3) 1276 { 1277 ASSERT_TRUE(component_ != nullptr); 1278 OMX_PARAM_PORTDEFINITIONTYPE param; 1279 InitParam(param); 1280 param.nPortIndex = (OMX_U32)PortIndex::PORT_INDEX_INPUT; 1281 auto err = component_->GetParameter(component_, OMX_IndexParamPortDefinition, (int8_t *)¶m, sizeof(param)); 1282 ASSERT_EQ(err, HDF_SUCCESS); 1283 1284 int32_t bufferSize = param.nBufferSize; 1285 int32_t bufferCount = param.nBufferCountActual; 1286 auto ret = UseBufferOnPort(PortIndex::PORT_INDEX_INPUT, bufferCount, bufferSize); 1287 ASSERT_TRUE(ret); 1288 ret = FreeBufferOnPort(PortIndex::PORT_INDEX_INPUT); 1289 ASSERT_TRUE(ret); 1290 } 1291 // When ComponentDeInit, must change to Loaded State 1292 /** 1293 * @tc.name HdfCodecHdiFreeBufferTest_004 1294 * @tc.number SUB_DriverSystem_CodecHdi_V2_0710 1295 * @tc.desc Test on normal release of the input port 1296 */ 1297 HWTEST_F(CodecHdiOmxTest, SUB_DriverSystem_CodecHdi_V2_0710, Function | MediumTest | Level3) 1298 { 1299 ASSERT_TRUE(component_ != nullptr); 1300 auto ret = component_->SendCommand(component_, OMX_CommandStateSet, OMX_StateLoaded, nullptr, 0); 1301 ASSERT_EQ(ret, HDF_SUCCESS); 1302 // State changed OMX_StateIdle when release all this buffer 1303 OMX_STATETYPE state = OMX_StateInvalid; 1304 do { 1305 usleep(100); 1306 ret = component_->GetState(component_, &state); 1307 ASSERT_EQ(ret, HDF_SUCCESS); 1308 } while (state != OMX_StateLoaded); 1309 ret = component_->ComponentDeInit(component_); 1310 ASSERT_EQ(ret, HDF_SUCCESS); 1311 } 1312 #endif 1313 1314 } // namespace 1315