1 #include "emotion_private.h"
4 #ifdef EMOTION_HAVE_EEZE
8 # include <sys/ioctl.h>
9 # include <linux/videodev2.h>
15 EAPI int EMOTION_WEBCAM_UPDATE = 0;
20 const char *extension;
23 #define MATCHING(Ext) \
26 static const struct ext_match_s matchs[] =
27 { /* map extensions to know if it's a emotion playable content for good first-guess tries */
78 _emotion_object_extension_can_play_generic_get(const void *data __UNUSED__, const char *file)
83 length = eina_stringshare_strlen(file) + 1;
84 if (length < 5) return EINA_FALSE;
86 for (i = 0; i < sizeof (matchs) / sizeof (struct ext_match_s); ++i)
88 if (matchs[i].length > length) continue;
90 if (!strcasecmp(matchs[i].extension,
91 file + length - matchs[i].length))
99 emotion_object_extension_may_play_fast_get(const char *file)
101 if (!file) return EINA_FALSE;
102 return _emotion_object_extension_can_play_generic_get(NULL, file);
106 emotion_object_extension_may_play_get(const char *file)
111 if (!file) return EINA_FALSE;
112 tmp = eina_stringshare_add(file);
113 result = emotion_object_extension_may_play_fast_get(tmp);
114 eina_stringshare_del(tmp);
119 #ifdef EMOTION_HAVE_EEZE
120 struct _Emotion_Webcam
129 static int _emotion_webcams_count = 0;
130 static Eina_List *_emotion_webcams = NULL;
131 static Eeze_Udev_Watch *eeze_watcher = NULL;
134 emotion_webcam_destroy(Emotion_Webcam *ew)
136 eina_stringshare_del(ew->syspath);
137 eina_stringshare_del(ew->device);
138 eina_stringshare_del(ew->name);
143 _emotion_check_device(Emotion_Webcam *ew)
145 Emotion_Webcam *check;
147 struct v4l2_capability caps;
151 if (!ew->device) goto on_error;
153 fd = open(ew->device, O_RDONLY);
154 if (!fd) goto on_error;
156 if (ioctl(fd, VIDIOC_QUERYCAP, &caps) == -1) goto on_error;
158 /* Likely not a webcam */
159 if (!caps.capabilities & V4L2_CAP_VIDEO_CAPTURE) goto on_error;
160 if (caps.capabilities & V4L2_CAP_TUNER
161 || caps.capabilities & V4L2_CAP_RADIO
162 || caps.capabilities & V4L2_CAP_MODULATOR)
165 EINA_LIST_FOREACH(_emotion_webcams, l, check)
166 if (check->device == ew->device)
169 _emotion_webcams = eina_list_append(_emotion_webcams, ew);
171 EINA_REFCOUNT_INIT(ew);
176 fprintf(stderr, "'%s' is not a webcam\n", ew->name);
177 eina_stringshare_del(ew->syspath);
178 eina_stringshare_del(ew->device);
179 eina_stringshare_del(ew->name);
183 static Emotion_Webcam *
184 _emotion_webcam_new(const char *syspath)
186 Emotion_Webcam *test;
190 test = malloc(sizeof (Emotion_Webcam));
191 if (!test) return NULL;
193 test->syspath = eina_stringshare_ref(syspath);
194 test->name = eeze_udev_syspath_get_sysattr(syspath, "name");
196 device = eeze_udev_syspath_get_property(syspath, "DEVNAME");
197 local = alloca(eina_stringshare_strlen(device) + 8);
198 snprintf(local, eina_stringshare_strlen(device) + 8, "v4l2://%s", device);
199 test->device = eina_stringshare_add(local);
200 eina_stringshare_del(device);
206 _emotion_enumerate_all_webcams(void)
211 devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_V4L, NULL);
213 EINA_LIST_FREE(devices, syspath)
215 Emotion_Webcam *test;
217 test = _emotion_webcam_new(syspath);
218 if (test) _emotion_check_device(test);
220 eina_stringshare_del(syspath);
225 _emotion_eeze_events(const char *syspath,
228 Eeze_Udev_Watch *watcher)
230 if (ev == EEZE_UDEV_EVENT_REMOVE)
232 Emotion_Webcam *check;
235 EINA_LIST_FOREACH(_emotion_webcams, l, check)
236 if (check->syspath == syspath)
238 _emotion_webcams = eina_list_remove_list(_emotion_webcams, l);
239 EINA_REFCOUNT_UNREF(check)
240 emotion_webcam_destroy(check);
244 else if (ev == EEZE_UDEV_EVENT_ADD)
246 Emotion_Webcam *test;
248 test = _emotion_webcam_new(syspath);
249 if (test) _emotion_check_device(test);
251 ecore_event_add(EMOTION_WEBCAM_UPDATE, NULL, NULL, NULL);
259 #ifdef EMOTION_HAVE_EEZE
260 if (_emotion_webcams_count++) return EINA_TRUE;
262 EMOTION_WEBCAM_UPDATE = ecore_event_type_new();
266 _emotion_enumerate_all_webcams();
268 eeze_watcher = eeze_udev_watch_add(EEZE_UDEV_TYPE_V4L,
269 (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE),
270 _emotion_eeze_events, NULL);
279 emotion_shutdown(void)
281 #ifdef EMOTION_HAVE_EEZE
282 if (--_emotion_webcams_count) return EINA_TRUE;
284 eeze_udev_watch_del(eeze_watcher);
295 EAPI const Eina_List *
296 emotion_webcams_get(void)
298 #ifdef EMOTION_HAVE_EEZE
299 return _emotion_webcams;
306 emotion_webcam_name_get(Emotion_Webcam *ew)
308 if (!ew) return NULL;
310 #ifdef EMOTION_HAVE_EEZE
318 emotion_webcam_device_get(Emotion_Webcam *ew)
320 if (!ew) return NULL;
322 #ifdef EMOTION_HAVE_EEZE