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 DemuxerFuncNdkTest : 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 OH_AVMemory *memory = nullptr;
45 static OH_AVSource *source = nullptr;
46 static OH_AVErrCode ret = AV_ERR_OK;
47 static OH_AVDemuxer *demuxer = nullptr;
48 static OH_AVFormat *sourceFormat = nullptr;
49 static OH_AVFormat *trackFormat = nullptr;
50 static int32_t g_trackCount;
51 static int32_t g_width = 3840;
52 static int32_t g_height = 2160;
53 const std::string HEVC_LIB_PATH = std::string(AV_CODEC_PATH) + "/libav_codec_hevc_parser.z.so";
54
SetUpTestCase()55 void DemuxerFuncNdkTest::SetUpTestCase() {}
TearDownTestCase()56 void DemuxerFuncNdkTest::TearDownTestCase() {}
SetUp()57 void DemuxerFuncNdkTest::SetUp()
58 {
59 memory = OH_AVMemory_Create(g_width * g_height);
60 g_trackCount = 0;
61 }
TearDown()62 void DemuxerFuncNdkTest::TearDown()
63 {
64 if (trackFormat != nullptr) {
65 OH_AVFormat_Destroy(trackFormat);
66 trackFormat = nullptr;
67 }
68
69 if (sourceFormat != nullptr) {
70 OH_AVFormat_Destroy(sourceFormat);
71 sourceFormat = nullptr;
72 }
73
74 if (memory != nullptr) {
75 OH_AVMemory_Destroy(memory);
76 memory = nullptr;
77 }
78 if (source != nullptr) {
79 OH_AVSource_Destroy(source);
80 source = nullptr;
81 }
82 if (demuxer != nullptr) {
83 OH_AVDemuxer_Destroy(demuxer);
84 demuxer = nullptr;
85 }
86 }
87 } // namespace Media
88 } // namespace OHOS
89
90 using namespace std;
91 using namespace OHOS;
92 using namespace OHOS::Media;
93 using namespace testing::ext;
94
GetFileSize(const char *fileName)95 static int64_t GetFileSize(const char *fileName)
96 {
97 int64_t fileSize = 0;
98 if (fileName != nullptr) {
99 struct stat fileStatus {};
100 if (stat(fileName, &fileStatus) == 0) {
101 fileSize = static_cast<int64_t>(fileStatus.st_size);
102 }
103 }
104 return fileSize;
105 }
106
SetAudioValue(OH_AVCodecBufferAttr attr, bool &audioIsEnd, int &audioFrame, int &aKeyCount)107 static void SetAudioValue(OH_AVCodecBufferAttr attr, bool &audioIsEnd, int &audioFrame, int &aKeyCount)
108 {
109 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
110 audioIsEnd = true;
111 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
112 } else {
113 audioFrame++;
114 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
115 aKeyCount++;
116 }
117 }
118 }
119
SetVideoValue(OH_AVCodecBufferAttr attr, bool &videoIsEnd, int &videoFrame, int &vKeyCount)120 static void SetVideoValue(OH_AVCodecBufferAttr attr, bool &videoIsEnd, int &videoFrame, int &vKeyCount)
121 {
122 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
123 videoIsEnd = true;
124 cout << videoFrame << " video is end !!!!!!!!!!!!!!!" << endl;
125 } else {
126 videoFrame++;
127 cout << "video track !!!!!" << endl;
128 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
129 vKeyCount++;
130 }
131 }
132 }
133
SetVarValue(OH_AVCodecBufferAttr attr, const int &tarckType, bool &audioIsEnd, bool &videoIsEnd)134 static void SetVarValue(OH_AVCodecBufferAttr attr, const int &tarckType, bool &audioIsEnd, bool &videoIsEnd)
135 {
136 if (tarckType == 0 && (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS)) {
137 audioIsEnd = true;
138 cout << "audio is end !!!!!!!!!!!!!!!" << endl;
139 }
140
141 if (tarckType == 1 && (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS)) {
142 videoIsEnd = true;
143 cout << "video is end !!!!!!!!!!!!!!!" << endl;
144 }
145 }
146
SetFirstFrameFlag(bool &isFirstFrame)147 static void SetFirstFrameFlag(bool &isFirstFrame)
148 {
149 if (isFirstFrame) {
150 isFirstFrame = false;
151 }
152 }
153
SetEndFlag(bool &audioIsEnd, bool &videoIsEnd)154 static void SetEndFlag(bool &audioIsEnd, bool &videoIsEnd)
155 {
156 audioIsEnd = true;
157 videoIsEnd = true;
158 }
159
160 /**
161 * @tc.number : DEMUXER_FUNCTION_0200
162 * @tc.name : create source with no permission URI
163 * @tc.desc : function test
164 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_0200, TestSize.Level0)165 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_0200, TestSize.Level0)
166 {
167 const char *uri = "http://10.174.172.228:8080/share/audio/AAC_48000_1.aac";
168 source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
169 ASSERT_EQ(nullptr, source);
170 }
171
172 /**
173 * @tc.number : DEMUXER_FUNCTION_0300
174 * @tc.name : create source with invalid uri
175 * @tc.desc : function test
176 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_0300, TestSize.Level1)177 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_0300, TestSize.Level1)
178 {
179 const char *uri = "http://invalidPath/invalid.mp4";
180 source = OH_AVSource_CreateWithURI(const_cast<char *>(uri));
181 ASSERT_EQ(nullptr, source);
182 }
183
184 /**
185 * @tc.number : DEMUXER_FUNCTION_0400
186 * @tc.name : create source with fd but no permission
187 * @tc.desc : function test
188 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_0400, TestSize.Level1)189 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_0400, TestSize.Level1)
190 {
191 const char *file = "/data/media/noPermission.mp4";
192 int fd = open(file, O_RDONLY);
193 int64_t size = GetFileSize(file);
194 cout << file << "----------------------" << fd << "---------" << size << endl;
195 cout << file << "------" << size << endl;
196 source = OH_AVSource_CreateWithFD(fd, 0, size);
197 demuxer = OH_AVDemuxer_CreateWithSource(source);
198 ASSERT_EQ(demuxer, nullptr);
199
200 close(fd);
201 }
202
203 /**
204 * @tc.number : DEMUXER_FUNCTION_0500
205 * @tc.name : create source with invalid fd
206 * @tc.desc : function test
207 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_0500, TestSize.Level1)208 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_0500, TestSize.Level1)
209 {
210 const char *file = "/data/test/media/invalid.mp4";
211 int fd = open(file, O_RDONLY);
212 int64_t size = GetFileSize(file);
213 cout << file << "----------------------" << fd << "---------" << size << endl;
214 source = OH_AVSource_CreateWithFD(fd, 0, size);
215 ASSERT_EQ(source, nullptr);
216 close(fd);
217 }
218
219 /**
220 * @tc.number : DEMUXER_FUNCTION_0700
221 * @tc.name : create source with fd, mp4
222 * @tc.desc : function test
223 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_0700, TestSize.Level0)224 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_0700, TestSize.Level0)
225 {
226 int tarckType = 0;
227 OH_AVCodecBufferAttr attr;
228 bool audioIsEnd = false;
229 bool videoIsEnd = false;
230 const char *file = "/data/test/media/01_video_audio.mp4";
231 int fd = open(file, O_RDONLY);
232 int64_t size = GetFileSize(file);
233 cout << file << "----------------------" << fd << "---------" << size << endl;
234 source = OH_AVSource_CreateWithFD(fd, 0, size);
235 ASSERT_NE(source, nullptr);
236
237 demuxer = OH_AVDemuxer_CreateWithSource(source);
238 ASSERT_NE(demuxer, nullptr);
239
240 sourceFormat = OH_AVSource_GetSourceFormat(source);
241 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
242 ASSERT_EQ(2, g_trackCount);
243 for (int32_t index = 0; index < g_trackCount; index++) {
244 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
245 }
246
247 while (!audioIsEnd || !videoIsEnd) {
248 for (int32_t index = 0; index < g_trackCount; index++) {
249
250 trackFormat = OH_AVSource_GetTrackFormat(source, index);
251 ASSERT_NE(trackFormat, nullptr);
252 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
253
254 if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
255 continue;
256 }
257 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
258
259 SetVarValue(attr, tarckType, audioIsEnd, videoIsEnd);
260 }
261 }
262 close(fd);
263 }
264
265 /**
266 * @tc.number : DEMUXER_FUNCTION_0800
267 * @tc.name : create source with fd,avcc mp4
268 * @tc.desc : function test
269 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_0800, TestSize.Level0)270 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_0800, TestSize.Level0)
271 {
272 int tarckType = 0;
273 OH_AVCodecBufferAttr attr;
274 bool audioIsEnd = false;
275 bool videoIsEnd = false;
276 int audioFrame = 0;
277 int videoFrame = 0;
278 const char *file = "/data/test/media/avcc_10sec.mp4";
279 int fd = open(file, O_RDONLY);
280 int64_t size = GetFileSize(file);
281 cout << file << "----------------------" << fd << "---------" << size << endl;
282 source = OH_AVSource_CreateWithFD(fd, 0, size);
283 ASSERT_NE(source, nullptr);
284
285 demuxer = OH_AVDemuxer_CreateWithSource(source);
286 ASSERT_NE(demuxer, nullptr);
287
288 sourceFormat = OH_AVSource_GetSourceFormat(source);
289 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
290 ASSERT_EQ(2, g_trackCount);
291
292 for (int32_t index = 0; index < g_trackCount; index++) {
293 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
294 }
295
296 int aKeyCount = 0;
297 int vKeyCount = 0;
298 while (!audioIsEnd || !videoIsEnd) {
299 for (int32_t index = 0; index < g_trackCount; index++) {
300 trackFormat = OH_AVSource_GetTrackFormat(source, index);
301 ASSERT_NE(trackFormat, nullptr);
302 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
303
304 if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
305 continue;
306 }
307 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
308
309 if (tarckType == 0) {
310 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
311 } else if (tarckType == 1) {
312 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
313 }
314 }
315 }
316 ASSERT_EQ(audioFrame, 431);
317 ASSERT_EQ(videoFrame, 600);
318 ASSERT_EQ(aKeyCount, 431);
319 ASSERT_EQ(vKeyCount, 10);
320 close(fd);
321 }
322
323 /**
324 * @tc.number : DEMUXER_FUNCTION_0900
325 * @tc.name : create source with fd,hvcc mp4
326 * @tc.desc : function test
327 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_0900, TestSize.Level0)328 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_0900, TestSize.Level0)
329 {
330 int tarckType = 0;
331 OH_AVCodecBufferAttr attr;
332 bool audioIsEnd = false;
333 bool videoIsEnd = false;
334 int audioFrame = 0;
335 int videoFrame = 0;
336 const char *file = "/data/test/media/hvcc.mp4";
337 int fd = open(file, O_RDONLY);
338 int64_t size = GetFileSize(file);
339 source = OH_AVSource_CreateWithFD(fd, 0, size);
340 ASSERT_NE(source, nullptr);
341
342 demuxer = OH_AVDemuxer_CreateWithSource(source);
343 ASSERT_NE(demuxer, nullptr);
344
345 sourceFormat = OH_AVSource_GetSourceFormat(source);
346 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
347 ASSERT_EQ(2, g_trackCount);
348
349 for (int32_t index = 0; index < g_trackCount; index++) {
350 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
351 }
352
353 int aKeyCount = 0;
354 int vKeyCount = 0;
355 while (!audioIsEnd || !videoIsEnd) {
356 for (int32_t index = 0; index < g_trackCount; index++) {
357 trackFormat = OH_AVSource_GetTrackFormat(source, index);
358 ASSERT_NE(trackFormat, nullptr);
359 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
360
361 if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
362 continue;
363 }
364 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
365
366 if (tarckType == 0) {
367 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
368 } else if (tarckType == 1) {
369 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
370 }
371 }
372 }
373 ASSERT_EQ(audioFrame, 433);
374 ASSERT_EQ(videoFrame, 602);
375 ASSERT_EQ(aKeyCount, 433);
376 ASSERT_EQ(vKeyCount, 3);
377 close(fd);
378 }
379
380 /**
381 * @tc.number : DEMUXER_FUNCTION_1000
382 * @tc.name : create source with fd,mpeg mp4
383 * @tc.desc : function test
384 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1000, TestSize.Level0)385 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1000, TestSize.Level0)
386 {
387 int tarckType = 0;
388 OH_AVCodecBufferAttr attr;
389 bool audioIsEnd = false;
390 bool videoIsEnd = false;
391 int audioFrame = 0;
392 int videoFrame = 0;
393 const char *file = "/data/test/media/mpeg2.mp4";
394 int fd = open(file, O_RDONLY);
395 int64_t size = GetFileSize(file);
396 cout << file << "----------------------" << fd << "---------" << size << endl;
397 source = OH_AVSource_CreateWithFD(fd, 0, size);
398 ASSERT_NE(source, nullptr);
399
400 demuxer = OH_AVDemuxer_CreateWithSource(source);
401 ASSERT_NE(demuxer, nullptr);
402
403 sourceFormat = OH_AVSource_GetSourceFormat(source);
404 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
405 ASSERT_EQ(2, g_trackCount);
406
407 for (int32_t index = 0; index < g_trackCount; index++) {
408 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
409 }
410
411 int aKeyCount = 0;
412 int vKeyCount = 0;
413 while (!audioIsEnd || !videoIsEnd) {
414 for (int32_t index = 0; index < g_trackCount; index++) {
415 trackFormat = OH_AVSource_GetTrackFormat(source, index);
416 ASSERT_NE(trackFormat, nullptr);
417 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
418
419 if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
420 continue;
421 }
422 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
423
424 if (tarckType == 0) {
425 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
426 } else if (tarckType == 1) {
427 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
428 }
429 }
430 }
431
432 ASSERT_EQ(audioFrame, 433);
433 ASSERT_EQ(videoFrame, 303);
434 ASSERT_EQ(aKeyCount, 433);
435 ASSERT_EQ(vKeyCount, 26);
436 close(fd);
437 }
438
439 /**
440 * @tc.number : DEMUXER_FUNCTION_1100
441 * @tc.name : demux m4a
442 * @tc.desc : function test
443 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1100, TestSize.Level0)444 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1100, TestSize.Level0)
445 {
446 OH_AVCodecBufferAttr attr;
447 bool audioIsEnd = false;
448 int audioFrame = 0;
449
450 const char *file = "/data/test/media/audio/M4A_48000_1.m4a";
451 int fd = open(file, O_RDONLY);
452 int64_t size = GetFileSize(file);
453 cout << file << "----------------------" << fd << "---------" << size << endl;
454 source = OH_AVSource_CreateWithFD(fd, 0, size);
455 ASSERT_NE(source, nullptr);
456
457 demuxer = OH_AVDemuxer_CreateWithSource(source);
458 ASSERT_NE(demuxer, nullptr);
459
460 sourceFormat = OH_AVSource_GetSourceFormat(source);
461 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
462 ASSERT_EQ(1, g_trackCount);
463
464 for (int32_t index = 0; index < g_trackCount; index++) {
465 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
466 }
467
468 int keyCount = 0;
469 while (!audioIsEnd) {
470 for (int32_t index = 0; index < g_trackCount; index++) {
471 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
472 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
473 audioIsEnd = true;
474 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
475 continue;
476 }
477
478 audioFrame++;
479 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
480 keyCount++;
481 }
482 }
483 }
484
485 ASSERT_EQ(audioFrame, 10293);
486 ASSERT_EQ(keyCount, 10293);
487 close(fd);
488 }
489
490 /**
491 * @tc.number : DEMUXER_FUNCTION_1200
492 * @tc.name : demux aac
493 * @tc.desc : function test
494 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1200, TestSize.Level0)495 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1200, TestSize.Level0)
496 {
497 OH_AVCodecBufferAttr attr;
498 bool audioIsEnd = false;
499 int audioFrame = 0;
500
501 const char *file = "/data/test/media/audio/AAC_48000_1.aac";
502 int fd = open(file, O_RDONLY);
503 int64_t size = GetFileSize(file);
504 cout << file << "----------------------" << fd << "---------" << size << endl;
505 source = OH_AVSource_CreateWithFD(fd, 0, size);
506 ASSERT_NE(source, nullptr);
507
508 demuxer = OH_AVDemuxer_CreateWithSource(source);
509 ASSERT_NE(demuxer, nullptr);
510
511 sourceFormat = OH_AVSource_GetSourceFormat(source);
512 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
513 ASSERT_EQ(1, g_trackCount);
514
515 for (int32_t index = 0; index < g_trackCount; index++) {
516 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
517 }
518 int keyCount = 0;
519 while (!audioIsEnd) {
520 for (int32_t index = 0; index < g_trackCount; index++) {
521 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
522 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
523 audioIsEnd = true;
524 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
525 continue;
526 }
527
528 audioFrame++;
529 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
530 keyCount++;
531 }
532 }
533 }
534 ASSERT_EQ(audioFrame, 9457);
535 ASSERT_EQ(keyCount, 9457);
536 close(fd);
537 }
538
539 /**
540 * @tc.number : DEMUXER_FUNCTION_1300
541 * @tc.name : demux mp3
542 * @tc.desc : function test
543 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1300, TestSize.Level0)544 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1300, TestSize.Level0)
545 {
546 OH_AVCodecBufferAttr attr;
547 bool audioIsEnd = false;
548 int audioFrame = 0;
549
550 const char *file = "/data/test/media/audio/MP3_48000_1.mp3";
551 int fd = open(file, O_RDONLY);
552 int64_t size = GetFileSize(file);
553 cout << file << "----------------------" << fd << "---------" << size << endl;
554 source = OH_AVSource_CreateWithFD(fd, 0, size);
555 ASSERT_NE(source, nullptr);
556
557 demuxer = OH_AVDemuxer_CreateWithSource(source);
558 ASSERT_NE(demuxer, nullptr);
559
560 sourceFormat = OH_AVSource_GetSourceFormat(source);
561 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
562 ASSERT_EQ(1, g_trackCount);
563
564 for (int32_t index = 0; index < g_trackCount; index++) {
565 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
566 }
567 int keyCount = 0;
568 while (!audioIsEnd) {
569 for (int32_t index = 0; index < g_trackCount; index++) {
570 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
571 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
572 audioIsEnd = true;
573 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
574 continue;
575 }
576
577 audioFrame++;
578 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
579 keyCount++;
580 }
581 }
582 }
583 ASSERT_EQ(audioFrame, 9150);
584 ASSERT_EQ(keyCount, 9150);
585 close(fd);
586 }
587
588 /**
589 * @tc.number : DEMUXER_FUNCTION_1400
590 * @tc.name : demux ogg
591 * @tc.desc : function test
592 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1400, TestSize.Level0)593 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1400, TestSize.Level0)
594 {
595 OH_AVCodecBufferAttr attr;
596 bool audioIsEnd = false;
597 int audioFrame = 0;
598
599 const char *file = "/data/test/media/audio/OGG_48000_1.ogg";
600 int fd = open(file, O_RDONLY);
601 int64_t size = GetFileSize(file);
602 cout << file << "----------------------" << fd << "---------" << size << endl;
603 source = OH_AVSource_CreateWithFD(fd, 0, size);
604 ASSERT_NE(source, nullptr);
605
606 demuxer = OH_AVDemuxer_CreateWithSource(source);
607 ASSERT_NE(demuxer, nullptr);
608
609 sourceFormat = OH_AVSource_GetSourceFormat(source);
610 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
611 ASSERT_EQ(1, g_trackCount);
612
613 for (int32_t index = 0; index < g_trackCount; index++) {
614 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
615 }
616 int keyCount = 0;
617 while (!audioIsEnd) {
618 for (int32_t index = 0; index < g_trackCount; index++) {
619 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
620 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
621 audioIsEnd = true;
622 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
623 continue;
624 }
625
626 audioFrame++;
627 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
628 keyCount++;
629 }
630 }
631 }
632 ASSERT_EQ(audioFrame, 11439);
633 ASSERT_EQ(keyCount, 11439);
634 close(fd);
635 }
636
637 /**
638 * @tc.number : DEMUXER_FUNCTION_1500
639 * @tc.name : demux flac
640 * @tc.desc : function test
641 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1500, TestSize.Level0)642 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1500, TestSize.Level0)
643 {
644 OH_AVCodecBufferAttr attr;
645 bool audioIsEnd = false;
646 int audioFrame = 0;
647
648 const char *file = "/data/test/media/audio/FLAC_48000_1.flac";
649 int fd = open(file, O_RDONLY);
650 int64_t size = GetFileSize(file);
651 cout << file << "----------------------" << fd << "---------" << size << endl;
652 source = OH_AVSource_CreateWithFD(fd, 0, size);
653 ASSERT_NE(source, nullptr);
654
655 demuxer = OH_AVDemuxer_CreateWithSource(source);
656 ASSERT_NE(demuxer, nullptr);
657
658 sourceFormat = OH_AVSource_GetSourceFormat(source);
659 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
660 ASSERT_EQ(1, g_trackCount);
661
662 for (int32_t index = 0; index < g_trackCount; index++) {
663 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
664 }
665
666 int keyCount = 0;
667 while (!audioIsEnd) {
668 for (int32_t index = 0; index < g_trackCount; index++) {
669 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
670 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
671 audioIsEnd = true;
672 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
673 continue;
674 }
675
676 audioFrame++;
677 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
678 keyCount++;
679 }
680 }
681 }
682 ASSERT_EQ(audioFrame, 2288);
683 ASSERT_EQ(keyCount, 2288);
684 close(fd);
685 }
686
687 /**
688 * @tc.number : DEMUXER_FUNCTION_1600
689 * @tc.name : demux wav
690 * @tc.desc : function test
691 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1600, TestSize.Level0)692 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1600, TestSize.Level0)
693 {
694 OH_AVCodecBufferAttr attr;
695 bool audioIsEnd = false;
696 int audioFrame = 0;
697
698 const char *file = "/data/test/media/audio/wav_48000_1.wav";
699 int fd = open(file, O_RDONLY);
700 int64_t size = GetFileSize(file);
701 cout << file << "----------------------" << fd << "---------" << size << endl;
702 source = OH_AVSource_CreateWithFD(fd, 0, size);
703 ASSERT_NE(source, nullptr);
704
705 demuxer = OH_AVDemuxer_CreateWithSource(source);
706 ASSERT_NE(demuxer, nullptr);
707
708 sourceFormat = OH_AVSource_GetSourceFormat(source);
709 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
710 ASSERT_EQ(1, g_trackCount);
711
712 for (int32_t index = 0; index < g_trackCount; index++) {
713 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
714 }
715
716 int keyCount = 0;
717 while (!audioIsEnd) {
718 for (int32_t index = 0; index < g_trackCount; index++) {
719 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
720 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
721 audioIsEnd = true;
722 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
723 continue;
724 }
725
726 audioFrame++;
727 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
728 keyCount++;
729 }
730 }
731 }
732 ASSERT_EQ(audioFrame, 5146);
733 ASSERT_EQ(keyCount, 5146);
734 close(fd);
735 }
736
737 /**
738 * @tc.number : DEMUXER_FUNCTION_1700
739 * @tc.name : demux mpeg-ts
740 * @tc.desc : function test
741 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1700, TestSize.Level0)742 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1700, TestSize.Level0)
743 {
744 int tarckType = 0;
745 OH_AVCodecBufferAttr attr;
746 bool audioIsEnd = false;
747 bool videoIsEnd = false;
748 int audioFrame = 0;
749 int videoFrame = 0;
750 const char *file = "/data/test/media/ts_video.ts";
751 int fd = open(file, O_RDONLY);
752 int64_t size = GetFileSize(file);
753 cout << file << "----------------------" << fd << "---------" << size << endl;
754 source = OH_AVSource_CreateWithFD(fd, 0, size);
755 ASSERT_NE(source, nullptr);
756
757 demuxer = OH_AVDemuxer_CreateWithSource(source);
758 ASSERT_NE(demuxer, nullptr);
759
760 sourceFormat = OH_AVSource_GetSourceFormat(source);
761 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
762 ASSERT_EQ(2, g_trackCount);
763
764 for (int32_t index = 0; index < g_trackCount; index++) {
765 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
766 }
767
768 int vKeyCount = 0;
769 int aKeyCount = 0;
770 while (!audioIsEnd || !videoIsEnd) {
771 for (int32_t index = 0; index < g_trackCount; index++) {
772
773 trackFormat = OH_AVSource_GetTrackFormat(source, index);
774 ASSERT_NE(trackFormat, nullptr);
775 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
776
777 if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
778 continue;
779 }
780 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
781
782 if (tarckType == 0) {
783 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
784 } else if (tarckType == 1) {
785 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
786 }
787 }
788 }
789 ASSERT_EQ(audioFrame, 384);
790 ASSERT_EQ(aKeyCount, 384);
791 ASSERT_EQ(videoFrame, 602);
792 ASSERT_EQ(vKeyCount, 51);
793 close(fd);
794 }
795
796 /**
797 * @tc.number : DEMUXER_FUNCTION_1800
798 * @tc.name : demux unsupported source
799 * @tc.desc : function test
800 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1800, TestSize.Level2)801 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1800, TestSize.Level2)
802 {
803 const char *file = "/data/test/media/mkv.mkv";
804 int fd = open(file, O_RDONLY);
805 int64_t size = GetFileSize(file);
806 cout << file << "----------------------" << fd << "---------" << size << endl;
807 source = OH_AVSource_CreateWithFD(fd, 0, size);
808 ASSERT_NE(source, nullptr);
809 close(fd);
810 }
811
812 /**
813 * @tc.number : DEMUXER_FUNCTION_1900
814 * @tc.name : demux mp4, zero track
815 * @tc.desc : function test
816 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1900, TestSize.Level1)817 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_1900, TestSize.Level1)
818 {
819 const char *file = "/data/test/media/zero_track.mp4";
820 int fd = open(file, O_RDONLY);
821 int64_t size = GetFileSize(file);
822 cout << file << "----------------------" << fd << "---------" << size << endl;
823 source = OH_AVSource_CreateWithFD(fd, 0, size);
824 ASSERT_NE(source, nullptr);
825 demuxer = OH_AVDemuxer_CreateWithSource(source);
826 ASSERT_NE(demuxer, nullptr);
827
828 sourceFormat = OH_AVSource_GetSourceFormat(source);
829 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
830 ASSERT_EQ(g_trackCount, 0);
831
832 ASSERT_EQ(AV_ERR_INVALID_VAL, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
833 close(fd);
834 }
835
836 /**
837 * @tc.number : DEMUXER_FUNCTION_2000
838 * @tc.name : OH_AVSource_CreateWithFD test
839 * @tc.desc : function test
840 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_2000, TestSize.Level0)841 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_2000, TestSize.Level0)
842 {
843 OH_AVCodecBufferAttr attr;
844 bool audioIsEnd = false;
845 int audioFrame = 0;
846
847 const char *file1 = "/data/test/media/audio/MP3_48000_1.mp3";
848 int64_t size1 = GetFileSize(file1);
849
850 const char *file = "/data/test/media/MP3_avcc_10sec.bin";
851 int fd = open(file, O_RDONLY);
852 int64_t size = GetFileSize(file);
853 cout << file << "----------------------" << fd << "---------" << size << endl;
854 source = OH_AVSource_CreateWithFD(fd, 0, size1);
855 ASSERT_NE(source, nullptr);
856
857 demuxer = OH_AVDemuxer_CreateWithSource(source);
858 ASSERT_NE(demuxer, nullptr);
859
860 sourceFormat = OH_AVSource_GetSourceFormat(source);
861 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
862 ASSERT_EQ(1, g_trackCount);
863
864 for (int32_t index = 0; index < g_trackCount; index++) {
865 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
866 }
867
868 int keyCount = 0;
869 while (!audioIsEnd) {
870 for (int32_t index = 0; index < g_trackCount; index++) {
871 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
872 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
873 audioIsEnd = true;
874 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
875 continue;
876 }
877
878 audioFrame++;
879 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
880 keyCount++;
881 }
882 }
883 }
884 ASSERT_EQ(audioFrame, 9150);
885 ASSERT_EQ(keyCount, 9150);
886 close(fd);
887 }
888
889 /**
890 * @tc.number : DEMUXER_FUNCTION_2100
891 * @tc.name : OH_AVSource_CreateWithFD test
892 * @tc.desc : function test
893 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_2100, TestSize.Level0)894 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_2100, TestSize.Level0)
895 {
896 OH_AVCodecBufferAttr attr;
897 bool audioIsEnd = false;
898 bool videoIsEnd = false;
899 int audioFrame = 0;
900 int videoFrame = 0;
901 const char *file1 = "/data/test/media/audio/MP3_48000_1.mp3";
902 int64_t size1 = GetFileSize(file1);
903
904 const char *file2 = "/data/test/media/avcc_10sec.mp4";
905 int64_t size2 = GetFileSize(file2);
906
907 const char *file = "/data/test/media/MP3_avcc_10sec.bin";
908 int fd = open(file, O_RDONLY);
909 int64_t size = GetFileSize(file);
910 cout << file << "----------------------" << fd << "---------" << size << endl;
911 source = OH_AVSource_CreateWithFD(fd, size1, size2);
912 ASSERT_NE(source, nullptr);
913
914 demuxer = OH_AVDemuxer_CreateWithSource(source);
915 ASSERT_NE(demuxer, nullptr);
916
917 sourceFormat = OH_AVSource_GetSourceFormat(source);
918 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
919 ASSERT_EQ(2, g_trackCount);
920
921 for (int32_t index = 0; index < g_trackCount; index++) {
922 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
923 }
924 int tarckType = 0;
925 int aKeyCount = 0;
926 int vKeyCount = 0;
927 while (!audioIsEnd || !videoIsEnd) {
928 for (int32_t index = 0; index < g_trackCount; index++) {
929 trackFormat = OH_AVSource_GetTrackFormat(source, index);
930 ASSERT_NE(trackFormat, nullptr);
931 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
932
933 if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
934 continue;
935 }
936 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
937
938 if (tarckType == 0) {
939 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
940 } else if (tarckType == 1) {
941 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
942 }
943 }
944 }
945 ASSERT_EQ(audioFrame, 431);
946 ASSERT_EQ(videoFrame, 600);
947 ASSERT_EQ(aKeyCount, 431);
948 ASSERT_EQ(vKeyCount, 10);
949 close(fd);
950 }
951
952 /**
953 * @tc.number : DEMUXER_FUNCTION_2200
954 * @tc.name : OH_AVSource_CreateWithFD test
955 * @tc.desc : function test
956 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_2200, TestSize.Level0)957 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_2200, TestSize.Level0)
958 {
959 OH_AVCodecBufferAttr attr;
960 bool audioIsEnd = false;
961 int audioFrame = 0;
962
963 const char *file1 = "/data/test/media/audio/MP3_48000_1.mp3";
964 int64_t size1 = GetFileSize(file1);
965
966 const char *file = "/data/test/media/MP3_OGG_48000_1.bin";
967 int fd = open(file, O_RDONLY);
968 int64_t size = GetFileSize(file);
969 cout << file << "----------------------" << fd << "---------" << size << endl;
970 source = OH_AVSource_CreateWithFD(fd, 0, size1);
971 ASSERT_NE(source, nullptr);
972
973 demuxer = OH_AVDemuxer_CreateWithSource(source);
974 ASSERT_NE(demuxer, nullptr);
975
976 sourceFormat = OH_AVSource_GetSourceFormat(source);
977 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
978 ASSERT_EQ(1, g_trackCount);
979
980 for (int32_t index = 0; index < g_trackCount; index++) {
981 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
982 }
983
984 int keyCount = 0;
985 while (!audioIsEnd) {
986 for (int32_t index = 0; index < g_trackCount; index++) {
987 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
988 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
989 audioIsEnd = true;
990 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
991 continue;
992 }
993
994 audioFrame++;
995 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
996 keyCount++;
997 }
998 }
999 }
1000 ASSERT_EQ(audioFrame, 9150);
1001 ASSERT_EQ(keyCount, 9150);
1002 close(fd);
1003 }
1004
1005 /**
1006 * @tc.number : DEMUXER_FUNCTION_2300
1007 * @tc.name : OH_AVSource_CreateWithFD test
1008 * @tc.desc : function test
1009 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_2300, TestSize.Level0)1010 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_2300, TestSize.Level0)
1011 {
1012 OH_AVCodecBufferAttr attr;
1013 bool audioIsEnd = false;
1014 int audioFrame = 0;
1015
1016 const char *file1 = "/data/test/media/audio/MP3_48000_1.mp3";
1017 int64_t size1 = GetFileSize(file1);
1018
1019 const char *file2 = "/data/test/media/audio/OGG_48000_1.ogg";
1020 int64_t size2 = GetFileSize(file2);
1021
1022 const char *file = "/data/test/media/MP3_OGG_48000_1.bin";
1023 int fd = open(file, O_RDONLY);
1024 int64_t size = GetFileSize(file);
1025 cout << file << "----------------------" << fd << "---------" << size << endl;
1026 source = OH_AVSource_CreateWithFD(fd, size1, size2);
1027 ASSERT_NE(source, nullptr);
1028
1029 demuxer = OH_AVDemuxer_CreateWithSource(source);
1030 ASSERT_NE(demuxer, nullptr);
1031
1032 sourceFormat = OH_AVSource_GetSourceFormat(source);
1033 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1034 ASSERT_EQ(1, g_trackCount);
1035
1036 for (int32_t index = 0; index < g_trackCount; index++) {
1037 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1038 }
1039
1040 int keyCount = 0;
1041 while (!audioIsEnd) {
1042 for (int32_t index = 0; index < g_trackCount; index++) {
1043 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1044 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1045 audioIsEnd = true;
1046 cout << audioFrame << " audio is end !!!!!!!!!!!!!!!" << endl;
1047 continue;
1048 }
1049
1050 audioFrame++;
1051 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_SYNC_FRAME) {
1052 keyCount++;
1053 }
1054 }
1055 }
1056 ASSERT_EQ(audioFrame, 11439);
1057 ASSERT_EQ(keyCount, 11439);
1058 close(fd);
1059 }
1060
1061 /**
1062 * @tc.number : DEMUXER_FUNCTION_2400
1063 * @tc.name : OH_AVSource_CreateWithFD test
1064 * @tc.desc : function test
1065 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_2400, TestSize.Level0)1066 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_2400, TestSize.Level0)
1067 {
1068 OH_AVCodecBufferAttr attr;
1069 bool audioIsEnd = false;
1070 bool videoIsEnd = false;
1071 int audioFrame = 0;
1072 int videoFrame = 0;
1073 const char *file1 = "/data/test/media/ts_video.ts";
1074 int64_t size1 = GetFileSize(file1);
1075
1076 const char *file = "/data/test/media/test_video_avcc_10sec.bin";
1077 int fd = open(file, O_RDONLY);
1078 int64_t size = GetFileSize(file);
1079 cout << file << "----------------------" << fd << "---------" << size << endl;
1080 source = OH_AVSource_CreateWithFD(fd, 0, size1);
1081 ASSERT_NE(source, nullptr);
1082
1083 demuxer = OH_AVDemuxer_CreateWithSource(source);
1084 ASSERT_NE(demuxer, nullptr);
1085
1086 sourceFormat = OH_AVSource_GetSourceFormat(source);
1087 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1088 ASSERT_EQ(2, g_trackCount);
1089
1090 for (int32_t index = 0; index < g_trackCount; index++) {
1091 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1092 }
1093 int tarckType = 0;
1094 int aKeyCount = 0;
1095 int vKeyCount = 0;
1096 while (!audioIsEnd || !videoIsEnd) {
1097 for (int32_t index = 0; index < g_trackCount; index++) {
1098 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1099 ASSERT_NE(trackFormat, nullptr);
1100 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1101
1102 if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
1103 continue;
1104 }
1105 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1106
1107 if (tarckType == 0) {
1108 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
1109 } else if (tarckType == 1) {
1110 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
1111 }
1112 }
1113 }
1114 ASSERT_EQ(audioFrame, 384);
1115 ASSERT_EQ(videoFrame, 602);
1116 ASSERT_EQ(aKeyCount, 384);
1117 ASSERT_EQ(vKeyCount, 51);
1118 close(fd);
1119 }
1120
1121 /**
1122 * @tc.number : DEMUXER_FUNCTION_3100
1123 * @tc.name : seek to the start time, previous mode
1124 * @tc.desc : function test
1125 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3100, TestSize.Level1)1126 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3100, TestSize.Level1)
1127 {
1128 uint32_t trackIndex = 0;
1129 OH_AVCodecBufferAttr attr;
1130 const char *file = "/data/test/media/01_video_audio.mp4";
1131 int count = 0;
1132 srand(time(nullptr));
1133 int fd = open(file, O_RDONLY);
1134 int64_t size = GetFileSize(file);
1135 cout << file << "----------------------" << fd << "---------" << size << endl;
1136 source = OH_AVSource_CreateWithFD(fd, 0, size);
1137 ASSERT_NE(source, nullptr);
1138
1139 demuxer = OH_AVDemuxer_CreateWithSource(source);
1140 ASSERT_NE(demuxer, nullptr);
1141
1142 int pos = rand() % 250;
1143 int64_t startPts = 0;
1144 bool isFirstFrame = true;
1145 bool isEnd = false;
1146 sourceFormat = OH_AVSource_GetSourceFormat(source);
1147 ASSERT_NE(sourceFormat, nullptr);
1148 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1149 cout << g_trackCount << "####################" << endl;
1150
1151 for (int32_t index = 0; index < g_trackCount; index++) {
1152 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1153 }
1154
1155 while (!isEnd) {
1156 for (int32_t index = 0; index < g_trackCount; index++) {
1157 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1158
1159 if (isFirstFrame) {
1160 startPts = attr.pts;
1161 isFirstFrame = false;
1162 }
1163 if (count == pos) {
1164 isEnd = true;
1165 cout << pos << " =====curr_pts = attr.pts" << endl;
1166 break;
1167 }
1168 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1169 isEnd = true;
1170 cout << "is end!!!!!!!!" << endl;
1171 }
1172 count++;
1173 }
1174 cout << "count: " << count << endl;
1175 }
1176 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, startPts / 1000, SEEK_MODE_PREVIOUS_SYNC));
1177 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &attr));
1178 ASSERT_EQ(attr.pts, startPts);
1179 close(fd);
1180 }
1181
1182 /**
1183 * @tc.number : DEMUXER_FUNCTION_3200
1184 * @tc.name : seek to the start time, next mode
1185 * @tc.desc : function test
1186 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3200, TestSize.Level1)1187 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3200, TestSize.Level1)
1188 {
1189 bool isEnd = false;
1190 uint32_t trackIndex = 0;
1191 OH_AVCodecBufferAttr attr;
1192 const char *file = "/data/test/media/01_video_audio.mp4";
1193 int count = 0;
1194 srand(time(nullptr));
1195 int fd = open(file, O_RDONLY);
1196 int64_t size = GetFileSize(file);
1197 cout << file << "----------------------" << fd << "---------" << size << endl;
1198 source = OH_AVSource_CreateWithFD(fd, 0, size);
1199 ASSERT_NE(source, nullptr);
1200
1201 demuxer = OH_AVDemuxer_CreateWithSource(source);
1202 ASSERT_NE(demuxer, nullptr);
1203
1204 int pos = rand() % 250;
1205 int64_t startPts = 0;
1206 bool isFirstFrame = true;
1207 sourceFormat = OH_AVSource_GetSourceFormat(source);
1208 ASSERT_NE(sourceFormat, nullptr);
1209 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1210
1211 for (int32_t index = 0; index < g_trackCount; index++) {
1212 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1213 }
1214
1215 while (!isEnd) {
1216 for (int32_t index = 0; index < g_trackCount; index++) {
1217 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1218
1219 if (isFirstFrame) {
1220 startPts = attr.pts;
1221 isFirstFrame = false;
1222 }
1223 if (count == pos) {
1224 isEnd = true;
1225 cout << "curr_pts = attr.pts" << endl;
1226 break;
1227 }
1228 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1229 isEnd = true;
1230 cout << "is end!!!!!!!!" << endl;
1231 }
1232 count++;
1233 }
1234 cout << "count: " << count << endl;
1235 }
1236
1237 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, startPts / 1000, SEEK_MODE_NEXT_SYNC));
1238 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &attr));
1239 ASSERT_EQ(attr.pts, startPts);
1240 close(fd);
1241 }
1242
1243 /**
1244 * @tc.number : DEMUXER_FUNCTION_3300
1245 * @tc.name : seek to the start time, closest mode
1246 * @tc.desc : function test
1247 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3300, TestSize.Level1)1248 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3300, TestSize.Level1)
1249 {
1250 bool isEnd = false;
1251 uint32_t trackIndex = 0;
1252 OH_AVCodecBufferAttr attr;
1253 const char *file = "/data/test/media/01_video_audio.mp4";
1254 int count = 0;
1255 srand(time(nullptr));
1256 int fd = open(file, O_RDONLY);
1257 int64_t size = GetFileSize(file);
1258 cout << file << "----------------------" << fd << "---------" << size << endl;
1259 source = OH_AVSource_CreateWithFD(fd, 0, size);
1260 ASSERT_NE(source, nullptr);
1261
1262 demuxer = OH_AVDemuxer_CreateWithSource(source);
1263 ASSERT_NE(demuxer, nullptr);
1264
1265 int pos = rand() % 250;
1266 int64_t startPts = 0;
1267 bool isFirstFrame = true;
1268 sourceFormat = OH_AVSource_GetSourceFormat(source);
1269 ASSERT_NE(sourceFormat, nullptr);
1270 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1271
1272 for (int32_t index = 0; index < g_trackCount; index++) {
1273 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1274 }
1275
1276 while (!isEnd) {
1277 for (int32_t index = 0; index < g_trackCount; index++) {
1278 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1279
1280 if (isFirstFrame) {
1281 startPts = attr.pts;
1282 isFirstFrame = false;
1283 }
1284 if (count == pos) {
1285 isEnd = true;
1286 cout << "curr_pts = attr.pts" << endl;
1287 break;
1288 }
1289 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1290 isEnd = true;
1291 cout << "is end!!!!!!!!" << endl;
1292 }
1293 count++;
1294 }
1295 cout << "count: " << count << endl;
1296 }
1297 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, startPts / 1000, SEEK_MODE_CLOSEST_SYNC));
1298 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &attr));
1299 ASSERT_EQ(attr.pts, startPts);
1300 close(fd);
1301 }
1302
1303 /**
1304 * @tc.number : DEMUXER_FUNCTION_3400
1305 * @tc.name : seek to the end time, previous mode
1306 * @tc.desc : function test
1307 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3400, TestSize.Level1)1308 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3400, TestSize.Level1)
1309 {
1310 bool isEnd = false;
1311 uint32_t trackIndex = 1;
1312 OH_AVCodecBufferAttr attr;
1313 const char *file = "/data/test/media/01_video_audio.mp4";
1314 int count = 0;
1315 srand(time(nullptr));
1316 int fd = open(file, O_RDONLY);
1317 int64_t size = GetFileSize(file);
1318 cout << file << "----------------------" << fd << "---------" << size << endl;
1319 source = OH_AVSource_CreateWithFD(fd, 0, size);
1320 ASSERT_NE(source, nullptr);
1321
1322 demuxer = OH_AVDemuxer_CreateWithSource(source);
1323 ASSERT_NE(demuxer, nullptr);
1324
1325 sourceFormat = OH_AVSource_GetSourceFormat(source);
1326 ASSERT_NE(sourceFormat, nullptr);
1327 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1328 cout << g_trackCount << "####################" << endl;
1329
1330 for (int32_t index = 0; index < g_trackCount; index++) {
1331 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1332 }
1333
1334 int64_t endPts = 0;
1335 while (!isEnd) {
1336 for (int32_t index = 0; index < g_trackCount; index++) {
1337 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1338
1339 if (static_cast<uint32_t>(index) != trackIndex) {
1340 continue;
1341 }
1342 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1343 isEnd = true;
1344 cout << "is end!!!!!!!!" << endl;
1345 } else {
1346 endPts = attr.pts;
1347 }
1348 count++;
1349 }
1350 cout << "count: " << count << endl;
1351 }
1352 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, endPts / 1000, SEEK_MODE_PREVIOUS_SYNC));
1353 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &attr));
1354 ASSERT_EQ(attr.pts, endPts);
1355 close(fd);
1356 }
1357
1358 /**
1359 * @tc.number : DEMUXER_FUNCTION_3500
1360 * @tc.name : seek to the end time, next mode
1361 * @tc.desc : function test
1362 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3500, TestSize.Level1)1363 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3500, TestSize.Level1)
1364 {
1365 bool isEnd = false;
1366 uint32_t trackIndex = 1;
1367 OH_AVCodecBufferAttr attr;
1368 const char *file = "/data/test/media/01_video_audio.mp4";
1369 int count = 0;
1370 srand(time(nullptr));
1371 int fd = open(file, O_RDONLY);
1372 int64_t size = GetFileSize(file);
1373 cout << file << "----------------------" << fd << "---------" << size << endl;
1374 source = OH_AVSource_CreateWithFD(fd, 0, size);
1375 ASSERT_NE(source, nullptr);
1376
1377 demuxer = OH_AVDemuxer_CreateWithSource(source);
1378 ASSERT_NE(demuxer, nullptr);
1379 sourceFormat = OH_AVSource_GetSourceFormat(source);
1380 ASSERT_NE(sourceFormat, nullptr);
1381 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1382 cout << g_trackCount << "####################" << endl;
1383
1384 for (int32_t index = 0; index < g_trackCount; index++) {
1385 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1386 }
1387 int64_t endPts = 0;
1388 while (!isEnd) {
1389 for (int32_t index = 0; index < g_trackCount; index++) {
1390 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1391 if (static_cast<uint32_t>(index) != trackIndex) {
1392 continue;
1393 }
1394 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1395 isEnd = true;
1396 cout << "is end!!!!!!!!" << endl;
1397 } else {
1398 endPts = attr.pts;
1399 }
1400 count++;
1401 }
1402 cout << "count: " << count << endl;
1403 }
1404 // end I
1405 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, endPts / 1000, SEEK_MODE_NEXT_SYNC));
1406 endPts += 1000;
1407 ASSERT_EQ(AV_ERR_UNKNOWN, OH_AVDemuxer_SeekToTime(demuxer, endPts / 1000, SEEK_MODE_NEXT_SYNC));
1408 endPts += 1000000;
1409 ASSERT_EQ(AV_ERR_OPERATE_NOT_PERMIT, OH_AVDemuxer_SeekToTime(demuxer, endPts / 1000, SEEK_MODE_NEXT_SYNC));
1410 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &attr));
1411 close(fd);
1412 }
1413
1414 /**
1415 * @tc.number : DEMUXER_FUNCTION_3600
1416 * @tc.name : seek to the end time, closest mode
1417 * @tc.desc : function test
1418 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3600, TestSize.Level1)1419 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3600, TestSize.Level1)
1420 {
1421 bool isEnd = false;
1422 uint32_t trackIndex = 1;
1423 OH_AVCodecBufferAttr attr;
1424 const char *file = "/data/test/media/01_video_audio.mp4";
1425 int count = 0;
1426 srand(time(nullptr));
1427 int fd = open(file, O_RDONLY);
1428 int64_t size = GetFileSize(file);
1429 cout << file << "----------------------" << fd << "---------" << size << endl;
1430 source = OH_AVSource_CreateWithFD(fd, 0, size);
1431 ASSERT_NE(source, nullptr);
1432
1433 demuxer = OH_AVDemuxer_CreateWithSource(source);
1434 ASSERT_NE(demuxer, nullptr);
1435 sourceFormat = OH_AVSource_GetSourceFormat(source);
1436 ASSERT_NE(sourceFormat, nullptr);
1437 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1438 cout << g_trackCount << "####################" << endl;
1439
1440 for (int32_t index = 0; index < g_trackCount; index++) {
1441 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1442 }
1443
1444 int64_t endPts = 0;
1445 while (!isEnd) {
1446 for (int32_t index = 0; index < g_trackCount; index++) {
1447 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1448 if (static_cast<uint32_t>(index) != trackIndex) {
1449 continue;
1450 }
1451 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1452 isEnd = true;
1453 cout << "is end!!!!!!!!" << endl;
1454 } else {
1455 endPts = attr.pts;
1456 }
1457 count++;
1458 }
1459 cout << "count: " << count << endl;
1460 }
1461 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, endPts / 1000, SEEK_MODE_CLOSEST_SYNC));
1462 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &attr));
1463 ASSERT_EQ(attr.pts, endPts);
1464 close(fd);
1465 }
1466
1467 /**
1468 * @tc.number : DEMUXER_FUNCTION_3700
1469 * @tc.name : seek to a random time, previous mode
1470 * @tc.desc : function test
1471 */
HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3700, TestSize.Level0)1472 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3700, TestSize.Level0)
1473 {
1474 bool isFirstFrame = true;
1475 uint32_t trackIndex = 1;
1476 int count = 0;
1477 srand(time(nullptr));
1478 int pos = rand() % 250;
1479 int posTo = rand() % 250;
1480 int64_t toMs = posTo * 40000;
1481 int tarckType = 0;
1482 OH_AVCodecBufferAttr attr;
1483 bool audioIsEnd = false;
1484 bool videoIsEnd = false;
1485 const char *file = "/data/test/media/01_video_audio.mp4";
1486 int fd = open(file, O_RDONLY);
1487 cout << file << "pos: " << pos << "toMs: " << toMs << " fd:" << fd << " size:" << GetFileSize(file) << endl;
1488 source = OH_AVSource_CreateWithFD(fd, 0, GetFileSize(file));
1489 ASSERT_NE(source, nullptr);
1490
1491 demuxer = OH_AVDemuxer_CreateWithSource(source);
1492 ASSERT_NE(demuxer, nullptr);
1493
1494 sourceFormat = OH_AVSource_GetSourceFormat(source);
1495 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1496 ASSERT_EQ(2, g_trackCount);
1497
1498 for (int32_t index = 0; index < g_trackCount; index++) {
1499 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1500 }
1501
1502 while (!audioIsEnd || !videoIsEnd) {
1503 for (int32_t index = 0; index < g_trackCount; index++) {
1504 trackFormat = OH_AVSource_GetTrackFormat(source, index);
1505 ASSERT_NE(trackFormat, nullptr);
1506 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
1507
1508 if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
1509 continue;
1510 }
1511 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1512
1513 SetFirstFrameFlag(isFirstFrame);
1514
1515 if (count == pos) {
1516 SetEndFlag(audioIsEnd, videoIsEnd);
1517 break;
1518 }
1519
1520 SetVarValue(attr, tarckType, audioIsEnd, videoIsEnd);
1521 }
1522 count++;
1523 }
1524
1525 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SeekToTime(demuxer, toMs / 1000, SEEK_MODE_PREVIOUS_SYNC));
1526 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &attr));
1527 bool ans = abs(toMs - attr.pts) < 40000 ? true : false;
1528 ASSERT_EQ(ans, true);
1529 close(fd);
1530 }
1531
1532 /**
1533 * @tc.number : DEMUXER_FUNCTION_3800
1534 * @tc.name : seek to a random time, next mode
1535 * @tc.desc : function test
1536 */
1537 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3800, TestSize.Level0)
1538 {
1539 bool isEnd = false;
1540 bool isFirstFrame = true;
1541 uint32_t trackIndex = 1;
1542 OH_AVCodecBufferAttr attr;
1543 const char *file = "/data/test/media/01_video_audio.mp4";
1544 int count = 0;
1545 srand(time(nullptr));
1546 int fd = open(file, O_RDONLY);
1547 int64_t size = GetFileSize(file);
1548 cout << file << "----------------------" << fd << "---------" << size << endl;
1549 source = OH_AVSource_CreateWithFD(fd, 0, size);
1550 ASSERT_NE(source, nullptr);
1551
1552 demuxer = OH_AVDemuxer_CreateWithSource(source);
1553 ASSERT_NE(demuxer, nullptr);
1554 sourceFormat = OH_AVSource_GetSourceFormat(source);
1555 ASSERT_NE(sourceFormat, nullptr);
1556 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1557
1558 for (int32_t index = 0; index < g_trackCount; index++) {
1559 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1560 }
1561 int pos = rand() % 250;
1562 int posTo = rand() % 250;
1563 int64_t toMs = posTo * 40000;
1564 while (!isEnd) {
1565 for (int32_t index = 0; index < g_trackCount; index++) {
1566 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1567 if (isFirstFrame) {
1568 isFirstFrame = false;
1569 }
1570 if (count == pos) {
1571 isEnd = true;
1572 break;
1573 }
1574 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1575 isEnd = true;
1576 }
1577 count++;
1578 }
1579 }
1580 int64_t nextIdrPts = toMs;
1581 ret = OH_AVDemuxer_SeekToTime(demuxer, toMs / 1000, SEEK_MODE_NEXT_SYNC);
1582 ASSERT_EQ(ret, AV_ERR_OK);
1583 ret = OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &attr);
1584 ASSERT_EQ(ret, AV_ERR_OK);
1585 bool ans = abs(nextIdrPts - attr.pts) < 40000 ? true : false;
1586 ASSERT_EQ(ans, true);
1587 close(fd);
1588 }
1589
1590 /**
1591 * @tc.number : DEMUXER_FUNCTION_3900
1592 * @tc.name : seek to a random time, closest mode
1593 * @tc.desc : function test
1594 */
1595 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_3900, TestSize.Level0)
1596 {
1597 bool isEnd = false;
1598 bool isFirstFrame = true;
1599 uint32_t trackIndex = 1;
1600 OH_AVCodecBufferAttr attr;
1601 const char *file = "/data/test/media/01_video_audio.mp4";
1602 int count = 0;
1603 srand(time(nullptr));
1604 int fd = open(file, O_RDONLY);
1605 int64_t size = GetFileSize(file);
1606 cout << file << "----------------------" << fd << "---------" << size << endl;
1607 source = OH_AVSource_CreateWithFD(fd, 0, size);
1608 ASSERT_NE(source, nullptr);
1609
1610 demuxer = OH_AVDemuxer_CreateWithSource(source);
1611 ASSERT_NE(demuxer, nullptr);
1612 sourceFormat = OH_AVSource_GetSourceFormat(source);
1613 ASSERT_NE(sourceFormat, nullptr);
1614 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1615
1616 for (int32_t index = 0; index < g_trackCount; index++) {
1617 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1618 }
1619 int pos = rand() % 250;
1620 int posTo = rand() % 250;
1621 int64_t toMs = posTo * 40000;
1622 while (!isEnd) {
1623 for (int32_t index = 0; index < g_trackCount; index++) {
1624 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1625 if (isFirstFrame) {
1626 isFirstFrame = false;
1627 }
1628 if (count == pos) {
1629 isEnd = true;
1630 cout << "curr_pts = attr.pts" << endl;
1631 break;
1632 }
1633 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1634 isEnd = true;
1635 }
1636 count++;
1637 }
1638 }
1639 int64_t closestIdrPts = toMs;
1640 ret = OH_AVDemuxer_SeekToTime(demuxer, toMs / 1000, SEEK_MODE_CLOSEST_SYNC);
1641 ASSERT_EQ(ret, AV_ERR_OK);
1642 ret = OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &attr);
1643 ASSERT_EQ(ret, AV_ERR_OK);
1644 bool ans = abs(closestIdrPts - attr.pts) < 40000 ? true : false;
1645 ASSERT_EQ(ans, true);
1646 close(fd);
1647 }
1648
1649 /**
1650 * @tc.number : DEMUXER_FUNCTION_4000
1651 * @tc.name : seek to a invalid time, closest mode
1652 * @tc.desc : function test
1653 */
1654 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_4000, TestSize.Level2)
1655 {
1656 const char *file = "/data/test/media/01_video_audio.mp4";
1657 srand(time(nullptr));
1658 int fd = open(file, O_RDONLY);
1659 int64_t size = GetFileSize(file);
1660 cout << file << "----------------------" << fd << "---------" << size << endl;
1661 source = OH_AVSource_CreateWithFD(fd, 0, size);
1662 ASSERT_NE(source, nullptr);
1663
1664 demuxer = OH_AVDemuxer_CreateWithSource(source);
1665 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
1666
1667 ASSERT_NE(demuxer, nullptr);
1668 int64_t invalidPts = 12000 * 16666;
1669 ret = OH_AVDemuxer_SeekToTime(demuxer, invalidPts, SEEK_MODE_CLOSEST_SYNC);
1670 ASSERT_NE(ret, AV_ERR_OK);
1671 close(fd);
1672 }
1673
1674 /**
1675 * @tc.number : DEMUXER_FUNCTION_4100
1676 * @tc.name : remove track before add track
1677 * @tc.desc : function test
1678 */
1679 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_4100, TestSize.Level2)
1680 {
1681 const char *file = "/data/test/media/01_video_audio.mp4";
1682 srand(time(nullptr));
1683 int fd = open(file, O_RDONLY);
1684 int64_t size = GetFileSize(file);
1685 cout << file << "----------------------" << fd << "---------" << size << endl;
1686 source = OH_AVSource_CreateWithFD(fd, 0, size);
1687 ASSERT_NE(source, nullptr);
1688
1689 demuxer = OH_AVDemuxer_CreateWithSource(source);
1690 ASSERT_NE(demuxer, nullptr);
1691 ret = OH_AVDemuxer_UnselectTrackByID(demuxer, 0);
1692 ASSERT_EQ(ret, AV_ERR_OK);
1693 ret = OH_AVDemuxer_SelectTrackByID(demuxer, 0);
1694 ASSERT_EQ(ret, AV_ERR_OK);
1695 close(fd);
1696 }
1697
1698 /**
1699 * @tc.number : DEMUXER_FUNCTION_4200
1700 * @tc.name : remove all tracks after demux finish
1701 * @tc.desc : function test
1702 */
1703 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_4200, TestSize.Level1)
1704 {
1705 OH_AVCodecBufferAttr attr;
1706 const char *file = "/data/test/media/01_video_audio.mp4";
1707 bool isEnd = false;
1708
1709 int fd = open(file, O_RDONLY);
1710 int64_t size = GetFileSize(file);
1711 cout << file << "----------------------" << fd << "---------" << size << endl;
1712 source = OH_AVSource_CreateWithFD(fd, 0, size);
1713 ASSERT_NE(source, nullptr);
1714
1715 demuxer = OH_AVDemuxer_CreateWithSource(source);
1716 ASSERT_NE(demuxer, nullptr);
1717
1718 sourceFormat = OH_AVSource_GetSourceFormat(source);
1719 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1720 ASSERT_EQ(2, g_trackCount);
1721 for (int32_t index = 0; index < g_trackCount; index++) {
1722 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1723 }
1724 while (!isEnd) {
1725 for (int32_t index = 0; index < g_trackCount; index++) {
1726 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1727 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1728 isEnd = true;
1729 cout << "is end !!!!!!!!!!!!!!!" << endl;
1730 }
1731 }
1732 }
1733
1734 for (int32_t index = 0; index < g_trackCount; index++) {
1735 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_UnselectTrackByID(demuxer, index));
1736 }
1737
1738 int32_t memorySize = OH_AVMemory_GetSize(memory);
1739 ASSERT_NE(0, memorySize);
1740 close(fd);
1741 }
1742
1743 /**
1744 * @tc.number : DEMUXER_FUNCTION_4300
1745 * @tc.name : remove all tracks before demux finish
1746 * @tc.desc : function test
1747 */
1748 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_4300, TestSize.Level1)
1749 {
1750 OH_AVCodecBufferAttr attr;
1751 const char *file = "/data/test/media/01_video_audio.mp4";
1752 bool isEnd = false;
1753 int count = 0;
1754 int fd = open(file, O_RDONLY);
1755 int64_t size = GetFileSize(file);
1756 cout << file << "----------------------" << fd << "---------" << size << endl;
1757 source = OH_AVSource_CreateWithFD(fd, 0, size);
1758 ASSERT_NE(source, nullptr);
1759
1760 demuxer = OH_AVDemuxer_CreateWithSource(source);
1761 ASSERT_NE(demuxer, nullptr);
1762
1763 sourceFormat = OH_AVSource_GetSourceFormat(source);
1764 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1765 ASSERT_EQ(2, g_trackCount);
1766 for (int32_t index = 0; index < g_trackCount; index++) {
1767 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1768 }
1769 srand(time(nullptr));
1770 int pos = rand() % 250;
1771 cout << " pos= " << pos << endl;
1772 while (!isEnd) {
1773 for (int32_t index = 0; index < g_trackCount; index++) {
1774 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1775 if (count == pos) {
1776 cout << count << " count == pos!!!!!!!!!" << endl;
1777 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_UnselectTrackByID(demuxer, 0));
1778 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_UnselectTrackByID(demuxer, 1));
1779 ASSERT_EQ(AV_ERR_OPERATE_NOT_PERMIT, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
1780 isEnd = true;
1781 break;
1782 }
1783
1784 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1785 isEnd = true;
1786 cout << "is end !!!!!!!!!!!!!!!" << endl;
1787 }
1788 if (index == 0) {
1789 count++;
1790 }
1791 }
1792 }
1793 close(fd);
1794 }
1795
1796 /**
1797 * @tc.number : DEMUXER_FUNCTION_4400
1798 * @tc.name : remove audio track before demux finish
1799 * @tc.desc : function test
1800 */
1801 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_4400, TestSize.Level1)
1802 {
1803 OH_AVCodecBufferAttr attr;
1804 const char *file = "/data/test/media/01_video_audio.mp4";
1805
1806 int audioCount = 0;
1807 int fd = open(file, O_RDONLY);
1808 int64_t size = GetFileSize(file);
1809 cout << file << "----------------------" << fd << "---------" << size << endl;
1810 source = OH_AVSource_CreateWithFD(fd, 0, size);
1811 ASSERT_NE(source, nullptr);
1812
1813 demuxer = OH_AVDemuxer_CreateWithSource(source);
1814 ASSERT_NE(demuxer, nullptr);
1815
1816 sourceFormat = OH_AVSource_GetSourceFormat(source);
1817 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1818 ASSERT_EQ(2, g_trackCount);
1819 for (int32_t index = 0; index < g_trackCount; index++) {
1820 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
1821 }
1822 srand(time(nullptr));
1823 int pos = rand() % 250;
1824 cout << " pos= " << pos << endl;
1825
1826 while (true) {
1827 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
1828 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 1, memory, &attr));
1829 if (audioCount == pos) {
1830 cout << audioCount << " audioCount == pos remove audio track!!!!!!!!!" << endl;
1831 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_UnselectTrackByID(demuxer, 1));
1832 ASSERT_NE(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 1, memory, &attr));
1833 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
1834 break;
1835 }
1836 audioCount++;
1837 }
1838
1839 while (true) {
1840 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
1841 if (attr.flags & OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS) {
1842 cout << "is end !!!!!!!!!!!!!!!" << endl;
1843 break;
1844 }
1845 }
1846 close(fd);
1847 }
1848
1849 /**
1850 * @tc.number : DEMUXER_FUNCTION_4500
1851 * @tc.name : start demux bufore add track
1852 * @tc.desc : function test
1853 */
1854 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_4500, TestSize.Level2)
1855 {
1856 uint32_t trackIndex = 0;
1857 OH_AVCodecBufferAttr attr;
1858 const char *file = "/data/test/media/01_video_audio.mp4";
1859 srand(time(nullptr));
1860 int fd = open(file, O_RDONLY);
1861 int64_t size = GetFileSize(file);
1862 cout << file << "----------------------" << fd << "---------" << size << endl;
1863 source = OH_AVSource_CreateWithFD(fd, 0, size);
1864 ASSERT_NE(source, nullptr);
1865
1866 demuxer = OH_AVDemuxer_CreateWithSource(source);
1867 ASSERT_NE(demuxer, nullptr);
1868 ret = OH_AVDemuxer_ReadSample(demuxer, trackIndex, memory, &attr);
1869 ASSERT_EQ(ret, AV_ERR_OPERATE_NOT_PERMIT);
1870 close(fd);
1871 }
1872
1873 /**
1874 * @tc.number : DEMUXER_FUNCTION_7000
1875 * @tc.name : demuxer MP4 ,GetSourceFormat,OH_MD_KEY_TRACK_COUNT
1876 * @tc.desc : function test
1877 */
1878 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_7000, TestSize.Level0)
1879 {
1880 OH_AVFormat *trackFormat2 = nullptr;
1881 const char *file = "/data/test/media/01_video_audio.mp4";
1882 int fd = open(file, O_RDONLY);
1883 int64_t size = GetFileSize(file);
1884 cout << file << "----------------------" << fd << "---------" << size << endl;
1885 source = OH_AVSource_CreateWithFD(fd, 0, size);
1886 ASSERT_NE(source, nullptr);
1887 sourceFormat = OH_AVSource_GetSourceFormat(source);
1888 ASSERT_NE(sourceFormat, nullptr);
1889 cout << OH_AVFormat_DumpInfo(sourceFormat) << "sourceFormat" << endl;
1890
1891 trackFormat = OH_AVSource_GetTrackFormat(source, 1);
1892 ASSERT_NE(trackFormat, nullptr);
1893 cout << OH_AVFormat_DumpInfo(trackFormat) << "trackformat1" << endl;
1894
1895 trackFormat2 = OH_AVSource_GetTrackFormat(source, 0);
1896 cout << OH_AVFormat_DumpInfo(trackFormat2) << "trackformat0" << endl;
1897
1898 close(fd);
1899 }
1900
1901 /**
1902 * @tc.number : DEMUXER_FUNCTION_7100
1903 * @tc.name : demuxer MP4 ,GetSourceFormat,OH_MD_KEY_TRACK_COUNT
1904 * @tc.desc : function test
1905 */
1906 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_7100, TestSize.Level0)
1907 {
1908 const char *file = "/data/test/media/01_video_audio.mp4";
1909 int fd = open(file, O_RDONLY);
1910 int64_t size = GetFileSize(file);
1911 cout << file << "----------------------" << fd << "---------" << size << endl;
1912 source = OH_AVSource_CreateWithFD(fd, 0, size);
1913 ASSERT_NE(source, nullptr);
1914
1915 sourceFormat = OH_AVSource_GetSourceFormat(source);
1916 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
1917 ASSERT_EQ(g_trackCount, 2);
1918 close(fd);
1919 }
1920
1921 /**
1922 * @tc.number : DEMUXER_FUNCTION_7200
1923 * @tc.name : demuxer MP4 ,GetAudioTrackFormat,MD_KEY_AAC_IS_ADTS
1924 * @tc.desc : function test
1925 */
1926 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_7200, TestSize.Level0)
1927 {
1928 const char *stringVal;
1929 const char *file = "/data/test/media/01_video_audio.mp4";
1930 int fd = open(file, O_RDONLY);
1931 int64_t size = GetFileSize(file);
1932 cout << file << "----------------------" << fd << "---------" << size << endl;
1933 source = OH_AVSource_CreateWithFD(fd, 0, size);
1934 ASSERT_NE(source, nullptr);
1935
1936 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1937 ASSERT_NE(trackFormat, nullptr);
1938 ASSERT_FALSE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_AAC_IS_ADTS, &stringVal));
1939 close(fd);
1940 }
1941
1942 /**
1943 * @tc.number : DEMUXER_FUNCTION_7300
1944 * @tc.name : demuxer MP4 ,GetAudioTrackFormat ,MD_KEY_BITRATE
1945 * @tc.desc : function test
1946 */
1947 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_7300, TestSize.Level0)
1948 {
1949 int64_t br = 0;
1950 const char *file = "/data/test/media/01_video_audio.mp4";
1951 int fd = open(file, O_RDONLY);
1952 int64_t size = GetFileSize(file);
1953 cout << file << "----------------------" << fd << "---------" << size << endl;
1954 source = OH_AVSource_CreateWithFD(fd, 0, size);
1955 ASSERT_NE(source, nullptr);
1956
1957 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1958 ASSERT_NE(trackFormat, nullptr);
1959 ASSERT_TRUE(OH_AVFormat_GetLongValue(trackFormat, OH_MD_KEY_BITRATE, &br));
1960 ASSERT_EQ(br, 319999);
1961 close(fd);
1962 }
1963
1964 /**
1965 * @tc.number : DEMUXER_FUNCTION_7400
1966 * @tc.name : demuxer MP4 ,GetAudioTrackFormat,MD_KEY_CHANNEL_COUNT
1967 * @tc.desc : function test
1968 */
1969 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_7400, TestSize.Level0)
1970 {
1971 int32_t cc = 0;
1972 const char *file = "/data/test/media/01_video_audio.mp4";
1973 int fd = open(file, O_RDONLY);
1974 int64_t size = GetFileSize(file);
1975 cout << file << "----------------------" << fd << "---------" << size << endl;
1976 source = OH_AVSource_CreateWithFD(fd, 0, size);
1977 ASSERT_NE(source, nullptr);
1978
1979 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
1980 ASSERT_NE(trackFormat, nullptr);
1981 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AUD_CHANNEL_COUNT, &cc));
1982
1983 ASSERT_EQ(cc, 2);
1984 close(fd);
1985 }
1986
1987 /**
1988 * @tc.number : DEMUXER_FUNCTION_7500
1989 * @tc.name : demuxer MP4 ,GetAudioTrackFormat,MD_KEY_SAMPLE_RATE
1990 * @tc.desc : function test
1991 */
1992 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_7500, TestSize.Level0)
1993 {
1994 int32_t sr = 0;
1995 const char *file = "/data/test/media/01_video_audio.mp4";
1996 int fd = open(file, O_RDONLY);
1997 int64_t size = GetFileSize(file);
1998 cout << file << "----------------------" << fd << "---------" << size << endl;
1999 source = OH_AVSource_CreateWithFD(fd, 0, size);
2000 ASSERT_NE(source, nullptr);
2001
2002 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
2003 ASSERT_NE(trackFormat, nullptr);
2004 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_AUD_SAMPLE_RATE, &sr));
2005 ASSERT_EQ(sr, 44100);
2006 close(fd);
2007 }
2008
2009 /**
2010 * @tc.number : DEMUXER_FUNCTION_7600
2011 * @tc.name : demuxer MP4 ,GetVideoTrackFormat,MD_KEY_HEIGHT
2012 * @tc.desc : function test
2013 */
2014 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_7600, TestSize.Level0)
2015 {
2016 int32_t height = 0;
2017 const char *file = "/data/test/media/01_video_audio.mp4";
2018 int fd = open(file, O_RDONLY);
2019 int64_t size = GetFileSize(file);
2020 cout << file << "----------------------" << fd << "---------" << size << endl;
2021 source = OH_AVSource_CreateWithFD(fd, 0, size);
2022 ASSERT_NE(source, nullptr);
2023
2024 trackFormat = OH_AVSource_GetTrackFormat(source, 1);
2025 ASSERT_NE(trackFormat, nullptr);
2026 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_HEIGHT, &height));
2027 ASSERT_EQ(height, 0);
2028 close(fd);
2029 }
2030
2031 /**
2032 * @tc.number : DEMUXER_FUNCTION_7700
2033 * @tc.name : demuxer MP4 ,GetVideoTrackFormat,MD_KEY_WIDTH
2034 * @tc.desc : function test
2035 */
2036 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_7700, TestSize.Level0)
2037 {
2038 int32_t weight = 0;
2039 const char *file = "/data/test/media/01_video_audio.mp4";
2040 int fd = open(file, O_RDONLY);
2041 int64_t size = GetFileSize(file);
2042 cout << file << "----------------------" << fd << "---------" << size << endl;
2043 source = OH_AVSource_CreateWithFD(fd, 0, size);
2044 ASSERT_NE(source, nullptr);
2045
2046 trackFormat = OH_AVSource_GetTrackFormat(source, 1);
2047 ASSERT_NE(trackFormat, nullptr);
2048 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_WIDTH, &weight));
2049 ASSERT_EQ(weight, 0);
2050 close(fd);
2051 }
2052
2053 /**
2054 * @tc.number : DEMUXER_FUNCTION_7800
2055 * @tc.name : demuxer MP4 GetPublicTrackFormat,MD_KEY_CODEC_MIME
2056 * @tc.desc : function test
2057 */
2058 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_7800, TestSize.Level0)
2059 {
2060 const char *stringVal;
2061 const char *file = "/data/test/media/01_video_audio.mp4";
2062 int fd = open(file, O_RDONLY);
2063 int64_t size = GetFileSize(file);
2064 cout << file << "----------------------" << fd << "---------" << size << endl;
2065 source = OH_AVSource_CreateWithFD(fd, 0, size);
2066 ASSERT_NE(source, nullptr);
2067
2068 trackFormat = OH_AVSource_GetTrackFormat(source, 1);
2069 ASSERT_NE(trackFormat, nullptr);
2070 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &stringVal));
2071 ASSERT_EQ(0, strcmp(stringVal, "video/mp4v-es"));
2072 close(fd);
2073 }
2074
2075 /**
2076 * @tc.number : DEMUXER_FUNCTION_7900
2077 * @tc.name : demuxer MP4 ,GetPublicTrackFormat,MD_KEY_TRACK_TYPE
2078 * @tc.desc : function test
2079 */
2080 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_7900, TestSize.Level0)
2081 {
2082 int32_t type = 0;
2083 const char *file = "/data/test/media/01_video_audio.mp4";
2084 int fd = open(file, O_RDONLY);
2085 int64_t size = GetFileSize(file);
2086 cout << file << "----------------------" << fd << "---------" << size << endl;
2087 source = OH_AVSource_CreateWithFD(fd, 0, size);
2088 ASSERT_NE(source, nullptr);
2089
2090 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
2091 ASSERT_NE(trackFormat, nullptr);
2092 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &type));
2093
2094 ASSERT_EQ(type, 0);
2095 close(fd);
2096 }
2097
2098 /**
2099 * @tc.number : DEMUXER_FUNCTION_8000
2100 * @tc.name : demuxer MP4 ,check source format,OH_MD_KEY_TITLE
2101 * @tc.desc : function test
2102 */
2103 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_8000, TestSize.Level0)
2104 {
2105 const char *stringVal;
2106 const char *file = "/data/test/media/01_video_audio.mp4";
2107 int fd = open(file, O_RDONLY);
2108 int64_t size = GetFileSize(file);
2109 cout << file << "----------------------" << fd << "---------" << size << endl;
2110 source = OH_AVSource_CreateWithFD(fd, 0, size);
2111 ASSERT_NE(source, nullptr);
2112
2113 sourceFormat = OH_AVSource_GetSourceFormat(source);
2114 ASSERT_NE(sourceFormat, nullptr);
2115 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_TITLE, &stringVal));
2116 ASSERT_EQ(0, strcmp(stringVal, "title"));
2117 close(fd);
2118 }
2119
2120 /**
2121 * @tc.number : DEMUXER_FUNCTION_8100
2122 * @tc.name : demuxer MP4 ,check source format,OH_MD_KEY_ALBUM
2123 * @tc.desc : function test
2124 */
2125 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_8100, TestSize.Level0)
2126 {
2127 const char *file = "/data/test/media/01_video_audio.mp4";
2128 int fd = open(file, O_RDONLY);
2129 int64_t size = GetFileSize(file);
2130 cout << file << "----------------------" << fd << "---------" << size << endl;
2131 source = OH_AVSource_CreateWithFD(fd, 0, size);
2132 ASSERT_NE(source, nullptr);
2133 sourceFormat = OH_AVSource_GetSourceFormat(source);
2134 ASSERT_NE(sourceFormat, nullptr);
2135 const char *stringVal;
2136 ASSERT_FALSE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM, &stringVal));
2137 close(fd);
2138 }
2139
2140 /**
2141 * @tc.number : DEMUXER_FUNCTION_8200
2142 * @tc.name : demuxer MP4 ,check source format,OH_MD_KEY_ALBUM_ARTIST
2143 * @tc.desc : function test
2144 */
2145 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_8200, TestSize.Level0)
2146 {
2147 const char *file = "/data/test/media/01_video_audio.mp4";
2148 int fd = open(file, O_RDONLY);
2149 int64_t size = GetFileSize(file);
2150 cout << file << "----------------------" << fd << "---------" << size << endl;
2151 source = OH_AVSource_CreateWithFD(fd, 0, size);
2152 ASSERT_NE(source, nullptr);
2153 sourceFormat = OH_AVSource_GetSourceFormat(source);
2154 ASSERT_NE(sourceFormat, nullptr);
2155 const char *stringVal;
2156 ASSERT_FALSE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ALBUM_ARTIST, &stringVal));
2157 close(fd);
2158 }
2159
2160 /**
2161 * @tc.number : DEMUXER_FUNCTION_8300
2162 * @tc.name : demuxer MP4 ,check track format,OH_MD_KEY_DATE
2163 * @tc.desc : function test
2164 */
2165 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_8300, TestSize.Level0)
2166 {
2167 const char *file = "/data/test/media/01_video_audio.mp4";
2168 int fd = open(file, O_RDONLY);
2169 int64_t size = GetFileSize(file);
2170 cout << file << "----------------------" << fd << "---------" << size << endl;
2171 source = OH_AVSource_CreateWithFD(fd, 0, size);
2172 ASSERT_NE(source, nullptr);
2173 sourceFormat = OH_AVSource_GetSourceFormat(source);
2174 ASSERT_NE(sourceFormat, nullptr);
2175 const char *stringVal;
2176 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_DATE, &stringVal));
2177 ASSERT_EQ(0, strcmp(stringVal, "2023"));
2178 close(fd);
2179 }
2180
2181 /**
2182 * @tc.number : DEMUXER_FUNCTION_8400
2183 * @tc.name : demuxer MP4 ,check track format,OH_MD_KEY_COMMENT
2184 * @tc.desc : function test
2185 */
2186 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_8400, TestSize.Level0)
2187 {
2188 const char *file = "/data/test/media/01_video_audio.mp4";
2189 int fd = open(file, O_RDONLY);
2190 int64_t size = GetFileSize(file);
2191 cout << file << "----------------------" << fd << "---------" << size << endl;
2192 source = OH_AVSource_CreateWithFD(fd, 0, size);
2193 ASSERT_NE(source, nullptr);
2194 sourceFormat = OH_AVSource_GetSourceFormat(source);
2195 ASSERT_NE(sourceFormat, nullptr);
2196 const char *stringVal;
2197 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_COMMENT, &stringVal));
2198 ASSERT_EQ(0, strcmp(stringVal, "COMMENT"));
2199 close(fd);
2200 }
2201
2202 /**
2203 * @tc.number : DEMUXER_FUNCTION_8500
2204 * @tc.name : demuxer MP4 ,check track format,OH_MD_KEY_GENRE
2205 * @tc.desc : function test
2206 */
2207 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_8500, TestSize.Level0)
2208 {
2209 const char *file = "/data/test/media/01_video_audio.mp4";
2210 int fd = open(file, O_RDONLY);
2211 int64_t size = GetFileSize(file);
2212 cout << file << "----------------------" << fd << "---------" << size << endl;
2213 source = OH_AVSource_CreateWithFD(fd, 0, size);
2214 ASSERT_NE(source, nullptr);
2215 sourceFormat = OH_AVSource_GetSourceFormat(source);
2216 ASSERT_NE(sourceFormat, nullptr);
2217 const char *stringVal;
2218 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_GENRE, &stringVal));
2219 ASSERT_EQ(0, strcmp(stringVal, "Classical"));
2220 close(fd);
2221 }
2222
2223 /**
2224 * @tc.number : DEMUXER_FUNCTION_8600
2225 * @tc.name : demuxer MP4 ,check track format,OH_MD_KEY_COPYRIGHT
2226 * @tc.desc : function test
2227 */
2228 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_8600, TestSize.Level0)
2229 {
2230 const char *file = "/data/test/media/01_video_audio.mp4";
2231 int fd = open(file, O_RDONLY);
2232 int64_t size = GetFileSize(file);
2233 cout << file << "----------------------" << fd << "---------" << size << endl;
2234 source = OH_AVSource_CreateWithFD(fd, 0, size);
2235 ASSERT_NE(source, nullptr);
2236 sourceFormat = OH_AVSource_GetSourceFormat(source);
2237 ASSERT_NE(sourceFormat, nullptr);
2238 const char *stringVal;
2239 ASSERT_FALSE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_COPYRIGHT, &stringVal));
2240 close(fd);
2241 }
2242
2243 /**
2244 * @tc.number : DEMUXER_FUNCTION_8700
2245 * @tc.name : demuxer MP4 ,check track format,OH_MD_KEY_LANGUAGE
2246 * @tc.desc : function test
2247 */
2248 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_8700, TestSize.Level0)
2249 {
2250 const char *file = "/data/test/media/01_video_audio.mp4";
2251 int fd = open(file, O_RDONLY);
2252 int64_t size = GetFileSize(file);
2253 cout << file << "----------------------" << fd << "---------" << size << endl;
2254 source = OH_AVSource_CreateWithFD(fd, 0, size);
2255 ASSERT_NE(source, nullptr);
2256 sourceFormat = OH_AVSource_GetSourceFormat(source);
2257 ASSERT_NE(sourceFormat, nullptr);
2258 const char *stringVal;
2259 ASSERT_FALSE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_LANGUAGE, &stringVal));
2260 close(fd);
2261 }
2262
2263 /**
2264 * @tc.number : DEMUXER_FUNCTION_8800
2265 * @tc.name : demuxer MP4 ,check track format,OH_MD_KEY_DESCRIPTION
2266 * @tc.desc : function test
2267 */
2268 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_8800, TestSize.Level0)
2269 {
2270 const char *file = "/data/test/media/01_video_audio.mp4";
2271 int fd = open(file, O_RDONLY);
2272 int64_t size = GetFileSize(file);
2273 cout << file << "----------------------" << fd << "---------" << size << endl;
2274 source = OH_AVSource_CreateWithFD(fd, 0, size);
2275 ASSERT_NE(source, nullptr);
2276 sourceFormat = OH_AVSource_GetSourceFormat(source);
2277 ASSERT_NE(sourceFormat, nullptr);
2278 const char *stringVal;
2279 ASSERT_FALSE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_DESCRIPTION, &stringVal));
2280 close(fd);
2281 }
2282
2283 /**
2284 * @tc.number : DEMUXER_FUNCTION_8800
2285 * @tc.name : demuxer MP4 ,check track format,OH_MD_KEY_LYRICS
2286 * @tc.desc : function test
2287 */
2288 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_8900, TestSize.Level0)
2289 {
2290 const char *file = "/data/test/media/01_video_audio.mp4";
2291 int fd = open(file, O_RDONLY);
2292 int64_t size = GetFileSize(file);
2293 cout << file << "----------------------" << fd << "---------" << size << endl;
2294 source = OH_AVSource_CreateWithFD(fd, 0, size);
2295 ASSERT_NE(source, nullptr);
2296 sourceFormat = OH_AVSource_GetSourceFormat(source);
2297 ASSERT_NE(sourceFormat, nullptr);
2298 const char *stringVal;
2299 ASSERT_FALSE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_LYRICS, &stringVal));
2300 close(fd);
2301 }
2302
2303 /**
2304 * @tc.number : DEMUXER_FUNCTION_9000
2305 * @tc.name : demuxer MP4 ,check source format,OH_MD_KEY_ARTIST
2306 * @tc.desc : function test
2307 */
2308 HWTEST_F(DemuxerFuncNdkTest, DEMUXER_FUNCTION_9000, TestSize.Level0)
2309 {
2310 const char *file = "/data/test/media/01_video_audio.mp4";
2311 int fd = open(file, O_RDONLY);
2312 int64_t size = GetFileSize(file);
2313 cout << file << "----------------------" << fd << "---------" << size << endl;
2314 source = OH_AVSource_CreateWithFD(fd, 0, size);
2315 ASSERT_NE(source, nullptr);
2316 sourceFormat = OH_AVSource_GetSourceFormat(source);
2317 ASSERT_NE(sourceFormat, nullptr);
2318 const char *stringVal;
2319 ASSERT_TRUE(OH_AVFormat_GetStringValue(sourceFormat, OH_MD_KEY_ARTIST, &stringVal));
2320 ASSERT_EQ(0, strcmp(stringVal, "sam"));
2321 close(fd);
2322 }
2323 /**
2324 * @tc.number : SUB_MEDIA_DEMUXER_FUNCTION_0200
2325 * @tc.name : demuxer video amr nb
2326 * @tc.desc : function test
2327 */
2328 HWTEST_F(DemuxerFuncNdkTest, SUB_MEDIA_DEMUXER_FUNCTION_0200, TestSize.Level0)
2329 {
2330 OH_AVCodecBufferAttr attr;
2331 bool audioIsEnd = false;
2332 int audioFrame = 0;
2333 const char *file = "/data/test/media/audio/amr_nb_8000_1.amr";
2334 int fd = open(file, O_RDONLY);
2335 int64_t size = GetFileSize(file);
2336 cout << file << "----------------------" << fd << "---------" << size << endl;
2337 source = OH_AVSource_CreateWithFD(fd, 0, size);
2338 ASSERT_NE(source, nullptr);
2339 demuxer = OH_AVDemuxer_CreateWithSource(source);
2340 ASSERT_NE(demuxer, nullptr);
2341 sourceFormat = OH_AVSource_GetSourceFormat(source);
2342 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
2343 ASSERT_EQ(1, g_trackCount);
2344 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
2345 int aKeyCount = 0;
2346 while (!audioIsEnd) {
2347 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
2348 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
2349 }
2350 cout << file << "audioFrame " << audioFrame << " aKeyCount " << aKeyCount << endl;
2351 ASSERT_EQ(audioFrame, 1501);
2352 ASSERT_EQ(aKeyCount, 1501);
2353 close(fd);
2354 }
2355
2356 /**
2357 * @tc.number : SUB_MEDIA_DEMUXER_FUNCTION_0300
2358 * @tc.name : demuxer video amr wb
2359 * @tc.desc : function test
2360 */
2361 HWTEST_F(DemuxerFuncNdkTest, SUB_MEDIA_DEMUXER_FUNCTION_0300, TestSize.Level0)
2362 {
2363 OH_AVCodecBufferAttr attr;
2364 bool audioIsEnd = false;
2365 int audioFrame = 0;
2366 const char *file = "/data/test/media/audio/amr_wb_16000_1.amr";
2367 int fd = open(file, O_RDONLY);
2368 int64_t size = GetFileSize(file);
2369 cout << file << "----------------------" << fd << "---------" << size << endl;
2370 source = OH_AVSource_CreateWithFD(fd, 0, size);
2371 ASSERT_NE(source, nullptr);
2372 demuxer = OH_AVDemuxer_CreateWithSource(source);
2373 ASSERT_NE(demuxer, nullptr);
2374 sourceFormat = OH_AVSource_GetSourceFormat(source);
2375 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
2376 ASSERT_EQ(1, g_trackCount);
2377 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
2378 int aKeyCount = 0;
2379 while (!audioIsEnd) {
2380 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
2381 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
2382 }
2383 cout << file << "audioFrame " << audioFrame << " aKeyCount " << aKeyCount << endl;
2384 ASSERT_EQ(audioFrame, 1500);
2385 ASSERT_EQ(aKeyCount, 1500);
2386 close(fd);
2387 }
2388
2389 /**
2390 * @tc.number : SUB_MEDIA_DEMUXER_FUNCTION_1000
2391 * @tc.name : demuxer amr_nb format
2392 * @tc.desc : function test
2393 */
2394 HWTEST_F(DemuxerFuncNdkTest, SUB_MEDIA_DEMUXER_FUNCTION_1000, TestSize.Level2)
2395 {
2396 const char *file = "/data/test/media/audio/amr_nb_8000_1.amr";
2397 int fd = open(file, O_RDONLY);
2398 int64_t size = GetFileSize(file);
2399 cout << file << "----------------------" << fd << "---------" << size << endl;
2400 source = OH_AVSource_CreateWithFD(fd, 0, size);
2401 ASSERT_NE(source, nullptr);
2402 demuxer = OH_AVDemuxer_CreateWithSource(source);
2403 ASSERT_NE(demuxer, nullptr);
2404 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
2405 ASSERT_NE(trackFormat, nullptr);
2406 const char *codecMime = "";
2407 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &codecMime));
2408 cout << "codecMime" << codecMime << endl;
2409 ASSERT_EQ(0, strcmp(codecMime, "audio/3gpp"));
2410 close(fd);
2411 }
2412
2413 /**
2414 * @tc.number : SUB_MEDIA_DEMUXER_FUNCTION_1100
2415 * @tc.name : demuxer amr_wb format
2416 * @tc.desc : function test
2417 */
2418 HWTEST_F(DemuxerFuncNdkTest, SUB_MEDIA_DEMUXER_FUNCTION_1100, TestSize.Level2)
2419 {
2420 const char *file = "/data/test/media/audio/amr_wb_16000_1.amr";
2421 int fd = open(file, O_RDONLY);
2422 int64_t size = GetFileSize(file);
2423 cout << file << "----------------------" << fd << "---------" << size << endl;
2424 source = OH_AVSource_CreateWithFD(fd, 0, size);
2425 ASSERT_NE(source, nullptr);
2426 demuxer = OH_AVDemuxer_CreateWithSource(source);
2427 ASSERT_NE(demuxer, nullptr);
2428 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
2429 ASSERT_NE(trackFormat, nullptr);
2430 const char *codecMime = "";
2431 ASSERT_TRUE(OH_AVFormat_GetStringValue(trackFormat, OH_MD_KEY_CODEC_MIME, &codecMime));
2432 cout << "codecMime" << codecMime << endl;
2433 ASSERT_EQ(0, strcmp(codecMime, "audio/amr-wb"));
2434 close(fd);
2435 }
2436
2437
2438 /**
2439 * @tc.number : SUB_MEDIA_DEMUXER_FUNCTION_1200
2440 * @tc.name : demux hevc ts video and audio
2441 * @tc.desc : function test
2442 */
2443 HWTEST_F(DemuxerFuncNdkTest, SUB_MEDIA_DEMUXER_FUNCTION_1200, TestSize.Level0)
2444 {
2445 if (access(HEVC_LIB_PATH.c_str(), F_OK) != 0) {
2446 return;
2447 }
2448 int tarckType = 0;
2449 OH_AVCodecBufferAttr attr;
2450 bool audioIsEnd = false;
2451 bool videoIsEnd = false;
2452 int audioFrame = 0;
2453 int videoFrame = 0;
2454 const char *file = "/data/test/media/hevc_v_a.ts";
2455 int fd = open(file, O_RDONLY);
2456 int64_t size = GetFileSize(file);
2457 cout << file << "----------------------" << fd << "---------" << size << endl;
2458 source = OH_AVSource_CreateWithFD(fd, 0, size);
2459 ASSERT_NE(source, nullptr);
2460
2461 demuxer = OH_AVDemuxer_CreateWithSource(source);
2462 ASSERT_NE(demuxer, nullptr);
2463
2464 sourceFormat = OH_AVSource_GetSourceFormat(source);
2465 ASSERT_TRUE(OH_AVFormat_GetIntValue(sourceFormat, OH_MD_KEY_TRACK_COUNT, &g_trackCount));
2466 ASSERT_EQ(2, g_trackCount);
2467
2468 for (int32_t index = 0; index < g_trackCount; index++) {
2469 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, index));
2470 }
2471 int vKeyCount = 0;
2472 int aKeyCount = 0;
2473 while (!audioIsEnd || !videoIsEnd) {
2474 for (int32_t index = 0; index < g_trackCount; index++) {
2475 trackFormat = OH_AVSource_GetTrackFormat(source, index);
2476 ASSERT_NE(trackFormat, nullptr);
2477 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
2478 if ((audioIsEnd && (tarckType == 0)) || (videoIsEnd && (tarckType == 1))) {
2479 continue;
2480 }
2481 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, index, memory, &attr));
2482 if (tarckType == 0) {
2483 SetAudioValue(attr, audioIsEnd, audioFrame, aKeyCount);
2484 } else if (tarckType == 1) {
2485 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
2486 }
2487 }
2488 }
2489 ASSERT_EQ(audioFrame, 384);
2490 ASSERT_EQ(aKeyCount, 384);
2491 ASSERT_EQ(videoFrame, 602);
2492 ASSERT_EQ(vKeyCount, 3);
2493 close(fd);
2494 }
2495
2496 /**
2497 * @tc.number : SUB_MEDIA_DEMUXER_FUNCTION_1300
2498 * @tc.name : demux hevc ts video
2499 * @tc.desc : function test
2500 */
2501 HWTEST_F(DemuxerFuncNdkTest, SUB_MEDIA_DEMUXER_FUNCTION_1300, TestSize.Level0)
2502 {
2503 if (access(HEVC_LIB_PATH.c_str(), F_OK) != 0) {
2504 return;
2505 }
2506 int tarckType = 0;
2507 OH_AVCodecBufferAttr attr;
2508 bool videoIsEnd = false;
2509 int videoFrame = 0;
2510 const char *file = "/data/test/media/hevc_v.ts";
2511 int fd = open(file, O_RDONLY);
2512 int64_t size = GetFileSize(file);
2513 cout << file << "----------------------" << fd << "---------" << size << endl;
2514 source = OH_AVSource_CreateWithFD(fd, 0, size);
2515 ASSERT_NE(source, nullptr);
2516
2517 demuxer = OH_AVDemuxer_CreateWithSource(source);
2518 ASSERT_NE(demuxer, nullptr);
2519
2520 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_SelectTrackByID(demuxer, 0));
2521 int vKeyCount = 0;
2522 while (!videoIsEnd) {
2523 trackFormat = OH_AVSource_GetTrackFormat(source, 0);
2524 ASSERT_NE(trackFormat, nullptr);
2525 ASSERT_TRUE(OH_AVFormat_GetIntValue(trackFormat, OH_MD_KEY_TRACK_TYPE, &tarckType));
2526 if (videoIsEnd && (tarckType == 1)) {
2527 continue;
2528 }
2529 ASSERT_EQ(AV_ERR_OK, OH_AVDemuxer_ReadSample(demuxer, 0, memory, &attr));
2530 SetVideoValue(attr, videoIsEnd, videoFrame, vKeyCount);
2531 }
2532 ASSERT_EQ(videoFrame, 602);
2533 ASSERT_EQ(vKeyCount, 3);
2534 close(fd);
2535 }