demux: mp4: use static mapping table per layout
[vlc.git] / modules / demux / wav.c
blobc01e7fd3c6f38b3b81a7e4b1ef5ada49ae76c239
1 /*****************************************************************************
2 * wav.c : wav file input module for vlc
3 *****************************************************************************
4 * Copyright (C) 2001-2008 VLC authors and VideoLAN
5 * $Id$
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
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.
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.
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 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include <assert.h>
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
36 #include <vlc_demux.h>
37 #include <vlc_aout.h>
38 #include <vlc_codecs.h>
40 #include "windows_audio_commons.h"
42 #define WAV_CHAN_MAX 32
43 static_assert( INPUT_CHAN_MAX >= WAV_CHAN_MAX, "channel count mismatch" );
45 /*****************************************************************************
46 * Module descriptor
47 *****************************************************************************/
48 static int Open ( vlc_object_t * );
49 static void Close( vlc_object_t * );
51 vlc_module_begin ()
52 set_description( N_("WAV demuxer") )
53 set_category( CAT_INPUT )
54 set_subcategory( SUBCAT_INPUT_DEMUX )
55 set_capability( "demux", 142 )
56 set_callbacks( Open, Close )
57 vlc_module_end ()
59 /*****************************************************************************
60 * Local prototypes
61 *****************************************************************************/
62 static int Demux ( demux_t * );
63 static int Control( demux_t *, int i_query, va_list args );
65 typedef struct
67 es_format_t fmt;
68 es_out_id_t *p_es;
70 int64_t i_data_pos;
71 int64_t i_data_size;
73 unsigned int i_frame_size;
74 int i_frame_samples;
76 date_t pts;
78 uint32_t i_channel_mask;
79 uint8_t i_chans_to_reorder; /* do we need channel reordering */
80 uint8_t pi_chan_table[AOUT_CHAN_MAX];
81 } demux_sys_t;
83 static int ChunkFind( demux_t *, const char *, unsigned int * );
85 static int FrameInfo_IMA_ADPCM( unsigned int *, int *, const es_format_t * );
86 static int FrameInfo_MS_ADPCM ( unsigned int *, int *, const es_format_t * );
87 static int FrameInfo_Creative_ADPCM( unsigned int *, int *, const es_format_t * );
88 static int FrameInfo_PCM ( unsigned int *, int *, const es_format_t * );
89 static int FrameInfo_MSGSM ( unsigned int *, int *, const es_format_t * );
91 /*****************************************************************************
92 * Open: check file and initializes structures
93 *****************************************************************************/
94 static int Open( vlc_object_t * p_this )
96 demux_t *p_demux = (demux_t*)p_this;
97 demux_sys_t *p_sys;
99 const uint8_t *p_peek;
100 bool b_is_rf64;
101 unsigned int i_size;
102 uint64_t i_data_size;
103 unsigned int i_extended;
104 const char *psz_name;
106 WAVEFORMATEXTENSIBLE *p_wf_ext = NULL;
107 WAVEFORMATEX *p_wf = NULL;
109 /* Is it a wav file ? */
110 if( vlc_stream_Peek( p_demux->s, &p_peek, 12 ) < 12 )
111 return VLC_EGENERIC;
113 b_is_rf64 = ( memcmp( p_peek, "RF64", 4 ) == 0 );
114 if( ( !b_is_rf64 && memcmp( p_peek, "RIFF", 4 ) ) ||
115 memcmp( &p_peek[8], "WAVE", 4 ) )
117 return VLC_EGENERIC;
120 p_demux->pf_demux = Demux;
121 p_demux->pf_control = Control;
122 p_demux->p_sys = p_sys = malloc( sizeof( *p_sys ) );
123 if( unlikely(!p_sys) )
124 return VLC_ENOMEM;
126 es_format_Init( &p_sys->fmt, AUDIO_ES, 0 );
127 p_sys->p_es = NULL;
128 p_sys->i_data_size = 0;
129 p_sys->i_chans_to_reorder = 0;
130 p_sys->i_channel_mask = 0;
132 /* skip riff header */
133 if( vlc_stream_Read( p_demux->s, NULL, 12 ) != 12 )
134 goto error;
136 if( b_is_rf64 )
138 /* search datasize64 chunk */
139 if( ChunkFind( p_demux, "ds64", &i_size ) )
141 msg_Err( p_demux, "cannot find 'ds64' chunk" );
142 goto error;
144 if( i_size < 24 )
146 msg_Err( p_demux, "invalid 'ds64' chunk" );
147 goto error;
149 if( vlc_stream_Read( p_demux->s, NULL, 8 ) != 8 )
150 goto error;
151 if( vlc_stream_Peek( p_demux->s, &p_peek, 24 ) < 24 )
152 goto error;
153 i_data_size = GetQWLE( &p_peek[8] );
154 if( i_data_size >> 62 )
155 p_sys->i_data_size = (int64_t)1 << 62;
156 else
157 p_sys->i_data_size = i_data_size;
158 if( vlc_stream_Read( p_demux->s, NULL, i_size ) != (int)i_size ||
159 ( (i_size & 1) && vlc_stream_Read( p_demux->s, NULL, 1 ) != 1 ) )
160 goto error;
163 /* search fmt chunk */
164 if( ChunkFind( p_demux, "fmt ", &i_size ) )
166 msg_Err( p_demux, "cannot find 'fmt ' chunk" );
167 goto error;
169 i_size += 2;
170 if( i_size < sizeof( WAVEFORMATEX ) )
172 msg_Err( p_demux, "invalid 'fmt ' chunk" );
173 goto error;
175 if( vlc_stream_Read( p_demux->s, NULL, 8 ) != 8 )
176 goto error;
179 /* load waveformatex */
180 p_wf_ext = malloc( i_size );
181 if( unlikely( !p_wf_ext ) )
182 goto error;
184 p_wf = &p_wf_ext->Format;
185 p_wf->cbSize = 0;
186 i_size -= 2;
187 if( vlc_stream_Read( p_demux->s, p_wf, i_size ) != (int)i_size ||
188 ( ( i_size & 1 ) && vlc_stream_Read( p_demux->s, NULL, 1 ) != 1 ) )
190 msg_Err( p_demux, "cannot load 'fmt ' chunk" );
191 goto error;
194 wf_tag_to_fourcc( GetWLE( &p_wf->wFormatTag ), &p_sys->fmt.i_codec,
195 &psz_name );
196 p_sys->fmt.audio.i_channels = GetWLE ( &p_wf->nChannels );
197 p_sys->fmt.audio.i_rate = GetDWLE( &p_wf->nSamplesPerSec );
198 p_sys->fmt.audio.i_blockalign = GetWLE( &p_wf->nBlockAlign );
199 p_sys->fmt.i_bitrate = GetDWLE( &p_wf->nAvgBytesPerSec ) * 8;
200 p_sys->fmt.audio.i_bitspersample = GetWLE( &p_wf->wBitsPerSample );
201 if( i_size >= sizeof(WAVEFORMATEX) )
202 p_sys->fmt.i_extra = __MIN( GetWLE( &p_wf->cbSize ), i_size - sizeof(WAVEFORMATEX) );
203 i_extended = 0;
205 /* Handle new WAVE_FORMAT_EXTENSIBLE wav files */
206 /* see the following link for more information:
207 * http://www.microsoft.com/whdc/device/audio/multichaud.mspx#EFAA */
208 if( GetWLE( &p_wf->wFormatTag ) == WAVE_FORMAT_EXTENSIBLE &&
209 i_size >= sizeof( WAVEFORMATEXTENSIBLE ) &&
210 ( p_sys->fmt.i_extra + sizeof( WAVEFORMATEX )
211 >= sizeof( WAVEFORMATEXTENSIBLE ) ) )
213 unsigned i_channel_mask;
214 GUID guid_subformat;
216 guid_subformat = p_wf_ext->SubFormat;
217 guid_subformat.Data1 = GetDWLE( &p_wf_ext->SubFormat.Data1 );
218 guid_subformat.Data2 = GetWLE( &p_wf_ext->SubFormat.Data2 );
219 guid_subformat.Data3 = GetWLE( &p_wf_ext->SubFormat.Data3 );
221 sf_tag_to_fourcc( &guid_subformat, &p_sys->fmt.i_codec, &psz_name );
223 msg_Dbg( p_demux, "extensible format guid " GUID_FMT, GUID_PRINT(guid_subformat) );
225 i_extended = sizeof( WAVEFORMATEXTENSIBLE ) - sizeof( WAVEFORMATEX );
226 p_sys->fmt.i_extra -= i_extended;
228 i_channel_mask = GetDWLE( &p_wf_ext->dwChannelMask );
229 if( i_channel_mask )
231 int i_match = 0;
232 p_sys->i_channel_mask = getChannelMask( &i_channel_mask, p_sys->fmt.audio.i_channels, &i_match );
233 if( i_channel_mask )
234 msg_Warn( p_demux, "Some channels are unrecognized or uselessly specified (0x%x)", i_channel_mask );
235 if( i_match < p_sys->fmt.audio.i_channels )
237 int i_missing = p_sys->fmt.audio.i_channels - i_match;
238 msg_Warn( p_demux, "Trying to fill up unspecified position for %d channels", p_sys->fmt.audio.i_channels - i_match );
240 static const uint32_t pi_pair[] = { AOUT_CHAN_REARLEFT|AOUT_CHAN_REARRIGHT,
241 AOUT_CHAN_MIDDLELEFT|AOUT_CHAN_MIDDLERIGHT,
242 AOUT_CHAN_LEFT|AOUT_CHAN_RIGHT };
243 /* FIXME: Unused yet
244 static const uint32_t pi_center[] = { AOUT_CHAN_REARCENTER,
246 AOUT_CHAN_CENTER }; */
248 /* Try to complete with pair */
249 for( unsigned i = 0; i < sizeof(pi_pair)/sizeof(*pi_pair); i++ )
251 if( i_missing >= 2 && !(p_sys->i_channel_mask & pi_pair[i] ) )
253 i_missing -= 2;
254 p_sys->i_channel_mask |= pi_pair[i];
257 /* Well fill up with what we can */
258 for( unsigned i = 0; i < sizeof(pi_channels_aout)/sizeof(*pi_channels_aout) && i_missing > 0; i++ )
260 if( !( p_sys->i_channel_mask & pi_channels_aout[i] ) )
262 p_sys->i_channel_mask |= pi_channels_aout[i];
263 i_missing--;
265 if( i_missing <= 0 )
266 break;
270 i_match = p_sys->fmt.audio.i_channels - i_missing;
272 if( i_match < p_sys->fmt.audio.i_channels )
274 msg_Err( p_demux, "Invalid/unsupported channel mask" );
275 p_sys->i_channel_mask = 0;
279 if( p_sys->i_channel_mask == 0 && p_sys->fmt.audio.i_channels > 2
280 && p_sys->fmt.audio.i_channels <= AOUT_CHAN_MAX )
282 /* A dwChannelMask of 0 tells the audio device to render the first
283 * channel to the first port on the device, the second channel to the
284 * second port on the device, and so on. pi_default_channels is
285 * different than pi_channels_aout. Indeed FLC/FRC must be treated a
286 * SL/SR in that case. See "Default Channel Ordering" and "Details
287 * about dwChannelMask" from msdn */
289 static const uint32_t pi_default_channels[] = {
290 AOUT_CHAN_LEFT, AOUT_CHAN_RIGHT, AOUT_CHAN_CENTER,
291 AOUT_CHAN_LFE, AOUT_CHAN_REARLEFT, AOUT_CHAN_REARRIGHT,
292 AOUT_CHAN_MIDDLELEFT, AOUT_CHAN_MIDDLERIGHT, AOUT_CHAN_REARCENTER };
294 for( unsigned i = 0; i < p_sys->fmt.audio.i_channels &&
295 i < (sizeof(pi_default_channels) / sizeof(*pi_default_channels));
296 i++ )
297 p_sys->i_channel_mask |= pi_default_channels[i];
300 if( p_sys->i_channel_mask )
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_aout, NULL,
306 p_sys->i_channel_mask,
307 p_sys->pi_chan_table );
309 msg_Dbg( p_demux, "channel mask: %x, reordering: %u",
310 p_sys->i_channel_mask, p_sys->i_chans_to_reorder );
313 p_sys->fmt.audio.i_physical_channels = p_sys->i_channel_mask;
315 if( p_sys->fmt.i_extra > 0 )
317 p_sys->fmt.p_extra = malloc( p_sys->fmt.i_extra );
318 if( unlikely(!p_sys->fmt.p_extra) )
320 p_sys->fmt.i_extra = 0;
321 goto error;
323 memcpy( p_sys->fmt.p_extra, (uint8_t *)p_wf + sizeof( WAVEFORMATEX ) + i_extended,
324 p_sys->fmt.i_extra );
327 msg_Dbg( p_demux, "format: 0x%4.4x, fourcc: %4.4s, channels: %d, "
328 "freq: %u Hz, bitrate: %uKo/s, blockalign: %d, bits/samples: %d, "
329 "extra size: %d",
330 GetWLE( &p_wf->wFormatTag ), (char *)&p_sys->fmt.i_codec,
331 p_sys->fmt.audio.i_channels, p_sys->fmt.audio.i_rate,
332 p_sys->fmt.i_bitrate / 8 / 1024, p_sys->fmt.audio.i_blockalign,
333 p_sys->fmt.audio.i_bitspersample, p_sys->fmt.i_extra );
335 free( p_wf );
336 p_wf = NULL;
338 switch( p_sys->fmt.i_codec )
340 case VLC_FOURCC( 'a', 'r', 'a', 'w' ):
341 case VLC_FOURCC( 'a', 'f', 'l', 't' ):
342 case VLC_FOURCC( 'u', 'l', 'a', 'w' ):
343 case VLC_CODEC_ALAW:
344 case VLC_CODEC_MULAW:
345 if( FrameInfo_PCM( &p_sys->i_frame_size, &p_sys->i_frame_samples,
346 &p_sys->fmt ) )
347 goto error;
348 p_sys->fmt.i_codec =
349 vlc_fourcc_GetCodecAudio( p_sys->fmt.i_codec,
350 p_sys->fmt.audio.i_bitspersample );
351 if( p_sys->fmt.i_codec == 0 ) {
352 msg_Err( p_demux, "Unrecognized codec" );
353 goto error;
355 break;
356 case VLC_CODEC_ADPCM_MS:
357 /* FIXME not sure at all FIXME */
358 case VLC_FOURCC( 'm', 's', 0x00, 0x61 ):
359 case VLC_FOURCC( 'm', 's', 0x00, 0x62 ):
360 if( FrameInfo_MS_ADPCM( &p_sys->i_frame_size, &p_sys->i_frame_samples,
361 &p_sys->fmt ) )
362 goto error;
363 break;
364 case VLC_CODEC_ADPCM_IMA_WAV:
365 if( FrameInfo_IMA_ADPCM( &p_sys->i_frame_size, &p_sys->i_frame_samples,
366 &p_sys->fmt ) )
367 goto error;
368 break;
369 case VLC_CODEC_ADPCM_CREATIVE:
370 if( FrameInfo_Creative_ADPCM( &p_sys->i_frame_size, &p_sys->i_frame_samples,
371 &p_sys->fmt ) )
372 goto error;
373 break;
374 case VLC_CODEC_MPGA:
375 case VLC_CODEC_A52:
376 /* FIXME set end of area FIXME */
377 goto error;
378 case VLC_CODEC_GSM_MS:
379 case VLC_CODEC_ADPCM_G726:
380 case VLC_CODEC_TRUESPEECH:
381 case VLC_CODEC_ATRAC3P:
382 case VLC_CODEC_ATRAC3:
383 case VLC_CODEC_G723_1:
384 case VLC_CODEC_WMA2:
385 if( FrameInfo_MSGSM( &p_sys->i_frame_size, &p_sys->i_frame_samples,
386 &p_sys->fmt ) )
387 goto error;
388 break;
389 default:
390 msg_Err( p_demux, "unsupported codec (%4.4s)",
391 (char*)&p_sys->fmt.i_codec );
392 goto error;
395 if( p_sys->i_frame_size <= 0 || p_sys->i_frame_samples <= 0 )
397 msg_Dbg( p_demux, "invalid frame size: %i %i", p_sys->i_frame_size,
398 p_sys->i_frame_samples );
399 goto error;
401 if( p_sys->fmt.audio.i_rate == 0 )
403 msg_Dbg( p_demux, "invalid sample rate: %i", p_sys->fmt.audio.i_rate );
404 goto error;
407 msg_Dbg( p_demux, "found %s audio format", psz_name );
409 if( ChunkFind( p_demux, "data", &i_size ) )
411 msg_Err( p_demux, "cannot find 'data' chunk" );
412 goto error;
414 if( !b_is_rf64 || i_size < UINT32_MAX )
416 int64_t i_stream_size = stream_Size( p_demux->s );
417 if( i_stream_size > 0 && i_stream_size >= i_size + p_sys->i_data_pos )
418 p_sys->i_data_size = i_size;
421 if( vlc_stream_Read( p_demux->s, NULL, 8 ) != 8 )
422 goto error;
423 p_sys->i_data_pos = vlc_stream_Tell( p_demux->s );
425 if( p_sys->fmt.i_bitrate <= 0 )
427 p_sys->fmt.i_bitrate = (int64_t)p_sys->i_frame_size *
428 p_sys->fmt.audio.i_rate * 8 / p_sys->i_frame_samples;
431 p_sys->p_es = es_out_Add( p_demux->out, &p_sys->fmt );
432 if( unlikely(p_sys->p_es == NULL) )
433 goto error;
435 date_Init( &p_sys->pts, p_sys->fmt.audio.i_rate, 1 );
436 date_Set( &p_sys->pts, VLC_TICK_0 );
438 return VLC_SUCCESS;
440 error:
441 msg_Err( p_demux, "An error occurred during wav demuxing" );
442 free( p_wf );
443 es_format_Clean( &p_sys->fmt );
444 free( p_sys );
445 return VLC_EGENERIC;
448 /*****************************************************************************
449 * Demux: read packet and send them to decoders
450 *****************************************************************************
451 * Returns -1 in case of error, 0 in case of EOF, 1 otherwise
452 *****************************************************************************/
453 static int Demux( demux_t *p_demux )
455 demux_sys_t *p_sys = p_demux->p_sys;
456 block_t *p_block;
457 const int64_t i_pos = vlc_stream_Tell( p_demux->s );
458 unsigned int i_read_size = p_sys->i_frame_size;
460 if( p_sys->i_data_size > 0 )
462 int64_t i_end = p_sys->i_data_pos + p_sys->i_data_size;
463 if ( i_pos >= i_end )
464 return VLC_DEMUXER_EOF; /* EOF */
466 /* Don't read past data chunk boundary */
467 if ( i_end < i_pos + i_read_size )
468 i_read_size = i_end - i_pos;
471 if( ( p_block = vlc_stream_Block( p_demux->s, i_read_size ) ) == NULL )
473 msg_Warn( p_demux, "cannot read data" );
474 return VLC_DEMUXER_EOF;
477 p_block->i_dts =
478 p_block->i_pts = date_Get( &p_sys->pts );
480 /* set PCR */
481 es_out_SetPCR( p_demux->out, p_block->i_pts );
483 /* Do the channel reordering */
484 if( p_sys->i_chans_to_reorder )
485 aout_ChannelReorder( p_block->p_buffer, p_block->i_buffer,
486 p_sys->fmt.audio.i_channels,
487 p_sys->pi_chan_table, p_sys->fmt.i_codec );
489 es_out_Send( p_demux->out, p_sys->p_es, p_block );
491 date_Increment( &p_sys->pts, p_sys->i_frame_samples );
493 return VLC_DEMUXER_SUCCESS;
496 /*****************************************************************************
497 * Close: frees unused data
498 *****************************************************************************/
499 static void Close ( vlc_object_t * p_this )
501 demux_t *p_demux = (demux_t*)p_this;
502 demux_sys_t *p_sys = p_demux->p_sys;
504 es_format_Clean( &p_sys->fmt );
505 free( p_sys );
508 /*****************************************************************************
509 * Control:
510 *****************************************************************************/
511 static int Control( demux_t *p_demux, int i_query, va_list args )
513 demux_sys_t *p_sys = p_demux->p_sys;
514 int64_t i_end = -1;
516 if( p_sys->i_data_size > 0 )
517 i_end = p_sys->i_data_pos + p_sys->i_data_size;
519 return demux_vaControlHelper( p_demux->s, p_sys->i_data_pos, i_end,
520 p_sys->fmt.i_bitrate,
521 p_sys->fmt.audio.i_blockalign,
522 i_query, args );
525 /*****************************************************************************
526 * Local functions
527 *****************************************************************************/
528 static int ChunkFind( demux_t *p_demux, const char *fcc, unsigned int *pi_size )
530 const uint8_t *p_peek;
532 for( ;; )
534 uint32_t i_size;
536 if( vlc_stream_Peek( p_demux->s, &p_peek, 8 ) < 8 )
538 msg_Err( p_demux, "cannot peek" );
539 return VLC_EGENERIC;
542 i_size = GetDWLE( p_peek + 4 );
544 msg_Dbg( p_demux, "chunk: fcc=`%4.4s` size=%"PRIu32, p_peek, i_size );
546 if( !memcmp( p_peek, fcc, 4 ) )
548 if( pi_size )
550 *pi_size = i_size;
552 return VLC_SUCCESS;
555 /* Skip chunk */
556 if( vlc_stream_Read( p_demux->s, NULL, 8 ) != 8 ||
557 vlc_stream_Read( p_demux->s, NULL, i_size ) != (int)i_size ||
558 ( (i_size & 1) && vlc_stream_Read( p_demux->s, NULL, 1 ) != 1 ) )
559 return VLC_EGENERIC;
563 static int FrameInfo_PCM( unsigned int *pi_size, int *pi_samples,
564 const es_format_t *p_fmt )
566 int i_bytes;
568 if( p_fmt->audio.i_rate > 352800
569 || p_fmt->audio.i_bitspersample > 64
570 || p_fmt->audio.i_channels > WAV_CHAN_MAX )
571 return VLC_EGENERIC;
573 /* read samples for 50ms of */
574 *pi_samples = __MAX( p_fmt->audio.i_rate / 20, 1 );
576 i_bytes = *pi_samples * p_fmt->audio.i_channels *
577 ( (p_fmt->audio.i_bitspersample + 7) / 8 );
579 if( p_fmt->audio.i_blockalign > 0 )
581 const int i_modulo = i_bytes % p_fmt->audio.i_blockalign;
582 if( i_modulo > 0 )
583 i_bytes += p_fmt->audio.i_blockalign - i_modulo;
586 *pi_size = i_bytes;
587 return VLC_SUCCESS;
590 static int FrameInfo_MS_ADPCM( unsigned int *pi_size, int *pi_samples,
591 const es_format_t *p_fmt )
593 if( p_fmt->audio.i_channels == 0 )
594 return VLC_EGENERIC;
596 *pi_samples = 2 + 2 * ( p_fmt->audio.i_blockalign -
597 7 * p_fmt->audio.i_channels ) / p_fmt->audio.i_channels;
598 *pi_size = p_fmt->audio.i_blockalign;
600 return VLC_SUCCESS;
603 static int FrameInfo_IMA_ADPCM( unsigned int *pi_size, int *pi_samples,
604 const es_format_t *p_fmt )
606 if( p_fmt->audio.i_channels == 0 )
607 return VLC_EGENERIC;
609 *pi_samples = 2 * ( p_fmt->audio.i_blockalign -
610 4 * p_fmt->audio.i_channels ) / p_fmt->audio.i_channels;
611 *pi_size = p_fmt->audio.i_blockalign;
613 return VLC_SUCCESS;
616 static int FrameInfo_Creative_ADPCM( unsigned int *pi_size, int *pi_samples,
617 const es_format_t *p_fmt )
619 if( p_fmt->audio.i_channels == 0 )
620 return VLC_EGENERIC;
622 /* 4 bits / sample */
623 *pi_samples = p_fmt->audio.i_blockalign * 2 / p_fmt->audio.i_channels;
624 *pi_size = p_fmt->audio.i_blockalign;
626 return VLC_SUCCESS;
629 static int FrameInfo_MSGSM( unsigned int *pi_size, int *pi_samples,
630 const es_format_t *p_fmt )
632 if( p_fmt->i_bitrate <= 0 )
633 return VLC_EGENERIC;
635 *pi_samples = ( p_fmt->audio.i_blockalign * p_fmt->audio.i_rate * 8)
636 / p_fmt->i_bitrate;
637 *pi_size = p_fmt->audio.i_blockalign;
639 return VLC_SUCCESS;