This commit is contained in:
JerryXiao 2022-11-11 01:24:38 +08:00
parent 636959b37b
commit 2bbc57814e
Signed by: Jerry
GPG key ID: 22618F758B5BE2E5
4 changed files with 96 additions and 13 deletions

View file

@ -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

View file

@ -16,6 +16,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <fcntl.h>
#include <unistd.h>
#include <stdbool.h>
#include <time.h>
@ -24,6 +25,19 @@
#include <errno.h>
#include <pjsua-lib/pjsua.h>
#include <pjsua-lib/pjsua_internal.h>
#include <pulse/simple.h>
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')
@ -51,6 +65,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);
}
@ -71,6 +87,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;
}
@ -123,6 +141,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;
@ -135,7 +187,15 @@ int main(int argc, char *argv[]) {
char *dialstr = argv[1];
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;
}
@ -171,7 +231,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);
@ -187,7 +250,7 @@ int main(int argc, char *argv[]) {
for (int i=0; i<count; i++) {
int pri = 0;
if (pj_strcmp2(&codecs[i].codec_id,"PCMU/8000/1") == 0) {
pri = 1;
pri = 0;
} else if (pj_strcmp2(&codecs[i].codec_id,"PCMA/8000/1") == 0) {
pri = 2;
}
@ -195,13 +258,17 @@ int main(int argc, char *argv[]) {
// printf("codec: %s %d\n",pj_strbuf(&codecs[i].codec_id),pri);
}
pjsua_transport_id transport_id;
/* Add UDP transport. */
{
pjsua_transport_config cfg;
pjsua_transport_config_default(&cfg);
cfg.port = 5060;
status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, NULL);
// cfg.port = 5060;
if (getenv("PJSIP_IPV6"))
status = pjsua_transport_create(PJSIP_TRANSPORT_UDP6, &cfg, &transport_id);
else
status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg, &transport_id);
if (status != PJ_SUCCESS) error_exit("Error creating transport", status);
}
@ -226,6 +293,7 @@ int main(int argc, char *argv[]) {
status = pjsua_start();
if (status != PJ_SUCCESS) error_exit("Error starting pjsua", status);
if (has_sip_user)
{
pjsua_acc_config cfg;
pjsua_acc_config_default(&cfg);
@ -233,7 +301,7 @@ int main(int argc, char *argv[]) {
pj_strdup2(pool,&cfg.id,buf);
snprintf(buf,sizeof(buf),"sip:%s",sip_domain);
pj_strdup2(pool,&cfg.reg_uri,buf);
cfg.register_on_acc_add = false;
cfg.register_on_acc_add = true;
cfg.cred_count = 1;
cfg.cred_info[0].realm = pj_str("*");
cfg.cred_info[0].scheme = pj_str("digest");
@ -244,11 +312,23 @@ int main(int argc, char *argv[]) {
status = pjsua_acc_add(&cfg, PJ_TRUE, &acc_id);
if (status != PJ_SUCCESS) error_exit("Error adding account", status);
}
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);
}
pjsua_get_var()->tpdata[transport_id].has_bound_addr = PJ_TRUE;
if (getenv("PJSIP_IPV6"))
pjsua_get_var()->acc[acc_id].cfg.ipv6_media_use = PJSUA_IPV6_ENABLED;
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);
start_pa();
pjsua_call_id callid;
status = pjsua_call_make_call(acc_id, &uri, 0, NULL, NULL, &callid);
if (status != PJ_SUCCESS) error_exit("Error making call", status);
@ -258,5 +338,6 @@ int main(int argc, char *argv[]) {
nanosleep(&ts,NULL);
}
stop_pa();
return 0;
}

View file

@ -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)"},
{'e',"exec","path to external application that transmits audio over the socket (required)",MANDATORY,STRING,"./d-modem"},
{}
};

View file

@ -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)
@ -635,7 +635,9 @@ static int socket_start (struct modem *m)
char str[16];
snprintf(str,sizeof(str),"%d",sockets[0]);
close(sockets[1]);
DBG("execl arg: %s, %s, %s\n", modem_exec, m->dial_string, str);
execl(modem_exec,modem_exec,m->dial_string,str,NULL);
DBG("execl failed arg: %s, %s, %s\n", modem_exec, m->dial_string, str);
} else {
close(sockets[0]);
dev->fd = sockets[1];
@ -1079,7 +1081,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);
@ -1095,8 +1097,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;