summaryrefslogtreecommitdiff
path: root/src/lib/emotion/emotion_modules.c
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@gmail.com>2013-01-11 00:27:35 +0000
committerGustavo Sverzut Barbieri <barbieri@gmail.com>2013-01-11 00:27:35 +0000
commit6e963a6118a515d71abb71dc07bfaf7de32c630c (patch)
tree80b4bef99cbdd8aedf257e15e31bca2c1b692913 /src/lib/emotion/emotion_modules.c
parent30cbbefd6a29d4f21640e271fb1708fa07d69a88 (diff)
efl/emotion: start to refactor engine handling.
Removed the engine handling out from smart object, later the module API will change and we'll be able to simplify many things. My plan is to allow generic players to register along as regular modules. SVN revision: 82597
Diffstat (limited to 'src/lib/emotion/emotion_modules.c')
-rw-r--r--src/lib/emotion/emotion_modules.c489
1 files changed, 487 insertions, 2 deletions
diff --git a/src/lib/emotion/emotion_modules.c b/src/lib/emotion/emotion_modules.c
index a019918fe0..41168565a7 100644
--- a/src/lib/emotion/emotion_modules.c
+++ b/src/lib/emotion/emotion_modules.c
@@ -17,8 +17,8 @@ Eina_Bool generic_module_init(void);
17void generic_module_shutdown(void); 17void generic_module_shutdown(void);
18#endif 18#endif
19 19
20Eina_Hash *_emotion_backends = NULL; 20static Eina_Hash *_emotion_backends = NULL;
21Eina_Array *_emotion_modules = NULL; 21static Eina_Array *_emotion_modules = NULL;
22 22
23static void 23static void
24_emotion_modules_load(void) 24_emotion_modules_load(void)
@@ -80,6 +80,9 @@ emotion_modules_init(void)
80{ 80{
81 int static_modules = 0; 81 int static_modules = 0;
82 82
83 _emotion_backends = eina_hash_string_small_new(free);
84 EINA_SAFETY_ON_NULL_RETURN_VAL(_emotion_backends, EINA_FALSE);
85
83 _emotion_modules_load(); 86 _emotion_modules_load();
84 87
85 /* Init static module */ 88 /* Init static module */
@@ -146,3 +149,485 @@ _emotion_module_unregister(const char *name)
146 INF("unregister module=%s", name); 149 INF("unregister module=%s", name);
147 return eina_hash_del_by_key(_emotion_backends, name); 150 return eina_hash_del_by_key(_emotion_backends, name);
148} 151}
152
153struct _Emotion_Engine_Instance
154{
155 Emotion_Video_Module *api;
156 Evas_Object *obj;
157 char *name;
158 void *data;
159};
160
161#define EMOTION_ENGINE_INSTANCE_CHECK(inst, meth, ...) \
162 do \
163 { \
164 if (!inst) \
165 { \
166 DBG("no instance to call "#meth); \
167 return __VA_ARGS__; \
168 } \
169 if (!inst->api->meth) \
170 { \
171 DBG("no "#meth" in instance=%p", inst); \
172 return __VA_ARGS__; \
173 } \
174 } \
175 while (0)
176
177#define EMOTION_ENGINE_INSTANCE_CALL(inst, meth, ...) \
178 do \
179 { \
180 EMOTION_ENGINE_INSTANCE_CHECK(inst, meth); \
181 inst->api->meth(inst->data, ## __VA_ARGS__); \
182 } \
183 while (0)
184
185#define EMOTION_ENGINE_INSTANCE_CALL_RET(inst, meth, retval, ...) \
186 do \
187 { \
188 EMOTION_ENGINE_INSTANCE_CHECK(inst, meth, retval); \
189 return inst->api->meth(inst->data, ## __VA_ARGS__); \
190 } \
191 while (0)
192
193
194static const char *_backend_priority[] = {
195 "gstreamer",
196 "xine",
197 "generic"
198};
199
200Emotion_Engine_Instance *
201emotion_engine_instance_new(const char *name, Evas_Object *obj, Emotion_Module_Options *opts)
202{
203 // TODO: rewrite
204 Eina_Emotion_Plugins *plugin;
205 unsigned int i = 0;
206 Emotion_Video_Module *mod = NULL;
207 void *data = NULL;
208
209 if (!_emotion_backends)
210 {
211 ERR("No backend loaded");
212 return NULL;
213 }
214
215 if (!name && getenv("EMOTION_ENGINE"))
216 {
217 name = getenv("EMOTION_ENGINE");
218 DBG("using EMOTION_ENGINE=%s", name);
219 }
220
221 /* FIXME: Always look for a working backend. */
222 retry:
223 if (!name || i > 0)
224 name = _backend_priority[i++];
225
226 plugin = eina_hash_find(_emotion_backends, name);
227 DBG("try engine=%s, plugin=%p", name, plugin);
228 if (!plugin)
229 {
230 if (i != 0 && i < (sizeof (_backend_priority) / sizeof (char*)))
231 goto retry;
232
233 ERR("No backend loaded");
234 return NULL;
235 }
236
237 if (plugin->open(obj, (const Emotion_Video_Module **) &mod, &data, opts))
238 {
239 Emotion_Engine_Instance *inst = calloc(1, sizeof(Emotion_Engine_Instance));
240 INF("opened %s, mod=%p, video=%p", name, mod, data);
241 mod->plugin = plugin;
242 inst->api = mod;
243 inst->obj = obj;
244 inst->data = data;
245 inst->name = strdup(name);
246 return inst;
247 }
248
249 if (i != 0 && i < (sizeof (_backend_priority) / sizeof (char*)))
250 goto retry;
251
252 ERR("Unable to load module: %s", name);
253
254 return NULL;
255}
256
257void
258emotion_engine_instance_del(Emotion_Engine_Instance *inst)
259{
260 EINA_SAFETY_ON_NULL_RETURN(inst);
261 inst->api->plugin->close(inst->api, inst->data); // TODO: weird api
262}
263
264Eina_Bool
265emotion_engine_instance_name_equal(const Emotion_Engine_Instance *inst, const char *name)
266{
267 /* these are valid, no safety macros here */
268 if (!name) return EINA_FALSE;
269 if (!inst) return EINA_FALSE;
270 return strcmp(name, inst->name) == 0;
271}
272
273void *
274emotion_engine_instance_data_get(const Emotion_Engine_Instance *inst)
275{
276 EINA_SAFETY_ON_NULL_RETURN_VAL(inst, NULL);
277 return inst->data;
278}
279
280unsigned char
281emotion_engine_instance_file_open(Emotion_Engine_Instance *inst, const char *file)
282{
283 EMOTION_ENGINE_INSTANCE_CHECK(inst, file_open, EINA_FALSE);
284 return inst->api->file_open(file, inst->obj, inst->data); // TODO: weird api
285}
286
287void
288emotion_engine_instance_file_close(Emotion_Engine_Instance *inst)
289{
290 EMOTION_ENGINE_INSTANCE_CALL(inst, file_close);
291}
292
293void
294emotion_engine_instance_play(Emotion_Engine_Instance *inst, double pos)
295{
296 EMOTION_ENGINE_INSTANCE_CALL(inst, play, pos);
297}
298
299void
300emotion_engine_instance_stop(Emotion_Engine_Instance *inst)
301{
302 EMOTION_ENGINE_INSTANCE_CALL(inst, stop);
303}
304
305void
306emotion_engine_instance_size_get(const Emotion_Engine_Instance *inst, int *w, int *h)
307{
308 EMOTION_ENGINE_INSTANCE_CALL(inst, size_get, w, h);
309}
310
311void
312emotion_engine_instance_pos_set(Emotion_Engine_Instance *inst, double pos)
313{
314 EMOTION_ENGINE_INSTANCE_CALL(inst, pos_set, pos);
315}
316
317double
318emotion_engine_instance_len_get(const Emotion_Engine_Instance *inst)
319{
320 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, len_get, 0.0);
321}
322
323double
324emotion_engine_instance_buffer_size_get(const Emotion_Engine_Instance *inst)
325{
326 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, buffer_size_get, 1.0);
327}
328
329int
330emotion_engine_instance_fps_num_get(const Emotion_Engine_Instance *inst)
331{
332 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, fps_num_get, 1);
333}
334
335int
336emotion_engine_instance_fps_den_get(const Emotion_Engine_Instance *inst)
337{
338 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, fps_den_get, 1);
339}
340
341double
342emotion_engine_instance_fps_get(const Emotion_Engine_Instance *inst)
343{
344 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, fps_get, 1.0);
345}
346
347double
348emotion_engine_instance_pos_get(const Emotion_Engine_Instance *inst)
349{
350 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, pos_get, 0.0);
351}
352
353void
354emotion_engine_instance_vis_set(Emotion_Engine_Instance *inst, Emotion_Vis vis)
355{
356 EMOTION_ENGINE_INSTANCE_CALL(inst, vis_set, vis);
357}
358
359Emotion_Vis
360emotion_engine_instance_vis_get(const Emotion_Engine_Instance *inst)
361{
362 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, vis_get, EMOTION_VIS_NONE);
363}
364
365Eina_Bool
366emotion_engine_instance_vis_supported(Emotion_Engine_Instance *inst, Emotion_Vis vis)
367{
368 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, vis_supported, EINA_FALSE, vis);
369}
370
371double
372emotion_engine_instance_ratio_get(const Emotion_Engine_Instance *inst)
373{
374 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, ratio_get, 0.0);
375}
376
377Eina_Bool
378emotion_engine_instance_video_handled(Emotion_Engine_Instance *inst)
379{
380 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, video_handled, EINA_FALSE);
381}
382
383Eina_Bool
384emotion_engine_instance_audio_handled(Emotion_Engine_Instance *inst)
385{
386 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, audio_handled, EINA_FALSE);
387}
388
389Eina_Bool
390emotion_engine_instance_seekable(Emotion_Engine_Instance *inst)
391{
392 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, seekable, EINA_FALSE);
393}
394
395void
396emotion_engine_instance_frame_done(Emotion_Engine_Instance *inst)
397{
398 EMOTION_ENGINE_INSTANCE_CALL(inst, frame_done);
399}
400
401Emotion_Format
402emotion_engine_instance_format_get(const Emotion_Engine_Instance *inst)
403{
404 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, format_get, EMOTION_FORMAT_NONE);
405}
406
407void
408emotion_engine_instance_video_data_size_get(const Emotion_Engine_Instance *inst, int *w, int *h)
409{
410 EMOTION_ENGINE_INSTANCE_CALL(inst, video_data_size_get, w, h);
411}
412
413Eina_Bool
414emotion_engine_instance_yuv_rows_get(const Emotion_Engine_Instance *inst, int w, int h, unsigned char **yrows, unsigned char **urows, unsigned char **vrows)
415{
416 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, yuv_rows_get, EINA_FALSE, w, h, yrows, urows, vrows);
417}
418
419Eina_Bool
420emotion_engine_instance_bgra_data_get(const Emotion_Engine_Instance *inst, unsigned char **bgra_data)
421{
422 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, bgra_data_get, EINA_FALSE, bgra_data);
423}
424
425void
426emotion_engine_instance_event_feed(Emotion_Engine_Instance *inst, int event)
427{
428 EMOTION_ENGINE_INSTANCE_CALL(inst, event_feed, event);
429}
430
431void
432emotion_engine_instance_event_mouse_button_feed(Emotion_Engine_Instance *inst, int button, int x, int y)
433{
434 EMOTION_ENGINE_INSTANCE_CALL(inst, event_mouse_button_feed, button, x, y);
435}
436
437void
438emotion_engine_instance_event_mouse_move_feed(Emotion_Engine_Instance *inst, int x, int y)
439{
440 EMOTION_ENGINE_INSTANCE_CALL(inst, event_mouse_move_feed, x, y);
441}
442
443int
444emotion_engine_instance_video_channel_count(Emotion_Engine_Instance *inst)
445{
446 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, video_channel_count, 0);
447}
448
449void
450emotion_engine_instance_video_channel_set(Emotion_Engine_Instance *inst, int channel)
451{
452 EMOTION_ENGINE_INSTANCE_CALL(inst, video_channel_set, channel);
453}
454
455int
456emotion_engine_instance_video_channel_get(const Emotion_Engine_Instance *inst)
457{
458 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, video_channel_get, 0);
459}
460
461void
462emotion_engine_instance_video_subtitle_file_set(Emotion_Engine_Instance *inst, const char *filepath)
463{
464 EMOTION_ENGINE_INSTANCE_CALL(inst, video_subtitle_file_set, filepath);
465}
466
467const char *
468emotion_engine_instance_video_subtitle_file_get(const Emotion_Engine_Instance *inst)
469{
470 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, video_subtitle_file_get, NULL);
471}
472
473const char *
474emotion_engine_instance_video_channel_name_get(const Emotion_Engine_Instance *inst, int channel)
475{
476 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, video_channel_name_get, NULL, channel);
477}
478
479void
480emotion_engine_instance_video_channel_mute_set(Emotion_Engine_Instance *inst, Eina_Bool mute)
481{
482 EMOTION_ENGINE_INSTANCE_CALL(inst, video_channel_mute_set, mute);
483}
484
485Eina_Bool
486emotion_engine_instance_video_channel_mute_get(const Emotion_Engine_Instance *inst)
487{
488 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, video_channel_mute_get, EINA_FALSE);
489}
490
491int
492emotion_engine_instance_audio_channel_count(Emotion_Engine_Instance *inst)
493{
494 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, audio_channel_count, 0);
495}
496
497void
498emotion_engine_instance_audio_channel_set(Emotion_Engine_Instance *inst, int channel)
499{
500 EMOTION_ENGINE_INSTANCE_CALL(inst, audio_channel_set, channel);
501}
502
503int
504emotion_engine_instance_audio_channel_get(const Emotion_Engine_Instance *inst)
505{
506 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, audio_channel_get, 0);
507}
508
509const char *
510emotion_engine_instance_audio_channel_name_get(const Emotion_Engine_Instance *inst, int channel)
511{
512 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, audio_channel_name_get, NULL, channel);
513}
514
515void
516emotion_engine_instance_audio_channel_mute_set(Emotion_Engine_Instance *inst, Eina_Bool mute)
517{
518 EMOTION_ENGINE_INSTANCE_CALL(inst, audio_channel_mute_set, mute);
519}
520
521Eina_Bool
522emotion_engine_instance_audio_channel_mute_get(const Emotion_Engine_Instance *inst)
523{
524 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, audio_channel_mute_get, EINA_FALSE);
525}
526
527void
528emotion_engine_instance_audio_channel_volume_set(Emotion_Engine_Instance *inst, double vol)
529{
530 EMOTION_ENGINE_INSTANCE_CALL(inst, audio_channel_volume_set, vol);
531}
532
533double
534emotion_engine_instance_audio_channel_volume_get(const Emotion_Engine_Instance *inst)
535{
536 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, audio_channel_volume_get, 0.0);
537}
538
539int
540emotion_engine_instance_spu_channel_count(Emotion_Engine_Instance *inst)
541{
542 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, spu_channel_count, 0);
543}
544
545void
546emotion_engine_instance_spu_channel_set(Emotion_Engine_Instance *inst, int channel)
547{
548 EMOTION_ENGINE_INSTANCE_CALL(inst, spu_channel_set, channel);
549}
550
551int
552emotion_engine_instance_spu_channel_get(const Emotion_Engine_Instance *inst)
553{
554 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, spu_channel_get, 0);
555}
556
557const char *
558emotion_engine_instance_spu_channel_name_get(const Emotion_Engine_Instance *inst, int channel)
559{
560 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, spu_channel_name_get, NULL, channel);
561}
562
563void
564emotion_engine_instance_spu_channel_mute_set(Emotion_Engine_Instance *inst, Eina_Bool mute)
565{
566 EMOTION_ENGINE_INSTANCE_CALL(inst, spu_channel_mute_set, mute);
567}
568
569Eina_Bool
570emotion_engine_instance_spu_channel_mute_get(const Emotion_Engine_Instance *inst)
571{
572 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, spu_channel_mute_get, EINA_FALSE);
573}
574
575int
576emotion_engine_instance_chapter_count(Emotion_Engine_Instance *inst)
577{
578 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, chapter_count, 0);
579}
580
581void
582emotion_engine_instance_chapter_set(Emotion_Engine_Instance *inst, int chapter)
583{
584 EMOTION_ENGINE_INSTANCE_CALL(inst, chapter_set, chapter);
585}
586
587int
588emotion_engine_instance_chapter_get(const Emotion_Engine_Instance *inst)
589{
590 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, chapter_get, 0);
591}
592
593const char *
594emotion_engine_instance_chapter_name_get(const Emotion_Engine_Instance *inst, int chapter)
595{
596 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, chapter_name_get, NULL, chapter);
597}
598
599void
600emotion_engine_instance_speed_set(Emotion_Engine_Instance *inst, double speed)
601{
602 EMOTION_ENGINE_INSTANCE_CALL(inst, speed_set, speed);
603}
604
605double
606emotion_engine_instance_speed_get(const Emotion_Engine_Instance *inst)
607{
608 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, speed_get, 0.0);
609}
610
611Eina_Bool
612emotion_engine_instance_eject(Emotion_Engine_Instance *inst)
613{
614 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, eject, EINA_FALSE);
615}
616
617const char *
618emotion_engine_instance_meta_get(const Emotion_Engine_Instance *inst, int meta)
619{
620 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, meta_get, NULL, meta);
621}
622
623void
624emotion_engine_instance_priority_set(Emotion_Engine_Instance *inst, Eina_Bool priority)
625{
626 EMOTION_ENGINE_INSTANCE_CALL(inst, priority_set, priority);
627}
628
629Eina_Bool
630emotion_engine_instance_priority_get(const Emotion_Engine_Instance *inst)
631{
632 EMOTION_ENGINE_INSTANCE_CALL_RET(inst, priority_get, EINA_FALSE);
633}