1/*
2 * Copyright (c) 1998-2010 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License").  You may not use this file except in compliance with the
9 * License.  Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23#ifndef _IOKIT_IOAUDIOENGINEUSERCLIENT_H
24#define _IOKIT_IOAUDIOENGINEUSERCLIENT_H
25
26#include <IOKit/IOUserClient.h>
27#ifndef IOAUDIOFAMILY_SELF_BUILD
28#include <IOKit/audio/IOAudioEngine.h>
29#include <IOKit/audio/IOAudioTypes.h>
30#else
31#include "IOAudioEngine.h"
32#include "IOAudioTypes.h"
33#endif
34#include <IOKit/IOBufferMemoryDescriptor.h>
35
36class IOAudioEngine;
37class IOAudioStream;
38class IOMemoryDescriptor;
39class IOCommandGate;
40class IOWorkLoop;
41
42class IOAudioEngineUserClient;
43class IOAudioClientBufferSet;
44struct IOAudioFormatNotification;
45
46typedef struct IOAudioClientBuffer
47{
48    IOAudioEngineUserClient		*userClient;
49    IOAudioStream 				*audioStream;
50    void						*sourceBuffer;
51    IOMemoryDescriptor			*sourceBufferDescriptor;
52    IOMemoryMap					*sourceBufferMap;
53    void						*unmappedSourceBuffer;
54    UInt32						numSampleFrames;
55    UInt32						numChannels;
56    IOAudioEnginePosition		mixedPosition;
57    struct IOAudioClientBuffer	*mNextBuffer32;
58    struct IOAudioClientBuffer	*nextClip;
59    struct IOAudioClientBuffer	*previousClip;
60    struct IOAudioClientBuffer	*nextClient;
61	IOAudioBufferDataDescriptor *bufferDataDescriptor;
62} IOAudioClientBuffer;
63
64/* IOAudioClientBuffer64 added for binary compatibility with old PPC drivers covered by <rdar://problem/4651809> */
65typedef struct IOAudioClientBuffer64
66{
67    IOAudioClientBuffer				mAudioClientBuffer32;
68    mach_vm_address_t				mUnmappedSourceBuffer64;
69    struct IOAudioClientBuffer64	*mNextBuffer64;
70} IOAudioClientBuffer64;
71
72typedef struct IOAudioClientBufferExtendedInfo
73{
74	// Added stuff for registerClientParameterBuffer
75	UInt32						bufferSetID;
76	void						*paramBuffer;
77	IOMemoryDescriptor			*paramBufferDescriptor;
78	IOMemoryMap					*paramBufferMap;
79	void						*unmappedParamBuffer;
80	struct IOAudioClientBufferExtendedInfo	*mNextExtended;
81} IOAudioClientBufferExtendedInfo;
82
83/* IOAudioClientBufferExtendedInfo64 added for binary compatibility with old PPC drivers covered by <rdar://problem/4651809>  */
84typedef struct IOAudioClientBufferExtendedInfo64
85{
86	IOAudioClientBufferExtendedInfo mAudioClientBufferExtended32;
87	mach_vm_address_t			mUnmappedParamBuffer64;
88	struct IOAudioClientBufferExtendedInfo64	*mNextExtended64;
89}	IOAudioClientBufferExtendedInfo64;
90
91
92class IOAudioEngineUserClient : public IOUserClient
93{
94	OSDeclareDefaultStructors(IOAudioEngineUserClient)
95
96	friend class IOAudioEngine;
97	friend class IOAudioClientBufferSet;
98	friend class IOAudioStream;
99
100protected:
101	IOAudioEngine				*audioEngine;
102
103	IOWorkLoop					*workLoop;
104	IOCommandGate				*commandGate;
105
106	IOExternalMethod			old_methods[5];		// It's size can't be changed for binary compatibility reasons, no longer used.
107	IOExternalTrap				trap;
108
109	task_t						clientTask;
110	UInt32						numSampleFrames;		// Never used...
111
112	IOAudioClientBufferSet		*clientBufferSetList;
113	IORecursiveLock 			*clientBufferLock;
114
115	IOAudioNotificationMessage	*notificationMessage;
116
117	bool						online;
118
119protected:
120	struct ExpansionData {
121		IOAudioClientBufferExtendedInfo64	*extendedInfo;
122		IOExternalMethod					methods[kIOAudioEngineNumCalls];		// This size can be changed, this is the new methods pointer
123		UInt32								classicMode;
124		UInt32								commandGateStatus;						// <rdar://8518215>
125		SInt32								commandGateUsage;						// <rdar://8518215>
126	};
127
128// <rdar://101000004> START
129	ExpansionData *reserved;
130
131public:
132	virtual IOReturn externalMethod( uint32_t selector, IOExternalMethodArguments * arguments, 	IOExternalMethodDispatch * dispatch,
133									OSObject * target, 	void * reference);
134	// New code added here...
135	// OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 0);
136	virtual IOReturn registerClientParameterBuffer (void * parameterBuffer, UInt32 bufferSetID);  // unused function
137	// OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 1);
138	virtual IOAudioClientBufferExtendedInfo * findExtendedInfo(UInt32 bufferSetID);
139	// OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 2);
140	virtual IOReturn getNearestStartTime(IOAudioStream *audioStream, IOAudioTimeStamp *ioTimeStamp, UInt32 isInput);
141	// OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 3);
142	virtual IOReturn getClientNearestStartTime(IOAudioStream *audioStream, IOAudioTimeStamp *ioTimeStamp, UInt32 isInput);
143	// OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 4);
144	virtual IOReturn safeRegisterClientBuffer(UInt32 audioStreamIndex, void * sourceBuffer, UInt32 bufSizeInBytes, UInt32 bufferSetID);
145	// OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 5);
146	virtual bool initWithAudioEngine(IOAudioEngine *engine, task_t task, void *securityToken, UInt32 type, OSDictionary *properties);
147	// OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 6);	<rdar://problems/5321701>
148	virtual IOReturn safeRegisterClientBuffer64(UInt32 audioStreamIndex, mach_vm_address_t * sourceBuffer, UInt32 bufSizeInBytes, UInt32 bufferSetID);
149	// OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 7);	<rdar://problems/5321701>
150	virtual IOReturn registerClientBuffer64(IOAudioStream *audioStream, mach_vm_address_t sourceBuffer, UInt32 bufSizeInBytes, UInt32 bufferSetID);
151	// OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 8);	<rdar://problems/5321701>
152	virtual IOReturn registerBuffer64(IOAudioStream *audioStream, mach_vm_address_t sourceBuffer, UInt32 bufSizeInBytes, UInt32 bufferSetID);
153	// OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 9);	<rdar://problems/5321701>
154	virtual IOReturn unregisterBuffer64(mach_vm_address_t sourceBuffer, UInt32 bufferSetID);
155	// OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 10);	<rdar://problems/5321701>
156	virtual IOReturn unregisterClientBuffer64(mach_vm_address_t  * sourceBuffer, UInt32 bufferSetID);
157	// OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 11);	 <rdar://problems/5321701>
158	virtual IOAudioClientBufferExtendedInfo64 * findExtendedInfo64(UInt32 bufferSetID);
159
160
161
162private:
163	OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 0);
164	OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 1);
165	OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 2);
166	OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 3);
167	OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 4);
168	OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 5);
169	OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 6);
170	OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 7);
171	OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 8);
172	OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 9);
173	OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 10);
174	OSMetaClassDeclareReservedUsed(IOAudioEngineUserClient, 11);
175
176
177	OSMetaClassDeclareReservedUnused(IOAudioEngineUserClient, 12);
178	OSMetaClassDeclareReservedUnused(IOAudioEngineUserClient, 13);
179	OSMetaClassDeclareReservedUnused(IOAudioEngineUserClient, 14);
180	OSMetaClassDeclareReservedUnused(IOAudioEngineUserClient, 15);
181	OSMetaClassDeclareReservedUnused(IOAudioEngineUserClient, 16);
182	OSMetaClassDeclareReservedUnused(IOAudioEngineUserClient, 17);
183	OSMetaClassDeclareReservedUnused(IOAudioEngineUserClient, 18);
184	OSMetaClassDeclareReservedUnused(IOAudioEngineUserClient, 19);
185	OSMetaClassDeclareReservedUnused(IOAudioEngineUserClient, 20);
186	OSMetaClassDeclareReservedUnused(IOAudioEngineUserClient, 21);
187	OSMetaClassDeclareReservedUnused(IOAudioEngineUserClient, 22);
188	OSMetaClassDeclareReservedUnused(IOAudioEngineUserClient, 23);
189	OSMetaClassDeclareReservedUnused(IOAudioEngineUserClient, 24);
190	OSMetaClassDeclareReservedUnused(IOAudioEngineUserClient, 25);
191	OSMetaClassDeclareReservedUnused(IOAudioEngineUserClient, 26);
192	OSMetaClassDeclareReservedUnused(IOAudioEngineUserClient, 27);
193	OSMetaClassDeclareReservedUnused(IOAudioEngineUserClient, 28);
194	OSMetaClassDeclareReservedUnused(IOAudioEngineUserClient, 29);
195	OSMetaClassDeclareReservedUnused(IOAudioEngineUserClient, 30);
196	OSMetaClassDeclareReservedUnused(IOAudioEngineUserClient, 31);
197
198protected:
199	virtual IOReturn clientClose();
200	virtual IOReturn clientDied();
201
202	static IOReturn _closeClientAction(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3);	// <rdar://7529580>
203	static IOReturn closeClientAction(OSObject *owner, void *arg1, void *arg2, void *arg3, void *arg4);
204	virtual IOReturn closeClient();
205
206
207	virtual IOReturn clientMemoryForType(UInt32 type, UInt32 *flags, IOMemoryDescriptor **memory);
208	virtual IOExternalMethod *getExternalMethodForIndex(UInt32 index);
209	virtual IOExternalTrap *getExternalTrapForIndex(UInt32 index);
210	virtual IOReturn registerNotificationPort(mach_port_t port, UInt32 type, UInt32 refCon);
211
212	static IOReturn _registerNotificationAction(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3);	// <rdar://7529580>
213	static IOReturn registerNotificationAction(OSObject *owner, void *arg1, void *arg2, void *arg3, void *arg4);
214	virtual IOReturn registerNotification(mach_port_t port, UInt32 refCon);
215
216	virtual void setOnline(bool newOnline);
217
218	virtual IOReturn performClientOutput(UInt32 firstSampleFrame, UInt32 loopCount, IOAudioClientBufferSet *bufferSet, UInt32 sampleIntervalHi, UInt32 sampleIntervalLo);
219	virtual IOReturn performClientInput(UInt32 firstSampleFrame, IOAudioClientBufferSet *bufferSet);
220	virtual void performWatchdogOutput(IOAudioClientBufferSet *clientBufferSet, UInt32 generationCount);
221
222	virtual void lockBuffers();
223	virtual void unlockBuffers();
224
225	static void setCommandGateUsage(IOAudioEngineUserClient *userClient, bool increment);		// <rdar://8518215>
226
227public:
228
229	static IOAudioEngineUserClient *withAudioEngine(IOAudioEngine *engine, task_t clientTask, void *securityToken, UInt32 type);
230	static IOAudioEngineUserClient *withAudioEngine(IOAudioEngine *engine, task_t clientTask, void *securityToken, UInt32 type, OSDictionary *properties);
231
232	virtual bool initWithAudioEngine(IOAudioEngine *engine, task_t task, void *securityToken, UInt32 type);
233
234	virtual void free();
235	virtual void freeClientBufferSetList();
236	virtual void freeClientBuffer(IOAudioClientBuffer64 *clientBuffer);
237
238	virtual void stop(IOService *provider);
239
240	virtual bool isOnline();
241
242	virtual IOReturn registerBuffer(IOAudioStream *audioStream, void* sourceBuffer, UInt32 bufSizeInBytes, UInt32 bufferSetID);
243	virtual IOReturn unregisterBuffer( void * sourceBuffer, UInt32 bufferSetID);
244
245	static IOReturn _registerBufferAction(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3);	// <rdar://7529580>
246	static IOReturn registerBufferAction(OSObject *owner, void *arg1, void *arg2, void *arg3, void *arg4);
247	static IOReturn _unregisterBufferAction(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3);	// <rdar://7529580>
248	static IOReturn unregisterBufferAction(OSObject *owner, void *arg1, void *arg2, void *arg3, void *arg4);
249
250	virtual IOReturn registerClientBuffer(IOAudioStream *audioStream, void * sourceBuffer, UInt32 bufSizeInBytes, UInt32 bufferSetID);
251	virtual IOReturn unregisterClientBuffer(void * sourceBuffer, UInt32 bufferSetID);
252
253	static IOReturn _getNearestStartTimeAction(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3);	// <rdar://7529580>
254	static IOReturn getNearestStartTimeAction(OSObject *owner, void *arg1, void *arg2, void *arg3, void *arg4);
255
256	virtual IOAudioClientBufferSet *findBufferSet(UInt32 bufferSetID);
257	virtual void removeBufferSet(IOAudioClientBufferSet *bufferSet);
258
259	virtual IOReturn getConnectionID(UInt32 *connectionID);
260
261	virtual IOReturn clientStart();
262	virtual IOReturn clientStop();
263
264	static IOReturn _startClientAction(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3);	// <rdar://7529580>
265	static IOReturn startClientAction(OSObject *owner, void *arg1, void *arg2, void *arg3, void *arg4);
266	static IOReturn _stopClientAction(OSObject *target, void *arg0, void *arg1, void *arg2, void *arg3);	// <rdar://7529580>
267	static IOReturn stopClientAction(OSObject *owner, void *arg1, void *arg2, void *arg3, void *arg4);
268
269	virtual IOReturn startClient();
270	virtual IOReturn stopClient();
271
272	virtual IOReturn performClientIO(UInt32 firstSampleFrame, UInt32 loopCount, bool inputIO, UInt32 bufferSetID, UInt32 sampleIntervalHi, UInt32 sampleIntervalLo);
273
274	virtual void sendFormatChangeNotification(IOAudioStream *audioStream);
275	virtual IOReturn sendNotification(UInt32 notificationType);
276
277};
278
279// <rdar://101000004> END
280
281
282#endif /* _IOKIT_IOAUDIOENGINEUSERCLIENT_H */
283