2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2006> Nokia Corporation (contact <stefan.kost@nokia.com>)
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.
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.
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.
21 #ifndef __GST_AVI_DEMUX_H__
22 #define __GST_AVI_DEMUX_H__
27 #include "gst/riff/riff-ids.h"
28 #include "gst/riff/riff-read.h"
29 #include <gst/base/gstadapter.h>
31 #ifdef DIVX_DRM /* need to check using same define */
37 #define GST_TYPE_AVI_DEMUX \
38 (gst_avi_demux_get_type ())
39 #define GST_AVI_DEMUX(obj) \
40 (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_AVI_DEMUX, GstAviDemux))
41 #define GST_AVI_DEMUX_CLASS(klass) \
42 (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_AVI_DEMUX, GstAviDemuxClass))
43 #define GST_IS_AVI_DEMUX(obj) \
44 (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_AVI_DEMUX))
45 #define GST_IS_AVI_DEMUX_CLASS(klass) \
46 (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_AVI_DEMUX))
48 #define GST_AVI_DEMUX_MAX_STREAMS 16
50 #define AVIDEMUX_MODIFICATION
52 #define CHUNKID_TO_STREAMNR(chunkid) \
53 ((((chunkid) & 0xff) - '0') * 10 + \
54 (((chunkid) >> 8) & 0xff) - '0')
57 /* new index entries 24 bytes */
60 guint32 size; /* bytes of the data */
61 guint64 offset; /* data offset in file */
62 guint64 total; /* total bytes before */
65 #ifdef AVIDEMUX_MODIFICATION
66 typedef struct _TrickPlayInfo TrickPlayInfo;
68 struct _TrickPlayInfo {
70 gint32 next_kidx; // next Key index
71 gint32 prev_kidx; // Previous key index
72 guint64 kidxs_dur_diff; // duration between two consecutive key frames
73 gint32 show_samples; // samples to show between two consecutive key frames
74 guint64 start_pos; /* trickplay start position */
79 /* index of this streamcontext */
86 /* stream info and headers */
89 gst_riff_strf_vids *vids;
90 gst_riff_strf_auds *auds;
91 gst_riff_strf_iavs *iavs;
94 GstBuffer *extradata, *initdata;
97 /* the start/step/stop entries */
102 #ifdef AVIDEMUX_MODIFICATION
103 TrickPlayInfo *trickplay_info;
106 /* current index entry */
108 /* position (byte, frame, time) for current_entry */
110 GstClockTime current_timestamp;
111 GstClockTime current_ts_end;
112 guint64 current_offset;
113 guint64 current_offset_end;
115 GstFlowReturn last_flow;
120 guint32 total_blocks;
122 /* stream length according to index */
123 GstClockTime idx_duration;
124 /* stream length according to header */
125 GstClockTime hdr_duration;
126 /* stream length based on header/index */
127 GstClockTime duration;
132 /* openDML support (for files >4GB) */
137 GstAviIndexEntry *index; /* array with index entries */
138 guint idx_n; /* number of entries */
139 guint idx_max; /* max allocated size of entries */
148 GST_AVI_DEMUX_HEADER,
154 GST_AVI_DEMUX_HEADER_TAG_LIST,
155 GST_AVI_DEMUX_HEADER_AVIH,
156 GST_AVI_DEMUX_HEADER_ELEMENTS,
157 GST_AVI_DEMUX_HEADER_INFO,
158 GST_AVI_DEMUX_HEADER_JUNK,
159 GST_AVI_DEMUX_HEADER_DATA
160 } GstAviDemuxHeaderState;
162 typedef struct _GstAviDemux {
168 /* AVI decoding state */
169 GstAviDemuxState state;
170 GstAviDemuxHeaderState header_state;
172 gboolean abort_buffering;
174 /* when we loaded the indexes */
176 /* index offset in the file */
177 guint64 index_offset;
180 GstAviStream stream[GST_AVI_DEMUX_MAX_STREAMS];
184 guint num_t_streams; /* subtitle text streams */
186 guint main_stream; /* used for seeking */
188 /* for streaming mode */
194 /* some stream info for length */
196 GstClockTime duration;
198 /* segment in TIME */
200 gboolean segment_running;
202 /* pending tags/events */
204 GstEvent *close_seg_event;
205 GstTagList *globaltags;
208 /* gst index support */
209 GstIndex *element_index;
216 uint8_t* (*divx_init) (uint8_t*, int*);
217 int (*divx_commit) (uint8_t *);
218 int (*divx_decrypt_audio) (uint8_t *, uint8_t *, uint32_t);
219 int (*divx_prepare_video_bitstream) (uint8_t *, uint8_t * , uint32_t , uint8_t * , uint32_t * );
220 int (*divx_finalize) (uint8_t *);
223 guint64 first_movi_offset;
224 guint64 idx1_offset; /* offset in file of list/chunk after movi */
225 GstEvent *seek_event;
227 gboolean building_index;
230 guint64 *odml_subidxs;
232 guint64 seek_kf_offset; /* offset of the keyframe to which we want to seek */
235 typedef struct _GstAviDemuxClass {
236 GstElementClass parent_class;
239 GType gst_avi_demux_get_type (void);
243 #endif /* __GST_AVI_DEMUX_H__ */