[vlc-devel] commit: Fixed embedded art attachment support (close #2416) (Laurent Aimar )

git version control git at videolan.org
Sat Jan 24 19:55:43 CET 2009


vlc | branch: master | Laurent Aimar <fenrir at videolan.org> | Sat Jan 24 19:50:49 2009 +0100| [8093b7f26426008b1b065bc8e771ec10eccd41e1] | committer: Laurent Aimar 

Fixed embedded art attachment support (close #2416)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=8093b7f26426008b1b065bc8e771ec10eccd41e1
---

 src/input/input.c  |   12 ++++++------
 src/input/meta.c   |   26 +++++++++++++++++++-------
 src/playlist/art.c |    2 +-
 3 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/src/input/input.c b/src/input/input.c
index c7b210f..a08542e 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -2822,26 +2822,26 @@ static void InputUpdateMeta( input_thread_t *p_input, vlc_meta_t *p_meta )
 
     if( !psz_arturl || *psz_arturl == '\0' )
     {
-        psz_arturl = vlc_meta_Get( p_item->p_meta, vlc_meta_ArtworkURL );
-        if( psz_arturl )
-            psz_arturl = strdup( psz_arturl );
+        const char *psz_tmp = vlc_meta_Get( p_item->p_meta, vlc_meta_ArtworkURL );
+        if( psz_tmp )
+            psz_arturl = strdup( psz_tmp );
     }
+    vlc_mutex_unlock( &p_item->lock );
 
     if( psz_arturl && *psz_arturl )
     {
-        vlc_meta_Set( p_item->p_meta, vlc_meta_ArtworkURL, psz_arturl );
+        input_item_SetArtURL( p_item, psz_arturl );
 
         if( !strncmp( psz_arturl, "attachment://", strlen("attachment") ) )
         {
             /* Don't look for art cover if sout
              * XXX It can change when sout has meta data support */
             if( p_input->p->p_sout && !p_input->b_preparsing )
-                vlc_meta_Set( p_item->p_meta, vlc_meta_ArtworkURL, "" );
+                input_item_SetArtURL( p_item, "" );
             else
                 input_ExtractAttachmentAndCacheArt( p_input );
         }
     }
-    vlc_mutex_unlock( &p_item->lock );
     free( psz_arturl );
 
     if( psz_title )
diff --git a/src/input/meta.c b/src/input/meta.c
index 7df5ce3..ad97c29 100644
--- a/src/input/meta.c
+++ b/src/input/meta.c
@@ -63,16 +63,20 @@ void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input )
     input_item_t *p_item = p_input->p->p_item;
 
     /* */
-    const char *psz_arturl = vlc_meta_Get( p_item->p_meta, vlc_meta_ArtworkURL );
+    char *psz_arturl = input_item_GetArtURL( p_item );
     if( !psz_arturl || strncmp( psz_arturl, "attachment://", strlen("attachment://") ) )
     {
         msg_Err( p_input, "internal input error with input_ExtractAttachmentAndCacheArt" );
+        free( psz_arturl );
         return;
     }
 
     playlist_t *p_playlist = pl_Hold( p_input );
     if( !p_playlist )
+    {
+        free( psz_arturl );
         return;
+    }
 
 
     if( input_item_IsArtFetched( p_item ) )
@@ -81,26 +85,30 @@ void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input )
          * condition */
         msg_Warn( p_input, "internal input error with input_ExtractAttachmentAndCacheArt" );
         playlist_FindArtInCache( p_item );
-        pl_Release( p_playlist );
-        return;
+        goto exit;
     }
 
     /* */
     input_attachment_t *p_attachment = NULL;
+
+    vlc_mutex_lock( &p_item->lock );
     for( int i_idx = 0; i_idx < p_input->p->i_attachment; i_idx++ )
     {
         if( !strcmp( p_input->p->attachment[i_idx]->psz_name,
                      &psz_arturl[strlen("attachment://")] ) )
         {
-            p_attachment = p_input->p->attachment[i_idx];
+            p_attachment = vlc_input_attachment_Duplicate( p_input->p->attachment[i_idx] );
             break;
         }
     }
+    vlc_mutex_unlock( &p_item->lock );
+
     if( !p_attachment || p_attachment->i_data <= 0 )
     {
+        if( p_attachment )
+            vlc_input_attachment_Delete( p_attachment );
         msg_Warn( p_input, "internal input error with input_ExtractAttachmentAndCacheArt" );
-        pl_Release( p_playlist );
-        return;
+        goto exit;
     }
 
     /* */
@@ -114,6 +122,10 @@ void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input )
     playlist_SaveArt( p_playlist, p_item,
                       p_attachment->p_data, p_attachment->i_data, psz_type );
 
-    pl_Release( p_playlist );
+    vlc_input_attachment_Delete( p_attachment );
+
+exit:
+    pl_Release( p_input );
+    free( psz_arturl );
 }
 
diff --git a/src/playlist/art.c b/src/playlist/art.c
index 28a5dff..1efe0de 100644
--- a/src/playlist/art.c
+++ b/src/playlist/art.c
@@ -221,7 +221,7 @@ int playlist_SaveArt( playlist_t *p_playlist, input_item_t *p_item,
     }
 
     /* Dump it otherwise */
-    FILE *f = utf8_fopen( psz_filename+7, "w" );
+    FILE *f = utf8_fopen( psz_filename+7, "wb" );
     if( f )
     {
         if( fwrite( p_buffer, i_buffer, 1, f ) != 1 )




More information about the vlc-devel mailing list