[PATCH 3/5] core/alsa: make rate and alternate rate sink/source specific

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use the specified rate and alternate rates instead of the global
values specified in daemon.conf

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart at intel.com>
---
 src/modules/alsa/alsa-sink.c          |    8 ++++++++
 src/modules/alsa/alsa-source.c        |    8 ++++++++
 src/modules/alsa/module-alsa-sink.c   |    2 ++
 src/modules/alsa/module-alsa-source.c |    2 ++
 src/pulsecore/modargs.c               |   12 ++++++++++++
 src/pulsecore/modargs.h               |    3 +++
 src/pulsecore/sink.c                  |   17 +++++++++++++++--
 src/pulsecore/sink.h                  |    5 +++++
 src/pulsecore/source.c                |   18 +++++++++++++++---
 src/pulsecore/source.h                |    5 +++++
 10 files changed, 75 insertions(+), 5 deletions(-)

diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index 3399c83..93ed8c6 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -1807,6 +1807,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
     struct userdata *u = NULL;
     const char *dev_id = NULL;
     pa_sample_spec ss, requested_ss;
+    uint32_t alternate_sample_rate;
     pa_channel_map map;
     uint32_t nfrags, frag_size, buffer_size, tsched_size, tsched_watermark, rewind_safeguard;
     snd_pcm_uframes_t period_frames, buffer_frames, tsched_frames;
@@ -1825,6 +1826,12 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
         goto fail;
     }
 
+    alternate_sample_rate = m->core->alternate_sample_rate;
+    if (pa_modargs_get_alternate_sample_rate(ma, &alternate_sample_rate) < 0) {
+        pa_log("Failed to parse alternate sample rate");
+        goto fail;
+    }
+
     requested_ss = ss;
     frame_size = pa_frame_size(&ss);
 
@@ -2007,6 +2014,7 @@ pa_sink *pa_alsa_sink_new(pa_module *m, pa_modargs *ma, const char*driver, pa_ca
 
     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);
 
     pa_alsa_init_proplist_pcm(m->core, data.proplist, u->pcm_handle);
     pa_proplist_sets(data.proplist, PA_PROP_DEVICE_STRING, u->device_name);
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
index 3358193..52333a0 100644
--- a/src/modules/alsa/alsa-source.c
+++ b/src/modules/alsa/alsa-source.c
@@ -1525,6 +1525,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
     struct userdata *u = NULL;
     const char *dev_id = NULL;
     pa_sample_spec ss, requested_ss;
+    uint32_t alternate_sample_rate;
     pa_channel_map map;
     uint32_t nfrags, frag_size, buffer_size, tsched_size, tsched_watermark;
     snd_pcm_uframes_t period_frames, buffer_frames, tsched_frames;
@@ -1543,6 +1544,12 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
         goto fail;
     }
 
+    alternate_sample_rate = m->core->alternate_sample_rate;
+    if (pa_modargs_get_alternate_sample_rate(ma, &alternate_sample_rate) < 0) {
+        pa_log("Failed to parse alternate sample rate");
+        goto fail;
+    }
+
     requested_ss = ss;
     frame_size = pa_frame_size(&ss);
 
@@ -1710,6 +1717,7 @@ pa_source *pa_alsa_source_new(pa_module *m, pa_modargs *ma, const char*driver, p
 
     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);
 
     pa_alsa_init_proplist_pcm(m->core, data.proplist, u->pcm_handle);
     pa_proplist_sets(data.proplist, PA_PROP_DEVICE_STRING, u->device_name);
