+ /* 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;
+
+ msg_Dbg( p_access, "track[%d] start=%d", i, p_sys->p_sectors[i] );
+
+ /* */
+ if( asprintf( &psz_uri, "cdda://%s", p_access->psz_path ) == -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;
+
+ /* Define a "default name" */
+ if( asprintf( &psz_name, _("Audio CD - Track %02i"), (i+1) ) == -1 )
+ psz_name = NULL;
+
+ /* 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( VLC_OBJECT( p_access ),
+ 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 );
+
+#ifdef HAVE_LIBCDDB
+ /* If we have CDDB info, change the name */
+ if( p_sys->p_disc )
+ {
+ cddb_track_t *t = cddb_disc_get_track( p_sys->p_disc, i );
+ if( t != NULL )
+ {
+ const char *psz_title = cddb_track_get_title( t );
+ const char *psz_artist = cddb_track_get_artist( t );
+
+ if( psz_title )
+ {
+ input_item_SetName( p_input_item, psz_title );
+ input_item_SetTitle( p_input_item, psz_title );
+ }
+ if( psz_artist )
+ input_item_SetArtist( p_input_item, psz_artist );
+ }
+ }
+#endif
+ input_item_AddSubItem( p_current, p_input_item );
+ vlc_gc_decref( p_input_item );
+ free( psz_uri ); free( psz_opt ); free( psz_name );
+ free( psz_first ); free( psz_last );
+ }