summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Raghavan <arun.raghavan@collabora.co.uk>2011-09-27 21:52:24 +0530
committerArun Raghavan <arun.raghavan@collabora.co.uk>2011-10-08 14:59:11 +0530
commit4150c5aece541403afd7163c65b8f92f747b1fad (patch)
treeee7e09b740bd598e8a235900ed11e7911e3173d6
parent4c117b2ae1e4df8e297f2e8efc65e3865d11d85c (diff)
sink,source: Avoid unnecessary call to pa_rtclock_now()
pa_{sink,source}_volume_change_apply were being called by the ALSA I/O thread on every iteration, causing a pa_rtclock_now() call, which can sometimes be heavy. We avoid this call by making sure there actually are changes to apply before proceeding into the function. While we're at it, also dropping a redundant check on s->write_volume.
-rw-r--r--src/pulsecore/sink.c8
-rw-r--r--src/pulsecore/source.c8
2 files changed, 10 insertions, 6 deletions
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 21c67236..05b08aaf 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -3400,12 +3400,12 @@ static void pa_sink_volume_change_flush(pa_sink *s) {
/* Called from the IO thread. */
pa_bool_t pa_sink_volume_change_apply(pa_sink *s, pa_usec_t *usec_to_next) {
- pa_usec_t now = pa_rtclock_now();
+ pa_usec_t now;
pa_bool_t ret = FALSE;
pa_assert(s);
- if (!PA_SINK_IS_LINKED(s->state)) {
+ if (!s->thread_info.volume_changes || !PA_SINK_IS_LINKED(s->state)) {
if (usec_to_next)
*usec_to_next = 0;
return ret;
@@ -3413,6 +3413,8 @@ pa_bool_t pa_sink_volume_change_apply(pa_sink *s, pa_usec_t *usec_to_next) {
pa_assert(s->write_volume);
+ now = pa_rtclock_now();
+
while (s->thread_info.volume_changes && now >= s->thread_info.volume_changes->at) {
pa_sink_volume_change *c = s->thread_info.volume_changes;
PA_LLIST_REMOVE(pa_sink_volume_change, s->thread_info.volume_changes, c);
@@ -3423,7 +3425,7 @@ pa_bool_t pa_sink_volume_change_apply(pa_sink *s, pa_usec_t *usec_to_next) {
pa_sink_volume_change_free(c);
}
- if (s->write_volume && ret)
+ if (ret)
s->write_volume(s);
if (s->thread_info.volume_changes) {
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index 52396101..d47280ce 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -2575,12 +2575,12 @@ static void pa_source_volume_change_flush(pa_source *s) {
/* Called from the IO thread. */
pa_bool_t pa_source_volume_change_apply(pa_source *s, pa_usec_t *usec_to_next) {
- pa_usec_t now = pa_rtclock_now();
+ pa_usec_t now;
pa_bool_t ret = FALSE;
pa_assert(s);
- if (!PA_SOURCE_IS_LINKED(s->state)) {
+ if (!s->thread_info.volume_changes || !PA_SOURCE_IS_LINKED(s->state)) {
if (usec_to_next)
*usec_to_next = 0;
return ret;
@@ -2588,6 +2588,8 @@ pa_bool_t pa_source_volume_change_apply(pa_source *s, pa_usec_t *usec_to_next) {
pa_assert(s->write_volume);
+ now = pa_rtclock_now();
+
while (s->thread_info.volume_changes && now >= s->thread_info.volume_changes->at) {
pa_source_volume_change *c = s->thread_info.volume_changes;
PA_LLIST_REMOVE(pa_source_volume_change, s->thread_info.volume_changes, c);
@@ -2598,7 +2600,7 @@ pa_bool_t pa_source_volume_change_apply(pa_source *s, pa_usec_t *usec_to_next) {
pa_source_volume_change_free(c);
}
- if (s->write_volume && ret)
+ if (ret)
s->write_volume(s);
if (s->thread_info.volume_changes) {