diff options
Diffstat (limited to 'res/res_rtp_asterisk.c')
-rw-r--r-- | res/res_rtp_asterisk.c | 55 |
1 files changed, 38 insertions, 17 deletions
diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c index 5271d1bf4..263dbff18 100644 --- a/res/res_rtp_asterisk.c +++ b/res/res_rtp_asterisk.c @@ -255,6 +255,8 @@ struct rtp_learning_info { 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 @@ -2765,8 +2767,7 @@ static int create_new_socket(const char *type, int af) } ast_log(LOG_WARNING, "Unable to allocate %s socket: %s\n", type, strerror(errno)); } else { - long flags = fcntl(sock, F_GETFL); - fcntl(sock, F_SETFL, flags | O_NONBLOCK); + ast_fd_set_flags(sock, O_NONBLOCK); #ifdef SO_NO_CHECK if (nochecksums) { setsockopt(sock, SOL_SOCKET, SO_NO_CHECK, &nochecksums, sizeof(nochecksums)); @@ -2813,18 +2814,29 @@ static int rtp_learning_rtp_seq_update(struct rtp_learning_info *info, uint16_t 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; @@ -3235,7 +3247,9 @@ static int ast_rtp_destroy(struct ast_rtp_instance *instance) * entry at this point since it holds a reference to the * RTP instance while it's active. */ - close(rtp->rtcp->s); + if (rtp->rtcp->s > -1 && rtp->s != rtp->rtcp->s) { + close(rtp->rtcp->s); + } ast_free(rtp->rtcp->local_addr_str); ast_free(rtp->rtcp); } @@ -4743,7 +4757,6 @@ static struct ast_frame *ast_rtcp_interpret(struct ast_rtp_instance *instance, c unsigned int first_word; /*! True if we have seen an acceptable SSRC to learn the remote RTCP address */ unsigned int ssrc_seen; - int report_counter = 0; struct ast_rtp_rtcp_report_block *report_block; struct ast_frame *f = &ast_null_frame; @@ -4957,7 +4970,7 @@ static struct ast_frame *ast_rtcp_interpret(struct ast_rtp_instance *instance, c if (!report_block) { return &ast_null_frame; } - rtcp_report->report_block[report_counter] = report_block; + rtcp_report->report_block[0] = report_block; report_block->source_ssrc = ntohl(rtcpheader[i]); report_block->lost_count.packets = ntohl(rtcpheader[i + 1]) & 0x00ffffff; report_block->lost_count.fraction = ((ntohl(rtcpheader[i + 1]) & 0xff000000) >> 24); @@ -4994,7 +5007,6 @@ static struct ast_frame *ast_rtcp_interpret(struct ast_rtp_instance *instance, c ast_verbose(" DLSR: %4.4f (sec)\n",(double)report_block->dlsr / 65536.0); ast_verbose(" RTT: %4.4f(sec)\n", rtp->rtcp->rtt); } - report_counter++; } /* If and when we handle more than one report block, this should occur outside * this loop. @@ -5433,6 +5445,15 @@ static struct ast_frame *ast_rtp_read(struct ast_rtp_instance *instance, int rtc * 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", |