• 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 #include "native_avbuffer.h"
23 
24 #include <iostream>
25 #include <cstdio>
26 #include <string>
27 #include <fcntl.h>
28 
29 namespace OHOS {
30 namespace Media {
31 class DemuxerApiNdkTest : public testing::Test {
32 public:
33     // SetUpTestCase: Called before all test cases
34     static void SetUpTestCase(void);
35     // TearDownTestCase: Called after all test case
36     static void TearDownTestCase(void);
37     // SetUp: Called before each test cases
38     void SetUp(void);
39     // TearDown: Called after each test cases
40     void TearDown(void);
41 
42 public:
43     int fd1;
44     int64_t size;
45 };
46 static int32_t g_width = 3840;
47 static int32_t g_height = 2160;
48 static OH_AVMemory *memory = nullptr;
49 static OH_AVBuffer *buffer = nullptr;
50 static OH_AVSource *source = nullptr;
51 static OH_AVDemuxer *demuxer = nullptr;
52 const char *g_file1 = "/data/test/media/01_video_audio.mp4";
53 const char *g_file2 = "/data/test/media/avcc_10sec.mp4";
54 
SetUpTestCase()55 void DemuxerApiNdkTest::SetUpTestCase() {}
TearDownTestCase()56 void DemuxerApiNdkTest::TearDownTestCase() {}
57 
SetUp()58 void DemuxerApiNdkTest::SetUp()
59 {
60     memory = OH_AVMemory_Create(g_width * g_height);
61     buffer = OH_AVBuffer_Create(g_width * g_height);
62     fd1 = open(g_file1, O_RDONLY);
63 
64     struct stat fileStatus {};
65     if (stat(g_file1, &fileStatus) == 0) {
66         size = static_cast<int64_t>(fileStatus.st_size);
67     }
68 
69     std::cout << fd1 << "----------" << g_file1 << "=====" << size << std::endl;
70 }
71 
TearDown()72 void DemuxerApiNdkTest::TearDown()
73 {
74     close(fd1);
75     fd1 = 0;
76     if (memory != nullptr) {
77         OH_AVMemory_Destroy(memory);
78         memory = nullptr;
79     }
80     if (buffer != nullptr) {
81         OH_AVBuffer_Destroy(buffer);
82         buffer = 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 } // namespace Media
94 } // namespace OHOS
95 
96 namespace {
97 using namespace std;
98 using namespace OHOS;
99 using namespace OHOS::Media;
100 using namespace testing::ext;
101 
102 /**
103  * @tc.number    : OH_AVSource_CreateWithDataSource_0100
104  * @tc.name      : OH_AVSource_CreateWithDataSource para error
105  * @tc.desc      : api test
106  */
107 HWTEST_F(DemuxerApiNdkTest, OH_AVSource_CreateWithDataSource_0100, TestSize.Level2)
108 {
109     source = OH_AVSource_CreateWithDataSource(nullptr);
110     ASSERT_EQ(nullptr, source);
111 }
112 
113 /**
114  * @tc.number    : OH_AVSource_CreateWithDataSourceExt_0100
115  * @tc.name      : OH_AVSource_CreateWithDataSourceExt_0100
116  * @tc.desc      : api test
117  */
118 HWTEST_F(DemuxerApiNdkTest, OH_AVSource_CreateWithDataSourceExt_0100, TestSize.Level2)
119 {
120     OH_AVSource* source = OH_AVSource_CreateWithDataSourceExt(nullptr, nullptr);
121     ASSERT_EQ(nullptr, source);
122 
123     OH_AVDataSourceExt dataSourceExt = {1000, nullptr};
124     source = OH_AVSource_CreateWithDataSourceExt(&dataSourceExt, nullptr);
125     ASSERT_EQ(nullptr, source);
126 
127     int dummy = 123;
128     source = OH_AVSource_CreateWithDataSourceExt(nullptr, &dummy);
129     ASSERT_EQ(nullptr, source);
130 }
131 
132 /**
133  * @tc.number    : DEMUXER_ILLEGAL_PARA_0100
134  * @tc.name      : OH_AVSource_CreateWithURI para error
135  * @tc.desc      : api test
136  */
137 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_0100, TestSize.Level2)
138 {
139     source = OH_AVSource_CreateWithURI(nullptr);
140     ASSERT_EQ(nullptr, source);
141 }
142 
143 /**
144  * @tc.number    : DEMUXER_ILLEGAL_PARA_0200
145  * @tc.name      : OH_AVSource_CreateWithFD para error
146  * @tc.desc      : api test
147  */
148 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_0200, TestSize.Level2)
149 {
150     // fd must bigger than 2
151     source = OH_AVSource_CreateWithFD(2, 0, 0);
152     ASSERT_EQ(nullptr, source);
153 }
154 
155 /**
156  * @tc.number    : DEMUXER_ILLEGAL_PARA_0700
157  * @tc.name      : OH_AVSource_CreateWithFD para error
158  * @tc.desc      : api test
159  */
160 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_0700, TestSize.Level2)
161 {
162     // fd must bigger than 2
163     source = OH_AVSource_CreateWithFD(3, 0, -1);
164     ASSERT_EQ(nullptr, source);
165 }
166 
167 /**
168  * @tc.number    : DEMUXER_ILLEGAL_PARA_0800
169  * @tc.name      : OH_AVSource_CreateWithFD para error
170  * @tc.desc      : api test
171  */
172 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_0800, TestSize.Level2)
173 {
174     // fd must bigger than 2
175     source = OH_AVSource_CreateWithFD(3, -1, 1);
176     ASSERT_EQ(nullptr, source);
177 }
178 
179 /**
180  * @tc.number    : DEMUXER_ILLEGAL_PARA_0300
181  * @tc.name      : OH_AVSource_Destroy para error
182  * @tc.desc      : api test
183  */
184 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_0300, TestSize.Level2)
185 {
186     ASSERT_EQ(AV_ERR_INVALID_VAL, OH_AVSource_Destroy(nullptr));
187 }
188 
189 /**
190  * @tc.number    : DEMUXER_ILLEGAL_PARA_0400
191  * @tc.name      : OH_AVSource_GetSourceFormat para error
192  * @tc.desc      : api test
193  */
194 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_0400, TestSize.Level2)
195 {
196     OH_AVFormat *format = OH_AVSource_GetSourceFormat(nullptr);
197     ASSERT_EQ(nullptr, format);
198 }
199 
200 /**
201  * @tc.number    : DEMUXER_ILLEGAL_PARA_0500
202  * @tc.name      : OH_AVSource_GetTrackFormat para error
203  * @tc.desc      : api test
204  */
205 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_0500, TestSize.Level2)
206 {
207     OH_AVFormat *format = OH_AVSource_GetTrackFormat(nullptr, 0);
208     ASSERT_EQ(nullptr, format);
209 }
210 
211 /**
212  * @tc.number    : DEMUXER_ILLEGAL_PARA_0600
213  * @tc.name      : OH_AVSource_GetSourceFormat para error
214  * @tc.desc      : api test
215  */
216 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_0600, TestSize.Level2)
217 {
218     source = OH_AVSource_CreateWithFD(fd1, 0, size);
219     ASSERT_NE(nullptr, source);
220     OH_AVFormat *format = OH_AVSource_GetTrackFormat(source, -1);
221     ASSERT_EQ(nullptr, format);
222 }
223 
224 /**
225  * @tc.number    : DEMUXER_ILLEGAL_PARA_2300
226  * @tc.name      : OH_AVSource_CreateWithFD para error
227  * @tc.desc      : api test
228  */
229 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_2300, TestSize.Level2)
230 {
231     source = OH_AVSource_CreateWithFD(fd1, 0, 0);
232     ASSERT_EQ(nullptr, source);
233 }
234 
235 /**
236  * @tc.number    : DEMUXER_ILLEGAL_PARA_0900
237  * @tc.name      : OH_AVDemuxer_CreateWithSource para error
238  * @tc.desc      : api test
239  */
240 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_0900, TestSize.Level2)
241 {
242     demuxer = OH_AVDemuxer_CreateWithSource(nullptr);
243     ASSERT_EQ(nullptr, demuxer);
244 }
245 
246 /**
247  * @tc.number    : DEMUXER_ILLEGAL_PARA_1000
248  * @tc.name      : OH_AVDemuxer_Destroy para error
249  * @tc.desc      : api test
250  */
251 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_1000, TestSize.Level2)
252 {
253     ASSERT_EQ(AV_ERR_INVALID_VAL, OH_AVDemuxer_Destroy(nullptr));
254 }
255 
256 /**
257  * @tc.number    : DEMUXER_ILLEGAL_PARA_1100
258  * @tc.name      : OH_AVDemuxer_SelectTrackByID para error
259  * @tc.desc      : api test
260  */
261 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_1100, TestSize.Level2)
262 {
263     ASSERT_EQ(AV_ERR_INVALID_VAL, OH_AVDemuxer_SelectTrackByID(nullptr, 0));
264 }
265 
266 /**
267  * @tc.number    : DEMUXER_ILLEGAL_PARA_1200
268  * @tc.name      : OH_AVDemuxer_SelectTrackByID para error
269  * @tc.desc      : api test
270  */
271 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_1200, TestSize.Level2)
272 {
273     source = OH_AVSource_CreateWithFD(fd1, 0, size);
274     ASSERT_NE(nullptr, source);
275     demuxer = OH_AVDemuxer_CreateWithSource(source);
276     ASSERT_EQ(AV_ERR_INVALID_VAL, OH_AVDemuxer_SelectTrackByID(demuxer, -1));
277 }
278 
279 /**
280  * @tc.number    : DEMUXER_ILLEGAL_PARA_1300
281  * @tc.name      : OH_AVDemuxer_UnselectTrackByID para error
282  * @tc.desc      : api test
283  */
284 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_1300, TestSize.Level2)
285 {
286     ASSERT_EQ(AV_ERR_INVALID_VAL, OH_AVDemuxer_UnselectTrackByID(nullptr, 0));
287 }
288 
289 /**
290  * @tc.number    : DEMUXER_ILLEGAL_PARA_1400
291  * @tc.name      : OH_AVDemuxer_UnselectTrackByID para error
292  * @tc.desc      : api test
293  */
294 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_1400, TestSize.Level2)
295 {
296     source = OH_AVSource_CreateWithFD(fd1, 0, size);
297     ASSERT_NE(nullptr, source);
298     demuxer = OH_AVDemuxer_CreateWithSource(source);
299     ASSERT_NE(nullptr, demuxer);
300     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_UnselectTrackByID(demuxer, -1)); // unselect ok
301 }
302 
303 /**
304  * @tc.number    : DEMUXER_ILLEGAL_PARA_1500
305  * @tc.name      : OH_AVDemuxer_ReadSample para error
306  * @tc.desc      : api test
307  */
308 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_1500, TestSize.Level2)
309 {
310     uint32_t trackIndex = 0;
311     OH_AVCodecBufferAttr bufferAttr;
312     ASSERT_EQ(AV_ERR_INVALID_VAL, OH_AVDemuxer_ReadSample(nullptr, trackIndex, memory, &bufferAttr));
313 }
314 
315 /**
316  * @tc.number    : DEMUXER_ILLEGAL_PARA_1600
317  * @tc.name      : OH_AVDemuxer_ReadSample para error
318  * @tc.desc      : api test
319  */
320 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_1600, TestSize.Level2)
321 {
322     uint32_t trackIndex = -1;
323     OH_AVCodecBufferAttr bufferAttr;
324     source = OH_AVSource_CreateWithFD(fd1, 0, size);
325     ASSERT_NE(nullptr, source);
326     demuxer = OH_AVDemuxer_CreateWithSource(source);
327     ASSERT_NE(nullptr, demuxer);
328     ASSERT_EQ(AV_ERR_OPERATE_NOT_PERMIT, OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &bufferAttr));
329 }
330 
331 /**
332  * @tc.number    : DEMUXER_ILLEGAL_PARA_1700
333  * @tc.name      : OH_AVDemuxer_ReadSample para error
334  * @tc.desc      : api test
335  */
336 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_1700, TestSize.Level2)
337 {
338     uint32_t trackIndex = 0;
339     OH_AVMemory *memory1 = OH_AVMemory_Create(2);
340     OH_AVCodecBufferAttr bufferAttr;
341     source = OH_AVSource_CreateWithFD(fd1, 0, size);
342     ASSERT_NE(nullptr, source);
343     demuxer = OH_AVDemuxer_CreateWithSource(source);
344     ASSERT_NE(nullptr, demuxer);
345     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
346     ASSERT_EQ(AV_ERR_NO_MEMORY, OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory1, &bufferAttr));
347 
348     OH_AVMemory_Destroy(memory1);
349     memory1 = nullptr;
350 }
351 
352 /**
353  * @tc.number    : DEMUXER_ILLEGAL_PARA_8600
354  * @tc.name      : OH_AVDemuxer_ReadSample para error
355  * @tc.desc      : api test
356  */
357 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_2400, TestSize.Level2)
358 {
359     uint32_t trackIndex = 0;
360     OH_AVMemory *memory1 = OH_AVMemory_Create(2);
361     OH_AVCodecBufferAttr bufferAttr;
362     source = OH_AVSource_CreateWithFD(fd1, 0, size);
363     ASSERT_NE(nullptr, source);
364     demuxer = OH_AVDemuxer_CreateWithSource(source);
365     ASSERT_NE(nullptr, demuxer);
366     ASSERT_EQ(AV_ERR_OPERATE_NOT_PERMIT, OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory1, &bufferAttr));
367 
368     OH_AVMemory_Destroy(memory1);
369     memory1 = nullptr;
370 }
371 
372 /**
373  * @tc.number    : DEMUXER_ILLEGAL_PARA_1700
374  * @tc.name      : OH_AVDemuxer_ReadSample para error
375  * @tc.desc      : api test
376  */
377 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_2500, TestSize.Level2)
378 {
379     uint32_t trackIndex = 0;
380     OH_AVCodecBufferAttr bufferAttr;
381     source = OH_AVSource_CreateWithFD(fd1, 0, size);
382     ASSERT_NE(nullptr, source);
383     demuxer = OH_AVDemuxer_CreateWithSource(source);
384     ASSERT_NE(nullptr, demuxer);
385     ASSERT_EQ(AV_ERR_INVALID_VAL, OH_AVDemuxer_ReadSample(demuxer, trackIndex, nullptr, &bufferAttr));
386 }
387 
388 /**
389  * @tc.number    : DEMUXER_ILLEGAL_PARA_2600
390  * @tc.name      : OH_AVDemuxer_ReadSampleBuffer para error, input null demuxer
391  * @tc.desc      : api test
392  */
393 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_2600, TestSize.Level2)
394 {
395     uint32_t trackIndex = 0;
396     ASSERT_EQ(AV_ERR_INVALID_VAL, OH_AVDemuxer_ReadSampleBuffer(nullptr, trackIndex, buffer));
397 }
398 
399 /**
400  * @tc.number    : DEMUXER_ILLEGAL_PARA_2700
401  * @tc.name      : OH_AVDemuxer_ReadSampleBuffer para error, input illegal trackIndex
402  * @tc.desc      : api test
403  */
404 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_2700, TestSize.Level2)
405 {
406     uint32_t trackIndex = -1;
407     source = OH_AVSource_CreateWithFD(fd1, 0, size);
408     ASSERT_NE(nullptr, source);
409     demuxer = OH_AVDemuxer_CreateWithSource(source);
410     ASSERT_NE(nullptr, demuxer);
411     ASSERT_EQ(AV_ERR_OPERATE_NOT_PERMIT, OH_AVDemuxer_ReadSampleBuffer(demuxer, trackIndex, buffer));
412 }
413 
414 /**
415  * @tc.number    : DEMUXER_ILLEGAL_PARA_2800
416  * @tc.name      : OH_AVDemuxer_ReadSampleBuffer para error, input buffer is not enough
417  * @tc.desc      : api test
418  */
419 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_2800, TestSize.Level2)
420 {
421     uint32_t trackIndex = 0;
422     OH_AVBuffer *buffer1 = OH_AVBuffer_Create(2);
423     source = OH_AVSource_CreateWithFD(fd1, 0, size);
424     ASSERT_NE(nullptr, source);
425     demuxer = OH_AVDemuxer_CreateWithSource(source);
426     ASSERT_NE(nullptr, demuxer);
427     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
428     ASSERT_EQ(AV_ERR_NO_MEMORY, OH_AVDemuxer_ReadSampleBuffer(demuxer, trackIndex, buffer1));
429 
430     OH_AVBuffer_Destroy(buffer1);
431     buffer1 = nullptr;
432 }
433 
434 /**
435  * @tc.number    : DEMUXER_ILLEGAL_PARA_2900
436  * @tc.name      : OH_AVDemuxer_ReadSampleBuffer para error, read before select
437  * @tc.desc      : api test
438  */
439 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_2900, TestSize.Level2)
440 {
441     uint32_t trackIndex = 0;
442     OH_AVBuffer *buffer1 = OH_AVBuffer_Create(2);
443     source = OH_AVSource_CreateWithFD(fd1, 0, size);
444     ASSERT_NE(nullptr, source);
445     demuxer = OH_AVDemuxer_CreateWithSource(source);
446     ASSERT_NE(nullptr, demuxer);
447     ASSERT_EQ(AV_ERR_OPERATE_NOT_PERMIT, OH_AVDemuxer_ReadSampleBuffer(demuxer, trackIndex, buffer1));
448 
449     OH_AVBuffer_Destroy(buffer1);
450     buffer1 = nullptr;
451 }
452 
453 /**
454  * @tc.number    : DEMUXER_ILLEGAL_PARA_3000
455  * @tc.name      : OH_AVDemuxer_ReadSampleBuffer para error, input null buffer
456  * @tc.desc      : api test
457  */
458 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_3000, TestSize.Level2)
459 {
460     uint32_t trackIndex = 0;
461     source = OH_AVSource_CreateWithFD(fd1, 0, size);
462     ASSERT_NE(nullptr, source);
463     demuxer = OH_AVDemuxer_CreateWithSource(source);
464     ASSERT_NE(nullptr, demuxer);
465     ASSERT_EQ(AV_ERR_INVALID_VAL, OH_AVDemuxer_ReadSampleBuffer(demuxer, trackIndex, nullptr));
466 }
467 
468 /**
469  * @tc.number    : DEMUXER_ILLEGAL_PARA_1800
470  * @tc.name      : OH_AVDemuxer_ReadSample para error
471  * @tc.desc      : api test
472  */
473 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_1800, TestSize.Level2)
474 {
475     uint32_t trackIndex = 0;
476     source = OH_AVSource_CreateWithFD(fd1, 0, size);
477     ASSERT_NE(nullptr, source);
478     demuxer = OH_AVDemuxer_CreateWithSource(source);
479     ASSERT_NE(nullptr, demuxer);
480     ASSERT_EQ(AV_ERR_INVALID_VAL, OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, nullptr));
481 }
482 
483 /**
484  * @tc.number    : DEMUXER_ILLEGAL_PARA_1900
485  * @tc.name      : OH_AVDemuxer_SeekToTime para error
486  * @tc.desc      : api test
487  */
488 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_1900, TestSize.Level2)
489 {
490     ASSERT_EQ(AV_ERR_INVALID_VAL, OH_AVDemuxer_SeekToTime(nullptr, 1, SEEK_MODE_NEXT_SYNC));
491 }
492 
493 /**
494  * @tc.number    : DEMUXER_ILLEGAL_PARA_2100
495  * @tc.name      : OH_AVMemory_Create para error
496  * @tc.desc      : api test
497  */
498 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_2100, TestSize.Level2)
499 {
500     memory = OH_AVMemory_Create(-1);
501     ASSERT_EQ(nullptr, memory);
502 }
503 
504 /**
505  * @tc.number    : DEMUXER_ILLEGAL_PARA_2200
506  * @tc.name      : OH_AVMemory_Destroy para error
507  * @tc.desc      : api test
508  */
509 HWTEST_F(DemuxerApiNdkTest, DEMUXER_ILLEGAL_PARA_2200, TestSize.Level2)
510 {
511     ASSERT_EQ(AV_ERR_INVALID_VAL, OH_AVMemory_Destroy(nullptr));
512 }
513 
514 /**
515  * @tc.number    : DEMUXER_API_0200
516  * @tc.name      : OH_AVSource_CreateWithFD Repeat Call
517  * @tc.desc      : api test
518  */
519 HWTEST_F(DemuxerApiNdkTest, DEMUXER_API_0200, TestSize.Level2)
520 {
521     OH_AVSource *source1 = OH_AVSource_CreateWithFD(fd1, 0, size);
522     ASSERT_NE(source1, nullptr);
523     int fd2 = open(g_file2, O_RDONLY);
524     int64_t size2 = 0;
525 
526     struct stat fileStatus {};
527     if (stat(g_file2, &fileStatus) == 0) {
528         size2 = static_cast<int64_t>(fileStatus.st_size);
529     }
530 
531     OH_AVSource *source2 = OH_AVSource_CreateWithFD(fd2, 0, size2);
532     cout << size2 << "------------------" << endl;
533     ASSERT_NE(source2, nullptr);
534     ASSERT_EQ(AV_ERR_OK, OH_AVSource_Destroy(source1));
535     ASSERT_EQ(AV_ERR_OK, OH_AVSource_Destroy(source2));
536     source1 = nullptr;
537     source2 = nullptr;
538     close(fd2);
539 }
540 
541 /**
542  * @tc.number    : DEMUXER_API_0300
543  * @tc.name      : OH_AVSource_Destroy Repeat Call
544  * @tc.desc      : api test
545  */
546 HWTEST_F(DemuxerApiNdkTest, DEMUXER_API_0300, TestSize.Level2)
547 {
548     source = OH_AVSource_CreateWithFD(fd1, 0, size);
549     ASSERT_EQ(AV_ERR_OK, OH_AVSource_Destroy(source));
550     source = nullptr;
551     ASSERT_EQ(AV_ERR_INVALID_VAL, OH_AVSource_Destroy(source));
552 }
553 
554 /**
555  * @tc.number    : DEMUXER_API_0500
556  * @tc.name      : OH_AVSource_GetSourceFormat Repeat Call
557  * @tc.desc      : api test
558  */
559 HWTEST_F(DemuxerApiNdkTest, DEMUXER_API_0500, TestSize.Level2)
560 {
561     OH_AVFormat *format;
562     source = OH_AVSource_CreateWithFD(fd1, 0, size);
563     ASSERT_NE(source, nullptr);
564     format = OH_AVSource_GetSourceFormat(source);
565     ASSERT_NE(format, nullptr);
566     format = OH_AVSource_GetSourceFormat(source);
567     ASSERT_NE(format, nullptr);
568 }
569 
570 /**
571  * @tc.number    : DEMUXER_API_0700
572  * @tc.name      : OH_AVSource_GetTrackFormat Repeat Call
573  * @tc.desc      : api test
574  */
575 HWTEST_F(DemuxerApiNdkTest, DEMUXER_API_0700, TestSize.Level2)
576 {
577     OH_AVFormat *format;
578     source = OH_AVSource_CreateWithFD(fd1, 0, size);
579     ASSERT_NE(source, nullptr);
580 
581     format = OH_AVSource_GetTrackFormat(source, 0);
582     ASSERT_NE(format, nullptr);
583     format = OH_AVSource_GetTrackFormat(source, 0);
584     ASSERT_NE(format, nullptr);
585 }
586 
587 /**
588  * @tc.number    : DEMUXER_API_1000
589  * @tc.name      : OH_AVDemuxer_Destroy Repeat Call
590  * @tc.desc      : api test
591  */
592 HWTEST_F(DemuxerApiNdkTest, DEMUXER_API_1000, TestSize.Level2)
593 {
594     source = OH_AVSource_CreateWithFD(fd1, 0, size);
595     ASSERT_NE(source, nullptr);
596 
597     demuxer = OH_AVDemuxer_CreateWithSource(source);
598     ASSERT_NE(demuxer, nullptr);
599 
600     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_Destroy(demuxer));
601     demuxer = nullptr;
602     ASSERT_EQ(AV_ERR_INVALID_VAL, OH_AVDemuxer_Destroy(demuxer));
603 }
604 
605 /**
606  * @tc.number    : DEMUXER_API_1100
607  * @tc.name      : OH_AVDemuxer_SelectTrackByID Repeat Call
608  * @tc.desc      : api test
609  */
610 HWTEST_F(DemuxerApiNdkTest, DEMUXER_API_1100, TestSize.Level2)
611 {
612     OH_AVErrCode ret = AV_ERR_OK;
613     source = OH_AVSource_CreateWithFD(fd1, 0, size);
614     ASSERT_NE(source, nullptr);
615 
616     demuxer = OH_AVDemuxer_CreateWithSource(source);
617     ASSERT_NE(demuxer, nullptr);
618     ret = OH_AVDemuxer_SelectTrackByID(demuxer, 0);
619     ASSERT_EQ(ret, AV_ERR_OK);
620     ret = OH_AVDemuxer_SelectTrackByID(demuxer, 0);
621     ASSERT_EQ(ret, AV_ERR_OK);
622 }
623 
624 /**
625  * @tc.number    : DEMUXER_API_1200
626  * @tc.name      : OH_AVDemuxer_UnselectTrackByID Repeat Call
627  * @tc.desc      : api test
628  */
629 HWTEST_F(DemuxerApiNdkTest, DEMUXER_API_1200, TestSize.Level2)
630 {
631     OH_AVErrCode ret = AV_ERR_OK;
632     source = OH_AVSource_CreateWithFD(fd1, 0, size);
633     ASSERT_NE(source, nullptr);
634 
635     demuxer = OH_AVDemuxer_CreateWithSource(source);
636     ASSERT_NE(demuxer, nullptr);
637     ret = OH_AVDemuxer_SelectTrackByID(demuxer, 0);
638     ASSERT_EQ(ret, AV_ERR_OK);
639     ret = OH_AVDemuxer_UnselectTrackByID(demuxer, 0);
640     ASSERT_EQ(ret, AV_ERR_OK);
641     ret = OH_AVDemuxer_UnselectTrackByID(demuxer, 0);
642     ASSERT_EQ(ret, AV_ERR_OK);
643 }
644 
645 /**
646  * @tc.number    : DEMUXER_API_1300
647  * @tc.name      : OH_AVDemuxer_ReadSample Repeat Call
648  * @tc.desc      : api test
649  */
650 HWTEST_F(DemuxerApiNdkTest, DEMUXER_API_1300, TestSize.Level2)
651 {
652     OH_AVErrCode ret = AV_ERR_OK;
653     OH_AVCodecBufferAttr attr;
654     source = OH_AVSource_CreateWithFD(fd1, 0, size);
655     ASSERT_NE(source, nullptr);
656     demuxer = OH_AVDemuxer_CreateWithSource(source);
657     ASSERT_NE(demuxer, nullptr);
658     ret = OH_AVDemuxer_SelectTrackByID(demuxer, 0);
659     ASSERT_EQ(ret, AV_ERR_OK);
660     ret = OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr);
661     ASSERT_EQ(ret, AV_ERR_OK);
662     ret = OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr);
663     ASSERT_EQ(ret, AV_ERR_OK);
664 }
665 
666 /**
667  * @tc.number    : DEMUXER_API_1400
668  * @tc.name      : OH_AVDemuxer_SeekToTime Repeat Call
669  * @tc.desc      : api test
670  */
671 HWTEST_F(DemuxerApiNdkTest, DEMUXER_API_1400, TestSize.Level2)
672 {
673     OH_AVErrCode ret = AV_ERR_OK;
674     uint32_t ms = 1000;
675     source = OH_AVSource_CreateWithFD(fd1, 0, size);
676     ASSERT_NE(source, nullptr);
677     demuxer = OH_AVDemuxer_CreateWithSource(source);
678     ASSERT_NE(demuxer, nullptr);
679     ret = OH_AVDemuxer_SelectTrackByID(demuxer, 0);
680     ASSERT_EQ(ret, AV_ERR_OK);
681     ret = OH_AVDemuxer_SeekToTime(demuxer, ms, SEEK_MODE_NEXT_SYNC);
682     ASSERT_EQ(ret, AV_ERR_OK);
683     ret = OH_AVDemuxer_SeekToTime(demuxer, ms, SEEK_MODE_NEXT_SYNC);
684     ASSERT_EQ(ret, AV_ERR_OK);
685 }
686 
687 /**
688  * @tc.number    : DEMUXER_API_1500
689  * @tc.name      : OH_AVMemory_Create Repeat Call
690  * @tc.desc      : api test
691  */
692 HWTEST_F(DemuxerApiNdkTest, DEMUXER_API_2300, TestSize.Level2)
693 {
694     memory = OH_AVMemory_Create(1024);
695     ASSERT_NE(nullptr, memory);
696     memory = OH_AVMemory_Create(2);
697     ASSERT_NE(nullptr, memory);
698 }
699 
700 /**
701  * @tc.number    : DEMUXER_ILLEGAL_PARA_2200
702  * @tc.name      : OH_AVMemory_Destroy para error
703  * @tc.desc      : api test
704  */
705 HWTEST_F(DemuxerApiNdkTest, DEMUXER_API_2400, TestSize.Level2)
706 {
707     memory = OH_AVMemory_Create(2);
708     ASSERT_EQ(AV_ERR_OK, OH_AVMemory_Destroy(memory));
709     memory = nullptr;
710     ASSERT_EQ(AV_ERR_INVALID_VAL, OH_AVMemory_Destroy(memory));
711 }
712 
713 /**
714  * @tc.number    : DEMUXER_API_2500
715  * @tc.name      : OH_AVDemuxer_ReadSampleBuffer Repeat Call
716  * @tc.desc      : api test
717  */
718 HWTEST_F(DemuxerApiNdkTest, DEMUXER_API_2500, TestSize.Level2)
719 {
720     OH_AVErrCode ret = AV_ERR_OK;
721     source = OH_AVSource_CreateWithFD(fd1, 0, size);
722     ASSERT_NE(source, nullptr);
723     demuxer = OH_AVDemuxer_CreateWithSource(source);
724     ASSERT_NE(demuxer, nullptr);
725     ret = OH_AVDemuxer_SelectTrackByID(demuxer, 0);
726     ASSERT_EQ(ret, AV_ERR_OK);
727     ret = OH_AVDemuxer_ReadSampleBuffer(demuxer, 0, buffer);
728     ASSERT_EQ(ret, AV_ERR_OK);
729     ret = OH_AVDemuxer_ReadSampleBuffer(demuxer, 0, buffer);
730     ASSERT_EQ(ret, AV_ERR_OK);
731 }
732 }
733