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 #include "native_avmemory.h"
23 #include "meta/meta_key.h"
24 #include "meta/meta.h"
25 #include "av_common.h"
26 
27 #include <iostream>
28 #include <cstdio>
29 #include <string>
30 #include <fcntl.h>
31 #include <cmath>
32 #include <thread>
33 
34 using namespace std;
35 using namespace OHOS;
36 using namespace OHOS::Media;
37 using namespace testing::ext;
38 
39 namespace OHOS {
40 namespace Media {
41 class DemuxerFunc2NdkTest : public testing::Test {
42 public:
43     // SetUpTestCase: Called before all test cases
44     static void SetUpTestCase(void);
45     // TearDownTestCase: Called after all test case
46     static void TearDownTestCase(void);
47     // SetUp: Called before each test cases
48     void SetUp(void);
49     // TearDown: Called after each test cases
50     void TearDown(void);
51 };
52 
53 static OH_AVMemory *memory = nullptr;
54 static OH_AVSource *source = nullptr;
55 static OH_AVDemuxer *demuxer = nullptr;
56 static OH_AVFormat *sourceFormat = nullptr;
57 static OH_AVFormat *trackFormat = nullptr;
58 static OH_AVBuffer *avBuffer = nullptr;
59 static OH_AVFormat *format = nullptr;
60 static int32_t g_trackCount;
61 static int32_t g_width = 3840;
62 static int32_t g_height = 2160;
63 constexpr int32_t VTTBACK = 4;
64 constexpr int32_t VTTFORWARD = 7;
65 constexpr int32_t VTTSEEKFORWARD = 5100;
66 constexpr int32_t VTTSEEKBACK = 2100;
SetUpTestCase()67 void DemuxerFunc2NdkTest::SetUpTestCase() {}
TearDownTestCase()68 void DemuxerFunc2NdkTest::TearDownTestCase() {}
SetUp()69 void DemuxerFunc2NdkTest::SetUp()
70 {
71     memory = OH_AVMemory_Create(g_width * g_height);
72     g_trackCount = 0;
73 }
TearDown()74 void DemuxerFunc2NdkTest::TearDown()
75 {
76     if (trackFormat != nullptr) {
77         OH_AVFormat_Destroy(trackFormat);
78         trackFormat = nullptr;
79     }
80 
81     if (sourceFormat != nullptr) {
82         OH_AVFormat_Destroy(sourceFormat);
83         sourceFormat = nullptr;
84     }
85 
86     if (memory != nullptr) {
87         OH_AVMemory_Destroy(memory);
88         memory = nullptr;
89     }
90     if (source != nullptr) {
91         OH_AVSource_Destroy(source);
92         source = nullptr;
93     }
94     if (demuxer != nullptr) {
95         OH_AVDemuxer_Destroy(demuxer);
96         demuxer = nullptr;
97     }
98     if (avBuffer != nullptr) {
99         OH_AVBuffer_Destroy(avBuffer);
100         avBuffer = nullptr;
101     }
102     if (format != nullptr) {
103         OH_AVFormat_Destroy(format);
104         format = nullptr;
105     }
106 }
107 } // namespace Media
108 } // namespace OHOS
GetFileSize(const char * fileName)109 static int64_t GetFileSize(const char *fileName)
110 {
111     int64_t fileSize = 0;
112     if (fileName != nullptr) {
113         struct stat fileStatus {};
114         if (stat(fileName, &fileStatus) == 0) {
115             fileSize = static_cast<int64_t>(fileStatus.st_size);
116         }
117     }
118     return fileSize;
119 }
120 
121 /**
122  * @tc.number    : SUB_MEDIA_DEMUXER_VTT_4800
123  * @tc.name      : create vtt demuxer with file and read
124  * @tc.desc      : function test
125  */
126 HWTEST_F(DemuxerFunc2NdkTest, SUB_MEDIA_DEMUXER_VTT_4800, TestSize.Level0)
127 {
128     OH_AVCodecBufferAttr attr;
129     const char* mimeType = nullptr;
130     int vttIndex = 1;
131     int vttSubtitle = 0;
132     const char *file = "/data/test/media/webvtt_test.vtt";
133     int fd = open(file, O_RDONLY);
134     int64_t size = GetFileSize(file);
135     cout << file << "----------------------" << fd << "---------" << size << endl;
136     source = OH_AVSource_CreateWithFD(fd, 0, size);
137     ASSERT_NE(source, nullptr);
138     demuxer = OH_AVDemuxer_CreateWithSource(source);
139     ASSERT_NE(demuxer, nullptr);
140     sourceFormat = OH_AVSource_GetSourceFormat(source);
141     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
142     ASSERT_NE(trackFormat, nullptr);
143     ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
144     ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_SUBTITLE_WEBVTT));
145     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
146     ASSERT_EQ(1, g_trackCount);
147     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
148     int tarckType = 0;
149     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
150     ASSERT_EQ(tarckType, MEDIA_TYPE_SUBTITLE);
151     int64_t starttime = 0;
152     ASSERT_FALSE(OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_TRACK_START_TIME, &starttime));
153     while (true) {
154         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
155         if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
156             cout << "   vtt is end !!!!!!!!!!!!!!!" << endl;
157             break;
158         }
159         uint8_t *data = OH_AVMemory_GetAddr(memory);
160         vttSubtitle = atoi(reinterpret_cast<const char*>(data));
161         cout << "subtitle" << "----------------" << vttSubtitle << "-----------------" << endl;
162         ASSERT_EQ(vttSubtitle, vttIndex);
163         vttIndex++;
164     }
165     close(fd);
166 }
167 
168 /**
169  * @tc.number    : SUB_MEDIA_DEMUXER_VTT_4900
170  * @tc.name      : create vtt demuxer with file and forward back seek+read
171  * @tc.desc      : function test
172  */
173 HWTEST_F(DemuxerFunc2NdkTest, SUB_MEDIA_DEMUXER_VTT_4900, TestSize.Level0)
174 {
175     OH_AVCodecBufferAttr attr;
176     const char* mimeType = nullptr;
177     int vttIndex = 1;
178     int vttSubtitle = 0;
179     uint8_t *data = nullptr;
180     const char *file = "/data/test/media/webvtt_test.vtt";
181     int fd = open(file, O_RDONLY);
182     int64_t size = GetFileSize(file);
183     source = OH_AVSource_CreateWithFD(fd, 0, size);
184     ASSERT_NE(source, nullptr);
185     demuxer = OH_AVDemuxer_CreateWithSource(source);
186     ASSERT_NE(demuxer, nullptr);
187     sourceFormat = OH_AVSource_GetSourceFormat(source);
188     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
189     ASSERT_NE(trackFormat, nullptr);
190     ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
191     ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_SUBTITLE_WEBVTT));
192     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
193     ASSERT_EQ(1, g_trackCount);
194     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
195     int tarckType = 0;
196     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
197     ASSERT_EQ(tarckType, MEDIA_TYPE_SUBTITLE);
198     for (int index = 0; index < 5; index++) {
199         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
200     }
201     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, VTTSEEKBACK, SEEK_MODE_CLOSEST_SYNC));
202     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
203     data = OH_AVMemory_GetAddr(memory);
204     vttSubtitle = atoi(reinterpret_cast<const char*>(data));
205     ASSERT_EQ(vttSubtitle, VTTBACK);
206     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, VTTSEEKFORWARD, SEEK_MODE_CLOSEST_SYNC));
207     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
208     data = OH_AVMemory_GetAddr(memory);
209     vttSubtitle = atoi(reinterpret_cast<const char*>(data));
210     vttIndex = VTTFORWARD;
211     ASSERT_EQ(vttSubtitle, VTTFORWARD);
212     while (true) {
213         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
214         if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
215             break;
216         }
217         data = OH_AVMemory_GetAddr(memory);
218         vttSubtitle = atoi(reinterpret_cast<const char*>(data));
219         vttIndex++;
220         ASSERT_EQ(vttSubtitle, vttIndex);
221     }
222     close(fd);
223 }
224 
225 /**
226  * @tc.number    : SUB_MEDIA_DEMUXER_VTT_5000
227  * @tc.name      : create vtt demuxer with file and back seek+read
228  * @tc.desc      : function test
229  */
230 HWTEST_F(DemuxerFunc2NdkTest, SUB_MEDIA_DEMUXER_VTT_5000, TestSize.Level0)
231 {
232     OH_AVCodecBufferAttr attr;
233     const char* mimeType = nullptr;
234     int vttIndex = 1;
235     int vttSubtitle = 0;
236     uint8_t *data = nullptr;
237     const char *file = "/data/test/media/webvtt_test.vtt";
238     int fd = open(file, O_RDONLY);
239     int64_t size = GetFileSize(file);
240     source = OH_AVSource_CreateWithFD(fd, 0, size);
241     ASSERT_NE(source, nullptr);
242     demuxer = OH_AVDemuxer_CreateWithSource(source);
243     ASSERT_NE(demuxer, nullptr);
244     sourceFormat = OH_AVSource_GetSourceFormat(source);
245     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
246     ASSERT_NE(trackFormat, nullptr);
247     ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
248     ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_SUBTITLE_WEBVTT));
249     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
250     ASSERT_EQ(1, g_trackCount);
251     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
252     int tarckType = 0;
253     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
254     ASSERT_EQ(tarckType, MEDIA_TYPE_SUBTITLE);
255     for (int index = 0; index < 5; index++) {
256         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
257         data = OH_AVMemory_GetAddr(memory);
258         vttSubtitle = atoi(reinterpret_cast<const char*>(data));
259         ASSERT_EQ(vttSubtitle, vttIndex);
260         vttIndex++;
261     }
262     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, VTTSEEKBACK, SEEK_MODE_CLOSEST_SYNC));
263     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
264     data = OH_AVMemory_GetAddr(memory);
265     vttSubtitle = atoi(reinterpret_cast<const char*>(data));
266     vttIndex = 4;
267     ASSERT_EQ(vttSubtitle, vttIndex);
268     while (true) {
269         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
270         if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
271             break;
272         }
273         data = OH_AVMemory_GetAddr(memory);
274         vttSubtitle = atoi(reinterpret_cast<const char*>(data));
275         vttIndex++;
276         ASSERT_EQ(vttSubtitle, vttIndex);
277     }
278     close(fd);
279 }
280 
281 /**
282  * @tc.number    : SUB_MEDIA_DEMUXER_VTT_5100
283  * @tc.name      : create vtt demuxer with file and forward seek+read
284  * @tc.desc      : function test
285  */
286 HWTEST_F(DemuxerFunc2NdkTest, SUB_MEDIA_DEMUXER_VTT_5100, TestSize.Level0)
287 {
288     OH_AVCodecBufferAttr attr;
289     const char* mimeType = nullptr;
290     int vttIndex = 1;
291     int vttSubtitle = 0;
292     uint8_t *data = nullptr;
293     const char *file = "/data/test/media/webvtt_test.vtt";
294     int fd = open(file, O_RDONLY);
295     int64_t size = GetFileSize(file);
296     source = OH_AVSource_CreateWithFD(fd, 0, size);
297     ASSERT_NE(source, nullptr);
298     demuxer = OH_AVDemuxer_CreateWithSource(source);
299     ASSERT_NE(demuxer, nullptr);
300     sourceFormat = OH_AVSource_GetSourceFormat(source);
301     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
302     ASSERT_NE(trackFormat, nullptr);
303     ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
304     ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_SUBTITLE_WEBVTT));
305     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
306     ASSERT_EQ(1, g_trackCount);
307     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
308     int tarckType = 0;
309     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
310     ASSERT_EQ(tarckType, MEDIA_TYPE_SUBTITLE);
311     for (int index = 0; index < 5; index++) {
312         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
313         data = OH_AVMemory_GetAddr(memory);
314         vttSubtitle = atoi(reinterpret_cast<const char*>(data));
315         ASSERT_EQ(vttSubtitle, vttIndex);
316         vttIndex++;
317     }
318     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, VTTSEEKFORWARD, SEEK_MODE_CLOSEST_SYNC));
319     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
320     data = OH_AVMemory_GetAddr(memory);
321     vttSubtitle = atoi(reinterpret_cast<const char*>(data));
322     vttIndex = 7;
323     ASSERT_EQ(vttSubtitle, vttIndex);
324     while (true) {
325         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
326         if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
327             break;
328         }
329         data = OH_AVMemory_GetAddr(memory);
330         vttSubtitle = atoi(reinterpret_cast<const char*>(data));
331         vttIndex++;
332         ASSERT_EQ(vttSubtitle, vttIndex);
333     }
334     close(fd);
335 }
336 
337 /**
338  * @tc.number    : SUB_MEDIA_DEMUXER_VTT_5600
339  * @tc.name      : create vtt demuxer with error file -- no empty paragraphs
340  * @tc.desc      : function test
341  */
342 HWTEST_F(DemuxerFunc2NdkTest, SUB_MEDIA_DEMUXER_VTT_5600, TestSize.Level2)
343 {
344     OH_AVCodecBufferAttr attr;
345     const char* mimeType = nullptr;
346     const char *file = "/data/test/media/vtt_5600.vtt";
347     int fd = open(file, O_RDONLY);
348     int64_t size = GetFileSize(file);
349     cout << file << "----------------------" << fd << "---------" << size << endl;
350     source = OH_AVSource_CreateWithFD(fd, 0, size);
351     ASSERT_NE(source, nullptr);
352     demuxer = OH_AVDemuxer_CreateWithSource(source);
353     ASSERT_NE(demuxer, nullptr);
354     sourceFormat = OH_AVSource_GetSourceFormat(source);
355     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
356     ASSERT_NE(trackFormat, nullptr);
357     ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
358     ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_SUBTITLE_WEBVTT));
359     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
360     ASSERT_EQ(1, g_trackCount);
361     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
362     int tarckType = 0;
363     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
364     ASSERT_EQ(tarckType, MEDIA_TYPE_SUBTITLE);
365     while (true) {
366         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
367         if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
368             cout << "   vtt is end !!!!!!!!!!!!!!!" << endl;
369             break;
370         }
371         uint8_t *data = OH_AVMemory_GetAddr(memory);
372         cout << "subtitle"<< "----------------" << data << "-----------------" << endl;
373     }
374     close(fd);
375 }
376 
377 /**
378  * @tc.number    : SUB_MEDIA_DEMUXER_VTT_5700
379  * @tc.name      : create vtt demuxer with error file -- subtitle sequence error
380  * @tc.desc      : function test
381  */
382 HWTEST_F(DemuxerFunc2NdkTest, SUB_MEDIA_DEMUXER_VTT_5700, TestSize.Level2)
383 {
384     OH_AVCodecBufferAttr attr;
385     const char* mimeType = nullptr;
386     const char *file = "/data/test/media/vtt_5700.vtt";
387     int fd = open(file, O_RDONLY);
388     int64_t size = GetFileSize(file);
389     cout << file << "----------------------" << fd << "---------" << size << endl;
390     source = OH_AVSource_CreateWithFD(fd, 0, size);
391     ASSERT_NE(source, nullptr);
392     demuxer = OH_AVDemuxer_CreateWithSource(source);
393     ASSERT_NE(demuxer, nullptr);
394     sourceFormat = OH_AVSource_GetSourceFormat(source);
395     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
396     ASSERT_NE(trackFormat, nullptr);
397     ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
398     ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_SUBTITLE_WEBVTT));
399     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
400     ASSERT_EQ(1, g_trackCount);
401     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
402     int tarckType = 0;
403     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
404     ASSERT_EQ(tarckType, MEDIA_TYPE_SUBTITLE);
405     while (true) {
406         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
407         if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
408             cout << "   vtt is end !!!!!!!!!!!!!!!" << endl;
409             break;
410         }
411         uint8_t *data = OH_AVMemory_GetAddr(memory);
412         cout << "subtitle" << "----------------" << data << "-----------------" << endl;
413     }
414     close(fd);
415 }
416 
417 /**
418  * @tc.number    : SUB_MEDIA_DEMUXER_VTT_5800
419  * @tc.name      : create vtt demuxer with error file -- timeline format error null
420  * @tc.desc      : function test
421  */
422 HWTEST_F(DemuxerFunc2NdkTest, SUB_MEDIA_DEMUXER_VTT_5800, TestSize.Level2)
423 {
424     OH_AVCodecBufferAttr attr;
425     const char *file = "/data/test/media/vtt_5800.vtt";
426     int fd = open(file, O_RDONLY);
427     int64_t size = GetFileSize(file);
428     cout << file << "----------------------" << fd << "---------" << size << endl;
429     source = OH_AVSource_CreateWithFD(fd, 0, size);
430     demuxer = OH_AVDemuxer_CreateWithSource(source);
431     sourceFormat = OH_AVSource_GetSourceFormat(source);
432     OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount);
433     OH_AVDemuxer_SelectTrackByID(demuxer, 0);
434     int tarckType = 0;
435     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
436     ASSERT_NE(trackFormat, nullptr);
437     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
438     ASSERT_EQ(tarckType, MEDIA_TYPE_SUBTITLE);
439     OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr);
440     uint8_t *data = OH_AVMemory_GetAddr(memory);
441     cout << "subtitle"<< "----------------" << data << "-----------------" << endl;
442     close(fd);
443 }
444 
445 /**
446  * @tc.number    : SUB_MEDIA_DEMUXER_VTT_5900
447  * @tc.name      : create vtt demuxer with error file -- subtitle is empty
448  * @tc.desc      : function test
449  */
450 HWTEST_F(DemuxerFunc2NdkTest, SUB_MEDIA_DEMUXER_VTT_5900, TestSize.Level2)
451 {
452     OH_AVCodecBufferAttr attr;
453     const char* mimeType = nullptr;
454     const char *file = "/data/test/media/vtt_5900.vtt";
455     int fd = open(file, O_RDONLY);
456     int64_t size = GetFileSize(file);
457     cout << file << "----------------------" << fd << "---------" << size << endl;
458     source = OH_AVSource_CreateWithFD(fd, 0, size);
459     ASSERT_NE(source, nullptr);
460     demuxer = OH_AVDemuxer_CreateWithSource(source);
461     ASSERT_NE(demuxer, nullptr);
462     sourceFormat = OH_AVSource_GetSourceFormat(source);
463     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
464     ASSERT_NE(trackFormat, nullptr);
465     ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
466     ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_SUBTITLE_WEBVTT));
467     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
468     ASSERT_EQ(1, g_trackCount);
469     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
470     int tarckType = 0;
471     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
472     ASSERT_EQ(tarckType, MEDIA_TYPE_SUBTITLE);
473     while (true) {
474         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
475         if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
476             cout << "   vtt is end !!!!!!!!!!!!!!!" << endl;
477             break;
478         }
479         uint8_t *data = OH_AVMemory_GetAddr(memory);
480         cout << "subtitle"<< "----------------" << data << "-----------------" << endl;
481     }
482     close(fd);
483 }
484 
485 /**
486  * @tc.number    : SUB_MEDIA_DEMUXER_VTT_6000
487  * @tc.name      : create vtt demuxer with error file -- vtt file is empty
488  * @tc.desc      : function test
489  * fail
490  */
491 HWTEST_F(DemuxerFunc2NdkTest, SUB_MEDIA_DEMUXER_VTT_6000, TestSize.Level2)
492 {
493     OH_AVCodecBufferAttr attr;
494     const char *file = "/data/test/media/vtt_6000.vtt";
495     int fd = open(file, O_RDONLY);
496     int64_t size = GetFileSize(file);
497     cout << file << "----------------------" << fd << "---------" << size << endl;
498     source = OH_AVSource_CreateWithFD(fd, 0, size);
499     demuxer = OH_AVDemuxer_CreateWithSource(source);
500     sourceFormat = OH_AVSource_GetSourceFormat(source);
501     OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount);
502     OH_AVDemuxer_SelectTrackByID(demuxer, 0);
503     OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr);
504     uint8_t *data = OH_AVMemory_GetAddr(memory);
505     cout << "subtitle"<< "----------------" << data << "-----------------" << endl;
506     close(fd);
507 }
508 
509 /**
510  * @tc.number    : SUB_MEDIA_DEMUXER_VTT_6100
511  * @tc.name      : create vtt demuxer with error file -- alternating Up and Down Times
512  * @tc.desc      : function test
513  */
514 HWTEST_F(DemuxerFunc2NdkTest, SUB_MEDIA_DEMUXER_VTT_6100, TestSize.Level2)
515 {
516     OH_AVCodecBufferAttr attr;
517     const char* mimeType = nullptr;
518     const char *file = "/data/test/media/vtt_6100.vtt";
519     int fd = open(file, O_RDONLY);
520     int64_t size = GetFileSize(file);
521     cout << file << "----------------------" << fd << "---------" << size << endl;
522     source = OH_AVSource_CreateWithFD(fd, 0, size);
523     ASSERT_NE(source, nullptr);
524     demuxer = OH_AVDemuxer_CreateWithSource(source);
525     ASSERT_NE(demuxer, nullptr);
526     sourceFormat = OH_AVSource_GetSourceFormat(source);
527     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
528     ASSERT_NE(trackFormat, nullptr);
529     ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
530     ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_SUBTITLE_WEBVTT));
531     ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
532     ASSERT_EQ(1, g_trackCount);
533     ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
534     int tarckType = 0;
535     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
536     ASSERT_EQ(tarckType, MEDIA_TYPE_SUBTITLE);
537     while (true) {
538         ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
539         if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
540             cout << "   vtt is end !!!!!!!!!!!!!!!" << endl;
541             break;
542         }
543         uint8_t *data = OH_AVMemory_GetAddr(memory);
544         cout << "subtitle"<< "----------------" << data << "-----------------" << endl;
545     }
546     close(fd);
547 }
548 
549 /**
550  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1000
551  * @tc.name     : determine the orientation type of the video ROTATE_NONE.mp4
552  * @tc.desc     : function test
553  */
554 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1000, TestSize.Level0)
555 {
556     static OH_AVFormat *trackFormat = nullptr;
557     int32_t rotation = -1;
558     const char *file = "/data/test/media/rotation/ROTATE_NONE.mp4";
559     int fd = open(file, O_RDONLY);
560     int64_t size = GetFileSize(file);
561     source = OH_AVSource_CreateWithFD(fd, 0, size);
562     ASSERT_NE(source, nullptr);
563     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
564     ASSERT_NE(trackFormat, nullptr);
565     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
566     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
567     OH_AVFormat_Destroy(trackFormat);
568     close(fd);
569 }
570 
571 /**
572  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1001
573  * @tc.name     : determine the orientation type of the video ROTATE_90.mp4
574  * @tc.desc     : function test
575  */
576 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1001, TestSize.Level1)
577 {
578     static OH_AVFormat *trackFormat = nullptr;
579     int32_t rotation = -1;
580     const char *file = "/data/test/media/rotation/ROTATE_90.mp4";
581     int fd = open(file, O_RDONLY);
582     int64_t size = GetFileSize(file);
583     source = OH_AVSource_CreateWithFD(fd, 0, size);
584     ASSERT_NE(source, nullptr);
585     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
586     ASSERT_NE(trackFormat, nullptr);
587     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
588     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_90);
589     OH_AVFormat_Destroy(trackFormat);
590     close(fd);
591 }
592 
593 /**
594  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1002
595  * @tc.name     : determine the orientation type of the video ROTATE_180.mp4
596  * @tc.desc     : function test
597  */
598 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1002, TestSize.Level1)
599 {
600     static OH_AVFormat *trackFormat = nullptr;
601     int32_t rotation = -1;
602     const char *file = "/data/test/media/rotation/ROTATE_180.mp4";
603     int fd = open(file, O_RDONLY);
604     int64_t size = GetFileSize(file);
605     source = OH_AVSource_CreateWithFD(fd, 0, size);
606     ASSERT_NE(source, nullptr);
607     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
608     ASSERT_NE(trackFormat, nullptr);
609     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
610     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_180);
611     OH_AVFormat_Destroy(trackFormat);
612     close(fd);
613 }
614 
615 /**
616  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1003
617  * @tc.name     : determine the orientation type of the video ROTATE_270.mp4
618  * @tc.desc     : function test
619  */
620 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1003, TestSize.Level1)
621 {
622     static OH_AVFormat *trackFormat = nullptr;
623     int32_t rotation = -1;
624     const char *file = "/data/test/media/rotation/ROTATE_270.mp4";
625     int fd = open(file, O_RDONLY);
626     int64_t size = GetFileSize(file);
627     source = OH_AVSource_CreateWithFD(fd, 0, size);
628     ASSERT_NE(source, nullptr);
629     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
630     ASSERT_NE(trackFormat, nullptr);
631     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
632     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_270);
633     OH_AVFormat_Destroy(trackFormat);
634     close(fd);
635 }
636 
637 /**
638  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1004
639  * @tc.name     : determine the orientation type of the video FLIP_H.mp4
640  * @tc.desc     : function test
641  */
642 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1004, TestSize.Level2)
643 {
644     static OH_AVFormat *trackFormat = nullptr;
645     int32_t rotation = -1;
646     const char *file = "/data/test/media/rotation/FLIP_H.mp4";
647     int fd = open(file, O_RDONLY);
648     int64_t size = GetFileSize(file);
649     source = OH_AVSource_CreateWithFD(fd, 0, size);
650     ASSERT_NE(source, nullptr);
651     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
652     ASSERT_NE(trackFormat, nullptr);
653     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
654     ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_H);
655     OH_AVFormat_Destroy(trackFormat);
656     close(fd);
657 }
658 
659 /**
660  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1005
661  * @tc.name     : determine the orientation type of the video FLIP_V.mp4
662  * @tc.desc     : function test
663  */
664 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1005, TestSize.Level2)
665 {
666     static OH_AVFormat *trackFormat = nullptr;
667     int32_t rotation = -1;
668     const char *file = "/data/test/media/rotation/FLIP_V.mp4";
669     int fd = open(file, O_RDONLY);
670     int64_t size = GetFileSize(file);
671     source = OH_AVSource_CreateWithFD(fd, 0, size);
672     ASSERT_NE(source, nullptr);
673     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
674     ASSERT_NE(trackFormat, nullptr);
675     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
676     ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_V);
677     OH_AVFormat_Destroy(trackFormat);
678     close(fd);
679 }
680 
681 /**
682  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1006
683  * @tc.name     : determine the orientation type of the video FLIP_H_90.mp4
684  * @tc.desc     : function test
685  */
686 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1006, TestSize.Level2)
687 {
688     static OH_AVFormat *trackFormat = nullptr;
689     int32_t rotation = -1;
690     const char *file = "/data/test/media/rotation/FLIP_H_90.mp4";
691     int fd = open(file, O_RDONLY);
692     int64_t size = GetFileSize(file);
693     source = OH_AVSource_CreateWithFD(fd, 0, size);
694     ASSERT_NE(source, nullptr);
695     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
696     ASSERT_NE(trackFormat, nullptr);
697     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
698     ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_H_ROT90);
699     OH_AVFormat_Destroy(trackFormat);
700     close(fd);
701 }
702 
703 /**
704  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1007
705  * @tc.name     : determine the orientation type of the video FLIP_V_90.mp4
706  * @tc.desc     : function test
707  */
708 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1007, TestSize.Level2)
709 {
710     static OH_AVFormat *trackFormat = nullptr;
711     int32_t rotation = -1;
712     const char *file = "/data/test/media/rotation/FLIP_V_90.mp4";
713     int fd = open(file, O_RDONLY);
714     int64_t size = GetFileSize(file);
715     source = OH_AVSource_CreateWithFD(fd, 0, size);
716     ASSERT_NE(source, nullptr);
717     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
718     ASSERT_NE(trackFormat, nullptr);
719     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
720     ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_V_ROT90);
721     OH_AVFormat_Destroy(trackFormat);
722     close(fd);
723 }
724 
725 /**
726  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1008
727  * @tc.name     : determine the orientation type of the video FLIP_H_180.mp4
728  * @tc.desc     : function test
729  */
730 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1008, TestSize.Level2)
731 {
732     static OH_AVFormat *trackFormat = nullptr;
733     int32_t rotation = -1;
734     const char *file = "/data/test/media/rotation/FLIP_H_180.mp4";
735     int fd = open(file, O_RDONLY);
736     int64_t size = GetFileSize(file);
737     source = OH_AVSource_CreateWithFD(fd, 0, size);
738     ASSERT_NE(source, nullptr);
739     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
740     ASSERT_NE(trackFormat, nullptr);
741     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
742     ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_V || rotation == OHOS::MediaAVCodec::FLIP_H_ROT180);
743     OH_AVFormat_Destroy(trackFormat);
744     close(fd);
745 }
746 
747 /**
748  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1009
749  * @tc.name     : determine the orientation type of the video FLIP_V_180.mp4
750  * @tc.desc     : function test
751  */
752 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1009, TestSize.Level2)
753 {
754     static OH_AVFormat *trackFormat = nullptr;
755     int32_t rotation = -1;
756     const char *file = "/data/test/media/rotation/FLIP_V_180.mp4";
757     int fd = open(file, O_RDONLY);
758     int64_t size = GetFileSize(file);
759     source = OH_AVSource_CreateWithFD(fd, 0, size);
760     ASSERT_NE(source, nullptr);
761     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
762     ASSERT_NE(trackFormat, nullptr);
763     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
764     ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_H || rotation == OHOS::MediaAVCodec::FLIP_V_ROT180);
765     OH_AVFormat_Destroy(trackFormat);
766     close(fd);
767 }
768 
769 /**
770  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1010
771  * @tc.name     : determine the orientation type of the video FLIP_H_270.mp4
772  * @tc.desc     : function test
773  */
774 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1010, TestSize.Level2)
775 {
776     static OH_AVFormat *trackFormat = nullptr;
777     int32_t rotation = -1;
778     const char *file = "/data/test/media/rotation/FLIP_H_270.mp4";
779     int fd = open(file, O_RDONLY);
780     int64_t size = GetFileSize(file);
781     source = OH_AVSource_CreateWithFD(fd, 0, size);
782     ASSERT_NE(source, nullptr);
783     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
784     ASSERT_NE(trackFormat, nullptr);
785     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
786     ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_V_ROT90 || rotation == OHOS::MediaAVCodec::FLIP_H_ROT270);
787     OH_AVFormat_Destroy(trackFormat);
788     close(fd);
789 }
790 
791 /**
792  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1011
793  * @tc.name     : determine the orientation type of the video FLIP_V_270.mp4
794  * @tc.desc     : function test
795  */
796 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1011, TestSize.Level2)
797 {
798     static OH_AVFormat *trackFormat = nullptr;
799     int32_t rotation = -1;
800     const char *file = "/data/test/media/rotation/FLIP_V_270.mp4";
801     int fd = open(file, O_RDONLY);
802     int64_t size = GetFileSize(file);
803     source = OH_AVSource_CreateWithFD(fd, 0, size);
804     ASSERT_NE(source, nullptr);
805     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
806     ASSERT_NE(trackFormat, nullptr);
807     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
808     ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_H_ROT90 || rotation == OHOS::MediaAVCodec::FLIP_V_ROT270);
809     OH_AVFormat_Destroy(trackFormat);
810     close(fd);
811 }
812 
813 /**
814  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1012
815  * @tc.name     : determine the orientation type of the video INVALID.mp4
816  * @tc.desc     : function test
817  */
818 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1012, TestSize.Level2)
819 {
820     static OH_AVFormat *trackFormat = nullptr;
821     int32_t rotation = -1;
822     const char *file = "/data/test/media/rotation/INVALID.mp4";
823     int fd = open(file, O_RDONLY);
824     int64_t size = GetFileSize(file);
825     source = OH_AVSource_CreateWithFD(fd, 0, size);
826     ASSERT_NE(source, nullptr);
827     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
828     ASSERT_NE(trackFormat, nullptr);
829     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
830     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
831     OH_AVFormat_Destroy(trackFormat);
832     close(fd);
833 }
834 
835 /**
836  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1013
837  * @tc.name     : determine the orientation type of the video AV_ROTATE_NONE.mp4
838  * @tc.desc     : function test
839  */
840 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1013, TestSize.Level0)
841 {
842     static OH_AVFormat *trackFormat = nullptr;
843     int32_t rotation = -1;
844     const char *file = "/data/test/media/rotation/AV_ROTATE_NONE.mp4";
845     int fd = open(file, O_RDONLY);
846     int64_t size = GetFileSize(file);
847     source = OH_AVSource_CreateWithFD(fd, 0, size);
848     ASSERT_NE(source, nullptr);
849     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
850     ASSERT_NE(trackFormat, nullptr);
851     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
852     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
853     OH_AVFormat_Destroy(trackFormat);
854     close(fd);
855 }
856 
857 /**
858  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1014
859  * @tc.name     : determine the orientation type of the video AV_ROTATE_90.mp4
860  * @tc.desc     : function test
861  */
862 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1014, TestSize.Level1)
863 {
864     static OH_AVFormat *trackFormat = nullptr;
865     int32_t rotation = -1;
866     const char *file = "/data/test/media/rotation/AV_ROTATE_90.mp4";
867     int fd = open(file, O_RDONLY);
868     int64_t size = GetFileSize(file);
869     source = OH_AVSource_CreateWithFD(fd, 0, size);
870     ASSERT_NE(source, nullptr);
871     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
872     ASSERT_NE(trackFormat, nullptr);
873     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
874     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_90);
875     OH_AVFormat_Destroy(trackFormat);
876     close(fd);
877 }
878 
879 /**
880  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1015
881  * @tc.name     : determine the orientation type of the video AV_ROTATE_180.mp4
882  * @tc.desc     : function test
883  */
884 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1015, TestSize.Level1)
885 {
886     static OH_AVFormat *trackFormat = nullptr;
887     int32_t rotation = -1;
888     const char *file = "/data/test/media/rotation/AV_ROTATE_180.mp4";
889     int fd = open(file, O_RDONLY);
890     int64_t size = GetFileSize(file);
891     source = OH_AVSource_CreateWithFD(fd, 0, size);
892     ASSERT_NE(source, nullptr);
893     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
894     ASSERT_NE(trackFormat, nullptr);
895     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
896     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_180);
897     OH_AVFormat_Destroy(trackFormat);
898     close(fd);
899 }
900 
901 /**
902  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1016
903  * @tc.name     : determine the orientation type of the video AV_ROTATE_270.mp4
904  * @tc.desc     : function test
905  */
906 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1016, TestSize.Level1)
907 {
908     static OH_AVFormat *trackFormat = nullptr;
909     int32_t rotation = -1;
910     const char *file = "/data/test/media/rotation/AV_ROTATE_270.mp4";
911     int fd = open(file, O_RDONLY);
912     int64_t size = GetFileSize(file);
913     source = OH_AVSource_CreateWithFD(fd, 0, size);
914     ASSERT_NE(source, nullptr);
915     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
916     ASSERT_NE(trackFormat, nullptr);
917     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
918     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_270);
919     OH_AVFormat_Destroy(trackFormat);
920     close(fd);
921 }
922 
923 /**
924  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1017
925  * @tc.name     : determine the orientation type of the video AV_FLIP_H.mp4
926  * @tc.desc     : function test
927  */
928 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1017, TestSize.Level2)
929 {
930     static OH_AVFormat *trackFormat = nullptr;
931     int32_t rotation = -1;
932     const char *file = "/data/test/media/rotation/AV_FLIP_H.mp4";
933     int fd = open(file, O_RDONLY);
934     int64_t size = GetFileSize(file);
935     source = OH_AVSource_CreateWithFD(fd, 0, size);
936     ASSERT_NE(source, nullptr);
937     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
938     ASSERT_NE(trackFormat, nullptr);
939     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
940     ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_H);
941     OH_AVFormat_Destroy(trackFormat);
942     close(fd);
943 }
944 
945 /**
946  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1018
947  * @tc.name     : determine the orientation type of the video AV_FLIP_V.mp4
948  * @tc.desc     : function test
949  */
950 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1018, TestSize.Level2)
951 {
952     static OH_AVFormat *trackFormat = nullptr;
953     int32_t rotation = -1;
954     const char *file = "/data/test/media/rotation/AV_FLIP_V.mp4";
955     int fd = open(file, O_RDONLY);
956     int64_t size = GetFileSize(file);
957     source = OH_AVSource_CreateWithFD(fd, 0, size);
958     ASSERT_NE(source, nullptr);
959     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
960     ASSERT_NE(trackFormat, nullptr);
961     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
962     ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_V);
963     OH_AVFormat_Destroy(trackFormat);
964     close(fd);
965 }
966 
967 /**
968  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1019
969  * @tc.name     : determine the orientation type of the video AV_FLIP_H_90.mp4
970  * @tc.desc     : function test
971  */
972 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1019, TestSize.Level2)
973 {
974     static OH_AVFormat *trackFormat = nullptr;
975     int32_t rotation = -1;
976     const char *file = "/data/test/media/rotation/AV_FLIP_H_90.mp4";
977     int fd = open(file, O_RDONLY);
978     int64_t size = GetFileSize(file);
979     source = OH_AVSource_CreateWithFD(fd, 0, size);
980     ASSERT_NE(source, nullptr);
981     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
982     ASSERT_NE(trackFormat, nullptr);
983     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
984     ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_H_ROT90);
985     OH_AVFormat_Destroy(trackFormat);
986     close(fd);
987 }
988 
989 /**
990  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1020
991  * @tc.name     : determine the orientation type of the video AV_FLIP_V_90.mp4
992  * @tc.desc     : function test
993  */
994 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1020, TestSize.Level2)
995 {
996     static OH_AVFormat *trackFormat = nullptr;
997     int32_t rotation = -1;
998     const char *file = "/data/test/media/rotation/AV_FLIP_V_90.mp4";
999     int fd = open(file, O_RDONLY);
1000     int64_t size = GetFileSize(file);
1001     source = OH_AVSource_CreateWithFD(fd, 0, size);
1002     ASSERT_NE(source, nullptr);
1003     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1004     ASSERT_NE(trackFormat, nullptr);
1005     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1006     ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_V_ROT90);
1007     OH_AVFormat_Destroy(trackFormat);
1008     close(fd);
1009 }
1010 
1011 /**
1012  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1021
1013  * @tc.name     : determine the orientation type of the video AV_FLIP_H_180.mp4
1014  * @tc.desc     : function test
1015  */
1016 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1021, TestSize.Level2)
1017 {
1018     static OH_AVFormat *trackFormat = nullptr;
1019     int32_t rotation = -1;
1020     const char *file = "/data/test/media/rotation/AV_FLIP_H_180.mp4";
1021     int fd = open(file, O_RDONLY);
1022     int64_t size = GetFileSize(file);
1023     source = OH_AVSource_CreateWithFD(fd, 0, size);
1024     ASSERT_NE(source, nullptr);
1025     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1026     ASSERT_NE(trackFormat, nullptr);
1027     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1028     ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_V || rotation == OHOS::MediaAVCodec::FLIP_H_ROT180);
1029     OH_AVFormat_Destroy(trackFormat);
1030     close(fd);
1031 }
1032 
1033 /**
1034  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1022
1035  * @tc.name     : determine the orientation type of the video AV_FLIP_V_180.mp4
1036  * @tc.desc     : function test
1037  */
1038 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1022, TestSize.Level2)
1039 {
1040     static OH_AVFormat *trackFormat = nullptr;
1041     int32_t rotation = -1;
1042     const char *file = "/data/test/media/rotation/AV_FLIP_V_180.mp4";
1043     int fd = open(file, O_RDONLY);
1044     int64_t size = GetFileSize(file);
1045     source = OH_AVSource_CreateWithFD(fd, 0, size);
1046     ASSERT_NE(source, nullptr);
1047     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1048     ASSERT_NE(trackFormat, nullptr);
1049     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1050     ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_H || rotation == OHOS::MediaAVCodec::FLIP_V_ROT180);
1051     OH_AVFormat_Destroy(trackFormat);
1052     close(fd);
1053 }
1054 
1055 /**
1056  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1023
1057  * @tc.name     : determine the orientation type of the video AV_FLIP_H_270.mp4
1058  * @tc.desc     : function test
1059  */
1060 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1023, TestSize.Level2)
1061 {
1062     static OH_AVFormat *trackFormat = nullptr;
1063     int32_t rotation = -1;
1064     const char *file = "/data/test/media/rotation/AV_FLIP_H_270.mp4";
1065     int fd = open(file, O_RDONLY);
1066     int64_t size = GetFileSize(file);
1067     source = OH_AVSource_CreateWithFD(fd, 0, size);
1068     ASSERT_NE(source, nullptr);
1069     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1070     ASSERT_NE(trackFormat, nullptr);
1071     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1072     ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_V_ROT90 || rotation == OHOS::MediaAVCodec::FLIP_H_ROT270);
1073     OH_AVFormat_Destroy(trackFormat);
1074     close(fd);
1075 }
1076 
1077 /**
1078  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1024
1079  * @tc.name     : determine the orientation type of the video AV_FLIP_V_270.mp4
1080  * @tc.desc     : function test
1081  */
1082 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1024, TestSize.Level2)
1083 {
1084     static OH_AVFormat *trackFormat = nullptr;
1085     int32_t rotation = -1;
1086     const char *file = "/data/test/media/rotation/AV_FLIP_V_270.mp4";
1087     int fd = open(file, O_RDONLY);
1088     int64_t size = GetFileSize(file);
1089     source = OH_AVSource_CreateWithFD(fd, 0, size);
1090     ASSERT_NE(source, nullptr);
1091     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1092     ASSERT_NE(trackFormat, nullptr);
1093     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1094     ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_H_ROT90 || rotation == OHOS::MediaAVCodec::FLIP_V_ROT270);
1095     OH_AVFormat_Destroy(trackFormat);
1096     close(fd);
1097 }
1098 
1099 /**
1100  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1025
1101  * @tc.name     : determine the orientation type of the video AV_INVALID.mp4
1102  * @tc.desc     : function test
1103  */
1104 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1025, TestSize.Level2)
1105 {
1106     static OH_AVFormat *trackFormat = nullptr;
1107     int32_t rotation = -1;
1108     const char *file = "/data/test/media/rotation/AV_INVALID.mp4";
1109     int fd = open(file, O_RDONLY);
1110     int64_t size = GetFileSize(file);
1111     source = OH_AVSource_CreateWithFD(fd, 0, size);
1112     ASSERT_NE(source, nullptr);
1113     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1114     ASSERT_NE(trackFormat, nullptr);
1115     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1116     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
1117     OH_AVFormat_Destroy(trackFormat);
1118     close(fd);
1119 }
1120 
1121 /**
1122  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1026
1123  * @tc.name     : determine the orientation type of the video UNDEFINED_FLV.flv
1124  * @tc.desc     : function test
1125  */
1126 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1026, TestSize.Level3)
1127 {
1128     static OH_AVFormat *trackFormat = nullptr;
1129     int32_t rotation = 0;
1130     const char *file = "/data/test/media/rotation/UNDEFINED_FLV.flv";
1131     int fd = open(file, O_RDONLY);
1132     int64_t size = GetFileSize(file);
1133     source = OH_AVSource_CreateWithFD(fd, 0, size);
1134     ASSERT_NE(source, nullptr);
1135     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1136     ASSERT_NE(trackFormat, nullptr);
1137     ASSERT_FALSE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1138     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
1139     OH_AVFormat_Destroy(trackFormat);
1140     close(fd);
1141 }
1142 
1143 /**
1144  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1027
1145  * @tc.name     : determine the orientation type of the video UNDEFINED_fmp4.mp4
1146  * @tc.desc     : function test
1147  */
1148 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1027, TestSize.Level3)
1149 {
1150     static OH_AVFormat *trackFormat = nullptr;
1151     int32_t rotation = 0;
1152     const char *file = "/data/test/media/rotation/UNDEFINED_FMP4.mp4";
1153     int fd = open(file, O_RDONLY);
1154     int64_t size = GetFileSize(file);
1155     source = OH_AVSource_CreateWithFD(fd, 0, size);
1156     ASSERT_NE(source, nullptr);
1157     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1158     ASSERT_NE(trackFormat, nullptr);
1159     ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1160     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
1161     OH_AVFormat_Destroy(trackFormat);
1162     close(fd);
1163 }
1164 
1165 /**
1166  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1028
1167  * @tc.name     : determine the orientation type of the video UNDEFINED_MKV.mkv
1168  * @tc.desc     : function test
1169  */
1170 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1028, TestSize.Level3)
1171 {
1172     static OH_AVFormat *trackFormat = nullptr;
1173     int32_t rotation = 0;
1174     const char *file = "/data/test/media/rotation/UNDEFINED_MKV.mkv";
1175     int fd = open(file, O_RDONLY);
1176     int64_t size = GetFileSize(file);
1177     source = OH_AVSource_CreateWithFD(fd, 0, size);
1178     ASSERT_NE(source, nullptr);
1179     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1180     ASSERT_NE(trackFormat, nullptr);
1181     ASSERT_FALSE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1182     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
1183     OH_AVFormat_Destroy(trackFormat);
1184     close(fd);
1185 }
1186 
1187 /**
1188  * @tc.number   : DEMUXER_ORIENTATIONTYPE_1029
1189  * @tc.name     : determine the orientation type of the video UNDEFINED_TS.ts
1190  * @tc.desc     : function test
1191  */
1192 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1029, TestSize.Level3)
1193 {
1194     static OH_AVFormat *trackFormat = nullptr;
1195     int32_t rotation = 0;
1196     const char *file = "/data/test/media/rotation/UNDEFINED_TS.ts";
1197     int fd = open(file, O_RDONLY);
1198     int64_t size = GetFileSize(file);
1199     source = OH_AVSource_CreateWithFD(fd, 0, size);
1200     ASSERT_NE(source, nullptr);
1201     trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1202     ASSERT_NE(trackFormat, nullptr);
1203     ASSERT_FALSE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1204     ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
1205     OH_AVFormat_Destroy(trackFormat);
1206     close(fd);
1207 }