[pulseaudio-discuss] [PATCH v2 1/4] stream-interaction: Modify codes to use idxset and macro
Sangchul Lee
sangchul1011 at gmail.com
Fri Apr 28 13:37:57 UTC 2017
Revise variable name and type(change interaction_state(hashmap) to interacted_inputs(idxset)).
Use PA_IDXSET_FOREACH macro instead of for loop and idxset functions.
Signed-off-by: Sangchul Lee <sc11.lee at samsung.com>
---
src/modules/stream-interaction.c | 29 +++++++++++++++--------------
1 file changed, 15 insertions(+), 14 deletions(-)
diff --git a/src/modules/stream-interaction.c b/src/modules/stream-interaction.c
index 4184786..32df9fb 100644
--- a/src/modules/stream-interaction.c
+++ b/src/modules/stream-interaction.c
@@ -38,7 +38,7 @@ struct group {
char *name;
pa_idxset *trigger_roles;
pa_idxset *interaction_roles;
- pa_hashmap *interaction_state;
+ pa_idxset *interacted_inputs;
pa_volume_t volume;
};
@@ -92,8 +92,7 @@ static const char *find_trigger_stream(struct userdata *u, pa_sink *s, pa_sink_i
pa_assert(u);
pa_sink_assert_ref(s);
- for (j = PA_SINK_INPUT(pa_idxset_first(s->inputs, &idx)); j; j = PA_SINK_INPUT(pa_idxset_next(s->inputs, &idx))) {
-
+ PA_IDXSET_FOREACH(j, s->inputs, idx) {
if (j == ignore)
continue;
@@ -162,7 +161,7 @@ static inline void apply_interaction_to_sink(struct userdata *u, pa_sink *s, con
pa_assert(u);
pa_sink_assert_ref(s);
- for (j = PA_SINK_INPUT(pa_idxset_first(s->inputs, &idx)); j; j = PA_SINK_INPUT(pa_idxset_next(s->inputs, &idx))) {
+ PA_IDXSET_FOREACH(j, s->inputs, idx) {
bool corked, interaction_applied;
const char *role;
@@ -188,16 +187,20 @@ static inline void apply_interaction_to_sink(struct userdata *u, pa_sink *s, con
corked = (pa_sink_input_get_state(j) == PA_SINK_INPUT_CORKED);
if (new_stream && corked)
corked = false;
- interaction_applied = !!pa_hashmap_get(g->interaction_state, j);
+
+ if (pa_idxset_get_by_data(g->interacted_inputs, j, NULL))
+ interaction_applied = true;
+ else
+ interaction_applied = false;
if (new_trigger && ((!corked && !j->muted) || u->duck)) {
if (!interaction_applied)
- pa_hashmap_put(g->interaction_state, j, PA_INT_TO_PTR(1));
+ pa_idxset_put(g->interacted_inputs, j, NULL);
cork_or_duck(u, j, role, new_trigger, interaction_applied, g);
} else if (!new_trigger && interaction_applied) {
- pa_hashmap_remove(g->interaction_state, j);
+ pa_idxset_remove_by_data(g->interacted_inputs, j, NULL);
uncork_or_unduck(u, j, role, corked, g);
}
@@ -223,10 +226,8 @@ static void remove_interactions(struct userdata *u, struct group *g) {
const char *role;
PA_IDXSET_FOREACH(s, u->core->sinks, idx) {
-
- for (j = PA_SINK_INPUT(pa_idxset_first(s->inputs, &idx_input)); j; j = PA_SINK_INPUT(pa_idxset_next(s->inputs, &idx_input))) {
-
- if(!!pa_hashmap_get(g->interaction_state, j)) {
+ PA_IDXSET_FOREACH(j, s->inputs, idx_input) {
+ if (pa_idxset_get_by_data(g->interacted_inputs, j, NULL)) {
corked = (pa_sink_input_get_state(j) == PA_SINK_INPUT_CORKED);
if (!(role = pa_proplist_gets(j->proplist, PA_PROP_MEDIA_ROLE)))
role = "no_role";
@@ -245,7 +246,7 @@ static pa_hook_result_t process(struct userdata *u, pa_sink_input *i, bool creat
if (!create)
for (j = 0; j < u->n_groups; j++)
- pa_hashmap_remove(u->groups[j]->interaction_state, i);
+ pa_idxset_remove_by_data(u->groups[j]->interacted_inputs, i, NULL);
if (!i->sink)
return PA_HOOK_OK;
@@ -389,7 +390,7 @@ int pa_stream_interaction_init(pa_module *m, const char* const v_modargs[]) {
u->groups[i] = pa_xnew0(struct group, 1);
u->groups[i]->trigger_roles = pa_idxset_new(NULL, NULL);
u->groups[i]->interaction_roles = pa_idxset_new(NULL, NULL);
- u->groups[i]->interaction_state = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
+ u->groups[i]->interacted_inputs = pa_idxset_new(NULL, NULL);
if (u->duck)
u->groups[i]->name = pa_sprintf_malloc("ducking_group_%u", i);
}
@@ -527,7 +528,7 @@ void pa_stream_interaction_done(pa_module *m) {
remove_interactions(u, u->groups[j]);
pa_idxset_free(u->groups[j]->trigger_roles, pa_xfree);
pa_idxset_free(u->groups[j]->interaction_roles, pa_xfree);
- pa_hashmap_free(u->groups[j]->interaction_state);
+ pa_idxset_free(u->groups[j]->interacted_inputs, pa_xfree);
if (u->duck)
pa_xfree(u->groups[j]->name);
pa_xfree(u->groups[j]);
--
2.7.4
More information about the pulseaudio-discuss
mailing list