Commit 5c47e150 authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

include/vlc_meta.h: Use the vlc_dictionary to store extra meta tags.

parent 74da5425
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
#ifndef _VLC_META_H #ifndef _VLC_META_H
#define _VLC_META_H 1 #define _VLC_META_H 1
#include <vlc_arrays.h>
/* VLC meta name */ /* VLC meta name */
#define VLC_META_INFO_CAT N_("Meta-information") #define VLC_META_INFO_CAT N_("Meta-information")
#define VLC_META_TITLE N_("Title") #define VLC_META_TITLE N_("Title")
...@@ -77,9 +79,7 @@ struct vlc_meta_t ...@@ -77,9 +79,7 @@ struct vlc_meta_t
char *psz_arturl; char *psz_arturl;
char *psz_trackid; char *psz_trackid;
int i_extra; vlc_dictionary_t extra_tags;
char **ppsz_extra_name;
char **ppsz_extra_value;
int i_status; int i_status;
...@@ -130,18 +130,13 @@ static inline vlc_meta_t *vlc_meta_New( void ) ...@@ -130,18 +130,13 @@ static inline vlc_meta_t *vlc_meta_New( void )
m->psz_arturl = NULL; m->psz_arturl = NULL;
m->psz_trackid = NULL; m->psz_trackid = NULL;
m->i_extra = 0;
m->ppsz_extra_name = NULL;
m->ppsz_extra_value = NULL;
m->i_status = 0; m->i_status = 0;
vlc_dictionary_init( &m->extra_tags, 32 /* "ought to be enough for anybody" */ );
return m; return m;
} }
static inline void vlc_meta_Delete( vlc_meta_t *m ) static inline void vlc_meta_Delete( vlc_meta_t *m )
{ {
int i;
free( m->psz_title ); free( m->psz_title );
free( m->psz_artist ); free( m->psz_artist );
free( m->psz_genre ); free( m->psz_genre );
...@@ -159,26 +154,22 @@ static inline void vlc_meta_Delete( vlc_meta_t *m ) ...@@ -159,26 +154,22 @@ static inline void vlc_meta_Delete( vlc_meta_t *m )
free( m->psz_encodedby ); free( m->psz_encodedby );
free( m->psz_trackid ); free( m->psz_trackid );
free( m->psz_arturl ); free( m->psz_arturl );
for( i = 0; i < m->i_extra; i++ ) vlc_dictionary_clear( &m->extra_tags );
{
free( m->ppsz_extra_name[i] );
free( m->ppsz_extra_value[i] );
}
free( m->ppsz_extra_name );
free( m->ppsz_extra_value );
free( m ); free( m );
} }
static inline void vlc_meta_AddExtra( vlc_meta_t *m, const char *psz_name, const char *psz_value ) static inline void vlc_meta_AddExtra( vlc_meta_t *m, const char *psz_name, const char *psz_value )
{ {
int i_extra = m->i_extra; char * psz_oldvalue = (char *)vlc_dictionary_value_for_key( &m->extra_tags, psz_name );
TAB_APPEND_CPP( char, m->i_extra, m->ppsz_extra_name, strdup(psz_name) ); if( psz_oldvalue != kVLCDictionaryNotFound )
TAB_APPEND_CPP( char, i_extra, m->ppsz_extra_value, strdup(psz_value) ); {
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 ) static inline void vlc_meta_Merge( vlc_meta_t *dst, const vlc_meta_t *src )
{ {
int i;
if( !dst || !src ) return; if( !dst || !src ) return;
#define COPY_FIELD( a ) \ #define COPY_FIELD( a ) \
if( src->psz_ ## a ) { \ if( src->psz_ ## a ) { \
...@@ -203,22 +194,19 @@ static inline void vlc_meta_Merge( vlc_meta_t *dst, const vlc_meta_t *src ) ...@@ -203,22 +194,19 @@ static inline void vlc_meta_Merge( vlc_meta_t *dst, const vlc_meta_t *src )
COPY_FIELD( trackid ); COPY_FIELD( trackid );
COPY_FIELD( arturl ); COPY_FIELD( arturl );
#undef COPY_FIELD #undef COPY_FIELD
char ** ppsz_all_keys;
for( i = 0; i < src->i_extra; i++ ) 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; /* Always try to remove the previous value */
for( j = 0; j < dst->i_extra; j++ ) 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] );
if( !strcmp( dst->ppsz_extra_name[j], src->ppsz_extra_name[i] ) ) vlc_dictionary_insert( &dst->extra_tags, ppsz_all_keys[i], p_value );
{ free( ppsz_all_keys[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] );
} }
free( ppsz_all_keys );
} }
enum { enum {
......
...@@ -612,7 +612,7 @@ static void EsOutProgramMeta( es_out_t *out, int i_group, vlc_meta_t *p_meta ) ...@@ -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 ); msg_Dbg( p_input, "EsOutProgramMeta: number=%d", i_group );
/* Check against empty meta data (empty for what we handle) */ /* 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; return;
/* Find program */ /* Find program */
for( i = 0; i < p_sys->i_pgrm; i++ ) 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 ) ...@@ -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 ); input_Control( p_input, INPUT_ADD_INFO, psz_cat, _(VLC_META_PUBLISHER), psz_provider );
} }
for( i = 0; i < p_meta->i_extra; i++ ) char ** ppsz_all_keys = vlc_dictionary_all_keys( &p_meta->extra_tags );
input_Control( p_input, INPUT_ADD_INFO, psz_cat, _(p_meta->ppsz_extra_name[i]), p_meta->ppsz_extra_value[i] ); 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 ); free( psz_cat );
} }
......
...@@ -2547,7 +2547,7 @@ static void InputUpdateMeta( input_thread_t *p_input, vlc_meta_t *p_meta ) ...@@ -2547,7 +2547,7 @@ static void InputUpdateMeta( input_thread_t *p_input, vlc_meta_t *p_meta )
/* A bit ugly */ /* A bit ugly */
p_meta = NULL; 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(); p_meta = vlc_meta_New();
vlc_meta_Merge( p_meta, p_item->p_meta ); 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 ) ...@@ -2562,9 +2562,14 @@ static void InputUpdateMeta( input_thread_t *p_input, vlc_meta_t *p_meta )
if( p_meta ) if( p_meta )
{ {
for( i = 0; i < p_meta->i_extra; i++ ) char ** ppsz_all_keys = vlc_dictionary_all_keys( &p_meta->extra_tags );
input_Control( p_input, INPUT_ADD_INFO, _(VLC_META_INFO_CAT), for( i = 0; ppsz_all_keys[i]; i++ )
_(p_meta->ppsz_extra_name[i]), "%s", p_meta->ppsz_extra_value[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 ); vlc_meta_Delete( p_meta );
} }
......
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