1 /*
2 * Copyright (C) 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 #include <iostream>
16 #include <cstdio>
17 #include <string>
18
19 #include "gtest/gtest.h"
20 #include "native_avcodec_base.h"
21 #include "native_avformat.h"
22 #include "native_avcodec_videoencoder.h"
23 #include "videoenc_sample.h"
24 #include "native_avcapability.h"
25 #include "videoenc_api11_sample.h"
26 using namespace std;
27 using namespace OHOS;
28 using namespace OHOS::Media;
29 using namespace testing::ext;
30 namespace {
31 OH_AVCodec *venc_ = NULL;
32 constexpr uint32_t DEFAULT_WIDTH = 1920;
33 constexpr uint32_t DEFAULT_HEIGHT = 1080;
34 constexpr uint32_t CODEC_NAME_SIZE = 128;
35 char g_codecName[CODEC_NAME_SIZE] = {};
36 OH_AVCapability *cap = nullptr;
37 OHOS::Media::VEncSignal *signal_ = nullptr;
38 OH_AVFormat *format;
onError(OH_AVCodec * codec,int32_t errorCode,void * userData)39 void onError(OH_AVCodec *codec, int32_t errorCode, void *userData)
40 {
41 cout << "Error errorCode=" << errorCode << endl;
42 };
43
onStreamChanged(OH_AVCodec * codec,OH_AVFormat * fmt,void * userData)44 void onStreamChanged(OH_AVCodec *codec, OH_AVFormat *fmt, void *userData)
45 {
46 cout << "stream Changed" << endl;
47 };
48
onNeedInputData(OH_AVCodec * codec,uint32_t index,OH_AVMemory * data,void * userData)49 void onNeedInputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, void *userData)
50 {
51 VEncSignal *signal = static_cast<VEncSignal *>(userData);
52 if (signal == nullptr) {
53 return;
54 }
55 unique_lock<mutex> lock(signal->inMutex_);
56 signal->inIdxQueue_.push(index);
57 signal->inBufferQueue_.push(data);
58 signal->inCond_.notify_all();
59 cout << "need input data" << endl;
60 };
61
onNewOutputData(OH_AVCodec * codec,uint32_t index,OH_AVMemory * data,OH_AVCodecBufferAttr * attr,void * userData)62 void onNewOutputData(OH_AVCodec *codec, uint32_t index, OH_AVMemory *data, OH_AVCodecBufferAttr *attr, void *userData)
63 {
64 cout << "output data" << endl;
65 VEncSignal *signal = static_cast<VEncSignal *>(userData);
66 if (signal == nullptr) {
67 return;
68 }
69 unique_lock<mutex> lock(signal->outMutex_);
70 signal->outIdxQueue_.push(index);
71 signal->attrQueue_.push(*attr);
72 signal->outBufferQueue_.push(data);
73 signal->outCond_.notify_all();
74 };
75 } // namespace
76
77 namespace OHOS {
78 namespace Media {
79 class HwEncApiNdkTest : public testing::Test {
80 public:
81 // SetUpTestCase: Called before all test cases
82 static void SetUpTestCase(void);
83 // TearDownTestCase: Called after all test case
84 static void TearDownTestCase(void);
85 // SetUp: Called before each test cases
86 void SetUp(void);
87 // TearDown: Called after each test cases
88 void TearDown(void);
89 };
90
SetUpTestCase()91 void HwEncApiNdkTest::SetUpTestCase()
92 {
93 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
94 const char *TMP_CODEC_NAME = OH_AVCapability_GetName(cap);
95 if (memcpy_s(g_codecName, sizeof(g_codecName), TMP_CODEC_NAME, strlen(TMP_CODEC_NAME)) != 0) {
96 cout << "memcpy failed" << endl;
97 }
98 cout << "codecname: " << g_codecName << endl;
99 }
TearDownTestCase()100 void HwEncApiNdkTest::TearDownTestCase() {}
SetUp()101 void HwEncApiNdkTest::SetUp()
102 {
103 signal_ = new VEncSignal();
104 }
TearDown()105 void HwEncApiNdkTest::TearDown()
106 {
107 if (format != nullptr) {
108 OH_AVFormat_Destroy(format);
109 format = nullptr;
110 }
111 if (venc_ != NULL) {
112 OH_VideoEncoder_Destroy(venc_);
113 venc_ = nullptr;
114 }
115 if (signal_) {
116 delete signal_;
117 signal_ = nullptr;
118 }
119 }
120 } // namespace Media
121 } // namespace OHOS
122
123 namespace {
124 /**
125 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_0100
126 * @tc.name : OH_VideoEncoder_CreateByMime para1 error
127 * @tc.desc : api test
128 */
129 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_0100, TestSize.Level2)
130 {
131 venc_ = OH_VideoEncoder_CreateByMime(nullptr);
132 ASSERT_EQ(nullptr, venc_);
133 }
134
135 /**
136 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_0200
137 * @tc.name : OH_VideoEncoder_CreateByMime para2 error
138 * @tc.desc : api test
139 */
140 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_0200, TestSize.Level2)
141 {
142 venc_ = OH_VideoEncoder_CreateByMime("");
143 ASSERT_EQ(nullptr, venc_);
144 }
145
146 /**
147 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_0300
148 * @tc.name : OH_VideoEncoder_CreateByMime para error
149 * @tc.desc : api test
150 */
151 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_0300, TestSize.Level2)
152 {
153 venc_ = OH_VideoEncoder_CreateByName(nullptr);
154 ASSERT_EQ(nullptr, venc_);
155 }
156
157 /**
158 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_0400
159 * @tc.name : OH_VideoEncoder_CreateByMime para error
160 * @tc.desc : api test
161 */
162 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_0400, TestSize.Level2)
163 {
164 venc_ = OH_VideoEncoder_CreateByName("");
165 ASSERT_EQ(nullptr, venc_);
166 }
167
168 /**
169 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_0500
170 * @tc.name : OH_VideoEncoder_CreateByMime para error
171 * @tc.desc : api test
172 */
173 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_0500, TestSize.Level2)
174 {
175 OH_AVErrCode ret = AV_ERR_OK;
176 ret = OH_VideoEncoder_Destroy(nullptr);
177 ASSERT_EQ(ret, AV_ERR_INVALID_VAL);
178 }
179
180 /**
181 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_0600
182 * @tc.name : OH_VideoEncoder_SetCallback para error
183 * @tc.desc : api test
184 */
185 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_0600, TestSize.Level2)
186 {
187 OH_AVCodecAsyncCallback cb_;
188 cb_.onError = onError;
189 cb_.onStreamChanged = onStreamChanged;
190 cb_.onNeedInputData = onNeedInputData;
191 cb_.onNeedOutputData = onNewOutputData;
192
193 ASSERT_EQ(AV_ERR_INVALID_VAL, OH_VideoEncoder_SetCallback(NULL, cb_, static_cast<void *>(signal_)));
194 }
195
196 /**
197 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_0700
198 * @tc.name : OH_VideoEncoder_SetCallback para error
199 * @tc.desc : api test
200 */
201 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_0700, TestSize.Level2)
202 {
203 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
204 if (cap) {
205 venc_ = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
206 ASSERT_NE(NULL, venc_);
207
208 OH_AVCodecAsyncCallback cb2_;
209 cb2_.onError = NULL;
210 cb2_.onStreamChanged = NULL;
211 cb2_.onNeedInputData = NULL;
212 cb2_.onNeedOutputData = NULL;
213 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_SetCallback(venc_, cb2_, static_cast<void *>(signal_)));
214 } else {
215 return;
216 }
217 }
218
219 /**
220 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_0800
221 * @tc.name : OH_VideoEncoder_SetCallback para error
222 * @tc.desc : api test
223 */
224 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_0800, TestSize.Level2)
225 {
226 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
227 if (cap) {
228 venc_ = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
229 OH_AVCodecAsyncCallback cb_;
230 cb_.onError = onError;
231 cb_.onStreamChanged = onStreamChanged;
232 cb_.onNeedInputData = onNeedInputData;
233 cb_.onNeedOutputData = onNewOutputData;
234 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_SetCallback(venc_, cb_, NULL));
235 } else {
236 return;
237 }
238 }
239
240 /**
241 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_0900
242 * @tc.name : OH_VideoEncoder_Configure para error
243 * @tc.desc : api test
244 */
245 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_0900, TestSize.Level2)
246 {
247 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
248 if (cap) {
249 OH_AVErrCode ret = AV_ERR_OK;
250 venc_ = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
251 ASSERT_NE(nullptr, venc_);
252 ret = OH_VideoEncoder_Configure(venc_, nullptr);
253 ASSERT_EQ(ret, AV_ERR_INVALID_VAL);
254 } else {
255 return;
256 }
257 }
258
259 /**
260 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_1100
261 * @tc.name : OH_VideoEncoder_Configure para not enough
262 * @tc.desc : api test
263 */
264 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_1100, TestSize.Level2)
265 {
266 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
267 if (cap) {
268 OH_AVErrCode ret = AV_ERR_OK;
269 venc_ = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
270 ASSERT_NE(nullptr, venc_);
271 format = OH_AVFormat_Create();
272 ASSERT_NE(nullptr, format);
273 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITRATE, 100000);
274 ret = OH_VideoEncoder_Configure(venc_, format);
275 ASSERT_EQ(ret, AV_ERR_INVALID_VAL);
276 } else {
277 return;
278 }
279 }
280
281 /**
282 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_1400
283 * @tc.name : OH_VideoEncoder_Start para error
284 * @tc.desc : api test
285 */
286 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_1400, TestSize.Level2)
287 {
288 OH_AVErrCode ret = AV_ERR_OK;
289 ret = OH_VideoEncoder_Start(nullptr);
290 ASSERT_EQ(ret, AV_ERR_INVALID_VAL);
291 }
292
293 /**
294 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_1500
295 * @tc.name : OH_VideoEncoder_Stop para error
296 * @tc.desc : api test
297 */
298 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_1500, TestSize.Level2)
299 {
300 OH_AVErrCode ret = AV_ERR_OK;
301 ret = OH_VideoEncoder_Stop(nullptr);
302 ASSERT_EQ(ret, AV_ERR_INVALID_VAL);
303 }
304
305 /**
306 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_1600
307 * @tc.name : OH_VideoEncoder_Flush para error
308 * @tc.desc : api test
309 */
310 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_1600, TestSize.Level2)
311 {
312 OH_AVErrCode ret = AV_ERR_OK;
313 ret = OH_VideoEncoder_Flush(nullptr);
314 ASSERT_EQ(ret, AV_ERR_INVALID_VAL);
315 }
316
317 /**
318 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_1700
319 * @tc.name : OH_VideoEncoder_Reset para error
320 * @tc.desc : api test
321 */
322 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_1700, TestSize.Level2)
323 {
324 OH_AVErrCode ret = AV_ERR_OK;
325 ret = OH_VideoEncoder_Reset(nullptr);
326 ASSERT_EQ(ret, AV_ERR_INVALID_VAL);
327 }
328
329 /**
330 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_1800
331 * @tc.name : OH_VideoEncoder_Reset para error
332 * @tc.desc : api test
333 */
334 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_1800, TestSize.Level2)
335 {
336 format = OH_VideoEncoder_GetOutputDescription(nullptr);
337 ASSERT_EQ(format, nullptr);
338 }
339
340 /**
341 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_1900
342 * @tc.name : OH_VideoEncoder_SetParameter para error
343 * @tc.desc : api test
344 */
345 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_1900, TestSize.Level2)
346 {
347 venc_ = OH_VideoEncoder_CreateByName(g_codecName);
348 ASSERT_EQ(AV_ERR_INVALID_VAL, OH_VideoEncoder_SetParameter(venc_, nullptr));
349 }
350
351 /**
352 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_2000
353 * @tc.name : OH_VideoEncoder_SetParameter para error
354 * @tc.desc : api test
355 */
356 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_2000, TestSize.Level2)
357 {
358 format = OH_AVFormat_Create();
359 ASSERT_NE(NULL, format);
360 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
361 ASSERT_EQ(AV_ERR_INVALID_VAL, OH_VideoEncoder_SetParameter(NULL, format));
362 }
363
364 /**
365 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_2100
366 * @tc.name : OH_VideoEncoder_GetSurface para error
367 * @tc.desc : api test
368 */
369 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_2100, TestSize.Level2)
370 {
371 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
372 if (cap) {
373 OH_AVErrCode ret = AV_ERR_OK;
374 venc_ = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
375 ASSERT_NE(nullptr, venc_);
376 ret = OH_VideoEncoder_GetSurface(venc_, nullptr);
377 ASSERT_EQ(ret, AV_ERR_INVALID_VAL);
378 } else {
379 return;
380 }
381 }
382
383 /**
384 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_2200
385 * @tc.name : OH_VideoEncoder_FreeOutputData para error
386 * @tc.desc : api test
387 */
388 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_2200, TestSize.Level2)
389 {
390 OH_AVErrCode ret = AV_ERR_OK;
391 ret = OH_VideoEncoder_FreeOutputData(nullptr, 0);
392 ASSERT_EQ(ret, AV_ERR_INVALID_VAL);
393 }
394
395 /**
396 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_2300
397 * @tc.name : OH_VideoEncoder_FreeOutputData para error
398 * @tc.desc : api test
399 */
400 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_2300, TestSize.Level2)
401 {
402 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
403 const int32_t *pixelFormat = nullptr;
404 uint32_t pixelFormatNum = 0;
405 if (cap) {
406 ASSERT_EQ(AV_ERR_OK, OH_AVCapability_GetVideoSupportedPixelFormats(cap, &pixelFormat, &pixelFormatNum));
407 if (pixelFormatNum > 0) {
408 OH_AVErrCode ret = AV_ERR_OK;
409 venc_ = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
410 ASSERT_NE(nullptr, venc_);
411 format = OH_AVFormat_Create();
412 ASSERT_NE(nullptr, format);
413 OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
414 OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_HEIGHT);
415 OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, pixelFormat[0]);
416 ret = OH_VideoEncoder_Configure(venc_, format);
417 ASSERT_EQ(ret, AV_ERR_OK);
418 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Start(venc_));
419 usleep(1000000);
420 ret = OH_VideoEncoder_FreeOutputData(venc_, 9999999);
421 ASSERT_EQ(ret, AV_ERR_INVALID_STATE);
422 }
423
424 } else {
425 return;
426 }
427 }
428
429 /**
430 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_2400
431 * @tc.name : OH_VideoEncoder_NotifyEndOfStream para error
432 * @tc.desc : api test
433 */
434 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_2400, TestSize.Level2)
435 {
436 OH_AVErrCode ret = AV_ERR_OK;
437 ret = OH_VideoEncoder_NotifyEndOfStream(nullptr);
438 ASSERT_EQ(ret, AV_ERR_INVALID_VAL);
439 }
440 /**
441 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_2500
442 * @tc.name : OH_VideoEncoder_NotifyEndOfStream para error
443 * @tc.desc : api test
444 */
445 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_2500, TestSize.Level2)
446 {
447 OH_AVErrCode ret = AV_ERR_OK;
448 ret = OH_VideoEncoder_NotifyEndOfStream(nullptr);
449 ASSERT_EQ(ret, AV_ERR_INVALID_VAL);
450 }
451
452 /**
453 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_2600
454 * @tc.name : OH_VideoEncoder_PushInputData para error
455 * @tc.desc : api test
456 */
457 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_2600, TestSize.Level2)
458 {
459 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
460 if (cap) {
461 venc_ = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
462 ASSERT_NE(nullptr, venc_);
463 OH_AVCodecBufferAttr attr;
464 attr.pts = -1;
465 attr.size = -1;
466 attr.offset = 0;
467 attr.flags = AVCODEC_BUFFER_FLAGS_EOS;
468
469 ASSERT_EQ(AV_ERR_INVALID_VAL, OH_VideoEncoder_PushInputData(venc_, 0, attr));
470 } else {
471 return;
472 }
473 }
474
475 /**
476 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_2700
477 * @tc.name : OH_VideoEncoder_PushInputData para error
478 * @tc.desc : api test
479 */
480 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_2700, TestSize.Level2)
481 {
482 OH_AVCodecBufferAttr attr;
483 attr.pts = 0;
484 attr.size = 0;
485 attr.offset = 0;
486 attr.flags = AVCODEC_BUFFER_FLAGS_EOS;
487 ASSERT_EQ(AV_ERR_INVALID_VAL, OH_VideoEncoder_PushInputData(NULL, 0, attr));
488 }
489
490 /**
491 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_2800
492 * @tc.name : OH_VideoEncoder_PushInputData para error
493 * @tc.desc : api test
494 */
495 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_2800, TestSize.Level2)
496 {
497 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
498 if (cap) {
499 venc_ = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
500 ASSERT_NE(nullptr, venc_);
501 OH_AVCodecBufferAttr attr;
502 attr.pts = 0;
503 attr.size = 0;
504 attr.offset = 0;
505 attr.flags = AVCODEC_BUFFER_FLAGS_EOS;
506 ASSERT_EQ(AV_ERR_INVALID_VAL, OH_VideoEncoder_PushInputData(NULL, 99999, attr));
507 } else {
508 return;
509 }
510 }
511
512 /**
513 * @tc.number : VIDEO_ENCODE_ILLEGAL_PARA_2900
514 * @tc.name : OH_VideoEncoder_GetInputDescription para error
515 * * @tc.desc : api test
516 */
517 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_ILLEGAL_PARA_2900, TestSize.Level2)
518 {
519 ASSERT_EQ(nullptr, OH_VideoEncoder_GetInputDescription(nullptr));
520 }
521
522 /**
523 * @tc.number : VIDEO_ENCODE_API_0100
524 * @tc.name : create create
525 * @tc.desc : function test
526 */
527 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_API_0100, TestSize.Level2)
528 {
529 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
530 if (cap) {
531 venc_ = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
532 ASSERT_NE(venc_, NULL);
533 OH_AVCodec *venc_2 = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
534 ASSERT_NE(venc_2, NULL);
535 OH_VideoEncoder_Destroy(venc_2);
536 venc_2 = nullptr;
537 } else {
538 return;
539 }
540 }
541
542 /**
543 * @tc.number : VIDEO_ENCODE_API_3100
544 * @tc.name : create create
545 * @tc.desc : function test
546 */
547 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_API_3100, TestSize.Level2)
548 {
549 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
550 if (cap) {
551 venc_ = OH_VideoEncoder_CreateByName(g_codecName);
552 ASSERT_NE(venc_, NULL);
553 OH_AVCodec *venc_2 = OH_VideoEncoder_CreateByName(g_codecName);
554 ASSERT_NE(venc_2, NULL);
555 OH_VideoEncoder_Destroy(venc_2);
556 venc_2 = nullptr;
557 } else {
558 return;
559 }
560 }
561
562 /**
563 * @tc.number : VIDEO_ENCODE_API_0200
564 * @tc.name : create configure configure
565 * @tc.desc : function test
566 */
567 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_API_0200, TestSize.Level2)
568 {
569 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
570 if (cap) {
571 venc_ = OH_VideoEncoder_CreateByName(g_codecName);
572 ASSERT_NE(NULL, venc_);
573
574 format = OH_AVFormat_Create();
575 ASSERT_NE(NULL, format);
576
577 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
578 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
579 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, AV_PIXEL_FORMAT_NV12);
580
581 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Configure(venc_, format));
582 ASSERT_EQ(AV_ERR_INVALID_STATE, OH_VideoEncoder_Configure(venc_, format));
583 } else {
584 return;
585 }
586 }
587
588 /**
589 * @tc.number : VIDEO_ENCODE_API_0300
590 * @tc.name : create configure start start
591 * @tc.desc : function test
592 */
593 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_API_0300, TestSize.Level2)
594 {
595 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
596 if (cap) {
597 venc_ = OH_VideoEncoder_CreateByName(g_codecName);
598 ASSERT_NE(NULL, venc_);
599
600 format = OH_AVFormat_Create();
601 ASSERT_NE(NULL, format);
602
603 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
604 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
605 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, AV_PIXEL_FORMAT_NV12);
606 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Configure(venc_, format));
607 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Start(venc_));
608 ASSERT_EQ(AV_ERR_INVALID_STATE, OH_VideoEncoder_Start(venc_));
609 } else {
610 return;
611 }
612 }
613
614 /**
615 * @tc.number : VIDEO_ENCODE_API_0400
616 * @tc.name : create configure start stop stop
617 * @tc.desc : function test
618 */
619 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_API_0400, TestSize.Level2)
620 {
621 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
622 if (cap) {
623 venc_ = OH_VideoEncoder_CreateByName(g_codecName);
624 ASSERT_NE(NULL, venc_);
625
626 format = OH_AVFormat_Create();
627 ASSERT_NE(NULL, format);
628
629 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
630 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
631 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, AV_PIXEL_FORMAT_NV12);
632
633 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Configure(venc_, format));
634 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Start(venc_));
635 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Stop(venc_));
636 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Stop(venc_));
637 } else {
638 return;
639 }
640 }
641
642 /**
643 * @tc.number : VIDEO_ENCODE_API_0500
644 * @tc.name : create configure start stop reset reset
645 * @tc.desc : function test
646 */
647 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_API_0500, TestSize.Level2)
648 {
649 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
650 if (cap) {
651 venc_ = OH_VideoEncoder_CreateByName(g_codecName);
652 ASSERT_NE(NULL, venc_);
653
654 format = OH_AVFormat_Create();
655 ASSERT_NE(NULL, format);
656 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
657 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
658 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, AV_PIXEL_FORMAT_NV12);
659
660 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Configure(venc_, format));
661 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Start(venc_));
662 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Stop(venc_));
663 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Reset(venc_));
664 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Reset(venc_));
665 } else {
666 return;
667 }
668 }
669
670 /**
671 * @tc.number : VIDEO_ENCODE_API_0600
672 * @tc.name : create configure start EOS EOS
673 * @tc.desc : function test
674 */
675 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_API_0600, TestSize.Level2)
676 {
677 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
678 if (cap) {
679 venc_ = OH_VideoEncoder_CreateByName(g_codecName);
680 ASSERT_NE(NULL, venc_);
681 format = OH_AVFormat_Create();
682 ASSERT_NE(NULL, format);
683 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
684 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
685 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, AV_PIXEL_FORMAT_NV12);
686 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Configure(venc_, format));
687 OH_AVCodecAsyncCallback cb_;
688 cb_.onError = onError;
689 cb_.onStreamChanged = onStreamChanged;
690 cb_.onNeedInputData = onNeedInputData;
691 cb_.onNeedOutputData = onNewOutputData;
692 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_SetCallback(venc_, cb_, static_cast<void *>(signal_)));
693
694 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Start(venc_));
695 unique_lock<mutex> lock(signal_->inMutex_);
__anon77d5b2120302null696 signal_->inCond_.wait(lock, [] { return signal_->inIdxQueue_.size() > 1; });
697 uint32_t index = signal_->inIdxQueue_.front();
698 OH_AVCodecBufferAttr attr;
699 attr.pts = 0;
700 attr.size = 0;
701 attr.offset = 0;
702 attr.flags = AVCODEC_BUFFER_FLAGS_EOS;
703
704 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_PushInputData(venc_, index, attr));
705 signal_->inIdxQueue_.pop();
706 index = signal_->inIdxQueue_.front();
707 ASSERT_EQ(AV_ERR_INVALID_STATE, OH_VideoEncoder_PushInputData(venc_, index, attr));
708 signal_->inIdxQueue_.pop();
709 } else {
710 return;
711 }
712 }
713
714 /**
715 * @tc.number : VIDEO_ENCODE_API_0700
716 * @tc.name : create configure start flush flush
717 * @tc.desc : function test
718 */
719 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_API_0700, TestSize.Level2)
720 {
721 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
722 if (cap) {
723 venc_ = OH_VideoEncoder_CreateByName(g_codecName);
724 ASSERT_NE(NULL, venc_);
725 format = OH_AVFormat_Create();
726 ASSERT_NE(NULL, format);
727 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
728 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
729 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, AV_PIXEL_FORMAT_NV12);
730 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Configure(venc_, format));
731 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Start(venc_));
732 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Flush(venc_));
733 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Flush(venc_));
734 } else {
735 return;
736 }
737 }
738
739 /**
740 * @tc.number : VIDEO_ENCODE_API_0800
741 * @tc.name : create configure start stop release release
742 * @tc.desc : function test
743 */
744 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_API_0800, TestSize.Level2)
745 {
746 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
747 if (cap) {
748 venc_ = OH_VideoEncoder_CreateByName(g_codecName);
749 ASSERT_NE(NULL, venc_);
750
751 format = OH_AVFormat_Create();
752 ASSERT_NE(NULL, format);
753
754 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
755 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
756 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, AV_PIXEL_FORMAT_NV12);
757
758 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Configure(venc_, format));
759 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Start(venc_));
760 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Stop(venc_));
761 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Destroy(venc_));
762 venc_ = nullptr;
763 ASSERT_EQ(AV_ERR_INVALID_VAL, OH_VideoEncoder_Destroy(venc_));
764 } else {
765 return;
766 }
767 }
768
769 /**
770 * @tc.number : VIDEO_ENCODE_API_0900
771 * @tc.name : create create
772 * @tc.desc : function test
773 */
774 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_API_0900, TestSize.Level2)
775 {
776 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
777 if (cap) {
778 venc_ = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
779 ASSERT_NE(venc_, NULL);
780 OH_AVCodec *venc_2 = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
781 ASSERT_NE(venc_2, NULL);
782 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Destroy(venc_2));
783 venc_2 = nullptr;
784 } else {
785 return;
786 }
787 }
788
789 /**
790 * @tc.number : VIDEO_ENCODE_API_1000
791 * @tc.name : repeat OH_VideoEncoder_SetCallback
792 * @tc.desc : function test
793 */
794 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_API_1000, TestSize.Level2)
795 {
796 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
797 if (cap) {
798 venc_ = OH_VideoEncoder_CreateByName(g_codecName);
799 ASSERT_NE(venc_, NULL);
800 OH_AVCodecAsyncCallback cb_;
801 cb_.onError = onError;
802 cb_.onStreamChanged = onStreamChanged;
803 cb_.onNeedInputData = onNeedInputData;
804 cb_.onNeedOutputData = onNewOutputData;
805 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_SetCallback(venc_, cb_, NULL));
806 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_SetCallback(venc_, cb_, NULL));
807 } else {
808 return;
809 }
810 }
811
812 /**
813 * @tc.number : VIDEO_ENCODE_API_1100
814 * @tc.name : repeat OH_VideoEncoder_GetOutputDescription
815 * @tc.desc : function test
816 */
817 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_API_1100, TestSize.Level2)
818 {
819 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
820 if (cap) {
821 venc_ = OH_VideoEncoder_CreateByName(g_codecName);
822 ASSERT_NE(venc_, NULL);
823 format = OH_VideoEncoder_GetOutputDescription(venc_);
824 ASSERT_NE(NULL, format);
825 OH_AVFormat_Destroy(format);
826 format = OH_VideoEncoder_GetOutputDescription(venc_);
827 ASSERT_NE(NULL, format);
828 } else {
829 return;
830 }
831 }
832
833 /**
834 * @tc.number : VIDEO_ENCODE_API_1200
835 * @tc.name : repeat OH_VideoEncoder_SetParameter
836 * @tc.desc : function test
837 */
838 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_API_1200, TestSize.Level2)
839 {
840 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
841 if (cap) {
842 venc_ = OH_VideoEncoder_CreateByName(g_codecName);
843 ASSERT_NE(NULL, venc_);
844
845 format = OH_AVFormat_Create();
846 ASSERT_NE(NULL, format);
847
848 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
849 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
850 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, AV_PIXEL_FORMAT_NV12);
851
852 ASSERT_EQ(AV_ERR_INVALID_STATE, OH_VideoEncoder_SetParameter(venc_, format));
853 ASSERT_EQ(AV_ERR_INVALID_STATE, OH_VideoEncoder_SetParameter(venc_, format));
854 } else {
855 return;
856 }
857 }
858
859 /**
860 * @tc.number : VIDEO_ENCODE_API_1200
861 * @tc.name : repeat OH_VideoEncoder_GetInputDescription
862 * @tc.desc : function test
863 */
864 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_API_1300, TestSize.Level2)
865 {
866 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
867 if (cap) {
868 venc_ = OH_VideoEncoder_CreateByName(g_codecName);
869 ASSERT_NE(NULL, venc_);
870 format = OH_VideoEncoder_GetInputDescription(venc_);
871 ASSERT_NE(NULL, format);
872 OH_AVFormat_Destroy(format);
873 format = OH_VideoEncoder_GetInputDescription(venc_);
874 ASSERT_NE(NULL, format);
875 } else {
876 return;
877 }
878 }
879
880 /**
881 * @tc.number : VIDEO_ENCODE_API_1400
882 * @tc.name : set quality with illegal value
883 * @tc.desc : function test
884 */
885 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_API_1400, TestSize.Level2)
886 {
887 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
888 const int32_t *pixelFormat = nullptr;
889 uint32_t pixelFormatNum = 0;
890 if (cap) {
891 ASSERT_EQ(AV_ERR_OK, OH_AVCapability_GetVideoSupportedPixelFormats(cap, &pixelFormat, &pixelFormatNum));
892 if (pixelFormatNum > 0) {
893 venc_ = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
894 ASSERT_NE(nullptr, venc_);
895 format = OH_AVFormat_Create();
896 ASSERT_EQ(true, OH_AVFormat_SetIntValue(format, OH_MD_KEY_VIDEO_ENCODE_BITRATE_MODE, CQ));
897 ASSERT_EQ(true, OH_AVFormat_SetIntValue(format, OH_MD_KEY_QUALITY, 101));
898 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
899 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
900 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, pixelFormat[0]);
901 ASSERT_EQ(AV_ERR_INVALID_VAL, OH_VideoEncoder_Configure(venc_, format));
902 }
903 } else {
904 return;
905 }
906 }
907
908 /**
909 * @tc.number : VIDEO_ENCODE_API_1410
910 * @tc.name : set quality with illegal value
911 * @tc.desc : function test
912 */
913 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_API_1410, TestSize.Level2)
914 {
915 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
916 const int32_t *pixelFormat = nullptr;
917 uint32_t pixelFormatNum = 0;
918 if (cap) {
919 ASSERT_EQ(AV_ERR_OK, OH_AVCapability_GetVideoSupportedPixelFormats(cap, &pixelFormat, &pixelFormatNum));
920 if (pixelFormatNum > 0) {
921 venc_ = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
922 ASSERT_NE(nullptr, venc_);
923 format = OH_AVFormat_Create();
924 ASSERT_EQ(true, OH_AVFormat_SetIntValue(format, OH_MD_KEY_VIDEO_ENCODE_BITRATE_MODE, CQ));
925 ASSERT_EQ(true, OH_AVFormat_SetIntValue(format, OH_MD_KEY_QUALITY, -1));
926 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
927 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
928 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, pixelFormat[0]);
929 ASSERT_EQ(AV_ERR_INVALID_VAL, OH_VideoEncoder_Configure(venc_, format));
930 }
931 } else {
932 return;
933 }
934 }
935 /**
936 * @tc.number : VIDEO_ENCODE_SYNC_API_0010
937 * @tc.name : VIDEO_ENCODE_SYNC_API_0010
938 * @tc.desc : api test
939 */
940 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_SYNC_API_0010, TestSize.Level2)
941 {
942 uint32_t index;
943 ASSERT_EQ(AV_ERR_INVALID_VAL, OH_VideoEncoder_QueryInputBuffer(nullptr, &index, -1));
944 }
945
946 /**
947 * @tc.number : VIDEO_ENCODE_SYNC_API_0020
948 * @tc.name : VIDEO_ENCODE_SYNC_API_0020
949 * @tc.desc : api test
950 */
951 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_SYNC_API_0020, TestSize.Level2)
952 {
953 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
954 const int32_t *pixelFormat = nullptr;
955 uint32_t pixelFormatNum = 0;
956 if (cap) {
957 ASSERT_EQ(AV_ERR_OK, OH_AVCapability_GetVideoSupportedPixelFormats(cap, &pixelFormat, &pixelFormatNum));
958 if (pixelFormatNum > 0) {
959 uint32_t index;
960 venc_ = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
961 ASSERT_NE(nullptr, venc_);
962 format = OH_AVFormat_Create();
963 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
964 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
965 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, pixelFormat[0]);
966 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_ENABLE_SYNC_MODE, 1);
967 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Configure(venc_, format));
968 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Prepare(venc_));
969 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Start(venc_));
970 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_QueryInputBuffer(venc_, &index, INT64_MAX));
971 }
972 }
973 }
974
975 /**
976 * @tc.number : VIDEO_ENCODE_SYNC_API_0030
977 * @tc.name : VIDEO_ENCODE_SYNC_API_0030
978 * @tc.desc : api test
979 */
980 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_SYNC_API_0030, TestSize.Level2)
981 {
982 cap = OH_AVCodec_GetCapabilityByCategory(OH_AVCODEC_MIMETYPE_VIDEO_AVC, true, HARDWARE);
983 const int32_t *pixelFormat = nullptr;
984 uint32_t pixelFormatNum = 0;
985 if (cap) {
986 ASSERT_EQ(AV_ERR_OK, OH_AVCapability_GetVideoSupportedPixelFormats(cap, &pixelFormat, &pixelFormatNum));
987 if (pixelFormatNum > 0) {
988 uint32_t index;
989 venc_ = OH_VideoEncoder_CreateByMime(OH_AVCODEC_MIMETYPE_VIDEO_AVC);
990 ASSERT_NE(nullptr, venc_);
991 format = OH_AVFormat_Create();
992 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, DEFAULT_WIDTH);
993 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, DEFAULT_HEIGHT);
994 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_PIXEL_FORMAT, pixelFormat[0]);
995 (void)OH_AVFormat_SetIntValue(format, OH_MD_KEY_ENABLE_SYNC_MODE, 1);
996 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Configure(venc_, format));
997 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Prepare(venc_));
998 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_Start(venc_));
999 ASSERT_EQ(AV_ERR_OK, OH_VideoEncoder_QueryInputBuffer(venc_, &index, INT64_MIN));
1000 }
1001 }
1002 }
1003
1004 /**
1005 * @tc.number : VIDEO_ENCODE_SYNC_API_0040
1006 * @tc.name : VIDEO_ENCODE_SYNC_API_0040
1007 * @tc.desc : api test
1008 */
1009 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_SYNC_API_0040, TestSize.Level2)
1010 {
1011 ASSERT_EQ(nullptr, OH_VideoEncoder_GetInputBuffer(nullptr, 1));
1012 }
1013
1014 /**
1015 * @tc.number : VIDEO_ENCODE_SYNC_API_0050
1016 * @tc.name : VIDEO_ENCODE_SYNC_API_0050
1017 * @tc.desc : api test
1018 */
1019 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_SYNC_API_0050, TestSize.Level2)
1020 {
1021 uint32_t index;
1022 ASSERT_EQ(AV_ERR_INVALID_VAL, OH_VideoEncoder_QueryOutputBuffer(nullptr, &index, -1));
1023 }
1024
1025 /**
1026 * @tc.number : VIDEO_ENCODE_SYNC_API_0060
1027 * @tc.name : VIDEO_ENCODE_SYNC_API_0060
1028 * @tc.desc : api test
1029 */
1030 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_SYNC_API_0060, TestSize.Level2)
1031 {
1032 if (cap != nullptr) {
1033 auto vEncSample = make_unique<VEncAPI11Sample>();
1034 vEncSample->INP_DIR = "/data/test/media/1280_720_nv.yuv";
1035 vEncSample->enbleSyncMode = 1;
1036 vEncSample->syncOutputWaitTime = INT64_MAX;
1037 ASSERT_EQ(AV_ERR_OK, vEncSample->CreateVideoEncoder(g_codecName));
1038 ASSERT_EQ(AV_ERR_OK, vEncSample->ConfigureVideoEncoder());
1039 ASSERT_EQ(AV_ERR_OK, vEncSample->StartVideoEncoder());
1040 vEncSample->WaitForEOS();
1041 ASSERT_EQ(AV_ERR_OK, vEncSample->errCount);
1042 }
1043 }
1044
1045 /**
1046 * @tc.number : VIDEO_ENCODE_SYNC_API_0070
1047 * @tc.name : VIDEO_ENCODE_SYNC_API_0070
1048 * @tc.desc : api test
1049 */
1050 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_SYNC_API_0070, TestSize.Level2)
1051 {
1052 if (cap != nullptr) {
1053 auto vEncSample = make_unique<VEncAPI11Sample>();
1054 vEncSample->INP_DIR = "/data/test/media/1280_720_nv.yuv";
1055 vEncSample->enbleSyncMode = 1;
1056 vEncSample->syncOutputWaitTime = INT64_MIN;
1057 ASSERT_EQ(AV_ERR_OK, vEncSample->CreateVideoEncoder(g_codecName));
1058 ASSERT_EQ(AV_ERR_OK, vEncSample->ConfigureVideoEncoder());
1059 ASSERT_EQ(AV_ERR_OK, vEncSample->StartVideoEncoder());
1060 vEncSample->WaitForEOS();
1061 ASSERT_EQ(AV_ERR_OK, vEncSample->errCount);
1062 }
1063 }
1064
1065 /**
1066 * @tc.number : VIDEO_ENCODE_SYNC_API_0080
1067 * @tc.name : VIDEO_ENCODE_SYNC_API_0080
1068 * @tc.desc : api test
1069 */
1070 HWTEST_F(HwEncApiNdkTest, VIDEO_ENCODE_SYNC_API_0080, TestSize.Level2)
1071 {
1072 ASSERT_EQ(nullptr, OH_VideoEncoder_GetOutputBuffer(nullptr, 1));
1073 }
1074 } // namespace
1075