Index: ChangeLog
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-good/ChangeLog,v
retrieving revision 1.3603
diff -u -r1.3603 ChangeLog
--- ChangeLog	14 Jul 2008 17:17:46 -0000	1.3603
+++ ChangeLog	17 Jul 2008 02:53:08 -0000
@@ -1,3 +1,9 @@
+2008-07-16  David Schleef  <ds@schleef.org>
+
+	* gst/avi/gstavimux.c:
+	* gst/avi/gstavimux.h:
+	  Reparse Dirac streams into appropriate chunks for AVI.
+
 2008-07-14  Sebastian Dröge  <slomo@circular-chaos.org>
 
 	* gst/debug/gsttaginject.c: (gst_tag_inject_start):
Index: gst/avi/gstavimux.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-good/gst/avi/gstavimux.c,v
retrieving revision 1.105
diff -u -r1.105 gstavimux.c
--- gst/avi/gstavimux.c	29 Jun 2008 19:52:51 -0000	1.105
+++ gst/avi/gstavimux.c	17 Jul 2008 02:53:09 -0000
@@ -75,6 +75,7 @@
 #include <string.h>
 
 #include <gst/video/video.h>
+#include <gst/base/gstadapter.h>
 
 #include "gstavimux.h"
 
@@ -800,6 +801,7 @@
 
     /* init pad specific data */
     avipad = g_malloc0 (sizeof (GstAviAudioPad));
+    avipad->adapter = gst_adapter_new();
     avipad->is_video = FALSE;
     avipad->hdr.type = GST_MAKE_FOURCC ('a', 'u', 'd', 's');
     avimux->audio_pads++;
@@ -817,6 +819,7 @@
     gst_pad_set_setcaps_function (newpad,
         GST_DEBUG_FUNCPTR (gst_avi_mux_vidsink_set_caps));
     avipad = g_malloc0 (sizeof (GstAviVideoPad));
+    avipad->adapter = gst_adapter_new();
 
     /* init pad specific data */
     avipad->is_video = TRUE;
@@ -881,6 +884,7 @@
       if (avimux->write_header) {
         avimux->sinkpads = g_slist_remove (avimux->sinkpads, avipad);
         gst_avi_mux_pad_reset (avipad, TRUE);
+        g_object_unref (avipad->adapter);
         g_free (avipad);
       }
       return;
@@ -1705,12 +1709,26 @@
 gst_avi_mux_do_buffer (GstAviMux * avimux, GstAviPad * avipad)
 {
   GstFlowReturn res;
-  GstBuffer *data, *header;
+  GstBuffer *data, *header, *outbuf;
   gulong total_size, pad_bytes = 0;
   guint flags;
+  int size;
 
   data = gst_collect_pads_pop (avimux->collect, avipad->collect);
 
+  if (avipad->is_video &&
+      ((GstAviVideoPad *)avipad)->vids.compression == GST_MAKE_FOURCC ('d', 'r', 'a', 'c')) {
+    int parse_code;
+    guint8 *buffer_data = GST_BUFFER_DATA(data);
+
+    parse_code = buffer_data[4];
+
+    if (!(parse_code & 0x08)) {
+      gst_adapter_push (avipad->adapter, data);
+      return GST_FLOW_OK;
+    }
+  }
+
   if (avimux->restart) {
     if ((res = gst_avi_mux_restart_file (avimux)) != GST_FLOW_OK)
       return res;
@@ -1728,12 +1746,14 @@
     }
   }
 
+  size = gst_adapter_available (avipad->adapter) + GST_BUFFER_SIZE (data);
+
   /* get header and record some stats */
-  if (GST_BUFFER_SIZE (data) & 1) {
-    pad_bytes = 2 - (GST_BUFFER_SIZE (data) & 1);
+  if (size & 1) {
+    pad_bytes = 2 - (size & 1);
   }
-  header = gst_avi_mux_riff_get_header (avipad, GST_BUFFER_SIZE (data));
-  total_size = GST_BUFFER_SIZE (header) + GST_BUFFER_SIZE (data) + pad_bytes;
+  header = gst_avi_mux_riff_get_header (avipad, size);
+  total_size = GST_BUFFER_SIZE (header) + size + pad_bytes;
 
   if (avimux->is_bigfile) {
     avimux->datax_size += total_size;
@@ -1757,22 +1777,26 @@
     GstAviAudioPad *audpad = (GstAviAudioPad *) avipad;
 
     flags = 0;
-    audpad->audio_size += GST_BUFFER_SIZE (data);
+    audpad->audio_size += size;
     audpad->audio_time += GST_BUFFER_DURATION (data);
   }
 
-  gst_avi_mux_add_index (avimux, avipad->tag, flags, GST_BUFFER_SIZE (data));
+  gst_adapter_push (avipad->adapter, data);
+  outbuf = gst_adapter_take_buffer (avipad->adapter,
+      gst_adapter_available (avipad->adapter));
+
+  gst_avi_mux_add_index (avimux, avipad->tag, flags, size);
 
   /* prepare buffers for sending */
   gst_buffer_set_caps (header, GST_PAD_CAPS (avimux->srcpad));
-  data = gst_buffer_make_metadata_writable (data);
-  gst_buffer_set_caps (data, GST_PAD_CAPS (avimux->srcpad));
+
+  gst_buffer_set_caps (outbuf, GST_PAD_CAPS (avimux->srcpad));
 
   GST_DEBUG ("pushing buffers: head, data");
 
   if ((res = gst_pad_push (avimux->srcpad, header)) != GST_FLOW_OK)
     return res;
-  if ((res = gst_pad_push (avimux->srcpad, data)) != GST_FLOW_OK)
+  if ((res = gst_pad_push (avimux->srcpad, outbuf)) != GST_FLOW_OK)
     return res;
 
   if (pad_bytes) {
Index: gst/avi/gstavimux.h
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-good/gst/avi/gstavimux.h,v
retrieving revision 1.19
diff -u -r1.19 gstavimux.h
--- gst/avi/gstavimux.h	29 Jun 2008 19:52:51 -0000	1.19
+++ gst/avi/gstavimux.h	17 Jul 2008 02:53:09 -0000
@@ -80,6 +80,9 @@
   gst_avi_superindex_entry idx[GST_AVI_SUPERINDEX_COUNT];
   gint idx_index;
   gchar *idx_tag;
+
+  /* list of stored buffers */
+  GstAdapter *adapter;
 } GstAviPad;
 
 typedef struct _GstAviVideoPad {
