From 0cc05bc5e3f7109a9b957091a6cdb8d6f035f68c Mon Sep 17 00:00:00 2001 From: Sangchul Lee Date: Mon, 14 May 2018 14:18:58 +0900 Subject: [PATCH] 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. [Version] 11.1-35 [Issue Type] Feature Change-Id: Ib58f269692649c98a16699756410e961fc1b8160 Signed-off-by: Sangchul Lee --- packaging/pulseaudio.spec | 2 +- src/modules/alsa/alsa-sink.c | 24 ++++++++++++++++++++++++ src/modules/alsa/alsa-source.c | 23 +++++++++++++++++++++++ src/modules/alsa/module-alsa-card.c | 6 ++++++ src/modules/module-udev-detect.c | 32 +++++++++++++++++++++++++++++++- src/pulsecore/sink.c | 13 ++++++++++++- src/pulsecore/sink.h | 6 ++++++ src/pulsecore/source.c | 13 ++++++++++++- src/pulsecore/source.h | 6 ++++++ 9 files changed, 121 insertions(+), 4 deletions(-) diff --git a/packaging/pulseaudio.spec b/packaging/pulseaudio.spec index 0164991..0a79e6a 100644 --- a/packaging/pulseaudio.spec +++ b/packaging/pulseaudio.spec @@ -3,7 +3,7 @@ Name: pulseaudio Summary: Improved Linux sound server Version: 11.1 -Release: 34 +Release: 35 Group: Multimedia/Audio License: LGPL-2.1 URL: http://pulseaudio.org diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c index 640c2d4..582f106 100644 --- a/src/modules/alsa/alsa-sink.c +++ b/src/modules/alsa/alsa-sink.c @@ -2032,7 +2032,20 @@ 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; +#ifdef __TIZEN__ + 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; +#else 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; +#endif pa_sink_new_data data; bool volume_is_set; bool mute_is_set; @@ -2044,6 +2057,9 @@ 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; +#ifdef __TIZEN__ + avoid_resampling = m->core->avoid_resampling; +#endif /* Pick sample spec overrides from the mapping, if any */ if (mapping) { @@ -2299,6 +2315,14 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca goto fail; } data.namereg_fail = namereg_fail; +#ifdef __TIZEN__ + 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; +#endif pa_sink_new_data_set_sample_spec(&data, &ss); pa_sink_new_data_set_channel_map(&data, &map); diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c index eddd810..6d85153 100644 --- a/src/modules/alsa/alsa-source.c +++ b/src/modules/alsa/alsa-source.c @@ -1727,7 +1727,19 @@ 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; +#ifdef __TIZEN__ + 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; +#else bool use_mmap = true, b, use_tsched = true, d, ignore_dB = false, namereg_fail = false, deferred_volume = false, fixed_latency_range = false; +#endif pa_source_new_data data; bool volume_is_set; bool mute_is_set; @@ -1739,6 +1751,9 @@ 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; +#ifdef __TIZEN__ + avoid_resampling = m->core->avoid_resampling; +#endif /* Pick sample spec overrides from the mapping, if any */ if (mapping) { @@ -1977,6 +1992,14 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p goto fail; } data.namereg_fail = namereg_fail; +#ifdef __TIZEN__ + 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; +#endif pa_source_new_data_set_sample_spec(&data, &ss); pa_source_new_data_set_channel_map(&data, &map); diff --git a/src/modules/alsa/module-alsa-card.c b/src/modules/alsa/module-alsa-card.c index 3c6bfc4..4c5da8b 100644 --- a/src/modules/alsa/module-alsa-card.c +++ b/src/modules/alsa/module-alsa-card.c @@ -69,6 +69,9 @@ PA_MODULE_USAGE( "profile_set= " "paths_dir= " "use_ucm= " +#ifdef __TIZEN__ + "avoid_resampling= " +#endif ); static const char* const valid_modargs[] = { @@ -96,6 +99,9 @@ static const char* const valid_modargs[] = { "profile_set", "paths_dir", "use_ucm", +#ifdef __TIZEN__ + "avoid_resampling", +#endif NULL }; diff --git a/src/modules/module-udev-detect.c b/src/modules/module-udev-detect.c index 1073f45..398dc95 100644 --- a/src/modules/module-udev-detect.c +++ b/src/modules/module-udev-detect.c @@ -48,7 +48,12 @@ PA_MODULE_USAGE( "fixed_latency_range= " "ignore_dB= " "deferred_volume= " - "use_ucm="); +#ifdef __TIZEN__ + "use_ucm= " + "avoid_resampling="); +#else + "use_ucm= "); +#endif struct device { char *path; @@ -69,6 +74,9 @@ struct userdata { bool ignore_dB:1; bool deferred_volume:1; bool use_ucm:1; +#ifdef __TIZEN__ + bool avoid_resampling:1; +#endif uint32_t tsched_buffer_size; @@ -87,6 +95,9 @@ static const char* const valid_modargs[] = { "ignore_dB", "deferred_volume", "use_ucm", +#ifdef __TIZEN__ + "avoid_resampling", +#endif NULL }; @@ -403,6 +414,9 @@ static void card_changed(struct userdata *u, struct udev_device *dev) { "ignore_dB=%s " "deferred_volume=%s " "use_ucm=%s " +#ifdef __TIZEN__ + "avoid_resampling=%s " +#endif "card_properties=\"module-udev-detect.discovered=1\"", path_get_card_id(path), n, @@ -411,7 +425,12 @@ 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), +#ifdef __TIZEN__ + pa_yes_no(u->use_ucm), + pa_yes_no(u->avoid_resampling)); +#else pa_yes_no(u->use_ucm)); +#endif pa_xfree(n); if (u->tsched_buffer_size_valid) @@ -708,6 +727,9 @@ 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; +#ifdef __TIZEN__ + bool avoid_resampling; +#endif pa_assert(m); @@ -760,6 +782,14 @@ int pa__init(pa_module *m) { } u->use_ucm = use_ucm; +#ifdef __TIZEN__ + 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; +#endif 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 a810838..dad0cc8 100644 --- a/src/pulsecore/sink.c +++ b/src/pulsecore/sink.c @@ -336,6 +336,9 @@ pa_sink* pa_sink_new( s->alternate_sample_rate = data->alternate_sample_rate; else s->alternate_sample_rate = s->core->alternate_sample_rate; +#ifdef __TIZEN__ + s->avoid_resampling = data->avoid_resampling; +#endif s->inputs = pa_idxset_new(NULL, NULL); s->n_corked = 0; @@ -1543,7 +1546,11 @@ 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; +#ifdef __TIZEN__ + bool avoid_resampling = s->avoid_resampling; +#else bool avoid_resampling = s->core->avoid_resampling; +#endif /* We currently only try to reconfigure the sample rate */ @@ -1611,7 +1618,11 @@ 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); +#ifdef __TIZEN__ + pa_log_debug("Suspending sink %s due to changing format, desired rate = %u", s->name, desired_spec.rate); +#else + pa_log_debug("Suspending sink %s due to changing format", s->name); +#endif 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 2a1dd43..2d6c80d 100644 --- a/src/pulsecore/sink.h +++ b/src/pulsecore/sink.h @@ -83,6 +83,9 @@ struct pa_sink { pa_channel_map channel_map; uint32_t default_sample_rate; uint32_t alternate_sample_rate; +#ifdef __TIZEN__ + bool avoid_resampling:1; +#endif pa_idxset *inputs; unsigned n_corked; @@ -365,6 +368,9 @@ typedef struct pa_sink_new_data { pa_sample_spec sample_spec; pa_channel_map channel_map; uint32_t alternate_sample_rate; +#ifdef __TIZEN__ + bool avoid_resampling:1; +#endif pa_cvolume volume; bool muted:1; diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c index 52bac2d..e6f022f 100644 --- a/src/pulsecore/source.c +++ b/src/pulsecore/source.c @@ -323,6 +323,9 @@ pa_source* pa_source_new( s->alternate_sample_rate = data->alternate_sample_rate; else s->alternate_sample_rate = s->core->alternate_sample_rate; +#ifdef __TIZEN__ + s->avoid_resampling = data->avoid_resampling; +#endif s->outputs = pa_idxset_new(NULL, NULL); s->n_corked = 0; @@ -1123,7 +1126,11 @@ 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; +#ifdef __TIZEN__ + bool avoid_resampling = s->avoid_resampling; +#else bool avoid_resampling = s->core->avoid_resampling; +#endif /* We currently only try to reconfigure the sample rate */ @@ -1191,7 +1198,11 @@ 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); +#ifdef __TIZEN__ + pa_log_debug("Suspending source %s due to changing the sample rate to %u", s->name, desired_spec.rate); +#else + pa_log_debug("Suspending source %s due to changing the sample rate", s->name); +#endif pa_source_suspend(s, true, PA_SUSPEND_INTERNAL); if (s->reconfigure) diff --git a/src/pulsecore/source.h b/src/pulsecore/source.h index 8da65be..ef76d17 100644 --- a/src/pulsecore/source.h +++ b/src/pulsecore/source.h @@ -84,6 +84,9 @@ struct pa_source { pa_channel_map channel_map; uint32_t default_sample_rate; uint32_t alternate_sample_rate; +#ifdef __TIZEN__ + bool avoid_resampling:1; +#endif pa_idxset *outputs; unsigned n_corked; @@ -303,6 +306,9 @@ typedef struct pa_source_new_data { pa_sample_spec sample_spec; pa_channel_map channel_map; uint32_t alternate_sample_rate; +#ifdef __TIZEN__ + bool avoid_resampling:1; +#endif pa_cvolume volume; bool muted:1; -- 2.7.4