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., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, 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 #include <gst/base/gstflowcombiner.h>
31 
32 G_BEGIN_DECLS
33 
34 #define GST_TYPE_AVI_DEMUX \
35   (gst_avi_demux_get_type ())
36 #define GST_AVI_DEMUX(obj) \
37   (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_AVI_DEMUX, GstAviDemux))
38 #define GST_AVI_DEMUX_CLASS(klass) \
39   (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_AVI_DEMUX, GstAviDemuxClass))
40 #define GST_IS_AVI_DEMUX(obj) \
41   (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_AVI_DEMUX))
42 #define GST_IS_AVI_DEMUX_CLASS(klass) \
43   (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_AVI_DEMUX))
44 
45 #define GST_AVI_DEMUX_MAX_STREAMS       16
46 
47 #define CHUNKID_TO_STREAMNR(chunkid) \
48   ((((chunkid) & 0xff) - '0') * 10 + \
49    (((chunkid) >> 8) & 0xff) - '0')
50 
51 
52 /* new index entries 24 bytes */
53 typedef struct {
54   guint32        flags;
55   guint32        size;    /* bytes of the data */
56   guint64        offset;  /* data offset in file */
57   guint64        total;   /* total bytes before */
58 } GstAviIndexEntry;
59 
60 typedef struct {
61   /* index of this streamcontext */
62   guint          num;
63 
64   /* pad*/
65   GstPad        *pad;
66   gboolean       exposed;
67 
68   /* stream info and headers */
69   gst_riff_strh *strh;
70   union {
71     gst_riff_strf_vids *vids;
72     gst_riff_strf_auds *auds;
73     gst_riff_strf_iavs *iavs;
74     gpointer     data;
75   } strf;
76   GstBuffer     *extradata, *initdata;
77   GstBuffer     *rgb8_palette;
78   gchar         *name;
79 
80   /* the start/step/stop entries */
81   guint          start_entry;
82   guint          step_entry;
83   guint          stop_entry;
84 
85   /* current index entry */
86   guint          current_entry;
87   /* position (byte, frame, time) for current_entry */
88   guint          current_total;
89   GstClockTime   current_timestamp;
90   GstClockTime   current_ts_end;
91   guint64        current_offset;
92   guint64        current_offset_end;
93 
94   gboolean       discont;
95 
96   /* stream length */
97   guint64        total_bytes;
98   guint32        total_blocks;
99   guint          n_keyframes;
100   /* stream length according to index */
101   GstClockTime   idx_duration;
102   /* stream length according to header */
103   GstClockTime   hdr_duration;
104   /* stream length based on header/index */
105   GstClockTime   duration;
106 
107   /* VBR indicator */
108   gboolean       is_vbr;
109 
110   /* openDML support (for files >4GB) */
111   gboolean       superindex;
112   guint64       *indexes;
113 
114   /* new indexes */
115   GstAviIndexEntry *index;     /* array with index entries */
116   guint             idx_n;     /* number of entries */
117   guint             idx_max;   /* max allocated size of entries */
118 
119   GstTagList	*taglist;
120 
121   gint           index_id;
122   gboolean is_raw;
123   gsize alignment;
124 } GstAviStream;
125 
126 typedef enum {
127   GST_AVI_DEMUX_START,
128   GST_AVI_DEMUX_HEADER,
129   GST_AVI_DEMUX_MOVI,
130   GST_AVI_DEMUX_SEEK,
131 } GstAviDemuxState;
132 
133 typedef enum {
134   GST_AVI_DEMUX_HEADER_TAG_LIST,
135   GST_AVI_DEMUX_HEADER_AVIH,
136   GST_AVI_DEMUX_HEADER_ELEMENTS,
137   GST_AVI_DEMUX_HEADER_INFO,
138   GST_AVI_DEMUX_HEADER_JUNK,
139   GST_AVI_DEMUX_HEADER_DATA
140 } GstAviDemuxHeaderState;
141 
142 typedef struct _GstAviDemux {
143   GstElement     parent;
144 
145   /* pads */
146   GstPad        *sinkpad;
147 
148   /* AVI decoding state */
149   GstAviDemuxState state;
150   GstAviDemuxHeaderState header_state;
151   guint64        offset;
152   gboolean       abort_buffering;
153 
154   /* when we loaded the indexes */
155   gboolean       have_index;
156   /* index offset in the file */
157   guint64        index_offset;
158 
159   /* streams */
160   GstAviStream   stream[GST_AVI_DEMUX_MAX_STREAMS];
161   guint          num_streams;
162   guint          num_v_streams;
163   guint          num_a_streams;
164   guint          num_t_streams;   /* subtitle text streams */
165   guint          num_sp_streams;  /* subpicture streams */
166 
167   guint          main_stream; /* used for seeking */
168 
169   GstFlowCombiner *flowcombiner;
170 
171   gboolean       have_group_id;
172   guint          group_id;
173 
174   /* for streaming mode */
175   gboolean       streaming;
176   gboolean       have_eos;
177   GstAdapter    *adapter;
178   guint          todrop;
179 
180   /* some stream info for length */
181   gst_riff_avih *avih;
182   GstClockTime   duration;
183 
184   /* segment in TIME */
185   GstSegment     segment;
186   guint32        segment_seqnum;
187 
188   /* pending tags/events */
189   GstEvent      *seg_event;
190   GstTagList	*globaltags;
191   gboolean	 got_tags;
192 
193 #if 0
194   /* gst index support */
195   GstIndex      *element_index;
196   gint           index_id;
197 #endif
198 
199   gboolean       seekable;
200 
201   guint64        first_movi_offset;
202   guint64        idx1_offset; /* offset in file of list/chunk after movi */
203   GstEvent      *seek_event;
204 
205   gboolean       building_index;
206   guint          odml_stream;
207   guint          odml_subidx;
208   guint64       *odml_subidxs;
209 
210   guint64        seek_kf_offset; /* offset of the keyframe to which we want to seek */
211 } GstAviDemux;
212 
213 typedef struct _GstAviDemuxClass {
214   GstElementClass parent_class;
215 } GstAviDemuxClass;
216 
217 GType           gst_avi_demux_get_type          (void);
218 
219 G_END_DECLS
220 
221 #endif /* __GST_AVI_DEMUX_H__ */
222