diff --git a/src/modules/alsa/module-alsa-sink.c b/src/modules/alsa/module-alsa-sink.c
index 697fab4..4e94eea 100644
--- a/src/modules/alsa/module-alsa-sink.c
+++ b/src/modules/alsa/module-alsa-sink.c
@@ -45,6 +45,7 @@ PA_MODULE_USAGE(
         "device_id=<ALSA card index> "
         "format=<sample format> "
         "rate=<sample rate> "
+        "alternate_rate=<alternate sample rate> "
         "channels=<number of channels> "
         "channel_map=<channel map> "
         "fragments=<number of fragments> "
@@ -68,6 +69,7 @@ static const char* const valid_modargs[] = {
     "device_id",
     "format",
     "rate",
+    "alternate_rate",
     "channels",
     "channel_map",
     "fragments",
diff --git a/src/modules/alsa/module-alsa-source.c b/src/modules/alsa/module-alsa-source.c
index 23da418..3ea0364 100644
--- a/src/modules/alsa/module-alsa-source.c
+++ b/src/modules/alsa/module-alsa-source.c
@@ -69,6 +69,7 @@ PA_MODULE_USAGE(
         "device_id=<ALSA card index> "
         "format=<sample format> "
         "rate=<sample rate> "
+        "alternate_rate=<alternate sample rate> "
         "channels=<number of channels> "
         "channel_map=<channel map> "
         "fragments=<number of fragments> "
@@ -88,6 +89,7 @@ static const char* const valid_modargs[] = {
     "device_id",
     "format",
     "rate",
+    "alternate_rate",
     "channels",
     "channel_map",
     "fragments",
diff --git a/src/pulsecore/modargs.c b/src/pulsecore/modargs.c
index e78cdb9..77e3241 100644
--- a/src/pulsecore/modargs.c
+++ b/src/pulsecore/modargs.c
@@ -341,6 +341,18 @@ int pa_modargs_get_sample_spec(pa_modargs *ma, pa_sample_spec *rss) {
     return 0;
 }
 
+int pa_modargs_get_alternate_sample_rate(pa_modargs *ma, uint32_t *alternate_rate) {
+    pa_assert(ma);
+    pa_assert(alternate_rate);
+
+    if ((pa_modargs_get_value_u32(ma, "alternate_rate", alternate_rate)) < 0 ||
+        *alternate_rate <= 0 ||
+        *alternate_rate > PA_RATE_MAX)
+        return -1;
+
+    return 0;
+}
+
 int pa_modargs_get_channel_map(pa_modargs *ma, const char *name, pa_channel_map *rmap) {
     pa_channel_map map;
     const char *cm;
diff --git a/src/pulsecore/modargs.h b/src/pulsecore/modargs.h
index 1ed66e9..619d28e 100644
--- a/src/pulsecore/modargs.h
+++ b/src/pulsecore/modargs.h
@@ -58,6 +58,9 @@ structure if no channel_map is found, using pa_channel_map_init_auto() */
 
 int pa_modargs_get_sample_spec_and_channel_map(pa_modargs *ma, pa_sample_spec *ss, pa_channel_map *map, pa_channel_map_def_t def);
 
+/* Return alternate sample rate from "alternate_sample_rate" parameter */
+int pa_modargs_get_alternate_sample_rate(pa_modargs *ma, uint32_t *alternate_rate);
+
 int pa_modargs_get_proplist(pa_modargs *ma, const char *name, pa_proplist *p, pa_update_mode_t m);
 
 /* Iterate through the module argument list. The user should allocate a
diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index e8ef0a7..5da6802 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -104,6 +104,13 @@ void pa_sink_new_data_set_channel_map(pa_sink_new_data *data, const pa_channel_m
         data->channel_map = *map;
 }
 
+void pa_sink_new_data_set_alternate_sample_rate(pa_sink_new_data *data, const uint32_t alternate_sample_rate) {
+    pa_assert(data);
+
+    data->alternate_sample_rate_is_set = TRUE;
+    data->alternate_sample_rate = alternate_sample_rate;
+}
+
 void pa_sink_new_data_set_volume(pa_sink_new_data *data, const pa_cvolume *volume) {
     pa_assert(data);
 
@@ -267,6 +274,11 @@ pa_sink* pa_sink_new(
 
     s->sample_spec = data->sample_spec;
     s->channel_map = data->channel_map;
+    if (data->alternate_sample_rate_is_set)
+        s->alternate_sample_rate = data->alternate_sample_rate;
+    else
+        s->alternate_sample_rate = s->core->alternate_sample_rate;
+    s->default_sample_rate = s->sample_spec.rate;
 
     s->inputs = pa_idxset_new(NULL, NULL);
     s->n_corked = 0;
@@ -353,6 +365,7 @@ pa_sink* pa_sink_new(
     pa_source_new_data_init(&source_data);
     pa_source_new_data_set_sample_spec(&source_data, &s->sample_spec);
     pa_source_new_data_set_channel_map(&source_data, &s->channel_map);
+    pa_source_new_data_set_alternate_sample_rate(&source_data, s->alternate_sample_rate);
     source_data.name = pa_sprintf_malloc("%s.monitor", name);
     source_data.driver = data->driver;
     source_data.module = data->module;
@@ -1168,8 +1181,8 @@ pa_bool_t pa_sink_update_rate(pa_sink *s, uint32_t rate)
     if (s->update_rate) {
 
         uint32_t desired_rate = rate;
-        uint32_t default_rate = s->core->default_sample_spec.rate;
-        uint32_t alternate_rate = s->core->alternate_sample_rate;
+        uint32_t default_rate = s->default_sample_rate;
+        uint32_t alternate_rate = s->alternate_sample_rate;
         pa_bool_t use_alternate = FALSE;
 
         if (PA_UNLIKELY (desired_rate < 8000 ||
diff --git a/src/pulsecore/sink.h b/src/pulsecore/sink.h
index f478af7..23514a0 100644
--- a/src/pulsecore/sink.h
+++ b/src/pulsecore/sink.h
@@ -82,6 +82,8 @@ struct pa_sink {
 
     pa_sample_spec sample_spec;
     pa_channel_map channel_map;
+    uint32_t default_sample_rate;
+    uint32_t alternate_sample_rate;
 
     pa_idxset *inputs;
     unsigned n_corked;
@@ -304,11 +306,13 @@ typedef struct pa_sink_new_data {
 
     pa_sample_spec sample_spec;
     pa_channel_map channel_map;
+    uint32_t alternate_sample_rate;
     pa_cvolume volume;
     pa_bool_t muted :1;
 
     pa_bool_t sample_spec_is_set:1;
     pa_bool_t channel_map_is_set:1;
+    pa_bool_t alternate_sample_rate_is_set:1;
     pa_bool_t volume_is_set:1;
     pa_bool_t muted_is_set:1;
 
@@ -323,6 +327,7 @@ pa_sink_new_data* pa_sink_new_data_init(pa_sink_new_data *data);
 void pa_sink_new_data_set_name(pa_sink_new_data *data, const char *name);
 void pa_sink_new_data_set_sample_spec(pa_sink_new_data *data, const pa_sample_spec *spec);
 void pa_sink_new_data_set_channel_map(pa_sink_new_data *data, const pa_channel_map *map);
+void pa_sink_new_data_set_alternate_sample_rate(pa_sink_new_data *data, const uint32_t alternate_sample_rate);
 void pa_sink_new_data_set_volume(pa_sink_new_data *data, const pa_cvolume *volume);
 void pa_sink_new_data_set_muted(pa_sink_new_data *data, pa_bool_t mute);
 void pa_sink_new_data_set_port(pa_sink_new_data *data, const char *port);
diff --git a/src/pulsecore/source.c b/src/pulsecore/source.c
index 9c06d92..952d4fd 100644
--- a/src/pulsecore/source.c
+++ b/src/pulsecore/source.c
@@ -80,6 +80,13 @@ void pa_source_new_data_set_channel_map(pa_source_new_data *data, const pa_chann
         data->channel_map = *map;
 }
 
+void pa_source_new_data_set_alternate_sample_rate(pa_source_new_data *data, const uint32_t alternate_sample_rate) {
+    pa_assert(data);
+
+    data->alternate_sample_rate_is_set = TRUE;
+    data->alternate_sample_rate = alternate_sample_rate;
+}
+
 void pa_source_new_data_set_volume(pa_source_new_data *data, const pa_cvolume *volume) {
     pa_assert(data);
 
@@ -218,6 +225,11 @@ pa_source* pa_source_new(
 
     s->sample_spec = data->sample_spec;
     s->channel_map = data->channel_map;
+    if (data->alternate_sample_rate_is_set)
+        s->alternate_sample_rate = data->alternate_sample_rate;
+    else
+        s->alternate_sample_rate = s->core->alternate_sample_rate;
+    s->default_sample_rate = s->sample_spec.rate;
 
     s->outputs = pa_idxset_new(NULL, NULL);
     s->n_corked = 0;
@@ -720,8 +732,8 @@ pa_bool_t pa_source_update_rate(pa_source *s, uint32_t rate)
 
     if (s->update_rate) {
         uint32_t desired_rate = rate;
-        uint32_t default_rate = s->core->default_sample_spec.rate;
-        uint32_t alternate_rate = s->core->alternate_sample_rate;
+        uint32_t default_rate = s->default_sample_rate;
+        uint32_t alternate_rate = s->alternate_sample_rate;
         pa_bool_t use_alternate = FALSE;
 
         if (PA_UNLIKELY (desired_rate < 8000 ||
@@ -743,7 +755,7 @@ pa_bool_t pa_source_update_rate(pa_source *s, uint32_t rate)
         else
             desired_rate = default_rate;
 
-        if (s->update_rate(s, rate) == TRUE) {
+        if (s->update_rate(s, desired_rate) == TRUE) {
             pa_log_info("Changed sampling rate successfully ");
             return TRUE;
         }
diff --git a/src/pulsecore/source.h b/src/pulsecore/source.h
index 4712cb9..ff8c6be 100644
--- a/src/pulsecore/source.h
+++ b/src/pulsecore/source.h
@@ -71,6 +71,8 @@ struct pa_source {
 
     pa_sample_spec sample_spec;
     pa_channel_map channel_map;
+    uint32_t default_sample_rate;
+    uint32_t alternate_sample_rate;
 
     pa_idxset *outputs;
     unsigned n_corked;
@@ -201,6 +203,7 @@ typedef struct pa_source_new_data {
 
     pa_sample_spec sample_spec;
     pa_channel_map channel_map;
+    uint32_t alternate_sample_rate;
     pa_cvolume volume;
     pa_bool_t muted:1;
 
@@ -208,6 +211,7 @@ typedef struct pa_source_new_data {
     pa_bool_t muted_is_set:1;
     pa_bool_t sample_spec_is_set:1;
     pa_bool_t channel_map_is_set:1;
+    pa_bool_t alternate_sample_rate_is_set:1;
 
     pa_bool_t namereg_fail:1;
 
@@ -220,6 +224,7 @@ pa_source_new_data* pa_source_new_data_init(pa_source_new_data *data);
 void pa_source_new_data_set_name(pa_source_new_data *data, const char *name);
 void pa_source_new_data_set_sample_spec(pa_source_new_data *data, const pa_sample_spec *spec);
 void pa_source_new_data_set_channel_map(pa_source_new_data *data, const pa_channel_map *map);
+void pa_source_new_data_set_alternate_sample_rate(pa_source_new_data *data, const uint32_t alternate_sample_rate);
 void pa_source_new_data_set_volume(pa_source_new_data *data, const pa_cvolume *volume);
 void pa_source_new_data_set_muted(pa_source_new_data *data, pa_bool_t mute);
 void pa_source_new_data_set_port(pa_source_new_data *data, const char *port);
-- 
1.7.4




[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux