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 */
34 #include <vlc_interface.h>
36 #include <cdio/cdio.h>
37 #include <cdio/logging.h>
38 #include <cdio/cd_types.h>
41 /* #ifdef variables below are defined via config.h via #include vlc above. */
43 #ifdef HAVE_SYS_TYPES_H
44 #include <sys/types.h>
51 /* FIXME: This variable is a hack. Would be nice to eliminate. */
52 access_t *p_cdda_input = NULL;
54 /*****************************************************************************
56 *****************************************************************************/
57 static ssize_t CDDARead( access_t *, uint8_t *, size_t );
58 static block_t *CDDAReadBlocks( access_t * p_access );
59 static int CDDASeek( access_t * p_access, int64_t i_pos );
60 static int CDDAControl( access_t *p_access, int i_query,
63 static int CDDAInit( access_t *p_access, cdda_data_t *p_cdda ) ;
66 /****************************************************************************
68 ****************************************************************************/
70 /* process messages that originate from libcdio.
74 cdio_log_handler( cdio_log_level_t level, const char message[] )
76 cdda_data_t *p_cdda = (cdda_data_t *)p_cdda_input->p_sys;
85 if (p_cdda->i_debug & INPUT_DBG_CDIO)
86 msg_Dbg( p_cdda_input, "%s", message);
89 msg_Warn( p_cdda_input, "%s", message);
93 msg_Err( p_cdda_input, "%s", message);
96 msg_Warn( p_cdda_input, "%s\n%s %d", message,
97 "the above message had unknown cdio log level",
104 /*! This routine is called by libcddb routines on error.
108 cddb_log_handler( cddb_log_level_t level, const char message[] )
110 cdda_data_t *p_cdda = (cdda_data_t *)p_cdda_input->p_sys;
115 if( !(p_cdda->i_debug & INPUT_DBG_CDDB) )
117 /* Fall through if to warn case */
119 cdio_log_handler( level, message );
123 #endif /*HAVE_LIBCDDB*/
126 /*! This routine is when vlc is not fully set up (before full initialization)
127 or is not around (before finalization).
130 uninit_log_handler( cdio_log_level_t level, const char message[] )
132 cdda_data_t *p_cdda = NULL;
135 p_cdda = (cdda_data_t *)p_cdda_input->p_sys;
141 if( !p_cdda || !(p_cdda->i_debug & (INPUT_DBG_CDIO|INPUT_DBG_CDDB)) )
143 /* Fall through if to warn case */
145 fprintf( stderr, "WARN: %s\n", message );
148 fprintf( stderr, "ERROR: %s\n", message );
150 case CDIO_LOG_ASSERT:
151 fprintf( stderr, "ASSERT ERROR: %s\n", message );
154 fprintf( stderr, "UNKNOWN ERROR: %s\n%s %d\n", message,
155 "The above message had unknown cdio log level",
159 /* gl_default_cdio_log_handler (level, message); */
162 /* Only used in audio control mode. Gets the current LSN from the
164 static int64_t get_audio_position ( access_t *p_access )
166 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
169 #if LIBCDIO_VERSION_NUM >= 73
170 if( p_cdda->b_audio_ctl )
172 cdio_subchannel_t sub;
173 CdIo_t *p_cdio = p_cdda->p_cdio;
175 if( DRIVER_OP_SUCCESS == cdio_audio_read_subchannel(p_cdio, &sub) )
177 if( (sub.audio_status != CDIO_MMC_READ_SUB_ST_PAUSED) &&
178 (sub.audio_status != CDIO_MMC_READ_SUB_ST_PLAY) )
179 return CDIO_INVALID_LSN;
181 if( ! p_cdda->b_nav_mode )
183 i_offset = cdio_msf_to_lba( (&sub.abs_addr) );
187 i_offset = cdio_msf_to_lba( (&sub.rel_addr) );
192 i_offset = p_cdda->i_lsn;
197 i_offset = p_cdda->i_lsn;
200 i_offset = p_cdda->i_lsn;
205 /*****************************************************************************
206 * CDDAReadBlocks: reads a group of blocks from the CD-DA and returns
207 * an allocated pointer to the data. NULL is returned if no data
208 * read. It is also possible if we haven't read a RIFF header in which
209 * case one that we creaded during Open/Initialization is returned.
210 *****************************************************************************/
211 static block_t * CDDAReadBlocks( access_t * p_access )
214 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
215 int i_blocks = p_cdda->i_blocks_per_read;
217 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_LSN),
218 "called i_lsn: %d i_pos: %lld, size: %lld",
219 p_cdda->i_lsn, p_access->info.i_pos, p_access->info.i_size );
221 /* Check end of file */
222 if( p_access->info.b_eof )
225 if( !p_cdda->b_header )
227 /* Return only the dummy RIFF header we created in Open/Init */
228 p_block = block_New( p_access, sizeof( WAVEHEADER ) );
229 memcpy( p_block->p_buffer, &p_cdda->waveheader, sizeof(WAVEHEADER) );
230 p_cdda->b_header = true;
234 /* Check end of track */
235 while( p_cdda->i_lsn > cdio_get_track_last_lsn(p_cdda->p_cdio,
240 if( p_cdda->b_nav_mode )
241 go_on = p_cdda->i_lsn > p_cdda->last_disc_frame;
243 go_on = p_cdda->i_track >= p_cdda->i_first_track+p_cdda->i_titles-1 ;
247 dbg_print( (INPUT_DBG_LSN), "EOF");
248 p_access->info.b_eof = true;
252 p_access->info.i_update |= INPUT_UPDATE_TITLE | INPUT_UPDATE_META;
253 p_access->info.i_title++;
256 if( p_cdda-> b_nav_mode )
258 char *psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
259 input_Control( p_cdda->p_input, INPUT_SET_NAME, psz_title );
264 p_access->info.i_size =
265 p_cdda->p_title[p_access->info.i_title]->i_size;
266 p_access->info.i_pos = 0;
267 p_access->info.i_update |= INPUT_UPDATE_SIZE;
271 /* Possibly adjust i_blocks so we don't read past the end of a track. */
272 if( p_cdda->i_lsn + i_blocks >=
273 cdio_get_track_lsn(p_cdda->p_cdio, p_cdda->i_track+1) )
275 i_blocks = cdio_get_track_lsn( p_cdda->p_cdio, p_cdda->i_track+1 )
279 /* Do the actual reading */
280 p_block = block_New( p_access, i_blocks * CDIO_CD_FRAMESIZE_RAW );
283 msg_Err( p_access, "cannot get a new block of size: %i",
284 i_blocks * CDIO_CD_FRAMESIZE_RAW );
285 intf_UserFatal( p_access, false, _("CD reading failed"),
286 _("VLC could not get a new block of size: %i."),
287 i_blocks * CDIO_CD_FRAMESIZE_RAW );
292 #if LIBCDIO_VERSION_NUM >= 72
293 driver_return_code_t rc = DRIVER_OP_SUCCESS;
295 if( p_cdda->e_paranoia && p_cdda->paranoia )
298 for( i = 0; i < i_blocks; i++ )
300 int16_t *p_readbuf = cdio_paranoia_read( p_cdda->paranoia, NULL );
301 char *psz_err = cdio_cddap_errors( p_cdda->paranoia_cd );
302 char *psz_mes = cdio_cddap_messages( p_cdda->paranoia_cd );
304 if( psz_mes || psz_err )
305 msg_Err( p_access, "%s%s\n", psz_mes ? psz_mes: "",
306 psz_err ? psz_err: "" );
312 msg_Err( p_access, "paranoia read error on frame %i\n",
316 memcpy( p_block->p_buffer + i * CDIO_CD_FRAMESIZE_RAW,
317 p_readbuf, CDIO_CD_FRAMESIZE_RAW );
322 rc = cdio_read_audio_sectors( p_cdda->p_cdio, p_block->p_buffer,
323 p_cdda->i_lsn, i_blocks );
325 #define DRIVER_OP_SUCCESS 0
327 rc = cdio_read_audio_sectors( p_cdda->p_cdio, p_block->p_buffer,
328 p_cdda->i_lsn, i_blocks);
331 if( rc != DRIVER_OP_SUCCESS )
333 msg_Err( p_access, "could not read %d sectors starting from %lu",
334 i_blocks, (long unsigned int) p_cdda->i_lsn );
335 block_Release( p_block );
337 /* If we had problems above, assume the problem is with
338 the first sector of the read and set to skip it. In
339 the future libcdio may have cdparanoia support.
342 p_access->info.i_pos += CDIO_CD_FRAMESIZE_RAW;
347 p_cdda->i_lsn += i_blocks;
348 p_access->info.i_pos += i_blocks * CDIO_CD_FRAMESIZE_RAW;
353 /*****************************************************************************
354 * CDDARead: Handler for audio control reads the CD-DA.
355 *****************************************************************************/
357 CDDARead( access_t * p_access, uint8_t *p_buffer, size_t i_len )
359 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
361 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_LSN),
362 "called lsn: %d pos: %lld, size: %lld",
363 p_cdda->i_lsn, p_access->info.i_pos, p_access->info.i_size);
365 /* Check end of file */
366 if( p_access->info.b_eof )
370 lsn_t i_lsn = get_audio_position(p_access);
371 if( CDIO_INVALID_LSN == i_lsn )
373 dbg_print( (INPUT_DBG_LSN), "invalid lsn" );
374 memset( p_buffer, 0, i_len );
378 p_cdda->i_lsn = i_lsn;
379 p_access->info.i_pos = p_cdda->i_lsn * CDIO_CD_FRAMESIZE_RAW;
382 dbg_print( (INPUT_DBG_LSN), "updated lsn: %d", p_cdda->i_lsn );
384 /* Check end of track */
385 while( p_cdda->i_lsn > cdio_get_track_last_lsn( p_cdda->p_cdio,
388 if( p_cdda->i_track >= p_cdda->i_first_track + p_cdda->i_titles - 1 )
390 dbg_print( (INPUT_DBG_LSN), "EOF");
391 p_access->info.b_eof = true;
394 p_access->info.i_update |= INPUT_UPDATE_TITLE;
395 p_access->info.i_title++;
398 if( p_cdda-> b_nav_mode )
400 char *psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
401 input_Control( p_cdda->p_input, INPUT_SET_NAME, psz_title );
406 p_access->info.i_size =
407 p_cdda->p_title[p_access->info.i_title]->i_size;
408 p_access->info.i_pos = 0;
409 p_access->info.i_update |= INPUT_UPDATE_SIZE;
412 memset( p_buffer, 0, i_len );
416 /*! Pause CD playing via audio control */
417 static bool cdda_audio_pause( CdIo_t *p_cdio )
420 #if LIBCDIO_VERSION_NUM >= 73
421 cdio_subchannel_t sub;
423 if( DRIVER_OP_SUCCESS == cdio_audio_read_subchannel( p_cdio, &sub ) )
425 if( sub.audio_status == CDIO_MMC_READ_SUB_ST_PLAY )
427 b_ok = DRIVER_OP_SUCCESS == cdio_audio_pause(p_cdio);
436 #if LIBCDIO_VERSION_NUM >= 73
437 /*! play CD using audio controls */
438 static driver_return_code_t
439 cdda_audio_play( CdIo_t *p_cdio, lsn_t start_lsn, lsn_t end_lsn )
443 cdio_lsn_to_msf( start_lsn, &start_msf );
444 cdio_lsn_to_msf( end_lsn, &last_msf );
445 cdda_audio_pause( p_cdio );
446 return cdio_audio_play_msf( p_cdio, &start_msf, &last_msf );
450 /****************************************************************************
451 * CDDASeek - change position for subsequent reads. For example, this
452 * can happen if the user moves a position slider bar in a GUI.
453 ****************************************************************************/
454 static int CDDASeek( access_t * p_access, int64_t i_pos )
456 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
458 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_SEEK),
459 "lsn %lu, offset: %lld",
460 (long unsigned int) p_cdda->i_lsn, i_pos );
462 p_cdda->i_lsn = (i_pos / CDIO_CD_FRAMESIZE_RAW);
464 #if LIBCDIO_VERSION_NUM >= 72
465 if( p_cdda->e_paranoia && p_cdda->paranoia )
466 cdio_paranoia_seek( p_cdda->paranoia, p_cdda->i_lsn, SEEK_SET );
469 #if LIBCDIO_VERSION_NUM >= 73
470 if( p_cdda->b_audio_ctl )
472 track_t i_track = cdio_get_track( p_cdda->p_cdio, p_cdda->i_lsn );
475 if( p_cdda->b_nav_mode )
476 i_last_lsn = p_cdda->last_disc_frame;
478 i_last_lsn = cdio_get_track_last_lsn( p_cdda->p_cdio, i_track );
480 cdda_audio_play( p_cdda->p_cdio, p_cdda->i_lsn, i_last_lsn );
484 if( ! p_cdda->b_nav_mode )
485 p_cdda->i_lsn += cdio_get_track_lsn( p_cdda->p_cdio, p_cdda->i_track );
487 /* Seeked backwards and we are doing disc mode. */
488 if( p_cdda->b_nav_mode && p_access->info.i_pos > i_pos )
493 for( i_track = p_cdda->i_track; i_track > 1 &&
494 p_cdda->i_lsn < cdio_get_track_lsn( p_cdda->p_cdio, i_track );
495 i_track--, p_access->info.i_title-- )
498 p_cdda->i_track = i_track;
499 p_access->info.i_update |= INPUT_UPDATE_TITLE | INPUT_UPDATE_META ;
500 psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
501 input_Control( p_cdda->p_input, INPUT_SET_NAME,
506 p_access->info.i_pos = i_pos;
507 p_access->info.b_eof = false;
512 Set up internal state so that we play a given track.
513 If we are using audio-ctl mode we also activate CD-ROM
516 static bool cdda_play_track( access_t *p_access, track_t i_track )
518 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
520 dbg_print( (INPUT_DBG_CALL), "called track: %d\n", i_track );
522 if( i_track > p_cdda->i_tracks )
524 msg_Err( p_access, "CD has %d tracks, and you requested track %d",
525 p_cdda->i_tracks, i_track );
528 p_cdda->i_track = i_track;
530 /* set up the frame boundaries for this particular track */
531 p_cdda->first_frame = p_cdda->i_lsn =
532 cdio_get_track_lsn( p_cdda->p_cdio, i_track );
534 p_cdda->last_frame = cdio_get_track_lsn( p_cdda->p_cdio, i_track+1 ) - 1;
536 #if LIBCDIO_VERSION_NUM >= 73
537 if( p_cdda->b_audio_ctl )
540 if( p_cdda->b_nav_mode )
541 i_last_lsn = p_cdda->last_disc_frame;
543 i_last_lsn = cdio_get_track_last_lsn( p_cdda->p_cdio, i_track );
544 cdda_audio_play( p_cdda->p_cdio, p_cdda->i_lsn, i_last_lsn );
550 /****************************************************************************
552 ****************************************************************************/
554 /*****************************************************************************
555 * Open: open cdda device or image file and initialize structures
556 * for subsequent operations.
557 *****************************************************************************/
558 int CDDAOpen( vlc_object_t *p_this )
560 access_t *p_access = (access_t*)p_this;
561 char * psz_source = NULL;
562 cdda_data_t *p_cdda = NULL;
565 bool b_single_track = false;
566 int i_rc = VLC_EGENERIC;
568 p_access->p_sys = NULL;
570 /* Set where to log errors messages from libcdio. */
571 p_cdda_input = p_access;
573 /* parse the options passed in command line : */
574 if( p_access->psz_path && *p_access->psz_path )
576 char *psz_parser = psz_source = strdup( p_access->psz_path );
578 while( *psz_parser && *psz_parser != '@' )
583 if( *psz_parser == '@' )
589 if ('T' == *psz_parser || 't' == *psz_parser )
592 i_track = (int)strtol( psz_parser, NULL, 10 );
593 i_track = i_track ? i_track : 1;
594 b_single_track = true;
598 if( !psz_source || !*psz_source )
600 /* No device/track given. Continue only when this plugin was
602 if( !p_this->b_force )
605 psz_source = var_CreateGetString( p_this, "cd-audio" );
606 if( !psz_source || !*psz_source )
608 /* Scan for a CD-ROM drive with a CD-DA in it. */
610 cdio_get_devices_with_cap( NULL, CDIO_FS_AUDIO, false );
612 if( (NULL == ppsz_drives) || (NULL == ppsz_drives[0]) )
615 "libcdio couldn't find something with a CD-DA in it" );
617 cdio_free_device_list( ppsz_drives );
620 psz_source = strdup( ppsz_drives[0] );
621 cdio_free_device_list( ppsz_drives );
624 cdio_log_set_handler( cdio_log_handler );
627 if( !(p_cdio = cdio_open( psz_source, DRIVER_UNKNOWN )) )
629 msg_Warn( p_access, "could not open %s", psz_source );
634 p_cdda = calloc( 1, sizeof(cdda_data_t) );
642 cddb_log_set_handler ( cddb_log_handler );
643 p_cdda->cddb.disc = NULL;
644 p_cdda->b_cddb_enabled =
645 config_GetInt( p_access, MODULE_STRING "-cddb-enabled" );
648 config_GetInt( p_access, MODULE_STRING "-cdtext-enabled" );
649 p_cdda->b_cdtext_prefer =
650 config_GetInt( p_access, MODULE_STRING "-cdtext-prefer" );
651 #if LIBCDIO_VERSION_NUM >= 73
652 p_cdda->b_audio_ctl =
653 config_GetInt( p_access, MODULE_STRING "-analog-output" );
656 p_cdda->psz_source = strdup( psz_source );
657 p_cdda->b_header = false;
658 p_cdda->p_cdio = p_cdio;
659 p_cdda->i_tracks = 0;
660 p_cdda->i_titles = 0;
661 p_cdda->i_debug = config_GetInt( p_this, MODULE_STRING "-debug" );
662 p_cdda->b_nav_mode = config_GetInt(p_this, MODULE_STRING "-navigation-mode" );
663 p_cdda->i_blocks_per_read =
664 config_GetInt( p_this, MODULE_STRING "-blocks-per-read" );
665 p_cdda->last_disc_frame =
666 cdio_get_track_lsn( p_cdio, CDIO_CDROM_LEADOUT_TRACK );
667 p_cdda->p_input = vlc_object_find( p_access, VLC_OBJECT_INPUT,
670 if( 0 == p_cdda->i_blocks_per_read )
671 p_cdda->i_blocks_per_read = DEFAULT_BLOCKS_PER_READ;
673 if( (p_cdda->i_blocks_per_read < MIN_BLOCKS_PER_READ)
674 || (p_cdda->i_blocks_per_read > MAX_BLOCKS_PER_READ) )
676 msg_Warn( p_cdda_input,
677 "number of blocks (%d) has to be between %d and %d. "
679 p_cdda->i_blocks_per_read,
680 MIN_BLOCKS_PER_READ, MAX_BLOCKS_PER_READ,
681 DEFAULT_BLOCKS_PER_READ );
682 p_cdda->i_blocks_per_read = DEFAULT_BLOCKS_PER_READ;
685 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "%s", psz_source );
687 /* Set up p_access */
688 if( p_cdda->b_audio_ctl )
690 p_access->pf_read = CDDARead;
691 p_access->pf_block = NULL;
695 p_access->pf_read = NULL;
696 p_access->pf_block = CDDAReadBlocks;
699 p_access->pf_control = CDDAControl;
700 p_access->pf_seek = CDDASeek;
705 if( p_cdda->b_nav_mode )
706 i_last_lsn = p_cdda->last_disc_frame;
708 i_last_lsn = cdio_get_track_last_lsn( p_cdio, i_track );
710 if( CDIO_INVALID_LSN != i_last_lsn )
711 p_access->info.i_size = i_last_lsn * (uint64_t) CDIO_CD_FRAMESIZE_RAW;
713 p_access->info.i_size = 0;
716 p_access->info.i_update = 0;
717 p_access->info.b_eof = false;
718 p_access->info.i_title = 0;
719 p_access->info.i_seekpoint = 0;
721 p_access->p_sys = (access_sys_t *) p_cdda;
723 /* We read the Table Of Content information */
724 i_rc = CDDAInit( p_access, p_cdda );
725 if( VLC_SUCCESS != i_rc )
728 cdda_play_track( p_access, i_track );
729 CDDAFixupPlaylist( p_access, p_cdda, b_single_track );
731 #if LIBCDIO_VERSION_NUM >= 72
733 char *psz_paranoia = config_GetPsz( p_access,
734 MODULE_STRING "-paranoia" );
736 p_cdda->e_paranoia = PARANOIA_MODE_DISABLE;
737 if( psz_paranoia && *psz_paranoia )
739 if( !strncmp( psz_paranoia, "full", strlen("full") ) )
740 p_cdda->e_paranoia = PARANOIA_MODE_FULL;
741 else if( !strncmp(psz_paranoia, "overlap", strlen("overlap")) )
742 p_cdda->e_paranoia = PARANOIA_MODE_OVERLAP;
744 /* Use CD Paranoia? */
745 if( p_cdda->e_paranoia )
747 p_cdda->paranoia_cd =
748 cdio_cddap_identify_cdio( p_cdio, 1, NULL );
749 /* We'll set for verbose paranoia messages. */
750 cdio_cddap_verbose_set( p_cdda->paranoia_cd,
751 CDDA_MESSAGE_PRINTIT,
752 CDDA_MESSAGE_PRINTIT );
753 if ( 0 != cdio_cddap_open(p_cdda->paranoia_cd) )
755 msg_Warn( p_cdda_input, "unable to get paranoia support - "
756 "continuing without it." );
757 p_cdda->e_paranoia = PARANOIA_MODE_DISABLE;
761 p_cdda->paranoia = cdio_paranoia_init(p_cdda->paranoia_cd);
762 cdio_paranoia_seek( p_cdda->paranoia, p_cdda->i_lsn,
765 /* Set reading mode for full or overlap paranoia,
766 * but allow skipping sectors. */
767 cdio_paranoia_modeset( p_cdda->paranoia,
768 PARANOIA_MODE_FULL == p_cdda->e_paranoia ?
769 PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP :
770 PARANOIA_MODE_OVERLAP^PARANOIA_MODE_NEVERSKIP );
777 /* Build a WAV header to put in front of the output data.
778 This gets sent back in the Block (read) routine.
780 memset( &p_cdda->waveheader, 0, sizeof(WAVEHEADER) );
782 SetWLE( &p_cdda->waveheader.Format, 1 ); /*WAVE_FORMAT_PCM*/
783 SetWLE( &p_cdda->waveheader.BitsPerSample, 16);
785 p_cdda->waveheader.MainChunkID = VLC_FOURCC('R', 'I', 'F', 'F');
786 p_cdda->waveheader.Length = 0; /* we just don't know */
787 p_cdda->waveheader.ChunkTypeID = VLC_FOURCC('W', 'A', 'V', 'E');
788 p_cdda->waveheader.SubChunkID = VLC_FOURCC('f', 'm', 't', ' ');
790 SetDWLE( &p_cdda->waveheader.SubChunkLength, 16);
791 SetWLE( &p_cdda->waveheader.Modus, 2);
792 SetDWLE( &p_cdda->waveheader.SampleFreq, CDDA_FREQUENCY_SAMPLE);
793 SetWLE( &p_cdda->waveheader.BytesPerSample,
794 2 /*Modus*/ * 16 /*BitsPerSample*/ / 8 );
795 SetDWLE( &p_cdda->waveheader.BytesPerSec,
796 2*16/8 /*BytesPerSample*/ * CDDA_FREQUENCY_SAMPLE );
798 p_cdda->waveheader.DataChunkID = VLC_FOURCC('d', 'a', 't', 'a');
799 p_cdda->waveheader.DataLength = 0; /* we just don't know */
802 var_Create( p_access, MODULE_STRING "-caching",
803 VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
804 vlc_object_release( p_cdda->p_input );
808 cdio_destroy( p_cdda->p_cdio );
812 if ( p_cdda->p_input )
813 vlc_object_release( p_cdda->p_input );
819 /*****************************************************************************
820 * CDDAClose: closes cdda and frees any resources associded with it.
821 *****************************************************************************/
822 void CDDAClose (vlc_object_t *p_this )
824 access_t *p_access = (access_t *) p_this;
825 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
828 #if LIBCDIO_VERSION_NUM >= 73
829 if( p_cdda->b_audio_ctl )
830 cdio_audio_stop(p_cdda->p_cdio);
833 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "" );
835 /* Remove playlist titles */
836 for( i = 0; i < p_cdda->i_titles; i++ )
838 vlc_input_title_Delete( p_cdda->p_title[i] );
842 cddb_log_set_handler( (cddb_log_handler_t) uninit_log_handler );
843 if( p_cdda->b_cddb_enabled )
844 cddb_disc_destroy( p_cdda->cddb.disc );
847 cdio_destroy( p_cdda->p_cdio );
848 cdio_log_set_handler( uninit_log_handler );
850 #if LIBCDIO_VERSION_NUM >= 72
851 if( p_cdda->paranoia )
852 cdio_paranoia_free(p_cdda->paranoia);
853 if( p_cdda->paranoia_cd )
854 cdio_cddap_close_no_free_cdio( p_cdda->paranoia_cd );
857 free( p_cdda->psz_mcn );
858 free( p_cdda->psz_source );
860 #if LIBCDDB_VERSION_NUM >= 1
868 /*****************************************************************************
869 * Control: The front-end or vlc engine calls here to ether get
870 * information such as meta information or plugin capabilities or to
871 * issue miscellaneous "set" requests.
872 *****************************************************************************/
873 static int CDDAControl( access_t *p_access, int i_query, va_list args )
875 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
879 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_EVENT),
880 "query %d", i_query );
884 /* Pass back a copy of meta information that was gathered when we
885 during the Open/Initialize call.
887 case ACCESS_GET_META:
890 vlc_meta_t **pp_meta = (vlc_meta_t**)va_arg( args, vlc_meta_t** );
893 *pp_meta = vlc_meta_Duplicate( p_cdda->p_meta );
894 dbg_print( INPUT_DBG_META, "%s", "Meta copied" );
900 msg_Warn( p_access, "tried to copy NULL meta info" );
905 case ACCESS_CAN_CONTROL_PACE:
907 bool *pb_bool = (bool*)va_arg( args, bool* );
908 *pb_bool = p_cdda->b_audio_ctl ? false : true;
909 dbg_print( INPUT_DBG_META, "can control pace? %d", *pb_bool);
913 case ACCESS_CAN_FASTSEEK:
914 dbg_print( INPUT_DBG_META, "can fast seek?");
916 case ACCESS_CAN_SEEK:
917 dbg_print( INPUT_DBG_META, "can seek?");
919 case ACCESS_CAN_PAUSE:
920 dbg_print( INPUT_DBG_META, "can pause?");
923 bool *pb_bool = (bool*)va_arg( args, bool* );
931 pi_int = (int*)va_arg( args, int * );
932 *pi_int = p_cdda-> i_blocks_per_read * CDIO_CD_FRAMESIZE_RAW;
933 dbg_print( INPUT_DBG_META, "Get MTU %d", *pi_int);
937 case ACCESS_GET_PTS_DELAY:
939 int64_t *pi_64 = (int64_t*)va_arg( args, int64_t * );
940 *pi_64 = var_GetInteger( p_access, MODULE_STRING "-caching" )
941 * MILLISECONDS_PER_SEC;
945 case ACCESS_GET_TITLE_INFO:
947 input_title_t ***ppp_title =
948 (input_title_t***)va_arg( args, input_title_t*** );
950 pi_int = (int*)va_arg( args, int* );
951 *((int*)va_arg( args, int* )) = 1; /* Title offset */
953 dbg_print ( INPUT_DBG_EVENT,
954 "GET TITLE: i_tracks %d, i_tracks %d",
955 p_cdda->i_tracks, p_cdda->i_tracks );
957 CDDAMetaInfo( p_access, CDIO_INVALID_TRACK );
959 if( p_cdda->b_nav_mode)
961 char *psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
962 input_Control( p_cdda->p_input, INPUT_SET_NAME, psz_title );
966 /* Duplicate title info */
967 if( p_cdda->i_titles == 0 )
969 *pi_int = 0; ppp_title = NULL;
972 *pi_int = p_cdda->i_titles;
973 *ppp_title = calloc(1, sizeof( input_title_t **)
974 * p_cdda->i_titles );
979 for( i = 0; i < p_cdda->i_titles; i++ )
981 if ( p_cdda->p_title[i] )
984 vlc_input_title_Duplicate( p_cdda->p_title[i] );
990 case ACCESS_SET_TITLE:
992 i = (int)va_arg( args, int );
994 dbg_print( INPUT_DBG_EVENT, "set title %d", i );
995 if( i != p_access->info.i_title )
997 const track_t i_track = p_cdda->i_first_track + i;
999 p_access->info.i_title = i;
1000 if( p_cdda->b_nav_mode)
1003 char *psz_title = CDDAFormatTitle( p_access, i_track );
1004 input_Control( p_cdda->p_input, INPUT_SET_NAME,
1007 p_cdda->i_track = i_track;
1008 i_last_lsn = cdio_get_track_lsn( p_cdda->p_cdio,
1009 CDIO_CDROM_LEADOUT_TRACK );
1010 if( CDIO_INVALID_LSN != i_last_lsn )
1011 p_access->info.i_size = (int64_t) CDIO_CD_FRAMESIZE_RAW
1013 p_access->info.i_pos = (int64_t)
1014 cdio_get_track_lsn( p_cdda->p_cdio, i_track )
1015 * CDIO_CD_FRAMESIZE_RAW;
1019 p_access->info.i_size = p_cdda->p_title[i]->i_size;
1020 p_access->info.i_pos = 0;
1022 p_access->info.i_update = INPUT_UPDATE_TITLE|INPUT_UPDATE_SIZE;
1024 /* Next sector to read */
1025 p_cdda->i_lsn = cdio_get_track_lsn( p_cdda->p_cdio, i_track );
1030 case ACCESS_SET_PAUSE_STATE:
1031 dbg_print( INPUT_DBG_META, "Pause");
1032 if( p_cdda->b_audio_ctl )
1033 cdda_audio_pause( p_cdda->p_cdio );
1036 case ACCESS_SET_SEEKPOINT:
1037 dbg_print( INPUT_DBG_META, "set seekpoint");
1038 return VLC_EGENERIC;
1040 case ACCESS_SET_PRIVATE_ID_STATE:
1041 dbg_print( INPUT_DBG_META, "set private id state");
1042 return VLC_EGENERIC;
1045 msg_Warn( p_access, "unimplemented query in control" );
1046 return VLC_EGENERIC;
1052 /*****************************************************************************
1055 Initialize information pertaining to the CD: the number of tracks,
1056 first track number, LSNs for each track and the leadout. The leadout
1057 information is stored after the last track. The LSN array is
1058 0-origin, same as p_access->info. Add first_track to get what track
1059 number this is on the CD. Note: libcdio uses the real track number.
1061 On input we assume p_cdda->p_cdio and p_cdda->i_track have been set.
1063 We return the VLC-type status, e.g. VLC_SUCCESS, VLC_ENOMEM, etc.
1064 *****************************************************************************/
1065 static int CDDAInit( access_t *p_access, cdda_data_t *p_cdda )
1067 discmode_t discmode = CDIO_DISC_MODE_NO_INFO;
1069 p_cdda->i_tracks = cdio_get_num_tracks( p_cdda->p_cdio );
1070 p_cdda->i_first_track = cdio_get_first_track_num( p_cdda->p_cdio );
1072 discmode = cdio_get_discmode( p_cdda->p_cdio );
1075 case CDIO_DISC_MODE_CD_DA:
1076 case CDIO_DISC_MODE_CD_MIXED:
1077 /* These are possible for CD-DA */
1080 /* These are not possible for CD-DA */
1082 "Disc seems not to be CD-DA. libcdio reports it is %s",
1083 discmode2str[discmode]
1085 return VLC_EGENERIC;
1088 /* Set reading start LSN. */
1089 p_cdda->i_lsn = cdio_get_track_lsn(p_cdda->p_cdio, p_cdda->i_track);