This commit is contained in:
JerryXiao 2022-11-13 00:05:27 +08:00
parent 902e7f8e30
commit 2441e32b79
Signed by: Jerry
GPG key ID: 22618F758B5BE2E5
2 changed files with 175 additions and 159 deletions

View file

@ -54,6 +54,7 @@ int wave_transmit = -1;
uint8_t mode = DMODEM_DIAL_MODE;
uint8_t ringing = 0;
uint8_t answered = 0;
int ppid;
pjsua_call_id incoming;
struct dmodem {
@ -74,7 +75,7 @@ static void error_exit(const char *title, pj_status_t status) {
pjsua_destroy();
stop_pa();
if (answered)
execl("/bin/sh", "/bin/sh", "-cx", "kill -INT $PPID", NULL);
kill(ppid, SIGINT);
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) {
printf("destroy\n");
if (answered)
execl("/bin/sh", "/bin/sh", "-cx", "kill -INT $PPID", NULL);
kill(ppid, SIGINT);
exit(-1);
}
@ -200,7 +201,7 @@ static void on_call_state(pjsua_call_id call_id, pjsip_event *e) {
pjsua_destroy();
stop_pa();
if (answered)
execl("/bin/sh", "/bin/sh", "-cx", "kill -INT $PPID", NULL);
kill(ppid, SIGINT);
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);
tmp[pj_strlen(&ci.remote_contact)] = '\0';
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);
return;
}
printf("Incoming call from: %s\n", tmp);
PJ_LOG(2,(__FILE__, "Incoming call from: %s", tmp));
free(tmp);
incoming = call_id;
ringing = 1;
@ -247,9 +248,21 @@ static void on_call_media_state(pjsua_call_id call_id) {
int main(int argc, char *argv[]) {
pjsua_acc_id acc_id;
pj_status_t status;
if (argc != 3) {
if (argc != 5) {
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)) {
mode = DMODEM_ANSWER_MODE;
}
@ -297,17 +310,16 @@ int main(int argc, char *argv[]) {
}
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);
med_cfg.no_vad = true;
med_cfg.ec_tail_len = 0;
med_cfg.jb_max = 2000;
// med_cfg.jb_init = 200;
/* // med_cfg.jb_init = 200 */
// med_cfg.jb_init = 0;
/* med_cfg.audio_frame_ptime = 5; */
med_cfg.jb_max = -1;
med_cfg.jb_init = -1;
med_cfg.audio_frame_ptime = 10;
med_cfg.quality = 10;
status = pjsua_init(&cfg, &log_cfg, &med_cfg);
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);
if (mode)
cfg.port = 5160;
cfg.port = sip_port;
if (getenv("PJSIP_IPV6"))
status = pjsua_transport_create(PJSIP_TRANSPORT_UDP6, &cfg, &transport_id);
else
@ -346,7 +358,7 @@ int main(int argc, char *argv[]) {
if (status != PJ_SUCCESS) error_exit("Error creating transport", status);
}
char buf[384];
printf("Initializing pool\n");
//printf("Initializing pool\n");
pj_caching_pool cp;
pj_caching_pool_init(&cp, NULL, 1024*1024);
pool = pj_pool_create(&cp.factory, "pool1", 4000, 4000, NULL);
@ -387,7 +399,6 @@ int main(int argc, char *argv[]) {
}
else
{
printf("acc add local\n");
status == pjsua_acc_add_local(transport_id, 1, &acc_id);
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);
else
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);
pjsua_call_id callid;
status = pjsua_call_make_call(acc_id, &uri, 0, NULL, NULL, &callid);

View file

@ -626,22 +626,27 @@ static int socket_start (struct modem *m)
exit(-1);
}
pid_t ppid = getpid();
pid_t pid = fork();
if (pid == -1) {
perror("fork");
exit(-1);
}
if (pid == 0) { // child
char str[16];
snprintf(str,sizeof(str),"%d",sockets[0]);
char _str[12];
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]);
if(_MODEM_DO_ANSWER) {
DBG("MODEM_ANSW execl arg: %s, %s, %s\n",modem_exec,"rr",str);
ret = execl(modem_exec,modem_exec,"rr",str,NULL);
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,_parent,_modem_path,NULL);
}
else {
DBG("MODEM_DIAL execl arg: %s, %s, %s\n",modem_exec,m->dial_string,str);
ret = execl(modem_exec,modem_exec,m->dial_string,str,NULL);
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,_parent,_modem_path,NULL);
}
if (ret == -1) {
ERR("prog: %s\n", modem_exec);