From patchwork Wed Feb 15 12:28:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Young X-Patchwork-Id: 9573979 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 834F7601D8 for ; Wed, 15 Feb 2017 12:35:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 727AC2842E for ; Wed, 15 Feb 2017 12:35:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6720A2847B; Wed, 15 Feb 2017 12:35:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 632652842E for ; Wed, 15 Feb 2017 12:35:37 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 0A227266C1C; Wed, 15 Feb 2017 13:28:47 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 0EDCB266C21; Wed, 15 Feb 2017 13:28:45 +0100 (CET) Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by alsa0.perex.cz (Postfix) with ESMTP id 073BB266B81 for ; Wed, 15 Feb 2017 13:28:40 +0100 (CET) Received: by mail-wm0-f67.google.com with SMTP id r18so7964842wmd.3 for ; Wed, 15 Feb 2017 04:28:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to; bh=9Htx8zukZDDDQPJYV2tiBjw1JG+3U14+nzQvsZvIvMQ=; b=M8neUrBLu/RT+peP31+4ZmsBI86jKQAhkKk1IDMAvPgE7swi8SrAfoKL0nTxNvd+Cd Ea+mBbL2FOui3HIZlNBwlKO3CWcqvgw+QDjLR0LGTwi9D9t9jXi6aNWEqpscE6GYK4Dt +7l2STayItKAzLm5SwhT56O3pUSB2yhDKY3WOCGdtypsY+swI/k64Z8NhZliGTMQazTf l0NK7EIYoQKL2vW/W0gOmBiGaiPtDyUUMu1+Lj3ltCDLz17Ch9NWpH6ZHT82KorQZ6HK NEBT7YVZsjvVWf/tAxDJLf2AodpYIvrjJ0NOxYDrh/rjEJtXvV9tciBApyV0RMjjnXjI O/WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:references:cc:from:message-id :date:user-agent:mime-version:in-reply-to; bh=9Htx8zukZDDDQPJYV2tiBjw1JG+3U14+nzQvsZvIvMQ=; b=TPYXBz32+Xk1PHNtTgfsKRbY81+QZFRp5/mrVEzNyio7eLJR7xBjZ9p0LPdZ5E8SnL /ggIW7b71J5VTIaP4Vn2VpegyhfOdrZAOftvRWaMQvl0qQff9e4k1gcKL0Q5m1nQyYmD of0Dp9xIY+B2jpABCxLVuzlKjGJ2v8Kz02vM2eDGH8i4scS6Di5LfxrfjBu5CGNjfSf6 uL6Yxu//xO8iqzlppDTSz00gGcfj0eFGtQ4Amo/rgx174VO2kZlPWqYKHvMzwzyAHzkv B7bCsY15M83wziv/bW8yXg7aWM4Bg2WQcodxwGl0C2lCjq9nHqURpVrB0CAR4xhF+ylv LY+Q== X-Gm-Message-State: AMke39nRv+R5jGGttb6EPrY9vqan0BZIkr1ccogh5puiI181X49UQPqIT7Xz6EiL7Ut6UQ== X-Received: by 10.28.189.135 with SMTP id n129mr7522300wmf.92.1487161720253; Wed, 15 Feb 2017 04:28:40 -0800 (PST) Received: from [192.168.11.11] (225.55.208.46.dyn.plus.net. [46.208.55.225]) by smtp.googlemail.com with ESMTPSA id y1sm5200459wme.15.2017.02.15.04.28.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 15 Feb 2017 04:28:39 -0800 (PST) To: Takashi Iwai References: <6d7c74b7-da90-5ae9-c355-c6884b2edf09@gmail.com> From: Alan Young Message-ID: Date: Wed, 15 Feb 2017 12:28:38 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: alsa-devel@alsa-project.org Subject: Re: [alsa-devel] [PATCH] [updated] pcm: rate: Add capability to pass configuration node to plugins X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP On 14/02/17 07:30, Alan Young wrote: > However, looking at that again now, I see that the test is flawed > because it has no marker to check that it is only applied on the first > iteration, so the loop would always stop after testing the second > alternative. I could fix that or remove the test altogether - what do > you think? Here is an updated patch with a more robust check. Alan. From e27a479d48e86313b868c1f23261f7dcdf68bf82 Mon Sep 17 00:00:00 2001 From: Alan Young Date: Thu, 7 Apr 2016 09:15:04 +0100 Subject: [PATCH] pcm: rate: Add capability to pass configuration node to plugins If a rate plugin uses a node (compound) instead of a plain string for its "converter" then that compound will be passed as an additional parameter to the new plugin open() function (SND_PCM_RATE_PLUGIN_CONF_ENTRY(XXX)). The previous open() function (SND_PCM_RATE_PLUGIN_ENTRY(XXX)) will be called if the CONF version is not found. It is up to the plugin to determine whether the presence of the conf parameter is mandatory. The existing behaviour of using the first (usable) plain string value, regardless of parameter name, within the configuration node as the converter name is unchanged. Signed-off-by: Alan Young --- include/pcm_rate.h | 5 ++++- src/pcm/pcm_rate.c | 51 ++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/include/pcm_rate.h b/include/pcm_rate.h index 4d70df2..da278ac 100644 --- a/include/pcm_rate.h +++ b/include/pcm_rate.h @@ -120,11 +120,14 @@ typedef struct snd_pcm_rate_ops { typedef int (*snd_pcm_rate_open_func_t)(unsigned int version, void **objp, snd_pcm_rate_ops_t *opsp); +typedef int (*snd_pcm_rate_open_conf_func_t)(unsigned int version, void **objp, + snd_pcm_rate_ops_t *opsp, const snd_config_t *conf); + /** * Define the object entry for external PCM rate-converter plugins */ #define SND_PCM_RATE_PLUGIN_ENTRY(name) _snd_pcm_rate_##name##_open - +#define SND_PCM_RATE_PLUGIN_CONF_ENTRY(name) _snd_pcm_rate_##name##_open_conf #ifndef DOC_HIDDEN /* old rate_ops for protocol version 0x010001 */ diff --git a/src/pcm/pcm_rate.c b/src/pcm/pcm_rate.c index cbb7618..90a00fb 100644 --- a/src/pcm/pcm_rate.c +++ b/src/pcm/pcm_rate.c @@ -1249,6 +1249,9 @@ const snd_config_t *snd_pcm_rate_get_default_converter(snd_config_t *root) } #ifdef PIC + +#include /* for isdigit() */ + static int is_builtin_plugin(const char *type) { return strcmp(type, "linear") == 0; @@ -1258,26 +1261,48 @@ static const char *const default_rate_plugins[] = { "speexrate", "linear", NULL }; -static int rate_open_func(snd_pcm_rate_t *rate, const char *type, int verbose) +static int rate_open_func(snd_pcm_rate_t *rate, const char *type, const snd_config_t *converter_conf, int verbose) { - char open_name[64], lib_name[128], *lib = NULL; + char open_name[64], open_conf_name[64], lib_name[128], *lib = NULL; snd_pcm_rate_open_func_t open_func; + snd_pcm_rate_open_conf_func_t open_conf_func; int err; snprintf(open_name, sizeof(open_name), "_snd_pcm_rate_%s_open", type); + snprintf(open_conf_name, sizeof(open_conf_name), "_snd_pcm_rate_%s_open_conf", type); if (!is_builtin_plugin(type)) { snprintf(lib_name, sizeof(lib_name), "%s/libasound_module_rate_%s.so", ALSA_PLUGIN_DIR, type); lib = lib_name; } + + rate->rate_min = SND_PCM_PLUGIN_RATE_MIN; + rate->rate_max = SND_PCM_PLUGIN_RATE_MAX; + rate->plugin_version = SND_PCM_RATE_PLUGIN_VERSION; + + open_conf_func = snd_dlobj_cache_get(lib, open_conf_name, NULL, verbose); + if (open_conf_func) { + err = open_conf_func(SND_PCM_RATE_PLUGIN_VERSION, + &rate->obj, &rate->ops, converter_conf); + if (!err) { + rate->plugin_version = rate->ops.version; + if (rate->ops.get_supported_rates) + rate->ops.get_supported_rates(rate->obj, + &rate->rate_min, + &rate->rate_max); + rate->open_func = open_conf_func; + return 0; + } else { + snd_dlobj_cache_put(open_conf_func); + return err; + } + } + open_func = snd_dlobj_cache_get(lib, open_name, NULL, verbose); if (!open_func) return -ENOENT; rate->open_func = open_func; - rate->rate_min = SND_PCM_PLUGIN_RATE_MIN; - rate->rate_max = SND_PCM_PLUGIN_RATE_MAX; - rate->plugin_version = SND_PCM_RATE_PLUGIN_VERSION; err = open_func(SND_PCM_RATE_PLUGIN_VERSION, &rate->obj, &rate->ops); if (!err) { @@ -1353,23 +1378,26 @@ int snd_pcm_rate_open(snd_pcm_t **pcmp, const char *name, if (!converter) { const char *const *types; for (types = default_rate_plugins; *types; types++) { - err = rate_open_func(rate, *types, 0); + err = rate_open_func(rate, *types, NULL, 0); if (!err) { type = *types; break; } } } else if (!snd_config_get_string(converter, &type)) - err = rate_open_func(rate, type, 1); + err = rate_open_func(rate, type, NULL, 1); else if (snd_config_get_type(converter) == SND_CONFIG_TYPE_COMPOUND) { snd_config_iterator_t i, next; snd_config_for_each(i, next, converter) { snd_config_t *n = snd_config_iterator_entry(i); + const char *id; if (snd_config_get_string(n, &type) < 0) break; - err = rate_open_func(rate, type, 0); + err = rate_open_func(rate, type, converter, 0); if (!err) break; + if (snd_config_get_id(n, &id) >= 0 && id && !isdigit(*id)) + break; /* not a simple array of types */ } } else { SNDERR("Invalid type for rate converter"); @@ -1386,7 +1414,7 @@ int snd_pcm_rate_open(snd_pcm_t **pcmp, const char *name, #else type = "linear"; open_func = SND_PCM_RATE_PLUGIN_ENTRY(linear); - err = open_func(SND_PCM_RATE_PLUGIN_VERSION, &rate->obj, &rate->ops); + err = open_func(SND_PCM_RATE_PLUGIN_VERSION, &rate->obj, &rate->ops, 0); if (err < 0) { snd_pcm_free(pcm); free(rate); @@ -1439,6 +1467,11 @@ pcm.name { converter [ STR1 STR2 ... ] # optional # Converter type, default is taken from # defaults.pcm.rate_converter + # or + converter { # optional + name STR # Convertor type + xxx yyy # optional convertor-specific configuration + } } \endcode -- 2.5.5