~bcurtiswx/ubuntu/precise/empathy/3.4.2.3-0ubuntu1

« back to all changes in this revision

Viewing changes to libempathy/cheese-camera-device-monitor.c

  • Committer: Package Import Robot
  • Author(s): Ken VanDine
  • Date: 2011-12-21 15:12:56 UTC
  • mfrom: (1.1.84)
  • Revision ID: package-import@ubuntu.com-20111221151256-9b1pny75wphfmqd6
Tags: 3.3.3-0ubuntu1
* New upstream version
  - Require folks >= 0.6.6 (LP: #907501)
* debian/control
  - bump build depends for folks to >= 0.6.6
* debian/watch
  - use the .xz file

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is a copy of cheese-camera-device-monitor.c from Empathy. We
 
2
 * just renamespaced it to avoid conflicts when linking on libcheese. */
1
3
/*
2
4
 * Copyright © 2007,2008 Jaap Haitsma <jaap@haitsma.org>
3
5
 * Copyright © 2007-2009 daniel g. siegel <dgsiegel@gnome.org>
49
51
 * @short_description: Simple object to enumerate v4l devices
50
52
 * @include: cheese/cheese-camera-device-monitor.h
51
53
 *
52
 
 * #CheeseCameraDeviceMonitor provides a basic interface for
 
54
 * #EmpathyCameraDeviceMonitor provides a basic interface for
53
55
 * video4linux device enumeration and hotplugging.
54
56
 *
55
57
 * It uses either GUdev or some platform specific code to list video
56
58
 * devices.  It is also capable (right now in linux only, with the
57
59
 * udev backend) to monitor device plugging and emit a
58
 
 * CheeseCameraDeviceMonitor::added or
59
 
 * CheeseCameraDeviceMonitor::removed signal when an event happens.
 
60
 * EmpathyCameraDeviceMonitor::added or
 
61
 * EmpathyCameraDeviceMonitor::removed signal when an event happens.
60
62
 */
61
63
 
62
 
G_DEFINE_TYPE (CheeseCameraDeviceMonitor, cheese_camera_device_monitor, G_TYPE_OBJECT)
63
 
 
64
 
#define CHEESE_CAMERA_DEVICE_MONITOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o),                               \
65
 
                                                                                  CHEESE_TYPE_CAMERA_DEVICE_MONITOR, \
66
 
                                                                                  CheeseCameraDeviceMonitorPrivate))
67
 
 
68
 
#define CHEESE_CAMERA_DEVICE_MONITOR_ERROR cheese_camera_device_monitor_error_quark ()
69
 
 
70
 
GST_DEBUG_CATEGORY (cheese_device_monitor_cat);
71
 
#define GST_CAT_DEFAULT cheese_device_monitor_cat
72
 
 
73
 
enum CheeseCameraDeviceMonitorError
 
64
G_DEFINE_TYPE (EmpathyCameraDeviceMonitor, empathy_camera_device_monitor, G_TYPE_OBJECT)
 
65
 
 
66
#define EMPATHY_CAMERA_DEVICE_MONITOR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o),                               \
 
67
                                                                                  EMPATHY_TYPE_CAMERA_DEVICE_MONITOR, \
 
68
                                                                                  EmpathyCameraDeviceMonitorPrivate))
 
69
 
 
70
#define EMPATHY_CAMERA_DEVICE_MONITOR_ERROR empathy_camera_device_monitor_error_quark ()
 
71
 
 
72
GST_DEBUG_CATEGORY (empathy_device_monitor_cat);
 
73
#define GST_CAT_DEFAULT empathy_device_monitor_cat
 
74
 
 
75
enum EmpathyCameraDeviceMonitorError
74
76
{
75
 
  CHEESE_CAMERA_DEVICE_MONITOR_ERROR_UNKNOWN,
76
 
  CHEESE_CAMERA_DEVICE_MONITOR_ERROR_ELEMENT_NOT_FOUND
 
77
  EMPATHY_CAMERA_DEVICE_MONITOR_ERROR_UNKNOWN,
 
78
  EMPATHY_CAMERA_DEVICE_MONITOR_ERROR_ELEMENT_NOT_FOUND
77
79
};
78
80
 
