From 5c47e1504ebede6bda22b1ac721021ea4e341bd0 Mon Sep 17 00:00:00 2001 From: Pierre d'Herbemont Date: Mon, 13 Aug 2007 13:55:10 +0000 Subject: [PATCH] include/vlc_meta.h: Use the vlc_dictionary to store extra meta tags. --- include/vlc_meta.h | 58 ++++++++++++++++++---------------------------- src/input/es_out.c | 12 +++++++--- src/input/input.c | 13 +++++++---- 3 files changed, 41 insertions(+), 42 deletions(-) diff --git a/include/vlc_meta.h b/include/vlc_meta.h index 28bd4acfce..1d5820419d 100644 --- a/include/vlc_meta.h +++ b/include/vlc_meta.h @@ -28,6 +28,8 @@ #ifndef _VLC_META_H #define _VLC_META_H 1 +#include + /* VLC meta name */ #define VLC_META_INFO_CAT N_("Meta-information") #define VLC_META_TITLE N_("Title") @@ -77,9 +79,7 @@ struct vlc_meta_t char *psz_arturl; char *psz_trackid; - int i_extra; - char **ppsz_extra_name; - char **ppsz_extra_value; + vlc_dictionary_t extra_tags; int i_status; @@ -130,18 +130,13 @@ static inline vlc_meta_t *vlc_meta_New( void ) m->psz_arturl = NULL; m->psz_trackid = NULL; - m->i_extra = 0; - m->ppsz_extra_name = NULL; - m->ppsz_extra_value = NULL; - m->i_status = 0; + vlc_dictionary_init( &m->extra_tags, 32 /* "ought to be enough for anybody" */ ); return m; } static inline void vlc_meta_Delete( vlc_meta_t *m ) { - int i; - free( m->psz_title ); free( m->psz_artist ); free( m->psz_genre ); @@ -159,26 +154,22 @@ static inline void vlc_meta_Delete( vlc_meta_t *m ) free( m->psz_encodedby ); free( m->psz_trackid ); free( m->psz_arturl ); - for( i = 0; i < m->i_extra; i++ ) - { - free( m->ppsz_extra_name[i] ); - free( m->ppsz_extra_value[i] ); - } - free( m->ppsz_extra_name ); - free( m->ppsz_extra_value ); - + vlc_dictionary_clear( &m->extra_tags ); free( m ); } static inline void vlc_meta_AddExtra( vlc_meta_t *m, const char *psz_name, const char *psz_value ) { - int i_extra = m->i_extra; - TAB_APPEND_CPP( char, m->i_extra, m->ppsz_extra_name, strdup(psz_name) ); - TAB_APPEND_CPP( char, i_extra, m->ppsz_extra_value, strdup(psz_value) ); + char * psz_oldvalue = (char *)vlc_dictionary_value_for_key( &m->extra_tags, psz_name ); + if( psz_oldvalue != kVLCDictionaryNotFound ) + { + free( psz_oldvalue ); + vlc_dictionary_remove_value_for_key( &m->extra_tags, psz_name ); + } + vlc_dictionary_insert( &m->extra_tags, psz_name, strdup(psz_value) ); } static inline void vlc_meta_Merge( vlc_meta_t *dst, const vlc_meta_t *src ) { - int i; if( !dst || !src ) return; #define COPY_FIELD( a ) \ if( src->psz_ ## a ) { \ @@ -203,22 +194,19 @@ static inline void vlc_meta_Merge( vlc_meta_t *dst, const vlc_meta_t *src ) COPY_FIELD( trackid ); COPY_FIELD( arturl ); #undef COPY_FIELD - - for( i = 0; i < src->i_extra; i++ ) + char ** ppsz_all_keys; + int i; + /* XXX: If speed up are needed, it is possible */ + ppsz_all_keys = vlc_dictionary_all_keys( &src->extra_tags ); + for( i = 0; ppsz_all_keys[i]; i++ ) { - int j; - for( j = 0; j < dst->i_extra; j++ ) - { - if( !strcmp( dst->ppsz_extra_name[j], src->ppsz_extra_name[i] ) ) - { - free( dst->ppsz_extra_value[j] ); - dst->ppsz_extra_value[j] = strdup( src->ppsz_extra_value[i] ); - break; - } - } - if( j >= dst->i_extra ) - vlc_meta_AddExtra( dst, src->ppsz_extra_name[i], src->ppsz_extra_value[i] ); + /* Always try to remove the previous value */ + vlc_dictionary_remove_value_for_key( &dst->extra_tags, ppsz_all_keys[i] ); + void * p_value = vlc_dictionary_value_for_key( &src->extra_tags, ppsz_all_keys[i] ); + vlc_dictionary_insert( &dst->extra_tags, ppsz_all_keys[i], p_value ); + free( ppsz_all_keys[i] ); } + free( ppsz_all_keys ); } enum { diff --git a/src/input/es_out.c b/src/input/es_out.c index f444d9529c..2b542c3468 100644 --- a/src/input/es_out.c +++ b/src/input/es_out.c @@ -612,7 +612,7 @@ static void EsOutProgramMeta( es_out_t *out, int i_group, vlc_meta_t *p_meta ) msg_Dbg( p_input, "EsOutProgramMeta: number=%d", i_group ); /* Check against empty meta data (empty for what we handle) */ - if( !p_meta->psz_title && !p_meta->psz_nowplaying && !p_meta->psz_publisher && p_meta->i_extra <= 0 ) + if( !p_meta->psz_title && !p_meta->psz_nowplaying && !p_meta->psz_publisher && vlc_dictionary_keys_count( &p_meta->extra_tags ) <= 0 ) return; /* Find program */ for( i = 0; i < p_sys->i_pgrm; i++ ) @@ -676,8 +676,14 @@ static void EsOutProgramMeta( es_out_t *out, int i_group, vlc_meta_t *p_meta ) } input_Control( p_input, INPUT_ADD_INFO, psz_cat, _(VLC_META_PUBLISHER), psz_provider ); } - for( i = 0; i < p_meta->i_extra; i++ ) - input_Control( p_input, INPUT_ADD_INFO, psz_cat, _(p_meta->ppsz_extra_name[i]), p_meta->ppsz_extra_value[i] ); + char ** ppsz_all_keys = vlc_dictionary_all_keys( &p_meta->extra_tags ); + for( i = 0; ppsz_all_keys[i]; i++ ) + { + input_Control( p_input, INPUT_ADD_INFO, psz_cat, _(ppsz_all_keys[i]), + vlc_dictionary_value_for_key( &p_meta->extra_tags, ppsz_all_keys[i] ) ); + free( ppsz_all_keys[i] ); + } + free( ppsz_all_keys ); free( psz_cat ); } diff --git a/src/input/input.c b/src/input/input.c index bcedc2d1c6..46b5759e71 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -2547,7 +2547,7 @@ static void InputUpdateMeta( input_thread_t *p_input, vlc_meta_t *p_meta ) /* A bit ugly */ p_meta = NULL; - if( p_item->p_meta->i_extra > 0 ) + if( vlc_dictionary_keys_count( &p_item->p_meta->extra_tags ) > 0 ) { p_meta = vlc_meta_New(); vlc_meta_Merge( p_meta, p_item->p_meta ); @@ -2562,9 +2562,14 @@ static void InputUpdateMeta( input_thread_t *p_input, vlc_meta_t *p_meta ) if( p_meta ) { - for( i = 0; i < p_meta->i_extra; i++ ) - input_Control( p_input, INPUT_ADD_INFO, _(VLC_META_INFO_CAT), - _(p_meta->ppsz_extra_name[i]), "%s", p_meta->ppsz_extra_value[i] ); + char ** ppsz_all_keys = vlc_dictionary_all_keys( &p_meta->extra_tags ); + for( i = 0; ppsz_all_keys[i]; i++ ) + { + input_Control( p_input, INPUT_ADD_INFO, _(VLC_META_INFO_CAT), _(ppsz_all_keys[i]), + vlc_dictionary_value_for_key( &p_meta->extra_tags, ppsz_all_keys[i] ) ); + free( ppsz_all_keys[i] ); + } + free( ppsz_all_keys ); vlc_meta_Delete( p_meta ); } -- 2.39.5