diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/audio.c | 16 | ||||
-rw-r--r-- | src/auplay.c | 35 | ||||
-rw-r--r-- | src/ausrc.c | 22 | ||||
-rw-r--r-- | src/baresip.c | 16 | ||||
-rw-r--r-- | src/play.c | 3 |
5 files changed, 58 insertions, 34 deletions
diff --git a/src/audio.c b/src/audio.c index 43af671..ddd83ef 100644 --- a/src/audio.c +++ b/src/audio.c @@ -986,7 +986,7 @@ static int start_player(struct aurx *rx, struct audio *a) } /* Start Audio Player */ - if (!rx->auplay && auplay_find(NULL)) { + if (!rx->auplay && auplay_find(baresip_auplayl(), NULL)) { struct auplay_prm prm; @@ -1004,7 +1004,8 @@ static int start_player(struct aurx *rx, struct audio *a) return err; } - err = auplay_alloc(&rx->auplay, a->cfg.play_mod, + err = auplay_alloc(&rx->auplay, baresip_auplayl(), + a->cfg.play_mod, &prm, rx->device, auplay_write_handler, rx); if (err) { @@ -1064,7 +1065,7 @@ static int start_source(struct autx *tx, struct audio *a) } /* Start Audio Source */ - if (!tx->ausrc && ausrc_find(NULL)) { + if (!tx->ausrc && ausrc_find(baresip_ausrcl(), NULL)) { struct ausrc_prm prm; @@ -1081,7 +1082,8 @@ static int start_source(struct autx *tx, struct audio *a) return err; } - err = ausrc_alloc(&tx->ausrc, NULL, a->cfg.src_mod, + err = ausrc_alloc(&tx->ausrc, baresip_ausrcl(), + NULL, a->cfg.src_mod, &prm, tx->device, ausrc_read_handler, ausrc_error_handler, a); if (err) { @@ -1471,7 +1473,8 @@ int audio_set_source(struct audio *au, const char *mod, const char *device) /* stop the audio device first */ tx->ausrc = mem_deref(tx->ausrc); - err = ausrc_alloc(&tx->ausrc, NULL, mod, &tx->ausrc_prm, device, + err = ausrc_alloc(&tx->ausrc, baresip_ausrcl(), + NULL, mod, &tx->ausrc_prm, device, ausrc_read_handler, ausrc_error_handler, au); if (err) { warning("audio: set_source failed (%s.%s): %m\n", @@ -1496,7 +1499,8 @@ int audio_set_player(struct audio *au, const char *mod, const char *device) /* stop the audio device first */ rx->auplay = mem_deref(rx->auplay); - err = auplay_alloc(&rx->auplay, mod, &rx->auplay_prm, device, + err = auplay_alloc(&rx->auplay, baresip_auplayl(), + mod, &rx->auplay_prm, device, auplay_write_handler, rx); if (err) { warning("audio: set_player failed (%s.%s): %m\n", diff --git a/src/auplay.c b/src/auplay.c index a1247b6..38a7010 100644 --- a/src/auplay.c +++ b/src/auplay.c @@ -9,9 +9,6 @@ #include "core.h" -static struct list auplayl = LIST_INIT; - - static void destructor(void *arg) { struct auplay *ap = arg; @@ -24,13 +21,14 @@ static void destructor(void *arg) * Register an Audio Player * * @param app Pointer to allocated Audio Player object + * @param auplayl List of Audio Players * @param name Audio Player name * @param alloch Allocation handler * * @return 0 if success, otherwise errorcode */ -int auplay_register(struct auplay **app, const char *name, - auplay_alloc_h *alloch) +int auplay_register(struct auplay **app, struct list *auplayl, + const char *name, auplay_alloc_h *alloch) { struct auplay *ap; @@ -41,7 +39,7 @@ int auplay_register(struct auplay **app, const char *name, if (!ap) return ENOMEM; - list_append(&auplayl, &ap->le, ap); + list_append(auplayl, &ap->le, ap); ap->name = name; ap->alloch = alloch; @@ -57,15 +55,16 @@ int auplay_register(struct auplay **app, const char *name, /** * Find an Audio Player by name * - * @param name Name of the Audio Player to find + * @param auplayl List of Audio Players + * @param name Name of the Audio Player to find * * @return Matching Audio Player if found, otherwise NULL */ -const struct auplay *auplay_find(const char *name) +const struct auplay *auplay_find(const struct list *auplayl, const char *name) { struct le *le; - for (le=auplayl.head; le; le=le->next) { + for (le=list_head(auplayl); le; le=le->next) { struct auplay *ap = le->data; @@ -82,22 +81,24 @@ const struct auplay *auplay_find(const char *name) /** * Allocate an Audio Player state * - * @param stp Pointer to allocated Audio Player state - * @param name Name of Audio Player - * @param prm Audio Player parameters - * @param device Name of Audio Player device (driver specific) - * @param wh Write handler - * @param arg Handler argument + * @param stp Pointer to allocated Audio Player state + * @param auplayl List of Audio Players + * @param name Name of Audio Player + * @param prm Audio Player parameters + * @param device Name of Audio Player device (driver specific) + * @param wh Write handler + * @param arg Handler argument * * @return 0 if success, otherwise errorcode */ -int auplay_alloc(struct auplay_st **stp, const char *name, +int auplay_alloc(struct auplay_st **stp, struct list *auplayl, + const char *name, struct auplay_prm *prm, const char *device, auplay_write_h *wh, void *arg) { struct auplay *ap; - ap = (struct auplay *)auplay_find(name); + ap = (struct auplay *)auplay_find(auplayl, name); if (!ap) return ENOENT; diff --git a/src/ausrc.c b/src/ausrc.c index 9782db3..c1ca416 100644 --- a/src/ausrc.c +++ b/src/ausrc.c @@ -9,9 +9,6 @@ #include "core.h" -static struct list ausrcl = LIST_INIT; - - static void destructor(void *arg) { struct ausrc *as = arg; @@ -24,12 +21,14 @@ static void destructor(void *arg) * Register an Audio Source * * @param asp Pointer to allocated Audio Source object + * @param ausrcl List of Audio Sources * @param name Audio Source name * @param alloch Allocation handler * * @return 0 if success, otherwise errorcode */ -int ausrc_register(struct ausrc **asp, const char *name, ausrc_alloc_h *alloch) +int ausrc_register(struct ausrc **asp, struct list *ausrcl, + const char *name, ausrc_alloc_h *alloch) { struct ausrc *as; @@ -40,7 +39,7 @@ int ausrc_register(struct ausrc **asp, const char *name, ausrc_alloc_h *alloch) if (!as) return ENOMEM; - list_append(&ausrcl, &as->le, as); + list_append(ausrcl, &as->le, as); as->name = name; as->alloch = alloch; @@ -56,15 +55,16 @@ int ausrc_register(struct ausrc **asp, const char *name, ausrc_alloc_h *alloch) /** * Find an Audio Source by name * - * @param name Name of the Audio Source to find + * @param ausrcl List of Audio Sources + * @param name Name of the Audio Source to find * * @return Matching Audio Source if found, otherwise NULL */ -const struct ausrc *ausrc_find(const char *name) +const struct ausrc *ausrc_find(const struct list *ausrcl, const char *name) { struct le *le; - for (le=ausrcl.head; le; le=le->next) { + for (le=list_head(ausrcl); le; le=le->next) { struct ausrc *as = le->data; @@ -82,6 +82,7 @@ const struct ausrc *ausrc_find(const char *name) * Allocate an Audio Source state * * @param stp Pointer to allocated Audio Source state + * @param ausrcl List of Audio Sources * @param ctx Media context (optional) * @param name Name of Audio Source * @param prm Audio Source parameters @@ -92,13 +93,14 @@ const struct ausrc *ausrc_find(const char *name) * * @return 0 if success, otherwise errorcode */ -int ausrc_alloc(struct ausrc_st **stp, struct media_ctx **ctx, +int ausrc_alloc(struct ausrc_st **stp, struct list *ausrcl, + struct media_ctx **ctx, const char *name, struct ausrc_prm *prm, const char *device, ausrc_read_h *rh, ausrc_error_h *errh, void *arg) { struct ausrc *as; - as = (struct ausrc *)ausrc_find(name); + as = (struct ausrc *)ausrc_find(ausrcl, name); if (!as) return ENOENT; diff --git a/src/baresip.c b/src/baresip.c index ae715ce..501fbe1 100644 --- a/src/baresip.c +++ b/src/baresip.c @@ -21,6 +21,8 @@ static struct baresip { struct list mnatl; struct list mencl; struct list aucodecl; + struct list ausrcl; + struct list auplayl; } baresip; @@ -36,6 +38,8 @@ int baresip_init(struct config *cfg, bool prefer_ipv6) list_init(&baresip.mnatl); list_init(&baresip.mencl); list_init(&baresip.aucodecl); + list_init(&baresip.ausrcl); + list_init(&baresip.auplayl); /* Initialise Network */ err = net_alloc(&baresip.net, &cfg->net, @@ -129,3 +133,15 @@ struct list *baresip_aucodecl(void) { return &baresip.aucodecl; } + + +struct list *baresip_ausrcl(void) +{ + return &baresip.ausrcl; +} + + +struct list *baresip_auplayl(void) +{ + return &baresip.auplayl; +} @@ -251,7 +251,8 @@ int play_tone(struct play **playp, struct player *player, wprm.srate = srate; wprm.ptime = PTIME; - err = auplay_alloc(&play->auplay, cfg->audio.alert_mod, &wprm, + err = auplay_alloc(&play->auplay, baresip_auplayl(), + cfg->audio.alert_mod, &wprm, cfg->audio.alert_dev, write_handler, play); if (err) goto out; |