• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 DemuxerMovFuncNdkTest : 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 uint8_t g_track0 = 0;
53 static uint8_t g_track1 = 1;
54 static uint8_t g_track2 = 2;
55 static uint8_t g_track3 = 3;
56 static int32_t g_trackCount;
57 static int32_t g_width = 3840;
58 static int32_t g_height = 2160;
59 const std::string HEVC_LIB_PATH = std::string(AV_CODEC_PATH) + "/libav_codec_hevc_parser.z.so";
SetUpTestCase()60 void DemuxerMovFuncNdkTest::SetUpTestCase() {}
TearDownTestCase()61 void DemuxerMovFuncNdkTest::TearDownTestCase() {}
SetUp()62 void DemuxerMovFuncNdkTest::SetUp()
63 {
64     memory = OH_AVMemory_Create(g_width * g_height);
65     g_trackCount = 0;
66 }
TearDown()67 void DemuxerMovFuncNdkTest::TearDown()
68 {
69     if (trackFormat != nullptr) {
70         OH_AVFormat_Destroy(trackFormat);
71         trackFormat = nullptr;
72     }
73 
74     if (sourceFormat != nullptr) {
75         OH_AVFormat_Destroy(sourceFormat);
76         sourceFormat = nullptr;
77     }
78     if (format != nullptr) {
79         OH_AVFormat_Destroy(format);
80         format = nullptr;
81     }
82 
83     if (memory != nullptr) {
84         OH_AVMemory_Destroy(memory);
85         memory = nullptr;
86     }
87     if (source != nullptr) {
88         OH_AVSource_Destroy(source);
89         source = nullptr;
90     }
91     if (demuxer != nullptr) {
92         OH_AVDemuxer_Destroy(demuxer);
93         demuxer = nullptr;
94     }
95     if (avBuffer != nullptr) {
96         OH_AVBuffer_Destroy(avBuffer);
97         avBuffer = nullptr;
98     }
99 }
100 } // namespace Media
101 } // namespace OHOS
102 
103 using namespace std;
104 using namespace OHOS;
105 using namespace OHOS::Media;
106 using namespace testing::ext;
107 
GetFileSize(const char * fileName)108 static int64_t GetFileSize(const char *fileName)
109 {
110     int64_t fileSize = 0;
111     if (fileName != nullptr) {
112         struct stat fileStatus {};
113         if (stat(fileName, &fileStatus) == 0) {
114             fileSize = static_cast<int64_t>(fileStatus.st_size);
115         }
116     }
117     return fileSize;
118 }
119 
OpenFile(const char * fileName,int fd,OH_AVSource ** src,OH_AVDemuxer ** Demuxer)120 static void OpenFile(const char *fileName, int fd, OH_AVSource **src, OH_AVDemuxer **Demuxer)
121 {
122     int64_t size = GetFileSize(fileName);
123     cout << fileName << "----------------------" << fd << "---------" << size << endl;
124     *src = OH_AVSource_CreateWithFD(fd, 0, size);
125     ASSERT_NE(*src, nullptr);
126 
127     *Demuxer = OH_AVDemuxer_CreateWithSource(*src);
128     ASSERT_NE(*Demuxer, nullptr);
129 }
130 
OpenSourceFormat(const char * fileName,int fd,OH_AVSource ** src,OH_AVFormat ** srcFormat)131 static void OpenSourceFormat(const char *fileName, int fd, OH_AVSource **src, OH_AVFormat **srcFormat)
132 {
133     int64_t size = GetFileSize(fileName);
134     cout << fileName << "----------------------" << fd << "---------" << size << endl;
135     *src = OH_AVSource_CreateWithFD(fd, 0, size);
136     ASSERT_NE(*src, nullptr);
137 
138     *srcFormat = OH_AVSource_GetSourceFormat(*src);
139     ASSERT_NE(*srcFormat, nullptr);
140 }
141 
CheckTrackCount(OH_AVFormat ** srcFormat,OH_AVSource * src,int32_t * trackCount,int trackNum)142 static void CheckTrackCount(OH_AVFormat **srcFormat, OH_AVSource *src, int32_t *trackCount, int trackNum)
143 {
144     *srcFormat = OH_AVSource_GetSourceFormat(src);
145     ASSERT_TRUE(OH_AVFormat_GetIntValue(*srcFormat, OH_MD_KEY_TRACK_COUNT, trackCount));
146     ASSERT_EQ(trackNum, *trackCount);
147 }
148 
CheckTrackSelect()149 static void CheckTrackSelect()
150 {
151     for (int32_t index = 0; index < g_trackCount; index++) {
152         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
153     }
154 }
155 
SetAudioValue(OH_AVCodecBufferAttr attr,bool & audioIsEnd,int & audioFrame,int & aKeyCount)156 static void SetAudioValue(OH_AVCodecBufferAttr attr, bool &audioIsEnd, int &audioFrame, int &aKeyCount)
157 {
158     if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
159         audioIsEnd = true;
160         cout << audioFrame << "    audio is end !!!!!!!!!!!!!!!" << endl;
161     } else {
162         audioFrame++;
163         if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
164             aKeyCount++;
165         }
166     }
167 }
168 
SetVideoValue(OH_AVCodecBufferAttr attr,bool & videoIsEnd,int & videoFrame,int & vKeyCount)169 static void SetVideoValue(OH_AVCodecBufferAttr attr, bool &videoIsEnd, int &videoFrame, int &vKeyCount)
170 {
171     if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
172         videoIsEnd = true;
173         cout << videoFrame << "   video is end !!!!!!!!!!!!!!!" << endl;
174     } else {
175         videoFrame++;
176         cout << "video track !!!!!" << endl;
177         if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
178             vKeyCount++;
179         }
180     }
181 }
182 
CheckFrames(int videoFrameNum,int videoKey,int audioFrameNum,int audioKey)183 static void CheckFrames(int videoFrameNum, int videoKey, int audioFrameNum, int audioKey)
184 {
185     int trackType = 0;
186     OH_AVCodecBufferAttr attr;
187     bool audioIsEnd = false;
188     bool videoIsEnd = false;
189     int audioFrame = 0;
190     int videoFrame = 0;
191     int vKeyCount = 0;
192     int aKeyCount = 0;
193 
194     while (!audioIsEnd || !videoIsEnd) {
195         for (int32_t index = 0; index < g_trackCount; index++) {
196             trackFormat = OH_AVSource_GetTrackFormat(source, index);
197             ASSERT_NE(trackFormat, nullptr);
198             ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &trackType));
199             OH_AVFormat_Destroy(trackFormat);
200             trackFormat = nullptr;
201             if ((audioIsEnd && (trackType == MEDIA_TYPE_AUD)) || (videoIsEnd && (trackType == MEDIA_TYPE_VID))) {
202                 continue;
203             }
204             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
205 
206             if (trackType == MEDIA_TYPE_AUD) {
207                 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
208             } else if (trackType == MEDIA_TYPE_VID) {
209                 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
210             }
211         }
212     }
213     ASSERT_EQ(audioFrame, audioFrameNum);
214     ASSERT_EQ(aKeyCount, audioKey);
215     ASSERT_EQ(videoFrame, videoFrameNum);
216     ASSERT_EQ(vKeyCount, videoKey);
217 }
218 
InitTrkPara(int index,int * trackType)219 static void InitTrkPara(int index, int *trackType)
220 {
221     trackFormat = OH_AVSource_GetTrackFormat(source, index);
222     ASSERT_NE(trackFormat, nullptr);
223     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, trackType));
224     OH_AVFormat_Destroy(trackFormat);
225     trackFormat = nullptr;
226 }
227 
FramesMultiTrks(int vFrameNum,int videoKey,int aFrameNum,int audioKey)228 static void FramesMultiTrks(int vFrameNum, int videoKey, int aFrameNum, int audioKey)
229 {
230     OH_AVCodecBufferAttr attr;
231     int aKeyCount = 0;
232     int vKeyCount = 0;
233     int audioFrame = 0;
234     int videoFrame = 0;
235     int trackType = 0;
236     bool trackEndFlag[4] = {0, 0, 0, 0};
237     bool allEnd = false;
238     while (!allEnd) {
239         for (int32_t index = 0; index < g_trackCount; index++) {
240             InitTrkPara(index, &trackType);
241             if ((trackEndFlag[index] && (trackType == MEDIA_TYPE_AUD)) ||
242                 (trackEndFlag[index] && (trackType == MEDIA_TYPE_VID))) {
243                 continue;
244             }
245             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
246 
247             if (trackType == MEDIA_TYPE_AUD &&
248                 (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS)) {
249                 trackEndFlag[index] = true;
250             } else if (trackType == MEDIA_TYPE_AUD &&
251                 (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME)) {
252                 aKeyCount++;
253                 audioFrame++;
254             } else if (trackType == MEDIA_TYPE_AUD) {
255                 audioFrame++;
256             }
257 
258             if (trackType == MEDIA_TYPE_VID &&
259                 (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS)) {
260                 trackEndFlag[index] = true;
261             } else if (trackType == MEDIA_TYPE_VID &&
262                 (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME)) {
263                 vKeyCount++;
264                 videoFrame++;
265             } else if (trackType == MEDIA_TYPE_VID) {
266                 videoFrame++;
267             }
268         }
269         allEnd = trackEndFlag[g_track0] && trackEndFlag[g_track1] &&
270                      trackEndFlag[g_track2] && trackEndFlag[g_track3];
271     }
272 
273     ASSERT_EQ(audioFrame, aFrameNum);
274     ASSERT_EQ(videoFrame, vFrameNum);
275     ASSERT_EQ(aKeyCount, audioKey);
276     ASSERT_EQ(vKeyCount, videoKey);
277 }
278 
CheckMOVVideoKey()279 static void CheckMOVVideoKey()
280 {
281     int64_t bitrate = 0;
282     const char* mimeType = nullptr;
283     double frameRate;
284     int32_t currentWidth = 0;
285     int32_t currentHeight = 0;
286     ASSERT_TRUE(OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_BITRATE, &bitrate));
287     int bitrateResult = 750752;
288     ASSERT_EQ(bitrateResult, bitrate);
289     ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
290     int expectNum = 0;
291     ASSERT_EQ(expectNum, strcmp(mimeType, OH_AVCODEC_MIMETYPE_VIDEO_AVC));
292     ASSERT_TRUE(OH_AVFormat_GetDoubleValue(trackFormat, OH_MD_KEY_FRAME_RATE, &frameRate));
293     int frameRateResult = 30.000000;
294     ASSERT_EQ(frameRateResult, frameRate);
295     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_HEIGHT, &currentHeight));
296     int currentHeightResult = 1080;
297     ASSERT_EQ(currentHeightResult, currentHeight);
298     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_WIDTH, &currentWidth));
299     int currentWidthResult = 1920;
300     ASSERT_EQ(currentWidthResult, currentWidth);
301 }
302 
CheckMOVAudioKey()303 static void CheckMOVAudioKey()
304 {
305     int32_t audioCount = 0;
306     int64_t bitrate = 0;
307     const char* mimeType = nullptr;
308     int32_t sampleRate = 0;
309     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, &audioCount));
310     int audioCountResult = 1;
311     ASSERT_EQ(audioCountResult, audioCount);
312     ASSERT_TRUE(OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_BITRATE, &bitrate));
313     int bitrateResult = 70005;
314     ASSERT_EQ(bitrateResult, bitrate);
315     ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
316     int expectNum = 0;
317     ASSERT_EQ(expectNum, strcmp(mimeType, OH_AVCODEC_MIMETYPE_AUDIO_AAC));
318     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, &sampleRate));
319     int sampleRateResult = 48000;
320     ASSERT_EQ(sampleRateResult, sampleRate);
321 }
322 
CheckMPGVideoKey()323 static void CheckMPGVideoKey()
324 {
325     int64_t bitrate = 0;
326     const char* mimeType = nullptr;
327     double frameRate;
328     int32_t currentWidth = 0;
329     int32_t currentHeight = 0;
330     ASSERT_FALSE(OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_BITRATE, &bitrate));
331     ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
332     int expectNum = 0;
333     ASSERT_EQ(expectNum, strcmp(mimeType, OH_AVCODEC_MIMETYPE_VIDEO_AVC));
334     ASSERT_TRUE(OH_AVFormat_GetDoubleValue(trackFormat, OH_MD_KEY_FRAME_RATE, &frameRate));
335     int frameRateResult = 30.000000;
336     ASSERT_EQ(frameRateResult, frameRate);
337     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_HEIGHT, &currentHeight));
338     int currentHeightResult = 1080;
339     ASSERT_EQ(currentHeightResult, currentHeight);
340     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_WIDTH, &currentWidth));
341     int currentWidthResult = 1920;
342     ASSERT_EQ(currentWidthResult, currentWidth);
343 }
344 
CheckMPGAudioKey()345 static void CheckMPGAudioKey()
346 {
347     int32_t audioCount = 0;
348     int64_t bitrate = 0;
349     const char* mimeType = nullptr;
350     int32_t sampleRate = 0;
351     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, &audioCount));
352     int audioCountResult = 1;
353     ASSERT_EQ(audioCountResult, audioCount);
354     ASSERT_TRUE(OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_BITRATE, &bitrate));
355     int bitrateResult = 384000;
356     ASSERT_EQ(bitrateResult, bitrate);
357     ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
358     int expectNum = 0;
359     ASSERT_EQ(expectNum, strcmp(mimeType, OH_AVCODEC_MIMETYPE_AUDIO_MPEG));
360     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, &sampleRate));
361     int sampleRateResult = 44100;
362     ASSERT_EQ(sampleRateResult, sampleRate);
363 }
364 
365 /**
366  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_0100
367  * @tc.name      : demux H264_base@5_1920_1080_30_AAC_48K_1.mov
368  * @tc.desc      : function test
369  */
370 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_0100, TestSize.Level0)
371 {
372     const char *file = "/data/test/media/H264_base@5_1920_1080_30_AAC_48K_1.mov";
373     int fd = open(file, O_RDONLY);
374     OpenFile(file, fd, &source, &demuxer);
375     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
376     CheckTrackSelect();
377     CheckFrames(60, 6, 95, 95);
378     close(fd);
379     fd = -1;
380 }
381 
382 /**
383  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_0200
384  * @tc.name      : demux H264_main@4_1280_720_60_MP2_44.1K_2.mov
385  * @tc.desc      : function test
386  */
387 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_0200, TestSize.Level0)
388 {
389     const char *file = "/data/test/media/H264_main@4_1280_720_60_MP2_44.1K_2.mov";
390     int fd = open(file, O_RDONLY);
391     OpenFile(file, fd, &source, &demuxer);
392     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
393     CheckTrackSelect();
394     CheckFrames(119, 12, 77, 77);
395     close(fd);
396     fd = -1;
397 }
398 
399 /**
400  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_0300
401  * @tc.name      : demux H264_high@5.1_3840_2160_30_MP3_48K_1.mov
402  * @tc.desc      : function test
403  */
404 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_0300, TestSize.Level0)
405 {
406     const char *file = "/data/test/media/H264_high@5.1_3840_2160_30_MP3_48K_1.mov";
407     int fd = open(file, O_RDONLY);
408     OpenFile(file, fd, &source, &demuxer);
409     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
410     CheckTrackSelect();
411     CheckFrames(60, 6, 85, 85);
412     close(fd);
413     fd = -1;
414 }
415 
416 /**
417  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_0400
418  * @tc.name      : demux H264_h444@5.1_1920_1080_60_vorbis_32K_2.mov
419  * @tc.desc      : function test
420  */
421 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_0400, TestSize.Level2)
422 {
423     const char *file = "/data/test/media/H264_h444@5.1_1920_1080_60_vorbis_32K_2.mov";
424     int fd = open(file, O_RDONLY);
425     OpenFile(file, fd, &source, &demuxer);
426     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
427     CheckTrackSelect();
428     CheckFrames(119, 12, 72, 72);
429     close(fd);
430     fd = -1;
431 }
432 
433 /**
434  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_0500
435  * @tc.name      : demux H264_main@3_720_480_30_PCM_48K_24_1.mov
436  * @tc.desc      : function test
437  */
438 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_0500, TestSize.Level0)
439 {
440     const char *file = "/data/test/media/H264_main@3_720_480_30_PCM_48K_24_1.mov";
441     int fd = open(file, O_RDONLY);
442     OpenFile(file, fd, &source, &demuxer);
443     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
444     CheckTrackSelect();
445     CheckFrames(60, 6, 144, 144);
446     close(fd);
447     fd = -1;
448 }
449 
450 /**
451  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_0600
452  * @tc.name      : demux H265_main@4_1920_1080_30_AAC_44.1K_2.mov
453  * @tc.desc      : function test
454  */
455 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_0600, TestSize.Level0)
456 {
457     if (access(HEVC_LIB_PATH.c_str(), F_OK) != 0) {
458         return;
459     }
460     const char *file = "/data/test/media/H265_main@4_1920_1080_30_AAC_44.1K_2.mov";
461     int fd = open(file, O_RDONLY);
462     OpenFile(file, fd, &source, &demuxer);
463     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
464     CheckTrackSelect();
465     CheckFrames(60, 6, 88, 88);
466     close(fd);
467     fd = -1;
468 }
469 
470 /**
471  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_0700
472  * @tc.name      : demux H265_main10@4.1_1280_720_60_MP2_48K_1.mov
473  * @tc.desc      : function test
474  */
475 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_0700, TestSize.Level2)
476 {
477     if (access(HEVC_LIB_PATH.c_str(), F_OK) != 0) {
478         return;
479     }
480     const char *file = "/data/test/media/H265_main10@4.1_1280_720_60_MP2_48K_1.mov";
481     int fd = open(file, O_RDONLY);
482     OpenFile(file, fd, &source, &demuxer);
483     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
484     CheckTrackSelect();
485     CheckFrames(119, 12, 84, 84);
486     close(fd);
487     fd = -1;
488 }
489 
490 /**
491  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_0800
492  * @tc.name      : demux H265_main10@5_1920_1080_60_MP3_44.1K_2.mov
493  * @tc.desc      : function test
494  */
495 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_0800, TestSize.Level2)
496 {
497     if (access(HEVC_LIB_PATH.c_str(), F_OK) != 0) {
498         return;
499     }
500     const char *file = "/data/test/media/H265_main10@5_1920_1080_60_MP3_44.1K_2.mov";
501     int fd = open(file, O_RDONLY);
502     OpenFile(file, fd, &source, &demuxer);
503     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
504     CheckTrackSelect();
505     CheckFrames(119, 12, 78, 78);
506     close(fd);
507     fd = -1;
508 }
509 
510 /**
511  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_0900
512  * @tc.name      : demux H265_main@5_3840_2160_30_vorbis_48K_1.mov
513  * @tc.desc      : function test
514  */
515 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_0900, TestSize.Level0)
516 {
517     if (access(HEVC_LIB_PATH.c_str(), F_OK) != 0) {
518         return;
519     }
520     const char *file = "/data/test/media/H265_main@5_3840_2160_30_vorbis_48K_1.mov";
521     int fd = open(file, O_RDONLY);
522     OpenFile(file, fd, &source, &demuxer);
523     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
524     CheckTrackSelect();
525     CheckFrames(60, 6, 96, 96);
526     close(fd);
527     fd = -1;
528 }
529 
530 /**
531  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_1000
532  * @tc.name      : demux H265_main10@5.1_3840_2160_60_PCM(mulaw)_48K_16_2.mov
533  * @tc.desc      : function test
534  */
535 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_1000, TestSize.Level2)
536 {
537     if (access(HEVC_LIB_PATH.c_str(), F_OK) != 0) {
538         return;
539     }
540     const char *file = "/data/test/media/H265_main10@5.1_3840_2160_60_PCM(mulaw)_48K_16_2.mov";
541     int fd = open(file, O_RDONLY);
542     OpenFile(file, fd, &source, &demuxer);
543     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
544     CheckTrackSelect();
545     CheckFrames(119, 12, 171, 171);
546     close(fd);
547     fd = -1;
548 }
549 
550 /**
551  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_1100
552  * @tc.name      : demux MPEG4_SP@5_720_480_30_AAC_32K_1.mov
553  * @tc.desc      : function test
554  */
555 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_1100, TestSize.Level0)
556 {
557     const char *file = "/data/test/media/MPEG4_SP@5_720_480_30_AAC_32K_1.mov";
558     int fd = open(file, O_RDONLY);
559     OpenFile(file, fd, &source, &demuxer);
560     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
561     CheckTrackSelect();
562     CheckFrames(60, 6, 64, 64);
563     close(fd);
564     fd = -1;
565 }
566 
567 /**
568  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_1200
569  * @tc.name      : demux MPEG4_SP@6_1280_720_30_MP2_32K_2.mov
570  * @tc.desc      : function test
571  */
572 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_1200, TestSize.Level0)
573 {
574     const char *file = "/data/test/media/MPEG4_SP@6_1280_720_30_MP2_32K_2.mov";
575     int fd = open(file, O_RDONLY);
576     OpenFile(file, fd, &source, &demuxer);
577     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
578     CheckTrackSelect();
579     CheckFrames(60, 6, 56, 56);
580     close(fd);
581     fd = -1;
582 }
583 
584 /**
585  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_1300
586  * @tc.name      : demux MPEG4_ASP@3_352_288_30_MP3_32K_1.mov
587  * @tc.desc      : function test
588  */
589 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_1300, TestSize.Level2)
590 {
591     const char *file = "/data/test/media/MPEG4_ASP@3_352_288_30_MP3_32K_1.mov";
592     int fd = open(file, O_RDONLY);
593     OpenFile(file, fd, &source, &demuxer);
594     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
595     CheckTrackSelect();
596     CheckFrames(60, 6, 57, 57);
597     close(fd);
598     fd = -1;
599 }
600 
601 /**
602  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_1400
603  * @tc.name      : demux MPEG4_ASP@4_720_576_30_Vorbis_44.1K_2.mov
604  * @tc.desc      : function test
605  */
606 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_1400, TestSize.Level2)
607 {
608     const char *file = "/data/test/media/MPEG4_ASP@4_720_576_30_Vorbis_44.1K_2.mov";
609     int fd = open(file, O_RDONLY);
610     OpenFile(file, fd, &source, &demuxer);
611     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
612     CheckTrackSelect();
613     CheckFrames(60, 6, 91, 91);
614     close(fd);
615     fd = -1;
616 }
617 
618 /**
619  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_1500
620  * @tc.name      : demux MPEG4_Core@2_1920_1080_30_PCM(mulaw)_44.1K_16_1.mov
621  * @tc.desc      : function test
622  */
623 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_1500, TestSize.Level0)
624 {
625     const char *file = "/data/test/media/MPEG4_Core@2_1920_1080_30_PCM(mulaw)_44.1K_16_1.mov";
626     int fd = open(file, O_RDONLY);
627     OpenFile(file, fd, &source, &demuxer);
628     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
629     CheckTrackSelect();
630     CheckFrames(45, 5, 65, 65);
631     close(fd);
632     fd = -1;
633 }
634 
635 /**
636  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_1600
637  * @tc.name      : create source with invalid fd
638  * @tc.desc      : function test
639  */
640 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_1600, TestSize.Level2)
641 {
642     const char *file = "/data/test/media/invalid.mov";
643     int fd = open(file, O_RDONLY);
644     int64_t size = GetFileSize(file);
645     cout << file << "----------------------" << fd << "---------" << size << endl;
646     source = OH_AVSource_CreateWithFD(fd, 0, size);
647     ASSERT_EQ(source, nullptr);
648     close(fd);
649     fd = -1;
650 }
651 
652 /**
653  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_1700
654  * @tc.name      : create source with invalid uri
655  * @tc.desc      : function test
656  */
657 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_1700, TestSize.Level2)
658 {
659     const char *uri = "http://invalidPath/invalid.mov";
660     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
661     ASSERT_EQ(nullptr, source);
662 }
663 
664 /**
665  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_1900
666  * @tc.name      : demuxer mov  ,check source format,OH_MD_KEY_TITLE
667  * @tc.desc      : function test
668  */
669 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_1900, TestSize.Level2)
670 {
671     const char *file = "/data/test/media/meta_test.mov";
672     int fd = open(file, O_RDONLY);
673     OpenSourceFormat(file, fd, &source, &sourceFormat);
674     const char *stringVal;
675     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &stringVal));
676     ASSERT_EQ(0, strcmp(stringVal, "title"));
677     close(fd);
678     fd = -1;
679 }
680 
681 /**
682  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_2000
683  * @tc.name      : demuxer mov  ,check source format,OH_MD_KEY_ALBUM
684  * @tc.desc      : function test
685  */
686 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_2000, TestSize.Level2)
687 {
688     const char *file = "/data/test/media/meta_test.mov";
689     int fd = open(file, O_RDONLY);
690     OpenSourceFormat(file, fd, &source, &sourceFormat);
691     const char *stringVal;
692     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &stringVal));
693     ASSERT_EQ(0, strcmp(stringVal, "album"));
694     close(fd);
695     fd = -1;
696 }
697 
698 /**
699  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_2100
700  * @tc.name      : demuxer mov  ,check source format,OH_MD_KEY_ALBUM_ARTIST
701  * @tc.desc      : function test
702  */
703 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_2100, TestSize.Level2)
704 {
705     const char *file = "/data/test/media/meta_test.mov";
706     int fd = open(file, O_RDONLY);
707     OpenSourceFormat(file, fd, &source, &sourceFormat);
708     const char *stringVal;
709     ASSERT_FALSE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM_ARTIST, &stringVal));
710     close(fd);
711     fd = -1;
712 }
713 
714 /**
715  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_2200
716  * @tc.name      : demuxer mov  ,check track format,OH_MD_KEY_DATE
717  * @tc.desc      : function test
718  */
719 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_2200, TestSize.Level2)
720 {
721     const char *file = "/data/test/media/meta_test.mov";
722     int fd = open(file, O_RDONLY);
723     OpenSourceFormat(file, fd, &source, &sourceFormat);
724     const char *stringVal;
725     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_DATE, &stringVal));
726     ASSERT_EQ(0, strcmp(stringVal, "date"));
727     close(fd);
728     fd = -1;
729 }
730 
731 /**
732  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_2300
733  * @tc.name      : demuxer mov  ,check track format,OH_MD_KEY_COMMENT
734  * @tc.desc      : function test
735  */
736 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_2300, TestSize.Level2)
737 {
738     const char *file = "/data/test/media/meta_test.mov";
739     int fd = open(file, O_RDONLY);
740     OpenSourceFormat(file, fd, &source, &sourceFormat);
741     const char *stringVal;
742     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_COMMENT, &stringVal));
743     ASSERT_EQ(0, strcmp(stringVal, "comment"));
744     close(fd);
745     fd = -1;
746 }
747 
748 /**
749  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_2400
750  * @tc.name      : demuxer mov  ,check track format,OH_MD_KEY_GENRE
751  * @tc.desc      : function test
752  */
753 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_2400, TestSize.Level2)
754 {
755     const char *file = "/data/test/media/meta_test.mov";
756     int fd = open(file, O_RDONLY);
757     OpenSourceFormat(file, fd, &source, &sourceFormat);
758     const char *stringVal;
759     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_GENRE, &stringVal));
760     ASSERT_EQ(0, strcmp(stringVal, "genre"));
761     close(fd);
762     fd = -1;
763 }
764 
765 /**
766  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_2500
767  * @tc.name      : demuxer mov  ,check track format,OH_MD_KEY_COPYRIGHT
768  * @tc.desc      : function test
769  */
770 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_2500, TestSize.Level2)
771 {
772     const char *file = "/data/test/media/meta_test.mov";
773     int fd = open(file, O_RDONLY);
774     OpenSourceFormat(file, fd, &source, &sourceFormat);
775     const char *stringVal;
776     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_COPYRIGHT, &stringVal));
777     ASSERT_EQ(0, strcmp(stringVal, "copyright"));
778     close(fd);
779     fd = -1;
780 }
781 
782 /**
783  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_2600
784  * @tc.name      : demuxer mov  ,check track format,OH_MD_KEY_LANGUAGE
785  * @tc.desc      : function test
786  */
787 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_2600, TestSize.Level2)
788 {
789     const char *file = "/data/test/media/meta_test.mov";
790     int fd = open(file, O_RDONLY);
791     OpenSourceFormat(file, fd, &source, &sourceFormat);
792     const char *stringVal;
793     ASSERT_FALSE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_LANGUAGE, &stringVal));
794     close(fd);
795     fd = -1;
796 }
797 
798 /**
799  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_2700
800  * @tc.name      : demuxer mov  ,check track format,OH_MD_KEY_DESCRIPTION
801  * @tc.desc      : function test
802  */
803 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_2700, TestSize.Level2)
804 {
805     const char *file = "/data/test/media/meta_test.mov";
806     int fd = open(file, O_RDONLY);
807     OpenSourceFormat(file, fd, &source, &sourceFormat);
808     const char *stringVal;
809     ASSERT_FALSE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_DESCRIPTION, &stringVal));
810     close(fd);
811     fd = -1;
812 }
813 
814 /**
815  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_2800
816  * @tc.name      : demuxer mov  ,check track format,OH_MD_KEY_LYRICS
817  * @tc.desc      : function test
818  */
819 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_2800, TestSize.Level2)
820 {
821     const char *file = "/data/test/media/meta_test.mov";
822     int fd = open(file, O_RDONLY);
823     OpenSourceFormat(file, fd, &source, &sourceFormat);
824     const char *stringVal;
825     ASSERT_FALSE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_LYRICS, &stringVal));
826     close(fd);
827     fd = -1;
828 }
829 
830 /**
831  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_2900
832  * @tc.name      : demuxer mov  ,check source format,OH_MD_KEY_ARTIST
833  * @tc.desc      : function test
834  */
835 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_2900, TestSize.Level2)
836 {
837     const char *file = "/data/test/media/meta_test.mov";
838     int fd = open(file, O_RDONLY);
839     OpenSourceFormat(file, fd, &source, &sourceFormat);
840     const char *stringVal;
841     ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &stringVal));
842     ASSERT_EQ(0, strcmp(stringVal, "artist"));
843     close(fd);
844     fd = -1;
845 }
846 
847 /**
848  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_3000
849  * @tc.name      : demuxer mov file, check key
850  * @tc.desc      : function test
851  */
852 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_3000, TestSize.Level2)
853 {
854     int trackType = 0;
855     int64_t duration = 0;
856     int64_t startTime;
857     const char *file = "/data/test/media/H264_base@5_1920_1080_30_AAC_48K_1.mov";
858     int fd = open(file, O_RDONLY);
859     OpenSourceFormat(file, fd, &source, &sourceFormat);
860     ASSERT_NE(OH_AVSource_GetTrackFormat(source, 0), nullptr);
861     ASSERT_TRUE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_DURATION, &duration));
862     ASSERT_EQ(2000000, duration);
863     ASSERT_TRUE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_START_TIME, &startTime));
864     ASSERT_EQ(0, startTime);
865     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
866     ASSERT_EQ(2, g_trackCount);
867     demuxer = OH_AVDemuxer_CreateWithSource(source);
868     ASSERT_NE(demuxer, nullptr);
869 
870     const char* mimeType = nullptr;
871     for (int32_t index = 0; index < g_trackCount; index++) {
872         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
873     }
874 
875     OH_AVCodecBufferAttr attr;
876     int vKeyCount = 0;
877     int aKeyCount = 0;
878     bool audioIsEnd = false;
879     bool videoIsEnd = false;
880     int audioFrame = 0;
881     int videoFrame = 0;
882 
883     for (int32_t index = 0; index < g_trackCount; index++) {
884             trackFormat = OH_AVSource_GetTrackFormat(source, index);
885             ASSERT_NE(trackFormat, nullptr);
886             ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &trackType));
887             if ((audioIsEnd && (trackType == MEDIA_TYPE_AUD) && index == MEDIA_TYPE_AUD) ||
888              (videoIsEnd && (trackType == MEDIA_TYPE_VID) && index == MEDIA_TYPE_VID)) {
889                 continue;
890             }
891             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
892             ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
893             if (trackType == MEDIA_TYPE_AUD) {
894                 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
895                 CheckMOVAudioKey();
896             } else if (trackType == MEDIA_TYPE_VID) {
897                 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
898                 CheckMOVVideoKey();
899             }
900             OH_AVFormat_Destroy(trackFormat);
901             trackFormat = nullptr;
902         }
903 
904     close(fd);
905     fd = -1;
906 }
907 
908 /**
909  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_3100
910  * @tc.name      : demux multi track mov file
911  * @tc.desc      : function test
912  */
913 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_3100, TestSize.Level2)
914 {
915     const char *file = "/data/test/media/multi_trk.mov";
916     int fd = open(file, O_RDONLY);
917     OpenFile(file, fd, &source, &demuxer);
918     CheckTrackCount(&sourceFormat, source, &g_trackCount, 4);
919     CheckTrackSelect();
920     FramesMultiTrks(120, 12, 145, 145);
921     close(fd);
922     fd = -1;
923 }
924 
925 /**
926  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_3200
927  * @tc.name      : create source with error mov file
928  * @tc.desc      : function test
929  */
930 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_3200, TestSize.Level3)
931 {
932     const char *file = "/data/test/media/error.mov";
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, 0, size);
937     ASSERT_NE(source, nullptr);
938 
939     demuxer = OH_AVDemuxer_CreateWithSource(source);
940     ASSERT_NE(demuxer, nullptr);
941     OH_AVCodecBufferAttr attr;
942     ASSERT_NE(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
943 
944     close(fd);
945     fd = -1;
946 }
947 
948 /**
949  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_3300
950  * @tc.name      : demux mov , zero track
951  * @tc.desc      : function test
952  */
953 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_3300, TestSize.Level3)
954 {
955     const char *file = "/data/test/media/zero_track.mov";
956     int fd = open(file, O_RDONLY);
957     OpenFile(file, fd, &source, &demuxer);
958     CheckTrackCount(&sourceFormat, source, &g_trackCount, 0);
959 
960     ASSERT_EQ(AV_ERR_INVALID_VAL, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
961     close(fd);
962     fd = -1;
963 }
964 
965 /**
966  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_3400
967  * @tc.name      : seek to a invalid time, closest mode
968  * @tc.desc      : function test
969  */
970 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_3400, TestSize.Level3)
971 {
972     const char *file = "/data/test/media/H264_base@5_1920_1080_30_AAC_48K_1.mov";
973     srand(time(nullptr));
974     int fd = open(file, O_RDONLY);
975     int64_t size = GetFileSize(file);
976     cout << file << "----------------------" << fd << "---------" << size << endl;
977     source = OH_AVSource_CreateWithFD(fd, 0, size);
978     ASSERT_NE(source, nullptr);
979 
980     demuxer = OH_AVDemuxer_CreateWithSource(source);
981     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
982 
983     ASSERT_NE(demuxer, nullptr);
984     int64_t invalidPts = 12000 * 16666;
985     ret = OH_AVDemuxer_SeekToTime(demuxer, invalidPts, SEEK_MODE_CLOSEST_SYNC);
986     ASSERT_NE(ret, AV_ERR_OK);
987     close(fd);
988     fd = -1;
989 }
990 
991 /**
992  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_3500
993  * @tc.name      : remove track before add track
994  * @tc.desc      : function test
995  */
996 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_3500, TestSize.Level3)
997 {
998     const char *file = "/data/test/media/H264_base@5_1920_1080_30_AAC_48K_1.mov";
999     srand(time(nullptr));
1000     int fd = open(file, O_RDONLY);
1001     int64_t size = GetFileSize(file);
1002     cout << file << "----------------------" << fd << "---------" << size << endl;
1003     source = OH_AVSource_CreateWithFD(fd, 0, size);
1004     ASSERT_NE(source, nullptr);
1005 
1006     demuxer = OH_AVDemuxer_CreateWithSource(source);
1007     ASSERT_NE(demuxer, nullptr);
1008     ret = OH_AVDemuxer_UnselectTrackByID(demuxer, 0);
1009     ASSERT_EQ(ret, AV_ERR_OK);
1010     ret = OH_AVDemuxer_SelectTrackByID(demuxer, 0);
1011     ASSERT_EQ(ret, AV_ERR_OK);
1012     close(fd);
1013     fd = -1;
1014 }
1015 
1016 /**
1017  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_3600
1018  * @tc.name      : remove all tracks before demux finish
1019  * @tc.desc      : function test
1020  */
1021 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_3600, TestSize.Level3)
1022 {
1023     OH_AVCodecBufferAttr attr;
1024     const char *file = "/data/test/media/H264_base@5_1920_1080_30_AAC_48K_1.mov";
1025     bool isEnd = false;
1026     int count = 0;
1027     int fd = open(file, O_RDONLY);
1028     int64_t size = GetFileSize(file);
1029     cout << file << "----------------------" << fd << "---------" << size << endl;
1030     source = OH_AVSource_CreateWithFD(fd, 0, size);
1031     ASSERT_NE(source, nullptr);
1032 
1033     demuxer = OH_AVDemuxer_CreateWithSource(source);
1034     ASSERT_NE(demuxer, nullptr);
1035 
1036     sourceFormat = OH_AVSource_GetSourceFormat(source);
1037     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1038     ASSERT_EQ(2, g_trackCount);
1039     for (int32_t index = 0; index < g_trackCount; index++) {
1040         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1041     }
1042     srand(time(nullptr));
1043     int pos = rand() % 60;
1044     cout << " pos= " << pos << endl;
1045     while (!isEnd) {
1046         for (int32_t index = 0; index < g_trackCount; index++) {
1047             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1048             if (count == pos) {
1049                 cout << count << " count == pos!!!!!!!!!" << endl;
1050                 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_UnselectTrackByID(demuxer, 0));
1051                 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_UnselectTrackByID(demuxer, 1));
1052                 ASSERT_EQ(AV_ERR_OPERATE_NOT_PERMIT, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1053                 isEnd = true;
1054                 break;
1055             }
1056 
1057             if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1058                 isEnd = true;
1059                 cout << "is end !!!!!!!!!!!!!!!" << endl;
1060             }
1061             if (index == MEDIA_TYPE_AUD) {
1062                 count++;
1063             }
1064         }
1065     }
1066     close(fd);
1067     fd = -1;
1068 }
1069 
1070 /**
1071  * @tc.number    : MOV_DEMUXER_FUNCTION_TEST_3700
1072  * @tc.name      : start demux bufore add track
1073  * @tc.desc      : function test
1074  */
1075 HWTEST_F(DemuxerMovFuncNdkTest, MOV_DEMUXER_FUNCTION_TEST_3700, TestSize.Level3)
1076 {
1077     uint32_t trackIndex = 0;
1078     OH_AVCodecBufferAttr attr;
1079     const char *file = "/data/test/media/H264_base@5_1920_1080_30_AAC_48K_1.mov";
1080     srand(time(nullptr));
1081     int fd = open(file, O_RDONLY);
1082     int64_t size = GetFileSize(file);
1083     cout << file << "----------------------" << fd << "---------" << size << endl;
1084     source = OH_AVSource_CreateWithFD(fd, 0, size);
1085     ASSERT_NE(source, nullptr);
1086 
1087     demuxer = OH_AVDemuxer_CreateWithSource(source);
1088     ASSERT_NE(demuxer, nullptr);
1089     ret = OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &attr);
1090     ASSERT_EQ(ret, AV_ERR_OPERATE_NOT_PERMIT);
1091     close(fd);
1092     fd = -1;
1093 }
1094 
1095 /**
1096  * @tc.number    : MPG_DEMUXER_FUNCTION_TEST_0100
1097  * @tc.name      : demux H264_base@5_1920_1080_30_MP2_44.1K_1.mpg
1098  * @tc.desc      : function test
1099  */
1100 HWTEST_F(DemuxerMovFuncNdkTest, MPG_DEMUXER_FUNCTION_TEST_0100, TestSize.Level0)
1101 {
1102     const char *file = "/data/test/media/H264_base@5_1920_1080_30_MP2_44.1K_1.mpg";
1103     int fd = open(file, O_RDONLY);
1104     OpenFile(file, fd, &source, &demuxer);
1105     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
1106     CheckTrackSelect();
1107     CheckFrames(60, 6, 77, 77);
1108     close(fd);
1109     fd = -1;
1110 }
1111 
1112 /**
1113  * @tc.number    : MPG_DEMUXER_FUNCTION_TEST_0200
1114  * @tc.name      : demux H264_h444p@5.1_1920_1080_60_MP2_48K_2.mpg
1115  * @tc.desc      : function test
1116  */
1117 HWTEST_F(DemuxerMovFuncNdkTest, MPG_DEMUXER_FUNCTION_TEST_0200, TestSize.Level2)
1118 {
1119     const char *file = "/data/test/media/H264_h444p@5.1_1920_1080_60_MP2_48K_2.mpg";
1120     int fd = open(file, O_RDONLY);
1121     OpenFile(file, fd, &source, &demuxer);
1122     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
1123     CheckTrackSelect();
1124     CheckFrames(119, 12, 84, 84);
1125     close(fd);
1126     fd = -1;
1127 }
1128 
1129 /**
1130  * @tc.number    : MPG_DEMUXER_FUNCTION_TEST_0300
1131  * @tc.name      : demux H264_high@5.1_3840_2160_30_MP3_44.1K_1.mpg
1132  * @tc.desc      : function test
1133  */
1134 HWTEST_F(DemuxerMovFuncNdkTest, MPG_DEMUXER_FUNCTION_TEST_0300, TestSize.Level2)
1135 {
1136     const char *file = "/data/test/media/H264_high@5.1_3840_2160_30_MP3_44.1K_1.mpg";
1137     int fd = open(file, O_RDONLY);
1138     OpenFile(file, fd, &source, &demuxer);
1139     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
1140     CheckTrackSelect();
1141     CheckFrames(60, 6, 78, 78);
1142     close(fd);
1143     fd = -1;
1144 }
1145 
1146 /**
1147  * @tc.number    : MPG_DEMUXER_FUNCTION_TEST_0400
1148  * @tc.name      : demux H264_main@4.2_1280_720_60_MP3_32K_2.mpg
1149  * @tc.desc      : function test
1150  */
1151 HWTEST_F(DemuxerMovFuncNdkTest, MPG_DEMUXER_FUNCTION_TEST_0400, TestSize.Level0)
1152 {
1153     const char *file = "/data/test/media/H264_main@4.2_1280_720_60_MP3_32K_2.mpg";
1154     int fd = open(file, O_RDONLY);
1155     OpenFile(file, fd, &source, &demuxer);
1156     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
1157     CheckTrackSelect();
1158     CheckFrames(119, 12, 57, 57);
1159     close(fd);
1160     fd = -1;
1161 }
1162 
1163 /**
1164  * @tc.number    : MPG_DEMUXER_FUNCTION_TEST_0500
1165  * @tc.name      : demux MPEG2_422p_1280_720_60_MP3_32K_1.mpg
1166  * @tc.desc      : function test
1167  */
1168 HWTEST_F(DemuxerMovFuncNdkTest, MPG_DEMUXER_FUNCTION_TEST_0500, TestSize.Level2)
1169 {
1170     const char *file = "/data/test/media/MPEG2_422p_1280_720_60_MP3_32K_1.mpg";
1171     int fd = open(file, O_RDONLY);
1172     OpenFile(file, fd, &source, &demuxer);
1173     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
1174     CheckTrackSelect();
1175     CheckFrames(119, 12, 57, 57);
1176     close(fd);
1177     fd = -1;
1178 }
1179 
1180 /**
1181  * @tc.number    : MPG_DEMUXER_FUNCTION_TEST_0600
1182  * @tc.name      : demux MPEG2_high_720_480_30_MP2_32K_2.mpg
1183  * @tc.desc      : function test
1184  */
1185 HWTEST_F(DemuxerMovFuncNdkTest, MPG_DEMUXER_FUNCTION_TEST_0600, TestSize.Level0)
1186 {
1187     const char *file = "/data/test/media/MPEG2_high_720_480_30_MP2_32K_2.mpg";
1188     int fd = open(file, O_RDONLY);
1189     OpenFile(file, fd, &source, &demuxer);
1190     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
1191     CheckTrackSelect();
1192     CheckFrames(60, 6, 56, 56);
1193     close(fd);
1194     fd = -1;
1195 }
1196 
1197 /**
1198  * @tc.number    : MPG_DEMUXER_FUNCTION_TEST_0700
1199  * @tc.name      : demux MPEG2_main_352_288_30_MP2_44.1K_1.mpg
1200  * @tc.desc      : function test
1201  */
1202 HWTEST_F(DemuxerMovFuncNdkTest, MPG_DEMUXER_FUNCTION_TEST_0700, TestSize.Level0)
1203 {
1204     const char *file = "/data/test/media/MPEG2_main_352_288_30_MP2_44.1K_1.mpg";
1205     int fd = open(file, O_RDONLY);
1206     OpenFile(file, fd, &source, &demuxer);
1207     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
1208     CheckTrackSelect();
1209     CheckFrames(60, 6, 77, 77);
1210     close(fd);
1211     fd = -1;
1212 }
1213 
1214 /**
1215  * @tc.number    : MPG_DEMUXER_FUNCTION_TEST_0800
1216  * @tc.name      : demux MPEG2_main_1920_1080_30_MP3_48K_2.mpg
1217  * @tc.desc      : function test
1218  */
1219 HWTEST_F(DemuxerMovFuncNdkTest, MPG_DEMUXER_FUNCTION_TEST_0800, TestSize.Level0)
1220 {
1221     const char *file = "/data/test/media/MPEG2_main_1920_1080_30_MP3_48K_2.mpg";
1222     int fd = open(file, O_RDONLY);
1223     OpenFile(file, fd, &source, &demuxer);
1224     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
1225     CheckTrackSelect();
1226     CheckFrames(60, 6, 85, 85);
1227     close(fd);
1228     fd = -1;
1229 }
1230 
1231 /**
1232  * @tc.number    : MPG_DEMUXER_FUNCTION_TEST_0900
1233  * @tc.name      : demux MPEG2_simple_320_240_24_MP3_48K_2.mpg
1234  * @tc.desc      : function test
1235  */
1236 HWTEST_F(DemuxerMovFuncNdkTest, MPG_DEMUXER_FUNCTION_TEST_0900, TestSize.Level0)
1237 {
1238     const char *file = "/data/test/media/MPEG2_simple_320_240_24_MP3_48K_2.mpg";
1239     int fd = open(file, O_RDONLY);
1240     OpenFile(file, fd, &source, &demuxer);
1241     CheckTrackCount(&sourceFormat, source, &g_trackCount, 2);
1242     CheckTrackSelect();
1243     CheckFrames(48, 5, 85, 85);
1244     close(fd);
1245     fd = -1;
1246 }
1247 
1248 /**
1249  * @tc.number    : MPG_DEMUXER_FUNCTION_TEST_1100
1250  * @tc.name      : demuxer mpg file, check key
1251  * @tc.desc      : function test
1252  */
1253 HWTEST_F(DemuxerMovFuncNdkTest, MPG_DEMUXER_FUNCTION_TEST_1100, TestSize.Level2)
1254 {
1255     int trackType = 0;
1256     int64_t duration = 0;
1257     int64_t startTime;
1258     const char *file = "/data/test/media/H264_base@5_1920_1080_30_MP2_44.1K_1.mpg";
1259     int fd = open(file, O_RDONLY);
1260     OpenSourceFormat(file, fd, &source, &sourceFormat);
1261     ASSERT_NE(OH_AVSource_GetTrackFormat(source, 0), nullptr);
1262     ASSERT_TRUE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_DURATION, &duration));
1263     ASSERT_EQ(2011433, duration);
1264     ASSERT_TRUE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_START_TIME, &startTime));
1265     ASSERT_EQ(500000, startTime);
1266     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1267     ASSERT_EQ(2, g_trackCount);
1268     demuxer = OH_AVDemuxer_CreateWithSource(source);
1269     ASSERT_NE(demuxer, nullptr);
1270     const char* mimeType = nullptr;
1271     for (int32_t index = 0; index < g_trackCount; index++) {
1272         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1273     }
1274     OH_AVCodecBufferAttr attr;
1275     int vKeyCount = 0;
1276     int aKeyCount = 0;
1277     bool audioIsEnd = false;
1278     bool videoIsEnd = false;
1279     int audioFrame = 0;
1280     int videoFrame = 0;
1281 
1282     for (int32_t index = 0; index < g_trackCount; index++) {
1283             trackFormat = OH_AVSource_GetTrackFormat(source, index);
1284             ASSERT_NE(trackFormat, nullptr);
1285             ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &trackType));
1286             if ((audioIsEnd && (trackType == MEDIA_TYPE_AUD) && index == MEDIA_TYPE_AUD) ||
1287              (videoIsEnd && (trackType == MEDIA_TYPE_VID) && index == MEDIA_TYPE_VID)) {
1288                 continue;
1289             }
1290             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1291             ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
1292             if (trackType == MEDIA_TYPE_AUD) {
1293                 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
1294                 CheckMPGAudioKey();
1295             } else if (trackType == MEDIA_TYPE_VID) {
1296                 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
1297                 CheckMPGVideoKey();
1298             }
1299             OH_AVFormat_Destroy(trackFormat);
1300             trackFormat = nullptr;
1301         }
1302     close(fd);
1303     fd = -1;
1304 }
1305 
1306 /**
1307  * @tc.number    : MPG_DEMUXER_FUNCTION_TEST_1200
1308  * @tc.name      : demux multi track mpg file
1309  * @tc.desc      : function test
1310  */
1311 HWTEST_F(DemuxerMovFuncNdkTest, MPG_DEMUXER_FUNCTION_TEST_1200, TestSize.Level2)
1312 {
1313     const char *file = "/data/test/media/multi_trk.mpg";
1314     int fd = open(file, O_RDONLY);
1315     OpenFile(file, fd, &source, &demuxer);
1316     CheckTrackCount(&sourceFormat, source, &g_trackCount, 4);
1317     CheckTrackSelect();
1318     FramesMultiTrks(167, 17, 142, 142);
1319     close(fd);
1320     fd = -1;
1321 }
1322 
1323 /**
1324  * @tc.number    : MPG_DEMUXER_FUNCTION_TEST_1300
1325  * @tc.name      : create source with error mpg file
1326  * @tc.desc      : function test
1327  */
1328 HWTEST_F(DemuxerMovFuncNdkTest, MPG_DEMUXER_FUNCTION_TEST_1300, TestSize.Level3)
1329 {
1330     const char *file = "/data/test/media/error.mpg";
1331     int fd = open(file, O_RDONLY);
1332     int64_t size = GetFileSize(file);
1333     cout << file << "----------------------" << fd << "---------" << size << endl;
1334     source = OH_AVSource_CreateWithFD(fd, 0, size);
1335     ASSERT_NE(source, nullptr);
1336     demuxer = OH_AVDemuxer_CreateWithSource(source);
1337     ASSERT_NE(demuxer, nullptr);
1338     OH_AVCodecBufferAttr attr;
1339     ASSERT_NE(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
1340     close(fd);
1341     fd = -1;
1342 }
1343 
1344 /**
1345  * @tc.number    : MPG_DEMUXER_FUNCTION_TEST_1400
1346  * @tc.name      : demux mpg , zero track
1347  * @tc.desc      : function test
1348  */
1349 HWTEST_F(DemuxerMovFuncNdkTest, MPG_DEMUXER_FUNCTION_TEST_1400, TestSize.Level3)
1350 {
1351     const char *file = "/data/test/media/zero_track.mpg";
1352     int fd = open(file, O_RDONLY);
1353     OpenFile(file, fd, &source, &demuxer);
1354     CheckTrackCount(&sourceFormat, source, &g_trackCount, 0);
1355 
1356     ASSERT_EQ(AV_ERR_INVALID_VAL, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
1357     close(fd);
1358     fd = -1;
1359 }
1360 
1361 /**
1362  * @tc.number    : MPG_DEMUXER_FUNCTION_TEST_1500
1363  * @tc.name      : seek to a invalid time, closest mode
1364  * @tc.desc      : function test
1365  */
1366 HWTEST_F(DemuxerMovFuncNdkTest, MPG_DEMUXER_FUNCTION_TEST_1500, TestSize.Level3)
1367 {
1368     const char *file = "/data/test/media/H264_base@5_1920_1080_30_MP2_44.1K_1.mpg";
1369     srand(time(nullptr));
1370     int fd = open(file, O_RDONLY);
1371     int64_t size = GetFileSize(file);
1372     cout << file << "----------------------" << fd << "---------" << size << endl;
1373     source = OH_AVSource_CreateWithFD(fd, 0, size);
1374     ASSERT_NE(source, nullptr);
1375 
1376     demuxer = OH_AVDemuxer_CreateWithSource(source);
1377     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
1378 
1379     ASSERT_NE(demuxer, nullptr);
1380     int64_t invalidPts = 12000 * 16666;
1381     ret = OH_AVDemuxer_SeekToTime(demuxer, invalidPts, SEEK_MODE_CLOSEST_SYNC);
1382     ASSERT_NE(ret, AV_ERR_OK);
1383     close(fd);
1384     fd = -1;
1385 }
1386 
1387 /**
1388  * @tc.number    : MPG_DEMUXER_FUNCTION_TEST_1600
1389  * @tc.name      : remove track before add track
1390  * @tc.desc      : function test
1391  */
1392 HWTEST_F(DemuxerMovFuncNdkTest, MPG_DEMUXER_FUNCTION_TEST_1600, TestSize.Level3)
1393 {
1394     const char *file = "/data/test/media/H264_base@5_1920_1080_30_MP2_44.1K_1.mpg";
1395     srand(time(nullptr));
1396     int fd = open(file, O_RDONLY);
1397     int64_t size = GetFileSize(file);
1398     cout << file << "----------------------" << fd << "---------" << size << endl;
1399     source = OH_AVSource_CreateWithFD(fd, 0, size);
1400     ASSERT_NE(source, nullptr);
1401 
1402     demuxer = OH_AVDemuxer_CreateWithSource(source);
1403     ASSERT_NE(demuxer, nullptr);
1404     ret = OH_AVDemuxer_UnselectTrackByID(demuxer, 0);
1405     ASSERT_EQ(ret, AV_ERR_OK);
1406     ret = OH_AVDemuxer_SelectTrackByID(demuxer, 0);
1407     ASSERT_EQ(ret, AV_ERR_OK);
1408     close(fd);
1409     fd = -1;
1410 }
1411 
1412 /**
1413  * @tc.number    : MPG_DEMUXER_FUNCTION_TEST_1700
1414  * @tc.name      : remove all tracks before demux finish
1415  * @tc.desc      : function test
1416  */
1417 HWTEST_F(DemuxerMovFuncNdkTest, MPG_DEMUXER_FUNCTION_TEST_1700, TestSize.Level3)
1418 {
1419     OH_AVCodecBufferAttr attr;
1420     const char *file = "/data/test/media/H264_base@5_1920_1080_30_MP2_44.1K_1.mpg";
1421     bool isEnd = false;
1422     int count = 0;
1423     int fd = open(file, O_RDONLY);
1424     int64_t size = GetFileSize(file);
1425     cout << file << "----------------------" << fd << "---------" << size << endl;
1426     source = OH_AVSource_CreateWithFD(fd, 0, size);
1427     ASSERT_NE(source, nullptr);
1428 
1429     demuxer = OH_AVDemuxer_CreateWithSource(source);
1430     ASSERT_NE(demuxer, nullptr);
1431 
1432     sourceFormat = OH_AVSource_GetSourceFormat(source);
1433     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1434     ASSERT_EQ(2, g_trackCount);
1435     for (int32_t index = 0; index < g_trackCount; index++) {
1436         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1437     }
1438     srand(time(nullptr));
1439     int pos = rand() % 60;
1440     cout << " pos= " << pos << endl;
1441     while (!isEnd) {
1442         for (int32_t index = 0; index < g_trackCount; index++) {
1443             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1444             if (count == pos) {
1445                 cout << count << " count == pos!!!!!!!!!" << endl;
1446                 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_UnselectTrackByID(demuxer, 0));
1447                 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_UnselectTrackByID(demuxer, 1));
1448                 ASSERT_EQ(AV_ERR_OPERATE_NOT_PERMIT, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1449                 isEnd = true;
1450                 break;
1451             }
1452 
1453             if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1454                 isEnd = true;
1455                 cout << "is end !!!!!!!!!!!!!!!" << endl;
1456             }
1457             if (index == MEDIA_TYPE_AUD) {
1458                 count++;
1459             }
1460         }
1461     }
1462     close(fd);
1463     fd = -1;
1464 }
1465 
1466 /**
1467  * @tc.number    : MPG_DEMUXER_FUNCTION_TEST_1800
1468  * @tc.name      : start demux bufore add track
1469  * @tc.desc      : function test
1470  */
1471 HWTEST_F(DemuxerMovFuncNdkTest, MPG_DEMUXER_FUNCTION_TEST_1800, TestSize.Level3)
1472 {
1473     uint32_t trackIndex = 0;
1474     OH_AVCodecBufferAttr attr;
1475     const char *file = "/data/test/media/H264_base@5_1920_1080_30_MP2_44.1K_1.mpg";
1476     srand(time(nullptr));
1477     int fd = open(file, O_RDONLY);
1478     int64_t size = GetFileSize(file);
1479     cout << file << "----------------------" << fd << "---------" << size << endl;
1480     source = OH_AVSource_CreateWithFD(fd, 0, size);
1481     ASSERT_NE(source, nullptr);
1482 
1483     demuxer = OH_AVDemuxer_CreateWithSource(source);
1484     ASSERT_NE(demuxer, nullptr);
1485     ret = OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &attr);
1486     ASSERT_EQ(ret, AV_ERR_OPERATE_NOT_PERMIT);
1487     close(fd);
1488     fd = -1;
1489 }