static int encode_update(struct vidfilt_enc_st **stp, void **ctx, const struct vidfilt *vf) { struct swscale_enc *st; struct config *config = conf_config(); int err = 0; if (!config) { warning("swscale: no config\n"); return EINVAL; } if (!stp || !ctx || !vf) return EINVAL; if (*stp) return 0; st = mem_zalloc(sizeof(*st), encode_destructor); if (!st) return ENOMEM; st->dst_size.w = config->video.width; st->dst_size.h = config->video.height; if (err) mem_deref(st); else *stp = (struct vidfilt_enc_st *)st; return err; }
static int print_uuid(struct re_printf *pf, void *arg) { struct config *cfg = conf_config(); (void)arg; if (cfg) re_hprintf(pf, "UUID: %s\n", cfg->sip.uuid); return 0; }
static int auloop_reset(struct audio_loop *al) { struct auplay_prm auplay_prm; struct ausrc_prm ausrc_prm; const struct config *cfg = conf_config(); int err; if (!cfg) return ENOENT; /* Optional audio codec */ if (str_isset(aucodec)) start_codec(al, aucodec); al->auplay = mem_deref(al->auplay); al->ausrc = mem_deref(al->ausrc); al->ab = mem_deref(al->ab); al->srate = configv[al->index].srate; al->ch = configv[al->index].ch; al->fs = al->srate * al->ch * PTIME / 1000; (void)re_printf("Audio-loop: %uHz, %dch\n", al->srate, al->ch); err = aubuf_alloc(&al->ab, 320, 0); if (err) return err; auplay_prm.fmt = AUFMT_S16LE; auplay_prm.srate = al->srate; auplay_prm.ch = al->ch; auplay_prm.frame_size = al->fs; err = auplay_alloc(&al->auplay, cfg->audio.play_mod, &auplay_prm, cfg->audio.play_dev, write_handler, al); if (err) { DEBUG_WARNING("auplay %s,%s failed: %m\n", cfg->audio.play_mod, cfg->audio.play_dev, err); return err; } ausrc_prm.fmt = AUFMT_S16LE; ausrc_prm.srate = al->srate; ausrc_prm.ch = al->ch; ausrc_prm.frame_size = al->fs; err = ausrc_alloc(&al->ausrc, NULL, cfg->audio.src_mod, &ausrc_prm, cfg->audio.src_dev, read_handler, error_handler, al); if (err) { DEBUG_WARNING("ausrc %s,%s failed: %m\n", cfg->audio.src_mod, cfg->audio.src_dev, err); return err; } return err; }
/** * Configure the system with default settings * * @return 0 if success, otherwise errorcode */ int conf_configure(void) { char path[FS_PATH_MAX], file[FS_PATH_MAX]; int err; #if defined (WIN32) dbg_init(DBG_INFO, DBG_NONE); #endif err = conf_path_get(path, sizeof(path)); if (err) { warning("conf: could not get config path: %m\n", err); return err; } if (re_snprintf(file, sizeof(file), "%s/config", path) < 0) return ENOMEM; if (!conf_fileexist(file)) { (void)fs_mkdir(path, 0700); err = config_write_template(file, conf_config()); if (err) goto out; } conf_obj = mem_deref(conf_obj); err = conf_alloc(&conf_obj, file); if (err) goto out; err = config_parse_conf(conf_config(), conf_obj); if (err) goto out; out: return err; }
static int ua_call_alloc(struct call **callp, struct ua *ua, enum vidmode vidmode, const struct sip_msg *msg, struct call *xcall, const char *local_uri) { struct call_prm cprm; if (*callp) { warning("ua: call_alloc: call is already allocated\n"); return EALREADY; } cprm.vidmode = vidmode; cprm.af = ua->af; return call_alloc(callp, conf_config(), &ua->calls, ua->acc->dispname, local_uri ? local_uri : ua->acc->aor, ua->acc, ua, &cprm, msg, xcall, call_event_handler, ua); }
static int module_init(void) { struct config *cfg = conf_config(); char path[256]; int err = 0; err = conf_path_get(path, sizeof(path)); if (err) return err; strncat(path, "/uuid", sizeof(path) - strlen(path) - 1); err = uuid_init(path); if (err) return err; err = uuid_load(path, cfg->sip.uuid, sizeof(cfg->sip.uuid)); if (err) return err; return 0; }
static int module_init(void) { int err = 0; struct config *cfg = conf_config(); webapp_accounts_init(); #if defined (DARWIN) re_snprintf(command, sizeof(command), "open https://stream.studio-link.de/stream/login/%s", cfg->sip.uuid); #elif defined (WIN32) re_snprintf(command, sizeof(command), "start https://stream.studio-link.de/stream/login/%s", cfg->sip.uuid); #else re_snprintf(command, sizeof(command), "xdg-open https://stream.studio-link.de/stream/login/%s", cfg->sip.uuid); #endif tmr_init(&tmr); tmr_start(&tmr, 1500, startup, NULL); return err; }
static int auloop_reset(struct audio_loop *al) { struct auplay_prm auplay_prm; struct ausrc_prm ausrc_prm; const struct config *cfg = conf_config(); int err; if (!cfg) return ENOENT; /* Optional audio codec */ if (str_isset(aucodec)) start_codec(al, aucodec); /* audio player/source must be stopped first */ al->auplay = mem_deref(al->auplay); al->ausrc = mem_deref(al->ausrc); al->sampv = mem_deref(al->sampv); al->ab = mem_deref(al->ab); al->srate = configv[al->index].srate; al->ch = configv[al->index].ch; if (str_isset(aucodec)) { al->sampc = al->srate * al->ch * PTIME / 1000; al->sampv = mem_alloc(al->sampc * 2, NULL); if (!al->sampv) return ENOMEM; } info("Audio-loop: %uHz, %dch\n", al->srate, al->ch); err = aubuf_alloc(&al->ab, 320, 0); if (err) return err; auplay_prm.srate = al->srate; auplay_prm.ch = al->ch; auplay_prm.ptime = PTIME; err = auplay_alloc(&al->auplay, cfg->audio.play_mod, &auplay_prm, cfg->audio.play_dev, write_handler, al); if (err) { warning("auloop: auplay %s,%s failed: %m\n", cfg->audio.play_mod, cfg->audio.play_dev, err); return err; } ausrc_prm.srate = al->srate; ausrc_prm.ch = al->ch; ausrc_prm.ptime = PTIME; err = ausrc_alloc(&al->ausrc, NULL, cfg->audio.src_mod, &ausrc_prm, cfg->audio.src_dev, read_handler, error_handler, al); if (err) { warning("auloop: ausrc %s,%s failed: %m\n", cfg->audio.src_mod, cfg->audio.src_dev, err); return err; } return err; }
/** * Initialise the User-Agents * * @param software SIP User-Agent string * @param udp Enable UDP transport * @param tcp Enable TCP transport * @param tls Enable TLS transport * @param prefer_ipv6 Prefer IPv6 flag * * @return 0 if success, otherwise errorcode */ int ua_init(const char *software, bool udp, bool tcp, bool tls, bool prefer_ipv6) { struct config *cfg = conf_config(); uint32_t bsize; int err; uag.cfg = &cfg->sip; bsize = cfg->sip.trans_bsize; play_init(); err = contact_init(); if (err) return err; /* Initialise Network */ err = net_init(&cfg->net, prefer_ipv6 ? AF_INET6 : AF_INET); if (err) { warning("ua: network init failed: %m\n", err); return err; } uag.use_udp = udp; uag.use_tcp = tcp; uag.use_tls = tls; uag.prefer_ipv6 = prefer_ipv6; list_init(&uag.ual); err = sip_alloc(&uag.sip, net_dnsc(), bsize, bsize, bsize, software, exit_handler, NULL); if (err) { warning("ua: sip stack failed: %m\n", err); goto out; } err = ua_add_transp(); if (err) goto out; err = sip_listen(&uag.lsnr, uag.sip, true, request_handler, NULL); if (err) goto out; err = sipsess_listen(&uag.sock, uag.sip, bsize, sipsess_conn_handler, NULL); if (err) goto out; err = sipevent_listen(&uag.evsock, uag.sip, bsize, bsize, NULL, NULL); if (err) goto out; err = cmd_register(cmdv, ARRAY_SIZE(cmdv)); if (err) goto out; net_change(60, net_change_handler, NULL); out: if (err) { warning("ua: init failed (%m)\n", err); ua_close(); } return err; }
static int auloop_reset(struct audio_loop *al, uint32_t srate, uint32_t ch) { struct auplay_prm auplay_prm; struct ausrc_prm ausrc_prm; const struct config *cfg = conf_config(); int err; if (!cfg) return ENOENT; if (cfg->audio.src_fmt != cfg->audio.play_fmt) { warning("auloop: ausrc_format and auplay_format" " must be the same\n"); return EINVAL; } al->fmt = cfg->audio.src_fmt; /* audio player/source must be stopped first */ al->auplay = mem_deref(al->auplay); al->ausrc = mem_deref(al->ausrc); al->aubuf = mem_deref(al->aubuf); al->srate = srate; al->ch = ch; info("Audio-loop: %uHz, %dch, %s\n", al->srate, al->ch, aufmt_name(al->fmt)); err = aubuf_alloc(&al->aubuf, 320, 0); if (err) return err; auplay_prm.srate = al->srate; auplay_prm.ch = al->ch; auplay_prm.ptime = PTIME; auplay_prm.fmt = al->fmt; err = auplay_alloc(&al->auplay, baresip_auplayl(), cfg->audio.play_mod, &auplay_prm, cfg->audio.play_dev, write_handler, al); if (err) { warning("auloop: auplay %s,%s failed: %m\n", cfg->audio.play_mod, cfg->audio.play_dev, err); return err; } ausrc_prm.srate = al->srate; ausrc_prm.ch = al->ch; ausrc_prm.ptime = PTIME; ausrc_prm.fmt = al->fmt; err = ausrc_alloc(&al->ausrc, baresip_ausrcl(), NULL, cfg->audio.src_mod, &ausrc_prm, cfg->audio.src_dev, read_handler, error_handler, al); if (err) { warning("auloop: ausrc %s,%s failed: %m\n", cfg->audio.src_mod, cfg->audio.src_dev, err); return err; } return err; }
static int cmd_config_print(struct re_printf *pf, void *unused) { (void)unused; return config_print(pf, conf_config()); }
int main(int argc, char *argv[]) { struct config *config; int err; err = libre_init(); if (err) return err; log_enable_info(false); for (;;) { const int c = getopt(argc, argv, "v"); if (0 > c) break; switch (c) { case '?': case 'h': usage(); return -2; case 'v': log_enable_info(true); break; default: break; } } re_printf("running baresip selftest version %s with %zu tests\n", BARESIP_VERSION, ARRAY_SIZE(tests)); /* note: run SIP-traffic on localhost */ config = conf_config(); if (!config) { err = ENOENT; goto out; } str_ncpy(config->sip.local, "127.0.0.1:0", sizeof(config->sip.local)); /* XXX: needed for ua tests */ err = ua_init("test", true, true, true, false); if (err) goto out; err = run_tests(); if (err) goto out; #if 1 ua_stop_all(true); #endif re_printf("\x1b[32mOK. %zu tests passed successfully\x1b[;m\n", ARRAY_SIZE(tests)); out: if (err) { warning("test failed (%m)\n", err); re_printf("%H\n", re_debug, 0); } ua_stop_all(true); ua_close(); libre_close(); tmr_debug(); mem_debug(); return err; }