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