summaryrefslogtreecommitdiff
path: root/src/lib/emotion
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@samsung.com>2013-12-13 12:44:19 +0900
committerCedric BAIL <cedric.bail@samsung.com>2013-12-13 12:44:19 +0900
commitca2f9571abf16670ac7c0d7c34d2221d97d5fffd (patch)
treebbd1de7df275eeb6abbf067b7f3de7ca49d7ca52 /src/lib/emotion
parent96c1d15ac04195a2fbee17294aae5a0ac3a3e1a1 (diff)
emotion: make webcam initialization lazy and non blocking.
This should fix T648.
Diffstat (limited to 'src/lib/emotion')
-rw-r--r--src/lib/emotion/emotion_webcam.c88
1 files changed, 68 insertions, 20 deletions
diff --git a/src/lib/emotion/emotion_webcam.c b/src/lib/emotion/emotion_webcam.c
index 974a9a8ca0..9a673d9174 100644
--- a/src/lib/emotion/emotion_webcam.c
+++ b/src/lib/emotion/emotion_webcam.c
@@ -27,6 +27,11 @@ typedef struct _Emotion_Webcams Emotion_Webcams;
27struct _Emotion_Webcams 27struct _Emotion_Webcams
28{ 28{
29 Eina_List *webcams; 29 Eina_List *webcams;
30
31 Ecore_Idler *idler;
32 Eina_List *check_list;
33
34 Eina_Bool init;
30}; 35};
31 36
32struct _Emotion_Webcam 37struct _Emotion_Webcam
@@ -62,6 +67,7 @@ _emotion_webcams_edds_new(void)
62 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Emotion_Webcams); 67 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Emotion_Webcams);
63 _webcams_edd = eet_data_descriptor_file_new(&eddc); 68 _webcams_edd = eet_data_descriptor_file_new(&eddc);
64 EET_DATA_DESCRIPTOR_ADD_LIST(_webcams_edd, Emotion_Webcams, "webcams", webcams, _webcam_edd); 69 EET_DATA_DESCRIPTOR_ADD_LIST(_webcams_edd, Emotion_Webcams, "webcams", webcams, _webcam_edd);
70 EET_DATA_DESCRIPTOR_ADD_BASIC(_webcam_edd, Emotion_Webcams, "init", init, EET_T_CHAR);
65 71
66 return _webcams_edd; 72 return _webcams_edd;
67} 73}
@@ -167,37 +173,64 @@ _emotion_webcam_new(const char *syspath)
167} 173}
168 174
169static void 175static void
170_emotion_enumerate_all_webcams(void) 176_emotion_webcam_remove_cb(void *user_data, void *func_data EINA_UNUSED)
171{ 177{
172 Eina_List *devices; 178 Emotion_Webcam *webcam;
173 const char *syspath;
174 179
175 devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_V4L, NULL); 180 /* called at the end of EMOTION_WEBCAM_ADD event, to prevent the free */
181 if (!user_data)
182 return;
176 183
177 EINA_LIST_FREE(devices, syspath) 184 webcam = user_data;
185
186 EINA_REFCOUNT_UNREF(webcam)
187 emotion_webcam_destroy(webcam);
188}
189
190static Eina_Bool
191_emotion_process_webcam(void *data)
192{
193 Emotion_Webcams *webcams;
194 Emotion_Webcam *test;
195 const char *syspath;
196
197 webcams = data;
198 syspath = eina_list_data_get(webcams->check_list);
199 if (!syspath)
178 { 200 {
179 Emotion_Webcam *test; 201 webcams->idler = NULL;
202 webcams->init = EINA_TRUE;
203 return EINA_FALSE;
204 }
180 205
181 test = _emotion_webcam_new(syspath); 206 webcams->check_list = eina_list_remove_list(webcams->check_list,
182 if (test) _emotion_check_device(test); 207 webcams->check_list);
183 208
184 eina_stringshare_del(syspath); 209 test = _emotion_webcam_new(syspath);
210 if (test)
211 {
212 if (_emotion_check_device(test))
213 ecore_event_add(EMOTION_WEBCAM_ADD, test, NULL, NULL);
214 else
215 _emotion_webcam_remove_cb(test, NULL);
185 } 216 }
217
218 eina_stringshare_del(syspath);
219
220 return EINA_TRUE;
186} 221}
187 222
188static void 223static void
189_emotion_webcam_remove_cb(void *user_data, void *func_data EINA_UNUSED) 224_emotion_enumerate_all_webcams(void)
190{ 225{
191 Emotion_Webcam *webcam; 226 Eina_List *devices;
192
193 /* called at the end of EMOTION_WEBCAM_ADD event, to prevent the free */
194 if (!user_data)
195 return;
196 227
197 webcam = user_data; 228 if (_emotion_webcams->init) return ;
229 devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_V4L, NULL);
198 230
199 EINA_REFCOUNT_UNREF(webcam) 231 _emotion_webcams->check_list = devices;
200 emotion_webcam_destroy(webcam); 232 _emotion_webcams->idler = ecore_idler_add(_emotion_process_webcam,
233 _emotion_webcams);
201} 234}
202 235
203static void 236static void
@@ -257,8 +290,6 @@ Eina_Bool emotion_webcam_init(void)
257#ifdef HAVE_EEZE 290#ifdef HAVE_EEZE
258 eeze_init(); 291 eeze_init();
259 292
260 _emotion_enumerate_all_webcams();
261
262 eeze_watcher = eeze_udev_watch_add(EEZE_UDEV_TYPE_V4L, 293 eeze_watcher = eeze_udev_watch_add(EEZE_UDEV_TYPE_V4L,
263 (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), 294 (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE),
264 _emotion_eeze_events, NULL); 295 _emotion_eeze_events, NULL);
@@ -271,6 +302,18 @@ void
271emotion_webcam_shutdown(void) 302emotion_webcam_shutdown(void)
272{ 303{
273 Emotion_Webcam *ew; 304 Emotion_Webcam *ew;
305 const char *syspath;
306
307 if (_emotion_webcams->idler)
308 {
309 ecore_idler_del(_emotion_webcams->idler);
310 _emotion_webcams->idler = NULL;
311 }
312
313 EINA_LIST_FREE(_emotion_webcams->check_list, syspath)
314 eina_stringshare_del(syspath);
315
316 _emotion_webcams->init = EINA_FALSE;
274 317
275 EINA_LIST_FREE(_emotion_webcams->webcams, ew) 318 EINA_LIST_FREE(_emotion_webcams->webcams, ew)
276 { 319 {
@@ -329,6 +372,9 @@ EAPI const Eina_List *
329emotion_webcams_get(void) 372emotion_webcams_get(void)
330{ 373{
331 EINA_SAFETY_ON_NULL_RETURN_VAL(_emotion_webcams, NULL); 374 EINA_SAFETY_ON_NULL_RETURN_VAL(_emotion_webcams, NULL);
375
376 _emotion_enumerate_all_webcams();
377
332 return _emotion_webcams->webcams; 378 return _emotion_webcams->webcams;
333} 379}
334 380
@@ -354,6 +400,8 @@ emotion_webcam_custom_get(const char *device)
354 400
355 EINA_SAFETY_ON_NULL_RETURN_VAL(_emotion_webcams, NULL); 401 EINA_SAFETY_ON_NULL_RETURN_VAL(_emotion_webcams, NULL);
356 402
403 _emotion_enumerate_all_webcams();
404
357 EINA_LIST_FOREACH(_emotion_webcams->webcams, l, ew) 405 EINA_LIST_FOREACH(_emotion_webcams->webcams, l, ew)
358 if (ew->device && strcmp(device, ew->device) == 0) 406 if (ew->device && strcmp(device, ew->device) == 0)
359 return ew->custom; 407 return ew->custom;