7
# include <evil_private.h>
10
#include "emotion_private.h"
11
#include "../../static_libs/buildsystem/buildsystem.h"
14
#if defined(EMOTION_STATIC_BUILD_GSTREAMER1)
15
Eina_Bool gstreamer_module_init(void);
16
void gstreamer_module_shutdown(void);
19
typedef struct _Emotion_Engine_Registry_Entry
21
const Emotion_Engine *engine;
23
} Emotion_Engine_Registry_Entry;
25
static Eina_List *_emotion_engine_registry = NULL;
26
static Eina_Array *_emotion_modules = NULL;
27
static Eina_Bool _emotion_modules_loaded = EINA_FALSE;
30
_emotion_engine_registry_entry_free(Emotion_Engine_Registry_Entry *re)
36
_emotion_engine_registry_entry_cmp(const void *pa, const void *pb)
38
const Emotion_Engine_Registry_Entry *a = pa, *b = pb;
39
int r = b->priority - a->priority;
42
r = b->engine->priority - a->engine->priority;
46
r = strcmp(b->engine->name, a->engine->name);
52
_emotion_modules_load(void)
56
if (_emotion_modules_loaded) return;
57
_emotion_modules_loaded = EINA_TRUE;
59
#ifdef NEED_RUN_IN_TREE
60
#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
61
if (getuid() == geteuid())
64
if (getenv("EFL_RUN_IN_TREE"))
67
snprintf(buf, sizeof(buf), "%s/src/modules/emotion",
69
if (stat(buf, &st) == 0)
71
const char *built_modules[] = {
76
for (itr = built_modules; *itr != NULL; itr++)
79
bs_mod_get(buf, sizeof(buf), "emotion", *itr);
80
m = eina_module_new(buf);
84
if (!_emotion_modules)
85
_emotion_modules = eina_array_new(4);
86
eina_array_push(_emotion_modules, m);
94
snprintf(buf, sizeof(buf), "%s/emotion/modules", eina_prefix_lib_get(_emotion_pfx));
95
_emotion_modules = eina_module_arch_list_get(_emotion_modules, buf, MODULE_ARCH);
109
emotion_modules_init(void)
111
#if defined(EMOTION_STATIC_BUILD_GSTREAMER1)
112
gstreamer_module_init();
119
emotion_modules_shutdown(void)
121
Emotion_Engine_Registry_Entry *re;
123
#if defined(EMOTION_STATIC_BUILD_GSTREAMER1)
124
gstreamer_module_shutdown();
127
if (_emotion_modules)
129
eina_module_list_free(_emotion_modules);
130
eina_array_free(_emotion_modules);
131
_emotion_modules = NULL;
134
EINA_LIST_FREE(_emotion_engine_registry, re)
136
WRN("Engine was not unregistered: %p", re->engine);
137
_emotion_engine_registry_entry_free(re);
140
_emotion_modules_loaded = EINA_FALSE;
144
_emotion_module_register(const Emotion_Engine *api)
146
Emotion_Engine_Registry_Entry *re;
148
EINA_SAFETY_ON_NULL_RETURN_VAL(api, EINA_FALSE);
150
if (api->version != EMOTION_ENGINE_API_VERSION)
152
ERR("Module '%p' uses api version=%u while %u was expected",
153
api, api->version, EMOTION_ENGINE_API_VERSION);
157
EINA_SAFETY_ON_NULL_RETURN_VAL(api->name, EINA_FALSE);
159
INF("register name=%s, version=%u, priority=%d, api=%p",
160
api->name, api->version, api->priority, api);
162
re = calloc(1, sizeof(Emotion_Engine_Registry_Entry));
163
EINA_SAFETY_ON_NULL_RETURN_VAL(re, EINA_FALSE);
166
re->priority = api->priority;
168
_emotion_engine_registry = eina_list_sorted_insert
169
(_emotion_engine_registry, _emotion_engine_registry_entry_cmp, re);
175
_emotion_module_unregister(const Emotion_Engine *api)
178
Emotion_Engine_Registry_Entry *re;
180
EINA_SAFETY_ON_NULL_RETURN_VAL(api, EINA_FALSE);
181
if (api->version != EMOTION_ENGINE_API_VERSION)
183
ERR("Module '%p' uses api version=%u while %u was expected",
184
api, api->version, EMOTION_ENGINE_API_VERSION);
188
INF("unregister name=%s, api=%p", api->name, api);
190
EINA_LIST_FOREACH(_emotion_engine_registry, n, re)
192
if (re->engine == api)
194
_emotion_engine_registry_entry_free(re);
195
_emotion_engine_registry = eina_list_remove_list
196
(_emotion_engine_registry, n);
201
ERR("module not registered name=%s, api=%p", api->name, api);
205
struct _Emotion_Engine_Instance
207
const Emotion_Engine *api;
212
#define EMOTION_ENGINE_INSTANCE_CHECK(inst, meth, ...) \
217
DBG("no instance to call "#meth); \
218
return __VA_ARGS__; \
220
if (!inst->api->meth) \
222
DBG("no "#meth" in instance=%p", inst); \
223
return __VA_ARGS__; \
228
#define EMOTION_ENGINE_INSTANCE_CALL(inst, meth, ...) \
231
EMOTION_ENGINE_INSTANCE_CHECK(inst, meth); \
232
inst->api->meth(inst->data, ## __VA_ARGS__); \
236
#define EMOTION_ENGINE_INSTANCE_CALL_RET(inst, meth, retval, ...) \
239
EMOTION_ENGINE_INSTANCE_CHECK(inst, meth, retval); \
240
return inst->api->meth(inst->data, ## __VA_ARGS__); \
245
static const Emotion_Engine *
246
_emotion_engine_registry_find(const char *name)
249
const Emotion_Engine_Registry_Entry *re;
250
EINA_LIST_FOREACH(_emotion_engine_registry, n, re)
252
if (strcmp(re->engine->name, name) == 0)
258
static Emotion_Engine_Instance *
259
_emotion_engine_instance_new(const Emotion_Engine *engine, Evas_Object *obj, void *data)
261
Emotion_Engine_Instance *inst = calloc(1, sizeof(Emotion_Engine_Instance));
262
EINA_SAFETY_ON_NULL_GOTO(inst, error);
274
_find_mod(const char *name)
276
Eina_Array_Iterator iterator;
281
if (!name || !_emotion_modules) return NULL;
282
inlen = strlen(name);
283
EINA_ARRAY_ITER_NEXT(_emotion_modules, i, m, iterator)
285
const char *path = eina_module_file_get(m);
286
const char *p, *p1, *p2, *p3;
287
int found, len, len2;
289
if ((!path) || (!path[0])) continue;
293
for (p = path + strlen(path) - 1;
308
if (found == 1) p3 = p;
309
if (found == 2) p2 = p;
321
len2 = p3 - (p2 + 1);
322
if (len == inlen || len2 == inlen)
324
if (!strncmp(p1, name, len) || !strncmp(p2 + 1, name, len2)) return m;
331
Emotion_Engine_Instance *
332
emotion_engine_instance_new(const char *name, Evas_Object *obj, Emotion_Module_Options *opts)
335
const Emotion_Engine_Registry_Entry *re;
336
const Emotion_Engine *engine;
341
_emotion_modules_load();
343
if ((!name) && getenv("EMOTION_ENGINE"))
345
name = getenv("EMOTION_ENGINE");
346
DBG("using EMOTION_ENGINE=%s", name);
349
if (getenv("WAYLAND_DISPLAY"))
351
disp = eina_strdup(getenv("DISPLAY"));
361
if (!eina_module_load(m))
362
ERR("Cannot load module %s", eina_module_file_get(m));
366
if (!_emotion_engine_registry)
368
m = _find_mod("gstreamer1");
369
if (!eina_module_load(m))
370
ERR("Cannot load module %s", eina_module_file_get(m));
375
engine = _emotion_engine_registry_find(name);
377
ERR("Couldn't find requested engine: %s. Try fallback", name);
380
data = engine->add(engine, obj, opts);
383
INF("Using requested engine %s, data=%p", name, data);
384
if (disp) setenv("DISPLAY", disp, 1);
386
return _emotion_engine_instance_new(engine, obj, data);
389
ERR("Requested engine '%s' could not be used. Try fallback", name);
393
EINA_LIST_FOREACH(_emotion_engine_registry, n, re)
396
DBG("Trying engine %s, priority=%d (%d)",
397
engine->name, re->priority, engine->priority);
399
data = engine->add(engine, obj, opts);
402
INF("Using fallback engine %s, data=%p", engine->name, data);
403
if (disp) setenv("DISPLAY", disp, 1);
405
return _emotion_engine_instance_new(engine, obj, data);
409
ERR("No engine worked");
410
if (disp) setenv("DISPLAY", disp, 1);
416
emotion_engine_instance_del(Emotion_Engine_Instance *inst)
418
EINA_SAFETY_ON_NULL_RETURN(inst);
419
inst->api->del(inst->data);
424
emotion_engine_instance_name_equal(const Emotion_Engine_Instance *inst, const char *name)
427
if (!name) return EINA_FALSE;
428
if (!inst) return EINA_FALSE;
429
return strcmp(name, inst->api->name) == 0;
433
emotion_engine_instance_data_get(const Emotion_Engine_Instance *inst)
435
EINA_SAFETY_ON_NULL_RETURN_VAL(inst, NULL);
440
emotion_engine_instance_file_open(Emotion_Engine_Instance *inst, const char *file)
442
EMOTION_ENGINE_INSTANCE_CHECK(inst, file_open, EINA_FALSE);
443
return inst->api->file_open(inst->data, file);
447
emotion_engine_instance_file_close(Emotion_Engine_Instance *inst)
449
EMOTION_ENGINE_INSTANCE_CALL(inst, file_close);
453
emotion_engine_instance_play(Emotion_Engine_Instance *inst, double pos)
455
EMOTION_ENGINE_INSTANCE_CALL(inst, play, pos);
459
emotion_engine_instance_stop(Emotion_Engine_Instance *inst)
461
EMOTION_ENGINE_INSTANCE_CALL(inst, stop);
465
emotion_engine_instance_size_get(const Emotion_Engine_Instance *inst, int *w, int *h)
467
EMOTION_ENGINE_INSTANCE_CALL(inst, size_get, w, h);
471
emotion_engine_instance_pos_set(Emotion_Engine_Instance *inst, double pos)
473
EMOTION_ENGINE_INSTANCE_CALL(inst, pos_set, pos);
477
emotion_engine_instance_len_get(const Emotion_Engine_Instance *inst)
479
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, len_get, 0.0);
483
emotion_engine_instance_buffer_size_get(const Emotion_Engine_Instance *inst)
485
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, buffer_size_get, 1.0);
489
emotion_engine_instance_fps_num_get(const Emotion_Engine_Instance *inst)
491
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, fps_num_get, 1);
495
emotion_engine_instance_fps_den_get(const Emotion_Engine_Instance *inst)
497
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, fps_den_get, 1);
501
emotion_engine_instance_fps_get(const Emotion_Engine_Instance *inst)
503
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, fps_get, 1.0);
507
emotion_engine_instance_pos_get(const Emotion_Engine_Instance *inst)
509
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, pos_get, 0.0);
513
emotion_engine_instance_vis_set(Emotion_Engine_Instance *inst, Emotion_Vis vis)
515
EMOTION_ENGINE_INSTANCE_CALL(inst, vis_set, vis);
519
emotion_engine_instance_vis_get(const Emotion_Engine_Instance *inst)
521
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, vis_get, EMOTION_VIS_NONE);
525
emotion_engine_instance_vis_supported(Emotion_Engine_Instance *inst, Emotion_Vis vis)
527
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, vis_supported, EINA_FALSE, vis);
531
emotion_engine_instance_ratio_get(const Emotion_Engine_Instance *inst)
533
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, ratio_get, 0.0);
537
emotion_engine_instance_video_handled(Emotion_Engine_Instance *inst)
539
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, video_handled, EINA_FALSE);
543
emotion_engine_instance_audio_handled(Emotion_Engine_Instance *inst)
545
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, audio_handled, EINA_FALSE);
549
emotion_engine_instance_seekable(Emotion_Engine_Instance *inst)
551
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, seekable, EINA_FALSE);
555
emotion_engine_instance_frame_done(Emotion_Engine_Instance *inst)
557
EMOTION_ENGINE_INSTANCE_CALL(inst, frame_done);
561
emotion_engine_instance_format_get(const Emotion_Engine_Instance *inst)
563
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, format_get, EMOTION_FORMAT_NONE);
567
emotion_engine_instance_video_data_size_get(const Emotion_Engine_Instance *inst, int *w, int *h)
569
EMOTION_ENGINE_INSTANCE_CALL(inst, video_data_size_get, w, h);
573
emotion_engine_instance_yuv_rows_get(const Emotion_Engine_Instance *inst, int w, int h, unsigned char **yrows, unsigned char **urows, unsigned char **vrows)
575
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, yuv_rows_get, EINA_FALSE, w, h, yrows, urows, vrows);
579
emotion_engine_instance_bgra_data_get(const Emotion_Engine_Instance *inst, unsigned char **bgra_data)
581
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, bgra_data_get, EINA_FALSE, bgra_data);
585
emotion_engine_instance_event_feed(Emotion_Engine_Instance *inst, int event)
587
EMOTION_ENGINE_INSTANCE_CALL(inst, event_feed, event);
591
emotion_engine_instance_event_mouse_button_feed(Emotion_Engine_Instance *inst, int button, int x, int y)
593
EMOTION_ENGINE_INSTANCE_CALL(inst, event_mouse_button_feed, button, x, y);
597
emotion_engine_instance_event_mouse_move_feed(Emotion_Engine_Instance *inst, int x, int y)
599
EMOTION_ENGINE_INSTANCE_CALL(inst, event_mouse_move_feed, x, y);
603
emotion_engine_instance_video_channel_count(Emotion_Engine_Instance *inst)
605
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, video_channel_count, 0);
609
emotion_engine_instance_video_channel_set(Emotion_Engine_Instance *inst, int channel)
611
EMOTION_ENGINE_INSTANCE_CALL(inst, video_channel_set, channel);
615
emotion_engine_instance_video_channel_get(const Emotion_Engine_Instance *inst)
617
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, video_channel_get, 0);
621
emotion_engine_instance_video_subtitle_file_set(Emotion_Engine_Instance *inst, const char *filepath)
623
EMOTION_ENGINE_INSTANCE_CALL(inst, video_subtitle_file_set, filepath);
627
emotion_engine_instance_video_subtitle_file_get(const Emotion_Engine_Instance *inst)
629
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, video_subtitle_file_get, NULL);
633
emotion_engine_instance_video_channel_name_get(const Emotion_Engine_Instance *inst, int channel)
635
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, video_channel_name_get, NULL, channel);
639
emotion_engine_instance_video_channel_mute_set(Emotion_Engine_Instance *inst, Eina_Bool mute)
641
EMOTION_ENGINE_INSTANCE_CALL(inst, video_channel_mute_set, mute);
645
emotion_engine_instance_video_channel_mute_get(const Emotion_Engine_Instance *inst)
647
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, video_channel_mute_get, EINA_FALSE);
651
emotion_engine_instance_audio_channel_count(Emotion_Engine_Instance *inst)
653
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, audio_channel_count, 0);
657
emotion_engine_instance_audio_channel_set(Emotion_Engine_Instance *inst, int channel)
659
EMOTION_ENGINE_INSTANCE_CALL(inst, audio_channel_set, channel);
663
emotion_engine_instance_audio_channel_get(const Emotion_Engine_Instance *inst)
665
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, audio_channel_get, 0);
669
emotion_engine_instance_audio_channel_name_get(const Emotion_Engine_Instance *inst, int channel)
671
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, audio_channel_name_get, NULL, channel);
675
emotion_engine_instance_audio_channel_mute_set(Emotion_Engine_Instance *inst, Eina_Bool mute)
677
EMOTION_ENGINE_INSTANCE_CALL(inst, audio_channel_mute_set, mute);
681
emotion_engine_instance_audio_channel_mute_get(const Emotion_Engine_Instance *inst)
683
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, audio_channel_mute_get, EINA_FALSE);
687
emotion_engine_instance_audio_channel_volume_set(Emotion_Engine_Instance *inst, double vol)
689
EMOTION_ENGINE_INSTANCE_CALL(inst, audio_channel_volume_set, vol);
693
emotion_engine_instance_audio_channel_volume_get(const Emotion_Engine_Instance *inst)
695
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, audio_channel_volume_get, 0.0);
699
emotion_engine_instance_spu_channel_count(Emotion_Engine_Instance *inst)
701
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, spu_channel_count, 0);
705
emotion_engine_instance_spu_channel_set(Emotion_Engine_Instance *inst, int channel)
707
EMOTION_ENGINE_INSTANCE_CALL(inst, spu_channel_set, channel);
711
emotion_engine_instance_spu_channel_get(const Emotion_Engine_Instance *inst)
713
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, spu_channel_get, 0);
717
emotion_engine_instance_spu_channel_name_get(const Emotion_Engine_Instance *inst, int channel)
719
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, spu_channel_name_get, NULL, channel);
723
emotion_engine_instance_spu_channel_mute_set(Emotion_Engine_Instance *inst, Eina_Bool mute)
725
EMOTION_ENGINE_INSTANCE_CALL(inst, spu_channel_mute_set, mute);
729
emotion_engine_instance_spu_channel_mute_get(const Emotion_Engine_Instance *inst)
731
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, spu_channel_mute_get, EINA_FALSE);
735
emotion_engine_instance_chapter_count(Emotion_Engine_Instance *inst)
737
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, chapter_count, 0);
741
emotion_engine_instance_chapter_set(Emotion_Engine_Instance *inst, int chapter)
743
EMOTION_ENGINE_INSTANCE_CALL(inst, chapter_set, chapter);
747
emotion_engine_instance_chapter_get(const Emotion_Engine_Instance *inst)
749
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, chapter_get, 0);
753
emotion_engine_instance_chapter_name_get(const Emotion_Engine_Instance *inst, int chapter)
755
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, chapter_name_get, NULL, chapter);
759
emotion_engine_instance_speed_set(Emotion_Engine_Instance *inst, double speed)
761
EMOTION_ENGINE_INSTANCE_CALL(inst, speed_set, speed);
765
emotion_engine_instance_speed_get(const Emotion_Engine_Instance *inst)
767
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, speed_get, 0.0);
771
emotion_engine_instance_eject(Emotion_Engine_Instance *inst)
773
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, eject, EINA_FALSE);
777
emotion_engine_instance_meta_get(const Emotion_Engine_Instance *inst, int meta)
779
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, meta_get, NULL, meta);
783
emotion_engine_instance_meta_artwork_get(const Emotion_Engine_Instance *inst, Evas_Object *img, const char *path, Emotion_Artwork_Info type)
785
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, meta_artwork_get, NULL, img, path, type);
789
emotion_engine_instance_priority_set(Emotion_Engine_Instance *inst, Eina_Bool priority)
791
EMOTION_ENGINE_INSTANCE_CALL(inst, priority_set, priority);
795
emotion_engine_instance_priority_get(const Emotion_Engine_Instance *inst)
797
EMOTION_ENGINE_INSTANCE_CALL_RET(inst, priority_get, EINA_FALSE);