<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/19832">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span></span><br></pre><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_rtp_asterisk: Don't use double math to generate timestamps<br><br>Rounding issues with double math were causing rtp timestamp<br>slips in outgoing packets. We're now back to integer math<br>and are getting no more slips.<br><br>ASTERISK-30391<br><br>Change-Id: I6ba992b49ffdf9ebea074581dfa784a188c661a4<br>---<br>M res/res_rtp_asterisk.c<br>1 file changed, 41 insertions(+), 6 deletions(-)<br><br></pre>
<pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c</span><br><span>index da0a3b9..bd4c1f7 100644</span><br><span>--- a/res/res_rtp_asterisk.c</span><br><span>+++ b/res/res_rtp_asterisk.c</span><br><span>@@ -442,6 +442,7 @@</span><br><span> int send_payload;</span><br><span> int send_duration;</span><br><span> unsigned int flags;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct timeval rxcore;</span><br><span> struct timeval txcore;</span><br><span> </span><br><span> struct timeval dtmfmute;</span><br><span>@@ -5496,10 +5497,10 @@</span><br><span> {</span><br><span> int rate = ast_rtp_get_rate(rtp->f.subclass.format);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- double estimated_elapsed;</span><br><span> double jitter = 0.0;</span><br><span> double prev_jitter = 0.0;</span><br><span> struct timeval now;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct timeval tmp;</span><br><span> double rxnow;</span><br><span> double arrival_sec;</span><br><span> unsigned int arrival;</span><br><span>@@ -5512,9 +5513,22 @@</span><br><span> rtp->rxstart = ast_tv2double(&now);</span><br><span> rtp->remote_seed_rx_rtp_ts = rx_rtp_ts;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- /* Round to 0.1ms for nice, pretty timestamps */</span><br><span style="color: hsl(0, 100%, 40%);">- rtp->rxstart = floor( rtp->rxstart * 10000.0 ) / 10000.0;</span><br><span style="color: hsl(0, 100%, 40%);">- *tv = ast_double2tv(rtp->rxstart);</span><br><span style="color: hsl(120, 100%, 40%);">+ /*</span><br><span style="color: hsl(120, 100%, 40%);">+ * "tv" is placed in the received frame's</span><br><span style="color: hsl(120, 100%, 40%);">+ * "delivered" field and when this frame is</span><br><span style="color: hsl(120, 100%, 40%);">+ * sent out again on the other side, it's</span><br><span style="color: hsl(120, 100%, 40%);">+ * used to calculate the timestamp on the</span><br><span style="color: hsl(120, 100%, 40%);">+ * outgoing RTP packets.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * NOTE: We need to do integer math here</span><br><span style="color: hsl(120, 100%, 40%);">+ * because double math rounding issues can</span><br><span style="color: hsl(120, 100%, 40%);">+ * generate incorrect timestamps.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ rtp->rxcore = now;</span><br><span style="color: hsl(120, 100%, 40%);">+ tmp = ast_samp2tv(rx_rtp_ts, rate);</span><br><span style="color: hsl(120, 100%, 40%);">+ rtp->rxcore = ast_tvsub(rtp->rxcore, tmp);</span><br><span style="color: hsl(120, 100%, 40%);">+ rtp->rxcore.tv_usec -= rtp->rxcore.tv_usec % 100;</span><br><span style="color: hsl(120, 100%, 40%);">+ *tv = ast_tvadd(rtp->rxcore, tmp);</span><br><span> </span><br><span> ast_debug_rtcp(3, "%s: "</span><br><span> "Seed ts: %u current time: %f\n",</span><br><span>@@ -5526,8 +5540,14 @@</span><br><span> return;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- estimated_elapsed = ast_samp2sec(rx_rtp_ts - rtp->remote_seed_rx_rtp_ts, rate);</span><br><span style="color: hsl(0, 100%, 40%);">- *tv = ast_double2tv(rtp->rxstart + estimated_elapsed);</span><br><span style="color: hsl(120, 100%, 40%);">+ tmp = ast_samp2tv(rx_rtp_ts, rate);</span><br><span style="color: hsl(120, 100%, 40%);">+ /* See the comment about "tv" above. Even if</span><br><span style="color: hsl(120, 100%, 40%);">+ * we don't use this received packet for jitter</span><br><span style="color: hsl(120, 100%, 40%);">+ * calculations, we still need to set tv so the</span><br><span style="color: hsl(120, 100%, 40%);">+ * timestamp will be correct when this packet is</span><br><span style="color: hsl(120, 100%, 40%);">+ * sent out again.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ *tv = ast_tvadd(rtp->rxcore, tmp);</span><br><span> </span><br><span> /*</span><br><span> * The first few packets are generally unstable so let's</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/19832">change 19832</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/19832"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: I6ba992b49ffdf9ebea074581dfa784a188c661a4 </div>
<div style="display:none"> Gerrit-Change-Number: 19832 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>