[aravis] gst: allow color caps.



commit 701580ab4ff192f42d3959dd0fa6abc1dc1d0511
Author: Emmanuel Pacaud <emmanuel gnome org>
Date:   Sun Feb 13 17:44:51 2011 +0100

    gst: allow color caps.

 docs/reference/aravis/aravis-sections.txt |    6 +++
 gst/gstaravis.c                           |   52 +++++++++++++++--------------
 src/arvtools.c                            |   41 ++++++++++++++++++++++
 src/arvtools.h                            |    2 +
 viewer/arvviewer.c                        |   26 ++------------
 5 files changed, 80 insertions(+), 47 deletions(-)
---
diff --git a/docs/reference/aravis/aravis-sections.txt b/docs/reference/aravis/aravis-sections.txt
index 0a7972e..9044540 100644
--- a/docs/reference/aravis/aravis-sections.txt
+++ b/docs/reference/aravis/aravis-sections.txt
@@ -738,6 +738,12 @@ G_IMPLEMENT_INTERFACE
 </SECTION>
 
 <SECTION>
+<FILE>arvgst</FILE>
+<TITLE>ArvGst</TITLE>
+arv_pixel_format_to_gst_caps_string
+</SECTION>
+
+<SECTION>
 <FILE>arvgvcp</FILE>
 <TITLE>ArvGvcp</TITLE>
 arv_gvcp_packet_free
diff --git a/gst/gstaravis.c b/gst/gstaravis.c
index 8ffd717..a437215 100644
--- a/gst/gstaravis.c
+++ b/gst/gstaravis.c
@@ -71,32 +71,29 @@ static GstStaticPadTemplate aravis_src_template = GST_STATIC_PAD_TEMPLATE ("src"
 GstCaps *
 gst_aravis_get_camera_caps (GstAravis *gst_aravis)
 {
-	GstCaps *gcaps = NULL;
-	GstStructure *gs;
+	GstCaps *caps = NULL;
+	ArvPixelFormat pixel_format;
+	const char *caps_string;
 	double frame_rate;
 	int height, width;
 
 	GST_LOG_OBJECT (gst_aravis, "Get camera caps");
 
-	gcaps = gst_caps_new_empty ();
-
 	arv_camera_get_region (gst_aravis->camera, NULL, NULL, &width, &height);
-
-	gs = gst_structure_empty_new ("video");
-	gst_structure_set_name (gs, "video/x-raw-gray");
-	gst_structure_set (gs,
-			   "bpp", G_TYPE_INT, 8,
-			   "depth", G_TYPE_INT, 8,
-			   "width", G_TYPE_INT, width,
-			   "height", G_TYPE_INT, height,
-			   NULL);
-
+	pixel_format = arv_camera_get_pixel_format (gst_aravis->camera);
 	frame_rate = arv_camera_get_frame_rate (gst_aravis->camera);
 
-	gst_structure_set(gs, "framerate", GST_TYPE_FRACTION, (gint) (100.0 * frame_rate), 100, NULL);
-	gst_caps_append_structure (gcaps, gs);
-
-	return gcaps;
+	caps_string = arv_pixel_format_to_gst_caps_string (pixel_format);
+	if (caps_string == NULL)
+		return NULL;
+
+	caps = gst_caps_from_string (caps_string);
+	gst_caps_set_simple (caps,
+			     "width", G_TYPE_INT, width,
+			     "height", G_TYPE_INT, height,
+			     "framerate", GST_TYPE_FRACTION, (unsigned int ) (double) (0.5 + frame_rate), 1,
+			     NULL);
+	return caps;
 }
 
 static GstCaps *
@@ -128,7 +125,6 @@ gst_aravis_start (GstBaseSrc *src)
 
 	arv_camera_set_region (gst_aravis->camera, 0, 0, gst_aravis->width, gst_aravis->height);
 	arv_camera_set_binning (gst_aravis->camera, gst_aravis->h_binning, gst_aravis->v_binning);
-	arv_camera_set_pixel_format (gst_aravis->camera, ARV_PIXEL_FORMAT_MONO_8);
 
 	GST_DEBUG_OBJECT (gst_aravis, "Frame rate = %g Hz", gst_aravis->frame_rate);
 	arv_camera_set_frame_rate (gst_aravis->camera, gst_aravis->frame_rate);
@@ -166,13 +162,19 @@ gboolean gst_aravis_stop( GstBaseSrc * src )
 
 	arv_camera_stop_acquisition (gst_aravis->camera);
 
-	g_object_unref (gst_aravis->stream);
-	g_object_unref (gst_aravis->camera);
-	gst_caps_unref (gst_aravis->caps);
+	if (gst_aravis->stream != NULL) {
+		g_object_unref (gst_aravis->stream);
+		gst_aravis->stream = NULL;
 
-	gst_aravis->camera = NULL;
-	gst_aravis->stream = NULL;
-	gst_aravis->caps = NULL;
+	}
+	if (gst_aravis->camera != NULL) {
+		g_object_unref (gst_aravis->camera);
+		gst_aravis->camera = NULL;
+	}
+	if (gst_aravis->caps != NULL) {
+		gst_caps_unref (gst_aravis->caps);
+		gst_aravis->caps = NULL;
+	}
 
         GST_DEBUG_OBJECT (gst_aravis, "Capture stoped");
 
diff --git a/src/arvtools.c b/src/arvtools.c
index d2b6429..fae79fa 100644
--- a/src/arvtools.c
+++ b/src/arvtools.c
@@ -688,3 +688,44 @@ CLEANUP:
 
 	return NULL;
 }
