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

Commit 004ecee

Browse files
author
Miguel Gaio
committed
Add support for TLV Bytes Control
Alsa Bytes Control mixer can be reached using TLV methods. This allows Bytes Control to be greater than 512 bytes. Add support for read/write TLV access methods. Signed-off-by: Miguel Gaio <miguel.gaio@intel.com>
1 parent 385ce72 commit 004ecee

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

legacy/LegacyAmixerControl.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,20 @@
3737
#include <assert.h>
3838
#include <string.h>
3939
#include <string>
40+
#include <vector>
4041
#include <errno.h>
4142
#include <ctype.h>
4243
#include <alsa/asoundlib.h>
4344
#include <sstream>
4445

46+
/* from sound/asound.h, header is not compatible with alsa/asoundlib.h
47+
*/
48+
struct snd_ctl_tlv {
49+
unsigned int numid; /* control element numeric identification */
50+
unsigned int length; /* in bytes aligned to 4 */
51+
unsigned char tlv[]; /* first TLV */
52+
};
53+
4554

4655
#define base AmixerControl
4756

@@ -172,6 +181,31 @@ bool LegacyAmixerControl::accessHW(bool receive, std::string &error)
172181

173182
if (receive) {
174183

184+
// Special hook for TLV Bytes Control
185+
if ((eType == SND_CTL_ELEM_TYPE_BYTES) &&
186+
snd_ctl_elem_info_is_tlv_readable(info)) {
187+
188+
std::vector<unsigned char> rawTlv(sizeof(struct snd_ctl_tlv) + elementCount);
189+
190+
struct snd_ctl_tlv *tlv = reinterpret_cast<struct snd_ctl_tlv *>(rawTlv.data());
191+
192+
ret = snd_ctl_elem_tlv_read(sndCtrl, id, reinterpret_cast<unsigned int *>(tlv),
193+
rawTlv.size());
194+
if (ret < 0) {
195+
196+
error = "ALSA: Unable to read element " + controlName +
197+
": " + snd_strerror(ret);
198+
199+
} else {
200+
blackboardWrite(tlv->tlv, elementCount);
201+
}
202+
203+
// Close sound control
204+
snd_ctl_close(sndCtrl);
205+
206+
return ret == 0;
207+
}
208+
175209
// Read element
176210
if ((ret = snd_ctl_elem_read(sndCtrl, control)) < 0) {
177211

@@ -221,6 +255,32 @@ bool LegacyAmixerControl::accessHW(bool receive, std::string &error)
221255

222256
} else {
223257

258+
// Special hook for TLV Bytes Control
259+
if ((eType == SND_CTL_ELEM_TYPE_BYTES) &&
260+
snd_ctl_elem_info_is_tlv_writable(info)) {
261+
262+
std::vector<unsigned char> rawTlv(sizeof(struct snd_ctl_tlv) + elementCount);
263+
264+
struct snd_ctl_tlv *tlv = reinterpret_cast<struct snd_ctl_tlv *>(rawTlv.data());
265+
266+
tlv->numid = 0;
267+
tlv->length = elementCount;
268+
269+
blackboardRead(tlv->tlv, elementCount);
270+
271+
ret = snd_ctl_elem_tlv_write(sndCtrl, id, reinterpret_cast<unsigned int *>(tlv));
272+
if (ret < 0) {
273+
274+
error = "ALSA: Unable to write element " + controlName +
275+
": " + snd_strerror(ret);
276+
}
277+
278+
// Close sound control
279+
snd_ctl_close(sndCtrl);
280+
281+
return ret == 0;
282+
}
283+
224284
// Go through all indexes
225285
for (index = 0; index < elementCount; index++) {
226286

0 commit comments

Comments
 (0)