[asterisk-commits] tzafrir: branch tzafrir/monitor-rtp-14 r222538 - in /team/tzafrir/monitor-rtp...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Oct 7 12:21:22 CDT 2009
Author: tzafrir
Date: Wed Oct 7 12:21:19 2009
New Revision: 222538
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=222538
Log:
Reduce diff from monitor-rtp trunk
A bunch of non-functional changes to reduce the diff from trunk.
Modified:
team/tzafrir/monitor-rtp-14/formats/format_rtp.c
team/tzafrir/monitor-rtp-14/res/res_monitor.c
Modified: team/tzafrir/monitor-rtp-14/formats/format_rtp.c
URL: http://svnview.digium.com/svn/asterisk/team/tzafrir/monitor-rtp-14/formats/format_rtp.c?view=diff&rev=222538&r1=222537&r2=222538
==============================================================================
--- team/tzafrir/monitor-rtp-14/formats/format_rtp.c (original)
+++ team/tzafrir/monitor-rtp-14/formats/format_rtp.c Wed Oct 7 12:21:19 2009
@@ -53,47 +53,53 @@
*/
static unsigned char lineartoulaw(short sample)
{
- static int exp_lut[256] = {0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,
- 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
- 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
- 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7};
- int sign, exponent, mantissa;
- unsigned char ulawbyte;
- const int CLIP = 32635;
- const int BIAS = 0x84; /* define the add-in bias for 16 bit samples */
+ static int exp_lut[256] = {
+ 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
+ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
+ };
+ int sign, exponent, mantissa;
+ unsigned char ulawbyte;
+ const int CLIP = 32635;
+ const int BIAS = 0x84; /* define the add-in bias for 16 bit samples */
- /* Get the sample into sign-magnitude. */
- sign = (sample >> 8) & 0x80; /* set aside the sign */
- if (sign != 0) sample = -sample; /* get magnitude */
- if (sample > CLIP) sample = CLIP; /* clip the magnitude */
+ /* Get the sample into sign-magnitude. */
+ sign = (sample >> 8) & 0x80; /* set aside the sign */
+ if (sign != 0)
+ sample = -sample; /* get magnitude */
+ if (sample > CLIP)
+ sample = CLIP; /* clip the magnitude */
- /* Convert from 16 bit linear to ulaw. */
- sample = sample + BIAS;
- exponent = exp_lut[(sample >> 7) & 0xFF];
- mantissa = (sample >> (exponent + 3)) & 0x0F;
- ulawbyte = ~(sign | (exponent << 4) | mantissa);
- if (ulawbyte == 0) ulawbyte = 0x02; /* optional CCITT trap */
- if (ulawbyte == 0xff) ulawbyte = 0x7f; /* never return 0xff */
- return(ulawbyte);
+ /* Convert from 16 bit linear to ulaw. */
+ sample = sample + BIAS;
+ exponent = exp_lut[(sample >> 7) & 0xFF];
+ mantissa = (sample >> (exponent + 3)) & 0x0F;
+ ulawbyte = ~(sign | (exponent << 4) | mantissa);
+ if (ulawbyte == 0)
+ ulawbyte = 0x02; /* optional CCITT trap */
+ if (ulawbyte == 0xff)
+ ulawbyte = 0x7f; /* never return 0xff */
+ return (ulawbyte);
}
-static void rtp_convert_toulaw(unsigned char *dst, const int16_t *src, int samples)
+static void rtp_convert_toulaw(unsigned char *dst, const int16_t * src, int samples)
{
- int i;
+ int i;
- for(i = 0; i < samples; i++)
+ for (i = 0; i < samples; i++)
dst[i] = lineartoulaw(src[i]);
}
@@ -115,8 +121,8 @@
ast_log(LOG_WARNING, "Asked to write non-slinear frame (%d)!\n", f->subclass);
return -1;
}
- rtp_state = (struct monitor_rtp_state *)fs->filename;
- if(!rtp_state) {
+ rtp_state = (struct monitor_rtp_state *) fs->filename;
+ if (!rtp_state) {
ast_log(LOG_WARNING, "No RTP state information for filestream\n");
return -1;
}
@@ -124,20 +130,24 @@
/*
* Build RTP header
*/
- codec = 0; /* AST_FORMAT_ULAW */
- tdiff = (long)ast_tvdiff_ms(ast_tvnow(), rtp_state->ts_start);
+ codec = 0; /* AST_FORMAT_ULAW */
+ tdiff = (long) ast_tvdiff_ms(ast_tvnow(), rtp_state->ts_start);
buf[0] = htonl((2 << 30) | (codec << 16) | (rtp_state->seqno) | (0 << 23));
buf[1] = htonl(tdiff * 8);
buf[2] = htonl(rtp_state->ssrc);
//memcpy(&buf[3], f->data, f->datalen);
- rtp_convert_toulaw((unsigned char*)&buf[3], f->data, f->datalen / 2);
- if((res = sendto(fd, buf, 4*3 + f->datalen / 2, 0, &rtp_state->dest, sizeof(rtp_state->dest))) < 0) {
- ast_log(LOG_WARNING, "Bad sendto #%d (%d bytes): %s\n", rtp_state->seqno, f->datalen, strerror(errno));
+ rtp_convert_toulaw((unsigned char*) &buf[3], f->data, f->datalen / 2);
+ if ((res =
+ sendto(fd, buf, 4 * 3 + f->datalen / 2, 0, &rtp_state->dest,
+ sizeof(rtp_state->dest))) < 0) {
+ ast_log(LOG_WARNING, "Bad sendto #%d (%d bytes): %s\n", rtp_state->seqno,
+ f->datalen, strerror(errno));
return -1;
}
rtp_state->seqno++;
- if((rate_limit++ % 1000) == 0)
- ast_log(LOG_NOTICE, "%s (fd=%d, datalen=%d res=%d)\n", __FUNCTION__, fd, f->datalen, res);
+ if ((rate_limit++ % 1000) == 0)
+ ast_log(LOG_NOTICE, "%s (fd=%d, datalen=%d res=%d)\n", __FUNCTION__, fd,
+ f->datalen, res);
return 0;
}
Modified: team/tzafrir/monitor-rtp-14/res/res_monitor.c
URL: http://svnview.digium.com/svn/asterisk/team/tzafrir/monitor-rtp-14/res/res_monitor.c?view=diff&rev=222538&r1=222537&r2=222538
==============================================================================
--- team/tzafrir/monitor-rtp-14/res/res_monitor.c (original)
+++ team/tzafrir/monitor-rtp-14/res/res_monitor.c Wed Oct 7 12:21:19 2009
@@ -240,28 +240,29 @@
static int sip_stream(const char *server, in_port_t port, struct sockaddr_in *saddr)
{
- int sock;
-
- if((sock = udp_stream(server, port, saddr)) < 0) {
+ int sock;
+
+ if ((sock = udp_stream(server, port, saddr)) < 0) {
ast_log(LOG_WARNING, "Failed to create SIP stream to '%s:%d'\n", server, port);
return -errno;
}
return sock;
}
-static struct ast_filestream *rtp_stream(struct ast_channel *chan, const char *server, uint32_t ssrc)
+static struct ast_filestream *rtp_stream(struct ast_channel *chan,
+ const char *server, uint32_t ssrc)
{
int sock;
struct ast_filestream *fs = NULL;
struct sockaddr_in saddr;
struct monitor_rtp_state *rtp_state;
- if((sock = udp_stream(server, 0, &saddr)) < 0) {
+ if ((sock = udp_stream(server, 0, &saddr)) < 0) {
ast_log(LOG_WARNING, "Failed to create RTP stream to '%s'\n", server);
return NULL;
}
rtp_state = ast_calloc(1, sizeof(*rtp_state));
- if(!rtp_state) {
+ if (!rtp_state) {
ast_log(LOG_NOTICE, "Failed to allocate memory for rtp_state\n");
close(sock);
return NULL;
@@ -271,8 +272,8 @@
rtp_state->ts_start = ast_tvnow();
rtp_state->dest = saddr;
ast_log(LOG_NOTICE, "%s: sockfd=%d\n", __FUNCTION__, sock);
- fs = ast_writefile((const char *)rtp_state, PCM_FORMAT, "UDP", 0, sock, 0);
- if(!fs) {
+ fs = ast_writefile((const char *) rtp_state, PCM_FORMAT, "UDP", 0, sock, 0);
+ if (!fs) {
ast_log(LOG_WARNING, "No such format '%s'\n", PCM_FORMAT);
ast_free(rtp_state);
}
@@ -280,42 +281,42 @@
}
#ifdef RTP_MONITOR_DEBUG
-static const char *cdr_readonly_vars[] = { "clid", "src", "dst", "dcontext", "channel", "dstchannel",
- "lastapp", "lastdata", "start", "answer", "end", "duration",
- "billsec", "disposition", "amaflags", "accountcode", "uniqueid",
- "userfield", NULL };
+static const char *cdr_readonly_vars[] =
+ { "clid", "src", "dst", "dcontext", "channel", "dstchannel",
+ "lastapp", "lastdata", "start", "answer", "end", "duration",
+ "billsec", "disposition", "amaflags", "accountcode", "uniqueid",
+ "userfield", NULL
+};
#endif /* ifdef RTP_MONITOR_DEBUG */
static int send_cdr(struct ast_channel *chan, int begin, int is_rx, struct monitor_rtp_state *rtp_state)
{
- char *src;
- char *dst;
- char *clid;
- char srcbuf[BUFSIZ];
- char dstbuf[BUFSIZ];
- char clidbuf[BUFSIZ];
- char header[BUFSIZ];
- char payload[BUFSIZ];
- char packet[BUFSIZ];
- struct sockaddr_in my_addr;
- char my_ip[INET_ADDRSTRLEN + 1];
- char dst_ip[INET_ADDRSTRLEN + 1];
- in_port_t rtp_port = rtp_state->dest.sin_port;
+ char *src;
+ char *dst;
+ char *clid;
+ char srcbuf[BUFSIZ];
+ char dstbuf[BUFSIZ];
+ char clidbuf[BUFSIZ];
+ char header[BUFSIZ];
+ char payload[BUFSIZ];
+ char packet[BUFSIZ];
+ struct sockaddr_in my_addr;
+ char my_ip[INET_ADDRSTRLEN + 1];
+ char dst_ip[INET_ADDRSTRLEN + 1];
+ in_port_t rtp_port = rtp_state->dest.sin_port;
struct ast_cdr *cdr = chan ? chan->cdr : NULL;
- int content_length;
- int i;
+ int content_length;
+ int i;
if (!cdr)
return -1;
ast_log(LOG_NOTICE, "%s-%s(%d): %s\n",
- (begin) ? "BEGIN" : "END",
- (is_rx) ? "RX" : "TX",
- ntohs(rtp_port),
- chan->uniqueid);
+ (begin) ? "BEGIN" : "END",
+ (is_rx) ? "RX" : "TX", ntohs(rtp_port), chan->uniqueid);
#if 0
/* Debugging code */
{
- char buf[BUFSIZ];
+ char buf[BUFSIZ];
buf[0] = '\0';
ast_cdr_serialize_variables(cdr, buf, sizeof(buf), '\t', '\n', 1);
@@ -324,13 +325,13 @@
#endif
#ifdef RTP_MONITOR_DEBUG
{
- char buf[BUFSIZ];
- int len = sizeof(buf);
-
- for(i = 0; cdr_readonly_vars[i]; i++) {
+ char buf[BUFSIZ];
+ int len = sizeof(buf);
+
+ for (i = 0; cdr_readonly_vars[i]; i++) {
buf[0] = '\0';
ast_cdr_getvar(cdr, cdr_readonly_vars[i], &ret, buf, len, 0, 0);
- if(ret) {
+ if (ret) {
ast_log(LOG_NOTICE, "%-20s - '%s'\n",
cdr_readonly_vars[i], ret);
}
@@ -341,7 +342,7 @@
ast_log(LOG_WARNING, "Bad reporting_host: '%s'\n", reporting_host);
return -1;
}
- if(inet_ntop(AF_INET, &my_addr.sin_addr, my_ip, sizeof(my_ip)) == NULL) {
+ if (inet_ntop(AF_INET, &my_addr.sin_addr, my_ip, sizeof(my_ip)) == NULL) {
ast_log(LOG_WARNING, "Cannot convert ip address: %s\n", strerror(errno));
return -1;
}
@@ -389,7 +390,7 @@
(begin) ? "BEGIN" : "END",
(is_rx) ? "RX" : "TX",
clid);
- if(begin) {
+ if (begin) {
i += snprintf(header + i, sizeof(header) - i, "Content-Type: application/sdp\r\n");
}
i += snprintf(header + i, sizeof(header) - i, "Content-Length: %d\r\n", content_length);
@@ -397,7 +398,7 @@
ast_log(LOG_WARNING, "SIP header: %s\n", header);
ast_log(LOG_WARNING, "SIP payload: %s\n", payload);
ast_log(LOG_WARNING, "SIP packet: %s\n", packet);
- if(sendto(sip_socket, packet, i, 0, &sip_server_addr, sizeof(sip_server_addr)) < 0) {
+ if (sendto(sip_socket, packet, i, 0, &sip_server_addr, sizeof(sip_server_addr)) < 0) {
ast_log(LOG_WARNING, "Bad SIP sendto (%d bytes): %s\n", i, strerror(errno));
return -1;
}
@@ -408,16 +409,18 @@
{
ast_log(LOG_NOTICE, "STOP monitor2rtp\n");
LOCK_IF_NEEDED(chan, need_lock);
- if ((chan->monitor)) {
+ if (chan->monitor) {
struct monitor_rtp_state *rtp_state_rx;
struct monitor_rtp_state *rtp_state_tx;
- rtp_state_rx = (struct monitor_rtp_state *)chan->monitor->read_stream->filename;
- rtp_state_tx = (struct monitor_rtp_state *)chan->monitor->write_stream->filename;
+ rtp_state_rx = (struct monitor_rtp_state *)
+ chan->monitor->read_stream->filename;
+ rtp_state_tx = (struct monitor_rtp_state *)
+ chan->monitor->write_stream->filename;
if (chan->monitor->read_stream) {
ast_log(LOG_NOTICE, "%s: close read_stream\n", __FUNCTION__);
- if(rtp_state_rx) {
+ if (rtp_state_rx) {
send_cdr(chan, 0, 1, rtp_state_rx);
chan->monitor->read_stream->filename = NULL;
ast_free(rtp_state_rx);
@@ -438,18 +441,19 @@
return 0;
}
-static void calc_ssrc(struct ast_channel *chan, uint32_t *rx_ssrc, uint32_t *tx_ssrc)
-{
- float val;
-
- if(chan->uniqueid && sscanf(chan->uniqueid, "%f", &val) == 1) {
- time_t t;
- int a;
- uint32_t ssrc;
-
- t = (time_t)val;
+static void calc_ssrc(struct ast_channel *chan, uint32_t * rx_ssrc, uint32_t * tx_ssrc)
+{
+ float val;
+
+ if (chan->uniqueid && sscanf(chan->uniqueid, "%f", &val) == 1) {
+ time_t t;
+ int a;
+ uint32_t ssrc;
+
+ t = (time_t) val;
a = (val - t) * 10;
- ast_log(LOG_DEBUG, "%s: val=%f t=%lu a=%d\n", __FUNCTION__, val, (unsigned long)t, a);
+ ast_log(LOG_DEBUG, "%s: val=%f t=%lu a=%d\n", __FUNCTION__, val,
+ (unsigned long)t, a);
ssrc = (t << 8) | ((a << 4) & 0xFF);
ast_log(LOG_DEBUG, "%s: ssrc=%u\n", __FUNCTION__, ssrc);
*rx_ssrc = ssrc;
@@ -457,8 +461,8 @@
return;
}
ast_log(LOG_WARNING,
- "%s: Failed to parse uniqueid='%s' using random SSRC\n",
- __FUNCTION__, chan->uniqueid);
+ "%s: Failed to parse uniqueid='%s' using random SSRC\n",
+ __FUNCTION__, chan->uniqueid);
*rx_ssrc = ast_random();
*tx_ssrc = ast_random();
}
@@ -468,9 +472,9 @@
struct ast_channel_monitor *monitor;
struct monitor_rtp_state *rtp_state_rx;
struct monitor_rtp_state *rtp_state_tx;
- uint32_t rx_ssrc;
- uint32_t tx_ssrc;
- int ret = -1;
+ uint32_t rx_ssrc;
+ uint32_t tx_ssrc;
+ int ret = -1;
ast_log(LOG_NOTICE, "START monitor2rtp\n");
LOCK_IF_NEEDED(chan, need_lock);
@@ -479,30 +483,34 @@
}
calc_ssrc(chan, &rx_ssrc, &tx_ssrc);
ast_log(LOG_NOTICE, "%s: rx_ssrc=%u tx_ssrc=%u\n", __FUNCTION__, rx_ssrc, tx_ssrc);
- /* RX port */
- monitor->read_stream = rtp_stream(chan, rtp_server_name, rx_ssrc);
+
+ monitor->read_stream =
+ rtp_stream(chan, rtp_server_name, rx_ssrc);
if (!monitor->read_stream) {
ast_log(LOG_WARNING, "Could not create UDP stream for read\n");
goto out;
}
- /* TX port */
- monitor->write_stream = rtp_stream(chan, rtp_server_name, tx_ssrc);
+
+ monitor->write_stream =
+ rtp_stream(chan, rtp_server_name, tx_ssrc);
if (!monitor->write_stream) {
ast_log(LOG_WARNING, "Could not create UDP stream for write\n");
ast_closestream(monitor->read_stream);
goto out;
}
- rtp_state_rx = (struct monitor_rtp_state *)(monitor->read_stream->filename);
- rtp_state_tx = (struct monitor_rtp_state *)(monitor->write_stream->filename);
+ rtp_state_rx = (struct monitor_rtp_state *)
+ (monitor->read_stream->filename);
+ rtp_state_tx = (struct monitor_rtp_state *)
+ (monitor->write_stream->filename);
send_cdr(chan, 1, 1, rtp_state_rx);
send_cdr(chan, 1, 0, rtp_state_tx);
monitor->stop = monitor2rtp_stop;
chan->monitor = monitor;
ast_monitor_set_state(chan, AST_MONITOR_RUNNING);
/* so we know this call has been monitored in case we need to bill for it or something */
- pbx_builtin_setvar_helper(chan, "__MONITORED","true");
+ pbx_builtin_setvar_helper(chan, "__MONITORED", "true");
ret = 0;
-out:
+ out:
UNLOCK_IF_NEEDED(chan, need_lock);
return 0;
}
@@ -1057,8 +1065,8 @@
static int reload_config(enum channelreloadreason reason, int startup)
{
- struct ast_config *cfg;
- struct ast_variable *v;
+ struct ast_config *cfg;
+ struct ast_variable *v;
ast_log(LOG_DEBUG, "%s [%s]\n", channelreloadreason2txt(reason), config_file);
cfg = ast_config_load(config_file);
@@ -1100,11 +1108,12 @@
ast_copy_string(reporting_host, v->value, sizeof(reporting_host));
} else {
ast_log(LOG_NOTICE, "%s:%d: Bad config option '%s' - (ignoring)\n",
- config_file, v->lineno, v->name);
- }
- }
+ config_file, v->lineno, v->name);
+ }
+ }
+ /* FIXME: check that rtp_mon_end > rtp_mon_start */
ast_log(LOG_DEBUG, "monitor to %s [RX=%d, TX=%d]\n",
- rtp_server_name, rtp_mon_start, rtp_mon_end);
+ rtp_server_name, rtp_mon_start, rtp_mon_end);
ast_config_destroy(cfg);
return 0;
}
@@ -1117,10 +1126,11 @@
static int load_module(void)
{
- if(reload_config(CHANNEL_MODULE_LOAD, 1))
+ if (reload_config(CHANNEL_MODULE_LOAD, 1)) {
return AST_MODULE_LOAD_DECLINE;
- if(rtp_server_name[0] != '\0') {
- if((sip_socket = sip_stream(rtp_server_name, 5060, &sip_server_addr)) < 0) {
+ }
+ if (rtp_server_name[0] != '\0') {
+ if ((sip_socket = sip_stream(rtp_server_name, 5060, &sip_server_addr)) < 0) {
ast_log(LOG_WARNING,
"Failed to create SIP stream to '%s:%d'\n",
rtp_server_name, 5060);
@@ -1154,8 +1164,9 @@
ast_manager_unregister("PauseMonitor");
ast_manager_unregister("UnpauseMonitor");
- if(sip_socket != -1)
+ if (sip_socket != -1) {
close(sip_socket);
+ }
return 0;
}
More information about the asterisk-commits
mailing list