zbar: allow to get symbol as bytes

It would be possible to get some binary symbols with a string, but if
they contain NUL bytes, the string will be cut off. To fix this,
provide the decoded symbol as a GBytes too.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4688>
This commit is contained in:
Kévin Commaille 2023-05-22 16:15:33 +02:00 committed by GStreamer Marge Bot
parent fcd2e61330
commit 9aeaea29f5
2 changed files with 16 additions and 2 deletions

View File

@ -30,7 +30,8 @@
*
* * #GstClockTime `timestamp`: the timestamp of the buffer that triggered the message.
* * gchar * `type`: the symbol type.
* * gchar * `symbol`: the detected bar code data.
* * gchar * `symbol`: the detected bar code data, as a string.
* * GBytes * `symbol-bytes`: the detected bar code data, as bytes. (Since 1.26)
* * gint `quality`: an unscaled, relative quantity: larger values are better than smaller
* values.
* * #GstSample `frame`: the frame in which the barcode message was detected, if
@ -299,6 +300,8 @@ gst_zbar_transform_frame_ip (GstVideoFilter * vfilter, GstVideoFrame * frame)
for (; symbol; symbol = zbar_symbol_next (symbol)) {
zbar_symbol_type_t typ = zbar_symbol_get_type (symbol);
const char *data = zbar_symbol_get_data (symbol);
unsigned len = zbar_symbol_get_data_length (symbol);
GBytes *data_bytes = g_bytes_new (data, len);
gint quality = zbar_symbol_get_quality (symbol);
GST_DEBUG_OBJECT (zbar, "decoded %s symbol \"%s\" at quality %d",
@ -328,7 +331,9 @@ gst_zbar_transform_frame_ip (GstVideoFilter * vfilter, GstVideoFrame * frame)
"stream-time", G_TYPE_UINT64, stream_time,
"running-time", G_TYPE_UINT64, running_time,
"type", G_TYPE_STRING, zbar_get_symbol_name (typ),
"symbol", G_TYPE_STRING, data, "quality", G_TYPE_INT, quality, NULL);
"symbol", G_TYPE_STRING, data,
"symbol-bytes", G_TYPE_BYTES, data_bytes,
"quality", G_TYPE_INT, quality, NULL);
if (GST_CLOCK_TIME_IS_VALID (duration))
gst_structure_set (s, "duration", G_TYPE_UINT64, duration, NULL);
@ -345,6 +350,7 @@ gst_zbar_transform_frame_ip (GstVideoFilter * vfilter, GstVideoFrame * frame)
m = gst_message_new_element (GST_OBJECT (zbar), s);
gst_element_post_message (GST_ELEMENT (zbar), m);
g_bytes_unref (data_bytes);
} else if (zbar->attach_frame)
GST_WARNING_OBJECT (zbar,
"attach-frame=true has no effect if message=false");

View File

@ -83,6 +83,8 @@ GST_START_TEST (test_still_image)
GstElement *pipeline;
const gchar *type, *symbol;
int qual;
const GValue *value;
GBytes *symbol_bytes;
pipeline = setup_pipeline ();
@ -99,6 +101,7 @@ GST_START_TEST (test_still_image)
fail_unless (gst_structure_has_field (s, "timestamp"));
fail_unless (gst_structure_has_field (s, "type"));
fail_unless (gst_structure_has_field (s, "symbol"));
fail_unless (gst_structure_has_field (s, "symbol-bytes"));
fail_unless (gst_structure_has_field (s, "quality"));
fail_unless (gst_structure_get_int (s, "quality", &qual));
fail_unless (qual >= 90);
@ -106,6 +109,11 @@ GST_START_TEST (test_still_image)
fail_unless_equals_string (type, "EAN-13");
symbol = gst_structure_get_string (s, "symbol");
fail_unless_equals_string (symbol, "9876543210128");
value = gst_structure_get_value (s, "symbol-bytes");
fail_unless (G_VALUE_HOLDS (value, G_TYPE_BYTES));
symbol_bytes = g_value_get_boxed (value);
fail_unless_equals_string (g_bytes_get_data (symbol_bytes, 0),
"9876543210128");
fail_if (gst_structure_has_field (s, "frame"));