From 34bc82b42c7546246ec9c5d3e257171847d4cf40 Mon Sep 17 00:00:00 2001 From: Romain Vimont <rom1v@videolabs.io> Date: Tue, 25 Sep 2018 16:43:23 +0200 Subject: [PATCH] input item: add a locked version of GetMeta() Expose a function which does not lock internally so that we can retrieve several meta values in a row without locking/unlocking. Signed-off-by: Thomas Guillem <thomas@gllm.fr> --- include/vlc_input_item.h | 1 + src/input/item.c | 20 +++++++++++--------- src/libvlccore.sym | 1 + 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/vlc_input_item.h b/include/vlc_input_item.h index 787f99a78b8e..94760663d487 100644 --- a/include/vlc_input_item.h +++ b/include/vlc_input_item.h @@ -271,6 +271,7 @@ VLC_API bool input_item_HasErrorWhenReading( input_item_t * ); VLC_API void input_item_SetMeta( input_item_t *, vlc_meta_type_t meta_type, const char *psz_val ); VLC_API bool input_item_MetaMatch( input_item_t *p_i, vlc_meta_type_t meta_type, const char *psz ); VLC_API char * input_item_GetMeta( input_item_t *p_i, vlc_meta_type_t meta_type ) VLC_USED; +VLC_API const char *input_item_GetMetaLocked(input_item_t *, vlc_meta_type_t meta_type); VLC_API char * input_item_GetName( input_item_t * p_i ) VLC_USED; VLC_API char * input_item_GetTitleFbName( input_item_t * p_i ) VLC_USED; VLC_API char * input_item_GetURI( input_item_t * p_i ) VLC_USED; diff --git a/src/input/item.c b/src/input/item.c index 1b3f54340d76..c5c2bd5d82cd 100644 --- a/src/input/item.c +++ b/src/input/item.c @@ -251,20 +251,22 @@ bool input_item_MetaMatch( input_item_t *p_i, return b_ret; } -char *input_item_GetMeta( input_item_t *p_i, vlc_meta_type_t meta_type ) +const char *input_item_GetMetaLocked(input_item_t *item, + vlc_meta_type_t meta_type) { - vlc_mutex_lock( &p_i->lock ); + vlc_mutex_assert(&item->lock); - if( !p_i->p_meta ) - { - vlc_mutex_unlock( &p_i->lock ); + if (!item->p_meta) return NULL; - } - char *psz = NULL; - if( vlc_meta_Get( p_i->p_meta, meta_type ) ) - psz = strdup( vlc_meta_Get( p_i->p_meta, meta_type ) ); + return vlc_meta_Get(item->p_meta, meta_type); +} +char *input_item_GetMeta( input_item_t *p_i, vlc_meta_type_t meta_type ) +{ + vlc_mutex_lock( &p_i->lock ); + const char *value = input_item_GetMetaLocked( p_i, meta_type ); + char *psz = value ? strdup( value ) : NULL; vlc_mutex_unlock( &p_i->lock ); return psz; } diff --git a/src/libvlccore.sym b/src/libvlccore.sym index 3fea6e122f20..b82272d019c4 100644 --- a/src/libvlccore.sym +++ b/src/libvlccore.sym @@ -173,6 +173,7 @@ input_item_DelInfo input_item_GetDuration input_item_GetInfo input_item_GetMeta +input_item_GetMetaLocked input_item_GetName input_item_GetNowPlayingFb input_item_GetTitleFbName -- GitLab