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 DASH_MPD_DEF_H
17 #define DASH_MPD_DEF_H
18 
19 #include <map>
20 #include "mpd_parser_def.h"
21 
22 namespace OHOS {
23 namespace Media {
24 namespace Plugins {
25 namespace HttpPlugin {
26 static const char *const VIDEO_MIME_TYPE = "video";
27 static const char *const AUDIO_MIME_TYPE = "audio";
28 static const char *const TEXT_MIME_TYPE = "text";
29 static const char *const APPLICATION_MIME_TYPE = "application";
30 
31 enum class VideoScanType { VIDEO_SCAN_PROGRESSIVE, VIDEO_SCAN_INTERLACED, VIDEO_SCAN_UNKNOW };
32 
33 enum class DashType { DASH_TYPE_STATIC, DASH_TYPE_DYNAMIC };
34 
35 struct DashSegUrl {
36     std::string media_;
37     std::string mediaRange_;
38     std::string index_;
39     std::string indexRange_;
40 };
41 
42 struct DashDescriptor {
43     std::string schemeIdUrl_;
44     std::string value_;
45     std::string defaultKid_;
46     std::map<std::string, std::string> elementMap_;
47 };
48 
49 struct DashSegTimeline {
50     uint64_t t_{0};
51     uint64_t d_{0};
52     int32_t r_{0};
53 };
54 
55 struct DashUrlType {
56     std::string sourceUrl_;
57     std::string range_;
58 };
59 
60 struct DashSegBaseInfo {
61     uint32_t timeScale_{0};
62     uint32_t presentationTimeOffset_{0};
63     std::string indexRange_;
64     bool indexRangeExact_{false};
65 
66     DashUrlType *initialization_{nullptr};
67     DashUrlType *representationIndex_{nullptr};
68 };
69 
70 struct DashMultSegBaseInfo {
71     uint32_t duration_{0};
72     std::string startNumber_; // if not present, the value set to 1.
73 
74     DashUrlType *bitstreamSwitching_{nullptr};
75     DashList<DashSegTimeline *> segTimeline_;
76     DashSegBaseInfo segBaseInfo_;
77 };
78 
79 // SegmentTemplate Element Infomation
80 struct DashSegTmpltInfo {
81     std::string segTmpltMedia_;
82     std::string segTmpltIndex_;
83     std::string segTmpltInitialization_;
84     std::string segTmpltBitstreamSwitching_;
85     DashMultSegBaseInfo multSegBaseInfo_;
86 };
87 
88 // SegmentList Element Infomation. <href> <actuate> are not support
89 struct DashSegListInfo {
90     DashList<DashSegUrl *> segmentUrl_;
91     DashMultSegBaseInfo multSegBaseInfo_;
92 };
93 
94 // <segmentProfiles> <codecs> <maximumSAPPeriod> <startWithSAP> <maxPlayoutRate> <codingDependency> <FramePacking>
95 // <AudioChannelConfiguration> are not support
96 struct DashCommonAttrsAndElements {
97     bool codingDependency_{false};
98     uint32_t width_{0};
99     uint32_t height_{0};
100     uint32_t startWithSAP_{0};
101     double maxPlayoutRate_{1.0};
102     std::string profiles_;
103     std::string sar_;
104     std::string frameRate_;
105     std::string audioSamplingRate_;
106     DashList<DashDescriptor *> audioChannelConfigurationList_;
107     std::string mimeType_;
108     std::string codecs_;
109     std::string cuvvVersion_; // private element
110     VideoScanType scanType_{VideoScanType::VIDEO_SCAN_PROGRESSIVE};
111     DashList<DashDescriptor *> contentProtectionList_;
112     DashList<DashDescriptor *> essentialPropertyList_;
113 };
114 
115 // Representation Element Infomation. <dependencyId> <mediaStreamStructureId> <SubRepresentation> are not support
116 struct DashRepresentationInfo {
117     std::string id_;
118     uint32_t bandwidth_{0};
119     uint32_t qualityRanking_{0};
120     std::list<std::string> baseUrl_;
121     std::string volumeAdjust_;
122 
123     DashSegBaseInfo *representationSegBase_{nullptr};
124     DashSegListInfo *representationSegList_{nullptr};
125     DashSegTmpltInfo *representationSegTmplt_{nullptr};
126 
127     DashCommonAttrsAndElements commonAttrsAndElements_;
128 };
129 
130 struct DashContentCompInfo {
131     uint32_t id_{0};
132     std::string lang_;
133     std::string contentType_;
134     std::string par_;
135     DashList<DashDescriptor *> roleList_;
136 };
137 
138 struct DashAdptSetInfo {
139     bool segmentAlignment_{false};
140     bool subSegmentAlignment_{false};
141     bool bitstreamSwitching_{false};
142     uint32_t id_{0};
143     uint32_t group_{0};
144     uint32_t minBandwidth_{0};
145     uint32_t maxBandwidth_{0};
146     uint32_t minWidth_{0};
147     uint32_t maxWidth_{0};
148     uint32_t minHeight_{0};
149     uint32_t maxHeight_{0};
150     uint32_t cameraIndex_{0}; // only for hw multi view
151     int32_t subSegmentStartsWithSAP_{0};
152     std::string lang_;
153     std::string contentType_;
154     std::string par_;
155     std::string minFrameRate_;
156     std::string maxFrameRate_;
157     std::string mimeType_;
158     std::string videoType_; // only for hw multi view
159 
160     DashSegBaseInfo *adptSetSegBase_{nullptr};
161     DashSegListInfo *adptSetSegList_{nullptr};
162     DashSegTmpltInfo *adptSetSegTmplt_{nullptr};
163 
164     std::list<std::string> baseUrl_;
165     DashList<DashContentCompInfo *> contentCompList_;
166     DashList<DashRepresentationInfo *> representationList_;
167     DashList<DashDescriptor *> roleList_;
168     DashCommonAttrsAndElements commonAttrsAndElements_;
169 };
170 
171 // Period Element Infomation. <href> <actuate> <subset> are not support
172 struct DashPeriodInfo {
173     uint32_t start_{0};
174     uint32_t duration_{0};
175     bool bitstreamSwitching_{false};
176     std::string id_;
177     std::list<std::string> baseUrl_;
178 
179     DashSegBaseInfo *periodSegBase_{nullptr};
180     DashSegListInfo *periodSegList_{nullptr};
181     DashSegTmpltInfo *periodSegTmplt_{nullptr};
182     DashList<DashAdptSetInfo *> adptSetList_;
183 };
184 
185 // MPD Element Infomation. ProgramInfomation Location Metrics are not support
186 struct DashMpdInfo {
187     DashType type_{DashType::DASH_TYPE_STATIC};
188     uint32_t mediaPresentationDuration_{0};
189     uint32_t minimumUpdatePeriod_{0};
190     uint32_t minBufferTime_{0};
191     uint32_t timeShiftBufferDepth_{0};
192     uint32_t suggestedPresentationDelay_{0};
193     uint32_t maxSegmentDuration_{0};
194     uint32_t maxSubSegmentDuration_{0};
195     uint32_t hwTotalViewNumber_{0};
196     uint32_t hwDefaultViewIndex_{0};
197     int64_t availabilityStartTime_{0};
198     int64_t availabilityEndTime_{0};
199     std::string mediaType_;
200     std::string profile_;
201     std::list<std::string> baseUrl_;
202     DashList<DashPeriodInfo *> periodInfoList_;
203 };
204 } // namespace HttpPluginLite
205 } // namespace Plugin
206 } // namespace Media
207 } // namespace OHOS
208 #endif // DASH_MPD_DEF_H
209