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