2007-06-01 14:36:04 +00:00
|
|
|
/* 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
|
2013-04-13 22:16:04 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin Street, Suite 500,
|
|
|
|
* Boston, MA 02110-1335, USA.
|
2007-06-01 14:36:04 +00:00
|
|
|
*/
|
|
|
|
/**
|
2013-04-15 07:24:23 +00:00
|
|
|
* SECTION:element-simplevideomark
|
2017-03-08 18:01:13 +00:00
|
|
|
* @title: simplevideomark
|
2019-05-25 14:57:57 +00:00
|
|
|
* @see_also: #GstSimpleVideoMarkDetect
|
2007-06-01 14:36:04 +00:00
|
|
|
*
|
2019-05-25 14:57:57 +00:00
|
|
|
* This plugin produces #GstSimpleVideoMark:pattern-count squares in the bottom left
|
2017-03-08 18:01:13 +00:00
|
|
|
* corner of the video frames. The squares have a width and height of
|
2013-04-15 07:24:23 +00:00
|
|
|
* respectively #GstSimpleVideoMark:pattern-width and #GstSimpleVideoMark:pattern-height.
|
2008-06-16 07:30:34 +00:00
|
|
|
* Even squares will be black and odd squares will be white.
|
2017-03-08 18:01:13 +00:00
|
|
|
*
|
2013-04-15 07:24:23 +00:00
|
|
|
* After writing the pattern, #GstSimpleVideoMark:pattern-data-count squares after the
|
2008-06-16 07:30:34 +00:00
|
|
|
* pattern squares are produced as the bitarray given in
|
2013-04-15 07:24:23 +00:00
|
|
|
* #GstSimpleVideoMark:pattern-data. 1 bits will produce white squares and 0 bits will
|
2008-06-16 07:30:34 +00:00
|
|
|
* produce black squares.
|
2017-03-08 18:01:13 +00:00
|
|
|
*
|
2013-04-15 07:24:23 +00:00
|
|
|
* The element can be enabled with the #GstSimpleVideoMark:enabled property. It is
|
2019-05-25 14:57:57 +00:00
|
|
|
* mostly used together with the #GstSimpleVideoMarkDetect plugin.
|
2017-03-08 18:01:13 +00:00
|
|
|
*
|
|
|
|
* ## Example launch line
|
2008-06-16 07:30:34 +00:00
|
|
|
* |[
|
2015-12-14 02:09:46 +00:00
|
|
|
* gst-launch-1.0 videotestsrc ! simplevideomark ! videoconvert ! ximagesink
|
2008-06-16 07:30:34 +00:00
|
|
|
* ]| Add the default black/white squares at the bottom left of the video frames.
|
2017-03-08 18:01:13 +00:00
|
|
|
*
|
2007-06-01 14:36:04 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gst/video/video.h>
|
|
|
|
#include <gst/video/gstvideofilter.h>
|
2013-04-15 07:24:23 +00:00
|
|
|
#include "gstsimplevideomark.h"
|
2007-06-01 14:36:04 +00:00
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_video_mark_debug_category);
|
|
|
|
#define GST_CAT_DEFAULT gst_video_mark_debug_category
|
2007-06-01 14:36:04 +00:00
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
/* prototypes */
|
2007-06-01 14:36:04 +00:00
|
|
|
|
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
static void gst_video_mark_set_property (GObject * object,
|
|
|
|
guint property_id, const GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_video_mark_get_property (GObject * object,
|
|
|
|
guint property_id, GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_video_mark_dispose (GObject * object);
|
|
|
|
static void gst_video_mark_finalize (GObject * object);
|
|
|
|
|
|
|
|
static gboolean gst_video_mark_start (GstBaseTransform * trans);
|
|
|
|
static gboolean gst_video_mark_stop (GstBaseTransform * trans);
|
|
|
|
static gboolean gst_video_mark_set_info (GstVideoFilter * filter,
|
|
|
|
GstCaps * incaps, GstVideoInfo * in_info, GstCaps * outcaps,
|
|
|
|
GstVideoInfo * out_info);
|
|
|
|
static GstFlowReturn gst_video_mark_transform_frame_ip (GstVideoFilter * filter,
|
|
|
|
GstVideoFrame * frame);
|
2007-06-01 14:36:04 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_PATTERN_WIDTH,
|
|
|
|
PROP_PATTERN_HEIGHT,
|
|
|
|
PROP_PATTERN_COUNT,
|
|
|
|
PROP_PATTERN_DATA_COUNT,
|
|
|
|
PROP_PATTERN_DATA,
|
2007-06-27 15:33:26 +00:00
|
|
|
PROP_ENABLED,
|
|
|
|
PROP_LEFT_OFFSET,
|
|
|
|
PROP_BOTTOM_OFFSET
|
2007-06-01 14:36:04 +00:00
|
|
|
};
|
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
#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
|
|
|
|
#define DEFAULT_LEFT_OFFSET 0
|
|
|
|
#define DEFAULT_BOTTOM_OFFSET 0
|
2007-06-01 14:36:04 +00:00
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
/* pad templates */
|
2007-06-01 14:36:04 +00:00
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
#define VIDEO_CAPS \
|
|
|
|
GST_VIDEO_CAPS_MAKE( \
|
|
|
|
"{ I420, YV12, Y41B, Y42B, Y444, YUY2, UYVY, AYUV, YVYU }")
|
2007-06-01 14:36:04 +00:00
|
|
|
|
2009-09-04 19:30:27 +00:00
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
/* class initialization */
|
2007-06-01 14:36:04 +00:00
|
|
|
|
2013-04-15 07:24:23 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstSimpleVideoMark, gst_video_mark,
|
|
|
|
GST_TYPE_VIDEO_FILTER,
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_video_mark_debug_category, "simplevideomark",
|
|
|
|
0, "debug category for simplevideomark element"));
|
2021-02-25 14:22:15 +00:00
|
|
|
GST_ELEMENT_REGISTER_DEFINE (simplevideomark, "simplevideomark",
|
|
|
|
GST_RANK_NONE, GST_TYPE_SIMPLE_VIDEO_MARK);
|
2007-06-01 14:36:04 +00:00
|
|
|
|
|
|
|
static void
|
2013-04-15 07:24:23 +00:00
|
|
|
gst_video_mark_class_init (GstSimpleVideoMarkClass * klass)
|
2007-06-01 14:36:04 +00:00
|
|
|
{
|
2013-04-13 22:16:04 +00:00
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GstBaseTransformClass *base_transform_class =
|
|
|
|
GST_BASE_TRANSFORM_CLASS (klass);
|
|
|
|
GstVideoFilterClass *video_filter_class = GST_VIDEO_FILTER_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),
|
|
|
|
"Video marker", "Filter/Effect/Video",
|
|
|
|
"Marks a video signal with a pattern", "Wim Taymans <wim@fluendo.com>");
|
2007-06-01 14:36:04 +00:00
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
gobject_class->set_property = gst_video_mark_set_property;
|
|
|
|
gobject_class->get_property = gst_video_mark_get_property;
|
|
|
|
gobject_class->dispose = gst_video_mark_dispose;
|
|
|
|
gobject_class->finalize = gst_video_mark_finalize;
|
|
|
|
base_transform_class->start = GST_DEBUG_FUNCPTR (gst_video_mark_start);
|
|
|
|
base_transform_class->stop = GST_DEBUG_FUNCPTR (gst_video_mark_stop);
|
|
|
|
video_filter_class->set_info = GST_DEBUG_FUNCPTR (gst_video_mark_set_info);
|
|
|
|
video_filter_class->transform_frame_ip =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_video_mark_transform_frame_ip);
|
2007-06-01 14:36:04 +00:00
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
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_PARAM_STATIC_STRINGS));
|
|
|
|
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_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_PATTERN_COUNT,
|
|
|
|
g_param_spec_int ("pattern-count", "Pattern count",
|
|
|
|
"The number of pattern markers", 0, G_MAXINT,
|
|
|
|
DEFAULT_PATTERN_COUNT,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
|
|
|
|
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, 64,
|
|
|
|
DEFAULT_PATTERN_DATA_COUNT,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_PATTERN_DATA,
|
|
|
|
g_param_spec_uint64 ("pattern-data", "Pattern data",
|
|
|
|
"The extra data pattern markers", 0, G_MAXUINT64,
|
|
|
|
DEFAULT_PATTERN_DATA,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
|
|
|
|
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 | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_LEFT_OFFSET,
|
|
|
|
g_param_spec_int ("left-offset", "Left Offset",
|
|
|
|
"The offset from the left border where the pattern starts", 0,
|
|
|
|
G_MAXINT, DEFAULT_LEFT_OFFSET,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
|
|
|
|
g_object_class_install_property (gobject_class, PROP_BOTTOM_OFFSET,
|
|
|
|
g_param_spec_int ("bottom-offset", "Bottom Offset",
|
|
|
|
"The offset from the bottom border where the pattern starts", 0,
|
|
|
|
G_MAXINT, DEFAULT_BOTTOM_OFFSET,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
|
2009-09-05 23:44:05 +00:00
|
|
|
|
2007-06-01 14:36:04 +00:00
|
|
|
}
|
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
static void
|
2013-04-15 07:24:23 +00:00
|
|
|
gst_video_mark_init (GstSimpleVideoMark * simplevideomark)
|
2007-06-01 14:36:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
void
|
|
|
|
gst_video_mark_set_property (GObject * object, guint property_id,
|
2007-06-01 14:36:04 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2013-04-15 07:24:23 +00:00
|
|
|
GstSimpleVideoMark *simplevideomark = GST_SIMPLE_VIDEO_MARK (object);
|
2007-06-01 14:36:04 +00:00
|
|
|
|
2013-04-15 07:24:23 +00:00
|
|
|
GST_DEBUG_OBJECT (simplevideomark, "set_property");
|
2007-06-01 14:36:04 +00:00
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
switch (property_id) {
|
2007-06-01 14:36:04 +00:00
|
|
|
case PROP_PATTERN_WIDTH:
|
2013-04-15 07:24:23 +00:00
|
|
|
simplevideomark->pattern_width = g_value_get_int (value);
|
2007-06-01 14:36:04 +00:00
|
|
|
break;
|
|
|
|
case PROP_PATTERN_HEIGHT:
|
2013-04-15 07:24:23 +00:00
|
|
|
simplevideomark->pattern_height = g_value_get_int (value);
|
2007-06-01 14:36:04 +00:00
|
|
|
break;
|
|
|
|
case PROP_PATTERN_COUNT:
|
2013-04-15 07:24:23 +00:00
|
|
|
simplevideomark->pattern_count = g_value_get_int (value);
|
2007-06-01 14:36:04 +00:00
|
|
|
break;
|
|
|
|
case PROP_PATTERN_DATA_COUNT:
|
2013-04-15 07:24:23 +00:00
|
|
|
simplevideomark->pattern_data_count = g_value_get_int (value);
|
2007-06-01 14:36:04 +00:00
|
|
|
break;
|
|
|
|
case PROP_PATTERN_DATA:
|
2013-04-15 07:24:23 +00:00
|
|
|
simplevideomark->pattern_data = g_value_get_uint64 (value);
|
2007-06-01 14:36:04 +00:00
|
|
|
break;
|
|
|
|
case PROP_ENABLED:
|
2013-04-15 07:24:23 +00:00
|
|
|
simplevideomark->enabled = g_value_get_boolean (value);
|
2007-06-01 14:36:04 +00:00
|
|
|
break;
|
2007-06-27 15:33:26 +00:00
|
|
|
case PROP_LEFT_OFFSET:
|
2013-04-15 07:24:23 +00:00
|
|
|
simplevideomark->left_offset = g_value_get_int (value);
|
2007-06-27 15:33:26 +00:00
|
|
|
break;
|
|
|
|
case PROP_BOTTOM_OFFSET:
|
2013-04-15 07:24:23 +00:00
|
|
|
simplevideomark->bottom_offset = g_value_get_int (value);
|
2007-06-27 15:33:26 +00:00
|
|
|
break;
|
2007-06-01 14:36:04 +00:00
|
|
|
default:
|
2013-04-13 22:16:04 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
2007-06-01 14:36:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
void
|
|
|
|
gst_video_mark_get_property (GObject * object, guint property_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
2007-06-01 14:36:04 +00:00
|
|
|
{
|
2013-04-15 07:24:23 +00:00
|
|
|
GstSimpleVideoMark *simplevideomark = GST_SIMPLE_VIDEO_MARK (object);
|
2007-06-01 14:36:04 +00:00
|
|
|
|
2013-04-15 07:24:23 +00:00
|
|
|
GST_DEBUG_OBJECT (simplevideomark, "get_property");
|
2007-06-01 14:36:04 +00:00
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
switch (property_id) {
|
2007-06-01 14:36:04 +00:00
|
|
|
case PROP_PATTERN_WIDTH:
|
2013-04-15 07:24:23 +00:00
|
|
|
g_value_set_int (value, simplevideomark->pattern_width);
|
2007-06-01 14:36:04 +00:00
|
|
|
break;
|
|
|
|
case PROP_PATTERN_HEIGHT:
|
2013-04-15 07:24:23 +00:00
|
|
|
g_value_set_int (value, simplevideomark->pattern_height);
|
2007-06-01 14:36:04 +00:00
|
|
|
break;
|
|
|
|
case PROP_PATTERN_COUNT:
|
2013-04-15 07:24:23 +00:00
|
|
|
g_value_set_int (value, simplevideomark->pattern_count);
|
2007-06-01 14:36:04 +00:00
|
|
|
break;
|
|
|
|
case PROP_PATTERN_DATA_COUNT:
|
2013-04-15 07:24:23 +00:00
|
|
|
g_value_set_int (value, simplevideomark->pattern_data_count);
|
2007-06-01 14:36:04 +00:00
|
|
|
break;
|
|
|
|
case PROP_PATTERN_DATA:
|
2013-04-15 07:24:23 +00:00
|
|
|
g_value_set_uint64 (value, simplevideomark->pattern_data);
|
2007-06-01 14:36:04 +00:00
|
|
|
break;
|
|
|
|
case PROP_ENABLED:
|
2013-04-15 07:24:23 +00:00
|
|
|
g_value_set_boolean (value, simplevideomark->enabled);
|
2007-06-01 14:36:04 +00:00
|
|
|
break;
|
2007-06-27 15:33:26 +00:00
|
|
|
case PROP_LEFT_OFFSET:
|
2013-04-15 07:24:23 +00:00
|
|
|
g_value_set_int (value, simplevideomark->left_offset);
|
2007-06-27 15:33:26 +00:00
|
|
|
break;
|
|
|
|
case PROP_BOTTOM_OFFSET:
|
2013-04-15 07:24:23 +00:00
|
|
|
g_value_set_int (value, simplevideomark->bottom_offset);
|
2007-06-27 15:33:26 +00:00
|
|
|
break;
|
2007-06-01 14:36:04 +00:00
|
|
|
default:
|
2013-04-13 22:16:04 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
2007-06-01 14:36:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
void
|
|
|
|
gst_video_mark_dispose (GObject * object)
|
2007-06-01 14:36:04 +00:00
|
|
|
{
|
2013-04-15 07:24:23 +00:00
|
|
|
GstSimpleVideoMark *simplevideomark = GST_SIMPLE_VIDEO_MARK (object);
|
2007-06-01 14:36:04 +00:00
|
|
|
|
2013-04-15 07:24:23 +00:00
|
|
|
GST_DEBUG_OBJECT (simplevideomark, "dispose");
|
2013-04-13 22:16:04 +00:00
|
|
|
|
|
|
|
/* clean up as possible. may be called multiple times */
|
2007-06-01 14:36:04 +00:00
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
G_OBJECT_CLASS (gst_video_mark_parent_class)->dispose (object);
|
2007-06-01 14:36:04 +00:00
|
|
|
}
|
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
void
|
|
|
|
gst_video_mark_finalize (GObject * object)
|
2007-06-01 14:36:04 +00:00
|
|
|
{
|
2013-04-15 07:24:23 +00:00
|
|
|
GstSimpleVideoMark *simplevideomark = GST_SIMPLE_VIDEO_MARK (object);
|
2007-06-01 14:36:04 +00:00
|
|
|
|
2013-04-15 07:24:23 +00:00
|
|
|
GST_DEBUG_OBJECT (simplevideomark, "finalize");
|
2007-06-01 14:36:04 +00:00
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
/* clean up object here */
|
2007-06-01 14:36:04 +00:00
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
G_OBJECT_CLASS (gst_video_mark_parent_class)->finalize (object);
|
|
|
|
}
|
2007-06-01 14:36:04 +00:00
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
static gboolean
|
|
|
|
gst_video_mark_start (GstBaseTransform * trans)
|
|
|
|
{
|
2013-04-15 07:24:23 +00:00
|
|
|
GstSimpleVideoMark *simplevideomark = GST_SIMPLE_VIDEO_MARK (trans);
|
2007-06-01 14:36:04 +00:00
|
|
|
|
2013-04-15 07:24:23 +00:00
|
|
|
GST_DEBUG_OBJECT (simplevideomark, "start");
|
2007-06-01 14:36:04 +00:00
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
return TRUE;
|
2007-06-01 14:36:04 +00:00
|
|
|
}
|
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
static gboolean
|
|
|
|
gst_video_mark_stop (GstBaseTransform * trans)
|
2007-06-01 14:36:04 +00:00
|
|
|
{
|
2013-04-15 07:24:23 +00:00
|
|
|
GstSimpleVideoMark *simplevideomark = GST_SIMPLE_VIDEO_MARK (trans);
|
2007-06-01 14:36:04 +00:00
|
|
|
|
2013-04-15 07:24:23 +00:00
|
|
|
GST_DEBUG_OBJECT (simplevideomark, "stop");
|
2007-06-01 14:36:04 +00:00
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
return TRUE;
|
2007-06-01 14:36:04 +00:00
|
|
|
}
|
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
static gboolean
|
|
|
|
gst_video_mark_set_info (GstVideoFilter * filter, GstCaps * incaps,
|
|
|
|
GstVideoInfo * in_info, GstCaps * outcaps, GstVideoInfo * out_info)
|
|
|
|
{
|
2013-04-15 07:24:23 +00:00
|
|
|
GstSimpleVideoMark *simplevideomark = GST_SIMPLE_VIDEO_MARK (filter);
|
2013-04-13 22:16:04 +00:00
|
|
|
|
2013-04-15 07:24:23 +00:00
|
|
|
GST_DEBUG_OBJECT (simplevideomark, "set_info");
|
2013-04-13 22:16:04 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-04-15 07:24:23 +00:00
|
|
|
gst_video_mark_draw_box (GstSimpleVideoMark * simplevideomark, guint8 * data,
|
2013-04-13 22:16:04 +00:00
|
|
|
gint width, gint height, gint row_stride, gint pixel_stride, guint8 color)
|
2007-06-01 14:36:04 +00:00
|
|
|
{
|
2013-04-13 22:16:04 +00:00
|
|
|
gint i, j;
|
|
|
|
|
|
|
|
for (i = 0; i < height; i++) {
|
|
|
|
for (j = 0; j < width; j++) {
|
|
|
|
data[pixel_stride * j] = color;
|
|
|
|
}
|
|
|
|
data += row_stride;
|
2007-06-01 14:36:04 +00:00
|
|
|
}
|
2013-04-13 22:16:04 +00:00
|
|
|
}
|
|
|
|
|
2015-06-02 01:21:42 +00:00
|
|
|
static gint
|
|
|
|
calculate_pw (gint pw, gint x, gint width)
|
|
|
|
{
|
|
|
|
if (x < 0)
|
|
|
|
pw += x;
|
|
|
|
else if ((x + pw) > width)
|
|
|
|
pw = width - x;
|
|
|
|
|
|
|
|
return pw;
|
|
|
|
}
|
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
static GstFlowReturn
|
2013-04-15 07:24:23 +00:00
|
|
|
gst_video_mark_yuv (GstSimpleVideoMark * simplevideomark, GstVideoFrame * frame)
|
2013-04-13 22:16:04 +00:00
|
|
|
{
|
|
|
|
gint i, pw, ph, row_stride, pixel_stride;
|
2015-06-02 01:21:42 +00:00
|
|
|
gint width, height, offset_calc, x, y;
|
2013-04-13 22:16:04 +00:00
|
|
|
guint8 *d;
|
|
|
|
guint64 pattern_shift;
|
|
|
|
guint8 color;
|
2015-06-02 01:21:42 +00:00
|
|
|
gint total_pattern;
|
2013-04-13 22:16:04 +00:00
|
|
|
|
|
|
|
width = frame->info.width;
|
|
|
|
height = frame->info.height;
|
|
|
|
|
2013-04-15 07:24:23 +00:00
|
|
|
pw = simplevideomark->pattern_width;
|
|
|
|
ph = simplevideomark->pattern_height;
|
2013-04-13 22:16:04 +00:00
|
|
|
row_stride = GST_VIDEO_FRAME_COMP_STRIDE (frame, 0);
|
|
|
|
pixel_stride = GST_VIDEO_FRAME_COMP_PSTRIDE (frame, 0);
|
|
|
|
|
2015-02-12 06:34:44 +00:00
|
|
|
d = GST_VIDEO_FRAME_COMP_DATA (frame, 0);
|
2015-06-02 01:21:42 +00:00
|
|
|
offset_calc =
|
|
|
|
row_stride * (height - ph - simplevideomark->bottom_offset) +
|
2015-02-12 06:34:44 +00:00
|
|
|
pixel_stride * simplevideomark->left_offset;
|
2015-06-02 01:21:42 +00:00
|
|
|
x = simplevideomark->left_offset;
|
|
|
|
y = height - ph - simplevideomark->bottom_offset;
|
|
|
|
|
|
|
|
total_pattern =
|
|
|
|
simplevideomark->pattern_count + simplevideomark->pattern_data_count;
|
|
|
|
/* If x and y offset values are outside the video, no need to draw */
|
|
|
|
if ((x + (pw * total_pattern)) < 0 || x > width || (y + height) < 0
|
2015-06-04 23:53:30 +00:00
|
|
|
|| y > height) {
|
|
|
|
GST_ERROR_OBJECT (simplevideomark,
|
|
|
|
"simplevideomark pattern is outside the video. Not drawing.");
|
2015-06-02 01:21:42 +00:00
|
|
|
return GST_FLOW_OK;
|
2015-06-04 23:53:30 +00:00
|
|
|
}
|
2015-06-02 01:21:42 +00:00
|
|
|
|
|
|
|
/* Offset calculation less than 0, then reset to 0 */
|
|
|
|
if (offset_calc < 0)
|
|
|
|
offset_calc = 0;
|
|
|
|
/* Y position of mark is negative or pattern exceeds the video height,
|
|
|
|
then recalculate pattern height for partial display */
|
|
|
|
if (y < 0)
|
|
|
|
ph += y;
|
|
|
|
else if ((y + ph) > height)
|
|
|
|
ph = height - y;
|
|
|
|
/* If pattern height is less than 0, need not draw anything */
|
|
|
|
if (ph < 0)
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
|
|
|
|
/* move to start of bottom left */
|
|
|
|
d += offset_calc;
|
2015-02-12 06:34:44 +00:00
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
/* draw the bottom left pixels */
|
2013-04-15 07:24:23 +00:00
|
|
|
for (i = 0; i < simplevideomark->pattern_count; i++) {
|
2015-06-02 01:21:42 +00:00
|
|
|
gint draw_pw;
|
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
if (i & 1)
|
|
|
|
/* odd pixels must be white */
|
|
|
|
color = 255;
|
|
|
|
else
|
|
|
|
color = 0;
|
|
|
|
|
2015-06-02 01:21:42 +00:00
|
|
|
/* X position of mark is negative or pattern exceeds the video width,
|
|
|
|
then recalculate pattern width for partial display */
|
|
|
|
draw_pw = calculate_pw (pw, x, width);
|
|
|
|
/* If pattern width is less than 0, continue with the next pattern */
|
|
|
|
if (draw_pw < 0)
|
|
|
|
continue;
|
|
|
|
|
2013-04-13 22:16:04 +00:00
|
|
|
/* draw box of width * height */
|
2015-06-02 01:21:42 +00:00
|
|
|
gst_video_mark_draw_box (simplevideomark, d, draw_pw, ph, row_stride,
|
2013-04-15 07:24:23 +00:00
|
|
|
pixel_stride, color);
|
2015-02-12 06:34:44 +00:00
|
|
|
|
|
|
|
/* move to i-th pattern */
|
2015-06-02 01:21:42 +00:00
|
|
|
d += pixel_stride * draw_pw;
|
|
|
|
x += draw_pw;
|
|
|
|
|
|
|
|
if ((x + (pw * (total_pattern - i - 1))) < 0 || x >= width)
|
|
|
|
return GST_FLOW_OK;
|
2013-04-13 22:16:04 +00:00
|
|
|
}
|
|
|
|
|
2013-04-15 07:24:23 +00:00
|
|
|
pattern_shift =
|
|
|
|
G_GUINT64_CONSTANT (1) << (simplevideomark->pattern_data_count - 1);
|
2013-04-13 22:16:04 +00:00
|
|
|
|
|
|
|
/* get the data of the pattern */
|
2013-04-15 07:24:23 +00:00
|
|
|
for (i = 0; i < simplevideomark->pattern_data_count; i++) {
|
2015-06-02 01:21:42 +00:00
|
|
|
gint draw_pw;
|
2013-04-15 07:24:23 +00:00
|
|
|
if (simplevideomark->pattern_data & pattern_shift)
|
2013-04-13 22:16:04 +00:00
|
|
|
color = 255;
|
|
|
|
else
|
|
|
|
color = 0;
|
|
|
|
|
2015-06-02 01:21:42 +00:00
|
|
|
/* X position of mark is negative or pattern exceeds the video width,
|
|
|
|
then recalculate pattern width for partial display */
|
|
|
|
draw_pw = calculate_pw (pw, x, width);
|
|
|
|
/* If pattern width is less than 0, continue with the next pattern */
|
|
|
|
if (draw_pw < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
gst_video_mark_draw_box (simplevideomark, d, draw_pw, ph, row_stride,
|
2013-04-15 07:24:23 +00:00
|
|
|
pixel_stride, color);
|
2013-04-13 22:16:04 +00:00
|
|
|
|
|
|
|
pattern_shift >>= 1;
|
2015-02-12 06:34:44 +00:00
|
|
|
|
|
|
|
/* move to i-th pattern data */
|
2015-06-02 01:21:42 +00:00
|
|
|
d += pixel_stride * draw_pw;
|
|
|
|
x += draw_pw;
|
|
|
|
|
|
|
|
if ((x + (pw * (simplevideomark->pattern_data_count - i - 1))) < 0
|
|
|
|
|| x >= width)
|
|
|
|
return GST_FLOW_OK;
|
2013-04-13 22:16:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_video_mark_transform_frame_ip (GstVideoFilter * filter,
|
|
|
|
GstVideoFrame * frame)
|
|
|
|
{
|
2013-04-15 07:24:23 +00:00
|
|
|
GstSimpleVideoMark *simplevideomark = GST_SIMPLE_VIDEO_MARK (filter);
|
2013-04-13 22:16:04 +00:00
|
|
|
|
2013-04-15 07:24:23 +00:00
|
|
|
GST_DEBUG_OBJECT (simplevideomark, "transform_frame_ip");
|
2013-04-13 22:16:04 +00:00
|
|
|
|
2013-04-15 07:24:23 +00:00
|
|
|
if (simplevideomark->enabled)
|
|
|
|
return gst_video_mark_yuv (simplevideomark, frame);
|
2013-04-13 22:16:04 +00:00
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
2007-06-01 14:36:04 +00:00
|
|
|
}
|