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 <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
31 using namespace OHOS;
32 using namespace OHOS::Media;
33 using namespace OHOS::MediaAVCodec;
34 using namespace testing::ext;
35 using namespace std;
36
37 namespace {
38 unique_ptr<FileServerDemo> server = nullptr;
39 static const string TEST_FILE_PATH = "/data/test/media/";
40 static const string TEST_URI_PATH = "http://127.0.0.1:46666/";
41 static const std::string_view OH_MD_KEY_COMMENT = "comment";
42 int32_t g_width = 3840;
43 int32_t g_height = 2160;
44 list<SeekMode> seekModes = {SeekMode::SEEK_NEXT_SYNC, SeekMode::SEEK_PREVIOUS_SYNC,
45 SeekMode::SEEK_CLOSEST_SYNC};
46 static const string AIGC_TEST_STR1 = "{Label:value1,ContentProducer:value2,ProduceID:value3,ReservedCode1:value4,"\
47 "ContentPropagator:value5,PropagateID:value6,ReservedCode2:value7}";
48 static const string AIGC_TEST_STR2 = "'{Label:value1,ContentProducer:value2,ProduceID:value3,ReservedCode1:value4,"\
49 "ContentPropagator:value5,PropagateID:value6,ReservedCode2:value7}'";
50 static const string AIGC_TEST_STR3 = "{\"Label\":\"value1\",\"ContentProducer\":\"value2\",\"ProduceID\":\"value3\","\
51 "\"ReservedCode1\":\"value4\",\"ContentPropagator\":\"value5\",\"PropagateID\":\"value6\",\"ReservedCode2\":"\
52 "\"value7\"}";
53
54 string g_mp4Path = TEST_FILE_PATH + string("test_264_B_Gop25_4sec_cover.mp4");
55 string g_mp4Path2 = TEST_FILE_PATH + string("test_mpeg2_B_Gop25_4sec.mp4");
56 string g_mp4Path3 = TEST_FILE_PATH + string("test_mpeg2_B_Gop25_4sec_attachment.mkv");
57 string g_mp4Path4 = TEST_FILE_PATH + string("zero_track.mp4");
58 string g_mp4Path5 = TEST_FILE_PATH + string("timed_metadata_track.mp4");
59 string g_mkvPath2 = TEST_FILE_PATH + string("h264_opus_4sec.mkv");
60 string g_tsPath = TEST_FILE_PATH + string("test_mpeg2_Gop25_4sec.ts");
61 string g_aacPath = TEST_FILE_PATH + string("audio/aac_44100_1.aac");
62 string g_flacPath = TEST_FILE_PATH + string("audio/flac_48000_1_cover.flac");
63 string g_m4aPath = TEST_FILE_PATH + string("audio/m4a_48000_1.m4a");
64 string g_mp3Path = TEST_FILE_PATH + string("audio/mp3_48000_1_cover.mp3");
65 string g_oggPath = TEST_FILE_PATH + string("audio/ogg_48000_1.ogg");
66 string g_wavPath = TEST_FILE_PATH + string("audio/wav_48000_1.wav");
67 string g_amrPath = TEST_FILE_PATH + string("audio/amr_nb_8000_1.amr");
68 string g_amrPath2 = TEST_FILE_PATH + string("audio/amr_wb_16000_1.amr");
69 string g_audioVividPath = TEST_FILE_PATH + string("2obj_44100Hz_16bit_32k.mp4");
70 string g_audioVividPath1 = TEST_FILE_PATH + string("2obj_44100Hz_16bit_32k_noftyp.mp4");
71 string g_audioVividPath2 = TEST_FILE_PATH + string("2obj_44100Hz_16bit_32k.ts");
72 string g_multiSoundTrackMp4Path = TEST_FILE_PATH + string("avcc_aac_mp3.mp4");
73 string g_flvPath = TEST_FILE_PATH + string("h264.flv");
74 string g_apePath = TEST_FILE_PATH + string("ape_test.ape");
75 string g_fmp4AvcPath = TEST_FILE_PATH + string("h264_fmp4.mp4");
76 string g_fmp4m4vPath = TEST_FILE_PATH + string("h264_fmp4.m4v");
77 string g_fmp4m4aPath = TEST_FILE_PATH + string("audio/h264_fmp4.m4a");
78 string g_srt = TEST_FILE_PATH + string("subtitle.srt");
79 string g_drmSm4cPath = TEST_FILE_PATH + string("drm/sm4c.ts");
80 string g_vttPath = TEST_FILE_PATH + string("webvtt_test.vtt");
81 string g_vttPath2 = TEST_FILE_PATH + string("webvtt_test2.vtt");
82 string g_vttMp4Path = TEST_FILE_PATH + string("webvtt.mp4");
83 string g_ptsConversionPath = TEST_FILE_PATH + string("camera_info_parser.mp4");
84 string g_mp4VvcPath = TEST_FILE_PATH + string("vvc.mp4");
85 string g_rmvbPath = TEST_FILE_PATH + string("rv40_cook.rmvb");
86 string g_ac3Path = TEST_FILE_PATH + string("audio/ac3_test.ac3");
87 string g_webmPath = TEST_FILE_PATH + string("vp8_vorbis.webm");
88 string g_mtsPath = TEST_FILE_PATH + string("h264_ac3.mts");
89 string g_vobPath = TEST_FILE_PATH + string("mpeg2_ac3.vob");
90 string g_m2tsPath = TEST_FILE_PATH + string("mpeg2_ac3.m2ts");
91 string g_trpPath = TEST_FILE_PATH + string("mpeg2_ac3.trp");
92 string g_lrcPath = TEST_FILE_PATH + string("lrc_test.lrc");
93 string g_samiPath = TEST_FILE_PATH + string("sami_test.smi");
94 string g_assPath = TEST_FILE_PATH + string("ass_test.ssa");
95 string g_commentTest1000Path = TEST_FILE_PATH + string("audio/Muxer_SetFormat_Comment_1000.mp4");
96 string g_commentTest1100Path = TEST_FILE_PATH + string("audio/Muxer_SetFormat_Comment_1100.mp4");
97 string g_commentTest1200Path = TEST_FILE_PATH + string("audio/Muxer_SetFormat_Comment_1200.mp4");
98 string g_commentTest1300Path = TEST_FILE_PATH + string("audio/Muxer_SetFormat_Comment_1300.mp4");
99 string g_wavAlawPath = TEST_FILE_PATH + string("audio/wav_48000_1_pcm_alaw.wav");
100 string g_reservedMp4Path = TEST_FILE_PATH + string("reserved_buffer_test.mp4");
101 string g_aigcStrMp4Path = TEST_FILE_PATH + string("aigc_str.mp4");
102 string g_aigcStrM4aPath = TEST_FILE_PATH + string("aigc_str.m4a");
103 string g_aigcStrM4vPath = TEST_FILE_PATH + string("aigc_str.m4v");
104 string g_aigcStrMovPath = TEST_FILE_PATH + string("aigc_str.mov");
105 string g_aigcStrFlvPath = TEST_FILE_PATH + string("aigc_str.flv");
106 string g_aigcStrMkvPath = TEST_FILE_PATH + string("aigc_str.mkv");
107 string g_aigcStrAviPath = TEST_FILE_PATH + string("aigc_str.avi");
108 } // namespace
109
SetUpTestCase(void)110 void DemuxerUnitTest::SetUpTestCase(void)
111 {
112 server = make_unique<FileServerDemo>();
113 server->StartServer();
114 cout << "start" << endl;
115 }
116
TearDownTestCase(void)117 void DemuxerUnitTest::TearDownTestCase(void)
118 {
119 server->StopServer();
120 }
121
SetUp(void)122 void DemuxerUnitTest::SetUp(void)
123 {
124 bufferSize_ = g_width * g_height;
125 }
126
TearDown(void)127 void DemuxerUnitTest::TearDown(void)
128 {
129 if (source_ != nullptr) {
130 source_->Destroy();
131 source_ = nullptr;
132 }
133 if (demuxer_ != nullptr) {
134 demuxer_->Destroy();
135 demuxer_ = nullptr;
136 }
137 if (format_ != nullptr) {
138 format_->Destroy();
139 format_ = nullptr;
140 }
141 if (sharedMem_ != nullptr) {
142 sharedMem_->Destory();
143 sharedMem_ = nullptr;
144 }
145 if (fd_ > 0) {
146 close(fd_);
147 fd_ = -1;
148 }
149 bufferSize_ = 0;
150 nbStreams_ = 0;
151 numbers_ = 0;
152 ret_ = AV_ERR_OK;
153 info_.presentationTimeUs = 0;
154 info_.offset = 0;
155 info_.size = 0;
156 initStatus_ = false;
157 selectedTrackIds_.clear();
158 }
159
GetFileSize(const string & fileName)160 int64_t DemuxerUnitTest::GetFileSize(const string &fileName)
161 {
162 int64_t fileSize = 0;
163 if (!fileName.empty()) {
164 struct stat fileStatus {};
165 if (stat(fileName.c_str(), &fileStatus) == 0) {
166 fileSize = static_cast<int64_t>(fileStatus.st_size);
167 }
168 }
169 return fileSize;
170 }
171
OpenFile(const string & fileName)172 int32_t DemuxerUnitTest::OpenFile(const string &fileName)
173 {
174 int32_t fd = open(fileName.c_str(), O_RDONLY);
175 return fd;
176 }
177
isEOS(map<uint32_t,bool> & countFlag)178 bool DemuxerUnitTest::isEOS(map<uint32_t, bool>& countFlag)
179 {
180 for (auto iter = countFlag.begin(); iter != countFlag.end(); ++iter) {
181 if (!iter->second) {
182 return false;
183 }
184 }
185 return true;
186 }
187
SetInitValue()188 bool DemuxerUnitTest::SetInitValue()
189 {
190 if (source_ == nullptr) {
191 printf("source_ is nullptr\n");
192 return false;
193 }
194 for (int i = 0; i < nbStreams_; i++) {
195 string codecMime = "";
196 int32_t trackType = -1;
197 if (format_ != nullptr) {
198 format_->Destroy();
199 format_ = nullptr;
200 }
201 format_ = source_->GetTrackFormat(i);
202 if (format_ == nullptr) {
203 return false;
204 }
205 format_->GetStringValue(MediaDescriptionKey::MD_KEY_CODEC_MIME, codecMime);
206 format_->GetIntValue(MediaDescriptionKey::MD_KEY_TRACK_TYPE, trackType);
207 if (codecMime.find("image/") != std::string::npos) {
208 continue;
209 }
210 if (trackType == OH_MediaType::MEDIA_TYPE_VID || trackType == OH_MediaType::MEDIA_TYPE_AUD ||
211 trackType == OH_MediaType::MEDIA_TYPE_SUBTITLE || trackType == OH_MediaType::MEDIA_TYPE_TIMED_METADATA ||
212 trackType == OH_MediaType::MEDIA_TYPE_AUXILIARY) {
213 selectedTrackIds_.push_back(static_cast<uint32_t>(i));
214 frames_[i] = 0;
215 keyFrames_[i] = 0;
216 eosFlag_[i] = false;
217 }
218 }
219 return true;
220 }
221
RemoveValue()222 void DemuxerUnitTest::RemoveValue()
223 {
224 if (!frames_.empty()) {
225 frames_.clear();
226 }
227 if (!keyFrames_.empty()) {
228 keyFrames_.clear();
229 }
230 if (!eosFlag_.empty()) {
231 eosFlag_.clear();
232 }
233 }
234
SetEosValue()235 void DemuxerUnitTest::SetEosValue()
236 {
237 for (int i = 0; i < nbStreams_; i++) {
238 eosFlag_[i] = true;
239 }
240 }
241
CountFrames(uint32_t index)242 void DemuxerUnitTest::CountFrames(uint32_t index)
243 {
244 if (flag_ & AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_EOS) {
245 eosFlag_[index] = true;
246 return;
247 }
248
249 if (flag_ & AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_SYNC_FRAME) {
250 keyFrames_[index]++;
251 frames_[index]++;
252 } else if ((flag_ & AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_NONE) == AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_NONE) {
253 frames_[index]++;
254 } else {
255 SetEosValue();
256 printf("flag is unknown, read sample break");
257 }
258 }
259
CheckKeyFrameIndex(std::vector<uint32_t> keyFrameIndexList,const uint32_t frameIndex,const bool isKeyFrame)260 bool DemuxerUnitTest::CheckKeyFrameIndex(
261 std::vector<uint32_t> keyFrameIndexList, const uint32_t frameIndex, const bool isKeyFrame)
262 {
263 bool contaionIndex = (std::count(keyFrameIndexList.begin(), keyFrameIndexList.end(), frameIndex) > 0);
264 return isKeyFrame ? contaionIndex : !contaionIndex;
265 }
266
ReadData()267 void DemuxerUnitTest::ReadData()
268 {
269 ASSERT_TRUE(SetInitValue());
270 while (!isEOS(eosFlag_)) {
271 for (auto idx : selectedTrackIds_) {
272 demuxer_->ReadSample(idx, sharedMem_, &info_, flag_);
273 if (ret_ != AV_ERR_OK) {
274 break;
275 }
276 CountFrames(idx);
277 }
278 if (ret_ != AV_ERR_OK) {
279 break;
280 }
281 }
282 }
283
ReadData(int readNum,int64_t & seekTime)284 void DemuxerUnitTest::ReadData(int readNum, int64_t &seekTime)
285 {
286 int num = 0;
287 ASSERT_TRUE(SetInitValue());
288 while (!isEOS(eosFlag_)) {
289 for (auto idx : selectedTrackIds_) {
290 ret_ = demuxer_->ReadSample(idx, sharedMem_, &info_, flag_);
291 if (ret_ != AV_ERR_OK) {
292 break;
293 }
294 CountFrames(idx);
295 }
296 if (ret_ != AV_ERR_OK) {
297 break;
298 }
299 if (num == readNum) {
300 seekTime = info_.presentationTimeUs;
301 break;
302 }
303 }
304 }
305
SeekTest(const std::list<int64_t> & toPtsList,const std::list<Media::SeekMode> & sm,const std::vector<std::vector<int32_t>> & ExpVals)306 void DemuxerUnitTest::SeekTest(const std::list<int64_t> &toPtsList, const std::list<Media::SeekMode> &sm,
307 const std::vector<std::vector<int32_t>> &ExpVals)
308 {
309 seekTestFlag_ = false;
310 for (auto &toPts : toPtsList) {
311 for (auto &mode : sm) {
312 ret_ = demuxer_->SeekToTime(toPts, mode);
313 if (ret_ != AV_ERR_OK) {
314 printf("seek failed, time = %" PRId64 " | ret = %d\n", toPts, ret_);
315 continue;
316 }
317 ReadData();
318 for (size_t i = 0; i < ExpVals.size(); i++) {
319 printf("time = %" PRId64 " | frames_[%d]=%d\n", toPts, static_cast<int32_t>(i), frames_[i]);
320 ASSERT_EQ(frames_[i], ExpVals[i][numbers_]);
321 }
322 numbers_ += 1;
323 RemoveValue();
324 selectedTrackIds_.clear();
325 }
326 }
327 seekTestFlag_ = true;
328 }
329
ReadAllSampleWithCheck(std::vector<uint32_t> & keyFrameIndex)330 void DemuxerUnitTest::ReadAllSampleWithCheck(std::vector<uint32_t> &keyFrameIndex)
331 {
332 readFlag_ = false;
333 while (!isEOS(eosFlag_)) {
334 for (auto idx : selectedTrackIds_) {
335 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
336 if (idx == 0) {
337 ASSERT_TRUE(CheckKeyFrameIndex(
338 keyFrameIndex, frames_[0], flag_ & AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_SYNC_FRAME));
339 }
340 CountFrames(idx);
341 }
342 }
343 readFlag_ = true;
344 }
345
346 /**********************************demuxer fd**************************************/
347 namespace {
348 /**
349 * @tc.name: Demuxer_CreateDemuxer_1000
350 * @tc.desc: create demuxer
351 * @tc.type: FUNC
352 */
353 HWTEST_F(DemuxerUnitTest, Demuxer_CreateDemuxer_1000, TestSize.Level1)
354 {
355 InitResource(g_mp4Path, LOCAL);
356 ASSERT_TRUE(initStatus_);
357 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
358 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
359 ASSERT_NE(demuxer_->SelectTrackByID(3), AV_ERR_OK);
360 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
361 ASSERT_NE(demuxer_->SelectTrackByID(-1), AV_ERR_OK);
362 ASSERT_EQ(demuxer_->UnselectTrackByID(1), AV_ERR_OK);
363 ASSERT_EQ(demuxer_->UnselectTrackByID(3), AV_ERR_OK);
364 ASSERT_EQ(demuxer_->UnselectTrackByID(-1), AV_ERR_OK);
365 }
366
367 /**
368 * @tc.name: Demuxer_CreateDemuxer_1001
369 * @tc.desc: create demuxer
370 * @tc.type: FUNC
371 */
372 HWTEST_F(DemuxerUnitTest, Demuxer_CreateDemuxer_1001, TestSize.Level1)
373 {
374 InitResource(g_mp4Path3, LOCAL);
375 ASSERT_TRUE(initStatus_);
376 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
377 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
378 ASSERT_NE(demuxer_->SelectTrackByID(2), AV_ERR_OK);
379 }
380
381 /**
382 * @tc.name: Demuxer_CreateDemuxer_1010
383 * @tc.desc: create demuxer
384 * @tc.type: FUNC
385 */
386 HWTEST_F(DemuxerUnitTest, Demuxer_CreateDemuxer_1010, TestSize.Level1)
387 {
388 source_ = nullptr;
389 demuxer_ = AVDemuxerMockFactory::CreateDemuxer(source_);
390 ASSERT_EQ(demuxer_, nullptr);
391 demuxer_ = nullptr;
392 }
393
394 /**
395 * @tc.name: Demuxer_CreateDemuxer_1020
396 * @tc.desc: repeatedly create demuxer
397 * @tc.type: FUNC
398 */
399 HWTEST_F(DemuxerUnitTest, Demuxer_CreateDemuxer_1020, TestSize.Level1)
400 {
401 InitResource(g_mp4Path, LOCAL);
402 ASSERT_TRUE(initStatus_);
403 demuxer_ = AVDemuxerMockFactory::CreateDemuxer(source_);
404 ASSERT_NE(demuxer_, nullptr);
405 }
406
407 /**
408 * @tc.name: Demuxer_CreateDemuxer_1030
409 * @tc.desc: create demuxer
410 * @tc.type: FUNC
411 */
412 HWTEST_F(DemuxerUnitTest, Demuxer_CreateDemuxer_1030, TestSize.Level1)
413 {
414 InitResource(g_tsPath, LOCAL);
415 ASSERT_TRUE(initStatus_);
416 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
417 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
418 ASSERT_NE(demuxer_->SelectTrackByID(3), AV_ERR_OK);
419 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
420 ASSERT_NE(demuxer_->SelectTrackByID(-1), AV_ERR_OK);
421 ASSERT_EQ(demuxer_->UnselectTrackByID(1), AV_ERR_OK);
422 ASSERT_EQ(demuxer_->UnselectTrackByID(3), AV_ERR_OK);
423 ASSERT_EQ(demuxer_->UnselectTrackByID(-1), AV_ERR_OK);
424 }
425
426 /**
427 * @tc.name: Demuxer_CreateDemuxer_1040
428 * @tc.desc: create demuxer
429 * @tc.type: FUNC
430 */
431 HWTEST_F(DemuxerUnitTest, Demuxer_CreateDemuxer_1040, TestSize.Level1)
432 {
433 InitResource(g_mp4Path4, LOCAL);
434 ASSERT_TRUE(initStatus_);
435 }
436
437 /**
438 * @tc.name: Demuxer_UnselectTrackByID_1000
439 * @tc.desc: select and remove track by ID
440 * @tc.type: FUNC
441 */
442 HWTEST_F(DemuxerUnitTest, Demuxer_UnselectTrackByID_1000, TestSize.Level1)
443 {
444 InitResource(g_mp4Path4, LOCAL);
445 ASSERT_TRUE(initStatus_);
446 ASSERT_NE(demuxer_->SelectTrackByID(0), AV_ERR_OK);
447 }
448
449 /**
450 * @tc.name: Demuxer_UnselectTrackByID_1010
451 * @tc.desc: select and remove track by ID
452 * @tc.type: FUNC
453 */
454 HWTEST_F(DemuxerUnitTest, Demuxer_UnselectTrackByID_1010, TestSize.Level1)
455 {
456 InitResource(g_aacPath, LOCAL);
457 ASSERT_TRUE(initStatus_);
458 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
459 ASSERT_NE(demuxer_->SelectTrackByID(3), AV_ERR_OK);
460 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
461 ASSERT_NE(demuxer_->SelectTrackByID(-1), AV_ERR_OK);
462 ASSERT_EQ(demuxer_->UnselectTrackByID(0), AV_ERR_OK);
463 ASSERT_EQ(demuxer_->UnselectTrackByID(1), AV_ERR_OK);
464 ASSERT_EQ(demuxer_->UnselectTrackByID(3), AV_ERR_OK);
465 ASSERT_EQ(demuxer_->UnselectTrackByID(-1), AV_ERR_OK);
466 }
467
468 /**
469 * @tc.name: Demuxer_UnselectTrackByID_1020
470 * @tc.desc: select and remove track by ID
471 * @tc.type: FUNC
472 */
473 HWTEST_F(DemuxerUnitTest, Demuxer_UnselectTrackByID_1020, TestSize.Level1)
474 {
475 InitResource(g_flacPath, LOCAL);
476 ASSERT_TRUE(initStatus_);
477 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
478 ASSERT_NE(demuxer_->SelectTrackByID(3), AV_ERR_OK);
479 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
480 ASSERT_NE(demuxer_->SelectTrackByID(-1), AV_ERR_OK);
481 ASSERT_NE(demuxer_->SelectTrackByID(1), AV_ERR_OK);
482 ASSERT_EQ(demuxer_->UnselectTrackByID(0), AV_ERR_OK);
483 ASSERT_EQ(demuxer_->UnselectTrackByID(1), AV_ERR_OK);
484 ASSERT_EQ(demuxer_->UnselectTrackByID(3), AV_ERR_OK);
485 ASSERT_EQ(demuxer_->UnselectTrackByID(-1), AV_ERR_OK);
486 }
487
488 /**
489 * @tc.name: Demuxer_UnselectTrackByID_1030
490 * @tc.desc: select and remove track by ID
491 * @tc.type: FUNC
492 */
493 HWTEST_F(DemuxerUnitTest, Demuxer_UnselectTrackByID_1030, TestSize.Level1)
494 {
495 InitResource(g_m4aPath, LOCAL);
496 ASSERT_TRUE(initStatus_);
497 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
498 ASSERT_NE(demuxer_->SelectTrackByID(3), AV_ERR_OK);
499 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
500 ASSERT_NE(demuxer_->SelectTrackByID(-1), AV_ERR_OK);
501 ASSERT_EQ(demuxer_->UnselectTrackByID(0), AV_ERR_OK);
502 ASSERT_EQ(demuxer_->UnselectTrackByID(1), AV_ERR_OK);
503 ASSERT_EQ(demuxer_->UnselectTrackByID(3), AV_ERR_OK);
504 ASSERT_EQ(demuxer_->UnselectTrackByID(-1), AV_ERR_OK);
505 }
506
507 /**
508 * @tc.name: Demuxer_UnselectTrackByID_1060
509 * @tc.desc: select and remove track by ID
510 * @tc.type: FUNC
511 */
512 HWTEST_F(DemuxerUnitTest, Demuxer_UnselectTrackByID_1060, TestSize.Level1)
513 {
514 InitResource(g_mp3Path, LOCAL);
515 ASSERT_TRUE(initStatus_);
516 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
517 ASSERT_NE(demuxer_->SelectTrackByID(3), AV_ERR_OK);
518 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
519 ASSERT_NE(demuxer_->SelectTrackByID(-1), AV_ERR_OK);
520 ASSERT_EQ(demuxer_->UnselectTrackByID(0), AV_ERR_OK);
521 ASSERT_EQ(demuxer_->UnselectTrackByID(1), AV_ERR_OK);
522 ASSERT_EQ(demuxer_->UnselectTrackByID(3), AV_ERR_OK);
523 ASSERT_EQ(demuxer_->UnselectTrackByID(-1), AV_ERR_OK);
524 }
525
526 /**
527 * @tc.name: Demuxer_UnselectTrackByID_1070
528 * @tc.desc: select and remove track by ID
529 * @tc.type: FUNC
530 */
531 HWTEST_F(DemuxerUnitTest, Demuxer_UnselectTrackByID_1070, TestSize.Level1)
532 {
533 InitResource(g_oggPath, LOCAL);
534 ASSERT_TRUE(initStatus_);
535 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
536 ASSERT_NE(demuxer_->SelectTrackByID(3), AV_ERR_OK);
537 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
538 ASSERT_NE(demuxer_->SelectTrackByID(-1), AV_ERR_OK);
539 ASSERT_EQ(demuxer_->UnselectTrackByID(0), AV_ERR_OK);
540 ASSERT_EQ(demuxer_->UnselectTrackByID(1), AV_ERR_OK);
541 ASSERT_EQ(demuxer_->UnselectTrackByID(3), AV_ERR_OK);
542 ASSERT_EQ(demuxer_->UnselectTrackByID(-1), AV_ERR_OK);
543 }
544
545 /**
546 * @tc.name: Demuxer_UnselectTrackByID_1080
547 * @tc.desc: select and remove track by ID
548 * @tc.type: FUNC
549 */
550 HWTEST_F(DemuxerUnitTest, Demuxer_UnselectTrackByID_1080, TestSize.Level1)
551 {
552 InitResource(g_wavPath, LOCAL);
553 ASSERT_TRUE(initStatus_);
554 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
555 ASSERT_NE(demuxer_->SelectTrackByID(3), AV_ERR_OK);
556 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
557 ASSERT_NE(demuxer_->SelectTrackByID(-1), AV_ERR_OK);
558 ASSERT_EQ(demuxer_->UnselectTrackByID(0), AV_ERR_OK);
559 ASSERT_EQ(demuxer_->UnselectTrackByID(1), AV_ERR_OK);
560 ASSERT_EQ(demuxer_->UnselectTrackByID(3), AV_ERR_OK);
561 ASSERT_EQ(demuxer_->UnselectTrackByID(-1), AV_ERR_OK);
562 }
563
564 /**
565 * @tc.name: Demuxer_UnselectTrackByID_1090
566 * @tc.desc: select and remove track by ID
567 * @tc.type: FUNC
568 */
569 HWTEST_F(DemuxerUnitTest, Demuxer_UnselectTrackByID_1090, TestSize.Level1)
570 {
571 InitResource(g_mkvPath2, LOCAL);
572 ASSERT_TRUE(initStatus_);
573 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
574 ASSERT_NE(demuxer_->SelectTrackByID(3), AV_ERR_OK);
575 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
576 ASSERT_NE(demuxer_->SelectTrackByID(-1), AV_ERR_OK);
577 ASSERT_EQ(demuxer_->UnselectTrackByID(0), AV_ERR_OK);
578 ASSERT_EQ(demuxer_->UnselectTrackByID(1), AV_ERR_OK);
579 ASSERT_EQ(demuxer_->UnselectTrackByID(3), AV_ERR_OK);
580 ASSERT_EQ(demuxer_->UnselectTrackByID(-1), AV_ERR_OK);
581 }
582
583 /**
584 * @tc.name: Demuxer_UnselectTrackByID_1100
585 * @tc.desc: select and remove track by ID
586 * @tc.type: FUNC
587 */
588 HWTEST_F(DemuxerUnitTest, Demuxer_UnselectTrackByID_1100, TestSize.Level1)
589 {
590 InitResource(g_amrPath, LOCAL);
591 ASSERT_TRUE(initStatus_);
592 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
593 ASSERT_NE(demuxer_->SelectTrackByID(3), AV_ERR_OK);
594 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
595 ASSERT_NE(demuxer_->SelectTrackByID(-1), AV_ERR_OK);
596 ASSERT_EQ(demuxer_->UnselectTrackByID(0), AV_ERR_OK);
597 ASSERT_EQ(demuxer_->UnselectTrackByID(1), AV_ERR_OK);
598 ASSERT_EQ(demuxer_->UnselectTrackByID(3), AV_ERR_OK);
599 ASSERT_EQ(demuxer_->UnselectTrackByID(-1), AV_ERR_OK);
600 }
601
602 /**
603 * @tc.name: Demuxer_ReadSample_1000
604 * @tc.desc: copy current sample to buffer
605 * @tc.type: FUNC
606 */
607 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1000, TestSize.Level1)
608 {
609 InitResource(g_mp4Path, LOCAL);
610 ASSERT_TRUE(initStatus_);
611 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
612 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
613 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
614 ASSERT_NE(sharedMem_, nullptr);
615 ASSERT_TRUE(SetInitValue());
616 while (!isEOS(eosFlag_)) {
617 for (auto idx : selectedTrackIds_) {
618 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
619 CountFrames(idx);
620 }
621 }
622 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
623 printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]);
624 ASSERT_EQ(frames_[0], 103);
625 ASSERT_EQ(frames_[1], 174);
626 ASSERT_EQ(keyFrames_[0], 5);
627 ASSERT_EQ(keyFrames_[1], 174);
628 RemoveValue();
629 }
630
631 /**
632 * @tc.name: Demuxer_ReadSample_1050
633 * @tc.desc: Read sample test for timed metadata track
634 * @tc.type: FUNC
635 */
636 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1050, TestSize.Level1)
637 {
638 InitResource(g_mp4Path5, LOCAL);
639 ASSERT_TRUE(initStatus_);
640 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
641 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
642 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
643 ASSERT_NE(sharedMem_, nullptr);
644 ASSERT_TRUE(SetInitValue());
645 while (!isEOS(eosFlag_)) {
646 for (auto idx : selectedTrackIds_) {
647 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
648 CountFrames(idx);
649 }
650 }
651 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
652 printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]);
653 ASSERT_EQ(frames_[0], 601);
654 ASSERT_EQ(frames_[1], 601);
655 ASSERT_EQ(keyFrames_[0], 3);
656 ASSERT_EQ(keyFrames_[1], 601);
657 RemoveValue();
658 }
659
660 /**
661 * @tc.name: Demuxer_ReadSample_1010
662 * @tc.desc: copy current sample to buffer
663 * @tc.type: FUNC
664 */
665 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1010, TestSize.Level1)
666 {
667 InitResource(g_mp4Path, LOCAL);
668 ASSERT_TRUE(initStatus_);
669 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
670 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
671 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
672 ASSERT_NE(sharedMem_, nullptr);
673 uint32_t idx = 4;
674 ASSERT_NE(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
675 }
676
677 /**
678 * @tc.name: Demuxer_ReadSample_1020
679 * @tc.desc: copy current sample to buffer
680 * @tc.type: FUNC
681 */
682 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1020, TestSize.Level1)
683 {
684 InitResource(g_mp4Path, LOCAL);
685 ASSERT_TRUE(initStatus_);
686 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
687 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
688 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
689 ASSERT_NE(sharedMem_, nullptr);
690 uint32_t idx = -1;
691 ASSERT_NE(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
692 }
693
694 /**
695 * @tc.name: Demuxer_ReadSample_1030
696 * @tc.desc: copy current sample to buffer(only video track)
697 * @tc.type: FUNC
698 */
699 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1030, TestSize.Level1)
700 {
701 InitResource(g_mp4Path, LOCAL);
702 ASSERT_TRUE(initStatus_);
703 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
704 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
705 ASSERT_NE(sharedMem_, nullptr);
706 int32_t vkeyFrames = 0;
707 int32_t vframes = 0;
708 flag_ = AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_NONE;
709 while (!(flag_ & AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_EOS)) {
710 ASSERT_EQ(demuxer_->ReadSample(0, sharedMem_, &info_, flag_), AV_ERR_OK);
711 if (flag_ & AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_EOS) {
712 break;
713 }
714 if (flag_ & AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_SYNC_FRAME) {
715 vkeyFrames++;
716 vframes++;
717 } else if ((flag_ & AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_NONE) == 0) {
718 vframes++;
719 }
720 }
721 printf("vframes=%d | vkFrames=%d\n", vframes, vkeyFrames);
722 ASSERT_EQ(vframes, 103);
723 ASSERT_EQ(vkeyFrames, 5);
724 }
725
726 /**
727 * @tc.name: Demuxer_ReadSample_1040
728 * @tc.desc: copy current sample to buffer
729 * @tc.type: FUNC
730 */
731 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1040, TestSize.Level1)
732 {
733 InitResource(g_mp4Path2, LOCAL);
734 ASSERT_TRUE(initStatus_);
735 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
736 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
737 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
738 ASSERT_NE(sharedMem_, nullptr);
739 ASSERT_TRUE(SetInitValue());
740 while (!isEOS(eosFlag_)) {
741 for (auto idx : selectedTrackIds_) {
742 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
743 CountFrames(idx);
744 }
745 }
746 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
747 printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]);
748 ASSERT_EQ(frames_[0], 103);
749 ASSERT_EQ(frames_[1], 174);
750 ASSERT_EQ(keyFrames_[0], 5);
751 ASSERT_EQ(keyFrames_[1], 174);
752 RemoveValue();
753 }
754
755 /**
756 * @tc.name: Demuxer_ReadSample_1070
757 * @tc.desc: copy current sample to buffer
758 * @tc.type: FUNC
759 */
760 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1070, TestSize.Level1)
761 {
762 InitResource(g_mkvPath2, LOCAL);
763 ASSERT_TRUE(initStatus_);
764 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
765 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
766 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
767 ASSERT_NE(sharedMem_, nullptr);
768 ASSERT_TRUE(SetInitValue());
769 while (!isEOS(eosFlag_)) {
770 for (auto idx : selectedTrackIds_) {
771 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
772 CountFrames(idx);
773 }
774 }
775 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
776 printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]);
777 ASSERT_EQ(frames_[0], 240);
778 ASSERT_EQ(frames_[1], 199);
779 ASSERT_EQ(keyFrames_[0], 4);
780 ASSERT_EQ(keyFrames_[1], 199);
781 RemoveValue();
782 }
783
784 /**
785 * @tc.name: Demuxer_ReadSample_1090
786 * @tc.desc: copy current sample to buffer
787 * @tc.type: FUNC
788 */
789 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1090, TestSize.Level1)
790 {
791 InitResource(g_tsPath, LOCAL);
792 ASSERT_TRUE(initStatus_);
793 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
794 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
795 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
796 ASSERT_NE(sharedMem_, nullptr);
797 ASSERT_TRUE(SetInitValue());
798 while (!isEOS(eosFlag_)) {
799 for (auto idx : selectedTrackIds_) {
800 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
801 CountFrames(idx);
802 }
803 }
804 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
805 printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]);
806 ASSERT_EQ(frames_[0], 103);
807 ASSERT_EQ(frames_[1], 174);
808 ASSERT_EQ(keyFrames_[0], 5);
809 ASSERT_EQ(keyFrames_[1], 174);
810 RemoveValue();
811 }
812
813 /**
814 * @tc.name: Demuxer_ReadSample_1100
815 * @tc.desc: copy current sample to buffer
816 * @tc.type: FUNC
817 */
818 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1100, TestSize.Level1)
819 {
820 InitResource(g_aacPath, LOCAL);
821 ASSERT_TRUE(initStatus_);
822 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
823 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
824 ASSERT_NE(sharedMem_, nullptr);
825 ASSERT_TRUE(SetInitValue());
826 uint32_t idx = 0;
827 while (!isEOS(eosFlag_)) {
828 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
829 CountFrames(idx);
830 }
831 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
832 ASSERT_EQ(frames_[0], 1293);
833 ASSERT_EQ(keyFrames_[0], 1293);
834 RemoveValue();
835 }
836
837 /**
838 * @tc.name: Demuxer_ReadSample_1110
839 * @tc.desc: copy current sample to buffer
840 * @tc.type: FUNC
841 */
842 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1110, TestSize.Level1)
843 {
844 InitResource(g_flacPath, LOCAL);
845 ASSERT_TRUE(initStatus_);
846 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
847 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
848 ASSERT_NE(sharedMem_, nullptr);
849 ASSERT_TRUE(SetInitValue());
850 uint32_t idx = 0;
851 while (!isEOS(eosFlag_)) {
852 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
853 CountFrames(idx);
854 }
855 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
856 ASSERT_EQ(frames_[0], 313);
857 ASSERT_EQ(keyFrames_[0], 313);
858 RemoveValue();
859 }
860
861 /**
862 * @tc.name: Demuxer_ReadSample_1120
863 * @tc.desc: copy current sample to buffer
864 * @tc.type: FUNC
865 */
866 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1120, TestSize.Level1)
867 {
868 InitResource(g_m4aPath, LOCAL);
869 ASSERT_TRUE(initStatus_);
870 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
871 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
872 ASSERT_NE(sharedMem_, nullptr);
873 ASSERT_TRUE(SetInitValue());
874 uint32_t idx = 0;
875 while (!isEOS(eosFlag_)) {
876 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
877 CountFrames(idx);
878 }
879 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
880 ASSERT_EQ(frames_[0], 1408);
881 ASSERT_EQ(keyFrames_[0], 1408);
882 RemoveValue();
883 }
884
885 /**
886 * @tc.name: Demuxer_ReadSample_1130
887 * @tc.desc: copy current sample to buffer
888 * @tc.type: FUNC
889 */
890 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1130, TestSize.Level1)
891 {
892 InitResource(g_mp3Path, LOCAL);
893 ASSERT_TRUE(initStatus_);
894 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
895 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
896 ASSERT_NE(sharedMem_, nullptr);
897 ASSERT_TRUE(SetInitValue());
898 uint32_t idx = 0;
899 while (!isEOS(eosFlag_)) {
900 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
901 CountFrames(idx);
902 }
903 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
904 ASSERT_EQ(frames_[0], 1251);
905 ASSERT_EQ(keyFrames_[0], 1251);
906 RemoveValue();
907 }
908
909 /**
910 * @tc.name: Demuxer_ReadSample_1140
911 * @tc.desc: copy current sample to buffer
912 * @tc.type: FUNC
913 */
914 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1140, TestSize.Level1)
915 {
916 InitResource(g_oggPath, LOCAL);
917 ASSERT_TRUE(initStatus_);
918 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
919 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
920 ASSERT_NE(sharedMem_, nullptr);
921 ASSERT_TRUE(SetInitValue());
922 uint32_t idx = 0;
923 while (!isEOS(eosFlag_)) {
924 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
925 CountFrames(idx);
926 }
927 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
928 ASSERT_EQ(frames_[0], 1598);
929 ASSERT_EQ(keyFrames_[0], 1598);
930 RemoveValue();
931 }
932
933 /**
934 * @tc.name: Demuxer_ReadSample_1150
935 * @tc.desc: copy current sample to buffer
936 * @tc.type: FUNC
937 */
938 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1150, TestSize.Level1)
939 {
940 InitResource(g_wavPath, LOCAL);
941 ASSERT_TRUE(initStatus_);
942 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
943 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
944 ASSERT_NE(sharedMem_, nullptr);
945 ASSERT_TRUE(SetInitValue());
946 uint32_t idx = 0;
947 while (!isEOS(eosFlag_)) {
948 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
949 CountFrames(idx);
950 }
951 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
952 ASSERT_EQ(frames_[0], 704);
953 ASSERT_EQ(keyFrames_[0], 704);
954 RemoveValue();
955 }
956
957 /**
958 * @tc.name: Demuxer_ReadSample_1160
959 * @tc.desc: copy current sample to buffer
960 * @tc.type: FUNC
961 */
962 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1160, TestSize.Level1)
963 {
964 InitResource(g_amrPath, LOCAL);
965 ASSERT_TRUE(initStatus_);
966 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
967 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
968 ASSERT_NE(sharedMem_, nullptr);
969 ASSERT_TRUE(SetInitValue());
970 uint32_t idx = 0;
971 while (!isEOS(eosFlag_)) {
972 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
973 CountFrames(idx);
974 }
975 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
976 ASSERT_EQ(frames_[0], 1501);
977 ASSERT_EQ(keyFrames_[0], 1501);
978 RemoveValue();
979 }
980
981 /**
982 * @tc.name: Demuxer_ReadSample_1170
983 * @tc.desc: copy current sample to buffer
984 * @tc.type: FUNC
985 */
986 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1170, TestSize.Level1)
987 {
988 InitResource(g_amrPath2, LOCAL);
989 ASSERT_TRUE(initStatus_);
990 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
991 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
992 ASSERT_NE(sharedMem_, nullptr);
993 ASSERT_TRUE(SetInitValue());
994 uint32_t idx = 0;
995 while (!isEOS(eosFlag_)) {
996 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
997 CountFrames(idx);
998 }
999 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
1000 ASSERT_EQ(frames_[0], 1500);
1001 ASSERT_EQ(keyFrames_[0], 1500);
1002 RemoveValue();
1003 }
1004
1005 /**
1006 * @tc.name: Demuxer_ReadSample_1180
1007 * @tc.desc: copy current sample to buffer(av3a mp4)
1008 * @tc.type: FUNC
1009 */
1010 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1180, TestSize.Level1)
1011 {
1012 InitResource(g_audioVividPath, LOCAL);
1013 ASSERT_TRUE(initStatus_);
1014 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1015 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1016 ASSERT_NE(sharedMem_, nullptr);
1017 ASSERT_TRUE(SetInitValue());
1018 uint32_t idx = 0;
1019 while (!isEOS(eosFlag_)) {
1020 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
1021 CountFrames(idx);
1022 }
1023 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
1024 ASSERT_EQ(frames_[0], 1380);
1025 ASSERT_EQ(keyFrames_[0], 1380);
1026 RemoveValue();
1027 }
1028
1029 /**
1030 * @tc.name: Demuxer_ReadSample_1181
1031 * @tc.desc: copy current sample to buffer(av3a mp4)
1032 * @tc.type: FUNC
1033 */
1034 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1181, TestSize.Level1)
1035 {
1036 InitResource(g_audioVividPath1, LOCAL);
1037 ASSERT_TRUE(initStatus_);
1038 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1039 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1040 ASSERT_NE(sharedMem_, nullptr);
1041 ASSERT_TRUE(SetInitValue());
1042 uint32_t idx = 0;
1043 while (!isEOS(eosFlag_)) {
1044 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
1045 CountFrames(idx);
1046 }
1047 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
1048 ASSERT_EQ(frames_[0], 1380);
1049 ASSERT_EQ(keyFrames_[0], 1380);
1050 RemoveValue();
1051 }
1052
1053 /**
1054 * @tc.name: Demuxer_SeekToTime_1000
1055 * @tc.desc: seek to the specified time
1056 * @tc.type: FUNC
1057 */
1058 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1000, TestSize.Level1)
1059 {
1060 InitResource(g_mp4Path, LOCAL);
1061 ASSERT_TRUE(initStatus_);
1062 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1063 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
1064 list<int64_t> toPtsList = {0, 2000, 1920, 2160, 2200, 2440, 2600, 2700, 4080, 4100}; // ms
1065 vector<int32_t> audioVals = {174, 174, 174, 90, 91, 91, 90, 134, 90, 47, 91, 91, 47, 91, 91, 47, 91, 47, 47, 91, 47,
1066 47, 91, 47, 5, 5, 5, 5};
1067 vector<int32_t> videoVals = {103, 103, 103, 53, 53, 53, 53, 78, 53, 28, 53, 53, 28, 53, 53, 28, 53, 28, 28, 53, 28,
1068 28, 53, 28, 3, 3, 3, 3};
1069 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1070 ASSERT_NE(sharedMem_, nullptr);
1071 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1072 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1073 ret_ = demuxer_->SeekToTime(*toPts, *mode);
1074 if (ret_ != AV_ERR_OK) {
1075 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1076 continue;
1077 }
1078 ReadData();
1079 printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
1080 printf("time = %" PRId64 " | frames_[1]=%d | kFrames[1]=%d\n", *toPts, frames_[1], keyFrames_[1]);
1081 ASSERT_EQ(frames_[0], videoVals[numbers_]);
1082 ASSERT_EQ(frames_[1], audioVals[numbers_]);
1083 numbers_ += 1;
1084 RemoveValue();
1085 selectedTrackIds_.clear();
1086 }
1087 }
1088 }
1089
1090 /**
1091 * @tc.name: Demuxer_SeekToTime_1001
1092 * @tc.desc: seek to the specified time
1093 * @tc.type: FUNC
1094 */
1095 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1001, TestSize.Level1)
1096 {
1097 InitResource(g_mp4Path, LOCAL);
1098 ASSERT_TRUE(initStatus_);
1099 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1100 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
1101 list<int64_t> toPtsList = {-100, 1000000}; // ms
1102 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1103 ASSERT_NE(sharedMem_, nullptr);
1104 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1105 ret_ = demuxer_->SeekToTime(*toPts, SeekMode::SEEK_NEXT_SYNC);
1106 ASSERT_NE(ret_, AV_ERR_OK);
1107 ret_ = demuxer_->SeekToTime(*toPts, SeekMode::SEEK_PREVIOUS_SYNC);
1108 ASSERT_NE(ret_, AV_ERR_OK);
1109 ret_ = demuxer_->SeekToTime(*toPts, SeekMode::SEEK_CLOSEST_SYNC);
1110 ASSERT_NE(ret_, AV_ERR_OK);
1111 }
1112 }
1113
1114 /**
1115 * @tc.name: Demuxer_SeekToTime_1002
1116 * @tc.desc: seek to the specified time
1117 * @tc.type: FUNC
1118 */
1119 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1002, TestSize.Level1)
1120 {
1121 InitResource(g_mp4Path, LOCAL);
1122 ASSERT_TRUE(initStatus_);
1123 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1124 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
1125 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1126 ASSERT_NE(sharedMem_, nullptr);
1127 int readNum = 121;
1128 int64_t seekTime = 0;
1129 ReadData(readNum, seekTime);
1130 seekTime = (seekTime / 1000) + 500;
1131 ASSERT_EQ(demuxer_->SeekToTime(seekTime, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1132 ASSERT_EQ(demuxer_->ReadSample(0, sharedMem_, &info_, flag_), AV_ERR_OK);
1133 printf("time = %" PRId64 " | pts = %" PRId64 "\n", seekTime, info_.presentationTimeUs);
1134 }
1135
1136 /**
1137 * @tc.name: Demuxer_SeekToTime_1010
1138 * @tc.desc: seek to the specified time
1139 * @tc.type: FUNC
1140 */
1141 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1010, TestSize.Level1)
1142 {
1143 InitResource(g_mp4Path2, LOCAL);
1144 ASSERT_TRUE(initStatus_);
1145 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1146 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
1147 list<int64_t> toPtsList = {0, 3000, 2040, 1880, 1960, 2400, 2720, 2830, 4040, 4100}; // ms
1148 vector<int32_t> audioVals = {174, 174, 174, 7, 49, 49, 48, 91, 91, 90, 132, 90, 90, 91, 91, 48, 91, 91, 48, 91, 48,
1149 48, 91, 48, 8, 8, 8, 8};
1150 vector<int32_t> videoVals = {103, 103, 103, 6, 30, 30, 30, 54, 54, 54, 78, 54, 54, 54, 54, 30, 54, 54, 30, 54, 30,
1151 30, 54, 30, 6, 6, 6, 6};
1152 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1153 ASSERT_NE(sharedMem_, nullptr);
1154 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1155 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1156 ret_ = demuxer_->SeekToTime(*toPts, *mode);
1157 if (ret_ != AV_ERR_OK) {
1158 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1159 continue;
1160 }
1161 ReadData();
1162 printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
1163 printf("time = %" PRId64 " | frames_[1]=%d | kFrames[1]=%d\n", *toPts, frames_[1], keyFrames_[1]);
1164 ASSERT_EQ(frames_[0], videoVals[numbers_]);
1165 ASSERT_EQ(frames_[1], audioVals[numbers_]);
1166 numbers_ += 1;
1167 RemoveValue();
1168 selectedTrackIds_.clear();
1169 }
1170 }
1171 }
1172
1173 /**
1174 * @tc.name: Demuxer_SeekToTime_1040
1175 * @tc.desc: seek to the specified time
1176 * @tc.type: FUNC
1177 */
1178 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1040, TestSize.Level1)
1179 {
1180 InitResource(g_mkvPath2, LOCAL);
1181 ASSERT_TRUE(initStatus_);
1182 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1183 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
1184 list<int64_t> toPtsList = {0, 1000, 1017, 1500, 1700, 1940, 3983, 1983, 3990}; // ms
1185 vector<int32_t> audioVals = {199, 199, 199, 149, 149, 149, 99, 149, 149, 99, 149, 149, 99, 149, 99, 99, 149, 99,
1186 49, 49, 99, 149, 99, 49, 49};
1187 vector<int32_t> videoVals = {240, 240, 240, 180, 180, 180, 120, 180, 180, 120, 180, 180, 120, 180, 120, 120, 180,
1188 120, 60, 60, 120, 180, 120, 60, 60};
1189 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1190 ASSERT_NE(sharedMem_, nullptr);
1191 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1192 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1193 ret_ = demuxer_->SeekToTime(*toPts, *mode);
1194 if (ret_ != AV_ERR_OK) {
1195 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1196 continue;
1197 }
1198 ReadData();
1199 printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
1200 printf("time = %" PRId64 " | frames_[1]=%d | kFrames[1]=%d\n", *toPts, frames_[1], keyFrames_[1]);
1201 ASSERT_EQ(frames_[0], videoVals[numbers_]);
1202 ASSERT_EQ(frames_[1], audioVals[numbers_]);
1203 numbers_ += 1;
1204 RemoveValue();
1205 selectedTrackIds_.clear();
1206 }
1207 }
1208 }
1209
1210 /**
1211 * @tc.name: Demuxer_SeekToTime_1060
1212 * @tc.desc: seek to the specified time
1213 * @tc.type: FUNC
1214 */
1215 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1060, TestSize.Level1)
1216 {
1217 InitResource(g_tsPath, LOCAL);
1218 ASSERT_TRUE(initStatus_);
1219 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1220 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
1221 list<int64_t> toPtsList = {0, 3480, 3640, 3320, 3000, 3100, 4120, 5520}; // ms
1222 vector<int32_t> videoVals = {103, 103, 103, 15, 15, 15, 11, 11, 11, 19, 19, 19, 27, 27, 27, 24, 25, 25, 1, 1, 1};
1223 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1224 ASSERT_NE(sharedMem_, nullptr);
1225 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1226 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1227 ret_ = demuxer_->SeekToTime(*toPts, *mode);
1228 if (ret_ != AV_ERR_OK) {
1229 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1230 continue;
1231 }
1232 ReadData();
1233 printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
1234 ASSERT_EQ(frames_[0], videoVals[numbers_]);
1235 numbers_ += 1;
1236 RemoveValue();
1237 selectedTrackIds_.clear();
1238 }
1239 }
1240 }
1241
1242 /**
1243 * @tc.name: Demuxer_SeekToTime_1070
1244 * @tc.desc: seek to the specified time
1245 * @tc.type: FUNC
1246 */
1247 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1070, TestSize.Level1)
1248 {
1249 InitResource(g_aacPath, LOCAL);
1250 ASSERT_TRUE(initStatus_);
1251 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1252 list<int64_t> toPtsList = {0, 10240, 10230, 10220, 30000, 30010}; // ms
1253 vector<int32_t> audioVals = {1293, 1293, 1293, 852, 852, 852, 852, 853, 853, 852, 853, 853, 2, 2, 2, 1, 1, 1};
1254 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1255 ASSERT_NE(sharedMem_, nullptr);
1256 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1257 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1258 ret_ = demuxer_->SeekToTime(*toPts, *mode);
1259 if (ret_ != AV_ERR_OK) {
1260 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1261 continue;
1262 }
1263 ReadData();
1264 printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
1265 ASSERT_EQ(frames_[0], audioVals[numbers_]);
1266 numbers_ += 1;
1267 RemoveValue();
1268 selectedTrackIds_.clear();
1269 }
1270 }
1271 }
1272
1273 /**
1274 * @tc.name: Demuxer_SeekToTime_1080
1275 * @tc.desc: seek to the specified time
1276 * @tc.type: FUNC
1277 */
1278 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1080, TestSize.Level1)
1279 {
1280 InitResource(g_flacPath, LOCAL);
1281 ASSERT_TRUE(initStatus_);
1282 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1283 list<int64_t> toPtsList = {0, 3072, 4031, 4035, 29952, 29953}; // ms
1284 vector<int32_t> audioVals = {313, 313, 313, 281, 281, 281, 271, 271, 271, 270, 270, 270, 1, 1, 1, 2, 2, 2};
1285 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1286 ASSERT_NE(sharedMem_, nullptr);
1287 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1288 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1289 ret_ = demuxer_->SeekToTime(*toPts, *mode);
1290 if (ret_ != AV_ERR_OK) {
1291 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1292 continue;
1293 }
1294 ReadData();
1295 printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
1296 ASSERT_EQ(frames_[0], audioVals[numbers_]);
1297 numbers_ += 1;
1298 RemoveValue();
1299 selectedTrackIds_.clear();
1300 }
1301 }
1302 }
1303
1304 /**
1305 * @tc.name: Demuxer_SeekToTime_1090
1306 * @tc.desc: seek to the specified time
1307 * @tc.type: FUNC
1308 */
1309 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1090, TestSize.Level1)
1310 {
1311 InitResource(g_m4aPath, LOCAL);
1312 ASSERT_TRUE(initStatus_);
1313 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1314 list<int64_t> toPtsList = {0, 14592, 15297, 15290, 29994, 29998}; // ms
1315 vector<int32_t> audioVals = {1407, 1407, 1407, 723, 723, 723, 689, 690, 690, 690, 691, 691, 2, 2, 2, 1, 1, 1};
1316 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1317 ASSERT_NE(sharedMem_, nullptr);
1318 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1319 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1320 ret_ = demuxer_->SeekToTime(*toPts, *mode);
1321 if (ret_ != AV_ERR_OK) {
1322 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1323 continue;
1324 }
1325 ReadData();
1326 printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
1327 ASSERT_EQ(frames_[0], audioVals[numbers_]);
1328 numbers_ += 1;
1329 RemoveValue();
1330 selectedTrackIds_.clear();
1331 }
1332 }
1333 }
1334
1335 /**
1336 * @tc.name: Demuxer_SeekToTime_1100
1337 * @tc.desc: seek to the specified time
1338 * @tc.type: FUNC
1339 */
1340 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1100, TestSize.Level1)
1341 {
1342 InitResource(g_mp3Path, LOCAL);
1343 ASSERT_TRUE(initStatus_);
1344 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1345 list<int64_t> toPtsList = {0, 4128, 11980, 11990, 30000, 30010}; // ms
1346 vector<int32_t> audioVals = {1251, 1251, 1251, 1077, 1078, 1078, 750, 751, 751, 750, 751, 751, 1, 1, 1, 1, 1, 1};
1347 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1348 ASSERT_NE(sharedMem_, nullptr);
1349 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1350 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1351 ret_ = demuxer_->SeekToTime(*toPts, *mode);
1352 if (ret_ != AV_ERR_OK) {
1353 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1354 continue;
1355 }
1356 ReadData();
1357 printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
1358 ASSERT_EQ(frames_[0], audioVals[numbers_]);
1359 numbers_ += 1;
1360 RemoveValue();
1361 selectedTrackIds_.clear();
1362 }
1363 }
1364 }
1365
1366 /**
1367 * @tc.name: Demuxer_SeekToTime_1110
1368 * @tc.desc: seek to the specified time
1369 * @tc.type: FUNC
1370 */
1371 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1110, TestSize.Level1)
1372 {
1373 InitResource(g_oggPath, LOCAL);
1374 ASSERT_TRUE(initStatus_);
1375 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1376 list<int64_t> toPtsList = {0, 5868, 5548, 5292, 29992, 29999}; // ms
1377 vector<int32_t> audioVals = {1598, 1598, 1598, 1357, 1357, 1357, 1357, 1357, 1357, 1357, 1357, 1357, 46, 46,
1378 46, 46, 46, 46};
1379 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1380 ASSERT_NE(sharedMem_, nullptr);
1381 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1382 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1383 ret_ = demuxer_->SeekToTime(*toPts, *mode);
1384 if (ret_ != AV_ERR_OK) {
1385 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1386 continue;
1387 }
1388 ReadData();
1389 printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
1390 ASSERT_EQ(frames_[0], audioVals[numbers_]);
1391 numbers_ += 1;
1392 RemoveValue();
1393 selectedTrackIds_.clear();
1394 }
1395 }
1396 }
1397
1398 /**
1399 * @tc.name: Demuxer_SeekToTime_1120
1400 * @tc.desc: seek to the specified time
1401 * @tc.type: FUNC
1402 */
1403 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1120, TestSize.Level1)
1404 {
1405 InitResource(g_wavPath, LOCAL);
1406 ASSERT_TRUE(initStatus_);
1407 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1408 list<int64_t> toPtsList = {0, 8576, 8566, 8578, 29994, 30000}; // ms
1409 vector<int32_t> audioVals = {704, 704, 704, 503, 503, 503, 504, 504, 504, 503, 503, 503, 2, 2, 2, 1, 1, 1};
1410 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1411 ASSERT_NE(sharedMem_, nullptr);
1412 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1413 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1414 ret_ = demuxer_->SeekToTime(*toPts, *mode);
1415 if (ret_ != AV_ERR_OK) {
1416 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1417 continue;
1418 }
1419 ReadData();
1420 printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
1421 ASSERT_EQ(frames_[0], audioVals[numbers_]);
1422 numbers_ += 1;
1423 RemoveValue();
1424 selectedTrackIds_.clear();
1425 }
1426 }
1427 }
1428
1429 /**
1430 * @tc.name: Demuxer_SeekToTime_1130
1431 * @tc.desc: seek to the specified time
1432 * @tc.type: FUNC
1433 */
1434 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1130, TestSize.Level1)
1435 {
1436 InitResource(g_amrPath, LOCAL);
1437 ASSERT_TRUE(initStatus_);
1438 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1439 list<int64_t> toPtsList = {0, 8560, 8550, 8570, 30000, 30900}; // ms
1440 vector<int32_t> audioVals = {1501, 1501, 1501, 1073, 1073, 1073, 1073, 1074, 1074, 1072, 1073, 1073,
1441 1, 1, 1, 1, 1, 1};
1442 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1443 ASSERT_NE(sharedMem_, nullptr);
1444 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1445 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1446 ret_ = demuxer_->SeekToTime(*toPts, *mode);
1447 if (ret_ != AV_ERR_OK) {
1448 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1449 continue;
1450 }
1451 ReadData();
1452 printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
1453 ASSERT_EQ(frames_[0], audioVals[numbers_]);
1454 numbers_ += 1;
1455 RemoveValue();
1456 selectedTrackIds_.clear();
1457 }
1458 }
1459 }
1460
1461 /**
1462 * @tc.name: Demuxer_SeekToTime_1140
1463 * @tc.desc: seek to the specified time
1464 * @tc.type: FUNC
1465 */
1466 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1140, TestSize.Level1)
1467 {
1468 InitResource(g_amrPath2, LOCAL);
1469 ASSERT_TRUE(initStatus_);
1470 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1471 list<int64_t> toPtsList = {0, 11920, 11910, 11930, 29980, 30800}; // ms
1472 vector<int32_t> audioVals = {1500, 1500, 1500, 904, 904, 904, 904, 905, 905, 903, 904, 904,
1473 1, 1, 1, 1, 1, 1};
1474 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1475 ASSERT_NE(sharedMem_, nullptr);
1476 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1477 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1478 ret_ = demuxer_->SeekToTime(*toPts, *mode);
1479 if (ret_ != AV_ERR_OK) {
1480 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1481 continue;
1482 }
1483 ReadData();
1484 printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
1485 ASSERT_EQ(frames_[0], audioVals[numbers_]);
1486 numbers_ += 1;
1487 RemoveValue();
1488 selectedTrackIds_.clear();
1489 }
1490 }
1491 }
1492
1493 /**
1494 * @tc.name: Demuxer_SeekToTime_1150
1495 * @tc.desc: seek to the specified time(audioVivid mp4)
1496 * @tc.type: FUNC
1497 */
1498 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1150, TestSize.Level1)
1499 {
1500 InitResource(g_audioVividPath, LOCAL);
1501 ASSERT_TRUE(initStatus_);
1502 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1503 list<int64_t> toPtsList = {0, 10000, 8000, 12300, 25000, 29000, 30800, 33000}; // ms
1504 vector<int32_t> audioVals = {1380, 1380, 1380, 949, 950, 950, 1035, 1036, 1036, 850, 851, 851, 303, 304, 304,
1505 131, 132, 132, 53, 54, 54};
1506 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1507 ASSERT_NE(sharedMem_, nullptr);
1508 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1509 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1510 ret_ = demuxer_->SeekToTime(*toPts, *mode);
1511 if (ret_ != AV_ERR_OK) {
1512 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1513 continue;
1514 }
1515 ReadData();
1516 printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
1517 ASSERT_EQ(frames_[0], audioVals[numbers_]);
1518 numbers_ += 1;
1519 RemoveValue();
1520 selectedTrackIds_.clear();
1521 }
1522 }
1523 ASSERT_NE(demuxer_->SelectTrackByID(3), AV_ERR_OK);
1524 ASSERT_NE(demuxer_->SelectTrackByID(-1), AV_ERR_OK);
1525 ASSERT_EQ(demuxer_->UnselectTrackByID(3), AV_ERR_OK);
1526 ASSERT_EQ(demuxer_->UnselectTrackByID(-1), AV_ERR_OK);
1527 ASSERT_EQ(demuxer_->UnselectTrackByID(0), AV_ERR_OK);
1528 }
1529
1530 /**
1531 * @tc.name: Demuxer_SeekToTime_1160
1532 * @tc.desc: seek to the specified time(audioVivid ts)
1533 * @tc.type: FUNC
1534 */
1535 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1160, TestSize.Level1)
1536 {
1537 InitResource(g_audioVividPath2, LOCAL);
1538 ASSERT_TRUE(initStatus_);
1539 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1540 list<int64_t> toPtsList = {0, 10000, 8000, 12300, 25000, 29000, 30800, 32000}; // ms
1541 vector<int32_t> audioVals = {92, 92, 92, 63, 64, 64, 69, 70, 70, 56, 57, 57, 20, 21, 21, 8, 9, 9, 4, 4, 4};
1542 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1543 ASSERT_NE(sharedMem_, nullptr);
1544 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1545 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1546 ret_ = demuxer_->SeekToTime(*toPts, *mode);
1547 if (ret_ != AV_ERR_OK) {
1548 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1549 continue;
1550 }
1551 ReadData();
1552 printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
1553 ASSERT_EQ(frames_[0], audioVals[numbers_]);
1554 numbers_ += 1;
1555 RemoveValue();
1556 selectedTrackIds_.clear();
1557 }
1558 }
1559 ASSERT_NE(demuxer_->SelectTrackByID(3), AV_ERR_OK);
1560 ASSERT_NE(demuxer_->SelectTrackByID(-1), AV_ERR_OK);
1561 ASSERT_EQ(demuxer_->UnselectTrackByID(3), AV_ERR_OK);
1562 ASSERT_EQ(demuxer_->UnselectTrackByID(-1), AV_ERR_OK);
1563 ASSERT_EQ(demuxer_->UnselectTrackByID(0), AV_ERR_OK);
1564 }
1565
1566 /**
1567 * @tc.name: Demuxer_SeekToTime_1200
1568 * @tc.desc: read first and then seek
1569 * @tc.type: FUNC
1570 */
1571 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1200, TestSize.Level1)
1572 {
1573 InitResource(g_mp4Path2, LOCAL);
1574 ASSERT_TRUE(initStatus_);
1575 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1576 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
1577 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1578 ASSERT_NE(sharedMem_, nullptr);
1579 ASSERT_TRUE(SetInitValue());
1580 for (int i = 0; i < 50; i++) {
1581 for (auto idx : selectedTrackIds_) {
1582 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
1583 }
1584 }
1585 int64_t seekTime = info_.presentationTimeUs / 1000 + 2000;
1586 ASSERT_EQ(demuxer_->SeekToTime(seekTime, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1587 ASSERT_EQ(demuxer_->ReadSample(0, sharedMem_, &info_, flag_), AV_ERR_OK);
1588 ASSERT_EQ(info_.presentationTimeUs, 3960000);
1589 RemoveValue();
1590 }
1591
1592 /**
1593 * @tc.name: Demuxer_ReadSample_1219
1594 * @tc.desc: copy current sample to buffer(two sound track mp4)
1595 * @tc.type: FUNC
1596 */
1597 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1219, TestSize.Level1)
1598 {
1599 InitResource(g_multiSoundTrackMp4Path, LOCAL);
1600 ASSERT_TRUE(initStatus_);
1601 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1602 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
1603 ASSERT_EQ(demuxer_->SelectTrackByID(2), AV_ERR_OK);
1604 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1605 ASSERT_NE(sharedMem_, nullptr);
1606 ASSERT_TRUE(SetInitValue());
1607 while (!isEOS(eosFlag_)) {
1608 for (auto idx : selectedTrackIds_) {
1609 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
1610 CountFrames(idx);
1611 }
1612 }
1613 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
1614 printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]);
1615 printf("frames_[2]=%d | kFrames[2]=%d\n", frames_[2], keyFrames_[2]);
1616 ASSERT_EQ(frames_[0], 602);
1617 ASSERT_EQ(frames_[1], 433);
1618 ASSERT_EQ(frames_[2], 417);
1619 ASSERT_EQ(keyFrames_[0], 3);
1620 ASSERT_EQ(keyFrames_[1], 433);
1621 ASSERT_EQ(keyFrames_[2], 417);
1622 RemoveValue();
1623 }
1624
1625 /**
1626 * @tc.name: Demuxer_ReadSample_1228
1627 * @tc.desc: copy current sample to buffer, local
1628 * @tc.type: FUNC
1629 */
1630 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1228, TestSize.Level1)
1631 {
1632 InitResource(g_fmp4AvcPath, LOCAL);
1633 ASSERT_TRUE(initStatus_);
1634 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1635 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
1636 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1637 ASSERT_NE(sharedMem_, nullptr);
1638 ASSERT_TRUE(SetInitValue());
1639 while (!isEOS(eosFlag_)) {
1640 for (auto idx : selectedTrackIds_) {
1641 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
1642 CountFrames(idx);
1643 }
1644 }
1645 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
1646 printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]);
1647 ASSERT_EQ(frames_[0], 602);
1648 ASSERT_EQ(frames_[1], 433);
1649 ASSERT_EQ(keyFrames_[0], 3);
1650 ASSERT_EQ(keyFrames_[1], 433);
1651 RemoveValue();
1652 }
1653
1654 /**
1655 * @tc.name: Demuxer_ReadSample_1234
1656 * @tc.desc: copy current sample to buffer, local
1657 * @tc.type: FUNC
1658 */
1659 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1234, TestSize.Level1)
1660 {
1661 InitResource(g_fmp4m4vPath, LOCAL);
1662 ASSERT_TRUE(initStatus_);
1663 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1664 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1665 ASSERT_NE(sharedMem_, nullptr);
1666 ASSERT_TRUE(SetInitValue());
1667 while (!isEOS(eosFlag_)) {
1668 for (auto idx : selectedTrackIds_) {
1669 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
1670 CountFrames(idx);
1671 }
1672 }
1673 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
1674 ASSERT_EQ(frames_[0], 602);
1675 ASSERT_EQ(keyFrames_[0], 3);
1676 RemoveValue();
1677 }
1678
1679 /**
1680 * @tc.name: Demuxer_ReadSample_1236
1681 * @tc.desc: copy current sample to buffer, local
1682 * @tc.type: FUNC
1683 */
1684 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1236, TestSize.Level1)
1685 {
1686 InitResource(g_fmp4m4aPath, LOCAL);
1687 ASSERT_TRUE(initStatus_);
1688 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1689 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1690 ASSERT_NE(sharedMem_, nullptr);
1691 ASSERT_TRUE(SetInitValue());
1692 while (!isEOS(eosFlag_)) {
1693 for (auto idx : selectedTrackIds_) {
1694 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
1695 CountFrames(idx);
1696 }
1697 }
1698 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
1699 ASSERT_EQ(frames_[0], 433);
1700 ASSERT_EQ(keyFrames_[0], 433);
1701 RemoveValue();
1702 }
1703
1704 /**
1705 * @tc.name: Demuxer_SeekToTime_1194
1706 * @tc.desc: seek to the specified time(two sound track mp4 local)
1707 * @tc.type: FUNC
1708 */
1709 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1194, TestSize.Level1)
1710 {
1711 InitResource(g_multiSoundTrackMp4Path, LOCAL);
1712 ASSERT_TRUE(initStatus_);
1713 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1714 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
1715 ASSERT_EQ(demuxer_->SelectTrackByID(2), AV_ERR_OK);
1716 list<int64_t> toPtsList = {0, 4500, 7000, 2000, 10000}; // ms
1717 vector<int32_t> videoVals = {602, 602, 602, 102, 352, 352, 102, 352, 102, 352, 602, 602, 102, 102};
1718 vector<int32_t> audioVals = {433, 433, 433, 74, 254, 254, 74, 254, 74, 253, 433, 433, 75, 75};
1719 vector<int32_t> audioVals2 = {417, 417, 417, 71, 245, 245, 71, 245, 71, 244, 417, 417, 72, 72};
1720 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1721 ASSERT_NE(sharedMem_, nullptr);
1722 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1723 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1724 ret_ = demuxer_->SeekToTime(*toPts, *mode);
1725 if (ret_ != AV_ERR_OK) {
1726 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1727 continue;
1728 }
1729 ReadData();
1730 printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
1731 printf("time = %" PRId64 " | frames_[1]=%d | kFrames[1]=%d\n", *toPts, frames_[1], keyFrames_[1]);
1732 printf("time = %" PRId64 " | frames_[2]=%d | kFrames[2]=%d\n", *toPts, frames_[2], keyFrames_[2]);
1733 ASSERT_EQ(frames_[0], videoVals[numbers_]);
1734 ASSERT_EQ(frames_[1], audioVals[numbers_]);
1735 ASSERT_EQ(frames_[2], audioVals2[numbers_]);
1736 numbers_ += 1;
1737 RemoveValue();
1738 selectedTrackIds_.clear();
1739 }
1740 }
1741 ASSERT_NE(demuxer_->SeekToTime(11000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1742 ASSERT_NE(demuxer_->SeekToTime(-1000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1743 }
1744
1745 /**
1746 * @tc.name: Demuxer_ReadSample_1222
1747 * @tc.desc: copy current sample to buffer(ape)
1748 * @tc.type: FUNC
1749 */
1750 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1222, TestSize.Level1)
1751 {
1752 InitResource(g_apePath, LOCAL);
1753 ASSERT_TRUE(initStatus_);
1754 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1755 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1756 ASSERT_NE(sharedMem_, nullptr);
1757 ASSERT_TRUE(SetInitValue());
1758 uint32_t idx = 0;
1759 while (!isEOS(eosFlag_)) {
1760 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
1761 CountFrames(idx);
1762 }
1763 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
1764 ASSERT_EQ(frames_[0], 7);
1765 ASSERT_EQ(keyFrames_[0], 7);
1766 RemoveValue();
1767 }
1768
1769 /**
1770 * @tc.name: Demuxer_SeekToTime_1224
1771 * @tc.desc: seek to the specified time(two sound track ape local)
1772 * @tc.type: FUNC
1773 */
1774 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1224, TestSize.Level1)
1775 {
1776 InitResource(g_apePath, LOCAL);
1777 ASSERT_TRUE(initStatus_);
1778 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1779 list<int64_t> toPtsList = {0, 4500, 7000, 2000, 10000}; // ms
1780 vector<int32_t> audioVals = {7, 7, 7, 4, 5, 5, 2, 3, 3, 5, 6, 6, 1, 2, 2};
1781
1782 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1783 ASSERT_NE(sharedMem_, nullptr);
1784 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1785 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1786 ret_ = demuxer_->SeekToTime(*toPts, *mode);
1787 if (ret_ != AV_ERR_OK) {
1788 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1789 continue;
1790 }
1791 ReadData();
1792 printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
1793 ASSERT_EQ(frames_[0], audioVals[numbers_]);
1794 numbers_ += 1;
1795 RemoveValue();
1796 selectedTrackIds_.clear();
1797 }
1798 }
1799 ASSERT_NE(demuxer_->SeekToTime(12000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1800 ASSERT_NE(demuxer_->SeekToTime(-1000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1801 }
1802
1803 /**
1804 * @tc.name: Demuxer_ReadSample_1400
1805 * @tc.desc: copy current sample to buffer(flv)
1806 * @tc.type: FUNC
1807 */
1808 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1400, TestSize.Level1)
1809 {
1810 InitResource(g_flvPath, LOCAL);
1811 ASSERT_TRUE(initStatus_);
1812 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1813 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
1814 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1815 ASSERT_NE(sharedMem_, nullptr);
1816 ASSERT_TRUE(SetInitValue());
1817 std::vector<uint32_t> keyFrameIndex = {0};
1818 while (!isEOS(eosFlag_)) {
1819 for (auto idx : selectedTrackIds_) {
1820 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
1821 if (idx == 0) {
1822 ASSERT_TRUE(CheckKeyFrameIndex(
1823 keyFrameIndex, frames_[0], flag_ & AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_SYNC_FRAME));
1824 }
1825 CountFrames(idx);
1826 }
1827 }
1828 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
1829 printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]);
1830 ASSERT_EQ(frames_[0], 76);
1831 ASSERT_EQ(frames_[1], 113);
1832 ASSERT_EQ(keyFrames_[0], 1);
1833 ASSERT_EQ(keyFrames_[1], 113);
1834 RemoveValue();
1835 }
1836
1837 /**
1838 * @tc.name: Demuxer_SeekToTime_1206
1839 * @tc.desc: seek to the specified time(h264 flv local)
1840 * @tc.type: FUNC
1841 */
1842 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1206, TestSize.Level1)
1843 {
1844 InitResource(g_flvPath, LOCAL);
1845 ASSERT_TRUE(initStatus_);
1846 ASSERT_TRUE(SetInitValue());
1847 for (auto idx : selectedTrackIds_) {
1848 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
1849 }
1850 list<int64_t> toPtsList = {0, 1500, 1000, 1740, 1970, 2100}; // ms
1851 vector<int32_t> videoVals = {76, 76, 76, 0, 76, 0, 0, 76, 76, 0, 76, 0, 0, 76, 0, 0, 76, 0};
1852 vector<int32_t> audioVals = {107, 107, 107, 0, 107, 0, 0, 107, 107, 0, 107, 0, 0, 107, 0, 0, 107, 0};
1853 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1854 ASSERT_NE(sharedMem_, nullptr);
1855 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1856 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1857 ret_ = demuxer_->SeekToTime(*toPts, *mode);
1858 if (ret_ != AV_ERR_OK) {
1859 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1860 continue;
1861 }
1862 ReadData();
1863 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
1864 printf("time = %" PRId64 " | frames_[1]=%d\n", *toPts, frames_[1]);
1865 ASSERT_EQ(frames_[0], videoVals[numbers_]);
1866 ASSERT_EQ(frames_[1], audioVals[numbers_]);
1867 numbers_ += 1;
1868 RemoveValue();
1869 selectedTrackIds_.clear();
1870 }
1871 }
1872 ASSERT_NE(demuxer_->SeekToTime(11000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1873 ASSERT_NE(demuxer_->SeekToTime(-1000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1874 }
1875
1876 /**
1877 * @tc.name: Demuxer_SeekToTime_1229
1878 * @tc.desc: seek to the specified time(h264 fmp4 fd)
1879 * @tc.type: FUNC
1880 */
1881 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1229, TestSize.Level1)
1882 {
1883 InitResource(g_fmp4AvcPath, LOCAL);
1884 ASSERT_TRUE(initStatus_);
1885 ASSERT_TRUE(SetInitValue());
1886 for (auto idx : selectedTrackIds_) {
1887 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
1888 }
1889 list<int64_t> toPtsList = {0, 4500, 7000, 2000}; // ms
1890 vector<int32_t> videoVals = {602, 602, 602, 102, 352, 352, 102, 352, 102, 352, 602, 602};
1891 vector<int32_t> audioVals = {433, 433, 433, 74, 254, 254, 74, 254, 74, 253, 433, 433};
1892 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1893 ASSERT_NE(sharedMem_, nullptr);
1894 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1895 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1896 ret_ = demuxer_->SeekToTime(*toPts, *mode);
1897 if (ret_ != AV_ERR_OK) {
1898 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1899 continue;
1900 }
1901 ReadData();
1902 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
1903 printf("time = %" PRId64 " | frames_[1]=%d\n", *toPts, frames_[1]);
1904 ASSERT_EQ(frames_[0], videoVals[numbers_]);
1905 ASSERT_EQ(frames_[1], audioVals[numbers_]);
1906 numbers_ += 1;
1907 RemoveValue();
1908 selectedTrackIds_.clear();
1909 }
1910 }
1911 ASSERT_NE(demuxer_->SeekToTime(11000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1912 ASSERT_NE(demuxer_->SeekToTime(-1000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1913 }
1914
1915 /**
1916 * @tc.name: Demuxer_SeekToTime_1238
1917 * @tc.desc: seek to the specified time(fmp4 m4v fd)
1918 * @tc.type: FUNC
1919 */
1920 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1238, TestSize.Level1)
1921 {
1922 InitResource(g_fmp4m4vPath, LOCAL);
1923 ASSERT_TRUE(initStatus_);
1924 ASSERT_TRUE(SetInitValue());
1925 for (auto idx : selectedTrackIds_) {
1926 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
1927 }
1928 list<int64_t> toPtsList = {0, 4500, 7000, 2000}; // ms
1929 vector<int32_t> videoVals = {602, 602, 602, 102, 352, 352, 102, 352, 102, 352, 602, 602};
1930 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1931 ASSERT_NE(sharedMem_, nullptr);
1932 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1933 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1934 ret_ = demuxer_->SeekToTime(*toPts, *mode);
1935 if (ret_ != AV_ERR_OK) {
1936 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1937 continue;
1938 }
1939 ReadData();
1940 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
1941 ASSERT_EQ(frames_[0], videoVals[numbers_]);
1942 numbers_ += 1;
1943 RemoveValue();
1944 selectedTrackIds_.clear();
1945 }
1946 }
1947 ASSERT_NE(demuxer_->SeekToTime(11000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1948 ASSERT_NE(demuxer_->SeekToTime(-1000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1949 }
1950
1951 /**
1952 * @tc.name: Demuxer_SeekToTime_1239
1953 * @tc.desc: seek to the specified time(fmp4 m4a fd)
1954 * @tc.type: FUNC
1955 */
1956 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1239, TestSize.Level1)
1957 {
1958 InitResource(g_fmp4m4aPath, LOCAL);
1959 ASSERT_TRUE(initStatus_);
1960 ASSERT_TRUE(SetInitValue());
1961 for (auto idx : selectedTrackIds_) {
1962 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
1963 }
1964 list<int64_t> toPtsList = {0, 4500, 7000, 2000}; // ms
1965 vector<int32_t> audioVals = {433, 433, 433, 239, 240, 240, 131, 132, 132, 347, 348, 348};
1966 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1967 ASSERT_NE(sharedMem_, nullptr);
1968 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1969 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1970 ret_ = demuxer_->SeekToTime(*toPts, *mode);
1971 if (ret_ != AV_ERR_OK) {
1972 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1973 continue;
1974 }
1975 ReadData();
1976 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
1977 ASSERT_EQ(frames_[0], audioVals[numbers_]);
1978 numbers_ += 1;
1979 RemoveValue();
1980 selectedTrackIds_.clear();
1981 }
1982 }
1983 ASSERT_NE(demuxer_->SeekToTime(11000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1984 ASSERT_NE(demuxer_->SeekToTime(-1000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1985 }
1986
1987 /**
1988 * @tc.name: Demuxer_ReadSample_3000
1989 * @tc.desc: copy current sample to buffer(srt)
1990 * @tc.type: FUNC
1991 */
1992 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_3000, TestSize.Level1)
1993 {
1994 InitResource(g_srt, LOCAL);
1995 ASSERT_TRUE(initStatus_);
1996 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1997
1998 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1999 ASSERT_NE(sharedMem_, nullptr);
2000 ASSERT_TRUE(SetInitValue());
2001 while (!isEOS(eosFlag_)) {
2002 for (auto idx : selectedTrackIds_) {
2003 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
2004 CountFrames(idx);
2005 }
2006 }
2007 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
2008 ASSERT_EQ(frames_[0], 5);
2009 RemoveValue();
2010 }
2011
2012 #ifndef DEMUXER_CAPI_BUFFER_UNIT_TEST
2013 /**
2014 * @tc.name: Demuxer_ReadSample_3002
2015 * @tc.desc: copy current sample to buffer(vtt, en)
2016 * @tc.type: FUNC
2017 */
2018 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_3002, TestSize.Level1)
2019 {
2020 InitResource(g_vttPath, LOCAL);
2021 ASSERT_TRUE(initStatus_);
2022 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
2023
2024 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
2025 ASSERT_NE(sharedMem_, nullptr);
2026 ASSERT_TRUE(SetInitValue());
2027 int32_t vttIndex = 0;
2028 while (!isEOS(eosFlag_)) {
2029 for (auto idx : selectedTrackIds_) {
2030 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
2031 char *vttStr = static_cast<char *>(malloc(info_.size * sizeof(char) + 1));
2032 memcpy_s(vttStr, info_.size, sharedMem_->GetAddr(), info_.size);
2033 *(vttStr + info_.size) = '\0';
2034 switch (vttIndex) {
2035 case 0:
2036 ASSERT_EQ(strcmp(vttStr, "testA"), 0);
2037 ASSERT_EQ(info_.presentationTimeUs, 500000);
2038 ASSERT_EQ(info_.size, 5);
2039 break;
2040 case 1:
2041 ASSERT_EQ(strcmp(vttStr, "testBB"), 0);
2042 ASSERT_EQ(info_.presentationTimeUs, 1001000);
2043 ASSERT_EQ(info_.size, 6);
2044 break;
2045 case 2:
2046 ASSERT_EQ(strcmp(vttStr, "testCCC"), 0);
2047 ASSERT_EQ(info_.presentationTimeUs, 2003000);
2048 ASSERT_EQ(info_.size, 7);
2049 break;
2050 case 3:
2051 ASSERT_EQ(strcmp(vttStr, "testDDDD"), 0);
2052 ASSERT_EQ(info_.presentationTimeUs, 2100000);
2053 ASSERT_EQ(info_.size, 8);
2054 break;
2055 default:
2056 break;
2057 }
2058 CountFrames(idx);
2059 free(vttStr);
2060 }
2061 vttIndex++;
2062 }
2063 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
2064 ASSERT_EQ(frames_[0], 4);
2065 RemoveValue();
2066 }
2067
2068 /**
2069 * @tc.name: Demuxer_ReadSample_3003
2070 * @tc.desc: copy current sample to buffer(vtt, zh)
2071 * @tc.type: FUNC
2072 */
2073 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_3003, TestSize.Level1)
2074 {
2075 InitResource(g_vttPath2, LOCAL);
2076 ASSERT_TRUE(initStatus_);
2077 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
2078
2079 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
2080 ASSERT_NE(sharedMem_, nullptr);
2081 ASSERT_TRUE(SetInitValue());
2082 int32_t vttIndex = 0;
2083 while (!isEOS(eosFlag_)) {
2084 for (auto idx : selectedTrackIds_) {
2085 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
2086 char *vttStr = static_cast<char *>(malloc(info_.size * sizeof(char) + 1));
2087 memcpy_s(vttStr, info_.size, sharedMem_->GetAddr(), info_.size);
2088 *(vttStr + info_.size) = '\0';
2089 switch (vttIndex) {
2090 case 0:
2091 ASSERT_EQ(strcmp(vttStr, "第1帧"), 0);
2092 ASSERT_EQ(info_.presentationTimeUs, 30000);
2093 ASSERT_EQ(info_.size, 7);
2094 break;
2095 case 1:
2096 ASSERT_EQ(strcmp(vttStr, "第2帧"), 0);
2097 ASSERT_EQ(info_.presentationTimeUs, 2030000);
2098 ASSERT_EQ(info_.size, 7);
2099 break;
2100 case 2:
2101 ASSERT_EQ(strcmp(vttStr, "第3帧"), 0);
2102 ASSERT_EQ(info_.presentationTimeUs, 2900000);
2103 ASSERT_EQ(info_.size, 7);
2104 break;
2105 case 3:
2106 ASSERT_EQ(strcmp(vttStr, "第4帧"), 0);
2107 ASSERT_EQ(info_.presentationTimeUs, 3000000);
2108 ASSERT_EQ(info_.size, 7);
2109 break;
2110 default:
2111 break;
2112 }
2113 CountFrames(idx);
2114 free(vttStr);
2115 }
2116 vttIndex++;
2117 }
2118 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
2119
2120 ASSERT_EQ(frames_[0], 10);
2121 RemoveValue();
2122 }
2123
2124 /**
2125 * @tc.name: Demuxer_ReadSample_3013
2126 * @tc.desc: copy current sample to buffer(vtt, zh)
2127 * @tc.type: FUNC
2128 */
2129 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_3013, TestSize.Level1)
2130 {
2131 InitResource(g_vttMp4Path, LOCAL);
2132 ASSERT_TRUE(initStatus_);
2133 for (int i = 0; i < nbStreams_; i++) {
2134 ASSERT_EQ(demuxer_->SelectTrackByID(i), AV_ERR_OK);
2135 }
2136
2137 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
2138 ASSERT_NE(sharedMem_, nullptr);
2139 ASSERT_TRUE(SetInitValue());
2140 while (!isEOS(eosFlag_)) {
2141 for (auto idx : selectedTrackIds_) {
2142 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
2143 CountFrames(idx);
2144 }
2145 }
2146 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
2147
2148 ASSERT_EQ(frames_[0], 604);
2149 ASSERT_EQ(keyFrames_[0], 61);
2150 ASSERT_EQ(frames_[1], 434);
2151 ASSERT_EQ(keyFrames_[1], 434);
2152 ASSERT_EQ(frames_[2], 9);
2153 ASSERT_EQ(keyFrames_[2], 9);
2154 RemoveValue();
2155 }
2156 #endif
2157
2158 #ifdef SUPPORT_DEMUXER_LRC
2159 /**
2160 * @tc.name: Demuxer_ReadSample_3004
2161 * @tc.desc: copy current sample to buffer(lrc)
2162 * @tc.type: FUNC
2163 */
2164 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_3004, TestSize.Level1)
2165 {
2166 InitResource(g_lrcPath, LOCAL);
2167 ASSERT_TRUE(initStatus_);
2168 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
2169
2170 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
2171 ASSERT_NE(sharedMem_, nullptr);
2172 ASSERT_TRUE(SetInitValue());
2173 while (!isEOS(eosFlag_)) {
2174 for (auto idx : selectedTrackIds_) {
2175 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
2176 CountFrames(idx);
2177 }
2178 }
2179 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
2180 ASSERT_EQ(frames_[0], 5);
2181 RemoveValue();
2182 }
2183 #endif
2184
2185 #ifdef SUPPORT_DEMUXER_SAMI
2186 /**
2187 * @tc.name: Demuxer_ReadSample_3005
2188 * @tc.desc: copy current sample to buffer(sami)
2189 * @tc.type: FUNC
2190 */
2191 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_3005, TestSize.Level1)
2192 {
2193 InitResource(g_samiPath, LOCAL);
2194 ASSERT_TRUE(initStatus_);
2195 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
2196
2197 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
2198 ASSERT_NE(sharedMem_, nullptr);
2199 ASSERT_TRUE(SetInitValue());
2200 while (!isEOS(eosFlag_)) {
2201 for (auto idx : selectedTrackIds_) {
2202 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
2203 CountFrames(idx);
2204 }
2205 }
2206 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
2207 ASSERT_EQ(frames_[0], 10);
2208 RemoveValue();
2209 }
2210 #endif
2211
2212 #ifdef SUPPORT_DEMUXER_ASS
2213 /**
2214 * @tc.name: Demuxer_ReadSample_3006
2215 * @tc.desc: copy current sample to buffer(ass)
2216 * @tc.type: FUNC
2217 */
2218 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_3006, TestSize.Level1)
2219 {
2220 InitResource(g_assPath, LOCAL);
2221 ASSERT_TRUE(initStatus_);
2222 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
2223
2224 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
2225 ASSERT_NE(sharedMem_, nullptr);
2226 ASSERT_TRUE(SetInitValue());
2227 while (!isEOS(eosFlag_)) {
2228 for (auto idx : selectedTrackIds_) {
2229 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
2230 CountFrames(idx);
2231 }
2232 }
2233 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
2234 ASSERT_EQ(frames_[0], 5);
2235 RemoveValue();
2236 }
2237 #endif
2238
2239 /**
2240 * @tc.name: Demuxer_SeekToTime_3000
2241 * @tc.desc: seek to the specified time(srt)
2242 * @tc.type: FUNC
2243 */
2244 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_3000, TestSize.Level1)
2245 {
2246 InitResource(g_srt, LOCAL);
2247 ASSERT_TRUE(initStatus_);
2248 ASSERT_TRUE(SetInitValue());
2249 for (auto idx : selectedTrackIds_) {
2250 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
2251 }
2252 list<int64_t> toPtsList = {0, 160, 2000, 4000, 7000}; // ms
2253 vector<int32_t> subVals = {5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 2, 2, 2};
2254 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
2255 ASSERT_NE(sharedMem_, nullptr);
2256 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
2257 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
2258 ret_ = demuxer_->SeekToTime(*toPts, *mode);
2259 if (ret_ != AV_ERR_OK) {
2260 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
2261 continue;
2262 }
2263 ReadData();
2264 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
2265 ASSERT_EQ(frames_[0], subVals[numbers_]);
2266 numbers_ += 1;
2267 RemoveValue();
2268 selectedTrackIds_.clear();
2269 }
2270 }
2271 }
2272
2273 #ifndef DEMUXER_CAPI_BUFFER_UNIT_TEST
2274 /**
2275 * @tc.name: Demuxer_SeekToTime_3002
2276 * @tc.desc: seek to the specified time(vtt, en)
2277 * @tc.type: FUNC
2278 */
2279 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_3002, TestSize.Level1)
2280 {
2281 InitResource(g_vttPath, LOCAL);
2282 ASSERT_TRUE(initStatus_);
2283 ASSERT_TRUE(SetInitValue());
2284 for (auto idx : selectedTrackIds_) {
2285 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
2286 }
2287 list<int64_t> toPtsList = {500, 1000, 2000, 3000}; // ms
2288 vector<int32_t> subVals = {4, 4, 4, 4, 4, 4, 3, 3, 3, 1, 1, 1};
2289 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
2290 ASSERT_NE(sharedMem_, nullptr);
2291 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
2292 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
2293 ret_ = demuxer_->SeekToTime(*toPts, *mode);
2294 if (ret_ != AV_ERR_OK) {
2295 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
2296 continue;
2297 }
2298 ReadData();
2299 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
2300 ASSERT_EQ(frames_[0], subVals[numbers_]);
2301 numbers_ += 1;
2302 RemoveValue();
2303 selectedTrackIds_.clear();
2304 }
2305 }
2306 }
2307
2308 /**
2309 * @tc.name: Demuxer_SeekToTime_3003
2310 * @tc.desc: seek to the specified time(vtt, zh)
2311 * @tc.type: FUNC
2312 */
2313 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_3003, TestSize.Level1)
2314 {
2315 InitResource(TEST_FILE_PATH + string("webvtt_test2.vtt"), LOCAL);
2316 ASSERT_TRUE(initStatus_);
2317 ASSERT_TRUE(SetInitValue());
2318 for (auto idx : selectedTrackIds_) {
2319 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
2320 }
2321 list<int64_t> toPtsList = {100, 1000, 1200, 61000, 65000}; // ms
2322 vector<int32_t> subVals = {10, 10, 10, 10, 10, 10, 9, 9, 9, 1, 1, 1, 1, 1, 1};
2323 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
2324 ASSERT_NE(sharedMem_, nullptr);
2325 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
2326 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
2327 ret_ = demuxer_->SeekToTime(*toPts, *mode);
2328 if (ret_ != AV_ERR_OK) {
2329 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
2330 continue;
2331 }
2332 ReadData();
2333 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
2334 ASSERT_EQ(frames_[0], subVals[numbers_]);
2335 numbers_ += 1;
2336 RemoveValue();
2337 selectedTrackIds_.clear();
2338 }
2339 }
2340 }
2341 #endif
2342
2343 #ifdef SUPPORT_DEMUXER_LRC
2344 /**
2345 * @tc.name: Demuxer_SeekToTime_3004
2346 * @tc.desc: seek to the specified time(lrc)
2347 * @tc.type: FUNC
2348 */
2349 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_3004, TestSize.Level1)
2350 {
2351 InitResource(g_lrcPath, LOCAL);
2352 ASSERT_TRUE(initStatus_);
2353 ASSERT_TRUE(SetInitValue());
2354 for (auto idx : selectedTrackIds_) {
2355 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
2356 }
2357 list<int64_t> toPtsList = {0, 160, 2000, 4000, 7000}; // ms
2358 vector<int32_t> subVals = {5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 2, 2, 2};
2359 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
2360 ASSERT_NE(sharedMem_, nullptr);
2361 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
2362 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
2363 ret_ = demuxer_->SeekToTime(*toPts, *mode);
2364 if (ret_ != AV_ERR_OK) {
2365 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
2366 continue;
2367 }
2368 ReadData();
2369 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
2370 ASSERT_EQ(frames_[0], subVals[numbers_]);
2371 numbers_ += 1;
2372 RemoveValue();
2373 selectedTrackIds_.clear();
2374 }
2375 }
2376 }
2377 #endif
2378
2379 #ifdef SUPPORT_DEMUXER_SAMI
2380 /**
2381 * @tc.name: Demuxer_SeekToTime_3005
2382 * @tc.desc: seek to the specified time(sami)
2383 * @tc.type: FUNC
2384 */
2385 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_3005, TestSize.Level1)
2386 {
2387 InitResource(g_samiPath, LOCAL);
2388 ASSERT_TRUE(initStatus_);
2389 ASSERT_TRUE(SetInitValue());
2390 for (auto idx : selectedTrackIds_) {
2391 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
2392 }
2393 list<int64_t> toPtsList = {0, 160, 2000, 4000, 7000}; // ms
2394 vector<int32_t> subVals = {10, 10, 10, 10, 10, 10, 10, 10, 10, 8, 8, 8, 4, 4, 4};
2395 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
2396 ASSERT_NE(sharedMem_, nullptr);
2397 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
2398 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
2399 ret_ = demuxer_->SeekToTime(*toPts, *mode);
2400 if (ret_ != AV_ERR_OK) {
2401 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
2402 continue;
2403 }
2404 ReadData();
2405 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
2406 ASSERT_EQ(frames_[0], subVals[numbers_]);
2407 numbers_ += 1;
2408 RemoveValue();
2409 selectedTrackIds_.clear();
2410 }
2411 }
2412 }
2413 #endif
2414
2415 #ifdef SUPPORT_DEMUXER_ASS
2416 /**
2417 * @tc.name: Demuxer_SeekToTime_3006
2418 * @tc.desc: seek to the specified time(ass)
2419 * @tc.type: FUNC
2420 */
2421 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_3006, TestSize.Level1)
2422 {
2423 InitResource(g_assPath, LOCAL);
2424 ASSERT_TRUE(initStatus_);
2425 ASSERT_TRUE(SetInitValue());
2426 for (auto idx : selectedTrackIds_) {
2427 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
2428 }
2429 list<int64_t> toPtsList = {0, 160, 2000, 4000, 7000}; // ms
2430 vector<int32_t> subVals = {5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 2, 2, 2};
2431 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
2432 ASSERT_NE(sharedMem_, nullptr);
2433 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
2434 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
2435 ret_ = demuxer_->SeekToTime(*toPts, *mode);
2436 if (ret_ != AV_ERR_OK) {
2437 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
2438 continue;
2439 }
2440 ReadData();
2441 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
2442 ASSERT_EQ(frames_[0], subVals[numbers_]);
2443 numbers_ += 1;
2444 RemoveValue();
2445 selectedTrackIds_.clear();
2446 }
2447 }
2448 }
2449 #endif
2450
2451 /**
2452 * @tc.name: Demuxer_SetMediaKeySystemInfoCallback_4000
2453 * @tc.desc: set normal drm callback
2454 * @tc.type: FUNC
2455 */
2456 HWTEST_F(DemuxerUnitTest, Demuxer_SetMediaKeySystemInfoCallback_4000, TestSize.Level1)
2457 {
2458 InitResource(g_drmSm4cPath, LOCAL);
2459 ASSERT_TRUE(initStatus_);
2460
2461 bool isNullCallback = false;
2462 int32_t ret = demuxer_->SetMediaKeySystemInfoCallback(isNullCallback);
2463 ASSERT_EQ(ret, AV_ERR_OK);
2464 }
2465
2466 /**
2467 * @tc.name: Demuxer_SetMediaKeySystemInfoCallback_4001
2468 * @tc.desc: set null drm callback
2469 * @tc.type: FUNC
2470 */
2471 HWTEST_F(DemuxerUnitTest, Demuxer_SetMediaKeySystemInfoCallback_4001, TestSize.Level1)
2472 {
2473 InitResource(g_drmSm4cPath, LOCAL);
2474 ASSERT_TRUE(initStatus_);
2475
2476 bool isNullCallback = true;
2477 int32_t ret = demuxer_->SetMediaKeySystemInfoCallback(isNullCallback);
2478 ASSERT_EQ(ret, AV_ERR_OK);
2479 }
2480
2481 /**
2482 * @tc.name: Demuxer_SetDemuxerMediaKeySystemInfoCallback_4002
2483 * @tc.desc: set normal drm callback
2484 * @tc.type: FUNC
2485 */
2486 HWTEST_F(DemuxerUnitTest, Demuxer_SetDemuxerMediaKeySystemInfoCallback_4002, TestSize.Level1)
2487 {
2488 InitResource(g_drmSm4cPath, LOCAL);
2489 ASSERT_TRUE(initStatus_);
2490
2491 bool isNullCallback = false;
2492 int32_t ret = demuxer_->SetDemuxerMediaKeySystemInfoCallback(isNullCallback);
2493 ASSERT_EQ(ret, AV_ERR_OK);
2494 }
2495
2496 /**
2497 * @tc.name: Demuxer_SetDemuxerMediaKeySystemInfoCallback_4003
2498 * @tc.desc: set null drm callback
2499 * @tc.type: FUNC
2500 */
2501 HWTEST_F(DemuxerUnitTest, Demuxer_SetDemuxerMediaKeySystemInfoCallback_4003, TestSize.Level1)
2502 {
2503 InitResource(g_drmSm4cPath, LOCAL);
2504 ASSERT_TRUE(initStatus_);
2505
2506 bool isNullCallback = true;
2507 int32_t ret = demuxer_->SetDemuxerMediaKeySystemInfoCallback(isNullCallback);
2508 ASSERT_EQ(ret, AV_ERR_OK);
2509 }
2510
2511 /**
2512 * @tc.name: Demuxer_GetMediaKeySystemInfo_4004
2513 * @tc.desc: get drm info when play drm
2514 * @tc.type: FUNC
2515 */
2516 HWTEST_F(DemuxerUnitTest, Demuxer_GetMediaKeySystemInfo_4004, TestSize.Level1)
2517 {
2518 InitResource(g_drmSm4cPath, LOCAL);
2519 ASSERT_TRUE(initStatus_);
2520
2521 int32_t ret = demuxer_->GetMediaKeySystemInfo();
2522 ASSERT_EQ(ret, AV_ERR_OK);
2523 }
2524
2525 #ifndef DEMUXER_CAPI_UNIT_TEST
2526 /**
2527 * @tc.name: Demuxer_GetIndexByRelativePresentationTimeUs_1000
2528 * @tc.desc: Get index by pts(audio track)
2529 * @tc.type: FUNC
2530 */
2531 HWTEST_F(DemuxerUnitTest, Demuxer_GetIndexByRelativePresentationTimeUs_1000, TestSize.Level1)
2532 {
2533 InitResource(g_ptsConversionPath, LOCAL);
2534 ASSERT_TRUE(initStatus_);
2535
2536 uint32_t trackIndex = 0;
2537 uint64_t relativePresentationTimeUs = 69659;
2538 uint32_t index = 0;
2539
2540 int32_t ret = demuxer_->GetIndexByRelativePresentationTimeUs(trackIndex, relativePresentationTimeUs, index);
2541 ASSERT_EQ(ret, AV_ERR_OK);
2542
2543 ASSERT_EQ(index, 3);
2544 }
2545
2546 /**
2547 * @tc.name: Demuxer_GetIndexByRelativePresentationTimeUs_1001
2548 * @tc.desc: Get index by pts(video track)
2549 * @tc.type: FUNC
2550 */
2551 HWTEST_F(DemuxerUnitTest, Demuxer_GetIndexByRelativePresentationTimeUs_1001, TestSize.Level1)
2552 {
2553 InitResource(g_ptsConversionPath, LOCAL);
2554 ASSERT_TRUE(initStatus_);
2555
2556 uint32_t trackIndex = 1;
2557 uint64_t relativePresentationTimeUs = 66666;
2558 uint32_t index = 0;
2559
2560 int32_t ret = demuxer_->GetIndexByRelativePresentationTimeUs(trackIndex, relativePresentationTimeUs, index);
2561 ASSERT_EQ(ret, AV_ERR_OK);
2562
2563 ASSERT_EQ(index, 4);
2564 }
2565
2566 /**
2567 * @tc.name: Demuxer_GetIndexByRelativePresentationTimeUs_1002
2568 * @tc.desc: Get index by pts(not MP4)
2569 * @tc.type: FUNC
2570 */
2571 HWTEST_F(DemuxerUnitTest, Demuxer_GetIndexByRelativePresentationTimeUs_1002, TestSize.Level1)
2572 {
2573 InitResource(g_flvPath, LOCAL);
2574 ASSERT_TRUE(initStatus_);
2575
2576 uint32_t trackIndex = 0;
2577 uint64_t relativePresentationTimeUs = 69659;
2578 uint32_t index = 0;
2579
2580 int32_t ret = demuxer_->GetIndexByRelativePresentationTimeUs(trackIndex, relativePresentationTimeUs, index);
2581 ASSERT_NE(ret, AV_ERR_OK);
2582
2583 ASSERT_EQ(index, 0);
2584 }
2585
2586 /**
2587 * @tc.name: Demuxer_GetIndexByRelativePresentationTimeUs_1003
2588 * @tc.desc: Get index by pts(non-standard pts & different track)
2589 * @tc.type: FUNC
2590 */
2591 HWTEST_F(DemuxerUnitTest, Demuxer_GetIndexByRelativePresentationTimeUs_1003, TestSize.Level1)
2592 {
2593 InitResource(g_ptsConversionPath, LOCAL);
2594 ASSERT_TRUE(initStatus_);
2595
2596 // standard pts & video track
2597 uint32_t trackIndex = 1;
2598 uint64_t relativePresentationTimeUs = 166666;
2599 uint32_t index = 0;
2600 int32_t ret = demuxer_->GetIndexByRelativePresentationTimeUs(trackIndex, relativePresentationTimeUs, index);
2601 ASSERT_EQ(ret, AV_ERR_OK);
2602 ASSERT_EQ(index, 10);
2603 }
2604
2605 /**
2606 * @tc.name: Demuxer_GetRelativePresentationTimeUsByIndex_1000
2607 * @tc.desc: get pts by frameIndex(audio track)
2608 * @tc.type: FUNC
2609 */
2610 HWTEST_F(DemuxerUnitTest, Demuxer_GetRelativePresentationTimeUsByIndex_1000, TestSize.Level1)
2611 {
2612 InitResource(g_ptsConversionPath, LOCAL);
2613 ASSERT_TRUE(initStatus_);
2614
2615 uint32_t trackIndex = 0;
2616 uint64_t relativePresentationTimeUs = 0;
2617 uint32_t index = 2;
2618
2619 int32_t ret = demuxer_->GetRelativePresentationTimeUsByIndex(trackIndex, index, relativePresentationTimeUs);
2620 ASSERT_EQ(ret, AV_ERR_OK);
2621
2622 ASSERT_EQ(relativePresentationTimeUs, 46439);
2623 }
2624
2625 /**
2626 * @tc.name: Demuxer_GetRelativePresentationTimeUsByIndex_1001
2627 * @tc.desc: get pts by frameIndex(video track)
2628 * @tc.type: FUNC
2629 */
2630 HWTEST_F(DemuxerUnitTest, Demuxer_GetRelativePresentationTimeUsByIndex_1001, TestSize.Level1)
2631 {
2632 InitResource(g_ptsConversionPath, LOCAL);
2633 ASSERT_TRUE(initStatus_);
2634
2635 uint32_t trackIndex = 1;
2636 uint64_t relativePresentationTimeUs = 0;
2637 uint32_t index = 2;
2638
2639 int32_t ret = demuxer_->GetRelativePresentationTimeUsByIndex(trackIndex, index, relativePresentationTimeUs);
2640 ASSERT_EQ(ret, AV_ERR_OK);
2641
2642 ASSERT_EQ(relativePresentationTimeUs, 33333);
2643 }
2644
2645 /**
2646 * @tc.name: Demuxer_GetRelativePresentationTimeUsByIndex_1002
2647 * @tc.desc: get pts by frameIndex(not MP4)
2648 * @tc.type: FUNC
2649 */
2650 HWTEST_F(DemuxerUnitTest, Demuxer_GetRelativePresentationTimeUsByIndex_1002, TestSize.Level1)
2651 {
2652 InitResource(g_flvPath, LOCAL);
2653 ASSERT_TRUE(initStatus_);
2654
2655 uint32_t trackIndex = 0;
2656 uint64_t relativePresentationTimeUs = 0;
2657 uint32_t index = 10;
2658
2659 int32_t ret = demuxer_->GetRelativePresentationTimeUsByIndex(trackIndex, index, relativePresentationTimeUs);
2660 ASSERT_NE(ret, AV_ERR_OK);
2661
2662 ASSERT_EQ(relativePresentationTimeUs, 0);
2663 }
2664
2665 /**
2666 * @tc.name: Demuxer_PtsAndFrameIndexConversion_1000
2667 * @tc.desc: pts and frameIndex convertion test(pts -> frameIndex -> pts)
2668 * @tc.type: FUNC
2669 */
2670 HWTEST_F(DemuxerUnitTest, Demuxer_PtsAndFrameIndexConversion_1000, TestSize.Level1)
2671 {
2672 InitResource(g_ptsConversionPath, LOCAL);
2673 ASSERT_TRUE(initStatus_);
2674
2675 uint32_t trackIndex = 0;
2676 uint64_t relativePresentationTimeUs = 92879;
2677 uint32_t index = 0;
2678
2679 int32_t ret = demuxer_->GetIndexByRelativePresentationTimeUs(trackIndex, relativePresentationTimeUs, index);
2680 ASSERT_EQ(ret, AV_ERR_OK);
2681 ASSERT_EQ(index, 4);
2682
2683 uint64_t relativePresentationTimeUs1 = 0;
2684
2685 ret = demuxer_->GetRelativePresentationTimeUsByIndex(trackIndex, index, relativePresentationTimeUs1);
2686 ASSERT_EQ(ret, AV_ERR_OK);
2687 ASSERT_EQ(relativePresentationTimeUs1, 92879);
2688 }
2689
2690 /**
2691 * @tc.name: Demuxer_PtsAndFrameIndexConversion_1001
2692 * @tc.desc: pts and frameIndex convertion test(frameIndex -> pts -> frameIndex)
2693 * @tc.type: FUNC
2694 */
2695 HWTEST_F(DemuxerUnitTest, Demuxer_PtsAndFrameIndexConversion_1001, TestSize.Level1)
2696 {
2697 InitResource(g_ptsConversionPath, LOCAL);
2698 ASSERT_TRUE(initStatus_);
2699
2700 uint32_t trackIndex = 0;
2701 uint64_t relativePresentationTimeUs = 0;
2702 uint32_t index = 4;
2703
2704 int32_t ret = demuxer_->GetRelativePresentationTimeUsByIndex(trackIndex, index, relativePresentationTimeUs);
2705 ASSERT_EQ(ret, AV_ERR_OK);
2706 ASSERT_EQ(relativePresentationTimeUs, 92879);
2707
2708 uint32_t index1 = 0;
2709
2710 ret = demuxer_->GetIndexByRelativePresentationTimeUs(trackIndex, relativePresentationTimeUs, index1);
2711 ASSERT_EQ(ret, AV_ERR_OK);
2712 ASSERT_EQ(index1, 4);
2713 }
2714
2715 /**
2716 * @tc.name: Demuxer_PTSOutOfRange_1000
2717 * @tc.desc: pts out of range
2718 * @tc.type: FUNC
2719 */
2720 HWTEST_F(DemuxerUnitTest, Demuxer_PTSOutOfRange_1000, TestSize.Level1)
2721 {
2722 InitResource(g_ptsConversionPath, LOCAL);
2723 ASSERT_TRUE(initStatus_);
2724
2725 uint32_t trackIndex = 0;
2726 uint64_t relativePresentationTimeUs = 999999999;
2727 uint32_t index = 0;
2728 int32_t ret = demuxer_->GetIndexByRelativePresentationTimeUs(trackIndex, relativePresentationTimeUs, index);
2729 ASSERT_NE(ret, AV_ERR_OK);
2730 }
2731
2732 /**
2733 * @tc.name: Demuxer_IndexOutOfRange_1000
2734 * @tc.desc: Index out of range
2735 * @tc.type: FUNC
2736 */
2737 HWTEST_F(DemuxerUnitTest, Demuxer_IndexOutOfRange_1000, TestSize.Level1)
2738 {
2739 InitResource(g_ptsConversionPath, LOCAL);
2740 ASSERT_TRUE(initStatus_);
2741
2742 uint32_t trackIndex = 0;
2743 uint64_t relativePresentationTimeUs = 0;
2744 uint32_t index = 9999999;
2745 int32_t ret = demuxer_->GetRelativePresentationTimeUsByIndex(trackIndex, index, relativePresentationTimeUs);
2746 ASSERT_NE(ret, AV_ERR_OK);
2747 }
2748
2749 /**
2750 * @tc.name: Demuxer_TrackOutOfRange_1000
2751 * @tc.desc: Track out of range
2752 * @tc.type: FUNC
2753 */
2754 HWTEST_F(DemuxerUnitTest, Demuxer_TrackOutOfRange_1000, TestSize.Level1)
2755 {
2756 InitResource(g_ptsConversionPath, LOCAL);
2757 ASSERT_TRUE(initStatus_);
2758
2759 uint32_t trackIndex = 99;
2760 uint64_t relativePresentationTimeUs = 0;
2761 uint32_t index = 0;
2762 int32_t ret = demuxer_->GetRelativePresentationTimeUsByIndex(trackIndex, index, relativePresentationTimeUs);
2763 ASSERT_NE(ret, AV_ERR_OK);
2764 }
2765
2766 #endif
2767
2768 /**
2769 * @tc.name: Demuxer_ReadSample_1601
2770 * @tc.desc: copy current sample to buffer(mp4 vvc)
2771 * @tc.type: FUNC
2772 */
2773 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1601, TestSize.Level1)
2774 {
2775 if (access(g_mp4VvcPath.c_str(), F_OK) == 0) {
2776 InitResource(g_mp4VvcPath, LOCAL);
2777 ASSERT_TRUE(initStatus_);
2778 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
2779 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
2780 ASSERT_NE(sharedMem_, nullptr);
2781 ASSERT_TRUE(SetInitValue());
2782 uint32_t idx = 0;
2783 while (!isEOS(eosFlag_)) {
2784 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
2785 CountFrames(idx);
2786 }
2787 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
2788 ASSERT_EQ(frames_[0], 600);
2789 ASSERT_EQ(keyFrames_[0], 10);
2790 RemoveValue();
2791 }
2792 }
2793
2794 /**
2795 * @tc.name: Demuxer_SeekToTime_1601
2796 * @tc.desc: seek to the specified time(mp4 vvc fd)
2797 * @tc.type: FUNC
2798 */
2799 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1601, TestSize.Level1)
2800 {
2801 if (access(g_mp4VvcPath.c_str(), F_OK) == 0) {
2802 InitResource(g_mp4VvcPath, LOCAL);
2803 ASSERT_TRUE(initStatus_);
2804 ASSERT_TRUE(SetInitValue());
2805 for (auto idx : selectedTrackIds_) {
2806 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
2807 }
2808 list<int64_t> toPtsList = {0, 4500, 7000, 2000}; // ms
2809 vector<int32_t> audioVals = {433, 433, 433, 240, 240, 240, 132, 132, 132, 348, 348, 348};
2810 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
2811 ASSERT_NE(sharedMem_, nullptr);
2812 SeekTest(toPtsList, seekModes, {audioVals});
2813 ASSERT_TRUE(seekTestFlag_);
2814 ASSERT_NE(demuxer_->SeekToTime(11000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
2815 ASSERT_NE(demuxer_->SeekToTime(-1000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
2816 }
2817 }
2818
2819 /**
2820 * @tc.number : Demuxer_GetCommentData_1000
2821 * @tc.name : demux MP4 muxed by avmuxer,check track format,OH_MD_KEY_COMMENT
2822 * @tc.desc : function test
2823 */
2824 HWTEST_F(DemuxerUnitTest, Demuxer_GetCommentData_1000, TestSize.Level0)
2825 {
2826 InitResource(g_commentTest1000Path, LOCAL);
2827 ASSERT_TRUE(initStatus_);
2828 std::string stringVal = "";
2829 ASSERT_TRUE(format_->GetStringValue(OH_MD_KEY_COMMENT, stringVal));
2830 ASSERT_EQ(stringVal, "comment_test_str");
2831 }
2832
2833 /**
2834 * @tc.number : Demuxer_GetCommentData_1100
2835 * @tc.name : demux MP4 muxed by avmuxer,check track format,OH_MD_KEY_COMMENT
2836 * @tc.desc : function test
2837 */
2838 HWTEST_F(DemuxerUnitTest, Demuxer_GetCommentData_1100, TestSize.Level0)
2839 {
2840 InitResource(g_commentTest1100Path, LOCAL);
2841 ASSERT_TRUE(initStatus_);
2842 std::string stringVal = "";
2843 ASSERT_FALSE(format_->GetStringValue(OH_MD_KEY_COMMENT, stringVal));
2844 ASSERT_EQ(stringVal, "");
2845 }
2846
2847 /**
2848 * @tc.number : Demuxer_GetCommentData_1200
2849 * @tc.name : demux MP4 muxed by avmuxer,check track format,OH_MD_KEY_COMMENT
2850 * @tc.desc : function test
2851 */
2852 HWTEST_F(DemuxerUnitTest, Demuxer_GetCommentData_1200, TestSize.Level0)
2853 {
2854 InitResource(g_commentTest1200Path, LOCAL);
2855 ASSERT_TRUE(initStatus_);
2856 std::string stringVal = "";
2857 ASSERT_TRUE(format_->GetStringValue(OH_MD_KEY_COMMENT, stringVal));
2858 ASSERT_EQ(stringVal, "中文测试字符串");
2859 }
2860
2861 /**
2862 * @tc.number : Demuxer_GetCommentData_1300
2863 * @tc.name : demux MP4 muxed by avmuxer,check track format,OH_MD_KEY_COMMENT
2864 * @tc.desc : function test
2865 */
2866 HWTEST_F(DemuxerUnitTest, Demuxer_GetCommentData_1300, TestSize.Level0)
2867 {
2868 InitResource(g_commentTest1300Path, LOCAL);
2869 ASSERT_TRUE(initStatus_);
2870 std::string stringVal = "";
2871 ASSERT_TRUE(format_->GetStringValue(OH_MD_KEY_COMMENT, stringVal));
2872 ASSERT_EQ(stringVal, "comment_test_strcomment_test_strcomment_test_str"
2873 "comment_test_strcomment_test_strcomment_test_strcomment_test_strcomment_test_str"
2874 "comment_test_strcomment_test_strcomment_test_strcomment_test_strcomment_test_str"
2875 "comment_test_strcomment_test_strcomment_test_str");
2876 }
2877
2878 /**
2879 * @tc.name: Demuxer_ReadSample_WavAlaw_0001
2880 * @tc.desc: copy current sample to buffer(wav alaw)
2881 * @tc.type: FUNC
2882 */
2883 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_WavAlaw_0001, TestSize.Level1)
2884 {
2885 ASSERT_TRUE(!access(g_wavAlawPath.c_str(), F_OK));
2886 InitResource(g_wavAlawPath, LOCAL);
2887 ASSERT_TRUE(initStatus_);
2888 int trackIndex = 0;
2889 ASSERT_EQ(demuxer_->SelectTrackByID(trackIndex), AV_ERR_OK);
2890 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
2891 ASSERT_NE(sharedMem_, nullptr);
2892 ASSERT_TRUE(SetInitValue());
2893 std::vector<int> expPtsVec = {0, 85333, 170666, 256000, 341333, 426666, 512000};
2894 std::vector<int> expSizeVec = {4096, 4096, 4096, 4096, 4096, 4096, 4096};
2895 size_t idx = 0;
2896 while (!isEOS(eosFlag_)) {
2897 ASSERT_EQ(demuxer_->ReadSample(trackIndex, sharedMem_, &info_, flag_), AV_ERR_OK);
2898 if (idx < expPtsVec.size()) {
2899 ASSERT_EQ(expPtsVec[idx], info_.presentationTimeUs);
2900 ASSERT_EQ(expSizeVec[idx], info_.size);
2901 }
2902 CountFrames(trackIndex);
2903 idx++;
2904 }
2905 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[trackIndex], keyFrames_[trackIndex]);
2906 ASSERT_EQ(frames_[trackIndex], 352);
2907 ASSERT_EQ(keyFrames_[trackIndex], 352);
2908 RemoveValue();
2909 }
2910
2911 /**
2912 * @tc.name: Demuxer_SeekToTime_WavAlaw_0001
2913 * @tc.desc: seek to the specified time(wav alaw)
2914 * @tc.type: FUNC
2915 */
2916 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_WavAlaw_0001, TestSize.Level1)
2917 {
2918 ASSERT_TRUE(!access(g_wavAlawPath.c_str(), F_OK));
2919 InitResource(g_wavAlawPath, LOCAL);
2920 ASSERT_TRUE(initStatus_);
2921 ASSERT_TRUE(SetInitValue());
2922 for (auto idx : selectedTrackIds_) {
2923 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
2924 }
2925 list<int64_t> toPtsList = {0, 100, 500, 900}; // ms
2926 vector<int32_t> audioVals = {352, 352, 352, 351, 351, 351, 347, 347, 347, 342, 342, 342};
2927 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
2928 ASSERT_NE(sharedMem_, nullptr);
2929 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
2930 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
2931 ret_ = demuxer_->SeekToTime(*toPts, *mode);
2932 if (ret_ != AV_ERR_OK) {
2933 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
2934 continue;
2935 }
2936 ReadData();
2937 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
2938 ASSERT_EQ(frames_[0], audioVals[numbers_]);
2939 numbers_ += 1;
2940 RemoveValue();
2941 selectedTrackIds_.clear();
2942 }
2943 }
2944 }
2945
2946 #ifdef SUPPORT_CODEC_RM
2947 /**
2948 * @tc.name: Demuxer_ReadSample_1800
2949 * @tc.desc: copy current sample to buffer(rmvb)
2950 * @tc.type: FUNC
2951 */
2952 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1800, TestSize.Level1)
2953 {
2954 InitResource(g_rmvbPath, LOCAL);
2955 ASSERT_NE(source_, nullptr);
2956 ASSERT_NE(format_, nullptr);
2957 ASSERT_NE(demuxer_, nullptr);
2958 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
2959 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
2960 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
2961 ASSERT_NE(demuxer_->SelectTrackByID(-1), AV_ERR_OK);
2962 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
2963 ASSERT_NE(sharedMem_, nullptr);
2964 ASSERT_TRUE(SetInitValue());
2965 while (!isEOS(eosFlag_)) {
2966 for (auto idx : selectedTrackIds_) {
2967 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
2968 CountFrames(idx);
2969 }
2970 }
2971 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
2972 printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]);
2973 ASSERT_EQ(frames_[0], 251);
2974 ASSERT_EQ(frames_[1], 480);
2975 ASSERT_EQ(keyFrames_[0], 2);
2976 ASSERT_EQ(keyFrames_[1], 480);
2977 RemoveValue();
2978 ASSERT_EQ(demuxer_->UnselectTrackByID(0), AV_ERR_OK);
2979 ASSERT_EQ(demuxer_->UnselectTrackByID(1), AV_ERR_OK);
2980 ASSERT_EQ(demuxer_->UnselectTrackByID(3), AV_ERR_OK);
2981 ASSERT_EQ(demuxer_->UnselectTrackByID(-1), AV_ERR_OK);
2982 ASSERT_EQ(demuxer_->Destroy(), AV_ERR_OK);
2983 }
2984
2985 /**
2986 * @tc.name: Demuxer_SeekToTime_1800
2987 * @tc.desc: seek to the specified time(rmvb)
2988 * @tc.type: FUNC
2989 */
2990 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1800, TestSize.Level1)
2991 {
2992 InitResource(g_rmvbPath, LOCAL);
2993 ASSERT_TRUE(SetInitValue());
2994 for (auto idx : selectedTrackIds_) {
2995 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
2996 }
2997 list<int64_t> toPtsList = {0, 4500, 7000, 2000, 10000, 8000}; // ms
2998 vector<int32_t> videoVals = {251, 251, 251, 2, 251, 251, 2, 251, 2, 2, 251, 251, 2, 2, 2, 2, 251, 2};
2999 vector<int32_t> audioVals = {480, 480, 480, 0, 480, 480, 0, 480, 0, 80, 480, 480, 0, 80, 0, 80, 480, 0};
3000 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
3001 ASSERT_NE(sharedMem_, nullptr);
3002 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
3003 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
3004 ret_ = demuxer_->SeekToTime(*toPts, *mode);
3005 if (ret_ != AV_ERR_OK) {
3006 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
3007 continue;
3008 }
3009 ReadData();
3010 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
3011 printf("time = %" PRId64 " | frames_[1]=%d\n", *toPts, frames_[1]);
3012 ASSERT_EQ(frames_[0], videoVals[numbers_]);
3013 ASSERT_EQ(frames_[1], audioVals[numbers_]);
3014 numbers_ += 1;
3015 RemoveValue();
3016 selectedTrackIds_.clear();
3017 }
3018 }
3019 ASSERT_NE(demuxer_->SeekToTime(12000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
3020 ASSERT_NE(demuxer_->SeekToTime(-1000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
3021 }
3022 #endif
3023
3024 /**
3025 * @tc.name: Demuxer_ReadSample_1801
3026 * @tc.desc: copy current sample to buffer(ac3)
3027 * @tc.type: FUNC
3028 */
3029 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1801, TestSize.Level1)
3030 {
3031 InitResource(g_ac3Path, LOCAL);
3032 ASSERT_NE(source_, nullptr);
3033 ASSERT_NE(format_, nullptr);
3034 ASSERT_NE(demuxer_, nullptr);
3035 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
3036 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
3037 ASSERT_NE(sharedMem_, nullptr);
3038 ASSERT_TRUE(SetInitValue());
3039 while (!isEOS(eosFlag_)) {
3040 for (auto idx : selectedTrackIds_) {
3041 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
3042 CountFrames(idx);
3043 }
3044 }
3045 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
3046 ASSERT_EQ(frames_[0], 317);
3047 ASSERT_EQ(keyFrames_[0], 317);
3048 RemoveValue();
3049 ASSERT_EQ(demuxer_->Destroy(), AV_ERR_OK);
3050 }
3051
3052 /**
3053 * @tc.name: Demuxer_SeekToTime_1801
3054 * @tc.desc: seek to the specified time(ac3)
3055 * @tc.type: FUNC
3056 */
3057 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1801, TestSize.Level1)
3058 {
3059 InitResource(g_ac3Path, LOCAL);
3060 ASSERT_TRUE(SetInitValue());
3061 for (auto idx : selectedTrackIds_) {
3062 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
3063 }
3064 list<int64_t> toPtsList = {0, 4500, 7000, 2000, 10000, 8000}; // ms
3065 vector<int32_t> audioVals = {317, 317, 317, 187, 188, 188, 115, 116, 116, 259, 260, 260, 29, 30, 30, 87, 88, 88};
3066 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
3067 ASSERT_NE(sharedMem_, nullptr);
3068 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
3069 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
3070 ret_ = demuxer_->SeekToTime(*toPts, *mode);
3071 if (ret_ != AV_ERR_OK) {
3072 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
3073 continue;
3074 }
3075 ReadData();
3076 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
3077 ASSERT_EQ(frames_[0], audioVals[numbers_]);
3078 numbers_ += 1;
3079 RemoveValue();
3080 selectedTrackIds_.clear();
3081 }
3082 }
3083 ASSERT_NE(demuxer_->SeekToTime(12000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
3084 ASSERT_NE(demuxer_->SeekToTime(-1000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
3085 }
3086
3087 /**
3088 * @tc.name: Demuxer_ReadSample_1802
3089 * @tc.desc: copy current sample to buffer(webm)
3090 * @tc.type: FUNC
3091 */
3092 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1802, TestSize.Level1)
3093 {
3094 InitResource(g_webmPath, LOCAL);
3095 ASSERT_NE(source_, nullptr);
3096 ASSERT_NE(format_, nullptr);
3097 ASSERT_NE(demuxer_, nullptr);
3098 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
3099 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
3100 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
3101 ASSERT_NE(demuxer_->SelectTrackByID(-1), AV_ERR_OK);
3102 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
3103 ASSERT_NE(sharedMem_, nullptr);
3104 ASSERT_TRUE(SetInitValue());
3105 while (!isEOS(eosFlag_)) {
3106 for (auto idx : selectedTrackIds_) {
3107 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
3108 CountFrames(idx);
3109 }
3110 }
3111 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
3112 printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]);
3113 ASSERT_EQ(frames_[0], 602);
3114 ASSERT_EQ(frames_[1], 594);
3115 ASSERT_EQ(keyFrames_[0], 5);
3116 ASSERT_EQ(keyFrames_[1], 594);
3117 RemoveValue();
3118 ASSERT_EQ(demuxer_->UnselectTrackByID(0), AV_ERR_OK);
3119 ASSERT_EQ(demuxer_->UnselectTrackByID(1), AV_ERR_OK);
3120 ASSERT_EQ(demuxer_->UnselectTrackByID(3), AV_ERR_OK);
3121 ASSERT_EQ(demuxer_->UnselectTrackByID(-1), AV_ERR_OK);
3122 ASSERT_EQ(demuxer_->Destroy(), AV_ERR_OK);
3123 }
3124
3125 /**
3126 * @tc.name: Demuxer_SeekToTime_1802
3127 * @tc.desc: seek to the specified time(webm)
3128 * @tc.type: FUNC
3129 */
3130 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1802, TestSize.Level1)
3131 {
3132 InitResource(g_webmPath, LOCAL);
3133 ASSERT_TRUE(SetInitValue());
3134 for (auto idx : selectedTrackIds_) {
3135 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
3136 }
3137 list<int64_t> toPtsList = {0, 4500, 7000, 2000, 6000}; // ms
3138 vector<int32_t> videoVals = {602, 602, 602, 218, 346, 346, 90, 218, 218, 474, 602, 474, 218, 346, 218};
3139 vector<int32_t> audioVals = {593, 593, 593, 224, 351, 351, 96, 224, 224, 472, 593, 472, 224, 351, 224};
3140 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
3141 ASSERT_NE(sharedMem_, nullptr);
3142 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
3143 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
3144 ret_ = demuxer_->SeekToTime(*toPts, *mode);
3145 if (ret_ != AV_ERR_OK) {
3146 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
3147 continue;
3148 }
3149 ReadData();
3150 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
3151 printf("time = %" PRId64 " | frames_[1]=%d\n", *toPts, frames_[1]);
3152 ASSERT_EQ(frames_[0], videoVals[numbers_]);
3153 ASSERT_EQ(frames_[1], audioVals[numbers_]);
3154 numbers_ += 1;
3155 RemoveValue();
3156 selectedTrackIds_.clear();
3157 }
3158 }
3159 ASSERT_NE(demuxer_->SeekToTime(12000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
3160 ASSERT_NE(demuxer_->SeekToTime(-1000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
3161 }
3162
3163 /**
3164 * @tc.name: Demuxer_ReadSample_1803
3165 * @tc.desc: copy current sample to buffer(mts)
3166 * @tc.type: FUNC
3167 */
3168 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1803, TestSize.Level1)
3169 {
3170 InitResource(g_mtsPath, LOCAL);
3171 ASSERT_NE(source_, nullptr);
3172 ASSERT_NE(format_, nullptr);
3173 ASSERT_NE(demuxer_, nullptr);
3174 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
3175 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
3176 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
3177 ASSERT_NE(demuxer_->SelectTrackByID(-1), AV_ERR_OK);
3178 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
3179 ASSERT_NE(sharedMem_, nullptr);
3180 ASSERT_TRUE(SetInitValue());
3181 while (!isEOS(eosFlag_)) {
3182 for (auto idx : selectedTrackIds_) {
3183 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
3184 CountFrames(idx);
3185 }
3186 }
3187 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
3188 printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]);
3189 ASSERT_EQ(frames_[0], 602);
3190 ASSERT_EQ(frames_[1], 314);
3191 ASSERT_EQ(keyFrames_[0], 3);
3192 ASSERT_EQ(keyFrames_[1], 314);
3193 RemoveValue();
3194 ASSERT_EQ(demuxer_->UnselectTrackByID(0), AV_ERR_OK);
3195 ASSERT_EQ(demuxer_->UnselectTrackByID(1), AV_ERR_OK);
3196 ASSERT_EQ(demuxer_->UnselectTrackByID(3), AV_ERR_OK);
3197 ASSERT_EQ(demuxer_->UnselectTrackByID(-1), AV_ERR_OK);
3198 ASSERT_EQ(demuxer_->Destroy(), AV_ERR_OK);
3199 }
3200
3201 /**
3202 * @tc.name: Demuxer_SeekToTime_1803
3203 * @tc.desc: seek to the specified time(mts)
3204 * @tc.type: FUNC
3205 */
3206 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1803, TestSize.Level1)
3207 {
3208 InitResource(g_mtsPath, LOCAL);
3209 ASSERT_TRUE(SetInitValue());
3210 for (auto idx : selectedTrackIds_) {
3211 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
3212 }
3213 list<int64_t> toPtsList = {0, 4500, 7000, 2000, 6000}; // ms
3214 vector<int32_t> videoVals = {602, 602, 602, 330, 330, 330, 180, 180, 180, 480, 480, 480, 240, 240, 240};
3215 vector<int32_t> audioVals = {314, 314, 314, 174, 174, 174, 96, 96, 96, 252, 252, 252, 127, 127, 127};
3216 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
3217 ASSERT_NE(sharedMem_, nullptr);
3218 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
3219 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
3220 ret_ = demuxer_->SeekToTime(*toPts, *mode);
3221 if (ret_ != AV_ERR_OK) {
3222 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
3223 continue;
3224 }
3225 ReadData();
3226 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
3227 printf("time = %" PRId64 " | frames_[1]=%d\n", *toPts, frames_[1]);
3228 ASSERT_EQ(frames_[0], videoVals[numbers_]);
3229 ASSERT_EQ(frames_[1], audioVals[numbers_]);
3230 numbers_ += 1;
3231 RemoveValue();
3232 selectedTrackIds_.clear();
3233 }
3234 }
3235 ASSERT_NE(demuxer_->SeekToTime(12000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
3236 ASSERT_NE(demuxer_->SeekToTime(-1000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
3237 }
3238
3239 /**
3240 * @tc.name: Demuxer_ReadSample_1804
3241 * @tc.desc: copy current sample to buffer(vob)
3242 * @tc.type: FUNC
3243 */
3244 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1804, TestSize.Level1)
3245 {
3246 InitResource(g_vobPath, LOCAL);
3247 ASSERT_NE(source_, nullptr);
3248 ASSERT_NE(format_, nullptr);
3249 ASSERT_NE(demuxer_, nullptr);
3250 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
3251 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
3252 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
3253 ASSERT_NE(demuxer_->SelectTrackByID(-1), AV_ERR_OK);
3254 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
3255 ASSERT_NE(sharedMem_, nullptr);
3256 ASSERT_TRUE(SetInitValue());
3257 while (!isEOS(eosFlag_)) {
3258 for (auto idx : selectedTrackIds_) {
3259 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
3260 CountFrames(idx);
3261 }
3262 }
3263 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
3264 printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]);
3265 ASSERT_EQ(frames_[0], 602);
3266 ASSERT_EQ(frames_[1], 314);
3267 ASSERT_EQ(keyFrames_[0], 51);
3268 ASSERT_EQ(keyFrames_[1], 314);
3269 RemoveValue();
3270 ASSERT_EQ(demuxer_->UnselectTrackByID(0), AV_ERR_OK);
3271 ASSERT_EQ(demuxer_->UnselectTrackByID(1), AV_ERR_OK);
3272 ASSERT_EQ(demuxer_->UnselectTrackByID(3), AV_ERR_OK);
3273 ASSERT_EQ(demuxer_->UnselectTrackByID(-1), AV_ERR_OK);
3274 ASSERT_EQ(demuxer_->Destroy(), AV_ERR_OK);
3275 }
3276
3277 /**
3278 * @tc.name: Demuxer_SeekToTime_1804
3279 * @tc.desc: seek to the specified time(vob)
3280 * @tc.type: FUNC
3281 */
3282 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1804, TestSize.Level1)
3283 {
3284 InitResource(g_vobPath, LOCAL);
3285 ASSERT_TRUE(SetInitValue());
3286 for (auto idx : selectedTrackIds_) {
3287 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
3288 }
3289 list<int64_t> toPtsList = {0, 4500, 7000, 2000, 6000}; // ms
3290 vector<int32_t> videoVals = {602, 602, 602, 331, 334, 331, 182, 182, 182, 482, 482, 482, 242, 242, 242};
3291 vector<int32_t> audioVals = {313, 313, 313, 194, 195, 194, 115, 115, 115, 271, 271, 271, 147, 147, 147};
3292 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
3293 ASSERT_NE(sharedMem_, nullptr);
3294 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
3295 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
3296 ret_ = demuxer_->SeekToTime(*toPts, *mode);
3297 if (ret_ != AV_ERR_OK) {
3298 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
3299 continue;
3300 }
3301 ReadData();
3302 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
3303 printf("time = %" PRId64 " | frames_[1]=%d\n", *toPts, frames_[1]);
3304 ASSERT_EQ(frames_[0], videoVals[numbers_]);
3305 ASSERT_EQ(frames_[1], audioVals[numbers_]);
3306 numbers_ += 1;
3307 RemoveValue();
3308 selectedTrackIds_.clear();
3309 }
3310 }
3311 ASSERT_NE(demuxer_->SeekToTime(12000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
3312 ASSERT_NE(demuxer_->SeekToTime(-1000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
3313 }
3314
3315 /**
3316 * @tc.name: Demuxer_ReadSample_1805
3317 * @tc.desc: copy current sample to buffer(m2ts)
3318 * @tc.type: FUNC
3319 */
3320 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1805, TestSize.Level1)
3321 {
3322 InitResource(g_m2tsPath, LOCAL);
3323 ASSERT_NE(source_, nullptr);
3324 ASSERT_NE(format_, nullptr);
3325 ASSERT_NE(demuxer_, nullptr);
3326 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
3327 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
3328 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
3329 ASSERT_NE(demuxer_->SelectTrackByID(-1), AV_ERR_OK);
3330 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
3331 ASSERT_NE(sharedMem_, nullptr);
3332 ASSERT_TRUE(SetInitValue());
3333 while (!isEOS(eosFlag_)) {
3334 for (auto idx : selectedTrackIds_) {
3335 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
3336 CountFrames(idx);
3337 }
3338 }
3339 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
3340 printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]);
3341 ASSERT_EQ(frames_[0], 602);
3342 ASSERT_EQ(frames_[1], 314);
3343 ASSERT_EQ(keyFrames_[0], 51);
3344 ASSERT_EQ(keyFrames_[1], 314);
3345 RemoveValue();
3346 ASSERT_EQ(demuxer_->UnselectTrackByID(0), AV_ERR_OK);
3347 ASSERT_EQ(demuxer_->UnselectTrackByID(1), AV_ERR_OK);
3348 ASSERT_EQ(demuxer_->UnselectTrackByID(3), AV_ERR_OK);
3349 ASSERT_EQ(demuxer_->UnselectTrackByID(-1), AV_ERR_OK);
3350 ASSERT_EQ(demuxer_->Destroy(), AV_ERR_OK);
3351 }
3352
3353 /**
3354 * @tc.name: Demuxer_SeekToTime_1805
3355 * @tc.desc: seek to the specified time(m2ts)
3356 * @tc.type: FUNC
3357 */
3358 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1805, TestSize.Level1)
3359 {
3360 InitResource(g_m2tsPath, LOCAL);
3361 ASSERT_TRUE(SetInitValue());
3362 for (auto idx : selectedTrackIds_) {
3363 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
3364 }
3365 list<int64_t> toPtsList = {0, 4500, 7000, 2000, 6000}; // ms
3366 vector<int32_t> videoVals = {602, 602, 602, 331, 331, 331, 181, 181, 181, 481, 481, 481, 241, 241, 241};
3367 vector<int32_t> audioVals = {314, 314, 314, 174, 174, 174, 96, 96, 96, 252, 252, 252, 127, 127, 127};
3368 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
3369 ASSERT_NE(sharedMem_, nullptr);
3370 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
3371 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
3372 ret_ = demuxer_->SeekToTime(*toPts, *mode);
3373 if (ret_ != AV_ERR_OK) {
3374 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
3375 continue;
3376 }
3377 ReadData();
3378 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
3379 printf("time = %" PRId64 " | frames_[1]=%d\n", *toPts, frames_[1]);
3380 ASSERT_EQ(frames_[0], videoVals[numbers_]);
3381 ASSERT_EQ(frames_[1], audioVals[numbers_]);
3382 numbers_ += 1;
3383 RemoveValue();
3384 selectedTrackIds_.clear();
3385 }
3386 }
3387 ASSERT_NE(demuxer_->SeekToTime(12000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
3388 ASSERT_NE(demuxer_->SeekToTime(-1000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
3389 }
3390
3391 /**
3392 * @tc.name: Demuxer_ReadSample_1806
3393 * @tc.desc: copy current sample to buffer(trp)
3394 * @tc.type: FUNC
3395 */
3396 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1806, TestSize.Level1)
3397 {
3398 InitResource(g_trpPath, LOCAL);
3399 ASSERT_NE(source_, nullptr);
3400 ASSERT_NE(format_, nullptr);
3401 ASSERT_NE(demuxer_, nullptr);
3402 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
3403 ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
3404 ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
3405 ASSERT_NE(demuxer_->SelectTrackByID(-1), AV_ERR_OK);
3406 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
3407 ASSERT_NE(sharedMem_, nullptr);
3408 ASSERT_TRUE(SetInitValue());
3409 while (!isEOS(eosFlag_)) {
3410 for (auto idx : selectedTrackIds_) {
3411 ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
3412 CountFrames(idx);
3413 }
3414 }
3415 printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
3416 printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]);
3417 ASSERT_EQ(frames_[0], 242);
3418 ASSERT_EQ(frames_[1], 315);
3419 ASSERT_EQ(keyFrames_[0], 11);
3420 ASSERT_EQ(keyFrames_[1], 315);
3421 RemoveValue();
3422 ASSERT_EQ(demuxer_->UnselectTrackByID(0), AV_ERR_OK);
3423 ASSERT_EQ(demuxer_->UnselectTrackByID(1), AV_ERR_OK);
3424 ASSERT_EQ(demuxer_->UnselectTrackByID(3), AV_ERR_OK);
3425 ASSERT_EQ(demuxer_->UnselectTrackByID(-1), AV_ERR_OK);
3426 ASSERT_EQ(demuxer_->Destroy(), AV_ERR_OK);
3427 }
3428
3429 /**
3430 * @tc.name: Demuxer_SeekToTime_1806
3431 * @tc.desc: seek to the specified time(trp)
3432 * @tc.type: FUNC
3433 */
3434 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1806, TestSize.Level1)
3435 {
3436 InitResource(g_trpPath, LOCAL);
3437 ASSERT_TRUE(SetInitValue());
3438 for (auto idx : selectedTrackIds_) {
3439 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
3440 }
3441 list<int64_t> toPtsList = {0, 4500, 7000, 2000, 6000}; // ms
3442 vector<int32_t> videoVals = {242, 242, 242, 133, 133, 133, 73, 73, 73, 193, 193, 193, 97, 97, 97};
3443 vector<int32_t> audioVals = {315, 315, 315, 175, 175, 175, 97, 97, 97, 253, 253, 253, 128, 128, 128};
3444 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
3445 ASSERT_NE(sharedMem_, nullptr);
3446 for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
3447 for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
3448 ret_ = demuxer_->SeekToTime(*toPts, *mode);
3449 if (ret_ != AV_ERR_OK) {
3450 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
3451 continue;
3452 }
3453 ReadData();
3454 printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
3455 printf("time = %" PRId64 " | frames_[1]=%d\n", *toPts, frames_[1]);
3456 ASSERT_EQ(frames_[0], videoVals[numbers_]);
3457 ASSERT_EQ(frames_[1], audioVals[numbers_]);
3458 numbers_ += 1;
3459 RemoveValue();
3460 selectedTrackIds_.clear();
3461 }
3462 }
3463 ASSERT_NE(demuxer_->SeekToTime(12000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
3464 ASSERT_NE(demuxer_->SeekToTime(-1000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
3465 }
3466
3467 /**
3468 * @tc.name: Demuxer_SeekToTime_1806
3469 * @tc.desc: seek to the specified time(trp)
3470 * @tc.type: FUNC
3471 */
3472 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1807, TestSize.Level1)
3473 {
3474 InitResource(g_flvPath, LOCAL);
3475 ASSERT_TRUE(SetInitValue());
3476 for (auto idx : selectedTrackIds_) {
3477 ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
3478 }
3479 list<int64_t> toPtsList = {0, 2466}; // ms
3480 vector<int32_t> videoVals = {76, 76, 76, 0, 76, 0};
3481 vector<int32_t> audioVals = {107, 107, 107, 0, 107, 0};
3482 sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
3483 ASSERT_NE(sharedMem_, nullptr);
3484 SeekTest(toPtsList, seekModes, {videoVals, audioVals});
3485 ASSERT_TRUE(seekTestFlag_);
3486 }
3487
3488 /**
3489 * @tc.number : Demuxer_GetReservedBuffer_1000
3490 * @tc.name : demux MP4 muxed by avmuxer,check user reserved buffer
3491 * @tc.desc : function test
3492 */
3493 HWTEST_F(DemuxerUnitTest, Demuxer_GetReservedBuffer_1000, TestSize.Level0)
3494 {
3495 InitResource(g_reservedMp4Path, LOCAL);
3496 ASSERT_TRUE(initStatus_);
3497 std::string stringVal = "";
3498 uint8_t *metaBuffer = nullptr;
3499 size_t bufferLen = 0;
3500 auto userformat = source_->GetUserData();
3501 ASSERT_TRUE(userformat->GetBuffer("com.openharmony.test", &metaBuffer, bufferLen));
3502 std::vector<uint8_t> metaVec(metaBuffer, metaBuffer + bufferLen);
3503 std::vector<uint8_t> expVec =
3504 {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 16, 17, 18, 19, 20, 100, 200, 255};
3505 ASSERT_TRUE(metaVec == expVec);
3506 }
3507
3508 /**
3509 * @tc.number : Demuxer_GetAIGCString_1000
3510 * @tc.name : check AIGC info
3511 * @tc.desc : function test
3512 */
3513 HWTEST_F(DemuxerUnitTest, Demuxer_GetAIGCString_1000, TestSize.Level0)
3514 {
3515 InitResource(g_aigcStrMp4Path, LOCAL);
3516 ASSERT_TRUE(initStatus_);
3517 std::string stringVal = "";
3518 auto userformat = source_->GetSourceFormat();
3519 ASSERT_TRUE(userformat->GetStringValue(MediaDescriptionKey::MD_KEY_AIGC, stringVal));
3520 printf("AIGC key:%s\nvalue:%s\n", MediaDescriptionKey::MD_KEY_AIGC.data(), stringVal.c_str());
3521 ASSERT_TRUE(AIGC_TEST_STR2 == stringVal);
3522 }
3523
3524 /**
3525 * @tc.number : Demuxer_GetAIGCString_1100
3526 * @tc.name : check AIGC info
3527 * @tc.desc : function test
3528 */
3529 HWTEST_F(DemuxerUnitTest, Demuxer_GetAIGCString_1100, TestSize.Level0)
3530 {
3531 InitResource(g_aigcStrM4aPath, LOCAL);
3532 ASSERT_TRUE(initStatus_);
3533 std::string stringVal = "";
3534 auto userformat = source_->GetSourceFormat();
3535 ASSERT_TRUE(userformat->GetStringValue(MediaDescriptionKey::MD_KEY_AIGC, stringVal));
3536 printf("AIGC key:%s\nvalue:%s\n", MediaDescriptionKey::MD_KEY_AIGC.data(), stringVal.c_str());
3537 ASSERT_TRUE(AIGC_TEST_STR1 == stringVal);
3538 }
3539
3540 /**
3541 * @tc.number : Demuxer_GetAIGCString_1200
3542 * @tc.name : check AIGC info
3543 * @tc.desc : function test
3544 */
3545 HWTEST_F(DemuxerUnitTest, Demuxer_GetAIGCString_1200, TestSize.Level0)
3546 {
3547 InitResource(g_aigcStrM4vPath, LOCAL);
3548 ASSERT_TRUE(initStatus_);
3549 std::string stringVal = "";
3550 auto userformat = source_->GetSourceFormat();
3551 ASSERT_TRUE(userformat->GetStringValue(MediaDescriptionKey::MD_KEY_AIGC, stringVal));
3552 printf("AIGC key:%s\nvalue:%s\n", MediaDescriptionKey::MD_KEY_AIGC.data(), stringVal.c_str());
3553 ASSERT_TRUE(AIGC_TEST_STR1 == stringVal);
3554 }
3555
3556 /**
3557 * @tc.number : Demuxer_GetAIGCString_1300
3558 * @tc.name : check AIGC info
3559 * @tc.desc : function test
3560 */
3561 HWTEST_F(DemuxerUnitTest, Demuxer_GetAIGCString_1300, TestSize.Level0)
3562 {
3563 InitResource(g_aigcStrMovPath, LOCAL);
3564 ASSERT_TRUE(initStatus_);
3565 std::string stringVal = "";
3566 auto userformat = source_->GetSourceFormat();
3567 ASSERT_TRUE(userformat->GetStringValue(MediaDescriptionKey::MD_KEY_AIGC, stringVal));
3568 printf("AIGC key:%s\nvalue:%s\n", MediaDescriptionKey::MD_KEY_AIGC.data(), stringVal.c_str());
3569 ASSERT_TRUE(AIGC_TEST_STR1 == stringVal);
3570 }
3571
3572 /**
3573 * @tc.number : Demuxer_GetAIGCString_1400
3574 * @tc.name : check AIGC info
3575 * @tc.desc : function test
3576 */
3577 HWTEST_F(DemuxerUnitTest, Demuxer_GetAIGCString_1400, TestSize.Level0)
3578 {
3579 InitResource(g_aigcStrFlvPath, LOCAL);
3580 ASSERT_TRUE(initStatus_);
3581 std::string stringVal = "";
3582 auto userformat = source_->GetSourceFormat();
3583 ASSERT_TRUE(userformat->GetStringValue(MediaDescriptionKey::MD_KEY_AIGC, stringVal));
3584 printf("AIGC key:%s\nvalue:%s\n", MediaDescriptionKey::MD_KEY_AIGC.data(), stringVal.c_str());
3585 ASSERT_TRUE(AIGC_TEST_STR2 == stringVal);
3586 }
3587
3588 /**
3589 * @tc.number : Demuxer_GetAIGCString_1500
3590 * @tc.name : check AIGC info
3591 * @tc.desc : function test
3592 */
3593 HWTEST_F(DemuxerUnitTest, Demuxer_GetAIGCString_1500, TestSize.Level0)
3594 {
3595 InitResource(g_aigcStrMkvPath, LOCAL);
3596 ASSERT_TRUE(initStatus_);
3597 std::string stringVal = "";
3598 auto userformat = source_->GetSourceFormat();
3599 ASSERT_TRUE(userformat->GetStringValue(MediaDescriptionKey::MD_KEY_AIGC, stringVal));
3600 printf("AIGC key:%s\nvalue:%s\n", MediaDescriptionKey::MD_KEY_AIGC.data(), stringVal.c_str());
3601 ASSERT_TRUE(AIGC_TEST_STR2 == stringVal);
3602 }
3603
3604 /**
3605 * @tc.number : Demuxer_GetAIGCString_1600
3606 * @tc.name : check AIGC info
3607 * @tc.desc : function test
3608 */
3609 HWTEST_F(DemuxerUnitTest, Demuxer_GetAIGCString_1600, TestSize.Level0)
3610 {
3611 InitResource(g_aigcStrAviPath, LOCAL);
3612 ASSERT_TRUE(initStatus_);
3613 std::string stringVal = "";
3614 auto userformat = source_->GetSourceFormat();
3615 ASSERT_TRUE(userformat->GetStringValue(MediaDescriptionKey::MD_KEY_AIGC, stringVal));
3616 printf("AIGC key:%s\nvalue:%s\n", MediaDescriptionKey::MD_KEY_AIGC.data(), stringVal.c_str());
3617 ASSERT_TRUE(AIGC_TEST_STR3 == stringVal);
3618 }
3619
3620 } // namespace
3621