double ratio = 0.0;
DBusMessage *reply = NULL;
pa_stream_manager *m = (pa_stream_manager*)userdata;
+ pa_cvolume vol;
+ pa_cvolume_ramp vol_ramp;
stream_ducking *sd = NULL;
- bool target_matched = false;
hal_ducking_activation_info ducking_activation_info;
ret_msg_t ret_msg = RET_MSG_OK;
if (!pa_safe_streq(target_stream, pa_proplist_gets(i->proplist, PA_PROP_MEDIA_ROLE)))
continue;
- if (i->state == PA_SINK_INPUT_RUNNING) {
- target_matched = true;
+ if (i->state == PA_SINK_INPUT_RUNNING)
sd->ducking_stream_count++;
- }
if (enable) {
- pa_cvolume_ramp vol_ramp;
-
pa_idxset_put(sd->idx_ducking_streams, (void *)i, NULL);
pa_log_error("ducking: add volume_ramp factor, key[%s], set_vol[%u] to stream[idx:%u]",
pa_cvolume_ramp_set(&vol_ramp, i->volume.channels,
PA_VOLUME_RAMP_TYPE_LINEAR, (long)duration, sd->set_vol);
- if (i->state != PA_SINK_INPUT_RUNNING) {
- pa_cvolume vol;
+ if (i->state != PA_SINK_INPUT_RUNNING || duration == 0) {
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);
pa_hal_interface_notify_ducking_activation_changed(m->hal, &ducking_activation_info);
- if (target_matched == false) {
+ if (sd->ducking_stream_count <= 0 || duration == 0) {
/* change ducking state and send signal here,
- because ramp_finish_cb could not be called in this case */
+ because ramp_finish_cb could not be called in this case. */
if (enable)
sd->state = STREAM_DUCKING_STATE_DUCKED;
else
sd->state = STREAM_DUCKING_STATE_UNDUCKED;
- pa_log_info("send signal for ramp finished(but, no stream matched) - state[%u]", sd->state);
+ pa_log_info("send signal for ramp finished - state[%u]", sd->state);
+
+ /* It should be reset here because it's increased,
+ but will not be decreased in case of 0 duration. */
+ sd->ducking_stream_count = 0;
send_ducking_state_changed_signal(pa_dbus_connection_get(m->dbus_conn), sd->trigger_index, is_stream_ducked(sd));
}