From: DINESH R T <rtdinesh.89@xxxxxxxxx> Extended enable-remixing field with mono-only option which enables remixing only when source/sink is mono. I couldn't simulate the mono scenario in source/sink, so i din't test the code but compiled the code with pulseaduio head. --- src/daemon/daemon-conf.c | 26 ++++++++++++++++++++++---- src/daemon/daemon-conf.h | 2 +- src/daemon/main.c | 2 +- src/pulse/sample.c | 28 ++++++++++++++++++++++++++++ src/pulse/sample.h | 19 +++++++++++++++++++ src/pulsecore/core.c | 2 +- src/pulsecore/core.h | 2 +- src/pulsecore/resampler.c | 29 ++++++++++++++++++++++++++--- src/pulsecore/resampler.h | 3 ++- src/pulsecore/sink-input.c | 8 +++++--- src/pulsecore/source-output.c | 8 +++++--- 11 files changed, 111 insertions(+), 18 deletions(-) diff --git a/src/daemon/daemon-conf.c b/src/daemon/daemon-conf.c index 2c43cf9..45976b1 100644 --- a/src/daemon/daemon-conf.c +++ b/src/daemon/daemon-conf.c @@ -84,7 +84,7 @@ static const pa_daemon_conf default_conf = { .log_meta = FALSE, .log_time = FALSE, .resample_method = PA_RESAMPLER_AUTO, - .disable_remixing = FALSE, + .remixing_option = PA_DISABLE_REMIXING, .disable_lfe_remixing = TRUE, .config_file = NULL, .use_pid_file = TRUE, @@ -511,6 +511,24 @@ static int parse_nice_level(pa_config_parser_state *state) { return 0; } + + +static int parse_enable_remixing(pa_config_parser_state *state) { + pa_daemon_conf *c; + pa_remixing_option_t f; + + pa_assert(state); + + c = state->data; + + if ((f = pa_parse_remixing(state->rvalue)) < 0) { + pa_log(_("[%s:%u] Invalid remixing option '%s'."), state->filename, state->lineno, state->rvalue); + return -1; + } + + c->remixing_option = f; + return 0; +} static int parse_rtprio(pa_config_parser_state *state) { #if !defined(OS_IS_WIN32) && defined(HAVE_SCHED_H) pa_daemon_conf *c; @@ -600,8 +618,8 @@ int pa_daemon_conf_load(pa_daemon_conf *c, const char *filename) { { "deferred-volume-extra-delay-usec", pa_config_parse_int, &c->deferred_volume_extra_delay_usec, NULL }, { "nice-level", parse_nice_level, c, NULL }, - { "disable-remixing", pa_config_parse_bool, &c->disable_remixing, NULL }, - { "enable-remixing", pa_config_parse_not_bool, &c->disable_remixing, NULL }, + { "disable-remixing", parse_enable_remixing, &c->remixing_option, NULL }, + { "enable-remixing", parse_enable_remixing, &c->remixing_option, NULL }, { "disable-lfe-remixing", pa_config_parse_bool, &c->disable_lfe_remixing, NULL }, { "enable-lfe-remixing", pa_config_parse_not_bool, &c->disable_lfe_remixing, NULL }, { "load-default-script-file", pa_config_parse_bool, &c->load_default_script_file, NULL }, @@ -790,7 +808,7 @@ char *pa_daemon_conf_dump(pa_daemon_conf *c) { pa_strbuf_printf(s, "log-target = %s\n", c->auto_log_target ? "auto" : (c->log_target == PA_LOG_SYSLOG ? "syslog" : "stderr")); pa_strbuf_printf(s, "log-level = %s\n", log_level_to_string[c->log_level]); pa_strbuf_printf(s, "resample-method = %s\n", pa_resample_method_to_string(c->resample_method)); - pa_strbuf_printf(s, "enable-remixing = %s\n", pa_yes_no(!c->disable_remixing)); + pa_strbuf_printf(s, "enable-remixing = %s\n", pa_remixing_option_to_string(c->remixing_option)); pa_strbuf_printf(s, "enable-lfe-remixing = %s\n", pa_yes_no(!c->disable_lfe_remixing)); pa_strbuf_printf(s, "default-sample-format = %s\n", pa_sample_format_to_string(c->default_sample_spec.format)); pa_strbuf_printf(s, "default-sample-rate = %u\n", c->default_sample_spec.rate); diff --git a/src/daemon/daemon-conf.h b/src/daemon/daemon-conf.h index faf2540..da42cfc 100644 --- a/src/daemon/daemon-conf.h +++ b/src/daemon/daemon-conf.h @@ -68,7 +68,6 @@ typedef struct pa_daemon_conf { system_instance, no_cpu_limit, disable_shm, - disable_remixing, disable_lfe_remixing, load_default_script_file, disallow_exit, @@ -84,6 +83,7 @@ typedef struct pa_daemon_conf { realtime_priority, nice_level, resample_method; + pa_remixing_option_t remixing_option; char *script_commands, *dl_search_path, *default_script_file; pa_log_target_t log_target; pa_log_level_t log_level; diff --git a/src/daemon/main.c b/src/daemon/main.c index c18524f..6f8c160 100644 --- a/src/daemon/main.c +++ b/src/daemon/main.c @@ -1026,7 +1026,7 @@ int main(int argc, char *argv[]) { c->resample_method = conf->resample_method; c->realtime_priority = conf->realtime_priority; c->realtime_scheduling = !!conf->realtime_scheduling; - c->disable_remixing = !!conf->disable_remixing; + c->remixing_option = conf->remixing_option; c->disable_lfe_remixing = !!conf->disable_lfe_remixing; c->deferred_volume = !!conf->deferred_volume; c->running_as_daemon = !!conf->daemonize; diff --git a/src/pulse/sample.c b/src/pulse/sample.c index b613612..cbb2da7 100644 --- a/src/pulse/sample.c +++ b/src/pulse/sample.c @@ -157,6 +157,18 @@ const char *pa_sample_format_to_string(pa_sample_format_t f) { return table[f]; } +const char *pa_remixing_option_to_string(pa_remixing_option_t f) { + static const char* const table[]= { + [PA_DISABLE_REMIXING] = "NO", + [PA_ENABLE_REMIXING] = "YES", + [PA_MONO_ONLY] = "MONO-ONLY" + }; + + if (f < 0 || f >= PA_REMIXING_MAX) + return NULL; + + return table[f]; +} char *pa_sample_spec_snprint(char *s, size_t l, const pa_sample_spec *spec) { pa_assert(s); @@ -244,6 +256,22 @@ pa_sample_format_t pa_parse_sample_format(const char *format) { return PA_SAMPLE_INVALID; } + +pa_remixing_option_t pa_parse_remixing(const char *format){ + pa_assert(format); + if (strcasecmp(format, "mono-only") == 0) + return PA_MONO_ONLY; + else if (strcasecmp(format, "yes") == 0) + return PA_ENABLE_REMIXING; + else if (strcasecmp(format,"true") == 0) + return PA_ENABLE_REMIXING; + else if(strcasecmp(format, "no") == 0) + return PA_DISABLE_REMIXING; + else if(strcasecmp(format, "false") == 0) + return PA_DISABLE_REMIXING; + + return PA_REMIXING_INVALID; +} int pa_sample_format_is_le(pa_sample_format_t f) { pa_assert(f >= PA_SAMPLE_U8); pa_assert(f < PA_SAMPLE_MAX); diff --git a/src/pulse/sample.h b/src/pulse/sample.h index 9067951..65272a0 100644 --- a/src/pulse/sample.h +++ b/src/pulse/sample.h @@ -180,6 +180,21 @@ typedef enum pa_sample_format { /**< An invalid value */ } pa_sample_format_t; +/* Remixing Options */ +typedef enum pa_remixing_option{ + /* ENable Remixing */ + PA_ENABLE_REMIXING=0, + /* Enable Remix if input/output/both is mono-only */ + PA_MONO_ONLY=1, + /* Disable Remixing */ + PA_DISABLE_REMIXING=2, + /*Upper limit of valid remixing type */ + PA_REMIXING_MAX=4, + + PA_REMIXING_INVALID = -1 +}pa_remixing_option_t; + + #ifdef WORDS_BIGENDIAN /** Signed 16 Bit PCM, native endian */ #define PA_SAMPLE_S16NE PA_SAMPLE_S16BE @@ -244,6 +259,10 @@ typedef enum pa_sample_format { #define PA_SAMPLE_S24BE PA_SAMPLE_S24BE #define PA_SAMPLE_S24_32LE PA_SAMPLE_S24_32LE #define PA_SAMPLE_S24_32BE PA_SAMPLE_S24_32BE + +#define PA_ENABLE_REMIXING PA_ENABLE_REMIXING +#define PA_DISABLE_REMIXING PA_DISABLE_REMIXING +#define PA_MONO_ONLY PA_MONO_ONLY /** \endcond */ /** A sample format and attribute specification */ diff --git a/src/pulsecore/core.c b/src/pulsecore/core.c index 2ca50c2..330fe04 100644 --- a/src/pulsecore/core.c +++ b/src/pulsecore/core.c @@ -138,7 +138,7 @@ pa_core* pa_core_new(pa_mainloop_api *m, pa_bool_t shared, size_t shm_size) { c->running_as_daemon = FALSE; c->realtime_scheduling = FALSE; c->realtime_priority = 5; - c->disable_remixing = FALSE; + c->remixing_option = PA_DISABLE_REMIXING; c->disable_lfe_remixing = FALSE; c->deferred_volume = TRUE; c->resample_method = PA_RESAMPLER_SPEEX_FLOAT_BASE + 1; diff --git a/src/pulsecore/core.h b/src/pulsecore/core.h index a8cff5c..0f14878 100644 --- a/src/pulsecore/core.h +++ b/src/pulsecore/core.h @@ -174,11 +174,11 @@ struct pa_core { pa_bool_t disallow_exit:1; pa_bool_t running_as_daemon:1; pa_bool_t realtime_scheduling:1; - pa_bool_t disable_remixing:1; pa_bool_t disable_lfe_remixing:1; pa_bool_t deferred_volume:1; pa_resample_method_t resample_method; + pa_remixing_option_t remixing_option; int realtime_priority; pa_server_type_t server_type; diff --git a/src/pulsecore/resampler.c b/src/pulsecore/resampler.c index bc45f06..53f4b03 100644 --- a/src/pulsecore/resampler.c +++ b/src/pulsecore/resampler.c @@ -203,7 +203,6 @@ pa_resampler* pa_resampler_new( pa_resample_flags_t flags) { pa_resampler *r = NULL; - pa_assert(pool); pa_assert(a); pa_assert(b); @@ -700,7 +699,7 @@ static void calc_map_table(pa_resampler *r) { m->map_table_f[oc][ic] = 1.0f; } } - } else { + }else { /* OK, we shall do the full monty: upmixing and downmixing. Our * algorithm is relatively simple, does not do spacialization, delay @@ -770,11 +769,35 @@ static void calc_map_table(pa_resampler *r) { ic_unconnected_left = 0, ic_unconnected_right = 0, ic_unconnected_center = 0, - ic_unconnected_lfe = 0; + ic_unconnected_lfe = 0, + c; bool ic_unconnected_center_mixed_in = 0; + bool input_is_mono_only = true; + bool output_is_mono_only = true; pa_assert(remix); + if(r->flags & PA_RESAMPLER_MONO_ONLY){ + + for (c = 0; c < r->i_cm.channels; c++) { + if (r->i_cm.map[c] != PA_CHANNEL_POSITION_MONO) { + input_is_mono_only = false; + break; + } + } + + for (c = 0; c < r->o_cm.channels; c++) { + if (r->o_cm.map[c] != PA_CHANNEL_POSITION_MONO) { + output_is_mono_only = false; + break; + } + } + + if ((!input_is_mono_only) || (!output_is_mono_only)) + return; + } + + for (ic = 0; ic < n_ic; ic++) { if (on_left(r->i_cm.map[ic])) ic_left++; diff --git a/src/pulsecore/resampler.h b/src/pulsecore/resampler.h index 742de6a..1d09ff4 100644 --- a/src/pulsecore/resampler.h +++ b/src/pulsecore/resampler.h @@ -52,7 +52,8 @@ typedef enum pa_resample_flags { PA_RESAMPLER_VARIABLE_RATE = 0x0001U, PA_RESAMPLER_NO_REMAP = 0x0002U, /* implies NO_REMIX */ PA_RESAMPLER_NO_REMIX = 0x0004U, - PA_RESAMPLER_NO_LFE = 0x0008U + PA_RESAMPLER_NO_LFE = 0x0008U, + PA_RESAMPLER_MONO_ONLY = 0x0010U } pa_resample_flags_t; pa_resampler* pa_resampler_new( diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c index 6131bd3..bef09c9 100644 --- a/src/pulsecore/sink-input.c +++ b/src/pulsecore/sink-input.c @@ -450,7 +450,8 @@ int pa_sink_input_new( data->resample_method, ((data->flags & PA_SINK_INPUT_VARIABLE_RATE) ? PA_RESAMPLER_VARIABLE_RATE : 0) | ((data->flags & PA_SINK_INPUT_NO_REMAP) ? PA_RESAMPLER_NO_REMAP : 0) | - (core->disable_remixing || (data->flags & PA_SINK_INPUT_NO_REMIX) ? PA_RESAMPLER_NO_REMIX : 0) | + ((core->remixing_option & PA_DISABLE_REMIXING) || (data->flags & PA_SINK_INPUT_NO_REMIX) ? PA_RESAMPLER_NO_REMIX : 0) | + ((core->remixing_option & PA_MONO_ONLY)?PA_RESAMPLER_MONO_ONLY:0)| (core->disable_lfe_remixing ? PA_RESAMPLER_NO_LFE : 0)))) { pa_log_warn("Unsupported resampling operation."); return -PA_ERR_NOTSUPPORTED; @@ -2193,9 +2194,10 @@ int pa_sink_input_update_rate(pa_sink_input *i) { &i->sample_spec, &i->channel_map, &i->sink->sample_spec, &i->sink->channel_map, i->requested_resample_method, - ((i->flags & PA_SINK_INPUT_VARIABLE_RATE) ? PA_RESAMPLER_VARIABLE_RATE : 0) | + ((i->flags & PA_SINK_INPUT_VARIABLE_RATE)? PA_RESAMPLER_VARIABLE_RATE : 0) | ((i->flags & PA_SINK_INPUT_NO_REMAP) ? PA_RESAMPLER_NO_REMAP : 0) | - (i->core->disable_remixing || (i->flags & PA_SINK_INPUT_NO_REMIX) ? PA_RESAMPLER_NO_REMIX : 0)); + ((i->core->remixing_option & PA_DISABLE_REMIXING) || (i->flags & PA_SINK_INPUT_NO_REMIX) ? PA_RESAMPLER_NO_REMIX : 0)| + (((i->core->remixing_option & PA_MONO_ONLY))? PA_RESAMPLER_MONO_ONLY :0)); if (!new_resampler) { pa_log_warn("Unsupported resampling operation."); diff --git a/src/pulsecore/source-output.c b/src/pulsecore/source-output.c index d942419..4b01d49 100644 --- a/src/pulsecore/source-output.c +++ b/src/pulsecore/source-output.c @@ -392,7 +392,8 @@ int pa_source_output_new( data->resample_method, ((data->flags & PA_SOURCE_OUTPUT_VARIABLE_RATE) ? PA_RESAMPLER_VARIABLE_RATE : 0) | ((data->flags & PA_SOURCE_OUTPUT_NO_REMAP) ? PA_RESAMPLER_NO_REMAP : 0) | - (core->disable_remixing || (data->flags & PA_SOURCE_OUTPUT_NO_REMIX) ? PA_RESAMPLER_NO_REMIX : 0) | + ((core->remixing_option & PA_DISABLE_REMIXING) || (data->flags & PA_SOURCE_OUTPUT_NO_REMIX) ? PA_RESAMPLER_NO_REMIX : 0) | + ((core->remixing_option & PA_MONO_ONLY)?PA_RESAMPLER_MONO_ONLY:0)| (core->disable_lfe_remixing ? PA_RESAMPLER_NO_LFE : 0)))) { pa_log_warn("Unsupported resampling operation."); return -PA_ERR_NOTSUPPORTED; @@ -1644,9 +1645,10 @@ int pa_source_output_update_rate(pa_source_output *o) { &o->source->sample_spec, &o->source->channel_map, &o->sample_spec, &o->channel_map, o->requested_resample_method, - ((o->flags & PA_SOURCE_OUTPUT_VARIABLE_RATE) ? PA_RESAMPLER_VARIABLE_RATE : 0) | + ((o->flags & PA_SOURCE_OUTPUT_VARIABLE_RATE)? PA_RESAMPLER_VARIABLE_RATE : 0) | ((o->flags & PA_SOURCE_OUTPUT_NO_REMAP) ? PA_RESAMPLER_NO_REMAP : 0) | - (o->core->disable_remixing || (o->flags & PA_SOURCE_OUTPUT_NO_REMIX) ? PA_RESAMPLER_NO_REMIX : 0)); + ((o->core->remixing_option & PA_DISABLE_REMIXING) || (o->flags & PA_SOURCE_OUTPUT_NO_REMIX) ? PA_RESAMPLER_NO_REMIX : 0)| + ((o->core->remixing_option & PA_MONO_ONLY)?PA_RESAMPLER_MONO_ONLY:0)); if (!new_resampler) { pa_log_warn("Unsupported resampling operation."); -- 1.7.9.5