+
+/**
+ * SECTION: arvgst
+ * @short_description: Gstreamer utilities
+ */
+
+typedef struct {
+	ArvPixelFormat pixel_format;
+	const char *gst_caps_string;
+} ArvGstCapsInfos;
+
+ArvGstCapsInfos arv_gst_caps_infos[] = {
+	{ ARV_PIXEL_FORMAT_MONO_8,		"video/x-raw-yuv, format=(fourcc)Y8  "},
+	{ ARV_PIXEL_FORMAT_MONO_10,		"video/x-raw-gray, bpp=(int)16, depth=(int)16"},
+	{ ARV_PIXEL_FORMAT_MONO_12,		"video/x-raw-gray, bpp=(int)16, depth=(int)16"},
+	{ ARV_PIXEL_FORMAT_MONO_16,		"video/x-raw-gray, bpp=(int)16, depth=(int)16"},
+	{ ARV_PIXEL_FORMAT_YUV_422_PACKED,	"video/x-raw-yuv, format=(fourcc)UYVY"},
+	{ ARV_PIXEL_FORMAT_YUV_422_YUYV_PACKED,	"video/x-raw-yuv, format=(fourcc)YUY2"},
+	{ ARV_PIXEL_FORMAT_RGB_8_PACKED,	"video/x-raw-rgb, bpp=(int)24, depth=(int)24"},
+};
+
+/**
+ * arv_pixel_format_to_gst_caps_string:
+ * @pixel_format: a pixel format
+ * Return value: a gstreamer caps string describing the given @pixel_format
+ */
+
+const char *
+arv_pixel_format_to_gst_caps_string (ArvPixelFormat pixel_format)
+{
+	int i;
+
+	for (i = 0; i < G_N_ELEMENTS (arv_gst_caps_infos); i++)
+		if (arv_gst_caps_infos[i].pixel_format == pixel_format)
+			break;
+
+	if (i == G_N_ELEMENTS (arv_gst_caps_infos))
+		return NULL;
+
+	return arv_gst_caps_infos[i].gst_caps_string;
+}
diff --git a/src/arvtools.h b/src/arvtools.h
index c8747c3..3e2408b 100644
--- a/src/arvtools.h
+++ b/src/arvtools.h
@@ -107,6 +107,8 @@ void 		arv_copy_memory_with_endianess 	(void *to, size_t to_size, guint to_endia
 
 void * 		arv_decompress 			(void *input_buffer, size_t input_size, size_t *output_size);
 
+const char * 	arv_pixel_format_to_gst_caps_string 	(ArvPixelFormat pixel_format);
+
 /*
    Compatibility with glib < 2.23
    	Define 	G_DEFINE_INTERFACE
diff --git a/viewer/arvviewer.c b/viewer/arvviewer.c
index e7c97ac..0699f77 100644
--- a/viewer/arvviewer.c
+++ b/viewer/arvviewer.c
@@ -30,21 +30,6 @@
 #include <math.h>
 
 typedef struct {
-	ArvPixelFormat pixel_format;
-	const char *gst_caps_string;
-} ArvViewerCapsInfos;
-
-ArvViewerCapsInfos arv_viewer_caps_infos[] = {
-	{ ARV_PIXEL_FORMAT_MONO_8,		"video/x-raw-yuv, format=(fourcc)Y8  "},
-	{ ARV_PIXEL_FORMAT_MONO_10,		"video/x-raw-gray, bpp=(int)16, depth=(int)16"},
-	{ ARV_PIXEL_FORMAT_MONO_12,		"video/x-raw-gray, bpp=(int)16, depth=(int)16"},
-	{ ARV_PIXEL_FORMAT_MONO_16,		"video/x-raw-gray, bpp=(int)16, depth=(int)16"},
-	{ ARV_PIXEL_FORMAT_YUV_422_PACKED,	"video/x-raw-yuv, format=(fourcc)UYVY"},
-	{ ARV_PIXEL_FORMAT_YUV_422_YUYV_PACKED,	"video/x-raw-yuv, format=(fourcc)YUY2"},
-	{ ARV_PIXEL_FORMAT_RGB_8_PACKED,	"video/x-raw-rgb, bpp=(int)24, depth=(int)24"},
-};
-
-typedef struct {
 	ArvCamera *camera;
 	ArvDevice *device;
 	ArvStream *stream;
@@ -356,7 +341,6 @@ arv_viewer_select_camera_cb (GtkComboBox *combo_box, ArvViewer *viewer)
 	unsigned int payload;
 	int width;
 	int height;
-	int caps_infos_id;
 	unsigned int i;
 	gulong window_xid;
 	double exposure;
@@ -364,6 +348,7 @@ arv_viewer_select_camera_cb (GtkComboBox *combo_box, ArvViewer *viewer)
 	double frame_rate;
 	gint64 gain, gain_min, gain_max;
 	gboolean auto_gain, auto_exposure;
+	const char *caps_string;
 
 	g_return_if_fail (viewer != NULL);
 
@@ -429,11 +414,8 @@ arv_viewer_select_camera_cb (GtkComboBox *combo_box, ArvViewer *viewer)
 	g_signal_handler_unblock (viewer->auto_gain_toggle, viewer->auto_gain_clicked);
 	g_signal_handler_unblock (viewer->auto_exposure_toggle, viewer->auto_exposure_clicked);
 
-	for (caps_infos_id = 0; caps_infos_id < G_N_ELEMENTS (arv_viewer_caps_infos); caps_infos_id++)
-		if (arv_viewer_caps_infos[caps_infos_id].pixel_format == pixel_format)
-			break;
-
-	if (caps_infos_id == G_N_ELEMENTS (arv_viewer_caps_infos))
+	caps_string = arv_pixel_format_to_gst_caps_string (pixel_format);
+	if (caps_string == NULL)
 		return;
 
 	arv_camera_start_acquisition (viewer->camera);
@@ -447,7 +429,7 @@ arv_viewer_select_camera_cb (GtkComboBox *combo_box, ArvViewer *viewer)
 	gst_bin_add_many (GST_BIN (viewer->pipeline), viewer->appsrc, ffmpegcolorspace, ximagesink, NULL);
 	gst_element_link_many (viewer->appsrc, ffmpegcolorspace, ximagesink, NULL);
 
-	caps = gst_caps_from_string (arv_viewer_caps_infos[caps_infos_id].gst_caps_string);
+	caps = gst_caps_from_string (caps_string);
 	gst_caps_set_simple (caps,
 			     "width", G_TYPE_INT, width,
 			     "height", G_TYPE_INT, height,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]