Commit 70ee5fbf authored by Laurent Aimar's avatar Laurent Aimar

* block: added

    - BLOCK_FLAG_CORRUPTED : signal corrupted data (do not use anymore
 BLOCK_FLAG_DISCONTINUITY in that case)
    - BLOCK_FLAG_PREROLL : mark this block to be decoded (no matter what).
 * ffmpeg, libmpeg2: support BLOCK_FLAG_PREROLL (ie disable frame dropping).
 * input: added ES_OUT_SET_NEXT_DISPLAY_TIME to ease the work for preroll
 (untested).
 * mp4: added support for CTTS table (pts, needed for h264+bframe).
 * decoders: for now handle discontinuity and corrupted block the same way.
parent 26b8ba09
......@@ -68,6 +68,10 @@ typedef struct block_sys_t block_sys_t;
#define BLOCK_FLAG_CLOCK 0x0200
/** This block is scrambled */
#define BLOCK_FLAG_SCRAMBLED 0x0400
/** This block has to be decoded but not be displayed */
#define BLOCK_FLAG_PREROLL 0x0800
/** This block is corrupted and/or there is data loss */
#define BLOCK_FLAG_CORRUPTED 0x1000
#define BLOCK_FLAG_PRIVATE_MASK 0xffff0000
#define BLOCK_FLAG_PRIVATE_SHIFT 16
......
......@@ -59,7 +59,12 @@ enum es_out_query_e
ES_OUT_SET_GROUP, /* arg1= int */
ES_OUT_GET_GROUP, /* arg1= int* */
/* PCR handling, dts/pts will be automatically computed using thoses PCR */
/* PCR handling, dts/pts will be automatically computed using thoses PCR
* XXX: SET_PCR(_GROUP) is in charge of the pace control. They will wait to slow
* down the demuxer to read at the right speed.
* XXX: if you want PREROLL just call RESET_PCR and ES_OUT_SET_NEXT_DISPLAY_TIME and send
* data to the decoder *without* calling SET_PCR until preroll is finished.
*/
ES_OUT_SET_PCR, /* arg1=int64_t i_pcr(microsecond!) (using default group 0)*/
ES_OUT_SET_GROUP_PCR, /* arg1= int i_group, arg2=int64_t i_pcr(microsecond!)*/
ES_OUT_RESET_PCR, /* no arg */
......@@ -69,7 +74,10 @@ enum es_out_query_e
ES_OUT_GET_TS, /* arg1=int64_t i_ts(microsecond!) (using default group 0), arg2=int64_t* converted i_ts */
/* Try not to use this one as it is a bit hacky */
ES_OUT_SET_FMT /* arg1= es_out_id_t* arg2=es_format_t* */
ES_OUT_SET_FMT, /* arg1= es_out_id_t* arg2=es_format_t* */
/* Allow preroll of data (data with dts/pts < i_pts for one ES will be decoded but not displayed */
ES_OUT_SET_NEXT_DISPLAY_TIME, /* arg1=es_out_id_t* arg2=int64_t i_pts(microsecond) */
};
struct es_out_t
......
......@@ -174,7 +174,7 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
return NULL;
}
if( (*pp_block)->i_flags&BLOCK_FLAG_DISCONTINUITY )
if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
{
p_sys->i_state = STATE_NOSYNC;
}
......
......@@ -175,7 +175,7 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
return NULL;
}
if( (*pp_block)->i_flags&BLOCK_FLAG_DISCONTINUITY )
if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
{
p_sys->i_state = STATE_NOSYNC;
}
......
......@@ -181,7 +181,7 @@ static aout_buffer_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
p_block = *pp_block;
if( p_block->i_flags&BLOCK_FLAG_DISCONTINUITY )
if( p_block->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
{
block_Release( p_block );
return NULL;
......
......@@ -209,7 +209,7 @@ aout_buffer_t *E_( DecodeAudio )( decoder_t *p_dec, block_t **pp_block )
return NULL;
}
if( p_block->i_buffer <= 0 || p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
if( p_block->i_buffer <= 0 || ( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) )
{
block_Release( p_block );
return NULL;
......
......@@ -438,7 +438,7 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
p_block = *pp_block;
if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
if( p_block->i_flags & (BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
{
p_sys->i_buffer = 0;
p_sys->i_pts = 0; /* To make sure we recover properly */
......@@ -450,6 +450,14 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
return NULL;
}
if( p_block->i_flags & BLOCK_FLAG_PREROLL )
{
/* Do not care about late frames when prerolling
* TODO avoid decoding of non reference frame
* (ie all B except for H264 where it depends only on nal_ref_idc) */
p_sys->i_late_frames = 0;
}
if( !p_dec->b_pace_control && p_sys->i_late_frames > 0 &&
mdate() - p_sys->i_late_frames_start > I64C(5000000) )
{
......@@ -579,8 +587,9 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
continue;
}
/* Update frame late count*/
if( p_sys->i_pts && p_sys->i_pts <= mdate() )
/* Update frame late count (except when doing preroll) */
if( p_sys->i_pts && p_sys->i_pts <= mdate() &&
!(p_block->i_flags & BLOCK_FLAG_PREROLL) )
{
p_sys->i_late_frames++;
if( p_sys->i_late_frames == 1 )
......@@ -630,6 +639,10 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
{
p_pic->date = p_sys->i_pts;
static int64_t i_old = 0;
msg_Dbg( p_dec, "pts=%lld diff=%lld", p_pic->date, p_pic->date - i_old );
i_old = p_pic->date;
/* interpolate the next PTS */
if( p_sys->p_context->frame_rate > 0 )
{
......@@ -657,6 +670,7 @@ picture_t *E_(DecodeVideo)( decoder_t *p_dec, block_t **pp_block )
else
{
p_dec->pf_vout_buffer_del( p_dec, p_pic );
msg_Dbg( p_dec, "pts=0" );
}
}
......
......@@ -295,7 +295,7 @@ static block_t *PacketizeBlock( decoder_t *p_dec, block_t **pp_block )
aout_DateSet( &p_sys->end_date, (*pp_block)->i_pts );
}
if( (*pp_block)->i_flags&BLOCK_FLAG_DISCONTINUITY )
if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
{
p_sys->i_state = STATE_NOSYNC;
}
......
......@@ -65,6 +65,8 @@ struct decoder_sys_t
* the sequence header ? */
vlc_bool_t b_slice_i; /* intra-slice refresh stream */
vlc_bool_t b_preroll;
/*
* Output properties
*/
......@@ -137,6 +139,7 @@ static int OpenDecoder( vlc_object_t *p_this )
p_sys->b_garbage_pic = 0;
p_sys->b_slice_i = 0;
p_sys->b_skip = 0;
p_sys->b_preroll = VLC_FALSE;
#if defined( __i386__ )
if( p_dec->p_libvlc->i_cpu & CPU_CAPABILITY_MMX )
......@@ -213,7 +216,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
return NULL;
}
if( (p_block->i_flags&BLOCK_FLAG_DISCONTINUITY) &&
if( (p_block->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED)) &&
p_sys->p_synchro &&
p_sys->p_info->sequence &&
p_sys->p_info->sequence->width != (unsigned)-1 )
......@@ -244,6 +247,17 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
}
}
if( p_block->i_flags & BLOCK_FLAG_PREROLL )
{
p_sys->b_preroll = VLC_TRUE;
}
else if( p_sys->b_preroll )
{
p_sys->b_preroll = VLC_FALSE;
/* Reset synchro */
vout_SynchroReset( p_sys->p_synchro );
}
#ifdef PIC_FLAG_PTS
if( p_block->i_pts )
{
......@@ -432,7 +446,7 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
p_sys->p_info->current_picture->nb_fields, i_pts, i_dts,
p_sys->i_current_rate );
if( !p_dec->b_pace_control &&
if( !p_dec->b_pace_control && !p_sys->b_preroll &&
!(p_sys->b_slice_i
&& ((p_sys->p_info->current_picture->flags
& PIC_MASK_CODING_TYPE) == P_CODING_TYPE))
......
......@@ -196,7 +196,7 @@ static void *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
return NULL;
}
if( (*pp_block)->i_flags&BLOCK_FLAG_DISCONTINUITY )
if( (*pp_block)->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) )
{
p_sys->i_state = STATE_NOSYNC;
}
......
......@@ -386,7 +386,7 @@ static void *ProcessPacket( decoder_t *p_dec, ogg_packet *p_oggpacket,
block_t *p_block = *pp_block;
void *p_buf;
if( ( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY ) != 0 )
if( ( p_block->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) != 0 )
{
/* Don't send the the first packet after a discontinuity to
* theora_decode, otherwise we get purple/green display artifacts
......
This diff is collapsed.
......@@ -1420,7 +1420,7 @@ static vlc_bool_t GatherPES( demux_t *p_demux, ts_pid_t *pid, block_t *p_bk )
{
/* Small video artifacts are usually better then
* dropping full frames */
pid->es->p_pes->i_flags |= BLOCK_FLAG_DISCONTINUITY;
pid->es->p_pes->i_flags |= BLOCK_FLAG_CORRUPTED;
}
}
}
......
......@@ -60,6 +60,8 @@ struct decoder_owner_sys_t
{
vlc_bool_t b_own_thread;
int64_t i_preroll_end;
input_thread_t *p_input;
aout_instance_t *p_aout;
......@@ -276,6 +278,11 @@ vlc_bool_t input_DecoderEmpty( decoder_t * p_dec )
return VLC_TRUE;
}
void input_DecoderPreroll( decoder_t *p_dec, int64_t i_preroll_end )
{
p_dec->p_owner->i_preroll_end = i_preroll_end;
}
#if 0
/**
* Create a NULL packet for padding in case of a data loss
......@@ -392,6 +399,7 @@ static decoder_t * CreateDecoder( input_thread_t *p_input,
return NULL;
}
p_dec->p_owner->b_own_thread = VLC_TRUE;
p_dec->p_owner->i_preroll_end = -1;
p_dec->p_owner->p_input = p_input;
p_dec->p_owner->p_aout = NULL;
p_dec->p_owner->p_aout_input = NULL;
......@@ -610,9 +618,21 @@ static int DecoderDecode( decoder_t *p_dec, block_t *p_block )
while( (p_aout_buf = p_dec->pf_decode_audio( p_dec,
&p_packetized_block )) )
{
aout_DecPlay( p_dec->p_owner->p_aout,
p_dec->p_owner->p_aout_input,
p_aout_buf );
/* FIXME the best would be to handle the case start_date < preroll < end_date
* but that's not easy with non raw audio stream */
if( p_dec->p_owner->i_preroll_end > 0 &&
p_aout_buf->start_date < p_dec->p_owner->i_preroll_end )
{
aout_DecDeleteBuffer( p_dec->p_owner->p_aout,
p_dec->p_owner->p_aout_input, p_aout_buf );
}
else
{
p_dec->p_owner->i_preroll_end = -1;
aout_DecPlay( p_dec->p_owner->p_aout,
p_dec->p_owner->p_aout_input,
p_aout_buf );
}
}
p_packetized_block = p_next;
......@@ -621,8 +641,19 @@ static int DecoderDecode( decoder_t *p_dec, block_t *p_block )
}
else while( (p_aout_buf = p_dec->pf_decode_audio( p_dec, &p_block )) )
{
aout_DecPlay( p_dec->p_owner->p_aout,
p_dec->p_owner->p_aout_input, p_aout_buf );
if( p_dec->p_owner->i_preroll_end > 0 &&
p_aout_buf->start_date < p_dec->p_owner->i_preroll_end )
{
aout_DecDeleteBuffer( p_dec->p_owner->p_aout,
p_dec->p_owner->p_aout_input, p_aout_buf );
}
else
{
p_dec->p_owner->i_preroll_end = -1;
aout_DecPlay( p_dec->p_owner->p_aout,
p_dec->p_owner->p_aout_input,
p_aout_buf );
}
}
}
else if( p_dec->fmt_in.i_cat == VIDEO_ES )
......@@ -646,9 +677,18 @@ static int DecoderDecode( decoder_t *p_dec, block_t *p_block )
while( (p_pic = p_dec->pf_decode_video( p_dec,
&p_packetized_block )) )
{
vout_DatePicture( p_dec->p_owner->p_vout, p_pic,
p_pic->date );
vout_DisplayPicture( p_dec->p_owner->p_vout, p_pic );
if( p_dec->p_owner->i_preroll_end > 0 &&
p_pic->date < p_dec->p_owner->i_preroll_end )
{
vout_DestroyPicture( p_dec->p_owner->p_vout, p_pic );
}
else
{
p_dec->p_owner->i_preroll_end = -1;
vout_DatePicture( p_dec->p_owner->p_vout, p_pic,
p_pic->date );
vout_DisplayPicture( p_dec->p_owner->p_vout, p_pic );
}
}
p_packetized_block = p_next;
......@@ -657,8 +697,17 @@ static int DecoderDecode( decoder_t *p_dec, block_t *p_block )
}
else while( (p_pic = p_dec->pf_decode_video( p_dec, &p_block )) )
{
vout_DatePicture( p_dec->p_owner->p_vout, p_pic, p_pic->date );
vout_DisplayPicture( p_dec->p_owner->p_vout, p_pic );
if( p_dec->p_owner->i_preroll_end > 0 &&
p_pic->date < p_dec->p_owner->i_preroll_end )
{
vout_DestroyPicture( p_dec->p_owner->p_vout, p_pic );
}
else
{
p_dec->p_owner->i_preroll_end = -1;
vout_DatePicture( p_dec->p_owner->p_vout, p_pic, p_pic->date );
vout_DisplayPicture( p_dec->p_owner->p_vout, p_pic );
}
}
}
else if( p_dec->fmt_in.i_cat == SPU_ES )
......@@ -667,6 +716,15 @@ static int DecoderDecode( decoder_t *p_dec, block_t *p_block )
subpicture_t *p_spu;
while( (p_spu = p_dec->pf_decode_sub( p_dec, &p_block ) ) )
{
if( p_dec->p_owner->i_preroll_end > 0 &&
p_spu->i_start < p_dec->p_owner->i_preroll_end &&
( p_spu->i_stop <= 0 || p_spu->i_stop <= p_dec->p_owner->i_preroll_end ) )
{
spu_DestroySubpicture( p_dec->p_owner->p_vout->p_spu, p_spu );
continue;
}
p_dec->p_owner->i_preroll_end = -1;
p_vout = vlc_object_find( p_dec, VLC_OBJECT_VOUT, FIND_ANYWHERE );
if( p_vout )
{
......
......@@ -61,6 +61,9 @@ struct es_out_id_t
int i_id;
es_out_pgrm_t *p_pgrm;
/* */
int64_t i_preroll_end;
/* Channel in the track type */
int i_channel;
es_format_t fmt;
......@@ -517,6 +520,8 @@ static es_out_id_t *EsOutAdd( es_out_t *out, es_format_t *fmt )
es->i_id = fmt->i_id;
es->p_pgrm = p_pgrm;
es_format_Copy( &es->fmt, fmt );
es->i_preroll_end = -1;
switch( fmt->i_cat )
{
case AUDIO_ES:
......@@ -601,6 +606,7 @@ static void EsSelect( es_out_t *out, es_out_id_t *es )
}
}
es->i_preroll_end = -1;
es->p_dec = input_DecoderNew( p_input, &es->fmt, VLC_FALSE );
if( es->p_dec == NULL || es->p_pgrm != p_sys->p_pgrm )
return;
......@@ -859,6 +865,18 @@ static int EsOutSend( es_out_t *out, es_out_id_t *es, block_t *p_block )
}
p_block->i_rate = p_input->i_rate;
/* Mark preroll blocks */
if( es->i_preroll_end >= 0 )
{
int64_t i_date = p_block->i_pts;
if( i_date <= 0 )
i_date = p_block->i_dts;
if( i_date < es->i_preroll_end )
p_block->i_flags |= BLOCK_FLAG_PREROLL;
else
es->i_preroll_end = -1;
}
/* TODO handle mute */
if( es->p_dec && ( es->fmt.i_cat != AUDIO_ES ||
......@@ -1169,6 +1187,22 @@ static int EsOutControl( es_out_t *out, int i_query, va_list args )
return VLC_SUCCESS;
}
case ES_OUT_SET_NEXT_DISPLAY_TIME:
{
int64_t i_date;
es = (es_out_id_t*) va_arg( args, es_out_id_t * );
i_date = (int64_t)va_arg( args, int64_t );
if( !es || !es->p_dec )
return VLC_EGENERIC;
es->i_preroll_end = i_date;
input_DecoderPreroll( es->p_dec, i_date );
return VLC_SUCCESS;
}
default:
msg_Err( p_sys->p_input, "unknown query in es_out_Control" );
return VLC_EGENERIC;
......
......@@ -1210,6 +1210,9 @@ static vlc_bool_t Control( input_thread_t *p_input, int i_type,
}
if( f_pos < 0.0 ) f_pos = 0.0;
if( f_pos > 1.0 ) f_pos = 1.0;
/* Reset the decoders states and clock synch (before calling the demuxer */
es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
if( demux2_Control( p_input->input.p_demux, DEMUX_SET_POSITION,
f_pos ) )
{
......@@ -1221,8 +1224,8 @@ static vlc_bool_t Control( input_thread_t *p_input, int i_type,
if( p_input->i_slave > 0 )
SlaveSeek( p_input );
input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
//input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
//es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
b_force_update = VLC_TRUE;
}
break;
......@@ -1246,6 +1249,11 @@ static vlc_bool_t Control( input_thread_t *p_input, int i_type,
i_time += val.i_time;
}
if( i_time < 0 ) i_time = 0;
/* Reset the decoders states and clock synch (before calling the demuxer */
es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
i_ret = demux2_Control( p_input->input.p_demux,
DEMUX_SET_TIME, i_time );
if( i_ret )
......@@ -1272,9 +1280,8 @@ static vlc_bool_t Control( input_thread_t *p_input, int i_type,
if( p_input->i_slave > 0 )
SlaveSeek( p_input );
input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
//input_EsOutDiscontinuity( p_input->p_es_out, VLC_FALSE );
//es_out_Control( p_input->p_es_out, ES_OUT_RESET_PCR );
b_force_update = VLC_TRUE;
}
break;
......
......@@ -110,6 +110,7 @@ void stream_AccessUpdate( stream_t *s );
/* decoder.c FIXME make it public ?*/
void input_DecoderDiscontinuity( decoder_t * p_dec );
vlc_bool_t input_DecoderEmpty( decoder_t * p_dec );
void input_DecoderPreroll( decoder_t *p_dec, int64_t i_preroll_end );
/* es_out.c */
es_out_t *input_EsOutNew( input_thread_t * );
......
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