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 */
33 #include <vlc_playlist.h> /* Has to come *after* cdda.h */
35 #include <vlc_interface.h>
37 #include <cdio/cdio.h>
38 #include <cdio/logging.h>
39 #include <cdio/cd_types.h>
42 /* #ifdef variables below are defined via config.h via #include vlc above. */
46 #ifdef HAVE_SYS_TYPES_H
47 #include <sys/types.h>
57 /* FIXME: This variable is a hack. Would be nice to eliminate. */
58 access_t *p_cdda_input = NULL;
60 /*****************************************************************************
62 *****************************************************************************/
63 static int CDDARead( access_t *, uint8_t *, int );
64 static block_t *CDDAReadBlocks( access_t * p_access );
65 static int CDDASeek( access_t * p_access, int64_t i_pos );
66 static int CDDAControl( access_t *p_access, int i_query,
69 static int CDDAInit( access_t *p_access, cdda_data_t *p_cdda ) ;
72 /****************************************************************************
74 ****************************************************************************/
76 /* process messages that originate from libcdio.
80 cdio_log_handler( cdio_log_level_t level, const char message[] )
82 cdda_data_t *p_cdda = (cdda_data_t *)p_cdda_input->p_sys;
91 if (p_cdda->i_debug & INPUT_DBG_CDIO)
92 msg_Dbg( p_cdda_input, "%s", message);
95 msg_Warn( p_cdda_input, "%s", message);
99 msg_Err( p_cdda_input, "%s", message);
102 msg_Warn( p_cdda_input, "%s\n%s %d", message,
103 "the above message had unknown cdio log level",
110 /*! This routine is called by libcddb routines on error.
114 cddb_log_handler( cddb_log_level_t level, const char message[] )
116 cdda_data_t *p_cdda = (cdda_data_t *)p_cdda_input->p_sys;
121 if( !(p_cdda->i_debug & INPUT_DBG_CDDB) )
123 /* Fall through if to warn case */
125 cdio_log_handler( level, message );
129 #endif /*HAVE_LIBCDDB*/
132 /*! This routine is when vlc is not fully set up (before full initialization)
133 or is not around (before finalization).
136 uninit_log_handler( cdio_log_level_t level, const char message[] )
138 cdda_data_t *p_cdda = NULL;
141 p_cdda = (cdda_data_t *)p_cdda_input->p_sys;
147 if( !p_cdda || !(p_cdda->i_debug & (INPUT_DBG_CDIO|INPUT_DBG_CDDB)) )
149 /* Fall through if to warn case */
151 fprintf( stderr, "WARN: %s\n", message );
154 fprintf( stderr, "ERROR: %s\n", message );
156 case CDIO_LOG_ASSERT:
157 fprintf( stderr, "ASSERT ERROR: %s\n", message );
160 fprintf( stderr, "UNKNOWN ERROR: %s\n%s %d\n", message,
161 "The above message had unknown cdio log level",
165 /* gl_default_cdio_log_handler (level, message); */
168 /* Only used in audio control mode. Gets the current LSN from the
170 static int64_t get_audio_position ( access_t *p_access )
172 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
175 #if LIBCDIO_VERSION_NUM >= 73
176 if( p_cdda->b_audio_ctl )
178 cdio_subchannel_t sub;
179 CdIo_t *p_cdio = p_cdda->p_cdio;
181 if( DRIVER_OP_SUCCESS == cdio_audio_read_subchannel(p_cdio, &sub) )
183 if( (sub.audio_status != CDIO_MMC_READ_SUB_ST_PAUSED) &&
184 (sub.audio_status != CDIO_MMC_READ_SUB_ST_PLAY) )
185 return CDIO_INVALID_LSN;
187 if( ! p_cdda->b_nav_mode )
189 i_offset = cdio_msf_to_lba( (&sub.abs_addr) );
193 i_offset = cdio_msf_to_lba( (&sub.rel_addr) );
198 i_offset = p_cdda->i_lsn;
203 i_offset = p_cdda->i_lsn;
206 i_offset = p_cdda->i_lsn;
211 /*****************************************************************************
212 * CDDAReadBlocks: reads a group of blocks from the CD-DA and returns
213 * an allocated pointer to the data. NULL is returned if no data
214 * read. It is also possible if we haven't read a RIFF header in which
215 * case one that we creaded during Open/Initialization is returned.
216 *****************************************************************************/
217 static block_t * CDDAReadBlocks( access_t * p_access )
220 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
221 int i_blocks = p_cdda->i_blocks_per_read;
223 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_LSN),
224 "called i_lsn: %d i_pos: %lld, size: %lld",
225 p_cdda->i_lsn, p_access->info.i_pos, p_access->info.i_size );
227 /* Check end of file */
228 if( p_access->info.b_eof )
231 if( !p_cdda->b_header )
233 /* Return only the dummy RIFF header we created in Open/Init */
234 p_block = block_New( p_access, sizeof( WAVEHEADER ) );
235 memcpy( p_block->p_buffer, &p_cdda->waveheader, sizeof(WAVEHEADER) );
236 p_cdda->b_header = VLC_TRUE;
240 /* Check end of track */
241 while( p_cdda->i_lsn > cdio_get_track_last_lsn(p_cdda->p_cdio,
246 if( p_cdda->b_nav_mode )
247 go_on = p_cdda->i_lsn > p_cdda->last_disc_frame;
249 go_on = p_cdda->i_track >= p_cdda->i_first_track+p_cdda->i_titles-1 ;
253 dbg_print( (INPUT_DBG_LSN), "EOF");
254 p_access->info.b_eof = VLC_TRUE;
258 p_access->info.i_update |= INPUT_UPDATE_TITLE | INPUT_UPDATE_META;
259 p_access->info.i_title++;
262 if( p_cdda-> b_nav_mode )
264 char *psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
265 input_Control( p_cdda->p_input, INPUT_SET_NAME, psz_title );
270 p_access->info.i_size =
271 p_cdda->p_title[p_access->info.i_title]->i_size;
272 p_access->info.i_pos = 0;
273 p_access->info.i_update |= INPUT_UPDATE_SIZE;
277 /* Possibly adjust i_blocks so we don't read past the end of a track. */
278 if( p_cdda->i_lsn + i_blocks >=
279 cdio_get_track_lsn(p_cdda->p_cdio, p_cdda->i_track+1) )
281 i_blocks = cdio_get_track_lsn( p_cdda->p_cdio, p_cdda->i_track+1 )
285 /* Do the actual reading */
286 p_block = block_New( p_access, i_blocks * CDIO_CD_FRAMESIZE_RAW );
289 msg_Err( p_access, "cannot get a new block of size: %i",
290 i_blocks * CDIO_CD_FRAMESIZE_RAW );
291 intf_UserFatal( p_access, VLC_FALSE, _("CD reading failed"),
292 _("VLC could not get a new block of size: %i."),
293 i_blocks * CDIO_CD_FRAMESIZE_RAW );
298 #if LIBCDIO_VERSION_NUM >= 72
299 driver_return_code_t rc = DRIVER_OP_SUCCESS;
301 if( p_cdda->e_paranoia && p_cdda->paranoia )
304 for( i = 0; i < i_blocks; i++ )
306 int16_t *p_readbuf = cdio_paranoia_read( p_cdda->paranoia, NULL );
307 char *psz_err = cdio_cddap_errors( p_cdda->paranoia_cd );
308 char *psz_mes = cdio_cddap_messages( p_cdda->paranoia_cd );
310 if( psz_mes || psz_err )
311 msg_Err( p_access, "%s%s\n", psz_mes ? psz_mes: "",
312 psz_err ? psz_err: "" );
314 if( psz_err ) free( psz_err );
315 if( psz_mes ) free( psz_mes );
318 msg_Err( p_access, "paranoia read error on frame %i\n",
322 memcpy( p_block->p_buffer + i * CDIO_CD_FRAMESIZE_RAW,
323 p_readbuf, CDIO_CD_FRAMESIZE_RAW );
328 rc = cdio_read_audio_sectors( p_cdda->p_cdio, p_block->p_buffer,
329 p_cdda->i_lsn, i_blocks );
331 #define DRIVER_OP_SUCCESS 0
333 rc = cdio_read_audio_sectors( p_cdda->p_cdio, p_block->p_buffer,
334 p_cdda->i_lsn, i_blocks);
337 if( rc != DRIVER_OP_SUCCESS )
339 msg_Err( p_access, "could not read %d sectors starting from %lu",
340 i_blocks, (long unsigned int) p_cdda->i_lsn );
341 block_Release( p_block );
343 /* If we had problems above, assume the problem is with
344 the first sector of the read and set to skip it. In
345 the future libcdio may have cdparanoia support.
348 p_access->info.i_pos += CDIO_CD_FRAMESIZE_RAW;
353 p_cdda->i_lsn += i_blocks;
354 p_access->info.i_pos += i_blocks * CDIO_CD_FRAMESIZE_RAW;
359 /*****************************************************************************
360 * CDDARead: Handler for audio control reads the CD-DA.
361 *****************************************************************************/
363 CDDARead( access_t * p_access, uint8_t *p_buffer, int i_len )
365 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
367 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_LSN),
368 "called lsn: %d pos: %lld, size: %lld",
369 p_cdda->i_lsn, p_access->info.i_pos, p_access->info.i_size);
371 /* Check end of file */
372 if( p_access->info.b_eof )
376 lsn_t i_lsn = get_audio_position(p_access);
377 if( CDIO_INVALID_LSN == i_lsn )
379 dbg_print( (INPUT_DBG_LSN), "invalid lsn" );
380 memset( p_buffer, 0, i_len );
384 p_cdda->i_lsn = i_lsn;
385 p_access->info.i_pos = p_cdda->i_lsn * CDIO_CD_FRAMESIZE_RAW;
388 dbg_print( (INPUT_DBG_LSN), "updated lsn: %d", p_cdda->i_lsn );
390 /* Check end of track */
391 while( p_cdda->i_lsn > cdio_get_track_last_lsn( p_cdda->p_cdio,
394 if( p_cdda->i_track >= p_cdda->i_first_track + p_cdda->i_titles - 1 )
396 dbg_print( (INPUT_DBG_LSN), "EOF");
397 p_access->info.b_eof = VLC_TRUE;
400 p_access->info.i_update |= INPUT_UPDATE_TITLE;
401 p_access->info.i_title++;
404 if( p_cdda-> b_nav_mode )
406 char *psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
407 input_Control( p_cdda->p_input, INPUT_SET_NAME, psz_title );
412 p_access->info.i_size =
413 p_cdda->p_title[p_access->info.i_title]->i_size;
414 p_access->info.i_pos = 0;
415 p_access->info.i_update |= INPUT_UPDATE_SIZE;
418 memset( p_buffer, 0, i_len );
422 /*! Pause CD playing via audio control */
423 static bool cdda_audio_pause( CdIo_t *p_cdio )
426 #if LIBCDIO_VERSION_NUM >= 73
427 cdio_subchannel_t sub;
429 if( DRIVER_OP_SUCCESS == cdio_audio_read_subchannel( p_cdio, &sub ) )
431 if( sub.audio_status == CDIO_MMC_READ_SUB_ST_PLAY )
433 b_ok = DRIVER_OP_SUCCESS == cdio_audio_pause(p_cdio);
442 #if LIBCDIO_VERSION_NUM >= 73
443 /*! play CD using audio controls */
444 static driver_return_code_t
445 cdda_audio_play( CdIo_t *p_cdio, lsn_t start_lsn, lsn_t end_lsn )
449 cdio_lsn_to_msf( start_lsn, &start_msf );
450 cdio_lsn_to_msf( end_lsn, &last_msf );
451 cdda_audio_pause( p_cdio );
452 return cdio_audio_play_msf( p_cdio, &start_msf, &last_msf );
456 /****************************************************************************
457 * CDDASeek - change position for subsequent reads. For example, this
458 * can happen if the user moves a position slider bar in a GUI.
459 ****************************************************************************/
460 static int CDDASeek( access_t * p_access, int64_t i_pos )
462 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
464 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_SEEK),
465 "lsn %lu, offset: %lld",
466 (long unsigned int) p_cdda->i_lsn, i_pos );
468 p_cdda->i_lsn = (i_pos / CDIO_CD_FRAMESIZE_RAW);
470 #if LIBCDIO_VERSION_NUM >= 72
471 if( p_cdda->e_paranoia && p_cdda->paranoia )
472 cdio_paranoia_seek( p_cdda->paranoia, p_cdda->i_lsn, SEEK_SET );
475 #if LIBCDIO_VERSION_NUM >= 73
476 if( p_cdda->b_audio_ctl )
478 track_t i_track = cdio_get_track( p_cdda->p_cdio, p_cdda->i_lsn );
481 if( p_cdda->b_nav_mode )
482 i_last_lsn = p_cdda->last_disc_frame;
484 i_last_lsn = cdio_get_track_last_lsn( p_cdda->p_cdio, i_track );
486 cdda_audio_play( p_cdda->p_cdio, p_cdda->i_lsn, i_last_lsn );
490 if( ! p_cdda->b_nav_mode )
491 p_cdda->i_lsn += cdio_get_track_lsn( p_cdda->p_cdio, p_cdda->i_track );
493 /* Seeked backwards and we are doing disc mode. */
494 if( p_cdda->b_nav_mode && p_access->info.i_pos > i_pos )
499 for( i_track = p_cdda->i_track; i_track > 1 &&
500 p_cdda->i_lsn < cdio_get_track_lsn( p_cdda->p_cdio, i_track );
501 i_track--, p_access->info.i_title-- )
504 p_cdda->i_track = i_track;
505 p_access->info.i_update |= INPUT_UPDATE_TITLE | INPUT_UPDATE_META ;
506 psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
507 input_Control( p_cdda->p_input, INPUT_SET_NAME,
512 p_access->info.i_pos = i_pos;
513 p_access->info.b_eof = VLC_FALSE;
518 Set up internal state so that we play a given track.
519 If we are using audio-ctl mode we also activate CD-ROM
522 static bool cdda_play_track( access_t *p_access, track_t i_track )
524 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
526 dbg_print( (INPUT_DBG_CALL), "called track: %d\n", i_track );
528 if( i_track > p_cdda->i_tracks )
530 msg_Err( p_access, "CD has %d tracks, and you requested track %d",
531 p_cdda->i_tracks, i_track );
534 p_cdda->i_track = i_track;
536 /* set up the frame boundaries for this particular track */
537 p_cdda->first_frame = p_cdda->i_lsn =
538 cdio_get_track_lsn( p_cdda->p_cdio, i_track );
540 p_cdda->last_frame = cdio_get_track_lsn( p_cdda->p_cdio, i_track+1 ) - 1;
542 #if LIBCDIO_VERSION_NUM >= 73
543 if( p_cdda->b_audio_ctl )
546 if( p_cdda->b_nav_mode )
547 i_last_lsn = p_cdda->last_disc_frame;
549 i_last_lsn = cdio_get_track_last_lsn( p_cdda->p_cdio, i_track );
550 cdda_audio_play( p_cdda->p_cdio, p_cdda->i_lsn, i_last_lsn );
556 /****************************************************************************
558 ****************************************************************************/
560 /*****************************************************************************
561 * Open: open cdda device or image file and initialize structures
562 * for subsequent operations.
563 *****************************************************************************/
564 int CDDAOpen( vlc_object_t *p_this )
566 access_t *p_access = (access_t*)p_this;
567 char * psz_source = NULL;
568 cdda_data_t *p_cdda = NULL;
571 vlc_bool_t b_single_track = false;
572 int i_rc = VLC_EGENERIC;
574 p_access->p_sys = NULL;
576 /* Set where to log errors messages from libcdio. */
577 p_cdda_input = p_access;
579 /* parse the options passed in command line : */
580 if( p_access->psz_path && *p_access->psz_path )
582 char *psz_parser = psz_source = strdup( p_access->psz_path );
584 while( *psz_parser && *psz_parser != '@' )
589 if( *psz_parser == '@' )
595 if ('T' == *psz_parser || 't' == *psz_parser )
598 i_track = (int)strtol( psz_parser, NULL, 10 );
599 i_track = i_track ? i_track : 1;
600 b_single_track = true;
604 if( !psz_source || !*psz_source )
606 /* No device/track given. Continue only when this plugin was
608 if( !p_this->b_force )
611 psz_source = var_CreateGetString( p_this, "cd-audio" );
612 if( !psz_source || !*psz_source )
614 /* Scan for a CD-ROM drive with a CD-DA in it. */
616 cdio_get_devices_with_cap( NULL, CDIO_FS_AUDIO, false );
618 if( (NULL == ppsz_drives) || (NULL == ppsz_drives[0]) )
621 "libcdio couldn't find something with a CD-DA in it" );
623 cdio_free_device_list( ppsz_drives );
626 psz_source = strdup( ppsz_drives[0] );
627 cdio_free_device_list( ppsz_drives );
630 cdio_log_set_handler( cdio_log_handler );
633 if( !(p_cdio = cdio_open( psz_source, DRIVER_UNKNOWN )) )
635 msg_Warn( p_access, "could not open %s", psz_source );
641 p_cdda = calloc( 1, sizeof(cdda_data_t) );
644 msg_Err( p_access, "out of memory" );
650 cddb_log_set_handler ( cddb_log_handler );
651 p_cdda->cddb.disc = NULL;
652 p_cdda->b_cddb_enabled =
653 config_GetInt( p_access, MODULE_STRING "-cddb-enabled" );
656 config_GetInt( p_access, MODULE_STRING "-cdtext-enabled" );
657 p_cdda->b_cdtext_prefer =
658 config_GetInt( p_access, MODULE_STRING "-cdtext-prefer" );
659 #if LIBCDIO_VERSION_NUM >= 73
660 p_cdda->b_audio_ctl =
661 config_GetInt( p_access, MODULE_STRING "-analog-output" );
664 p_cdda->psz_source = strdup( psz_source );
665 p_cdda->b_header = VLC_FALSE;
666 p_cdda->p_cdio = p_cdio;
667 p_cdda->i_tracks = 0;
668 p_cdda->i_titles = 0;
669 p_cdda->i_debug = config_GetInt( p_this, MODULE_STRING "-debug" );
670 p_cdda->b_nav_mode = config_GetInt(p_this, MODULE_STRING "-navigation-mode" );
671 p_cdda->i_blocks_per_read =
672 config_GetInt( p_this, MODULE_STRING "-blocks-per-read" );
673 p_cdda->last_disc_frame =
674 cdio_get_track_lsn( p_cdio, CDIO_CDROM_LEADOUT_TRACK );
675 p_cdda->p_input = vlc_object_find( p_access, VLC_OBJECT_INPUT,
678 if( 0 == p_cdda->i_blocks_per_read )
679 p_cdda->i_blocks_per_read = DEFAULT_BLOCKS_PER_READ;
681 if( (p_cdda->i_blocks_per_read < MIN_BLOCKS_PER_READ)
682 || (p_cdda->i_blocks_per_read > MAX_BLOCKS_PER_READ) )
684 msg_Warn( p_cdda_input,
685 "number of blocks (%d) has to be between %d and %d. "
687 p_cdda->i_blocks_per_read,
688 MIN_BLOCKS_PER_READ, MAX_BLOCKS_PER_READ,
689 DEFAULT_BLOCKS_PER_READ );
690 p_cdda->i_blocks_per_read = DEFAULT_BLOCKS_PER_READ;
693 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "%s", psz_source );
695 /* Set up p_access */
696 if( p_cdda->b_audio_ctl )
698 p_access->pf_read = CDDARead;
699 p_access->pf_block = NULL;
703 p_access->pf_read = NULL;
704 p_access->pf_block = CDDAReadBlocks;
707 p_access->pf_control = CDDAControl;
708 p_access->pf_seek = CDDASeek;
713 if( p_cdda->b_nav_mode )
714 i_last_lsn = p_cdda->last_disc_frame;
716 i_last_lsn = cdio_get_track_last_lsn( p_cdio, i_track );
718 if( CDIO_INVALID_LSN != i_last_lsn )
719 p_access->info.i_size = i_last_lsn * (uint64_t) CDIO_CD_FRAMESIZE_RAW;
721 p_access->info.i_size = 0;
724 p_access->info.i_update = 0;
725 p_access->info.b_eof = VLC_FALSE;
726 p_access->info.i_title = 0;
727 p_access->info.i_seekpoint = 0;
729 p_access->p_sys = (access_sys_t *) p_cdda;
731 /* We read the Table Of Content information */
732 i_rc = CDDAInit( p_access, p_cdda );
733 if( VLC_SUCCESS != i_rc )
736 cdda_play_track( p_access, i_track );
737 CDDAFixupPlaylist( p_access, p_cdda, b_single_track );
739 #if LIBCDIO_VERSION_NUM >= 72
741 char *psz_paranoia = config_GetPsz( p_access,
742 MODULE_STRING "-paranoia" );
744 p_cdda->e_paranoia = PARANOIA_MODE_DISABLE;
745 if( psz_paranoia && *psz_paranoia )
747 if( !strncmp( psz_paranoia, "full", strlen("full") ) )
748 p_cdda->e_paranoia = PARANOIA_MODE_FULL;
749 else if( !strncmp(psz_paranoia, "overlap", strlen("overlap")) )
750 p_cdda->e_paranoia = PARANOIA_MODE_OVERLAP;
752 /* Use CD Paranoia? */
753 if( p_cdda->e_paranoia )
755 p_cdda->paranoia_cd =
756 cdio_cddap_identify_cdio( p_cdio, 1, NULL );
757 /* We'll set for verbose paranoia messages. */
758 cdio_cddap_verbose_set( p_cdda->paranoia_cd,
759 CDDA_MESSAGE_PRINTIT,
760 CDDA_MESSAGE_PRINTIT );
761 if ( 0 != cdio_cddap_open(p_cdda->paranoia_cd) )
763 msg_Warn( p_cdda_input, "unable to get paranoia support - "
764 "continuing without it." );
765 p_cdda->e_paranoia = PARANOIA_MODE_DISABLE;
769 p_cdda->paranoia = cdio_paranoia_init(p_cdda->paranoia_cd);
770 cdio_paranoia_seek( p_cdda->paranoia, p_cdda->i_lsn,
773 /* Set reading mode for full or overlap paranoia,
774 * but allow skipping sectors. */
775 cdio_paranoia_modeset( p_cdda->paranoia,
776 PARANOIA_MODE_FULL == p_cdda->e_paranoia ?
777 PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP :
778 PARANOIA_MODE_OVERLAP^PARANOIA_MODE_NEVERSKIP );
785 /* Build a WAV header to put in front of the output data.
786 This gets sent back in the Block (read) routine.
788 memset( &p_cdda->waveheader, 0, sizeof(WAVEHEADER) );
790 SetWLE( &p_cdda->waveheader.Format, 1 ); /*WAVE_FORMAT_PCM*/
791 SetWLE( &p_cdda->waveheader.BitsPerSample, 16);
793 p_cdda->waveheader.MainChunkID = VLC_FOURCC('R', 'I', 'F', 'F');
794 p_cdda->waveheader.Length = 0; /* we just don't know */
795 p_cdda->waveheader.ChunkTypeID = VLC_FOURCC('W', 'A', 'V', 'E');
796 p_cdda->waveheader.SubChunkID = VLC_FOURCC('f', 'm', 't', ' ');
798 SetDWLE( &p_cdda->waveheader.SubChunkLength, 16);
799 SetWLE( &p_cdda->waveheader.Modus, 2);
800 SetDWLE( &p_cdda->waveheader.SampleFreq, CDDA_FREQUENCY_SAMPLE);
801 SetWLE( &p_cdda->waveheader.BytesPerSample,
802 2 /*Modus*/ * 16 /*BitsPerSample*/ / 8 );
803 SetDWLE( &p_cdda->waveheader.BytesPerSec,
804 2*16/8 /*BytesPerSample*/ * CDDA_FREQUENCY_SAMPLE );
806 p_cdda->waveheader.DataChunkID = VLC_FOURCC('d', 'a', 't', 'a');
807 p_cdda->waveheader.DataLength = 0; /* we just don't know */
810 var_Create( p_access, MODULE_STRING "-caching",
811 VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
812 vlc_object_release( p_cdda->p_input );
816 cdio_destroy( p_cdda->p_cdio );
817 if( psz_source) free( psz_source );
820 if ( p_cdda->p_input )
821 vlc_object_release( p_cdda->p_input );
827 /*****************************************************************************
828 * CDDAClose: closes cdda and frees any resources associded with it.
829 *****************************************************************************/
830 void CDDAClose (vlc_object_t *p_this )
832 access_t *p_access = (access_t *) p_this;
833 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
836 #if LIBCDIO_VERSION_NUM >= 73
837 if( p_cdda->b_audio_ctl )
838 cdio_audio_stop(p_cdda->p_cdio);
841 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "" );
843 /* Remove playlist titles */
844 for( i = 0; i < p_cdda->i_titles; i++ )
846 vlc_input_title_Delete( p_cdda->p_title[i] );
850 cddb_log_set_handler( (cddb_log_handler_t) uninit_log_handler );
851 if( p_cdda->b_cddb_enabled )
852 cddb_disc_destroy( p_cdda->cddb.disc );
855 cdio_destroy( p_cdda->p_cdio );
856 cdio_log_set_handler( uninit_log_handler );
858 #if LIBCDIO_VERSION_NUM >= 72
859 if( p_cdda->paranoia )
860 cdio_paranoia_free(p_cdda->paranoia);
861 if( p_cdda->paranoia_cd )
862 cdio_cddap_close_no_free_cdio( p_cdda->paranoia_cd );
865 if( p_cdda->psz_mcn ) free( p_cdda->psz_mcn );
866 if( p_cdda->psz_source ) free( p_cdda->psz_source );
868 #if LIBCDDB_VERSION_NUM >= 1
876 /*****************************************************************************
877 * Control: The front-end or vlc engine calls here to ether get
878 * information such as meta information or plugin capabilities or to
879 * issue miscellaneous "set" requests.
880 *****************************************************************************/
881 static int CDDAControl( access_t *p_access, int i_query, va_list args )
883 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
887 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_EVENT),
888 "query %d", i_query );
892 /* Pass back a copy of meta information that was gathered when we
893 during the Open/Initialize call.
895 case ACCESS_GET_META:
898 vlc_meta_t **pp_meta = (vlc_meta_t**)va_arg( args, vlc_meta_t** );
901 *pp_meta = vlc_meta_Duplicate( p_cdda->p_meta );
902 dbg_print( INPUT_DBG_META, "%s", "Meta copied" );
908 msg_Warn( p_access, "tried to copy NULL meta info" );
913 case ACCESS_CAN_CONTROL_PACE:
915 vlc_bool_t *pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
916 *pb_bool = p_cdda->b_audio_ctl ? VLC_FALSE : VLC_TRUE;
917 dbg_print( INPUT_DBG_META, "can control pace? %d", *pb_bool);
921 case ACCESS_CAN_FASTSEEK:
922 dbg_print( INPUT_DBG_META, "can fast seek?");
924 case ACCESS_CAN_SEEK:
925 dbg_print( INPUT_DBG_META, "can seek?");
927 case ACCESS_CAN_PAUSE:
928 dbg_print( INPUT_DBG_META, "can pause?");
931 vlc_bool_t *pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
939 pi_int = (int*)va_arg( args, int * );
940 *pi_int = p_cdda-> i_blocks_per_read * CDIO_CD_FRAMESIZE_RAW;
941 dbg_print( INPUT_DBG_META, "Get MTU %d", *pi_int);
945 case ACCESS_GET_PTS_DELAY:
947 int64_t *pi_64 = (int64_t*)va_arg( args, int64_t * );
948 *pi_64 = var_GetInteger( p_access, MODULE_STRING "-caching" )
949 * MILLISECONDS_PER_SEC;
953 case ACCESS_GET_TITLE_INFO:
955 input_title_t ***ppp_title =
956 (input_title_t***)va_arg( args, input_title_t*** );
958 pi_int = (int*)va_arg( args, int* );
959 *((int*)va_arg( args, int* )) = 1; /* Title offset */
961 dbg_print ( INPUT_DBG_EVENT,
962 "GET TITLE: i_tracks %d, i_tracks %d",
963 p_cdda->i_tracks, p_cdda->i_tracks );
965 CDDAMetaInfo( p_access, CDIO_INVALID_TRACK );
967 if( p_cdda->b_nav_mode)
969 char *psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
970 input_Control( p_cdda->p_input, INPUT_SET_NAME, psz_title );
974 /* Duplicate title info */
975 if( p_cdda->i_titles == 0 )
977 *pi_int = 0; ppp_title = NULL;
980 *pi_int = p_cdda->i_titles;
981 *ppp_title = calloc(1, sizeof( input_title_t **)
982 * p_cdda->i_titles );
987 for( i = 0; i < p_cdda->i_titles; i++ )
989 if ( p_cdda->p_title[i] )
992 vlc_input_title_Duplicate( p_cdda->p_title[i] );
998 case ACCESS_SET_TITLE:
1000 i = (int)va_arg( args, int );
1002 dbg_print( INPUT_DBG_EVENT, "set title %d", i );
1003 if( i != p_access->info.i_title )
1005 const track_t i_track = p_cdda->i_first_track + i;
1007 p_access->info.i_title = i;
1008 if( p_cdda->b_nav_mode)
1011 char *psz_title = CDDAFormatTitle( p_access, i_track );
1012 input_Control( p_cdda->p_input, INPUT_SET_NAME,
1015 p_cdda->i_track = i_track;
1016 i_last_lsn = cdio_get_track_lsn( p_cdda->p_cdio,
1017 CDIO_CDROM_LEADOUT_TRACK );
1018 if( CDIO_INVALID_LSN != i_last_lsn )
1019 p_access->info.i_size = (int64_t) CDIO_CD_FRAMESIZE_RAW
1021 p_access->info.i_pos = (int64_t)
1022 cdio_get_track_lsn( p_cdda->p_cdio, i_track )
1023 * CDIO_CD_FRAMESIZE_RAW;
1027 p_access->info.i_size = p_cdda->p_title[i]->i_size;
1028 p_access->info.i_pos = 0;
1030 p_access->info.i_update = INPUT_UPDATE_TITLE|INPUT_UPDATE_SIZE;
1032 /* Next sector to read */
1033 p_cdda->i_lsn = cdio_get_track_lsn( p_cdda->p_cdio, i_track );
1038 case ACCESS_SET_PAUSE_STATE:
1039 dbg_print( INPUT_DBG_META, "Pause");
1040 if( p_cdda->b_audio_ctl )
1041 cdda_audio_pause( p_cdda->p_cdio );
1044 case ACCESS_SET_SEEKPOINT:
1045 dbg_print( INPUT_DBG_META, "set seekpoint");
1046 return VLC_EGENERIC;
1048 case ACCESS_SET_PRIVATE_ID_STATE:
1049 dbg_print( INPUT_DBG_META, "set private id state");
1050 return VLC_EGENERIC;
1053 msg_Warn( p_access, "unimplemented query in control" );
1054 return VLC_EGENERIC;
1060 /*****************************************************************************
1063 Initialize information pertaining to the CD: the number of tracks,
1064 first track number, LSNs for each track and the leadout. The leadout
1065 information is stored after the last track. The LSN array is
1066 0-origin, same as p_access->info. Add first_track to get what track
1067 number this is on the CD. Note: libcdio uses the real track number.
1069 On input we assume p_cdda->p_cdio and p_cdda->i_track have been set.
1071 We return the VLC-type status, e.g. VLC_SUCCESS, VLC_ENOMEM, etc.
1072 *****************************************************************************/
1073 static int CDDAInit( access_t *p_access, cdda_data_t *p_cdda )
1075 discmode_t discmode = CDIO_DISC_MODE_NO_INFO;
1077 p_cdda->i_tracks = cdio_get_num_tracks( p_cdda->p_cdio );
1078 p_cdda->i_first_track = cdio_get_first_track_num( p_cdda->p_cdio );
1080 discmode = cdio_get_discmode( p_cdda->p_cdio );
1083 case CDIO_DISC_MODE_CD_DA:
1084 case CDIO_DISC_MODE_CD_MIXED:
1085 /* These are possible for CD-DA */
1088 /* These are not possible for CD-DA */
1090 "Disc seems not to be CD-DA. libcdio reports it is %s",
1091 discmode2str[discmode]
1093 return VLC_EGENERIC;
1096 /* Set reading start LSN. */
1097 p_cdda->i_lsn = cdio_get_track_lsn(p_cdda->p_cdio, p_cdda->i_track);