]> git.sesse.net Git - vlc/blob - modules/demux/mpeg/audio.c
* ALL: changed the prototype of input_AddES() to include enough information so we...
[vlc] / modules / demux / mpeg / audio.c
1 /*****************************************************************************
2  * audio.c : mpeg audio Stream input module for vlc
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: audio.c,v 1.18 2003/05/05 22:23:36 gbazin Exp $
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <string.h>
29
30 #include <vlc/vlc.h>
31 #include <vlc/input.h>
32
33 #include <sys/types.h>
34
35 /*****************************************************************************
36  * Local prototypes
37  *****************************************************************************/
38 static int  Activate ( vlc_object_t * );
39 static int  Demux ( input_thread_t * );
40
41 /* TODO: support MPEG-2.5, not difficult, but I need somes samples... */
42
43 /*****************************************************************************
44  * Module descriptor
45  *****************************************************************************/
46 vlc_module_begin();
47     set_description( _("MPEG I/II audio stream demuxer" ) );
48     set_capability( "demux", 50 );
49     set_callbacks( Activate, NULL );
50     add_shortcut( "mpegaudio" );
51     add_shortcut( "mp3" );
52 vlc_module_end();
53
54 /*****************************************************************************
55  * Definitions of structures  and functions used by this plugins
56  *****************************************************************************/
57
58 /* XXX set this to 0 to avoid problem with PS XXX */
59 /* but with some file or web radio will failed to detect */
60 /* it's you to choose */
61 #define MPEGAUDIO_MAXTESTPOS    0
62
63 typedef struct mpeg_header_s
64 {
65     uint32_t i_header;
66     int i_version;
67     int i_layer;
68     int i_crc;
69     int i_bitrate;
70     int i_samplerate;
71     int i_padding;
72     int i_extension;
73     int i_mode;
74     int i_modeext;
75     int i_copyright;
76     int i_original;
77     int i_emphasis;
78
79 } mpeg_header_t;
80
81 /* Xing Header if present */
82 #define FRAMES_FLAG     0x0001  /* these flags is for i_flags */
83 #define BYTES_FLAG      0x0002  /* because all is optionnal */
84 #define TOC_FLAG        0x0004
85 #define VBR_SCALE_FLAG  0x0008
86 typedef struct xing_header_s
87 {
88     int     i_flags;      /* from Xing header data */
89     int     i_frames;     /* total bit stream frames from Xing header data */
90     int     i_bytes;      /* total bit stream bytes from Xing header data */
91     int     i_vbr_scale;  /* encoded vbr scale from Xing header data */
92     uint8_t i_toc[100];   /* for seek */
93     int     i_avgbitrate; /* calculated, XXX: bits/sec not Kb */
94 } xing_header_t;
95
96 struct demux_sys_t
97 {
98     mtime_t i_pts;
99
100     es_descriptor_t *p_es;
101     mpeg_header_t   mpeg;
102     xing_header_t   xingheader;
103
104     /* extracted information */
105     int i_samplerate;
106     int i_samplelength;
107     int i_framelength;
108 };
109
110
111 static int mpegaudio_bitrate[2][3][16] =
112 {
113   {
114     /* v1 l1 */
115     { 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448, 0},
116     /* v1 l2 */
117     { 0, 32, 48, 56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, 384, 0},
118     /* v1 l3 */
119     { 0, 32, 40, 48,  56,  64,  80,  96, 112, 128, 160, 192, 224, 256, 320, 0}
120   },
121
122   {
123      /* v2 l1 */
124     { 0, 32, 48, 56,  64,  80,  96, 112, 128, 144, 160, 176, 192, 224, 256, 0},
125     /* v2 l2 */
126     { 0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160, 0},
127     /* v2 l3 */
128     { 0,  8, 16, 24,  32,  40,  48,  56,  64,  80,  96, 112, 128, 144, 160, 0}
129   }
130
131 };
132
133 static int mpegaudio_samplerate[2][4] = /* version 1 then 2 */
134 {
135     { 44100, 48000, 32000, 0 },
136     { 22050, 24000, 16000, 0 }
137 };
138
139 static char* mpegaudio_mode[4] =
140 {
141     "stereo", "joint stereo", "dual channel", "mono"
142 };
143
144 static inline uint32_t GetDWBE( uint8_t *p_buff )
145 {
146     return( ( p_buff[0] << 24 )|( p_buff[1] << 16 )|
147             ( p_buff[2] <<  8 )|( p_buff[3] ) );
148 }
149
150 /*****************************************************************************
151  * Function to manipulate stream easily
152  *****************************************************************************
153  *
154  * SkipBytes : skip bytes, not yet optimised, read bytes to be skipped :P
155  *
156  * ReadPes : read data and make a PES
157  *
158  *****************************************************************************/
159 static int SkipBytes( input_thread_t *p_input, int i_size )
160 {
161     data_packet_t *p_data;
162     int i_read;
163
164     while( i_size > 0 )
165     {
166         i_read = input_SplitBuffer(p_input, &p_data, __MIN( i_size, 1024 ) );
167         if( i_read <= 0 )
168         {
169             return( 0 );
170         }
171         input_DeletePacket( p_input->p_method_data, p_data );
172         i_size -= i_read;
173     }
174     return( 1 );
175 }
176
177 static int ReadPES( input_thread_t *p_input,
178                     pes_packet_t **pp_pes,
179                     int i_size )
180 {
181     pes_packet_t *p_pes;
182
183     *pp_pes = NULL;
184
185     if( !(p_pes = input_NewPES( p_input->p_method_data )) )
186     {
187         msg_Err( p_input, "cannot allocate new PES" );
188         return( 0 );
189     }
190
191     while( i_size > 0 )
192     {
193         data_packet_t   *p_data;
194         int i_read;
195
196         if( (i_read = input_SplitBuffer( p_input,
197                                          &p_data,
198                                          __MIN( i_size, 1024 ) ) ) <= 0 )
199         {
200             input_DeletePES( p_input->p_method_data, p_pes );
201             return( 0 );
202         }
203         if( !p_pes->p_first )
204         {
205             p_pes->p_first = p_data;
206             p_pes->i_nb_data = 1;
207             p_pes->i_pes_size = i_read;
208         }
209         else
210         {
211             p_pes->p_last->p_next  = p_data;
212             p_pes->i_nb_data++;
213             p_pes->i_pes_size += i_read;
214         }
215         p_pes->p_last  = p_data;
216         i_size -= i_read;
217     }
218     *pp_pes = p_pes;
219     return( 1 );
220 }
221
222 /*****************************************************************************
223  * CheckHeader : Test the validity of the header
224  *****************************************************************************/
225 static int CheckHeader( uint32_t i_header )
226 {
227     if( ((( i_header >> 20 )&0x0FFF) != 0x0FFF )  /* header sync */
228         || (((i_header >> 17)&0x03) == 0 )  /* valid layer ?*/
229         || (((i_header >> 12)&0x0F) == 0x0F )
230         || (((i_header >> 12)&0x0F) == 0x00 ) /* valid bitrate ? */
231         || (((i_header >> 10) & 0x03) == 0x03 ) /* valide sampling freq ? */
232         || ((i_header & 0x03) == 0x02 )) /* valid emphasis ? */
233     {
234         return( 0 ); /*invalid */
235     }
236     return( 1 ); /* valid */
237 }
238
239 /*****************************************************************************
240  * DecodedFrameSize : give the length of the decoded pcm data
241  *****************************************************************************/
242 static int DecodedFrameSize( mpeg_header_t *p_mpeg )
243 {
244     switch( p_mpeg->i_layer )
245     {
246         case( 0 ): /* layer 1 */
247             return( 384);
248         case( 1 ): /* layer 2 */
249             return( 1152 );
250         case( 2 ): /* layer 3 */
251             return( !p_mpeg->i_version ? 1152 : 576 );
252             /* XXX: perhaps we have to /2 for all layer but i'm not sure */
253     }
254     return( 0 );
255 }
256
257 /****************************************************************************
258  * GetHeader : find an mpeg header and load it
259  ****************************************************************************/
260 static int GetHeader( input_thread_t  *p_input,
261                       mpeg_header_t   *p_mpeg,
262                       int             i_max_pos,
263                       int             *pi_skip )
264 {
265     uint32_t i_header;
266     uint8_t  *p_peek;
267     int i_size;
268
269     *pi_skip = 0;
270     i_size = input_Peek( p_input, &p_peek, i_max_pos + 4 );
271
272     for( ; ; )
273     {
274         if( i_size < 4 )
275         {
276             return( 0 );
277         }
278         if( !CheckHeader( GetDWBE( p_peek ) ) )
279         {
280             p_peek++;
281             i_size--;
282             *pi_skip += 1;
283             continue;
284         }
285         /* we found an header, load it */
286         break;
287     }
288     i_header = GetDWBE( p_peek );
289     p_mpeg->i_header = i_header;
290     p_mpeg->i_version =  1 - ( ( i_header >> 19 ) & 0x01 );
291     p_mpeg->i_layer =  3 - ( ( i_header >> 17 ) & 0x03 );
292     p_mpeg->i_crc = 1 - (( i_header >> 16 ) & 0x01);
293     p_mpeg->i_bitrate =
294         mpegaudio_bitrate[p_mpeg->i_version][p_mpeg->i_layer][(i_header>>12)&0x0F];
295     p_mpeg->i_samplerate = mpegaudio_samplerate[p_mpeg->i_version][(i_header>>10)&0x03];
296     p_mpeg->i_padding = (( i_header >> 9 ) & 0x01);
297     p_mpeg->i_extension = ( i_header >> 7 ) & 0x01;
298     p_mpeg->i_mode = ( i_header >> 6 ) & 0x03;
299     p_mpeg->i_modeext = ( i_header >> 4 ) & 0x03;
300     p_mpeg->i_copyright = ( i_header >> 3 ) & 0x01;
301     p_mpeg->i_original = ( i_header >> 2 ) & 0x01;
302     p_mpeg->i_emphasis = ( i_header ) & 0x03;
303
304     return( 1 );
305 }
306
307 /*****************************************************************************
308  * ExtractXingHeader : extract a Xing header if exist
309  *****************************************************************************
310  * It also calcul avgbitrate, using Xing header if present or assume that
311  * the bitrate of the first frame is the same for the all file
312  *****************************************************************************/
313 static void ExtractXingHeader( input_thread_t *p_input,
314                                xing_header_t *p_xh )
315 {
316     int i_skip;
317     int i_size;
318     uint8_t  *p_peek;
319     mpeg_header_t mpeg;
320
321     p_xh->i_flags = 0;  /* nothing present */
322     if( !( GetHeader( p_input,
323                       &mpeg,
324                       8192,
325                       &i_skip ) ) )
326     {
327         msg_Err( p_input, "ExtractXingHeader failed, shouldn't ..." );
328         return;
329     }
330
331     p_xh->i_avgbitrate = mpeg.i_bitrate * 1000; /* default */
332
333     /* 1024 is enougth */
334     if( ( i_size = input_Peek( p_input, &p_peek, 1024 + i_skip ) ) < 8 )
335     {
336         return;
337     }
338     p_peek += i_skip;
339     i_size -= i_skip;
340
341     /* calculate pos of xing header */
342     if( !mpeg.i_version )
343     {
344         p_peek += mpeg.i_mode != 3 ? 36 : 21;
345         i_size -= mpeg.i_mode != 3 ? 36 : 21;
346     }
347     else
348     {
349         p_peek += mpeg.i_mode != 3 ? 21 : 13;
350         i_size -= mpeg.i_mode != 3 ? 21 : 13;
351     }
352     if( i_size < 8 )
353     {
354         return;
355     }
356     if( ( p_peek[0] != 'X' )||( p_peek[1] != 'i' )||
357         ( p_peek[2] != 'n' )||( p_peek[3] != 'g' ) )
358     {
359         return;
360     }
361     else
362     {
363         msg_Dbg( p_input, "Xing header is present" );
364         p_peek += 4;
365         i_size -= 4;
366     }
367     if( i_size < 4 )
368     {
369         return;
370     }
371     else
372     {
373         p_xh->i_flags = GetDWBE( p_peek );
374         p_peek += 4;
375         i_size -= 4;
376     }
377
378     if( ( p_xh->i_flags&FRAMES_FLAG )&&( i_size >= 4 ) )
379     {
380         p_xh->i_frames = GetDWBE( p_peek );
381         if( p_xh->i_frames == 0 ) p_xh->i_flags &= ~FRAMES_FLAG;
382         p_peek += 4;
383         i_size -= 4;
384     }
385     if( ( p_xh->i_flags&BYTES_FLAG ) &&( i_size >= 4 ) )
386
387     {
388         p_xh->i_bytes = GetDWBE( p_peek );
389         if( p_xh->i_bytes == 0 ) p_xh->i_flags &= ~BYTES_FLAG;
390         p_peek += 4;
391         i_size -= 4;
392     }
393     if( ( p_xh->i_flags&TOC_FLAG ) &&( i_size >= 100 ) )
394
395     {
396         memcpy( p_xh->i_toc, p_peek, 100 );
397         p_peek += 100;
398         i_size -= 100;
399     }
400     if( ( p_xh->i_flags&VBR_SCALE_FLAG ) &&( i_size >= 4 ) )
401
402     {
403         p_xh->i_vbr_scale = GetDWBE( p_peek );
404         p_peek += 4;
405         i_size -= 4;
406     }
407
408     if( ( p_xh->i_flags&FRAMES_FLAG )&&( p_xh->i_flags&BYTES_FLAG ) )
409     {
410         p_xh->i_avgbitrate =
411               ( (uint64_t)p_xh->i_bytes *
412                 (uint64_t)8 *
413                 (uint64_t)mpeg.i_samplerate) /
414                ((uint64_t)p_xh->i_frames * (uint64_t)DecodedFrameSize( &mpeg ) );
415     }
416 }
417
418 /****************************************************************************
419  * ExtractConfiguration : extract usefull informations from mpeg_header_t
420  ****************************************************************************/
421 static void ExtractConfiguration( demux_sys_t *p_demux )
422 {
423     p_demux->i_samplerate   = p_demux->mpeg.i_samplerate;
424
425     p_demux->i_samplelength = DecodedFrameSize( &p_demux->mpeg );
426
427     /* XXX if crc do i need to add 2 bytes or not? */
428     switch( p_demux->mpeg.i_layer )
429     {
430         case( 0 ):
431             p_demux->i_framelength =
432                 ( ( 12000 * p_demux->mpeg.i_bitrate ) /
433                        p_demux->mpeg.i_samplerate + p_demux->mpeg.i_padding ) * 4;
434             break;
435         case( 1 ):
436             p_demux->i_framelength =
437                   ( 144000 * p_demux->mpeg.i_bitrate ) /
438                        p_demux->mpeg.i_samplerate + p_demux->mpeg.i_padding;
439             break;
440         case( 2 ):
441             p_demux->i_framelength =
442                   (p_demux->mpeg.i_version ? 72000 : 144000) *
443                   p_demux->mpeg.i_bitrate /
444                        p_demux->mpeg.i_samplerate + p_demux->mpeg.i_padding;
445             break;
446
447     }
448 }
449
450 /****************************************************************************
451  * CheckPS : check if this stream could be some ps,
452  *           yes it's ugly ...  but another idea ?
453  *
454  ****************************************************************************/
455 static int CheckPS( input_thread_t *p_input )
456 {
457     uint8_t  *p_peek;
458     int i_startcode = 0;
459     int i_size = input_Peek( p_input, &p_peek, 8196 );
460
461     while( i_size > 4 )
462     {
463         if( ( p_peek[0] == 0 ) && ( p_peek[1] == 0 ) &&
464             ( p_peek[2] == 1 ) && ( p_peek[3] >= 0xb9 ) &&
465             ++i_startcode >= 3 )
466         {
467             return 1;
468         }
469         p_peek++;
470         i_size--;
471     }
472
473     return 0;
474 }
475
476 /*****************************************************************************
477  * Activate: initializes MPEGaudio structures
478  *****************************************************************************/
479 static int Activate( vlc_object_t * p_this )
480 {
481     input_thread_t * p_input = (input_thread_t *)p_this;
482     demux_sys_t * p_demux;
483     input_info_category_t * p_category;
484     module_t * p_id3;
485
486     int i_found;
487     int b_forced;
488     int i_skip;
489
490     int i_max_pos;
491
492     /* Set the demux function */
493     p_input->pf_demux = Demux;
494
495     /* Initialize access plug-in structures. */
496     if( p_input->i_mtu == 0 )
497     {
498         /* Improve speed. */
499         p_input->i_bufsize = INPUT_DEFAULT_BUFSIZE;
500     }
501
502     b_forced = VLC_FALSE;
503     i_max_pos = MPEGAUDIO_MAXTESTPOS;
504
505     if( ( *p_input->psz_demux )
506         &&( ( !strncmp( p_input->psz_demux, "mpegaudio", 10 ) )||
507             ( !strncmp( p_input->psz_demux, "mp3", 3 ) ) ) )
508     {
509         b_forced = VLC_TRUE;
510         i_max_pos = 4000;
511     }
512     else if( p_input->psz_name )
513     {
514         char *name = p_input->psz_name;
515         int  i_len = strlen( name );
516
517         if( i_len > 4 && !strcasecmp( &name[i_len - 4], ".mp3" ) )
518         {
519             i_max_pos = 2000;
520         }
521     }
522
523     p_id3 = module_Need( p_input, "id3", NULL );
524     if ( p_id3 ) {
525         module_Unneed( p_input, p_id3 );
526     }
527
528     /* create p_demux and init it */
529     if( !( p_demux = p_input->p_demux_data = malloc( sizeof(demux_sys_t) ) ) )
530     {
531         msg_Err( p_input, "out of memory" );
532         return( -1 );
533     }
534     memset( p_demux, 0, sizeof(demux_sys_t) );
535
536     /* check if it could be a ps stream */
537     if( !b_forced && CheckPS(  p_input ))
538     {
539         free( p_input->p_demux_data );
540         return( -1 );
541     }
542
543
544     /* must be sure that is mpeg audio stream unless forced */
545     if( !( i_found = GetHeader( p_input,
546                                 &p_demux->mpeg,
547                                 i_max_pos,
548                                 &i_skip ) ) )
549     {
550         if( b_forced )
551         {
552             msg_Warn( p_input,
553                       "this does not look like an MPEG audio stream, "
554                       "but continuing anyway" );
555         }
556         else
557         {
558             msg_Warn( p_input, "MPEGAudio module discarded (no frame found)" );
559             free( p_input->p_demux_data );
560             return( -1 );
561         }
562     }
563     else
564     {
565         ExtractConfiguration( p_demux );
566     }
567
568
569     vlc_mutex_lock( &p_input->stream.stream_lock );
570     if( input_InitStream( p_input, 0 ) == -1)
571     {
572         msg_Err( p_input, "cannot init stream" );
573         free( p_input->p_demux_data );
574         return( -1 );
575     }
576     if( input_AddProgram( p_input, 0, 0) == NULL )
577     {
578         msg_Err( p_input, "cannot add program" );
579         free( p_input->p_demux_data );
580         return( -1 );
581     }
582     p_input->stream.pp_programs[0]->b_is_ok = 0;
583     p_input->stream.p_selected_program = p_input->stream.pp_programs[0];
584
585     /* create our ES */
586     p_demux->p_es = input_AddES( p_input, p_input->stream.p_selected_program,
587                                  1 /* id */, AUDIO_ES, NULL, 0 );
588     if( !p_demux->p_es )
589     {
590         vlc_mutex_unlock( &p_input->stream.stream_lock );
591         msg_Err( p_input, "out of memory" );
592         free( p_input->p_demux_data );
593         return( -1 );
594     }
595     p_demux->p_es->i_stream_id = 1;
596     p_demux->p_es->i_fourcc = VLC_FOURCC('m','p','g','a');
597
598     input_SelectES( p_input, p_demux->p_es );
599
600     p_input->stream.p_selected_program->b_is_ok = 1;
601     vlc_mutex_unlock( &p_input->stream.stream_lock );
602
603
604     if( i_found )
605     {
606         /* parse Xing Header if present */
607         ExtractXingHeader( p_input, &p_demux->xingheader );
608
609         vlc_mutex_lock( &p_input->stream.stream_lock );
610         p_input->stream.i_mux_rate = p_demux->xingheader.i_avgbitrate / 50 / 8;
611         vlc_mutex_unlock( &p_input->stream.stream_lock );
612
613
614         /* all is ok :)) */
615         msg_Dbg( p_input, "audio MPEG-%d layer %d %s %dHz %dKb/s %s",
616                 p_demux->mpeg.i_version + 1,
617                 p_demux->mpeg.i_layer + 1,
618                 mpegaudio_mode[p_demux->mpeg.i_mode],
619                 p_demux->mpeg.i_samplerate,
620                 p_demux->xingheader.i_avgbitrate / 1000,
621                 p_demux->xingheader.i_flags ?
622                         "VBR (Xing)" : ""
623                     );
624
625         vlc_mutex_lock( &p_input->stream.stream_lock );
626         p_category = input_InfoCategory( p_input, _("mpeg") );
627         input_AddInfo( p_category, _("Input Type"), "Audio MPEG-%d",
628                        p_demux->mpeg.i_version +1 );
629         input_AddInfo( p_category, _("Layer"), "%d", p_demux->mpeg.i_layer + 1 );
630         input_AddInfo( p_category, _("Mode"),
631                        mpegaudio_mode[p_demux->mpeg.i_mode] );
632         input_AddInfo( p_category, _("Sample Rate"), "%dHz",
633                        p_demux->mpeg.i_samplerate );
634         input_AddInfo( p_category, _("Average Bitrate"), "%dKb/s",
635                        p_demux->xingheader.i_avgbitrate / 1000 );
636         vlc_mutex_unlock( &p_input->stream.stream_lock );
637     }
638     else
639     {
640         msg_Dbg( p_input,
641                  "assuming audio MPEG, but not frame header yet found" );
642         vlc_mutex_lock( &p_input->stream.stream_lock );
643         p_category = input_InfoCategory( p_input, _("mpeg") );
644         input_AddInfo( p_category, _("Input Type"), "Audio MPEG-?" );
645         vlc_mutex_unlock( &p_input->stream.stream_lock );
646
647     }
648
649     return( 0 );
650 }
651
652 /*****************************************************************************
653  * Demux: reads and demuxes data packets
654  *****************************************************************************
655  * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
656  *****************************************************************************/
657 static int Demux( input_thread_t * p_input )
658 {
659     demux_sys_t  *p_demux = p_input->p_demux_data;
660     pes_packet_t *p_pes;
661     int          i_skip;
662
663     if( !GetHeader( p_input,
664                     &p_demux->mpeg,
665                     8192,
666                     &i_skip ) )
667     {
668         if( i_skip > 0)
669         {
670             msg_Dbg( p_input,
671                      "skipping %d bytes (garbage ?)",
672                      i_skip );
673             SkipBytes( p_input, i_skip );
674             return( 1 );
675         }
676         else
677         {
678             msg_Dbg( p_input,
679                      "cannot find next frame (EOF ?)" );
680             return( 0 );
681         }
682     }
683
684     ExtractConfiguration( p_demux );
685
686     input_ClockManageRef( p_input,
687                           p_input->stream.p_selected_program,
688                           p_demux->i_pts );
689
690     /*
691      * For layer 1 and 2 i_skip is garbage but for layer 3 it is not.
692      * Since mad accept without to much trouble garbage I don't skip
693      * it ( in case I misdetect garbage ... )
694      *
695      */
696     if( !ReadPES( p_input, &p_pes, p_demux->i_framelength + i_skip) )
697     {
698         msg_Warn( p_input,
699                 "cannot read data" );
700         return( -1 );
701     }
702
703     p_pes->i_rate = p_input->stream.control.i_rate;
704     p_pes->i_dts =
705         p_pes->i_pts = input_ClockGetTS( p_input,
706                                          p_input->stream.p_selected_program,
707                                          p_demux->i_pts );
708
709     if( !p_demux->p_es->p_decoder_fifo )
710     {
711         msg_Err( p_input, "no audio decoder" );
712         input_DeletePES( p_input->p_method_data, p_pes );
713         return( -1 ); /* perhaps not, it's my choice */
714     }
715     else
716     {
717         input_DecodePES( p_demux->p_es->p_decoder_fifo, p_pes );
718     }
719     p_demux->i_pts += (mtime_t)90000 *
720                       (mtime_t)p_demux->i_samplelength /
721                       (mtime_t)p_demux->i_samplerate;
722     return( 1 );
723
724 }
725
726