Skip to content

Commit

Permalink
Implement MIXER_FDS_OUTPUT for pulse (cmus#1139)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgaskin authored and flyingmutant committed Dec 24, 2021
1 parent 0f0db50 commit 757aa6f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Doc/cmus.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,7 @@ output_plugin [roar, pulse, alsa, arts, oss, sndio, sun, coreaudio]
pause_on_output_change (false)
Pauses playback when the audio output changes.

Supported output plugins: none.
Supported output plugins: pulse.

pl_sort () [`Sort Keys`]
Sort keys for the playlist view (3). Empty value disables sorting and
Expand Down
19 changes: 19 additions & 0 deletions op/pulse.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ static pa_sample_spec pa_ss;
static int mixer_notify_in;
static int mixer_notify_out;

static int mixer_notify_output_in;
static int mixer_notify_output_out;
static long pa_last_output_idx;

/* configuration */
static int pa_restore_volume = 1;

Expand Down Expand Up @@ -161,6 +165,13 @@ static void _pa_sink_input_info_cb(pa_context *c,
if (i) {
memcpy(&pa_vol, &i->volume, sizeof(pa_vol));
notify_via_pipe(mixer_notify_in);

if (pa_last_output_idx != i->sink) {
if (pa_last_output_idx != -1) {
notify_via_pipe(mixer_notify_output_in);
}
pa_last_output_idx = i->sink;
}
}
}

Expand Down Expand Up @@ -391,6 +402,7 @@ static int op_pulse_open(sample_format_t sf, const channel_position_t *channel_m
ret_pa_last_error();
}

pa_last_output_idx = -1;
pa_stream_set_state_callback(pa_s, _pa_stream_running_cb, NULL);

rc = pa_stream_connect_playback(pa_s,
Expand Down Expand Up @@ -500,6 +512,7 @@ static int op_pulse_mixer_init(void)
pa_cvolume_reset(&pa_vol, 2);

init_pipes(&mixer_notify_out, &mixer_notify_in);
init_pipes(&mixer_notify_output_out, &mixer_notify_output_in);

return OP_ERROR_SUCCESS;
}
Expand All @@ -509,6 +522,9 @@ static int op_pulse_mixer_exit(void)
close(mixer_notify_out);
close(mixer_notify_in);

close(mixer_notify_output_out);
close(mixer_notify_output_in);

return OP_ERROR_SUCCESS;
}

Expand All @@ -530,6 +546,9 @@ static int op_pulse_mixer_get_fds(int what, int *fds)
case MIXER_FDS_VOLUME:
fds[0] = mixer_notify_out;
return 1;
case MIXER_FDS_OUTPUT:
fds[0] = mixer_notify_output_out;
return 1;
default:
return 0;
}
Expand Down

0 comments on commit 757aa6f

Please sign in to comment.