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