xref: /haiku/src/add-ons/kernel/drivers/audio/usb/Device.h (revision 220d04022750f40f8bac8f01fa551211e28d04f2)
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_DEVICE_H_
8 #define _USB_AUDIO_DEVICE_H_
9 
10 
11 #include "AudioControlInterface.h"
12 #include "Stream.h"
13 
14 
15 class Device {
16 	friend	class			Stream;
17 
18 public:
19 							Device(usb_device device);
20 	virtual					~Device();
21 
22 			status_t		InitCheck() { return fStatus; };
23 
24 			status_t		Open(uint32 flags);
25 			bool			IsOpen() { return fOpen; };
26 
27 			status_t		Close();
28 			status_t		Free();
29 
30 			status_t		Read(uint8* buffer, size_t* numBytes);
31 			status_t		Write(const uint8* buffer, size_t* numBytes);
32 			status_t		Control(uint32 op, void* buffer, size_t length);
33 
34 			void			Removed();
35 			bool			IsRemoved() { return fRemoved; };
36 
37 			status_t		CompareAndReattach(usb_device device);
38 	virtual	status_t		SetupDevice(bool deviceReplugged);
39 
40 			usb_device		USBDevice() { return fDevice; }
41 
42 			AudioControlInterface&
43 							AudioControl() { return fAudioControl; }
44 
45 private:
46 			status_t		_SetupEndpoints();
47 
48 // protected:
49 	virtual	status_t		StartDevice() { return B_OK; }
50 	virtual	status_t		StopDevice();
51 
52 			void			TraceMultiDescription(multi_description* Description,
53 								Vector<multi_channel_info>& Channels);
54 			void			TraceListMixControls(multi_mix_control_info* Info);
55 
56 		// state tracking
57 			status_t		fStatus;
58 			bool			fOpen;
59 			bool			fRemoved;
60 			usb_device		fDevice;
61 			uint16			fUSBVersion;
62 			uint16			fVendorID;
63 			uint16			fProductID;
64 	const	char*			fDescription;
65 			bool			fNonBlocking;
66 
67 			AudioControlInterface	fAudioControl;
68 			Vector<Stream*>	fStreams;
69 
70 // protected:
71 			status_t		_MultiGetDescription(multi_description* Description);
72 			status_t		_MultiGetEnabledChannels(multi_channel_enable* Enable);
73 			status_t		_MultiSetEnabledChannels(multi_channel_enable* Enable);
74 			status_t		_MultiGetBuffers(multi_buffer_list* List);
75 			status_t		_MultiGetGlobalFormat(multi_format_info* Format);
76 			status_t		_MultiSetGlobalFormat(multi_format_info* Format);
77 			status_t		_MultiGetMix(multi_mix_value_info* Info);
78 			status_t		_MultiSetMix(multi_mix_value_info* Info);
79 			status_t		_MultiListMixControls(multi_mix_control_info* Info);
80 			status_t		_MultiBufferExchange(multi_buffer_info* Info);
81 			status_t		_MultiBufferForceStop();
82 
83 			sem_id			fBuffersReadySem;
84 };
85 
86 
87 #endif // _USB_AUDIO_DEVICE_H_
88 
89