fixed first bunch of compiler warnings
[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_%d",
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_%d",
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,25.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", 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;
296       
297       gst_caps_get_string (caps, "format", &format);
298
299       if (!strncmp (format, "strf_vids", 9)) {
300         avimux->vids.size        = sizeof(gst_riff_strf_vids);
301         gst_caps_get (caps,
302                       "width",       GST_PROPS_INT_TYPE,    &avimux->vids.width,
303                       "height",      GST_PROPS_INT_TYPE,    &avimux->vids.height,
304                       "planes",      GST_PROPS_INT_TYPE,    &avimux->vids.planes,
305                       "bit_cnt",     GST_PROPS_INT_TYPE,    &avimux->vids.bit_cnt,
306                       "compression", GST_PROPS_FOURCC_TYPE, &avimux->vids.compression,
307                       "image_size",  GST_PROPS_INT_TYPE,    &avimux->vids.image_size,
308                       "xpels_meter", GST_PROPS_INT_TYPE,    &avimux->vids.xpels_meter,
309                       "ypels_meter", GST_PROPS_INT_TYPE,    &avimux->vids.ypels_meter,
310                       "num_colors",  GST_PROPS_INT_TYPE,    &avimux->vids.num_colors,
311                       "imp_colors",  GST_PROPS_INT_TYPE,    &avimux->vids.imp_colors,
312                       NULL);
313       }
314       else if (!strncmp (format, "strf_auds", 9)) {
315         gst_caps_get (caps,
316                       "format",      GST_PROPS_INT_TYPE,    &avimux->auds.format,
317                       "channels",    GST_PROPS_INT_TYPE,    &avimux->auds.channels,
318                       "rate",        GST_PROPS_INT_TYPE,    &avimux->auds.rate,
319                       "av_bps",      GST_PROPS_INT_TYPE,    &avimux->auds.av_bps,
320                       "blockalign",  GST_PROPS_INT_TYPE,    &avimux->auds.blockalign,
321                       "size",        GST_PROPS_INT_TYPE,    &avimux->auds.size,
322                       NULL);
323       }
324       goto done;
325     }
326     else if (!strcmp (mimetype, "video/raw"))
327     {
328       guint32 format;
329       gint temp;
330
331       gst_caps_get_fourcc_int (caps, "format", &format);
332       switch (format)
333       {
334         case GST_MAKE_FOURCC('Y','U','Y','2'):
335         case GST_MAKE_FOURCC('I','4','2','0'):
336         case GST_MAKE_FOURCC('Y','4','1','P'):
337         case GST_MAKE_FOURCC('R','G','B',' '):
338           avimux->vids.size        = sizeof(gst_riff_strf_vids);
339           gst_caps_get (caps,
340                       "width",       GST_PROPS_INT_TYPE,    &avimux->vids.width,
341                       "height",      GST_PROPS_INT_TYPE,    &avimux->vids.height,
342                       NULL);
343           avimux->vids.planes      = 1;
344           switch (format)
345           {
346             case GST_MAKE_FOURCC('Y','U','Y','2'):
347               avimux->vids.bit_cnt     = 16; /* YUY2 */
348               break;
349             case GST_MAKE_FOURCC('R','G','B',' '):
350               gst_caps_get_int (caps, "bpp", &temp); /* RGB */
351               avimux->vids.bit_cnt = temp;
352               break;
353             case GST_MAKE_FOURCC('Y','4','1','P'):
354             case GST_MAKE_FOURCC('I','4','2','0'):
355               avimux->vids.bit_cnt     = 12; /* Y41P or I420 */
356               break;
357           }
358           gst_caps_get_fourcc_int(caps, "format", &avimux->vids.compression);
359           avimux->vids.image_size  = avimux->vids.height * avimux->vids.width;
360           goto done;
361         default:
362           break;
363       }
364     }
365     else if (!strcmp (mimetype, "video/jpeg"))
366     {
367       avimux->vids.size        = sizeof(gst_riff_strf_vids);
368       gst_caps_get (caps,
369                       "width",       GST_PROPS_INT_TYPE,    &avimux->vids.width,
370                       "height",      GST_PROPS_INT_TYPE,    &avimux->vids.height,
371                       NULL);
372       avimux->vids.planes      = 1;
373       avimux->vids.bit_cnt     = 24;
374       avimux->vids.compression = GST_MAKE_FOURCC('M','J','P','G');
375       avimux->vids.image_size  = avimux->vids.height * avimux->vids.width;
376       goto done;
377     }
378     else if (!strcmp (mimetype, "audio/raw"))
379     {
380       gint width;
381
382       avimux->auds.format      = GST_RIFF_WAVE_FORMAT_PCM;
383       gst_caps_get (caps,
384                       "channels",    GST_PROPS_INT_TYPE,    &avimux->auds.channels,
385                       "rate",        GST_PROPS_INT_TYPE,    &avimux->auds.rate,
386                       "width",       GST_PROPS_INT_TYPE,    &width,
387                       "depth",       GST_PROPS_INT_TYPE,    &avimux->auds.size,
388                       NULL);
389       avimux->auds.av_bps      = width * avimux->auds.rate * avimux->auds.channels / 8;
390       avimux->auds.blockalign  = width * avimux->auds.channels/8;
391       goto done;
392     }
393     else if (!strcmp (mimetype, "audio/mp3"))
394     {
395       gint layer;
396
397       gst_caps_get_int(caps, "layer", &layer);
398
399       /* we don't need to do anything here, compressed mp3 contains it all */
400       avimux->auds.format      = (layer == 3?
401                                    GST_RIFF_WAVE_FORMAT_MPEGL3 : 
402                                    GST_RIFF_WAVE_FORMAT_MPEGL12);
403       goto done;
404     }
405   }
406   return GST_PAD_CONNECT_REFUSED;
407
408 done:
409   return GST_PAD_CONNECT_OK;
410 }
411
412 static GstPad*
413 gst_avimux_request_new_pad (GstElement     *element,
414                             GstPadTemplate *templ,
415                             const gchar    *req_name)
416 {
417   GstAviMux *avimux;
418   gchar *name = NULL;
419   GstPad *newpad;
420
421   g_return_val_if_fail (templ != NULL, NULL);
422
423   if (templ->direction != GST_PAD_SINK) {
424     g_warning ("avimux: request pad that is not a SINK pad\n");
425     return NULL;
426   }
427
428   g_return_val_if_fail (GST_IS_AVIMUX (element), NULL);
429
430   avimux = GST_AVIMUX (element);
431
432   if (templ == GST_PADTEMPLATE_GET (audio_sink_factory)) {
433     g_return_val_if_fail(avimux->num_audio_pads == 0 /*< MAX_NUM_AUDIO_PADS*/, NULL);
434     name = g_strdup_printf ("audio_%02d", avimux->num_audio_pads);
435     newpad = gst_pad_new_from_template (templ, name);
436     gst_pad_set_element_private (newpad, GINT_TO_POINTER (avimux->num_audio_pads));
437
438     avimux->audiosinkpad[avimux->num_audio_pads] = newpad;
439     avimux->num_audio_pads++;
440   }
441   else if (templ == GST_PADTEMPLATE_GET (video_sink_factory)) {
442     g_return_val_if_fail(avimux->num_video_pads == 0 /*< MAX_NUM_VIDEO_PADS*/, NULL);
443     name = g_strdup_printf ("video_%02d", avimux->num_video_pads);
444     newpad = gst_pad_new_from_template (templ, name);
445     gst_pad_set_element_private (newpad, GINT_TO_POINTER (avimux->num_video_pads));
446
447     avimux->videosinkpad[avimux->num_video_pads] = newpad;
448     avimux->num_video_pads++;
449   }
450   else {
451     g_warning ("avimux: this is not our template!\n");
452     return NULL;
453   }
454
455   gst_pad_set_chain_function (newpad, gst_avimux_chain);
456   gst_pad_set_connect_function (newpad, gst_avimux_sinkconnect);
457   gst_element_add_pad (element, newpad);
458   
459   return newpad;
460 }
461
462 /* maybe some of these functions should be moved to riff.h? */
463
464 /* DISCLAIMER: this function is ugly. So be it (i.e. it makes the rest easier) */
465
466 static GstBuffer *
467 gst_avimux_riff_get_avi_header (GstAviMux *avimux)
468 {
469   GstBuffer *buffer;
470   guint8 *buffdata;
471   guint16 temp16;
472   guint32 temp32;
473
474   buffer = gst_buffer_new();
475
476   /* first, let's see what actually needs to be in the buffer */
477   GST_BUFFER_SIZE(buffer) = 0;
478   GST_BUFFER_SIZE(buffer) += 32 + sizeof(gst_riff_avih); /* avi header */
479   if (avimux->num_video_pads)
480   { /* we have video */
481     GST_BUFFER_SIZE(buffer) += 28 + sizeof(gst_riff_strh) + sizeof(gst_riff_strf_vids); /* vid hdr */
482     GST_BUFFER_SIZE(buffer) += 24; /* odml header */
483   }
484   if (avimux->num_audio_pads)
485   { /* we have audio */
486     GST_BUFFER_SIZE(buffer) += 28 + sizeof(gst_riff_strh) + sizeof(gst_riff_strf_auds); /* aud hdr */
487   }
488   /* this is the "riff size" */
489   avimux->header_size = GST_BUFFER_SIZE(buffer);
490   GST_BUFFER_SIZE(buffer) += 12; /* avi data header */
491
492   /* allocate the buffer */
493   buffdata = GST_BUFFER_DATA(buffer) = g_malloc(GST_BUFFER_SIZE(buffer));
494
495   /* avi header metadata */
496   memcpy(buffdata, "RIFF", 4); buffdata += 4;
497   temp32 = LE_FROM_GUINT32(avimux->header_size + avimux->idx_size + avimux->data_size);
498   memcpy(buffdata, &temp32, 4); buffdata += 4;
499   memcpy(buffdata, "AVI ", 4); buffdata += 4;
500   memcpy(buffdata, "LIST", 4); buffdata += 4;
501   temp32 = LE_FROM_GUINT32(avimux->header_size - 4*5);
502   memcpy(buffdata, &temp32, 4); buffdata += 4;
503   memcpy(buffdata, "hdrl", 4); buffdata += 4;
504   memcpy(buffdata, "avih", 4); buffdata += 4;
505   temp32 = LE_FROM_GUINT32(sizeof(gst_riff_avih));
506   memcpy(buffdata, &temp32, 4); buffdata += 4;
507   /* the AVI header itself */
508   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.us_frame);
509   memcpy(buffdata, &temp32, 4); buffdata += 4;
510   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.max_bps);
511   memcpy(buffdata, &temp32, 4); buffdata += 4;
512   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.pad_gran);
513   memcpy(buffdata, &temp32, 4); buffdata += 4;
514   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.flags);
515   memcpy(buffdata, &temp32, 4); buffdata += 4;
516   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.tot_frames);
517   memcpy(buffdata, &temp32, 4); buffdata += 4;
518   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.init_frames);
519   memcpy(buffdata, &temp32, 4); buffdata += 4;
520   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.streams);
521   memcpy(buffdata, &temp32, 4); buffdata += 4;
522   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.bufsize);
523   memcpy(buffdata, &temp32, 4); buffdata += 4;
524   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.width);
525   memcpy(buffdata, &temp32, 4); buffdata += 4;
526   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.height);
527   memcpy(buffdata, &temp32, 4); buffdata += 4;
528   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.scale);
529   memcpy(buffdata, &temp32, 4); buffdata += 4;
530   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.rate);
531   memcpy(buffdata, &temp32, 4); buffdata += 4;
532   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.start);
533   memcpy(buffdata, &temp32, 4); buffdata += 4;
534   temp32 = LE_FROM_GUINT32(avimux->avi_hdr.length);
535   memcpy(buffdata, &temp32, 4); buffdata += 4;
536
537   if (avimux->num_video_pads)
538   {
539     /* video header metadata */
540     memcpy(buffdata, "LIST", 4); buffdata += 4;
541     temp32 = LE_FROM_GUINT32(sizeof(gst_riff_strh) + sizeof(gst_riff_strf_vids) + 4*5);
542     memcpy(buffdata, &temp32, 4); buffdata += 4;
543     memcpy(buffdata, "strl", 4); buffdata += 4;
544     /* generic header */
545     memcpy(buffdata, "strh", 4); buffdata += 4;
546     temp32 = LE_FROM_GUINT32(sizeof(gst_riff_strh));
547     memcpy(buffdata, &temp32, 4); buffdata += 4;
548     /* the actual header */
549     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.type);
550     memcpy(buffdata, &temp32, 4); buffdata += 4;
551     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.fcc_handler);
552     memcpy(buffdata, &temp32, 4); buffdata += 4;
553     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.flags);
554     memcpy(buffdata, &temp32, 4); buffdata += 4;
555     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.priority);
556     memcpy(buffdata, &temp32, 4); buffdata += 4;
557     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.init_frames);
558     memcpy(buffdata, &temp32, 4); buffdata += 4;
559     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.scale);
560     memcpy(buffdata, &temp32, 4); buffdata += 4;
561     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.rate);
562     memcpy(buffdata, &temp32, 4); buffdata += 4;
563     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.start);
564     memcpy(buffdata, &temp32, 4); buffdata += 4;
565     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.length);
566     memcpy(buffdata, &temp32, 4); buffdata += 4;
567     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.bufsize);
568     memcpy(buffdata, &temp32, 4); buffdata += 4;
569     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.quality);
570     memcpy(buffdata, &temp32, 4); buffdata += 4;
571     temp32 = LE_FROM_GUINT32(avimux->vids_hdr.samplesize);
572     memcpy(buffdata, &temp32, 4); buffdata += 4;
573     /* the video header */
574     memcpy(buffdata, "strf", 4); buffdata += 4;
575     temp32 = LE_FROM_GUINT32(sizeof(gst_riff_strf_vids));
576     memcpy(buffdata, &temp32, 4); buffdata += 4;
577     /* the actual header */
578     temp32 = LE_FROM_GUINT32(avimux->vids.size);
579     memcpy(buffdata, &temp32, 4); buffdata += 4;
580     temp32 = LE_FROM_GUINT32(avimux->vids.width);
581     memcpy(buffdata, &temp32, 4); buffdata += 4;
582     temp32 = LE_FROM_GUINT32(avimux->vids.height);
583     memcpy(buffdata, &temp32, 4); buffdata += 4;
584     temp16 = LE_FROM_GUINT16(avimux->vids.planes);
585     memcpy(buffdata, &temp16, 2); buffdata += 2;
586     temp16 = LE_FROM_GUINT16(avimux->vids.bit_cnt);
587     memcpy(buffdata, &temp16, 2); buffdata += 2;
588     temp32 = LE_FROM_GUINT32(avimux->vids.compression);
589     memcpy(buffdata, &temp32, 4); buffdata += 4;
590     temp32 = LE_FROM_GUINT32(avimux->vids.image_size);
591     memcpy(buffdata, &temp32, 4); buffdata += 4;
592     temp32 = LE_FROM_GUINT32(avimux->vids.xpels_meter);
593     memcpy(buffdata, &temp32, 4); buffdata += 4;
594     temp32 = LE_FROM_GUINT32(avimux->vids.ypels_meter);
595     memcpy(buffdata, &temp32, 4); buffdata += 4;
596     temp32 = LE_FROM_GUINT32(avimux->vids.num_colors);
597     memcpy(buffdata, &temp32, 4); buffdata += 4;
598     temp32 = LE_FROM_GUINT32(avimux->vids.imp_colors);
599     memcpy(buffdata, &temp32, 4); buffdata += 4;
600   }
601
602   if (avimux->num_audio_pads)
603   {
604     /* audio header */
605     memcpy(buffdata, "LIST", 4); buffdata += 4;
606     temp32 = LE_FROM_GUINT32(sizeof(gst_riff_strh) + sizeof(gst_riff_strf_auds) + 4*5);
607     memcpy(buffdata, &temp32, 4); buffdata += 4;
608     memcpy(buffdata, "strl", 4); buffdata += 4;
609     /* generic header */
610     memcpy(buffdata, "strh", 4); buffdata += 4;
611     temp32 = LE_FROM_GUINT32(sizeof(gst_riff_strh));
612     memcpy(buffdata, &temp32, 4); buffdata += 4;
613     /* the actual header */
614     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.type);
615     memcpy(buffdata, &temp32, 4); buffdata += 4;
616     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.fcc_handler);
617     memcpy(buffdata, &temp32, 4); buffdata += 4;
618     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.flags);
619     memcpy(buffdata, &temp32, 4); buffdata += 4;
620     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.priority);
621     memcpy(buffdata, &temp32, 4); buffdata += 4;
622     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.init_frames);
623     memcpy(buffdata, &temp32, 4); buffdata += 4;
624     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.scale);
625     memcpy(buffdata, &temp32, 4); buffdata += 4;
626     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.rate);
627     memcpy(buffdata, &temp32, 4); buffdata += 4;
628     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.start);
629     memcpy(buffdata, &temp32, 4); buffdata += 4;
630     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.length);
631     memcpy(buffdata, &temp32, 4); buffdata += 4;
632     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.bufsize);
633     memcpy(buffdata, &temp32, 4); buffdata += 4;
634     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.quality);
635     memcpy(buffdata, &temp32, 4); buffdata += 4;
636     temp32 = LE_FROM_GUINT32(avimux->auds_hdr.samplesize);
637     memcpy(buffdata, &temp32, 4); buffdata += 4;
638     /* the audio header */
639     memcpy(buffdata, "strf", 4); buffdata += 4;
640     temp32 = LE_FROM_GUINT32(sizeof(gst_riff_strf_vids));
641     memcpy(buffdata, &temp32, 4); buffdata += 4;
642     /* the actual header */
643     temp16 = LE_FROM_GUINT16(avimux->auds.format);
644     memcpy(buffdata, &temp16, 2); buffdata += 2;
645     temp16 = LE_FROM_GUINT16(avimux->auds.channels);
646     memcpy(buffdata, &temp16, 2); buffdata += 2;
647     temp32 = LE_FROM_GUINT32(avimux->auds.rate);
648     memcpy(buffdata, &temp32, 4); buffdata += 4;
649     temp32 = LE_FROM_GUINT32(avimux->auds.av_bps);
650     memcpy(buffdata, &temp32, 4); buffdata += 4;
651     temp16 = LE_FROM_GUINT16(avimux->auds.blockalign);
652     memcpy(buffdata, &temp16, 2); buffdata += 2;
653     temp16 = LE_FROM_GUINT16(avimux->auds.size);
654     memcpy(buffdata, &temp16, 2); buffdata += 2;
655   }
656
657   if (avimux->num_video_pads)
658   {
659     /* odml header */
660     memcpy(buffdata, "LIST", 4); buffdata += 4;
661     temp32 = LE_FROM_GUINT32(sizeof(guint32)+4*3);
662     memcpy(buffdata, &temp32, 4); buffdata += 4;
663     memcpy(buffdata, "odml", 4); buffdata += 4;
664     memcpy(buffdata, "dmlh", 4); buffdata += 4;
665     temp32 = LE_FROM_GUINT32(sizeof(guint32));
666     memcpy(buffdata, &temp32, 4); buffdata += 4;
667     temp32 = LE_FROM_GUINT32(avimux->total_frames);
668     memcpy(buffdata, &temp32, 4); buffdata += 4;
669   }
670
671   /* avi data header */
672   memcpy(buffdata, "LIST", 4); buffdata += 4;
673   temp32 = LE_FROM_GUINT32(avimux->data_size);
674   memcpy(buffdata, &temp32, 4); buffdata += 4;
675   memcpy(buffdata, "movi", 4);
676
677   return buffer;
678 }
679
680 static GstBuffer *
681 gst_avimux_riff_get_avix_header (guint32 datax_size)
682 {
683   GstBuffer *buffer;
684   guint8 *buffdata;
685   guint32 temp32;
686
687   buffer = gst_buffer_new();
688   GST_BUFFER_SIZE(buffer) = 24;
689   buffdata = GST_BUFFER_DATA(buffer) = g_malloc(GST_BUFFER_SIZE(buffer));
690
691   memcpy(buffdata, "LIST", 4); buffdata += 4;
692   temp32 = LE_FROM_GUINT32(datax_size+4*4);
693   memcpy(buffdata, &temp32, 4); buffdata += 4;
694   memcpy(buffdata, "AVIX", 4); buffdata += 4;
695   memcpy(buffdata, "LIST", 4); buffdata += 4;
696   temp32 = LE_FROM_GUINT32(datax_size);
697   memcpy(buffdata, &temp32, 4); buffdata += 4;
698   memcpy(buffdata, "movi", 4);
699
700   return buffer;
701 }
702
703 static GstBuffer *
704 gst_avimux_riff_get_video_header (guint32 video_frame_size)
705 {
706   GstBuffer *buffer;
707   guint32 temp32;
708
709   buffer = gst_buffer_new();
710   GST_BUFFER_DATA(buffer) = g_malloc(8);
711   GST_BUFFER_SIZE(buffer) = 8;
712   memcpy(GST_BUFFER_DATA(buffer), "00db", 4);
713   temp32 = LE_FROM_GUINT32(video_frame_size);
714   memcpy(GST_BUFFER_DATA(buffer)+4, &temp32, 4);
715
716   return buffer;
717 }
718
719 static GstBuffer *
720 gst_avimux_riff_get_audio_header (guint32 audio_sample_size)
721 {
722   GstBuffer *buffer;
723   guint32 temp32;
724
725   buffer = gst_buffer_new();
726   GST_BUFFER_DATA(buffer) = g_malloc(8);
727   GST_BUFFER_SIZE(buffer) = 8;
728   memcpy(GST_BUFFER_DATA(buffer), "01wb", 4);
729   temp32 = LE_FROM_GUINT32(audio_sample_size);
730   memcpy(GST_BUFFER_DATA(buffer)+4, &temp32, 4);
731
732   return buffer;
733 }
734
735 /* some other usable functions (thankyou xawtv ;-) ) */
736
737 static void
738 gst_avimux_add_index (GstAviMux *avimux, guint32 fourcc, guint32 flags, guint32 size)
739 {
740   guint32 temp32;
741   
742   if (avimux->idx_index == avimux->idx_count)
743   {
744     avimux->idx_count += 256;
745     avimux->idx = realloc(avimux->idx, avimux->idx_count*sizeof(gst_riff_index_entry));
746   }
747   temp32 = LE_FROM_GUINT32(fourcc);
748   memcpy(&(avimux->idx[avimux->idx_index].id), &temp32, 4);
749   avimux->idx[avimux->idx_index].flags = LE_FROM_GUINT32(flags);
750   avimux->idx[avimux->idx_index].offset = LE_FROM_GUINT32(avimux->idx_offset-avimux->header_size-8);
751   avimux->idx[avimux->idx_index].size = LE_FROM_GUINT32(size);
752   avimux->idx_index++;
753   avimux->idx_offset += size + sizeof(gst_riff_index_entry);
754 }
755
756 static void
757 gst_avimux_write_index (GstAviMux *avimux)
758 {
759   GstBuffer *buffer;
760   guint32 temp32;
761
762   buffer = gst_buffer_new();
763   GST_BUFFER_SIZE(buffer) = 8;
764   GST_BUFFER_DATA(buffer) = g_malloc(8);
765   memcpy(GST_BUFFER_DATA(buffer), "idx1", 4);
766   temp32 = LE_FROM_GUINT32(avimux->idx_index * sizeof(gst_riff_index_entry)); 
767   memcpy(GST_BUFFER_DATA(buffer)+4, &temp32, 4);
768   gst_pad_push(avimux->srcpad, buffer);
769
770   buffer = gst_buffer_new();
771   GST_BUFFER_SIZE(buffer) = avimux->idx_index * sizeof(gst_riff_index_entry);
772   GST_BUFFER_DATA(buffer) = (unsigned char*) avimux->idx;
773   avimux->idx = NULL; /* will be free()'ed by gst_buffer_unref() */
774   avimux->total_data += GST_BUFFER_SIZE(buffer);
775   gst_pad_push(avimux->srcpad, buffer);
776
777   avimux->idx_size += avimux->idx_index * sizeof(gst_riff_index_entry) + 8;
778
779   /* update header */
780   avimux->avi_hdr.flags |= GST_RIFF_AVIH_HASINDEX;
781 }
782
783 static void
784 gst_avimux_bigfile(GstAviMux *avimux, gboolean last)
785 {
786   GstBuffer *header;
787   GstEvent *event;
788     
789   if (avimux->is_bigfile)
790   {
791     /* sarch back */
792     event = gst_event_new_seek(GST_SEEK_BYTEOFFSET_SET, avimux->avix_start, TRUE);
793     gst_pad_send_event(avimux->srcpad, event);
794
795     /* rewrite AVIX header */
796     header = gst_avimux_riff_get_avix_header(avimux->datax_size);
797     gst_pad_push(avimux->srcpad, header);
798
799     /* go back to current location */
800     event = gst_event_new_seek(GST_SEEK_BYTEOFFSET_SET, avimux->total_data, TRUE);
801     gst_pad_send_event(avimux->srcpad, event);
802   }
803   avimux->avix_start = avimux->total_data;
804
805   if (last)
806     return;
807
808   avimux->is_bigfile = TRUE;
809   avimux->numx_frames = 0;
810   avimux->datax_size = 0;
811
812   header = gst_avimux_riff_get_avix_header(0);
813   avimux->total_data += GST_BUFFER_SIZE(header);
814   gst_pad_push(avimux->srcpad, header);
815 }
816
817 /* enough header blabla now, let's go on to actually writing the headers */
818
819 static void
820 gst_avimux_start_file (GstAviMux *avimux)
821 {
822   GstBuffer *header;
823
824   avimux->total_data = 0;
825   avimux->total_frames = 0;
826   avimux->data_size = 4; /* ? */
827   avimux->datax_size = 0;
828   avimux->num_frames = 0;
829   avimux->numx_frames = 0;
830   avimux->audio_size = 0;
831
832   avimux->idx_index = 0;
833   avimux->idx_offset = avimux->header_size + 12;
834   avimux->idx_size = 0;
835   avimux->idx_count = 0;
836   avimux->idx = NULL;
837
838   /* header */
839   avimux->avi_hdr.streams = avimux->num_video_pads + avimux->num_audio_pads;
840   avimux->is_bigfile = FALSE;
841
842   header = gst_avimux_riff_get_avi_header(avimux);
843   avimux->total_data += GST_BUFFER_SIZE(header);
844   gst_pad_push(avimux->srcpad, header);
845
846   avimux->write_header = FALSE;
847   avimux->restart = FALSE;
848 }
849
850 static void
851 gst_avimux_stop_file (GstAviMux *avimux)
852 {
853   GstEvent *event;
854   GstBuffer *header;
855
856   /* if bigfile, rewrite header, else write indexes */
857   if (avimux->num_video_pads)
858   {
859     if (avimux->is_bigfile)
860     {
861       gst_avimux_bigfile(avimux, TRUE);
862       avimux->idx_size = 0;
863     }
864     else
865     {
866       gst_avimux_write_index(avimux);
867     }
868   }
869
870   /* statistics/total_frames/... */
871   avimux->avi_hdr.tot_frames = avimux->num_frames;
872   if (avimux->num_video_pads)
873     avimux->vids_hdr.length = avimux->num_frames;
874   if (avimux->num_audio_pads)
875     avimux->auds_hdr.length = avimux->audio_size/avimux->auds_hdr.scale;
876
877   /* TODO: fps calculation!! */
878   avimux->avi_hdr.us_frame = 1000000/avimux->framerate;
879   avimux->avi_hdr.max_bps = 0;
880   if (avimux->num_audio_pads)
881     avimux->avi_hdr.max_bps += avimux->auds.av_bps;
882   if (avimux->num_video_pads)
883     avimux->avi_hdr.max_bps += avimux->vids.bit_cnt/8 * avimux->framerate;
884
885   /* seek and rewrite the header */
886   header = gst_avimux_riff_get_avi_header(avimux);
887   event = gst_event_new_seek(GST_SEEK_BYTEOFFSET_SET, 0, TRUE);
888   gst_pad_send_event(avimux->srcpad, event);
889   gst_pad_push(avimux->srcpad, header);
890
891   avimux->write_header = TRUE;
892 }
893
894 static void
895 gst_avimux_restart_file (GstAviMux *avimux)
896 {
897   GstEvent *event;
898
899   gst_avimux_stop_file(avimux);
900
901   event = gst_event_new(GST_EVENT_NEW_MEDIA);
902   gst_pad_send_event(avimux->srcpad, event);
903
904   gst_avimux_start_file(avimux);
905 }
906
907 /* handle events (search) */
908 static gboolean
909 gst_avimux_handle_event (GstPad *pad, GstEvent *event)
910 {
911   GstAviMux *avimux;
912   GstEventType type;
913
914   avimux = GST_AVIMUX (gst_pad_get_parent (pad));
915   
916   type = event ? GST_EVENT_TYPE (event) : GST_EVENT_UNKNOWN;
917
918   switch (type) {
919     case GST_EVENT_NEW_MEDIA:
920       avimux->restart = TRUE;
921       break;
922     default:
923       break;
924   }
925
926   return TRUE;
927 }
928
929 static void
930 gst_avimux_chain (GstPad *pad, GstBuffer *buf)
931 {
932   GstAviMux *avimux;
933   GstBuffer *newbuf;
934   const gchar *padname = gst_pad_get_name (pad);
935
936   g_return_if_fail (pad != NULL);
937   g_return_if_fail (GST_IS_PAD (pad));
938   g_return_if_fail (buf != NULL);
939   g_return_if_fail (GST_BUFFER_DATA (buf) != NULL);
940
941   avimux = GST_AVIMUX (gst_pad_get_parent (pad));
942   
943   if (GST_IS_EVENT(buf))
944   {
945     gst_avimux_handle_event(pad, GST_EVENT(buf));
946     return;
947   }
948
949
950   if (avimux->write_header)
951     gst_avimux_start_file(avimux);
952
953   if (strncmp(padname, "audio_", 6) == 0)
954   {
955     /* write a audio header + index entry */
956     newbuf = gst_avimux_riff_get_audio_header(GST_BUFFER_SIZE(buf));
957     avimux->total_data += GST_BUFFER_SIZE(newbuf) + GST_BUFFER_SIZE(buf);
958
959     if (avimux->is_bigfile)
960     {
961       avimux->datax_size += GST_BUFFER_SIZE(newbuf) + GST_BUFFER_SIZE(buf);
962     }
963     else
964     {
965       avimux->data_size += GST_BUFFER_SIZE(newbuf) + GST_BUFFER_SIZE(buf);
966       avimux->audio_size += GST_BUFFER_SIZE(buf);
967       gst_avimux_add_index(avimux, avimux->auds.format, 0x0, GST_BUFFER_SIZE(buf));
968     }
969
970     gst_pad_push(avimux->srcpad, newbuf);
971   }
972   else if (strncmp(padname, "video_", 6) == 0)
973   {
974     if (avimux->restart)
975       gst_avimux_restart_file(avimux);
976
977     /* write a video header + index entry */
978     GST_BUFFER_SIZE(buf) = (GST_BUFFER_SIZE(buf)+3)&~3;
979
980     if ((avimux->is_bigfile?avimux->datax_size:avimux->data_size)+GST_BUFFER_SIZE(buf)>1024*1024*2000)
981     {
982       if (avimux->enable_large_avi)
983         gst_avimux_bigfile(avimux, FALSE);
984       else
985         gst_avimux_restart_file(avimux);
986     }
987
988     newbuf = gst_avimux_riff_get_video_header(GST_BUFFER_SIZE(buf));
989     avimux->total_data += GST_BUFFER_SIZE(newbuf) + GST_BUFFER_SIZE(buf);
990     avimux->total_frames++;
991
992     if (avimux->is_bigfile)
993     {
994       avimux->datax_size += GST_BUFFER_SIZE(newbuf) + GST_BUFFER_SIZE(buf);
995       avimux->numx_frames++;
996     }
997     else
998     {
999       avimux->data_size += GST_BUFFER_SIZE(newbuf) + GST_BUFFER_SIZE(buf);
1000       avimux->num_frames++;
1001       gst_avimux_add_index(avimux, avimux->vids.compression, 0x12, GST_BUFFER_SIZE(buf));
1002     }
1003
1004     gst_pad_push(avimux->srcpad, newbuf);
1005   }
1006   else
1007   {
1008     g_warning("Unknown padname \'%s\'\n", padname);
1009     return;
1010   }
1011
1012   /* data */
1013   gst_pad_push(avimux->srcpad, buf);
1014 }
1015
1016 static void
1017 gst_avimux_get_property (GObject    *object,
1018                          guint      prop_id,
1019                          GValue     *value,
1020                          GParamSpec *pspec)
1021 {
1022   GstAviMux *avimux;
1023
1024   /* it's not null if we got it, but it might not be ours */
1025   g_return_if_fail(GST_IS_AVIMUX(object));
1026   avimux = GST_AVIMUX(object);
1027
1028   switch (prop_id)
1029   {
1030     case ARG_BIGFILE:
1031       g_value_set_boolean(value, avimux->enable_large_avi);
1032       break;
1033     case ARG_FRAMERATE:
1034       g_value_set_double(value, avimux->framerate);
1035       break;
1036     default:
1037       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1038       break;
1039   }
1040 }
1041
1042 static void
1043 gst_avimux_set_property (GObject      *object,
1044                          guint         prop_id,
1045                          const GValue *value,
1046                          GParamSpec   *pspec)
1047 {
1048   GstAviMux *avimux;
1049
1050   /* it's not null if we got it, but it might not be ours */
1051   g_return_if_fail(GST_IS_AVIMUX(object));
1052   avimux = GST_AVIMUX(object);
1053
1054   switch (prop_id)
1055   {
1056     case ARG_BIGFILE:
1057       avimux->enable_large_avi = g_value_get_boolean(value);
1058       break;
1059     case ARG_FRAMERATE:
1060       avimux->framerate = g_value_get_double(value);
1061       break;
1062     default:
1063       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1064       break;
1065   }
1066 }
1067
1068 static GstElementStateReturn
1069 gst_avimux_change_state (GstElement *element)
1070 {
1071   GstAviMux *avimux;
1072   gint transition = GST_STATE_TRANSITION (element);
1073
1074   /* TODO: timer (for fps calculations) */
1075
1076   g_return_val_if_fail(GST_IS_AVIMUX(element), GST_STATE_FAILURE);
1077   
1078   avimux = GST_AVIMUX(element);
1079
1080   switch (transition) {
1081     case GST_STATE_READY_TO_PAUSED:
1082       /*gst_avimux_start_file(avimux);*/
1083       break;
1084     case GST_STATE_PAUSED_TO_PLAYING:
1085       break;
1086     case GST_STATE_PLAYING_TO_PAUSED:
1087       gst_avimux_stop_file(avimux);
1088       break;
1089     case GST_STATE_PAUSED_TO_READY:
1090       /*gst_avimux_stop_file(avimux);*/
1091       break;
1092   }
1093
1094   if (GST_ELEMENT_CLASS (parent_class)->change_state)
1095     return GST_ELEMENT_CLASS (parent_class)->change_state (element);
1096
1097   return GST_STATE_SUCCESS;
1098 }
1099
1100 static gboolean
1101 plugin_init (GModule *module, GstPlugin *plugin)
1102 {
1103   GstElementFactory *factory;
1104
1105   /* this filter needs the riff parser */
1106 #if 0
1107   if (!gst_library_load ("gstriff")) {
1108     gst_info ("avimux: could not load support library: 'gstriff'\n");
1109     return FALSE;
1110   }
1111 #endif
1112
1113   /* create an elementfactory for the avimux element */
1114   factory = gst_elementfactory_new ("avimux", GST_TYPE_AVIMUX,
1115                                     &gst_avimux_details);
1116   g_return_val_if_fail (factory != NULL, FALSE);
1117
1118   gst_elementfactory_add_padtemplate (factory, GST_PADTEMPLATE_GET (src_factory));
1119   gst_elementfactory_add_padtemplate (factory, GST_PADTEMPLATE_GET (audio_sink_factory));
1120   gst_elementfactory_add_padtemplate (factory, GST_PADTEMPLATE_GET (video_sink_factory));
1121   
1122   gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (factory));
1123
1124   return TRUE;
1125 }
1126
1127 GstPluginDesc plugin_desc = {
1128   GST_VERSION_MAJOR,
1129   GST_VERSION_MINOR,
1130   "avimux",
1131   plugin_init
1132 };