/* unload the module. we check for a cleanup function, but we don't * die if one doesn't exist. however, things are likely to leak without one. */ void uam_unload(struct uam_mod *mod) { if (mod->uam_fcn->uam_cleanup) (*mod->uam_fcn->uam_cleanup)(); mod_close(mod->uam_module); free(mod); }
int mod_decode(OutputBuffer * cb, DecoderControl * dc, char * path) { mod_Data * data; float time = 0.0; int ret; float secPerByte; if(mod_initMikMod() < 0) return -1; if(!(data = mod_open(path))) { ERROR("failed to open mod: %s\n", path); MikMod_Exit(); return -1; } dc->audioFormat.bits = 16; dc->audioFormat.sampleRate = 44100; dc->audioFormat.channels = 2; getOutputAudioFormat(&(dc->audioFormat),&(cb->audioFormat)); secPerByte = 1.0/((dc->audioFormat.bits*dc->audioFormat.channels/8.0)* (float)dc->audioFormat.sampleRate); dc->state = DECODE_STATE_DECODE; while(1) { if(dc->seek) { dc->seekError = 1; dc->seek = 0; } if(dc->stop) break; if(!Player_Active()) break; ret = VC_WriteBytes(data->audio_buffer, MIKMOD_FRAME_SIZE); time += ret*secPerByte; sendDataToOutputBuffer(cb, NULL, dc, 0, (char *)data->audio_buffer, ret, time, 0, NULL); } flushOutputBuffer(cb); mod_close(data); MikMod_Exit(); if(dc->stop) { dc->state = DECODE_STATE_STOP; dc->stop = 0; } else dc->state = DECODE_STATE_STOP; return 0; }
/* uam_load. uams must have a uam_setup function. */ struct uam_mod *uam_load(const char *path, const char *name) { char buf[MAXPATHLEN + 1], *p; struct uam_mod *mod; void *module; if ((module = mod_open(path)) == NULL) { LOG(log_error, logtype_afpd, "uam_load(%s): failed to load: %s", name, mod_error()); return NULL; } if ((mod = (struct uam_mod *) malloc(sizeof(struct uam_mod))) == NULL) { LOG(log_error, logtype_afpd, "uam_load(%s): malloc failed", name); goto uam_load_fail; } strlcpy(buf, name, sizeof(buf)); if ((p = strchr(buf, '.'))) *p = '\0'; if ((mod->uam_fcn = mod_symbol(module, buf)) == NULL) { LOG(log_error, logtype_afpd, "uam_load(%s): mod_symbol error for symbol %s", name, buf); goto uam_load_err; } if (mod->uam_fcn->uam_type != UAM_MODULE_SERVER) { LOG(log_error, logtype_afpd, "uam_load(%s): attempted to load a non-server module", name); goto uam_load_err; } /* version check would go here */ if (!mod->uam_fcn->uam_setup || ((*mod->uam_fcn->uam_setup)(name) < 0)) { LOG(log_error, logtype_afpd, "uam_load(%s): uam_setup failed", name); goto uam_load_err; } mod->uam_module = module; return mod; uam_load_err: free(mod); uam_load_fail: mod_close(module); return NULL; }
static void signal_handler(int sig) { static bool term = false; if (term) { mod_close(); exit(0); } term = true; info("terminated by signal %d\n", sig); ua_stop_all(false); }
int main(int argc, char *argv[]) { bool prefer_ipv6 = false, run_daemon = false, test = false; const char *exec = NULL; int err; (void)re_fprintf(stderr, "baresip v%s" " Copyright (C) 2010 - 2015" " Alfred E. Heggestad et al.\n", BARESIP_VERSION); (void)sys_coredump_set(true); err = libre_init(); if (err) goto out; #ifdef HAVE_GETOPT for (;;) { const int c = getopt(argc, argv, "6de:f:p:hvtm:"); if (0 > c) break; switch (c) { case '?': case 'h': usage(); return -2; #if HAVE_INET6 case '6': prefer_ipv6 = true; break; #endif case 'd': run_daemon = true; break; case 'e': exec = optarg; break; case 'f': conf_path_set(optarg); break; case 'm': err = module_preload(optarg); if (err) { re_fprintf(stderr, "could not pre-load module" " '%s' (%m)\n", optarg, err); } break; case 'p': play_set_path(optarg); break; case 't': test = true; break; case 'v': log_enable_debug(true); break; default: break; } } #else (void)argc; (void)argv; #endif err = conf_configure(); if (err) { warning("main: configure failed: %m\n", err); goto out; } /* Initialise User Agents */ err = ua_init("baresip v" BARESIP_VERSION " (" ARCH "/" OS ")", true, true, true, prefer_ipv6); if (err) goto out; if (test) goto out; /* Load modules */ err = conf_modules(); if (err) goto out; if (run_daemon) { err = sys_daemon(); if (err) goto out; log_enable_stderr(false); } info("baresip is ready.\n"); if (exec) ui_input_str(exec); /* Main loop */ err = re_main(signal_handler); out: if (err) ua_stop_all(true); ua_close(); mod_close(); libre_close(); /* Check for memory leaks */ tmr_debug(); mem_debug(); return err; }
int main(int argc, char *argv[]) { bool prefer_ipv6 = false, run_daemon = false; const char *exec = NULL; int err; (void)re_fprintf(stderr, "baresip v%s" " Copyright (C) 2010 - 2014" " Alfred E. Heggestad et al.\n", BARESIP_VERSION); (void)sys_coredump_set(true); #ifdef HAVE_GETOPT for (;;) { const int c = getopt(argc, argv, "6de:f:hv"); if (0 > c) break; switch (c) { case '?': case 'h': (void)re_fprintf(stderr, "Usage: baresip [options]\n" "options:\n" #if HAVE_INET6 "\t-6 Prefer IPv6\n" #endif "\t-d Daemon\n" "\t-e <commands> Exec commands\n" "\t-f <path> Config path\n" "\t-h -? Help\n" "\t-v Verbose debug\n" ); return -2; #if HAVE_INET6 case '6': prefer_ipv6 = true; break; #endif case 'd': run_daemon = true; break; case 'e': exec = optarg; break; case 'f': conf_path_set(optarg); break; case 'v': log_enable_debug(true); break; default: break; } } #else (void)argc; (void)argv; #endif err = libre_init(); if (err) goto out; err = conf_configure(); if (err) { warning("main: configure failed: %m\n", err); goto out; } /* Initialise User Agents */ err = ua_init("baresip v" BARESIP_VERSION " (" ARCH "/" OS ")", true, true, true, prefer_ipv6); if (err) goto out; /* Load modules */ err = conf_modules(); if (err) goto out; if (run_daemon) { err = sys_daemon(); if (err) goto out; log_enable_stderr(false); } info("baresip is ready.\n"); if (exec) ui_input_str(exec); /* Main loop */ err = re_main(signal_handler); out: if (err) ua_stop_all(true); ua_close(); mod_close(); libre_close(); /* Check for memory leaks */ tmr_debug(); mem_debug(); return err; }
int main(int ac, char** av) { pcm_desc_t desc; pcm_handle_t ipcm; pcm_handle_t opcm; mod_handle_t mod; int err; cmdline_t cmd; size_t i; err = -1; if (get_cmdline(&cmd, ac - 1, av + 1)) goto on_error_0; pcm_init_desc(&desc); desc.flags |= PCM_FLAG_IN; if (cmd.flags & CMDLINE_FLAG(IPCM)) desc.name = cmd.ipcm; if (pcm_open(&ipcm, &desc)) goto on_error_0; pcm_init_desc(&desc); desc.flags |= PCM_FLAG_OUT; if (cmd.flags & CMDLINE_FLAG(OPCM)) desc.name = cmd.opcm; if (pcm_open(&opcm, &desc)) goto on_error_1; if (mod_open(&mod, 512)) goto on_error_2; if (pcm_start(&ipcm)) goto on_error_3; if (pcm_start(&opcm)) goto on_error_3; signal(SIGINT, on_sigint); for (i = 0; is_sigint == 0; i += 1) { size_t nsampl; size_t navail; size_t off; /* read ipcm */ err = snd_pcm_wait(ipcm.pcm, -1); if (is_sigint) break ; if (err < 0) goto on_ipcm_xrun; navail = (size_t)snd_pcm_avail_update(ipcm.pcm); if (ipcm.wpos >= ipcm.rpos) nsampl = ipcm.nsampl - ipcm.wpos; else nsampl = ipcm.rpos - ipcm.wpos; if (nsampl > navail) nsampl = navail; off = ipcm.wpos * ipcm.scale; err = snd_pcm_readi(ipcm.pcm, ipcm.buf + off, nsampl); if (err < 0) goto on_ipcm_xrun; ipcm.wpos += (size_t)err; if (ipcm.wpos == ipcm.nsampl) ipcm.wpos = 0; /* apply modifier */ redo_mod: if (ipcm.wpos >= ipcm.rpos) nsampl = ipcm.wpos - ipcm.rpos; else nsampl = ipcm.nsampl - ipcm.rpos + ipcm.wpos; if (cmd.flags & CMDLINE_FLAG(FILT)) { const size_t n = mod_apply (&mod, ipcm.buf, ipcm.nsampl, ipcm.rpos, nsampl); nsampl = n; } if (nsampl == 0) continue ; if ((ipcm.rpos + nsampl) > ipcm.nsampl) { const size_t n = ipcm.nsampl - ipcm.rpos; off = ipcm.rpos * ipcm.scale; err = snd_pcm_writei(opcm.pcm, ipcm.buf + off, n); if (err < 0) goto on_opcm_xrun; nsampl -= n; ipcm.rpos = 0; } off = ipcm.rpos * ipcm.scale; err = snd_pcm_writei(opcm.pcm, ipcm.buf + off, nsampl); if (err < 0) goto on_opcm_xrun; ipcm.rpos += nsampl; if (ipcm.rpos == ipcm.nsampl) ipcm.rpos = 0; goto redo_mod; continue ; on_ipcm_xrun: if (pcm_recover_xrun(&ipcm, err)) PERROR_GOTO("", on_error_2); continue ; on_opcm_xrun: if (pcm_recover_xrun(&opcm, err)) PERROR_GOTO("", on_error_2); continue ; } err = 0; on_error_3: mod_close(&mod); on_error_2: pcm_close(&opcm); on_error_1: pcm_close(&ipcm); on_error_0: return err; }
int main(int argc, char *argv[]) { bool daemon = true; int err = 0; struct pl opt; (void)sys_coredump_set(true); #ifdef HAVE_GETOPT for (;;) { const int c = getopt(argc, argv, "dhnf:"); if (0 > c) break; switch (c) { case 'd': force_debug = true; restund_log_enable_debug(true); break; case 'f': configfile = optarg; break; case 'n': daemon = false; break; case '?': err = EINVAL; /*@fallthrough@*/ case 'h': usage(); return err; } } #else (void)argc; (void)argv; #endif restund_cmd_subscribe(&cmd_reload); err = fd_setsize(4096); if (err) { restund_warning("fd_setsize error: %m\n", err); goto out; } err = libre_init(); if (err) { restund_error("re init failed: %m\n", err); goto out; } /* configuration file */ err = conf_alloc(&conf, configfile); if (err) { restund_error("error loading configuration: %s: %m\n", configfile, err); goto out; } /* debug config */ if (!conf_get(conf, "debug", &opt) && !pl_strcasecmp(&opt, "yes")) restund_log_enable_debug(true); /* udp */ err = restund_udp_init(); if (err) goto out; /* tcp */ err = restund_tcp_init(); if (err) goto out; /* daemon config */ if (!conf_get(conf, "daemon", &opt) && !pl_strcasecmp(&opt, "no")) daemon = false; /* module config */ if (conf_get(conf, "module_path", &opt)) pl_set_str(&opt, "."); err = conf_apply(conf, "module", module_handler, &opt); if (err) goto out; /* daemon */ if (daemon) { err = sys_daemon(); if (err) { restund_error("daemon error: %m\n", err); goto out; } restund_log_enable_stderr(false); } /* database */ err = restund_db_init(); if (err) { restund_warning("database error: %m\n", err); goto out; } restund_info("stun server ready\n"); /* main loop */ err = re_main(signal_handler); out: restund_db_close(); mod_close(); restund_udp_close(); restund_tcp_close(); conf = mem_deref(conf); libre_close(); restund_cmd_unsubscribe(&cmd_reload); /* check for memory leaks */ tmr_debug(); mem_debug(); return err; }
void conf_close(void) { mod_close(); conf_obj = mem_deref(conf_obj); }