- if( p_sys->b_frame_slice && ( p_frag->p_buffer[3] == 0x00 || p_frag->p_buffer[3] > 0xaf ) )
- {
- /* We have a complete picture output it */
- if( p_sys->p_seq == NULL )
- {
- msg_Dbg( p_dec, "waiting sequence start" );
- block_ChainRelease( p_sys->p_frame );
- }
- else if( p_sys->i_dts <= 0 && p_sys->i_pts <= 0 && p_sys->i_interpolated_dts <= 0 )
- {
- msg_Dbg( p_dec, "need a starting pts/dts" );
- block_ChainRelease( p_sys->p_frame );
- }
- else if( p_sys->b_frame_corrupted )
- {
- msg_Warn( p_dec, "trashing a corrupted picture" );
- block_ChainRelease( p_sys->p_frame );
- p_sys->b_frame_corrupted = VLC_FALSE;
- }
- else
- {
- block_t *p_pic = block_ChainGather( p_sys->p_frame );
- mtime_t i_duration = (mtime_t)( 1000000 * p_sys->i_frame_rate_base / p_sys->i_frame_rate);
-
- if( !p_sys->b_seq_progressive && p_sys->i_picture_structure != 0x03 )
- {
- i_duration /= 2;
- }
-
- if( p_sys->b_seq_progressive )
- {
- if( p_sys->i_top_field_first == 0 && p_sys->i_repeat_first_field == 1 )
- {
- i_duration *= 2;
- }
- else if( p_sys->i_top_field_first == 1 && p_sys->i_repeat_first_field == 1 )
- {
- i_duration *= 3;
- }
- }
- else
- {
- if( p_sys->i_picture_structure == 0x03 )
- {
- if( p_sys->i_progressive_frame && p_sys->i_repeat_first_field )
- {
- i_duration += i_duration / 2;
- }
- }
- }
-
- if( p_sys->b_low_delay || p_sys->i_picture_type == 0x03 )
- {
- /* Trivial case (DTS == PTS) */
- /* Correct interpolated dts when we receive a new pts/dts */
- if( p_sys->i_pts > 0 ) p_sys->i_interpolated_dts = p_sys->i_pts;
- if( p_sys->i_dts > 0 ) p_sys->i_interpolated_dts = p_sys->i_dts;
- }
- else
- {
- /* Correct interpolated dts when we receive a new pts/dts */
- if( p_sys->i_last_ref_pts > 0 )
- p_sys->i_interpolated_dts = p_sys->i_last_ref_pts;
- if( p_sys->i_dts > 0 ) p_sys->i_interpolated_dts = p_sys->i_dts;
-
- p_sys->i_last_ref_pts = p_sys->i_pts;
- }
-
- p_pic->i_dts = p_sys->i_interpolated_dts;
- /* Set PTS only if I frame or come from stream */
- if( p_sys->i_pts > 0 )
- {
- p_pic->i_pts = p_sys->i_pts;
- }
- else if( p_sys->i_picture_type == 0x03 )
- {
- p_pic->i_pts = p_pic->i_dts;
- }
- else
- {
- p_pic->i_pts = -1;
- }
-
- if( p_sys->b_low_delay || p_sys->i_picture_type == 0x03 )
- {
- /* Trivial case (DTS == PTS) */
- p_sys->i_interpolated_dts += i_duration;
- }
- else
- {
- p_sys->i_interpolated_dts += p_sys->i_old_duration;
- p_sys->i_old_duration = i_duration;
- }
-
- p_pic->i_length = p_sys->i_interpolated_dts - p_pic->i_dts;
-
- //msg_Dbg( p_dec, "pic: type=%d dts=%lld pts-dts=%lld", p_sys->i_picture_type, p_pic->i_dts, p_pic->i_pts - p_pic->i_dts);
-
- block_ChainAppend( &p_chain_out, p_pic );