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 "avdemuxer.h"
19 #include "avsource.h"
20 #include "meta/format.h"
21 #include "avcodec_errors.h"
22 #include "avcodec_common.h"
23 #include "buffer/avsharedmemory.h"
24 #include "buffer/avsharedmemorybase.h"
25 #include "securec.h"
26 #include "inner_demuxer_sample.h"
27 
28 #include "native_avcodec_base.h"
29 #include "native_avdemuxer.h"
30 #include "native_avformat.h"
31 #include "native_avsource.h"
32 #include "native_avmemory.h"
33 #include "meta/meta_key.h"
34 #include "meta/meta.h"
35 #include "av_common.h"
36 
37 #include <iostream>
38 #include <cstdio>
39 #include <string>
40 #include <fcntl.h>
41 #include <thread>
42 
43 using namespace std;
44 using namespace OHOS;
45 using namespace OHOS::MediaAVCodec;
46 using namespace OHOS::Media;
47 using namespace testing::ext;
48 
49 namespace {
50 class DemuxerNet2NdkTest : public testing::Test {
51 public:
52     // SetUpTestCase: Called before all test cases
53     static void SetUpTestCase(void);
54     // TearDownTestCase: Called after all test case
55     static void TearDownTestCase(void);
56     // SetUp: Called before each test cases
57     void SetUp(void);
58     // TearDown: Called after each test cases
59     void TearDown(void);
60 
61 public:
62     int32_t fd_ = -1;
63     int64_t size;
64 };
65 static OH_AVMemory *memory = nullptr;
66 static OH_AVFormat *sourceFormat = nullptr;
67 static OH_AVFormat *trackFormat = nullptr;
68 static OH_AVSource *source = nullptr;
69 static OH_AVDemuxer *demuxer = nullptr;
70 static int32_t g_trackCount = 0;
71 static OH_AVBuffer *avBuffer = nullptr;
72 
73 static int32_t g_width = 3840;
74 static int32_t g_height = 2160;
SetUpTestCase()75 void DemuxerNet2NdkTest::SetUpTestCase() {}
TearDownTestCase()76 void DemuxerNet2NdkTest::TearDownTestCase() {}
SetUp()77 void DemuxerNet2NdkTest::SetUp()
78 {
79     memory = OH_AVMemory_Create(g_width * g_height);
80     g_trackCount = 0;
81 }
TearDown()82 void DemuxerNet2NdkTest::TearDown()
83 {
84     if (fd_ > 0) {
85         close(fd_);
86         fd_ = -1;
87     }
88     if (demuxer != nullptr) {
89         OH_AVDemuxer_Destroy(demuxer);
90         demuxer = nullptr;
91     }
92     if (memory != nullptr) {
93         OH_AVMemory_Destroy(memory);
94         memory = nullptr;
95     }
96     if (source != nullptr) {
97         OH_AVSource_Destroy(source);
98         source = nullptr;
99     }
100     if (avBuffer != nullptr) {
101         OH_AVBuffer_Destroy(avBuffer);
102         avBuffer = nullptr;
103     }
104     if (trackFormat != nullptr) {
105         OH_AVFormat_Destroy(trackFormat);
106         trackFormat = nullptr;
107     }
108     if (sourceFormat != nullptr) {
109         OH_AVFormat_Destroy(sourceFormat);
110         sourceFormat = nullptr;
111     }
112 }
113 } // namespace
114 
115 namespace {
CheckVideoKey()116     static void CheckVideoKey()
117     {
118         uint8_t *codecConfig = nullptr;
119         size_t bufferSize;
120         int64_t bitrate = 0;
121         const char* mimeType = nullptr;
122         double frameRate;
123         int32_t currentWidth = 0;
124         int32_t currentHeight = 0;
125         const char* language = nullptr;
126         int32_t rotation;
127         ASSERT_TRUE(OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_BITRATE, &bitrate));
128         int bitrateResult = 1660852;
129         ASSERT_EQ(bitrateResult, bitrate);
130         ASSERT_TRUE(OH_AVFormat_GetBuffer(trackFormat, OH_MD_KEY_CODEC_CONFIG, &codecConfig, &bufferSize));
131         int bufferSizeResult = 255;
132         ASSERT_EQ(bufferSizeResult, bufferSize);
133         ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
134         int expectNum = 0;
135         ASSERT_EQ(expectNum, strcmp(mimeType, OH_AVCODEC_MIMETYPE_VIDEO_VVC));
136         ASSERT_TRUE(OH_AVFormat_GetDoubleValue(trackFormat, OH_MD_KEY_FRAME_RATE, &frameRate));
137         int frameRateResult = 50.000000;
138         ASSERT_EQ(frameRateResult, frameRate);
139         ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_HEIGHT, &currentHeight));
140         int currentHeightResult = 1080;
141         ASSERT_EQ(currentHeightResult, currentHeight);
142         ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_WIDTH, &currentWidth));
143         int currentWidthResult = 1920;
144         ASSERT_EQ(currentWidthResult, currentWidth);
145         ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_LANGUAGE, &language));
146         ASSERT_EQ(0, strcmp(language, "und"));
147         ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_ROTATION, &rotation));
148         ASSERT_EQ(0, rotation);
149     }
150 
CheckAudioKey()151     static void CheckAudioKey()
152     {
153         int32_t aacisAdts = 0;
154         int64_t channelLayout;
155         int32_t audioCount = 0;
156         int32_t sampleFormat;
157         int64_t bitrate = 0;
158         int32_t bitsPreCodedSample;
159         uint8_t *codecConfig = nullptr;
160         size_t bufferSize;
161         const char* mimeType = nullptr;
162         int32_t sampleRate = 0;
163         const char* language = nullptr;
164         ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AAC_IS_ADTS, &aacisAdts));
165         int aacisAdtsResult = 1;
166         ASSERT_EQ(aacisAdtsResult, aacisAdts);
167         ASSERT_TRUE(OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_CHANNEL_LAYOUT, &channelLayout));
168         int channelLayoutResult = 3;
169         ASSERT_EQ(channelLayoutResult, channelLayout);
170         ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, &audioCount));
171         int audioCountResult = 2;
172         ASSERT_EQ(audioCountResult, audioCount);
173         ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, &sampleFormat));
174         int sampleFormatResult = 0;
175         ASSERT_EQ(sampleFormatResult, sampleFormat);
176         ASSERT_TRUE(OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_BITRATE, &bitrate));
177         int bitrateResult = 127881;
178         ASSERT_EQ(bitrateResult, bitrate);
179         ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_BITS_PER_CODED_SAMPLE, &bitsPreCodedSample));
180         int bitsPreCodedSampleResult = 16;
181         ASSERT_EQ(bitsPreCodedSampleResult, bitsPreCodedSample);
182         ASSERT_TRUE(OH_AVFormat_GetBuffer(trackFormat, OH_MD_KEY_CODEC_CONFIG, &codecConfig, &bufferSize));
183         int bufferSizeResult = 5;
184         ASSERT_EQ(bufferSizeResult, bufferSize);
185         ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
186         int expectNum = 0;
187         ASSERT_EQ(expectNum, strcmp(mimeType, OH_AVCODEC_MIMETYPE_AUDIO_AAC));
188         ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_LANGUAGE, &language));
189         ASSERT_EQ(expectNum, strcmp(language, "eng"));
190         ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, &sampleRate));
191         int sampleRateResult = 48000;
192         ASSERT_EQ(sampleRateResult, sampleRate);
193     }
CheckAudioKeyVVC()194     static void CheckAudioKeyVVC()
195     {
196         uint8_t *codecConfig = nullptr;
197         size_t bufferSize;
198         const char* language = nullptr;
199         int64_t bitrate = 0;
200         double frameRate;
201         int32_t currentWidth = 0;
202         int32_t currentHeight = 0;
203         int tarckType = 0;
204         const char* mimeType = nullptr;
205         int32_t rotation;
206         ASSERT_TRUE(OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_BITRATE, &bitrate));
207         int bitrateResutlt = 10014008;
208         ASSERT_EQ(bitrateResutlt, bitrate);
209         ASSERT_TRUE(OH_AVFormat_GetBuffer(trackFormat, OH_MD_KEY_CODEC_CONFIG, &codecConfig, &bufferSize));
210         size_t bufferSizeResult = 247;
211         ASSERT_EQ(bufferSizeResult, bufferSize);
212         ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
213         int expectNum = 0;
214         ASSERT_EQ(expectNum, strcmp(mimeType, OH_AVCODEC_MIMETYPE_VIDEO_VVC));
215         ASSERT_TRUE(OH_AVFormat_GetDoubleValue(trackFormat, OH_MD_KEY_FRAME_RATE, &frameRate));
216         double frameRateResult = 60.000000;
217         ASSERT_EQ(frameRateResult, frameRate);
218         ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_HEIGHT, &currentHeight));
219         int currentHeightResult = 2160;
220         ASSERT_EQ(currentHeightResult, currentHeight);
221         ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_WIDTH, &currentWidth));
222         int currentWidthResult = 3840;
223         ASSERT_EQ(currentWidthResult, currentWidth);
224         ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_LANGUAGE, &language));
225         ASSERT_EQ(expectNum, strcmp(language, "und"));
226         ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_ROTATION, &rotation));
227         int rotationResult = 0;
228         ASSERT_EQ(rotationResult, rotation);
229         ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
230         int tarckTypeResult = 1;
231         ASSERT_EQ(tarckTypeResult, tarckType);
232     }
233 
SetAudioValue(OH_AVCodecBufferAttr attr,bool & audioIsEnd,int & audioFrame,int & aKeyCount)234     static void SetAudioValue(OH_AVCodecBufferAttr attr, bool &audioIsEnd, int &audioFrame, int &aKeyCount)
235     {
236         if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
237             audioIsEnd = true;
238             cout << audioFrame << "    audio is end !!!!!!!!!!!!!!!" << endl;
239         } else {
240             audioFrame++;
241             if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
242                 aKeyCount++;
243             }
244         }
245     }
246 
SetVideoValue(OH_AVCodecBufferAttr attr,bool & videoIsEnd,int & videoFrame,int & vKeyCount)247     static void SetVideoValue(OH_AVCodecBufferAttr attr, bool &videoIsEnd, int &videoFrame, int &vKeyCount)
248     {
249         if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
250             videoIsEnd = true;
251             cout << videoFrame << "   video is end !!!!!!!!!!!!!!!" << endl;
252         } else {
253             videoFrame++;
254             cout << "video track !!!!!" << endl;
255             if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
256                 vKeyCount++;
257             }
258         }
259     }
260 
261     /**
262  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1000
263  * @tc.name     : determine the orientation type of the video ROTATE_NONE.mp4
264  * @tc.desc     : function test
265  */
266 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1000, TestSize.Level0)
267 {
268     static OH_AVFormat *trackFormat = nullptr;
269     int32_t rotation = -1;
270     const char *uri = "http://192.168.3.11:8080/share/rotation/ROTATE_NONE.mp4";
271     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
272     ASSERT_NE(source, nullptr);
273     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
274     ASSERT_NE(trackFormat, nullptr);
275     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
276     ASSERT_EQ(rotation, MediaAVCodec::ROTATE_NONE);
277     OH_AVFormat_Destroy(trackFormat);
278 }
279 
280 /**
281  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1001
282  * @tc.name     : determine the orientation type of the video ROTATE_90.mp4
283  * @tc.desc     : function test
284  */
285 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1001, TestSize.Level1)
286 {
287     static OH_AVFormat *trackFormat = nullptr;
288     int32_t rotation = -1;
289     const char *uri = "http://192.168.3.11:8080/share/rotation/ROTATE_90.mp4";
290     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
291     ASSERT_NE(source, nullptr);
292     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
293     ASSERT_NE(trackFormat, nullptr);
294     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
295     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_90);
296     OH_AVFormat_Destroy(trackFormat);
297 }
298 
299 /**
300  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1002
301  * @tc.name     : determine the orientation type of the video ROTATE_180.mp4
302  * @tc.desc     : function test
303  */
304 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1002, TestSize.Level1)
305 {
306     static OH_AVFormat *trackFormat = nullptr;
307     int32_t rotation = -1;
308     const char *uri = "http://192.168.3.11:8080/share/rotation/ROTATE_180.mp4";
309     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
310     ASSERT_NE(source, nullptr);
311     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
312     ASSERT_NE(trackFormat, nullptr);
313     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
314     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_180);
315     OH_AVFormat_Destroy(trackFormat);
316 }
317 
318 /**
319  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1003
320  * @tc.name     : determine the orientation type of the video ROTATE_270.mp4
321  * @tc.desc     : function test
322  */
323 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1003, TestSize.Level1)
324 {
325     static OH_AVFormat *trackFormat = nullptr;
326     int32_t rotation = -1;
327     const char *uri = "http://192.168.3.11:8080/share/rotation/ROTATE_270.mp4";
328     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
329     ASSERT_NE(source, nullptr);
330     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
331     ASSERT_NE(trackFormat, nullptr);
332     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
333     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_270);
334     OH_AVFormat_Destroy(trackFormat);
335 }
336 
337 /**
338  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1004
339  * @tc.name     : determine the orientation type of the video FLIP_H.mp4
340  * @tc.desc     : function test
341  */
342 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1004, TestSize.Level2)
343 {
344     static OH_AVFormat *trackFormat = nullptr;
345     int32_t rotation = -1;
346     const char *uri = "http://192.168.3.11:8080/share/rotation/FLIP_H.mp4";
347     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
348     ASSERT_NE(source, nullptr);
349     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
350     ASSERT_NE(trackFormat, nullptr);
351     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
352     ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_H);
353     OH_AVFormat_Destroy(trackFormat);
354 }
355 
356 /**
357  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1005
358  * @tc.name     : determine the orientation type of the video FLIP_V.mp4
359  * @tc.desc     : function test
360  */
361 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1005, TestSize.Level2)
362 {
363     static OH_AVFormat *trackFormat = nullptr;
364     int32_t rotation = -1;
365     const char *uri = "http://192.168.3.11:8080/share/rotation/FLIP_V.mp4";
366     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
367     ASSERT_NE(source, nullptr);
368     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
369     ASSERT_NE(trackFormat, nullptr);
370     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
371     ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_V);
372     OH_AVFormat_Destroy(trackFormat);
373 }
374 
375 /**
376  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1006
377  * @tc.name     : determine the orientation type of the video FLIP_H_90.mp4
378  * @tc.desc     : function test
379  */
380 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1006, TestSize.Level2)
381 {
382     static OH_AVFormat *trackFormat = nullptr;
383     int32_t rotation = -1;
384     const char *uri = "http://192.168.3.11:8080/share/rotation/FLIP_H_90.mp4";;
385     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
386     ASSERT_NE(source, nullptr);
387     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
388     ASSERT_NE(trackFormat, nullptr);
389     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
390     ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_H_ROT90);
391     OH_AVFormat_Destroy(trackFormat);
392 }
393 
394 /**
395  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1007
396  * @tc.name     : determine the orientation type of the video FLIP_V_90.mp4
397  * @tc.desc     : function test
398  */
399 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1007, TestSize.Level2)
400 {
401     static OH_AVFormat *trackFormat = nullptr;
402     int32_t rotation = -1;
403     const char *uri = "http://192.168.3.11:8080/share/rotation/FLIP_V_90.mp4";
404     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
405     ASSERT_NE(source, nullptr);
406     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
407     ASSERT_NE(trackFormat, nullptr);
408     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
409     ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_V_ROT90);
410     OH_AVFormat_Destroy(trackFormat);
411 }
412 
413 /**
414  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1008
415  * @tc.name     : determine the orientation type of the video FLIP_H_180.mp4
416  * @tc.desc     : function test
417  */
418 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1008, TestSize.Level2)
419 {
420     static OH_AVFormat *trackFormat = nullptr;
421     int32_t rotation = -1;
422     const char *uri = "http://192.168.3.11:8080/share/rotation/FLIP_H_180.mp4";
423     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
424     ASSERT_NE(source, nullptr);
425     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
426     ASSERT_NE(trackFormat, nullptr);
427     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
428     ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_V || rotation == OHOS::MediaAVCodec::FLIP_H_ROT180);
429     OH_AVFormat_Destroy(trackFormat);
430 }
431 
432 /**
433  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1009
434  * @tc.name     : determine the orientation type of the video FLIP_V_180.mp4
435  * @tc.desc     : function test
436  */
437 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1009, TestSize.Level2)
438 {
439     static OH_AVFormat *trackFormat = nullptr;
440     int32_t rotation = -1;
441     const char *uri = "http://192.168.3.11:8080/share/rotation/FLIP_V_180.mp4";
442     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
443     ASSERT_NE(source, nullptr);
444     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
445     ASSERT_NE(trackFormat, nullptr);
446     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
447     ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_H || rotation == OHOS::MediaAVCodec::FLIP_V_ROT180);
448     OH_AVFormat_Destroy(trackFormat);
449 }
450 
451 /**
452  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1010
453  * @tc.name     : determine the orientation type of the video FLIP_H_270.mp4
454  * @tc.desc     : function test
455  */
456 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1010, TestSize.Level2)
457 {
458     static OH_AVFormat *trackFormat = nullptr;
459     int32_t rotation = -1;
460     const char *uri = "http://192.168.3.11:8080/share/rotation/FLIP_H_270.mp4";
461     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
462     ASSERT_NE(source, nullptr);
463     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
464     ASSERT_NE(trackFormat, nullptr);
465     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
466     ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_V_ROT90 || rotation == OHOS::MediaAVCodec::FLIP_H_ROT270);
467     OH_AVFormat_Destroy(trackFormat);
468 }
469 
470 /**
471  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1011
472  * @tc.name     : determine the orientation type of the video FLIP_V_270.mp4
473  * @tc.desc     : function test
474  */
475 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1011, TestSize.Level2)
476 {
477     static OH_AVFormat *trackFormat = nullptr;
478     int32_t rotation = -1;
479     const char *uri = "http://192.168.3.11:8080/share/rotation/FLIP_V_270.mp4";
480     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
481     ASSERT_NE(source, nullptr);
482     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
483     ASSERT_NE(trackFormat, nullptr);
484     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
485     ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_H_ROT90 || rotation == OHOS::MediaAVCodec::FLIP_V_ROT270);
486     OH_AVFormat_Destroy(trackFormat);
487 }
488 
489 /**
490  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1012
491  * @tc.name     : determine the orientation type of the video INVALID.mp4
492  * @tc.desc     : function test
493  */
494 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1012, TestSize.Level2)
495 {
496     static OH_AVFormat *trackFormat = nullptr;
497     int32_t rotation = -1;
498     const char *uri = "http://192.168.3.11:8080/share/rotation/INVALID.mp4";
499     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
500     ASSERT_NE(source, nullptr);
501     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
502     ASSERT_NE(trackFormat, nullptr);
503     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
504     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
505     OH_AVFormat_Destroy(trackFormat);
506 }
507 
508 /**
509  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1013
510  * @tc.name     : determine the orientation type of the video AV_ROTATE_NONE.mp4
511  * @tc.desc     : function test
512  */
513 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1013, TestSize.Level0)
514 {
515     static OH_AVFormat *trackFormat = nullptr;
516     int32_t rotation = -1;
517     const char *uri = "http://192.168.3.11:8080/share/rotation/AV_ROTATE_NONE.mp4";
518     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
519     ASSERT_NE(source, nullptr);
520     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
521     ASSERT_NE(trackFormat, nullptr);
522     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
523     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
524     OH_AVFormat_Destroy(trackFormat);
525 }
526 
527 /**
528  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1014
529  * @tc.name     : determine the orientation type of the video AV_ROTATE_90.mp4
530  * @tc.desc     : function test
531  */
532 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1014, TestSize.Level1)
533 {
534     static OH_AVFormat *trackFormat = nullptr;
535     int32_t rotation = -1;
536     const char *uri = "http://192.168.3.11:8080/share/rotation/AV_ROTATE_90.mp4";
537     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
538     ASSERT_NE(source, nullptr);
539     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
540     ASSERT_NE(trackFormat, nullptr);
541     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
542     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_90);
543     OH_AVFormat_Destroy(trackFormat);
544 }
545 
546 /**
547  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1015
548  * @tc.name     : determine the orientation type of the video AV_ROTATE_180.mp4
549  * @tc.desc     : function test
550  */
551 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1015, TestSize.Level1)
552 {
553     static OH_AVFormat *trackFormat = nullptr;
554     int32_t rotation = -1;
555     const char *uri = "http://192.168.3.11:8080/share/rotation/AV_ROTATE_180.mp4";
556     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
557     ASSERT_NE(source, nullptr);
558     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
559     ASSERT_NE(trackFormat, nullptr);
560     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
561     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_180);
562     OH_AVFormat_Destroy(trackFormat);
563 }
564 
565 /**
566  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1016
567  * @tc.name     : determine the orientation type of the video AV_ROTATE_270.mp4
568  * @tc.desc     : function test
569  */
570 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1016, TestSize.Level1)
571 {
572     static OH_AVFormat *trackFormat = nullptr;
573     int32_t rotation = -1;
574     const char *uri = "http://192.168.3.11:8080/share/rotation/AV_ROTATE_270.mp4";
575     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
576     ASSERT_NE(source, nullptr);
577     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
578     ASSERT_NE(trackFormat, nullptr);
579     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
580     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_270);
581     OH_AVFormat_Destroy(trackFormat);
582 }
583 
584 /**
585  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1017
586  * @tc.name     : determine the orientation type of the video AV_FLIP_H.mp4
587  * @tc.desc     : function test
588  */
589 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1017, TestSize.Level2)
590 {
591     static OH_AVFormat *trackFormat = nullptr;
592     int32_t rotation = -1;
593     const char *uri = "http://192.168.3.11:8080/share/rotation/AV_FLIP_H.mp4";
594     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
595     ASSERT_NE(source, nullptr);
596     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
597     ASSERT_NE(trackFormat, nullptr);
598     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
599     ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_H);
600     OH_AVFormat_Destroy(trackFormat);
601 }
602 
603 /**
604  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1018
605  * @tc.name     : determine the orientation type of the video AV_FLIP_V.mp4
606  * @tc.desc     : function test
607  */
608 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1018, TestSize.Level2)
609 {
610     static OH_AVFormat *trackFormat = nullptr;
611     int32_t rotation = -1;
612     const char *uri = "http://192.168.3.11:8080/share/rotation/AV_FLIP_V.mp4";
613     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
614     ASSERT_NE(source, nullptr);
615     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
616     ASSERT_NE(trackFormat, nullptr);
617     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
618     ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_V);
619     OH_AVFormat_Destroy(trackFormat);
620 }
621 
622 /**
623  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1019
624  * @tc.name     : determine the orientation type of the video AV_FLIP_H_90.mp4
625  * @tc.desc     : function test
626  */
627 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1019, TestSize.Level2)
628 {
629     static OH_AVFormat *trackFormat = nullptr;
630     int32_t rotation = -1;
631     const char *uri = "http://192.168.3.11:8080/share/rotation/AV_FLIP_H_90.mp4";
632     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
633     ASSERT_NE(source, nullptr);
634     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
635     ASSERT_NE(trackFormat, nullptr);
636     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
637     ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_H_ROT90);
638     OH_AVFormat_Destroy(trackFormat);
639 }
640 
641 /**
642  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1020
643  * @tc.name     : determine the orientation type of the video AV_FLIP_V_90.mp4
644  * @tc.desc     : function test
645  */
646 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1020, TestSize.Level2)
647 {
648     static OH_AVFormat *trackFormat = nullptr;
649     int32_t rotation = -1;
650     const char *uri = "http://192.168.3.11:8080/share/rotation/AV_FLIP_V_90.mp4";
651     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
652     ASSERT_NE(source, nullptr);
653     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
654     ASSERT_NE(trackFormat, nullptr);
655     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
656     ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_V_ROT90);
657     OH_AVFormat_Destroy(trackFormat);
658 }
659 
660 /**
661  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1021
662  * @tc.name     : determine the orientation type of the video AV_FLIP_H_180.mp4
663  * @tc.desc     : function test
664  */
665 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1021, TestSize.Level2)
666 {
667     static OH_AVFormat *trackFormat = nullptr;
668     int32_t rotation = -1;
669     const char *uri = "http://192.168.3.11:8080/share/rotation/AV_FLIP_H_180.mp4";
670     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
671     ASSERT_NE(source, nullptr);
672     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
673     ASSERT_NE(trackFormat, nullptr);
674     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
675     ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_V || rotation == OHOS::MediaAVCodec::FLIP_H_ROT180);
676     OH_AVFormat_Destroy(trackFormat);
677 }
678 
679 /**
680  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1022
681  * @tc.name     : determine the orientation type of the video AV_FLIP_V_180.mp4
682  * @tc.desc     : function test
683  */
684 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1022, TestSize.Level2)
685 {
686     static OH_AVFormat *trackFormat = nullptr;
687     int32_t rotation = -1;
688     const char *uri = "http://192.168.3.11:8080/share/rotation/AV_FLIP_V_180.mp4";
689     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
690     ASSERT_NE(source, nullptr);
691     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
692     ASSERT_NE(trackFormat, nullptr);
693     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
694     ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_H || rotation == OHOS::MediaAVCodec::FLIP_V_ROT180);
695     OH_AVFormat_Destroy(trackFormat);
696 }
697 
698 /**
699  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1023
700  * @tc.name     : determine the orientation type of the video AV_FLIP_H_270.mp4
701  * @tc.desc     : function test
702  */
703 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1023, TestSize.Level2)
704 {
705     static OH_AVFormat *trackFormat = nullptr;
706     int32_t rotation = -1;
707     const char *uri = "http://192.168.3.11:8080/share/rotation/AV_FLIP_H_270.mp4";
708     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
709     ASSERT_NE(source, nullptr);
710     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
711     ASSERT_NE(trackFormat, nullptr);
712     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
713     ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_V_ROT90 || rotation == OHOS::MediaAVCodec::FLIP_H_ROT270);
714     OH_AVFormat_Destroy(trackFormat);
715 }
716 
717 /**
718  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1024
719  * @tc.name     : determine the orientation type of the video AV_FLIP_V_270.mp4
720  * @tc.desc     : function test
721  */
722 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1024, TestSize.Level2)
723 {
724     static OH_AVFormat *trackFormat = nullptr;
725     int32_t rotation = -1;
726     const char *uri = "http://192.168.3.11:8080/share/rotation/AV_FLIP_V_270.mp4";
727     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
728     ASSERT_NE(source, nullptr);
729     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
730     ASSERT_NE(trackFormat, nullptr);
731     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
732     ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_H_ROT90 || rotation == OHOS::MediaAVCodec::FLIP_V_ROT270);
733     OH_AVFormat_Destroy(trackFormat);
734 }
735 
736 /**
737  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1025
738  * @tc.name     : determine the orientation type of the video AV_INVALID.mp4
739  * @tc.desc     : function test
740  */
741 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1025, TestSize.Level2)
742 {
743     static OH_AVFormat *trackFormat = nullptr;
744     int32_t rotation = -1;
745     const char *uri = "http://192.168.3.11:8080/share/rotation/AV_INVALID.mp4";
746     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
747     ASSERT_NE(source, nullptr);
748     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
749     ASSERT_NE(trackFormat, nullptr);
750     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
751     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
752     OH_AVFormat_Destroy(trackFormat);
753 }
754 
755 /**
756  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1026
757  * @tc.name     : determine the orientation type of the video UNDEFINED_FLV.flv
758  * @tc.desc     : function test
759  */
760 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1026, TestSize.Level3)
761 {
762     static OH_AVFormat *trackFormat = nullptr;
763     int32_t rotation = 0;
764     const char *uri = "http://192.168.3.11:8080/share/rotation/UNDEFINED_FLV.flv";
765     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
766     ASSERT_NE(source, nullptr);
767     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
768     ASSERT_NE(trackFormat, nullptr);
769     ASSERT_FALSE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
770     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
771     OH_AVFormat_Destroy(trackFormat);
772 }
773 
774 /**
775  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1027
776  * @tc.name     : determine the orientation type of the video UNDEFINED_fmp4.mp4
777  * @tc.desc     : function test
778  */
779 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1027, TestSize.Level3)
780 {
781     static OH_AVFormat *trackFormat = nullptr;
782     int32_t rotation = 0;
783     const char *uri = "http://192.168.3.11:8080/share/rotation/UNDEFINED_FMP4.mp4";
784     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
785     ASSERT_NE(source, nullptr);
786     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
787     ASSERT_NE(trackFormat, nullptr);
788     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
789     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
790     OH_AVFormat_Destroy(trackFormat);
791 }
792 
793 /**
794  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1028
795  * @tc.name     : determine the orientation type of the video UNDEFINED_MKV.mkv
796  * @tc.desc     : function test
797  */
798 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1028, TestSize.Level3)
799 {
800     static OH_AVFormat *trackFormat = nullptr;
801     int32_t rotation = 0;
802     const char *uri = "http://192.168.3.11:8080/share/rotation/UNDEFINED_MKV.mkv";
803     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
804     ASSERT_NE(source, nullptr);
805     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
806     ASSERT_NE(trackFormat, nullptr);
807     ASSERT_FALSE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
808     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
809     OH_AVFormat_Destroy(trackFormat);
810 }
811 
812 /**
813  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1029
814  * @tc.name     : determine the orientation type of the video UNDEFINED_TS.ts
815  * @tc.desc     : function test
816  */
817 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_ORIENTATIONTYPE_1029, TestSize.Level3)
818 {
819     static OH_AVFormat *trackFormat = nullptr;
820     int32_t rotation = 0;
821     const char *uri = "http://192.168.3.11:8080/share/rotation/UNDEFINED_TS.ts";
822     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
823     ASSERT_NE(source, nullptr);
824     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
825     ASSERT_NE(trackFormat, nullptr);
826     ASSERT_FALSE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
827     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
828     OH_AVFormat_Destroy(trackFormat);
829 }
830 
831 /**
832  * @tc.number    : DEMUXER_VVC_NET_0100
833  * @tc.name      : demuxer 8bit H266 MP4 file, read
834  * @tc.desc      : function test
835  */
836 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_VVC_NET_0100, TestSize.Level0)
837 {
838     if (memory == nullptr) {
839         memory = OH_AVMemory_Create(g_width * g_height);
840     }
841     int tarckType = 0;
842     OH_AVCodecBufferAttr attr;
843     bool videoIsEnd = false;
844     int videoFrame = 0;
845     const char *uri = "http://192.168.3.11:8080/share/vvc_8bit_3840_2160.mp4";
846     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
847     ASSERT_NE(source, nullptr);
848     demuxer = OH_AVDemuxer_CreateWithSource(source);
849     ASSERT_NE(demuxer, nullptr);
850     sourceFormat = OH_AVSource_GetSourceFormat(source);
851     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
852     ASSERT_EQ(1, g_trackCount);
853     for (int32_t index = 0; index < g_trackCount; index++) {
854         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
855     }
856     int vKeyCount = 0;
857     while (!videoIsEnd) {
858         trackFormat = OH_AVSource_GetTrackFormat(source, 0);
859         ASSERT_NE(trackFormat, nullptr);
860         ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
861         OH_AVFormat_Destroy(trackFormat);
862         trackFormat = nullptr;
863         if (videoIsEnd) {
864             continue;
865         }
866         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
867         SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
868     }
869     ASSERT_EQ(videoFrame, 600);
870     ASSERT_EQ(vKeyCount, 10);
871 }
872 
873 /**
874  * @tc.number    : DEMUXER_VVC_NET_0200
875  * @tc.name      : demuxer 10bit H266 MP4 file, read
876  * @tc.desc      : function test
877  */
878 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_VVC_NET_0200, TestSize.Level0)
879 {
880     if (memory == nullptr) {
881         memory = OH_AVMemory_Create(g_width * g_height);
882     }
883     int tarckType = 0;
884     OH_AVCodecBufferAttr attr;
885     bool videoIsEnd = false;
886     int videoFrame = 0;
887     const char *uri = "http://192.168.3.11:8080/share/vvc_aac_10bit_1920_1080.mp4";
888     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
889     ASSERT_NE(source, nullptr);
890     demuxer = OH_AVDemuxer_CreateWithSource(source);
891     ASSERT_NE(demuxer, nullptr);
892     sourceFormat = OH_AVSource_GetSourceFormat(source);
893     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
894     ASSERT_EQ(2, g_trackCount);
895     for (int32_t index = 0; index < g_trackCount; index++) {
896         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
897     }
898     int vKeyCount = 0;
899     int aKeyCount = 0;
900     int audioFrame = 0;
901     bool audioIsEnd = false;
902     while (!audioIsEnd || !videoIsEnd) {
903         for (int32_t index = 0; index < g_trackCount; index++) {
904             trackFormat = OH_AVSource_GetTrackFormat(source, index);
905             ASSERT_NE(trackFormat, nullptr);
906             ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
907             OH_AVFormat_Destroy(trackFormat);
908             trackFormat = nullptr;
909             if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
910                 continue;
911             }
912             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
913             if (tarckType == OHOS::Media::MEDIA_TYPE_VID) {
914                 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
915             } else if (tarckType == OHOS::Media::MEDIA_TYPE_AUD) {
916                 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
917             }
918         }
919     }
920     ASSERT_EQ(audioFrame, 2812);
921     ASSERT_EQ(aKeyCount, 2812);
922     ASSERT_EQ(videoFrame, 3000);
923     ASSERT_EQ(vKeyCount, 63);
924 }
925 
926 /**
927  * @tc.number    : DEMUXER_VVC_NET_0300
928  * @tc.name      : demuxer 8bit H266 MP4 file, read+seek
929  * @tc.desc      : function test
930  */
931 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_VVC_NET_0300, TestSize.Level0)
932 {
933     if (memory == nullptr) {
934         memory = OH_AVMemory_Create(g_width * g_height);
935     }
936     int64_t duration = 0;
937     OH_AVCodecBufferAttr attr;
938     const char *uri = "http://192.168.3.11:8080/share/vvc_8bit_3840_2160.mp4";
939     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
940     ASSERT_NE(source, nullptr);
941     demuxer = OH_AVDemuxer_CreateWithSource(source);
942     ASSERT_NE(demuxer, nullptr);
943     sourceFormat = OH_AVSource_GetSourceFormat(source);
944     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
945     ASSERT_EQ(1, g_trackCount);
946     for (int32_t index = 0; index < g_trackCount; index++) {
947         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
948     }
949     ASSERT_TRUE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_DURATION, &duration));
950     ASSERT_EQ(duration, 10000000);
951     for (int index = 0; index < (duration / 1000); index++) {
952         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
953         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, index, OH_AVSeekMode::SEEK_MODE_CLOSEST_SYNC));
954     }
955 }
956 
957 /**
958  * @tc.number    : DEMUXER_VVC_NET_0400
959  * @tc.name      : demuxer 10bit H266 MP4 file, read+seek
960  * @tc.desc      : function test
961  */
962 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_VVC_NET_0400, TestSize.Level0)
963 {
964     if (memory == nullptr) {
965         memory = OH_AVMemory_Create(g_width * g_height);
966     }
967     int64_t duration = 0;
968     OH_AVCodecBufferAttr attr;
969     const char *uri = "http://192.168.3.11:8080/share/vvc_aac_10bit_1920_1080.mp4";
970     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
971     ASSERT_NE(source, nullptr);
972     demuxer = OH_AVDemuxer_CreateWithSource(source);
973     ASSERT_NE(demuxer, nullptr);
974     sourceFormat = OH_AVSource_GetSourceFormat(source);
975     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
976     ASSERT_EQ(2, g_trackCount);
977     for (int32_t index = 0; index < g_trackCount; index++) {
978         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
979     }
980     ASSERT_TRUE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_DURATION, &duration));
981     ASSERT_EQ(duration, 60000000);
982     for (int num = 0; num < (duration / 1000); num++) {
983         for (int32_t index = 0; index < g_trackCount; index++) {
984             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
985             ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, num, OH_AVSeekMode::SEEK_MODE_CLOSEST_SYNC));
986         }
987     }
988 }
989 
990 /**
991  * @tc.number    : DEMUXER_VVC_NET_0500
992  * @tc.name      : demuxer 8bit H266 MP4 file, check key
993  * @tc.desc      : function test
994  */
995 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_VVC_NET_0500, TestSize.Level0)
996 {
997     int64_t duration = 0;
998     int64_t startTime;
999     const char *uri = "http://192.168.3.11:8080/share/vvc_8bit_3840_2160.mp4";
1000     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
1001     ASSERT_NE(source, nullptr);
1002     sourceFormat = OH_AVSource_GetSourceFormat(source);
1003     ASSERT_NE(sourceFormat, nullptr);
1004     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1005     ASSERT_NE(trackFormat, nullptr);
1006     ASSERT_TRUE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_DURATION, &duration));
1007     int durationResutlt = 10000000;
1008     ASSERT_EQ(durationResutlt, duration);
1009     ASSERT_TRUE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_START_TIME, &startTime));
1010     int startTimeResult = 0;
1011     ASSERT_EQ(startTimeResult, startTime);
1012     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1013     ASSERT_EQ(1, g_trackCount);
1014     CheckAudioKeyVVC();
1015 }
1016 
1017 /**
1018  * @tc.number    : DEMUXER_VVC_NET_0600
1019  * @tc.name      : demuxer 10bit H266 MP4 file, check key
1020  * @tc.desc      : function test
1021  */
1022 HWTEST_F(DemuxerNet2NdkTest, DEMUXER_VVC_NET_0600, TestSize.Level0)
1023 {
1024     int64_t duration = 0;
1025     int64_t startTime;
1026     int tarckType = 0;
1027     const char *uri = "http://192.168.3.11:8080/share/vvc_aac_10bit_1920_1080.mp4";
1028     source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
1029     ASSERT_NE(source, nullptr);
1030     sourceFormat = OH_AVSource_GetSourceFormat(source);
1031     ASSERT_NE(sourceFormat, nullptr);
1032     ASSERT_TRUE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_DURATION, &duration));
1033     ASSERT_EQ(60000000, duration);
1034     ASSERT_TRUE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_START_TIME, &startTime));
1035     ASSERT_EQ(0, startTime);
1036     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1037     ASSERT_EQ(2, g_trackCount);
1038     for (int32_t index = 0; index < g_trackCount; index++) {
1039         trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1040         ASSERT_NE(trackFormat, nullptr);
1041         ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1042         OH_AVFormat_Destroy(trackFormat);
1043         trackFormat = nullptr;
1044         if (tarckType == OHOS::Media::MEDIA_TYPE_VID) {
1045             CheckVideoKey();
1046         } else if (tarckType == OHOS::Media::MEDIA_TYPE_AUD) {
1047             CheckAudioKey();
1048         }
1049     }
1050 }
1051 } // namespace