[asterisk-commits] twilson: trunk r323374 - in /trunk: ./ channels/ include/asterisk/ main/ res/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jun 14 12:03:41 CDT 2011
Author: twilson
Date: Tue Jun 14 12:03:37 2011
New Revision: 323374
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=323374
Log:
Merged revisions 323370 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8
........
r323370 | twilson | 2011-06-14 09:33:55 -0700 (Tue, 14 Jun 2011) | 10 lines
Add rtpkeepalives back to 1.8
The RTP-engine conversion left out support for handling rtpkeepalives.
This patch adds them back.
(closes issue ASTERISK-17304)
Reported by: lmadsen
Review: https://reviewboard.asterisk.org/r/1226/
........
Modified:
trunk/ (props changed)
trunk/channels/chan_sip.c
trunk/include/asterisk/rtp_engine.h
trunk/main/rtp_engine.c
trunk/res/res_rtp_asterisk.c
Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.8-merged' - no diff available.
Modified: trunk/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_sip.c?view=diff&rev=323374&r1=323373&r2=323374
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Tue Jun 14 12:03:37 2011
@@ -5061,6 +5061,7 @@
}
ast_rtp_instance_set_timeout(dialog->vrtp, global_rtptimeout);
ast_rtp_instance_set_hold_timeout(dialog->vrtp, global_rtpholdtimeout);
+ ast_rtp_instance_set_keepalive(dialog->vrtp, global_rtpholdtimeout);
ast_rtp_instance_set_prop(dialog->vrtp, AST_RTP_PROPERTY_RTCP, 1);
}
@@ -5071,12 +5072,14 @@
}
ast_rtp_instance_set_timeout(dialog->trtp, global_rtptimeout);
ast_rtp_instance_set_hold_timeout(dialog->trtp, global_rtpholdtimeout);
+ ast_rtp_instance_set_keepalive(dialog->trtp, global_rtpholdtimeout);
ast_rtp_instance_set_prop(dialog->trtp, AST_RTP_PROPERTY_RTCP, 1);
}
ast_rtp_instance_set_timeout(dialog->rtp, global_rtptimeout);
ast_rtp_instance_set_hold_timeout(dialog->rtp, global_rtpholdtimeout);
+ ast_rtp_instance_set_keepalive(dialog->rtp, global_rtpkeepalive);
ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_RTCP, 1);
ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_DTMF, ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833);
@@ -5144,6 +5147,7 @@
ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_DTMF_COMPENSATE, ast_test_flag(&dialog->flags[1], SIP_PAGE2_RFC2833_COMPENSATE));
ast_rtp_instance_set_timeout(dialog->rtp, peer->rtptimeout);
ast_rtp_instance_set_hold_timeout(dialog->rtp, peer->rtpholdtimeout);
+ ast_rtp_instance_set_keepalive(dialog->rtp, peer->rtpkeepalive);
/* Set Frame packetization */
ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(dialog->rtp), dialog->rtp, &dialog->prefs);
dialog->autoframing = peer->autoframing;
@@ -5151,10 +5155,12 @@
if (dialog->vrtp) { /* Video */
ast_rtp_instance_set_timeout(dialog->vrtp, peer->rtptimeout);
ast_rtp_instance_set_hold_timeout(dialog->vrtp, peer->rtpholdtimeout);
+ ast_rtp_instance_set_keepalive(dialog->vrtp, peer->rtpkeepalive);
}
if (dialog->trtp) { /* Realtime text */
ast_rtp_instance_set_timeout(dialog->trtp, peer->rtptimeout);
ast_rtp_instance_set_hold_timeout(dialog->trtp, peer->rtpholdtimeout);
+ ast_rtp_instance_set_keepalive(dialog->trtp, peer->rtpkeepalive);
}
/* XXX TODO: get fields directly from peer only as they are needed using dialog->relatedpeer */
@@ -25396,9 +25402,17 @@
}
/* If we have no timers set, return now */
- if (!ast_rtp_instance_get_timeout(dialog->rtp) && !ast_rtp_instance_get_hold_timeout(dialog->rtp)) {
+ if (!ast_rtp_instance_get_keepalive(dialog->rtp) && !ast_rtp_instance_get_timeout(dialog->rtp) && !ast_rtp_instance_get_hold_timeout(dialog->rtp)) {
dialog_unlink_rtpcheck(dialog);
return;
+ }
+
+ /* Check AUDIO RTP keepalives */
+ if (dialog->lastrtptx && ast_rtp_instance_get_keepalive(dialog->rtp) &&
+ (t > dialog->lastrtptx + ast_rtp_instance_get_keepalive(dialog->rtp))) {
+ /* Need to send an empty RTP packet */
+ dialog->lastrtptx = time(NULL);
+ ast_rtp_instance_sendcng(dialog->rtp, 0);
}
/*! \todo Check video RTP keepalives
Modified: trunk/include/asterisk/rtp_engine.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/rtp_engine.h?view=diff&rev=323374&r1=323373&r2=323374
==============================================================================
--- trunk/include/asterisk/rtp_engine.h (original)
+++ trunk/include/asterisk/rtp_engine.h Tue Jun 14 12:03:37 2011
@@ -377,6 +377,8 @@
void (*stun_request)(struct ast_rtp_instance *instance, struct ast_sockaddr *suggestion, const char *username);
/*! Callback to get the transcodeable formats supported. result returned in ast_format_cap *result */
void (*available_formats)(struct ast_rtp_instance *instance, struct ast_format_cap *to_endpoint, struct ast_format_cap *to_asterisk, struct ast_format_cap *result);
+ /*! Callback to send CNG */
+ int (*sendcng)(struct ast_rtp_instance *instance, int level);
/*! Linked list information */
AST_RWLIST_ENTRY(ast_rtp_engine) entry;
};
@@ -1713,6 +1715,24 @@
void ast_rtp_instance_set_hold_timeout(struct ast_rtp_instance *instance, int timeout);
/*!
+ * \brief Set the RTP keepalive interval
+ *
+ * \param instance The RTP instance
+ * \param period Value to set the keepalive interval to
+ *
+ * Example usage:
+ *
+ * \code
+ * ast_rtp_instance_set_keepalive(instance, 5000);
+ * \endcode
+ *
+ * This sets the RTP keepalive interval on 'instance' to be 5000.
+ *
+ * \since 1.8
+ */
+void ast_rtp_instance_set_keepalive(struct ast_rtp_instance *instance, int timeout);
+
+/*!
* \brief Get the RTP timeout value
*
* \param instance The RTP instance
@@ -1751,6 +1771,25 @@
int ast_rtp_instance_get_hold_timeout(struct ast_rtp_instance *instance);
/*!
+ * \brief Get the RTP keepalive interval
+ *
+ * \param instance The RTP instance
+ *
+ * \retval period Keepalive interval value
+ *
+ * Example usage:
+ *
+ * \code
+ * int interval = ast_rtp_instance_get_keepalive(instance);
+ * \endcode
+ *
+ * This gets the RTP keepalive interval value for the RTP instance pointed to by 'instance'.
+ *
+ * \since 1.8
+ */
+int ast_rtp_instance_get_keepalive(struct ast_rtp_instance *instance);
+
+/*!
* \brief Get the RTP engine in use on an RTP instance
*
* \param instance The RTP instance
@@ -1808,6 +1847,17 @@
* \since 1.8
*/
struct ast_channel *ast_rtp_instance_get_chan(struct ast_rtp_instance *instance);
+
+/*!
+ * \brief Send a comfort noise packet to the RTP instance
+ *
+ * \param instance The RTP instance
+ * \param level Magnitude of the noise level
+ *
+ * \retval 0 Success
+ * \retval non-zero Failure
+ */
+int ast_rtp_instance_sendcng(struct ast_rtp_instance *instance, int level);
int ast_rtp_instance_add_srtp_policy(struct ast_rtp_instance *instance, struct ast_srtp_policy *policy);
struct ast_srtp *ast_rtp_instance_get_srtp(struct ast_rtp_instance *instance);
Modified: trunk/main/rtp_engine.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/rtp_engine.c?view=diff&rev=323374&r1=323373&r2=323374
==============================================================================
--- trunk/main/rtp_engine.c (original)
+++ trunk/main/rtp_engine.c Tue Jun 14 12:03:37 2011
@@ -66,6 +66,8 @@
int timeout;
/*! RTP timeout when on hold (negative or zero means disabled, negative value means temporarily disabled). */
int holdtimeout;
+ /*! RTP keepalive interval */
+ int keepalive;
/*! DTMF mode in use */
enum ast_rtp_dtmf_mode dtmf_mode;
/*! Glue currently in use */
@@ -1781,6 +1783,11 @@
instance->holdtimeout = timeout;
}
+void ast_rtp_instance_set_keepalive(struct ast_rtp_instance *instance, int interval)
+{
+ instance->keepalive = interval;
+}
+
int ast_rtp_instance_get_timeout(struct ast_rtp_instance *instance)
{
return instance->timeout;
@@ -1789,6 +1796,11 @@
int ast_rtp_instance_get_hold_timeout(struct ast_rtp_instance *instance)
{
return instance->holdtimeout;
+}
+
+int ast_rtp_instance_get_keepalive(struct ast_rtp_instance *instance)
+{
+ return instance->keepalive;
}
struct ast_rtp_engine *ast_rtp_instance_get_engine(struct ast_rtp_instance *instance)
@@ -1848,6 +1860,15 @@
struct ast_srtp *ast_rtp_instance_get_srtp(struct ast_rtp_instance *instance)
{
return instance->srtp;
+}
+
+int ast_rtp_instance_sendcng(struct ast_rtp_instance *instance, int level)
+{
+ if (instance->engine->sendcng) {
+ return instance->engine->sendcng(instance, level);
+ }
+
+ return -1;
}
static void set_next_mime_type(const struct ast_format *format, int rtp_code, char *type, char *subtype, unsigned int sample_rate)
Modified: trunk/res/res_rtp_asterisk.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_rtp_asterisk.c?view=diff&rev=323374&r1=323373&r2=323374
==============================================================================
--- trunk/res/res_rtp_asterisk.c (original)
+++ trunk/res/res_rtp_asterisk.c Tue Jun 14 12:03:37 2011
@@ -272,6 +272,7 @@
static void ast_rtp_stun_request(struct ast_rtp_instance *instance, struct ast_sockaddr *suggestion, const char *username);
static void ast_rtp_stop(struct ast_rtp_instance *instance);
static int ast_rtp_qos_set(struct ast_rtp_instance *instance, int tos, int cos, const char* desc);
+static int ast_rtp_sendcng(struct ast_rtp_instance *instance, int level);
/* RTP Engine Declaration */
static struct ast_rtp_engine asterisk_rtp_engine = {
@@ -297,6 +298,7 @@
.stun_request = ast_rtp_stun_request,
.stop = ast_rtp_stop,
.qos = ast_rtp_qos_set,
+ .sendcng = ast_rtp_sendcng,
};
static inline int rtp_debug_test_addr(struct ast_sockaddr *addr)
@@ -2591,6 +2593,49 @@
return ast_set_qos(rtp->s, tos, cos, desc);
}
+/*! \brief generate comfort noice (CNG) */
+static int ast_rtp_sendcng(struct ast_rtp_instance *instance, int level)
+{
+ unsigned int *rtpheader;
+ int hdrlen = 12;
+ int res;
+ int payload;
+ char data[256];
+ struct ast_rtp *rtp = ast_rtp_instance_get_data(instance);
+ struct ast_sockaddr remote_address = { {0,} };
+
+ ast_rtp_instance_get_remote_address(instance, &remote_address);
+
+ if (ast_sockaddr_isnull(&remote_address)) {
+ return -1;
+ }
+
+ payload = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(instance), 0, NULL, AST_RTP_CN);
+
+ level = 127 - (level & 0x7f);
+
+ rtp->dtmfmute = ast_tvadd(ast_tvnow(), ast_tv(0, 500000));
+
+ /* Get a pointer to the header */
+ rtpheader = (unsigned int *)data;
+ rtpheader[0] = htonl((2 << 30) | (1 << 23) | (payload << 16) | (rtp->seqno++));
+ rtpheader[1] = htonl(rtp->lastts);
+ rtpheader[2] = htonl(rtp->ssrc);
+ data[12] = level;
+
+ res = rtp_sendto(instance, (void *) rtpheader, hdrlen + 1, 0, &remote_address);
+
+ if (res < 0) {
+ ast_log(LOG_ERROR, "RTP Comfort Noise Transmission error to %s: %s\n", ast_sockaddr_stringify(&remote_address), strerror(errno));
+ } else if (rtp_debug_test_addr(&remote_address)) {
+ ast_verbose("Sent Comfort Noise RTP packet to %s (type %-2.2d, seq %-6.6u, ts %-6.6u, len %-6.6u)\n",
+ ast_sockaddr_stringify(&remote_address),
+ AST_RTP_CN, rtp->seqno, rtp->lastdigitts, res - hdrlen);
+ }
+
+ return res;
+}
+
static char *rtp_do_debug_ip(struct ast_cli_args *a)
{
char *arg = ast_strdupa(a->argv[4]);
More information about the asterisk-commits
mailing list