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 URI false
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 string TEST_URI_PATH2 = "http://192.168.3.11:8080/share/";
42 
43 list<SeekMode> seekModes = {SeekMode::SEEK_NEXT_SYNC, SeekMode::SEEK_PREVIOUS_SYNC,
44     SeekMode::SEEK_CLOSEST_SYNC};
45 string g_mp4Uri = TEST_URI_PATH + string("test_264_B_Gop25_4sec_cover.mp4");
46 string g_mp4Uri2 = TEST_URI_PATH + string("test_mpeg2_B_Gop25_4sec.mp4");
47 string g_mp4Uri4 = TEST_URI_PATH + string("zero_track.mp4");
48 string g_mkvUri2 = TEST_URI_PATH + string("h264_opus_4sec.mkv");
49 string g_tsUri = TEST_URI_PATH + string("test_mpeg2_Gop25_4sec.ts");
50 string g_aacUri = TEST_URI_PATH + string("audio/aac_44100_1.aac");
51 string g_flacUri = TEST_URI_PATH + string("audio/flac_48000_1_cover.flac");
52 string g_m4aUri = TEST_URI_PATH + string("audio/m4a_48000_1.m4a");
53 string g_mp3Uri = TEST_URI_PATH + string("audio/mp3_48000_1_cover.mp3");
54 string g_oggUri = TEST_URI_PATH + string("audio/ogg_48000_1.ogg");
55 string g_wavUri = TEST_URI_PATH + string("audio/wav_48000_1.wav");
56 string g_amrUri = TEST_URI_PATH + string("audio/amr_nb_8000_1.amr");
57 string g_amrUri2 = TEST_URI_PATH + string("audio/amr_wb_16000_1.amr");
58 string g_audioVividUri = TEST_URI_PATH + string("2obj_44100Hz_16bit_32k.m4a");
59 string g_apeUri = TEST_URI_PATH + string("ape_test.ape");
60 string g_flvUri = TEST_URI_PATH + string("h264.flv");
61 string g_fmp4AvcUri = TEST_URI_PATH + string("h264_fmp4.mp4");
62 string g_fmp4m4vUri = TEST_URI_PATH + string("h264_fmp4.m4v");
63 string g_fmp4m4aUri = TEST_URI_PATH + string("audio/h264_fmp4.m4a");
64 string g_hls = TEST_URI_PATH2 + string("index_264.m3u8");
65 string g_srt = TEST_URI_PATH + string("subtitle.srt");
66 string g_mp4VvcUri = TEST_URI_PATH + string("vvc.mp4");
67 string g_mp4VvcPath = TEST_FILE_PATH + string("vvc.mp4");
68 
69 std::map<std::string, std::map<std::string, std::vector<int32_t>>> infoMap = {
70     {"ape",        {{"frames", {7}}, {"kFrames", {7}}}},
71 };
72 
73 /**
74  * @tc.name: Demuxer_CreateDemuxer_2000
75  * @tc.desc: create demuxer(URI)
76  * @tc.type: FUNC
77  */
78 HWTEST_F(DemuxerUnitTest, Demuxer_CreateDemuxer_2000, TestSize.Level1)
79 {
80     printf("---- %s ------\n", g_mp4Uri.data());
81     source_ = AVSourceMockFactory::CreateSourceWithURI(const_cast<char*>(g_mp4Uri.data()));
82     ASSERT_NE(source_, nullptr);
83     demuxer_ = AVDemuxerMockFactory::CreateDemuxer(source_);
84     ASSERT_NE(demuxer_, nullptr);
85 }
86 
87 /**
88  * @tc.name: Demuxer_CreateDemuxer_2010
89  * @tc.desc: repeatedly create demuxer
90  * @tc.type: FUNC
91  */
92 HWTEST_F(DemuxerUnitTest, Demuxer_CreateDemuxer_2010, TestSize.Level1)
93 {
94     printf("---- %s ------\n", g_mp4Uri.data());
95     source_ = AVSourceMockFactory::CreateSourceWithURI(const_cast<char*>(g_mp4Uri.data()));
96     ASSERT_NE(source_, nullptr);
97     demuxer_ = AVDemuxerMockFactory::CreateDemuxer(source_);
98     ASSERT_NE(demuxer_, nullptr);
99     demuxer_ = AVDemuxerMockFactory::CreateDemuxer(source_);
100     ASSERT_NE(demuxer_, nullptr);
101 }
102 
103 /**
104  * @tc.name: Demuxer_CreateDemuxer_2020
105  * @tc.desc: create demuxer
106  * @tc.type: FUNC
107  */
108 HWTEST_F(DemuxerUnitTest, Demuxer_CreateDemuxer_2300, TestSize.Level1)
109 {
110     printf("---- %s ------\n", g_mp4Uri4.data());
111     source_ = AVSourceMockFactory::CreateSourceWithURI(const_cast<char*>(g_mp4Uri4.data()));
112     ASSERT_NE(source_, nullptr);
113     demuxer_ = AVDemuxerMockFactory::CreateDemuxer(source_);
114     ASSERT_NE(demuxer_, nullptr);
115 }
116 
117 /**
118  * @tc.name: Demuxer_UnselectTrackByID_2000
119  * @tc.desc: select and remove track by ID
120  * @tc.type: FUNC
121  */
122 HWTEST_F(DemuxerUnitTest, Demuxer_UnselectTrackByID_2000, TestSize.Level1)
123 {
124     printf("---- %s ------\n", g_mp4Uri.data());
125     source_ = AVSourceMockFactory::CreateSourceWithURI(const_cast<char*>(g_mp4Uri.data()));
126     ASSERT_NE(source_, nullptr);
127     demuxer_ = AVDemuxerMockFactory::CreateDemuxer(source_);
128     ASSERT_NE(demuxer_, nullptr);
129     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
130     ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
131     ASSERT_NE(demuxer_->SelectTrackByID(3), AV_ERR_OK);
132     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
133     ASSERT_NE(demuxer_->SelectTrackByID(-1), AV_ERR_OK);
134     ASSERT_EQ(demuxer_->UnselectTrackByID(1), AV_ERR_OK);
135     ASSERT_EQ(demuxer_->UnselectTrackByID(3), AV_ERR_OK);
136     ASSERT_EQ(demuxer_->UnselectTrackByID(-1), AV_ERR_OK);
137 }
138 
139 /**
140  * @tc.name: Demuxer_ReadSample_2000
141  * @tc.desc: copy current sample to buffer
142  * @tc.type: FUNC
143  */
144 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_2000, TestSize.Level1)
145 {
146     InitResource(g_mp4Uri, URI);
147     ASSERT_TRUE(initStatus_);
148     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
149     ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
150     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
151     ASSERT_NE(sharedMem_, nullptr);
152     SetInitValue();
153     while (!isEOS(eosFlag_)) {
154         for (auto idx : selectedTrackIds_) {
155             ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
156             CountFrames(idx);
157         }
158     }
159     printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
160     printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]);
161     ASSERT_EQ(frames_[0], 103);
162     ASSERT_EQ(frames_[1], 174);
163     ASSERT_EQ(keyFrames_[0], 5);
164     ASSERT_EQ(keyFrames_[1], 174);
165     RemoveValue();
166 }
167 
168 /**
169  * @tc.name: Demuxer_ReadSample_2010
170  * @tc.desc: copy current sample to buffer
171  * @tc.type: FUNC
172  */
173 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_2010, TestSize.Level1)
174 {
175     printf("---- %s ------\n", g_mp4Uri.data());
176     source_ = AVSourceMockFactory::CreateSourceWithURI(const_cast<char*>(g_mp4Uri.data()));
177     ASSERT_NE(source_, nullptr);
178     demuxer_ = AVDemuxerMockFactory::CreateDemuxer(source_);
179     ASSERT_NE(demuxer_, nullptr);
180     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
181     ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
182     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
183     ASSERT_NE(sharedMem_, nullptr);
184     uint32_t idx = 4;
185     ASSERT_NE(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
186 }
187 
188 /**
189  * @tc.name: Demuxer_ReadSample_2020
190  * @tc.desc: copy current sample to buffer
191  * @tc.type: FUNC
192  */
193 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_2020, TestSize.Level1)
194 {
195     printf("---- %s ------\n", g_mp4Uri.data());
196     source_ = AVSourceMockFactory::CreateSourceWithURI(const_cast<char*>(g_mp4Uri.data()));
197     ASSERT_NE(source_, nullptr);
198     demuxer_ = AVDemuxerMockFactory::CreateDemuxer(source_);
199     ASSERT_NE(demuxer_, nullptr);
200     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
201     ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
202     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
203     ASSERT_NE(sharedMem_, nullptr);
204     uint32_t idx = -1;
205     ASSERT_NE(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
206 }
207 
208 /**
209  * @tc.name: Demuxer_ReadSample_2030
210  * @tc.desc: copy current sample to buffer
211  * @tc.type: FUNC
212  */
213 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_2030, TestSize.Level1)
214 {
215     InitResource(g_mp4Uri, URI);
216     ASSERT_TRUE(initStatus_);
217     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
218     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
219     ASSERT_NE(sharedMem_, nullptr);
220     int32_t vkeyFrames = 0;
221     int32_t vframes = 0;
222     flag_ = AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_NONE;
223     while (!(flag_ & AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_EOS)) {
224         ASSERT_EQ(demuxer_->ReadSample(0, sharedMem_, &info_, flag_), AV_ERR_OK);
225         if (flag_ & AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_EOS) {
226             break;
227         }
228         if (flag_ & AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_SYNC_FRAME) {
229             vkeyFrames++;
230             vframes++;
231         } else if ((flag_ & AVCodecBufferFlag::AVCODEC_BUFFER_FLAG_NONE) == 0) {
232             vframes++;
233         }
234     }
235     printf("vframes=%d | vkFrames=%d\n", vframes, vkeyFrames);
236     ASSERT_EQ(vframes, 103);
237     ASSERT_EQ(vkeyFrames, 5);
238 }
239 
240 /**
241  * @tc.name: Demuxer_ReadSample_2040
242  * @tc.desc: copy current sample to buffer
243  * @tc.type: FUNC
244  */
245 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_2040, TestSize.Level1)
246 {
247     InitResource(g_mp4Uri2, URI);
248     ASSERT_TRUE(initStatus_);
249     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
250     ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
251     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
252     ASSERT_NE(sharedMem_, nullptr);
253     SetInitValue();
254     while (!isEOS(eosFlag_)) {
255         for (auto idx : selectedTrackIds_) {
256             ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
257             CountFrames(idx);
258         }
259     }
260     printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
261     printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]);
262     ASSERT_EQ(frames_[0], 103);
263     ASSERT_EQ(frames_[1], 174);
264     ASSERT_EQ(keyFrames_[0], 5);
265     ASSERT_EQ(keyFrames_[1], 174);
266     RemoveValue();
267 }
268 
269 /**
270  * @tc.name: Demuxer_ReadSample_2060
271  * @tc.desc: copy current sample to buffer
272  * @tc.type: FUNC
273  */
274 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_2060, TestSize.Level1)
275 {
276     InitResource(g_mkvUri2, URI);
277     ASSERT_TRUE(initStatus_);
278     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
279     ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
280     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
281     ASSERT_NE(sharedMem_, nullptr);
282     SetInitValue();
283     while (!isEOS(eosFlag_)) {
284         for (auto idx : selectedTrackIds_) {
285             ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
286             CountFrames(idx);
287         }
288     }
289     printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
290     printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]);
291     ASSERT_EQ(frames_[0], 240);
292     ASSERT_EQ(frames_[1], 199);
293     ASSERT_EQ(keyFrames_[0], 4);
294     ASSERT_EQ(keyFrames_[1], 199);
295     RemoveValue();
296 }
297 
298 /**
299  * @tc.name: Demuxer_ReadSample_2070
300  * @tc.desc: copy current sample to buffer
301  * @tc.type: FUNC
302  */
303 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_2070, TestSize.Level1)
304 {
305     InitResource(g_tsUri, URI);
306     ASSERT_TRUE(initStatus_);
307     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
308     ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
309     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
310     ASSERT_NE(sharedMem_, nullptr);
311     SetInitValue();
312     while (!isEOS(eosFlag_)) {
313         for (auto idx : selectedTrackIds_) {
314             ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
315             CountFrames(idx);
316         }
317     }
318     printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
319     printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]);
320     ASSERT_EQ(frames_[0], 103);
321     ASSERT_EQ(frames_[1], 174);
322     ASSERT_EQ(keyFrames_[0], 5);
323     ASSERT_EQ(keyFrames_[1], 174);
324     RemoveValue();
325 }
326 
327 /**
328  * @tc.name: Demuxer_ReadSample_2080
329  * @tc.desc: copy current sample to buffer
330  * @tc.type: FUNC
331  */
332 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_2080, TestSize.Level1)
333 {
334     InitResource(g_aacUri, URI);
335     ASSERT_TRUE(initStatus_);
336     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
337     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
338     ASSERT_NE(sharedMem_, nullptr);
339     SetInitValue();
340     uint32_t idx = 0;
341     while (!isEOS(eosFlag_)) {
342         ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
343         CountFrames(idx);
344     }
345     printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
346     ASSERT_EQ(frames_[0], 1293);
347     ASSERT_EQ(keyFrames_[0], 1293);
348     RemoveValue();
349 }
350 
351 /**
352  * @tc.name: Demuxer_ReadSample_2090
353  * @tc.desc: copy current sample to buffer
354  * @tc.type: FUNC
355  */
356 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_2090, TestSize.Level1)
357 {
358     InitResource(g_flacUri, URI);
359     ASSERT_TRUE(initStatus_);
360     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
361     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
362     ASSERT_NE(sharedMem_, nullptr);
363     SetInitValue();
364     uint32_t idx = 0;
365     while (!isEOS(eosFlag_)) {
366         ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
367         CountFrames(idx);
368     }
369     printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
370     ASSERT_EQ(frames_[0], 313);
371     ASSERT_EQ(keyFrames_[0], 313);
372     RemoveValue();
373 }
374 
375 /**
376  * @tc.name: Demuxer_ReadSample_2100
377  * @tc.desc: copy current sample to buffer
378  * @tc.type: FUNC
379  */
380 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_2100, TestSize.Level1)
381 {
382     InitResource(g_m4aUri, URI);
383     ASSERT_TRUE(initStatus_);
384     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
385     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
386     ASSERT_NE(sharedMem_, nullptr);
387     SetInitValue();
388     uint32_t idx = 0;
389     while (!isEOS(eosFlag_)) {
390         ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
391         CountFrames(idx);
392     }
393     printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
394     ASSERT_EQ(frames_[0], 1408);
395     ASSERT_EQ(keyFrames_[0], 1408);
396     RemoveValue();
397 }
398 
399 /**
400  * @tc.name: Demuxer_ReadSample_2110
401  * @tc.desc: copy current sample to buffer
402  * @tc.type: FUNC
403  */
404 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_2110, TestSize.Level1)
405 {
406     InitResource(g_mp3Uri, URI);
407     ASSERT_TRUE(initStatus_);
408     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
409     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
410     ASSERT_NE(sharedMem_, nullptr);
411     SetInitValue();
412     uint32_t idx = 0;
413     while (!isEOS(eosFlag_)) {
414         ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
415         CountFrames(idx);
416     }
417     printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
418     ASSERT_EQ(frames_[0], 1251);
419     ASSERT_EQ(keyFrames_[0], 1251);
420     RemoveValue();
421 }
422 
423 /**
424  * @tc.name: Demuxer_ReadSample_2120
425  * @tc.desc: copy current sample to buffer
426  * @tc.type: FUNC
427  */
428 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_2120, TestSize.Level1)
429 {
430     InitResource(g_oggUri, URI);
431     ASSERT_TRUE(initStatus_);
432     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
433     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
434     ASSERT_NE(sharedMem_, nullptr);
435     SetInitValue();
436     uint32_t idx = 0;
437     while (!isEOS(eosFlag_)) {
438         ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
439         CountFrames(idx);
440     }
441     printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
442     ASSERT_EQ(frames_[0], 1598);
443     ASSERT_EQ(keyFrames_[0], 1598);
444     RemoveValue();
445 }
446 
447 /**
448  * @tc.name: Demuxer_ReadSample_2130
449  * @tc.desc: copy current sample to buffer
450  * @tc.type: FUNC
451  */
452 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_2130, TestSize.Level1)
453 {
454     InitResource(g_wavUri, URI);
455     ASSERT_TRUE(initStatus_);
456     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
457     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
458     ASSERT_NE(sharedMem_, nullptr);
459     SetInitValue();
460     uint32_t idx = 0;
461     while (!isEOS(eosFlag_)) {
462         ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
463         CountFrames(idx);
464     }
465     printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
466     ASSERT_EQ(frames_[0], 704);
467     ASSERT_EQ(keyFrames_[0], 704);
468     RemoveValue();
469 }
470 
471 /**
472  * @tc.name: Demuxer_ReadSample_2140
473  * @tc.desc: copy current sample to buffer
474  * @tc.type: FUNC
475  */
476 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_2140, TestSize.Level1)
477 {
478     InitResource(g_amrUri, URI);
479     ASSERT_TRUE(initStatus_);
480     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
481     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
482     ASSERT_NE(sharedMem_, nullptr);
483     SetInitValue();
484     uint32_t idx = 0;
485     while (!isEOS(eosFlag_)) {
486         ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
487         CountFrames(idx);
488     }
489     printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
490     ASSERT_EQ(frames_[0], 1501);
491     ASSERT_EQ(keyFrames_[0], 1501);
492     RemoveValue();
493 }
494 
495 /**
496  * @tc.name: Demuxer_ReadSample_1233
497  * @tc.desc: copy current sample to buffer
498  * @tc.type: FUNC
499  */
500 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1233, TestSize.Level1)
501 {
502     InitResource(g_fmp4AvcUri, URI);
503     ASSERT_TRUE(initStatus_);
504     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
505     ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
506     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
507     ASSERT_NE(sharedMem_, nullptr);
508     SetInitValue();
509     while (!isEOS(eosFlag_)) {
510         for (auto idx : selectedTrackIds_) {
511             ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
512             CountFrames(idx);
513         }
514     }
515     printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
516     printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]);
517     ASSERT_EQ(frames_[0], 602);
518     ASSERT_EQ(frames_[1], 433);
519     ASSERT_EQ(keyFrames_[0], 3);
520     ASSERT_EQ(keyFrames_[1], 433);
521     RemoveValue();
522 }
523 
524 /**
525  * @tc.name: Demuxer_ReadSample_1233
526  * @tc.desc: copy current sample to buffer
527  * @tc.type: FUNC
528  */
529 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1235, TestSize.Level1)
530 {
531     InitResource(g_fmp4m4vUri, URI);
532     ASSERT_TRUE(initStatus_);
533     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
534     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
535     ASSERT_NE(sharedMem_, nullptr);
536     SetInitValue();
537     while (!isEOS(eosFlag_)) {
538         for (auto idx : selectedTrackIds_) {
539             ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
540             CountFrames(idx);
541         }
542     }
543     printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
544     ASSERT_EQ(frames_[0], 602);
545     ASSERT_EQ(keyFrames_[0], 3);
546     RemoveValue();
547 }
548 
549 /**
550  * @tc.name: Demuxer_ReadSample_1233
551  * @tc.desc: copy current sample to buffer
552  * @tc.type: FUNC
553  */
554 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1237, TestSize.Level1)
555 {
556     InitResource(g_fmp4m4aUri, URI);
557     ASSERT_TRUE(initStatus_);
558     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
559     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
560     ASSERT_NE(sharedMem_, nullptr);
561     SetInitValue();
562     while (!isEOS(eosFlag_)) {
563         for (auto idx : selectedTrackIds_) {
564             ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
565             CountFrames(idx);
566         }
567     }
568     printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
569     ASSERT_EQ(frames_[0], 433);
570     ASSERT_EQ(keyFrames_[0], 433);
571     RemoveValue();
572 }
573 
574 /**
575  * @tc.name: Demuxer_SeekToTime_2000
576  * @tc.desc: seek to the specified time
577  * @tc.type: FUNC
578  */
579 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2000, TestSize.Level1)
580 {
581     InitResource(g_mp4Uri, URI);
582     ASSERT_TRUE(initStatus_);
583     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
584     ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
585     list<int64_t> toPtsList = {0, 2000, 1920, 2160, 2200, 2440, 2600, 2700, 4080, 4100}; // ms
586     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,
587         47, 91, 47, 5, 5, 5, 5};
588     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,
589         28, 53, 28, 3, 3, 3, 3};
590     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
591     ASSERT_NE(sharedMem_, nullptr);
592     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
593         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
594             ret_ = demuxer_->SeekToTime(*toPts, *mode);
595             if (ret_ != AV_ERR_OK) {
596                 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
597                 continue;
598             }
599             ReadData();
600             printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
601             printf("time = %" PRId64 " | frames_[1]=%d | kFrames[1]=%d\n", *toPts, frames_[1], keyFrames_[1]);
602             ASSERT_EQ(frames_[0], videoVals[numbers_]);
603             ASSERT_EQ(frames_[1], audioVals[numbers_]);
604             numbers_ += 1;
605             RemoveValue();
606             selectedTrackIds_.clear();
607         }
608     }
609 }
610 
611 /**
612  * @tc.name: Demuxer_SeekToTime_2001
613  * @tc.desc: seek to the specified time
614  * @tc.type: FUNC
615  */
616 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2001, TestSize.Level1)
617 {
618     InitResource(g_mp4Uri, URI);
619     ASSERT_TRUE(initStatus_);
620     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
621     ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
622     list<int64_t> toPtsList = {-100, 1000000}; // ms
623     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
624         sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
625         ASSERT_NE(sharedMem_, nullptr);
626         ret_ = demuxer_->SeekToTime(*toPts, SeekMode::SEEK_NEXT_SYNC);
627         ASSERT_NE(ret_, AV_ERR_OK);
628         ret_ = demuxer_->SeekToTime(*toPts, SeekMode::SEEK_PREVIOUS_SYNC);
629         ASSERT_NE(ret_, AV_ERR_OK);
630         ret_ = demuxer_->SeekToTime(*toPts, SeekMode::SEEK_CLOSEST_SYNC);
631         ASSERT_NE(ret_, AV_ERR_OK);
632         if (sharedMem_ != nullptr) {
633             sharedMem_->Destory();
634             sharedMem_ = nullptr;
635         }
636     }
637 }
638 
639 /**
640  * @tc.name: Demuxer_SeekToTime_2002
641  * @tc.desc: seek to the specified time
642  * @tc.type: FUNC
643  */
644 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2002, TestSize.Level1)
645 {
646     InitResource(g_mp4Uri, URI);
647     ASSERT_TRUE(initStatus_);
648     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
649     ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
650     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
651     ASSERT_NE(sharedMem_, nullptr);
652     int readNum = 121;
653     int64_t seekTime = 0;
654     ReadData(readNum, seekTime);
655     seekTime = (seekTime / 1000) + 500;
656     ASSERT_EQ(demuxer_->SeekToTime(seekTime, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
657     ASSERT_EQ(demuxer_->ReadSample(0, sharedMem_, &info_, flag_), AV_ERR_OK);
658     printf("time = %" PRId64 " | pts = %" PRId64 "\n", seekTime, info_.presentationTimeUs);
659 }
660 
661 /**
662  * @tc.name: Demuxer_SeekToTime_2010
663  * @tc.desc: seek to the specified time
664  * @tc.type: FUNC
665  */
666 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2010, TestSize.Level1)
667 {
668     InitResource(g_mp4Uri2, URI);
669     ASSERT_TRUE(initStatus_);
670     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
671     ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
672     list<int64_t> toPtsList = {0, 3000, 2040, 1880, 1960, 2400, 2720, 2830, 4040, 4100}; // ms
673     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,
674         48, 91, 48, 8, 8, 8, 8};
675     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,
676         30, 54, 30, 6, 6, 6, 6};
677     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
678     ASSERT_NE(sharedMem_, nullptr);
679     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
680         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
681             ret_ = demuxer_->SeekToTime(*toPts, *mode);
682             if (ret_ != AV_ERR_OK) {
683                 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
684                 continue;
685             }
686             ReadData();
687             printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
688             printf("time = %" PRId64 " | frames_[1]=%d | kFrames[1]=%d\n", *toPts, frames_[1], keyFrames_[1]);
689             ASSERT_EQ(frames_[0], videoVals[numbers_]);
690             ASSERT_EQ(frames_[1], audioVals[numbers_]);
691             numbers_ += 1;
692             RemoveValue();
693             selectedTrackIds_.clear();
694         }
695     }
696 }
697 
698 /**
699  * @tc.name: Demuxer_SeekToTime_2040
700  * @tc.desc: seek to the specified time
701  * @tc.type: FUNC
702  */
703 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2040, TestSize.Level1)
704 {
705     InitResource(g_mkvUri2, URI);
706     ASSERT_TRUE(initStatus_);
707     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
708     ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
709     list<int64_t> toPtsList = {0, 1000, 1017, 1500, 1700, 1940, 3983, 1983, 3990}; // ms
710     vector<int32_t> audioVals = {199, 199, 199, 149, 149, 149, 99, 149, 149, 99, 149, 149, 99, 149, 99, 99, 149, 99,
711         49, 49, 99, 149, 99, 49, 49};
712     vector<int32_t> videoVals = {240, 240, 240, 180, 180, 180, 120, 180, 180, 120, 180, 180, 120, 180, 120, 120, 180,
713         120, 60, 60, 120, 180, 120, 60, 60};
714     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
715     ASSERT_NE(sharedMem_, nullptr);
716     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
717         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
718             ret_ = demuxer_->SeekToTime(*toPts, *mode);
719             if (ret_ != AV_ERR_OK) {
720                 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
721                 continue;
722             }
723             ReadData();
724             printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
725             printf("time = %" PRId64 " | frames_[1]=%d | kFrames[1]=%d\n", *toPts, frames_[1], keyFrames_[1]);
726             ASSERT_EQ(frames_[0], videoVals[numbers_]);
727             ASSERT_EQ(frames_[1], audioVals[numbers_]);
728             numbers_ += 1;
729             RemoveValue();
730             selectedTrackIds_.clear();
731         }
732     }
733 }
734 
735 /**
736  * @tc.name: Demuxer_SeekToTime_2060
737  * @tc.desc: seek to the specified time
738  * @tc.type: FUNC
739  */
740 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2060, TestSize.Level1)
741 {
742     InitResource(g_tsUri, URI);
743     ASSERT_TRUE(initStatus_);
744     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
745     ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
746     list<int64_t> toPtsList = {0, 3480, 3640, 3320, 3000, 3100, 4120, 5520}; // ms
747     vector<int32_t> videoVals = {102, 102, 102, 15, 15, 15, 11, 11, 11, 19, 19, 19, 27, 27, 27, 24, 25, 25, 1, 1, 1};
748     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
749     ASSERT_NE(sharedMem_, nullptr);
750     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
751         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
752             ret_ = demuxer_->SeekToTime(*toPts, *mode);
753             if (ret_ != AV_ERR_OK) {
754                 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
755                 continue;
756             }
757             ReadData();
758             printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
759             ASSERT_EQ(frames_[0], videoVals[numbers_]);
760             numbers_ += 1;
761             RemoveValue();
762             selectedTrackIds_.clear();
763         }
764     }
765 }
766 
767 /**
768  * @tc.name: Demuxer_SeekToTime_2070
769  * @tc.desc: seek to the specified time
770  * @tc.type: FUNC
771  */
772 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2070, TestSize.Level1)
773 {
774     InitResource(g_aacUri, URI);
775     ASSERT_TRUE(initStatus_);
776     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
777     list<int64_t> toPtsList = {0, 10240, 10230, 10220, 30000, 30010}; // ms
778     vector<int32_t> audioVals = {1293, 1293, 1293, 852, 852, 852, 853, 853, 853, 853, 853, 853, 2, 2, 2, 1, 1, 1};
779     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
780     ASSERT_NE(sharedMem_, nullptr);
781     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
782         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
783             ret_ = demuxer_->SeekToTime(*toPts, *mode);
784             if (ret_ != AV_ERR_OK) {
785                 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
786                 continue;
787             }
788             ReadData();
789             printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
790             ASSERT_EQ(frames_[0], audioVals[numbers_]);
791             numbers_ += 1;
792             RemoveValue();
793             selectedTrackIds_.clear();
794         }
795     }
796 }
797 
798 /**
799  * @tc.name: Demuxer_SeekToTime_2080
800  * @tc.desc: seek to the specified time
801  * @tc.type: FUNC
802  */
803 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2080, TestSize.Level1)
804 {
805     InitResource(g_flacUri, URI);
806     ASSERT_TRUE(initStatus_);
807     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
808     list<int64_t> toPtsList = {0, 3072, 4031, 4035, 29952, 29953}; // ms
809     vector<int32_t> audioVals = {313, 313, 313, 281, 281, 281, 272, 272, 272, 271, 271, 271, 1, 1, 1, 2, 2, 2};
810     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
811     ASSERT_NE(sharedMem_, nullptr);
812     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
813         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
814             ret_ = demuxer_->SeekToTime(*toPts, *mode);
815             if (ret_ != AV_ERR_OK) {
816                 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
817                 continue;
818             }
819             ReadData();
820             printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
821             ASSERT_EQ(frames_[0], audioVals[numbers_]);
822             numbers_ += 1;
823             RemoveValue();
824             selectedTrackIds_.clear();
825         }
826     }
827 }
828 
829 /**
830  * @tc.name: Demuxer_SeekToTime_2090
831  * @tc.desc: seek to the specified time
832  * @tc.type: FUNC
833  */
834 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2090, TestSize.Level1)
835 {
836     InitResource(g_m4aUri, URI);
837     ASSERT_TRUE(initStatus_);
838     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
839     list<int64_t> toPtsList = {0, 14592, 15297, 15290, 29994, 29998}; // ms
840     vector<int32_t> audioVals = {1407, 1407, 1407, 723, 723, 723, 690, 690, 690, 691, 691, 691, 2, 2, 2, 1, 1, 1};
841     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
842     ASSERT_NE(sharedMem_, nullptr);
843     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
844         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
845             ret_ = demuxer_->SeekToTime(*toPts, *mode);
846             if (ret_ != AV_ERR_OK) {
847                 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
848                 continue;
849             }
850             ReadData();
851             printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
852             ASSERT_EQ(frames_[0], audioVals[numbers_]);
853             numbers_ += 1;
854             RemoveValue();
855             selectedTrackIds_.clear();
856         }
857     }
858 }
859 
860 /**
861  * @tc.name: Demuxer_SeekToTime_2100
862  * @tc.desc: seek to the specified time
863  * @tc.type: FUNC
864  */
865 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2100, TestSize.Level1)
866 {
867     InitResource(g_mp3Uri, URI);
868     ASSERT_TRUE(initStatus_);
869     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
870     list<int64_t> toPtsList = {0, 4128, 11980, 11990, 30000, 30010}; // ms
871     vector<int32_t> audioVals = {1251, 1251, 1251, 1079, 1079, 1079, 752, 752, 752, 752, 752, 752, 1, 1, 1, 1, 1, 1};
872     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
873     ASSERT_NE(sharedMem_, nullptr);
874     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
875         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
876             ret_ = demuxer_->SeekToTime(*toPts, *mode);
877             if (ret_ != AV_ERR_OK) {
878                 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
879                 continue;
880             }
881             ReadData();
882             printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
883             ASSERT_EQ(frames_[0], audioVals[numbers_]);
884             numbers_ += 1;
885             RemoveValue();
886             selectedTrackIds_.clear();
887         }
888     }
889 }
890 
891 /**
892  * @tc.name: Demuxer_SeekToTime_2110
893  * @tc.desc: seek to the specified time
894  * @tc.type: FUNC
895  */
896 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2110, TestSize.Level1)
897 {
898     InitResource(g_oggUri, URI);
899     ASSERT_TRUE(initStatus_);
900     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
901     list<int64_t> toPtsList = {0, 5868, 5548, 5292, 29992, 29999}; // ms
902     vector<int32_t> audioVals = {1598, 1598, 1598, 1357, 1357, 1357, 1357, 1357, 1357, 1357, 1357, 1357, 46, 46,
903         46, 46, 46, 46};
904     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
905     ASSERT_NE(sharedMem_, nullptr);
906     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
907         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
908             ret_ = demuxer_->SeekToTime(*toPts, *mode);
909             if (ret_ != AV_ERR_OK) {
910                 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
911                 continue;
912             }
913             ReadData();
914             printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
915             ASSERT_EQ(frames_[0], audioVals[numbers_]);
916             numbers_ += 1;
917             RemoveValue();
918             selectedTrackIds_.clear();
919         }
920     }
921 }
922 
923 /**
924  * @tc.name: Demuxer_SeekToTime_2120
925  * @tc.desc: seek to the specified time
926  * @tc.type: FUNC
927  */
928 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2120, TestSize.Level1)
929 {
930     InitResource(g_wavUri, URI);
931     ASSERT_TRUE(initStatus_);
932     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
933     list<int64_t> toPtsList = {0, 8576, 8566, 8578, 29994, 30000}; // ms
934     vector<int32_t> audioVals = {704, 704, 704, 503, 503, 503, 504, 504, 504, 503, 503, 503, 2, 2, 2, 1, 1, 1};
935     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
936     ASSERT_NE(sharedMem_, nullptr);
937     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
938         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
939             ret_ = demuxer_->SeekToTime(*toPts, *mode);
940             if (ret_ != AV_ERR_OK) {
941                 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
942                 continue;
943             }
944             ReadData();
945             printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
946             ASSERT_EQ(frames_[0], audioVals[numbers_]);
947             numbers_ += 1;
948             RemoveValue();
949             selectedTrackIds_.clear();
950         }
951     }
952 }
953 
954 /**
955  * @tc.name: Demuxer_SeekToTime_2130
956  * @tc.desc: seek to the specified time
957  * @tc.type: FUNC
958  */
959 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2130, TestSize.Level1)
960 {
961     InitResource(g_amrUri, URI);
962     ASSERT_TRUE(initStatus_);
963     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
964     list<int64_t> toPtsList = {0, 8560, 8550, 8570, 30000, 30900}; // ms
965     vector<int32_t> audioVals = {1501, 1501, 1501, 1073, 1073, 1073, 1074, 1074, 1074, 1073, 1073, 1073,
966         1, 1, 1, 1, 1, 1};
967     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
968     ASSERT_NE(sharedMem_, nullptr);
969     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
970         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
971             ret_ = demuxer_->SeekToTime(*toPts, *mode);
972             if (ret_ != AV_ERR_OK) {
973                 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
974                 continue;
975             }
976             ReadData();
977             printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
978             ASSERT_EQ(frames_[0], audioVals[numbers_]);
979             numbers_ += 1;
980             RemoveValue();
981             selectedTrackIds_.clear();
982         }
983     }
984 }
985 
986 /**
987  * @tc.name: Demuxer_SeekToTime_2140
988  * @tc.desc: seek to the specified time
989  * @tc.type: FUNC
990  */
991 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2140, TestSize.Level1)
992 {
993     InitResource(g_amrUri2, URI);
994     ASSERT_TRUE(initStatus_);
995     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
996     list<int64_t> toPtsList = {0, 11920, 11910, 11930, 29980, 30800}; // ms
997     vector<int32_t> audioVals = {1500, 1500, 1500, 904, 904, 904, 905, 905, 905, 904, 904, 904,
998         1, 1, 1, 1, 1, 1};
999     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1000     ASSERT_NE(sharedMem_, nullptr);
1001     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1002         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1003             ret_ = demuxer_->SeekToTime(*toPts, *mode);
1004             if (ret_ != AV_ERR_OK) {
1005                 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1006                 continue;
1007             }
1008             ReadData();
1009             printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
1010             ASSERT_EQ(frames_[0], audioVals[numbers_]);
1011             numbers_ += 1;
1012             RemoveValue();
1013             selectedTrackIds_.clear();
1014         }
1015     }
1016 }
1017 
1018 /**
1019  * @tc.name: Demuxer_SeekToTime_2150
1020  * @tc.desc: seek to the specified time(audioVivid m4a)
1021  * @tc.type: FUNC
1022  */
1023 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_2150, TestSize.Level1)
1024 {
1025     InitResource(g_audioVividUri, URI);
1026     ASSERT_TRUE(initStatus_);
1027     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1028     list<int64_t> toPtsList = {0, 10000, 8000, 12300, 25000, 29000, 30800, 33000}; // ms
1029     vector<int32_t> audioVals = {1380, 1380, 1380, 950, 950, 950, 1036, 1036, 1036, 851, 851, 851, 304, 304, 304,
1030         132, 132, 132, 54, 54, 54};
1031     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1032     ASSERT_NE(sharedMem_, nullptr);
1033     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1034         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1035             ret_ = demuxer_->SeekToTime(*toPts, *mode);
1036             if (ret_ != AV_ERR_OK) {
1037                 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1038                 continue;
1039             }
1040             ReadData();
1041             printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
1042             ASSERT_EQ(frames_[0], audioVals[numbers_]);
1043             numbers_ += 1;
1044             RemoveValue();
1045             selectedTrackIds_.clear();
1046         }
1047     }
1048     ASSERT_NE(demuxer_->SelectTrackByID(3), AV_ERR_OK);
1049     ASSERT_NE(demuxer_->SelectTrackByID(-1), AV_ERR_OK);
1050     ASSERT_EQ(demuxer_->UnselectTrackByID(3), AV_ERR_OK);
1051     ASSERT_EQ(demuxer_->UnselectTrackByID(-1), AV_ERR_OK);
1052     ASSERT_EQ(demuxer_->UnselectTrackByID(0), AV_ERR_OK);
1053 }
1054 
1055 /**
1056  * @tc.name: Demuxer_SeekToTime_21501
1057  * @tc.desc: seek to the file duration(audioVivid m4a)
1058  * @tc.type: FUNC
1059  */
1060 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_21501, TestSize.Level1)
1061 {
1062     InitResource(g_audioVividUri, URI);
1063     ASSERT_TRUE(initStatus_);
1064     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1065     list<int64_t> toPtsList = {32044}; // file duration ms
1066     vector<int32_t> audioVals = {1, 1, 1};
1067     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1068     ASSERT_NE(sharedMem_, nullptr);
1069     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1070         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1071             ret_ = demuxer_->SeekToTime(*toPts, *mode);
1072             ASSERT_EQ(ret_, AV_ERR_OK);
1073             ReadData();
1074             printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
1075             ASSERT_EQ(frames_[0], audioVals[numbers_]);
1076             numbers_ += 1;
1077             RemoveValue();
1078             selectedTrackIds_.clear();
1079         }
1080     }
1081 }
1082 
1083 /**
1084  * @tc.name: Demuxer_SeekToTime_1195
1085  * @tc.desc: seek to the specified time(two sound track mp4 uri)
1086  * @tc.type: FUNC
1087  */
1088 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1195, TestSize.Level1)
1089 {
1090     string path = TEST_URI_PATH + string("avcc_aac_mp3.mp4");
1091     InitResource(path, URI);
1092     ASSERT_TRUE(initStatus_);
1093     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1094     ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
1095     ASSERT_EQ(demuxer_->SelectTrackByID(2), AV_ERR_OK);
1096     list<int64_t> toPtsList = {0, 4500, 7000, 2000, 10000}; // ms
1097     vector<int32_t> videoVals = {602, 602, 602, 102, 352, 352, 102, 352, 102, 352, 602, 602, 102, 102};
1098     vector<int32_t> audioVals = {433, 433, 433, 74, 254, 254, 74, 254, 74, 253, 433, 433, 75, 75};
1099     vector<int32_t> audioVals2 = {417, 417, 417, 71, 245, 245, 71, 245, 71, 244, 417, 417, 72, 72};
1100     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1101     ASSERT_NE(sharedMem_, nullptr);
1102     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1103         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1104             ret_ = demuxer_->SeekToTime(*toPts, *mode);
1105             if (ret_ != AV_ERR_OK) {
1106                 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1107                 continue;
1108             }
1109             ReadData();
1110             printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
1111             printf("time = %" PRId64 " | frames_[1]=%d | kFrames[1]=%d\n", *toPts, frames_[1], keyFrames_[1]);
1112             printf("time = %" PRId64 " | frames_[2]=%d | kFrames[2]=%d\n", *toPts, frames_[2], keyFrames_[2]);
1113             ASSERT_EQ(frames_[0], videoVals[numbers_]);
1114             ASSERT_EQ(frames_[1], audioVals[numbers_]);
1115             ASSERT_EQ(frames_[2], audioVals2[numbers_]);
1116             numbers_ += 1;
1117             RemoveValue();
1118             selectedTrackIds_.clear();
1119         }
1120     }
1121     ASSERT_NE(demuxer_->SeekToTime(11000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1122     ASSERT_NE(demuxer_->SeekToTime(-1000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1123 }
1124 
1125 /**
1126  * @tc.name: Demuxer_ReadSample_1223
1127  * @tc.desc: copy current sample to buffer(ape)
1128  * @tc.type: FUNC
1129  */
1130 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1223, TestSize.Level1)
1131 {
1132     ReadSample(g_apeUri, URI);
1133     for (auto idx : selectedTrackIds_) {
1134         ASSERT_EQ(frames_[idx], infoMap["ape"]["frames"][idx]);
1135         ASSERT_EQ(keyFrames_[idx], infoMap["ape"]["kFrames"][idx]);
1136     }
1137     RemoveValue();
1138     selectedTrackIds_.clear();
1139 }
1140 
1141 /**
1142  * @tc.name: Demuxer_SeekToTime_1225
1143  * @tc.desc: seek to the specified time(two sound track ape local)
1144  * @tc.type: FUNC
1145  */
1146 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1225, TestSize.Level1)
1147 {
1148     InitResource(g_apeUri, URI);
1149     ASSERT_TRUE(initStatus_);
1150     SetInitValue();
1151     for (auto idx : selectedTrackIds_) {
1152         ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
1153     }
1154     list<int64_t> toPtsList = {0, 4500, 7000, 2000, 10000}; // ms
1155     vector<int32_t> audioVals = {7, 7, 7, 5, 5, 5, 3, 3, 3, 6, 6, 6, 2, 2, 2};
1156 
1157     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1158     ASSERT_NE(sharedMem_, nullptr);
1159     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1160         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1161             ret_ = demuxer_->SeekToTime(*toPts, *mode);
1162             if (ret_ != AV_ERR_OK) {
1163                 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1164                 continue;
1165             }
1166             ReadData();
1167             printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
1168             ASSERT_EQ(frames_[0], audioVals[numbers_]);
1169             numbers_ += 1;
1170             RemoveValue();
1171             selectedTrackIds_.clear();
1172         }
1173     }
1174     ASSERT_NE(demuxer_->SeekToTime(12000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1175     ASSERT_NE(demuxer_->SeekToTime(-1000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1176 }
1177 
1178 /**
1179  * @tc.name: Demuxer_SeekToTime_1205
1180  * @tc.desc: seek to the specified time(h264 flv uri)
1181  * @tc.type: FUNC
1182  */
1183 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1205, TestSize.Level1)
1184 {
1185     InitResource(g_flvUri, URI);
1186     ASSERT_TRUE(initStatus_);
1187     SetInitValue();
1188     for (auto idx : selectedTrackIds_) {
1189         ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
1190     }
1191     list<int64_t> toPtsList = {0, 1500, 1000, 1740, 1970, 2100}; // ms
1192     vector<int32_t> videoVals = {76, 76, 76, 0, 76, 0, 0, 76, 76, 0, 76, 0, 0, 76, 0, 0, 76, 0};
1193     vector<int32_t> audioVals = {107, 107, 107, 0, 107, 0, 0, 107, 107, 0, 107, 0, 0, 107, 0, 0, 107, 0};
1194     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1195     ASSERT_NE(sharedMem_, nullptr);
1196     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1197         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1198             ret_ = demuxer_->SeekToTime(*toPts, *mode);
1199             if (ret_ != AV_ERR_OK) {
1200                 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1201                 continue;
1202             }
1203             ReadData();
1204             printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
1205             printf("time = %" PRId64 " | frames_[1]=%d\n", *toPts, frames_[1]);
1206             ASSERT_EQ(frames_[0], videoVals[numbers_]);
1207             ASSERT_EQ(frames_[1], audioVals[numbers_]);
1208             numbers_ += 1;
1209             RemoveValue();
1210             selectedTrackIds_.clear();
1211         }
1212     }
1213     ASSERT_NE(demuxer_->SeekToTime(11000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1214     ASSERT_NE(demuxer_->SeekToTime(-1000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1215 }
1216 
1217 /**
1218  * @tc.name: Demuxer_SeekToTime_1230
1219  * @tc.desc: seek to the specified time(h264 fmp4 uri)
1220  * @tc.type: FUNC
1221  */
1222 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1230, TestSize.Level1)
1223 {
1224     InitResource(g_fmp4AvcUri, URI);
1225     ASSERT_TRUE(initStatus_);
1226     SetInitValue();
1227     for (auto idx : selectedTrackIds_) {
1228         ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
1229     }
1230     list<int64_t> toPtsList = {0, 4500, 7000, 2000}; // ms
1231     vector<int32_t> videoVals = {602, 602, 602, 102, 352, 352, 102, 352, 102, 352, 602, 602};
1232     vector<int32_t> audioVals = {433, 433, 433, 74, 254, 254, 74, 254, 74, 253, 433, 433};
1233     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1234     ASSERT_NE(sharedMem_, nullptr);
1235     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1236         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1237             ret_ = demuxer_->SeekToTime(*toPts, *mode);
1238             if (ret_ != AV_ERR_OK) {
1239                 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1240                 continue;
1241             }
1242             ReadData();
1243             printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
1244             printf("time = %" PRId64 " | frames_[1]=%d\n", *toPts, frames_[1]);
1245             ASSERT_EQ(frames_[0], videoVals[numbers_]);
1246             ASSERT_EQ(frames_[1], audioVals[numbers_]);
1247             numbers_ += 1;
1248             RemoveValue();
1249             selectedTrackIds_.clear();
1250         }
1251     }
1252     ASSERT_NE(demuxer_->SeekToTime(11000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1253     ASSERT_NE(demuxer_->SeekToTime(-1000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1254 }
1255 
1256 /**
1257  * @tc.name: Demuxer_SeekToTime_1240
1258  * @tc.desc: seek to the specified time(fmp4 m4v uri)
1259  * @tc.type: FUNC
1260  */
1261 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1240, TestSize.Level1)
1262 {
1263     InitResource(g_fmp4m4vUri, URI);
1264     ASSERT_TRUE(initStatus_);
1265     SetInitValue();
1266     for (auto idx : selectedTrackIds_) {
1267         ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
1268     }
1269     list<int64_t> toPtsList = {0, 4500, 7000, 2000}; // ms
1270     vector<int32_t> videoVals = {602, 602, 602, 102, 352, 352, 102, 352, 102, 352, 602, 602};
1271     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1272     ASSERT_NE(sharedMem_, nullptr);
1273     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1274         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1275             ret_ = demuxer_->SeekToTime(*toPts, *mode);
1276             if (ret_ != AV_ERR_OK) {
1277                 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1278                 continue;
1279             }
1280             ReadData();
1281             printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
1282             ASSERT_EQ(frames_[0], videoVals[numbers_]);
1283             numbers_ += 1;
1284             RemoveValue();
1285             selectedTrackIds_.clear();
1286         }
1287     }
1288     ASSERT_NE(demuxer_->SeekToTime(11000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1289     ASSERT_NE(demuxer_->SeekToTime(-1000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1290 }
1291 
1292 /**
1293  * @tc.name: Demuxer_SeekToTime_1241
1294  * @tc.desc: seek to the specified time(fmp4 m4a uri)
1295  * @tc.type: FUNC
1296  */
1297 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1241, TestSize.Level1)
1298 {
1299     InitResource(g_fmp4m4aUri, URI);
1300     ASSERT_TRUE(initStatus_);
1301     SetInitValue();
1302     for (auto idx : selectedTrackIds_) {
1303         ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
1304     }
1305     list<int64_t> toPtsList = {0, 4500, 7000, 2000}; // ms
1306     vector<int32_t> audioVals = {433, 433, 433, 240, 240, 240, 132, 132, 132, 348, 348, 348};
1307     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1308     ASSERT_NE(sharedMem_, nullptr);
1309     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1310         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1311             ret_ = demuxer_->SeekToTime(*toPts, *mode);
1312             if (ret_ != AV_ERR_OK) {
1313                 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1314                 continue;
1315             }
1316             ReadData();
1317             printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
1318             ASSERT_EQ(frames_[0], audioVals[numbers_]);
1319             numbers_ += 1;
1320             RemoveValue();
1321             selectedTrackIds_.clear();
1322         }
1323     }
1324     ASSERT_NE(demuxer_->SeekToTime(11000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1325     ASSERT_NE(demuxer_->SeekToTime(-1000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1326 }
1327 
1328 /**
1329  * @tc.name: Demuxer_ReadSample_1410
1330  * @tc.desc: copy current sample to buffer(h264 hls uri)
1331  * @tc.type: FUNC
1332  */
1333 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1410, TestSize.Level1)
1334 {
1335     if (g_hls.find(TEST_URI_PATH2) != std::string::npos) {
1336         return;
1337     }
1338     InitResource(g_hls, URI);
1339     ASSERT_TRUE(initStatus_);
1340     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1341     ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
1342     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1343     ASSERT_NE(sharedMem_, nullptr);
1344     SetInitValue();
1345     while (!isEOS(eosFlag_)) {
1346         for (auto idx : selectedTrackIds_) {
1347             ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
1348             CountFrames(idx);
1349         }
1350     }
1351     printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
1352     printf("frames_[1]=%d | kFrames[1]=%d\n", frames_[1], keyFrames_[1]);
1353     ASSERT_EQ(frames_[0], 602);
1354     ASSERT_EQ(frames_[1], 433);
1355     ASSERT_EQ(keyFrames_[0], 3);
1356     ASSERT_EQ(keyFrames_[1], 433);
1357     RemoveValue();
1358 }
1359 
1360 /**
1361  * @tc.name: Demuxer_SeekToTime_1411
1362  * @tc.desc: seek to the specified time(h264 hls uri)
1363  * @tc.type: FUNC
1364  */
1365 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1411, TestSize.Level1)
1366 {
1367     if (g_hls.find(TEST_URI_PATH2) != std::string::npos) {
1368         return;
1369     }
1370     InitResource(g_hls, URI);
1371     ASSERT_TRUE(initStatus_);
1372     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1373     ASSERT_EQ(demuxer_->SelectTrackByID(1), AV_ERR_OK);
1374     list<int64_t> toPtsList = {0, 4500, 7000, 2000, 10000}; // ms
1375     vector<int32_t> videoVals = {602, 602, 602, 102, 352, 352, 102, 352, 102, 352, 602, 602, 102, 102};
1376     vector<int32_t> audioVals = {433, 433, 433, 74, 254, 254, 74, 254, 74, 253, 433, 433, 75, 75};
1377     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1378     ASSERT_NE(sharedMem_, nullptr);
1379     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1380         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1381             ret_ = demuxer_->SeekToTime(*toPts, *mode);
1382             if (ret_ != AV_ERR_OK) {
1383                 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1384                 continue;
1385             }
1386             ReadData();
1387             printf("time = %" PRId64 " | frames_[0]=%d | kFrames[0]=%d\n", *toPts, frames_[0], keyFrames_[0]);
1388             printf("time = %" PRId64 " | frames_[1]=%d | kFrames[1]=%d\n", *toPts, frames_[1], keyFrames_[1]);
1389             ASSERT_EQ(frames_[0], videoVals[numbers_]);
1390             ASSERT_EQ(frames_[1], audioVals[numbers_]);
1391             numbers_ += 1;
1392             RemoveValue();
1393             selectedTrackIds_.clear();
1394         }
1395     }
1396     ASSERT_NE(demuxer_->SeekToTime(11000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1397     ASSERT_NE(demuxer_->SeekToTime(-1000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1398 }
1399 
1400 /**
1401  * @tc.name: Demuxer_ReadSample_3001
1402  * @tc.desc: copy current sample to buffer(srt)
1403  * @tc.type: FUNC
1404  */
1405 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_3001, TestSize.Level1)
1406 {
1407     InitResource(g_srt, URI);
1408     ASSERT_TRUE(initStatus_);
1409     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1410 
1411     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1412     ASSERT_NE(sharedMem_, nullptr);
1413     SetInitValue();
1414     while (!isEOS(eosFlag_)) {
1415         for (auto idx : selectedTrackIds_) {
1416             ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
1417             CountFrames(idx);
1418         }
1419     }
1420     printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
1421     ASSERT_EQ(frames_[0], 5);
1422     RemoveValue();
1423 }
1424 
1425 /**
1426  * @tc.name: Demuxer_SeekToTime_3001
1427  * @tc.desc: seek to the specified time(srt)
1428  * @tc.type: FUNC
1429  */
1430 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_3001, TestSize.Level1)
1431 {
1432     InitResource(g_srt, URI);
1433     ASSERT_TRUE(initStatus_);
1434     SetInitValue();
1435     for (auto idx : selectedTrackIds_) {
1436         ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
1437     }
1438     list<int64_t> toPtsList = {160, 2000, 4000, 7000}; // ms
1439     vector<int32_t> subVals = {5, 5, 5, 5, 5, 5, 4, 4, 4, 2, 2, 2};
1440     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1441     ASSERT_NE(sharedMem_, nullptr);
1442     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1443         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1444             ret_ = demuxer_->SeekToTime(*toPts, *mode);
1445             if (ret_ != AV_ERR_OK) {
1446                 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1447                 continue;
1448             }
1449             ReadData();
1450             printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
1451             ASSERT_EQ(frames_[0], subVals[numbers_]);
1452             numbers_ += 1;
1453             RemoveValue();
1454             selectedTrackIds_.clear();
1455         }
1456     }
1457 }
1458 
1459 /**
1460  * @tc.name: Demuxer_ReadSample_1611
1461  * @tc.desc: copy current sample to buffer(mp4 vvc)
1462  * @tc.type: FUNC
1463  */
1464 HWTEST_F(DemuxerUnitTest, Demuxer_ReadSample_1611, TestSize.Level1)
1465 {
1466     if (access(g_mp4VvcPath.c_str(), F_OK) != 0) {
1467         return;
1468     }
1469     InitResource(g_mp4VvcUri, URI);
1470     ASSERT_TRUE(initStatus_);
1471     ASSERT_EQ(demuxer_->SelectTrackByID(0), AV_ERR_OK);
1472     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1473     ASSERT_NE(sharedMem_, nullptr);
1474     SetInitValue();
1475     uint32_t idx = 0;
1476     while (!isEOS(eosFlag_)) {
1477         ASSERT_EQ(demuxer_->ReadSample(idx, sharedMem_, &info_, flag_), AV_ERR_OK);
1478         CountFrames(idx);
1479     }
1480     printf("frames_[0]=%d | kFrames[0]=%d\n", frames_[0], keyFrames_[0]);
1481     ASSERT_EQ(frames_[0], 600);
1482     ASSERT_EQ(keyFrames_[0], 10);
1483     RemoveValue();
1484 }
1485 
1486 /**
1487  * @tc.name: Demuxer_SeekToTime_1611
1488  * @tc.desc: seek to the specified time(mpv vvc uri)
1489  * @tc.type: FUNC
1490  */
1491 HWTEST_F(DemuxerUnitTest, Demuxer_SeekToTime_1611, TestSize.Level1)
1492 {
1493     if (access(g_mp4VvcPath.c_str(), F_OK) != 0) {
1494         return;
1495     }
1496     InitResource(g_mp4VvcUri, URI);
1497     ASSERT_TRUE(initStatus_);
1498     SetInitValue();
1499     for (auto idx : selectedTrackIds_) {
1500         ASSERT_EQ(demuxer_->SelectTrackByID(idx), AV_ERR_OK);
1501     }
1502     list<int64_t> toPtsList = {0, 4500, 7000, 2000}; // ms
1503     vector<int32_t> audioVals = {433, 433, 433, 240, 240, 240, 132, 132, 132, 348, 348, 348};
1504     sharedMem_ = AVMemoryMockFactory::CreateAVMemoryMock(bufferSize_);
1505     ASSERT_NE(sharedMem_, nullptr);
1506     for (auto toPts = toPtsList.begin(); toPts != toPtsList.end(); toPts++) {
1507         for (auto mode = seekModes.begin(); mode != seekModes.end(); mode++) {
1508             ret_ = demuxer_->SeekToTime(*toPts, *mode);
1509             if (ret_ != AV_ERR_OK) {
1510                 printf("seek failed, time = %" PRId64 " | ret = %d\n", *toPts, ret_);
1511                 continue;
1512             }
1513             ReadData();
1514             printf("time = %" PRId64 " | frames_[0]=%d\n", *toPts, frames_[0]);
1515             numbers_ += 1;
1516             RemoveValue();
1517             selectedTrackIds_.clear();
1518         }
1519     }
1520     ASSERT_NE(demuxer_->SeekToTime(11000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1521     ASSERT_NE(demuxer_->SeekToTime(-1000, SeekMode::SEEK_NEXT_SYNC), AV_ERR_OK);
1522 }
1523 } // namespace
1524