Skip to content

Commit

Permalink
role-ducking, role-cork: Add use_source_trigger argument
Browse files Browse the repository at this point in the history
This is added to keep backward compatibility. The default value of
this new argument is false. Therefore, triggering by source-output
will be activated only if it is set to true explicitly.

Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
  • Loading branch information
sangchul1011 authored and georgchini committed Mar 26, 2019
1 parent 5540f72 commit 65cc86f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/modules/module-role-cork.c
Expand Up @@ -32,12 +32,15 @@ PA_MODULE_LOAD_ONCE(true);
PA_MODULE_USAGE(
"trigger_roles=<Comma separated list of roles which will trigger a cork> "
"cork_roles=<Comma separated list of roles which will be corked> "
"global=<Should we operate globally or only inside the same device?>");
"global=<Should we operate globally or only inside the same device?>"
"use_source_trigger=<Do we trigger a cork by a role of source-output as well as sink-input's? Default: false>"
);

static const char* const valid_modargs[] = {
"trigger_roles",
"cork_roles",
"global",
"use_source_trigger",
NULL
};

Expand Down
2 changes: 2 additions & 0 deletions src/modules/module-role-ducking.c
Expand Up @@ -34,13 +34,15 @@ 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>"
"use_source_trigger=<Do we trigger a ducking by a role of source-output as well as sink-input's? Default: false>"
);

static const char* const valid_modargs[] = {
"trigger_roles",
"ducking_roles",
"global",
"volume",
"use_source_trigger",
NULL
};

Expand Down
31 changes: 24 additions & 7 deletions src/modules/stream-interaction.c
Expand Up @@ -48,6 +48,7 @@ struct userdata {
struct group **groups;
bool global:1;
bool duck:1;
bool source_trigger:1;
pa_hook_slot
*sink_input_put_slot,
*sink_input_unlink_slot,
Expand Down Expand Up @@ -114,9 +115,14 @@ static const char *find_trigger_stream(struct userdata *u, pa_object *device, pa
if (!(trigger_role = get_trigger_role(u, PA_OBJECT(j), g)))
continue;

if (pa_sink_isinstance(device) ? !PA_SINK_INPUT(j)->muted && PA_SINK_INPUT(j)->state != PA_SINK_INPUT_CORKED :
!PA_SOURCE_OUTPUT(j)->muted && PA_SOURCE_OUTPUT(j)->state != PA_SOURCE_OUTPUT_CORKED) {
return trigger_role;
if (pa_sink_isinstance(device)) {
if (!PA_SINK_INPUT(j)->muted &&
PA_SINK_INPUT(j)->state != PA_SINK_INPUT_CORKED)
return trigger_role;
} else {
if (!PA_SOURCE_OUTPUT(j)->muted &&
PA_SOURCE_OUTPUT(j)->state != PA_SOURCE_OUTPUT_CORKED)
return trigger_role;
}
}

Expand All @@ -136,7 +142,7 @@ static const char *find_global_trigger_stream(struct userdata *u, pa_object *ign
if ((trigger_role = find_trigger_stream(u, PA_OBJECT(sink), ignore_stream, g)))
break;

if (trigger_role)
if (!u->source_trigger || trigger_role)
return trigger_role;

PA_IDXSET_FOREACH(source, u->core->sources, idx)
Expand Down Expand Up @@ -274,9 +280,13 @@ static pa_hook_result_t process(struct userdata *u, pa_object *stream, bool crea
(pa_source_output_isinstance(stream) && !PA_SOURCE_OUTPUT(stream)->source))
return PA_HOOK_OK;

/* If it is triggered from source-output with false of global option, no need to apply interaction. */
if (!u->global && pa_source_output_isinstance(stream))
return PA_HOOK_OK;
if (pa_source_output_isinstance(stream)) {
if (!u->source_trigger)
return PA_HOOK_OK;
/* If it is triggered from source-output with false of global option, no need to apply interaction. */
if (!u->global)
return PA_HOOK_OK;
}

for (j = 0; j < u->n_groups; j++) {
if (u->global) {
Expand Down Expand Up @@ -412,6 +422,7 @@ int pa_stream_interaction_init(pa_module *m, const char* const v_modargs[]) {
const char *roles;
char *roles_in_group = NULL;
bool global = false;
bool source_trigger = false;
uint32_t i = 0;

pa_assert(m);
Expand Down Expand Up @@ -580,6 +591,12 @@ int pa_stream_interaction_init(pa_module *m, const char* const v_modargs[]) {
}
u->global = global;

if (pa_modargs_get_value_boolean(ma, "use_source_trigger", &source_trigger) < 0) {
pa_log("Invalid boolean parameter: use_source_trigger");
goto fail;
}
u->source_trigger = source_trigger;

u->sink_input_put_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_PUT], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_put_cb, u);
u->sink_input_unlink_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_UNLINK], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_unlink_cb, u);
u->sink_input_move_start_slot = pa_hook_connect(&m->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_START], PA_HOOK_LATE, (pa_hook_cb_t) sink_input_move_start_cb, u);
Expand Down

0 comments on commit 65cc86f

Please sign in to comment.