[Asterisk-code-review] res rtp asterisk.c: Disable packet flood detection for video... (asterisk[13])

Richard Mudgett asteriskteam at digium.com
Wed Dec 13 18:54:53 CST 2017


Richard Mudgett has uploaded this change for review. ( https://gerrit.asterisk.org/7573


Change subject: res_rtp_asterisk.c: Disable packet flood detection for video streams.
......................................................................

res_rtp_asterisk.c: Disable packet flood detection for video streams.

We should not do flood detection on video RTP streams.  Video RTP streams
are very bursty by nature.  They send out a burst of packets to update the
video frame then wait for the next video frame update.  Really only audio
streams can be checked for flooding.  The others are either bursty or
don't have a set rate.

* Added code to selectively disable packet flood detection for video RTP
streams.

ASTERISK-27440

Change-Id: I78031491a6e75c2d4b1e9c2462dc498fe9880a70
---
M include/asterisk/rtp_engine.h
M main/rtp_engine.c
M res/res_rtp_asterisk.c
3 files changed, 62 insertions(+), 11 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/73/7573/1

diff --git a/include/asterisk/rtp_engine.h b/include/asterisk/rtp_engine.h
index 0b29f34..7daff67 100644
--- a/include/asterisk/rtp_engine.h
+++ b/include/asterisk/rtp_engine.h
@@ -1348,6 +1348,16 @@
 void ast_rtp_codecs_payloads_unset(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload);
 
 /*!
+ * \brief Determine the type of RTP stream media from the codecs mapped.
+ * \since 13.19.0
+ *
+ * \param codecs Codecs structure to look in
+ *
+ * \return Media type or AST_MEDIA_TYPE_UNKNOWN if no codecs mapped.
+ */
+enum ast_media_type ast_rtp_codecs_get_stream_type(struct ast_rtp_codecs *codecs);
+
+/*!
  * \brief Retrieve payload information by payload
  *
  * \param codecs Codecs structure to look in
diff --git a/main/rtp_engine.c b/main/rtp_engine.c
index e703272..b12761b 100644
--- a/main/rtp_engine.c
+++ b/main/rtp_engine.c
@@ -887,6 +887,25 @@
 	ast_rwlock_unlock(&codecs->codecs_lock);
 }
 
+enum ast_media_type ast_rtp_codecs_get_stream_type(struct ast_rtp_codecs *codecs)
+{
+	enum ast_media_type stream_type = AST_MEDIA_TYPE_UNKNOWN;
+	int payload;
+	struct ast_rtp_payload_type *type;
+
+	ast_rwlock_rdlock(&codecs->codecs_lock);
+	for (payload = 0; payload < AST_VECTOR_SIZE(&codecs->payloads); ++payload) {
+		type = AST_VECTOR_GET(&codecs->payloads, payload);
+		if (type && type->asterisk_format) {
+			stream_type = ast_format_get_type(type->format);
+			break;
+		}
+	}
+	ast_rwlock_unlock(&codecs->codecs_lock);
+
+	return stream_type;
+}
+
 struct ast_rtp_payload_type *ast_rtp_codecs_get_payload(struct ast_rtp_codecs *codecs, int payload)
 {
 	struct ast_rtp_payload_type *type = NULL;
diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c
index cf793a6..230d147 100644
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -255,6 +255,8 @@
 	struct timeval received; /*!< The time of the first received packet */
 	int max_seq;	/*!< The highest sequence number received */
 	int packets;	/*!< The number of remaining packets before the source is accepted */
+	/*! Type of media stream carried by the RTP instance */
+	enum ast_media_type stream_type;
 };
 
 #ifdef HAVE_OPENSSL_SRTP
@@ -2812,18 +2814,29 @@
 		info->received = ast_tvnow();
 	}
 
-	/*
-	 * Protect against packet floods by checking that we
-	 * received the packet sequence in at least the minimum
-	 * allowed time.
-	 */
-	if (ast_tvzero(info->received)) {
-		info->received = ast_tvnow();
-	} else if (!info->packets && (ast_tvdiff_ms(ast_tvnow(), info->received) < learning_min_duration )) {
-		/* Packet flood; reset */
-		info->packets = learning_min_sequential - 1;
-		info->received = ast_tvnow();
+	switch (info->stream_type) {
+	case AST_MEDIA_TYPE_UNKNOWN:
+	case AST_MEDIA_TYPE_AUDIO:
+		/*
+		 * Protect against packet floods by checking that we
+		 * received the packet sequence in at least the minimum
+		 * allowed time.
+		 */
+		if (ast_tvzero(info->received)) {
+			info->received = ast_tvnow();
+		} else if (!info->packets
+			&& ast_tvdiff_ms(ast_tvnow(), info->received) < learning_min_duration) {
+			/* Packet flood; reset */
+			info->packets = learning_min_sequential - 1;
+			info->received = ast_tvnow();
+		}
+		break;
+	case AST_MEDIA_TYPE_VIDEO:
+	case AST_MEDIA_TYPE_IMAGE:
+	case AST_MEDIA_TYPE_TEXT:
+		break;
 	}
+
 	info->max_seq = seq;
 
 	return info->packets;
@@ -5430,6 +5443,15 @@
 			 * source and we should switch to it.
 			 */
 			if (!ast_sockaddr_cmp(&rtp->rtp_source_learn.proposed_address, &addr)) {
+				if (rtp->rtp_source_learn.stream_type == AST_MEDIA_TYPE_UNKNOWN) {
+					struct ast_rtp_codecs *codecs;
+
+					codecs = ast_rtp_instance_get_codecs(instance);
+					rtp->rtp_source_learn.stream_type =
+						ast_rtp_codecs_get_stream_type(codecs);
+					ast_verb(4, "%p -- Strict RTP qualifying stream type: %s\n",
+						rtp, ast_codec_media_type2str(rtp->rtp_source_learn.stream_type));
+				}
 				if (!rtp_learning_rtp_seq_update(&rtp->rtp_source_learn, seqno)) {
 					/* Accept the new RTP stream */
 					ast_verb(4, "%p -- Strict RTP switching source address to %s\n",

-- 
To view, visit https://gerrit.asterisk.org/7573
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: I78031491a6e75c2d4b1e9c2462dc498fe9880a70
Gerrit-Change-Number: 7573
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171213/56b21c51/attachment-0001.html>


More information about the asterisk-code-review mailing list