[3/3] module-role-ducking: Add argument duck_while_corked

Submitted by Juho Hämäläinen on July 13, 2018, 8:21 a.m.

Details

Message ID 1531470065-6571-4-git-send-email-jusa@hilvi.org
State New
Series "Series without cover letter"
Headers show

Commit Message

Juho Hämäläinen July 13, 2018, 8:21 a.m.
With this enabled when trigger stream is available but
in corked state trigger is already applied to interaction
streams. This is useful when trigger stream pauses for
a while before playing, so that the trigger happens
slightly earlier.

Signed-off-by: Juho Hämäläinen <jusa@hilvi.org>
---
 src/modules/module-role-ducking.c |  2 ++
 src/modules/stream-interaction.c  | 16 ++++++++++------
 2 files changed, 12 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/modules/module-role-ducking.c b/src/modules/module-role-ducking.c
index 1b2ecd7..50c23b7 100644
--- a/src/modules/module-role-ducking.c
+++ b/src/modules/module-role-ducking.c
@@ -34,6 +34,7 @@  PA_MODULE_USAGE(
         "ducking_roles=<Comma(and slash) separated list of roles which will be ducked. Slash can divide the roles into groups>"
         "global=<Should we operate globally or only inside the same device?>"
         "volume=<Volume for the attenuated streams. Default: -20dB. If trigger_roles and ducking_roles are separated by slash, use slash for dividing volume group>"
+        "duck_while_corked=<Duck ducking_roles even if trigger_roles are corked. Default false>"
 );
 
 static const char* const valid_modargs[] = {
@@ -41,6 +42,7 @@  static const char* const valid_modargs[] = {
     "ducking_roles",
     "global",
     "volume",
+    "duck_while_corked",
     NULL
 };
 
diff --git a/src/modules/stream-interaction.c b/src/modules/stream-interaction.c
index c30a8c0..dc727dc 100644
--- a/src/modules/stream-interaction.c
+++ b/src/modules/stream-interaction.c
@@ -56,8 +56,9 @@  struct group {
 struct userdata {
     pa_core *core;
     PA_LLIST_HEAD(struct group, groups);
-    bool global:1;
-    bool duck:1;
+    bool global;
+    bool duck;
+    bool duck_while_corked;
 };
 
 static const char *sink_input_role(pa_sink_input *sink_input) {
@@ -85,7 +86,7 @@  static bool update_group_active(struct userdata *u, struct group *g) {
     if (pa_hashmap_size(g->trigger_state) > 0) {
         PA_HASHMAP_FOREACH_KV(sink_input, value, g->trigger_state, state) {
             if (!sink_input->muted &&
-                sink_input->state != PA_SINK_INPUT_CORKED) {
+                (u->duck_while_corked || sink_input->state != PA_SINK_INPUT_CORKED)) {
                 new_active = true;
                 break;
             }
@@ -463,7 +464,6 @@  static int count_groups(pa_modargs *ma, const char *module_argument) {
 int pa_stream_interaction_init(pa_module *m, const char* const v_modargs[]) {
     pa_modargs *ma = NULL;
     struct userdata *u;
-    bool global = false;
     uint32_t i = 0;
     uint32_t group_count_tr = 0;
     struct group *last = NULL;
@@ -539,11 +539,15 @@  int pa_stream_interaction_init(pa_module *m, const char* const v_modargs[]) {
         if (!group_parse_roles(ma, "volume", group_value_add_volume, u->groups))
             goto fail;
 
-    if (pa_modargs_get_value_boolean(ma, "global", &global) < 0) {
+    if (pa_modargs_get_value_boolean(ma, "global", &u->global) < 0) {
         pa_log("Invalid boolean parameter: global");
         goto fail;
     }
-    u->global = global;
+
+    if (pa_modargs_get_value_boolean(ma, "duck_while_corked", &u->duck_while_corked) < 0) {
+        pa_log("Invalid boolean parameter: duck_while_corked");
+        goto fail;
+    }
 
     pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_INPUT_PUT], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_put_cb, u);
     pa_module_hook_connect(m, &m->core->hooks[PA_CORE_HOOK_SINK_INPUT_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_unlink_cb, u);

Comments

Tanu Kaskinen Aug. 11, 2018, 9:52 a.m.
On Fri, 2018-07-13 at 11:21 +0300, Juho Hämäläinen wrote:
> With this enabled when trigger stream is available but
> in corked state trigger is already applied to interaction
> streams. This is useful when trigger stream pauses for
> a while before playing, so that the trigger happens
> slightly earlier.

Is this option something that you actually use (or want to use)? Can
you give a concrete example of where this is useful?

If a new option is added, I think it would be good to have it also for
module-role-cork, and I would suggest "ignore_corked_triggers" for the
option name (the meaning is inverted, so the default should be true).