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
197 GstFrameRate *frameRate;
198 gchar *audioSamplingRate;
200 gchar *segmentProfiles;
202 gdouble maximumSAPPeriod;
203 GstSAPType startWithSAP;
204 gdouble maxPlayoutRate;
205 gboolean codingDependency;
207 /* list of FramePacking DescriptorType nodes */
209 /* list of AudioChannelConfiguration DescriptorType nodes */
210 GList *AudioChannelConfiguration;
211 /* list of ContentProtection DescriptorType nodes */
212 GList *ContentProtection;
215 struct _GstSubRepresentationNode
217 /* RepresentationBase extension */
218 GstRepresentationBaseType *RepresentationBase;
220 guint *dependencyLevel; /* UIntVectorType */
221 guint size; /* size of "dependencyLevel" array */
223 gchar **contentComponent; /* StringVectorType */
226 struct _GstRepresentationNode
230 guint qualityRanking;
231 gchar **dependencyId; /* StringVectorType */
232 gchar **mediaStreamStructureId; /* StringVectorType */
233 /* RepresentationBase extension */
234 GstRepresentationBaseType *RepresentationBase;
235 /* list of BaseURL nodes */
237 /* list of SubRepresentation nodes */
238 GList *SubRepresentations;
239 /* SegmentBase node */
240 GstSegmentBaseType *SegmentBase;
241 /* SegmentTemplate node */
242 GstSegmentTemplateNode *SegmentTemplate;
243 /* SegmentList node */
244 GstSegmentListNode *SegmentList;
247 struct _GstDescriptorType
251 /* For adding ContentProtection to caps , get string of <mspr:pro> */
255 struct _GstContentComponentNode
258 gchar *lang; /* LangVectorType RFC 5646 */
261 /* list of Accessibility DescriptorType nodes */
262 GList *Accessibility;
263 /* list of Role DescriptorType nodes */
265 /* list of Rating DescriptorType nodes */
267 /* list of Viewpoint DescriptorType nodes */
271 struct _GstAdaptationSetNode
275 gchar *lang; /* LangVectorType RFC 5646 */
284 GstFrameRate *minFrameRate;
285 GstFrameRate *maxFrameRate;
286 GstConditionalUintType *segmentAlignment;
287 GstConditionalUintType *subsegmentAlignment;
288 GstSAPType subsegmentStartsWithSAP;
289 gboolean bitstreamSwitching;
290 /* list of Accessibility DescriptorType nodes */
291 GList *Accessibility;
292 /* list of Role DescriptorType nodes */
294 /* list of Rating DescriptorType nodes */
296 /* list of Viewpoint DescriptorType nodes */
298 /* RepresentationBase extension */
299 GstRepresentationBaseType *RepresentationBase;
300 /* SegmentBase node */
301 GstSegmentBaseType *SegmentBase;
302 /* SegmentList node */
303 GstSegmentListNode *SegmentList;
304 /* SegmentTemplate node */
305 GstSegmentTemplateNode *SegmentTemplate;
306 /* list of BaseURL nodes */
308 /* list of Representation nodes */
309 GList *Representations;
310 /* list of ContentComponent nodes */
311 GList *ContentComponents;
314 struct _GstSubsetNode
316 guint *contains; /* UIntVectorType */
317 guint size; /* size of the "contains" array */
320 struct _GstPeriodNode
323 gint64 start; /* [ms] */
324 gint64 duration; /* [ms] */
325 gboolean bitstreamSwitching;
326 /* SegmentBase node */
327 GstSegmentBaseType *SegmentBase;
328 /* SegmentList node */
329 GstSegmentListNode *SegmentList;
330 /* SegmentTemplate node */
331 GstSegmentTemplateNode *SegmentTemplate;
332 /* list of Adaptation Set nodes */
333 GList *AdaptationSets;
334 /* list of Representation nodes */
336 /* list of BaseURL nodes */
340 struct _GstProgramInformationNode
342 gchar *lang; /* LangVectorType RFC 5646 */
343 gchar *moreInformationURL;
350 struct _GstMetricsRangeNode
352 gint64 starttime; /* [ms] */
353 gint64 duration; /* [ms] */
356 struct _GstMetricsNode
359 /* list of Metrics Range nodes */
360 GList *MetricsRanges;
361 /* list of Reporting nodes */
367 gchar *default_namespace;
368 gchar *namespace_xsi;
369 gchar *namespace_ext;
370 gchar *schemaLocation;
374 GstDateTime *availabilityStartTime;
375 GstDateTime *availabilityEndTime;
376 gint64 mediaPresentationDuration; /* [ms] */
377 gint64 minimumUpdatePeriod; /* [ms] */
378 gint64 minBufferTime; /* [ms] */
379 gint64 timeShiftBufferDepth; /* [ms] */
380 gint64 suggestedPresentationDelay; /* [ms] */
381 gint64 maxSegmentDuration; /* [ms] */
382 gint64 maxSubsegmentDuration; /* [ms] */
383 /* list of BaseURL nodes */
385 /* list of Location nodes */
387 /* List of ProgramInformation nodes */
389 /* list of Periods nodes */
391 /* list of Metrics nodes */
398 * Stream period data structure
400 struct _GstStreamPeriod
402 GstPeriodNode *period; /* Stream period */
403 guint number; /* Period number */
404 GstClockTime start; /* Period start time */
405 GstClockTime duration; /* Period duration */
411 * Media segment data structure
413 struct _GstMediaSegment
415 GstSegmentURLNode *SegmentURL; /* this is NULL when using a SegmentTemplate */
416 guint number; /* segment number */
417 guint start; /* segment start time in timescale units */
418 GstClockTime start_time; /* segment start time */
419 GstClockTime duration; /* segment duration */
425 * Active stream data structure
427 struct _GstActiveStream
429 GstStreamMimeType mimeType; /* video/audio/application */
431 guint baseURL_idx; /* index of the baseURL used for last request */
432 gchar *baseURL; /* active baseURL used for last request */
433 guint max_bandwidth; /* max bandwidth allowed for this mimeType */
435 GstAdaptationSetNode *cur_adapt_set; /* active adaptation set */
436 gint representation_idx; /* index of current representation */
437 GstRepresentationNode *cur_representation; /* active representation */
438 GstSegmentBaseType *cur_segment_base; /* active segment base */
439 GstSegmentListNode *cur_segment_list; /* active segment list */
440 GstSegmentTemplateNode *cur_seg_template; /* active segment template */
441 guint segment_idx; /* index of next sequence chunk */
442 GList *segments; /* list of GstMediaSegment */
447 GstMPDNode *mpd_node; /* active MPD manifest file */
449 GList *periods; /* list of GstStreamPeriod */
450 guint period_idx; /* index of current Period */
452 GList *active_streams; /* list of GstActiveStream */
453 guint stream_idx; /* currently active stream */
455 guint update_failed_count;
456 gchar *mpd_uri; /* manifest file URI */
460 /* Basic initialization/deinitialization functions */
461 GstMpdClient *gst_mpd_client_new ();
462 void gst_active_streams_free (GstMpdClient * client);
463 void gst_mpd_client_free (GstMpdClient * client);
465 /* MPD file parsing */
466 gboolean gst_mpd_parse (GstMpdClient *client, const gchar *data, gint size);
468 /* Streaming management */
469 gboolean gst_mpd_client_setup_media_presentation (GstMpdClient *client);
470 gboolean gst_mpd_client_setup_streaming (GstMpdClient *client, GstStreamMimeType mimeType, gchar* lang);
471 gboolean gst_mpd_client_setup_representation (GstMpdClient *client, GstActiveStream *stream, GstRepresentationNode *representation);
472 GstClockTime gst_mpd_client_get_current_position (GstMpdClient *client);
473 GstClockTime gst_mpd_client_get_next_fragment_duration (GstMpdClient * client);
474 GstClockTime gst_mpd_client_get_media_presentation_duration (GstMpdClient *client);
475 gboolean gst_mpd_client_get_next_fragment (GstMpdClient *client, guint indexStream, gboolean *discontinuity, gchar **uri, GstClockTime *duration, GstClockTime *timestamp);
476 gboolean gst_mpd_client_get_next_header (GstMpdClient *client, const gchar **uri, guint stream_idx);
477 gboolean gst_mpd_client_is_live (GstMpdClient * client);
479 /* Period selection */
480 gboolean gst_mpd_client_set_period_index (GstMpdClient *client, guint period_idx);
481 guint gst_mpd_client_get_period_index (GstMpdClient *client);
483 /* Representation selection */
484 gint gst_mpdparser_get_rep_idx_with_max_bandwidth (GList *Representations, gint max_bandwidth);
487 const gchar *gst_mpdparser_get_baseURL (GstMpdClient *client);
488 GstMediaSegment *gst_mpdparser_get_chunk_by_index (GstMpdClient *client, guint indexStream, guint indexChunk);
491 guint gst_mpdparser_get_nb_active_stream (GstMpdClient *client);
492 GstActiveStream *gst_mpdparser_get_active_stream_by_index (GstMpdClient *client, guint stream_idx);
495 guint gst_mpdparser_get_nb_adaptationSet (GstMpdClient *client);
498 void gst_mpd_client_set_segment_index_for_all_streams (GstMpdClient * client, guint segment_idx);
499 guint gst_mpd_client_get_segment_index (GstActiveStream * stream);
501 /* Get audio/video stream parameters (mimeType, width, height, rate, number of channels) */
502 const gchar *gst_mpd_client_get_stream_mimeType (GstActiveStream * stream);
503 const gboolean gst_mpd_client_get_bitstream_switching_flag (GstActiveStream * stream);
504 guint gst_mpd_client_get_video_stream_width (GstActiveStream * stream);
505 guint gst_mpd_client_get_video_stream_height (GstActiveStream * stream);
506 guint gst_mpd_client_get_audio_stream_rate (GstActiveStream * stream);
507 guint gst_mpd_client_get_audio_stream_num_channels (GstActiveStream * stream);
509 /* Support multi language */
510 guint gst_mpdparser_get_list_and_nb_of_audio_language (GstMpdClient *client, GList **lang);
513 #endif /* __GST_MPDPARSER_H__ */