• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "dash_segment_downloader_unit_test.h"
17 #include <iostream>
18 #include "dash_segment_downloader.h"
19 #include "http_server_demo.h"
20 
21 namespace OHOS {
22 namespace Media {
23 namespace Plugins {
24 namespace HttpPlugin {
25 namespace {
26 constexpr int32_t SERVERPORT = 47777;
27 // range 0-1065
28 static const std::string AUDIO_SEGMENT_URL = "http://127.0.0.1:47777/test_dash/segment_base/media-audio-und-mp4a.mp4";
29 static const std::string VIDEO_MEDIA_SEGMENT_URL_1 = "http://127.0.0.1:47777/test_dash/segment_list/video/1/seg-1.m4s";
30 static const std::string VIDEO_MEDIA_SEGMENT_URL_2 = "http://127.0.0.1:47777/test_dash/segment_list/video/1/seg-2.m4s";
31 static const std::string VIDEO_INIT_SEGMENT_URL = "http://127.0.0.1:47777/test_dash/segment_list/video/1/init.mp4";
32 }
33 using namespace testing::ext;
34 
35 std::unique_ptr<MediaAVCodec::HttpServerDemo> g_server = nullptr;
SetUpTestCase(void)36 void DashSegmentDownloaderUnitTest::SetUpTestCase(void)
37 {
38     g_server = std::make_unique<MediaAVCodec::HttpServerDemo>();
39     g_server->StartServer(SERVERPORT);
40     std::cout << "start" << std::endl;
41 }
42 
TearDownTestCase(void)43 void DashSegmentDownloaderUnitTest::TearDownTestCase(void)
44 {
45     g_server->StopServer();
46     g_server = nullptr;
47 }
48 
SetUp(void)49 void DashSegmentDownloaderUnitTest::SetUp(void)
50 {
51     if (g_server == nullptr) {
52         g_server = std::make_unique<MediaAVCodec::HttpServerDemo>();
53         g_server->StartServer(SERVERPORT);
54         std::cout << "start server" << std::endl;
55     }
56 }
57 
TearDown(void)58 void DashSegmentDownloaderUnitTest::TearDown(void) {}
59 
60 HWTEST_F(DashSegmentDownloaderUnitTest, TEST_DASH_SEGMENT_DOWNLOADER, TestSize.Level1)
61 {
62     std::shared_ptr<DashSegmentDownloader> segmentDownloader = std::make_shared<DashSegmentDownloader>(nullptr,
63             1, MediaAVCodec::MediaType::MEDIA_TYPE_VID, 10);
64 
65     EXPECT_NE(segmentDownloader, nullptr);
66     EXPECT_EQ(segmentDownloader->GetStreamId(), 1);
67     EXPECT_EQ(segmentDownloader->GetStreamType(), MediaAVCodec::MediaType::MEDIA_TYPE_VID);
68 }
69 
70 HWTEST_F(DashSegmentDownloaderUnitTest, TEST_OPEN, TestSize.Level1)
71 {
72     std::shared_ptr<DashSegmentDownloader> segmentDownloader = std::make_shared<DashSegmentDownloader>(nullptr,
73             1, MediaAVCodec::MediaType::MEDIA_TYPE_VID, 10);
74 
75     std::shared_ptr<DashSegment> segmentSp = std::make_shared<DashSegment>();
76     segmentSp->url_ = AUDIO_SEGMENT_URL;
77     segmentSp->streamId_ = 1;
78     segmentSp->duration_ = 5;
79     segmentSp->bandwidth_ = 1024;
80     segmentSp->startNumberSeq_ = 1;
81     segmentSp->numberSeq_ = 1;
82     auto statusCallback = [] (DownloadStatus&& status, std::shared_ptr<Downloader>& downloader,
__anon8cc649470202(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 83                                   std::shared_ptr<DownloadRequest>& request) {};
84     segmentDownloader->SetStatusCallback(statusCallback);
__anon8cc649470302(int streamId) 85     auto doneCallback = [] (int streamId) {};
86     segmentDownloader->SetDownloadDoneCallback(doneCallback);
87     bool result = segmentDownloader->Open(segmentSp);
88     segmentDownloader->Pause();
89     segmentDownloader->Resume();
90     segmentDownloader->Close(true, true);
91     segmentDownloader = nullptr;
92     EXPECT_TRUE(result);
93 }
94 
95 HWTEST_F(DashSegmentDownloaderUnitTest, TEST_OPEN_WITH_RANGE, TestSize.Level1)
96 {
97     std::shared_ptr<DashSegmentDownloader> segmentDownloader = std::make_shared<DashSegmentDownloader>(nullptr,
98             1, MediaAVCodec::MediaType::MEDIA_TYPE_VID, 10);
99 
100     std::shared_ptr<DashSegment> segmentSp = std::make_shared<DashSegment>();
101     segmentSp->url_ = AUDIO_SEGMENT_URL;
102     segmentSp->streamId_ = 4;
103     segmentSp->duration_ = 5;
104     segmentSp->bandwidth_ = 1024;
105     segmentSp->startNumberSeq_ = 1;
106     segmentSp->numberSeq_ = 1;
107     segmentSp->startRangeValue_ = 0;
108     segmentSp->endRangeValue_ = 1065;
109     auto statusCallback = [] (DownloadStatus&& status, std::shared_ptr<Downloader>& downloader,
__anon8cc649470402(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 110                                   std::shared_ptr<DownloadRequest>& request) {};
111     segmentDownloader->SetStatusCallback(statusCallback);
__anon8cc649470502(int streamId) 112     auto doneCallback = [] (int streamId) {};
113     segmentDownloader->SetDownloadDoneCallback(doneCallback);
114     bool result = segmentDownloader->Open(segmentSp);
115     segmentDownloader->GetBufferSize();
116     segmentDownloader->GetRingBufferCapacity();
117     segmentDownloader->Close(true, true);
118     segmentDownloader = nullptr;
119     EXPECT_TRUE(result);
120 }
121 
122 HWTEST_F(DashSegmentDownloaderUnitTest, TEST_OPEN_WITH_INIT_SEGMENT, TestSize.Level1)
123 {
124     std::shared_ptr<DashSegmentDownloader> segmentDownloader = std::make_shared<DashSegmentDownloader>(nullptr,
125             1, MediaAVCodec::MediaType::MEDIA_TYPE_VID, 10);
126 
127     std::shared_ptr<DashInitSegment> initSeg = std::make_shared<DashInitSegment>();
128     initSeg->url_ = VIDEO_INIT_SEGMENT_URL;
129     initSeg->streamId_ = 1;
130     segmentDownloader->SetInitSegment(initSeg);
131 
132     std::shared_ptr<DashSegment> segmentSp = std::make_shared<DashSegment>();
133     segmentSp->url_ = VIDEO_MEDIA_SEGMENT_URL_1;
134     segmentSp->streamId_ = 1;
135     segmentSp->duration_ = 5;
136     segmentSp->bandwidth_ = 1024;
137     segmentSp->startNumberSeq_ = 1;
138     segmentSp->numberSeq_ = 1;
139     auto statusCallback = [] (DownloadStatus&& status, std::shared_ptr<Downloader>& downloader,
__anon8cc649470602(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 140                                   std::shared_ptr<DownloadRequest>& request) {};
141     segmentDownloader->SetStatusCallback(statusCallback);
__anon8cc649470702(int streamId) 142     auto doneCallback = [] (int streamId) {};
143     segmentDownloader->SetDownloadDoneCallback(doneCallback);
144     bool result = segmentDownloader->Open(segmentSp);
145     segmentDownloader->Close(true, true);
146     segmentDownloader = nullptr;
147 
148     EXPECT_TRUE(result);
149 }
150 
151 HWTEST_F(DashSegmentDownloaderUnitTest, TEST_READ, TestSize.Level1)
152 {
153     std::shared_ptr<DashSegmentDownloader> segmentDownloader = std::make_shared<DashSegmentDownloader>(nullptr,
154             1, MediaAVCodec::MediaType::MEDIA_TYPE_VID, 10);
155 
156     std::shared_ptr<DashSegment> segmentSp = std::make_shared<DashSegment>();
157     segmentSp->url_ = AUDIO_SEGMENT_URL;
158     segmentSp->streamId_ = 1;
159     segmentSp->duration_ = 5;
160     segmentSp->bandwidth_ = 1024;
161     segmentSp->startNumberSeq_ = 1;
162     segmentSp->numberSeq_ = 1;
163     auto statusCallback = [] (DownloadStatus&& status, std::shared_ptr<Downloader>& downloader,
__anon8cc649470802(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 164                                   std::shared_ptr<DownloadRequest>& request) {};
165     segmentDownloader->SetStatusCallback(statusCallback);
__anon8cc649470902(int streamId) 166     auto doneCallback = [] (int streamId) {};
167     segmentDownloader->SetDownloadDoneCallback(doneCallback);
168     segmentDownloader->Open(segmentSp);
169     int repeat = 0;
170     bool status = false;
171     while (repeat++ < 1000) {
172         status = segmentDownloader->GetStartedStatus();
173         if (status) {
174             break;
175         }
176         OSAL::SleepFor(2);
177     }
178 
179     unsigned char buffer[1024];
180     ReadDataInfo readDataInfo;
181     readDataInfo.streamId_ = 1;
182     readDataInfo.wantReadLength_ = 1024;
183     readDataInfo.realReadLength_ = 0;
184     readDataInfo.nextStreamId_ = 1;
185     std::atomic<bool> isInterruptNeeded = false;
186     DashReadRet result = segmentDownloader->Read(buffer, readDataInfo, isInterruptNeeded);
187     EXPECT_EQ(result, DASH_READ_OK);
188     EXPECT_EQ(readDataInfo.nextStreamId_, 1);
189     EXPECT_GE(readDataInfo.realReadLength_, 0);
190     readDataInfo.streamId_ = 2;
191     result = segmentDownloader->Read(buffer, readDataInfo, isInterruptNeeded);
192     segmentDownloader->Close(true, true);
193     segmentDownloader = nullptr;
194     EXPECT_EQ(result, DASH_READ_OK);
195 }
196 
197 HWTEST_F(DashSegmentDownloaderUnitTest, TEST_CLEAN_SEGMENT_BUFFER, TestSize.Level1)
198 {
199     std::shared_ptr<DashSegmentDownloader> segmentDownloader = std::make_shared<DashSegmentDownloader>(nullptr,
200             1, MediaAVCodec::MediaType::MEDIA_TYPE_VID, 10);
201 
202     std::shared_ptr<DashSegment> segmentSp = std::make_shared<DashSegment>();
203     segmentSp->url_ = AUDIO_SEGMENT_URL;
204     segmentSp->streamId_ = 1;
205     segmentSp->duration_ = 5;
206     segmentSp->bandwidth_ = 1024;
207     segmentSp->startNumberSeq_ = 1;
208     segmentSp->numberSeq_ = 1;
209     auto statusCallback = [] (DownloadStatus&& status, std::shared_ptr<Downloader>& downloader,
__anon8cc649470a02(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 210                                   std::shared_ptr<DownloadRequest>& request) {};
211     segmentDownloader->SetStatusCallback(statusCallback);
__anon8cc649470b02(int streamId) 212     auto doneCallback = [] (int streamId) {};
213     segmentDownloader->SetDownloadDoneCallback(doneCallback);
214     segmentDownloader->Open(segmentSp);
215     int repeat = 0;
216     bool status = false;
217     while (repeat++ < 1000) {
218         status = segmentDownloader->GetStartedStatus();
219         if (status) {
220             break;
221         }
222         OSAL::SleepFor(2);
223     }
224 
225     int64_t remainLastNumberSeq = -1;
226     segmentDownloader->CleanSegmentBuffer(false, remainLastNumberSeq);
227     segmentDownloader->Close(true, true);
228     segmentDownloader = nullptr;
229 
230     EXPECT_EQ(remainLastNumberSeq, 1);
231 }
232 
233 HWTEST_F(DashSegmentDownloaderUnitTest, TEST_CLEAN_SEGMENT_BUFFER_ALL, TestSize.Level1)
234 {
235     std::shared_ptr<DashSegmentDownloader> segmentDownloader = std::make_shared<DashSegmentDownloader>(nullptr,
236             1, MediaAVCodec::MediaType::MEDIA_TYPE_VID, 10);
237 
238     std::shared_ptr<DashSegment> segmentSp = std::make_shared<DashSegment>();
239     segmentSp->url_ = AUDIO_SEGMENT_URL;
240     segmentSp->streamId_ = 1;
241     segmentSp->duration_ = 5;
242     segmentSp->bandwidth_ = 1024;
243     segmentSp->startNumberSeq_ = 1;
244     segmentSp->numberSeq_ = 1;
245     auto statusCallback = [] (DownloadStatus&& status, std::shared_ptr<Downloader>& downloader,
__anon8cc649470c02(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 246                                   std::shared_ptr<DownloadRequest>& request) {};
247     segmentDownloader->SetStatusCallback(statusCallback);
__anon8cc649470d02(int streamId) 248     auto doneCallback = [] (int streamId) {};
249     segmentDownloader->SetDownloadDoneCallback(doneCallback);
250     segmentDownloader->Open(segmentSp);
251 
252     int64_t remainLastNumberSeq = -1;
253     bool result = segmentDownloader->CleanSegmentBuffer(true, remainLastNumberSeq);
254     segmentDownloader->Close(true, true);
255     segmentDownloader = nullptr;
256 
257     EXPECT_TRUE(result);
258     EXPECT_EQ(remainLastNumberSeq, 1);
259 }
260 
261 HWTEST_F(DashSegmentDownloaderUnitTest, TEST_UPDATE_STREAM_ID, TestSize.Level1)
262 {
263     std::shared_ptr<DashSegmentDownloader> segmentDownloader = std::make_shared<DashSegmentDownloader>(nullptr,
264             1, MediaAVCodec::MediaType::MEDIA_TYPE_VID, 10);
265     segmentDownloader->UpdateStreamId(2);
266     EXPECT_EQ(segmentDownloader->GetStreamId(), 2);
267 }
268 
269 HWTEST_F(DashSegmentDownloaderUnitTest, TEST_GET_CONTENT_LENGTH, TestSize.Level1)
270 {
271     std::shared_ptr<DashSegmentDownloader> segmentDownloader = std::make_shared<DashSegmentDownloader>(nullptr,
272             1, MediaAVCodec::MediaType::MEDIA_TYPE_VID, 10);
273     EXPECT_EQ(segmentDownloader->GetContentLength(), 0);
274 }
275 
276 HWTEST_F(DashSegmentDownloaderUnitTest, TEST_GET_IS_SEGMENT_FINISH, TestSize.Level1)
277 {
278     std::shared_ptr<DashSegmentDownloader> segmentDownloader = std::make_shared<DashSegmentDownloader>(nullptr,
279             1, MediaAVCodec::MediaType::MEDIA_TYPE_VID, 10);
280     EXPECT_FALSE(segmentDownloader->IsSegmentFinish());
281 }
282 
283 HWTEST_F(DashSegmentDownloaderUnitTest, TEST_SEEK_TO_TIME, TestSize.Level1)
284 {
285     std::shared_ptr<DashSegmentDownloader> segmentDownloader = std::make_shared<DashSegmentDownloader>(nullptr,
286             1, MediaAVCodec::MediaType::MEDIA_TYPE_VID, 10);
287 
288     std::shared_ptr<DashSegment> segmentSp = std::make_shared<DashSegment>();
289     segmentSp->url_ = VIDEO_MEDIA_SEGMENT_URL_1;
290     segmentSp->streamId_ = 1;
291     segmentSp->duration_ = 5;
292     segmentSp->bandwidth_ = 1024;
293     segmentSp->startNumberSeq_ = 1;
294     segmentSp->numberSeq_ = 1;
295     auto statusCallback = [] (DownloadStatus&& status, std::shared_ptr<Downloader>& downloader,
__anon8cc649470e02(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 296                                   std::shared_ptr<DownloadRequest>& request) {};
297     segmentDownloader->SetStatusCallback(statusCallback);
__anon8cc649470f02(int streamId) 298     auto doneCallback = [] (int streamId) {};
299     segmentDownloader->SetDownloadDoneCallback(doneCallback);
300     segmentDownloader->Open(segmentSp);
301 
302     std::shared_ptr<DashSegment> seekSegment = std::make_shared<DashSegment>();
303     segmentSp->url_ = VIDEO_MEDIA_SEGMENT_URL_2;
304     segmentSp->streamId_ = 1;
305     segmentSp->duration_ = 5;
306     segmentSp->bandwidth_ = 1024;
307     segmentSp->startNumberSeq_ = 1;
308     segmentSp->numberSeq_ = 2;
309 
310     bool result = segmentDownloader->SeekToTime(seekSegment);
311     segmentDownloader->Close(true, true);
312     segmentDownloader = nullptr;
313 
314     EXPECT_FALSE(result);
315 }
316 
317 HWTEST_F(DashSegmentDownloaderUnitTest, TEST_DASH_SEGMENT_DOWNLOADER_SUCCESS_001, TestSize.Level1)
318 {
319     std::shared_ptr<DashSegmentDownloader> segmentDownloaderSp = std::make_shared<DashSegmentDownloader>(nullptr,
320             0, MediaAVCodec::MediaType::MEDIA_TYPE_VID, 10);
321     std::shared_ptr<DashSegment> segmentSp = std::make_shared<DashSegment>();
322     segmentSp->url_ = VIDEO_MEDIA_SEGMENT_URL_1;
323     segmentSp->streamId_ = 0;
324     segmentSp->duration_ = 5;
325     segmentSp->bandwidth_ = 1024;
326     segmentSp->startNumberSeq_ = 0;
327     segmentSp->numberSeq_ = 0;
328     auto statusCallback = [] (DownloadStatus&& status, std::shared_ptr<Downloader>& downloader,
__anon8cc649471002(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 329                                   std::shared_ptr<DownloadRequest>& request) {};
330     segmentDownloaderSp->SetStatusCallback(statusCallback);
__anon8cc649471102(int streamId) 331     auto doneCallback = [] (int streamId) {};
332     segmentDownloaderSp->SetDownloadDoneCallback(doneCallback);
333     segmentDownloaderSp->Open(segmentSp);
334     OSAL::SleepFor(1000);
335     segmentDownloaderSp->Close(true, true);
336     bool status = segmentDownloaderSp->GetStartedStatus();
337     EXPECT_GE(status, false);
338 }
339 
340 HWTEST_F(DashSegmentDownloaderUnitTest, TEST_DASH_SEGMENT_DOWNLOADER_WATERLINE_001, TestSize.Level1)
341 {
342     std::shared_ptr<DashSegmentDownloader> segmentDownloaderSp = std::make_shared<DashSegmentDownloader>(nullptr,
343         0, MediaAVCodec::MediaType::MEDIA_TYPE_VID, 10);
344     std::shared_ptr<DashSegment> segmentSp = std::make_shared<DashSegment>();
345     segmentSp->url_ = VIDEO_MEDIA_SEGMENT_URL_1;
346     segmentSp->streamId_ = 0;
347     segmentSp->duration_ = 5;
348     segmentSp->bandwidth_ = 1024;
349     segmentSp->startNumberSeq_ = 0;
350     segmentSp->numberSeq_ = 0;
351     auto statusCallback = [] (DownloadStatus&& status, std::shared_ptr<Downloader>& downloader,
__anon8cc649471202(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 352                               std::shared_ptr<DownloadRequest>& request) {};
353     segmentDownloaderSp->SetStatusCallback(statusCallback);
__anon8cc649471302(int streamId) 354     auto doneCallback = [] (int streamId) {};
355     segmentDownloaderSp->SetDownloadDoneCallback(doneCallback);
356     segmentDownloaderSp->SetDemuxerState();
357     segmentDownloaderSp->SetCurrentBitRate(1048576);
358     unsigned char buffer[1024];
359     ReadDataInfo readDataInfo;
360     readDataInfo.streamId_ = 1;
361     readDataInfo.wantReadLength_ = 1024;
362     readDataInfo.realReadLength_ = 0;
363     readDataInfo.nextStreamId_ = 1;
364     std::atomic<bool> isInterruptNeeded = false;
365     DashReadRet result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
366     EXPECT_EQ(result, DASH_READ_AGAIN);
367     result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
368     EXPECT_EQ(result, DASH_READ_AGAIN);
369     segmentDownloaderSp->Open(segmentSp);
370     OSAL::SleepFor(1000);
371     result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
372     segmentDownloaderSp->Close(true, true);
373     EXPECT_GE(result, DASH_READ_SEGMENT_DOWNLOAD_FINISH);
374 }
375 
376 class SourceCallbackMock : public Plugins::Callback {
377 public:
OnEvent(const Plugins::PluginEvent & event)378     void OnEvent(const Plugins::PluginEvent &event) override
379     {
380         (void)event;
381     }
382 
SetSelectBitRateFlag(bool flag,uint32_t desBitRate)383     void SetSelectBitRateFlag(bool flag, uint32_t desBitRate) override
384     {
385         (void)flag;
386         (void)desBitRate;
387     }
388 
CanAutoSelectBitRate()389     bool CanAutoSelectBitRate() override
390     {
391         return true;
392     }
393 };
394 
395 HWTEST_F(DashSegmentDownloaderUnitTest, TEST_DASH_SEGMENT_DOWNLOADER_WATERLINE_002, TestSize.Level1)
396 {
397     Plugins::Callback* sourceCallback = new SourceCallbackMock();
398     std::shared_ptr<DashSegmentDownloader> segmentDownloaderSp = std::make_shared<DashSegmentDownloader>(sourceCallback,
399         0, MediaAVCodec::MediaType::MEDIA_TYPE_VID, 10);
400     std::shared_ptr<DashSegment> segmentSp = std::make_shared<DashSegment>();
401     segmentSp->url_ = VIDEO_MEDIA_SEGMENT_URL_1;
402     segmentSp->streamId_ = 0;
403     segmentSp->duration_ = 5;
404     segmentSp->bandwidth_ = 1024;
405     segmentSp->startNumberSeq_ = 0;
406     segmentSp->numberSeq_ = 0;
407     auto statusCallback = [] (DownloadStatus&& status, std::shared_ptr<Downloader>& downloader,
__anon8cc649471402(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 408                               std::shared_ptr<DownloadRequest>& request) {};
409     segmentDownloaderSp->SetStatusCallback(statusCallback);
__anon8cc649471502(int streamId) 410     auto doneCallback = [] (int streamId) {};
411     segmentDownloaderSp->SetDownloadDoneCallback(doneCallback);
412     segmentDownloaderSp->SetDemuxerState();
413     segmentDownloaderSp->SetCurrentBitRate(1048576);
414     unsigned char buffer[1024];
415     ReadDataInfo readDataInfo;
416     readDataInfo.streamId_ = 1;
417     readDataInfo.wantReadLength_ = 1024;
418     readDataInfo.realReadLength_ = 0;
419     readDataInfo.nextStreamId_ = 1;
420     std::atomic<bool> isInterruptNeeded = false;
421     DashReadRet result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
422     EXPECT_EQ(result, DASH_READ_AGAIN);
423     result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
424     EXPECT_EQ(result, DASH_READ_AGAIN);
425     segmentDownloaderSp->Open(segmentSp);
426     segmentDownloaderSp->SetAllSegmentFinished();
427     result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
428     segmentDownloaderSp->Close(true, true);
429     EXPECT_EQ(result, DASH_READ_END);
430     delete sourceCallback;
431     sourceCallback = nullptr;
432 }
433 
434 HWTEST_F(DashSegmentDownloaderUnitTest, TEST_DASH_SEGMENT_DOWNLOADER_WATERLINE_003, TestSize.Level1)
435 {
436     Plugins::Callback* sourceCallback = new SourceCallbackMock();
437     std::shared_ptr<DashSegmentDownloader> segmentDownloaderSp = std::make_shared<DashSegmentDownloader>(sourceCallback,
438         0, MediaAVCodec::MediaType::MEDIA_TYPE_VID, 10);
439     std::shared_ptr<DashSegment> segmentSp = std::make_shared<DashSegment>();
440     segmentSp->url_ = VIDEO_MEDIA_SEGMENT_URL_1;
441     segmentSp->streamId_ = 0;
442     segmentSp->duration_ = 5;
443     segmentSp->bandwidth_ = 1024;
444     segmentSp->startNumberSeq_ = 0;
445     segmentSp->numberSeq_ = 0;
446     auto statusCallback = [] (DownloadStatus&& status, std::shared_ptr<Downloader>& downloader,
__anon8cc649471602(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 447                               std::shared_ptr<DownloadRequest>& request) {};
448     segmentDownloaderSp->SetStatusCallback(statusCallback);
__anon8cc649471702(int streamId) 449     auto doneCallback = [] (int streamId) {};
450     segmentDownloaderSp->SetDownloadDoneCallback(doneCallback);
451     segmentDownloaderSp->SetDemuxerState();
452     segmentDownloaderSp->SetCurrentBitRate(1048576000);
453     unsigned char buffer[1024];
454     ReadDataInfo readDataInfo;
455     readDataInfo.streamId_ = 1;
456     readDataInfo.wantReadLength_ = 1024;
457     readDataInfo.realReadLength_ = 0;
458     readDataInfo.nextStreamId_ = 1;
459     std::atomic<bool> isInterruptNeeded = false;
460     DashReadRet result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
461     EXPECT_EQ(result, DASH_READ_AGAIN);
462     result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
463     EXPECT_EQ(result, DASH_READ_AGAIN);
464     segmentDownloaderSp->Open(segmentSp);
465     result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
466     segmentDownloaderSp->Close(true, true);
467     EXPECT_EQ(result, DASH_READ_AGAIN);
468     delete sourceCallback;
469     sourceCallback = nullptr;
470 }
471 
472 HWTEST_F(DashSegmentDownloaderUnitTest, TEST_DASH_SEGMENT_DOWNLOADER_WATERLINE_004, TestSize.Level1)
473 {
474     Plugins::Callback* sourceCallback = new SourceCallbackMock();
475     std::shared_ptr<DashSegmentDownloader> segmentDownloaderSp = std::make_shared<DashSegmentDownloader>(sourceCallback,
476         0, MediaAVCodec::MediaType::MEDIA_TYPE_VID, 10);
477     std::shared_ptr<DashSegment> segmentSp = std::make_shared<DashSegment>();
478     segmentSp->url_ = "http://test/index.mpd";
479     segmentSp->streamId_ = 0;
480     segmentSp->duration_ = 5;
481     segmentSp->bandwidth_ = 1024;
482     segmentSp->startNumberSeq_ = 0;
483     segmentSp->numberSeq_ = 0;
484     auto statusCallback = [] (DownloadStatus&& status, std::shared_ptr<Downloader>& downloader,
__anon8cc649471802(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 485                               std::shared_ptr<DownloadRequest>& request) {};
486     segmentDownloaderSp->SetStatusCallback(statusCallback);
__anon8cc649471902(int streamId) 487     auto doneCallback = [] (int streamId) {};
488     segmentDownloaderSp->SetDownloadDoneCallback(doneCallback);
489     segmentDownloaderSp->SetDemuxerState();
490     segmentDownloaderSp->SetCurrentBitRate(1048576);
491     unsigned char buffer[1024];
492     ReadDataInfo readDataInfo;
493     readDataInfo.streamId_ = 1;
494     readDataInfo.wantReadLength_ = 1024;
495     readDataInfo.realReadLength_ = 0;
496     readDataInfo.nextStreamId_ = 1;
497     std::atomic<bool> isInterruptNeeded = false;
498     segmentDownloaderSp->Open(segmentSp);
499     DashReadRet result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
500     EXPECT_EQ(result, DASH_READ_AGAIN);
501     result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
502     EXPECT_EQ(result, DASH_READ_AGAIN);
503     isInterruptNeeded.store(true);
504     result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
505     segmentDownloaderSp->Close(true, true);
506     EXPECT_EQ(result, DASH_READ_INTERRUPT);
507     delete sourceCallback;
508     sourceCallback = nullptr;
509 }
510 }
511 }
512 }
513 }