1 /*
2 * Copyright (c) 2021 Shenzhen Kaihong DID 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 #ifdef SUPPORT_OMX
41 constexpr uint32_t MAX_ROLE_INDEX = 1000;
42 constexpr int32_t ROLE_LEN = 240;
43 #endif
44 constexpr int32_t HEIGHT = 480;
45 constexpr int32_t BUFFER_SIZE = WIDTH * HEIGHT * 3;
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__anon0371ebe90111::CodecHdiOmxTest::BufferInfo69 BufferInfo()
70 {
71 omxBuffer = nullptr;
72 sharedMem = nullptr;
73 bufferHandle = nullptr;
74 }
~BufferInfo__anon0371ebe90111::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 // Test GetComponentVersion
254 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiGetVersionTest_001, TestSize.Level1)
255 {
256 ASSERT_TRUE(component_ != nullptr);
257 struct CompVerInfo verInfo;
258 auto ret = component_->GetComponentVersion(component_, &verInfo);
259 ASSERT_EQ(ret, HDF_SUCCESS);
260 }
261 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiGetVersionTest_002, TestSize.Level1)
262 {
263 ASSERT_TRUE(component_ != nullptr);
264 auto ret = component_->GetComponentVersion(component_, nullptr);
265 ASSERT_NE(ret, HDF_SUCCESS);
266 }
267
268 #ifdef SUPPORT_OMX
269 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiGetParameterTest_001, TestSize.Level1)
270 {
271 ASSERT_TRUE(component_ != nullptr);
272 CodecVideoPortFormatParam pixFormat;
273 InitExtParam(pixFormat);
274 pixFormat.portIndex = (uint32_t)PortIndex::PORT_INDEX_OUTPUT;
275 pixFormat.codecColorIndex = 0;
276 auto ret = component_->GetParameter(component_, OMX_IndexCodecVideoPortFormat,
277 reinterpret_cast<int8_t *>(&pixFormat), sizeof(pixFormat));
278 ASSERT_EQ(ret, HDF_SUCCESS);
279 }
280
281 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiGetParameterTest_002, TestSize.Level1)
282 {
283 ASSERT_TRUE(component_ != nullptr);
284 CodecVideoPortFormatParam pixFormat;
285 InitExtParam(pixFormat);
286 pixFormat.portIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
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 #endif
293
294 // Test GetParameter
295 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiGetParameterTest_003, TestSize.Level1)
296 {
297 ASSERT_TRUE(component_ != nullptr);
298 auto ret = component_->GetParameter(component_, OMX_IndexParamVideoPortFormat, nullptr, 0);
299 ASSERT_NE(ret, HDF_SUCCESS);
300 }
301
302 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiGetParameterTest_004, TestSize.Level1)
303 {
304 ASSERT_TRUE(component_ != nullptr);
305 OMX_VIDEO_PARAM_PORTFORMATTYPE param;
306 InitParam(param);
307 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
308 param.eCompressionFormat = OMX_VIDEO_CodingAVC;
309 auto ret = component_->GetParameter(component_, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(¶m),
310 sizeof(param));
311 ASSERT_EQ(ret, HDF_SUCCESS);
312 }
313
314 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiGetParameterTest_005, TestSize.Level1)
315 {
316 ASSERT_TRUE(component_ != nullptr);
317 OMX_VIDEO_PARAM_PORTFORMATTYPE param;
318 memset_s(¶m, sizeof(param), 0, sizeof(param));
319 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
320 param.eCompressionFormat = OMX_VIDEO_CodingAVC;
321 auto ret = component_->GetParameter(component_, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(¶m),
322 sizeof(param));
323 ASSERT_NE(ret, HDF_SUCCESS);
324 }
325
326 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiGetParameterTest_006, TestSize.Level1)
327 {
328 ASSERT_TRUE(component_ != nullptr);
329 OMX_VIDEO_CONFIG_BITRATETYPE param;
330 InitParam(param);
331 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
332 auto ret = component_->GetParameter(component_, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(¶m),
333 sizeof(param));
334 ASSERT_NE(ret, HDF_SUCCESS);
335 }
336
337 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiGetParameterTest_007, TestSize.Level1)
338 {
339 ASSERT_TRUE(component_ != nullptr);
340 OMX_VIDEO_CONFIG_BITRATETYPE param;
341 InitParam(param);
342 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
343 auto ret = component_->GetParameter(component_, OMX_IndexVideoStartUnused, reinterpret_cast<int8_t *>(¶m),
344 sizeof(param));
345 ASSERT_NE(ret, HDF_SUCCESS);
346 }
347
348 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiSetParameterTest_001, TestSize.Level1)
349 {
350 ASSERT_TRUE(component_ != nullptr);
351 OMX_VIDEO_PARAM_PORTFORMATTYPE param;
352 InitParam(param);
353 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
354 auto ret = component_->SetParameter(component_, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(¶m),
355 sizeof(param));
356 ASSERT_EQ(ret, HDF_SUCCESS);
357 }
358
359 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiSetParameterTest_002, TestSize.Level1)
360 {
361 ASSERT_TRUE(component_ != nullptr);
362 OMX_VIDEO_PARAM_PORTFORMATTYPE param;
363 memset_s(¶m, sizeof(param), 0, sizeof(param));
364 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
365 auto ret = component_->SetParameter(component_, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(¶m),
366 sizeof(param));
367 ASSERT_NE(ret, HDF_SUCCESS);
368 }
369
370 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiSetParameterTest_003, TestSize.Level1)
371 {
372 ASSERT_TRUE(component_ != nullptr);
373 auto ret = component_->SetParameter(component_, OMX_IndexParamVideoPortFormat, nullptr, 0);
374 ASSERT_NE(ret, HDF_SUCCESS);
375 }
376
377 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiSetParameterTest_004, TestSize.Level1)
378 {
379 ASSERT_TRUE(component_ != nullptr);
380 OMX_VIDEO_CONFIG_BITRATETYPE param;
381 InitParam(param);
382 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
383 auto ret = component_->SetParameter(component_, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(¶m),
384 sizeof(param));
385 ASSERT_NE(ret, HDF_SUCCESS);
386 }
387
388 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiSetParameterTest_005, TestSize.Level1)
389 {
390 ASSERT_TRUE(component_ != nullptr);
391 OMX_VIDEO_PARAM_PORTFORMATTYPE param;
392 InitParam(param);
393 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
394 auto ret = component_->SetParameter(component_, OMX_IndexVideoStartUnused, reinterpret_cast<int8_t *>(¶m),
395 sizeof(param));
396 ASSERT_NE(ret, HDF_SUCCESS);
397 }
398
399 #ifdef SUPPORT_OMX
400 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiSetParameterTest_006, TestSize.Level1)
401 {
402 ASSERT_TRUE(component_ != nullptr);
403 CodecVideoPortFormatParam pixFormat;
404 InitExtParam(pixFormat);
405 pixFormat.portIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
406 pixFormat.codecColorIndex = 0;
407 auto ret = component_->GetParameter(component_, OMX_IndexCodecVideoPortFormat,
408 reinterpret_cast<int8_t *>(&pixFormat), sizeof(pixFormat));
409 ASSERT_EQ(ret, HDF_SUCCESS);
410 pixFormat.codecColorFormat = PIXEL_FMT_RGB_555;
411 ret = component_->SetParameter(component_, OMX_IndexCodecVideoPortFormat, reinterpret_cast<int8_t *>(&pixFormat),
412 sizeof(pixFormat));
413 ASSERT_EQ(ret, HDF_SUCCESS);
414 }
415 #endif
416
417 // Test GetConfig
418 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiGetConfigTest_001, TestSize.Level1)
419 {
420 ASSERT_TRUE(component_ != nullptr);
421 OMX_VIDEO_CONFIG_BITRATETYPE param;
422 InitParam(param);
423 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_OUTPUT;
424 auto ret = component_->GetConfig(component_, OMX_IndexConfigVideoBitrate, reinterpret_cast<int8_t *>(¶m),
425 sizeof(param));
426 ASSERT_EQ(ret, HDF_SUCCESS);
427 }
428
429 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiGetConfigTest_002, TestSize.Level1)
430 {
431 ASSERT_TRUE(component_ != nullptr);
432 OMX_VIDEO_CONFIG_BITRATETYPE param;
433 InitParam(param);
434 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
435 auto ret = component_->GetConfig(component_, OMX_IndexConfigVideoBitrate, reinterpret_cast<int8_t *>(¶m),
436 sizeof(param));
437 ASSERT_NE(ret, HDF_SUCCESS);
438 }
439
440 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiGetConfigTest_003, TestSize.Level1)
441 {
442 ASSERT_TRUE(component_ != nullptr);
443 auto ret = component_->GetConfig(component_, OMX_IndexConfigVideoBitrate, nullptr, 0);
444 ASSERT_NE(ret, HDF_SUCCESS);
445 }
446
447 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiGetConfigTest_004, TestSize.Level1)
448 {
449 ASSERT_TRUE(component_ != nullptr);
450 OMX_VIDEO_CONFIG_BITRATETYPE param;
451 InitParam(param);
452 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_OUTPUT;
453 auto ret =
454 component_->GetConfig(component_, OMX_IndexVideoStartUnused, reinterpret_cast<int8_t *>(¶m), sizeof(param));
455 ASSERT_NE(ret, HDF_SUCCESS);
456 }
457
458 // Test SetConfig
459 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiSetConfigTest_001, TestSize.Level1)
460 {
461 ASSERT_TRUE(component_ != nullptr);
462 OMX_VIDEO_CONFIG_BITRATETYPE param;
463 InitParam(param);
464 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_OUTPUT;
465 param.nEncodeBitrate = FRAMERATE;
466 auto ret = component_->SetConfig(component_, OMX_IndexConfigVideoBitrate, reinterpret_cast<int8_t *>(¶m),
467 sizeof(param));
468 ASSERT_EQ(ret, HDF_SUCCESS);
469 }
470
471 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiSetConfigTest_002, TestSize.Level1)
472 {
473 ASSERT_TRUE(component_ != nullptr);
474 OMX_VIDEO_CONFIG_BITRATETYPE param;
475 InitParam(param);
476 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_INPUT;
477 param.nEncodeBitrate = FRAMERATE;
478 auto ret = component_->SetConfig(component_, OMX_IndexConfigVideoBitrate, reinterpret_cast<int8_t *>(¶m),
479 sizeof(param));
480 ASSERT_NE(ret, HDF_SUCCESS);
481 }
482
483 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiSetConfigTest_003, TestSize.Level1)
484 {
485 ASSERT_TRUE(component_ != nullptr);
486 auto ret = component_->SetConfig(component_, OMX_IndexConfigVideoBitrate, nullptr, 0);
487 ASSERT_NE(ret, HDF_SUCCESS);
488 }
489
490 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiSetConfigTest_004, TestSize.Level1)
491 {
492 ASSERT_TRUE(component_ != nullptr);
493 OMX_VIDEO_CONFIG_BITRATETYPE param;
494 InitParam(param);
495 param.nPortIndex = (uint32_t)PortIndex::PORT_INDEX_OUTPUT;
496 auto ret =
497 component_->SetConfig(component_, OMX_IndexVideoStartUnused, reinterpret_cast<int8_t *>(¶m), sizeof(param));
498 ASSERT_NE(ret, HDF_SUCCESS);
499 }
500
501 #ifdef SUPPORT_OMX
502 // Test GetExtensionIndex
503 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiGetExtensionIndexTest_001, TestSize.Level1)
504 {
505 ASSERT_TRUE(component_ != nullptr);
506 OMX_INDEXTYPE indexType;
507 auto ret =
508 component_->GetExtensionIndex(component_, "OMX.Topaz.index.param.extended_video", (uint32_t *)&indexType);
509 ASSERT_EQ(ret, HDF_SUCCESS);
510 }
511 #endif
512
513 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiGetExtensionIndexTest_002, TestSize.Level1)
514 {
515 ASSERT_TRUE(component_ != nullptr);
516 OMX_INDEXTYPE indexType;
517 auto ret = component_->GetExtensionIndex(component_, nullptr, (uint32_t *)&indexType);
518 ASSERT_NE(ret, HDF_SUCCESS);
519 }
520
521 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiGetExtensionIndexTest_003, TestSize.Level1)
522 {
523 ASSERT_TRUE(component_ != nullptr);
524 OMX_INDEXTYPE indexType;
525 auto ret = component_->GetExtensionIndex(component_, "OMX.Topaz.index.param.extended_test", (uint32_t *)&indexType);
526 ASSERT_NE(ret, HDF_SUCCESS);
527 }
528
529 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiGetExtensionIndexTest_004, TestSize.Level1)
530 {
531 ASSERT_TRUE(component_ != nullptr);
532 auto ret = component_->GetExtensionIndex(component_, "OMX.Topaz.index.param.extended_video", nullptr);
533 ASSERT_NE(ret, HDF_SUCCESS);
534 }
535
536 // Test GetState
537 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiGetStateTest_001, TestSize.Level1)
538 {
539 ASSERT_TRUE(component_ != nullptr);
540 OMX_STATETYPE state;
541 auto ret = component_->GetState(component_, &state);
542 ASSERT_EQ(state, OMX_StateLoaded);
543 ASSERT_EQ(ret, HDF_SUCCESS);
544 }
545
546 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiGetStateTest_002, TestSize.Level1)
547 {
548 ASSERT_TRUE(component_ != nullptr);
549 auto ret = component_->GetState(component_, nullptr);
550 ASSERT_NE(ret, HDF_SUCCESS);
551 }
552
553 #ifdef SUPPORT_OMX
554 // Test ComponentTunnelRequest
555 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiTunnelRequestTest_001, TestSize.Level1)
556 {
557 ASSERT_TRUE(component_ != nullptr);
558 const int32_t tunneledComp = 1002;
559 const uint32_t tunneledPort = 101;
560 OMX_TUNNELSETUPTYPE tunnelSetup;
561 tunnelSetup.eSupplier = OMX_BufferSupplyInput;
562
563 auto ret = component_->ComponentTunnelRequest(component_, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, tunneledComp,
564 tunneledPort, &tunnelSetup);
565 ASSERT_NE(ret, HDF_SUCCESS);
566 }
567 #endif
568
569 // Test SendCommand
570 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiLoadedToExecutingTest_001, TestSize.Level1)
571 {
572 ASSERT_TRUE(component_ != nullptr);
573 auto ret = component_->SendCommand(component_, OMX_CommandStateSet, OMX_StateExecuting, nullptr, 0);
574 ASSERT_EQ(ret, HDF_SUCCESS);
575 }
576
577 struct OmxCodecBuffer allocBuffer;
578 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiAllocateBufferTest_001, TestSize.Level1)
579 {
580 ASSERT_TRUE(component_ != nullptr);
581 InitCodecBuffer(allocBuffer, CODEC_BUFFER_TYPE_INVALID, version_);
582 auto ret = component_->AllocateBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_INPUT, &allocBuffer);
583 ASSERT_NE(ret, HDF_SUCCESS);
584 }
585
586 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiAllocateBufferTest_002, TestSize.Level1)
587 {
588 ASSERT_TRUE(component_ != nullptr);
589 InitCodecBuffer(allocBuffer, CODEC_BUFFER_TYPE_VIRTUAL_ADDR, version_);
590 auto ret = component_->AllocateBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_INPUT, &allocBuffer);
591 ASSERT_NE(ret, HDF_SUCCESS);
592 }
593
594 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiAllocateBufferTest_003, TestSize.Level1)
595 {
596 ASSERT_TRUE(component_ != nullptr);
597 InitCodecBuffer(allocBuffer, CODEC_BUFFER_TYPE_INVALID, version_);
598 auto ret = component_->AllocateBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, &allocBuffer);
599 ASSERT_NE(ret, HDF_SUCCESS);
600 }
601
602 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiAllocateBufferTest_004, TestSize.Level1)
603 {
604 ASSERT_TRUE(component_ != nullptr);
605 InitCodecBuffer(allocBuffer, CODEC_BUFFER_TYPE_VIRTUAL_ADDR, version_);
606 auto ret = component_->AllocateBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, &allocBuffer);
607 ASSERT_NE(ret, HDF_SUCCESS);
608 }
609
610 // Test UseBuffer
611 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiUseBufferTest_001, TestSize.Level1)
612 {
613 ASSERT_TRUE(component_ != nullptr);
614 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
615 ASSERT_TRUE(omxBuffer != nullptr);
616 omxBuffer->size = sizeof(OmxCodecBuffer);
617 omxBuffer->version = version_;
618 omxBuffer->bufferType = CODEC_BUFFER_TYPE_INVALID;
619 omxBuffer->bufferLen = 0;
620 omxBuffer->buffer = nullptr;
621 omxBuffer->allocLen = 0;
622 omxBuffer->fenceFd = -1;
623 omxBuffer->pts = 0;
624 omxBuffer->flag = 0;
625
626 auto err = component_->UseBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_INPUT, omxBuffer.get());
627 ASSERT_NE(err, HDF_SUCCESS);
628 }
629
630 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiUseBufferTest_002, TestSize.Level1)
631 {
632 ASSERT_TRUE(component_ != nullptr);
633 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
634 ASSERT_TRUE(omxBuffer != nullptr);
635 omxBuffer->size = sizeof(OmxCodecBuffer);
636 omxBuffer->version = version_;
637 omxBuffer->bufferType = CODEC_BUFFER_TYPE_INVALID;
638 omxBuffer->bufferLen = 0;
639 omxBuffer->buffer = nullptr;
640 omxBuffer->allocLen = 0;
641 omxBuffer->fenceFd = -1;
642 omxBuffer->pts = 0;
643 omxBuffer->flag = 0;
644
645 auto err = component_->UseBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, omxBuffer.get());
646 ASSERT_NE(err, HDF_SUCCESS);
647 }
648
649 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiUseBufferTest_003, TestSize.Level1)
650 {
651 ASSERT_TRUE(component_ != nullptr);
652 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
653 ASSERT_TRUE(omxBuffer != nullptr);
654 omxBuffer->size = sizeof(OmxCodecBuffer);
655 omxBuffer->version = version_;
656 omxBuffer->bufferType = CODEC_BUFFER_TYPE_VIRTUAL_ADDR;
657 omxBuffer->bufferLen = 0;
658 omxBuffer->buffer = nullptr;
659 omxBuffer->allocLen = 0;
660 omxBuffer->fenceFd = -1;
661 omxBuffer->pts = 0;
662 omxBuffer->flag = 0;
663
664 auto err = component_->UseBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_INPUT, omxBuffer.get());
665 ASSERT_NE(err, HDF_SUCCESS);
666 }
667
668 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiUseBufferTest_004, TestSize.Level1)
669 {
670 ASSERT_TRUE(component_ != nullptr);
671 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
672 ASSERT_TRUE(omxBuffer != nullptr);
673 omxBuffer->size = sizeof(OmxCodecBuffer);
674 omxBuffer->version = version_;
675 omxBuffer->bufferType = CODEC_BUFFER_TYPE_VIRTUAL_ADDR;
676 omxBuffer->bufferLen = 0;
677 omxBuffer->buffer = nullptr;
678 omxBuffer->allocLen = 0;
679 omxBuffer->fenceFd = -1;
680 omxBuffer->pts = 0;
681 omxBuffer->flag = 0;
682
683 auto err = component_->UseBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, omxBuffer.get());
684 ASSERT_NE(err, HDF_SUCCESS);
685 }
686
687 #ifdef SUPPORT_OMX
688 // Use buffer on input index
689 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiUseBufferTest_005, TestSize.Level1)
690 {
691 ASSERT_TRUE(component_ != nullptr);
692 OMX_PARAM_PORTDEFINITIONTYPE param;
693 InitParam(param);
694 param.nPortIndex = (OMX_U32)PortIndex::PORT_INDEX_INPUT;
695 auto err = component_->GetParameter(component_, OMX_IndexParamPortDefinition, (int8_t *)¶m, sizeof(param));
696 ASSERT_EQ(err, HDF_SUCCESS);
697
698 int32_t bufferSize = param.nBufferSize;
699 int32_t bufferCount = param.nBufferCountActual;
700 auto ret = UseBufferOnPort(PortIndex::PORT_INDEX_INPUT, bufferCount, bufferSize);
701 ASSERT_TRUE(ret);
702 FreeBufferOnPort(PortIndex::PORT_INDEX_INPUT);
703 }
704
705 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiUseBufferTest_006, TestSize.Level1)
706 {
707 ASSERT_TRUE(component_ != nullptr);
708 auto err = component_->SendCommand(component_, OMX_CommandStateSet, OMX_StateIdle, NULL, 0);
709 ASSERT_EQ(err, HDF_SUCCESS);
710 AllocInfo alloc = {.width = WIDTH,
711 .height = HEIGHT,
712 .usage = HBM_USE_CPU_READ | HBM_USE_CPU_WRITE | HBM_USE_MEM_DMA,
713 .format = PIXEL_FMT_YCBCR_420_SP};
714 ASSERT_TRUE(gralloc_ != nullptr);
715 BufferHandle *bufferHandle = nullptr;
716 err = gralloc_->AllocMem(alloc, bufferHandle);
717 ASSERT_EQ(err, DISPLAY_SUCCESS);
718 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
719 ASSERT_TRUE(omxBuffer != nullptr);
720 omxBuffer->size = sizeof(OmxCodecBuffer);
721 omxBuffer->version = version_;
722 omxBuffer->bufferType = CODEC_BUFFER_TYPE_HANDLE;
723 omxBuffer->bufferLen = sizeof(BufferHandle);
724 omxBuffer->buffer = reinterpret_cast<uint8_t *>(bufferHandle);
725 omxBuffer->allocLen = sizeof(BufferHandle);
726 omxBuffer->fenceFd = -1;
727 omxBuffer->pts = 0;
728 omxBuffer->flag = 0;
729
730 err = component_->UseBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_INPUT, omxBuffer.get());
731 if (err != HDF_SUCCESS) {
732 HDF_LOGE("%{public}s failed to UseBuffer with input port", __func__);
733 omxBuffer = nullptr;
734 }
735 ASSERT_EQ(err, HDF_SUCCESS);
736 omxBuffer->bufferLen = 0;
737 std::shared_ptr<BufferInfo> bufferInfo = std::make_shared<BufferInfo>();
738 ASSERT_TRUE(bufferInfo != nullptr);
739 bufferInfo->omxBuffer = omxBuffer;
740 bufferInfo->bufferHandle = bufferHandle;
741 inputBuffers_.emplace(std::make_pair(omxBuffer->bufferId, bufferInfo));
742 FreeBufferOnPort(PortIndex::PORT_INDEX_INPUT);
743 }
744
745 // Use Buffer on output index
746 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiUseBufferTest_007, TestSize.Level1)
747 {
748 ASSERT_TRUE(component_ != nullptr);
749 OMX_PARAM_PORTDEFINITIONTYPE param;
750 InitParam(param);
751 param.nPortIndex = (OMX_U32)PortIndex::PORT_INDEX_OUTPUT;
752 auto err = component_->GetParameter(component_, OMX_IndexParamPortDefinition, (int8_t *)¶m, sizeof(param));
753 ASSERT_EQ(err, HDF_SUCCESS);
754
755 int32_t bufferSize = param.nBufferSize;
756 int32_t bufferCount = param.nBufferCountActual;
757 bool ret = UseBufferOnPort(PortIndex::PORT_INDEX_OUTPUT, bufferCount, bufferSize);
758 ASSERT_TRUE(ret);
759 ret = FreeBufferOnPort(PortIndex::PORT_INDEX_OUTPUT);
760 ASSERT_TRUE(ret);
761 }
762
763 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiUseBufferTest_008, TestSize.Level1)
764 {
765 ASSERT_TRUE(component_ != nullptr);
766 auto err = component_->SendCommand(component_, OMX_CommandStateSet, OMX_StateIdle, NULL, 0);
767 ASSERT_EQ(err, HDF_SUCCESS);
768 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
769 ASSERT_TRUE(omxBuffer != nullptr);
770 omxBuffer->size = sizeof(OmxCodecBuffer);
771 omxBuffer->version = version_;
772 omxBuffer->bufferType = CODEC_BUFFER_TYPE_DYNAMIC_HANDLE;
773 omxBuffer->bufferLen = 0;
774 omxBuffer->buffer = nullptr;
775 omxBuffer->allocLen = 0;
776 omxBuffer->fenceFd = -1;
777 omxBuffer->pts = 0;
778 omxBuffer->flag = 0;
779
780 err = component_->UseBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, omxBuffer.get());
781 if (err != HDF_SUCCESS) {
782 HDF_LOGE("%{public}s failed to UseBuffer with input port", __func__);
783 omxBuffer = nullptr;
784 }
785 ASSERT_EQ(err, HDF_SUCCESS);
786 omxBuffer->bufferLen = 0;
787 std::shared_ptr<BufferInfo> bufferInfo = std::make_shared<BufferInfo>();
788 ASSERT_TRUE(bufferInfo != nullptr);
789 bufferInfo->omxBuffer = omxBuffer;
790 outputBuffers_.emplace(std::make_pair(omxBuffer->bufferId, bufferInfo));
791 FreeBufferOnPort(PortIndex::PORT_INDEX_OUTPUT);
792 }
793
794 // Use buffer on input index error when OMX_ErrorInsufficientResources
795 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiUseBufferTest_009, TestSize.Level1)
796 {
797 ASSERT_TRUE(component_ != nullptr);
798 OMX_PARAM_PORTDEFINITIONTYPE param;
799 InitParam(param);
800 param.nPortIndex = (OMX_U32)PortIndex::PORT_INDEX_INPUT;
801 auto err = component_->GetParameter(component_, OMX_IndexParamPortDefinition, (int8_t *)¶m, sizeof(param));
802 ASSERT_EQ(err, HDF_SUCCESS);
803
804 bool ret = UseBufferOnPort(PortIndex::PORT_INDEX_INPUT, param.nBufferCountActual, param.nBufferSize);
805 ASSERT_TRUE(ret);
806 ret = UseBufferOnPort(PortIndex::PORT_INDEX_INPUT, 1, param.nBufferSize);
807 FreeBufferOnPort(PortIndex::PORT_INDEX_INPUT);
808 ASSERT_FALSE(ret);
809 }
810 // Use buffer on output index error when OMX_ErrorInsufficientResources
811 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiUseBufferTest_010, TestSize.Level1)
812 {
813 ASSERT_TRUE(component_ != nullptr);
814 OMX_PARAM_PORTDEFINITIONTYPE param;
815 InitParam(param);
816 param.nPortIndex = (OMX_U32)PortIndex::PORT_INDEX_OUTPUT;
817 auto err = component_->GetParameter(component_, OMX_IndexParamPortDefinition, (int8_t *)¶m, sizeof(param));
818 ASSERT_EQ(err, HDF_SUCCESS);
819 bool ret = UseBufferOnPort(PortIndex::PORT_INDEX_OUTPUT, param.nBufferCountActual, param.nBufferSize);
820 ASSERT_TRUE(ret);
821 ret = UseBufferOnPort(PortIndex::PORT_INDEX_OUTPUT, 1, param.nBufferSize);
822 FreeBufferOnPort(PortIndex::PORT_INDEX_OUTPUT);
823 ASSERT_FALSE(ret);
824 }
825 #endif
826
827 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiAllocateBufferTest_005, TestSize.Level1)
828 {
829 ASSERT_TRUE(component_ != nullptr);
830 auto err = component_->SendCommand(component_, OMX_CommandStateSet, OMX_StateIdle, NULL, 0);
831 ASSERT_EQ(err, HDF_SUCCESS);
832 InitCodecBuffer(allocBuffer, CODEC_BUFFER_TYPE_AVSHARE_MEM_FD, version_);
833 err = component_->AllocateBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_INPUT, &allocBuffer);
834 ASSERT_EQ(err, HDF_SUCCESS);
835 err = component_->FreeBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_INPUT, &allocBuffer);
836 ASSERT_EQ(err, HDF_SUCCESS);
837 }
838
839 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiAllocateBufferTest_006, TestSize.Level1)
840 {
841 ASSERT_TRUE(component_ != nullptr);
842 auto err = component_->SendCommand(component_, OMX_CommandStateSet, OMX_StateIdle, NULL, 0);
843 ASSERT_EQ(err, HDF_SUCCESS);
844 InitCodecBuffer(allocBuffer, CODEC_BUFFER_TYPE_AVSHARE_MEM_FD, version_);
845 allocBuffer.type = READ_WRITE_TYPE;
846 err = component_->AllocateBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, &allocBuffer);
847 ASSERT_EQ(err, HDF_SUCCESS);
848 err = component_->FreeBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_INPUT, &allocBuffer);
849 ASSERT_EQ(err, HDF_SUCCESS);
850 }
851
852 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiUseEglImageTest_001, TestSize.Level1)
853 {
854 ASSERT_TRUE(component_ != nullptr);
855 struct OmxCodecBuffer buffer;
856 buffer.fenceFd = -1;
857 buffer.version = version_;
858 buffer.bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD;
859 buffer.allocLen = BUFFER_SIZE;
860 buffer.buffer = 0;
861 buffer.bufferLen = 0;
862 buffer.pts = 0;
863 buffer.flag = 0;
864 buffer.type = READ_ONLY_TYPE;
865 auto eglImage = std::make_unique<int8_t[]>(BUFFER_SIZE);
866 ASSERT_TRUE(eglImage != nullptr);
867 auto ret = component_->UseEglImage(component_, &buffer, (uint32_t)PortIndex::PORT_INDEX_INPUT, eglImage.get(),
868 BUFFER_SIZE);
869 ASSERT_NE(ret, HDF_SUCCESS);
870 eglImage = nullptr;
871 }
872
873 #ifdef SUPPORT_OMX
874 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiBufferFillAndEmptyTest_001, TestSize.Level1)
875 {
876 ASSERT_TRUE(component_ != nullptr);
877 auto err = component_->SendCommand(component_, OMX_CommandStateSet, OMX_StateIdle, NULL, 0);
878 ASSERT_EQ(err, HDF_SUCCESS);
879 OMX_PARAM_PORTDEFINITIONTYPE param;
880 InitParam(param);
881 param.nPortIndex = (OMX_U32)PortIndex::PORT_INDEX_INPUT;
882 err = component_->GetParameter(component_, OMX_IndexParamPortDefinition, (int8_t *)¶m, sizeof(param));
883 ASSERT_EQ(err, HDF_SUCCESS);
884
885 bool ret = UseBufferOnPort(PortIndex::PORT_INDEX_INPUT, param.nBufferCountActual, param.nBufferSize);
886 ASSERT_TRUE(ret);
887 InitParam(param);
888 param.nPortIndex = (OMX_U32)PortIndex::PORT_INDEX_OUTPUT;
889 err = component_->GetParameter(component_, OMX_IndexParamPortDefinition, (int8_t *)¶m, sizeof(param));
890 ASSERT_EQ(err, HDF_SUCCESS);
891 ret = UseBufferOnPort(PortIndex::PORT_INDEX_OUTPUT, param.nBufferCountActual, param.nBufferSize);
892 ASSERT_TRUE(ret);
893 err = component_->SendCommand(component_, OMX_CommandStateSet, OMX_StateExecuting, NULL, 0);
894
895 OMX_STATETYPE state = OMX_StateInvalid;
896 do {
897 usleep(10);
898 auto ret = component_->GetState(component_, &state);
899 ASSERT_EQ(ret, HDF_SUCCESS);
900 } while (state != OMX_StateExecuting);
901
902 auto iter = outputBuffers_.begin();
903 if (iter != outputBuffers_.end()) {
904 auto ret = component_->FillThisBuffer(component_, iter->second->omxBuffer.get());
905 ASSERT_EQ(ret, HDF_SUCCESS);
906 }
907 iter = inputBuffers_.begin();
908 if (iter != inputBuffers_.end()) {
909 auto ret = component_->EmptyThisBuffer(component_, iter->second->omxBuffer.get());
910 ASSERT_EQ(ret, HDF_SUCCESS);
911 }
912
913 err = component_->SendCommand(component_, OMX_CommandStateSet, OMX_StateIdle, nullptr, 0);
914 FreeBufferOnPort(PortIndex::PORT_INDEX_INPUT);
915 FreeBufferOnPort(PortIndex::PORT_INDEX_OUTPUT);
916
917 err = component_->SendCommand(component_, OMX_CommandStateSet, OMX_StateLoaded, nullptr, 0);
918 do {
919 usleep(10);
920 auto ret = component_->GetState(component_, &state);
921 ASSERT_EQ(ret, HDF_SUCCESS);
922 } while (state != OMX_StateLoaded);
923 component_->ComponentDeInit(component_);
924 }
925 #endif
926
927 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiFillThisBufferTest_002, TestSize.Level1)
928 {
929 ASSERT_TRUE(component_ != nullptr);
930 allocBuffer.bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD;
931 allocBuffer.fenceFd = -1;
932 allocBuffer.version = version_;
933 allocBuffer.allocLen = BUFFER_SIZE;
934 allocBuffer.buffer = 0;
935 allocBuffer.bufferLen = 0;
936 allocBuffer.pts = 0;
937 allocBuffer.flag = 0;
938 allocBuffer.type = READ_ONLY_TYPE;
939 allocBuffer.bufferId = BUFFER_ID_ERROR;
940 auto ret = component_->FillThisBuffer(component_, &allocBuffer);
941 ASSERT_NE(ret, HDF_SUCCESS);
942 }
943
944 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiEmptyThisBufferTest_002, TestSize.Level1)
945 {
946 ASSERT_TRUE(component_ != nullptr);
947 allocBuffer.bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD;
948 allocBuffer.fenceFd = -1;
949 allocBuffer.version = version_;
950 allocBuffer.allocLen = BUFFER_SIZE;
951 allocBuffer.buffer = 0;
952 allocBuffer.bufferLen = 0;
953 allocBuffer.pts = 0;
954 allocBuffer.flag = 0;
955 allocBuffer.type = READ_ONLY_TYPE;
956 allocBuffer.bufferId = BUFFER_ID_ERROR;
957 auto ret = component_->EmptyThisBuffer(component_, &allocBuffer);
958 ASSERT_NE(ret, HDF_SUCCESS);
959 }
960
961 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiSetCallbackTest_001, TestSize.Level1)
962 {
963 ASSERT_TRUE(component_ != nullptr);
964 if (callback_ != nullptr) {
965 CodecCallbackTypeStubRelease(callback_);
966 }
967 callback_ = CodecCallbackTypeStubGetInstance();
968 ASSERT_TRUE(callback_ != nullptr);
969 auto ret = component_->SetCallbacks(component_, callback_, (int64_t)this);
970 ASSERT_EQ(ret, HDF_SUCCESS);
971 }
972
973 #ifdef SUPPORT_OMX
974 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiRoleEnumTest_001, TestSize.Level1)
975 {
976 ASSERT_TRUE(component_ != nullptr);
977 uint8_t role[ROLE_LEN] = {0};
978 auto ret = component_->ComponentRoleEnum(component_, role, ROLE_LEN, 0);
979 ASSERT_EQ(ret, HDF_SUCCESS);
980 }
981 #endif
982
983 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiRoleEnumTest_002, TestSize.Level1)
984 {
985 ASSERT_TRUE(component_ != nullptr);
986 auto ret = component_->ComponentRoleEnum(component_, nullptr, 0, 0);
987 ASSERT_NE(ret, HDF_SUCCESS);
988 }
989
990 #ifdef SUPPORT_OMX
991 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiRoleEnumTest_003, TestSize.Level1)
992 {
993 ASSERT_TRUE(component_ != nullptr);
994 uint8_t role[ROLE_LEN] = {0};
995 auto ret = component_->ComponentRoleEnum(component_, role, ROLE_LEN, MAX_ROLE_INDEX);
996 ASSERT_NE(ret, HDF_SUCCESS);
997 }
998
999 // Executing to Idle
1000 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiExecutingToIdleTest_001, TestSize.Level1)
1001 {
1002 ASSERT_TRUE(component_ != nullptr);
1003 auto ret = component_->SendCommand(component_, OMX_CommandStateSet, OMX_StateIdle, nullptr, 0);
1004 ASSERT_EQ(ret, HDF_SUCCESS);
1005 }
1006 #endif
1007
1008 // Release input buffer
1009 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiFreeBufferTest_001, TestSize.Level1)
1010 {
1011 ASSERT_TRUE(component_ != nullptr);
1012 allocBuffer.bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD;
1013 allocBuffer.fenceFd = -1;
1014 allocBuffer.version = version_;
1015 allocBuffer.allocLen = BUFFER_SIZE;
1016 allocBuffer.buffer = 0;
1017 allocBuffer.bufferLen = 0;
1018 allocBuffer.pts = 0;
1019 allocBuffer.flag = 0;
1020 allocBuffer.type = READ_ONLY_TYPE;
1021 allocBuffer.bufferId = BUFFER_ID_ERROR;
1022 auto ret = component_->FreeBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_OUTPUT, &allocBuffer);
1023 ASSERT_NE(ret, HDF_SUCCESS);
1024 }
1025
1026 #ifdef SUPPORT_OMX
1027 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiFreeBufferTest_002, TestSize.Level1)
1028 {
1029 ASSERT_TRUE(component_ != nullptr);
1030 OMX_PARAM_PORTDEFINITIONTYPE param;
1031 InitParam(param);
1032 param.nPortIndex = (OMX_U32)PortIndex::PORT_INDEX_OUTPUT;
1033 auto err = component_->GetParameter(component_, OMX_IndexParamPortDefinition, (int8_t *)¶m, sizeof(param));
1034 ASSERT_EQ(err, HDF_SUCCESS);
1035
1036 int32_t bufferSize = param.nBufferSize;
1037 int32_t bufferCount = param.nBufferCountActual;
1038 auto ret = UseBufferOnPort(PortIndex::PORT_INDEX_OUTPUT, bufferCount, bufferSize);
1039 ASSERT_TRUE(ret);
1040 ret = FreeBufferOnPort(PortIndex::PORT_INDEX_OUTPUT);
1041 ASSERT_TRUE(ret);
1042 }
1043 #endif
1044
1045 // Release input buffer
1046 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiFreeBufferTest_003, TestSize.Level1)
1047 {
1048 ASSERT_TRUE(component_ != nullptr);
1049 allocBuffer.bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD;
1050 allocBuffer.fenceFd = -1;
1051 allocBuffer.version = version_;
1052 allocBuffer.allocLen = BUFFER_SIZE;
1053 allocBuffer.buffer = 0;
1054 allocBuffer.bufferLen = 0;
1055 allocBuffer.pts = 0;
1056 allocBuffer.flag = 0;
1057 allocBuffer.type = READ_ONLY_TYPE;
1058 allocBuffer.bufferId = BUFFER_ID_ERROR;
1059 auto ret = component_->FreeBuffer(component_, (uint32_t)PortIndex::PORT_INDEX_INPUT, &allocBuffer);
1060 ASSERT_NE(ret, HDF_SUCCESS);
1061 }
1062
1063 #ifdef SUPPORT_OMX
1064 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiFreeBufferTest_004, TestSize.Level1)
1065 {
1066 ASSERT_TRUE(component_ != nullptr);
1067 OMX_PARAM_PORTDEFINITIONTYPE param;
1068 InitParam(param);
1069 param.nPortIndex = (OMX_U32)PortIndex::PORT_INDEX_INPUT;
1070 auto err = component_->GetParameter(component_, OMX_IndexParamPortDefinition, (int8_t *)¶m, sizeof(param));
1071 ASSERT_EQ(err, HDF_SUCCESS);
1072
1073 int32_t bufferSize = param.nBufferSize;
1074 int32_t bufferCount = param.nBufferCountActual;
1075 auto ret = UseBufferOnPort(PortIndex::PORT_INDEX_INPUT, bufferCount, bufferSize);
1076 ASSERT_TRUE(ret);
1077 ret = FreeBufferOnPort(PortIndex::PORT_INDEX_INPUT);
1078 ASSERT_TRUE(ret);
1079 }
1080
1081 // When ComponentDeInit, must change to Loaded State
1082 HWTEST_F(CodecHdiOmxTest, HdfCodecHdiDeInitTest_001, TestSize.Level1)
1083 {
1084 ASSERT_TRUE(component_ != nullptr);
1085 auto ret = component_->SendCommand(component_, OMX_CommandStateSet, OMX_StateLoaded, nullptr, 0);
1086 ASSERT_EQ(ret, HDF_SUCCESS);
1087 // State changed OMX_StateIdle when release all this buffer
1088 OMX_STATETYPE state = OMX_StateInvalid;
1089 do {
1090 usleep(100);
1091 ret = component_->GetState(component_, &state);
1092 ASSERT_EQ(ret, HDF_SUCCESS);
1093 } while (state != OMX_StateLoaded);
1094 ret = component_->ComponentDeInit(component_);
1095 ASSERT_EQ(ret, HDF_SUCCESS);
1096 }
1097 #endif
1098
1099 } // namespace