[cheese/cheese-window-refactor] Don't initialize device objects in device monitor
- From: Filippo Argiolas <fargiolas src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [cheese/cheese-window-refactor] Don't initialize device objects in device monitor
- Date: Wed, 3 Feb 2010 10:12:52 +0000 (UTC)
commit 506f3716d02dbdcfef633fd34a93fd818108d10a
Author: Filippo Argiolas <filippo argiolas gmail com>
Date: Wed Feb 3 10:41:04 2010 +0100
Don't initialize device objects in device monitor
This way the monitor becomes just a tiny udev interface that doesn't use
gstreamer for caps retrieval so that multiple monitors can be
instanciated.
The device creation has been moved into the "added" signal
handler in cheese-camera.c
configure.ac | 3 ++
libcheese/Makefile.am | 12 ++++++++++-
libcheese/cheese-camera-device-monitor.c | 29 ++++++++++-----------------
libcheese/cheese-camera-device-monitor.h | 6 ++++-
libcheese/cheese-camera-device.c | 31 +++++++++++++++--------------
libcheese/cheese-camera-device.h | 2 +-
libcheese/cheese-camera.c | 23 ++++++++++++++++++---
libcheese/cheese-marshal.list | 1 +
tests/cheese-test-monitor.c | 9 +++----
9 files changed, 71 insertions(+), 45 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 342bae4..231c669 100644
--- a/configure.ac
+++ b/configure.ac
@@ -147,6 +147,9 @@ CHEESE_LIBS="$CHEESE_LIBS -lgstinterfaces-0.10"
AC_SUBST(CHEESE_LIBS)
+GLIB_GENMARSHAL=`$PKG_CONFIG --variable=glib_genmarshal glib-2.0`
+AC_SUBST(GLIB_GENMARSHAL)
+
AC_PATH_PROG(GCONFTOOL, gconftool-2)
AM_GCONF_SOURCE_2
diff --git a/libcheese/Makefile.am b/libcheese/Makefile.am
index bea7082..25b821c 100644
--- a/libcheese/Makefile.am
+++ b/libcheese/Makefile.am
@@ -12,8 +12,16 @@ INCLUDES = \
lib_LTLIBRARIES = libcheese-gtk.la
noinst_LTLIBRARIES = libcheesecommon.la
+cheese-marshal.h: cheese-marshal.list Makefile
+ $(AM_V_GEN) $(GLIB_GENMARSHAL) --prefix=_cheese_marshal $< --header > $@
+
+cheese-marshal.c: cheese-marshal.list Makefile
+ $(AM_V_GEN) $(GLIB_GENMARSHAL) --prefix=_cheese_marshal $< --body > $@
+
libcheese_gtk_la_CFLAGS = $(CHEESE_CFLAGS)
+marshal_SOURCES = cheese-marshal.c cheese-marshal.h
+
libcheesecommon_la_SOURCES = \
cheese-gconf.c \
cheese-gconf.h \
@@ -28,7 +36,8 @@ libcheesecommon_la_SOURCES = \
cheese-flash.h \
cheese-flash.c \
cheese-countdown.c \
- cheese-countdown.h
+ cheese-countdown.h \
+ $(marshal_SOURCES)
libcheese_gtk_la_SOURCES = \
cheese-avatar-chooser.c \
@@ -41,6 +50,7 @@ libcheese_gtk_la_SOURCES = \
$(NULL)
EXTRA_DIST = cheese-gtk.symbols
+CLEANFILES = $(marshal_SOURCES)
# FIXME when we have a .pc file, and sonames
cheesedir = $(includedir)/cheese
diff --git a/libcheese/cheese-camera-device-monitor.c b/libcheese/cheese-camera-device-monitor.c
index 80dc28d..dd141eb 100644
--- a/libcheese/cheese-camera-device-monitor.c
+++ b/libcheese/cheese-camera-device-monitor.c
@@ -26,7 +26,6 @@
#include <glib-object.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <string.h>
-#include <cheese-camera-device.h>
#ifdef HAVE_UDEV
#define G_UDEV_API_IS_SUBJECT_TO_CHANGE 1
@@ -45,6 +44,7 @@
#endif
#include "cheese-camera-device-monitor.h"
+#include "cheese-marshal.h"
G_DEFINE_TYPE (CheeseCameraDeviceMonitor, cheese_camera_device_monitor, G_TYPE_OBJECT)
@@ -93,17 +93,17 @@ cheese_camera_device_monitor_added (CheeseCameraDeviceMonitor *monitor,
GUdevDevice *udevice)
{
const char *device_file;
- const char *gstreamer_src, *product_name;
+ const char *product_name;
const char *vendor;
const char *product;
const char *bus;
gint vendor_id = 0;
gint product_id = 0;
gint v4l_version = 0;
- GError *error = NULL;
- CheeseCameraDevice *device;
- GST_INFO ("Checking udev device '%s'", g_udev_device_get_property (udevice, "DEVPATH"));
+ const gchar *devpath = g_udev_device_get_property (udevice, "DEVPATH");
+
+ GST_INFO ("Checking udev device '%s'", devpath);
bus = g_udev_device_get_property (udevice, "ID_BUS");
if (g_strcmp0 (bus, "usb") == 0)
@@ -155,7 +155,6 @@ cheese_camera_device_monitor_added (CheeseCameraDeviceMonitor *monitor,
"Removing it from device list.", device_file);
return;
}
- gstreamer_src = (v4l_version == 2) ? "v4l2src" : "v4lsrc";
product_name = g_udev_device_get_property (udevice, "ID_V4L_PRODUCT");
}
else if (v4l_version == 0)
@@ -168,17 +167,11 @@ cheese_camera_device_monitor_added (CheeseCameraDeviceMonitor *monitor,
g_assert_not_reached ();
}
- device = cheese_camera_device_new (g_udev_device_get_property (udevice, "DEVPATH"),
- device_file,
- product_name,
- gstreamer_src,
- &error);
- if (device == NULL)
- GST_WARNING ("Device initialization for %s failed: %s ",
+ g_signal_emit (monitor, monitor_signals[ADDED], 0,
+ devpath,
device_file,
- (error != NULL) ? error->message : "Unknown reason");
- else
- g_signal_emit (monitor, monitor_signals[ADDED], 0, device);
+ product_name,
+ v4l_version);
}
static void
@@ -349,8 +342,8 @@ cheese_camera_device_monitor_class_init (CheeseCameraDeviceMonitorClass *klass)
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (CheeseCameraDeviceMonitorClass, added),
NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE, 1, G_TYPE_OBJECT);
+ _cheese_marshal_VOID__STRING_STRING_STRING_INT,
+ G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT);
/**
* CheeseCameraDeviceMonitor::removed:
diff --git a/libcheese/cheese-camera-device-monitor.h b/libcheese/cheese-camera-device-monitor.h
index b42ac22..3910054 100644
--- a/libcheese/cheese-camera-device-monitor.h
+++ b/libcheese/cheese-camera-device-monitor.h
@@ -47,7 +47,11 @@ typedef struct
{
GObjectClass parent_class;
- void (*added)(CheeseCameraDeviceMonitor *camera, GObject *device);
+ void (*added)(CheeseCameraDeviceMonitor *camera,
+ const char *id,
+ const char *device_file,
+ const char *product_name,
+ int api_version);
void (*removed)(CheeseCameraDeviceMonitor *camera, const char *id);
} CheeseCameraDeviceMonitorClass;
diff --git a/libcheese/cheese-camera-device.c b/libcheese/cheese-camera-device.c
index bd0d235..e1786e8 100644
--- a/libcheese/cheese-camera-device.c
+++ b/libcheese/cheese-camera-device.c
@@ -69,15 +69,16 @@ enum
PROP_NAME,
PROP_FILE,
PROP_ID,
- PROP_SRC
+ PROP_API
};
typedef struct
{
gchar *device;
gchar *id;
- gchar *src;
+ const gchar *src;
gchar *name;
+ gint api;
GstCaps *caps;
GList *formats;
@@ -344,7 +345,10 @@ static void
cheese_camera_device_constructed (GObject *object)
{
CheeseCameraDevice *device = CHEESE_CAMERA_DEVICE (object);
+ CheeseCameraDevicePrivate *priv =
+ CHEESE_CAMERA_DEVICE_GET_PRIVATE (device);
+ priv->src = (priv->api == 2) ? "v4l2src" : "v4lsrc";
cheese_camera_device_get_caps (device);
@@ -370,8 +374,8 @@ cheese_camera_device_get_property (GObject *object, guint prop_id, GValue *value
case PROP_ID:
g_value_set_string (value, priv->id);
break;
- case PROP_SRC:
- g_value_set_string (value, priv->src);
+ case PROP_API:
+ g_value_set_int (value, priv->api);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -403,10 +407,8 @@ cheese_camera_device_set_property (GObject *object, guint prop_id, const GValue
g_free (priv->device);
priv->device = g_value_dup_string (value);
break;
- case PROP_SRC:
- if (priv->src)
- g_free (priv->src);
- priv->src = g_value_dup_string (value);
+ case PROP_API:
+ priv->api = g_value_get_int (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -423,7 +425,6 @@ cheese_camera_device_finalize (GObject *object)
g_free (priv->device);
g_free (priv->id);
- g_free (priv->src);
g_free (priv->name);
gst_caps_unref (priv->caps);
@@ -462,10 +463,10 @@ cheese_camera_device_class_init (CheeseCameraDeviceClass *klass)
NULL, NULL, NULL,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
- g_object_class_install_property (object_class, PROP_SRC,
- g_param_spec_string ("src",
- NULL, NULL, NULL,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ g_object_class_install_property (object_class, PROP_API,
+ g_param_spec_int ("api", NULL, NULL,
+ 1, 2, 2,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
g_type_class_add_private (klass, sizeof (CheeseCameraDevicePrivate));
}
@@ -526,7 +527,7 @@ CheeseCameraDevice *
cheese_camera_device_new (const gchar *device_id,
const gchar *device_file,
const gchar *product_name,
- const gchar *gstreamer_source,
+ gint api_version,
GError **error)
{
return CHEESE_CAMERA_DEVICE (g_initable_new (CHEESE_TYPE_CAMERA_DEVICE,
@@ -534,7 +535,7 @@ cheese_camera_device_new (const gchar *device_id,
"device-id", device_id,
"device-file", device_file,
"name", product_name,
- "src", gstreamer_source,
+ "api", api_version,
NULL));
}
diff --git a/libcheese/cheese-camera-device.h b/libcheese/cheese-camera-device.h
index 9aa085a..56e2773 100644
--- a/libcheese/cheese-camera-device.h
+++ b/libcheese/cheese-camera-device.h
@@ -63,7 +63,7 @@ GType cheese_camera_device_get_type (void) G_GNUC_CONST;
CheeseCameraDevice *cheese_camera_device_new (const gchar *device_id,
const gchar *device_file,
const gchar *product_name,
- const gchar *gstreamer_source,
+ gint api_version,
GError **error);
GstCaps * cheese_camera_device_get_caps_for_format (CheeseCameraDevice *device,
diff --git a/libcheese/cheese-camera.c b/libcheese/cheese-camera.c
index 003e67d..816695d 100644
--- a/libcheese/cheese-camera.c
+++ b/libcheese/cheese-camera.c
@@ -288,13 +288,28 @@ cheese_camera_bus_message_cb (GstBus *bus, GstMessage *message, CheeseCamera *ca
static void
cheese_camera_add_device (CheeseCameraDeviceMonitor *monitor,
- CheeseCameraDevice *device,
+ const gchar *id,
+ const gchar *device_file,
+ const gchar *product_name,
+ gint api_version,
CheeseCamera *camera)
{
CheeseCameraPrivate *priv = CHEESE_CAMERA_GET_PRIVATE (camera);
-
- g_ptr_array_add (priv->camera_devices, device);
- priv->num_camera_devices++;
+ GError *error;
+
+ CheeseCameraDevice *device = cheese_camera_device_new (id,
+ device_file,
+ product_name,
+ api_version,
+ &error);
+ if (device == NULL)
+ GST_WARNING ("Device initialization for %s failed: %s ",
+ device_file,
+ (error != NULL) ? error->message : "Unknown reason");
+ else {
+ g_ptr_array_add (priv->camera_devices, device);
+ priv->num_camera_devices++;
+ }
}
static void
diff --git a/libcheese/cheese-marshal.list b/libcheese/cheese-marshal.list
new file mode 100644
index 0000000..7013605
--- /dev/null
+++ b/libcheese/cheese-marshal.list
@@ -0,0 +1 @@
+VOID:STRING,STRING,STRING,INT
diff --git a/tests/cheese-test-monitor.c b/tests/cheese-test-monitor.c
index 7db0e28..aed85e9 100644
--- a/tests/cheese-test-monitor.c
+++ b/tests/cheese-test-monitor.c
@@ -5,13 +5,12 @@
static void
added_cb (CheeseCameraDeviceMonitor *monitor,
- CheeseCameraDevice *device)
+ const char *id,
+ const char *device_file,
+ const char *product_name,
+ gint api_version)
{
- gchar *id;
-
- g_object_get (device, "device-id", &id, NULL);
g_message ("Added new device with ID '%s'", id);
- g_free (id);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]