From patchwork Tue Jan 13 03:00:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: han.lu@intel.com X-Patchwork-Id: 5617501 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3FBAD9F3A0 for ; Tue, 13 Jan 2015 03:01:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 08D2F20600 for ; Tue, 13 Jan 2015 03:01:19 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id C4ECB205E8 for ; Tue, 13 Jan 2015 03:01:17 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id D202C261537; Tue, 13 Jan 2015 04:01:15 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NO_DNS_FOR_FROM, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id B6A1B26147E; Tue, 13 Jan 2015 04:00:57 +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 E5CF3261498; Tue, 13 Jan 2015 04:00:55 +0100 (CET) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by alsa0.perex.cz (Postfix) with ESMTP id 7035B26147E; Tue, 13 Jan 2015 04:00:45 +0100 (CET) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP; 12 Jan 2015 18:57:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.07,746,1413270000"; d="scan'208";a="636378078" Received: from hanlu-optiplex-9020.sh.intel.com ([10.239.13.38]) by orsmga001.jf.intel.com with ESMTP; 12 Jan 2015 19:00:43 -0800 From: han.lu@intel.com To: patch@alsa-project.org Date: Tue, 13 Jan 2015 11:00:39 +0800 Message-Id: <1421118039-8075-2-git-send-email-han.lu@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1421118039-8075-1-git-send-email-han.lu@intel.com> References: <1421118039-8075-1-git-send-email-han.lu@intel.com> Cc: "Lu, Han" , alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH - UCM 2/2] ucm: add binary configure file parse 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: "Lu, Han" with cset command, UCM set kcontrol parameters directly: cset "name='' 1,2<,3,...>" This patch enables UCM to set kcontrol with parameters from configure file: bcsetf "name='' " where "bcsetf" is a newly added keyword alongside of "cset", to indicate binary cset with file; and is the configure file storing parameters in bytes array, up to 512 Bytes (the maxim value that struct snd_ctl_elem_value can hold). Signed-off-by: Lu, Han diff --git a/src/ucm/main.c b/src/ucm/main.c index 37ae4c8..1496b22 100644 --- a/src/ucm/main.c +++ b/src/ucm/main.c @@ -160,11 +160,45 @@ static int open_ctl(snd_use_case_mgr_t *uc_mgr, return 0; } +static int binary_file_parse(snd_ctl_elem_value_t *dst, + const char *filepath) +{ + int err = 0; + FILE *in; + long len; + char *res; + unsigned int idx; + + in = fopen(filepath, "r"); + if (!in) { + err = -errno; + goto __fail; + } + fseek(in, 0L, SEEK_END); + len = ftell(in); + rewind(in); + if (len > 512) + len = 512; + res = calloc(1, (size_t)len); + if (res == NULL) { + err = -ENOMEM; + goto __fail_nomem; + } + fread(res, (size_t)len, 1, in); + for (idx = 0; idx < len; idx++) + snd_ctl_elem_value_set_byte(dst, idx, *(res + idx)); + free(res); + __fail_nomem: + fclose(in); + __fail: + return err; +} + extern int __snd_ctl_ascii_elem_id_parse(snd_ctl_elem_id_t *dst, const char *str, const char **ret_ptr); -static int execute_cset(snd_ctl_t *ctl, const char *cset) +static int execute_cset(snd_ctl_t *ctl, const char *cset, int isbin) { const char *pos; int err; @@ -194,7 +228,10 @@ static int execute_cset(snd_ctl_t *ctl, const char *cset) err = snd_ctl_elem_info(ctl, info); if (err < 0) goto __fail; - err = snd_ctl_ascii_value_parse(ctl, value, info, pos); + if (isbin) + err = binary_file_parse(value, pos); + else + err = snd_ctl_ascii_value_parse(ctl, value, info, pos); if (err < 0) goto __fail; err = snd_ctl_elem_write(ctl, value); @@ -239,6 +276,7 @@ static int execute_sequence(snd_use_case_mgr_t *uc_mgr, goto __fail_nomem; break; case SEQUENCE_ELEMENT_TYPE_CSET: + case SEQUENCE_ELEMENT_TYPE_BCSETF: if (cdev == NULL) { const char *cdev1 = NULL, *cdev2 = NULL; err = get_value3(&cdev1, "PlaybackCTL", @@ -274,7 +312,7 @@ static int execute_sequence(snd_use_case_mgr_t *uc_mgr, goto __fail; } } - err = execute_cset(ctl, s->data.cset); + err = execute_cset(ctl, s->data.cset, s->isbin); if (err < 0) { uc_error("unable to execute cset '%s'\n", s->data.cset); goto __fail; diff --git a/src/ucm/parser.c b/src/ucm/parser.c index d7517f6..686c883 100644 --- a/src/ucm/parser.c +++ b/src/ucm/parser.c @@ -306,6 +306,17 @@ static int parse_sequence(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED, continue; } + if (strcmp(cmd, "bcsetf") == 0) { + curr->type = SEQUENCE_ELEMENT_TYPE_BCSETF; + curr->isbin = 1; + err = parse_string(n, &curr->data.cset); + if (err < 0) { + uc_error("error: bcsetf requires a string!"); + return err; + } + continue; + } + if (strcmp(cmd, "usleep") == 0) { curr->type = SEQUENCE_ELEMENT_TYPE_SLEEP; err = snd_config_get_integer(n, &curr->data.sleep); diff --git a/src/ucm/ucm_local.h b/src/ucm/ucm_local.h index 87f14a2..80d7335 100644 --- a/src/ucm/ucm_local.h +++ b/src/ucm/ucm_local.h @@ -47,6 +47,7 @@ #define SEQUENCE_ELEMENT_TYPE_CSET 2 #define SEQUENCE_ELEMENT_TYPE_SLEEP 3 #define SEQUENCE_ELEMENT_TYPE_EXEC 4 +#define SEQUENCE_ELEMENT_TYPE_BCSETF 5 struct ucm_value { struct list_head list; @@ -63,6 +64,7 @@ struct sequence_element { char *cset; char *exec; } data; + int isbin; /* Indicate cset is binary array or ascii array */ }; /*