summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2011-11-09 16:27:49 +0000
committerCedric BAIL <cedric.bail@free.fr>2011-11-09 16:27:49 +0000
commit2fb36c52f6277888f1e8ef949933b273ea434dc9 (patch)
treeacdad3f3822c4329b38a06713714d51dc7a9a6dd
parent8810e636e714647af0f9dee57ba25b2c3000ae3a (diff)
emotion: make it possible to define webcam statically.
SVN revision: 64995
Diffstat (limited to '')
-rw-r--r--legacy/emotion/configure.ac2
-rw-r--r--legacy/emotion/src/lib/emotion_main.c134
-rw-r--r--legacy/emotion/src/lib/emotion_private.h2
3 files changed, 108 insertions, 30 deletions
diff --git a/legacy/emotion/configure.ac b/legacy/emotion/configure.ac
index 98512efc53..b704f1763d 100644
--- a/legacy/emotion/configure.ac
+++ b/legacy/emotion/configure.ac
@@ -107,7 +107,7 @@ EFL_CHECK_DOXYGEN([build_doc="yes"], [build_doc="no"])
107 107
108### Checks for libraries 108### Checks for libraries
109 109
110PKG_CHECK_MODULES(EMOTION, [eina >= 1.0.0 evas >= 1.0.0 ecore >= 1.0.0]) 110PKG_CHECK_MODULES(EMOTION, [eina >= 1.0.0 evas >= 1.0.0 ecore >= 1.0.0 eet >= 1.4.0])
111requirement_emotion="ecore >= 1.0.0 evas >= 1.0.0 eina >= 1.0.0" 111requirement_emotion="ecore >= 1.0.0 evas >= 1.0.0 eina >= 1.0.0"
112 112
113if test "x${have_emotion_test}" = "xyes" ; then 113if test "x${have_emotion_test}" = "xyes" ; then
diff --git a/legacy/emotion/src/lib/emotion_main.c b/legacy/emotion/src/lib/emotion_main.c
index 0e2afed543..cca649151b 100644
--- a/legacy/emotion/src/lib/emotion_main.c
+++ b/legacy/emotion/src/lib/emotion_main.c
@@ -14,6 +14,8 @@
14# include <Eeze.h> 14# include <Eeze.h>
15#endif 15#endif
16 16
17#include <Eet.h>
18
17EAPI int EMOTION_WEBCAM_UPDATE = 0; 19EAPI int EMOTION_WEBCAM_UPDATE = 0;
18 20
19struct ext_match_s 21struct ext_match_s
@@ -118,7 +120,13 @@ emotion_object_extension_may_play_get(const char *file)
118 return result; 120 return result;
119} 121}
120 122
121#ifdef EMOTION_HAVE_EEZE 123typedef struct _Emotion_Webcams Emotion_Webcams;
124
125struct _Emotion_Webcams
126{
127 Eina_List *webcams;
128};
129
122struct _Emotion_Webcam 130struct _Emotion_Webcam
123{ 131{
124 EINA_REFCOUNT; 132 EINA_REFCOUNT;
@@ -127,19 +135,49 @@ struct _Emotion_Webcam
127 const char *device; 135 const char *device;
128 const char *name; 136 const char *name;
129 137
138 const char *custom;
139
130 const char *filename; 140 const char *filename;
131}; 141};
132 142
133static int _emotion_webcams_count = 0; 143static int _emotion_webcams_count = 0;
134static Eina_List *_emotion_webcams = NULL; 144static Eet_Data_Descriptor *_webcam_edd;
145static Eet_Data_Descriptor *_webcams_edd;
146
147static Emotion_Webcams *_emotion_webcams = NULL;
148static Eet_File *_emotion_webcams_file = NULL;
149
150static Eet_Data_Descriptor *
151_emotion_webcams_data(void)
152{
153 Eet_Data_Descriptor_Class eddc;
154
155 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Emotion_Webcam);
156 _webcam_edd = eet_data_descriptor_file_new(&eddc);
157 EET_DATA_DESCRIPTOR_ADD_BASIC(_webcam_edd, Emotion_Webcam, "device", device, EET_T_STRING);
158 EET_DATA_DESCRIPTOR_ADD_BASIC(_webcam_edd, Emotion_Webcam, "name", name, EET_T_STRING);
159 EET_DATA_DESCRIPTOR_ADD_BASIC(_webcam_edd, Emotion_Webcam, "custom", custom, EET_T_STRING);
160 EET_DATA_DESCRIPTOR_ADD_BASIC(_webcam_edd, Emotion_Webcam, "filename", filename, EET_T_STRING);
161
162 EET_EINA_FILE_DATA_DESCRIPTOR_CLASS_SET(&eddc, Emotion_Webcams);
163 _webcams_edd = eet_data_descriptor_file_new(&eddc);
164 EET_DATA_DESCRIPTOR_ADD_LIST(_webcams_edd, Emotion_Webcams, "webcams", webcams, _webcam_edd);
165
166 return _webcams_edd;
167}
168
169#ifdef EMOTION_HAVE_EEZE
135static Eeze_Udev_Watch *eeze_watcher = NULL; 170static Eeze_Udev_Watch *eeze_watcher = NULL;
136 171
137static void 172static void
138emotion_webcam_destroy(Emotion_Webcam *ew) 173emotion_webcam_destroy(Emotion_Webcam *ew)
139{ 174{
140 eina_stringshare_del(ew->syspath); 175 if (!ew->custom)
141 eina_stringshare_del(ew->device); 176 {
142 eina_stringshare_del(ew->name); 177 eina_stringshare_del(ew->syspath);
178 eina_stringshare_del(ew->device);
179 eina_stringshare_del(ew->name);
180 }
143 free(ew); 181 free(ew);
144} 182}
145 183
@@ -169,11 +207,11 @@ _emotion_check_device(Emotion_Webcam *ew)
169 || caps.capabilities & V4L2_CAP_MODULATOR) 207 || caps.capabilities & V4L2_CAP_MODULATOR)
170 goto on_error; 208 goto on_error;
171 209
172 EINA_LIST_FOREACH(_emotion_webcams, l, check) 210 EINA_LIST_FOREACH(_emotion_webcams->webcams, l, check)
173 if (check->device == ew->device) 211 if (check->device == ew->device)
174 goto on_error; 212 goto on_error;
175 213
176 _emotion_webcams = eina_list_append(_emotion_webcams, ew); 214 _emotion_webcams->webcams = eina_list_append(_emotion_webcams->webcams, ew);
177 215
178 EINA_REFCOUNT_INIT(ew); 216 EINA_REFCOUNT_INIT(ew);
179 217
@@ -198,6 +236,7 @@ _emotion_webcam_new(const char *syspath)
198 test = malloc(sizeof (Emotion_Webcam)); 236 test = malloc(sizeof (Emotion_Webcam));
199 if (!test) return NULL; 237 if (!test) return NULL;
200 238
239 test->custom = NULL;
201 test->syspath = eina_stringshare_ref(syspath); 240 test->syspath = eina_stringshare_ref(syspath);
202 test->name = eeze_udev_syspath_get_sysattr(syspath, "name"); 241 test->name = eeze_udev_syspath_get_sysattr(syspath, "name");
203 242
@@ -241,10 +280,10 @@ _emotion_eeze_events(const char *syspath,
241 Emotion_Webcam *check; 280 Emotion_Webcam *check;
242 Eina_List *l; 281 Eina_List *l;
243 282
244 EINA_LIST_FOREACH(_emotion_webcams, l, check) 283 EINA_LIST_FOREACH(_emotion_webcams->webcams, l, check)
245 if (check->syspath == syspath) 284 if (check->syspath == syspath)
246 { 285 {
247 _emotion_webcams = eina_list_remove_list(_emotion_webcams, l); 286 _emotion_webcams->webcams = eina_list_remove_list(_emotion_webcams->webcams, l);
248 EINA_REFCOUNT_UNREF(check) 287 EINA_REFCOUNT_UNREF(check)
249 emotion_webcam_destroy(check); 288 emotion_webcam_destroy(check);
250 break ; 289 break ;
@@ -265,9 +304,31 @@ _emotion_eeze_events(const char *syspath,
265EAPI Eina_Bool 304EAPI Eina_Bool
266emotion_init(void) 305emotion_init(void)
267{ 306{
268#ifdef EMOTION_HAVE_EEZE 307 char buffer[4096];
308
269 if (_emotion_webcams_count++) return EINA_TRUE; 309 if (_emotion_webcams_count++) return EINA_TRUE;
270 310
311 snprintf(buffer, 4096, "%s/emotion.cfg", PACKAGE_DATA_DIR);
312 _emotion_webcams_file = eet_open(buffer, EET_FILE_MODE_READ);
313 if (_emotion_webcams_file)
314 {
315 Eet_Data_Descriptor *edd;
316
317 edd = _emotion_webcams_data();
318
319 _emotion_webcams = eet_data_read(_emotion_webcams_file, edd, "config");
320
321 eet_data_descriptor_free(_webcams_edd); _webcams_edd = NULL;
322 eet_data_descriptor_free(_webcam_edd); _webcam_edd = NULL;
323 }
324
325 if (!_emotion_webcams)
326 {
327 _emotion_webcams = calloc(1, sizeof (Emotion_Webcams));
328 if (!_emotion_webcams) return EINA_FALSE;
329 }
330
331#ifdef EMOTION_HAVE_EEZE
271 EMOTION_WEBCAM_UPDATE = ecore_event_type_new(); 332 EMOTION_WEBCAM_UPDATE = ecore_event_type_new();
272 333
273 eeze_init(); 334 eeze_init();
@@ -277,38 +338,48 @@ emotion_init(void)
277 eeze_watcher = eeze_udev_watch_add(EEZE_UDEV_TYPE_V4L, 338 eeze_watcher = eeze_udev_watch_add(EEZE_UDEV_TYPE_V4L,
278 (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), 339 (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE),
279 _emotion_eeze_events, NULL); 340 _emotion_eeze_events, NULL);
341#endif
280 342
281 return EINA_TRUE; 343 return EINA_TRUE;
282#else
283 return EINA_FALSE;
284#endif
285} 344}
286 345
287EAPI Eina_Bool 346EAPI Eina_Bool
288emotion_shutdown(void) 347emotion_shutdown(void)
289{ 348{
290#ifdef EMOTION_HAVE_EEZE 349 Emotion_Webcam *ew;
350
291 if (--_emotion_webcams_count) return EINA_TRUE; 351 if (--_emotion_webcams_count) return EINA_TRUE;
292 352
353 EINA_LIST_FREE(_emotion_webcams->webcams, ew)
354 {
355 /* There is currently no way to refcount from the outside, this help, but could lead to some issue */
356 EINA_REFCOUNT_UNREF(ew)
357 emotion_webcam_destroy(ew);
358 }
359 free(_emotion_webcams);
360 _emotion_webcams = NULL;
361
362 if (_emotion_webcams_file)
363 {
364 /* As long as there is no one reference any pointer, you are safe */
365 eet_close(_emotion_webcams_file);
366 _emotion_webcams_file = NULL;
367 }
368
369#ifdef EMOTION_HAVE_EEZE
293 eeze_udev_watch_del(eeze_watcher); 370 eeze_udev_watch_del(eeze_watcher);
294 eeze_watcher = NULL; 371 eeze_watcher = NULL;
295 372
296 eeze_shutdown(); 373 eeze_shutdown();
374#endif
297 375
298 return EINA_TRUE; 376 return EINA_TRUE;
299#else
300 return EINA_FALSE;
301#endif
302} 377}
303 378
304EAPI const Eina_List * 379EAPI const Eina_List *
305emotion_webcams_get(void) 380emotion_webcams_get(void)
306{ 381{
307#ifdef EMOTION_HAVE_EEZE 382 return _emotion_webcams->webcams;
308 return _emotion_webcams;
309#else
310 return NULL;
311#endif
312} 383}
313 384
314EAPI const char * 385EAPI const char *
@@ -316,11 +387,7 @@ emotion_webcam_name_get(const Emotion_Webcam *ew)
316{ 387{
317 if (!ew) return NULL; 388 if (!ew) return NULL;
318 389
319#ifdef EMOTION_HAVE_EEZE
320 return ew->name; 390 return ew->name;
321#else
322 return NULL;
323#endif
324} 391}
325 392
326EAPI const char * 393EAPI const char *
@@ -328,9 +395,18 @@ emotion_webcam_device_get(const Emotion_Webcam *ew)
328{ 395{
329 if (!ew) return NULL; 396 if (!ew) return NULL;
330 397
331#ifdef EMOTION_HAVE_EEZE
332 return ew->device; 398 return ew->device;
333#else 399}
400
401EAPI const char *
402emotion_webcam_custom_get(const char *device)
403{
404 const Emotion_Webcam *ew;
405 const Eina_List *l;
406
407 EINA_LIST_FOREACH(_emotion_webcams->webcams, l, ew)
408 if (ew->device && strcmp(device, ew->device) == 0)
409 return ew->custom;
410
334 return NULL; 411 return NULL;
335#endif
336} 412}
diff --git a/legacy/emotion/src/lib/emotion_private.h b/legacy/emotion/src/lib/emotion_private.h
index bbdf0eb69b..7c5eb6e0aa 100644
--- a/legacy/emotion/src/lib/emotion_private.h
+++ b/legacy/emotion/src/lib/emotion_private.h
@@ -137,4 +137,6 @@ EAPI void _emotion_seek_done(Evas_Object *obj);
137EAPI Eina_Bool _emotion_module_register(const char *name, Emotion_Module_Open open, Emotion_Module_Close close); 137EAPI Eina_Bool _emotion_module_register(const char *name, Emotion_Module_Open open, Emotion_Module_Close close);
138EAPI Eina_Bool _emotion_module_unregister(const char *name); 138EAPI Eina_Bool _emotion_module_unregister(const char *name);
139 139
140EAPI const char *emotion_webcam_custom_get(const char *device);
141
140#endif 142#endif