From 755cfb8a54c81353ec2eb198c78df9bc4b074331 Mon Sep 17 00:00:00 2001 From: Jerry Date: Fri, 11 Nov 2022 01:24:38 +0800 Subject: [PATCH] fix --- Makefile | 2 +- d-modem.c | 112 +++++++++++++++++++++++++++++++++++---- slmodemd/modem_cmdline.c | 4 +- slmodemd/modem_main.c | 8 +-- 4 files changed, 110 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index f61e331..a10ffd3 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ $(PKG_CONFIG_PATH)/libpjproject.pc: $(MAKE) -C $(PJSIP_DIR) install d-modem: d-modem.c $(PKG_CONFIG_PATH)/libpjproject.pc - $(CC) -o $@ $< `PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" pkg-config --static --cflags --libs libpjproject` + $(CC) -o $@ $< `PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)" pkg-config --static --cflags --libs libpjproject` -lpulse -lpulse-simple slmodemd: $(MAKE) -C slmodemd diff --git a/d-modem.c b/d-modem.c index 79bc028..93b6d26 100644 --- a/d-modem.c +++ b/d-modem.c @@ -16,6 +16,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include #include #include #include @@ -24,6 +25,19 @@ #include // test #include +#include + +#include + +pa_simple *pa_s1; +pa_simple *pa_s2; +const pa_sample_spec pa_ss = { + .format = PA_SAMPLE_S16LE, + .rate = 9600, + .channels = 1 +}; +int wave_recv; +int wave_transmit; #define SIGNATURE PJMEDIA_SIG_CLASS_PORT_AUD('D','M') #define DMODEM_DIAL_MODE 0 @@ -58,6 +72,8 @@ static pj_status_t dmodem_put_frame(pjmedia_port *this_port, pjmedia_frame *fram int len; if (frame->type == PJMEDIA_FRAME_TYPE_AUDIO) { + pa_simple_write(pa_s1, frame->buf, frame->size, NULL); + write(wave_recv, frame->buf, frame->size); if ((len=write(sm->sock, frame->buf, frame->size)) != frame->size) { error_exit("error writing frame",0); } @@ -78,6 +94,8 @@ static pj_status_t dmodem_get_frame(pjmedia_port *this_port, pjmedia_frame *fram frame->timestamp.u64 = sm->timestamp.u64; frame->type = PJMEDIA_FRAME_TYPE_AUDIO; sm->timestamp.u64 += PJMEDIA_PIA_SPF(&this_port->info); + pa_simple_write(pa_s2, frame->buf, frame->size, NULL); + write(wave_transmit, frame->buf, frame->size); return PJ_SUCCESS; } @@ -145,6 +163,40 @@ static void on_call_media_state(pjsua_call_id call_id) { } +void start_pa() { + wave_recv = open("/tmp/dmodem.recv.s16le.9600hz.pcm", O_WRONLY | O_CREAT, 00644); + wave_transmit = open("/tmp/dmodem.transmit.s16le.9600hz.pcm", O_WRONLY | O_CREAT, 00644); + if (wave_recv <= 0 || wave_transmit <= 0) + error_exit("open wave files", 1); + pa_s1 = pa_simple_new(NULL, // Use the default server. + "dmodem", // Our application's name. + PA_STREAM_PLAYBACK, + NULL, // Use the default device. + "recv", // Description of our stream. + &pa_ss, // Our sample format. + NULL, // Use default channel map + NULL, // Use default buffering attributes. + NULL // Ignore error code. + ); + pa_s2 = pa_simple_new(NULL, // Use the default server. + "dmodem", // Our application's name. + PA_STREAM_PLAYBACK, + NULL, // Use the default device. + "transmit", // Description of our stream. + &pa_ss, // Our sample format. + NULL, // Use default channel map + NULL, // Use default buffering attributes. + NULL // Ignore error code. + ); + if (!pa_s1 || !pa_s2) + error_exit("pulseaudio", 1); +} +void stop_pa() { + pa_simple_free(pa_s1); + pa_simple_free(pa_s2); + close(wave_recv); + close(wave_transmit); +} int main(int argc, char *argv[]) { pjsua_acc_id acc_id; pj_status_t status; @@ -160,10 +212,29 @@ int main(int argc, char *argv[]) { signal(SIGPIPE,SIG_IGN); char *dialstr = argv[1]; - char *sip_user = "dialupuser"; - char *sip_domain = "192.168.1.2"; - char *sip_pass = "pppasswdModem1"; - printf("sip data: user: %s, passwd: %s, server: %s\nMODE: %d\n", sip_user, sip_pass, sip_domain, mode); + int has_sip_user = 1; + char *sip_user = getenv("SIP_LOGIN"); + if (!sip_user) { + has_sip_user = 0; + printf("[!] SIP_LOGIN is empty, no registration will be attempted\n"); + char sip_user_buf[40]; + strcpy(sip_user_buf, "placeholder:placeholder@placeholder"); + sip_user = sip_user_buf; + } + if (!sip_user) { + return -1; + } + char *sip_domain = strchr(sip_user,'@'); + if (!sip_domain) { + return -1; + } + *sip_domain++ = '\0'; + char *sip_pass = strchr(sip_user,':'); + if (!sip_pass) { + return -1; + } + *sip_pass++ = '\0'; + status = pjsua_create(); if (status != PJ_SUCCESS) error_exit("Error in pjsua_create()", status); @@ -189,7 +260,10 @@ int main(int argc, char *argv[]) { med_cfg.ec_tail_len = 0; med_cfg.jb_max = 2000; // med_cfg.jb_init = 200; - med_cfg.audio_frame_ptime = 5; +/* // med_cfg.jb_init = 200 */ + med_cfg.jb_init = 100; +/* med_cfg.audio_frame_ptime = 5; */ + med_cfg.audio_frame_ptime = 10; status = pjsua_init(&cfg, &log_cfg, &med_cfg); if (status != PJ_SUCCESS) error_exit("Error in pjsua_init()", status); @@ -205,7 +279,7 @@ int main(int argc, char *argv[]) { for (int i=0; itpdata[transport_id].has_bound_addr = PJ_TRUE; + if (getenv("PJSIP_IPV6")) + pjsua_get_var()->acc[acc_id].cfg.ipv6_media_use = PJSUA_IPV6_ENABLED; + start_pa(); if(mode == DMODEM_DIAL_MODE) { - snprintf(buf,sizeof(buf),"sip:%s@%s",dialstr,sip_domain); + if (has_sip_user) + snprintf(buf,sizeof(buf),"sip:%s@%s",dialstr,sip_domain); + else + snprintf(buf,sizeof(buf),"sip:%s",dialstr); printf("calling %s\n",buf); pj_str_t uri = pj_str(buf); pjsua_call_id callid; @@ -294,5 +387,6 @@ int main(int argc, char *argv[]) { nanosleep(&ts,NULL); } + stop_pa(); return 0; } diff --git a/slmodemd/modem_cmdline.c b/slmodemd/modem_cmdline.c index ec20a91..a6f5684 100644 --- a/slmodemd/modem_cmdline.c +++ b/slmodemd/modem_cmdline.c @@ -71,7 +71,7 @@ const char *modem_dev_name = NULL; const char *modem_default_dev_name = "/dev/slamr0"; const char *modem_alsa_dev_name = "modem:1"; const char *modem_exec = NULL; -unsigned int need_realtime = 1; +unsigned int need_realtime = 0; #ifdef MODEM_CONFIG_RING_DETECTOR unsigned int ring_detector = 0; #endif @@ -125,7 +125,7 @@ static struct opt { {'s',"shortbuffer","use short buffer (4 periods length)"}, {'d',"debug","debug level (developers only, for ./sl...)",OPTIONAL,INTEGER,"0"}, {'l',"log","logging mode",OPTIONAL,INTEGER,"5"}, - {'e',"exec","path to external application that transmits audio over the socket (required)",MANDATORY,STRING,""}, + {'e',"exec","path to external application that transmits audio over the socket (required)",MANDATORY,STRING,"./d-modem"}, {} }; diff --git a/slmodemd/modem_main.c b/slmodemd/modem_main.c index e924249..4c19eee 100644 --- a/slmodemd/modem_main.c +++ b/slmodemd/modem_main.c @@ -87,7 +87,7 @@ #define DBG(fmt,args...) dprintf("main: " fmt, ##args) -#define SLMODEMD_USER "nobody" +//#define SLMODEMD_USER "nobody" #define LOCKED_MEM_MIN_KB (8UL * 1024) #define LOCKED_MEM_MIN (LOCKED_MEM_MIN_KB * 1024) @@ -1089,7 +1089,7 @@ int modem_main(const char *dev_name) prop_dp_init(); modem_timer_init(); - sprintf(link_name,"/dev/ttySL%d", device.num); + sprintf(link_name,"/tmp/ttySL%d", device.num); m = modem_create(modem_driver,basename(dev_name)); m->name = basename(dev_name); @@ -1105,8 +1105,8 @@ int modem_main(const char *dev_name) INFO("modem `%s' created. TTY is `%s'\n", m->name, m->pty_name); - sprintf(path_name,"/var/lib/slmodem/data.%s",basename(dev_name)); - datafile_load_info(path_name,&m->dsp_info); +// sprintf(path_name,"/var/lib/slmodem/data.%s",basename(dev_name)); +// datafile_load_info(path_name,&m->dsp_info); if (need_realtime) { struct sched_param prm;