Commit b19614ae authored by Sébastien Escudier's avatar Sébastien Escudier

avformat : fix overflow in timestamp computation

parent b7d96d26
......@@ -609,17 +609,37 @@ static int Demux( demux_t *p_demux )
if( pkt.flags & AV_PKT_FLAG_KEY )
p_frame->i_flags |= BLOCK_FLAG_TYPE_I;
i_start_time = ( p_sys->ic->start_time != (int64_t)AV_NOPTS_VALUE ) ?
( p_sys->ic->start_time * 1000000 / AV_TIME_BASE ) : 0;
p_frame->i_dts = ( pkt.dts == (int64_t)AV_NOPTS_VALUE ) ?
VLC_TS_INVALID : (pkt.dts) * 1000000 *
p_stream->time_base.num /
p_stream->time_base.den - i_start_time + VLC_TS_0;
p_frame->i_pts = ( pkt.pts == (int64_t)AV_NOPTS_VALUE ) ?
VLC_TS_INVALID : (pkt.pts) * 1000000 *
p_stream->time_base.num /
p_stream->time_base.den - i_start_time + VLC_TS_0;
/* Used to avoid timestamps overlow */
lldiv_t q;
if( p_sys->ic->start_time != (int64_t)AV_NOPTS_VALUE )
{
q = lldiv( p_sys->ic->start_time, AV_TIME_BASE);
i_start_time = q.quot * (int64_t)1000000 + q.rem * (int64_t)1000000 / AV_TIME_BASE;
}
else
i_start_time = 0;
if( pkt.dts == (int64_t)AV_NOPTS_VALUE )
p_frame->i_dts = VLC_TS_INVALID;
else
{
q = lldiv( pkt.dts, p_stream->time_base.den );
p_frame->i_dts = q.quot * (int64_t)1000000 *
p_stream->time_base.num + q.rem * (int64_t)1000000 *
p_stream->time_base.num /
p_stream->time_base.den - i_start_time + VLC_TS_0;
}
if( pkt.pts == (int64_t)AV_NOPTS_VALUE )
p_frame->i_pts = VLC_TS_INVALID;
else
{
q = lldiv( pkt.pts, p_stream->time_base.den );
p_frame->i_pts = q.quot * (int64_t)1000000 *
p_stream->time_base.num + q.rem * (int64_t)1000000 *
p_stream->time_base.num /
p_stream->time_base.den - i_start_time + VLC_TS_0;
}
if( pkt.duration > 0 && p_frame->i_length <= 0 )
p_frame->i_length = pkt.duration * 1000000 *
p_stream->time_base.num /
......
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