From 3f813e47784674a3909fe1277bc10b70d03791e2 Mon Sep 17 00:00:00 2001 From: Pankaj Bharadiya Date: Mon, 9 Jan 2017 13:42:14 +0530 Subject: Fix the byte control set/get method The TLV byte controls expect a TLV header as well. Check for TLV access and add TLV header size before invoking mixer API. Change-Id: I12ba129e5bbc0676e80eb920e85b3683decfe0db Signed-off-by: Pawse, GuruprasadX Signed-off-by: Pankaj Bharadiya --- utils/tinymix.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'utils') diff --git a/utils/tinymix.c b/utils/tinymix.c index ff3ca7b..a7e7c05 100644 --- a/utils/tinymix.c +++ b/utils/tinymix.c @@ -192,6 +192,7 @@ static void tinymix_detail_control(struct mixer *mixer, const char *control) int min, max; int ret; char *buf = NULL; + unsigned int tlv_header_size = 0; if (isdigit(control[0])) ctl = mixer_get_ctl(mixer, atoi(control)); @@ -207,13 +208,16 @@ static void tinymix_detail_control(struct mixer *mixer, const char *control) num_values = mixer_ctl_get_num_values(ctl); if ((type == MIXER_CTL_TYPE_BYTE) && (num_values > 0)) { - buf = calloc(1, num_values); + if (mixer_ctl_is_access_tlv_rw(ctl) != 0) { + tlv_header_size = TLV_HEADER_SIZE; + } + buf = calloc(1, num_values + tlv_header_size); if (buf == NULL) { fprintf(stderr, "Failed to alloc mem for bytes %u\n", num_values); return; } - ret = mixer_ctl_get_array(ctl, buf, num_values); + ret = mixer_ctl_get_array(ctl, buf, num_values + tlv_header_size); if (ret < 0) { fprintf(stderr, "Failed to mixer_ctl_get_array\n"); free(buf); @@ -234,7 +238,8 @@ static void tinymix_detail_control(struct mixer *mixer, const char *control) tinymix_print_enum(ctl); break; case MIXER_CTL_TYPE_BYTE: - printf("%02x", buf[i]); + /* skip printing TLV header if exists */ + printf(" %02x", buf[i + tlv_header_size]); break; default: printf("unknown"); @@ -262,13 +267,25 @@ static void tinymix_set_byte_ctl(struct mixer_ctl *ctl, char *end; unsigned int i; long n; + unsigned int *tlv, tlv_size; + unsigned int tlv_header_size = 0; + + if (mixer_ctl_is_access_tlv_rw(ctl) != 0) { + tlv_header_size = TLV_HEADER_SIZE; + } - buf = calloc(1, num_values); + tlv_size = num_values + tlv_header_size; + + buf = calloc(1, tlv_size); if (buf == NULL) { fprintf(stderr, "set_byte_ctl: Failed to alloc mem for bytes %u\n", num_values); exit(EXIT_FAILURE); } + tlv = (unsigned int *)buf; + tlv[0] = 0; + tlv[1] = num_values; + for (i = 0; i < num_values; i++) { errno = 0; n = strtol(values[i], &end, 0); @@ -286,10 +303,11 @@ static void tinymix_set_byte_ctl(struct mixer_ctl *ctl, values[i]); goto fail; } - buf[i] = n; + /* start filling after tlv header */ + buf[i + tlv_header_size] = n; } - ret = mixer_ctl_set_array(ctl, buf, num_values); + ret = mixer_ctl_set_array(ctl, buf, tlv_size); if (ret < 0) { fprintf(stderr, "Failed to set binary control\n"); goto fail; -- cgit v1.2.3