mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
zbar: add frame sample to barcode message
New attach-frame property enables barcode frame dumping when set to true. https://bugzilla.gnome.org/show_bug.cgi?id=747557
This commit is contained in:
parent
5b0c3ac153
commit
1246d93f3e
2 changed files with 49 additions and 2 deletions
|
@ -22,6 +22,8 @@
|
|||
*
|
||||
* Detect bar codes in the video streams and send them as element messages to
|
||||
* the #GstBus if .#GstZBar:message property is %TRUE.
|
||||
* If the .#GstZBar:attach-frame property is %TRUE, the posted barcode message
|
||||
* includes a sample of the frame where the barcode was detected (Since 1.6).
|
||||
*
|
||||
* The element generate messages named
|
||||
* <classname>"barcode"</classname>. The structure containes these
|
||||
|
@ -56,6 +58,14 @@
|
|||
* values.
|
||||
* </para>
|
||||
* </listitem>
|
||||
* <listitem>
|
||||
* <para>
|
||||
* GstSample
|
||||
* <classname>"frame"</classname>:
|
||||
* the frame in which the barcode message was detected, if
|
||||
* the .#GstZBar:attach-frame property was set to %TRUE (Since 1.6)
|
||||
* </para>
|
||||
* </listitem>
|
||||
* </itemizedlist>
|
||||
*
|
||||
* <refsect2>
|
||||
|
@ -95,11 +105,13 @@ enum
|
|||
{
|
||||
PROP_0,
|
||||
PROP_MESSAGE,
|
||||
PROP_ATTACH_FRAME,
|
||||
PROP_CACHE
|
||||
};
|
||||
|
||||
#define DEFAULT_CACHE FALSE
|
||||
#define DEFAULT_MESSAGE TRUE
|
||||
#define DEFAULT_ATTACH_FRAME FALSE
|
||||
|
||||
#define ZBAR_YUV_CAPS \
|
||||
"{ Y800, I420, YV12, NV12, NV21, Y41B, Y42B, YUV9, YVU9 }"
|
||||
|
@ -155,6 +167,19 @@ gst_zbar_class_init (GstZBarClass * g_class)
|
|||
"Post a barcode message for each detected code",
|
||||
DEFAULT_MESSAGE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
/**
|
||||
* GstZBar::attach-frame:
|
||||
*
|
||||
* Attach the frame in which the barcode was detected to the posted
|
||||
* barcode message.
|
||||
*
|
||||
* Since: 1.6
|
||||
*/
|
||||
g_object_class_install_property (gobject_class, PROP_ATTACH_FRAME,
|
||||
g_param_spec_boolean ("attach-frame", "Attach frame",
|
||||
"Attach a frame dump to each barcode message",
|
||||
DEFAULT_ATTACH_FRAME, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
||||
g_object_class_install_property (gobject_class, PROP_CACHE,
|
||||
g_param_spec_boolean ("cache", "cache",
|
||||
"Enable or disable the inter-image result cache",
|
||||
|
@ -185,6 +210,7 @@ gst_zbar_init (GstZBar * zbar)
|
|||
{
|
||||
zbar->cache = DEFAULT_CACHE;
|
||||
zbar->message = DEFAULT_MESSAGE;
|
||||
zbar->attach_frame = DEFAULT_ATTACH_FRAME;
|
||||
|
||||
zbar->scanner = zbar_image_scanner_create ();
|
||||
}
|
||||
|
@ -215,6 +241,9 @@ gst_zbar_set_property (GObject * object, guint prop_id, const GValue * value,
|
|||
case PROP_MESSAGE:
|
||||
zbar->message = g_value_get_boolean (value);
|
||||
break;
|
||||
case PROP_ATTACH_FRAME:
|
||||
zbar->attach_frame = g_value_get_boolean (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
|
@ -237,6 +266,9 @@ gst_zbar_get_property (GObject * object, guint prop_id, GValue * value,
|
|||
case PROP_MESSAGE:
|
||||
g_value_set_boolean (value, zbar->message);
|
||||
break;
|
||||
case PROP_ATTACH_FRAME:
|
||||
g_value_set_boolean (value, zbar->attach_frame);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
|
@ -286,15 +318,29 @@ gst_zbar_transform_frame_ip (GstVideoFilter * vfilter, GstVideoFrame * frame)
|
|||
if (zbar->message) {
|
||||
GstMessage *m;
|
||||
GstStructure *s;
|
||||
GstSample *sample;
|
||||
GstCaps *sample_caps;
|
||||
|
||||
/* post a message */
|
||||
s = gst_structure_new ("barcode",
|
||||
"timestamp", G_TYPE_UINT64, GST_BUFFER_TIMESTAMP (frame->buffer),
|
||||
"type", G_TYPE_STRING, zbar_get_symbol_name (typ),
|
||||
"symbol", G_TYPE_STRING, data, "quality", G_TYPE_INT, quality, NULL);
|
||||
|
||||
if (zbar->attach_frame) {
|
||||
/* create a sample from image */
|
||||
sample_caps = gst_video_info_to_caps (&frame->info);
|
||||
sample = gst_sample_new (frame->buffer, sample_caps, NULL, NULL);
|
||||
gst_caps_unref (sample_caps);
|
||||
gst_structure_set (s, "frame", GST_TYPE_SAMPLE, sample, NULL);
|
||||
gst_sample_unref (sample);
|
||||
}
|
||||
|
||||
m = gst_message_new_element (GST_OBJECT (zbar), s);
|
||||
gst_element_post_message (GST_ELEMENT (zbar), m);
|
||||
}
|
||||
|
||||
} else if (zbar->attach_frame)
|
||||
GST_WARNING_OBJECT (zbar,
|
||||
"attach-frame=true has no effect if message=false");
|
||||
}
|
||||
|
||||
out:
|
||||
|
|
|
@ -53,6 +53,7 @@ struct _GstZBar
|
|||
|
||||
/* properties */
|
||||
gboolean message;
|
||||
gboolean attach_frame;
|
||||
gboolean cache;
|
||||
|
||||
/* internals */
|
||||
|
|
Loading…
Reference in a new issue