refine
This commit is contained in:
parent
902e7f8e30
commit
2441e32b79
2 changed files with 175 additions and 159 deletions
43
d-modem.c
43
d-modem.c
|
@ -54,6 +54,7 @@ int wave_transmit = -1;
|
||||||
uint8_t mode = DMODEM_DIAL_MODE;
|
uint8_t mode = DMODEM_DIAL_MODE;
|
||||||
uint8_t ringing = 0;
|
uint8_t ringing = 0;
|
||||||
uint8_t answered = 0;
|
uint8_t answered = 0;
|
||||||
|
int ppid;
|
||||||
pjsua_call_id incoming;
|
pjsua_call_id incoming;
|
||||||
|
|
||||||
struct dmodem {
|
struct dmodem {
|
||||||
|
@ -74,7 +75,7 @@ static void error_exit(const char *title, pj_status_t status) {
|
||||||
pjsua_destroy();
|
pjsua_destroy();
|
||||||
stop_pa();
|
stop_pa();
|
||||||
if (answered)
|
if (answered)
|
||||||
execl("/bin/sh", "/bin/sh", "-cx", "kill -INT $PPID", NULL);
|
kill(ppid, SIGINT);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,7 +179,7 @@ static pj_status_t dmodem_get_frame(pjmedia_port *this_port, pjmedia_frame *fram
|
||||||
static pj_status_t dmodem_on_destroy(pjmedia_port *this_port) {
|
static pj_status_t dmodem_on_destroy(pjmedia_port *this_port) {
|
||||||
printf("destroy\n");
|
printf("destroy\n");
|
||||||
if (answered)
|
if (answered)
|
||||||
execl("/bin/sh", "/bin/sh", "-cx", "kill -INT $PPID", NULL);
|
kill(ppid, SIGINT);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +201,7 @@ static void on_call_state(pjsua_call_id call_id, pjsip_event *e) {
|
||||||
pjsua_destroy();
|
pjsua_destroy();
|
||||||
stop_pa();
|
stop_pa();
|
||||||
if (answered)
|
if (answered)
|
||||||
execl("/bin/sh", "/bin/sh", "-cx", "kill -INT $PPID", NULL);
|
kill(ppid, SIGINT);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,11 +214,11 @@ static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, pjsip_r
|
||||||
strcpy(tmp, ci.remote_contact.ptr);
|
strcpy(tmp, ci.remote_contact.ptr);
|
||||||
tmp[pj_strlen(&ci.remote_contact)] = '\0';
|
tmp[pj_strlen(&ci.remote_contact)] = '\0';
|
||||||
if (answered) {
|
if (answered) {
|
||||||
printf("Incoming call rejected from: %s\n", tmp);
|
PJ_LOG(2,(__FILE__, "Incoming call rejected from: %s", tmp));
|
||||||
pjsua_call_hangup(call_id, 0u, NULL, NULL);
|
pjsua_call_hangup(call_id, 0u, NULL, NULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
printf("Incoming call from: %s\n", tmp);
|
PJ_LOG(2,(__FILE__, "Incoming call from: %s", tmp));
|
||||||
free(tmp);
|
free(tmp);
|
||||||
incoming = call_id;
|
incoming = call_id;
|
||||||
ringing = 1;
|
ringing = 1;
|
||||||
|
@ -247,9 +248,21 @@ static void on_call_media_state(pjsua_call_id call_id) {
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
pjsua_acc_id acc_id;
|
pjsua_acc_id acc_id;
|
||||||
pj_status_t status;
|
pj_status_t status;
|
||||||
if (argc != 3) {
|
if (argc != 5) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
ppid = atoi(argv[3]);
|
||||||
|
char* _modemid_tmp = argv[4];
|
||||||
|
for (size_t i = strlen(_modemid_tmp) - 1 ; ; i--) {
|
||||||
|
if (i < 0 || _modemid_tmp[i] < '0' || _modemid_tmp[i] > '9') {
|
||||||
|
_modemid_tmp += i+1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int sip_port = atoi(_modemid_tmp);
|
||||||
|
sip_port = sip_port >= 0 ? sip_port : 0;
|
||||||
|
sip_port += 5060;
|
||||||
|
sip_port = sip_port <= 65535 ? sip_port : 65535;
|
||||||
if(!strncmp(argv[1], "rr", 2)) {
|
if(!strncmp(argv[1], "rr", 2)) {
|
||||||
mode = DMODEM_ANSWER_MODE;
|
mode = DMODEM_ANSWER_MODE;
|
||||||
}
|
}
|
||||||
|
@ -297,17 +310,16 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pjsua_logging_config_default(&log_cfg);
|
pjsua_logging_config_default(&log_cfg);
|
||||||
log_cfg.console_level = 4;
|
// log_cfg.console_level = 4;
|
||||||
|
log_cfg.console_level = 2;
|
||||||
|
|
||||||
pjsua_media_config_default(&med_cfg);
|
pjsua_media_config_default(&med_cfg);
|
||||||
med_cfg.no_vad = true;
|
med_cfg.no_vad = true;
|
||||||
med_cfg.ec_tail_len = 0;
|
med_cfg.ec_tail_len = 0;
|
||||||
med_cfg.jb_max = 2000;
|
med_cfg.jb_max = -1;
|
||||||
// med_cfg.jb_init = 200;
|
med_cfg.jb_init = -1;
|
||||||
/* // med_cfg.jb_init = 200 */
|
|
||||||
// med_cfg.jb_init = 0;
|
|
||||||
/* med_cfg.audio_frame_ptime = 5; */
|
|
||||||
med_cfg.audio_frame_ptime = 10;
|
med_cfg.audio_frame_ptime = 10;
|
||||||
|
med_cfg.quality = 10;
|
||||||
|
|
||||||
status = pjsua_init(&cfg, &log_cfg, &med_cfg);
|
status = pjsua_init(&cfg, &log_cfg, &med_cfg);
|
||||||
if (status != PJ_SUCCESS) error_exit("Error in pjsua_init()", status);
|
if (status != PJ_SUCCESS) error_exit("Error in pjsua_init()", status);
|
||||||
|
@ -338,7 +350,7 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
pjsua_transport_config_default(&cfg);
|
pjsua_transport_config_default(&cfg);
|
||||||
if (mode)
|
if (mode)
|
||||||
cfg.port = 5160;
|
cfg.port = sip_port;
|
||||||
if (getenv("PJSIP_IPV6"))
|
if (getenv("PJSIP_IPV6"))
|
||||||
status = pjsua_transport_create(PJSIP_TRANSPORT_UDP6, &cfg, &transport_id);
|
status = pjsua_transport_create(PJSIP_TRANSPORT_UDP6, &cfg, &transport_id);
|
||||||
else
|
else
|
||||||
|
@ -346,7 +358,7 @@ int main(int argc, char *argv[]) {
|
||||||
if (status != PJ_SUCCESS) error_exit("Error creating transport", status);
|
if (status != PJ_SUCCESS) error_exit("Error creating transport", status);
|
||||||
}
|
}
|
||||||
char buf[384];
|
char buf[384];
|
||||||
printf("Initializing pool\n");
|
//printf("Initializing pool\n");
|
||||||
pj_caching_pool cp;
|
pj_caching_pool cp;
|
||||||
pj_caching_pool_init(&cp, NULL, 1024*1024);
|
pj_caching_pool_init(&cp, NULL, 1024*1024);
|
||||||
pool = pj_pool_create(&cp.factory, "pool1", 4000, 4000, NULL);
|
pool = pj_pool_create(&cp.factory, "pool1", 4000, 4000, NULL);
|
||||||
|
@ -387,7 +399,6 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("acc add local\n");
|
|
||||||
status == pjsua_acc_add_local(transport_id, 1, &acc_id);
|
status == pjsua_acc_add_local(transport_id, 1, &acc_id);
|
||||||
if (status != PJ_SUCCESS) error_exit("Error adding local account", status);
|
if (status != PJ_SUCCESS) error_exit("Error adding local account", status);
|
||||||
}
|
}
|
||||||
|
@ -401,7 +412,7 @@ int main(int argc, char *argv[]) {
|
||||||
snprintf(buf,sizeof(buf),"sip:%s@%s",dialstr,sip_domain);
|
snprintf(buf,sizeof(buf),"sip:%s@%s",dialstr,sip_domain);
|
||||||
else
|
else
|
||||||
snprintf(buf,sizeof(buf),"sip:%s",dialstr);
|
snprintf(buf,sizeof(buf),"sip:%s",dialstr);
|
||||||
printf("calling %s\n",buf);
|
PJ_LOG(2,(__FILE__, "calling %s\n",buf));
|
||||||
pj_str_t uri = pj_str(buf);
|
pj_str_t uri = pj_str(buf);
|
||||||
pjsua_call_id callid;
|
pjsua_call_id callid;
|
||||||
status = pjsua_call_make_call(acc_id, &uri, 0, NULL, NULL, &callid);
|
status = pjsua_call_make_call(acc_id, &uri, 0, NULL, NULL, &callid);
|
||||||
|
|
|
@ -626,22 +626,27 @@ static int socket_start (struct modem *m)
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pid_t ppid = getpid();
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (pid == -1) {
|
if (pid == -1) {
|
||||||
perror("fork");
|
perror("fork");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
if (pid == 0) { // child
|
if (pid == 0) { // child
|
||||||
char str[16];
|
char _str[12];
|
||||||
snprintf(str,sizeof(str),"%d",sockets[0]);
|
char _parent[12];
|
||||||
|
snprintf(_str,sizeof(_str),"%d",sockets[0]);
|
||||||
|
snprintf(_parent,sizeof(_parent),"%d",ppid);
|
||||||
|
char *_modem_path = strrchr(modem_dev_name, '/');
|
||||||
|
_modem_path = _modem_path == NULL ? modem_dev_name : _modem_path + 1;
|
||||||
close(sockets[1]);
|
close(sockets[1]);
|
||||||
if(_MODEM_DO_ANSWER) {
|
if(_MODEM_DO_ANSWER) {
|
||||||
DBG("MODEM_ANSW execl arg: %s, %s, %s\n",modem_exec,"rr",str);
|
DBG("MODEM_ANSW execl arg: %s, %s, %s, %s, %s\n",modem_exec,"rr",_str,_parent,_modem_path);
|
||||||
ret = execl(modem_exec,modem_exec,"rr",str,NULL);
|
ret = execl(modem_exec,modem_exec,"rr",_str,_parent,_modem_path,NULL);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DBG("MODEM_DIAL execl arg: %s, %s, %s\n",modem_exec,m->dial_string,str);
|
DBG("MODEM_DIAL execl arg: %s, %s, %s, %s, %s\n",modem_exec,"rr",_str,_parent,_modem_path);
|
||||||
ret = execl(modem_exec,modem_exec,m->dial_string,str,NULL);
|
ret = execl(modem_exec,modem_exec,m->dial_string,_str,_parent,_modem_path,NULL);
|
||||||
}
|
}
|
||||||
if (ret == -1) {
|
if (ret == -1) {
|
||||||
ERR("prog: %s\n", modem_exec);
|
ERR("prog: %s\n", modem_exec);
|
||||||
|
|
Loading…
Reference in a new issue