mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 07:58:51 +00:00
effectv: port vertigotv to 0.11
This commit is contained in:
parent
39f689dc97
commit
577f689f7e
2 changed files with 73 additions and 50 deletions
|
@ -43,11 +43,10 @@
|
||||||
|
|
||||||
#include "gstvertigo.h"
|
#include "gstvertigo.h"
|
||||||
|
|
||||||
#include <gst/video/video.h>
|
|
||||||
#include <gst/controller/gstcontroller.h>
|
#include <gst/controller/gstcontroller.h>
|
||||||
|
|
||||||
GST_BOILERPLATE (GstVertigoTV, gst_vertigotv, GstVideoFilter,
|
#define gst_vertigotv_parent_class parent_class
|
||||||
GST_TYPE_VIDEO_FILTER);
|
G_DEFINE_TYPE (GstVertigoTV, gst_vertigotv, GST_TYPE_VIDEO_FILTER);
|
||||||
|
|
||||||
/* Filter signals and args */
|
/* Filter signals and args */
|
||||||
enum
|
enum
|
||||||
|
@ -58,9 +57,9 @@ enum
|
||||||
};
|
};
|
||||||
|
|
||||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||||
#define CAPS_STR GST_VIDEO_CAPS_RGBx ";" GST_VIDEO_CAPS_BGRx
|
#define CAPS_STR GST_VIDEO_CAPS_MAKE ("{ RGBx, BGRx }")
|
||||||
#else
|
#else
|
||||||
#define CAPS_STR GST_VIDEO_CAPS_xRGB ";" GST_VIDEO_CAPS_xBGR
|
#define CAPS_STR GST_VIDEO_CAPS_MAKE ("{ xRGB, xBGR }")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static GstStaticPadTemplate gst_vertigotv_src_template =
|
static GstStaticPadTemplate gst_vertigotv_src_template =
|
||||||
|
@ -82,28 +81,34 @@ gst_vertigotv_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
|
||||||
GstCaps * outcaps)
|
GstCaps * outcaps)
|
||||||
{
|
{
|
||||||
GstVertigoTV *filter = GST_VERTIGOTV (btrans);
|
GstVertigoTV *filter = GST_VERTIGOTV (btrans);
|
||||||
GstStructure *structure;
|
GstVideoInfo info;
|
||||||
gboolean ret = FALSE;
|
gint area, 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)) {
|
|
||||||
gint area = filter->width * filter->height;
|
|
||||||
|
|
||||||
g_free (filter->buffer);
|
width = GST_VIDEO_INFO_WIDTH (&info);
|
||||||
filter->buffer = (guint32 *) g_malloc0 (area * 2 * sizeof (guint32));
|
height = GST_VIDEO_INFO_HEIGHT (&info);
|
||||||
|
|
||||||
filter->current_buffer = filter->buffer;
|
area = width * height;
|
||||||
filter->alt_buffer = filter->buffer + area;
|
|
||||||
filter->phase = 0;
|
|
||||||
|
|
||||||
ret = TRUE;
|
g_free (filter->buffer);
|
||||||
|
filter->buffer = (guint32 *) g_malloc0 (area * 2 * sizeof (guint32));
|
||||||
|
|
||||||
|
filter->current_buffer = filter->buffer;
|
||||||
|
filter->alt_buffer = filter->buffer + area;
|
||||||
|
filter->phase = 0;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
/* ERRORS */
|
||||||
|
invalid_caps:
|
||||||
|
{
|
||||||
|
GST_DEBUG_OBJECT (filter, "invalid caps received");
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
GST_OBJECT_UNLOCK (filter);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -113,15 +118,19 @@ gst_vertigotv_set_parms (GstVertigoTV * filter)
|
||||||
double t;
|
double t;
|
||||||
double x, y;
|
double x, y;
|
||||||
double dizz;
|
double dizz;
|
||||||
|
gint width, height;
|
||||||
|
|
||||||
dizz = sin (filter->phase) * 10 + sin (filter->phase * 1.9 + 5) * 5;
|
dizz = sin (filter->phase) * 10 + sin (filter->phase * 1.9 + 5) * 5;
|
||||||
|
|
||||||
x = filter->width / 2;
|
width = GST_VIDEO_INFO_WIDTH (&filter->info);
|
||||||
y = filter->height / 2;
|
height = GST_VIDEO_INFO_HEIGHT (&filter->info);
|
||||||
|
|
||||||
|
x = width / 2;
|
||||||
|
y = height / 2;
|
||||||
|
|
||||||
t = (x * x + y * y) * filter->zoomrate;
|
t = (x * x + y * y) * filter->zoomrate;
|
||||||
|
|
||||||
if (filter->width > filter->height) {
|
if (width > height) {
|
||||||
if (dizz >= 0) {
|
if (dizz >= 0) {
|
||||||
if (dizz > x)
|
if (dizz > x)
|
||||||
dizz = x;
|
dizz = x;
|
||||||
|
@ -162,8 +171,8 @@ gst_vertigotv_transform (GstBaseTransform * trans, GstBuffer * in,
|
||||||
guint32 *src, *dest, *p;
|
guint32 *src, *dest, *p;
|
||||||
guint32 v;
|
guint32 v;
|
||||||
gint x, y, ox, oy, i, width, height, area;
|
gint x, y, ox, oy, i, width, height, area;
|
||||||
GstFlowReturn ret = GST_FLOW_OK;
|
|
||||||
GstClockTime timestamp, stream_time;
|
GstClockTime timestamp, stream_time;
|
||||||
|
GstVideoFrame in_frame, out_frame;
|
||||||
|
|
||||||
timestamp = GST_BUFFER_TIMESTAMP (in);
|
timestamp = GST_BUFFER_TIMESTAMP (in);
|
||||||
stream_time =
|
stream_time =
|
||||||
|
@ -175,13 +184,18 @@ gst_vertigotv_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;
|
||||||
|
|
||||||
GST_OBJECT_LOCK (filter);
|
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 (&in_frame, 0);
|
||||||
|
|
||||||
|
width = GST_VIDEO_FRAME_WIDTH (&in_frame);
|
||||||
|
height = GST_VIDEO_FRAME_HEIGHT (&in_frame);
|
||||||
|
|
||||||
width = filter->width;
|
|
||||||
height = filter->height;
|
|
||||||
area = width * height;
|
area = width * height;
|
||||||
|
|
||||||
gst_vertigotv_set_parms (filter);
|
gst_vertigotv_set_parms (filter);
|
||||||
|
@ -214,9 +228,22 @@ gst_vertigotv_transform (GstBaseTransform * trans, GstBuffer * in,
|
||||||
p = filter->current_buffer;
|
p = filter->current_buffer;
|
||||||
filter->current_buffer = filter->alt_buffer;
|
filter->current_buffer = filter->alt_buffer;
|
||||||
filter->alt_buffer = p;
|
filter->alt_buffer = p;
|
||||||
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
|
||||||
|
@ -279,26 +306,11 @@ gst_vertigotv_finalize (GObject * object)
|
||||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
gst_vertigotv_base_init (gpointer g_class)
|
|
||||||
{
|
|
||||||
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
||||||
|
|
||||||
gst_element_class_set_details_simple (element_class, "VertigoTV effect",
|
|
||||||
"Filter/Effect/Video",
|
|
||||||
"A loopback alpha blending effector with rotating and scaling",
|
|
||||||
"Wim Taymans <wim.taymans@chello.be>");
|
|
||||||
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
|
||||||
gst_static_pad_template_get (&gst_vertigotv_sink_template));
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
|
||||||
gst_static_pad_template_get (&gst_vertigotv_src_template));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_vertigotv_class_init (GstVertigoTVClass * klass)
|
gst_vertigotv_class_init (GstVertigoTVClass * 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_vertigotv_set_property;
|
gobject_class->set_property = gst_vertigotv_set_property;
|
||||||
|
@ -313,13 +325,23 @@ gst_vertigotv_class_init (GstVertigoTVClass * klass)
|
||||||
"Control the rate of zooming", 1.01, 1.1, 1.01,
|
"Control the rate of zooming", 1.01, 1.1, 1.01,
|
||||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
|
gst_element_class_set_details_simple (gstelement_class, "VertigoTV effect",
|
||||||
|
"Filter/Effect/Video",
|
||||||
|
"A loopback alpha blending effector with rotating and scaling",
|
||||||
|
"Wim Taymans <wim.taymans@gmail.be>");
|
||||||
|
|
||||||
|
gst_element_class_add_pad_template (gstelement_class,
|
||||||
|
gst_static_pad_template_get (&gst_vertigotv_sink_template));
|
||||||
|
gst_element_class_add_pad_template (gstelement_class,
|
||||||
|
gst_static_pad_template_get (&gst_vertigotv_src_template));
|
||||||
|
|
||||||
trans_class->start = GST_DEBUG_FUNCPTR (gst_vertigotv_start);
|
trans_class->start = GST_DEBUG_FUNCPTR (gst_vertigotv_start);
|
||||||
trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_vertigotv_set_caps);
|
trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_vertigotv_set_caps);
|
||||||
trans_class->transform = GST_DEBUG_FUNCPTR (gst_vertigotv_transform);
|
trans_class->transform = GST_DEBUG_FUNCPTR (gst_vertigotv_transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_vertigotv_init (GstVertigoTV * filter, GstVertigoTVClass * klass)
|
gst_vertigotv_init (GstVertigoTV * filter)
|
||||||
{
|
{
|
||||||
filter->buffer = NULL;
|
filter->buffer = NULL;
|
||||||
filter->phase = 0.0;
|
filter->phase = 0.0;
|
||||||
|
|
|
@ -26,6 +26,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
|
||||||
|
@ -49,8 +50,8 @@ struct _GstVertigoTV
|
||||||
GstVideoFilter videofilter;
|
GstVideoFilter videofilter;
|
||||||
|
|
||||||
/* < private > */
|
/* < private > */
|
||||||
|
GstVideoInfo info;
|
||||||
|
|
||||||
gint width, height;
|
|
||||||
guint32 *buffer;
|
guint32 *buffer;
|
||||||
guint32 *current_buffer, *alt_buffer;
|
guint32 *current_buffer, *alt_buffer;
|
||||||
gint dx, dy;
|
gint dx, dy;
|
||||||
|
|
Loading…
Reference in a new issue