Commit da623e25 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont
Browse files

input: private input item reference count

(And remove an useless constant function pointer.)
parent c52e96aa
......@@ -54,7 +54,6 @@ struct info_category_t
struct input_item_t
{
VLC_GC_MEMBERS
int i_id; /**< Identifier of the item */
char *psz_name; /**< text describing this item */
......@@ -267,6 +266,15 @@ VLC_API input_item_t * input_item_NewExt( const char *psz_uri, const char *psz_n
*/
VLC_API input_item_t * input_item_Copy(input_item_t * ) VLC_USED;
/** Holds an input item, i.e. creates a new reference. */
VLC_API input_item_t *input_item_Hold(input_item_t *);
/** Releases an input item, i.e. decrements its reference counter. */
VLC_API void input_item_Release(input_item_t *);
/* Historical hack... */
#define vlc_gc_incref(i) input_item_Hold(i)
#define vlc_gc_decref(i) input_item_Release(i)
/******************
* Input stats
......
......@@ -29,10 +29,8 @@
#include <vlc_common.h>
#include <vlc_url.h>
#include "vlc_playlist.h"
#include "vlc_interface.h"
#include <vlc_interface.h>
#include <vlc_charset.h>
#include <vlc_atomic.h>
#include "item.h"
#include "info.h"
......@@ -407,11 +405,21 @@ bool input_item_IsArtFetched( input_item_t *p_item )
return b_fetched;
}
static void input_item_Destroy ( gc_object_t *p_gc )
input_item_t *input_item_Hold( input_item_t *p_item )
{
input_item_t *p_item = vlc_priv( p_gc, input_item_t );
input_item_owner_t *owner = item_owner(p_item);
atomic_fetch_add( &owner->refs, 1 );
return p_item;
}
void input_item_Release( input_item_t *p_item )
{
input_item_owner_t *owner = item_owner(p_item);
if( atomic_fetch_sub(&owner->refs, 1) != 1 )
return;
vlc_event_manager_fini( &p_item->event_manager );
free( p_item->psz_name );
......@@ -810,11 +818,12 @@ input_item_NewWithType( const char *psz_uri, const char *psz_name,
if( unlikely(owner == NULL) )
return NULL;
atomic_init( &owner->refs, 1 );
input_item_t *p_input = &owner->item;
vlc_event_manager_t * p_em = &p_input->event_manager;
p_input->i_id = atomic_fetch_add(&last_input_id, 1);
vlc_gc_init( p_input, input_item_Destroy );
vlc_mutex_init( &p_input->lock );
p_input->psz_name = NULL;
......
......@@ -25,6 +25,7 @@
#define LIBVLC_INPUT_ITEM_H 1
#include "input_interface.h"
#include <vlc_atomic.h>
void input_item_SetErrorWhenReading( input_item_t *p_i, bool b_error );
void input_item_UpdateTracksInfo( input_item_t *item, const es_format_t *fmt );
......@@ -32,6 +33,7 @@ void input_item_UpdateTracksInfo( input_item_t *item, const es_format_t *fmt );
typedef struct input_item_owner
{
input_item_t item;
atomic_uint refs;
} input_item_owner_t;
# define item_owner(item) ((struct input_item_owner *)(item))
......
......@@ -197,6 +197,8 @@ input_item_MetaMatch
input_item_MergeInfos
input_item_NewExt
input_item_NewWithType
input_item_Hold
input_item_Release
input_item_node_AppendItem
input_item_node_AppendNode
input_item_node_Create
......
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