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 */
35 #include <cdio/cdio.h>
36 #include <cdio/logging.h>
37 #include <cdio/cd_types.h>
41 /* #ifdef variables below are defined via config.h via #include vlc above. */
46 #ifdef HAVE_SYS_TYPES_H
47 #include <sys/types.h>
58 /* FIXME: This variable is a hack. Would be nice to eliminate. */
59 access_t *p_cdda_input = NULL;
61 /*****************************************************************************
63 *****************************************************************************/
64 static int CDDARead( access_t *, uint8_t *, int );
65 static block_t *CDDAReadBlocks( access_t * p_access );
66 static int CDDASeek( access_t * p_access, int64_t i_pos );
67 static int CDDAControl( access_t *p_access, int i_query,
70 static int CDDAInit( access_t *p_access, cdda_data_t *p_cdda ) ;
73 /****************************************************************************
75 ****************************************************************************/
77 /* process messages that originate from libcdio.
81 cdio_log_handler( cdio_log_level_t level, const char message[] )
83 cdda_data_t *p_cdda = (cdda_data_t *)p_cdda_input->p_sys;
92 if (p_cdda->i_debug & INPUT_DBG_CDIO)
93 msg_Dbg( p_cdda_input, message);
96 msg_Warn( p_cdda_input, message);
100 msg_Err( p_cdda_input, message);
103 msg_Warn( p_cdda_input, message,
104 "the above message had unknown cdio log level",
111 /*! This routine is called by libcddb routines on error.
115 cddb_log_handler( cddb_log_level_t level, const char message[] )
117 cdda_data_t *p_cdda = (cdda_data_t *)p_cdda_input->p_sys;
122 if( !(p_cdda->i_debug & INPUT_DBG_CDDB) )
124 /* Fall through if to warn case */
126 cdio_log_handler( level, message );
130 #endif /*HAVE_LIBCDDB*/
133 /*! This routine is when vlc is not fully set up (before full initialization)
134 or is not around (before finalization).
137 uninit_log_handler( cdio_log_level_t level, const char message[] )
139 cdda_data_t *p_cdda = NULL;
142 p_cdda = (cdda_data_t *)p_cdda_input->p_sys;
148 if( !p_cdda || !(p_cdda->i_debug & (INPUT_DBG_CDIO|INPUT_DBG_CDDB)) )
150 /* Fall through if to warn case */
152 fprintf( stderr, "WARN: %s\n", message );
155 fprintf( stderr, "ERROR: %s\n", message );
157 case CDIO_LOG_ASSERT:
158 fprintf( stderr, "ASSERT ERROR: %s\n", message );
161 fprintf( stderr, "UNKNOWN ERROR: %s\n%s %d\n", message,
162 "The above message had unknown cdio log level",
166 /* gl_default_cdio_log_handler (level, message); */
169 /* Only used in audio control mode. Gets the current LSN from the
171 static int64_t get_audio_position ( access_t *p_access )
173 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
176 #if LIBCDIO_VERSION_NUM >= 73
177 if( p_cdda->b_audio_ctl )
179 cdio_subchannel_t sub;
180 CdIo_t *p_cdio = p_cdda->p_cdio;
182 if( DRIVER_OP_SUCCESS == cdio_audio_read_subchannel(p_cdio, &sub) )
184 if( (sub.audio_status != CDIO_MMC_READ_SUB_ST_PAUSED) &&
185 (sub.audio_status != CDIO_MMC_READ_SUB_ST_PLAY) )
186 return CDIO_INVALID_LSN;
188 if( ! p_cdda->b_nav_mode )
190 i_offset = cdio_msf_to_lba( (&sub.abs_addr) );
194 i_offset = cdio_msf_to_lba( (&sub.rel_addr) );
199 i_offset = p_cdda->i_lsn;
204 i_offset = p_cdda->i_lsn;
206 i_offset = p_cdda->i_lsn;
212 /*****************************************************************************
213 * CDDAReadBlocks: reads a group of blocks from the CD-DA and returns
214 * an allocated pointer to the data. NULL is returned if no data
215 * read. It is also possible if we haven't read a RIFF header in which
216 * case one that we creaded during Open/Initialization is returned.
217 *****************************************************************************/
218 static block_t * CDDAReadBlocks( access_t * p_access )
221 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
222 int i_blocks = p_cdda->i_blocks_per_read;
224 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_LSN),
225 "called i_lsn: %d i_pos: %lld, size: %lld",
226 p_cdda->i_lsn, p_access->info.i_pos, p_access->info.i_size );
228 /* Check end of file */
229 if( p_access->info.b_eof )
232 if( !p_cdda->b_header )
234 /* Return only the dummy RIFF header we created in Open/Init */
235 p_block = block_New( p_access, sizeof( WAVEHEADER ) );
236 memcpy( p_block->p_buffer, &p_cdda->waveheader, sizeof(WAVEHEADER) );
237 p_cdda->b_header = VLC_TRUE;
241 /* Check end of track */
242 while( p_cdda->i_lsn > cdio_get_track_last_lsn(p_cdda->p_cdio,
247 if( p_cdda->b_nav_mode )
248 go_on = p_cdda->i_lsn > p_cdda->last_disc_frame;
250 go_on = p_cdda->i_track >= p_cdda->i_first_track+p_cdda->i_titles-1 ;
254 dbg_print( (INPUT_DBG_LSN), "EOF");
255 p_access->info.b_eof = VLC_TRUE;
259 p_access->info.i_update |= INPUT_UPDATE_TITLE | INPUT_UPDATE_META;
260 p_access->info.i_title++;
263 if( p_cdda-> b_nav_mode )
265 char *psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
266 input_Control( p_cdda->p_input, INPUT_SET_NAME, psz_title );
271 p_access->info.i_size =
272 p_cdda->p_title[p_access->info.i_title]->i_size;
273 p_access->info.i_pos = 0;
274 p_access->info.i_update |= INPUT_UPDATE_SIZE;
278 /* Possibly adjust i_blocks so we don't read past the end of a track. */
279 if( p_cdda->i_lsn + i_blocks >=
280 cdio_get_track_lsn(p_cdda->p_cdio, p_cdda->i_track+1) )
282 i_blocks = cdio_get_track_lsn( p_cdda->p_cdio, p_cdda->i_track+1 )
286 /* Do the actual reading */
287 p_block = block_New( p_access, i_blocks * CDIO_CD_FRAMESIZE_RAW );
290 msg_Err( p_access, "cannot get a new block of size: %i",
291 i_blocks * CDIO_CD_FRAMESIZE_RAW );
296 #if LIBCDIO_VERSION_NUM >= 72
297 driver_return_code_t rc = DRIVER_OP_SUCCESS;
299 if( p_cdda->e_paranoia && p_cdda->paranoia )
302 for( i = 0; i < i_blocks; i++ )
304 int16_t *p_readbuf = cdio_paranoia_read( p_cdda->paranoia, NULL );
305 char *psz_err = cdio_cddap_errors( p_cdda->paranoia_cd );
306 char *psz_mes = cdio_cddap_messages( p_cdda->paranoia_cd );
308 if( psz_mes || psz_err )
309 msg_Err( p_access, "%s%s\n", psz_mes ? psz_mes: "",
310 psz_err ? psz_err: "" );
312 if( psz_err ) free( psz_err );
313 if( psz_mes ) free( psz_mes );
316 msg_Err( p_access, "paranoia read error on frame %i\n",
320 memcpy( p_block->p_buffer + i * CDIO_CD_FRAMESIZE_RAW,
321 p_readbuf, CDIO_CD_FRAMESIZE_RAW );
326 rc = cdio_read_audio_sectors( p_cdda->p_cdio, p_block->p_buffer,
327 p_cdda->i_lsn, i_blocks );
329 #define DRIVER_OP_SUCCESS 0
331 rc = cdio_read_audio_sectors( p_cdda->p_cdio, p_block->p_buffer,
332 p_cdda->i_lsn, i_blocks);
335 if( rc != DRIVER_OP_SUCCESS )
337 msg_Err( p_access, "could not read %d sectors starting from %lu",
338 i_blocks, (long unsigned int) p_cdda->i_lsn );
339 block_Release( p_block );
341 /* If we had problems above, assume the problem is with
342 the first sector of the read and set to skip it. In
343 the future libcdio may have cdparanoia support.
346 p_access->info.i_pos += CDIO_CD_FRAMESIZE_RAW;
351 p_cdda->i_lsn += i_blocks;
352 p_access->info.i_pos += i_blocks * CDIO_CD_FRAMESIZE_RAW;
357 /*****************************************************************************
358 * CDDARead: Handler for audio control reads the CD-DA.
359 *****************************************************************************/
361 CDDARead( access_t * p_access, uint8_t *p_buffer, int i_len )
363 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
365 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_LSN),
366 "called lsn: %d pos: %lld, size: %lld",
367 p_cdda->i_lsn, p_access->info.i_pos, p_access->info.i_size);
369 /* Check end of file */
370 if( p_access->info.b_eof )
374 lsn_t i_lsn = get_audio_position(p_access);
375 if( CDIO_INVALID_LSN == i_lsn )
377 dbg_print( (INPUT_DBG_LSN), "invalid lsn" );
378 memset( p_buffer, 0, i_len );
382 p_cdda->i_lsn = i_lsn;
383 p_access->info.i_pos = p_cdda->i_lsn * CDIO_CD_FRAMESIZE_RAW;
386 dbg_print( (INPUT_DBG_LSN), "updated lsn: %d", p_cdda->i_lsn );
388 /* Check end of track */
389 while( p_cdda->i_lsn > cdio_get_track_last_lsn( p_cdda->p_cdio,
392 if( p_cdda->i_track >= p_cdda->i_first_track + p_cdda->i_titles - 1 )
394 dbg_print( (INPUT_DBG_LSN), "EOF");
395 p_access->info.b_eof = VLC_TRUE;
398 p_access->info.i_update |= INPUT_UPDATE_TITLE;
399 p_access->info.i_title++;
402 if( p_cdda-> b_nav_mode )
404 char *psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
405 input_Control( p_cdda->p_input, INPUT_SET_NAME, psz_title );
410 p_access->info.i_size =
411 p_cdda->p_title[p_access->info.i_title]->i_size;
412 p_access->info.i_pos = 0;
413 p_access->info.i_update |= INPUT_UPDATE_SIZE;
416 memset( p_buffer, 0, i_len );
420 /*! Pause CD playing via audio control */
421 static bool cdda_audio_pause( CdIo_t *p_cdio )
424 #if LIBCDIO_VERSION_NUM >= 73
425 cdio_subchannel_t sub;
427 if( DRIVER_OP_SUCCESS == cdio_audio_read_subchannel( p_cdio, &sub ) )
429 if( sub.audio_status == CDIO_MMC_READ_SUB_ST_PLAY )
431 b_ok = DRIVER_OP_SUCCESS == cdio_audio_pause(p_cdio);
440 #if LIBCDIO_VERSION_NUM >= 73
441 /*! play CD using audio controls */
442 static driver_return_code_t
443 cdda_audio_play( CdIo_t *p_cdio, lsn_t start_lsn, lsn_t end_lsn )
447 cdio_lsn_to_msf( start_lsn, &start_msf );
448 cdio_lsn_to_msf( end_lsn, &last_msf );
449 cdda_audio_pause( p_cdio );
450 return cdio_audio_play_msf( p_cdio, &start_msf, &last_msf );
454 /****************************************************************************
455 * CDDASeek - change position for subsequent reads. For example, this
456 * can happen if the user moves a position slider bar in a GUI.
457 ****************************************************************************/
458 static int CDDASeek( access_t * p_access, int64_t i_pos )
460 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
462 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_SEEK),
463 "lsn %lu, offset: %lld",
464 (long unsigned int) p_cdda->i_lsn, i_pos );
466 p_cdda->i_lsn = (i_pos / CDIO_CD_FRAMESIZE_RAW);
468 #if LIBCDIO_VERSION_NUM >= 72
469 if( p_cdda->e_paranoia && p_cdda->paranoia )
470 cdio_paranoia_seek( p_cdda->paranoia, p_cdda->i_lsn, SEEK_SET );
473 #if LIBCDIO_VERSION_NUM >= 73
474 if( p_cdda->b_audio_ctl )
476 track_t i_track = cdio_get_track( p_cdda->p_cdio, p_cdda->i_lsn );
479 if( p_cdda->b_nav_mode )
480 i_last_lsn = p_cdda->last_disc_frame;
482 i_last_lsn = cdio_get_track_last_lsn( p_cdda->p_cdio, i_track );
484 cdda_audio_play( p_cdda->p_cdio, p_cdda->i_lsn, i_last_lsn );
488 if( ! p_cdda->b_nav_mode )
489 p_cdda->i_lsn += cdio_get_track_lsn( p_cdda->p_cdio, p_cdda->i_track );
491 /* Seeked backwards and we are doing disc mode. */
492 if( p_cdda->b_nav_mode && p_access->info.i_pos > i_pos )
497 for( i_track = p_cdda->i_track; i_track > 1 &&
498 p_cdda->i_lsn < cdio_get_track_lsn( p_cdda->p_cdio, i_track );
499 i_track--, p_access->info.i_title-- )
502 p_cdda->i_track = i_track;
503 p_access->info.i_update |= INPUT_UPDATE_TITLE | INPUT_UPDATE_META ;
504 psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
505 input_Control( p_cdda->p_input, INPUT_SET_NAME,
510 p_access->info.i_pos = i_pos;
515 Set up internal state so that we play a given track.
516 If we are using audio-ctl mode we also activate CD-ROM
519 static bool cdda_play_track( access_t *p_access, track_t i_track )
521 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
523 dbg_print( (INPUT_DBG_CALL), "called track: %d\n", i_track );
525 if( i_track > p_cdda->i_tracks )
527 msg_Err( p_access, "CD has %d tracks, and you requested track %d",
528 p_cdda->i_tracks, i_track );
531 p_cdda->i_track = i_track;
533 /* set up the frame boundaries for this particular track */
534 p_cdda->first_frame = p_cdda->i_lsn =
535 cdio_get_track_lsn( p_cdda->p_cdio, i_track );
537 p_cdda->last_frame = cdio_get_track_lsn( p_cdda->p_cdio, i_track+1 ) - 1;
539 #if LIBCDIO_VERSION_NUM >= 73
540 if( p_cdda->b_audio_ctl )
543 if( p_cdda->b_nav_mode )
544 i_last_lsn = p_cdda->last_disc_frame;
546 i_last_lsn = cdio_get_track_last_lsn( p_cdda->p_cdio, i_track );
547 cdda_audio_play( p_cdda->p_cdio, p_cdda->i_lsn, i_last_lsn );
553 /****************************************************************************
555 ****************************************************************************/
557 /*****************************************************************************
558 * Open: open cdda device or image file and initialize structures
559 * for subsequent operations.
560 *****************************************************************************/
561 int CDDAOpen( vlc_object_t *p_this )
563 access_t *p_access = (access_t*)p_this;
564 char * psz_source = NULL;
565 cdda_data_t *p_cdda = NULL;
568 vlc_bool_t b_single_track = false;
569 int i_rc = VLC_EGENERIC;
571 p_access->p_sys = NULL;
573 /* Set where to log errors messages from libcdio. */
574 p_cdda_input = p_access;
576 /* parse the options passed in command line : */
577 if( p_access->psz_path && *p_access->psz_path )
579 char *psz_parser = psz_source = strdup( p_access->psz_path );
581 while( *psz_parser && *psz_parser != '@' )
586 if( *psz_parser == '@' )
592 if ('T' == *psz_parser || 't' == *psz_parser )
595 i_track = (int)strtol( psz_parser, NULL, 10 );
596 i_track = i_track ? i_track : 1;
597 b_single_track = true;
601 if( !psz_source || !*psz_source )
603 /* No device/track given. Continue only when this plugin was
605 if( !p_this->b_force )
608 psz_source = var_CreateGetString( p_this, "cd-audio" );
609 if( !psz_source || !*psz_source )
611 /* Scan for a CD-ROM drive with a CD-DA in it. */
613 cdio_get_devices_with_cap( NULL, CDIO_FS_AUDIO, false );
615 if( (NULL == ppsz_drives) || (NULL == ppsz_drives[0]) )
618 "libcdio couldn't find something with a CD-DA in it" );
620 cdio_free_device_list( ppsz_drives );
623 psz_source = strdup( ppsz_drives[0] );
624 cdio_free_device_list( ppsz_drives );
627 cdio_log_set_handler( cdio_log_handler );
630 if( !(p_cdio = cdio_open( psz_source, DRIVER_UNKNOWN )) )
632 msg_Warn( p_access, "could not open %s", psz_source );
638 p_cdda = calloc( 1, sizeof(cdda_data_t) );
641 msg_Err( p_access, "out of memory" );
647 cddb_log_set_handler ( cddb_log_handler );
648 p_cdda->cddb.disc = NULL;
649 p_cdda->b_cddb_enabled =
650 config_GetInt( p_access, MODULE_STRING "-cddb-enabled" );
653 config_GetInt( p_access, MODULE_STRING "-cdtext-enabled" );
654 p_cdda->b_cdtext_prefer =
655 config_GetInt( p_access, MODULE_STRING "-cdtext-prefer" );
656 #if LIBCDIO_VERSION_NUM >= 73
657 p_cdda->b_audio_ctl =
658 config_GetInt( p_access, MODULE_STRING "-analog-output" );
661 p_cdda->psz_source = strdup( psz_source );
662 p_cdda->b_header = VLC_FALSE;
663 p_cdda->p_cdio = p_cdio;
664 p_cdda->i_tracks = 0;
665 p_cdda->i_titles = 0;
666 p_cdda->i_debug = config_GetInt( p_this, MODULE_STRING "-debug" );
667 p_cdda->b_nav_mode = config_GetInt(p_this, MODULE_STRING "-navigation-mode" );
668 p_cdda->i_blocks_per_read =
669 config_GetInt( p_this, MODULE_STRING "-blocks-per-read" );
670 p_cdda->last_disc_frame =
671 cdio_get_track_lsn( p_cdio, CDIO_CDROM_LEADOUT_TRACK );
672 p_cdda->p_input = vlc_object_find( p_access, VLC_OBJECT_INPUT,
675 if( 0 == p_cdda->i_blocks_per_read )
676 p_cdda->i_blocks_per_read = DEFAULT_BLOCKS_PER_READ;
678 if( (p_cdda->i_blocks_per_read < MIN_BLOCKS_PER_READ)
679 || (p_cdda->i_blocks_per_read > MAX_BLOCKS_PER_READ) )
681 msg_Warn( p_cdda_input,
682 "number of blocks (%d) has to be between %d and %d. "
684 p_cdda->i_blocks_per_read,
685 MIN_BLOCKS_PER_READ, MAX_BLOCKS_PER_READ,
686 DEFAULT_BLOCKS_PER_READ );
687 p_cdda->i_blocks_per_read = DEFAULT_BLOCKS_PER_READ;
690 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "%s", psz_source );
692 /* Set up p_access */
693 if( p_cdda->b_audio_ctl )
695 p_access->pf_read = CDDARead;
696 p_access->pf_block = NULL;
700 p_access->pf_read = NULL;
701 p_access->pf_block = CDDAReadBlocks;
704 p_access->pf_control = CDDAControl;
705 p_access->pf_seek = CDDASeek;
710 if( p_cdda->b_nav_mode )
711 i_last_lsn = p_cdda->last_disc_frame;
713 i_last_lsn = cdio_get_track_last_lsn( p_cdio, i_track );
715 if( CDIO_INVALID_LSN != i_last_lsn )
716 p_access->info.i_size = i_last_lsn * (uint64_t) CDIO_CD_FRAMESIZE_RAW;
718 p_access->info.i_size = 0;
721 p_access->info.i_update = 0;
722 p_access->info.b_eof = VLC_FALSE;
723 p_access->info.i_title = 0;
724 p_access->info.i_seekpoint = 0;
726 p_access->p_sys = (access_sys_t *) p_cdda;
728 /* We read the Table Of Content information */
729 i_rc = CDDAInit( p_access, p_cdda );
730 if( VLC_SUCCESS != i_rc )
733 cdda_play_track( p_access, i_track );
734 CDDAFixupPlaylist( p_access, p_cdda, b_single_track );
736 #if LIBCDIO_VERSION_NUM >= 72
738 char *psz_paranoia = config_GetPsz( p_access,
739 MODULE_STRING "-paranoia" );
741 p_cdda->e_paranoia = paranoia_none;
742 if( psz_paranoia && *psz_paranoia )
744 if( !strncmp( psz_paranoia, "full", strlen("full") ) )
745 p_cdda->e_paranoia = paranoia_full;
746 else if( !strncmp(psz_paranoia, "overlap", strlen("overlap")) )
747 p_cdda->e_paranoia = paranoia_overlap;
749 /* Use CD Paranoia? */
750 if( p_cdda->e_paranoia )
752 p_cdda->paranoia_cd =
753 cdio_cddap_identify_cdio( p_cdio, 1, NULL );
754 /* We'll set for verbose paranoia messages. */
755 cdio_cddap_verbose_set( p_cdda->paranoia_cd,
756 CDDA_MESSAGE_PRINTIT,
757 CDDA_MESSAGE_PRINTIT );
758 if ( 0 != cdio_cddap_open(p_cdda->paranoia_cd) )
760 msg_Warn( p_cdda_input, "unable to get paranoia support - "
761 "continuing without it." );
762 p_cdda->e_paranoia = paranoia_none;
766 p_cdda->paranoia = cdio_paranoia_init(p_cdda->paranoia_cd);
767 cdio_paranoia_seek( p_cdda->paranoia, p_cdda->i_lsn,
770 /* Set reading mode for full or overlap paranoia,
771 * but allow skipping sectors. */
772 cdio_paranoia_modeset( p_cdda->paranoia,
773 paranoia_full == p_cdda->e_paranoia ?
774 PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP :
775 PARANOIA_MODE_OVERLAP^PARANOIA_MODE_NEVERSKIP );
782 /* Build a WAV header to put in front of the output data.
783 This gets sent back in the Block (read) routine.
785 memset( &p_cdda->waveheader, 0, sizeof(WAVEHEADER) );
787 SetWLE( &p_cdda->waveheader.Format, 1 ); /*WAVE_FORMAT_PCM*/
788 SetWLE( &p_cdda->waveheader.BitsPerSample, 16);
790 p_cdda->waveheader.MainChunkID = VLC_FOURCC('R', 'I', 'F', 'F');
791 p_cdda->waveheader.Length = 0; /* we just don't know */
792 p_cdda->waveheader.ChunkTypeID = VLC_FOURCC('W', 'A', 'V', 'E');
793 p_cdda->waveheader.SubChunkID = VLC_FOURCC('f', 'm', 't', ' ');
795 SetDWLE( &p_cdda->waveheader.SubChunkLength, 16);
796 SetWLE( &p_cdda->waveheader.Modus, 2);
797 SetDWLE( &p_cdda->waveheader.SampleFreq, CDDA_FREQUENCY_SAMPLE);
798 SetWLE( &p_cdda->waveheader.BytesPerSample,
799 2 /*Modus*/ * 16 /*BitsPerSample*/ / 8 );
800 SetDWLE( &p_cdda->waveheader.BytesPerSec,
801 2*16/8 /*BytesPerSample*/ * CDDA_FREQUENCY_SAMPLE );
803 p_cdda->waveheader.DataChunkID = VLC_FOURCC('d', 'a', 't', 'a');
804 p_cdda->waveheader.DataLength = 0; /* we just don't know */
807 var_Create( p_access, MODULE_STRING "-caching",
808 VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
809 vlc_object_release( p_cdda->p_input );
813 cdio_destroy( p_cdda->p_cdio );
814 if( psz_source) free( psz_source );
817 if ( p_cdda->p_input )
818 vlc_object_release( p_cdda->p_input );
824 /*****************************************************************************
825 * CDDAClose: closes cdda and frees any resources associded with it.
826 *****************************************************************************/
827 void CDDAClose (vlc_object_t *p_this )
829 access_t *p_access = (access_t *) p_this;
830 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
833 #if LIBCDIO_VERSION_NUM >= 73
834 if( p_cdda->b_audio_ctl )
835 cdio_audio_stop(p_cdda->p_cdio);
838 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "" );
840 /* Remove playlist titles */
841 for( i = 0; i < p_cdda->i_titles; i++ )
843 vlc_input_title_Delete( p_cdda->p_title[i] );
847 cddb_log_set_handler( (cddb_log_handler_t) uninit_log_handler );
848 if( p_cdda->b_cddb_enabled )
849 cddb_disc_destroy( p_cdda->cddb.disc );
852 cdio_destroy( p_cdda->p_cdio );
853 cdio_log_set_handler( uninit_log_handler );
855 #if LIBCDIO_VERSION_NUM >= 72
856 if( p_cdda->paranoia )
857 cdio_paranoia_free(p_cdda->paranoia);
858 if( p_cdda->paranoia_cd )
859 cdio_cddap_close_no_free_cdio( p_cdda->paranoia_cd );
862 if( p_cdda->psz_mcn ) free( p_cdda->psz_mcn );
863 if( p_cdda->psz_source ) free( p_cdda->psz_source );
865 #if LIBCDDB_VERSION_NUM >= 1
873 /*****************************************************************************
874 * Control: The front-end or vlc engine calls here to ether get
875 * information such as meta information or plugin capabilities or to
876 * issue miscellaneous "set" requests.
877 *****************************************************************************/
878 static int CDDAControl( access_t *p_access, int i_query, va_list args )
880 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
884 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_EVENT),
885 "query %d", i_query );
889 /* Pass back a copy of meta information that was gathered when we
890 during the Open/Initialize call.
892 case ACCESS_GET_META:
894 vlc_meta_t **pp_meta = (vlc_meta_t**)va_arg( args, vlc_meta_t** );
898 *pp_meta = vlc_meta_Duplicate( p_cdda->p_meta );
899 dbg_print( INPUT_DBG_META, "%s", "Meta copied" );
905 msg_Warn( p_access, "tried to copy NULL meta info" );
910 case ACCESS_CAN_CONTROL_PACE:
912 vlc_bool_t *pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
913 *pb_bool = p_cdda->b_audio_ctl ? VLC_FALSE : VLC_TRUE;
914 dbg_print( INPUT_DBG_META, "can control pace? %d", *pb_bool);
918 case ACCESS_CAN_FASTSEEK:
919 dbg_print( INPUT_DBG_META, "can fast seek?");
921 case ACCESS_CAN_SEEK:
922 dbg_print( INPUT_DBG_META, "can seek?");
924 case ACCESS_CAN_PAUSE:
925 dbg_print( INPUT_DBG_META, "can pause?");
928 vlc_bool_t *pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
936 pi_int = (int*)va_arg( args, int * );
937 *pi_int = p_cdda-> i_blocks_per_read * CDIO_CD_FRAMESIZE_RAW;
938 dbg_print( INPUT_DBG_META, "Get MTU %d", *pi_int);
942 case ACCESS_GET_PTS_DELAY:
944 int64_t *pi_64 = (int64_t*)va_arg( args, int64_t * );
945 *pi_64 = var_GetInteger( p_access, MODULE_STRING "-caching" )
946 * MILLISECONDS_PER_SEC;
950 case ACCESS_GET_TITLE_INFO:
952 input_title_t ***ppp_title =
953 (input_title_t***)va_arg( args, input_title_t*** );
955 pi_int = (int*)va_arg( args, int* );
956 *((int*)va_arg( args, int* )) = 1; /* Title offset */
958 dbg_print ( INPUT_DBG_EVENT,
959 "GET TITLE: i_tracks %d, i_tracks %d",
960 p_cdda->i_tracks, p_cdda->i_tracks );
962 CDDAMetaInfo( p_access, CDIO_INVALID_TRACK );
964 if( p_cdda->b_nav_mode)
966 char *psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
967 input_Control( p_cdda->p_input, INPUT_SET_NAME, psz_title );
971 /* Duplicate title info */
972 if( p_cdda->i_titles == 0 )
974 *pi_int = 0; ppp_title = NULL;
977 *pi_int = p_cdda->i_titles;
978 *ppp_title = calloc(1, sizeof( input_title_t **)
979 * p_cdda->i_titles );
984 for( i = 0; i < p_cdda->i_titles; i++ )
986 if ( p_cdda->p_title[i] )
989 vlc_input_title_Duplicate( p_cdda->p_title[i] );
995 case ACCESS_SET_TITLE:
997 i = (int)va_arg( args, int );
999 dbg_print( INPUT_DBG_EVENT, "set title %d", i );
1000 if( i != p_access->info.i_title )
1002 const track_t i_track = p_cdda->i_first_track + i;
1004 p_access->info.i_title = i;
1005 if( p_cdda->b_nav_mode)
1008 char *psz_title = CDDAFormatTitle( p_access, i_track );
1009 input_Control( p_cdda->p_input, INPUT_SET_NAME,
1012 p_cdda->i_track = i_track;
1013 i_last_lsn = cdio_get_track_lsn( p_cdda->p_cdio,
1014 CDIO_CDROM_LEADOUT_TRACK );
1015 if( CDIO_INVALID_LSN != i_last_lsn )
1016 p_access->info.i_size = (int64_t) CDIO_CD_FRAMESIZE_RAW
1018 p_access->info.i_pos = (int64_t)
1019 cdio_get_track_lsn( p_cdda->p_cdio, i_track )
1020 * CDIO_CD_FRAMESIZE_RAW;
1024 p_access->info.i_size = p_cdda->p_title[i]->i_size;
1025 p_access->info.i_pos = 0;
1027 p_access->info.i_update = INPUT_UPDATE_TITLE|INPUT_UPDATE_SIZE;
1029 /* Next sector to read */
1030 p_cdda->i_lsn = cdio_get_track_lsn( p_cdda->p_cdio, i_track );
1035 case ACCESS_SET_PAUSE_STATE:
1036 dbg_print( INPUT_DBG_META, "Pause");
1037 if( p_cdda->b_audio_ctl )
1038 cdda_audio_pause( p_cdda->p_cdio );
1041 case ACCESS_SET_SEEKPOINT:
1042 dbg_print( INPUT_DBG_META, "set seekpoint");
1043 return VLC_EGENERIC;
1045 case ACCESS_SET_PRIVATE_ID_STATE:
1046 dbg_print( INPUT_DBG_META, "set private id state");
1047 return VLC_EGENERIC;
1050 msg_Warn( p_access, "unimplemented query in control" );
1051 return VLC_EGENERIC;
1057 /*****************************************************************************
1060 Initialize information pertaining to the CD: the number of tracks,
1061 first track number, LSNs for each track and the leadout. The leadout
1062 information is stored after the last track. The LSN array is
1063 0-origin, same as p_access->info. Add first_track to get what track
1064 number this is on the CD. Note: libcdio uses the real track number.
1066 On input we assume p_cdda->p_cdio and p_cdda->i_track have been set.
1068 We return the VLC-type status, e.g. VLC_SUCCESS, VLC_ENOMEM, etc.
1069 *****************************************************************************/
1070 static int CDDAInit( access_t *p_access, cdda_data_t *p_cdda )
1072 discmode_t discmode = CDIO_DISC_MODE_NO_INFO;
1074 p_cdda->i_tracks = cdio_get_num_tracks( p_cdda->p_cdio );
1075 p_cdda->i_first_track = cdio_get_first_track_num( p_cdda->p_cdio );
1077 discmode = cdio_get_discmode( p_cdda->p_cdio );
1080 case CDIO_DISC_MODE_CD_DA:
1081 case CDIO_DISC_MODE_CD_MIXED:
1082 /* These are possible for CD-DA */
1085 /* These are not possible for CD-DA */
1087 "Disc seems not to be CD-DA. libcdio reports it is %s",
1088 discmode2str[discmode]
1090 return VLC_EGENERIC;
1093 /* Set reading start LSN. */
1094 p_cdda->i_lsn = cdio_get_track_lsn(p_cdda->p_cdio, p_cdda->i_track);