2020-07-09 16:37:55 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2006 Stefan Kost <ensonic@users.sf.net>
|
2020-07-09 17:05:20 +00:00
|
|
|
* Copyright (c) 2020 Anthony Violo <anthony.violo@ubicast.eu>
|
2020-07-09 16:37:55 +00:00
|
|
|
*
|
|
|
|
* 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-qroverlay
|
|
|
|
*
|
2020-07-09 16:49:51 +00:00
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* ## Example launch line
|
|
|
|
*
|
|
|
|
* ``` bash
|
2020-07-09 16:37:55 +00:00
|
|
|
* gst-launch -v -m videotestsrc ! qroverlay ! fakesink silent=TRUE
|
2020-07-09 16:49:51 +00:00
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* Since: 1.20
|
2020-07-09 16:37:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gst/base/gstbasetransform.h>
|
2020-07-09 18:14:45 +00:00
|
|
|
#include <json-glib/json-glib.h>
|
2020-07-09 16:37:55 +00:00
|
|
|
|
|
|
|
#include <qrencode.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "gstqroverlay.h"
|
|
|
|
|
2020-07-09 16:49:51 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_qr_overlay_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_qr_overlay_debug
|
2020-07-09 16:37:55 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_X_AXIS,
|
|
|
|
PROP_Y_AXIS,
|
|
|
|
PROP_PIXEL_SIZE,
|
|
|
|
PROP_DATA_INTERVAL_BUFFERS,
|
|
|
|
PROP_DATA_SPAN_BUFFERS,
|
|
|
|
PROP_EXTRA_DATA_NAME,
|
|
|
|
PROP_EXTRA_DATA_ARRAY,
|
|
|
|
PROP_QRCODE_ERROR_CORRECTION,
|
|
|
|
};
|
|
|
|
|
2020-07-12 03:06:16 +00:00
|
|
|
typedef struct _GstQROverlayPrivate GstQROverlayPrivate;
|
|
|
|
struct _GstQROverlayPrivate
|
|
|
|
{
|
|
|
|
guint32 frame_number;
|
|
|
|
gfloat qrcode_size;
|
|
|
|
guint qrcode_quality;
|
|
|
|
guint array_counter;
|
|
|
|
guint array_size;
|
|
|
|
guint span_frame;
|
|
|
|
guint64 extra_data_interval_buffers;
|
|
|
|
guint64 extra_data_span_buffers;
|
|
|
|
QRecLevel level;
|
|
|
|
gchar *framerate_string;
|
|
|
|
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 PRIV(s) gst_qr_overlay_get_instance_private (GST_QR_OVERLAY (s))
|
2020-07-09 16:37:55 +00:00
|
|
|
|
|
|
|
static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("video/x-raw, "
|
|
|
|
"format = (string) { I420 }, "
|
|
|
|
"framerate = (fraction) [0, MAX], "
|
|
|
|
"width = (int) [ 16, MAX ], " "height = (int) [ 16, MAX ]")
|
|
|
|
);
|
|
|
|
|
|
|
|
static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("video/x-raw, "
|
|
|
|
"format = (string) { I420 }, "
|
|
|
|
"framerate = (fraction) [0, MAX], "
|
|
|
|
"width = (int) [ 16, MAX ], " "height = (int) [ 16, MAX ]")
|
|
|
|
);
|
|
|
|
|
|
|
|
#define DEFAULT_PROP_QUALITY 1
|
2020-07-11 19:04:57 +00:00
|
|
|
#define DEFAULT_PROP_PIXEL_SIZE 3
|
2020-07-09 16:37:55 +00:00
|
|
|
|
|
|
|
#define GST_TYPE_QRCODE_QUALITY (gst_qrcode_quality_get_type())
|
|
|
|
static GType
|
|
|
|
gst_qrcode_quality_get_type (void)
|
|
|
|
{
|
|
|
|
static GType qrcode_quality_type = 0;
|
|
|
|
|
|
|
|
static const GEnumValue qrcode_quality[] = {
|
|
|
|
{0, "Level L", "Approx 7%"},
|
|
|
|
{1, "Level M", "Approx 15%"},
|
|
|
|
{2, "Level Q", "Approx 25%"},
|
|
|
|
{3, "Level H", "Approx 30%"},
|
|
|
|
{0, NULL, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!qrcode_quality_type) {
|
|
|
|
qrcode_quality_type =
|
|
|
|
g_enum_register_static ("GstQrcodeOverlayCorrection", qrcode_quality);
|
|
|
|
}
|
|
|
|
return qrcode_quality_type;
|
|
|
|
}
|
|
|
|
|
2020-07-09 16:49:51 +00:00
|
|
|
#define gst_qr_overlay_parent_class parent_class
|
2020-07-12 03:06:16 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GstQROverlay, gst_qr_overlay,
|
|
|
|
GST_TYPE_VIDEO_FILTER);
|
2020-07-09 16:37:55 +00:00
|
|
|
|
2020-07-09 16:49:51 +00:00
|
|
|
static void gst_qr_overlay_set_property (GObject * object, guint prop_id,
|
2020-07-09 16:37:55 +00:00
|
|
|
const GValue * value, GParamSpec * pspec);
|
2020-07-09 16:49:51 +00:00
|
|
|
static void gst_qr_overlay_get_property (GObject * object, guint prop_id,
|
2020-07-09 16:37:55 +00:00
|
|
|
GValue * value, GParamSpec * pspec);
|
|
|
|
|
2020-07-12 00:42:51 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_qr_overlay_transform_frame_ip (GstVideoFilter * base,
|
|
|
|
GstVideoFrame * frame);
|
2020-07-09 16:37:55 +00:00
|
|
|
|
|
|
|
/* GObject vmethod implementations */
|
|
|
|
|
|
|
|
/* initialize the qroverlay's class */
|
|
|
|
static void
|
2020-07-09 16:49:51 +00:00
|
|
|
gst_qr_overlay_class_init (GstQROverlayClass * klass)
|
2020-07-09 16:37:55 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
|
2020-07-09 16:49:51 +00:00
|
|
|
gobject_class->set_property = gst_qr_overlay_set_property;
|
|
|
|
gobject_class->get_property = gst_qr_overlay_get_property;
|
2020-07-09 16:37:55 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_X_AXIS, g_param_spec_float ("x",
|
|
|
|
"X position (in percent of the width)",
|
|
|
|
"X position (in percent of the width)",
|
|
|
|
0.0, 100.0, 50.0, G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_Y_AXIS, g_param_spec_float ("y",
|
|
|
|
"Y position (in percent of the height)",
|
|
|
|
"Y position (in percent of the height)",
|
|
|
|
0.0, 100.0, 50.0, G_PARAM_READWRITE));
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_PIXEL_SIZE, g_param_spec_float ("pixel-size",
|
|
|
|
"pixel-size", "Pixel size of each Qrcode pixel",
|
2020-07-11 19:04:57 +00:00
|
|
|
1, 100.0, DEFAULT_PROP_PIXEL_SIZE, G_PARAM_READWRITE));
|
2020-07-09 16:37:55 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_DATA_INTERVAL_BUFFERS,
|
|
|
|
g_param_spec_int64 ("extra-data-interval-buffers",
|
|
|
|
"extra-data-interval-buffers",
|
2020-07-09 16:49:51 +00:00
|
|
|
"Extra data append into the Qrcode at the first buffer of each "
|
|
|
|
" interval", 0, G_MAXINT64, 60, G_PARAM_READWRITE));
|
2020-07-09 16:37:55 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_DATA_SPAN_BUFFERS, g_param_spec_int64 ("extra-data-span-buffers",
|
|
|
|
"extra-data-span-buffers",
|
2020-07-09 16:49:51 +00:00
|
|
|
"Numbers of consecutive buffers that the extra data will be inserted "
|
|
|
|
" (counting the first buffer)", 0, G_MAXINT64, 1, G_PARAM_READWRITE));
|
2020-07-09 16:37:55 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_EXTRA_DATA_NAME, g_param_spec_string ("extra-data-name",
|
2020-07-09 16:49:51 +00:00
|
|
|
"Extra data name",
|
|
|
|
"Json key name for extra append data", NULL, G_PARAM_READWRITE));
|
2020-07-09 16:37:55 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_EXTRA_DATA_ARRAY, g_param_spec_string ("extra-data-array",
|
2020-07-09 16:49:51 +00:00
|
|
|
"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));
|
2020-07-09 16:37:55 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, PROP_QRCODE_ERROR_CORRECTION,
|
|
|
|
g_param_spec_enum ("qrcode-error-correction", "qrcode-error-correction",
|
|
|
|
"qrcode-error-correction", GST_TYPE_QRCODE_QUALITY,
|
|
|
|
DEFAULT_PROP_QUALITY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
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_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&src_template));
|
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&sink_template));
|
|
|
|
|
2020-07-09 16:49:51 +00:00
|
|
|
gst_type_mark_as_plugin_api (GST_TYPE_QRCODE_QUALITY, 0);
|
|
|
|
|
2020-07-12 00:42:51 +00:00
|
|
|
GST_VIDEO_FILTER_CLASS (klass)->transform_frame_ip =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_qr_overlay_transform_frame_ip);
|
2020-07-09 16:37:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize the new element
|
|
|
|
* initialize instance structure
|
|
|
|
*/
|
|
|
|
static void
|
2020-07-09 16:49:51 +00:00
|
|
|
gst_qr_overlay_init (GstQROverlay * filter)
|
2020-07-09 16:37:55 +00:00
|
|
|
{
|
2020-07-12 03:06:16 +00:00
|
|
|
GstQROverlayPrivate *priv = PRIV (filter);
|
|
|
|
|
|
|
|
priv->frame_number = 1;
|
|
|
|
priv->x_percent = 50.0;
|
|
|
|
priv->y_percent = 50.0;
|
|
|
|
priv->qrcode_quality = DEFAULT_PROP_QUALITY;
|
|
|
|
priv->array_counter = 0;
|
|
|
|
priv->array_size = 0;
|
|
|
|
priv->extra_data_interval_buffers = 60;
|
|
|
|
priv->extra_data_span_buffers = 1;
|
|
|
|
priv->span_frame = 0;
|
|
|
|
priv->qrcode_size = DEFAULT_PROP_PIXEL_SIZE;
|
2020-07-09 16:37:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-07-09 16:49:51 +00:00
|
|
|
gst_qr_overlay_set_property (GObject * object, guint prop_id,
|
2020-07-09 16:37:55 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2020-07-12 03:06:16 +00:00
|
|
|
GstQROverlayPrivate *priv = PRIV (object);
|
2020-07-09 16:37:55 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_X_AXIS:
|
2020-07-12 03:06:16 +00:00
|
|
|
priv->x_percent = g_value_get_float (value);
|
2020-07-09 16:37:55 +00:00
|
|
|
break;
|
|
|
|
case PROP_Y_AXIS:
|
2020-07-12 03:06:16 +00:00
|
|
|
priv->y_percent = g_value_get_float (value);
|
2020-07-09 16:37:55 +00:00
|
|
|
break;
|
|
|
|
case PROP_PIXEL_SIZE:
|
2020-07-12 03:06:16 +00:00
|
|
|
priv->qrcode_size = g_value_get_float (value);
|
2020-07-09 16:37:55 +00:00
|
|
|
break;
|
|
|
|
case PROP_QRCODE_ERROR_CORRECTION:
|
2020-07-12 03:06:16 +00:00
|
|
|
priv->qrcode_quality = g_value_get_enum (value);
|
2020-07-09 16:37:55 +00:00
|
|
|
break;
|
|
|
|
case PROP_DATA_INTERVAL_BUFFERS:
|
2020-07-12 03:06:16 +00:00
|
|
|
priv->extra_data_interval_buffers = g_value_get_int64 (value);
|
2020-07-09 16:37:55 +00:00
|
|
|
break;
|
|
|
|
case PROP_DATA_SPAN_BUFFERS:
|
2020-07-12 03:06:16 +00:00
|
|
|
priv->extra_data_span_buffers = g_value_get_int64 (value);
|
2020-07-09 16:37:55 +00:00
|
|
|
break;
|
|
|
|
case PROP_EXTRA_DATA_NAME:
|
2020-07-12 03:06:16 +00:00
|
|
|
priv->extra_data_name = g_value_dup_string (value);
|
2020-07-09 16:37:55 +00:00
|
|
|
break;
|
|
|
|
case PROP_EXTRA_DATA_ARRAY:
|
2020-07-09 18:14:45 +00:00
|
|
|
{
|
2020-07-12 03:06:16 +00:00
|
|
|
g_clear_pointer (&priv->extra_data_str, g_free);
|
|
|
|
g_clear_pointer (&priv->extra_data_array, g_strfreev);
|
|
|
|
priv->extra_data_str = g_value_dup_string (value);
|
|
|
|
if (priv->extra_data_str) {
|
|
|
|
priv->extra_data_array = g_strsplit (priv->extra_data_str, ",", -1);
|
|
|
|
priv->array_size = g_strv_length (priv->extra_data_array);
|
2020-07-09 18:14:45 +00:00
|
|
|
}
|
2020-07-09 16:37:55 +00:00
|
|
|
break;
|
2020-07-09 18:14:45 +00:00
|
|
|
}
|
2020-07-09 16:37:55 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-07-09 16:49:51 +00:00
|
|
|
gst_qr_overlay_get_property (GObject * object, guint prop_id,
|
2020-07-09 16:37:55 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2020-07-12 03:06:16 +00:00
|
|
|
GstQROverlayPrivate *priv = PRIV (object);
|
2020-07-09 16:37:55 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case PROP_X_AXIS:
|
2020-07-12 03:06:16 +00:00
|
|
|
g_value_set_float (value, priv->x_percent);
|
2020-07-09 16:37:55 +00:00
|
|
|
break;
|
|
|
|
case PROP_Y_AXIS:
|
2020-07-12 03:06:16 +00:00
|
|
|
g_value_set_float (value, priv->y_percent);
|
2020-07-09 16:37:55 +00:00
|
|
|
break;
|
|
|
|
case PROP_PIXEL_SIZE:
|
2020-07-12 03:06:16 +00:00
|
|
|
g_value_set_float (value, priv->qrcode_size);
|
2020-07-09 16:37:55 +00:00
|
|
|
break;
|
|
|
|
case PROP_QRCODE_ERROR_CORRECTION:
|
2020-07-12 03:06:16 +00:00
|
|
|
g_value_set_enum (value, priv->qrcode_quality);
|
2020-07-09 16:37:55 +00:00
|
|
|
break;
|
|
|
|
case PROP_DATA_INTERVAL_BUFFERS:
|
2020-07-12 03:06:16 +00:00
|
|
|
g_value_set_int64 (value, priv->extra_data_interval_buffers);
|
2020-07-09 16:37:55 +00:00
|
|
|
break;
|
|
|
|
case PROP_DATA_SPAN_BUFFERS:
|
2020-07-12 03:06:16 +00:00
|
|
|
g_value_set_int64 (value, priv->extra_data_span_buffers);
|
2020-07-09 16:37:55 +00:00
|
|
|
break;
|
|
|
|
case PROP_EXTRA_DATA_NAME:
|
2020-07-12 03:06:16 +00:00
|
|
|
g_value_set_string (value, priv->extra_data_name);
|
2020-07-09 16:37:55 +00:00
|
|
|
break;
|
|
|
|
case PROP_EXTRA_DATA_ARRAY:
|
2020-07-12 03:06:16 +00:00
|
|
|
g_value_set_string (value, priv->extra_data_str);
|
2020-07-09 16:37:55 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-09 16:51:23 +00:00
|
|
|
static gchar *
|
2020-07-12 00:42:51 +00:00
|
|
|
get_qrcode_content (GstQROverlay * filter, GstBuffer * outbuf)
|
2020-07-09 16:37:55 +00:00
|
|
|
{
|
2020-07-12 03:06:16 +00:00
|
|
|
GstQROverlayPrivate *priv = PRIV (filter);
|
2020-07-09 18:14:45 +00:00
|
|
|
GString *res = g_string_new (NULL);
|
|
|
|
JsonGenerator *jgen;
|
2020-07-09 16:37:55 +00:00
|
|
|
|
2020-07-09 18:14:45 +00:00
|
|
|
JsonObject *jobj = json_object_new ();
|
|
|
|
JsonNode *root = json_node_new (JSON_NODE_OBJECT);
|
|
|
|
|
|
|
|
json_object_set_int_member (jobj, "TIMESTAMP",
|
|
|
|
(gint64) GST_BUFFER_TIMESTAMP (outbuf));
|
2020-07-12 03:06:16 +00:00
|
|
|
json_object_set_int_member (jobj, "BUFFERCOUNT", (gint64) priv->frame_number);
|
|
|
|
json_object_set_string_member (jobj, "FRAMERATE", priv->framerate_string);
|
2020-07-12 00:42:51 +00:00
|
|
|
json_object_set_string_member (jobj, "NAME", GST_ELEMENT_NAME (filter));
|
2020-07-09 18:14:45 +00:00
|
|
|
|
2020-07-12 03:06:16 +00:00
|
|
|
if (priv->extra_data_array && priv->extra_data_name &&
|
|
|
|
(priv->frame_number == 1
|
|
|
|
|| priv->frame_number % priv->extra_data_interval_buffers == 1
|
|
|
|
|| (priv->span_frame > 0
|
|
|
|
&& priv->span_frame < priv->extra_data_span_buffers))) {
|
|
|
|
json_object_set_string_member (jobj, priv->extra_data_name,
|
|
|
|
priv->extra_data_array[priv->array_counter]);
|
|
|
|
|
|
|
|
priv->span_frame++;
|
|
|
|
if (priv->span_frame == priv->extra_data_span_buffers) {
|
|
|
|
priv->array_counter++;
|
|
|
|
priv->span_frame = 0;
|
|
|
|
if (priv->array_counter >= priv->array_size)
|
|
|
|
priv->array_counter = 0;
|
2020-07-09 16:37:55 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-09 18:14:45 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
return g_strdup (g_string_free (res, FALSE));
|
2020-07-09 16:37:55 +00:00
|
|
|
}
|
|
|
|
|
2020-07-09 16:51:23 +00:00
|
|
|
static void
|
2020-07-12 00:42:51 +00:00
|
|
|
overlay_qr_in_frame (GstQROverlay * filter, QRcode * qrcode,
|
|
|
|
GstVideoFrame * frame)
|
2020-07-09 16:37:55 +00:00
|
|
|
{
|
2020-07-12 03:06:16 +00:00
|
|
|
GstQROverlayPrivate *priv = PRIV (filter);
|
2020-07-09 16:37:55 +00:00
|
|
|
guchar *source_data;
|
2020-07-12 00:42:51 +00:00
|
|
|
gint32 k, y, x, yy, square_size, line = 0;
|
|
|
|
int x1, x2, y1, y2;
|
|
|
|
guint8 *d;
|
|
|
|
gint stride;
|
2020-07-09 16:37:55 +00:00
|
|
|
|
2020-07-12 03:06:16 +00:00
|
|
|
square_size = (qrcode->width + 4 * 2) * priv->qrcode_size;
|
2020-07-09 16:37:55 +00:00
|
|
|
/* White bg */
|
2020-07-12 00:42:51 +00:00
|
|
|
x1 = (int) (GST_VIDEO_FRAME_WIDTH (frame) -
|
2020-07-12 03:06:16 +00:00
|
|
|
square_size) * (priv->x_percent / 100);
|
2020-07-12 00:42:51 +00:00
|
|
|
x1 = GST_ROUND_DOWN_2 (x1);
|
|
|
|
x2 = x1 + square_size;
|
|
|
|
y1 = (int) (GST_VIDEO_FRAME_HEIGHT (frame) -
|
2020-07-12 03:06:16 +00:00
|
|
|
square_size) * (priv->y_percent / 100);
|
2020-07-12 00:42:51 +00:00
|
|
|
y1 = GST_ROUND_DOWN_4 (y1);
|
|
|
|
y2 = y1 + square_size;
|
|
|
|
|
|
|
|
d = GST_VIDEO_FRAME_PLANE_DATA (frame, 0);
|
|
|
|
stride = GST_VIDEO_FRAME_PLANE_STRIDE (frame, 0);
|
|
|
|
|
|
|
|
/* Start drawing the white luma plane */
|
|
|
|
for (y = y1; y < y2; y++) {
|
|
|
|
for (x = x1; x < x2; x += square_size)
|
|
|
|
memset (&d[y * stride + x], 0xff, square_size);
|
2020-07-09 16:37:55 +00:00
|
|
|
}
|
2020-07-12 00:42:51 +00:00
|
|
|
|
|
|
|
/* Draw the black QR code blocks with 4px white space around it
|
|
|
|
* on top */
|
2020-07-12 03:06:16 +00:00
|
|
|
line += 4 * priv->qrcode_size * stride;
|
2020-07-09 16:37:55 +00:00
|
|
|
source_data = qrcode->data;
|
|
|
|
for (y = 0; y < qrcode->width; y++) {
|
|
|
|
for (x = 0; x < (qrcode->width); x++) {
|
2020-07-12 03:06:16 +00:00
|
|
|
for (yy = 0; yy < priv->qrcode_size; yy++) {
|
|
|
|
k = ((((line + (4 * priv->qrcode_size))) + stride * yy +
|
|
|
|
x * priv->qrcode_size) + x1) + (y1 * stride);
|
2020-07-09 16:37:55 +00:00
|
|
|
if (*source_data & 1) {
|
2020-07-12 03:06:16 +00:00
|
|
|
memset (d + k, 0, priv->qrcode_size);
|
2020-07-09 16:37:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
source_data++;
|
|
|
|
}
|
2020-07-12 03:06:16 +00:00
|
|
|
line += (stride * priv->qrcode_size);
|
2020-07-12 00:42:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set Chrominance planes */
|
|
|
|
x1 /= 2;
|
|
|
|
x2 /= 2;
|
|
|
|
y1 /= 2;
|
|
|
|
y2 /= 2;
|
|
|
|
stride = GST_VIDEO_FRAME_PLANE_STRIDE (frame, 1);
|
|
|
|
for (y = y1; y < y2; y++) {
|
|
|
|
for (x = x1; x < x2; x += (x2 - x1)) {
|
|
|
|
d = GST_VIDEO_FRAME_PLANE_DATA (frame, 1);
|
|
|
|
memset (&d[y * stride + x], 128, (x2 - x1));
|
|
|
|
d = GST_VIDEO_FRAME_PLANE_DATA (frame, 2);
|
|
|
|
memset (&d[y * stride + x], 128, (x2 - x1));
|
|
|
|
}
|
2020-07-09 16:37:55 +00:00
|
|
|
}
|
2020-07-12 00:42:51 +00:00
|
|
|
|
2020-07-09 16:37:55 +00:00
|
|
|
QRcode_free (qrcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* GstBaseTransform vmethod implementations */
|
|
|
|
/* this function does the actual processing
|
|
|
|
*/
|
|
|
|
static GstFlowReturn
|
2020-07-12 00:42:51 +00:00
|
|
|
gst_qr_overlay_transform_frame_ip (GstVideoFilter * base, GstVideoFrame * frame)
|
2020-07-09 16:37:55 +00:00
|
|
|
{
|
2020-07-12 03:06:16 +00:00
|
|
|
GstQROverlayPrivate *priv = PRIV (base);
|
2020-07-09 16:37:55 +00:00
|
|
|
QRcode *qrcode;
|
2020-07-12 00:42:51 +00:00
|
|
|
gchar *content;
|
|
|
|
GstClockTime rtime =
|
|
|
|
gst_segment_to_running_time (&GST_BASE_TRANSFORM (base)->segment,
|
|
|
|
GST_FORMAT_TIME, GST_BUFFER_PTS (frame->buffer));
|
2020-07-09 16:37:55 +00:00
|
|
|
|
2020-07-12 00:42:51 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (rtime))
|
2020-07-12 03:06:16 +00:00
|
|
|
gst_object_sync_values (GST_OBJECT (base), rtime);
|
2020-07-12 00:42:51 +00:00
|
|
|
|
2020-07-12 03:06:16 +00:00
|
|
|
content = get_qrcode_content (GST_QR_OVERLAY (base), frame->buffer);
|
|
|
|
GST_INFO_OBJECT (base, "String will be encoded : %s", content);
|
|
|
|
qrcode = QRcode_encodeString (content, 0, priv->qrcode_quality, QR_MODE_8, 0);
|
2020-07-09 16:37:55 +00:00
|
|
|
if (qrcode) {
|
2020-07-12 03:06:16 +00:00
|
|
|
GST_DEBUG_OBJECT (base, "String encoded");
|
|
|
|
overlay_qr_in_frame (GST_QR_OVERLAY (base), qrcode, frame);
|
|
|
|
priv->frame_number++;
|
2020-07-12 00:42:51 +00:00
|
|
|
} else {
|
2020-07-12 03:06:16 +00:00
|
|
|
GST_WARNING_OBJECT (base, "Could not encode content: %s", content);
|
2020-07-12 00:42:51 +00:00
|
|
|
}
|
|
|
|
g_free (content);
|
|
|
|
|
2020-07-09 16:37:55 +00:00
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
qroverlay_init (GstPlugin * qroverlay)
|
|
|
|
{
|
2020-07-09 16:49:51 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_qr_overlay_debug, "qroverlay", 0,
|
2020-07-09 16:37:55 +00:00
|
|
|
"Qrcode overlay element");
|
|
|
|
|
|
|
|
return gst_element_register (qroverlay, "qroverlay", GST_RANK_NONE,
|
2020-07-09 16:49:51 +00:00
|
|
|
GST_TYPE_QR_OVERLAY);
|
2020-07-09 16:37:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
qroverlay,
|
|
|
|
"libqrencode qroverlay plugin",
|
|
|
|
qroverlay_init, VERSION, "LGPL", PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|