Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 9fe36c6

Browse files
author
Miguel Gaio
committed
LegacyAmixerControl: fix bytes control support mapped to component type
When bytes control is mapped to component type, to/from Blackboard() calls can not be used. In this case, blackboard has to be accessed using blackboardWrite() and blackboardRead() Signed-off-by: Miguel Gaio <[email protected]>
1 parent cb3a6b2 commit 9fe36c6

File tree

1 file changed

+75
-64
lines changed

1 file changed

+75
-64
lines changed

legacy/LegacyAmixerControl.cpp

Lines changed: 75 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -217,40 +217,46 @@ bool LegacyAmixerControl::accessHW(bool receive, std::string &error)
217217

218218
return false;
219219
}
220-
// Go through all indexes
221-
for (index = 0; index < elementCount; index++) {
222-
223-
switch (eType) {
224-
case SND_CTL_ELEM_TYPE_BOOLEAN:
225-
value = snd_ctl_elem_value_get_boolean(control, index);
226-
break;
227-
case SND_CTL_ELEM_TYPE_INTEGER:
228-
value = snd_ctl_elem_value_get_integer(control, index);
229-
break;
230-
case SND_CTL_ELEM_TYPE_INTEGER64:
231-
value = snd_ctl_elem_value_get_integer64(control, index);
232-
break;
233-
case SND_CTL_ELEM_TYPE_ENUMERATED:
234-
value = snd_ctl_elem_value_get_enumerated(control, index);
235-
break;
236-
case SND_CTL_ELEM_TYPE_BYTES:
237-
value = snd_ctl_elem_value_get_byte(control, index);
238-
break;
239-
default:
240-
error = "ALSA: Unknown control element type while reading alsa element " +
241-
controlName;
242-
return false;
243-
}
244-
245-
if (isDebugEnabled()) {
246220

247-
// The "info" method has been shadowed by a local variable
248-
this->info() << "Reading alsa element " << controlName
249-
<< ", index " << index << " with value " << value;
221+
if (eType == SND_CTL_ELEM_TYPE_BYTES) {
222+
const void *data = snd_ctl_elem_value_get_bytes(control);
223+
224+
blackboardWrite(data, elementCount);
225+
226+
} else {
227+
228+
// Go through all indexes
229+
for (index = 0; index < elementCount; index++) {
230+
231+
switch (eType) {
232+
case SND_CTL_ELEM_TYPE_BOOLEAN:
233+
value = snd_ctl_elem_value_get_boolean(control, index);
234+
break;
235+
case SND_CTL_ELEM_TYPE_INTEGER:
236+
value = snd_ctl_elem_value_get_integer(control, index);
237+
break;
238+
case SND_CTL_ELEM_TYPE_INTEGER64:
239+
value = snd_ctl_elem_value_get_integer64(control, index);
240+
break;
241+
case SND_CTL_ELEM_TYPE_ENUMERATED:
242+
value = snd_ctl_elem_value_get_enumerated(control, index);
243+
break;
244+
default:
245+
error = "ALSA: Unknown control element type while reading alsa element " +
246+
controlName;
247+
return false;
248+
}
249+
250+
if (isDebugEnabled()) {
251+
252+
// The "info" method has been shadowed by a local variable
253+
this->info() << "Reading alsa element " << controlName
254+
<< ", index " << index << " with value " << value;
255+
}
256+
257+
// Write data to blackboard (beware this code is OK on Little Endian machines only)
258+
toBlackboard(value);
250259
}
251-
252-
// Write data to blackboard (beware this code is OK on Little Endian machines only)
253-
toBlackboard(value);
254260
}
255261

256262
} else {
@@ -281,39 +287,44 @@ bool LegacyAmixerControl::accessHW(bool receive, std::string &error)
281287
return ret == 0;
282288
}
283289

284-
// Go through all indexes
285-
for (index = 0; index < elementCount; index++) {
286-
287-
// Read data from blackboard (beware this code is OK on Little Endian machines only)
288-
value = fromBlackboard();
289-
290-
if (isDebugEnabled()) {
291-
292-
// The "info" method has been shadowed by a local variable
293-
this->info() << "Writing alsa element " << controlName
294-
<< ", index " << index << " with value " << value;
295-
}
296-
297-
switch (eType) {
298-
case SND_CTL_ELEM_TYPE_BOOLEAN:
299-
snd_ctl_elem_value_set_boolean(control, index, value);
300-
break;
301-
case SND_CTL_ELEM_TYPE_INTEGER:
302-
snd_ctl_elem_value_set_integer(control, index, value);
303-
break;
304-
case SND_CTL_ELEM_TYPE_INTEGER64:
305-
snd_ctl_elem_value_set_integer64(control, index, value);
306-
break;
307-
case SND_CTL_ELEM_TYPE_ENUMERATED:
308-
snd_ctl_elem_value_set_enumerated(control, index, value);
309-
break;
310-
case SND_CTL_ELEM_TYPE_BYTES:
311-
snd_ctl_elem_value_set_byte(control, index, value);
312-
break;
313-
default:
314-
error = "ALSA: Unknown control element type while writing alsa element " +
290+
if (eType == SND_CTL_ELEM_TYPE_BYTES) {
291+
std::vector<unsigned char> rawData(elementCount);
292+
293+
blackboardRead(rawData.data(), elementCount);
294+
snd_ctl_elem_set_bytes(control, rawData.data(), elementCount);
295+
296+
} else {
297+
// Go through all indexes
298+
for (index = 0; index < elementCount; index++) {
299+
300+
// Read data from blackboard (beware this code is OK on Little Endian machines only)
301+
value = fromBlackboard();
302+
303+
if (isDebugEnabled()) {
304+
305+
// The "info" method has been shadowed by a local variable
306+
this->info() << "Writing alsa element " << controlName
307+
<< ", index " << index << " with value " << value;
308+
}
309+
310+
switch (eType) {
311+
case SND_CTL_ELEM_TYPE_BOOLEAN:
312+
snd_ctl_elem_value_set_boolean(control, index, value);
313+
break;
314+
case SND_CTL_ELEM_TYPE_INTEGER:
315+
snd_ctl_elem_value_set_integer(control, index, value);
316+
break;
317+
case SND_CTL_ELEM_TYPE_INTEGER64:
318+
snd_ctl_elem_value_set_integer64(control, index, value);
319+
break;
320+
case SND_CTL_ELEM_TYPE_ENUMERATED:
321+
snd_ctl_elem_value_set_enumerated(control, index, value);
322+
break;
323+
default:
324+
error = "ALSA: Unknown control element type while writing alsa element " +
315325
controlName;
316-
return false;
326+
return false;
327+
}
317328
}
318329
}
319330

0 commit comments

Comments
 (0)