• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 #define HST_LOG_TAG "Source"
17 #define MEDIA_ATOMIC_ABILITY
18 
19 #include "avcodec_trace.h"
20 #include "cpp_ext/type_traits_ext.h"
21 #include "common/log.h"
22 #include "osal/utils/util.h"
23 #include "common/media_source.h"
24 #include "plugin/plugin_manager_v2.h"
25 #include "source.h"
26 
27 namespace {
28 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, LOG_DOMAIN_SYSTEM_PLAYER, "Source" };
29 }
30 
31 namespace OHOS {
32 namespace Media {
33 using namespace Plugins;
34 
35 static std::map<std::string, ProtocolType> g_protocolStringToType = {
36     {"http", ProtocolType::HTTP},
37     {"https", ProtocolType::HTTPS},
38     {"file", ProtocolType::FILE},
39     {"stream", ProtocolType::STREAM},
40     {"fd", ProtocolType::FD}
41 };
42 
43 const int32_t MAX_RETRY = 20;
44 const int32_t WAIT_TIME = 10;
45 
Source()46 Source::Source()
47     : protocol_(),
48       uri_(),
49       seekable_(Seekable::INVALID),
50       plugin_(nullptr),
51       isPluginReady_(false),
52       isAboveWaterline_(false),
53       mediaDemuxerCallback_(std::make_shared<CallbackImpl>())
54 {
55     MEDIA_LOG_D("Source called");
56 }
57 
~Source()58 Source::~Source()
59 {
60     MEDIA_LOG_D("~Source called");
61     if (plugin_) {
62         plugin_->Deinit();
63     }
64 }
65 
SetCallback(Callback * callback)66 void Source::SetCallback(Callback* callback)
67 {
68     MEDIA_LOG_I("SetCallback entered.");
69     FALSE_RETURN_MSG(callback != nullptr, "callback is nullptr");
70     FALSE_RETURN_MSG(mediaDemuxerCallback_ != nullptr, "mediaDemuxerCallback is nullptr");
71     mediaDemuxerCallback_->SetCallbackWrap(callback);
72 }
73 
ClearData()74 void Source::ClearData()
75 {
76     protocol_.clear();
77     uri_.clear();
78     seekable_ = Seekable::INVALID;
79     isPluginReady_ = false;
80     isAboveWaterline_ = false;
81     seekToTimeFlag_ = false;
82 }
83 
IsFlvLiveStream() const84 bool Source::IsFlvLiveStream() const
85 {
86     return isFlvLiveStream_;
87 }
SetSource(const std::shared_ptr<MediaSource> & source)88 Status Source::SetSource(const std::shared_ptr<MediaSource>& source)
89 {
90     MediaAVCodec::AVCodecTrace trace("Source::SetSource");
91     MEDIA_LOG_I("SetSource enter.");
92     FALSE_RETURN_V_MSG_E(source != nullptr, Status::ERROR_INVALID_PARAMETER, "SetSource Invalid source");
93 
94     ClearData();
95     Status ret = FindPlugin(source);
96     FALSE_RETURN_V_MSG_E(ret == Status::OK, ret, "SetSource FindPlugin failed");
97 
98     ret = InitPlugin(source);
99     FALSE_RETURN_V_MSG_E(ret == Status::OK, ret, "SetSource InitPlugin failed");
100 
101     if (plugin_ != nullptr) {
102         seekToTimeFlag_ = plugin_->IsSeekToTimeSupported();
103     }
104     MEDIA_LOG_I("SetSource seekToTimeFlag_: " PUBLIC_LOG_D32, seekToTimeFlag_);
105 
106     MEDIA_LOG_I("SetSource exit.");
107     return Status::OK;
108 }
109 
SetStartPts(int64_t startPts)110 Status Source::SetStartPts(int64_t startPts)
111 {
112     MEDIA_LOG_D("startPts=" PUBLIC_LOG_D64, startPts);
113     if (plugin_ == nullptr) {
114         MEDIA_LOG_E("SetStartPts failed, plugin_ is nullptr");
115         return Status::ERROR_INVALID_OPERATION;
116     }
117     return plugin_->SetStartPts(startPts);
118 }
119 
SetExtraCache(uint64_t cacheDuration)120 Status Source::SetExtraCache(uint64_t cacheDuration)
121 {
122     if (plugin_ == nullptr) {
123         MEDIA_LOG_E("SetExtraCache failed, plugin_ is nullptr");
124         return Status::ERROR_INVALID_OPERATION;
125     }
126     return plugin_->SetExtraCache(cacheDuration);
127 }
128 
SetBundleName(const std::string & bundleName)129 void Source::SetBundleName(const std::string& bundleName)
130 {
131     if (plugin_ != nullptr) {
132         plugin_->SetBundleName(bundleName);
133     }
134 }
135 
SetDemuxerState(int32_t streamId)136 void Source::SetDemuxerState(int32_t streamId)
137 {
138     plugin_->SetDemuxerState(streamId);
139 }
140 
InitPlugin(const std::shared_ptr<MediaSource> & source)141 Status Source::InitPlugin(const std::shared_ptr<MediaSource>& source)
142 {
143     MediaAVCodec::AVCodecTrace trace("Source::InitPlugin");
144     MEDIA_LOG_I("InitPlugin enter");
145     FALSE_RETURN_V_MSG_E(plugin_ != nullptr, Status::ERROR_INVALID_OPERATION, "InitPlugin, Source plugin is nullptr");
146 
147     Status ret = plugin_->Init();
148     FALSE_RETURN_V_MSG_E(ret == Status::OK, ret, "InitPlugin failed");
149 
150     plugin_->SetCallback(this);
151     plugin_->SetEnableOnlineFdCache(isEnableFdCache_);
152     ret = plugin_->SetSource(source);
153 
154     MEDIA_LOG_I("InitPlugin exit");
155     return ret;
156 }
157 
Prepare()158 Status Source::Prepare()
159 {
160     MEDIA_LOG_I("Prepare entered.");
161     if (plugin_ == nullptr) {
162         return Status::OK;
163     }
164     Status ret = plugin_->Prepare();
165     if (ret == Status::OK) {
166         MEDIA_LOG_D("media source send EVENT_READY");
167     } else if (ret == Status::ERROR_DELAY_READY) {
168         if (isAboveWaterline_) {
169             MEDIA_LOG_D("media source send EVENT_READY");
170             isPluginReady_ = false;
171             isAboveWaterline_ = false;
172         }
173     }
174     return ret;
175 }
176 
IsSeekToTimeSupported()177 bool Source::IsSeekToTimeSupported()
178 {
179     return seekToTimeFlag_;
180 }
181 
Start()182 Status Source::Start()
183 {
184     MEDIA_LOG_I("Start entered.");
185     return plugin_ ? plugin_->Start() : Status::ERROR_INVALID_OPERATION;
186 }
187 
GetBitRates(std::vector<uint32_t> & bitRates)188 Status Source::GetBitRates(std::vector<uint32_t>& bitRates)
189 {
190     MEDIA_LOG_I("GetBitRates");
191     if (plugin_ == nullptr) {
192         MEDIA_LOG_E("GetBitRates failed, plugin_ is nullptr");
193         return Status::ERROR_INVALID_OPERATION;
194     }
195     return plugin_->GetBitRates(bitRates);
196 }
197 
SelectBitRate(uint32_t bitRate)198 Status Source::SelectBitRate(uint32_t bitRate)
199 {
200     MEDIA_LOG_I("SelectBitRate" PUBLIC_LOG_U32, bitRate);
201     if (plugin_ == nullptr) {
202         MEDIA_LOG_E("SelectBitRate failed, plugin_ is nullptr");
203         return Status::ERROR_INVALID_OPERATION;
204     }
205     return plugin_->SelectBitRate(bitRate);
206 }
207 
StopBufferring(bool flag)208 Status Source::StopBufferring(bool flag)
209 {
210     FALSE_RETURN_V_MSG_E(plugin_ != nullptr, Status::ERROR_INVALID_OPERATION,
211         "StopBufferring failed, plugin_ is nullptr!");
212     MEDIA_LOG_I("StopBufferring begin, flag = " PUBLIC_LOG_D32, flag);
213     return plugin_->StopBufferring(flag);
214 }
215 
SetCurrentBitRate(int32_t bitRate,int32_t streamID)216 Status Source::SetCurrentBitRate(int32_t bitRate, int32_t streamID)
217 {
218     MEDIA_LOG_I("SetCurrentBitRate");
219     if (plugin_ == nullptr) {
220         MEDIA_LOG_E("SetCurrentBitRate failed, plugin_ is nullptr");
221         return Status::ERROR_INVALID_OPERATION;
222     }
223     return plugin_->SetCurrentBitRate(bitRate, streamID);
224 }
225 
SeekToTime(int64_t seekTime,SeekMode mode)226 Status Source::SeekToTime(int64_t seekTime, SeekMode mode)
227 {
228     if (seekable_ != Seekable::SEEKABLE) {
229         GetSeekable();
230     }
231     int64_t timeNs;
232     if (Plugins::Ms2HstTime(seekTime, timeNs)) {
233         return plugin_->SeekToTime(timeNs, mode);
234     } else {
235         return Status::ERROR_INVALID_PARAMETER;
236     }
237 }
238 
GetDownloadInfo(DownloadInfo & downloadInfo)239 Status Source::GetDownloadInfo(DownloadInfo& downloadInfo)
240 {
241     MEDIA_LOG_I("GetDownloadInfo");
242     if (plugin_ == nullptr) {
243         MEDIA_LOG_E("GetDownloadInfo failed, plugin_ is nullptr");
244         return Status::ERROR_INVALID_OPERATION;
245     }
246     return plugin_->GetDownloadInfo(downloadInfo);
247 }
248 
GetPlaybackInfo(PlaybackInfo & playbackInfo)249 Status Source::GetPlaybackInfo(PlaybackInfo& playbackInfo)
250 {
251     MEDIA_LOG_I("GetPlaybackInfo");
252     if (plugin_ == nullptr) {
253         MEDIA_LOG_E("GetPlaybackInfo  failed, plugin_ is nullptr");
254         return Status::ERROR_INVALID_OPERATION;
255     }
256     return plugin_->GetPlaybackInfo(playbackInfo);
257 }
258 
IsNeedPreDownload()259 bool Source::IsNeedPreDownload()
260 {
261     if (plugin_ == nullptr) {
262         MEDIA_LOG_E("IsNeedPreDownload failed, plugin_ is nullptr");
263         return false;
264     }
265     return plugin_->IsNeedPreDownload();
266 }
267 
Stop()268 Status Source::Stop()
269 {
270     MEDIA_LOG_I("Stop entered.");
271     seekable_ = Seekable::INVALID;
272     protocol_.clear();
273     uri_.clear();
274     return plugin_->Stop();
275 }
276 
Pause()277 Status Source::Pause()
278 {
279     MEDIA_LOG_I("Pause entered.");
280     if (plugin_ != nullptr) {
281         plugin_->Pause();
282     }
283     return Status::OK;
284 }
285 
Resume()286 Status Source::Resume()
287 {
288     MEDIA_LOG_I("Resume entered.");
289     if (plugin_ != nullptr) {
290         plugin_->Resume();
291     }
292     return Status::OK;
293 }
294 
SetReadBlockingFlag(bool isReadBlockingAllowed)295 Status Source::SetReadBlockingFlag(bool isReadBlockingAllowed)
296 {
297     MEDIA_LOG_D("SetReadBlockingFlag entered, IsReadBlockingAllowed %{public}d", isReadBlockingAllowed);
298     FALSE_RETURN_V(plugin_ != nullptr, Status::OK);
299     return plugin_->SetReadBlockingFlag(isReadBlockingAllowed);
300 }
301 
OnEvent(const Plugins::PluginEvent & event)302 void Source::OnEvent(const Plugins::PluginEvent& event)
303 {
304     MEDIA_LOG_D("OnEvent");
305     if (protocol_ == "http" && isInterruptNeeded_) {
306         MEDIA_LOG_I("http OnEvent isInterruptNeeded, return");
307         return;
308     }
309     if (event.type == PluginEventType::ABOVE_LOW_WATERLINE) {
310         if (isPluginReady_ && isAboveWaterline_) {
311             isPluginReady_ = false;
312             isAboveWaterline_ = false;
313         }
314         return;
315     }
316     FALSE_RETURN_MSG(mediaDemuxerCallback_ != nullptr, "mediaDemuxerCallback is nullptr");
317     if (event.type == PluginEventType::CLIENT_ERROR || event.type == PluginEventType::SERVER_ERROR) {
318         MEDIA_LOG_I("Error happened, need notify client by OnEvent");
319         mediaDemuxerCallback_->OnEvent(event);
320     } else if (event.type == PluginEventType::SOURCE_DRM_INFO_UPDATE) {
321         MEDIA_LOG_I("Drminfo updates from source");
322         mediaDemuxerCallback_->OnEvent(event);
323     } else if (event.type == PluginEventType::BUFFERING_END || event.type == PluginEventType::BUFFERING_START) {
324         MEDIA_LOG_I("Buffering start or end.");
325         mediaDemuxerCallback_->OnEvent(event);
326     } else if (event.type == PluginEventType::SOURCE_BITRATE_START) {
327         MEDIA_LOG_I("source bitrate start from source.");
328         mediaDemuxerCallback_->OnEvent(event);
329     } else if (event.type == PluginEventType::CACHED_DURATION) {
330         MEDIA_LOG_D("Onevent cached duration.");
331         mediaDemuxerCallback_->OnEvent(event);
332     } else if (event.type == PluginEventType::EVENT_BUFFER_PROGRESS) {
333         MEDIA_LOG_I("buffer percent update.");
334         mediaDemuxerCallback_->OnEvent(event);
335     } else if (event.type == PluginEventType::INITIAL_BUFFER_SUCCESS) {
336         MEDIA_LOG_I("initial buffer success.");
337         mediaDemuxerCallback_->OnEvent(event);
338     } else if (event.type == PluginEventType::DASH_SEEK_READY) {
339         MEDIA_LOG_D("Onevent dash seek ready.");
340         mediaDemuxerCallback_->OnEvent(event);
341     }  else if (event.type == PluginEventType::HLS_SEEK_READY) {
342         MEDIA_LOG_D("Onevent hls seek ready.");
343         mediaDemuxerCallback_->OnEvent(event);
344     } else {
345         MEDIA_LOG_I("on event type undefined.");
346     }
347 }
348 
SetSelectBitRateFlag(bool flag,uint32_t desBitRate)349 void Source::SetSelectBitRateFlag(bool flag, uint32_t desBitRate)
350 {
351     if (mediaDemuxerCallback_) {
352         mediaDemuxerCallback_->SetSelectBitRateFlag(flag, desBitRate);
353     }
354 }
355 
CanAutoSelectBitRate()356 bool Source::CanAutoSelectBitRate()
357 {
358     FALSE_RETURN_V_MSG_E(mediaDemuxerCallback_ != nullptr, false, "mediaDemuxerCallback_ is nullptr.");
359     return mediaDemuxerCallback_->CanAutoSelectBitRate();
360 }
361 
SetInterruptState(bool isInterruptNeeded)362 void Source::SetInterruptState(bool isInterruptNeeded)
363 {
364     MEDIA_LOG_I("Source OnInterrupted %{public}d", isInterruptNeeded);
365     std::unique_lock<std::mutex> lock(mutex_);
366     isInterruptNeeded_ = isInterruptNeeded;
367     if (plugin_) {
368         plugin_->SetInterruptState(isInterruptNeeded_);
369     }
370     seekCond_.notify_all();
371 }
372 
GetSeekable()373 Plugins::Seekable Source::GetSeekable()
374 {
375     FALSE_RETURN_V_MSG_E(plugin_ != nullptr, Plugins::Seekable::INVALID, "GetSeekable, Source plugin is nullptr");
376     int32_t retry {0};
377     seekable_ = Seekable::INVALID;
378     do {
379         seekable_ = plugin_->GetSeekable();
380         retry++;
381         if (seekable_ == Seekable::INVALID) {
382             if (retry >= MAX_RETRY) {
383                 break;
384             }
385             std::unique_lock<std::mutex> lock(mutex_);
386             seekCond_.wait_for(lock, std::chrono::milliseconds(WAIT_TIME), [&] { return isInterruptNeeded_.load(); });
387         }
388     } while (seekable_ == Seekable::INVALID && !isInterruptNeeded_.load());
389     return seekable_;
390 }
391 
GetUriSuffix(const std::string & uri)392 std::string Source::GetUriSuffix(const std::string& uri)
393 {
394     MEDIA_LOG_D("IN");
395     std::string suffix;
396     auto const pos = uri.find_last_of('.');
397     if (pos != std::string::npos) {
398         suffix = uri.substr(pos + 1);
399     }
400     return suffix;
401 }
402 
Read(int32_t streamID,std::shared_ptr<Buffer> & buffer,uint64_t offset,size_t expectedLen)403 Status Source::Read(int32_t streamID, std::shared_ptr<Buffer>& buffer, uint64_t offset, size_t expectedLen)
404 {
405     FALSE_RETURN_V_MSG_E(plugin_ != nullptr, Status::ERROR_INVALID_OPERATION, "ReadData, Source plugin is nullptr");
406     FALSE_RETURN_V_NOLOG(!perfRecEnabled_, ReadWithPerfRecord(streamID, buffer, offset, expectedLen));
407     if (seekToTimeFlag_) {
408         return plugin_->Read(streamID, buffer, offset, expectedLen);
409     }
410     return plugin_->Read(buffer, offset, expectedLen);
411 }
412 
SetPerfRecEnabled(bool perfRecEnabled)413 Status Source::SetPerfRecEnabled(bool perfRecEnabled)
414 {
415     perfRecEnabled_ = perfRecEnabled;
416     return Status::OK;
417 }
418 
ReadWithPerfRecord(int32_t streamID,std::shared_ptr<Buffer> & buffer,uint64_t offset,size_t expectedLen)419 Status Source::ReadWithPerfRecord(
420     int32_t streamID, std::shared_ptr<Buffer>& buffer, uint64_t offset, size_t expectedLen)
421 {
422     int64_t readDuration = 0;
423     Status readRes = Status::OK;
424     if (seekToTimeFlag_) {
425         readDuration = CALC_EXPR_TIME_MS(readRes = plugin_->Read(streamID, buffer, offset, expectedLen));
426     } else {
427         readDuration = CALC_EXPR_TIME_MS(readRes = plugin_->Read(buffer, offset, expectedLen));
428     }
429     int64_t readDurationUs = 0;
430     FALSE_RETURN_V_MSG(
431         Plugins::Ms2Us(readDuration, readDurationUs), readRes, "Invalid readDuration %{public}" PRId64, readDuration);
432     int64_t readSpeed = static_cast<int64_t>(expectedLen) / readDurationUs;
433     FALSE_RETURN_V_NOLOG(perfRecorder_.Record(readSpeed) == PerfRecorder::FULL, readRes);
434     FALSE_RETURN_V_MSG(mediaDemuxerCallback_ != nullptr, readRes, "Report perf failed, callback is nullptr");
435     mediaDemuxerCallback_->OnDfxEvent(
436         { .type = Plugins::PluginDfxEventType::PERF_SOURCE, .param = perfRecorder_.GetMainPerfData() });
437     perfRecorder_.Reset();
438     return readRes;
439 }
440 
SeekTo(uint64_t offset)441 Status Source::SeekTo(uint64_t offset)
442 {
443     FALSE_RETURN_V_MSG_E(plugin_ != nullptr, Status::ERROR_INVALID_OPERATION, "SeekTo, Source plugin is nullptr");
444     return plugin_->SeekTo(offset);
445 }
446 
GetStreamInfo(std::vector<StreamInfo> & streams)447 Status Source::GetStreamInfo(std::vector<StreamInfo>& streams)
448 {
449     FALSE_RETURN_V_MSG_E(plugin_ != nullptr, Status::ERROR_INVALID_OPERATION,
450         "GetStreamInfo, Source plugin is nullptr");
451     Status ret = plugin_->GetStreamInfo(streams);
452     if (ret == Status::OK && streams.size() == 0) {
453         MEDIA_LOG_I("GetStreamInfo empty, MIX Stream");
454         Plugins::StreamInfo info;
455         info.streamId = 0;
456         info.bitRate = 0;
457         info.type = Plugins::MIXED;
458         streams.push_back(info);
459     }
460     for (auto& iter : streams) {
461         MEDIA_LOG_I("Source GetStreamInfo id = " PUBLIC_LOG_D32 " type = " PUBLIC_LOG_D32,
462             iter.streamId, iter.type);
463     }
464     return ret;
465 }
466 
GetProtocolByUri()467 bool Source::GetProtocolByUri()
468 {
469     auto ret = true;
470     auto const pos = uri_.find("://");
471     if (pos != std::string::npos) {
472         auto prefix = uri_.substr(0, pos);
473         protocol_.append(prefix);
474     } else {
475         protocol_.append("file");
476         std::string fullPath;
477         ret = OSAL::ConvertFullPath(uri_, fullPath); // convert path to full path
478         if (ret && !fullPath.empty()) {
479             uri_ = fullPath;
480         }
481     }
482     return ret;
483 }
484 
ParseProtocol(const std::shared_ptr<MediaSource> & source)485 bool Source::ParseProtocol(const std::shared_ptr<MediaSource>& source)
486 {
487     bool ret = true;
488     SourceType srcType = source->GetSourceType();
489     MEDIA_LOG_D("sourceType = " PUBLIC_LOG_D32, CppExt::to_underlying(srcType));
490     if (srcType == SourceType::SOURCE_TYPE_URI) {
491         uri_ = source->GetSourceUri();
492         isFlvLiveStream_ = source->GetMediaStreamList().size() > 0;
493         std::string mimeType = source->GetMimeType();
494         if (mimeType == AVMimeTypes::APPLICATION_M3U8) {
495             protocol_ = "http";
496         } else {
497             ret = GetProtocolByUri();
498         }
499     } else if (srcType == SourceType::SOURCE_TYPE_FD) {
500         protocol_.append("fd");
501         uri_ = source->GetSourceUri();
502     } else if (srcType == SourceType::SOURCE_TYPE_STREAM) {
503         protocol_.append("stream");
504         uri_.append("stream://");
505     }
506     return ret;
507 }
508 
FindPlugin(const std::shared_ptr<MediaSource> & source)509 Status Source::FindPlugin(const std::shared_ptr<MediaSource>& source)
510 {
511     MediaAVCodec::AVCodecTrace trace("Source::FindPlugin");
512     if (!ParseProtocol(source)) {
513         MEDIA_LOG_E("Invalid source!");
514         return Status::ERROR_INVALID_PARAMETER;
515     }
516     if (protocol_.empty()) {
517         MEDIA_LOG_E("protocol_ is empty");
518         return Status::ERROR_INVALID_PARAMETER;
519     }
520     auto plugin = Plugins::PluginManagerV2::Instance().CreatePluginByMime(Plugins::PluginType::SOURCE, protocol_);
521     if (plugin != nullptr) {
522         plugin_ = std::static_pointer_cast<SourcePlugin>(plugin);
523         plugin_->SetInterruptState(isInterruptNeeded_);
524         return Status::OK;
525     }
526     MEDIA_LOG_E("Cannot find any plugin");
527     return Status::ERROR_UNSUPPORTED_FORMAT;
528 }
529 
GetDuration()530 int64_t Source::GetDuration()
531 {
532     FALSE_RETURN_V_MSG_W(seekToTimeFlag_, Plugins::HST_TIME_NONE, "Source GetDuration return -1 for isHls false.");
533     int64_t duration;
534     Status ret = plugin_->GetDuration(duration);
535     FALSE_RETURN_V_MSG_W(ret == Status::OK, Plugins::HST_TIME_NONE, "Source GetDuration from source plugin failed.");
536     return duration;
537 }
538 
GetSize(uint64_t & fileSize)539 Status Source::GetSize(uint64_t &fileSize)
540 {
541     FALSE_RETURN_V_MSG_W(plugin_ != nullptr, Status::ERROR_INVALID_OPERATION, "GetSize Source plugin is nullptr!");
542     return plugin_->GetSize(fileSize);
543 }
544 
SelectStream(int32_t streamID)545 Status Source::SelectStream(int32_t streamID)
546 {
547     FALSE_RETURN_V_MSG_W(plugin_ != nullptr, Status::ERROR_INVALID_OPERATION, "SelectStream Source plugin is nullptr!");
548     return plugin_->SelectStream(streamID);
549 }
550 
SetEnableOnlineFdCache(bool isEnableFdCache)551 void Source::SetEnableOnlineFdCache(bool isEnableFdCache)
552 {
553     isEnableFdCache_ = isEnableFdCache;
554 }
555 
GetSegmentOffset()556 size_t Source::GetSegmentOffset()
557 {
558     FALSE_RETURN_V_MSG_W(plugin_ != nullptr, 0, "GetSegmentOffset source plugin is nullptr!");
559     return plugin_->GetSegmentOffset();
560 }
561 
GetHLSDiscontinuity()562 bool Source::GetHLSDiscontinuity()
563 {
564     FALSE_RETURN_V_MSG_W(plugin_ != nullptr, false, "GetHLSDiscontinuity source plugin is nullptr!");
565     return plugin_->GetHLSDiscontinuity();
566 }
567 
SetInitialBufferSize(int32_t offset,int32_t size)568 bool Source::SetInitialBufferSize(int32_t offset, int32_t size)
569 {
570     FALSE_RETURN_V_MSG_W(plugin_ != nullptr, false, "SetInitialBufferSize source plugin is nullptr");
571     return plugin_->SetSourceInitialBufferSize(offset, size);
572 }
573 
WaitForBufferingEnd()574 void Source::WaitForBufferingEnd()
575 {
576     FALSE_RETURN_MSG(plugin_ != nullptr, "WaitForBufferingEnd source plugin is nullptr");
577     return plugin_->WaitForBufferingEnd();
578 }
579 
NotifyInitSuccess()580 void Source::NotifyInitSuccess()
581 {
582     FALSE_RETURN_MSG(plugin_ != nullptr, "NotifyInitSuccess source plugin is nullptr");
583     plugin_->NotifyInitSuccess();
584 }
585 
IsLocalFd()586 bool Source::IsLocalFd()
587 {
588     FALSE_RETURN_V_MSG_W(plugin_ != nullptr, false, "IsLocalFd source plugin is nullptr");
589     return plugin_->IsLocalFd();
590 }
591 
GetCachedDuration()592 uint64_t Source::GetCachedDuration()
593 {
594     FALSE_RETURN_V_MSG_E(plugin_ != nullptr, 0, "plugin_ is nullptr");
595     return plugin_->GetCachedDuration();
596 }
597 
RestartAndClearBuffer()598 void Source::RestartAndClearBuffer()
599 {
600     FALSE_RETURN_MSG(plugin_ != nullptr, "plugin_ is nullptr");
601     return plugin_->RestartAndClearBuffer();
602 }
603 
IsFlvLive()604 bool Source::IsFlvLive()
605 {
606     FALSE_RETURN_V_MSG_E(plugin_ != nullptr, false, "plugin_ is nullptr");
607     return plugin_->IsFlvLive();
608 }
609 
IsHlsFmp4()610 bool Source::IsHlsFmp4()
611 {
612     FALSE_RETURN_V_MSG_E(plugin_ != nullptr, false, "plugin_ is nullptr");
613     return plugin_->IsHlsFmp4();
614 }
615 } // namespace Media
616 } // namespace OHOS