]> git.sesse.net Git - vlc/blobdiff - include/vlc_input.h
Input access locking, part 2.
[vlc] / include / vlc_input.h
index 25e45921e1195abbb251db03622813c18ff2d588..ee219660b5d8b545a98c688358d9db0552482d76 100644 (file)
   #error You are not libvlc or one of its plugins. You cannot include this file
 #endif
 
+#ifndef __USE_GNU
+#define __USE_GNU
+#endif
+#include <string.h>                                     /* strcasestr() */
+
 /* __ is need because conflict with <vlc/input.h> */
 #ifndef _VLC__INPUT_H
 #define _VLC__INPUT_H 1
@@ -114,7 +119,7 @@ static inline void input_ItemInit( vlc_object_t *p_o, input_item_t *p_i )
     p_i->p_meta = NULL;
 
     vlc_mutex_init( p_o, &p_i->lock );
-    vlc_event_manager_init( &p_i->event_manager, p_i );
+    vlc_event_manager_init( &p_i->event_manager, p_i, p_o );
     vlc_event_manager_register_event_type( &p_i->event_manager,
         vlc_InputItemMetaChanged );
     vlc_event_manager_register_event_type( &p_i->event_manager,
@@ -221,9 +226,12 @@ static inline void input_ItemClean( input_item_t *p_i )
 static inline void input_item_SetMeta( input_item_t *p_i, vlc_meta_type_t meta_type, const char *psz_val )
 {
     vlc_event_t event;
+
+    vlc_mutex_lock( &p_i->lock );
     if( !p_i->p_meta )
         p_i->p_meta = vlc_meta_New();
     vlc_meta_Set( p_i->p_meta, meta_type, psz_val );
+    vlc_mutex_unlock( &p_i->lock ); 
 
     /* Notify interested third parties */
     event.type = vlc_InputItemMetaChanged;
@@ -231,11 +239,40 @@ static inline void input_item_SetMeta( input_item_t *p_i, vlc_meta_type_t meta_t
     vlc_event_send( &p_i->event_manager, &event );
 }
 
-static inline const char * input_item_GetMeta( input_item_t *p_i, vlc_meta_type_t meta_type )
+static inline vlc_bool_t input_item_MetaMatch( input_item_t *p_i, vlc_meta_type_t meta_type, const char *psz )
+{
+    vlc_mutex_lock( &p_i->lock );
+    const char * meta = vlc_meta_Get( p_i->p_meta, meta_type );
+    vlc_bool_t ret = meta && strcasestr( meta, psz );
+    vlc_mutex_unlock( &p_i->lock );
+
+    return ret;
+}
+
+static inline char * input_item_GetMeta( input_item_t *p_i, vlc_meta_type_t meta_type )
 {
+    char * psz = NULL;
+    vlc_mutex_lock( &p_i->lock );
+
     if( !p_i->p_meta )
+    {
+        vlc_mutex_unlock( &p_i->lock );
         return NULL;
-    return vlc_meta_Get( p_i->p_meta, meta_type );
+    }
+
+    if( vlc_meta_Get( p_i->p_meta, meta_type ) )
+        psz = strdup( vlc_meta_Get( p_i->p_meta, meta_type ) );
+
+    vlc_mutex_unlock( &p_i->lock );
+    return psz;
+}
+
+static inline char * input_item_GetName( input_item_t * p_i )
+{
+    vlc_mutex_lock( &p_i->lock );
+    char *psz_s = p_i->psz_name ? strdup( p_i->psz_name ) : NULL;
+    vlc_mutex_unlock( &p_i->lock );
+    return psz_s;
 }
 
 static inline void input_item_SetPreparsed( input_item_t *p_i, vlc_bool_t preparsed )