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