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