Added support for IEC958

This commit is contained in:
Jaroslav Kysela 2000-12-22 11:25:11 +00:00
parent 84f294a3b9
commit 66608d67ea

View file

@ -200,6 +200,9 @@ static int get_control(snd_ctl_t *handle, snd_control_id_t *id, snd_config_t *to
case SND_CONTROL_TYPE_BYTES: case SND_CONTROL_TYPE_BYTES:
s = "bytes"; s = "bytes";
break; break;
case SND_CONTROL_TYPE_IEC958:
s = "iec958";
break;
default: default:
s = "unknown"; s = "unknown";
break; break;
@ -311,11 +314,14 @@ static int get_control(snd_ctl_t *handle, snd_control_id_t *id, snd_config_t *to
switch (info.type) { switch (info.type) {
case SND_CONTROL_TYPE_BYTES: case SND_CONTROL_TYPE_BYTES:
case SND_CONTROL_TYPE_IEC958:
{ {
char buf[info.values_count * 2 + 1]; int count = info.type == SND_CONTROL_TYPE_BYTES ?
info.values_count : sizeof(snd_aes_iec958_t);
char buf[count * 2 + 1];
char *p = buf; char *p = buf;
char *hex = "0123456789abcdef"; char *hex = "0123456789abcdef";
for (idx = 0; idx < info.values_count; idx++) { for (idx = 0; idx < count; idx++) {
int v = ctl.value.bytes.data[idx]; int v = ctl.value.bytes.data[idx];
*p++ = hex[v >> 4]; *p++ = hex[v >> 4];
*p++ = hex[v & 0x0f]; *p++ = hex[v & 0x0f];
@ -328,9 +334,6 @@ static int get_control(snd_ctl_t *handle, snd_control_id_t *id, snd_config_t *to
} }
return 0; return 0;
} }
case SND_CONTROL_TYPE_IEC958:
error("An IEC958 control ignored");
return 0;
default: default:
break; break;
} }
@ -748,42 +751,53 @@ static int set_control(snd_ctl_t *handle, snd_config_t *control)
goto _ok; goto _ok;
} }
break; break;
case SND_CONTROL_TYPE_BYTES:
case SND_CONTROL_TYPE_IEC958:
break;
default: default:
error("Unknow control type: %d", info.type); error("Unknow control type: %d", info.type);
return -EINVAL; return -EINVAL;
} }
} }
if (info.type == SND_CONTROL_TYPE_BYTES) { switch (info.type) {
char *buf; case SND_CONTROL_TYPE_BYTES:
err = snd_config_string_get(value, &buf); case SND_CONTROL_TYPE_IEC958:
if (err >= 0) { {
int c1 = 0; char *buf;
int len = strlen(buf); err = snd_config_string_get(value, &buf);
int idx = 0; if (err >= 0) {
if (info.values_count * 2 != len) { int c1 = 0;
error("bad control.%d.value contents\n", numid); int len = strlen(buf);
return -EINVAL; int idx = 0;
} int count = info.type == SND_CONTROL_TYPE_BYTES ?
while (*buf) { info.values_count : sizeof(snd_aes_iec958_t);
int c = *buf++; if (count * 2 != len) {
if (c >= '0' && c <= '9')
c -= '0';
else if (c <= 'a' && c <= 'f')
c = c - 'a' + 10;
else if (c <= 'A' && c <= 'F')
c = c - 'A' + 10;
else {
error("bad control.%d.value contents\n", numid); error("bad control.%d.value contents\n", numid);
return -EINVAL; return -EINVAL;
} }
idx++; while (*buf) {
if (idx % 2 == 0) int c = *buf++;
ctl.value.bytes.data[idx / 2] = c1 << 4 | c; if (c >= '0' && c <= '9')
else c -= '0';
c1 = c; else if (c <= 'a' && c <= 'f')
c = c - 'a' + 10;
else if (c <= 'A' && c <= 'F')
c = c - 'A' + 10;
else {
error("bad control.%d.value contents\n", numid);
return -EINVAL;
}
idx++;
if (idx % 2 == 0)
ctl.value.bytes.data[idx / 2] = c1 << 4 | c;
else
c1 = c;
}
goto _ok;
} }
goto _ok;
} }
default:
break;
} }
if (snd_config_type(value) != SND_CONFIG_TYPE_COMPOUND) { if (snd_config_type(value) != SND_CONFIG_TYPE_COMPOUND) {
error("bad control.%d.value type", numid); error("bad control.%d.value type", numid);
@ -826,6 +840,7 @@ static int set_control(snd_ctl_t *handle, snd_config_t *control)
ctl.value.enumerated.item[idx] = val; ctl.value.enumerated.item[idx] = val;
break; break;
case SND_CONTROL_TYPE_BYTES: case SND_CONTROL_TYPE_BYTES:
case SND_CONTROL_TYPE_IEC958:
err = snd_config_integer_get(n, &val); err = snd_config_integer_get(n, &val);
if (err < 0 || val < 0 || val > 255) { if (err < 0 || val < 0 || val > 255) {
error("bad control.%d.value.%d content", numid, idx); error("bad control.%d.value.%d content", numid, idx);