Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

484 строки
13KB

  1. #ifndef _dash_parser_h_
  2. #define _dash_parser_h_
  3. #include "dash-proto.h"
  4. #include <stdint.h>
  5. #include <stddef.h>
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. enum
  10. {
  11. DASH_SEGMENT_NONE = 0,
  12. DASH_SEGMENT_BASE,
  13. DASH_SEGMENT_LIST,
  14. DASH_SEGMENT_TEMPLATE,
  15. };
  16. // https://tools.ietf.org/html/rfc6838
  17. enum
  18. {
  19. DASH_MEDIA_UNKNOWN,
  20. DASH_MEDIA_FONT, // font
  21. DASH_MEDIA_TEXT, // text
  22. DASH_MEDIA_IMAGE, // image
  23. DASH_MEDIA_AUDIO, // audio
  24. DASH_MEDIA_VIDEO, // video
  25. DASH_MEDIA_APPLICATION, // application
  26. };
  27. // 5.3.9.4.4 Template-based Segment URL construction
  28. // @media, @index, @initialization, @bitstreamSwitching
  29. // 1. Either $Number$ or $Time$ may be used but not both at the same time.
  30. // 2. $SubNumber$ shall only be present if either $Number$ or $Time$ are present as well
  31. enum
  32. {
  33. DASH_TEMPLATE_UNKNOWN,
  34. DASH_TEMPLATE_REPRESENTATIONID, // Representation@id
  35. DASH_TEMPLATE_NUMBER,
  36. DASH_TEMPLATE_BANDWIDTH, // Representation@bandwidth
  37. DASH_TEMPLATE_TIME, // SegmentTimeline@t
  38. DASH_TEMPLATE_SUBNUMBER,
  39. };
  40. enum { DASH_SCAN_UNKNOWN = 0, DASH_SCAN_PROGRESSIVE, DASH_SCAN_INTERLACED, };
  41. struct dash_urltype_t
  42. {
  43. char* source_url;
  44. char* range;
  45. };
  46. // BaseURL
  47. struct dash_url_t
  48. {
  49. size_t count;
  50. struct
  51. {
  52. char* uri;
  53. char* service_location;
  54. char* byte_range;
  55. double availability_time_offset;
  56. int availability_time_complete; // boolean
  57. } *urls;
  58. };
  59. struct dash_event_t
  60. {
  61. uint64_t presentation_time;
  62. uint64_t duration;
  63. unsigned int id;
  64. char* message_data;
  65. };
  66. struct dash_event_stream_t
  67. {
  68. char* href;
  69. char* actuate; // default: onRequest
  70. char* scheme_id_uri; // SchemeIdUri
  71. char* value;
  72. unsigned int timescale;
  73. size_t event_count;
  74. struct dash_event_t* events;
  75. };
  76. struct dash_label_t
  77. {
  78. size_t count;
  79. struct
  80. {
  81. char* label;
  82. unsigned int id;
  83. char* lang;
  84. }*labels;
  85. };
  86. struct dash_program_information_t
  87. {
  88. char* lang;
  89. char* more_information;
  90. char* title;
  91. char* source;
  92. char* copyright;
  93. };
  94. struct dash_descriptor_t
  95. {
  96. size_t count;
  97. struct
  98. {
  99. char* scheme_uri;
  100. char* value;
  101. char* id;
  102. }* descs;
  103. };
  104. struct dash_metric_t
  105. {
  106. char* metrics;
  107. size_t range_count;
  108. struct
  109. {
  110. int64_t time;
  111. int64_t duration;
  112. }* ranges;
  113. struct dash_descriptor_t reportings;
  114. };
  115. struct dash_segment_url_t
  116. {
  117. char* media;
  118. char* media_range;
  119. char* index;
  120. char* index_range;
  121. };
  122. struct dash_segment_timeline_t
  123. {
  124. size_t count;
  125. struct
  126. {
  127. uint64_t t;
  128. uint64_t n; // specifies the Segment number of the first Segment in the series.
  129. uint64_t d; // Any @d value shall not exceed the value of MPD@maxSegmentDuration
  130. uint64_t k; // default 1
  131. int r; // default 0
  132. }* S;
  133. };
  134. struct dash_segment_t
  135. {
  136. int type; // DASH_SEGMENT_BASE/DASH_SEGMENT_LIST/DASH_SEGMENT_TEMPLATE
  137. // segment base
  138. unsigned int timescale;
  139. uint64_t presentation_time_offset;
  140. uint64_t presentation_duration;
  141. int64_t time_shift_buffer_depth;
  142. char* index_range;
  143. int index_range_exact; // 0-false, 1-true
  144. double availability_time_offset;
  145. int availability_time_complete;
  146. struct dash_urltype_t initialization; // Initialization
  147. struct dash_urltype_t representation_index; // RepresentationIndex
  148. // Multiple segment base
  149. uint64_t start_number;
  150. // All Segments within this Representation element have the same duration
  151. // unless it is the last Segment within the Period, which can be significantly shorter.
  152. unsigned int duration; // specifies the constant approximate Segment duration.
  153. struct dash_segment_timeline_t segment_timeline; // SegmentTimeline
  154. struct dash_urltype_t bitstream_switching; // BitstreamSwitching
  155. // segment list
  156. char* href;
  157. char* actuate; // default: onRequest
  158. size_t segment_url_count;
  159. struct dash_segment_url_t* segment_urls; // SegmentURL
  160. // segment template
  161. char* media;
  162. char* index;
  163. char* initialization_url; // initialization
  164. char* bitstream_switching_url;
  165. };
  166. struct dash_content_component_t
  167. {
  168. unsigned int id;
  169. char* lang;
  170. char* content_type;
  171. char* par;
  172. char* tag;
  173. struct dash_descriptor_t accessibilities; // Accessibility
  174. struct dash_descriptor_t roles; // Role
  175. struct dash_descriptor_t ratings; // Rating
  176. struct dash_descriptor_t viewpoints; // Viewpoint
  177. };
  178. struct dash_representation_base_t
  179. {
  180. char* profiles;
  181. unsigned int width;
  182. unsigned int height;
  183. char* sar;
  184. char* frame_rate;
  185. char* audio_sampling_rate;
  186. char* mime_type;
  187. char* segment_profiles;
  188. char* codecs;
  189. double maxmum_sap_period;
  190. char* start_with_sap;
  191. double max_playout_rate;
  192. int coding_dependency;
  193. int scan_type; // progressive, interlaced
  194. unsigned int selection_priority; // default 1
  195. int tag;
  196. struct dash_descriptor_t frame_packings; // FramePacking
  197. struct dash_descriptor_t audio_channel_configurations; // AudioChannelConfiguration
  198. struct dash_descriptor_t content_protections; // ContentProtection
  199. struct dash_descriptor_t essentials; // EssentialProperty
  200. struct dash_descriptor_t supplementals; // SupplementalProperty
  201. size_t inband_event_stream_count;
  202. struct dash_event_stream_t* inband_event_streams; // InbandEventStream
  203. size_t switching_count;
  204. struct
  205. {
  206. unsigned int interval;
  207. int type; // media, bitstream
  208. } *switchings; // Switching
  209. size_t random_access_count;
  210. struct
  211. {
  212. unsigned int interval;
  213. int type; // closed, open, gradual
  214. int64_t min_buffer_time;
  215. unsigned int bandwidth;
  216. } *random_accesses; // RandomAccess
  217. struct dash_label_t group_labels; // GroupLabel
  218. struct dash_label_t labels; // Label
  219. };
  220. struct dash_preselection_t
  221. {
  222. char* id;
  223. char* preselection_compoents;
  224. char* lang;
  225. struct dash_representation_base_t base;
  226. struct dash_descriptor_t accessibilities; // Accessibility
  227. struct dash_descriptor_t roles; // Role
  228. struct dash_descriptor_t ratings; // Rating
  229. struct dash_descriptor_t viewpoints; // Viewpoint
  230. };
  231. struct dash_subrepresentation_t
  232. {
  233. unsigned int level;
  234. unsigned int dependency_level;
  235. unsigned int bandwidth;
  236. char* content_component;
  237. struct dash_representation_t* parent;
  238. struct dash_representation_base_t base;
  239. };
  240. struct dash_representation_t
  241. {
  242. char* id;
  243. unsigned int bandwidth;
  244. unsigned int quality_ranking;
  245. char* dependncy_id;
  246. char* association_id;
  247. char* association_type;
  248. char* media_stream_structure_id;
  249. struct dash_adaptation_set_t* parent;
  250. struct dash_representation_base_t base;
  251. struct dash_url_t base_urls; // BaseURL
  252. size_t subrepresentation_count;
  253. struct dash_subrepresentation_t* subrepresentations; // SubRepresentation
  254. struct dash_segment_t segment;
  255. };
  256. struct dash_adaptation_set_t
  257. {
  258. char* href;
  259. char* actuate; // default: onRequest
  260. unsigned int id;
  261. unsigned int group;
  262. char* lang; // und
  263. char* content_type; // text/image/audio/video/application/font
  264. char* par; // n:m 16:9
  265. unsigned int min_bandwidth;
  266. unsigned int max_bandwidth;
  267. unsigned int min_width;
  268. unsigned int max_width;
  269. unsigned int min_height;
  270. unsigned int max_height;
  271. char* min_framerate; // n/m
  272. char* max_framerate;
  273. int segment_alignment; // 0-false, 1-true
  274. int subsegment_aligment; // 0-false, 1-true
  275. int subsegment_start_with_sap; // default 0
  276. int bitstream_switching; // 0-false, 1-true
  277. struct dash_period_t* parent;
  278. struct dash_representation_base_t base;
  279. struct dash_descriptor_t accessibilities; // Accessibility
  280. struct dash_descriptor_t roles; // Role
  281. struct dash_descriptor_t ratings; // Rating
  282. struct dash_descriptor_t viewpoints; // Viewpoint
  283. size_t content_component_count;
  284. struct dash_content_component_t* content_components; // ContentComponent
  285. struct dash_url_t base_urls; // BaseURL
  286. struct dash_segment_t segment;
  287. size_t representation_count;
  288. struct dash_representation_t* representations; // Representation
  289. };
  290. struct dash_period_t
  291. {
  292. char* href;
  293. char* actuate; // default: onRequest
  294. char* id;
  295. int64_t start; // start
  296. int64_t duration; // duration
  297. int bitstream_switching; // 0-false
  298. struct dash_mpd_t* parent;
  299. struct dash_url_t base_urls; // BaseURL
  300. struct dash_segment_t segment; // SegmentBase/SegmentList/SegmentTemplate
  301. struct dash_descriptor_t asset_identifier; // AssetIdentifier
  302. size_t event_stream_count;
  303. size_t event_stream_capacity;
  304. struct dash_event_stream_t* event_streams; // EventStream
  305. size_t adaptation_set_count;
  306. struct dash_adaptation_set_t* adaptation_sets; // AdaptationSet
  307. size_t subset_count;
  308. struct
  309. {
  310. char* contains;
  311. char* id;
  312. } *subsets; // SubSet
  313. struct dash_descriptor_t supplementals; // SupplementalProperty
  314. size_t empty_adaptation_set_count;
  315. struct dash_adaptation_set_t* empty_adaptation_sets; // EmptyAdaptationSet
  316. struct dash_label_t group_labels; // GroupLabel
  317. size_t preselection_count;
  318. struct dash_preselection_t* preselections; // Preselection
  319. };
  320. struct dash_mpd_t
  321. {
  322. int type; // presentation type: 0-static, 1-dynamic
  323. char* id;
  324. char* profiles; // profiles
  325. char* availability_start_time;
  326. char* availability_end_time;
  327. char* publish_time;
  328. int64_t media_presentation_duration; // mediaPresentationDuration, MPD total duration
  329. int64_t minimum_update_period; // minimumUpdatePeriod
  330. int64_t min_buffer_time; // minBufferTime
  331. int64_t time_shift_buffer_depth; // timeShiftBufferDepth
  332. int64_t suggested_presentation_delay; // suggestedPresentationDelay
  333. int64_t max_segment_duration; // maxSegmentDuration
  334. int64_t max_subsegment_duration; // maxSubsegmentDuration
  335. char* xsi; // xmlns:xsi
  336. char* xmlns; // xmlns
  337. char* schema_location; // xsi:schemaLocation
  338. size_t info_count;
  339. struct dash_program_information_t* infos; // ProgramInfomation
  340. struct dash_url_t urls; // BaseURL
  341. size_t location_count;
  342. char** locations; // Location
  343. size_t period_count;
  344. struct dash_period_t* periods; // Period
  345. size_t metric_count;
  346. struct dash_metric_t* metrics; // Metrics
  347. struct dash_descriptor_t essentials; // EssentialProperty
  348. struct dash_descriptor_t supplementals; // SupplementalProperty
  349. struct dash_descriptor_t timings; // UTCTming
  350. };
  351. /// Parse MPD(Media Presentation Description for MPEG-DASH ) manifest file
  352. /// @param[out] mpd mpd object(free by dash_mpd_free)
  353. /// @return 0-ok, other-error
  354. int dash_mpd_parse(struct dash_mpd_t** mpd, const char* data, size_t bytes);
  355. int dash_mpd_free(struct dash_mpd_t** mpd);
  356. /// @return -1-live, >=0-duration(ms), other-error
  357. int64_t dash_get_duration(const struct dash_mpd_t* mpd);
  358. /// Period
  359. /// location period by time
  360. /// @param[in] time from previous period end to current perid end, range: (period-m-end, period-n-end]
  361. /// @return >=0-period index, -1-if don't find, other-undefined
  362. int dash_period_find(const struct dash_mpd_t* mpd, int64_t time);
  363. /// @param[in] media DASH_MEDIA_AUDIO/DASH_MEDIA_VIDEO/xxx
  364. /// @param[in] id adaptation set id, 0 if unknown
  365. /// @param[in] group adaptation set group id, 0 if unknown
  366. /// @param[in] lang adaptation set lang, such as 'en'/'fr', NULL if don't care
  367. /// @param[in] codecs adaptation set codec type, such as 'avc1', NULL if don't care
  368. /// @return NULL if don't find any adaptation set
  369. const struct dash_adaptation_set_t* dash_period_select(const struct dash_period_t* period, int media, unsigned int id, unsigned int group, const char* lang, const char* codecs);
  370. /// Adaptation Set
  371. /// @return adaptation set media type DASH_MEDIA_AUDIO/DASH_MEDIA_VIDEO, DASH_MEDIA_UNKNOWN if unknown
  372. int dash_adaptation_set_media_type(const struct dash_adaptation_set_t* set);
  373. /// Priority: 1. selectionPriority; 2. qualityRanking; 3. bandwidth
  374. /// @return >=0-representation index, -1-error
  375. int dash_adaptation_set_best_representation(const struct dash_adaptation_set_t* set);
  376. /// Representation
  377. const struct dash_url_t* dash_representation_get_base_url(const struct dash_representation_t* representation);
  378. /// Get initialization segment url(MUST use with dash_representation_get_base_url)
  379. /// @return >0-ok with url length, =0-don't have initialization segment, <0-error
  380. int dash_representation_get_initialization(const struct dash_representation_t* representation, char* url, size_t size);
  381. /// Find segment by start time
  382. /// @param[in] time segment time, range: (previous segment end, segment start + duration)
  383. /// @return -1-not found, >=0-segment item index(index is not the startnumber)
  384. int dash_representation_find_segment(const struct dash_representation_t* representation, int64_t time);
  385. /// @return <0-error, >=0-segment count(INT_MAX for segment template)
  386. int dash_representation_segment_count(const struct dash_representation_t* representation);
  387. /// Get segment url(MUST use with dash_representation_get_base_url)
  388. /// @param[in] index segment index(!= start number)
  389. /// @param[out] number start number of representation
  390. /// @param[out] start start time of representation(MUST add period.start)
  391. /// @param[out] duration segment duration, 0 if unknown
  392. /// @param[out] range url range, NULL if don't have range
  393. /// @return >=0-ok with url length, <0-error
  394. int dash_representation_segment_url(const struct dash_representation_t* representation, int index, int64_t* number, int64_t* start, int64_t* duration, const char** range, char* url, size_t size);
  395. #ifdef __cplusplus
  396. }
  397. #endif
  398. #endif /* !_dash_parser_h_ */