if (enable) {
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]",
- sd->vol_key, sd->set_vol, i->index);
+ pa_log_error("ducking: add volume_ramp factor, key[%s], set_vol[%u] to stream[idx:%u, state:%u]",
+ sd->vol_key, sd->set_vol, i->index, i->state);
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(i, sd->vol_key, &vol_ramp, true);
}
} else {
- pa_log_error("unducking: remove volume(ramp) factor, key[%s] from stream[idx:%u]",
- sd->vol_key, i->index);
+ pa_log_error("unducking: remove volume(ramp) factor, key[%s] from stream[idx:%u, state:%u]",
+ sd->vol_key, i->index, i->state);
pa_sink_input_remove_volume_factor(i, sd->vol_key);
pa_sink_input_remove_volume_ramp_factor(i, sd->vol_key, true);
memset(&sd->vol_key, 0, sizeof(sd->vol_key));
}
- pa_log_info("ducking stream count[%p,%d]", sd, sd->ducking_stream_count);
+ pa_log_info("stream ducking[%p, ducking_stream_count:%d]", sd, sd->ducking_stream_count);
_ACTIVATE_DUCKING_DONE:
pa_dbus_send_basic_value_reply(conn, msg, DBUS_TYPE_STRING, &stream_manager_dbus_ret_str[ret_msg]);
}
static pa_hook_result_t sink_input_ramp_finish_cb(pa_core *core, pa_sink_input *i, pa_stream_manager *m) {
- stream_ducking *sd = NULL;
- pa_sink_input *stream = NULL;
- uint32_t idx;
+ stream_ducking *sd;
void *state;
pa_core_assert_ref(core);
* Check the number of managed streams of the context id, if it is the last one
* then broadcast a signal with context id.*/
PA_HASHMAP_FOREACH(sd, m->stream_duckings, state) {
- PA_IDXSET_FOREACH(stream, sd->idx_ducking_streams, idx) {
- if (stream == i && sd->ducking_stream_count > 0) {
- pa_log_info("found matched stream(%p, index:%u) in sd(%p)", i, i->index, sd);
- break;
- }
- }
- if (stream != i) {
+ if (!pa_idxset_get_by_data(sd->idx_ducking_streams, i, NULL)) {
pa_log_debug("not found matched stream(%p, index:%u) in sd(%p)", i, i->index, sd);
continue;
}
+ pa_log_info("found matched stream(%p, index:%u) in sd(%p, ducking_stream_count:%d, state:%u)",
+ i, i->index, sd, sd->ducking_stream_count, sd->state);
+
+ if (sd->ducking_stream_count <= 0)
+ continue;
+
/* Remove trigger when unducked */
if (sd->state == STREAM_DUCKING_STATE_UNDUCKING)
pa_idxset_remove_by_data(sd->idx_ducking_streams, (void *)i, NULL);
/* 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) {
- if (sd->state == STREAM_DUCKING_STATE_DUCKING)
+ if (--sd->ducking_stream_count == 0) {
+ if (sd->state == STREAM_DUCKING_STATE_DUCKING) {
sd->state = STREAM_DUCKING_STATE_DUCKED;
- else
+ } else if (sd->state == STREAM_DUCKING_STATE_UNDUCKING) {
sd->state = STREAM_DUCKING_STATE_UNDUCKED;
+ } else {
+ pa_log_warn("sd->state(%d), already ducked or unducked, skip sending signal", sd->state);
+ continue;
+ }
- pa_log_info("send signal for ramp finished - sd(%p, state:%d)", sd, sd->state);
-
+ pa_log_info("send signal for ramp finished - sd(%p, state:%u)", sd, sd->state);
send_ducking_state_changed_signal(pa_dbus_connection_get(m->dbus_conn), sd->trigger_index, is_stream_ducked(sd));
}
}