[pulseaudio-discuss] [PATCH 1/8] sink, source: Reduce indentation level in *_update_rate()

Tanu Kaskinen tanu.kaskinen at linux.intel.com
Thu Aug 8 23:57:52 PDT 2013


---
 src/pulsecore/sink.c   | 120 ++++++++++++++++++++++++-------------------------
 src/pulsecore/source.c | 106 +++++++++++++++++++++----------------------
 2 files changed, 113 insertions(+), 113 deletions(-)

diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 3cdabd4..2f5174e 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -1379,86 +1379,86 @@ void pa_sink_render_full(pa_sink *s, size_t length, pa_memchunk *result) {
 /* Called from main thread */
 bool pa_sink_update_rate(pa_sink *s, uint32_t rate, bool passthrough) {
     bool ret = false;
+    uint32_t desired_rate = rate;
+    uint32_t default_rate = s->default_sample_rate;
+    uint32_t alternate_rate = s->alternate_sample_rate;
+    uint32_t idx;
+    pa_sink_input *i;
+    bool use_alternate = false;
 
-    if (s->update_rate) {
-        uint32_t desired_rate = rate;
-        uint32_t default_rate = s->default_sample_rate;
-        uint32_t alternate_rate = s->alternate_sample_rate;
-        uint32_t idx;
-        pa_sink_input *i;
-        bool use_alternate = false;
+    if (!s->update_rate)
+        return false;
 
-        if (PA_UNLIKELY(default_rate == alternate_rate)) {
-            pa_log_warn("Default and alternate sample rates are the same.");
-            return false;
-        }
+    if (PA_UNLIKELY(default_rate == alternate_rate)) {
+        pa_log_warn("Default and alternate sample rates are the same.");
+        return false;
+    }
 
-        if (PA_SINK_IS_RUNNING(s->state)) {
-            pa_log_info("Cannot update rate, SINK_IS_RUNNING, will keep using %u Hz",
-                        s->sample_spec.rate);
-            return false;
-        }
+    if (PA_SINK_IS_RUNNING(s->state)) {
+        pa_log_info("Cannot update rate, SINK_IS_RUNNING, will keep using %u Hz",
+                    s->sample_spec.rate);
+        return false;
+    }
 
-        if (s->monitor_source) {
-            if (PA_SOURCE_IS_RUNNING(s->monitor_source->state) == true) {
-                pa_log_info("Cannot update rate, monitor source is RUNNING");
-                return false;
-            }
+    if (s->monitor_source) {
+        if (PA_SOURCE_IS_RUNNING(s->monitor_source->state) == true) {
+            pa_log_info("Cannot update rate, monitor source is RUNNING");
+            return false;
         }
+    }
 
-        if (PA_UNLIKELY (desired_rate < 8000 ||
-                         desired_rate > PA_RATE_MAX))
-            return false;
+    if (PA_UNLIKELY (desired_rate < 8000 ||
+                     desired_rate > PA_RATE_MAX))
+        return false;
 
-        if (!passthrough) {
-            pa_assert(default_rate % 4000 || default_rate % 11025);
-            pa_assert(alternate_rate % 4000 || alternate_rate % 11025);
-
-            if (default_rate % 4000) {
-                /* default is a 11025 multiple */
-                if ((alternate_rate % 4000 == 0) && (desired_rate % 4000 == 0))
-                    use_alternate=true;
-            } else {
-                /* default is 4000 multiple */
-                if ((alternate_rate % 11025 == 0) && (desired_rate % 11025 == 0))
-                    use_alternate=true;
-            }
+    if (!passthrough) {
+        pa_assert(default_rate % 4000 || default_rate % 11025);
+        pa_assert(alternate_rate % 4000 || alternate_rate % 11025);
 
-            if (use_alternate)
-                desired_rate = alternate_rate;
-            else
-                desired_rate = default_rate;
+        if (default_rate % 4000) {
+            /* default is a 11025 multiple */
+            if ((alternate_rate % 4000 == 0) && (desired_rate % 4000 == 0))
+                use_alternate=true;
         } else {
-            desired_rate = rate; /* use stream sampling rate, discard default/alternate settings */
+            /* default is 4000 multiple */
+            if ((alternate_rate % 11025 == 0) && (desired_rate % 11025 == 0))
+                use_alternate=true;
         }
 
-        if (desired_rate == s->sample_spec.rate)
-            return false;
+        if (use_alternate)
+            desired_rate = alternate_rate;
+        else
+            desired_rate = default_rate;
+    } else {
+        desired_rate = rate; /* use stream sampling rate, discard default/alternate settings */
+    }
 
-        if (!passthrough && pa_sink_used_by(s) > 0)
-            return false;
+    if (desired_rate == s->sample_spec.rate)
+        return false;
 
-        pa_log_debug("Suspending sink %s due to changing the sample rate.", s->name);
-        pa_sink_suspend(s, true, PA_SUSPEND_INTERNAL);
+    if (!passthrough && pa_sink_used_by(s) > 0)
+        return false;
 
-        if (s->update_rate(s, desired_rate) == true) {
-            /* update monitor source as well */
-            if (s->monitor_source && !passthrough)
-                pa_source_update_rate(s->monitor_source, desired_rate, false);
-            pa_log_info("Changed sampling rate successfully");
+    pa_log_debug("Suspending sink %s due to changing the sample rate.", s->name);
+    pa_sink_suspend(s, true, PA_SUSPEND_INTERNAL);
 
-            PA_IDXSET_FOREACH(i, s->inputs, idx) {
-                if (i->state == PA_SINK_INPUT_CORKED)
-                    pa_sink_input_update_rate(i);
-            }
+    if (s->update_rate(s, desired_rate) == true) {
+        /* update monitor source as well */
+        if (s->monitor_source && !passthrough)
+            pa_source_update_rate(s->monitor_source, desired_rate, false);
+        pa_log_info("Changed sampling rate successfully");
 
-            ret = true;
+        PA_IDXSET_FOREACH(i, s->inputs, idx) {
+            if (i->state == PA_SINK_INPUT_CORKED)
+                pa_sink_input_update_rate(i);
         }
 
-        pa_sink_suspend(s, false, PA_SUSPEND_INTERNAL);
+        ret = true;
     }
 
-    return ret ;
+    pa_sink_suspend(s, false, PA_SUSPEND_INTERNAL);
+
+    return ret;
 }
 
 /* Called from main thread */
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index 9c492c1..2c8d440 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -969,74 +969,74 @@ void pa_source_post_direct(pa_source*s, pa_source_output *o, const pa_memchunk *
 /* Called from main thread */
 bool pa_source_update_rate(pa_source *s, uint32_t rate, bool passthrough) {
     bool ret = false;
+    uint32_t desired_rate = rate;
+    uint32_t default_rate = s->default_sample_rate;
+    uint32_t alternate_rate = s->alternate_sample_rate;
+    uint32_t idx;
+    pa_source_output *o;
+    bool use_alternate = false;
 
-    if (s->update_rate) {
-        uint32_t desired_rate = rate;
-        uint32_t default_rate = s->default_sample_rate;
-        uint32_t alternate_rate = s->alternate_sample_rate;
-        uint32_t idx;
-        pa_source_output *o;
-        bool use_alternate = false;
+    if (!s->update_rate)
+        return false;
 
-        if (PA_UNLIKELY(default_rate == alternate_rate)) {
-            pa_log_warn("Default and alternate sample rates are the same.");
-            return false;
-        }
+    if (PA_UNLIKELY(default_rate == alternate_rate)) {
+        pa_log_warn("Default and alternate sample rates are the same.");
+        return false;
+    }
 
-        if (PA_SOURCE_IS_RUNNING(s->state)) {
-            pa_log_info("Cannot update rate, SOURCE_IS_RUNNING, will keep using %u Hz",
-                        s->sample_spec.rate);
-            return false;
-        }
+    if (PA_SOURCE_IS_RUNNING(s->state)) {
+        pa_log_info("Cannot update rate, SOURCE_IS_RUNNING, will keep using %u Hz",
+                    s->sample_spec.rate);
+        return false;
+    }
 
-        if (PA_UNLIKELY (desired_rate < 8000 ||
-                         desired_rate > PA_RATE_MAX))
-            return false;
-
-        if (!passthrough) {
-            pa_assert(default_rate % 4000 || default_rate % 11025);
-            pa_assert(alternate_rate % 4000 || alternate_rate % 11025);
-
-            if (default_rate % 4000) {
-                /* default is a 11025 multiple */
-                if ((alternate_rate % 4000 == 0) && (desired_rate % 4000 == 0))
-                    use_alternate=true;
-            } else {
-                /* default is 4000 multiple */
-                if ((alternate_rate % 11025 == 0) && (desired_rate % 11025 == 0))
-                    use_alternate=true;
-            }
+    if (PA_UNLIKELY (desired_rate < 8000 ||
+                     desired_rate > PA_RATE_MAX))
+        return false;
 
-            if (use_alternate)
-                desired_rate = alternate_rate;
-            else
-                desired_rate = default_rate;
+    if (!passthrough) {
+        pa_assert(default_rate % 4000 || default_rate % 11025);
+        pa_assert(alternate_rate % 4000 || alternate_rate % 11025);
+
+        if (default_rate % 4000) {
+            /* default is a 11025 multiple */
+            if ((alternate_rate % 4000 == 0) && (desired_rate % 4000 == 0))
+                use_alternate=true;
         } else {
-            desired_rate = rate; /* use stream sampling rate, discard default/alternate settings */
+            /* default is 4000 multiple */
+            if ((alternate_rate % 11025 == 0) && (desired_rate % 11025 == 0))
+                use_alternate=true;
         }
 
-        if (desired_rate == s->sample_spec.rate)
-            return false;
+        if (use_alternate)
+            desired_rate = alternate_rate;
+        else
+            desired_rate = default_rate;
+    } else {
+        desired_rate = rate; /* use stream sampling rate, discard default/alternate settings */
+    }
 
-        if (!passthrough && pa_source_used_by(s) > 0)
-            return false;
+    if (desired_rate == s->sample_spec.rate)
+        return false;
 
-        pa_log_debug("Suspending source %s due to changing the sample rate.", s->name);
-        pa_source_suspend(s, true, PA_SUSPEND_INTERNAL);
+    if (!passthrough && pa_source_used_by(s) > 0)
+        return false;
 
-        if (s->update_rate(s, desired_rate) == true) {
-            pa_log_info("Changed sampling rate successfully ");
+    pa_log_debug("Suspending source %s due to changing the sample rate.", s->name);
+    pa_source_suspend(s, true, PA_SUSPEND_INTERNAL);
 
-            PA_IDXSET_FOREACH(o, s->outputs, idx) {
-                if (o->state == PA_SOURCE_OUTPUT_CORKED)
-                    pa_source_output_update_rate(o);
-            }
-            ret = true;
-        }
+    if (s->update_rate(s, desired_rate) == true) {
+        pa_log_info("Changed sampling rate successfully ");
 
-        pa_source_suspend(s, false, PA_SUSPEND_INTERNAL);
+        PA_IDXSET_FOREACH(o, s->outputs, idx) {
+            if (o->state == PA_SOURCE_OUTPUT_CORKED)
+                pa_source_output_update_rate(o);
+        }
+        ret = true;
     }
 
+    pa_source_suspend(s, false, PA_SUSPEND_INTERNAL);
+
     return ret;
 }
 
-- 
1.8.1.2



More information about the pulseaudio-discuss mailing list