From 32aa80cda8e8f7a958a2e1bf2410b2964f3617a7 Mon Sep 17 00:00:00 2001 From: David Schleef Date: Thu, 30 Jun 2011 18:47:48 -0700 Subject: [PATCH] multipartmux: Add \r\n to tail of pushed buffers Clients such as Firefox require the \r\n after the payload. --- gst/multipart/multipartmux.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/gst/multipart/multipartmux.c b/gst/multipart/multipartmux.c index 9f246ddf49..9f69975f56 100644 --- a/gst/multipart/multipartmux.c +++ b/gst/multipart/multipartmux.c @@ -427,6 +427,7 @@ gst_multipart_mux_collected (GstCollectPads * pads, GstMultipartMux * mux) gchar *header = NULL; size_t headerlen; GstBuffer *headerbuf = NULL; + GstBuffer *footerbuf = NULL; GstBuffer *databuf = NULL; GstStructure *structure = NULL; const gchar *mime; @@ -484,7 +485,7 @@ gst_multipart_mux_collected (GstCollectPads * pads, GstMultipartMux * mux) /* get the mime type for the structure */ mime = gst_multipart_mux_get_mime (mux, structure); - header = g_strdup_printf ("\r\n--%s\r\nContent-Type: %s\r\n" + header = g_strdup_printf ("--%s\r\nContent-Type: %s\r\n" "Content-Length: %u\r\n\r\n", mux->boundary, mime, GST_BUFFER_SIZE (best->buffer)); headerlen = strlen (header); @@ -529,6 +530,29 @@ gst_multipart_mux_collected (GstCollectPads * pads, GstMultipartMux * mux) GST_DEBUG_OBJECT (mux, "pushing %u bytes data buffer", GST_BUFFER_SIZE (databuf)); ret = gst_pad_push (mux->srcpad, databuf); + if (ret != GST_FLOW_OK) + /* push always takes ownership of the buffer, even after an error, so we + * don't need to unref headerbuf here. */ + goto beach; + + ret = gst_pad_alloc_buffer_and_set_caps (mux->srcpad, GST_BUFFER_OFFSET_NONE, + 2, GST_PAD_CAPS (mux->srcpad), &footerbuf); + if (ret != GST_FLOW_OK) + goto alloc_failed; + + memcpy (GST_BUFFER_DATA (footerbuf), "\r\n", 2); + + /* the footer has the same timestamp as the data buffer and has a + * duration of 0 */ + GST_BUFFER_TIMESTAMP (footerbuf) = best->timestamp; + GST_BUFFER_DURATION (footerbuf) = 0; + GST_BUFFER_OFFSET (footerbuf) = mux->offset; + mux->offset += 2; + GST_BUFFER_OFFSET_END (footerbuf) = mux->offset; + GST_BUFFER_FLAG_SET (footerbuf, GST_BUFFER_FLAG_DELTA_UNIT); + + GST_DEBUG_OBJECT (mux, "pushing %" G_GSIZE_FORMAT " bytes footer buffer", 2); + ret = gst_pad_push (mux->srcpad, footerbuf); beach: if (best && best->buffer) {