Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
sfos: combine-sink: Add argument for ignoring sinks in automatic mode.
  • Loading branch information
jusa committed Feb 24, 2021
1 parent 0f0e393 commit 7b861ff
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/modules/module-combine-sink.c
Expand Up @@ -45,6 +45,8 @@
#include <pulsecore/rtpoll.h>
#include <pulsecore/time-smoother.h>
#include <pulsecore/strlist.h>
#include <pulsecore/hashmap.h>
#include <pulsecore/idxset.h>

PA_MODULE_AUTHOR("Lennart Poettering");
PA_MODULE_DESCRIPTION("Combine multiple sinks to one");
Expand All @@ -54,6 +56,7 @@ PA_MODULE_USAGE(
"sink_name=<name for the sink> "
"sink_properties=<properties for the sink> "
"slaves=<slave sinks> "
"ignore=<slave sinks to ignore in automatic mode> "
"adjust_time=<how often to readjust rates in s> "
"resample_method=<method> "
"format=<sample format> "
Expand All @@ -73,6 +76,7 @@ static const char* const valid_modargs[] = {
"sink_name",
"sink_properties",
"slaves",
"ignore",
"adjust_time",
"resample_method",
"format",
Expand Down Expand Up @@ -140,6 +144,8 @@ struct userdata {
bool automatic;
bool auto_desc;

pa_hashmap *ignore_sinks;

pa_strlist *unlinked_slaves;

pa_hook_slot *sink_put_slot, *sink_unlink_slot, *sink_state_changed_slot;
Expand Down Expand Up @@ -1187,6 +1193,9 @@ static bool is_suitable_sink(struct userdata *u, pa_sink *s) {
if (!pa_streq(t, "sound"))
return false;

if (u->ignore_sinks && pa_hashmap_get(u->ignore_sinks, s->name))
return false;

return true;
}

Expand Down Expand Up @@ -1286,7 +1295,7 @@ static pa_hook_result_t sink_state_changed_hook_cb(pa_core *c, pa_sink *s, struc
int pa__init(pa_module*m) {
struct userdata *u;
pa_modargs *ma = NULL;
const char *slaves, *rm;
const char *slaves, *rm, *ignore;
int resample_method = PA_RESAMPLER_TRIVIAL;
pa_sample_spec ss;
pa_channel_map map;
Expand Down Expand Up @@ -1345,6 +1354,28 @@ int pa__init(pa_module*m) {
slaves = pa_modargs_get_value(ma, "slaves", NULL);
u->automatic = !slaves;

if ((ignore = pa_modargs_get_value(ma, "ignore", NULL))) {
const char* split_state = NULL;
char *n = NULL;

if (!u->automatic) {
pa_log("ignore is not valid argument when not in automatic mode");
goto fail;
}

u->ignore_sinks = pa_hashmap_new_full(pa_idxset_string_hash_func,
pa_idxset_string_compare_func,
pa_xfree,
NULL);

while ((n = pa_split(ignore, ",", &split_state))) {
if (!pa_hashmap_get(u->ignore_sinks, n))
pa_hashmap_put(u->ignore_sinks, n, PA_UINT_TO_PTR(1));
else
pa_xfree(n);
}
}

ss = m->core->default_sample_spec;
map = m->core->default_channel_map;

Expand Down Expand Up @@ -1543,6 +1574,9 @@ void pa__done(pa_module*m) {

pa_strlist_free(u->unlinked_slaves);

if (u->ignore_sinks)
pa_hashmap_free(u->ignore_sinks);

if (u->sink_put_slot)
pa_hook_slot_free(u->sink_put_slot);

Expand Down

0 comments on commit 7b861ff

Please sign in to comment.