2 * Copyright (C) 2004 Wim Taymans <wim@fluendo.com>
4 * gstoggdemux.c: ogg stream demuxer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #ifndef __GST_OGG_DEMUX_H__
23 #define __GST_OGG_DEMUX_H__
29 #include "gstoggstream.h"
33 #define GST_TYPE_OGG_PAD (gst_ogg_pad_get_type())
34 #define GST_OGG_PAD(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_OGG_PAD, GstOggPad))
35 #define GST_OGG_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_OGG_PAD, GstOggPad))
36 #define GST_IS_OGG_PAD(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_OGG_PAD))
37 #define GST_IS_OGG_PAD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_OGG_PAD))
39 typedef struct _GstOggPad GstOggPad;
40 typedef struct _GstOggPadClass GstOggPadClass;
42 #define GST_TYPE_OGG_DEMUX (gst_ogg_demux_get_type())
43 #define GST_OGG_DEMUX(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_OGG_DEMUX, GstOggDemux))
44 #define GST_OGG_DEMUX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_OGG_DEMUX, GstOggDemux))
45 #define GST_IS_OGG_DEMUX(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_OGG_DEMUX))
46 #define GST_IS_OGG_DEMUX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_OGG_DEMUX))
48 GType gst_ogg_demux_get_type (void);
50 typedef struct _GstOggDemux GstOggDemux;
51 typedef struct _GstOggDemuxClass GstOggDemuxClass;
52 typedef struct _GstOggChain GstOggChain;
54 /* all information needed for one ogg chain (relevant for chained bitstreams) */
59 gint64 offset; /* starting offset of chain */
60 gint64 end_offset; /* end offset of chain */
61 gint64 bytes; /* number of bytes */
67 GstClockTime total_time; /* the total time of this chain, this is the MAX of
68 the totals of all streams */
69 GstClockTime begin_time; /* when this chain starts in the stream */
71 GstClockTime segment_start; /* the timestamp of the first sample, this is the MIN of
72 the start times of all streams. */
73 GstClockTime segment_stop; /* the timestamp of the last page, this is the MAX of the
77 /* different modes for the pad */
80 GST_OGG_PAD_MODE_INIT, /* we are feeding our internal decoder to get info */
81 GST_OGG_PAD_MODE_STREAMING, /* we are streaming buffers to the outside */
84 /* all information needed for one ogg stream */
87 GstPad pad; /* subclass GstPad */
92 GstOggChain *chain; /* the chain we are part of */
93 GstOggDemux *ogg; /* the ogg demuxer we are part of */
98 gint64 current_granule;
99 gint64 keyframe_granule;
101 GstClockTime start_time; /* the timestamp of the first sample */
103 gint64 first_granule; /* the granulepos of first page == first sample in next page */
104 GstClockTime first_time; /* the timestamp of the second page or granuletime of first page */
106 GstClockTime last_stop; /* last_stop when last push occured; used to detect when we
107 * need to send a newsegment update event for sparse streams */
112 GstFlowReturn last_ret; /* last return of _pad_push() */
117 /* push mode seeking */
118 GstClockTime push_kf_time;
119 GstClockTime push_sync_time;
122 struct _GstOggPadClass
124 GstPadClass parent_class;
130 * The ogg demuxer object structure.
145 gboolean need_chains;
148 /* keep track of how large pages and packets are,
149 useful for skewing when seeking */
150 guint64 max_packet_size, max_page_size;
153 GMutex *chain_lock; /* we need the lock to protect the chains */
154 GArray *chains; /* list of chains we know */
155 GstClockTime total_time;
156 gint bitrate; /* bitrate of the current chain */
158 GstOggChain *current_chain;
159 GstOggChain *building_chain;
161 /* playback start/stop positions */
163 gboolean segment_running;
167 GstEvent *newsegment; /* pending newsegment to be sent from _loop */
173 /* push mode seeking support */
174 GMutex *push_lock; /* we need the lock to protect the push mode variables */
175 gint64 push_byte_offset; /* where were are at in the stream, in bytes */
176 gint64 push_byte_length; /* length in bytes of the stream, -1 if unknown */
177 GstClockTime push_time_length; /* length in time of the stream */
178 GstClockTime push_start_time; /* start time of the stream */
179 GstClockTime push_time_offset; /* where were are at in the stream, in time */
180 enum { PUSH_PLAYING, PUSH_DURATION, PUSH_BISECT1, PUSH_LINEAR1, PUSH_BISECT2, PUSH_LINEAR2 } push_state;
182 GstClockTime push_seek_time_original_target;
183 GstClockTime push_seek_time_target;
184 gint64 push_last_seek_offset;
185 GstClockTime push_last_seek_time;
186 gint64 push_offset0, push_offset1; /* bisection search offset bounds */
187 GstClockTime push_time0, push_time1; /* bisection search time bounds */
189 double push_seek_rate;
190 GstSeekFlags push_seek_flags;
191 GstEvent *push_mode_seek_delayed_event;
192 gboolean push_disable_seeking;
193 gboolean seek_secant;
194 gboolean seek_undershot;
195 GstClockTime push_prev_seek_time;
197 gint push_bisection_steps[2];
198 gint stats_bisection_steps[2];
199 gint stats_bisection_max_steps[2];
200 gint stats_nbisections;
206 struct _GstOggDemuxClass
208 GstElementClass parent_class;
211 gboolean gst_ogg_demux_plugin_init (GstPlugin * plugin);
215 #endif /* __GST_OGG_DEMUX_H__ */