mshtml: Added IHTMLWindow6::get_sessionStorage implementation.
[wine] / dlls / dsound / dsound_private.h
1 /*                      DirectSound
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 /* Linux does not support better timing than 10ms */
23 #define DS_TIME_RES 2  /* Resolution of multimedia timer */
24 #define DS_TIME_DEL 10  /* Delay of multimedia timer callback, and duration of HEL fragment */
25
26 #include "wingdi.h"
27 #include "mmdeviceapi.h"
28 #include "audioclient.h"
29 #include "mmsystem.h"
30
31 #include "wine/list.h"
32
33 extern int ds_hel_buflen DECLSPEC_HIDDEN;
34 extern int ds_snd_queue_max DECLSPEC_HIDDEN;
35 extern int ds_snd_shadow_maxsize DECLSPEC_HIDDEN;
36 extern int ds_default_sample_rate DECLSPEC_HIDDEN;
37 extern int ds_default_bits_per_sample DECLSPEC_HIDDEN;
38
39 /*****************************************************************************
40  * Predeclare the interface implementation structures
41  */
42 typedef struct IDirectSoundBufferImpl        IDirectSoundBufferImpl;
43 typedef struct IDirectSoundCaptureBufferImpl IDirectSoundCaptureBufferImpl;
44 typedef struct DirectSoundDevice             DirectSoundDevice;
45 typedef struct DirectSoundCaptureDevice      DirectSoundCaptureDevice;
46
47 /* dsound_convert.h */
48 typedef float (*bitsgetfunc)(const IDirectSoundBufferImpl *, DWORD, DWORD);
49 typedef void (*bitsputfunc)(const IDirectSoundBufferImpl *, DWORD, DWORD, float);
50 extern const bitsgetfunc getbpp[5] DECLSPEC_HIDDEN;
51 void putieee32(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel, float value) DECLSPEC_HIDDEN;
52 void mixieee32(float *src, float *dst, unsigned samples) DECLSPEC_HIDDEN;
53 typedef void (*normfunc)(const void *, void *, unsigned);
54 extern const normfunc normfunctions[5] DECLSPEC_HIDDEN;
55
56 typedef struct _DSVOLUMEPAN
57 {
58     DWORD       dwTotalLeftAmpFactor;
59     DWORD       dwTotalRightAmpFactor;
60     LONG        lVolume;
61     DWORD       dwVolAmpFactor;
62     LONG        lPan;
63     DWORD       dwPanLeftAmpFactor;
64     DWORD       dwPanRightAmpFactor;
65 } DSVOLUMEPAN,*PDSVOLUMEPAN;
66
67 /*****************************************************************************
68  * IDirectSoundDevice implementation structure
69  */
70 struct DirectSoundDevice
71 {
72     LONG                        ref;
73
74     GUID                        guid;
75     DSCAPS                      drvcaps;
76     DWORD                       priolevel;
77     PWAVEFORMATEX               pwfx;
78     UINT                        timerID, playing_offs_bytes, in_mmdev_bytes, prebuf, helfrags;
79     DWORD                       fraglen;
80     LPBYTE                      buffer;
81     DWORD                       writelead, buflen, state, playpos, mixpos;
82     int                         nrofbuffers;
83     IDirectSoundBufferImpl**    buffers;
84     RTL_RWLOCK                  buffer_list_lock;
85     CRITICAL_SECTION            mixlock;
86     IDirectSoundBufferImpl     *primary;
87     DWORD                       speaker_config;
88     float *mix_buffer, *tmp_buffer;
89     DWORD                       tmp_buffer_len, mix_buffer_len;
90
91     DSVOLUMEPAN                 volpan;
92
93     normfunc normfunction;
94
95     /* DirectSound3DListener fields */
96     DS3DLISTENER                ds3dl;
97     BOOL                        ds3dl_need_recalc;
98
99     IMMDevice *mmdevice;
100     IAudioClient *client;
101     IAudioClock *clock;
102     IAudioStreamVolume *volume;
103     IAudioRenderClient *render;
104
105     struct list entry;
106 };
107
108 /* reference counted buffer memory for duplicated buffer memory */
109 typedef struct BufferMemory
110 {
111     LONG                        ref;
112     LPBYTE                      memory;
113     struct list buffers;
114 } BufferMemory;
115
116 ULONG DirectSoundDevice_Release(DirectSoundDevice * device) DECLSPEC_HIDDEN;
117 HRESULT DirectSoundDevice_Initialize(
118     DirectSoundDevice ** ppDevice,
119     LPCGUID lpcGUID) DECLSPEC_HIDDEN;
120 HRESULT DirectSoundDevice_AddBuffer(
121     DirectSoundDevice * device,
122     IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
123 HRESULT DirectSoundDevice_RemoveBuffer(
124     DirectSoundDevice * device,
125     IDirectSoundBufferImpl * pDSB) DECLSPEC_HIDDEN;
126 HRESULT DirectSoundDevice_GetCaps(DirectSoundDevice * device, LPDSCAPS lpDSCaps) DECLSPEC_HIDDEN;
127 HRESULT DirectSoundDevice_CreateSoundBuffer(
128     DirectSoundDevice * device,
129     LPCDSBUFFERDESC dsbd,
130     LPLPDIRECTSOUNDBUFFER ppdsb,
131     LPUNKNOWN lpunk,
132     BOOL from8) DECLSPEC_HIDDEN;
133 HRESULT DirectSoundDevice_DuplicateSoundBuffer(
134     DirectSoundDevice * device,
135     LPDIRECTSOUNDBUFFER psb,
136     LPLPDIRECTSOUNDBUFFER ppdsb) DECLSPEC_HIDDEN;
137 HRESULT DirectSoundDevice_SetCooperativeLevel(
138     DirectSoundDevice * devcie,
139     HWND hwnd,
140     DWORD level) DECLSPEC_HIDDEN;
141 HRESULT DirectSoundDevice_Compact(DirectSoundDevice * device) DECLSPEC_HIDDEN;
142 HRESULT DirectSoundDevice_GetSpeakerConfig(
143     DirectSoundDevice * device,
144     LPDWORD lpdwSpeakerConfig) DECLSPEC_HIDDEN;
145 HRESULT DirectSoundDevice_SetSpeakerConfig(
146     DirectSoundDevice * device,
147     DWORD config) DECLSPEC_HIDDEN;
148 HRESULT DirectSoundDevice_VerifyCertification(DirectSoundDevice * device,
149     LPDWORD pdwCertified) DECLSPEC_HIDDEN;
150
151 /*****************************************************************************
152  * IDirectSoundBuffer implementation structure
153  */
154 struct IDirectSoundBufferImpl
155 {
156     IDirectSoundBuffer8         IDirectSoundBuffer8_iface;
157     IDirectSoundNotify          IDirectSoundNotify_iface;
158     IDirectSound3DListener      IDirectSound3DListener_iface; /* only primary buffer */
159     IDirectSound3DBuffer        IDirectSound3DBuffer_iface; /* only secondary buffer */
160     IKsPropertySet              IKsPropertySet_iface;
161     LONG                        numIfaces; /* "in use interfaces" refcount */
162     LONG                        ref, refn, ref3D, refiks;
163     /* IDirectSoundBufferImpl fields */
164     DirectSoundDevice*          device;
165     RTL_RWLOCK                  lock;
166     PWAVEFORMATEX               pwfx;
167     BufferMemory*               buffer;
168     DWORD                       playflags,state,leadin;
169     DWORD                       writelead,buflen;
170     DWORD                       nAvgBytesPerSec;
171     DWORD                       freq;
172     DSVOLUMEPAN                 volpan;
173     DSBUFFERDESC                dsbd;
174     /* used for frequency conversion (PerfectPitch) */
175     ULONG                       freqneeded;
176     DWORD                       firstep;
177     float freqAcc, freqAdjust, firgain;
178     /* used for mixing */
179     DWORD                       sec_mixpos;
180
181     /* IDirectSoundNotify fields */
182     LPDSBPOSITIONNOTIFY         notifies;
183     int                         nrofnotifies;
184     /* DirectSound3DBuffer fields */
185     DS3DBUFFER                  ds3db_ds3db;
186     LONG                        ds3db_lVolume;
187     BOOL                        ds3db_need_recalc;
188     /* Used for bit depth conversion */
189     int                         mix_channels;
190     bitsgetfunc get, get_aux;
191     bitsputfunc put, put_aux;
192
193     struct list entry;
194 };
195
196 float get_mono(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel) DECLSPEC_HIDDEN;
197 void put_mono2stereo(const IDirectSoundBufferImpl *dsb, DWORD pos, DWORD channel, float value) DECLSPEC_HIDDEN;
198
199 HRESULT IDirectSoundBufferImpl_Create(
200     DirectSoundDevice *device,
201     IDirectSoundBufferImpl **ppdsb,
202     LPCDSBUFFERDESC dsbd) DECLSPEC_HIDDEN;
203 HRESULT IDirectSoundBufferImpl_Duplicate(
204     DirectSoundDevice *device,
205     IDirectSoundBufferImpl **ppdsb,
206     IDirectSoundBufferImpl *pdsb) DECLSPEC_HIDDEN;
207 void secondarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
208 const IDirectSound3DListenerVtbl ds3dlvt DECLSPEC_HIDDEN;
209 const IDirectSound3DBufferVtbl ds3dbvt DECLSPEC_HIDDEN;
210 const IKsPropertySetVtbl iksbvt DECLSPEC_HIDDEN;
211
212 /*****************************************************************************
213  * DirectSoundCaptureDevice implementation structure
214  */
215 struct DirectSoundCaptureDevice
216 {
217     GUID                               guid;
218     LONG                               ref;
219
220     DSCCAPS                            drvcaps;
221
222     LPBYTE                             buffer;
223     DWORD                              buflen, write_pos_bytes;
224
225     PWAVEFORMATEX                      pwfx;
226
227     IDirectSoundCaptureBufferImpl*     capture_buffer;
228     DWORD                              state;
229     UINT timerID;
230     CRITICAL_SECTION                   lock;
231
232     IMMDevice *mmdevice;
233     IAudioClient *client;
234     IAudioCaptureClient *capture;
235
236     struct list entry;
237 };
238
239 /*****************************************************************************
240  * IDirectSoundCaptureBuffer implementation structure
241  */
242 struct IDirectSoundCaptureBufferImpl
243 {
244     IDirectSoundCaptureBuffer8          IDirectSoundCaptureBuffer8_iface;
245     IDirectSoundNotify                  IDirectSoundNotify_iface;
246     LONG                                numIfaces; /* "in use interfaces" refcount */
247     LONG                                ref, refn;
248     /* IDirectSoundCaptureBuffer fields */
249     DirectSoundCaptureDevice*           device;
250     LPDSCBUFFERDESC                     pdscbd;
251     DWORD                               flags;
252     /* IDirectSoundNotify fields */
253     LPDSBPOSITIONNOTIFY                 notifies;
254     int                                 nrofnotifies;
255 };
256
257 HRESULT IKsPrivatePropertySetImpl_Create(REFIID riid, IKsPropertySet **piks) DECLSPEC_HIDDEN;
258
259 /*******************************************************************************
260  */
261
262 /* dsound.c */
263
264 HRESULT DSOUND_Create(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
265 HRESULT DSOUND_Create8(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
266 HRESULT IDirectSoundImpl_Create(IUnknown *outer_unk, REFIID riid, void **ppv, BOOL has_ds8) DECLSPEC_HIDDEN;
267
268 /* primary.c */
269
270 HRESULT DSOUND_PrimaryCreate(DirectSoundDevice *device) DECLSPEC_HIDDEN;
271 HRESULT DSOUND_PrimaryDestroy(DirectSoundDevice *device) DECLSPEC_HIDDEN;
272 HRESULT DSOUND_PrimaryPlay(DirectSoundDevice *device) DECLSPEC_HIDDEN;
273 HRESULT DSOUND_PrimaryStop(DirectSoundDevice *device) DECLSPEC_HIDDEN;
274 HRESULT DSOUND_PrimaryGetPosition(DirectSoundDevice *device, LPDWORD playpos, LPDWORD writepos) DECLSPEC_HIDDEN;
275 LPWAVEFORMATEX DSOUND_CopyFormat(LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
276 HRESULT DSOUND_ReopenDevice(DirectSoundDevice *device, BOOL forcewave) DECLSPEC_HIDDEN;
277 HRESULT primarybuffer_create(DirectSoundDevice *device, IDirectSoundBufferImpl **ppdsb,
278     const DSBUFFERDESC *dsbd) DECLSPEC_HIDDEN;
279 void primarybuffer_destroy(IDirectSoundBufferImpl *This) DECLSPEC_HIDDEN;
280 HRESULT primarybuffer_SetFormat(DirectSoundDevice *device, LPCWAVEFORMATEX wfex) DECLSPEC_HIDDEN;
281 LONG capped_refcount_dec(LONG *ref) DECLSPEC_HIDDEN;
282
283 /* duplex.c */
284
285 HRESULT DSOUND_FullDuplexCreate(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
286
287 /* mixer.c */
288 void DSOUND_CheckEvent(const IDirectSoundBufferImpl *dsb, DWORD playpos, int len) DECLSPEC_HIDDEN;
289 void DSOUND_RecalcVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
290 void DSOUND_AmpFactorToVolPan(PDSVOLUMEPAN volpan) DECLSPEC_HIDDEN;
291 void DSOUND_RecalcFormat(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
292 DWORD DSOUND_secpos_to_bufpos(const IDirectSoundBufferImpl *dsb, DWORD secpos, DWORD secmixpos, float *overshot) DECLSPEC_HIDDEN;
293
294 void CALLBACK DSOUND_timer(UINT timerID, UINT msg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) DECLSPEC_HIDDEN;
295
296 /* sound3d.c */
297
298 void DSOUND_Calc3DBuffer(IDirectSoundBufferImpl *dsb) DECLSPEC_HIDDEN;
299
300 /* capture.c */
301  
302 HRESULT DSOUND_CaptureCreate(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
303 HRESULT DSOUND_CaptureCreate8(REFIID riid, void **ppv) DECLSPEC_HIDDEN;
304 HRESULT IDirectSoundCaptureImpl_Create(IUnknown *outer_unk, REFIID riid, void **ppv, BOOL has_dsc8) DECLSPEC_HIDDEN;
305
306 #define STATE_STOPPED   0
307 #define STATE_STARTING  1
308 #define STATE_PLAYING   2
309 #define STATE_CAPTURING 2
310 #define STATE_STOPPING  3
311
312 extern CRITICAL_SECTION DSOUND_renderers_lock DECLSPEC_HIDDEN;
313 extern CRITICAL_SECTION DSOUND_capturers_lock DECLSPEC_HIDDEN;
314 extern struct list DSOUND_capturers DECLSPEC_HIDDEN;
315 extern struct list DSOUND_renderers DECLSPEC_HIDDEN;
316
317 extern GUID DSOUND_renderer_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
318 extern GUID DSOUND_capture_guids[MAXWAVEDRIVERS] DECLSPEC_HIDDEN;
319
320 extern WCHAR wine_vxd_drv[] DECLSPEC_HIDDEN;
321
322 void setup_dsound_options(void) DECLSPEC_HIDDEN;
323 const char * dumpCooperativeLevel(DWORD level) DECLSPEC_HIDDEN;
324
325 HRESULT get_mmdevice(EDataFlow flow, const GUID *tgt, IMMDevice **device) DECLSPEC_HIDDEN;
326
327 BOOL DSOUND_check_supported(IAudioClient *client, DWORD rate,
328         DWORD depth, WORD channels) DECLSPEC_HIDDEN;
329 UINT DSOUND_create_timer(LPTIMECALLBACK cb, DWORD_PTR user) DECLSPEC_HIDDEN;
330 HRESULT enumerate_mmdevices(EDataFlow flow, GUID *guids,
331         LPDSENUMCALLBACKW cb, void *user) DECLSPEC_HIDDEN;