]> git.saurik.com Git - apple/xnu.git/blame - iokit/Families/IOCDStorage/IOCDAudioControlUserClient.cpp
xnu-124.13.tar.gz
[apple/xnu.git] / iokit / Families / IOCDStorage / IOCDAudioControlUserClient.cpp
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 1998-2000 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#include <IOKit/assert.h>
24#include <IOKit/IOLib.h>
25#include <IOKit/storage/IOCDAudioControlUserClient.h>
26
27#define super IOUserClient
28OSDefineMetaClassAndStructors(IOCDAudioControlUserClient, IOUserClient)
29
30// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
31
32IOCDAudioControl * IOCDAudioControlUserClient::getProvider() const
33{
34 //
35 // Obtain this object's provider. We override the superclass's method
36 // to return a more specific subclass of IOService -- IOCDAudioControl.
37 // This method serves simply as a convenience to subclass developers.
38 //
39
40 return (IOCDAudioControl *) IOService::getProvider();
41}
42
43// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
44
45IOCDAudioControlUserClient * IOCDAudioControlUserClient::withTask(task_t)
46{
47 //
48 // Create a new IOCDAudioControlUserClient.
49 //
50
51 IOCDAudioControlUserClient * me = new IOCDAudioControlUserClient;
52
53 if ( me && me->init() == false )
54 {
55 me->release();
56 me = 0;
57 }
58
59 return me;
60}
61
62// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
63
64bool IOCDAudioControlUserClient::start(IOService * provider)
65{
66 //
67 // Prepare the user client for usage.
68 //
69
70 // State our assumptions.
71
72 assert(OSDynamicCast(IOCDAudioControl, provider));
73
74 // Ask our superclass' opinion.
75
76 if ( super::start(provider) == false ) return false;
77
78 // Open our provider.
79
80 if ( provider->open(this) == false ) return false;
81
82 // Prepare our method dispatch table.
83
84 _methods[kIOCDAudioControlMethodGetStatus].func = (IOMethod) &IOCDAudioControlUserClient::getStatus;
85 _methods[kIOCDAudioControlMethodGetStatus].flags = kIOUCScalarIStructO;
86 _methods[kIOCDAudioControlMethodGetStatus].count0 = 0;
87 _methods[kIOCDAudioControlMethodGetStatus].count1 = sizeof(CDAudioStatus);
88 _methods[kIOCDAudioControlMethodGetStatus].object = this;
89
90 _methods[kIOCDAudioControlMethodGetTOC ].func = (IOMethod) &IOCDAudioControlUserClient::getTOC;
91 _methods[kIOCDAudioControlMethodGetTOC ].flags = kIOUCScalarIStructO;
92 _methods[kIOCDAudioControlMethodGetTOC ].count0 = 0;
93 _methods[kIOCDAudioControlMethodGetTOC ].count1 = 0xFFFFFFFF;
94 _methods[kIOCDAudioControlMethodGetTOC ].object = this;
95
96 _methods[kIOCDAudioControlMethodGetVolume].func = (IOMethod) &IOCDAudioControlUserClient::getVolume;
97 _methods[kIOCDAudioControlMethodGetVolume].flags = kIOUCScalarIScalarO;
98 _methods[kIOCDAudioControlMethodGetVolume].count0 = 0;
99 _methods[kIOCDAudioControlMethodGetVolume].count1 = 2;
100 _methods[kIOCDAudioControlMethodGetVolume].object = this;
101
102 _methods[kIOCDAudioControlMethodSetVolume].func = (IOMethod) &IOCDAudioControlUserClient::setVolume;
103 _methods[kIOCDAudioControlMethodSetVolume].flags = kIOUCScalarIScalarO;
104 _methods[kIOCDAudioControlMethodSetVolume].count0 = 2;
105 _methods[kIOCDAudioControlMethodSetVolume].count1 = 0;
106 _methods[kIOCDAudioControlMethodSetVolume].object = this;
107
108 _methods[kIOCDAudioControlMethodPause ].func = (IOMethod) &IOCDAudioControlUserClient::pause;
109 _methods[kIOCDAudioControlMethodPause ].flags = kIOUCScalarIScalarO;
110 _methods[kIOCDAudioControlMethodPause ].count0 = 1;
111 _methods[kIOCDAudioControlMethodPause ].count1 = 0;
112 _methods[kIOCDAudioControlMethodPause ].object = this;
113
114 _methods[kIOCDAudioControlMethodPlay ].func = (IOMethod) &IOCDAudioControlUserClient::play;
115 _methods[kIOCDAudioControlMethodPlay ].flags = kIOUCScalarIScalarO;
116 _methods[kIOCDAudioControlMethodPlay ].count0 = 2;
117 _methods[kIOCDAudioControlMethodPlay ].count1 = 0;
118 _methods[kIOCDAudioControlMethodPlay ].object = this;
119
120 _methods[kIOCDAudioControlMethodScan ].func = (IOMethod) &IOCDAudioControlUserClient::scan;
121 _methods[kIOCDAudioControlMethodScan ].flags = kIOUCScalarIScalarO;
122 _methods[kIOCDAudioControlMethodScan ].count0 = 2;
123 _methods[kIOCDAudioControlMethodScan ].count1 = 0;
124 _methods[kIOCDAudioControlMethodScan ].object = this;
125
126 _methods[kIOCDAudioControlMethodStop ].func = (IOMethod) &IOCDAudioControlUserClient::stop;
127 _methods[kIOCDAudioControlMethodStop ].flags = 0;
128 _methods[kIOCDAudioControlMethodStop ].count0 = 0;
129 _methods[kIOCDAudioControlMethodStop ].count1 = 0;
130 _methods[kIOCDAudioControlMethodStop ].object = this;
131
132 return true;
133}
134
135// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
136
137IOReturn IOCDAudioControlUserClient::clientClose()
138{
139 //
140 // Relinquish the user client.
141 //
142
143 IOCDAudioControl * provider = getProvider();
144
145 if ( provider && provider->isOpen(this) )
146 {
147 provider->close(this);
148 detach(provider);
149 }
150
151 return kIOReturnSuccess;
152}
153
154// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
155
156IOExternalMethod * IOCDAudioControlUserClient::getExternalMethodForIndex(
157 UInt32 index )
158{
159 //
160 // Obtain the method definition given a method index.
161 //
162
163 if (index >= kIOCDAudioControlMethodCount) return 0;
164
165 return _methods + index;
166}
167
168// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
169
170IOReturn IOCDAudioControlUserClient::getStatus( CDAudioStatus * status,
171 UInt32 * statusSize )
172{
173 //
174 // Get the current audio play status information.
175 //
176
177 if ( *statusSize != sizeof(CDAudioStatus) ) return kIOReturnBadArgument;
178
179 return getProvider()->getStatus(status);
180}
181
182// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
183
184IOReturn IOCDAudioControlUserClient::getTOC(CDTOC * toc, UInt32 * tocMaxSize)
185{
186 //
187 // Get the full Table Of Contents.
188 //
189
190 CDTOC * original = getProvider()->getTOC();
191
192 if (original == 0) return kIOReturnBadMedia;
193
194 *tocMaxSize = min(original->length + sizeof(UInt16), *tocMaxSize);
195 bcopy(original, toc, *tocMaxSize);
196
197 return kIOReturnSuccess;
198}
199
200// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
201
202IOReturn IOCDAudioControlUserClient::getVolume(UInt32 * left, UInt32 * right)
203{
204 //
205 // Get the current audio volume.
206 //
207
208 IOReturn status;
209
210 if ( ((*left) & ~0xFF) || ((*right) & ~0xFF) ) return kIOReturnBadArgument;
211
212 status = getProvider()->getVolume((UInt8 *) left, (UInt8 *) right);
213
214 *left = *((UInt8 *) left );
215 *right = *((UInt8 *) right);
216
217 return status;
218}
219
220// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
221
222IOReturn IOCDAudioControlUserClient::setVolume(UInt32 left, UInt32 right)
223{
224 //
225 // Set the current audio volume.
226 //
227
228 if ( (left & ~0xFF) || (right & ~0xFF) ) return kIOReturnBadArgument;
229
230 return getProvider()->setVolume((UInt8) left, (UInt8) right);
231}
232
233// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
234
235IOReturn IOCDAudioControlUserClient::pause(UInt32 pause)
236{
237 //
238 // Pause or resume the audio playback.
239 //
240
241 return getProvider()->pause((bool) pause);
242}
243
244// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
245
246IOReturn IOCDAudioControlUserClient::play(UInt32 msfStart, UInt32 msfStop)
247{
248 //
249 // Play audio.
250 //
251
252 CDMSF timeStart;
253 CDMSF timeStop;
254
255 timeStart.minute = (msfStart >> 16) & 0xFF;
256 timeStart.second = (msfStart >> 8) & 0xFF;
257 timeStart.frame = (msfStart >> 0) & 0xFF;
258
259 timeStop.minute = (msfStop >> 16) & 0xFF;
260 timeStop.second = (msfStop >> 8) & 0xFF;
261 timeStop.frame = (msfStop >> 0) & 0xFF;
262
263 return getProvider()->play(timeStart, timeStop);
264}
265
266// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
267
268IOReturn IOCDAudioControlUserClient::scan(UInt32 msfStart, UInt32 reverse)
269{
270 //
271 // Perform a fast-forward or fast-backward operation.
272 //
273
274 CDMSF timeStart;
275
276 timeStart.minute = (msfStart >> 16) & 0xFF;
277 timeStart.second = (msfStart >> 8) & 0xFF;
278 timeStart.frame = (msfStart >> 0) & 0xFF;
279
280 return getProvider()->scan(timeStart, reverse ? true : false);
281}
282
283// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
284
285IOReturn IOCDAudioControlUserClient::stop()
286{
287 //
288 // Stop the audio playback (or audio scan).
289 //
290
291 return getProvider()->stop();
292}
293
294// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
295
296OSMetaClassDefineReservedUnused(IOCDAudioControlUserClient, 0);
297
298// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
299
300OSMetaClassDefineReservedUnused(IOCDAudioControlUserClient, 1);
301
302// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
303
304OSMetaClassDefineReservedUnused(IOCDAudioControlUserClient, 2);
305
306// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
307
308OSMetaClassDefineReservedUnused(IOCDAudioControlUserClient, 3);
309
310// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
311
312OSMetaClassDefineReservedUnused(IOCDAudioControlUserClient, 4);
313
314// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
315
316OSMetaClassDefineReservedUnused(IOCDAudioControlUserClient, 5);
317
318// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
319
320OSMetaClassDefineReservedUnused(IOCDAudioControlUserClient, 6);
321
322// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
323
324OSMetaClassDefineReservedUnused(IOCDAudioControlUserClient, 7);