[asterisk-commits] twilson: branch 1.8 r323370 - in /branches/1.8: channels/ include/asterisk/ m...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jun 14 11:34:00 CDT 2011
Author: twilson
Date: Tue Jun 14 11:33:55 2011
New Revision: 323370
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=323370
Log:
Add rtpkeepalives back to 1.8
The RTP-engine conversion left out support for handling rtpkeepalives.
This patch adds them back.
(closes ASTERISK-17304)
Review: https://reviewboard.asterisk.org/r/1226/
Modified:
branches/1.8/channels/chan_sip.c
branches/1.8/include/asterisk/rtp_engine.h
branches/1.8/main/rtp_engine.c
branches/1.8/res/res_rtp_asterisk.c
Modified: branches/1.8/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/channels/chan_sip.c?view=diff&rev=323370&r1=323369&r2=323370
==============================================================================
--- branches/1.8/channels/chan_sip.c (original)
+++ branches/1.8/channels/chan_sip.c Tue Jun 14 11:33:55 2011
@@ -5020,6 +5020,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);
}
@@ -5030,12 +5031,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);
@@ -5103,6 +5106,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;
@@ -5110,10 +5114,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 */
@@ -24771,8 +24777,16 @@
return;
/* 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)) {
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: branches/1.8/include/asterisk/rtp_engine.h
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/include/asterisk/rtp_engine.h?view=diff&rev=323370&r1=323369&r2=323370
==============================================================================
--- branches/1.8/include/asterisk/rtp_engine.h (original)
+++ branches/1.8/include/asterisk/rtp_engine.h Tue Jun 14 11:33:55 2011
@@ -373,6 +373,8 @@
void (*stun_request)(struct ast_rtp_instance *instance, struct ast_sockaddr *suggestion, const char *username);
/*! Callback to get the transcodeable formats supported */
int (*available_formats)(struct ast_rtp_instance *instance, format_t to_endpoint, format_t to_asterisk);
+ /*! Callback to send CNG */
+ int (*sendcng)(struct ast_rtp_instance *instance, int level);
/*! Linked list information */
AST_RWLIST_ENTRY(ast_rtp_engine) entry;
};
@@ -1685,6 +1687,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
@@ -1723,6 +1743,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
@@ -1780,6 +1819,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: branches/1.8/main/rtp_engine.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/main/rtp_engine.c?view=diff&rev=323370&r1=323369&r2=323370
==============================================================================
--- branches/1.8/main/rtp_engine.c (original)
+++ branches/1.8/main/rtp_engine.c Tue Jun 14 11:33:55 2011
@@ -65,6 +65,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 */
@@ -1710,6 +1712,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;
@@ -1718,6 +1725,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)
@@ -1778,3 +1790,12 @@
{
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;
+}
Modified: branches/1.8/res/res_rtp_asterisk.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.8/res/res_rtp_asterisk.c?view=diff&rev=323370&r1=323369&r2=323370
==============================================================================
--- branches/1.8/res/res_rtp_asterisk.c (original)
+++ branches/1.8/res/res_rtp_asterisk.c Tue Jun 14 11:33:55 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;
+ struct ast_rtp_payload_type 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_lookup(ast_rtp_instance_get_codecs(instance), 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.code << 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