From patchwork Fri Dec 7 16:12:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Wischer X-Patchwork-Id: 10718489 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B789F1731 for ; Fri, 7 Dec 2018 16:12:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A51BE2DD05 for ; Fri, 7 Dec 2018 16:12:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 991F42DDB4; Fri, 7 Dec 2018 16:12:45 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham 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 921CB2DD05 for ; Fri, 7 Dec 2018 16:12:44 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 4D87E267D1F; Fri, 7 Dec 2018 17:12:36 +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 AFE18267D16; Fri, 7 Dec 2018 17:12:32 +0100 (CET) Received: from smtp1.de.adit-jv.com (smtp1.de.adit-jv.com [93.241.18.167]) by alsa0.perex.cz (Postfix) with ESMTP id D9F0A267D14 for ; Fri, 7 Dec 2018 17:12:27 +0100 (CET) Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id A85223C0022; Fri, 7 Dec 2018 17:12:27 +0100 (CET) Received: from smtp1.de.adit-jv.com ([127.0.0.1]) by localhost (smtp1.de.adit-jv.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 8ZyjBNXgxzD4; Fri, 7 Dec 2018 17:12:20 +0100 (CET) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id CAC203C02EF; Fri, 7 Dec 2018 17:12:20 +0100 (CET) Received: from vmlxhi-087.adit-jv.com (10.72.93.172) by HI2EXCH01.adit-jv.com (10.72.92.24) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 7 Dec 2018 17:12:20 +0100 From: To: Date: Fri, 7 Dec 2018 17:12:13 +0100 Message-ID: <1544199133-15051-2-git-send-email-twischer@de.adit-jv.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1544199133-15051-1-git-send-email-twischer@de.adit-jv.com> References: <1544199133-15051-1-git-send-email-twischer@de.adit-jv.com> MIME-Version: 1.0 X-Originating-IP: [10.72.93.172] Cc: Timo Wischer , alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH - extplug without conversion 1/1] pcm: extplug: Use same format and channels for slave 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 From: Timo Wischer if conversion is not supported by the implemented extplug. Currently only the parameters for client and slave PCM can be limited separately. But there is no dependency between this parameters. This patch allows the user to link both parameter sets also if snd_pcm_extplug_set_param*() was used to limit the capabilities of the plugin. Signed-off-by: Timo Wischer diff --git a/include/pcm_extplug.h b/include/pcm_extplug.h index e3b71bc..27ae848 100644 --- a/include/pcm_extplug.h +++ b/include/pcm_extplug.h @@ -31,6 +31,8 @@ #ifndef __ALSA_PCM_EXTPLUG_H #define __ALSA_PCM_EXTPLUG_H +#include + /** * \defgroup PCM_ExtPlug External Filter plugin SDK * \ingroup Plugin_SDK @@ -180,17 +182,25 @@ int snd_pcm_extplug_delete(snd_pcm_extplug_t *ext); void snd_pcm_extplug_params_reset(snd_pcm_extplug_t *ext); /* hw_parameter setting */ -int snd_pcm_extplug_set_param_list(snd_pcm_extplug_t *extplug, int type, unsigned int num_list, const unsigned int *list); -int snd_pcm_extplug_set_param_minmax(snd_pcm_extplug_t *extplug, int type, unsigned int min, unsigned int max); +int snd_pcm_extplug_set_param_list(snd_pcm_extplug_t *extplug, int type, + unsigned int num_list, + const unsigned int *list, + const bool conversion_supported); +int snd_pcm_extplug_set_param_minmax(snd_pcm_extplug_t *extplug, int type, + unsigned int min, unsigned int max, + const bool conversion_supported); int snd_pcm_extplug_set_slave_param_list(snd_pcm_extplug_t *extplug, int type, unsigned int num_list, const unsigned int *list); int snd_pcm_extplug_set_slave_param_minmax(snd_pcm_extplug_t *extplug, int type, unsigned int min, unsigned int max); /** * set the parameter constraint with a single value */ -static __inline__ int snd_pcm_extplug_set_param(snd_pcm_extplug_t *extplug, int type, unsigned int val) +static __inline__ int snd_pcm_extplug_set_param(snd_pcm_extplug_t *extplug, + int type, unsigned int val, + const bool conversion_supported) { - return snd_pcm_extplug_set_param_list(extplug, type, 1, &val); + return snd_pcm_extplug_set_param_list(extplug, type, 1, &val, + conversion_supported); } /** diff --git a/src/pcm/pcm_extplug.c b/src/pcm/pcm_extplug.c index 1004f54..d1c451e 100644 --- a/src/pcm/pcm_extplug.c +++ b/src/pcm/pcm_extplug.c @@ -41,6 +41,7 @@ const char *_snd_module_pcm_extplug = ""; typedef struct snd_pcm_extplug_priv { snd_pcm_plugin_t plug; snd_pcm_extplug_t *data; + bool conversion_supported[SND_PCM_EXTPLUG_HW_PARAMS]; struct snd_ext_parm params[SND_PCM_EXTPLUG_HW_PARAMS]; struct snd_ext_parm sparams[SND_PCM_EXTPLUG_HW_PARAMS]; } extplug_priv_t; @@ -232,7 +233,7 @@ static int snd_pcm_extplug_hw_refine_sprepare(snd_pcm_t *pcm, return 0; } -static unsigned int get_links(struct snd_ext_parm *params) +static unsigned int get_links(extplug_priv_t *ext, struct snd_ext_parm *params) { int i; unsigned int links = (SND_PCM_HW_PARBIT_FORMAT | @@ -249,7 +250,10 @@ static unsigned int get_links(struct snd_ext_parm *params) SND_PCM_HW_PARBIT_TICK_TIME); for (i = 0; i < SND_PCM_EXTPLUG_HW_PARAMS; i++) { - if (params[i].active) + /* only disable the link if the param is set and conversion is + * supported by the extplug + */ + if (params[i].active && ext->conversion_supported[i]) links &= ~excl_parbits[i]; } return links; @@ -260,7 +264,7 @@ static int snd_pcm_extplug_hw_refine_schange(snd_pcm_t *pcm, snd_pcm_hw_params_t *sparams) { extplug_priv_t *ext = pcm->private_data; - unsigned int links = get_links(ext->sparams); + unsigned int links = get_links(ext, ext->sparams); return _snd_pcm_hw_params_refine(sparams, links, params); } @@ -270,7 +274,7 @@ static int snd_pcm_extplug_hw_refine_cchange(snd_pcm_t *pcm, snd_pcm_hw_params_t *sparams) { extplug_priv_t *ext = pcm->private_data; - unsigned int links = get_links(ext->params); + unsigned int links = get_links(ext, ext->params); return _snd_pcm_hw_params_refine(params, links, sparams); } @@ -698,6 +702,9 @@ int snd_pcm_extplug_create(snd_pcm_extplug_t *extplug, const char *name, ext->data = extplug; extplug->stream = stream; + /* keep the old behaviour as default */ + for (int i = 0; i < SND_PCM_EXTPLUG_HW_PARAMS; i++) + ext->conversion_supported[i] = true; snd_pcm_plugin_init(&ext->plug); ext->plug.read = snd_pcm_extplug_read_areas; @@ -772,6 +779,11 @@ int snd_pcm_extplug_set_slave_param_list(snd_pcm_extplug_t *extplug, int type, u SNDERR("EXTPLUG: invalid parameter type %d", type); return -EINVAL; } + if (!ext->conversion_supported[type]) { + SNDERR("EXTPLUG: do not call %s(%d) if conversion is not supported", + __func__, type); + return -EINVAL; + } return snd_ext_parm_set_list(&ext->sparams[type], num_list, list); } @@ -798,6 +810,11 @@ int snd_pcm_extplug_set_slave_param_minmax(snd_pcm_extplug_t *extplug, int type, SNDERR("EXTPLUG: invalid parameter type %d", type); return -EINVAL; } + if (!ext->conversion_supported[type]) { + SNDERR("EXTPLUG: do not call %s(%d) if conversion is not supported", + __func__, type); + return -EINVAL; + } return snd_ext_parm_set_minmax(&ext->sparams[type], min, max); } @@ -807,19 +824,30 @@ int snd_pcm_extplug_set_slave_param_minmax(snd_pcm_extplug_t *extplug, int type, * \param type parameter type * \param num_list number of available values * \param list the list of available values + * \param conversion_supported set true if the extplug is capabile to convert + * to any slave format/channels (defined by type) * \return 0 if successful, or a negative error code * * Sets the master parameter as the list. * The available values of the given parameter type of this PCM (as input) is restricted * to the ones of the given list. */ -int snd_pcm_extplug_set_param_list(snd_pcm_extplug_t *extplug, int type, unsigned int num_list, const unsigned int *list) +int snd_pcm_extplug_set_param_list(snd_pcm_extplug_t *extplug, int type, + unsigned int num_list, + const unsigned int *list, + const bool conversion_supported) { extplug_priv_t *ext = extplug->pcm->private_data; if (type < 0 || type >= SND_PCM_EXTPLUG_HW_PARAMS) { SNDERR("EXTPLUG: invalid parameter type %d", type); return -EINVAL; } + if (!conversion_supported && ext->sparams[type].active) { + SNDERR("EXTPLUG: do not call snd_pcm_extplug_set_slave_param*(%d) if conversion is not supported", + type); + return -EINVAL; + } + ext->conversion_supported[type] = conversion_supported; return snd_ext_parm_set_list(&ext->params[type], num_list, list); } @@ -829,13 +857,17 @@ int snd_pcm_extplug_set_param_list(snd_pcm_extplug_t *extplug, int type, unsigne * \param type parameter type * \param min the minimum value * \param max the maximum value + * \param conversion_supported set true if the extplug is capabile to convert + * to any slave format/channels (defined by type) * \return 0 if successful, or a negative error code * * Sets the master parameter as the min/max values. * The available values of the given parameter type of this PCM (as input) is restricted * between the given minimum and maximum values. */ -int snd_pcm_extplug_set_param_minmax(snd_pcm_extplug_t *extplug, int type, unsigned int min, unsigned int max) +int snd_pcm_extplug_set_param_minmax(snd_pcm_extplug_t *extplug, int type, + unsigned int min, unsigned int max, + const bool conversion_supported) { extplug_priv_t *ext = extplug->pcm->private_data; if (type < 0 || type >= SND_PCM_EXTPLUG_HW_PARAMS) { @@ -846,6 +878,12 @@ int snd_pcm_extplug_set_param_minmax(snd_pcm_extplug_t *extplug, int type, unsig SNDERR("EXTPLUG: invalid parameter type %d", type); return -EINVAL; } + if (!conversion_supported && ext->sparams[type].active) { + SNDERR("EXTPLUG: do not call snd_pcm_extplug_set_slave_param*(%d) if conversion is not supported", + type); + return -EINVAL; + } + ext->conversion_supported[type] = conversion_supported; return snd_ext_parm_set_minmax(&ext->params[type], min, max); }