1 /* 2 * Copyright (c) 2024-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 #ifndef HISTREAMER_HLS_PLAYLIST_DOWNLOADER_H 17 #define HISTREAMER_HLS_PLAYLIST_DOWNLOADER_H 18 19 #include "playlist_downloader.h" 20 #include "m3u8.h" 21 22 namespace OHOS { 23 namespace Media { 24 namespace Plugins { 25 namespace HttpPlugin { 26 class HlsPlayListDownloader : public PlayListDownloader { 27 public: 28 using PlayListDownloader::PlayListDownloader; 29 ~HlsPlayListDownloader() override; 30 31 void Open(const std::string& url, const std::map<std::string, std::string>& httpHeader) override; 32 void UpdateManifest() override; 33 void ParseManifest(const std::string& location, bool isPreParse = false) override; 34 void SetPlayListCallback(PlayListChangeCallback* callback) override; 35 int64_t GetDuration() const override; 36 Seekable GetSeekable() const override; 37 void SelectBitRate(uint32_t bitRate) override; 38 std::vector<uint32_t> GetBitRates() override; 39 uint64_t GetCurrentBitRate() override; 40 int GetVedioHeight() override; 41 int GetVedioWidth() override; 42 bool IsBitrateSame(uint32_t bitRate) override; 43 uint32_t GetCurBitrate() override; 44 bool IsLive() const override; 45 void NotifyListChange(); 46 void SetMimeType(const std::string& mimeType) override; 47 void PreParseManifest(const std::string& location) override; 48 bool IsParseAndNotifyFinished() override; 49 bool IsParseFinished() override; 50 std::string GetUrl(); 51 std::shared_ptr<M3U8MasterPlaylist> GetMaster(); 52 std::shared_ptr<M3U8VariantStream> GetCurrentVariant(); 53 std::shared_ptr<M3U8VariantStream> GetNewVariant(); 54 size_t GetSegmentOffset(uint32_t tsIndex) override; 55 bool GetHLSDiscontinuity() override; 56 void SetInitResolution(uint32_t width, uint32_t height) override; 57 58 private: 59 void UpdateMasterInfo(bool isPreParse); 60 void UpdateMasterAndNotifyList(bool isPreParse); 61 private: 62 std::string url_ {}; 63 PlayListChangeCallback* callback_ {nullptr}; 64 std::shared_ptr<M3U8MasterPlaylist> master_; 65 std::shared_ptr<M3U8VariantStream> currentVariant_; 66 std::shared_ptr<M3U8VariantStream> newVariant_; 67 std::string mimeType_; 68 std::atomic<bool> isParseFinished_ {false}; 69 std::atomic<bool> isNotifyPlayListFinished_ {false}; 70 std::atomic<bool> isLiveUpdateTaskStarted_ {false}; 71 uint32_t initResolution_ {0}; 72 }; 73 } 74 } 75 } 76 } 77 #endif