<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/7573">View Change</a></p><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
Jenkins2: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_rtp_asterisk.c: Disable packet flood detection for video streams.<br><br>We should not do flood detection on video RTP streams. Video RTP streams<br>are very bursty by nature. They send out a burst of packets to update the<br>video frame then wait for the next video frame update. Really only audio<br>streams can be checked for flooding. The others are either bursty or<br>don't have a set rate.<br><br>* Added code to selectively disable packet flood detection for video RTP<br>streams.<br><br>ASTERISK-27440<br><br>Change-Id: I78031491a6e75c2d4b1e9c2462dc498fe9880a70<br>---<br>M configs/samples/rtp.conf.sample<br>M include/asterisk/rtp_engine.h<br>M main/rtp_engine.c<br>M res/res_rtp_asterisk.c<br>4 files changed, 73 insertions(+), 14 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/configs/samples/rtp.conf.sample b/configs/samples/rtp.conf.sample<br>index 9bc3de3..de9d590 100644<br>--- a/configs/samples/rtp.conf.sample<br>+++ b/configs/samples/rtp.conf.sample<br>@@ -21,9 +21,17 @@<br> ; rtcpinterval = 5000 ; Milliseconds between rtcp reports<br> ;(min 500, max 60000, default 5000)<br> ;<br>-; Enable strict RTP protection. This will drop RTP packets that<br>-; do not come from the source of the RTP stream. This option is<br>-; enabled by default.<br>+; Enable strict RTP protection. This will drop RTP packets that do not come<br>+; from the recoginized source of the RTP stream. Strict RTP qualifies RTP<br>+; packet stream sources before accepting them upon initial connection and<br>+; when the connection is renegotiated (e.g., transfers and direct media).<br>+; Initial connection and renegotiation starts a learning mode to qualify<br>+; stream source addresses. Once Asterisk has recognized a stream it will<br>+; allow other streams to qualify and replace the current stream for 5<br>+; seconds after starting learning mode. Once learning mode completes the<br>+; current stream is locked in and cannot change until the next<br>+; renegotiation.<br>+; This option is enabled by default.<br> ; strictrtp=yes<br> ;<br> ; Number of packets containing consecutive sequence values needed<br>diff --git a/include/asterisk/rtp_engine.h b/include/asterisk/rtp_engine.h<br>index 0b29f34..7daff67 100644<br>--- a/include/asterisk/rtp_engine.h<br>+++ b/include/asterisk/rtp_engine.h<br>@@ -1348,6 +1348,16 @@<br> void ast_rtp_codecs_payloads_unset(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload);<br> <br> /*!<br>+ * \brief Determine the type of RTP stream media from the codecs mapped.<br>+ * \since 13.19.0<br>+ *<br>+ * \param codecs Codecs structure to look in<br>+ *<br>+ * \return Media type or AST_MEDIA_TYPE_UNKNOWN if no codecs mapped.<br>+ */<br>+enum ast_media_type ast_rtp_codecs_get_stream_type(struct ast_rtp_codecs *codecs);<br>+<br>+/*!<br> * \brief Retrieve payload information by payload<br> *<br> * \param codecs Codecs structure to look in<br>diff --git a/main/rtp_engine.c b/main/rtp_engine.c<br>index e703272..b12761b 100644<br>--- a/main/rtp_engine.c<br>+++ b/main/rtp_engine.c<br>@@ -887,6 +887,25 @@<br> ast_rwlock_unlock(&codecs->codecs_lock);<br> }<br> <br>+enum ast_media_type ast_rtp_codecs_get_stream_type(struct ast_rtp_codecs *codecs)<br>+{<br>+ enum ast_media_type stream_type = AST_MEDIA_TYPE_UNKNOWN;<br>+ int payload;<br>+ struct ast_rtp_payload_type *type;<br>+<br>+ ast_rwlock_rdlock(&codecs->codecs_lock);<br>+ for (payload = 0; payload < AST_VECTOR_SIZE(&codecs->payloads); ++payload) {<br>+ type = AST_VECTOR_GET(&codecs->payloads, payload);<br>+ if (type && type->asterisk_format) {<br>+ stream_type = ast_format_get_type(type->format);<br>+ break;<br>+ }<br>+ }<br>+ ast_rwlock_unlock(&codecs->codecs_lock);<br>+<br>+ return stream_type;<br>+}<br>+<br> struct ast_rtp_payload_type *ast_rtp_codecs_get_payload(struct ast_rtp_codecs *codecs, int payload)<br> {<br> struct ast_rtp_payload_type *type = NULL;<br>diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c<br>index cf793a6..230d147 100644<br>--- a/res/res_rtp_asterisk.c<br>+++ b/res/res_rtp_asterisk.c<br>@@ -255,6 +255,8 @@<br> struct timeval received; /*!< The time of the first received packet */<br> int max_seq; /*!< The highest sequence number received */<br> int packets; /*!< The number of remaining packets before the source is accepted */<br>+ /*! Type of media stream carried by the RTP instance */<br>+ enum ast_media_type stream_type;<br> };<br> <br> #ifdef HAVE_OPENSSL_SRTP<br>@@ -2812,18 +2814,29 @@<br> info->received = ast_tvnow();<br> }<br> <br>- /*<br>- * Protect against packet floods by checking that we<br>- * received the packet sequence in at least the minimum<br>- * allowed time.<br>- */<br>- if (ast_tvzero(info->received)) {<br>- info->received = ast_tvnow();<br>- } else if (!info->packets && (ast_tvdiff_ms(ast_tvnow(), info->received) < learning_min_duration )) {<br>- /* Packet flood; reset */<br>- info->packets = learning_min_sequential - 1;<br>- info->received = ast_tvnow();<br>+ switch (info->stream_type) {<br>+ case AST_MEDIA_TYPE_UNKNOWN:<br>+ case AST_MEDIA_TYPE_AUDIO:<br>+ /*<br>+ * Protect against packet floods by checking that we<br>+ * received the packet sequence in at least the minimum<br>+ * allowed time.<br>+ */<br>+ if (ast_tvzero(info->received)) {<br>+ info->received = ast_tvnow();<br>+ } else if (!info->packets<br>+ && ast_tvdiff_ms(ast_tvnow(), info->received) < learning_min_duration) {<br>+ /* Packet flood; reset */<br>+ info->packets = learning_min_sequential - 1;<br>+ info->received = ast_tvnow();<br>+ }<br>+ break;<br>+ case AST_MEDIA_TYPE_VIDEO:<br>+ case AST_MEDIA_TYPE_IMAGE:<br>+ case AST_MEDIA_TYPE_TEXT:<br>+ break;<br> }<br>+<br> info->max_seq = seq;<br> <br> return info->packets;<br>@@ -5430,6 +5443,15 @@<br> * source and we should switch to it.<br> */<br> if (!ast_sockaddr_cmp(&rtp->rtp_source_learn.proposed_address, &addr)) {<br>+ if (rtp->rtp_source_learn.stream_type == AST_MEDIA_TYPE_UNKNOWN) {<br>+ struct ast_rtp_codecs *codecs;<br>+<br>+ codecs = ast_rtp_instance_get_codecs(instance);<br>+ rtp->rtp_source_learn.stream_type =<br>+ ast_rtp_codecs_get_stream_type(codecs);<br>+ ast_verb(4, "%p -- Strict RTP qualifying stream type: %s\n",<br>+ rtp, ast_codec_media_type2str(rtp->rtp_source_learn.stream_type));<br>+ }<br> if (!rtp_learning_rtp_seq_update(&rtp->rtp_source_learn, seqno)) {<br> /* Accept the new RTP stream */<br> ast_verb(4, "%p -- Strict RTP switching source address to %s\n",<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7573">change 7573</a>. To unsubscribe, 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/7573"/><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-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I78031491a6e75c2d4b1e9c2462dc498fe9880a70 </div>
<div style="display:none"> Gerrit-Change-Number: 7573 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>