From patchwork Tue Feb 21 16:14:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Young X-Patchwork-Id: 9585001 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 492556042F for ; Tue, 21 Feb 2017 16:14:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35D3228178 for ; Tue, 21 Feb 2017 16:14:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A49028582; Tue, 21 Feb 2017 16:14:42 +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 AE1F128178 for ; Tue, 21 Feb 2017 16:14:40 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 78777266D6C; Tue, 21 Feb 2017 17:14:37 +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 62BE9266D71; Tue, 21 Feb 2017 17:14:35 +0100 (CET) Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by alsa0.perex.cz (Postfix) with ESMTP id D1DD8266D6B for ; Tue, 21 Feb 2017 17:14:31 +0100 (CET) Received: by mail-wr0-f193.google.com with SMTP id 89so9108808wrr.1 for ; Tue, 21 Feb 2017 08:14:31 -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=OuxrUcFbuIeDj3MqsMe6vrQebLgBpnRjnmZlM5X5qio=; b=oUw7c5MO72p/wDKqlzcF/K26UyrT5z06wY5NfCdXQpxxQxLhVLT2gmlEg1SgqPshz4 uo//LO+iAIA2yBtNm8sYE6o6xM8PoeqTdyFCAreIr+Fmxd0NJgxWxHib9XJial5H89cW WIGGJQR8g2VWX3mFizE4crHJGxfZNhpecFaNveCI8HHdnPD8gro7I68FJjHA/cSSvwiu WgoGsIuIMCf4bo2NdQ/oxQfRnCKJ6ROiL5FVynRI4f/+OvoeZqda2cAcBlUjX0dhwlbI ntknmd/L3vYWVe/Dczvky8OzSiEfDJBKhZJgha1iuivBjhLD0Z1OypcpmUUNYFXQkjz2 9GEw== 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=OuxrUcFbuIeDj3MqsMe6vrQebLgBpnRjnmZlM5X5qio=; b=T58P4vPwldU7jNX9Hlusl9Ur2AEIg+ofZe/5ihHHpz2s1TsyAeuWL7CEmk3/bvjO/H +PfQfXNj2lm07mGOoN66C/Mfr2DFf0OWohYsnJ1CNXcFpDUxkBS30yMYkH4cIQ0+OCYR /eYhoqqm8zAfhP3Cyh1SUqS/ghqgwofoh+yRzJ5PBZvnGOc34o440nC0n7D28jIF7yma wfht5bwhLhogvT9oXgicbNrhAc9Lme9qZwqeCVsJ3EhVvFRTQmOr5yq/q4tXvdqtOrfq jkRE+JFZSdO6aUnG9Qw+BwB9Idw6LEO+puq/HVgG8wd8Quc+npXF7nLt/Zm4lJfLawqx p53w== X-Gm-Message-State: AMke39l2jAx5pSPjmZDj8ZImFfwIZa3dlwF8Iky6NphBiivwtjiHLNN6k6n0sQYNL5VoQg== X-Received: by 10.223.131.34 with SMTP id 31mr23319666wrd.119.1487693671188; Tue, 21 Feb 2017 08:14:31 -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 4sm3141551wrp.61.2017.02.21.08.14.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Feb 2017 08:14:30 -0800 (PST) To: Takashi Iwai References: <6d7c74b7-da90-5ae9-c355-c6884b2edf09@gmail.com> <7b3c655f-4b7a-e10a-90ff-5cb480332f3f@IEE.org> <3b8cd9c9-8248-b22a-ebb8-dce7d901951d@IEE.org> <2cb132c7-638b-6d93-621d-3460654660b8@IEE.org> From: Alan Young Message-ID: Date: Tue, 21 Feb 2017 16:14:29 +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 21/02/17 15:28, Takashi Iwai wrote: > You forgot to call > > snd_pcm_free(pcm); > free(rate); > > before returning an error. Ah, ok. Updated patch. From de90c659c98ae4dac7de6eb225b22147f56a3d1c 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", and that compound is not a simple string array, then the 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. Signed-off-by: Alan Young --- include/pcm_rate.h | 5 +++- src/pcm/pcm_rate.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 83 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..d439f4a 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 && converter_conf != NULL); + 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) { @@ -1301,6 +1323,30 @@ static int rate_open_func(snd_pcm_rate_t *rate, const char *type, int verbose) } #endif +/* + * If the conf is an array of alternatives then the id of + * the first element will be "0" (or maybe NULL). Otherwise assume it is + * a structure. + */ +static int is_string_array(const snd_config_t *conf) +{ + snd_config_iterator_t i; + + if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND) + return 0; + + i = snd_config_iterator_first(conf); + if (i && i != snd_config_iterator_end(conf)) { + snd_config_t *n = snd_config_iterator_entry(i); + const char *id; + snd_config_get_id(n, &id); + if (id && strcmp(id, "0") != 0) + return 0; + } + + return 1; +} + /** * \brief Creates a new rate PCM * \param pcmp Returns created PCM handle @@ -1353,24 +1399,43 @@ 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); - else if (snd_config_get_type(converter) == SND_CONFIG_TYPE_COMPOUND) { + err = rate_open_func(rate, type, NULL, 1); + else if (is_string_array(converter)) { snd_config_iterator_t i, next; snd_config_for_each(i, next, converter) { snd_config_t *n = snd_config_iterator_entry(i); if (snd_config_get_string(n, &type) < 0) break; - err = rate_open_func(rate, type, 0); + err = rate_open_func(rate, type, NULL, 0); if (!err) break; } + } + 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; + snd_config_get_id(n, &id); + if (strcmp(id, "name") != 0) + continue; + snd_config_get_string(n, &type); + break; + } + if (!type) { + SNDERR("No name given for rate converter"); + snd_pcm_free(pcm); + free(rate); + return -EINVAL; + } + err = rate_open_func(rate, type, converter, 1); } else { SNDERR("Invalid type for rate converter"); snd_pcm_free(pcm); @@ -1439,6 +1504,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