1 /*****************************************************************************
2 * access.c : CD digital audio input module for vlc using libcdio
3 *****************************************************************************
4 * Copyright (C) 2000, 2003, 2004, 2005 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
29 #include "callback.h" /* FIXME - reorganize callback.h, cdda.h better */
30 #include "cdda.h" /* private structures. Also #includes vlc things */
31 #include "info.h" /* headers for meta info retrieval */
32 #include <vlc_playlist.h> /* Has to come *after* cdda.h */
34 #include <vlc_interaction.h>
36 #include <cdio/cdio.h>
37 #include <cdio/logging.h>
38 #include <cdio/cd_types.h>
42 /* #ifdef variables below are defined via config.h via #include vlc above. */
47 #ifdef HAVE_SYS_TYPES_H
48 #include <sys/types.h>
59 /* FIXME: This variable is a hack. Would be nice to eliminate. */
60 access_t *p_cdda_input = NULL;
62 /*****************************************************************************
64 *****************************************************************************/
65 static int CDDARead( access_t *, uint8_t *, int );
66 static block_t *CDDAReadBlocks( access_t * p_access );
67 static int CDDASeek( access_t * p_access, int64_t i_pos );
68 static int CDDAControl( access_t *p_access, int i_query,
71 static int CDDAInit( access_t *p_access, cdda_data_t *p_cdda ) ;
74 /****************************************************************************
76 ****************************************************************************/
78 /* process messages that originate from libcdio.
82 cdio_log_handler( cdio_log_level_t level, const char message[] )
84 cdda_data_t *p_cdda = (cdda_data_t *)p_cdda_input->p_sys;
93 if (p_cdda->i_debug & INPUT_DBG_CDIO)
94 msg_Dbg( p_cdda_input, message);
97 msg_Warn( p_cdda_input, message);
100 case CDIO_LOG_ASSERT:
101 msg_Err( p_cdda_input, message);
104 msg_Warn( p_cdda_input, message,
105 "the above message had unknown cdio log level",
112 /*! This routine is called by libcddb routines on error.
116 cddb_log_handler( cddb_log_level_t level, const char message[] )
118 cdda_data_t *p_cdda = (cdda_data_t *)p_cdda_input->p_sys;
123 if( !(p_cdda->i_debug & INPUT_DBG_CDDB) )
125 /* Fall through if to warn case */
127 cdio_log_handler( level, message );
131 #endif /*HAVE_LIBCDDB*/
134 /*! This routine is when vlc is not fully set up (before full initialization)
135 or is not around (before finalization).
138 uninit_log_handler( cdio_log_level_t level, const char message[] )
140 cdda_data_t *p_cdda = NULL;
143 p_cdda = (cdda_data_t *)p_cdda_input->p_sys;
149 if( !p_cdda || !(p_cdda->i_debug & (INPUT_DBG_CDIO|INPUT_DBG_CDDB)) )
151 /* Fall through if to warn case */
153 fprintf( stderr, "WARN: %s\n", message );
156 fprintf( stderr, "ERROR: %s\n", message );
158 case CDIO_LOG_ASSERT:
159 fprintf( stderr, "ASSERT ERROR: %s\n", message );
162 fprintf( stderr, "UNKNOWN ERROR: %s\n%s %d\n", message,
163 "The above message had unknown cdio log level",
167 /* gl_default_cdio_log_handler (level, message); */
170 /* Only used in audio control mode. Gets the current LSN from the
172 static int64_t get_audio_position ( access_t *p_access )
174 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
177 #if LIBCDIO_VERSION_NUM >= 73
178 if( p_cdda->b_audio_ctl )
180 cdio_subchannel_t sub;
181 CdIo_t *p_cdio = p_cdda->p_cdio;
183 if( DRIVER_OP_SUCCESS == cdio_audio_read_subchannel(p_cdio, &sub) )
185 if( (sub.audio_status != CDIO_MMC_READ_SUB_ST_PAUSED) &&
186 (sub.audio_status != CDIO_MMC_READ_SUB_ST_PLAY) )
187 return CDIO_INVALID_LSN;
189 if( ! p_cdda->b_nav_mode )
191 i_offset = cdio_msf_to_lba( (&sub.abs_addr) );
195 i_offset = cdio_msf_to_lba( (&sub.rel_addr) );
200 i_offset = p_cdda->i_lsn;
205 i_offset = p_cdda->i_lsn;
208 i_offset = p_cdda->i_lsn;
213 /*****************************************************************************
214 * CDDAReadBlocks: reads a group of blocks from the CD-DA and returns
215 * an allocated pointer to the data. NULL is returned if no data
216 * read. It is also possible if we haven't read a RIFF header in which
217 * case one that we creaded during Open/Initialization is returned.
218 *****************************************************************************/
219 static block_t * CDDAReadBlocks( access_t * p_access )
222 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
223 int i_blocks = p_cdda->i_blocks_per_read;
225 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_LSN),
226 "called i_lsn: %d i_pos: %lld, size: %lld",
227 p_cdda->i_lsn, p_access->info.i_pos, p_access->info.i_size );
229 /* Check end of file */
230 if( p_access->info.b_eof )
233 if( !p_cdda->b_header )
235 /* Return only the dummy RIFF header we created in Open/Init */
236 p_block = block_New( p_access, sizeof( WAVEHEADER ) );
237 memcpy( p_block->p_buffer, &p_cdda->waveheader, sizeof(WAVEHEADER) );
238 p_cdda->b_header = VLC_TRUE;
242 /* Check end of track */
243 while( p_cdda->i_lsn > cdio_get_track_last_lsn(p_cdda->p_cdio,
248 if( p_cdda->b_nav_mode )
249 go_on = p_cdda->i_lsn > p_cdda->last_disc_frame;
251 go_on = p_cdda->i_track >= p_cdda->i_first_track+p_cdda->i_titles-1 ;
255 dbg_print( (INPUT_DBG_LSN), "EOF");
256 p_access->info.b_eof = VLC_TRUE;
260 p_access->info.i_update |= INPUT_UPDATE_TITLE | INPUT_UPDATE_META;
261 p_access->info.i_title++;
264 if( p_cdda-> b_nav_mode )
266 char *psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
267 input_Control( p_cdda->p_input, INPUT_SET_NAME, psz_title );
272 p_access->info.i_size =
273 p_cdda->p_title[p_access->info.i_title]->i_size;
274 p_access->info.i_pos = 0;
275 p_access->info.i_update |= INPUT_UPDATE_SIZE;
279 /* Possibly adjust i_blocks so we don't read past the end of a track. */
280 if( p_cdda->i_lsn + i_blocks >=
281 cdio_get_track_lsn(p_cdda->p_cdio, p_cdda->i_track+1) )
283 i_blocks = cdio_get_track_lsn( p_cdda->p_cdio, p_cdda->i_track+1 )
287 /* Do the actual reading */
288 p_block = block_New( p_access, i_blocks * CDIO_CD_FRAMESIZE_RAW );
291 msg_Err( p_access, "cannot get a new block of size: %i",
292 i_blocks * CDIO_CD_FRAMESIZE_RAW );
293 intf_UserFatal( p_access, VLC_FALSE, _("CD reading failed"),
294 _("VLC could not get a new block of size: %i."),
295 i_blocks * CDIO_CD_FRAMESIZE_RAW );
300 #if LIBCDIO_VERSION_NUM >= 72
301 driver_return_code_t rc = DRIVER_OP_SUCCESS;
303 if( p_cdda->e_paranoia && p_cdda->paranoia )
306 for( i = 0; i < i_blocks; i++ )
308 int16_t *p_readbuf = cdio_paranoia_read( p_cdda->paranoia, NULL );
309 char *psz_err = cdio_cddap_errors( p_cdda->paranoia_cd );
310 char *psz_mes = cdio_cddap_messages( p_cdda->paranoia_cd );
312 if( psz_mes || psz_err )
313 msg_Err( p_access, "%s%s\n", psz_mes ? psz_mes: "",
314 psz_err ? psz_err: "" );
316 if( psz_err ) free( psz_err );
317 if( psz_mes ) free( psz_mes );
320 msg_Err( p_access, "paranoia read error on frame %i\n",
324 memcpy( p_block->p_buffer + i * CDIO_CD_FRAMESIZE_RAW,
325 p_readbuf, CDIO_CD_FRAMESIZE_RAW );
330 rc = cdio_read_audio_sectors( p_cdda->p_cdio, p_block->p_buffer,
331 p_cdda->i_lsn, i_blocks );
333 #define DRIVER_OP_SUCCESS 0
335 rc = cdio_read_audio_sectors( p_cdda->p_cdio, p_block->p_buffer,
336 p_cdda->i_lsn, i_blocks);
339 if( rc != DRIVER_OP_SUCCESS )
341 msg_Err( p_access, "could not read %d sectors starting from %lu",
342 i_blocks, (long unsigned int) p_cdda->i_lsn );
343 block_Release( p_block );
345 /* If we had problems above, assume the problem is with
346 the first sector of the read and set to skip it. In
347 the future libcdio may have cdparanoia support.
350 p_access->info.i_pos += CDIO_CD_FRAMESIZE_RAW;
355 p_cdda->i_lsn += i_blocks;
356 p_access->info.i_pos += i_blocks * CDIO_CD_FRAMESIZE_RAW;
361 /*****************************************************************************
362 * CDDARead: Handler for audio control reads the CD-DA.
363 *****************************************************************************/
365 CDDARead( access_t * p_access, uint8_t *p_buffer, int i_len )
367 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
369 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_LSN),
370 "called lsn: %d pos: %lld, size: %lld",
371 p_cdda->i_lsn, p_access->info.i_pos, p_access->info.i_size);
373 /* Check end of file */
374 if( p_access->info.b_eof )
378 lsn_t i_lsn = get_audio_position(p_access);
379 if( CDIO_INVALID_LSN == i_lsn )
381 dbg_print( (INPUT_DBG_LSN), "invalid lsn" );
382 memset( p_buffer, 0, i_len );
386 p_cdda->i_lsn = i_lsn;
387 p_access->info.i_pos = p_cdda->i_lsn * CDIO_CD_FRAMESIZE_RAW;
390 dbg_print( (INPUT_DBG_LSN), "updated lsn: %d", p_cdda->i_lsn );
392 /* Check end of track */
393 while( p_cdda->i_lsn > cdio_get_track_last_lsn( p_cdda->p_cdio,
396 if( p_cdda->i_track >= p_cdda->i_first_track + p_cdda->i_titles - 1 )
398 dbg_print( (INPUT_DBG_LSN), "EOF");
399 p_access->info.b_eof = VLC_TRUE;
402 p_access->info.i_update |= INPUT_UPDATE_TITLE;
403 p_access->info.i_title++;
406 if( p_cdda-> b_nav_mode )
408 char *psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
409 input_Control( p_cdda->p_input, INPUT_SET_NAME, psz_title );
414 p_access->info.i_size =
415 p_cdda->p_title[p_access->info.i_title]->i_size;
416 p_access->info.i_pos = 0;
417 p_access->info.i_update |= INPUT_UPDATE_SIZE;
420 memset( p_buffer, 0, i_len );
424 /*! Pause CD playing via audio control */
425 static bool cdda_audio_pause( CdIo_t *p_cdio )
428 #if LIBCDIO_VERSION_NUM >= 73
429 cdio_subchannel_t sub;
431 if( DRIVER_OP_SUCCESS == cdio_audio_read_subchannel( p_cdio, &sub ) )
433 if( sub.audio_status == CDIO_MMC_READ_SUB_ST_PLAY )
435 b_ok = DRIVER_OP_SUCCESS == cdio_audio_pause(p_cdio);
444 #if LIBCDIO_VERSION_NUM >= 73
445 /*! play CD using audio controls */
446 static driver_return_code_t
447 cdda_audio_play( CdIo_t *p_cdio, lsn_t start_lsn, lsn_t end_lsn )
451 cdio_lsn_to_msf( start_lsn, &start_msf );
452 cdio_lsn_to_msf( end_lsn, &last_msf );
453 cdda_audio_pause( p_cdio );
454 return cdio_audio_play_msf( p_cdio, &start_msf, &last_msf );
458 /****************************************************************************
459 * CDDASeek - change position for subsequent reads. For example, this
460 * can happen if the user moves a position slider bar in a GUI.
461 ****************************************************************************/
462 static int CDDASeek( access_t * p_access, int64_t i_pos )
464 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
466 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_SEEK),
467 "lsn %lu, offset: %lld",
468 (long unsigned int) p_cdda->i_lsn, i_pos );
470 p_cdda->i_lsn = (i_pos / CDIO_CD_FRAMESIZE_RAW);
472 #if LIBCDIO_VERSION_NUM >= 72
473 if( p_cdda->e_paranoia && p_cdda->paranoia )
474 cdio_paranoia_seek( p_cdda->paranoia, p_cdda->i_lsn, SEEK_SET );
477 #if LIBCDIO_VERSION_NUM >= 73
478 if( p_cdda->b_audio_ctl )
480 track_t i_track = cdio_get_track( p_cdda->p_cdio, p_cdda->i_lsn );
483 if( p_cdda->b_nav_mode )
484 i_last_lsn = p_cdda->last_disc_frame;
486 i_last_lsn = cdio_get_track_last_lsn( p_cdda->p_cdio, i_track );
488 cdda_audio_play( p_cdda->p_cdio, p_cdda->i_lsn, i_last_lsn );
492 if( ! p_cdda->b_nav_mode )
493 p_cdda->i_lsn += cdio_get_track_lsn( p_cdda->p_cdio, p_cdda->i_track );
495 /* Seeked backwards and we are doing disc mode. */
496 if( p_cdda->b_nav_mode && p_access->info.i_pos > i_pos )
501 for( i_track = p_cdda->i_track; i_track > 1 &&
502 p_cdda->i_lsn < cdio_get_track_lsn( p_cdda->p_cdio, i_track );
503 i_track--, p_access->info.i_title-- )
506 p_cdda->i_track = i_track;
507 p_access->info.i_update |= INPUT_UPDATE_TITLE | INPUT_UPDATE_META ;
508 psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
509 input_Control( p_cdda->p_input, INPUT_SET_NAME,
514 p_access->info.i_pos = i_pos;
519 Set up internal state so that we play a given track.
520 If we are using audio-ctl mode we also activate CD-ROM
523 static bool cdda_play_track( access_t *p_access, track_t i_track )
525 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
527 dbg_print( (INPUT_DBG_CALL), "called track: %d\n", i_track );
529 if( i_track > p_cdda->i_tracks )
531 msg_Err( p_access, "CD has %d tracks, and you requested track %d",
532 p_cdda->i_tracks, i_track );
535 p_cdda->i_track = i_track;
537 /* set up the frame boundaries for this particular track */
538 p_cdda->first_frame = p_cdda->i_lsn =
539 cdio_get_track_lsn( p_cdda->p_cdio, i_track );
541 p_cdda->last_frame = cdio_get_track_lsn( p_cdda->p_cdio, i_track+1 ) - 1;
543 #if LIBCDIO_VERSION_NUM >= 73
544 if( p_cdda->b_audio_ctl )
547 if( p_cdda->b_nav_mode )
548 i_last_lsn = p_cdda->last_disc_frame;
550 i_last_lsn = cdio_get_track_last_lsn( p_cdda->p_cdio, i_track );
551 cdda_audio_play( p_cdda->p_cdio, p_cdda->i_lsn, i_last_lsn );
557 /****************************************************************************
559 ****************************************************************************/
561 /*****************************************************************************
562 * Open: open cdda device or image file and initialize structures
563 * for subsequent operations.
564 *****************************************************************************/
565 int CDDAOpen( vlc_object_t *p_this )
567 access_t *p_access = (access_t*)p_this;
568 char * psz_source = NULL;
569 cdda_data_t *p_cdda = NULL;
572 vlc_bool_t b_single_track = false;
573 int i_rc = VLC_EGENERIC;
575 p_access->p_sys = NULL;
577 /* Set where to log errors messages from libcdio. */
578 p_cdda_input = p_access;
580 /* parse the options passed in command line : */
581 if( p_access->psz_path && *p_access->psz_path )
583 char *psz_parser = psz_source = strdup( p_access->psz_path );
585 while( *psz_parser && *psz_parser != '@' )
590 if( *psz_parser == '@' )
596 if ('T' == *psz_parser || 't' == *psz_parser )
599 i_track = (int)strtol( psz_parser, NULL, 10 );
600 i_track = i_track ? i_track : 1;
601 b_single_track = true;
605 if( !psz_source || !*psz_source )
607 /* No device/track given. Continue only when this plugin was
609 if( !p_this->b_force )
612 psz_source = var_CreateGetString( p_this, "cd-audio" );
613 if( !psz_source || !*psz_source )
615 /* Scan for a CD-ROM drive with a CD-DA in it. */
617 cdio_get_devices_with_cap( NULL, CDIO_FS_AUDIO, false );
619 if( (NULL == ppsz_drives) || (NULL == ppsz_drives[0]) )
622 "libcdio couldn't find something with a CD-DA in it" );
624 cdio_free_device_list( ppsz_drives );
627 psz_source = strdup( ppsz_drives[0] );
628 cdio_free_device_list( ppsz_drives );
631 cdio_log_set_handler( cdio_log_handler );
634 if( !(p_cdio = cdio_open( psz_source, DRIVER_UNKNOWN )) )
636 msg_Warn( p_access, "could not open %s", psz_source );
642 p_cdda = calloc( 1, sizeof(cdda_data_t) );
645 msg_Err( p_access, "out of memory" );
651 cddb_log_set_handler ( cddb_log_handler );
652 p_cdda->cddb.disc = NULL;
653 p_cdda->b_cddb_enabled =
654 config_GetInt( p_access, MODULE_STRING "-cddb-enabled" );
657 config_GetInt( p_access, MODULE_STRING "-cdtext-enabled" );
658 p_cdda->b_cdtext_prefer =
659 config_GetInt( p_access, MODULE_STRING "-cdtext-prefer" );
660 #if LIBCDIO_VERSION_NUM >= 73
661 p_cdda->b_audio_ctl =
662 config_GetInt( p_access, MODULE_STRING "-analog-output" );
665 p_cdda->psz_source = strdup( psz_source );
666 p_cdda->b_header = VLC_FALSE;
667 p_cdda->p_cdio = p_cdio;
668 p_cdda->i_tracks = 0;
669 p_cdda->i_titles = 0;
670 p_cdda->i_debug = config_GetInt( p_this, MODULE_STRING "-debug" );
671 p_cdda->b_nav_mode = config_GetInt(p_this, MODULE_STRING "-navigation-mode" );
672 p_cdda->i_blocks_per_read =
673 config_GetInt( p_this, MODULE_STRING "-blocks-per-read" );
674 p_cdda->last_disc_frame =
675 cdio_get_track_lsn( p_cdio, CDIO_CDROM_LEADOUT_TRACK );
676 p_cdda->p_input = vlc_object_find( p_access, VLC_OBJECT_INPUT,
679 if( 0 == p_cdda->i_blocks_per_read )
680 p_cdda->i_blocks_per_read = DEFAULT_BLOCKS_PER_READ;
682 if( (p_cdda->i_blocks_per_read < MIN_BLOCKS_PER_READ)
683 || (p_cdda->i_blocks_per_read > MAX_BLOCKS_PER_READ) )
685 msg_Warn( p_cdda_input,
686 "number of blocks (%d) has to be between %d and %d. "
688 p_cdda->i_blocks_per_read,
689 MIN_BLOCKS_PER_READ, MAX_BLOCKS_PER_READ,
690 DEFAULT_BLOCKS_PER_READ );
691 p_cdda->i_blocks_per_read = DEFAULT_BLOCKS_PER_READ;
694 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "%s", psz_source );
696 /* Set up p_access */
697 if( p_cdda->b_audio_ctl )
699 p_access->pf_read = CDDARead;
700 p_access->pf_block = NULL;
704 p_access->pf_read = NULL;
705 p_access->pf_block = CDDAReadBlocks;
708 p_access->pf_control = CDDAControl;
709 p_access->pf_seek = CDDASeek;
714 if( p_cdda->b_nav_mode )
715 i_last_lsn = p_cdda->last_disc_frame;
717 i_last_lsn = cdio_get_track_last_lsn( p_cdio, i_track );
719 if( CDIO_INVALID_LSN != i_last_lsn )
720 p_access->info.i_size = i_last_lsn * (uint64_t) CDIO_CD_FRAMESIZE_RAW;
722 p_access->info.i_size = 0;
725 p_access->info.i_update = 0;
726 p_access->info.b_eof = VLC_FALSE;
727 p_access->info.i_title = 0;
728 p_access->info.i_seekpoint = 0;
730 p_access->p_sys = (access_sys_t *) p_cdda;
732 /* We read the Table Of Content information */
733 i_rc = CDDAInit( p_access, p_cdda );
734 if( VLC_SUCCESS != i_rc )
737 cdda_play_track( p_access, i_track );
738 CDDAFixupPlaylist( p_access, p_cdda, b_single_track );
740 #if LIBCDIO_VERSION_NUM >= 72
742 char *psz_paranoia = config_GetPsz( p_access,
743 MODULE_STRING "-paranoia" );
745 p_cdda->e_paranoia = paranoia_none;
746 if( psz_paranoia && *psz_paranoia )
748 if( !strncmp( psz_paranoia, "full", strlen("full") ) )
749 p_cdda->e_paranoia = paranoia_full;
750 else if( !strncmp(psz_paranoia, "overlap", strlen("overlap")) )
751 p_cdda->e_paranoia = paranoia_overlap;
753 /* Use CD Paranoia? */
754 if( p_cdda->e_paranoia )
756 p_cdda->paranoia_cd =
757 cdio_cddap_identify_cdio( p_cdio, 1, NULL );
758 /* We'll set for verbose paranoia messages. */
759 cdio_cddap_verbose_set( p_cdda->paranoia_cd,
760 CDDA_MESSAGE_PRINTIT,
761 CDDA_MESSAGE_PRINTIT );
762 if ( 0 != cdio_cddap_open(p_cdda->paranoia_cd) )
764 msg_Warn( p_cdda_input, "unable to get paranoia support - "
765 "continuing without it." );
766 p_cdda->e_paranoia = paranoia_none;
770 p_cdda->paranoia = cdio_paranoia_init(p_cdda->paranoia_cd);
771 cdio_paranoia_seek( p_cdda->paranoia, p_cdda->i_lsn,
774 /* Set reading mode for full or overlap paranoia,
775 * but allow skipping sectors. */
776 cdio_paranoia_modeset( p_cdda->paranoia,
777 paranoia_full == p_cdda->e_paranoia ?
778 PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP :
779 PARANOIA_MODE_OVERLAP^PARANOIA_MODE_NEVERSKIP );
786 /* Build a WAV header to put in front of the output data.
787 This gets sent back in the Block (read) routine.
789 memset( &p_cdda->waveheader, 0, sizeof(WAVEHEADER) );
791 SetWLE( &p_cdda->waveheader.Format, 1 ); /*WAVE_FORMAT_PCM*/
792 SetWLE( &p_cdda->waveheader.BitsPerSample, 16);
794 p_cdda->waveheader.MainChunkID = VLC_FOURCC('R', 'I', 'F', 'F');
795 p_cdda->waveheader.Length = 0; /* we just don't know */
796 p_cdda->waveheader.ChunkTypeID = VLC_FOURCC('W', 'A', 'V', 'E');
797 p_cdda->waveheader.SubChunkID = VLC_FOURCC('f', 'm', 't', ' ');
799 SetDWLE( &p_cdda->waveheader.SubChunkLength, 16);
800 SetWLE( &p_cdda->waveheader.Modus, 2);
801 SetDWLE( &p_cdda->waveheader.SampleFreq, CDDA_FREQUENCY_SAMPLE);
802 SetWLE( &p_cdda->waveheader.BytesPerSample,
803 2 /*Modus*/ * 16 /*BitsPerSample*/ / 8 );
804 SetDWLE( &p_cdda->waveheader.BytesPerSec,
805 2*16/8 /*BytesPerSample*/ * CDDA_FREQUENCY_SAMPLE );
807 p_cdda->waveheader.DataChunkID = VLC_FOURCC('d', 'a', 't', 'a');
808 p_cdda->waveheader.DataLength = 0; /* we just don't know */
811 var_Create( p_access, MODULE_STRING "-caching",
812 VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
813 vlc_object_release( p_cdda->p_input );
817 cdio_destroy( p_cdda->p_cdio );
818 if( psz_source) free( psz_source );
821 if ( p_cdda->p_input )
822 vlc_object_release( p_cdda->p_input );
828 /*****************************************************************************
829 * CDDAClose: closes cdda and frees any resources associded with it.
830 *****************************************************************************/
831 void CDDAClose (vlc_object_t *p_this )
833 access_t *p_access = (access_t *) p_this;
834 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
837 #if LIBCDIO_VERSION_NUM >= 73
838 if( p_cdda->b_audio_ctl )
839 cdio_audio_stop(p_cdda->p_cdio);
842 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "" );
844 /* Remove playlist titles */
845 for( i = 0; i < p_cdda->i_titles; i++ )
847 vlc_input_title_Delete( p_cdda->p_title[i] );
851 cddb_log_set_handler( (cddb_log_handler_t) uninit_log_handler );
852 if( p_cdda->b_cddb_enabled )
853 cddb_disc_destroy( p_cdda->cddb.disc );
856 cdio_destroy( p_cdda->p_cdio );
857 cdio_log_set_handler( uninit_log_handler );
859 #if LIBCDIO_VERSION_NUM >= 72
860 if( p_cdda->paranoia )
861 cdio_paranoia_free(p_cdda->paranoia);
862 if( p_cdda->paranoia_cd )
863 cdio_cddap_close_no_free_cdio( p_cdda->paranoia_cd );
866 if( p_cdda->psz_mcn ) free( p_cdda->psz_mcn );
867 if( p_cdda->psz_source ) free( p_cdda->psz_source );
869 #if LIBCDDB_VERSION_NUM >= 1
877 /*****************************************************************************
878 * Control: The front-end or vlc engine calls here to ether get
879 * information such as meta information or plugin capabilities or to
880 * issue miscellaneous "set" requests.
881 *****************************************************************************/
882 static int CDDAControl( access_t *p_access, int i_query, va_list args )
884 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
888 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_EVENT),
889 "query %d", i_query );
893 /* Pass back a copy of meta information that was gathered when we
894 during the Open/Initialize call.
896 case ACCESS_GET_META:
898 vlc_meta_t **pp_meta = (vlc_meta_t**)va_arg( args, vlc_meta_t** );
902 *pp_meta = vlc_meta_Duplicate( p_cdda->p_meta );
903 dbg_print( INPUT_DBG_META, "%s", "Meta copied" );
909 msg_Warn( p_access, "tried to copy NULL meta info" );
914 case ACCESS_CAN_CONTROL_PACE:
916 vlc_bool_t *pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
917 *pb_bool = p_cdda->b_audio_ctl ? VLC_FALSE : VLC_TRUE;
918 dbg_print( INPUT_DBG_META, "can control pace? %d", *pb_bool);
922 case ACCESS_CAN_FASTSEEK:
923 dbg_print( INPUT_DBG_META, "can fast seek?");
925 case ACCESS_CAN_SEEK:
926 dbg_print( INPUT_DBG_META, "can seek?");
928 case ACCESS_CAN_PAUSE:
929 dbg_print( INPUT_DBG_META, "can pause?");
932 vlc_bool_t *pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
940 pi_int = (int*)va_arg( args, int * );
941 *pi_int = p_cdda-> i_blocks_per_read * CDIO_CD_FRAMESIZE_RAW;
942 dbg_print( INPUT_DBG_META, "Get MTU %d", *pi_int);
946 case ACCESS_GET_PTS_DELAY:
948 int64_t *pi_64 = (int64_t*)va_arg( args, int64_t * );
949 *pi_64 = var_GetInteger( p_access, MODULE_STRING "-caching" )
950 * MILLISECONDS_PER_SEC;
954 case ACCESS_GET_TITLE_INFO:
956 input_title_t ***ppp_title =
957 (input_title_t***)va_arg( args, input_title_t*** );
959 pi_int = (int*)va_arg( args, int* );
960 *((int*)va_arg( args, int* )) = 1; /* Title offset */
962 dbg_print ( INPUT_DBG_EVENT,
963 "GET TITLE: i_tracks %d, i_tracks %d",
964 p_cdda->i_tracks, p_cdda->i_tracks );
966 CDDAMetaInfo( p_access, CDIO_INVALID_TRACK );
968 if( p_cdda->b_nav_mode)
970 char *psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
971 input_Control( p_cdda->p_input, INPUT_SET_NAME, psz_title );
975 /* Duplicate title info */
976 if( p_cdda->i_titles == 0 )
978 *pi_int = 0; ppp_title = NULL;
981 *pi_int = p_cdda->i_titles;
982 *ppp_title = calloc(1, sizeof( input_title_t **)
983 * p_cdda->i_titles );
988 for( i = 0; i < p_cdda->i_titles; i++ )
990 if ( p_cdda->p_title[i] )
993 vlc_input_title_Duplicate( p_cdda->p_title[i] );
999 case ACCESS_SET_TITLE:
1001 i = (int)va_arg( args, int );
1003 dbg_print( INPUT_DBG_EVENT, "set title %d", i );
1004 if( i != p_access->info.i_title )
1006 const track_t i_track = p_cdda->i_first_track + i;
1008 p_access->info.i_title = i;
1009 if( p_cdda->b_nav_mode)
1012 char *psz_title = CDDAFormatTitle( p_access, i_track );
1013 input_Control( p_cdda->p_input, INPUT_SET_NAME,
1016 p_cdda->i_track = i_track;
1017 i_last_lsn = cdio_get_track_lsn( p_cdda->p_cdio,
1018 CDIO_CDROM_LEADOUT_TRACK );
1019 if( CDIO_INVALID_LSN != i_last_lsn )
1020 p_access->info.i_size = (int64_t) CDIO_CD_FRAMESIZE_RAW
1022 p_access->info.i_pos = (int64_t)
1023 cdio_get_track_lsn( p_cdda->p_cdio, i_track )
1024 * CDIO_CD_FRAMESIZE_RAW;
1028 p_access->info.i_size = p_cdda->p_title[i]->i_size;
1029 p_access->info.i_pos = 0;
1031 p_access->info.i_update = INPUT_UPDATE_TITLE|INPUT_UPDATE_SIZE;
1033 /* Next sector to read */
1034 p_cdda->i_lsn = cdio_get_track_lsn( p_cdda->p_cdio, i_track );
1039 case ACCESS_SET_PAUSE_STATE:
1040 dbg_print( INPUT_DBG_META, "Pause");
1041 if( p_cdda->b_audio_ctl )
1042 cdda_audio_pause( p_cdda->p_cdio );
1045 case ACCESS_SET_SEEKPOINT:
1046 dbg_print( INPUT_DBG_META, "set seekpoint");
1047 return VLC_EGENERIC;
1049 case ACCESS_SET_PRIVATE_ID_STATE:
1050 dbg_print( INPUT_DBG_META, "set private id state");
1051 return VLC_EGENERIC;
1054 msg_Warn( p_access, "unimplemented query in control" );
1055 return VLC_EGENERIC;
1061 /*****************************************************************************
1064 Initialize information pertaining to the CD: the number of tracks,
1065 first track number, LSNs for each track and the leadout. The leadout
1066 information is stored after the last track. The LSN array is
1067 0-origin, same as p_access->info. Add first_track to get what track
1068 number this is on the CD. Note: libcdio uses the real track number.
1070 On input we assume p_cdda->p_cdio and p_cdda->i_track have been set.
1072 We return the VLC-type status, e.g. VLC_SUCCESS, VLC_ENOMEM, etc.
1073 *****************************************************************************/
1074 static int CDDAInit( access_t *p_access, cdda_data_t *p_cdda )
1076 discmode_t discmode = CDIO_DISC_MODE_NO_INFO;
1078 p_cdda->i_tracks = cdio_get_num_tracks( p_cdda->p_cdio );
1079 p_cdda->i_first_track = cdio_get_first_track_num( p_cdda->p_cdio );
1081 discmode = cdio_get_discmode( p_cdda->p_cdio );
1084 case CDIO_DISC_MODE_CD_DA:
1085 case CDIO_DISC_MODE_CD_MIXED:
1086 /* These are possible for CD-DA */
1089 /* These are not possible for CD-DA */
1091 "Disc seems not to be CD-DA. libcdio reports it is %s",
1092 discmode2str[discmode]
1094 return VLC_EGENERIC;
1097 /* Set reading start LSN. */
1098 p_cdda->i_lsn = cdio_get_track_lsn(p_cdda->p_cdio, p_cdda->i_track);