Commit 7ed3e0e4 authored by Pierre Ynard's avatar Pierre Ynard

rtp sout: fix integer overflow

This became likely to happen using VoD. Thanks to Denis Charmet for
pointing out this issue.
parent fbc4d5b8
...@@ -946,9 +946,14 @@ rtp_set_ptime (sout_stream_id_t *id, unsigned ptime_ms, size_t bytes) ...@@ -946,9 +946,14 @@ rtp_set_ptime (sout_stream_id_t *id, unsigned ptime_ms, size_t bytes)
uint32_t rtp_compute_ts( unsigned i_clock_rate, int64_t i_pts ) uint32_t rtp_compute_ts( unsigned i_clock_rate, int64_t i_pts )
{ {
/* NOTE: this plays nice with offsets because the calculations are /* This is an overflow-proof way of doing:
* linear. */ * return i_pts * (int64_t)i_clock_rate / CLOCK_FREQ;
return i_pts * (int64_t)i_clock_rate / CLOCK_FREQ; *
* NOTE: this plays nice with offsets because the (equivalent)
* calculations are linear. */
lldiv_t q = lldiv(i_pts, CLOCK_FREQ);
return q.quot * (int64_t)i_clock_rate
+ q.rem * (int64_t)i_clock_rate / CLOCK_FREQ;
} }
/** Add an ES as a new RTP stream */ /** Add an ES as a new RTP stream */
......
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