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