1 /*
2 * Copyright (C) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
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 DemuxerFuncNdkTest : 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_AVErrCode ret = AV_ERR_OK;
47 static OH_AVDemuxer *demuxer = nullptr;
48 static OH_AVFormat *sourceFormat = nullptr;
49 static OH_AVFormat *trackFormat = nullptr;
50 static int32_t g_trackCount;
51 static int32_t g_width = 3840;
52 static int32_t g_height = 2160;
53
SetUpTestCase()54 void DemuxerFuncNdkTest::SetUpTestCase() {}
TearDownTestCase()55 void DemuxerFuncNdkTest::TearDownTestCase() {}
SetUp()56 void DemuxerFuncNdkTest::SetUp()
57 {
58 memory = OH_AVMemory_Create(g_width * g_height);
59 g_trackCount = 0;
60 }
TearDown()61 void DemuxerFuncNdkTest::TearDown()
62 {
63 if (trackFormat != nullptr) {
64 OH_AVFormat_Destroy(trackFormat);
65 trackFormat = nullptr;
66 }
67
68 if (sourceFormat != nullptr) {
69 OH_AVFormat_Destroy(sourceFormat);
70 sourceFormat = nullptr;
71 }
72
73 if (memory != nullptr) {
74 OH_AVMemory_Destroy(memory);
75 memory = nullptr;
76 }
77 if (source != nullptr) {
78 OH_AVSource_Destroy(source);
79 source = nullptr;
80 }
81 if (demuxer != nullptr) {
82 OH_AVDemuxer_Destroy(demuxer);
83 demuxer = nullptr;
84 }
85 }
86 } // namespace Media
87 } // namespace OHOS
88
89 using namespace std;
90 using namespace OHOS;
91 using namespace OHOS::Media;
92 using namespace testing::ext;
93
GetFileSize(const char * fileName)94 static int64_t GetFileSize(const char *fileName)
95 {
96 int64_t fileSize = 0;
97 if (fileName != nullptr) {
98 struct stat fileStatus {};
99 if (stat(fileName, &fileStatus) == 0) {
100 fileSize = static_cast<int64_t>(fileStatus.st_size);
101 }
102 }
103 return fileSize;
104 }
105
106 /**
107 * @tc.number : DEMUXER_FUNCTION_0200
108 * @tc.name : create source with no permission URI
109 * @tc.desc : function test
110 */
111 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_0200, TestSize.Level0)
112 {
113 const char *uri = "http://10.174.172.228:8080/share/audio/AAC_48000_1.aac";
114 source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
115 ASSERT_EQ(nullptr, source);
116 }
117
118 /**
119 * @tc.number : DEMUXER_FUNCTION_0300
120 * @tc.name : create source with invalid uri
121 * @tc.desc : function test
122 */
123 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_0300, TestSize.Level1)
124 {
125 const char *uri = "http://invalidPath/invalid.mp4";
126 source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
127 ASSERT_EQ(nullptr, source);
128 }
129
130 /**
131 * @tc.number : DEMUXER_FUNCTION_0400
132 * @tc.name : create source with fd but no permission
133 * @tc.desc : function test
134 */
135 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_0400, TestSize.Level1)
136 {
137 const char *file = "/data/media/noPermission.mp4";
138 int fd = open(file, O_RDONLY);
139 int64_t size = GetFileSize(file);
140 cout << file << "----------------------" << fd << "---------" << size << endl;
141 cout << file << "------" << size << endl;
142 source = OH_AVSource_CreateWithFD(fd, 0, size);
143 demuxer = OH_AVDemuxer_CreateWithSource(source);
144 ASSERT_EQ(demuxer, nullptr);
145
146 close(fd);
147 }
148
149 /**
150 * @tc.number : DEMUXER_FUNCTION_0500
151 * @tc.name : create source with invalid fd
152 * @tc.desc : function test
153 */
154 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_0500, TestSize.Level1)
155 {
156 const char *file = "/data/test/media/invalid.mp4";
157 int fd = open(file, O_RDONLY);
158 int64_t size = GetFileSize(file);
159 cout << file << "----------------------" << fd << "---------" << size << endl;
160 source = OH_AVSource_CreateWithFD(fd, 0, size);
161 ASSERT_EQ(source, nullptr);
162 close(fd);
163 }
164
165 /**
166 * @tc.number : DEMUXER_FUNCTION_0700
167 * @tc.name : create source with fd, mp4
168 * @tc.desc : function test
169 */
170 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_0700, TestSize.Level0)
171 {
172 int tarckType = 0;
173 OH_AVCodecBufferAttr attr;
174 bool audioIsEnd = false;
175 bool videoIsEnd = false;
176 int audioFrame = 0;
177 int videoFrame = 0;
178 const char *file = "/data/test/media/01_video_audio.mp4";
179 int fd = open(file, O_RDONLY);
180 int64_t size = GetFileSize(file);
181 cout << file << "----------------------" << fd << "---------" << size << endl;
182 source = OH_AVSource_CreateWithFD(fd, 0, size);
183 ASSERT_NE(source, nullptr);
184
185 demuxer = OH_AVDemuxer_CreateWithSource(source);
186 ASSERT_NE(demuxer, nullptr);
187
188 sourceFormat = OH_AVSource_GetSourceFormat(source);
189 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
190 ASSERT_EQ(2, g_trackCount);
191 for (int32_t index = 0; index < g_trackCount; index++) {
192 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
193 }
194 while (!audioIsEnd || !videoIsEnd) {
195 for (int32_t index = 0; index < g_trackCount; index++) {
196
197 trackFormat = OH_AVSource_GetTrackFormat(source, index);
198 ASSERT_NE(trackFormat, nullptr);
199 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
200
201 if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
202 continue;
203 }
204 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
205
206 if (tarckType == 0) {
207 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
208 audioIsEnd = true;
209 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
210 } else {
211 audioFrame++;
212 }
213 } else if (tarckType == 1) {
214 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
215 videoIsEnd = true;
216 cout << videoFrame << " video is end !!!!!!!!!!!!!!!" << endl;
217 } else {
218 videoFrame++;
219 }
220 }
221 }
222 }
223 close(fd);
224 }
225
226 /**
227 * @tc.number : DEMUXER_FUNCTION_0800
228 * @tc.name : create source with fd,avcc mp4
229 * @tc.desc : function test
230 */
231 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_0800, TestSize.Level0)
232 {
233 int tarckType = 0;
234 OH_AVCodecBufferAttr attr;
235 bool audioIsEnd = false;
236 bool videoIsEnd = false;
237 int audioFrame = 0;
238 int videoFrame = 0;
239 const char *file = "/data/test/media/avcc_10sec.mp4";
240 int fd = open(file, O_RDONLY);
241 int64_t size = GetFileSize(file);
242 cout << file << "----------------------" << fd << "---------" << size << endl;
243 source = OH_AVSource_CreateWithFD(fd, 0, size);
244 ASSERT_NE(source, nullptr);
245
246 demuxer = OH_AVDemuxer_CreateWithSource(source);
247 ASSERT_NE(demuxer, nullptr);
248
249 sourceFormat = OH_AVSource_GetSourceFormat(source);
250 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
251 ASSERT_EQ(2, g_trackCount);
252
253 for (int32_t index = 0; index < g_trackCount; index++) {
254 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
255 }
256
257 int aKeyCount = 0;
258 int vKeyCount = 0;
259 while (!audioIsEnd || !videoIsEnd) {
260 for (int32_t index = 0; index < g_trackCount; index++) {
261
262 trackFormat = OH_AVSource_GetTrackFormat(source, index);
263 ASSERT_NE(trackFormat, nullptr);
264 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
265
266 if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
267 continue;
268 }
269 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
270
271 if (tarckType == 0) {
272 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
273 audioIsEnd = true;
274 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
275 } else {
276 audioFrame++;
277 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
278 aKeyCount++;
279 }
280 }
281 } else if (tarckType == 1) {
282 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
283 videoIsEnd = true;
284 cout << videoFrame << " video is end !!!!!!!!!!!!!!!" << endl;
285 } else {
286 videoFrame++;
287 uint8_t *buffer = OH_AVMemory_GetAddr(memory);
288 for (int i = 0; i < 16; i++) {
289 printf("%2x ", buffer[i]);
290 }
291 cout << "video track !!!!!" << endl;
292 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
293 vKeyCount++;
294 }
295 }
296 }
297 }
298 }
299 ASSERT_EQ(audioFrame, 431);
300 ASSERT_EQ(videoFrame, 600);
301 ASSERT_EQ(aKeyCount, 431);
302 ASSERT_EQ(vKeyCount, 10);
303 close(fd);
304 }
305
306 /**
307 * @tc.number : DEMUXER_FUNCTION_0900
308 * @tc.name : create source with fd,hvcc mp4
309 * @tc.desc : function test
310 */
311 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_0900, TestSize.Level0)
312 {
313 int tarckType = 0;
314 OH_AVCodecBufferAttr attr;
315 bool audioIsEnd = false;
316 bool videoIsEnd = false;
317 int audioFrame = 0;
318 int videoFrame = 0;
319 const char *file = "/data/test/media/hvcc.mp4";
320 int fd = open(file, O_RDONLY);
321 int64_t size = GetFileSize(file);
322 source = OH_AVSource_CreateWithFD(fd, 0, size);
323 ASSERT_NE(source, nullptr);
324
325 demuxer = OH_AVDemuxer_CreateWithSource(source);
326 ASSERT_NE(demuxer, nullptr);
327
328 sourceFormat = OH_AVSource_GetSourceFormat(source);
329 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
330 ASSERT_EQ(2, g_trackCount);
331
332 for (int32_t index = 0; index < g_trackCount; index++) {
333 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
334 }
335
336 int aKeyCount = 0;
337 int vKeyCount = 0;
338 while (!audioIsEnd || !videoIsEnd) {
339 for (int32_t index = 0; index < g_trackCount; index++) {
340
341 trackFormat = OH_AVSource_GetTrackFormat(source, index);
342 ASSERT_NE(trackFormat, nullptr);
343 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
344
345 if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
346 continue;
347 }
348 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
349
350 if (tarckType == 0) {
351 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
352 audioIsEnd = true;
353 } else {
354 audioFrame++;
355 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
356 aKeyCount++;
357 }
358 }
359 } else if (tarckType == 1) {
360 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
361 videoIsEnd = true;
362 } else {
363 videoFrame++;
364 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
365 vKeyCount++;
366 }
367 }
368 }
369 }
370 }
371 ASSERT_EQ(audioFrame, 433);
372 ASSERT_EQ(videoFrame, 602);
373 ASSERT_EQ(aKeyCount, 433);
374 ASSERT_EQ(vKeyCount, 3);
375 close(fd);
376 }
377
378 /**
379 * @tc.number : DEMUXER_FUNCTION_1000
380 * @tc.name : create source with fd,mpeg mp4
381 * @tc.desc : function test
382 */
383 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1000, TestSize.Level0)
384 {
385 int tarckType = 0;
386 OH_AVCodecBufferAttr attr;
387 bool audioIsEnd = false;
388 bool videoIsEnd = false;
389 int audioFrame = 0;
390 int videoFrame = 0;
391 const char *file = "/data/test/media/mpeg2.mp4";
392 int fd = open(file, O_RDONLY);
393 int64_t size = GetFileSize(file);
394 cout << file << "----------------------" << fd << "---------" << size << endl;
395 source = OH_AVSource_CreateWithFD(fd, 0, size);
396 ASSERT_NE(source, nullptr);
397
398 demuxer = OH_AVDemuxer_CreateWithSource(source);
399 ASSERT_NE(demuxer, nullptr);
400
401 sourceFormat = OH_AVSource_GetSourceFormat(source);
402 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
403 ASSERT_EQ(2, g_trackCount);
404
405 for (int32_t index = 0; index < g_trackCount; index++) {
406 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
407 }
408
409 int aKeyCount = 0;
410 int vKeyCount = 0;
411 while (!audioIsEnd || !videoIsEnd) {
412 for (int32_t index = 0; index < g_trackCount; index++) {
413 trackFormat = OH_AVSource_GetTrackFormat(source, index);
414 ASSERT_NE(trackFormat, nullptr);
415 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
416
417 if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
418 continue;
419 }
420 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
421
422 if (tarckType == 0) {
423 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
424 audioIsEnd = true;
425 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
426 } else {
427 audioFrame++;
428 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
429 aKeyCount++;
430 }
431 }
432 } else if (tarckType == 1) {
433 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
434 videoIsEnd = true;
435 cout << videoFrame << " video is end !!!!!!!!!!!!!!!" << endl;
436 } else {
437 videoFrame++;
438 cout << "video track !!!!!" << endl;
439 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
440 vKeyCount++;
441 }
442 }
443 }
444 }
445 }
446
447 ASSERT_EQ(audioFrame, 433);
448 ASSERT_EQ(videoFrame, 303);
449 ASSERT_EQ(aKeyCount, 433);
450 ASSERT_EQ(vKeyCount, 26);
451 close(fd);
452 }
453
454 /**
455 * @tc.number : DEMUXER_FUNCTION_1100
456 * @tc.name : demux m4a
457 * @tc.desc : function test
458 */
459 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1100, TestSize.Level0)
460 {
461 OH_AVCodecBufferAttr attr;
462 bool audioIsEnd = false;
463 int audioFrame = 0;
464
465 const char *file = "/data/test/media/audio/M4A_48000_1.m4a";
466 int fd = open(file, O_RDONLY);
467 int64_t size = GetFileSize(file);
468 cout << file << "----------------------" << fd << "---------" << size << endl;
469 source = OH_AVSource_CreateWithFD(fd, 0, size);
470 ASSERT_NE(source, nullptr);
471
472 demuxer = OH_AVDemuxer_CreateWithSource(source);
473 ASSERT_NE(demuxer, nullptr);
474
475 sourceFormat = OH_AVSource_GetSourceFormat(source);
476 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
477 ASSERT_EQ(1, g_trackCount);
478
479 for (int32_t index = 0; index < g_trackCount; index++) {
480 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
481 }
482
483 int keyCount = 0;
484 while (!audioIsEnd) {
485 for (int32_t index = 0; index < g_trackCount; index++) {
486 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
487 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
488 audioIsEnd = true;
489 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
490 } else {
491 audioFrame++;
492 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
493 keyCount++;
494 }
495 }
496 }
497 }
498
499 ASSERT_EQ(audioFrame, 10293);
500 ASSERT_EQ(keyCount, 10293);
501 close(fd);
502 }
503
504 /**
505 * @tc.number : DEMUXER_FUNCTION_1200
506 * @tc.name : demux aac
507 * @tc.desc : function test
508 */
509 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1200, TestSize.Level0)
510 {
511 OH_AVCodecBufferAttr attr;
512 bool audioIsEnd = false;
513 int audioFrame = 0;
514
515 const char *file = "/data/test/media/audio/AAC_48000_1.aac";
516 int fd = open(file, O_RDONLY);
517 int64_t size = GetFileSize(file);
518 cout << file << "----------------------" << fd << "---------" << size << endl;
519 source = OH_AVSource_CreateWithFD(fd, 0, size);
520 ASSERT_NE(source, nullptr);
521
522 demuxer = OH_AVDemuxer_CreateWithSource(source);
523 ASSERT_NE(demuxer, nullptr);
524
525 sourceFormat = OH_AVSource_GetSourceFormat(source);
526 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
527 ASSERT_EQ(1, g_trackCount);
528
529 for (int32_t index = 0; index < g_trackCount; index++) {
530 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
531 }
532 int keyCount = 0;
533 while (!audioIsEnd) {
534 for (int32_t index = 0; index < g_trackCount; index++) {
535 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
536 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
537 audioIsEnd = true;
538 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
539 } else {
540 audioFrame++;
541 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
542 keyCount++;
543 }
544 }
545 }
546 }
547 ASSERT_EQ(audioFrame, 9457);
548 ASSERT_EQ(keyCount, 9457);
549 close(fd);
550 }
551
552 /**
553 * @tc.number : DEMUXER_FUNCTION_1300
554 * @tc.name : demux mp3
555 * @tc.desc : function test
556 */
557 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1300, TestSize.Level0)
558 {
559 OH_AVCodecBufferAttr attr;
560 bool audioIsEnd = false;
561 int audioFrame = 0;
562
563 const char *file = "/data/test/media/audio/MP3_48000_1.mp3";
564 int fd = open(file, O_RDONLY);
565 int64_t size = GetFileSize(file);
566 cout << file << "----------------------" << fd << "---------" << size << endl;
567 source = OH_AVSource_CreateWithFD(fd, 0, size);
568 ASSERT_NE(source, nullptr);
569
570 demuxer = OH_AVDemuxer_CreateWithSource(source);
571 ASSERT_NE(demuxer, nullptr);
572
573 sourceFormat = OH_AVSource_GetSourceFormat(source);
574 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
575 ASSERT_EQ(1, g_trackCount);
576
577 for (int32_t index = 0; index < g_trackCount; index++) {
578 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
579 }
580 int keyCount = 0;
581 while (!audioIsEnd) {
582 for (int32_t index = 0; index < g_trackCount; index++) {
583 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
584 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
585 audioIsEnd = true;
586 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
587 } else {
588 audioFrame++;
589 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
590 keyCount++;
591 }
592 }
593 }
594 }
595 ASSERT_EQ(audioFrame, 9150);
596 ASSERT_EQ(keyCount, 9150);
597 close(fd);
598 }
599
600 /**
601 * @tc.number : DEMUXER_FUNCTION_1400
602 * @tc.name : demux ogg
603 * @tc.desc : function test
604 */
605 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1400, TestSize.Level0)
606 {
607 OH_AVCodecBufferAttr attr;
608 bool audioIsEnd = false;
609 int audioFrame = 0;
610
611 const char *file = "/data/test/media/audio/OGG_48000_1.ogg";
612 int fd = open(file, O_RDONLY);
613 int64_t size = GetFileSize(file);
614 cout << file << "----------------------" << fd << "---------" << size << endl;
615 source = OH_AVSource_CreateWithFD(fd, 0, size);
616 ASSERT_NE(source, nullptr);
617
618 demuxer = OH_AVDemuxer_CreateWithSource(source);
619 ASSERT_NE(demuxer, nullptr);
620
621 sourceFormat = OH_AVSource_GetSourceFormat(source);
622 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
623 ASSERT_EQ(1, g_trackCount);
624
625 for (int32_t index = 0; index < g_trackCount; index++) {
626 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
627 }
628 int keyCount = 0;
629 while (!audioIsEnd) {
630 for (int32_t index = 0; index < g_trackCount; index++) {
631 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
632 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
633 audioIsEnd = true;
634 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
635 } else {
636 audioFrame++;
637 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
638 keyCount++;
639 }
640 }
641 }
642 }
643 ASSERT_EQ(audioFrame, 11439);
644 ASSERT_EQ(keyCount, 11439);
645 close(fd);
646 }
647
648 /**
649 * @tc.number : DEMUXER_FUNCTION_1500
650 * @tc.name : demux flac
651 * @tc.desc : function test
652 */
653 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1500, TestSize.Level0)
654 {
655 OH_AVCodecBufferAttr attr;
656 bool audioIsEnd = false;
657 int audioFrame = 0;
658
659 const char *file = "/data/test/media/audio/FLAC_48000_1.flac";
660 int fd = open(file, O_RDONLY);
661 int64_t size = GetFileSize(file);
662 cout << file << "----------------------" << fd << "---------" << size << endl;
663 source = OH_AVSource_CreateWithFD(fd, 0, size);
664 ASSERT_NE(source, nullptr);
665
666 demuxer = OH_AVDemuxer_CreateWithSource(source);
667 ASSERT_NE(demuxer, nullptr);
668
669 sourceFormat = OH_AVSource_GetSourceFormat(source);
670 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
671 ASSERT_EQ(1, g_trackCount);
672
673 for (int32_t index = 0; index < g_trackCount; index++) {
674 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
675 }
676
677 int keyCount = 0;
678 while (!audioIsEnd) {
679 for (int32_t index = 0; index < g_trackCount; index++) {
680 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
681 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
682 audioIsEnd = true;
683 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
684 } else {
685 audioFrame++;
686 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
687 keyCount++;
688 }
689 }
690 }
691 }
692 ASSERT_EQ(audioFrame, 2288);
693 ASSERT_EQ(keyCount, 2288);
694 close(fd);
695 }
696
697 /**
698 * @tc.number : DEMUXER_FUNCTION_1600
699 * @tc.name : demux wav
700 * @tc.desc : function test
701 */
702 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1600, TestSize.Level0)
703 {
704 OH_AVCodecBufferAttr attr;
705 bool audioIsEnd = false;
706 int audioFrame = 0;
707
708 const char *file = "/data/test/media/audio/wav_48000_1.wav";
709 int fd = open(file, O_RDONLY);
710 int64_t size = GetFileSize(file);
711 cout << file << "----------------------" << fd << "---------" << size << endl;
712 source = OH_AVSource_CreateWithFD(fd, 0, size);
713 ASSERT_NE(source, nullptr);
714
715 demuxer = OH_AVDemuxer_CreateWithSource(source);
716 ASSERT_NE(demuxer, nullptr);
717
718 sourceFormat = OH_AVSource_GetSourceFormat(source);
719 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
720 ASSERT_EQ(1, g_trackCount);
721
722 for (int32_t index = 0; index < g_trackCount; index++) {
723 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
724 }
725
726 int keyCount = 0;
727 while (!audioIsEnd) {
728 for (int32_t index = 0; index < g_trackCount; index++) {
729 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
730 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
731 audioIsEnd = true;
732 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
733 } else {
734 audioFrame++;
735 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
736 keyCount++;
737 }
738 }
739 }
740 }
741 ASSERT_EQ(audioFrame, 5146);
742 ASSERT_EQ(keyCount, 5146);
743 close(fd);
744 }
745
746 /**
747 * @tc.number : DEMUXER_FUNCTION_1700
748 * @tc.name : demux mpeg-ts
749 * @tc.desc : function test
750 */
751 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1700, TestSize.Level0)
752 {
753 int tarckType = 0;
754 OH_AVCodecBufferAttr attr;
755 bool audioIsEnd = false;
756 bool videoIsEnd = false;
757 int audioFrame = 0;
758 int videoFrame = 0;
759 const char *file = "/data/test/media/ts_video.ts";
760 int fd = open(file, O_RDONLY);
761 int64_t size = GetFileSize(file);
762 cout << file << "----------------------" << fd << "---------" << size << endl;
763 source = OH_AVSource_CreateWithFD(fd, 0, size);
764 ASSERT_NE(source, nullptr);
765
766 demuxer = OH_AVDemuxer_CreateWithSource(source);
767 ASSERT_NE(demuxer, nullptr);
768
769 sourceFormat = OH_AVSource_GetSourceFormat(source);
770 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
771 ASSERT_EQ(2, g_trackCount);
772
773 for (int32_t index = 0; index < g_trackCount; index++) {
774 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
775 }
776
777 int vKeyCount = 0;
778 int aKeyCount = 0;
779 while (!audioIsEnd || !videoIsEnd) {
780 for (int32_t index = 0; index < g_trackCount; index++) {
781
782 trackFormat = OH_AVSource_GetTrackFormat(source, index);
783 ASSERT_NE(trackFormat, nullptr);
784 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
785
786 if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
787 continue;
788 }
789 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
790
791 if (tarckType == 0) {
792 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
793 audioIsEnd = true;
794 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
795 } else {
796 audioFrame++;
797 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
798 aKeyCount++;
799 }
800 }
801 } else if (tarckType == 1) {
802 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
803 videoIsEnd = true;
804 cout << videoFrame << " video is end !!!!!!!!!!!!!!!" << endl;
805 } else {
806 videoFrame++;
807 cout << "video track !!!!!" << endl;
808 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
809 vKeyCount++;
810 }
811 }
812 }
813 }
814 }
815 ASSERT_EQ(audioFrame, 384);
816 ASSERT_EQ(aKeyCount, 384);
817 ASSERT_EQ(videoFrame, 602);
818 ASSERT_EQ(vKeyCount, 51);
819 close(fd);
820 }
821
822 /**
823 * @tc.number : DEMUXER_FUNCTION_1800
824 * @tc.name : demux unsupported source
825 * @tc.desc : function test
826 */
827 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1800, TestSize.Level2)
828 {
829 const char *file = "/data/test/media/mkv.mkv";
830 int fd = open(file, O_RDONLY);
831 int64_t size = GetFileSize(file);
832 cout << file << "----------------------" << fd << "---------" << size << endl;
833 source = OH_AVSource_CreateWithFD(fd, 0, size);
834 ASSERT_EQ(source, nullptr);
835 close(fd);
836 }
837
838 /**
839 * @tc.number : DEMUXER_FUNCTION_1900
840 * @tc.name : demux mp4, zero track
841 * @tc.desc : function test
842 */
843 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1900, TestSize.Level1)
844 {
845 const char *file = "/data/test/media/zero_track.mp4";
846 int fd = open(file, O_RDONLY);
847 int64_t size = GetFileSize(file);
848 cout << file << "----------------------" << fd << "---------" << size << endl;
849 source = OH_AVSource_CreateWithFD(fd, 0, size);
850 ASSERT_NE(source, nullptr);
851 demuxer = OH_AVDemuxer_CreateWithSource(source);
852 ASSERT_NE(demuxer, nullptr);
853
854 sourceFormat = OH_AVSource_GetSourceFormat(source);
855 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
856 ASSERT_EQ(g_trackCount, 0);
857
858 ASSERT_EQ(AV_ERR_INVALID_VAL, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
859 close(fd);
860 }
861
862 /**
863 * @tc.number : DEMUXER_FUNCTION_2000
864 * @tc.name : OH_AVSource_CreateWithFD test
865 * @tc.desc : function test
866 */
867 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_2000, TestSize.Level0)
868 {
869 OH_AVCodecBufferAttr attr;
870 bool audioIsEnd = false;
871 int audioFrame = 0;
872
873 const char *file1 = "/data/test/media/audio/MP3_48000_1.mp3";
874 int64_t size1 = GetFileSize(file1);
875
876 const char *file = "/data/test/media/MP3_avcc_10sec.bin";
877 int fd = open(file, O_RDONLY);
878 int64_t size = GetFileSize(file);
879 cout << file << "----------------------" << fd << "---------" << size << endl;
880 source = OH_AVSource_CreateWithFD(fd, 0, size1);
881 ASSERT_NE(source, nullptr);
882
883 demuxer = OH_AVDemuxer_CreateWithSource(source);
884 ASSERT_NE(demuxer, nullptr);
885
886 sourceFormat = OH_AVSource_GetSourceFormat(source);
887 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
888 ASSERT_EQ(1, g_trackCount);
889
890 for (int32_t index = 0; index < g_trackCount; index++) {
891 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
892 }
893
894 int keyCount = 0;
895 while (!audioIsEnd) {
896 for (int32_t index = 0; index < g_trackCount; index++) {
897 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
898 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
899 audioIsEnd = true;
900 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
901 } else {
902 audioFrame++;
903 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
904 keyCount++;
905 }
906 }
907 }
908 }
909 ASSERT_EQ(audioFrame, 9150);
910 ASSERT_EQ(keyCount, 9150);
911 close(fd);
912 }
913
914 /**
915 * @tc.number : DEMUXER_FUNCTION_2100
916 * @tc.name : OH_AVSource_CreateWithFD test
917 * @tc.desc : function test
918 */
919 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_2100, TestSize.Level0)
920 {
921 OH_AVCodecBufferAttr attr;
922 bool audioIsEnd = false;
923 bool videoIsEnd = false;
924 int audioFrame = 0;
925 int videoFrame = 0;
926 const char *file1 = "/data/test/media/audio/MP3_48000_1.mp3";
927 int64_t size1 = GetFileSize(file1);
928
929 const char *file2 = "/data/test/media/avcc_10sec.mp4";
930 int64_t size2 = GetFileSize(file2);
931
932 const char *file = "/data/test/media/MP3_avcc_10sec.bin";
933 int fd = open(file, O_RDONLY);
934 int64_t size = GetFileSize(file);
935 cout << file << "----------------------" << fd << "---------" << size << endl;
936 source = OH_AVSource_CreateWithFD(fd, size1, size2);
937 ASSERT_NE(source, nullptr);
938
939 demuxer = OH_AVDemuxer_CreateWithSource(source);
940 ASSERT_NE(demuxer, nullptr);
941
942 sourceFormat = OH_AVSource_GetSourceFormat(source);
943 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
944 ASSERT_EQ(2, g_trackCount);
945
946 for (int32_t index = 0; index < g_trackCount; index++) {
947 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
948 }
949 int tarckType = 0;
950 int aKeyCount = 0;
951 int vKeyCount = 0;
952 while (!audioIsEnd || !videoIsEnd) {
953 for (int32_t index = 0; index < g_trackCount; index++) {
954
955 trackFormat = OH_AVSource_GetTrackFormat(source, index);
956 ASSERT_NE(trackFormat, nullptr);
957 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
958
959 if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
960 continue;
961 }
962 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
963
964 if (tarckType == 0) {
965 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
966 audioIsEnd = true;
967 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
968 } else {
969 audioFrame++;
970 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
971 aKeyCount++;
972 }
973 }
974 } else if (tarckType == 1) {
975 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
976 videoIsEnd = true;
977 cout << videoFrame << " video is end !!!!!!!!!!!!!!!" << endl;
978 } else {
979 videoFrame++;
980 cout << "video track !!!!!" << endl;
981 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
982 vKeyCount++;
983 }
984 }
985 }
986 }
987 }
988 ASSERT_EQ(audioFrame, 431);
989 ASSERT_EQ(videoFrame, 600);
990 ASSERT_EQ(aKeyCount, 431);
991 ASSERT_EQ(vKeyCount, 10);
992 close(fd);
993 }
994
995 /**
996 * @tc.number : DEMUXER_FUNCTION_2200
997 * @tc.name : OH_AVSource_CreateWithFD test
998 * @tc.desc : function test
999 */
1000 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_2200, TestSize.Level0)
1001 {
1002 OH_AVCodecBufferAttr attr;
1003 bool audioIsEnd = false;
1004 int audioFrame = 0;
1005
1006 const char *file1 = "/data/test/media/audio/MP3_48000_1.mp3";
1007 int64_t size1 = GetFileSize(file1);
1008
1009 const char *file = "/data/test/media/MP3_OGG_48000_1.bin";
1010 int fd = open(file, O_RDONLY);
1011 int64_t size = GetFileSize(file);
1012 cout << file << "----------------------" << fd << "---------" << size << endl;
1013 source = OH_AVSource_CreateWithFD(fd, 0, size1);
1014 ASSERT_NE(source, nullptr);
1015
1016 demuxer = OH_AVDemuxer_CreateWithSource(source);
1017 ASSERT_NE(demuxer, nullptr);
1018
1019 sourceFormat = OH_AVSource_GetSourceFormat(source);
1020 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1021 ASSERT_EQ(1, g_trackCount);
1022
1023 for (int32_t index = 0; index < g_trackCount; index++) {
1024 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1025 }
1026
1027 int keyCount = 0;
1028 while (!audioIsEnd) {
1029 for (int32_t index = 0; index < g_trackCount; index++) {
1030 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1031 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1032 audioIsEnd = true;
1033 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
1034 } else {
1035 audioFrame++;
1036 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
1037 keyCount++;
1038 }
1039 }
1040 }
1041 }
1042 ASSERT_EQ(audioFrame, 9150);
1043 ASSERT_EQ(keyCount, 9150);
1044 close(fd);
1045 }
1046
1047 /**
1048 * @tc.number : DEMUXER_FUNCTION_2300
1049 * @tc.name : OH_AVSource_CreateWithFD test
1050 * @tc.desc : function test
1051 */
1052 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_2300, TestSize.Level0)
1053 {
1054 OH_AVCodecBufferAttr attr;
1055 bool audioIsEnd = false;
1056 int audioFrame = 0;
1057
1058 const char *file1 = "/data/test/media/audio/MP3_48000_1.mp3";
1059 int64_t size1 = GetFileSize(file1);
1060
1061 const char *file2 = "/data/test/media/audio/OGG_48000_1.ogg";
1062 int64_t size2 = GetFileSize(file2);
1063
1064 const char *file = "/data/test/media/MP3_OGG_48000_1.bin";
1065 int fd = open(file, O_RDONLY);
1066 int64_t size = GetFileSize(file);
1067 cout << file << "----------------------" << fd << "---------" << size << endl;
1068 source = OH_AVSource_CreateWithFD(fd, size1, size2);
1069 ASSERT_NE(source, nullptr);
1070
1071 demuxer = OH_AVDemuxer_CreateWithSource(source);
1072 ASSERT_NE(demuxer, nullptr);
1073
1074 sourceFormat = OH_AVSource_GetSourceFormat(source);
1075 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1076 ASSERT_EQ(1, g_trackCount);
1077
1078 for (int32_t index = 0; index < g_trackCount; index++) {
1079 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1080 }
1081
1082 int keyCount = 0;
1083 while (!audioIsEnd) {
1084 for (int32_t index = 0; index < g_trackCount; index++) {
1085 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1086 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1087 audioIsEnd = true;
1088 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
1089 } else {
1090 audioFrame++;
1091 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
1092 keyCount++;
1093 }
1094 }
1095 }
1096 }
1097 ASSERT_EQ(audioFrame, 11439);
1098 ASSERT_EQ(keyCount, 11439);
1099 close(fd);
1100 }
1101
1102 /**
1103 * @tc.number : DEMUXER_FUNCTION_2400
1104 * @tc.name : OH_AVSource_CreateWithFD test
1105 * @tc.desc : function test
1106 */
1107 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_2400, TestSize.Level0)
1108 {
1109 OH_AVCodecBufferAttr attr;
1110 bool audioIsEnd = false;
1111 bool videoIsEnd = false;
1112 int audioFrame = 0;
1113 int videoFrame = 0;
1114 const char *file1 = "/data/test/media/ts_video.ts";
1115 int64_t size1 = GetFileSize(file1);
1116
1117 const char *file = "/data/test/media/test_video_avcc_10sec.bin";
1118 int fd = open(file, O_RDONLY);
1119 int64_t size = GetFileSize(file);
1120 cout << file << "----------------------" << fd << "---------" << size << endl;
1121 source = OH_AVSource_CreateWithFD(fd, 0, size1);
1122 ASSERT_NE(source, nullptr);
1123
1124 demuxer = OH_AVDemuxer_CreateWithSource(source);
1125 ASSERT_NE(demuxer, nullptr);
1126
1127 sourceFormat = OH_AVSource_GetSourceFormat(source);
1128 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1129 ASSERT_EQ(2, g_trackCount);
1130
1131 for (int32_t index = 0; index < g_trackCount; index++) {
1132 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1133 }
1134 int tarckType = 0;
1135 int aKeyCount = 0;
1136 int vKeyCount = 0;
1137 while (!audioIsEnd || !videoIsEnd) {
1138 for (int32_t index = 0; index < g_trackCount; index++) {
1139
1140 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1141 ASSERT_NE(trackFormat, nullptr);
1142 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1143
1144 if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
1145 continue;
1146 }
1147 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1148
1149 if (tarckType == 0) {
1150 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1151 audioIsEnd = true;
1152 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
1153 } else {
1154 audioFrame++;
1155 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
1156 aKeyCount++;
1157 }
1158 }
1159 } else if (tarckType == 1) {
1160 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1161 videoIsEnd = true;
1162 cout << videoFrame << " video is end !!!!!!!!!!!!!!!" << endl;
1163 } else {
1164 videoFrame++;
1165 cout << "video track !!!!!" << endl;
1166 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
1167 vKeyCount++;
1168 }
1169 }
1170 }
1171 }
1172 }
1173 ASSERT_EQ(audioFrame, 384);
1174 ASSERT_EQ(videoFrame, 602);
1175 ASSERT_EQ(aKeyCount, 384);
1176 ASSERT_EQ(vKeyCount, 51);
1177 close(fd);
1178 }
1179
1180 /**
1181 * @tc.number : DEMUXER_FUNCTION_3100
1182 * @tc.name : seek to the start time, previous mode
1183 * @tc.desc : function test
1184 */
1185 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3100, TestSize.Level1)
1186 {
1187 uint32_t trackIndex = 0;
1188 OH_AVCodecBufferAttr attr;
1189 const char *file = "/data/test/media/01_video_audio.mp4";
1190 int count = 0;
1191 srand(time(nullptr));
1192 int fd = open(file, O_RDONLY);
1193 int64_t size = GetFileSize(file);
1194 cout << file << "----------------------" << fd << "---------" << size << endl;
1195 source = OH_AVSource_CreateWithFD(fd, 0, size);
1196 ASSERT_NE(source, nullptr);
1197
1198 demuxer = OH_AVDemuxer_CreateWithSource(source);
1199 ASSERT_NE(demuxer, nullptr);
1200
1201 int pos = rand() % 250;
1202 int64_t startPts = 0;
1203 bool isFirstFrame = true;
1204 bool isEnd = false;
1205 sourceFormat = OH_AVSource_GetSourceFormat(source);
1206 ASSERT_NE(sourceFormat, nullptr);
1207 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1208 cout << g_trackCount << "####################" << endl;
1209
1210 for (int32_t index = 0; index < g_trackCount; index++) {
1211 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1212 }
1213
1214 while (!isEnd) {
1215 for (int32_t index = 0; index < g_trackCount; index++) {
1216 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1217
1218 if (isFirstFrame) {
1219 startPts = attr.pts;
1220 isFirstFrame = false;
1221 }
1222 if (count == pos) {
1223 isEnd = true;
1224 cout << pos << " =====curr_pts = attr.pts" << endl;
1225 break;
1226 }
1227 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1228 isEnd = true;
1229 cout << "is end!!!!!!!!" << endl;
1230 }
1231 count++;
1232 }
1233 cout << "count: " << count << endl;
1234 }
1235 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, startPts / 1000, SEEK_MODE_PREVIOUS_SYNC));
1236 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &attr));
1237 ASSERT_EQ(attr.pts, startPts);
1238 close(fd);
1239 }
1240
1241 /**
1242 * @tc.number : DEMUXER_FUNCTION_3200
1243 * @tc.name : seek to the start time, next mode
1244 * @tc.desc : function test
1245 */
1246 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3200, TestSize.Level1)
1247 {
1248 bool isEnd = false;
1249 uint32_t trackIndex = 0;
1250 OH_AVCodecBufferAttr attr;
1251 const char *file = "/data/test/media/01_video_audio.mp4";
1252 int count = 0;
1253 srand(time(nullptr));
1254 int fd = open(file, O_RDONLY);
1255 int64_t size = GetFileSize(file);
1256 cout << file << "----------------------" << fd << "---------" << size << endl;
1257 source = OH_AVSource_CreateWithFD(fd, 0, size);
1258 ASSERT_NE(source, nullptr);
1259
1260 demuxer = OH_AVDemuxer_CreateWithSource(source);
1261 ASSERT_NE(demuxer, nullptr);
1262
1263 int pos = rand() % 250;
1264 int64_t startPts = 0;
1265 bool isFirstFrame = true;
1266 sourceFormat = OH_AVSource_GetSourceFormat(source);
1267 ASSERT_NE(sourceFormat, nullptr);
1268 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1269
1270 for (int32_t index = 0; index < g_trackCount; index++) {
1271 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1272 }
1273
1274 while (!isEnd) {
1275 for (int32_t index = 0; index < g_trackCount; index++) {
1276 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1277
1278 if (isFirstFrame) {
1279 startPts = attr.pts;
1280 isFirstFrame = false;
1281 }
1282 if (count == pos) {
1283 isEnd = true;
1284 cout << "curr_pts = attr.pts" << endl;
1285 break;
1286 }
1287 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1288 isEnd = true;
1289 cout << "is end!!!!!!!!" << endl;
1290 }
1291 count++;
1292 }
1293 cout << "count: " << count << endl;
1294 }
1295
1296 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, startPts / 1000, SEEK_MODE_NEXT_SYNC));
1297 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &attr));
1298 ASSERT_EQ(attr.pts, startPts);
1299 close(fd);
1300 }
1301
1302 /**
1303 * @tc.number : DEMUXER_FUNCTION_3300
1304 * @tc.name : seek to the start time, closest mode
1305 * @tc.desc : function test
1306 */
1307 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3300, TestSize.Level1)
1308 {
1309 bool isEnd = false;
1310 uint32_t trackIndex = 0;
1311 OH_AVCodecBufferAttr attr;
1312 const char *file = "/data/test/media/01_video_audio.mp4";
1313 int count = 0;
1314 srand(time(nullptr));
1315 int fd = open(file, O_RDONLY);
1316 int64_t size = GetFileSize(file);
1317 cout << file << "----------------------" << fd << "---------" << size << endl;
1318 source = OH_AVSource_CreateWithFD(fd, 0, size);
1319 ASSERT_NE(source, nullptr);
1320
1321 demuxer = OH_AVDemuxer_CreateWithSource(source);
1322 ASSERT_NE(demuxer, nullptr);
1323
1324 int pos = rand() % 250;
1325 int64_t startPts = 0;
1326 bool isFirstFrame = true;
1327 sourceFormat = OH_AVSource_GetSourceFormat(source);
1328 ASSERT_NE(sourceFormat, nullptr);
1329 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1330
1331 for (int32_t index = 0; index < g_trackCount; index++) {
1332 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1333 }
1334
1335 while (!isEnd) {
1336 for (int32_t index = 0; index < g_trackCount; index++) {
1337 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1338
1339 if (isFirstFrame) {
1340 startPts = attr.pts;
1341 isFirstFrame = false;
1342 }
1343 if (count == pos) {
1344 isEnd = true;
1345 cout << "curr_pts = attr.pts" << endl;
1346 break;
1347 }
1348 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1349 isEnd = true;
1350 cout << "is end!!!!!!!!" << endl;
1351 }
1352 count++;
1353 }
1354 cout << "count: " << count << endl;
1355 }
1356 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, startPts / 1000, SEEK_MODE_CLOSEST_SYNC));
1357 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &attr));
1358 ASSERT_EQ(attr.pts, startPts);
1359 close(fd);
1360 }
1361
1362 /**
1363 * @tc.number : DEMUXER_FUNCTION_3400
1364 * @tc.name : seek to the end time, previous mode
1365 * @tc.desc : function test
1366 */
1367 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3400, TestSize.Level1)
1368 {
1369 bool isEnd = false;
1370 uint32_t trackIndex = 1;
1371 OH_AVCodecBufferAttr attr;
1372 const char *file = "/data/test/media/01_video_audio.mp4";
1373 int count = 0;
1374 srand(time(nullptr));
1375 int fd = open(file, O_RDONLY);
1376 int64_t size = GetFileSize(file);
1377 cout << file << "----------------------" << fd << "---------" << size << endl;
1378 source = OH_AVSource_CreateWithFD(fd, 0, size);
1379 ASSERT_NE(source, nullptr);
1380
1381 demuxer = OH_AVDemuxer_CreateWithSource(source);
1382 ASSERT_NE(demuxer, nullptr);
1383
1384 sourceFormat = OH_AVSource_GetSourceFormat(source);
1385 ASSERT_NE(sourceFormat, nullptr);
1386 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1387 cout << g_trackCount << "####################" << endl;
1388
1389 for (int32_t index = 0; index < g_trackCount; index++) {
1390 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1391 }
1392
1393 int64_t endPts = 0;
1394 while (!isEnd) {
1395 for (int32_t index = 0; index < g_trackCount; index++) {
1396 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1397
1398 if (static_cast<uint32_t>(index) != trackIndex) {
1399 continue;
1400 }
1401 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1402 isEnd = true;
1403 cout << "is end!!!!!!!!" << endl;
1404 } else {
1405 endPts = attr.pts;
1406 }
1407 count++;
1408 }
1409 cout << "count: " << count << endl;
1410 }
1411 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, endPts / 1000, SEEK_MODE_PREVIOUS_SYNC));
1412 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &attr));
1413 ASSERT_EQ(attr.pts, endPts);
1414 close(fd);
1415 }
1416
1417 /**
1418 * @tc.number : DEMUXER_FUNCTION_3500
1419 * @tc.name : seek to the end time, next mode
1420 * @tc.desc : function test
1421 */
1422 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3500, TestSize.Level1)
1423 {
1424 bool isEnd = false;
1425 uint32_t trackIndex = 1;
1426 OH_AVCodecBufferAttr attr;
1427 const char *file = "/data/test/media/01_video_audio.mp4";
1428 int count = 0;
1429 srand(time(nullptr));
1430 int fd = open(file, O_RDONLY);
1431 int64_t size = GetFileSize(file);
1432 cout << file << "----------------------" << fd << "---------" << size << endl;
1433 source = OH_AVSource_CreateWithFD(fd, 0, size);
1434 ASSERT_NE(source, nullptr);
1435
1436 demuxer = OH_AVDemuxer_CreateWithSource(source);
1437 ASSERT_NE(demuxer, nullptr);
1438 sourceFormat = OH_AVSource_GetSourceFormat(source);
1439 ASSERT_NE(sourceFormat, nullptr);
1440 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1441 cout << g_trackCount << "####################" << endl;
1442
1443 for (int32_t index = 0; index < g_trackCount; index++) {
1444 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1445 }
1446 int64_t endPts = 0;
1447 while (!isEnd) {
1448 for (int32_t index = 0; index < g_trackCount; index++) {
1449 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1450 if (static_cast<uint32_t>(index) != trackIndex) {
1451 continue;
1452 }
1453 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1454 isEnd = true;
1455 cout << "is end!!!!!!!!" << endl;
1456 } else {
1457 endPts = attr.pts;
1458 }
1459 count++;
1460 }
1461 cout << "count: " << count << endl;
1462 }
1463 // end I
1464 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, endPts / 1000, SEEK_MODE_NEXT_SYNC));
1465 endPts += 1000;
1466 ASSERT_EQ(AV_ERR_UNKNOWN, OH_AVDemuxer_SeekToTime(demuxer, endPts / 1000, SEEK_MODE_NEXT_SYNC));
1467 endPts += 1000000;
1468 ASSERT_EQ(AV_ERR_OPERATE_NOT_PERMIT, OH_AVDemuxer_SeekToTime(demuxer, endPts / 1000, SEEK_MODE_NEXT_SYNC));
1469 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &attr));
1470 close(fd);
1471 }
1472
1473 /**
1474 * @tc.number : DEMUXER_FUNCTION_3600
1475 * @tc.name : seek to the end time, closest mode
1476 * @tc.desc : function test
1477 */
1478 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3600, TestSize.Level1)
1479 {
1480 bool isEnd = false;
1481 uint32_t trackIndex = 1;
1482 OH_AVCodecBufferAttr attr;
1483 const char *file = "/data/test/media/01_video_audio.mp4";
1484 int count = 0;
1485 srand(time(nullptr));
1486 int fd = open(file, O_RDONLY);
1487 int64_t size = GetFileSize(file);
1488 cout << file << "----------------------" << fd << "---------" << size << endl;
1489 source = OH_AVSource_CreateWithFD(fd, 0, size);
1490 ASSERT_NE(source, nullptr);
1491
1492 demuxer = OH_AVDemuxer_CreateWithSource(source);
1493 ASSERT_NE(demuxer, nullptr);
1494 sourceFormat = OH_AVSource_GetSourceFormat(source);
1495 ASSERT_NE(sourceFormat, nullptr);
1496 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1497 cout << g_trackCount << "####################" << endl;
1498
1499 for (int32_t index = 0; index < g_trackCount; index++) {
1500 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1501 }
1502
1503 int64_t endPts = 0;
1504 while (!isEnd) {
1505 for (int32_t index = 0; index < g_trackCount; index++) {
1506 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1507 if (static_cast<uint32_t>(index) != trackIndex) {
1508 continue;
1509 }
1510 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1511 isEnd = true;
1512 cout << "is end!!!!!!!!" << endl;
1513 } else {
1514 endPts = attr.pts;
1515 }
1516 count++;
1517 }
1518 cout << "count: " << count << endl;
1519 }
1520 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, endPts / 1000, SEEK_MODE_CLOSEST_SYNC));
1521 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &attr));
1522 ASSERT_EQ(attr.pts, endPts);
1523 close(fd);
1524 }
1525
1526 /**
1527 * @tc.number : DEMUXER_FUNCTION_3700
1528 * @tc.name : seek to a random time, previous mode
1529 * @tc.desc : function test
1530 */
1531 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3700, TestSize.Level0)
1532 {
1533 bool isFirstFrame = true;
1534 uint32_t trackIndex = 1;
1535 int count = 0;
1536 srand(time(nullptr));
1537 int pos = rand() % 250;
1538 int posTo = rand() % 250;
1539 int64_t toMs = posTo * 40000;
1540 cout << "pos: " << pos << "posTo: " << posTo << "toMs: " << toMs << endl;
1541 int tarckType = 0;
1542 OH_AVCodecBufferAttr attr;
1543 bool audioIsEnd = false;
1544 bool videoIsEnd = false;
1545 int audioFrame = 0;
1546 int videoFrame = 0;
1547 const char *file = "/data/test/media/01_video_audio.mp4";
1548 int fd = open(file, O_RDONLY);
1549 int64_t size = GetFileSize(file);
1550 cout << file << "----------------------" << fd << "---------" << size << endl;
1551 source = OH_AVSource_CreateWithFD(fd, 0, size);
1552 ASSERT_NE(source, nullptr);
1553
1554 demuxer = OH_AVDemuxer_CreateWithSource(source);
1555 ASSERT_NE(demuxer, nullptr);
1556
1557 sourceFormat = OH_AVSource_GetSourceFormat(source);
1558 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1559 ASSERT_EQ(2, g_trackCount);
1560
1561 for (int32_t index = 0; index < g_trackCount; index++) {
1562 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1563 }
1564
1565 while (!audioIsEnd || !videoIsEnd) {
1566 for (int32_t index = 0; index < g_trackCount; index++) {
1567 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1568 ASSERT_NE(trackFormat, nullptr);
1569 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1570
1571 if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
1572 continue;
1573 }
1574 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1575 if (isFirstFrame) {
1576 isFirstFrame = false;
1577 }
1578
1579 if (count == pos) {
1580 videoIsEnd = true;
1581 audioIsEnd = true;
1582 cout << "curr_pts = attr.pts" << endl;
1583 break;
1584 }
1585
1586 if (tarckType == 0 && attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1587 audioIsEnd = true;
1588 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
1589 }
1590 if (tarckType == 1 && attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1591 videoIsEnd = true;
1592 cout << videoFrame << " video is end !!!!!!!!!!!!!!!" << endl;
1593 }
1594 }
1595 count++;
1596 }
1597 cout << "count: " << count << endl;
1598 int64_t prevIdrPts = toMs;
1599 ret = OH_AVDemuxer_SeekToTime(demuxer, toMs / 1000, SEEK_MODE_PREVIOUS_SYNC);
1600 ASSERT_EQ(ret, AV_ERR_OK);
1601 ret = OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &attr);
1602 ASSERT_EQ(ret, AV_ERR_OK);
1603 bool ans = abs(prevIdrPts - attr.pts) < 40000 ? true : false;
1604 ASSERT_EQ(ans, true);
1605 close(fd);
1606 }
1607
1608 /**
1609 * @tc.number : DEMUXER_FUNCTION_3800
1610 * @tc.name : seek to a random time, next mode
1611 * @tc.desc : function test
1612 */
1613 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3800, TestSize.Level0)
1614 {
1615 bool isEnd = false;
1616 bool isFirstFrame = true;
1617 uint32_t trackIndex = 1;
1618 OH_AVCodecBufferAttr attr;
1619 const char *file = "/data/test/media/01_video_audio.mp4";
1620 int count = 0;
1621 srand(time(nullptr));
1622 int fd = open(file, O_RDONLY);
1623 int64_t size = GetFileSize(file);
1624 cout << file << "----------------------" << fd << "---------" << size << endl;
1625 source = OH_AVSource_CreateWithFD(fd, 0, size);
1626 ASSERT_NE(source, nullptr);
1627
1628 demuxer = OH_AVDemuxer_CreateWithSource(source);
1629 ASSERT_NE(demuxer, nullptr);
1630 sourceFormat = OH_AVSource_GetSourceFormat(source);
1631 ASSERT_NE(sourceFormat, nullptr);
1632 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1633
1634 for (int32_t index = 0; index < g_trackCount; index++) {
1635 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1636 }
1637 int pos = rand() % 250;
1638 int posTo = rand() % 250;
1639 int64_t toMs = posTo * 40000;
1640 while (!isEnd) {
1641 for (int32_t index = 0; index < g_trackCount; index++) {
1642 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1643 if (isFirstFrame) {
1644 isFirstFrame = false;
1645 }
1646 if (count == pos) {
1647 isEnd = true;
1648 break;
1649 }
1650 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1651 isEnd = true;
1652 }
1653 count++;
1654 }
1655 }
1656 int64_t nextIdrPts = toMs;
1657 ret = OH_AVDemuxer_SeekToTime(demuxer, toMs / 1000, SEEK_MODE_NEXT_SYNC);
1658 ASSERT_EQ(ret, AV_ERR_OK);
1659 ret = OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &attr);
1660 ASSERT_EQ(ret, AV_ERR_OK);
1661 bool ans = abs(nextIdrPts - attr.pts) < 40000 ? true : false;
1662 ASSERT_EQ(ans, true);
1663 close(fd);
1664 }
1665
1666 /**
1667 * @tc.number : DEMUXER_FUNCTION_3900
1668 * @tc.name : seek to a random time, closest mode
1669 * @tc.desc : function test
1670 */
1671 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3900, TestSize.Level0)
1672 {
1673 bool isEnd = false;
1674 bool isFirstFrame = true;
1675 uint32_t trackIndex = 1;
1676 OH_AVCodecBufferAttr attr;
1677 const char *file = "/data/test/media/01_video_audio.mp4";
1678 int count = 0;
1679 srand(time(nullptr));
1680 int fd = open(file, O_RDONLY);
1681 int64_t size = GetFileSize(file);
1682 cout << file << "----------------------" << fd << "---------" << size << endl;
1683 source = OH_AVSource_CreateWithFD(fd, 0, size);
1684 ASSERT_NE(source, nullptr);
1685
1686 demuxer = OH_AVDemuxer_CreateWithSource(source);
1687 ASSERT_NE(demuxer, nullptr);
1688 sourceFormat = OH_AVSource_GetSourceFormat(source);
1689 ASSERT_NE(sourceFormat, nullptr);
1690 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1691
1692 for (int32_t index = 0; index < g_trackCount; index++) {
1693 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1694 }
1695 int pos = rand() % 250;
1696 int posTo = rand() % 250;
1697 int64_t toMs = posTo * 40000;
1698 while (!isEnd) {
1699 for (int32_t index = 0; index < g_trackCount; index++) {
1700 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1701 if (isFirstFrame) {
1702 isFirstFrame = false;
1703 }
1704 if (count == pos) {
1705 isEnd = true;
1706 cout << "curr_pts = attr.pts" << endl;
1707 break;
1708 }
1709 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1710 isEnd = true;
1711 }
1712 count++;
1713 }
1714 }
1715 int64_t closestIdrPts = toMs;
1716 ret = OH_AVDemuxer_SeekToTime(demuxer, toMs / 1000, SEEK_MODE_CLOSEST_SYNC);
1717 ASSERT_EQ(ret, AV_ERR_OK);
1718 ret = OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &attr);
1719 ASSERT_EQ(ret, AV_ERR_OK);
1720 bool ans = abs(closestIdrPts - attr.pts) < 40000 ? true : false;
1721 ASSERT_EQ(ans, true);
1722 close(fd);
1723 }
1724
1725 /**
1726 * @tc.number : DEMUXER_FUNCTION_4000
1727 * @tc.name : seek to a invalid time, closest mode
1728 * @tc.desc : function test
1729 */
1730 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_4000, TestSize.Level2)
1731 {
1732 const char *file = "/data/test/media/01_video_audio.mp4";
1733 srand(time(nullptr));
1734 int fd = open(file, O_RDONLY);
1735 int64_t size = GetFileSize(file);
1736 cout << file << "----------------------" << fd << "---------" << size << endl;
1737 source = OH_AVSource_CreateWithFD(fd, 0, size);
1738 ASSERT_NE(source, nullptr);
1739
1740 demuxer = OH_AVDemuxer_CreateWithSource(source);
1741 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
1742
1743 ASSERT_NE(demuxer, nullptr);
1744 int64_t invalidPts = 12000 * 16666;
1745 ret = OH_AVDemuxer_SeekToTime(demuxer, invalidPts, SEEK_MODE_CLOSEST_SYNC);
1746 ASSERT_NE(ret, AV_ERR_OK);
1747 close(fd);
1748 }
1749
1750 /**
1751 * @tc.number : DEMUXER_FUNCTION_4100
1752 * @tc.name : remove track before add track
1753 * @tc.desc : function test
1754 */
1755 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_4100, TestSize.Level2)
1756 {
1757 const char *file = "/data/test/media/01_video_audio.mp4";
1758 srand(time(nullptr));
1759 int fd = open(file, O_RDONLY);
1760 int64_t size = GetFileSize(file);
1761 cout << file << "----------------------" << fd << "---------" << size << endl;
1762 source = OH_AVSource_CreateWithFD(fd, 0, size);
1763 ASSERT_NE(source, nullptr);
1764
1765 demuxer = OH_AVDemuxer_CreateWithSource(source);
1766 ASSERT_NE(demuxer, nullptr);
1767 ret = OH_AVDemuxer_UnselectTrackByID(demuxer, 0);
1768 ASSERT_EQ(ret, AV_ERR_OK);
1769 ret = OH_AVDemuxer_SelectTrackByID(demuxer, 0);
1770 ASSERT_EQ(ret, AV_ERR_OK);
1771 close(fd);
1772 }
1773
1774 /**
1775 * @tc.number : DEMUXER_FUNCTION_4200
1776 * @tc.name : remove all tracks after demux finish
1777 * @tc.desc : function test
1778 */
1779 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_4200, TestSize.Level1)
1780 {
1781 OH_AVCodecBufferAttr attr;
1782 const char *file = "/data/test/media/01_video_audio.mp4";
1783 bool isEnd = false;
1784
1785 int fd = open(file, O_RDONLY);
1786 int64_t size = GetFileSize(file);
1787 cout << file << "----------------------" << fd << "---------" << size << endl;
1788 source = OH_AVSource_CreateWithFD(fd, 0, size);
1789 ASSERT_NE(source, nullptr);
1790
1791 demuxer = OH_AVDemuxer_CreateWithSource(source);
1792 ASSERT_NE(demuxer, nullptr);
1793
1794 sourceFormat = OH_AVSource_GetSourceFormat(source);
1795 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1796 ASSERT_EQ(2, g_trackCount);
1797 for (int32_t index = 0; index < g_trackCount; index++) {
1798 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1799 }
1800 while (!isEnd) {
1801 for (int32_t index = 0; index < g_trackCount; index++) {
1802 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1803 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1804 isEnd = true;
1805 cout << "is end !!!!!!!!!!!!!!!" << endl;
1806 }
1807 }
1808 }
1809
1810 for (int32_t index = 0; index < g_trackCount; index++) {
1811 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_UnselectTrackByID(demuxer, index));
1812 }
1813
1814 int32_t memorySize = OH_AVMemory_GetSize(memory);
1815 ASSERT_NE(0, memorySize);
1816 close(fd);
1817 }
1818
1819 /**
1820 * @tc.number : DEMUXER_FUNCTION_4300
1821 * @tc.name : remove all tracks before demux finish
1822 * @tc.desc : function test
1823 */
1824 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_4300, TestSize.Level1)
1825 {
1826 OH_AVCodecBufferAttr attr;
1827 const char *file = "/data/test/media/01_video_audio.mp4";
1828 bool isEnd = false;
1829 int count = 0;
1830 int fd = open(file, O_RDONLY);
1831 int64_t size = GetFileSize(file);
1832 cout << file << "----------------------" << fd << "---------" << size << endl;
1833 source = OH_AVSource_CreateWithFD(fd, 0, size);
1834 ASSERT_NE(source, nullptr);
1835
1836 demuxer = OH_AVDemuxer_CreateWithSource(source);
1837 ASSERT_NE(demuxer, nullptr);
1838
1839 sourceFormat = OH_AVSource_GetSourceFormat(source);
1840 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1841 ASSERT_EQ(2, g_trackCount);
1842 for (int32_t index = 0; index < g_trackCount; index++) {
1843 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1844 }
1845 srand(time(nullptr));
1846 int pos = rand() % 250;
1847 cout << " pos= " << pos << endl;
1848 while (!isEnd) {
1849 for (int32_t index = 0; index < g_trackCount; index++) {
1850 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1851 if (count == pos) {
1852 cout << count << " count == pos!!!!!!!!!" << endl;
1853 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_UnselectTrackByID(demuxer, 0));
1854 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_UnselectTrackByID(demuxer, 1));
1855 ASSERT_EQ(AV_ERR_OPERATE_NOT_PERMIT, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1856 isEnd = true;
1857 break;
1858 }
1859
1860 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1861 isEnd = true;
1862 cout << "is end !!!!!!!!!!!!!!!" << endl;
1863 }
1864 if (index == 0) {
1865 count++;
1866 }
1867 }
1868 }
1869 close(fd);
1870 }
1871
1872 /**
1873 * @tc.number : DEMUXER_FUNCTION_4400
1874 * @tc.name : remove audio track before demux finish
1875 * @tc.desc : function test
1876 */
1877 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_4400, TestSize.Level1)
1878 {
1879 OH_AVCodecBufferAttr attr;
1880 const char *file = "/data/test/media/01_video_audio.mp4";
1881
1882 int audioCount = 0;
1883 int fd = open(file, O_RDONLY);
1884 int64_t size = GetFileSize(file);
1885 cout << file << "----------------------" << fd << "---------" << size << endl;
1886 source = OH_AVSource_CreateWithFD(fd, 0, size);
1887 ASSERT_NE(source, nullptr);
1888
1889 demuxer = OH_AVDemuxer_CreateWithSource(source);
1890 ASSERT_NE(demuxer, nullptr);
1891
1892 sourceFormat = OH_AVSource_GetSourceFormat(source);
1893 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1894 ASSERT_EQ(2, g_trackCount);
1895 for (int32_t index = 0; index < g_trackCount; index++) {
1896 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1897 }
1898 srand(time(nullptr));
1899 int pos = rand() % 250;
1900 cout << " pos= " << pos << endl;
1901
1902 while (true) {
1903 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
1904 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 1, memory, &attr));
1905 if (audioCount == pos) {
1906 cout << audioCount << " audioCount == pos remove audio track!!!!!!!!!" << endl;
1907 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_UnselectTrackByID(demuxer, 1));
1908 ASSERT_NE(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 1, memory, &attr));
1909 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
1910 break;
1911 }
1912 audioCount++;
1913 }
1914
1915 while (true) {
1916 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
1917 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1918 cout << "is end !!!!!!!!!!!!!!!" << endl;
1919 break;
1920 }
1921 }
1922 close(fd);
1923 }
1924
1925 /**
1926 * @tc.number : DEMUXER_FUNCTION_4500
1927 * @tc.name : start demux bufore add track
1928 * @tc.desc : function test
1929 */
1930 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_4500, TestSize.Level2)
1931 {
1932 uint32_t trackIndex = 0;
1933 OH_AVCodecBufferAttr attr;
1934 const char *file = "/data/test/media/01_video_audio.mp4";
1935 srand(time(nullptr));
1936 int fd = open(file, O_RDONLY);
1937 int64_t size = GetFileSize(file);
1938 cout << file << "----------------------" << fd << "---------" << size << endl;
1939 source = OH_AVSource_CreateWithFD(fd, 0, size);
1940 ASSERT_NE(source, nullptr);
1941
1942 demuxer = OH_AVDemuxer_CreateWithSource(source);
1943 ASSERT_NE(demuxer, nullptr);
1944 ret = OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &attr);
1945 ASSERT_EQ(ret, AV_ERR_OPERATE_NOT_PERMIT);
1946 close(fd);
1947 }
1948
1949 /**
1950 * @tc.number : DEMUXER_FUNCTION_7000
1951 * @tc.name : demuxer MP4 ,GetSourceFormat,OH_MD_KEY_TRACK_COUNT
1952 * @tc.desc : function test
1953 */
1954 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_7000, TestSize.Level0)
1955 {
1956 OH_AVFormat *trackFormat2 = nullptr;
1957 const char *file = "/data/test/media/01_video_audio.mp4";
1958 int fd = open(file, O_RDONLY);
1959 int64_t size = GetFileSize(file);
1960 cout << file << "----------------------" << fd << "---------" << size << endl;
1961 source = OH_AVSource_CreateWithFD(fd, 0, size);
1962 ASSERT_NE(source, nullptr);
1963 sourceFormat = OH_AVSource_GetSourceFormat(source);
1964 ASSERT_NE(sourceFormat, nullptr);
1965 cout << OH_AVFormat_DumpInfo(sourceFormat) << "sourceFormat" << endl;
1966
1967 trackFormat = OH_AVSource_GetTrackFormat(source, 1);
1968 ASSERT_NE(trackFormat, nullptr);
1969 cout << OH_AVFormat_DumpInfo(trackFormat) << "trackformat1" << endl;
1970
1971 trackFormat2 = OH_AVSource_GetTrackFormat(source, 0);
1972 cout << OH_AVFormat_DumpInfo(trackFormat2) << "trackformat0" << endl;
1973
1974 close(fd);
1975 }
1976
1977 /**
1978 * @tc.number : DEMUXER_FUNCTION_7100
1979 * @tc.name : demuxer MP4 ,GetSourceFormat,OH_MD_KEY_TRACK_COUNT
1980 * @tc.desc : function test
1981 */
1982 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_7100, TestSize.Level0)
1983 {
1984 const char *file = "/data/test/media/01_video_audio.mp4";
1985 int fd = open(file, O_RDONLY);
1986 int64_t size = GetFileSize(file);
1987 cout << file << "----------------------" << fd << "---------" << size << endl;
1988 source = OH_AVSource_CreateWithFD(fd, 0, size);
1989 ASSERT_NE(source, nullptr);
1990
1991 sourceFormat = OH_AVSource_GetSourceFormat(source);
1992 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1993 ASSERT_EQ(g_trackCount, 2);
1994 close(fd);
1995 }
1996
1997 /**
1998 * @tc.number : DEMUXER_FUNCTION_7200
1999 * @tc.name : demuxer MP4 ,GetAudioTrackFormat,MD_KEY_AAC_IS_ADTS
2000 * @tc.desc : function test
2001 */
2002 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_7200, TestSize.Level0)
2003 {
2004 const char *stringVal;
2005 const char *file = "/data/test/media/01_video_audio.mp4";
2006 int fd = open(file, O_RDONLY);
2007 int64_t size = GetFileSize(file);
2008 cout << file << "----------------------" << fd << "---------" << size << endl;
2009 source = OH_AVSource_CreateWithFD(fd, 0, size);
2010 ASSERT_NE(source, nullptr);
2011
2012 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
2013 ASSERT_NE(trackFormat, nullptr);
2014 ASSERT_FALSE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_AAC_IS_ADTS, &stringVal));
2015 close(fd);
2016 }
2017
2018 /**
2019 * @tc.number : DEMUXER_FUNCTION_7300
2020 * @tc.name : demuxer MP4 ,GetAudioTrackFormat ,MD_KEY_BITRATE
2021 * @tc.desc : function test
2022 */
2023 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_7300, TestSize.Level0)
2024 {
2025 int64_t br = 0;
2026 const char *file = "/data/test/media/01_video_audio.mp4";
2027 int fd = open(file, O_RDONLY);
2028 int64_t size = GetFileSize(file);
2029 cout << file << "----------------------" << fd << "---------" << size << endl;
2030 source = OH_AVSource_CreateWithFD(fd, 0, size);
2031 ASSERT_NE(source, nullptr);
2032
2033 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
2034 ASSERT_NE(trackFormat, nullptr);
2035 ASSERT_TRUE(OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_BITRATE, &br));
2036 ASSERT_EQ(br, 319999);
2037 close(fd);
2038 }
2039
2040 /**
2041 * @tc.number : DEMUXER_FUNCTION_7400
2042 * @tc.name : demuxer MP4 ,GetAudioTrackFormat,MD_KEY_CHANNEL_COUNT
2043 * @tc.desc : function test
2044 */
2045 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_7400, TestSize.Level0)
2046 {
2047 int32_t cc = 0;
2048 const char *file = "/data/test/media/01_video_audio.mp4";
2049 int fd = open(file, O_RDONLY);
2050 int64_t size = GetFileSize(file);
2051 cout << file << "----------------------" << fd << "---------" << size << endl;
2052 source = OH_AVSource_CreateWithFD(fd, 0, size);
2053 ASSERT_NE(source, nullptr);
2054
2055 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
2056 ASSERT_NE(trackFormat, nullptr);
2057 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, &cc));
2058
2059 ASSERT_EQ(cc, 2);
2060 close(fd);
2061 }
2062
2063 /**
2064 * @tc.number : DEMUXER_FUNCTION_7500
2065 * @tc.name : demuxer MP4 ,GetAudioTrackFormat,MD_KEY_SAMPLE_RATE
2066 * @tc.desc : function test
2067 */
2068 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_7500, TestSize.Level0)
2069 {
2070 int32_t sr = 0;
2071 const char *file = "/data/test/media/01_video_audio.mp4";
2072 int fd = open(file, O_RDONLY);
2073 int64_t size = GetFileSize(file);
2074 cout << file << "----------------------" << fd << "---------" << size << endl;
2075 source = OH_AVSource_CreateWithFD(fd, 0, size);
2076 ASSERT_NE(source, nullptr);
2077
2078 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
2079 ASSERT_NE(trackFormat, nullptr);
2080 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, &sr));
2081 ASSERT_EQ(sr, 44100);
2082 close(fd);
2083 }
2084
2085 /**
2086 * @tc.number : DEMUXER_FUNCTION_7600
2087 * @tc.name : demuxer MP4 ,GetVideoTrackFormat,MD_KEY_HEIGHT
2088 * @tc.desc : function test
2089 */
2090 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_7600, TestSize.Level0)
2091 {
2092 int32_t height = 0;
2093 const char *file = "/data/test/media/01_video_audio.mp4";
2094 int fd = open(file, O_RDONLY);
2095 int64_t size = GetFileSize(file);
2096 cout << file << "----------------------" << fd << "---------" << size << endl;
2097 source = OH_AVSource_CreateWithFD(fd, 0, size);
2098 ASSERT_NE(source, nullptr);
2099
2100 trackFormat = OH_AVSource_GetTrackFormat(source, 1);
2101 ASSERT_NE(trackFormat, nullptr);
2102 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_HEIGHT, &height));
2103 ASSERT_EQ(height, 0);
2104 close(fd);
2105 }
2106
2107 /**
2108 * @tc.number : DEMUXER_FUNCTION_7700
2109 * @tc.name : demuxer MP4 ,GetVideoTrackFormat,MD_KEY_WIDTH
2110 * @tc.desc : function test
2111 */
2112 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_7700, TestSize.Level0)
2113 {
2114 int32_t weight = 0;
2115 const char *file = "/data/test/media/01_video_audio.mp4";
2116 int fd = open(file, O_RDONLY);
2117 int64_t size = GetFileSize(file);
2118 cout << file << "----------------------" << fd << "---------" << size << endl;
2119 source = OH_AVSource_CreateWithFD(fd, 0, size);
2120 ASSERT_NE(source, nullptr);
2121
2122 trackFormat = OH_AVSource_GetTrackFormat(source, 1);
2123 ASSERT_NE(trackFormat, nullptr);
2124 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_WIDTH, &weight));
2125 ASSERT_EQ(weight, 0);
2126 close(fd);
2127 }
2128
2129 /**
2130 * @tc.number : DEMUXER_FUNCTION_7800
2131 * @tc.name : demuxer MP4 GetPublicTrackFormat,MD_KEY_CODEC_MIME
2132 * @tc.desc : function test
2133 */
2134 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_7800, TestSize.Level0)
2135 {
2136 const char *stringVal;
2137 const char *file = "/data/test/media/01_video_audio.mp4";
2138 int fd = open(file, O_RDONLY);
2139 int64_t size = GetFileSize(file);
2140 cout << file << "----------------------" << fd << "---------" << size << endl;
2141 source = OH_AVSource_CreateWithFD(fd, 0, size);
2142 ASSERT_NE(source, nullptr);
2143
2144 trackFormat = OH_AVSource_GetTrackFormat(source, 1);
2145 ASSERT_NE(trackFormat, nullptr);
2146 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &stringVal));
2147 ASSERT_EQ(0, strcmp(stringVal, "video/mp4v-es"));
2148 close(fd);
2149 }
2150
2151 /**
2152 * @tc.number : DEMUXER_FUNCTION_7900
2153 * @tc.name : demuxer MP4 ,GetPublicTrackFormat,MD_KEY_TRACK_TYPE
2154 * @tc.desc : function test
2155 */
2156 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_7900, TestSize.Level0)
2157 {
2158 int32_t type = 0;
2159 const char *file = "/data/test/media/01_video_audio.mp4";
2160 int fd = open(file, O_RDONLY);
2161 int64_t size = GetFileSize(file);
2162 cout << file << "----------------------" << fd << "---------" << size << endl;
2163 source = OH_AVSource_CreateWithFD(fd, 0, size);
2164 ASSERT_NE(source, nullptr);
2165
2166 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
2167 ASSERT_NE(trackFormat, nullptr);
2168 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &type));
2169
2170 ASSERT_EQ(type, 0);
2171 close(fd);
2172 }
2173
2174 /**
2175 * @tc.number : DEMUXER_FUNCTION_8000
2176 * @tc.name : demuxer MP4 ,check source format,OH_MD_KEY_TITLE
2177 * @tc.desc : function test
2178 */
2179 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_8000, TestSize.Level0)
2180 {
2181 const char *stringVal;
2182 const char *file = "/data/test/media/01_video_audio.mp4";
2183 int fd = open(file, O_RDONLY);
2184 int64_t size = GetFileSize(file);
2185 cout << file << "----------------------" << fd << "---------" << size << endl;
2186 source = OH_AVSource_CreateWithFD(fd, 0, size);
2187 ASSERT_NE(source, nullptr);
2188
2189 sourceFormat = OH_AVSource_GetSourceFormat(source);
2190 ASSERT_NE(sourceFormat, nullptr);
2191 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &stringVal));
2192 ASSERT_EQ(0, strcmp(stringVal, "title"));
2193 close(fd);
2194 }
2195
2196 /**
2197 * @tc.number : DEMUXER_FUNCTION_8100
2198 * @tc.name : demuxer MP4 ,check source format,OH_MD_KEY_ALBUM
2199 * @tc.desc : function test
2200 */
2201 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_8100, TestSize.Level0)
2202 {
2203 const char *file = "/data/test/media/01_video_audio.mp4";
2204 int fd = open(file, O_RDONLY);
2205 int64_t size = GetFileSize(file);
2206 cout << file << "----------------------" << fd << "---------" << size << endl;
2207 source = OH_AVSource_CreateWithFD(fd, 0, size);
2208 ASSERT_NE(source, nullptr);
2209 sourceFormat = OH_AVSource_GetSourceFormat(source);
2210 ASSERT_NE(sourceFormat, nullptr);
2211 const char *stringVal;
2212 ASSERT_FALSE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &stringVal));
2213 close(fd);
2214 }
2215
2216 /**
2217 * @tc.number : DEMUXER_FUNCTION_8200
2218 * @tc.name : demuxer MP4 ,check source format,OH_MD_KEY_ALBUM_ARTIST
2219 * @tc.desc : function test
2220 */
2221 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_8200, TestSize.Level0)
2222 {
2223 const char *file = "/data/test/media/01_video_audio.mp4";
2224 int fd = open(file, O_RDONLY);
2225 int64_t size = GetFileSize(file);
2226 cout << file << "----------------------" << fd << "---------" << size << endl;
2227 source = OH_AVSource_CreateWithFD(fd, 0, size);
2228 ASSERT_NE(source, nullptr);
2229 sourceFormat = OH_AVSource_GetSourceFormat(source);
2230 ASSERT_NE(sourceFormat, nullptr);
2231 const char *stringVal;
2232 ASSERT_FALSE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM_ARTIST, &stringVal));
2233 close(fd);
2234 }
2235
2236 /**
2237 * @tc.number : DEMUXER_FUNCTION_8300
2238 * @tc.name : demuxer MP4 ,check track format,OH_MD_KEY_DATE
2239 * @tc.desc : function test
2240 */
2241 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_8300, TestSize.Level0)
2242 {
2243 const char *file = "/data/test/media/01_video_audio.mp4";
2244 int fd = open(file, O_RDONLY);
2245 int64_t size = GetFileSize(file);
2246 cout << file << "----------------------" << fd << "---------" << size << endl;
2247 source = OH_AVSource_CreateWithFD(fd, 0, size);
2248 ASSERT_NE(source, nullptr);
2249 sourceFormat = OH_AVSource_GetSourceFormat(source);
2250 ASSERT_NE(sourceFormat, nullptr);
2251 const char *stringVal;
2252 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_DATE, &stringVal));
2253 ASSERT_EQ(0, strcmp(stringVal, "2023"));
2254 close(fd);
2255 }
2256
2257 /**
2258 * @tc.number : DEMUXER_FUNCTION_8400
2259 * @tc.name : demuxer MP4 ,check track format,OH_MD_KEY_COMMENT
2260 * @tc.desc : function test
2261 */
2262 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_8400, TestSize.Level0)
2263 {
2264 const char *file = "/data/test/media/01_video_audio.mp4";
2265 int fd = open(file, O_RDONLY);
2266 int64_t size = GetFileSize(file);
2267 cout << file << "----------------------" << fd << "---------" << size << endl;
2268 source = OH_AVSource_CreateWithFD(fd, 0, size);
2269 ASSERT_NE(source, nullptr);
2270 sourceFormat = OH_AVSource_GetSourceFormat(source);
2271 ASSERT_NE(sourceFormat, nullptr);
2272 const char *stringVal;
2273 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_COMMENT, &stringVal));
2274 ASSERT_EQ(0, strcmp(stringVal, "COMMENT"));
2275 close(fd);
2276 }
2277
2278 /**
2279 * @tc.number : DEMUXER_FUNCTION_8500
2280 * @tc.name : demuxer MP4 ,check track format,OH_MD_KEY_GENRE
2281 * @tc.desc : function test
2282 */
2283 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_8500, TestSize.Level0)
2284 {
2285 const char *file = "/data/test/media/01_video_audio.mp4";
2286 int fd = open(file, O_RDONLY);
2287 int64_t size = GetFileSize(file);
2288 cout << file << "----------------------" << fd << "---------" << size << endl;
2289 source = OH_AVSource_CreateWithFD(fd, 0, size);
2290 ASSERT_NE(source, nullptr);
2291 sourceFormat = OH_AVSource_GetSourceFormat(source);
2292 ASSERT_NE(sourceFormat, nullptr);
2293 const char *stringVal;
2294 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_GENRE, &stringVal));
2295 ASSERT_EQ(0, strcmp(stringVal, "Classical"));
2296 close(fd);
2297 }
2298
2299 /**
2300 * @tc.number : DEMUXER_FUNCTION_8600
2301 * @tc.name : demuxer MP4 ,check track format,OH_MD_KEY_COPYRIGHT
2302 * @tc.desc : function test
2303 */
2304 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_8600, TestSize.Level0)
2305 {
2306 const char *file = "/data/test/media/01_video_audio.mp4";
2307 int fd = open(file, O_RDONLY);
2308 int64_t size = GetFileSize(file);
2309 cout << file << "----------------------" << fd << "---------" << size << endl;
2310 source = OH_AVSource_CreateWithFD(fd, 0, size);
2311 ASSERT_NE(source, nullptr);
2312 sourceFormat = OH_AVSource_GetSourceFormat(source);
2313 ASSERT_NE(sourceFormat, nullptr);
2314 const char *stringVal;
2315 ASSERT_FALSE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_COPYRIGHT, &stringVal));
2316 close(fd);
2317 }
2318
2319 /**
2320 * @tc.number : DEMUXER_FUNCTION_8700
2321 * @tc.name : demuxer MP4 ,check track format,OH_MD_KEY_LANGUAGE
2322 * @tc.desc : function test
2323 */
2324 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_8700, TestSize.Level0)
2325 {
2326 const char *file = "/data/test/media/01_video_audio.mp4";
2327 int fd = open(file, O_RDONLY);
2328 int64_t size = GetFileSize(file);
2329 cout << file << "----------------------" << fd << "---------" << size << endl;
2330 source = OH_AVSource_CreateWithFD(fd, 0, size);
2331 ASSERT_NE(source, nullptr);
2332 sourceFormat = OH_AVSource_GetSourceFormat(source);
2333 ASSERT_NE(sourceFormat, nullptr);
2334 const char *stringVal;
2335 ASSERT_FALSE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_LANGUAGE, &stringVal));
2336 close(fd);
2337 }
2338
2339 /**
2340 * @tc.number : DEMUXER_FUNCTION_8800
2341 * @tc.name : demuxer MP4 ,check track format,OH_MD_KEY_DESCRIPTION
2342 * @tc.desc : function test
2343 */
2344 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_8800, TestSize.Level0)
2345 {
2346 const char *file = "/data/test/media/01_video_audio.mp4";
2347 int fd = open(file, O_RDONLY);
2348 int64_t size = GetFileSize(file);
2349 cout << file << "----------------------" << fd << "---------" << size << endl;
2350 source = OH_AVSource_CreateWithFD(fd, 0, size);
2351 ASSERT_NE(source, nullptr);
2352 sourceFormat = OH_AVSource_GetSourceFormat(source);
2353 ASSERT_NE(sourceFormat, nullptr);
2354 const char *stringVal;
2355 ASSERT_FALSE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_DESCRIPTION, &stringVal));
2356 close(fd);
2357 }
2358
2359 /**
2360 * @tc.number : DEMUXER_FUNCTION_8800
2361 * @tc.name : demuxer MP4 ,check track format,OH_MD_KEY_LYRICS
2362 * @tc.desc : function test
2363 */
2364 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_8900, TestSize.Level0)
2365 {
2366 const char *file = "/data/test/media/01_video_audio.mp4";
2367 int fd = open(file, O_RDONLY);
2368 int64_t size = GetFileSize(file);
2369 cout << file << "----------------------" << fd << "---------" << size << endl;
2370 source = OH_AVSource_CreateWithFD(fd, 0, size);
2371 ASSERT_NE(source, nullptr);
2372 sourceFormat = OH_AVSource_GetSourceFormat(source);
2373 ASSERT_NE(sourceFormat, nullptr);
2374 const char *stringVal;
2375 ASSERT_FALSE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_LYRICS, &stringVal));
2376 close(fd);
2377 }
2378
2379 /**
2380 * @tc.number : DEMUXER_FUNCTION_9000
2381 * @tc.name : demuxer MP4 ,check source format,OH_MD_KEY_ARTIST
2382 * @tc.desc : function test
2383 */
2384 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_9000, TestSize.Level0)
2385 {
2386 const char *file = "/data/test/media/01_video_audio.mp4";
2387 int fd = open(file, O_RDONLY);
2388 int64_t size = GetFileSize(file);
2389 cout << file << "----------------------" << fd << "---------" << size << endl;
2390 source = OH_AVSource_CreateWithFD(fd, 0, size);
2391 ASSERT_NE(source, nullptr);
2392 sourceFormat = OH_AVSource_GetSourceFormat(source);
2393 ASSERT_NE(sourceFormat, nullptr);
2394 const char *stringVal;
2395 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &stringVal));
2396 ASSERT_EQ(0, strcmp(stringVal, "sam"));
2397 close(fd);
2398 }