gaudieffects: port chromium to GstVideoFilter

This commit is contained in:
Luis de Bethencourt 2012-05-09 15:44:02 +01:00
parent 5a4b8d8937
commit ebad8a4dbc
2 changed files with 27 additions and 49 deletions

View File

@ -67,6 +67,9 @@
#include "gstplugin.h" #include "gstplugin.h"
#include "gstchromium.h" #include "gstchromium.h"
#define gst_chromium_parent_class parent_class
G_DEFINE_TYPE (GstChromium, gst_chromium, GST_TYPE_VIDEO_FILTER);
GST_DEBUG_CATEGORY_STATIC (gst_chromium_debug); GST_DEBUG_CATEGORY_STATIC (gst_chromium_debug);
#define GST_CAT_DEFAULT gst_chromium_debug #define GST_CAT_DEFAULT gst_chromium_debug
@ -76,8 +79,6 @@ GST_DEBUG_CATEGORY_STATIC (gst_chromium_debug);
#define CAPS_STR GST_VIDEO_CAPS_MAKE ("{ xBGR, xRGB }") #define CAPS_STR GST_VIDEO_CAPS_MAKE ("{ xBGR, xRGB }")
#endif #endif
G_DEFINE_TYPE (GstChromium, gst_chromium, GST_TYPE_VIDEO_FILTER);
/* Filter signals and args. */ /* Filter signals and args. */
enum enum
{ {
@ -131,11 +132,10 @@ static void gst_chromium_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec); const GValue * value, GParamSpec * pspec);
static void gst_chromium_get_property (GObject * object, guint prop_id, static void gst_chromium_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec); GValue * value, GParamSpec * pspec);
static void gst_chromium_finalize (GObject * object);
static gboolean gst_chromium_set_caps (GstBaseTransform * btrans, static GstFlowReturn gst_chromium_transform_frame (GstVideoFilter * vfilter,
GstCaps * incaps, GstCaps * outcaps); GstVideoFrame * in_frame, GstVideoFrame * out_frame);
static GstFlowReturn gst_chromium_transform (GstBaseTransform * btrans,
GstBuffer * in_buf, GstBuffer * out_buf);
/* GObject vmethod implementations */ /* GObject vmethod implementations */
@ -145,7 +145,7 @@ gst_chromium_class_init (GstChromiumClass * klass)
{ {
GObjectClass *gobject_class = (GObjectClass *) klass; GObjectClass *gobject_class = (GObjectClass *) klass;
GstElementClass *gstelement_class = (GstElementClass *) klass; GstElementClass *gstelement_class = (GstElementClass *) klass;
GstBaseTransformClass *trans_class = (GstBaseTransformClass *) klass; GstVideoFilterClass *vfilter_class = (GstVideoFilterClass *) klass;
gst_element_class_set_details_simple (gstelement_class, "Chromium", gst_element_class_set_details_simple (gstelement_class, "Chromium",
"Filter/Effect/Video", "Filter/Effect/Video",
@ -159,6 +159,7 @@ gst_chromium_class_init (GstChromiumClass * klass)
gobject_class->set_property = gst_chromium_set_property; gobject_class->set_property = gst_chromium_set_property;
gobject_class->get_property = gst_chromium_get_property; gobject_class->get_property = gst_chromium_get_property;
gobject_class->finalize = gst_chromium_finalize;
g_object_class_install_property (gobject_class, PROP_EDGE_A, g_object_class_install_property (gobject_class, PROP_EDGE_A,
g_param_spec_uint ("edge-a", "Edge A", g_param_spec_uint ("edge-a", "Edge A",
@ -174,8 +175,8 @@ gst_chromium_class_init (GstChromiumClass * klass)
g_param_spec_boolean ("silent", "Silent", "Produce verbose output ?", g_param_spec_boolean ("silent", "Silent", "Produce verbose output ?",
FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_chromium_set_caps); vfilter_class->transform_frame =
trans_class->transform = GST_DEBUG_FUNCPTR (gst_chromium_transform); GST_DEBUG_FUNCPTR (gst_chromium_transform_frame);
} }
/* Initialize the element, /* Initialize the element,
@ -215,7 +216,6 @@ gst_chromium_set_property (GObject * object, guint prop_id,
} }
} }
static void static void
gst_chromium_get_property (GObject * object, guint prop_id, gst_chromium_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec) GValue * value, GParamSpec * pspec)
@ -240,56 +240,36 @@ gst_chromium_get_property (GObject * object, guint prop_id,
GST_OBJECT_UNLOCK (filter); GST_OBJECT_UNLOCK (filter);
} }
/* GstElement vmethod implementations */ static void
gst_chromium_finalize (GObject * object)
/* Handle the link with other elements. */
static gboolean
gst_chromium_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
GstCaps * outcaps)
{ {
GstChromium *chromium = GST_CHROMIUM (btrans); G_OBJECT_CLASS (parent_class)->finalize (object);
GstVideoInfo info;
if (!gst_video_info_from_caps (&info, incaps))
goto invalid_caps;
chromium->info = info;
chromium->width = GST_VIDEO_INFO_WIDTH (&info);
chromium->height = GST_VIDEO_INFO_HEIGHT (&info);
return TRUE;
/* ERRORS */
invalid_caps:
{
GST_DEBUG_OBJECT (btrans, "could not parse caps");
return FALSE;
}
} }
/* GstElement vmethod implementations */
/* Actual processing. */ /* Actual processing. */
static GstFlowReturn static GstFlowReturn
gst_chromium_transform (GstBaseTransform * btrans, gst_chromium_transform_frame (GstVideoFilter * vfilter,
GstBuffer * in_buf, GstBuffer * out_buf) GstVideoFrame * in_frame, GstVideoFrame * out_frame)
{ {
GstChromium *filter = GST_CHROMIUM (btrans); GstChromium *filter = GST_CHROMIUM (vfilter);
gint video_size, edge_a, edge_b; gint video_size, edge_a, edge_b, width, height;
guint32 *src, *dest; guint32 *src, *dest;
GstClockTime timestamp; GstClockTime timestamp;
gint64 stream_time; gint64 stream_time;
GstVideoFrame in_frame, out_frame;
gst_video_frame_map (&in_frame, &filter->info, in_buf, GST_MAP_READ); src = GST_VIDEO_FRAME_PLANE_DATA (in_frame, 0);
gst_video_frame_map (&out_frame, &filter->info, out_buf, GST_MAP_WRITE); dest = GST_VIDEO_FRAME_PLANE_DATA (out_frame, 0);
src = GST_VIDEO_FRAME_PLANE_DATA (&in_frame, 0); width = GST_VIDEO_FRAME_WIDTH (in_frame);
dest = GST_VIDEO_FRAME_PLANE_DATA (&out_frame, 0); height = GST_VIDEO_FRAME_HEIGHT (in_frame);
/* GstController: update the properties */ /* GstController: update the properties */
timestamp = GST_BUFFER_TIMESTAMP (in_buf); timestamp = GST_BUFFER_TIMESTAMP (in_frame->buffer);
stream_time = stream_time =
gst_segment_to_stream_time (&btrans->segment, GST_FORMAT_TIME, timestamp); gst_segment_to_stream_time (&GST_BASE_TRANSFORM (filter)->segment,
GST_FORMAT_TIME, timestamp);
GST_DEBUG_OBJECT (filter, "sync to %" GST_TIME_FORMAT, GST_DEBUG_OBJECT (filter, "sync to %" GST_TIME_FORMAT,
GST_TIME_ARGS (timestamp)); GST_TIME_ARGS (timestamp));
@ -302,7 +282,7 @@ gst_chromium_transform (GstBaseTransform * btrans,
edge_b = filter->edge_b; edge_b = filter->edge_b;
GST_OBJECT_UNLOCK (filter); GST_OBJECT_UNLOCK (filter);
video_size = filter->width * filter->height; video_size = width * height;
transform (src, dest, video_size, edge_a, edge_b); transform (src, dest, video_size, edge_a, edge_b);
return GST_FLOW_OK; return GST_FLOW_OK;

View File

@ -68,10 +68,8 @@ typedef struct GstChromiumClass GstChromiumClass;
struct GstChromium struct GstChromium
{ {
GstVideoFilter videofilter; GstVideoFilter videofilter;
gint width, height;
/* < private > */ /* < private > */
GstVideoInfo info;
gint edge_a, edge_b; gint edge_a, edge_b;
gboolean silent; gboolean silent;
}; };