mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-06 23:48:53 +00:00
videofiltersbad: port to 1.0
This commit is contained in:
parent
13ac73bef4
commit
83862968a3
8 changed files with 231 additions and 566 deletions
|
@ -321,7 +321,7 @@ GST_PLUGINS_NONPORTED=" aiff \
|
||||||
kate librfb \
|
kate librfb \
|
||||||
mve mythtv nsf nuvdemux \
|
mve mythtv nsf nuvdemux \
|
||||||
patchdetect real \
|
patchdetect real \
|
||||||
sdi stereo tta videofilters \
|
sdi stereo tta \
|
||||||
videomeasure videosignal vmnc \
|
videomeasure videosignal vmnc \
|
||||||
linsys vcd \
|
linsys vcd \
|
||||||
apexsink cdaudio dc1394 dirac directfb \
|
apexsink cdaudio dc1394 dirac directfb \
|
||||||
|
|
|
@ -4,8 +4,6 @@ plugin_LTLIBRARIES = libgstvideofiltersbad.la
|
||||||
#include $(top_srcdir)/common/orc.mak
|
#include $(top_srcdir)/common/orc.mak
|
||||||
|
|
||||||
libgstvideofiltersbad_la_SOURCES = \
|
libgstvideofiltersbad_la_SOURCES = \
|
||||||
gstvideofilter2.c \
|
|
||||||
gstvideofilter2.h \
|
|
||||||
gstzebrastripe.c \
|
gstzebrastripe.c \
|
||||||
gstscenechange.c \
|
gstscenechange.c \
|
||||||
gstvideofiltersbad.c
|
gstvideofiltersbad.c
|
||||||
|
|
|
@ -78,11 +78,10 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
#include <gst/base/gstbasetransform.h>
|
|
||||||
#include <gst/video/video.h>
|
#include <gst/video/video.h>
|
||||||
#include "gstvideofilter2.h"
|
#include <gst/video/gstvideofilter.h>
|
||||||
#include "gstscenechange.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "gstscenechange.h"
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_STATIC (gst_scene_change_debug_category);
|
GST_DEBUG_CATEGORY_STATIC (gst_scene_change_debug_category);
|
||||||
#define GST_CAT_DEFAULT gst_scene_change_debug_category
|
#define GST_CAT_DEFAULT gst_scene_change_debug_category
|
||||||
|
@ -97,12 +96,11 @@ static void gst_scene_change_get_property (GObject * object,
|
||||||
static void gst_scene_change_dispose (GObject * object);
|
static void gst_scene_change_dispose (GObject * object);
|
||||||
static void gst_scene_change_finalize (GObject * object);
|
static void gst_scene_change_finalize (GObject * object);
|
||||||
|
|
||||||
static gboolean gst_scene_change_start (GstBaseTransform * trans);
|
static gboolean gst_scene_change_set_info (GstVideoFilter * filter,
|
||||||
static gboolean gst_scene_change_stop (GstBaseTransform * trans);
|
GstCaps * incaps, GstVideoInfo * in_info, GstCaps * outcaps,
|
||||||
static GstFlowReturn
|
GstVideoInfo * out_info);
|
||||||
gst_scene_change_prefilter (GstVideoFilter2 * videofilter2, GstBuffer * buf);
|
static GstFlowReturn gst_scene_change_transform_frame_ip (GstVideoFilter *
|
||||||
|
filter, GstVideoFrame * frame);
|
||||||
static GstVideoFilter2Functions gst_scene_change_filter_functions[];
|
|
||||||
|
|
||||||
#undef TESTING
|
#undef TESTING
|
||||||
#ifdef TESTING
|
#ifdef TESTING
|
||||||
|
@ -114,54 +112,46 @@ enum
|
||||||
PROP_0
|
PROP_0
|
||||||
};
|
};
|
||||||
|
|
||||||
/* pad templates */
|
#define VIDEO_CAPS \
|
||||||
|
GST_VIDEO_CAPS_MAKE("{ I420, Y42B, Y41B, Y444 }")
|
||||||
|
|
||||||
/* class initialization */
|
/* class initialization */
|
||||||
|
|
||||||
#define DEBUG_INIT(bla) \
|
G_DEFINE_TYPE_WITH_CODE (GstSceneChange, gst_scene_change,
|
||||||
GST_DEBUG_CATEGORY_INIT (gst_scene_change_debug_category, "scenechange", 0, \
|
GST_TYPE_VIDEO_FILTER,
|
||||||
"debug category for scenechange element");
|
GST_DEBUG_CATEGORY_INIT (gst_scene_change_debug_category, "scenechange", 0,
|
||||||
|
"debug category for scenechange element"));
|
||||||
GST_BOILERPLATE_FULL (GstSceneChange, gst_scene_change, GstVideoFilter2,
|
|
||||||
GST_TYPE_VIDEO_FILTER2, DEBUG_INIT);
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_scene_change_base_init (gpointer g_class)
|
|
||||||
{
|
|
||||||
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
||||||
|
|
||||||
|
|
||||||
gst_element_class_set_static_metadata (element_class, "Scene change detector",
|
|
||||||
"Video/Filter", "Detects scene changes in video",
|
|
||||||
"David Schleef <ds@entropywave.com>");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_scene_change_class_init (GstSceneChangeClass * klass)
|
gst_scene_change_class_init (GstSceneChangeClass * klass)
|
||||||
{
|
{
|
||||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||||
GstBaseTransformClass *base_transform_class =
|
GstVideoFilterClass *video_filter_class = GST_VIDEO_FILTER_CLASS (klass);
|
||||||
GST_BASE_TRANSFORM_CLASS (klass);
|
|
||||||
GstVideoFilter2Class *video_filter2_class = GST_VIDEO_FILTER2_CLASS (klass);
|
gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
|
||||||
|
gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
|
||||||
|
gst_caps_from_string (VIDEO_CAPS)));
|
||||||
|
gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
|
||||||
|
gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
|
||||||
|
gst_caps_from_string (VIDEO_CAPS)));
|
||||||
|
|
||||||
|
gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
|
||||||
|
"Scene change detector",
|
||||||
|
"Video/Filter", "Detects scene changes in video",
|
||||||
|
"David Schleef <ds@entropywave.com>");
|
||||||
|
|
||||||
gobject_class->set_property = gst_scene_change_set_property;
|
gobject_class->set_property = gst_scene_change_set_property;
|
||||||
gobject_class->get_property = gst_scene_change_get_property;
|
gobject_class->get_property = gst_scene_change_get_property;
|
||||||
gobject_class->dispose = gst_scene_change_dispose;
|
gobject_class->dispose = gst_scene_change_dispose;
|
||||||
gobject_class->finalize = gst_scene_change_finalize;
|
gobject_class->finalize = gst_scene_change_finalize;
|
||||||
base_transform_class->start = GST_DEBUG_FUNCPTR (gst_scene_change_start);
|
video_filter_class->set_info = GST_DEBUG_FUNCPTR (gst_scene_change_set_info);
|
||||||
base_transform_class->stop = GST_DEBUG_FUNCPTR (gst_scene_change_stop);
|
video_filter_class->transform_frame_ip =
|
||||||
video_filter2_class->prefilter =
|
GST_DEBUG_FUNCPTR (gst_scene_change_transform_frame_ip);
|
||||||
GST_DEBUG_FUNCPTR (gst_scene_change_prefilter);
|
|
||||||
|
|
||||||
gst_video_filter2_class_add_functions (video_filter2_class,
|
|
||||||
gst_scene_change_filter_functions);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_scene_change_init (GstSceneChange * scenechange,
|
gst_scene_change_init (GstSceneChange * scenechange)
|
||||||
GstSceneChangeClass * scenechange_class)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,7 +159,9 @@ void
|
||||||
gst_scene_change_set_property (GObject * object, guint property_id,
|
gst_scene_change_set_property (GObject * object, guint property_id,
|
||||||
const GValue * value, GParamSpec * pspec)
|
const GValue * value, GParamSpec * pspec)
|
||||||
{
|
{
|
||||||
g_return_if_fail (GST_IS_SCENE_CHANGE (object));
|
GstSceneChange *scenechange = GST_SCENE_CHANGE (object);
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (scenechange, "set_property");
|
||||||
|
|
||||||
switch (property_id) {
|
switch (property_id) {
|
||||||
default:
|
default:
|
||||||
|
@ -182,7 +174,9 @@ void
|
||||||
gst_scene_change_get_property (GObject * object, guint property_id,
|
gst_scene_change_get_property (GObject * object, guint property_id,
|
||||||
GValue * value, GParamSpec * pspec)
|
GValue * value, GParamSpec * pspec)
|
||||||
{
|
{
|
||||||
g_return_if_fail (GST_IS_SCENE_CHANGE (object));
|
GstSceneChange *scenechange = GST_SCENE_CHANGE (object);
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (scenechange, "get_property");
|
||||||
|
|
||||||
switch (property_id) {
|
switch (property_id) {
|
||||||
default:
|
default:
|
||||||
|
@ -194,105 +188,107 @@ gst_scene_change_get_property (GObject * object, guint property_id,
|
||||||
void
|
void
|
||||||
gst_scene_change_dispose (GObject * object)
|
gst_scene_change_dispose (GObject * object)
|
||||||
{
|
{
|
||||||
g_return_if_fail (GST_IS_SCENE_CHANGE (object));
|
GstSceneChange *scenechange = GST_SCENE_CHANGE (object);
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (scenechange, "dispose");
|
||||||
|
|
||||||
/* clean up as possible. may be called multiple times */
|
/* clean up as possible. may be called multiple times */
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
G_OBJECT_CLASS (gst_scene_change_parent_class)->dispose (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gst_scene_change_finalize (GObject * object)
|
gst_scene_change_finalize (GObject * object)
|
||||||
{
|
{
|
||||||
GstSceneChange *scenechange;
|
GstSceneChange *scenechange = GST_SCENE_CHANGE (object);
|
||||||
|
|
||||||
g_return_if_fail (GST_IS_SCENE_CHANGE (object));
|
GST_DEBUG_OBJECT (scenechange, "finalize");
|
||||||
scenechange = GST_SCENE_CHANGE (object);
|
|
||||||
|
|
||||||
if (scenechange->oldbuf)
|
/* clean up object here */
|
||||||
gst_buffer_unref (scenechange->oldbuf);
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
G_OBJECT_CLASS (gst_scene_change_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_scene_change_start (GstBaseTransform * trans)
|
gst_scene_change_set_info (GstVideoFilter * filter, GstCaps * incaps,
|
||||||
|
GstVideoInfo * in_info, GstCaps * outcaps, GstVideoInfo * out_info)
|
||||||
{
|
{
|
||||||
|
GstSceneChange *scenechange = GST_SCENE_CHANGE (filter);
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (scenechange, "set_info");
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gst_scene_change_stop (GstBaseTransform * trans)
|
|
||||||
{
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GstFlowReturn
|
|
||||||
gst_scene_change_prefilter (GstVideoFilter2 * video_filter2, GstBuffer * buf)
|
|
||||||
{
|
|
||||||
|
|
||||||
return GST_FLOW_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static double
|
static double
|
||||||
get_frame_score (guint8 * s1, guint8 * s2, int width, int height)
|
get_frame_score (GstVideoFrame * f1, GstVideoFrame * f2)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
int score = 0;
|
int score = 0;
|
||||||
|
int width, height;
|
||||||
|
guint8 *s1;
|
||||||
|
guint8 *s2;
|
||||||
|
|
||||||
|
width = f1->info.width;
|
||||||
|
height = f1->info.height;
|
||||||
|
|
||||||
for (j = 0; j < height; j++) {
|
for (j = 0; j < height; j++) {
|
||||||
|
s1 = (guint8 *) f1->data[0] + f1->info.stride[0] * j;
|
||||||
|
s2 = (guint8 *) f2->data[0] + f2->info.stride[0] * j;
|
||||||
for (i = 0; i < width; i++) {
|
for (i = 0; i < width; i++) {
|
||||||
score += ABS (s1[i] - s2[i]);
|
score += ABS (s1[i] - s2[i]);
|
||||||
}
|
}
|
||||||
s1 += width;
|
|
||||||
s2 += width;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ((double) score) / (width * height);
|
return ((double) score) / (width * height);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_scene_change_filter_ip_I420 (GstVideoFilter2 * videofilter2,
|
gst_scene_change_transform_frame_ip (GstVideoFilter * filter,
|
||||||
GstBuffer * buf, int start, int end)
|
GstVideoFrame * frame)
|
||||||
{
|
{
|
||||||
GstSceneChange *scenechange;
|
GstSceneChange *scenechange = GST_SCENE_CHANGE (filter);
|
||||||
|
GstVideoFrame oldframe;
|
||||||
double score_min;
|
double score_min;
|
||||||
double score_max;
|
double score_max;
|
||||||
double threshold;
|
double threshold;
|
||||||
double score;
|
double score;
|
||||||
gboolean change;
|
gboolean change;
|
||||||
|
gboolean ret;
|
||||||
int i;
|
int i;
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GST_IS_SCENE_CHANGE (videofilter2), GST_FLOW_ERROR);
|
GST_DEBUG_OBJECT (scenechange, "transform_frame_ip");
|
||||||
scenechange = GST_SCENE_CHANGE (videofilter2);
|
|
||||||
|
|
||||||
width = GST_VIDEO_FILTER2_WIDTH (videofilter2);
|
|
||||||
height = GST_VIDEO_FILTER2_HEIGHT (videofilter2);
|
|
||||||
|
|
||||||
if (!scenechange->oldbuf) {
|
if (!scenechange->oldbuf) {
|
||||||
scenechange->n_diffs = 0;
|
scenechange->n_diffs = 0;
|
||||||
memset (scenechange->diffs, 0, sizeof (double) * SC_N_DIFFS);
|
memset (scenechange->diffs, 0, sizeof (double) * SC_N_DIFFS);
|
||||||
scenechange->oldbuf = gst_buffer_ref (buf);
|
scenechange->oldbuf = gst_buffer_ref (frame->buffer);
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
score = get_frame_score (GST_BUFFER_DATA (scenechange->oldbuf),
|
ret =
|
||||||
GST_BUFFER_DATA (buf), width, height);
|
gst_video_frame_map (&oldframe, &scenechange->oldinfo,
|
||||||
|
scenechange->oldbuf, GST_MAP_READ);
|
||||||
|
if (!ret) {
|
||||||
|
GST_ERROR_OBJECT (scenechange, "failed to map old video frame");
|
||||||
|
return GST_FLOW_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
score = get_frame_score (&oldframe, frame);
|
||||||
|
|
||||||
|
gst_video_frame_unmap (&oldframe);
|
||||||
|
|
||||||
|
gst_buffer_unref (scenechange->oldbuf);
|
||||||
|
scenechange->oldbuf = gst_buffer_ref (frame->buffer);
|
||||||
|
memcpy (&scenechange->oldinfo, &frame->info, sizeof (GstVideoInfo));
|
||||||
|
|
||||||
memmove (scenechange->diffs, scenechange->diffs + 1,
|
memmove (scenechange->diffs, scenechange->diffs + 1,
|
||||||
sizeof (double) * (SC_N_DIFFS - 1));
|
sizeof (double) * (SC_N_DIFFS - 1));
|
||||||
scenechange->diffs[SC_N_DIFFS - 1] = score;
|
scenechange->diffs[SC_N_DIFFS - 1] = score;
|
||||||
scenechange->n_diffs++;
|
scenechange->n_diffs++;
|
||||||
|
|
||||||
gst_buffer_unref (scenechange->oldbuf);
|
|
||||||
scenechange->oldbuf = gst_buffer_ref (buf);
|
|
||||||
|
|
||||||
score_min = scenechange->diffs[0];
|
score_min = scenechange->diffs[0];
|
||||||
score_max = scenechange->diffs[0];
|
score_max = scenechange->diffs[0];
|
||||||
for (i = 1; i < SC_N_DIFFS - 1; i++) {
|
for (i = 1; i < SC_N_DIFFS - 1; i++) {
|
||||||
|
@ -328,11 +324,13 @@ gst_scene_change_filter_ip_I420 (GstVideoFilter2 * videofilter2,
|
||||||
if (change) {
|
if (change) {
|
||||||
GstEvent *event;
|
GstEvent *event;
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (scenechange, "%d %g %g %g %d",
|
GST_INFO_OBJECT (scenechange, "%d %g %g %g %d",
|
||||||
scenechange->n_diffs, score / threshold, score, threshold, change);
|
scenechange->n_diffs, score / threshold, score, threshold, change);
|
||||||
|
|
||||||
event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM,
|
event =
|
||||||
gst_structure_new ("GstForceKeyUnit", NULL));
|
gst_video_event_new_downstream_force_key_unit (GST_BUFFER_PTS
|
||||||
|
(frame->buffer), GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE, FALSE,
|
||||||
|
scenechange->count++);
|
||||||
|
|
||||||
gst_pad_push_event (GST_BASE_TRANSFORM_SRC_PAD (scenechange), event);
|
gst_pad_push_event (GST_BASE_TRANSFORM_SRC_PAD (scenechange), event);
|
||||||
}
|
}
|
||||||
|
@ -340,11 +338,6 @@ gst_scene_change_filter_ip_I420 (GstVideoFilter2 * videofilter2,
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstVideoFilter2Functions gst_scene_change_filter_functions[] = {
|
|
||||||
{GST_VIDEO_FORMAT_I420, NULL, gst_scene_change_filter_ip_I420},
|
|
||||||
{GST_VIDEO_FORMAT_UNKNOWN}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/* GStreamer
|
/* GStreamer
|
||||||
* Copyright (C) 2011 FIXME <fixme@example.com>
|
* Copyright (C) 2011 David Schleef <ds@schleef.org>
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Library General Public
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
@ -20,9 +20,8 @@
|
||||||
#ifndef _GST_SCENE_CHANGE_H_
|
#ifndef _GST_SCENE_CHANGE_H_
|
||||||
#define _GST_SCENE_CHANGE_H_
|
#define _GST_SCENE_CHANGE_H_
|
||||||
|
|
||||||
#include <gst/base/gstbasetransform.h>
|
|
||||||
#include <gst/video/video.h>
|
#include <gst/video/video.h>
|
||||||
#include "gstvideofilter2.h"
|
#include <gst/video/gstvideofilter.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
@ -39,16 +38,18 @@ typedef struct _GstSceneChangeClass GstSceneChangeClass;
|
||||||
|
|
||||||
struct _GstSceneChange
|
struct _GstSceneChange
|
||||||
{
|
{
|
||||||
GstVideoFilter2 base_scenechange;
|
GstVideoFilter base_scenechange;
|
||||||
|
|
||||||
int n_diffs;
|
int n_diffs;
|
||||||
double diffs[SC_N_DIFFS];
|
double diffs[SC_N_DIFFS];
|
||||||
GstBuffer *oldbuf;
|
GstBuffer *oldbuf;
|
||||||
|
GstVideoInfo oldinfo;
|
||||||
|
int count;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstSceneChangeClass
|
struct _GstSceneChangeClass
|
||||||
{
|
{
|
||||||
GstVideoFilter2Class base_scenechange_class;
|
GstVideoFilterClass base_scenechange_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
GType gst_scene_change_get_type (void);
|
GType gst_scene_change_get_type (void);
|
||||||
|
|
|
@ -1,269 +0,0 @@
|
||||||
/* GStreamer
|
|
||||||
* Copyright (C) 2011 David Schleef <ds@schleef.org>
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Library General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Library General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this library; if not, write to the
|
|
||||||
* Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
|
|
||||||
* Boston, MA 02110-1335, USA.
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* SECTION:element-gstvideofilter2
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include "config.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <gst/gst.h>
|
|
||||||
#include <gst/base/gstbasetransform.h>
|
|
||||||
#include <gst/video/video.h>
|
|
||||||
#include "gstvideofilter2.h"
|
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_STATIC (gst_video_filter2_debug_category);
|
|
||||||
#define GST_CAT_DEFAULT gst_video_filter2_debug_category
|
|
||||||
|
|
||||||
/* prototypes */
|
|
||||||
|
|
||||||
|
|
||||||
static void gst_video_filter2_set_property (GObject * object,
|
|
||||||
guint property_id, const GValue * value, GParamSpec * pspec);
|
|
||||||
static void gst_video_filter2_get_property (GObject * object,
|
|
||||||
guint property_id, GValue * value, GParamSpec * pspec);
|
|
||||||
static void gst_video_filter2_dispose (GObject * object);
|
|
||||||
static void gst_video_filter2_finalize (GObject * object);
|
|
||||||
|
|
||||||
static GstCaps *gst_video_filter2_transform_caps (GstBaseTransform * trans,
|
|
||||||
GstPadDirection direction, GstCaps * caps);
|
|
||||||
static gboolean
|
|
||||||
gst_video_filter2_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
|
|
||||||
guint * size);
|
|
||||||
static gboolean
|
|
||||||
gst_video_filter2_set_caps (GstBaseTransform * trans, GstCaps * incaps,
|
|
||||||
GstCaps * outcaps);
|
|
||||||
static gboolean gst_video_filter2_start (GstBaseTransform * trans);
|
|
||||||
static gboolean gst_video_filter2_stop (GstBaseTransform * trans);
|
|
||||||
static GstFlowReturn gst_video_filter2_transform (GstBaseTransform * trans,
|
|
||||||
GstBuffer * inbuf, GstBuffer * outbuf);
|
|
||||||
static GstFlowReturn gst_video_filter2_transform_ip (GstBaseTransform * trans,
|
|
||||||
GstBuffer * buf);
|
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
PROP_0
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* class initialization */
|
|
||||||
|
|
||||||
#define DEBUG_INIT(bla) \
|
|
||||||
GST_DEBUG_CATEGORY_INIT (gst_video_filter2_debug_category, "videofilter2", 0, \
|
|
||||||
"debug category for videofilter2 element");
|
|
||||||
|
|
||||||
GST_BOILERPLATE_FULL (GstVideoFilter2, gst_video_filter2, GstBaseTransform,
|
|
||||||
GST_TYPE_BASE_TRANSFORM, DEBUG_INIT);
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_video_filter2_base_init (gpointer g_class)
|
|
||||||
{
|
|
||||||
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
||||||
int i;
|
|
||||||
GstCaps *caps = NULL;
|
|
||||||
|
|
||||||
caps = gst_caps_new_empty ();
|
|
||||||
for (i = GST_VIDEO_FORMAT_I420; i <= GST_VIDEO_FORMAT_I420; i++) {
|
|
||||||
gst_caps_append (caps, gst_video_format_new_template_caps (i));
|
|
||||||
}
|
|
||||||
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
|
||||||
gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
|
|
||||||
gst_caps_ref (caps)));
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
|
||||||
gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, caps));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_video_filter2_class_init (GstVideoFilter2Class * klass)
|
|
||||||
{
|
|
||||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
||||||
GstBaseTransformClass *base_transform_class =
|
|
||||||
GST_BASE_TRANSFORM_CLASS (klass);
|
|
||||||
|
|
||||||
gobject_class->set_property = gst_video_filter2_set_property;
|
|
||||||
gobject_class->get_property = gst_video_filter2_get_property;
|
|
||||||
gobject_class->dispose = gst_video_filter2_dispose;
|
|
||||||
gobject_class->finalize = gst_video_filter2_finalize;
|
|
||||||
base_transform_class->transform_caps =
|
|
||||||
GST_DEBUG_FUNCPTR (gst_video_filter2_transform_caps);
|
|
||||||
base_transform_class->get_unit_size =
|
|
||||||
GST_DEBUG_FUNCPTR (gst_video_filter2_get_unit_size);
|
|
||||||
base_transform_class->set_caps =
|
|
||||||
GST_DEBUG_FUNCPTR (gst_video_filter2_set_caps);
|
|
||||||
base_transform_class->start = GST_DEBUG_FUNCPTR (gst_video_filter2_start);
|
|
||||||
base_transform_class->stop = GST_DEBUG_FUNCPTR (gst_video_filter2_stop);
|
|
||||||
base_transform_class->transform =
|
|
||||||
GST_DEBUG_FUNCPTR (gst_video_filter2_transform);
|
|
||||||
base_transform_class->transform_ip =
|
|
||||||
GST_DEBUG_FUNCPTR (gst_video_filter2_transform_ip);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_video_filter2_init (GstVideoFilter2 * videofilter2,
|
|
||||||
GstVideoFilter2Class * videofilter2_class)
|
|
||||||
{
|
|
||||||
|
|
||||||
gst_base_transform_set_qos_enabled (GST_BASE_TRANSFORM (videofilter2), TRUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_video_filter2_set_property (GObject * object, guint property_id,
|
|
||||||
const GValue * value, GParamSpec * pspec)
|
|
||||||
{
|
|
||||||
g_return_if_fail (GST_IS_VIDEO_FILTER2 (object));
|
|
||||||
|
|
||||||
switch (property_id) {
|
|
||||||
default:
|
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_video_filter2_get_property (GObject * object, guint property_id,
|
|
||||||
GValue * value, GParamSpec * pspec)
|
|
||||||
{
|
|
||||||
g_return_if_fail (GST_IS_VIDEO_FILTER2 (object));
|
|
||||||
|
|
||||||
switch (property_id) {
|
|
||||||
default:
|
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_video_filter2_dispose (GObject * object)
|
|
||||||
{
|
|
||||||
g_return_if_fail (GST_IS_VIDEO_FILTER2 (object));
|
|
||||||
|
|
||||||
/* clean up as possible. may be called multiple times */
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->dispose (object);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_video_filter2_finalize (GObject * object)
|
|
||||||
{
|
|
||||||
g_return_if_fail (GST_IS_VIDEO_FILTER2 (object));
|
|
||||||
|
|
||||||
/* clean up object here */
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
||||||
}
|
|
||||||
|
|
||||||
static GstCaps *
|
|
||||||
gst_video_filter2_transform_caps (GstBaseTransform * trans,
|
|
||||||
GstPadDirection direction, GstCaps * caps)
|
|
||||||
{
|
|
||||||
return gst_caps_ref (caps);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gst_video_filter2_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
|
|
||||||
guint * size)
|
|
||||||
{
|
|
||||||
GstVideoFormat format;
|
|
||||||
gint width, height;
|
|
||||||
gboolean ret;
|
|
||||||
|
|
||||||
ret = gst_video_format_parse_caps (caps, &format, &width, &height);
|
|
||||||
*size = gst_video_format_get_size (format, width, height);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gst_video_filter2_set_caps (GstBaseTransform * trans, GstCaps * incaps,
|
|
||||||
GstCaps * outcaps)
|
|
||||||
{
|
|
||||||
GstVideoFilter2 *videofilter2;
|
|
||||||
gboolean ret;
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
GstVideoFormat format;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GST_IS_VIDEO_FILTER2 (trans), FALSE);
|
|
||||||
videofilter2 = GST_VIDEO_FILTER2 (trans);
|
|
||||||
|
|
||||||
ret = gst_video_format_parse_caps (incaps, &format, &width, &height);
|
|
||||||
|
|
||||||
if (ret) {
|
|
||||||
videofilter2->format = format;
|
|
||||||
videofilter2->width = width;
|
|
||||||
videofilter2->height = height;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gst_video_filter2_start (GstBaseTransform * trans)
|
|
||||||
{
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gst_video_filter2_stop (GstBaseTransform * trans)
|
|
||||||
{
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GstFlowReturn
|
|
||||||
gst_video_filter2_transform (GstBaseTransform * trans, GstBuffer * inbuf,
|
|
||||||
GstBuffer * outbuf)
|
|
||||||
{
|
|
||||||
|
|
||||||
return GST_FLOW_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GstFlowReturn
|
|
||||||
gst_video_filter2_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
|
|
||||||
{
|
|
||||||
GstVideoFilter2 *video_filter2 = GST_VIDEO_FILTER2 (trans);
|
|
||||||
GstVideoFilter2Class *klass =
|
|
||||||
GST_VIDEO_FILTER2_CLASS (G_OBJECT_GET_CLASS (trans));
|
|
||||||
int i;
|
|
||||||
GstFlowReturn ret;
|
|
||||||
|
|
||||||
for (i = 0; klass->functions[i].format != GST_VIDEO_FORMAT_UNKNOWN; i++) {
|
|
||||||
if (klass->functions[i].format == video_filter2->format) {
|
|
||||||
ret = klass->functions[i].filter_ip (video_filter2, buf, 0,
|
|
||||||
video_filter2->height);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return GST_FLOW_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* API */
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_video_filter2_class_add_functions (GstVideoFilter2Class * klass,
|
|
||||||
const GstVideoFilter2Functions * functions)
|
|
||||||
{
|
|
||||||
klass->functions = functions;
|
|
||||||
}
|
|
|
@ -1,81 +0,0 @@
|
||||||
/* GStreamer
|
|
||||||
* Copyright (C) 2011 David Schleef <ds@schleef.org>
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Library General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This library is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
* Library General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Library General Public
|
|
||||||
* License along with this library; if not, write to the
|
|
||||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
||||||
* Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _GST_VIDEO_FILTER2_H_
|
|
||||||
#define _GST_VIDEO_FILTER2_H_
|
|
||||||
|
|
||||||
#include <gst/base/gstbasetransform.h>
|
|
||||||
#include <gst/video/video.h>
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
|
||||||
|
|
||||||
#define GST_TYPE_VIDEO_FILTER2 (gst_video_filter2_get_type())
|
|
||||||
#define GST_VIDEO_FILTER2(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VIDEO_FILTER2,GstVideoFilter2))
|
|
||||||
#define GST_VIDEO_FILTER2_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VIDEO_FILTER2,GstVideoFilter2Class))
|
|
||||||
#define GST_IS_VIDEO_FILTER2(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VIDEO_FILTER2))
|
|
||||||
#define GST_IS_VIDEO_FILTER2_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VIDEO_FILTER2))
|
|
||||||
|
|
||||||
typedef struct _GstVideoFilter2 GstVideoFilter2;
|
|
||||||
typedef struct _GstVideoFilter2Class GstVideoFilter2Class;
|
|
||||||
typedef struct _GstVideoFilter2Functions GstVideoFilter2Functions;
|
|
||||||
|
|
||||||
struct _GstVideoFilter2
|
|
||||||
{
|
|
||||||
GstBaseTransform base_videofilter2;
|
|
||||||
|
|
||||||
GstVideoFormat format;
|
|
||||||
int width;
|
|
||||||
int height;
|
|
||||||
|
|
||||||
gpointer _gst_reserved[GST_PADDING_LARGE];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _GstVideoFilter2Class
|
|
||||||
{
|
|
||||||
GstBaseTransformClass base_videofilter2_class;
|
|
||||||
|
|
||||||
const GstVideoFilter2Functions *functions;
|
|
||||||
|
|
||||||
GstFlowReturn (*prefilter) (GstVideoFilter2 *filter, GstBuffer *inbuf);
|
|
||||||
|
|
||||||
gpointer _gst_reserved[GST_PADDING_LARGE];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct _GstVideoFilter2Functions
|
|
||||||
{
|
|
||||||
GstVideoFormat format;
|
|
||||||
GstFlowReturn (*filter) (GstVideoFilter2 *filter, GstBuffer *inbuf,
|
|
||||||
GstBuffer *outbuf, int start, int end);
|
|
||||||
GstFlowReturn (*filter_ip) (GstVideoFilter2 *filter, GstBuffer *buffer,
|
|
||||||
int start, int end);
|
|
||||||
gpointer _gst_reserved[GST_PADDING_LARGE];
|
|
||||||
};
|
|
||||||
|
|
||||||
#define GST_VIDEO_FILTER2_FORMAT(vf) (((GstVideoFilter2 *)vf)->format)
|
|
||||||
#define GST_VIDEO_FILTER2_WIDTH(vf) (((GstVideoFilter2 *)vf)->width)
|
|
||||||
#define GST_VIDEO_FILTER2_HEIGHT(vf) (((GstVideoFilter2 *)vf)->height)
|
|
||||||
|
|
||||||
GType gst_video_filter2_get_type (void);
|
|
||||||
|
|
||||||
void gst_video_filter2_class_add_functions (GstVideoFilter2Class *klass,
|
|
||||||
const GstVideoFilter2Functions *functions);
|
|
||||||
|
|
||||||
G_END_DECLS
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -47,10 +47,10 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
#include <gst/base/gstbasetransform.h>
|
|
||||||
#include <gst/video/video.h>
|
#include <gst/video/video.h>
|
||||||
#include <math.h>
|
#include <gst/video/gstvideofilter.h>
|
||||||
#include "gstzebrastripe.h"
|
#include "gstzebrastripe.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_STATIC (gst_zebra_stripe_debug_category);
|
GST_DEBUG_CATEGORY_STATIC (gst_zebra_stripe_debug_category);
|
||||||
#define GST_CAT_DEFAULT gst_zebra_stripe_debug_category
|
#define GST_CAT_DEFAULT gst_zebra_stripe_debug_category
|
||||||
|
@ -62,15 +62,16 @@ static void gst_zebra_stripe_set_property (GObject * object,
|
||||||
guint property_id, const GValue * value, GParamSpec * pspec);
|
guint property_id, const GValue * value, GParamSpec * pspec);
|
||||||
static void gst_zebra_stripe_get_property (GObject * object,
|
static void gst_zebra_stripe_get_property (GObject * object,
|
||||||
guint property_id, GValue * value, GParamSpec * pspec);
|
guint property_id, GValue * value, GParamSpec * pspec);
|
||||||
|
static void gst_zebra_stripe_dispose (GObject * object);
|
||||||
static void gst_zebra_stripe_finalize (GObject * object);
|
static void gst_zebra_stripe_finalize (GObject * object);
|
||||||
|
|
||||||
static gboolean gst_zebra_stripe_start (GstBaseTransform * trans);
|
static gboolean gst_zebra_stripe_start (GstBaseTransform * trans);
|
||||||
static gboolean gst_zebra_stripe_stop (GstBaseTransform * trans);
|
static gboolean gst_zebra_stripe_stop (GstBaseTransform * trans);
|
||||||
|
|
||||||
static GstFlowReturn
|
static gboolean gst_zebra_stripe_set_info (GstVideoFilter * filter,
|
||||||
gst_zebra_stripe_prefilter (GstVideoFilter2 * videofilter2, GstBuffer * buf);
|
GstCaps * incaps, GstVideoInfo * in_info, GstCaps * outcaps,
|
||||||
|
GstVideoInfo * out_info);
|
||||||
static GstVideoFilter2Functions gst_zebra_stripe_filter_functions[];
|
static GstFlowReturn gst_zebra_stripe_transform_frame_ip (GstVideoFilter *
|
||||||
|
filter, GstVideoFrame * frame);
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
@ -80,68 +81,71 @@ enum
|
||||||
|
|
||||||
#define DEFAULT_THRESHOLD 90
|
#define DEFAULT_THRESHOLD 90
|
||||||
|
|
||||||
|
/* pad templates */
|
||||||
|
|
||||||
|
#define VIDEO_CAPS GST_VIDEO_CAPS_MAKE( \
|
||||||
|
"{ I420, Y444, Y42B, Y41B, YUY2, UYVY, AYUV }")
|
||||||
|
|
||||||
|
|
||||||
/* class initialization */
|
/* class initialization */
|
||||||
|
|
||||||
#define DEBUG_INIT(bla) \
|
G_DEFINE_TYPE_WITH_CODE (GstZebraStripe, gst_zebra_stripe,
|
||||||
GST_DEBUG_CATEGORY_INIT (gst_zebra_stripe_debug_category, "zebrastripe", 0, \
|
GST_TYPE_VIDEO_FILTER,
|
||||||
"debug category for zebrastripe element");
|
GST_DEBUG_CATEGORY_INIT (gst_zebra_stripe_debug_category, "zebrastripe", 0,
|
||||||
|
"debug category for zebrastripe element"));
|
||||||
GST_BOILERPLATE_FULL (GstZebraStripe, gst_zebra_stripe, GstVideoFilter2,
|
|
||||||
GST_TYPE_VIDEO_FILTER2, DEBUG_INIT);
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_zebra_stripe_base_init (gpointer g_class)
|
|
||||||
{
|
|
||||||
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
||||||
|
|
||||||
gst_element_class_set_static_metadata (element_class, "Zebra stripe overlay",
|
|
||||||
"Filter/Analysis",
|
|
||||||
"Overlays zebra striping on overexposed areas of video",
|
|
||||||
"David Schleef <ds@entropywave.com>");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_zebra_stripe_class_init (GstZebraStripeClass * klass)
|
gst_zebra_stripe_class_init (GstZebraStripeClass * klass)
|
||||||
{
|
{
|
||||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||||
GstVideoFilter2Class *video_filter2_class = GST_VIDEO_FILTER2_CLASS (klass);
|
|
||||||
GstBaseTransformClass *base_transform_class =
|
GstBaseTransformClass *base_transform_class =
|
||||||
GST_BASE_TRANSFORM_CLASS (klass);
|
GST_BASE_TRANSFORM_CLASS (klass);
|
||||||
|
GstVideoFilterClass *video_filter_class = GST_VIDEO_FILTER_CLASS (klass);
|
||||||
|
|
||||||
|
/* Setting up pads and setting metadata should be moved to
|
||||||
|
base_class_init if you intend to subclass this class. */
|
||||||
|
gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
|
||||||
|
gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
|
||||||
|
gst_caps_from_string (VIDEO_CAPS)));
|
||||||
|
gst_element_class_add_pad_template (GST_ELEMENT_CLASS (klass),
|
||||||
|
gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
|
||||||
|
gst_caps_from_string (VIDEO_CAPS)));
|
||||||
|
|
||||||
|
gst_element_class_set_static_metadata (GST_ELEMENT_CLASS (klass),
|
||||||
|
"Zebra stripe overlay",
|
||||||
|
"Filter/Analysis",
|
||||||
|
"Overlays zebra striping on overexposed areas of video",
|
||||||
|
"David Schleef <ds@entropywave.com>");
|
||||||
|
|
||||||
gobject_class->set_property = gst_zebra_stripe_set_property;
|
gobject_class->set_property = gst_zebra_stripe_set_property;
|
||||||
gobject_class->get_property = gst_zebra_stripe_get_property;
|
gobject_class->get_property = gst_zebra_stripe_get_property;
|
||||||
|
gobject_class->dispose = gst_zebra_stripe_dispose;
|
||||||
gobject_class->finalize = gst_zebra_stripe_finalize;
|
gobject_class->finalize = gst_zebra_stripe_finalize;
|
||||||
base_transform_class->start = GST_DEBUG_FUNCPTR (gst_zebra_stripe_start);
|
base_transform_class->start = GST_DEBUG_FUNCPTR (gst_zebra_stripe_start);
|
||||||
base_transform_class->stop = GST_DEBUG_FUNCPTR (gst_zebra_stripe_stop);
|
base_transform_class->stop = GST_DEBUG_FUNCPTR (gst_zebra_stripe_stop);
|
||||||
|
video_filter_class->set_info = GST_DEBUG_FUNCPTR (gst_zebra_stripe_set_info);
|
||||||
video_filter2_class->prefilter =
|
video_filter_class->transform_frame_ip =
|
||||||
GST_DEBUG_FUNCPTR (gst_zebra_stripe_prefilter);
|
GST_DEBUG_FUNCPTR (gst_zebra_stripe_transform_frame_ip);
|
||||||
|
|
||||||
g_object_class_install_property (gobject_class, PROP_THRESHOLD,
|
g_object_class_install_property (gobject_class, PROP_THRESHOLD,
|
||||||
g_param_spec_int ("threshold", "Threshold",
|
g_param_spec_int ("threshold", "Threshold",
|
||||||
"Threshold above which the video is striped", 0, 100,
|
"Threshold above which the video is striped", 0, 100,
|
||||||
DEFAULT_THRESHOLD,
|
DEFAULT_THRESHOLD,
|
||||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
|
||||||
|
|
||||||
gst_video_filter2_class_add_functions (video_filter2_class,
|
|
||||||
gst_zebra_stripe_filter_functions);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_zebra_stripe_init (GstZebraStripe * zebrastripe,
|
gst_zebra_stripe_init (GstZebraStripe * zebrastripe)
|
||||||
GstZebraStripeClass * zebrastripe_class)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gst_zebra_stripe_set_property (GObject * object, guint property_id,
|
gst_zebra_stripe_set_property (GObject * object, guint property_id,
|
||||||
const GValue * value, GParamSpec * pspec)
|
const GValue * value, GParamSpec * pspec)
|
||||||
{
|
{
|
||||||
GstZebraStripe *zebrastripe;
|
GstZebraStripe *zebrastripe = GST_ZEBRA_STRIPE (object);
|
||||||
|
|
||||||
g_return_if_fail (GST_IS_ZEBRA_STRIPE (object));
|
GST_DEBUG_OBJECT (zebrastripe, "set_property");
|
||||||
zebrastripe = GST_ZEBRA_STRIPE (object);
|
|
||||||
|
|
||||||
switch (property_id) {
|
switch (property_id) {
|
||||||
case PROP_THRESHOLD:
|
case PROP_THRESHOLD:
|
||||||
|
@ -159,10 +163,9 @@ void
|
||||||
gst_zebra_stripe_get_property (GObject * object, guint property_id,
|
gst_zebra_stripe_get_property (GObject * object, guint property_id,
|
||||||
GValue * value, GParamSpec * pspec)
|
GValue * value, GParamSpec * pspec)
|
||||||
{
|
{
|
||||||
GstZebraStripe *zebrastripe;
|
GstZebraStripe *zebrastripe = GST_ZEBRA_STRIPE (object);
|
||||||
|
|
||||||
g_return_if_fail (GST_IS_ZEBRA_STRIPE (object));
|
GST_DEBUG_OBJECT (zebrastripe, "get_property");
|
||||||
zebrastripe = GST_ZEBRA_STRIPE (object);
|
|
||||||
|
|
||||||
switch (property_id) {
|
switch (property_id) {
|
||||||
case PROP_THRESHOLD:
|
case PROP_THRESHOLD:
|
||||||
|
@ -174,60 +177,79 @@ gst_zebra_stripe_get_property (GObject * object, guint property_id,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
gst_zebra_stripe_dispose (GObject * object)
|
||||||
|
{
|
||||||
|
GstZebraStripe *zebrastripe = GST_ZEBRA_STRIPE (object);
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (zebrastripe, "dispose");
|
||||||
|
|
||||||
|
/* clean up as possible. may be called multiple times */
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (gst_zebra_stripe_parent_class)->dispose (object);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gst_zebra_stripe_finalize (GObject * object)
|
gst_zebra_stripe_finalize (GObject * object)
|
||||||
{
|
{
|
||||||
g_return_if_fail (GST_IS_ZEBRA_STRIPE (object));
|
GstZebraStripe *zebrastripe = GST_ZEBRA_STRIPE (object);
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (zebrastripe, "finalize");
|
||||||
|
|
||||||
/* clean up object here */
|
/* clean up object here */
|
||||||
|
|
||||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
G_OBJECT_CLASS (gst_zebra_stripe_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_zebra_stripe_start (GstBaseTransform * trans)
|
gst_zebra_stripe_start (GstBaseTransform * trans)
|
||||||
{
|
{
|
||||||
|
GstZebraStripe *zebrastripe = GST_ZEBRA_STRIPE (trans);
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (zebrastripe, "start");
|
||||||
|
|
||||||
|
if (GST_BASE_TRANSFORM_CLASS (gst_zebra_stripe_parent_class)->start)
|
||||||
|
return
|
||||||
|
GST_BASE_TRANSFORM_CLASS (gst_zebra_stripe_parent_class)->start (trans);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
gst_zebra_stripe_stop (GstBaseTransform * trans)
|
gst_zebra_stripe_stop (GstBaseTransform * trans)
|
||||||
{
|
{
|
||||||
|
GstZebraStripe *zebrastripe = GST_ZEBRA_STRIPE (trans);
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (zebrastripe, "stop");
|
||||||
|
|
||||||
|
if (GST_BASE_TRANSFORM_CLASS (gst_zebra_stripe_parent_class)->stop)
|
||||||
|
return
|
||||||
|
GST_BASE_TRANSFORM_CLASS (gst_zebra_stripe_parent_class)->stop (trans);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_zebra_stripe_set_info (GstVideoFilter * filter, GstCaps * incaps,
|
||||||
|
GstVideoInfo * in_info, GstCaps * outcaps, GstVideoInfo * out_info)
|
||||||
|
{
|
||||||
|
GstZebraStripe *zebrastripe = GST_ZEBRA_STRIPE (filter);
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (zebrastripe, "set_info");
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_zebra_stripe_prefilter (GstVideoFilter2 * videofilter2, GstBuffer * buf)
|
gst_zebra_stripe_transform_frame_ip_planarY (GstZebraStripe * zebrastripe,
|
||||||
|
GstVideoFrame * frame)
|
||||||
{
|
{
|
||||||
GstZebraStripe *zebrastripe = GST_ZEBRA_STRIPE (videofilter2);
|
int width = frame->info.width;
|
||||||
|
int height = frame->info.height;
|
||||||
zebrastripe->t++;
|
|
||||||
|
|
||||||
return GST_FLOW_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GstFlowReturn
|
|
||||||
gst_zebra_stripe_filter_ip_planarY (GstVideoFilter2 * videofilter2,
|
|
||||||
GstBuffer * buf, int start, int end)
|
|
||||||
{
|
|
||||||
GstZebraStripe *zebrastripe = GST_ZEBRA_STRIPE (videofilter2);
|
|
||||||
int width = GST_VIDEO_FILTER2_WIDTH (zebrastripe);
|
|
||||||
int i, j;
|
int i, j;
|
||||||
int threshold = zebrastripe->y_threshold;
|
int threshold = zebrastripe->y_threshold;
|
||||||
int t = zebrastripe->t;
|
int t = zebrastripe->t;
|
||||||
guint8 *ydata;
|
|
||||||
int ystride;
|
|
||||||
|
|
||||||
ydata = GST_BUFFER_DATA (buf);
|
for (j = 0; j < height; j++) {
|
||||||
ystride =
|
guint8 *data = (guint8 *) frame->data[0] + frame->info.stride[0] * j;
|
||||||
gst_video_format_get_row_stride (GST_VIDEO_FILTER2_FORMAT (videofilter2),
|
|
||||||
0, width);
|
|
||||||
|
|
||||||
for (j = start; j < end; j++) {
|
|
||||||
guint8 *data = ydata + ystride * j;
|
|
||||||
for (i = 0; i < width; i++) {
|
for (i = 0; i < width; i++) {
|
||||||
if (data[i] >= threshold) {
|
if (data[i] >= threshold) {
|
||||||
if ((i + j + t) & 0x4)
|
if ((i + j + t) & 0x4)
|
||||||
|
@ -239,27 +261,23 @@ gst_zebra_stripe_filter_ip_planarY (GstVideoFilter2 * videofilter2,
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_zebra_stripe_filter_ip_YxYy (GstVideoFilter2 * videofilter2,
|
gst_zebra_stripe_transform_frame_ip_YUY2 (GstZebraStripe * zebrastripe,
|
||||||
GstBuffer * buf, int start, int end)
|
GstVideoFrame * frame)
|
||||||
{
|
{
|
||||||
GstZebraStripe *zebrastripe = GST_ZEBRA_STRIPE (videofilter2);
|
int width = frame->info.width;
|
||||||
GstVideoFormat format = GST_VIDEO_FILTER2_FORMAT (zebrastripe);
|
int height = frame->info.height;
|
||||||
int width = GST_VIDEO_FILTER2_WIDTH (zebrastripe);
|
|
||||||
int i, j;
|
int i, j;
|
||||||
int threshold = zebrastripe->y_threshold;
|
int threshold = zebrastripe->y_threshold;
|
||||||
int t = zebrastripe->t;
|
int t = zebrastripe->t;
|
||||||
guint8 *ydata;
|
int offset = 0;
|
||||||
int ystride;
|
|
||||||
|
|
||||||
ydata = GST_BUFFER_DATA (buf);
|
if (frame->info.finfo->format == GST_VIDEO_FORMAT_UYVY) {
|
||||||
ystride = gst_video_format_get_row_stride (format, 0, width);
|
offset = 1;
|
||||||
|
|
||||||
if (format == GST_VIDEO_FORMAT_UYVY) {
|
|
||||||
ydata++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (j = start; j < end; j++) {
|
for (j = 0; j < height; j++) {
|
||||||
guint8 *data = ydata + ystride * j;
|
guint8 *data =
|
||||||
|
(guint8 *) frame->data[0] + frame->info.stride[0] * j + offset;
|
||||||
for (i = 0; i < width; i++) {
|
for (i = 0; i < width; i++) {
|
||||||
if (data[2 * i] >= threshold) {
|
if (data[2 * i] >= threshold) {
|
||||||
if ((i + j + t) & 0x4)
|
if ((i + j + t) & 0x4)
|
||||||
|
@ -271,29 +289,21 @@ gst_zebra_stripe_filter_ip_YxYy (GstVideoFilter2 * videofilter2,
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstFlowReturn
|
static GstFlowReturn
|
||||||
gst_zebra_stripe_filter_ip_AYUV (GstVideoFilter2 * videofilter2,
|
gst_zebra_stripe_transform_frame_ip_AYUV (GstZebraStripe * zebrastripe,
|
||||||
GstBuffer * buf, int start, int end)
|
GstVideoFrame * frame)
|
||||||
{
|
{
|
||||||
GstZebraStripe *zebrastripe = GST_ZEBRA_STRIPE (videofilter2);
|
int width = frame->info.width;
|
||||||
int width = GST_VIDEO_FILTER2_WIDTH (zebrastripe);
|
int height = frame->info.height;
|
||||||
int i, j;
|
int i, j;
|
||||||
int threshold = zebrastripe->y_threshold;
|
int threshold = zebrastripe->y_threshold;
|
||||||
int t = zebrastripe->t;
|
int t = zebrastripe->t;
|
||||||
guint8 *ydata;
|
|
||||||
int ystride;
|
|
||||||
|
|
||||||
ydata = GST_BUFFER_DATA (buf);
|
for (j = 0; j < height; j++) {
|
||||||
ystride =
|
guint8 *data = (guint8 *) frame->data[0] + frame->info.stride[0] * j;
|
||||||
gst_video_format_get_row_stride (GST_VIDEO_FILTER2_FORMAT (videofilter2),
|
|
||||||
0, width);
|
|
||||||
|
|
||||||
ydata++;
|
|
||||||
for (j = start; j < end; j++) {
|
|
||||||
guint8 *data = ydata + ystride * j;
|
|
||||||
for (i = 0; i < width; i++) {
|
for (i = 0; i < width; i++) {
|
||||||
if (data[4 * i] >= threshold) {
|
if (data[4 * i + 1] >= threshold) {
|
||||||
if ((i + j + t) & 0x4)
|
if ((i + j + t) & 0x4)
|
||||||
data[4 * i] = 16;
|
data[4 * i + 1] = 16;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -301,19 +311,33 @@ gst_zebra_stripe_filter_ip_AYUV (GstVideoFilter2 * videofilter2,
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GstVideoFilter2Functions gst_zebra_stripe_filter_functions[] = {
|
static GstFlowReturn
|
||||||
{GST_VIDEO_FORMAT_I420, NULL, gst_zebra_stripe_filter_ip_planarY},
|
gst_zebra_stripe_transform_frame_ip (GstVideoFilter * filter,
|
||||||
{GST_VIDEO_FORMAT_YV12, NULL, gst_zebra_stripe_filter_ip_planarY},
|
GstVideoFrame * frame)
|
||||||
{GST_VIDEO_FORMAT_Y41B, NULL, gst_zebra_stripe_filter_ip_planarY},
|
{
|
||||||
{GST_VIDEO_FORMAT_Y42B, NULL, gst_zebra_stripe_filter_ip_planarY},
|
GstZebraStripe *zebrastripe = GST_ZEBRA_STRIPE (filter);
|
||||||
{GST_VIDEO_FORMAT_NV12, NULL, gst_zebra_stripe_filter_ip_planarY},
|
|
||||||
{GST_VIDEO_FORMAT_NV21, NULL, gst_zebra_stripe_filter_ip_planarY},
|
GST_DEBUG_OBJECT (zebrastripe, "transform_frame_ip");
|
||||||
{GST_VIDEO_FORMAT_YUV9, NULL, gst_zebra_stripe_filter_ip_planarY},
|
zebrastripe->t++;
|
||||||
{GST_VIDEO_FORMAT_YVU9, NULL, gst_zebra_stripe_filter_ip_planarY},
|
|
||||||
{GST_VIDEO_FORMAT_Y444, NULL, gst_zebra_stripe_filter_ip_planarY},
|
switch (frame->info.finfo->format) {
|
||||||
{GST_VIDEO_FORMAT_UYVY, NULL, gst_zebra_stripe_filter_ip_YxYy},
|
case GST_VIDEO_FORMAT_I420:
|
||||||
{GST_VIDEO_FORMAT_YUY2, NULL, gst_zebra_stripe_filter_ip_YxYy},
|
case GST_VIDEO_FORMAT_Y41B:
|
||||||
{GST_VIDEO_FORMAT_YVYU, NULL, gst_zebra_stripe_filter_ip_YxYy},
|
case GST_VIDEO_FORMAT_Y444:
|
||||||
{GST_VIDEO_FORMAT_AYUV, NULL, gst_zebra_stripe_filter_ip_AYUV},
|
case GST_VIDEO_FORMAT_Y42B:
|
||||||
{GST_VIDEO_FORMAT_UNKNOWN}
|
gst_zebra_stripe_transform_frame_ip_planarY (zebrastripe, frame);
|
||||||
};
|
break;
|
||||||
|
case GST_VIDEO_FORMAT_YUY2:
|
||||||
|
case GST_VIDEO_FORMAT_UYVY:
|
||||||
|
gst_zebra_stripe_transform_frame_ip_YUY2 (zebrastripe, frame);
|
||||||
|
break;
|
||||||
|
case GST_VIDEO_FORMAT_AYUV:
|
||||||
|
gst_zebra_stripe_transform_frame_ip_AYUV (zebrastripe, frame);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
g_assert_not_reached ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return GST_FLOW_OK;
|
||||||
|
}
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
#ifndef _GST_ZEBRA_STRIPE_H_
|
#ifndef _GST_ZEBRA_STRIPE_H_
|
||||||
#define _GST_ZEBRA_STRIPE_H_
|
#define _GST_ZEBRA_STRIPE_H_
|
||||||
|
|
||||||
#include "gstvideofilter2.h"
|
|
||||||
#include <gst/video/video.h>
|
#include <gst/video/video.h>
|
||||||
|
#include <gst/video/gstvideofilter.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ typedef struct _GstZebraStripeClass GstZebraStripeClass;
|
||||||
|
|
||||||
struct _GstZebraStripe
|
struct _GstZebraStripe
|
||||||
{
|
{
|
||||||
GstVideoFilter2 video_filter2;
|
GstVideoFilter base_zebrastripe;
|
||||||
|
|
||||||
/* properties */
|
/* properties */
|
||||||
int threshold;
|
int threshold;
|
||||||
|
@ -44,12 +44,11 @@ struct _GstZebraStripe
|
||||||
/* state */
|
/* state */
|
||||||
int t;
|
int t;
|
||||||
int y_threshold;
|
int y_threshold;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstZebraStripeClass
|
struct _GstZebraStripeClass
|
||||||
{
|
{
|
||||||
GstVideoFilter2Class video_filter2_class;
|
GstVideoFilterClass base_zebrastripe_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
GType gst_zebra_stripe_get_type (void);
|
GType gst_zebra_stripe_get_type (void);
|
||||||
|
|
Loading…
Reference in a new issue