[vlc-commits] meta: simplify input_ExtractAttachmentAndCacheArt()
Rémi Denis-Courmont
git at videolan.org
Fri Aug 15 18:46:46 CEST 2014
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Aug 15 19:03:40 2014 +0300| [39c984278e06ae31e258f6c34170beeb0b4235c4] | committer: Rémi Denis-Courmont
meta: simplify input_ExtractAttachmentAndCacheArt()
Also improve error messages.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=39c984278e06ae31e258f6c34170beeb0b4235c4
---
src/input/es_out.c | 2 +-
src/input/input_internal.h | 4 ++--
src/input/meta.c | 42 ++++++++++++++----------------------------
3 files changed, 17 insertions(+), 31 deletions(-)
diff --git a/src/input/es_out.c b/src/input/es_out.c
index 414970b..f042fa6 100644
--- a/src/input/es_out.c
+++ b/src/input/es_out.c
@@ -1371,7 +1371,7 @@ static void EsOutMeta( es_out_t *p_out, const vlc_meta_t *p_meta )
if( p_input->p->p_sout && !p_input->b_preparsing )
input_item_SetArtURL( p_item, NULL );
else
- input_ExtractAttachmentAndCacheArt( p_input );
+ input_ExtractAttachmentAndCacheArt( p_input, psz_arturl + 13 );
}
free( psz_arturl );
diff --git a/src/input/input_internal.h b/src/input/input_internal.h
index 9f71294..e23b74d 100644
--- a/src/input/input_internal.h
+++ b/src/input/input_internal.h
@@ -227,8 +227,8 @@ void input_ControlPush( input_thread_t *, int i_type, vlc_value_t * );
* Item metadata
**********************************************************************/
/* input_ExtractAttachmentAndCacheArt:
- * Becarefull; p_item lock HAS to be taken */
-void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input );
+ * Be careful: p_item lock will be taken! */
+void input_ExtractAttachmentAndCacheArt( input_thread_t *, const char *name );
/***************************************************************************
* Internal prototypes
diff --git a/src/input/meta.c b/src/input/meta.c
index 892b4af..17987e3 100644
--- a/src/input/meta.c
+++ b/src/input/meta.c
@@ -204,26 +204,17 @@ void vlc_meta_Merge( vlc_meta_t *dst, const vlc_meta_t *src )
}
-void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input )
+void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input,
+ const char *name )
{
input_item_t *p_item = p_input->p->p_item;
- /* */
- 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;
- }
-
if( input_item_IsArtFetched( p_item ) )
- {
- /* XXX Weird, we should not have end up with attachment:// art url unless there is a race
- * condition */
- msg_Warn( p_input, "internal input error with input_ExtractAttachmentAndCacheArt" );
+ { /* XXX Weird, we should not end up with attachment:// art URL
+ * unless there is a race condition */
+ msg_Warn( p_input, "art already fetched" );
playlist_FindArtInCache( p_item );
- goto exit;
+ return;
}
/* */
@@ -232,38 +223,33 @@ void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input )
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://")] ) )
+ input_attachment_t *a = p_input->p->attachment[i_idx];
+
+ if( !strcmp( a->psz_name, name ) )
{
- p_attachment = vlc_input_attachment_Duplicate( p_input->p->attachment[i_idx] );
+ p_attachment = vlc_input_attachment_Duplicate( a );
break;
}
}
vlc_mutex_unlock( &p_item->lock );
- if( !p_attachment || p_attachment->i_data <= 0 )
+ if( p_attachment == NULL )
{
- if( p_attachment )
- vlc_input_attachment_Delete( p_attachment );
- msg_Warn( p_input, "internal input error with input_ExtractAttachmentAndCacheArt" );
- goto exit;
+ msg_Warn( p_input, "art attachment %s not found", name );
+ return;
}
/* */
const char *psz_type = NULL;
+
if( !strcmp( p_attachment->psz_mime, "image/jpeg" ) )
psz_type = ".jpg";
else if( !strcmp( p_attachment->psz_mime, "image/png" ) )
psz_type = ".png";
- /* */
playlist_SaveArt( VLC_OBJECT(p_input), p_item,
p_attachment->p_data, p_attachment->i_data, psz_type );
-
vlc_input_attachment_Delete( p_attachment );
-
-exit:
- free( psz_arturl );
}
int input_item_WriteMeta( vlc_object_t *obj, input_item_t *p_item )
More information about the vlc-commits
mailing list