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>
43 /* #ifdef variables below are defined via config.h via #include vlc above. */
48 #ifdef HAVE_SYS_TYPES_H
49 #include <sys/types.h>
60 /* FIXME: This variable is a hack. Would be nice to eliminate. */
61 access_t *p_cdda_input = NULL;
63 /*****************************************************************************
65 *****************************************************************************/
66 static int CDDARead( access_t *, uint8_t *, int );
67 static block_t *CDDAReadBlocks( access_t * p_access );
68 static int CDDASeek( access_t * p_access, int64_t i_pos );
69 static int CDDAControl( access_t *p_access, int i_query,
72 static int CDDAInit( access_t *p_access, cdda_data_t *p_cdda ) ;
75 /****************************************************************************
77 ****************************************************************************/
79 /* process messages that originate from libcdio.
83 cdio_log_handler( cdio_log_level_t level, const char message[] )
85 cdda_data_t *p_cdda = (cdda_data_t *)p_cdda_input->p_sys;
94 if (p_cdda->i_debug & INPUT_DBG_CDIO)
95 msg_Dbg( p_cdda_input, "%s", message);
98 msg_Warn( p_cdda_input, "%s", message);
101 case CDIO_LOG_ASSERT:
102 msg_Err( p_cdda_input, "%s", message);
105 msg_Warn( p_cdda_input, "%s\n%s %d", message,
106 "the above message had unknown cdio log level",
113 /*! This routine is called by libcddb routines on error.
117 cddb_log_handler( cddb_log_level_t level, const char message[] )
119 cdda_data_t *p_cdda = (cdda_data_t *)p_cdda_input->p_sys;
124 if( !(p_cdda->i_debug & INPUT_DBG_CDDB) )
126 /* Fall through if to warn case */
128 cdio_log_handler( level, message );
132 #endif /*HAVE_LIBCDDB*/
135 /*! This routine is when vlc is not fully set up (before full initialization)
136 or is not around (before finalization).
139 uninit_log_handler( cdio_log_level_t level, const char message[] )
141 cdda_data_t *p_cdda = NULL;
144 p_cdda = (cdda_data_t *)p_cdda_input->p_sys;
150 if( !p_cdda || !(p_cdda->i_debug & (INPUT_DBG_CDIO|INPUT_DBG_CDDB)) )
152 /* Fall through if to warn case */
154 fprintf( stderr, "WARN: %s\n", message );
157 fprintf( stderr, "ERROR: %s\n", message );
159 case CDIO_LOG_ASSERT:
160 fprintf( stderr, "ASSERT ERROR: %s\n", message );
163 fprintf( stderr, "UNKNOWN ERROR: %s\n%s %d\n", message,
164 "The above message had unknown cdio log level",
168 /* gl_default_cdio_log_handler (level, message); */
171 /* Only used in audio control mode. Gets the current LSN from the
173 static int64_t get_audio_position ( access_t *p_access )
175 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
178 #if LIBCDIO_VERSION_NUM >= 73
179 if( p_cdda->b_audio_ctl )
181 cdio_subchannel_t sub;
182 CdIo_t *p_cdio = p_cdda->p_cdio;
184 if( DRIVER_OP_SUCCESS == cdio_audio_read_subchannel(p_cdio, &sub) )
186 if( (sub.audio_status != CDIO_MMC_READ_SUB_ST_PAUSED) &&
187 (sub.audio_status != CDIO_MMC_READ_SUB_ST_PLAY) )
188 return CDIO_INVALID_LSN;
190 if( ! p_cdda->b_nav_mode )
192 i_offset = cdio_msf_to_lba( (&sub.abs_addr) );
196 i_offset = cdio_msf_to_lba( (&sub.rel_addr) );
201 i_offset = p_cdda->i_lsn;
206 i_offset = p_cdda->i_lsn;
209 i_offset = p_cdda->i_lsn;
214 /*****************************************************************************
215 * CDDAReadBlocks: reads a group of blocks from the CD-DA and returns
216 * an allocated pointer to the data. NULL is returned if no data
217 * read. It is also possible if we haven't read a RIFF header in which
218 * case one that we creaded during Open/Initialization is returned.
219 *****************************************************************************/
220 static block_t * CDDAReadBlocks( access_t * p_access )
223 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
224 int i_blocks = p_cdda->i_blocks_per_read;
226 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_LSN),
227 "called i_lsn: %d i_pos: %lld, size: %lld",
228 p_cdda->i_lsn, p_access->info.i_pos, p_access->info.i_size );
230 /* Check end of file */
231 if( p_access->info.b_eof )
234 if( !p_cdda->b_header )
236 /* Return only the dummy RIFF header we created in Open/Init */
237 p_block = block_New( p_access, sizeof( WAVEHEADER ) );
238 memcpy( p_block->p_buffer, &p_cdda->waveheader, sizeof(WAVEHEADER) );
239 p_cdda->b_header = VLC_TRUE;
243 /* Check end of track */
244 while( p_cdda->i_lsn > cdio_get_track_last_lsn(p_cdda->p_cdio,
249 if( p_cdda->b_nav_mode )
250 go_on = p_cdda->i_lsn > p_cdda->last_disc_frame;
252 go_on = p_cdda->i_track >= p_cdda->i_first_track+p_cdda->i_titles-1 ;
256 dbg_print( (INPUT_DBG_LSN), "EOF");
257 p_access->info.b_eof = VLC_TRUE;
261 p_access->info.i_update |= INPUT_UPDATE_TITLE | INPUT_UPDATE_META;
262 p_access->info.i_title++;
265 if( p_cdda-> b_nav_mode )
267 char *psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
268 input_Control( p_cdda->p_input, INPUT_SET_NAME, psz_title );
273 p_access->info.i_size =
274 p_cdda->p_title[p_access->info.i_title]->i_size;
275 p_access->info.i_pos = 0;
276 p_access->info.i_update |= INPUT_UPDATE_SIZE;
280 /* Possibly adjust i_blocks so we don't read past the end of a track. */
281 if( p_cdda->i_lsn + i_blocks >=
282 cdio_get_track_lsn(p_cdda->p_cdio, p_cdda->i_track+1) )
284 i_blocks = cdio_get_track_lsn( p_cdda->p_cdio, p_cdda->i_track+1 )
288 /* Do the actual reading */
289 p_block = block_New( p_access, i_blocks * CDIO_CD_FRAMESIZE_RAW );
292 msg_Err( p_access, "cannot get a new block of size: %i",
293 i_blocks * CDIO_CD_FRAMESIZE_RAW );
294 intf_UserFatal( p_access, VLC_FALSE, _("CD reading failed"),
295 _("VLC could not get a new block of size: %i."),
296 i_blocks * CDIO_CD_FRAMESIZE_RAW );
301 #if LIBCDIO_VERSION_NUM >= 72
302 driver_return_code_t rc = DRIVER_OP_SUCCESS;
304 if( p_cdda->e_paranoia && p_cdda->paranoia )
307 for( i = 0; i < i_blocks; i++ )
309 int16_t *p_readbuf = cdio_paranoia_read( p_cdda->paranoia, NULL );
310 char *psz_err = cdio_cddap_errors( p_cdda->paranoia_cd );
311 char *psz_mes = cdio_cddap_messages( p_cdda->paranoia_cd );
313 if( psz_mes || psz_err )
314 msg_Err( p_access, "%s%s\n", psz_mes ? psz_mes: "",
315 psz_err ? psz_err: "" );
317 if( psz_err ) free( psz_err );
318 if( psz_mes ) free( psz_mes );
321 msg_Err( p_access, "paranoia read error on frame %i\n",
325 memcpy( p_block->p_buffer + i * CDIO_CD_FRAMESIZE_RAW,
326 p_readbuf, CDIO_CD_FRAMESIZE_RAW );
331 rc = cdio_read_audio_sectors( p_cdda->p_cdio, p_block->p_buffer,
332 p_cdda->i_lsn, i_blocks );
334 #define DRIVER_OP_SUCCESS 0
336 rc = cdio_read_audio_sectors( p_cdda->p_cdio, p_block->p_buffer,
337 p_cdda->i_lsn, i_blocks);
340 if( rc != DRIVER_OP_SUCCESS )
342 msg_Err( p_access, "could not read %d sectors starting from %lu",
343 i_blocks, (long unsigned int) p_cdda->i_lsn );
344 block_Release( p_block );
346 /* If we had problems above, assume the problem is with
347 the first sector of the read and set to skip it. In
348 the future libcdio may have cdparanoia support.
351 p_access->info.i_pos += CDIO_CD_FRAMESIZE_RAW;
356 p_cdda->i_lsn += i_blocks;
357 p_access->info.i_pos += i_blocks * CDIO_CD_FRAMESIZE_RAW;
362 /*****************************************************************************
363 * CDDARead: Handler for audio control reads the CD-DA.
364 *****************************************************************************/
366 CDDARead( access_t * p_access, uint8_t *p_buffer, int i_len )
368 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
370 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_LSN),
371 "called lsn: %d pos: %lld, size: %lld",
372 p_cdda->i_lsn, p_access->info.i_pos, p_access->info.i_size);
374 /* Check end of file */
375 if( p_access->info.b_eof )
379 lsn_t i_lsn = get_audio_position(p_access);
380 if( CDIO_INVALID_LSN == i_lsn )
382 dbg_print( (INPUT_DBG_LSN), "invalid lsn" );
383 memset( p_buffer, 0, i_len );
387 p_cdda->i_lsn = i_lsn;
388 p_access->info.i_pos = p_cdda->i_lsn * CDIO_CD_FRAMESIZE_RAW;
391 dbg_print( (INPUT_DBG_LSN), "updated lsn: %d", p_cdda->i_lsn );
393 /* Check end of track */
394 while( p_cdda->i_lsn > cdio_get_track_last_lsn( p_cdda->p_cdio,
397 if( p_cdda->i_track >= p_cdda->i_first_track + p_cdda->i_titles - 1 )
399 dbg_print( (INPUT_DBG_LSN), "EOF");
400 p_access->info.b_eof = VLC_TRUE;
403 p_access->info.i_update |= INPUT_UPDATE_TITLE;
404 p_access->info.i_title++;
407 if( p_cdda-> b_nav_mode )
409 char *psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
410 input_Control( p_cdda->p_input, INPUT_SET_NAME, psz_title );
415 p_access->info.i_size =
416 p_cdda->p_title[p_access->info.i_title]->i_size;
417 p_access->info.i_pos = 0;
418 p_access->info.i_update |= INPUT_UPDATE_SIZE;
421 memset( p_buffer, 0, i_len );
425 /*! Pause CD playing via audio control */
426 static bool cdda_audio_pause( CdIo_t *p_cdio )
429 #if LIBCDIO_VERSION_NUM >= 73
430 cdio_subchannel_t sub;
432 if( DRIVER_OP_SUCCESS == cdio_audio_read_subchannel( p_cdio, &sub ) )
434 if( sub.audio_status == CDIO_MMC_READ_SUB_ST_PLAY )
436 b_ok = DRIVER_OP_SUCCESS == cdio_audio_pause(p_cdio);
445 #if LIBCDIO_VERSION_NUM >= 73
446 /*! play CD using audio controls */
447 static driver_return_code_t
448 cdda_audio_play( CdIo_t *p_cdio, lsn_t start_lsn, lsn_t end_lsn )
452 cdio_lsn_to_msf( start_lsn, &start_msf );
453 cdio_lsn_to_msf( end_lsn, &last_msf );
454 cdda_audio_pause( p_cdio );
455 return cdio_audio_play_msf( p_cdio, &start_msf, &last_msf );
459 /****************************************************************************
460 * CDDASeek - change position for subsequent reads. For example, this
461 * can happen if the user moves a position slider bar in a GUI.
462 ****************************************************************************/
463 static int CDDASeek( access_t * p_access, int64_t i_pos )
465 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
467 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_SEEK),
468 "lsn %lu, offset: %lld",
469 (long unsigned int) p_cdda->i_lsn, i_pos );
471 p_cdda->i_lsn = (i_pos / CDIO_CD_FRAMESIZE_RAW);
473 #if LIBCDIO_VERSION_NUM >= 72
474 if( p_cdda->e_paranoia && p_cdda->paranoia )
475 cdio_paranoia_seek( p_cdda->paranoia, p_cdda->i_lsn, SEEK_SET );
478 #if LIBCDIO_VERSION_NUM >= 73
479 if( p_cdda->b_audio_ctl )
481 track_t i_track = cdio_get_track( p_cdda->p_cdio, p_cdda->i_lsn );
484 if( p_cdda->b_nav_mode )
485 i_last_lsn = p_cdda->last_disc_frame;
487 i_last_lsn = cdio_get_track_last_lsn( p_cdda->p_cdio, i_track );
489 cdda_audio_play( p_cdda->p_cdio, p_cdda->i_lsn, i_last_lsn );
493 if( ! p_cdda->b_nav_mode )
494 p_cdda->i_lsn += cdio_get_track_lsn( p_cdda->p_cdio, p_cdda->i_track );
496 /* Seeked backwards and we are doing disc mode. */
497 if( p_cdda->b_nav_mode && p_access->info.i_pos > i_pos )
502 for( i_track = p_cdda->i_track; i_track > 1 &&
503 p_cdda->i_lsn < cdio_get_track_lsn( p_cdda->p_cdio, i_track );
504 i_track--, p_access->info.i_title-- )
507 p_cdda->i_track = i_track;
508 p_access->info.i_update |= INPUT_UPDATE_TITLE | INPUT_UPDATE_META ;
509 psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
510 input_Control( p_cdda->p_input, INPUT_SET_NAME,
515 p_access->info.i_pos = i_pos;
516 p_access->info.b_eof = VLC_FALSE;
521 Set up internal state so that we play a given track.
522 If we are using audio-ctl mode we also activate CD-ROM
525 static bool cdda_play_track( access_t *p_access, track_t i_track )
527 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
529 dbg_print( (INPUT_DBG_CALL), "called track: %d\n", i_track );
531 if( i_track > p_cdda->i_tracks )
533 msg_Err( p_access, "CD has %d tracks, and you requested track %d",
534 p_cdda->i_tracks, i_track );
537 p_cdda->i_track = i_track;
539 /* set up the frame boundaries for this particular track */
540 p_cdda->first_frame = p_cdda->i_lsn =
541 cdio_get_track_lsn( p_cdda->p_cdio, i_track );
543 p_cdda->last_frame = cdio_get_track_lsn( p_cdda->p_cdio, i_track+1 ) - 1;
545 #if LIBCDIO_VERSION_NUM >= 73
546 if( p_cdda->b_audio_ctl )
549 if( p_cdda->b_nav_mode )
550 i_last_lsn = p_cdda->last_disc_frame;
552 i_last_lsn = cdio_get_track_last_lsn( p_cdda->p_cdio, i_track );
553 cdda_audio_play( p_cdda->p_cdio, p_cdda->i_lsn, i_last_lsn );
559 /****************************************************************************
561 ****************************************************************************/
563 /*****************************************************************************
564 * Open: open cdda device or image file and initialize structures
565 * for subsequent operations.
566 *****************************************************************************/
567 int CDDAOpen( vlc_object_t *p_this )
569 access_t *p_access = (access_t*)p_this;
570 char * psz_source = NULL;
571 cdda_data_t *p_cdda = NULL;
574 vlc_bool_t b_single_track = false;
575 int i_rc = VLC_EGENERIC;
577 p_access->p_sys = NULL;
579 /* Set where to log errors messages from libcdio. */
580 p_cdda_input = p_access;
582 /* parse the options passed in command line : */
583 if( p_access->psz_path && *p_access->psz_path )
585 char *psz_parser = psz_source = strdup( p_access->psz_path );
587 while( *psz_parser && *psz_parser != '@' )
592 if( *psz_parser == '@' )
598 if ('T' == *psz_parser || 't' == *psz_parser )
601 i_track = (int)strtol( psz_parser, NULL, 10 );
602 i_track = i_track ? i_track : 1;
603 b_single_track = true;
607 if( !psz_source || !*psz_source )
609 /* No device/track given. Continue only when this plugin was
611 if( !p_this->b_force )
614 psz_source = var_CreateGetString( p_this, "cd-audio" );
615 if( !psz_source || !*psz_source )
617 /* Scan for a CD-ROM drive with a CD-DA in it. */
619 cdio_get_devices_with_cap( NULL, CDIO_FS_AUDIO, false );
621 if( (NULL == ppsz_drives) || (NULL == ppsz_drives[0]) )
624 "libcdio couldn't find something with a CD-DA in it" );
626 cdio_free_device_list( ppsz_drives );
629 psz_source = strdup( ppsz_drives[0] );
630 cdio_free_device_list( ppsz_drives );
633 cdio_log_set_handler( cdio_log_handler );
636 if( !(p_cdio = cdio_open( psz_source, DRIVER_UNKNOWN )) )
638 msg_Warn( p_access, "could not open %s", psz_source );
644 p_cdda = calloc( 1, sizeof(cdda_data_t) );
647 msg_Err( p_access, "out of memory" );
653 cddb_log_set_handler ( cddb_log_handler );
654 p_cdda->cddb.disc = NULL;
655 p_cdda->b_cddb_enabled =
656 config_GetInt( p_access, MODULE_STRING "-cddb-enabled" );
659 config_GetInt( p_access, MODULE_STRING "-cdtext-enabled" );
660 p_cdda->b_cdtext_prefer =
661 config_GetInt( p_access, MODULE_STRING "-cdtext-prefer" );
662 #if LIBCDIO_VERSION_NUM >= 73
663 p_cdda->b_audio_ctl =
664 config_GetInt( p_access, MODULE_STRING "-analog-output" );
667 p_cdda->psz_source = strdup( psz_source );
668 p_cdda->b_header = VLC_FALSE;
669 p_cdda->p_cdio = p_cdio;
670 p_cdda->i_tracks = 0;
671 p_cdda->i_titles = 0;
672 p_cdda->i_debug = config_GetInt( p_this, MODULE_STRING "-debug" );
673 p_cdda->b_nav_mode = config_GetInt(p_this, MODULE_STRING "-navigation-mode" );
674 p_cdda->i_blocks_per_read =
675 config_GetInt( p_this, MODULE_STRING "-blocks-per-read" );
676 p_cdda->last_disc_frame =
677 cdio_get_track_lsn( p_cdio, CDIO_CDROM_LEADOUT_TRACK );
678 p_cdda->p_input = vlc_object_find( p_access, VLC_OBJECT_INPUT,
681 if( 0 == p_cdda->i_blocks_per_read )
682 p_cdda->i_blocks_per_read = DEFAULT_BLOCKS_PER_READ;
684 if( (p_cdda->i_blocks_per_read < MIN_BLOCKS_PER_READ)
685 || (p_cdda->i_blocks_per_read > MAX_BLOCKS_PER_READ) )
687 msg_Warn( p_cdda_input,
688 "number of blocks (%d) has to be between %d and %d. "
690 p_cdda->i_blocks_per_read,
691 MIN_BLOCKS_PER_READ, MAX_BLOCKS_PER_READ,
692 DEFAULT_BLOCKS_PER_READ );
693 p_cdda->i_blocks_per_read = DEFAULT_BLOCKS_PER_READ;
696 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "%s", psz_source );
698 /* Set up p_access */
699 if( p_cdda->b_audio_ctl )
701 p_access->pf_read = CDDARead;
702 p_access->pf_block = NULL;
706 p_access->pf_read = NULL;
707 p_access->pf_block = CDDAReadBlocks;
710 p_access->pf_control = CDDAControl;
711 p_access->pf_seek = CDDASeek;
716 if( p_cdda->b_nav_mode )
717 i_last_lsn = p_cdda->last_disc_frame;
719 i_last_lsn = cdio_get_track_last_lsn( p_cdio, i_track );
721 if( CDIO_INVALID_LSN != i_last_lsn )
722 p_access->info.i_size = i_last_lsn * (uint64_t) CDIO_CD_FRAMESIZE_RAW;
724 p_access->info.i_size = 0;
727 p_access->info.i_update = 0;
728 p_access->info.b_eof = VLC_FALSE;
729 p_access->info.i_title = 0;
730 p_access->info.i_seekpoint = 0;
732 p_access->p_sys = (access_sys_t *) p_cdda;
734 /* We read the Table Of Content information */
735 i_rc = CDDAInit( p_access, p_cdda );
736 if( VLC_SUCCESS != i_rc )
739 cdda_play_track( p_access, i_track );
740 CDDAFixupPlaylist( p_access, p_cdda, b_single_track );
742 #if LIBCDIO_VERSION_NUM >= 72
744 char *psz_paranoia = config_GetPsz( p_access,
745 MODULE_STRING "-paranoia" );
747 p_cdda->e_paranoia = PARANOIA_MODE_DISABLE;
748 if( psz_paranoia && *psz_paranoia )
750 if( !strncmp( psz_paranoia, "full", strlen("full") ) )
751 p_cdda->e_paranoia = PARANOIA_MODE_FULL;
752 else if( !strncmp(psz_paranoia, "overlap", strlen("overlap")) )
753 p_cdda->e_paranoia = PARANOIA_MODE_OVERLAP;
755 /* Use CD Paranoia? */
756 if( p_cdda->e_paranoia )
758 p_cdda->paranoia_cd =
759 cdio_cddap_identify_cdio( p_cdio, 1, NULL );
760 /* We'll set for verbose paranoia messages. */
761 cdio_cddap_verbose_set( p_cdda->paranoia_cd,
762 CDDA_MESSAGE_PRINTIT,
763 CDDA_MESSAGE_PRINTIT );
764 if ( 0 != cdio_cddap_open(p_cdda->paranoia_cd) )
766 msg_Warn( p_cdda_input, "unable to get paranoia support - "
767 "continuing without it." );
768 p_cdda->e_paranoia = PARANOIA_MODE_DISABLE;
772 p_cdda->paranoia = cdio_paranoia_init(p_cdda->paranoia_cd);
773 cdio_paranoia_seek( p_cdda->paranoia, p_cdda->i_lsn,
776 /* Set reading mode for full or overlap paranoia,
777 * but allow skipping sectors. */
778 cdio_paranoia_modeset( p_cdda->paranoia,
779 PARANOIA_MODE_FULL == p_cdda->e_paranoia ?
780 PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP :
781 PARANOIA_MODE_OVERLAP^PARANOIA_MODE_NEVERSKIP );
788 /* Build a WAV header to put in front of the output data.
789 This gets sent back in the Block (read) routine.
791 memset( &p_cdda->waveheader, 0, sizeof(WAVEHEADER) );
793 SetWLE( &p_cdda->waveheader.Format, 1 ); /*WAVE_FORMAT_PCM*/
794 SetWLE( &p_cdda->waveheader.BitsPerSample, 16);
796 p_cdda->waveheader.MainChunkID = VLC_FOURCC('R', 'I', 'F', 'F');
797 p_cdda->waveheader.Length = 0; /* we just don't know */
798 p_cdda->waveheader.ChunkTypeID = VLC_FOURCC('W', 'A', 'V', 'E');
799 p_cdda->waveheader.SubChunkID = VLC_FOURCC('f', 'm', 't', ' ');
801 SetDWLE( &p_cdda->waveheader.SubChunkLength, 16);
802 SetWLE( &p_cdda->waveheader.Modus, 2);
803 SetDWLE( &p_cdda->waveheader.SampleFreq, CDDA_FREQUENCY_SAMPLE);
804 SetWLE( &p_cdda->waveheader.BytesPerSample,
805 2 /*Modus*/ * 16 /*BitsPerSample*/ / 8 );
806 SetDWLE( &p_cdda->waveheader.BytesPerSec,
807 2*16/8 /*BytesPerSample*/ * CDDA_FREQUENCY_SAMPLE );
809 p_cdda->waveheader.DataChunkID = VLC_FOURCC('d', 'a', 't', 'a');
810 p_cdda->waveheader.DataLength = 0; /* we just don't know */
813 var_Create( p_access, MODULE_STRING "-caching",
814 VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
815 vlc_object_release( p_cdda->p_input );
819 cdio_destroy( p_cdda->p_cdio );
820 if( psz_source) free( psz_source );
823 if ( p_cdda->p_input )
824 vlc_object_release( p_cdda->p_input );
830 /*****************************************************************************
831 * CDDAClose: closes cdda and frees any resources associded with it.
832 *****************************************************************************/
833 void CDDAClose (vlc_object_t *p_this )
835 access_t *p_access = (access_t *) p_this;
836 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
839 #if LIBCDIO_VERSION_NUM >= 73
840 if( p_cdda->b_audio_ctl )
841 cdio_audio_stop(p_cdda->p_cdio);
844 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "" );
846 /* Remove playlist titles */
847 for( i = 0; i < p_cdda->i_titles; i++ )
849 vlc_input_title_Delete( p_cdda->p_title[i] );
853 cddb_log_set_handler( (cddb_log_handler_t) uninit_log_handler );
854 if( p_cdda->b_cddb_enabled )
855 cddb_disc_destroy( p_cdda->cddb.disc );
858 cdio_destroy( p_cdda->p_cdio );
859 cdio_log_set_handler( uninit_log_handler );
861 #if LIBCDIO_VERSION_NUM >= 72
862 if( p_cdda->paranoia )
863 cdio_paranoia_free(p_cdda->paranoia);
864 if( p_cdda->paranoia_cd )
865 cdio_cddap_close_no_free_cdio( p_cdda->paranoia_cd );
868 if( p_cdda->psz_mcn ) free( p_cdda->psz_mcn );
869 if( p_cdda->psz_source ) free( p_cdda->psz_source );
871 #if LIBCDDB_VERSION_NUM >= 1
879 /*****************************************************************************
880 * Control: The front-end or vlc engine calls here to ether get
881 * information such as meta information or plugin capabilities or to
882 * issue miscellaneous "set" requests.
883 *****************************************************************************/
884 static int CDDAControl( access_t *p_access, int i_query, va_list args )
886 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
890 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_EVENT),
891 "query %d", i_query );
895 /* Pass back a copy of meta information that was gathered when we
896 during the Open/Initialize call.
898 case ACCESS_GET_META:
901 vlc_meta_t **pp_meta = (vlc_meta_t**)va_arg( args, vlc_meta_t** );
904 *pp_meta = vlc_meta_Duplicate( p_cdda->p_meta );
905 dbg_print( INPUT_DBG_META, "%s", "Meta copied" );
911 msg_Warn( p_access, "tried to copy NULL meta info" );
916 case ACCESS_CAN_CONTROL_PACE:
918 vlc_bool_t *pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
919 *pb_bool = p_cdda->b_audio_ctl ? VLC_FALSE : VLC_TRUE;
920 dbg_print( INPUT_DBG_META, "can control pace? %d", *pb_bool);
924 case ACCESS_CAN_FASTSEEK:
925 dbg_print( INPUT_DBG_META, "can fast seek?");
927 case ACCESS_CAN_SEEK:
928 dbg_print( INPUT_DBG_META, "can seek?");
930 case ACCESS_CAN_PAUSE:
931 dbg_print( INPUT_DBG_META, "can pause?");
934 vlc_bool_t *pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
942 pi_int = (int*)va_arg( args, int * );
943 *pi_int = p_cdda-> i_blocks_per_read * CDIO_CD_FRAMESIZE_RAW;
944 dbg_print( INPUT_DBG_META, "Get MTU %d", *pi_int);
948 case ACCESS_GET_PTS_DELAY:
950 int64_t *pi_64 = (int64_t*)va_arg( args, int64_t * );
951 *pi_64 = var_GetInteger( p_access, MODULE_STRING "-caching" )
952 * MILLISECONDS_PER_SEC;
956 case ACCESS_GET_TITLE_INFO:
958 input_title_t ***ppp_title =
959 (input_title_t***)va_arg( args, input_title_t*** );
961 pi_int = (int*)va_arg( args, int* );
962 *((int*)va_arg( args, int* )) = 1; /* Title offset */
964 dbg_print ( INPUT_DBG_EVENT,
965 "GET TITLE: i_tracks %d, i_tracks %d",
966 p_cdda->i_tracks, p_cdda->i_tracks );
968 CDDAMetaInfo( p_access, CDIO_INVALID_TRACK );
970 if( p_cdda->b_nav_mode)
972 char *psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
973 input_Control( p_cdda->p_input, INPUT_SET_NAME, psz_title );
977 /* Duplicate title info */
978 if( p_cdda->i_titles == 0 )
980 *pi_int = 0; ppp_title = NULL;
983 *pi_int = p_cdda->i_titles;
984 *ppp_title = calloc(1, sizeof( input_title_t **)
985 * p_cdda->i_titles );
990 for( i = 0; i < p_cdda->i_titles; i++ )
992 if ( p_cdda->p_title[i] )
995 vlc_input_title_Duplicate( p_cdda->p_title[i] );
1001 case ACCESS_SET_TITLE:
1003 i = (int)va_arg( args, int );
1005 dbg_print( INPUT_DBG_EVENT, "set title %d", i );
1006 if( i != p_access->info.i_title )
1008 const track_t i_track = p_cdda->i_first_track + i;
1010 p_access->info.i_title = i;
1011 if( p_cdda->b_nav_mode)
1014 char *psz_title = CDDAFormatTitle( p_access, i_track );
1015 input_Control( p_cdda->p_input, INPUT_SET_NAME,
1018 p_cdda->i_track = i_track;
1019 i_last_lsn = cdio_get_track_lsn( p_cdda->p_cdio,
1020 CDIO_CDROM_LEADOUT_TRACK );
1021 if( CDIO_INVALID_LSN != i_last_lsn )
1022 p_access->info.i_size = (int64_t) CDIO_CD_FRAMESIZE_RAW
1024 p_access->info.i_pos = (int64_t)
1025 cdio_get_track_lsn( p_cdda->p_cdio, i_track )
1026 * CDIO_CD_FRAMESIZE_RAW;
1030 p_access->info.i_size = p_cdda->p_title[i]->i_size;
1031 p_access->info.i_pos = 0;
1033 p_access->info.i_update = INPUT_UPDATE_TITLE|INPUT_UPDATE_SIZE;
1035 /* Next sector to read */
1036 p_cdda->i_lsn = cdio_get_track_lsn( p_cdda->p_cdio, i_track );
1041 case ACCESS_SET_PAUSE_STATE:
1042 dbg_print( INPUT_DBG_META, "Pause");
1043 if( p_cdda->b_audio_ctl )
1044 cdda_audio_pause( p_cdda->p_cdio );
1047 case ACCESS_SET_SEEKPOINT:
1048 dbg_print( INPUT_DBG_META, "set seekpoint");
1049 return VLC_EGENERIC;
1051 case ACCESS_SET_PRIVATE_ID_STATE:
1052 dbg_print( INPUT_DBG_META, "set private id state");
1053 return VLC_EGENERIC;
1056 msg_Warn( p_access, "unimplemented query in control" );
1057 return VLC_EGENERIC;
1063 /*****************************************************************************
1066 Initialize information pertaining to the CD: the number of tracks,
1067 first track number, LSNs for each track and the leadout. The leadout
1068 information is stored after the last track. The LSN array is
1069 0-origin, same as p_access->info. Add first_track to get what track
1070 number this is on the CD. Note: libcdio uses the real track number.
1072 On input we assume p_cdda->p_cdio and p_cdda->i_track have been set.
1074 We return the VLC-type status, e.g. VLC_SUCCESS, VLC_ENOMEM, etc.
1075 *****************************************************************************/
1076 static int CDDAInit( access_t *p_access, cdda_data_t *p_cdda )
1078 discmode_t discmode = CDIO_DISC_MODE_NO_INFO;
1080 p_cdda->i_tracks = cdio_get_num_tracks( p_cdda->p_cdio );
1081 p_cdda->i_first_track = cdio_get_first_track_num( p_cdda->p_cdio );
1083 discmode = cdio_get_discmode( p_cdda->p_cdio );
1086 case CDIO_DISC_MODE_CD_DA:
1087 case CDIO_DISC_MODE_CD_MIXED:
1088 /* These are possible for CD-DA */
1091 /* These are not possible for CD-DA */
1093 "Disc seems not to be CD-DA. libcdio reports it is %s",
1094 discmode2str[discmode]
1096 return VLC_EGENERIC;
1099 /* Set reading start LSN. */
1100 p_cdda->i_lsn = cdio_get_track_lsn(p_cdda->p_cdio, p_cdda->i_track);