[svn-commits] twilson: branch group/srtp_reboot r254048 - in /team/group/srtp_reboot: inclu...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Tue Mar 23 16:10:42 CDT 2010
Author: twilson
Date: Tue Mar 23 16:10:38 2010
New Revision: 254048
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=254048
Log:
Add support SRTCP
Modified:
team/group/srtp_reboot/include/asterisk/res_srtp.h
team/group/srtp_reboot/res/res_rtp_asterisk.c
team/group/srtp_reboot/res/res_srtp.c
Modified: team/group/srtp_reboot/include/asterisk/res_srtp.h
URL: http://svnview.digium.com/svn/asterisk/team/group/srtp_reboot/include/asterisk/res_srtp.h?view=diff&rev=254048&r1=254047&r2=254048
==============================================================================
--- team/group/srtp_reboot/include/asterisk/res_srtp.h (original)
+++ team/group/srtp_reboot/include/asterisk/res_srtp.h Tue Mar 23 16:10:38 2010
@@ -34,8 +34,8 @@
void (*destroy)(struct ast_srtp *srtp);
int (*add_stream)(struct ast_srtp *srtp, struct ast_srtp_policy *policy);
void (*set_cb)(struct ast_srtp *srtp, const struct ast_srtp_cb *cb, void *data);
- int (*unprotect)(struct ast_srtp *srtp, void *buf, int *size);
- int (*protect)(struct ast_srtp *srtp, void **buf, int *size);
+ int (*unprotect)(struct ast_srtp *srtp, void *buf, int *size, int rtcp);
+ int (*protect)(struct ast_srtp *srtp, void **buf, int *size, int rtcp);
int (*get_random)(unsigned char *key, size_t len);
};
Modified: team/group/srtp_reboot/res/res_rtp_asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/group/srtp_reboot/res/res_rtp_asterisk.c?view=diff&rev=254048&r1=254047&r2=254048
==============================================================================
--- team/group/srtp_reboot/res/res_rtp_asterisk.c (original)
+++ team/group/srtp_reboot/res/res_rtp_asterisk.c Tue Mar 23 16:10:38 2010
@@ -327,37 +327,56 @@
return 1;
}
+static int __rtp_recvfrom(struct ast_rtp_instance *instance, void *buf, size_t size, int flags, struct sockaddr *sa, socklen_t *salen, int rtcp)
+{
+ int len;
+ struct ast_rtp *rtp = ast_rtp_instance_get_data(instance);
+ struct ast_srtp *srtp = ast_rtp_instance_get_srtp(instance);
+
+ if ((len = recvfrom(rtcp ? rtp->rtcp->s : rtp->s, buf, size, flags, sa, salen)) < 0) {
+ return len;
+ }
+
+ if (res_srtp && srtp && res_srtp->unprotect(srtp, buf, &len, rtcp) < 0) {
+ return -1;
+ }
+
+ return len;
+}
+
+static int rtcp_recvfrom(struct ast_rtp_instance *instance, void *buf, size_t size, int flags, struct sockaddr *sa, socklen_t *salen)
+{
+ return __rtp_recvfrom(instance, buf, size, flags, sa, salen, 1);
+}
+
static int rtp_recvfrom(struct ast_rtp_instance *instance, void *buf, size_t size, int flags, struct sockaddr *sa, socklen_t *salen)
{
- int len;
- struct ast_rtp *rtp = ast_rtp_instance_get_data(instance);
- struct ast_srtp *srtp = ast_rtp_instance_get_srtp(instance);
-
- if ((len = recvfrom(rtp->s, buf, size, flags, sa, salen)) < 0) {
- return len;
- }
-
- if (res_srtp && srtp && res_srtp->unprotect(srtp, buf, &len) < 0) {
- return -1;
- }
-
- return len;
-}
-
-static int rtp_sendto(struct ast_rtp_instance *instance, void *buf, size_t size, int flags, struct sockaddr *sa, socklen_t salen)
+ return __rtp_recvfrom(instance, buf, size, flags, sa, salen, 0);
+}
+
+static int __rtp_sendto(struct ast_rtp_instance *instance, void *buf, size_t size, int flags, struct sockaddr *sa, socklen_t salen, int rtcp)
{
int len = size;
void *temp = buf;
struct ast_rtp *rtp = ast_rtp_instance_get_data(instance);
struct ast_srtp *srtp = ast_rtp_instance_get_srtp(instance);
- if (res_srtp && srtp && res_srtp->protect(srtp, &temp, &len) < 0) {
+ if (res_srtp && srtp && res_srtp->protect(srtp, &temp, &len, rtcp) < 0) {
return -1;
}
- return sendto(rtp->s, temp, len, flags, sa, salen);
-}
-
+ return sendto(rtcp ? rtp->rtcp->s : rtp->s, temp, len, flags, sa, salen);
+}
+
+static int rtcp_sendto(struct ast_rtp_instance *instance, void *buf, size_t size, int flags, struct sockaddr *sa, socklen_t salen)
+{
+ return __rtp_sendto(instance, buf, size, flags, sa, salen, 1);
+}
+
+static int rtp_sendto(struct ast_rtp_instance *instance, void *buf, size_t size, int flags, struct sockaddr *sa, socklen_t salen)
+{
+ return __rtp_sendto(instance, buf, size, flags, sa, salen, 0);
+}
static int rtp_get_rate(format_t subclass)
{
@@ -745,9 +764,9 @@
}
/*! \brief Send RTCP recipient's report */
-static int ast_rtcp_write_rr(const void *data)
-{
- struct ast_rtp *rtp = (struct ast_rtp *)data;
+static int ast_rtcp_write_rr(struct ast_rtp_instance *instance)
+{
+ struct ast_rtp *rtp = ast_rtp_instance_get_data(instance);
int res;
int len = 32;
unsigned int lost;
@@ -820,7 +839,7 @@
rtcpheader[(len/4)+2] = htonl(0x01 << 24); /* Empty for the moment */
len += 12;
- res = sendto(rtp->rtcp->s, (unsigned int *)rtcpheader, len, 0, (struct sockaddr *)&rtp->rtcp->them, sizeof(rtp->rtcp->them));
+ res = rtcp_sendto(instance, (unsigned int *)rtcpheader, len, 0, (struct sockaddr *)&rtp->rtcp->them, sizeof(rtp->rtcp->them));
if (res < 0) {
ast_log(LOG_ERROR, "RTCP RR transmission error, rtcp halted: %s\n",strerror(errno));
@@ -848,9 +867,9 @@
}
/*! \brief Send RTCP sender's report */
-static int ast_rtcp_write_sr(const void *data)
-{
- struct ast_rtp *rtp = (struct ast_rtp *)data;
+static int ast_rtcp_write_sr(struct ast_rtp_instance *instance)
+{
+ struct ast_rtp *rtp = ast_rtp_instance_get_data(instance);
int res;
int len = 0;
struct timeval now;
@@ -920,7 +939,7 @@
rtcpheader[(len/4)+2] = htonl(0x01 << 24); /* Empty for the moment */
len += 12;
- res = sendto(rtp->rtcp->s, (unsigned int *)rtcpheader, len, 0, (struct sockaddr *)&rtp->rtcp->them, sizeof(rtp->rtcp->them));
+ res =rtcp_sendto(instance, (unsigned int *)rtcpheader, len, 0, (struct sockaddr *)&rtp->rtcp->them, sizeof(rtp->rtcp->them));
if (res < 0) {
ast_log(LOG_ERROR, "RTCP SR transmission error to %s:%d, rtcp halted %s\n",ast_inet_ntoa(rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port), strerror(errno));
AST_SCHED_DEL(rtp->sched, rtp->rtcp->schedid);
@@ -978,16 +997,17 @@
* RR is sent if we have not sent any rtp packets in the previous interval */
static int ast_rtcp_write(const void *data)
{
- struct ast_rtp *rtp = (struct ast_rtp *)data;
+ struct ast_rtp_instance *instance = (struct ast_rtp_instance *) data;
+ struct ast_rtp *rtp = ast_rtp_instance_get_data(instance);
int res;
if (!rtp || !rtp->rtcp)
return 0;
if (rtp->txcount > rtp->rtcp->lastsrtxcount)
- res = ast_rtcp_write_sr(data);
+ res = ast_rtcp_write_sr(instance);
else
- res = ast_rtcp_write_rr(data);
+ res = ast_rtcp_write_rr(instance);
return res;
}
@@ -1095,7 +1115,7 @@
if (rtp->rtcp && rtp->rtcp->schedid < 1) {
ast_debug(1, "Starting RTCP transmission on RTP instance '%p'\n", instance);
- rtp->rtcp->schedid = ast_sched_add(rtp->sched, ast_rtcp_calc_interval(rtp), ast_rtcp_write, rtp);
+ rtp->rtcp->schedid = ast_sched_add(rtp->sched, ast_rtcp_calc_interval(rtp), ast_rtcp_write, instance);
}
}
@@ -1581,7 +1601,7 @@
struct ast_frame *f = &ast_null_frame;
/* Read in RTCP data from the socket */
- if ((res = recvfrom(rtp->rtcp->s, rtcpdata + AST_FRIENDLY_OFFSET, sizeof(rtcpdata) - sizeof(unsigned int) * AST_FRIENDLY_OFFSET, 0, (struct sockaddr *)&sin, &len)) < 0) {
+ if ((res = rtcp_recvfrom(instance, rtcpdata + AST_FRIENDLY_OFFSET, sizeof(rtcpdata) - sizeof(unsigned int) * AST_FRIENDLY_OFFSET, 0, (struct sockaddr *)&sin, &len)) < 0) {
ast_assert(errno != EBADF);
if (errno != EAGAIN) {
ast_log(LOG_WARNING, "RTCP Read error: %s. Hanging up.\n", strerror(errno));
@@ -2057,7 +2077,7 @@
/* Do not schedule RR if RTCP isn't run */
if (rtp->rtcp && rtp->rtcp->them.sin_addr.s_addr && rtp->rtcp->schedid < 1) {
/* Schedule transmission of Receiver Report */
- rtp->rtcp->schedid = ast_sched_add(rtp->sched, ast_rtcp_calc_interval(rtp), ast_rtcp_write, rtp);
+ rtp->rtcp->schedid = ast_sched_add(rtp->sched, ast_rtcp_calc_interval(rtp), ast_rtcp_write, instance);
}
if ((int)rtp->lastrxseqno - (int)seqno > 100) /* if so it would indicate that the sender cycled; allow for misordering */
rtp->cycles += RTP_SEQ_MOD;
Modified: team/group/srtp_reboot/res/res_srtp.c
URL: http://svnview.digium.com/svn/asterisk/team/group/srtp_reboot/res/res_srtp.c?view=diff&rev=254048&r1=254047&r2=254048
==============================================================================
--- team/group/srtp_reboot/res/res_srtp.c (original)
+++ team/group/srtp_reboot/res/res_srtp.c Tue Mar 23 16:10:38 2010
@@ -74,8 +74,8 @@
void ast_srtp_destroy(struct ast_srtp *srtp);
int ast_srtp_add_stream(struct ast_srtp *srtp, struct ast_srtp_policy *policy);
-int ast_srtp_unprotect(struct ast_srtp *srtp, void *buf, int *len);
-int ast_srtp_protect(struct ast_srtp *srtp, void **buf, int *len);
+int ast_srtp_unprotect(struct ast_srtp *srtp, void *buf, int *len, int rtcp);
+int ast_srtp_protect(struct ast_srtp *srtp, void **buf, int *len, int rtcp);
int ast_srtp_get_random(unsigned char *key, size_t len);
void ast_srtp_set_cb(struct ast_srtp *srtp, const struct ast_srtp_cb *cb, void *data);
@@ -278,14 +278,14 @@
}
/* Vtable functions */
-int ast_srtp_unprotect(struct ast_srtp *srtp, void *buf, int *len)
+int ast_srtp_unprotect(struct ast_srtp *srtp, void *buf, int *len, int rtcp)
{
int res = 0;
int i;
struct ast_rtp_instance_stats stats = {0,};
for (i = 0; i < 2; i++) {
- res = srtp_unprotect(srtp->session, buf, len);
+ res = rtcp ? srtp_unprotect_rtcp(srtp->session, buf, len) : srtp_unprotect(srtp->session, buf, len);
if (res != err_status_no_ctx) {
break;
}
@@ -310,7 +310,7 @@
return *len;
}
-int ast_srtp_protect(struct ast_srtp *srtp, void **buf, int *len)
+int ast_srtp_protect(struct ast_srtp *srtp, void **buf, int *len, int rtcp)
{
int res;
@@ -320,7 +320,7 @@
memcpy(srtp->buf, *buf, *len);
- if ((res = srtp_protect(srtp->session, srtp->buf, len)) != err_status_ok && res != err_status_replay_fail) {
+ if ((res = rtcp ? srtp_protect_rtcp(srtp->session, srtp->buf, len) : srtp_protect(srtp->session, srtp->buf, len)) != err_status_ok && res != err_status_replay_fail) {
ast_debug(1, "SRTP protect: %s\n", srtp_errstr(res));
return -1;
}
More information about the svn-commits
mailing list