1 /*****************************************************************************
2 * access.c : CD digital audio input module for vlc using libcdio
3 *****************************************************************************
4 * Copyright (C) 2000, 2003, 2004, 2005 VideoLAN
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., 59 Temple Place - Suite 330, Boston, MA 02111, 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); */
170 get_current_pos ( 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;
180 if (DRIVER_OP_SUCCESS == cdio_audio_read_subchannel(p_cdio, &sub)) {
181 if (sub.audio_status == CDIO_MMC_READ_SUB_ST_PAUSED ||
182 sub.audio_status == CDIO_MMC_READ_SUB_ST_PLAY)
183 return CDIO_INVALID_LSN;
185 if ( ! p_cdda->b_nav_mode ) {
186 char *psz = cdio_msf_to_str(&sub.abs_addr);
187 // fprintf(stderr, "+++disk mode abs msf %s", psz);
189 i_offset = cdio_msf_to_lsn((&sub.abs_addr));
190 // fprintf(stderr, " frame offset %d\n", i_offset);
192 char *psz = cdio_msf_to_str(&sub.rel_addr);
193 // fprintf(stderr, "+++track abs msf %s", psz);
195 i_offset = cdio_msf_to_lsn((&sub.rel_addr));
196 // fprintf(stderr, " frame offset %d\n", i_offset);
199 // fprintf(stderr, "+++Error reading current pos\n");
200 i_offset = p_cdda->i_lsn;
203 i_offset = p_cdda->i_lsn;
205 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 ) return NULL;
230 if( !p_cdda->b_header )
232 /* Return only the dummy RIFF header we created in Open/Init */
233 p_block = block_New( p_access, sizeof( WAVEHEADER ) );
234 memcpy( p_block->p_buffer, &p_cdda->waveheader, sizeof(WAVEHEADER) );
235 p_cdda->b_header = VLC_TRUE;
239 /* Check end of track */
240 while( p_cdda->i_lsn > cdio_get_track_last_lsn(p_cdda->p_cdio,
243 if( p_cdda->i_track >= p_cdda->i_first_track + p_cdda->i_titles - 1 )
245 dbg_print( (INPUT_DBG_LSN), "EOF");
246 p_access->info.b_eof = VLC_TRUE;
250 p_access->info.i_update |= INPUT_UPDATE_TITLE | INPUT_UPDATE_META;
251 p_access->info.i_title++;
254 if ( p_cdda-> b_nav_mode ) {
255 char *psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
256 input_Control( p_cdda->p_input, INPUT_SET_NAME, psz_title );
259 p_access->info.i_size =
260 p_cdda->p_title[p_access->info.i_title]->i_size;
261 p_access->info.i_pos = 0;
262 p_access->info.i_update |= INPUT_UPDATE_SIZE;
266 /* Possibly adjust i_blocks so we don't read past the end of a track. */
267 if( p_cdda->i_lsn + i_blocks >=
268 cdio_get_track_lsn(p_cdda->p_cdio, p_cdda->i_track+1) )
270 i_blocks = cdio_get_track_lsn( p_cdda->p_cdio, p_cdda->i_track+1 )
274 /* Do the actual reading */
275 p_block = block_New( p_access, i_blocks * CDIO_CD_FRAMESIZE_RAW );
278 msg_Err( p_access, "Cannot get a new block of size: %i",
279 i_blocks * CDIO_CD_FRAMESIZE_RAW );
284 #if LIBCDIO_VERSION_NUM >= 72
285 driver_return_code_t rc = DRIVER_OP_SUCCESS;
287 if ( p_cdda->e_paranoia && p_cdda->paranoia )
290 for( i = 0; i < i_blocks; i++ )
292 int16_t *p_readbuf = cdio_paranoia_read(p_cdda->paranoia, NULL);
293 char *psz_err=cdio_cddap_errors(p_cdda->paranoia_cd);
294 char *psz_mes=cdio_cddap_messages(p_cdda->paranoia_cd);
296 if (psz_mes || psz_err)
297 msg_Err( p_access, "%s%s\n", psz_mes ? psz_mes: "",
298 psz_err ? psz_err: "" );
300 if (psz_err) free(psz_err);
301 if (psz_mes) free(psz_mes);
303 msg_Err( p_access, "paranoia read error on frame %i\n",
306 memcpy(p_block->p_buffer + i * CDIO_CD_FRAMESIZE_RAW,
307 p_readbuf, CDIO_CD_FRAMESIZE_RAW);
311 rc = cdio_read_audio_sectors( p_cdda->p_cdio, p_block->p_buffer,
312 p_cdda->i_lsn, i_blocks);
314 #define DRIVER_OP_SUCCESS 0
316 rc = cdio_read_audio_sectors( p_cdda->p_cdio, p_block->p_buffer,
317 p_cdda->i_lsn, i_blocks);
319 if( rc != DRIVER_OP_SUCCESS )
321 msg_Err( p_access, "could not read %d sectors starting from %lu",
322 i_blocks, (long unsigned int) p_cdda->i_lsn );
323 block_Release( p_block );
325 /* If we had problems above, assume the problem is with
326 the first sector of the read and set to skip it. In
327 the future libcdio may have cdparanoia support.
330 p_access->info.i_pos += CDIO_CD_FRAMESIZE_RAW;
335 p_cdda->i_lsn += i_blocks;
336 p_access->info.i_pos += i_blocks * CDIO_CD_FRAMESIZE_RAW;
341 /*****************************************************************************
342 * CDDARead: Handler for audio control reads the CD-DA.
343 *****************************************************************************/
345 CDDARead( access_t * p_access, uint8_t *p_buffer, int i_len )
347 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
349 dbg_print((INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_LSN),
350 "called lsn: %d pos: %lld, size: %lld",
351 p_cdda->i_lsn, p_access->info.i_pos, p_access->info.i_size);
353 /* Check end of file */
354 if( p_access->info.b_eof ) return 0;
357 lsn_t i_lsn = get_current_pos(p_access);
358 if (CDIO_INVALID_LSN == i_lsn) {
359 memset( p_buffer, 0, i_len );
363 p_cdda->i_lsn = i_lsn;
364 p_access->info.i_pos = p_cdda->i_lsn * CDIO_CD_FRAMESIZE_RAW;
367 dbg_print((INPUT_DBG_LSN), "updated lsn: %d", p_cdda->i_lsn);
369 /* Check end of track */
370 while( p_cdda->i_lsn > cdio_get_track_last_lsn(p_cdda->p_cdio,
373 if( p_cdda->i_track >= p_cdda->i_first_track + p_cdda->i_titles - 1 )
375 dbg_print( (INPUT_DBG_LSN), "EOF");
376 p_access->info.b_eof = VLC_TRUE;
380 p_access->info.i_update |= INPUT_UPDATE_TITLE;
381 p_access->info.i_title++;
384 if ( p_cdda-> b_nav_mode ) {
385 char *psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
386 input_Control( p_cdda->p_input, INPUT_SET_NAME, psz_title );
389 p_access->info.i_size =
390 p_cdda->p_title[p_access->info.i_title]->i_size;
391 p_access->info.i_pos = 0;
392 p_access->info.i_update |= INPUT_UPDATE_SIZE;
396 memset( p_buffer, 0, i_len );
400 #if LIBCDIO_VERSION_NUM >= 73
401 /*! Pause CD playing via audio control */
403 cdda_audio_pause(CdIo_t *p_cdio)
406 cdio_subchannel_t sub;
407 if (DRIVER_OP_SUCCESS == cdio_audio_read_subchannel(p_cdio, &sub)) {
408 if (sub.audio_status == CDIO_MMC_READ_SUB_ST_PLAY) {
409 b_ok = DRIVER_OP_SUCCESS == cdio_audio_pause(p_cdio);
416 /*! play CD using audio controls */
417 static driver_return_code_t
418 cdda_audio_play(CdIo_t *p_cdio, lsn_t start_lsn, lsn_t end_lsn)
422 cdio_lsn_to_msf(start_lsn, &start_msf);
423 cdio_lsn_to_msf(end_lsn, &last_msf);
424 cdda_audio_pause(p_cdio);
425 return cdio_audio_play_msf (p_cdio, &start_msf, &last_msf);
429 /****************************************************************************
430 * CDDASeek - change position for subsequent reads. For example, this
431 * can happen if the user moves a position slider bar in a GUI.
432 ****************************************************************************/
434 CDDASeek( access_t * p_access, int64_t i_pos )
436 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
438 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_SEEK),
439 "lsn %lu, offset: %lld",
440 (long unsigned int) p_cdda->i_lsn, i_pos );
442 p_cdda->i_lsn = (i_pos / CDIO_CD_FRAMESIZE_RAW);
444 #if LIBCDIO_VERSION_NUM >= 72
445 if ( p_cdda->e_paranoia && p_cdda->paranoia )
446 cdio_paranoia_seek(p_cdda->paranoia, p_cdda->i_lsn, SEEK_SET);
449 #if LIBCDIO_VERSION_NUM >= 73
450 if ( p_cdda->b_audio_ctl ) {
451 track_t i_track = cdio_get_track(p_cdda->p_cdio, p_cdda->i_lsn);
454 if ( p_cdda->b_nav_mode )
455 last_lsn = p_cdda->i_lsn + cdio_get_track_sec_count(p_cdda->p_cdio,
458 last_lsn = p_cdda->i_lsn +
459 cdio_get_track_lsn(p_cdda->p_cdio, CDIO_CDROM_LEADOUT_TRACK);
461 cdda_audio_play(p_cdda->p_cdio, p_cdda->i_lsn, last_lsn);
465 if ( ! p_cdda->b_nav_mode )
466 p_cdda->i_lsn += cdio_get_track_lsn(p_cdda->p_cdio, p_cdda->i_track);
468 /* Seeked backwards and we are doing disc mode. */
469 if ( p_cdda->b_nav_mode && p_access->info.i_pos > i_pos ) {
473 for( i_track = p_cdda->i_track;
475 p_cdda->i_lsn < cdio_get_track_lsn(p_cdda->p_cdio, i_track);
476 i_track--, p_access->info.i_title-- ) ;
478 p_cdda->i_track = i_track;
479 p_access->info.i_update |= INPUT_UPDATE_TITLE;
480 psz_title = CDDAFormatTitle( p_access, p_cdda->i_track );
481 input_Control( p_cdda->p_input, INPUT_SET_NAME,
487 p_access->info.i_pos = i_pos;
492 /****************************************************************************
494 ****************************************************************************/
496 /*****************************************************************************
497 * Open: open cdda device or image file and initialize structures
498 * for subsequent operations.
499 *****************************************************************************/
501 CDDAOpen( vlc_object_t *p_this )
503 access_t *p_access = (access_t*)p_this;
504 char * psz_source = NULL;
505 cdda_data_t *p_cdda = NULL;
508 vlc_bool_t b_single_track = false;
509 int i_rc = VLC_EGENERIC;
511 p_access->p_sys = NULL;
513 /* Set where to log errors messages from libcdio. */
514 p_cdda_input = p_access;
516 /* parse the options passed in command line : */
518 if( p_access->psz_path && *p_access->psz_path )
520 char *psz_parser = psz_source = strdup( p_access->psz_path );
522 while( *psz_parser && *psz_parser != '@' )
527 if( *psz_parser == '@' )
533 if ('T' == *psz_parser || 't' == *psz_parser )
536 i_track = (int)strtol( psz_parser, NULL, 10 );
537 i_track = i_track ? i_track : 1;
538 b_single_track = true;
542 if (!psz_source || !*psz_source)
544 /* No device/track given. Continue only when this plugin was
546 if( !p_this->b_force ) return VLC_EGENERIC;
548 psz_source = var_CreateGetString( p_this, "cd-audio" );
550 if( !psz_source || !*psz_source )
552 /* Scan for a CD-ROM drive with a CD-DA in it. */
554 cdio_get_devices_with_cap(NULL, CDIO_FS_AUDIO, false);
556 if (NULL == ppsz_drives || NULL == ppsz_drives[0] )
559 "libcdio couldn't find something with a CD-DA in it" );
560 if (ppsz_drives) cdio_free_device_list(ppsz_drives);
564 psz_source = strdup(ppsz_drives[0]);
565 cdio_free_device_list(ppsz_drives);
569 cdio_log_set_handler ( cdio_log_handler );
572 if( !(p_cdio = cdio_open( psz_source, DRIVER_UNKNOWN )) )
574 msg_Warn( p_access, "could not open %s", psz_source );
575 if (psz_source) free( psz_source );
579 p_cdda = calloc( 1, sizeof(cdda_data_t) );
582 msg_Err( p_access, "out of memory" );
588 cddb_log_set_handler ( cddb_log_handler );
589 p_cdda->cddb.disc = NULL;
590 p_cdda->b_cddb_enabled =
591 config_GetInt( p_access, MODULE_STRING "-cddb-enabled" );
595 config_GetInt( p_access, MODULE_STRING "-cdtext-enabled" );
597 p_cdda->b_cdtext_prefer =
598 config_GetInt( p_access, MODULE_STRING "-cdtext-prefer" );
600 #if LIBCDIO_VERSION_NUM >= 73
601 p_cdda->b_audio_ctl =
602 config_GetInt( p_access, MODULE_STRING "-analog-output" );
605 p_cdda->psz_source = strdup(psz_source);
606 p_cdda->b_header = VLC_FALSE;
607 p_cdda->p_cdio = p_cdio;
608 p_cdda->i_tracks = 0;
610 p_cdda->i_titles = 0;
611 p_cdda->i_track = i_track;
612 p_cdda->i_debug = config_GetInt(p_this, MODULE_STRING
614 p_cdda->b_nav_mode = config_GetInt(p_this, MODULE_STRING
615 "-navigation-mode" );
616 p_cdda->i_blocks_per_read
617 = config_GetInt(p_this, MODULE_STRING "-blocks-per-read");
619 p_cdda->p_input = vlc_object_find( p_access, VLC_OBJECT_INPUT,
622 if (0 == p_cdda->i_blocks_per_read)
623 p_cdda->i_blocks_per_read = DEFAULT_BLOCKS_PER_READ;
625 if ( p_cdda->i_blocks_per_read < MIN_BLOCKS_PER_READ
626 || p_cdda->i_blocks_per_read > MAX_BLOCKS_PER_READ )
628 msg_Warn( p_cdda_input,
629 "Number of blocks (%d) has to be between %d and %d. "
631 p_cdda->i_blocks_per_read,
632 MIN_BLOCKS_PER_READ, MAX_BLOCKS_PER_READ,
633 DEFAULT_BLOCKS_PER_READ );
634 p_cdda->i_blocks_per_read = DEFAULT_BLOCKS_PER_READ;
637 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "%s", psz_source );
639 /* Set up p_access */
640 if (p_cdda->b_audio_ctl)
642 p_access->pf_read = CDDARead;
643 p_access->pf_block = NULL;
646 p_access->pf_read = NULL;
647 p_access->pf_block = CDDAReadBlocks;
650 p_access->pf_control = CDDAControl;
651 p_access->pf_seek = CDDASeek;
656 if (p_cdda->b_nav_mode)
657 i_last_lsn = cdio_get_track_lsn(p_cdio, CDIO_CDROM_LEADOUT_TRACK);
659 i_last_lsn = cdio_get_track_last_lsn(p_cdio, i_track);
661 if (CDIO_INVALID_LSN != i_last_lsn)
662 p_access->info.i_size = i_last_lsn * (uint64_t) CDIO_CD_FRAMESIZE_RAW;
664 p_access->info.i_size = 0;
667 p_access->info.i_update = 0;
668 p_access->info.b_eof = VLC_FALSE;
669 p_access->info.i_title = 0;
670 p_access->info.i_seekpoint = 0;
672 p_access->p_sys = (access_sys_t *) p_cdda;
674 /* We read the Table Of Content information */
675 i_rc = CDDAInit( p_access, p_cdda );
676 if ( VLC_SUCCESS != i_rc ) goto error;
678 CDDAFixupPlaylist( p_access, p_cdda, b_single_track );
680 #if LIBCDIO_VERSION_NUM >= 72
683 char *psz_paranoia = config_GetPsz( p_access,
684 MODULE_STRING "-paranoia" );
685 p_cdda->e_paranoia = paranoia_none;
686 if( psz_paranoia && *psz_paranoia )
689 if( !strncmp( psz_paranoia, "full", strlen("full") ) )
690 p_cdda->e_paranoia = paranoia_full;
691 else if( !strncmp( psz_paranoia, "overlap", strlen("overlap") ) )
692 p_cdda->e_paranoia = paranoia_overlap;
694 /* Use CD Paranoia? */
695 if ( p_cdda->e_paranoia ) {
696 p_cdda->paranoia_cd = cdio_cddap_identify_cdio(p_cdio, 1, NULL);
697 /* We'll set for verbose paranoia messages. */
698 cdio_cddap_verbose_set(p_cdda->paranoia_cd, CDDA_MESSAGE_PRINTIT,
699 CDDA_MESSAGE_PRINTIT);
700 if ( 0 != cdio_cddap_open(p_cdda->paranoia_cd) ) {
701 msg_Warn( p_cdda_input, "Unable to get paranoia support - "
702 "continuing without it." );
703 p_cdda->e_paranoia = paranoia_none;
705 p_cdda->paranoia = cdio_paranoia_init(p_cdda->paranoia_cd);
706 cdio_paranoia_seek(p_cdda->paranoia, p_cdda->i_lsn, SEEK_SET);
708 /* Set reading mode for full or overlap paranoia,
709 but allow skipping sectors. */
710 cdio_paranoia_modeset(p_cdda->paranoia,
711 paranoia_full == p_cdda->e_paranoia ?
712 PARANOIA_MODE_FULL^PARANOIA_MODE_NEVERSKIP :
713 PARANOIA_MODE_OVERLAP^PARANOIA_MODE_NEVERSKIP
721 /* Build a WAV header to put in front of the output data.
722 This gets sent back in the Block (read) routine.
724 memset( &p_cdda->waveheader, 0, sizeof(WAVEHEADER) );
725 SetWLE( &p_cdda->waveheader.Format, 1 ); /*WAVE_FORMAT_PCM*/
726 SetWLE( &p_cdda->waveheader.BitsPerSample, 16);
727 p_cdda->waveheader.MainChunkID = VLC_FOURCC('R', 'I', 'F', 'F');
728 p_cdda->waveheader.Length = 0; /* we just don't know */
729 p_cdda->waveheader.ChunkTypeID = VLC_FOURCC('W', 'A', 'V', 'E');
730 p_cdda->waveheader.SubChunkID = VLC_FOURCC('f', 'm', 't', ' ');
731 SetDWLE( &p_cdda->waveheader.SubChunkLength, 16);
732 SetWLE( &p_cdda->waveheader.Modus, 2);
733 SetDWLE( &p_cdda->waveheader.SampleFreq, CDDA_FREQUENCY_SAMPLE);
734 SetWLE( &p_cdda->waveheader.BytesPerSample,
735 2 /*Modus*/ * 16 /*BitsPerSample*/ / 8 );
736 SetDWLE( &p_cdda->waveheader.BytesPerSec,
737 2*16/8 /*BytesPerSample*/ * CDDA_FREQUENCY_SAMPLE );
738 p_cdda->waveheader.DataChunkID = VLC_FOURCC('d', 'a', 't', 'a');
739 p_cdda->waveheader.DataLength = 0; /* we just don't know */
742 var_Create( p_access, MODULE_STRING "-caching",
743 VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
744 vlc_object_release( p_cdda->p_input );
748 cdio_destroy( p_cdda->p_cdio );
749 if( psz_source) free( psz_source );
751 if ( p_cdda->p_input )
752 vlc_object_release( p_cdda->p_input );
760 /*****************************************************************************
761 * CDDAClose: closes cdda and frees any resources associded with it.
762 *****************************************************************************/
764 CDDAClose (vlc_object_t *p_this )
766 access_t *p_access = (access_t *) p_this;
767 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
770 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "" );
772 /* Remove playlist titles */
773 for( i = 0; i < p_cdda->i_titles; i++ )
775 vlc_input_title_Delete( p_cdda->p_title[i] );
779 cddb_log_set_handler ((cddb_log_handler_t) uninit_log_handler);
780 if (p_cdda->b_cddb_enabled)
781 cddb_disc_destroy(p_cdda->cddb.disc);
784 cdio_destroy( p_cdda->p_cdio );
785 cdio_log_set_handler (uninit_log_handler);
787 #if LIBCDIO_VERSION_NUM >= 72
788 if (p_cdda->paranoia)
789 cdio_paranoia_free(p_cdda->paranoia);
790 if (p_cdda->paranoia_cd)
791 cdio_cddap_close_no_free_cdio(p_cdda->paranoia_cd);
794 if (p_cdda->psz_mcn) free( p_cdda->psz_mcn );
795 if (p_cdda->psz_source) free( p_cdda->psz_source );
797 #if LIBCDDB_VERSION_NUM >= 1
805 /*****************************************************************************
806 * Control: The front-end or vlc engine calls here to ether get
807 * information such as meta information or plugin capabilities or to
808 * issue miscellaneous "set" requests.
809 *****************************************************************************/
810 static int CDDAControl( access_t *p_access, int i_query, va_list args )
812 cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
816 dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_EVENT),
817 "query %d", i_query );
821 /* Pass back a copy of meta information that was gathered when we
822 during the Open/Initialize call.
824 case ACCESS_GET_META:
826 vlc_meta_t **pp_meta = (vlc_meta_t**)va_arg( args, vlc_meta_t** );
827 if ( p_cdda->p_meta )
829 *pp_meta = vlc_meta_Duplicate( p_cdda->p_meta );
830 dbg_print( INPUT_DBG_META, "%s", "Meta copied" );
834 msg_Warn( p_access, "tried to copy NULL meta info" );
839 case ACCESS_CAN_CONTROL_PACE:
841 vlc_bool_t *pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
842 dbg_print( INPUT_DBG_META, "can control pace");
843 *pb_bool = p_cdda->b_audio_ctl ? VLC_FALSE : VLC_TRUE;
847 case ACCESS_CAN_FASTSEEK:
848 dbg_print( INPUT_DBG_META, "can fast seek");
850 case ACCESS_CAN_SEEK:
851 dbg_print( INPUT_DBG_META, "can seek");
853 case ACCESS_CAN_PAUSE:
854 dbg_print( INPUT_DBG_META, "can pause");
857 vlc_bool_t *pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
865 pi_int = (int*)va_arg( args, int * );
866 *pi_int = p_cdda-> i_blocks_per_read * CDIO_CD_FRAMESIZE_RAW;
867 dbg_print( INPUT_DBG_META, "Get MTU %d", *pi_int);
871 case ACCESS_GET_PTS_DELAY:
873 int64_t *pi_64 = (int64_t*)va_arg( args, int64_t * );
874 *pi_64 = var_GetInteger( p_access, MODULE_STRING "-caching" )
875 * MILLISECONDS_PER_SEC;
880 case ACCESS_SET_PAUSE_STATE:
881 dbg_print( INPUT_DBG_META, "Set pause state");
884 case ACCESS_GET_TITLE_INFO:
886 input_title_t ***ppp_title =
887 (input_title_t***)va_arg( args, input_title_t*** );
889 pi_int = (int*)va_arg( args, int* );
890 *((int*)va_arg( args, int* )) = 1; /* Title offset */
892 dbg_print ( INPUT_DBG_EVENT,
893 "GET TITLE: i_tracks %d, i_tracks %d",
894 p_cdda->i_tracks, p_cdda->i_tracks );
896 CDDAMetaInfo( p_access, CDIO_INVALID_TRACK );
898 if ( p_cdda->b_nav_mode) {
900 CDDAFormatTitle( p_access, p_cdda->i_track );
901 input_Control( p_cdda->p_input, INPUT_SET_NAME,
906 /* Duplicate title info */
907 if( p_cdda->i_titles == 0 )
909 *pi_int = 0; ppp_title = NULL;
912 *pi_int = p_cdda->i_titles;
913 *ppp_title = calloc(1,
914 sizeof( input_title_t **) * p_cdda->i_titles );
916 if (!*ppp_title) return VLC_ENOMEM;
918 for( i = 0; i < p_cdda->i_titles; i++ )
920 if ( p_cdda->p_title[i] ) {
922 vlc_input_title_Duplicate( p_cdda->p_title[i] );
928 case ACCESS_SET_TITLE:
930 i = (int)va_arg( args, int );
932 dbg_print( INPUT_DBG_EVENT, "set title %d", i );
933 if( i != p_access->info.i_title )
935 const track_t i_track = p_cdda->i_track + i;
937 p_access->info.i_title = i;
938 if ( p_cdda->b_nav_mode)
941 char *psz_title = CDDAFormatTitle( p_access, i_track );
942 input_Control( p_cdda->p_input, INPUT_SET_NAME,
945 p_cdda->i_track = i_track;
946 i_last_lsn = cdio_get_track_lsn(p_cdda->p_cdio,
947 CDIO_CDROM_LEADOUT_TRACK);
948 if (CDIO_INVALID_LSN != i_last_lsn)
949 p_access->info.i_size = (int64_t) CDIO_CD_FRAMESIZE_RAW
951 p_access->info.i_pos = (int64_t)
952 cdio_get_track_lsn( p_cdda->p_cdio, i_track )
953 * CDIO_CD_FRAMESIZE_RAW;
955 p_access->info.i_size = p_cdda->p_title[i]->i_size;
956 p_access->info.i_pos = 0;
958 p_access->info.i_update =
959 INPUT_UPDATE_TITLE | INPUT_UPDATE_SIZE;
961 /* Next sector to read */
962 p_cdda->i_lsn = cdio_get_track_lsn(p_cdda->p_cdio, i_track);
967 case ACCESS_SET_SEEKPOINT:
968 case ACCESS_SET_PRIVATE_ID_STATE:
969 dbg_print( INPUT_DBG_META, "set seekpoint/set private id state");
973 msg_Warn( p_access, "unimplemented query in control" );
980 /*****************************************************************************
983 Initialize information pertaining to the CD: the number of tracks,
984 first track number, LSNs for each track and the leadout. The leadout
985 information is stored after the last track. The LSN array is
986 0-origin, same as p_access->info. Add first_track to get what track
987 number this is on the CD. Note: libcdio uses the real track number.
989 On input we assume p_cdda->p_cdio and p_cdda->i_track have been set.
991 We return the VLC-type status, e.g. VLC_SUCCESS, VLC_ENOMEM, etc.
992 *****************************************************************************/
993 static int CDDAInit( access_t *p_access, cdda_data_t *p_cdda )
995 discmode_t discmode = CDIO_DISC_MODE_NO_INFO;
997 p_cdda->i_tracks = cdio_get_num_tracks(p_cdda->p_cdio);
998 p_cdda->i_first_track = cdio_get_first_track_num(p_cdda->p_cdio);
1000 discmode = cdio_get_discmode(p_cdda->p_cdio);
1002 case CDIO_DISC_MODE_CD_DA:
1003 case CDIO_DISC_MODE_CD_MIXED:
1004 /* These are possible for CD-DA */
1007 /* These are not possible for CD-DA */
1009 "Disc seems not to be CD-DA. libcdio reports it is %s",
1010 discmode2str[discmode]
1012 return VLC_EGENERIC;
1015 /* Set reading start LSN. */
1016 p_cdda->i_lsn = cdio_get_track_lsn(p_cdda->p_cdio, p_cdda->i_track);