mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-05 13:29:57 -05:00
replace sink/source SET_STATE handlers with callbacks
There are no behaviour changes, the code from almost all the SET_STATE handlers is moved with minimal changes to the newly introduced set_state_in_io_thread() callback. The only exception is module-tunnel, which has to call pa_sink_render() after pa_sink.thread_info.state has been updated. The set_state_in_io_thread() callback is called before updating that variable, so moving the SET_STATE handler code to the callback isn't possible. The purpose of this change is to make it easier to get state change handling right in modules. Hooking to the SET_STATE messages in modules required care in calling pa_sink/source_process_msg() at the right time (or not calling it at all, as was the case on resume failures), and there were a few bugs (fixed before this patch). Now the core takes care of ordering things correctly. Another motivation for this change is that there was some talk about adding a suspend_cause variable to pa_sink/source.thread_info. The variable would be updated in the core SET_STATE handler, but that would not work with the old design, because in case of resume failures modules didn't call the core message handler.
This commit is contained in:
parent
73b8a57078
commit
b2537a8f38
25 changed files with 874 additions and 658 deletions
|
|
@ -429,30 +429,39 @@ static int sink_process_msg_cb(pa_msgobject *o, int code, void *data, int64_t of
|
|||
*((int64_t*) data) = remote_latency;
|
||||
return 0;
|
||||
}
|
||||
case PA_SINK_MESSAGE_SET_STATE:
|
||||
if (!u->stream || pa_stream_get_state(u->stream) != PA_STREAM_READY)
|
||||
break;
|
||||
|
||||
switch ((pa_sink_state_t) PA_PTR_TO_UINT(data)) {
|
||||
case PA_SINK_SUSPENDED: {
|
||||
cork_stream(u, true);
|
||||
break;
|
||||
}
|
||||
case PA_SINK_IDLE:
|
||||
case PA_SINK_RUNNING: {
|
||||
cork_stream(u, false);
|
||||
break;
|
||||
}
|
||||
case PA_SINK_INVALID_STATE:
|
||||
case PA_SINK_INIT:
|
||||
case PA_SINK_UNLINKED:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return pa_sink_process_msg(o, code, data, offset, chunk);
|
||||
}
|
||||
|
||||
/* Called from the IO thread. */
|
||||
static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state) {
|
||||
struct userdata *u;
|
||||
|
||||
pa_assert(s);
|
||||
pa_assert_se(u = s->userdata);
|
||||
|
||||
if (!u->stream || pa_stream_get_state(u->stream) != PA_STREAM_READY)
|
||||
return 0;
|
||||
|
||||
switch (new_state) {
|
||||
case PA_SINK_SUSPENDED: {
|
||||
cork_stream(u, true);
|
||||
break;
|
||||
}
|
||||
case PA_SINK_IDLE:
|
||||
case PA_SINK_RUNNING: {
|
||||
cork_stream(u, false);
|
||||
break;
|
||||
}
|
||||
case PA_SINK_INVALID_STATE:
|
||||
case PA_SINK_INIT:
|
||||
case PA_SINK_UNLINKED:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pa__init(pa_module *m) {
|
||||
struct userdata *u = NULL;
|
||||
pa_modargs *ma = NULL;
|
||||
|
|
@ -545,6 +554,7 @@ int pa__init(pa_module *m) {
|
|||
pa_sink_new_data_done(&sink_data);
|
||||
u->sink->userdata = u;
|
||||
u->sink->parent.process_msg = sink_process_msg_cb;
|
||||
u->sink->set_state_in_io_thread = sink_set_state_in_io_thread_cb;
|
||||
u->sink->update_requested_latency = sink_update_requested_latency_cb;
|
||||
pa_sink_set_latency_range(u->sink, 0, MAX_LATENCY_USEC);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue