[asterisk-commits] jdixon: branch jdixon/chan_usbradio-1.4 r141021 - in /team/jdixon/chan_usbrad...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Sep 4 03:10:18 CDT 2008
Author: jdixon
Date: Thu Sep 4 03:10:17 2008
New Revision: 141021
URL: http://svn.digium.com/view/asterisk?view=rev&rev=141021
Log:
Added support for DTMF, etc
Removed:
team/jdixon/chan_usbradio-1.4/dev-1.0/channels/irlp-scripts/irlp_fullreset
Modified:
team/jdixon/chan_usbradio-1.4/dev-1.0/channels/chan_irlp.c
Modified: team/jdixon/chan_usbradio-1.4/dev-1.0/channels/chan_irlp.c
URL: http://svn.digium.com/view/asterisk/team/jdixon/chan_usbradio-1.4/dev-1.0/channels/chan_irlp.c?view=diff&rev=141021&r1=141020&r2=141021
==============================================================================
--- team/jdixon/chan_usbradio-1.4/dev-1.0/channels/chan_irlp.c (original)
+++ team/jdixon/chan_usbradio-1.4/dev-1.0/channels/chan_irlp.c Thu Sep 4 03:10:17 2008
@@ -29,7 +29,7 @@
/*** MODULEINFO
***/
-/* Version 0.5, 9/2/2008
+/* Version 0.6, 9/4/2008
irlp channel driver for Asterisk/app_rpt.
This is a first attempt.
@@ -92,7 +92,6 @@
#include "asterisk/options.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
-#include "asterisk/dsp.h"
#include "asterisk/translate.h"
#include "asterisk/cli.h"
@@ -121,7 +120,13 @@
#define IRLP_CALL_REFL "su - repeater /tmp/irlpwrap /home/irlp/scripts/connect_to_reflector ref%04d &"
#define IRLP_CALL "su - repeater /tmp/irlpwrap /home/irlp/scripts/call stn%04d &"
#define IRLP_WRAPPER "echo '#! /bin/sh\n\n. /home/irlp/custom/environment\n" \
- "exec $1 $2 $3\n' > /tmp/irlpwrap ; chown repeater /tmp/irlpwrap ; chmod 755 /tmp/irlpwrap"
+ "exec $1 $2 $3 $4 $5 $6\n' > /tmp/irlpwrap ; chown repeater /tmp/irlpwrap ; chmod 755 /tmp/irlpwrap"
+#define IRLP_AST_PLAYFILE "rpt playback %s /home/irlp/astrun/astplay"
+#define IRLP_PLAY_FILE "/home/irlp/astrun/astplay.pcm"
+#define IRLP_DTMF_FIFO "/home/irlp/astrun/dtmf_fifo"
+#define IRLP_MAKE_FIFO "(/bin/mknod /home/irlp/astrun/dtmf_fifo p;" \
+ "chown repeater /home/irlp/astrun/dtmf_fifo) > /dev/null 2>&1"
+#define IRLP_SEND_DTMF "su - repeater /tmp/irlpwrap \"/home/irlp/scripts/fifoecho stn%04d dtmfregen %s\""
enum {IRLP_NOPROTO,IRLP_ISADPCM,IRLP_ISGSM} ;
@@ -201,8 +206,12 @@
static struct ast_channel *curcall = NULL;
AST_MUTEX_DEFINE_STATIC(irlplock);
static char stream[256];
-struct ast_dsp *dsp = NULL;
-struct ast_trans_pvt *xpath = NULL;
+static int nullfd = -1;
+static int dfd = -1;
+static int playing = 0;
+static unsigned int xcount = 0;
+static char havedtmf = 0;
+static char irlp_dtmf_string[64];
#ifdef OLD_ASTERISK
#define ast_free free
@@ -256,6 +265,8 @@
tx_audio_port = audio_port_cfg;
audio_port = audio_port_cfg;
ctrl_port = audio_port + 1;
+ havedtmf = 0;
+ memset(irlp_dtmf_string,0,sizeof(irlp_dtmf_string));
if (curcall)
{
curcall->nativeformats = AST_FORMAT_ADPCM;
@@ -418,13 +429,6 @@
else if (proto != IRLP_ISGSM)
ast_log(LOG_NOTICE,"irlp channel format changed to GSM\n");
proto = IRLP_ISGSM;
- if (xpath) ast_translator_free_path(xpath);
- xpath = ast_translator_build_path(AST_FORMAT_SLINEAR,AST_FORMAT_GSM);
- if (!xpath)
- {
- ast_log(LOG_ERROR,"Cannot get translator!!\n");
- return;
- }
ast->nativeformats = AST_FORMAT_GSM;
}
else
@@ -434,13 +438,6 @@
else if (proto != IRLP_ISADPCM)
ast_log(LOG_NOTICE,"irlp channel format changed to GSM\n");
proto = IRLP_ISADPCM;
- if (xpath) ast_translator_free_path(xpath);
- xpath = ast_translator_build_path(AST_FORMAT_SLINEAR,AST_FORMAT_ADPCM);
- if (!xpath)
- {
- ast_log(LOG_ERROR,"Cannot get translator!!\n");
- return;
- }
ast->nativeformats = AST_FORMAT_ADPCM;
}
ast_set_read_format(ast,ast->readformat);
@@ -454,7 +451,7 @@
static void *irlp_reader(void *nothing)
{
- fd_set fds[2];
+ fd_set fds[3];
struct timeval tmout;
int i,myaud,myctl,x;
@@ -465,11 +462,21 @@
socklen_t fromlen;
ssize_t recvlen;
size_t len;
+ struct stat statbuf;
ast_log(LOG_NOTICE, "IRLP reader thread started.\n");
while(run_forever)
{
if ((proto == IRLP_NOPROTO) && curcall) process_codec_file(curcall);
+ i = ((stat(IRLP_PLAY_FILE,&statbuf) != -1));
+ if (i != playing)
+ {
+ char mystr[60];
+
+ snprintf(mystr,sizeof(mystr) - 1,IRLP_AST_PLAYFILE,astnode);
+ if (!playing) ast_cli_command(nullfd,mystr);
+ playing = i;
+ }
myaud = (alt_audio_sock != -1) ? alt_audio_sock : audio_sock;
myctl = (alt_ctrl_sock != -1) ? alt_ctrl_sock : ctrl_sock;
FD_ZERO(fds);
@@ -588,13 +595,6 @@
else if (proto != IRLP_ISADPCM)
ast_log(LOG_NOTICE,"irlp channel format changed to GSM\n");
proto = IRLP_ISADPCM;
- if (xpath) ast_translator_free_path(xpath);
- xpath = ast_translator_build_path(AST_FORMAT_SLINEAR,AST_FORMAT_ADPCM);
- if (!xpath)
- {
- ast_log(LOG_ERROR,"Cannot get translator!!\n");
- break;
- }
if (curcall)
{
@@ -610,13 +610,6 @@
else if (proto != IRLP_ISGSM)
ast_log(LOG_NOTICE,"irlp channel format changed to GSM\n");
proto = IRLP_ISGSM;
- if (xpath) ast_translator_free_path(xpath);
- xpath = ast_translator_build_path(AST_FORMAT_SLINEAR,AST_FORMAT_GSM);
- if (!xpath)
- {
- ast_log(LOG_ERROR,"Cannot get translator!!\n");
- pthread_exit(NULL);
- }
if (curcall)
{
curcall->nativeformats = AST_FORMAT_GSM;
@@ -667,8 +660,7 @@
ast_mutex_unlock(&irlplock);
if (run_forever)
{
- x = open("/dev/null",O_RDWR);
- ast_cli_command(x,"rpt restart");
+ ast_cli_command(nullfd,"rpt restart");
}
run_forever = 0;
ast_log(LOG_NOTICE, "IRLP read thread exited.\n");
@@ -730,7 +722,6 @@
si_me.sin_family = AF_INET;
si_me.sin_addr.s_addr = htonl(INADDR_ANY);
si_me.sin_port = htons(tx_audio_port);
-printf("foop alt audio port %d bound to port %d\n",alt_audio_sock,tx_audio_port);
if (bind(alt_audio_sock, &si_me, sizeof(si_me))==-1)
{
ast_log(LOG_WARNING, "Unable to bind port for irlp audio connection\n");
@@ -766,7 +757,6 @@
}
reset_stuff();
ast_safe_system(IRLP_END);
- ast_safe_system(IRLP_RESET);
irlp_destroy(p);
ast->tech_pvt = NULL;
ast_setstate(ast, AST_STATE_DOWN);
@@ -796,6 +786,23 @@
static int irlp_text(struct ast_channel *ast, const char *text)
{
+int destnode,hisnode,seqno,i;
+char c;
+
+ struct irlp_pvt *p = ast->tech_pvt;
+
+ if (!p->txkey) return(0);
+ if (text[0] != 'D') return 0;
+ if (sscanf(text + 2,"%d %d %d %c",&destnode,&hisnode,&seqno,&c) != 4) return(0);
+ if (destnode != (in_node + 40000)) return(0);
+ if (c == '*') c = 'S';
+ if (c == '#') c = 'P';
+ i = strlen(irlp_dtmf_string);
+ if (i < (sizeof(irlp_dtmf_string) - 1))
+ {
+ irlp_dtmf_string[i + 1] = 0;
+ irlp_dtmf_string[i] = c;
+ }
return 0;
}
@@ -832,12 +839,13 @@
struct irlp_pvt *p = ast->tech_pvt;
struct ast_frame fr;
struct irlp_rxqast *qpast;
- int n,i,x,len,gotone,dosync,blocking_factor,frame_size,frame_samples;
+ int n,i,len,gotone,dosync,blocking_factor,frame_size,frame_samples,recvlen;
char outbuf[ADPCM_FRAME_SIZE + AST_FRIENDLY_OFFSET + 3]; /* turns out that ADPCM is larger */
struct irlp_audio irlp_audio_packet;
static char tx_buf[(ADPCM_BLOCKING_FACTOR * ADPCM_FRAME_SIZE) + 3]; /* turns out the ADPCM is larger */
- char *outbuf_new,*cp;
+ char *outbuf_new,*cp,c,str[200];
unsigned char *dp;
+ static int lasttx = 0;
if (ast->_state != AST_STATE_UP)
return 0;
@@ -847,6 +855,44 @@
if (proto == IRLP_NOPROTO) return 0;
+ if ((xcount++ & 3) == 0) /* every 80 ms */
+ {
+ struct ast_frame fr;
+
+ fr.datalen = 0;
+ fr.samples = 0;
+ fr.frametype = AST_FRAME_DTMF_END;
+ fr.subclass = havedtmf;
+ fr.len = 80;
+ fr.data = 0;
+ fr.src = type;
+ fr.offset = 0;
+ fr.mallocd=0;
+ fr.delivery.tv_sec = 0;
+ fr.delivery.tv_usec = 0;
+ if (havedtmf)
+ {
+ if (curcall) ast_queue_frame(curcall,&fr);
+ ast_log(LOG_NOTICE,"Got DTMF %c on IRLP\n",havedtmf);
+ havedtmf = 0;
+ }
+ else
+ {
+ recvlen = read(dfd,&c,1);
+ if ((recvlen > 0) && strchr("0123456789SPABCD",c))
+ {
+
+ if (c == 'S') c = '#';
+ if (c == 'P') c = '*';
+
+ fr.len = 0;
+ fr.subclass = c;
+ fr.frametype = AST_FRAME_DTMF_BEGIN;
+ if (curcall) ast_queue_frame(curcall,&fr);
+ havedtmf = c;
+ }
+ }
+ }
frame_samples = 160;
if (proto == IRLP_ISGSM)
{
@@ -979,28 +1025,7 @@
fr.delivery.tv_sec = 0;
fr.delivery.tv_usec = 0;
- x = 0;
- if (dsp && (!radmode))
- {
- struct ast_frame *f1,*f2;
-
- f2 = ast_translate(xpath,&fr,0);
- f1 = ast_dsp_process(NULL,dsp,f2);
- ast_frfree(f2);
- if ((f1->frametype == AST_FRAME_DTMF_END) ||
- (f1->frametype == AST_FRAME_DTMF_BEGIN))
- {
- if ((f1->subclass != 'm') && (f1->subclass != 'u'))
- {
- if (f1->frametype == AST_FRAME_DTMF_END)
- ast_log(LOG_NOTICE,"IRLP Got DTMF char %c\n",f1->subclass);
- ast_queue_frame(ast,f1);
- x = 1;
- }
- }
- ast_frfree(f1);
- }
- if (!x) ast_queue_frame(ast,&fr);
+ ast_queue_frame(ast,&fr);
}
if (p->rxkey == 1) {
fr.datalen = 0;
@@ -1020,6 +1045,18 @@
rxidx = 0;
}
if (p->rxkey) p->rxkey--;
+
+ if (lasttx != p->txkey)
+ {
+ lasttx = p->txkey;
+ if ((!p->txkey) && irlp_dtmf_string[0])
+ {
+ sprintf(str,IRLP_SEND_DTMF,in_node,irlp_dtmf_string);
+ ast_safe_system(str);
+ ast_log(LOG_NOTICE,"Sent DTMF %s to IRLP\n",irlp_dtmf_string);
+ }
+ irlp_dtmf_string[0] = 0;
+ }
if (!p->txkey) return(0);
@@ -1101,7 +1138,6 @@
}
txindex = 0;
}
-
if (p->txkey) return 0;
if (p->keepalive--) return 0;
p->keepalive = KEEPALIVE_TIME;
@@ -1168,6 +1204,7 @@
ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format '%d'\n", oldformat);
return NULL;
}
+ unlink(IRLP_PLAY_FILE);
ast_safe_system(IRLP_RESET);
usleep(10000);
reset_stuff();
@@ -1183,8 +1220,6 @@
static int unload_module(void)
{
- if (dsp) ast_dsp_free(dsp);
- if (xpath) ast_translator_free_path(xpath);
run_forever = 0;
usleep(100000);
if (audio_sock != -1) close(audio_sock);
@@ -1195,6 +1230,8 @@
alt_audio_sock = -1;
if (alt_ctrl_sock != -1) close(alt_ctrl_sock);
alt_ctrl_sock = -1;
+ if (nullfd != -1) close(nullfd);
+ if (dfd != -1) close(dfd);
/* First, take us out of the channel loop */
ast_channel_unregister(&irlp_tech);
return 0;
@@ -1275,20 +1312,6 @@
ast_config_destroy(cfg);
- dsp = ast_dsp_new();
- if (!dsp)
- {
- ast_log(LOG_ERROR,"Cannot get dsp facility\n");
- return -1;
- }
-#ifdef NEW_ASTERISK
- ast_dsp_set_features(dsp,DSP_FEATURE_DIGIT_DETECT);
- ast_dsp_set_digitmode(dsp,DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_RELAXDTMF);
-#else
- ast_dsp_set_features(dsp,DSP_FEATURE_DTMF_DETECT);
- ast_dsp_digitmode(dsp,DSP_DIGITMODE_DTMF | DSP_DIGITMODE_MUTECONF | DSP_DIGITMODE_RELAXDTMF);
-#endif
-
ast_safe_system(IRLP_RESET);
usleep(10000);
@@ -1328,8 +1351,18 @@
}
fcntl(audio_sock,F_SETFL,O_NONBLOCK);
fcntl(ctrl_sock,F_SETFL,O_NONBLOCK);
-
+ nullfd = open("/dev/null",O_RDWR);
+
+ ast_safe_system(IRLP_MAKE_FIFO);
+ dfd = open(IRLP_DTMF_FIFO,O_RDONLY | O_NONBLOCK);
+ if (dfd == -1)
+ {
+ ast_log(LOG_ERROR,"Cannot open FIFO for DTMF!!\n");
+ return AST_MODULE_LOAD_DECLINE;
+ }
ast_safe_system(IRLP_RESET);
+ unlink(IRLP_PLAY_FILE);
+
usleep(100000);
cfg = NULL;
More information about the asterisk-commits
mailing list