ext/jpeg/: Refuse sink caps in the encoder if width or height is not a multiple of 16, the encoder does not support t...

Original commit message from CVS:
* ext/jpeg/gstsmokedec.c: (gst_smokedec_chain):
* ext/jpeg/gstsmokeenc.c: (gst_smokeenc_setcaps),
(gst_smokeenc_resync), (gst_smokeenc_chain):
Refuse sink caps in the encoder if width or height is not a
multiple of 16, the encoder does not support that yet; along the
same lines, check the return value of the encoder setup function;
also remove some debug log clutter.
This commit is contained in:
Tim-Philipp Müller 2006-08-08 14:40:47 +00:00
parent 7fbf85ea54
commit 7e522c28c2
3 changed files with 51 additions and 25 deletions

View File

@ -1,3 +1,13 @@
2006-08-08 Tim-Philipp Müller <tim at centricular dot net>
* ext/jpeg/gstsmokedec.c: (gst_smokedec_chain):
* ext/jpeg/gstsmokeenc.c: (gst_smokeenc_setcaps),
(gst_smokeenc_resync), (gst_smokeenc_chain):
Refuse sink caps in the encoder if width or height is not a
multiple of 16, the encoder does not support that yet; along the
same lines, check the return value of the encoder setup function;
also remove some debug log clutter.
2006-08-04 Andy Wingo <wingo@pobox.com> 2006-08-04 Andy Wingo <wingo@pobox.com>
* ext/ladspa/gstsignalprocessor.h: Add infrastructure for storing * ext/ladspa/gstsignalprocessor.h: Add infrastructure for storing

View File

