dbus_bool_t enable = 0;
const char *target_stream = NULL;
uint32_t idx = 0;
- pa_sink_input *stream = NULL;
+ pa_sink_input *i = NULL;
dbus_uint32_t duration = 0;
double ratio = 0.0;
DBusMessage *reply = NULL;
}
/* set volume ramp factor to target stream */
- PA_IDXSET_FOREACH(stream, m->core->sink_inputs, idx) {
- if (!pa_safe_streq(target_stream, pa_proplist_gets(stream->proplist, PA_PROP_MEDIA_ROLE)))
+ PA_IDXSET_FOREACH(i, m->core->sink_inputs, idx) {
+ if (!pa_safe_streq(target_stream, pa_proplist_gets(i->proplist, PA_PROP_MEDIA_ROLE)))
continue;
- target_matched = true;
- sd->ducking_stream_count++;
+ if (i->state == PA_SINK_INPUT_RUNNING) {
+ target_matched = true;
+ sd->ducking_stream_count++;
+ }
if (enable) {
pa_cvolume_ramp vol_ramp;
- pa_idxset_put(sd->idx_ducking_streams, (void *)stream, NULL);
+ pa_idxset_put(sd->idx_ducking_streams, (void *)i, NULL);
pa_log_info("ducking: add volume_ramp factor, key[%s], set_vol[%u] to stream[idx:%u]",
- sd->vol_key, sd->set_vol, stream->index);
+ sd->vol_key, sd->set_vol, i->index);
- pa_cvolume_ramp_set(&vol_ramp, stream->volume.channels,
+ pa_cvolume_ramp_set(&vol_ramp, i->volume.channels,
PA_VOLUME_RAMP_TYPE_LINEAR, (long)duration, sd->set_vol);
- pa_sink_input_add_volume_ramp_factor(stream, sd->vol_key, &vol_ramp, true);
+ if (i->state != PA_SINK_INPUT_RUNNING) {
+ pa_cvolume vol;
+ pa_cvolume_set(&vol, i->volume.channels, sd->set_vol);
+ pa_sink_input_add_volume_factor(i, sd->vol_key, &vol);
+ pa_sink_input_add_volume_ramp_factor(i, sd->vol_key, &vol_ramp, false);
+ } else {
+ pa_sink_input_add_volume_ramp_factor(i, sd->vol_key, &vol_ramp, true);
+ }
+
} else {
pa_log_info("unducking: remove volume(ramp) factor, key[%s] from stream[idx:%u]",
- sd->vol_key, stream->index);
+ sd->vol_key, i->index);
- pa_sink_input_remove_volume_factor(stream, sd->vol_key);
- pa_sink_input_remove_volume_ramp_factor(stream, sd->vol_key, true);
+ pa_sink_input_remove_volume_factor(i, sd->vol_key);
+ pa_sink_input_remove_volume_ramp_factor(i, sd->vol_key, true);
}
}
pa_log_info("remove stream(idx:%u,%p) from idx_ducking_streams, trigger_index(%u)",
i->index, i, sd->trigger_index);
- pa_idxset_remove_by_data(sd->idx_ducking_streams, stream, NULL);
+ pa_idxset_remove_by_data(sd->idx_ducking_streams, i, NULL);
+
return;
}
}
is_ducked = i->thread_info.ramp.ramps[0].start > i->thread_info.ramp.ramps[0].end;
- /* remove trigger when unducked */
+ /* Remove trigger when unducked */
if (is_ducked == false)
pa_idxset_remove_by_data(sd->idx_ducking_streams, (void *)i, NULL);
- /* send signal when all streams are ducked */
- if (--sd->ducking_stream_count == 0) {
+ /* Send signal when all streams are ducked.
+ * Note that the condition of increasing count value below is located in
+ * handle_activate_ducking() of DBus handler. */
+ if (sd->ducking_stream_count > 0 && --sd->ducking_stream_count == 0) {
pa_log_info("send signal for ramp finished - is_ducked(%d)", is_ducked);
sd->is_ducked = is_ducked;
send_ducking_state_changed_signal(pa_dbus_connection_get(m->dbus_conn), sd->trigger_index, sd->is_ducked);