emotion: add a way to test if a file could be played by emotion.
authorcedric <cedric>
Thu, 23 Jun 2011 14:58:11 +0000 (14:58 +0000)
committercedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 23 Jun 2011 14:58:11 +0000 (14:58 +0000)
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/emotion@60637 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/lib/Emotion.h
src/lib/emotion_private.h
src/lib/emotion_smart.c
src/modules/gstreamer/emotion_gstreamer.c
src/modules/vlc/emotion_vlc.c
src/modules/xine/emotion_xine.c

index 009e391..9a2b4f8 100644 (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
index 3fae968..cedf978 100644 (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);
 
index 5fdbc33..bdee730 100644 (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)
 {
index 0b59718..0295d4f 100644 (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 */
 };
 
index eec07ea..6179d18 100644 (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 */
 };
index d07f1b6..3738f6a 100644 (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 */
 };