diff options
author | Arun Raghavan <arun@arunraghavan.net> | 2017-01-30 14:07:37 +0530 |
---|---|---|
committer | Arun Raghavan <arun@arunraghavan.net> | 2017-01-30 14:07:37 +0530 |
commit | 539371b3f722e92287f04f962160413e4efe1fa1 (patch) | |
tree | 395a42cada6071c49c608cf35a4f1ad4d88055be /src/pulsecore | |
parent | cc021c73305023a113f78190fb1b995528d003ae (diff) |
sink, source: Make rate selection more explicit
This serves to explicitly document the various cases we deal with in
pa_sink_update_rate()/pa_source_update_rate() rather than have some of
them hidden behind the initialisation of desired_rate.
Diffstat (limited to 'src/pulsecore')
-rw-r--r-- | src/pulsecore/sink.c | 25 | ||||
-rw-r--r-- | src/pulsecore/source.c | 25 |
2 files changed, 34 insertions, 16 deletions
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c index 1a968f35..6011f45b 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -1407,7 +1407,7 @@ void pa_sink_render_full(pa_sink *s, size_t length, pa_memchunk *result) { /* Called from main thread */ int pa_sink_update_rate(pa_sink *s, uint32_t rate, bool passthrough) { int ret = -1; - uint32_t desired_rate = rate; + uint32_t desired_rate; uint32_t default_rate = s->default_sample_rate; uint32_t alternate_rate = s->alternate_sample_rate; uint32_t idx; @@ -1440,21 +1440,30 @@ int pa_sink_update_rate(pa_sink *s, uint32_t rate, bool passthrough) { } } - if (PA_UNLIKELY(!pa_sample_rate_valid(desired_rate))) + if (PA_UNLIKELY(!pa_sample_rate_valid(rate))) return -1; - if (avoid_resampling && (rate >= default_rate || rate >= alternate_rate)) { + if (passthrough) { + /* We have to try to use the sink input rate */ + desired_rate = rate; + + } else if (avoid_resampling && (rate >= default_rate || rate >= alternate_rate)) { /* We just try to set the sink input's sample rate if it's not too low */ desired_rate = rate; - } else if (!passthrough && default_rate != desired_rate && alternate_rate != desired_rate) { - if (default_rate % 11025 == 0 && desired_rate % 11025 == 0) + } else if (default_rate == rate || alternate_rate == rate) { + /* We can directly try to use this rate */ + desired_rate = rate; + + } else { + /* See if we can pick a rate that results in less resampling effort */ + if (default_rate % 11025 == 0 && rate % 11025 == 0) default_rate_is_usable = true; - if (default_rate % 4000 == 0 && desired_rate % 4000 == 0) + if (default_rate % 4000 == 0 && rate % 4000 == 0) default_rate_is_usable = true; - if (alternate_rate && alternate_rate % 11025 == 0 && desired_rate % 11025 == 0) + if (alternate_rate && alternate_rate % 11025 == 0 && rate % 11025 == 0) alternate_rate_is_usable = true; - if (alternate_rate && alternate_rate % 4000 == 0 && desired_rate % 4000 == 0) + if (alternate_rate && alternate_rate % 4000 == 0 && rate % 4000 == 0) alternate_rate_is_usable = true; if (alternate_rate_is_usable && !default_rate_is_usable) diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index 72aae479..09c953f1 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -977,7 +977,7 @@ void pa_source_post_direct(pa_source*s, pa_source_output *o, const pa_memchunk * /* Called from main thread */ int pa_source_update_rate(pa_source *s, uint32_t rate, bool passthrough) { int ret; - uint32_t desired_rate = rate; + uint32_t desired_rate; uint32_t default_rate = s->default_sample_rate; uint32_t alternate_rate = s->alternate_sample_rate; bool default_rate_is_usable = false; @@ -1008,21 +1008,30 @@ int pa_source_update_rate(pa_source *s, uint32_t rate, bool passthrough) { } } - if (PA_UNLIKELY(!pa_sample_rate_valid(desired_rate))) + if (PA_UNLIKELY(!pa_sample_rate_valid(rate))) return -1; - if (avoid_resampling && (rate >= default_rate || rate >= alternate_rate)) { + if (passthrough) { + /* We have to try to use the source output rate */ + desired_rate = rate; + + } else if (avoid_resampling && (rate >= default_rate || rate >= alternate_rate)) { /* We just try to set the source output's sample rate if it's not too low */ desired_rate = rate; - } else if (!passthrough && default_rate != desired_rate && alternate_rate != desired_rate) { - if (default_rate % 11025 == 0 && desired_rate % 11025 == 0) + } else if (default_rate == rate || alternate_rate == rate) { + /* We can directly try to use this rate */ + desired_rate = rate; + + } else { + /* See if we can pick a rate that results in less resampling effort */ + if (default_rate % 11025 == 0 && rate % 11025 == 0) default_rate_is_usable = true; - if (default_rate % 4000 == 0 && desired_rate % 4000 == 0) + if (default_rate % 4000 == 0 && rate % 4000 == 0) default_rate_is_usable = true; - if (alternate_rate && alternate_rate % 11025 == 0 && desired_rate % 11025 == 0) + if (alternate_rate && alternate_rate % 11025 == 0 && rate % 11025 == 0) alternate_rate_is_usable = true; - if (alternate_rate && alternate_rate % 4000 == 0 && desired_rate % 4000 == 0) + if (alternate_rate && alternate_rate % 4000 == 0 && rate % 4000 == 0) alternate_rate_is_usable = true; if (alternate_rate_is_usable && !default_rate_is_usable) |