[asterisk-commits] jdixon: branch jdixon/chan_usbradio-1.4 r129800 - /team/jdixon/chan_usbradio-...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Jul 10 16:36:21 CDT 2008
Author: jdixon
Date: Thu Jul 10 16:36:20 2008
New Revision: 129800
URL: http://svn.digium.com/view/asterisk?view=rev&rev=129800
Log:
Fixed so that if slammed with packets, will not crash or hang rx
Modified:
team/jdixon/chan_usbradio-1.4/channels/chan_rtpdir.c
Modified: team/jdixon/chan_usbradio-1.4/channels/chan_rtpdir.c
URL: http://svn.digium.com/view/asterisk/team/jdixon/chan_usbradio-1.4/channels/chan_rtpdir.c?view=diff&rev=129800&r1=129799&r2=129800
==============================================================================
--- team/jdixon/chan_usbradio-1.4/channels/chan_rtpdir.c (original)
+++ team/jdixon/chan_usbradio-1.4/channels/chan_rtpdir.c Thu Jul 10 16:36:20 2008
@@ -29,17 +29,10 @@
/*** MODULEINFO
***/
-/* Version 0.1, 07/07/2008
+/* Version 0.2, 07/10/2008
Channel connection for Asterisk to KI4LKF's RtpDir Echolink/IRLP/app_rpt
bridging program for Amateur Radio over VOIP.
-
-Its invoked as rtpdir/HISIP:HISPORT[:MYPORT]
-
-HISIP is the IP address (or FQDN) of the RtpDir program
-HISPORT is the UDP socket of the RtpDir program
-MYPORT (optional) is the UDP socket that Asterisk listens on for this channel
-
This protocol sends UDP packets in both directions containing 4 frames
of 33 byte (160 sample) GSM encoded payload every 80 ms. It indicates
@@ -100,6 +93,8 @@
#define BLOCKING_FACTOR 4
#define GSM_FRAME_SIZE 33
+
+#define QUEUE_OVERLOAD_THRESHOLD 25
static const char tdesc[] = "RTPDIR Ham Radio Bridging Driver";
@@ -177,7 +172,7 @@
if (p->rtpdir)
close(p->rtpdir);
ast_module_user_remove(p->u);
- free(p);
+ ast_free(p);
}
static struct rtpdir_pvt *rtpdir_alloc(void *data)
@@ -202,7 +197,7 @@
if ((!args.hisport) || (!args.hisport[0])) args.hisport = "1234";
if ((!args.myport) || (!args.myport[0])) args.myport = args.hisport;
- p = malloc(sizeof(struct rtpdir_pvt));
+ p = ast_malloc(sizeof(struct rtpdir_pvt));
if (p) {
memset(p, 0, sizeof(struct rtpdir_pvt));
@@ -216,7 +211,7 @@
if (!host)
{
ast_log(LOG_WARNING, "Unable to find host %s\n", args.hisip);
- free(p);
+ ast_free(p);
return NULL;
}
memset((char *) &p->si_other, 0, sizeof(p->si_other));
@@ -227,7 +222,7 @@
if ((p->rtpdir=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1)
{
ast_log(LOG_WARNING, "Unable to create new socket for rtpdir connection\n");
- free(p);
+ ast_free(p);
return(NULL);
}
@@ -241,13 +236,13 @@
if (bind(p->rtpdir, &si_me, sizeof(si_me))==-1)
{
ast_log(LOG_WARNING, "Unable to bind port for rtpdir connection\n");
- free(p);
+ ast_free(p);
return(NULL);
}
if (!p->rtpdir) {
ast_log(LOG_WARNING, "Unable to allocate new rtpdir stream '%s' with flags %d\n", stream, flags);
- free(p);
+ ast_free(p);
return NULL;
}
}
@@ -338,7 +333,7 @@
}
for(i = 0; i < BLOCKING_FACTOR; i++)
{
- qp = malloc(sizeof(struct rtpdir_rxq));
+ qp = ast_malloc(sizeof(struct rtpdir_rxq));
if (!qp)
{
ast_log(LOG_NOTICE,"Cannot malloc for qp\n");
@@ -369,6 +364,7 @@
struct ast_frame fr;
struct rtpdir_rxq *qp;
char buf[GSM_FRAME_SIZE + AST_FRIENDLY_OFFSET];
+ int n;
if (ast->_state != AST_STATE_UP) {
/* Don't try tos end audio on-hook */
@@ -380,37 +376,54 @@
/* if something in rx queue */
if (p->rxq.qe_forw != &p->rxq)
{
- if (!p->rxkey)
- {
- fr.datalen = 0;
- fr.samples = 0;
- fr.frametype = AST_FRAME_CONTROL;
- fr.subclass = AST_CONTROL_RADIO_KEY;
- fr.data = 0;
+ for(n = 0,qp = p->rxq.qe_forw; qp != &p->rxq; qp = qp->qe_forw)
+ {
+ n++;
+ }
+ if (n > QUEUE_OVERLOAD_THRESHOLD)
+ {
+ while(p->rxq.qe_forw != &p->rxq)
+ {
+ qp = p->rxq.qe_forw;
+ remque((struct qelem *)qp);
+ free(qp);
+ }
+ if (p->rxkey) p->rxkey = 1;
+ }
+ else
+ {
+ if (!p->rxkey)
+ {
+ fr.datalen = 0;
+ fr.samples = 0;
+ fr.frametype = AST_FRAME_CONTROL;
+ fr.subclass = AST_CONTROL_RADIO_KEY;
+ fr.data = 0;
+ fr.src = type;
+ fr.offset = 0;
+ fr.mallocd=0;
+ fr.delivery.tv_sec = 0;
+ fr.delivery.tv_usec = 0;
+ ast_queue_frame(ast,&fr);
+ }
+ p->rxkey = MAX_RXKEY_TIME;
+ qp = p->rxq.qe_forw;
+ remque((struct qelem *) qp);
+ memcpy(buf + AST_FRIENDLY_OFFSET,qp->buf,GSM_FRAME_SIZE);
+ ast_free(qp);
+
+ fr.datalen = GSM_FRAME_SIZE;
+ fr.samples = 160;
+ fr.frametype = AST_FRAME_VOICE;
+ fr.subclass = AST_FORMAT_GSM;
+ fr.data = buf + AST_FRIENDLY_OFFSET;
fr.src = type;
- fr.offset = 0;
+ fr.offset = AST_FRIENDLY_OFFSET;
fr.mallocd=0;
fr.delivery.tv_sec = 0;
fr.delivery.tv_usec = 0;
ast_queue_frame(ast,&fr);
- }
- p->rxkey = MAX_RXKEY_TIME;
- qp = p->rxq.qe_forw;
- remque((struct qelem *) qp);
- memcpy(buf + AST_FRIENDLY_OFFSET,qp->buf,GSM_FRAME_SIZE);
- free(qp);
-
- fr.datalen = GSM_FRAME_SIZE;
- fr.samples = 160;
- fr.frametype = AST_FRAME_VOICE;
- fr.subclass = AST_FORMAT_GSM;
- fr.data = buf + AST_FRIENDLY_OFFSET;
- fr.src = type;
- fr.offset = AST_FRIENDLY_OFFSET;
- fr.mallocd=0;
- fr.delivery.tv_sec = 0;
- fr.delivery.tv_usec = 0;
- ast_queue_frame(ast,&fr);
+ }
}
if (p->rxkey == 1)
{
More information about the asterisk-commits
mailing list