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

Commit b4ef15e

Browse files
author
Miguel Gaio
committed
LegacyAmixerControl: fix bytes control support mapped to component type
When bytes control is mapped to component type, PFW scalar size is the whole size of amixer bytes control, this does not match scalar size of a byte. Thus, the call of to/from Blackboard() calls can not be used. To handle this case, use blackboardWrite() and blackboardRead() for hw access. Signed-off-by: Miguel Gaio <[email protected]>
1 parent cb3a6b2 commit b4ef15e

File tree

1 file changed

+79
-55
lines changed

1 file changed

+79
-55
lines changed

legacy/LegacyAmixerControl.cpp

Lines changed: 79 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -217,40 +217,52 @@ 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-
}
220+
221+
if (eType == SND_CTL_ELEM_TYPE_BYTES) {
222+
const void *data = snd_ctl_elem_value_get_bytes(control);
244223

245224
if (isDebugEnabled()) {
246225

247-
// The "info" method has been shadowed by a local variable
248-
this->info() << "Reading alsa element " << controlName
249-
<< ", index " << index << " with value " << value;
226+
// The "info" method has been shadowed by a local variable
227+
this->info() << "Reading alsa element " << controlName;
250228
}
251229

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

256268
} else {
@@ -281,39 +293,51 @@ bool LegacyAmixerControl::accessHW(bool receive, std::string &error)
281293
return ret == 0;
282294
}
283295

284-
// Go through all indexes
285-
for (index = 0; index < elementCount; index++) {
296+
if (eType == SND_CTL_ELEM_TYPE_BYTES) {
297+
std::vector<unsigned char> rawData(elementCount);
286298

287-
// Read data from blackboard (beware this code is OK on Little Endian machines only)
288-
value = fromBlackboard();
299+
blackboardRead(rawData.data(), elementCount);
289300

290301
if (isDebugEnabled()) {
291302

292-
// The "info" method has been shadowed by a local variable
293-
this->info() << "Writing alsa element " << controlName
294-
<< ", index " << index << " with value " << value;
303+
// The "info" method has been shadowed by a local variable
304+
this->info() << "Writing alsa element " << controlName;
295305
}
296306

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 " +
307+
snd_ctl_elem_set_bytes(control, rawData.data(), elementCount);
308+
309+
} else {
310+
// Go through all indexes
311+
for (index = 0; index < elementCount; index++) {
312+
313+
// Read data from blackboard (beware this code is OK on Little Endian machines only)
314+
value = fromBlackboard();
315+
316+
if (isDebugEnabled()) {
317+
318+
// The "info" method has been shadowed by a local variable
319+
this->info() << "Writing alsa element " << controlName
320+
<< ", index " << index << " with value " << value;
321+
}
322+
323+
switch (eType) {
324+
case SND_CTL_ELEM_TYPE_BOOLEAN:
325+
snd_ctl_elem_value_set_boolean(control, index, value);
326+
break;
327+
case SND_CTL_ELEM_TYPE_INTEGER:
328+
snd_ctl_elem_value_set_integer(control, index, value);
329+
break;
330+
case SND_CTL_ELEM_TYPE_INTEGER64:
331+
snd_ctl_elem_value_set_integer64(control, index, value);
332+
break;
333+
case SND_CTL_ELEM_TYPE_ENUMERATED:
334+
snd_ctl_elem_value_set_enumerated(control, index, value);
335+
break;
336+
default:
337+
error = "ALSA: Unknown control element type while writing alsa element " +
315338
controlName;
316-
return false;
339+
return false;
340+
}
317341
}
318342
}
319343

0 commit comments

Comments
 (0)