/
AudioStreamingInterface.h
162 lines (125 loc) · 3.86 KB
/
AudioStreamingInterface.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* Driver for USB Audio Device Class devices.
* Copyright (c) 2009-13 S.Zharski <imker@gmx.li>
* Distributed under the terms of the MIT license.
*
*/
#ifndef _AUDIO_STREAMING_INTERFACE_H_
#define _AUDIO_STREAMING_INTERFACE_H_
#include <USB3.h>
#include <util/VectorMap.h>
#include "AudioControlInterface.h"
class ASInterfaceDescriptor {
public:
ASInterfaceDescriptor(
usb_audio_streaming_interface_descriptor*
Descriptor);
~ASInterfaceDescriptor();
// protected:
uint8 fTerminalLink;
uint8 fDelay;
uint16 fFormatTag;
};
class ASEndpointDescriptor {
public:
ASEndpointDescriptor(
usb_endpoint_descriptor* Endpoint,
usb_audio_streaming_endpoint_descriptor*
Descriptor);
~ASEndpointDescriptor();
// protected:
uint8 fCSAttributes;
uint8 fLockDelayUnits;
uint16 fLockDelay;
uint16 fMaxPacketSize;
uint8 fEndpointAddress;
uint8 fEndpointAttributes;
};
class _ASFormatDescriptor {
public:
_ASFormatDescriptor(
usb_audio_format_descriptor* Descriptor);
virtual ~_ASFormatDescriptor();
// protected:
uint8 fFormatType;
static uint32 GetSamFreq(const usb_audio_sampling_freq& freq);
static usb_audio_sampling_freq GetSamFreq(uint32 rate);
};
class TypeIFormatDescriptor : public _ASFormatDescriptor {
public:
TypeIFormatDescriptor(
usb_audio_format_descriptor* Descriptor);
virtual ~TypeIFormatDescriptor();
status_t Init(usb_audio_format_descriptor* Descriptor);
// protected:
uint8 fNumChannels;
uint8 fSubframeSize;
uint8 fBitResolution;
uint8 fSampleFrequencyType;
Vector<uint32> fSampleFrequencies;
};
class TypeIIFormatDescriptor : public _ASFormatDescriptor {
public:
TypeIIFormatDescriptor(
usb_audio_format_descriptor* Descriptor);
virtual ~TypeIIFormatDescriptor();
// protected:
uint16 fMaxBitRate;
uint16 fSamplesPerFrame;
uint8 fSampleFrequencyType;
Vector<uint32> fSampleFrequencies;
};
class TypeIIIFormatDescriptor : public TypeIFormatDescriptor {
public:
TypeIIIFormatDescriptor(
usb_audio_format_descriptor* Descriptor);
virtual ~TypeIIIFormatDescriptor();
// protected:
};
class AudioStreamAlternate {
public:
AudioStreamAlternate(size_t alternate,
ASInterfaceDescriptor* interface,
ASEndpointDescriptor* endpoint,
_ASFormatDescriptor* format);
~AudioStreamAlternate();
ASInterfaceDescriptor* Interface() { return fInterface; }
ASEndpointDescriptor* Endpoint() { return fEndpoint; }
_ASFormatDescriptor* Format() { return fFormat; }
status_t SetSamplingRate(uint32 newRate);
status_t SetSamplingRateById(uint32 newId);
uint32 GetSamplingRate() { return fSamplingRate; }
uint32 GetSamplingRateId(uint32 rate);
uint32 GetSamplingRateIds();
uint32 GetFormatId();
status_t SetFormatId(uint32 newFormatId);
uint32 SamplingRateFromId(uint32 id);
protected:
size_t fAlternate;
ASInterfaceDescriptor* fInterface;
ASEndpointDescriptor* fEndpoint;
_ASFormatDescriptor* fFormat;
uint32 fSamplingRate;
};
class AudioStreamingInterface {
public:
AudioStreamingInterface(
AudioControlInterface* controlInterface,
size_t interface, usb_interface_list* List);
~AudioStreamingInterface();
// status_t InitCheck() { return fStatus; }
uint8 TerminalLink();
bool IsInput() { return fIsInput; }
AudioChannelCluster* ChannelCluster();
void GetFormatsAndRates(
multi_description* Description);
protected:
size_t fInterface;
AudioControlInterface* fControlInterface;
// status_t fStatus;
bool fIsInput;
// alternates of the streams
Vector<AudioStreamAlternate*> fAlternates;
size_t fActiveAlternate;
};
#endif // _AUDIO_STREAMING_INTERFACE_H_