Add option to draw markers on frame corners
authorJussi Saavalainen <jussi.saavalainen@ixonos.com>
Fri, 1 Feb 2013 13:33:37 +0000 (15:33 +0200)
committerJussi Saavalainen <jussi.saavalainen@ixonos.com>
Fri, 1 Feb 2013 13:33:37 +0000 (15:33 +0200)
Add a debug aid so we can tell where the frame data actually is.
Default off, use draw-corner-markers=true property to enable.

Change-Id: Id49eafc6e07550f68b88afd0c03182d49f1cd9a2

gst/mfldv4l2cam/gstv4l2camsrc.c
gst/mfldv4l2cam/gstv4l2camsrc.h
gst/mfldv4l2cam/v4l2camsrc_calls.c

index dcdee0e..8a530f6 100644 (file)
@@ -129,6 +129,7 @@ typedef enum
   PROP_DUMP_IMAGE,
   PROP_DEBUG_FLAGS,
   PROP_DISABLE_LOW_RES_CROP,
+  PROP_DRAW_CORNER_MARKERS,
 } GstV4L2CamSrcProperties;
 
 
@@ -976,6 +977,12 @@ gst_v4l2camsrc_class_init (GstMFLDV4l2CamSrcClass * klass)
           "disable software crop on unsupported low resolution frame size", FALSE,
           G_PARAM_READWRITE));
 
+  g_object_class_install_property (gobject_class,
+      PROP_DRAW_CORNER_MARKERS,
+      g_param_spec_boolean ("draw-corner-markers", "draw markers in frame corners",
+          "draw markers in frame corners", FALSE,
+          G_PARAM_READWRITE));
+
   camera_class->is_open = GST_DEBUG_FUNCPTR (gst_v4l2camsrc_is_open);
   camera_class->open = GST_DEBUG_FUNCPTR (gst_v4l2camsrc_open);
   camera_class->close = GST_DEBUG_FUNCPTR (gst_v4l2camsrc_close);
@@ -1129,6 +1136,7 @@ gst_v4l2camsrc_init (GstMFLDV4l2CamSrc * v4l2camsrc,
   v4l2camsrc->raw_output_size = 0;
   v4l2camsrc->debug_flags = DEFAULT_DEBUG_FLAGS;
   v4l2camsrc->disable_low_res_crop = FALSE;
+  v4l2camsrc->draw_corner_markers = FALSE;
 
   v4l2camsrc->device_mutex = g_mutex_new ();
 
@@ -1515,6 +1523,9 @@ gst_v4l2camsrc_set_property (GObject * object,
     case PROP_DISABLE_LOW_RES_CROP:
       v4l2camsrc->disable_low_res_crop = g_value_get_boolean (value);
       break;
+    case PROP_DRAW_CORNER_MARKERS:
+      v4l2camsrc->draw_corner_markers = g_value_get_boolean (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -1694,6 +1705,9 @@ gst_v4l2camsrc_get_property (GObject * object,
     case PROP_DISABLE_LOW_RES_CROP:
       g_value_set_boolean (value, v4l2camsrc->disable_low_res_crop);
       break;
+    case PROP_DRAW_CORNER_MARKERS:
+      g_value_set_boolean (value, v4l2camsrc->draw_corner_markers);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
index 5108e04..f5e6df2 100644 (file)
@@ -299,6 +299,7 @@ struct _GstMFLDV4l2CamSrc {
   GstCameraSrcDebugFlags debug_flags;
 
   gboolean disable_low_res_crop;
+  gboolean draw_corner_markers;
 };
 
 
index 55fe886..f8febab 100644 (file)
@@ -2027,6 +2027,21 @@ default_frame_sizes:
   return ret;
 }
 
+static void draw_corner_markers_nv12(unsigned char *buf, unsigned w, unsigned h)
+{
+       int i,j;
+#define put_dot(x,y) buf[(x)+w*(y)] = (((x+y)&0x01)?0x00:0xff)
+
+       for(j = 0; j < 4; ++j)
+               for(i = 0; i < 8; ++i) {
+                       put_dot(i, j); put_dot(w-1-i, j);
+                       put_dot(j, i); put_dot(j, h-1-i);
+                       put_dot(i, h-1-j); put_dot(w-1-i, h-1-j);
+                       put_dot(w-1-j, i); put_dot(w-1-j, h-1-i);
+               }
+#undef put_dot
+}
+
 /* Crop to upper left corner of NV12 frame. */
 static gboolean crop_buffer_inplace_nv12(unsigned char *buf, unsigned in_w, unsigned in_h,
                                unsigned out_w, unsigned out_h)
@@ -2051,19 +2066,6 @@ static gboolean crop_buffer_inplace_nv12(unsigned char *buf, unsigned in_w, unsi
                in += in_w;
                out += out_w;
        }
-#if 0
-       /* B/W Marker to top left corner */
-#define put_dot(x,y,c) buf[(y)*out_w+x] = c
-       put_dot(0,0,0xff); put_dot(1,0,0x00); put_dot(2,0,0xff); put_dot(3,0,0x00); put_dot(4,0,0xff); put_dot(5,0,0x00); put_dot(6,0,0xff); put_dot(7,0,0x00);
-       put_dot(0,1,0x00); put_dot(1,1,0xff); put_dot(2,1,0x00); put_dot(3,1,0xff); put_dot(4,1,0x00); put_dot(5,1,0xff); put_dot(6,1,0x00); put_dot(7,1,0xff);
-       put_dot(0,2,0xff); put_dot(1,2,0x00);
-       put_dot(0,3,0x00); put_dot(1,3,0xff);
-       put_dot(0,4,0xff); put_dot(1,4,0x00);
-       put_dot(0,5,0x00); put_dot(1,5,0xff);
-       put_dot(0,6,0xff); put_dot(1,6,0x00);
-       put_dot(0,7,0x00); put_dot(1,7,0xff);
-#undef put_dot
-#endif
 
        return TRUE;
 }
@@ -2290,6 +2292,10 @@ gst_v4l2camsrc_grab_frame (GstCameraSrc * camsrc, GstBuffer ** buf,
     }
   }
 
+  if(v4l2camsrc->draw_corner_markers)
+    draw_corner_markers_nv12(GST_BUFFER_DATA(pool_buffer),
+      v4l2camsrc->expected_capture_w, v4l2camsrc->expected_capture_h);
+
   g_mutex_unlock (v4l2camsrc->pool->lock);
 
   /* this can change at every frame, esp. with jpeg */