From patchwork Mon Feb 13 17:20:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Young X-Patchwork-Id: 9570425 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 0EF8E60572 for ; Mon, 13 Feb 2017 17:20:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F145B26E97 for ; Mon, 13 Feb 2017 17:20:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E60DA271CB; Mon, 13 Feb 2017 17:20:20 +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=-0.5 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, RDNS_NONE, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (unknown [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E24626E97 for ; Mon, 13 Feb 2017 17:20:20 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 272D6266A99; Mon, 13 Feb 2017 18:20:08 +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 24C65266DE2; Mon, 13 Feb 2017 18:20:06 +0100 (CET) Received: from mail-wm0-f41.google.com (mail-wm0-f41.google.com [74.125.82.41]) by alsa0.perex.cz (Postfix) with ESMTP id A30642669C8 for ; Mon, 13 Feb 2017 18:20:03 +0100 (CET) Received: by mail-wm0-f41.google.com with SMTP id r141so99628104wmg.1 for ; Mon, 13 Feb 2017 09:20:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to; bh=Vd3HgZ1zbcObjTdDtB7g3OLXR9Drpv34Bd6vv4b8H8Y=; b=b/u9QaSXclYxwA7kYMAtFNNI4iUDFW2OYFwgqmHxw3bwSBgryNVtkzcLmtqHJTRn8S AyLSTgwRUrk9fWWaP074TD5ZcgTLxNE9Ldg5zlfsKSo4+Tj1LiuKSB8XDrswjd7LrGsf G1dsIjMWXKKfzHRZkJVdHe7V1tunTLGlhr9flI8lo0SSB3iW4uRh24gxHrcnBb+c8pOK UJ/TlhbS98UxoeanbVBhVFEivHiAjFh/rQVsBWqKLB90pEc/U6FXte4TyPvcwIVmWhkF KZf0i9YxDf1ucXuPmB1oQmHJW8cimRt1/a/QJWNWWnIZN+WilmNzMkU64wTdNOWRYIOf dKqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to; bh=Vd3HgZ1zbcObjTdDtB7g3OLXR9Drpv34Bd6vv4b8H8Y=; b=fHyecfp98jtlcCm4pXL3Q9RnCezkbJUIRc5uWhcR09kId7w6Fbod/ZtJ5G9votHoof y9Vox6QKo/MiYDNBwU+WxeL0J+zKb4iO6JS0IRWwaMiIRfP7XNiQwtSWSBpYbseXIYUh RJWXRtQTr8YOnDpZ+LEta1xW/9sSMECf521xCk6nDwIn/arkNsXdjIx7iqEN2fRPJHeH cY6icOI+RGayiHD4VV5F6yjCodcOASlMEK7xHbwc2C4DeexaSKNNgYt3Ja1wqw99d69V PfFEYLeuSBG3mwxHG0+4DjZL9a2zjjkZPNm+3UYh3jmPG8fdWIrQBSrggRg5CBQwUK2z uUiw== X-Gm-Message-State: AMke39kHV7iMccgUcZdy/lqAqbzrdKgC0JLtHmcrHb60zokzMYHMrONURRgTnDlTWd2Yeg== X-Received: by 10.28.135.82 with SMTP id j79mr37781187wmd.19.1487006402961; Mon, 13 Feb 2017 09:20:02 -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 o22sm14676723wro.2.2017.02.13.09.20.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Feb 2017 09:20:02 -0800 (PST) To: Takashi Iwai References: <6d7c74b7-da90-5ae9-c355-c6884b2edf09@gmail.com> From: Alan Young Message-ID: Date: Mon, 13 Feb 2017 17:20:01 +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: [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 Here is a revised patch. It is useful for the converter used by a rate plugin to be capable of receiving configuration. This patch enables the "converter" node of the configuration of a "type rate" plugin to be specified as a compound and passed to open func of the converter plugin. The SND_PCM_RATE_PLUGIN_CONF_ENTRY macro is used to define a rate converter plugin entry point that takes the additional snd_config_t *conf parameter. If a rate converter plugin also supports the existing SND_PCM_RATE_PLUGIN_ENTRY entry point, or if passed conf parameter is NULL then it is up to the plugin to determine whether or not this is a fatal condition. Alan. From 28ce5b014c922a95f9398fad47c7c02fca94665c 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 | 48 +++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 43 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..bbfe4b1 100644 --- a/src/pcm/pcm_rate.c +++ b/src/pcm/pcm_rate.c @@ -1258,26 +1258,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 +1375,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 && strcmp(id, "0") != 0) + break; /* not a simple array of types */ } } else { SNDERR("Invalid type for rate converter"); @@ -1386,7 +1411,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 +1464,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