Add plugin to generate a pattern detectable by videodetect.

Original commit message from CVS:
* docs/plugins/Makefile.am:
* docs/plugins/gst-plugins-bad-plugins-docs.sgml:
* docs/plugins/gst-plugins-bad-plugins-sections.txt:
* docs/plugins/inspect/plugin-videosignal.xml:
* gst/videosignal/Makefile.am:
* gst/videosignal/gstvideomark.c: (gst_video_mark_set_caps),
(gst_video_mark_draw_box), (gst_video_mark_420),
(gst_video_mark_transform_ip), (gst_video_mark_set_property),
(gst_video_mark_get_property), (gst_video_mark_base_init),
(gst_video_mark_class_init), (gst_video_mark_init),
(gst_video_mark_get_type):
* gst/videosignal/gstvideomark.h:
* gst/videosignal/gstvideosignal.c: (plugin_init):
Add plugin to generate a pattern detectable by videodetect.
This commit is contained in:
Wim Taymans 2007-06-01 14:36:04 +00:00
parent 54cadb7e0f
commit 8540f47485
9 changed files with 494 additions and 3 deletions

View file

@ -1,3 +1,20 @@
2007-06-01 Wim Taymans <wim@fluendo.com>
* docs/plugins/Makefile.am:
* docs/plugins/gst-plugins-bad-plugins-docs.sgml:
* docs/plugins/gst-plugins-bad-plugins-sections.txt:
* docs/plugins/inspect/plugin-videosignal.xml:
* gst/videosignal/Makefile.am:
* gst/videosignal/gstvideomark.c: (gst_video_mark_set_caps),
(gst_video_mark_draw_box), (gst_video_mark_420),
(gst_video_mark_transform_ip), (gst_video_mark_set_property),
(gst_video_mark_get_property), (gst_video_mark_base_init),
(gst_video_mark_class_init), (gst_video_mark_init),
(gst_video_mark_get_type):
* gst/videosignal/gstvideomark.h:
* gst/videosignal/gstvideosignal.c: (plugin_init):
Add plugin to generate a pattern detectable by videodetect.
2007-06-01 Tim-Philipp Müller <tim at centricular dot net>
* ext/neon/gstneonhttpsrc.c: (gst_neonhttp_src_create):

View file

@ -113,7 +113,8 @@ EXTRA_HFILES = \
$(top_srcdir)/gst/rtpmanager/gstrtpssrcdemux.h \
$(top_srcdir)/gst/videocrop/gstvideocrop.h \
$(top_srcdir)/gst/videosignal/gstvideoanalyse.h \
$(top_srcdir)/gst/videosignal/gstvideodetect.h
$(top_srcdir)/gst/videosignal/gstvideodetect.h \
$(top_srcdir)/gst/videosignal/gstvideomark.h
# Images to copy into HTML directory.
HTML_IMAGES =

View file

@ -33,6 +33,7 @@
<xi:include href="xml/element-videocrop.xml" />
<xi:include href="xml/element-videoanalyse.xml" />
<xi:include href="xml/element-videodetect.xml" />
<xi:include href="xml/element-videomark.xml" />
<xi:include href="xml/element-waveformsink.xml" />
<xi:include href="xml/element-wavpackdec.xml" />
<xi:include href="xml/element-wavpackenc.xml" />

View file

@ -229,6 +229,19 @@ GST_VIDEO_DETECT_CLASS
GST_IS_VIDEO_DETECT_CLASS
</SECTION>
<SECTION>
<FILE>element-videomark</FILE>
<TITLE>videomark</TITLE>
GstVideoMark
<SUBSECTION Standard>
GstVideoMarkClass
GST_VIDEO_MARK
GST_IS_VIDEO_MARK
GST_TYPE_VIDEO_MARK
gst_video_mark_get_type
GST_VIDEO_MARK_CLASS
GST_IS_VIDEO_MARK_CLASS
</SECTION>
<SECTION>
<FILE>element-waveformsink</FILE>

View file

@ -23,5 +23,12 @@
<description>Detect patterns in a video signal</description>
<author>Wim Taymans &lt;wim@fluendo.com&gt;</author>
</element>
<element>
<name>videomark</name>
<longname>Video marker</longname>
<class>Filter/Effect/Video</class>
<description>Marks a video signal with a pattern</description>
<author>Wim Taymans &lt;wim@fluendo.com&gt;</author>
</element>
</elements>
</plugin>

View file

