1 /*
2 * Copyright (C) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <string>
17 #include "gtest/gtest.h"
18 #include "AVMuxerDemo.h"
19
20 using namespace std;
21 using namespace testing::ext;
22 using namespace OHOS;
23 using namespace OHOS::MediaAVCodec;
24
25 namespace {
26 class NativeAVMuxerParamCheckTest : public testing::Test {
27 public:
28 static void SetUpTestCase();
29 static void TearDownTestCase();
30 void SetUp() override;
31 void TearDown() override;
32 };
33
SetUpTestCase()34 void NativeAVMuxerParamCheckTest::SetUpTestCase() {}
TearDownTestCase()35 void NativeAVMuxerParamCheckTest::TearDownTestCase() {}
SetUp()36 void NativeAVMuxerParamCheckTest::SetUp() {}
TearDown()37 void NativeAVMuxerParamCheckTest::TearDown() {}
38
39 constexpr int32_t ROTATION_0 = 0;
40 constexpr int32_t ROTATION_90 = 90;
41 constexpr int32_t ROTATION_180 = 180;
42 constexpr int32_t ROTATION_270 = 270;
43 constexpr int32_t ROTATION_ERROR = -90;
44 constexpr int32_t ROTATION_45 = 45;
45
46 constexpr int64_t AUDIO_BITRATE = 320000;
47 constexpr int64_t VIDEO_BITRATE = 524569;
48 constexpr int32_t CODEC_CONFIG = 100;
49 constexpr int32_t CHANNEL_COUNT = 1;
50 constexpr int32_t SAMPLE_RATE = 48000;
51 constexpr int32_t PROFILE = 0;
52 constexpr int32_t INFO_SIZE = 100;
53
54 constexpr int32_t WIDTH = 352;
55 constexpr int32_t HEIGHT = 288;
56 constexpr int32_t FRAME_RATE = 60;
57 } // namespace
58
59 /**
60 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_001
61 * @tc.name : OH_AVMuxer_Create - fd check
62 * @tc.desc : param check test
63 */
64 HWTEST_F(NativeAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_001, TestSize.Level2)
65 {
66 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
67 OH_AVOutputFormat format = AV_OUTPUT_FORMAT_M4A;
68 int32_t fd = -1;
69 OH_AVMuxer *handle = muxerDemo->NativeCreate(fd, format);
70 ASSERT_EQ(nullptr, handle);
71
72 fd = muxerDemo->getErrorFd();
73 handle = muxerDemo->NativeCreate(fd, format);
74 ASSERT_EQ(nullptr, handle);
75
76 fd = muxerDemo->getFdByMode(format);
77 handle = muxerDemo->NativeCreate(fd, format);
78 ASSERT_NE(nullptr, handle);
79 muxerDemo->NativeDestroy(handle);
80 delete muxerDemo;
81 }
82
83 /**
84 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_002
85 * @tc.name : OH_AVMuxer_Create - format check
86 * @tc.desc : param check test
87 */
88 HWTEST_F(NativeAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_002, TestSize.Level2)
89 {
90 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
91 OH_AVOutputFormat format = AV_OUTPUT_FORMAT_DEFAULT;
92 int32_t fd = muxerDemo->getFdByMode(format);
93 OH_AVMuxer *handle = muxerDemo->NativeCreate(fd, format);
94 ASSERT_NE(nullptr, handle);
95 muxerDemo->NativeDestroy(handle);
96 handle = nullptr;
97
98 format = AV_OUTPUT_FORMAT_MPEG_4;
99 fd = muxerDemo->getFdByMode(format);
100 handle = muxerDemo->NativeCreate(fd, format);
101 ASSERT_NE(nullptr, handle);
102 muxerDemo->NativeDestroy(handle);
103 handle = nullptr;
104
105 format = AV_OUTPUT_FORMAT_M4A;
106 fd = muxerDemo->getFdByMode(format);
107 handle = muxerDemo->NativeCreate(fd, format);
108 ASSERT_NE(nullptr, handle);
109 muxerDemo->NativeDestroy(handle);
110 handle = nullptr;
111 delete muxerDemo;
112 }
113
114 /**
115 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_003
116 * @tc.name : OH_AVMuxer_SetRotation - rotation check
117 * @tc.desc : param check test
118 */
119 HWTEST_F(NativeAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_003, TestSize.Level2)
120 {
121 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
122 OH_AVOutputFormat format = AV_OUTPUT_FORMAT_MPEG_4;
123 int32_t fd = muxerDemo->getFdByMode(format);
124 OH_AVMuxer *handle = muxerDemo->NativeCreate(fd, format);
125 ASSERT_NE(nullptr, handle);
126
127 int32_t rotation;
128
129 rotation = ROTATION_0;
130 OH_AVErrCode ret = muxerDemo->NativeSetRotation(handle, rotation);
131 ASSERT_EQ(AV_ERR_OK, ret);
132
133 rotation = ROTATION_90;
134 ret = muxerDemo->NativeSetRotation(handle, rotation);
135 ASSERT_EQ(AV_ERR_OK, ret);
136
137 rotation = ROTATION_180;
138 ret = muxerDemo->NativeSetRotation(handle, rotation);
139 ASSERT_EQ(AV_ERR_OK, ret);
140
141 rotation = ROTATION_270;
142 ret = muxerDemo->NativeSetRotation(handle, rotation);
143 ASSERT_EQ(AV_ERR_OK, ret);
144
145 rotation = ROTATION_ERROR;
146 ret = muxerDemo->NativeSetRotation(handle, rotation);
147 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
148
149 rotation = ROTATION_45;
150 ret = muxerDemo->NativeSetRotation(handle, rotation);
151 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
152
153 muxerDemo->NativeDestroy(handle);
154 handle = nullptr;
155 delete muxerDemo;
156 }
157
158 /**
159 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_004
160 * @tc.name : OH_AVMuxer_AddTrack - trackFormat(OH_MD_KEY_CODEC_MIME) check
161 * @tc.desc : param check test
162 */
163 HWTEST_F(NativeAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_004, TestSize.Level2)
164 {
165 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
166 OH_AVOutputFormat format = AV_OUTPUT_FORMAT_MPEG_4;
167 int32_t fd = muxerDemo->getFdByMode(format);
168 OH_AVMuxer *handle = muxerDemo->NativeCreate(fd, format);
169 ASSERT_NE(nullptr, handle);
170
171 uint8_t a[CODEC_CONFIG];
172
173 OH_AVFormat *trackFormat = OH_AVFormat_Create();
174 OH_AVFormat_SetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_AUDIO_AAC);
175 OH_AVFormat_SetLongValue(trackFormat, OH_MD_KEY_BITRATE, AUDIO_BITRATE);
176 OH_AVFormat_SetBuffer(trackFormat, OH_MD_KEY_CODEC_CONFIG, a, CODEC_CONFIG);
177 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AV_SAMPLE_FMT_S16);
178 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, CHANNEL_COUNT);
179 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, SAMPLE_RATE);
180 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_PROFILE, PROFILE);
181
182 int32_t trackId;
183
184 OH_AVErrCode ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
185 ASSERT_EQ(0, trackId);
186
187 OH_AVFormat_SetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_AUDIO_MPEG);
188 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
189 ASSERT_EQ(1, trackId);
190
191 OH_AVFormat_SetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, "aaaaaa");
192 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
193 ASSERT_NE(AV_ERR_OK, ret);
194
195 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_CODEC_MIME, 0);
196 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
197 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
198
199 OH_AVFormat_SetLongValue(trackFormat, OH_MD_KEY_CODEC_MIME, 0);
200 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
201 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
202
203 OH_AVFormat_SetFloatValue(trackFormat, OH_MD_KEY_CODEC_MIME, 0.1);
204 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
205 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
206
207 OH_AVFormat_SetDoubleValue(trackFormat, OH_MD_KEY_CODEC_MIME, 0.1);
208 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
209 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
210
211 uint8_t b[100];
212 OH_AVFormat_SetBuffer(trackFormat, OH_MD_KEY_CODEC_MIME, b, 100);
213 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
214 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
215
216 muxerDemo->NativeDestroy(handle);
217 OH_AVFormat_Destroy(trackFormat);
218 handle = nullptr;
219 delete muxerDemo;
220 }
221
222 /**
223 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_005
224 * @tc.name : OH_AVMuxer_AddTrack - trackFormat(OH_MD_KEY_AUD_CHANNEL_COUNT) check
225 * @tc.desc : param check test
226 */
227 HWTEST_F(NativeAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_005, TestSize.Level2)
228 {
229 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
230 OH_AVOutputFormat format = AV_OUTPUT_FORMAT_MPEG_4;
231 int32_t fd = muxerDemo->getFdByMode(format);
232 OH_AVMuxer *handle = muxerDemo->NativeCreate(fd, format);
233 ASSERT_NE(nullptr, handle);
234
235 uint8_t a[CODEC_CONFIG];
236
237 OH_AVFormat *trackFormat = OH_AVFormat_Create();
238 OH_AVFormat_SetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_AUDIO_AAC);
239 OH_AVFormat_SetLongValue(trackFormat, OH_MD_KEY_BITRATE, AUDIO_BITRATE);
240 OH_AVFormat_SetBuffer(trackFormat, OH_MD_KEY_CODEC_CONFIG, a, CODEC_CONFIG);
241 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AV_SAMPLE_FMT_S16);
242 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, CHANNEL_COUNT);
243 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, SAMPLE_RATE);
244 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_PROFILE, PROFILE);
245
246 int32_t trackId;
247
248 OH_AVErrCode ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
249 ASSERT_EQ(0, trackId);
250
251 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, -1);
252 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
253 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
254
255 OH_AVFormat_SetStringValue(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, "aaaaaa");
256 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
257 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
258
259 OH_AVFormat_SetLongValue(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, 0);
260 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
261 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
262
263 OH_AVFormat_SetFloatValue(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, 0.1);
264 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
265 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
266
267 OH_AVFormat_SetDoubleValue(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, 0.1);
268 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
269 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
270
271 uint8_t b[100];
272 OH_AVFormat_SetBuffer(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, b, 100);
273 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
274 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
275
276 muxerDemo->NativeDestroy(handle);
277 OH_AVFormat_Destroy(trackFormat);
278 handle = nullptr;
279 delete muxerDemo;
280 }
281
282 /**
283 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_006
284 * @tc.name : OH_AVMuxer_AddTrack - trackFormat(OH_MD_KEY_AUD_SAMPLE_RATE) check
285 * @tc.desc : param check test
286 */
287 HWTEST_F(NativeAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_006, TestSize.Level2)
288 {
289 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
290 OH_AVOutputFormat format = AV_OUTPUT_FORMAT_MPEG_4;
291 int32_t fd = muxerDemo->getFdByMode(format);
292 OH_AVMuxer *handle = muxerDemo->NativeCreate(fd, format);
293 ASSERT_NE(nullptr, handle);
294
295 uint8_t a[CODEC_CONFIG];
296
297 OH_AVFormat *trackFormat = OH_AVFormat_Create();
298 OH_AVFormat_SetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_AUDIO_AAC);
299 OH_AVFormat_SetLongValue(trackFormat, OH_MD_KEY_BITRATE, AUDIO_BITRATE);
300 OH_AVFormat_SetBuffer(trackFormat, OH_MD_KEY_CODEC_CONFIG, a, CODEC_CONFIG);
301 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AV_SAMPLE_FMT_S16);
302 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, CHANNEL_COUNT);
303 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, SAMPLE_RATE);
304 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_PROFILE, PROFILE);
305
306 int32_t trackId;
307
308 OH_AVErrCode ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
309 ASSERT_EQ(0, trackId);
310
311 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, -1);
312 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
313 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
314
315 OH_AVFormat_SetStringValue(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, "aaaaaa");
316 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
317 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
318
319 OH_AVFormat_SetLongValue(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, 0);
320 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
321 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
322
323 OH_AVFormat_SetFloatValue(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, 0.1);
324 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
325 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
326
327 OH_AVFormat_SetDoubleValue(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, 0.1);
328 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
329 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
330
331 uint8_t b[100];
332 OH_AVFormat_SetBuffer(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, b, 100);
333 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
334 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
335
336 muxerDemo->NativeDestroy(handle);
337 OH_AVFormat_Destroy(trackFormat);
338 handle = nullptr;
339 delete muxerDemo;
340 }
341
342 /**
343 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_007
344 * @tc.name : OH_AVMuxer_AddTrack - video trackFormat(OH_MD_KEY_CODEC_MIME) check
345 * @tc.desc : param check test
346 */
347 HWTEST_F(NativeAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_007, TestSize.Level2)
348 {
349 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
350 OH_AVOutputFormat format = AV_OUTPUT_FORMAT_MPEG_4;
351 int32_t fd = muxerDemo->getFdByMode(format);
352 OH_AVMuxer *handle = muxerDemo->NativeCreate(fd, format);
353 ASSERT_NE(nullptr, handle);
354
355 uint8_t a[CODEC_CONFIG];
356
357 OH_AVFormat *trackFormat = OH_AVFormat_Create();
358 OH_AVFormat_SetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_VIDEO_AVC);
359 OH_AVFormat_SetLongValue(trackFormat, OH_MD_KEY_BITRATE, VIDEO_BITRATE);
360 OH_AVFormat_SetBuffer(trackFormat, OH_MD_KEY_CODEC_CONFIG, a, CODEC_CONFIG);
361 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_PIXEL_FORMAT, AV_PIX_FMT_YUV420P);
362 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_WIDTH, WIDTH);
363 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_HEIGHT, HEIGHT);
364
365 int32_t trackId;
366
367 OH_AVErrCode ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
368 ASSERT_EQ(AV_ERR_OK, ret);
369 ASSERT_EQ(0, trackId);
370
371 OH_AVFormat_SetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_VIDEO_MPEG4);
372 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
373 ASSERT_EQ(AV_ERR_OK, ret);
374 ASSERT_EQ(1, trackId);
375
376 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_CODEC_MIME, 0);
377 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
378 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
379
380 OH_AVFormat_SetLongValue(trackFormat, OH_MD_KEY_CODEC_MIME, 0);
381 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
382 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
383
384 OH_AVFormat_SetFloatValue(trackFormat, OH_MD_KEY_CODEC_MIME, 0.1);
385 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
386 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
387
388 OH_AVFormat_SetDoubleValue(trackFormat, OH_MD_KEY_CODEC_MIME, 0.1);
389 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
390 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
391
392 uint8_t b[100];
393 OH_AVFormat_SetBuffer(trackFormat, OH_MD_KEY_CODEC_MIME, b, 100);
394 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
395 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
396
397 muxerDemo->NativeDestroy(handle);
398 OH_AVFormat_Destroy(trackFormat);
399 handle = nullptr;
400 delete muxerDemo;
401 }
402
403 /**
404 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_008
405 * @tc.name : OH_AVMuxer_AddTrack - video trackFormat(OH_MD_KEY_WIDTH) check
406 * @tc.desc : param check test
407 */
408 HWTEST_F(NativeAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_008, TestSize.Level2)
409 {
410 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
411 OH_AVOutputFormat format = AV_OUTPUT_FORMAT_MPEG_4;
412 int32_t fd = muxerDemo->getFdByMode(format);
413 OH_AVMuxer *handle = muxerDemo->NativeCreate(fd, format);
414 ASSERT_NE(nullptr, handle);
415
416 uint8_t a[CODEC_CONFIG];
417
418 OH_AVFormat *trackFormat = OH_AVFormat_Create();
419 OH_AVFormat_SetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_VIDEO_AVC);
420 OH_AVFormat_SetLongValue(trackFormat, OH_MD_KEY_BITRATE, 524569);
421 OH_AVFormat_SetBuffer(trackFormat, OH_MD_KEY_CODEC_CONFIG, a, CODEC_CONFIG);
422 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_PIXEL_FORMAT, AV_PIX_FMT_YUV420P);
423 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_WIDTH, WIDTH);
424 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_HEIGHT, HEIGHT);
425 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_FRAME_RATE, FRAME_RATE);
426 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_PROFILE, PROFILE);
427
428 int32_t trackId;
429
430 OH_AVErrCode ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
431 ASSERT_EQ(0, trackId);
432
433 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_WIDTH, -1);
434 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
435 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
436
437 OH_AVFormat_SetStringValue(trackFormat, OH_MD_KEY_WIDTH, "aaa");
438 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
439 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
440
441 OH_AVFormat_SetLongValue(trackFormat, OH_MD_KEY_WIDTH, 0);
442 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
443 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
444
445 OH_AVFormat_SetFloatValue(trackFormat, OH_MD_KEY_WIDTH, 0.1);
446 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
447 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
448
449 OH_AVFormat_SetDoubleValue(trackFormat, OH_MD_KEY_WIDTH, 0.1);
450 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
451 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
452
453 uint8_t b[100];
454 OH_AVFormat_SetBuffer(trackFormat, OH_MD_KEY_WIDTH, b, 100);
455 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
456 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
457
458 muxerDemo->NativeDestroy(handle);
459 OH_AVFormat_Destroy(trackFormat);
460 handle = nullptr;
461 delete muxerDemo;
462 }
463
464 /**
465 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_009
466 * @tc.name : OH_AVMuxer_AddTrack - video trackFormat(OH_MD_KEY_HEIGHT) check
467 * @tc.desc : param check test
468 */
469 HWTEST_F(NativeAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_009, TestSize.Level2)
470 {
471 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
472 OH_AVOutputFormat format = AV_OUTPUT_FORMAT_MPEG_4;
473 int32_t fd = muxerDemo->getFdByMode(format);
474 OH_AVMuxer *handle = muxerDemo->NativeCreate(fd, format);
475 ASSERT_NE(nullptr, handle);
476
477 uint8_t a[CODEC_CONFIG];
478
479 OH_AVFormat *trackFormat = OH_AVFormat_Create();
480 OH_AVFormat_SetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_VIDEO_AVC);
481 OH_AVFormat_SetLongValue(trackFormat, OH_MD_KEY_BITRATE, 524569);
482 OH_AVFormat_SetBuffer(trackFormat, OH_MD_KEY_CODEC_CONFIG, a, CODEC_CONFIG);
483 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_PIXEL_FORMAT, AV_PIX_FMT_YUV420P);
484 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_WIDTH, WIDTH);
485 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_HEIGHT, HEIGHT);
486 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_FRAME_RATE, FRAME_RATE);
487 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_PROFILE, PROFILE);
488
489 int32_t trackId;
490
491 OH_AVErrCode ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
492 ASSERT_EQ(0, trackId);
493
494 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_HEIGHT, -1);
495 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
496 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
497
498 OH_AVFormat_SetStringValue(trackFormat, OH_MD_KEY_HEIGHT, "aaa");
499 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
500 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
501
502 OH_AVFormat_SetLongValue(trackFormat, OH_MD_KEY_HEIGHT, 0);
503 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
504 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
505
506 OH_AVFormat_SetFloatValue(trackFormat, OH_MD_KEY_HEIGHT, 0.1);
507 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
508 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
509
510 OH_AVFormat_SetDoubleValue(trackFormat, OH_MD_KEY_HEIGHT, 0.1);
511 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
512 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
513
514 uint8_t b[100];
515 OH_AVFormat_SetBuffer(trackFormat, OH_MD_KEY_HEIGHT, b, 100);
516 ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
517 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
518
519 muxerDemo->NativeDestroy(handle);
520 OH_AVFormat_Destroy(trackFormat);
521 handle = nullptr;
522 delete muxerDemo;
523 }
524
525 /**
526 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_010
527 * @tc.name : OH_AVMuxer_AddTrack - trackFormat(any key) check
528 * @tc.desc : param check test
529 */
530 HWTEST_F(NativeAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_010, TestSize.Level2)
531 {
532 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
533 OH_AVOutputFormat format = AV_OUTPUT_FORMAT_MPEG_4;
534 int32_t fd = muxerDemo->getFdByMode(format);
535 OH_AVMuxer *handle = muxerDemo->NativeCreate(fd, format);
536 ASSERT_NE(nullptr, handle);
537
538 OH_AVFormat *trackFormat = OH_AVFormat_Create();
539 OH_AVFormat_SetStringValue(trackFormat, "aaaaa", "bbbbb");
540
541 int32_t trackId;
542
543 OH_AVErrCode ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
544 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
545
546 muxerDemo->NativeDestroy(handle);
547 OH_AVFormat_Destroy(trackFormat);
548 handle = nullptr;
549 delete muxerDemo;
550 }
551
552 /**
553 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_011
554 * @tc.name : OH_AVMuxer_WriteSampleBuffer - trackIndex check
555 * @tc.desc : param check test
556 */
557 HWTEST_F(NativeAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_011, TestSize.Level2)
558 {
559 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
560 OH_AVOutputFormat format = AV_OUTPUT_FORMAT_MPEG_4;
561 int32_t fd = muxerDemo->getFdByMode(format);
562 OH_AVMuxer *handle = muxerDemo->NativeCreate(fd, format);
563 ASSERT_NE(nullptr, handle);
564
565 uint8_t a[CODEC_CONFIG];
566
567 OH_AVFormat *trackFormat = OH_AVFormat_Create();
568 OH_AVFormat_SetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_AUDIO_AAC);
569 OH_AVFormat_SetLongValue(trackFormat, OH_MD_KEY_BITRATE, AUDIO_BITRATE);
570 OH_AVFormat_SetBuffer(trackFormat, OH_MD_KEY_CODEC_CONFIG, a, CODEC_CONFIG);
571 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AV_SAMPLE_FMT_S16);
572 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, CHANNEL_COUNT);
573 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, SAMPLE_RATE);
574 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_PROFILE, PROFILE);
575
576 int32_t trackId;
577
578 OH_AVErrCode ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
579 ASSERT_EQ(0, trackId);
580
581 ret = muxerDemo->NativeStart(handle);
582 ASSERT_EQ(AV_ERR_OK, ret);
583
584 OH_AVMemory *avMemBuffer = OH_AVMemory_Create(INFO_SIZE);
585
586 OH_AVCodecBufferAttr info;
587 info.pts = 0;
588 info.size = INFO_SIZE;
589 info.offset = 0;
590 info.flags = 0;
591
592 ret = muxerDemo->NativeWriteSampleBuffer(handle, trackId, avMemBuffer, info);
593 ASSERT_EQ(AV_ERR_OK, ret);
594
595 trackId = -1;
596 ret = muxerDemo->NativeWriteSampleBuffer(handle, trackId, avMemBuffer, info);
597 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
598
599 muxerDemo->NativeDestroy(handle);
600 OH_AVFormat_Destroy(trackFormat);
601 handle = nullptr;
602 delete muxerDemo;
603 }
604
605 /**
606 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_012
607 * @tc.name : OH_AVMuxer_WriteSampleBuffer - info.pts check
608 * @tc.desc : param check test
609 */
610 HWTEST_F(NativeAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_012, TestSize.Level2)
611 {
612 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
613 OH_AVOutputFormat format = AV_OUTPUT_FORMAT_MPEG_4;
614 int32_t fd = muxerDemo->getFdByMode(format);
615 OH_AVMuxer *handle = muxerDemo->NativeCreate(fd, format);
616 ASSERT_NE(nullptr, handle);
617
618 uint8_t a[CODEC_CONFIG];
619
620 OH_AVFormat *trackFormat = OH_AVFormat_Create();
621 OH_AVFormat_SetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_AUDIO_AAC);
622 OH_AVFormat_SetLongValue(trackFormat, OH_MD_KEY_BITRATE, AUDIO_BITRATE);
623 OH_AVFormat_SetBuffer(trackFormat, OH_MD_KEY_CODEC_CONFIG, a, CODEC_CONFIG);
624 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AV_SAMPLE_FMT_S16);
625 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, CHANNEL_COUNT);
626 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, SAMPLE_RATE);
627 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_PROFILE, PROFILE);
628
629 int32_t trackId;
630
631 OH_AVErrCode ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
632 ASSERT_EQ(0, trackId);
633
634 ret = muxerDemo->NativeStart(handle);
635 ASSERT_EQ(AV_ERR_OK, ret);
636
637 OH_AVMemory *avMemBuffer = OH_AVMemory_Create(INFO_SIZE);
638
639 OH_AVCodecBufferAttr info;
640 info.pts = 0;
641 info.size = INFO_SIZE;
642 info.offset = 0;
643 info.flags = 0;
644
645 ret = muxerDemo->NativeWriteSampleBuffer(handle, trackId, avMemBuffer, info);
646 ASSERT_EQ(AV_ERR_OK, ret);
647
648 info.pts = -1;
649 ret = muxerDemo->NativeWriteSampleBuffer(handle, trackId, avMemBuffer, info);
650 ASSERT_EQ(AV_ERR_OK, ret);
651
652 muxerDemo->NativeDestroy(handle);
653 OH_AVFormat_Destroy(trackFormat);
654 handle = nullptr;
655 delete muxerDemo;
656 }
657
658 /**
659 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_013
660 * @tc.name : OH_AVMuxer_WriteSampleBuffer - info.size check
661 * @tc.desc : param check test
662 */
663 HWTEST_F(NativeAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_013, TestSize.Level2)
664 {
665 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
666 OH_AVOutputFormat format = AV_OUTPUT_FORMAT_MPEG_4;
667 int32_t fd = muxerDemo->getFdByMode(format);
668 OH_AVMuxer *handle = muxerDemo->NativeCreate(fd, format);
669 ASSERT_NE(nullptr, handle);
670
671 uint8_t a[CODEC_CONFIG];
672
673 OH_AVFormat *trackFormat = OH_AVFormat_Create();
674 OH_AVFormat_SetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_AUDIO_AAC);
675 OH_AVFormat_SetLongValue(trackFormat, OH_MD_KEY_BITRATE, AUDIO_BITRATE);
676 OH_AVFormat_SetBuffer(trackFormat, OH_MD_KEY_CODEC_CONFIG, a, CODEC_CONFIG);
677 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AV_SAMPLE_FMT_S16);
678 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, CHANNEL_COUNT);
679 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, SAMPLE_RATE);
680 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_PROFILE, PROFILE);
681
682 int32_t trackId;
683
684 OH_AVErrCode ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
685 ASSERT_EQ(0, trackId);
686
687 ret = muxerDemo->NativeStart(handle);
688 ASSERT_EQ(AV_ERR_OK, ret);
689
690 OH_AVMemory *avMemBuffer = OH_AVMemory_Create(INFO_SIZE);
691
692 OH_AVCodecBufferAttr info;
693 info.pts = 0;
694 info.size = INFO_SIZE;
695 info.offset = 0;
696 info.flags = 0;
697
698 ret = muxerDemo->NativeWriteSampleBuffer(handle, trackId, avMemBuffer, info);
699 ASSERT_EQ(AV_ERR_OK, ret);
700
701 info.size = -1;
702 ret = muxerDemo->NativeWriteSampleBuffer(handle, trackId, avMemBuffer, info);
703 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
704
705 muxerDemo->NativeDestroy(handle);
706 OH_AVFormat_Destroy(trackFormat);
707 handle = nullptr;
708 delete muxerDemo;
709 }
710
711 /**
712 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_014
713 * @tc.name : OH_AVMuxer_WriteSampleBuffer - info.offset check
714 * @tc.desc : param check test
715 */
716 HWTEST_F(NativeAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_014, TestSize.Level2)
717 {
718 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
719 OH_AVOutputFormat format = AV_OUTPUT_FORMAT_MPEG_4;
720 int32_t fd = muxerDemo->getFdByMode(format);
721 OH_AVMuxer *handle = muxerDemo->NativeCreate(fd, format);
722 ASSERT_NE(nullptr, handle);
723
724 uint8_t a[CODEC_CONFIG];
725
726 OH_AVFormat *trackFormat = OH_AVFormat_Create();
727 OH_AVFormat_SetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_AUDIO_AAC);
728 OH_AVFormat_SetLongValue(trackFormat, OH_MD_KEY_BITRATE, AUDIO_BITRATE);
729 OH_AVFormat_SetBuffer(trackFormat, OH_MD_KEY_CODEC_CONFIG, a, CODEC_CONFIG);
730 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AV_SAMPLE_FMT_S16);
731 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, CHANNEL_COUNT);
732 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, SAMPLE_RATE);
733 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_PROFILE, PROFILE);
734
735 int32_t trackId;
736
737 OH_AVErrCode ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
738 ASSERT_EQ(0, trackId);
739
740 ret = muxerDemo->NativeStart(handle);
741 ASSERT_EQ(AV_ERR_OK, ret);
742
743 OH_AVMemory *avMemBuffer = OH_AVMemory_Create(INFO_SIZE);
744
745 OH_AVCodecBufferAttr info;
746 info.pts = 0;
747 info.size = INFO_SIZE;
748 info.offset = 0;
749 info.flags = 0;
750
751 ret = muxerDemo->NativeWriteSampleBuffer(handle, trackId, avMemBuffer, info);
752 ASSERT_EQ(AV_ERR_OK, ret);
753
754 info.offset = -1;
755 ret = muxerDemo->NativeWriteSampleBuffer(handle, trackId, avMemBuffer, info);
756 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
757
758 OH_AVMemory_Destroy(avMemBuffer);
759 muxerDemo->NativeDestroy(handle);
760 OH_AVFormat_Destroy(trackFormat);
761 handle = nullptr;
762 delete muxerDemo;
763 }
764
765 /**
766 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_015
767 * @tc.name : OH_AVMuxer_WriteSampleBuffer - info.flags check
768 * @tc.desc : param check test
769 */
770 HWTEST_F(NativeAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_015, TestSize.Level2)
771 {
772 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
773 OH_AVOutputFormat format = AV_OUTPUT_FORMAT_MPEG_4;
774 int32_t fd = muxerDemo->getFdByMode(format);
775 OH_AVMuxer *handle = muxerDemo->NativeCreate(fd, format);
776 ASSERT_NE(nullptr, handle);
777
778 uint8_t a[CODEC_CONFIG];
779
780 OH_AVFormat *trackFormat = OH_AVFormat_Create();
781 OH_AVFormat_SetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_AUDIO_AAC);
782 OH_AVFormat_SetLongValue(trackFormat, OH_MD_KEY_BITRATE, AUDIO_BITRATE);
783 OH_AVFormat_SetBuffer(trackFormat, OH_MD_KEY_CODEC_CONFIG, a, CODEC_CONFIG);
784 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AV_SAMPLE_FMT_S16);
785 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, CHANNEL_COUNT);
786 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, SAMPLE_RATE);
787 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_PROFILE, PROFILE);
788
789 int32_t trackId;
790
791 OH_AVErrCode ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
792 ASSERT_EQ(0, trackId);
793
794 ret = muxerDemo->NativeStart(handle);
795 ASSERT_EQ(AV_ERR_OK, ret);
796
797 OH_AVMemory *avMemBuffer = OH_AVMemory_Create(INFO_SIZE);
798
799 OH_AVCodecBufferAttr info;
800 info.pts = 0;
801 info.size = INFO_SIZE;
802 info.offset = 0;
803 info.flags = 0;
804
805 ret = muxerDemo->NativeWriteSampleBuffer(handle, trackId, avMemBuffer, info);
806 ASSERT_EQ(AV_ERR_OK, ret);
807
808 info.flags = -1;
809 ret = muxerDemo->NativeWriteSampleBuffer(handle, trackId, avMemBuffer, info);
810 ASSERT_EQ(AV_ERR_OK, ret);
811
812 OH_AVMemory_Destroy(avMemBuffer);
813 muxerDemo->NativeDestroy(handle);
814 OH_AVFormat_Destroy(trackFormat);
815 handle = nullptr;
816 delete muxerDemo;
817 }
818
819 /**
820 * @tc.number : SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_016
821 * @tc.name : OH_AVMuxer_WriteSampleBuffer - sample check
822 * @tc.desc : param check test
823 */
824 HWTEST_F(NativeAVMuxerParamCheckTest, SUB_MULTIMEDIA_MEDIA_MUXER_PARAM_CHECK_016, TestSize.Level2)
825 {
826 AVMuxerDemo *muxerDemo = new AVMuxerDemo();
827 OH_AVOutputFormat format = AV_OUTPUT_FORMAT_MPEG_4;
828 int32_t fd = muxerDemo->getFdByMode(format);
829 OH_AVMuxer *handle = muxerDemo->NativeCreate(fd, format);
830 ASSERT_NE(nullptr, handle);
831
832 uint8_t a[CODEC_CONFIG];
833
834 OH_AVFormat *trackFormat = OH_AVFormat_Create();
835 OH_AVFormat_SetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, OH_AVCODEC_MIMETYPE_AUDIO_AAC);
836 OH_AVFormat_SetLongValue(trackFormat, OH_MD_KEY_BITRATE, AUDIO_BITRATE);
837 OH_AVFormat_SetBuffer(trackFormat, OH_MD_KEY_CODEC_CONFIG, a, CODEC_CONFIG);
838 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, AV_SAMPLE_FMT_S16);
839 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, CHANNEL_COUNT);
840 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, SAMPLE_RATE);
841 OH_AVFormat_SetIntValue(trackFormat, OH_MD_KEY_PROFILE, PROFILE);
842
843 int32_t trackId;
844
845 OH_AVErrCode ret = muxerDemo->NativeAddTrack(handle, &trackId, trackFormat);
846 ASSERT_EQ(0, trackId);
847
848 ret = muxerDemo->NativeStart(handle);
849 ASSERT_EQ(AV_ERR_OK, ret);
850
851 OH_AVMemory *avMemBuffer = OH_AVMemory_Create(10);
852
853 OH_AVCodecBufferAttr info;
854 info.pts = 0;
855 info.size = INFO_SIZE;
856 info.offset = 0;
857 info.flags = 0;
858
859 ret = muxerDemo->NativeWriteSampleBuffer(handle, trackId, avMemBuffer, info);
860 ASSERT_EQ(AV_ERR_INVALID_VAL, ret);
861
862 OH_AVMemory_Destroy(avMemBuffer);
863 muxerDemo->NativeDestroy(handle);
864 OH_AVFormat_Destroy(trackFormat);
865 handle = nullptr;
866 delete muxerDemo;
867 }