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