+ pa_sink_input_assert_ref(i);
+ pa_assert_ctl_context();
+ pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
+ pa_assert(volume_factor);
+ pa_assert(key);
+ pa_assert(pa_cvolume_valid(volume_factor));
+ pa_assert(volume_factor->channels == 1 || pa_cvolume_compatible(volume_factor, &i->sample_spec));
+
+ v = volume_factor_entry_new(key, volume_factor);
+ if (!pa_cvolume_compatible(volume_factor, &i->sample_spec))
+ pa_cvolume_set(&v->volume, i->sample_spec.channels, volume_factor->values[0]);
+
+ pa_assert_se(pa_hashmap_put(i->volume_factor_items, v->key, v) >= 0);
+ if (pa_hashmap_size(i->volume_factor_items) == 1)
+ i->volume_factor = v->volume;
+ else
+ pa_sw_cvolume_multiply(&i->volume_factor, &i->volume_factor, &v->volume);
+
+ pa_sw_cvolume_multiply(&i->soft_volume, &i->real_ratio, &i->volume_factor);
+
+ /* Copy the new soft_volume to the thread_info struct */
+ pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_SOFT_VOLUME, NULL, 0, NULL) == 0);
+}
+
+/* Returns 0 if an entry was removed and -1 if no entry for the given key was
+ * found. */
+int pa_sink_input_remove_volume_factor(pa_sink_input *i, const char *key) {
+ struct volume_factor_entry *v;
+
+ pa_sink_input_assert_ref(i);
+ pa_assert(key);
+ pa_assert_ctl_context();
+ pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
+
+ if (pa_hashmap_remove_and_free(i->volume_factor_items, key) < 0)
+ return -1;
+
+ switch (pa_hashmap_size(i->volume_factor_items)) {
+ case 0:
+ pa_cvolume_reset(&i->volume_factor, i->sample_spec.channels);
+ break;
+ case 1:
+ v = pa_hashmap_first(i->volume_factor_items);
+ i->volume_factor = v->volume;
+ break;
+ default:
+ volume_factor_from_hashmap(&i->volume_factor, i->volume_factor_items, i->volume_factor.channels);
+ }
+
+ pa_sw_cvolume_multiply(&i->soft_volume, &i->real_ratio, &i->volume_factor);
+
+ /* Copy the new soft_volume to the thread_info struct */
+ pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_SOFT_VOLUME, NULL, 0, NULL) == 0);
+
+ return 0;