+ /* Sanity check (seems to be needed for some streams) */
+ if( p_sys->p_ff_pic->pict_type == FF_B_TYPE )
+ {
+ p_sys->b_has_b_frames = true;
+ }
+
+ /* Compute the PTS */
+ mtime_t i_pts = VLC_TS_INVALID;
+ if( p_sys->p_ff_pic->reordered_opaque != INT64_MIN )
+ {
+ mtime_t i_ts = p_sys->p_ff_pic->reordered_opaque >> 1;
+ bool b_dts = p_sys->p_ff_pic->reordered_opaque & 1;
+ if( b_dts )
+ {
+ if( !p_context->has_b_frames ||
+ !p_sys->b_has_b_frames ||
+ !p_sys->p_ff_pic->reference ||
+ p_sys->i_pts <= VLC_TS_INVALID )
+ i_pts = i_ts;
+
+ /* Guess what ? The rules are different for Real Video :( */
+ if( (p_dec->fmt_in.i_codec == VLC_CODEC_RV30 ||
+ p_dec->fmt_in.i_codec == VLC_CODEC_RV40) &&
+ p_sys->b_has_b_frames )
+ {
+ i_pts = VLC_TS_INVALID;
+ if(p_sys->p_ff_pic->reference) i_pts = i_ts;
+ }
+ }
+ else
+ {
+ i_pts = i_ts;
+ }
+ }
+ if( i_pts <= VLC_TS_INVALID )
+ i_pts = p_sys->i_pts;
+
+ /* Interpolate the next PTS */
+ if( i_pts > VLC_TS_INVALID )
+ p_sys->i_pts = i_pts;
+ if( p_sys->i_pts > VLC_TS_INVALID )
+ {
+ /* interpolate the next PTS */
+ if( p_dec->fmt_in.video.i_frame_rate > 0 &&
+ p_dec->fmt_in.video.i_frame_rate_base > 0 )
+ {
+ p_sys->i_pts += INT64_C(1000000) *
+ (2 + p_sys->p_ff_pic->repeat_pict) *
+ p_dec->fmt_in.video.i_frame_rate_base /
+ (2 * p_dec->fmt_in.video.i_frame_rate);
+ }
+ else if( p_context->time_base.den > 0 )
+ {
+ int i_tick = p_context->ticks_per_frame;
+ if( i_tick <= 0 )
+ i_tick = 1;
+
+ p_sys->i_pts += INT64_C(1000000) *
+ (2 + p_sys->p_ff_pic->repeat_pict) *
+ i_tick * p_context->time_base.num /
+ (2 * p_context->time_base.den);
+ }
+ }