<p>Richard Mudgett has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7574">View Change</a></p><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 include/asterisk/rtp_engine.h<br>M main/rtp_engine.c<br>M res/res_rtp_asterisk.c<br>3 files changed, 63 insertions(+), 11 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/74/7574/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/include/asterisk/rtp_engine.h b/include/asterisk/rtp_engine.h<br>index f9d686a..c77be45 100644<br>--- a/include/asterisk/rtp_engine.h<br>+++ b/include/asterisk/rtp_engine.h<br>@@ -1383,6 +1383,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 rx payload mapped information by payload type<br> *<br> * \param codecs Codecs structure to look in<br>diff --git a/main/rtp_engine.c b/main/rtp_engine.c<br>index 2431ffc..68c53e7 100644<br>--- a/main/rtp_engine.c<br>+++ b/main/rtp_engine.c<br>@@ -1176,6 +1176,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->payload_mapping_rx); ++payload) {<br>+ type = AST_VECTOR_GET(&codecs->payload_mapping_rx, 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 bdc8330..51e509c 100644<br>--- a/res/res_rtp_asterisk.c<br>+++ b/res/res_rtp_asterisk.c<br>@@ -256,6 +256,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>@@ -3095,18 +3097,30 @@<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>+ case AST_MEDIA_TYPE_END:<br>+ break;<br> }<br>+<br> info->max_seq = seq;<br> <br> return info->packets;<br>@@ -5951,6 +5965,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/7574">change 7574</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/7574"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 15 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I78031491a6e75c2d4b1e9c2462dc498fe9880a70 </div>
<div style="display:none"> Gerrit-Change-Number: 7574 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Richard Mudgett <rmudgett@digium.com> </div>