mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 16:50:47 +00:00
qroverlay: Add a qroverlay element that allows overlaying any data
This moves `gstqroverlay.c` to `gstdebugqroverlay.c` and implements a simple `gstqroverlay` element. Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1730>
This commit is contained in:
parent
7d9f125ab1
commit
e7ec9986ca
5 changed files with 387 additions and 201 deletions
279
ext/qroverlay/gstdebugqroverlay.c
Executable file
279
ext/qroverlay/gstdebugqroverlay.c
Executable file
|
@ -0,0 +1,279 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (C) 2006 Stefan Kost <ensonic@users.sf.net>
|
||||
* Copyright (c) 2020 Anthony Violo <anthony.violo@ubicast.eu>
|
||||
*
|
||||
* 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-debugqroverlay
|
||||
*
|
||||
* This element will build a Json string that contains a description of the
|
||||
* buffer and will convert the string to a QRcode. The QRcode contains a
|
||||
* timestamp, a buffer number, a framerate and some custom extra-data. Each
|
||||
* frame will have a Qrcode overlaid in the video stream. Some properties are
|
||||
* available to set the position and to define its size. You can add custom data
|
||||
* with the properties #debugqroverlay:extra-data-name and
|
||||
* #debugqroverlay:extra-data-array. You can also define the quality of the Qrcode
|
||||
* with #debugqroverlay:qrcode-error-correction. You can also define interval and
|
||||
* span of #debugqroverlay:extra-data-name #debugqroverlay:extra-data-array
|
||||
*
|
||||
* ## Example launch line
|
||||
*
|
||||
* ``` bash
|
||||
* gst-launch -v -m videotestsrc ! debugqroverlay ! fakesink silent=TRUE
|
||||
* ```
|
||||
*
|
||||
* Since: 1.20
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/base/gstbasetransform.h>
|
||||
#include <json-glib/json-glib.h>
|
||||
|
||||
#include <qrencode.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "gstdebugqroverlay.h"
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (gst_debug_qr_overlay_debug);
|
||||
#define GST_CAT_DEFAULT gst_debug_qr_overlay_debug
|
||||
|
||||
static gchar *get_qrcode_content (GstBaseQROverlay * filter,
|
||||
GstVideoFrame * frame);
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_DATA_INTERVAL_BUFFERS,
|
||||
PROP_DATA_SPAN_BUFFERS,
|
||||
PROP_EXTRA_DATA_NAME,
|
||||
PROP_EXTRA_DATA_ARRAY,
|
||||
};
|
||||
|
||||
struct _GstDebugQROverlay
|
||||
{
|
||||
GstBaseQROverlay parent;
|
||||
|
||||
guint32 frame_number;
|
||||
guint array_counter;
|
||||
guint array_size;
|
||||
guint span_frame;
|
||||
guint64 extra_data_interval_buffers;
|
||||
guint64 extra_data_span_buffers;
|
||||
gchar *extra_data_name;
|
||||
gchar *extra_data_str;
|
||||
gchar **extra_data_array;
|
||||
gfloat x_percent;
|
||||
gfloat y_percent;
|
||||
gboolean silent;
|
||||
gboolean extra_data_enabled;
|
||||
};
|
||||
|
||||
#define DEFAULT_PROP_QUALITY 1
|
||||
#define DEFAULT_PROP_PIXEL_SIZE 3
|
||||
|
||||
#define gst_debug_qr_overlay_parent_class parent_class
|
||||
G_DEFINE_TYPE (GstDebugQROverlay, gst_debug_qr_overlay,
|
||||
GST_TYPE_BASE_QR_OVERLAY);
|
||||
|
||||
static void gst_debug_qr_overlay_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec);
|
||||
static void gst_debug_qr_overlay_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec);
|
||||
|
||||
/* initialize the qroverlay's class */
|
||||
static void
|
||||
gst_debug_qr_overlay_class_init (GstDebugQROverlayClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
GstElementClass *gstelement_class;
|
||||
|
||||
gobject_class = (GObjectClass *) klass;
|
||||
gstelement_class = (GstElementClass *) klass;
|
||||
|
||||
GST_DEBUG_CATEGORY_INIT (gst_debug_qr_overlay_debug, "debugqroverlay", 0,
|
||||
"Qrcode overlay element");
|
||||
|
||||
gobject_class->set_property = gst_debug_qr_overlay_set_property;
|
||||
gobject_class->get_property = gst_debug_qr_overlay_get_property;
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_DATA_INTERVAL_BUFFERS,
|
||||
g_param_spec_int64 ("extra-data-interval-buffers",
|
||||
"extra-data-interval-buffers",
|
||||
"Extra data append into the Qrcode at the first buffer of each "
|
||||
" interval", 0, G_MAXINT64, 60, G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_DATA_SPAN_BUFFERS, g_param_spec_int64 ("extra-data-span-buffers",
|
||||
"extra-data-span-buffers",
|
||||
"Numbers of consecutive buffers that the extra data will be inserted "
|
||||
" (counting the first buffer)", 0, G_MAXINT64, 1, G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_EXTRA_DATA_NAME, g_param_spec_string ("extra-data-name",
|
||||
"Extra data name",
|
||||
"Json key name for extra append data", NULL, G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_EXTRA_DATA_ARRAY, g_param_spec_string ("extra-data-array",
|
||||
"Extra data array",
|
||||
"List of comma separated values that the extra data value will be "
|
||||
" cycled from at each interval, example array structure :"
|
||||
" \"240,480,720,960,1200,1440,1680,1920\"", NULL, G_PARAM_READWRITE));
|
||||
|
||||
|
||||
gst_element_class_set_details_simple (gstelement_class,
|
||||
"qroverlay",
|
||||
"Qrcode overlay containing buffer information",
|
||||
"Overlay Qrcodes over each buffer with buffer information and custom data",
|
||||
"Anthony Violo <anthony.violo@ubicast.eu>");
|
||||
|
||||
gst_type_mark_as_plugin_api (GST_TYPE_BASE_QR_OVERLAY, 0);
|
||||
|
||||
GST_BASE_QR_OVERLAY_CLASS (klass)->get_content =
|
||||
GST_DEBUG_FUNCPTR (get_qrcode_content);
|
||||
}
|
||||
|
||||
/* initialize the new element
|
||||
* initialize instance structure
|
||||
*/
|
||||
static void
|
||||
gst_debug_qr_overlay_init (GstDebugQROverlay * filter)
|
||||
{
|
||||
filter->frame_number = 1;
|
||||
filter->x_percent = 50.0;
|
||||
filter->y_percent = 50.0;
|
||||
filter->array_counter = 0;
|
||||
filter->array_size = 0;
|
||||
filter->extra_data_interval_buffers = 60;
|
||||
filter->extra_data_span_buffers = 1;
|
||||
filter->span_frame = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_debug_qr_overlay_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstDebugQROverlay *filter = GST_DEBUG_QR_OVERLAY (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DATA_INTERVAL_BUFFERS:
|
||||
filter->extra_data_interval_buffers = g_value_get_int64 (value);
|
||||
break;
|
||||
case PROP_DATA_SPAN_BUFFERS:
|
||||
filter->extra_data_span_buffers = g_value_get_int64 (value);
|
||||
break;
|
||||
case PROP_EXTRA_DATA_NAME:
|
||||
filter->extra_data_name = g_value_dup_string (value);
|
||||
break;
|
||||
case PROP_EXTRA_DATA_ARRAY:
|
||||
{
|
||||
g_clear_pointer (&filter->extra_data_str, g_free);
|
||||
g_clear_pointer (&filter->extra_data_array, g_strfreev);
|
||||
filter->extra_data_str = g_value_dup_string (value);
|
||||
if (filter->extra_data_str) {
|
||||
filter->extra_data_array = g_strsplit (filter->extra_data_str, ",", -1);
|
||||
filter->array_size = g_strv_length (filter->extra_data_array);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_debug_qr_overlay_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstDebugQROverlay *filter = GST_DEBUG_QR_OVERLAY (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DATA_INTERVAL_BUFFERS:
|
||||
g_value_set_int64 (value, filter->extra_data_interval_buffers);
|
||||
break;
|
||||
case PROP_DATA_SPAN_BUFFERS:
|
||||
g_value_set_int64 (value, filter->extra_data_span_buffers);
|
||||
break;
|
||||
case PROP_EXTRA_DATA_NAME:
|
||||
g_value_set_string (value, filter->extra_data_name);
|
||||
break;
|
||||
case PROP_EXTRA_DATA_ARRAY:
|
||||
g_value_set_string (value, filter->extra_data_str);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static gchar *
|
||||
get_qrcode_content (GstBaseQROverlay * base, GstVideoFrame * frame)
|
||||
{
|
||||
GstDebugQROverlay *filter = GST_DEBUG_QR_OVERLAY (base);
|
||||
GstBuffer *buf = frame->buffer;
|
||||
GString *res = g_string_new (NULL);
|
||||
JsonGenerator *jgen;
|
||||
gchar *framerate_string =
|
||||
g_strdup_printf ("%d/%d", frame->info.fps_n, frame->info.fps_d);
|
||||
|
||||
JsonObject *jobj = json_object_new ();
|
||||
JsonNode *root = json_node_new (JSON_NODE_OBJECT);
|
||||
|
||||
json_object_set_int_member (jobj, "TIMESTAMP",
|
||||
(gint64) GST_BUFFER_TIMESTAMP (buf));
|
||||
json_object_set_int_member (jobj, "BUFFERCOUNT",
|
||||
(gint64) filter->frame_number);
|
||||
json_object_set_string_member (jobj, "FRAMERATE", framerate_string);
|
||||
json_object_set_string_member (jobj, "NAME", GST_ELEMENT_NAME (filter));
|
||||
g_free (framerate_string);
|
||||
|
||||
if (filter->extra_data_array && filter->extra_data_name &&
|
||||
(filter->frame_number == 1
|
||||
|| filter->frame_number % filter->extra_data_interval_buffers == 1
|
||||
|| (filter->span_frame > 0
|
||||
&& filter->span_frame < filter->extra_data_span_buffers))) {
|
||||
json_object_set_string_member (jobj, filter->extra_data_name,
|
||||
filter->extra_data_array[filter->array_counter]);
|
||||
|
||||
filter->span_frame++;
|
||||
if (filter->span_frame == filter->extra_data_span_buffers) {
|
||||
filter->array_counter++;
|
||||
filter->span_frame = 0;
|
||||
if (filter->array_counter >= filter->array_size)
|
||||
filter->array_counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
jgen = json_generator_new ();
|
||||
json_node_set_object (root, jobj);
|
||||
json_generator_set_root (jgen, root);
|
||||
res = json_generator_to_gstring (jgen, res);
|
||||
g_object_unref (jgen);
|
||||
filter->frame_number++;
|
||||
|
||||
return g_strdup (g_string_free (res, FALSE));
|
||||
}
|
33
ext/qroverlay/gstdebugqroverlay.h
Executable file
33
ext/qroverlay/gstdebugqroverlay.h
Executable file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* GStreamer
|
||||
* Copyright (C) 2006 Stefan Kost <ensonic@users.sf.net>
|
||||
* Copyright (c) 2020 Anthony Violo <anthony.violo@ubicast.eu>
|
||||
*
|
||||
* 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_DEBUG_QR_OVERLAY_H__
|
||||
#define __GST_DEBUG_QR_OVERLAY_H__
|
||||
|
||||
#include "gstbaseqroverlay.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
#define GST_TYPE_DEBUG_QR_OVERLAY (gst_debug_qr_overlay_get_type())
|
||||
|
||||
G_DECLARE_FINAL_TYPE (GstDebugQROverlay, gst_debug_qr_overlay, GST, DEBUG_QR_OVERLAY, GstBaseQROverlay);
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* __GST_DEBUG_QR_OVERLAY_H__ */
|
|
@ -2,6 +2,7 @@
|
|||
* GStreamer
|
||||
* Copyright (C) 2006 Stefan Kost <ensonic@users.sf.net>
|
||||
* Copyright (c) 2020 Anthony Violo <anthony.violo@ubicast.eu>
|
||||
* Copyright (c) 2020 Thibault Saunier <tsaunier@igalia.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
|
@ -20,17 +21,9 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* SECTION:element-debugqroverlay
|
||||
* SECTION:element-qroverlay
|
||||
*
|
||||
* This element will build a Json string that contains a description of the
|
||||
* buffer and will convert the string to a QRcode. The QRcode contains a
|
||||
* timestamp, a buffer number, a framerate and some custom extra-data. Each
|
||||
* frame will have a Qrcode overlaid in the video stream. Some properties are
|
||||
* available to set the position and to define its size. You can add custom data
|
||||
* with the properties #qroverlay:extra-data-name and
|
||||
* #qroverlay:extra-data-array. You can also define the quality of the Qrcode
|
||||
* with #qroverlay:qrcode-error-correction. You can also define interval and
|
||||
* span of #qrovlerlay:extra-data-name #qrovlerlay:extra-data-array
|
||||
* Element to set random data on a qroverlay.
|
||||
*
|
||||
* ## Example launch line
|
||||
*
|
||||
|
@ -56,55 +49,64 @@
|
|||
|
||||
#include "gstqroverlay.h"
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (gst_debug_qr_overlay_debug);
|
||||
#define GST_CAT_DEFAULT gst_debug_qr_overlay_debug
|
||||
|
||||
static gchar *get_qrcode_content (GstBaseQROverlay * filter,
|
||||
GstVideoFrame * frame);
|
||||
GST_DEBUG_CATEGORY_STATIC (gst_qr_overlay_debug);
|
||||
#define GST_CAT_DEFAULT gst_qr_overlay_debug
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_DATA_INTERVAL_BUFFERS,
|
||||
PROP_DATA_SPAN_BUFFERS,
|
||||
PROP_EXTRA_DATA_NAME,
|
||||
PROP_EXTRA_DATA_ARRAY,
|
||||
PROP_DATA,
|
||||
};
|
||||
|
||||
struct _GstDebugQROverlay
|
||||
struct _GstQROverlay
|
||||
{
|
||||
GstBaseQROverlay parent;
|
||||
|
||||
guint32 frame_number;
|
||||
guint array_counter;
|
||||
guint array_size;
|
||||
guint span_frame;
|
||||
guint64 extra_data_interval_buffers;
|
||||
guint64 extra_data_span_buffers;
|
||||
gchar *extra_data_name;
|
||||
gchar *extra_data_str;
|
||||
gchar **extra_data_array;
|
||||
gfloat x_percent;
|
||||
gfloat y_percent;
|
||||
gboolean silent;
|
||||
gboolean extra_data_enabled;
|
||||
gchar *data;
|
||||
};
|
||||
|
||||
#define DEFAULT_PROP_QUALITY 1
|
||||
#define DEFAULT_PROP_PIXEL_SIZE 3
|
||||
#define gst_qr_overlay_parent_class parent_class
|
||||
G_DEFINE_TYPE (GstQROverlay, gst_qr_overlay, GST_TYPE_BASE_QR_OVERLAY);
|
||||
|
||||
#define gst_debug_qr_overlay_parent_class parent_class
|
||||
G_DEFINE_TYPE (GstDebugQROverlay, gst_debug_qr_overlay,
|
||||
GST_TYPE_BASE_QR_OVERLAY);
|
||||
static gchar *
|
||||
get_qrcode_content (GstBaseQROverlay * filter, GstVideoFrame * frame)
|
||||
{
|
||||
return g_strdup (GST_QR_OVERLAY (filter)->data);
|
||||
}
|
||||
|
||||
static void gst_debug_qr_overlay_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec);
|
||||
static void gst_debug_qr_overlay_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec);
|
||||
|
||||
/* initialize the qroverlay's class */
|
||||
static void
|
||||
gst_debug_qr_overlay_class_init (GstDebugQROverlayClass * klass)
|
||||
gst_qr_overlay_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstQROverlay *self = GST_QR_OVERLAY (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DATA:
|
||||
self->data = g_value_dup_string (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_qr_overlay_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstQROverlay *self = GST_QR_OVERLAY (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DATA:
|
||||
g_value_set_string (value, self->data);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_qr_overlay_class_init (GstQROverlayClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
GstElementClass *gstelement_class;
|
||||
|
@ -112,42 +114,22 @@ gst_debug_qr_overlay_class_init (GstDebugQROverlayClass * klass)
|
|||
gobject_class = (GObjectClass *) klass;
|
||||
gstelement_class = (GstElementClass *) klass;
|
||||
|
||||
gobject_class->set_property = gst_debug_qr_overlay_set_property;
|
||||
gobject_class->get_property = gst_debug_qr_overlay_get_property;
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_DATA_INTERVAL_BUFFERS,
|
||||
g_param_spec_int64 ("extra-data-interval-buffers",
|
||||
"extra-data-interval-buffers",
|
||||
"Extra data append into the Qrcode at the first buffer of each "
|
||||
" interval", 0, G_MAXINT64, 60, G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_DATA_SPAN_BUFFERS, g_param_spec_int64 ("extra-data-span-buffers",
|
||||
"extra-data-span-buffers",
|
||||
"Numbers of consecutive buffers that the extra data will be inserted "
|
||||
" (counting the first buffer)", 0, G_MAXINT64, 1, G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_EXTRA_DATA_NAME, g_param_spec_string ("extra-data-name",
|
||||
"Extra data name",
|
||||
"Json key name for extra append data", NULL, G_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_EXTRA_DATA_ARRAY, g_param_spec_string ("extra-data-array",
|
||||
"Extra data array",
|
||||
"List of comma separated values that the extra data value will be "
|
||||
" cycled from at each interval, example array structure :"
|
||||
" \"240,480,720,960,1200,1440,1680,1920\"", NULL, G_PARAM_READWRITE));
|
||||
|
||||
gobject_class->set_property = gst_qr_overlay_set_property;
|
||||
gobject_class->get_property = gst_qr_overlay_get_property;
|
||||
|
||||
gst_element_class_set_details_simple (gstelement_class,
|
||||
"qroverlay",
|
||||
"Qrcode overlay containing buffer information",
|
||||
"Overlay Qrcodes over each buffer with buffer information and custom data",
|
||||
"Anthony Violo <anthony.violo@ubicast.eu>");
|
||||
"Qrcode overlay containing random data",
|
||||
"Overlay Qrcodes over each buffer with data passed in",
|
||||
"Thibault Saunier <tsaunier@igalia.com>");
|
||||
|
||||
gst_type_mark_as_plugin_api (GST_TYPE_BASE_QR_OVERLAY, 0);
|
||||
g_object_class_install_property (gobject_class,
|
||||
PROP_DATA, g_param_spec_string ("data",
|
||||
"Data",
|
||||
"Data to write in the QRCode to be overlaid",
|
||||
NULL,
|
||||
G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING |
|
||||
GST_PARAM_CONTROLLABLE));
|
||||
|
||||
GST_BASE_QR_OVERLAY_CLASS (klass)->get_content =
|
||||
GST_DEBUG_FUNCPTR (get_qrcode_content);
|
||||
|
@ -157,132 +139,24 @@ gst_debug_qr_overlay_class_init (GstDebugQROverlayClass * klass)
|
|||
* initialize instance structure
|
||||
*/
|
||||
static void
|
||||
gst_debug_qr_overlay_init (GstDebugQROverlay * filter)
|
||||
gst_qr_overlay_init (GstQROverlay * filter)
|
||||
{
|
||||
filter->frame_number = 1;
|
||||
filter->x_percent = 50.0;
|
||||
filter->y_percent = 50.0;
|
||||
filter->array_counter = 0;
|
||||
filter->array_size = 0;
|
||||
filter->extra_data_interval_buffers = 60;
|
||||
filter->extra_data_span_buffers = 1;
|
||||
filter->span_frame = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_debug_qr_overlay_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstDebugQROverlay *filter = GST_DEBUG_QR_OVERLAY (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DATA_INTERVAL_BUFFERS:
|
||||
filter->extra_data_interval_buffers = g_value_get_int64 (value);
|
||||
break;
|
||||
case PROP_DATA_SPAN_BUFFERS:
|
||||
filter->extra_data_span_buffers = g_value_get_int64 (value);
|
||||
break;
|
||||
case PROP_EXTRA_DATA_NAME:
|
||||
filter->extra_data_name = g_value_dup_string (value);
|
||||
break;
|
||||
case PROP_EXTRA_DATA_ARRAY:
|
||||
{
|
||||
g_clear_pointer (&filter->extra_data_str, g_free);
|
||||
g_clear_pointer (&filter->extra_data_array, g_strfreev);
|
||||
filter->extra_data_str = g_value_dup_string (value);
|
||||
if (filter->extra_data_str) {
|
||||
filter->extra_data_array = g_strsplit (filter->extra_data_str, ",", -1);
|
||||
filter->array_size = g_strv_length (filter->extra_data_array);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_debug_qr_overlay_get_property (GObject * object, guint prop_id,
|
||||
GValue * value, GParamSpec * pspec)
|
||||
{
|
||||
GstDebugQROverlay *filter = GST_DEBUG_QR_OVERLAY (object);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_DATA_INTERVAL_BUFFERS:
|
||||
g_value_set_int64 (value, filter->extra_data_interval_buffers);
|
||||
break;
|
||||
case PROP_DATA_SPAN_BUFFERS:
|
||||
g_value_set_int64 (value, filter->extra_data_span_buffers);
|
||||
break;
|
||||
case PROP_EXTRA_DATA_NAME:
|
||||
g_value_set_string (value, filter->extra_data_name);
|
||||
break;
|
||||
case PROP_EXTRA_DATA_ARRAY:
|
||||
g_value_set_string (value, filter->extra_data_str);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static gchar *
|
||||
get_qrcode_content (GstBaseQROverlay * base, GstVideoFrame * frame)
|
||||
{
|
||||
GstDebugQROverlay *filter = GST_DEBUG_QR_OVERLAY (base);
|
||||
GstBuffer *buf = frame->buffer;
|
||||
GString *res = g_string_new (NULL);
|
||||
JsonGenerator *jgen;
|
||||
gchar *framerate_string =
|
||||
g_strdup_printf ("%d/%d", frame->info.fps_n, frame->info.fps_d);
|
||||
|
||||
JsonObject *jobj = json_object_new ();
|
||||
JsonNode *root = json_node_new (JSON_NODE_OBJECT);
|
||||
|
||||
json_object_set_int_member (jobj, "TIMESTAMP",
|
||||
(gint64) GST_BUFFER_TIMESTAMP (buf));
|
||||
json_object_set_int_member (jobj, "BUFFERCOUNT",
|
||||
(gint64) filter->frame_number);
|
||||
json_object_set_string_member (jobj, "FRAMERATE", framerate_string);
|
||||
json_object_set_string_member (jobj, "NAME", GST_ELEMENT_NAME (filter));
|
||||
g_free (framerate_string);
|
||||
|
||||
if (filter->extra_data_array && filter->extra_data_name &&
|
||||
(filter->frame_number == 1
|
||||
|| filter->frame_number % filter->extra_data_interval_buffers == 1
|
||||
|| (filter->span_frame > 0
|
||||
&& filter->span_frame < filter->extra_data_span_buffers))) {
|
||||
json_object_set_string_member (jobj, filter->extra_data_name,
|
||||
filter->extra_data_array[filter->array_counter]);
|
||||
|
||||
filter->span_frame++;
|
||||
if (filter->span_frame == filter->extra_data_span_buffers) {
|
||||
filter->array_counter++;
|
||||
filter->span_frame = 0;
|
||||
if (filter->array_counter >= filter->array_size)
|
||||
filter->array_counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
jgen = json_generator_new ();
|
||||
json_node_set_object (root, jobj);
|
||||
json_generator_set_root (jgen, root);
|
||||
res = json_generator_to_gstring (jgen, res);
|
||||
g_object_unref (jgen);
|
||||
filter->frame_number++;
|
||||
|
||||
return g_strdup (g_string_free (res, FALSE));
|
||||
}
|
||||
#include "gstdebugqroverlay.h"
|
||||
|
||||
static gboolean
|
||||
qroverlay_init (GstPlugin * qroverlay)
|
||||
{
|
||||
GST_DEBUG_CATEGORY_INIT (gst_debug_qr_overlay_debug, "debugqroverlay", 0,
|
||||
GST_DEBUG_CATEGORY_INIT (gst_qr_overlay_debug, "qroverlay", 0,
|
||||
"Qrcode overlay element");
|
||||
|
||||
return gst_element_register (qroverlay, "debugqroverlay", GST_RANK_NONE,
|
||||
GST_TYPE_QR_OVERLAY);
|
||||
if (gst_element_register (qroverlay, "debugqroverlay", GST_RANK_NONE,
|
||||
GST_TYPE_DEBUG_QR_OVERLAY))
|
||||
return gst_element_register (qroverlay, "qroverlay", GST_RANK_NONE,
|
||||
GST_TYPE_QR_OVERLAY);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
||||
|
|
|
@ -19,15 +19,15 @@
|
|||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GST_DEBUG_QR_OVERLAY_H__
|
||||
#define __GST_DEBUG_QR_OVERLAY_H__
|
||||
#ifndef __GST_QR_OVERLAY_H__
|
||||
#define __GST_QR_OVERLAY_H__
|
||||
|
||||
#include "gstbaseqroverlay.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
#define GST_TYPE_QR_OVERLAY (gst_debug_qr_overlay_get_type())
|
||||
#define GST_TYPE_QR_OVERLAY (gst_qr_overlay_get_type())
|
||||
|
||||
G_DECLARE_FINAL_TYPE (GstDebugQROverlay, gst_debug_qr_overlay, GST, DEBUG_QR_OVERLAY, GstBaseQROverlay);
|
||||
G_DECLARE_FINAL_TYPE (GstQROverlay, gst_qr_overlay, GST, QR_OVERLAY, GstBaseQROverlay);
|
||||
|
||||
G_END_DECLS
|
||||
#endif /* __GST_DEBUG_QR_OVERLAY_H__ */
|
||||
#endif /* __GST_QR_OVERLAY_H__ */
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
qrencode_dep = dependency('libqrencode', required: get_option('qroverlay'))
|
||||
json_dep = dependency('json-glib-1.0', fallback : ['json-glib', 'json_glib_dep'])
|
||||
if qrencode_dep.found()
|
||||
gstqroverlay = library('gstqroverlay', ['gstqroverlay.c', 'gstbaseqroverlay.c'],
|
||||
gstqroverlay = library('gstqroverlay', ['gstqroverlay.c', 'gstdebugqroverlay.c', 'gstbaseqroverlay.c'],
|
||||
c_args : gst_plugins_bad_args,
|
||||
include_directories : [configinc],
|
||||
dependencies : [gstvideo_dep, qrencode_dep, json_dep],
|
||||
|
|
Loading…
Reference in a new issue