1
mirror of https://code.videolan.org/videolan/vlc synced 2024-08-27 04:21:53 +02:00

Input access locking. Part one

This commit is contained in:
Rafaël Carré 2007-08-18 03:22:03 +00:00
parent a9d17dba88
commit 38dbd37adf
18 changed files with 206 additions and 96 deletions

View File

@ -221,9 +221,11 @@ 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->p_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->p_lock );
/* Notify interested third parties */
event.type = vlc_InputItemMetaChanged;
@ -231,11 +233,25 @@ 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 char * input_item_GetMeta( input_item_t *p_i, vlc_meta_type_t meta_type )
{
vlc_mutex_lock( &p_i->p_lock );
if( !p_i->p_meta )
{
vlc_mutex_unlock( &p_i->p_lock );
return NULL;
return vlc_meta_Get( p_i->p_meta, meta_type );
}
char *psz_s = strdup( vlc_meta_Get( p_i->p_meta, meta_type ) );
vlc_mutex_unlock( &p_i->p_lock );
return psz_s;
}
static inline char * input_item_GetName( input_item_t *p_i )
{
vlc_mutex_lock( &p_i->p_lock );
char *psz_s = strdup( p_i->psz_name );
vlc_mutex_unlock( &p_i->p_lock );
return psz_s;
}
static inline void input_item_SetPreparsed( input_item_t *p_i, vlc_bool_t preparsed )

View File

@ -866,9 +866,10 @@ static int TrackChange( vlc_object_t *p_this, const char *psz_var,
#define ADD_VLC_META_STRING( entry, item ) \
{ \
const char * psz = input_item_Get##item( p_input );\
char * psz = input_item_Get##item( p_input );\
ADD_META( entry, DBUS_TYPE_STRING, \
psz ); \
free( psz ); \
}
static int GetInputMeta( input_item_t* p_input,

View File

@ -620,7 +620,7 @@ static void ParseComment( demux_t *p_demux, const uint8_t *p_data, int i_data )
#define IF_EXTRACT(txt,var) \
if( !strncasecmp(psz, txt, strlen(txt)) ) \
{ \
const char * oldval = vlc_meta_Get( p_sys->p_meta, vlc_meta_ ## var ); \
char * oldval = vlc_meta_Get( p_sys->p_meta, vlc_meta_ ## var ); \
if( oldval ) \
{ \
char * newval; \
@ -630,6 +630,7 @@ static void ParseComment( demux_t *p_demux, const uint8_t *p_data, int i_data )
} \
else \
vlc_meta_Set( p_sys->p_meta, vlc_meta_ ## var, &psz[strlen(txt)] ); \
free( oldval ); \
}
IF_EXTRACT("TITLE=", Title )
else IF_EXTRACT("ALBUM=", Album )

View File

@ -271,38 +271,50 @@
if( [[o_tc identifier] isEqualToString:@"1"] )
{
/* sanity check to prevent the NSString class from crashing */
if( !EMPTY_STR( input_item_GetTitle( p_item->p_input ) ) )
char *psz_title = input_item_GetTitle( p_item->p_input );
if( !EMPTY_STR( psz_title ) ) )
{
o_value = [NSString stringWithUTF8String: input_item_GetTitle( p_item->p_input )];
o_value = [NSString stringWithUTF8String: psz_title )];
if( o_value == NULL )
o_value = [NSString stringWithCString: input_item_GetTitle( p_item->p_input )];
o_value = [NSString stringWithCString: psz_title )];
}
else if( p_item->p_input->psz_name != NULL )
{
o_value = [NSString stringWithUTF8String: p_item->p_input->psz_name];
if( o_value == NULL )
o_value = [NSString stringWithCString: p_item->p_input->psz_name];
}
}
else if( [[o_tc identifier] isEqualToString:@"2"] && !EMPTY_STR( input_item_GetArtist( p_item->p_input ) ) )
{
o_value = [NSString stringWithUTF8String: input_item_GetArtist( p_item->p_input )];
if( o_value == NULL )
o_value = [NSString stringWithCString: input_item_GetArtist( p_item->p_input )];
}
else if( [[o_tc identifier] isEqualToString:@"3"] )
{
char psz_duration[MSTRTIME_MAX_SIZE];
mtime_t dur = p_item->p_input->i_duration;
if( dur != -1 )
{
secstotimestr( psz_duration, dur/1000000 );
o_value = [NSString stringWithUTF8String: psz_duration];
}
else
{
o_value = @"-:--:--";
char *psz_name = input_item_GetName( p_item->p_input );
if( psz_name != NULL )
{
o_value = [NSString stringWithUTF8String: psz_name];
if( o_value == NULL )
o_value = [NSString stringWithCString: psz_name];
}
}
free( psz_title );
free( psz_name );
}
else
{
char *psz_artist = input_item_GetArtist( p_item->p_input );
if( [[o_tc identifier] isEqualToString:@"2"] && !EMPTY_STR( psz_artist ) )
{
o_value = [NSString stringWithUTF8String: psz_artist )];
if( o_value == NULL )
o_value = [NSString stringWithCString: psz_artist )];
}
else if( [[o_tc identifier] isEqualToString:@"3"] )
{
char psz_duration[MSTRTIME_MAX_SIZE];
mtime_t dur = p_item->p_input->i_duration;
if( dur != -1 )
{
secstotimestr( psz_duration, dur/1000000 );
o_value = [NSString stringWithUTF8String: psz_duration];
}
else
{
o_value = @"-:--:--";
}
}
free( psz_artist );
}
return( o_value );

