Added regedit unit test, a couple minor changes to regedit.
[wine] / dlls / dsound / capture.c
1 /*                      DirectSoundCapture
2  *
3  * Copyright 1998 Marcus Meissner
4  * Copyright 1998 Rob Riggs
5  * Copyright 2000-2001 TransGaming Technologies, Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21 /*
22  * TODO:
23  *      Implement DirectSoundCapture API
24  */
25
26 #include "config.h"
27 #include <assert.h>
28 #include <stdio.h>
29 #include <sys/types.h>
30 #include <sys/fcntl.h>
31 #include <unistd.h>
32 #include <stdlib.h>
33 #include <string.h>
34
35 #include "windef.h"
36 #include "winbase.h"
37 #include "wingdi.h"
38 #include "winuser.h"
39 #include "winerror.h"
40 #include "mmsystem.h"
41 #include "wine/debug.h"
42 #include "dsound.h"
43
44 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
45
46 /*****************************************************************************
47  * Predeclare the interface implementation structures
48  */
49 typedef struct IDirectSoundCaptureImpl IDirectSoundCaptureImpl;
50 typedef struct IDirectSoundCaptureBufferImpl IDirectSoundCaptureBufferImpl;
51
52
53 /*****************************************************************************
54  * IDirectSoundCapture implementation structure
55  */
56 struct IDirectSoundCaptureImpl
57 {
58     /* IUnknown fields */
59     ICOM_VFIELD(IDirectSoundCapture);
60     DWORD                              ref;
61
62     /* IDirectSoundCaptureImpl fields */
63     CRITICAL_SECTION        lock;
64 };
65
66 /*****************************************************************************
67  * IDirectSoundCapture implementation structure
68  */
69 struct IDirectSoundCaptureBufferImpl
70 {
71     /* IUnknown fields */
72     ICOM_VFIELD(IDirectSoundCaptureBuffer8);
73     DWORD                              ref;
74
75     /* IDirectSoundCaptureBufferImpl fields */
76     CRITICAL_SECTION        lock;
77 };
78
79
80 static HRESULT DSOUND_CreateDirectSoundCapture( LPVOID* ppobj );
81 static HRESULT DSOUND_CreateDirectSoundCaptureBuffer( LPCDSCBUFFERDESC lpcDSCBufferDesc, LPVOID* ppobj );
82
83 static ICOM_VTABLE(IDirectSoundCapture) dscvt;
84 static ICOM_VTABLE(IDirectSoundCaptureBuffer8) dscbvt;
85
86
87 /***************************************************************************
88  * DirectSoundCaptureCreate [DSOUND.6]
89  *
90  * Create and initialize a DirectSoundCapture interface
91  *
92  * RETURNS
93  *    Success: DS_OK
94  *    Failure: DSERR_NOAGGREGATION, DSERR_ALLOCATED, DSERR_INVALIDPARAM,
95  *             DSERR_OUTOFMEMORY
96  */
97 HRESULT WINAPI DirectSoundCaptureCreate8(
98         LPCGUID lpcGUID,
99         LPDIRECTSOUNDCAPTURE* lplpDSC,
100         LPUNKNOWN pUnkOuter )
101 {
102         TRACE("(%s,%p,%p)\n", debugstr_guid(lpcGUID), lplpDSC, pUnkOuter);
103
104         if( pUnkOuter ) {
105                 return DSERR_NOAGGREGATION;
106         }
107
108         /* Default device? */
109         if ( !lpcGUID ||
110              IsEqualGUID(lpcGUID, &DSDEVID_DefaultCapture) ||
111              IsEqualGUID(lpcGUID, &DSDEVID_DefaultVoiceCapture) ) {
112                 return DSOUND_CreateDirectSoundCapture( (LPVOID*)lplpDSC );
113         }
114
115         FIXME( "Unknown GUID %s\n", debugstr_guid(lpcGUID) );
116         *lplpDSC = NULL;
117
118         return DSERR_OUTOFMEMORY;
119 }
120
121 /***************************************************************************
122  * DirectSoundCaptureEnumerateA [DSOUND.7]
123  *
124  * Enumerate all DirectSound drivers installed in the system
125  *
126  * RETURNS
127  *    Success: DS_OK
128  *    Failure: DSERR_INVALIDPARAM
129  */
130 HRESULT WINAPI DirectSoundCaptureEnumerateA(
131         LPDSENUMCALLBACKA lpDSEnumCallback,
132         LPVOID lpContext)
133 {
134         TRACE("(%p,%p)\n", lpDSEnumCallback, lpContext );
135
136         if ( lpDSEnumCallback )
137                 lpDSEnumCallback(NULL,"WINE Primary Sound Capture Driver",
138                     "SoundCap",lpContext);
139
140
141         return DS_OK;
142 }
143
144 /***************************************************************************
145  * DirectSoundCaptureEnumerateW [DSOUND.8]
146  *
147  * Enumerate all DirectSound drivers installed in the system
148  *
149  * RETURNS
150  *    Success: DS_OK
151  *    Failure: DSERR_INVALIDPARAM
152  */
153 HRESULT WINAPI DirectSoundCaptureEnumerateW(
154         LPDSENUMCALLBACKW lpDSEnumCallback,
155         LPVOID lpContext)
156 {
157         FIXME("(%p,%p):stub\n", lpDSEnumCallback, lpContext );
158         return DS_OK;
159 }
160
161 static HRESULT
162 DSOUND_CreateDirectSoundCapture( LPVOID* ppobj )
163 {
164         *ppobj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( IDirectSoundCaptureImpl ) );
165
166         if ( *ppobj == NULL ) {
167                 return DSERR_OUTOFMEMORY;
168         }
169
170         {
171                 ICOM_THIS(IDirectSoundCaptureImpl,*ppobj);
172
173                 This->ref = 1;
174                 ICOM_VTBL(This) = &dscvt;
175
176                 InitializeCriticalSection( &This->lock );
177         }
178
179         return S_OK;
180 }
181
182 static HRESULT WINAPI
183 IDirectSoundCaptureImpl_QueryInterface(
184         LPDIRECTSOUNDCAPTURE iface,
185         REFIID riid,
186         LPVOID* ppobj )
187 {
188         ICOM_THIS(IDirectSoundCaptureImpl,iface);
189
190         FIXME( "(%p)->(%s,%p): stub\n", This, debugstr_guid(riid), ppobj );
191
192         return E_FAIL;
193 }
194
195 static ULONG WINAPI
196 IDirectSoundCaptureImpl_AddRef( LPDIRECTSOUNDCAPTURE iface )
197 {
198         ULONG uRef;
199         ICOM_THIS(IDirectSoundCaptureImpl,iface);
200
201         EnterCriticalSection( &This->lock );
202
203         TRACE( "(%p) was 0x%08lx\n", This, This->ref );
204         uRef = ++(This->ref);
205
206         LeaveCriticalSection( &This->lock );
207
208         return uRef;
209 }
210
211 static ULONG WINAPI
212 IDirectSoundCaptureImpl_Release( LPDIRECTSOUNDCAPTURE iface )
213 {
214         ULONG uRef;
215         ICOM_THIS(IDirectSoundCaptureImpl,iface);
216
217         EnterCriticalSection( &This->lock );
218
219         TRACE( "(%p) was 0x%08lx\n", This, This->ref );
220         uRef = --(This->ref);
221
222         LeaveCriticalSection( &This->lock );
223
224         if ( uRef == 0 ) {
225                 DeleteCriticalSection( &This->lock );
226                 HeapFree( GetProcessHeap(), 0, This );
227         }
228
229         return uRef;
230 }
231
232 static HRESULT WINAPI
233 IDirectSoundCaptureImpl_CreateCaptureBuffer(
234         LPDIRECTSOUNDCAPTURE iface,
235         LPCDSCBUFFERDESC lpcDSCBufferDesc,
236         LPDIRECTSOUNDCAPTUREBUFFER* lplpDSCaptureBuffer,
237         LPUNKNOWN pUnk )
238 {
239         HRESULT hr;
240         ICOM_THIS(IDirectSoundCaptureImpl,iface);
241
242         TRACE( "(%p)->(%p,%p,%p)\n", This, lpcDSCBufferDesc, lplpDSCaptureBuffer, pUnk );
243
244         if ( pUnk ) {
245                 return DSERR_INVALIDPARAM;
246         }
247
248         hr = DSOUND_CreateDirectSoundCaptureBuffer( lpcDSCBufferDesc, (LPVOID*)lplpDSCaptureBuffer );
249
250         return hr;
251 }
252
253 static HRESULT WINAPI
254 IDirectSoundCaptureImpl_GetCaps(
255         LPDIRECTSOUNDCAPTURE iface,
256         LPDSCCAPS lpDSCCaps )
257 {
258         ICOM_THIS(IDirectSoundCaptureImpl,iface);
259
260         FIXME( "(%p)->(%p): stub\n", This, lpDSCCaps );
261
262         return DS_OK;
263 }
264
265 static HRESULT WINAPI
266 IDirectSoundCaptureImpl_Initialize(
267         LPDIRECTSOUNDCAPTURE iface,
268         LPCGUID lpcGUID )
269 {
270         ICOM_THIS(IDirectSoundCaptureImpl,iface);
271
272         FIXME( "(%p)->(%p): stub\n", This, lpcGUID );
273
274         return DS_OK;
275 }
276
277
278 static ICOM_VTABLE(IDirectSoundCapture) dscvt =
279 {
280         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
281         /* IUnknown methods */
282         IDirectSoundCaptureImpl_QueryInterface,
283         IDirectSoundCaptureImpl_AddRef,
284         IDirectSoundCaptureImpl_Release,
285
286         /* IDirectSoundCapture methods */
287         IDirectSoundCaptureImpl_CreateCaptureBuffer,
288         IDirectSoundCaptureImpl_GetCaps,
289         IDirectSoundCaptureImpl_Initialize
290 };
291
292 static HRESULT
293 DSOUND_CreateDirectSoundCaptureBuffer( LPCDSCBUFFERDESC lpcDSCBufferDesc, LPVOID* ppobj )
294 {
295
296         FIXME( "(%p,%p): ignoring lpcDSCBufferDesc\n", lpcDSCBufferDesc, ppobj );
297
298         *ppobj = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof( IDirectSoundCaptureBufferImpl ) );
299
300         if ( *ppobj == NULL ) {
301                 return DSERR_OUTOFMEMORY;
302         }
303
304         {
305                 ICOM_THIS(IDirectSoundCaptureBufferImpl,*ppobj);
306
307                 This->ref = 1;
308                 ICOM_VTBL(This) = &dscbvt;
309
310                 InitializeCriticalSection( &This->lock );
311         }
312
313         return S_OK;
314 }
315
316
317 static HRESULT WINAPI
318 IDirectSoundCaptureBufferImpl_QueryInterface(
319         LPDIRECTSOUNDCAPTUREBUFFER8 iface,
320         REFIID riid,
321         LPVOID* ppobj )
322 {
323         ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
324
325         FIXME( "(%p)->(%s,%p): stub\n", This, debugstr_guid(riid), ppobj );
326
327         return E_FAIL;
328 }
329
330 static ULONG WINAPI
331 IDirectSoundCaptureBufferImpl_AddRef( LPDIRECTSOUNDCAPTUREBUFFER8 iface )
332 {
333         ULONG uRef;
334         ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
335
336         EnterCriticalSection( &This->lock );
337
338         TRACE( "(%p) was 0x%08lx\n", This, This->ref );
339         uRef = ++(This->ref);
340
341         LeaveCriticalSection( &This->lock );
342
343         return uRef;
344 }
345
346 static ULONG WINAPI
347 IDirectSoundCaptureBufferImpl_Release( LPDIRECTSOUNDCAPTUREBUFFER8 iface )
348 {
349         ULONG uRef;
350         ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
351
352         EnterCriticalSection( &This->lock );
353
354         TRACE( "(%p) was 0x%08lx\n", This, This->ref );
355         uRef = --(This->ref);
356
357         LeaveCriticalSection( &This->lock );
358
359         if ( uRef == 0 ) {
360                 DeleteCriticalSection( &This->lock );
361                 HeapFree( GetProcessHeap(), 0, This );
362         }
363
364         return uRef;
365 }
366
367 static HRESULT WINAPI
368 IDirectSoundCaptureBufferImpl_GetCaps(
369         LPDIRECTSOUNDCAPTUREBUFFER8 iface,
370         LPDSCBCAPS lpDSCBCaps )
371 {
372         ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
373
374         FIXME( "(%p)->(%p): stub\n", This, lpDSCBCaps );
375
376         return DS_OK;
377 }
378
379 static HRESULT WINAPI
380 IDirectSoundCaptureBufferImpl_GetCurrentPosition(
381         LPDIRECTSOUNDCAPTUREBUFFER8 iface,
382         LPDWORD lpdwCapturePosition,
383         LPDWORD lpdwReadPosition )
384 {
385         ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
386
387         FIXME( "(%p)->(%p,%p): stub\n", This, lpdwCapturePosition, lpdwReadPosition );
388
389         return DS_OK;
390 }
391
392 static HRESULT WINAPI
393 IDirectSoundCaptureBufferImpl_GetFormat(
394         LPDIRECTSOUNDCAPTUREBUFFER8 iface,
395         LPWAVEFORMATEX lpwfxFormat,
396         DWORD dwSizeAllocated,
397         LPDWORD lpdwSizeWritten )
398 {
399         ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
400
401         FIXME( "(%p)->(%p,0x%08lx,%p): stub\n", This, lpwfxFormat, dwSizeAllocated, lpdwSizeWritten );
402
403         return DS_OK;
404 }
405
406 static HRESULT WINAPI
407 IDirectSoundCaptureBufferImpl_GetStatus(
408         LPDIRECTSOUNDCAPTUREBUFFER8 iface,
409         LPDWORD lpdwStatus )
410 {
411         ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
412
413         FIXME( "(%p)->(%p): stub\n", This, lpdwStatus );
414
415         return DS_OK;
416 }
417
418 static HRESULT WINAPI
419 IDirectSoundCaptureBufferImpl_Initialize(
420         LPDIRECTSOUNDCAPTUREBUFFER8 iface,
421         LPDIRECTSOUNDCAPTURE lpDSC,
422         LPCDSCBUFFERDESC lpcDSCBDesc )
423 {
424         ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
425
426         FIXME( "(%p)->(%p,%p): stub\n", This, lpDSC, lpcDSCBDesc );
427
428         return DS_OK;
429 }
430
431 static HRESULT WINAPI
432 IDirectSoundCaptureBufferImpl_Lock(
433         LPDIRECTSOUNDCAPTUREBUFFER8 iface,
434         DWORD dwReadCusor,
435         DWORD dwReadBytes,
436         LPVOID* lplpvAudioPtr1,
437         LPDWORD lpdwAudioBytes1,
438         LPVOID* lplpvAudioPtr2,
439         LPDWORD lpdwAudioBytes2,
440         DWORD dwFlags )
441 {
442         ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
443
444         FIXME( "(%p)->(%08lu,%08lu,%p,%p,%p,%p,0x%08lx): stub\n", This, dwReadCusor, dwReadBytes, lplpvAudioPtr1, lpdwAudioBytes1, lplpvAudioPtr2, lpdwAudioBytes2, dwFlags );
445
446         return DS_OK;
447 }
448
449 static HRESULT WINAPI
450 IDirectSoundCaptureBufferImpl_Start(
451         LPDIRECTSOUNDCAPTUREBUFFER8 iface,
452         DWORD dwFlags )
453 {
454         ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
455
456         FIXME( "(%p)->(0x%08lx): stub\n", This, dwFlags );
457
458         return DS_OK;
459 }
460
461 static HRESULT WINAPI
462 IDirectSoundCaptureBufferImpl_Stop( LPDIRECTSOUNDCAPTUREBUFFER8 iface )
463 {
464         ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
465
466         FIXME( "(%p): stub\n", This );
467
468         return DS_OK;
469 }
470
471 static HRESULT WINAPI
472 IDirectSoundCaptureBufferImpl_Unlock(
473         LPDIRECTSOUNDCAPTUREBUFFER8 iface,
474         LPVOID lpvAudioPtr1,
475         DWORD dwAudioBytes1,
476         LPVOID lpvAudioPtr2,
477         DWORD dwAudioBytes2 )
478 {
479         ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
480
481         FIXME( "(%p)->(%p,%08lu,%p,%08lu): stub\n", This, lpvAudioPtr1, dwAudioBytes1, lpvAudioPtr2, dwAudioBytes2 );
482
483         return DS_OK;
484 }
485
486 static HRESULT WINAPI
487 IDirectSoundCaptureBufferImpl_GetObjectInPath(
488         LPDIRECTSOUNDCAPTUREBUFFER8 iface,
489         REFGUID rguidObject,
490         DWORD dwIndex,
491         REFGUID rguidInterface,
492         LPVOID* ppObject )
493 {
494         ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
495
496         FIXME( "(%p)->(%s,%lu,%s,%p): stub\n", This, debugstr_guid(rguidObject), dwIndex, debugstr_guid(rguidInterface), ppObject );
497
498         return DS_OK;
499 }
500
501 static HRESULT WINAPI
502 IDirectSoundCaptureBufferImpl_GetFXStatus(
503         LPDIRECTSOUNDCAPTUREBUFFER8 iface,
504         DWORD dwFXCount,
505         LPDWORD pdwFXStatus )
506 {
507         ICOM_THIS(IDirectSoundCaptureBufferImpl,iface);
508
509         FIXME( "(%p)->(%lu,%p): stub\n", This, dwFXCount, pdwFXStatus );
510
511         return DS_OK;
512 }
513
514
515 static ICOM_VTABLE(IDirectSoundCaptureBuffer8) dscbvt =
516 {
517         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
518         /* IUnknown methods */
519         IDirectSoundCaptureBufferImpl_QueryInterface,
520         IDirectSoundCaptureBufferImpl_AddRef,
521         IDirectSoundCaptureBufferImpl_Release,
522
523         /* IDirectSoundCaptureBuffer methods */
524         IDirectSoundCaptureBufferImpl_GetCaps,
525         IDirectSoundCaptureBufferImpl_GetCurrentPosition,
526         IDirectSoundCaptureBufferImpl_GetFormat,
527         IDirectSoundCaptureBufferImpl_GetStatus,
528         IDirectSoundCaptureBufferImpl_Initialize,
529         IDirectSoundCaptureBufferImpl_Lock,
530         IDirectSoundCaptureBufferImpl_Start,
531         IDirectSoundCaptureBufferImpl_Stop,
532         IDirectSoundCaptureBufferImpl_Unlock,
533
534         /* IDirectSoundCaptureBuffer methods */
535         IDirectSoundCaptureBufferImpl_GetObjectInPath,
536         IDirectSoundCaptureBufferImpl_GetFXStatus
537 };