• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "gtest/gtest.h"
17 
18 #include "native_avcodec_base.h"
19 #include "native_avdemuxer.h"
20 #include "native_avformat.h"
21 #include "native_avsource.h"
22 
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 DemuxerReli2NdkTest : 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 int g_fd = -1;
45 static OH_AVMemory *memory = nullptr;
46 static OH_AVSource *source = nullptr;
47 static OH_AVDemuxer *demuxer = nullptr;
48 static OH_AVFormat *sourceFormat = nullptr;
49 static OH_AVFormat *trackFormat = nullptr;
50 static int32_t g_trackCount;
51 static int32_t g_width = 3840;
52 static int32_t g_height = 2160;
53 static int32_t g_maxThread = 16;
54 OH_AVSource *source_list[16] = {};
55 OH_AVMemory *memory_list[16] = {};
56 OH_AVDemuxer *demuxer_list[16] = {};
57 int g_fdList[16] = {};
58 int32_t g_track = 2;
59 
SetUpTestCase()60 void DemuxerReli2NdkTest::SetUpTestCase() {}
TearDownTestCase()61 void DemuxerReli2NdkTest::TearDownTestCase() {}
SetUp()62 void DemuxerReli2NdkTest::SetUp()
63 {
64     memory = OH_AVMemory_Create(g_width * g_height);
65     g_trackCount = 0;
66 }
TearDown()67 void DemuxerReli2NdkTest::TearDown()
68 {
69     if (g_fd > 0) {
70         close(g_fd);
71         g_fd = -1;
72     }
73 
74     if (trackFormat != nullptr) {
75         OH_AVFormat_Destroy(trackFormat);
76         trackFormat = nullptr;
77     }
78 
79     if (sourceFormat != nullptr) {
80         OH_AVFormat_Destroy(sourceFormat);
81         sourceFormat = nullptr;
82     }
83 
84     if (memory != nullptr) {
85         OH_AVMemory_Destroy(memory);
86         memory = nullptr;
87     }
88 
89     if (source != nullptr) {
90         OH_AVSource_Destroy(source);
91         source = nullptr;
92     }
93 
94     if (demuxer != nullptr) {
95         OH_AVDemuxer_Destroy(demuxer);
96         demuxer = nullptr;
97     }
98 }
99 } // namespace Media
100 } // namespace OHOS
101 
102 using namespace std;
103 using namespace OHOS;
104 using namespace OHOS::Media;
105 using namespace testing::ext;
106 namespace {
GetFileSize(const char * fileName)107 static int64_t GetFileSize(const char *fileName)
108 {
109     int64_t fileSize = 0;
110     if (fileName != nullptr) {
111         struct stat fileStatus {};
112         if (stat(fileName, &fileStatus) == 0) {
113             fileSize = static_cast<int64_t>(fileStatus.st_size);
114         }
115     }
116     return fileSize;
117 }
118 
DemuxFunc(int i,int loop)119 void DemuxFunc(int i, int loop)
120 {
121     bool audioIsEnd = false;
122     bool videoIsEnd = false;
123     OH_AVCodecBufferAttr attr;
124     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer_list[i], 0));
125     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer_list[i], 1));
126     while (!audioIsEnd || !videoIsEnd) {
127         for (int32_t index = 0; index < g_track; index++) {
128             if ((audioIsEnd && (index == MEDIA_TYPE_AUD)) || (videoIsEnd && (index == MEDIA_TYPE_VID))) {
129                 continue;
130             }
131             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer_list[i], index, memory_list[i], &attr));
132 
133             if ((index == MEDIA_TYPE_AUD) && (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS)) {
134                 audioIsEnd = true;
135             }
136             if ((index == MEDIA_TYPE_VID) && (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS)) {
137                 videoIsEnd = true;
138             }
139         }
140     }
141 }
142 
SetAudioValue(OH_AVCodecBufferAttr attr,bool & audioIsEnd,int & audioFrame)143 static void SetAudioValue(OH_AVCodecBufferAttr attr, bool &audioIsEnd, int &audioFrame)
144 {
145     if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
146         audioIsEnd = true;
147         cout << audioFrame << "    audio is end !!!!!!!!!!!!!!!" << endl;
148     } else {
149         audioFrame++;
150     }
151 }
152 
SetVideoValue(OH_AVCodecBufferAttr attr,bool & videoIsEnd,int & videoFrame)153 static void SetVideoValue(OH_AVCodecBufferAttr attr, bool &videoIsEnd, int &videoFrame)
154 {
155     if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
156         videoIsEnd = true;
157         cout << videoFrame << "   video is end !!!!!!!!!!!!!!!" << endl;
158     } else {
159         videoFrame++;
160         cout << "video track !!!!!" << endl;
161     }
162 }
163 
164 /**
165  * @tc.number    : DEMUXER_RELI_9200
166  * @tc.name      : create 16 instances create-destory
167  * @tc.desc      : function test
168  */
169 HWTEST_F(DemuxerReli2NdkTest, DEMUXER_RELI_9200, TestSize.Level3)
170 {
171     int num = 0;
172     int len = 256;
173     while (num < 10) {
174         num++;
175         vector<std::thread> vecThread;
176         for (int i = 0; i < g_maxThread; i++) {
177             memory_list[i] = OH_AVMemory_Create(g_width * g_height);
178             char file[256] = {};
179             sprintf_s(file, len, "/data/test/media/16/%d_creat_destroy.mov", i);
180             g_fdList[i] = open(file, O_RDONLY);
181             int64_t size = GetFileSize(file);
182             cout << file << "----------------------" << g_fdList[i] << "---------" << size << endl;
183 
184             source_list[i] = OH_AVSource_CreateWithFD(g_fdList[i], 0, size);
185             ASSERT_NE(source_list[i], nullptr);
186 
187             demuxer_list[i] = OH_AVDemuxer_CreateWithSource(source_list[i]);
188             ASSERT_NE(demuxer_list[i], nullptr);
189             vecThread.emplace_back(DemuxFunc, i, num);
190         }
191         for (auto &val : vecThread) {
192             val.join();
193         }
194 
195         for (int i = 0; i < g_maxThread; i++) {
196             if (demuxer_list[i] != nullptr) {
197                 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_Destroy(demuxer_list[i]));
198                 demuxer_list[i] = nullptr;
199             }
200 
201             if (source_list[i] != nullptr) {
202                 ASSERT_EQ(AV_ERR_OK, OH_AVSource_Destroy(source_list[i]));
203                 source_list[i] = nullptr;
204             }
205             if (memory_list[i] != nullptr) {
206                 ASSERT_EQ(AV_ERR_OK, OH_AVMemory_Destroy(memory_list[i]));
207                 memory_list[i] = nullptr;
208             }
209             std::cout << i << "            finish Destroy!!!!" << std::endl;
210 
211             close(g_fdList[i]);
212         }
213         cout << "num: " << num << endl;
214     }
215 }
216 
217 /**
218  * @tc.number    : DEMUXER_RELI_9300
219  * @tc.name      : create 16 instances create-destory
220  * @tc.desc      : function test
221  */
222 HWTEST_F(DemuxerReli2NdkTest, DEMUXER_RELI_9300, TestSize.Level3)
223 {
224     int num = 0;
225     while (num < 10) {
226         num++;
227         vector<std::thread> vecThread;
228         const char *uri = "http://192.168.3.17:8080/share/MOV_H264_baseline@level5_1920_1080_30_AAC_48K_1.mov";
229         for (int i = 0; i < g_maxThread; i++) {
230             memory_list[i] = OH_AVMemory_Create(g_width * g_height);
231             cout << i << "  uri:  " << uri << endl;
232             source_list[i] = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
233             ASSERT_NE(source_list[i], nullptr);
234             demuxer_list[i] = OH_AVDemuxer_CreateWithSource(source_list[i]);
235             ASSERT_NE(demuxer_list[i], nullptr);
236             vecThread.emplace_back(DemuxFunc, i, num);
237         }
238         for (auto &val : vecThread) {
239             val.join();
240         }
241         for (int i = 0; i < g_maxThread; i++) {
242             if (demuxer_list[i] != nullptr) {
243                 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_Destroy(demuxer_list[i]));
244                 demuxer_list[i] = nullptr;
245             }
246 
247             if (source_list[i] != nullptr) {
248                 ASSERT_EQ(AV_ERR_OK, OH_AVSource_Destroy(source_list[i]));
249                 source_list[i] = nullptr;
250             }
251             if (memory_list[i] != nullptr) {
252                 ASSERT_EQ(AV_ERR_OK, OH_AVMemory_Destroy(memory_list[i]));
253                 memory_list[i] = nullptr;
254             }
255             std::cout << i << "            finish Destroy!!!!" << std::endl;
256         }
257         cout << "num: " << num << endl;
258     }
259 }
260 
261 
262 /**
263  * @tc.number    : DEMUXER_RELI_9400
264  * @tc.name      : one instance demux long file
265  * @tc.desc      : function test
266  */
267 HWTEST_F(DemuxerReli2NdkTest, DEMUXER_RELI_9400, TestSize.Level3)
268 {
269     int num = 0;
270     OH_AVCodecBufferAttr attr;
271 
272     const char *file = "/data/test/media/long.mov";
273 
274     bool audioIsEnd = false;
275     bool videoIsEnd = false;
276     int audioFrame = 0;
277     int videoFrame = 0;
278 
279     int fd = open(file, O_RDONLY);
280     int64_t size = GetFileSize(file);
281     cout << file << "----------------------" << fd << "---------" << size << endl;
282     num++;
283     cout << num << endl;
284     source = OH_AVSource_CreateWithFD(fd, 0, size);
285     ASSERT_NE(source, nullptr);
286 
287     demuxer = OH_AVDemuxer_CreateWithSource(source);
288     ASSERT_NE(demuxer, nullptr);
289 
290     for (int32_t index = 0; index < 2; index++) {
291         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
292     }
293     while (!audioIsEnd || !videoIsEnd) {
294         for (int32_t index = 0; index < 2; index++) {
295             if ((audioIsEnd && (index == MEDIA_TYPE_AUD)) || (videoIsEnd && (index == MEDIA_TYPE_VID))) {
296                 continue;
297             }
298             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
299 
300             if (index == MEDIA_TYPE_AUD) {
301                 SetAudioValue(attr, audioIsEnd, audioFrame);
302             } else if (index == MEDIA_TYPE_VID) {
303                 SetVideoValue(attr, videoIsEnd, videoFrame);
304             }
305         }
306     }
307     close(fd);
308 }
309 
310 /**
311  * @tc.number    : DEMUXER_RELI_9500
312  * @tc.name      : create 16 instances create-destory
313  * @tc.desc      : function test
314  */
315 HWTEST_F(DemuxerReli2NdkTest, DEMUXER_RELI_9500, TestSize.Level3)
316 {
317     int num = 0;
318     int len = 256;
319     while (num < 10) {
320         num++;
321         vector<std::thread> vecThread;
322         for (int i = 0; i < g_maxThread; i++) {
323             memory_list[i] = OH_AVMemory_Create(g_width * g_height);
324             char file[256] = {};
325             sprintf_s(file, len, "/data/test/media/16/%d_creat_destroy.mpg", i);
326             g_fdList[i] = open(file, O_RDONLY);
327             int64_t size = GetFileSize(file);
328             cout << file << "----------------------" << g_fdList[i] << "---------" << size << endl;
329 
330             source_list[i] = OH_AVSource_CreateWithFD(g_fdList[i], 0, size);
331             ASSERT_NE(source_list[i], nullptr);
332 
333             demuxer_list[i] = OH_AVDemuxer_CreateWithSource(source_list[i]);
334             ASSERT_NE(demuxer_list[i], nullptr);
335             vecThread.emplace_back(DemuxFunc, i, num);
336         }
337         for (auto &val : vecThread) {
338             val.join();
339         }
340 
341         for (int i = 0; i < g_maxThread; i++) {
342             if (demuxer_list[i] != nullptr) {
343                 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_Destroy(demuxer_list[i]));
344                 demuxer_list[i] = nullptr;
345             }
346 
347             if (source_list[i] != nullptr) {
348                 ASSERT_EQ(AV_ERR_OK, OH_AVSource_Destroy(source_list[i]));
349                 source_list[i] = nullptr;
350             }
351             if (memory_list[i] != nullptr) {
352                 ASSERT_EQ(AV_ERR_OK, OH_AVMemory_Destroy(memory_list[i]));
353                 memory_list[i] = nullptr;
354             }
355             std::cout << i << "            finish Destroy!!!!" << std::endl;
356 
357             close(g_fdList[i]);
358         }
359         cout << "num: " << num << endl;
360     }
361 }
362 
363 /**
364  * @tc.number    : DEMUXER_RELI_9600
365  * @tc.name      : create 16 instances create-destory
366  * @tc.desc      : function test
367  */
368 HWTEST_F(DemuxerReli2NdkTest, DEMUXER_RELI_9600, TestSize.Level3)
369 {
370     int num = 0;
371     while (num < 10) {
372         num++;
373         vector<std::thread> vecThread;
374         const char *uri = "http://192.168.3.17:8080/share/MPG_H264_baseline@level5_1920_1080_30_MP2_44.1K_1.mpg";
375         for (int i = 0; i < g_maxThread; i++) {
376             memory_list[i] = OH_AVMemory_Create(g_width * g_height);
377             cout << i << "  uri:  " << uri << endl;
378             source_list[i] = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
379             ASSERT_NE(source_list[i], nullptr);
380             demuxer_list[i] = OH_AVDemuxer_CreateWithSource(source_list[i]);
381             ASSERT_NE(demuxer_list[i], nullptr);
382             vecThread.emplace_back(DemuxFunc, i, num);
383         }
384         for (auto &val : vecThread) {
385             val.join();
386         }
387         for (int i = 0; i < g_maxThread; i++) {
388             if (demuxer_list[i] != nullptr) {
389                 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_Destroy(demuxer_list[i]));
390                 demuxer_list[i] = nullptr;
391             }
392 
393             if (source_list[i] != nullptr) {
394                 ASSERT_EQ(AV_ERR_OK, OH_AVSource_Destroy(source_list[i]));
395                 source_list[i] = nullptr;
396             }
397             if (memory_list[i] != nullptr) {
398                 ASSERT_EQ(AV_ERR_OK, OH_AVMemory_Destroy(memory_list[i]));
399                 memory_list[i] = nullptr;
400             }
401             std::cout << i << "            finish Destroy!!!!" << std::endl;
402         }
403         cout << "num: " << num << endl;
404     }
405 }
406 
407 
408 /**
409  * @tc.number    : DEMUXER_RELI_9700
410  * @tc.name      : one instance demux long file
411  * @tc.desc      : function test
412  */
413 HWTEST_F(DemuxerReli2NdkTest, DEMUXER_RELI_9700, TestSize.Level3)
414 {
415     int num = 0;
416     OH_AVCodecBufferAttr attr;
417 
418     const char *file = "/data/test/media/long.mpg";
419 
420     bool audioIsEnd = false;
421     bool videoIsEnd = false;
422     int audioFrame = 0;
423     int videoFrame = 0;
424 
425     int fd = open(file, O_RDONLY);
426     int64_t size = GetFileSize(file);
427     cout << file << "----------------------" << fd << "---------" << size << endl;
428     num++;
429     cout << num << endl;
430     source = OH_AVSource_CreateWithFD(fd, 0, size);
431     ASSERT_NE(source, nullptr);
432 
433     demuxer = OH_AVDemuxer_CreateWithSource(source);
434     ASSERT_NE(demuxer, nullptr);
435 
436     for (int32_t index = 0; index < 2; index++) {
437         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
438     }
439     while (!audioIsEnd || !videoIsEnd) {
440         for (int32_t index = 0; index < 2; index++) {
441             if ((audioIsEnd && (index == MEDIA_TYPE_AUD)) || (videoIsEnd && (index == MEDIA_TYPE_VID))) {
442                 continue;
443             }
444             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
445 
446             if (index == MEDIA_TYPE_AUD) {
447                 SetAudioValue(attr, audioIsEnd, audioFrame);
448             } else if (index == MEDIA_TYPE_VID) {
449                 SetVideoValue(attr, videoIsEnd, videoFrame);
450             }
451         }
452     }
453     close(fd);
454 }
455 
456 /**
457  * @tc.number    : DEMUXER_AVI_RELI_0100
458  * @tc.name      : one fd instance repeat create destory
459  * @tc.desc      : function test
460  */
461 HWTEST_F(DemuxerReli2NdkTest, DEMUXER_AVI_RELI_0100, TestSize.Level2)
462 {
463     int num = 0;
464     OH_AVCodecBufferAttr attr;
465 
466     const char *file = "/data/test/media/AVI_MPEG4_advanced_simple@level3_352_288_MP3_2.avi";
467     bool audioIsEnd = false;
468     bool videoIsEnd = false;
469 
470     g_fd = open(file, O_RDONLY);
471     int64_t size = GetFileSize(file);
472     cout << file << "----------------------" << g_fd << "---------" << size << endl;
473     num++;
474     cout << num << endl;
475     source = OH_AVSource_CreateWithFD(g_fd, 0, size);
476     ASSERT_NE(source, nullptr);
477 
478     demuxer = OH_AVDemuxer_CreateWithSource(source);
479     ASSERT_NE(demuxer, nullptr);
480 
481     for (int32_t index = 0; index < 2; index++) {
482         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
483     }
484     while (!audioIsEnd || !videoIsEnd) {
485         for (int32_t index = 0; index < 2; index++) {
486 
487             if ((audioIsEnd && (index == MEDIA_TYPE_AUD)) || (videoIsEnd && (index == MEDIA_TYPE_VID))) {
488                 continue;
489             }
490             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
491 
492             if ((index == MEDIA_TYPE_AUD) && (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS)) {
493                 audioIsEnd = true;
494                 cout << "    audio is end !!!!!!!!!!!!!!!" << endl;
495             }
496             if ((index == MEDIA_TYPE_VID) && (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS)) {
497                 videoIsEnd = true;
498                 cout << "   video is end !!!!!!!!!!!!!!!" << endl;
499             }
500         }
501     }
502     if (source != nullptr) {
503         OH_AVSource_Destroy(source);
504         source = nullptr;
505     }
506     if (demuxer != nullptr) {
507         OH_AVDemuxer_Destroy(demuxer);
508         demuxer = nullptr;
509     }
510     close(g_fd);
511 }
512 
513 /**
514  * @tc.number    : DEMUXER_AVI_RELI_0200
515  * @tc.name      : one uri instance repeat create destory
516  * @tc.desc      : function test
517  */
518 HWTEST_F(DemuxerReli2NdkTest, DEMUXER_AVI_RELI_0200, TestSize.Level2)
519 {
520     int num = 0;
521     OH_AVCodecBufferAttr attr;
522 
523     const char *file = "http://192.168.3.17:8080/share/AVI_MPEG2_422P@high_1920_1080_PCM_s24_1.avi";
524     bool audioIsEnd = false;
525     bool videoIsEnd = false;
526 
527     g_fd = open(file, O_RDONLY);
528     int64_t size = GetFileSize(file);
529     cout << file << "----------------------" << g_fd << "---------" << size << endl;
530     num++;
531     cout << num << endl;
532     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
533     ASSERT_NE(source, nullptr);
534 
535     demuxer = OH_AVDemuxer_CreateWithSource(source);
536     ASSERT_NE(demuxer, nullptr);
537 
538     for (int32_t index = 0; index < 2; index++) {
539         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
540     }
541     while (!audioIsEnd || !videoIsEnd) {
542         for (int32_t index = 0; index < 2; index++) {
543 
544             if ((audioIsEnd && (index == MEDIA_TYPE_AUD)) || (videoIsEnd && (index == MEDIA_TYPE_VID))) {
545                 continue;
546             }
547             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
548 
549             if ((index == MEDIA_TYPE_AUD) && (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS)) {
550                 audioIsEnd = true;
551                 cout << "    audio is end !!!!!!!!!!!!!!!" << endl;
552             }
553             if ((index == MEDIA_TYPE_VID) && (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS)) {
554                 videoIsEnd = true;
555                 cout << "   video is end !!!!!!!!!!!!!!!" << endl;
556             }
557         }
558     }
559     if (source != nullptr) {
560         OH_AVSource_Destroy(source);
561         source = nullptr;
562     }
563     if (demuxer != nullptr) {
564         OH_AVDemuxer_Destroy(demuxer);
565         demuxer = nullptr;
566     }
567     close(g_fd);
568 }
569 
570 /**
571  * @tc.number    : DEMUXER_AVI_RELI_0300
572  * @tc.name      : create 16 instances create-destory
573  * @tc.desc      : function test
574  */
575 HWTEST_F(DemuxerReli2NdkTest, DEMUXER_AVI_RELI_0300, TestSize.Level3)
576 {
577     int len = 256;
578     int num = 0;
579     vector<std::thread> vecThread;
580     for (int i = 0; i < g_maxThread; i++) {
581         memory_list[i] = OH_AVMemory_Create(g_width * g_height);
582         char file[256] = {};
583         sprintf_s(file, len, "/data/test/media/16/%d_video_audio.avi", i);
584         g_fdList[i] = open(file, O_RDONLY);
585         int64_t size = GetFileSize(file);
586         cout << file << "----------------------" << g_fdList[i] << "---------" << size << endl;
587 
588         source_list[i] = OH_AVSource_CreateWithFD(g_fdList[i], 0, size);
589         ASSERT_NE(source_list[i], nullptr);
590 
591         demuxer_list[i] = OH_AVDemuxer_CreateWithSource(source_list[i]);
592         ASSERT_NE(demuxer_list[i], nullptr);
593         vecThread.emplace_back(DemuxFunc, i, num);
594     }
595     for (auto &val : vecThread) {
596         val.join();
597     }
598     for (int i = 0; i < g_maxThread; i++) {
599         if (demuxer_list[i] != nullptr) {
600             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_Destroy(demuxer_list[i]));
601             demuxer_list[i] = nullptr;
602         }
603 
604         if (source_list[i] != nullptr) {
605             ASSERT_EQ(AV_ERR_OK, OH_AVSource_Destroy(source_list[i]));
606             source_list[i] = nullptr;
607         }
608         if (memory_list[i] != nullptr) {
609             ASSERT_EQ(AV_ERR_OK, OH_AVMemory_Destroy(memory_list[i]));
610             memory_list[i] = nullptr;
611         }
612         std::cout << i << "            finish Destroy!!!!" << std::endl;
613 
614         close(g_fdList[i]);
615     }
616 }
617 
618 /**
619  * @tc.number    : DEMUXER_AVI_RELI_0400
620  * @tc.name      : create 16 instances repeat create-destory with avi fd
621  * @tc.desc      : function test
622  */
623 HWTEST_F(DemuxerReli2NdkTest, DEMUXER_AVI_RELI_0400, TestSize.Level3)
624 {
625     int num = 0;
626     int len = 256;
627     while (num < 10) {
628         num++;
629         vector<std::thread> vecThread;
630         for (int i = 0; i < g_maxThread; i++) {
631             memory_list[i] = OH_AVMemory_Create(g_width * g_height);
632             char file[256] = {};
633             sprintf_s(file, len, "/data/test/media/16/%d_video_audio.avi", i);
634             g_fdList[i] = open(file, O_RDONLY);
635             int64_t size = GetFileSize(file);
636             cout << file << "----------------------" << g_fdList[i] << "---------" << size << endl;
637 
638             source_list[i] = OH_AVSource_CreateWithFD(g_fdList[i], 0, size);
639             ASSERT_NE(source_list[i], nullptr);
640 
641             demuxer_list[i] = OH_AVDemuxer_CreateWithSource(source_list[i]);
642             ASSERT_NE(demuxer_list[i], nullptr);
643             vecThread.emplace_back(DemuxFunc, i, num);
644         }
645         for (auto &val : vecThread) {
646             val.join();
647         }
648 
649         for (int i = 0; i < g_maxThread; i++) {
650             if (demuxer_list[i] != nullptr) {
651                 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_Destroy(demuxer_list[i]));
652                 demuxer_list[i] = nullptr;
653             }
654 
655             if (source_list[i] != nullptr) {
656                 ASSERT_EQ(AV_ERR_OK, OH_AVSource_Destroy(source_list[i]));
657                 source_list[i] = nullptr;
658             }
659             if (memory_list[i] != nullptr) {
660                 ASSERT_EQ(AV_ERR_OK, OH_AVMemory_Destroy(memory_list[i]));
661                 memory_list[i] = nullptr;
662             }
663             std::cout << i << "            finish Destroy!!!!" << std::endl;
664 
665             close(g_fdList[i]);
666         }
667         cout << "num: " << num << endl;
668     }
669 }
670 
671 /**
672  * @tc.number    : DEMUXER_AVI_RELI_0500
673  * @tc.name      : create 16 instances create-destory with avi uri
674  * @tc.desc      : function test
675  */
676 HWTEST_F(DemuxerReli2NdkTest, DEMUXER_AVI_RELI_0500, TestSize.Level3)
677 {
678     int num = 0;
679     vector<std::thread> vecThread;
680     for (int i = 0; i < g_maxThread; i++) {
681             char uri[256];
682             sprintf_s(uri, "http://192.168.3.17:8080/share/16/%d_video_audio.avi", i);
683             memory_list[i] = OH_AVMemory_Create(g_width * g_height);
684             cout << i << "  uri:  " << uri << endl;
685             source_list[i] = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
686             ASSERT_NE(source_list[i], nullptr);
687 
688         demuxer_list[i] = OH_AVDemuxer_CreateWithSource(source_list[i]);
689         ASSERT_NE(demuxer_list[i], nullptr);
690         vecThread.emplace_back(DemuxFunc, i, num);
691     }
692     for (auto &val : vecThread) {
693         val.join();
694     }
695     for (int i = 0; i < g_maxThread; i++) {
696         if (demuxer_list[i] != nullptr) {
697             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_Destroy(demuxer_list[i]));
698             demuxer_list[i] = nullptr;
699         }
700 
701         if (source_list[i] != nullptr) {
702             ASSERT_EQ(AV_ERR_OK, OH_AVSource_Destroy(source_list[i]));
703             source_list[i] = nullptr;
704         }
705         if (memory_list[i] != nullptr) {
706             ASSERT_EQ(AV_ERR_OK, OH_AVMemory_Destroy(memory_list[i]));
707             memory_list[i] = nullptr;
708         }
709         std::cout << i << "            finish Destroy!!!!" << std::endl;
710 
711         close(g_fdList[i]);
712     }
713 }
714 
715 /**
716  * @tc.number    : DEMUXER_AVI_RELI_0600
717  * @tc.name      : create 16 instances repeat create-destory with avi uri
718  * @tc.desc      : function test
719  */
720 HWTEST_F(DemuxerReli2NdkTest, DEMUXER_AVI_RELI_0600, TestSize.Level3)
721 {
722     int num = 0;
723     while (num < 10) {
724         num++;
725         vector<std::thread> vecThread;
726         for (int i = 0; i < g_maxThread; i++) {
727             char uri[256];
728             sprintf_s(uri, "http://192.168.3.17:8080/share/16/%d_video_audio.avi", i);
729             memory_list[i] = OH_AVMemory_Create(g_width * g_height);
730             cout << i << "  uri:  " << uri << endl;
731             source_list[i] = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
732             ASSERT_NE(source_list[i], nullptr);
733 
734             demuxer_list[i] = OH_AVDemuxer_CreateWithSource(source_list[i]);
735             ASSERT_NE(demuxer_list[i], nullptr);
736             vecThread.emplace_back(DemuxFunc, i, num);
737         }
738         for (auto &val : vecThread) {
739             val.join();
740         }
741         for (int i = 0; i < g_maxThread; i++) {
742             if (demuxer_list[i] != nullptr) {
743                 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_Destroy(demuxer_list[i]));
744                 demuxer_list[i] = nullptr;
745             }
746             if (source_list[i] != nullptr) {
747                 ASSERT_EQ(AV_ERR_OK, OH_AVSource_Destroy(source_list[i]));
748                 source_list[i] = nullptr;
749             }
750             if (memory_list[i] != nullptr) {
751                 ASSERT_EQ(AV_ERR_OK, OH_AVMemory_Destroy(memory_list[i]));
752                 memory_list[i] = nullptr;
753             }
754             std::cout << i << "            finish Destroy!!!!" << std::endl;
755         }
756         cout << "num: " << num << endl;
757     }
758 }
759 
760 /**
761  * @tc.number    : DEMUXER_AVI_RELI_0700
762  * @tc.name      : one instance demux long file
763  * @tc.desc      : function test
764  */
765 HWTEST_F(DemuxerReli2NdkTest, DEMUXER_AVI_RELI_0700, TestSize.Level3)
766 {
767     int num = 0;
768     OH_AVCodecBufferAttr attr;
769     const char *file = "/data/test/media/long.avi";
770     bool audioIsEnd = false;
771     bool videoIsEnd = false;
772     int audioFrame = 0;
773     int videoFrame = 0;
774     g_fd = open(file, O_RDONLY);
775     int64_t size = GetFileSize(file);
776     cout << file << "----------------------" << g_fd << "---------" << size << endl;
777     num++;
778     cout << num << endl;
779     source = OH_AVSource_CreateWithFD(g_fd, 0, size);
780     ASSERT_NE(source, nullptr);
781 
782     demuxer = OH_AVDemuxer_CreateWithSource(source);
783     ASSERT_NE(demuxer, nullptr);
784 
785     for (int32_t index = 0; index < 2; index++) {
786         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
787     }
788     while (!audioIsEnd || !videoIsEnd) {
789         for (int32_t index = 0; index < 2; index++) {
790             if ((audioIsEnd && (index == MEDIA_TYPE_AUD)) || (videoIsEnd && (index == MEDIA_TYPE_VID))) {
791                 continue;
792             }
793             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
794 
795             if (index == MEDIA_TYPE_AUD) {
796                 SetAudioValue(attr, audioIsEnd, audioFrame);
797             } else if (index == MEDIA_TYPE_VID) {
798                 SetVideoValue(attr, videoIsEnd, videoFrame);
799             }
800         }
801     }
802     close(g_fd);
803 }
804 }