• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "gtest/gtest.h"
17 #include "demuxer_plugin_manager.h"
18 #include "stream_demuxer.h"
19 #include "plugin/plugin_manager_v2.h"
20 
21 using namespace OHOS;
22 using namespace OHOS::Media;
23 using namespace testing::ext;
24 using namespace testing;
25 using namespace std;
26 
27 namespace OHOS {
28 namespace Media {
29 
30 class DemuxerAsynInnerFuncTest : public testing::Test {
31 public:
32     // SetUpTestCase: Called before all test cases
33     static void SetUpTestCase(void);
34     // TearDownTestCase: Called after all test case
35     static void TearDownTestCase(void);
36     // SetUp: Called before each test cases
37     void SetUp(void);
38     // TearDown: Called after each test cases
39     void TearDown(void);
40 
41 protected:
42     std::shared_ptr<DataSourceImpl> dataSourceImpl_{ nullptr };
43 
44 private:
45     bool CreateDataSource(const std::string& filePath);
46     bool CreateDemuxerPluginByName(const std::string& typeName, const std::string& filePath, int probSize);
47     void RemoveValue();
48     bool CreateBufferSize();
49     void GetFrameNum(int32_t i);
50     void ThreadTask(std::shared_ptr<Plugins::DemuxerPlugin> demuxerPlugin, uint32_t timeout);
51     int streamId_ = 0;
52     std::map<uint32_t, uint32_t> frames_;
53     std::map<uint32_t, uint32_t> keyFrames_;
54     std::map<uint32_t, bool> eosFlag_;
55 
56     std::shared_ptr<Media::StreamDemuxer> realStreamDemuxer_{ nullptr };
57     std::shared_ptr<Media::MediaSource> mediaSource_{ nullptr };
58     std::shared_ptr<Media::Source> realSource_{ nullptr };
59     std::shared_ptr<Media::PluginBase> pluginBase_{ nullptr };
60     std::shared_ptr<AVBuffer> avBuf_{ nullptr };
61     uint32_t indexVid = 0;
62     uint32_t indexAud = 0;
63     int32_t readPos = 0;
64     int32_t unSelectTrack = 0;
65     bool isVideoEosFlagForSave = false;
66     bool isAudioEosFlagForSave = false;
67     int32_t videoTrackIdx = 0;
68     int32_t audioTrackIdx = 1;
69     uint32_t videoIndexForRead = 0;
70     uint32_t audioIndexForRead = 0;
71 };
72 
73 static const int DEF_PROB_SIZE = 16 * 1024;
74 constexpr int32_t THOUSAND = 1000.0;
75 constexpr int32_t TIME_0 = 0;
76 constexpr int32_t TRACKNUM_2 = 2;
77 static const std::string DEMUXER_PLUGIN_NAME_FLV = "avdemux_flv";
78 
79 
80 static const string TEST_FILE_PATH = "/data/test/media/";
81 static const string TEST_FILE_URI_FLV = TEST_FILE_PATH + "avc_aac_60.flv";
82 static const string TEST_FILE_URI_FLV_1 = TEST_FILE_PATH + "avc_60.flv";
83 static const string TEST_FILE_URI_FLV_2 = TEST_FILE_PATH + "avc_mp3.flv";
SetUpTestCase(void)84 void DemuxerAsynInnerFuncTest::SetUpTestCase(void) {}
85 
TearDownTestCase(void)86 void DemuxerAsynInnerFuncTest::TearDownTestCase(void) {}
87 
SetUp(void)88 void DemuxerAsynInnerFuncTest::SetUp(void)
89 {
90 }
91 
TearDown(void)92 void DemuxerAsynInnerFuncTest::TearDown(void)
93 {
94     dataSourceImpl_ = nullptr;
95 }
96 
CreateBufferSize()97 bool DemuxerAsynInnerFuncTest::CreateBufferSize()
98 {
99     uint32_t buffersize = 1024*1024;
100     std::shared_ptr<AVAllocator> allocator = AVAllocatorFactory::CreateSharedAllocator(MemoryFlag::MEMORY_READ_WRITE);
101     avBuf_ = OHOS::Media::AVBuffer::CreateAVBuffer(allocator, buffersize);
102     if (!avBuf_) {
103         return false;
104     }
105     return true;
106 }
CreateDataSource(const std::string & filePath)107 bool DemuxerAsynInnerFuncTest::CreateDataSource(const std::string &filePath)
108 {
109     mediaSource_ = std::make_shared<MediaSource>(filePath);
110     realSource_ = std::make_shared<Source>();
111     realSource_->SetSource(mediaSource_);
112 
113     realStreamDemuxer_ = std::make_shared<StreamDemuxer>();
114     realStreamDemuxer_->SetSourceType(Plugins::SourceType::SOURCE_TYPE_FD);
115     realStreamDemuxer_->SetSource(realSource_);
116     realStreamDemuxer_->Init(filePath);
117 
118     realStreamDemuxer_->SetDemuxerState(streamId_, DemuxerState::DEMUXER_STATE_PARSE_HEADER);
119     dataSourceImpl_ = std::make_shared<DataSourceImpl>(realStreamDemuxer_, streamId_);
120     dataSourceImpl_->stream_ = realStreamDemuxer_;
121     realSource_->NotifyInitSuccess();
122 
123     return true;
124 }
125 
CreateDemuxerPluginByName(const std::string & typeName,const std::string & filePath,int probSize)126 bool DemuxerAsynInnerFuncTest::CreateDemuxerPluginByName(const std::string& typeName, const std::string& filePath,
127     int probSize)
128 {
129     if (!CreateDataSource(filePath)) {
130         printf("false return: CreateDataSource is fail\n");
131         return false;
132     }
133     pluginBase_ = Plugins::PluginManagerV2::Instance().CreatePluginByName(typeName);
134     if (!(pluginBase_ != nullptr)) {
135         printf("false return: pluginBase_ == nullptr\n");
136         return false;
137     }
138     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
139     if (!(demuxerPlugin->SetDataSourceWithProbSize(dataSourceImpl_, probSize) == Status::OK)) {
140         printf("false return: demuxerPlugin->SetDataSourceWithProbSize(dataSourceImpl_, probSize) != Status::OK\n");
141         return false;
142     }
143     realStreamDemuxer_->SetDemuxerState(streamId_, DemuxerState::DEMUXER_STATE_PARSE_FIRST_FRAME);
144 
145     return true;
146 }
147 
RemoveValue()148 void DemuxerAsynInnerFuncTest::RemoveValue()
149 {
150     if (!frames_.empty()) {
151         frames_.clear();
152     }
153     if (!keyFrames_.empty()) {
154         keyFrames_.clear();
155     }
156     if (!eosFlag_.empty()) {
157         eosFlag_.clear();
158     }
159 }
160 
GetFrameNum(int32_t i)161 void DemuxerAsynInnerFuncTest::GetFrameNum(int32_t i)
162 {
163     if (avBuf_->flag_ == MediaAVCodec::AVCODEC_BUFFER_FLAG_EOS) {
164         if (i == videoTrackIdx) {
165             isVideoEosFlagForSave = true;
166         } else {
167             isAudioEosFlagForSave = true;
168         }
169     } else {
170         if (i == videoTrackIdx) {
171             videoIndexForRead++;
172         } else {
173             audioIndexForRead++;
174         }
175     }
176 }
177 
178 
ThreadTask(std::shared_ptr<Plugins::DemuxerPlugin> demuxerPlugin,uint32_t timeout)179 void DemuxerAsynInnerFuncTest::ThreadTask(std::shared_ptr<Plugins::DemuxerPlugin> demuxerPlugin, uint32_t timeout)
180 {
181     int64_t realtime = 0;
182     while (!isAudioEosFlagForSave || !isVideoEosFlagForSave) {
183         for (int32_t i = 0; i < TRACKNUM_2; i++) {
184             if (((i == videoTrackIdx) && isVideoEosFlagForSave) || ((i == audioTrackIdx) && isAudioEosFlagForSave)) {
185                 continue;
186             }
187             auto ret = demuxerPlugin->ReadSample(i, avBuf_, timeout);
188             while (ret == Status::ERROR_WAIT_TIMEOUT) {
189                 ret = demuxerPlugin->ReadSample(i, avBuf_, timeout);
190             }
191             ASSERT_EQ(ret, Status::OK);
192             GetFrameNum(i);
193             if (isVideoEosFlagForSave && isAudioEosFlagForSave) {
194                 ASSERT_EQ(demuxerPlugin->SeekTo(indexVid, TIME_0 / THOUSAND, Plugins::SeekMode::SEEK_NEXT_SYNC,
195                     realtime), Status::OK);
196             }
197         }
198     }
199 }
200 /**
201  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0010
202  * @tc.name      : trackId为 UNINT32_T_MAX
203  * @tc.desc      : func test
204  */
205 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0010, TestSize.Level0)
206 {
207     indexVid = 4294967295;
208     uint32_t timeout = 100;
209     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
210     ASSERT_NE(pluginBase_, nullptr);
211     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
212     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
213     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
214     ASSERT_EQ(CreateBufferSize(), true);
215     ASSERT_EQ(demuxerPlugin->ReadSample(indexVid, avBuf_, timeout), Status::ERROR_INVALID_PARAMETER);
216 }
217 
218 /**
219  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0020
220  * @tc.name      : buffer为nullptr
221  * @tc.desc      : func test
222  */
223 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0020, TestSize.Level0)
224 {
225     indexVid = 0;
226     uint32_t timeout = 100;
227     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
228     ASSERT_NE(pluginBase_, nullptr);
229     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
230     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
231     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
232     ASSERT_EQ(demuxerPlugin->ReadSample(indexVid, nullptr, timeout), Status::ERROR_INVALID_PARAMETER);
233 }
234 
235 /**
236  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0030
237  * @tc.name      : timeout为 UNINT32_T_MAX
238  * @tc.desc      : func test
239  */
240 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0030, TestSize.Level0)
241 {
242     indexVid = 0;
243     uint32_t timeout = 4294967295;
244     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
245     ASSERT_NE(pluginBase_, nullptr);
246     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
247     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
248     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
249     ASSERT_EQ(CreateBufferSize(), true);
250     ASSERT_EQ(demuxerPlugin->ReadSample(indexVid, avBuf_, timeout), Status::OK);
251 }
252 
253 /**
254  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0040
255  * @tc.name      : trackId为 UNINT32_T_MAX
256  * @tc.desc      : func test
257  */
258 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0040, TestSize.Level0)
259 {
260     indexVid = 4294967295;
261     uint32_t timeout = 100;
262     int32_t size = 0;
263     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
264     ASSERT_NE(pluginBase_, nullptr);
265     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
266     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
267     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
268     ASSERT_EQ(demuxerPlugin->GetNextSampleSize(indexVid, size, timeout), Status::ERROR_UNKNOWN);
269 }
270 
271 /**
272  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0050
273  * @tc.name      : timeout为 UNINT32_T_MAX
274  * @tc.desc      : func test
275  */
276 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0050, TestSize.Level0)
277 {
278     indexVid = 0;
279     uint32_t timeout = 4294967295;
280     int32_t size = 0;
281     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
282     ASSERT_NE(pluginBase_, nullptr);
283     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
284     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
285     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
286     ASSERT_EQ(demuxerPlugin->GetNextSampleSize(indexVid, size, timeout), Status::OK);
287 }
288 
289 /**
290  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0060
291  * @tc.name      : trackID为 UNINT32_T_MAX
292  * @tc.desc      : func test
293  */
294 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0060, TestSize.Level0)
295 {
296     indexVid = 4294967295;
297     int64_t pts = 0;
298     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
299     ASSERT_NE(pluginBase_, nullptr);
300     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
301     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
302     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
303     ASSERT_EQ(demuxerPlugin->GetLastPTSByTrackId(indexVid, pts), Status::ERROR_INVALID_PARAMETER);
304 }
305 
306 /**
307  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0070
308  * @tc.name      : ReadSample全流程
309  * @tc.desc      : func test
310  */
311 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0070, TestSize.Level1)
312 {
313     uint32_t timeout = 100;
314     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
315     ASSERT_NE(pluginBase_, nullptr);
316     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
317     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
318     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
319     ASSERT_EQ(CreateBufferSize(), true);
320     while (!isAudioEosFlagForSave || !isVideoEosFlagForSave) {
321         for (int32_t i = 0;i < 2; i++) {
322             if (((i == videoTrackIdx) && isVideoEosFlagForSave) || ((i == audioTrackIdx) && isAudioEosFlagForSave)) {
323                 continue;
324             }
325             ASSERT_EQ(demuxerPlugin->ReadSample(i, avBuf_, timeout), Status::OK);
326             GetFrameNum(i);
327         }
328     }
329     ASSERT_EQ(videoIndexForRead, 307);
330     ASSERT_EQ(audioIndexForRead, 318);
331 }
332 /**
333  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0080
334  * @tc.name      : ReadSample,一条轨,timeout = 0
335  * @tc.desc      : func test
336  */
337 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0080, TestSize.Level1)
338 {
339     indexVid = 0;
340     uint32_t timeout = 0;
341     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV_1, DEF_PROB_SIZE), true);
342     ASSERT_NE(pluginBase_, nullptr);
343     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
344     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
345     ASSERT_EQ(CreateBufferSize(), true);
346     ASSERT_EQ(demuxerPlugin->ReadSample(indexVid, avBuf_, timeout), Status::OK);
347     ASSERT_EQ(demuxerPlugin->ReadSample(indexVid, avBuf_, timeout), Status::ERROR_WAIT_TIMEOUT);
348 }
349 /**
350  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0090
351  * @tc.name      : read , timeout > 1帧读取时间
352  * @tc.desc      : func test
353  */
354 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0090, TestSize.Level1)
355 {
356     indexVid = 0;
357     uint32_t timeout = 100;
358     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
359     ASSERT_NE(pluginBase_, nullptr);
360     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
361     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
362     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
363     ASSERT_EQ(CreateBufferSize(), true);
364     ASSERT_EQ(demuxerPlugin->ReadSample(indexVid, avBuf_, timeout), Status::OK);
365 }
366 /**
367  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0100
368  * @tc.name      : GetNextSampleSize,读取视频轨
369  * @tc.desc      : func test
370  */
371 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0100, TestSize.Level1)
372 {
373     int32_t size = 0;
374     indexVid = 0;
375     uint32_t timeout = 100;
376     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
377     ASSERT_NE(pluginBase_, nullptr);
378     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
379     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
380     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
381     ASSERT_EQ(CreateBufferSize(), true);
382     ASSERT_EQ(demuxerPlugin->GetNextSampleSize(indexVid, size, timeout), Status::OK);
383     ASSERT_EQ(size, 136906);
384 }
385 
386 /**
387  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0110
388  * @tc.name      : GetNextSampleSize,读取音频轨
389  * @tc.desc      : func test
390  */
391 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0110, TestSize.Level1)
392 {
393     int32_t size = 0;
394     indexAud = 1;
395     uint32_t timeout = 100;
396     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
397     ASSERT_NE(pluginBase_, nullptr);
398     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
399     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
400     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
401     ASSERT_EQ(CreateBufferSize(), true);
402     ASSERT_EQ(demuxerPlugin->GetNextSampleSize(indexAud, size, timeout), Status::OK);
403     ASSERT_EQ(size, 304);
404 }
405 
406 /**
407  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0120
408  * @tc.name      : GetNextSampleSize,读取不存在轨
409  * @tc.desc      : func test
410  */
411 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0120, TestSize.Level1)
412 {
413     int32_t size = 0;
414     indexAud = 7;
415     uint32_t timeout = 100;
416     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
417     ASSERT_NE(pluginBase_, nullptr);
418     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
419     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
420     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
421     ASSERT_EQ(CreateBufferSize(), true);
422     ASSERT_EQ(demuxerPlugin->GetNextSampleSize(indexAud, size, timeout), Status::ERROR_UNKNOWN);
423 }
424 
425 /**
426  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0130
427  * @tc.name      : GetLastPTSByTrackId,读取视频轨,得到音频轨lastpts
428  * @tc.desc      : func test
429  */
430 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0130, TestSize.Level2)
431 {
432     indexVid = 0;
433     indexAud = 1;
434     readPos = 30;
435     int32_t readCount = 0;
436     int64_t pts = 0;
437     uint32_t timeout = 100;
438     int64_t ptsMin = 1087;
439     int64_t ptsMax = 1127;
440     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
441     ASSERT_NE(pluginBase_, nullptr);
442     ASSERT_EQ(CreateBufferSize(), true);
443     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
444     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
445     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
446     while (true) {
447         if (readCount >= readPos) {
448             ASSERT_EQ(demuxerPlugin->GetLastPTSByTrackId(indexAud, pts), Status::OK);
449             break;
450         } else {
451             readCount++;
452             ASSERT_EQ(demuxerPlugin->ReadSample(indexVid, avBuf_, timeout), Status::OK);
453         }
454     }
455     ASSERT_GE(pts, ptsMin);
456     ASSERT_LE(pts, ptsMax);
457 }
458 /**
459  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0140
460  * @tc.name      : GetLastPTSByTrackId,读取音频轨,得到视频轨lastpts
461  * @tc.desc      : func test
462  */
463 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0140, TestSize.Level2)
464 {
465     indexVid = 0;
466     indexAud = 1;
467     readPos = 30;
468     int32_t readCount = 0;
469     int64_t pts = 0;
470     uint32_t timeout = 100;
471     int64_t ptsMin = 1293;
472     int64_t ptsMax = 1393;
473     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
474     ASSERT_NE(pluginBase_, nullptr);
475     ASSERT_EQ(CreateBufferSize(), true);
476     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
477     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
478     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
479     while (true) {
480         if (readCount >= readPos) {
481             ASSERT_EQ(demuxerPlugin->GetLastPTSByTrackId(indexVid, pts), Status::OK);
482             break;
483         } else {
484             readCount++;
485             ASSERT_EQ(demuxerPlugin->ReadSample(indexAud, avBuf_, timeout), Status::OK);
486         }
487     }
488     ASSERT_GE(pts, ptsMin);
489     ASSERT_LE(pts, ptsMax);
490 }
491 
492 /**
493  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0150
494  * @tc.name      : GetLastPTSByTrackId,不选轨道
495  * @tc.desc      : func test
496  */
497 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0150, TestSize.Level2)
498 {
499     indexVid = 0;
500     int64_t pts = 0;
501     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
502     ASSERT_NE(pluginBase_, nullptr);
503     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
504     ASSERT_EQ(demuxerPlugin->GetLastPTSByTrackId(indexVid, pts), Status::ERROR_INVALID_OPERATION);
505 }
506 
507 /**
508  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0160
509  * @tc.name      : GetLastPTSByTrackId,入参的id没有被选择
510  * @tc.desc      : func test
511  */
512 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0160, TestSize.Level2)
513 {
514     indexVid = 0;
515     int64_t pts = 0;
516     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
517     ASSERT_NE(pluginBase_, nullptr);
518     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
519     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
520     ASSERT_EQ(demuxerPlugin->GetLastPTSByTrackId(indexVid, pts), Status::ERROR_INVALID_PARAMETER);
521 }
522 
523 /**
524  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0170
525  * @tc.name      : read-pause-read
526  * @tc.desc      : func test
527  */
528 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0170, TestSize.Level3)
529 {
530     indexVid = 0;
531     uint32_t timeout = 100;
532     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
533     ASSERT_NE(pluginBase_, nullptr);
534     ASSERT_EQ(CreateBufferSize(), true);
535     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
536     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
537     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
538     ASSERT_EQ(demuxerPlugin->ReadSample(indexVid, avBuf_, timeout), Status::OK);
539     ASSERT_EQ(demuxerPlugin->Pause(), Status::OK);
540     while (!isAudioEosFlagForSave || !isVideoEosFlagForSave) {
541         for (int32_t i = 0;i < 2; i++) {
542             if (((i == videoTrackIdx) && isVideoEosFlagForSave) || ((i == audioTrackIdx) && isAudioEosFlagForSave)) {
543                 continue;
544             }
545             ASSERT_EQ(demuxerPlugin->ReadSample(i, avBuf_, timeout), Status::OK);
546             GetFrameNum(i);
547         }
548     }
549     ASSERT_EQ(audioIndexForRead, 318);
550     ASSERT_EQ(videoIndexForRead, 306);
551 }
552 
553 /**
554  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0180
555  * @tc.name      : read-pause-seek-read
556  * @tc.desc      : func test
557  */
558 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0180, TestSize.Level3)
559 {
560     indexVid = 0;
561     uint32_t timeout = 1000;
562     int64_t realtime = 0;
563     int64_t seekTime = 5042000;
564     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV_2, DEF_PROB_SIZE), true);
565     ASSERT_NE(pluginBase_, nullptr);
566     ASSERT_EQ(CreateBufferSize(), true);
567     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
568     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
569     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
570     auto ret = demuxerPlugin->ReadSample(indexVid, avBuf_, timeout);
571     while (ret == Status::ERROR_WAIT_TIMEOUT) {
572         ret = demuxerPlugin->ReadSample(indexVid, avBuf_, timeout);
573     }
574     ASSERT_EQ(ret, Status::OK);
575     ASSERT_EQ(demuxerPlugin->Pause(), Status::OK);
576     ASSERT_EQ(demuxerPlugin->SeekTo(
577         indexVid, seekTime / THOUSAND, Plugins::SeekMode::SEEK_NEXT_SYNC, realtime), Status::OK);
578     while (!isAudioEosFlagForSave || !isVideoEosFlagForSave) {
579         for (int32_t i = 0;i < 2; i++) {
580             if (((i == videoTrackIdx) && isVideoEosFlagForSave) || ((i == audioTrackIdx) && isAudioEosFlagForSave)) {
581                 continue;
582             }
583             ret = demuxerPlugin->ReadSample(i, avBuf_, timeout);
584             while (ret == Status::ERROR_WAIT_TIMEOUT) {
585                 ret = demuxerPlugin->ReadSample(i, avBuf_, timeout);
586             }
587             ASSERT_EQ(ret, Status::OK);
588             GetFrameNum(i);
589         }
590     }
591     ASSERT_EQ(audioIndexForRead, 65);
592     ASSERT_EQ(videoIndexForRead, 102);
593 }
594 
595 /**
596  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0190
597  * @tc.name      : pause-read
598  * @tc.desc      : func test
599  */
600 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0190, TestSize.Level3)
601 {
602     indexVid = 0;
603     uint32_t timeout = 1000;
604     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
605     ASSERT_NE(pluginBase_, nullptr);
606     ASSERT_EQ(CreateBufferSize(), true);
607     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
608     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
609     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
610     ASSERT_EQ(demuxerPlugin->Pause(), Status::OK);
611     while (!isAudioEosFlagForSave || !isVideoEosFlagForSave) {
612         for (int32_t i = 0;i < 2; i++) {
613             if (((i == videoTrackIdx) && isVideoEosFlagForSave) || ((i == audioTrackIdx) && isAudioEosFlagForSave)) {
614                 continue;
615             }
616             auto ret = demuxerPlugin->ReadSample(i, avBuf_, timeout);
617             while (ret == Status::ERROR_WAIT_TIMEOUT) {
618                 ret = demuxerPlugin->ReadSample(i, avBuf_, timeout);
619             }
620             ASSERT_EQ(ret, Status::OK);
621             GetFrameNum(i);
622         }
623     }
624     ASSERT_EQ(audioIndexForRead, 318);
625     ASSERT_EQ(videoIndexForRead, 307);
626 }
627 
628 /**
629  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0200
630  * @tc.name      : pause-seek-read
631  * @tc.desc      : func test
632  */
633 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0200, TestSize.Level3)
634 {
635     indexVid = 0;
636     uint32_t timeout = 100;
637     int64_t realtime = 0;
638     int64_t seekTime = 5042000;
639     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV_2, DEF_PROB_SIZE), true);
640     ASSERT_NE(pluginBase_, nullptr);
641     ASSERT_EQ(CreateBufferSize(), true);
642     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
643     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
644     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
645     ASSERT_EQ(demuxerPlugin->Pause(), Status::OK);
646     ASSERT_EQ(demuxerPlugin->SeekTo(
647         indexVid, seekTime / THOUSAND, Plugins::SeekMode::SEEK_NEXT_SYNC, realtime), Status::OK);
648     while (!isAudioEosFlagForSave || !isVideoEosFlagForSave) {
649         for (int32_t i = 0;i < 2; i++) {
650             if (((i == videoTrackIdx) && isVideoEosFlagForSave) || ((i == audioTrackIdx) && isAudioEosFlagForSave)) {
651                 continue;
652             }
653             ASSERT_EQ(demuxerPlugin->ReadSample(i, avBuf_, timeout), Status::OK);
654             GetFrameNum(i);
655         }
656     }
657     ASSERT_EQ(audioIndexForRead, 65);
658     ASSERT_EQ(videoIndexForRead, 102);
659 }
660 
661 /**
662  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0210
663  * @tc.name      : 未选择轨,pause
664  * @tc.desc      : func test
665  */
666 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0210, TestSize.Level3)
667 {
668     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
669     ASSERT_NE(pluginBase_, nullptr);
670     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
671     ASSERT_EQ(demuxerPlugin->Pause(), Status::OK);
672 }
673 
674 /**
675  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0220
676  * @tc.name      : seek + read
677  * @tc.desc      : func test
678  */
679 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0220, TestSize.Level3)
680 {
681     indexVid = 0;
682     indexAud = 1;
683     uint32_t timeout = 100;
684     int64_t seekTime = 5042000;
685     int64_t realtime = 0;
686     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV_2, DEF_PROB_SIZE), true);
687     ASSERT_NE(pluginBase_, nullptr);
688     ASSERT_EQ(CreateBufferSize(), true);
689     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
690     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
691     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
692     ASSERT_EQ(demuxerPlugin->SeekTo(
693         indexVid, seekTime / THOUSAND, Plugins::SeekMode::SEEK_NEXT_SYNC, realtime), Status::OK);
694     while (!isAudioEosFlagForSave || !isVideoEosFlagForSave) {
695         for (int32_t i = 0;i < 2; i++) {
696             if (((i == videoTrackIdx) && isVideoEosFlagForSave) || ((i == audioTrackIdx) && isAudioEosFlagForSave)) {
697                 continue;
698             }
699             ASSERT_EQ(demuxerPlugin->ReadSample(i, avBuf_, timeout), Status::OK);
700             GetFrameNum(i);
701         }
702     }
703     ASSERT_EQ(audioIndexForRead, 65);
704     ASSERT_EQ(videoIndexForRead, 102);
705 }
706 
707 /**
708  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0230
709  * @tc.name      : seek后清理缓存
710  * @tc.desc      : func test
711  */
712 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0230, TestSize.Level3)
713 {
714     indexVid = 0;
715     indexAud = 1;
716     uint32_t timeout = 100;
717     int64_t realtime = 0;
718     int64_t seekTime = 5042000;
719     int64_t pts = 0;
720     int32_t readCount = 0;
721     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV_2, DEF_PROB_SIZE), true);
722     ASSERT_NE(pluginBase_, nullptr);
723     ASSERT_EQ(CreateBufferSize(), true);
724     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
725     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
726     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
727     while (true) {
728         if (readCount >= readPos) {
729             ASSERT_EQ(demuxerPlugin->SeekTo(
730                 indexVid, seekTime / THOUSAND, Plugins::SeekMode::SEEK_NEXT_SYNC, realtime), Status::OK);
731             ASSERT_EQ(demuxerPlugin->GetLastPTSByTrackId(indexAud, pts), Status::ERROR_NOT_EXISTED);
732             break;
733         } else {
734             readCount++;
735             ASSERT_EQ(demuxerPlugin->ReadSample(indexVid, avBuf_, timeout), Status::OK);
736         }
737     }
738 }
739 
740 /**
741  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0240
742  * @tc.name      : >pts, SEEK_NEXT_SYNC+GetLastPTSByTrackId
743  * @tc.desc      : func test
744  */
745 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0240, TestSize.Level2)
746 {
747     indexVid = 0;
748     int64_t realtime = 0;
749     int64_t seekTime = 10458000;
750     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
751     ASSERT_NE(pluginBase_, nullptr);
752     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
753     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
754     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
755     ASSERT_EQ(demuxerPlugin->SeekTo(
756         indexVid, seekTime / THOUSAND, Plugins::SeekMode::SEEK_NEXT_SYNC, realtime), Status::ERROR_UNKNOWN);
757 }
758 
759 /**
760  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0250
761  * @tc.name      : >pts, SEEK_PREVIOUS_SYNC+GetLastPTSByTrackId
762  * @tc.desc      : func test
763  */
764 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0250, TestSize.Level2)
765 {
766     indexVid = 0;
767     int64_t realtime = 0;
768     int64_t seekTime = 10360000;
769     int64_t pts = 0;
770     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
771     ASSERT_NE(pluginBase_, nullptr);
772     ASSERT_EQ(CreateBufferSize(), true);
773     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
774     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
775     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
776     ASSERT_EQ(demuxerPlugin->SeekTo(
777         indexVid, seekTime / THOUSAND, Plugins::SeekMode::SEEK_PREVIOUS_SYNC, realtime), Status::OK);
778     ASSERT_EQ(demuxerPlugin->GetLastPTSByTrackId(indexVid, pts), Status::ERROR_NOT_EXISTED);
779 }
780 
781 /**
782  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0260
783  * @tc.name      : >pts, SEEK_CLOSEST_SYNC+GetLastPTSByTrackId
784  * @tc.desc      : func test
785  */
786 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0260, TestSize.Level2)
787 {
788     indexVid = 0;
789     int64_t realtime = 0;
790     int64_t seekTime = 10360000;
791     int64_t pts = 0;
792     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
793     ASSERT_NE(pluginBase_, nullptr);
794     ASSERT_EQ(CreateBufferSize(), true);
795     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
796     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
797     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
798     ASSERT_EQ(demuxerPlugin->SeekTo(
799         indexVid, seekTime / THOUSAND, Plugins::SeekMode::SEEK_CLOSEST_SYNC, realtime), Status::OK);
800     ASSERT_EQ(demuxerPlugin->GetLastPTSByTrackId(indexVid, pts), Status::ERROR_NOT_EXISTED);
801 }
802 /**
803  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0270
804  * @tc.name      : 老ReadSample + 新 ReadSample
805  * @tc.desc      : func test
806  */
807 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0270, TestSize.Level2)
808 {
809     indexVid = 0;
810     uint32_t timeout = 100;
811     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
812     ASSERT_NE(pluginBase_, nullptr);
813     ASSERT_EQ(CreateBufferSize(), true);
814     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
815     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
816     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
817     ASSERT_EQ(demuxerPlugin->ReadSample(indexVid, avBuf_), Status::OK);
818     ASSERT_EQ(demuxerPlugin->ReadSample(indexVid, avBuf_, timeout), Status::ERROR_INVALID_OPERATION);
819 }
820 
821 /**
822  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0280
823  * @tc.name      : 老ReadSample + 新 GetNextSampleSize
824  * @tc.desc      : func test
825  */
826 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0280, TestSize.Level2)
827 {
828     indexVid = 0;
829     uint32_t timeout = 100;
830     int32_t size = 0;
831     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
832     ASSERT_NE(pluginBase_, nullptr);
833     ASSERT_EQ(CreateBufferSize(), true);
834     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
835     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
836     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
837     ASSERT_EQ(demuxerPlugin->ReadSample(indexVid, avBuf_), Status::OK);
838     ASSERT_EQ(demuxerPlugin->GetNextSampleSize(indexVid, size, timeout), Status::ERROR_INVALID_OPERATION);
839 }
840 
841 /**
842  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0290
843  * @tc.name      : 老 GetNextSampleSize + 新 ReadSample
844  * @tc.desc      : func test
845  */
846 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0290, TestSize.Level2)
847 {
848     indexVid = 0;
849     uint32_t timeout = 100;
850     int32_t size = 0;
851     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
852     ASSERT_NE(pluginBase_, nullptr);
853     ASSERT_EQ(CreateBufferSize(), true);
854     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
855     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
856     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
857     ASSERT_EQ(demuxerPlugin->GetNextSampleSize(indexVid, size), Status::OK);
858     ASSERT_EQ(demuxerPlugin->ReadSample(indexVid, avBuf_, timeout), Status::ERROR_INVALID_OPERATION);
859 }
860 
861 /**
862  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0300
863  * @tc.name      : 老 GetNextSampleSize + 新 GetNextSampleSize
864  * @tc.desc      : func test
865  */
866 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0300, TestSize.Level2)
867 {
868     indexVid = 0;
869     uint32_t timeout = 100;
870     int32_t size = 0;
871     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
872     ASSERT_NE(pluginBase_, nullptr);
873     ASSERT_EQ(CreateBufferSize(), true);
874     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
875     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
876     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
877     ASSERT_EQ(demuxerPlugin->GetNextSampleSize(indexVid, size), Status::OK);
878     ASSERT_EQ(demuxerPlugin->GetNextSampleSize(indexVid, size, timeout), Status::ERROR_INVALID_OPERATION);
879 }
880 
881 /**
882  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0310
883  * @tc.name      : 新 ReadSample + 老 ReadSample
884  * @tc.desc      : func test
885  */
886 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0310, TestSize.Level2)
887 {
888     indexVid = 0;
889     uint32_t timeout = 100;
890     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
891     ASSERT_NE(pluginBase_, nullptr);
892     ASSERT_EQ(CreateBufferSize(), true);
893     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
894     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
895     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
896     ASSERT_EQ(demuxerPlugin->ReadSample(indexVid, avBuf_, timeout), Status::OK);
897     ASSERT_EQ(demuxerPlugin->ReadSample(indexVid, avBuf_), Status::ERROR_INVALID_OPERATION);
898 }
899 
900 /**
901  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0320
902  * @tc.name      : 新 ReadSample + 老 GetNextSampleSize
903  * @tc.desc      : func test
904  */
905 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0320, TestSize.Level2)
906 {
907     indexVid = 0;
908     uint32_t timeout = 100;
909     int32_t size = 0;
910     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
911     ASSERT_NE(pluginBase_, nullptr);
912     ASSERT_EQ(CreateBufferSize(), true);
913     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
914     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
915     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
916     ASSERT_EQ(demuxerPlugin->ReadSample(indexVid, avBuf_, timeout), Status::OK);
917     ASSERT_EQ(demuxerPlugin->GetNextSampleSize(indexVid, size), Status::ERROR_INVALID_OPERATION);
918 }
919 
920 /**
921  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0330
922  * @tc.name      : 新 GetNextSampleSize + 老 ReadSample
923  * @tc.desc      : func test
924  */
925 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0330, TestSize.Level2)
926 {
927     indexVid = 0;
928     uint32_t timeout = 100;
929     int32_t size = 0;
930     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
931     ASSERT_NE(pluginBase_, nullptr);
932     ASSERT_EQ(CreateBufferSize(), true);
933     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
934     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
935     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
936     ASSERT_EQ(demuxerPlugin->GetNextSampleSize(indexVid, size, timeout), Status::OK);
937     ASSERT_EQ(demuxerPlugin->ReadSample(indexVid, avBuf_), Status::ERROR_INVALID_OPERATION);
938 }
939 
940 /**
941  * @tc.number    : DEMUXER_ASYN_INNER_FUNC_0340
942  * @tc.name      : 新 GetNextSampleSize + 老 GetNextSampleSize
943  * @tc.desc      : func test
944  */
945 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_FUNC_0340, TestSize.Level2)
946 {
947     indexVid = 0;
948     uint32_t timeout = 100;
949     int32_t size = 0;
950     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
951     ASSERT_NE(pluginBase_, nullptr);
952     ASSERT_EQ(CreateBufferSize(), true);
953     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
954     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
955     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
956     ASSERT_EQ(demuxerPlugin->GetNextSampleSize(indexVid, size, timeout), Status::OK);
957     ASSERT_EQ(demuxerPlugin->GetNextSampleSize(indexVid, size), Status::ERROR_INVALID_OPERATION);
958 }
959 
960 /**
961  * @tc.number    : DEMUXER_ASYN_INNER_MULTI_THREAD_FUNC_0010
962  * @tc.name      : 多线程解析
963  * @tc.desc      : func test
964  */
965 HWTEST_F(DemuxerAsynInnerFuncTest, DEMUXER_ASYN_INNER_MULTI_THREAD_FUNC_0010, TestSize.Level2)
966 {
967     uint32_t timeout = 1000;
968     ASSERT_EQ(CreateDemuxerPluginByName(DEMUXER_PLUGIN_NAME_FLV, TEST_FILE_URI_FLV, DEF_PROB_SIZE), true);
969     ASSERT_NE(pluginBase_, nullptr);
970     auto demuxerPlugin = std::static_pointer_cast<Plugins::DemuxerPlugin>(pluginBase_);
971     ASSERT_EQ(demuxerPlugin->SelectTrack(0), Status::OK);
972     ASSERT_EQ(demuxerPlugin->SelectTrack(1), Status::OK);
973     ASSERT_EQ(CreateBufferSize(), true);
974     for (int count = 0; count < 5; count++) {
975         isAudioEosFlagForSave = false;
976         isVideoEosFlagForSave = false;
__anon9739fde60102() 977         std::thread readSeek1([demuxerPlugin, timeout, this]() {
978             ThreadTask(demuxerPlugin, timeout);
979         });
__anon9739fde60202() 980         std::thread readSeek2([demuxerPlugin, timeout, this]() {
981             ThreadTask(demuxerPlugin, timeout);
982         });
983         readSeek1.join();
984         readSeek2.join();
985     }
986     ASSERT_EQ(demuxerPlugin->UnselectTrack(0), Status::OK);
987     ASSERT_EQ(demuxerPlugin->UnselectTrack(1), Status::OK);
988 }
989 
990 }  // namespace Media
991 }  // namespace OHOS