@ -171,9 +171,7 @@ gst_smokedec_chain (GstPad * pad, GstBuffer * buf)
size = GST_BUFFER_SIZE (buf); size = GST_BUFFER_SIZE (buf);
time = GST_BUFFER_TIMESTAMP (buf); time = GST_BUFFER_TIMESTAMP (buf);
GST_DEBUG_OBJECT (smokedec, GST_LOG_OBJECT (smokedec, "got buffer of %u bytes", size);
"gst_smokedec_chain: got buffer of %ld bytes in '%s'", size,
GST_OBJECT_NAME (smokedec));
/* have the ID packet. */ /* have the ID packet. */
if (data[0] == SMOKECODEC_TYPE_ID) { if (data[0] == SMOKECODEC_TYPE_ID) {
@ -186,8 +184,7 @@ gst_smokedec_chain (GstPad * pad, GstBuffer * buf)
} }
/* now handle data packets */ /* now handle data packets */
GST_DEBUG_OBJECT (smokedec, "gst_smokedec_chain: reading header %08lx", GST_DEBUG_OBJECT (smokedec, "reading header %08lx", *(gulong *) data);
*(gulong *) data);
smokecodec_parse_header (smokedec->info, data, size, &flags, &width, &height, smokecodec_parse_header (smokedec->info, data, size, &flags, &width, &height,
&fps_num, &fps_denom); &fps_num, &fps_denom);
@ -195,6 +192,9 @@ gst_smokedec_chain (GstPad * pad, GstBuffer * buf)
smokedec->fps_num != fps_num || smokedec->fps_denom != fps_denom) { smokedec->fps_num != fps_num || smokedec->fps_denom != fps_denom) {
GstCaps *caps; GstCaps *caps;
GST_DEBUG_OBJECT (smokedec, "parameter change: %dx%d @ %d/%dfps",
width, height, fps_num, fps_denom);
smokedec->height = height; smokedec->height = height;
smokedec->width = width; smokedec->width = width;

View File

@ -67,7 +67,7 @@ static GstFlowReturn gst_smokeenc_chain (GstPad * pad, GstBuffer * buf);
static gboolean gst_smokeenc_setcaps (GstPad * pad, GstCaps * caps); static gboolean gst_smokeenc_setcaps (GstPad * pad, GstCaps * caps);
static GstCaps *gst_smokeenc_getcaps (GstPad * pad); static GstCaps *gst_smokeenc_getcaps (GstPad * pad);
static void gst_smokeenc_resync (GstSmokeEnc * smokeenc); static gboolean gst_smokeenc_resync (GstSmokeEnc * smokeenc);
static void gst_smokeenc_set_property (GObject * object, guint prop_id, static void gst_smokeenc_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec); const GValue * value, GParamSpec * pspec);
static void gst_smokeenc_get_property (GObject * object, guint prop_id, static void gst_smokeenc_get_property (GObject * object, guint prop_id,
@ -255,6 +255,9 @@ gst_smokeenc_setcaps (GstPad * pad, GstCaps * caps)
gst_structure_get_int (structure, "width", &smokeenc->width); gst_structure_get_int (structure, "width", &smokeenc->width);
gst_structure_get_int (structure, "height", &smokeenc->height); gst_structure_get_int (structure, "height", &smokeenc->height);
if ((smokeenc->width & 0x0f) != 0 || (smokeenc->height & 0x0f) != 0)
goto width_or_height_notx16;
othercaps = gst_caps_copy (gst_pad_get_pad_template_caps (otherpad)); othercaps = gst_caps_copy (gst_pad_get_pad_template_caps (otherpad));
gst_caps_set_simple (othercaps, gst_caps_set_simple (othercaps,
@ -267,26 +270,42 @@ gst_smokeenc_setcaps (GstPad * pad, GstCaps * caps)
ret = gst_pad_set_caps (otherpad, othercaps); ret = gst_pad_set_caps (otherpad, othercaps);
gst_caps_unref (othercaps); gst_caps_unref (othercaps);
if (GST_PAD_LINK_SUCCESSFUL (ret)) { if (ret) {
gst_smokeenc_resync (smokeenc); ret = gst_smokeenc_resync (smokeenc);
} }
gst_object_unref (smokeenc); gst_object_unref (smokeenc);
return ret; return ret;
width_or_height_notx16:
{
GST_WARNING_OBJECT (smokeenc, "width and height must be multiples of 16"
", %dx%d not allowed", smokeenc->width, smokeenc->height);
return FALSE;
}
} }
static void static gboolean
gst_smokeenc_resync (GstSmokeEnc * smokeenc) gst_smokeenc_resync (GstSmokeEnc * smokeenc)
{ {
GST_DEBUG ("gst_smokeenc_resync: resync"); int ret;
smokecodec_encode_new (&smokeenc->info, smokeenc->width, smokeenc->height, GST_DEBUG ("resync: %dx%d@%d/%dfps", smokeenc->width, smokeenc->height,
smokeenc->fps_num, smokeenc->fps_denom); smokeenc->fps_num, smokeenc->fps_denom);
ret = smokecodec_encode_new (&smokeenc->info, smokeenc->width,
smokeenc->height, smokeenc->fps_num, smokeenc->fps_denom);
if (ret != SMOKECODEC_OK) {
GST_WARNING_OBJECT (smokeenc, "smokecodec_encode_new() failed: %d", ret);
return FALSE;
}
smokecodec_set_quality (smokeenc->info, smokeenc->min_quality, smokecodec_set_quality (smokeenc->info, smokeenc->min_quality,
smokeenc->max_quality); smokeenc->max_quality);
GST_DEBUG ("gst_smokeenc_resync: resync done"); GST_DEBUG ("resync done");
return TRUE;
} }
static GstFlowReturn static GstFlowReturn
@ -300,31 +319,27 @@ gst_smokeenc_chain (GstPad * pad, GstBuffer * buf)
GstBuffer *outbuf; GstBuffer *outbuf;
SmokeCodecFlags flags; SmokeCodecFlags flags;
GstFlowReturn ret; GstFlowReturn ret;
GstCaps *caps;
smokeenc = GST_SMOKEENC (GST_OBJECT_PARENT (pad)); smokeenc = GST_SMOKEENC (GST_OBJECT_PARENT (pad));
data = GST_BUFFER_DATA (buf); data = GST_BUFFER_DATA (buf);
size = GST_BUFFER_SIZE (buf); size = GST_BUFFER_SIZE (buf);
GST_DEBUG ("gst_smokeenc_chain: got buffer of %ld bytes in '%s'", size, GST_LOG_OBJECT (smokeenc, "got buffer of %u bytes", size);
GST_OBJECT_NAME (smokeenc));
if (smokeenc->need_header) { if (smokeenc->need_header) {
outbuf = gst_buffer_new (); outbuf = gst_buffer_new_and_alloc (256);
outsize = 256; gst_buffer_set_caps (outbuf, GST_PAD_CAPS (smokeenc->srcpad));
outdata = g_malloc (outsize);
GST_BUFFER_DATA (outbuf) = outdata;
GST_BUFFER_MALLOCDATA (outbuf) = outdata;
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf); GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buf); GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buf);
caps = GST_PAD_CAPS (smokeenc->srcpad);
gst_buffer_set_caps (outbuf, caps); smokecodec_encode_id (smokeenc->info, GST_BUFFER_DATA (outbuf), &encsize);
smokecodec_encode_id (smokeenc->info, outdata, &encsize);
GST_BUFFER_SIZE (outbuf) = encsize; GST_BUFFER_SIZE (outbuf) = encsize;
ret = gst_pad_push (smokeenc->srcpad, outbuf); ret = gst_pad_push (smokeenc->srcpad, outbuf);
if (ret != GST_FLOW_OK)
goto done;
smokeenc->need_header = FALSE; smokeenc->need_header = FALSE;
} }
@ -337,8 +352,7 @@ gst_smokeenc_chain (GstPad * pad, GstBuffer * buf)
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf); GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (outbuf) =
smokeenc->fps_denom * GST_SECOND / smokeenc->fps_num; smokeenc->fps_denom * GST_SECOND / smokeenc->fps_num;
caps = GST_PAD_CAPS (smokeenc->srcpad); gst_buffer_set_caps (outbuf, GST_PAD_CAPS (smokeenc->srcpad));
gst_buffer_set_caps (outbuf, caps);
flags = 0; flags = 0;
if ((smokeenc->frame % smokeenc->keyframe) == 0) { if ((smokeenc->frame % smokeenc->keyframe) == 0) {
@ -358,6 +372,8 @@ gst_smokeenc_chain (GstPad * pad, GstBuffer * buf)
smokeenc->frame++; smokeenc->frame++;
done:
return ret; return ret;
} }