Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 89 additions & 53 deletions legacy/LegacyAmixerControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <ctype.h>
#include <alsa/asoundlib.h>
#include <sstream>
#include <numeric>

/* from sound/asound.h, header is not compatible with alsa/asoundlib.h
*/
Expand Down Expand Up @@ -217,40 +218,58 @@ bool LegacyAmixerControl::accessHW(bool receive, std::string &error)

return false;
}
// Go through all indexes
for (index = 0; index < elementCount; index++) {

switch (eType) {
case SND_CTL_ELEM_TYPE_BOOLEAN:
value = snd_ctl_elem_value_get_boolean(control, index);
break;
case SND_CTL_ELEM_TYPE_INTEGER:
value = snd_ctl_elem_value_get_integer(control, index);
break;
case SND_CTL_ELEM_TYPE_INTEGER64:
value = snd_ctl_elem_value_get_integer64(control, index);
break;
case SND_CTL_ELEM_TYPE_ENUMERATED:
value = snd_ctl_elem_value_get_enumerated(control, index);
break;
case SND_CTL_ELEM_TYPE_BYTES:
value = snd_ctl_elem_value_get_byte(control, index);
break;
default:
error = "ALSA: Unknown control element type while reading alsa element " +
controlName;
return false;
}

if (eType == SND_CTL_ELEM_TYPE_BYTES) {
const void *data = snd_ctl_elem_value_get_bytes(control);

if (isDebugEnabled()) {
const unsigned char *first = reinterpret_cast<const unsigned char *>(data);
const unsigned char *last = first + elementCount;

// The "info" method has been shadowed by a local variable
this->info() << "Reading alsa element " << controlName
<< ", index " << index << " with value " << value;
this->info() << "Reading alsa element " << controlName << ": "
<< std::accumulate(first, last, std::string{},
[](const std::string& a, std::vector<unsigned char>::value_type b) {
return a.empty() ? std::to_string(b) : a + ',' + std::to_string(b);
});
}

// Write data to blackboard (beware this code is OK on Little Endian machines only)
toBlackboard(value);
blackboardWrite(data, elementCount);

} else {

// Go through all indexes
for (index = 0; index < elementCount; index++) {

switch (eType) {
case SND_CTL_ELEM_TYPE_BOOLEAN:
value = snd_ctl_elem_value_get_boolean(control, index);
break;
case SND_CTL_ELEM_TYPE_INTEGER:
value = snd_ctl_elem_value_get_integer(control, index);
break;
case SND_CTL_ELEM_TYPE_INTEGER64:
value = snd_ctl_elem_value_get_integer64(control, index);
break;
case SND_CTL_ELEM_TYPE_ENUMERATED:
value = snd_ctl_elem_value_get_enumerated(control, index);
break;
default:
error = "ALSA: Unknown control element type while reading alsa element " +
controlName;
return false;
}

if (isDebugEnabled()) {

// The "info" method has been shadowed by a local variable
this->info() << "Reading alsa element " << controlName
<< ", index " << index << " with value " << value;
}

// Write data to blackboard (beware this code is OK on Little Endian machines only)
toBlackboard(value);
}
}

} else {
Expand Down Expand Up @@ -281,39 +300,56 @@ bool LegacyAmixerControl::accessHW(bool receive, std::string &error)
return ret == 0;
}

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

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

if (isDebugEnabled()) {

// The "info" method has been shadowed by a local variable
this->info() << "Writing alsa element " << controlName
<< ", index " << index << " with value " << value;
this->info() << "Writing alsa element " << controlName << ": "
<< std::accumulate(begin(rawData), end(rawData), std::string{},
[](const std::string& a, std::vector<unsigned char>::value_type b) {
return a.empty() ? std::to_string(b) : a + ',' + std::to_string(b);
});

}

switch (eType) {
case SND_CTL_ELEM_TYPE_BOOLEAN:
snd_ctl_elem_value_set_boolean(control, index, value);
break;
case SND_CTL_ELEM_TYPE_INTEGER:
snd_ctl_elem_value_set_integer(control, index, value);
break;
case SND_CTL_ELEM_TYPE_INTEGER64:
snd_ctl_elem_value_set_integer64(control, index, value);
break;
case SND_CTL_ELEM_TYPE_ENUMERATED:
snd_ctl_elem_value_set_enumerated(control, index, value);
break;
case SND_CTL_ELEM_TYPE_BYTES:
snd_ctl_elem_value_set_byte(control, index, value);
break;
default:
error = "ALSA: Unknown control element type while writing alsa element " +
snd_ctl_elem_set_bytes(control, rawData.data(), elementCount);

} else {
// Go through all indexes
for (index = 0; index < elementCount; index++) {

// Read data from blackboard (beware this code is OK on Little Endian machines only)
value = fromBlackboard();

if (isDebugEnabled()) {

// The "info" method has been shadowed by a local variable
this->info() << "Writing alsa element " << controlName
Copy link
Contributor

@dawagner dawagner May 12, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this patch, that log isn't produced in case of byte controls anymore. (Same issue applies when reading alsa byte controls).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but one bytes per line, if you have at worst 512 bytes is not really helpfull.
So just skip as done in TLV bytes control

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure but you could come up with a smarter way to log.

<< ", index " << index << " with value " << value;
}

switch (eType) {
case SND_CTL_ELEM_TYPE_BOOLEAN:
snd_ctl_elem_value_set_boolean(control, index, value);
break;
case SND_CTL_ELEM_TYPE_INTEGER:
snd_ctl_elem_value_set_integer(control, index, value);
break;
case SND_CTL_ELEM_TYPE_INTEGER64:
snd_ctl_elem_value_set_integer64(control, index, value);
break;
case SND_CTL_ELEM_TYPE_ENUMERATED:
snd_ctl_elem_value_set_enumerated(control, index, value);
break;
default:
error = "ALSA: Unknown control element type while writing alsa element " +
controlName;
return false;
return false;
}
}
}

Expand Down