[vlc-devel] [PATCH] Fixed libvlc_vlm_show_media to return a string representation of a vlm media again

Alexander Bethke abethke at oamk.fi
Wed Mar 11 13:54:30 CET 2009


The libvlc_vlm_show_media function was deliberately turned off/crippled. This fixes the function and turns it on again, as it is part of the current public vlm API and it is not understandable for
users of libvlc and it's bindings that it just always fails. The function is important to get vital information about a vlm media if you don't use vlm via the telnet interface, but the libvlc public
API.
I reckon that there is a beginning of a different and better approach to request information about a vlm media, but it is very limited at the moment and not bound in at least the Java bindings
either. I would really like to participate in the improvement of the libvlc_vlm public API (like using some struct instead of string representation, and/or adding new methods to request specific
aspects of a media) and also update the Java bindings to reflect those, but I need some help from people who have been working on vlm to design and plan those api changes with me.
---
 src/control/vlm.c |  139 ++++++++++++++++++++++++++---------------------------
 1 files changed, 68 insertions(+), 71 deletions(-)

diff --git a/src/control/vlm.c b/src/control/vlm.c
index cafd8dc..f5d50aa 100644
--- a/src/control/vlm.c
+++ b/src/control/vlm.c
@@ -28,15 +28,68 @@
 #include <vlc_input.h>
 #include <vlc_vlm.h>
 
