Commit 39c98427 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

meta: simplify input_ExtractAttachmentAndCacheArt()

Also improve error messages.
parent d022a1a7
...@@ -1371,7 +1371,7 @@ static void EsOutMeta( es_out_t *p_out, const vlc_meta_t *p_meta ) ...@@ -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 ) if( p_input->p->p_sout && !p_input->b_preparsing )
input_item_SetArtURL( p_item, NULL ); input_item_SetArtURL( p_item, NULL );
else else
input_ExtractAttachmentAndCacheArt( p_input ); input_ExtractAttachmentAndCacheArt( p_input, psz_arturl + 13 );
} }
free( psz_arturl ); free( psz_arturl );
......
...@@ -227,8 +227,8 @@ void input_ControlPush( input_thread_t *, int i_type, vlc_value_t * ); ...@@ -227,8 +227,8 @@ void input_ControlPush( input_thread_t *, int i_type, vlc_value_t * );
* Item metadata * Item metadata
**********************************************************************/ **********************************************************************/
/* input_ExtractAttachmentAndCacheArt: /* input_ExtractAttachmentAndCacheArt:
* Becarefull; p_item lock HAS to be taken */ * Be careful: p_item lock will be taken! */
void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input ); void input_ExtractAttachmentAndCacheArt( input_thread_t *, const char *name );
/*************************************************************************** /***************************************************************************
* Internal prototypes * Internal prototypes
......
...@@ -204,26 +204,17 @@ void vlc_meta_Merge( vlc_meta_t *dst, const vlc_meta_t *src ) ...@@ -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; 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 ) ) if( input_item_IsArtFetched( p_item ) )
{ { /* XXX Weird, we should not end up with attachment:// art URL
/* XXX Weird, we should not have end up with attachment:// art url unless there is a race * unless there is a race condition */
* condition */ msg_Warn( p_input, "art already fetched" );
msg_Warn( p_input, "internal input error with input_ExtractAttachmentAndCacheArt" );
playlist_FindArtInCache( p_item ); playlist_FindArtInCache( p_item );
goto exit; return;
} }
/* */ /* */
...@@ -232,38 +223,33 @@ void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input ) ...@@ -232,38 +223,33 @@ void input_ExtractAttachmentAndCacheArt( input_thread_t *p_input )
vlc_mutex_lock( &p_item->lock ); vlc_mutex_lock( &p_item->lock );
for( int i_idx = 0; i_idx < p_input->p->i_attachment; i_idx++ ) for( int i_idx = 0; i_idx < p_input->p->i_attachment; i_idx++ )
{ {
if( !strcmp( p_input->p->attachment[i_idx]->psz_name, input_attachment_t *a = p_input->p->attachment[i_idx];
&psz_arturl[strlen("attachment://")] ) )
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; break;
} }
} }
vlc_mutex_unlock( &p_item->lock ); vlc_mutex_unlock( &p_item->lock );
if( !p_attachment || p_attachment->i_data <= 0 ) if( p_attachment == NULL )
{ {
if( p_attachment ) msg_Warn( p_input, "art attachment %s not found", name );
vlc_input_attachment_Delete( p_attachment ); return;
msg_Warn( p_input, "internal input error with input_ExtractAttachmentAndCacheArt" );
goto exit;
} }
/* */ /* */
const char *psz_type = NULL; const char *psz_type = NULL;
if( !strcmp( p_attachment->psz_mime, "image/jpeg" ) ) if( !strcmp( p_attachment->psz_mime, "image/jpeg" ) )
psz_type = ".jpg"; psz_type = ".jpg";
else if( !strcmp( p_attachment->psz_mime, "image/png" ) ) else if( !strcmp( p_attachment->psz_mime, "image/png" ) )
psz_type = ".png"; psz_type = ".png";
/* */
playlist_SaveArt( VLC_OBJECT(p_input), p_item, playlist_SaveArt( VLC_OBJECT(p_input), p_item,
p_attachment->p_data, p_attachment->i_data, psz_type ); p_attachment->p_data, p_attachment->i_data, psz_type );
vlc_input_attachment_Delete( p_attachment ); vlc_input_attachment_Delete( p_attachment );
exit:
free( psz_arturl );
} }
int input_item_WriteMeta( vlc_object_t *obj, input_item_t *p_item ) int input_item_WriteMeta( vlc_object_t *obj, input_item_t *p_item )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment