Initialize Tizen 2.3
[framework/multimedia/gst-plugins-ext0.10.git] / wearable / dashdemux / src / gstmpdparser.h
1 /*
2  * DASH MPD parsing library
3  *
4  * gstmpdparser.h
5  *
6  * Copyright (C) 2012 STMicroelectronics
7  *
8  * Authors:
9  *   Gianluca Gennari <gennarone@gmail.com>
10  *
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.
15  *
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.
20  *
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.
25  */
26
27 #ifndef __GST_MPDPARSER_H__
28 #define __GST_MPDPARSER_H__
29
30 #include <gst/gst.h>
31
32 G_BEGIN_DECLS
33
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;
63
64 #define GST_MPD_CLIENT_LOCK(c) g_mutex_lock (c->lock);
65 #define GST_MPD_CLIENT_UNLOCK(c) g_mutex_unlock (c->lock);
66
67 typedef enum
68 {
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 */
72 } GstStreamMimeType;
73
74 typedef enum
75 {
76   GST_MPD_FILE_TYPE_STATIC,
77   GST_MPD_FILE_TYPE_DYNAMIC
78 } GstMPDFileType;
79
80 typedef enum
81 {
82   GST_SAP_TYPE_0 = 0,
83   GST_SAP_TYPE_1,
84   GST_SAP_TYPE_2,
85   GST_SAP_TYPE_3,
86   GST_SAP_TYPE_4,
87   GST_SAP_TYPE_5,
88   GST_SAP_TYPE_6
89 } GstSAPType;
90
91 struct _GstBaseURL
92 {
93   gchar *baseURL;
94   gchar *serviceLocation;
95   gchar *byteRange;
96 };
97
98 struct _GstRange
99 {
100   guint64 first_byte_pos;
101   guint64 last_byte_pos;
102 };
103
104 struct _GstRatio
105 {
106   guint num;
107   guint den;
108 };
109
110 struct _GstFrameRate
111 {
112   guint num;
113   guint den;
114 };
115
116 struct _GstConditionalUintType
117 {
118   gboolean flag;
119   guint value;
120 };
121
122 struct _GstSNode
123 {
124   guint t;
125   guint d;
126   guint r;
127 };
128
129 struct _GstSegmentTimelineNode
130 {
131   /* list of S nodes */
132   GList *S;
133 };
134
135 struct _GstURLType
136 {
137   gchar *sourceURL;
138   GstRange *range;
139 };
140
141 struct _GstSegmentBaseType
142 {
143   guint timescale;
144   guint presentationTimeOffset;
145   gchar *indexRange;
146   gboolean indexRangeExact;
147   /* Initialization node */
148   GstURLType *Initialization;
149   /* RepresentationIndex node */
150   GstURLType *RepresentationIndex;
151 };
152
153 struct _GstMultSegmentBaseType
154 {
155   guint duration;                  /* in seconds */
156   guint startNumber;
157   /* SegmentBaseType extension */
158   GstSegmentBaseType *SegBaseType;
159   /* SegmentTimeline node */
160   GstSegmentTimelineNode *SegmentTimeline;
161   /* BitstreamSwitching node */
162   GstURLType *BitstreamSwitching;
163 };
164
165 struct _GstSegmentListNode
166 {
167   /* extension */
168   GstMultSegmentBaseType *MultSegBaseType;
169   /* list of SegmentURL nodes */
170   GList *SegmentURL;
171 };
172
173 struct _GstSegmentTemplateNode
174 {
175   /* extension */
176   GstMultSegmentBaseType *MultSegBaseType;
177   gchar *media;
178   gchar *index;
179   gchar *initialization;
180   gchar *bitstreamSwitching;
181 };
182
183 struct _GstSegmentURLNode
184 {
185   gchar *media;
186   GstRange *mediaRange;
187   gchar *index;
188   GstRange *indexRange;
189 };
190
191 struct _GstRepresentationBaseType
192 {
193   gchar *profiles;
194   guint width;
195   guint height;
196   GstRatio *sar;
197   GstFrameRate *frameRate;
198   gchar *audioSamplingRate;
199   gchar *mimeType;
200   gchar *segmentProfiles;
201   gchar *codecs;
202   gdouble maximumSAPPeriod;
203   GstSAPType startWithSAP;
204   gdouble maxPlayoutRate;
205   gboolean codingDependency;
206   gchar *scanType;
207   /* list of FramePacking DescriptorType nodes */
208   GList *FramePacking;
209   /* list of AudioChannelConfiguration DescriptorType nodes */
210   GList *AudioChannelConfiguration;
211   /* list of ContentProtection DescriptorType nodes */
212   GList *ContentProtection;
213 };
214
215 struct _GstSubRepresentationNode
216 {
217   /* RepresentationBase extension */
218   GstRepresentationBaseType *RepresentationBase;
219   guint level;
220   guint *dependencyLevel;            /* UIntVectorType */
221   guint size;                        /* size of "dependencyLevel" array */
222   guint bandwidth;
223   gchar **contentComponent;          /* StringVectorType */
224 };
225
226 struct _GstRepresentationNode
227 {
228   gchar *id;
229   guint bandwidth;
230   guint qualityRanking;
231   gchar **dependencyId;              /* StringVectorType */
232   gchar **mediaStreamStructureId;    /* StringVectorType */
233   /* RepresentationBase extension */
234   GstRepresentationBaseType *RepresentationBase;
235   /* list of BaseURL nodes */
236   GList *BaseURLs;
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;
245 };
246
247 struct _GstDescriptorType
248 {
249   gchar *schemeIdUri;
250   gchar *value;
251   /* For adding ContentProtection to caps , get string of <mspr:pro> */
252   gchar *msprPro;
253 };
254
255 struct _GstContentComponentNode
256 {
257   guint id;
258   gchar *lang;                      /* LangVectorType RFC 5646 */
259   gchar *contentType;
260   GstRatio *par;
261   /* list of Accessibility DescriptorType nodes */
262   GList *Accessibility;
263   /* list of Role DescriptorType nodes */
264   GList *Role;
265   /* list of Rating DescriptorType nodes */
266   GList *Rating;
267   /* list of Viewpoint DescriptorType nodes */
268   GList *Viewpoint;
269 };
270
271 struct _GstAdaptationSetNode
272 {
273   guint id;
274   guint group;
275   gchar *lang;                      /* LangVectorType RFC 5646 */
276   gchar *contentType;
277   GstRatio *par;
278   guint minBandwidth;
279   guint maxBandwidth;
280   guint minWidth;
281   guint maxWidth;
282   guint minHeight;
283   guint maxHeight;
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 */
293   GList *Role;
294   /* list of Rating DescriptorType nodes */
295   GList *Rating;
296   /* list of Viewpoint DescriptorType nodes */
297   GList *Viewpoint;
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 */
307   GList *BaseURLs;
308   /* list of Representation nodes */
309   GList *Representations;
310   /* list of ContentComponent nodes */
311   GList *ContentComponents;
312 };
313
314 struct _GstSubsetNode
315 {
316   guint *contains;                   /* UIntVectorType */
317   guint size;                        /* size of the "contains" array */
318 };
319
320 struct _GstPeriodNode
321 {
322   gchar *id;
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 */
335   GList *Subsets;
336   /* list of BaseURL nodes */
337   GList *BaseURLs;
338 };
339
340 struct _GstProgramInformationNode
341 {
342   gchar *lang;                      /* LangVectorType RFC 5646 */
343   gchar *moreInformationURL;
344   /* children nodes */
345   gchar *Title;
346   gchar *Source;
347   gchar *Copyright;
348 };
349
350 struct _GstMetricsRangeNode
351 {
352   gint64 starttime;                  /* [ms] */
353   gint64 duration;                   /* [ms] */
354 };
355
356 struct _GstMetricsNode
357 {
358   gchar *metrics;
359   /* list of Metrics Range nodes */
360   GList *MetricsRanges;
361   /* list of Reporting nodes */
362   GList *Reportings;
363 };
364
365 struct _GstMPDNode
366 {
367   gchar *default_namespace;
368   gchar *namespace_xsi;
369   gchar *namespace_ext;
370   gchar *schemaLocation;
371   gchar *id;
372   gchar *profiles;
373   GstMPDFileType type;
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 */
384   GList *BaseURLs;
385   /* list of Location nodes */
386   GList *Locations;
387   /* List of ProgramInformation nodes */
388   GList *ProgramInfo;
389   /* list of Periods nodes */
390   GList *Periods;
391   /* list of Metrics nodes */
392   GList *Metrics;
393 };
394
395 /**
396  * GstStreamPeriod:
397  *
398  * Stream period data structure
399  */
400 struct _GstStreamPeriod
401 {
402   GstPeriodNode *period;                      /* Stream period */
403   guint number;                               /* Period number */
404   GstClockTime start;                         /* Period start time */
405   GstClockTime duration;                      /* Period duration */
406 };
407
408 /**
409  * GstMediaSegment:
410  *
411  * Media segment data structure
412  */
413 struct _GstMediaSegment
414 {
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 */
420 };
421
422 /**
423  * GstActiveStream:
424  *
425  * Active stream data structure
426  */
427 struct _GstActiveStream
428 {
429   GstStreamMimeType mimeType;                 /* video/audio/application */
430
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 */
434
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 */
443 };
444
445 struct _GstMpdClient
446 {
447   GstMPDNode *mpd_node;                       /* active MPD manifest file */
448
449   GList *periods;                             /* list of GstStreamPeriod */
450   guint period_idx;                           /* index of current Period */
451
452   GList *active_streams;                      /* list of GstActiveStream */
453   guint stream_idx;                           /* currently active stream */
454
455   guint update_failed_count;
456   gchar *mpd_uri;                             /* manifest file URI */
457   GMutex *lock;
458 };
459
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);
464
465 /* MPD file parsing */
466 gboolean gst_mpd_parse (GstMpdClient *client, const gchar *data, gint size);
467
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);
478
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
483 /* Representation selection */
484 gint gst_mpdparser_get_rep_idx_with_max_bandwidth (GList *Representations, gint max_bandwidth);
485
486 /* URL management */
487 const gchar *gst_mpdparser_get_baseURL (GstMpdClient *client);
488 GstMediaSegment *gst_mpdparser_get_chunk_by_index (GstMpdClient *client, guint indexStream, guint indexChunk);
489
490 /* Active stream */
491 guint gst_mpdparser_get_nb_active_stream (GstMpdClient *client);
492 GstActiveStream *gst_mpdparser_get_active_stream_by_index (GstMpdClient *client, guint stream_idx);
493
494 /* AdaptationSet */
495 guint gst_mpdparser_get_nb_adaptationSet (GstMpdClient *client);
496
497 /* Segment */
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);
500
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);
508
509 /* Support multi language */
510 guint gst_mpdparser_get_list_and_nb_of_audio_language (GstMpdClient *client, GList **lang);
511 G_END_DECLS
512
513 #endif /* __GST_MPDPARSER_H__ */