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;
515 p_access->info.b_eof = VLC_FALSE;
520 Set up internal state so that we play a given track.
521 If we are using audio-ctl mode we also activate CD-ROM
524 static bool cdda_play_track( access_t *p_access, track_t i_track )
526 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
528 dbg_print( (INPUT_DBG_CALL), "called track: %d\n", i_track );
530 if( i_track > p_cdda->i_tracks )
532 msg_Err( p_access, "CD has %d tracks, and you requested track %d",
533 p_cdda->i_tracks, i_track );
536 p_cdda->i_track = i_track;
538 /* set up the frame boundaries for this particular track */
539 p_cdda->first_frame = p_cdda->i_lsn =
540 cdio_get_track_lsn( p_cdda->p_cdio, i_track );
542 p_cdda->last_frame = cdio_get_track_lsn( p_cdda->p_cdio, i_track+1 ) - 1;
544 #if LIBCDIO_VERSION_NUM >= 73
545 if( p_cdda->b_audio_ctl )
548 if( p_cdda->b_nav_mode )
549 i_last_lsn = p_cdda->last_disc_frame;
551 i_last_lsn = cdio_get_track_last_lsn( p_cdda->p_cdio, i_track );
552 cdda_audio_play( p_cdda->p_cdio, p_cdda->i_lsn, i_last_lsn );
558 /****************************************************************************
560 ****************************************************************************/
562 /*****************************************************************************
563 * Open: open cdda device or image file and initialize structures
564 * for subsequent operations.
565 *****************************************************************************/
566 int CDDAOpen( vlc_object_t *p_this )
568 access_t *p_access = (access_t*)p_this;
569 char * psz_source = NULL;
570 cdda_data_t *p_cdda = NULL;
573 vlc_bool_t b_single_track = false;
574 int i_rc = VLC_EGENERIC;
576 p_access->p_sys = NULL;
578 /* Set where to log errors messages from libcdio. */
579 p_cdda_input = p_access;
581 /* parse the options passed in command line : */
582 if( p_access->psz_path && *p_access->psz_path )
584 char *psz_parser = psz_source = strdup( p_access->psz_path );
586 while( *psz_parser && *psz_parser != '@' )
591 if( *psz_parser == '@' )
597 if ('T' == *psz_parser || 't' == *psz_parser )
600 i_track = (int)strtol( psz_parser, NULL, 10 );
601 i_track = i_track ? i_track : 1;
602 b_single_track = true;
606 if( !psz_source || !*psz_source )
608 /* No device/track given. Continue only when this plugin was
610 if( !p_this->b_force )
613 psz_source = var_CreateGetString( p_this, "cd-audio" );
614 if( !psz_source || !*psz_source )
616 /* Scan for a CD-ROM drive with a CD-DA in it. */
618 cdio_get_devices_with_cap( NULL, CDIO_FS_AUDIO, false );
620 if( (NULL == ppsz_drives) || (NULL == ppsz_drives[0]) )
623 "libcdio couldn't find something with a CD-DA in it" );
625 cdio_free_device_list( ppsz_drives );
628 psz_source = strdup( ppsz_drives[0] );
629 cdio_free_device_list( ppsz_drives );
632 cdio_log_set_handler( cdio_log_handler );
635 if( !(p_cdio = cdio_open( psz_source, DRIVER_UNKNOWN )) )
637 msg_Warn( p_access, "could not open %s", psz_source );
643 p_cdda = calloc( 1, sizeof(cdda_data_t) );
646 msg_Err( p_access, "out of memory" );
652 cddb_log_set_handler ( cddb_log_handler );
653 p_cdda->cddb.disc = NULL;
654 p_cdda->b_cddb_enabled =
655 config_GetInt( p_access, MODULE_STRING "-cddb-enabled" );
658 config_GetInt( p_access, MODULE_STRING "-cdtext-enabled" );
659 p_cdda->b_cdtext_prefer =
660 config_GetInt( p_access, MODULE_STRING "-cdtext-prefer" );
661 #if LIBCDIO_VERSION_NUM >= 73
662 p_cdda->b_audio_ctl =
663 config_GetInt( p_access, MODULE_STRING "-analog-output" );
666 p_cdda->psz_source = strdup( psz_source );
667 p_cdda->b_header = VLC_FALSE;
668 p_cdda->p_cdio = p_cdio;
669 p_cdda->i_tracks = 0;
670 p_cdda->i_titles = 0;
671 p_cdda->i_debug = config_GetInt( p_this, MODULE_STRING "-debug" );
672 p_cdda->b_nav_mode = config_GetInt(p_this, MODULE_STRING "-navigation-mode" );
673 p_cdda->i_blocks_per_read =
674 config_GetInt( p_this, MODULE_STRING "-blocks-per-read" );
675 p_cdda->last_disc_frame =
676 cdio_get_track_lsn( p_cdio, CDIO_CDROM_LEADOUT_TRACK );
677 p_cdda->p_input = vlc_object_find( p_access, VLC_OBJECT_INPUT,
680 if( 0 == p_cdda->i_blocks_per_read )
681 p_cdda->i_blocks_per_read = DEFAULT_BLOCKS_PER_READ;
683 if( (p_cdda->i_blocks_per_read < MIN_BLOCKS_PER_READ)
684 || (p_cdda->i_blocks_per_read > MAX_BLOCKS_PER_READ) )
686 msg_Warn( p_cdda_input,
687 "number of blocks (%d) has to be between %d and %d. "
689 p_cdda->i_blocks_per_read,
690 MIN_BLOCKS_PER_READ, MAX_BLOCKS_PER_READ,
691 DEFAULT_BLOCKS_PER_READ );
692 p_cdda->i_blocks_per_read = DEFAULT_BLOCKS_PER_READ;
695 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "%s", psz_source );
697 /* Set up p_access */
698 if( p_cdda->b_audio_ctl )
700 p_access->pf_read = CDDARead;
701 p_access->pf_block = NULL;
705 p_access->pf_read = NULL;
706 p_access->pf_block = CDDAReadBlocks;
709 p_access->pf_control = CDDAControl;
710 p_access->pf_seek = CDDASeek;
715 if( p_cdda->b_nav_mode )
716 i_last_lsn = p_cdda->last_disc_frame;
718 i_last_lsn = cdio_get_track_last_lsn( p_cdio, i_track );
720 if( CDIO_INVALID_LSN != i_last_lsn )
721 p_access->info.i_size = i_last_lsn * (uint64_t) CDIO_CD_FRAMESIZE_RAW;
723 p_access->info.i_size = 0;
726 p_access->info.i_update = 0;
727 p_access->info.b_eof = VLC_FALSE;
728 p_access->info.i_title = 0;
729 p_access->info.i_seekpoint = 0;
731 p_access->p_sys = (access_sys_t *) p_cdda;
733 /* We read the Table Of Content information */
734 i_rc = CDDAInit( p_access, p_cdda );
735 if( VLC_SUCCESS != i_rc )
738 cdda_play_track( p_access, i_track );
739 CDDAFixupPlaylist( p_access, p_cdda, b_single_track );
741 #if LIBCDIO_VERSION_NUM >= 72
743 char *psz_paranoia = config_GetPsz( p_access,
744 MODULE_STRING "-paranoia" );
746 p_cdda->e_paranoia = paranoia_none;
747 if( psz_paranoia && *psz_paranoia )
749 if( !strncmp( psz_paranoia, "full", strlen("full") ) )
750 p_cdda->e_paranoia = paranoia_full;
751 else if( !strncmp(psz_paranoia, "overlap", strlen("overlap")) )
752 p_cdda->e_paranoia = paranoia_overlap;
754 /* Use CD Paranoia? */
755 if( p_cdda->e_paranoia )
757 p_cdda->paranoia_cd =
758 cdio_cddap_identify_cdio( p_cdio, 1, NULL );
759 /* We'll set for verbose paranoia messages. */
760 cdio_cddap_verbose_set( p_cdda->paranoia_cd,
761 CDDA_MESSAGE_PRINTIT,
762 CDDA_MESSAGE_PRINTIT );
763 if ( 0 != cdio_cddap_open(p_cdda->paranoia_cd) )
765 msg_Warn( p_cdda_input, "unable to get paranoia support - "
766 "continuing without it." );
767 p_cdda->e_paranoia = paranoia_none;
771 p_cdda->paranoia = cdio_paranoia_init(p_cdda->paranoia_cd);
772 cdio_paranoia_seek( p_cdda->paranoia, p_cdda->i_lsn,
775 /* Set reading mode for full or overlap paranoia,
776 * but allow skipping sectors. */
777 cdio_paranoia_modeset( p_cdda->paranoia,
778 paranoia_full == p_cdda->e_paranoia ?
779 PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP :
780 PARANOIA_MODE_OVERLAP^PARANOIA_MODE_NEVERSKIP );
787 /* Build a WAV header to put in front of the output data.
788 This gets sent back in the Block (read) routine.
790 memset( &p_cdda->waveheader, 0, sizeof(WAVEHEADER) );
792 SetWLE( &p_cdda->waveheader.Format, 1 ); /*WAVE_FORMAT_PCM*/
793 SetWLE( &p_cdda->waveheader.BitsPerSample, 16);
795 p_cdda->waveheader.MainChunkID = VLC_FOURCC('R', 'I', 'F', 'F');
796 p_cdda->waveheader.Length = 0; /* we just don't know */
797 p_cdda->waveheader.ChunkTypeID = VLC_FOURCC('W', 'A', 'V', 'E');
798 p_cdda->waveheader.SubChunkID = VLC_FOURCC('f', 'm', 't', ' ');
800 SetDWLE( &p_cdda->waveheader.SubChunkLength, 16);
801 SetWLE( &p_cdda->waveheader.Modus, 2);
802 SetDWLE( &p_cdda->waveheader.SampleFreq, CDDA_FREQUENCY_SAMPLE);
803 SetWLE( &p_cdda->waveheader.BytesPerSample,
804 2 /*Modus*/ * 16 /*BitsPerSample*/ / 8 );
805 SetDWLE( &p_cdda->waveheader.BytesPerSec,
806 2*16/8 /*BytesPerSample*/ * CDDA_FREQUENCY_SAMPLE );
808 p_cdda->waveheader.DataChunkID = VLC_FOURCC('d', 'a', 't', 'a');
809 p_cdda->waveheader.DataLength = 0; /* we just don't know */
812 var_Create( p_access, MODULE_STRING "-caching",
813 VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
814 vlc_object_release( p_cdda->p_input );
818 cdio_destroy( p_cdda->p_cdio );
819 if( psz_source) free( psz_source );
822 if ( p_cdda->p_input )
823 vlc_object_release( p_cdda->p_input );
829 /*****************************************************************************
830 * CDDAClose: closes cdda and frees any resources associded with it.
831 *****************************************************************************/
832 void CDDAClose (vlc_object_t *p_this )
834 access_t *p_access = (access_t *) p_this;
835 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
838 #if LIBCDIO_VERSION_NUM >= 73
839 if( p_cdda->b_audio_ctl )
840 cdio_audio_stop(p_cdda->p_cdio);
843 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "" );
845 /* Remove playlist titles */
846 for( i = 0; i < p_cdda->i_titles; i++ )
848 vlc_input_title_Delete( p_cdda->p_title[i] );
852 cddb_log_set_handler( (cddb_log_handler_t) uninit_log_handler );
853 if( p_cdda->b_cddb_enabled )
854 cddb_disc_destroy( p_cdda->cddb.disc );
857 cdio_destroy( p_cdda->p_cdio );
858 cdio_log_set_handler( uninit_log_handler );
860 #if LIBCDIO_VERSION_NUM >= 72
861 if( p_cdda->paranoia )
862 cdio_paranoia_free(p_cdda->paranoia);
863 if( p_cdda->paranoia_cd )
864 cdio_cddap_close_no_free_cdio( p_cdda->paranoia_cd );
867 if( p_cdda->psz_mcn ) free( p_cdda->psz_mcn );
868 if( p_cdda->psz_source ) free( p_cdda->psz_source );
870 #if LIBCDDB_VERSION_NUM >= 1
878 /*****************************************************************************
879 * Control: The front-end or vlc engine calls here to ether get
880 * information such as meta information or plugin capabilities or to
881 * issue miscellaneous "set" requests.
882 *****************************************************************************/
883 static int CDDAControl( access_t *p_access, int i_query, va_list args )
885 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
889 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_EVENT),
890 "query %d", i_query );
894 /* Pass back a copy of meta information that was gathered when we
895 during the Open/Initialize call.
897 case ACCESS_GET_META:
899 vlc_meta_t **pp_meta = (vlc_meta_t**)va_arg( args, vlc_meta_t** );
903 *pp_meta = vlc_meta_Duplicate( p_cdda->p_meta );
904 dbg_print( INPUT_DBG_META, "%s", "Meta copied" );
910 msg_Warn( p_access, "tried to copy NULL meta info" );
915 case ACCESS_CAN_CONTROL_PACE:
917 vlc_bool_t *pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
918 *pb_bool = p_cdda->b_audio_ctl ? VLC_FALSE : VLC_TRUE;
919 dbg_print( INPUT_DBG_META, "can control pace? %d", *pb_bool);
923 case ACCESS_CAN_FASTSEEK:
924 dbg_print( INPUT_DBG_META, "can fast seek?");
926 case ACCESS_CAN_SEEK:
927 dbg_print( INPUT_DBG_META, "can seek?");
929 case ACCESS_CAN_PAUSE:
930 dbg_print( INPUT_DBG_META, "can pause?");
933 vlc_bool_t *pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
941 pi_int = (int*)va_arg( args, int * );
942 *pi_int = p_cdda-> i_blocks_per_read * CDIO_CD_FRAMESIZE_RAW;
943 dbg_print( INPUT_DBG_META, "Get MTU %d", *pi_int);
947 case ACCESS_GET_PTS_DELAY:
949 int64_t *pi_64 = (int64_t*)va_arg( args, int64_t * );
950 *pi_64 = var_GetInteger( p_access, MODULE_STRING "-caching" )
951 * MILLISECONDS_PER_SEC;
955 case ACCESS_GET_TITLE_INFO:
957 input_title_t ***ppp_title =
958 (input_title_t***)va_arg( args, input_title_t*** );
960 pi_int = (int*)va_arg( args, int* );
961 *((int*)va_arg( args, int* )) = 1; /* Title offset */
963 dbg_print ( INPUT_DBG_EVENT,
964 "GET TITLE: i_tracks %d, i_tracks %d",
965 p_cdda->i_tracks, p_cdda->i_tracks );
967 CDDAMetaInfo( p_access, CDIO_INVALID_TRACK );
969 if( p_cdda->b_nav_mode)
971 char *psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
972 input_Control( p_cdda->p_input, INPUT_SET_NAME, psz_title );
976 /* Duplicate title info */
977 if( p_cdda->i_titles == 0 )
979 *pi_int = 0; ppp_title = NULL;
982 *pi_int = p_cdda->i_titles;
983 *ppp_title = calloc(1, sizeof( input_title_t **)
984 * p_cdda->i_titles );
989 for( i = 0; i < p_cdda->i_titles; i++ )
991 if ( p_cdda->p_title[i] )
994 vlc_input_title_Duplicate( p_cdda->p_title[i] );
1000 case ACCESS_SET_TITLE:
1002 i = (int)va_arg( args, int );
1004 dbg_print( INPUT_DBG_EVENT, "set title %d", i );
1005 if( i != p_access->info.i_title )
1007 const track_t i_track = p_cdda->i_first_track + i;
1009 p_access->info.i_title = i;
1010 if( p_cdda->b_nav_mode)
1013 char *psz_title = CDDAFormatTitle( p_access, i_track );
1014 input_Control( p_cdda->p_input, INPUT_SET_NAME,
1017 p_cdda->i_track = i_track;
1018 i_last_lsn = cdio_get_track_lsn( p_cdda->p_cdio,
1019 CDIO_CDROM_LEADOUT_TRACK );
1020 if( CDIO_INVALID_LSN != i_last_lsn )
1021 p_access->info.i_size = (int64_t) CDIO_CD_FRAMESIZE_RAW
1023 p_access->info.i_pos = (int64_t)
1024 cdio_get_track_lsn( p_cdda->p_cdio, i_track )
1025 * CDIO_CD_FRAMESIZE_RAW;
1029 p_access->info.i_size = p_cdda->p_title[i]->i_size;
1030 p_access->info.i_pos = 0;
1032 p_access->info.i_update = INPUT_UPDATE_TITLE|INPUT_UPDATE_SIZE;
1034 /* Next sector to read */
1035 p_cdda->i_lsn = cdio_get_track_lsn( p_cdda->p_cdio, i_track );
1040 case ACCESS_SET_PAUSE_STATE:
1041 dbg_print( INPUT_DBG_META, "Pause");
1042 if( p_cdda->b_audio_ctl )
1043 cdda_audio_pause( p_cdda->p_cdio );
1046 case ACCESS_SET_SEEKPOINT:
1047 dbg_print( INPUT_DBG_META, "set seekpoint");
1048 return VLC_EGENERIC;
1050 case ACCESS_SET_PRIVATE_ID_STATE:
1051 dbg_print( INPUT_DBG_META, "set private id state");
1052 return VLC_EGENERIC;
1055 msg_Warn( p_access, "unimplemented query in control" );
1056 return VLC_EGENERIC;
1062 /*****************************************************************************
1065 Initialize information pertaining to the CD: the number of tracks,
1066 first track number, LSNs for each track and the leadout. The leadout
1067 information is stored after the last track. The LSN array is
1068 0-origin, same as p_access->info. Add first_track to get what track
1069 number this is on the CD. Note: libcdio uses the real track number.
1071 On input we assume p_cdda->p_cdio and p_cdda->i_track have been set.
1073 We return the VLC-type status, e.g. VLC_SUCCESS, VLC_ENOMEM, etc.
1074 *****************************************************************************/
1075 static int CDDAInit( access_t *p_access, cdda_data_t *p_cdda )
1077 discmode_t discmode = CDIO_DISC_MODE_NO_INFO;
1079 p_cdda->i_tracks = cdio_get_num_tracks( p_cdda->p_cdio );
1080 p_cdda->i_first_track = cdio_get_first_track_num( p_cdda->p_cdio );
1082 discmode = cdio_get_discmode( p_cdda->p_cdio );
1085 case CDIO_DISC_MODE_CD_DA:
1086 case CDIO_DISC_MODE_CD_MIXED:
1087 /* These are possible for CD-DA */
1090 /* These are not possible for CD-DA */
1092 "Disc seems not to be CD-DA. libcdio reports it is %s",
1093 discmode2str[discmode]
1095 return VLC_EGENERIC;
1098 /* Set reading start LSN. */
1099 p_cdda->i_lsn = cdio_get_track_lsn(p_cdda->p_cdio, p_cdda->i_track);