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