1 /*
2  * DASH demux plugin for GStreamer
3  *
4  * gstdashdemux.h
5  *
6  * Copyright (C) 2012 Orange
7  * Authors:
8  *   David Corvoysier <david.corvoysier@orange.com>
9  *   Hamid Zakari <hamid.zakari@gmail.com>
10  *
11  * Copyright (C) 2013 Smart TV Alliance
12  *  Author: Thiago Sousa Santos <thiago.sousa.santos@collabora.com>, Collabora Ltd.
13  *
14  * This library is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU Library General Public
16  * License as published by the Free Software Foundation; either
17  * version 2.1 of the License, or (at your option) any later version.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22  * Library General Public License for more details.
23  *
24  * You should have received a copy of the GNU Library General Public
25  * License along with this library (COPYING); if not, write to the
26  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27  * Boston, MA 02111-1307, USA.
28  */
29 
30 #ifndef __GST_DASH_DEMUX_H__
31 #define __GST_DASH_DEMUX_H__
32 
33 #include <gst/gst.h>
34 #include <gst/adaptivedemux/gstadaptivedemux.h>
35 #include <gst/base/gstadapter.h>
36 #include <gst/base/gstdataqueue.h>
37 #include "gstmpdparser.h"
38 #include <gst/isoff/gstisoff.h>
39 #include <gst/uridownloader/gsturidownloader.h>
40 
41 G_BEGIN_DECLS
42 #define GST_TYPE_DASH_DEMUX \
43         (gst_dash_demux_get_type())
44 #define GST_DASH_DEMUX(obj) \
45         (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DASH_DEMUX,GstDashDemux))
46 #define GST_DASH_DEMUX_CLASS(klass) \
47         (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DASH_DEMUX,GstDashDemuxClass))
48 #define GST_IS_DASH_DEMUX(obj) \
49         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DASH_DEMUX))
50 #define GST_IS_DASH_DEMUX_CLASS(klass) \
51         (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DASH_DEMUX))
52 #define GST_DASH_DEMUX_CAST(obj) \
53 	((GstDashDemux *)obj)
54 
55 typedef struct _GstDashDemuxClockDrift GstDashDemuxClockDrift;
56 typedef struct _GstDashDemuxStream GstDashDemuxStream;
57 typedef struct _GstDashDemux GstDashDemux;
58 typedef struct _GstDashDemuxClass GstDashDemuxClass;
59 
60 struct _GstDashDemuxStream
61 {
62   GstAdaptiveDemuxStream parent;
63 
64   gint index;
65   GstActiveStream *active_stream;
66 
67   GstMediaFragmentInfo current_fragment;
68 
69   /* index parsing */
70   GstSidxParser sidx_parser;
71   GstClockTime sidx_position;
72   gint64 sidx_base_offset;
73   gboolean allow_sidx;
74   GstClockTime pending_seek_ts;
75 
76   GstAdapter *adapter;
77   /* current offset of the first byte in the adapter / last byte we pushed or
78    * dropped*/
79   guint64 current_offset;
80   /* index = 1, header = 2, data = 3 */
81   guint current_index_header_or_data;
82 
83   /* ISOBMFF box parsing */
84   gboolean is_isobmff;
85   struct {
86     /* index = 1, header = 2, data = 3 */
87     guint32 current_fourcc;
88     guint64 current_start_offset;
89     guint64 current_size;
90   } isobmff_parser;
91 
92   GstMoofBox *moof;
93   guint64 moof_offset, moof_size;
94   GArray *moof_sync_samples;
95   guint current_sync_sample;
96 
97   guint64 moof_average_size;
98   guint64 keyframe_average_size;
99   guint64 keyframe_average_distance;
100   gboolean first_sync_sample_after_moof, first_sync_sample_always_after_moof;
101 
102   /* Internal position value, at the keyframe/entry level */
103   GstClockTime actual_position;
104   /* Timestamp of the beginning of the current fragment */
105   GstClockTime current_fragment_timestamp;
106   GstClockTime current_fragment_duration;
107   GstClockTime current_fragment_keyframe_distance;
108 
109   /* Average keyframe download time (only in trickmode-key-units) */
110   GstClockTime average_download_time;
111   /* Cached target time (only in trickmode-key-units) */
112   GstClockTime target_time;
113   /* Average skip-ahead time (only in trickmode-key-units) */
114   GstClockTime average_skip_size;
115 };
116 
117 /**
118  * GstDashDemux:
119  *
120  * Opaque #GstDashDemux data structure.
121  */
122 struct _GstDashDemux
123 {
124   GstAdaptiveDemux parent;
125 
126   GSList *next_periods;
127 
128   GstMpdClient *client;         /* MPD client */
129   GMutex client_lock;
130 
131   GstDashDemuxClockDrift *clock_drift;
132 
133   gboolean end_of_period;
134   gboolean end_of_manifest;
135 
136   /* Properties */
137   GstClockTime max_buffering_time;      /* Maximum buffering time accumulated during playback */
138   guint max_bitrate;          /* max of bitrate supported by target decoder         */
139   gint max_video_width, max_video_height;
140   gint max_video_framerate_n, max_video_framerate_d;
141   gchar* default_presentation_delay; /* presentation time delay if MPD@suggestedPresentationDelay is not present */
142 
143   gint n_audio_streams;
144   gint n_video_streams;
145   gint n_subtitle_streams;
146 
147   gboolean trickmode_no_audio;
148   gboolean allow_trickmode_key_units;
149 };
150 
151 struct _GstDashDemuxClass
152 {
153   GstAdaptiveDemuxClass parent_class;
154 };
155 
156 GType gst_dash_demux_get_type (void);
157 
158 G_END_DECLS
159 #endif /* __GST_DASH_DEMUX_H__ */
160 
161