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_M3U8_H 17 #define HISTREAMER_M3U8_H 18 19 #include <memory> 20 #include <string> 21 #include <list> 22 #include "hls_tags.h" 23 24 namespace OHOS { 25 namespace Media { 26 namespace Plugin { 27 namespace HttpPlugin { 28 enum class M3U8MediaType : int32_t { 29 M3U8_MEDIA_TYPE_INVALID = -1, 30 M3U8_MEDIA_TYPE_AUDIO, 31 M3U8_MEDIA_TYPE_VIDEO, 32 M3U8_MEDIA_TYPE_SUBTITLES, 33 M3U8_MEDIA_TYPE_CLOSED_CAPTIONS, 34 M3U8_N_MEDIA_TYPES, 35 }; 36 37 struct M3U8InitFile { 38 std::string uri; 39 int offset; 40 int size; 41 }; 42 43 struct M3U8Fragment { 44 M3U8Fragment(std::string uri, std::string title, double duration, int sequence, bool discont); 45 std::string uri_; 46 std::string title_; 47 double duration_; 48 int64_t sequence_; 49 bool discont_ {false}; 50 std::string key_ {}; 51 int iv_[16] {0}; 52 int offset_ {-1}; 53 int size_ {0}; 54 }; 55 56 struct M3U8 { 57 M3U8(std::string uri, std::string name); 58 bool Update(std::string& playList); 59 void UpdateFromTags(std::list<std::shared_ptr<Tag>>& tags); 60 void GetExtInf(const std::shared_ptr<Tag>& tag, double& duration, std::string& title) const; 61 double GetDuration() const; 62 bool IsLive() const; 63 64 std::string uri_; 65 std::string name_; 66 67 double targetDuration_ {0.0}; 68 bool bLive_ {}; 69 std::list<std::shared_ptr<M3U8Fragment>> files_; 70 int64_t sequence_ {1}; // default 1 71 int discontSequence_ {0}; 72 std::string playList_; 73 }; 74 75 struct M3U8Media { 76 M3U8MediaType type_; 77 std::string groupID_; 78 std::string name_; 79 std::string lang_; 80 std::string uri_; 81 bool isDefault_; 82 bool autoSelect_; 83 bool forced_; 84 std::shared_ptr<M3U8> m3u8_; 85 }; 86 87 struct M3U8VariantStream { 88 M3U8VariantStream(std::string name, std::string uri, std::shared_ptr<M3U8> m3u8); 89 std::string name_; 90 std::string uri_; 91 std::string codecs_; 92 uint64_t bandWidth_ {}; 93 int programID_ {}; 94 int width_ {}; 95 int height_ {}; 96 bool iframe_ {false}; 97 std::shared_ptr<M3U8> m3u8_; 98 std::list<M3U8Media> media_; 99 }; 100 101 struct M3U8MasterPlaylist { 102 M3U8MasterPlaylist(std::string& playList, const std::string& uri); 103 void UpdateMediaPlaylist(); 104 void UpdateMasterPlaylist(); 105 std::list<std::shared_ptr<M3U8VariantStream>> variants_; 106 std::shared_ptr<M3U8VariantStream> defaultVariant_; 107 std::string uri_; 108 bool isSimple_ {false}; 109 std::string playList_; 110 double duration_ {0}; 111 bool bLive_ {}; 112 }; 113 } 114 } 115 } 116 } 117 #endif