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