1 /*
2 * Copyright (c) 2022-2023 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 <gtest/gtest.h>
22 #include <hdf_log.h>
23 #include <osal_mem.h>
24 #include <securec.h>
25 #include <servmgr_hdi.h>
26
27 #include "codec_component_manager.h"
28 #include "codec_component_type.h"
29 #include "hdf_io_service_if.h"
30 #include "codec_omx_ext.h"
31
32 #define HDF_LOG_TAG codec_hdi_test
33
34 using namespace std;
35 using namespace testing::ext;
36
37 namespace {
38 struct CodecComponentManager *g_manager = nullptr;
39 struct CodecComponentType *g_component = nullptr;
40 uint32_t g_componentId = 0;
41 struct CodecCallbackType *g_callback = nullptr;
42 int32_t g_count = 0;
43
44 constexpr const char *ENCODER_AVC = "rk.video_encoder.avc";
45 constexpr const char *DECODER_AVC = "rk.video_decoder.avc";
46
47 constexpr int32_t INT_TO_STR_LEN = 32;
48 constexpr int32_t ARRAY_TO_STR_LEN = 1000;
49
50 union OMX_VERSIONTYPE g_version;
51 constexpr int32_t FRAME_RATE = 24;
52 constexpr int32_t VIDEO_WIDHT = 640;
53 constexpr int32_t VIDEO_HEIGHT = 480;
54 constexpr int32_t BUFFER_SIZE = (640 * 480 * 3);
55 constexpr int32_t ROLE_LEN = 240;
56 constexpr int32_t FRAMERATE = (30 << 16);
57 constexpr uint32_t BUFFER_ID_ERROR = 65000;
58 constexpr int64_t APP_DATA = 64;
59 constexpr int64_t APP_DATA_MAX = 9223372036854775807;
60 constexpr int64_t APP_DATA_MIN = -9223372036854775807;
61 enum class PortIndex { PORT_INDEX_INPUT = 0, PORT_INDEX_OUTPUT = 1, PORT_INDEX_ERROR_INPUT = 2 };
62
63 template <typename T>
InitParam(T & param)64 void InitParam(T ¶m)
65 {
66 memset_s(¶m, sizeof(param), 0x0, sizeof(param));
67 param.nSize = sizeof(param);
68 param.nVersion = g_version;
69 }
70
71 struct BufferInfo {
72 std::shared_ptr<OmxCodecBuffer> omxBuffer;
73 std::shared_ptr<OHOS::Ashmem> sharedMem;
BufferInfo__anon667992240111::BufferInfo74 BufferInfo()
75 {
76 omxBuffer = nullptr;
77 sharedMem = nullptr;
78 }
~BufferInfo__anon667992240111::BufferInfo79 ~BufferInfo()
80 {
81 omxBuffer = nullptr;
82 if (sharedMem != nullptr) {
83 sharedMem->UnmapAshmem();
84 sharedMem->CloseAshmem();
85 sharedMem = nullptr;
86 }
87 }
88 };
89 std::map<int32_t, std::shared_ptr<BufferInfo>> inputBuffers;
90 std::map<int32_t, std::shared_ptr<BufferInfo>> outputBuffers;
InitCodecBufferWithAshMem(enum PortIndex portIndex,int bufferSize,shared_ptr<OmxCodecBuffer> omxBuffer,shared_ptr<OHOS::Ashmem> sharedMem)91 static void InitCodecBufferWithAshMem(
92 enum PortIndex portIndex, int bufferSize, shared_ptr<OmxCodecBuffer> omxBuffer, shared_ptr<OHOS::Ashmem> sharedMem)
93 {
94 omxBuffer->size = sizeof(OmxCodecBuffer);
95 omxBuffer->version = g_version;
96 omxBuffer->bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD;
97 omxBuffer->bufferLen = sizeof(int);
98 omxBuffer->buffer = (uint8_t *)(uintptr_t)sharedMem->GetAshmemFd();
99 omxBuffer->allocLen = bufferSize;
100 omxBuffer->fenceFd = -1;
101 omxBuffer->pts = 0;
102 omxBuffer->flag = 0;
103 if (portIndex == PortIndex::PORT_INDEX_INPUT) {
104 omxBuffer->type = READ_ONLY_TYPE;
105 sharedMem->MapReadAndWriteAshmem();
106 } else {
107 omxBuffer->type = READ_WRITE_TYPE;
108 sharedMem->MapReadOnlyAshmem();
109 }
110 }
111
UseBufferOnPort(enum PortIndex portIndex,int bufferCount,int bufferSize)112 static bool UseBufferOnPort(enum PortIndex portIndex, int bufferCount, int bufferSize)
113 {
114 for (int i = 0; i < bufferCount; i++) {
115 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
116 if (omxBuffer == nullptr) {
117 HDF_LOGE("%{public}s omxBuffer is null", __func__);
118 return false;
119 }
120
121 int fd = OHOS::AshmemCreate(0, bufferSize);
122 shared_ptr<OHOS::Ashmem> sharedMem = make_shared<OHOS::Ashmem>(fd, bufferSize);
123 if (sharedMem == nullptr) {
124 HDF_LOGE("%{public}s sharedMem is null", __func__);
125 if (fd >= 0) {
126 close(fd);
127 fd = -1;
128 }
129 return false;
130 }
131 InitCodecBufferWithAshMem(portIndex, bufferSize, omxBuffer, sharedMem);
132 auto err = g_component->UseBuffer(g_component, static_cast<uint32_t>(portIndex), omxBuffer.get());
133 if (err != HDF_SUCCESS) {
134 HDF_LOGE("%{public}s failed to UseBuffer with portIndex[%{public}d]", __func__, portIndex);
135 sharedMem->UnmapAshmem();
136 sharedMem->CloseAshmem();
137 sharedMem = nullptr;
138 omxBuffer = nullptr;
139 return false;
140 }
141 omxBuffer->bufferLen = 0;
142 HDF_LOGI("UseBuffer returned bufferID [%{public}d]", omxBuffer->bufferId);
143 std::shared_ptr<BufferInfo> bufferInfo = std::make_shared<BufferInfo>();
144 bufferInfo->omxBuffer = omxBuffer;
145 bufferInfo->sharedMem = sharedMem;
146 if (portIndex == PortIndex::PORT_INDEX_INPUT) {
147 inputBuffers.emplace(std::make_pair(omxBuffer->bufferId, bufferInfo));
148 } else {
149 outputBuffers.emplace(std::make_pair(omxBuffer->bufferId, bufferInfo));
150 }
151 }
152 return true;
153 }
154
155 class CodecHdiAdapterTest : public testing::Test {
156 public:
SetUpTestCase()157 static void SetUpTestCase() {}
TearDownTestCase()158 static void TearDownTestCase() {}
SetUp()159 void SetUp() {}
TearDown()160 void TearDown() {}
161 };
162
163 static char g_arrayStr[ARRAY_TO_STR_LEN];
GetArrayStr(int32_t * array,int32_t arrayLen,int32_t endValue)164 static char *GetArrayStr(int32_t *array, int32_t arrayLen, int32_t endValue)
165 {
166 int32_t len = 0;
167 int32_t totalLen = 0;
168 int32_t ret;
169 char value[INT_TO_STR_LEN];
170 ret = memset_s(g_arrayStr, sizeof(g_arrayStr), 0, sizeof(g_arrayStr));
171 if (ret != EOK) {
172 HDF_LOGE("%{public}s: memset_s g_arrayStr failed, error code: %{public}d", __func__, ret);
173 return g_arrayStr;
174 }
175 for (int32_t i = 0; i < arrayLen; i++) {
176 if (array[i] == endValue) {
177 break;
178 }
179 ret = memset_s(value, sizeof(value), 0, sizeof(value));
180 if (ret != EOK) {
181 HDF_LOGE("%{public}s: memset_s value failed, error code: %{public}d", __func__, ret);
182 return g_arrayStr;
183 }
184 ret = sprintf_s(value, sizeof(value), "0x0%X, ", array[i]);
185 if (ret < 0) {
186 HDF_LOGE("%{public}s: sprintf_s value failed, error code: %{public}d", __func__, ret);
187 return g_arrayStr;
188 }
189 len = strnlen(value, ARRAY_TO_STR_LEN);
190 ret = memcpy_s(g_arrayStr + totalLen, len, value, len);
191 if (ret != EOK) {
192 HDF_LOGE("%{public}s: memcpy_s g_arrayStr failed, error code: %{public}d", __func__, ret);
193 return g_arrayStr;
194 }
195 totalLen += len;
196 }
197 return g_arrayStr;
198 }
199
PrintCapability(CodecCompCapability * cap,int32_t index)200 static void PrintCapability(CodecCompCapability *cap, int32_t index)
201 {
202 HDF_LOGI("---------------------- component capability %{public}d ---------------------", index + 1);
203 HDF_LOGI("role:%{public}d", cap->role);
204 HDF_LOGI("type:%{public}d", cap->type);
205 HDF_LOGI("compName:%{public}s", cap->compName);
206 HDF_LOGI("supportProfiles:%{public}s", GetArrayStr(cap->supportProfiles, PROFILE_NUM, INVALID_PROFILE));
207 HDF_LOGI("maxInst:%{public}d", cap->maxInst);
208 HDF_LOGI("isSoftwareCodec:%{public}d", cap->isSoftwareCodec);
209 HDF_LOGI("processModeMask:0x0%{public}x", cap->processModeMask);
210 HDF_LOGI("capsMask:0x0%{public}x", cap->capsMask);
211 HDF_LOGI("bitRate.min:%{public}d", cap->bitRate.min);
212 HDF_LOGI("bitRate.max:%{public}d", cap->bitRate.max);
213 if (strstr(cap->compName, "video") != NULL) {
214 HDF_LOGI("minSize.width:%{public}d", cap->port.video.minSize.width);
215 HDF_LOGI("minSize.height:%{public}d", cap->port.video.minSize.height);
216 HDF_LOGI("maxSize.width:%{public}d", cap->port.video.maxSize.width);
217 HDF_LOGI("maxSize.height:%{public}d", cap->port.video.maxSize.height);
218 HDF_LOGI("widthAlignment:%{public}d", cap->port.video.whAlignment.widthAlignment);
219 HDF_LOGI("heightAlignment:%{public}d", cap->port.video.whAlignment.heightAlignment);
220 HDF_LOGI("blockCount.min:%{public}d", cap->port.video.blockCount.min);
221 HDF_LOGI("blockCount.max:%{public}d", cap->port.video.blockCount.max);
222 HDF_LOGI("blocksPerSecond.min:%{public}d", cap->port.video.blocksPerSecond.min);
223 HDF_LOGI("blocksPerSecond.max:%{public}d", cap->port.video.blocksPerSecond.max);
224 HDF_LOGI("blockSize.width:%{public}d", cap->port.video.blockSize.width);
225 HDF_LOGI("blockSize.height:%{public}d", cap->port.video.blockSize.height);
226 HDF_LOGI("supportPixFmts:%{public}s", GetArrayStr(cap->port.video.supportPixFmts, PIX_FORMAT_NUM, 0));
227 } else {
228 HDF_LOGI(":%{public}s", GetArrayStr(cap->port.audio.sampleFormats, SAMPLE_FMT_NUM, AUDIO_SAMPLE_FMT_INVALID));
229 HDF_LOGI(":%{public}s", GetArrayStr(cap->port.audio.sampleRate, SAMPLE_RATE_NUM, AUD_SAMPLE_RATE_INVALID));
230 HDF_LOGI(":%{public}s", GetArrayStr(cap->port.audio.channelLayouts, CHANNEL_NUM, -1));
231 HDF_LOGI(":%{public}s", GetArrayStr(cap->port.audio.channelCount, CHANNEL_NUM, -1));
232 }
233 HDF_LOGI("-------------------------------------------------------------------");
234 }
235
236 /**
237 * @tc.name: HdfCodecHdiGetCodecComponentManagerTest_001
238 * @tc.desc: Get codec component manager test.
239 * @tc.type: FUNC
240 * @tc.require: issueI5HAII
241 */
242 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiGetCodecComponentManagerTest_001, TestSize.Level1)
243 {
244 g_manager = GetCodecComponentManager();
245 ASSERT_TRUE(g_manager != nullptr);
246 g_callback = CodecCallbackTypeGet(nullptr);
247 ASSERT_TRUE(g_callback != nullptr);
248 }
249
250 /**
251 * @tc.name: HdfCodecHdiGetComponentNumTest_001
252 * @tc.desc: Get codec component num test.
253 * @tc.type: FUNC
254 * @tc.require: issueI5HAII
255 */
256 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiGetComponentNumTest_001, TestSize.Level1)
257 {
258 ASSERT_TRUE(g_manager != nullptr);
259 g_count = g_manager->GetComponentNum();
260 ASSERT_GT(g_count, 0);
261 }
262
263 /**
264 * @tc.name: HdfCodecHdiGetComponentCapabilityListTest_001
265 * @tc.desc: Get codec component capability list test.
266 * @tc.type: FUNC
267 * @tc.require: issueI5HAII
268 */
269 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiGetComponentCapabilityListTest_001, TestSize.Level1)
270 {
271 ASSERT_GT(g_count, 0);
272 ASSERT_TRUE(g_manager != nullptr);
273 CodecCompCapability *capList = reinterpret_cast<CodecCompCapability *>
274 (OsalMemAlloc(sizeof(CodecCompCapability) * g_count));
275 ASSERT_TRUE(capList != nullptr);
276 g_manager->GetComponentCapabilityList(capList, g_count);
277 for (int32_t i = 0; i < g_count; i++) {
278 PrintCapability(&capList[i], i);
279 }
280 OsalMemFree(capList);
281 capList = nullptr;
282 }
283
284 // Test CreateComponent
285 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiCreateComponentCompNameErrorTest_001, TestSize.Level1)
286 {
287 ASSERT_TRUE(g_manager != nullptr);
288 ASSERT_TRUE(g_callback != nullptr);
289 char name[] = "test";
290 int32_t ret = g_manager->CreateComponent(&g_component, &g_componentId, reinterpret_cast<char *>(name),
291 APP_DATA, g_callback);
292 ASSERT_NE(ret, HDF_SUCCESS);
293 ASSERT_TRUE(g_component == nullptr);
294 }
295
296 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiCreateComponentCompNameNullptrTest_002, TestSize.Level1)
297 {
298 ASSERT_TRUE(g_manager != nullptr);
299 ASSERT_TRUE(g_callback != nullptr);
300 int32_t ret = g_manager->CreateComponent(&g_component, &g_componentId, nullptr, APP_DATA, g_callback);
301 ASSERT_NE(ret, HDF_SUCCESS);
302 ASSERT_TRUE(g_component == nullptr);
303 }
304
305 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiCreateComponentAppdataMaxTest_003, TestSize.Level1)
306 {
307 ASSERT_TRUE(g_manager != nullptr);
308 struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr);
309 ASSERT_TRUE(callback != nullptr);
310 struct CodecComponentType *component = nullptr;
311 uint32_t componentId = 0;
312 int32_t ret =
313 g_manager->CreateComponent(&component, &componentId, const_cast<char *>(DECODER_AVC), APP_DATA_MAX, callback);
314 ASSERT_EQ(ret, HDF_SUCCESS);
315 ASSERT_TRUE(component != nullptr);
316 ret = g_manager->DestroyComponent(componentId);
317 ASSERT_EQ(ret, HDF_SUCCESS);
318 CodecCallbackTypeRelease(callback);
319 callback = nullptr;
320 }
321
322 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiCreateComponentAppdataMinTest_004, TestSize.Level1)
323 {
324 ASSERT_TRUE(g_manager != nullptr);
325 struct CodecCallbackType *callback = CodecCallbackTypeGet(nullptr);
326 ASSERT_TRUE(callback != nullptr);
327 struct CodecComponentType *component = nullptr;
328 uint32_t componentId = 0;
329 int32_t ret =
330 g_manager->CreateComponent(&component, &componentId, const_cast<char *>(DECODER_AVC), APP_DATA_MIN, callback);
331 ASSERT_EQ(ret, HDF_SUCCESS);
332 ASSERT_TRUE(component != nullptr);
333 ret = g_manager->DestroyComponent(componentId);
334 ASSERT_EQ(ret, HDF_SUCCESS);
335 CodecCallbackTypeRelease(callback);
336 callback = nullptr;
337 }
338
339 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiCreateComponentCallbackIsNullptrTest_005, TestSize.Level1)
340 {
341 ASSERT_TRUE(g_manager != nullptr);
342 struct CodecCallbackType *callback = nullptr;
343 struct CodecComponentType *component = nullptr;
344 uint32_t componentId = 0;
345 int32_t ret =
346 g_manager->CreateComponent(&component, &componentId, const_cast<char *>(DECODER_AVC), APP_DATA, callback);
347 ASSERT_NE(ret, HDF_SUCCESS);
348 }
349
350 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiCreateComponentSuccessTest_006, TestSize.Level1)
351 {
352 ASSERT_TRUE(g_manager != nullptr);
353 ASSERT_TRUE(g_callback != nullptr);
354 int32_t ret = g_manager->CreateComponent(&g_component, &g_componentId,
355 const_cast<char *>(ENCODER_AVC), APP_DATA, g_callback);
356 ASSERT_EQ(ret, HDF_SUCCESS);
357 ASSERT_TRUE(g_component != nullptr);
358 }
359
360 // Test GetComponentVersion Adapter not support
361 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiGetComponentVersionUnsupportedTest_001, TestSize.Level1)
362 {
363 ASSERT_TRUE(g_component != nullptr);
364 struct CompVerInfo verInfo;
365 int32_t ret = g_component->GetComponentVersion(g_component, &verInfo);
366 g_version = verInfo.compVersion;
367 ASSERT_NE(ret, HDF_SUCCESS);
368 }
369
370 // Test GetParameter
371 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiGetParameterParamStructNullptrTest_001, TestSize.Level1)
372 {
373 ASSERT_TRUE(g_component != nullptr);
374 auto ret = g_component->GetParameter(g_component, OMX_IndexParamVideoPortFormat, nullptr, 0);
375 ASSERT_NE(ret, HDF_SUCCESS);
376 }
377
378 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiGetParameterSuccessTest_002, TestSize.Level1)
379 {
380 ASSERT_TRUE(g_component != nullptr);
381 OMX_VIDEO_PARAM_PORTFORMATTYPE param;
382 InitParam(param);
383 param.nPortIndex = static_cast<uint32_t>(PortIndex::PORT_INDEX_INPUT);
384 param.eCompressionFormat = OMX_VIDEO_CodingAVC;
385 auto ret = g_component->GetParameter(
386 g_component, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(¶m), sizeof(param));
387 ASSERT_EQ(ret, HDF_SUCCESS);
388 }
389
390 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiGetParameterParamIndexNotMatchParamStructTest_003, TestSize.Level1)
391 {
392 ASSERT_TRUE(g_component != nullptr);
393 OMX_VIDEO_CONFIG_BITRATETYPE param;
394 InitParam(param);
395 param.nPortIndex = static_cast<uint32_t>(PortIndex::PORT_INDEX_INPUT);
396 auto ret = g_component->GetParameter(
397 g_component, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(¶m), sizeof(param));
398 ASSERT_NE(ret, HDF_SUCCESS);
399 }
400
401 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiGetParameterParamIndexUnusedTest_004, TestSize.Level1)
402 {
403 ASSERT_TRUE(g_component != nullptr);
404 OMX_VIDEO_CONFIG_BITRATETYPE param;
405 InitParam(param);
406 param.nPortIndex = static_cast<uint32_t>(PortIndex::PORT_INDEX_INPUT);
407 auto ret = g_component->GetParameter(
408 g_component, OMX_IndexVideoStartUnused, reinterpret_cast<int8_t *>(¶m), sizeof(param));
409 ASSERT_NE(ret, HDF_SUCCESS);
410 }
411
412 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiSetPortDefineSuccessTest_001, TestSize.Level1)
413 {
414 ASSERT_TRUE(g_component != nullptr);
415 OMX_PARAM_PORTDEFINITIONTYPE param;
416 InitParam(param);
417 param.nPortIndex = static_cast<uint32_t>(PortIndex::PORT_INDEX_INPUT);
418 auto ret = g_component->GetParameter(
419 g_component, OMX_IndexParamPortDefinition, reinterpret_cast<int8_t *>(¶m), sizeof(param));
420 ASSERT_EQ(ret, HDF_SUCCESS);
421
422 param.format.video.nFrameWidth = VIDEO_WIDHT;
423 param.format.video.nFrameHeight = VIDEO_HEIGHT;
424 ret = g_component->SetParameter(
425 g_component, OMX_IndexParamPortDefinition, reinterpret_cast<int8_t *>(¶m), sizeof(param));
426 ASSERT_EQ(ret, HDF_SUCCESS);
427 }
428
429 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiSetParameterSuccessTest_001, TestSize.Level1)
430 {
431 ASSERT_TRUE(g_component != nullptr);
432 OMX_VIDEO_PARAM_PORTFORMATTYPE param;
433 InitParam(param);
434 param.xFramerate = FRAME_RATE;
435 param.nPortIndex = static_cast<uint32_t>(PortIndex::PORT_INDEX_INPUT);
436 int32_t ret = g_component->SetParameter(
437 g_component, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(¶m), sizeof(param));
438 ASSERT_EQ(ret, HDF_SUCCESS);
439 }
440
441 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiSetParameterParamStructNullptrTest_002, TestSize.Level1)
442 {
443 ASSERT_TRUE(g_component != nullptr);
444 int32_t ret = g_component->SetParameter(g_component, OMX_IndexParamVideoPortFormat, nullptr, 0);
445 ASSERT_NE(ret, HDF_SUCCESS);
446 }
447
448 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiSetParameterParamIndexNotMatchParamStructTest_003, TestSize.Level1)
449 {
450 ASSERT_TRUE(g_component != nullptr);
451 OMX_VIDEO_CONFIG_BITRATETYPE param;
452 InitParam(param);
453 param.nPortIndex = static_cast<uint32_t>(PortIndex::PORT_INDEX_INPUT);
454 int32_t ret = g_component->SetParameter(
455 g_component, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(¶m), sizeof(param));
456 ASSERT_NE(ret, HDF_SUCCESS);
457 }
458
459 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiSetParameterParamIndexUnusedTest_004, TestSize.Level1)
460 {
461 ASSERT_TRUE(g_component != nullptr);
462 OMX_VIDEO_PARAM_PORTFORMATTYPE param;
463 InitParam(param);
464 param.nPortIndex = static_cast<uint32_t>(PortIndex::PORT_INDEX_INPUT);
465 int32_t ret = g_component->SetParameter(
466 g_component, OMX_IndexVideoStartUnused, reinterpret_cast<int8_t *>(¶m), sizeof(param));
467 ASSERT_NE(ret, HDF_SUCCESS);
468 }
469
470 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiSetParameterCodecComponentTypeNullptrTest_005, TestSize.Level1)
471 {
472 ASSERT_TRUE(g_component != nullptr);
473 OMX_VIDEO_PARAM_PORTFORMATTYPE param;
474 InitParam(param);
475 param.nPortIndex = static_cast<uint32_t>(PortIndex::PORT_INDEX_INPUT);
476 int32_t ret = g_component->SetParameter(
477 nullptr, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(¶m), sizeof(param));
478 ASSERT_NE(ret, HDF_SUCCESS);
479 }
480
481 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiSetParameterParamStructLenNotMatchTest_006, TestSize.Level1)
482 {
483 ASSERT_TRUE(g_component != nullptr);
484 OMX_VIDEO_PARAM_PORTFORMATTYPE param;
485 InitParam(param);
486 param.nPortIndex = static_cast<uint32_t>(PortIndex::PORT_INDEX_INPUT);
487 int32_t ret =
488 g_component->SetParameter(g_component, OMX_IndexParamVideoPortFormat, reinterpret_cast<int8_t *>(¶m), 0);
489 ASSERT_NE(ret, HDF_SUCCESS);
490 }
491
492 // Test GetConfig Adapter not support
493 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiGetConfigUnsupportedTest_001, TestSize.Level1)
494 {
495 ASSERT_TRUE(g_component != nullptr);
496 OMX_VIDEO_CONFIG_BITRATETYPE param;
497 InitParam(param);
498 param.nPortIndex = static_cast<uint32_t>(PortIndex::PORT_INDEX_OUTPUT);
499 int32_t ret = g_component->GetConfig(
500 g_component, OMX_IndexConfigVideoBitrate, reinterpret_cast<int8_t *>(¶m), sizeof(param));
501 ASSERT_NE(ret, HDF_SUCCESS);
502 }
503
504 // Test SetConfig Adapter not support
505 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiSetConfigUnsupportedTest_001, TestSize.Level1)
506 {
507 ASSERT_TRUE(g_component != nullptr);
508 OMX_VIDEO_CONFIG_BITRATETYPE param;
509 InitParam(param);
510 param.nPortIndex = static_cast<uint32_t>(PortIndex::PORT_INDEX_OUTPUT);
511 param.nEncodeBitrate = FRAMERATE;
512 int32_t ret = g_component->SetConfig(
513 g_component, OMX_IndexConfigVideoBitrate, reinterpret_cast<int8_t *>(¶m), sizeof(param));
514 ASSERT_NE(ret, HDF_SUCCESS);
515 }
516
517 // Test GetExtensionIndex Adapter not support
518 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiGetExtensionIndexUnsupportedTest_001, TestSize.Level1)
519 {
520 ASSERT_TRUE(g_component != nullptr);
521 OMX_INDEXTYPE indexType;
522 int32_t ret =
523 g_component->GetExtensionIndex(g_component, "OMX.Topaz.index.param.extended_video", (uint32_t *)&indexType);
524 ASSERT_NE(ret, HDF_SUCCESS);
525 }
526
527 // Test GetState
528 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiGetStateSuccessTest_001, TestSize.Level1)
529 {
530 ASSERT_TRUE(g_component != nullptr);
531 OMX_STATETYPE state;
532 int32_t ret = g_component->GetState(g_component, &state);
533 ASSERT_EQ(state, OMX_StateLoaded);
534 ASSERT_EQ(ret, HDF_SUCCESS);
535 }
536
537 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiGetStateStateNullptrTest_002, TestSize.Level1)
538 {
539 ASSERT_TRUE(g_component != nullptr);
540 int32_t ret = g_component->GetState(g_component, nullptr);
541 ASSERT_NE(ret, HDF_SUCCESS);
542 }
543
544 // Test ComponentTunnelRequest Adapter not support
545 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiTunnelRequestUnsupportedTest_001, TestSize.Level1)
546 {
547 ASSERT_TRUE(g_component != nullptr);
548 const int32_t tunneledComp = 1002;
549 const uint32_t tunneledPort = 101;
550 OMX_TUNNELSETUPTYPE tunnelSetup;
551 tunnelSetup.eSupplier = OMX_BufferSupplyInput;
552
553 int32_t ret = g_component->ComponentTunnelRequest(
554 g_component, static_cast<uint32_t>(PortIndex::PORT_INDEX_OUTPUT), tunneledComp, tunneledPort, &tunnelSetup);
555 ASSERT_NE(ret, HDF_SUCCESS);
556 }
557
558 struct OmxCodecBuffer allocBuffer;
559 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiAllocateBufferInvalidInputBufferTypeTest_001, TestSize.Level1)
560 {
561 ASSERT_TRUE(g_component != nullptr);
562 allocBuffer.bufferType = CODEC_BUFFER_TYPE_INVALID;
563 allocBuffer.fenceFd = -1;
564 allocBuffer.version = g_version;
565 allocBuffer.allocLen = BUFFER_SIZE;
566 allocBuffer.buffer = 0;
567 allocBuffer.bufferLen = 0;
568 allocBuffer.pts = 0;
569 allocBuffer.flag = 0;
570 allocBuffer.type = READ_ONLY_TYPE;
571 int32_t ret = g_component->AllocateBuffer(g_component, static_cast<uint32_t>(PortIndex::PORT_INDEX_INPUT),
572 &allocBuffer);
573 ASSERT_NE(ret, HDF_SUCCESS);
574 }
575
576 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiAllocateBufferInputBufferNotInitTest_002, TestSize.Level1)
577 {
578 ASSERT_TRUE(g_component != nullptr);
579 allocBuffer.bufferType = CODEC_BUFFER_TYPE_VIRTUAL_ADDR;
580 int32_t ret = g_component->AllocateBuffer(g_component, static_cast<uint32_t>(PortIndex::PORT_INDEX_INPUT),
581 &allocBuffer);
582 ASSERT_NE(ret, HDF_SUCCESS);
583 }
584
585 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiAllocateBufferInvalidOutputBufferTypeTest_003, TestSize.Level1)
586 {
587 ASSERT_TRUE(g_component != nullptr);
588 allocBuffer.bufferType = CODEC_BUFFER_TYPE_INVALID;
589 int32_t ret = g_component->AllocateBuffer(g_component, static_cast<uint32_t>(PortIndex::PORT_INDEX_OUTPUT),
590 &allocBuffer);
591 ASSERT_NE(ret, HDF_SUCCESS);
592 }
593
594 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiAllocateBufferOutputBufferNotInitTest_004, TestSize.Level1)
595 {
596 ASSERT_TRUE(g_component != nullptr);
597 allocBuffer.bufferType = CODEC_BUFFER_TYPE_VIRTUAL_ADDR;
598 int32_t ret = g_component->AllocateBuffer(g_component, static_cast<uint32_t>(PortIndex::PORT_INDEX_OUTPUT),
599 &allocBuffer);
600 ASSERT_NE(ret, HDF_SUCCESS);
601 }
602
603 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiAllocateBufferAvshareMemFdInputNotInitTest_005, TestSize.Level1)
604 {
605 ASSERT_TRUE(g_component != nullptr);
606 allocBuffer.bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD;
607 int32_t ret = g_component->AllocateBuffer(g_component, static_cast<uint32_t>(PortIndex::PORT_INDEX_INPUT),
608 &allocBuffer);
609 ASSERT_NE(ret, HDF_SUCCESS);
610 }
611
612 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiAllocateBufferAvshareMemFdOutputNotInitTest_006, TestSize.Level1)
613 {
614 ASSERT_TRUE(g_component != nullptr);
615 allocBuffer.bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD;
616 int32_t ret = g_component->AllocateBuffer(g_component, static_cast<uint32_t>(PortIndex::PORT_INDEX_OUTPUT),
617 &allocBuffer);
618 ASSERT_NE(ret, HDF_SUCCESS);
619 }
620
621 // Test UseBuffer
622 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiUseBufferInvalidInputBufferTypeTest_001, TestSize.Level1)
623 {
624 ASSERT_TRUE(g_component != nullptr);
625 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
626 ASSERT_TRUE(omxBuffer != nullptr);
627 omxBuffer->size = sizeof(OmxCodecBuffer);
628 omxBuffer->version = g_version;
629 omxBuffer->bufferType = CODEC_BUFFER_TYPE_INVALID;
630 omxBuffer->bufferLen = 0;
631 omxBuffer->buffer = nullptr;
632 omxBuffer->allocLen = 0;
633 omxBuffer->fenceFd = -1;
634 omxBuffer->pts = 0;
635 omxBuffer->flag = 0;
636
637 auto err = g_component->UseBuffer(g_component, static_cast<uint32_t>(PortIndex::PORT_INDEX_INPUT),
638 omxBuffer.get());
639 ASSERT_NE(err, HDF_SUCCESS);
640 }
641
642 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiUseBufferInvalidOutputBufferTypeTest_002, TestSize.Level1)
643 {
644 ASSERT_TRUE(g_component != nullptr);
645 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
646 ASSERT_TRUE(omxBuffer != nullptr);
647 omxBuffer->size = sizeof(OmxCodecBuffer);
648 omxBuffer->version = g_version;
649 omxBuffer->bufferType = CODEC_BUFFER_TYPE_INVALID;
650 omxBuffer->bufferLen = 0;
651 omxBuffer->buffer = nullptr;
652 omxBuffer->allocLen = 0;
653 omxBuffer->fenceFd = -1;
654 omxBuffer->pts = 0;
655 omxBuffer->flag = 0;
656
657 auto err = g_component->UseBuffer(g_component, static_cast<uint32_t>(PortIndex::PORT_INDEX_OUTPUT),
658 omxBuffer.get());
659 ASSERT_NE(err, HDF_SUCCESS);
660 }
661
662 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiUseBufferTestVirtualAddrInputTest_003, TestSize.Level1)
663 {
664 ASSERT_TRUE(g_component != nullptr);
665 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
666 ASSERT_TRUE(omxBuffer != nullptr);
667 omxBuffer->size = sizeof(OmxCodecBuffer);
668 omxBuffer->version = g_version;
669 omxBuffer->bufferType = CODEC_BUFFER_TYPE_VIRTUAL_ADDR;
670 omxBuffer->bufferLen = 0;
671 omxBuffer->buffer = nullptr;
672 omxBuffer->allocLen = 0;
673 omxBuffer->fenceFd = -1;
674 omxBuffer->pts = 0;
675 omxBuffer->flag = 0;
676
677 auto err = g_component->UseBuffer(g_component, static_cast<uint32_t>(PortIndex::PORT_INDEX_INPUT),
678 omxBuffer.get());
679 ASSERT_NE(err, HDF_SUCCESS);
680 }
681
682 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiUseBufferTestVirtualAddrOutput_004, TestSize.Level1)
683 {
684 ASSERT_TRUE(g_component != nullptr);
685 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
686 ASSERT_TRUE(omxBuffer != nullptr);
687 omxBuffer->size = sizeof(OmxCodecBuffer);
688 omxBuffer->version = g_version;
689 omxBuffer->bufferType = CODEC_BUFFER_TYPE_VIRTUAL_ADDR;
690 omxBuffer->bufferLen = 0;
691 omxBuffer->buffer = nullptr;
692 omxBuffer->allocLen = 0;
693 omxBuffer->fenceFd = -1;
694 omxBuffer->pts = 0;
695 omxBuffer->flag = 0;
696
697 auto err = g_component->UseBuffer(g_component, static_cast<uint32_t>(PortIndex::PORT_INDEX_OUTPUT),
698 omxBuffer.get());
699 ASSERT_NE(err, HDF_SUCCESS);
700 }
701
702 // Use buffer on input index
703 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiUseBufferInputSuccessTest_005, TestSize.Level1)
704 {
705 ASSERT_TRUE(g_component != nullptr);
706 OMX_PARAM_PORTDEFINITIONTYPE param;
707 InitParam(param);
708 param.nPortIndex = static_cast<OMX_U32>(PortIndex::PORT_INDEX_INPUT);
709 auto err = g_component->GetParameter(g_component, OMX_IndexParamPortDefinition,
710 reinterpret_cast<int8_t *>(¶m), sizeof(param));
711 ASSERT_EQ(err, HDF_SUCCESS);
712
713 int bufferSize = param.nBufferSize;
714 int bufferCount = param.nBufferCountActual;
715 bool ret = UseBufferOnPort(PortIndex::PORT_INDEX_INPUT, bufferCount, bufferSize);
716 ASSERT_TRUE(ret);
717 }
718
719 // Use Buffer on output index
720 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiUseBufferOutputSuccessTest_006, TestSize.Level1)
721 {
722 ASSERT_TRUE(g_component != nullptr);
723 OMX_PARAM_PORTDEFINITIONTYPE param;
724 InitParam(param);
725 param.nPortIndex = static_cast<OMX_U32>(PortIndex::PORT_INDEX_OUTPUT);
726 auto err = g_component->GetParameter(g_component, OMX_IndexParamPortDefinition,
727 reinterpret_cast<int8_t *>(¶m), sizeof(param));
728 ASSERT_EQ(err, HDF_SUCCESS);
729
730 int bufferSize = param.nBufferSize;
731 int bufferCount = param.nBufferCountActual;
732 bool ret = UseBufferOnPort(PortIndex::PORT_INDEX_OUTPUT, bufferCount, bufferSize);
733 ASSERT_TRUE(ret);
734 }
735
736 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiUseBufferDynamicHandleOutputTest_007, TestSize.Level1)
737 {
738 ASSERT_TRUE(g_component != nullptr);
739 std::shared_ptr<OmxCodecBuffer> omxBuffer = std::make_shared<OmxCodecBuffer>();
740 ASSERT_TRUE(omxBuffer != nullptr);
741 omxBuffer->size = sizeof(OmxCodecBuffer);
742 omxBuffer->version = g_version;
743 omxBuffer->bufferType = CODEC_BUFFER_TYPE_DYNAMIC_HANDLE;
744
745 omxBuffer->bufferLen = 0;
746 omxBuffer->buffer = nullptr;
747 omxBuffer->allocLen = 0;
748 omxBuffer->fenceFd = -1;
749 omxBuffer->pts = 0;
750 omxBuffer->flag = 0;
751
752 auto err = g_component->UseBuffer(g_component, static_cast<uint32_t>(PortIndex::PORT_INDEX_OUTPUT),
753 omxBuffer.get());
754 if (err != HDF_SUCCESS) {
755 HDF_LOGE("%{public}s failed to UseBuffer with input port", __func__);
756 omxBuffer = nullptr;
757 }
758 ASSERT_NE(err, HDF_SUCCESS);
759 }
760
761 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiUseBufferAbnormalPortIndexTest_008, TestSize.Level1)
762 {
763 ASSERT_TRUE(g_component != nullptr);
764 OMX_PARAM_PORTDEFINITIONTYPE param;
765 InitParam(param);
766 param.nPortIndex = static_cast<OMX_U32>(PortIndex::PORT_INDEX_INPUT);
767 auto err = g_component->GetParameter(g_component, OMX_IndexParamPortDefinition,
768 reinterpret_cast<int8_t *>(¶m), sizeof(param));
769 ASSERT_EQ(err, HDF_SUCCESS);
770
771 int bufferSize = param.nBufferSize;
772 int bufferCount = param.nBufferCountActual;
773 bool ret = UseBufferOnPort(PortIndex::PORT_INDEX_ERROR_INPUT, bufferCount, bufferSize);
774 ASSERT_FALSE(ret);
775 }
776
777 // Test SendCommand
778 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiSetStateLoadedToIdleTest_001, TestSize.Level1)
779 {
780 ASSERT_TRUE(g_component != nullptr);
781 int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StateIdle, nullptr, 0);
782 ASSERT_EQ(ret, HDF_SUCCESS);
783 }
784
785 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiSetStateIdleToExecutingTest_002, TestSize.Level1)
786 {
787 ASSERT_TRUE(g_component != nullptr);
788 int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StateExecuting, nullptr, 0);
789 ASSERT_EQ(ret, HDF_SUCCESS);
790 }
791
792 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiSetStateExecutingToPauseTest_003, TestSize.Level1)
793 {
794 ASSERT_TRUE(g_component != nullptr);
795 int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StatePause, nullptr, 0);
796 ASSERT_EQ(ret, HDF_SUCCESS);
797 }
798
799 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiSetStatePauseToIdleTest_004, TestSize.Level1)
800 {
801 ASSERT_TRUE(g_component != nullptr);
802 int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StateIdle, nullptr, 0);
803 ASSERT_EQ(ret, HDF_SUCCESS);
804
805 OMX_STATETYPE state;
806 ret = g_component->GetState(g_component, &state);
807 ASSERT_EQ(ret, HDF_SUCCESS);
808 }
809
810 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiSendCommandCodecComponentTypeNullptrTest_005, TestSize.Level1)
811 {
812 ASSERT_TRUE(g_component != nullptr);
813 int32_t ret = g_component->SendCommand(nullptr, OMX_CommandStateSet, OMX_StateIdle, nullptr, 0);
814 ASSERT_NE(ret, HDF_SUCCESS);
815 }
816
817 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiSendCommandAbnormalCommandTest_006, TestSize.Level1)
818 {
819 ASSERT_TRUE(g_component != nullptr);
820 int32_t ret = g_component->SendCommand(g_component, OMX_CommandMax, OMX_StatePause, nullptr, 0);
821 ASSERT_NE(ret, HDF_SUCCESS);
822 }
823
824 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiSendCommandAbnormalParamTest_007, TestSize.Level1)
825 {
826 ASSERT_TRUE(g_component != nullptr);
827 int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StateMax, nullptr, 0);
828 ASSERT_NE(ret, HDF_SUCCESS);
829 }
830
831 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiUseEglImageUnsupportedTest_001, TestSize.Level1)
832 {
833 ASSERT_TRUE(g_component != nullptr);
834 struct OmxCodecBuffer buffer;
835 buffer.fenceFd = -1;
836 buffer.version = g_version;
837 buffer.bufferType = CODEC_BUFFER_TYPE_AVSHARE_MEM_FD;
838 buffer.allocLen = BUFFER_SIZE;
839 buffer.buffer = 0;
840 buffer.bufferLen = 0;
841 buffer.pts = 0;
842 buffer.flag = 0;
843 buffer.type = READ_ONLY_TYPE;
844 auto eglImage = std::make_unique<int8_t[]>(BUFFER_SIZE);
845 ASSERT_TRUE(eglImage != nullptr);
846 int32_t ret = g_component->UseEglImage(
847 g_component, &buffer, static_cast<uint32_t>(PortIndex::PORT_INDEX_INPUT), eglImage.get(), BUFFER_SIZE);
848 ASSERT_NE(ret, HDF_SUCCESS);
849 eglImage = nullptr;
850 }
851
852 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiWaitStateIdleTest_001, TestSize.Level1)
853 {
854 ASSERT_TRUE(g_component != nullptr);
855 // wait for Idle status
856 OMX_STATETYPE state = OMX_StateInvalid;
857 do {
858 usleep(100);
859 auto ret = g_component->GetState(g_component, &state);
860 ASSERT_EQ(ret, HDF_SUCCESS);
861 } while (state != OMX_StateIdle);
862 }
863
864 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiFillThisBufferSuccessTest_001, TestSize.Level1)
865 {
866 ASSERT_TRUE(g_component != nullptr);
867 auto iter = outputBuffers.begin();
868 if (iter != outputBuffers.end()) {
869 int32_t ret = g_component->FillThisBuffer(g_component, iter->second->omxBuffer.get());
870 ASSERT_EQ(ret, HDF_SUCCESS);
871 }
872 }
873
874 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiFillThisBufferUseErrorBufferIdTest_002, TestSize.Level1)
875 {
876 ASSERT_TRUE(g_component != nullptr);
877 auto iter = outputBuffers.begin();
878 if (iter != outputBuffers.end()) {
879 auto omxBuffer = iter->second->omxBuffer;
880 auto tempId = omxBuffer->bufferId;
881 omxBuffer->bufferId = BUFFER_ID_ERROR;
882 int32_t ret = g_component->FillThisBuffer(g_component, omxBuffer.get());
883 ASSERT_NE(ret, HDF_SUCCESS);
884 omxBuffer->bufferId = tempId;
885 }
886 }
887
888 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiEmptyThisBufferSuccessTest_001, TestSize.Level1)
889 {
890 ASSERT_TRUE(g_component != nullptr);
891 auto iter = inputBuffers.begin();
892 if (iter != inputBuffers.end()) {
893 int32_t ret = g_component->EmptyThisBuffer(g_component, iter->second->omxBuffer.get());
894 ASSERT_EQ(ret, HDF_SUCCESS);
895 }
896 }
897
898 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiEmptyThisBufferUseErrorBufferIdTest_002, TestSize.Level1)
899 {
900 ASSERT_TRUE(g_component != nullptr);
901 auto iter = inputBuffers.begin();
902 if (iter != inputBuffers.end()) {
903 auto omxBuffer = iter->second->omxBuffer;
904 auto tempId = omxBuffer->bufferId;
905 omxBuffer->bufferId = BUFFER_ID_ERROR;
906 int32_t ret = g_component->EmptyThisBuffer(g_component, iter->second->omxBuffer.get());
907 ASSERT_NE(ret, HDF_SUCCESS);
908 omxBuffer->bufferId = tempId;
909 }
910 }
911
912 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiSetCallbackSuccessTest_001, TestSize.Level1)
913 {
914 ASSERT_TRUE(g_component != nullptr);
915 if (g_callback != nullptr) {
916 CodecCallbackTypeRelease(g_callback);
917 }
918 g_callback = CodecCallbackTypeGet(nullptr);
919 ASSERT_TRUE(g_callback != nullptr);
920 int32_t ret = g_component->SetCallbacks(g_component, g_callback, APP_DATA);
921 ASSERT_EQ(ret, HDF_SUCCESS);
922 }
923
924 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiSetCallbackAppDataLenMaxTest_002, TestSize.Level1)
925 {
926 ASSERT_TRUE(g_component != nullptr);
927 if (g_callback != nullptr) {
928 CodecCallbackTypeRelease(g_callback);
929 }
930 g_callback = CodecCallbackTypeGet(nullptr);
931 ASSERT_TRUE(g_callback != nullptr);
932 int32_t ret = g_component->SetCallbacks(g_component, g_callback, APP_DATA_MAX);
933 ASSERT_EQ(ret, HDF_SUCCESS);
934 }
935
936 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiSetCallbackAppDataLenMinTest_003, TestSize.Level1)
937 {
938 ASSERT_TRUE(g_component != nullptr);
939 if (g_callback != nullptr) {
940 CodecCallbackTypeRelease(g_callback);
941 }
942 g_callback = CodecCallbackTypeGet(nullptr);
943 ASSERT_TRUE(g_callback != nullptr);
944 int32_t ret = g_component->SetCallbacks(g_component, g_callback, APP_DATA_MIN);
945 ASSERT_EQ(ret, HDF_SUCCESS);
946 }
947
948 // Test ComponentRoleEnum Adapter not support
949 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiRoleEnumUnsupportedTest_001, TestSize.Level1)
950 {
951 ASSERT_TRUE(g_component != nullptr);
952 uint8_t role[ROLE_LEN] = {0};
953 int32_t ret = g_component->ComponentRoleEnum(g_component, role, ROLE_LEN, 0);
954 ASSERT_NE(ret, HDF_SUCCESS);
955 }
956
957 // Test FreeBuffer Adapter not support
958 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiFreeBufferPortIndexOutputUnsupportedTest_001, TestSize.Level1)
959 {
960 ASSERT_TRUE(g_component != nullptr);
961 auto iter = outputBuffers.begin();
962 while (iter != outputBuffers.end()) {
963 int32_t ret = g_component->FreeBuffer(g_component,
964 static_cast<uint32_t>(PortIndex::PORT_INDEX_OUTPUT), iter->second->omxBuffer.get());
965 ASSERT_NE(ret, HDF_SUCCESS);
966 iter = outputBuffers.erase(iter);
967 }
968 }
969
970 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiFreeBufferPortIndexInputUnsupportedTest_002, TestSize.Level1)
971 {
972 ASSERT_TRUE(g_component != nullptr);
973 auto iter = inputBuffers.begin();
974 while (iter != inputBuffers.end()) {
975 int32_t ret = g_component->FreeBuffer(g_component,
976 static_cast<uint32_t>(PortIndex::PORT_INDEX_INPUT), iter->second->omxBuffer.get());
977 ASSERT_NE(ret, HDF_SUCCESS);
978 iter = inputBuffers.erase(iter);
979 }
980 }
981
982 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiSetStateIdleToLoadedTest_001, TestSize.Level1)
983 {
984 ASSERT_TRUE(g_component != nullptr);
985 int32_t ret = g_component->SendCommand(g_component, OMX_CommandStateSet, OMX_StateLoaded, nullptr, 0);
986 ASSERT_EQ(ret, HDF_SUCCESS);
987
988 OMX_STATETYPE state = OMX_StateInvalid;
989 do {
990 usleep(100);
991 auto ret = g_component->GetState(g_component, &state);
992 ASSERT_EQ(ret, HDF_SUCCESS);
993 } while (state != OMX_StateLoaded);
994 }
995
996 // Test ComponentDeInit Adapter not support
997 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiDeInitUnsupportedTest_001, TestSize.Level1)
998 {
999 ASSERT_TRUE(g_component != nullptr);
1000 int32_t ret = g_component->ComponentDeInit(g_component);
1001 ASSERT_NE(ret, HDF_SUCCESS);
1002 }
1003
1004 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiDestroyComponentSuccessTest_001, TestSize.Level1)
1005 {
1006 ASSERT_TRUE(g_component != nullptr);
1007 ASSERT_TRUE(g_manager != nullptr);
1008 int ret = g_manager->DestroyComponent(g_componentId);
1009 ASSERT_EQ(ret, HDF_SUCCESS);
1010 }
1011
1012 HWTEST_F(CodecHdiAdapterTest, HdfCodecHdiCallbackTypeReleaseAndManagerReleaseTest_001, TestSize.Level1)
1013 {
1014 ASSERT_TRUE(g_manager != nullptr);
1015 ASSERT_TRUE(g_callback != nullptr);
1016 CodecCallbackTypeRelease(g_callback);
1017 CodecComponentManagerRelease();
1018 g_callback = nullptr;
1019 g_manager = nullptr;
1020 }
1021 } // namespace
1022