From 4ce3e1e72f600be69702ac918f4ff8a099d49c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Bouchaud=20=28yoz=29?= Date: Wed, 9 Oct 2013 12:29:04 +0200 Subject: [PATCH] emotion: add two events to trigger when a webcam is plugged or unplugged --- AUTHORS | 2 ++ ChangeLog | 4 ++++ NEWS | 1 + src/lib/emotion/Emotion.h | 4 +++- src/lib/emotion/emotion_webcam.c | 36 +++++++++++++++++++++++++------- 5 files changed, 39 insertions(+), 8 deletions(-) diff --git a/AUTHORS b/AUTHORS index e0e0cecbe4..0893f793b7 100644 --- a/AUTHORS +++ b/AUTHORS @@ -306,6 +306,8 @@ Pierre Le Magourou Hugo Camboulive Sohyun Kim Leandro Dorileo +Michael Bouchaud (yoz) +Aymeric Dumaz Ethumb ------ diff --git a/ChangeLog b/ChangeLog index cb4ea4ee4d..0fec054967 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2013-10-10 Michael Bouchaud (yoz) + + * Emotion: add two events to trigger webcam plug and unplug + 2013-10-04 ChunEon Park (Hermet) * Eina: fix eina_file_map_lines() to not drop of one character in the last line. diff --git a/NEWS b/NEWS index fc83666916..173dd1b0f6 100644 --- a/NEWS +++ b/NEWS @@ -424,6 +424,7 @@ Fixes: * Emotion: - Fix memory leak in gstreamer_ecore_x_check. - Fix backend priority order. + - Add two events to trigger webcam plug and unplug * Ethumb: - Fix memory leak in error case. * Eeze: diff --git a/src/lib/emotion/Emotion.h b/src/lib/emotion/Emotion.h index 454ee0f42e..34d1cc3af0 100644 --- a/src/lib/emotion/Emotion.h +++ b/src/lib/emotion/Emotion.h @@ -1287,7 +1287,9 @@ EAPI Evas_Object *emotion_object_image_get(const Evas_Object *obj); typedef struct _Emotion_Webcam Emotion_Webcam; /**< Webcam description */ -EAPI extern int EMOTION_WEBCAM_UPDATE; /**< Ecore_Event triggered when a new webcam is plugged in */ +EAPI extern int EMOTION_WEBCAM_UPDATE; /**< Ecore_Event triggered when a new webcam is plugged or unplugged */ +EAPI extern int EMOTION_WEBCAM_ADD; /**< Ecore_Event triggered when a new webcam is plugged in @since 1.8*/ +EAPI extern int EMOTION_WEBCAM_DEL; /**< Ecore_Event triggered when a webcam is unplugged @since 1.8 */ /** * @brief Get a list of active and available webcam diff --git a/src/lib/emotion/emotion_webcam.c b/src/lib/emotion/emotion_webcam.c index 52e6b5b457..6302742fdb 100644 --- a/src/lib/emotion/emotion_webcam.c +++ b/src/lib/emotion/emotion_webcam.c @@ -19,6 +19,8 @@ #include "emotion_private.h" EAPI int EMOTION_WEBCAM_UPDATE = 0; +EAPI int EMOTION_WEBCAM_ADD = 0; +EAPI int EMOTION_WEBCAM_DEL = 0; typedef struct _Emotion_Webcams Emotion_Webcams; @@ -89,7 +91,7 @@ emotion_webcam_destroy(Emotion_Webcam *ew) #ifdef HAVE_EEZE static Eeze_Udev_Watch *eeze_watcher = NULL; -static void +static Eina_Bool _emotion_check_device(Emotion_Webcam *ew) { #ifdef HAVE_V4L2 @@ -99,7 +101,7 @@ _emotion_check_device(Emotion_Webcam *ew) int fd = -1; #endif - if (!ew) return; + if (!ew) return EINA_FALSE; #ifdef HAVE_V4L2 if (!ew->device) goto on_error; @@ -125,7 +127,7 @@ _emotion_check_device(Emotion_Webcam *ew) if (fd >= 0) close(fd); - return; + return EINA_TRUE; on_error: #endif @@ -137,6 +139,7 @@ _emotion_check_device(Emotion_Webcam *ew) #ifdef HAVE_V4L2 if (fd > 0) close(fd); #endif + return EINA_FALSE; } static Emotion_Webcam * @@ -182,6 +185,21 @@ _emotion_enumerate_all_webcams(void) } } +static void +_emotion_webcam_remove_cb(void *user_data, void *func_data EINA_UNUSED) +{ + Emotion_Webcam *webcam; + + /* called at the end of EMOTION_WEBCAM_ADD event, to prevent the free */ + if (!user_data) + return; + + webcam = user_data; + + EINA_REFCOUNT_UNREF(webcam) + emotion_webcam_destroy(webcam); +} + static void _emotion_eeze_events(const char *syspath, Eeze_Udev_Event ev, @@ -196,9 +214,10 @@ _emotion_eeze_events(const char *syspath, EINA_LIST_FOREACH(_emotion_webcams->webcams, l, check) if (check->syspath == syspath) { - _emotion_webcams->webcams = eina_list_remove_list(_emotion_webcams->webcams, l); - EINA_REFCOUNT_UNREF(check) - emotion_webcam_destroy(check); + _emotion_webcams->webcams = + eina_list_remove_list(_emotion_webcams->webcams, l); + ecore_event_add(EMOTION_WEBCAM_DEL, check, + _emotion_webcam_remove_cb, check); break ; } } @@ -207,7 +226,8 @@ _emotion_eeze_events(const char *syspath, Emotion_Webcam *test; test = _emotion_webcam_new(syspath); - if (test) _emotion_check_device(test); + if ((test) && (_emotion_check_device(test))) + ecore_event_add(EMOTION_WEBCAM_ADD, test, NULL, NULL); } ecore_event_add(EMOTION_WEBCAM_UPDATE, NULL, NULL, NULL); } @@ -217,6 +237,8 @@ _emotion_eeze_events(const char *syspath, Eina_Bool emotion_webcam_init(void) { EMOTION_WEBCAM_UPDATE = ecore_event_type_new(); + EMOTION_WEBCAM_ADD = ecore_event_type_new(); + EMOTION_WEBCAM_DEL = ecore_event_type_new(); eet_init(); _emotion_webcams_edds_new();