gst/multipart/multipartmux.c: Push header in a separate buffer instead of memcpy...
authorJonas Holmberg <jonas.holmberg@axis.com>
Mon, 27 Nov 2006 16:29:07 +0000 (16:29 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Mon, 27 Nov 2006 16:29:07 +0000 (16:29 +0000)
Original commit message from CVS:
Patch by: Jonas Holmberg <jonas dot holmberg at axis dot com>
* gst/multipart/multipartmux.c: (gst_multipart_mux_collected):
Push header in a separate buffer instead of memcpy:ing all data
Change LF => CRLF in headers
Move trailing LF to header

ChangeLog
gst/multipart/multipartmux.c

index 6406273..72f3a57 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2006-11-27  Wim Taymans  <wim@fluendo.com>
 
+       Patch by: Jonas Holmberg <jonas dot holmberg at axis dot com>
+
+       * gst/multipart/multipartmux.c: (gst_multipart_mux_collected):
+       Push header in a separate buffer instead of memcpy:ing all data
+       Change LF => CRLF in headers
+       Move trailing LF to header
+
+2006-11-27  Wim Taymans  <wim@fluendo.com>
+
        * gst/rtp/gstrtpmpadepay.c: (gst_rtp_mpa_depay_chain):
        Small buffer overflow fix and improve debugging.
 
index 33460cd..fa83c01 100644 (file)
@@ -434,7 +434,8 @@ gst_multipart_mux_queue_pads (GstMultipartMux * mux)
  *
  * 1) find a pad to pull on, this is done by pulling on all pads and
  *    looking at the buffers to decide which one should be muxed first.
- * 2) push buffer on best pad, go to 1
+ * 2) create a new buffer for the header
+ * 3) push both buffers on best pad, go to 1
  */
 static GstFlowReturn
 gst_multipart_mux_collected (GstCollectPads * pads, GstMultipartMux * mux)
@@ -442,11 +443,10 @@ gst_multipart_mux_collected (GstCollectPads * pads, GstMultipartMux * mux)
   GstMultipartPad *best;
   GstFlowReturn ret = GST_FLOW_OK;
   gchar *header = NULL;
-  size_t newlen, headerlen;
-  GstBuffer *newbuf = NULL;
+  size_t headerlen;
+  GstBuffer *headerbuf = NULL;
+  GstBuffer *databuf = NULL;
   GstStructure *structure = NULL;
-  guint8 *data;
-  guint datasize;
 
   GST_DEBUG_OBJECT (mux, "all pads are collected");
 
@@ -485,42 +485,39 @@ gst_multipart_mux_collected (GstCollectPads * pads, GstMultipartMux * mux)
     goto beach;
   }
 
-  header = g_strdup_printf ("--%s\nContent-type: %s\n\n",
-      mux->boundary, gst_structure_get_name (structure));
-
-  datasize = GST_BUFFER_SIZE (best->buffer);
-
+  header = g_strdup_printf ("\r\n--%s\r\nContent-Type: %s\r\n"
+      "Content-Length: %u\r\n\r\n",
+      mux->boundary, gst_structure_get_name (structure),
+      GST_BUFFER_SIZE (best->buffer));
   headerlen = strlen (header);
-  /* header, data, trailing \n */
-  newlen = headerlen + datasize + 1;
 
-  ret =
-      gst_pad_alloc_buffer_and_set_caps (mux->srcpad, GST_BUFFER_OFFSET_NONE,
-      newlen, GST_PAD_CAPS (mux->srcpad), &newbuf);
+  ret = gst_pad_alloc_buffer_and_set_caps (mux->srcpad, GST_BUFFER_OFFSET_NONE,
+      headerlen, GST_PAD_CAPS (mux->srcpad), &headerbuf);
   if (ret != GST_FLOW_OK) {
-    GST_WARNING_OBJECT (mux, "failed allocating a %d bytes buffer", newlen);
+    GST_WARNING_OBJECT (mux, "failed allocating a %d bytes buffer", headerlen);
     g_free (header);
     goto beach;
   }
 
-  data = GST_BUFFER_DATA (newbuf);
-
-  memcpy (data, header, headerlen);
-  memcpy (data + headerlen, GST_BUFFER_DATA (best->buffer), datasize);
-
-  /* trailing \n */
-  data[headerlen + datasize] = '\n';
+  memcpy (GST_BUFFER_DATA (headerbuf), header, headerlen);
+  g_free (header);
 
-  gst_buffer_stamp (newbuf, best->buffer);
-  GST_BUFFER_OFFSET (newbuf) = mux->offset;
+  databuf = gst_buffer_make_metadata_writable (best->buffer);
+  gst_buffer_set_caps (databuf, GST_PAD_CAPS (mux->srcpad));
 
-  g_free (header);
+  gst_buffer_stamp (headerbuf, databuf);
 
-  mux->offset += newlen;
+  GST_BUFFER_OFFSET (headerbuf) = mux->offset;
+  mux->offset += headerlen;
+  GST_DEBUG_OBJECT (mux, "pushing %u bytes header buffer", headerlen);
+  gst_pad_push (mux->srcpad, headerbuf);
 
-  gst_pad_push (mux->srcpad, newbuf);
+  GST_BUFFER_OFFSET (databuf) = mux->offset;
+  mux->offset += GST_BUFFER_SIZE (databuf);
+  GST_DEBUG_OBJECT (mux, "pushing %u bytes data buffer",
+      GST_BUFFER_SIZE (databuf));
+  gst_pad_push (mux->srcpad, databuf);
 
-  gst_buffer_unref (best->buffer);
   best->buffer = NULL;
 
 beach: