jpegenc: Set correct getcaps/setcaps functions on srcpads and simplify them

This fixes downstream negotiation, upstream negotiation isn't really
supported by jpegenc yet.

Fixes bug #613789.
This commit is contained in:
Raimo Järvi 2010-03-26 13:34:17 +01:00 committed by Sebastian Dröge
parent 3bdd50c93b
commit 10f092dc61

View file

@ -274,10 +274,7 @@ gst_jpegenc_init (GstJpegEnc * jpegenc)
jpegenc->srcpad = jpegenc->srcpad =
gst_pad_new_from_static_template (&gst_jpegenc_src_pad_template, "src"); gst_pad_new_from_static_template (&gst_jpegenc_src_pad_template, "src");
gst_pad_set_getcaps_function (jpegenc->sinkpad, gst_pad_use_fixed_caps (jpegenc->srcpad);
GST_DEBUG_FUNCPTR (gst_jpegenc_getcaps));
/*gst_pad_set_setcaps_function (jpegenc->sinkpad, gst_jpegenc_setcaps); */
gst_pad_use_fixed_caps (jpegenc->sinkpad);
gst_element_add_pad (GST_ELEMENT (jpegenc), jpegenc->srcpad); gst_element_add_pad (GST_ELEMENT (jpegenc), jpegenc->srcpad);
/* reset the initial video state */ /* reset the initial video state */
@ -317,38 +314,25 @@ static GstCaps *
gst_jpegenc_getcaps (GstPad * pad) gst_jpegenc_getcaps (GstPad * pad)
{ {
GstJpegEnc *jpegenc = GST_JPEGENC (gst_pad_get_parent (pad)); GstJpegEnc *jpegenc = GST_JPEGENC (gst_pad_get_parent (pad));
GstPad *otherpad;
GstCaps *caps; GstCaps *caps;
const char *name;
int i; int i;
GstStructure *structure = NULL; GstStructure *structure = NULL;
/* we want to proxy properties like width, height and framerate from the /* we want to proxy properties like width, height and framerate from the
other end of the element */ other end of the element */
otherpad = (pad == jpegenc->srcpad) ? jpegenc->sinkpad : jpegenc->srcpad;
caps = gst_pad_peer_get_caps (otherpad); caps = gst_pad_peer_get_caps (jpegenc->srcpad);
if (caps == NULL) if (caps == NULL)
caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad)); caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
else else
caps = gst_caps_make_writable (caps); caps = gst_caps_make_writable (caps);
if (pad == jpegenc->srcpad) {
name = "image/jpeg";
} else {
name = "video/x-raw-yuv";
}
for (i = 0; i < gst_caps_get_size (caps); i++) { for (i = 0; i < gst_caps_get_size (caps); i++) {
structure = gst_caps_get_structure (caps, i); structure = gst_caps_get_structure (caps, i);
gst_structure_set_name (structure, name); gst_structure_set_name (structure, "video/x-raw-yuv");
gst_structure_remove_field (structure, "format"); gst_structure_set (structure, "format", GST_TYPE_FOURCC,
/* ... but for the sink pad, we only do I420 anyway, so add that */ GST_STR_FOURCC ("I420"), NULL);
if (pad == jpegenc->sinkpad) {
gst_structure_set (structure, "format", GST_TYPE_FOURCC,
GST_STR_FOURCC ("I420"), NULL);
}
} }
gst_object_unref (jpegenc); gst_object_unref (jpegenc);
@ -358,40 +342,32 @@ gst_jpegenc_getcaps (GstPad * pad)
static gboolean static gboolean
gst_jpegenc_setcaps (GstPad * pad, GstCaps * caps) gst_jpegenc_setcaps (GstPad * pad, GstCaps * caps)
{ {
GstJpegEnc *jpegenc = GST_JPEGENC (gst_pad_get_parent (pad)); GstJpegEnc *jpegenc;
GstStructure *structure;
GstCaps *othercaps;
GstPad *otherpad;
gboolean ret;
const GValue *framerate; const GValue *framerate;
GstStructure *structure;
GstCaps *pcaps;
gboolean ret;
otherpad = (pad == jpegenc->srcpad) ? jpegenc->sinkpad : jpegenc->srcpad; jpegenc = GST_JPEGENC (gst_pad_get_parent (pad));
structure = gst_caps_get_structure (caps, 0); structure = gst_caps_get_structure (caps, 0);
framerate = gst_structure_get_value (structure, "framerate"); framerate = gst_structure_get_value (structure, "framerate");
gst_structure_get_int (structure, "width", &jpegenc->width); gst_structure_get_int (structure, "width", &jpegenc->width);
gst_structure_get_int (structure, "height", &jpegenc->height); gst_structure_get_int (structure, "height", &jpegenc->height);
othercaps = gst_caps_copy (gst_pad_get_pad_template_caps (otherpad)); pcaps = gst_caps_new_simple ("image/jpeg",
if (framerate) { "width", G_TYPE_INT, jpegenc->width,
gst_caps_set_simple (othercaps, "height", G_TYPE_INT, jpegenc->height, NULL);
"width", G_TYPE_INT, jpegenc->width, structure = gst_caps_get_structure (pcaps, 0);
"height", G_TYPE_INT, jpegenc->height, if (framerate)
"framerate", GST_TYPE_FRACTION, gst_structure_set_value (structure, "framerate", framerate);
gst_value_get_fraction_numerator (framerate),
gst_value_get_fraction_denominator (framerate), NULL);
} else {
gst_caps_set_simple (othercaps,
"width", G_TYPE_INT, jpegenc->width,
"height", G_TYPE_INT, jpegenc->height, NULL);
}
ret = gst_pad_set_caps (jpegenc->srcpad, othercaps); ret = gst_pad_set_caps (jpegenc->srcpad, pcaps);
gst_caps_unref (othercaps);
if (ret) if (ret)
gst_jpegenc_resync (jpegenc); gst_jpegenc_resync (jpegenc);
gst_caps_unref (pcaps);
gst_object_unref (jpegenc); gst_object_unref (jpegenc);
return ret; return ret;