summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfred E. Heggestad <aeh@db.org>2015-10-11 13:01:47 +0200
committerAlfred E. Heggestad <aeh@db.org>2015-10-11 13:01:47 +0200
commite82485c88c082e96343d7cc72f955e0ccbd64a4e (patch)
tree802e1d61f49adf3f00b2d52bcab96acffd1df575
parent25225de72f2ba6c89abe862e2e027906c9ef8a76 (diff)
audio: add API to set source/player while in call
int audio_set_source(struct audio *au, const char *mod, const char *device); int audio_set_player(struct audio *au, const char *mod, const char *device); example usage: audio_set_player(call_audio(ua_call(uag_cur())), "alsa", "default"); fixes #70
-rw-r--r--include/baresip.h2
-rw-r--r--src/audio.c56
2 files changed, 58 insertions, 0 deletions
diff --git a/include/baresip.h b/include/baresip.h
index 9c87e95..67fef23 100644
--- a/include/baresip.h
+++ b/include/baresip.h
@@ -844,6 +844,8 @@ struct audio;
void audio_mute(struct audio *a, bool muted);
bool audio_ismuted(const struct audio *a);
void audio_set_devicename(struct audio *a, const char *src, const char *play);
+int audio_set_source(struct audio *au, const char *mod, const char *device);
+int audio_set_player(struct audio *au, const char *mod, const char *device);
void audio_encoder_cycle(struct audio *audio);
int audio_debug(struct re_printf *pf, const struct audio *a);
diff --git a/src/audio.c b/src/audio.c
index 78adc7d..5e4d390 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -75,6 +75,7 @@ enum {
*/
struct autx {
struct ausrc_st *ausrc; /**< Audio Source */
+ struct ausrc_prm ausrc_prm;
const struct aucodec *ac; /**< Current audio encoder */
struct auenc_state *enc; /**< Audio encoder state (optional) */
struct aubuf *aubuf; /**< Packetize outgoing stream */
@@ -122,6 +123,7 @@ struct autx {
*/
struct aurx {
struct auplay_st *auplay; /**< Audio Player */
+ struct auplay_prm auplay_prm;
const struct aucodec *ac; /**< Current audio decoder */
struct audec_state *dec; /**< Audio decoder state (optional) */
struct aubuf *aubuf; /**< Incoming audio buffer */
@@ -962,6 +964,8 @@ static int start_player(struct aurx *rx, struct audio *a)
a->cfg.play_mod, rx->device, err);
return err;
}
+
+ rx->auplay_prm = prm;
}
return 0;
@@ -1061,6 +1065,8 @@ static int start_source(struct autx *tx, struct audio *a)
default:
break;
}
+
+ tx->ausrc_prm = prm;
}
return 0;
@@ -1397,6 +1403,56 @@ void audio_set_devicename(struct audio *a, const char *src, const char *play)
}
+int audio_set_source(struct audio *au, const char *mod, const char *device)
+{
+ struct autx *tx;
+ int err;
+
+ if (!au)
+ return EINVAL;
+
+ tx = &au->tx;
+
+ /* stop the audio device first */
+ tx->ausrc = mem_deref(tx->ausrc);
+
+ err = ausrc_alloc(&tx->ausrc, NULL, mod, &tx->ausrc_prm, device,
+ ausrc_read_handler, ausrc_error_handler, au);
+ if (err) {
+ warning("audio: set_source failed (%s.%s): %m\n",
+ mod, device, err);
+ return err;
+ }
+
+ return 0;
+}
+
+
+int audio_set_player(struct audio *au, const char *mod, const char *device)
+{
+ struct aurx *rx;
+ int err;
+
+ if (!au)
+ return EINVAL;
+
+ rx = &au->rx;
+
+ /* stop the audio device first */
+ rx->auplay = mem_deref(rx->auplay);
+
+ err = auplay_alloc(&rx->auplay, mod, &rx->auplay_prm, device,
+ auplay_write_handler, rx);
+ if (err) {
+ warning("audio: set_player failed (%s.%s): %m\n",
+ mod, device, err);
+ return err;
+ }
+
+ return 0;
+}
+
+
/*
* Reference:
*