X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Faccess%2Fcdda.c;h=e798d2191e06b5eb808a279a11b0463fedf2d401;hb=943b5ccc082784273bc21baa216527a605fc8e04;hp=2ddfa822324ddfc634db6baff3698d1381f2e922;hpb=d3fe7f28797d4dba65ffcdd60bf932e758a48a9e;p=vlc diff --git a/modules/access/cdda.c b/modules/access/cdda.c index 2ddfa82232..e798d2191e 100644 --- a/modules/access/cdda.c +++ b/modules/access/cdda.c @@ -31,16 +31,22 @@ /***************************************************************************** * Preamble *****************************************************************************/ -#define _GNU_SOURCE -#include -#include +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include #include #include +#include +#include #include /* For WAVEHEADER */ #include "vcd/cdrom.h" +#warning playlist code must not be used here. #include #ifdef HAVE_LIBCDDB @@ -63,30 +69,30 @@ static void Close( vlc_object_t * ); "value should be set in milliseconds." ) vlc_module_begin(); - set_shortname( _("Audio CD")); - set_description( _("Audio CD input") ); - set_capability( "access2", 10 ); + set_shortname( N_("Audio CD")); + set_description( N_("Audio CD input") ); + set_capability( "access", 10 ); set_category( CAT_INPUT ); set_subcategory( SUBCAT_INPUT_ACCESS ); set_callbacks( Open, Close ); add_usage_hint( N_("[cdda:][device][@[track]]") ); add_integer( "cdda-caching", DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT, - CACHING_LONGTEXT, VLC_TRUE ); + CACHING_LONGTEXT, true ); - add_integer( "cdda-track", -1 , NULL, NULL, NULL, VLC_TRUE ); + add_integer( "cdda-track", -1 , NULL, NULL, NULL, true ); change_internal(); - add_integer( "cdda-first-sector", -1, NULL, NULL, NULL, VLC_TRUE ); + add_integer( "cdda-first-sector", -1, NULL, NULL, NULL, true ); change_internal(); - add_integer( "cdda-last-sector", -1, NULL, NULL, NULL, VLC_TRUE ); + add_integer( "cdda-last-sector", -1, NULL, NULL, NULL, true ); change_internal(); add_string( "cddb-server", "freedb.freedb.org", NULL, N_( "CDDB Server" ), N_( "Address of the CDDB server to use." ), - VLC_TRUE ); + true ); add_integer( "cddb-port", 8880, NULL, N_( "CDDB port" ), N_( "CDDB Server port to use." ), - VLC_TRUE ); + true ); add_shortcut( "cdda" ); add_shortcut( "cddasimple" ); vlc_module_end(); @@ -109,7 +115,7 @@ struct access_sys_t /* Wave header for the output data */ WAVEHEADER waveheader; - vlc_bool_t b_header; + bool b_header; int i_track; int i_first_sector; @@ -141,10 +147,6 @@ static int Open( vlc_object_t *p_this ) vcddev_t *vcddev; char *psz_name; int i_mrl_tracknum = -1; - - input_thread_t *p_input; - playlist_item_t *p_item = NULL; - playlist_t *p_playlist = NULL; int i_ret; if( !p_access->psz_path || !*p_access->psz_path ) @@ -155,11 +157,11 @@ static int Open( vlc_object_t *p_this ) psz_name = var_CreateGetString( p_this, "cd-audio" ); if( !psz_name || !*psz_name ) { - if( psz_name ) free( psz_name ); + free( psz_name ); return VLC_EGENERIC; } } - else psz_name = strdup( p_access->psz_path ); + else psz_name = ToLocaleDup( p_access->psz_path ); #ifdef WIN32 if( psz_name[0] && psz_name[1] == ':' && @@ -179,36 +181,38 @@ static int Open( vlc_object_t *p_this ) STANDARD_BLOCK_ACCESS_INIT p_sys->vcddev = vcddev; - /* We only do separate items if the whole disc is requested - - * Dirty hack we access some private data ! */ - p_input = (input_thread_t *)( p_access->p_parent ); - /* Do we play a single track ? */ p_sys->i_track = var_CreateGetInteger( p_access, "cdda-track" ); if( p_sys->i_track < 0 && i_mrl_tracknum <= 0 ) { - p_playlist = pl_Yield( p_access ); - if( p_playlist->status.p_item->p_input == - input_GetItem( (input_thread_t *)p_access->p_parent)) - p_item = p_playlist->status.p_item; - else - { - input_item_t *p_current = input_GetItem( - (input_thread_t*)p_access->p_parent); - p_item = playlist_ItemGetByInput( p_playlist, p_current, VLC_FALSE ); + /* We only do separate items if the whole disc is requested */ + playlist_t *p_playlist = pl_Yield( p_access ); - if( !p_item ) + i_ret = -1; + if( p_playlist ) + { + input_thread_t *p_input = (input_thread_t*)vlc_object_find( p_access, VLC_OBJECT_INPUT, FIND_PARENT ); + if( p_input ) { - msg_Dbg( p_playlist, "unable to find item in playlist"); - return -1; + input_item_t *p_current = input_GetItem( p_input ); + playlist_item_t *p_item; + + if( p_playlist->status.p_item->p_input == p_current ) + p_item = p_playlist->status.p_item; + else + p_item = playlist_ItemGetByInput( p_playlist, p_current, pl_Unlocked ); + + if( p_item ) + i_ret = GetTracks( p_access, p_playlist, p_item ); + else + msg_Dbg( p_playlist, "unable to find item in playlist"); + vlc_object_release( p_input ); } + pl_Release( p_access ); } - - i_ret = GetTracks( p_access, p_playlist, p_item ); - - if( p_playlist ) vlc_object_release( p_playlist ); - if( i_ret < 0 ) goto error; + if( i_ret < 0 ) + goto error; } else { @@ -261,7 +265,6 @@ static int Open( vlc_object_t *p_this ) error: ioctl_Close( VLC_OBJECT(p_access), p_sys->vcddev ); free( p_sys ); - if( p_playlist ) vlc_object_release( p_playlist ); return VLC_EGENERIC; } @@ -285,7 +288,7 @@ static block_t *Block( access_t *p_access ) int i_blocks = CDDA_BLOCKS_ONCE; block_t *p_block; - if( p_sys->i_track < 0 ) p_access->info.b_eof = VLC_TRUE; + if( p_sys->i_track < 0 ) p_access->info.b_eof = true; /* Check end of file */ if( p_access->info.b_eof ) return NULL; @@ -295,13 +298,13 @@ static block_t *Block( access_t *p_access ) /* Return only the header */ p_block = block_New( p_access, sizeof( WAVEHEADER ) ); memcpy( p_block->p_buffer, &p_sys->waveheader, sizeof(WAVEHEADER) ); - p_sys->b_header = VLC_TRUE; + p_sys->b_header = true; return p_block; } if( p_sys->i_sector >= p_sys->i_last_sector ) { - p_access->info.b_eof = VLC_TRUE; + p_access->info.b_eof = true; return NULL; } @@ -355,7 +358,7 @@ static int Seek( access_t *p_access, int64_t i_pos ) *****************************************************************************/ static int Control( access_t *p_access, int i_query, va_list args ) { - vlc_bool_t *pb_bool; + bool *pb_bool; int *pi_int; int64_t *pi_64; @@ -365,8 +368,8 @@ static int Control( access_t *p_access, int i_query, va_list args ) case ACCESS_CAN_FASTSEEK: case ACCESS_CAN_PAUSE: case ACCESS_CAN_CONTROL_PACE: - pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* ); - *pb_bool = VLC_TRUE; + pb_bool = (bool*)va_arg( args, bool* ); + *pb_bool = true; break; case ACCESS_GET_MTU: @@ -385,6 +388,7 @@ static int Control( access_t *p_access, int i_query, va_list args ) case ACCESS_GET_META: case ACCESS_SET_SEEKPOINT: case ACCESS_SET_PRIVATE_ID_STATE: + case ACCESS_GET_CONTENT_TYPE: return VLC_EGENERIC; default: @@ -416,13 +420,9 @@ static int GetTracks( access_t *p_access, return VLC_EGENERIC; } - p_item_in_category = playlist_ItemToNode( p_playlist, p_parent, VLC_FALSE ); - psz_name = strdup( "Audio CD" ); - vlc_mutex_lock( &p_playlist->object_lock ); - playlist_ItemSetName( p_parent, psz_name ); - vlc_mutex_unlock( &p_playlist->object_lock ); + p_item_in_category = playlist_ItemToNode( p_playlist, p_parent, pl_Unlocked ); + playlist_ItemSetName( p_parent, "Audio CD" ); var_SetInteger( p_playlist, "item-change", p_parent->p_input->i_id ); - free( psz_name ); #ifdef HAVE_LIBCDDB GetCDDBInfo( p_access, i_titles, p_sys->p_sectors ); @@ -430,13 +430,10 @@ static int GetTracks( access_t *p_access, { if( cddb_disc_get_title( p_sys->p_disc ) ) { - asprintf( &psz_name, "%s", cddb_disc_get_title( p_sys->p_disc ) ); - vlc_mutex_lock( &p_playlist->object_lock ); + const char *psz_name = cddb_disc_get_title( p_sys->p_disc ); playlist_ItemSetName( p_parent, psz_name ); - vlc_mutex_unlock( &p_playlist->object_lock ); var_SetInteger( p_playlist, "item-change", p_parent->p_input->i_id ); - free( psz_name ); } } #endif @@ -479,33 +476,31 @@ static int GetTracks( access_t *p_access, /* If we have CDDB info, change the name */ if( p_sys->p_disc ) { - char *psz_result; cddb_track_t *t = cddb_disc_get_track( p_sys->p_disc, i ); if( t!= NULL ) { if( cddb_track_get_title( t ) != NULL ) { - input_ItemAddInfo( p_input_item, _(VLC_META_INFO_CAT), - _(VLC_META_TITLE), - cddb_track_get_title( t ) ); - if( p_input_item->psz_name ) - free( p_input_item->psz_name ); - asprintf( &p_input_item->psz_name, "%s", - cddb_track_get_title( t ) ); + free( p_input_item->psz_name ); + p_input_item->psz_name = strdup( cddb_track_get_title( t ) ); + input_item_SetTitle( p_input_item, cddb_track_get_title( t ) ); } - psz_result = cddb_track_get_artist( t ); - if( psz_result ) + if( cddb_track_get_artist( t ) != NULL ) { - input_ItemAddInfo( p_input_item, _(VLC_META_INFO_CAT), - _(VLC_META_ARTIST), psz_result ); + input_item_SetArtist( p_input_item, cddb_track_get_artist( t ) ); } } } #endif - playlist_BothAddInput( p_playlist, p_input_item, p_item_in_category, - PLAYLIST_APPEND, PLAYLIST_END, NULL, NULL ); + int i_ret = playlist_BothAddInput( p_playlist, p_input_item, + p_item_in_category, + PLAYLIST_APPEND, PLAYLIST_END, NULL, NULL, + pl_Unlocked ); + vlc_gc_decref( p_input_item ); free( psz_uri ); free( psz_opt ); free( psz_name ); free( psz_first ); free( psz_last ); + if( i_ret != VLC_SUCCESS ) + return VLC_EGENERIC; } return VLC_SUCCESS; } @@ -523,9 +518,11 @@ static void GetCDDBInfo( access_t *p_access, int i_titles, int *p_sectors ) goto cddb_destroy; } + char* psz_tmp = config_GetPsz( p_access, "cddb-server" ); cddb_set_email_address( p_cddb, "vlc@videolan.org" ); - cddb_set_server_name( p_cddb, config_GetPsz( p_access, "cddb-server" ) ); + cddb_set_server_name( p_cddb, psz_tmp ); cddb_set_server_port( p_cddb, config_GetInt( p_access, "cddb-port" ) ); + free( psz_tmp ); /// \todo cddb_cache_disable( p_cddb ); @@ -554,7 +551,7 @@ static void GetCDDBInfo( access_t *p_access, int i_titles, int *p_sectors ) cddb_disc_add_track( p_access->p_sys->p_disc, t ); i_size = ( p_sectors[i+1] - p_sectors[i] ) * (int64_t)CDDA_DATA_SIZE; - i_length += I64C(1000000) * i_size / 44100 / 4 ; + i_length += INT64_C(1000000) * i_size / 44100 / 4 ; } cddb_disc_set_length( p_access->p_sys->p_disc, (int)(i_length/1000000) );