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_DASH_COMMON_H 17 #define HISTREAMER_DASH_COMMON_H 18 19 #include <string> 20 #include "av_common.h" 21 22 namespace OHOS { 23 namespace Media { 24 namespace Plugins { 25 namespace HttpPlugin { 26 constexpr const char *const DRM_URN_UUID_PREFIX = "urn:uuid:"; 27 28 using DashSegmentInitValue = enum DashSegmentInitValue { 29 DASH_SEGMENT_INIT_FAILED = -1, 30 DASH_SEGMENT_INIT_SUCCESS, 31 DASH_SEGMENT_INIT_UNDO 32 }; 33 34 using DashSegsState = enum DashSegsState { 35 DASH_SEGS_STATE_NONE, 36 DASH_SEGS_STATE_PARSING, 37 DASH_SEGS_STATE_FINISH 38 }; 39 40 using DashVideoType = enum DashVideoType { 41 DASH_VIDEO_TYPE_SDR, 42 DASH_VIDEO_TYPE_HDR_VIVID, 43 DASH_VIDEO_TYPE_HDR_10 44 }; 45 46 struct DashSegment { DashSegmentDashSegment47 DashSegment() 48 { 49 streamId_ = -1; 50 duration_ = 0; 51 bandwidth_ = 0; 52 startNumberSeq_ = 1; 53 numberSeq_ = 1; 54 startRangeValue_ = 0; 55 endRangeValue_ = 0; 56 isLast_ = false; 57 } 58 DashSegmentDashSegment59 DashSegment(const DashSegment& srcSegment) 60 { 61 streamId_ = srcSegment.streamId_; 62 duration_ = srcSegment.duration_; 63 bandwidth_ = srcSegment.bandwidth_; 64 startNumberSeq_ = srcSegment.startNumberSeq_; 65 numberSeq_ = srcSegment.numberSeq_; 66 startRangeValue_ = srcSegment.startRangeValue_; 67 endRangeValue_ = srcSegment.endRangeValue_; 68 url_ = srcSegment.url_; 69 byteRange_ = srcSegment.byteRange_; 70 isLast_ = srcSegment.isLast_; 71 } 72 73 DashSegment& operator=(const DashSegment& srcSegment) 74 { 75 if (this != &srcSegment) { 76 streamId_ = srcSegment.streamId_; 77 duration_ = srcSegment.duration_; 78 bandwidth_ = srcSegment.bandwidth_; 79 startNumberSeq_ = srcSegment.startNumberSeq_; 80 numberSeq_ = srcSegment.numberSeq_; 81 startRangeValue_ = srcSegment.startRangeValue_; 82 endRangeValue_ = srcSegment.endRangeValue_; 83 url_ = srcSegment.url_; 84 byteRange_ = srcSegment.byteRange_; 85 isLast_ = srcSegment.isLast_; 86 } 87 return *this; 88 } 89 90 int32_t streamId_; 91 unsigned int duration_; 92 unsigned int bandwidth_; 93 int64_t startNumberSeq_; 94 int64_t numberSeq_; 95 int64_t startRangeValue_; 96 int64_t endRangeValue_; 97 std::string url_; 98 std::string byteRange_; 99 bool isLast_; 100 }; 101 102 struct DashIndexSegment { DashIndexSegmentDashIndexSegment103 DashIndexSegment() 104 { 105 indexRangeBegin_ = 0; 106 indexRangeEnd_ = 0; 107 } 108 109 int64_t indexRangeBegin_; 110 int64_t indexRangeEnd_; 111 std::string url_; 112 }; 113 114 using InitSegmentState = enum InitSegmentState { 115 INIT_SEGMENT_STATE_UNUSE, 116 INIT_SEGMENT_STATE_USING, 117 INIT_SEGMENT_STATE_USED 118 }; 119 120 struct DashInitSegment { DashInitSegmentDashInitSegment121 DashInitSegment() 122 { 123 isDownloadFinish_ = false; 124 streamId_ = 0; 125 readIndex_ = 0; 126 rangeBegin_ = 0; 127 rangeEnd_ = 0; 128 readState_ = INIT_SEGMENT_STATE_USED; 129 writeState_ = INIT_SEGMENT_STATE_USED; 130 } 131 132 bool isDownloadFinish_; 133 int streamId_; 134 unsigned int readIndex_; 135 int64_t rangeBegin_; 136 int64_t rangeEnd_; 137 std::string url_; 138 std::string content_; 139 InitSegmentState readState_; // no need to get init segment as init segment is null 140 InitSegmentState writeState_; 141 }; 142 143 struct DashStreamDescription { DashStreamDescriptionDashStreamDescription144 DashStreamDescription() 145 { 146 } 147 DashStreamDescriptionDashStreamDescription148 DashStreamDescription(const DashStreamDescription& desc) 149 { 150 streamId_ = desc.streamId_; 151 periodIndex_ = desc.periodIndex_; 152 adptSetIndex_ = desc.adptSetIndex_; 153 representationIndex_ = desc.representationIndex_; 154 duration_ = desc.duration_; 155 width_ = desc.width_; 156 height_ = desc.height_; 157 bandwidth_ = desc.bandwidth_; 158 startNumberSeq_ = desc.startNumberSeq_; 159 type_ = desc.type_; 160 segsState_ = desc.segsState_; 161 inUse_ = desc.inUse_; 162 videoType_ = desc.videoType_; 163 currentNumberSeq_ = desc.currentNumberSeq_; 164 lang_ = desc.lang_; 165 } 166 167 DashStreamDescription& operator=(const DashStreamDescription& desc) 168 { 169 if (this != &desc) { 170 streamId_ = desc.streamId_; 171 periodIndex_ = desc.periodIndex_; 172 adptSetIndex_ = desc.adptSetIndex_; 173 representationIndex_ = desc.representationIndex_; 174 duration_ = desc.duration_; 175 width_ = desc.width_; 176 height_ = desc.height_; 177 bandwidth_ = desc.bandwidth_; 178 startNumberSeq_ = desc.startNumberSeq_; 179 type_ = desc.type_; 180 segsState_ = desc.segsState_; 181 inUse_ = desc.inUse_; 182 videoType_ = desc.videoType_; 183 currentNumberSeq_ = desc.currentNumberSeq_; 184 lang_ = desc.lang_; 185 } 186 return *this; 187 } 188 189 DashSegsState segsState_ = DASH_SEGS_STATE_NONE; 190 bool inUse_ = false; 191 DashVideoType videoType_ = DASH_VIDEO_TYPE_SDR; 192 MediaAVCodec::MediaType type_ = MediaAVCodec::MediaType::MEDIA_TYPE_VID; 193 int streamId_ = 0; 194 unsigned int periodIndex_ = 0; 195 unsigned int adptSetIndex_ = 0; 196 unsigned int representationIndex_ = 0; 197 unsigned int duration_ = 0; 198 unsigned int width_ = 0; 199 unsigned int height_ = 0; 200 unsigned int bandwidth_ = 0; 201 int64_t startNumberSeq_ = 1; 202 int64_t currentNumberSeq_ = -1; 203 std::string lang_ {}; 204 std::shared_ptr<DashInitSegment> initSegment_ = nullptr; 205 std::shared_ptr<DashIndexSegment> indexSegment_ = nullptr; 206 std::vector<std::shared_ptr<DashSegment>> mediaSegments_; 207 }; 208 209 struct DashDrmInfo { 210 std::string drmId_; 211 std::string uuid_; 212 std::string pssh_; 213 }; 214 } 215 } 216 } 217 } 218 #endif