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