Commit eb7a8935 authored by Rafaël Carré's avatar Rafaël Carré

Various bugfixes

Replaces gotos with #defines
Put duplicate code in #defines
Disables plugin by default
parent 3bed3c33
...@@ -1501,8 +1501,8 @@ dnl Audioscrobbler plugin ...@@ -1501,8 +1501,8 @@ dnl Audioscrobbler plugin
dnl dnl
AC_ARG_ENABLE(audioscrobbler, AC_ARG_ENABLE(audioscrobbler,
[ --enable-audioscrobbler Last.fm submission plugin (default enabled)]) [ --enable-audioscrobbler Last.fm submission plugin (default disabled)])
AS_IF([test "${enable_audioscrobbler}" != "no"], [ AS_IF([test "${enable_audioscrobbler}" = "yes"], [
VLC_ADD_PLUGINS([audioscrobbler]) VLC_ADD_PLUGINS([audioscrobbler])
]) ])
......
...@@ -22,6 +22,10 @@ ...@@ -22,6 +22,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
/* audioscrobbler protocol version: 1.1
* http://audioscrobbler.net/wiki/Protocol1.1
* */
/***************************************************************************** /*****************************************************************************
* Preamble * Preamble
*****************************************************************************/ *****************************************************************************/
...@@ -34,9 +38,7 @@ ...@@ -34,9 +38,7 @@
#endif #endif
/* /*
* TODO : * TODO :
* implement musicbrainz unique track identifier in p_meta
* check meta_engine's state, and remove delaying of metadata reading * check meta_engine's state, and remove delaying of metadata reading
* check md5 operations on BIGENDIAN and 64 bits architectures
*/ */
#include <vlc/vlc.h> #include <vlc/vlc.h>
#include <vlc/intf.h> #include <vlc/intf.h>
...@@ -52,7 +54,7 @@ ...@@ -52,7 +54,7 @@
* Local prototypes * Local prototypes
*****************************************************************************/ *****************************************************************************/
/* Keeps track of metadata to be submitted, and if song has been submitted */ /* Keeps track of metadata to be submitted */
typedef struct audioscrobbler_song_t typedef struct audioscrobbler_song_t
{ {
char *psz_a; /* track artist */ char *psz_a; /* track artist */
...@@ -78,7 +80,7 @@ struct intf_sys_t ...@@ -78,7 +80,7 @@ struct intf_sys_t
audioscrobbler_queue_t *p_first_queue; /* 1st queue */ audioscrobbler_queue_t *p_first_queue; /* 1st queue */
vlc_mutex_t lock; /* p_sys mutex */ vlc_mutex_t lock; /* p_sys mutex */
/* data about audioscrobbler session */ /* data about audioscrobbler session */
int i_interval; /* last interval recorded */ int i_interval; /* last interval recorded */
time_t time_last_interval; /* when was it recorded ? */ time_t time_last_interval; /* when was it recorded ? */
char *psz_submit_host; /* where to submit data ? */ char *psz_submit_host; /* where to submit data ? */
...@@ -86,16 +88,15 @@ struct intf_sys_t ...@@ -86,16 +88,15 @@ struct intf_sys_t
char *psz_submit_file; /* in which file ? */ char *psz_submit_file; /* in which file ? */
char *psz_username; /* last.fm username */ char *psz_username; /* last.fm username */
vlc_bool_t b_handshaked; /* did we handshake ? */ vlc_bool_t b_handshaked; /* did we handshake ? */
int i_post_socket; /* socket for submission */
char *psz_response_md5; /* md5 response to use */ char *psz_response_md5; /* md5 response to use */
/* data about input elements */ /* data about song currently playing */
audioscrobbler_song_t *p_current_song; /* song being played */ audioscrobbler_song_t *p_current_song; /* song being played */
time_t time_pause; /* time when vlc paused */ time_t time_pause; /* time when vlc paused */
time_t time_total_pauses; /* sum of time in pause */ time_t time_total_pauses; /* sum of time in pause */
vlc_bool_t b_queued; /* has it been queud ? */ vlc_bool_t b_queued; /* has it been queud ? */
vlc_bool_t b_metadata_read; /* did we read metadata ? */ vlc_bool_t b_metadata_read; /* did we read metadata ? */
vlc_bool_t b_paused; /* are we playing ? */ vlc_bool_t b_paused; /* is vlc paused ? */
vlc_bool_t b_waiting_meta; /* we need fetched data? */ vlc_bool_t b_waiting_meta; /* we need fetched data? */
}; };
...@@ -104,22 +105,20 @@ intf_sys_t *p_sys_global; /* to retrieve p_sys in Run() thread */ ...@@ -104,22 +105,20 @@ intf_sys_t *p_sys_global; /* to retrieve p_sys in Run() thread */
static int Open ( vlc_object_t * ); static int Open ( vlc_object_t * );
static void Close ( vlc_object_t * ); static void Close ( vlc_object_t * );
static void Run ( intf_thread_t * ); static void Run ( intf_thread_t * );
static int ItemChange ( vlc_object_t *, const char *, static int ItemChange ( vlc_object_t *, const char *, vlc_value_t,
vlc_value_t, vlc_value_t, void * ); vlc_value_t, void * );
static int PlayingChange( vlc_object_t *, const char *, static int PlayingChange( vlc_object_t *, const char *, vlc_value_t,
vlc_value_t, vlc_value_t, void * ); vlc_value_t, void * );
static int AddToQueue ( intf_thread_t *p_this ); static int AddToQueue ( intf_thread_t *p_this );
static int Handshake ( intf_thread_t *p_sd ); static int Handshake ( intf_thread_t *p_sd );
static int ReadMetaData ( intf_thread_t *p_this ); static int ReadMetaData ( intf_thread_t *p_this );
static int ReadLocalMetaData( intf_thread_t *p_this, input_thread_t *p_input ); static int ReadLocalMetaData( intf_thread_t *p_this, input_thread_t *p_input );
void DeleteQueue( audioscrobbler_queue_t *p_queue ); void DeleteQueue ( audioscrobbler_queue_t *p_queue );
/***************************************************************************** /*****************************************************************************
* Module descriptor * Module descriptor
****************************************************************************/ ****************************************************************************/
#define APPLICATION_NAME "VLC media player"
#define USERNAME_TEXT N_("Username") #define USERNAME_TEXT N_("Username")
#define USERNAME_LONGTEXT N_("The username of your last.fm account") #define USERNAME_LONGTEXT N_("The username of your last.fm account")
#define PASSWORD_TEXT N_("Password") #define PASSWORD_TEXT N_("Password")
...@@ -127,6 +126,7 @@ void DeleteQueue( audioscrobbler_queue_t *p_queue ); ...@@ -127,6 +126,7 @@ void DeleteQueue( audioscrobbler_queue_t *p_queue );
/* if something goes wrong, we wait at least one minute before trying again */ /* if something goes wrong, we wait at least one minute before trying again */
#define DEFAULT_INTERVAL 60 #define DEFAULT_INTERVAL 60
/* last.fm client identifier */ /* last.fm client identifier */
#define CLIENT_NAME PACKAGE #define CLIENT_NAME PACKAGE
#define CLIENT_VERSION VERSION #define CLIENT_VERSION VERSION
...@@ -144,8 +144,9 @@ void DeleteQueue( audioscrobbler_queue_t *p_queue ); ...@@ -144,8 +144,9 @@ void DeleteQueue( audioscrobbler_queue_t *p_queue );
"\r\n" "\r\n"
/* data to submit */ /* data to submit */
#define POST_DATA "u=%s&s=%s&a%%5B%d%%5D=%s&t%%5B%d%%5D=%s" \ #define POST_DATA "&a%%5B%d%%5D=%s&t%%5B%d%%5D=%s&b%%5B%d%%5D=%s" \
"&b%%5B%d%%5D=%s&m%%5B%d%%5D=%s&l%%5B%d%%5D=%d&i%%5B%d%%5D=%s" "&m%%5B%d%%5D=%s&l%%5B%d%%5D=%d&i%%5B%d%%5D=%s"
#define HTTPPOST_MAXLEN 2048
vlc_module_begin(); vlc_module_begin();
set_category( CAT_INTERFACE ); set_category( CAT_INTERFACE );
...@@ -167,13 +168,22 @@ vlc_module_end(); ...@@ -167,13 +168,22 @@ vlc_module_end();
static int Open( vlc_object_t *p_this ) static int Open( vlc_object_t *p_this )
{ {
playlist_t *p_playlist; playlist_t *p_playlist;
intf_thread_t *p_intf = ( intf_thread_t* ) p_this; intf_thread_t *p_intf = ( intf_thread_t* ) p_this;
intf_sys_t *p_sys = malloc( sizeof( intf_sys_t ) ); intf_sys_t *p_sys = malloc( sizeof( intf_sys_t ) );
#define MEM_ERROR \
free( p_sys->p_current_song ); \
free( p_sys->p_first_queue ); \
free( p_sys->psz_response_md5 ); \
free( p_sys ); \
return VLC_ENOMEM;
if( !p_sys ) if( !p_sys )
{ {
goto error; MEM_ERROR
} }
vlc_mutex_init( p_this, &p_sys->lock ); vlc_mutex_init( p_this, &p_sys->lock );
p_sys_global = p_sys; p_sys_global = p_sys;
...@@ -185,55 +195,41 @@ static int Open( vlc_object_t *p_this ) ...@@ -185,55 +195,41 @@ static int Open( vlc_object_t *p_this )
p_sys->psz_username = NULL; p_sys->psz_username = NULL;
p_sys->b_paused = VLC_FALSE; p_sys->b_paused = VLC_FALSE;
/* md5 response is 32 chars, + final \0 */ #define MALLOC_CHECK( a ) \
p_sys->psz_response_md5 = malloc( sizeof( char ) * 33 ); if( !a ) { \
if( !p_sys->psz_response_md5 ) vlc_mutex_destroy( &p_sys->lock ); \
{ MEM_ERROR \
vlc_mutex_destroy ( &p_sys->lock );
goto error;
} }
/* md5 response is 32 chars, + final \0 */
p_sys->psz_response_md5 = malloc( 33 );
MALLOC_CHECK( p_sys->psz_response_md5 )
p_sys->p_first_queue = malloc( sizeof( audioscrobbler_queue_t ) ); p_sys->p_first_queue = malloc( sizeof( audioscrobbler_queue_t ) );
if( !p_sys->p_first_queue ) MALLOC_CHECK( p_sys->p_first_queue )
{
vlc_mutex_destroy( &p_sys->lock );
goto error;
}
p_sys->p_current_song = malloc( sizeof( audioscrobbler_song_t ) ); p_sys->p_current_song = malloc( sizeof( audioscrobbler_song_t ) );
if( !p_sys->p_current_song ) MALLOC_CHECK( p_sys->p_current_song )
{
vlc_mutex_destroy( &p_sys->lock );
goto error;
}
/* queues can't contain more than 10 songs */ /* queues can't contain more than 10 songs */
p_sys->p_first_queue->p_queue = p_sys->p_first_queue->p_queue =
malloc( 10 * sizeof( audioscrobbler_song_t ) ); malloc( 10 * sizeof( audioscrobbler_song_t ) );
if( !p_sys->p_current_song ) MALLOC_CHECK( p_sys->p_current_song )
{
vlc_mutex_destroy( &p_sys->lock );
goto error;
}
p_sys->p_first_queue->i_songs_nb = 0; p_sys->p_first_queue->i_songs_nb = 0;
p_sys->p_first_queue->p_next_queue = NULL; p_sys->p_first_queue->p_next_queue = NULL;
p_playlist = pl_Yield( p_intf ); p_playlist = pl_Yield( p_intf );
PL_LOCK;
var_AddCallback( p_playlist, "playlist-current", ItemChange, p_intf ); var_AddCallback( p_playlist, "playlist-current", ItemChange, p_intf );
PL_UNLOCK;
pl_Release( p_playlist ); pl_Release( p_playlist );
p_intf->pf_run = Run; p_intf->pf_run = Run;
return VLC_SUCCESS; return VLC_SUCCESS;
#undef MEM_ERROR
error: #undef MALLOC_CHECK
free( p_sys->p_current_song );
free( p_sys->p_first_queue );
free( p_sys->psz_response_md5 );
free( p_sys );
return VLC_ENOMEM;
} }
/***************************************************************************** /*****************************************************************************
...@@ -244,15 +240,14 @@ static void Close( vlc_object_t *p_this ) ...@@ -244,15 +240,14 @@ static void Close( vlc_object_t *p_this )
audioscrobbler_queue_t *p_current_queue, *p_next_queue; audioscrobbler_queue_t *p_current_queue, *p_next_queue;
playlist_t *p_playlist; playlist_t *p_playlist;
input_thread_t *p_input; input_thread_t *p_input;
intf_thread_t *p_intf = ( intf_thread_t* ) p_this; intf_thread_t *p_intf = ( intf_thread_t* ) p_this;
intf_sys_t *p_sys = p_intf->p_sys; intf_sys_t *p_sys = p_intf->p_sys;
p_playlist = pl_Yield( p_intf ); p_playlist = pl_Yield( p_intf );
PL_LOCK; PL_LOCK;
p_input = p_playlist->p_input;
var_DelCallback( p_playlist, "playlist-current", ItemChange, p_intf ); var_DelCallback( p_playlist, "playlist-current", ItemChange, p_intf );
p_input = p_playlist->p_input;
if ( p_input ) if ( p_input )
{ {
vlc_object_yield( p_input ); vlc_object_yield( p_input );
...@@ -282,34 +277,55 @@ static void Close( vlc_object_t *p_this ) ...@@ -282,34 +277,55 @@ static void Close( vlc_object_t *p_this )
vlc_mutex_lock ( &p_sys->lock ); vlc_mutex_lock ( &p_sys->lock );
free( p_sys->psz_username ); free( p_sys->psz_username );
free( p_sys->p_current_song ); free( p_sys->p_current_song );
free( p_sys->psz_submit_host );
free( p_sys->psz_submit_file );
free( p_sys->psz_response_md5 );
vlc_mutex_unlock ( &p_sys->lock ); vlc_mutex_unlock ( &p_sys->lock );
vlc_mutex_destroy( &p_sys->lock ); vlc_mutex_destroy( &p_sys->lock );
free( p_sys ); free( p_sys );
} }
/***************************************************************************** /*****************************************************************************
* Run : Handshake with audioscrobbler, then submit songs * Run : call Handshake() then submit songs
*****************************************************************************/ *****************************************************************************/
static void Run( intf_thread_t *p_this ) static void Run( intf_thread_t *p_this )
{ {
char *psz_submit_string = NULL; char *psz_submit = NULL;
char *psz_submit_song = NULL;
int i_net_ret; int i_net_ret;
int i_song; int i_song;
playlist_t *p_playlist; playlist_t *p_playlist;
uint8_t *p_buffer = NULL; uint8_t *p_buffer = NULL;
char *p_buffer_pos = NULL; char *p_buffer_pos = NULL;
audioscrobbler_queue_t *p_first_queue; audioscrobbler_queue_t *p_first_queue;
int i_post_socket;
/* TODO: remove when meta_engine works */ /* TODO: remove when meta_engine works */
time_t played_time; time_t played_time;
p_this->p_sys = p_sys_global; p_this->p_sys = p_sys_global;
intf_sys_t *p_sys = p_this->p_sys; intf_sys_t *p_sys = p_this->p_sys;
#define MEM_ERROR \
free( psz_submit ); \
free( psz_submit_song ); \
free( p_buffer ); \
msg_Err( p_this, "Out of memory" ); \
return;
psz_submit = malloc( HTTPPOST_MAXLEN );
psz_submit_song = malloc( HTTPPOST_MAXLEN );
p_buffer = ( uint8_t* ) malloc( 1024 );
if( !psz_submit || !psz_submit_song || !p_buffer )
{
MEM_ERROR
}
/* main loop */ /* main loop */
while( !p_this->b_die ) while( !p_this->b_die )
{ {
/* verify if there is data to submit /* verify if there is data to submit
* and if waiting interval is finished */ * and if waiting interval is elapsed */
if ( ( p_sys->p_first_queue->i_songs_nb > 0 ) && if ( ( p_sys->p_first_queue->i_songs_nb > 0 ) &&
( time( NULL ) >= ( time( NULL ) >=
( p_sys->time_last_interval + p_sys->i_interval ) ) ) ( p_sys->time_last_interval + p_sys->i_interval ) ) )
...@@ -322,20 +338,21 @@ static void Run( intf_thread_t *p_this ) ...@@ -322,20 +338,21 @@ static void Run( intf_thread_t *p_this )
switch( Handshake( p_this ) ) switch( Handshake( p_this ) )
{ {
case VLC_ENOMEM: case VLC_ENOMEM:
msg_Err( p_this, "Out of memory" ); MEM_ERROR
return;
break; break;
case VLC_ENOVAR: case VLC_ENOVAR:
/* username not set */ /* username not set */
vlc_mutex_unlock ( &p_sys->lock ); vlc_mutex_unlock ( &p_sys->lock );
intf_UserFatal( p_this, VLC_FALSE, intf_UserFatal( p_this, VLC_FALSE,
_("last.fm username not set"), _("Last.fm username not set"),
_("You have to set a username," _("Please set an username or disable"
" and then restart VLC.\n" "audioscrobbler plugin, and then restart VLC.\n"
"Visit https://www.last.fm/join/" "Visit https://www.last.fm/join/ to get an account")
" if you don't have one.")
); );
free( psz_submit );
free( psz_submit_song );
free( p_buffer );
return; return;
break; break;
...@@ -348,7 +365,7 @@ static void Run( intf_thread_t *p_this ) ...@@ -348,7 +365,7 @@ static void Run( intf_thread_t *p_this )
case VLC_EGENERIC: case VLC_EGENERIC:
default: default:
/* VLC_EGENERIC : we'll try later */ /* protocol error : we'll try later */
vlc_mutex_lock ( &p_sys->lock ); vlc_mutex_lock ( &p_sys->lock );
p_sys->i_interval = DEFAULT_INTERVAL; p_sys->i_interval = DEFAULT_INTERVAL;
time( &p_sys->time_last_interval ); time( &p_sys->time_last_interval );
...@@ -359,21 +376,15 @@ static void Run( intf_thread_t *p_this ) ...@@ -359,21 +376,15 @@ static void Run( intf_thread_t *p_this )
msg_Dbg( p_this, "Going to submit some data..." ); msg_Dbg( p_this, "Going to submit some data..." );
vlc_mutex_lock ( &p_sys->lock ); vlc_mutex_lock ( &p_sys->lock );
psz_submit_string = malloc( 2048 * sizeof( char ) );
if (!psz_submit_string) snprintf( psz_submit, HTTPPOST_MAXLEN, "u=%s&s=%s",
{ p_sys->psz_username, p_sys->psz_response_md5 );
msg_Err( p_this, "Out of memory" );
vlc_mutex_unlock ( &p_sys->lock );
return;
}
/* forge the HTTP POST request */ /* forge the HTTP POST request */
for (i_song = 0; i_song < p_sys->p_first_queue->i_songs_nb ; for (i_song = 0 ; i_song < p_sys->p_first_queue->i_songs_nb ;
i_song++ ) i_song++ )
{ {
snprintf( psz_submit_string, 2048, POST_DATA, snprintf( psz_submit_song, HTTPPOST_MAXLEN -1, POST_DATA,
p_sys->psz_username, p_sys->psz_response_md5,
i_song, p_sys->p_first_queue->p_queue[i_song]->psz_a, i_song, p_sys->p_first_queue->p_queue[i_song]->psz_a,
i_song, p_sys->p_first_queue->p_queue[i_song]->psz_t, i_song, p_sys->p_first_queue->p_queue[i_song]->psz_t,
i_song, p_sys->p_first_queue->p_queue[i_song]->psz_b, i_song, p_sys->p_first_queue->p_queue[i_song]->psz_b,
...@@ -381,17 +392,18 @@ static void Run( intf_thread_t *p_this ) ...@@ -381,17 +392,18 @@ static void Run( intf_thread_t *p_this )
i_song, p_sys->p_first_queue->p_queue[i_song]->i_l, i_song, p_sys->p_first_queue->p_queue[i_song]->i_l,
i_song, p_sys->p_first_queue->p_queue[i_song]->psz_i i_song, p_sys->p_first_queue->p_queue[i_song]->psz_i
); );
strncat( psz_submit, psz_submit_song, HTTPPOST_MAXLEN - 1 );
} }
p_sys->i_post_socket = net_ConnectTCP( p_this, i_post_socket = net_ConnectTCP( p_this,
p_sys->psz_submit_host, p_sys->i_submit_port); p_sys->psz_submit_host, p_sys->i_submit_port);
/* we transmit the data */ /* we transmit the data */
i_net_ret = net_Printf( i_net_ret = net_Printf(
VLC_OBJECT(p_this), p_sys->i_post_socket, NULL, VLC_OBJECT(p_this), i_post_socket, NULL,
POST_REQUEST, p_sys->psz_submit_file, POST_REQUEST, p_sys->psz_submit_file,
strlen( psz_submit_string), p_sys->psz_submit_file, strlen( psz_submit ), p_sys->psz_submit_file,
VERSION, psz_submit_string VERSION, psz_submit
); );
if ( i_net_ret == -1 ) if ( i_net_ret == -1 )
...@@ -404,15 +416,9 @@ static void Run( intf_thread_t *p_this ) ...@@ -404,15 +416,9 @@ static void Run( intf_thread_t *p_this )
continue; continue;
} }
p_buffer = ( uint8_t* ) calloc( 1, 1024 ); memset( p_buffer, '\0', 1024 );
if ( !p_buffer )
{
msg_Err( p_this, "Out of memory" );
vlc_mutex_unlock ( &p_sys->lock );
return;
}
i_net_ret = net_Read( p_this, p_sys->i_post_socket, NULL, i_net_ret = net_Read( p_this, i_post_socket, NULL,
p_buffer, 1024, VLC_FALSE ); p_buffer, 1024, VLC_FALSE );
if ( i_net_ret <= 0 ) if ( i_net_ret <= 0 )
{ {
...@@ -421,7 +427,7 @@ static void Run( intf_thread_t *p_this ) ...@@ -421,7 +427,7 @@ static void Run( intf_thread_t *p_this )
continue; continue;
} }
net_Close( p_sys->i_post_socket ); net_Close( i_post_socket );
/* record interval */ /* record interval */
p_buffer_pos = strstr( ( char * ) p_buffer, "INTERVAL" ); p_buffer_pos = strstr( ( char * ) p_buffer, "INTERVAL" );
...@@ -435,7 +441,7 @@ static void Run( intf_thread_t *p_this ) ...@@ -435,7 +441,7 @@ static void Run( intf_thread_t *p_this )
p_buffer_pos = strstr( ( char * ) p_buffer, "FAILED" ); p_buffer_pos = strstr( ( char * ) p_buffer, "FAILED" );
if ( p_buffer_pos ) if ( p_buffer_pos )
{ {
/* woops, something failed */ /* woops, submission failed */
msg_Dbg( p_this, p_buffer_pos ); msg_Dbg( p_this, p_buffer_pos );
vlc_mutex_unlock ( &p_sys->lock ); vlc_mutex_unlock ( &p_sys->lock );
continue; continue;
...@@ -444,7 +450,6 @@ static void Run( intf_thread_t *p_this ) ...@@ -444,7 +450,6 @@ static void Run( intf_thread_t *p_this )
p_buffer_pos = strstr( ( char * ) p_buffer, "BADAUTH" ); p_buffer_pos = strstr( ( char * ) p_buffer, "BADAUTH" );
if ( p_buffer_pos ) if ( p_buffer_pos )
{ {
/* too much time elapsed after last handshake? */
msg_Dbg( p_this, "Authentification failed, handshaking again" ); msg_Dbg( p_this, "Authentification failed, handshaking again" );
p_sys->b_handshaked = VLC_FALSE; p_sys->b_handshaked = VLC_FALSE;
vlc_mutex_unlock ( &p_sys->lock ); vlc_mutex_unlock ( &p_sys->lock );
...@@ -478,19 +483,14 @@ static void Run( intf_thread_t *p_this ) ...@@ -478,19 +483,14 @@ static void Run( intf_thread_t *p_this )
PL_LOCK; PL_LOCK;
if( p_playlist->request.i_status == PLAYLIST_STOPPED ) if( p_playlist->request.i_status == PLAYLIST_STOPPED )
{ {
PL_UNLOCK;
pl_Release( p_playlist );
/* if we stopped, we won't submit playing song */ /* if we stopped, we won't submit playing song */
vlc_mutex_lock( &p_sys->lock ); vlc_mutex_lock( &p_sys->lock );
p_sys->b_queued = VLC_TRUE; p_sys->b_queued = VLC_TRUE;
p_sys->b_metadata_read = VLC_TRUE; p_sys->b_metadata_read = VLC_TRUE;
vlc_mutex_unlock( &p_sys->lock ); vlc_mutex_unlock( &p_sys->lock );
} }
else
{
PL_UNLOCK; PL_UNLOCK;
pl_Release( p_playlist ); pl_Release( p_playlist );
}
vlc_mutex_lock( &p_sys->lock ); vlc_mutex_lock( &p_sys->lock );
if( p_sys->b_metadata_read == VLC_FALSE ) if( p_sys->b_metadata_read == VLC_FALSE )
...@@ -508,8 +508,7 @@ static void Run( intf_thread_t *p_this ) ...@@ -508,8 +508,7 @@ static void Run( intf_thread_t *p_this )
{ {
if ( ReadMetaData( p_this ) == VLC_ENOMEM ) if ( ReadMetaData( p_this ) == VLC_ENOMEM )
{ {
msg_Err( p_this, "Out of memory" ); MEM_ERROR
return;
} }
} }
} }
...@@ -522,8 +521,7 @@ static void Run( intf_thread_t *p_this ) ...@@ -522,8 +521,7 @@ static void Run( intf_thread_t *p_this )
vlc_mutex_unlock( &p_sys->lock ); vlc_mutex_unlock( &p_sys->lock );
if( AddToQueue( p_this ) == VLC_ENOMEM ) if( AddToQueue( p_this ) == VLC_ENOMEM )
{ {
msg_Err( p_this, "Out of memory" ); MEM_ERROR
return;
} }
} }
else else
...@@ -532,6 +530,7 @@ static void Run( intf_thread_t *p_this ) ...@@ -532,6 +530,7 @@ static void Run( intf_thread_t *p_this )
} }
} }
} }
#undef MEM_ERROR
} }
/***************************************************************************** /*****************************************************************************
...@@ -545,6 +544,10 @@ static int PlayingChange( vlc_object_t *p_this, const char *psz_var, ...@@ -545,6 +544,10 @@ static int PlayingChange( vlc_object_t *p_this, const char *psz_var,
(void)p_this; (void)psz_var; (void)oldval; (void)p_this; (void)psz_var; (void)oldval;
/* don't bother if song has already been queued */
if( p_sys->b_queued == VLC_TRUE )
return VLC_SUCCESS;
vlc_mutex_lock( &p_sys->lock ); vlc_mutex_lock( &p_sys->lock );
if( newval.i_int == PAUSE_S ) if( newval.i_int == PAUSE_S )
...@@ -553,7 +556,7 @@ static int PlayingChange( vlc_object_t *p_this, const char *psz_var, ...@@ -553,7 +556,7 @@ static int PlayingChange( vlc_object_t *p_this, const char *psz_var,
p_sys->b_paused = VLC_TRUE; p_sys->b_paused = VLC_TRUE;
} }
if( newval.i_int == PLAYING_S ) else if( newval.i_int == PLAYING_S )
{ {
p_sys->time_total_pauses += time( NULL ) - p_sys->time_pause; p_sys->time_total_pauses += time( NULL ) - p_sys->time_pause;
p_sys->b_paused = VLC_FALSE; p_sys->b_paused = VLC_FALSE;
...@@ -575,11 +578,9 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var, ...@@ -575,11 +578,9 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
time_t epoch; time_t epoch;
struct tm *epoch_tm; struct tm *epoch_tm;
char psz_date[20]; char psz_date[20];
(void)p_this; (void)psz_var; (void)oldval; (void)newval;
intf_thread_t *p_intf = ( intf_thread_t* ) p_data; intf_thread_t *p_intf = ( intf_thread_t* ) p_data;
intf_sys_t *p_sys = p_intf->p_sys; intf_sys_t *p_sys = p_intf->p_sys;
(void)p_this; (void)psz_var; (void)oldval; (void)newval;
p_playlist = pl_Yield( p_intf ); p_playlist = pl_Yield( p_intf );
PL_LOCK; PL_LOCK;
...@@ -591,7 +592,6 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var, ...@@ -591,7 +592,6 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
pl_Release( p_playlist ); pl_Release( p_playlist );
vlc_mutex_lock( &p_sys->lock ); vlc_mutex_lock( &p_sys->lock );
/* we won't read p_input */
p_sys->b_queued = VLC_TRUE; p_sys->b_queued = VLC_TRUE;
p_sys->b_metadata_read = VLC_TRUE; p_sys->b_metadata_read = VLC_TRUE;
...@@ -639,37 +639,40 @@ static int AddToQueue ( intf_thread_t *p_this ) ...@@ -639,37 +639,40 @@ static int AddToQueue ( intf_thread_t *p_this )
{ {
int i_songs_nb; int i_songs_nb;
time_t played_time; time_t played_time;
audioscrobbler_queue_t *p_queue = NULL, *p_next_queue = NULL; audioscrobbler_queue_t *p_queue = NULL,
*p_next_queue = NULL;
intf_sys_t *p_sys = p_this->p_sys; intf_sys_t *p_sys = p_this->p_sys;
/* wait for the user to listen enough before submitting */ /* wait for the user to listen enough before submitting */
time ( &played_time ); time ( &played_time );
vlc_mutex_lock( &p_sys->lock );
played_time -= p_sys->p_current_song->time_playing; played_time -= p_sys->p_current_song->time_playing;
played_time -= p_sys->time_total_pauses; played_time -= p_sys->time_total_pauses;
vlc_mutex_lock( &p_sys->lock ); #define NO_SUBMISSION \
if( ( played_time < 240 ) p_sys->b_queued = VLC_TRUE; \
&& ( played_time < ( p_sys->p_current_song->i_l / 2 ) ) ) vlc_mutex_unlock( &p_sys->lock ); \
return VLC_SUCCESS;
if( ( played_time < 240 ) &&
( played_time < ( p_sys->p_current_song->i_l / 2 ) ) )
{ {
vlc_mutex_unlock ( &p_sys->lock ); //msg_Dbg( p_this, "Song not listened long enough -> waiting" );
vlc_mutex_unlock( &p_sys->lock );
return VLC_SUCCESS; return VLC_SUCCESS;
} }
if( p_sys->p_current_song->i_l < 30 ) if( p_sys->p_current_song->i_l < 30 )
{ {
msg_Dbg( p_this, "Song too short (< 30s) -> not submitting" ); msg_Dbg( p_this, "Song too short (< 30s) -> not submitting" );
p_sys->b_queued = VLC_TRUE; NO_SUBMISSION
vlc_mutex_unlock ( &p_sys->lock );
return VLC_SUCCESS;
} }
if( !*p_sys->p_current_song->psz_a || !*p_sys->p_current_song->psz_t ) if( !*p_sys->p_current_song->psz_a || !*p_sys->p_current_song->psz_t )
{ {
msg_Dbg( p_this, "Missing artist or title -> not submitting" ); msg_Dbg( p_this, "Missing artist or title -> not submitting" );
p_sys->b_queued = VLC_TRUE; NO_SUBMISSION
vlc_mutex_unlock ( &p_sys->lock );
return VLC_SUCCESS;
} }
msg_Dbg( p_this, "Ok. We'll put it in the queue for submission" ); msg_Dbg( p_this, "Ok. We'll put it in the queue for submission" );
...@@ -677,44 +680,38 @@ static int AddToQueue ( intf_thread_t *p_this ) ...@@ -677,44 +680,38 @@ static int AddToQueue ( intf_thread_t *p_this )
/* go to last queue */ /* go to last queue */
p_queue = p_sys->p_first_queue; p_queue = p_sys->p_first_queue;
while( ( p_queue->i_songs_nb == 10 ) && ( p_queue->p_next_queue != NULL ) ) while( ( p_queue->i_songs_nb == 10 ) && ( p_queue->p_next_queue != NULL ) )
{
p_queue = p_queue->p_next_queue; p_queue = p_queue->p_next_queue;
}
i_songs_nb = p_queue->i_songs_nb; i_songs_nb = p_queue->i_songs_nb;
#define MALLOC_CHECK( a ) \
if( !a ) { \
vlc_mutex_unlock( &p_sys->lock ); \
return VLC_ENOMEM; \
}
if( i_songs_nb == 10 ) if( i_songs_nb == 10 )
{ {
p_next_queue = malloc( sizeof( audioscrobbler_queue_t ) ); p_next_queue = malloc( sizeof( audioscrobbler_queue_t ) );
if( !p_next_queue ) MALLOC_CHECK( p_next_queue );
{
vlc_mutex_unlock ( &p_sys->lock );
return VLC_ENOMEM;
}
p_queue->p_next_queue = p_next_queue; p_queue->p_next_queue = p_next_queue;
i_songs_nb = 0;
p_queue = p_next_queue; p_queue = p_next_queue;
i_songs_nb = 0;
p_queue->i_songs_nb = i_songs_nb; p_queue->i_songs_nb = i_songs_nb;
} }
p_queue->p_queue[i_songs_nb] = malloc( sizeof( audioscrobbler_song_t ) ); p_queue->p_queue[i_songs_nb] = malloc( sizeof( audioscrobbler_song_t ) );
MALLOC_CHECK( p_queue->p_queue[i_songs_nb] );
p_queue->p_queue[i_songs_nb]->i_l = p_sys->p_current_song->i_l; #define QUEUE_COPY( a ) \
p_queue->p_queue[i_songs_nb]->a = p_sys->p_current_song->a
p_queue->p_queue[i_songs_nb]->psz_a =
strdup( p_sys->p_current_song->psz_a );
p_queue->p_queue[i_songs_nb]->psz_t =
strdup( p_sys->p_current_song->psz_t );
p_queue->p_queue[i_songs_nb]->psz_b = QUEUE_COPY(i_l);
strdup( p_sys->p_current_song->psz_b ); QUEUE_COPY(psz_a);
QUEUE_COPY(psz_t);
p_queue->p_queue[i_songs_nb]->psz_m = QUEUE_COPY(psz_b);
strdup( p_sys->p_current_song->psz_m ); QUEUE_COPY(psz_m);
QUEUE_COPY(psz_i);
p_queue->p_queue[i_songs_nb]->psz_i =
strdup( p_sys->p_current_song->psz_i );
p_queue->i_songs_nb++; p_queue->i_songs_nb++;
p_sys->b_queued = VLC_TRUE; p_sys->b_queued = VLC_TRUE;
...@@ -722,6 +719,9 @@ static int AddToQueue ( intf_thread_t *p_this ) ...@@ -722,6 +719,9 @@ static int AddToQueue ( intf_thread_t *p_this )
vlc_mutex_unlock( &p_sys->lock ); vlc_mutex_unlock( &p_sys->lock );
return VLC_SUCCESS; return VLC_SUCCESS;
#undef QUEUE_COPY
#undef MALLOC_CHECK
#undef NO_SUBMISSION
} }
/***************************************************************************** /*****************************************************************************
...@@ -733,14 +733,12 @@ static int Handshake( intf_thread_t *p_this ) ...@@ -733,14 +733,12 @@ static int Handshake( intf_thread_t *p_this )
struct md5_s *p_struct_md5 = NULL; struct md5_s *p_struct_md5 = NULL;
char *psz_password_md5 = NULL; char *psz_password_md5 = NULL;
char *ps_challenge_md5 = NULL; char *ps_challenge_md5 = NULL;
stream_t *p_stream; stream_t *p_stream;
char *psz_handshake_url = NULL; char *psz_handshake_url = NULL;
uint8_t *p_buffer = NULL; uint8_t *p_buffer = NULL;
char *p_buffer_pos = NULL; char *p_buffer_pos = NULL;
char *psz_buffer_substring = NULL;
char *psz_url_parser = NULL; char *psz_url_parser = NULL;
char *psz_buffer_substring;
int i_url_pos, i; int i_url_pos, i;
intf_thread_t *p_intf = ( intf_thread_t* ) p_this; intf_thread_t *p_intf = ( intf_thread_t* ) p_this;
...@@ -748,22 +746,33 @@ static int Handshake( intf_thread_t *p_this ) ...@@ -748,22 +746,33 @@ static int Handshake( intf_thread_t *p_this )
vlc_mutex_lock ( &p_sys->lock ); vlc_mutex_lock ( &p_sys->lock );
p_sys->psz_username = config_GetPsz(p_this, "lastfm-username"); #define MEM_ERROR \
if ( !p_sys->psz_username ) free( p_buffer ); \
{ free( p_struct_md5 ); \
goto memerror; free( ps_challenge_md5 ); \
vlc_mutex_unlock( &p_sys->lock ); \
return VLC_ENOMEM;
#define PROTOCOL_ERROR \
free( p_buffer ); \
vlc_mutex_unlock( &p_sys->lock ); \
return VLC_EGENERIC;
#define MALLOC_CHECK( a ) \
if( !a ) \
{ \
MEM_ERROR \
} }
p_sys->psz_username = config_GetPsz(p_this, "lastfm-username");
MALLOC_CHECK( p_sys->psz_username )
/* username has not been setup, ignoring */
if ( !*p_sys->psz_username ) if ( !*p_sys->psz_username )
{
return VLC_ENOVAR; return VLC_ENOVAR;
}
psz_handshake_url = malloc( 1024 ); psz_handshake_url = malloc( 1024 );
if ( !psz_handshake_url ) MALLOC_CHECK( p_sys->psz_username )
{
goto memerror;
}
snprintf( psz_handshake_url, 1024, snprintf( psz_handshake_url, 1024,
"http://post.audioscrobbler.com/?hs=true&p=1.1&c=%s&v=%s&u=%s", "http://post.audioscrobbler.com/?hs=true&p=1.1&c=%s&v=%s&u=%s",
...@@ -784,107 +793,102 @@ static int Handshake( intf_thread_t *p_this ) ...@@ -784,107 +793,102 @@ static int Handshake( intf_thread_t *p_this )
if ( !p_buffer ) if ( !p_buffer )
{ {
stream_Delete( p_stream ); stream_Delete( p_stream );
goto memerror; MEM_ERROR
} }
/* read answer */ /* read answer */
if ( stream_Read( p_stream, p_buffer, 1024 ) == 0 ) if ( stream_Read( p_stream, p_buffer, 1024 ) == 0 )
{ {
stream_Delete( p_stream ); stream_Delete( p_stream );
goto generic_error; PROTOCOL_ERROR
} }
stream_Delete( p_stream ); stream_Delete( p_stream );
/* record interval before next submission */ /* record interval before next submission */
p_buffer_pos = strstr( ( char * ) p_buffer, "INTERVAL" ); p_buffer_pos = strstr( ( char* ) p_buffer, "INTERVAL" );
if ( p_buffer_pos ) if ( p_buffer_pos )
{ {
p_sys->i_interval = atoi( p_buffer_pos + strlen( "INTERVAL " ) ); p_sys->i_interval = atoi( p_buffer_pos + strlen( "INTERVAL " ) );
time( &p_sys->time_last_interval ); time( &p_sys->time_last_interval );
} }
p_buffer_pos = strstr( ( char * ) p_buffer, "FAILED" ); p_buffer_pos = strstr( ( char* ) p_buffer, "FAILED" );
if ( p_buffer_pos ) if ( p_buffer_pos )
{ {
/* handshake request failed */ /* handshake request failed, sorry */
msg_Dbg( p_this, p_buffer_pos ); msg_Dbg( p_this, p_buffer_pos );
goto generic_error; PROTOCOL_ERROR
} }
p_buffer_pos = strstr( ( char * ) p_buffer, "BADUSER" ); p_buffer_pos = strstr( ( char* ) p_buffer, "BADUSER" );
if ( p_buffer_pos ) if ( p_buffer_pos )
{ {
/* username does not exist */ /* username does not exist on the server */
intf_UserFatal( p_this, VLC_FALSE, _("Bad last.fm Username"), intf_UserFatal( p_this, VLC_FALSE, _("Bad last.fm Username"),
_("last.fm username is incorrect, please verify your settings") _("last.fm username is incorrect, please verify your settings")
); );
goto generic_error; PROTOCOL_ERROR
} }
p_buffer_pos = strstr( ( char * ) p_buffer, "UPDATE" ); p_buffer_pos = strstr( ( char* ) p_buffer, "UPDATE" );
if ( p_buffer_pos ) if ( p_buffer_pos )
{ {
/* protocol has been updated, developers need to work :) */ /* protocol has been updated, time to update the code */
msg_Dbg( p_intf, "Protocol updated" ); msg_Dbg( p_intf, "Protocol updated : plugin may be outdated" );
msg_Dbg( p_intf, p_buffer_pos ); msg_Dbg( p_intf, p_buffer_pos );
} }
else else
{ {
p_buffer_pos = strstr( ( char * ) p_buffer, "UPTODATE" ); p_buffer_pos = strstr( ( char* ) p_buffer, "UPTODATE" );
if ( !p_buffer_pos ) if ( !p_buffer_pos )
{ {
msg_Dbg( p_intf, "Protocol error" ); msg_Dbg( p_intf, "Can't recognize server protocol" );
goto generic_error; PROTOCOL_ERROR
} }
} }
psz_buffer_substring = strndup( strstr( p_buffer_pos, "\n" ) + 1, 32 ); psz_buffer_substring = strstr( p_buffer_pos, "\n" );
if ( !psz_buffer_substring ) if( ( psz_buffer_substring == NULL ) || \
( strlen( psz_buffer_substring + 1 ) < 32 ) )
{ {
goto memerror; msg_Dbg( p_intf, "Can't recognize server protocol" );
PROTOCOL_ERROR
} }
else else
{ {
ps_challenge_md5 = malloc( sizeof( char ) * 32 ); ps_challenge_md5 = malloc( 32 );
if ( !ps_challenge_md5 ) MALLOC_CHECK( ps_challenge_md5 )
{ memcpy( ps_challenge_md5, psz_buffer_substring + 1, 32 );
goto memerror;
}
memcpy( ps_challenge_md5, psz_buffer_substring, 32 );
free( psz_buffer_substring );
} }
p_buffer_pos = ( void* ) strstr( ( char* ) p_buffer, "http://" ); p_buffer_pos = ( void* ) strstr( ( char* ) p_buffer, "http://" );
/* free old information */
free( p_sys->psz_submit_host ); free( p_sys->psz_submit_host );
free( p_sys->psz_submit_file ); free( p_sys->psz_submit_file );
psz_url_parser = p_buffer_pos + strlen( "http://" ); psz_url_parser = p_buffer_pos + strlen( "http://" );
i_url_pos = strcspn( psz_url_parser, ":" ); i_url_pos = strcspn( psz_url_parser, ":" );
p_sys->psz_submit_host = strndup( psz_url_parser, i_url_pos ); p_sys->psz_submit_host = strndup( psz_url_parser, i_url_pos );
MALLOC_CHECK( p_sys->psz_submit_host )
p_sys->i_submit_port = atoi( psz_url_parser + i_url_pos + 1 ); p_sys->i_submit_port = atoi( psz_url_parser + i_url_pos + 1 );
psz_url_parser += strcspn( psz_url_parser , "/" ) + 1; psz_url_parser += strcspn( psz_url_parser , "/" ) + 1;
i_url_pos = strcspn( psz_url_parser, "\n" ); i_url_pos = strcspn( psz_url_parser, "\n" );
p_sys->psz_submit_file = strndup( psz_url_parser, i_url_pos ); p_sys->psz_submit_file = strndup( psz_url_parser, i_url_pos );
MALLOC_CHECK( p_sys->psz_submit_file )
free(p_buffer); free(p_buffer);
p_struct_md5 = malloc( sizeof( struct md5_s ) ); p_struct_md5 = malloc( sizeof( struct md5_s ) );
if( !p_struct_md5 ) MALLOC_CHECK( p_struct_md5 )
{
goto memerror;
}
psz_password = config_GetPsz(p_this, "lastfm-password"); psz_password = config_GetPsz(p_this, "lastfm-password");
if ( !psz_password ) MALLOC_CHECK( psz_password )
{
goto memerror;
}
/* generates a md5 hash of the password */ /* generates a md5 hash of the password */
InitMD5( p_struct_md5 ); InitMD5( p_struct_md5 );
...@@ -893,11 +897,8 @@ static int Handshake( intf_thread_t *p_this ) ...@@ -893,11 +897,8 @@ static int Handshake( intf_thread_t *p_this )
free( psz_password ); free( psz_password );
psz_password_md5 = malloc ( 33 * sizeof( char ) ); psz_password_md5 = malloc ( 33 );
if ( !psz_password_md5 ) MALLOC_CHECK( psz_password_md5 )
{
goto memerror;
}
for ( i = 0; i < 4; i++ ) for ( i = 0; i < 4; i++ )
{ {
...@@ -910,7 +911,7 @@ static int Handshake( intf_thread_t *p_this ) ...@@ -910,7 +911,7 @@ static int Handshake( intf_thread_t *p_this )
} }
/* generates a md5 hash of : /* generates a md5 hash of :
* - md5 hash of the password * - md5 hash of the password, plus
* - md5 challenge sent by last.fm server * - md5 challenge sent by last.fm server
*/ */
InitMD5( p_struct_md5 ); InitMD5( p_struct_md5 );
...@@ -931,24 +932,14 @@ static int Handshake( intf_thread_t *p_this ) ...@@ -931,24 +932,14 @@ static int Handshake( intf_thread_t *p_this )
); );
} }
p_sys->psz_response_md5[32] = 0; p_sys->psz_response_md5[32] = '\0';
vlc_mutex_unlock ( &p_sys->lock ); vlc_mutex_unlock ( &p_sys->lock );
return VLC_SUCCESS; return VLC_SUCCESS;
#undef MEM_ERROR
generic_error: #undef PROTOCOL_ERROR
free( p_buffer ); #undef MALLOC_CHECK
vlc_mutex_unlock( &p_sys->lock );
return VLC_EGENERIC;
memerror:
free( p_buffer );
free( p_struct_md5 );
free( psz_buffer_substring );
vlc_mutex_unlock( &p_sys->lock );
return VLC_ENOMEM;
} }
/***************************************************************************** /*****************************************************************************
...@@ -999,7 +990,7 @@ static int ReadMetaData( intf_thread_t *p_this ) ...@@ -999,7 +990,7 @@ static int ReadMetaData( intf_thread_t *p_this )
if( ( video_val.i_int > 0 ) || \ if( ( video_val.i_int > 0 ) || \
( p_input->input.p_item->i_type == ITEM_TYPE_NET ) ) ( p_input->input.p_item->i_type == ITEM_TYPE_NET ) )
{ {
msg_Dbg( p_this, "Not an audio file -> no submission"); msg_Dbg( p_this, "Not an audio only local file -> no submission");
vlc_object_release( p_input ); vlc_object_release( p_input );
vlc_mutex_lock( &p_sys->lock ); vlc_mutex_lock( &p_sys->lock );
...@@ -1024,93 +1015,77 @@ static int ReadLocalMetaData( intf_thread_t *p_this, input_thread_t *p_input ) ...@@ -1024,93 +1015,77 @@ static int ReadLocalMetaData( intf_thread_t *p_this, input_thread_t *p_input )
char *psz_trackid = NULL; char *psz_trackid = NULL;
int i_length = -1; int i_length = -1;
vlc_bool_t b_waiting; vlc_bool_t b_waiting;
int i_status;
intf_sys_t *p_sys = p_this->p_sys; intf_sys_t *p_sys = p_this->p_sys;
int i_status;
i_status = p_input->input.p_item->p_meta->i_status; i_status = p_input->input.p_item->p_meta->i_status;
#define FREE_INPUT_AND_CHARS \
vlc_object_release( p_input ); \
free( psz_title ); \
free( psz_artist ); \
free( psz_album ); \
free( psz_trackid );
#define WAIT_METADATA_FETCHING( a ) \
if ( b_waiting == VLC_TRUE ) \
{ \
a = calloc( 1, 1 ); \
} \
else \
{ \
vlc_object_release( p_input ); \
vlc_mutex_lock( &p_sys->lock ); \
p_sys->b_waiting_meta = VLC_TRUE; \
vlc_mutex_unlock( &p_sys->lock ); \
free( psz_artist ); \
return VLC_SUCCESS; \
}
#define ALLOC_ITEM_META( a, b ) \
if ( p_input->input.p_item->b ) \
{ \
a = encode_URI_component( \
p_input->input.p_item->b ); \
if( !a ) \
{ \
FREE_INPUT_AND_CHARS \
return VLC_ENOMEM; \
} \
}
vlc_mutex_lock( &p_sys->lock ); vlc_mutex_lock( &p_sys->lock );
b_waiting = p_sys->b_waiting_meta; b_waiting = p_sys->b_waiting_meta;
vlc_mutex_unlock( &p_sys->lock ); vlc_mutex_unlock( &p_sys->lock );
/* TODO : remove if (1) when meta_engine works */ /* TODO : replace 1 with ( i_status & ITEM_PREPARSED )
if ( (1/*( i_status & ITEM_PREPARSED )*/&& ( b_waiting == VLC_FALSE ) ) || \ * when meta_engine works */
( ( i_status & ITEM_META_FETCHED ) && ( b_waiting == VLC_TRUE ) ) ) if ( ( b_waiting == VLC_FALSE ) ? 1 : ( i_status & ITEM_META_FETCHED ) )
{
if ( p_input->input.p_item->p_meta->psz_artist )
{ {
psz_artist = encode_URI_component( ALLOC_ITEM_META( psz_artist, p_meta->psz_artist )
p_input->input.p_item->p_meta->psz_artist );
if ( !psz_artist )
{
goto error;
}
}
else else
{ {
msg_Dbg( p_this, "No artist.." ); msg_Dbg( p_this, "No artist.." );
if ( b_waiting == VLC_TRUE ) WAIT_METADATA_FETCHING( psz_artist )
{
psz_artist = calloc( 1, sizeof( char ) );
}
else
{
goto waiting_meta_data_fetching;
}
}
if ( p_input->input.p_item->psz_name )
{
psz_title = encode_URI_component( p_input->input.p_item->psz_name );
if ( !psz_title )
{
goto error;
}
} }
ALLOC_ITEM_META( psz_title, psz_name )
else else
{ {
msg_Dbg( p_this, "No track name.." ); msg_Dbg( p_this, "No track name.." );
if ( b_waiting == VLC_TRUE ) WAIT_METADATA_FETCHING( psz_title );
{
psz_title = calloc( 1, sizeof( char ) );
}
else
{
goto waiting_meta_data_fetching;
}
} }
if ( p_input->input.p_item->p_meta->psz_trackid ) ALLOC_ITEM_META( psz_album, p_meta->psz_album )
{
psz_trackid = strdup( p_input->input.p_item->p_meta->psz_trackid );
if ( !psz_trackid )
{
goto error;
}
}
else else
{ psz_album = calloc( 1, 1 );
psz_trackid = calloc( 1, sizeof( char ) );
}
if ( p_input->input.p_item->p_meta->psz_album ) ALLOC_ITEM_META( psz_trackid, p_meta->psz_trackid )
{
psz_album = encode_URI_component(
p_input->input.p_item->p_meta->psz_album );
if ( !psz_album )
{
goto error;
}
}
else else
{ psz_trackid = calloc( 1, 1 );
psz_album = calloc( 1, sizeof( char ) );
}
i_length = p_input->input.p_item->i_duration / 1000000; i_length = p_input->input.p_item->i_duration / 1000000;
vlc_object_release( p_input );
vlc_mutex_lock ( &p_sys->lock ); vlc_mutex_lock ( &p_sys->lock );
p_sys->p_current_song->psz_a = strdup( psz_artist ); p_sys->p_current_song->psz_a = strdup( psz_artist );
...@@ -1121,39 +1096,16 @@ static int ReadLocalMetaData( intf_thread_t *p_this, input_thread_t *p_input ) ...@@ -1121,39 +1096,16 @@ static int ReadLocalMetaData( intf_thread_t *p_this, input_thread_t *p_input )
p_sys->b_queued = VLC_FALSE; p_sys->b_queued = VLC_FALSE;
p_sys->b_metadata_read = VLC_TRUE; p_sys->b_metadata_read = VLC_TRUE;
vlc_mutex_unlock ( &p_sys->lock ); vlc_mutex_unlock( &p_sys->lock );
msg_Dbg( p_this, "Meta data registered, waiting to be queued" ); msg_Dbg( p_this, "Meta data registered, waiting to be queued" );
free( psz_title ); FREE_INPUT_AND_CHARS
free( psz_artist );
free( psz_album );
free( psz_trackid );
return VLC_SUCCESS;
} }
return VLC_SUCCESS;
waiting_meta_data_fetching:
vlc_object_release( p_input ); vlc_object_release( p_input );
vlc_mutex_lock( &p_sys->lock );
p_sys->b_waiting_meta = VLC_TRUE;
vlc_mutex_unlock( &p_sys->lock );
free( psz_artist );
free( psz_album );
free( psz_title );
return VLC_SUCCESS; return VLC_SUCCESS;
#undef FREE_INPUT_AND_CHARS
error: #undef ALLOC_ITEM_META
vlc_object_release( p_input ); #undef WAIT_METADATA_FETCHING
free( psz_artist );
free( psz_album );
free( psz_title );
free( psz_trackid );
return VLC_ENOMEM;
} }
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