summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian.droege@collabora.co.uk>2009-07-16 21:55:31 +0200
committerSebastian Dröge <sebastian.droege@collabora.co.uk>2009-07-16 21:55:31 +0200
commit5d0787aa203ef49454b4abdb5031f80763330cce (patch)
tree3666c1b7f936b14caeb060960b380b0a998ea9fa
parent28bee12728f4346dcf2920beb8564e3533c82158 (diff)
cairorender: Fix caps negotiation and cairo surface creation
-rw-r--r--ext/cairo/gstcairorender.c88
1 files changed, 34 insertions, 54 deletions
diff --git a/ext/cairo/gstcairorender.c b/ext/cairo/gstcairorender.c
index 4e69aa54..6de85ced 100644
--- a/ext/cairo/gstcairorender.c
+++ b/ext/cairo/gstcairorender.c
@@ -171,6 +171,7 @@ gst_cairo_render_setcaps_sink (GstPad * pad, GstCaps * caps)
GstStructure *s = gst_caps_get_structure (caps, 0);
const gchar *mime = gst_structure_get_name (s);
gint fps_n = 0, fps_d = 1;
+ gint w, h;
GST_DEBUG_OBJECT (c, "Got caps (%s).", mime);
if ((c->png = !strcmp (mime, "image/png")))
@@ -204,10 +205,41 @@ gst_cairo_render_setcaps_sink (GstPad * pad, GstCaps * caps)
caps = gst_caps_make_writable (caps);
gst_caps_truncate (caps);
s = gst_caps_get_structure (caps, 0);
+ mime = gst_structure_get_name (s);
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);
+
+ if (c->surface) {
+ cairo_surface_destroy (c->surface);
+ c->surface = NULL;
+ }
+
+ w = c->width;
+ h = c->height;
+
GST_DEBUG_OBJECT (c, "Setting src caps %" GST_PTR_FORMAT, caps);
gst_pad_set_caps (c->src, caps);
+
+#if CAIRO_HAS_PS_SURFACE
+ if (!strcmp (mime, "application/postscript")) {
+ c->surface = cairo_ps_surface_create_for_stream (write_func, c, w, h);
+ } else
+#endif
+#if CAIRO_HAS_PDF_SURFACE
+ if (!strcmp (mime, "application/x-pdf")) {
+ c->surface = cairo_pdf_surface_create_for_stream (write_func, c, w, h);
+ } else
+#endif
+#if CAIRO_HAS_SVG_SURFACE
+ if (!strcmp (mime, "image/svg")) {
+ c->surface = cairo_svg_surface_create_for_stream (write_func, c, w, h);
+ } else
+#endif
+ {
+ gst_caps_unref (caps);
+ return FALSE;
+ }
+
gst_caps_unref (caps);
return TRUE;
@@ -244,57 +276,6 @@ gst_cairo_render_activatepull_sink (GstPad * pad, gboolean active)
return gst_pad_stop_task (pad);
}
-static gboolean
-gst_cairo_render_setcaps_src (GstPad * pad, GstCaps * caps)
-{
- GstCairoRender *c = GST_CAIRO_RENDER (GST_PAD_PARENT (pad));
- const GValue *value;
- GstStructure *s = gst_caps_get_structure (caps, 0);
- const gchar *mime = gst_structure_get_name (s);
- gdouble w = 256, h = 256;
-
- if (c->surface) {
- cairo_surface_destroy (c->surface);
- c->surface = NULL;
- }
-#if CAIRO_HAS_PNG_FUNCTIONS
- if (!strcmp (mime, "image/png"))
- return TRUE;
-#endif
- value = gst_structure_get_value (s, "width");
- if (!value || !G_VALUE_HOLDS_INT (value)) {
- GST_DEBUG_OBJECT (c, "Width is missing.");
- return FALSE;
- }
- w = 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;
- }
- h = g_value_get_int (value);
-
-#if CAIRO_HAS_PS_SURFACE
- if (!strcmp (mime, "application/postscript")) {
- c->surface = cairo_ps_surface_create_for_stream (write_func, c, w, h);
- return TRUE;
- }
-#endif
-#if CAIRO_HAS_PDF_SURFACE
- if (!strcmp (mime, "application/x-pdf")) {
- c->surface = cairo_pdf_surface_create_for_stream (write_func, c, w, h);
- return TRUE;
- }
-#endif
-#if CAIRO_HAS_SVG_SURFACE
- if (!strcmp (mime, "image/svg")) {
- c->surface = cairo_svg_surface_create_for_stream (write_func, c, w, h);
- return TRUE;
- }
-#endif
- return FALSE;
-}
-
static GstElementDetails cairo_render_details =
GST_ELEMENT_DETAILS ("CAIRO encoder",
"Codec/Encoder", "Encodes streams using CAIRO",
@@ -355,12 +336,11 @@ gst_cairo_render_init (GstCairoRender * c, GstCairoRenderClass * klass)
/* The source */
c->src =
gst_pad_new_from_template (gst_static_pad_template_get (&t_src), "src");
- gst_pad_set_setcaps_function (c->src, gst_cairo_render_setcaps_src);
gst_pad_use_fixed_caps (c->src);
gst_element_add_pad (GST_ELEMENT (c), c->src);
- c->width = 256;
- c->height = 256;
+ c->width = 0;
+ c->height = 0;
}
static void