View File

@ -188,18 +188,21 @@ void MetaPanel::saveMeta()
**/
void MetaPanel::update( input_item_t *p_item )
{
const char *psz_meta;
char *psz_meta;
#define UPDATE_META( meta, widget ) { \
psz_meta = input_item_Get##meta( p_item ); \
if( !EMPTY_STR( psz_meta ) ) \
widget->setText( qfu( psz_meta ) ); \
else \
widget->setText( "" ); }
widget->setText( "" ); } \
free( psz_meta );
#define UPDATE_META_INT( meta, widget ) { \
psz_meta = input_item_Get##meta( p_item ); \
if( !EMPTY_STR( psz_meta ) ) \
widget->setValue( atoi( psz_meta ) ); }
widget->setValue( atoi( psz_meta ) ); } \
free( psz_meta );
/* Name / Title */
psz_meta = input_item_GetTitle( p_item );
@ -208,6 +211,7 @@ void MetaPanel::update( input_item_t *p_item )
else if( !EMPTY_STR( p_item->psz_name ) )
title_text->setText( qfu( p_item->psz_name ) );
else title_text->setText( "" );
free( psz_meta );
/* URL / URI */
psz_meta = input_item_GetURL( p_item );
@ -215,6 +219,7 @@ void MetaPanel::update( input_item_t *p_item )
emit uriSet( QString( psz_meta ) );
else if( !EMPTY_STR( p_item->psz_uri ) )
emit uriSet( QString( p_item->psz_uri ) );
free( psz_meta );
/* Other classic though */
UPDATE_META( Artist, artist_text );
@ -243,6 +248,7 @@ void MetaPanel::update( input_item_t *p_item )
}
else
art_cover->setPixmap( QPixmap( ":/noart.png" ) );
free( psz_meta );
}
/*

View File

@ -132,22 +132,24 @@ void InputManager::update()
/* Update text */
QString text;
if( !EMPTY_STR(input_item_GetNowPlaying( input_GetItem(p_input) )) )
char *psz_name = input_GetName( input_GetItem( p_input ) );
char *psz_nowplaying = input_item_GetNowPlaying( input_GetItem( p_input );
char *psz_artist = input_item_GetArtist( input_GetItem( p_input ) );
if( !EMPTY_STR( psz_nowplaying ) )
{
text.sprintf( "%s - %s",
input_item_GetNowPlaying( input_GetItem(p_input) ),
input_GetItem(p_input)->psz_name );
text.sprintf( "%s - %s", psz_now_playing, psz_name );
}
else if( !EMPTY_STR(input_item_GetArtist( input_GetItem(p_input) )) )
else if( !EMPTY_STR( psz_artist ) )
{
text.sprintf( "%s - %s",
input_item_GetArtist( input_GetItem(p_input) ),
input_GetItem(p_input)->psz_name );
text.sprintf( "%s - %s", psz_artist, psz_name );
}
else
{
text.sprintf( "%s", input_GetItem(p_input)->psz_name );
text.sprintf( "%s", psz_name );
}
free( psz_name );
free( psz_nowplaying );
free( psz_artist );
if( old_name != text )
{
emit nameChanged( text );

View File

@ -20,7 +20,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#define PLI_NAME( p ) p ? p->p_input->psz_name : "null"
#include <assert.h>
#include <QIcon>
@ -184,11 +183,13 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent )
type = p_item->p_input->i_type;
current = iscurrent;
if( current && input_item_GetArtURL( p_item->p_input ) &&
!strncmp( input_item_GetArtURL( p_item->p_input ), "file://", 7 ) )
model->sendArt( qfu( input_item_GetArtURL( p_item->p_input ) ) );
char *psz_arturl = input_item_GetArtURL( p_item->p_input );
if( current && psz_arturl ) &&
!strncmp( psz_arturl, "file://", 7 ) )
model->sendArt( qfu( psz_arturl ) ) );
else if( current )
model->removeArt();
free( psz_arturl );
strings.clear();
@ -198,9 +199,11 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent )
return;
}
char *psz_meta;
#define ADD_META( item, meta ) \
strings.append( qfu( input_item_Get ## meta ( item->p_input ) ) )
psz_meta = input_item_Get ## meta ( item->p_input ); \
strings.append( qfu( psz_meta ) ); \
free( psz_meta );
for( int i_index=1; i_index <= VLC_META_ENGINE_MB_TRM_ID; i_index = i_index * 2 )
{
@ -212,12 +215,17 @@ void PLItem::update( playlist_item_t *p_item, bool iscurrent )
ADD_META( p_item, Artist );
break;
case VLC_META_ENGINE_TITLE:
if( input_item_GetTitle( p_item->p_input ) )
char *psz_title;
psz_title = input_item_GetTile( p_item->p_input );
psz_name = input_item_GetName( p_item->p_input );
if( psz_title )
{
ADD_META( p_item, Title );
} else {
strings.append( qfu( p_item->p_input->psz_name ) );
strings.append( qfu( psz_name ) );
}
free( psz_title );
free( psz_name );
break;
case VLC_META_ENGINE_DESCRIPTION:
ADD_META( p_item, Description );

View File

@ -121,13 +121,14 @@ void MetaDataPanel::Update( input_item_t *p_item )
name_text->SetValue( wxU( p_item->psz_name ) );
#define UPDATE_META( meta, widget ) { \
const char *psz_meta = input_item_Get##meta( p_item ); \
char *psz_meta = input_item_Get##meta( p_item ); \
if( psz_meta != NULL && *psz_meta) \
{ \
widget->SetLabel( wxU( psz_meta ) ); \
} \
else { widget->SetLabel( wxU( "-" ) ); } \
}
} \
free( psz_meta );
UPDATE_META( Artist, artist_text );
UPDATE_META( Genre, genre_text );

View File

@ -513,9 +513,7 @@ void Playlist::UpdateTreeItem( wxTreeItemId item )
wxString duration = wxU( "" );
char *psz_artist;
psz_artist = input_item_GetArtist( p_item->p_input ) ?
strdup( input_item_GetArtist( p_item->p_input ) ) :
strdup("");
psz_artist = input_item_GetArtist( p_item->p_input );
char psz_duration[MSTRTIME_MAX_SIZE];
mtime_t dur = p_item->p_input->i_duration;

View File

@ -210,7 +210,7 @@ void InputManager::UpdateInput()
void InputManager::UpdateNowPlaying()
{
const char *psz_now_playing = input_item_GetNowPlaying( input_GetItem(p_input) );
char *psz_now_playing = input_item_GetNowPlaying( input_GetItem(p_input) );
if( psz_now_playing && *psz_now_playing )
{
p_main_intf->statusbar->SetStatusText(
@ -222,6 +222,7 @@ void InputManager::UpdateNowPlaying()
p_main_intf->statusbar->SetStatusText(
wxU(input_GetItem(p_input)->psz_name), 2 );
}
free( psz_now_playing );
}
void InputManager::UpdateButtons( vlc_bool_t b_play )

View File

@ -299,7 +299,7 @@ void PlaylistManager::UpdateTreeItem( wxTreeItemId item )
wxString msg;
wxString duration = wxU( "" );
const char *psz_artist = input_item_GetArtist( p_item->p_input );
char *psz_artist = input_item_GetArtist( p_item->p_input );
if( ! psz_artist )
{
psz_artist = "";
@ -324,6 +324,7 @@ void PlaylistManager::UpdateTreeItem( wxTreeItemId item )
msg = wxString(wxU( psz_artist )) + wxT(" - ") +
wxString(wxU(p_item->p_input->psz_name)) + duration;
}
free( psz_artist );
treectrl->SetItemText( item , msg );
treectrl->SetItemImage( item, p_item->p_input->i_type );

View File

@ -250,6 +250,7 @@ static lua_State * vlclua_meta_init( vlc_object_t *p_this, input_item_t * p_item
msg_Err( p_this, "Could not create new Lua State" );
return NULL;
}
char *psz_meta;
/* Load Lua libraries */
luaL_openlibs( p_state ); /* XXX: Don't open all the libs? */
@ -258,19 +259,27 @@ static lua_State * vlclua_meta_init( vlc_object_t *p_this, input_item_t * p_item
lua_pushlightuserdata( p_state, p_this );
lua_setfield( p_state, lua_gettop( p_state ) - 1, "private" );
lua_pushstring( p_state, p_item->psz_name );
psz_meta = input_item_GetName( p_item );
lua_pushstring( p_state, psz_meta );
lua_setfield( p_state, lua_gettop( p_state ) - 1, "name" );
lua_pushstring( p_state, input_item_GetTitle( p_item ) );
free( psz_meta );
psz_meta = input_item_GetTitle( p_item ) ;
lua_pushstring( p_state, psz_meta );
lua_setfield( p_state, lua_gettop( p_state ) - 1, "title" );
lua_pushstring( p_state, input_item_GetAlbum( p_item ) );
free( psz_meta );
psz_meta = input_item_GetAlbum( p_item );
lua_pushstring( p_state, psz_meta );
lua_setfield( p_state, lua_gettop( p_state ) - 1, "album" );
free( psz_meta );
lua_pushstring( p_state, input_item_GetArtURL( p_item ) );
psz_meta = input_item_GetArtURL( p_item );
lua_pushstring( p_state, psz_meta );
lua_setfield( p_state, lua_gettop( p_state ) - 1, "arturl" );
/* XXX: all should be passed */
free( psz_meta );
/* XXX: all should be passed ( could use macro ) */
return p_state;
}

View File

@ -77,16 +77,20 @@ static int GetData( vlc_object_t *p_obj, input_item_t *p_item,
char i_album_count, i;
char *ppsz_args[4];
char *psz_title;
char *psz_artist;
char *psz_album;
psz_artist = input_item_GetArtist( p_item );
psz_album = input_item_GetAlbum( p_item );
psz_title = p_item->psz_name;
if( !psz_artist || !psz_album )
{
free( psz_artist );
free( psz_album );
return VLC_EGENERIC;
}
free( psz_artist );
free( psz_album );
musicbrainz_t p_mb;
@ -154,8 +158,13 @@ static int GetData( vlc_object_t *p_obj, input_item_t *p_item,
if( !b_art )
return VLC_SUCCESS;
else
return EMPTY_STR( input_item_GetArtURL( p_item ) ) ?
VLC_SUCCESS : VLC_EGENERIC;
{
char *psz_arturl;
psz_arturl = input_item_GetArtURL( p_item );
int i_ret;
i_ret = EMPTY_STR( psz_arturl ) ? VLC_SUCCESS : VLC_EGENERIC ;
free( psz_arturl );
return i_ret;
}
static int FindMetaMBId( vlc_object_t *p_this )

View File

@ -193,22 +193,35 @@ static int WriteMeta( vlc_object_t *p_this )
TagLib::Tag *tag = f.tag();
SET( Artist, input_item_GetArtist( p_item ) );
char *psz_meta;
const char *psz_titlec = ( input_item_GetTitle( p_item ) ?
input_item_GetTitle( p_item ) : p_item->psz_name );
TagLib::String *psz_title = new TagLib::String( psz_titlec,
psz_meta = input_item_GetArtist( p_item );
SET( Artist, psz_meta );
free( psz_meta );
psz_meta = input_item_GetTitle( p_item );
if( !psz_meta ) psz_meta = input_item_GetName( p_item );
TagLib::String *psz_title = new TagLib::String( psz_meta,
TagLib::String::UTF8 );
tag->setTitle( *psz_title );
delete psz_title;
free( psz_meta );
SET( Album, input_item_GetAlbum( p_item ) );
SET( Genre, input_item_GetGenre( p_item ) );
psz_meta = input_item_GetAlbum( p_item );
SET( Album, psz_meta );
free( psz_meta );
if( input_item_GetDate( p_item ) )
tag->setYear( atoi( input_item_GetDate( p_item ) ) );
if( input_item_GetTrackNum( p_item ) )
tag->setTrack( atoi( input_item_GetTrackNum( p_item ) ) );
psz_meta = input_item_GetGenre( p_item );
SET( Genre, psz_meta );
free( psz_meta );
psz_meta = input_item_GetDate( p_item );
if( psz_meta ) tag->setYear( atoi( psz_meta ) );
free( psz_meta );
psz_meta = input_item_GetTrackNum( p_item );
if( psz_meta ) tag->setTrack( atoi( psz_meta ) );
free( psz_meta );
f.save();
return VLC_SUCCESS;

View File

@ -630,8 +630,10 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
p_sys->p_current_song->psz_i = encode_URI_component( psz_date );
p_sys->p_current_song->time_playing = epoch;
p_sys->b_paused = ( p_input->b_dead || !input_GetItem(p_input)->psz_name )
char *psz_name = input_item_GetName( input_GetItem( p_input ) );
p_sys->b_paused = ( p_input->b_dead || !psz_name )
? VLC_TRUE : VLC_FALSE;
free( psz_name );
vlc_mutex_unlock( &p_sys->lock );
@ -1003,7 +1005,7 @@ static int ReadMetaData( intf_thread_t *p_this )
var_Change( p_input, "video-es", VLC_VAR_CHOICESCOUNT, &video_val, NULL );
if( ( video_val.i_int > 0 ) || \
( input_GetItem(p_input)->i_type == ITEM_TYPE_NET ) )
( input_GetItem( p_input )->i_type == ITEM_TYPE_NET ) )
{
msg_Dbg( p_this, "Not an audio only local file -> no submission");
vlc_object_release( p_input );
@ -1038,16 +1040,19 @@ static int ReadMetaData( intf_thread_t *p_this )
return VLC_SUCCESS; \
}
char *psz_meta;
#define ALLOC_ITEM_META( a, b ) \
if ( input_item_Get##b( input_GetItem(p_input) ) ) \
psz_meta = input_item_Get##b( input_GetItem( p_input ) ) \
if( psz_meta ) \
{ \
a = encode_URI_component( \
input_item_Get##b( input_GetItem(p_input) )); \
a = encode_URI_component( psz_meta ); \
if( !a ) \
{ \
free( psz_meta ); \
FREE_INPUT_AND_CHARS \
return VLC_ENOMEM; \
} \
free( psz_meta ); \
}
i_status = input_GetItem(p_input)->p_meta->i_status;
@ -1064,15 +1069,17 @@ static int ReadMetaData( intf_thread_t *p_this )
msg_Dbg( p_this, "No artist.." );
WAIT_METADATA_FETCHING( psz_artist )
}
if( input_GetItem(p_input)->psz_name )
psz_meta = input_item_GetName( input_GetItem( p_input ) );
if( psz_meta )
{
psz_title = encode_URI_component( input_GetItem(p_input)->psz_name );
psz_title = encode_URI_component( psz_meta );
if( !psz_title )
{
free( psz_meta );
FREE_INPUT_AND_CHARS
return VLC_ENOMEM;
}
free( psz_meta );
}
else
{

View File

@ -276,7 +276,7 @@ char * libvlc_media_descriptor_get_meta( libvlc_media_descriptor_t *p_md,
libvlc_meta_t e_meta,
libvlc_exception_t *p_e )
{
const char * psz_meta;
char * psz_meta;
/* XXX: locking */
@ -287,11 +287,17 @@ char * libvlc_media_descriptor_get_meta( libvlc_media_descriptor_t *p_md,
/* Should be integrated in core */
if( !psz_meta && e_meta == libvlc_meta_Title && p_md->p_input_item->psz_name )
{
free( psz_meta );
return strdup( p_md->p_input_item->psz_name );
}
if( !psz_meta )
return NULL;
{
free( psz_meta );
return NULL
}
return strdup( psz_meta );
return psz_meta;
}

View File

@ -120,12 +120,29 @@ int playlist_LiveSearchUpdate( playlist_t *p_playlist, playlist_item_t *p_root,
{
playlist_LiveSearchUpdate( p_playlist, p_item, psz_string );
}
#define META_MATCHES( field ) ( input_item_GetMeta( p_item->p_input, vlc_meta_##field ) && \
strcasestr( input_item_GetMeta( p_item->p_input, vlc_meta_##field ), psz_string ) )
else
{
if( strcasestr( p_item->p_input->psz_name, psz_string ) ||
META_MATCHES( Artist ) || META_MATCHES( Album ) )
char *psz_name_matches, *psz_artist_matches, *psz_album_matches;
char *psz_field, *psz_field_case;
psz_field = input_item_GetName( p_i );
psz_name_matches = strcasestr( psz_field, psz_string );
free( psz_field );
psz_field = input_item_GetMeta( p_item->p_input, vlc_meta_Artist );
psz_field_case = strcasestr( input_item_GetMeta( p_item->p_input, vlc_meta_Artist ), psz_string );
psz_artist_matches = ( psz_field && psz_field_case );
free( psz_field );
free( psz_field_case );
psz_field = input_item_GetMeta( p_item->p_input, vlc_meta_Album );
psz_field_case = strcasestr( input_item_GetMeta( p_item->p_input, vlc_meta_Album ), psz_string );
psz_album_matches = ( psz_field && psz_field_case );
free( psz_field );
free( psz_field_case );
if( psz_name_matches || psz_artist_matches || psz_album_matches )
p_item->i_flags &= ~PLAYLIST_DBL_FLAG;
else
p_item->i_flags |= PLAYLIST_DBL_FLAG;

View File

@ -105,8 +105,8 @@ static int playlist_ItemArraySort( playlist_t *p_playlist, int i_items,
}
#define DO_META_SORT( node ) { \
const char *psz_a = input_item_GetMeta( pp_items[i]->p_input, vlc_meta_##node ); \
const char *psz_b = input_item_GetMeta( pp_items[i_small]->p_input, vlc_meta_##node ); \
char *psz_a = input_item_GetMeta( pp_items[i]->p_input, vlc_meta_##node ); \
char *psz_b = input_item_GetMeta( pp_items[i_small]->p_input, vlc_meta_##node ); \
/* Nodes go first */ \
if( pp_items[i]->i_children == -1 && pp_items[i_small]->i_children >= 0 ) \
i_test = 1;\
@ -198,5 +198,7 @@ static int playlist_ItemArraySort( playlist_t *p_playlist, int i_items,
pp_items[i_position] = pp_items[i_small];
pp_items[i_small] = p_temp;
}
free( psz_a );
free( psz_b );
return VLC_SUCCESS;
}