<p>George Joseph <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/13976">View Change</a></p><div style="white-space:pre-wrap">Approvals:
George Joseph: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">chan_psip, res_pjsip_sdp_rtp: ignore rtptimeout if direct-media is active<br><br>Do not hang up a PJSIP channel on RTP timeout if that channel is in<br>a direct-media bridge. Also reset the time of the last received RTP packet when<br>direct-media ends (wait full rtp_timeout period before checking first time after<br>audio came back to Asterisk).<br><br>ASTERISK-28774<br>Reported-by: Michael Neuhauser<br><br>Change-Id: I8b62012be7685849e8fb2b1c5dd39d35313ca2d1<br>---<br>M channels/chan_pjsip.c<br>M res/res_pjsip_sdp_rtp.c<br>2 files changed, 41 insertions(+), 10 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c</span><br><span>index 0466fd3..33c023d 100644</span><br><span>--- a/channels/chan_pjsip.c</span><br><span>+++ b/channels/chan_pjsip.c</span><br><span>@@ -295,6 +295,14 @@</span><br><span> ast_sockaddr_setnull(&media->direct_media_addr);</span><br><span> changed = 1;</span><br><span> if (media->rtp) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Direct media has ended - reset time of last received RTP packet</span><br><span style="color: hsl(120, 100%, 40%);">+ * to avoid premature RTP timeout. Synchronisation between the</span><br><span style="color: hsl(120, 100%, 40%);">+ * modification of direct_mdedia_addr+last_rx here and reading the</span><br><span style="color: hsl(120, 100%, 40%);">+ * values in res_pjsip_sdp_rtp.c:rtp_check_timeout() is provided</span><br><span style="color: hsl(120, 100%, 40%);">+ * by the channel's lock (which is held while this function is</span><br><span style="color: hsl(120, 100%, 40%);">+ * executed).</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_rtp_instance_set_last_rx(media->rtp, time(NULL));</span><br><span> ast_rtp_instance_set_prop(media->rtp, AST_RTP_PROPERTY_RTCP, 1);</span><br><span> ast_channel_set_fd(chan, rtcp_fd, ast_rtp_instance_fd(media->rtp, 1));</span><br><span> }</span><br><span>diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c</span><br><span>index b0a9188..018074c 100644</span><br><span>--- a/res/res_pjsip_sdp_rtp.c</span><br><span>+++ b/res/res_pjsip_sdp_rtp.c</span><br><span>@@ -144,30 +144,53 @@</span><br><span> struct ast_sip_session_media *session_media = (struct ast_sip_session_media *)data;</span><br><span> struct ast_rtp_instance *rtp = session_media->rtp;</span><br><span> int elapsed;</span><br><span style="color: hsl(120, 100%, 40%);">+ int timeout;</span><br><span> struct ast_channel *chan;</span><br><span> </span><br><span> if (!rtp) {</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- elapsed = time(NULL) - ast_rtp_instance_get_last_rx(rtp);</span><br><span style="color: hsl(0, 100%, 40%);">- if (elapsed < ast_rtp_instance_get_timeout(rtp)) {</span><br><span style="color: hsl(0, 100%, 40%);">- return (ast_rtp_instance_get_timeout(rtp) - elapsed) * 1000;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> chan = ast_channel_get_by_name(ast_rtp_instance_get_channel_id(rtp));</span><br><span> if (!chan) {</span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_log(LOG_NOTICE, "Disconnecting channel '%s' for lack of RTP activity in %d seconds\n",</span><br><span style="color: hsl(0, 100%, 40%);">- ast_channel_name(chan), elapsed);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Get channel lock to make sure that we access a consistent set of values</span><br><span style="color: hsl(120, 100%, 40%);">+ * (last_rx and direct_media_addr) - the lock is held when values are modified</span><br><span style="color: hsl(120, 100%, 40%);">+ * (see send_direct_media_request()/check_for_rtp_changes() in chan_pjsip.c). We</span><br><span style="color: hsl(120, 100%, 40%);">+ * are trying to avoid a situation where direct_media_addr has been reset but the</span><br><span style="color: hsl(120, 100%, 40%);">+ * last-rx time was not set yet.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span> ast_channel_lock(chan);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_channel_hangupcause_set(chan, AST_CAUSE_REQUESTED_CHAN_UNAVAIL);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_channel_unlock(chan);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ elapsed = time(NULL) - ast_rtp_instance_get_last_rx(rtp);</span><br><span style="color: hsl(120, 100%, 40%);">+ timeout = ast_rtp_instance_get_timeout(rtp);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (elapsed < timeout) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unref(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ return (timeout - elapsed) * 1000;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Last RTP packet was received too long ago</span><br><span style="color: hsl(120, 100%, 40%);">+ * - disconnect channel unless direct media is in use.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_sockaddr_isnull(&session_media->direct_media_addr)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(3, "Not disconnecting channel '%s' for lack of %s RTP activity in %d seconds "</span><br><span style="color: hsl(120, 100%, 40%);">+ "since direct media is in use\n", ast_channel_name(chan),</span><br><span style="color: hsl(120, 100%, 40%);">+ session_media->stream_type, elapsed);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unref(chan);</span><br><span style="color: hsl(120, 100%, 40%);">+ return timeout * 1000; /* recheck later, direct media may have ended then */</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_NOTICE, "Disconnecting channel '%s' for lack of %s RTP activity in %d seconds\n",</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_name(chan), session_media->stream_type, elapsed);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_hangupcause_set(chan, AST_CAUSE_REQUESTED_CHAN_UNAVAIL);</span><br><span> ast_softhangup(chan, AST_SOFTHANGUP_DEV);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_channel_unlock(chan);</span><br><span> ast_channel_unref(chan);</span><br><span> </span><br><span> return 0;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/13976">change 13976</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/+/13976"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: I8b62012be7685849e8fb2b1c5dd39d35313ca2d1 </div>
<div style="display:none"> Gerrit-Change-Number: 13976 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Michael Neuhauser <mike@firmix.at> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>