1 /*****************************************************************************
2 * cddax.c : CD digital audio input module for vlc using libcdio
3 *****************************************************************************
4 * Copyright (C) 2000,2003 VideoLAN
5 * $Id: access.c,v 1.8 2003/12/02 01:54:30 rocky Exp $
7 * Authors: Rocky Bernstein <rocky@panix.com>
8 * Laurent Aimar <fenrir@via.ecp.fr>
9 * Gildas Bazin <gbazin@netcourrier.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
35 #include <sys/types.h>
36 #include <cdio/cdio.h>
37 #include <cdio/cd_types.h>
50 /* how many blocks Open will read in each loop */
51 #define CDDA_BLOCKS_ONCE 1
52 #define CDDA_DATA_ONCE (CDDA_BLOCKS_ONCE * CDIO_CD_FRAMESIZE_RAW)
54 #define CDDA_MRL_PREFIX "cddax://"
56 /* FIXME: This variable is a hack. Would be nice to eliminate. */
57 static input_thread_t *p_cdda_input = NULL;
59 /*****************************************************************************
61 *****************************************************************************/
62 static int CDDARead ( input_thread_t *, byte_t *, size_t );
63 static void CDDASeek ( input_thread_t *, off_t );
64 static int CDDASetArea ( input_thread_t *, input_area_t * );
65 static int CDDASetProgram ( input_thread_t *, pgrm_descriptor_t * );
67 static int CDDAFixupPlayList( input_thread_t *p_input,
68 cdda_data_t *p_cdda, const char *psz_source,
69 bool play_single_track);
71 /****************************************************************************
73 ****************************************************************************/
76 E_(DebugCallback) ( vlc_object_t *p_this, const char *psz_name,
77 vlc_value_t oldval, vlc_value_t val, void *p_data )
81 if (NULL == p_cdda_input) return VLC_EGENERIC;
83 p_cdda = (cdda_data_t *)p_cdda_input->p_access_data;
85 if (p_cdda->i_debug & (INPUT_DBG_CALL|INPUT_DBG_EXT)) {
86 msg_Dbg( p_cdda_input, "Old debug (x%0x) %d, new debug (x%0x) %d",
87 p_cdda->i_debug, p_cdda->i_debug, val.i_int, val.i_int);
89 p_cdda->i_debug = val.i_int;
93 /* process messages that originate from libcdio. */
95 cdio_log_handler (cdio_log_level_t level, const char message[])
97 cdda_data_t *p_cdda = (cdda_data_t *)p_cdda_input->p_access_data;
101 if (p_cdda->i_debug & INPUT_DBG_CDIO)
102 msg_Dbg( p_cdda_input, message);
105 msg_Warn( p_cdda_input, message);
108 case CDIO_LOG_ASSERT:
109 msg_Err( p_cdda_input, message);
112 msg_Warn( p_cdda_input, message,
113 _("The above message had unknown vcdimager log level"),
121 /*! This routine is called by libcddb routines on error.
122 Setup is done by init_input_plugin.
125 cddb_log_handler (cddb_log_level_t level, const char message[])
127 cdda_data_t *p_cdda = (cdda_data_t *)p_cdda_input->p_access_data;
131 if (!(p_cdda->i_debug & INPUT_DBG_CDDB)) return;
132 /* Fall through if to warn case */
134 cdio_log_handler (level, message);
137 #endif /*HAVE_LIBCDDB*/
140 /*! This routine is when xine is not fully set up (before full initialization)
141 or is not around (before finalization).
144 uninit_log_handler (cdio_log_level_t level, const char message[])
146 cdda_data_t *p_cdda = (cdda_data_t *)p_cdda_input->p_access_data;
150 if (!(p_cdda->i_debug & (INPUT_DBG_CDIO|INPUT_DBG_CDDB)))
152 /* Fall through if to warn case */
154 fprintf(stderr, "WARN: %s\n", message);
157 fprintf(stderr, "ERROR: %s\n", message);
159 case CDIO_LOG_ASSERT:
160 fprintf(stderr, "ASSERT ERROR: %s\n", message);
163 fprintf(stderr, "UNKNOWN ERROR: %s\n%s %d\n",
165 _("The above message had unknown cdio log level"),
169 /* gl_default_cdio_log_handler (level, message); */
172 /*****************************************************************************
174 *****************************************************************************/
176 E_(Open)( vlc_object_t *p_this )
178 input_thread_t * p_input = (input_thread_t *)p_this;
182 cdda_data_t * p_cdda;
186 bool play_single_track = false;
188 /* Set where to log errors messages from libcdio. */
189 p_cdda_input = (input_thread_t *)p_this;
191 /* parse the options passed in command line : */
192 psz_orig = psz_parser = psz_source = strdup( p_input->psz_name );
199 while( *psz_parser && *psz_parser != '@' )
204 if( *psz_parser == '@' )
210 if ('T' == *psz_parser || 't' == *psz_parser )
213 i_track = (int)strtol( psz_parser, NULL, 10 );
214 i_track = i_track ? i_track : 1;
215 play_single_track = true;
219 /* No source specified, so figure it out. */
220 if( !p_input->psz_access ) {
224 psz_source = config_GetPsz( p_input, MODULE_STRING "-device" );
226 if( !psz_source || 0==strlen(psz_source) ) {
227 /* Scan for a CD-ROM drive with a CD-DA in it. */
229 cdio_get_devices_with_cap(NULL, CDIO_FS_AUDIO, false);
230 if (NULL == cd_drives) return -1;
231 if (cd_drives[0] == NULL) {
232 cdio_free_device_list(cd_drives);
235 psz_source = strdup(cd_drives[0]);
236 cdio_free_device_list(cd_drives);
241 cdio_log_set_handler ( cdio_log_handler );
243 cddb_log_set_handler ( cddb_log_handler );
246 if( !(p_cddev = ioctl_Open( p_this, psz_source )) )
248 msg_Warn( p_input, "could not open %s", psz_source );
253 p_cdda = malloc( sizeof(cdda_data_t) );
256 msg_Err( p_input, "out of memory" );
261 p_cdda->p_cddev = p_cddev;
262 p_cdda->i_debug = config_GetInt( p_this, MODULE_STRING "-debug" );
263 p_input->p_access_data = (void *)p_cdda;
265 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "%s", psz_source );
267 p_input->i_mtu = CDDA_DATA_ONCE;
269 /* We read the Table Of Content information */
270 p_cdda->i_nb_tracks = ioctl_GetTracksMap( VLC_OBJECT(p_input),
271 p_cdda->p_cddev->cdio, &p_cdda->p_sectors );
272 if( p_cdda->i_nb_tracks < 0 )
273 msg_Err( p_input, "unable to count tracks" );
274 else if( p_cdda->i_nb_tracks <= 0 )
275 msg_Err( p_input, "no audio tracks found" );
277 if( p_cdda->i_nb_tracks <= 1)
279 ioctl_Close( p_cdda->p_cddev );
285 if( i_track >= p_cdda->i_nb_tracks || i_track < 1 )
288 /* Set stream and area data */
289 vlc_mutex_lock( &p_input->stream.stream_lock );
291 /* Initialize ES structures */
292 input_InitStream( p_input, 0 );
294 /* cdda input method */
295 p_input->stream.i_method = INPUT_METHOD_CDDA;
297 p_input->stream.b_pace_control = 1;
298 p_input->stream.b_seekable = 1;
299 p_input->stream.i_mux_rate = 44100 * 4 / 50;
301 #define area p_input->stream.pp_areas
302 for( i = 1 ; i <= p_cdda->i_nb_tracks ; i++ )
304 input_AddArea( p_input, i, 1 );
306 /* Absolute start offset and size */
308 (off_t)p_cdda->p_sectors[i-1] * (off_t)CDIO_CD_FRAMESIZE_RAW;
310 (off_t)(p_cdda->p_sectors[i] - p_cdda->p_sectors[i-1])
311 * (off_t)CDIO_CD_FRAMESIZE_RAW;
315 CDDAPlay( p_input, i_track);
317 CDDAFixupPlayList(p_input, p_cdda, psz_source, play_single_track);
319 vlc_mutex_unlock( &p_input->stream.stream_lock );
321 if( !p_input->psz_demux || !*p_input->psz_demux )
323 p_input->psz_demux = "cdda";
326 p_input->pf_read = CDDARead;
327 p_input->pf_seek = CDDASeek;
328 p_input->pf_set_area = CDDASetArea;
329 p_input->pf_set_program = CDDASetProgram;
331 /* Update default_pts to a suitable value for cdda access */
332 p_input->i_pts_delay = config_GetInt( p_input,
333 MODULE_STRING "-caching" ) * 1000;
335 p_cdda->p_intf = intf_Create( p_input, "cddax" );
336 intf_RunThread( p_cdda->p_intf );
342 /*****************************************************************************
343 * CDDAPlay: Arrange things so we play the specified track.
344 * VLC_TRUE is returned if there was no error.
345 *****************************************************************************/
347 CDDAPlay( input_thread_t *p_input, int i_track )
349 cdda_data_t *p_cdda = (cdda_data_t *) p_input->p_access_data;
351 if( i_track >= p_cdda->i_nb_tracks || i_track < 1 )
354 CDDASetArea( p_input, p_input->stream.pp_areas[i_track] );
358 /*****************************************************************************
359 * CDDAClose: closes cdda
360 *****************************************************************************/
362 E_(Close)( vlc_object_t *p_this )
364 input_thread_t * p_input = (input_thread_t *)p_this;
365 cdda_data_t *p_cdda = (cdda_data_t *)p_input->p_access_data;
367 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "" );
368 ioctl_Close( p_cdda->p_cddev );
370 cdio_log_set_handler (uninit_log_handler);
373 cddb_log_set_handler (uninit_log_handler);
374 if (p_cdda->i_cddb_enabled)
375 cddb_disc_destroy(p_cdda->cddb.disc);
382 /*****************************************************************************
383 * CDDARead: reads from the CDDA into PES packets.
384 *****************************************************************************
385 * Returns -1 in case of error, 0 in case of EOF, otherwise the number of
387 *****************************************************************************/
388 static int CDDARead( input_thread_t * p_input, byte_t * p_buffer,
391 cdda_data_t * p_cdda;
396 p_cdda = (cdda_data_t *)p_input->p_access_data;
400 /* Compute the number of blocks we have to read */
402 i_blocks = i_len / CDIO_CD_FRAMESIZE_RAW;
404 for ( i_index = 0; i_index < i_blocks; i_index++ )
407 if (cdio_read_audio_sector(p_cdda->p_cddev->cdio, p_buffer,
408 p_cdda->i_sector) != 0)
410 msg_Err( p_input, "could not read sector %d", p_cdda->i_sector );
415 if ( p_cdda->i_sector == p_cdda->p_sectors[p_cdda->i_track + 1] )
417 input_area_t *p_area;
419 dbg_print( (INPUT_DBG_LSN|INPUT_DBG_CALL),
420 "end of track, cur: %u", p_cdda->i_sector );
422 /*???? if ( p_cdda->i_track >= p_cdda->i_nb_tracks - 1 )*/
425 vlc_mutex_lock( &p_input->stream.stream_lock );
426 p_area = p_input->stream.pp_areas[
427 p_input->stream.p_selected_area->i_id + 1 ];
430 CDDASetArea( p_input, p_area );
431 vlc_mutex_unlock( &p_input->stream.stream_lock );
433 i_read += CDIO_CD_FRAMESIZE_RAW;
436 if ( i_len % CDIO_CD_FRAMESIZE_RAW ) /* this should not happen */
438 msg_Err( p_input, "must read full sectors" );
444 /*****************************************************************************
445 * CDDASetProgram: Does nothing since a CDDA is mono_program
446 *****************************************************************************/
447 static int CDDASetProgram( input_thread_t * p_input,
448 pgrm_descriptor_t * p_program)
450 cdda_data_t * p_cdda= (cdda_data_t *) p_input->p_access_data;
451 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "" );
455 /*****************************************************************************
456 * CDDASetArea: initialize input data for title x.
457 * It should be called for each user navigation request.
458 ****************************************************************************/
459 static int CDDASetArea( input_thread_t * p_input, input_area_t * p_area )
461 cdda_data_t *p_cdda = (cdda_data_t*) p_input->p_access_data;
464 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "");
466 /* we can't use the interface slider until initilization is complete */
467 p_input->stream.b_seekable = 0;
469 if( p_area != p_input->stream.p_selected_area )
471 /* Change the default area */
472 p_input->stream.p_selected_area = p_area;
474 /* Change the current track */
475 p_cdda->i_track = p_area->i_id - 1;
476 p_cdda->i_sector = p_cdda->p_sectors[p_cdda->i_track];
478 /* Update the navigation variables without triggering a callback */
479 val.i_int = p_area->i_id;
480 var_Change( p_input, "title", VLC_VAR_SETVALUE, &val, NULL );
483 p_cdda->i_sector = p_cdda->p_sectors[p_cdda->i_track];
485 p_input->stream.p_selected_area->i_tell =
486 (off_t)p_cdda->i_sector * (off_t)CDIO_CD_FRAMESIZE_RAW
487 - p_input->stream.p_selected_area->i_start;
489 /* warn interface that something has changed */
490 p_input->stream.b_seekable = 1;
491 p_input->stream.b_changed = 1;
496 /****************************************************************************
498 ****************************************************************************/
499 static void CDDASeek( input_thread_t * p_input, off_t i_off )
501 cdda_data_t * p_cdda;
503 p_cdda = (cdda_data_t *) p_input->p_access_data;
505 p_cdda->i_sector = p_cdda->p_sectors[p_cdda->i_track]
506 + i_off / (off_t)CDIO_CD_FRAMESIZE_RAW;
508 vlc_mutex_lock( &p_input->stream.stream_lock );
509 p_input->stream.p_selected_area->i_tell =
510 (off_t)p_cdda->i_sector * (off_t)CDIO_CD_FRAMESIZE_RAW
511 - p_input->stream.p_selected_area->i_start;
513 vlc_mutex_unlock( &p_input->stream.stream_lock );
515 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_SEEK),
516 "sector %ud, offset: %lld, i_tell: %lld", p_cdda->i_sector, i_off,
517 p_input->stream.p_selected_area->i_tell );
521 #define meta_info_add_str(title, str) \
523 printf("field %s str %s\n", title, str); \
524 input_AddInfo( p_cat, _(title), "%s", str ); \
528 static void InformationCreate( input_thread_t *p_input )
530 cdda_data_t *p_cdda = (cdda_data_t *) p_input->p_access_data;
531 input_info_category_t *p_cat;
532 int use_cddb = p_cdda->i_cddb_enabled;
534 p_cat = input_InfoCategory( p_input, "General" );
539 if( p_cdda->cddb.disc->length > 1000 )
541 int64_t i_sec = (int64_t) p_cdda->cddb.disc->length;
542 char psz_buffer[MSTRTIME_MAX_SIZE];
543 input_AddInfo( p_cat, _("Duration"), "%s",
544 secstotimestr( psz_buffer, i_sec ) );
550 meta_info_add_str( "Title", p_cdda->cddb.disc->title );
551 meta_info_add_str( "Artist", p_cdda->cddb.disc->artist );
552 meta_info_add_str( "Genre", p_cdda->cddb.disc->genre );
553 meta_info_add_str( "Extended Data", p_cdda->cddb.disc->ext_data );
556 if (p_cdda->cddb.disc->year != 0) {
557 snprintf(year, 5, "%d", p_cdda->cddb.disc->year);
558 meta_info_add_str( "Year", year );
560 if ( p_cdda->cddb.disc->discid ) {
561 input_AddInfo( p_cat, _("CDDB Disc ID"), "%x",
562 p_cdda->cddb.disc->discid );
565 if ( p_cdda->cddb.disc->category != CDDB_CAT_INVALID ) {
566 input_AddInfo( p_cat, _("CDDB Disc Category"), "%s",
567 CDDB_CATEGORY[p_cdda->cddb.disc->category] );
573 #endif /*HAVE_LIBCDDB*/
577 track_t i_track = p_cdda->i_nb_tracks;
578 char psz_buffer[MSTRTIME_MAX_SIZE];
580 (p_cdda->p_sectors[i_track] - p_cdda->p_sectors[i_track-1])
581 / CDIO_CD_FRAMES_PER_SEC;
583 input_AddInfo( p_cat, _("Duration"), "%s",
584 secstotimestr( psz_buffer, i_duration ) );
591 #define free_and_dup(var, val) \
592 if (var) free(var); \
593 if (val) var=strdup(val);
597 GetCDDBInfo( const input_thread_t *p_input, cdda_data_t *p_cdda )
600 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "" );
602 if (config_GetInt( p_input, MODULE_STRING "-cddb-enabled" )) {
604 cddb_conn_t *conn = cddb_new();
605 const CdIo *cdio = p_cdda->p_cddev->cdio;
608 cddb_log_set_handler (uninit_log_handler);
611 msg_Warn( p_input, "unable to initialize libcddb" );
615 cddb_set_email_address( conn,
616 config_GetPsz( p_input,
617 MODULE_STRING "-cddb-email") );
619 cddb_set_server_name( conn,
620 config_GetPsz( p_input,
621 MODULE_STRING "-cddb-server") );
623 cddb_set_server_port(conn,
624 config_GetInt( p_input,
625 MODULE_STRING "-cddb-port") );
627 /* Set the location of the local CDDB cache directory.
628 The default location of this directory is */
630 if (!config_GetInt( p_input, MODULE_STRING "-cddb-enable-cache" ))
631 cddb_cache_disable(conn);
633 cddb_cache_set_dir(conn,
634 config_GetPsz( p_input,
635 MODULE_STRING "-cddb-cachedir") );
637 cddb_set_timeout(conn,
638 config_GetInt( p_input, MODULE_STRING "-cddb-timeout") );
641 if (config_GetInt( p_input, MODULE_STRING "-cddb-httpd" )) {
642 cddb_http_enable(conn);
644 cddb_http_disable(conn);
646 p_cdda->cddb.disc = cddb_disc_new();
647 if (!p_cdda->cddb.disc) {
648 msg_Err( p_input, "Unable to create CDDB disc structure." );
652 for(i = 1; i <= p_cdda->i_nb_tracks; i++) {
653 cddb_track_t *t = cddb_track_new();
654 t->frame_offset = cdio_get_track_lba(cdio, i);
655 cddb_disc_add_track(p_cdda->cddb.disc, t);
658 p_cdda->cddb.disc->length =
659 cdio_get_track_lba(cdio, CDIO_CDROM_LEADOUT_TRACK)
660 / CDIO_CD_FRAMES_PER_SEC;
663 if (!cddb_disc_calc_discid(p_cdda->cddb.disc)) {
664 msg_Err( p_input, "CDDB disc calc failed" );
668 i_matches = cddb_query(conn, p_cdda->cddb.disc);
671 msg_Warn( p_input, "Found %d matches in CDDB. Using first one.",
673 cddb_read(conn, p_cdda->cddb.disc);
675 if (p_cdda->i_debug & INPUT_DBG_CDDB)
676 cddb_disc_print(p_cdda->cddb.disc);
679 msg_Warn( p_input, "CDDB error: %s", cddb_error_str(errno));
687 #endif /*HAVE_LIBCDDB*/
689 #define add_format_str_info(val) \
691 const char *str = val; \
696 strncat(tp, str, TEMP_STR_LEN-(tp-temp_str)); \
699 saw_control_prefix = false; \
703 #define add_format_num_info(val, fmt) \
707 sprintf(num_str, fmt, val); \
708 len=strlen(num_str); \
710 strncat(tp, num_str, TEMP_STR_LEN-(tp-temp_str)); \
713 saw_control_prefix = false; \
717 Take a format string and expand escape sequences, that is sequences that
718 begin with %, with information from the current CD.
719 The expanded string is returned. Here is a list of escape sequences:
721 %a : The album artist **
722 %A : The album information **
727 %m : The CD-DA Media Catalog Number (MCN)
728 %n : The number of tracks on the CD
729 %p : The artist/performer/composer in the track **
730 %T : The track number **
731 %s : Number of seconds in this track
733 %Y : The year 19xx or 20xx **
737 CDDAFormatStr(const input_thread_t *p_input, cdda_data_t *p_cdda,
738 const char format_str[], const char *mrl, int i_track)
740 #define TEMP_STR_SIZE 256
741 #define TEMP_STR_LEN (TEMP_STR_SIZE-1)
742 static char temp_str[TEMP_STR_SIZE];
744 char * tp = temp_str;
745 bool saw_control_prefix = false;
746 size_t format_len = strlen(format_str);
748 bzero(temp_str, TEMP_STR_SIZE);
750 for (i=0; i<format_len; i++) {
752 if (!saw_control_prefix && format_str[i] != '%') {
753 *tp++ = format_str[i];
754 saw_control_prefix = false;
758 switch(format_str[i]) {
760 if (saw_control_prefix) {
763 saw_control_prefix = !saw_control_prefix;
767 if (!p_cdda->i_cddb_enabled) goto not_special;
768 add_format_str_info(p_cdda->cddb.disc->artist);
771 if (!p_cdda->i_cddb_enabled) goto not_special;
772 add_format_str_info(p_cdda->cddb.disc->title);
775 if (!p_cdda->i_cddb_enabled) goto not_special;
776 add_format_str_info(CDDB_CATEGORY[p_cdda->cddb.disc->category]);
779 if (!p_cdda->i_cddb_enabled) goto not_special;
780 add_format_str_info(p_cdda->cddb.disc->genre);
783 if (!p_cdda->i_cddb_enabled) goto not_special;
784 add_format_num_info(p_cdda->cddb.disc->discid, "%x");
787 if (!p_cdda->i_cddb_enabled) goto not_special;
788 add_format_num_info(p_cdda->cddb.disc->year, "%5d");
791 if (p_cdda->i_cddb_enabled) {
792 cddb_track_t *t=cddb_disc_get_track(p_cdda->cddb.disc,
794 if (t != NULL && t->title != NULL)
795 add_format_str_info(t->title);
796 } else goto not_special;
799 if (p_cdda->i_cddb_enabled) {
800 cddb_track_t *t=cddb_disc_get_track(p_cdda->cddb.disc,
802 if (t != NULL && t->artist != NULL)
803 add_format_str_info(t->artist);
804 } else goto not_special;
809 add_format_str_info(mrl);
814 add_format_str_info(p_cdda->mcn);
819 add_format_num_info(p_cdda->i_nb_tracks, "%d");
823 if (p_cdda->i_cddb_enabled) {
824 char psz_buffer[MSTRTIME_MAX_SIZE];
826 (p_cdda->p_sectors[i_track] - p_cdda->p_sectors[i_track-1])
827 / CDIO_CD_FRAMES_PER_SEC;
828 add_format_str_info(secstotimestr( psz_buffer, i_duration ) );
829 } else goto not_special;
833 add_format_num_info(i_track, "%d");
840 *tp++ = format_str[i];
841 saw_control_prefix = false;
844 return strdup(temp_str);
848 CDDACreatePlayListItem(const input_thread_t *p_input, cdda_data_t *p_cdda,
849 playlist_t *p_playlist, unsigned int i_track,
850 char *psz_mrl, int psz_mrl_max,
851 const char *psz_source, int playlist_operation,
855 (p_cdda->p_sectors[i_track] - p_cdda->p_sectors[i_track-1])
856 / CDIO_CD_FRAMES_PER_SEC;
859 snprintf(psz_mrl, psz_mrl_max, "%s%s@T%u",
860 CDDA_MRL_PREFIX, psz_source, i_track);
862 p_title = CDDAFormatStr(p_input, p_cdda,
863 config_GetPsz( p_input,
864 MODULE_STRING "-title-format" ),
867 playlist_AddExt( p_playlist, psz_mrl, p_title, i_duration,
868 0, 0, playlist_operation, i_pos );
872 CDDAFixupPlayList( input_thread_t *p_input, cdda_data_t *p_cdda,
873 const char *psz_source, bool play_single_track)
876 playlist_t * p_playlist;
878 unsigned int psz_mrl_max = strlen(CDDA_MRL_PREFIX) + strlen(psz_source) +
879 strlen("@T") + strlen("100") + 1;
882 p_cdda->i_cddb_enabled =
883 config_GetInt( p_input, MODULE_STRING "-cddb-enabled" );
886 if (play_single_track && !p_cdda->i_cddb_enabled) return 0;
888 psz_mrl = malloc( psz_mrl_max );
890 if( psz_mrl == NULL )
892 msg_Warn( p_input, "out of memory" );
896 p_playlist = (playlist_t *) vlc_object_find( p_input, VLC_OBJECT_PLAYLIST,
900 msg_Warn( p_input, "can't find playlist" );
906 if (p_cdda->i_cddb_enabled)
907 GetCDDBInfo(p_input, p_cdda);
909 p_cdda->cddb.disc = NULL;
912 InformationCreate(p_input);
914 if (play_single_track) {
915 /* May fill out more information when the playlist user interface becomes
918 CDDACreatePlayListItem(p_input, p_cdda, p_playlist, p_cdda->i_track+1,
919 psz_mrl, psz_mrl_max, psz_source, PLAYLIST_REPLACE,
920 p_playlist->i_index);
923 playlist_Delete( p_playlist, p_playlist->i_index);
925 for( i = 1 ; i <= p_cdda->i_nb_tracks ; i++ )
927 CDDACreatePlayListItem(p_input, p_cdda, p_playlist, i, psz_mrl,
928 psz_mrl_max, psz_source, PLAYLIST_APPEND,
933 playlist_Command( p_playlist, PLAYLIST_GOTO, 0 );
937 vlc_object_release( p_playlist );