From ad84153daccb964c22cb859d526958da24bdc0d9 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Thu, 10 Oct 2024 07:06:44 +0200 Subject: [PATCH] amix/aumix: add slmagic record routing --- Makefile | 3 +- modules/amix/amix.c | 20 ++++++++++- patches/re_aumix_record_only.patch | 54 ++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 patches/re_aumix_record_only.patch diff --git a/Makefile b/Makefile index 624b44b..1400994 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,8 @@ external: git clone --depth 1 -b playout_time \ https://github.com/baresip/baresip.git external/baresip cd external/re && \ - patch -p1 < ../../patches/re_aubuf_timestamp_order_fix.patch + patch -p1 < ../../patches/re_aubuf_timestamp_order_fix.patch && \ + patch -p1 < ../../patches/re_aumix_record_only.patch .PHONY: external_pro external_pro: external diff --git a/modules/amix/amix.c b/modules/amix/amix.c index 52120db..2580764 100644 --- a/modules/amix/amix.c +++ b/modules/amix/amix.c @@ -42,6 +42,7 @@ struct amix { struct aumix_source *aumix_src; char *device; uint16_t speaker_id; + bool magic; bool muted; }; @@ -140,6 +141,13 @@ static int amix_alloc(struct amix **amixp, const char *device) amix->muted = true; + if (strstr(device, "slmagic")) { + amix->magic = true; + aumix_source_mute(amix->aumix_src, amix->muted); + aumix_source_enable(amix->aumix_src, true); + aumix_source_record_only(amix->aumix_src, true); + } + out: if (err) { mem_deref(amix); @@ -303,7 +311,9 @@ static int play_alloc(struct auplay_st **stp, const struct auplay *ap, void amix_mute(const char *dev, bool mute, uint16_t id); void amix_mute(const char *dev, bool mute, uint16_t id) { - struct le *le; + struct le *le, *le_magic; + char dev_magic[128]; + struct amix *amix_magic = NULL; le = hash_lookup(amixl, hash_joaat_str(dev), dev_cmp_h, (void *)dev); if (!le) @@ -311,10 +321,18 @@ void amix_mute(const char *dev, bool mute, uint16_t id) struct amix *amix = le->data; + re_snprintf(dev_magic, sizeof(dev_magic), "%s_slmagic", dev); + le_magic = hash_lookup(amixl, hash_joaat_str(dev_magic), dev_cmp_h, + (void *)dev_magic); + if (le_magic) + amix_magic = le_magic->data; + aumix_source_mute(amix->aumix_src, mute); amix->muted = mute; if (id) { amix->speaker_id = id; + if (amix_magic) + amix_magic->speaker_id = 10000 + id; if (!list_contains(&speakerl, &amix->sle)) list_append(&speakerl, &amix->sle, amix); diff --git a/patches/re_aumix_record_only.patch b/patches/re_aumix_record_only.patch new file mode 100644 index 0000000..d1b33ea --- /dev/null +++ b/patches/re_aumix_record_only.patch @@ -0,0 +1,54 @@ +diff --git a/rem/aumix/aumix.c b/rem/aumix/aumix.c +index 95032be..b46fbf7 100644 +--- a/rem/aumix/aumix.c ++++ b/rem/aumix/aumix.c +@@ -47,6 +47,7 @@ struct aumix_source { + aumix_read_h *readh; + void *arg; + bool muted; ++ bool record_only; + }; + + +@@ -193,6 +194,9 @@ static int aumix_thread(void *arg) + if (csrc->muted) + continue; + ++ if (csrc->record_only) ++ continue; ++ + for (size_t i = 0; i < mix->frame_size; i++) { + sample = mix_frame[i] + csrc->frame[i]; + +@@ -222,6 +226,9 @@ static int aumix_thread(void *arg) + if (csrc->muted) + continue; + ++ if(!csrc->record_only) ++ continue; ++ + for (size_t i = 0; i < mix->frame_size; i++) { + sample = mix_frame[i] + csrc->frame[i]; + +@@ -493,6 +500,21 @@ void aumix_source_mute(struct aumix_source *src, bool mute) + } + + ++/** ++ * Record only aumix source ++ * ++ * @param src Audio mixer source ++ * @param mute True to record only, false to disable ++ */ ++void aumix_source_record_only(struct aumix_source *src, bool enable) ++{ ++ if (!src) ++ return; ++ ++ src->record_only = enable; ++} ++ ++ + /** + * Enable/disable aumix source + *