@ -1,10 +1,11 @@
plugin_LTLIBRARIES = libgstvideosignal.la
noinst_HEADERS = gstvideoanalyse.h gstvideodetect.h
noinst_HEADERS = gstvideoanalyse.h gstvideodetect.h gstvideomark.h
libgstvideosignal_la_SOURCES = gstvideosignal.c \
gstvideoanalyse.c \
gstvideodetect.c
gstvideodetect.c \
gstvideomark.c
libgstvideosignal_la_CFLAGS = $(GST_CFLAGS) $(GST_BASE_CFLAGS) \
$(GST_PLUGINS_BASE_CFLAGS)

View file

@ -0,0 +1,379 @@
/* GStreamer
* Copyright (C) <2007> Wim Taymans <wim@fluendo.com>
*
* 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., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/**
* SECTION:element-videomark
* @short_description: Mark a pattern in a video signal
*
* <refsect2>
* <para>
* This plugin produces ::pattern-count squares in the bottom left corner of
* the video frames. The squares have a width and height of respectively
* ::pattern-width and ::patern-height. Even squares will be black and odd
* squares will be white.
* </para>
* <para>
* After writing the pattern, ::pattern-data-count squares after the
* pattern squares are produced as the bitarray given in ::pattern-data. 1 bits
* will produce white squares and 0 bits will produce black squares.
* </para>
* <para>
* The element can be enabled with the ::enabled property. It is mostly used
* together with the videodetect plugin.
* </para>
* <title>Example launch line</title>
* <para>
* <programlisting>
* gst-launch videotestsrc ! videomark ! ximagesink
* </programlisting>
* Add the default black/white squares at the bottom left of the video frames.
* </para>
* </refsect2>
*
* Last reviewed on 2007-06-01 (0.10.6)
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstvideomark.h"
#include <string.h>
#include <math.h>
#include <gst/video/video.h>
/* GstVideoMark signals and args */
#define DEFAULT_PATTERN_WIDTH 4
#define DEFAULT_PATTERN_HEIGHT 16
#define DEFAULT_PATTERN_COUNT 4
#define DEFAULT_PATTERN_DATA_COUNT 5
#define DEFAULT_PATTERN_DATA 10
#define DEFAULT_ENABLED TRUE
enum
{
PROP_0,
PROP_PATTERN_WIDTH,
PROP_PATTERN_HEIGHT,
PROP_PATTERN_COUNT,
PROP_PATTERN_DATA_COUNT,
PROP_PATTERN_DATA,
PROP_ENABLED
};
GST_DEBUG_CATEGORY_STATIC (video_mark_debug);
#define GST_CAT_DEFAULT video_mark_debug
static const GstElementDetails video_mark_details =
GST_ELEMENT_DETAILS ("Video marker",
"Filter/Effect/Video",
"Marks a video signal with a pattern",
"Wim Taymans <wim@fluendo.com>");
static GstStaticPadTemplate gst_video_mark_src_template =
GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("{ I420, YV12 }"))
);
static GstStaticPadTemplate gst_video_mark_sink_template =
GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("{ I420, YV12 }"))
);
static GstVideoFilterClass *parent_class = NULL;
static gboolean
gst_video_mark_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
GstCaps * outcaps)
{
GstVideoMark *vf;
GstStructure *in_s;
gboolean ret;
vf = GST_VIDEO_MARK (btrans);
in_s = gst_caps_get_structure (incaps, 0);
ret = gst_structure_get_int (in_s, "width", &vf->width);
ret &= gst_structure_get_int (in_s, "height", &vf->height);
ret &= gst_structure_get_fourcc (in_s, "format", &vf->format);
return ret;
}
/* Useful macros */
#define GST_VIDEO_I420_Y_ROWSTRIDE(width) (GST_ROUND_UP_4(width))
#define GST_VIDEO_I420_U_ROWSTRIDE(width) (GST_ROUND_UP_8(width)/2)
#define GST_VIDEO_I420_V_ROWSTRIDE(width) ((GST_ROUND_UP_8(GST_VIDEO_I420_Y_ROWSTRIDE(width)))/2)
#define GST_VIDEO_I420_Y_OFFSET(w,h) (0)
#define GST_VIDEO_I420_U_OFFSET(w,h) (GST_VIDEO_I420_Y_OFFSET(w,h)+(GST_VIDEO_I420_Y_ROWSTRIDE(w)*GST_ROUND_UP_2(h)))
#define GST_VIDEO_I420_V_OFFSET(w,h) (GST_VIDEO_I420_U_OFFSET(w,h)+(GST_VIDEO_I420_U_ROWSTRIDE(w)*GST_ROUND_UP_2(h)/2))
#define GST_VIDEO_I420_SIZE(w,h) (GST_VIDEO_I420_V_OFFSET(w,h)+(GST_VIDEO_I420_V_ROWSTRIDE(w)*GST_ROUND_UP_2(h)/2))
static void
gst_video_mark_draw_box (GstVideoMark * videomark, guint8 * data,
gint width, gint height, gint stride, guint8 color)
{
gint i, j;
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
data[j] = color;
}
/* move to next line */
data += stride;
}
}
static void
gst_video_mark_420 (GstVideoMark * videomark, GstBuffer * buffer)
{
gint i, pw, ph, stride, width, height;
guint8 *d, *data;
guint pattern_shift;
guint8 color;
data = GST_BUFFER_DATA (buffer);
width = videomark->width;
height = videomark->height;
pw = videomark->pattern_width;
ph = videomark->pattern_height;
stride = GST_VIDEO_I420_Y_ROWSTRIDE (width);
/* draw the bottom left pixels */
for (i = 0; i < videomark->pattern_count; i++) {
d = data;
/* move to start of bottom left */
d += stride * (height - ph);
/* move to i-th pattern */
d += pw * i;
if (i & 1)
/* odd pixels must be white */
color = 255;
else
color = 0;
/* draw box of width * height */
gst_video_mark_draw_box (videomark, d, pw, ph, stride, color);
}
pattern_shift = 1 << (videomark->pattern_data_count - 1);
/* get the data of the pattern */
for (i = 0; i < videomark->pattern_data_count; i++) {
d = data;
/* move to start of bottom left, after the pattern */
d += stride * (height - ph) + (videomark->pattern_count * pw);
/* move to i-th pattern data */
d += pw * i;
if (videomark->pattern_data & pattern_shift)
color = 255;
else
color = 0;
gst_video_mark_draw_box (videomark, d, pw, ph, stride, color);
pattern_shift >>= 1;
}
}
static GstFlowReturn
gst_video_mark_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
{
GstVideoMark *videomark;
GstFlowReturn ret = GST_FLOW_OK;
videomark = GST_VIDEO_MARK (trans);
if (videomark->enabled)
gst_video_mark_420 (videomark, buf);
return ret;
}
static void
gst_video_mark_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec)
{
GstVideoMark *videomark;
videomark = GST_VIDEO_MARK (object);
switch (prop_id) {
case PROP_PATTERN_WIDTH:
videomark->pattern_width = g_value_get_int (value);
break;
case PROP_PATTERN_HEIGHT:
videomark->pattern_height = g_value_get_int (value);
break;
case PROP_PATTERN_COUNT:
videomark->pattern_count = g_value_get_int (value);
break;
case PROP_PATTERN_DATA_COUNT:
videomark->pattern_data_count = g_value_get_int (value);
break;
case PROP_PATTERN_DATA:
videomark->pattern_data = g_value_get_int (value);
break;
case PROP_ENABLED:
videomark->enabled = g_value_get_boolean (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_video_mark_get_property (GObject * object, guint prop_id, GValue * value,
GParamSpec * pspec)
{
GstVideoMark *videomark;
videomark = GST_VIDEO_MARK (object);
switch (prop_id) {
case PROP_PATTERN_WIDTH:
g_value_set_int (value, videomark->pattern_width);
break;
case PROP_PATTERN_HEIGHT:
g_value_set_int (value, videomark->pattern_height);
break;
case PROP_PATTERN_COUNT:
g_value_set_int (value, videomark->pattern_count);
break;
case PROP_PATTERN_DATA_COUNT:
g_value_set_int (value, videomark->pattern_data_count);
break;
case PROP_PATTERN_DATA:
g_value_set_int (value, videomark->pattern_data);
break;
case PROP_ENABLED:
g_value_set_boolean (value, videomark->enabled);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gst_video_mark_base_init (gpointer g_class)
{
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_set_details (element_class, &video_mark_details);
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_video_mark_sink_template));
gst_element_class_add_pad_template (element_class,
gst_static_pad_template_get (&gst_video_mark_src_template));
}
static void
gst_video_mark_class_init (gpointer klass, gpointer class_data)
{
GObjectClass *gobject_class;
GstBaseTransformClass *trans_class;
gobject_class = (GObjectClass *) klass;
trans_class = (GstBaseTransformClass *) klass;
parent_class = g_type_class_peek_parent (klass);
gobject_class->set_property = gst_video_mark_set_property;
gobject_class->get_property = gst_video_mark_get_property;
g_object_class_install_property (gobject_class, PROP_PATTERN_WIDTH,
g_param_spec_int ("pattern-width", "Pattern width",
"The width of the pattern markers", 1, G_MAXINT,
DEFAULT_PATTERN_WIDTH, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (gobject_class, PROP_PATTERN_HEIGHT,
g_param_spec_int ("pattern-height", "Pattern height",
"The height of the pattern markers", 1, G_MAXINT,
DEFAULT_PATTERN_HEIGHT, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (gobject_class, PROP_PATTERN_COUNT,
g_param_spec_int ("pattern-count", "Pattern count",
"The number of pattern markers", 1, G_MAXINT,
DEFAULT_PATTERN_COUNT, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (gobject_class, PROP_PATTERN_DATA_COUNT,
g_param_spec_int ("pattern-data-count", "Pattern data count",
"The number of extra data pattern markers", 0, G_MAXINT,
DEFAULT_PATTERN_DATA_COUNT, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (gobject_class, PROP_PATTERN_DATA,
g_param_spec_int ("pattern-data", "Pattern data",
"The extra data pattern markers", 0, G_MAXINT,
DEFAULT_PATTERN_DATA, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (gobject_class, PROP_ENABLED,
g_param_spec_boolean ("enabled", "Enabled",
"Enable or disable the filter",
DEFAULT_ENABLED, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_video_mark_set_caps);
trans_class->transform_ip = GST_DEBUG_FUNCPTR (gst_video_mark_transform_ip);
GST_DEBUG_CATEGORY_INIT (video_mark_debug, "videomark", 0, "Video mark");
}
static void
gst_video_mark_init (GTypeInstance * instance, gpointer g_class)
{
GstVideoMark *videomark;
videomark = GST_VIDEO_MARK (instance);
GST_DEBUG_OBJECT (videomark, "gst_video_mark_init");
}
GType
gst_video_mark_get_type (void)
{
static GType video_mark_type = 0;
if (!video_mark_type) {
static const GTypeInfo video_mark_info = {
sizeof (GstVideoMarkClass),
gst_video_mark_base_init,
NULL,
gst_video_mark_class_init,
NULL,
NULL,
sizeof (GstVideoMark),
0,
gst_video_mark_init,
};
video_mark_type = g_type_register_static (GST_TYPE_VIDEO_FILTER,
"GstVideoMark", &video_mark_info, 0);
}
return video_mark_type;
}

View file

@ -0,0 +1,68 @@
/* GStreamer
* Copyright (C) <2006> Wim Taymans <wim@fluendo.com>
*
* 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., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __GST_VIDEO_MARK_H__
#define __GST_VIDEO_MARK_H__
#include <gst/video/gstvideofilter.h>
G_BEGIN_DECLS
#define GST_TYPE_VIDEO_MARK \
(gst_video_mark_get_type())
#define GST_VIDEO_MARK(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VIDEO_MARK,GstVideoMark))
#define GST_VIDEO_MARK_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VIDEO_MARK,GstVideoMarkClass))
#define GST_IS_VIDEO_MARK(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VIDEO_MARK))
#define GST_IS_VIDEO_MARK_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VIDEO_MARK))
typedef struct _GstVideoMark GstVideoMark;
typedef struct _GstVideoMarkClass GstVideoMarkClass;
/**
* GstVideoMark:
*
* Opaque datastructure.
*/
struct _GstVideoMark {
GstVideoFilter videofilter;
gint width, height;
guint32 format;
gint pattern_width;
gint pattern_height;
gint pattern_count;
gint pattern_data_count;
gint pattern_data;
gboolean enabled;
};
struct _GstVideoMarkClass {
GstVideoFilterClass parent_class;
};
GType gst_video_mark_get_type (void);
G_END_DECLS
#endif /* __GST_VIDEO_MARK_H__ */

View file

@ -23,6 +23,7 @@
#include "gstvideoanalyse.h"
#include "gstvideodetect.h"
#include "gstvideomark.h"
static gboolean
plugin_init (GstPlugin * plugin)
@ -35,6 +36,9 @@ plugin_init (GstPlugin * plugin)
res &= gst_element_register (plugin, "videodetect", GST_RANK_NONE,
GST_TYPE_VIDEO_DETECT);
res &= gst_element_register (plugin, "videomark", GST_RANK_NONE,
GST_TYPE_VIDEO_MARK);
return res;
}