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