1 /* 2 * Copyright (c) 2022-2022 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 #ifndef HISTREAMER_PLAYLIST_DOWNLOADER_H 17 #define HISTREAMER_PLAYLIST_DOWNLOADER_H 18 19 #include <vector> 20 #include "plugin/plugins/source/http_source/download/downloader.h" 21 22 namespace OHOS { 23 namespace Media { 24 namespace Plugin { 25 namespace HttpPlugin { 26 struct PlayListChangeCallback { 27 virtual ~PlayListChangeCallback() = default; 28 virtual void OnPlayListChanged(const std::vector<std::string>& playList) = 0; 29 }; 30 class PlayListDownloader { 31 public: 32 PlayListDownloader(); 33 virtual ~PlayListDownloader(); 34 35 virtual void Open(const std::string& url) = 0; 36 virtual void UpdateManifest() = 0; 37 virtual void ParseManifest() = 0; 38 virtual void PlayListUpdateLoop() = 0; 39 virtual void SetPlayListCallback(PlayListChangeCallback* callback) = 0; 40 virtual double GetDuration() const = 0; 41 virtual Seekable GetSeekable() const = 0; 42 43 void Resume(); 44 void Pause(); 45 void Close(); 46 void SetStatusCallback(StatusCallbackFunc cb); 47 bool GetPlayListDownloadStatus(); 48 49 protected: 50 bool SaveData(uint8_t* data, uint32_t len, int64_t offset); 51 void OnDownloadStatus(DownloadStatus status, std::shared_ptr<Downloader>&, 52 std::shared_ptr<DownloadRequest>& request); 53 void DoOpen(const std::string& url); 54 55 protected: 56 std::shared_ptr<Downloader> downloader_; 57 std::shared_ptr<DownloadRequest> downloadRequest_; 58 std::shared_ptr<OSAL::Task> updateTask_; 59 DataSaveFunc dataSave_; 60 StatusCallbackFunc statusCallback_; 61 std::string playList_; 62 bool startedDownloadStatus_ {false}; 63 }; 64 } 65 } 66 } 67 } 68 #endif