mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-22 13:25:17 +00:00
Merge "res_rtp_asterisk: Cache local RTCP address."
This commit is contained in:
@@ -407,6 +407,12 @@ struct ast_rtcp {
|
|||||||
#ifdef HAVE_OPENSSL_SRTP
|
#ifdef HAVE_OPENSSL_SRTP
|
||||||
struct dtls_details dtls; /*!< DTLS state information */
|
struct dtls_details dtls; /*!< DTLS state information */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Cached local address string allows us to generate
|
||||||
|
* RTCP stasis messages without having to look up our
|
||||||
|
* own address every time
|
||||||
|
*/
|
||||||
|
char *local_addr_str;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct rtp_red {
|
struct rtp_red {
|
||||||
@@ -2700,6 +2706,7 @@ static int ast_rtp_destroy(struct ast_rtp_instance *instance)
|
|||||||
* RTP instance while it's active.
|
* RTP instance while it's active.
|
||||||
*/
|
*/
|
||||||
close(rtp->rtcp->s);
|
close(rtp->rtcp->s);
|
||||||
|
ast_free(rtp->rtcp->local_addr_str);
|
||||||
ast_free(rtp->rtcp);
|
ast_free(rtp->rtcp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3112,12 +3119,7 @@ static int ast_rtcp_write_report(struct ast_rtp_instance *instance, int sr)
|
|||||||
int rate = rtp_get_rate(rtp->f.subclass.format);
|
int rate = rtp_get_rate(rtp->f.subclass.format);
|
||||||
int ice;
|
int ice;
|
||||||
int header_offset = 0;
|
int header_offset = 0;
|
||||||
char *str_remote_address;
|
|
||||||
char *str_local_address;
|
|
||||||
struct ast_sockaddr remote_address = { { 0, } };
|
struct ast_sockaddr remote_address = { { 0, } };
|
||||||
struct ast_sockaddr local_address = { { 0, } };
|
|
||||||
struct ast_sockaddr real_remote_address = { { 0, } };
|
|
||||||
struct ast_sockaddr real_local_address = { { 0, } };
|
|
||||||
struct ast_rtp_rtcp_report_block *report_block = NULL;
|
struct ast_rtp_rtcp_report_block *report_block = NULL;
|
||||||
RAII_VAR(struct ast_rtp_rtcp_report *, rtcp_report,
|
RAII_VAR(struct ast_rtp_rtcp_report *, rtcp_report,
|
||||||
ast_rtp_rtcp_report_alloc(rtp->themssrc ? 1 : 0),
|
ast_rtp_rtcp_report_alloc(rtp->themssrc ? 1 : 0),
|
||||||
@@ -3244,22 +3246,9 @@ static int ast_rtcp_write_report(struct ast_rtp_instance *instance, int sr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_rtp_instance_get_local_address(instance, &local_address);
|
|
||||||
if (!ast_find_ourip(&real_local_address, &local_address, 0)) {
|
|
||||||
str_local_address = ast_strdupa(ast_sockaddr_stringify(&real_local_address));
|
|
||||||
} else {
|
|
||||||
str_local_address = ast_strdupa(ast_sockaddr_stringify(&local_address));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ast_find_ourip(&real_remote_address, &remote_address, 0)) {
|
|
||||||
str_remote_address = ast_strdupa(ast_sockaddr_stringify(&real_remote_address));
|
|
||||||
} else {
|
|
||||||
str_remote_address = ast_strdupa(ast_sockaddr_stringify(&remote_address));
|
|
||||||
}
|
|
||||||
|
|
||||||
message_blob = ast_json_pack("{s: s, s: s}",
|
message_blob = ast_json_pack("{s: s, s: s}",
|
||||||
"to", str_remote_address,
|
"to", ast_sockaddr_stringify(&remote_address),
|
||||||
"from", str_local_address);
|
"from", rtp->rtcp->local_addr_str);
|
||||||
ast_rtp_publish_rtcp_message(instance, ast_rtp_rtcp_sent_type(),
|
ast_rtp_publish_rtcp_message(instance, ast_rtp_rtcp_sent_type(),
|
||||||
rtcp_report,
|
rtcp_report,
|
||||||
message_blob);
|
message_blob);
|
||||||
@@ -4067,11 +4056,6 @@ static struct ast_frame *ast_rtcp_read(struct ast_rtp_instance *instance)
|
|||||||
int report_counter = 0;
|
int report_counter = 0;
|
||||||
struct ast_rtp_rtcp_report_block *report_block;
|
struct ast_rtp_rtcp_report_block *report_block;
|
||||||
struct ast_frame *f = &ast_null_frame;
|
struct ast_frame *f = &ast_null_frame;
|
||||||
char *str_local_address;
|
|
||||||
char *str_remote_address;
|
|
||||||
struct ast_sockaddr local_address = { { 0,} };
|
|
||||||
struct ast_sockaddr real_local_address = { { 0, } };
|
|
||||||
struct ast_sockaddr real_remote_address = { { 0, } };
|
|
||||||
|
|
||||||
/* Read in RTCP data from the socket */
|
/* Read in RTCP data from the socket */
|
||||||
if ((res = rtcp_recvfrom(instance, rtcpdata + AST_FRIENDLY_OFFSET,
|
if ((res = rtcp_recvfrom(instance, rtcpdata + AST_FRIENDLY_OFFSET,
|
||||||
@@ -4128,8 +4112,6 @@ static struct ast_frame *ast_rtcp_read(struct ast_rtp_instance *instance)
|
|||||||
|
|
||||||
ast_debug(1, "Got RTCP report of %d bytes\n", res);
|
ast_debug(1, "Got RTCP report of %d bytes\n", res);
|
||||||
|
|
||||||
ast_rtp_instance_get_local_address(instance, &local_address);
|
|
||||||
|
|
||||||
while (position < packetwords) {
|
while (position < packetwords) {
|
||||||
int i, pt, rc;
|
int i, pt, rc;
|
||||||
unsigned int length;
|
unsigned int length;
|
||||||
@@ -4245,21 +4227,10 @@ static struct ast_frame *ast_rtcp_read(struct ast_rtp_instance *instance)
|
|||||||
/* If and when we handle more than one report block, this should occur outside
|
/* If and when we handle more than one report block, this should occur outside
|
||||||
* this loop.
|
* this loop.
|
||||||
*/
|
*/
|
||||||
if (!ast_find_ourip(&real_local_address, &local_address, 0)) {
|
|
||||||
str_local_address = ast_strdupa(ast_sockaddr_stringify(&real_local_address));
|
|
||||||
} else {
|
|
||||||
str_local_address = ast_strdupa(ast_sockaddr_stringify(&local_address));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ast_find_ourip(&real_remote_address, &addr, 0)) {
|
|
||||||
str_remote_address = ast_strdupa(ast_sockaddr_stringify(&real_remote_address));
|
|
||||||
} else {
|
|
||||||
str_remote_address = ast_strdupa(ast_sockaddr_stringify(&addr));
|
|
||||||
}
|
|
||||||
|
|
||||||
message_blob = ast_json_pack("{s: s, s: s, s: f}",
|
message_blob = ast_json_pack("{s: s, s: s, s: f}",
|
||||||
"from", str_remote_address,
|
"from", ast_sockaddr_stringify(&rtp->rtcp->them),
|
||||||
"to", str_local_address,
|
"to", rtp->rtcp->local_addr_str,
|
||||||
"rtt", rtp->rtcp->rtt);
|
"rtt", rtp->rtcp->rtt);
|
||||||
ast_rtp_publish_rtcp_message(instance, ast_rtp_rtcp_received_type(),
|
ast_rtp_publish_rtcp_message(instance, ast_rtp_rtcp_received_type(),
|
||||||
rtcp_report,
|
rtcp_report,
|
||||||
@@ -4822,6 +4793,8 @@ static void ast_rtp_prop_set(struct ast_rtp_instance *instance, enum ast_rtp_pro
|
|||||||
|
|
||||||
if (property == AST_RTP_PROPERTY_RTCP) {
|
if (property == AST_RTP_PROPERTY_RTCP) {
|
||||||
if (value) {
|
if (value) {
|
||||||
|
struct ast_sockaddr local_addr;
|
||||||
|
|
||||||
if (rtp->rtcp) {
|
if (rtp->rtcp) {
|
||||||
ast_debug(1, "Ignoring duplicate RTCP property on RTP instance '%p'\n", instance);
|
ast_debug(1, "Ignoring duplicate RTCP property on RTP instance '%p'\n", instance);
|
||||||
return;
|
return;
|
||||||
@@ -4836,6 +4809,19 @@ static void ast_rtp_prop_set(struct ast_rtp_instance *instance, enum ast_rtp_pro
|
|||||||
ast_sockaddr_set_port(&rtp->rtcp->us,
|
ast_sockaddr_set_port(&rtp->rtcp->us,
|
||||||
ast_sockaddr_port(&rtp->rtcp->us) + 1);
|
ast_sockaddr_port(&rtp->rtcp->us) + 1);
|
||||||
|
|
||||||
|
if (!ast_find_ourip(&local_addr, &rtp->rtcp->us, 0)) {
|
||||||
|
ast_sockaddr_set_port(&local_addr, ast_sockaddr_port(&rtp->rtcp->us));
|
||||||
|
} else {
|
||||||
|
ast_sockaddr_copy(&local_addr, &rtp->rtcp->us);
|
||||||
|
}
|
||||||
|
|
||||||
|
rtp->rtcp->local_addr_str = ast_strdup(ast_sockaddr_stringify(&local_addr));
|
||||||
|
if (!rtp->rtcp->local_addr_str) {
|
||||||
|
ast_free(rtp->rtcp);
|
||||||
|
rtp->rtcp = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ((rtp->rtcp->s =
|
if ((rtp->rtcp->s =
|
||||||
create_new_socket("RTCP",
|
create_new_socket("RTCP",
|
||||||
ast_sockaddr_is_ipv4(&rtp->rtcp->us) ?
|
ast_sockaddr_is_ipv4(&rtp->rtcp->us) ?
|
||||||
@@ -4843,6 +4829,7 @@ static void ast_rtp_prop_set(struct ast_rtp_instance *instance, enum ast_rtp_pro
|
|||||||
ast_sockaddr_is_ipv6(&rtp->rtcp->us) ?
|
ast_sockaddr_is_ipv6(&rtp->rtcp->us) ?
|
||||||
AF_INET6 : -1)) < 0) {
|
AF_INET6 : -1)) < 0) {
|
||||||
ast_debug(1, "Failed to create a new socket for RTCP on instance '%p'\n", instance);
|
ast_debug(1, "Failed to create a new socket for RTCP on instance '%p'\n", instance);
|
||||||
|
ast_free(rtp->rtcp->local_addr_str);
|
||||||
ast_free(rtp->rtcp);
|
ast_free(rtp->rtcp);
|
||||||
rtp->rtcp = NULL;
|
rtp->rtcp = NULL;
|
||||||
return;
|
return;
|
||||||
@@ -4852,6 +4839,7 @@ static void ast_rtp_prop_set(struct ast_rtp_instance *instance, enum ast_rtp_pro
|
|||||||
if (ast_bind(rtp->rtcp->s, &rtp->rtcp->us)) {
|
if (ast_bind(rtp->rtcp->s, &rtp->rtcp->us)) {
|
||||||
ast_debug(1, "Failed to setup RTCP on RTP instance '%p'\n", instance);
|
ast_debug(1, "Failed to setup RTCP on RTP instance '%p'\n", instance);
|
||||||
close(rtp->rtcp->s);
|
close(rtp->rtcp->s);
|
||||||
|
ast_free(rtp->rtcp->local_addr_str);
|
||||||
ast_free(rtp->rtcp);
|
ast_free(rtp->rtcp);
|
||||||
rtp->rtcp = NULL;
|
rtp->rtcp = NULL;
|
||||||
return;
|
return;
|
||||||
@@ -4891,6 +4879,7 @@ static void ast_rtp_prop_set(struct ast_rtp_instance *instance, enum ast_rtp_pro
|
|||||||
SSL_free(rtp->rtcp->dtls.ssl);
|
SSL_free(rtp->rtcp->dtls.ssl);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
ast_free(rtp->rtcp->local_addr_str);
|
||||||
ast_free(rtp->rtcp);
|
ast_free(rtp->rtcp);
|
||||||
rtp->rtcp = NULL;
|
rtp->rtcp = NULL;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user