[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gstreamer-cvs
Subject:    gst-plugins-bad: zbar: add frame sample to barcode message
From:       reynaldo () kemper ! freedesktop ! org (Reynaldo H !  Verdejo Pinochet)
Date:       2015-05-31 23:02:09
Message-ID: 20150531230209.D1271761E9 () kemper ! freedesktop ! org
[Download RAW message or body]

Module: gst-plugins-bad
Branch: master
Commit: 1246d93f3e32a13c95c70cf3ba0f26b224de5e58
URL:    http://cgit.freedesktop.org/gstreamer/gst-plugins-bad/commit/?id=1246d93f3e32a13c95c70cf3ba0f26b224de5e58


Author: Reynaldo H. Verdejo Pinochet <reynaldo@osg.samsung.com>
Date:   Fri May  1 23:20:30 2015 -0300

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

---

 ext/zbar/gstzbar.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++--
 ext/zbar/gstzbar.h |    1 +
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/ext/zbar/gstzbar.c b/ext/zbar/gstzbar.c
index 8c98ed9..faf2b55 100644
--- a/ext/zbar/gstzbar.c
+++ b/ext/zbar/gstzbar.c
@@ -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>&quot;barcode&quot;</classname>. The structure containes these
@@ -56,6 +58,14 @@
  *   values.
  *   </para>
  * </listitem>
+ * <listitem>
+ *   <para>
+ *   GstSample
+ *   <classname>&quot;frame&quot;</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:
diff --git a/ext/zbar/gstzbar.h b/ext/zbar/gstzbar.h
index bb2e15b..c07e01d 100644
--- a/ext/zbar/gstzbar.h
+++ b/ext/zbar/gstzbar.h
@@ -53,6 +53,7 @@ struct _GstZBar
 
   /* properties */
   gboolean message;
+  gboolean attach_frame;
   gboolean cache;
 
   /* internals */

_______________________________________________
gstreamer-commits mailing list
gstreamer-commits@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/gstreamer-commits


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic