#include <vlc_block_helper.h>
#include <vlc_bits.h>
+#include "packetizer_helper.h"
/*****************************************************************************
* Module descriptor
date_t end_date;
mtime_t i_pts;
- int i_frame_size, i_frame_length, i_bits_per_sample;
- unsigned int i_rate, i_channels;
-};
-
-enum
-{
- STATE_NOSYNC,
- STATE_SYNC,
- STATE_HEADER,
- STATE_NEXT_SYNC,
- STATE_GET_DATA,
- STATE_SEND_DATA
+ int i_frame_length;
+ size_t i_frame_size;
+ unsigned int i_rate, i_channels, i_bits_per_sample;
};
/*****************************************************************************
static block_t *Packetize( decoder_t *, block_t ** );
static int SyncInfo( decoder_t *, uint8_t *, unsigned int *,
- unsigned int *,int * );
+ unsigned int *, unsigned int * );
static uint64_t read_utf8( const uint8_t *p_buf, int *pi_read );
static uint8_t flac_crc8( const uint8_t *data, unsigned len );
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 );
if( !p_sys->b_stream_info )
ProcessHeader( p_dec );
- if( p_sys->stream_info.channels > 6 )
+ if( p_sys->stream_info.channels > 8 )
{
msg_Err( p_dec, "This stream uses too many audio channels" );
return NULL;
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;
if( p_sys->i_rate != p_dec->fmt_out.audio.i_rate )
{
p_dec->fmt_out.audio.i_rate = p_sys->i_rate;
+ const mtime_t i_end_date = date_Get( &p_sys->end_date );
date_Init( &p_sys->end_date, p_sys->i_rate, 1 );
- date_Set( &p_sys->end_date, p_sys->i_pts );
+ date_Set( &p_sys->end_date, i_end_date );
}
p_sys->i_state = STATE_NEXT_SYNC;
p_sys->i_frame_size = p_sys->b_stream_info && p_sys->stream_info.min_framesize > 0 ?
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 =
static int SyncInfo( decoder_t *p_dec, uint8_t *p_buf,
unsigned int * pi_channels,
unsigned int * pi_sample_rate,
- int * pi_bits_per_sample )
+ unsigned int * pi_bits_per_sample )
{
decoder_sys_t *p_sys = p_dec->p_sys;
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;
if( i_blocksize < p_sys->stream_info.min_blocksize ||
i_blocksize > p_sys->stream_info.max_blocksize )
return 0;
+ if( *pi_bits_per_sample != p_sys->stream_info.bits_per_sample )
+ return 0;
+ if( *pi_sample_rate != p_sys->stream_info.sample_rate )
+ return 0;
}
return i_blocksize;
}