effectv: port radioactv to 0.11

This commit is contained in:
Wim Taymans 2011-07-07 17:40:22 +02:00
parent 99c45328b7
commit b8c426564f
2 changed files with 100 additions and 73 deletions

View file

@ -55,7 +55,6 @@
#include "gstradioac.h" #include "gstradioac.h"
#include "gsteffectv.h" #include "gsteffectv.h"
#include <gst/video/video.h>
#include <gst/controller/gstcontroller.h> #include <gst/controller/gstcontroller.h>
enum enum
@ -135,13 +134,13 @@ enum
static guint32 palettes[COLORS * PATTERN]; static guint32 palettes[COLORS * PATTERN];
GST_BOILERPLATE (GstRadioacTV, gst_radioactv, GstVideoFilter, #define gst_radioactv_parent_class parent_class
GST_TYPE_VIDEO_FILTER); G_DEFINE_TYPE (GstRadioacTV, gst_radioactv, GST_TYPE_VIDEO_FILTER);
#if G_BYTE_ORDER == G_LITTLE_ENDIAN #if G_BYTE_ORDER == G_LITTLE_ENDIAN
#define CAPS_STR GST_VIDEO_CAPS_RGBx #define CAPS_STR GST_VIDEO_CAPS_MAKE ("RGBx")
#else #else
#define CAPS_STR GST_VIDEO_CAPS_xBGR #define CAPS_STR GST_VIDEO_CAPS_MAKE ("xBGR")
#endif #endif
static GstStaticPadTemplate gst_radioactv_src_template = static GstStaticPadTemplate gst_radioactv_src_template =
@ -235,7 +234,7 @@ blur (GstRadioacTV * filter)
guint8 v; guint8 v;
width = filter->buf_width; width = filter->buf_width;
p = filter->blurzoombuf + filter->width + 1; p = filter->blurzoombuf + GST_VIDEO_INFO_WIDTH (&filter->info) + 1;
q = p + filter->buf_area; q = p + filter->buf_area;
for (y = filter->buf_height - 2; y > 0; y--) { for (y = filter->buf_height - 2; y > 0; y--) {
@ -320,9 +319,9 @@ gst_radioactv_transform (GstBaseTransform * trans, GstBuffer * in,
{ {
GstRadioacTV *filter = GST_RADIOACTV (trans); GstRadioacTV *filter = GST_RADIOACTV (trans);
guint32 *src, *dest; guint32 *src, *dest;
GstFlowReturn ret = GST_FLOW_OK; GstVideoFrame in_frame, out_frame;
GstClockTime timestamp, stream_time; GstClockTime timestamp, stream_time;
gint x, y; gint x, y, width, height;
guint32 a, b; guint32 a, b;
guint8 *diff, *p; guint8 *diff, *p;
guint32 *palette; guint32 *palette;
@ -337,8 +336,17 @@ gst_radioactv_transform (GstBaseTransform * trans, GstBuffer * in,
if (GST_CLOCK_TIME_IS_VALID (stream_time)) if (GST_CLOCK_TIME_IS_VALID (stream_time))
gst_object_sync_values (G_OBJECT (filter), stream_time); gst_object_sync_values (G_OBJECT (filter), stream_time);
src = (guint32 *) GST_BUFFER_DATA (in); if (!gst_video_frame_map (&in_frame, &filter->info, in, GST_MAP_READ))
dest = (guint32 *) GST_BUFFER_DATA (out); 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); GST_OBJECT_LOCK (filter);
palette = &palettes[COLORS * filter->color]; palette = &palettes[COLORS * filter->color];
@ -351,7 +359,7 @@ gst_radioactv_transform (GstBaseTransform * trans, GstBuffer * in,
if (filter->mode != 2 || filter->snaptime <= 0) { if (filter->mode != 2 || filter->snaptime <= 0) {
image_bgsubtract_update_y (src, filter->background, diff, image_bgsubtract_update_y (src, filter->background, diff,
filter->width * filter->height, MAGIC_THRESHOLD * 7); width * height, MAGIC_THRESHOLD * 7);
if (filter->mode == 0 || filter->snaptime <= 0) { if (filter->mode == 0 || filter->snaptime <= 0) {
diff += filter->buf_margin_left; diff += filter->buf_margin_left;
p = filter->blurzoombuf; p = filter->blurzoombuf;
@ -359,11 +367,11 @@ gst_radioactv_transform (GstBaseTransform * trans, GstBuffer * in,
for (x = 0; x < filter->buf_width; x++) { for (x = 0; x < filter->buf_width; x++) {
p[x] |= diff[x] >> 3; p[x] |= diff[x] >> 3;
} }
diff += filter->width; diff += width;
p += filter->buf_width; p += filter->buf_width;
} }
if (filter->mode == 1 || filter->mode == 2) { if (filter->mode == 1 || filter->mode == 2) {
memcpy (filter->snapframe, src, filter->width * filter->height * 4); memcpy (filter->snapframe, src, width * height * 4);
} }
} }
} }
@ -373,7 +381,7 @@ gst_radioactv_transform (GstBaseTransform * trans, GstBuffer * in,
src = filter->snapframe; src = filter->snapframe;
} }
p = filter->blurzoombuf; p = filter->blurzoombuf;
for (y = 0; y < filter->height; y++) { for (y = 0; y < height; y++) {
for (x = 0; x < filter->buf_margin_left; x++) { for (x = 0; x < filter->buf_margin_left; x++) {
*dest++ = *src++; *dest++ = *src++;
} }
@ -397,7 +405,20 @@ gst_radioactv_transform (GstBaseTransform * trans, GstBuffer * in,
} }
GST_OBJECT_UNLOCK (filter); GST_OBJECT_UNLOCK (filter);
return ret; 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 static gboolean
@ -405,57 +426,67 @@ gst_radioactv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
GstCaps * outcaps) GstCaps * outcaps)
{ {
GstRadioacTV *filter = GST_RADIOACTV (btrans); GstRadioacTV *filter = GST_RADIOACTV (btrans);
GstStructure *structure; GstVideoInfo info;
gboolean ret = FALSE; gint width, height;
structure = gst_caps_get_structure (incaps, 0); if (!gst_video_info_from_caps (&info, incaps))
goto invalid_caps;
GST_OBJECT_LOCK (filter); filter->info = info;
if (gst_structure_get_int (structure, "width", &filter->width) &&
gst_structure_get_int (structure, "height", &filter->height)) {
filter->buf_width_blocks = filter->width / 32;
if (filter->buf_width_blocks > 255)
goto out;
filter->buf_width = filter->buf_width_blocks * 32; width = GST_VIDEO_INFO_WIDTH (&info);
filter->buf_height = filter->height; height = GST_VIDEO_INFO_HEIGHT (&info);
filter->buf_area = filter->buf_height * filter->buf_width;
filter->buf_margin_left = (filter->width - filter->buf_width) / 2;
filter->buf_margin_right =
filter->height - filter->buf_width - filter->buf_margin_left;
if (filter->blurzoombuf) filter->buf_width_blocks = width / 32;
g_free (filter->blurzoombuf); if (filter->buf_width_blocks > 255)
filter->blurzoombuf = g_new0 (guint8, filter->buf_area * 2); goto too_wide;
if (filter->blurzoomx) filter->buf_width = filter->buf_width_blocks * 32;
g_free (filter->blurzoomx); filter->buf_height = height;
filter->blurzoomx = g_new0 (gint, filter->buf_width); filter->buf_area = filter->buf_height * filter->buf_width;
filter->buf_margin_left = (width - filter->buf_width) / 2;
filter->buf_margin_right =
height - filter->buf_width - filter->buf_margin_left;
if (filter->blurzoomy) if (filter->blurzoombuf)
g_free (filter->blurzoomy); g_free (filter->blurzoombuf);
filter->blurzoomy = g_new0 (gint, filter->buf_height); filter->blurzoombuf = g_new0 (guint8, filter->buf_area * 2);
if (filter->snapframe) if (filter->blurzoomx)
g_free (filter->snapframe); g_free (filter->blurzoomx);
filter->snapframe = g_new (guint32, filter->width * filter->height); filter->blurzoomx = g_new0 (gint, filter->buf_width);
if (filter->diff) if (filter->blurzoomy)
g_free (filter->diff); g_free (filter->blurzoomy);
filter->diff = g_new (guint8, filter->width * filter->height); filter->blurzoomy = g_new0 (gint, filter->buf_height);
if (filter->background) if (filter->snapframe)
g_free (filter->background); g_free (filter->snapframe);
filter->background = g_new0 (gint16, filter->width * filter->height); filter->snapframe = g_new (guint32, width * height);
setTable (filter); if (filter->diff)
g_free (filter->diff);
filter->diff = g_new (guint8, width * height);
ret = TRUE; if (filter->background)
g_free (filter->background);
filter->background = g_new0 (gint16, width * height);
setTable (filter);
return TRUE;
/* ERRORS */
invalid_caps:
{
GST_DEBUG_OBJECT (filter, "invalid caps received");
return FALSE;
}
too_wide:
{
GST_DEBUG_OBJECT (filter, "frame too wide");
return FALSE;
} }
out:
GST_OBJECT_UNLOCK (filter);
return ret;
} }
static gboolean static gboolean
@ -554,27 +585,11 @@ gst_radioactv_get_property (GObject * object, guint prop_id,
} }
} }
static void
gst_radioactv_base_init (gpointer g_class)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_set_details_simple (element_class, "RadioacTV effect",
"Filter/Effect/Video",
"motion-enlightment effect",
"FUKUCHI, Kentarou <fukuchi@users.sourceforge.net>, "
"Sebastian Dröge <sebastian.droege@collabora.co.uk>");
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_radioactv_sink_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_radioactv_src_template));
}
static void static void
gst_radioactv_class_init (GstRadioacTVClass * klass) gst_radioactv_class_init (GstRadioacTVClass * klass)
{ {
GObjectClass *gobject_class = (GObjectClass *) klass; GObjectClass *gobject_class = (GObjectClass *) klass;
GstElementClass *gstelement_class = (GstElementClass *) klass;
GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass; GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass;
gobject_class->set_property = gst_radioactv_set_property; gobject_class->set_property = gst_radioactv_set_property;
@ -602,6 +617,17 @@ gst_radioactv_class_init (GstRadioacTVClass * klass)
"Trigger (in trigger mode)", DEFAULT_TRIGGER, "Trigger (in trigger mode)", DEFAULT_TRIGGER,
GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); GST_PARAM_CONTROLLABLE | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
gst_element_class_set_details_simple (gstelement_class, "RadioacTV effect",
"Filter/Effect/Video",
"motion-enlightment effect",
"FUKUCHI, Kentarou <fukuchi@users.sourceforge.net>, "
"Sebastian Dröge <sebastian.droege@collabora.co.uk>");
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_radioactv_sink_template));
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&gst_radioactv_src_template));
trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_radioactv_set_caps); trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_radioactv_set_caps);
trans_class->transform = GST_DEBUG_FUNCPTR (gst_radioactv_transform); trans_class->transform = GST_DEBUG_FUNCPTR (gst_radioactv_transform);
trans_class->start = GST_DEBUG_FUNCPTR (gst_radioactv_start); trans_class->start = GST_DEBUG_FUNCPTR (gst_radioactv_start);
@ -610,7 +636,7 @@ gst_radioactv_class_init (GstRadioacTVClass * klass)
} }
static void static void
gst_radioactv_init (GstRadioacTV * filter, GstRadioacTVClass * klass) gst_radioactv_init (GstRadioacTV * filter)
{ {
filter->mode = DEFAULT_MODE; filter->mode = DEFAULT_MODE;
filter->color = DEFAULT_COLOR; filter->color = DEFAULT_COLOR;

View file

@ -29,6 +29,7 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/video/gstvideofilter.h> #include <gst/video/gstvideofilter.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -52,7 +53,7 @@ struct _GstRadioacTV
GstVideoFilter element; GstVideoFilter element;
/* < private > */ /* < private > */
gint width, height; GstVideoInfo info;
gint mode; gint mode;
gint color; gint color;