/*****************************************************************************
* flac.c: flac packetizer module.
*****************************************************************************
- * Copyright (C) 1999-2001 the VideoLAN team
+ * Copyright (C) 1999-2001 VLC authors and VideoLAN
* $Id$
*
* Authors: Gildas Bazin <gbazin@videolan.org>
* Sigmund Augdal Helberg <dnumgis@videolan.org>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
#include <vlc_block_helper.h>
#include <vlc_bits.h>
+#include "packetizer_helper.h"
/*****************************************************************************
* Module descriptor
unsigned int i_rate, i_channels, i_bits_per_sample;
};
-enum
+static const int pi_channels_maps[9] =
{
- STATE_NOSYNC,
- STATE_SYNC,
- STATE_HEADER,
- STATE_NEXT_SYNC,
- STATE_GET_DATA,
- STATE_SEND_DATA
+ 0,
+ AOUT_CHAN_CENTER,
+ AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT,
+ AOUT_CHAN_CENTER | AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT,
+ AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_REARLEFT
+ | AOUT_CHAN_REARRIGHT,
+ AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
+ | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT,
+ AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
+ | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_LFE,
+ AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER
+ | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT | AOUT_CHAN_MIDDLELEFT
+ | AOUT_CHAN_MIDDLERIGHT,
+ AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER | AOUT_CHAN_REARLEFT
+ | AOUT_CHAN_REARRIGHT | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT
+ | AOUT_CHAN_LFE
};
+
/*****************************************************************************
* Local prototypes
*****************************************************************************/
p_sys->i_state = STATE_NOSYNC;
p_sys->b_stream_info = false;
p_sys->i_pts = VLC_TS_INVALID;
- p_sys->bytestream = block_BytestreamInit();
+ block_BytestreamInit( &p_sys->bytestream );
/* */
es_format_Copy( &p_dec->fmt_out, &p_dec->fmt_in );
while( block_PeekBytes( &p_sys->bytestream, p_header, 2 )
== VLC_SUCCESS )
{
- if( p_header[0] == 0xFF && p_header[1] == 0xF8 )
+ if( p_header[0] == 0xFF && (p_header[1] & 0xFE) == 0xF8 )
{
p_sys->i_state = STATE_SYNC;
break;
MAX_FLAC_HEADER_SIZE )
== VLC_SUCCESS )
{
- if( p_header[0] == 0xFF && p_header[1] == 0xF8 )
+ if( p_header[0] == 0xFF && (p_header[1] & 0xFE) == 0xF8 )
{
/* Check if frame is valid and get frame info */
int i_frame_length =
}
case STATE_SEND_DATA:
- p_sout_block = block_New( p_dec, p_sys->i_frame_size );
+ p_sout_block = block_Alloc( p_sys->i_frame_size );
/* Copy the whole frame into the buffer. When we reach this point
* we already know we have enough data available. */
if( p_sys->i_pts == p_sys->bytestream.p_block->i_pts )
p_sys->i_pts = p_sys->bytestream.p_block->i_pts = VLC_TS_INVALID;
+ p_dec->fmt_out.audio.i_channels = p_sys->i_channels;
+ p_dec->fmt_out.audio.i_physical_channels =
+ p_dec->fmt_out.audio.i_original_channels =
+ pi_channels_maps[p_sys->stream_info.channels];
+
/* So p_block doesn't get re-added several times */
*pp_block = block_BytestreamPop( &p_sys->bytestream );
int i_header, i_temp, i_read;
unsigned i_blocksize = 0;
int i_blocksize_hint = 0, i_sample_rate_hint = 0;
- uint64_t i_sample_number = 0;
-
- bool b_variable_blocksize = ( p_sys->b_stream_info &&
- p_sys->stream_info.min_blocksize != p_sys->stream_info.max_blocksize );
- bool b_fixed_blocksize = ( p_sys->b_stream_info &&
- p_sys->stream_info.min_blocksize == p_sys->stream_info.max_blocksize );
/* Check syncword */
- if( p_buf[0] != 0xFF || p_buf[1] != 0xF8 ) return 0;
+ if( p_buf[0] != 0xFF || (p_buf[1] & 0xFE) != 0xF8 ) return 0;
/* Check there is no emulated sync code in the rest of the header */
if( p_buf[2] == 0xff || p_buf[3] == 0xFF ) return 0;
switch( i_temp = p_buf[2] >> 4 )
{
case 0:
- if( b_fixed_blocksize )
+ if( p_sys->b_stream_info &&
+ p_sys->stream_info.min_blocksize == p_sys->stream_info.max_blocksize )
i_blocksize = p_sys->stream_info.min_blocksize;
else return 0; /* We can't do anything with this */
break;
i_blocksize = 256 << (i_temp - 8);
break;
}
+ if( p_sys->b_stream_info &&
+ ( i_blocksize < p_sys->stream_info.min_blocksize ||
+ i_blocksize > p_sys->stream_info.max_blocksize ) )
+ return 0;
/* Find samplerate */
switch( i_temp = p_buf[2] & 0x0f )
/* End of fixed size header */
i_header = 4;
- /* Find Sample/Frame number */
- if( i_blocksize_hint && b_variable_blocksize )
- {
- i_sample_number = read_utf8( &p_buf[i_header++], &i_read );
- if( i_sample_number == INT64_C(0xffffffffffffffff) ) return 0;
- }
- else
- {
- i_sample_number = read_utf8( &p_buf[i_header++], &i_read );
- if( i_sample_number == INT64_C(0xffffffffffffffff) ) return 0;
-
- if( p_sys->b_stream_info )
- i_sample_number *= p_sys->stream_info.min_blocksize;
- }
+ /* Check Sample/Frame number */
+ if( read_utf8( &p_buf[i_header++], &i_read ) == INT64_C(0xffffffffffffffff) )
+ return 0;
i_header += i_read;