[pulseaudio-commits] Branch 'next' - 2 commits - src/modules src/pulsecore

Tanu Kaskinen tanuk at kemper.freedesktop.org
Thu May 31 13:07:19 UTC 2018


 src/modules/alsa/alsa-sink.c        |   22 +++++++++++++++++++---
 src/modules/alsa/alsa-source.c      |   21 ++++++++++++++++++---
 src/modules/alsa/module-alsa-card.c |    2 ++
 src/modules/module-udev-detect.c    |   17 +++++++++++++++--
 src/pulsecore/sink.c                |   13 +++++--------
 src/pulsecore/sink.h                |    2 ++
 src/pulsecore/source.c              |   13 +++++--------
 src/pulsecore/source.h              |    2 ++
 8 files changed, 68 insertions(+), 24 deletions(-)

New commits:
commit 8bd91939aca270268319833b9b6cb0701e41f69b
Author: Sangchul Lee <sangchul1011 at gmail.com>
Date:   Fri May 25 01:29:53 2018 +0900

    udev-detect, alsa-card: Adopt avoid resampling option from daemon.conf
    
    Previously, the "avoid-resampling" option of daemon.conf is to make the
    daemon try to use the stream sample rate if possible for all sinks or
    sources.
    
    This patch applies this option to module-udev-detect and module-alsa-card
    as a module argument in order to override the default value of daemon.conf.
    
    As a result, user can use this argument for more fine-grained control.
    e.g.) set it false in daemon.conf and set it true for module-udev-detect
    or a particular module-alsa-card in default.pa.(or vice versa)
    
    To set it, use "avoid_resampling=true or false" as the module argument.
    
    Signed-off-by: Sangchul Lee <sc11.lee at samsung.com>

diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index 4cc4b0e3..4c6aaad5 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -2101,7 +2101,16 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
     uint32_t nfrags, frag_size, buffer_size, tsched_size, tsched_watermark, rewind_safeguard;
     snd_pcm_uframes_t period_frames, buffer_frames, tsched_frames;
     size_t frame_size;
-    bool use_mmap = true, b, use_tsched = true, d, ignore_dB = false, namereg_fail = false, deferred_volume = false, set_formats = false, fixed_latency_range = false;
+    bool use_mmap = true;
+    bool use_tsched = true;
+    bool ignore_dB = false;
+    bool namereg_fail = false;
+    bool deferred_volume = false;
+    bool set_formats = false;
+    bool fixed_latency_range = false;
+    bool b;
+    bool d;
+    bool avoid_resampling;
     pa_sink_new_data data;
     bool volume_is_set;
     bool mute_is_set;
@@ -2113,6 +2122,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
 
     ss = m->core->default_sample_spec;
     map = m->core->default_channel_map;
+    avoid_resampling = m->core->avoid_resampling;
 
     /* Pick sample spec overrides from the mapping, if any */
     if (mapping) {
@@ -2369,6 +2379,13 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
     }
     data.namereg_fail = namereg_fail;
 
+    if (pa_modargs_get_value_boolean(ma, "avoid_resampling", &avoid_resampling) < 0) {
+        pa_log("Failed to parse avoid_resampling argument.");
+        pa_sink_new_data_done(&data);
+        goto fail;
+    }
+    data.avoid_resampling = avoid_resampling;
+
     pa_sink_new_data_set_sample_spec(&data, &ss);
     pa_sink_new_data_set_channel_map(&data, &map);
     pa_sink_new_data_set_alternate_sample_rate(&data, alternate_sample_rate);
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
index 2bb42f0b..fd457af1 100644
--- a/src/modules/alsa/alsa-source.c
+++ b/src/modules/alsa/alsa-source.c
@@ -1795,7 +1795,15 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
     uint32_t nfrags, frag_size, buffer_size, tsched_size, tsched_watermark;
     snd_pcm_uframes_t period_frames, buffer_frames, tsched_frames;
     size_t frame_size;
-    bool use_mmap = true, b, use_tsched = true, d, ignore_dB = false, namereg_fail = false, deferred_volume = false, fixed_latency_range = false;
+    bool use_mmap = true;
+    bool use_tsched = true;
+    bool ignore_dB = false;
+    bool namereg_fail = false;
+    bool deferred_volume = false;
+    bool fixed_latency_range = false;
+    bool b;
+    bool d;
+    bool avoid_resampling;
     pa_source_new_data data;
     bool volume_is_set;
     bool mute_is_set;
