From a5252aec08d6b939ed57ac3ed499c6a406994df2 Mon Sep 17 00:00:00 2001 From: Arnout Vandecappelle Date: Wed, 20 May 2009 13:29:02 +0200 Subject: [PATCH] multipartdemux: allow content to be empty. gst_adapter_take_buffer doesn't allow buffer to be empty. Simply skip any part where the content is empty. Don't create a pad for it either. See #582169 --- gst/multipart/multipartdemux.c | 51 +++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/gst/multipart/multipartdemux.c b/gst/multipart/multipartdemux.c index 3187920e80..a4f0f9c65a 100644 --- a/gst/multipart/multipartdemux.c +++ b/gst/multipart/multipartdemux.c @@ -502,35 +502,42 @@ gst_multipart_demux_chain (GstPad * pad, GstBuffer * buf) if ((size = multipart_find_boundary (multipart, &datalen)) < 0) { goto nodata; } - srcpad = - gst_multipart_find_pad_by_mime (multipart, - multipart->mime_type, &created); - outbuf = gst_adapter_take_buffer (adapter, datalen); - gst_adapter_flush (adapter, size - datalen); /* Invalidate header info */ multipart->header_completed = FALSE; multipart->content_length = -1; - gst_buffer_set_caps (outbuf, GST_PAD_CAPS (srcpad->pad)); - if (created) { - GstEvent *event; - - /* Push new segment, first buffer has 0 timestamp */ - event = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0); - gst_pad_push_event (srcpad->pad, event); - GST_BUFFER_TIMESTAMP (outbuf) = 0; + if (G_UNLIKELY (datalen <= 0)) { + GST_DEBUG_OBJECT (multipart, "skipping empty content."); + gst_adapter_flush (adapter, size - datalen); } else { - GST_BUFFER_TIMESTAMP (outbuf) = timestamp; + srcpad = + gst_multipart_find_pad_by_mime (multipart, + multipart->mime_type, &created); + outbuf = gst_adapter_take_buffer (adapter, datalen); + gst_adapter_flush (adapter, size - datalen); + + gst_buffer_set_caps (outbuf, GST_PAD_CAPS (srcpad->pad)); + if (created) { + GstEvent *event; + + /* Push new segment, first buffer has 0 timestamp */ + event = + gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0); + gst_pad_push_event (srcpad->pad, event); + GST_BUFFER_TIMESTAMP (outbuf) = 0; + } else { + GST_BUFFER_TIMESTAMP (outbuf) = timestamp; + } + GST_DEBUG_OBJECT (multipart, + "pushing buffer with timestamp %" GST_TIME_FORMAT, + GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf))); + GST_DEBUG_OBJECT (multipart, "buffer has caps %" GST_PTR_FORMAT, + GST_BUFFER_CAPS (outbuf)); + res = gst_pad_push (srcpad->pad, outbuf); + if (res != GST_FLOW_OK) + break; } - GST_DEBUG_OBJECT (multipart, - "pushing buffer with timestamp %" GST_TIME_FORMAT, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf))); - GST_DEBUG_OBJECT (multipart, "buffer has caps %" GST_PTR_FORMAT, - GST_BUFFER_CAPS (outbuf)); - res = gst_pad_push (srcpad->pad, outbuf); - if (res != GST_FLOW_OK) - break; } nodata: