1 /*
2 * GStreamer
3 * Copyright (C) 2006 Stefan Kost <ensonic@users.sf.net>
4 * Copyright (c) 2020 Anthony Violo <anthony.violo@ubicast.eu>
5 * Copyright (c) 2020 Thibault Saunier <tsaunier@igalia.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
23 /**
24 * SECTION:element-qroverlay
25 *
26 * Element to set random data on a qroverlay.
27 *
28 * ## Example launch line
29 *
30 * ``` bash
31 * gst-launch -v -m videotestsrc ! qroverlay ! fakesink silent=TRUE
32 * ```
33 *
34 * Since: 1.20
35 */
36
37 #ifdef HAVE_CONFIG_H
38 #include "config.h"
39 #endif
40
41 #include <gst/gst.h>
42 #include <gst/base/gstbasetransform.h>
43 #include <json-glib/json-glib.h>
44
45 #include <qrencode.h>
46 #include <string.h>
47 #include <stdio.h>
48 #include <stdlib.h>
49
50 #include "gstqroverlayelements.h"
51 #include "gstqroverlay.h"
52
53 enum
54 {
55 PROP_0,
56 PROP_DATA,
57 };
58
59 struct _GstQROverlay
60 {
61 GstBaseQROverlay parent;
62 gchar *data;
63
64 gboolean data_changed;
65 };
66
67 #define gst_qr_overlay_parent_class parent_class
68 G_DEFINE_TYPE (GstQROverlay, gst_qr_overlay, GST_TYPE_BASE_QR_OVERLAY);
69 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (qroverlay, "qroverlay", GST_RANK_NONE,
70 GST_TYPE_QR_OVERLAY, qroverlay_element_init (plugin));
71
72 static gchar *
get_qrcode_content(GstBaseQROverlay * base,GstBuffer * buf,GstVideoInfo * info,gboolean * reuse_prev)73 get_qrcode_content (GstBaseQROverlay * base, GstBuffer * buf,
74 GstVideoInfo * info, gboolean * reuse_prev)
75 {
76 gchar *content;
77 GstQROverlay *self = GST_QR_OVERLAY (base);
78
79 GST_OBJECT_LOCK (self);
80 content = g_strdup (self->data);
81 *reuse_prev = self->data_changed;
82 GST_OBJECT_UNLOCK (self);
83
84 return content;
85 }
86
87 static void
gst_qr_overlay_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)88 gst_qr_overlay_set_property (GObject * object, guint prop_id,
89 const GValue * value, GParamSpec * pspec)
90 {
91 GstQROverlay *self = GST_QR_OVERLAY (object);
92
93 switch (prop_id) {
94 case PROP_DATA:
95 GST_OBJECT_LOCK (self);
96 self->data = g_value_dup_string (value);
97 self->data_changed = TRUE;
98 GST_OBJECT_UNLOCK (self);
99 break;
100 default:
101 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
102 break;
103 }
104 }
105
106 static void
gst_qr_overlay_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)107 gst_qr_overlay_get_property (GObject * object, guint prop_id,
108 GValue * value, GParamSpec * pspec)
109 {
110 GstQROverlay *self = GST_QR_OVERLAY (object);
111
112 switch (prop_id) {
113 case PROP_DATA:
114 g_value_set_string (value, self->data);
115 break;
116 default:
117 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
118 break;
119 }
120 }
121
122 static void
gst_qr_overlay_class_init(GstQROverlayClass * klass)123 gst_qr_overlay_class_init (GstQROverlayClass * klass)
124 {
125 GObjectClass *gobject_class;
126 GstElementClass *gstelement_class;
127
128 gobject_class = (GObjectClass *) klass;
129 gstelement_class = (GstElementClass *) klass;
130
131 gobject_class->set_property = gst_qr_overlay_set_property;
132 gobject_class->get_property = gst_qr_overlay_get_property;
133
134 gst_element_class_set_details_simple (gstelement_class,
135 "qroverlay",
136 "Qrcode overlay containing random data",
137 "Overlay Qrcodes over each buffer with data passed in",
138 "Thibault Saunier <tsaunier@igalia.com>");
139
140 g_object_class_install_property (gobject_class,
141 PROP_DATA, g_param_spec_string ("data",
142 "Data",
143 "Data to write in the QRCode to be overlaid",
144 NULL,
145 G_PARAM_READWRITE | GST_PARAM_MUTABLE_PLAYING |
146 GST_PARAM_CONTROLLABLE));
147
148 GST_BASE_QR_OVERLAY_CLASS (klass)->get_content =
149 GST_DEBUG_FUNCPTR (get_qrcode_content);
150 }
151
152 /* initialize the new element
153 * initialize instance structure
154 */
155 static void
gst_qr_overlay_init(GstQROverlay * filter)156 gst_qr_overlay_init (GstQROverlay * filter)
157 {
158 }
159