Commit bf48c33d authored by Laurent Aimar's avatar Laurent Aimar
Browse files

Added a b_discontinuity to aout_buffer_t for non-pcm streams.

Set aout_buffer_t.b_discontinuity in mpeg audio packetizer.
Silent first 3 frames on discontinuity in mad decoder.
(close #590)
parent 1fc3e360
......@@ -144,6 +144,7 @@ struct aout_buffer_t
size_t i_size, i_nb_bytes;
unsigned int i_nb_samples;
mtime_t start_date, end_date;
vlc_bool_t b_discontinuity; /* Set on discontinuity (for non pcm stream) */
struct aout_buffer_t * p_next;
......@@ -155,12 +156,12 @@ struct aout_buffer_t
void (*pf_release)( aout_buffer_t * );
};
#define aout_BufferFree( p_buffer ) \
#define aout_BufferFree( p_buffer ) do { \
if( p_buffer != NULL && (p_buffer)->i_alloc_type == AOUT_ALLOC_HEAP ) \
{ \
free( p_buffer ); \
} \
p_buffer = NULL;
p_buffer = NULL; } while(0)
/* Size of a frame for S/PDIF output. */
#define AOUT_SPDIF_SIZE 6144
......
......@@ -54,8 +54,10 @@ static block_t *Convert( filter_t *, block_t * );
struct filter_sys_t
{
struct mad_stream mad_stream;
struct mad_frame mad_frame;
struct mad_synth mad_synth;
struct mad_frame mad_frame;
struct mad_synth mad_synth;
int i_reject_count;
};
/*****************************************************************************
......@@ -109,6 +111,7 @@ static int Create( vlc_object_t *p_this )
mad_frame_init( &p_sys->mad_frame );
mad_synth_init( &p_sys->mad_synth );
mad_stream_options( &p_sys->mad_stream, MAD_OPTION_IGNORECRC );
p_sys->i_reject_count = 0;
p_filter->pf_do_work = DoWork;
p_filter->b_in_place = 0;
......@@ -135,6 +138,15 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
{
msg_Dbg( p_aout, "libmad error: %s",
mad_stream_errorstr( &p_sys->mad_stream ) );
p_sys->i_reject_count = 3;
}
else if( p_in_buf->b_discontinuity )
{
p_sys->i_reject_count = 3;
}
if( p_sys->i_reject_count > 0 )
{
if( p_filter->output.i_format == VLC_FOURCC('f','l','3','2') )
{
int i;
......@@ -148,9 +160,11 @@ static void DoWork( aout_instance_t * p_aout, aout_filter_t * p_filter,
{
memset( p_out_buf->p_buffer, 0, p_out_buf->i_nb_bytes );
}
p_sys->i_reject_count--;
return;
}
mad_synth_frame( &p_sys->mad_synth, &p_sys->mad_frame );
if ( p_filter->output.i_format == VLC_FOURCC('f','i','3','2') )
......
......@@ -60,6 +60,8 @@ struct decoder_sys_t
unsigned int i_channels_conf, i_channels;
unsigned int i_rate, i_max_frame_size, i_frame_length;
unsigned int i_layer, i_bit_rate;
vlc_bool_t b_discontinuity;
};
enum {
......@@ -152,6 +154,7 @@ static int OpenDecoder( vlc_object_t *p_this )
p_sys->i_state = STATE_NOSYNC;
aout_DateSet( &p_sys->end_date, 0 );
p_sys->bytestream = block_BytestreamInit( p_dec );
p_sys->b_discontinuity = VLC_FALSE;
/* Set output properties */
p_dec->fmt_out.i_cat = AUDIO_ES;
......@@ -205,6 +208,7 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
}
// aout_DateSet( &p_sys->end_date, 0 );
block_Release( *pp_block );
p_sys->b_discontinuity = VLC_TRUE;
return NULL;
}
......@@ -281,6 +285,7 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
msg_Dbg( p_dec, "emulated startcode" );
block_SkipByte( &p_sys->bytestream );
p_sys->i_state = STATE_NOSYNC;
p_sys->b_discontinuity = VLC_TRUE;
break;
}
......@@ -355,6 +360,7 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
msg_Dbg( p_dec, "emulated startcode on next frame" );
block_SkipByte( &p_sys->bytestream );
p_sys->i_state = STATE_NOSYNC;
p_sys->b_discontinuity = VLC_TRUE;
break;
}
......@@ -530,6 +536,8 @@ static aout_buffer_t *GetAoutBuffer( decoder_t *p_dec )
p_buf->start_date = aout_DateGet( &p_sys->end_date );
p_buf->end_date =
aout_DateIncrement( &p_sys->end_date, p_sys->i_frame_length );
p_buf->b_discontinuity = p_sys->b_discontinuity;
p_sys->b_discontinuity = VLC_FALSE;
/* Hack for libmad filter */
p_buf->i_nb_bytes = p_sys->i_frame_size + MAD_BUFFER_GUARD;
......
......@@ -59,6 +59,7 @@
(p_new_buffer)->i_size = i_alloc_size; \
(p_new_buffer)->p_buffer = (byte_t *)(p_new_buffer) \
+ sizeof(aout_buffer_t); \
(p_new_buffer)->b_discontinuity = VLC_FALSE; \
if ( (p_previous_buffer) != NULL ) \
{ \
(p_new_buffer)->start_date = \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment