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