1 /*
2 * Copyright (C) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "gtest/gtest.h"
17
18 #include "native_avcodec_base.h"
19 #include "native_avdemuxer.h"
20 #include "native_avformat.h"
21 #include "native_avsource.h"
22 #include "native_avmemory.h"
23
24 #include <iostream>
25 #include <cstdio>
26 #include <string>
27 #include <fcntl.h>
28 #include <cmath>
29 #include <thread>
30 namespace OHOS {
31 namespace Media {
32 class DemuxerProcNdkTest : public testing::Test {
33 public:
34 // SetUpTestCase: Called before all test cases
35 static void SetUpTestCase(void);
36 // TearDownTestCase: Called after all test case
37 static void TearDownTestCase(void);
38 // SetUp: Called before each test cases
39 void SetUp(void);
40 // TearDown: Called after each test cases
41 void TearDown(void);
42 };
43
44 static int g_fd = -1;
45 static OH_AVMemory *memory = nullptr;
46 static OH_AVSource *source = nullptr;
47 static OH_AVDemuxer *demuxer = nullptr;
48 static OH_AVFormat *sourceFormat = nullptr;
49 static OH_AVFormat *trackFormat = nullptr;
50 static OH_AVBuffer *avBuffer = nullptr;
51 static OH_AVFormat *format = nullptr;
52
53 static int32_t g_trackCount;
54 static int32_t g_width = 3840;
55 static int32_t g_height = 2160;
56 constexpr uint32_t AVC_ROTATION = 270;
57 constexpr uint32_t HEVC_ROTATION = 90;
58 constexpr int32_t LAYOUTMONO = 4;
59 constexpr int32_t LAYOUTDUAL = 3;
60 constexpr int32_t SAMPLERATEMONO = 8000;
61 constexpr int32_t SAMPLERATEDUAL = 44100;
62 constexpr int32_t COUNTMONO = 1;
63 constexpr int32_t COUNTDUAL = 2;
64 constexpr int32_t BITRATEMONO = 64000;
65 constexpr int32_t BITRATEDUAL = 705600;
66 constexpr int32_t FRAME_REMAINING = 100;
67 constexpr int64_t START_TIME_NUM = 5011;
SetUpTestCase()68 void DemuxerProcNdkTest::SetUpTestCase() {}
TearDownTestCase()69 void DemuxerProcNdkTest::TearDownTestCase() {}
SetUp()70 void DemuxerProcNdkTest::SetUp()
71 {
72 memory = OH_AVMemory_Create(g_width * g_height);
73 g_trackCount = 0;
74 }
TearDown()75 void DemuxerProcNdkTest::TearDown()
76 {
77 if (trackFormat != nullptr) {
78 OH_AVFormat_Destroy(trackFormat);
79 trackFormat = nullptr;
80 }
81
82 if (sourceFormat != nullptr) {
83 OH_AVFormat_Destroy(sourceFormat);
84 sourceFormat = nullptr;
85 }
86
87 if (memory != nullptr) {
88 OH_AVMemory_Destroy(memory);
89 memory = nullptr;
90 }
91 if (source != nullptr) {
92 OH_AVSource_Destroy(source);
93 source = nullptr;
94 }
95 if (demuxer != nullptr) {
96 OH_AVDemuxer_Destroy(demuxer);
97 demuxer = nullptr;
98 }
99 if (avBuffer != nullptr) {
100 OH_AVBuffer_Destroy(avBuffer);
101 avBuffer = nullptr;
102 }
103 if (format != nullptr) {
104 OH_AVFormat_Destroy(format);
105 format = nullptr;
106 }
107 if (g_fd > 0) {
108 close(g_fd);
109 g_fd = -1;
110 }
111 }
112 } // namespace Media
113 } // namespace OHOS
114
115 using namespace std;
116 using namespace OHOS;
117 using namespace OHOS::Media;
118 using namespace testing::ext;
119
120 string g_mp4Vvc8bitPath = string("/data/test/media/vvc_8bit_3840_2160.mp4");
121 string g_mp4Vvc10bitPath = string("/data/test/media/vvc_aac_10bit_1920_1080.mp4");
122 const char *INP_DIR_1 = "/data/test/media/video_2audio.avi";
123 const char *INP_DIR_2 = "/data/test/media/audio_2video.avi";
124
GetFileSize(const char * fileName)125 static int64_t GetFileSize(const char *fileName)
126 {
127 int64_t fileSize = 0;
128 if (fileName != nullptr) {
129 struct stat fileStatus {};
130 if (stat(fileName, &fileStatus) == 0) {
131 fileSize = static_cast<int64_t>(fileStatus.st_size);
132 }
133 }
134 return fileSize;
135 }
136
SetAudioValue(OH_AVCodecBufferAttr attr,bool & audioIsEnd,int & audioFrame,int & aKeyCount)137 static void SetAudioValue(OH_AVCodecBufferAttr attr, bool &audioIsEnd, int &audioFrame, int &aKeyCount)
138 {
139 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
140 audioIsEnd = true;
141 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
142 } else {
143 audioFrame++;
144 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
145 aKeyCount++;
146 }
147 }
148 }
149
SetVideoValue(OH_AVCodecBufferAttr attr,bool & videoIsEnd,int & videoFrame,int & vKeyCount)150 static void SetVideoValue(OH_AVCodecBufferAttr attr, bool &videoIsEnd, int &videoFrame, int &vKeyCount)
151 {
152 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
153 videoIsEnd = true;
154 cout << videoFrame << " video is end !!!!!!!!!!!!!!!" << endl;
155 } else {
156 videoFrame++;
157 cout << "video track !!!!!" << endl;
158 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
159 vKeyCount++;
160 }
161 }
162 }
163
IsHdrVivid(OH_AVFormat * paramFormat)164 static void IsHdrVivid(OH_AVFormat *paramFormat)
165 {
166 int32_t videoIsHdrvivid;
167 if (!access("/system/lib64/media/", 0)) {
168 ASSERT_TRUE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_VIDEO_IS_HDR_VIVID, &videoIsHdrvivid));
169 ASSERT_EQ(1, videoIsHdrvivid);
170 } else {
171 ASSERT_FALSE(OH_AVFormat_GetIntValue(paramFormat, OH_MD_KEY_VIDEO_IS_HDR_VIVID, &videoIsHdrvivid));
172 }
173 }
174
CheckFile(const char * fileName,int fd,OH_AVSource ** src,OH_AVDemuxer ** Demuxer,int32_t * trackCount)175 static void CheckFile(const char *fileName, int fd, OH_AVSource **src, OH_AVDemuxer **Demuxer, int32_t *trackCount)
176 {
177 int64_t size = GetFileSize(fileName);
178 cout << fileName << "----------------------" << fd << "---------" << size << endl;
179 *src = OH_AVSource_CreateWithFD(fd, 0, size);
180 ASSERT_NE(*src, nullptr);
181 *Demuxer = OH_AVDemuxer_CreateWithSource(*src);
182 ASSERT_NE(*Demuxer, nullptr);
183 sourceFormat = OH_AVSource_GetSourceFormat(source);
184 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, trackCount));
185 }
186
CheckAudioParam(OH_AVSource * audioSource,int & audioFrameAll)187 static void CheckAudioParam(OH_AVSource *audioSource, int &audioFrameAll)
188 {
189 int tarckType = 0;
190 OH_AVCodecBufferAttr bufferAttr;
191 bool audioIsEnd = false;
192 int32_t count = 0;
193 int32_t rate = 0;
194 int64_t bitrate = 0;
195 int64_t layout = 0;
196 int32_t index = 0;
197 const char* mimeType = nullptr;
198 while (!audioIsEnd) {
199 trackFormat = OH_AVSource_GetTrackFormat(audioSource, index);
200 ASSERT_NE(trackFormat, nullptr);
201 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
202 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer));
203 ASSERT_NE(avBuffer, nullptr);
204 ASSERT_EQ(AV_ERR_OK, OH_AVBuffer_GetBufferAttr(avBuffer, &bufferAttr));
205 if (tarckType == MEDIA_TYPE_AUD) {
206 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
207 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, &rate));
208 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, &count));
209 ASSERT_TRUE(OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_CHANNEL_LAYOUT, &layout));
210 ASSERT_TRUE(OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_BITRATE, &bitrate));
211 if (bufferAttr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
212 audioIsEnd = true;
213 continue;
214 }
215 audioFrameAll++;
216 }
217 OH_AVFormat_Destroy(trackFormat);
218 trackFormat = nullptr;
219 }
220 if (count == 1) {
221 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_AUDIO_G711MU));
222 ASSERT_EQ(layout, LAYOUTMONO);
223 ASSERT_EQ(rate, SAMPLERATEMONO);
224 ASSERT_EQ(count, COUNTMONO);
225 ASSERT_EQ(bitrate, BITRATEMONO);
226 } else {
227 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_AUDIO_G711MU));
228 ASSERT_EQ(layout, LAYOUTDUAL);
229 ASSERT_EQ(rate, SAMPLERATEDUAL);
230 ASSERT_EQ(count, COUNTDUAL);
231 ASSERT_EQ(bitrate, BITRATEDUAL);
232 }
233 }
234
235 /**
236 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_1400
237 * @tc.name : demuxer video and 2 audio file
238 * @tc.desc : function test
239 */
240 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_1400, TestSize.Level0)
241 {
242 int tarckType = 0;
243 int auidoTrackCount = 2;
244 OH_AVCodecBufferAttr attr;
245 bool videoIsEnd = false;
246 int videoFrame = 0;
247 const char *file = "/data/test/media/video_2audio.mp4";
248 int fd = open(file, O_RDONLY);
249 int64_t size = GetFileSize(file);
250 source = OH_AVSource_CreateWithFD(fd, 0, size);
251 ASSERT_NE(source, nullptr);
252 demuxer = OH_AVDemuxer_CreateWithSource(source);
253 ASSERT_NE(demuxer, nullptr);
254 sourceFormat = OH_AVSource_GetSourceFormat(source);
255 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
256 ASSERT_EQ(auidoTrackCount + 1, g_trackCount);
257 for (int32_t index = 0; index < g_trackCount; index++) {
258 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
259 }
260 int vKeyCount = 0;
261 int aKeyCount[2] = {};
262 int audioFrame[2] = {};
263 bool audioIsEnd = false;
264 while (!audioIsEnd || !videoIsEnd) {
265 for (int32_t index = 0; index < g_trackCount; index++) {
266 trackFormat = OH_AVSource_GetTrackFormat(source, index);
267 ASSERT_NE(trackFormat, nullptr);
268 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
269 OH_AVFormat_Destroy(trackFormat);
270 trackFormat = nullptr;
271 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
272 continue;
273 }
274 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
275 if (tarckType == MEDIA_TYPE_VID) {
276 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
277 } else if (tarckType == MEDIA_TYPE_AUD) {
278 SetAudioValue(attr, audioIsEnd, audioFrame[index-1], aKeyCount[index-1]);
279 }
280 }
281 }
282 for (int index = 0; index < auidoTrackCount; index++) {
283 ASSERT_EQ(audioFrame[index], 433);
284 ASSERT_EQ(aKeyCount[index], 433);
285 }
286 ASSERT_EQ(videoFrame, 602);
287 ASSERT_EQ(vKeyCount, 3);
288 close(fd);
289 fd = -1;
290 }
291
292 /**
293 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_1500
294 * @tc.name : demuxer video and 9 audio file
295 * @tc.desc : function test
296 */
297 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_1500, TestSize.Level0)
298 {
299 int tarckType = 0;
300 int auidoTrackCount = 9;
301 OH_AVCodecBufferAttr attr;
302 bool videoIsEnd = false;
303 int videoFrame = 0;
304 const char *file = "/data/test/media/video_9audio.mp4";
305 int fd = open(file, O_RDONLY);
306 int64_t size = GetFileSize(file);
307 source = OH_AVSource_CreateWithFD(fd, 0, size);
308 ASSERT_NE(source, nullptr);
309 demuxer = OH_AVDemuxer_CreateWithSource(source);
310 ASSERT_NE(demuxer, nullptr);
311 sourceFormat = OH_AVSource_GetSourceFormat(source);
312 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
313 ASSERT_EQ(auidoTrackCount + 1, g_trackCount);
314 for (int32_t index = 0; index < g_trackCount; index++) {
315 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
316 }
317 int vKeyCount = 0;
318 int aKeyCount[9] = {};
319 int audioFrame[9] = {};
320 bool audioIsEnd = false;
321 while (!audioIsEnd || !videoIsEnd) {
322 for (int32_t index = 0; index < g_trackCount; index++) {
323 trackFormat = OH_AVSource_GetTrackFormat(source, index);
324 ASSERT_NE(trackFormat, nullptr);
325 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
326 OH_AVFormat_Destroy(trackFormat);
327 trackFormat = nullptr;
328 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
329 continue;
330 }
331 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
332 if (tarckType == MEDIA_TYPE_VID) {
333 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
334 } else if (tarckType == MEDIA_TYPE_AUD) {
335 SetAudioValue(attr, audioIsEnd, audioFrame[index-1], aKeyCount[index-1]);
336 }
337 }
338 }
339 for (int index = 0; index < auidoTrackCount; index++) {
340 ASSERT_EQ(audioFrame[index], 433);
341 ASSERT_EQ(aKeyCount[index], 433);
342 }
343 ASSERT_EQ(videoFrame, 602);
344 ASSERT_EQ(vKeyCount, 3);
345 close(fd);
346 fd = -1;
347 }
348
349 /**
350 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_1600
351 * @tc.name : demuxer avc+MP3 flv video file
352 * @tc.desc : function test
353 */
354 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_1600, TestSize.Level0)
355 {
356 int tarckType = 0;
357 OH_AVCodecBufferAttr attr;
358 bool videoIsEnd = false;
359 int videoFrame = 0;
360 const char *file = "/data/test/media/avc_mp3.flv";
361 int fd = open(file, O_RDONLY);
362 int64_t size = GetFileSize(file);
363 cout << file << "----------------------" << fd << "---------" << size << endl;
364 source = OH_AVSource_CreateWithFD(fd, 0, size);
365 ASSERT_NE(source, nullptr);
366 demuxer = OH_AVDemuxer_CreateWithSource(source);
367 ASSERT_NE(demuxer, nullptr);
368 sourceFormat = OH_AVSource_GetSourceFormat(source);
369 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
370 ASSERT_EQ(2, g_trackCount);
371 for (int32_t index = 0; index < g_trackCount; index++) {
372 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
373 }
374 int vKeyCount = 0;
375 int aKeyCount = 0;
376 int audioFrame = 0;
377 bool audioIsEnd = false;
378 while (!audioIsEnd || !videoIsEnd) {
379 for (int32_t index = 0; index < g_trackCount; index++) {
380 trackFormat = OH_AVSource_GetTrackFormat(source, index);
381 ASSERT_NE(trackFormat, nullptr);
382 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
383 OH_AVFormat_Destroy(trackFormat);
384 trackFormat = nullptr;
385 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
386 continue;
387 }
388 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
389 if (tarckType == MEDIA_TYPE_VID) {
390 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
391 } else if (tarckType == MEDIA_TYPE_AUD) {
392 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
393 }
394 }
395 }
396 ASSERT_EQ(audioFrame, 385);
397 ASSERT_EQ(aKeyCount, 385);
398 ASSERT_EQ(videoFrame, 602);
399 ASSERT_EQ(vKeyCount, 3);
400 close(fd);
401 fd = -1;
402 }
403
404 /**
405 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_1700
406 * @tc.name : demuxer hevc+pcm flv video file
407 * @tc.desc : function test
408 */
409 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_1700, TestSize.Level0)
410 {
411 int tarckType = 0;
412 OH_AVCodecBufferAttr attr;
413 bool videoIsEnd = false;
414 int videoFrame = 0;
415 const char *file = "/data/test/media/hevc_pcm_a.flv";
416 int fd = open(file, O_RDONLY);
417 int64_t size = GetFileSize(file);
418 cout << file << "----------------------" << fd << "---------" << size << endl;
419 source = OH_AVSource_CreateWithFD(fd, 0, size);
420 ASSERT_NE(source, nullptr);
421 demuxer = OH_AVDemuxer_CreateWithSource(source);
422 ASSERT_NE(demuxer, nullptr);
423 sourceFormat = OH_AVSource_GetSourceFormat(source);
424 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
425 ASSERT_EQ(2, g_trackCount);
426 for (int32_t index = 0; index < g_trackCount; index++) {
427 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
428 }
429 int vKeyCount = 0;
430 int aKeyCount = 0;
431 int audioFrame = 0;
432 bool audioIsEnd = false;
433 while (!audioIsEnd || !videoIsEnd) {
434 for (int32_t index = 0; index < g_trackCount; index++) {
435 trackFormat = OH_AVSource_GetTrackFormat(source, index);
436 ASSERT_NE(trackFormat, nullptr);
437 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
438 OH_AVFormat_Destroy(trackFormat);
439 trackFormat = nullptr;
440 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
441 continue;
442 }
443 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
444 if (tarckType == MEDIA_TYPE_VID) {
445 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
446 } else if (tarckType == MEDIA_TYPE_AUD) {
447 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
448 }
449 }
450 }
451 ASSERT_EQ(audioFrame, 385);
452 ASSERT_EQ(aKeyCount, 385);
453 ASSERT_EQ(videoFrame, 602);
454 ASSERT_EQ(vKeyCount, 3);
455 close(fd);
456 fd = -1;
457 }
458
459 /**
460 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_1800
461 * @tc.name : demuxer damaged flv video file
462 * @tc.desc : function test
463 */
464 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_1800, TestSize.Level2)
465 {
466 int tarckType = 0;
467 OH_AVCodecBufferAttr attr;
468 bool videoIsEnd = false;
469 int videoFrame = 0;
470 const char *file = "/data/test/media/avc_mp3_error.flv";
471 int fd = open(file, O_RDONLY);
472 int64_t size = GetFileSize(file);
473 cout << file << "----------------------" << fd << "---------" << size << endl;
474 source = OH_AVSource_CreateWithFD(fd, 0, size);
475 ASSERT_NE(source, nullptr);
476 demuxer = OH_AVDemuxer_CreateWithSource(source);
477 ASSERT_NE(demuxer, nullptr);
478 sourceFormat = OH_AVSource_GetSourceFormat(source);
479 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
480 ASSERT_EQ(2, g_trackCount);
481 for (int32_t index = 0; index < g_trackCount; index++) {
482 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
483 }
484 int vKeyCount = 0;
485 int aKeyCount = 0;
486 int audioFrame = 0;
487 bool audioIsEnd = false;
488 while (!audioIsEnd || !videoIsEnd) {
489 for (int32_t index = 0; index < g_trackCount; index++) {
490 trackFormat = OH_AVSource_GetTrackFormat(source, index);
491 ASSERT_NE(trackFormat, nullptr);
492 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
493 OH_AVFormat_Destroy(trackFormat);
494 trackFormat = nullptr;
495 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
496 continue;
497 }
498 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
499 if (tarckType == MEDIA_TYPE_VID) {
500 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
501 } else if (tarckType == MEDIA_TYPE_AUD) {
502 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
503 }
504 }
505 }
506 close(fd);
507 fd = -1;
508 }
509
510 /**
511 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_1900
512 * @tc.name : demuxer damaged ape audio file
513 * @tc.desc : function test
514 */
515 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_1900, TestSize.Level2)
516 {
517 OH_AVCodecBufferAttr attr;
518 const char* mimeType = nullptr;
519 bool audioIsEnd = false;
520 int audioFrame = 0;
521 const char *file = "/data/test/media/audio/ape.ape";
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_AUDIO_APE));
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 aKeyCount = 0;
538 while (!audioIsEnd) {
539 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
540 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
541 }
542 ASSERT_EQ(audioFrame, 8);
543 ASSERT_EQ(aKeyCount, 8);
544 close(fd);
545 fd = -1;
546 }
547
548 /**
549 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_2000
550 * @tc.name : demuxer h264+mp3 fmp4 file
551 * @tc.desc : function test
552 */
553 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_2000, TestSize.Level0)
554 {
555 int tarckType = 0;
556 OH_AVCodecBufferAttr attr;
557 bool videoIsEnd = false;
558 int videoFrame = 0;
559 const char *file = "/data/test/media/h264_mp3_3mevx_fmp4.mp4";
560 int fd = open(file, O_RDONLY);
561 int64_t size = GetFileSize(file);
562 cout << file << "----------------------" << fd << "---------" << size << endl;
563 source = OH_AVSource_CreateWithFD(fd, 0, size);
564 ASSERT_NE(source, nullptr);
565 demuxer = OH_AVDemuxer_CreateWithSource(source);
566 ASSERT_NE(demuxer, nullptr);
567 sourceFormat = OH_AVSource_GetSourceFormat(source);
568 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
569 ASSERT_EQ(2, g_trackCount);
570 for (int32_t index = 0; index < g_trackCount; index++) {
571 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
572 }
573 int vKeyCount = 0;
574 int aKeyCount = 0;
575 int audioFrame = 0;
576 bool audioIsEnd = false;
577 while (!audioIsEnd || !videoIsEnd) {
578 for (int32_t index = 0; index < g_trackCount; index++) {
579 trackFormat = OH_AVSource_GetTrackFormat(source, index);
580 ASSERT_NE(trackFormat, nullptr);
581 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
582 OH_AVFormat_Destroy(trackFormat);
583 trackFormat = nullptr;
584 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
585 continue;
586 }
587 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
588 if (tarckType == MEDIA_TYPE_VID) {
589 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
590 } else if (tarckType == MEDIA_TYPE_AUD) {
591 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
592 }
593 }
594 }
595 ASSERT_EQ(audioFrame, 465);
596 ASSERT_EQ(aKeyCount, 465);
597 ASSERT_EQ(videoFrame, 369);
598 ASSERT_EQ(vKeyCount, 3);
599 close(fd);
600 fd = -1;
601 }
602
603 /**
604 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_2100
605 * @tc.name : demuxer h265+aac fmp4 file
606 * @tc.desc : function test
607 */
608 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_2100, TestSize.Level0)
609 {
610 int tarckType = 0;
611 OH_AVCodecBufferAttr attr;
612 bool videoIsEnd = false;
613 int videoFrame = 0;
614 const char *file = "/data/test/media/h265_aac_1mvex_fmp4.mp4";
615 int fd = open(file, O_RDONLY);
616 int64_t size = GetFileSize(file);
617 cout << file << "----------------------" << fd << "---------" << size << endl;
618 source = OH_AVSource_CreateWithFD(fd, 0, size);
619 ASSERT_NE(source, nullptr);
620 demuxer = OH_AVDemuxer_CreateWithSource(source);
621 ASSERT_NE(demuxer, nullptr);
622 sourceFormat = OH_AVSource_GetSourceFormat(source);
623 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
624 ASSERT_EQ(2, g_trackCount);
625 for (int32_t index = 0; index < g_trackCount; index++) {
626 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
627 }
628 int vKeyCount = 0;
629 int aKeyCount = 0;
630 int audioFrame = 0;
631 bool audioIsEnd = false;
632 while (!audioIsEnd || !videoIsEnd) {
633 for (int32_t index = 0; index < g_trackCount; index++) {
634 trackFormat = OH_AVSource_GetTrackFormat(source, index);
635 ASSERT_NE(trackFormat, nullptr);
636 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
637 OH_AVFormat_Destroy(trackFormat);
638 trackFormat = nullptr;
639 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
640 continue;
641 }
642 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
643 if (tarckType == MEDIA_TYPE_VID) {
644 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
645 } else if (tarckType == MEDIA_TYPE_AUD) {
646 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
647 }
648 }
649 }
650 ASSERT_EQ(audioFrame, 173);
651 ASSERT_EQ(aKeyCount, 173);
652 ASSERT_EQ(videoFrame, 242);
653 ASSERT_EQ(vKeyCount, 1);
654 close(fd);
655 fd = -1;
656 }
657
658 /**
659 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_2200
660 * @tc.name : demuxer HDRVivid+AudioVivid fmp4 file
661 * @tc.desc : function test
662 */
663 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_2200, TestSize.Level0)
664 {
665 int tarckType = 0;
666 OH_AVCodecBufferAttr attr;
667 bool videoIsEnd = false;
668 int videoFrame = 0;
669 const char* mimeType = nullptr;
670 const char *file = "/data/test/media/audiovivid_hdrvivid_1s_fmp4.mp4";
671 int fd = open(file, O_RDONLY);
672 int64_t size = GetFileSize(file);
673 cout << file << "----------------------" << fd << "---------" << size << endl;
674 source = OH_AVSource_CreateWithFD(fd, 0, size);
675 ASSERT_NE(source, nullptr);
676 demuxer = OH_AVDemuxer_CreateWithSource(source);
677 ASSERT_NE(demuxer, nullptr);
678 sourceFormat = OH_AVSource_GetSourceFormat(source);
679 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
680 ASSERT_EQ(2, g_trackCount);
681 for (int32_t index = 0; index < g_trackCount; index++) {
682 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
683 }
684 int vKeyCount = 0;
685 int aKeyCount = 0;
686 int audioFrame = 0;
687 bool audioIsEnd = false;
688 while (!audioIsEnd || !videoIsEnd) {
689 for (int32_t index = 0; index < g_trackCount; index++) {
690 trackFormat = OH_AVSource_GetTrackFormat(source, index);
691 ASSERT_NE(trackFormat, nullptr);
692 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
693 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
694 continue;
695 }
696 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
697 if (tarckType == MEDIA_TYPE_VID) {
698 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
699 } else if (tarckType == MEDIA_TYPE_AUD) {
700 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
701 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
702 ASSERT_EQ(0, strcmp(mimeType, OH_AVCODEC_MIMETYPE_AUDIO_VIVID));
703 }
704 OH_AVFormat_Destroy(trackFormat);
705 trackFormat = nullptr;
706 }
707 }
708 ASSERT_EQ(videoFrame, 26);
709 ASSERT_EQ(vKeyCount, 1);
710 close(fd);
711 fd = -1;
712 }
713
714 /**
715 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_2300
716 * @tc.name : demuxer M4A fmp4 file
717 * @tc.desc : function test
718 */
719 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_2300, TestSize.Level0)
720 {
721 OH_AVCodecBufferAttr attr;
722 bool audioIsEnd = false;
723 int audioFrame = 0;
724 const char *file = "/data/test/media/m4a_fmp4.mp4";
725 int fd = open(file, O_RDONLY);
726 int64_t size = GetFileSize(file);
727 cout << file << "----------------------" << fd << "---------" << size << endl;
728 source = OH_AVSource_CreateWithFD(fd, 0, size);
729 ASSERT_NE(source, nullptr);
730 demuxer = OH_AVDemuxer_CreateWithSource(source);
731 ASSERT_NE(demuxer, nullptr);
732 sourceFormat = OH_AVSource_GetSourceFormat(source);
733 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
734 ASSERT_EQ(1, g_trackCount);
735 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
736 int aKeyCount = 0;
737 while (!audioIsEnd) {
738 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
739 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
740 }
741 ASSERT_EQ(audioFrame, 352);
742 ASSERT_EQ(aKeyCount, 352);
743 close(fd);
744 fd = -1;
745 }
746
747 /**
748 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_2400
749 * @tc.name : demuxer M4V fmp4 file
750 * @tc.desc : function test
751 */
752 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_2400, TestSize.Level0)
753 {
754 int tarckType = 0;
755 OH_AVCodecBufferAttr attr;
756 bool videoIsEnd = false;
757 int videoFrame = 0;
758 const char *file = "/data/test/media/m4v_fmp4.mp4";
759 int fd = open(file, O_RDONLY);
760 int64_t size = GetFileSize(file);
761 cout << file << "----------------------" << fd << "---------" << size << endl;
762 source = OH_AVSource_CreateWithFD(fd, 0, size);
763 ASSERT_NE(source, nullptr);
764 demuxer = OH_AVDemuxer_CreateWithSource(source);
765 ASSERT_NE(demuxer, nullptr);
766 sourceFormat = OH_AVSource_GetSourceFormat(source);
767 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
768 ASSERT_EQ(2, g_trackCount);
769 for (int32_t index = 0; index < g_trackCount; index++) {
770 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
771 }
772 int vKeyCount = 0;
773 int aKeyCount = 0;
774 int audioFrame = 0;
775 bool audioIsEnd = false;
776 while (!audioIsEnd || !videoIsEnd) {
777 for (int32_t index = 0; index < g_trackCount; index++) {
778 trackFormat = OH_AVSource_GetTrackFormat(source, index);
779 ASSERT_NE(trackFormat, nullptr);
780 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
781 OH_AVFormat_Destroy(trackFormat);
782 trackFormat = nullptr;
783 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
784 continue;
785 }
786 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
787 if (tarckType == MEDIA_TYPE_VID) {
788 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
789 } else if (tarckType == MEDIA_TYPE_AUD) {
790 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
791 }
792 }
793 }
794 ASSERT_EQ(audioFrame, 176);
795 ASSERT_EQ(aKeyCount, 176);
796 ASSERT_EQ(videoFrame, 123);
797 ASSERT_EQ(vKeyCount, 1);
798 close(fd);
799 fd = -1;
800 }
801
802 /**
803 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_2500
804 * @tc.name : create hls demuxer with error uri
805 * @tc.desc : function test
806 */
807 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_2500, TestSize.Level1)
808 {
809 const char *uri = "http://192.168.3.11:8080/share/index.m3u8";
810 source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
811 ASSERT_EQ(nullptr, source);
812 }
813
814 /**
815 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_2600
816 * @tc.name : create str demuxer with file and read
817 * @tc.desc : function test
818 */
819 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_2600, TestSize.Level0)
820 {
821 OH_AVCodecBufferAttr attr;
822 const char* mimeType = nullptr;
823 int srtIndex = 1;
824 int srtSubtitle = 0;
825 const char *file = "/data/test/media/srt_test.srt";
826 int fd = open(file, O_RDONLY);
827 int64_t size = GetFileSize(file);
828 cout << file << "----------------------" << fd << "---------" << size << endl;
829 source = OH_AVSource_CreateWithFD(fd, 0, size);
830 ASSERT_NE(source, nullptr);
831 demuxer = OH_AVDemuxer_CreateWithSource(source);
832 ASSERT_NE(demuxer, nullptr);
833 sourceFormat = OH_AVSource_GetSourceFormat(source);
834 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
835 ASSERT_NE(trackFormat, nullptr);
836 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
837 string mimeTypeString = mimeType;
838 string srtString = OH_AVCODEC_MIMETYPE_SUBTITLE_SRT;
839 cout << "------mimeType-------" << mimeTypeString << endl;
840 ASSERT_EQ(mimeTypeString, srtString);
841 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
842 ASSERT_EQ(1, g_trackCount);
843 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
844 while (true) {
845 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
846 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
847 cout << " srt is end !!!!!!!!!!!!!!!" << endl;
848 break;
849 }
850 uint8_t *data = OH_AVMemory_GetAddr(memory);
851 srtSubtitle = atoi(reinterpret_cast<const char*>(data));
852 cout << "subtitle" << "----------------" << srtSubtitle << "-----------------" << endl;
853 ASSERT_EQ(srtSubtitle, srtIndex);
854 srtIndex++;
855 }
856 close(fd);
857 fd = -1;
858 }
859
860 /**
861 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_2700
862 * @tc.name : create str demuxer with file and seek+read
863 * @tc.desc : function test
864 */
865 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_2700, TestSize.Level0)
866 {
867 OH_AVCodecBufferAttr attr;
868 const char* mimeType = nullptr;
869 int srtIndex = 1;
870 int srtSubtitle = 0;
871 uint8_t *data = nullptr;
872 const char *file = "/data/test/media/srt_test.srt";
873 int fd = open(file, O_RDONLY);
874 int64_t size = GetFileSize(file);
875 source = OH_AVSource_CreateWithFD(fd, 0, size);
876 ASSERT_NE(source, nullptr);
877 demuxer = OH_AVDemuxer_CreateWithSource(source);
878 ASSERT_NE(demuxer, nullptr);
879 sourceFormat = OH_AVSource_GetSourceFormat(source);
880 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
881 ASSERT_NE(trackFormat, nullptr);
882 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
883 string mimeTypeString = mimeType;
884 string srtString = OH_AVCODEC_MIMETYPE_SUBTITLE_SRT;
885 ASSERT_EQ(mimeTypeString, srtString);
886 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
887 ASSERT_EQ(1, g_trackCount);
888 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
889 for (int index = 0; index < 5; index++) {
890 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
891 data = OH_AVMemory_GetAddr(memory);
892 srtSubtitle = atoi(reinterpret_cast<const char*>(data));
893 ASSERT_EQ(srtSubtitle, srtIndex);
894 srtIndex++;
895 }
896 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, 5400, SEEK_MODE_CLOSEST_SYNC));
897 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
898 data = OH_AVMemory_GetAddr(memory);
899 srtSubtitle = atoi(reinterpret_cast<const char*>(data));
900 srtIndex = 2;
901 ASSERT_EQ(srtSubtitle, srtIndex);
902 while (true) {
903 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
904 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
905 break;
906 }
907 data = OH_AVMemory_GetAddr(memory);
908 srtSubtitle = atoi(reinterpret_cast<const char*>(data));
909 srtIndex++;
910 ASSERT_EQ(srtSubtitle, srtIndex);
911 }
912 close(fd);
913 fd = -1;
914 }
915
916 /**
917 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_2800
918 * @tc.name : create str demuxer with error file -- no empty paragraphs
919 * @tc.desc : function test
920 */
921 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_2800, TestSize.Level2)
922 {
923 OH_AVCodecBufferAttr attr;
924 const char* mimeType = nullptr;
925 const char *file = "/data/test/media/srt_2800.srt";
926 int fd = open(file, O_RDONLY);
927 int64_t size = GetFileSize(file);
928 cout << file << "----------------------" << fd << "---------" << size << endl;
929 source = OH_AVSource_CreateWithFD(fd, 0, size);
930 ASSERT_NE(source, nullptr);
931 demuxer = OH_AVDemuxer_CreateWithSource(source);
932 ASSERT_NE(demuxer, nullptr);
933 sourceFormat = OH_AVSource_GetSourceFormat(source);
934 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
935 ASSERT_NE(trackFormat, nullptr);
936 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
937 string mimeTypeString = mimeType;
938 string srtString = OH_AVCODEC_MIMETYPE_SUBTITLE_SRT;
939 cout << "------mimeType-------" << mimeTypeString << endl;
940 ASSERT_EQ(mimeTypeString, srtString);
941 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
942 ASSERT_EQ(1, g_trackCount);
943 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
944 while (true) {
945 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
946 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
947 cout << " srt is end !!!!!!!!!!!!!!!" << endl;
948 break;
949 }
950 uint8_t *data = OH_AVMemory_GetAddr(memory);
951 cout << "subtitle"<< "----------------" << data << "-----------------" << endl;
952 }
953
954 close(fd);
955 fd = -1;
956 }
957
958 /**
959 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_2900
960 * @tc.name : create str demuxer with error file -- subtitle sequence error
961 * @tc.desc : function test
962 */
963 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_2900, TestSize.Level2)
964 {
965 OH_AVCodecBufferAttr attr;
966 const char* mimeType = nullptr;
967 const char *file = "/data/test/media/srt_2900.srt";
968 int fd = open(file, O_RDONLY);
969 int64_t size = GetFileSize(file);
970 cout << file << "----------------------" << fd << "---------" << size << endl;
971 source = OH_AVSource_CreateWithFD(fd, 0, size);
972 ASSERT_NE(source, nullptr);
973 demuxer = OH_AVDemuxer_CreateWithSource(source);
974 ASSERT_NE(demuxer, nullptr);
975 sourceFormat = OH_AVSource_GetSourceFormat(source);
976 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
977 ASSERT_NE(trackFormat, nullptr);
978 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
979 string mimeTypeString = mimeType;
980 string srtString = OH_AVCODEC_MIMETYPE_SUBTITLE_SRT;
981 cout << "------mimeType-------" << mimeTypeString << endl;
982 ASSERT_EQ(mimeTypeString, srtString);
983 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
984 ASSERT_EQ(1, g_trackCount);
985 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
986 while (true) {
987 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
988 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
989 cout << " srt is end !!!!!!!!!!!!!!!" << endl;
990 break;
991 }
992 uint8_t *data = OH_AVMemory_GetAddr(memory);
993 cout << "subtitle" << "----------------" << data << "-----------------" << endl;
994 }
995
996 close(fd);
997 fd = -1;
998 }
999
1000 /**
1001 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_3000
1002 * @tc.name : create str demuxer with error file -- timeline format error
1003 * @tc.desc : function test
1004 */
1005 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_3000, TestSize.Level2)
1006 {
1007 OH_AVCodecBufferAttr attr;
1008 const char *file = "/data/test/media/srt_3000.srt";
1009 int fd = open(file, O_RDONLY);
1010 int64_t size = GetFileSize(file);
1011 cout << file << "----------------------" << fd << "---------" << size << endl;
1012 source = OH_AVSource_CreateWithFD(fd, 0, size);
1013 if (source) {
1014 demuxer = OH_AVDemuxer_CreateWithSource(source);
1015 ASSERT_NE(demuxer, nullptr);
1016 sourceFormat = OH_AVSource_GetSourceFormat(source);
1017 ASSERT_NE(sourceFormat, nullptr);
1018 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1019 cout << "g_trackCount"<< "----------------" << g_trackCount << "-----------------" << endl;
1020 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
1021 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
1022 uint8_t *data = OH_AVMemory_GetAddr(memory);
1023 cout << "subtitle"<< "----------------" << data << "-----------------" << endl;
1024 }
1025 close(fd);
1026 fd = -1;
1027 }
1028
1029 /**
1030 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_3100
1031 * @tc.name : create str demuxer with error file -- subtitle is empty
1032 * @tc.desc : function test
1033 */
1034 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_3100, TestSize.Level2)
1035 {
1036 OH_AVCodecBufferAttr attr;
1037 const char* mimeType = nullptr;
1038 const char *file = "/data/test/media/srt_3100.srt";
1039 int fd = open(file, O_RDONLY);
1040 int64_t size = GetFileSize(file);
1041 cout << file << "----------------------" << fd << "---------" << size << endl;
1042 source = OH_AVSource_CreateWithFD(fd, 0, size);
1043 ASSERT_NE(source, nullptr);
1044 demuxer = OH_AVDemuxer_CreateWithSource(source);
1045 ASSERT_NE(demuxer, nullptr);
1046 sourceFormat = OH_AVSource_GetSourceFormat(source);
1047 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1048 ASSERT_NE(trackFormat, nullptr);
1049 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
1050 string mimeTypeString = mimeType;
1051 string srtString = OH_AVCODEC_MIMETYPE_SUBTITLE_SRT;
1052 cout << "------mimeType-------" << mimeTypeString << endl;
1053 ASSERT_EQ(mimeTypeString, srtString);
1054 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1055 ASSERT_EQ(1, g_trackCount);
1056 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
1057 while (true) {
1058 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
1059 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1060 cout << " srt is end !!!!!!!!!!!!!!!" << endl;
1061 break;
1062 }
1063 uint8_t *data = OH_AVMemory_GetAddr(memory);
1064 cout << "subtitle"<< "----------------" << data << "-----------------" << endl;
1065 }
1066
1067 close(fd);
1068 fd = -1;
1069 }
1070
1071 /**
1072 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_3200
1073 * @tc.name : create str demuxer with error file -- SRT file is empty
1074 * @tc.desc : function test
1075 * fail
1076 */
1077 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_3200, TestSize.Level2)
1078 {
1079 OH_AVCodecBufferAttr attr;
1080 const char *file = "/data/test/media/srt_3200.srt";
1081 int fd = open(file, O_RDONLY);
1082 int64_t size = GetFileSize(file);
1083 cout << file << "----------------------" << fd << "---------" << size << endl;
1084 source = OH_AVSource_CreateWithFD(fd, 0, size);
1085 if (source) {
1086 demuxer = OH_AVDemuxer_CreateWithSource(source);
1087 ASSERT_NE(demuxer, nullptr);
1088 sourceFormat = OH_AVSource_GetSourceFormat(source);
1089 ASSERT_NE(sourceFormat, nullptr);
1090 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1091 cout << "g_trackCount"<< "----------------" << g_trackCount << "-----------------" << endl;
1092 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
1093 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
1094 uint8_t *data = OH_AVMemory_GetAddr(memory);
1095 cout << "subtitle"<< "----------------" << data << "-----------------" << endl;
1096 }
1097 close(fd);
1098 fd = -1;
1099 }
1100
1101 /**
1102 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_3300
1103 * @tc.name : create str demuxer with error file -- alternating Up and Down Times
1104 * @tc.desc : function test
1105 */
1106 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_3300, TestSize.Level2)
1107 {
1108 OH_AVCodecBufferAttr attr;
1109 const char* mimeType = nullptr;
1110 const char *file = "/data/test/media/srt_3300.srt";
1111 int fd = open(file, O_RDONLY);
1112 int64_t size = GetFileSize(file);
1113 cout << file << "----------------------" << fd << "---------" << size << endl;
1114 source = OH_AVSource_CreateWithFD(fd, 0, size);
1115 ASSERT_NE(source, nullptr);
1116 demuxer = OH_AVDemuxer_CreateWithSource(source);
1117 ASSERT_NE(demuxer, nullptr);
1118 sourceFormat = OH_AVSource_GetSourceFormat(source);
1119 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1120 ASSERT_NE(trackFormat, nullptr);
1121 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &mimeType));
1122 string mimeTypeString = mimeType;
1123 string srtString = OH_AVCODEC_MIMETYPE_SUBTITLE_SRT;
1124 cout << "------mimeType-------" << mimeTypeString << endl;
1125 ASSERT_EQ(mimeTypeString, srtString);
1126 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1127 ASSERT_EQ(1, g_trackCount);
1128 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
1129 while (true) {
1130 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
1131 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1132 cout << " srt is end !!!!!!!!!!!!!!!" << endl;
1133 break;
1134 }
1135 uint8_t *data = OH_AVMemory_GetAddr(memory);
1136 cout << "subtitle"<< "----------------" << data << "-----------------" << endl;
1137 }
1138
1139 close(fd);
1140 fd = -1;
1141 }
1142
1143 /**
1144 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_3400
1145 * @tc.name : demuxer MP4 ,OH_MD_KEY_DURATION,OH_MD_KEY_CODEC_CONFIG
1146 * @tc.desc : function test
1147 */
1148 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_3400, TestSize.Level0)
1149 {
1150 int64_t duration;
1151 static OH_AVFormat *trackFormatFirst = nullptr;
1152 static OH_AVFormat *trackFormatSecond = nullptr;
1153 uint8_t *codecConfig = nullptr;
1154 double frameRate;
1155 int32_t rotation;
1156 int64_t channelLayout;
1157 int32_t audioSampleFormat;
1158 int32_t bitsPreCodedSample;
1159 int32_t profile;
1160 int32_t colorPrimaries;
1161 int32_t videoIsHdrvivid;
1162 size_t bufferSize;
1163 const char *file = "/data/test/media/01_video_audio.mp4";
1164 int fd = open(file, O_RDONLY);
1165 int64_t size = GetFileSize(file);
1166 source = OH_AVSource_CreateWithFD(fd, 0, size);
1167 ASSERT_NE(source, nullptr);
1168 sourceFormat = OH_AVSource_GetSourceFormat(source);
1169 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1170 trackFormatFirst = OH_AVSource_GetTrackFormat(source, 0);
1171 ASSERT_NE(trackFormatFirst, nullptr);
1172 trackFormatSecond = OH_AVSource_GetTrackFormat(source, 1);
1173 ASSERT_NE(trackFormatSecond, nullptr);
1174 ASSERT_TRUE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_DURATION, &duration));
1175 ASSERT_EQ(duration, 10032000);
1176 ASSERT_TRUE(OH_AVFormat_GetBuffer(trackFormatSecond, OH_MD_KEY_CODEC_CONFIG, &codecConfig, &bufferSize));
1177 ASSERT_TRUE(OH_AVFormat_GetDoubleValue(trackFormatSecond, OH_MD_KEY_FRAME_RATE, &frameRate));
1178 ASSERT_EQ(frameRate, 25.1);
1179 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormatSecond, OH_MD_KEY_ROTATION, &rotation));
1180 ASSERT_EQ(rotation, 0);
1181 ASSERT_TRUE(OH_AVFormat_GetLongValue(trackFormatFirst, OH_MD_KEY_CHANNEL_LAYOUT, &channelLayout));
1182 ASSERT_EQ(channelLayout, 3);
1183 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormatFirst, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, &audioSampleFormat));
1184 ASSERT_EQ(audioSampleFormat, 9);
1185 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormatFirst, OH_MD_KEY_BITS_PER_CODED_SAMPLE, &bitsPreCodedSample));
1186 ASSERT_EQ(bitsPreCodedSample, 16);
1187 ASSERT_FALSE(OH_AVFormat_GetIntValue(trackFormatFirst, OH_MD_KEY_PROFILE, &profile));
1188 ASSERT_FALSE(OH_AVFormat_GetIntValue(trackFormatFirst, OH_MD_KEY_COLOR_PRIMARIES, &colorPrimaries));
1189 ASSERT_FALSE(OH_AVFormat_GetIntValue(trackFormatFirst, OH_MD_KEY_VIDEO_IS_HDR_VIVID, &videoIsHdrvivid));
1190 OH_AVFormat_Destroy(trackFormatFirst);
1191 trackFormatFirst = nullptr;
1192 OH_AVFormat_Destroy(trackFormatSecond);
1193 trackFormatSecond = nullptr;
1194 close(fd);
1195 fd = -1;
1196 }
1197
1198 /**
1199 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_3500
1200 * @tc.name : demuxer MP4 ,startTime
1201 * @tc.desc : function test
1202 */
1203 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_3500, TestSize.Level0)
1204 {
1205 int64_t startTime;
1206 const char *file = "/data/test/media/test_265_B_Gop25_4sec.mp4";
1207 int fd = open(file, O_RDONLY);
1208 int64_t size = GetFileSize(file);
1209 source = OH_AVSource_CreateWithFD(fd, 0, size);
1210 ASSERT_NE(source, nullptr);
1211 sourceFormat = OH_AVSource_GetSourceFormat(source);
1212 ASSERT_NE(sourceFormat, nullptr);
1213 ASSERT_TRUE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_START_TIME, &startTime));
1214 ASSERT_EQ(0, startTime);
1215 close(fd);
1216 fd = -1;
1217 }
1218
1219 /**
1220 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_3510
1221 * @tc.name : demuxer MP4 ,startTime Non-zero
1222 * @tc.desc : function test
1223 */
1224 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_3510, TestSize.Level0)
1225 {
1226 int64_t startTime;
1227 const char *file = "/data/test/media/test_starttime.mp4";
1228 int fd = open(file, O_RDONLY);
1229 int64_t size = GetFileSize(file);
1230 source = OH_AVSource_CreateWithFD(fd, 0, size);
1231 ASSERT_NE(source, nullptr);
1232 sourceFormat = OH_AVSource_GetSourceFormat(source);
1233 ASSERT_NE(sourceFormat, nullptr);
1234 ASSERT_TRUE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_START_TIME, &startTime));
1235 cout << "---startTime---" << startTime << endl;
1236 ASSERT_EQ(START_TIME_NUM, startTime);
1237 close(fd);
1238 fd = -1;
1239 }
1240
1241 /**
1242 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_3600
1243 * @tc.name : demuxer MP4 ,SAR,bitsPreCodedSample,sampleFormat
1244 * @tc.desc : function test
1245 */
1246 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_3600, TestSize.Level0)
1247 {
1248 int tarckType = 0;
1249 double sar;
1250 int32_t bitsPreCodedSample;
1251 int32_t sampleFormat;
1252 const char *file = "/data/test/media/test_265_B_Gop25_4sec.mp4";
1253 int fd = open(file, O_RDONLY);
1254 int64_t size = GetFileSize(file);
1255 cout << file << "----------------------" << fd << "---------" << size << endl;
1256 source = OH_AVSource_CreateWithFD(fd, 0, size);
1257 ASSERT_NE(source, nullptr);
1258 sourceFormat = OH_AVSource_GetSourceFormat(source);
1259 ASSERT_NE(sourceFormat, nullptr);
1260 demuxer = OH_AVDemuxer_CreateWithSource(source);
1261 ASSERT_NE(demuxer, nullptr);
1262 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1263 ASSERT_EQ(2, g_trackCount);
1264 for (int32_t index = 0; index < g_trackCount; index++) {
1265 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1266 }
1267 for (int32_t index = 0; index < g_trackCount; index++) {
1268 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1269 ASSERT_NE(trackFormat, nullptr);
1270 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1271 if (tarckType == MEDIA_TYPE_VID) {
1272 ASSERT_TRUE(OH_AVFormat_GetDoubleValue(trackFormat, OH_MD_KEY_VIDEO_SAR, &sar));
1273 }else if (tarckType == MEDIA_TYPE_AUD) {
1274 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_BITS_PER_CODED_SAMPLE, &bitsPreCodedSample));
1275 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AUDIO_SAMPLE_FORMAT, &sampleFormat));
1276 }
1277 OH_AVFormat_Destroy(trackFormat);
1278 trackFormat = nullptr;
1279 }
1280 ASSERT_EQ(1, sar);
1281 ASSERT_EQ(16, bitsPreCodedSample);
1282 ASSERT_EQ(9, sampleFormat);
1283 close(fd);
1284 fd = -1;
1285 }
1286
1287 /**
1288 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_3700
1289 * @tc.name : demuxer MP4,duration,dts
1290 * @tc.desc : function test
1291 */
1292 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_3700, TestSize.Level0)
1293 {
1294 int tarckType = 0;
1295 int64_t duration;
1296 int64_t dts;
1297 const char *file = "/data/test/media/test_265_B_Gop25_4sec.mp4";
1298 int fd = open(file, O_RDONLY);
1299 int64_t size = GetFileSize(file);
1300 cout << file << "----------------------" << fd << "---------" << size << endl;
1301 source = OH_AVSource_CreateWithFD(fd, 0, size);
1302 ASSERT_NE(source, nullptr);
1303 demuxer = OH_AVDemuxer_CreateWithSource(source);
1304 ASSERT_NE(demuxer, nullptr);
1305 avBuffer = OH_AVBuffer_Create(size);
1306 ASSERT_NE(avBuffer, nullptr);
1307 sourceFormat = OH_AVSource_GetSourceFormat(source);
1308 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1309 ASSERT_EQ(2, g_trackCount);
1310 for (int32_t index = 0; index < g_trackCount; index++) {
1311 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1312 }
1313 for (int32_t index = 0; index < g_trackCount; index++) {
1314 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1315 ASSERT_NE(trackFormat, nullptr);
1316 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1317 OH_AVFormat_Destroy(trackFormat);
1318 trackFormat = nullptr;
1319 if (tarckType == MEDIA_TYPE_VID) {
1320 OH_AVDemuxer_ReadSampleBuffer(demuxer, index, avBuffer);
1321 ASSERT_NE(avBuffer, nullptr);
1322 format = OH_AVBuffer_GetParameter(avBuffer);
1323 ASSERT_NE(format, nullptr);
1324 ASSERT_TRUE(OH_AVFormat_GetLongValue(format, OH_MD_KEY_BUFFER_DURATION, &duration));
1325 ASSERT_TRUE(OH_AVFormat_GetLongValue(format, OH_MD_KEY_DECODING_TIMESTAMP, &dts));
1326 ASSERT_EQ(40000, duration);
1327 ASSERT_EQ(-80000, dts);
1328 }
1329 }
1330 }
1331 /**
1332 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_3800
1333 * @tc.name : demuxer MP4 ,AVCODEC_BUFFER_FLAGS_DISCARD
1334 * @tc.desc : function test
1335 */
1336 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_3800, TestSize.Level0)
1337 {
1338 OH_AVCodecBufferAttr attr;
1339 int tarckType = 0;
1340 const char *file = "/data/test/media/test_265_B_Gop25_4sec.mp4";
1341 int fd = open(file, O_RDONLY);
1342 int64_t size = GetFileSize(file);
1343 cout << file << "----------------------" << fd << "---------" << size << endl;
1344 source = OH_AVSource_CreateWithFD(fd, 0, size);
1345 ASSERT_NE(source, nullptr);
1346 sourceFormat = OH_AVSource_GetSourceFormat(source);
1347 ASSERT_NE(sourceFormat, nullptr);
1348 demuxer = OH_AVDemuxer_CreateWithSource(source);
1349 ASSERT_NE(demuxer, nullptr);
1350 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1351 ASSERT_EQ(2, g_trackCount);
1352 for (int32_t index = 0; index < g_trackCount; index++) {
1353 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1354 }
1355 int audioFrame = 0;
1356 bool audioIsEnd = false;
1357 while (!audioIsEnd) {
1358 for (int32_t index = 0; index < g_trackCount; index++) {
1359 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1360 ASSERT_NE(trackFormat, nullptr);
1361 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1362 OH_AVFormat_Destroy(trackFormat);
1363 trackFormat = nullptr;
1364 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD))) {
1365 continue;
1366 }
1367 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1368 if (tarckType == MEDIA_TYPE_AUD && (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_DISCARD)) {
1369 audioIsEnd = true;
1370 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
1371 }
1372 }
1373 }
1374 close(fd);
1375 fd = -1;
1376 }
1377
1378 /**
1379 * @tc.number : SUB_MP3_TITLE_RESOLUTION_4100
1380 * @tc.name : audio resolution with fffe mp3
1381 * @tc.desc : function test
1382 */
1383 HWTEST_F(DemuxerProcNdkTest, SUB_MP3_TITLE_RESOLUTION_4100, TestSize.Level0)
1384 {
1385 const char *stringVal;
1386 const char *file = "/data/test/media/audio/fffe_bom.mp3";
1387 int fd = open(file, O_RDONLY);
1388 int64_t size = GetFileSize(file);
1389 cout << file << "----------------------" << fd << "---------" << size << endl;
1390 source = OH_AVSource_CreateWithFD(fd, 0, size);
1391 ASSERT_NE(source, nullptr);
1392
1393 sourceFormat = OH_AVSource_GetSourceFormat(source);
1394 ASSERT_NE(sourceFormat, nullptr);
1395 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &stringVal));
1396 cout << "title" << "----------------------" << stringVal << "---------" << endl;
1397 ASSERT_EQ(0, strcmp(stringVal, "bom"));
1398 close(fd);
1399 fd = -1;
1400 }
1401
1402 /**
1403 * @tc.number : SUB_MP3_TITLE_RESOLUTION_4200
1404 * @tc.name : audio resolution with feff mp3
1405 * @tc.desc : function test
1406 */
1407 HWTEST_F(DemuxerProcNdkTest, SUB_MP3_TITLE_RESOLUTION_4200, TestSize.Level0)
1408 {
1409 const char *stringVal;
1410 const char *file = "/data/test/media/audio/feff_bom.mp3";
1411 int fd = open(file, O_RDONLY);
1412 int64_t size = GetFileSize(file);
1413 cout << file << "----------------------" << fd << "---------" << size << endl;
1414 source = OH_AVSource_CreateWithFD(fd, 0, size);
1415 ASSERT_NE(source, nullptr);
1416
1417 sourceFormat = OH_AVSource_GetSourceFormat(source);
1418 ASSERT_NE(sourceFormat, nullptr);
1419 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &stringVal));
1420 cout << "title" << "----------------------" << stringVal << "---------" << endl;
1421 ASSERT_EQ(0, strcmp(stringVal, "bom"));
1422 close(fd);
1423 fd = -1;
1424 }
1425
1426 /**
1427 * @tc.number : SUB_MP3_TITLE_RESOLUTION_4300
1428 * @tc.name : audio resolution non_standard mp3
1429 * @tc.desc : function test
1430 */
1431 HWTEST_F(DemuxerProcNdkTest, SUB_MP3_TITLE_RESOLUTION_4300, TestSize.Level0)
1432 {
1433 const char *stringVal;
1434 const char *file = "/data/test/media/audio/nonstandard_bom.mp3";
1435 int fd = open(file, O_RDONLY);
1436 int64_t size = GetFileSize(file);
1437 cout << file << "----------------------" << fd << "---------" << size << endl;
1438 source = OH_AVSource_CreateWithFD(fd, 0, size);
1439 ASSERT_NE(source, nullptr);
1440
1441 sourceFormat = OH_AVSource_GetSourceFormat(source);
1442 ASSERT_NE(sourceFormat, nullptr);
1443 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &stringVal));
1444 cout << "title" << "----------------------" << stringVal << "---------" << endl;
1445 ASSERT_EQ(0, strcmp(stringVal, "bom"));
1446 close(fd);
1447 fd = -1;
1448 }
1449
1450 /**
1451 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_4600
1452 * @tc.name : demuxer AVC MP4 ,OH_MD_KEY_DURATION,OH_MD_KEY_CODEC_CONFIG
1453 * @tc.desc : function test
1454 */
1455 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_4600, TestSize.Level0)
1456 {
1457 int tarckType = 0;
1458 uint8_t *codecConfig = nullptr;
1459 int32_t rotation;
1460 int32_t videoIsHdrvivid;
1461 size_t bufferSize;
1462 const char *file = "/data/test/media/single_rk.mp4";
1463 int fd = open(file, O_RDONLY);
1464 int64_t size = GetFileSize(file);
1465 source = OH_AVSource_CreateWithFD(fd, 0, size);
1466 ASSERT_NE(source, nullptr);
1467 demuxer = OH_AVDemuxer_CreateWithSource(source);
1468 ASSERT_NE(demuxer, nullptr);
1469 sourceFormat = OH_AVSource_GetSourceFormat(source);
1470 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1471 for (int32_t index = 0; index < g_trackCount; index++) {
1472 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1473 }
1474 OH_AVCodecBufferAttr attr;
1475 int vKeyCount = 0;
1476 int aKeyCount = 0;
1477 bool audioIsEnd = false;
1478 bool videoIsEnd = false;
1479 int audioFrame = 0;
1480 int videoFrame = 0;
1481 while (!audioIsEnd || !videoIsEnd) {
1482 for (int32_t index = 0; index < g_trackCount; index++) {
1483 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1484 ASSERT_NE(trackFormat, nullptr);
1485 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1486 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
1487 continue;
1488 }
1489 ASSERT_TRUE(OH_AVFormat_GetBuffer(trackFormat, OH_MD_KEY_CODEC_CONFIG, &codecConfig, &bufferSize));
1490 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1491 if (tarckType == MEDIA_TYPE_AUD) {
1492 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
1493 } else if (tarckType == MEDIA_TYPE_VID) {
1494 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
1495 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_ROTATION, &rotation));
1496 ASSERT_FALSE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_VIDEO_IS_HDR_VIVID, &videoIsHdrvivid));
1497 }
1498 OH_AVFormat_Destroy(trackFormat);
1499 trackFormat = nullptr;
1500 }
1501 }
1502 ASSERT_EQ(AVC_ROTATION, rotation);
1503 close(fd);
1504 fd = -1;
1505 }
1506 /**
1507 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_4700
1508 * @tc.name : demuxer HEVC MP4 ,OH_MD_KEY_DURATION,OH_MD_KEY_CODEC_CONFIG
1509 * @tc.desc : function test
1510 */
1511 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_4700, TestSize.Level0)
1512 {
1513 int tarckType = 0;
1514 uint8_t *codecConfig = nullptr;
1515 int32_t rotation;
1516 size_t bufferSize;
1517 const char *file = "/data/test/media/single_60.mp4";
1518 int fd = open(file, O_RDONLY);
1519 int64_t size = GetFileSize(file);
1520 source = OH_AVSource_CreateWithFD(fd, 0, size);
1521 ASSERT_NE(source, nullptr);
1522 demuxer = OH_AVDemuxer_CreateWithSource(source);
1523 ASSERT_NE(demuxer, nullptr);
1524 sourceFormat = OH_AVSource_GetSourceFormat(source);
1525 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1526 for (int32_t index = 0; index < g_trackCount; index++) {
1527 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1528 }
1529 OH_AVCodecBufferAttr attr;
1530 int vKeyCount = 0;
1531 int aKeyCount = 0;
1532 bool audioIsEnd = false;
1533 bool videoIsEnd = false;
1534 int audioFrame = 0;
1535 int videoFrame = 0;
1536 while (!audioIsEnd || !videoIsEnd) {
1537 for (int32_t index = 0; index < g_trackCount; index++) {
1538 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1539 ASSERT_NE(trackFormat, nullptr);
1540 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1541 if ((audioIsEnd && (tarckType == MEDIA_TYPE_AUD)) || (videoIsEnd && (tarckType == MEDIA_TYPE_VID))) {
1542 continue;
1543 }
1544 ASSERT_TRUE(OH_AVFormat_GetBuffer(trackFormat, OH_MD_KEY_CODEC_CONFIG, &codecConfig, &bufferSize));
1545 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1546 if (tarckType == MEDIA_TYPE_AUD) {
1547 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
1548 } else if (tarckType == MEDIA_TYPE_VID) {
1549 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
1550 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_ROTATION, &rotation));
1551 IsHdrVivid(trackFormat);
1552 }
1553 OH_AVFormat_Destroy(trackFormat);
1554 trackFormat = nullptr;
1555 }
1556 }
1557 ASSERT_EQ(HEVC_ROTATION, rotation);
1558 close(fd);
1559 fd = -1;
1560 }
1561 /**
1562 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_6200
1563 * @tc.name : create pcm-mulaw wav demuxer with file
1564 * @tc.desc : function test
1565 */
1566 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_6200, TestSize.Level2)
1567 {
1568 int audioFrame = 0;
1569 const char *file = "/data/test/media/audio/wav_audio_test_202406290859.wav";
1570 int fd = open(file, O_RDONLY);
1571 int64_t size = GetFileSize(file);
1572 cout << file << "----------------------" << fd << "---------" << size << endl;
1573 source = OH_AVSource_CreateWithFD(fd, 0, size);
1574 ASSERT_NE(source, nullptr);
1575 demuxer = OH_AVDemuxer_CreateWithSource(source);
1576 ASSERT_NE(demuxer, nullptr);
1577 avBuffer = OH_AVBuffer_Create(size);
1578 ASSERT_NE(avBuffer, nullptr);
1579 sourceFormat = OH_AVSource_GetSourceFormat(source);
1580 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1581 ASSERT_EQ(1, g_trackCount);
1582 for (int32_t index = 0; index < g_trackCount; index++) {
1583 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1584 }
1585 CheckAudioParam(source, audioFrame);
1586 ASSERT_EQ(103, audioFrame);
1587 cout << "-----------audioFrame-----------" << audioFrame << endl;
1588 close(fd);
1589 fd = -1;
1590 }
1591
1592 /**
1593 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_6400
1594 * @tc.name : create pcm-mulaw wav demuxer with Mono channel file
1595 * @tc.desc : function test
1596 */
1597 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_6400, TestSize.Level2)
1598 {
1599 int audioFrame = 0;
1600 const char *file = "/data/test/media/audio/wav_audio_test_1562.wav";
1601 int fd = open(file, O_RDONLY);
1602 int64_t size = GetFileSize(file);
1603 cout << file << "----------------------" << fd << "---------" << size << endl;
1604 source = OH_AVSource_CreateWithFD(fd, 0, size);
1605 ASSERT_NE(source, nullptr);
1606 demuxer = OH_AVDemuxer_CreateWithSource(source);
1607 ASSERT_NE(demuxer, nullptr);
1608 avBuffer = OH_AVBuffer_Create(size);
1609 ASSERT_NE(avBuffer, nullptr);
1610 sourceFormat = OH_AVSource_GetSourceFormat(source);
1611 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1612 ASSERT_EQ(1, g_trackCount);
1613 for (int32_t index = 0; index < g_trackCount; index++) {
1614 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1615 }
1616 CheckAudioParam(source, audioFrame);
1617 ASSERT_EQ(7, audioFrame);
1618 cout << "-----------audioFrame-----------" << audioFrame << endl;
1619 close(fd);
1620 fd = -1;
1621 }
1622
1623 /**
1624 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_6600
1625 * @tc.name : create pcm+mulaw wav demuxer with file and forward back seek+read
1626 * @tc.desc : function test
1627 */
1628 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_6600, TestSize.Level0)
1629 {
1630 int audioFrame = 0;
1631 const char *file = "/data/test/media/audio/wav_audio_test_202406290859.wav";
1632 int fd = open(file, O_RDONLY);
1633 int64_t size = GetFileSize(file);
1634 source = OH_AVSource_CreateWithFD(fd, 0, size);
1635 ASSERT_NE(source, nullptr);
1636 demuxer = OH_AVDemuxer_CreateWithSource(source);
1637 ASSERT_NE(demuxer, nullptr);
1638 sourceFormat = OH_AVSource_GetSourceFormat(source);
1639 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1640 ASSERT_NE(trackFormat, nullptr);
1641 avBuffer = OH_AVBuffer_Create(size);
1642 ASSERT_NE(avBuffer, nullptr);
1643 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1644 ASSERT_EQ(1, g_trackCount);
1645 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
1646 int tarckType = 0;
1647 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1648 int time = 4600000;
1649 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, time/1000, SEEK_MODE_CLOSEST_SYNC));
1650 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, 0, avBuffer));
1651 time = 92000;
1652 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, time/1000, SEEK_MODE_CLOSEST_SYNC));
1653 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, 0, avBuffer));
1654 CheckAudioParam(source, audioFrame);
1655 ASSERT_EQ(FRAME_REMAINING, audioFrame);
1656 cout << "-----------audioFrame-----------" << audioFrame << endl;
1657 close(fd);
1658 fd = -1;
1659 }
1660
1661 /**
1662 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_6700
1663 * @tc.name : create pcm+mulaw wav demuxer with file and back seek+read
1664 * @tc.desc : function test
1665 */
1666 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_6700, TestSize.Level0)
1667 {
1668 int audioFrame = 0;
1669 const char *file = "/data/test/media/audio/wav_audio_test_202406290859.wav";
1670 int fd = open(file, O_RDONLY);
1671 int64_t size = GetFileSize(file);
1672 source = OH_AVSource_CreateWithFD(fd, 0, size);
1673 ASSERT_NE(source, nullptr);
1674 demuxer = OH_AVDemuxer_CreateWithSource(source);
1675 ASSERT_NE(demuxer, nullptr);
1676 sourceFormat = OH_AVSource_GetSourceFormat(source);
1677 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1678 ASSERT_NE(trackFormat, nullptr);
1679 avBuffer = OH_AVBuffer_Create(size);
1680 ASSERT_NE(avBuffer, nullptr);
1681 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1682 ASSERT_EQ(1, g_trackCount);
1683 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
1684 int tarckType = 0;
1685 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1686 int time = 4736000;
1687 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, time/1000, SEEK_MODE_CLOSEST_SYNC));
1688 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, 0, avBuffer));
1689 time = 600000;
1690 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, time/1000, SEEK_MODE_CLOSEST_SYNC));
1691 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, 0, avBuffer));
1692 time = 92000;
1693 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, time/1000, SEEK_MODE_CLOSEST_SYNC));
1694 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, 0, avBuffer));
1695 CheckAudioParam(source, audioFrame);
1696 ASSERT_EQ(FRAME_REMAINING, audioFrame);
1697 cout << "-----------audioFrame-----------" << audioFrame << endl;
1698 close(fd);
1699 fd = -1;
1700 }
1701
1702 /**
1703 * @tc.number : SUB_MEDIA_DEMUXER_PROCESS_6800
1704 * @tc.name : create pcm+mulaw wav demuxer with file and forward seek+read
1705 * @tc.desc : function test
1706 */
1707 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_PROCESS_6800, TestSize.Level0)
1708 {
1709 int audioFrame = 0;
1710 const char *file = "/data/test/media/audio/wav_audio_test_202406290859.wav";
1711 int fd = open(file, O_RDONLY);
1712 int64_t size = GetFileSize(file);
1713 source = OH_AVSource_CreateWithFD(fd, 0, size);
1714 ASSERT_NE(source, nullptr);
1715 demuxer = OH_AVDemuxer_CreateWithSource(source);
1716 ASSERT_NE(demuxer, nullptr);
1717 sourceFormat = OH_AVSource_GetSourceFormat(source);
1718 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1719 ASSERT_NE(trackFormat, nullptr);
1720 avBuffer = OH_AVBuffer_Create(size);
1721 ASSERT_NE(avBuffer, nullptr);
1722 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1723 ASSERT_EQ(1, g_trackCount);
1724 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
1725 int tarckType = 0;
1726 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1727 int time = 92000;
1728 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, time/1000, SEEK_MODE_CLOSEST_SYNC));
1729 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSampleBuffer(demuxer, 0, avBuffer));
1730 CheckAudioParam(source, audioFrame);
1731 ASSERT_EQ(FRAME_REMAINING, audioFrame);
1732 cout << "-----------audioFrame-----------" << audioFrame << endl;
1733 close(fd);
1734 fd = -1;
1735 }
1736
1737 /**
1738 * @tc.number : VIDEO_DEMUXER_VVC_0100
1739 * @tc.name : demuxer 8bit H266 MP4 file, read
1740 * @tc.desc : function test
1741 */
1742 HWTEST_F(DemuxerProcNdkTest, VIDEO_DEMUXER_VVC_0100, TestSize.Level0)
1743 {
1744 if (access(g_mp4Vvc8bitPath.c_str(), F_OK) != 0) {
1745 return;
1746 }
1747 int tarckType = 0;
1748 OH_AVCodecBufferAttr attr;
1749 bool videoIsEnd = false;
1750 int videoFrame = 0;
1751 int fd = open(g_mp4Vvc8bitPath.c_str(), O_RDONLY);
1752 int64_t size = GetFileSize(g_mp4Vvc8bitPath.c_str());
1753 cout << g_mp4Vvc8bitPath.c_str() << "---------" << fd << "----------" << size <<endl;
1754 source = OH_AVSource_CreateWithFD(fd, 0, size);
1755 ASSERT_NE(source, nullptr);
1756 demuxer = OH_AVDemuxer_CreateWithSource(source);
1757 ASSERT_NE(demuxer, nullptr);
1758 sourceFormat = OH_AVSource_GetSourceFormat(source);
1759 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1760 ASSERT_EQ(1, g_trackCount);
1761 for (int32_t index = 0; index < g_trackCount; index++) {
1762 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1763 }
1764 int vKeyCount = 0;
1765 while (!videoIsEnd) {
1766 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1767 ASSERT_NE(trackFormat, nullptr);
1768 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1769 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
1770 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
1771 OH_AVFormat_Destroy(trackFormat);
1772 trackFormat = nullptr;
1773 }
1774 ASSERT_EQ(videoFrame, 600);
1775 ASSERT_EQ(vKeyCount, 10);
1776 close(fd);
1777 fd = -1;
1778 }
1779
1780 /**
1781 * @tc.number : VIDEO_DEMUXER_VVC_0200
1782 * @tc.name : demuxer 10bit H266 MP4 file, read
1783 * @tc.desc : function test
1784 */
1785 HWTEST_F(DemuxerProcNdkTest, VIDEO_DEMUXER_VVC_0200, TestSize.Level0)
1786 {
1787 if (access(g_mp4Vvc10bitPath.c_str(), F_OK) != 0) {
1788 return;
1789 }
1790 int tarckType = 0;
1791 OH_AVCodecBufferAttr attr;
1792 bool videoIsEnd = false;
1793 int videoFrame = 0;
1794 int fd = open(g_mp4Vvc10bitPath.c_str(), O_RDONLY);
1795 int64_t size = GetFileSize(g_mp4Vvc10bitPath.c_str());
1796 cout << g_mp4Vvc10bitPath.c_str() << "---------" << fd << "----------" << size <<endl;
1797 source = OH_AVSource_CreateWithFD(fd, 0, size);
1798 ASSERT_NE(source, nullptr);
1799 demuxer = OH_AVDemuxer_CreateWithSource(source);
1800 ASSERT_NE(demuxer, nullptr);
1801 sourceFormat = OH_AVSource_GetSourceFormat(source);
1802 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1803 ASSERT_EQ(2, g_trackCount);
1804 for (int32_t index = 0; index < g_trackCount; index++) {
1805 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1806 }
1807 int vKeyCount = 0;
1808 int aKeyCount = 0;
1809 int audioFrame = 0;
1810 bool audioIsEnd = false;
1811 while (!audioIsEnd || !videoIsEnd) {
1812 for (int32_t index = 0; index < g_trackCount; index++) {
1813 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1814 ASSERT_NE(trackFormat, nullptr);
1815 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1816 OH_AVFormat_Destroy(trackFormat);
1817 trackFormat = nullptr;
1818 if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
1819 continue;
1820 }
1821 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1822 if (tarckType == MEDIA_TYPE_VID) {
1823 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
1824 } else if (tarckType == MEDIA_TYPE_AUD) {
1825 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
1826 }
1827 }
1828 }
1829 ASSERT_EQ(audioFrame, 2812);
1830 ASSERT_EQ(aKeyCount, 2812);
1831 ASSERT_EQ(videoFrame, 3000);
1832 ASSERT_EQ(vKeyCount, 63);
1833 close(fd);
1834 fd = -1;
1835 }
1836
1837 /**
1838 * @tc.number : VIDEO_DEMUXER_VVC_0300
1839 * @tc.name : demuxer 8bit H266 MP4 file, read+seek
1840 * @tc.desc : function test
1841 */
1842 HWTEST_F(DemuxerProcNdkTest, VIDEO_DEMUXER_VVC_0300, TestSize.Level0)
1843 {
1844 if (access(g_mp4Vvc8bitPath.c_str(), F_OK) != 0) {
1845 return;
1846 }
1847 int64_t duration = 0;
1848 OH_AVCodecBufferAttr attr;
1849 int fd = open(g_mp4Vvc8bitPath.c_str(), O_RDONLY);
1850 int64_t size = GetFileSize(g_mp4Vvc8bitPath.c_str());
1851 cout << g_mp4Vvc8bitPath.c_str() << "---------" << fd << "----------" << size <<endl;
1852 source = OH_AVSource_CreateWithFD(fd, 0, size);
1853 ASSERT_NE(source, nullptr);
1854 demuxer = OH_AVDemuxer_CreateWithSource(source);
1855 ASSERT_NE(demuxer, nullptr);
1856 sourceFormat = OH_AVSource_GetSourceFormat(source);
1857 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1858 ASSERT_EQ(1, g_trackCount);
1859 for (int32_t index = 0; index < g_trackCount; index++) {
1860 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1861 }
1862 ASSERT_TRUE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_DURATION, &duration));
1863 ASSERT_EQ(duration, 10000000);
1864 for (int index = 0; index < (duration / 1000); index++) {
1865 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
1866 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, index, SEEK_MODE_CLOSEST_SYNC));
1867 }
1868 close(fd);
1869 fd = -1;
1870 }
1871
1872 /**
1873 * @tc.number : VIDEO_DEMUXER_VVC_0400
1874 * @tc.name : demuxer 10bit H266 MP4 file, read+seek
1875 * @tc.desc : function test
1876 */
1877 HWTEST_F(DemuxerProcNdkTest, VIDEO_DEMUXER_VVC_0400, TestSize.Level0)
1878 {
1879 if (access(g_mp4Vvc10bitPath.c_str(), F_OK) != 0) {
1880 return;
1881 }
1882 int64_t duration = 0;
1883 OH_AVCodecBufferAttr attr;
1884 int fd = open(g_mp4Vvc10bitPath.c_str(), O_RDONLY);
1885 int64_t size = GetFileSize(g_mp4Vvc10bitPath.c_str());
1886 cout << g_mp4Vvc10bitPath.c_str() << "---------" << fd << "----------" << size <<endl;
1887 source = OH_AVSource_CreateWithFD(fd, 0, size);
1888 ASSERT_NE(source, nullptr);
1889 demuxer = OH_AVDemuxer_CreateWithSource(source);
1890 ASSERT_NE(demuxer, nullptr);
1891 sourceFormat = OH_AVSource_GetSourceFormat(source);
1892 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1893 ASSERT_EQ(2, g_trackCount);
1894 for (int32_t index = 0; index < g_trackCount; index++) {
1895 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1896 }
1897 ASSERT_TRUE(OH_AVFormat_GetLongValue(sourceFormat, OH_MD_KEY_DURATION, &duration));
1898 ASSERT_EQ(duration, 60000000);
1899 for (int num = 0; num < (duration / 1000); num++) {
1900 for (int32_t index = 0; index < g_trackCount; index++) {
1901 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1902 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, num, SEEK_MODE_CLOSEST_SYNC));
1903 }
1904 }
1905 close(fd);
1906 fd = -1;
1907 }
1908
1909 /**
1910 * @tc.number : SUB_MEDIA_DEMUXER_AVI_PROCESS_0100
1911 * @tc.name : demuxer video and 2 audio file
1912 * @tc.desc : function test
1913 */
1914 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_AVI_PROCESS_0100, TestSize.Level2)
1915 {
1916 OH_AVCodecBufferAttr attr;
1917 const char *file = INP_DIR_1;
1918 g_fd = open(file, O_RDONLY);
1919 CheckFile(file, g_fd, &source, &demuxer, &g_trackCount);
1920 int tarckType = 0;
1921 int auidoTrackCount = 2;
1922 bool videoIsEnd = false;
1923 int videoFrame = 0;
1924 ASSERT_EQ(auidoTrackCount + 1, g_trackCount);
1925 for (int32_t index = 0; index < g_trackCount; index++) {
1926 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1927 }
1928 int vKeyCount = 0;
1929 int aKeyCount[2] = {};
1930 int audioFrame[2] = {};
1931 bool audioIsEnd1 = false;
1932 bool audioIsEnd2 = false;
1933 while (!audioIsEnd1 || !audioIsEnd2 || !videoIsEnd) {
1934 for (int32_t index = 0; index < g_trackCount; index++) {
1935 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1936 ASSERT_NE(trackFormat, nullptr);
1937 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1938 OH_AVFormat_Destroy(trackFormat);
1939 trackFormat = nullptr;
1940 if ((videoIsEnd && (index == 0)) || (audioIsEnd1 && (index == 1)) || (audioIsEnd2 && (index == 2))) {
1941 continue;
1942 }
1943 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1944 if (tarckType == MEDIA_TYPE_VID) {
1945 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
1946 }else if (tarckType == MEDIA_TYPE_AUD && index ==1) {
1947 SetAudioValue(attr, audioIsEnd1, audioFrame[index-1], aKeyCount[index-1]);
1948 }else if (tarckType == MEDIA_TYPE_AUD && index ==2) {
1949 SetAudioValue(attr, audioIsEnd2, audioFrame[index-1], aKeyCount[index-1]);
1950 }
1951 }
1952 }
1953 ASSERT_EQ(videoFrame, 25);
1954 ASSERT_EQ(vKeyCount, 3);
1955 ASSERT_EQ(audioFrame[0], 39);
1956 ASSERT_EQ(aKeyCount[0], 39);
1957 ASSERT_EQ(audioFrame[1], 14);
1958 ASSERT_EQ(aKeyCount[1], 14);
1959 close(g_fd);
1960 g_fd = -1;
1961 }
1962
1963 /**
1964 * @tc.number : SUB_MEDIA_DEMUXER_AVI_PROCESS_0200
1965 * @tc.name : demuxer audio and 2 video file
1966 * @tc.desc : function test
1967 */
1968 HWTEST_F(DemuxerProcNdkTest, SUB_MEDIA_DEMUXER_AVI_PROCESS_0200, TestSize.Level2)
1969 {
1970 OH_AVCodecBufferAttr attr;
1971 const char *file = INP_DIR_2;
1972 g_fd = open(file, O_RDONLY);
1973 CheckFile(file, g_fd, &source, &demuxer, &g_trackCount);
1974 int tarckType = 0;
1975 int videoTrackCount = 2;
1976 bool audioIsEnd = false;
1977 int audioFrame = 0;
1978 ASSERT_EQ(videoTrackCount + 1, g_trackCount);
1979 for (int32_t index = 0; index < g_trackCount; index++) {
1980 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1981 }
1982 int aKeyCount = 0;
1983 int vKeyCount[2] = {};
1984 int videoFrame[2] = {};
1985 bool videoIsEnd1 = false;
1986 bool videoIsEnd2 = false;
1987 while (!audioIsEnd || !videoIsEnd1 || !videoIsEnd2) {
1988 for (int32_t index = 0; index < g_trackCount; index++) {
1989 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1990 ASSERT_NE(trackFormat, nullptr);
1991 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1992 OH_AVFormat_Destroy(trackFormat);
1993 trackFormat = nullptr;
1994 if ((audioIsEnd && (index == 2)) || (videoIsEnd1 && (index == 0)) || (videoIsEnd2 && (index == 1))) {
1995 continue;
1996 }
1997 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1998 if (tarckType == MEDIA_TYPE_AUD) {
1999 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
2000 }else if (tarckType == MEDIA_TYPE_VID && index == 0) {
2001 SetVideoValue(attr, videoIsEnd1, videoFrame[index], vKeyCount[index]);
2002 }else if (tarckType == MEDIA_TYPE_VID && index == 1) {
2003 SetVideoValue(attr, videoIsEnd2, videoFrame[index], vKeyCount[index]);
2004 }
2005 }
2006 }
2007 ASSERT_EQ(videoFrame[0], 29);
2008 ASSERT_EQ(vKeyCount[0], 1);
2009 ASSERT_EQ(videoFrame[1], 29);
2010 ASSERT_EQ(vKeyCount[1], 1);
2011 ASSERT_EQ(audioFrame, 40);
2012 ASSERT_EQ(aKeyCount, 40);
2013 close(g_fd);
2014 g_fd = -1;
2015 }