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__
34 typedef struct _GstMpdClient GstMpdClient;
35 typedef struct _GstActiveStream GstActiveStream;
36 typedef struct _GstStreamPeriod GstStreamPeriod;
37 typedef struct _GstMediaSegment GstMediaSegment;
38 typedef struct _GstMPDNode GstMPDNode;
39 typedef struct _GstPeriodNode GstPeriodNode;
40 typedef struct _GstRepresentationBaseType GstRepresentationBaseType;
41 typedef struct _GstDescriptorType GstDescriptorType;
42 typedef struct _GstContentComponentNode GstContentComponentNode;
43 typedef struct _GstAdaptationSetNode GstAdaptationSetNode;
44 typedef struct _GstRepresentationNode GstRepresentationNode;
45 typedef struct _GstSubRepresentationNode GstSubRepresentationNode;
46 typedef struct _GstSegmentListNode GstSegmentListNode;
47 typedef struct _GstSegmentTemplateNode GstSegmentTemplateNode;
48 typedef struct _GstSegmentURLNode GstSegmentURLNode;
49 typedef struct _GstBaseURL GstBaseURL;
50 typedef struct _GstRange GstRange;
51 typedef struct _GstRatio GstRatio;
52 typedef struct _GstFrameRate GstFrameRate;
53 typedef struct _GstConditionalUintType GstConditionalUintType;
54 typedef struct _GstSubsetNode GstSubsetNode;
55 typedef struct _GstProgramInformationNode GstProgramInformationNode;
56 typedef struct _GstMetricsRangeNode GstMetricsRangeNode;
57 typedef struct _GstMetricsNode GstMetricsNode;
58 typedef struct _GstSNode GstSNode;
59 typedef struct _GstSegmentTimelineNode GstSegmentTimelineNode;
60 typedef struct _GstSegmentBaseType GstSegmentBaseType;
61 typedef struct _GstURLType GstURLType;
62 typedef struct _GstMultSegmentBaseType GstMultSegmentBaseType;
64 #define GST_MPD_CLIENT_LOCK(c) g_mutex_lock (c->lock);
65 #define GST_MPD_CLIENT_UNLOCK(c) g_mutex_unlock (c->lock);
69 GST_STREAM_VIDEO, /* video stream (the main one) */
70 GST_STREAM_AUDIO, /* audio stream (optional) */
71 GST_STREAM_APPLICATION /* application stream (optional): for timed text/subtitles */
76 GST_MPD_FILE_TYPE_STATIC,
77 GST_MPD_FILE_TYPE_DYNAMIC
94 gchar *serviceLocation;
100 guint64 first_byte_pos;
101 guint64 last_byte_pos;
116 struct _GstConditionalUintType
129 struct _GstSegmentTimelineNode
131 /* list of S nodes */
141 struct _GstSegmentBaseType
144 guint presentationTimeOffset;
146 gboolean indexRangeExact;
147 /* Initialization node */
148 GstURLType *Initialization;
149 /* RepresentationIndex node */
150 GstURLType *RepresentationIndex;
153 struct _GstMultSegmentBaseType
155 guint duration; /* in seconds */
157 /* SegmentBaseType extension */
158 GstSegmentBaseType *SegBaseType;
159 /* SegmentTimeline node */
160 GstSegmentTimelineNode *SegmentTimeline;
161 /* BitstreamSwitching node */
162 GstURLType *BitstreamSwitching;
165 struct _GstSegmentListNode
168 GstMultSegmentBaseType *MultSegBaseType;
169 /* list of SegmentURL nodes */
173 struct _GstSegmentTemplateNode
176 GstMultSegmentBaseType *MultSegBaseType;
179 gchar *initialization;
180 gchar *bitstreamSwitching;
183 struct _GstSegmentURLNode
186 GstRange *mediaRange;
188 GstRange *indexRange;
191 struct _GstRepresentationBaseType
198 GstFrameRate *frameRate;
199 gchar *audioSamplingRate;
201 gchar *segmentProfiles;
203 gdouble maximumSAPPeriod;
204 GstSAPType startWithSAP;
205 gdouble maxPlayoutRate;
206 gboolean codingDependency;
208 /* list of FramePacking DescriptorType nodes */
210 /* list of AudioChannelConfiguration DescriptorType nodes */
211 GList *AudioChannelConfiguration;
212 /* list of ContentProtection DescriptorType nodes */
213 GList *ContentProtection;
216 struct _GstSubRepresentationNode
218 /* RepresentationBase extension */
219 GstRepresentationBaseType *RepresentationBase;
221 guint *dependencyLevel; /* UIntVectorType */
222 guint size; /* size of "dependencyLevel" array */
224 gchar **contentComponent; /* StringVectorType */
227 struct _GstRepresentationNode
231 guint qualityRanking;
232 gchar **dependencyId; /* StringVectorType */
233 gchar **mediaStreamStructureId; /* StringVectorType */
234 /* RepresentationBase extension */
235 GstRepresentationBaseType *RepresentationBase;
236 /* list of BaseURL nodes */
238 /* list of SubRepresentation nodes */
239 GList *SubRepresentations;
240 /* SegmentBase node */
241 GstSegmentBaseType *SegmentBase;
242 /* SegmentTemplate node */
243 GstSegmentTemplateNode *SegmentTemplate;
244 /* SegmentList node */
245 GstSegmentListNode *SegmentList;
248 struct _GstDescriptorType
252 /* For adding ContentProtection to caps , get string of <mspr:pro> */
256 struct _GstContentComponentNode
259 gchar *lang; /* LangVectorType RFC 5646 */
262 /* list of Accessibility DescriptorType nodes */
263 GList *Accessibility;
264 /* list of Role DescriptorType nodes */
266 /* list of Rating DescriptorType nodes */
268 /* list of Viewpoint DescriptorType nodes */
272 struct _GstAdaptationSetNode
276 gchar *lang; /* LangVectorType RFC 5646 */
285 GstFrameRate *minFrameRate;
286 GstFrameRate *maxFrameRate;
287 GstConditionalUintType *segmentAlignment;
288 GstConditionalUintType *subsegmentAlignment;
289 GstSAPType subsegmentStartsWithSAP;
290 gboolean bitstreamSwitching;
291 /* list of Accessibility DescriptorType nodes */
292 GList *Accessibility;
293 /* list of Role DescriptorType nodes */
295 /* list of Rating DescriptorType nodes */
297 /* list of Viewpoint DescriptorType nodes */
299 /* RepresentationBase extension */
300 GstRepresentationBaseType *RepresentationBase;
301 /* SegmentBase node */
302 GstSegmentBaseType *SegmentBase;
303 /* SegmentList node */
304 GstSegmentListNode *SegmentList;
305 /* SegmentTemplate node */
306 GstSegmentTemplateNode *SegmentTemplate;
307 /* list of BaseURL nodes */
309 /* list of Representation nodes */
310 GList *Representations;
311 /* list of ContentComponent nodes */
312 GList *ContentComponents;
315 struct _GstSubsetNode
317 guint *contains; /* UIntVectorType */
318 guint size; /* size of the "contains" array */
321 struct _GstPeriodNode
324 gint64 start; /* [ms] */
325 gint64 duration; /* [ms] */
326 gboolean bitstreamSwitching;
327 /* SegmentBase node */
328 GstSegmentBaseType *SegmentBase;
329 /* SegmentList node */
330 GstSegmentListNode *SegmentList;
331 /* SegmentTemplate node */
332 GstSegmentTemplateNode *SegmentTemplate;
333 /* list of Adaptation Set nodes */
334 GList *AdaptationSets;
335 /* list of Representation nodes */
337 /* list of BaseURL nodes */
341 struct _GstProgramInformationNode
343 gchar *lang; /* LangVectorType RFC 5646 */
344 gchar *moreInformationURL;
351 struct _GstMetricsRangeNode
353 gint64 starttime; /* [ms] */
354 gint64 duration; /* [ms] */
357 struct _GstMetricsNode
360 /* list of Metrics Range nodes */
361 GList *MetricsRanges;
362 /* list of Reporting nodes */
368 gchar *default_namespace;
369 gchar *namespace_xsi;
370 gchar *namespace_ext;
371 gchar *schemaLocation;
375 GstDateTime *availabilityStartTime;
376 GstDateTime *availabilityEndTime;
377 gint64 mediaPresentationDuration; /* [ms] */
378 gint64 minimumUpdatePeriod; /* [ms] */
379 gint64 minBufferTime; /* [ms] */
380 gint64 timeShiftBufferDepth; /* [ms] */
381 gint64 suggestedPresentationDelay; /* [ms] */
382 gint64 maxSegmentDuration; /* [ms] */
383 gint64 maxSubsegmentDuration; /* [ms] */
384 /* list of BaseURL nodes */
386 /* list of Location nodes */
388 /* List of ProgramInformation nodes */
390 /* list of Periods nodes */
392 /* list of Metrics nodes */
399 * Stream period data structure
401 struct _GstStreamPeriod
403 GstPeriodNode *period; /* Stream period */
404 guint number; /* Period number */
405 GstClockTime start; /* Period start time */
406 GstClockTime duration; /* Period duration */
412 * Media segment data structure
414 struct _GstMediaSegment
416 GstSegmentURLNode *SegmentURL; /* this is NULL when using a SegmentTemplate */
417 guint number; /* segment number */
418 guint start; /* segment start time in timescale units */
419 GstClockTime start_time; /* segment start time */
420 GstClockTime duration; /* segment duration */
426 * Active stream data structure
428 struct _GstActiveStream
430 GstStreamMimeType mimeType; /* video/audio/application */
432 guint mpd_baseURL_idx; /* MPD baseURL index */
433 guint period_baseURL_idx; /* Period baseURL index */
434 guint adaptset_baseURL_idx; /* AdaptationSet baseURL index */
435 guint repr_baseURL_idx; /* Representation baseURL index */
437 gchar *baseURL; /* active baseURL used for last request */
438 guint max_bandwidth; /* max bandwidth allowed for this mimeType */
440 GstAdaptationSetNode *cur_adapt_set; /* active adaptation set */
441 gint representation_idx; /* index of current representation */
442 GstRepresentationNode *cur_representation; /* active representation */
443 GstSegmentBaseType *cur_segment_base; /* active segment base */
444 GstSegmentListNode *cur_segment_list; /* active segment list */
445 GstSegmentTemplateNode *cur_seg_template; /* active segment template */
446 guint segment_idx; /* index of next sequence chunk */
447 GList *segments; /* list of GstMediaSegment */
452 GstMPDNode *mpd_node; /* active MPD manifest file */
454 GList *periods; /* list of GstStreamPeriod */
455 guint period_idx; /* index of current Period */
457 GList *active_streams; /* list of GstActiveStream */
458 guint stream_idx; /* currently active stream */
460 guint download_failed_count;
461 gchar *mpd_uri; /* manifest file URI */
465 /* Basic initialization/deinitialization functions */
466 GstMpdClient *gst_mpd_client_new ();
467 void gst_active_streams_free (GstMpdClient * client);
468 void gst_mpd_client_free (GstMpdClient * client);
470 /* MPD file parsing */
471 gboolean gst_mpd_parse (GstMpdClient *client, const gchar *data, gint size);
473 /* Streaming management */
474 gboolean gst_mpd_client_setup_media_presentation (GstMpdClient *client);
475 gboolean gst_mpd_client_setup_streaming (GstMpdClient *client, GstStreamMimeType mimeType, gchar* lang);
476 gboolean gst_mpd_client_setup_representation (GstMpdClient *client, GstActiveStream *stream, GstRepresentationNode *representation);
477 gboolean gst_mpd_client_get_stream_current_position (GstMpdClient * client, guint stream_idx, GstClockTime *ts);
478 GstClockTime gst_mpd_client_get_next_fragment_duration (GstMpdClient * client);
479 GstClockTime gst_mpd_client_get_media_presentation_duration (GstMpdClient *client);
480 gboolean gst_mpd_client_get_next_fragment (GstMpdClient *client, guint indexStream, gboolean *discontinuity, gchar **uri, GstClockTime *duration, GstClockTime *timestamp);
481 gboolean gst_mpd_client_get_last_fragment_timestamp (GstMpdClient * client, guint stream_idx, GstClockTime * ts);
482 gboolean gst_mpd_client_get_next_fragment_timestamp (GstMpdClient * client, guint stream_idx, GstClockTime * ts);
483 gboolean gst_mpd_client_get_next_header (GstMpdClient *client, const gchar **uri, guint stream_idx);
484 gboolean gst_mpd_client_is_live (GstMpdClient * client);
486 /* Period selection */
487 gboolean gst_mpd_client_set_period_index (GstMpdClient *client, guint period_idx);
488 guint gst_mpd_client_get_period_index (GstMpdClient *client);
489 const gchar* gst_mpd_client_get_period_id (GstMpdClient * client);
490 gboolean gst_mpd_client_set_period_id (GstMpdClient * client, const gchar * period_id);
491 gboolean gst_mpd_client_has_next_period (GstMpdClient * client);
493 /* Representation selection */
494 gint gst_mpdparser_get_rep_idx_with_max_bandwidth (GList *Representations, guint64 max_bandwidth);
497 const gchar *gst_mpdparser_get_baseURL (GstMpdClient *client);
498 gboolean gst_mpdparser_get_chunk_by_index (GstMpdClient * client, guint indexStream, guint indexChunk, GstMediaSegment *segment);
499 gboolean gst_mpd_client_set_next_baseURL_for_stream (GstMpdClient * client);
502 guint gst_mpdparser_get_nb_active_stream (GstMpdClient *client);
503 GstActiveStream *gst_mpdparser_get_active_stream_by_index (GstMpdClient *client, guint stream_idx);
504 gint gst_mpd_client_get_video_active_stream_id(GstMpdClient *client);
505 gboolean gst_mpd_client_stream_seek (GstMpdClient * client, gint stream_idx, GstClockTime ts);
506 gboolean gst_mpd_client_seek_to_time (GstMpdClient * client, GDateTime * time);
507 gint gst_mpd_client_check_time_position (GstMpdClient * client, GstActiveStream * stream, GstClockTime ts, gint64 * diff);
508 GstClockTime gst_mpd_client_stream_find_segment(GstMpdClient *client, guint stream_idx, GstClockTime seek_pos, guint *seg_num);
511 guint gst_mpdparser_get_nb_adaptationSet (GstMpdClient *client);
514 void gst_mpd_client_set_segment_index_for_all_streams (GstMpdClient * client, guint segment_idx);
515 void gst_mpd_client_set_segment_index (GstActiveStream * stream, guint segment_idx);
516 guint gst_mpd_client_get_segment_index (GstActiveStream * stream);
518 /* Get audio/video stream parameters (mimeType, width, height, rate, number of channels) */
519 const gchar *gst_mpd_client_get_stream_mimeType (GstActiveStream * stream);
520 const gboolean gst_mpd_client_get_bitstream_switching_flag (GstActiveStream * stream);
521 gboolean gst_mpd_client_get_max_video_dimensions(GstMpdClient *client, gint *max_width, gint *max_height);
522 guint gst_mpd_client_get_video_stream_width (GstActiveStream * stream);
523 guint gst_mpd_client_get_video_stream_height (GstActiveStream * stream);
524 guint gst_mpd_client_get_video_stream_bandwidth (GstActiveStream * stream);
525 guint gst_mpd_client_get_audio_stream_rate (GstActiveStream * stream);
526 guint gst_mpd_client_get_audio_stream_num_channels (GstActiveStream * stream);
528 /* Support multi language */
529 guint gst_mpdparser_get_list_and_nb_of_audio_language (GstMpdClient *client, GList **lang);
532 #endif /* __GST_MPDPARSER_H__ */