static int Open( vlc_object_t *p_this )
{
access_t *p_access = (access_t*)p_this;
- access_sys_t *p_sys;
vcddev_t *vcddev;
char *psz_name;
psz_name[2] == '\\' && psz_name[3] == '\0' ) psz_name[2] = '\0';
#endif
- /* Open CDDA */
- if( (vcddev = ioctl_Open( VLC_OBJECT(p_access), psz_name ) ) == NULL )
+ access_sys_t *p_sys = calloc( 1, sizeof (*p_sys) );
+ if( unlikely(p_sys == NULL) )
{
- msg_Warn( p_access, "could not open %s", psz_name );
free( psz_name );
- return VLC_EGENERIC;
+ return VLC_ENOMEM;
}
+ p_access->p_sys = p_sys;
+
+ /* Open CDDA */
+ vcddev = ioctl_Open( VLC_OBJECT(p_access), psz_name );
+ if( vcddev == NULL )
+ msg_Warn( p_access, "could not open %s", psz_name );
free( psz_name );
+ if( vcddev == NULL )
+ {
+ free( p_sys );
+ return VLC_EGENERIC;
+ }
- /* Set up p_access */
- STANDARD_BLOCK_ACCESS_INIT
p_sys->vcddev = vcddev;
/* Do we play a single track ? */
* (int64_t)CDDA_DATA_SIZE;
}
+ /* Set up p_access */
+ access_InitFields( p_access );
+ ACCESS_SET_CALLBACKS( NULL, Block, Control, Seek );
return VLC_SUCCESS;
error:
cddb_disc_t *p_disc = GetCDDBInfo( p_access, i_titles, p_sys->p_sectors );
if( p_disc )
{
+ msg_Dbg( p_access, "Disc ID: %08x", cddb_disc_get_discid( p_disc ) );
psz_album = cddb_disc_get_title( p_disc );
psz_genre = cddb_disc_get_genre( p_disc );
psz_artist = psz_track_artist;
}
}
+ else
+ msg_Dbg( p_access, "GetCDDBInfo failed" );
#endif
/* CD-Text */
/* Build title table */
for( int i = 0; i < i_titles; i++ )
{
- input_item_t *p_input_item;
-
- char *psz_uri, *psz_opt, *psz_first, *psz_last;
- char *psz_name;
+ char *psz_uri, *psz_opt, *psz_name;
msg_Dbg( p_access, "track[%d] start=%d", i, p_sys->p_sectors[i] );
- /* */
if( asprintf( &psz_uri, "cdda://%s", p_access->psz_location ) == -1 )
- psz_uri = NULL;
- if( asprintf( &psz_opt, "cdda-track=%i", i+1 ) == -1 )
- psz_opt = NULL;
- if( asprintf( &psz_first, "cdda-first-sector=%i",p_sys->p_sectors[i] ) == -1 )
- psz_first = NULL;
- if( asprintf( &psz_last, "cdda-last-sector=%i", p_sys->p_sectors[i+1] ) == -1 )
- psz_last = NULL;
+ continue;
/* Define a "default name" */
if( asprintf( &psz_name, _("Audio CD - Track %02i"), (i+1) ) == -1 )
- psz_name = NULL;
+ psz_name = psz_uri;
/* Create playlist items */
const mtime_t i_duration = (int64_t)( p_sys->p_sectors[i+1] - p_sys->p_sectors[i] ) *
CDDA_DATA_SIZE * 1000000 / 44100 / 2 / 2;
- p_input_item = input_item_NewWithType( psz_uri, psz_name, 0, NULL, 0,
- i_duration, ITEM_TYPE_DISC );
- input_item_CopyOptions( p_current, p_input_item );
- input_item_AddOption( p_input_item, psz_first, VLC_INPUT_OPTION_TRUSTED );
- input_item_AddOption( p_input_item, psz_last, VLC_INPUT_OPTION_TRUSTED );
- input_item_AddOption( p_input_item, psz_opt, VLC_INPUT_OPTION_TRUSTED );
+
+ input_item_t *p_item = input_item_NewWithType( psz_uri, psz_name, 0,
+ NULL, 0, i_duration, ITEM_TYPE_DISC );
+ if( likely(psz_name != psz_uri) )
+ free( psz_name );
+ free( psz_uri );
+
+ if( unlikely(p_item == NULL) )
+ continue;
+
+ input_item_CopyOptions( p_current, p_item );
+
+ if( likely(asprintf( &psz_opt, "cdda-track=%i", i+1 ) != -1) )
+ {
+ input_item_AddOption( p_item, psz_opt, VLC_INPUT_OPTION_TRUSTED );
+ free( psz_opt );
+ }
+ if( likely(asprintf( &psz_opt, "cdda-first-sector=%i",
+ p_sys->p_sectors[i] ) != -1) )
+ {
+ input_item_AddOption( p_item, psz_opt, VLC_INPUT_OPTION_TRUSTED );
+ free( psz_opt );
+ }
+ if( likely(asprintf( &psz_opt, "cdda-last-sector=%i",
+ p_sys->p_sectors[i+1] ) != -1) )
+ {
+ input_item_AddOption( p_item, psz_opt, VLC_INPUT_OPTION_TRUSTED );
+ free( psz_opt );
+ }
const char *psz_track_title = NULL;
const char *psz_track_artist = NULL;
/* */
if( NONEMPTY( psz_track_title ) )
{
- input_item_SetName( p_input_item, psz_track_title );
- input_item_SetTitle( p_input_item, psz_track_title );
+ input_item_SetName( p_item, psz_track_title );
+ input_item_SetTitle( p_item, psz_track_title );
}
if( NONEMPTY( psz_track_artist ) )
- input_item_SetArtist( p_input_item, psz_track_artist );
+ input_item_SetArtist( p_item, psz_track_artist );
if( NONEMPTY( psz_track_genre ) )
- input_item_SetGenre( p_input_item, psz_track_genre );
+ input_item_SetGenre( p_item, psz_track_genre );
if( NONEMPTY( psz_track_description ) )
- input_item_SetDescription( p_input_item, psz_track_description );
+ input_item_SetDescription( p_item, psz_track_description );
if( NONEMPTY( psz_album ) )
- input_item_SetAlbum( p_input_item, psz_album );
+ input_item_SetAlbum( p_item, psz_album );
if( NONEMPTY( psz_year ) )
- input_item_SetDate( p_input_item, psz_year );
+ input_item_SetDate( p_item, psz_year );
char psz_num[3+1];
snprintf( psz_num, sizeof(psz_num), "%d", 1+i );
- input_item_SetTrackNum( p_input_item, psz_num );
+ input_item_SetTrackNum( p_item, psz_num );
- input_item_node_AppendItem( p_root, p_input_item );
- vlc_gc_decref( p_input_item );
- free( psz_uri ); free( psz_opt ); free( psz_name );
- free( psz_first ); free( psz_last );
+ input_item_node_AppendItem( p_root, p_item );
+ vlc_gc_decref( p_item );
}
#undef ON_EMPTY
#undef NONEMPTY
#ifdef HAVE_LIBCDDB
static cddb_disc_t *GetCDDBInfo( access_t *p_access, int i_titles, int *p_sectors )
{
- if( var_InheritInteger( p_access, "album-art" ) == ALBUM_ART_WHEN_ASKED )
+ if( var_InheritInteger( p_access, "album-art" ) != ALBUM_ART_ALL &&
+ ! var_InheritBool( p_access, "metadata-network-access" ) )
+ {
+ msg_Dbg( p_access, "Album art policy set to manual; no automatic fetching" );
return NULL;
+ }
/* */
cddb_conn_t *p_cddb = cddb_new();
goto error;
}
- int64_t i_length = 0;
+ int64_t i_length = 2000000; /* PreGap */
for( int i = 0; i < i_titles; i++ )
{
cddb_track_t *t = cddb_track_new();
- cddb_track_set_frame_offset( t, p_sectors[i] );
+ cddb_track_set_frame_offset( t, p_sectors[i] + 150 ); /* Pregap offset */
+
cddb_disc_add_track( p_disc, t );
const int64_t i_size = ( p_sectors[i+1] - p_sectors[i] ) *
(int64_t)CDDA_DATA_SIZE;
i_length += INT64_C(1000000) * i_size / 44100 / 4 ;
+
+ msg_Dbg( p_access, "Track %i offset: %i", i, p_sectors[i] + 150 );
}
+ msg_Dbg( p_access, "Total length: %i", (int)(i_length/1000000) );
cddb_disc_set_length( p_disc, (int)(i_length/1000000) );
if( !cddb_disc_calc_discid( p_disc ) )