zbar: post a message instead of printing the code to stdout

Docment the message format that we sent. Add a property to turn message sending off.
This commit is contained in:
Stefan Kost 2009-10-02 13:02:31 +03:00
parent 6ff0a498aa
commit f55eefd22c
2 changed files with 59 additions and 6 deletions

View file

@ -27,7 +27,35 @@
/** /**
* SECTION:element-zbar * SECTION:element-zbar
* *
* Detect bar codes in the video streams and send them as app messages. * Detect bar codes in the video streams and send them as element messages to
* the #GstBus if .#GstZBar:message property is %TRUE.
*
* The element generate messages named
* <classname>&quot;barcode&quot;</classname>. The structure containes these
* fields:
* <itemizedlist>
* <listitem>
* <para>
* #GstClockTime
* <classname>&quot;timestamp&quot;</classname>:
* the timestamp of the buffer that triggered the message.
* </para>
* </listitem>
* <listitem>
* <para>
* gchar*
* <classname>&quot;type&quot;</classname>:
* the symbol type.
* </para>
* </listitem>
* <listitem>
* <para>
* gchar*
* <classname>&quot;symbol&quot;</classname>:
* the deteted bar code data.
* </para>
* </listitem>
* </itemizedlist>
* *
* <refsect2> * <refsect2>
* <title>Example launch lines</title> * <title>Example launch lines</title>
@ -65,7 +93,7 @@ enum
enum enum
{ {
PROP_0, PROP_0,
/* FILL ME */ PROP_MESSAGE,
}; };
#define DEFAULT_PROP_ZBAR 1 #define DEFAULT_PROP_ZBAR 1
@ -132,6 +160,11 @@ gst_zbar_class_init (GstZBarClass * g_class)
gobject_class->get_property = gst_zbar_get_property; gobject_class->get_property = gst_zbar_get_property;
gobject_class->finalize = gst_zbar_finalize; gobject_class->finalize = gst_zbar_finalize;
g_object_class_install_property (gobject_class, PROP_MESSAGE,
g_param_spec_boolean ("message", "mesage",
"Post a barcode message for each detected code",
TRUE, G_PARAM_READWRITE));
trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_zbar_set_caps); trans_class->set_caps = GST_DEBUG_FUNCPTR (gst_zbar_set_caps);
trans_class->transform_ip = GST_DEBUG_FUNCPTR (gst_zbar_transform_ip); trans_class->transform_ip = GST_DEBUG_FUNCPTR (gst_zbar_transform_ip);
trans_class->start = GST_DEBUG_FUNCPTR (gst_zbar_start); trans_class->start = GST_DEBUG_FUNCPTR (gst_zbar_start);
@ -141,6 +174,8 @@ gst_zbar_class_init (GstZBarClass * g_class)
static void static void
gst_zbar_init (GstZBar * zbar, GstZBarClass * g_class) gst_zbar_init (GstZBar * zbar, GstZBarClass * g_class)
{ {
zbar->message = TRUE;
zbar->scanner = zbar_image_scanner_create (); zbar->scanner = zbar_image_scanner_create ();
} }
@ -164,6 +199,9 @@ gst_zbar_set_property (GObject * object, guint prop_id, const GValue * value,
zbar = GST_ZBAR (object); zbar = GST_ZBAR (object);
switch (prop_id) { switch (prop_id) {
case PROP_MESSAGE:
zbar->message = g_value_get_boolean (value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -180,6 +218,9 @@ gst_zbar_get_property (GObject * object, guint prop_id, GValue * value,
zbar = GST_ZBAR (object); zbar = GST_ZBAR (object);
switch (prop_id) { switch (prop_id) {
case PROP_MESSAGE:
g_value_set_boolean (value, zbar->message);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -226,19 +267,30 @@ gst_zbar_transform_ip (GstBaseTransform * base, GstBuffer * outbuf)
zbar_image_set_data (image, (gpointer) data, zbar->width * zbar->height, zbar_image_set_data (image, (gpointer) data, zbar->width * zbar->height,
NULL); NULL);
/* scan the image for barcodes */ /* scan the image for barcodes */
n = zbar_scan_image (zbar->scanner, image); n = zbar_scan_image (zbar->scanner, image);
/* extract results */ /* extract results */
symbol = zbar_image_first_symbol (image); symbol = zbar_image_first_symbol (image);
for (; symbol; symbol = zbar_symbol_next (symbol)) { for (; symbol; symbol = zbar_symbol_next (symbol)) {
/* do something useful with results */
zbar_symbol_type_t typ = zbar_symbol_get_type (symbol); zbar_symbol_type_t typ = zbar_symbol_get_type (symbol);
const char *data = zbar_symbol_get_data (symbol); const char *data = zbar_symbol_get_data (symbol);
/* FIXME: post a message instead */ GST_DEBUG_OBJECT (zbar, "decoded %s symbol \"%s\"",
printf ("decoded %s symbol \"%s\"\n", zbar_get_symbol_name (typ), data); zbar_get_symbol_name (typ), data);
if (zbar->message) {
GstMessage *m;
GstStructure *s;
/* post a message */
s = gst_structure_new ("barcode",
"timestamp", G_TYPE_UINT64, GST_BUFFER_TIMESTAMP (outbuf),
"type", G_TYPE_STRING, zbar_get_symbol_name (typ),
"symbol", G_TYPE_STRING, data, NULL);
m = gst_message_new_element (GST_OBJECT (zbar), s);
gst_element_post_message (GST_ELEMENT (zbar), m);
}
} }
/* clean up */ /* clean up */

View file

@ -54,6 +54,7 @@ struct _GstZBar
gint height; gint height;
/* properties */ /* properties */
gboolean message;
/* internals */ /* internals */
zbar_image_scanner_t *scanner; zbar_image_scanner_t *scanner;