1 /* 2 * Copyright (C) 2024 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 <string> 17 #include <malloc.h> 18 #include <sys/stat.h> 19 #include <cinttypes> 20 #include <fcntl.h> 21 #include <list> 22 #include <cmath> 23 #include "gtest/gtest.h" 24 #include "avcodec_errors.h" 25 #include "media_description.h" 26 #include "file_server_demo.h" 27 #include "demuxer_unit_test.h" 28 29 #define LOCAL true 30 #define URI false 31 32 using namespace OHOS; 33 using namespace OHOS::Media; 34 using namespace OHOS::MediaAVCodec; 35 using namespace testing::ext; 36 using namespace std; 37 38 namespace { 39 unique_ptr<FileServerDemo> server = nullptr; 40 static const string TEST_FILE_PATH = "/data/test/media/"; 41 static const string TEST_URI_PATH = "http://127.0.0.1:46666/"; 42 43 list<SeekMode> seekModes = {SeekMode::SEEK_NEXT_SYNC, SeekMode::SEEK_PREVIOUS_SYNC, 44 SeekMode::SEEK_CLOSEST_SYNC}; 45 string g_mpegPath = TEST_FILE_PATH + string("mpeg_h264_mp2.mpeg"); 46 string g_mpegPath2 = TEST_FILE_PATH + string("mpeg_h264_mp3.mpeg"); 47 string g_mpegPath3 = TEST_FILE_PATH + string("mpeg_mpeg2_mp2.mpeg"); 48 string g_mpegPath4 = TEST_FILE_PATH + string("mpeg_mpeg2_mp3.mpeg"); 49 string g_mpegUri = TEST_URI_PATH + string("mpeg_h264_mp2.mpeg"); 50 string g_mpegUri2 = TEST_URI_PATH + string("mpeg_h264_mp3.mpeg"); 51 string g_mpegUri3 = TEST_URI_PATH + string("mpeg_mpeg2_mp2.mpeg"); 52 string g_mpegUri4 = TEST_URI_PATH + string("mpeg_mpeg2_mp3.mpeg"); 53 } //namespace 54 55 56 namespace { 57 /** 58 * @tc.name: Demuxer_ReadSample_2250 59 * @tc.desc: Read sample test for timed metadata track,local 60 * @tc.type: FUNC 61 */ 62 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_2250, TestSize.Level1) 63 { 64 InitResource(g_mpegPath, LOCAL); 65 ASSERT_TRUE(initStatus_); 66 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK); 67 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK); 68 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_); 69 ASSERT_NE(sharedMem_, nullptr); 70 SetInitValue(); 71 while (!isEOS(eosFlag_)) { 72 for (auto idx : selectedTrackIds_) { 73 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK); 74 CountFrames(idx); 75 } 76 } 77 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]); 78 printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]); 79 ASSERT_EQ(frames_[0], 1253); 80 ASSERT_EQ(frames_[1], 2164); 81 ASSERT_EQ(keyFrames_[0], 19); 82 ASSERT_EQ(keyFrames_[1], 2164); 83 RemoveValue(); 84 } 85 86 /** 87 * @tc.name: Demuxer_ReadSample_2251 88 * @tc.desc: Read sample test for timed metadata track,local 89 * @tc.type: FUNC 90 */ 91 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_2251, TestSize.Level1) 92 { 93 InitResource(g_mpegPath2, LOCAL); 94 ASSERT_TRUE(initStatus_); 95 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK); 96 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK); 97 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_); 98 ASSERT_NE(sharedMem_, nullptr); 99 SetInitValue(); 100 while (!isEOS(eosFlag_)) { 101 for (auto idx : selectedTrackIds_) { 102 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK); 103 CountFrames(idx); 104 } 105 } 106 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]); 107 printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]); 108 ASSERT_EQ(frames_[0], 1253); 109 ASSERT_EQ(frames_[1], 2165); 110 ASSERT_EQ(keyFrames_[0], 19); 111 ASSERT_EQ(keyFrames_[1], 2165); 112 RemoveValue(); 113 } 114 115 /** 116 * @tc.name: Demuxer_ReadSample_2252 117 * @tc.desc: Read sample test for timed metadata track,local 118 * @tc.type: FUNC 119 */ 120 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_2252, TestSize.Level1) 121 { 122 InitResource(g_mpegPath3, LOCAL); 123 ASSERT_TRUE(initStatus_); 124 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK); 125 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK); 126 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_); 127 ASSERT_NE(sharedMem_, nullptr); 128 SetInitValue(); 129 while (!isEOS(eosFlag_)) { 130 for (auto idx : selectedTrackIds_) { 131 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK); 132 CountFrames(idx); 133 } 134 } 135 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]); 136 printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]); 137 ASSERT_EQ(frames_[0], 1253); 138 ASSERT_EQ(frames_[1], 2164); 139 ASSERT_EQ(keyFrames_[0], 109); 140 ASSERT_EQ(keyFrames_[1], 2164); 141 RemoveValue(); 142 } 143 144 /** 145 * @tc.name: Demuxer_ReadSample_2253 146 * @tc.desc: Read sample test for timed metadata track,local 147 * @tc.type: FUNC 148 */ 149 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_2253, TestSize.Level1) 150 { 151 InitResource(g_mpegPath4, LOCAL); 152 ASSERT_TRUE(initStatus_); 153 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK); 154 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK); 155 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_); 156 ASSERT_NE(sharedMem_, nullptr); 157 SetInitValue(); 158 while (!isEOS(eosFlag_)) { 159 for (auto idx : selectedTrackIds_) { 160 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK); 161 CountFrames(idx); 162 } 163 } 164 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]); 165 printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]); 166 ASSERT_EQ(frames_[0], 1253); 167 ASSERT_EQ(frames_[1], 2165); 168 ASSERT_EQ(keyFrames_[0], 120); 169 ASSERT_EQ(keyFrames_[1], 2165); 170 RemoveValue(); 171 } 172 173 /** 174 * @tc.name: Demuxer_ReadSample_2260 175 * @tc.desc: copy current sample to buffer,Uri 176 * @tc.type: FUNC 177 */ 178 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_2260, TestSize.Level1) 179 { 180 InitResource(g_mpegUri, URI); 181 ASSERT_TRUE(initStatus_); 182 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK); 183 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK); 184 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_); 185 ASSERT_NE(sharedMem_, nullptr); 186 SetInitValue(); 187 while (!isEOS(eosFlag_)) { 188 for (auto idx : selectedTrackIds_) { 189 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK); 190 CountFrames(idx); 191 } 192 } 193 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]); 194 printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]); 195 ASSERT_EQ(frames_[0], 1253); 196 ASSERT_EQ(frames_[1], 2164); 197 ASSERT_EQ(keyFrames_[0], 19); 198 ASSERT_EQ(keyFrames_[1], 2164); 199 RemoveValue(); 200 } 201 202 /** 203 * @tc.name: Demuxer_ReadSample_2261 204 * @tc.desc: copy current sample to buffer,Uri 205 * @tc.type: FUNC 206 */ 207 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_2261, TestSize.Level1) 208 { 209 InitResource(g_mpegUri2, URI); 210 ASSERT_TRUE(initStatus_); 211 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK); 212 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK); 213 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_); 214 ASSERT_NE(sharedMem_, nullptr); 215 SetInitValue(); 216 while (!isEOS(eosFlag_)) { 217 for (auto idx : selectedTrackIds_) { 218 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK); 219 CountFrames(idx); 220 } 221 } 222 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]); 223 printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]); 224 ASSERT_EQ(frames_[0], 1253); 225 ASSERT_EQ(frames_[1], 2165); 226 ASSERT_EQ(keyFrames_[0], 19); 227 ASSERT_EQ(keyFrames_[1], 2165); 228 RemoveValue(); 229 } 230 231 /** 232 * @tc.name: Demuxer_ReadSample_2262 233 * @tc.desc: copy current sample to buffer,Uri 234 * @tc.type: FUNC 235 */ 236 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_2262, TestSize.Level1) 237 { 238 InitResource(g_mpegUri3, URI); 239 ASSERT_TRUE(initStatus_); 240 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK); 241 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK); 242 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_); 243 ASSERT_NE(sharedMem_, nullptr); 244 SetInitValue(); 245 while (!isEOS(eosFlag_)) { 246 for (auto idx : selectedTrackIds_) { 247 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK); 248 CountFrames(idx); 249 } 250 } 251 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]); 252 printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]); 253 ASSERT_EQ(frames_[0], 1253); 254 ASSERT_EQ(frames_[1], 2164); 255 ASSERT_EQ(keyFrames_[0], 109); 256 ASSERT_EQ(keyFrames_[1], 2164); 257 RemoveValue(); 258 } 259 260 /** 261 * @tc.name: Demuxer_ReadSample_2263 262 * @tc.desc: copy current sample to buffer,Uri 263 * @tc.type: FUNC 264 */ 265 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_2263, TestSize.Level1) 266 { 267 InitResource(g_mpegUri4, URI); 268 ASSERT_TRUE(initStatus_); 269 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK); 270 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK); 271 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_); 272 ASSERT_NE(sharedMem_, nullptr); 273 SetInitValue(); 274 while (!isEOS(eosFlag_)) { 275 for (auto idx : selectedTrackIds_) { 276 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK); 277 CountFrames(idx); 278 } 279 } 280 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]); 281 printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]); 282 ASSERT_EQ(frames_[0], 1253); 283 ASSERT_EQ(frames_[1], 2165); 284 ASSERT_EQ(keyFrames_[0], 120); 285 ASSERT_EQ(keyFrames_[1], 2165); 286 RemoveValue(); 287 } 288 289 /** 290 * @tc.name: Demuxer_SeekToTime_2250 291 * @tc.desc: seek to the specified time 292 * @tc.type: FUNC 293 */ 294 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2250, TestSize.Level1) 295 { 296 InitResource(g_mpegPath, LOCAL); 297 ASSERT_TRUE(initStatus_); 298 SetInitValue(); 299 for (auto idx : selectedTrackIds_) { 300 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK); 301 } 302 list<int64_t> toPtsList = {0, 25000, 40000, 30000}; // ms 303 vector<int32_t> videoVals = {1253, 1253, 1253, 651, 651, 651, 291, 291, 291, 531, 531, 531}; 304 vector<int32_t> audioVals = {2164, 2164, 2164, 1146, 1146, 1146, 523, 523, 523, 928, 928, 928}; 305 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_); 306 ASSERT_NE(sharedMem_, nullptr); 307 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) { 308 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) { 309 ret_ = demuxer_->SeekToTime(*toPts, *mode); 310 if (ret_ != AV_ERR_OK) { 311 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_); 312 continue; 313 } 314 ReadData(); 315 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]); 316 printf("time = %" PRId64 " | frames_[1]=%d\n", *toPts, frames_[1]); 317 ASSERT_EQ(frames_[0], videoVals[numbers_]); 318 ASSERT_EQ(frames_[1], audioVals[numbers_]); 319 numbers_ += 1; 320 RemoveValue(); 321 selectedTrackIds_.clear(); 322 } 323 } 324 } 325 326 /** 327 * @tc.name: Demuxer_SeekToTime_2251 328 * @tc.desc: seek to the specified time 329 * @tc.type: FUNC 330 */ 331 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2251, TestSize.Level1) 332 { 333 InitResource(g_mpegPath2, LOCAL); 334 ASSERT_TRUE(initStatus_); 335 SetInitValue(); 336 for (auto idx : selectedTrackIds_) { 337 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK); 338 } 339 list<int64_t> toPtsList = {0, 25000, 40000, 30000}; // ms 340 vector<int32_t> videoVals = {1253, 1253, 1253, 651, 651, 651, 291, 291, 291, 531, 531, 531}; 341 vector<int32_t> audioVals = {2165, 2165, 2165, 1136, 1136, 1136, 519, 519, 519, 916, 916, 916}; 342 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_); 343 ASSERT_NE(sharedMem_, nullptr); 344 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) { 345 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) { 346 ret_ = demuxer_->SeekToTime(*toPts, *mode); 347 if (ret_ != AV_ERR_OK) { 348 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_); 349 continue; 350 } 351 ReadData(); 352 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]); 353 printf("time = %" PRId64 " | frames_[1]=%d\n", *toPts, frames_[1]); 354 ASSERT_EQ(frames_[0], videoVals[numbers_]); 355 ASSERT_EQ(frames_[1], audioVals[numbers_]); 356 numbers_ += 1; 357 RemoveValue(); 358 selectedTrackIds_.clear(); 359 } 360 } 361 } 362 363 /** 364 * @tc.name: Demuxer_SeekToTime_2252 365 * @tc.desc: seek to the specified time 366 * @tc.type: FUNC 367 */ 368 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2252, TestSize.Level1) 369 { 370 InitResource(g_mpegPath3, LOCAL); 371 ASSERT_TRUE(initStatus_); 372 SetInitValue(); 373 for (auto idx : selectedTrackIds_) { 374 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK); 375 } 376 list<int64_t> toPtsList = {0, 25000, 40000, 30000}; // ms 377 vector<int32_t> videoVals = {1253, 1253, 1253, 653, 653, 653, 293, 293, 293, 533, 533, 533}; 378 vector<int32_t> audioVals = {2162, 2162, 2162, 1150, 1150, 1150, 525, 525, 525, 941, 941, 941}; 379 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_); 380 ASSERT_NE(sharedMem_, nullptr); 381 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) { 382 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) { 383 ret_ = demuxer_->SeekToTime(*toPts, *mode); 384 if (ret_ != AV_ERR_OK) { 385 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_); 386 continue; 387 } 388 ReadData(); 389 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]); 390 printf("time = %" PRId64 " | frames_[1]=%d\n", *toPts, frames_[1]); 391 ASSERT_EQ(frames_[0], videoVals[numbers_]); 392 ASSERT_EQ(frames_[1], audioVals[numbers_]); 393 numbers_ += 1; 394 RemoveValue(); 395 selectedTrackIds_.clear(); 396 } 397 } 398 } 399 400 401 /** 402 * @tc.name: Demuxer_SeekToTime_2253 403 * @tc.desc: seek to the specified time 404 * @tc.type: FUNC 405 */ 406 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2253, TestSize.Level1) 407 { 408 InitResource(g_mpegPath4, LOCAL); 409 ASSERT_TRUE(initStatus_); 410 SetInitValue(); 411 for (auto idx : selectedTrackIds_) { 412 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK); 413 } 414 list<int64_t> toPtsList = {0, 25000, 40000, 30000}; // ms 415 vector<int32_t> videoVals = {1253, 1253, 1253, 653, 653, 653, 293, 293, 293, 533, 533, 533}; 416 vector<int32_t> audioVals = {2159, 2159, 2159, 1131, 1131, 1131, 503, 503, 503, 915, 915, 915}; 417 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_); 418 ASSERT_NE(sharedMem_, nullptr); 419 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) { 420 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) { 421 ret_ = demuxer_->SeekToTime(*toPts, *mode); 422 if (ret_ != AV_ERR_OK) { 423 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_); 424 continue; 425 } 426 ReadData(); 427 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]); 428 printf("time = %" PRId64 " | frames_[1]=%d\n", *toPts, frames_[1]); 429 ASSERT_EQ(frames_[0], videoVals[numbers_]); 430 ASSERT_EQ(frames_[1], audioVals[numbers_]); 431 numbers_ += 1; 432 RemoveValue(); 433 selectedTrackIds_.clear(); 434 } 435 } 436 } 437 438 /** 439 * @tc.name: Demuxer_SeekToTime_2260 440 * @tc.desc: seek to the specified time 441 * @tc.type: FUNC 442 */ 443 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2260, TestSize.Level1) 444 { 445 InitResource(g_mpegUri, URI); 446 ASSERT_TRUE(initStatus_); 447 SetInitValue(); 448 for (auto idx : selectedTrackIds_) { 449 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK); 450 } 451 list<int64_t> toPtsList = {0, 25000, 40000, 30000}; // ms 452 vector<int32_t> videoVals = {1253, 1253, 1253, 651, 651, 651, 291, 291, 291, 531, 531, 531}; 453 vector<int32_t> audioVals = {2164, 2164, 2164, 1146, 1146, 1146, 523, 523, 523, 928, 928, 928}; 454 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_); 455 ASSERT_NE(sharedMem_, nullptr); 456 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) { 457 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) { 458 ret_ = demuxer_->SeekToTime(*toPts, *mode); 459 if (ret_ != AV_ERR_OK) { 460 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_); 461 continue; 462 } 463 ReadData(); 464 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]); 465 printf("time = %" PRId64 " | frames_[1]=%d\n", *toPts, frames_[1]); 466 ASSERT_EQ(frames_[0], videoVals[numbers_]); 467 ASSERT_EQ(frames_[1], audioVals[numbers_]); 468 numbers_ += 1; 469 RemoveValue(); 470 selectedTrackIds_.clear(); 471 } 472 } 473 } 474 475 /** 476 * @tc.name: Demuxer_SeekToTime_2261 477 * @tc.desc: seek to the specified time 478 * @tc.type: FUNC 479 */ 480 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2261, TestSize.Level1) 481 { 482 InitResource(g_mpegUri2, URI); 483 ASSERT_TRUE(initStatus_); 484 SetInitValue(); 485 for (auto idx : selectedTrackIds_) { 486 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK); 487 } 488 list<int64_t> toPtsList = {0, 25000, 40000, 30000}; // ms 489 vector<int32_t> videoVals = {1253, 1253, 1253, 651, 651, 651, 291, 291, 291, 531, 531, 531}; 490 vector<int32_t> audioVals = {2165, 2165, 2165, 1136, 1136, 1136, 519, 519, 519, 916, 916, 916}; 491 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_); 492 ASSERT_NE(sharedMem_, nullptr); 493 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) { 494 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) { 495 ret_ = demuxer_->SeekToTime(*toPts, *mode); 496 if (ret_ != AV_ERR_OK) { 497 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_); 498 continue; 499 } 500 ReadData(); 501 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]); 502 printf("time = %" PRId64 " | frames_[1]=%d\n", *toPts, frames_[1]); 503 ASSERT_EQ(frames_[0], videoVals[numbers_]); 504 ASSERT_EQ(frames_[1], audioVals[numbers_]); 505 numbers_ += 1; 506 RemoveValue(); 507 selectedTrackIds_.clear(); 508 } 509 } 510 } 511 512 /** 513 * @tc.name: Demuxer_SeekToTime_2262 514 * @tc.desc: seek to the specified time 515 * @tc.type: FUNC 516 */ 517 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2262, TestSize.Level1) 518 { 519 InitResource(g_mpegUri3, URI); 520 ASSERT_TRUE(initStatus_); 521 SetInitValue(); 522 for (auto idx : selectedTrackIds_) { 523 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK); 524 } 525 list<int64_t> toPtsList = {0, 25000, 40000, 30000}; // ms 526 vector<int32_t> videoVals = {1253, 1253, 1253, 653, 653, 653, 293, 293, 293, 533, 533, 533}; 527 vector<int32_t> audioVals = {2162, 2162, 2162, 1150, 1150, 1150, 525, 525, 525, 941, 941, 941}; 528 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_); 529 ASSERT_NE(sharedMem_, nullptr); 530 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) { 531 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) { 532 ret_ = demuxer_->SeekToTime(*toPts, *mode); 533 if (ret_ != AV_ERR_OK) { 534 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_); 535 continue; 536 } 537 ReadData(); 538 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]); 539 printf("time = %" PRId64 " | frames_[1]=%d\n", *toPts, frames_[1]); 540 ASSERT_EQ(frames_[0], videoVals[numbers_]); 541 ASSERT_EQ(frames_[1], audioVals[numbers_]); 542 numbers_ += 1; 543 RemoveValue(); 544 selectedTrackIds_.clear(); 545 } 546 } 547 } 548 549 /** 550 * @tc.name: Demuxer_SeekToTime_2263 551 * @tc.desc: seek to the specified time 552 * @tc.type: FUNC 553 */ 554 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2263, TestSize.Level1) 555 { 556 InitResource(g_mpegUri4, URI); 557 ASSERT_TRUE(initStatus_); 558 SetInitValue(); 559 for (auto idx : selectedTrackIds_) { 560 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK); 561 } 562 list<int64_t> toPtsList = {0, 25000, 40000, 30000}; // ms 563 vector<int32_t> videoVals = {1253, 1253, 1253, 653, 653, 653, 293, 293, 293, 533, 533, 533}; 564 vector<int32_t> audioVals = {2159, 2159, 2159, 1131, 1131, 1131, 503, 503, 503, 915, 915, 915}; 565 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_); 566 ASSERT_NE(sharedMem_, nullptr); 567 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) { 568 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) { 569 ret_ = demuxer_->SeekToTime(*toPts, *mode); 570 if (ret_ != AV_ERR_OK) { 571 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_); 572 continue; 573 } 574 ReadData(); 575 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]); 576 printf("time = %" PRId64 " | frames_[1]=%d\n", *toPts, frames_[1]); 577 ASSERT_EQ(frames_[0], videoVals[numbers_]); 578 ASSERT_EQ(frames_[1], audioVals[numbers_]); 579 numbers_ += 1; 580 RemoveValue(); 581 selectedTrackIds_.clear(); 582 } 583 } 584 } 585 } //namespace