From c0826dc21d0ee5c7119354fe1da9a499cef44905 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 25 Aug 2008 09:48:06 +0000 Subject: gst/law/: The encoder can't really renegotiate at the time they perform a pad-alloc so make the srcpads use fixed caps. Original commit message from CVS: * gst/law/alaw-encode.c: (gst_alaw_enc_init), (gst_alaw_enc_chain): * gst/law/mulaw-conversion.c: * gst/law/mulaw-encode.c: (gst_mulawenc_init), (gst_mulawenc_chain): The encoder can't really renegotiate at the time they perform a pad-alloc so make the srcpads use fixed caps. Check the buffer size after a pad-alloc because the returned size might not be right when the downstream element does not know the size of the new buffer (capsfilter). Fixes #549073. --- gst/law/mulaw-encode.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'gst/law/mulaw-encode.c') diff --git a/gst/law/mulaw-encode.c b/gst/law/mulaw-encode.c index e926b992..033665e4 100644 --- a/gst/law/mulaw-encode.c +++ b/gst/law/mulaw-encode.c @@ -194,6 +194,7 @@ gst_mulawenc_init (GstMuLawEnc * mulawenc) mulawenc->srcpad = gst_pad_new_from_template (mulawenc_src_template, "src"); gst_pad_set_setcaps_function (mulawenc->srcpad, mulawenc_setcaps); gst_pad_set_getcaps_function (mulawenc->srcpad, mulawenc_getcaps); + gst_pad_use_fixed_caps (mulawenc->srcpad); gst_element_add_pad (GST_ELEMENT (mulawenc), mulawenc->srcpad); /* init rest */ @@ -225,18 +226,24 @@ gst_mulawenc_chain (GstPad * pad, GstBuffer * buffer) timestamp = GST_BUFFER_TIMESTAMP (buffer); duration = GST_BUFFER_DURATION (buffer); - if (duration == -1) { - duration = gst_util_uint64_scale_int (mulaw_size, - GST_SECOND, mulawenc->rate * mulawenc->channels); - } - ret = - gst_pad_alloc_buffer_and_set_caps (mulawenc->srcpad, + ret = gst_pad_alloc_buffer_and_set_caps (mulawenc->srcpad, GST_BUFFER_OFFSET_NONE, mulaw_size, GST_PAD_CAPS (mulawenc->srcpad), &outbuf); if (ret != GST_FLOW_OK) goto alloc_failed; + if (duration == -1) { + duration = gst_util_uint64_scale_int (mulaw_size, + GST_SECOND, mulawenc->rate * mulawenc->channels); + } + + if (GST_BUFFER_SIZE (outbuf) < mulaw_size) { + /* pad-alloc can suggest a smaller size */ + gst_buffer_unref (outbuf); + outbuf = gst_buffer_new_and_alloc (mulaw_size); + } + mulaw_data = (guint8 *) GST_BUFFER_DATA (outbuf); /* copy discont flag */ -- cgit