• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 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 <gtest/gtest.h>
17 #include <securec.h>
18 #include <servmgr_hdi.h>
19 #include <vector>
20 #include "codec_function_utils.h"
21 #include "v3_0/codec_callback_service.h"
22 
23 #define ERR_COUNT (-1)
24 
25 using namespace std;
26 using namespace testing::ext;
27 using OHOS::sptr;
28 using OHOS::HDI::Base::NativeBuffer;
29 using namespace OHOS::HDI::Codec::V3_0;
30 using namespace OHOS::HDI::Display::Buffer::V1_0;
31 using namespace OHOS::HDI::Display::Composer::V1_0;
32 
33 namespace {
34 constexpr CodecType TYPE = CodecType::VIDEO_ENCODER;
35 constexpr AvCodecRole ROLE = MEDIA_ROLETYPE_VIDEO_AVC;
36 static sptr<ICodecComponent> g_component = nullptr;
37 static sptr<ICodecCallback> g_callback = nullptr;
38 static sptr<ICodecComponentManager> g_manager = nullptr;
39 static OHOS::HDI::Codec::V3_0::CodecVersionType g_version;
40 static std::string g_compName = "";
41 
42 class CodecHdiOmxEncTest : public testing::Test {
43 public:
SetUpTestCase()44     static void SetUpTestCase()
45     {
46         g_manager = ICodecComponentManager::Get();
47         int32_t count = 0;
48         auto ret = g_manager->GetComponentNum(count);
49         ASSERT_EQ(ret, HDF_SUCCESS);
50         if (count <= 0) {
51             return;
52         }
53 
54         std::vector<CodecCompCapability> capList;
55         auto err = g_manager->GetComponentCapabilityList(capList, count);
56         ASSERT_TRUE(err == HDF_SUCCESS);
57         for (auto cap : capList) {
58             if (cap.type == TYPE && cap.role == ROLE) {
59                 g_compName = cap.compName;
60                 break;
61             }
62         }
63     }
64 
TearDownTestCase()65     static void TearDownTestCase()
66     {
67         g_manager = nullptr;
68     }
69 
SetUp()70     void SetUp()
71     {
72         ASSERT_TRUE(g_manager != nullptr && !g_compName.empty());
73         g_callback = new CodecCallbackService();
74         ASSERT_TRUE(g_callback != nullptr);
75         auto ret = g_manager->CreateComponent(g_component, componentId_, g_compName.data(), APP_DATA, g_callback);
76         ASSERT_EQ(ret, HDF_SUCCESS);
77         ret = g_manager->CreateComponent(g_component, componentId_, "", APP_DATA, g_callback);
78         ASSERT_TRUE(ret != HDF_SUCCESS);
79         struct CompVerInfo verInfo;
80         ret = g_component->GetComponentVersion(verInfo);
81         ASSERT_EQ(ret, HDF_SUCCESS);
82         g_version = verInfo.compVersion;
83 
84         func_ = new FunctionUtil(g_version);
85         ASSERT_TRUE(func_ != nullptr);
86     }
87 
TearDown()88     void TearDown()
89     {
90         std::vector<int8_t> cmdData;
91         if (g_component != nullptr) {
92             g_component->SendCommand(CODEC_COMMAND_STATE_SET, CODEC_STATE_LOADED, cmdData);
93         }
94         if (g_manager != nullptr && g_component != nullptr) {
95             g_manager->DestroyComponent(componentId_);
96         }
97         g_component = nullptr;
98         g_callback = nullptr;
99         func_ = nullptr;
100     }
101 
102 public:
103     uint32_t componentId_ = 0;
104     sptr<FunctionUtil> func_ = nullptr;
105     const static uint32_t inputIndex = static_cast<uint32_t>(PortIndex::INDEX_INPUT);
106     const static uint32_t outputIndex = static_cast<uint32_t>(PortIndex::INDEX_OUTPUT);
107 };
108 
109 // Test GetComponentVersion
110 /**
111 * @tc.number : SUB_Driver_Codec_idlomx_0900
112 * @tc.name   : HdfCodecHdiGetVersionTest001
113 * @tc.desc   : Verify the GetComponentVersion function when the input parameter is valid.
114   @tc.type: FUNC
115 */
116 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiGetVersionTest001, TestSize.Level1)
117 {
118     ASSERT_TRUE(g_component != nullptr);
119     struct CompVerInfo verInfo;
120     auto ret = g_component->GetComponentVersion(verInfo);
121     ASSERT_EQ(ret, HDF_SUCCESS);
122 }
123 
124 /**
125 * @tc.number : SUB_Driver_Codec_idlomx_1000
126 * @tc.name   : HdfCodecHdiGetParameterTest001
127 * @tc.desc   : Verify the GetParameter function when the input parameter pixFormat.portIndex is outputIndex.
128   @tc.type: FUNC
129 */
130 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiGetParameterTest001, TestSize.Level1)
131 {
132     ASSERT_TRUE(g_component != nullptr);
133     CodecVideoPortFormatParam pixFormat;
134     func_->InitExtParam(pixFormat);
135     pixFormat.portIndex = outputIndex;
136     pixFormat.codecColorIndex = 0;
137 
138     std::vector<int8_t> inParam;
139     func_->ObjectToVector(pixFormat, inParam);
140 
141     std::vector<int8_t> outParam;
142     auto ret = g_component->GetParameter(OMX_IndexCodecVideoPortFormat, inParam, outParam);
143     ASSERT_EQ(ret, HDF_SUCCESS);
144 }
145 
146 /**
147 * @tc.number : SUB_Driver_Codec_idlomx_1100
148 * @tc.name   : HdfCodecHdiGetParameterTest002
149 * @tc.desc   : Verify the GetParameter function when the input parameter pixFormat.portIndex is inputIndex.
150   @tc.type: FUNC
151 */
152 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiGetParameterTest002, TestSize.Level1)
153 {
154     ASSERT_TRUE(g_component != nullptr);
155     CodecVideoPortFormatParam pixFormat;
156     func_->InitExtParam(pixFormat);
157     pixFormat.portIndex = inputIndex;
158     pixFormat.codecColorIndex = 0;
159 
160     std::vector<int8_t> inParam;
161     func_->ObjectToVector(pixFormat, inParam);
162 
163     std::vector<int8_t> outParam;
164     auto ret = g_component->GetParameter(OMX_IndexCodecVideoPortFormat, inParam, outParam);
165     ASSERT_EQ(ret, HDF_SUCCESS);
166 }
167 
168 // Test GetParameter
169 /**
170 * @tc.number : SUB_Driver_Codec_idlomx_1200
171 * @tc.name   : HdfCodecHdiGetParameterTest003
172 * @tc.desc   : Verify the GetParameter function when the input parameter is valid.
173   @tc.type: FUNC
174 */
175 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiGetParameterTest003, TestSize.Level1)
176 {
177     ASSERT_TRUE(g_component != nullptr);
178     std::vector<int8_t> inParam;
179     std::vector <int8_t> outParam;
180     auto ret = g_component->GetParameter(OMX_IndexParamVideoPortFormat, inParam, outParam);
181     ASSERT_NE(ret, HDF_SUCCESS);
182 }
183 
184 /**
185 * @tc.number : SUB_Driver_Codec_idlomx_1300
186 * @tc.name   : HdfCodecHdiGetParameterTest004
187 * @tc.desc   : Verify the GetParameter function when the input parameter is valid.
188   @tc.type: FUNC
189 */
190 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiGetParameterTest004, TestSize.Level1)
191 {
192     ASSERT_TRUE(g_component != nullptr);
193     OMX_VIDEO_PARAM_PORTFORMATTYPE param;
194     func_->InitParam(param);
195     param.nPortIndex = inputIndex;
196     param.eCompressionFormat = OMX_VIDEO_CodingAVC;
197     std::vector<int8_t> inParam;
198     func_->ObjectToVector(param, inParam);
199 
200     std::vector<int8_t> outParam;
201     auto ret = g_component->GetParameter(OMX_IndexCodecVideoPortFormat, inParam, outParam);
202     ASSERT_EQ(ret, HDF_SUCCESS);
203 }
204 
205 /**
206 * @tc.number : SUB_Driver_Codec_idlomx_1400
207 * @tc.name   : HdfCodecHdiGetParameterTest005
208 * @tc.desc   : Verify the GetParameter function when the input parameter is invalid.
209   @tc.type: FUNC
210 */
211 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiGetParameterTest005, TestSize.Level1)
212 {
213     ASSERT_TRUE(g_component != nullptr);
214     OMX_VIDEO_PARAM_PORTFORMATTYPE param;
215     int32_t ret = memset_s(&param, sizeof(param), 0, sizeof(param));
216     ASSERT_EQ(ret, EOK);
217     param.nPortIndex = inputIndex;
218     param.eCompressionFormat = OMX_VIDEO_CodingAVC;
219     std::vector<int8_t> inParam;
220     func_->ObjectToVector(param, inParam);
221 
222     std::vector<int8_t> outParam;
223     ret = g_component->GetParameter(OMX_IndexCodecVideoPortFormat, inParam, outParam);
224     ASSERT_NE(ret, HDF_SUCCESS);
225 }
226 
227 /**
228 * @tc.number : SUB_Driver_Codec_idlomx_1500
229 * @tc.name   : HdfCodecHdiGetParameterTest006
230 * @tc.desc   : Verify the GetParameter function when the input parameter is invalid.
231   @tc.type: FUNC
232 */
233 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiGetParameterTest006, TestSize.Level1)
234 {
235     ASSERT_TRUE(g_component != nullptr);
236     OMX_VIDEO_CONFIG_BITRATETYPE param;
237     func_->InitParam(param);
238     param.nPortIndex = inputIndex;
239     std::vector<int8_t> inParam;
240     func_->ObjectToVector(param, inParam);
241 
242     std::vector<int8_t> outParam;
243     auto ret = g_component->GetParameter(OMX_IndexCodecVideoPortFormat, inParam, outParam);
244     ASSERT_NE(ret, HDF_SUCCESS);
245 }
246 
247 /**
248 * @tc.number : SUB_Driver_Codec_idlomx_1600
249 * @tc.name   : HdfCodecHdiGetParameterTest007
250 * @tc.desc   : Verify the GetParameter function when the input parameter is invalid.
251   @tc.type: FUNC
252 */
253 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiGetParameterTest007, TestSize.Level1)
254 {
255     ASSERT_TRUE(g_component != nullptr);
256     OMX_VIDEO_CONFIG_BITRATETYPE param;
257     func_->InitParam(param);
258     param.nPortIndex = inputIndex;
259     std::vector<int8_t> inParam;
260     func_->ObjectToVector(param, inParam);
261 
262     std::vector<int8_t> outParam;
263     auto ret = g_component->GetParameter(OMX_IndexVideoStartUnused, inParam, outParam);
264     ASSERT_NE(ret, HDF_SUCCESS);
265 }
266 
267 /**
268 * @tc.number : SUB_Driver_Codec_idlomx_1700
269 * @tc.name   : HdfCodecHdiSetParameterTest001
270 * @tc.desc   : Verify the SetParameter function when the input parameter is valid.
271   @tc.type: FUNC
272 */
273 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiSetParameterTest001, TestSize.Level1)
274 {
275     ASSERT_TRUE(g_component != nullptr);
276     OMX_VIDEO_PARAM_PORTFORMATTYPE param;
277     func_->InitParam(param);
278     param.nPortIndex = inputIndex;
279     std::vector<int8_t> paramVec;
280     func_->ObjectToVector(param, paramVec);
281     auto ret = g_component->SetParameter(OMX_IndexParamVideoPortFormat, paramVec);
282     ASSERT_EQ(ret, HDF_SUCCESS);
283 }
284 
285 /**
286 * @tc.number : SUB_Driver_Codec_idlomx_1800
287 * @tc.name   : HdfCodecHdiSetParameterTest002
288 * @tc.desc   : Verify the SetParameter function when the input parameter is isvalid.
289   @tc.type: FUNC
290 */
291 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiSetParameterTest002, TestSize.Level1)
292 {
293     ASSERT_TRUE(g_component != nullptr);
294     OMX_VIDEO_PARAM_PORTFORMATTYPE param;
295     int32_t ret = memset_s(&param, sizeof(param), 0, sizeof(param));
296     ASSERT_EQ(ret, EOK);
297     param.nPortIndex = inputIndex;
298     std::vector<int8_t> paramVec;
299     func_->ObjectToVector(param, paramVec);
300     ret = g_component->SetParameter(OMX_IndexParamVideoPortFormat, paramVec);
301     ASSERT_NE(ret, HDF_SUCCESS);
302 }
303 
304 /**
305 * @tc.number : SUB_Driver_Codec_idlomx_1900
306 * @tc.name   : HdfCodecHdiSetParameterTest003
307 * @tc.desc   : Verify the SetParameter function when the input parameter is isvalid.
308   @tc.type: FUNC
309 */
310 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiSetParameterTest003, TestSize.Level1)
311 {
312     ASSERT_TRUE(g_component != nullptr);
313     std::vector<int8_t> paramVec;
314     auto ret = g_component->SetParameter(OMX_IndexParamVideoPortFormat, paramVec);
315     ASSERT_NE(ret, HDF_SUCCESS);
316 }
317 
318 /**
319 * @tc.number : SUB_Driver_Codec_idlomx_2000
320 * @tc.name   : HdfCodecHdiSetParameterTest004
321 * @tc.desc   : Verify the SetParameter function when the input parameter param.nPortIndex = inputIndex.
322   @tc.type: FUNC
323 */
324 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiSetParameterTest004, TestSize.Level1)
325 {
326     ASSERT_TRUE(g_component != nullptr);
327     OMX_VIDEO_CONFIG_BITRATETYPE param;
328     func_->InitParam(param);
329     param.nPortIndex = inputIndex;
330     std::vector<int8_t> paramVec;
331     func_->ObjectToVector(param, paramVec);
332     auto ret = g_component->SetParameter(OMX_IndexParamVideoPortFormat, paramVec);
333     ASSERT_NE(ret, HDF_SUCCESS);
334 }
335 
336 /**
337 * @tc.number : SUB_Driver_Codec_idlomx_2100
338 * @tc.name   : HdfCodecHdiSetParameterTest005
339 * @tc.desc   : Verify the SetParameter function when the input parameter OMX_IndexVideoStartUnused.
340   @tc.type: FUNC
341 */
342 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiSetParameterTest005, TestSize.Level1)
343 {
344     ASSERT_TRUE(g_component != nullptr);
345     OMX_VIDEO_PARAM_PORTFORMATTYPE param;
346     func_->InitParam(param);
347     param.nPortIndex = inputIndex;
348     std::vector<int8_t> paramVec;
349     func_->ObjectToVector(param, paramVec);
350     auto ret = g_component->SetParameter(OMX_IndexVideoStartUnused, paramVec);
351     ASSERT_NE(ret, HDF_SUCCESS);
352 }
353 
354 /**
355 * @tc.number : SUB_Driver_Codec_idlomx_2200
356 * @tc.name   : HdfCodecHdiSetParameterTest006
357 * @tc.desc   : Verify the SetParameter function when the input parameter is valid.
358   @tc.type: FUNC
359 */
360 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiSetParameterTest006, TestSize.Level1)
361 {
362     ASSERT_TRUE(g_component != nullptr);
363     CodecVideoPortFormatParam pixFormat;
364     func_->InitExtParam(pixFormat);
365     pixFormat.portIndex = inputIndex;
366     pixFormat.codecColorIndex = 0;
367     std::vector<int8_t> inParam;
368     func_->ObjectToVector(pixFormat, inParam);
369 
370     std::vector<int8_t> outParam;
371     auto ret = g_component->GetParameter(OMX_IndexCodecVideoPortFormat, inParam, outParam);
372     ASSERT_EQ(ret, HDF_SUCCESS);
373 
374     pixFormat.codecColorFormat = PIXEL_FMT_YCBCR_420_SP;
375     std::vector<int8_t> paramVec;
376     func_->ObjectToVector(pixFormat, paramVec);
377     ret = g_component->SetParameter(OMX_IndexCodecVideoPortFormat, paramVec);
378     ASSERT_EQ(ret, HDF_SUCCESS);
379 }
380 
381 #ifdef SUPPORT_DMA_BUFFER
382 /**
383 * @tc.number : SUB_Driver_Codec_idlomx_2300
384 * @tc.name   : HdfCodecHdiDMABufferTest001
385 * @tc.desc   : Verify the codec support DMA buffer process.
386   @tc.type: FUNC
387 */
388 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiDMABufferTest001, TestSize.Level1)
389 {
390     ASSERT_TRUE(g_component != nullptr);
391     SupportBufferType bufferType;
392     func_->InitExtParam(bufferType);
393     bufferType.portIndex = outputIndex;
394     std::vector<int8_t> inParam, outParam;
395     func_->ObjectToVector(bufferType, inParam);
396     auto ret = g_component->GetParameter(OMX_IndexParamSupportBufferType, inParam, outParam);
397     ASSERT_EQ(ret, HDF_SUCCESS);
398     func_->VectorToObject(outParam, bufferType);
399     ASSERT_TRUE(bufferType.bufferTypes & CODEC_BUFFER_TYPE_DMA_MEM_FD) ;
400 }
401 #endif
402 
403 #ifdef SUPPORT_OMX_EXTEND
404 /**
405 * @tc.number : SUB_Driver_Codec_idlomx_2400
406 * @tc.name   : HdfCodecHdiUseBufferAndFreeBufferTest001
407 * @tc.desc   : Verify Use buffer on input index error when OMX_ErrorInsufficientResources.
408   @tc.type: FUNC
409 */
410 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiUseBufferAndFreeBufferTest001, TestSize.Level1)
411 {
412     ASSERT_TRUE(g_component != nullptr);
413     std::vector<int8_t> cmdData;
414     auto ret = g_component->SendCommand(CODEC_COMMAND_STATE_SET, CODEC_STATE_IDLE, cmdData);
415     ASSERT_EQ(ret, HDF_SUCCESS);
416 
417     OMX_PARAM_PORTDEFINITIONTYPE param;
418     func_->GetPortParameter(g_component, PortIndex::INDEX_INPUT, param);
419 
420     auto err = func_->UseBufferOnPort(g_component, PortIndex::INDEX_INPUT, param.nBufferCountActual,
421         param.nBufferSize);
422     ASSERT_TRUE(err);
423     err = func_->UseBufferOnPort(g_component, PortIndex::INDEX_INPUT, 1, param.nBufferSize);
424     ASSERT_FALSE(err);
425     err = func_->FreeBufferOnPort(g_component, PortIndex::INDEX_INPUT);
426     ASSERT_TRUE(err);
427 }
428 
429 /**
430 * @tc.number : SUB_Driver_Codec_idlomx_2500
431 * @tc.name   : HdfCodecHdiUseBufferAndFreeBufferTest002
432 * @tc.desc   : Verify Use buffer on output index error when OMX_ErrorInsufficientResources.
433   @tc.type: FUNC
434 */
435 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiUseBufferAndFreeBufferTest002, TestSize.Level1)
436 {
437     ASSERT_TRUE(g_component != nullptr);
438     std::vector<int8_t> cmdData;
439     auto ret = g_component->SendCommand(CODEC_COMMAND_STATE_SET, CODEC_STATE_IDLE, cmdData);
440     ASSERT_EQ(ret, HDF_SUCCESS);
441 
442     OMX_PARAM_PORTDEFINITIONTYPE param;
443     func_->GetPortParameter(g_component, PortIndex::INDEX_OUTPUT, param);
444 
445     auto err = func_->UseBufferOnPort(g_component, PortIndex::INDEX_OUTPUT, param.nBufferCountActual,
446         param.nBufferSize);
447     ASSERT_TRUE(err);
448     err = func_->UseBufferOnPort(g_component, PortIndex::INDEX_OUTPUT, 1, param.nBufferSize);
449     ASSERT_FALSE(err);
450     err = func_->FreeBufferOnPort(g_component, PortIndex::INDEX_OUTPUT);
451     ASSERT_TRUE(err);
452 }
453 #endif
454 
455 /**
456 * @tc.number : SUB_Driver_Codec_idlomx_2600
457 * @tc.name   : HdfCodecHdiEmptyAndFillBufferTest001
458 * @tc.desc   : Verify the encode EmptyAndFillBuffer process.
459   @tc.type: FUNC
460 */
461 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiEmptyAndFillBufferTest001, TestSize.Level1)
462 {
463     ASSERT_TRUE(g_component != nullptr);
464     std::vector<int8_t> cmdData;
465     auto ret = g_component->SendCommand(CODEC_COMMAND_STATE_SET, CODEC_STATE_IDLE, cmdData);
466     ASSERT_EQ(ret, HDF_SUCCESS);
467 
468     OMX_PARAM_PORTDEFINITIONTYPE param;
469     auto err = func_->InitBufferHandleParameter(g_component, param, inputIndex, CODEC_BUFFER_TYPE_DYNAMIC_HANDLE);
470     ASSERT_TRUE(err);
471     ret = func_->GetPortParameter(g_component, PortIndex::INDEX_INPUT, param);
472     ASSERT_EQ(ret, HDF_SUCCESS);
473     err = func_->UseDynaBuffer(g_component, PortIndex::INDEX_INPUT, param.nBufferCountActual, param.nBufferSize);
474     ASSERT_TRUE(err);
475 
476     ret = func_->GetPortParameter(g_component, PortIndex::INDEX_OUTPUT, param);
477     ASSERT_EQ(ret, HDF_SUCCESS);
478     err = func_->UseBufferOnPort(g_component, PortIndex::INDEX_OUTPUT, param.nBufferCountActual, param.nBufferSize);
479     ASSERT_TRUE(err);
480 
481     ret = g_component->SendCommand(CODEC_COMMAND_STATE_SET, CODEC_STATE_EXECUTING, cmdData);
482     ASSERT_EQ(ret, HDF_SUCCESS);
483     err = func_->WaitState(g_component, CODEC_STATE_EXECUTING);
484     ASSERT_TRUE(err);
485     err = func_->FillAndEmptyAllBuffer(g_component, CODEC_BUFFER_TYPE_DYNAMIC_HANDLE);
486     ASSERT_TRUE(err);
487 
488     ret = g_component->SendCommand(CODEC_COMMAND_STATE_SET, CODEC_STATE_IDLE, cmdData);
489     ASSERT_EQ(ret, HDF_SUCCESS);
490     err = func_->WaitState(g_component, CODEC_STATE_IDLE);
491     ASSERT_TRUE(err);
492     ret = g_component->SendCommand(CODEC_COMMAND_STATE_SET, CODEC_STATE_LOADED, cmdData);
493     ASSERT_EQ(ret, HDF_SUCCESS);
494     err = func_->WaitState(g_component, CODEC_STATE_IDLE);
495     ASSERT_TRUE(err);
496 
497     err = func_->FreeBufferOnPort(g_component, PortIndex::INDEX_INPUT);
498     ASSERT_TRUE(err);
499     err = func_->FreeBufferOnPort(g_component, PortIndex::INDEX_OUTPUT);
500     ASSERT_TRUE(err);
501     err = func_->WaitState(g_component, CODEC_STATE_LOADED);
502     ASSERT_TRUE(err);
503 }
504 
505 /**
506 * @tc.number : SUB_Driver_Codec_idlomx_2700
507 * @tc.name   : HdfCodecHdiFreeBufferTest001
508 * @tc.desc   : Verify the encode Release output buffer.
509   @tc.type: FUNC
510 */
511 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiFreeBufferTest001, TestSize.Level1)
512 {
513     ASSERT_TRUE(g_component != nullptr);
514     struct OmxCodecBuffer omxBuffer;
515     func_->InitOmxCodecBuffer(omxBuffer, CODEC_BUFFER_TYPE_AVSHARE_MEM_FD);
516     omxBuffer.bufferId = BUFFER_ID_ERROR;
517     auto ret = g_component->FreeBuffer(outputIndex, omxBuffer);
518     ASSERT_NE(ret, HDF_SUCCESS);
519 }
520 
521 /**
522 * @tc.number : SUB_Driver_Codec_idlomx_2800
523 * @tc.name   : HdfCodecHdiFreeBufferTest002
524 * @tc.desc   : Verify the encode Release input buffer.
525   @tc.type: FUNC
526 */
527 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiFreeBufferTest002, TestSize.Level1)
528 {
529     ASSERT_TRUE(g_component != nullptr);
530     struct OmxCodecBuffer omxBuffer;
531     func_->InitOmxCodecBuffer(omxBuffer, CODEC_BUFFER_TYPE_AVSHARE_MEM_FD);
532     omxBuffer.bufferId = BUFFER_ID_ERROR;
533     auto ret = g_component->FreeBuffer(inputIndex, omxBuffer);
534     ASSERT_NE(ret, HDF_SUCCESS);
535 }
536 
537 #ifdef SUPPORT_OMX_EXTEND
538 /**
539 * @tc.number : SUB_Driver_Codec_idlomx_2900
540 * @tc.name   : HdfCodecHdiDeInitTest001
541 * @tc.desc   : Verify When ComponentDeInit, must change to Loaded State.
542   @tc.type: FUNC
543 */
544 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiDeInitTest001, TestSize.Level1)
545 {
546     ASSERT_TRUE(g_component != nullptr);
547     auto ret = g_component->ComponentDeInit();
548     ASSERT_EQ(ret, HDF_SUCCESS);
549 }
550 #endif
551 
552 #ifdef SUPPORT_HIGH_WORK_FREQUENCY
553 /**
554 * @tc.number : SUB_Driver_Codec_idlomx_3000
555 * @tc.name   : HdfCodecHdiHighWorkingFrequencyTest001
556 * @tc.desc   : Verify the encode support HIGH_WORK_FREQUENCY process.
557   @tc.type: FUNC
558 */
559 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiHighWorkingFrequencyTest001, TestSize.Level1)
560 {
561     const std::string processName = "cast_engine_service";
562     std::vector<int8_t> paramVec;
563 
564     ASSERT_TRUE(g_component != nullptr);
565 
566     ProcessNameParam nameParam;
567     func_->InitExtParam(nameParam);
568     int32_t ret = strcpy_s(nameParam.processName, sizeof(nameParam.processName), processName.c_str());
569     ASSERT_TRUE(ret == EOK);
570     func_->ObjectToVector(nameParam, paramVec);
571     ret = g_component->SetParameter(OMX_IndexParamProcessName, paramVec);
572     ASSERT_TRUE(ret == HDF_SUCCESS);
573 
574     WorkingFrequencyParam freqParam;
575     std::vector<int8_t> inParam;
576     std::vector<int8_t> outParam;
577 
578     func_->InitExtParam(freqParam);
579     func_->ObjectToVector(freqParam, inParam);
580     ret = g_component->GetParameter(OMX_IndexParamWorkingFrequency, inParam, outParam);
581     ASSERT_TRUE(ret == HDF_SUCCESS);
582     func_->VectorToObject(outParam, freqParam);
583 
584     // 设置为最高档
585     freqParam.level = freqParam.level - 1;
586     func_->ObjectToVector(freqParam, inParam);
587     ret = g_component->SetParameter(OMX_IndexParamWorkingFrequency, inParam);
588     ASSERT_TRUE(ret == HDF_SUCCESS);
589 }
590 #endif
591 
592 /**
593 * @tc.number : SUB_Driver_Codec_idlomx_3100
594 * @tc.name   : HdfCodecHdiGetConfigTest001
595 * @tc.desc   : Verify Set parameters is outputindex  under the structure of OMX_VIDEO_CONFIG_BITRATETYPE.
596   @tc.type: FUNC
597 */
598 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiGetConfigTest001, TestSize.Level1)
599 {
600     ASSERT_TRUE(g_component != nullptr);
601     OMX_VIDEO_CONFIG_BITRATETYPE param;
602     func_->InitParam(param);
603     param.nPortIndex = outputIndex;
604 
605     std::vector<int8_t> inParam;
606     func_->ObjectToVector(param, inParam);
607     std::vector<int8_t> outParam;
608     auto ret = g_component->GetConfig(OMX_IndexConfigVideoBitrate, inParam, outParam);
609     ASSERT_EQ(ret, HDF_SUCCESS);
610 }
611 
612 /**
613 * @tc.number : SUB_Driver_Codec_idlomx_3200
614 * @tc.name   : HdfCodecHdiGetConfigTest002
615 * @tc.desc   : Verify Set parameters is inputIndex under the structure of OMX_VIDEO_CONFIG_BITRATETYPE.
616   @tc.type: FUNC
617 */
618 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiGetConfigTest002, TestSize.Level1)
619 {
620     ASSERT_TRUE(g_component != nullptr);
621     OMX_VIDEO_CONFIG_BITRATETYPE param;
622     func_->InitParam(param);
623     param.nPortIndex = inputIndex;
624 
625     std::vector<int8_t> inParam;
626     func_->ObjectToVector(param, inParam);
627     std::vector<int8_t> outParam;
628     auto ret = g_component->GetConfig(OMX_IndexConfigVideoBitrate, inParam, outParam);
629     ASSERT_NE(ret, HDF_SUCCESS);
630 }
631 
632 /**
633 * @tc.number : SUB_Driver_Codec_idlomx_3300
634 * @tc.name   : HdfCodecHdiGetConfigTest003
635 * @tc.desc   : Verify param not initialized and not set structure.
636   @tc.type: FUNC
637 */
638 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiGetConfigTest003, TestSize.Level1)
639 {
640     ASSERT_TRUE(g_component != nullptr);
641     std::vector<int8_t> inParam;
642     std::vector<int8_t> outParam;
643     auto ret = g_component->GetConfig(OMX_IndexConfigVideoBitrate, inParam, outParam);
644     ASSERT_NE(ret, HDF_SUCCESS);
645 }
646 
647 /**
648 * @tc.number : SUB_Driver_Codec_idlomx_3400
649 * @tc.name   : HdfCodecHdiGetConfigTest004
650 * @tc.desc   : Verify that the structure does not match the index.
651   @tc.type: FUNC
652 */
653 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiGetConfigTest004, TestSize.Level1)
654 {
655     ASSERT_TRUE(g_component != nullptr);
656     OMX_VIDEO_CONFIG_BITRATETYPE param;
657     func_->InitParam(param);
658     param.nPortIndex = outputIndex;
659 
660     std::vector<int8_t> inParam;
661     func_->ObjectToVector(param, inParam);
662     std::vector<int8_t> outParam;
663     auto ret = g_component->GetConfig(OMX_IndexVideoStartUnused, inParam, outParam);
664     ASSERT_NE(ret, HDF_SUCCESS);
665 }
666 
667 /**
668 * @tc.number : SUB_Driver_Codec_idlomx_3500
669 * @tc.name   : HdfCodecHdiSetConfigTest001
670 * @tc.desc   : Verify param is nPortIndex is outputIndex and nEncodeBitrate is FRAMERATE.
671   @tc.type: FUNC
672 */
673 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiSetConfigTest001, TestSize.Level1)
674 {
675     ASSERT_TRUE(g_component != nullptr);
676     OMX_VIDEO_CONFIG_BITRATETYPE param;
677     func_->InitParam(param);
678     param.nPortIndex = outputIndex;
679     param.nEncodeBitrate = FRAMERATE;
680 
681     std::vector<int8_t> inParam;
682     func_->ObjectToVector(param, inParam);
683     auto ret = g_component->SetConfig(OMX_IndexConfigVideoBitrate, inParam);
684     ASSERT_EQ(ret, HDF_SUCCESS);
685 }
686 
687 /**
688 * @tc.number : SUB_Driver_Codec_idlomx_3600
689 * @tc.name   : HdfCodecHdiSetConfigTest002
690 * @tc.desc   : Verify param is nPortIndex is inputIndex and nEncodeBitrate is FRAMERATE.
691   @tc.type: FUNC
692 */
693 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiSetConfigTest002, TestSize.Level1)
694 {
695     ASSERT_TRUE(g_component != nullptr);
696     OMX_VIDEO_CONFIG_BITRATETYPE param;
697     func_->InitParam(param);
698     param.nPortIndex = inputIndex;
699     param.nEncodeBitrate = FRAMERATE;
700 
701     std::vector<int8_t> inParam;
702     func_->ObjectToVector(param, inParam);
703     auto ret = g_component->SetConfig(OMX_IndexConfigVideoBitrate, inParam);
704     ASSERT_NE(ret, HDF_SUCCESS);
705 }
706 
707 /**
708 * @tc.number : SUB_Driver_Codec_idlomx_3700
709 * @tc.name   : HdfCodecHdiSetConfigTest003
710 * @tc.desc   : Verify param not initialized and not set structure.
711   @tc.type: FUNC
712 */
713 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiSetConfigTest003, TestSize.Level1)
714 {
715     ASSERT_TRUE(g_component != nullptr);
716     std::vector<int8_t> inParam;
717     auto ret = g_component->SetConfig(OMX_IndexConfigVideoBitrate, inParam);
718     ASSERT_NE(ret, HDF_SUCCESS);
719 }
720 
721 /**
722 * @tc.number : SUB_Driver_Codec_idlomx_3800
723 * @tc.name   : HdfCodecHdiSetConfigTest004
724 * @tc.desc   : Verify that the structure does not match the index.
725   @tc.type: FUNC
726 */
727 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiSetConfigTest004, TestSize.Level1)
728 {
729     ASSERT_TRUE(g_component != nullptr);
730     OMX_VIDEO_CONFIG_BITRATETYPE param;
731     func_->InitParam(param);
732     param.nPortIndex = outputIndex;
733 
734     std::vector<int8_t> inParam;
735     func_->ObjectToVector(param, inParam);
736     auto ret = g_component->SetConfig(OMX_IndexVideoStartUnused, inParam);
737     ASSERT_NE(ret, HDF_SUCCESS);
738 }
739 
740 /**
741 * @tc.number : SUB_Driver_Codec_idlomx_3900
742 * @tc.name   : HdfCodecHdiUseEglImageTest001
743 * @tc.desc   : Verify the function is UseEglImage whether or not supported.
744   @tc.type: FUNC
745 */
746 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiUseEglImageTest001, TestSize.Level1)
747 {
748     ASSERT_TRUE(g_component != nullptr);
749     struct OmxCodecBuffer omxBuffer;
750     func_->InitOmxCodecBuffer(omxBuffer, CODEC_BUFFER_TYPE_AVSHARE_MEM_FD);
751     auto eglImage = std::make_unique<int8_t[]>(BUFFER_SIZE);
752     ASSERT_TRUE(eglImage != nullptr);
753     std::vector<int8_t> eglImageVec;
754     eglImageVec.assign(eglImage.get(), eglImage.get() + BUFFER_SIZE);
755     struct OmxCodecBuffer outbuffer;
756     int32_t ret = g_component->UseEglImage(inputIndex, omxBuffer, outbuffer, eglImageVec);
757     ASSERT_NE(ret, HDF_SUCCESS);
758     eglImage = nullptr;
759 }
760 
761 /**
762 * @tc.number : SUB_Driver_Codec_idlomx_4000
763 * @tc.name   : HdfCodecHdiFillThisBufferTest001
764 * @tc.desc   : Verify the function is FillThisBuffer when bufferId is BUFFER_ID_ERROR.
765   @tc.type: FUNC
766 */
767 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiFillThisBufferTest001, TestSize.Level1)
768 {
769     ASSERT_TRUE(g_component != nullptr);
770     struct OmxCodecBuffer omxBuffer;
771     func_->InitOmxCodecBuffer(omxBuffer, CODEC_BUFFER_TYPE_AVSHARE_MEM_FD);
772     omxBuffer.bufferId = BUFFER_ID_ERROR;
773     auto ret = g_component->FillThisBuffer(omxBuffer);
774     ASSERT_NE(ret, HDF_SUCCESS);
775 }
776 
777 /**
778 * @tc.number : SUB_Driver_Codec_idlomx_4100
779 * @tc.name   : HdfCodecHdiEmptyThisBufferTest001
780 * @tc.desc   : Verify the function is EmptyThisBuffer when bufferId is BUFFER_ID_ERROR.
781   @tc.type: FUNC
782 */
783 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiEmptyThisBufferTest001, TestSize.Level1)
784 {
785     ASSERT_TRUE(g_component != nullptr);
786     struct OmxCodecBuffer omxBuffer;
787     func_->InitOmxCodecBuffer(omxBuffer, CODEC_BUFFER_TYPE_AVSHARE_MEM_FD);
788     omxBuffer.bufferId = BUFFER_ID_ERROR;
789     auto ret = g_component->EmptyThisBuffer(omxBuffer);
790     ASSERT_NE(ret, HDF_SUCCESS);
791 }
792 
793 /**
794 * @tc.number : SUB_Driver_Codec_idlomx_4200
795 * @tc.name   : HdfCodecHdiSetCallbackTest001
796 * @tc.desc   : Verify the function is SetCallbacks when params is valid.
797   @tc.type: FUNC
798 */
799 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiSetCallbackTest001, TestSize.Level1)
800 {
801     ASSERT_TRUE(g_component != nullptr);
802     g_callback = new CodecCallbackService();
803     ASSERT_TRUE(g_callback != nullptr);
804     auto ret = g_component->SetCallbacks(g_callback, APP_DATA);
805     ASSERT_EQ(ret, HDF_SUCCESS);
806 }
807 
808 /**
809 * @tc.number : SUB_Driver_Codec_idlomx_4300
810 * @tc.name   : HdfCodecHdiSetCallbackTest002
811 * @tc.desc   : Verify the function is SetCallbacks when params is invalid.
812   @tc.type: FUNC
813 */
814 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiSetCallbackTest002, TestSize.Level1)
815 {
816     ASSERT_TRUE(g_component != nullptr);
817     auto ret = g_component->SetCallbacks(nullptr, APP_DATA);
818     ASSERT_NE(ret, HDF_SUCCESS);
819 }
820 
821 /**
822 * @tc.number : SUB_Driver_Codec_idlomx_4400
823 * @tc.name   : HdfCodecHdiUseBufferTest001
824 * @tc.desc   : Verify the function is UseBuffer when portindex is inputIndex.
825   @tc.type: FUNC
826 */
827 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiUseBufferTest001, TestSize.Level1)
828 {
829     ASSERT_TRUE(g_component != nullptr);
830     struct OmxCodecBuffer omxBuffer;
831     func_->InitOmxCodecBuffer(omxBuffer, CODEC_BUFFER_TYPE_INVALID);
832     struct OmxCodecBuffer outBuffer;
833     auto ret = g_component->UseBuffer(inputIndex, omxBuffer, outBuffer);
834     ASSERT_NE(ret, HDF_SUCCESS);
835 }
836 
837 /**
838 * @tc.number : SUB_Driver_Codec_idlomx_4500
839 * @tc.name   : HdfCodecHdiUseBufferTest002
840 * @tc.desc   : Verify the function is UseBuffer when portindex is outputIndex.
841   @tc.type: FUNC
842 */
843 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiUseBufferTest002, TestSize.Level1)
844 {
845     ASSERT_TRUE(g_component != nullptr);
846     struct OmxCodecBuffer omxBuffer;
847     func_->InitOmxCodecBuffer(omxBuffer, CODEC_BUFFER_TYPE_INVALID);
848     struct OmxCodecBuffer outBuffer;
849     auto ret = g_component->UseBuffer(outputIndex, omxBuffer, outBuffer);
850     ASSERT_NE(ret, HDF_SUCCESS);
851 }
852 
853 /**
854 * @tc.number : SUB_Driver_Codec_idlomx_4600
855 * @tc.name   : HdfCodecHdiUseBufferTest003
856 * @tc.desc   : Verify the function is UseBuffer when portindex is inputIndex
857                and omxBuffer is CODEC_BUFFER_TYPE_VIRTUAL_ADDR.
858   @tc.type: FUNC
859 */
860 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiUseBufferTest003, TestSize.Level1)
861 {
862     ASSERT_TRUE(g_component != nullptr);
863     struct OmxCodecBuffer omxBuffer;
864     func_->InitOmxCodecBuffer(omxBuffer, CODEC_BUFFER_TYPE_VIRTUAL_ADDR);
865     struct OmxCodecBuffer outBuffer;
866     auto ret = g_component->UseBuffer(inputIndex, omxBuffer, outBuffer);
867     ASSERT_NE(ret, HDF_SUCCESS);
868 }
869 
870 /**
871 * @tc.number : SUB_Driver_Codec_idlomx_4700
872 * @tc.name   : HdfCodecHdiUseBufferTest003
873 * @tc.desc   : Verify the function is UseBuffer when portindex is outputIndex
874                and omxBuffer is CODEC_BUFFER_TYPE_VIRTUAL_ADDR.
875   @tc.type: FUNC
876 */
877 HWTEST_F(CodecHdiOmxEncTest, HdfCodecHdiUseBufferTest004, TestSize.Level1)
878 {
879     ASSERT_TRUE(g_component != nullptr);
880     struct OmxCodecBuffer omxBuffer;
881     func_->InitOmxCodecBuffer(omxBuffer, CODEC_BUFFER_TYPE_VIRTUAL_ADDR);
882     struct OmxCodecBuffer outBuffer;
883     auto ret = g_component->UseBuffer(outputIndex, omxBuffer, outBuffer);
884     ASSERT_NE(ret, HDF_SUCCESS);
885 }
886 }  // namespace
887