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
OpenFile(const char * fileName,int fd,OH_AVSource ** src,OH_AVDemuxer ** audioDemuxer)121 static void OpenFile(const char *fileName, int fd, OH_AVSource **src, OH_AVDemuxer **audioDemuxer)
122 {
123 int64_t size = GetFileSize(fileName);
124 cout << fileName << "----------------------" << fd << "---------" << size << endl;
125 *src = OH_AVSource_CreateWithFD(fd, 0, size);
126 ASSERT_NE(*src, nullptr);
127
128 *audioDemuxer = OH_AVDemuxer_CreateWithSource(*src);
129 ASSERT_NE(*audioDemuxer, nullptr);
130 }
131
CheckTrackCount(OH_AVFormat ** srcFormat,OH_AVSource * src,int32_t * trackCount,int trackNum)132 static void CheckTrackCount(OH_AVFormat **srcFormat, OH_AVSource *src, int32_t *trackCount, int trackNum)
133 {
134 *srcFormat = OH_AVSource_GetSourceFormat(src);
135 ASSERT_TRUE(OH_AVFormat_GetIntValue(*srcFormat, OH_MD_KEY_TRACK_COUNT, trackCount));
136 ASSERT_EQ(trackNum, *trackCount);
137 }
138
CheckChannelCount(OH_AVFormat ** trkFormat,OH_AVSource * src,int channelNum)139 static void CheckChannelCount(OH_AVFormat **trkFormat, OH_AVSource *src, int channelNum)
140 {
141 int cc = 0;
142 *trkFormat = OH_AVSource_GetTrackFormat(src, 0);
143 ASSERT_NE(trkFormat, nullptr);
144 ASSERT_TRUE(OH_AVFormat_GetIntValue(*trkFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, &cc));
145 ASSERT_EQ(channelNum, cc);
146 }
147
CheckTrackSelect(int32_t trackCount,OH_AVDemuxer * audioDemuxer)148 static void CheckTrackSelect(int32_t trackCount, OH_AVDemuxer *audioDemuxer)
149 {
150 for (int32_t index = 0; index < g_trackCount; index++) {
151 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
152 }
153 }
154
CountAudioFrames(OH_AVDemuxer * audioDemuxer,OH_AVMemory * mem,int32_t trackCount,int audioFrameNum,int audioKeyNum)155 static void CountAudioFrames(OH_AVDemuxer *audioDemuxer, OH_AVMemory *mem,
156 int32_t trackCount, int audioFrameNum, int audioKeyNum)
157 {
158 int audioFrame = 0;
159 int keyCount = 0;
160 bool audioIsEnd = false;
161 OH_AVCodecBufferAttr attr;
162
163 while (!audioIsEnd) {
164 for (int32_t index = 0; index < trackCount; index++) {
165 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(audioDemuxer, index, mem, &attr));
166 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
167 audioIsEnd = true;
168 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
169 continue;
170 }
171
172 audioFrame++;
173 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
174 keyCount++;
175 }
176 }
177 }
178 ASSERT_EQ(audioFrame, audioFrameNum);
179 ASSERT_EQ(keyCount, audioKeyNum);
180 }
181
182 /**
183 * @tc.number : SUB_MEDIA_DEMUXER_VTT_4800
184 * @tc.name : create vtt demuxer with file and read
185 * @tc.desc : function test
186 */
187 HWTEST_F(DemuxerFunc2NdkTest, SUB_MEDIA_DEMUXER_VTT_4800, TestSize.Level0)
188 {
189 OH_AVCodecBufferAttr attr;
190 const char* mimeType = nullptr;
191 int vttIndex = 1;
192 int vttSubtitle = 0;
193 const char *file = "/data/test/media/webvtt_test.vtt";
194 int fd = open(file, O_RDONLY);
195 int64_t size = GetFileSize(file);
196 cout << file << "----------------------" << fd << "---------" << size << endl;
197 source = OH_AVSource_CreateWithFD(fd, 0, size);
198 ASSERT_NE(source, nullptr);
199 demuxer = OH_AVDemuxer_CreateWithSource(source);
200 ASSERT_NE(demuxer, nullptr);
201 sourceFormat = OH_AVSource_GetSourceFormat(source);
202 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
203 ASSERT_NE(trackFormat, nullptr);
204 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
205 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_SUBTITLE_WEBVTT));
206 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
207 ASSERT_EQ(1, g_trackCount);
208 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
209 int tarckType = 0;
210 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
211 ASSERT_EQ(tarckType, MEDIA_TYPE_SUBTITLE);
212 int64_t starttime = 0;
213 ASSERT_FALSE(OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_TRACK_START_TIME, &starttime));
214 while (true) {
215 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
216 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
217 cout << " vtt is end !!!!!!!!!!!!!!!" << endl;
218 break;
219 }
220 uint8_t *data = OH_AVMemory_GetAddr(memory);
221 vttSubtitle = atoi(reinterpret_cast<const char*>(data));
222 cout << "subtitle" << "----------------" << vttSubtitle << "-----------------" << endl;
223 ASSERT_EQ(vttSubtitle, vttIndex);
224 vttIndex++;
225 }
226 close(fd);
227 fd = -1;
228 }
229
230 /**
231 * @tc.number : SUB_MEDIA_DEMUXER_VTT_4900
232 * @tc.name : create vtt demuxer with file and forward back seek+read
233 * @tc.desc : function test
234 */
235 HWTEST_F(DemuxerFunc2NdkTest, SUB_MEDIA_DEMUXER_VTT_4900, TestSize.Level0)
236 {
237 OH_AVCodecBufferAttr attr;
238 const char* mimeType = nullptr;
239 int vttSubtitle = 0;
240 uint8_t *data = nullptr;
241 const char *file = "/data/test/media/webvtt_test.vtt";
242 int fd = open(file, O_RDONLY);
243 int64_t size = GetFileSize(file);
244 source = OH_AVSource_CreateWithFD(fd, 0, size);
245 ASSERT_NE(source, nullptr);
246 demuxer = OH_AVDemuxer_CreateWithSource(source);
247 ASSERT_NE(demuxer, nullptr);
248 sourceFormat = OH_AVSource_GetSourceFormat(source);
249 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
250 ASSERT_NE(trackFormat, nullptr);
251 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
252 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_SUBTITLE_WEBVTT));
253 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
254 ASSERT_EQ(1, g_trackCount);
255 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
256 int tarckType = 0;
257 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
258 ASSERT_EQ(tarckType, MEDIA_TYPE_SUBTITLE);
259 for (int index = 0; index < 5; index++) {
260 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
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 ASSERT_EQ(vttSubtitle, VTTBACK);
267 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, VTTSEEKFORWARD, SEEK_MODE_CLOSEST_SYNC));
268 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
269 data = OH_AVMemory_GetAddr(memory);
270 vttSubtitle = atoi(reinterpret_cast<const char*>(data));
271 int vttIndex = VTTFORWARD;
272 ASSERT_EQ(vttSubtitle, VTTFORWARD);
273 while (true) {
274 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
275 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
276 break;
277 }
278 data = OH_AVMemory_GetAddr(memory);
279 vttSubtitle = atoi(reinterpret_cast<const char*>(data));
280 vttIndex++;
281 ASSERT_EQ(vttSubtitle, vttIndex);
282 }
283 close(fd);
284 fd = -1;
285 }
286
287 /**
288 * @tc.number : SUB_MEDIA_DEMUXER_VTT_5000
289 * @tc.name : create vtt demuxer with file and back seek+read
290 * @tc.desc : function test
291 */
292 HWTEST_F(DemuxerFunc2NdkTest, SUB_MEDIA_DEMUXER_VTT_5000, TestSize.Level0)
293 {
294 OH_AVCodecBufferAttr attr;
295 const char* mimeType = nullptr;
296 int vttIndex = 1;
297 int vttSubtitle = 0;
298 uint8_t *data = nullptr;
299 const char *file = "/data/test/media/webvtt_test.vtt";
300 int fd = open(file, O_RDONLY);
301 int64_t size = GetFileSize(file);
302 source = OH_AVSource_CreateWithFD(fd, 0, size);
303 ASSERT_NE(source, nullptr);
304 demuxer = OH_AVDemuxer_CreateWithSource(source);
305 ASSERT_NE(demuxer, nullptr);
306 sourceFormat = OH_AVSource_GetSourceFormat(source);
307 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
308 ASSERT_NE(trackFormat, nullptr);
309 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
310 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_SUBTITLE_WEBVTT));
311 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
312 ASSERT_EQ(1, g_trackCount);
313 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
314 int tarckType = 0;
315 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
316 ASSERT_EQ(tarckType, MEDIA_TYPE_SUBTITLE);
317 for (int index = 0; index < 5; index++) {
318 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
319 data = OH_AVMemory_GetAddr(memory);
320 vttSubtitle = atoi(reinterpret_cast<const char*>(data));
321 ASSERT_EQ(vttSubtitle, vttIndex);
322 vttIndex++;
323 }
324 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, VTTSEEKBACK, SEEK_MODE_CLOSEST_SYNC));
325 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
326 data = OH_AVMemory_GetAddr(memory);
327 vttSubtitle = atoi(reinterpret_cast<const char*>(data));
328 vttIndex = 4;
329 ASSERT_EQ(vttSubtitle, vttIndex);
330 while (true) {
331 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
332 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
333 break;
334 }
335 data = OH_AVMemory_GetAddr(memory);
336 vttSubtitle = atoi(reinterpret_cast<const char*>(data));
337 vttIndex++;
338 ASSERT_EQ(vttSubtitle, vttIndex);
339 }
340 close(fd);
341 fd = -1;
342 }
343
344 /**
345 * @tc.number : SUB_MEDIA_DEMUXER_VTT_5100
346 * @tc.name : create vtt demuxer with file and forward seek+read
347 * @tc.desc : function test
348 */
349 HWTEST_F(DemuxerFunc2NdkTest, SUB_MEDIA_DEMUXER_VTT_5100, TestSize.Level0)
350 {
351 OH_AVCodecBufferAttr attr;
352 const char* mimeType = nullptr;
353 int vttIndex = 1;
354 int vttSubtitle = 0;
355 uint8_t *data = nullptr;
356 const char *file = "/data/test/media/webvtt_test.vtt";
357 int fd = open(file, O_RDONLY);
358 int64_t size = GetFileSize(file);
359 source = OH_AVSource_CreateWithFD(fd, 0, size);
360 ASSERT_NE(source, nullptr);
361 demuxer = OH_AVDemuxer_CreateWithSource(source);
362 ASSERT_NE(demuxer, nullptr);
363 sourceFormat = OH_AVSource_GetSourceFormat(source);
364 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
365 ASSERT_NE(trackFormat, nullptr);
366 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
367 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_SUBTITLE_WEBVTT));
368 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
369 ASSERT_EQ(1, g_trackCount);
370 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
371 int tarckType = 0;
372 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
373 ASSERT_EQ(tarckType, MEDIA_TYPE_SUBTITLE);
374 for (int index = 0; index < 5; index++) {
375 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
376 data = OH_AVMemory_GetAddr(memory);
377 vttSubtitle = atoi(reinterpret_cast<const char*>(data));
378 ASSERT_EQ(vttSubtitle, vttIndex);
379 vttIndex++;
380 }
381 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, VTTSEEKFORWARD, SEEK_MODE_CLOSEST_SYNC));
382 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
383 data = OH_AVMemory_GetAddr(memory);
384 vttSubtitle = atoi(reinterpret_cast<const char*>(data));
385 vttIndex = 7;
386 ASSERT_EQ(vttSubtitle, vttIndex);
387 while (true) {
388 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
389 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
390 break;
391 }
392 data = OH_AVMemory_GetAddr(memory);
393 vttSubtitle = atoi(reinterpret_cast<const char*>(data));
394 vttIndex++;
395 ASSERT_EQ(vttSubtitle, vttIndex);
396 }
397 close(fd);
398 fd = -1;
399 }
400
401 /**
402 * @tc.number : SUB_MEDIA_DEMUXER_VTT_5600
403 * @tc.name : create vtt demuxer with error file -- no empty paragraphs
404 * @tc.desc : function test
405 */
406 HWTEST_F(DemuxerFunc2NdkTest, SUB_MEDIA_DEMUXER_VTT_5600, TestSize.Level2)
407 {
408 OH_AVCodecBufferAttr attr;
409 const char* mimeType = nullptr;
410 const char *file = "/data/test/media/vtt_5600.vtt";
411 int fd = open(file, O_RDONLY);
412 int64_t size = GetFileSize(file);
413 cout << file << "----------------------" << fd << "---------" << size << endl;
414 source = OH_AVSource_CreateWithFD(fd, 0, size);
415 ASSERT_NE(source, nullptr);
416 demuxer = OH_AVDemuxer_CreateWithSource(source);
417 ASSERT_NE(demuxer, nullptr);
418 sourceFormat = OH_AVSource_GetSourceFormat(source);
419 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
420 ASSERT_NE(trackFormat, nullptr);
421 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
422 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_SUBTITLE_WEBVTT));
423 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
424 ASSERT_EQ(1, g_trackCount);
425 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
426 int tarckType = 0;
427 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
428 ASSERT_EQ(tarckType, MEDIA_TYPE_SUBTITLE);
429 while (true) {
430 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
431 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
432 cout << " vtt is end !!!!!!!!!!!!!!!" << endl;
433 break;
434 }
435 uint8_t *data = OH_AVMemory_GetAddr(memory);
436 cout << "subtitle"<< "----------------" << data << "-----------------" << endl;
437 }
438 close(fd);
439 fd = -1;
440 }
441
442 /**
443 * @tc.number : SUB_MEDIA_DEMUXER_VTT_5700
444 * @tc.name : create vtt demuxer with error file -- subtitle sequence error
445 * @tc.desc : function test
446 */
447 HWTEST_F(DemuxerFunc2NdkTest, SUB_MEDIA_DEMUXER_VTT_5700, TestSize.Level2)
448 {
449 OH_AVCodecBufferAttr attr;
450 const char* mimeType = nullptr;
451 const char *file = "/data/test/media/vtt_5700.vtt";
452 int fd = open(file, O_RDONLY);
453 int64_t size = GetFileSize(file);
454 cout << file << "----------------------" << fd << "---------" << size << endl;
455 source = OH_AVSource_CreateWithFD(fd, 0, size);
456 ASSERT_NE(source, nullptr);
457 demuxer = OH_AVDemuxer_CreateWithSource(source);
458 ASSERT_NE(demuxer, nullptr);
459 sourceFormat = OH_AVSource_GetSourceFormat(source);
460 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
461 ASSERT_NE(trackFormat, nullptr);
462 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
463 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_SUBTITLE_WEBVTT));
464 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
465 ASSERT_EQ(1, g_trackCount);
466 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
467 int tarckType = 0;
468 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
469 ASSERT_EQ(tarckType, MEDIA_TYPE_SUBTITLE);
470 while (true) {
471 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
472 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
473 cout << " vtt is end !!!!!!!!!!!!!!!" << endl;
474 break;
475 }
476 uint8_t *data = OH_AVMemory_GetAddr(memory);
477 cout << "subtitle" << "----------------" << data << "-----------------" << endl;
478 }
479 close(fd);
480 fd = -1;
481 }
482
483 /**
484 * @tc.number : SUB_MEDIA_DEMUXER_VTT_5800
485 * @tc.name : create vtt demuxer with error file -- timeline format error null
486 * @tc.desc : function test
487 */
488 HWTEST_F(DemuxerFunc2NdkTest, SUB_MEDIA_DEMUXER_VTT_5800, TestSize.Level2)
489 {
490 OH_AVCodecBufferAttr attr;
491 const char *file = "/data/test/media/vtt_5800.vtt";
492 int fd = open(file, O_RDONLY);
493 int64_t size = GetFileSize(file);
494 cout << file << "----------------------" << fd << "---------" << size << endl;
495 source = OH_AVSource_CreateWithFD(fd, 0, size);
496 demuxer = OH_AVDemuxer_CreateWithSource(source);
497 sourceFormat = OH_AVSource_GetSourceFormat(source);
498 OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount);
499 OH_AVDemuxer_SelectTrackByID(demuxer, 0);
500 int tarckType = 0;
501 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
502 ASSERT_NE(trackFormat, nullptr);
503 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
504 ASSERT_EQ(tarckType, MEDIA_TYPE_SUBTITLE);
505 OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr);
506 uint8_t *data = OH_AVMemory_GetAddr(memory);
507 cout << "subtitle"<< "----------------" << data << "-----------------" << endl;
508 close(fd);
509 fd = -1;
510 }
511
512 /**
513 * @tc.number : SUB_MEDIA_DEMUXER_VTT_5900
514 * @tc.name : create vtt demuxer with error file -- subtitle is empty
515 * @tc.desc : function test
516 */
517 HWTEST_F(DemuxerFunc2NdkTest, SUB_MEDIA_DEMUXER_VTT_5900, TestSize.Level2)
518 {
519 OH_AVCodecBufferAttr attr;
520 const char* mimeType = nullptr;
521 const char *file = "/data/test/media/vtt_5900.vtt";
522 int fd = open(file, O_RDONLY);
523 int64_t size = GetFileSize(file);
524 cout << file << "----------------------" << fd << "---------" << size << endl;
525 source = OH_AVSource_CreateWithFD(fd, 0, size);
526 ASSERT_NE(source, nullptr);
527 demuxer = OH_AVDemuxer_CreateWithSource(source);
528 ASSERT_NE(demuxer, nullptr);
529 sourceFormat = OH_AVSource_GetSourceFormat(source);
530 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
531 ASSERT_NE(trackFormat, nullptr);
532 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
533 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_SUBTITLE_WEBVTT));
534 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
535 ASSERT_EQ(1, g_trackCount);
536 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
537 int tarckType = 0;
538 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
539 ASSERT_EQ(tarckType, MEDIA_TYPE_SUBTITLE);
540 while (true) {
541 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
542 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
543 cout << " vtt is end !!!!!!!!!!!!!!!" << endl;
544 break;
545 }
546 uint8_t *data = OH_AVMemory_GetAddr(memory);
547 cout << "subtitle"<< "----------------" << data << "-----------------" << endl;
548 }
549 close(fd);
550 fd = -1;
551 }
552
553 /**
554 * @tc.number : SUB_MEDIA_DEMUXER_VTT_6000
555 * @tc.name : create vtt demuxer with error file -- vtt file is empty
556 * @tc.desc : function test
557 * fail
558 */
559 HWTEST_F(DemuxerFunc2NdkTest, SUB_MEDIA_DEMUXER_VTT_6000, TestSize.Level2)
560 {
561 OH_AVCodecBufferAttr attr;
562 const char *file = "/data/test/media/vtt_6000.vtt";
563 int fd = open(file, O_RDONLY);
564 int64_t size = GetFileSize(file);
565 cout << file << "----------------------" << fd << "---------" << size << endl;
566 source = OH_AVSource_CreateWithFD(fd, 0, size);
567 if (source) {
568 demuxer = OH_AVDemuxer_CreateWithSource(source);
569 ASSERT_NE(demuxer, nullptr);
570 sourceFormat = OH_AVSource_GetSourceFormat(source);
571 ASSERT_NE(sourceFormat, nullptr);
572 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
573 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
574 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
575 uint8_t *data = OH_AVMemory_GetAddr(memory);
576 cout << "subtitle"<< "----------------" << data << "-----------------" << endl;
577 }
578 close(fd);
579 fd = -1;
580 }
581
582 /**
583 * @tc.number : SUB_MEDIA_DEMUXER_VTT_6100
584 * @tc.name : create vtt demuxer with error file -- alternating Up and Down Times
585 * @tc.desc : function test
586 */
587 HWTEST_F(DemuxerFunc2NdkTest, SUB_MEDIA_DEMUXER_VTT_6100, TestSize.Level2)
588 {
589 OH_AVCodecBufferAttr attr;
590 const char* mimeType = nullptr;
591 const char *file = "/data/test/media/vtt_6100.vtt";
592 int fd = open(file, O_RDONLY);
593 int64_t size = GetFileSize(file);
594 cout << file << "----------------------" << fd << "---------" << size << endl;
595 source = OH_AVSource_CreateWithFD(fd, 0, size);
596 ASSERT_NE(source, nullptr);
597 demuxer = OH_AVDemuxer_CreateWithSource(source);
598 ASSERT_NE(demuxer, nullptr);
599 sourceFormat = OH_AVSource_GetSourceFormat(source);
600 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
601 ASSERT_NE(trackFormat, nullptr);
602 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
603 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_SUBTITLE_WEBVTT));
604 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
605 ASSERT_EQ(1, g_trackCount);
606 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
607 int tarckType = 0;
608 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
609 ASSERT_EQ(tarckType, MEDIA_TYPE_SUBTITLE);
610 while (true) {
611 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
612 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
613 cout << " vtt is end !!!!!!!!!!!!!!!" << endl;
614 break;
615 }
616 uint8_t *data = OH_AVMemory_GetAddr(memory);
617 cout << "subtitle"<< "----------------" << data << "-----------------" << endl;
618 }
619 close(fd);
620 fd = -1;
621 }
622
623 /**
624 * @tc.number : DEMUXER_ORIENTATIONTYPE_1000
625 * @tc.name : determine the orientation type of the video ROTATE_NONE.mp4
626 * @tc.desc : function test
627 */
628 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1000, TestSize.Level0)
629 {
630 static OH_AVFormat *trackFormat = nullptr;
631 int32_t rotation = -1;
632 const char *file = "/data/test/media/rotation/ROTATE_NONE.mp4";
633 int fd = open(file, O_RDONLY);
634 int64_t size = GetFileSize(file);
635 source = OH_AVSource_CreateWithFD(fd, 0, size);
636 ASSERT_NE(source, nullptr);
637 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
638 ASSERT_NE(trackFormat, nullptr);
639 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
640 ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
641 OH_AVFormat_Destroy(trackFormat);
642 close(fd);
643 fd = -1;
644 }
645
646 /**
647 * @tc.number : DEMUXER_ORIENTATIONTYPE_1001
648 * @tc.name : determine the orientation type of the video ROTATE_90.mp4
649 * @tc.desc : function test
650 */
651 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1001, TestSize.Level1)
652 {
653 static OH_AVFormat *trackFormat = nullptr;
654 int32_t rotation = -1;
655 const char *file = "/data/test/media/rotation/ROTATE_90.mp4";
656 int fd = open(file, O_RDONLY);
657 int64_t size = GetFileSize(file);
658 source = OH_AVSource_CreateWithFD(fd, 0, size);
659 ASSERT_NE(source, nullptr);
660 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
661 ASSERT_NE(trackFormat, nullptr);
662 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
663 ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_90);
664 OH_AVFormat_Destroy(trackFormat);
665 close(fd);
666 fd = -1;
667 }
668
669 /**
670 * @tc.number : DEMUXER_ORIENTATIONTYPE_1002
671 * @tc.name : determine the orientation type of the video ROTATE_180.mp4
672 * @tc.desc : function test
673 */
674 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1002, TestSize.Level1)
675 {
676 static OH_AVFormat *trackFormat = nullptr;
677 int32_t rotation = -1;
678 const char *file = "/data/test/media/rotation/ROTATE_180.mp4";
679 int fd = open(file, O_RDONLY);
680 int64_t size = GetFileSize(file);
681 source = OH_AVSource_CreateWithFD(fd, 0, size);
682 ASSERT_NE(source, nullptr);
683 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
684 ASSERT_NE(trackFormat, nullptr);
685 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
686 ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_180);
687 OH_AVFormat_Destroy(trackFormat);
688 close(fd);
689 fd = -1;
690 }
691
692 /**
693 * @tc.number : DEMUXER_ORIENTATIONTYPE_1003
694 * @tc.name : determine the orientation type of the video ROTATE_270.mp4
695 * @tc.desc : function test
696 */
697 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1003, TestSize.Level1)
698 {
699 static OH_AVFormat *trackFormat = nullptr;
700 int32_t rotation = -1;
701 const char *file = "/data/test/media/rotation/ROTATE_270.mp4";
702 int fd = open(file, O_RDONLY);
703 int64_t size = GetFileSize(file);
704 source = OH_AVSource_CreateWithFD(fd, 0, size);
705 ASSERT_NE(source, nullptr);
706 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
707 ASSERT_NE(trackFormat, nullptr);
708 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
709 ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_270);
710 OH_AVFormat_Destroy(trackFormat);
711 close(fd);
712 fd = -1;
713 }
714
715 /**
716 * @tc.number : DEMUXER_ORIENTATIONTYPE_1004
717 * @tc.name : determine the orientation type of the video FLIP_H.mp4
718 * @tc.desc : function test
719 */
720 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1004, TestSize.Level2)
721 {
722 static OH_AVFormat *trackFormat = nullptr;
723 int32_t rotation = -1;
724 const char *file = "/data/test/media/rotation/FLIP_H.mp4";
725 int fd = open(file, O_RDONLY);
726 int64_t size = GetFileSize(file);
727 source = OH_AVSource_CreateWithFD(fd, 0, size);
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_EQ(rotation, OHOS::MediaAVCodec::FLIP_H);
733 OH_AVFormat_Destroy(trackFormat);
734 close(fd);
735 fd = -1;
736 }
737
738 /**
739 * @tc.number : DEMUXER_ORIENTATIONTYPE_1005
740 * @tc.name : determine the orientation type of the video FLIP_V.mp4
741 * @tc.desc : function test
742 */
743 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1005, TestSize.Level2)
744 {
745 static OH_AVFormat *trackFormat = nullptr;
746 int32_t rotation = -1;
747 const char *file = "/data/test/media/rotation/FLIP_V.mp4";
748 int fd = open(file, O_RDONLY);
749 int64_t size = GetFileSize(file);
750 source = OH_AVSource_CreateWithFD(fd, 0, size);
751 ASSERT_NE(source, nullptr);
752 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
753 ASSERT_NE(trackFormat, nullptr);
754 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
755 ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_V);
756 OH_AVFormat_Destroy(trackFormat);
757 close(fd);
758 fd = -1;
759 }
760
761 /**
762 * @tc.number : DEMUXER_ORIENTATIONTYPE_1006
763 * @tc.name : determine the orientation type of the video FLIP_H_90.mp4
764 * @tc.desc : function test
765 */
766 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1006, TestSize.Level2)
767 {
768 static OH_AVFormat *trackFormat = nullptr;
769 int32_t rotation = -1;
770 const char *file = "/data/test/media/rotation/FLIP_H_90.mp4";
771 int fd = open(file, O_RDONLY);
772 int64_t size = GetFileSize(file);
773 source = OH_AVSource_CreateWithFD(fd, 0, size);
774 ASSERT_NE(source, nullptr);
775 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
776 ASSERT_NE(trackFormat, nullptr);
777 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
778 ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_H_ROT90);
779 OH_AVFormat_Destroy(trackFormat);
780 close(fd);
781 fd = -1;
782 }
783
784 /**
785 * @tc.number : DEMUXER_ORIENTATIONTYPE_1007
786 * @tc.name : determine the orientation type of the video FLIP_V_90.mp4
787 * @tc.desc : function test
788 */
789 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1007, TestSize.Level2)
790 {
791 static OH_AVFormat *trackFormat = nullptr;
792 int32_t rotation = -1;
793 const char *file = "/data/test/media/rotation/FLIP_V_90.mp4";
794 int fd = open(file, O_RDONLY);
795 int64_t size = GetFileSize(file);
796 source = OH_AVSource_CreateWithFD(fd, 0, size);
797 ASSERT_NE(source, nullptr);
798 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
799 ASSERT_NE(trackFormat, nullptr);
800 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
801 ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_V_ROT90);
802 OH_AVFormat_Destroy(trackFormat);
803 close(fd);
804 fd = -1;
805 }
806
807 /**
808 * @tc.number : DEMUXER_ORIENTATIONTYPE_1008
809 * @tc.name : determine the orientation type of the video FLIP_H_180.mp4
810 * @tc.desc : function test
811 */
812 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1008, TestSize.Level2)
813 {
814 static OH_AVFormat *trackFormat = nullptr;
815 int32_t rotation = -1;
816 const char *file = "/data/test/media/rotation/FLIP_H_180.mp4";
817 int fd = open(file, O_RDONLY);
818 int64_t size = GetFileSize(file);
819 source = OH_AVSource_CreateWithFD(fd, 0, size);
820 ASSERT_NE(source, nullptr);
821 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
822 ASSERT_NE(trackFormat, nullptr);
823 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
824 ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_V || rotation == OHOS::MediaAVCodec::FLIP_H_ROT180);
825 OH_AVFormat_Destroy(trackFormat);
826 close(fd);
827 fd = -1;
828 }
829
830 /**
831 * @tc.number : DEMUXER_ORIENTATIONTYPE_1009
832 * @tc.name : determine the orientation type of the video FLIP_V_180.mp4
833 * @tc.desc : function test
834 */
835 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1009, TestSize.Level2)
836 {
837 static OH_AVFormat *trackFormat = nullptr;
838 int32_t rotation = -1;
839 const char *file = "/data/test/media/rotation/FLIP_V_180.mp4";
840 int fd = open(file, O_RDONLY);
841 int64_t size = GetFileSize(file);
842 source = OH_AVSource_CreateWithFD(fd, 0, size);
843 ASSERT_NE(source, nullptr);
844 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
845 ASSERT_NE(trackFormat, nullptr);
846 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
847 ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_H || rotation == OHOS::MediaAVCodec::FLIP_V_ROT180);
848 OH_AVFormat_Destroy(trackFormat);
849 close(fd);
850 fd = -1;
851 }
852
853 /**
854 * @tc.number : DEMUXER_ORIENTATIONTYPE_1010
855 * @tc.name : determine the orientation type of the video FLIP_H_270.mp4
856 * @tc.desc : function test
857 */
858 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1010, TestSize.Level2)
859 {
860 static OH_AVFormat *trackFormat = nullptr;
861 int32_t rotation = -1;
862 const char *file = "/data/test/media/rotation/FLIP_H_270.mp4";
863 int fd = open(file, O_RDONLY);
864 int64_t size = GetFileSize(file);
865 source = OH_AVSource_CreateWithFD(fd, 0, size);
866 ASSERT_NE(source, nullptr);
867 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
868 ASSERT_NE(trackFormat, nullptr);
869 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
870 ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_V_ROT90 || rotation == OHOS::MediaAVCodec::FLIP_H_ROT270);
871 OH_AVFormat_Destroy(trackFormat);
872 close(fd);
873 fd = -1;
874 }
875
876 /**
877 * @tc.number : DEMUXER_ORIENTATIONTYPE_1011
878 * @tc.name : determine the orientation type of the video FLIP_V_270.mp4
879 * @tc.desc : function test
880 */
881 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1011, TestSize.Level2)
882 {
883 static OH_AVFormat *trackFormat = nullptr;
884 int32_t rotation = -1;
885 const char *file = "/data/test/media/rotation/FLIP_V_270.mp4";
886 int fd = open(file, O_RDONLY);
887 int64_t size = GetFileSize(file);
888 source = OH_AVSource_CreateWithFD(fd, 0, size);
889 ASSERT_NE(source, nullptr);
890 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
891 ASSERT_NE(trackFormat, nullptr);
892 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
893 ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_H_ROT90 || rotation == OHOS::MediaAVCodec::FLIP_V_ROT270);
894 OH_AVFormat_Destroy(trackFormat);
895 close(fd);
896 fd = -1;
897 }
898
899 /**
900 * @tc.number : DEMUXER_ORIENTATIONTYPE_1012
901 * @tc.name : determine the orientation type of the video INVALID.mp4
902 * @tc.desc : function test
903 */
904 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1012, TestSize.Level2)
905 {
906 static OH_AVFormat *trackFormat = nullptr;
907 int32_t rotation = -1;
908 const char *file = "/data/test/media/rotation/INVALID.mp4";
909 int fd = open(file, O_RDONLY);
910 int64_t size = GetFileSize(file);
911 source = OH_AVSource_CreateWithFD(fd, 0, size);
912 ASSERT_NE(source, nullptr);
913 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
914 ASSERT_NE(trackFormat, nullptr);
915 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
916 ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
917 OH_AVFormat_Destroy(trackFormat);
918 close(fd);
919 fd = -1;
920 }
921
922 /**
923 * @tc.number : DEMUXER_ORIENTATIONTYPE_1013
924 * @tc.name : determine the orientation type of the video AV_ROTATE_NONE.mp4
925 * @tc.desc : function test
926 */
927 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1013, TestSize.Level0)
928 {
929 static OH_AVFormat *trackFormat = nullptr;
930 int32_t rotation = -1;
931 const char *file = "/data/test/media/rotation/AV_ROTATE_NONE.mp4";
932 int fd = open(file, O_RDONLY);
933 int64_t size = GetFileSize(file);
934 source = OH_AVSource_CreateWithFD(fd, 0, size);
935 ASSERT_NE(source, nullptr);
936 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
937 ASSERT_NE(trackFormat, nullptr);
938 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
939 ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
940 OH_AVFormat_Destroy(trackFormat);
941 close(fd);
942 fd = -1;
943 }
944
945 /**
946 * @tc.number : DEMUXER_ORIENTATIONTYPE_1014
947 * @tc.name : determine the orientation type of the video AV_ROTATE_90.mp4
948 * @tc.desc : function test
949 */
950 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1014, TestSize.Level1)
951 {
952 static OH_AVFormat *trackFormat = nullptr;
953 int32_t rotation = -1;
954 const char *file = "/data/test/media/rotation/AV_ROTATE_90.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::ROTATE_90);
963 OH_AVFormat_Destroy(trackFormat);
964 close(fd);
965 fd = -1;
966 }
967
968 /**
969 * @tc.number : DEMUXER_ORIENTATIONTYPE_1015
970 * @tc.name : determine the orientation type of the video AV_ROTATE_180.mp4
971 * @tc.desc : function test
972 */
973 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1015, TestSize.Level1)
974 {
975 static OH_AVFormat *trackFormat = nullptr;
976 int32_t rotation = -1;
977 const char *file = "/data/test/media/rotation/AV_ROTATE_180.mp4";
978 int fd = open(file, O_RDONLY);
979 int64_t size = GetFileSize(file);
980 source = OH_AVSource_CreateWithFD(fd, 0, size);
981 ASSERT_NE(source, nullptr);
982 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
983 ASSERT_NE(trackFormat, nullptr);
984 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
985 ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_180);
986 OH_AVFormat_Destroy(trackFormat);
987 close(fd);
988 fd = -1;
989 }
990
991 /**
992 * @tc.number : DEMUXER_ORIENTATIONTYPE_1016
993 * @tc.name : determine the orientation type of the video AV_ROTATE_270.mp4
994 * @tc.desc : function test
995 */
996 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1016, TestSize.Level1)
997 {
998 static OH_AVFormat *trackFormat = nullptr;
999 int32_t rotation = -1;
1000 const char *file = "/data/test/media/rotation/AV_ROTATE_270.mp4";
1001 int fd = open(file, O_RDONLY);
1002 int64_t size = GetFileSize(file);
1003 source = OH_AVSource_CreateWithFD(fd, 0, size);
1004 ASSERT_NE(source, nullptr);
1005 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1006 ASSERT_NE(trackFormat, nullptr);
1007 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1008 ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_270);
1009 OH_AVFormat_Destroy(trackFormat);
1010 close(fd);
1011 fd = -1;
1012 }
1013
1014 /**
1015 * @tc.number : DEMUXER_ORIENTATIONTYPE_1017
1016 * @tc.name : determine the orientation type of the video AV_FLIP_H.mp4
1017 * @tc.desc : function test
1018 */
1019 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1017, TestSize.Level2)
1020 {
1021 static OH_AVFormat *trackFormat = nullptr;
1022 int32_t rotation = -1;
1023 const char *file = "/data/test/media/rotation/AV_FLIP_H.mp4";
1024 int fd = open(file, O_RDONLY);
1025 int64_t size = GetFileSize(file);
1026 source = OH_AVSource_CreateWithFD(fd, 0, size);
1027 ASSERT_NE(source, nullptr);
1028 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1029 ASSERT_NE(trackFormat, nullptr);
1030 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1031 ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_H);
1032 OH_AVFormat_Destroy(trackFormat);
1033 close(fd);
1034 fd = -1;
1035 }
1036
1037 /**
1038 * @tc.number : DEMUXER_ORIENTATIONTYPE_1018
1039 * @tc.name : determine the orientation type of the video AV_FLIP_V.mp4
1040 * @tc.desc : function test
1041 */
1042 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1018, TestSize.Level2)
1043 {
1044 static OH_AVFormat *trackFormat = nullptr;
1045 int32_t rotation = -1;
1046 const char *file = "/data/test/media/rotation/AV_FLIP_V.mp4";
1047 int fd = open(file, O_RDONLY);
1048 int64_t size = GetFileSize(file);
1049 source = OH_AVSource_CreateWithFD(fd, 0, size);
1050 ASSERT_NE(source, nullptr);
1051 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1052 ASSERT_NE(trackFormat, nullptr);
1053 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1054 ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_V);
1055 OH_AVFormat_Destroy(trackFormat);
1056 close(fd);
1057 fd = -1;
1058 }
1059
1060 /**
1061 * @tc.number : DEMUXER_ORIENTATIONTYPE_1019
1062 * @tc.name : determine the orientation type of the video AV_FLIP_H_90.mp4
1063 * @tc.desc : function test
1064 */
1065 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1019, TestSize.Level2)
1066 {
1067 static OH_AVFormat *trackFormat = nullptr;
1068 int32_t rotation = -1;
1069 const char *file = "/data/test/media/rotation/AV_FLIP_H_90.mp4";
1070 int fd = open(file, O_RDONLY);
1071 int64_t size = GetFileSize(file);
1072 source = OH_AVSource_CreateWithFD(fd, 0, size);
1073 ASSERT_NE(source, nullptr);
1074 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1075 ASSERT_NE(trackFormat, nullptr);
1076 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1077 ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_H_ROT90);
1078 OH_AVFormat_Destroy(trackFormat);
1079 close(fd);
1080 fd = -1;
1081 }
1082
1083 /**
1084 * @tc.number : DEMUXER_ORIENTATIONTYPE_1020
1085 * @tc.name : determine the orientation type of the video AV_FLIP_V_90.mp4
1086 * @tc.desc : function test
1087 */
1088 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1020, TestSize.Level2)
1089 {
1090 static OH_AVFormat *trackFormat = nullptr;
1091 int32_t rotation = -1;
1092 const char *file = "/data/test/media/rotation/AV_FLIP_V_90.mp4";
1093 int fd = open(file, O_RDONLY);
1094 int64_t size = GetFileSize(file);
1095 source = OH_AVSource_CreateWithFD(fd, 0, size);
1096 ASSERT_NE(source, nullptr);
1097 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1098 ASSERT_NE(trackFormat, nullptr);
1099 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1100 ASSERT_EQ(rotation, OHOS::MediaAVCodec::FLIP_V_ROT90);
1101 OH_AVFormat_Destroy(trackFormat);
1102 close(fd);
1103 fd = -1;
1104 }
1105
1106 /**
1107 * @tc.number : DEMUXER_ORIENTATIONTYPE_1021
1108 * @tc.name : determine the orientation type of the video AV_FLIP_H_180.mp4
1109 * @tc.desc : function test
1110 */
1111 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1021, TestSize.Level2)
1112 {
1113 static OH_AVFormat *trackFormat = nullptr;
1114 int32_t rotation = -1;
1115 const char *file = "/data/test/media/rotation/AV_FLIP_H_180.mp4";
1116 int fd = open(file, O_RDONLY);
1117 int64_t size = GetFileSize(file);
1118 source = OH_AVSource_CreateWithFD(fd, 0, size);
1119 ASSERT_NE(source, nullptr);
1120 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1121 ASSERT_NE(trackFormat, nullptr);
1122 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1123 ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_V || rotation == OHOS::MediaAVCodec::FLIP_H_ROT180);
1124 OH_AVFormat_Destroy(trackFormat);
1125 close(fd);
1126 fd = -1;
1127 }
1128
1129 /**
1130 * @tc.number : DEMUXER_ORIENTATIONTYPE_1022
1131 * @tc.name : determine the orientation type of the video AV_FLIP_V_180.mp4
1132 * @tc.desc : function test
1133 */
1134 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1022, TestSize.Level2)
1135 {
1136 static OH_AVFormat *trackFormat = nullptr;
1137 int32_t rotation = -1;
1138 const char *file = "/data/test/media/rotation/AV_FLIP_V_180.mp4";
1139 int fd = open(file, O_RDONLY);
1140 int64_t size = GetFileSize(file);
1141 source = OH_AVSource_CreateWithFD(fd, 0, size);
1142 ASSERT_NE(source, nullptr);
1143 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1144 ASSERT_NE(trackFormat, nullptr);
1145 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1146 ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_H || rotation == OHOS::MediaAVCodec::FLIP_V_ROT180);
1147 OH_AVFormat_Destroy(trackFormat);
1148 close(fd);
1149 fd = -1;
1150 }
1151
1152 /**
1153 * @tc.number : DEMUXER_ORIENTATIONTYPE_1023
1154 * @tc.name : determine the orientation type of the video AV_FLIP_H_270.mp4
1155 * @tc.desc : function test
1156 */
1157 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1023, TestSize.Level2)
1158 {
1159 static OH_AVFormat *trackFormat = nullptr;
1160 int32_t rotation = -1;
1161 const char *file = "/data/test/media/rotation/AV_FLIP_H_270.mp4";
1162 int fd = open(file, O_RDONLY);
1163 int64_t size = GetFileSize(file);
1164 source = OH_AVSource_CreateWithFD(fd, 0, size);
1165 ASSERT_NE(source, nullptr);
1166 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1167 ASSERT_NE(trackFormat, nullptr);
1168 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1169 ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_V_ROT90 || rotation == OHOS::MediaAVCodec::FLIP_H_ROT270);
1170 OH_AVFormat_Destroy(trackFormat);
1171 close(fd);
1172 fd = -1;
1173 }
1174
1175 /**
1176 * @tc.number : DEMUXER_ORIENTATIONTYPE_1024
1177 * @tc.name : determine the orientation type of the video AV_FLIP_V_270.mp4
1178 * @tc.desc : function test
1179 */
1180 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1024, TestSize.Level2)
1181 {
1182 static OH_AVFormat *trackFormat = nullptr;
1183 int32_t rotation = -1;
1184 const char *file = "/data/test/media/rotation/AV_FLIP_V_270.mp4";
1185 int fd = open(file, O_RDONLY);
1186 int64_t size = GetFileSize(file);
1187 source = OH_AVSource_CreateWithFD(fd, 0, size);
1188 ASSERT_NE(source, nullptr);
1189 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1190 ASSERT_NE(trackFormat, nullptr);
1191 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1192 ASSERT_TRUE(rotation == OHOS::MediaAVCodec::FLIP_H_ROT90 || rotation == OHOS::MediaAVCodec::FLIP_V_ROT270);
1193 OH_AVFormat_Destroy(trackFormat);
1194 close(fd);
1195 fd = -1;
1196 }
1197
1198 /**
1199 * @tc.number : DEMUXER_ORIENTATIONTYPE_1025
1200 * @tc.name : determine the orientation type of the video AV_INVALID.mp4
1201 * @tc.desc : function test
1202 */
1203 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1025, TestSize.Level2)
1204 {
1205 static OH_AVFormat *trackFormat = nullptr;
1206 int32_t rotation = -1;
1207 const char *file = "/data/test/media/rotation/AV_INVALID.mp4";
1208 int fd = open(file, O_RDONLY);
1209 int64_t size = GetFileSize(file);
1210 source = OH_AVSource_CreateWithFD(fd, 0, size);
1211 ASSERT_NE(source, nullptr);
1212 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1213 ASSERT_NE(trackFormat, nullptr);
1214 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1215 ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
1216 OH_AVFormat_Destroy(trackFormat);
1217 close(fd);
1218 fd = -1;
1219 }
1220
1221 /**
1222 * @tc.number : DEMUXER_ORIENTATIONTYPE_1026
1223 * @tc.name : determine the orientation type of the video UNDEFINED_FLV.flv
1224 * @tc.desc : function test
1225 */
1226 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1026, TestSize.Level3)
1227 {
1228 static OH_AVFormat *trackFormat = nullptr;
1229 int32_t rotation = 0;
1230 const char *file = "/data/test/media/rotation/UNDEFINED_FLV.flv";
1231 int fd = open(file, O_RDONLY);
1232 int64_t size = GetFileSize(file);
1233 source = OH_AVSource_CreateWithFD(fd, 0, size);
1234 ASSERT_NE(source, nullptr);
1235 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1236 ASSERT_NE(trackFormat, nullptr);
1237 ASSERT_FALSE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1238 ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
1239 OH_AVFormat_Destroy(trackFormat);
1240 close(fd);
1241 fd = -1;
1242 }
1243
1244 /**
1245 * @tc.number : DEMUXER_ORIENTATIONTYPE_1027
1246 * @tc.name : determine the orientation type of the video UNDEFINED_fmp4.mp4
1247 * @tc.desc : function test
1248 */
1249 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1027, TestSize.Level3)
1250 {
1251 static OH_AVFormat *trackFormat = nullptr;
1252 int32_t rotation = 0;
1253 const char *file = "/data/test/media/rotation/UNDEFINED_FMP4.mp4";
1254 int fd = open(file, O_RDONLY);
1255 int64_t size = GetFileSize(file);
1256 source = OH_AVSource_CreateWithFD(fd, 0, size);
1257 ASSERT_NE(source, nullptr);
1258 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1259 ASSERT_NE(trackFormat, nullptr);
1260 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1261 ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
1262 OH_AVFormat_Destroy(trackFormat);
1263 close(fd);
1264 fd = -1;
1265 }
1266
1267 /**
1268 * @tc.number : DEMUXER_ORIENTATIONTYPE_1028
1269 * @tc.name : determine the orientation type of the video UNDEFINED_MKV.mkv
1270 * @tc.desc : function test
1271 */
1272 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1028, TestSize.Level3)
1273 {
1274 static OH_AVFormat *trackFormat = nullptr;
1275 int32_t rotation = 0;
1276 const char *file = "/data/test/media/rotation/UNDEFINED_MKV.mkv";
1277 int fd = open(file, O_RDONLY);
1278 int64_t size = GetFileSize(file);
1279 source = OH_AVSource_CreateWithFD(fd, 0, size);
1280 ASSERT_NE(source, nullptr);
1281 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1282 ASSERT_NE(trackFormat, nullptr);
1283 ASSERT_FALSE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1284 ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
1285 OH_AVFormat_Destroy(trackFormat);
1286 close(fd);
1287 fd = -1;
1288 }
1289
1290 /**
1291 * @tc.number : DEMUXER_ORIENTATIONTYPE_1029
1292 * @tc.name : determine the orientation type of the video UNDEFINED_TS.ts
1293 * @tc.desc : function test
1294 */
1295 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_ORIENTATIONTYPE_1029, TestSize.Level3)
1296 {
1297 static OH_AVFormat *trackFormat = nullptr;
1298 int32_t rotation = 0;
1299 const char *file = "/data/test/media/rotation/UNDEFINED_TS.ts";
1300 int fd = open(file, O_RDONLY);
1301 int64_t size = GetFileSize(file);
1302 source = OH_AVSource_CreateWithFD(fd, 0, size);
1303 ASSERT_NE(source, nullptr);
1304 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1305 ASSERT_NE(trackFormat, nullptr);
1306 ASSERT_FALSE(OH_AVFormat_GetIntValue(trackFormat, Media::Tag::VIDEO_ORIENTATION_TYPE, &rotation));
1307 ASSERT_EQ(rotation, OHOS::MediaAVCodec::ROTATE_NONE);
1308 OH_AVFormat_Destroy(trackFormat);
1309 close(fd);
1310 fd = -1;
1311 }
1312
1313 /**
1314 * @tc.number : AUDIO_DEMUXER_FUNCTION_0100
1315 * @tc.name : demux AAC_8K_1
1316 * @tc.desc : function test
1317 */
1318 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_0100, TestSize.Level2)
1319 {
1320 const char *file = "/data/test/media/audio/AAC_8K_1.aac";
1321 int fd = open(file, O_RDONLY);
1322
1323 OpenFile(file, fd, &source, &demuxer);
1324 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1325 CheckChannelCount(&trackFormat, source, 1);
1326 CheckTrackSelect(g_trackCount, demuxer);
1327 CountAudioFrames(demuxer, memory, g_trackCount, 1717, 1717);
1328
1329 close(fd);
1330 fd = -1;
1331 }
1332
1333 /**
1334 * @tc.number : AUDIO_DEMUXER_FUNCTION_0200
1335 * @tc.name : demux AAC_16K_2
1336 * @tc.desc : function test
1337 */
1338 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_0200, TestSize.Level2)
1339 {
1340 const char *file = "/data/test/media/audio/AAC_16K_2.aac";
1341 int fd = open(file, O_RDONLY);
1342
1343 OpenFile(file, fd, &source, &demuxer);
1344 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1345 CheckChannelCount(&trackFormat, source, 2);
1346 CheckTrackSelect(g_trackCount, demuxer);
1347 CountAudioFrames(demuxer, memory, g_trackCount, 3432, 3432);
1348
1349 close(fd);
1350 fd = -1;
1351 }
1352
1353 /**
1354 * @tc.number : AUDIO_DEMUXER_FUNCTION_0300
1355 * @tc.name : demux AAC_24K_1
1356 * @tc.desc : function test
1357 */
1358 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_0300, TestSize.Level2)
1359 {
1360 const char *file = "/data/test/media/audio/AAC_24K_1.aac";
1361 int fd = open(file, O_RDONLY);
1362
1363 OpenFile(file, fd, &source, &demuxer);
1364 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1365 CheckChannelCount(&trackFormat, source, 1);
1366 CheckTrackSelect(g_trackCount, demuxer);
1367 CountAudioFrames(demuxer, memory, g_trackCount, 5147, 5147);
1368
1369 close(fd);
1370 fd = -1;
1371 }
1372
1373 /**
1374 * @tc.number : AUDIO_DEMUXER_FUNCTION_0400
1375 * @tc.name : demux AAC_48K_1
1376 * @tc.desc : function test
1377 */
1378 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_0400, TestSize.Level0)
1379 {
1380 const char *file = "/data/test/media/audio/AAC_48K_1.aac";
1381 int fd = open(file, O_RDONLY);
1382
1383 OpenFile(file, fd, &source, &demuxer);
1384 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1385 CheckChannelCount(&trackFormat, source, 1);
1386 CheckTrackSelect(g_trackCount, demuxer);
1387 CountAudioFrames(demuxer, memory, g_trackCount, 10293, 10293);
1388
1389 close(fd);
1390 fd = -1;
1391 }
1392
1393 /**
1394 * @tc.number : AUDIO_DEMUXER_FUNCTION_0500
1395 * @tc.name : demux AAC_88.2K_1
1396 * @tc.desc : function test
1397 */
1398 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_0500, TestSize.Level2)
1399 {
1400 const char *file = "/data/test/media/audio/AAC_88.2K_1.aac";
1401 int fd = open(file, O_RDONLY);
1402
1403 OpenFile(file, fd, &source, &demuxer);
1404 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1405 CheckChannelCount(&trackFormat, source, 1);
1406 CheckTrackSelect(g_trackCount, demuxer);
1407 CountAudioFrames(demuxer, memory, g_trackCount, 18912, 18912);
1408
1409 close(fd);
1410 fd = -1;
1411 }
1412
1413 /**
1414 * @tc.number : AUDIO_DEMUXER_FUNCTION_0600
1415 * @tc.name : demux AAC_96K_1_main
1416 * @tc.desc : function test
1417 */
1418 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_0600, TestSize.Level2)
1419 {
1420 const char *file = "/data/test/media/audio/AAC_96K_1_main.aac";
1421 int fd = open(file, O_RDONLY);
1422
1423 OpenFile(file, fd, &source, &demuxer);
1424 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1425 CheckChannelCount(&trackFormat, source, 1);
1426 CheckTrackSelect(g_trackCount, demuxer);
1427 CountAudioFrames(demuxer, memory, g_trackCount, 20585, 20585);
1428
1429 close(fd);
1430 fd = -1;
1431 }
1432
1433 /**
1434 * @tc.number : AUDIO_DEMUXER_FUNCTION_0700
1435 * @tc.name : demux FLAC_16K_24b_1
1436 * @tc.desc : function test
1437 */
1438 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_0700, TestSize.Level2)
1439 {
1440 const char *file = "/data/test/media/audio/FLAC_16K_24b_1.flac";
1441 int fd = open(file, O_RDONLY);
1442
1443 OpenFile(file, fd, &source, &demuxer);
1444 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1445 CheckChannelCount(&trackFormat, source, 1);
1446 CheckTrackSelect(g_trackCount, demuxer);
1447 CountAudioFrames(demuxer, memory, g_trackCount, 3050, 3050);
1448
1449 close(fd);
1450 fd = -1;
1451 }
1452
1453 /**
1454 * @tc.number : AUDIO_DEMUXER_FUNCTION_0800
1455 * @tc.name : demux FLAC_96K_24b_2
1456 * @tc.desc : function test
1457 */
1458 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_0800, TestSize.Level2)
1459 {
1460 const char *file = "/data/test/media/audio/FLAC_96K_24b_2.flac";
1461 int fd = open(file, O_RDONLY);
1462
1463 OpenFile(file, fd, &source, &demuxer);
1464 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1465 CheckChannelCount(&trackFormat, source, 2);
1466 CheckTrackSelect(g_trackCount, demuxer);
1467 CountAudioFrames(demuxer, memory, g_trackCount, 704, 704);
1468
1469 close(fd);
1470 fd = -1;
1471 }
1472
1473 /**
1474 * @tc.number : AUDIO_DEMUXER_FUNCTION_0900
1475 * @tc.name : demux FLAC_192K_24b_2
1476 * @tc.desc : function test
1477 */
1478 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_0900, TestSize.Level2)
1479 {
1480 const char *file = "/data/test/media/audio/FLAC_192K_24b_2.flac";
1481 int fd = open(file, O_RDONLY);
1482
1483 OpenFile(file, fd, &source, &demuxer);
1484 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1485 CheckChannelCount(&trackFormat, source, 2);
1486 CheckTrackSelect(g_trackCount, demuxer);
1487 CountAudioFrames(demuxer, memory, g_trackCount, 352, 352);
1488
1489 close(fd);
1490 fd = -1;
1491 }
1492
1493 /**
1494 * @tc.number : AUDIO_DEMUXER_FUNCTION_1000
1495 * @tc.name : demux M4A_24K_2
1496 * @tc.desc : function test
1497 */
1498 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_1000, TestSize.Level2)
1499 {
1500 const char *file = "/data/test/media/audio/M4A_24K_2.m4a";
1501 int fd = open(file, O_RDONLY);
1502
1503 OpenFile(file, fd, &source, &demuxer);
1504 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1505 CheckChannelCount(&trackFormat, source, 2);
1506 CheckTrackSelect(g_trackCount, demuxer);
1507 CountAudioFrames(demuxer, memory, g_trackCount, 5147, 5147);
1508
1509 close(fd);
1510 fd = -1;
1511 }
1512
1513 /**
1514 * @tc.number : AUDIO_DEMUXER_FUNCTION_1100
1515 * @tc.name : demux M4A_48K_2_AC3
1516 * @tc.desc : function test
1517 */
1518 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_1100, TestSize.Level1)
1519 {
1520 const char *file = "/data/test/media/audio/M4A_48K_2_AC3.m4a";
1521 int fd = open(file, O_RDONLY);
1522
1523 OpenFile(file, fd, &source, &demuxer);
1524 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1525 CheckChannelCount(&trackFormat, source, 2);
1526 CheckTrackSelect(g_trackCount, demuxer);
1527 CountAudioFrames(demuxer, memory, g_trackCount, 6862, 6862);
1528
1529 close(fd);
1530 fd = -1;
1531 }
1532
1533 /**
1534 * @tc.number : AUDIO_DEMUXER_FUNCTION_1200
1535 * @tc.name : demux M4A_64K_2_main
1536 * @tc.desc : function test
1537 */
1538 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_1200, TestSize.Level2)
1539 {
1540 const char *file = "/data/test/media/audio/M4A_64K_2_main.m4a";
1541 int fd = open(file, O_RDONLY);
1542
1543 OpenFile(file, fd, &source, &demuxer);
1544 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1545 CheckChannelCount(&trackFormat, source, 2);
1546 CheckTrackSelect(g_trackCount, demuxer);
1547 CountAudioFrames(demuxer, memory, g_trackCount, 13724, 13724);
1548
1549 close(fd);
1550 fd = -1;
1551 }
1552
1553 /**
1554 * @tc.number : AUDIO_DEMUXER_FUNCTION_1300
1555 * @tc.name : demux M4A_96K_1_cbr
1556 * @tc.desc : function test
1557 */
1558 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_1300, TestSize.Level2)
1559 {
1560 const char *file = "/data/test/media/audio/M4A_96K_1_cbr.m4a";
1561 int fd = open(file, O_RDONLY);
1562
1563 OpenFile(file, fd, &source, &demuxer);
1564 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1565 CheckChannelCount(&trackFormat, source, 1);
1566 CheckTrackSelect(g_trackCount, demuxer);
1567 CountAudioFrames(demuxer, memory, g_trackCount, 20585, 20585);
1568
1569 close(fd);
1570 fd = -1;
1571 }
1572
1573 /**
1574 * @tc.number : AUDIO_DEMUXER_FUNCTION_1400
1575 * @tc.name : demux MP3_8K_1
1576 * @tc.desc : function test
1577 */
1578 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_1400, TestSize.Level2)
1579 {
1580 const char *file = "/data/test/media/audio/MP3_8K_1.mp3";
1581 int fd = open(file, O_RDONLY);
1582
1583 OpenFile(file, fd, &source, &demuxer);
1584 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1585 CheckChannelCount(&trackFormat, source, 1);
1586 CheckTrackSelect(g_trackCount, demuxer);
1587 CountAudioFrames(demuxer, memory, g_trackCount, 3052, 3052);
1588
1589 close(fd);
1590 fd = -1;
1591 }
1592
1593 /**
1594 * @tc.number : AUDIO_DEMUXER_FUNCTION_1500
1595 * @tc.name : demux MP3_16K_2
1596 * @tc.desc : function test
1597 */
1598 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_1500, TestSize.Level2)
1599 {
1600 const char *file = "/data/test/media/audio/MP3_16K_2.mp3";
1601 int fd = open(file, O_RDONLY);
1602
1603 OpenFile(file, fd, &source, &demuxer);
1604 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1605 CheckChannelCount(&trackFormat, source, 2);
1606 CheckTrackSelect(g_trackCount, demuxer);
1607 CountAudioFrames(demuxer, memory, g_trackCount, 6101, 6101);
1608
1609 close(fd);
1610 fd = -1;
1611 }
1612
1613 /**
1614 * @tc.number : AUDIO_DEMUXER_FUNCTION_1600
1615 * @tc.name : demux MP3_24K_1
1616 * @tc.desc : function test
1617 */
1618 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_1600, TestSize.Level1)
1619 {
1620 const char *file = "/data/test/media/audio/MP3_24K_1.mp3";
1621 int fd = open(file, O_RDONLY);
1622
1623 OpenFile(file, fd, &source, &demuxer);
1624 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1625 CheckChannelCount(&trackFormat, source, 1);
1626 CheckTrackSelect(g_trackCount, demuxer);
1627 CountAudioFrames(demuxer, memory, g_trackCount, 9151, 9151);
1628
1629 close(fd);
1630 fd = -1;
1631 }
1632
1633 /**
1634 * @tc.number : AUDIO_DEMUXER_FUNCTION_1700
1635 * @tc.name : demux OGG_8K_1
1636 * @tc.desc : function test
1637 */
1638 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_1700, TestSize.Level2)
1639 {
1640 const char *file = "/data/test/media/audio/OGG_8K_1.ogg";
1641 int fd = open(file, O_RDONLY);
1642
1643 OpenFile(file, fd, &source, &demuxer);
1644 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1645 CheckChannelCount(&trackFormat, source, 1);
1646 CheckTrackSelect(g_trackCount, demuxer);
1647 CountAudioFrames(demuxer, memory, g_trackCount, 6863, 6863);
1648
1649 close(fd);
1650 fd = -1;
1651 }
1652
1653 /**
1654 * @tc.number : AUDIO_DEMUXER_FUNCTION_1800
1655 * @tc.name : demux OGG_16K_1
1656 * @tc.desc : function test
1657 */
1658 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_1800, TestSize.Level2)
1659 {
1660 const char *file = "/data/test/media/audio/OGG_16K_1.ogg";
1661 int fd = open(file, O_RDONLY);
1662
1663 OpenFile(file, fd, &source, &demuxer);
1664 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1665 CheckChannelCount(&trackFormat, source, 1);
1666 CheckTrackSelect(g_trackCount, demuxer);
1667 CountAudioFrames(demuxer, memory, g_trackCount, 7198, 7198);
1668
1669 close(fd);
1670 fd = -1;
1671 }
1672
1673 /**
1674 * @tc.number : AUDIO_DEMUXER_FUNCTION_1900
1675 * @tc.name : demux OGG_24K_1
1676 * @tc.desc : function test
1677 */
1678 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_1900, TestSize.Level0)
1679 {
1680 const char *file = "/data/test/media/audio/OGG_24K_1.ogg";
1681 int fd = open(file, O_RDONLY);
1682
1683 OpenFile(file, fd, &source, &demuxer);
1684 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1685 CheckChannelCount(&trackFormat, source, 1);
1686 CheckTrackSelect(g_trackCount, demuxer);
1687 CountAudioFrames(demuxer, memory, g_trackCount, 10722, 10722);
1688
1689 close(fd);
1690 fd = -1;
1691 }
1692
1693 /**
1694 * @tc.number : AUDIO_DEMUXER_FUNCTION_2000
1695 * @tc.name : demux OGG_96K_1
1696 * @tc.desc : function test
1697 */
1698 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_2000, TestSize.Level1)
1699 {
1700 const char *file = "/data/test/media/audio/OGG_96K_1.ogg";
1701 int fd = open(file, O_RDONLY);
1702
1703 OpenFile(file, fd, &source, &demuxer);
1704 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1705 CheckChannelCount(&trackFormat, source, 1);
1706 CheckTrackSelect(g_trackCount, demuxer);
1707 CountAudioFrames(demuxer, memory, g_trackCount, 23223, 23223);
1708
1709 close(fd);
1710 fd = -1;
1711 }
1712
1713 /**
1714 * @tc.number : AUDIO_DEMUXER_FUNCTION_2100
1715 * @tc.name : demux OGG_192K_2
1716 * @tc.desc : function test
1717 */
1718 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_2100, TestSize.Level2)
1719 {
1720 const char *file = "/data/test/media/audio/OGG_192K_2.ogg";
1721 int fd = open(file, O_RDONLY);
1722
1723 OpenFile(file, fd, &source, &demuxer);
1724 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1725 CheckChannelCount(&trackFormat, source, 2);
1726 CheckTrackSelect(g_trackCount, demuxer);
1727 CountAudioFrames(demuxer, memory, g_trackCount, 42629, 42629);
1728
1729 close(fd);
1730 fd = -1;
1731 }
1732
1733 /**
1734 * @tc.number : AUDIO_DEMUXER_FUNCTION_2200
1735 * @tc.name : demux WAV_24K_32b_1
1736 * @tc.desc : function test
1737 */
1738 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_2200, TestSize.Level2)
1739 {
1740 int32_t bps = 0;
1741 const char *file = "/data/test/media/audio/WAV_24K_32b_1.wav";
1742 int fd = open(file, O_RDONLY);
1743
1744 OpenFile(file, fd, &source, &demuxer);
1745 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1746 CheckChannelCount(&trackFormat, source, 1);
1747 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_BITS_PER_CODED_SAMPLE, &bps));
1748 ASSERT_EQ(32, bps);
1749 CheckTrackSelect(g_trackCount, demuxer);
1750 CountAudioFrames(demuxer, memory, g_trackCount, 2110, 2110);
1751
1752 close(fd);
1753 fd = -1;
1754 }
1755
1756 /**
1757 * @tc.number : AUDIO_DEMUXER_FUNCTION_2300
1758 * @tc.name : demux WAV_96K_24b_2
1759 * @tc.desc : function test
1760 */
1761 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_2300, TestSize.Level2)
1762 {
1763 int32_t bps = 0;
1764 const char *file = "/data/test/media/audio/WAV_96K_24b_2.wav";
1765 int fd = open(file, O_RDONLY);
1766
1767 OpenFile(file, fd, &source, &demuxer);
1768 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1769 CheckChannelCount(&trackFormat, source, 2);
1770 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_BITS_PER_CODED_SAMPLE, &bps));
1771 ASSERT_EQ(24, bps);
1772 CheckTrackSelect(g_trackCount, demuxer);
1773 CountAudioFrames(demuxer, memory, g_trackCount, 2112, 2112);
1774
1775 close(fd);
1776 fd = -1;
1777 }
1778
1779 /**
1780 * @tc.number : AUDIO_DEMUXER_FUNCTION_2400
1781 * @tc.name : demux WAV_192K_32b_2
1782 * @tc.desc : function test
1783 */
1784 HWTEST_F(DemuxerFunc2NdkTest, AUDIO_DEMUXER_FUNCTION_2400, TestSize.Level2)
1785 {
1786 int32_t bps = 0;
1787 const char *file = "/data/test/media/audio/WAV_192K_32b_2.wav";
1788 int fd = open(file, O_RDONLY);
1789
1790 OpenFile(file, fd, &source, &demuxer);
1791 CheckTrackCount(&sourceFormat, source, &g_trackCount, 1);
1792 CheckChannelCount(&trackFormat, source, 2);
1793 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_BITS_PER_CODED_SAMPLE, &bps));
1794 ASSERT_EQ(32, bps);
1795 CheckTrackSelect(g_trackCount, demuxer);
1796 CountAudioFrames(demuxer, memory, g_trackCount, 1875, 1875);
1797
1798 close(fd);
1799 fd = -1;
1800 }
1801
1802 /**
1803 * @tc.number : DEMUXER_SRT_GBK_0010
1804 * @tc.name : create str demuxer with GBK file
1805 * @tc.desc : function test
1806 */
1807 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_SRT_GBK_0010, TestSize.Level2)
1808 {
1809 OH_AVCodecBufferAttr attr;
1810 const char* mimeType = nullptr;
1811 const char *file = "/data/test/media/gbk.srt";
1812 int fd = open(file, O_RDONLY);
1813 int64_t size = GetFileSize(file);
1814 cout << file << "----------------------" << fd << "---------" << size << endl;
1815 source = OH_AVSource_CreateWithFD(fd, 0, size);
1816 ASSERT_NE(source, nullptr);
1817 demuxer = OH_AVDemuxer_CreateWithSource(source);
1818 ASSERT_NE(demuxer, nullptr);
1819 sourceFormat = OH_AVSource_GetSourceFormat(source);
1820 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1821 ASSERT_NE(trackFormat, nullptr);
1822 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
1823 string mimeTypeString = mimeType;
1824 string srtString = OH_AVCODEC_MIMETYPE_SUBTITLE_SRT;
1825 cout << "------mimeType-------" << mimeTypeString << endl;
1826 ASSERT_EQ(mimeTypeString, srtString);
1827 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1828 ASSERT_EQ(1, g_trackCount);
1829 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
1830 while (true) {
1831 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
1832 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1833 cout << " srt is end !!!!!!!!!!!!!!!" << endl;
1834 break;
1835 }
1836 uint8_t *data = OH_AVMemory_GetAddr(memory);
1837 cout << "subtitle" << "----------------" << data << "-----------------" << endl;
1838 }
1839
1840 close(fd);
1841 fd = -1;
1842 }
1843
1844 /**
1845 * @tc.number : DEMUXER_SRT_GBK_0020
1846 * @tc.name : create str demuxer with GB2312 file
1847 * @tc.desc : function test
1848 */
1849 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_SRT_GBK_0020, TestSize.Level2)
1850 {
1851 OH_AVCodecBufferAttr attr;
1852 const char* mimeType = nullptr;
1853 const char *file = "/data/test/media/gb2312.srt";
1854 int fd = open(file, O_RDONLY);
1855 int64_t size = GetFileSize(file);
1856 cout << file << "----------------------" << fd << "---------" << size << endl;
1857 source = OH_AVSource_CreateWithFD(fd, 0, size);
1858 ASSERT_NE(source, nullptr);
1859 demuxer = OH_AVDemuxer_CreateWithSource(source);
1860 ASSERT_NE(demuxer, nullptr);
1861 sourceFormat = OH_AVSource_GetSourceFormat(source);
1862 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1863 ASSERT_NE(trackFormat, nullptr);
1864 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
1865 string mimeTypeString = mimeType;
1866 string srtString = OH_AVCODEC_MIMETYPE_SUBTITLE_SRT;
1867 cout << "------mimeType-------" << mimeTypeString << endl;
1868 ASSERT_EQ(mimeTypeString, srtString);
1869 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1870 ASSERT_EQ(1, g_trackCount);
1871 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
1872 while (true) {
1873 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
1874 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1875 cout << " srt is end !!!!!!!!!!!!!!!" << endl;
1876 break;
1877 }
1878 uint8_t *data = OH_AVMemory_GetAddr(memory);
1879 cout << "subtitle" << "----------------" << data << "-----------------" << endl;
1880 }
1881
1882 close(fd);
1883 fd = -1;
1884 }
1885
1886 /**
1887 * @tc.number : DEMUXER_SRT_GBK_0030
1888 * @tc.name : create str demuxer with GB18030 file
1889 * @tc.desc : function test
1890 */
1891 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_SRT_GBK_0030, TestSize.Level2)
1892 {
1893 OH_AVCodecBufferAttr attr;
1894 const char* mimeType = nullptr;
1895 const char *file = "/data/test/media/gb18030.srt";
1896 int fd = open(file, O_RDONLY);
1897 int64_t size = GetFileSize(file);
1898 cout << file << "----------------------" << fd << "---------" << size << endl;
1899 source = OH_AVSource_CreateWithFD(fd, 0, size);
1900 ASSERT_NE(source, nullptr);
1901 demuxer = OH_AVDemuxer_CreateWithSource(source);
1902 ASSERT_NE(demuxer, nullptr);
1903 sourceFormat = OH_AVSource_GetSourceFormat(source);
1904 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1905 ASSERT_NE(trackFormat, nullptr);
1906 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
1907 string mimeTypeString = mimeType;
1908 string srtString = OH_AVCODEC_MIMETYPE_SUBTITLE_SRT;
1909 cout << "------mimeType-------" << mimeTypeString << endl;
1910 ASSERT_EQ(mimeTypeString, srtString);
1911 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1912 ASSERT_EQ(1, g_trackCount);
1913 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
1914 while (true) {
1915 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
1916 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1917 cout << " srt is end !!!!!!!!!!!!!!!" << endl;
1918 break;
1919 }
1920 uint8_t *data = OH_AVMemory_GetAddr(memory);
1921 cout << "subtitle" << "----------------" << data << "-----------------" << endl;
1922 }
1923
1924 close(fd);
1925 fd = -1;
1926 }
1927
1928 /**
1929 * @tc.number : DEMUXER_VTT_GBK_0010
1930 * @tc.name : create vtt demuxer with GBK file
1931 * @tc.desc : function test
1932 */
1933 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_VTT_GBK_0010, TestSize.Level2)
1934 {
1935 OH_AVCodecBufferAttr attr;
1936 const char* mimeType = nullptr;
1937 const char *file = "/data/test/media/gbk.vtt";
1938 int fd = open(file, O_RDONLY);
1939 int64_t size = GetFileSize(file);
1940 cout << file << "----------------------" << fd << "---------" << size << endl;
1941 source = OH_AVSource_CreateWithFD(fd, 0, size);
1942 ASSERT_NE(source, nullptr);
1943 demuxer = OH_AVDemuxer_CreateWithSource(source);
1944 ASSERT_NE(demuxer, nullptr);
1945 sourceFormat = OH_AVSource_GetSourceFormat(source);
1946 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1947 ASSERT_NE(trackFormat, nullptr);
1948 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
1949 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_SUBTITLE_WEBVTT));
1950 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1951 ASSERT_EQ(1, g_trackCount);
1952 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
1953 int tarckType = 0;
1954 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1955 ASSERT_EQ(tarckType, MEDIA_TYPE_SUBTITLE);
1956 while (true) {
1957 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
1958 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1959 cout << " vtt is end !!!!!!!!!!!!!!!" << endl;
1960 break;
1961 }
1962 uint8_t *data = OH_AVMemory_GetAddr(memory);
1963 cout << "subtitle"<< "----------------" << data << "-----------------" << endl;
1964 }
1965 close(fd);
1966 fd = -1;
1967 }
1968
1969 /**
1970 * @tc.number : DEMUXER_VTT_GBK_0020
1971 * @tc.name : create vtt demuxer with GB2312 file
1972 * @tc.desc : function test
1973 */
1974 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_VTT_GBK_0020, TestSize.Level2)
1975 {
1976 OH_AVCodecBufferAttr attr;
1977 const char* mimeType = nullptr;
1978 const char *file = "/data/test/media/gb2312.vtt";
1979 int fd = open(file, O_RDONLY);
1980 int64_t size = GetFileSize(file);
1981 cout << file << "----------------------" << fd << "---------" << size << endl;
1982 source = OH_AVSource_CreateWithFD(fd, 0, size);
1983 ASSERT_NE(source, nullptr);
1984 demuxer = OH_AVDemuxer_CreateWithSource(source);
1985 ASSERT_NE(demuxer, nullptr);
1986 sourceFormat = OH_AVSource_GetSourceFormat(source);
1987 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1988 ASSERT_NE(trackFormat, nullptr);
1989 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
1990 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_SUBTITLE_WEBVTT));
1991 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1992 ASSERT_EQ(1, g_trackCount);
1993 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
1994 int tarckType = 0;
1995 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1996 ASSERT_EQ(tarckType, MEDIA_TYPE_SUBTITLE);
1997 while (true) {
1998 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
1999 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
2000 cout << " vtt is end !!!!!!!!!!!!!!!" << endl;
2001 break;
2002 }
2003 uint8_t *data = OH_AVMemory_GetAddr(memory);
2004 cout << "subtitle"<< "----------------" << data << "-----------------" << endl;
2005 }
2006 close(fd);
2007 fd = -1;
2008 }
2009
2010 /**
2011 * @tc.number : DEMUXER_VTT_GBK_0030
2012 * @tc.name : create vtt demuxer with GB18030 file
2013 * @tc.desc : function test
2014 */
2015 HWTEST_F(DemuxerFunc2NdkTest, DEMUXER_VTT_GBK_0030, TestSize.Level2)
2016 {
2017 OH_AVCodecBufferAttr attr;
2018 const char* mimeType = nullptr;
2019 const char *file = "/data/test/media/gb18030.vtt";
2020 int fd = open(file, O_RDONLY);
2021 int64_t size = GetFileSize(file);
2022 cout << file << "----------------------" << fd << "---------" << size << endl;
2023 source = OH_AVSource_CreateWithFD(fd, 0, size);
2024 ASSERT_NE(source, nullptr);
2025 demuxer = OH_AVDemuxer_CreateWithSource(source);
2026 ASSERT_NE(demuxer, nullptr);
2027 sourceFormat = OH_AVSource_GetSourceFormat(source);
2028 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
2029 ASSERT_NE(trackFormat, nullptr);
2030 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
2031 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_SUBTITLE_WEBVTT));
2032 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
2033 ASSERT_EQ(1, g_trackCount);
2034 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
2035 int tarckType = 0;
2036 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
2037 ASSERT_EQ(tarckType, MEDIA_TYPE_SUBTITLE);
2038 while (true) {
2039 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
2040 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
2041 cout << " vtt is end !!!!!!!!!!!!!!!" << endl;
2042 break;
2043 }
2044 uint8_t *data = OH_AVMemory_GetAddr(memory);
2045 cout << "subtitle"<< "----------------" << data << "-----------------" << endl;
2046 }
2047 close(fd);
2048 fd = -1;
2049 }