From c0db348787917489b05e741a370443515bd636cb Mon Sep 17 00:00:00 2001 From: cedric Date: Thu, 23 Jun 2011 14:58:11 +0000 Subject: [PATCH] emotion: add a way to test if a file could be played by emotion. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/emotion@60637 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/lib/Emotion.h | 8 +- src/lib/emotion_private.h | 3 + src/lib/emotion_smart.c | 135 ++++++++++++++++++++++++++++-- src/modules/gstreamer/emotion_gstreamer.c | 1 + src/modules/vlc/emotion_vlc.c | 1 + src/modules/xine/emotion_xine.c | 2 +- 6 files changed, 143 insertions(+), 7 deletions(-) diff --git a/src/lib/Emotion.h b/src/lib/Emotion.h index 009e391..9a2b4f8 100644 --- a/src/lib/Emotion.h +++ b/src/lib/Emotion.h @@ -174,8 +174,14 @@ EAPI void emotion_object_vis_set (Evas_Object *obj, Emotio EAPI Emotion_Vis emotion_object_vis_get (const Evas_Object *obj); EAPI Eina_Bool emotion_object_vis_supported (const Evas_Object *obj, Emotion_Vis visualization); +EAPI Eina_Bool emotion_object_extension_can_play_get(const Evas_Object *obj, const char *file); +EAPI Eina_Bool emotion_object_extension_can_play_fast_get(const Evas_Object *obj, const char *file); + +EAPI Eina_Bool emotion_object_extension_may_play_fast_get(const char *file); +EAPI Eina_Bool emotion_object_extension_may_play_get(const char *file); + #ifdef __cplusplus } #endif - + #endif diff --git a/src/lib/emotion_private.h b/src/lib/emotion_private.h index 3fae968..cedf978 100644 --- a/src/lib/emotion_private.h +++ b/src/lib/emotion_private.h @@ -109,6 +109,7 @@ struct _Emotion_Video_Module double (*speed_get) (void *ef); int (*eject) (void *ef); const char * (*meta_get) (void *ef, int meta); + Eina_Bool (*can_play_get) (const void *ef, const char *file); Eina_Emotion_Plugins *plugin; }; @@ -131,6 +132,8 @@ EAPI void _emotion_spu_button_num_set(Evas_Object *obj, int num); EAPI void _emotion_spu_button_set(Evas_Object *obj, int button); EAPI void _emotion_seek_done(Evas_Object *obj); +EAPI Eina_Bool _emotion_object_extension_can_play_generic_get(const void *data __UNUSED__, const char *file); + EAPI Eina_Bool _emotion_module_register(const char *name, Emotion_Module_Open open, Emotion_Module_Close close); EAPI Eina_Bool _emotion_module_unregister(const char *name); diff --git a/src/lib/emotion_smart.c b/src/lib/emotion_smart.c index 5fdbc33..bdee730 100644 --- a/src/lib/emotion_smart.c +++ b/src/lib/emotion_smart.c @@ -184,7 +184,7 @@ _emotion_module_open(const char *name, Evas_Object *obj, Emotion_Video_Module ** { Eina_Emotion_Plugins *plugin; Smart_Data *sd; - unsigned int index = 0; + unsigned int i = 0; E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0); if (!_backends) @@ -198,13 +198,13 @@ _emotion_module_open(const char *name, Evas_Object *obj, Emotion_Video_Module ** /* FIXME: Always look for a working backend. */ retry: - if (!name || index > 0) - name = _backend_priority[index++]; + if (!name || i > 0) + name = _backend_priority[i++]; plugin = eina_hash_find(_backends, name); if (!plugin) { - if (index != 0 && index < (sizeof (_backend_priority) / sizeof (char*))) + if (i != 0 && i < (sizeof (_backend_priority) / sizeof (char*))) goto retry; ERR("No backend loaded"); @@ -220,7 +220,7 @@ _emotion_module_open(const char *name, Evas_Object *obj, Emotion_Video_Module ** } } - if (index != 0 && index < (sizeof (_backend_priority) / sizeof (char*))) + if (i != 0 && i < (sizeof (_backend_priority) / sizeof (char*))) goto retry; ERR("Unable to load module: %s", name); @@ -991,12 +991,137 @@ emotion_object_vis_supported(const Evas_Object *obj, Emotion_Vis visualization) return sd->module->vis_supported(sd->video, visualization); } +EAPI Eina_Bool +emotion_object_extension_can_play_fast_get(const Evas_Object *obj, const char *file) +{ + const Smart_Data *sd; + + E_SMART_OBJ_GET_RETURN(sd, obj, E_OBJ_NAME, 0); + if (!sd->module) return EINA_FALSE; + if (!sd->video) return EINA_FALSE; + if (!sd->module->can_play_get) return EINA_FALSE; + return sd->module->can_play_get(sd->video, file); +} + +EAPI Eina_Bool +emotion_object_extension_can_play_get(const Evas_Object *obj, const char *file) +{ + const char *tmp; + Eina_Bool result; + tmp = eina_stringshare_add(file); + result = emotion_object_extension_can_play_fast_get(obj, tmp); + eina_stringshare_del(tmp); + + return result; +} + +EAPI Eina_Bool +emotion_object_extension_may_play_fast_get(const char *file) +{ + if (!file) return EINA_FALSE; + return _emotion_object_extension_can_play_generic_get(NULL, file); +} + +EAPI Eina_Bool +emotion_object_extension_may_play_get(const char *file) +{ + const char *tmp; + Eina_Bool result; + + if (!file) return EINA_FALSE; + tmp = eina_stringshare_add(file); + result = emotion_object_extension_may_play_fast_get(tmp); + eina_stringshare_del(tmp); + + return result; +} /*****************************/ /* Utility calls for modules */ /*****************************/ +struct ext_match_s +{ + unsigned int length; + const char *extension; +}; + +#define MATCHING(Ext) \ + { sizeof (Ext), Ext } + +static const struct ext_match_s matchs[] = +{ /* map extensions to know if it's a emotion playable content for good first-guess tries */ + MATCHING(".264"), + MATCHING(".3g2"), + MATCHING(".3gp"), + MATCHING(".3gp2"), + MATCHING(".3gpp"), + MATCHING(".3gpp2"), + MATCHING(".3p2"), + MATCHING(".asf"), + MATCHING(".avi"), + MATCHING(".bdm"), + MATCHING(".bdmv"), + MATCHING(".clpi"), + MATCHING(".clp"), + MATCHING(".fla"), + MATCHING(".flv"), + MATCHING(".m1v"), + MATCHING(".m2v"), + MATCHING(".m2t"), + MATCHING(".m4v"), + MATCHING(".mkv"), + MATCHING(".mov"), + MATCHING(".mp2"), + MATCHING(".mp2ts"), + MATCHING(".mp4"), + MATCHING(".mpe"), + MATCHING(".mpeg"), + MATCHING(".mpg"), + MATCHING(".mpl"), + MATCHING(".mpls"), + MATCHING(".mts"), + MATCHING(".mxf"), + MATCHING(".nut"), + MATCHING(".nuv"), + MATCHING(".ogg"), + MATCHING(".ogm"), + MATCHING(".ogv"), + MATCHING(".rm"), + MATCHING(".rmj"), + MATCHING(".rmm"), + MATCHING(".rms"), + MATCHING(".rmx"), + MATCHING(".rmvb"), + MATCHING(".swf"), + MATCHING(".ts"), + MATCHING(".weba"), + MATCHING(".webm"), + MATCHING(".wmv") +}; + +EAPI Eina_Bool +_emotion_object_extension_can_play_generic_get(const void *data __UNUSED__, const char *file) +{ + unsigned int length; + unsigned int i; + + length = eina_stringshare_strlen(file) + 1; + if (length < 5) return EINA_FALSE; + + for (i = 0; i < sizeof (matchs) / sizeof (struct ext_match_s); ++i) + { + if (matchs[i].length > length) continue; + + if (!strcasecmp(matchs[i].extension, + file + length - matchs[i].length)) + return EINA_TRUE; + } + + return EINA_FALSE; +} + EAPI void * _emotion_video_get(const Evas_Object *obj) { diff --git a/src/modules/gstreamer/emotion_gstreamer.c b/src/modules/gstreamer/emotion_gstreamer.c index 0b59718..0295d4f 100644 --- a/src/modules/gstreamer/emotion_gstreamer.c +++ b/src/modules/gstreamer/emotion_gstreamer.c @@ -227,6 +227,7 @@ static Emotion_Video_Module em_module = em_speed_get, /* speed_get */ em_eject, /* eject */ em_meta_get, /* meta_get */ + _emotion_object_extension_can_play_generic_get, /* play_get */ NULL /* handle */ }; diff --git a/src/modules/vlc/emotion_vlc.c b/src/modules/vlc/emotion_vlc.c index eec07ea..6179d18 100644 --- a/src/modules/vlc/emotion_vlc.c +++ b/src/modules/vlc/emotion_vlc.c @@ -1193,6 +1193,7 @@ static Emotion_Video_Module em_module = em_speed_get, /* speed_get */ em_eject, /* eject */ em_meta_get, /* meta_get */ + _emotion_object_extension_can_play_generic_get, /* can_play_get */ NULL /* handle */ }; diff --git a/src/modules/xine/emotion_xine.c b/src/modules/xine/emotion_xine.c index d07f1b6..3738f6a 100644 --- a/src/modules/xine/emotion_xine.c +++ b/src/modules/xine/emotion_xine.c @@ -1555,7 +1555,7 @@ static Emotion_Video_Module em_module = em_speed_get, /* speed_get */ em_eject, /* eject */ em_meta_get, /* meta_get */ - + _emotion_object_extension_can_play_generic_get, /* can_play_get */ NULL /* handle */ }; -- 2.7.4