xref: /haiku/src/add-ons/kernel/drivers/audio/usb/Stream.h (revision b785b0cf1ccb28e2a40bf5ef797c98b112534edf)
1a69892caSSiarzhuk Zharski /*
2a69892caSSiarzhuk Zharski  *	Driver for USB Audio Device Class devices.
3a69892caSSiarzhuk Zharski  *	Copyright (c) 2009-13 S.Zharski <imker@gmx.li>
4a69892caSSiarzhuk Zharski  *	Distributed under the terms of the MIT license.
5a69892caSSiarzhuk Zharski  *
6a69892caSSiarzhuk Zharski  */
7a69892caSSiarzhuk Zharski #ifndef _USB_AUDIO_STREAM_H_
8a69892caSSiarzhuk Zharski #define _USB_AUDIO_STREAM_H_
9a69892caSSiarzhuk Zharski 
10a69892caSSiarzhuk Zharski 
11a69892caSSiarzhuk Zharski #include "AudioStreamingInterface.h"
12a69892caSSiarzhuk Zharski 
13a69892caSSiarzhuk Zharski 
14a69892caSSiarzhuk Zharski class Device;
15a69892caSSiarzhuk Zharski 
16a69892caSSiarzhuk Zharski class Stream : public AudioStreamingInterface {
17a69892caSSiarzhuk Zharski 	friend	class			Device;
18a69892caSSiarzhuk Zharski public:
19a69892caSSiarzhuk Zharski 							Stream(Device* device, size_t interface,
20a69892caSSiarzhuk Zharski 								usb_interface_list* List);
21a69892caSSiarzhuk Zharski 							~Stream();
22a69892caSSiarzhuk Zharski 
23a69892caSSiarzhuk Zharski 			status_t		Init();
InitCheck()24a69892caSSiarzhuk Zharski 			status_t		InitCheck() { return fStatus; }
25a69892caSSiarzhuk Zharski 
26a69892caSSiarzhuk Zharski 			status_t		Start();
27a69892caSSiarzhuk Zharski 			status_t		Stop();
IsRunning()28a69892caSSiarzhuk Zharski 			bool			IsRunning() { return fIsRunning; }
29a69892caSSiarzhuk Zharski 			void			OnRemove();
30a69892caSSiarzhuk Zharski 
31a69892caSSiarzhuk Zharski 			status_t		GetBuffers(multi_buffer_list* List);
32a69892caSSiarzhuk Zharski 
33a69892caSSiarzhuk Zharski 			status_t		OnSetConfiguration(usb_device device,
34a69892caSSiarzhuk Zharski 							const usb_configuration_info* config);
35a69892caSSiarzhuk Zharski 
36a69892caSSiarzhuk Zharski 			bool			ExchangeBuffer(multi_buffer_info* Info);
37a69892caSSiarzhuk Zharski 			status_t		GetEnabledChannels(uint32& offset,
38a69892caSSiarzhuk Zharski 								multi_channel_enable* Enable);
39a69892caSSiarzhuk Zharski 			status_t		SetEnabledChannels(uint32& offset,
40a69892caSSiarzhuk Zharski 								multi_channel_enable* Enable);
41a69892caSSiarzhuk Zharski 			status_t		GetGlobalFormat(multi_format_info* Format);
42a69892caSSiarzhuk Zharski 			status_t		SetGlobalFormat(multi_format_info* Format);
43a69892caSSiarzhuk Zharski 
44a69892caSSiarzhuk Zharski protected:
45a69892caSSiarzhuk Zharski 			Device*			fDevice;
46a69892caSSiarzhuk Zharski 			status_t		fStatus;
47a69892caSSiarzhuk Zharski 
48a69892caSSiarzhuk Zharski 			usb_pipe		fStreamEndpoint;
4934352671SAugustin Cavalier 
50a69892caSSiarzhuk Zharski 			bool			fIsRunning;
517b2bc835SAugustin Cavalier 			area_id			fArea, fKernelArea;
52a69892caSSiarzhuk Zharski 			size_t			fAreaSize;
53a69892caSSiarzhuk Zharski 			usb_iso_packet_descriptor* fDescriptors;
54a69892caSSiarzhuk Zharski 			size_t			fDescriptorsCount;
557b2bc835SAugustin Cavalier 			uint8*			fBuffers;
567b2bc835SAugustin Cavalier 			uint8*			fKernelBuffers;
57a69892caSSiarzhuk Zharski 			size_t			fCurrentBuffer;
58a69892caSSiarzhuk Zharski 			size_t			fSamplesCount;
5934352671SAugustin Cavalier 
60*b99d228dSAugustin Cavalier 			bigtime_t		fRealTime;
6134352671SAugustin Cavalier 			uint32			fStartingFrame;
62a69892caSSiarzhuk Zharski 			int32			fProcessedBuffers;
63a69892caSSiarzhuk Zharski 			int32			fInsideNotify;
64a69892caSSiarzhuk Zharski 
65a69892caSSiarzhuk Zharski private:
66a69892caSSiarzhuk Zharski 			status_t		_ChooseAlternate();
67a69892caSSiarzhuk Zharski 			status_t		_SetupBuffers();
68a69892caSSiarzhuk Zharski 			status_t		_QueueNextTransfer(size_t buffer, bool start);
69222b10cbSSiarzhuk Zharski 	static	void			_TransferCallback(void* cookie, status_t status,
70222b10cbSSiarzhuk Zharski 								void* data, size_t actualLength);
71a69892caSSiarzhuk Zharski 			void			_DumpDescriptors();
72a69892caSSiarzhuk Zharski };
73a69892caSSiarzhuk Zharski 
74a69892caSSiarzhuk Zharski 
75a69892caSSiarzhuk Zharski #endif // _USB_AUDIO_STREAM_H_
76a69892caSSiarzhuk Zharski 
77