[vlc-devel] [PATCH 3/4] Various fixes to get album art working on oldhttp interface

John Freed okvlc at johnfreed.com
Thu Mar 29 20:32:24 CEST 2012


---
 modules/control/http/http.c    |   68 +++++++++++++++++++---------------------
 modules/control/http/http.h    |   10 +++--
 share/http/dialogs/main        |    2 +-
 share/http/js/functions.js     |    4 +-
 share/lua/http/js/functions.js |    4 +-
 5 files changed, 43 insertions(+), 45 deletions(-)

diff --git a/modules/control/http/http.c b/modules/control/http/http.c
index c8469e8..8709770 100644
--- a/modules/control/http/http.c
+++ b/modules/control/http/http.c
@@ -110,6 +110,7 @@ static int Open( vlc_object_t *p_this )
                   *psz_crl = NULL;
     int           i_port       = 0;
     char          *psz_src = NULL;
+    httpd_handler_sys_t *p_art_handler_sys = NULL;
 
     psz_address = var_CreateGetNonEmptyString( p_intf, "http-host" );
     if( psz_address != NULL )
@@ -261,18 +262,20 @@ static int Open( vlc_object_t *p_this )
 
     if( var_InheritBool( p_intf, "http-album-art" ) )
     {
-        /* FIXME: we're leaking h */
-        httpd_handler_sys_t *h = malloc( sizeof( httpd_handler_sys_t ) );
-        if( !h )
+        httpd_handler_sys_t *p_art_handler_sys = malloc( sizeof( httpd_handler_sys_t ) );
+        if( !p_art_handler_sys )
+        {
+            msg_Err( p_intf, "out of memory: could not allocate /art URL" );
             goto failed;
-        h->file.p_intf = p_intf;
-        h->file.file = NULL;
-        h->file.name = NULL;
+        }
+
+        p_art_handler_sys->file.p_intf = p_intf;
+        p_art_handler_sys->file.file = NULL;
+        p_art_handler_sys->file.name = NULL;
         /* TODO: use ACL and login/password stuff here too */
-        h->p_handler = httpd_HandlerNew( p_sys->p_httpd_host,
+        p_sys->p_art_handler =  httpd_HandlerNew( p_sys->p_httpd_host,
                                          "/art", NULL, NULL, NULL,
-                                         ArtCallback, h );
-        p_sys->p_art_handler = h->p_handler;
+                                         ArtCallback, p_art_handler_sys );
     }
 
     free( psz_src );
@@ -284,6 +287,7 @@ failed:
     httpd_HostDelete( p_sys->p_httpd_host );
     free( p_sys->psz_address );
     free( p_sys );
+    free( p_art_handler_sys );
     return VLC_EGENERIC;
 }
 
@@ -295,6 +299,7 @@ static void Close ( vlc_object_t *p_this )
     intf_thread_t *p_intf = (intf_thread_t *)p_this;
     intf_sys_t    *p_sys = p_intf->p_sys;
     int i;
+    httpd_handler_sys_t *p_art_handler_sys = NULL;
 
 #ifdef ENABLE_VLM
     if( p_sys->p_vlm )
@@ -330,10 +335,11 @@ static void Close ( vlc_object_t *p_this )
     if( p_sys->i_handlers )
         free( p_sys->pp_handlers );
     if( p_sys->p_art_handler )
-        httpd_HandlerDelete( p_sys->p_art_handler );
+        p_art_handler_sys = httpd_HandlerDelete( p_sys->p_art_handler );
     httpd_HostDelete( p_sys->p_httpd_host );
     free( p_sys->psz_address );
     free( p_sys );
