]> git.sesse.net Git - vlc/blob - modules/access/cdda/access.c
Fix crash
[vlc] / modules / access / cdda / access.c
1 /*****************************************************************************
2  * cddax.c : CD digital audio input module for vlc using libcdio
3  *****************************************************************************
4  * Copyright (C) 2000, 2003, 2004 VideoLAN
5  * $Id$
6  *
7  * Authors: Rocky Bernstein <rocky@panix.com>
8  *          Laurent Aimar <fenrir@via.ecp.fr>
9  *          Gildas Bazin <gbazin@netcourrier.com>
10  *
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.
15  *
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.
20  *
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  *****************************************************************************/
25
26 /*****************************************************************************
27  * Preamble
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 */
33 #include "vlc_keys.h"
34
35 #include <cdio/cdio.h>
36 #include <cdio/logging.h>
37 #include <cdio/cd_types.h>
38
39 #include <stdio.h>
40
41 /* #ifdef variables below are defined via config.h via #include vlc above. */
42 #ifdef HAVE_STDLIB_H
43 #include <stdlib.h>
44 #endif
45
46 #ifdef HAVE_SYS_TYPES_H
47 #include <sys/types.h>
48 #endif
49
50 #ifdef HAVE_STRING_H
51 #include <string.h>
52 #endif
53
54 #ifdef HAVE_UNISTD_H
55 #   include <unistd.h>
56 #endif
57
58 /* FIXME: This variable is a hack. Would be nice to eliminate. */
59 access_t *p_cdda_input = NULL;
60
61 /*****************************************************************************
62  * Local prototypes
63  *****************************************************************************/
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,
67                              va_list args );
68
69 static int      CDDAInit( access_t *p_access, cdda_data_t *p_cdda ) ;
70
71
72 /****************************************************************************
73  * Private functions
74  ****************************************************************************/
75
76 /* process messages that originate from libcdio. */
77 static void
78 cdio_log_handler (cdio_log_level_t level, const char message[])
79 {
80   cdda_data_t *p_cdda = (cdda_data_t *)p_cdda_input->p_sys;
81
82   if( p_cdda == NULL )
83       return;
84
85   switch (level) {
86   case CDIO_LOG_DEBUG:
87   case CDIO_LOG_INFO:
88     if (p_cdda->i_debug & INPUT_DBG_CDIO)
89       msg_Dbg( p_cdda_input, message);
90     break;
91   case CDIO_LOG_WARN:
92     msg_Warn( p_cdda_input, message);
93     break;
94   case CDIO_LOG_ERROR:
95   case CDIO_LOG_ASSERT:
96     msg_Err( p_cdda_input, message);
97     break;
98   default:
99     msg_Warn( p_cdda_input, message,
100             "The above message had unknown cdio log level",
101             level);
102   }
103   return;
104 }
105
106
107 #ifdef HAVE_LIBCDDB
108 /*! This routine is called by libcddb routines on error.
109    Setup is done by init_input_plugin.
110 */
111 static void
112 cddb_log_handler (cddb_log_level_t level, const char message[])
113 {
114     cdda_data_t *p_cdda = (cdda_data_t *)p_cdda_input->p_sys;
115     switch (level)
116     {
117         case CDDB_LOG_DEBUG:
118         case CDDB_LOG_INFO:
119         if (!(p_cdda->i_debug & INPUT_DBG_CDDB)) return;
120
121         /* Fall through if to warn case */
122         default:
123             cdio_log_handler (level, message);
124     }
125 }
126 #endif /*HAVE_LIBCDDB*/
127
128
129 /*! This routine is when xine is not fully set up (before full initialization)
130    or is not around (before finalization).
131 */
132 static void
133 uninit_log_handler (cdio_log_level_t level, const char message[])
134 {
135     cdda_data_t *p_cdda = NULL;
136
137     if (p_cdda_input)
138         p_cdda = (cdda_data_t *)p_cdda_input->p_sys;
139
140      switch (level)
141      {
142         case CDIO_LOG_DEBUG:
143         case CDIO_LOG_INFO:
144         if (!p_cdda || !(p_cdda->i_debug & (INPUT_DBG_CDIO|INPUT_DBG_CDDB)))
145             return;
146
147         /* Fall through if to warn case */
148         case CDIO_LOG_WARN:
149             fprintf(stderr, "WARN: %s\n", message);
150             break;
151         case CDIO_LOG_ERROR:
152             fprintf(stderr, "ERROR: %s\n", message);
153             break;
154         case CDIO_LOG_ASSERT:
155             fprintf(stderr, "ASSERT ERROR: %s\n", message);
156             break;
157         default:
158             fprintf(stderr, "UNKNOWN ERROR: %s\n%s %d\n", message,
159                             "The above message had unknown cdio log level",
160                             level);
161     }
162
163     /* gl_default_cdio_log_handler (level, message); */
164 }
165
166 /*****************************************************************************
167  * CDDAReadBlocks: reads a group of blocks from the CD-DA and returns
168  * an allocated pointer to the data. NULL is returned if no data
169  * read. It is also possible if we haven't read a RIFF header in which
170  * case one that we creaded during Open/Initialization is returned.
171  *****************************************************************************/
172 static block_t * CDDAReadBlocks( access_t * p_access )
173 {
174     block_t     *p_block;
175     cdda_data_t *p_cdda   = (cdda_data_t *) p_access->p_sys;
176     int          i_blocks = p_cdda->i_blocks_per_read;
177
178     dbg_print((INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_LSN), "called %d",
179               p_cdda->i_lsn);
180
181     /* Check end of file */
182     if( p_access->info.b_eof ) return NULL;
183
184     if( !p_cdda->b_header )
185       {
186         /* Return only the dummy RIFF header we created in Open/Init */
187         p_block = block_New( p_access, sizeof( WAVEHEADER ) );
188         memcpy( p_block->p_buffer, &p_cdda->waveheader, sizeof(WAVEHEADER) );
189         p_cdda->b_header = VLC_TRUE;
190         return p_block;
191     }
192
193     /* Check end of track */
194     while( p_cdda->i_lsn >= p_cdda->lsn[p_cdda->i_track+1] )
195     {
196         if( p_cdda->i_track >= p_cdda->i_first_track + p_cdda->i_titles - 1 )
197         {
198             p_access->info.b_eof = VLC_TRUE;
199             return NULL;
200         }
201
202         p_access->info.i_update |= INPUT_UPDATE_TITLE | INPUT_UPDATE_SIZE;
203         p_access->info.i_title++;
204         p_access->info.i_size =
205                   p_cdda->p_title[p_access->info.i_title]->i_size;
206         p_access->info.i_pos = 0;
207         p_cdda->i_track++;
208     }
209
210     /* Possibly adjust i_blocks so we don't read past the end of a track. */
211     if( p_cdda->i_lsn + i_blocks >= p_cdda->lsn[p_cdda->i_track+1] )
212     {
213         i_blocks = p_cdda->lsn[p_cdda->i_track+1 ] - p_cdda->i_lsn;
214     }
215
216     /* Do the actual reading */
217     p_block = block_New( p_access, i_blocks * CDIO_CD_FRAMESIZE_RAW );
218     if( !p_block)
219     {
220       msg_Err( p_access, "Cannot get a new block of size: %i",
221                i_blocks * CDIO_CD_FRAMESIZE_RAW );
222       return NULL;
223     }
224
225     if( cdio_read_audio_sectors( p_cdda->p_cdio, p_block->p_buffer,
226                                  p_cdda->i_lsn, i_blocks) != 0 )
227     {
228         msg_Err( p_access, "could not read sector %lu",
229                  (long unsigned int) p_cdda->i_lsn );
230         block_Release( p_block );
231
232         /* If we had problems above, assume the problem is with
233            the first sector of the read and set to skip it.  In
234            the future libcdio may have cdparanoia support.
235         */
236         p_cdda->i_lsn++;
237         p_access->info.i_pos += CDIO_CD_FRAMESIZE_RAW;
238         return NULL;
239     }
240
241     p_cdda->i_lsn        += i_blocks;
242     p_access->info.i_pos += p_block->i_buffer;
243
244     return p_block;
245 }
246
247 /****************************************************************************
248  * CDDASeek - change position for subsequent reads. For example, this
249  * can happen if the user moves a position slider bar in a GUI.
250  ****************************************************************************/
251 static int CDDASeek( access_t * p_access, int64_t i_pos )
252 {
253     cdda_data_t *p_cdda = (cdda_data_t *) p_access->p_sys;
254
255     p_cdda->i_lsn = p_cdda->lsn[p_cdda->i_track]
256                   + (i_pos / CDIO_CD_FRAMESIZE_RAW);
257     p_access->info.i_pos = i_pos;
258
259     dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_SEEK),
260                "lsn %lu, offset: %lld",
261                (long unsigned int) p_cdda->i_lsn, i_pos );
262     return VLC_SUCCESS;
263 }
264
265 /****************************************************************************
266  * Public functions
267  ****************************************************************************/
268
269 /*****************************************************************************
270  * Open: open cdda device or image file and initialize structures
271  *       for subsequent operations.
272  *****************************************************************************/
273 int E_(CDDAOpen)( vlc_object_t *p_this )
274 {
275     access_t    *p_access = (access_t*)p_this;
276     char *      psz_source = NULL;
277     cdda_data_t *p_cdda    = NULL;
278     CdIo        *p_cdio;
279     track_t     i_track = 1;
280     vlc_bool_t  b_single_track = false;
281     int         i_rc = VLC_EGENERIC;
282
283     p_access->p_sys = NULL;
284
285     /* Set where to log errors messages from libcdio. */
286     p_cdda_input = p_access;
287
288     /* parse the options passed in command line : */
289
290     if( p_access->psz_path && *p_access->psz_path )
291     {
292         char *psz_parser = psz_source = strdup( p_access->psz_path );
293
294         while( *psz_parser && *psz_parser != '@' )
295         {
296             psz_parser++;
297         }
298
299         if( *psz_parser == '@' )
300         {
301             /* Found options */
302             *psz_parser = '\0';
303             ++psz_parser;
304
305             if ('T' == *psz_parser || 't' == *psz_parser )
306             ++psz_parser;
307
308             i_track = (int)strtol( psz_parser, NULL, 10 );
309             i_track = i_track ? i_track : 1;
310             b_single_track = true;
311         }
312     }
313
314     if (!psz_source || !*psz_source)
315     {
316         /* No device/track given. Continue only when this plugin was
317            selected */
318         if( !p_this->b_force ) return VLC_EGENERIC;
319
320         psz_source = var_CreateGetString( p_this, "cd-audio" );
321
322         if( !psz_source || !*psz_source )
323         {
324             /* Scan for a CD-ROM drive with a CD-DA in it. */
325             char **cd_drives =
326               cdio_get_devices_with_cap(NULL,  CDIO_FS_AUDIO, false);
327
328             if (NULL == cd_drives || NULL == cd_drives[0] )
329             {
330                 msg_Err( p_access,
331                      "libcdio couldn't find something with a CD-DA in it" );
332                 if (cd_drives) cdio_free_device_list(cd_drives);
333                 return VLC_EGENERIC;
334             }
335
336             psz_source = strdup(cd_drives[0]);
337             cdio_free_device_list(cd_drives);
338         }
339     }
340
341     cdio_log_set_handler ( cdio_log_handler );
342
343     /* Open CDDA */
344     if( !(p_cdio = cdio_open( psz_source, DRIVER_UNKNOWN )) )
345     {
346         msg_Warn( p_access, "could not open %s", psz_source );
347         goto error2;
348     }
349
350     p_cdda = malloc( sizeof(cdda_data_t) );
351     if( p_cdda == NULL )
352     {
353         msg_Err( p_access, "out of memory" );
354         free( psz_source );
355         return VLC_ENOMEM;
356     }
357     memset( p_cdda, 0, sizeof(cdda_data_t) );
358
359 #ifdef HAVE_LIBCDDB
360     cddb_log_set_handler ( cddb_log_handler );
361     p_cdda->cddb.disc = NULL;
362     p_cdda->b_cddb_enabled =
363       config_GetInt( p_access, MODULE_STRING "-cddb-enabled" );
364 #endif
365
366     p_cdda->b_cdtext_enabled =
367       config_GetInt( p_access, MODULE_STRING "-cdtext-enabled" );
368
369     p_cdda->b_cdtext_prefer =
370       config_GetInt( p_access, MODULE_STRING "-cdtext-prefer" );
371
372     p_cdda->b_header = VLC_FALSE;
373     p_cdda->p_cdio   = p_cdio;
374     p_cdda->i_titles = 0;
375     p_cdda->i_track  = i_track;
376     p_cdda->i_debug  = config_GetInt(p_this, MODULE_STRING "-debug");
377     p_cdda->i_blocks_per_read
378                      = config_GetInt(p_this, MODULE_STRING "-blocks-per-read");
379
380     p_cdda->p_input  = vlc_object_find( p_access, VLC_OBJECT_INPUT,
381                                         FIND_PARENT );
382
383     if (0 == p_cdda->i_blocks_per_read)
384         p_cdda->i_blocks_per_read = DEFAULT_BLOCKS_PER_READ;
385
386     if ( p_cdda->i_blocks_per_read < MIN_BLOCKS_PER_READ
387          || p_cdda->i_blocks_per_read > MAX_BLOCKS_PER_READ )
388     {
389         msg_Warn( p_cdda_input,
390                 "Number of blocks (%d) has to be between %d and %d. "
391                 "Using %d.",
392                 p_cdda->i_blocks_per_read,
393                 MIN_BLOCKS_PER_READ, MAX_BLOCKS_PER_READ,
394                 DEFAULT_BLOCKS_PER_READ );
395         p_cdda->i_blocks_per_read = DEFAULT_BLOCKS_PER_READ;
396     }
397
398     dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "%s", psz_source );
399
400     /* Set up p_access */
401     p_access->pf_read    = NULL;
402     p_access->pf_block   = CDDAReadBlocks;
403     p_access->pf_control = CDDAControl;
404     p_access->pf_seek    = CDDASeek;
405
406     p_access->info.i_size      = 0;
407
408     p_access->info.i_update    = 0;
409     p_access->info.b_eof       = VLC_FALSE;
410     p_access->info.i_title     = 0;
411     p_access->info.i_seekpoint = 0;
412
413     p_access->p_sys     = (access_sys_t *) p_cdda;
414
415     /* We read the Table Of Content information */
416     i_rc = CDDAInit( p_access, p_cdda );
417     if ( VLC_SUCCESS != i_rc ) goto error;
418
419     CDDAFixupPlaylist( p_access, p_cdda, psz_source, b_single_track );
420
421     /* Build a WAV header to put in front of the output data.
422        This gets sent back in the Block (read) routine.
423      */
424     memset( &p_cdda->waveheader, 0, sizeof(WAVEHEADER) );
425     SetWLE( &p_cdda->waveheader.Format, 1 ); /*WAVE_FORMAT_PCM*/
426     SetWLE( &p_cdda->waveheader.BitsPerSample, 16);
427     p_cdda->waveheader.MainChunkID = VLC_FOURCC('R', 'I', 'F', 'F');
428     p_cdda->waveheader.Length = 0;                     /* we just don't know */
429     p_cdda->waveheader.ChunkTypeID = VLC_FOURCC('W', 'A', 'V', 'E');
430     p_cdda->waveheader.SubChunkID  = VLC_FOURCC('f', 'm', 't', ' ');
431     SetDWLE( &p_cdda->waveheader.SubChunkLength, 16);
432     SetWLE( &p_cdda->waveheader.Modus, 2);
433     SetDWLE( &p_cdda->waveheader.SampleFreq, CDDA_FREQUENCY_SAMPLE);
434     SetWLE( &p_cdda->waveheader.BytesPerSample,
435             2 /*Modus*/ * 16 /*BitsPerSample*/ / 8 );
436     SetDWLE( &p_cdda->waveheader.BytesPerSec,
437              2*16/8 /*BytesPerSample*/ * CDDA_FREQUENCY_SAMPLE );
438     p_cdda->waveheader.DataChunkID = VLC_FOURCC('d', 'a', 't', 'a');
439     p_cdda->waveheader.DataLength  = 0;    /* we just don't know */
440
441     /* PTS delay */
442     var_Create( p_access, MODULE_STRING "-caching",
443                 VLC_VAR_INTEGER|VLC_VAR_DOINHERIT );
444     vlc_object_release( p_cdda->p_input );
445     return VLC_SUCCESS;
446
447  error:
448     cdio_destroy( p_cdda->p_cdio );
449     free( p_cdda );
450  error2:
451     free( psz_source );
452     if( p_cdda && p_cdda->p_input )
453     {
454         vlc_object_release( p_cdda->p_input );
455     }
456     return i_rc;
457
458 }
459
460 /*****************************************************************************
461  * CDDAClose: closes cdda and frees any resources associded with it.
462  *****************************************************************************/
463 void E_(CDDAClose)( vlc_object_t *p_this )
464 {
465     access_t    *p_access = (access_t *) p_this;
466     cdda_data_t *p_cdda   = (cdda_data_t *) p_access->p_sys;
467     track_t      i;
468
469     dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT), "" );
470
471     /* Remove playlist titles */
472     for( i = 0; i < p_cdda->i_titles; i++ )
473     {
474         vlc_input_title_Delete( p_cdda->p_title[i] );
475     }
476
477     cdio_destroy( p_cdda->p_cdio );
478
479     cdio_log_set_handler (uninit_log_handler);
480
481 #ifdef HAVE_LIBCDDB
482     cddb_log_set_handler (uninit_log_handler);
483     if (p_cdda->b_cddb_enabled)
484       cddb_disc_destroy(p_cdda->cddb.disc);
485 #endif
486
487     if (p_cdda->psz_mcn) free( p_cdda->psz_mcn );
488     free( p_cdda );
489     p_cdda_input = NULL;
490 }
491
492 /*****************************************************************************
493  * Control: The front-end or vlc engine calls here to ether get
494  * information such as meta information or plugin capabilities or to
495  * issue miscellaneous "set" requests.
496  *****************************************************************************/
497 static int CDDAControl( access_t *p_access, int i_query, va_list args )
498 {
499     cdda_data_t  *p_cdda = (cdda_data_t *) p_access->p_sys;
500     int          *pi_int;
501     int i;
502
503     dbg_print( (INPUT_DBG_CALL|INPUT_DBG_EXT|INPUT_DBG_EVENT),
504                "query %d", i_query );
505
506     switch( i_query )
507     {
508         /* Pass back a copy of meta information that was gathered when we
509            during the Open/Initialize call.
510          */
511         case ACCESS_GET_META:
512         {
513             vlc_meta_t **pp_meta = (vlc_meta_t**)va_arg( args, vlc_meta_t** );
514             if ( p_cdda->p_meta )
515             {
516                 *pp_meta = vlc_meta_Duplicate( p_cdda->p_meta );
517                 dbg_print( INPUT_DBG_META, "%s", "Meta copied" );
518             }
519             else
520                 msg_Warn( p_access, "tried to copy NULL meta info" );
521
522             return VLC_SUCCESS;
523         }
524
525         case ACCESS_CAN_SEEK:
526         case ACCESS_CAN_FASTSEEK:
527         case ACCESS_CAN_PAUSE:
528         case ACCESS_CAN_CONTROL_PACE:
529         {
530             vlc_bool_t *pb_bool = (vlc_bool_t*)va_arg( args, vlc_bool_t* );
531             *pb_bool = VLC_TRUE;
532             return VLC_SUCCESS;;
533         }
534
535         /* */
536         case ACCESS_GET_MTU:
537         {
538             pi_int = (int*)va_arg( args, int * );
539             *pi_int = p_cdda-> i_blocks_per_read * CDIO_CD_FRAMESIZE_RAW;
540             break;
541         }
542
543         case ACCESS_GET_PTS_DELAY:
544         {
545             int64_t *pi_64 = (int64_t*)va_arg( args, int64_t * );
546             *pi_64 = var_GetInteger( p_access, MODULE_STRING "-caching" )
547               * MILLISECONDS_PER_SEC;
548             break;
549         }
550
551         /* */
552         case ACCESS_SET_PAUSE_STATE:
553             break;
554
555         case ACCESS_GET_TITLE_INFO:
556         {
557             input_title_t ***ppp_title;
558             ppp_title = (input_title_t***)va_arg( args, input_title_t*** );
559             pi_int    = (int*)va_arg( args, int* );
560             *((int*)va_arg( args, int* )) = 1; /* Title offset */
561
562             /* Duplicate title info */
563             dbg_print ( INPUT_DBG_EVENT,
564                         "GET TITLE: i_tracks %d, i_titles %d",
565                         p_cdda->i_tracks, p_cdda->i_titles );
566             if( p_cdda->i_titles == 0 )
567             {
568                 *pi_int = 0; ppp_title = NULL;
569                 return VLC_SUCCESS;
570             }
571             *pi_int = p_cdda->i_titles;
572             *ppp_title = malloc(sizeof( input_title_t **) * p_cdda->i_titles );
573
574             if (!*ppp_title) return VLC_ENOMEM;
575
576             for( i = 0; i < p_cdda->i_titles; i++ )
577             {
578                 if ( p_cdda->p_title[i] )
579                    (*ppp_title)[i] =
580                           vlc_input_title_Duplicate( p_cdda->p_title[i] );
581             }
582             break;
583         }
584
585         case ACCESS_SET_TITLE:
586         {
587             i = (int)va_arg( args, int );
588             if( i != p_access->info.i_title )
589             {
590                 /* Update info */
591                 p_access->info.i_update |=
592                     INPUT_UPDATE_TITLE|INPUT_UPDATE_SIZE;
593                 p_access->info.i_title = i;
594                 p_access->info.i_size = p_cdda->p_title[i]->i_size;
595                 p_access->info.i_pos = 0;
596
597                 /* Next sector to read */
598                 p_cdda->i_lsn = p_cdda->lsn[p_cdda->i_first_track+i];
599             }
600             break;
601         }
602
603         case ACCESS_SET_SEEKPOINT:
604         case ACCESS_SET_PRIVATE_ID_STATE:
605             return VLC_EGENERIC;
606
607         default:
608             msg_Warn( p_access, "unimplemented query in control" );
609             return VLC_EGENERIC;
610
611     }
612     return VLC_SUCCESS;
613 }
614
615 /*****************************************************************************
616   CDDAInit:
617
618  Initialize information pertaining to the CD: the number of tracks,
619  first track number, LSNs for each track and the leadout. The leadout
620  information is stored after the last track. The LSN array is
621  0-origin, same as p_access->info.  Add first_track to get what track
622  number this is on the CD. Note: libcdio uses the real track number.
623
624  On input we assume p_cdda->p_cdio and p_cdda->i_track have been set.
625
626  We return the VLC-type status, e.g. VLC_SUCCESS, VLC_ENOMEM, etc.
627  *****************************************************************************/
628 static int CDDAInit( access_t *p_access, cdda_data_t *p_cdda )
629 {
630     track_t i;
631     discmode_t  discmode = CDIO_DISC_MODE_NO_INFO;
632
633     p_cdda->i_tracks       = cdio_get_num_tracks(p_cdda->p_cdio);
634     p_cdda->i_first_track  = cdio_get_first_track_num(p_cdda->p_cdio);
635
636     discmode = cdio_get_discmode(p_cdda->p_cdio);
637     switch(discmode) {
638     case CDIO_DISC_MODE_CD_DA:
639     case CDIO_DISC_MODE_CD_MIXED:
640         /* These are possible for CD-DA */
641         break;
642     default:
643         /* These are not possible for CD-DA */
644         msg_Err( p_access,
645                "Disc seems not to be CD-DA. libcdio reports it is %s",
646                discmode2str[discmode]
647                );
648         return VLC_EGENERIC;
649     }
650
651     /* Fill the lsn array with the track/sector matches.
652        Note cdio_get_track_lsn when given num_tracks + 1 will return
653        the leadout LSN.
654      */
655     for( i = 0 ; i <= p_cdda->i_tracks ; i++ )
656     {
657         track_t i_track = p_cdda->i_first_track + i;
658         (p_cdda->lsn)[ i_track ] = cdio_get_track_lsn(p_cdda->p_cdio, i_track);
659     }
660
661     /* Set reading start LSN. */
662     p_cdda->i_lsn = p_cdda->lsn[p_cdda->i_track];
663
664     return VLC_SUCCESS;
665 }