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