emotion: add a way to test if a file could be played by emotion.

SVN revision: 60637
This commit is contained in:
Cedric BAIL 2011-06-23 14:58:11 +00:00
parent 28c4f6f8f5
commit 3c8eb1b62b
6 changed files with 143 additions and 7 deletions

View File

@ -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

View File

@ -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);

View File

@ -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)
{

View File

@ -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 */
};

View File

@ -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 */
};

View File

@ -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 */
};