All of lore.kernel.org
 help / color / mirror / Atom feed
From: han.lu@intel.com
To: patch@alsa-project.org
Cc: "Lu, Han" <han.lu@intel.com>, alsa-devel@alsa-project.org
Subject: [PATCH - UCM 2/2] ucm: add binary file parse
Date: Mon, 12 Jan 2015 13:21:17 +0800	[thread overview]
Message-ID: <1421040077-3494-2-git-send-email-han.lu@intel.com> (raw)
In-Reply-To: <1421040077-3494-1-git-send-email-han.lu@intel.com>

From: "Lu, Han" <han.lu@intel.com>

Signed-off-by: Lu, Han <han.lu@intel.com>

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 */
 };
 
 /*
-- 
1.9.1

  reply	other threads:[~2015-01-12  5:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-12  5:21 [PATCH - UCM 1/2] control: add hexadecimal parse han.lu
2015-01-12  5:21 ` han.lu [this message]
2015-01-12 14:50   ` [PATCH - UCM 2/2] ucm: add binary file parse Takashi Iwai
2015-01-13  3:04     ` Lu, Han
2015-01-12  7:50 ` [PATCH - UCM 1/2] control: add hexadecimal parse Takashi Iwai
2015-01-13  3:02   ` Lu, Han

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1421040077-3494-2-git-send-email-han.lu@intel.com \
    --to=han.lu@intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=patch@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.