-#if 0
+#define VLM_RET(p,ret) do {                                     \
+    if( libvlc_vlm_init( p_instance, p_exception ) ) return ret;\
+    (p) = p_instance->p_vlm;                                    \
+  } while(0)
+#define VLM(p) VLM_RET(p,)
+
+static int libvlc_vlm_init( libvlc_instance_t *p_instance,
+                            libvlc_exception_t *p_exception )
+{
+    if( !p_instance->p_vlm )
+        p_instance->p_vlm = vlm_New( p_instance->p_libvlc_int );
+
+    if( !p_instance->p_vlm )
+    {
+        libvlc_exception_raise( p_exception,
+                                "Unable to create VLM." );
+        return VLC_EGENERIC;
+    }
+    return VLC_SUCCESS;
+}
+
+
+static vlm_media_instance_t *libvlc_vlm_get_media_instance( libvlc_instance_t *p_instance,
+                                                            const char *psz_name,
+                                                            int i_minstance_idx,
+                                                            libvlc_exception_t *p_exception )
+{
+    vlm_t *p_vlm;
+    vlm_media_instance_t **pp_minstance;
+    vlm_media_instance_t *p_minstance;
+    int i_minstance;
+    int64_t id;
+
+    VLM_RET(p_vlm, NULL);
+
+    if( vlm_Control( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) ||
+        vlm_Control( p_vlm, VLM_GET_MEDIA_INSTANCES, id, &pp_minstance, &i_minstance ) )
+    {
+        libvlc_exception_raise( p_exception, "Unable to get %s instances", psz_name );
+        return NULL;
+    }
+    p_minstance = NULL;
+    if( i_minstance_idx >= 0 && i_minstance_idx < i_minstance )
+    {
+        p_minstance = pp_minstance[i_minstance_idx];
+        TAB_REMOVE( i_minstance, pp_minstance, p_minstance );
+    }
+    while( i_minstance > 0 )
+        vlm_media_instance_Delete( pp_minstance[--i_minstance] );
+    TAB_CLEAN( i_minstance, pp_minstance );
+    return p_minstance;
+}
+
 /* local function to be used in libvlc_vlm_show_media only */
 static char* recurse_answer( char* psz_prefix, vlm_message_t *p_answer ) {
     char* psz_childprefix;
-    char* psz_response="";
+    char* psz_response;
     char* response_tmp;
     int i;
     vlm_message_t *aw_child, **paw_child;
 
+    asprintf( &psz_response, "");
     asprintf( &psz_childprefix, "%s%s.", psz_prefix, p_answer->psz_name );
 
     if ( p_answer->i_child )
@@ -65,96 +118,40 @@ static char* recurse_answer( char* psz_prefix, vlm_message_t *p_answer ) {
     return psz_response;
 }
 
-char* libvlc_vlm_show_media( libvlc_instance_t *p_instance, char *psz_name,
+/*  Returning a string representation of the media I find should be changed to
+    either refactoring this to return some sort of struct or or to add more
+    libvlc_vlm_get_media_instance_x methods to make available all information
+    that you get out of the string representation.
+    -Alexander Bethke */
+char* libvlc_vlm_show_media( libvlc_instance_t *p_instance,
+                             const char *psz_name,
                              libvlc_exception_t *p_exception )
 {
     char *psz_message;
     vlm_message_t *answer;
     char *psz_response;
+    vlm_t *p_vlm;
+
+    VLM_RET(p_vlm, NULL);
 
-    CHECK_VLM;
     asprintf( &psz_message, "show %s", psz_name );
     asprintf( &psz_response, "", psz_name );
-    vlm_ExecuteCommand( p_instance->p_vlm, psz_message, &answer );
+    vlm_ExecuteCommand( p_vlm, psz_message, &answer );
     if( answer->psz_value )
     {
         libvlc_exception_raise( p_exception, "Unable to call show %s: %s",
                                 psz_name, answer->psz_value );
     }
-    else
-    {
+    else {
         if ( answer->child )
         {
             psz_response = recurse_answer( "", answer );
         }
     }
+
     free( psz_message );
     return(psz_response );
 }
-#else
-
-char* libvlc_vlm_show_media( libvlc_instance_t *p_instance,
-                             const char *psz_name,
-                             libvlc_exception_t *p_exception )
-{
-    (void)p_instance;
-    /* FIXME is it needed ? */
-    libvlc_exception_raise( p_exception, "Unable to call show %s", psz_name );
-    return NULL;
-}
-
-#endif /* 0 */
-
-static int libvlc_vlm_init( libvlc_instance_t *p_instance,
-                            libvlc_exception_t *p_exception )
-{
-    if( !p_instance->p_vlm )
-        p_instance->p_vlm = vlm_New( p_instance->p_libvlc_int );
-
-    if( !p_instance->p_vlm )
-    {
-        libvlc_exception_raise( p_exception,
-                                "Unable to create VLM." );
-        return VLC_EGENERIC;
-    }
-    return VLC_SUCCESS;
-}
-#define VLM_RET(p,ret) do {                                     \
-    if( libvlc_vlm_init( p_instance, p_exception ) ) return ret;\
-    (p) = p_instance->p_vlm;                                    \
-  } while(0)
-#define VLM(p) VLM_RET(p,)
-
-static vlm_media_instance_t *libvlc_vlm_get_media_instance( libvlc_instance_t *p_instance,
-                                                            const char *psz_name,
-                                                            int i_minstance_idx,
-                                                            libvlc_exception_t *p_exception )
-{
-    vlm_t *p_vlm;
-    vlm_media_instance_t **pp_minstance;
-    vlm_media_instance_t *p_minstance;
-    int i_minstance;
-    int64_t id;
-
-    VLM_RET(p_vlm, NULL);
-
-    if( vlm_Control( p_vlm, VLM_GET_MEDIA_ID, psz_name, &id ) ||
-        vlm_Control( p_vlm, VLM_GET_MEDIA_INSTANCES, id, &pp_minstance, &i_minstance ) )
-    {
-        libvlc_exception_raise( p_exception, "Unable to get %s instances", psz_name );
-        return NULL;
-    }
-    p_minstance = NULL;
-    if( i_minstance_idx >= 0 && i_minstance_idx < i_minstance )
-    {
-        p_minstance = pp_minstance[i_minstance_idx];
-        TAB_REMOVE( i_minstance, pp_minstance, p_minstance );
-    }
-    while( i_minstance > 0 )
-        vlm_media_instance_Delete( pp_minstance[--i_minstance] );
-    TAB_CLEAN( i_minstance, pp_minstance );
-    return p_minstance;
-}
 
 
 void libvlc_vlm_release( libvlc_instance_t *p_instance, libvlc_exception_t *p_exception)
-- 
1.5.6.3




More information about the vlc-devel mailing list