• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 == 0)) || (videoIsEnd && (index == 1))) {
142                 continue;
143             }
144             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer_list[i], index, memory_list[i], &attr));
145 
146             if ((index == 0) && (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS)) {
147                 audioIsEnd = true;
148             }
149             if ((index == 1) && (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS)) {
150                 videoIsEnd = true;
151             }
152         }
153     }
154 }
155 
156 /**
157  * @tc.number    : DEMUXER_RELI_1000
158  * @tc.name      : create 16 instances create-destory
159  * @tc.desc      : function test
160  */
161 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_1000, TestSize.Level3)
162 {
163     int len = 256;
164     int num = 0;
165     vector<std::thread> vecThread;
166     for (int i = 0; i < g_maxThread; i++) {
167         memory_list[i] = OH_AVMemory_Create(g_width * g_height);
168         char file[256] = {};
169         sprintf_s(file, len, "/data/test/media/16/%d_video_audio.mp4", i);
170         g_fdList[i] = open(file, O_RDONLY);
171         int64_t size = GetFileSize(file);
172         cout << file << "----------------------" << g_fdList[i] << "---------" << size << endl;
173 
174         source_list[i] = OH_AVSource_CreateWithFD(g_fdList[i], 0, size);
175         ASSERT_NE(source_list[i], nullptr);
176 
177         demuxer_list[i] = OH_AVDemuxer_CreateWithSource(source_list[i]);
178         ASSERT_NE(demuxer_list[i], nullptr);
179         vecThread.emplace_back(DemuxFunc, i, num);
180     }
181     for (auto &val : vecThread) {
182         val.join();
183     }
184 }
185 
186 /**
187  * @tc.number    : DEMUXER_RELI_0200
188  * @tc.name      : create 16 instances repeat create-destory
189  * @tc.desc      : function test
190  */
191 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_0200, TestSize.Level3)
192 {
193     int num = 0;
194     int len = 256;
195     while (num < 10) {
196         num++;
197         vector<std::thread> vecThread;
198         for (int i = 0; i < g_maxThread; i++) {
199             memory_list[i] = OH_AVMemory_Create(g_width * g_height);
200             char file[256] = {};
201             sprintf_s(file, len, "/data/test/media/16/%d_video_audio.mp4", i);
202             g_fdList[i] = open(file, O_RDONLY);
203             int64_t size = GetFileSize(file);
204             cout << file << "----------------------" << g_fdList[i] << "---------" << size << endl;
205 
206             source_list[i] = OH_AVSource_CreateWithFD(g_fdList[i], 0, size);
207             ASSERT_NE(source_list[i], nullptr);
208 
209             demuxer_list[i] = OH_AVDemuxer_CreateWithSource(source_list[i]);
210             ASSERT_NE(demuxer_list[i], nullptr);
211             vecThread.emplace_back(DemuxFunc, i, num);
212         }
213         for (auto &val : vecThread) {
214             val.join();
215         }
216 
217         for (int i = 0; i < g_maxThread; i++) {
218             if (demuxer_list[i] != nullptr) {
219                 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_Destroy(demuxer_list[i]));
220                 demuxer_list[i] = nullptr;
221             }
222 
223             if (source_list[i] != nullptr) {
224                 ASSERT_EQ(AV_ERR_OK, OH_AVSource_Destroy(source_list[i]));
225                 source_list[i] = nullptr;
226             }
227             if (memory_list[i] != nullptr) {
228                 ASSERT_EQ(AV_ERR_OK, OH_AVMemory_Destroy(memory_list[i]));
229                 memory_list[i] = nullptr;
230             }
231             std::cout << i << "            finish Destroy!!!!" << std::endl;
232 
233             close(g_fdList[i]);
234         }
235         cout << "num: " << num << endl;
236     }
237 }
238 
239 /**
240  * @tc.number    : DEMUXER_RELI_0300
241  * @tc.name      : create 17 instances,17 failed
242  * @tc.desc      : function test
243  */
244 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_0300, TestSize.Level3)
245 {
246     int num = 0;
247     int len = 256;
248     int64_t size = 0;
249     vector<std::thread> vecThread;
250     for (int i = 0; i < g_maxThread; i++) {
251         memory_list[i] = OH_AVMemory_Create(g_width * g_height);
252         char file[256] = {};
253         sprintf_s(file, len, "/data/test/media/16/%d_video_audio.mp4", i);
254         g_fdList[i] = open(file, O_RDONLY);
255         size = GetFileSize(file);
256         cout << file << "----------------------" << g_fdList[i] << "---------" << size << endl;
257 
258         source_list[i] = OH_AVSource_CreateWithFD(g_fdList[i], 0, size);
259         ASSERT_NE(source_list[i], nullptr);
260 
261         demuxer_list[i] = OH_AVDemuxer_CreateWithSource(source_list[i]);
262         ASSERT_NE(demuxer_list[i], nullptr);
263         vecThread.emplace_back(DemuxFunc, i, num);
264     }
265     for (auto &val : vecThread) {
266         val.join();
267     }
268 
269     source = OH_AVSource_CreateWithFD(g_fdList[15], 0, size);
270     ASSERT_EQ(source, nullptr);
271     demuxer = OH_AVDemuxer_CreateWithSource(source);
272     ASSERT_EQ(demuxer, nullptr);
273 }
274 
275 /**
276  * @tc.number    : DEMUXER_RELI_0400
277  * @tc.name      : one instance repeat create destory
278  * @tc.desc      : function test
279  */
280 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_0400, TestSize.Level0)
281 {
282     int num = 0;
283     OH_AVCodecBufferAttr attr;
284 
285     const char *file = "/data/test/media/01_video_audio.mp4";
286     while (num < 10) {
287         bool audioIsEnd = false;
288         bool videoIsEnd = false;
289 
290         int fd = open(file, O_RDONLY);
291         int64_t size = GetFileSize(file);
292         cout << file << "----------------------" << fd << "---------" << size << endl;
293         num++;
294         cout << num << endl;
295         source = OH_AVSource_CreateWithFD(fd, 0, size);
296         ASSERT_NE(source, nullptr);
297 
298         demuxer = OH_AVDemuxer_CreateWithSource(source);
299         ASSERT_NE(demuxer, nullptr);
300 
301         for (int32_t index = 0; index < 2; index++) {
302             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
303         }
304         while (!audioIsEnd || !videoIsEnd) {
305             for (int32_t index = 0; index < 2; index++) {
306 
307                 if ((audioIsEnd && (index == 0)) || (videoIsEnd && (index == 1))) {
308                     continue;
309                 }
310                 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
311 
312                 if ((index == 0) && (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS)) {
313                     audioIsEnd = true;
314                     cout << "    audio is end !!!!!!!!!!!!!!!" << endl;
315                 }
316                 if ((index == 1) && (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS)) {
317                     videoIsEnd = true;
318                     cout << "   video is end !!!!!!!!!!!!!!!" << endl;
319                 }
320             }
321         }
322         if (source != nullptr) {
323             OH_AVSource_Destroy(source);
324             source = nullptr;
325         }
326         if (demuxer != nullptr) {
327             OH_AVDemuxer_Destroy(demuxer);
328             demuxer = nullptr;
329         }
330         close(fd);
331     }
332 }
333 
334 /**
335  * @tc.number    : DEMUXER_RELI_0500
336  * @tc.name      : one instance demux long file
337  * @tc.desc      : function test
338  */
339 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_0500, TestSize.Level3)
340 {
341     int num = 0;
342     OH_AVCodecBufferAttr attr;
343 
344     const char *file = "/data/test/media/long.mp4";
345 
346     bool audioIsEnd = false;
347     bool videoIsEnd = false;
348     int audioFrame = 0;
349     int videoFrame = 0;
350 
351     int fd = open(file, O_RDONLY);
352     int64_t size = GetFileSize(file);
353     cout << file << "----------------------" << fd << "---------" << size << endl;
354     num++;
355     cout << num << endl;
356     source = OH_AVSource_CreateWithFD(fd, 0, size);
357     ASSERT_NE(source, nullptr);
358 
359     demuxer = OH_AVDemuxer_CreateWithSource(source);
360     ASSERT_NE(demuxer, nullptr);
361 
362     for (int32_t index = 0; index < 2; index++) {
363         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
364     }
365     while (!audioIsEnd || !videoIsEnd) {
366         for (int32_t index = 0; index < 2; index++) {
367             if ((audioIsEnd && (index == 0)) || (videoIsEnd && (index == 1))) {
368                 continue;
369             }
370             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
371 
372             if (index == 0) {
373                 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
374                     audioIsEnd = true;
375                     cout << audioFrame << "    audio is end !!!!!!!!!!!!!!!" << endl;
376                 } else {
377                     audioFrame++;
378                 }
379             } else if (index == 1) {
380                 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
381                     videoIsEnd = true;
382                     cout << videoFrame << "   video is end !!!!!!!!!!!!!!!" << endl;
383                 } else {
384                     videoFrame++;
385                 }
386             }
387         }
388     }
389     close(fd);
390 }
391 
392 /**
393  * @tc.number    : DEMUXER_RELI_0100
394  * @tc.name      : OH_AVSource_CreateWithURI Repeat Call
395  * @tc.desc      : api test
396  */
397 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_0100, TestSize.Level2)
398 {
399     OH_AVSource *source1 = OH_AVSource_CreateWithURI(const_cast<char *>(URI1));
400     cout << URI1 << "-----------------------" << endl;
401     ASSERT_NE(source1, nullptr);
402     OH_AVSource *source2 = OH_AVSource_CreateWithURI(const_cast<char *>(URI2));
403     cout << URI2 << "-----------------------" << endl;
404     ASSERT_NE(source2, nullptr);
405     ASSERT_EQ(AV_ERR_OK, OH_AVSource_Destroy(source1));
406     source1 = nullptr;
407     ASSERT_EQ(AV_ERR_OK, OH_AVSource_Destroy(source2));
408     source2 = nullptr;
409 }
410 
411 /**
412  * @tc.number    : DEMUXER_RELI_4400
413  * @tc.name      : OH_AVSource_CreateWithURI with unSupported rtsp uri
414  * @tc.desc      : api test
415  */
416 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_4400, TestSize.Level2)
417 {
418     const char *URI = "rtp://192.168.3.11:12345";
419     cout << URI << "------" << endl;
420     source = OH_AVSource_CreateWithURI(const_cast<char *>(URI));
421     ASSERT_EQ(source, nullptr);
422 }
423 
424 /**
425  * @tc.number    : DEMUXER_RELI_4500
426  * @tc.name      : OH_AVSource_CreateWithURI with unSupported rtp uri
427  * @tc.desc      : api test
428  */
429 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_4500, TestSize.Level2)
430 {
431     const char *URI = "rtp://192.168.3.11:12345";
432     cout << URI << "------" << endl;
433     source = OH_AVSource_CreateWithURI(const_cast<char *>(URI));
434     ASSERT_EQ(source, nullptr);
435 }
436 
437 /**
438  * @tc.number    : DEMUXER_RELI_4600
439  * @tc.name      : OH_AVSource_CreateWithURI with invalid uri
440  * @tc.desc      : api test
441  */
442 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_4600, TestSize.Level2)
443 {
444     const char *URI = "https://media.w3.org/2010/05/sinte/trailer.mp4";
445     cout << URI << "------" << endl;
446     source = OH_AVSource_CreateWithURI(const_cast<char *>(URI));
447     ASSERT_EQ(source, nullptr);
448 }
449 
450 /**
451  * @tc.number    : DEMUXER_RELI_4700
452  * @tc.name      : OH_AVSource_CreateWithURI with https
453  * @tc.desc      : api test
454  */
455 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_4700, TestSize.Level2)
456 {
457     OH_AVCodecBufferAttr attr;
458     bool audioIsEnd = false;
459     bool videoIsEnd = false;
460     int audioFrame = 0;
461     int videoFrame = 0;
462     int tarckType = 0;
463     const char *URI = "https://media.w3.org/2010/05/sintel/trailer.mp4";
464     cout << URI << "------" << endl;
465     source = OH_AVSource_CreateWithURI(const_cast<char *>(URI));
466     ASSERT_NE(source, nullptr);
467 
468     demuxer = OH_AVDemuxer_CreateWithSource(source);
469     ASSERT_NE(demuxer, nullptr);
470 
471     sourceFormat = OH_AVSource_GetSourceFormat(source);
472     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
473     ASSERT_EQ(2, g_trackCount);
474     for (int32_t index = 0; index < g_trackCount; index++) {
475         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
476     }
477     while (!audioIsEnd || !videoIsEnd) {
478         for (int32_t index = 0; index < g_trackCount; index++) {
479 
480             trackFormat = OH_AVSource_GetTrackFormat(source, index);
481             ASSERT_NE(trackFormat, nullptr);
482             ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
483 
484             if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
485                 continue;
486             }
487             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
488 
489             if (tarckType == 0) {
490                 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
491                     audioIsEnd = true;
492                     cout << audioFrame << "    audio is end !!!!!!!!!!!!!!!" << endl;
493                 } else {
494                     audioFrame++;
495                 }
496             } else if (tarckType == 1) {
497                 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
498                     videoIsEnd = true;
499                     cout << videoFrame << "   video is end !!!!!!!!!!!!!!!" << endl;
500                 } else {
501                     videoFrame++;
502                 }
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_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 2));
529     ASSERT_EQ(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             } else {
566                 audioFrame++;
567                 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
568                     keyCount++;
569                 }
570             }
571         }
572     }
573     ASSERT_EQ(audioFrame, 9150);
574     ASSERT_EQ(keyCount, 9150);
575 }
576 
577 /**
578  * @tc.number    : DEMUXER_RELI_0500
579  * @tc.name      : create source with uri,aac
580  * @tc.desc      : function test
581  */
582 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_5000, TestSize.Level0)
583 {
584     OH_AVCodecBufferAttr attr;
585     bool isEnd = false;
586 
587     const char *URI = "http://192.168.3.11:8080/share/audio/AAC_48000_1.aac";
588     cout << URI << "------" << endl;
589     source = OH_AVSource_CreateWithURI(const_cast<char *>(URI));
590     ASSERT_NE(source, nullptr);
591 
592     demuxer = OH_AVDemuxer_CreateWithSource(source);
593     ASSERT_NE(demuxer, nullptr);
594 
595     sourceFormat = OH_AVSource_GetSourceFormat(source);
596     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
597 
598     for (int32_t index = 0; index < g_trackCount; index++) {
599         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
600     }
601 
602     int audioFrame = 0;
603     int keyCount = 0;
604     while (!isEnd) {
605         for (int32_t index = 0; index < g_trackCount; index++) {
606             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
607             cout << attr.size << "size---------------pts:" << attr.pts << endl;
608             if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
609                 isEnd = true;
610                 cout << "isend !!!!!!!!!!!!!!!" << endl;
611             } else {
612                 audioFrame++;
613                 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
614                     keyCount++;
615                 }
616             }
617         }
618     }
619     ASSERT_EQ(audioFrame, 9457);
620     ASSERT_EQ(keyCount, 9457);
621 }
622 
623 /**
624  * @tc.number    : DEMUXER_RELI_5100
625  * @tc.name      : create source with uri,flac
626  * @tc.desc      : function test
627  */
628 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_5100, TestSize.Level0)
629 {
630     OH_AVCodecBufferAttr attr;
631     bool isEnd = false;
632 
633     const char *URI = "http://192.168.3.11:8080/share/audio/FLAC_48000_1.flac";
634     cout << URI << "------" << endl;
635     source = OH_AVSource_CreateWithURI(const_cast<char *>(URI));
636     ASSERT_NE(source, nullptr);
637 
638     demuxer = OH_AVDemuxer_CreateWithSource(source);
639     ASSERT_NE(demuxer, nullptr);
640 
641     sourceFormat = OH_AVSource_GetSourceFormat(source);
642     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
643 
644     for (int32_t index = 0; index < g_trackCount; index++) {
645         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
646     }
647 
648     int audioFrame = 0;
649     int keyCount = 0;
650     while (!isEnd) {
651         for (int32_t index = 0; index < g_trackCount; index++) {
652             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
653             cout << attr.size << "size---------------pts:" << attr.pts << endl;
654             if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
655                 isEnd = true;
656                 cout << "isend !!!!!!!!!!!!!!!" << endl;
657             } else {
658                 audioFrame++;
659                 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
660                     keyCount++;
661                 }
662             }
663         }
664     }
665     ASSERT_EQ(audioFrame, 2288);
666     ASSERT_EQ(keyCount, 2288);
667 }
668 
669 /**
670  * @tc.number    : DEMUXER_RELI_5200
671  * @tc.name      : create source with uri,m4a
672  * @tc.desc      : function test
673  */
674 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_5200, TestSize.Level0)
675 {
676     OH_AVCodecBufferAttr attr;
677     bool isEnd = false;
678 
679     const char *URI = "http://192.168.3.11:8080/share/audio/M4A_48000_1.m4a";
680     cout << URI << "------" << endl;
681     source = OH_AVSource_CreateWithURI(const_cast<char *>(URI));
682     ASSERT_NE(source, nullptr);
683 
684     demuxer = OH_AVDemuxer_CreateWithSource(source);
685     ASSERT_NE(demuxer, nullptr);
686 
687     sourceFormat = OH_AVSource_GetSourceFormat(source);
688     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
689 
690     for (int32_t index = 0; index < g_trackCount; index++) {
691         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
692     }
693 
694     int audioFrame = 0;
695     int keyCount = 0;
696     while (!isEnd) {
697         for (int32_t index = 0; index < g_trackCount; index++) {
698             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
699             cout << attr.size << "size---------------pts:" << attr.pts << endl;
700             if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
701                 isEnd = true;
702                 cout << "isend !!!!!!!!!!!!!!!" << endl;
703             } else {
704                 audioFrame++;
705                 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
706                     keyCount++;
707                 }
708             }
709         }
710     }
711     ASSERT_EQ(audioFrame, 10293);
712     ASSERT_EQ(keyCount, 10293);
713 }
714 
715 /**
716  * @tc.number    : DEMUXER_RELI_5300
717  * @tc.name      : create source with uri,mp3
718  * @tc.desc      : function test
719  */
720 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_5300, TestSize.Level0)
721 {
722     OH_AVCodecBufferAttr attr;
723     bool isEnd = false;
724 
725     const char *URI = "http://192.168.3.11:8080/share/audio/MP3_48000_1.mp3";
726     cout << URI << "------" << endl;
727     source = OH_AVSource_CreateWithURI(const_cast<char *>(URI));
728     ASSERT_NE(source, nullptr);
729 
730     demuxer = OH_AVDemuxer_CreateWithSource(source);
731     ASSERT_NE(demuxer, nullptr);
732 
733     sourceFormat = OH_AVSource_GetSourceFormat(source);
734     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
735 
736     for (int32_t index = 0; index < g_trackCount; index++) {
737         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
738     }
739 
740     int audioFrame = 0;
741     int keyCount = 0;
742     while (!isEnd) {
743         for (int32_t index = 0; index < g_trackCount; index++) {
744             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
745             cout << attr.size << "size---------------pts:" << attr.pts << endl;
746             if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
747                 isEnd = true;
748                 cout << "isend !!!!!!!!!!!!!!!" << endl;
749             } else {
750                 audioFrame++;
751                 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
752                     keyCount++;
753                 }
754             }
755         }
756     }
757     ASSERT_EQ(audioFrame, 9150);
758     ASSERT_EQ(keyCount, 9150);
759 }
760 
761 /**
762  * @tc.number    : DEMUXER_RELI_5400
763  * @tc.name      : create source with uri,ogg
764  * @tc.desc      : function test
765  */
766 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_5400, TestSize.Level0)
767 {
768     OH_AVCodecBufferAttr attr;
769     bool isEnd = false;
770 
771     const char *URI = "http://192.168.3.11:8080/share/audio/OGG_48000_1.ogg";
772     cout << URI << "------" << endl;
773     source = OH_AVSource_CreateWithURI(const_cast<char *>(URI));
774     ASSERT_NE(source, nullptr);
775 
776     demuxer = OH_AVDemuxer_CreateWithSource(source);
777     ASSERT_NE(demuxer, nullptr);
778 
779     sourceFormat = OH_AVSource_GetSourceFormat(source);
780     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
781 
782     for (int32_t index = 0; index < g_trackCount; index++) {
783         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
784     }
785 
786     int audioFrame = 0;
787     int keyCount = 0;
788     while (!isEnd) {
789         for (int32_t index = 0; index < g_trackCount; index++) {
790             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
791             cout << attr.size << "size---------------pts:" << attr.pts << endl;
792             if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
793                 isEnd = true;
794                 cout << "isend !!!!!!!!!!!!!!!" << endl;
795             } else {
796                 audioFrame++;
797                 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
798                     keyCount++;
799                 }
800             }
801         }
802     }
803     ASSERT_EQ(audioFrame, 11439);
804     ASSERT_EQ(keyCount, 11439);
805 }
806 
807 /**
808  * @tc.number    : DEMUXER_RELI_5500
809  * @tc.name      : create source with uri,wav
810  * @tc.desc      : function test
811  */
812 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_5500, TestSize.Level0)
813 {
814     OH_AVCodecBufferAttr attr;
815     bool isEnd = false;
816 
817     const char *URI = "http://192.168.3.11:8080/share/audio/wav_48000_1.wav";
818     cout << URI << "------" << endl;
819     source = OH_AVSource_CreateWithURI(const_cast<char *>(URI));
820     ASSERT_NE(source, nullptr);
821 
822     demuxer = OH_AVDemuxer_CreateWithSource(source);
823     ASSERT_NE(demuxer, nullptr);
824 
825     sourceFormat = OH_AVSource_GetSourceFormat(source);
826     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
827 
828     for (int32_t index = 0; index < g_trackCount; index++) {
829         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
830     }
831 
832     int audioFrame = 0;
833     int keyCount = 0;
834     while (!isEnd) {
835         for (int32_t index = 0; index < g_trackCount; index++) {
836             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
837             cout << attr.size << "size---------------pts:" << attr.pts << endl;
838             if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
839                 isEnd = true;
840                 cout << "isend !!!!!!!!!!!!!!!" << endl;
841             } else {
842                 audioFrame++;
843                 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
844                     keyCount++;
845                 }
846             }
847         }
848     }
849     ASSERT_EQ(audioFrame, 5146);
850     ASSERT_EQ(keyCount, 5146);
851 }
852 
853 /**
854  * @tc.number    : DEMUXER_RELI_5600
855  * @tc.name      : create source with uri,mp4
856  * @tc.desc      : function test
857  */
858 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_5600, TestSize.Level0)
859 {
860     OH_AVCodecBufferAttr attr;
861     bool audioIsEnd = false;
862     bool videoIsEnd = false;
863     int audioFrame = 0;
864     int videoFrame = 0;
865     int tarckType = 0;
866     const char *URI = "http://192.168.3.11:8080/share/01_video_audio.mp4";
867     cout << URI << "------" << endl;
868     source = OH_AVSource_CreateWithURI(const_cast<char *>(URI));
869     ASSERT_NE(source, nullptr);
870 
871     demuxer = OH_AVDemuxer_CreateWithSource(source);
872     ASSERT_NE(demuxer, nullptr);
873 
874     sourceFormat = OH_AVSource_GetSourceFormat(source);
875     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
876     ASSERT_EQ(2, g_trackCount);
877     for (int32_t index = 0; index < g_trackCount; index++) {
878         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
879     }
880     while (!audioIsEnd || !videoIsEnd) {
881         for (int32_t index = 0; index < g_trackCount; index++) {
882 
883             trackFormat = OH_AVSource_GetTrackFormat(source, index);
884             ASSERT_NE(trackFormat, nullptr);
885             ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
886 
887             if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
888                 continue;
889             }
890             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
891 
892             if (tarckType == 0) {
893                 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
894                     audioIsEnd = true;
895                     cout << audioFrame << "    audio is end !!!!!!!!!!!!!!!" << endl;
896                 } else {
897                     audioFrame++;
898                 }
899             } else if (tarckType == 1) {
900                 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
901                     videoIsEnd = true;
902                     cout << videoFrame << "   video is end !!!!!!!!!!!!!!!" << endl;
903                 } else {
904                     videoFrame++;
905                 }
906             }
907         }
908     }
909 }
910 
CreateDemuxer(char * URI)911 void CreateDemuxer(char *URI)
912 {
913     int two = 2;
914     source = OH_AVSource_CreateWithURI(const_cast<char *>(URI));
915     ASSERT_NE(source, nullptr);
916 
917     demuxer = OH_AVDemuxer_CreateWithSource(source);
918     ASSERT_NE(demuxer, nullptr);
919 
920     sourceFormat = OH_AVSource_GetSourceFormat(source);
921     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
922     ASSERT_EQ(two, g_trackCount);
923 
924     for (int32_t index = 0; index < g_trackCount; index++) {
925         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
926     }
927 }
928 
929 /**
930  * @tc.number    : DEMUXER_RELI_5700
931  * @tc.name      : create source with uri,hvcc mp4
932  * @tc.desc      : function test
933  */
934 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_5700, TestSize.Level0)
935 {
936     int tarckType = 0;
937     OH_AVCodecBufferAttr attr;
938     bool audioIsEnd = false;
939     bool videoIsEnd = false;
940     int audioFrame = 0;
941     int videoFrame = 0;
942     const char *URI = "http://192.168.3.11:8080/share/hvcc_1920x1080_60.mp4";
943     cout << URI << "------" << endl;
944     CreateDemuxer(const_cast<char *>(URI));
945     int aKeyCount = 0;
946     int vKeyCount = 0;
947     while (!audioIsEnd || !videoIsEnd) {
948         for (int32_t index = 0; index < g_trackCount; index++) {
949 
950             trackFormat = OH_AVSource_GetTrackFormat(source, index);
951             ASSERT_NE(trackFormat, nullptr);
952             ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
953 
954             if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
955                 continue;
956             }
957             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
958 
959             if (tarckType == 0) {
960                 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
961                     audioIsEnd = true;
962                 } else {
963                     audioFrame++;
964                     if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
965                         aKeyCount++;
966                     }
967                 }
968             } else if (tarckType == 1) {
969                 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
970                     videoIsEnd = true;
971                 } else {
972                     videoFrame++;
973                     if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
974                         vKeyCount++;
975                     }
976                 }
977             }
978         }
979     }
980     ASSERT_EQ(audioFrame, 433);
981     ASSERT_EQ(videoFrame, 602);
982     ASSERT_EQ(aKeyCount, 433);
983     ASSERT_EQ(vKeyCount, 3);
984 }
985 
986 /**
987  * @tc.number    : DEMUXER_RELI_5800
988  * @tc.name      : create source with uri,wav
989  * @tc.desc      : function test
990  */
991 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_5800, TestSize.Level0)
992 {
993     int tarckType = 0;
994     OH_AVCodecBufferAttr attr;
995     bool audioIsEnd = false;
996     bool videoIsEnd = false;
997     int audioFrame = 0;
998     int videoFrame = 0;
999 
1000     const char *URI = "http://192.168.3.11:8080/share/avcc_10sec.mp4";
1001     cout << URI << "------" << endl;
1002     CreateDemuxer(const_cast<char *>(URI));
1003     while (!audioIsEnd || !videoIsEnd) {
1004         for (int32_t index = 0; index < g_trackCount; index++) {
1005 
1006             trackFormat = OH_AVSource_GetTrackFormat(source, index);
1007             ASSERT_NE(trackFormat, nullptr);
1008             ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1009 
1010             if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
1011                 continue;
1012             }
1013             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1014 
1015             if (tarckType == 0) {
1016                 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1017                     audioIsEnd = true;
1018                     cout << audioFrame << "    audio is end !!!!!!!!!!!!!!!" << endl;
1019                 } else {
1020                     audioFrame++;
1021                 }
1022             } else if (tarckType == 1) {
1023                 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1024                     videoIsEnd = true;
1025                     cout << videoFrame << "   video is end !!!!!!!!!!!!!!!" << endl;
1026                 } else {
1027                     videoFrame++;
1028                     uint8_t *buffer = OH_AVMemory_GetAddr(memory);
1029                     for (int i = 0; i < 16; i++) {
1030                         printf("%2x ", buffer[i]);
1031                     }
1032                 }
1033             }
1034         }
1035     }
1036     ASSERT_EQ(audioFrame, 431);
1037     ASSERT_EQ(videoFrame, 600);
1038 }
1039 
1040 /**
1041  * @tc.number    : DEMUXER_RELI_5900
1042  * @tc.name      : create source with uri,wav
1043  * @tc.desc      : function test
1044  */
1045 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_5900, TestSize.Level0)
1046 {
1047     int tarckType = 0;
1048     OH_AVCodecBufferAttr attr;
1049     bool audioIsEnd = false;
1050     bool videoIsEnd = false;
1051     int audioFrame = 0;
1052     int videoFrame = 0;
1053     const char *URI = "http://192.168.3.11:8080/share/ts_video.ts";
1054     cout << URI << "------" << endl;
1055     CreateDemuxer(const_cast<char *>(URI));
1056     while (!audioIsEnd || !videoIsEnd) {
1057         for (int32_t index = 0; index < g_trackCount; index++) {
1058 
1059             trackFormat = OH_AVSource_GetTrackFormat(source, index);
1060             ASSERT_NE(trackFormat, nullptr);
1061             ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1062 
1063             if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
1064                 continue;
1065             }
1066             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1067 
1068             if (tarckType == 0) {
1069                 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1070                     audioIsEnd = true;
1071                     cout << audioFrame << "    audio is end !!!!!!!!!!!!!!!" << endl;
1072                 } else {
1073                     audioFrame++;
1074                 }
1075             } else if (tarckType == 1) {
1076                 if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1077                     videoIsEnd = true;
1078                     cout << videoFrame << "   video is end !!!!!!!!!!!!!!!" << endl;
1079                 } else {
1080                     videoFrame++;
1081                 }
1082             }
1083         }
1084     }
1085     ASSERT_EQ(audioFrame, 384);
1086     ASSERT_EQ(videoFrame, 602);
1087 }
1088 
1089 /**
1090  * @tc.number    : DEMUXER_RELI_6000
1091  * @tc.name      : create source with uri,wav
1092  * @tc.desc      : function test
1093  */
1094 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_6000, TestSize.Level0)
1095 {
1096     const char *URI = "http://192.168.3.11:8080/share/zero_track.mp4";
1097     cout << URI << "------" << endl;
1098     source = OH_AVSource_CreateWithURI(const_cast<char *>(URI));
1099     ASSERT_NE(source, nullptr);
1100 
1101     demuxer = OH_AVDemuxer_CreateWithSource(source);
1102     ASSERT_NE(demuxer, nullptr);
1103 
1104     sourceFormat = OH_AVSource_GetSourceFormat(source);
1105     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1106     ASSERT_EQ(g_trackCount, 0);
1107 
1108     ASSERT_EQ(AV_ERR_INVALID_VAL, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
1109 }
1110 
1111 /**
1112  * @tc.number    : DEMUXER_RELI_6100
1113  * @tc.name      : create source with uri
1114  * @tc.desc      : reliable test
1115  */
1116 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_6100, TestSize.Level0)
1117 {
1118     int num = 0;
1119     OH_AVCodecBufferAttr attr;
1120     const char *URI = "http://192.168.3.11:8080/share/avcc_10sec.mp4";
1121     cout << URI << "------" << endl;
1122     while (num < 10) {
1123         cout<<"num: "<<num<<endl;
1124         int tarckType = 0;
1125         bool audioIsEnd = false;
1126         bool videoIsEnd = false;
1127         int audioFrame = 0;
1128         int videoFrame = 0;
1129         CreateDemuxer(const_cast<char *>(URI));
1130         while (!audioIsEnd || !videoIsEnd) {
1131             for (int32_t index = 0; index < g_trackCount; index++) {
1132 
1133                 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1134                 ASSERT_NE(trackFormat, nullptr);
1135                 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1136 
1137                 if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
1138                     continue;
1139                 }
1140                 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1141 
1142                 if (tarckType == 0) {
1143                     if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1144                         audioIsEnd = true;
1145                         cout << audioFrame << "    audio is end !!!!!!!!!!!!!!!" << endl;
1146                     } else {
1147                         audioFrame++;
1148                     }
1149                 } else if (tarckType == 1) {
1150                     if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1151                         videoIsEnd = true;
1152                         cout << videoFrame << "   video is end !!!!!!!!!!!!!!!" << endl;
1153                     } else {
1154                         videoFrame++;
1155                     }
1156                 }
1157             }
1158         }
1159         ASSERT_EQ(audioFrame, 431);
1160         ASSERT_EQ(videoFrame, 600);
1161         num++;
1162     }
1163 }
1164 
1165 /**
1166  * @tc.number    : DEMUXER_RELI_6200
1167  * @tc.name      : create source with uri
1168  * @tc.desc      : reliable test
1169  */
1170 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_6200, TestSize.Level3)
1171 {
1172     int num = 0;
1173     OH_AVCodecBufferAttr attr;
1174     const char *URI = "https://media.w3.org/2010/05/sintel/trailer.mp4";
1175     cout << URI << "------" << endl;
1176     while (num < 10) {
1177         cout<<"num: "<<num<<endl;
1178         int tarckType = 0;
1179         bool audioIsEnd = false;
1180         bool videoIsEnd = false;
1181         int audioFrame = 0;
1182         int videoFrame = 0;
1183         CreateDemuxer(const_cast<char *>(URI));
1184         while (!audioIsEnd || !videoIsEnd) {
1185             for (int32_t index = 0; index < g_trackCount; index++) {
1186 
1187                 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1188                 ASSERT_NE(trackFormat, nullptr);
1189                 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1190 
1191                 if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
1192                     continue;
1193                 }
1194                 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1195 
1196                 if (tarckType == 0) {
1197                     if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1198                         audioIsEnd = true;
1199                         cout << audioFrame << "    audio is end !!!!!!!!!!!!!!!" << endl;
1200                     } else {
1201                         audioFrame++;
1202                     }
1203                 } else if (tarckType == 1) {
1204                     if (attr.flags == OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1205                         videoIsEnd = true;
1206                         cout << videoFrame << "   video is end !!!!!!!!!!!!!!!" << endl;
1207                     } else {
1208                         videoFrame++;
1209                     }
1210                 }
1211             }
1212         }
1213         num++;
1214     }
1215 }
1216 
1217 /**
1218  * @tc.number    : DEMUXER_RELI_6300
1219  * @tc.name      : create 16 instances create-destory
1220  * @tc.desc      : function test
1221  */
1222 HWTEST_F(DemuxerReliNdkTest, DEMUXER_RELI_6300, TestSize.Level3)
1223 {
1224     int num = 0;
1225     while (num < 5) {
1226         num++;
1227         vector<std::thread> vecThread;
1228         // "https://media.w3.org/2010/05/sintel/trailer.mp4"
1229         const char *URI = "http://192.168.3.11:8080/share/avcc_10sec.mp4";
1230         for (int i = 0; i < g_maxThread; i++) {
1231             memory_list[i] = OH_AVMemory_Create(g_width * g_height);
1232             cout << i << "  URI:  " << URI << endl;
1233             source_list[i] = OH_AVSource_CreateWithURI(const_cast<char *>(URI));
1234             ASSERT_NE(source_list[i], nullptr);
1235             demuxer_list[i] = OH_AVDemuxer_CreateWithSource(source_list[i]);
1236             ASSERT_NE(demuxer_list[i], nullptr);
1237             vecThread.emplace_back(DemuxFunc, i, num);
1238         }
1239         for (auto &val : vecThread) {
1240             val.join();
1241         }
1242 
1243         for (int i = 0; i < g_maxThread; i++) {
1244             if (demuxer_list[i] != nullptr) {
1245                 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_Destroy(demuxer_list[i]));
1246                 demuxer_list[i] = nullptr;
1247             }
1248 
1249             if (source_list[i] != nullptr) {
1250                 ASSERT_EQ(AV_ERR_OK, OH_AVSource_Destroy(source_list[i]));
1251                 source_list[i] = nullptr;
1252             }
1253             if (memory_list[i] != nullptr) {
1254                 ASSERT_EQ(AV_ERR_OK, OH_AVMemory_Destroy(memory_list[i]));
1255                 memory_list[i] = nullptr;
1256             }
1257             std::cout << i << "            finish Destroy!!!!" << std::endl;
1258         }
1259         cout << "num: " << num << endl;
1260     }
1261 }
1262 }