1 /* AVI muxer plugin for GStreamer
2  * Copyright (C) 2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 
20 
21 #ifndef __GST_AVI_MUX_H__
22 #define __GST_AVI_MUX_H__
23 
24 
25 #include <gst/gst.h>
26 #include <gst/base/gstcollectpads.h>
27 #include <gst/riff/riff-ids.h>
28 #include "avi-ids.h"
29 
30 G_BEGIN_DECLS
31 
32 #define GST_TYPE_AVI_MUX \
33   (gst_avi_mux_get_type())
34 #define GST_AVI_MUX(obj) \
35   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AVI_MUX,GstAviMux))
36 #define GST_AVI_MUX_CLASS(klass) \
37   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_AVI_MUX,GstAviMuxClass))
38 #define GST_IS_AVI_MUX(obj) \
39   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AVI_MUX))
40 #define GST_IS_AVI_MUX_CLASS(klass) \
41   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_AVI_MUX))
42 
43 #define GST_AVI_INDEX_OF_INDEXES     0
44 #define GST_AVI_INDEX_OF_CHUNKS      1
45 
46 /* this allows indexing up to 64GB avi file */
47 #define GST_AVI_SUPERINDEX_COUNT    32
48 
49 /* max size */
50 #define GST_AVI_MAX_SIZE    0x40000000
51 
52 typedef struct _gst_avi_superindex_entry {
53   guint64 offset;
54   guint32 size;
55   guint32 duration;
56 } gst_avi_superindex_entry;
57 
58 typedef struct _gst_riff_strh_full {
59   gst_riff_strh  parent;
60   /* rcFrame, RECT structure (struct of 4 shorts) */
61   gint16  left;
62   gint16  top;
63   gint16  right;
64   gint16  bottom;
65 } gst_riff_strh_full;
66 
67 typedef struct _GstAviPad GstAviPad;
68 typedef struct _GstAviMux GstAviMux;
69 typedef struct _GstAviMuxClass GstAviMuxClass;
70 
71 typedef GstFlowReturn (*GstAviPadHook) (GstAviMux * avi, GstAviPad * avipad,
72                                         GstBuffer * buffer);
73 
74 struct _GstAviPad {
75   /* do not extend, link to it */
76   /* is NULL if original sink request pad has been removed */
77   GstCollectData *collect;
78 
79   /* type */
80   gboolean is_video;
81   gboolean connected;
82 
83   /* chunk tag */
84   gchar *tag;
85 
86   /* stream header */
87   gst_riff_strh hdr;
88 
89   /* odml super indexes */
90   gst_avi_superindex_entry idx[GST_AVI_SUPERINDEX_COUNT];
91   gint idx_index;
92   gchar *idx_tag;
93 
94   /* stream specific hook */
95   GstAviPadHook hook;
96 };
97 
98 typedef struct _GstAviVideoPad {
99   GstAviPad parent;
100 
101   /* stream format */
102   gst_riff_strf_vids vids;
103   /* extra data */
104   GstBuffer *vids_codec_data;
105   /* ODML video properties */
106   gst_riff_vprp vprp;
107 
108   GstBuffer *prepend_buffer;
109 
110 } GstAviVideoPad;
111 
112 typedef struct _GstAviAudioPad {
113   GstAviPad parent;
114 
115   /* stream format */
116   gst_riff_strf_auds auds;
117   /* audio info for bps calculation */
118   guint32 audio_size;
119   guint64 audio_time;
120   /* max audio chunk size for vbr */
121   guint32 max_audio_chunk;
122 
123   /* counts the number of samples to put in indx chunk
124    * useful for raw audio where usually there are more than
125    * 1 sample in each GstBuffer */
126   gint samples;
127 
128   /* extra data */
129   GstBuffer *auds_codec_data;
130 } GstAviAudioPad;
131 
132 typedef struct _GstAviCollectData {
133   /* extend the CollectData */
134   GstCollectData collect;
135 
136   GstAviPad      *avipad;
137 } GstAviCollectData;
138 
139 struct _GstAviMux {
140   GstElement element;
141 
142   /* pads */
143   GstPad              *srcpad;
144   /* sinkpads, video first */
145   GSList              *sinkpads;
146   /* video restricted to 1 pad */
147   guint               video_pads, audio_pads;
148   GstCollectPads     *collect;
149 
150   /* the AVI header */
151   /* still some single stream video data in mux struct */
152   gst_riff_avih avi_hdr;
153   /* total number of (video) frames */
154   guint32 total_frames;
155   /* amount of total data (bytes) */
156   guint64 total_data;
157   /* amount of data (bytes) in the AVI/AVIX block;
158    * actually the movi list, so counted from and including the movi tag */
159   guint32 data_size, datax_size;
160   /* num (video) frames in the AVI/AVIX block */
161   guint32 num_frames, numx_frames;
162   /* size of hdrl list, including tag as usual */
163 
164   /* total size of extra codec data */
165   guint32 codec_data_size;
166   /* state info */
167   gboolean write_header;
168   gboolean restart;
169 
170   /* tags */
171   GstTagList *tags_snap;
172 
173   /* information about the AVI index ('idx') */
174   gst_riff_index_entry *idx;
175   gint idx_index, idx_count;
176   /* offset of *chunk* (relative to a base offset); entered in the index */
177   guint32 idx_offset;
178   /* size of idx1 chunk (including! chunk header and size bytes) */
179   guint32 idx_size;
180 
181   /* are we a big file already? */
182   gboolean is_bigfile;
183   guint64 avix_start;
184 
185   /* whether to use "large AVI files" or just stick to small indexed files */
186   gboolean enable_large_avi;
187 };
188 
189 struct _GstAviMuxClass {
190   GstElementClass parent_class;
191 };
192 
193 GType gst_avi_mux_get_type(void);
194 
195 G_END_DECLS
196 
197 
198 #endif /* __GST_AVI_MUX_H__ */
199