7dd6f9638dc229f8422b7ef3a29567d65f55f9df
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-good / ext / adaptivedemux2 / dash / 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 #include <gst/base/gstadapter.h>
32
33 #include "gstadaptivedemux.h"
34
35 #include "gstmpd-prelude.h"
36 #include "gstmpdhelper.h"
37 #include "gstxmlhelper.h"
38 #include "gstmpdrootnode.h"
39 #include "gstmpdbaseurlnode.h"
40 #include "gstmpdutctimingnode.h"
41 #include "gstmpdmetricsnode.h"
42 #include "gstmpdmetricsrangenode.h"
43 #include "gstmpdsnode.h"
44 #include "gstmpdsegmenttimelinenode.h"
45 #include "gstmpdsegmenttemplatenode.h"
46 #include "gstmpdsegmenturlnode.h"
47 #include "gstmpdsegmentlistnode.h"
48 #include "gstmpdsegmentbasenode.h"
49 #include "gstmpdperiodnode.h"
50 #include "gstmpdrepresentationnode.h"
51 #include "gstmpdsubrepresentationnode.h"
52 #include "gstmpdcontentcomponentnode.h"
53 #include "gstmpdadaptationsetnode.h"
54 #include "gstmpdsubsetnode.h"
55 #include "gstmpdprograminformationnode.h"
56 #include "gstmpdlocationnode.h"
57 #include "gstmpdreportingnode.h"
58 #include "gstmpdurltypenode.h"
59 #include "gstmpddescriptortypenode.h"
60 #include "gstmpdrepresentationbasenode.h"
61 #include "gstmpdmultsegmentbasenode.h"
62
63 G_BEGIN_DECLS
64
65 typedef struct _GstActiveStream           GstActiveStream;
66 typedef struct _GstStreamPeriod           GstStreamPeriod;
67 typedef struct _GstMediaFragmentInfo      GstMediaFragmentInfo;
68 typedef struct _GstMediaSegment           GstMediaSegment;
69
70
71 #define GST_MPD_DURATION_NONE ((guint64)-1)
72
73 typedef enum
74 {
75   GST_STREAM_UNKNOWN,
76   GST_STREAM_VIDEO,           /* video stream (the main one) */
77   GST_STREAM_AUDIO,           /* audio stream (optional) */
78   GST_STREAM_APPLICATION      /* application stream (optional): for timed text/subtitles */
79 } GstStreamMimeType;
80
81 /**
82  * GstStreamPeriod:
83  *
84  * Stream period data structure
85  */
86 struct _GstStreamPeriod
87 {
88   GstMPDPeriodNode *period;                      /* Stream period */
89   guint number;                               /* Period number */
90   GstClockTime start;                         /* Period start time */
91   GstClockTime duration;                      /* Period duration */
92 };
93
94 /**
95  * GstMediaSegment:
96  *
97  * Media segment data structure
98  */
99 struct _GstMediaSegment
100 {
101   GstMPDSegmentURLNode *SegmentURL;              /* this is NULL when using a SegmentTemplate */
102   guint number;                               /* segment number */
103   gint repeat;                                /* number of extra repetitions (0 = played only once) */
104   guint64 scale_start;                        /* start time in timescale units */
105   guint64 scale_duration;                     /* duration in timescale units */
106   GstClockTime start;                         /* segment start time */
107   GstClockTime duration;                      /* segment duration */
108 };
109
110 struct _GstMediaFragmentInfo
111 {
112   gchar *uri;
113   gint64 range_start;
114   gint64 range_end;
115
116   gchar *index_uri;
117   gint64 index_range_start;
118   gint64 index_range_end;
119
120   gboolean discontinuity;
121   GstClockTime timestamp;
122   GstClockTime duration;
123 };
124
125 /**
126  * GstActiveStream:
127  *
128  * Active stream data structure
129  */
130 struct _GstActiveStream
131 {
132   GstStreamMimeType mimeType;                 /* video/audio/application */
133
134   guint baseURL_idx;                          /* index of the baseURL used for last request */
135   gchar *baseURL;                             /* active baseURL used for last request */
136   gchar *queryURL;                            /* active queryURL used for last request */
137   guint max_bandwidth;                        /* max bandwidth allowed for this mimeType */
138
139   GstMPDAdaptationSetNode *cur_adapt_set;        /* active adaptation set */
140   gint representation_idx;                    /* index of current representation */
141   GstMPDRepresentationNode *cur_representation;  /* active representation */
142   GstMPDSegmentBaseNode *cur_segment_base;       /* active segment base */
143   GstMPDSegmentListNode *cur_segment_list;       /* active segment list */
144   GstMPDSegmentTemplateNode *cur_seg_template;   /* active segment template */
145   gint segment_index;                         /* index of next sequence chunk */
146   guint segment_repeat_index;                 /* index of the repeat count of a segment */
147   GPtrArray *segments;                        /* array of GstMediaSegment */
148   GstClockTime presentationTimeOffset;        /* presentation time offset of the current segment */
149 };
150
151 /* MPD file parsing */
152 gboolean gst_mpdparser_get_mpd_root_node (GstMPDRootNode ** mpd_root_node, const gchar * data, gint size);
153 GstMPDSegmentListNode * gst_mpdparser_get_external_segment_list (const gchar * data, gint size, GstMPDSegmentListNode * parent);
154 GList * gst_mpdparser_get_external_periods (const gchar * data, gint size);
155 GList * gst_mpdparser_get_external_adaptation_sets (const gchar * data, gint size, GstMPDPeriodNode* period);
156
157 /* navigation functions */
158 GstStreamMimeType gst_mpdparser_representation_get_mimetype (GstMPDAdaptationSetNode * adapt_set, GstMPDRepresentationNode * rep);
159
160 /* Memory management */
161 void gst_mpdparser_free_stream_period (GstStreamPeriod * stream_period);
162 void gst_mpdparser_free_media_segment (GstMediaSegment * media_segment);
163 void gst_mpdparser_free_active_stream (GstActiveStream * active_stream);
164 void gst_mpdparser_media_fragment_info_clear (GstMediaFragmentInfo * fragment);
165 /* Active stream methods*/
166 void gst_mpdparser_init_active_stream_segments (GstActiveStream * stream);
167 gchar *gst_mpdparser_get_mediaURL (GstActiveStream * stream, GstMPDSegmentURLNode * segmentURL);
168 const gchar *gst_mpdparser_get_initializationURL (GstActiveStream * stream, GstMPDURLTypeNode * InitializationURL);
169 gchar *gst_mpdparser_build_URL_from_template (const gchar * url_template, const gchar * id, guint number, guint bandwidth, guint64 time);
170
171 G_END_DECLS
172
173 #endif /* __GST_MPDPARSER_H__ */
174