summaryrefslogtreecommitdiff
path: root/legacy/emotion/src/lib
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2011-07-17 21:58:40 +0000
committerCedric BAIL <cedric.bail@free.fr>2011-07-17 21:58:40 +0000
commit9384d7d814764b9e6804b728d9b734e76590be00 (patch)
treef8313fcb3400552451a0ae915b43b0529b0be45f /legacy/emotion/src/lib
parent0f1f6bfe1861c83b6fb958e131e3a5401d8a30dc (diff)
emotion: always forgot that damn svn add !
SVN revision: 61454
Diffstat (limited to 'legacy/emotion/src/lib')
-rw-r--r--legacy/emotion/src/lib/emotion_main.c320
1 files changed, 320 insertions, 0 deletions
diff --git a/legacy/emotion/src/lib/emotion_main.c b/legacy/emotion/src/lib/emotion_main.c
new file mode 100644
index 0000000000..8a5a055ddd
--- /dev/null
+++ b/legacy/emotion/src/lib/emotion_main.c
@@ -0,0 +1,320 @@
1#include "emotion_private.h"
2#include "Emotion.h"
3
4#ifdef EMOTION_HAVE_EEZE
5#include <sys/types.h>
6#include <sys/stat.h>
7#include <fcntl.h>
8# include <sys/ioctl.h>
9# include <linux/videodev2.h>
10
11# include <Ecore.h>
12# include <Eeze.h>
13#endif
14
15EAPI int EMOTION_WEBCAM_UPDATE = 0;
16
17struct ext_match_s
18{
19 unsigned int length;
20 const char *extension;
21};
22
23#define MATCHING(Ext) \
24 { sizeof (Ext), Ext }
25
26static const struct ext_match_s matchs[] =
27{ /* map extensions to know if it's a emotion playable content for good first-guess tries */
28 MATCHING(".264"),
29 MATCHING(".3g2"),
30 MATCHING(".3gp"),
31 MATCHING(".3gp2"),
32 MATCHING(".3gpp"),
33 MATCHING(".3gpp2"),
34 MATCHING(".3p2"),
35 MATCHING(".asf"),
36 MATCHING(".avi"),
37 MATCHING(".bdm"),
38 MATCHING(".bdmv"),
39 MATCHING(".clpi"),
40 MATCHING(".clp"),
41 MATCHING(".fla"),
42 MATCHING(".flv"),
43 MATCHING(".m1v"),
44 MATCHING(".m2v"),
45 MATCHING(".m2t"),
46 MATCHING(".m4v"),
47 MATCHING(".mkv"),
48 MATCHING(".mov"),
49 MATCHING(".mp2"),
50 MATCHING(".mp2ts"),
51 MATCHING(".mp4"),
52 MATCHING(".mpe"),
53 MATCHING(".mpeg"),
54 MATCHING(".mpg"),
55 MATCHING(".mpl"),
56 MATCHING(".mpls"),
57 MATCHING(".mts"),
58 MATCHING(".mxf"),
59 MATCHING(".nut"),
60 MATCHING(".nuv"),
61 MATCHING(".ogg"),
62 MATCHING(".ogm"),
63 MATCHING(".ogv"),
64 MATCHING(".rm"),
65 MATCHING(".rmj"),
66 MATCHING(".rmm"),
67 MATCHING(".rms"),
68 MATCHING(".rmx"),
69 MATCHING(".rmvb"),
70 MATCHING(".swf"),
71 MATCHING(".ts"),
72 MATCHING(".weba"),
73 MATCHING(".webm"),
74 MATCHING(".wmv")
75};
76
77Eina_Bool
78_emotion_object_extension_can_play_generic_get(const void *data __UNUSED__, const char *file)
79{
80 unsigned int length;
81 unsigned int i;
82
83 length = eina_stringshare_strlen(file) + 1;
84 if (length < 5) return EINA_FALSE;
85
86 for (i = 0; i < sizeof (matchs) / sizeof (struct ext_match_s); ++i)
87 {
88 if (matchs[i].length > length) continue;
89
90 if (!strcasecmp(matchs[i].extension,
91 file + length - matchs[i].length))
92 return EINA_TRUE;
93 }
94
95 return EINA_FALSE;
96}
97
98EAPI Eina_Bool
99emotion_object_extension_may_play_fast_get(const char *file)
100{
101 if (!file) return EINA_FALSE;
102 return _emotion_object_extension_can_play_generic_get(NULL, file);
103}
104
105EAPI Eina_Bool
106emotion_object_extension_may_play_get(const char *file)
107{
108 const char *tmp;
109 Eina_Bool result;
110
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);
115
116 return result;
117}
118
119#ifdef EMOTION_HAVE_EEZE
120struct _Emotion_Webcam
121{
122 EINA_REFCOUNT;
123
124 const char *syspath;
125 const char *device;
126 const char *name;
127};
128
129static int _emotion_webcams_count = 0;
130static Eina_List *_emotion_webcams = NULL;
131static Eeze_Udev_Watch *eeze_watcher = NULL;
132
133static void
134emotion_webcam_destroy(Emotion_Webcam *ew)
135{
136 eina_stringshare_del(ew->syspath);
137 eina_stringshare_del(ew->device);
138 eina_stringshare_del(ew->name);
139 free(ew);
140}
141
142static void
143_emotion_check_device(Emotion_Webcam *ew)
144{
145 Emotion_Webcam *check;
146 Eina_List *l;
147 struct v4l2_capability caps;
148 int fd;
149
150 if (!ew) return ;
151 if (!ew->device) goto on_error;
152
153 fd = open(ew->device, O_RDONLY);
154 if (!fd) goto on_error;
155
156 if (ioctl(fd, VIDIOC_QUERYCAP, &caps) == -1) goto on_error;
157
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)
163 goto on_error;
164
165 EINA_LIST_FOREACH(_emotion_webcams, l, check)
166 if (check->device == ew->device)
167 goto on_error;
168
169 _emotion_webcams = eina_list_append(_emotion_webcams, ew);
170
171 EINA_REFCOUNT_INIT(ew);
172
173 return ;
174
175 on_error:
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);
180 free(ew);
181}
182
183static Emotion_Webcam *
184_emotion_webcam_new(const char *syspath)
185{
186 Emotion_Webcam *test;
187
188 test = malloc(sizeof (Emotion_Webcam));
189 if (!test) return NULL;
190
191 test->syspath = eina_stringshare_ref(syspath);
192 test->device = eeze_udev_syspath_get_property(syspath, "DEVNAME");
193 test->name = eeze_udev_syspath_get_sysattr(syspath, "name");
194
195 return test;
196}
197
198static void
199_emotion_enumerate_all_webcams(void)
200{
201 Eina_List *devices;
202 const char *syspath;
203
204 devices = eeze_udev_find_by_type(EEZE_UDEV_TYPE_V4L, NULL);
205
206 EINA_LIST_FREE(devices, syspath)
207 {
208 Emotion_Webcam *test;
209
210 test = _emotion_webcam_new(syspath);
211 if (test) _emotion_check_device(test);
212
213 eina_stringshare_del(syspath);
214 }
215}
216
217static void
218_emotion_eeze_events(const char *syspath,
219 Eeze_Udev_Event ev,
220 void *data,
221 Eeze_Udev_Watch *watcher)
222{
223 if (ev == EEZE_UDEV_EVENT_REMOVE)
224 {
225 Emotion_Webcam *check;
226 Eina_List *l;
227
228 EINA_LIST_FOREACH(_emotion_webcams, l, check)
229 if (check->syspath == syspath)
230 {
231 _emotion_webcams = eina_list_remove_list(_emotion_webcams, l);
232 EINA_REFCOUNT_UNREF(check)
233 emotion_webcam_destroy(check);
234 break ;
235 }
236 }
237 else if (ev == EEZE_UDEV_EVENT_ADD)
238 {
239 Emotion_Webcam *test;
240
241 test = _emotion_webcam_new(syspath);
242 if (test) _emotion_check_device(test);
243 }
244 ecore_event_add(EMOTION_WEBCAM_UPDATE, NULL, NULL, NULL);
245}
246
247#endif
248
249EAPI Eina_Bool
250emotion_init(void)
251{
252#ifdef EMOTION_HAVE_EEZE
253 if (_emotion_webcams_count++) return EINA_TRUE;
254
255 EMOTION_WEBCAM_UPDATE = ecore_event_type_new();
256
257 eeze_init();
258
259 _emotion_enumerate_all_webcams();
260
261 eeze_watcher = eeze_udev_watch_add(EEZE_UDEV_TYPE_V4L,
262 (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE),
263 _emotion_eeze_events, NULL);
264
265 return EINA_TRUE;
266#else
267 return EINA_FALSE;
268#endif
269}
270
271EAPI Eina_Bool
272emotion_shutdown(void)
273{
274#ifdef EMOTION_HAVE_EEZE
275 if (--_emotion_webcams_count) return EINA_TRUE;
276
277 eeze_udev_watch_del(eeze_watcher);
278 eeze_watcher = NULL;
279
280 eeze_shutdown();
281
282 return EINA_TRUE;
283#else
284 return EINA_FALSE;
285#endif
286}
287
288EAPI const Eina_List *
289emotion_webcams_get(void)
290{
291#ifdef EMOTION_HAVE_EEZE
292 return _emotion_webcams;
293#else
294 return NULL;
295#endif
296}
297
298EAPI const char *
299emotion_webcam_name_get(Emotion_Webcam *ew)
300{
301 if (!ew) return NULL;
302
303#ifdef EMOTION_HAVE_EEZE
304 return ew->name;
305#else
306 return NULL;
307#endif
308}
309
310EAPI const char *
311emotion_webcam_device_get(Emotion_Webcam *ew)
312{
313 if (!ew) return NULL;
314
315#ifdef EMOTION_HAVE_EEZE
316 return ew->device;
317#else
318 return NULL;
319#endif
320}