2 * DASH MPD parsing library
6 * Copyright (C) 2012 STMicroelectronics
9 * Gianluca Gennari <gennarone@gmail.com>
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library (COPYING); if not, write to the
23 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 * Boston, MA 02111-1307, USA.
27 #ifndef __GST_MPDPARSER_H__
28 #define __GST_MPDPARSER_H__
31 #include <gst/uridownloader/gsturidownloader.h>
32 #include <gst/base/gstadapter.h>
36 typedef struct _GstMpdClient GstMpdClient;
37 typedef struct _GstActiveStream GstActiveStream;
38 typedef struct _GstStreamPeriod GstStreamPeriod;
39 typedef struct _GstMediaFragmentInfo GstMediaFragmentInfo;
40 typedef struct _GstMediaSegment GstMediaSegment;
41 typedef struct _GstMPDNode GstMPDNode;
42 typedef struct _GstPeriodNode GstPeriodNode;
43 typedef struct _GstRepresentationBaseType GstRepresentationBaseType;
44 typedef struct _GstDescriptorType GstDescriptorType;
45 typedef struct _GstContentComponentNode GstContentComponentNode;
46 typedef struct _GstAdaptationSetNode GstAdaptationSetNode;
47 typedef struct _GstRepresentationNode GstRepresentationNode;
48 typedef struct _GstSubRepresentationNode GstSubRepresentationNode;
49 typedef struct _GstSegmentListNode GstSegmentListNode;
50 typedef struct _GstSegmentTemplateNode GstSegmentTemplateNode;
51 typedef struct _GstSegmentURLNode GstSegmentURLNode;
52 typedef struct _GstBaseURL GstBaseURL;
53 typedef struct _GstRange GstRange;
54 typedef struct _GstRatio GstRatio;
55 typedef struct _GstFrameRate GstFrameRate;
56 typedef struct _GstConditionalUintType GstConditionalUintType;
57 typedef struct _GstSubsetNode GstSubsetNode;
58 typedef struct _GstProgramInformationNode GstProgramInformationNode;
59 typedef struct _GstMetricsRangeNode GstMetricsRangeNode;
60 typedef struct _GstMetricsNode GstMetricsNode;
61 typedef struct _GstUTCTimingNode GstUTCTimingNode;
62 typedef struct _GstSNode GstSNode;
63 typedef struct _GstSegmentTimelineNode GstSegmentTimelineNode;
64 typedef struct _GstSegmentBaseType GstSegmentBaseType;
65 typedef struct _GstURLType GstURLType;
66 typedef struct _GstMultSegmentBaseType GstMultSegmentBaseType;
68 #define GST_MPD_CLIENT_LOCK(c) g_mutex_lock (&c->lock);
69 #define GST_MPD_CLIENT_UNLOCK(c) g_mutex_unlock (&c->lock);
71 #ifdef TIZEN_FEATURE_ADAPTIVE_MODIFICATION
72 #define DEFAULT_ADAPTIVE_RETRY -1
73 #define DEFAULT_ADAPTIVE_TIMEOUT -1
76 #define GST_MPD_DURATION_NONE ((guint64)-1)
81 GST_STREAM_VIDEO, /* video stream (the main one) */
82 GST_STREAM_AUDIO, /* audio stream (optional) */
83 GST_STREAM_APPLICATION /* application stream (optional): for timed text/subtitles */
88 GST_MPD_FILE_TYPE_STATIC,
89 GST_MPD_FILE_TYPE_DYNAMIC
105 GST_XLINK_ACTUATE_ON_REQUEST,
106 GST_XLINK_ACTUATE_ON_LOAD
111 GST_MPD_UTCTIMING_TYPE_UNKNOWN = 0x00,
112 GST_MPD_UTCTIMING_TYPE_NTP = 0x01,
113 GST_MPD_UTCTIMING_TYPE_SNTP = 0x02,
114 GST_MPD_UTCTIMING_TYPE_HTTP_HEAD = 0x04,
115 GST_MPD_UTCTIMING_TYPE_HTTP_XSDATE = 0x08,
116 GST_MPD_UTCTIMING_TYPE_HTTP_ISO = 0x10,
117 GST_MPD_UTCTIMING_TYPE_HTTP_NTP = 0x20,
118 GST_MPD_UTCTIMING_TYPE_DIRECT = 0x40
119 } GstMPDUTCTimingType;
124 gchar *serviceLocation;
130 guint64 first_byte_pos;
131 guint64 last_byte_pos;
146 struct _GstConditionalUintType
159 struct _GstSegmentTimelineNode
161 /* list of S nodes */
171 struct _GstSegmentBaseType
174 guint64 presentationTimeOffset;
175 GstRange *indexRange;
176 gboolean indexRangeExact;
177 /* Initialization node */
178 GstURLType *Initialization;
179 /* RepresentationIndex node */
180 GstURLType *RepresentationIndex;
183 struct _GstMultSegmentBaseType
185 guint duration; /* in seconds */
187 /* SegmentBaseType extension */
188 GstSegmentBaseType *SegBaseType;
189 /* SegmentTimeline node */
190 GstSegmentTimelineNode *SegmentTimeline;
191 /* BitstreamSwitching node */
192 GstURLType *BitstreamSwitching;
195 struct _GstSegmentListNode
198 GstMultSegmentBaseType *MultSegBaseType;
199 /* list of SegmentURL nodes */
203 GstXLinkActuate actuate;
206 struct _GstSegmentTemplateNode
209 GstMultSegmentBaseType *MultSegBaseType;
212 gchar *initialization;
213 gchar *bitstreamSwitching;
216 struct _GstSegmentURLNode
219 GstRange *mediaRange;
221 GstRange *indexRange;
224 struct _GstRepresentationBaseType
230 GstFrameRate *minFrameRate;
231 GstFrameRate *maxFrameRate;
232 GstFrameRate *frameRate;
233 gchar *audioSamplingRate;
235 gchar *segmentProfiles;
237 gdouble maximumSAPPeriod;
238 GstSAPType startWithSAP;
239 gdouble maxPlayoutRate;
240 gboolean codingDependency;
242 /* list of FramePacking DescriptorType nodes */
244 /* list of AudioChannelConfiguration DescriptorType nodes */
245 GList *AudioChannelConfiguration;
246 /* list of ContentProtection DescriptorType nodes */
247 GList *ContentProtection;
250 struct _GstSubRepresentationNode
252 /* RepresentationBase extension */
253 GstRepresentationBaseType *RepresentationBase;
255 guint *dependencyLevel; /* UIntVectorType */
256 guint size; /* size of "dependencyLevel" array */
258 gchar **contentComponent; /* StringVectorType */
261 struct _GstRepresentationNode
265 guint qualityRanking;
266 gchar **dependencyId; /* StringVectorType */
267 gchar **mediaStreamStructureId; /* StringVectorType */
268 /* RepresentationBase extension */
269 GstRepresentationBaseType *RepresentationBase;
270 /* list of BaseURL nodes */
272 /* list of SubRepresentation nodes */
273 GList *SubRepresentations;
274 /* SegmentBase node */
275 GstSegmentBaseType *SegmentBase;
276 /* SegmentTemplate node */
277 GstSegmentTemplateNode *SegmentTemplate;
278 /* SegmentList node */
279 GstSegmentListNode *SegmentList;
282 struct _GstDescriptorType
288 struct _GstContentComponentNode
291 gchar *lang; /* LangVectorType RFC 5646 */
294 /* list of Accessibility DescriptorType nodes */
295 GList *Accessibility;
296 /* list of Role DescriptorType nodes */
298 /* list of Rating DescriptorType nodes */
300 /* list of Viewpoint DescriptorType nodes */
304 struct _GstAdaptationSetNode
308 gchar *lang; /* LangVectorType RFC 5646 */
317 GstConditionalUintType *segmentAlignment;
318 GstConditionalUintType *subsegmentAlignment;
319 GstSAPType subsegmentStartsWithSAP;
320 gboolean bitstreamSwitching;
321 /* list of Accessibility DescriptorType nodes */
322 GList *Accessibility;
323 /* list of Role DescriptorType nodes */
325 /* list of Rating DescriptorType nodes */
327 /* list of Viewpoint DescriptorType nodes */
329 /* RepresentationBase extension */
330 GstRepresentationBaseType *RepresentationBase;
331 /* SegmentBase node */
332 GstSegmentBaseType *SegmentBase;
333 /* SegmentList node */
334 GstSegmentListNode *SegmentList;
335 /* SegmentTemplate node */
336 GstSegmentTemplateNode *SegmentTemplate;
337 /* list of BaseURL nodes */
339 /* list of Representation nodes */
340 GList *Representations;
341 /* list of ContentComponent nodes */
342 GList *ContentComponents;
343 #ifdef TIZEN_FEATURE_ADAPTIVE_MODIFICATION
344 /* stream variant information */
349 GstXLinkActuate actuate;
352 struct _GstSubsetNode
354 guint *contains; /* UIntVectorType */
355 guint size; /* size of the "contains" array */
358 struct _GstPeriodNode
361 guint64 start; /* [ms] */
362 guint64 duration; /* [ms] */
363 gboolean bitstreamSwitching;
364 /* SegmentBase node */
365 GstSegmentBaseType *SegmentBase;
366 /* SegmentList node */
367 GstSegmentListNode *SegmentList;
368 /* SegmentTemplate node */
369 GstSegmentTemplateNode *SegmentTemplate;
370 /* list of Adaptation Set nodes */
371 GList *AdaptationSets;
372 /* list of Representation nodes */
374 /* list of BaseURL nodes */
378 GstXLinkActuate actuate;
381 struct _GstProgramInformationNode
383 gchar *lang; /* LangVectorType RFC 5646 */
384 gchar *moreInformationURL;
391 struct _GstMetricsRangeNode
393 guint64 starttime; /* [ms] */
394 guint64 duration; /* [ms] */
397 struct _GstMetricsNode
400 /* list of Metrics Range nodes */
401 GList *MetricsRanges;
402 /* list of Reporting nodes */
406 struct _GstUTCTimingNode {
407 GstMPDUTCTimingType method;
408 /* NULL terminated array of strings */
414 gchar *default_namespace;
415 gchar *namespace_xsi;
416 gchar *namespace_ext;
417 gchar *schemaLocation;
421 GstDateTime *availabilityStartTime;
422 GstDateTime *availabilityEndTime;
423 guint64 mediaPresentationDuration; /* [ms] */
424 guint64 minimumUpdatePeriod; /* [ms] */
425 guint64 minBufferTime; /* [ms] */
426 guint64 timeShiftBufferDepth; /* [ms] */
427 guint64 suggestedPresentationDelay; /* [ms] */
428 guint64 maxSegmentDuration; /* [ms] */
429 guint64 maxSubsegmentDuration; /* [ms] */
430 /* list of BaseURL nodes */
432 /* list of Location nodes */
434 /* List of ProgramInformation nodes */
436 /* list of Periods nodes */
438 /* list of Metrics nodes */
440 /* list of GstUTCTimingNode nodes */
447 * Stream period data structure
449 struct _GstStreamPeriod
451 GstPeriodNode *period; /* Stream period */
452 guint number; /* Period number */
453 GstClockTime start; /* Period start time */
454 GstClockTime duration; /* Period duration */
460 * Media segment data structure
462 struct _GstMediaSegment
464 GstSegmentURLNode *SegmentURL; /* this is NULL when using a SegmentTemplate */
465 guint number; /* segment number */
466 gint repeat; /* number of extra repetitions (0 = played only once) */
467 guint64 scale_start; /* start time in timescale units */
468 guint64 scale_duration; /* duration in timescale units */
469 GstClockTime start; /* segment start time */
470 GstClockTime duration; /* segment duration */
473 struct _GstMediaFragmentInfo
480 gint64 index_range_start;
481 gint64 index_range_end;
483 gboolean discontinuity;
484 GstClockTime timestamp;
485 GstClockTime duration;
491 * Active stream data structure
493 struct _GstActiveStream
495 GstStreamMimeType mimeType; /* video/audio/application */
497 guint baseURL_idx; /* index of the baseURL used for last request */
498 gchar *baseURL; /* active baseURL used for last request */
499 gchar *queryURL; /* active queryURL used for last request */
500 guint max_bandwidth; /* max bandwidth allowed for this mimeType */
502 GstAdaptationSetNode *cur_adapt_set; /* active adaptation set */
503 gint representation_idx; /* index of current representation */
504 GstRepresentationNode *cur_representation; /* active representation */
505 GstSegmentBaseType *cur_segment_base; /* active segment base */
506 GstSegmentListNode *cur_segment_list; /* active segment list */
507 GstSegmentTemplateNode *cur_seg_template; /* active segment template */
508 gint segment_index; /* index of next sequence chunk */
509 guint segment_repeat_index; /* index of the repeat count of a segment */
510 GPtrArray *segments; /* array of GstMediaSegment */
511 GstClockTime presentationTimeOffset; /* presentation time offset of the current segment */
516 GstMPDNode *mpd_node; /* active MPD manifest file */
518 GList *periods; /* list of GstStreamPeriod */
519 guint period_idx; /* index of current Period */
521 GList *active_streams; /* list of GstActiveStream */
523 guint update_failed_count;
524 gchar *mpd_uri; /* manifest file URI */
525 gchar *mpd_base_uri; /* base URI for resolving relative URIs.
526 * this will be different for redirects */
529 gboolean profile_isoff_ondemand;
531 GstUriDownloader * downloader;
534 /* Basic initialization/deinitialization functions */
535 GstMpdClient *gst_mpd_client_new (void);
536 void gst_active_streams_free (GstMpdClient * client);
537 void gst_mpd_client_free (GstMpdClient * client);
538 void gst_media_fragment_info_clear (GstMediaFragmentInfo * fragment);
540 void gst_mpd_client_set_uri_downloader (GstMpdClient * client, GstUriDownloader * download);
542 /* MPD file parsing */
543 gboolean gst_mpd_parse (GstMpdClient *client, const gchar *data, gint size);
545 /* Streaming management */
546 gboolean gst_mpd_client_setup_media_presentation (GstMpdClient *client, GstClockTime time, gint period_index, const gchar *period_id);
547 gboolean gst_mpd_client_setup_streaming (GstMpdClient * client, GstAdaptationSetNode * adapt_set);
548 gboolean gst_mpd_client_setup_representation (GstMpdClient *client, GstActiveStream *stream, GstRepresentationNode *representation);
549 GstClockTime gst_mpd_client_get_next_fragment_duration (GstMpdClient * client, GstActiveStream * stream);
550 GstClockTime gst_mpd_client_get_media_presentation_duration (GstMpdClient *client);
551 GstClockTime gst_mpd_client_get_maximum_segment_duration (GstMpdClient * client);
552 gboolean gst_mpd_client_get_last_fragment_timestamp_end (GstMpdClient * client, guint stream_idx, GstClockTime * ts);
553 gboolean gst_mpd_client_get_next_fragment_timestamp (GstMpdClient * client, guint stream_idx, GstClockTime * ts);
554 gboolean gst_mpd_client_get_next_fragment (GstMpdClient *client, guint indexStream, GstMediaFragmentInfo * fragment);
555 gboolean gst_mpd_client_get_next_header (GstMpdClient *client, gchar **uri, guint stream_idx, gint64 * range_start, gint64 * range_end);
556 gboolean gst_mpd_client_get_next_header_index (GstMpdClient *client, gchar **uri, guint stream_idx, gint64 * range_start, gint64 * range_end);
557 gboolean gst_mpd_client_is_live (GstMpdClient * client);
558 gboolean gst_mpd_client_stream_seek (GstMpdClient * client, GstActiveStream * stream, gboolean forward, GstSeekFlags flags, GstClockTime ts, GstClockTime * final_ts);
559 gboolean gst_mpd_client_seek_to_time (GstMpdClient * client, GDateTime * time);
560 GstClockTime gst_mpd_parser_get_stream_presentation_offset (GstMpdClient *client, guint stream_idx);
561 gchar** gst_mpd_client_get_utc_timing_sources (GstMpdClient *client, guint methods, GstMPDUTCTimingType *selected_method);
562 GstClockTime gst_mpd_parser_get_period_start_time (GstMpdClient *client);
564 /* Period selection */
565 guint gst_mpd_client_get_period_index_at_time (GstMpdClient * client, GstDateTime * time);
566 gboolean gst_mpd_client_set_period_index (GstMpdClient *client, guint period_idx);
567 gboolean gst_mpd_client_set_period_id (GstMpdClient *client, const gchar * period_id);
568 guint gst_mpd_client_get_period_index (GstMpdClient *client);
569 const gchar *gst_mpd_client_get_period_id (GstMpdClient *client);
570 gboolean gst_mpd_client_has_next_period (GstMpdClient *client);
571 gboolean gst_mpd_client_has_previous_period (GstMpdClient * client);
573 /* Representation selection */
574 #ifdef TIZEN_FEATURE_ADAPTIVE_MODIFICATION
575 gint gst_mpdparser_get_rep_idx_with_max_bandwidth (GList *Representations, gint max_bandwidth, gint max_video_width, gint max_video_height);
577 gint gst_mpdparser_get_rep_idx_with_max_bandwidth (GList *Representations, gint max_bandwidth, gint max_video_width, gint max_video_height, gint max_video_framerate_n, gint max_video_framerate_d);
579 gint gst_mpdparser_get_rep_idx_with_min_bandwidth (GList * Representations);
582 const gchar *gst_mpdparser_get_baseURL (GstMpdClient *client, guint indexStream);
585 guint gst_mpdparser_get_nb_active_stream (GstMpdClient *client);
586 GstActiveStream *gst_mpdparser_get_active_stream_by_index (GstMpdClient *client, guint stream_idx);
587 gboolean gst_mpd_client_active_stream_contains_subtitles (GstActiveStream * stream);
590 guint gst_mpdparser_get_nb_adaptationSet (GstMpdClient *client);
591 GList * gst_mpd_client_get_adaptation_sets (GstMpdClient * client);
594 gboolean gst_mpd_client_has_next_segment (GstMpdClient * client, GstActiveStream * stream, gboolean forward);
595 GstFlowReturn gst_mpd_client_advance_segment (GstMpdClient * client, GstActiveStream * stream, gboolean forward);
596 void gst_mpd_client_seek_to_first_segment (GstMpdClient * client);
597 GstDateTime *gst_mpd_client_get_next_segment_availability_start_time (GstMpdClient * client, GstActiveStream * stream);
599 /* Get audio/video stream parameters (caps, width, height, rate, number of channels) */
600 GstCaps * gst_mpd_client_get_stream_caps (GstActiveStream * stream);
601 gboolean gst_mpd_client_get_bitstream_switching_flag (GstActiveStream * stream);
602 guint gst_mpd_client_get_video_stream_width (GstActiveStream * stream);
603 guint gst_mpd_client_get_video_stream_height (GstActiveStream * stream);
604 gboolean gst_mpd_client_get_video_stream_framerate (GstActiveStream * stream, gint * fps_num, gint * fps_den);
605 guint gst_mpd_client_get_audio_stream_rate (GstActiveStream * stream);
606 guint gst_mpd_client_get_audio_stream_num_channels (GstActiveStream * stream);
608 /* Support multi language */
609 guint gst_mpdparser_get_list_and_nb_of_audio_language (GstMpdClient *client, GList **lang);
611 gint64 gst_mpd_client_calculate_time_difference (const GstDateTime * t1, const GstDateTime * t2);
612 GstDateTime *gst_mpd_client_add_time_difference (GstDateTime * t1, gint64 usecs);
613 gint64 gst_mpd_client_parse_default_presentation_delay(GstMpdClient * client, const gchar * default_presentation_delay);
616 gboolean gst_mpd_client_has_isoff_ondemand_profile (GstMpdClient *client);
620 #endif /* __GST_MPDPARSER_H__ */