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 _USB_AUDIO_STREAM_H_ 8 #define _USB_AUDIO_STREAM_H_ 9 10 11 #include "AudioStreamingInterface.h" 12 13 14 class Device; 15 16 class Stream : public AudioStreamingInterface { 17 friend class Device; 18 public: 19 Stream(Device* device, size_t interface, 20 usb_interface_list* List); 21 ~Stream(); 22 23 status_t Init(); 24 status_t InitCheck() { return fStatus; } 25 26 status_t Start(); 27 status_t Stop(); 28 bool IsRunning() { return fIsRunning; } 29 void OnRemove(); 30 31 status_t GetBuffers(multi_buffer_list* List); 32 33 status_t OnSetConfiguration(usb_device device, 34 const usb_configuration_info* config); 35 36 bool ExchangeBuffer(multi_buffer_info* Info); 37 status_t GetEnabledChannels(uint32& offset, 38 multi_channel_enable* Enable); 39 status_t SetEnabledChannels(uint32& offset, 40 multi_channel_enable* Enable); 41 status_t GetGlobalFormat(multi_format_info* Format); 42 status_t SetGlobalFormat(multi_format_info* Format); 43 44 protected: 45 Device* fDevice; 46 status_t fStatus; 47 48 usb_pipe fStreamEndpoint; 49 50 bool fIsRunning; 51 area_id fArea, fKernelArea; 52 size_t fAreaSize; 53 usb_iso_packet_descriptor* fDescriptors; 54 size_t fDescriptorsCount; 55 uint8* fBuffers; 56 uint8* fKernelBuffers; 57 size_t fCurrentBuffer; 58 size_t fSamplesCount; 59 60 bigtime_t fRealTime; 61 uint32 fStartingFrame; 62 int32 fProcessedBuffers; 63 int32 fInsideNotify; 64 65 private: 66 status_t _ChooseAlternate(); 67 status_t _SetupBuffers(); 68 status_t _QueueNextTransfer(size_t buffer, bool start); 69 static void _TransferCallback(void* cookie, status_t status, 70 void* data, size_t actualLength); 71 void _DumpDescriptors(); 72 }; 73 74 75 #endif // _USB_AUDIO_STREAM_H_ 76 77