[longomatch/device: 3/5] add support to signal device connected/disconnected changes



commit 2d05f7e8c2e814285ba61fd95c73ff23fe655945
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Sun Aug 1 20:13:33 2010 +0200

    add support to signal device connected/disconnected changes

 libcesarplayer/src/gst-camera-capturer.c |   34 ++++++++++++++++++++++++++++++
 libcesarplayer/src/gst-camera-capturer.h |    1 +
 2 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/libcesarplayer/src/gst-camera-capturer.c b/libcesarplayer/src/gst-camera-capturer.c
index a0c9cff..6c77b63 100644
--- a/libcesarplayer/src/gst-camera-capturer.c
+++ b/libcesarplayer/src/gst-camera-capturer.c
@@ -74,6 +74,7 @@ enum
   SIGNAL_ERROR,
   SIGNAL_EOS,
   SIGNAL_STATE_CHANGED,
+  SIGNAL_DEVICE_CHANGE,
   LAST_SIGNAL
 };
 
@@ -874,6 +875,14 @@ gst_camera_capturer_class_init (GstCameraCapturerClass * klass)
       G_SIGNAL_RUN_LAST,
       G_STRUCT_OFFSET (GstCameraCapturerClass, eos),
       NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+
+  gcc_signals[SIGNAL_DEVICE_CHANGE] =
+      g_signal_new ("device-change",
+      G_TYPE_FROM_CLASS (object_class),
+      G_SIGNAL_RUN_LAST,
+      G_STRUCT_OFFSET (GstCameraCapturerClass, device_change),
+      NULL, NULL,
+      g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
 }
 
 void
@@ -1409,6 +1418,31 @@ gcc_bus_message_cb (GstBus * bus, GstMessage * message, gpointer data)
       }
     }
 
+    case GST_MESSAGE_ELEMENT:
+    {
+      const GstStructure *s;
+      gint device_change;
+
+      /* We only care about messages sent by the device source */
+      if (GST_MESSAGE_SRC (message) !=  GST_OBJECT (gcc->priv->device_source))
+        break;
+
+      s = gst_message_get_structure (message);
+      /* check if it's bus reset message and it contains the
+       * 'current-device-change' field */
+      if (g_strcmp0(gst_structure_get_name(s), "ieee1394-bus-reset"))
+        break;
+      if (!gst_structure_has_field (s, "current-device-change"))
+        break;
+
+      /* emit a signal if the device was connected or disconnected */
+      device_change = gst_structure_get_int (s, "current-device-change",
+          &device_change);
+      if (device_change != 0)
+        g_signal_emit (gcc, gcc_signals[SIGNAL_DEVICE_CHANGE], 0, device_change);
+      break;
+    }
+
     default:
       GST_LOG ("Unhandled message: %" GST_PTR_FORMAT, message);
       break;
diff --git a/libcesarplayer/src/gst-camera-capturer.h b/libcesarplayer/src/gst-camera-capturer.h
index 40c98ae..0e83bb5 100644
--- a/libcesarplayer/src/gst-camera-capturer.h
+++ b/libcesarplayer/src/gst-camera-capturer.h
@@ -54,6 +54,7 @@ struct _GstCameraCapturerClass
 
   void (*eos) (GstCameraCapturer * gcc);
   void (*error) (GstCameraCapturer * gcc, const char *message);
+  void (*device_change) (GstCameraCapturer * gcc, gint *device_change);
   void (*invalidsource) (GstCameraCapturer * gcc);
 };
 



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