1
From 6a9272f950649fdf3650e23d08320093d6ef7a64 Mon Sep 17 00:00:00 2001
2
From: Arun Raghavan <arun.raghavan@collabora.co.uk>
3
Date: Tue, 27 Sep 2011 21:52:24 +0530
4
Subject: [PATCH 101/101] sink,source: Avoid unnecessary call to
7
pa_{sink,source}_volume_change_apply were being called by the ALSA I/O
8
thread on every iteration, causing a pa_rtclock_now() call, which can
9
sometimes be heavy. We avoid this call by making sure there actually are
10
changes to apply before proceeding into the function.
12
While we're at it, also dropping a redundant check on s->write_volume.
14
src/pulsecore/sink.c | 8 +++++---
15
src/pulsecore/source.c | 8 +++++---
16
2 files changed, 10 insertions(+), 6 deletions(-)
18
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
19
index 21c6723..05b08aa 100644
20
--- a/src/pulsecore/sink.c
21
+++ b/src/pulsecore/sink.c
22
@@ -3400,12 +3400,12 @@ static void pa_sink_volume_change_flush(pa_sink *s) {
24
/* Called from the IO thread. */
25
pa_bool_t pa_sink_volume_change_apply(pa_sink *s, pa_usec_t *usec_to_next) {
26
- pa_usec_t now = pa_rtclock_now();
28
pa_bool_t ret = FALSE;
32
- if (!PA_SINK_IS_LINKED(s->state)) {
33
+ if (!s->thread_info.volume_changes || !PA_SINK_IS_LINKED(s->state)) {
37
@@ -3413,6 +3413,8 @@ pa_bool_t pa_sink_volume_change_apply(pa_sink *s, pa_usec_t *usec_to_next) {
39
pa_assert(s->write_volume);
41
+ now = pa_rtclock_now();
43
while (s->thread_info.volume_changes && now >= s->thread_info.volume_changes->at) {
44
pa_sink_volume_change *c = s->thread_info.volume_changes;
45
PA_LLIST_REMOVE(pa_sink_volume_change, s->thread_info.volume_changes, c);
46
@@ -3423,7 +3425,7 @@ pa_bool_t pa_sink_volume_change_apply(pa_sink *s, pa_usec_t *usec_to_next) {
47
pa_sink_volume_change_free(c);
50
- if (s->write_volume && ret)
54
if (s->thread_info.volume_changes) {
55
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
56
index 5239610..d47280c 100644
57
--- a/src/pulsecore/source.c
58
+++ b/src/pulsecore/source.c
59
@@ -2575,12 +2575,12 @@ static void pa_source_volume_change_flush(pa_source *s) {
61
/* Called from the IO thread. */
62
pa_bool_t pa_source_volume_change_apply(pa_source *s, pa_usec_t *usec_to_next) {
63
- pa_usec_t now = pa_rtclock_now();
65
pa_bool_t ret = FALSE;
69
- if (!PA_SOURCE_IS_LINKED(s->state)) {
70
+ if (!s->thread_info.volume_changes || !PA_SOURCE_IS_LINKED(s->state)) {
74
@@ -2588,6 +2588,8 @@ pa_bool_t pa_source_volume_change_apply(pa_source *s, pa_usec_t *usec_to_next) {
76
pa_assert(s->write_volume);
78
+ now = pa_rtclock_now();
80
while (s->thread_info.volume_changes && now >= s->thread_info.volume_changes->at) {
81
pa_source_volume_change *c = s->thread_info.volume_changes;
82
PA_LLIST_REMOVE(pa_source_volume_change, s->thread_info.volume_changes, c);
83
@@ -2598,7 +2600,7 @@ pa_bool_t pa_source_volume_change_apply(pa_source *s, pa_usec_t *usec_to_next) {
84
pa_source_volume_change_free(c);
87
- if (s->write_volume && ret)
91
if (s->thread_info.volume_changes) {