Add encoder support for Dirac using the Schroedinger library.
[vlc/asuraparaju-public.git] / modules / codec / mpeg_audio.c
blob2335c4e457e05e2ce8d75a1fedd1e5b0fff34356
1 /*****************************************************************************
2 * mpeg_audio.c: parse MPEG audio sync info and packetize the stream
3 *****************************************************************************
4 * Copyright (C) 2001-2003 the VideoLAN team
5 * $Id$
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * Eric Petit <titer@videolan.org>
9 * Christophe Massiot <massiot@via.ecp.fr>
10 * Gildas Bazin <gbazin@videolan.org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 /*****************************************************************************
28 * Preamble
29 *****************************************************************************/
30 #ifdef HAVE_CONFIG_H
31 # include "config.h"
32 #endif
34 #include <vlc_common.h>
35 #include <vlc_plugin.h>
36 #include <vlc_codec.h>
37 #include <vlc_aout.h>
38 #include <vlc_modules.h>
39 #include <assert.h>
41 #include <vlc_block_helper.h>
43 /*****************************************************************************
44 * decoder_sys_t : decoder descriptor
45 *****************************************************************************/
46 struct decoder_sys_t
48 /* Module mode */
49 bool b_packetizer;
52 * Input properties
54 int i_state;
56 block_bytestream_t bytestream;
59 * Common properties
61 date_t end_date;
62 unsigned int i_current_layer;
64 mtime_t i_pts;
66 int i_frame_size, i_free_frame_size;
67 unsigned int i_channels_conf, i_channels;
68 unsigned int i_rate, i_max_frame_size, i_frame_length;
69 unsigned int i_layer, i_bit_rate;
71 bool b_discontinuity;
74 enum {
76 STATE_NOSYNC,
77 STATE_SYNC,
78 STATE_HEADER,
79 STATE_NEXT_SYNC,
80 STATE_GET_DATA,
81 STATE_SEND_DATA
84 /* This isn't the place to put mad-specific stuff. However, it makes the
85 * mad plug-in's life much easier if we put 8 extra bytes at the end of the
86 * buffer, because that way it doesn't have to copy the aout_buffer_t to a
87 * bigger buffer. This has no implication on other plug-ins, and we only
88 * lose 8 bytes per frame. --Meuuh */
89 #define MAD_BUFFER_GUARD 8
90 #define MPGA_HEADER_SIZE 4
92 /****************************************************************************
93 * Local prototypes
94 ****************************************************************************/
95 static int OpenDecoder ( vlc_object_t * );
96 static int OpenPacketizer( vlc_object_t * );
97 static void CloseDecoder ( vlc_object_t * );
98 static void *DecodeBlock ( decoder_t *, block_t ** );
100 static uint8_t *GetOutBuffer ( decoder_t *, block_t ** );
101 static aout_buffer_t *GetAoutBuffer( decoder_t * );
102 static block_t *GetSoutBuffer( decoder_t * );
104 static int SyncInfo( uint32_t i_header, unsigned int * pi_channels,
105 unsigned int * pi_channels_conf,
106 unsigned int * pi_sample_rate, unsigned int * pi_bit_rate,
107 unsigned int * pi_frame_length,
108 unsigned int * pi_max_frame_size,
109 unsigned int * pi_layer );
111 /*****************************************************************************
112 * Module descriptor
113 *****************************************************************************/
114 vlc_module_begin ()
115 set_description( N_("MPEG audio layer I/II/III decoder") )
116 set_category( CAT_INPUT )
117 set_subcategory( SUBCAT_INPUT_ACODEC )
118 #if defined(UNDER_CE)
119 set_capability( "decoder", 5 )
120 #else
121 set_capability( "decoder", 100 )
122 #endif
123 set_callbacks( OpenDecoder, CloseDecoder )
125 add_submodule ()
126 set_description( N_("MPEG audio layer I/II/III packetizer") )
127 set_capability( "packetizer", 10 )
128 set_callbacks( OpenPacketizer, CloseDecoder )
129 vlc_module_end ()
131 /*****************************************************************************
132 * Open: probe the decoder and return score
133 *****************************************************************************/
134 static int Open( vlc_object_t *p_this )
136 decoder_t *p_dec = (decoder_t*)p_this;
137 decoder_sys_t *p_sys;
139 if( p_dec->fmt_in.i_codec != VLC_CODEC_MPGA )
141 return VLC_EGENERIC;
144 /* Allocate the memory needed to store the decoder's structure */
145 if( ( p_dec->p_sys = p_sys =
146 (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
147 return VLC_ENOMEM;
149 /* Misc init */
150 p_sys->b_packetizer = false;
151 p_sys->i_state = STATE_NOSYNC;
152 date_Set( &p_sys->end_date, 0 );
153 p_sys->bytestream = block_BytestreamInit();
154 p_sys->i_pts = VLC_TS_INVALID;
155 p_sys->b_discontinuity = false;
157 /* Set output properties */
158 p_dec->fmt_out.i_cat = AUDIO_ES;
159 p_dec->fmt_out.i_codec = VLC_CODEC_MPGA;
160 p_dec->fmt_out.audio.i_rate = 0; /* So end_date gets initialized */
162 /* Set callback */
163 p_dec->pf_decode_audio = (aout_buffer_t *(*)(decoder_t *, block_t **))
164 DecodeBlock;
165 p_dec->pf_packetize = (block_t *(*)(decoder_t *, block_t **))
166 DecodeBlock;
168 /* Start with the minimum size for a free bitrate frame */
169 p_sys->i_free_frame_size = MPGA_HEADER_SIZE;
171 return VLC_SUCCESS;
174 static int OpenDecoder( vlc_object_t *p_this )
176 /* HACK: Don't use this codec if we don't have an mpga audio filter */
177 if( !module_exists( "mpgatofixed32" ) )
178 return VLC_EGENERIC;
180 return Open( p_this );
183 static int OpenPacketizer( vlc_object_t *p_this )
185 decoder_t *p_dec = (decoder_t*)p_this;
187 int i_ret = Open( p_this );
189 if( i_ret == VLC_SUCCESS ) p_dec->p_sys->b_packetizer = true;
191 return i_ret;
194 /****************************************************************************
195 * DecodeBlock: the whole thing
196 ****************************************************************************
197 * This function is called just after the thread is launched.
198 ****************************************************************************/
199 static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
201 decoder_sys_t *p_sys = p_dec->p_sys;
202 uint8_t p_header[MAD_BUFFER_GUARD];
203 uint32_t i_header;
204 uint8_t *p_buf;
205 block_t *p_out_buffer;
207 if( !pp_block || !*pp_block ) return NULL;
209 if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
211 if( (*pp_block)->i_flags&BLOCK_FLAG_CORRUPTED )
213 p_sys->i_state = STATE_NOSYNC;
214 block_BytestreamEmpty( &p_sys->bytestream );
216 date_Set( &p_sys->end_date, 0 );
217 block_Release( *pp_block );
218 p_sys->b_discontinuity = true;
219 return NULL;
222 if( !date_Get( &p_sys->end_date ) && (*pp_block)->i_pts <= VLC_TS_INVALID )
224 /* We've just started the stream, wait for the first PTS. */
225 msg_Dbg( p_dec, "waiting for PTS" );
226 block_Release( *pp_block );
227 return NULL;
230 block_BytestreamPush( &p_sys->bytestream, *pp_block );
232 while( 1 )
234 switch( p_sys->i_state )
237 case STATE_NOSYNC:
238 while( block_PeekBytes( &p_sys->bytestream, p_header, 2 )
239 == VLC_SUCCESS )
241 /* Look for sync word - should be 0xffe */
242 if( p_header[0] == 0xff && (p_header[1] & 0xe0) == 0xe0 )
244 p_sys->i_state = STATE_SYNC;
245 break;
247 block_SkipByte( &p_sys->bytestream );
249 if( p_sys->i_state != STATE_SYNC )
251 block_BytestreamFlush( &p_sys->bytestream );
253 /* Need more data */
254 return NULL;
257 case STATE_SYNC:
258 /* New frame, set the Presentation Time Stamp */
259 p_sys->i_pts = p_sys->bytestream.p_block->i_pts;
260 if( p_sys->i_pts > VLC_TS_INVALID &&
261 p_sys->i_pts != date_Get( &p_sys->end_date ) )
263 date_Set( &p_sys->end_date, p_sys->i_pts );
265 p_sys->i_state = STATE_HEADER;
267 case STATE_HEADER:
268 /* Get MPGA frame header (MPGA_HEADER_SIZE bytes) */
269 if( block_PeekBytes( &p_sys->bytestream, p_header,
270 MPGA_HEADER_SIZE ) != VLC_SUCCESS )
272 /* Need more data */
273 return NULL;
276 /* Build frame header */
277 i_header = (p_header[0]<<24)|(p_header[1]<<16)|(p_header[2]<<8)
278 |p_header[3];
280 /* Check if frame is valid and get frame info */
281 p_sys->i_frame_size = SyncInfo( i_header,
282 &p_sys->i_channels,
283 &p_sys->i_channels_conf,
284 &p_sys->i_rate,
285 &p_sys->i_bit_rate,
286 &p_sys->i_frame_length,
287 &p_sys->i_max_frame_size,
288 &p_sys->i_layer );
290 p_dec->fmt_in.i_profile = p_sys->i_layer;
292 if( p_sys->i_frame_size == -1 )
294 msg_Dbg( p_dec, "emulated startcode" );
295 block_SkipByte( &p_sys->bytestream );
296 p_sys->i_state = STATE_NOSYNC;
297 p_sys->b_discontinuity = true;
298 break;
301 if( p_sys->i_bit_rate == 0 )
303 /* Free bitrate, but 99% emulated startcode :( */
304 if( p_dec->p_sys->i_free_frame_size == MPGA_HEADER_SIZE )
306 msg_Dbg( p_dec, "free bitrate mode");
308 /* The -1 below is to account for the frame padding */
309 p_sys->i_frame_size = p_sys->i_free_frame_size - 1;
312 p_sys->i_state = STATE_NEXT_SYNC;
314 case STATE_NEXT_SYNC:
315 /* TODO: If p_block == NULL, flush the buffer without checking the
316 * next sync word */
318 /* Check if next expected frame contains the sync word */
319 if( block_PeekOffsetBytes( &p_sys->bytestream,
320 p_sys->i_frame_size, p_header,
321 MAD_BUFFER_GUARD ) != VLC_SUCCESS )
323 /* Need more data */
324 return NULL;
327 if( p_header[0] == 0xff && (p_header[1] & 0xe0) == 0xe0 )
329 /* Startcode is fine, let's try the header as an extra check */
330 int i_next_frame_size;
331 unsigned int i_next_channels, i_next_channels_conf;
332 unsigned int i_next_rate, i_next_bit_rate;
333 unsigned int i_next_frame_length, i_next_max_frame_size;
334 unsigned int i_next_layer;
336 /* Build frame header */
337 i_header = (p_header[0]<<24)|(p_header[1]<<16)|(p_header[2]<<8)
338 |p_header[3];
340 i_next_frame_size = SyncInfo( i_header,
341 &i_next_channels,
342 &i_next_channels_conf,
343 &i_next_rate,
344 &i_next_bit_rate,
345 &i_next_frame_length,
346 &i_next_max_frame_size,
347 &i_next_layer );
349 /* Free bitrate only */
350 if( p_sys->i_bit_rate == 0 && i_next_frame_size == -1 )
352 if( (unsigned int)p_sys->i_frame_size >
353 p_sys->i_max_frame_size )
355 msg_Dbg( p_dec, "frame too big %d > %d "
356 "(emulated startcode ?)", p_sys->i_frame_size,
357 p_sys->i_max_frame_size );
358 block_SkipByte( &p_sys->bytestream );
359 p_sys->i_state = STATE_NOSYNC;
360 p_sys->i_free_frame_size = MPGA_HEADER_SIZE;
361 break;
364 p_sys->i_frame_size++;
365 break;
368 if( i_next_frame_size == -1 )
370 msg_Dbg( p_dec, "emulated startcode on next frame" );
371 block_SkipByte( &p_sys->bytestream );
372 p_sys->i_state = STATE_NOSYNC;
373 p_sys->b_discontinuity = true;
374 break;
377 /* Check info is in sync with previous one */
378 if( i_next_channels_conf != p_sys->i_channels_conf ||
379 i_next_rate != p_sys->i_rate ||
380 i_next_layer != p_sys->i_layer ||
381 i_next_frame_length != p_sys->i_frame_length )
383 /* Free bitrate only */
384 if( p_sys->i_bit_rate == 0 )
386 p_sys->i_frame_size++;
387 break;
390 msg_Dbg( p_dec, "parameters changed unexpectedly "
391 "(emulated startcode ?)" );
392 block_SkipByte( &p_sys->bytestream );
393 p_sys->i_state = STATE_NOSYNC;
394 break;
397 /* Free bitrate only */
398 if( p_sys->i_bit_rate == 0 )
400 if( i_next_bit_rate != 0 )
402 p_sys->i_frame_size++;
403 break;
408 else
410 /* Free bitrate only */
411 if( p_sys->i_bit_rate == 0 )
413 if( (unsigned int)p_sys->i_frame_size >
414 p_sys->i_max_frame_size )
416 msg_Dbg( p_dec, "frame too big %d > %d "
417 "(emulated startcode ?)", p_sys->i_frame_size,
418 p_sys->i_max_frame_size );
419 block_SkipByte( &p_sys->bytestream );
420 p_sys->i_state = STATE_NOSYNC;
421 p_sys->i_free_frame_size = MPGA_HEADER_SIZE;
422 break;
425 p_sys->i_frame_size++;
426 break;
429 msg_Dbg( p_dec, "emulated startcode "
430 "(no startcode on following frame)" );
431 p_sys->i_state = STATE_NOSYNC;
432 block_SkipByte( &p_sys->bytestream );
433 break;
436 p_sys->i_state = STATE_SEND_DATA;
437 break;
439 case STATE_GET_DATA:
440 /* Make sure we have enough data.
441 * (Not useful if we went through NEXT_SYNC) */
442 if( block_WaitBytes( &p_sys->bytestream,
443 p_sys->i_frame_size ) != VLC_SUCCESS )
445 /* Need more data */
446 return NULL;
448 p_sys->i_state = STATE_SEND_DATA;
450 case STATE_SEND_DATA:
451 if( !(p_buf = GetOutBuffer( p_dec, &p_out_buffer )) )
453 //p_dec->b_error = true;
454 return NULL;
457 /* Free bitrate only */
458 if( p_sys->i_bit_rate == 0 )
460 p_sys->i_free_frame_size = p_sys->i_frame_size;
463 /* Copy the whole frame into the buffer. When we reach this point
464 * we already know we have enough data available. */
465 block_GetBytes( &p_sys->bytestream,
466 p_buf, __MIN( (unsigned)p_sys->i_frame_size, p_out_buffer->i_buffer ) );
468 /* Get beginning of next frame for libmad */
469 if( !p_sys->b_packetizer )
471 assert( p_out_buffer->i_buffer >= (unsigned)p_sys->i_frame_size + MAD_BUFFER_GUARD );
472 memcpy( p_buf + p_sys->i_frame_size,
473 p_header, MAD_BUFFER_GUARD );
476 p_sys->i_state = STATE_NOSYNC;
478 /* Make sure we don't reuse the same pts twice */
479 if( p_sys->i_pts == p_sys->bytestream.p_block->i_pts )
480 p_sys->i_pts = p_sys->bytestream.p_block->i_pts = VLC_TS_INVALID;
482 /* So p_block doesn't get re-added several times */
483 *pp_block = block_BytestreamPop( &p_sys->bytestream );
485 return p_out_buffer;
489 return NULL;
492 /*****************************************************************************
493 * GetOutBuffer:
494 *****************************************************************************/
495 static uint8_t *GetOutBuffer( decoder_t *p_dec, block_t **pp_out_buffer )
497 decoder_sys_t *p_sys = p_dec->p_sys;
498 uint8_t *p_buf;
500 if( p_dec->fmt_out.audio.i_rate != p_sys->i_rate )
502 msg_Dbg( p_dec, "MPGA channels:%d samplerate:%d bitrate:%d",
503 p_sys->i_channels, p_sys->i_rate, p_sys->i_bit_rate );
505 date_Init( &p_sys->end_date, p_sys->i_rate, 1 );
506 date_Set( &p_sys->end_date, p_sys->i_pts );
509 p_dec->fmt_out.audio.i_rate = p_sys->i_rate;
510 p_dec->fmt_out.audio.i_channels = p_sys->i_channels;
511 p_dec->fmt_out.audio.i_frame_length = p_sys->i_frame_length;
512 p_dec->fmt_out.audio.i_bytes_per_frame =
513 p_sys->i_max_frame_size + MAD_BUFFER_GUARD;
515 p_dec->fmt_out.audio.i_original_channels = p_sys->i_channels_conf;
516 p_dec->fmt_out.audio.i_physical_channels =
517 p_sys->i_channels_conf & AOUT_CHAN_PHYSMASK;
519 p_dec->fmt_out.i_bitrate = p_sys->i_bit_rate * 1000;
521 if( p_sys->b_packetizer )
523 block_t *p_sout_buffer = GetSoutBuffer( p_dec );
524 p_buf = p_sout_buffer ? p_sout_buffer->p_buffer : NULL;
525 *pp_out_buffer = p_sout_buffer;
527 else
529 aout_buffer_t *p_aout_buffer = GetAoutBuffer( p_dec );
530 p_buf = p_aout_buffer ? p_aout_buffer->p_buffer : NULL;
531 *pp_out_buffer = p_aout_buffer;
534 return p_buf;
537 /*****************************************************************************
538 * GetAoutBuffer:
539 *****************************************************************************/
540 static aout_buffer_t *GetAoutBuffer( decoder_t *p_dec )
542 decoder_sys_t *p_sys = p_dec->p_sys;
543 aout_buffer_t *p_buf;
545 p_buf = decoder_NewAudioBuffer( p_dec, p_sys->i_frame_length );
546 if( p_buf == NULL ) return NULL;
548 p_buf->i_pts = date_Get( &p_sys->end_date );
549 p_buf->i_length = date_Increment( &p_sys->end_date, p_sys->i_frame_length )
550 - p_buf->i_pts;
551 if( p_sys->b_discontinuity )
552 p_buf->i_flags |= BLOCK_FLAG_DISCONTINUITY;
553 p_sys->b_discontinuity = false;
555 /* Hack for libmad filter */
556 p_buf = block_Realloc( p_buf, 0, p_sys->i_frame_size + MAD_BUFFER_GUARD );
558 return p_buf;
561 /*****************************************************************************
562 * GetSoutBuffer:
563 *****************************************************************************/
564 static block_t *GetSoutBuffer( decoder_t *p_dec )
566 decoder_sys_t *p_sys = p_dec->p_sys;
567 block_t *p_block;
569 p_block = block_New( p_dec, p_sys->i_frame_size );
570 if( p_block == NULL ) return NULL;
572 p_block->i_pts = p_block->i_dts = date_Get( &p_sys->end_date );
574 p_block->i_length =
575 date_Increment( &p_sys->end_date, p_sys->i_frame_length ) - p_block->i_pts;
577 return p_block;
580 /*****************************************************************************
581 * CloseDecoder: clean up the decoder
582 *****************************************************************************/
583 static void CloseDecoder( vlc_object_t *p_this )
585 decoder_t *p_dec = (decoder_t *)p_this;
586 decoder_sys_t *p_sys = p_dec->p_sys;
588 block_BytestreamRelease( &p_sys->bytestream );
590 free( p_sys );
593 /*****************************************************************************
594 * SyncInfo: parse MPEG audio sync info
595 *****************************************************************************/
596 static int SyncInfo( uint32_t i_header, unsigned int * pi_channels,
597 unsigned int * pi_channels_conf,
598 unsigned int * pi_sample_rate, unsigned int * pi_bit_rate,
599 unsigned int * pi_frame_length,
600 unsigned int * pi_max_frame_size, unsigned int * pi_layer)
602 static const int ppi_bitrate[2][3][16] =
605 /* v1 l1 */
606 { 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384,
607 416, 448, 0},
608 /* v1 l2 */
609 { 0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256,
610 320, 384, 0},
611 /* v1 l3 */
612 { 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224,
613 256, 320, 0}
617 /* v2 l1 */
618 { 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192,
619 224, 256, 0},
620 /* v2 l2 */
621 { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128,
622 144, 160, 0},
623 /* v2 l3 */
624 { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128,
625 144, 160, 0}
629 static const int ppi_samplerate[2][4] = /* version 1 then 2 */
631 { 44100, 48000, 32000, 0 },
632 { 22050, 24000, 16000, 0 }
635 int i_version, i_mode, i_emphasis;
636 bool b_padding, b_mpeg_2_5, b_crc;
637 int i_frame_size = 0;
638 int i_bitrate_index, i_samplerate_index;
639 int i_max_bit_rate;
641 b_mpeg_2_5 = 1 - ((i_header & 0x100000) >> 20);
642 i_version = 1 - ((i_header & 0x80000) >> 19);
643 *pi_layer = 4 - ((i_header & 0x60000) >> 17);
644 b_crc = !((i_header >> 16) & 0x01);
645 i_bitrate_index = (i_header & 0xf000) >> 12;
646 i_samplerate_index = (i_header & 0xc00) >> 10;
647 b_padding = (i_header & 0x200) >> 9;
648 /* Extension */
649 i_mode = (i_header & 0xc0) >> 6;
650 /* Modeext, copyright & original */
651 i_emphasis = i_header & 0x3;
653 if( *pi_layer != 4 &&
654 i_bitrate_index < 0x0f &&
655 i_samplerate_index != 0x03 &&
656 i_emphasis != 0x02 )
658 switch ( i_mode )
660 case 0: /* stereo */
661 case 1: /* joint stereo */
662 *pi_channels = 2;
663 *pi_channels_conf = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
664 break;
665 case 2: /* dual-mono */
666 *pi_channels = 2;
667 *pi_channels_conf = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT
668 | AOUT_CHAN_DUALMONO;
669 break;
670 case 3: /* mono */
671 *pi_channels = 1;
672 *pi_channels_conf = AOUT_CHAN_CENTER;
673 break;
675 *pi_bit_rate = ppi_bitrate[i_version][*pi_layer-1][i_bitrate_index];
676 i_max_bit_rate = ppi_bitrate[i_version][*pi_layer-1][14];
677 *pi_sample_rate = ppi_samplerate[i_version][i_samplerate_index];
679 if ( b_mpeg_2_5 )
681 *pi_sample_rate >>= 1;
684 switch( *pi_layer )
686 case 1:
687 i_frame_size = ( 12000 * *pi_bit_rate / *pi_sample_rate +
688 b_padding ) * 4;
689 *pi_max_frame_size = ( 12000 * i_max_bit_rate /
690 *pi_sample_rate + 1 ) * 4;
691 *pi_frame_length = 384;
692 break;
694 case 2:
695 i_frame_size = 144000 * *pi_bit_rate / *pi_sample_rate + b_padding;
696 *pi_max_frame_size = 144000 * i_max_bit_rate / *pi_sample_rate + 1;
697 *pi_frame_length = 1152;
698 break;
700 case 3:
701 i_frame_size = ( i_version ? 72000 : 144000 ) *
702 *pi_bit_rate / *pi_sample_rate + b_padding;
703 *pi_max_frame_size = ( i_version ? 72000 : 144000 ) *
704 i_max_bit_rate / *pi_sample_rate + 1;
705 *pi_frame_length = i_version ? 576 : 1152;
706 break;
708 default:
709 break;
712 /* Free bitrate mode can support higher bitrates */
713 if( !*pi_bit_rate ) *pi_max_frame_size *= 2;
715 else
717 return -1;
720 return i_frame_size;