aboutsummaryrefslogtreecommitdiffstats
path: root/rtp.c
diff options
context:
space:
mode:
authormarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-05-16 02:50:46 +0000
committermarkster <markster@f38db490-d61c-443f-a65b-d21fe96a405b>2003-05-16 02:50:46 +0000
commitdd5109df85bea6488cfc0a382049b06a5b9d1cb5 (patch)
tree39c8cada755920170ead80735399ae198b7d23ae /rtp.c
parenta03b20a405bfe3d0e78b3276b3133f4968774d12 (diff)
Make RTP ports configurable
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@1026 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'rtp.c')
-rwxr-xr-xrtp.c59
1 files changed, 56 insertions, 3 deletions
diff --git a/rtp.c b/rtp.c
index 90266f837..63cb6c415 100755
--- a/rtp.c
+++ b/rtp.c
@@ -32,6 +32,7 @@
#include <asterisk/channel.h>
#include <asterisk/acl.h>
#include <asterisk/channel_pvt.h>
+#include <asterisk/config.h>
#define TYPE_HIGH 0x0
#define TYPE_LOW 0x1
@@ -41,6 +42,9 @@
static int dtmftimeout = 300; /* 300 samples */
+static int rtpstart = 0;
+static int rtpend = 0;
+
// The value of each payload format mapping:
struct rtpPayloadType {
int isAstFormat; // whether the following code is an AST_FORMAT
@@ -567,6 +571,7 @@ struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io)
struct ast_rtp *rtp;
int x;
int flags;
+ int startplace;
rtp = malloc(sizeof(struct ast_rtp));
if (!rtp)
return NULL;
@@ -583,11 +588,12 @@ struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io)
}
flags = fcntl(rtp->s, F_GETFL);
fcntl(rtp->s, F_SETFL, flags | O_NONBLOCK);
+ /* Find us a place */
+ x = (rand() % (rtpend-rtpstart)) + rtpstart;
+ x = x & ~1;
+ startplace = x;
for (;;) {
- /* Find us a place */
- x = (rand() % (65000-1025)) + 1025;
/* Must be an even port number by RTP spec */
- x = x & ~1;
rtp->us.sin_port = htons(x);
if (!bind(rtp->s, &rtp->us, sizeof(rtp->us)))
break;
@@ -597,6 +603,15 @@ struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io)
free(rtp);
return NULL;
}
+ x += 2;
+ if (x > rtpend)
+ x = (rtpstart + 1) & ~1;
+ if (x == startplace) {
+ ast_log(LOG_WARNING, "No RTP ports remaining\n");
+ close(rtp->s);
+ free(rtp);
+ return NULL;
+ }
}
if (io && sched) {
/* Operate this one in a callback mode */
@@ -1081,3 +1096,41 @@ int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, st
}
return -1;
}
+
+void ast_rtp_reload(void)
+{
+ struct ast_config *cfg;
+ char *s;
+ rtpstart = 5000;
+ rtpend = 31000;
+ cfg = ast_load("rtp.conf");
+ if (cfg) {
+ if ((s = ast_variable_retrieve(cfg, "general", "rtpstart"))) {
+ rtpstart = atoi(s);
+ if (rtpstart < 1024)
+ rtpstart = 1024;
+ if (rtpstart > 65535)
+ rtpstart = 65535;
+ }
+ if ((s = ast_variable_retrieve(cfg, "general", "rtpend"))) {
+ rtpend = atoi(s);
+ if (rtpend < 1024)
+ rtpend = 1024;
+ if (rtpend > 65535)
+ rtpend = 65535;
+ }
+ ast_destroy(cfg);
+ }
+ if (rtpstart >= rtpend) {
+ ast_log(LOG_WARNING, "Unreasonable values for RTP start/end\n");
+ rtpstart = 5000;
+ rtpend = 31000;
+ }
+ if (option_verbose > 1)
+ ast_verbose(VERBOSE_PREFIX_2 "RTP Allocating from port range %d -> %d\n", rtpstart, rtpend);
+}
+
+void ast_rtp_init(void)
+{
+ ast_rtp_reload();
+}