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;
91 if (p_cdda->i_debug & INPUT_DBG_CDIO)
92 msg_Dbg( p_cdda_input, message);
95 msg_Warn( p_cdda_input, message);
99 msg_Err( p_cdda_input, message);
102 msg_Warn( p_cdda_input, message,
103 "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)) return;
124 /* Fall through if to warn case */
126 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)))
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
172 get_audio_position ( access_t *p_access )
174 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
177 #if LIBCDIO_VERSION_NUM >= 73
178 if (p_cdda->b_audio_ctl)
180 cdio_subchannel_t sub;
181 CdIo_t *p_cdio = p_cdda->p_cdio;
182 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 ) {
188 // char *psz = cdio_msf_to_str(&sub.abs_addr);
189 // fprintf(stderr, "+++disk mode abs msf %s", psz);
191 i_offset = cdio_msf_to_lba((&sub.abs_addr));
192 // fprintf(stderr, " frame offset %d\n", i_offset);
194 // char *psz = cdio_msf_to_str(&sub.rel_addr);
195 // fprintf(stderr, "+++track abs msf %s", psz);
197 i_offset = cdio_msf_to_lba((&sub.rel_addr));
198 // fprintf(stderr, " frame offset %d\n", i_offset);
201 // fprintf(stderr, "+++Error reading current pos\n");
202 i_offset = p_cdda->i_lsn;
205 i_offset = p_cdda->i_lsn;
207 i_offset = p_cdda->i_lsn;
213 /*****************************************************************************
214 * CDDAReadBlocks: reads a group of blocks from the CD-DA and returns
215 * an allocated pointer to the data. NULL is returned if no data
216 * read. It is also possible if we haven't read a RIFF header in which
217 * case one that we creaded during Open/Initialization is returned.
218 *****************************************************************************/
219 static block_t * CDDAReadBlocks( access_t * p_access )
222 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
223 int i_blocks = p_cdda->i_blocks_per_read;
225 dbg_print((INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_LSN),
226 "called i_lsn: %d i_pos: %lld, size: %lld",
227 p_cdda->i_lsn, p_access->info.i_pos, p_access->info.i_size);
229 /* Check end of file */
230 if( p_access->info.b_eof ) return NULL;
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 ) {
264 char *psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
265 input_Control( p_cdda->p_input, INPUT_SET_NAME, psz_title );
268 p_access->info.i_size =
269 p_cdda->p_title[p_access->info.i_title]->i_size;
270 p_access->info.i_pos = 0;
271 p_access->info.i_update |= INPUT_UPDATE_SIZE;
275 /* Possibly adjust i_blocks so we don't read past the end of a track. */
276 if( p_cdda->i_lsn + i_blocks >=
277 cdio_get_track_lsn(p_cdda->p_cdio, p_cdda->i_track+1) )
279 i_blocks = cdio_get_track_lsn( p_cdda->p_cdio, p_cdda->i_track+1 )
283 /* Do the actual reading */
284 p_block = block_New( p_access, i_blocks * CDIO_CD_FRAMESIZE_RAW );
287 msg_Err( p_access, "cannot get a new block of size: %i",
288 i_blocks * CDIO_CD_FRAMESIZE_RAW );
293 #if LIBCDIO_VERSION_NUM >= 72
294 driver_return_code_t rc = DRIVER_OP_SUCCESS;
296 if ( p_cdda->e_paranoia && p_cdda->paranoia )
299 for( i = 0; i < i_blocks; i++ )
301 int16_t *p_readbuf = cdio_paranoia_read(p_cdda->paranoia, NULL);
302 char *psz_err=cdio_cddap_errors(p_cdda->paranoia_cd);
303 char *psz_mes=cdio_cddap_messages(p_cdda->paranoia_cd);
305 if (psz_mes || psz_err)
306 msg_Err( p_access, "%s%s\n", psz_mes ? psz_mes: "",
307 psz_err ? psz_err: "" );
309 if (psz_err) free(psz_err);
310 if (psz_mes) free(psz_mes);
312 msg_Err( p_access, "paranoia read error on frame %i\n",
315 memcpy(p_block->p_buffer + i * CDIO_CD_FRAMESIZE_RAW,
316 p_readbuf, CDIO_CD_FRAMESIZE_RAW);
320 rc = cdio_read_audio_sectors( p_cdda->p_cdio, p_block->p_buffer,
321 p_cdda->i_lsn, i_blocks);
323 #define DRIVER_OP_SUCCESS 0
325 rc = cdio_read_audio_sectors( p_cdda->p_cdio, p_block->p_buffer,
326 p_cdda->i_lsn, i_blocks);
328 if( rc != DRIVER_OP_SUCCESS )
330 msg_Err( p_access, "could not read %d sectors starting from %lu",
331 i_blocks, (long unsigned int) p_cdda->i_lsn );
332 block_Release( p_block );
334 /* If we had problems above, assume the problem is with
335 the first sector of the read and set to skip it. In
336 the future libcdio may have cdparanoia support.
339 p_access->info.i_pos += CDIO_CD_FRAMESIZE_RAW;
344 p_cdda->i_lsn += i_blocks;
345 p_access->info.i_pos += i_blocks * CDIO_CD_FRAMESIZE_RAW;
350 /*****************************************************************************
351 * CDDARead: Handler for audio control reads the CD-DA.
352 *****************************************************************************/
354 CDDARead( access_t * p_access, uint8_t *p_buffer, int i_len )
356 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
358 dbg_print((INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_LSN),
359 "called lsn: %d pos: %lld, size: %lld",
360 p_cdda->i_lsn, p_access->info.i_pos, p_access->info.i_size);
362 /* Check end of file */
363 if( p_access->info.b_eof ) return 0;
366 lsn_t i_lsn = get_audio_position(p_access);
367 if (CDIO_INVALID_LSN == i_lsn) {
368 dbg_print((INPUT_DBG_LSN), "invalid lsn");
369 memset( p_buffer, 0, i_len );
373 p_cdda->i_lsn = i_lsn;
374 p_access->info.i_pos = p_cdda->i_lsn * CDIO_CD_FRAMESIZE_RAW;
377 dbg_print((INPUT_DBG_LSN), "updated lsn: %d", p_cdda->i_lsn);
379 /* Check end of track */
380 while( p_cdda->i_lsn > cdio_get_track_last_lsn(p_cdda->p_cdio,
383 if( p_cdda->i_track >= p_cdda->i_first_track + p_cdda->i_titles - 1 )
385 dbg_print( (INPUT_DBG_LSN), "EOF");
386 p_access->info.b_eof = VLC_TRUE;
390 p_access->info.i_update |= INPUT_UPDATE_TITLE;
391 p_access->info.i_title++;
394 if ( p_cdda-> b_nav_mode ) {
395 char *psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
396 input_Control( p_cdda->p_input, INPUT_SET_NAME, psz_title );
399 p_access->info.i_size =
400 p_cdda->p_title[p_access->info.i_title]->i_size;
401 p_access->info.i_pos = 0;
402 p_access->info.i_update |= INPUT_UPDATE_SIZE;
406 memset( p_buffer, 0, i_len );
410 /*! Pause CD playing via audio control */
412 cdda_audio_pause(CdIo_t *p_cdio)
415 #if LIBCDIO_VERSION_NUM >= 73
416 cdio_subchannel_t sub;
417 if (DRIVER_OP_SUCCESS == cdio_audio_read_subchannel(p_cdio, &sub)) {
418 if (sub.audio_status == CDIO_MMC_READ_SUB_ST_PLAY) {
419 b_ok = DRIVER_OP_SUCCESS == cdio_audio_pause(p_cdio);
427 #if LIBCDIO_VERSION_NUM >= 73
428 /*! play CD using audio controls */
429 static driver_return_code_t
430 cdda_audio_play(CdIo_t *p_cdio, lsn_t start_lsn, lsn_t end_lsn)
434 cdio_lsn_to_msf(start_lsn, &start_msf);
435 cdio_lsn_to_msf(end_lsn, &last_msf);
436 cdda_audio_pause(p_cdio);
437 return cdio_audio_play_msf (p_cdio, &start_msf, &last_msf);
441 /****************************************************************************
442 * CDDASeek - change position for subsequent reads. For example, this
443 * can happen if the user moves a position slider bar in a GUI.
444 ****************************************************************************/
446 CDDASeek( access_t * p_access, int64_t i_pos )
448 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
450 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_SEEK),
451 "lsn %lu, offset: %lld",
452 (long unsigned int) p_cdda->i_lsn, i_pos );
454 p_cdda->i_lsn = (i_pos / CDIO_CD_FRAMESIZE_RAW);
456 #if LIBCDIO_VERSION_NUM >= 72
457 if ( p_cdda->e_paranoia && p_cdda->paranoia )
458 cdio_paranoia_seek(p_cdda->paranoia, p_cdda->i_lsn, SEEK_SET);
461 #if LIBCDIO_VERSION_NUM >= 73
462 if ( p_cdda->b_audio_ctl ) {
463 track_t i_track = cdio_get_track(p_cdda->p_cdio, p_cdda->i_lsn);
466 if ( p_cdda->b_nav_mode )
467 i_last_lsn = p_cdda->last_disc_frame;
469 i_last_lsn = cdio_get_track_last_lsn(p_cdda->p_cdio, i_track);
471 cdda_audio_play(p_cdda->p_cdio, p_cdda->i_lsn, i_last_lsn);
475 if ( ! p_cdda->b_nav_mode )
476 p_cdda->i_lsn += cdio_get_track_lsn(p_cdda->p_cdio, p_cdda->i_track);
478 /* Seeked backwards and we are doing disc mode. */
479 if ( p_cdda->b_nav_mode && p_access->info.i_pos > i_pos ) {
483 for( i_track = p_cdda->i_track;
485 p_cdda->i_lsn < cdio_get_track_lsn(p_cdda->p_cdio, i_track);
486 i_track--, p_access->info.i_title-- ) ;
488 p_cdda->i_track = i_track;
489 p_access->info.i_update |= INPUT_UPDATE_TITLE | INPUT_UPDATE_META ;
490 psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
491 input_Control( p_cdda->p_input, INPUT_SET_NAME,
497 p_access->info.i_pos = i_pos;
503 Set up internal state so that we play a given track.
504 If we are using audio-ctl mode we also activate CD-ROM
508 cdda_play_track( access_t *p_access, track_t i_track )
510 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
512 dbg_print((INPUT_DBG_CALL), "called track: %d\n", i_track);
514 if (i_track > p_cdda->i_tracks)
516 msg_Err( p_access, "CD has %d tracks, and you requested track %d",
517 p_cdda->i_tracks, i_track );
521 p_cdda->i_track = i_track;
523 /* set up the frame boundaries for this particular track */
524 p_cdda->first_frame = p_cdda->i_lsn =
525 cdio_get_track_lsn(p_cdda->p_cdio, i_track);
527 p_cdda->last_frame = cdio_get_track_lsn(p_cdda->p_cdio, i_track+1) - 1;
529 #if LIBCDIO_VERSION_NUM >= 73
530 if (p_cdda->b_audio_ctl)
533 if ( p_cdda->b_nav_mode )
534 i_last_lsn = p_cdda->last_disc_frame;
536 i_last_lsn = cdio_get_track_last_lsn(p_cdda->p_cdio, i_track);
537 cdda_audio_play(p_cdda->p_cdio, p_cdda->i_lsn, i_last_lsn);
544 /****************************************************************************
546 ****************************************************************************/
548 /*****************************************************************************
549 * Open: open cdda device or image file and initialize structures
550 * for subsequent operations.
551 *****************************************************************************/
553 CDDAOpen( vlc_object_t *p_this )
555 access_t *p_access = (access_t*)p_this;
556 char * psz_source = NULL;
557 cdda_data_t *p_cdda = NULL;
560 vlc_bool_t b_single_track = false;
561 int i_rc = VLC_EGENERIC;
563 p_access->p_sys = NULL;
565 /* Set where to log errors messages from libcdio. */
566 p_cdda_input = p_access;
568 /* parse the options passed in command line : */
570 if( p_access->psz_path && *p_access->psz_path )
572 char *psz_parser = psz_source = strdup( p_access->psz_path );
574 while( *psz_parser && *psz_parser != '@' )
579 if( *psz_parser == '@' )
585 if ('T' == *psz_parser || 't' == *psz_parser )
588 i_track = (int)strtol( psz_parser, NULL, 10 );
589 i_track = i_track ? i_track : 1;
590 b_single_track = true;
594 if (!psz_source || !*psz_source)
596 /* No device/track given. Continue only when this plugin was
598 if( !p_this->b_force ) return VLC_EGENERIC;
600 psz_source = var_CreateGetString( p_this, "cd-audio" );
602 if( !psz_source || !*psz_source )
604 /* Scan for a CD-ROM drive with a CD-DA in it. */
606 cdio_get_devices_with_cap(NULL, CDIO_FS_AUDIO, false);
608 if (NULL == ppsz_drives || NULL == ppsz_drives[0] )
611 "libcdio couldn't find something with a CD-DA in it" );
612 if (ppsz_drives) cdio_free_device_list(ppsz_drives);
616 psz_source = strdup(ppsz_drives[0]);
617 cdio_free_device_list(ppsz_drives);
621 cdio_log_set_handler ( cdio_log_handler );
624 if( !(p_cdio = cdio_open( psz_source, DRIVER_UNKNOWN )) )
626 msg_Warn( p_access, "could not open %s", psz_source );
627 if (psz_source) free( psz_source );
631 p_cdda = calloc( 1, sizeof(cdda_data_t) );
634 msg_Err( p_access, "out of memory" );
640 cddb_log_set_handler ( cddb_log_handler );
641 p_cdda->cddb.disc = NULL;
642 p_cdda->b_cddb_enabled =
643 config_GetInt( p_access, MODULE_STRING "-cddb-enabled" );
647 config_GetInt( p_access, MODULE_STRING "-cdtext-enabled" );
649 p_cdda->b_cdtext_prefer =
650 config_GetInt( p_access, MODULE_STRING "-cdtext-prefer" );
652 #if LIBCDIO_VERSION_NUM >= 73
653 p_cdda->b_audio_ctl =
654 config_GetInt( p_access, MODULE_STRING "-analog-output" );
657 p_cdda->psz_source = strdup(psz_source);
658 p_cdda->b_header = VLC_FALSE;
659 p_cdda->p_cdio = p_cdio;
660 p_cdda->i_tracks = 0;
661 p_cdda->i_titles = 0;
662 p_cdda->i_debug = config_GetInt(p_this, MODULE_STRING
664 p_cdda->b_nav_mode = config_GetInt(p_this, MODULE_STRING
665 "-navigation-mode" );
666 p_cdda->i_blocks_per_read
667 = config_GetInt(p_this, MODULE_STRING "-blocks-per-read");
669 p_cdda->last_disc_frame =
670 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;
699 p_access->pf_read = NULL;
700 p_access->pf_block = CDDAReadBlocks;
703 p_access->pf_control = CDDAControl;
704 p_access->pf_seek = CDDASeek;
709 if (p_cdda->b_nav_mode)
710 i_last_lsn = p_cdda->last_disc_frame;
712 i_last_lsn = cdio_get_track_last_lsn(p_cdio, i_track);
714 if (CDIO_INVALID_LSN != i_last_lsn)
715 p_access->info.i_size = i_last_lsn * (uint64_t) CDIO_CD_FRAMESIZE_RAW;
717 p_access->info.i_size = 0;
720 p_access->info.i_update = 0;
721 p_access->info.b_eof = VLC_FALSE;
722 p_access->info.i_title = 0;
723 p_access->info.i_seekpoint = 0;
725 p_access->p_sys = (access_sys_t *) p_cdda;
727 /* We read the Table Of Content information */
728 i_rc = CDDAInit( p_access, p_cdda );
729 if ( VLC_SUCCESS != i_rc ) goto error;
731 cdda_play_track( p_access, i_track );
733 CDDAFixupPlaylist( p_access, p_cdda, b_single_track );
735 #if LIBCDIO_VERSION_NUM >= 72
738 char *psz_paranoia = config_GetPsz( p_access,
739 MODULE_STRING "-paranoia" );
740 p_cdda->e_paranoia = paranoia_none;
741 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 ) {
751 p_cdda->paranoia_cd = cdio_cddap_identify_cdio(p_cdio, 1, NULL);
752 /* We'll set for verbose paranoia messages. */
753 cdio_cddap_verbose_set(p_cdda->paranoia_cd, CDDA_MESSAGE_PRINTIT,
754 CDDA_MESSAGE_PRINTIT);
755 if ( 0 != cdio_cddap_open(p_cdda->paranoia_cd) ) {
756 msg_Warn( p_cdda_input, "unable to get paranoia support - "
757 "continuing without it." );
758 p_cdda->e_paranoia = paranoia_none;
760 p_cdda->paranoia = cdio_paranoia_init(p_cdda->paranoia_cd);
761 cdio_paranoia_seek(p_cdda->paranoia, p_cdda->i_lsn, SEEK_SET);
763 /* Set reading mode for full or overlap paranoia,
764 but allow skipping sectors. */
765 cdio_paranoia_modeset(p_cdda->paranoia,
766 paranoia_full == p_cdda->e_paranoia ?
767 PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP :
768 PARANOIA_MODE_OVERLAP^PARANOIA_MODE_NEVERSKIP
776 /* Build a WAV header to put in front of the output data.
777 This gets sent back in the Block (read) routine.
779 memset( &p_cdda->waveheader, 0, sizeof(WAVEHEADER) );
780 SetWLE( &p_cdda->waveheader.Format, 1 ); /*WAVE_FORMAT_PCM*/
781 SetWLE( &p_cdda->waveheader.BitsPerSample, 16);
782 p_cdda->waveheader.MainChunkID = VLC_FOURCC('R', 'I', 'F', 'F');
783 p_cdda->waveheader.Length = 0; /* we just don't know */
784 p_cdda->waveheader.ChunkTypeID = VLC_FOURCC('W', 'A', 'V', 'E');
785 p_cdda->waveheader.SubChunkID = VLC_FOURCC('f', 'm', 't', ' ');
786 SetDWLE( &p_cdda->waveheader.SubChunkLength, 16);
787 SetWLE( &p_cdda->waveheader.Modus, 2);
788 SetDWLE( &p_cdda->waveheader.SampleFreq, CDDA_FREQUENCY_SAMPLE);
789 SetWLE( &p_cdda->waveheader.BytesPerSample,
790 2 /*Modus*/ * 16 /*BitsPerSample*/ / 8 );
791 SetDWLE( &p_cdda->waveheader.BytesPerSec,
792 2*16/8 /*BytesPerSample*/ * CDDA_FREQUENCY_SAMPLE );
793 p_cdda->waveheader.DataChunkID = VLC_FOURCC('d', 'a', 't', 'a');
794 p_cdda->waveheader.DataLength = 0; /* we just don't know */
797 var_Create( p_access, MODULE_STRING "-caching",
798 VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
799 vlc_object_release( p_cdda->p_input );
803 cdio_destroy( p_cdda->p_cdio );
804 if( psz_source) free( psz_source );
806 if ( p_cdda->p_input )
807 vlc_object_release( p_cdda->p_input );
815 /*****************************************************************************
816 * CDDAClose: closes cdda and frees any resources associded with it.
817 *****************************************************************************/
819 CDDAClose (vlc_object_t *p_this )
821 access_t *p_access = (access_t *) p_this;
822 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
825 #if LIBCDIO_VERSION_NUM >= 73
826 if (p_cdda->b_audio_ctl)
827 cdio_audio_stop(p_cdda->p_cdio);
830 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "" );
832 /* Remove playlist titles */
833 for( i = 0; i < p_cdda->i_titles; i++ )
835 vlc_input_title_Delete( p_cdda->p_title[i] );
839 cddb_log_set_handler ((cddb_log_handler_t) uninit_log_handler);
840 if (p_cdda->b_cddb_enabled)
841 cddb_disc_destroy(p_cdda->cddb.disc);
844 cdio_destroy( p_cdda->p_cdio );
845 cdio_log_set_handler (uninit_log_handler);
847 #if LIBCDIO_VERSION_NUM >= 72
848 if (p_cdda->paranoia)
849 cdio_paranoia_free(p_cdda->paranoia);
850 if (p_cdda->paranoia_cd)
851 cdio_cddap_close_no_free_cdio(p_cdda->paranoia_cd);
854 if (p_cdda->psz_mcn) free( p_cdda->psz_mcn );
855 if (p_cdda->psz_source) free( p_cdda->psz_source );
857 #if LIBCDDB_VERSION_NUM >= 1
865 /*****************************************************************************
866 * Control: The front-end or vlc engine calls here to ether get
867 * information such as meta information or plugin capabilities or to
868 * issue miscellaneous "set" requests.
869 *****************************************************************************/
870 static int CDDAControl( access_t *p_access, int i_query, va_list args )
872 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
876 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_EVENT),
877 "query %d", i_query );
881 /* Pass back a copy of meta information that was gathered when we
882 during the Open/Initialize call.
884 case ACCESS_GET_META:
886 vlc_meta_t **pp_meta = (vlc_meta_t**)va_arg( args, vlc_meta_t** );
890 *pp_meta = vlc_meta_Duplicate( p_cdda->p_meta );
891 dbg_print( INPUT_DBG_META, "%s", "Meta copied" );
897 msg_Warn( p_access, "tried to copy NULL meta info" );
902 case ACCESS_CAN_CONTROL_PACE:
904 vlc_bool_t *pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
905 *pb_bool = p_cdda->b_audio_ctl ? VLC_FALSE : VLC_TRUE;
906 dbg_print( INPUT_DBG_META, "can control pace? %d", *pb_bool);
910 case ACCESS_CAN_FASTSEEK:
911 dbg_print( INPUT_DBG_META, "can fast seek?");
913 case ACCESS_CAN_SEEK:
914 dbg_print( INPUT_DBG_META, "can seek?");
916 case ACCESS_CAN_PAUSE:
917 dbg_print( INPUT_DBG_META, "can pause?");
920 vlc_bool_t *pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
928 pi_int = (int*)va_arg( args, int * );
929 *pi_int = p_cdda-> i_blocks_per_read * CDIO_CD_FRAMESIZE_RAW;
930 dbg_print( INPUT_DBG_META, "Get MTU %d", *pi_int);
934 case ACCESS_GET_PTS_DELAY:
936 int64_t *pi_64 = (int64_t*)va_arg( args, int64_t * );
937 *pi_64 = var_GetInteger( p_access, MODULE_STRING "-caching" )
938 * MILLISECONDS_PER_SEC;
942 case ACCESS_GET_TITLE_INFO:
944 input_title_t ***ppp_title =
945 (input_title_t***)va_arg( args, input_title_t*** );
947 pi_int = (int*)va_arg( args, int* );
948 *((int*)va_arg( args, int* )) = 1; /* Title offset */
950 dbg_print ( INPUT_DBG_EVENT,
951 "GET TITLE: i_tracks %d, i_tracks %d",
952 p_cdda->i_tracks, p_cdda->i_tracks );
954 CDDAMetaInfo( p_access, CDIO_INVALID_TRACK );
956 if ( p_cdda->b_nav_mode) {
958 CDDAFormatTitle( p_access, p_cdda->i_track );
959 input_Control( p_cdda->p_input, INPUT_SET_NAME,
964 /* Duplicate title info */
965 if( p_cdda->i_titles == 0 )
967 *pi_int = 0; ppp_title = NULL;
970 *pi_int = p_cdda->i_titles;
971 *ppp_title = calloc(1,
972 sizeof( input_title_t **) * p_cdda->i_titles );
974 if (!*ppp_title) return VLC_ENOMEM;
976 for( i = 0; i < p_cdda->i_titles; i++ )
978 if ( p_cdda->p_title[i] ) {
980 vlc_input_title_Duplicate( p_cdda->p_title[i] );
986 case ACCESS_SET_TITLE:
988 i = (int)va_arg( args, int );
990 dbg_print( INPUT_DBG_EVENT, "set title %d", i );
991 if( i != p_access->info.i_title )
993 const track_t i_track = p_cdda->i_first_track + i;
995 p_access->info.i_title = i;
996 if ( p_cdda->b_nav_mode)
999 char *psz_title = CDDAFormatTitle( p_access, i_track );
1000 input_Control( p_cdda->p_input, INPUT_SET_NAME,
1003 p_cdda->i_track = i_track;
1004 i_last_lsn = cdio_get_track_lsn(p_cdda->p_cdio,
1005 CDIO_CDROM_LEADOUT_TRACK);
1006 if (CDIO_INVALID_LSN != i_last_lsn)
1007 p_access->info.i_size = (int64_t) CDIO_CD_FRAMESIZE_RAW
1009 p_access->info.i_pos = (int64_t)
1010 cdio_get_track_lsn( p_cdda->p_cdio, i_track )
1011 * CDIO_CD_FRAMESIZE_RAW;
1013 p_access->info.i_size = p_cdda->p_title[i]->i_size;
1014 p_access->info.i_pos = 0;
1016 p_access->info.i_update =
1017 INPUT_UPDATE_TITLE | INPUT_UPDATE_SIZE;
1019 /* Next sector to read */
1020 p_cdda->i_lsn = cdio_get_track_lsn(p_cdda->p_cdio, i_track);
1025 case ACCESS_SET_PAUSE_STATE:
1026 dbg_print( INPUT_DBG_META, "Pause");
1027 if (p_cdda->b_audio_ctl)
1028 cdda_audio_pause(p_cdda->p_cdio);
1031 case ACCESS_SET_SEEKPOINT:
1032 dbg_print( INPUT_DBG_META, "set seekpoint");
1033 return VLC_EGENERIC;
1035 case ACCESS_SET_PRIVATE_ID_STATE:
1036 dbg_print( INPUT_DBG_META, "set private id state");
1037 return VLC_EGENERIC;
1040 msg_Warn( p_access, "unimplemented query in control" );
1041 return VLC_EGENERIC;
1047 /*****************************************************************************
1050 Initialize information pertaining to the CD: the number of tracks,
1051 first track number, LSNs for each track and the leadout. The leadout
1052 information is stored after the last track. The LSN array is
1053 0-origin, same as p_access->info. Add first_track to get what track
1054 number this is on the CD. Note: libcdio uses the real track number.
1056 On input we assume p_cdda->p_cdio and p_cdda->i_track have been set.
1058 We return the VLC-type status, e.g. VLC_SUCCESS, VLC_ENOMEM, etc.
1059 *****************************************************************************/
1060 static int CDDAInit( access_t *p_access, cdda_data_t *p_cdda )
1062 discmode_t discmode = CDIO_DISC_MODE_NO_INFO;
1064 p_cdda->i_tracks = cdio_get_num_tracks(p_cdda->p_cdio);
1065 p_cdda->i_first_track = cdio_get_first_track_num(p_cdda->p_cdio);
1067 discmode = cdio_get_discmode(p_cdda->p_cdio);
1069 case CDIO_DISC_MODE_CD_DA:
1070 case CDIO_DISC_MODE_CD_MIXED:
1071 /* These are possible for CD-DA */
1074 /* These are not possible for CD-DA */
1076 "Disc seems not to be CD-DA. libcdio reports it is %s",
1077 discmode2str[discmode]
1079 return VLC_EGENERIC;
1082 /* Set reading start LSN. */
1083 p_cdda->i_lsn = cdio_get_track_lsn(p_cdda->p_cdio, p_cdda->i_track);