@@ -1807,6 +1815,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
 
     ss = m->core->default_sample_spec;
     map = m->core->default_channel_map;
+    avoid_resampling = m->core->avoid_resampling;
 
     /* Pick sample spec overrides from the mapping, if any */
     if (mapping) {
@@ -2046,6 +2055,13 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
     }
     data.namereg_fail = namereg_fail;
 
+    if (pa_modargs_get_value_boolean(ma, "avoid_resampling", &avoid_resampling) < 0) {
+        pa_log("Failed to parse avoid_resampling argument.");
+        pa_source_new_data_done(&data);
+        goto fail;
+    }
+    data.avoid_resampling = avoid_resampling;
+
     pa_source_new_data_set_sample_spec(&data, &ss);
     pa_source_new_data_set_channel_map(&data, &map);
     pa_source_new_data_set_alternate_sample_rate(&data, alternate_sample_rate);
diff --git a/src/modules/alsa/module-alsa-card.c b/src/modules/alsa/module-alsa-card.c
index 385d61d2..6840e88d 100644
--- a/src/modules/alsa/module-alsa-card.c
+++ b/src/modules/alsa/module-alsa-card.c
@@ -68,6 +68,7 @@ PA_MODULE_USAGE(
         "profile_set=<profile set configuration file> "
         "paths_dir=<directory containing the path configuration files> "
         "use_ucm=<load use case manager> "
+        "avoid_resampling=<use stream original sample rate if possible?> "
 );
 
 static const char* const valid_modargs[] = {
@@ -95,6 +96,7 @@ static const char* const valid_modargs[] = {
     "profile_set",
     "paths_dir",
     "use_ucm",
+    "avoid_resampling",
     NULL
 };
 
diff --git a/src/modules/module-udev-detect.c b/src/modules/module-udev-detect.c
index beac9d42..d119f96a 100644
--- a/src/modules/module-udev-detect.c
+++ b/src/modules/module-udev-detect.c
@@ -46,7 +46,8 @@ PA_MODULE_USAGE(
         "fixed_latency_range=<disable latency range changes on underrun?> "
         "ignore_dB=<ignore dB information from the device?> "
         "deferred_volume=<syncronize sw and hw volume changes in IO-thread?> "
-        "use_ucm=<use ALSA UCM for card configuration?>");
+        "use_ucm=<use ALSA UCM for card configuration?> "
+        "avoid_resampling=<use stream original sample rate if possible?>");
 
 struct device {
     char *path;
@@ -67,6 +68,7 @@ struct userdata {
     bool ignore_dB:1;
     bool deferred_volume:1;
     bool use_ucm:1;
+    bool avoid_resampling:1;
 
     uint32_t tsched_buffer_size;
 
@@ -85,6 +87,7 @@ static const char* const valid_modargs[] = {
     "ignore_dB",
     "deferred_volume",
     "use_ucm",
+    "avoid_resampling",
     NULL
 };
 
@@ -401,6 +404,7 @@ static void card_changed(struct userdata *u, struct udev_device *dev) {
                      "ignore_dB=%s "
                      "deferred_volume=%s "
                      "use_ucm=%s "
+                     "avoid_resampling=%s "
                      "card_properties=\"module-udev-detect.discovered=1\"",
                      path_get_card_id(path),
                      n,
@@ -409,7 +413,8 @@ static void card_changed(struct userdata *u, struct udev_device *dev) {
                      pa_yes_no(u->fixed_latency_range),
                      pa_yes_no(u->ignore_dB),
                      pa_yes_no(u->deferred_volume),
-                     pa_yes_no(u->use_ucm));
+                     pa_yes_no(u->use_ucm),
+                     pa_yes_no(u->avoid_resampling));
     pa_xfree(n);
 
     if (u->tsched_buffer_size_valid)
@@ -682,6 +687,7 @@ int pa__init(pa_module *m) {
     int fd;
     bool use_tsched = true, fixed_latency_range = false, ignore_dB = false, deferred_volume = m->core->deferred_volume;
     bool use_ucm = true;
+    bool avoid_resampling;
 
     pa_assert(m);
 
@@ -734,6 +740,13 @@ int pa__init(pa_module *m) {
     }
     u->use_ucm = use_ucm;
 
+    avoid_resampling = m->core->avoid_resampling;
+    if (pa_modargs_get_value_boolean(ma, "avoid_resampling", &avoid_resampling) < 0) {
+        pa_log("Failed to parse avoid_resampling= argument.");
+        goto fail;
+    }
+    u->avoid_resampling = avoid_resampling;
+
     if (!(u->udev = udev_new())) {
         pa_log("Failed to initialize udev library.");
         goto fail;
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 38e8e50d..d617d27f 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -271,6 +271,8 @@ pa_sink* pa_sink_new(
     else
         s->alternate_sample_rate = s->core->alternate_sample_rate;
 
+    s->avoid_resampling = data->avoid_resampling;
+
     s->inputs = pa_idxset_new(NULL, NULL);
     s->n_corked = 0;
     s->input_to_master = NULL;
@@ -1444,7 +1446,7 @@ int pa_sink_reconfigure(pa_sink *s, pa_sample_spec *spec, bool passthrough) {
     pa_sink_input *i;
     bool default_rate_is_usable = false;
     bool alternate_rate_is_usable = false;
-    bool avoid_resampling = s->core->avoid_resampling;
+    bool avoid_resampling = s->avoid_resampling;
 
     /* We currently only try to reconfigure the sample rate */
 
@@ -1512,7 +1514,7 @@ int pa_sink_reconfigure(pa_sink *s, pa_sample_spec *spec, bool passthrough) {
     if (!passthrough && pa_sink_used_by(s) > 0)
         return -1;
 
-    pa_log_debug("Suspending sink %s due to changing format.", s->name);
+    pa_log_debug("Suspending sink %s due to changing format, desired rate = %u", s->name, desired_spec.rate);
     pa_sink_suspend(s, true, PA_SUSPEND_INTERNAL);
 
     if (s->reconfigure(s, &desired_spec, passthrough) >= 0) {
diff --git a/src/pulsecore/sink.h b/src/pulsecore/sink.h
index abf2d924..638d5069 100644
--- a/src/pulsecore/sink.h
+++ b/src/pulsecore/sink.h
@@ -83,6 +83,7 @@ struct pa_sink {
     pa_channel_map channel_map;
     uint32_t default_sample_rate;
     uint32_t alternate_sample_rate;
+    bool avoid_resampling:1;
 
     pa_idxset *inputs;
     unsigned n_corked;
@@ -376,6 +377,7 @@ typedef struct pa_sink_new_data {
     pa_sample_spec sample_spec;
     pa_channel_map channel_map;
     uint32_t alternate_sample_rate;
+    bool avoid_resampling:1;
     pa_cvolume volume;
     bool muted:1;
 
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index 02ae87a8..dac085ce 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -258,6 +258,8 @@ pa_source* pa_source_new(
     else
         s->alternate_sample_rate = s->core->alternate_sample_rate;
 
+    s->avoid_resampling = data->avoid_resampling;
+
     s->outputs = pa_idxset_new(NULL, NULL);
     s->n_corked = 0;
     s->monitor_of = NULL;
@@ -1025,7 +1027,7 @@ int pa_source_reconfigure(pa_source *s, pa_sample_spec *spec, bool passthrough)
     uint32_t alternate_rate = s->alternate_sample_rate;
     bool default_rate_is_usable = false;
     bool alternate_rate_is_usable = false;
-    bool avoid_resampling = s->core->avoid_resampling;
+    bool avoid_resampling = s->avoid_resampling;
 
     /* We currently only try to reconfigure the sample rate */
 
@@ -1093,7 +1095,7 @@ int pa_source_reconfigure(pa_source *s, pa_sample_spec *spec, bool passthrough)
     if (!passthrough && pa_source_used_by(s) > 0)
         return -1;
 
-    pa_log_debug("Suspending source %s due to changing the sample rate.", s->name);
+    pa_log_debug("Suspending source %s due to changing the sample rate to %u", s->name, desired_spec.rate);
     pa_source_suspend(s, true, PA_SUSPEND_INTERNAL);
 
     if (s->reconfigure)
diff --git a/src/pulsecore/source.h b/src/pulsecore/source.h
index b0fa608d..f89a0c87 100644
--- a/src/pulsecore/source.h
+++ b/src/pulsecore/source.h
@@ -84,6 +84,7 @@ struct pa_source {
     pa_channel_map channel_map;
     uint32_t default_sample_rate;
     uint32_t alternate_sample_rate;
+    bool avoid_resampling:1;
 
     pa_idxset *outputs;
     unsigned n_corked;
@@ -314,6 +315,7 @@ typedef struct pa_source_new_data {
     pa_sample_spec sample_spec;
     pa_channel_map channel_map;
     uint32_t alternate_sample_rate;
+    bool avoid_resampling:1;
     pa_cvolume volume;
     bool muted:1;
 

commit 354a690694cf28c859bfdafd252b9120b673b744
Author: Sangchul Lee <sangchul1011 at gmail.com>
Date:   Sat Apr 28 01:07:26 2018 +0900

    alsa-sink/source: always set reconfiguration callback
    
    Reconfiguration callback should also be set in case of avoiding resampling
    option. This patch set the callback for every case because the callback
    has already conditions to leave if it is not needed.
    Also unnecessary codes of setting alternate sample rate to 0 are removed.
    
    Signed-off-by: Sangchul Lee <sc11.lee at samsung.com>

diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index ed9e0a51..4cc4b0e3 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -2435,8 +2435,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
         u->sink->set_port = sink_set_port_ucm_cb;
     else
         u->sink->set_port = sink_set_port_cb;
-    if (u->sink->alternate_sample_rate)
-        u->sink->reconfigure = sink_reconfigure_cb;
+    u->sink->reconfigure = sink_reconfigure_cb;
     u->sink->userdata = u;
 
     pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq);
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
index 31d5bb32..2bb42f0b 100644
--- a/src/modules/alsa/alsa-source.c
+++ b/src/modules/alsa/alsa-source.c
@@ -2111,8 +2111,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
         u->source->set_port = source_set_port_ucm_cb;
     else
         u->source->set_port = source_set_port_cb;
-    if (u->source->alternate_sample_rate)
-        u->source->reconfigure = source_reconfigure_cb;
+    u->source->reconfigure = source_reconfigure_cb;
     u->source->userdata = u;
 
     pa_source_set_asyncmsgq(u->source, u->thread_mq.inq);
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index b801b6bc..38e8e50d 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -271,11 +271,6 @@ pa_sink* pa_sink_new(
     else
         s->alternate_sample_rate = s->core->alternate_sample_rate;
 
-    if (s->sample_spec.rate == s->alternate_sample_rate) {
-        pa_log_warn("Default and alternate sample rates are the same.");
-        s->alternate_sample_rate = 0;
-    }
-
     s->inputs = pa_idxset_new(NULL, NULL);
     s->n_corked = 0;
     s->input_to_master = NULL;
@@ -1500,9 +1495,9 @@ int pa_sink_reconfigure(pa_sink *s, pa_sample_spec *spec, bool passthrough) {
             default_rate_is_usable = true;
         if (default_rate % 4000 == 0 && spec->rate % 4000 == 0)
             default_rate_is_usable = true;
-        if (alternate_rate && alternate_rate % 11025 == 0 && spec->rate % 11025 == 0)
+        if (alternate_rate % 11025 == 0 && spec->rate % 11025 == 0)
             alternate_rate_is_usable = true;
-        if (alternate_rate && alternate_rate % 4000 == 0 && spec->rate % 4000 == 0)
+        if (alternate_rate % 4000 == 0 && spec->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 ffb8b6ce..02ae87a8 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -258,11 +258,6 @@ pa_source* pa_source_new(
     else
         s->alternate_sample_rate = s->core->alternate_sample_rate;
 
-    if (s->sample_spec.rate == s->alternate_sample_rate) {
-        pa_log_warn("Default and alternate sample rates are the same.");
-        s->alternate_sample_rate = 0;
-    }
-
     s->outputs = pa_idxset_new(NULL, NULL);
     s->n_corked = 0;
     s->monitor_of = NULL;
@@ -1081,9 +1076,9 @@ int pa_source_reconfigure(pa_source *s, pa_sample_spec *spec, bool passthrough)
             default_rate_is_usable = true;
         if (default_rate % 4000 == 0 && spec->rate % 4000 == 0)
             default_rate_is_usable = true;
-        if (alternate_rate && alternate_rate % 11025 == 0 && spec->rate % 11025 == 0)
+        if (alternate_rate % 11025 == 0 && spec->rate % 11025 == 0)
             alternate_rate_is_usable = true;
-        if (alternate_rate && alternate_rate % 4000 == 0 && spec->rate % 4000 == 0)
+        if (alternate_rate % 4000 == 0 && spec->rate % 4000 == 0)
             alternate_rate_is_usable = true;
 
         if (alternate_rate_is_usable && !default_rate_is_usable)



More information about the pulseaudio-commits mailing list