]> git.sesse.net Git - vlc/blob - modules/demux/wav.c
Use _WIN32 rather than WIN32 (same for WIN64)
[vlc] / modules / demux / wav.c
1 /*****************************************************************************
2  * wav.c : wav file input module for vlc
3  *****************************************************************************
4  * Copyright (C) 2001-2008 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_demux.h>
35 #include <vlc_aout.h>
36 #include <vlc_codecs.h>
37
38 /*****************************************************************************
39  * Module descriptor
40  *****************************************************************************/
41 static int  Open ( vlc_object_t * );
42 static void Close( vlc_object_t * );
43
44 vlc_module_begin ()
45     set_description( N_("WAV demuxer") )
46     set_category( CAT_INPUT )
47     set_subcategory( SUBCAT_INPUT_DEMUX )
48     set_capability( "demux", 142 )
49     set_callbacks( Open, Close )
50 vlc_module_end ()
51
52 /*****************************************************************************
53  * Local prototypes
54  *****************************************************************************/
55 static int Demux  ( demux_t * );
56 static int Control( demux_t *, int i_query, va_list args );
57
58 struct demux_sys_t
59 {
60     es_format_t     fmt;
61     es_out_id_t     *p_es;
62
63     int64_t         i_data_pos;
64     int64_t         i_data_size;
65
66     unsigned int    i_frame_size;
67     int             i_frame_samples;
68
69     date_t          pts;
70
71     uint32_t i_channel_mask;
72     uint8_t i_chans_to_reorder;            /* do we need channel reordering */
73     uint8_t pi_chan_table[AOUT_CHAN_MAX];
74 };
75
76 static int ChunkFind( demux_t *, const char *, unsigned int * );
77
78 static int FrameInfo_IMA_ADPCM( unsigned int *, int *, const es_format_t * );
79 static int FrameInfo_MS_ADPCM ( unsigned int *, int *, const es_format_t * );
80 static int FrameInfo_PCM      ( unsigned int *, int *, const es_format_t * );
81 static int FrameInfo_MSGSM    ( unsigned int *, int *, const es_format_t * );
82
83 static const uint32_t pi_channels_src[] =
84     { WAVE_SPEAKER_FRONT_LEFT, WAVE_SPEAKER_FRONT_RIGHT,
85       WAVE_SPEAKER_FRONT_CENTER, WAVE_SPEAKER_LOW_FREQUENCY,
86       WAVE_SPEAKER_BACK_LEFT, WAVE_SPEAKER_BACK_RIGHT, WAVE_SPEAKER_BACK_CENTER,
87       WAVE_SPEAKER_SIDE_LEFT, WAVE_SPEAKER_SIDE_RIGHT, 0 };
88 static const uint32_t pi_channels_in[] =
89     { AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT,
90       AOUT_CHAN_CENTER, AOUT_CHAN_LFE,
91       AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT, AOUT_CHAN_REARCENTER,
92       AOUT_CHAN_MIDDLELEFT, AOUT_CHAN_MIDDLERIGHT, 0 };
93
94 /*****************************************************************************
95  * Open: check file and initializes structures
96  *****************************************************************************/
97 static int Open( vlc_object_t * p_this )
98 {
99     demux_t     *p_demux = (demux_t*)p_this;
100     demux_sys_t *p_sys;
101
102     const uint8_t *p_peek;
103     bool           b_is_rf64;
104     unsigned int   i_size;
105     uint64_t       i_data_size;
106     unsigned int   i_extended;
107     const char    *psz_name;
108
109     WAVEFORMATEXTENSIBLE *p_wf_ext = NULL;
110     WAVEFORMATEX         *p_wf = NULL;
111
112     /* Is it a wav file ? */
113     if( stream_Peek( p_demux->s, &p_peek, 12 ) < 12 )
114         return VLC_EGENERIC;
115
116     b_is_rf64 = ( memcmp( p_peek, "RF64", 4 ) == 0 );
117     if( ( !b_is_rf64 && memcmp( p_peek, "RIFF", 4 ) ) ||
118           memcmp( &p_peek[8], "WAVE", 4 ) )
119     {
120         return VLC_EGENERIC;
121     }
122
123     p_demux->pf_demux     = Demux;
124     p_demux->pf_control   = Control;
125     p_demux->p_sys        = p_sys = malloc( sizeof( *p_sys ) );
126     if( unlikely(!p_sys) )
127         return VLC_ENOMEM;
128
129     p_sys->p_es           = NULL;
130     p_sys->i_data_size    = 0;
131     p_sys->i_chans_to_reorder = 0;
132     p_sys->i_channel_mask = 0;
133
134     /* skip riff header */
135     if( stream_Read( p_demux->s, NULL, 12 ) != 12 )
136         goto error;
137
138     if( b_is_rf64 )
139     {
140         /* search datasize64 chunk */
141         if( ChunkFind( p_demux, "ds64", &i_size ) )
142         {
143             msg_Err( p_demux, "cannot find 'ds64' chunk" );
144             goto error;
145         }
146         if( i_size < 24 )
147         {
148             msg_Err( p_demux, "invalid 'ds64' chunk" );
149             goto error;
150         }
151         if( stream_Read( p_demux->s, NULL, 8 ) != 8 )
152             goto error;
153         if( stream_Peek( p_demux->s, &p_peek, 24 ) < 24 )
154             goto error;
155         i_data_size = GetQWLE( &p_peek[8] );
156         if( i_data_size >> 62 )
157             p_sys->i_data_size = (int64_t)1 << 62;
158         else
159             p_sys->i_data_size = i_data_size;
160         if( stream_Read( p_demux->s, NULL, i_size ) != (int)i_size ||
161             ( (i_size & 1) && stream_Read( p_demux->s, NULL, 1 ) != 1 ) )
162             goto error;
163     }
164
165     /* search fmt chunk */
166     if( ChunkFind( p_demux, "fmt ", &i_size ) )
167     {
168         msg_Err( p_demux, "cannot find 'fmt ' chunk" );
169         goto error;
170     }
171     i_size += 2;
172     if( i_size < sizeof( WAVEFORMATEX ) )
173     {
174         msg_Err( p_demux, "invalid 'fmt ' chunk" );
175         goto error;
176     }
177     if( stream_Read( p_demux->s, NULL, 8 ) != 8 )
178         goto error;
179
180
181     /* load waveformatex */
182     p_wf_ext = malloc( i_size );
183     if( unlikely( !p_wf_ext ) )
184          goto error;
185
186     p_wf         = &p_wf_ext->Format;
187     p_wf->cbSize = 0;
188     i_size      -= 2;
189     if( stream_Read( p_demux->s, p_wf, i_size ) != (int)i_size ||
190         ( ( i_size & 1 ) && stream_Read( p_demux->s, NULL, 1 ) != 1 ) )
191     {
192         msg_Err( p_demux, "cannot load 'fmt ' chunk" );
193         goto error;
194     }
195
196     es_format_Init( &p_sys->fmt, AUDIO_ES, 0 );
197     wf_tag_to_fourcc( GetWLE( &p_wf->wFormatTag ), &p_sys->fmt.i_codec,
198                       &psz_name );
199     p_sys->fmt.audio.i_channels      = GetWLE ( &p_wf->nChannels );
200     p_sys->fmt.audio.i_rate          = GetDWLE( &p_wf->nSamplesPerSec );
201     p_sys->fmt.audio.i_blockalign    = GetWLE( &p_wf->nBlockAlign );
202     p_sys->fmt.i_bitrate             = GetDWLE( &p_wf->nAvgBytesPerSec ) * 8;
203     p_sys->fmt.audio.i_bitspersample = GetWLE( &p_wf->wBitsPerSample );
204     if( i_size >= sizeof(WAVEFORMATEX) )
205         p_sys->fmt.i_extra = __MIN( GetWLE( &p_wf->cbSize ), i_size - sizeof(WAVEFORMATEX) );
206     i_extended = 0;
207
208     /* Handle new WAVE_FORMAT_EXTENSIBLE wav files */
209     /* see the following link for more information:
210      * http://www.microsoft.com/whdc/device/audio/multichaud.mspx#EFAA */
211     if( GetWLE( &p_wf->wFormatTag ) == WAVE_FORMAT_EXTENSIBLE &&
212         i_size >= sizeof( WAVEFORMATEXTENSIBLE ) &&
213         ( p_sys->fmt.i_extra + sizeof( WAVEFORMATEX )
214             >= sizeof( WAVEFORMATEXTENSIBLE ) ) )
215     {
216         unsigned i_channel_mask;
217         GUID guid_subformat;
218
219         guid_subformat = p_wf_ext->SubFormat;
220         guid_subformat.Data1 = GetDWLE( &p_wf_ext->SubFormat.Data1 );
221         guid_subformat.Data2 = GetWLE( &p_wf_ext->SubFormat.Data2 );
222         guid_subformat.Data3 = GetWLE( &p_wf_ext->SubFormat.Data3 );
223
224         sf_tag_to_fourcc( &guid_subformat, &p_sys->fmt.i_codec, &psz_name );
225
226         i_extended = sizeof( WAVEFORMATEXTENSIBLE ) - sizeof( WAVEFORMATEX );
227         p_sys->fmt.i_extra -= i_extended;
228
229         i_channel_mask = GetDWLE( &p_wf_ext->dwChannelMask );
230         if( i_channel_mask )
231         {
232             int i_match = 0;
233             for( unsigned i = 0; i < sizeof(pi_channels_src)/sizeof(*pi_channels_src); i++ )
234             {
235                 if( i_channel_mask & pi_channels_src[i] )
236                 {
237                     if( !( p_sys->i_channel_mask & pi_channels_in[i] ) )
238                         i_match++;
239
240                     i_channel_mask &= ~pi_channels_src[i];
241                     p_sys->i_channel_mask |= pi_channels_in[i];
242
243                     if( i_match >= p_sys->fmt.audio.i_channels )
244                         break;
245                 }
246             }
247             if( i_channel_mask )
248                 msg_Warn( p_demux, "Some channels are unrecognized or uselessly specified (0x%x)", i_channel_mask );
249             if( i_match < p_sys->fmt.audio.i_channels )
250             {
251                 int i_missing = p_sys->fmt.audio.i_channels - i_match;
252                 msg_Warn( p_demux, "Trying to fill up unspecified position for %d channels", p_sys->fmt.audio.i_channels - i_match );
253
254                 static const uint32_t pi_pair[] = { AOUT_CHAN_REARLEFT|AOUT_CHAN_REARRIGHT,
255                                                     AOUT_CHAN_MIDDLELEFT|AOUT_CHAN_MIDDLERIGHT,
256                                                     AOUT_CHAN_LEFT|AOUT_CHAN_RIGHT };
257                 /* FIXME: Unused yet
258                 static const uint32_t pi_center[] = { AOUT_CHAN_REARCENTER,
259                                                       0,
260                                                       AOUT_CHAN_CENTER }; */
261
262                 /* Try to complete with pair */
263                 for( unsigned i = 0; i < sizeof(pi_pair)/sizeof(*pi_pair); i++ )
264                 {
265                     if( i_missing >= 2 && !(p_sys->i_channel_mask & pi_pair[i] ) )
266                     {
267                         i_missing -= 2;
268                         p_sys->i_channel_mask |= pi_pair[i];
269                     }
270                 }
271                 /* Well fill up with what we can */
272                 for( unsigned i = 0; i < sizeof(pi_channels_in)/sizeof(*pi_channels_in) && i_missing > 0; i++ )
273                 {
274                     if( !( p_sys->i_channel_mask & pi_channels_in[i] ) )
275                     {
276                         p_sys->i_channel_mask |= pi_channels_in[i];
277                         i_missing--;
278
279                         if( i_missing <= 0 )
280                             break;
281                     }
282                 }
283
284                 i_match = p_sys->fmt.audio.i_channels - i_missing;
285             }
286             if( i_match < p_sys->fmt.audio.i_channels )
287             {
288                 msg_Err( p_demux, "Invalid/unsupported channel mask" );
289                 p_sys->i_channel_mask = 0;
290             }
291         }
292     }
293     else if( GetWLE( &p_wf->wFormatTag ) == WAVE_FORMAT_PCM &&
294              p_sys->fmt.audio.i_channels > 2 && p_sys->fmt.audio.i_channels <= 9 )
295     {
296         for( int i = 0; i < p_sys->fmt.audio.i_channels; i++ )
297             p_sys->i_channel_mask |= pi_channels_in[i];
298     }
299
300     if( p_sys->i_channel_mask )
301     {
302         if( p_sys->fmt.i_codec == VLC_FOURCC('a','r','a','w') ||
303             p_sys->fmt.i_codec == VLC_FOURCC('a','f','l','t') )
304             p_sys->i_chans_to_reorder =
305                 aout_CheckChannelReorder( pi_channels_in, NULL,
306                                           p_sys->i_channel_mask,
307                                           p_sys->pi_chan_table );
308
309         msg_Dbg( p_demux, "channel mask: %x, reordering: %u",
310                  p_sys->i_channel_mask, p_sys->i_chans_to_reorder );
311     }
312
313     p_sys->fmt.audio.i_physical_channels =
314     p_sys->fmt.audio.i_original_channels = p_sys->i_channel_mask;
315
316     if( p_sys->fmt.i_extra > 0 )
317     {
318         p_sys->fmt.p_extra = malloc( p_sys->fmt.i_extra );
319         if( unlikely(!p_sys->fmt.p_extra) )
320         {
321             p_sys->fmt.i_extra = 0;
322             goto error;
323         }
324         memcpy( p_sys->fmt.p_extra, (uint8_t *)p_wf + sizeof( WAVEFORMATEX ) + i_extended,
325                 p_sys->fmt.i_extra );
326     }
327
328     msg_Dbg( p_demux, "format: 0x%4.4x, fourcc: %4.4s, channels: %d, "
329              "freq: %u Hz, bitrate: %uKo/s, blockalign: %d, bits/samples: %d, "
330              "extra size: %d",
331              GetWLE( &p_wf->wFormatTag ), (char *)&p_sys->fmt.i_codec,
332              p_sys->fmt.audio.i_channels, p_sys->fmt.audio.i_rate,
333              p_sys->fmt.i_bitrate / 8 / 1024, p_sys->fmt.audio.i_blockalign,
334              p_sys->fmt.audio.i_bitspersample, p_sys->fmt.i_extra );
335
336     free( p_wf );
337     p_wf = NULL;
338
339     switch( p_sys->fmt.i_codec )
340     {
341     case VLC_FOURCC( 'a', 'r', 'a', 'w' ):
342     case VLC_FOURCC( 'a', 'f', 'l', 't' ):
343     case VLC_FOURCC( 'u', 'l', 'a', 'w' ):
344     case VLC_CODEC_ALAW:
345     case VLC_CODEC_MULAW:
346         if( FrameInfo_PCM( &p_sys->i_frame_size, &p_sys->i_frame_samples,
347                            &p_sys->fmt ) )
348             goto error;
349         p_sys->fmt.i_codec =
350             vlc_fourcc_GetCodecAudio( p_sys->fmt.i_codec,
351                                       p_sys->fmt.audio.i_bitspersample );
352         break;
353     case VLC_CODEC_ADPCM_MS:
354     /* FIXME not sure at all FIXME */
355     case VLC_FOURCC( 'm', 's', 0x00, 0x61 ):
356     case VLC_FOURCC( 'm', 's', 0x00, 0x62 ):
357         if( FrameInfo_MS_ADPCM( &p_sys->i_frame_size, &p_sys->i_frame_samples,
358                                 &p_sys->fmt ) )
359             goto error;
360         break;
361     case VLC_CODEC_ADPCM_IMA_WAV:
362         if( FrameInfo_IMA_ADPCM( &p_sys->i_frame_size, &p_sys->i_frame_samples,
363                                  &p_sys->fmt ) )
364             goto error;
365         break;
366     case VLC_CODEC_MPGA:
367     case VLC_CODEC_A52:
368         /* FIXME set end of area FIXME */
369         goto error;
370     case VLC_CODEC_GSM_MS:
371     case VLC_CODEC_ADPCM_G726:
372     case VLC_CODEC_TRUESPEECH:
373     case VLC_CODEC_ATRAC3:
374     case VLC_CODEC_G723_1:
375     case VLC_CODEC_WMA2:
376         if( FrameInfo_MSGSM( &p_sys->i_frame_size, &p_sys->i_frame_samples,
377                              &p_sys->fmt ) )
378             goto error;
379         break;
380     default:
381         msg_Err( p_demux, "unsupported codec (%4.4s)",
382                  (char*)&p_sys->fmt.i_codec );
383         goto error;
384     }
385
386     if( p_sys->i_frame_size <= 0 || p_sys->i_frame_samples <= 0 )
387     {
388         msg_Dbg( p_demux, "invalid frame size: %i %i", p_sys->i_frame_size,
389                                                        p_sys->i_frame_samples );
390         goto error;
391     }
392     if( p_sys->fmt.audio.i_rate <= 0 )
393     {
394         msg_Dbg( p_demux, "invalid sample rate: %i", p_sys->fmt.audio.i_rate );
395         goto error;
396     }
397
398     msg_Dbg( p_demux, "found %s audio format", psz_name );
399
400     if( ChunkFind( p_demux, "data", &i_size ) )
401     {
402         msg_Err( p_demux, "cannot find 'data' chunk" );
403         goto error;
404     }
405     if( !b_is_rf64 || i_size < UINT32_MAX )
406         p_sys->i_data_size = i_size;
407     if( stream_Read( p_demux->s, NULL, 8 ) != 8 )
408         goto error;
409     p_sys->i_data_pos = stream_Tell( p_demux->s );
410
411     if( p_sys->fmt.i_bitrate <= 0 )
412     {
413         p_sys->fmt.i_bitrate = (int64_t)p_sys->i_frame_size *
414             p_sys->fmt.audio.i_rate * 8 / p_sys->i_frame_samples;
415     }
416
417     p_sys->p_es = es_out_Add( p_demux->out, &p_sys->fmt );
418
419     date_Init( &p_sys->pts, p_sys->fmt.audio.i_rate, 1 );
420     date_Set( &p_sys->pts, 1 );
421
422     return VLC_SUCCESS;
423
424 error:
425     msg_Err( p_demux, "An error occurred during wav demuxing" );
426     free( p_wf );
427     free( p_sys );
428     return VLC_EGENERIC;
429 }
430
431 /*****************************************************************************
432  * Demux: read packet and send them to decoders
433  *****************************************************************************
434  * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
435  *****************************************************************************/
436 static int Demux( demux_t *p_demux )
437 {
438     demux_sys_t *p_sys = p_demux->p_sys;
439     block_t     *p_block;
440     const int64_t i_pos = stream_Tell( p_demux->s );
441
442     if( p_sys->i_data_size > 0 &&
443         i_pos >= p_sys->i_data_pos + p_sys->i_data_size )
444     {
445         /* EOF */
446         return 0;
447     }
448
449     if( ( p_block = stream_Block( p_demux->s, p_sys->i_frame_size ) ) == NULL )
450     {
451         msg_Warn( p_demux, "cannot read data" );
452         return 0;
453     }
454
455     p_block->i_dts =
456     p_block->i_pts = VLC_TS_0 + date_Get( &p_sys->pts );
457
458     /* set PCR */
459     es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
460
461     /* Do the channel reordering */
462     if( p_sys->i_chans_to_reorder )
463         aout_ChannelReorder( p_block->p_buffer, p_block->i_buffer,
464                              p_sys->fmt.audio.i_channels,
465                              p_sys->pi_chan_table, p_sys->fmt.i_codec );
466
467     es_out_Send( p_demux->out, p_sys->p_es, p_block );
468
469     date_Increment( &p_sys->pts, p_sys->i_frame_samples );
470
471     return 1;
472 }
473
474 /*****************************************************************************
475  * Close: frees unused data
476  *****************************************************************************/
477 static void Close ( vlc_object_t * p_this )
478 {
479     demux_t     *p_demux = (demux_t*)p_this;
480     demux_sys_t *p_sys   = p_demux->p_sys;
481
482     free( p_sys );
483 }
484
485 /*****************************************************************************
486  * Control:
487  *****************************************************************************/
488 static int Control( demux_t *p_demux, int i_query, va_list args )
489 {
490     demux_sys_t *p_sys  = p_demux->p_sys;
491     int64_t i_end = -1;
492
493     if( p_sys->i_data_size > 0 )
494         i_end = p_sys->i_data_pos + p_sys->i_data_size;
495
496     return demux_vaControlHelper( p_demux->s, p_sys->i_data_pos, i_end,
497                                    p_sys->fmt.i_bitrate,
498                                    p_sys->fmt.audio.i_blockalign,
499                                    i_query, args );
500 }
501
502 /*****************************************************************************
503  * Local functions
504  *****************************************************************************/
505 static int ChunkFind( demux_t *p_demux, const char *fcc, unsigned int *pi_size )
506 {
507     const uint8_t *p_peek;
508
509     for( ;; )
510     {
511         uint32_t i_size;
512
513         if( stream_Peek( p_demux->s, &p_peek, 8 ) < 8 )
514         {
515             msg_Err( p_demux, "cannot peek" );
516             return VLC_EGENERIC;
517         }
518
519         i_size = GetDWLE( p_peek + 4 );
520
521         msg_Dbg( p_demux, "chunk: fcc=`%4.4s` size=%"PRIu32, p_peek, i_size );
522
523         if( !memcmp( p_peek, fcc, 4 ) )
524         {
525             if( pi_size )
526             {
527                 *pi_size = i_size;
528             }
529             return VLC_SUCCESS;
530         }
531
532         /* Skip chunk */
533         if( stream_Read( p_demux->s, NULL, 8 ) != 8 ||
534             stream_Read( p_demux->s, NULL, i_size ) != (int)i_size ||
535             ( (i_size & 1) && stream_Read( p_demux->s, NULL, 1 ) != 1 ) )
536             return VLC_EGENERIC;
537     }
538 }
539
540 static int FrameInfo_PCM( unsigned int *pi_size, int *pi_samples,
541                           const es_format_t *p_fmt )
542 {
543     int i_bytes;
544
545     /* read samples for 50ms of */
546     *pi_samples = __MAX( p_fmt->audio.i_rate / 20, 1 );
547
548     i_bytes = *pi_samples * p_fmt->audio.i_channels *
549         ( (p_fmt->audio.i_bitspersample + 7) / 8 );
550
551     if( p_fmt->audio.i_blockalign > 0 )
552     {
553         const int i_modulo = i_bytes % p_fmt->audio.i_blockalign;
554         if( i_modulo > 0 )
555             i_bytes += p_fmt->audio.i_blockalign - i_modulo;
556     }
557
558     *pi_size = i_bytes;
559     return VLC_SUCCESS;
560 }
561
562 static int FrameInfo_MS_ADPCM( unsigned int *pi_size, int *pi_samples,
563                                const es_format_t *p_fmt )
564 {
565     if( p_fmt->audio.i_channels <= 0 )
566         return VLC_EGENERIC;
567
568     *pi_samples = 2 + 2 * ( p_fmt->audio.i_blockalign -
569         7 * p_fmt->audio.i_channels ) / p_fmt->audio.i_channels;
570     *pi_size = p_fmt->audio.i_blockalign;
571
572     return VLC_SUCCESS;
573 }
574
575 static int FrameInfo_IMA_ADPCM( unsigned int *pi_size, int *pi_samples,
576                                 const es_format_t *p_fmt )
577 {
578     if( p_fmt->audio.i_channels <= 0 )
579         return VLC_EGENERIC;
580
581     *pi_samples = 2 * ( p_fmt->audio.i_blockalign -
582         4 * p_fmt->audio.i_channels ) / p_fmt->audio.i_channels;
583     *pi_size = p_fmt->audio.i_blockalign;
584
585     return VLC_SUCCESS;
586 }
587
588 static int FrameInfo_MSGSM( unsigned int *pi_size, int *pi_samples,
589                             const es_format_t *p_fmt )
590 {
591     if( p_fmt->i_bitrate <= 0 )
592         return VLC_EGENERIC;
593
594     *pi_samples = ( p_fmt->audio.i_blockalign * p_fmt->audio.i_rate * 8)
595                     / p_fmt->i_bitrate;
596     *pi_size = p_fmt->audio.i_blockalign;
597
598     return VLC_SUCCESS;
599 }
600