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,
__anon59f90d7f0202(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 83 std::shared_ptr<DownloadRequest>& request) {};
84 segmentDownloader->SetStatusCallback(statusCallback);
__anon59f90d7f0302(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,
__anon59f90d7f0402(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 110 std::shared_ptr<DownloadRequest>& request) {};
111 segmentDownloader->SetStatusCallback(statusCallback);
__anon59f90d7f0502(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,
__anon59f90d7f0602(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 140 std::shared_ptr<DownloadRequest>& request) {};
141 segmentDownloader->SetStatusCallback(statusCallback);
__anon59f90d7f0702(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,
__anon59f90d7f0802(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 164 std::shared_ptr<DownloadRequest>& request) {};
165 segmentDownloader->SetStatusCallback(statusCallback);
__anon59f90d7f0902(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,
__anon59f90d7f0a02(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 210 std::shared_ptr<DownloadRequest>& request) {};
211 segmentDownloader->SetStatusCallback(statusCallback);
__anon59f90d7f0b02(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,
__anon59f90d7f0c02(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 246 std::shared_ptr<DownloadRequest>& request) {};
247 segmentDownloader->SetStatusCallback(statusCallback);
__anon59f90d7f0d02(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,
__anon59f90d7f0e02(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 296 std::shared_ptr<DownloadRequest>& request) {};
297 segmentDownloader->SetStatusCallback(statusCallback);
__anon59f90d7f0f02(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 int32_t streamId = -1;
311 bool result = segmentDownloader->SeekToTime(seekSegment, streamId);
312 segmentDownloader->Close(true, true);
313 segmentDownloader = nullptr;
314
315 EXPECT_FALSE(result);
316 }
317
318 HWTEST_F(DashSegmentDownloaderUnitTest, TEST_DASH_SEGMENT_DOWNLOADER_SUCCESS_001, TestSize.Level1)
319 {
320 std::shared_ptr<DashSegmentDownloader> segmentDownloaderSp = std::make_shared<DashSegmentDownloader>(nullptr,
321 0, MediaAVCodec::MediaType::MEDIA_TYPE_VID, 10);
322 std::shared_ptr<DashSegment> segmentSp = std::make_shared<DashSegment>();
323 segmentSp->url_ = VIDEO_MEDIA_SEGMENT_URL_1;
324 segmentSp->streamId_ = 0;
325 segmentSp->duration_ = 5;
326 segmentSp->bandwidth_ = 1024;
327 segmentSp->startNumberSeq_ = 0;
328 segmentSp->numberSeq_ = 0;
329 auto statusCallback = [] (DownloadStatus&& status, std::shared_ptr<Downloader>& downloader,
__anon59f90d7f1002(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 330 std::shared_ptr<DownloadRequest>& request) {};
331 segmentDownloaderSp->SetStatusCallback(statusCallback);
__anon59f90d7f1102(int streamId) 332 auto doneCallback = [] (int streamId) {};
333 segmentDownloaderSp->SetDownloadDoneCallback(doneCallback);
334 segmentDownloaderSp->Open(segmentSp);
335 OSAL::SleepFor(1000);
336 segmentDownloaderSp->Close(true, true);
337 bool status = segmentDownloaderSp->GetStartedStatus();
338 EXPECT_GE(status, false);
339 }
340
341 HWTEST_F(DashSegmentDownloaderUnitTest, TEST_DASH_SEGMENT_DOWNLOADER_WATERLINE_001, TestSize.Level1)
342 {
343 std::shared_ptr<DashSegmentDownloader> segmentDownloaderSp = std::make_shared<DashSegmentDownloader>(nullptr,
344 0, MediaAVCodec::MediaType::MEDIA_TYPE_VID, 10);
345 std::shared_ptr<DashSegment> segmentSp = std::make_shared<DashSegment>();
346 segmentSp->url_ = VIDEO_MEDIA_SEGMENT_URL_1;
347 segmentSp->streamId_ = 0;
348 segmentSp->duration_ = 5;
349 segmentSp->bandwidth_ = 1024;
350 segmentSp->startNumberSeq_ = 0;
351 segmentSp->numberSeq_ = 0;
352 auto statusCallback = [] (DownloadStatus&& status, std::shared_ptr<Downloader>& downloader,
__anon59f90d7f1202(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 353 std::shared_ptr<DownloadRequest>& request) {};
354 segmentDownloaderSp->SetStatusCallback(statusCallback);
__anon59f90d7f1302(int streamId) 355 auto doneCallback = [] (int streamId) {};
356 segmentDownloaderSp->SetDownloadDoneCallback(doneCallback);
357 segmentDownloaderSp->SetDemuxerState();
358 segmentDownloaderSp->SetCurrentBitRate(1048576);
359 unsigned char buffer[1024];
360 ReadDataInfo readDataInfo;
361 readDataInfo.streamId_ = 1;
362 readDataInfo.wantReadLength_ = 1024;
363 readDataInfo.realReadLength_ = 0;
364 readDataInfo.nextStreamId_ = 1;
365 std::atomic<bool> isInterruptNeeded = false;
366 DashReadRet result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
367 EXPECT_EQ(result, DASH_READ_AGAIN);
368 result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
369 EXPECT_EQ(result, DASH_READ_AGAIN);
370 segmentDownloaderSp->Open(segmentSp);
371 OSAL::SleepFor(1000);
372 result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
373 segmentDownloaderSp->Close(true, true);
374 EXPECT_GE(result, DASH_READ_SEGMENT_DOWNLOAD_FINISH);
375 }
376
377 class SourceCallbackMock : public Plugins::Callback {
378 public:
OnEvent(const Plugins::PluginEvent & event)379 void OnEvent(const Plugins::PluginEvent &event) override
380 {
381 (void)event;
382 }
383
SetSelectBitRateFlag(bool flag,uint32_t desBitRate)384 void SetSelectBitRateFlag(bool flag, uint32_t desBitRate) override
385 {
386 (void)flag;
387 (void)desBitRate;
388 }
389
CanAutoSelectBitRate()390 bool CanAutoSelectBitRate() override
391 {
392 return true;
393 }
394 };
395
396 HWTEST_F(DashSegmentDownloaderUnitTest, TEST_DASH_SEGMENT_DOWNLOADER_WATERLINE_002, TestSize.Level1)
397 {
398 Plugins::Callback* sourceCallback = new SourceCallbackMock();
399 std::shared_ptr<DashSegmentDownloader> segmentDownloaderSp = std::make_shared<DashSegmentDownloader>(sourceCallback,
400 0, MediaAVCodec::MediaType::MEDIA_TYPE_VID, 10);
401 std::shared_ptr<DashSegment> segmentSp = std::make_shared<DashSegment>();
402 segmentSp->url_ = VIDEO_MEDIA_SEGMENT_URL_1;
403 segmentSp->streamId_ = 0;
404 segmentSp->duration_ = 5;
405 segmentSp->bandwidth_ = 1024;
406 segmentSp->startNumberSeq_ = 0;
407 segmentSp->numberSeq_ = 0;
408 auto statusCallback = [] (DownloadStatus&& status, std::shared_ptr<Downloader>& downloader,
__anon59f90d7f1402(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 409 std::shared_ptr<DownloadRequest>& request) {};
410 segmentDownloaderSp->SetStatusCallback(statusCallback);
__anon59f90d7f1502(int streamId) 411 auto doneCallback = [] (int streamId) {};
412 segmentDownloaderSp->SetDownloadDoneCallback(doneCallback);
413 segmentDownloaderSp->SetDemuxerState();
414 segmentDownloaderSp->SetCurrentBitRate(1048576);
415 unsigned char buffer[1024];
416 ReadDataInfo readDataInfo;
417 readDataInfo.streamId_ = 1;
418 readDataInfo.wantReadLength_ = 1024;
419 readDataInfo.realReadLength_ = 0;
420 readDataInfo.nextStreamId_ = 1;
421 std::atomic<bool> isInterruptNeeded = false;
422 DashReadRet result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
423 EXPECT_EQ(result, DASH_READ_AGAIN);
424 result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
425 EXPECT_EQ(result, DASH_READ_AGAIN);
426 segmentDownloaderSp->Open(segmentSp);
427 segmentDownloaderSp->SetAllSegmentFinished();
428 result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
429 segmentDownloaderSp->Close(true, true);
430 EXPECT_EQ(result, DASH_READ_END);
431 delete sourceCallback;
432 sourceCallback = nullptr;
433 }
434
435 HWTEST_F(DashSegmentDownloaderUnitTest, TEST_DASH_SEGMENT_DOWNLOADER_WATERLINE_003, TestSize.Level1)
436 {
437 Plugins::Callback* sourceCallback = new SourceCallbackMock();
438 std::shared_ptr<DashSegmentDownloader> segmentDownloaderSp = std::make_shared<DashSegmentDownloader>(sourceCallback,
439 0, MediaAVCodec::MediaType::MEDIA_TYPE_VID, 10);
440 std::shared_ptr<DashSegment> segmentSp = std::make_shared<DashSegment>();
441 segmentSp->url_ = VIDEO_MEDIA_SEGMENT_URL_1;
442 segmentSp->streamId_ = 0;
443 segmentSp->duration_ = 5;
444 segmentSp->bandwidth_ = 1024;
445 segmentSp->startNumberSeq_ = 0;
446 segmentSp->numberSeq_ = 0;
447 auto statusCallback = [] (DownloadStatus&& status, std::shared_ptr<Downloader>& downloader,
__anon59f90d7f1602(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 448 std::shared_ptr<DownloadRequest>& request) {};
449 segmentDownloaderSp->SetStatusCallback(statusCallback);
__anon59f90d7f1702(int streamId) 450 auto doneCallback = [] (int streamId) {};
451 segmentDownloaderSp->SetDownloadDoneCallback(doneCallback);
452 segmentDownloaderSp->SetDemuxerState();
453 segmentDownloaderSp->SetCurrentBitRate(1048576000);
454 unsigned char buffer[1024];
455 ReadDataInfo readDataInfo;
456 readDataInfo.streamId_ = 1;
457 readDataInfo.wantReadLength_ = 1024;
458 readDataInfo.realReadLength_ = 0;
459 readDataInfo.nextStreamId_ = 1;
460 std::atomic<bool> isInterruptNeeded = false;
461 DashReadRet result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
462 EXPECT_EQ(result, DASH_READ_AGAIN);
463 result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
464 EXPECT_EQ(result, DASH_READ_AGAIN);
465 segmentDownloaderSp->Open(segmentSp);
466 result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
467 segmentDownloaderSp->Close(true, true);
468 EXPECT_EQ(result, DASH_READ_AGAIN);
469 delete sourceCallback;
470 sourceCallback = nullptr;
471 }
472
473 HWTEST_F(DashSegmentDownloaderUnitTest, TEST_DASH_SEGMENT_DOWNLOADER_WATERLINE_004, TestSize.Level1)
474 {
475 Plugins::Callback* sourceCallback = new SourceCallbackMock();
476 std::shared_ptr<DashSegmentDownloader> segmentDownloaderSp = std::make_shared<DashSegmentDownloader>(sourceCallback,
477 0, MediaAVCodec::MediaType::MEDIA_TYPE_VID, 10);
478 std::shared_ptr<DashSegment> segmentSp = std::make_shared<DashSegment>();
479 segmentSp->url_ = "http://test/index.mpd";
480 segmentSp->streamId_ = 0;
481 segmentSp->duration_ = 5;
482 segmentSp->bandwidth_ = 1024;
483 segmentSp->startNumberSeq_ = 0;
484 segmentSp->numberSeq_ = 0;
485 auto statusCallback = [] (DownloadStatus&& status, std::shared_ptr<Downloader>& downloader,
__anon59f90d7f1802(DownloadStatus&& status, std::shared_ptr<Downloader>& downloader, std::shared_ptr<DownloadRequest>& request) 486 std::shared_ptr<DownloadRequest>& request) {};
487 segmentDownloaderSp->SetStatusCallback(statusCallback);
__anon59f90d7f1902(int streamId) 488 auto doneCallback = [] (int streamId) {};
489 segmentDownloaderSp->SetDownloadDoneCallback(doneCallback);
490 segmentDownloaderSp->SetDemuxerState();
491 segmentDownloaderSp->SetCurrentBitRate(1048576);
492 unsigned char buffer[1024];
493 ReadDataInfo readDataInfo;
494 readDataInfo.streamId_ = 1;
495 readDataInfo.wantReadLength_ = 1024;
496 readDataInfo.realReadLength_ = 0;
497 readDataInfo.nextStreamId_ = 1;
498 std::atomic<bool> isInterruptNeeded = false;
499 segmentDownloaderSp->Open(segmentSp);
500 DashReadRet result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
501 EXPECT_EQ(result, DASH_READ_AGAIN);
502 result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
503 EXPECT_EQ(result, DASH_READ_AGAIN);
504 isInterruptNeeded.store(true);
505 result = segmentDownloaderSp->Read(buffer, readDataInfo, isInterruptNeeded);
506 segmentDownloaderSp->Close(true, true);
507 EXPECT_EQ(result, DASH_READ_INTERRUPT);
508 delete sourceCallback;
509 sourceCallback = nullptr;
510 }
511 }
512 }
513 }
514 }