+    free( p_art_handler_sys );
 }
 
 /****************************************************************************
@@ -429,7 +435,7 @@ static void ParseExecute( httpd_file_sys_t *p_args, char *p_buffer,
     /* Stats */
     if( p_sys->p_input )
     {
-        /* FIXME: Workarround a stupid assert in input_GetItem */
+        /* Workaround a stupid assert in input_GetItem */
         input_item_t *p_item = p_sys->p_input && p_sys->p_input->p
                                ? input_GetItem( p_sys->p_input )
                                : NULL;
@@ -754,34 +760,16 @@ int  ArtCallback( httpd_handler_sys_t *p_args,
     VLC_UNUSED(p_handler); VLC_UNUSED(_p_url); VLC_UNUSED(i_type); 
     VLC_UNUSED(p_in); VLC_UNUSED(i_in); VLC_UNUSED(psz_remote_addr); 
     VLC_UNUSED(psz_remote_host); 
+    VLC_UNUSED(p_request);
 
     char *psz_art = NULL;
     intf_thread_t *p_intf = p_args->file.p_intf;
     intf_sys_t *p_sys = p_intf->p_sys;
-    char psz_id[16];
     input_item_t *p_item = NULL;
-    int i_id;
-
-    psz_id[0] = '\0';
-    if( p_request )
-        ExtractURIValue( (char *)p_request, "id", psz_id, 15 );
-    i_id = atoi( psz_id );
-    if( i_id )
-    {
-        playlist_Lock( p_sys->p_playlist );
-        playlist_item_t *p_pl_item = playlist_ItemGetById( p_sys->p_playlist,
-                                                           i_id );
-        if( p_pl_item )
-            p_item = p_pl_item->p_input;
-        playlist_Unlock( p_sys->p_playlist );
-    }
-    else
-    {
-        /* FIXME: Workarround a stupid assert in input_GetItem */
+    p_sys->p_input = playlist_CurrentInput( p_sys->p_playlist );
+        /* Workaround a stupid assert in input_GetItem */
         if( p_sys->p_input && p_sys->p_input->p )
             p_item = input_GetItem( p_sys->p_input );
-    }
-
     if( p_item )
     {
         psz_art = input_item_GetArtURL( p_item );
@@ -796,15 +784,23 @@ int  ArtCallback( httpd_handler_sys_t *p_args,
 
     if( psz_art == NULL )
     {
-        msg_Dbg( p_intf, "No album art found" );
-        Callback404( &p_args->file, (char**)pp_data, pi_data );
-        return VLC_SUCCESS;
+        msg_Dbg( p_intf, "didn't find any art, so use default" );
+        char *psz_src = var_InheritString( p_intf, "http-src" );
+        if( psz_src == NULL )
+        {
+            char *data_path = config_GetDataDir( p_intf );
+            if( asprintf( &psz_src, "%s" DIR_SEP "http", data_path ) == -1 )
+                psz_src = NULL;
+            free( data_path );
+        }
+        if( asprintf( &psz_art, "%s" DIR_SEP "images" DIR_SEP "default_album_art.png", psz_src ) == -1 )
+                psz_art = NULL;
+        free( psz_src );
     }
 
     FILE *f = vlc_fopen( psz_art, "r" );
     if( f == NULL )
     {
-        msg_Dbg( p_intf, "Couldn't open album art file %s", psz_art );
         Callback404( &p_args->file, (char**)pp_data, pi_data );
         free( psz_art );
         return VLC_SUCCESS;
diff --git a/modules/control/http/http.h b/modules/control/http/http.h
index ac32dc9..1262db0 100644
--- a/modules/control/http/http.h
+++ b/modules/control/http/http.h
@@ -355,10 +355,12 @@ struct intf_sys_t
 };
 
 /** This function is the main HTTPD Callback used by the HTTP Interface */
-int HttpCallback( httpd_file_sys_t *p_args,
-                      httpd_file_t *,
-                      uint8_t *p_request,
-                      uint8_t **pp_data, int *pi_data );
+
+int  HttpCallback( httpd_file_sys_t *p_args,
+                       httpd_file_t *p_file,
+                       uint8_t *_p_request,
+                       uint8_t **_pp_data, int *pi_data );
+
 /** This function is the HTTPD Callback used for CGIs */
 int  HandlerCallback( httpd_handler_sys_t *p_args,
                           httpd_handler_t *p_handler, char *_p_url,
diff --git a/share/http/dialogs/main b/share/http/dialogs/main
index ecf038a..0eadcc9 100644
--- a/share/http/dialogs/main
+++ b/share/http/dialogs/main
@@ -106,7 +106,7 @@ sout and playlist .
     <img src="images/slider_left.png" alt="slider left" /><span id="progressbar" style="background-image: url( 'images/slider_bar.png' ); width: 408px; height:16px; position:absolute;" onclick="slider_seek( event, this );" onmousemove="slider_move( event, this );"><img src="images/slider_point.png" alt="slider point" style="position:relative; left:0px;" id="main_slider_point" onmousedown="slider_down( event, this );" onmouseup="slider_up( event, this.parentNode );" onmouseout="slider_up( event, this.parentNode );"/></span><img src="images/slider_right.png" alt="slider right" style="position:relative;left:408px;" />
     <br/>
     <span id="nowplaying">(?)</span>
-    <img id="albumart" alt="" src="/art" style="float: right" onclick="refresh_albumart(true);"/>
+    <img id="albumart" src="/art" alt="Album art" width="200" style="float: right" onload="refresh_albumart(true);" />
   </div>
 </div>
 
diff --git a/share/http/js/functions.js b/share/http/js/functions.js
index fcd6c7a..19d0278 100644
--- a/share/http/js/functions.js
+++ b/share/http/js/functions.js
@@ -1043,11 +1043,11 @@ function browse_path( p )
 }
 function refresh_albumart( force )
 {
-    if( albumart_id != pl_cur_id || force )
+    if( ( albumart_id != pl_cur_id ) || force )
     {
         var now = new Date();
         var albumart = document.getElementById( 'albumart' );
-        albumart.src = '/art?timestamp=' + now.getTime();
+        albumart.src = '/art?timestamp=' + now.getTime() + '&id=' + pl_cur_id;
         albumart_id = pl_cur_id;
     }
 }
diff --git a/share/lua/http/js/functions.js b/share/lua/http/js/functions.js
index d965e06..8204058 100644
--- a/share/lua/http/js/functions.js
+++ b/share/lua/http/js/functions.js
@@ -1134,11 +1134,11 @@ function browse_path( p )
 }
 function refresh_albumart( force )
 {
-    if( albumart_id != pl_cur_id || force )
+    if( ( albumart_id != pl_cur_id ) || force )
     {
         var now = new Date();
         var albumart = document.getElementById( 'albumart' );
-        albumart.src = '/art?timestamp=' + now.getTime();
+        albumart.src = '/art?timestamp=' + now.getTime() + '&id=' + pl_cur_id;
         albumart_id = pl_cur_id;
     }
 }
-- 
1.7.7.6




More information about the vlc-devel mailing list