optimize set_state_in_io_thread() callbacks

Source and sink are passed in arguments to set_state_in_io_thread()
callbacks. There is optimal to access them directly.
This commit is contained in:
Raman Shyshniou 2018-03-20 16:26:20 +03:00 committed by Arun Raghavan
parent de705a0eea
commit 556cdfa190
16 changed files with 41 additions and 41 deletions

View file

@ -1291,7 +1291,7 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
switch (new_state) { switch (new_state) {
case PA_SINK_SUSPENDED: { case PA_SINK_SUSPENDED: {
pa_assert(PA_SINK_IS_OPENED(u->sink->thread_info.state)); pa_assert(PA_SINK_IS_OPENED(s->thread_info.state));
suspend(u); suspend(u);
@ -1302,7 +1302,7 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
case PA_SINK_RUNNING: { case PA_SINK_RUNNING: {
int r; int r;
if (u->sink->thread_info.state == PA_SINK_INIT) { if (s->thread_info.state == PA_SINK_INIT) {
if (build_pollfd(u) < 0) if (build_pollfd(u) < 0)
/* FIXME: This will cause an assertion failure, because /* FIXME: This will cause an assertion failure, because
* with the current design pa_sink_put() is not allowed * with the current design pa_sink_put() is not allowed
@ -1312,7 +1312,7 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
return -PA_ERR_IO; return -PA_ERR_IO;
} }
if (u->sink->thread_info.state == PA_SINK_SUSPENDED) { if (s->thread_info.state == PA_SINK_SUSPENDED) {
if ((r = unsuspend(u)) < 0) if ((r = unsuspend(u)) < 0)
return r; return r;
} }

View file

@ -1146,7 +1146,7 @@ static int source_set_state_in_io_thread_cb(pa_source *s, pa_source_state_t new_
switch (new_state) { switch (new_state) {
case PA_SOURCE_SUSPENDED: { case PA_SOURCE_SUSPENDED: {
pa_assert(PA_SOURCE_IS_OPENED(u->source->thread_info.state)); pa_assert(PA_SOURCE_IS_OPENED(s->thread_info.state));
suspend(u); suspend(u);
@ -1157,7 +1157,7 @@ static int source_set_state_in_io_thread_cb(pa_source *s, pa_source_state_t new_
case PA_SOURCE_RUNNING: { case PA_SOURCE_RUNNING: {
int r; int r;
if (u->source->thread_info.state == PA_SOURCE_INIT) { if (s->thread_info.state == PA_SOURCE_INIT) {
if (build_pollfd(u) < 0) if (build_pollfd(u) < 0)
/* FIXME: This will cause an assertion failure, because /* FIXME: This will cause an assertion failure, because
* with the current design pa_source_put() is not allowed * with the current design pa_source_put() is not allowed
@ -1167,7 +1167,7 @@ static int source_set_state_in_io_thread_cb(pa_source *s, pa_source_state_t new_
return -PA_ERR_IO; return -PA_ERR_IO;
} }
if (u->source->thread_info.state == PA_SOURCE_SUSPENDED) { if (s->thread_info.state == PA_SOURCE_SUSPENDED) {
if ((r = unsuspend(u)) < 0) if ((r = unsuspend(u)) < 0)
return r; return r;
} }

View file

@ -423,7 +423,7 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
case PA_SINK_SUSPENDED: case PA_SINK_SUSPENDED:
/* Ignore if transition is PA_SINK_INIT->PA_SINK_SUSPENDED */ /* Ignore if transition is PA_SINK_INIT->PA_SINK_SUSPENDED */
if (!PA_SINK_IS_OPENED(u->sink->thread_info.state)) if (!PA_SINK_IS_OPENED(s->thread_info.state))
break; break;
/* Stop the device if the source is suspended as well */ /* Stop the device if the source is suspended as well */
@ -437,7 +437,7 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
case PA_SINK_IDLE: case PA_SINK_IDLE:
case PA_SINK_RUNNING: case PA_SINK_RUNNING:
if (u->sink->thread_info.state != PA_SINK_SUSPENDED) if (s->thread_info.state != PA_SINK_SUSPENDED)
break; break;
/* Resume the device if the source was suspended as well */ /* Resume the device if the source was suspended as well */
@ -497,7 +497,7 @@ static int source_set_state_in_io_thread_cb(pa_source *s, pa_source_state_t new_
case PA_SOURCE_SUSPENDED: case PA_SOURCE_SUSPENDED:
/* Ignore if transition is PA_SOURCE_INIT->PA_SOURCE_SUSPENDED */ /* Ignore if transition is PA_SOURCE_INIT->PA_SOURCE_SUSPENDED */
if (!PA_SOURCE_IS_OPENED(u->source->thread_info.state)) if (!PA_SOURCE_IS_OPENED(s->thread_info.state))
break; break;
/* Stop the device if the sink is suspended as well */ /* Stop the device if the sink is suspended as well */
@ -510,7 +510,7 @@ static int source_set_state_in_io_thread_cb(pa_source *s, pa_source_state_t new_
case PA_SOURCE_IDLE: case PA_SOURCE_IDLE:
case PA_SOURCE_RUNNING: case PA_SOURCE_RUNNING:
if (u->source->thread_info.state != PA_SOURCE_SUSPENDED) if (s->thread_info.state != PA_SOURCE_SUSPENDED)
break; break;
/* Resume the device if the sink was suspended as well */ /* Resume the device if the sink was suspended as well */

View file

@ -980,7 +980,7 @@ static int source_set_state_in_io_thread_cb(pa_source *s, pa_source_state_t new_
case PA_SOURCE_SUSPENDED: case PA_SOURCE_SUSPENDED:
/* Ignore if transition is PA_SOURCE_INIT->PA_SOURCE_SUSPENDED */ /* Ignore if transition is PA_SOURCE_INIT->PA_SOURCE_SUSPENDED */
if (!PA_SOURCE_IS_OPENED(u->source->thread_info.state)) if (!PA_SOURCE_IS_OPENED(s->thread_info.state))
break; break;
/* Stop the device if the sink is suspended as well */ /* Stop the device if the sink is suspended as well */
@ -994,7 +994,7 @@ static int source_set_state_in_io_thread_cb(pa_source *s, pa_source_state_t new_
case PA_SOURCE_IDLE: case PA_SOURCE_IDLE:
case PA_SOURCE_RUNNING: case PA_SOURCE_RUNNING:
if (u->source->thread_info.state != PA_SOURCE_SUSPENDED) if (s->thread_info.state != PA_SOURCE_SUSPENDED)
break; break;
/* Resume the device if the sink was suspended as well */ /* Resume the device if the sink was suspended as well */
@ -1157,7 +1157,7 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
case PA_SINK_SUSPENDED: case PA_SINK_SUSPENDED:
/* Ignore if transition is PA_SINK_INIT->PA_SINK_SUSPENDED */ /* Ignore if transition is PA_SINK_INIT->PA_SINK_SUSPENDED */
if (!PA_SINK_IS_OPENED(u->sink->thread_info.state)) if (!PA_SINK_IS_OPENED(s->thread_info.state))
break; break;
/* Stop the device if the source is suspended as well */ /* Stop the device if the source is suspended as well */
@ -1171,7 +1171,7 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
case PA_SINK_IDLE: case PA_SINK_IDLE:
case PA_SINK_RUNNING: case PA_SINK_RUNNING:
if (u->sink->thread_info.state != PA_SINK_SUSPENDED) if (s->thread_info.state != PA_SINK_SUSPENDED)
break; break;
/* Resume the device if the source was suspended as well */ /* Resume the device if the source was suspended as well */

View file

@ -522,7 +522,7 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
/* When set to running or idle for the first time, request a rewind /* When set to running or idle for the first time, request a rewind
* of the master sink to make sure we are heard immediately */ * of the master sink to make sure we are heard immediately */
if ((new_state == PA_SINK_IDLE || new_state == PA_SINK_RUNNING) && u->sink->thread_info.state == PA_SINK_INIT) { if (PA_SINK_IS_OPENED(new_state) && s->thread_info.state == PA_SINK_INIT) {
pa_log_debug("Requesting rewind due to state change."); pa_log_debug("Requesting rewind due to state change.");
pa_sink_input_request_rewind(u->sink_input, 0, false, true, true); pa_sink_input_request_rewind(u->sink_input, 0, false, true, true);
} }

View file

@ -296,7 +296,7 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
/* When set to running or idle for the first time, request a rewind /* When set to running or idle for the first time, request a rewind
* of the master sink to make sure we are heard immediately */ * of the master sink to make sure we are heard immediately */
if ((new_state == PA_SINK_IDLE || new_state == PA_SINK_RUNNING) && u->sink->thread_info.state == PA_SINK_INIT) { if (PA_SINK_IS_OPENED(new_state) && s->thread_info.state == PA_SINK_INIT) {
pa_log_debug("Requesting rewind due to state change."); pa_log_debug("Requesting rewind due to state change.");
pa_sink_input_request_rewind(u->sink_input, 0, false, true, true); pa_sink_input_request_rewind(u->sink_input, 0, false, true, true);
} }

View file

@ -183,7 +183,7 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
switch (new_state) { switch (new_state) {
case PA_SINK_SUSPENDED: case PA_SINK_SUSPENDED:
pa_assert(PA_SINK_IS_OPENED(u->sink->thread_info.state)); pa_assert(PA_SINK_IS_OPENED(s->thread_info.state));
pa_smoother_pause(u->smoother, pa_rtclock_now()); pa_smoother_pause(u->smoother, pa_rtclock_now());
break; break;
@ -191,7 +191,7 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
case PA_SINK_IDLE: case PA_SINK_IDLE:
case PA_SINK_RUNNING: case PA_SINK_RUNNING:
if (u->sink->thread_info.state == PA_SINK_SUSPENDED) if (s->thread_info.state == PA_SINK_SUSPENDED)
pa_smoother_resume(u->smoother, pa_rtclock_now(), true); pa_smoother_resume(u->smoother, pa_rtclock_now(), true);
break; break;

View file

@ -403,7 +403,7 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
/* When set to running or idle for the first time, request a rewind /* When set to running or idle for the first time, request a rewind
* of the master sink to make sure we are heard immediately */ * of the master sink to make sure we are heard immediately */
if ((new_state == PA_SINK_IDLE || new_state == PA_SINK_RUNNING) && u->sink->thread_info.state == PA_SINK_INIT) { if (PA_SINK_IS_OPENED(new_state) && s->thread_info.state == PA_SINK_INIT) {
pa_log_debug("Requesting rewind due to state change."); pa_log_debug("Requesting rewind due to state change.");
pa_sink_input_request_rewind(u->sink_input, 0, false, true, true); pa_sink_input_request_rewind(u->sink_input, 0, false, true, true);
} }

View file

@ -109,7 +109,7 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
pa_assert(s); pa_assert(s);
pa_assert_se(u = s->userdata); pa_assert_se(u = s->userdata);
if (u->sink->thread_info.state == PA_SINK_SUSPENDED || u->sink->thread_info.state == PA_SINK_INIT) { if (s->thread_info.state == PA_SINK_SUSPENDED || s->thread_info.state == PA_SINK_INIT) {
if (PA_SINK_IS_OPENED(new_state)) if (PA_SINK_IS_OPENED(new_state))
u->timestamp = pa_rtclock_now(); u->timestamp = pa_rtclock_now();
} }

View file

@ -142,10 +142,10 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
pa_assert(s); pa_assert(s);
pa_assert_se(u = s->userdata); pa_assert_se(u = s->userdata);
if (u->sink->thread_info.state == PA_SINK_SUSPENDED || u->sink->thread_info.state == PA_SINK_INIT) { if (s->thread_info.state == PA_SINK_SUSPENDED || s->thread_info.state == PA_SINK_INIT) {
if (PA_SINK_IS_OPENED(new_state)) if (PA_SINK_IS_OPENED(new_state))
u->timestamp = pa_rtclock_now(); u->timestamp = pa_rtclock_now();
} else if (u->sink->thread_info.state == PA_SINK_RUNNING || u->sink->thread_info.state == PA_SINK_IDLE) { } else if (PA_SINK_IS_OPENED(s->thread_info.state)) {
if (new_state == PA_SINK_SUSPENDED) { if (new_state == PA_SINK_SUSPENDED) {
/* Clear potential FIFO error flag */ /* Clear potential FIFO error flag */
u->fifo_error = false; u->fifo_error = false;

View file

@ -123,7 +123,7 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
/* When set to running or idle for the first time, request a rewind /* When set to running or idle for the first time, request a rewind
* of the master sink to make sure we are heard immediately */ * of the master sink to make sure we are heard immediately */
if ((new_state == PA_SINK_IDLE || new_state == PA_SINK_RUNNING) && u->sink->thread_info.state == PA_SINK_INIT) { if (PA_SINK_IS_OPENED(new_state) && s->thread_info.state == PA_SINK_INIT) {
pa_log_debug("Requesting rewind due to state change."); pa_log_debug("Requesting rewind due to state change.");
pa_sink_input_request_rewind(u->sink_input, 0, false, true, true); pa_sink_input_request_rewind(u->sink_input, 0, false, true, true);
} }

View file

@ -411,7 +411,7 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
case PA_SINK_SUSPENDED: case PA_SINK_SUSPENDED:
pa_assert(PA_SINK_IS_OPENED(u->sink->thread_info.state)); pa_assert(PA_SINK_IS_OPENED(s->thread_info.state));
pa_smoother_pause(u->smoother, pa_rtclock_now()); pa_smoother_pause(u->smoother, pa_rtclock_now());
@ -424,16 +424,16 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
case PA_SINK_IDLE: case PA_SINK_IDLE:
case PA_SINK_RUNNING: case PA_SINK_RUNNING:
if (u->sink->thread_info.state == PA_SINK_SUSPENDED) { if (s->thread_info.state == PA_SINK_SUSPENDED) {
pa_smoother_resume(u->smoother, pa_rtclock_now(), true); pa_smoother_resume(u->smoother, pa_rtclock_now(), true);
if (!u->source || u->source_suspended) { if (!u->source || u->source_suspended) {
bool mute; bool mute;
if (unsuspend(u) < 0) if (unsuspend(u) < 0)
return -1; return -1;
u->sink->get_volume(u->sink); s->get_volume(s);
if (u->sink->get_mute(u->sink, &mute) >= 0) if (s->get_mute(s, &mute) >= 0)
pa_sink_set_mute(u->sink, mute, false); pa_sink_set_mute(s, mute, false);
} }
u->sink_suspended = false; u->sink_suspended = false;
} }
@ -477,7 +477,7 @@ static int source_set_state_in_io_thread_cb(pa_source *s, pa_source_state_t new_
case PA_SOURCE_SUSPENDED: case PA_SOURCE_SUSPENDED:
pa_assert(PA_SOURCE_IS_OPENED(u->source->thread_info.state)); pa_assert(PA_SOURCE_IS_OPENED(s->thread_info.state));
if (!u->sink || u->sink_suspended) if (!u->sink || u->sink_suspended)
suspend(u); suspend(u);
@ -488,11 +488,11 @@ static int source_set_state_in_io_thread_cb(pa_source *s, pa_source_state_t new_
case PA_SOURCE_IDLE: case PA_SOURCE_IDLE:
case PA_SOURCE_RUNNING: case PA_SOURCE_RUNNING:
if (u->source->thread_info.state == PA_SOURCE_SUSPENDED) { if (s->thread_info.state == PA_SOURCE_SUSPENDED) {
if (!u->sink || u->sink_suspended) { if (!u->sink || u->sink_suspended) {
if (unsuspend(u) < 0) if (unsuspend(u) < 0)
return -1; return -1;
u->source->get_volume(u->source); s->get_volume(s);
} }
u->source_suspended = false; u->source_suspended = false;
} }

View file

@ -135,7 +135,7 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
/* When set to running or idle for the first time, request a rewind /* When set to running or idle for the first time, request a rewind
* of the master sink to make sure we are heard immediately */ * of the master sink to make sure we are heard immediately */
if ((new_state == PA_SINK_IDLE || new_state == PA_SINK_RUNNING) && u->sink->thread_info.state == PA_SINK_INIT) { if (PA_SINK_IS_OPENED(new_state) && s->thread_info.state == PA_SINK_INIT) {
pa_log_debug("Requesting rewind due to state change."); pa_log_debug("Requesting rewind due to state change.");
pa_sink_input_request_rewind(u->sink_input, 0, false, true, true); pa_sink_input_request_rewind(u->sink_input, 0, false, true, true);
} }

View file

@ -163,7 +163,7 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
/* When set to running or idle for the first time, request a rewind /* When set to running or idle for the first time, request a rewind
* of the master sink to make sure we are heard immediately */ * of the master sink to make sure we are heard immediately */
if ((new_state == PA_SINK_IDLE || new_state == PA_SINK_RUNNING) && u->sink->thread_info.state == PA_SINK_INIT) { if (PA_SINK_IS_OPENED(new_state) && s->thread_info.state == PA_SINK_INIT) {
pa_log_debug("Requesting rewind due to state change."); pa_log_debug("Requesting rewind due to state change.");
pa_sink_input_request_rewind(u->sink_input, 0, false, true, true); pa_sink_input_request_rewind(u->sink_input, 0, false, true, true);
} }

View file

@ -682,7 +682,7 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
switch (new_state) { switch (new_state) {
case PA_SINK_SUSPENDED: case PA_SINK_SUSPENDED:
pa_assert(PA_SINK_IS_OPENED(u->sink->thread_info.state)); pa_assert(PA_SINK_IS_OPENED(s->thread_info.state));
if (!u->source || u->source_suspended) if (!u->source || u->source_suspended)
suspend(u); suspend(u);
@ -695,12 +695,12 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
case PA_SINK_IDLE: case PA_SINK_IDLE:
case PA_SINK_RUNNING: case PA_SINK_RUNNING:
if (u->sink->thread_info.state == PA_SINK_INIT) { if (s->thread_info.state == PA_SINK_INIT) {
do_trigger = true; do_trigger = true;
quick = u->source && PA_SOURCE_IS_OPENED(u->source->thread_info.state); quick = u->source && PA_SOURCE_IS_OPENED(u->source->thread_info.state);
} }
if (u->sink->thread_info.state == PA_SINK_SUSPENDED) { if (s->thread_info.state == PA_SINK_SUSPENDED) {
if (!u->source || u->source_suspended) { if (!u->source || u->source_suspended) {
if (unsuspend(u) < 0) if (unsuspend(u) < 0)
@ -770,7 +770,7 @@ static int source_set_state_in_io_thread_cb(pa_source *s, pa_source_state_t new_
switch (new_state) { switch (new_state) {
case PA_SOURCE_SUSPENDED: case PA_SOURCE_SUSPENDED:
pa_assert(PA_SOURCE_IS_OPENED(u->source->thread_info.state)); pa_assert(PA_SOURCE_IS_OPENED(s->thread_info.state));
if (!u->sink || u->sink_suspended) if (!u->sink || u->sink_suspended)
suspend(u); suspend(u);
@ -783,12 +783,12 @@ static int source_set_state_in_io_thread_cb(pa_source *s, pa_source_state_t new_
case PA_SOURCE_IDLE: case PA_SOURCE_IDLE:
case PA_SOURCE_RUNNING: case PA_SOURCE_RUNNING:
if (u->source->thread_info.state == PA_SOURCE_INIT) { if (s->thread_info.state == PA_SOURCE_INIT) {
do_trigger = true; do_trigger = true;
quick = u->sink && PA_SINK_IS_OPENED(u->sink->thread_info.state); quick = u->sink && PA_SINK_IS_OPENED(u->sink->thread_info.state);
} }
if (u->source->thread_info.state == PA_SOURCE_SUSPENDED) { if (s->thread_info.state == PA_SOURCE_SUSPENDED) {
if (!u->sink || u->sink_suspended) { if (!u->sink || u->sink_suspended) {
if (unsuspend(u) < 0) if (unsuspend(u) < 0)

View file

@ -236,7 +236,7 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
case PA_SINK_SUSPENDED: case PA_SINK_SUSPENDED:
pa_log_debug("RAOP: SUSPENDED"); pa_log_debug("RAOP: SUSPENDED");
pa_assert(PA_SINK_IS_OPENED(u->sink->thread_info.state)); pa_assert(PA_SINK_IS_OPENED(s->thread_info.state));
/* Issue a TEARDOWN if we are still connected */ /* Issue a TEARDOWN if we are still connected */
if (pa_raop_client_is_alive(u->raop)) { if (pa_raop_client_is_alive(u->raop)) {
@ -249,7 +249,7 @@ static int sink_set_state_in_io_thread_cb(pa_sink *s, pa_sink_state_t new_state,
pa_log_debug("RAOP: IDLE"); pa_log_debug("RAOP: IDLE");
/* Issue a FLUSH if we're comming from running state */ /* Issue a FLUSH if we're comming from running state */
if (u->sink->thread_info.state == PA_SINK_RUNNING) { if (s->thread_info.state == PA_SINK_RUNNING) {
pa_rtpoll_set_timer_disabled(u->rtpoll); pa_rtpoll_set_timer_disabled(u->rtpoll);
pa_raop_client_flush(u->raop); pa_raop_client_flush(u->raop);
} }