diff --git a/ext/gdk_pixbuf/pixbufscale.c b/ext/gdk_pixbuf/pixbufscale.c index bedd982524..35af64e6dd 100644 --- a/ext/gdk_pixbuf/pixbufscale.c +++ b/ext/gdk_pixbuf/pixbufscale.c @@ -57,14 +57,14 @@ static GstStaticPadTemplate gst_pixbufscale_src_template = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB) + GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("RGB")) ); static GstStaticPadTemplate gst_pixbufscale_sink_template = GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB) + GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE ("RGB")) ); #define GST_TYPE_PIXBUFSCALE_METHOD (gst_pixbufscale_method_get_type()) @@ -93,28 +93,32 @@ static void gst_pixbufscale_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); static GstCaps *gst_pixbufscale_transform_caps (GstBaseTransform * trans, - GstPadDirection direction, GstCaps * caps); -static gboolean gst_pixbufscale_set_caps (GstBaseTransform * trans, - GstCaps * in, GstCaps * out); -static gboolean gst_pixbufscale_get_unit_size (GstBaseTransform * trans, - GstCaps * caps, guint * size); -static void gst_pixbufscale_fixate_caps (GstBaseTransform * base, + GstPadDirection direction, GstCaps * caps, GstCaps * filter); +static gboolean gst_pixbufscale_set_info (GstVideoFilter * filter, + GstCaps * in, GstVideoInfo * in_info, GstCaps * out, + GstVideoInfo * out_info); +static GstCaps *gst_pixbufscale_fixate_caps (GstBaseTransform * base, GstPadDirection direction, GstCaps * caps, GstCaps * othercaps); -static GstFlowReturn gst_pixbufscale_transform (GstBaseTransform * trans, - GstBuffer * in, GstBuffer * out); -static gboolean gst_pixbufscale_handle_src_event (GstPad * pad, +static GstFlowReturn gst_pixbufscale_transform_frame (GstVideoFilter * filter, + GstVideoFrame * in, GstVideoFrame * out); +static gboolean gst_pixbufscale_handle_src_event (GstBaseTransform * trans, GstEvent * event); - -static gboolean parse_caps (GstCaps * caps, gint * width, gint * height); - -GST_BOILERPLATE (GstPixbufScale, gst_pixbufscale, GstBaseTransform, - GST_TYPE_BASE_TRANSFORM); +#define gst_pixbufscale_parent_class parent_class +G_DEFINE_TYPE (GstPixbufScale, gst_pixbufscale, GST_TYPE_VIDEO_FILTER); static void -gst_pixbufscale_base_init (gpointer g_class) +gst_pixbufscale_class_init (GstPixbufScaleClass * klass) { - GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); + GObjectClass *gobject_class; + GstElementClass *element_class; + GstBaseTransformClass *trans_class; + GstVideoFilterClass *filter_class; + + gobject_class = (GObjectClass *) klass; + element_class = (GstElementClass *) klass; + trans_class = (GstBaseTransformClass *) klass; + filter_class = (GstVideoFilterClass *) klass; gst_element_class_set_details_simple (element_class, "GdkPixbuf image scaler", "Filter/Effect/Video", "Resizes video", @@ -126,16 +130,6 @@ gst_pixbufscale_base_init (gpointer g_class) gst_static_pad_template_get (&gst_pixbufscale_src_template)); gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&gst_pixbufscale_sink_template)); -} - -static void -gst_pixbufscale_class_init (GstPixbufScaleClass * klass) -{ - GObjectClass *gobject_class; - GstBaseTransformClass *trans_class; - - gobject_class = (GObjectClass *) klass; - trans_class = (GstBaseTransformClass *) klass; gobject_class->set_property = gst_pixbufscale_set_property; gobject_class->get_property = gst_pixbufscale_get_property; @@ -148,26 +142,21 @@ gst_pixbufscale_class_init (GstPixbufScaleClass * klass) trans_class->transform_caps = GST_DEBUG_FUNCPTR (gst_pixbufscale_transform_caps); - trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_pixbufscale_set_caps); - trans_class->get_unit_size = - GST_DEBUG_FUNCPTR (gst_pixbufscale_get_unit_size); - trans_class->transform = GST_DEBUG_FUNCPTR (gst_pixbufscale_transform); trans_class->fixate_caps = GST_DEBUG_FUNCPTR (gst_pixbufscale_fixate_caps); + trans_class->src_event = GST_DEBUG_FUNCPTR (gst_pixbufscale_handle_src_event); trans_class->passthrough_on_same_caps = TRUE; + filter_class->set_info = GST_DEBUG_FUNCPTR (gst_pixbufscale_set_info); + filter_class->transform_frame = + GST_DEBUG_FUNCPTR (gst_pixbufscale_transform_frame); + parent_class = g_type_class_peek_parent (klass); } static void -gst_pixbufscale_init (GstPixbufScale * pixbufscale, - GstPixbufScaleClass * kclass) +gst_pixbufscale_init (GstPixbufScale * pixbufscale) { - GstBaseTransform *trans; - GST_DEBUG_OBJECT (pixbufscale, "_init"); - trans = GST_BASE_TRANSFORM (pixbufscale); - - gst_pad_set_event_function (trans->srcpad, gst_pixbufscale_handle_src_event); pixbufscale->method = GST_PIXBUFSCALE_TILES; pixbufscale->gdk_method = GDK_INTERP_TILES; @@ -227,7 +216,7 @@ gst_pixbufscale_get_property (GObject * object, guint prop_id, GValue * value, static GstCaps * gst_pixbufscale_transform_caps (GstBaseTransform * trans, - GstPadDirection direction, GstCaps * caps) + GstPadDirection direction, GstCaps * caps, GstCaps * filter) { GstCaps *ret; int i; @@ -243,76 +232,46 @@ gst_pixbufscale_transform_caps (GstBaseTransform * trans, gst_structure_remove_field (structure, "pixel-aspect-ratio"); } + if (filter) { + GstCaps *intersection; + + intersection = + gst_caps_intersect_full (filter, ret, GST_CAPS_INTERSECT_FIRST); + gst_caps_unref (ret); + ret = intersection; + } + GST_DEBUG_OBJECT (trans, "returning caps: %" GST_PTR_FORMAT, ret); return ret; } static gboolean -parse_caps (GstCaps * caps, gint * width, gint * height) +gst_pixbufscale_set_info (GstVideoFilter * filter, GstCaps * in, + GstVideoInfo * in_info, GstCaps * out, GstVideoInfo * out_info) { - gboolean ret; - GstStructure *structure; + if (in_info->width == out_info->width && in_info->height == out_info->height) { + gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (filter), TRUE); + } else { + gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (filter), FALSE); + } - structure = gst_caps_get_structure (caps, 0); - ret = gst_structure_get_int (structure, "width", width); - ret &= gst_structure_get_int (structure, "height", height); - - return ret; -} - -static gboolean -gst_pixbufscale_set_caps (GstBaseTransform * trans, GstCaps * in, GstCaps * out) -{ - GstPixbufScale *pixbufscale; - gboolean ret; - - pixbufscale = GST_PIXBUFSCALE (trans); - ret = parse_caps (in, &pixbufscale->from_width, &pixbufscale->from_height); - ret &= parse_caps (out, &pixbufscale->to_width, &pixbufscale->to_height); - if (!ret) - goto done; - - pixbufscale->from_stride = GST_ROUND_UP_4 (pixbufscale->from_width * 3); - pixbufscale->from_buf_size = - pixbufscale->from_stride * pixbufscale->from_height; - - pixbufscale->to_stride = GST_ROUND_UP_4 (pixbufscale->to_width * 3); - pixbufscale->to_buf_size = pixbufscale->to_stride * pixbufscale->to_height; - - GST_DEBUG_OBJECT (pixbufscale, "from=%dx%d, size %d -> to=%dx%d, size %d", - pixbufscale->from_width, pixbufscale->from_height, - pixbufscale->from_buf_size, pixbufscale->to_width, pixbufscale->to_height, - pixbufscale->to_buf_size); - -done: - return ret; -} - - -static gboolean -gst_pixbufscale_get_unit_size (GstBaseTransform * trans, - GstCaps * caps, guint * size) -{ - gint width, height; - - g_assert (size); - - if (!parse_caps (caps, &width, &height)) - return FALSE; - - *size = GST_ROUND_UP_4 (width * 3) * height; + GST_DEBUG_OBJECT (filter, "from=%dx%d, size %" G_GSIZE_FORMAT + " -> to=%dx%d, size %" G_GSIZE_FORMAT, + in_info->width, in_info->height, in_info->size, + out_info->width, out_info->height, out_info->size); return TRUE; } -static void +static GstCaps * gst_pixbufscale_fixate_caps (GstBaseTransform * base, GstPadDirection direction, GstCaps * caps, GstCaps * othercaps) { GstStructure *ins, *outs; const GValue *from_par, *to_par; - g_return_if_fail (gst_caps_is_fixed (caps)); + othercaps = gst_caps_make_writable (othercaps); + gst_caps_truncate (othercaps); GST_DEBUG_OBJECT (base, "trying to fixate othercaps %" GST_PTR_FORMAT " based on caps %" GST_PTR_FORMAT, othercaps, caps); @@ -337,7 +296,7 @@ gst_pixbufscale_fixate_caps (GstBaseTransform * base, GstPadDirection direction, if (count == 2) { GST_DEBUG_OBJECT (base, "dimensions already set to %dx%d, not fixating", w, h); - return; + goto done; } gst_structure_get_int (ins, "width", &from_w); @@ -396,33 +355,39 @@ gst_pixbufscale_fixate_caps (GstBaseTransform * base, GstPadDirection direction, } } +done: GST_DEBUG_OBJECT (base, "fixated othercaps to %" GST_PTR_FORMAT, othercaps); + + return othercaps; } static GstFlowReturn -gst_pixbufscale_transform (GstBaseTransform * trans, - GstBuffer * in, GstBuffer * out) +gst_pixbufscale_transform_frame (GstVideoFilter * filter, + GstVideoFrame * in, GstVideoFrame * out) { GstPixbufScale *scale; GdkPixbuf *src_pixbuf, *dest_pixbuf; - scale = GST_PIXBUFSCALE (trans); + scale = GST_PIXBUFSCALE (filter); src_pixbuf = - gdk_pixbuf_new_from_data (GST_BUFFER_DATA (in), GDK_COLORSPACE_RGB, FALSE, - 8, scale->from_width, scale->from_height, - GST_RGB24_ROWSTRIDE (scale->from_width), NULL, NULL); + gdk_pixbuf_new_from_data (GST_VIDEO_FRAME_COMP_DATA (in, 0), + GDK_COLORSPACE_RGB, FALSE, 8, GST_VIDEO_FRAME_WIDTH (in), + GST_VIDEO_FRAME_HEIGHT (in), + GST_VIDEO_FRAME_COMP_STRIDE (in, 0), NULL, NULL); dest_pixbuf = - gdk_pixbuf_new_from_data (GST_BUFFER_DATA (out), GDK_COLORSPACE_RGB, - FALSE, 8, scale->to_width, scale->to_height, - GST_RGB24_ROWSTRIDE (scale->to_width), NULL, NULL); + gdk_pixbuf_new_from_data (GST_VIDEO_FRAME_COMP_DATA (out, 0), + GDK_COLORSPACE_RGB, FALSE, 8, GST_VIDEO_FRAME_WIDTH (out), + GST_VIDEO_FRAME_HEIGHT (out), + GST_VIDEO_FRAME_COMP_STRIDE (out, 0), NULL, NULL); gdk_pixbuf_scale (src_pixbuf, dest_pixbuf, 0, 0, - scale->to_width, - scale->to_height, 0, 0, - (double) scale->to_width / scale->from_width, - (double) scale->to_height / scale->from_height, scale->gdk_method); + GST_VIDEO_FRAME_WIDTH (out), + GST_VIDEO_FRAME_HEIGHT (out), 0, 0, + (double) GST_VIDEO_FRAME_WIDTH (out) / GST_VIDEO_FRAME_WIDTH (in), + (double) GST_VIDEO_FRAME_HEIGHT (out) / GST_VIDEO_FRAME_HEIGHT (in), + scale->gdk_method); g_object_unref (src_pixbuf); g_object_unref (dest_pixbuf); @@ -431,14 +396,14 @@ gst_pixbufscale_transform (GstBaseTransform * trans, } static gboolean -gst_pixbufscale_handle_src_event (GstPad * pad, GstEvent * event) +gst_pixbufscale_handle_src_event (GstBaseTransform * trans, GstEvent * event) { GstPixbufScale *pixbufscale; gboolean ret; double a; GstStructure *structure; - pixbufscale = GST_PIXBUFSCALE (gst_pad_get_parent (pad)); + pixbufscale = GST_PIXBUFSCALE (trans); GST_DEBUG_OBJECT (pixbufscale, "handling %s event", GST_EVENT_TYPE_NAME (event)); @@ -462,9 +427,7 @@ gst_pixbufscale_handle_src_event (GstPad * pad, GstEvent * event) break; } - ret = gst_pad_event_default (pad, event); - - gst_object_unref (pixbufscale); + ret = GST_BASE_TRANSFORM_CLASS (parent_class)->src_event (trans, event); return ret; } diff --git a/ext/gdk_pixbuf/pixbufscale.h b/ext/gdk_pixbuf/pixbufscale.h index 3e40477724..0b3afcb561 100644 --- a/ext/gdk_pixbuf/pixbufscale.h +++ b/ext/gdk_pixbuf/pixbufscale.h @@ -25,6 +25,8 @@ #include #include +#include + #include G_BEGIN_DECLS @@ -52,7 +54,7 @@ typedef struct _GstPixbufScale GstPixbufScale; typedef struct _GstPixbufScaleClass GstPixbufScaleClass; struct _GstPixbufScale { - GstBaseTransform element; + GstVideoFilter element; /* video state */ gint to_width; @@ -72,7 +74,7 @@ struct _GstPixbufScale { }; struct _GstPixbufScaleClass { - GstBaseTransformClass parent_class; + GstVideoFilterClass parent_class; }; GType gst_pixbufscale_get_type(void);