79
81
typedef struct
83
85
#else
84
86
  guint filler;
85
87
#endif /* HAVE_UDEV */
86
 
} CheeseCameraDeviceMonitorPrivate;
 
88
} EmpathyCameraDeviceMonitorPrivate;
87
89
 
88
90
enum
89
91
{
96
98
 
97
99
#if 0
98
100
GQuark
99
 
cheese_camera_device_monitor_error_quark (void)
 
101
empathy_camera_device_monitor_error_quark (void)
100
102
{
101
 
  return g_quark_from_static_string ("cheese-camera-error-quark");
 
103
  return g_quark_from_static_string ("empathy-camera-error-quark");
102
104
}
103
105
#endif
104
106
 
105
107
#ifdef HAVE_UDEV
106
108
static void
107
 
cheese_camera_device_monitor_added (CheeseCameraDeviceMonitor *monitor,
 
109
empathy_camera_device_monitor_added (EmpathyCameraDeviceMonitor *monitor,
108
110
                                    GUdevDevice               *udevice)
109
111
{
110
112
  const char *device_file;
190
192
}
191
193
 
192
194
static void
193
 
cheese_camera_device_monitor_removed (CheeseCameraDeviceMonitor *monitor,
 
195
empathy_camera_device_monitor_removed (EmpathyCameraDeviceMonitor *monitor,
194
196
                                      GUdevDevice               *udevice)
195
197
{
196
198
  g_signal_emit (monitor, monitor_signals[REMOVED], 0,
198
200
}
199
201
 
200
202
static void
201
 
cheese_camera_device_monitor_uevent_cb (GUdevClient               *client,
 
203
empathy_camera_device_monitor_uevent_cb (GUdevClient               *client,
202
204
                                        const gchar               *action,
203
205
                                        GUdevDevice               *udevice,
204
 
                                        CheeseCameraDeviceMonitor *monitor)
 
206
                                        EmpathyCameraDeviceMonitor *monitor)
205
207
{
206
208
  if (g_str_equal (action, "remove"))
207
 
    cheese_camera_device_monitor_removed (monitor, udevice);
 
209
    empathy_camera_device_monitor_removed (monitor, udevice);
208
210
  else if (g_str_equal (action, "add"))
209
 
    cheese_camera_device_monitor_added (monitor, udevice);
 
211
    empathy_camera_device_monitor_added (monitor, udevice);
210
212
}
211
213
 
212
214
/**
213
 
 * cheese_camera_device_monitor_coldplug:
214
 
 * @monitor: a #CheeseCameraDeviceMonitor object.
 
215
 * empathy_camera_device_monitor_coldplug:
 
216
 * @monitor: a #EmpathyCameraDeviceMonitor object.
215
217
 *
216
218
 * Will actively look for plugged in cameras and emit
217
219
 * ::added for those new cameras.
219
221
 * to those signals before they are emitted.
220
222
 */
221
223
void
222
 
cheese_camera_device_monitor_coldplug (CheeseCameraDeviceMonitor *monitor)
 
224
empathy_camera_device_monitor_coldplug (EmpathyCameraDeviceMonitor *monitor)
223
225
{
224
 
  CheeseCameraDeviceMonitorPrivate *priv = CHEESE_CAMERA_DEVICE_MONITOR_GET_PRIVATE (monitor);
 
226
  EmpathyCameraDeviceMonitorPrivate *priv = EMPATHY_CAMERA_DEVICE_MONITOR_GET_PRIVATE (monitor);
225
227
  GList                            *devices, *l;
226
228
  gint                              i = 0;
227
229
 
235
237
  /* Initialize camera structures */
236
238
  for (l = devices; l != NULL; l = l->next)
237
239
  {
238
 
    cheese_camera_device_monitor_added (monitor, l->data);
 
240
    empathy_camera_device_monitor_added (monitor, l->data);
239
241
    g_object_unref (l->data);
240
242
    i++;
241
243
  }
246
248
 
247
249
#else /* HAVE_UDEV */
248
250
void
249
 
cheese_camera_device_monitor_coldplug (CheeseCameraDeviceMonitor *monitor)
 
251
empathy_camera_device_monitor_coldplug (EmpathyCameraDeviceMonitor *monitor)
250
252
{
251
253
  #if 0
252
 
  CheeseCameraDeviceMonitorPrivate *priv = CHEESE_CAMERA_DEVICE_MONITOR_GET_PRIVATE (monitor);
 
254
  EmpathyCameraDeviceMonitorPrivate *priv = EMPATHY_CAMERA_DEVICE_MONITOR_GET_PRIVATE (monitor);
253
255
  struct v4l2_capability            v2cap;
254
256
  struct video_capability           v1cap;
255
257
  int                               fd, ok;
307
309
  /* Initialize camera structures */
308
310
  for (l = devices; l != NULL; l = l->next)
309
311
  {
310
 
    cheese_camera_device_monitor_added (monitor, l->data);
 
312
    empathy_camera_device_monitor_added (monitor, l->data);
311
313
    g_object_unref (l->data);
312
314
  }
313
315
  g_list_free (devices);
317
319
#endif /* HAVE_UDEV */
318
320
 
319
321
static void
320
 
cheese_camera_device_monitor_finalize (GObject *object)
 
322
empathy_camera_device_monitor_finalize (GObject *object)
321
323
{
322
324
#ifdef HAVE_UDEV
323
 
  CheeseCameraDeviceMonitor *monitor = CHEESE_CAMERA_DEVICE_MONITOR (object);
324
 
  CheeseCameraDeviceMonitorPrivate *priv = CHEESE_CAMERA_DEVICE_MONITOR_GET_PRIVATE (monitor);
 
325
  EmpathyCameraDeviceMonitor *monitor = EMPATHY_CAMERA_DEVICE_MONITOR (object);
 
326
  EmpathyCameraDeviceMonitorPrivate *priv = EMPATHY_CAMERA_DEVICE_MONITOR_GET_PRIVATE (monitor);
325
327
 
326
328
  if (priv->client != NULL)
327
329
  {
329
331
    priv->client = NULL;
330
332
  }
331
333
#endif /* HAVE_UDEV */
332
 
  G_OBJECT_CLASS (cheese_camera_device_monitor_parent_class)->finalize (object);
 
334
  G_OBJECT_CLASS (empathy_camera_device_monitor_parent_class)->finalize (object);
333
335
}
334
336
 
335
337
static void
336
 
cheese_camera_device_monitor_class_init (CheeseCameraDeviceMonitorClass *klass)
 
338
empathy_camera_device_monitor_class_init (EmpathyCameraDeviceMonitorClass *klass)
337
339
{
338
340
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
339
341
 
340
 
  if (cheese_device_monitor_cat == NULL)
341
 
    GST_DEBUG_CATEGORY_INIT (cheese_device_monitor_cat,
342
 
                             "cheese-device-monitor",
343
 
                             0, "Cheese Camera Device Monitor");
 
342
  if (empathy_device_monitor_cat == NULL)
 
343
    GST_DEBUG_CATEGORY_INIT (empathy_device_monitor_cat,
 
344
                             "empathy-device-monitor",
 
345
                             0, "Empathy Camera Device Monitor");
344
346
 
345
 
  object_class->finalize = cheese_camera_device_monitor_finalize;
 
347
  object_class->finalize = empathy_camera_device_monitor_finalize;
346
348
 
347
349
  /**
348
 
   * CheeseCameraDeviceMonitor::added:
 
350
   * EmpathyCameraDeviceMonitor::added:
349
351
   * @device: A private object representing the newly added camera.
350
352
   * @id: Device unique identifier.
351
353
   * @device: Device file name  (e.g. /dev/video2).
353
355
   * @api_version: Supported video4linux API: 1 for v4l, 2 for v4l2.
354
356
   *
355
357
   * The ::added signal is emitted when a camera is added, or on start-up
356
 
   * after #cheese_camera_device_monitor_colplug is called.
 
358
   * after #empathy_camera_device_monitor_colplug is called.
357
359
   **/
358
360
  monitor_signals[ADDED] = g_signal_new ("added", G_OBJECT_CLASS_TYPE (klass),
359
361
                                         G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
360
 
                                         G_STRUCT_OFFSET (CheeseCameraDeviceMonitorClass, added),
 
362
                                         G_STRUCT_OFFSET (EmpathyCameraDeviceMonitorClass, added),
361
363
                                         NULL, NULL,
362
364
                                         g_cclosure_marshal_generic,
363
365
                                         G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT);
364
366
 
365
367
  /**
366
 
   * CheeseCameraDeviceMonitor::removed:
 
368
   * EmpathyCameraDeviceMonitor::removed:
367
369
   * @device: A private object representing the newly added camera
368
370
   * @id: Device unique identifier.
369
371
   *
372
374
   **/
373
375
  monitor_signals[REMOVED] = g_signal_new ("removed", G_OBJECT_CLASS_TYPE (klass),
374
376
                                           G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
375
 
                                           G_STRUCT_OFFSET (CheeseCameraDeviceMonitorClass, removed),
 
377
                                           G_STRUCT_OFFSET (EmpathyCameraDeviceMonitorClass, removed),
376
378
                                           NULL, NULL,
377
379
                                           g_cclosure_marshal_generic,
378
380
                                           G_TYPE_NONE, 1, G_TYPE_STRING);
379
381
 
380
 
  g_type_class_add_private (klass, sizeof (CheeseCameraDeviceMonitorPrivate));
 
382
  g_type_class_add_private (klass, sizeof (EmpathyCameraDeviceMonitorPrivate));
381
383
}
382
384
 
383
385
static void
384
 
cheese_camera_device_monitor_init (CheeseCameraDeviceMonitor *monitor)
 
386
empathy_camera_device_monitor_init (EmpathyCameraDeviceMonitor *monitor)
385
387
{
386
388
#ifdef HAVE_UDEV
387
 
  CheeseCameraDeviceMonitorPrivate *priv         = CHEESE_CAMERA_DEVICE_MONITOR_GET_PRIVATE (monitor);
 
389
  EmpathyCameraDeviceMonitorPrivate *priv         = EMPATHY_CAMERA_DEVICE_MONITOR_GET_PRIVATE (monitor);
388
390
  const gchar *const                subsystems[] = {"video4linux", NULL};
389
391
 
390
392
  priv->client = g_udev_client_new (subsystems);
391
393
  g_signal_connect (G_OBJECT (priv->client), "uevent",
392
 
                    G_CALLBACK (cheese_camera_device_monitor_uevent_cb), monitor);
 
394
                    G_CALLBACK (empathy_camera_device_monitor_uevent_cb), monitor);
393
395
#endif /* HAVE_UDEV */
394
396
}
395
397
 
396
398
/**
397
 
 * cheese_camera_device_monitor_new:
398
 
 *
399
 
 * Returns a new #CheeseCameraDeviceMonitor object.
400
 
 *
401
 
 * Return value: a new #CheeseCameraDeviceMonitor object.
 
399
 * empathy_camera_device_monitor_new:
 
400
 *
 
401
 * Returns a new #EmpathyCameraDeviceMonitor object.
 
402
 *
 
403
 * Return value: a new #EmpathyCameraDeviceMonitor object.
402
404
 **/
403
 
CheeseCameraDeviceMonitor *
404
 
cheese_camera_device_monitor_new (void)
 
405
EmpathyCameraDeviceMonitor *
 
406
empathy_camera_device_monitor_new (void)
405
407
{
406
 
  return g_object_new (CHEESE_TYPE_CAMERA_DEVICE_MONITOR, NULL);
 
408
  return g_object_new (EMPATHY_TYPE_CAMERA_DEVICE_MONITOR, NULL);
407
409
}
408
410
 
409
411
/*