diff --git a/gst/effectv/gstop.c b/gst/effectv/gstop.c index de798dc89b..e3a6b2e829 100644 --- a/gst/effectv/gstop.c +++ b/gst/effectv/gstop.c @@ -34,7 +34,7 @@ * * Example launch line * |[ - * gst-launch -v videotestsrc ! optv ! ffmpegcolorspace ! autovideosink + * gst-launch -v videotestsrc ! optv ! videoconvert ! autovideosink * ]| This pipeline shows the effect of optv on a test stream. * */ @@ -95,12 +95,13 @@ enum static guint32 palette[256]; -GST_BOILERPLATE (GstOpTV, gst_optv, GstVideoFilter, GST_TYPE_VIDEO_FILTER); +#define gst_optv_parent_class parent_class +G_DEFINE_TYPE (GstOpTV, gst_optv, GST_TYPE_VIDEO_FILTER); #if G_BYTE_ORDER == G_LITTLE_ENDIAN -#define CAPS_STR GST_VIDEO_CAPS_BGRx ";" GST_VIDEO_CAPS_RGBx +#define CAPS_STR GST_VIDEO_CAPS_MAKE ("{ BGRx, RGBx }") #else -#define CAPS_STR GST_VIDEO_CAPS_xBGR ";" GST_VIDEO_CAPS_xRGB +#define CAPS_STR GST_VIDEO_CAPS_MAKE ("{ xBGR, xRGB }") #endif static GstStaticPadTemplate gst_optv_src_template = @@ -203,7 +204,7 @@ gst_optv_transform (GstBaseTransform * trans, GstBuffer * in, GstBuffer * out) { GstOpTV *filter = GST_OPTV (trans); guint32 *src, *dest; - GstFlowReturn ret = GST_FLOW_OK; + GstVideoFrame in_frame, out_frame; gint8 *p; guint8 *diff; gint x, y, width, height; @@ -220,12 +221,21 @@ gst_optv_transform (GstBaseTransform * trans, GstBuffer * in, GstBuffer * out) if (GST_CLOCK_TIME_IS_VALID (stream_time)) gst_object_sync_values (G_OBJECT (filter), stream_time); - src = (guint32 *) GST_BUFFER_DATA (in); - dest = (guint32 *) GST_BUFFER_DATA (out); - if (G_UNLIKELY (filter->opmap[0] == NULL)) return GST_FLOW_NOT_NEGOTIATED; + if (!gst_video_frame_map (&in_frame, &filter->info, in, GST_MAP_READ)) + goto invalid_in; + + if (!gst_video_frame_map (&out_frame, &filter->info, out, GST_MAP_WRITE)) + goto invalid_out; + + src = GST_VIDEO_FRAME_PLANE_DATA (&in_frame, 0); + dest = GST_VIDEO_FRAME_PLANE_DATA (&out_frame, 0); + + width = GST_VIDEO_FRAME_WIDTH (&in_frame); + height = GST_VIDEO_FRAME_HEIGHT (&in_frame); + GST_OBJECT_LOCK (filter); switch (filter->mode) { default: @@ -246,9 +256,7 @@ gst_optv_transform (GstBaseTransform * trans, GstBuffer * in, GstBuffer * out) filter->phase -= filter->speed; diff = filter->diff; - image_y_over (src, diff, filter->threshold, filter->width * filter->height); - height = filter->height; - width = filter->width; + image_y_over (src, diff, filter->threshold, width * height); phase = filter->phase; for (y = 0; y < height; y++) { @@ -259,7 +267,23 @@ gst_optv_transform (GstBaseTransform * trans, GstBuffer * in, GstBuffer * out) } GST_OBJECT_UNLOCK (filter); - return ret; + gst_video_frame_unmap (&in_frame); + gst_video_frame_unmap (&out_frame); + + return GST_FLOW_OK; + + /* ERRORS */ +invalid_in: + { + GST_DEBUG_OBJECT (filter, "invalid input frame"); + return GST_FLOW_ERROR; + } +invalid_out: + { + GST_DEBUG_OBJECT (filter, "invalid output frame"); + gst_video_frame_unmap (&in_frame); + return GST_FLOW_ERROR; + } } static gboolean @@ -267,32 +291,36 @@ gst_optv_set_caps (GstBaseTransform * btrans, GstCaps * incaps, GstCaps * outcaps) { GstOpTV *filter = GST_OPTV (btrans); - GstStructure *structure; - gboolean ret = FALSE; + GstVideoInfo info; + gint i, width, height; - structure = gst_caps_get_structure (incaps, 0); + if (!gst_video_info_from_caps (&info, incaps)) + goto invalid_caps; - GST_OBJECT_LOCK (filter); - if (gst_structure_get_int (structure, "width", &filter->width) && - gst_structure_get_int (structure, "height", &filter->height)) { - gint i; + filter->info = info; - for (i = 0; i < 4; i++) { - if (filter->opmap[i]) - g_free (filter->opmap[i]); - filter->opmap[i] = g_new (gint8, filter->width * filter->height); - } - setOpmap (filter->opmap, filter->width, filter->height); + width = GST_VIDEO_INFO_WIDTH (&info); + height = GST_VIDEO_INFO_HEIGHT (&info); - if (filter->diff) - g_free (filter->diff); - filter->diff = g_new (guint8, filter->width * filter->height); - - ret = TRUE; + for (i = 0; i < 4; i++) { + if (filter->opmap[i]) + g_free (filter->opmap[i]); + filter->opmap[i] = g_new (gint8, width * height); } - GST_OBJECT_UNLOCK (filter); + setOpmap (filter->opmap, width, height); - return ret; + if (filter->diff) + g_free (filter->diff); + filter->diff = g_new (guint8, width * height); + + return TRUE; + + /* ERRORS */ +invalid_caps: + { + GST_DEBUG_OBJECT (filter, "invalid caps received"); + return FALSE; + } } static gboolean @@ -373,27 +401,11 @@ gst_optv_get_property (GObject * object, guint prop_id, GValue * value, } } -static void -gst_optv_base_init (gpointer g_class) -{ - GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - - gst_element_class_set_details_simple (element_class, "OpTV effect", - "Filter/Effect/Video", - "Optical art meets real-time video effect", - "FUKUCHI, Kentarou , " - "Sebastian Dröge "); - - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&gst_optv_sink_template)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&gst_optv_src_template)); -} - static void gst_optv_class_init (GstOpTVClass * klass) { GObjectClass *gobject_class = (GObjectClass *) klass; + GstElementClass *gstelement_class = (GstElementClass *) klass; GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass; gobject_class->set_property = gst_optv_set_property; @@ -416,6 +428,17 @@ gst_optv_class_init (GstOpTVClass * klass) "Luma threshold", 0, G_MAXINT, DEFAULT_THRESHOLD, GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + gst_element_class_set_details_simple (gstelement_class, "OpTV effect", + "Filter/Effect/Video", + "Optical art meets real-time video effect", + "FUKUCHI, Kentarou , " + "Sebastian Dröge "); + + gst_element_class_add_pad_template (gstelement_class, + gst_static_pad_template_get (&gst_optv_sink_template)); + gst_element_class_add_pad_template (gstelement_class, + gst_static_pad_template_get (&gst_optv_src_template)); + trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_optv_set_caps); trans_class->transform = GST_DEBUG_FUNCPTR (gst_optv_transform); trans_class->start = GST_DEBUG_FUNCPTR (gst_optv_start); @@ -424,7 +447,7 @@ gst_optv_class_init (GstOpTVClass * klass) } static void -gst_optv_init (GstOpTV * filter, GstOpTVClass * klass) +gst_optv_init (GstOpTV * filter) { filter->speed = DEFAULT_SPEED; filter->mode = DEFAULT_MODE; diff --git a/gst/effectv/gstop.h b/gst/effectv/gstop.h index e79460302a..d5e0fec85c 100644 --- a/gst/effectv/gstop.h +++ b/gst/effectv/gstop.h @@ -29,6 +29,7 @@ #include +#include #include G_BEGIN_DECLS @@ -52,7 +53,7 @@ struct _GstOpTV GstVideoFilter element; /* < private > */ - gint width, height; + GstVideoInfo info; gint mode; gint speed;