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
253 struct _GstContentComponentNode
256 gchar *lang; /* LangVectorType RFC 5646 */
259 /* list of Accessibility DescriptorType nodes */
260 GList *Accessibility;
261 /* list of Role DescriptorType nodes */
263 /* list of Rating DescriptorType nodes */
265 /* list of Viewpoint DescriptorType nodes */
269 struct _GstAdaptationSetNode
273 gchar *lang; /* LangVectorType RFC 5646 */
282 GstFrameRate *minFrameRate;
283 GstFrameRate *maxFrameRate;
284 GstConditionalUintType *segmentAlignment;
285 GstConditionalUintType *subsegmentAlignment;
286 GstSAPType subsegmentStartsWithSAP;
287 gboolean bitstreamSwitching;
288 /* list of Accessibility DescriptorType nodes */
289 GList *Accessibility;
290 /* list of Role DescriptorType nodes */
292 /* list of Rating DescriptorType nodes */
294 /* list of Viewpoint DescriptorType nodes */
296 /* RepresentationBase extension */
297 GstRepresentationBaseType *RepresentationBase;
298 /* SegmentBase node */
299 GstSegmentBaseType *SegmentBase;
300 /* SegmentList node */
301 GstSegmentListNode *SegmentList;
302 /* SegmentTemplate node */
303 GstSegmentTemplateNode *SegmentTemplate;
304 /* list of BaseURL nodes */
306 /* list of Representation nodes */
307 GList *Representations;
308 /* list of ContentComponent nodes */
309 GList *ContentComponents;
312 struct _GstSubsetNode
314 guint *contains; /* UIntVectorType */
315 guint size; /* size of the "contains" array */
318 struct _GstPeriodNode
321 gint64 start; /* [ms] */
322 gint64 duration; /* [ms] */
323 gboolean bitstreamSwitching;
324 /* SegmentBase node */
325 GstSegmentBaseType *SegmentBase;
326 /* SegmentList node */
327 GstSegmentListNode *SegmentList;
328 /* SegmentTemplate node */
329 GstSegmentTemplateNode *SegmentTemplate;
330 /* list of Adaptation Set nodes */
331 GList *AdaptationSets;
332 /* list of Representation nodes */
334 /* list of BaseURL nodes */
338 struct _GstProgramInformationNode
340 gchar *lang; /* LangVectorType RFC 5646 */
341 gchar *moreInformationURL;
348 struct _GstMetricsRangeNode
350 gint64 starttime; /* [ms] */
351 gint64 duration; /* [ms] */
354 struct _GstMetricsNode
357 /* list of Metrics Range nodes */
358 GList *MetricsRanges;
359 /* list of Reporting nodes */
365 gchar *default_namespace;
366 gchar *namespace_xsi;
367 gchar *namespace_ext;
368 gchar *schemaLocation;
372 GstDateTime *availabilityStartTime;
373 GstDateTime *availabilityEndTime;
374 gint64 mediaPresentationDuration; /* [ms] */
375 gint64 minimumUpdatePeriod; /* [ms] */
376 gint64 minBufferTime; /* [ms] */
377 gint64 timeShiftBufferDepth; /* [ms] */
378 gint64 suggestedPresentationDelay; /* [ms] */
379 gint64 maxSegmentDuration; /* [ms] */
380 gint64 maxSubsegmentDuration; /* [ms] */
381 /* list of BaseURL nodes */
383 /* list of Location nodes */
385 /* List of ProgramInformation nodes */
387 /* list of Periods nodes */
389 /* list of Metrics nodes */
396 * Stream period data structure
398 struct _GstStreamPeriod
400 GstPeriodNode *period; /* Stream period */
401 guint number; /* Period number */
402 GstClockTime start; /* Period start time */
403 GstClockTime duration; /* Period duration */
409 * Media segment data structure
411 struct _GstMediaSegment
413 GstSegmentURLNode *SegmentURL; /* this is NULL when using a SegmentTemplate */
414 guint number; /* segment number */
415 guint64 start; /* segment start time in timescale units */
416 GstClockTime start_time; /* segment start time */
417 GstClockTime duration; /* segment duration */
423 * Active stream data structure
425 struct _GstActiveStream
427 GstStreamMimeType mimeType; /* video/audio/application */
429 guint baseURL_idx; /* index of the baseURL used for last request */
430 gchar *baseURL; /* active baseURL used for last request */
431 gchar *queryURL; /* active baseURL used for last request */
432 guint max_bandwidth; /* max bandwidth allowed for this mimeType */
434 GstAdaptationSetNode *cur_adapt_set; /* active adaptation set */
435 gint representation_idx; /* index of current representation */
436 GstRepresentationNode *cur_representation; /* active representation */
437 GstSegmentBaseType *cur_segment_base; /* active segment base */
438 GstSegmentListNode *cur_segment_list; /* active segment list */
439 GstSegmentTemplateNode *cur_seg_template; /* active segment template */
440 guint segment_idx; /* index of next sequence chunk */
441 GList *segments; /* list of GstMediaSegment */
446 GstMPDNode *mpd_node; /* active MPD manifest file */
448 GList *periods; /* list of GstStreamPeriod */
449 guint period_idx; /* index of current Period */
451 GList *active_streams; /* list of GstActiveStream */
452 guint stream_idx; /* currently active stream */
454 guint update_failed_count;
455 gchar *mpd_uri; /* manifest file URI */
459 /* Basic initialization/deinitialization functions */
460 GstMpdClient *gst_mpd_client_new (void);
461 void gst_active_streams_free (GstMpdClient * client);
462 void gst_mpd_client_free (GstMpdClient * client);
464 /* MPD file parsing */
465 gboolean gst_mpd_parse (GstMpdClient *client, const gchar *data, gint size);
467 /* Streaming management */
468 gboolean gst_mpd_client_setup_media_presentation (GstMpdClient *client);
469 gboolean gst_mpd_client_setup_streaming (GstMpdClient *client, GstStreamMimeType mimeType, const gchar* lang);
470 gboolean gst_mpd_client_setup_representation (GstMpdClient *client, GstActiveStream *stream, GstRepresentationNode *representation);
471 GstClockTime gst_mpd_client_get_current_position (GstMpdClient *client);
472 GstClockTime gst_mpd_client_get_next_fragment_duration (GstMpdClient * client);
473 GstClockTime gst_mpd_client_get_media_presentation_duration (GstMpdClient *client);
474 gboolean gst_mpd_client_get_next_fragment_timestamp (GstMpdClient * client, guint stream_idx, GstClockTime * ts);
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, 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);
482 gboolean gst_mpd_client_has_next_period (GstMpdClient *client);
484 /* Representation selection */
485 gint gst_mpdparser_get_rep_idx_with_max_bandwidth (GList *Representations, gint max_bandwidth);
486 gint gst_mpdparser_get_rep_idx_with_min_bandwidth (GList * Representations);
489 const gchar *gst_mpdparser_get_baseURL (GstMpdClient *client, guint indexStream);
490 GstMediaSegment *gst_mpdparser_get_chunk_by_index (GstMpdClient *client, guint indexStream, guint indexChunk);
493 guint gst_mpdparser_get_nb_active_stream (GstMpdClient *client);
494 GstActiveStream *gst_mpdparser_get_active_stream_by_index (GstMpdClient *client, guint stream_idx);
497 guint gst_mpdparser_get_nb_adaptationSet (GstMpdClient *client);
500 void gst_mpd_client_set_segment_index_for_all_streams (GstMpdClient * client, guint segment_idx);
501 guint gst_mpd_client_get_segment_index (GstActiveStream * stream);
502 void gst_mpd_client_set_segment_index (GstActiveStream * stream, guint segment_idx);
504 /* Get audio/video stream parameters (mimeType, width, height, rate, number of channels) */
505 const gchar *gst_mpd_client_get_stream_mimeType (GstActiveStream * stream);
506 const gboolean gst_mpd_client_get_bitstream_switching_flag (GstActiveStream * stream);
507 guint gst_mpd_client_get_video_stream_width (GstActiveStream * stream);
508 guint gst_mpd_client_get_video_stream_height (GstActiveStream * stream);
509 guint gst_mpd_client_get_audio_stream_rate (GstActiveStream * stream);
510 guint gst_mpd_client_get_audio_stream_num_channels (GstActiveStream * stream);
512 /* Support multi language */
513 guint gst_mpdparser_get_list_and_nb_of_audio_language (GstMpdClient *client, GList **lang);
516 #endif /* __GST_MPDPARSER_H__ */