cairorender: Correctly set srccaps

This commit is contained in:
Sebastian Dröge 2009-07-16 21:42:21 +02:00
parent 13f23f81e8
commit 28bee12728

View file

@ -168,50 +168,48 @@ static gboolean
gst_cairo_render_setcaps_sink (GstPad * pad, GstCaps * caps) gst_cairo_render_setcaps_sink (GstPad * pad, GstCaps * caps)
{ {
GstCairoRender *c = GST_CAIRO_RENDER (GST_PAD_PARENT (pad)); GstCairoRender *c = GST_CAIRO_RENDER (GST_PAD_PARENT (pad));
const GValue *value;
GstStructure *s = gst_caps_get_structure (caps, 0); GstStructure *s = gst_caps_get_structure (caps, 0);
const gchar *mime = gst_structure_get_name (s); const gchar *mime = gst_structure_get_name (s);
gint fps_n = 0, fps_d = 1;
GST_DEBUG_OBJECT (c, "Got caps (%s).", mime); GST_DEBUG_OBJECT (c, "Got caps (%s).", mime);
if ((c->png = !strcmp (mime, "image/png"))) if ((c->png = !strcmp (mime, "image/png")))
return TRUE; return TRUE;
/* Width and height */ /* Width and height */
value = gst_structure_get_value (s, "width"); if (!gst_structure_get_int (s, "width", &c->width) ||
if (!value || !G_VALUE_HOLDS_INT (value)) { !gst_structure_get_int (s, "height", &c->height)) {
GST_DEBUG_OBJECT (c, "Width is missing."); GST_ERROR_OBJECT (c, "Invalid caps");
return FALSE; return FALSE;
} }
c->width = g_value_get_int (value);
value = gst_structure_get_value (s, "height");
if (!value || !G_VALUE_HOLDS_INT (value)) {
GST_DEBUG_OBJECT (c, "Height is missing.");
return FALSE;
}
c->height = g_value_get_int (value);
/* Colorspace /* Colorspace
* FIXME: I couldn't figure out the right caps. The solution below * FIXME: I couldn't figure out the right caps. The solution below
* results in a black and white result which is better than nothing. * results in a black and white result which is better than nothing.
* If you know how to fix this, please do it. */ * If you know how to fix this, please do it. */
if (!strcmp (mime, "video/x-raw-yuv")) if (!strcmp (mime, "video/x-raw-yuv")) {
c->format = CAIRO_FORMAT_A8; c->format = CAIRO_FORMAT_A8;
else if (!strcmp (mime, "video/x-raw-rgb")) } else if (!strcmp (mime, "video/x-raw-rgb")) {
c->format = CAIRO_FORMAT_RGB24; c->format = CAIRO_FORMAT_RGB24;
else { } else {
GST_DEBUG_OBJECT (c, "Unknown mime type '%s'.", mime); GST_DEBUG_OBJECT (c, "Unknown mime type '%s'.", mime);
return FALSE; return FALSE;
} }
/* Framerate */ /* Framerate */
value = gst_structure_get_value (s, "framerate"); gst_structure_get_fraction (s, "framerate", &fps_n, &fps_d);
if (value && GST_VALUE_HOLDS_FRACTION (value)) {
caps = gst_pad_get_allowed_caps (c->src); /* Create output caps */
s = gst_caps_get_structure (caps, 0); caps = gst_pad_get_allowed_caps (c->src);
gst_structure_set_value (s, "framerate", value); caps = gst_caps_make_writable (caps);
gst_pad_set_caps (c->src, caps); gst_caps_truncate (caps);
gst_caps_unref (caps); s = gst_caps_get_structure (caps, 0);
} gst_structure_set (s, "height", G_TYPE_INT, c->height, "width", G_TYPE_INT,
c->width, "framerate", GST_TYPE_FRACTION, fps_n, fps_d, NULL);
GST_DEBUG_OBJECT (c, "Setting src caps %" GST_PTR_FORMAT, caps);
gst_pad_set_caps (c->src, caps);
gst_caps_unref (caps);
return TRUE; return TRUE;
} }