+
+static int GetTracks( access_t *p_access, vlc_bool_t b_separate,
+ playlist_t *p_playlist, playlist_item_t *p_parent )
+{
+ access_sys_t *p_sys = p_access->p_sys;
+ int i;
+ playlist_item_t *p_item;
+ p_sys->i_titles = ioctl_GetTracksMap( VLC_OBJECT(p_access),
+ p_sys->vcddev, &p_sys->p_sectors );
+ if( p_sys->i_titles < 0 )
+ {
+ msg_Err( p_access, "unable to count tracks" );
+ return VLC_EGENERIC;;
+ }
+ else if( p_sys->i_titles <= 0 )
+ {
+ msg_Err( p_access, "no audio tracks found" );
+ return VLC_EGENERIC;
+ }
+
+ if( b_separate )
+ {
+ if( p_parent->i_children == -1 )
+ {
+ playlist_LockItemToNode( p_playlist, p_parent );
+ }
+ }
+
+ /* Build title table */
+ for( i = 0; i < p_sys->i_titles; i++ )
+ {
+ msg_Dbg( p_access, "track[%d] start=%d", i, p_sys->p_sectors[i] );
+ if( !b_separate )
+ {
+ input_title_t *t = p_sys->title[i] = vlc_input_title_New();
+
+ asprintf( &t->psz_name, _("Track %i"), i + 1 );
+ t->i_size = ( p_sys->p_sectors[i+1] - p_sys->p_sectors[i] ) *
+ (int64_t)CDDA_DATA_SIZE;
+
+ t->i_length = I64C(1000000) * t->i_size / 44100 / 4;
+ }
+ else
+ {
+ char *psz_uri;
+ int i_path_len = p_access->psz_path ? strlen( p_access->psz_path )
+ : 0;
+ char *psz_name = malloc( strlen( _("Audio CD - Track ") ) + 5 );
+ char *psz_opt = (char*)malloc( 14 );
+
+ psz_uri = (char*)malloc( i_path_len + 13 );
+ snprintf( psz_uri, i_path_len + 13, "cdda://%s",
+ p_access->psz_path ? p_access->psz_path : "" );
+ snprintf( psz_name, 100, _("Audio CD - Track %i" ),
+ (i+1) );
+ snprintf( psz_opt, 14, "cdda-track=%i", i+1 );
+ /* Create playlist items */
+ p_item = playlist_ItemNewWithType( VLC_OBJECT( p_playlist ),
+ psz_uri, psz_name, ITEM_TYPE_DISC );
+ playlist_ItemAddOption( p_item, psz_opt );
+ playlist_NodeAddItem( p_playlist, p_item,
+ p_parent->pp_parents[0]->i_view,
+ p_parent, PLAYLIST_APPEND, PLAYLIST_END );
+ free( psz_uri ); free( psz_opt );
+ }
+ }
+
+ p_sys->i_sector = p_sys->p_sectors[0];
+ if( p_sys->b_separate_items )
+ {
+ p_sys->i_titles = 0;
+ }
+
+ return VLC_SUCCESS;
+}