role-ducking, role-cork: Add use_source_trigger argument

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>
This commit is contained in:
Sangchul Lee 2019-03-18 14:46:13 +09:00 committed by Georg Chini
parent 5540f728e5
commit 65cc86f609
3 changed files with 30 additions and 8 deletions

View file

@ -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
};

View file

@ -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>"
"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[] = {
@ -41,6 +42,7 @@ static const char* const valid_modargs[] = {
"ducking_roles",
"global",
"volume",
"use_source_trigger",
NULL
};

View file

@ -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,
@ -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;
}
}
@ -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)
@ -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) {
@ -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);
@ -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);