Small updates to avimux and the v4l plugins for usability in general
[platform/upstream/gst-plugins-good.git] / gst / avi / gstavimux.c
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., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /* based on:
21  * - the old avimuxer (by Wim Taymans)
22  * - xawtv's aviwriter (by Gerd Knorr)
23  * - mjpegtools' avilib (by Rainer Johanni)
24  * - openDML large-AVI docs
25  */
26
27
28 #include <config.h>
29
30 #include <stdlib.h>
31 #include <string.h>
32
33 #include "gstavimux.h"
34
35 #ifndef LE_FROM_GUINT16
36 #define LE_FROM_GUINT16 GUINT16_FROM_LE
37 #endif
38
39 #ifndef LE_FROM_GUINT32
40 #define LE_FROM_GUINT32 GUINT32_FROM_LE
41 #endif
42
43
44 /* elementfactory information */
45 static GstElementDetails 
46 gst_avimux_details = 
47 {
48   ".avi mux",
49   "Mux/Video",
50   "Muxes audio and video into an avi stream",
51   VERSION,
52   "Ronald Bultje <rbultje@ronald.bitfreak.net>",
53   "(C) 2002",
54 };
55
56 /* AviMux signals and args */
57 enum {
58   /* FILL ME */
59   LAST_SIGNAL
60 };
61
62 enum {
63   ARG_0,
64   ARG_BIGFILE,
65   ARG_FRAMERATE,
66 };
67
68 GST_PADTEMPLATE_FACTORY (src_factory,
69   "src",
70   GST_PAD_SRC,
71   GST_PAD_ALWAYS,
72   GST_CAPS_NEW (
73     "avimux_src_video",
74     "video/avi",
75     NULL
76   )
77 )
78     
79 GST_PADTEMPLATE_FACTORY (video_sink_factory,
80   "video_%02d",
81   GST_PAD_SINK,
82   GST_PAD_REQUEST,
83   GST_CAPS_NEW (
84     "avimux_sink_video",
85     "video/avi",
86       "format",   GST_PROPS_STRING ("strf_vids")
87   ),
88   GST_CAPS_NEW (
89     "avimux_sink_video",
90     "video/raw",
91       "format", GST_PROPS_LIST (
92                   GST_PROPS_FOURCC (GST_MAKE_FOURCC('Y','U','Y','2')),
93                   GST_PROPS_FOURCC (GST_MAKE_FOURCC('I','4','2','0')),
94                   GST_PROPS_FOURCC (GST_MAKE_FOURCC('Y','4','1','P'))
95                 ),
96       "width",  GST_PROPS_INT_RANGE (16, 4096),
97       "height", GST_PROPS_INT_RANGE (16, 4096)
98   ),
99   GST_CAPS_NEW (
100     "avimux_sink_video",
101     "video/raw",
102       "format", GST_PROPS_FOURCC (GST_MAKE_FOURCC('R','G','B',' ')),
103       "width",  GST_PROPS_INT_RANGE (16, 4096),
104       "height", GST_PROPS_INT_RANGE (16, 4096),
105       "depth",  GST_PROPS_LIST(
106                   GST_PROPS_INT(16),
107                   GST_PROPS_INT(16),
108                   GST_PROPS_INT(24),
109                   GST_PROPS_INT(32)
110                 ),
111       "bpp",    GST_PROPS_LIST(
112                   GST_PROPS_INT(15),
113                   GST_PROPS_INT(16),
114                   GST_PROPS_INT(24),
115                   GST_PROPS_INT(32)
116                 )
117   ),
118   GST_CAPS_NEW (
119     "avimux_sink_video",
120     "video/jpeg",
121       "width",  GST_PROPS_INT_RANGE (16, 4096),
122       "height", GST_PROPS_INT_RANGE (16, 4096)
123   )
124 )
125     
126 GST_PADTEMPLATE_FACTORY (audio_sink_factory,
127   "audio_%02d",
128   GST_PAD_SINK,
129   GST_PAD_REQUEST,
130   GST_CAPS_NEW (
131     "avimux_sink_audio",
132     "video/avi",
133       "format",   GST_PROPS_STRING ("strf_auds")
134   ),
135   GST_CAPS_NEW (
136     "avimux_sink_audio",
137     "audio/raw",
138       "format",           GST_PROPS_STRING ("int"),
139       "law",              GST_PROPS_INT (0),
140       "endianness",       GST_PROPS_INT (G_BYTE_ORDER),
141       "signed",           GST_PROPS_LIST (
142                             GST_PROPS_BOOLEAN (TRUE),
143                             GST_PROPS_BOOLEAN (FALSE)
144                           ),
145       "width",            GST_PROPS_LIST (
146                             GST_PROPS_INT (8),
147                             GST_PROPS_INT (16)
148                           ),
149       "depth",            GST_PROPS_LIST (
150                             GST_PROPS_INT (8),
151                             GST_PROPS_INT (16)
152                           ),
153       "rate",             GST_PROPS_INT_RANGE (11025, 44100),
154       "channels",         GST_PROPS_INT_RANGE (1, 2)
155   ),
156   GST_CAPS_NEW (
157     "avimux_sink_audio",
158     "audio/mp3",
159       NULL
160   )
161 )
162     
163
164 static void     gst_avimux_class_init                (GstAviMuxClass *klass);
165 static void     gst_avimux_init                      (GstAviMux      *avimux);
166
167 static void     gst_avimux_chain                     (GstPad         *pad,
168                                                       GstBuffer      *buf);
169 static gboolean gst_avimux_handle_event              (GstPad         *pad,
170                                                       GstEvent       *event);
171 static GstPad*  gst_avimux_request_new_pad           (GstElement     *element,
172                                                       GstPadTemplate *templ,
173                                                       const gchar    *name);
174 static void     gst_avimux_set_property              (GObject        *object,
175                                                       guint           prop_id,
176                                                       const GValue   *value,
177                                                       GParamSpec     *pspec);
178 static void     gst_avimux_get_property              (GObject        *object,
179                                                       guint           prop_id,
180                                                       GValue         *value,
181                                                       GParamSpec     *pspec);
182 static GstElementStateReturn gst_avimux_change_state (GstElement     *element);
183
184 static GstElementClass *parent_class = NULL;
185 /*static guint gst_avimux_signals[LAST_SIGNAL] = { 0 }; */
186
187 GType
188 gst_avimux_get_type (void) 
189 {
190   static GType avimux_type = 0;
191
192   if (!avimux_type) {
193     static const GTypeInfo avimux_info = {
194       sizeof(GstAviMuxClass),      
195       NULL,
196       NULL,
197       (GClassInitFunc)gst_avimux_class_init,
198       NULL,
199       NULL,
200       sizeof(GstAviMux),
201       0,
202       (GInstanceInitFunc)gst_avimux_init,
203     };
204     avimux_type = g_type_register_static(GST_TYPE_ELEMENT, "GstAviMux", &avimux_info, 0);
205   }
206   return avimux_type;
207 }
208
209 static void
210 gst_avimux_class_init (GstAviMuxClass *klass) 
211 {
212   GObjectClass *gobject_class;
213   GstElementClass *gstelement_class;
214
215   gobject_class = (GObjectClass*)klass;
216   gstelement_class = (GstElementClass*)klass;
217
218   parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
219
220   g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_BIGFILE,
221     g_param_spec_boolean("bigfile","Bigfile Support","Whether to capture large or small AVI files",
222     0,G_PARAM_READWRITE));
223
224   g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_FRAMERATE,
225     g_param_spec_double("framerate","Framerate","Frames/sec",
226     G_MINDOUBLE,G_MAXDOUBLE,0,G_PARAM_READWRITE));
227
228   gstelement_class->request_new_pad = gst_avimux_request_new_pad;
229
230   gstelement_class->change_state = gst_avimux_change_state;
231
232   gstelement_class->get_property = gst_avimux_get_property;
233   gstelement_class->set_property = gst_avimux_set_property;
234 }
235
236 static void 
237 gst_avimux_init (GstAviMux *avimux) 
238 {
239   gint i;
240   avimux->srcpad = gst_pad_new_from_template (
241                   GST_PADTEMPLATE_GET (src_factory), "src");
242   gst_element_add_pad (GST_ELEMENT (avimux), avimux->srcpad);
243
244   GST_FLAG_SET (GST_ELEMENT(avimux), GST_ELEMENT_EVENT_AWARE);
245   gst_pad_set_event_function(avimux->srcpad, gst_avimux_handle_event);
246
247   for (i=0;i<MAX_NUM_AUDIO_PADS;i++)
248     avimux->audiosinkpad[i] = NULL;
249   avimux->num_audio_pads = 0;
250   for (i=0;i<MAX_NUM_VIDEO_PADS;i++)
251     avimux->videosinkpad[i] = NULL;
252   avimux->num_video_pads = 0;
253
254   avimux->num_frames = 0;
255
256   /* audio/video/AVI header initialisation */
257   memset(&(avimux->avi_hdr),0,sizeof(gst_riff_avih));
258   memset(&(avimux->vids_hdr),0,sizeof(gst_riff_strh));
259   memset(&(avimux->vids),0,sizeof(gst_riff_strf_vids));
260   memset(&(avimux->auds_hdr),0,sizeof(gst_riff_strh));
261   memset(&(avimux->auds),0,sizeof(gst_riff_strf_auds));
262   avimux->vids_hdr.type = GST_MAKE_FOURCC('v','i','d','s');
263   avimux->vids_hdr.rate = 1000000;
264   avimux->auds_hdr.type = GST_MAKE_FOURCC('a','u','d','s');
265
266   avimux->idx = NULL;
267
268   avimux->write_header = TRUE;
269
270   avimux->enable_large_avi = TRUE;
271
272   avimux->framerate = 25.;
273 }
274
275 static GstPadConnectReturn
276 gst_avimux_sinkconnect (GstPad *pad, GstCaps *vscaps)
277 {
278   GstAviMux *avimux;
279   GstCaps *caps;
280
281   avimux = GST_AVIMUX (gst_pad_get_parent (pad));
282
283   /* we are not going to act on variable caps */
284   if (!GST_CAPS_IS_FIXED (vscaps))
285     return GST_PAD_CONNECT_DELAYED;
286
287   GST_DEBUG (0, "avimux: sinkconnect triggered on %s\n", gst_pad_get_name (pad));
288
289   for (caps = vscaps; caps != NULL; caps = vscaps = vscaps->next)
290   {
291     const gchar* mimetype = gst_caps_get_mime(caps);
292
293     if (!strcmp (mimetype, "video/avi"))
294     {
295       const gchar* format = gst_caps_get_string(caps, "format");
296
297       if (!strncmp (format, "strf_vids", 9)) {
298         avimux->vids.size        = sizeof(gst_riff_strf_vids);
299         avimux->vids.width       = gst_caps_get_int (caps, "width");
300         avimux->vids.height      = gst_caps_get_int (caps, "height");
301         avimux->vids.planes      = gst_caps_get_int (caps, "planes");
302         avimux->vids.bit_cnt     = gst_caps_get_int (caps, "bit_cnt");
303         avimux->vids.compression = gst_caps_get_fourcc_int (caps, "compression");
304         avimux->vids.image_size  = gst_caps_get_int (caps, "image_size");
305         avimux->vids.xpels_meter = gst_caps_get_int (caps, "xpels_meter");
306         avimux->vids.ypels_meter = gst_caps_get_int (caps, "ypels_meter");
307         avimux->vids.num_colors  = gst_caps_get_int (caps, "num_colors");
308         avimux->vids.imp_colors  = gst_caps_get_int (caps, "imp_colors");
309       }
310       else if (!strncmp (format, "strf_auds", 9)) {
311         avimux->auds.format      = gst_caps_get_int (caps, "format");
312         avimux->auds.channels    = gst_caps_get_int (caps, "channels");
313         avimux->auds.rate        = gst_caps_get_int (caps, "rate");
314         avimux->auds.av_bps      = gst_caps_get_int (caps, "av_bps");
315         avimux->auds.blockalign  = gst_caps_get_int (caps, "blockalign");
316         avimux->auds.size        = gst_caps_get_int (caps, "size");
317       }
318       goto done;
319     }
320     else if (!strcmp (mimetype, "video/raw"))
321     {
322       switch (gst_caps_get_fourcc_int(caps, "format"))
323       {
324         case GST_MAKE_FOURCC('Y','U','Y','2'):
325         case GST_MAKE_FOURCC('I','4','2','0'):
326         case GST_MAKE_FOURCC('Y','4','1','P'):
327         case GST_MAKE_FOURCC('R','G','B',' '):
328           avimux->vids.size        = sizeof(gst_riff_strf_vids);
329           avimux->vids.width       = gst_caps_get_int (caps, "width");
330           avimux->vids.height      = gst_caps_get_int (caps, "height");
331           avimux->vids.planes      = 1;
332           switch (gst_caps_get_fourcc_int(caps, "format"))
333           {
334             case GST_MAKE_FOURCC('Y','U','Y','2'):
335               avimux->vids.bit_cnt     = 16; /* YUY2 */
336               break;
337             case GST_MAKE_FOURCC('R','G','B',' '):
338               avimux->vids.bit_cnt     = gst_caps_get_fourcc_int(caps, "bpp"); /* RGB */
339               break;
340             case GST_MAKE_FOURCC('Y','4','1','P'):
341             case GST_MAKE_FOURCC('I','4','2','0'):
342               avimux->vids.bit_cnt     = 12; /* Y41P or I420 */
343               break;
344           }
345           avimux->vids.compression = gst_caps_get_fourcc_int(caps, "format");
346           avimux->vids.image_size  = avimux->vids.height * avimux->vids.width;
347           goto done;
348         default:
349           break;
350       }
351     }
352     else if (!strcmp (mimetype, "video/jpeg"))
353     {
354       avimux->vids.size        = sizeof(gst_riff_strf_vids);
355       avimux->vids.width       = gst_caps_get_int (caps, "width");
356       avimux->vids.height      = gst_caps_get_int (caps, "height");
357       avimux->vids.planes      = 1;
358       avimux->vids.bit_cnt     = 24;
359       avimux->vids.compression = GST_MAKE_FOURCC('M','J','P','G');
360       avimux->vids.image_size  = avimux->vids.height * avimux->vids.width;
361       goto done;
362     }
363     else if (!strcmp (mimetype, "audio/raw"))
364     {
365 printf("WE HAVE AUDIO\n");
366       avimux->auds.format      = GST_RIFF_WAVE_FORMAT_PCM;
367       avimux->auds.channels    = gst_caps_get_int (caps, "channels");
368       avimux->auds.rate        = gst_caps_get_int (caps, "rate");
369       avimux->auds.av_bps      = gst_caps_get_int (caps, "width") * avimux->auds.rate *
370                                                avimux->auds.channels / 8;
371       avimux->auds.blockalign  = gst_caps_get_int (caps, "width") * avimux->auds.channels/8;
372       avimux->auds.size        = gst_caps_get_int (caps, "depth");
373       goto done;
374     }
375     else if (!strcmp (mimetype, "audio/mp3"))
376     {
377       /* we don't need to do anything here, compressed mp3 contains it all */
378       avimux->auds.format      = gst_caps_get_int(caps, "layer")==3?
379                                    GST_RIFF_WAVE_FORMAT_MPEGL3:GST_RIFF_WAVE_FORMAT_MPEGL12;
380       goto done;
381     }
382   }
383   return GST_PAD_CONNECT_REFUSED;
384
385 done:
386   return GST_PAD_CONNECT_OK;
387 }
388
389 static GstPad*
390 gst_avimux_request_new_pad (GstElement     *element,
391                             GstPadTemplate *templ,
392                             const gchar    *req_name)
393 {
394   GstAviMux *avimux;
395   gchar *name = NULL;
396   GstPad *newpad;
397   
398   g_return_val_if_fail (templ != NULL, NULL);
399
400   if (templ->direction != GST_PAD_SINK) {
401     g_warning ("avimux: request pad that is not a SINK pad\n");
402     return NULL;
403   }
404
405   g_return_val_if_fail (GST_IS_AVIMUX (element), NULL);
406
407   avimux = GST_AVIMUX (element);
408
409   if (templ == GST_PADTEMPLATE_GET (audio_sink_factory)) {
410 printf("AUDIOPAD REQUESTED\n");
411     g_return_val_if_fail(avimux->num_audio_pads == 0 /*< MAX_NUM_AUDIO_PADS*/, NULL);
412     name = g_strdup_printf ("audio_%02d", avimux->num_audio_pads);
413     newpad = gst_pad_new_from_template (templ, name);
414     gst_pad_set_element_private (newpad, GINT_TO_POINTER (avimux->num_audio_pads));
415
416     avimux->audiosinkpad[avimux->num_audio_pads] = newpad;
417     avimux->num_audio_pads++;
418   }
419   else if (templ == GST_PADTEMPLATE_GET (video_sink_factory)) {
420 printf("VIDEOPAD %d REQUESTED\n", avimux->num_video_pads);
421     g_return_val_if_fail(avimux->num_video_pads == 0 /*< MAX_NUM_VIDEO_PADS*/, NULL);
422     name = g_strdup_printf ("video_%02d", avimux->num_video_pads);
423     newpad = gst_pad_new_from_template (templ, name);
424     gst_pad_set_element_private (newpad, GINT_TO_POINTER (avimux->num_video_pads));
425
426     avimux->videosinkpad[avimux->num_video_pads] = newpad;
427     avimux->num_video_pads++;
428   }
429   else {
430     g_warning ("avimux: this is not our template!\n");
431     return NULL;
432   }
433
434   gst_pad_set_chain_function (newpad, gst_avimux_chain);
435   gst_pad_set_connect_function (newpad, gst_avimux_sinkconnect);
436   gst_element_add_pad (element, newpad);
437   
438   return newpad;
439 }
440
441 /* maybe some of these functions should be moved to riff.h? */
442
443 /* DISCLAIMER: this function is ugly. So be it (i.e. it makes the rest easier) */
444
445 static GstBuffer *
446 gst_avimux_riff_get_avi_header (GstAviMux *avimux)
447 {
448   GstBuffer *buffer;
449   guint8 *buffdata;
450   guint16 temp16;
451   guint32 temp32;
452
453   buffer = gst_buffer_new();
454
455   /* first, let's see what actually needs to be in the buffer */
456   GST_BUFFER_SIZE(buffer) = 0;
457   GST_BUFFER_SIZE(buffer) += 32 + sizeof(gst_riff_avih); /* avi header */
458   if (avimux->num_video_pads)
459   { /* we have video */
460     GST_BUFFER_SIZE(buffer) += 28 + sizeof(gst_riff_strh) + sizeof(gst_riff_strf_vids); /* vid hdr */
461     GST_BUFFER_SIZE(buffer) += 24; /* odml header */
462   }
463   if (avimux->num_audio_pads)
464   { /* we have audio */
465     GST_BUFFER_SIZE(buffer) += 28 + sizeof(gst_riff_strh) + sizeof(gst_riff_strf_auds); /* aud hdr */
466   }
467   /* this is the "riff size" */
468   avimux->header_size = GST_BUFFER_SIZE(buffer);
469   GST_BUFFER_SIZE(buffer) += 12; /* avi data header */
470
471   /* allocate the buffer */
472   buffdata = GST_BUFFER_DATA(buffer) = g_malloc(GST_BUFFER_SIZE(buffer));
473
474   /* avi header metadata */
475   memcpy(buffdata, "RIFF", 4); buffdata += 4;
476   temp32 = LE_FROM_GUINT32(avimux->header_size + avimux->idx_size + avimux->data_size);
477   memcpy(buffdata, &temp32, 4); buffdata += 4;
478   memcpy(buffdata, "AVI ", 4); buffdata += 4;
479   memcpy(buffdata, "LIST", 4); buffdata += 4;
480   temp32 = LE_FROM_GUINT32(avimux->header_size - 4*5);
481   memcpy(buffdata, &temp32, 4); buffdata += 4;
482   memcpy(buffdata, "hdrl", 4); buffdata += 4;
483   memcpy(buffdata, "avih", 4); buffdata += 4;
484   temp32 = LE_FROM_GUINT32(sizeof(gst_riff_avih));
485   memcpy(buffdata, &temp32, 4); buffdata += 4;
486   /* the AVI header itself */
487   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.us_frame);
488   memcpy(buffdata, &temp32, 4); buffdata += 4;
489   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.max_bps);
490   memcpy(buffdata, &temp32, 4); buffdata += 4;
491   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.pad_gran);
492   memcpy(buffdata, &temp32, 4); buffdata += 4;
493   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.flags);
494   memcpy(buffdata, &temp32, 4); buffdata += 4;
495   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.tot_frames);
496   memcpy(buffdata, &temp32, 4); buffdata += 4;
497   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.init_frames);
498   memcpy(buffdata, &temp32, 4); buffdata += 4;
499   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.streams);
500   memcpy(buffdata, &temp32, 4); buffdata += 4;
501   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.bufsize);
502   memcpy(buffdata, &temp32, 4); buffdata += 4;
503   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.width);
504   memcpy(buffdata, &temp32, 4); buffdata += 4;
505   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.height);
506   memcpy(buffdata, &temp32, 4); buffdata += 4;
507   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.scale);
508   memcpy(buffdata, &temp32, 4); buffdata += 4;
509   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.rate);
510   memcpy(buffdata, &temp32, 4); buffdata += 4;
511   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.start);
512   memcpy(buffdata, &temp32, 4); buffdata += 4;
513   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.length);
514   memcpy(buffdata, &temp32, 4); buffdata += 4;
515
516   if (avimux->num_video_pads)
517   {
518     /* video header metadata */
519     memcpy(buffdata, "LIST", 4); buffdata += 4;
520     temp32 = LE_FROM_GUINT32(sizeof(gst_riff_strh) + sizeof(gst_riff_strf_vids) + 4*5);
521     memcpy(buffdata, &temp32, 4); buffdata += 4;
522     memcpy(buffdata, "strl", 4); buffdata += 4;
523     /* generic header */
524     memcpy(buffdata, "strh", 4); buffdata += 4;
525     temp32 = LE_FROM_GUINT32(sizeof(gst_riff_strh));
526     memcpy(buffdata, &temp32, 4); buffdata += 4;
527     /* the actual header */
528     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.type);
529     memcpy(buffdata, &temp32, 4); buffdata += 4;
530     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.fcc_handler);
531     memcpy(buffdata, &temp32, 4); buffdata += 4;
532     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.flags);
533     memcpy(buffdata, &temp32, 4); buffdata += 4;
534     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.priority);
535     memcpy(buffdata, &temp32, 4); buffdata += 4;
536     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.init_frames);
537     memcpy(buffdata, &temp32, 4); buffdata += 4;
538     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.scale);
539     memcpy(buffdata, &temp32, 4); buffdata += 4;
540     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.rate);
541     memcpy(buffdata, &temp32, 4); buffdata += 4;
542     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.start);
543     memcpy(buffdata, &temp32, 4); buffdata += 4;
544     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.length);
545     memcpy(buffdata, &temp32, 4); buffdata += 4;
546     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.bufsize);
547     memcpy(buffdata, &temp32, 4); buffdata += 4;
548     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.quality);
549     memcpy(buffdata, &temp32, 4); buffdata += 4;
550     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.samplesize);
551     memcpy(buffdata, &temp32, 4); buffdata += 4;
552     /* the video header */
553     memcpy(buffdata, "strf", 4); buffdata += 4;
554     temp32 = LE_FROM_GUINT32(sizeof(gst_riff_strf_vids));
555     memcpy(buffdata, &temp32, 4); buffdata += 4;
556     /* the actual header */
557     temp32 = LE_FROM_GUINT32(avimux->vids.size);
558     memcpy(buffdata, &temp32, 4); buffdata += 4;
559     temp32 = LE_FROM_GUINT32(avimux->vids.width);
560     memcpy(buffdata, &temp32, 4); buffdata += 4;
561     temp32 = LE_FROM_GUINT32(avimux->vids.height);
562     memcpy(buffdata, &temp32, 4); buffdata += 4;
563     temp16 = LE_FROM_GUINT16(avimux->vids.planes);
564     memcpy(buffdata, &temp16, 2); buffdata += 2;
565     temp16 = LE_FROM_GUINT16(avimux->vids.bit_cnt);
566     memcpy(buffdata, &temp16, 2); buffdata += 2;
567     temp32 = LE_FROM_GUINT32(avimux->vids.compression);
568     memcpy(buffdata, &temp32, 4); buffdata += 4;
569     temp32 = LE_FROM_GUINT32(avimux->vids.image_size);
570     memcpy(buffdata, &temp32, 4); buffdata += 4;
571     temp32 = LE_FROM_GUINT32(avimux->vids.xpels_meter);
572     memcpy(buffdata, &temp32, 4); buffdata += 4;
573     temp32 = LE_FROM_GUINT32(avimux->vids.ypels_meter);
574     memcpy(buffdata, &temp32, 4); buffdata += 4;
575     temp32 = LE_FROM_GUINT32(avimux->vids.num_colors);
576     memcpy(buffdata, &temp32, 4); buffdata += 4;
577     temp32 = LE_FROM_GUINT32(avimux->vids.imp_colors);
578     memcpy(buffdata, &temp32, 4); buffdata += 4;
579   }
580
581   if (avimux->num_audio_pads)
582   {
583     /* audio header */
584     memcpy(buffdata, "LIST", 4); buffdata += 4;
585     temp32 = LE_FROM_GUINT32(sizeof(gst_riff_strh) + sizeof(gst_riff_strf_auds) + 4*5);
586     memcpy(buffdata, &temp32, 4); buffdata += 4;
587     memcpy(buffdata, "strl", 4); buffdata += 4;
588     /* generic header */
589     memcpy(buffdata, "strh", 4); buffdata += 4;
590     temp32 = LE_FROM_GUINT32(sizeof(gst_riff_strh));
591     memcpy(buffdata, &temp32, 4); buffdata += 4;
592     /* the actual header */
593     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.type);
594     memcpy(buffdata, &temp32, 4); buffdata += 4;
595     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.fcc_handler);
596     memcpy(buffdata, &temp32, 4); buffdata += 4;
597     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.flags);
598     memcpy(buffdata, &temp32, 4); buffdata += 4;
599     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.priority);
600     memcpy(buffdata, &temp32, 4); buffdata += 4;
601     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.init_frames);
602     memcpy(buffdata, &temp32, 4); buffdata += 4;
603     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.scale);
604     memcpy(buffdata, &temp32, 4); buffdata += 4;
605     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.rate);
606     memcpy(buffdata, &temp32, 4); buffdata += 4;
607     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.start);
608     memcpy(buffdata, &temp32, 4); buffdata += 4;
609     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.length);
610     memcpy(buffdata, &temp32, 4); buffdata += 4;
611     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.bufsize);
612     memcpy(buffdata, &temp32, 4); buffdata += 4;
613     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.quality);
614     memcpy(buffdata, &temp32, 4); buffdata += 4;
615     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.samplesize);
616     memcpy(buffdata, &temp32, 4); buffdata += 4;
617     /* the audio header */
618     memcpy(buffdata, "strf", 4); buffdata += 4;
619     temp32 = LE_FROM_GUINT32(sizeof(gst_riff_strf_vids));
620     memcpy(buffdata, &temp32, 4); buffdata += 4;
621     /* the actual header */
622     temp16 = LE_FROM_GUINT16(avimux->auds.format);
623     memcpy(buffdata, &temp16, 2); buffdata += 2;
624     temp16 = LE_FROM_GUINT16(avimux->auds.channels);
625     memcpy(buffdata, &temp16, 2); buffdata += 2;
626     temp32 = LE_FROM_GUINT32(avimux->auds.rate);
627     memcpy(buffdata, &temp32, 4); buffdata += 4;
628     temp32 = LE_FROM_GUINT32(avimux->auds.av_bps);
629     memcpy(buffdata, &temp32, 4); buffdata += 4;
630     temp16 = LE_FROM_GUINT16(avimux->auds.blockalign);
631     memcpy(buffdata, &temp16, 2); buffdata += 2;
632     temp16 = LE_FROM_GUINT16(avimux->auds.size);
633     memcpy(buffdata, &temp16, 2); buffdata += 2;
634   }
635
636   if (avimux->num_video_pads)
637   {
638     /* odml header */
639     memcpy(buffdata, "LIST", 4); buffdata += 4;
640     temp32 = LE_FROM_GUINT32(sizeof(guint32)+4*3);
641     memcpy(buffdata, &temp32, 4); buffdata += 4;
642     memcpy(buffdata, "odml", 4); buffdata += 4;
643     memcpy(buffdata, "dmlh", 4); buffdata += 4;
644     temp32 = LE_FROM_GUINT32(sizeof(guint32));
645     memcpy(buffdata, &temp32, 4); buffdata += 4;
646     temp32 = LE_FROM_GUINT32(avimux->total_frames);
647     memcpy(buffdata, &temp32, 4); buffdata += 4;
648   }
649
650   /* avi data header */
651   memcpy(buffdata, "LIST", 4); buffdata += 4;
652   temp32 = LE_FROM_GUINT32(avimux->data_size);
653   memcpy(buffdata, &temp32, 4); buffdata += 4;
654   memcpy(buffdata, "movi", 4);
655
656   return buffer;
657 }
658
659 static GstBuffer *
660 gst_avimux_riff_get_avix_header (guint32 datax_size)
661 {
662   GstBuffer *buffer;
663   guint8 *buffdata;
664   guint32 temp32;
665
666   buffer = gst_buffer_new();
667   GST_BUFFER_SIZE(buffer) = 24;
668   buffdata = GST_BUFFER_DATA(buffer) = g_malloc(GST_BUFFER_SIZE(buffer));
669
670   memcpy(buffdata, "LIST", 4); buffdata += 4;
671   temp32 = LE_FROM_GUINT32(datax_size+4*4);
672   memcpy(buffdata, &temp32, 4); buffdata += 4;
673   memcpy(buffdata, "AVIX", 4); buffdata += 4;
674   memcpy(buffdata, "LIST", 4); buffdata += 4;
675   temp32 = LE_FROM_GUINT32(datax_size);
676   memcpy(buffdata, &temp32, 4); buffdata += 4;
677   memcpy(buffdata, "movi", 4);
678
679   return buffer;
680 }
681
682 static GstBuffer *
683 gst_avimux_riff_get_video_header (guint32 video_frame_size)
684 {
685   GstBuffer *buffer;
686   guint32 temp32;
687
688   buffer = gst_buffer_new();
689   GST_BUFFER_DATA(buffer) = g_malloc(8);
690   GST_BUFFER_SIZE(buffer) = 8;
691   memcpy(GST_BUFFER_DATA(buffer), "00db", 4);
692   temp32 = LE_FROM_GUINT32(video_frame_size);
693   memcpy(GST_BUFFER_DATA(buffer)+4, &temp32, 4);
694
695   return buffer;
696 }
697
698 static GstBuffer *
699 gst_avimux_riff_get_audio_header (guint32 audio_sample_size)
700 {
701   GstBuffer *buffer;
702   guint32 temp32;
703
704   buffer = gst_buffer_new();
705   GST_BUFFER_DATA(buffer) = g_malloc(8);
706   GST_BUFFER_SIZE(buffer) = 8;
707   memcpy(GST_BUFFER_DATA(buffer), "01wb", 4);
708   temp32 = LE_FROM_GUINT32(audio_sample_size);
709   memcpy(GST_BUFFER_DATA(buffer)+4, &temp32, 4);
710
711   return buffer;
712 }
713
714 /* some other usable functions (thankyou xawtv ;-) ) */
715
716 static void
717 gst_avimux_add_index (GstAviMux *avimux, guint32 fourcc, guint32 flags, guint32 size)
718 {
719   guint32 temp32;
720   
721   if (avimux->idx_index == avimux->idx_count)
722   {
723     avimux->idx_count += 256;
724     avimux->idx = realloc(avimux->idx, avimux->idx_count*sizeof(gst_riff_index_entry));
725   }
726   temp32 = LE_FROM_GUINT32(fourcc);
727   memcpy(&(avimux->idx[avimux->idx_index].id), &temp32, 4);
728   avimux->idx[avimux->idx_index].flags = LE_FROM_GUINT32(flags);
729   avimux->idx[avimux->idx_index].offset = LE_FROM_GUINT32(avimux->idx_offset-avimux->header_size-8);
730   avimux->idx[avimux->idx_index].size = LE_FROM_GUINT32(size);
731   avimux->idx_index++;
732   avimux->idx_offset += size + sizeof(gst_riff_index_entry);
733 }
734
735 static void
736 gst_avimux_write_index (GstAviMux *avimux)
737 {
738   GstBuffer *buffer;
739   guint32 temp32;
740
741   buffer = gst_buffer_new();
742   GST_BUFFER_SIZE(buffer) = 8;
743   GST_BUFFER_DATA(buffer) = g_malloc(8);
744   memcpy(GST_BUFFER_DATA(buffer), "idx1", 4);
745   temp32 = LE_FROM_GUINT32(avimux->idx_index * sizeof(gst_riff_index_entry)); 
746   memcpy(GST_BUFFER_DATA(buffer)+4, &temp32, 4);
747   gst_pad_push(avimux->srcpad, buffer);
748
749   buffer = gst_buffer_new();
750   GST_BUFFER_SIZE(buffer) = avimux->idx_index * sizeof(gst_riff_index_entry);
751   GST_BUFFER_DATA(buffer) = (unsigned char*) avimux->idx;
752   avimux->idx = NULL; /* will be free()'ed by gst_buffer_unref() */
753   avimux->total_data += GST_BUFFER_SIZE(buffer);
754   gst_pad_push(avimux->srcpad, buffer);
755
756   avimux->idx_size += avimux->idx_index * sizeof(gst_riff_index_entry) + 8;
757
758   /* update header */
759   avimux->avi_hdr.flags |= GST_RIFF_AVIH_HASINDEX;
760 }
761
762 static void
763 gst_avimux_bigfile(GstAviMux *avimux, gboolean last)
764 {
765   GstBuffer *header;
766   GstEvent *event;
767     
768   if (avimux->is_bigfile)
769   {
770     /* sarch back */
771     event = gst_event_new_seek(GST_SEEK_BYTEOFFSET_SET, avimux->avix_start, TRUE);
772     gst_pad_send_event(avimux->srcpad, event);
773
774     /* rewrite AVIX header */
775     header = gst_avimux_riff_get_avix_header(avimux->datax_size);
776     gst_pad_push(avimux->srcpad, header);
777
778     /* go back to current location */
779     event = gst_event_new_seek(GST_SEEK_BYTEOFFSET_SET, avimux->total_data, TRUE);
780     gst_pad_send_event(avimux->srcpad, event);
781   }
782   avimux->avix_start = avimux->total_data;
783
784   if (last)
785     return;
786
787   avimux->is_bigfile = TRUE;
788   avimux->numx_frames = 0;
789   avimux->datax_size = 0;
790
791   header = gst_avimux_riff_get_avix_header(0);
792   avimux->total_data += GST_BUFFER_SIZE(header);
793   gst_pad_push(avimux->srcpad, header);
794 }
795
796 /* enough header blabla now, let's go on to actually writing the headers */
797
798 static void
799 gst_avimux_start_file (GstAviMux *avimux)
800 {
801   GstBuffer *header;
802
803   avimux->total_data = 0;
804   avimux->total_frames = 0;
805   avimux->data_size = 4; /* ? */
806   avimux->datax_size = 0;
807   avimux->num_frames = 0;
808   avimux->numx_frames = 0;
809   avimux->audio_size = 0;
810
811   avimux->idx_index = 0;
812   avimux->idx_offset = avimux->header_size + 12;
813   avimux->idx_size = 0;
814   avimux->idx_count = 0;
815   avimux->idx = NULL;
816
817   /* header */
818   avimux->avi_hdr.streams = avimux->num_video_pads + avimux->num_audio_pads;
819   avimux->is_bigfile = FALSE;
820
821   header = gst_avimux_riff_get_avi_header(avimux);
822   avimux->total_data += GST_BUFFER_SIZE(header);
823   gst_pad_push(avimux->srcpad, header);
824
825   avimux->write_header = FALSE;
826   avimux->restart = FALSE;
827 }
828
829 static void
830 gst_avimux_stop_file (GstAviMux *avimux)
831 {
832   GstEvent *event;
833   GstBuffer *header;
834
835   /* if bigfile, rewrite header, else write indexes */
836   if (avimux->num_video_pads)
837   {
838     if (avimux->is_bigfile)
839     {
840       gst_avimux_bigfile(avimux, TRUE);
841       avimux->idx_size = 0;
842     }
843     else
844     {
845       gst_avimux_write_index(avimux);
846     }
847   }
848
849   /* statistics/total_frames/... */
850   avimux->avi_hdr.tot_frames = avimux->num_frames;
851   if (avimux->num_video_pads)
852     avimux->vids_hdr.length = avimux->num_frames;
853   if (avimux->num_audio_pads)
854     avimux->auds_hdr.length = avimux->audio_size/avimux->auds_hdr.scale;
855
856   /* TODO: fps calculation!! */
857   avimux->avi_hdr.us_frame = 1000000/avimux->framerate;
858   avimux->avi_hdr.max_bps = 0;
859   if (avimux->num_audio_pads)
860     avimux->avi_hdr.max_bps += avimux->auds.av_bps;
861   if (avimux->num_video_pads)
862     avimux->avi_hdr.max_bps += avimux->vids.bit_cnt/8 * avimux->framerate;
863
864   /* seek and rewrite the header */
865   header = gst_avimux_riff_get_avi_header(avimux);
866   event = gst_event_new_seek(GST_SEEK_BYTEOFFSET_SET, 0, TRUE);
867   gst_pad_send_event(avimux->srcpad, event);
868   gst_pad_push(avimux->srcpad, header);
869
870   avimux->write_header = TRUE;
871 }
872
873 static void
874 gst_avimux_restart_file (GstAviMux *avimux)
875 {
876   GstEvent *event;
877
878   gst_avimux_stop_file(avimux);
879
880   event = gst_event_new(GST_EVENT_NEW_MEDIA);
881   gst_pad_send_event(avimux->srcpad, event);
882
883   gst_avimux_start_file(avimux);
884 }
885
886 /* handle events (search) */
887 static gboolean
888 gst_avimux_handle_event (GstPad *pad, GstEvent *event)
889 {
890   GstAviMux *avimux;
891   GstEventType type;
892
893   avimux = GST_AVIMUX (gst_pad_get_parent (pad));
894   
895   type = event ? GST_EVENT_TYPE (event) : GST_EVENT_UNKNOWN;
896
897   switch (type) {
898     case GST_EVENT_NEW_MEDIA:
899       avimux->restart = TRUE;
900       break;
901     default:
902       break;
903   }
904
905   return TRUE;
906 }
907
908 static void
909 gst_avimux_chain (GstPad *pad, GstBuffer *buf)
910 {
911   GstAviMux *avimux;
912   GstBuffer *newbuf;
913   const gchar *padname = gst_pad_get_name (pad);
914
915   g_return_if_fail (pad != NULL);
916   g_return_if_fail (GST_IS_PAD (pad));
917   g_return_if_fail (buf != NULL);
918   g_return_if_fail (GST_BUFFER_DATA (buf) != NULL);
919
920   avimux = GST_AVIMUX (gst_pad_get_parent (pad));
921   
922   if (GST_IS_EVENT(buf))
923   {
924     gst_avimux_handle_event(pad, GST_EVENT(buf));
925     return;
926   }
927
928
929   if (avimux->write_header)
930     gst_avimux_start_file(avimux);
931
932   if (strncmp(padname, "audio_", 6) == 0)
933   {
934     /* write a audio header + index entry */
935     newbuf = gst_avimux_riff_get_audio_header(GST_BUFFER_SIZE(buf));
936     avimux->total_data += GST_BUFFER_SIZE(newbuf) + GST_BUFFER_SIZE(buf);
937
938     if (avimux->is_bigfile)
939     {
940       avimux->datax_size += GST_BUFFER_SIZE(newbuf) + GST_BUFFER_SIZE(buf);
941     }
942     else
943     {
944       avimux->data_size += GST_BUFFER_SIZE(newbuf) + GST_BUFFER_SIZE(buf);
945       avimux->audio_size += GST_BUFFER_SIZE(buf);
946       gst_avimux_add_index(avimux, avimux->auds.format, 0x0, GST_BUFFER_SIZE(buf));
947     }
948
949     gst_pad_push(avimux->srcpad, newbuf);
950   }
951   else if (strncmp(padname, "video_", 6) == 0)
952   {
953     if (avimux->restart)
954       gst_avimux_restart_file(avimux);
955
956     /* write a video header + index entry */
957     GST_BUFFER_SIZE(buf) = (GST_BUFFER_SIZE(buf)+3)&~3;
958
959     if ((avimux->is_bigfile?avimux->datax_size:avimux->data_size)+GST_BUFFER_SIZE(buf)>1024*1024*2000)
960     {
961       if (avimux->enable_large_avi)
962         gst_avimux_bigfile(avimux, FALSE);
963       else
964         gst_avimux_restart_file(avimux);
965     }
966
967     newbuf = gst_avimux_riff_get_video_header(GST_BUFFER_SIZE(buf));
968     avimux->total_data += GST_BUFFER_SIZE(newbuf) + GST_BUFFER_SIZE(buf);
969     avimux->total_frames++;
970
971     if (avimux->is_bigfile)
972     {
973       avimux->datax_size += GST_BUFFER_SIZE(newbuf) + GST_BUFFER_SIZE(buf);
974       avimux->numx_frames++;
975     }
976     else
977     {
978       avimux->data_size += GST_BUFFER_SIZE(newbuf) + GST_BUFFER_SIZE(buf);
979       avimux->num_frames++;
980       gst_avimux_add_index(avimux, avimux->vids.compression, 0x12, GST_BUFFER_SIZE(buf));
981     }
982
983     gst_pad_push(avimux->srcpad, newbuf);
984   }
985   else
986   {
987     g_warning("Unknown padname \'%s\'\n", padname);
988     return;
989   }
990
991   /* data */
992   gst_pad_push(avimux->srcpad, buf);
993 }
994
995 static void
996 gst_avimux_get_property (GObject    *object,
997                          guint      prop_id,
998                          GValue     *value,
999                          GParamSpec *pspec)
1000 {
1001   GstAviMux *avimux;
1002
1003   /* it's not null if we got it, but it might not be ours */
1004   g_return_if_fail(GST_IS_AVIMUX(object));
1005   avimux = GST_AVIMUX(object);
1006
1007   switch (prop_id)
1008   {
1009     case ARG_BIGFILE:
1010       g_value_set_boolean(value, avimux->enable_large_avi);
1011       break;
1012     case ARG_FRAMERATE:
1013       g_value_set_double(value, avimux->framerate);
1014       break;
1015     default:
1016       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1017       break;
1018   }
1019 }
1020
1021 static void
1022 gst_avimux_set_property (GObject      *object,
1023                          guint         prop_id,
1024                          const GValue *value,
1025                          GParamSpec   *pspec)
1026 {
1027   GstAviMux *avimux;
1028
1029   /* it's not null if we got it, but it might not be ours */
1030   g_return_if_fail(GST_IS_AVIMUX(object));
1031   avimux = GST_AVIMUX(object);
1032
1033   switch (prop_id)
1034   {
1035     case ARG_BIGFILE:
1036       avimux->enable_large_avi = g_value_get_boolean(value);
1037       break;
1038     case ARG_FRAMERATE:
1039       avimux->framerate = g_value_get_double(value);
1040       break;
1041     default:
1042       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1043       break;
1044   }
1045 }
1046
1047 static GstElementStateReturn
1048 gst_avimux_change_state (GstElement *element)
1049 {
1050   GstAviMux *avimux;
1051   gint transition = GST_STATE_TRANSITION (element);
1052
1053   /* TODO: timer (for fps calculations) */
1054
1055   g_return_val_if_fail(GST_IS_AVIMUX(element), GST_STATE_FAILURE);
1056   
1057   avimux = GST_AVIMUX(element);
1058
1059   switch (transition) {
1060     case GST_STATE_READY_TO_PAUSED:
1061       /*gst_avimux_start_file(avimux);*/
1062       break;
1063     case GST_STATE_PAUSED_TO_PLAYING:
1064       break;
1065     case GST_STATE_PLAYING_TO_PAUSED:
1066       gst_avimux_stop_file(avimux);
1067       break;
1068     case GST_STATE_PAUSED_TO_READY:
1069       /*gst_avimux_stop_file(avimux);*/
1070       break;
1071   }
1072
1073   if (GST_ELEMENT_CLASS (parent_class)->change_state)
1074     return GST_ELEMENT_CLASS (parent_class)->change_state (element);
1075
1076   return GST_STATE_SUCCESS;
1077 }
1078
1079 static gboolean
1080 plugin_init (GModule *module, GstPlugin *plugin)
1081 {
1082   GstElementFactory *factory;
1083
1084   /* this filter needs the riff parser */
1085 #if 0
1086   if (!gst_library_load ("gstriff")) {
1087     gst_info ("avimux: could not load support library: 'gstriff'\n");
1088     return FALSE;
1089   }
1090 #endif
1091
1092   /* create an elementfactory for the avimux element */
1093   factory = gst_elementfactory_new ("avimux", GST_TYPE_AVIMUX,
1094                                     &gst_avimux_details);
1095   g_return_val_if_fail (factory != NULL, FALSE);
1096
1097   gst_elementfactory_add_padtemplate (factory, GST_PADTEMPLATE_GET (src_factory));
1098   gst_elementfactory_add_padtemplate (factory, GST_PADTEMPLATE_GET (audio_sink_factory));
1099   gst_elementfactory_add_padtemplate (factory, GST_PADTEMPLATE_GET (video_sink_factory));
1100   
1101   gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
1102
1103   return TRUE;
1104 }
1105
1106 GstPluginDesc plugin_desc = {
1107   GST_VERSION_MAJOR,
1108   GST_VERSION_MINOR,
1109   "avimux",
1110   plugin_init
1111 };