1 /*
2 * Copyright (C) 2025 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 "gtest/gtest.h"
17
18 #include "native_avcodec_base.h"
19 #include "native_avdemuxer.h"
20 #include "native_avformat.h"
21 #include "native_avsource.h"
22 #include "native_avmemory.h"
23
24 #include <iostream>
25 #include <cstdio>
26 #include <string>
27 #include <fcntl.h>
28 #include <cmath>
29 #include <thread>
30 namespace OHOS {
31 namespace Media {
32 class DemuxerFunc3NdkTest : public testing::Test {
33 public:
34 // SetUpTestCase: Called before all test cases
35 static void SetUpTestCase(void);
36 // TearDownTestCase: Called after all test case
37 static void TearDownTestCase(void);
38 // SetUp: Called before each test cases
39 void SetUp(void);
40 // TearDown: Called after each test cases
41 void TearDown(void);
42 };
43
44 static OH_AVMemory *memory = nullptr;
45 static OH_AVSource *source = nullptr;
46 static OH_AVDemuxer *demuxer = nullptr;
47 static OH_AVFormat *sourceFormat = nullptr;
48 static OH_AVFormat *trackFormat = nullptr;
49 static OH_AVBuffer *avBuffer = nullptr;
50 static OH_AVFormat *format = nullptr;
51 static OH_AVFormat *metaFormat = nullptr;
52 static int32_t g_trackCount;
53 static int32_t g_width = 3840;
54 static int32_t g_height = 2160;
55 constexpr int FLV_AUDIONUM_AAC = 5148;
56 constexpr int FLV_AUDIONUM_HEVC_AAC = 210;
57 constexpr int FLV_VIDEONUM_HEVC_AAC_ALL = 602;
58 constexpr int FLV_AUDIONUM_AVC_AAC = 318;
59 constexpr int32_t GOPNUM = 60;
SetUpTestCase()60 void DemuxerFunc3NdkTest::SetUpTestCase() {}
TearDownTestCase()61 void DemuxerFunc3NdkTest::TearDownTestCase() {}
SetUp()62 void DemuxerFunc3NdkTest::SetUp()
63 {
64 memory = OH_AVMemory_Create(g_width * g_height);
65 g_trackCount = 0;
66 }
TearDown()67 void DemuxerFunc3NdkTest::TearDown()
68 {
69 if (trackFormat != nullptr) {
70 OH_AVFormat_Destroy(trackFormat);
71 trackFormat = nullptr;
72 }
73
74 if (sourceFormat != nullptr) {
75 OH_AVFormat_Destroy(sourceFormat);
76 sourceFormat = nullptr;
77 }
78 if (format != nullptr) {
79 OH_AVFormat_Destroy(format);
80 format = nullptr;
81 }
82
83 if (memory != nullptr) {
84 OH_AVMemory_Destroy(memory);
85 memory = nullptr;
86 }
87 if (source != nullptr) {
88 OH_AVSource_Destroy(source);
89 source = nullptr;
90 }
91 if (demuxer != nullptr) {
92 OH_AVDemuxer_Destroy(demuxer);
93 demuxer = nullptr;
94 }
95 if (avBuffer != nullptr) {
96 OH_AVBuffer_Destroy(avBuffer);
97 avBuffer = nullptr;
98 }
99 if (metaFormat != nullptr) {
100 OH_AVFormat_Destroy(metaFormat);
101 metaFormat = nullptr;
102 }
103 }
104 } // namespace Media
105 } // namespace OHOS
106
107 using namespace std;
108 using namespace OHOS;
109 using namespace OHOS::Media;
110 using namespace testing::ext;
111
GetFileSize(const char * fileName)112 static int64_t GetFileSize(const char *fileName)
113 {
114 int64_t fileSize = 0;
115 if (fileName != nullptr) {
116 struct stat fileStatus {};
117 if (stat(fileName, &fileStatus) == 0) {
118 fileSize = static_cast<int64_t>(fileStatus.st_size);
119 }
120 }
121 return fileSize;
122 }
123
SetAudioValue(OH_AVCodecBufferAttr attr,bool & audioIsEnd,int & audioFrame,int & aKeyCount)124 static void SetAudioValue(OH_AVCodecBufferAttr attr, bool &audioIsEnd, int &audioFrame, int &aKeyCount)
125 {
126 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
127 audioIsEnd = true;
128 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
129 } else {
130 audioFrame++;
131 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
132 aKeyCount++;
133 }
134 }
135 }
136
SetVideoValue(OH_AVCodecBufferAttr attr,bool & videoIsEnd,int & videoFrame,int & vKeyCount)137 static void SetVideoValue(OH_AVCodecBufferAttr attr, bool &videoIsEnd, int &videoFrame, int &vKeyCount)
138 {
139 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
140 videoIsEnd = true;
141 cout << videoFrame << " video is end !!!!!!!!!!!!!!!" << endl;
142 } else {
143 videoFrame++;
144 cout << "video track !!!!!" << endl;
145 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
146 vKeyCount++;
147 }
148 }
149 }
150
InitFile(const char * file,int32_t trackNum,int & fd,bool & initResult)151 static void InitFile(const char *file, int32_t trackNum, int &fd, bool &initResult)
152 {
153 fd = open(file, O_RDONLY);
154 int64_t size = GetFileSize(file);
155 cout << file << "----------------------" << fd << "---------" << size << endl;
156 source = OH_AVSource_CreateWithFD(fd, 0, size);
157 ASSERT_NE(source, nullptr);
158
159 demuxer = OH_AVDemuxer_CreateWithSource(source);
160 ASSERT_NE(demuxer, nullptr);
161
162 sourceFormat = OH_AVSource_GetSourceFormat(source);
163 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
164 ASSERT_EQ(trackNum, g_trackCount);
165 for (int32_t index = 0; index < g_trackCount; index++) {
166 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
167 }
168 avBuffer = OH_AVBuffer_Create(size);
169 ASSERT_NE(avBuffer, nullptr);
170 initResult = true;
171 }
172
CheckVideoSyncFrame(int & vKeyCount,int32_t & gopCount,int32_t & count)173 static bool CheckVideoSyncFrame(int &vKeyCount, int32_t &gopCount, int32_t &count)
174 {
175 if (gopCount % GOPNUM == 0 && vKeyCount == count + 1) {
176 return true;
177 } else if (gopCount % GOPNUM != 0 && vKeyCount == count) {
178 return true;
179 } else {
180 return false;
181 }
182 }
183
CheckVideoFirstSyncFrame(int32_t & gopCount,int & vKeyCount)184 static bool CheckVideoFirstSyncFrame(int32_t &gopCount, int &vKeyCount)
185 {
186 if (gopCount == 0 && vKeyCount == 1) {
187 return true;
188 } else if (gopCount != 0 && vKeyCount == 1) {
189 return true;
190 } else {
191 return false;
192 }
193 }
194 /**
195 * @tc.number : DEMUXER_FUNCTION_FLV_0010
196 * @tc.name : create source with fd, avc+aac gop60 flv
197 * @tc.desc : function test
198 */
199 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_FLV_0010, TestSize.Level0)
200 {
201 int tarckType = 0;
202 bool audioIsEnd = false;
203 bool videoIsEnd = false;
204 int audioFrame = 0;
205 int videoFrame = 0;
206 OH_AVCodecBufferAttr bufferAttr;
207 const char *file = "/data/test/media/avc_aac_60.flv";
208 int fd = 0;
209 bool initResult = false;
210 InitFile(file, 2, fd, initResult);
211 ASSERT_TRUE(initResult);
212 int aKeyCount = 0;
213 int vKeyCount = 0;
214 int32_t gopCount = 0;
215 int32_t count = 0;
216 while (!audioIsEnd || !videoIsEnd) {
217 for (int32_t index = 0; index < g_trackCount; index++) {
218 trackFormat = OH_AVSource_GetTrackFormat(source, index);
219 ASSERT_NE(trackFormat, nullptr);
220 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
221 OH_AVFormat_Destroy(trackFormat);
222 trackFormat = nullptr;
223 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
224 continue;
225 }
226 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
227 ASSERT_NE(avBuffer, nullptr);
228 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
229 if (tarckType == MEDIA_TYPE_AUD) {
230 SetAudioValue(bufferAttr, audioIsEnd, audioFrame, aKeyCount);
231 } else if (tarckType == MEDIA_TYPE_VID) {
232 count = vKeyCount;
233 SetVideoValue(bufferAttr, videoIsEnd, videoFrame, vKeyCount);
234 ASSERT_TRUE(CheckVideoSyncFrame(vKeyCount, gopCount, count));
235 gopCount++;
236 }
237 }
238 }
239 ASSERT_EQ(aKeyCount, FLV_AUDIONUM_AVC_AAC);
240 close(fd);
241 fd = -1;
242 }
243
244 /**
245 * @tc.number : DEMUXER_FUNCTION_FLV_0020
246 * @tc.name : create source with fd, hevc+aac gop1 flv
247 * @tc.desc : function test
248 */
249 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_FLV_0020, TestSize.Level0)
250 {
251 int tarckType = 0;
252 bool audioIsEnd = false;
253 bool videoIsEnd = false;
254 int audioFrame = 0;
255 int videoFrame = 0;
256 OH_AVCodecBufferAttr bufferAttr;
257 const char *file = "/data/test/media/hevc_aac_1.flv";
258 int fd = 0;
259 bool initResult = false;
260 InitFile(file, 2, fd, initResult);
261 ASSERT_TRUE(initResult);
262 int aKeyCount = 0;
263 int vKeyCount = 0;
264 while (!audioIsEnd || !videoIsEnd) {
265 for (int32_t index = 0; index < g_trackCount; index++) {
266 trackFormat = OH_AVSource_GetTrackFormat(source, index);
267 ASSERT_NE(trackFormat, nullptr);
268 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
269 OH_AVFormat_Destroy(trackFormat);
270 trackFormat = nullptr;
271 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
272 continue;
273 }
274 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
275 ASSERT_NE(avBuffer, nullptr);
276 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
277 if (tarckType == MEDIA_TYPE_AUD) {
278 SetAudioValue(bufferAttr, audioIsEnd, audioFrame, aKeyCount);
279 } else if (tarckType == MEDIA_TYPE_VID) {
280 SetVideoValue(bufferAttr, videoIsEnd, videoFrame, vKeyCount);
281 }
282 }
283 }
284 ASSERT_EQ(aKeyCount, FLV_AUDIONUM_HEVC_AAC);
285 ASSERT_EQ(vKeyCount, FLV_VIDEONUM_HEVC_AAC_ALL);
286 close(fd);
287 fd = -1;
288 }
289
290 /**
291 * @tc.number : DEMUXER_FUNCTION_FLV_0030
292 * @tc.name : create source with fd, hevc+aac gop-1 flv
293 * @tc.desc : function test
294 */
295 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_FLV_0030, TestSize.Level0)
296 {
297 int tarckType = 0;
298 bool audioIsEnd = false;
299 bool videoIsEnd = false;
300 int audioFrame = 0;
301 int videoFrame = 0;
302 OH_AVCodecBufferAttr bufferAttr;
303 const char *file = "/data/test/media/hevc_aac_first.flv";
304 int fd = 0;
305 bool initResult = false;
306 InitFile(file, 2, fd, initResult);
307 ASSERT_TRUE(initResult);
308 int aKeyCount = 0;
309 int vKeyCount = 0;
310 int32_t gopCount = 0;
311 while (!audioIsEnd || !videoIsEnd) {
312 for (int32_t index = 0; index < g_trackCount; index++) {
313 trackFormat = OH_AVSource_GetTrackFormat(source, index);
314 ASSERT_NE(trackFormat, nullptr);
315 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
316 OH_AVFormat_Destroy(trackFormat);
317 trackFormat = nullptr;
318 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
319 continue;
320 }
321 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
322 ASSERT_NE(avBuffer, nullptr);
323 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
324 if (tarckType == MEDIA_TYPE_AUD) {
325 SetAudioValue(bufferAttr, audioIsEnd, audioFrame, aKeyCount);
326 } else if (tarckType == MEDIA_TYPE_VID) {
327 SetVideoValue(bufferAttr, videoIsEnd, videoFrame, vKeyCount);
328 ASSERT_TRUE(CheckVideoFirstSyncFrame(gopCount, vKeyCount));
329 gopCount++;
330 }
331 }
332 }
333 ASSERT_EQ(aKeyCount, FLV_AUDIONUM_HEVC_AAC);
334 ASSERT_EQ(vKeyCount, 1);
335 close(fd);
336 fd = -1;
337 }
338
339 /**
340 * @tc.number : DEMUXER_FUNCTION_FLV_0040
341 * @tc.name : create source with fd, avc gop60 flv
342 * @tc.desc : function test
343 */
344 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_FLV_0040, TestSize.Level2)
345 {
346 int tarckType = 0;
347 OH_AVCodecBufferAttr bufferAttr;
348 bool videoIsEnd = false;
349 int videoFrame = 0;
350 const char *file = "/data/test/media/avc_60.flv";
351 int fd = 0;
352 bool initResult = false;
353 InitFile(file, 1, fd, initResult);
354 ASSERT_TRUE(initResult);
355 int vKeyCount = 0;
356 int32_t gopCount = 0;
357 int32_t count = 0;
358 while (!videoIsEnd) {
359 for (int32_t index = 0; index < g_trackCount; index++) {
360 trackFormat = OH_AVSource_GetTrackFormat(source, index);
361 ASSERT_NE(trackFormat, nullptr);
362 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
363 OH_AVFormat_Destroy(trackFormat);
364 trackFormat = nullptr;
365 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
366 ASSERT_NE(avBuffer, nullptr);
367 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
368 if (tarckType == MEDIA_TYPE_VID) {
369 count = vKeyCount;
370 SetVideoValue(bufferAttr, videoIsEnd, videoFrame, vKeyCount);
371 ASSERT_TRUE(CheckVideoSyncFrame(vKeyCount, gopCount, count));
372 gopCount++;
373 }
374 }
375 }
376 close(fd);
377 fd = -1;
378 }
379
380 /**
381 * @tc.number : DEMUXER_FUNCTION_FLV_0050
382 * @tc.name : create source with fd, aac flv
383 * @tc.desc : function test
384 */
385 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_FLV_0050, TestSize.Level2)
386 {
387 int tarckType = 0;
388 bool audioIsEnd = false;
389 int audioFrame = 0;
390 OH_AVCodecBufferAttr bufferAttr;
391 const char *file = "/data/test/media/only_aac.flv";
392 int fd = 0;
393 bool initResult = false;
394 InitFile(file, 1, fd, initResult);
395 ASSERT_TRUE(initResult);
396 int aKeyCount = 0;
397 while (!audioIsEnd) {
398 for (int32_t index = 0; index < g_trackCount; index++) {
399 trackFormat = OH_AVSource_GetTrackFormat(source, index);
400 ASSERT_NE(trackFormat, nullptr);
401 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
402 OH_AVFormat_Destroy(trackFormat);
403 trackFormat = nullptr;
404 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
405 ASSERT_NE(avBuffer, nullptr);
406 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
407 if (tarckType == MEDIA_TYPE_AUD) {
408 SetAudioValue(bufferAttr, audioIsEnd, audioFrame, aKeyCount);
409 }
410 }
411 }
412 ASSERT_EQ(aKeyCount, FLV_AUDIONUM_AAC);
413 close(fd);
414 fd = -1;
415 }
416
417 /**
418 * @tc.number : DEMUXER_FUNCTION_FLV_0060
419 * @tc.name : create source with fd, aac_h264.flv
420 * @tc.desc : function test
421 */
422 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_FLV_0060, TestSize.Level0)
423 {
424 int tarckType = 0;
425 bool audioIsEnd = false;
426 bool videoIsEnd = false;
427 int audioFrame = 0;
428 int videoFrame = 0;
429 OH_AVCodecBufferAttr bufferAttr;
430 const char *file = "/data/test/media/aac_h264.flv";
431 int fd = 0;
432 bool initResult = false;
433 InitFile(file, 2, fd, initResult);
434 ASSERT_TRUE(initResult);
435 int aKeyCount = 0;
436 int vKeyCount = 0;
437 while (!audioIsEnd || !videoIsEnd) {
438 for (int32_t index = 0; index < g_trackCount; index++) {
439 trackFormat = OH_AVSource_GetTrackFormat(source, index);
440 ASSERT_NE(trackFormat, nullptr);
441 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
442 OH_AVFormat_Destroy(trackFormat);
443 trackFormat = nullptr;
444 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
445 continue;
446 }
447 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
448 ASSERT_NE(avBuffer, nullptr);
449 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
450 if (tarckType == MEDIA_TYPE_AUD) {
451 SetAudioValue(bufferAttr, audioIsEnd, audioFrame, aKeyCount);
452 } else if (tarckType == MEDIA_TYPE_VID) {
453 SetVideoValue(bufferAttr, videoIsEnd, videoFrame, vKeyCount);
454 }
455 }
456 }
457 ASSERT_EQ(aKeyCount, 528);
458 ASSERT_EQ(vKeyCount, 2);
459 close(fd);
460 fd = -1;
461 }
462
463 /**
464 * @tc.number : DEMUXER_FUNCTION_FLV_0070
465 * @tc.name : create source with fd, aac_h265.flv
466 * @tc.desc : function test
467 */
468 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_FLV_0070, TestSize.Level0)
469 {
470 int tarckType = 0;
471 bool audioIsEnd = false;
472 bool videoIsEnd = false;
473 int audioFrame = 0;
474 int videoFrame = 0;
475 OH_AVCodecBufferAttr bufferAttr;
476 const char *file = "/data/test/media/aac_h265.flv";
477 int fd = 0;
478 bool initResult = false;
479 InitFile(file, 2, fd, initResult);
480 ASSERT_TRUE(initResult);
481 int aKeyCount = 0;
482 int vKeyCount = 0;
483 while (!audioIsEnd || !videoIsEnd) {
484 for (int32_t index = 0; index < g_trackCount; index++) {
485 trackFormat = OH_AVSource_GetTrackFormat(source, index);
486 ASSERT_NE(trackFormat, nullptr);
487 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
488 OH_AVFormat_Destroy(trackFormat);
489 trackFormat = nullptr;
490 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
491 continue;
492 }
493 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
494 ASSERT_NE(avBuffer, nullptr);
495 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
496 if (tarckType == MEDIA_TYPE_AUD) {
497 SetAudioValue(bufferAttr, audioIsEnd, audioFrame, aKeyCount);
498 } else if (tarckType == MEDIA_TYPE_VID) {
499 SetVideoValue(bufferAttr, videoIsEnd, videoFrame, vKeyCount);
500 }
501 }
502 }
503 ASSERT_EQ(aKeyCount, 526);
504 ASSERT_EQ(vKeyCount, 2);
505 close(fd);
506 fd = -1;
507 }
508
509 /**
510 * @tc.number : DEMUXER_META_0010
511 * @tc.name : demuxer meta info, get value with right key
512 * @tc.desc : function test
513 */
514 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_META_0010, TestSize.Level1)
515 {
516 int32_t metaIntValue = 0;
517 const char *file = "/data/test/media/metaIntval.mp4";
518 int fd = open(file, O_RDONLY);
519 int64_t size = GetFileSize(file);
520 cout << file << "----------------------" << fd << "---------" << size << endl;
521 source = OH_AVSource_CreateWithFD(fd, 0, size);
522 ASSERT_NE(source, nullptr);
523 metaFormat= OH_AVSource_GetCustomMetadataFormat(source);
524 ASSERT_NE(metaFormat, nullptr);
525 int32_t metaNum = 101010101;
526 ASSERT_TRUE(OH_AVFormat_GetIntValue(metaFormat, "com.openharmony.intval.intvalintval", &metaIntValue));
527 ASSERT_EQ(metaIntValue, metaNum);
528 close(fd);
529 fd = -1;
530 }
531
532 /**
533 * @tc.number : DEMUXER_META_0020
534 * @tc.name : demuxer meta info, get value with right key
535 * @tc.desc : function test
536 */
537 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_META_0020, TestSize.Level1)
538 {
539 float metaFloatValue = 0.0;
540 const char *file = "/data/test/media/metaFloatval.mp4";
541 int fd = open(file, O_RDONLY);
542 int64_t size = GetFileSize(file);
543 cout << file << "----------------------" << fd << "---------" << size << endl;
544 source = OH_AVSource_CreateWithFD(fd, 0, size);
545 ASSERT_NE(source, nullptr);
546 metaFormat= OH_AVSource_GetCustomMetadataFormat(source);
547 ASSERT_NE(metaFormat, nullptr);
548 float metaFloatVal = 2.3;
549 ASSERT_TRUE(OH_AVFormat_GetFloatValue(metaFormat, "com.openharmony.floatval.aaa", &metaFloatValue));
550 ASSERT_EQ(metaFloatValue, metaFloatVal);
551 metaFloatVal = 25.3;
552 ASSERT_TRUE(OH_AVFormat_GetFloatValue(metaFormat, "com.openharmony.floatval.bbb", &metaFloatValue));
553 ASSERT_EQ(metaFloatValue, metaFloatVal);
554 metaFloatVal = 252.3;
555 ASSERT_TRUE(OH_AVFormat_GetFloatValue(metaFormat, "com.openharmony.floatval.ccc", &metaFloatValue));
556 ASSERT_EQ(metaFloatValue, metaFloatVal);
557 metaFloatVal = 2525.3;
558 ASSERT_TRUE(OH_AVFormat_GetFloatValue(metaFormat, "com.openharmony.floatval.ddd", &metaFloatValue));
559 ASSERT_EQ(metaFloatValue, metaFloatVal);
560 metaFloatVal = 25252.3;
561 ASSERT_TRUE(OH_AVFormat_GetFloatValue(metaFormat, "com.openharmony.floatval.eee", &metaFloatValue));
562 ASSERT_EQ(metaFloatValue, metaFloatVal);
563 close(fd);
564 fd = -1;
565 }
566 /**
567 * @tc.number : DEMUXER_META_0030
568 * @tc.name : demuxer meta info, get value with right key
569 * @tc.desc : function test
570 */
571 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_META_0030, TestSize.Level1)
572 {
573 const char *file = "/data/test/media/metaStringval.mp4";
574 int fd = open(file, O_RDONLY);
575 int64_t size = GetFileSize(file);
576 cout << file << "----------------------" << fd << "---------" << size << endl;
577 source = OH_AVSource_CreateWithFD(fd, 0, size);
578 ASSERT_NE(source, nullptr);
579 metaFormat= OH_AVSource_GetCustomMetadataFormat(source);
580 ASSERT_NE(metaFormat, nullptr);
581 const char* metaStringValue = nullptr;
582 string metaKeyAdd = "aba";
583 string metaKey = "com.openharmony.stringval.";
584 string metaVal = "aaaaa";
585 string metaValAdd = "b";
586 for (int i = 0; i < 100; i++) {
587 metaKey.append(metaKeyAdd);
588 metaVal.append(metaValAdd);
589 ASSERT_TRUE(OH_AVFormat_GetStringValue(metaFormat, metaKey.c_str(), &metaStringValue));
590 ASSERT_EQ(metaStringValue, metaVal);
591 }
592 close(fd);
593 fd = -1;
594 }
595 /**
596 * @tc.number : DEMUXER_META_0040
597 * @tc.name : demuxer meta info, get value with right key
598 * @tc.desc : function test
599 */
600 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_META_0040, TestSize.Level2)
601 {
602 const char* metaStringValue = nullptr;
603 int32_t metaIntValue = 0;
604 float metaFloatValue = 0.0;
605 const char *file = "/data/test/media/metaAlltype.mp4";
606 int fd = open(file, O_RDONLY);
607 int64_t size = GetFileSize(file);
608 cout << file << "----------------------" << fd << "---------" << size << endl;
609 source = OH_AVSource_CreateWithFD(fd, 0, size);
610 ASSERT_NE(source, nullptr);
611 metaFormat= OH_AVSource_GetCustomMetadataFormat(source);
612 ASSERT_NE(metaFormat, nullptr);
613 string metaKeyAdd = "a";
614 string metaKey = "com.openharmony.stringval.";
615 string metaVal = "aaaaa";
616 string metaValAdd = "b";
617 for (int i = 0; i < 50; i++) {
618 metaKey.append(metaKeyAdd);
619 metaVal.append(metaValAdd);
620 ASSERT_TRUE(OH_AVFormat_GetStringValue(metaFormat, metaKey.c_str(), &metaStringValue));
621 ASSERT_EQ(metaStringValue, metaVal);
622 }
623
624 metaKeyAdd = "a";
625 metaKey = "com.openharmony.floatval.";
626 float metaFloatVal = 123.5;
627 for (int i = 0; i < 50; i++) {
628 metaKey.append(metaKeyAdd);
629 metaFloatVal = metaFloatVal + 2;
630 ASSERT_TRUE(OH_AVFormat_GetFloatValue(metaFormat, metaKey.c_str(), &metaFloatValue));
631 ASSERT_EQ(metaFloatValue, metaFloatVal);
632 }
633 metaKeyAdd = "a";
634 metaKey = "com.openharmony.Intval.";
635 int32_t metaIntVal = 123;
636 for (int i = 0; i < 50; i++) {
637 metaKey.append(metaKeyAdd);
638 metaIntVal = metaIntVal + 2;
639 ASSERT_TRUE(OH_AVFormat_GetIntValue(metaFormat, metaKey.c_str(), &metaIntValue));
640 ASSERT_EQ(metaIntValue, metaIntVal);
641 }
642 close(fd);
643 fd = -1;
644 }
645 /**
646 * @tc.number : DEMUXER_META_0050
647 * @tc.name : demuxer meta info, get value with error key
648 * @tc.desc : function test
649 */
650 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_META_0050, TestSize.Level2)
651 {
652 const char* metaStringValue = nullptr;
653 int32_t metaIntValue = 0;
654 float metaFloatValue = 0.0;
655 const char *file = "/data/test/media/metaAlltype.mp4";
656 int fd = open(file, O_RDONLY);
657 int64_t size = GetFileSize(file);
658 cout << file << "----------------------" << fd << "---------" << size << endl;
659 source = OH_AVSource_CreateWithFD(fd, 0, size);
660 ASSERT_NE(source, nullptr);
661 metaFormat= OH_AVSource_GetCustomMetadataFormat(source);
662 ASSERT_NE(metaFormat, nullptr);
663 ASSERT_FALSE(OH_AVFormat_GetStringValue(metaFormat, "com.openharmony.stringval.abb", &metaStringValue));
664 ASSERT_FALSE(OH_AVFormat_GetIntValue(metaFormat, "com.openharmony.intnum.abb", &metaIntValue));
665 ASSERT_FALSE(OH_AVFormat_GetFloatValue(metaFormat, "com.openharmony.floatval.abb", &metaFloatValue));
666 close(fd);
667 fd = -1;
668 }
669
670 /**
671 * @tc.number : DEMUXER_META_0060
672 * @tc.name : demuxer meta info, get value with error key type
673 * @tc.desc : function test
674 */
675 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_META_0060, TestSize.Level2)
676 {
677 const char* metaStringValue = nullptr;
678 int32_t metaIntValue = 0;
679 float metaFloatValue = 0.0;
680 const char *file = "/data/test/media/metaAlltype.mp4";
681 int fd = open(file, O_RDONLY);
682 int64_t size = GetFileSize(file);
683 cout << file << "----------------------" << fd << "---------" << size << endl;
684 source = OH_AVSource_CreateWithFD(fd, 0, size);
685 ASSERT_NE(source, nullptr);
686 metaFormat= OH_AVSource_GetCustomMetadataFormat(source);
687 ASSERT_NE(metaFormat, nullptr);
688 ASSERT_FALSE(OH_AVFormat_GetStringValue(metaFormat, "com.openharmony.floatval.a", &metaStringValue));
689 ASSERT_FALSE(OH_AVFormat_GetIntValue(metaFormat, "com.openharmony.stringval.a", &metaIntValue));
690 ASSERT_FALSE(OH_AVFormat_GetFloatValue(metaFormat, "com.openharmony.intnum.a", &metaFloatValue));
691 close(fd);
692 fd = -1;
693 }
694
695 /**
696 * @tc.number : DEMUXER_META_0070
697 * @tc.name : demuxer meta info, file with no meta
698 * @tc.desc : function test
699 */
700 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_META_0070, TestSize.Level2)
701 {
702 const char *file = "/data/test/media/m4v_fmp4.mp4";
703 int fd = open(file, O_RDONLY);
704 int64_t size = GetFileSize(file);
705 cout << file << "----------------------" << fd << "---------" << size << endl;
706 source = OH_AVSource_CreateWithFD(fd, 0, size);
707 ASSERT_NE(source, nullptr);
708 metaFormat= OH_AVSource_GetCustomMetadataFormat(source);
709 ASSERT_NE(metaFormat, nullptr);
710 const char* language = OH_AVFormat_DumpInfo(metaFormat);
711 ASSERT_EQ(language, nullptr);
712 close(fd);
713 fd = -1;
714 }
715
716 /**
717 * @tc.number : DEMUXER_META_0080
718 * @tc.name : demuxer meta info, get value with right key
719 * @tc.desc : function test
720 */
721 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_META_0080, TestSize.Level3)
722 {
723 const char *file = "/data/test/media/double_hevc.mp4";
724 int fd = open(file, O_RDONLY);
725 int64_t size = GetFileSize(file);
726 cout << file << "----------------------" << fd << "---------" << size << endl;
727 source = OH_AVSource_CreateWithFD(fd, 0, size);
728 ASSERT_NE(source, nullptr);
729 metaFormat= OH_AVSource_GetCustomMetadataFormat(source);
730 ASSERT_NE(metaFormat, nullptr);
731 string metamanufacturer = "ABCDEF";
732 string metamarketingName = "AABBAABBAABBAABBAA";
733 string metamodel = "ABABABAB";
734 string metaversion = "12";
735 const char* manufacturer;
736 ASSERT_TRUE(OH_AVFormat_GetStringValue(metaFormat, "com.abababa.manufacturer", &manufacturer));
737 ASSERT_EQ(manufacturer, metamanufacturer);
738 const char* marketingName;
739 ASSERT_TRUE(OH_AVFormat_GetStringValue(metaFormat, "com.abababa.marketing_name", &marketingName));
740 ASSERT_EQ(marketingName, metamarketingName);
741 const char* model;
742 ASSERT_TRUE(OH_AVFormat_GetStringValue(metaFormat, "com.abababa.model", &model));
743 ASSERT_EQ(model, metamodel);
744 const char* version;
745 ASSERT_TRUE(OH_AVFormat_GetStringValue(metaFormat, "com.abababa.version", &version));
746 ASSERT_EQ(version, metaversion);
747 close(fd);
748 fd = -1;
749 }
750
751 /**
752 * @tc.number : DEMUXER_META_0090
753 * @tc.name : demuxer meta info, souce is null
754 * @tc.desc : api test
755 */
756 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_META_0090, TestSize.Level0)
757 {
758 metaFormat= OH_AVSource_GetCustomMetadataFormat(nullptr);
759 ASSERT_EQ(metaFormat, nullptr);
760 }
761
762 /**
763 * @tc.number : DEMUXER_META_0100
764 * @tc.name : demuxer meta info, get max value
765 * @tc.desc : function test
766 */
767 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_META_0100, TestSize.Level2)
768 {
769 const char* metaStringValue = nullptr;
770 int32_t metaIntValue = 0;
771 float metaFloatValue = 0.0;
772 const char *file = "/data/test/media/metaMaxval.mp4";
773 int fd = open(file, O_RDONLY);
774 int64_t size = GetFileSize(file);
775 cout << file << "----------------------" << fd << "---------" << size << endl;
776 source = OH_AVSource_CreateWithFD(fd, 0, size);
777 ASSERT_NE(source, nullptr);
778 metaFormat= OH_AVSource_GetCustomMetadataFormat(source);
779 ASSERT_NE(metaFormat, nullptr);
780 ASSERT_FALSE(OH_AVFormat_GetStringValue(metaFormat, "com.openharmony.stringval", &metaStringValue));
781 float floatValue = 3.4028235E38;
782 ASSERT_TRUE(OH_AVFormat_GetFloatValue(metaFormat, "com.openharmony.floatval.eee", &metaFloatValue));
783 ASSERT_EQ(floatValue, metaFloatValue);
784 int32_t intValue = 2147483647;
785 ASSERT_TRUE(OH_AVFormat_GetIntValue(metaFormat, "com.openharmony.intval.aaaa", &metaIntValue));
786 ASSERT_EQ(metaIntValue, intValue);
787 close(fd);
788 fd = -1;
789 }
790
791 /**
792 * @tc.number : DEMUXER_FUNCTION_MKV_0010
793 * @tc.name : create source with fd, aac_h265.mkv
794 * @tc.desc : function test
795 */
796 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_MKV_0010, TestSize.Level0)
797 {
798 int tarckType = 0;
799 bool audioIsEnd = false;
800 bool videoIsEnd = false;
801 int audioFrame = 0;
802 int videoFrame = 0;
803 OH_AVCodecBufferAttr bufferAttr;
804 const char *file = "/data/test/media/aac_h265.mkv";
805 int fd = 0;
806 bool initResult = false;
807 InitFile(file, 2, fd, initResult);
808 ASSERT_TRUE(initResult);
809 int aKeyCount = 0;
810 int vKeyCount = 0;
811 while (!audioIsEnd || !videoIsEnd) {
812 for (int32_t index = 0; index < g_trackCount; index++) {
813 trackFormat = OH_AVSource_GetTrackFormat(source, index);
814 ASSERT_NE(trackFormat, nullptr);
815 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
816 OH_AVFormat_Destroy(trackFormat);
817 trackFormat = nullptr;
818 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
819 continue;
820 }
821 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
822 ASSERT_NE(avBuffer, nullptr);
823 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
824 if (tarckType == MEDIA_TYPE_AUD) {
825 SetAudioValue(bufferAttr, audioIsEnd, audioFrame, aKeyCount);
826 } else if (tarckType == MEDIA_TYPE_VID) {
827 SetVideoValue(bufferAttr, videoIsEnd, videoFrame, vKeyCount);
828 }
829 }
830 }
831 ASSERT_EQ(aKeyCount, 526);
832 ASSERT_EQ(vKeyCount, 2);
833 close(fd);
834 fd = -1;
835 }
836
837 /**
838 * @tc.number : DEMUXER_FUNCTION_MKV_0020
839 * @tc.name : create source with fd, mp3_h264.mkv
840 * @tc.desc : function test
841 */
842 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_MKV_0020, TestSize.Level0)
843 {
844 int tarckType = 0;
845 bool audioIsEnd = false;
846 bool videoIsEnd = false;
847 int audioFrame = 0;
848 int videoFrame = 0;
849 OH_AVCodecBufferAttr bufferAttr;
850 const char *file = "/data/test/media/mp3_h264.mkv";
851 int fd = 0;
852 bool initResult = false;
853 InitFile(file, 2, fd, initResult);
854 ASSERT_TRUE(initResult);
855 int aKeyCount = 0;
856 int vKeyCount = 0;
857 while (!audioIsEnd || !videoIsEnd) {
858 for (int32_t index = 0; index < g_trackCount; index++) {
859 trackFormat = OH_AVSource_GetTrackFormat(source, index);
860 ASSERT_NE(trackFormat, nullptr);
861 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
862 OH_AVFormat_Destroy(trackFormat);
863 trackFormat = nullptr;
864 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
865 continue;
866 }
867 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
868 ASSERT_NE(avBuffer, nullptr);
869 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
870 if (tarckType == MEDIA_TYPE_AUD) {
871 SetAudioValue(bufferAttr, audioIsEnd, audioFrame, aKeyCount);
872 } else if (tarckType == MEDIA_TYPE_VID) {
873 SetVideoValue(bufferAttr, videoIsEnd, videoFrame, vKeyCount);
874 }
875 }
876 }
877 ASSERT_EQ(aKeyCount, 468);
878 ASSERT_EQ(vKeyCount, 2);
879 close(fd);
880 fd = -1;
881 }
882
883 /**
884 * @tc.number : DEMUXER_FUNCTION_MKV_0030
885 * @tc.name : create source with fd, mp3_h265.mkv
886 * @tc.desc : function test
887 */
888 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_MKV_0030, TestSize.Level0)
889 {
890 int tarckType = 0;
891 bool audioIsEnd = false;
892 bool videoIsEnd = false;
893 int audioFrame = 0;
894 int videoFrame = 0;
895 OH_AVCodecBufferAttr bufferAttr;
896 const char *file = "/data/test/media/mp3_h265.mkv";
897 int fd = 0;
898 bool initResult = false;
899 InitFile(file, 2, fd, initResult);
900 ASSERT_TRUE(initResult);
901 int aKeyCount = 0;
902 int vKeyCount = 0;
903 while (!audioIsEnd || !videoIsEnd) {
904 for (int32_t index = 0; index < g_trackCount; index++) {
905 trackFormat = OH_AVSource_GetTrackFormat(source, index);
906 ASSERT_NE(trackFormat, nullptr);
907 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
908 OH_AVFormat_Destroy(trackFormat);
909 trackFormat = nullptr;
910 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
911 continue;
912 }
913 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
914 ASSERT_NE(avBuffer, nullptr);
915 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
916 if (tarckType == MEDIA_TYPE_AUD) {
917 SetAudioValue(bufferAttr, audioIsEnd, audioFrame, aKeyCount);
918 } else if (tarckType == MEDIA_TYPE_VID) {
919 SetVideoValue(bufferAttr, videoIsEnd, videoFrame, vKeyCount);
920 }
921 }
922 }
923 ASSERT_EQ(aKeyCount, 468);
924 ASSERT_EQ(vKeyCount, 2);
925 close(fd);
926 fd = -1;
927 }
928
929 /**
930 * @tc.number : DEMUXER_FUNCTION_MKV_0040
931 * @tc.name : create source with fd, opus_h264.mkv
932 * @tc.desc : function test
933 */
934 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_MKV_0040, TestSize.Level0)
935 {
936 int tarckType = 0;
937 bool audioIsEnd = false;
938 bool videoIsEnd = false;
939 int audioFrame = 0;
940 int videoFrame = 0;
941 OH_AVCodecBufferAttr bufferAttr;
942 const char *file = "/data/test/media/opus_h264.mkv";
943 int fd = 0;
944 bool initResult = false;
945 InitFile(file, 2, fd, initResult);
946 ASSERT_TRUE(initResult);
947 int aKeyCount = 0;
948 int vKeyCount = 0;
949 while (!audioIsEnd || !videoIsEnd) {
950 for (int32_t index = 0; index < g_trackCount; index++) {
951 trackFormat = OH_AVSource_GetTrackFormat(source, index);
952 ASSERT_NE(trackFormat, nullptr);
953 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
954 OH_AVFormat_Destroy(trackFormat);
955 trackFormat = nullptr;
956 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
957 continue;
958 }
959 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
960 ASSERT_NE(avBuffer, nullptr);
961 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
962 if (tarckType == MEDIA_TYPE_AUD) {
963 SetAudioValue(bufferAttr, audioIsEnd, audioFrame, aKeyCount);
964 } else if (tarckType == MEDIA_TYPE_VID) {
965 SetVideoValue(bufferAttr, videoIsEnd, videoFrame, vKeyCount);
966 }
967 }
968 }
969 ASSERT_EQ(aKeyCount, 610);
970 ASSERT_EQ(vKeyCount, 2);
971 close(fd);
972 fd = -1;
973 }
974
975 /**
976 * @tc.number : DEMUXER_FUNCTION_MKV_0050
977 * @tc.name : create source with fd, opus_h265.mkv
978 * @tc.desc : function test
979 */
980 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_MKV_0050, TestSize.Level0)
981 {
982 int tarckType = 0;
983 bool audioIsEnd = false;
984 bool videoIsEnd = false;
985 int audioFrame = 0;
986 int videoFrame = 0;
987 OH_AVCodecBufferAttr bufferAttr;
988 const char *file = "/data/test/media/opus_h265.mkv";
989 int fd = 0;
990 bool initResult = false;
991 InitFile(file, 2, fd, initResult);
992 ASSERT_TRUE(initResult);
993 int aKeyCount = 0;
994 int vKeyCount = 0;
995 while (!audioIsEnd || !videoIsEnd) {
996 for (int32_t index = 0; index < g_trackCount; index++) {
997 trackFormat = OH_AVSource_GetTrackFormat(source, index);
998 ASSERT_NE(trackFormat, nullptr);
999 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1000 OH_AVFormat_Destroy(trackFormat);
1001 trackFormat = nullptr;
1002 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
1003 continue;
1004 }
1005 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
1006 ASSERT_NE(avBuffer, nullptr);
1007 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
1008 if (tarckType == MEDIA_TYPE_AUD) {
1009 SetAudioValue(bufferAttr, audioIsEnd, audioFrame, aKeyCount);
1010 } else if (tarckType == MEDIA_TYPE_VID) {
1011 SetVideoValue(bufferAttr, videoIsEnd, videoFrame, vKeyCount);
1012 }
1013 }
1014 }
1015 ASSERT_EQ(aKeyCount, 610);
1016 ASSERT_EQ(vKeyCount, 2);
1017 close(fd);
1018 fd = -1;
1019 }
1020
1021 /**
1022 * @tc.number : DEMUXER_FUNCTION_MP4_0010
1023 * @tc.name : create source with fd, aac_mpeg4.mp4
1024 * @tc.desc : function test
1025 */
1026 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_MP4_0010, TestSize.Level0)
1027 {
1028 int tarckType = 0;
1029 bool audioIsEnd = false;
1030 bool videoIsEnd = false;
1031 int audioFrame = 0;
1032 int videoFrame = 0;
1033 OH_AVCodecBufferAttr bufferAttr;
1034 const char *file = "/data/test/media/aac_mpeg4.mp4";
1035 int fd = 0;
1036 bool initResult = false;
1037 InitFile(file, 2, fd, initResult);
1038 ASSERT_TRUE(initResult);
1039 int aKeyCount = 0;
1040 int vKeyCount = 0;
1041 while (!audioIsEnd || !videoIsEnd) {
1042 for (int32_t index = 0; index < g_trackCount; index++) {
1043 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1044 ASSERT_NE(trackFormat, nullptr);
1045 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1046 OH_AVFormat_Destroy(trackFormat);
1047 trackFormat = nullptr;
1048 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
1049 continue;
1050 }
1051 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
1052 ASSERT_NE(avBuffer, nullptr);
1053 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
1054 if (tarckType == MEDIA_TYPE_AUD) {
1055 SetAudioValue(bufferAttr, audioIsEnd, audioFrame, aKeyCount);
1056 } else if (tarckType == MEDIA_TYPE_VID) {
1057 SetVideoValue(bufferAttr, videoIsEnd, videoFrame, vKeyCount);
1058 }
1059 }
1060 }
1061 ASSERT_EQ(aKeyCount, 528);
1062 ASSERT_EQ(vKeyCount, 31);
1063 close(fd);
1064 fd = -1;
1065 }
1066
1067 /**
1068 * @tc.number : DEMUXER_FUNCTION_MP4_0020
1069 * @tc.name : create source with fd, mp3_h264.mp4
1070 * @tc.desc : function test
1071 */
1072 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_MP4_0020, TestSize.Level0)
1073 {
1074 int tarckType = 0;
1075 bool audioIsEnd = false;
1076 bool videoIsEnd = false;
1077 int audioFrame = 0;
1078 int videoFrame = 0;
1079 OH_AVCodecBufferAttr bufferAttr;
1080 const char *file = "/data/test/media/mp3_h264.mp4";
1081 int fd = 0;
1082 bool initResult = false;
1083 InitFile(file, 2, fd, initResult);
1084 ASSERT_TRUE(initResult);
1085 int aKeyCount = 0;
1086 int vKeyCount = 0;
1087 while (!audioIsEnd || !videoIsEnd) {
1088 for (int32_t index = 0; index < g_trackCount; index++) {
1089 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1090 ASSERT_NE(trackFormat, nullptr);
1091 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1092 OH_AVFormat_Destroy(trackFormat);
1093 trackFormat = nullptr;
1094 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
1095 continue;
1096 }
1097 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
1098 ASSERT_NE(avBuffer, nullptr);
1099 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
1100 if (tarckType == MEDIA_TYPE_AUD) {
1101 SetAudioValue(bufferAttr, audioIsEnd, audioFrame, aKeyCount);
1102 } else if (tarckType == MEDIA_TYPE_VID) {
1103 SetVideoValue(bufferAttr, videoIsEnd, videoFrame, vKeyCount);
1104 }
1105 }
1106 }
1107 ASSERT_EQ(aKeyCount, 468);
1108 ASSERT_EQ(vKeyCount, 2);
1109 close(fd);
1110 fd = -1;
1111 }
1112
1113 /**
1114 * @tc.number : DEMUXER_FUNCTION_MP4_0030
1115 * @tc.name : create source with fd, mp3_h265.mp4
1116 * @tc.desc : function test
1117 */
1118 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_MP4_0030, TestSize.Level0)
1119 {
1120 int tarckType = 0;
1121 bool audioIsEnd = false;
1122 bool videoIsEnd = false;
1123 int audioFrame = 0;
1124 int videoFrame = 0;
1125 OH_AVCodecBufferAttr bufferAttr;
1126 const char *file = "/data/test/media/mp3_h265.mp4";
1127 int fd = 0;
1128 bool initResult = false;
1129 InitFile(file, 2, fd, initResult);
1130 ASSERT_TRUE(initResult);
1131 int aKeyCount = 0;
1132 int vKeyCount = 0;
1133 while (!audioIsEnd || !videoIsEnd) {
1134 for (int32_t index = 0; index < g_trackCount; index++) {
1135 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1136 ASSERT_NE(trackFormat, nullptr);
1137 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1138 OH_AVFormat_Destroy(trackFormat);
1139 trackFormat = nullptr;
1140 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
1141 continue;
1142 }
1143 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
1144 ASSERT_NE(avBuffer, nullptr);
1145 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
1146 if (tarckType == MEDIA_TYPE_AUD) {
1147 SetAudioValue(bufferAttr, audioIsEnd, audioFrame, aKeyCount);
1148 } else if (tarckType == MEDIA_TYPE_VID) {
1149 SetVideoValue(bufferAttr, videoIsEnd, videoFrame, vKeyCount);
1150 }
1151 }
1152 }
1153 ASSERT_EQ(aKeyCount, 468);
1154 ASSERT_EQ(vKeyCount, 2);
1155 close(fd);
1156 fd = -1;
1157 }
1158
1159 /**
1160 * @tc.number : DEMUXER_FUNCTION_MP4_0040
1161 * @tc.name : create source with fd, aac_mpeg4_subtitle.mp4
1162 * @tc.desc : function test
1163 */
1164 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_MP4_0040, TestSize.Level0)
1165 {
1166 int tarckType = 0;
1167 bool audioIsEnd = false;
1168 bool videoIsEnd = false;
1169 int audioFrame = 0;
1170 int videoFrame = 0;
1171 OH_AVCodecBufferAttr bufferAttr;
1172 const char *file = "/data/test/media/aac_mpeg4_subtitle.mp4";
1173 int fd = 0;
1174 bool initResult = false;
1175 InitFile(file, 3, fd, initResult);
1176 ASSERT_TRUE(initResult);
1177 int aKeyCount = 0;
1178 int vKeyCount = 0;
1179 while (!audioIsEnd || !videoIsEnd) {
1180 for (int32_t index = 0; index < g_trackCount; index++) {
1181 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1182 ASSERT_NE(trackFormat, nullptr);
1183 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1184 OH_AVFormat_Destroy(trackFormat);
1185 trackFormat = nullptr;
1186 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
1187 continue;
1188 }
1189 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
1190 ASSERT_NE(avBuffer, nullptr);
1191 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
1192 if (tarckType == MEDIA_TYPE_AUD) {
1193 SetAudioValue(bufferAttr, audioIsEnd, audioFrame, aKeyCount);
1194 } else if (tarckType == MEDIA_TYPE_VID) {
1195 SetVideoValue(bufferAttr, videoIsEnd, videoFrame, vKeyCount);
1196 }
1197 }
1198 }
1199 ASSERT_EQ(aKeyCount, 528);
1200 ASSERT_EQ(vKeyCount, 31);
1201 close(fd);
1202 fd = -1;
1203 }
1204
1205 /**
1206 * @tc.number : DEMUXER_FUNCTION_MP4_0050
1207 * @tc.name : create source with fd, mp3_h265_fmp4.mp4
1208 * @tc.desc : function test
1209 */
1210 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_MP4_0050, TestSize.Level0)
1211 {
1212 int tarckType = 0;
1213 bool audioIsEnd = false;
1214 bool videoIsEnd = false;
1215 int audioFrame = 0;
1216 int videoFrame = 0;
1217 OH_AVCodecBufferAttr bufferAttr;
1218 const char *file = "/data/test/media/mp3_h265_fmp4.mp4";
1219 int fd = 0;
1220 bool initResult = false;
1221 InitFile(file, 2, fd, initResult);
1222 ASSERT_TRUE(initResult);
1223 int aKeyCount = 0;
1224 int vKeyCount = 0;
1225 while (!audioIsEnd || !videoIsEnd) {
1226 for (int32_t index = 0; index < g_trackCount; index++) {
1227 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1228 ASSERT_NE(trackFormat, nullptr);
1229 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1230 OH_AVFormat_Destroy(trackFormat);
1231 trackFormat = nullptr;
1232 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
1233 continue;
1234 }
1235 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
1236 ASSERT_NE(avBuffer, nullptr);
1237 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
1238 if (tarckType == MEDIA_TYPE_AUD) {
1239 SetAudioValue(bufferAttr, audioIsEnd, audioFrame, aKeyCount);
1240 } else if (tarckType == MEDIA_TYPE_VID) {
1241 SetVideoValue(bufferAttr, videoIsEnd, videoFrame, vKeyCount);
1242 }
1243 }
1244 }
1245 ASSERT_EQ(aKeyCount, 468);
1246 ASSERT_EQ(vKeyCount, 2);
1247 close(fd);
1248 fd = -1;
1249 }
1250
1251 /**
1252 * @tc.number : DEMUXER_FUNCTION_TS_0010
1253 * @tc.name : create source with fd, aac_h265.ts
1254 * @tc.desc : function test
1255 */
1256 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_TS_0010, TestSize.Level0)
1257 {
1258 int tarckType = 0;
1259 bool audioIsEnd = false;
1260 bool videoIsEnd = false;
1261 int audioFrame = 0;
1262 int videoFrame = 0;
1263 OH_AVCodecBufferAttr bufferAttr;
1264 const char *file = "/data/test/media/aac_h265.ts";
1265 int fd = 0;
1266 bool initResult = false;
1267 InitFile(file, 2, fd, initResult);
1268 ASSERT_TRUE(initResult);
1269 int aKeyCount = 0;
1270 int vKeyCount = 0;
1271 while (!audioIsEnd || !videoIsEnd) {
1272 for (int32_t index = 0; index < g_trackCount; index++) {
1273 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1274 ASSERT_NE(trackFormat, nullptr);
1275 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1276 OH_AVFormat_Destroy(trackFormat);
1277 trackFormat = nullptr;
1278 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
1279 continue;
1280 }
1281 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
1282 ASSERT_NE(avBuffer, nullptr);
1283 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
1284 if (tarckType == MEDIA_TYPE_AUD) {
1285 SetAudioValue(bufferAttr, audioIsEnd, audioFrame, aKeyCount);
1286 } else if (tarckType == MEDIA_TYPE_VID) {
1287 SetVideoValue(bufferAttr, videoIsEnd, videoFrame, vKeyCount);
1288 }
1289 }
1290 }
1291 ASSERT_EQ(aKeyCount, 526);
1292 if (!access("/system/lib64/media/", 0)) {
1293 ASSERT_EQ(vKeyCount, 2);
1294 }
1295 close(fd);
1296 fd = -1;
1297 }
1298
1299 /**
1300 * @tc.number : DEMUXER_FUNCTION_TS_0020
1301 * @tc.name : create source with fd, aac_mpeg2.ts
1302 * @tc.desc : function test
1303 */
1304 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_TS_0020, TestSize.Level0)
1305 {
1306 int tarckType = 0;
1307 bool audioIsEnd = false;
1308 bool videoIsEnd = false;
1309 int audioFrame = 0;
1310 int videoFrame = 0;
1311 OH_AVCodecBufferAttr bufferAttr;
1312 const char *file = "/data/test/media/aac_mpeg2.ts";
1313 int fd = 0;
1314 bool initResult = false;
1315 InitFile(file, 2, fd, initResult);
1316 ASSERT_TRUE(initResult);
1317 int aKeyCount = 0;
1318 int vKeyCount = 0;
1319 while (!audioIsEnd || !videoIsEnd) {
1320 for (int32_t index = 0; index < g_trackCount; index++) {
1321 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1322 ASSERT_NE(trackFormat, nullptr);
1323 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1324 OH_AVFormat_Destroy(trackFormat);
1325 trackFormat = nullptr;
1326 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
1327 continue;
1328 }
1329 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
1330 ASSERT_NE(avBuffer, nullptr);
1331 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
1332 if (tarckType == MEDIA_TYPE_AUD) {
1333 SetAudioValue(bufferAttr, audioIsEnd, audioFrame, aKeyCount);
1334 } else if (tarckType == MEDIA_TYPE_VID) {
1335 SetVideoValue(bufferAttr, videoIsEnd, videoFrame, vKeyCount);
1336 }
1337 }
1338 }
1339 ASSERT_EQ(aKeyCount, 528);
1340 ASSERT_EQ(vKeyCount, 31);
1341 close(fd);
1342 fd = -1;
1343 }
1344
1345 /**
1346 * @tc.number : DEMUXER_FUNCTION_TS_0030
1347 * @tc.name : create source with fd, aac_mpeg4.ts
1348 * @tc.desc : function test
1349 */
1350 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_TS_0030, TestSize.Level0)
1351 {
1352 int tarckType = 0;
1353 bool audioIsEnd = false;
1354 bool videoIsEnd = false;
1355 int audioFrame = 0;
1356 int videoFrame = 0;
1357 OH_AVCodecBufferAttr bufferAttr;
1358 const char *file = "/data/test/media/aac_mpeg4.ts";
1359 int fd = 0;
1360 bool initResult = false;
1361 InitFile(file, 2, fd, initResult);
1362 ASSERT_TRUE(initResult);
1363 int aKeyCount = 0;
1364 int vKeyCount = 0;
1365 while (!audioIsEnd || !videoIsEnd) {
1366 for (int32_t index = 0; index < g_trackCount; index++) {
1367 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1368 ASSERT_NE(trackFormat, nullptr);
1369 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1370 OH_AVFormat_Destroy(trackFormat);
1371 trackFormat = nullptr;
1372 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
1373 continue;
1374 }
1375 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
1376 ASSERT_NE(avBuffer, nullptr);
1377 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
1378 if (tarckType == MEDIA_TYPE_AUD) {
1379 SetAudioValue(bufferAttr, audioIsEnd, audioFrame, aKeyCount);
1380 } else if (tarckType == MEDIA_TYPE_VID) {
1381 SetVideoValue(bufferAttr, videoIsEnd, videoFrame, vKeyCount);
1382 }
1383 }
1384 }
1385 ASSERT_EQ(aKeyCount, 528);
1386 ASSERT_EQ(vKeyCount, 31);
1387 close(fd);
1388 fd = -1;
1389 }
1390
1391 /**
1392 * @tc.number : DEMUXER_FUNCTION_TS_0040
1393 * @tc.name : create source with fd, mp3_h264.ts
1394 * @tc.desc : function test
1395 */
1396 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_TS_0040, TestSize.Level0)
1397 {
1398 int tarckType = 0;
1399 bool audioIsEnd = false;
1400 bool videoIsEnd = false;
1401 int audioFrame = 0;
1402 int videoFrame = 0;
1403 OH_AVCodecBufferAttr bufferAttr;
1404 const char *file = "/data/test/media/mp3_h264.ts";
1405 int fd = 0;
1406 bool initResult = false;
1407 InitFile(file, 2, fd, initResult);
1408 ASSERT_TRUE(initResult);
1409 int aKeyCount = 0;
1410 int vKeyCount = 0;
1411 while (!audioIsEnd || !videoIsEnd) {
1412 for (int32_t index = 0; index < g_trackCount; index++) {
1413 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1414 ASSERT_NE(trackFormat, nullptr);
1415 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1416 OH_AVFormat_Destroy(trackFormat);
1417 trackFormat = nullptr;
1418 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
1419 continue;
1420 }
1421 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
1422 ASSERT_NE(avBuffer, nullptr);
1423 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
1424 if (tarckType == MEDIA_TYPE_AUD) {
1425 SetAudioValue(bufferAttr, audioIsEnd, audioFrame, aKeyCount);
1426 } else if (tarckType == MEDIA_TYPE_VID) {
1427 SetVideoValue(bufferAttr, videoIsEnd, videoFrame, vKeyCount);
1428 }
1429 }
1430 }
1431 ASSERT_EQ(aKeyCount, 468);
1432 ASSERT_EQ(vKeyCount, 2);
1433 close(fd);
1434 fd = -1;
1435 }
1436
1437 /**
1438 * @tc.number : DEMUXER_FUNCTION_TS_0050
1439 * @tc.name : create source with fd, mp3_mpeg2.ts
1440 * @tc.desc : function test
1441 */
1442 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_TS_0050, TestSize.Level0)
1443 {
1444 int tarckType = 0;
1445 bool audioIsEnd = false;
1446 bool videoIsEnd = false;
1447 int audioFrame = 0;
1448 int videoFrame = 0;
1449 OH_AVCodecBufferAttr bufferAttr;
1450 const char *file = "/data/test/media/mp3_mpeg2.ts";
1451 int fd = 0;
1452 bool initResult = false;
1453 InitFile(file, 2, fd, initResult);
1454 ASSERT_TRUE(initResult);
1455 int aKeyCount = 0;
1456 int vKeyCount = 0;
1457 while (!audioIsEnd || !videoIsEnd) {
1458 for (int32_t index = 0; index < g_trackCount; index++) {
1459 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1460 ASSERT_NE(trackFormat, nullptr);
1461 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1462 OH_AVFormat_Destroy(trackFormat);
1463 trackFormat = nullptr;
1464 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
1465 continue;
1466 }
1467 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
1468 ASSERT_NE(avBuffer, nullptr);
1469 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
1470 if (tarckType == MEDIA_TYPE_AUD) {
1471 SetAudioValue(bufferAttr, audioIsEnd, audioFrame, aKeyCount);
1472 } else if (tarckType == MEDIA_TYPE_VID) {
1473 SetVideoValue(bufferAttr, videoIsEnd, videoFrame, vKeyCount);
1474 }
1475 }
1476 }
1477 ASSERT_EQ(aKeyCount, 468);
1478 ASSERT_EQ(vKeyCount, 31);
1479 close(fd);
1480 fd = -1;
1481 }
1482
1483 /**
1484 * @tc.number : DEMUXER_FUNCTION_TS_0060
1485 * @tc.name : create source with fd, mp3_mpeg4.ts
1486 * @tc.desc : function test
1487 */
1488 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_TS_0060, TestSize.Level0)
1489 {
1490 int tarckType = 0;
1491 bool audioIsEnd = false;
1492 bool videoIsEnd = false;
1493 int audioFrame = 0;
1494 int videoFrame = 0;
1495 OH_AVCodecBufferAttr bufferAttr;
1496 const char *file = "/data/test/media/mp3_mpeg4.ts";
1497 int fd = 0;
1498 bool initResult = false;
1499 InitFile(file, 2, fd, initResult);
1500 ASSERT_TRUE(initResult);
1501 int aKeyCount = 0;
1502 int vKeyCount = 0;
1503 while (!audioIsEnd || !videoIsEnd) {
1504 for (int32_t index = 0; index < g_trackCount; index++) {
1505 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1506 ASSERT_NE(trackFormat, nullptr);
1507 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1508 OH_AVFormat_Destroy(trackFormat);
1509 trackFormat = nullptr;
1510 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
1511 continue;
1512 }
1513 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
1514 ASSERT_NE(avBuffer, nullptr);
1515 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
1516 if (tarckType == MEDIA_TYPE_AUD) {
1517 SetAudioValue(bufferAttr, audioIsEnd, audioFrame, aKeyCount);
1518 } else if (tarckType == MEDIA_TYPE_VID) {
1519 SetVideoValue(bufferAttr, videoIsEnd, videoFrame, vKeyCount);
1520 }
1521 }
1522 }
1523 ASSERT_EQ(aKeyCount, 468);
1524 ASSERT_EQ(vKeyCount, 31);
1525 close(fd);
1526 fd = -1;
1527 }
1528
1529 /**
1530 * @tc.number : DEMUXER_FUNCTION_COMMENT_0010
1531 * @tc.name : 中文字符串,使用正确/错误的接口类型获取comment
1532 * @tc.desc : function test
1533 */
1534 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_COMMENT_0010, TestSize.Level0)
1535 {
1536 const char *file = "/data/test/media/comment_0010.mp4";
1537 int fd = open(file, O_RDONLY);
1538 int64_t size = GetFileSize(file);
1539 cout << file << "----------------------" << fd << "---------" << size << endl;
1540 source = OH_AVSource_CreateWithFD(fd, 0, size);
1541 ASSERT_NE(source, nullptr);
1542 demuxer = OH_AVDemuxer_CreateWithSource(source);
1543 ASSERT_NE(demuxer, nullptr);
1544 sourceFormat = OH_AVSource_GetSourceFormat(source);
1545 ASSERT_NE(sourceFormat, nullptr);
1546 int32_t intVal = 0;
1547 ASSERT_FALSE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_COMMENT, &intVal));
1548 int64_t longVal = 0;
1549 ASSERT_FALSE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_COMMENT, &longVal));
1550 double doubleVal;
1551 ASSERT_FALSE(OH_AVFormat_GetDoubleValue(sourceFormat, OH_MD_KEY_COMMENT, &doubleVal));
1552 float floatVal = 0.0;
1553 ASSERT_FALSE(OH_AVFormat_GetFloatValue(sourceFormat, OH_MD_KEY_COMMENT, &floatVal));
1554 const char *stringVal = nullptr;
1555 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_COMMENT, &stringVal));
1556 ASSERT_NE(stringVal, nullptr);
1557 ASSERT_EQ(0, strcmp(stringVal, "中文测试字符串中文测试字符串"));
1558 }
1559
1560 /**
1561 * @tc.number : DEMUXER_FUNCTION_COMMENT_0020
1562 * @tc.name : 英文字符串,使用正确/错误的接口类型获取comment
1563 * @tc.desc : function test
1564 */
1565 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_COMMENT_0020, TestSize.Level0)
1566 {
1567 const char *file = "/data/test/media/comment_0020.mp4";
1568 int fd = open(file, O_RDONLY);
1569 int64_t size = GetFileSize(file);
1570 cout << file << "----------------------" << fd << "---------" << size << endl;
1571 source = OH_AVSource_CreateWithFD(fd, 0, size);
1572 ASSERT_NE(source, nullptr);
1573 demuxer = OH_AVDemuxer_CreateWithSource(source);
1574 ASSERT_NE(demuxer, nullptr);
1575 sourceFormat = OH_AVSource_GetSourceFormat(source);
1576 ASSERT_NE(sourceFormat, nullptr);
1577 int32_t intVal = 0;
1578 ASSERT_FALSE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_COMMENT, &intVal));
1579 int64_t longVal = 0;
1580 ASSERT_FALSE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_COMMENT, &longVal));
1581 double doubleVal;
1582 ASSERT_FALSE(OH_AVFormat_GetDoubleValue(sourceFormat, OH_MD_KEY_COMMENT, &doubleVal));
1583 float floatVal = 0.0;
1584 ASSERT_FALSE(OH_AVFormat_GetFloatValue(sourceFormat, OH_MD_KEY_COMMENT, &floatVal));
1585 const char *stringVal = nullptr;
1586 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_COMMENT, &stringVal));
1587 ASSERT_NE(stringVal, nullptr);
1588 ASSERT_EQ(0, strcmp(stringVal, "comment_test"));
1589 }
1590
1591 /**
1592 * @tc.number : DEMUXER_FUNCTION_COMMENT_0030
1593 * @tc.name : 中文数字符号字符串,使用正确/错误的接口类型获取comment
1594 * @tc.desc : function test
1595 */
1596 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_COMMENT_0030, TestSize.Level0)
1597 {
1598 const char *file = "/data/test/media/comment_0030.mp4";
1599 int fd = open(file, O_RDONLY);
1600 int64_t size = GetFileSize(file);
1601 cout << file << "----------------------" << fd << "---------" << size << endl;
1602 source = OH_AVSource_CreateWithFD(fd, 0, size);
1603 ASSERT_NE(source, nullptr);
1604 demuxer = OH_AVDemuxer_CreateWithSource(source);
1605 ASSERT_NE(demuxer, nullptr);
1606 sourceFormat = OH_AVSource_GetSourceFormat(source);
1607 ASSERT_NE(sourceFormat, nullptr);
1608 int32_t intVal = 0;
1609 ASSERT_FALSE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_COMMENT, &intVal));
1610 int64_t longVal = 0;
1611 ASSERT_FALSE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_COMMENT, &longVal));
1612 double doubleVal;
1613 ASSERT_FALSE(OH_AVFormat_GetDoubleValue(sourceFormat, OH_MD_KEY_COMMENT, &doubleVal));
1614 float floatVal = 0.0;
1615 ASSERT_FALSE(OH_AVFormat_GetFloatValue(sourceFormat, OH_MD_KEY_COMMENT, &floatVal));
1616 const char *stringVal = nullptr;
1617 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_COMMENT, &stringVal));
1618 ASSERT_NE(stringVal, nullptr);
1619 ASSERT_EQ(0, strcmp(stringVal, ";;;;;‘’‘’1234"));
1620 }
1621
1622 /**
1623 * @tc.number : DEMUXER_FUNCTION_COMMENT_0040
1624 * @tc.name : 英文数字符号字符串,使用正确/错误的接口类型获取comment
1625 * @tc.desc : function test
1626 */
1627 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_COMMENT_0040, TestSize.Level0)
1628 {
1629 const char *file = "/data/test/media/comment_0040.mp4";
1630 int fd = open(file, O_RDONLY);
1631 int64_t size = GetFileSize(file);
1632 cout << file << "----------------------" << fd << "---------" << size << endl;
1633 source = OH_AVSource_CreateWithFD(fd, 0, size);
1634 ASSERT_NE(source, nullptr);
1635 demuxer = OH_AVDemuxer_CreateWithSource(source);
1636 ASSERT_NE(demuxer, nullptr);
1637 sourceFormat = OH_AVSource_GetSourceFormat(source);
1638 ASSERT_NE(sourceFormat, nullptr);
1639 int32_t intVal = 0;
1640 ASSERT_FALSE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_COMMENT, &intVal));
1641 int64_t longVal = 0;
1642 ASSERT_FALSE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_COMMENT, &longVal));
1643 double doubleVal;
1644 ASSERT_FALSE(OH_AVFormat_GetDoubleValue(sourceFormat, OH_MD_KEY_COMMENT, &doubleVal));
1645 float floatVal = 0.0;
1646 ASSERT_FALSE(OH_AVFormat_GetFloatValue(sourceFormat, OH_MD_KEY_COMMENT, &floatVal));
1647 const char *stringVal = nullptr;
1648 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_COMMENT, &stringVal));
1649 ASSERT_NE(stringVal, nullptr);
1650 ASSERT_EQ(0, strcmp(stringVal, "[[[]]]////1234"));
1651 }
1652 /**
1653 * @tc.number : DEMUXER_FUNCTION_COMMENT_0050
1654 * @tc.name : 边界值长字符串,使用正确/错误的接口类型获取comment
1655 * @tc.desc : function test
1656 */
1657 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_COMMENT_0050, TestSize.Level0)
1658 {
1659 char uri[] = "/data/test/media/comment_0050.mp4";
1660 source = OH_AVSource_CreateWithURI(uri);
1661 ASSERT_NE(source, nullptr);
1662 sourceFormat = OH_AVSource_GetSourceFormat(source);
1663 ASSERT_NE(sourceFormat, nullptr);
1664 int32_t intVal = 0;
1665 ASSERT_FALSE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_COMMENT, &intVal));
1666 int64_t longVal = 0;
1667 ASSERT_FALSE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_COMMENT, &longVal));
1668 double doubleVal;
1669 ASSERT_FALSE(OH_AVFormat_GetDoubleValue(sourceFormat, OH_MD_KEY_COMMENT, &doubleVal));
1670 float floatVal = 0.0;
1671 ASSERT_FALSE(OH_AVFormat_GetFloatValue(sourceFormat, OH_MD_KEY_COMMENT, &floatVal));
1672 const char *stringVal = nullptr;
1673 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_COMMENT, &stringVal));
1674 ASSERT_NE(stringVal, nullptr);
1675 ASSERT_EQ(0, strcmp(stringVal, "comment_comment_comment_comment_comment_comment"
1676 "comment_comment_comment_comment_comment_comment_comment_comment_comment_comment_comment_comment"
1677 "comment_comment_comment_comment_comment_comment_comment_comment_comment_comment_comment_comment"
1678 "comment_comment_com"));
1679 }
1680
1681 /**
1682 * @tc.number : DEMUXER_FUNCTION_COMMENT_0060
1683 * @tc.name : 边界值长字符串超过256,使用正确/错误的接口类型获取comment
1684 * @tc.desc : function test
1685 */
1686 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_COMMENT_0060, TestSize.Level0)
1687 {
1688 char uri[] = "/data/test/media/comment_0060.mp4";
1689 source = OH_AVSource_CreateWithURI(uri);
1690 ASSERT_NE(source, nullptr);
1691 sourceFormat = OH_AVSource_GetSourceFormat(source);
1692 ASSERT_NE(sourceFormat, nullptr);
1693 int32_t intVal = 0;
1694 ASSERT_FALSE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_COMMENT, &intVal));
1695 int64_t longVal = 0;
1696 ASSERT_FALSE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_COMMENT, &longVal));
1697 double doubleVal;
1698 ASSERT_FALSE(OH_AVFormat_GetDoubleValue(sourceFormat, OH_MD_KEY_COMMENT, &doubleVal));
1699 float floatVal = 0.0;
1700 ASSERT_FALSE(OH_AVFormat_GetFloatValue(sourceFormat, OH_MD_KEY_COMMENT, &floatVal));
1701 const char *stringVal = nullptr;
1702 ASSERT_FALSE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_COMMENT, &stringVal));
1703 }
1704
1705 /**
1706 * @tc.number : DEMUXER_FUNCTION_COMMENT_0070
1707 * @tc.name : 不含comment,使用正确/错误的接口类型获取comment
1708 * @tc.desc : function test
1709 */
1710 HWTEST_F(DemuxerFunc3NdkTest, DEMUXER_FUNCTION_COMMENT_0070, TestSize.Level0)
1711 {
1712 char uri[] = "/data/test/media/mp3_h265_fmp4.mp4";
1713 source = OH_AVSource_CreateWithURI(uri);
1714 ASSERT_NE(source, nullptr);
1715 sourceFormat = OH_AVSource_GetSourceFormat(source);
1716 ASSERT_NE(sourceFormat, nullptr);
1717 const char *stringVal = nullptr;
1718 int32_t intVal = 0;
1719 ASSERT_FALSE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_COMMENT, &intVal));
1720 int64_t longVal = 0;
1721 ASSERT_FALSE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_COMMENT, &longVal));
1722 double doubleVal;
1723 ASSERT_FALSE(OH_AVFormat_GetDoubleValue(sourceFormat, OH_MD_KEY_COMMENT, &doubleVal));
1724 float floatVal = 0.0;
1725 ASSERT_FALSE(OH_AVFormat_GetFloatValue(sourceFormat, OH_MD_KEY_COMMENT, &floatVal));
1726 ASSERT_FALSE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_COMMENT, &stringVal));
1727 }