[vlc-devel] [PATCH 01/12] input item: expose locked version of GetMeta()
Romain Vimont
rom1v at videolabs.io
Thu Oct 11 23:14:39 CEST 2018
In order to sort the playlist correctly, the input items must be locked
across several calls to GetMeta() (among others).
Therefore, expose a function to retrieve a meta value which does not
lock internally.
---
include/vlc_input_item.h | 2 ++
src/input/item.c | 24 +++++++++++++-----------
src/libvlccore.sym | 1 +
3 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/include/vlc_input_item.h b/include/vlc_input_item.h
index 57fc16193c..481251f100 100644
--- a/include/vlc_input_item.h
+++ b/include/vlc_input_item.h
@@ -281,6 +281,8 @@ VLC_API void input_item_SetDuration( input_item_t * p_i, vlc_tick_t i_duration )
VLC_API bool input_item_IsPreparsed( input_item_t *p_i );
VLC_API bool input_item_IsArtFetched( input_item_t *p_i );
+VLC_API const char *input_item_GetMetaLocked(input_item_t *, vlc_meta_type_t meta_type);
+
#define INPUT_META( name ) \
static inline \
void input_item_Set ## name (input_item_t *p_input, const char *val) \
diff --git a/src/input/item.c b/src/input/item.c
index ff2532ebfa..e52ed0c68c 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;
}
+const char *input_item_GetMetaLocked(input_item_t *item,
+ vlc_meta_type_t meta_type)
+{
+ vlc_assert_locked(&item->lock);
+
+ if (!item->p_meta)
+ return NULL;
+
+ 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 );
-
- if( !p_i->p_meta )
- {
- vlc_mutex_unlock( &p_i->lock );
- 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 ) );
-
+ 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 26fb58f8cb..a7df3bd87b 100644
--- a/src/libvlccore.sym
+++ b/src/libvlccore.sym
@@ -171,6 +171,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
--
2.19.1
More information about the vlc-devel
mailing list