avidemux: Push mode seeking support
[platform/upstream/gst-plugins-good.git] / gst / avi / gstavidemux.h
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  * Copyright (C) <2006> Nokia Corporation (contact <stefan.kost@nokia.com>)
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #ifndef __GST_AVI_DEMUX_H__
22 #define __GST_AVI_DEMUX_H__
23
24 #include <gst/gst.h>
25
26 #include "avi-ids.h"
27 #include "gst/riff/riff-ids.h"
28 #include "gst/riff/riff-read.h"
29 #include <gst/base/gstadapter.h>
30
31 G_BEGIN_DECLS
32
33 #define GST_TYPE_AVI_DEMUX \
34   (gst_avi_demux_get_type ())
35 #define GST_AVI_DEMUX(obj) \
36   (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_AVI_DEMUX, GstAviDemux))
37 #define GST_AVI_DEMUX_CLASS(klass) \
38   (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_AVI_DEMUX, GstAviDemuxClass))
39 #define GST_IS_AVI_DEMUX(obj) \
40   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_AVI_DEMUX))
41 #define GST_IS_AVI_DEMUX_CLASS(klass) \
42   (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_AVI_DEMUX))
43
44 #define GST_AVI_DEMUX_MAX_STREAMS       16
45
46 #define CHUNKID_TO_STREAMNR(chunkid) \
47   ((((chunkid) & 0xff) - '0') * 10 + \
48    (((chunkid) >> 8) & 0xff) - '0')
49
50
51 /* new index entries 24 bytes */
52 typedef struct {
53   guint32        flags;
54   guint32        size;    /* bytes of the data */
55   guint64        offset;  /* data offset in file */
56   guint64        total;   /* total bytes before */
57 } GstAviIndexEntry;
58
59 #define GST_AVI_KEYFRAME 1
60 #define ENTRY_IS_KEYFRAME(e) ((e)->flags == GST_AVI_KEYFRAME)
61 #define ENTRY_SET_KEYFRAME(e) ((e)->flags = GST_AVI_KEYFRAME)
62 #define ENTRY_UNSET_KEYFRAME(e) ((e)->flags = 0)
63
64 typedef struct {
65   /* index of this streamcontext */
66   guint          num;
67
68   /* pad*/
69   GstPad        *pad;
70   gboolean       exposed;
71
72   /* stream info and headers */
73   gst_riff_strh *strh;
74   union {
75     gst_riff_strf_vids *vids;
76     gst_riff_strf_auds *auds;
77     gst_riff_strf_iavs *iavs;
78     gpointer     data;
79   } strf;
80   GstBuffer     *extradata, *initdata;
81   gchar         *name;
82
83   /* the start/step/stop entries */
84   guint          start_entry;
85   guint          step_entry;
86   guint          stop_entry;
87
88   /* current index entry */
89   guint          current_entry;
90   /* position (byte, frame, time) for current_entry */
91   guint          current_total;
92   GstClockTime   current_timestamp;
93   GstClockTime   current_ts_end;
94   guint64        current_offset;
95   guint64        current_offset_end;
96
97   GstFlowReturn  last_flow;
98   gboolean       discont;
99
100   /* stream length */
101   guint64        total_bytes;
102   guint32        total_blocks;
103   guint          n_keyframes;
104   /* stream length according to index */
105   GstClockTime   idx_duration;
106   /* stream length according to header */
107   GstClockTime   hdr_duration;
108   /* stream length based on header/index */
109   GstClockTime   duration;
110
111   /* VBR indicator */
112   gboolean       is_vbr;
113
114   /* openDML support (for files >4GB) */
115   gboolean       superindex;
116   guint64       *indexes;
117
118   /* new indexes */
119   GstAviIndexEntry *index;     /* array with index entries */
120   guint             idx_n;     /* number of entries */
121   guint             idx_max;   /* max allocated size of entries */
122
123   GstTagList    *taglist;
124
125   gint           index_id;
126 } GstAviStream;
127
128 typedef enum {
129   GST_AVI_DEMUX_START,
130   GST_AVI_DEMUX_HEADER,
131   GST_AVI_DEMUX_MOVI,
132   GST_AVI_DEMUX_SEEK,
133 } GstAviDemuxState;
134
135 typedef enum {
136   GST_AVI_DEMUX_HEADER_TAG_LIST,
137   GST_AVI_DEMUX_HEADER_AVIH,
138   GST_AVI_DEMUX_HEADER_ELEMENTS,
139   GST_AVI_DEMUX_HEADER_INFO,
140   GST_AVI_DEMUX_HEADER_JUNK,
141   GST_AVI_DEMUX_HEADER_DATA
142 } GstAviDemuxHeaderState;
143
144 typedef struct _GstAviDemux {
145   GstElement     parent;
146
147   /* pads */
148   GstPad        *sinkpad;
149
150   /* AVI decoding state */
151   GstAviDemuxState state;
152   GstAviDemuxHeaderState header_state;
153   guint64        offset;
154   gboolean       abort_buffering;
155
156   /* when we loaded the indexes */
157   gboolean       have_index;
158   /* index offset in the file */
159   guint64        index_offset;
160
161   /* streams */
162   GstAviStream   stream[GST_AVI_DEMUX_MAX_STREAMS];
163   guint          num_streams;
164   guint          num_v_streams;
165   guint          num_a_streams;
166   guint          num_t_streams;  /* subtitle text streams */
167
168   guint          main_stream; /* used for seeking */
169
170   /* for streaming mode */
171   gboolean       streaming;
172   gboolean       have_eos;
173   GstAdapter    *adapter;
174   guint          todrop;
175
176   /* some stream info for length */
177   gst_riff_avih *avih;
178   GstClockTime   duration;
179
180   /* segment in TIME */
181   GstSegment     segment;
182   gboolean       segment_running;
183
184   /* pending tags/events */
185   GstEvent      *seg_event;
186   GstTagList    *globaltags;
187   gboolean       got_tags;
188
189   /* gst index support */
190   GstIndex      *element_index;
191   gint           index_id;
192   gboolean       seekable;
193
194   guint64        first_movi_offset;
195   guint64        idx1_offset; /* offset in file of list/chunk after movi */
196   GstEvent      *event_seek;
197
198   gboolean       building_index;
199   guint          odml_stream;
200   guint          odml_subidx;
201   guint64       *odml_subidxs;
202 } GstAviDemux;
203
204 typedef struct _GstAviDemuxClass {
205   GstElementClass parent_class;
206 } GstAviDemuxClass;
207
208 GType           gst_avi_demux_get_type          (void);
209
210 G_END_DECLS
211
212 #endif /* __GST_AVI_DEMUX_H__ */