1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
3 * Sample Wine Driver for Open Sound System (featured in Linux and FreeBSD)
5 * Copyright 1994 Martin Ayotte
6 * 1999 Eric Pouech (async playing in waveOut/waveIn)
7 * 2000 Eric Pouech (loops in waveOut)
8 * 2002 Eric Pouech (full duplex)
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * pause in waveOut does not work correctly in loop mode
27 * Direct Sound Capture driver does not work (not complete yet)
30 /*#define EMULATE_SB16*/
32 /* unless someone makes a wineserver kernel module, Unix pipes are faster than win32 events */
35 /* an exact wodGetPosition is usually not worth the extra context switches,
36 * as we're going to have near fragment accuracy anyway */
37 #define EXACT_WODPOSITION
38 #define EXACT_WIDPOSITION
41 #include "wine/port.h"
52 #ifdef HAVE_SYS_IOCTL_H
53 # include <sys/ioctl.h>
55 #ifdef HAVE_SYS_MMAN_H
56 # include <sys/mman.h>
58 #ifdef HAVE_SYS_POLL_H
59 # include <sys/poll.h>
66 #include "wine/winuser16.h"
75 #include "wine/debug.h"
77 WINE_DEFAULT_DEBUG_CHANNEL(wave
);
79 /* Allow 1% deviation for sample rates (some ES137x cards) */
80 #define NEAR_MATCH(rate1,rate2) (((100*((int)(rate1)-(int)(rate2)))/(rate1))==0)
84 #define MAX_WAVEDRV (6)
86 /* state diagram for waveOut writing:
88 * +---------+-------------+---------------+---------------------------------+
89 * | state | function | event | new state |
90 * +---------+-------------+---------------+---------------------------------+
91 * | | open() | | STOPPED |
92 * | PAUSED | write() | | PAUSED |
93 * | STOPPED | write() | <thrd create> | PLAYING |
94 * | PLAYING | write() | HEADER | PLAYING |
95 * | (other) | write() | <error> | |
96 * | (any) | pause() | PAUSING | PAUSED |
97 * | PAUSED | restart() | RESTARTING | PLAYING (if no thrd => STOPPED) |
98 * | (any) | reset() | RESETTING | STOPPED |
99 * | (any) | close() | CLOSING | CLOSED |
100 * +---------+-------------+---------------+---------------------------------+
103 /* states of the playing device */
104 #define WINE_WS_PLAYING 0
105 #define WINE_WS_PAUSED 1
106 #define WINE_WS_STOPPED 2
107 #define WINE_WS_CLOSED 3
109 /* events to be send to device */
110 enum win_wm_message
{
111 WINE_WM_PAUSING
= WM_USER
+ 1, WINE_WM_RESTARTING
, WINE_WM_RESETTING
, WINE_WM_HEADER
,
112 WINE_WM_UPDATE
, WINE_WM_BREAKLOOP
, WINE_WM_CLOSING
, WINE_WM_STARTING
, WINE_WM_STOPPING
116 #define SIGNAL_OMR(omr) do { int x = 0; write((omr)->msg_pipe[1], &x, sizeof(x)); } while (0)
117 #define CLEAR_OMR(omr) do { int x = 0; read((omr)->msg_pipe[0], &x, sizeof(x)); } while (0)
118 #define RESET_OMR(omr) do { } while (0)
119 #define WAIT_OMR(omr, sleep) \
120 do { struct pollfd pfd; pfd.fd = (omr)->msg_pipe[0]; \
121 pfd.events = POLLIN; poll(&pfd, 1, sleep); } while (0)
123 #define SIGNAL_OMR(omr) do { SetEvent((omr)->msg_event); } while (0)
124 #define CLEAR_OMR(omr) do { } while (0)
125 #define RESET_OMR(omr) do { ResetEvent((omr)->msg_event); } while (0)
126 #define WAIT_OMR(omr, sleep) \
127 do { WaitForSingleObject((omr)->msg_event, sleep); } while (0)
131 enum win_wm_message msg
; /* message identifier */
132 DWORD param
; /* parameter for this message */
133 HANDLE hEvent
; /* if message is synchronous, handle of event for synchro */
136 /* implement an in-process message ring for better performance
137 * (compared to passing thru the server)
138 * this ring will be used by the input (resp output) record (resp playback) routine
140 #define OSS_RING_BUFFER_INCREMENT 64
142 int ring_buffer_size
;
151 CRITICAL_SECTION msg_crst
;
154 typedef struct tagOSS_DEVICE
{
157 char interface_name
[64];
159 WAVEOUTCAPSA out_caps
;
160 WAVEOUTCAPSA duplex_out_caps
;
162 DWORD in_caps_support
;
163 unsigned open_access
;
169 unsigned audio_fragment
;
171 BOOL bTriggerSupport
;
174 DSDRIVERDESC ds_desc
;
175 DSDRIVERCAPS ds_caps
;
176 DSCDRIVERCAPS dsc_caps
;
179 static OSS_DEVICE OSS_Devices
[MAX_WAVEDRV
];
183 volatile int state
; /* one of the WINE_WS_ manifest constants */
184 WAVEOPENDESC waveDesc
;
186 WAVEFORMATPCMEX waveFormat
;
189 /* OSS information */
190 DWORD dwFragmentSize
; /* size of OSS buffer fragment */
191 DWORD dwBufferSize
; /* size of whole OSS buffer in bytes */
192 LPWAVEHDR lpQueuePtr
; /* start of queued WAVEHDRs (waiting to be notified) */
193 LPWAVEHDR lpPlayPtr
; /* start of not yet fully played buffers */
194 DWORD dwPartialOffset
; /* Offset of not yet written bytes in lpPlayPtr */
196 LPWAVEHDR lpLoopPtr
; /* pointer of first buffer in loop, if any */
197 DWORD dwLoops
; /* private copy of loop counter */
199 DWORD dwPlayedTotal
; /* number of bytes actually played since opening */
200 DWORD dwWrittenTotal
; /* number of bytes written to OSS buffer since opening */
201 BOOL bNeedPost
; /* whether audio still needs to be physically started */
203 /* synchronization stuff */
204 HANDLE hStartUpEvent
;
207 OSS_MSG_RING msgRing
;
213 DWORD dwFragmentSize
; /* OpenSound '/dev/dsp' give us that size */
214 WAVEOPENDESC waveDesc
;
216 WAVEFORMATPCMEX waveFormat
;
217 LPWAVEHDR lpQueuePtr
;
218 DWORD dwTotalRecorded
;
221 /* synchronization stuff */
224 HANDLE hStartUpEvent
;
225 OSS_MSG_RING msgRing
;
228 static WINE_WAVEOUT WOutDev
[MAX_WAVEDRV
];
229 static WINE_WAVEIN WInDev
[MAX_WAVEDRV
];
230 static unsigned numOutDev
;
231 static unsigned numInDev
;
233 static DWORD
wodDsCreate(UINT wDevID
, PIDSDRIVER
* drv
);
234 static DWORD
widDsCreate(UINT wDevID
, PIDSCDRIVER
* drv
);
235 static DWORD
wodDsDesc(UINT wDevID
, PDSDRIVERDESC desc
);
236 static DWORD
widDsDesc(UINT wDevID
, PDSDRIVERDESC desc
);
238 /* These strings used only for tracing */
239 static const char * getCmdString(enum win_wm_message msg
)
241 static char unknown
[32];
242 #define MSG_TO_STR(x) case x: return #x
244 MSG_TO_STR(WINE_WM_PAUSING
);
245 MSG_TO_STR(WINE_WM_RESTARTING
);
246 MSG_TO_STR(WINE_WM_RESETTING
);
247 MSG_TO_STR(WINE_WM_HEADER
);
248 MSG_TO_STR(WINE_WM_UPDATE
);
249 MSG_TO_STR(WINE_WM_BREAKLOOP
);
250 MSG_TO_STR(WINE_WM_CLOSING
);
251 MSG_TO_STR(WINE_WM_STARTING
);
252 MSG_TO_STR(WINE_WM_STOPPING
);
255 sprintf(unknown
, "UNKNOWN(0x%08x)", msg
);
259 static int getEnables(OSS_DEVICE
*ossdev
)
261 return ( (ossdev
->bOutputEnabled
? PCM_ENABLE_OUTPUT
: 0) |
262 (ossdev
->bInputEnabled
? PCM_ENABLE_INPUT
: 0) );
265 static const char * getMessage(UINT msg
)
267 static char unknown
[32];
268 #define MSG_TO_STR(x) case x: return #x
270 MSG_TO_STR(DRVM_INIT
);
271 MSG_TO_STR(DRVM_EXIT
);
272 MSG_TO_STR(DRVM_ENABLE
);
273 MSG_TO_STR(DRVM_DISABLE
);
274 MSG_TO_STR(WIDM_OPEN
);
275 MSG_TO_STR(WIDM_CLOSE
);
276 MSG_TO_STR(WIDM_ADDBUFFER
);
277 MSG_TO_STR(WIDM_PREPARE
);
278 MSG_TO_STR(WIDM_UNPREPARE
);
279 MSG_TO_STR(WIDM_GETDEVCAPS
);
280 MSG_TO_STR(WIDM_GETNUMDEVS
);
281 MSG_TO_STR(WIDM_GETPOS
);
282 MSG_TO_STR(WIDM_RESET
);
283 MSG_TO_STR(WIDM_START
);
284 MSG_TO_STR(WIDM_STOP
);
285 MSG_TO_STR(WODM_OPEN
);
286 MSG_TO_STR(WODM_CLOSE
);
287 MSG_TO_STR(WODM_WRITE
);
288 MSG_TO_STR(WODM_PAUSE
);
289 MSG_TO_STR(WODM_GETPOS
);
290 MSG_TO_STR(WODM_BREAKLOOP
);
291 MSG_TO_STR(WODM_PREPARE
);
292 MSG_TO_STR(WODM_UNPREPARE
);
293 MSG_TO_STR(WODM_GETDEVCAPS
);
294 MSG_TO_STR(WODM_GETNUMDEVS
);
295 MSG_TO_STR(WODM_GETPITCH
);
296 MSG_TO_STR(WODM_SETPITCH
);
297 MSG_TO_STR(WODM_GETPLAYBACKRATE
);
298 MSG_TO_STR(WODM_SETPLAYBACKRATE
);
299 MSG_TO_STR(WODM_GETVOLUME
);
300 MSG_TO_STR(WODM_SETVOLUME
);
301 MSG_TO_STR(WODM_RESTART
);
302 MSG_TO_STR(WODM_RESET
);
303 MSG_TO_STR(DRV_QUERYDEVICEINTERFACESIZE
);
304 MSG_TO_STR(DRV_QUERYDEVICEINTERFACE
);
305 MSG_TO_STR(DRV_QUERYDSOUNDIFACE
);
306 MSG_TO_STR(DRV_QUERYDSOUNDDESC
);
309 sprintf(unknown
, "UNKNOWN(0x%04x)", msg
);
313 static DWORD
wdDevInterfaceSize(UINT wDevID
, LPDWORD dwParam1
)
315 TRACE("(%u, %p)\n", wDevID
, dwParam1
);
317 *dwParam1
= MultiByteToWideChar(CP_ACP
, 0, OSS_Devices
[wDevID
].interface_name
, -1,
318 NULL
, 0 ) * sizeof(WCHAR
);
319 return MMSYSERR_NOERROR
;
322 static DWORD
wdDevInterface(UINT wDevID
, PWCHAR dwParam1
, DWORD dwParam2
)
324 if (dwParam2
>= MultiByteToWideChar(CP_ACP
, 0, OSS_Devices
[wDevID
].interface_name
, -1,
325 NULL
, 0 ) * sizeof(WCHAR
))
327 MultiByteToWideChar(CP_ACP
, 0, OSS_Devices
[wDevID
].interface_name
, -1,
328 dwParam1
, dwParam2
/ sizeof(WCHAR
));
329 return MMSYSERR_NOERROR
;
332 return MMSYSERR_INVALPARAM
;
335 static DWORD
bytes_to_mmtime(LPMMTIME lpTime
, DWORD position
,
336 WAVEFORMATPCMEX
* format
)
338 TRACE("wType=%04X wBitsPerSample=%u nSamplesPerSec=%lu nChannels=%u nAvgBytesPerSec=%lu\n",
339 lpTime
->wType
, format
->Format
.wBitsPerSample
, format
->Format
.nSamplesPerSec
,
340 format
->Format
.nChannels
, format
->Format
.nAvgBytesPerSec
);
341 TRACE("Position in bytes=%lu\n", position
);
343 switch (lpTime
->wType
) {
345 lpTime
->u
.sample
= position
/ (format
->Format
.wBitsPerSample
/ 8 * format
->Format
.nChannels
);
346 TRACE("TIME_SAMPLES=%lu\n", lpTime
->u
.sample
);
349 lpTime
->u
.ms
= 1000.0 * position
/ (format
->Format
.wBitsPerSample
/ 8 * format
->Format
.nChannels
* format
->Format
.nSamplesPerSec
);
350 TRACE("TIME_MS=%lu\n", lpTime
->u
.ms
);
353 position
= position
/ (format
->Format
.wBitsPerSample
/ 8 * format
->Format
.nChannels
);
354 lpTime
->u
.smpte
.sec
= position
/ format
->Format
.nSamplesPerSec
;
355 position
-= lpTime
->u
.smpte
.sec
* format
->Format
.nSamplesPerSec
;
356 lpTime
->u
.smpte
.min
= lpTime
->u
.smpte
.sec
/ 60;
357 lpTime
->u
.smpte
.sec
-= 60 * lpTime
->u
.smpte
.min
;
358 lpTime
->u
.smpte
.hour
= lpTime
->u
.smpte
.min
/ 60;
359 lpTime
->u
.smpte
.min
-= 60 * lpTime
->u
.smpte
.hour
;
360 lpTime
->u
.smpte
.fps
= 30;
361 lpTime
->u
.smpte
.frame
= position
* lpTime
->u
.smpte
.fps
/ format
->Format
.nSamplesPerSec
;
362 position
-= lpTime
->u
.smpte
.frame
* format
->Format
.nSamplesPerSec
/ lpTime
->u
.smpte
.fps
;
366 lpTime
->u
.smpte
.frame
++;
368 TRACE("TIME_SMPTE=%02u:%02u:%02u:%02u\n",
369 lpTime
->u
.smpte
.hour
, lpTime
->u
.smpte
.min
,
370 lpTime
->u
.smpte
.sec
, lpTime
->u
.smpte
.frame
);
373 FIXME("Format %d not supported ! use TIME_BYTES !\n", lpTime
->wType
);
374 lpTime
->wType
= TIME_BYTES
;
377 lpTime
->u
.cb
= position
;
378 TRACE("TIME_BYTES=%lu\n", lpTime
->u
.cb
);
381 return MMSYSERR_NOERROR
;
384 static BOOL
supportedFormat(LPWAVEFORMATEX wf
)
388 if (wf
->nSamplesPerSec
<DSBFREQUENCY_MIN
||wf
->nSamplesPerSec
>DSBFREQUENCY_MAX
)
391 if (wf
->wFormatTag
== WAVE_FORMAT_PCM
) {
392 if (wf
->nChannels
==1||wf
->nChannels
==2) {
393 if (wf
->wBitsPerSample
==8||wf
->wBitsPerSample
==16)
396 } else if (wf
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
) {
397 WAVEFORMATEXTENSIBLE
* wfex
= (WAVEFORMATEXTENSIBLE
*)wf
;
399 if (wf
->cbSize
== 22 && IsEqualGUID(&wfex
->SubFormat
, &KSDATAFORMAT_SUBTYPE_PCM
)) {
400 if (wf
->nChannels
==1||wf
->nChannels
==2) {
401 if (wf
->wBitsPerSample
==wfex
->Samples
.wValidBitsPerSample
) {
402 if (wf
->wBitsPerSample
==8||wf
->wBitsPerSample
==16)
405 WARN("wBitsPerSample != wValidBitsPerSample not supported yet\n");
408 WARN("only KSDATAFORMAT_SUBTYPE_PCM supported\n");
410 WARN("only WAVE_FORMAT_PCM and WAVE_FORMAT_EXTENSIBLE supported\n");
415 static void copy_format(LPWAVEFORMATEX wf1
, LPWAVEFORMATPCMEX wf2
)
417 ZeroMemory(wf2
, sizeof(wf2
));
418 if (wf1
->wFormatTag
== WAVE_FORMAT_PCM
)
419 memcpy(wf2
, wf1
, sizeof(PCMWAVEFORMAT
));
420 else if (wf1
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
)
421 memcpy(wf2
, wf1
, sizeof(WAVEFORMATPCMEX
));
423 memcpy(wf2
, wf1
, sizeof(WAVEFORMATEX
) + wf1
->cbSize
);
426 /*======================================================================*
427 * Low level WAVE implementation *
428 *======================================================================*/
430 /******************************************************************
433 * Low level device opening (from values stored in ossdev)
435 static DWORD
OSS_RawOpenDevice(OSS_DEVICE
* ossdev
, int strict_format
)
438 TRACE("(%p,%d)\n",ossdev
,strict_format
);
440 TRACE("open_access=%s\n",
441 ossdev
->open_access
== O_RDONLY
? "O_RDONLY" :
442 ossdev
->open_access
== O_WRONLY
? "O_WRONLY" :
443 ossdev
->open_access
== O_RDWR
? "O_RDWR" : "Unknown");
445 if ((fd
= open(ossdev
->dev_name
, ossdev
->open_access
|O_NDELAY
, 0)) == -1)
447 WARN("Couldn't open %s (%s)\n", ossdev
->dev_name
, strerror(errno
));
448 return (errno
== EBUSY
) ? MMSYSERR_ALLOCATED
: MMSYSERR_ERROR
;
450 fcntl(fd
, F_SETFD
, 1); /* set close on exec flag */
451 /* turn full duplex on if it has been requested */
452 if (ossdev
->open_access
== O_RDWR
&& ossdev
->full_duplex
) {
453 rc
= ioctl(fd
, SNDCTL_DSP_SETDUPLEX
, 0);
454 /* on *BSD, as full duplex is always enabled by default, this ioctl
455 * will fail with EINVAL
456 * so, we don't consider EINVAL an error here
458 if (rc
!= 0 && errno
!= EINVAL
) {
459 WARN("ioctl(%s, SNDCTL_DSP_SETDUPLEX) failed (%s)\n", ossdev
->dev_name
, strerror(errno
));
464 if (ossdev
->audio_fragment
) {
465 rc
= ioctl(fd
, SNDCTL_DSP_SETFRAGMENT
, &ossdev
->audio_fragment
);
467 ERR("ioctl(%s, SNDCTL_DSP_SETFRAGMENT) failed (%s)\n", ossdev
->dev_name
, strerror(errno
));
472 /* First size and stereo then samplerate */
473 if (ossdev
->format
>=0)
475 val
= ossdev
->format
;
476 rc
= ioctl(fd
, SNDCTL_DSP_SETFMT
, &ossdev
->format
);
477 if (rc
!= 0 || val
!= ossdev
->format
) {
478 TRACE("Can't set format to %d (returned %d)\n", val
, ossdev
->format
);
483 if (ossdev
->stereo
>=0)
485 val
= ossdev
->stereo
;
486 rc
= ioctl(fd
, SNDCTL_DSP_STEREO
, &ossdev
->stereo
);
487 if (rc
!= 0 || val
!= ossdev
->stereo
) {
488 TRACE("Can't set stereo to %u (returned %d)\n", val
, ossdev
->stereo
);
493 if (ossdev
->sample_rate
>=0)
495 val
= ossdev
->sample_rate
;
496 rc
= ioctl(fd
, SNDCTL_DSP_SPEED
, &ossdev
->sample_rate
);
497 if (rc
!= 0 || !NEAR_MATCH(val
, ossdev
->sample_rate
)) {
498 TRACE("Can't set sample_rate to %u (returned %d)\n", val
, ossdev
->sample_rate
);
505 if (ossdev
->bTriggerSupport
) {
507 rc
= ioctl(fd
, SNDCTL_DSP_GETTRIGGER
, &trigger
);
509 ERR("ioctl(%s, SNDCTL_DSP_GETTRIGGER) failed (%s)\n",
510 ossdev
->dev_name
, strerror(errno
));
514 ossdev
->bOutputEnabled
= ((trigger
& PCM_ENABLE_OUTPUT
) == PCM_ENABLE_OUTPUT
);
515 ossdev
->bInputEnabled
= ((trigger
& PCM_ENABLE_INPUT
) == PCM_ENABLE_INPUT
);
517 ossdev
->bOutputEnabled
= TRUE
; /* OSS enables by default */
518 ossdev
->bInputEnabled
= TRUE
; /* OSS enables by default */
521 return MMSYSERR_NOERROR
;
525 return WAVERR_BADFORMAT
;
528 return MMSYSERR_ERROR
;
531 /******************************************************************
534 * since OSS has poor capabilities in full duplex, we try here to let a program
535 * open the device for both waveout and wavein streams...
536 * this is hackish, but it's the way OSS interface is done...
538 static DWORD
OSS_OpenDevice(OSS_DEVICE
* ossdev
, unsigned req_access
,
539 int* frag
, int strict_format
,
540 int sample_rate
, int stereo
, int fmt
)
544 TRACE("(%p,%u,%p,%d,%d,%d,%x)\n",ossdev
,req_access
,frag
,strict_format
,sample_rate
,stereo
,fmt
);
546 if (ossdev
->full_duplex
&& (req_access
== O_RDONLY
|| req_access
== O_WRONLY
))
548 TRACE("Opening RDWR because full_duplex=%d and req_access=%d\n",
549 ossdev
->full_duplex
,req_access
);
550 open_access
= O_RDWR
;
554 open_access
=req_access
;
557 /* FIXME: this should be protected, and it also contains a race with OSS_CloseDevice */
558 if (ossdev
->open_count
== 0)
560 if (access(ossdev
->dev_name
, 0) != 0) return MMSYSERR_NODRIVER
;
562 ossdev
->audio_fragment
= (frag
) ? *frag
: 0;
563 ossdev
->sample_rate
= sample_rate
;
564 ossdev
->stereo
= stereo
;
565 ossdev
->format
= fmt
;
566 ossdev
->open_access
= open_access
;
567 ossdev
->owner_tid
= GetCurrentThreadId();
569 if ((ret
= OSS_RawOpenDevice(ossdev
,strict_format
)) != MMSYSERR_NOERROR
) return ret
;
570 if (ossdev
->full_duplex
&& ossdev
->bTriggerSupport
&&
571 (req_access
== O_RDONLY
|| req_access
== O_WRONLY
))
574 if (req_access
== O_WRONLY
)
575 ossdev
->bInputEnabled
=0;
577 ossdev
->bOutputEnabled
=0;
578 enable
= getEnables(ossdev
);
579 TRACE("Calling SNDCTL_DSP_SETTRIGGER with %x\n",enable
);
580 if (ioctl(ossdev
->fd
, SNDCTL_DSP_SETTRIGGER
, &enable
) < 0)
581 ERR("ioctl(%s, SNDCTL_DSP_SETTRIGGER, %d) failed (%s)\n",ossdev
->dev_name
, enable
, strerror(errno
));
586 /* check we really open with the same parameters */
587 if (ossdev
->open_access
!= open_access
)
589 ERR("FullDuplex: Mismatch in access. Your sound device is not full duplex capable.\n");
590 return WAVERR_BADFORMAT
;
593 /* check if the audio parameters are the same */
594 if (ossdev
->sample_rate
!= sample_rate
||
595 ossdev
->stereo
!= stereo
||
596 ossdev
->format
!= fmt
)
598 /* This is not a fatal error because MSACM might do the remapping */
599 WARN("FullDuplex: mismatch in PCM parameters for input and output\n"
600 "OSS doesn't allow us different parameters\n"
601 "audio_frag(%x/%x) sample_rate(%d/%d) stereo(%d/%d) fmt(%d/%d)\n",
602 ossdev
->audio_fragment
, frag
? *frag
: 0,
603 ossdev
->sample_rate
, sample_rate
,
604 ossdev
->stereo
, stereo
,
605 ossdev
->format
, fmt
);
606 return WAVERR_BADFORMAT
;
608 /* check if the fragment sizes are the same */
609 if (ossdev
->audio_fragment
!= (frag
? *frag
: 0) ) {
610 ERR("FullDuplex: Playback and Capture hardware acceleration levels are different.\n"
611 "Use: \"HardwareAcceleration\" = \"Emulation\" in the [dsound] section of your config file.\n");
612 return WAVERR_BADFORMAT
;
614 if (GetCurrentThreadId() != ossdev
->owner_tid
)
616 WARN("Another thread is trying to access audio...\n");
617 return MMSYSERR_ERROR
;
619 if (ossdev
->full_duplex
&& ossdev
->bTriggerSupport
&&
620 (req_access
== O_RDONLY
|| req_access
== O_WRONLY
))
623 if (req_access
== O_WRONLY
)
624 ossdev
->bOutputEnabled
=1;
626 ossdev
->bInputEnabled
=1;
627 enable
= getEnables(ossdev
);
628 TRACE("Calling SNDCTL_DSP_SETTRIGGER with %x\n",enable
);
629 if (ioctl(ossdev
->fd
, SNDCTL_DSP_SETTRIGGER
, &enable
) < 0)
630 ERR("ioctl(%s, SNDCTL_DSP_SETTRIGGER, %d) failed (%s)\n",ossdev
->dev_name
, enable
, strerror(errno
));
634 ossdev
->open_count
++;
636 return MMSYSERR_NOERROR
;
639 /******************************************************************
644 static void OSS_CloseDevice(OSS_DEVICE
* ossdev
)
646 TRACE("(%p)\n",ossdev
);
647 if (ossdev
->open_count
>0) {
648 ossdev
->open_count
--;
650 WARN("OSS_CloseDevice called too many times\n");
652 if (ossdev
->open_count
== 0)
654 /* reset the device before we close it in case it is in a bad state */
655 ioctl(ossdev
->fd
, SNDCTL_DSP_RESET
, 0);
660 /******************************************************************
663 * Resets the device. OSS Commercial requires the device to be closed
664 * after a SNDCTL_DSP_RESET ioctl call... this function implements
666 * FIXME: This causes problems when doing full duplex so we really
667 * only reset when not doing full duplex. We need to do this better
670 static DWORD
OSS_ResetDevice(OSS_DEVICE
* ossdev
)
672 DWORD ret
= MMSYSERR_NOERROR
;
673 int old_fd
= ossdev
->fd
;
674 TRACE("(%p)\n", ossdev
);
676 if (ossdev
->open_count
== 1) {
677 if (ioctl(ossdev
->fd
, SNDCTL_DSP_RESET
, NULL
) == -1)
679 perror("ioctl SNDCTL_DSP_RESET");
683 ret
= OSS_RawOpenDevice(ossdev
, 1);
684 TRACE("Changing fd from %d to %d\n", old_fd
, ossdev
->fd
);
686 WARN("Not resetting device because it is in full duplex mode!\n");
691 const static int win_std_oss_fmts
[2]={AFMT_U8
,AFMT_S16_LE
};
692 const static int win_std_rates
[5]={96000,48000,44100,22050,11025};
693 const static int win_std_formats
[2][2][5]=
694 {{{WAVE_FORMAT_96M08
, WAVE_FORMAT_48M08
, WAVE_FORMAT_4M08
,
695 WAVE_FORMAT_2M08
, WAVE_FORMAT_1M08
},
696 {WAVE_FORMAT_96S08
, WAVE_FORMAT_48S08
, WAVE_FORMAT_4S08
,
697 WAVE_FORMAT_2S08
, WAVE_FORMAT_1S08
}},
698 {{WAVE_FORMAT_96M16
, WAVE_FORMAT_48M16
, WAVE_FORMAT_4M16
,
699 WAVE_FORMAT_2M16
, WAVE_FORMAT_1M16
},
700 {WAVE_FORMAT_96S16
, WAVE_FORMAT_48S16
, WAVE_FORMAT_4S16
,
701 WAVE_FORMAT_2S16
, WAVE_FORMAT_1S16
}},
704 static void OSS_Info(int fd
)
706 /* Note that this only reports the formats supported by the hardware.
707 * The driver may support other formats and do the conversions in
708 * software which is why we don't use this value
710 int oss_mask
, oss_caps
;
711 if (ioctl(fd
, SNDCTL_DSP_GETFMTS
, &oss_mask
) >= 0) {
712 TRACE("Formats=%08x ( ", oss_mask
);
713 if (oss_mask
& AFMT_MU_LAW
) TRACE("AFMT_MU_LAW ");
714 if (oss_mask
& AFMT_A_LAW
) TRACE("AFMT_A_LAW ");
715 if (oss_mask
& AFMT_IMA_ADPCM
) TRACE("AFMT_IMA_ADPCM ");
716 if (oss_mask
& AFMT_U8
) TRACE("AFMT_U8 ");
717 if (oss_mask
& AFMT_S16_LE
) TRACE("AFMT_S16_LE ");
718 if (oss_mask
& AFMT_S16_BE
) TRACE("AFMT_S16_BE ");
719 if (oss_mask
& AFMT_S8
) TRACE("AFMT_S8 ");
720 if (oss_mask
& AFMT_U16_LE
) TRACE("AFMT_U16_LE ");
721 if (oss_mask
& AFMT_U16_BE
) TRACE("AFMT_U16_BE ");
722 if (oss_mask
& AFMT_MPEG
) TRACE("AFMT_MPEG ");
724 if (oss_mask
& AFMT_AC3
) TRACE("AFMT_AC3 ");
727 if (oss_mask
& AFMT_VORBIS
) TRACE("AFMT_VORBIS ");
730 if (oss_mask
& AFMT_S32_LE
) TRACE("AFMT_S32_LE ");
733 if (oss_mask
& AFMT_S32_BE
) TRACE("AFMT_S32_BE ");
736 if (oss_mask
& AFMT_FLOAT
) TRACE("AFMT_FLOAT ");
739 if (oss_mask
& AFMT_S24_LE
) TRACE("AFMT_S24_LE ");
742 if (oss_mask
& AFMT_S24_BE
) TRACE("AFMT_S24_BE ");
744 #ifdef AFMT_SPDIF_RAW
745 if (oss_mask
& AFMT_SPDIF_RAW
) TRACE("AFMT_SPDIF_RAW ");
749 if (ioctl(fd
, SNDCTL_DSP_GETCAPS
, &oss_caps
) >= 0) {
750 TRACE("Caps=%08x\n",oss_caps
);
751 TRACE("\tRevision: %d\n", oss_caps
&DSP_CAP_REVISION
);
752 TRACE("\tDuplex: %s\n", oss_caps
& DSP_CAP_DUPLEX
? "true" : "false");
753 TRACE("\tRealtime: %s\n", oss_caps
& DSP_CAP_REALTIME
? "true" : "false");
754 TRACE("\tBatch: %s\n", oss_caps
& DSP_CAP_BATCH
? "true" : "false");
755 TRACE("\tCoproc: %s\n", oss_caps
& DSP_CAP_COPROC
? "true" : "false");
756 TRACE("\tTrigger: %s\n", oss_caps
& DSP_CAP_TRIGGER
? "true" : "false");
757 TRACE("\tMmap: %s\n", oss_caps
& DSP_CAP_MMAP
? "true" : "false");
759 TRACE("\tMulti: %s\n", oss_caps
& DSP_CAP_MULTI
? "true" : "false");
762 TRACE("\tBind: %s\n", oss_caps
& DSP_CAP_BIND
? "true" : "false");
765 TRACE("\tInput: %s\n", oss_caps
& DSP_CAP_INPUT
? "true" : "false");
767 #ifdef DSP_CAP_OUTPUT
768 TRACE("\tOutput: %s\n", oss_caps
& DSP_CAP_OUTPUT
? "true" : "false");
770 #ifdef DSP_CAP_VIRTUAL
771 TRACE("\tVirtual: %s\n", oss_caps
& DSP_CAP_VIRTUAL
? "true" : "false");
773 #ifdef DSP_CAP_ANALOGOUT
774 TRACE("\tAnalog Out: %s\n", oss_caps
& DSP_CAP_ANALOGOUT
? "true" : "false");
776 #ifdef DSP_CAP_ANALOGIN
777 TRACE("\tAnalog In: %s\n", oss_caps
& DSP_CAP_ANALOGIN
? "true" : "false");
779 #ifdef DSP_CAP_DIGITALOUT
780 TRACE("\tDigital Out: %s\n", oss_caps
& DSP_CAP_DIGITALOUT
? "true" : "false");
782 #ifdef DSP_CAP_DIGITALIN
783 TRACE("\tDigital In: %s\n", oss_caps
& DSP_CAP_DIGITALIN
? "true" : "false");
785 #ifdef DSP_CAP_ADMASK
786 TRACE("\tA/D Mask: %s\n", oss_caps
& DSP_CAP_ADMASK
? "true" : "false");
788 #ifdef DSP_CAP_SHADOW
789 TRACE("\tShadow: %s\n", oss_caps
& DSP_CAP_SHADOW
? "true" : "false");
792 TRACE("\tChannel Mask: %x\n", oss_caps
& DSP_CH_MASK
);
795 TRACE("\tSlave: %s\n", oss_caps
& DSP_CAP_SLAVE
? "true" : "false");
800 /******************************************************************
805 static BOOL
OSS_WaveOutInit(OSS_DEVICE
* ossdev
)
809 TRACE("(%p) %s\n", ossdev
, ossdev
->dev_name
);
811 if (OSS_OpenDevice(ossdev
, O_WRONLY
, NULL
, 0,-1,-1,-1) != 0)
814 ioctl(ossdev
->fd
, SNDCTL_DSP_RESET
, 0);
816 #ifdef SOUND_MIXER_INFO
819 if ((mixer
= open(ossdev
->mixer_name
, O_RDONLY
|O_NDELAY
)) >= 0) {
821 if (ioctl(mixer
, SOUND_MIXER_INFO
, &info
) >= 0) {
822 strncpy(ossdev
->ds_desc
.szDesc
, info
.name
, sizeof(info
.name
));
823 strcpy(ossdev
->ds_desc
.szDrvName
, "wineoss.drv");
824 strncpy(ossdev
->out_caps
.szPname
, info
.name
, sizeof(info
.name
));
825 TRACE("%s\n", ossdev
->ds_desc
.szDesc
);
827 /* FreeBSD up to at least 5.2 provides this ioctl, but does not
828 * implement it properly, and there are probably similar issues
829 * on other platforms, so we warn but try to go ahead.
831 WARN("%s: cannot read SOUND_MIXER_INFO!\n", ossdev
->mixer_name
);
835 ERR("%s: %s\n", ossdev
->mixer_name
, strerror( errno
));
836 OSS_CloseDevice(ossdev
);
840 #endif /* SOUND_MIXER_INFO */
842 if (WINE_TRACE_ON(wave
))
843 OSS_Info(ossdev
->fd
);
845 /* FIXME: some programs compare this string against the content of the
846 * registry for MM drivers. The names have to match in order for the
847 * program to work (e.g. MS win9x mplayer.exe)
850 ossdev
->out_caps
.wMid
= 0x0002;
851 ossdev
->out_caps
.wPid
= 0x0104;
852 strcpy(ossdev
->out_caps
.szPname
, "SB16 Wave Out");
854 ossdev
->out_caps
.wMid
= 0x00FF; /* Manufac ID */
855 ossdev
->out_caps
.wPid
= 0x0001; /* Product ID */
857 ossdev
->out_caps
.vDriverVersion
= 0x0100;
858 ossdev
->out_caps
.wChannels
= 1;
859 ossdev
->out_caps
.dwFormats
= 0x00000000;
860 ossdev
->out_caps
.wReserved1
= 0;
861 ossdev
->out_caps
.dwSupport
= WAVECAPS_VOLUME
;
863 /* direct sound caps */
864 ossdev
->ds_caps
.dwFlags
= DSCAPS_CERTIFIED
;
865 ossdev
->ds_caps
.dwPrimaryBuffers
= 1;
866 ossdev
->ds_caps
.dwMinSecondarySampleRate
= DSBFREQUENCY_MIN
;
867 ossdev
->ds_caps
.dwMaxSecondarySampleRate
= DSBFREQUENCY_MAX
;
869 /* We must first set the format and the stereo mode as some sound cards
870 * may support 44kHz mono but not 44kHz stereo. Also we must
871 * systematically check the return value of these ioctls as they will
872 * always succeed (see OSS Linux) but will modify the parameter to match
873 * whatever they support. The OSS specs also say we must first set the
874 * sample size, then the stereo and then the sample rate.
877 arg
=win_std_oss_fmts
[f
];
878 rc
=ioctl(ossdev
->fd
, SNDCTL_DSP_SAMPLESIZE
, &arg
);
879 if (rc
!=0 || arg
!=win_std_oss_fmts
[f
]) {
880 TRACE("DSP_SAMPLESIZE: rc=%d returned %d for %d\n",
881 rc
,arg
,win_std_oss_fmts
[f
]);
885 ossdev
->ds_caps
.dwFlags
|= DSCAPS_PRIMARY8BIT
;
887 ossdev
->ds_caps
.dwFlags
|= DSCAPS_PRIMARY16BIT
;
891 rc
=ioctl(ossdev
->fd
, SNDCTL_DSP_STEREO
, &arg
);
892 if (rc
!=0 || arg
!=c
) {
893 TRACE("DSP_STEREO: rc=%d returned %d for %d\n",rc
,arg
,c
);
897 ossdev
->ds_caps
.dwFlags
|= DSCAPS_PRIMARYMONO
;
899 ossdev
->out_caps
.wChannels
=2;
900 ossdev
->out_caps
.dwSupport
|=WAVECAPS_LRVOLUME
;
901 ossdev
->ds_caps
.dwFlags
|= DSCAPS_PRIMARYSTEREO
;
904 for (r
=0;r
<sizeof(win_std_rates
)/sizeof(*win_std_rates
);r
++) {
905 arg
=win_std_rates
[r
];
906 rc
=ioctl(ossdev
->fd
, SNDCTL_DSP_SPEED
, &arg
);
907 TRACE("DSP_SPEED: rc=%d returned %d for %dx%dx%d\n",
908 rc
,arg
,win_std_rates
[r
],win_std_oss_fmts
[f
],c
+1);
909 if (rc
==0 && arg
!=0 && NEAR_MATCH(arg
,win_std_rates
[r
]))
910 ossdev
->out_caps
.dwFormats
|=win_std_formats
[f
][c
][r
];
915 if (ioctl(ossdev
->fd
, SNDCTL_DSP_GETCAPS
, &arg
) == 0) {
916 if (arg
& DSP_CAP_TRIGGER
)
917 ossdev
->bTriggerSupport
= TRUE
;
918 if ((arg
& DSP_CAP_REALTIME
) && !(arg
& DSP_CAP_BATCH
)) {
919 ossdev
->out_caps
.dwSupport
|= WAVECAPS_SAMPLEACCURATE
;
921 /* well, might as well use the DirectSound cap flag for something */
922 if ((arg
& DSP_CAP_TRIGGER
) && (arg
& DSP_CAP_MMAP
) &&
923 !(arg
& DSP_CAP_BATCH
)) {
924 ossdev
->out_caps
.dwSupport
|= WAVECAPS_DIRECTSOUND
;
926 ossdev
->ds_caps
.dwFlags
|= DSCAPS_EMULDRIVER
;
928 #ifdef DSP_CAP_MULTI /* not every oss has this */
929 /* check for hardware secondary buffer support (multi open) */
930 if ((arg
& DSP_CAP_MULTI
) &&
931 (ossdev
->out_caps
.dwSupport
& WAVECAPS_DIRECTSOUND
)) {
932 TRACE("hardware secondary buffer support available\n");
933 if (ossdev
->ds_caps
.dwFlags
& DSCAPS_PRIMARY8BIT
)
934 ossdev
->ds_caps
.dwFlags
|= DSCAPS_SECONDARY8BIT
;
935 if (ossdev
->ds_caps
.dwFlags
& DSCAPS_PRIMARY16BIT
)
936 ossdev
->ds_caps
.dwFlags
|= DSCAPS_SECONDARY16BIT
;
937 if (ossdev
->ds_caps
.dwFlags
& DSCAPS_PRIMARYMONO
)
938 ossdev
->ds_caps
.dwFlags
|= DSCAPS_SECONDARYMONO
;
939 if (ossdev
->ds_caps
.dwFlags
& DSCAPS_PRIMARYSTEREO
)
940 ossdev
->ds_caps
.dwFlags
|= DSCAPS_SECONDARYSTEREO
;
942 ossdev
->ds_caps
.dwMaxHwMixingAllBuffers
= 16;
943 ossdev
->ds_caps
.dwMaxHwMixingStaticBuffers
= 0;
944 ossdev
->ds_caps
.dwMaxHwMixingStreamingBuffers
= 16;
946 ossdev
->ds_caps
.dwFreeHwMixingAllBuffers
= 16;
947 ossdev
->ds_caps
.dwFreeHwMixingStaticBuffers
= 0;
948 ossdev
->ds_caps
.dwFreeHwMixingStreamingBuffers
= 16;
952 OSS_CloseDevice(ossdev
);
953 TRACE("out dwFormats = %08lX, dwSupport = %08lX\n",
954 ossdev
->out_caps
.dwFormats
, ossdev
->out_caps
.dwSupport
);
958 /******************************************************************
963 static BOOL
OSS_WaveInInit(OSS_DEVICE
* ossdev
)
967 TRACE("(%p) %s\n", ossdev
, ossdev
->dev_name
);
969 if (OSS_OpenDevice(ossdev
, O_RDONLY
, NULL
, 0,-1,-1,-1) != 0)
972 ioctl(ossdev
->fd
, SNDCTL_DSP_RESET
, 0);
974 #ifdef SOUND_MIXER_INFO
977 if ((mixer
= open(ossdev
->mixer_name
, O_RDONLY
|O_NDELAY
)) >= 0) {
979 if (ioctl(mixer
, SOUND_MIXER_INFO
, &info
) >= 0) {
980 strncpy(ossdev
->in_caps
.szPname
, info
.name
, sizeof(info
.name
));
981 TRACE("%s\n", ossdev
->ds_desc
.szDesc
);
983 /* FreeBSD up to at least 5.2 provides this ioctl, but does not
984 * implement it properly, and there are probably similar issues
985 * on other platforms, so we warn but try to go ahead.
987 WARN("%s: cannot read SOUND_MIXER_INFO!\n", ossdev
->mixer_name
);
991 ERR("%s: %s\n", ossdev
->mixer_name
, strerror(errno
));
992 OSS_CloseDevice(ossdev
);
996 #endif /* SOUND_MIXER_INFO */
998 if (WINE_TRACE_ON(wave
))
999 OSS_Info(ossdev
->fd
);
1001 /* See comment in OSS_WaveOutInit */
1003 ossdev
->in_caps
.wMid
= 0x0002;
1004 ossdev
->in_caps
.wPid
= 0x0004;
1005 strcpy(ossdev
->in_caps
.szPname
, "SB16 Wave In");
1007 ossdev
->in_caps
.wMid
= 0x00FF; /* Manufac ID */
1008 ossdev
->in_caps
.wPid
= 0x0001; /* Product ID */
1010 ossdev
->in_caps
.dwFormats
= 0x00000000;
1011 ossdev
->in_caps
.wChannels
= 1;
1012 ossdev
->in_caps
.wReserved1
= 0;
1014 /* direct sound caps */
1015 ossdev
->dsc_caps
.dwSize
= sizeof(ossdev
->dsc_caps
);
1016 ossdev
->dsc_caps
.dwFlags
= 0;
1017 ossdev
->dsc_caps
.dwFormats
= 0x00000000;
1018 ossdev
->dsc_caps
.dwChannels
= 1;
1020 /* See the comment in OSS_WaveOutInit for the loop order */
1022 arg
=win_std_oss_fmts
[f
];
1023 rc
=ioctl(ossdev
->fd
, SNDCTL_DSP_SAMPLESIZE
, &arg
);
1024 if (rc
!=0 || arg
!=win_std_oss_fmts
[f
]) {
1025 TRACE("DSP_SAMPLESIZE: rc=%d returned 0x%x for 0x%x\n",
1026 rc
,arg
,win_std_oss_fmts
[f
]);
1032 rc
=ioctl(ossdev
->fd
, SNDCTL_DSP_STEREO
, &arg
);
1033 if (rc
!=0 || arg
!=c
) {
1034 TRACE("DSP_STEREO: rc=%d returned %d for %d\n",rc
,arg
,c
);
1038 ossdev
->in_caps
.wChannels
=2;
1039 ossdev
->dsc_caps
.dwChannels
=2;
1042 for (r
=0;r
<sizeof(win_std_rates
)/sizeof(*win_std_rates
);r
++) {
1043 arg
=win_std_rates
[r
];
1044 rc
=ioctl(ossdev
->fd
, SNDCTL_DSP_SPEED
, &arg
);
1045 TRACE("DSP_SPEED: rc=%d returned %d for %dx%dx%d\n",rc
,arg
,win_std_rates
[r
],win_std_oss_fmts
[f
],c
+1);
1046 if (rc
==0 && NEAR_MATCH(arg
,win_std_rates
[r
]))
1047 ossdev
->in_caps
.dwFormats
|=win_std_formats
[f
][c
][r
];
1048 ossdev
->dsc_caps
.dwFormats
|=win_std_formats
[f
][c
][r
];
1053 if (ioctl(ossdev
->fd
, SNDCTL_DSP_GETCAPS
, &arg
) == 0) {
1054 if (arg
& DSP_CAP_TRIGGER
)
1055 ossdev
->bTriggerSupport
= TRUE
;
1056 if ((arg
& DSP_CAP_TRIGGER
) && (arg
& DSP_CAP_MMAP
) &&
1057 !(arg
& DSP_CAP_BATCH
)) {
1058 /* FIXME: enable the next statement if you want to work on the driver */
1060 ossdev
->in_caps_support
|= WAVECAPS_DIRECTSOUND
;
1063 if ((arg
& DSP_CAP_REALTIME
) && !(arg
& DSP_CAP_BATCH
))
1064 ossdev
->in_caps_support
|= WAVECAPS_SAMPLEACCURATE
;
1066 OSS_CloseDevice(ossdev
);
1067 TRACE("in dwFormats = %08lX, in_caps_support = %08lX\n",
1068 ossdev
->in_caps
.dwFormats
, ossdev
->in_caps_support
);
1072 /******************************************************************
1073 * OSS_WaveFullDuplexInit
1077 static void OSS_WaveFullDuplexInit(OSS_DEVICE
* ossdev
)
1082 TRACE("(%p) %s\n", ossdev
, ossdev
->dev_name
);
1084 /* The OSS documentation says we must call SNDCTL_SETDUPLEX
1085 * *before* checking for SNDCTL_DSP_GETCAPS otherwise we may
1086 * get the wrong result. This ioctl must even be done before
1087 * setting the fragment size so that only OSS_RawOpenDevice is
1088 * in a position to do it. So we set full_duplex speculatively
1089 * and adjust right after.
1091 ossdev
->full_duplex
=1;
1092 rc
=OSS_OpenDevice(ossdev
, O_RDWR
, NULL
, 0,-1,-1,-1);
1093 ossdev
->full_duplex
=0;
1097 ioctl(ossdev
->fd
, SNDCTL_DSP_RESET
, 0);
1098 TRACE("%s\n", ossdev
->ds_desc
.szDesc
);
1101 if (ioctl(ossdev
->fd
, SNDCTL_DSP_GETCAPS
, &caps
) == 0)
1102 ossdev
->full_duplex
= (caps
& DSP_CAP_DUPLEX
);
1104 ossdev
->duplex_out_caps
= ossdev
->out_caps
;
1106 ossdev
->duplex_out_caps
.wChannels
= 1;
1107 ossdev
->duplex_out_caps
.dwFormats
= 0x00000000;
1108 ossdev
->duplex_out_caps
.dwSupport
= WAVECAPS_VOLUME
;
1110 if (WINE_TRACE_ON(wave
))
1111 OSS_Info(ossdev
->fd
);
1113 /* See the comment in OSS_WaveOutInit for the loop order */
1115 arg
=win_std_oss_fmts
[f
];
1116 rc
=ioctl(ossdev
->fd
, SNDCTL_DSP_SAMPLESIZE
, &arg
);
1117 if (rc
!=0 || arg
!=win_std_oss_fmts
[f
]) {
1118 TRACE("DSP_SAMPLESIZE: rc=%d returned 0x%x for 0x%x\n",
1119 rc
,arg
,win_std_oss_fmts
[f
]);
1125 rc
=ioctl(ossdev
->fd
, SNDCTL_DSP_STEREO
, &arg
);
1126 if (rc
!=0 || arg
!=c
) {
1127 TRACE("DSP_STEREO: rc=%d returned %d for %d\n",rc
,arg
,c
);
1131 ossdev
->ds_caps
.dwFlags
|= DSCAPS_PRIMARYMONO
;
1133 ossdev
->duplex_out_caps
.wChannels
=2;
1134 ossdev
->duplex_out_caps
.dwSupport
|=WAVECAPS_LRVOLUME
;
1135 ossdev
->ds_caps
.dwFlags
|= DSCAPS_PRIMARYSTEREO
;
1138 for (r
=0;r
<sizeof(win_std_rates
)/sizeof(*win_std_rates
);r
++) {
1139 arg
=win_std_rates
[r
];
1140 rc
=ioctl(ossdev
->fd
, SNDCTL_DSP_SPEED
, &arg
);
1141 TRACE("DSP_SPEED: rc=%d returned %d for %dx%dx%d\n",
1142 rc
,arg
,win_std_rates
[r
],win_std_oss_fmts
[f
],c
+1);
1143 if (rc
==0 && arg
!=0 && NEAR_MATCH(arg
,win_std_rates
[r
]))
1144 ossdev
->duplex_out_caps
.dwFormats
|=win_std_formats
[f
][c
][r
];
1149 if (ioctl(ossdev
->fd
, SNDCTL_DSP_GETCAPS
, &arg
) == 0) {
1150 if ((arg
& DSP_CAP_REALTIME
) && !(arg
& DSP_CAP_BATCH
)) {
1151 ossdev
->duplex_out_caps
.dwSupport
|= WAVECAPS_SAMPLEACCURATE
;
1153 /* well, might as well use the DirectSound cap flag for something */
1154 if ((arg
& DSP_CAP_TRIGGER
) && (arg
& DSP_CAP_MMAP
) &&
1155 !(arg
& DSP_CAP_BATCH
)) {
1156 ossdev
->duplex_out_caps
.dwSupport
|= WAVECAPS_DIRECTSOUND
;
1159 OSS_CloseDevice(ossdev
);
1160 TRACE("duplex dwFormats = %08lX, dwSupport = %08lX\n",
1161 ossdev
->duplex_out_caps
.dwFormats
, ossdev
->duplex_out_caps
.dwSupport
);
1164 /******************************************************************
1167 * Initialize internal structures from OSS information
1169 LONG
OSS_WaveInit(void)
1174 for (i
= 0; i
< MAX_WAVEDRV
; ++i
)
1177 sprintf((char *)OSS_Devices
[i
].dev_name
, "/dev/dsp");
1178 sprintf((char *)OSS_Devices
[i
].mixer_name
, "/dev/mixer");
1180 sprintf((char *)OSS_Devices
[i
].dev_name
, "/dev/dsp%d", i
);
1181 sprintf((char *)OSS_Devices
[i
].mixer_name
, "/dev/mixer%d", i
);
1184 sprintf(OSS_Devices
[i
].interface_name
, "wineoss: %s", OSS_Devices
[i
].dev_name
);
1187 /* start with output devices */
1188 for (i
= 0; i
< MAX_WAVEDRV
; ++i
)
1190 if (OSS_WaveOutInit(&OSS_Devices
[i
]))
1192 WOutDev
[numOutDev
].state
= WINE_WS_CLOSED
;
1193 WOutDev
[numOutDev
].ossdev
= &OSS_Devices
[i
];
1194 WOutDev
[numOutDev
].volume
= 0xffffffff;
1199 /* then do input devices */
1200 for (i
= 0; i
< MAX_WAVEDRV
; ++i
)
1202 if (OSS_WaveInInit(&OSS_Devices
[i
]))
1204 WInDev
[numInDev
].state
= WINE_WS_CLOSED
;
1205 WInDev
[numInDev
].ossdev
= &OSS_Devices
[i
];
1210 /* finish with the full duplex bits */
1211 for (i
= 0; i
< MAX_WAVEDRV
; i
++)
1212 OSS_WaveFullDuplexInit(&OSS_Devices
[i
]);
1217 /******************************************************************
1218 * OSS_InitRingMessage
1220 * Initialize the ring of messages for passing between driver's caller and playback/record
1223 static int OSS_InitRingMessage(OSS_MSG_RING
* omr
)
1226 omr
->msg_tosave
= 0;
1227 #ifdef USE_PIPE_SYNC
1228 if (pipe(omr
->msg_pipe
) < 0) {
1229 omr
->msg_pipe
[0] = -1;
1230 omr
->msg_pipe
[1] = -1;
1231 ERR("could not create pipe, error=%s\n", strerror(errno
));
1234 omr
->msg_event
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
1236 omr
->ring_buffer_size
= OSS_RING_BUFFER_INCREMENT
;
1237 omr
->messages
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,omr
->ring_buffer_size
* sizeof(OSS_MSG
));
1238 InitializeCriticalSection(&omr
->msg_crst
);
1239 omr
->msg_crst
.DebugInfo
->Spare
[1] = (DWORD
)"WINEOSS_msg_crst";
1243 /******************************************************************
1244 * OSS_DestroyRingMessage
1247 static int OSS_DestroyRingMessage(OSS_MSG_RING
* omr
)
1249 #ifdef USE_PIPE_SYNC
1250 close(omr
->msg_pipe
[0]);
1251 close(omr
->msg_pipe
[1]);
1253 CloseHandle(omr
->msg_event
);
1255 HeapFree(GetProcessHeap(),0,omr
->messages
);
1256 DeleteCriticalSection(&omr
->msg_crst
);
1260 /******************************************************************
1261 * OSS_AddRingMessage
1263 * Inserts a new message into the ring (should be called from DriverProc derivated routines)
1265 static int OSS_AddRingMessage(OSS_MSG_RING
* omr
, enum win_wm_message msg
, DWORD param
, BOOL wait
)
1267 HANDLE hEvent
= INVALID_HANDLE_VALUE
;
1269 EnterCriticalSection(&omr
->msg_crst
);
1270 if ((omr
->msg_toget
== ((omr
->msg_tosave
+ 1) % omr
->ring_buffer_size
)))
1272 int old_ring_buffer_size
= omr
->ring_buffer_size
;
1273 omr
->ring_buffer_size
+= OSS_RING_BUFFER_INCREMENT
;
1274 TRACE("omr->ring_buffer_size=%d\n",omr
->ring_buffer_size
);
1275 omr
->messages
= HeapReAlloc(GetProcessHeap(),0,omr
->messages
, omr
->ring_buffer_size
* sizeof(OSS_MSG
));
1276 /* Now we need to rearrange the ring buffer so that the new
1277 buffers just allocated are in between omr->msg_tosave and
1280 if (omr
->msg_tosave
< omr
->msg_toget
)
1282 memmove(&(omr
->messages
[omr
->msg_toget
+ OSS_RING_BUFFER_INCREMENT
]),
1283 &(omr
->messages
[omr
->msg_toget
]),
1284 sizeof(OSS_MSG
)*(old_ring_buffer_size
- omr
->msg_toget
)
1286 omr
->msg_toget
+= OSS_RING_BUFFER_INCREMENT
;
1291 hEvent
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
1292 if (hEvent
== INVALID_HANDLE_VALUE
)
1294 ERR("can't create event !?\n");
1295 LeaveCriticalSection(&omr
->msg_crst
);
1298 if (omr
->msg_toget
!= omr
->msg_tosave
&& omr
->messages
[omr
->msg_toget
].msg
!= WINE_WM_HEADER
)
1299 FIXME("two fast messages in the queue!!!! toget = %d(%s), tosave=%d(%s)\n",
1300 omr
->msg_toget
,getCmdString(omr
->messages
[omr
->msg_toget
].msg
),
1301 omr
->msg_tosave
,getCmdString(omr
->messages
[omr
->msg_tosave
].msg
));
1303 /* fast messages have to be added at the start of the queue */
1304 omr
->msg_toget
= (omr
->msg_toget
+ omr
->ring_buffer_size
- 1) % omr
->ring_buffer_size
;
1305 omr
->messages
[omr
->msg_toget
].msg
= msg
;
1306 omr
->messages
[omr
->msg_toget
].param
= param
;
1307 omr
->messages
[omr
->msg_toget
].hEvent
= hEvent
;
1311 omr
->messages
[omr
->msg_tosave
].msg
= msg
;
1312 omr
->messages
[omr
->msg_tosave
].param
= param
;
1313 omr
->messages
[omr
->msg_tosave
].hEvent
= INVALID_HANDLE_VALUE
;
1314 omr
->msg_tosave
= (omr
->msg_tosave
+ 1) % omr
->ring_buffer_size
;
1316 LeaveCriticalSection(&omr
->msg_crst
);
1317 /* signal a new message */
1321 /* wait for playback/record thread to have processed the message */
1322 WaitForSingleObject(hEvent
, INFINITE
);
1323 CloseHandle(hEvent
);
1328 /******************************************************************
1329 * OSS_RetrieveRingMessage
1331 * Get a message from the ring. Should be called by the playback/record thread.
1333 static int OSS_RetrieveRingMessage(OSS_MSG_RING
* omr
,
1334 enum win_wm_message
*msg
, DWORD
*param
, HANDLE
*hEvent
)
1336 EnterCriticalSection(&omr
->msg_crst
);
1338 if (omr
->msg_toget
== omr
->msg_tosave
) /* buffer empty ? */
1340 LeaveCriticalSection(&omr
->msg_crst
);
1344 *msg
= omr
->messages
[omr
->msg_toget
].msg
;
1345 omr
->messages
[omr
->msg_toget
].msg
= 0;
1346 *param
= omr
->messages
[omr
->msg_toget
].param
;
1347 *hEvent
= omr
->messages
[omr
->msg_toget
].hEvent
;
1348 omr
->msg_toget
= (omr
->msg_toget
+ 1) % omr
->ring_buffer_size
;
1350 LeaveCriticalSection(&omr
->msg_crst
);
1354 /******************************************************************
1355 * OSS_PeekRingMessage
1357 * Peek at a message from the ring but do not remove it.
1358 * Should be called by the playback/record thread.
1360 static int OSS_PeekRingMessage(OSS_MSG_RING
* omr
,
1361 enum win_wm_message
*msg
,
1362 DWORD
*param
, HANDLE
*hEvent
)
1364 EnterCriticalSection(&omr
->msg_crst
);
1366 if (omr
->msg_toget
== omr
->msg_tosave
) /* buffer empty ? */
1368 LeaveCriticalSection(&omr
->msg_crst
);
1372 *msg
= omr
->messages
[omr
->msg_toget
].msg
;
1373 *param
= omr
->messages
[omr
->msg_toget
].param
;
1374 *hEvent
= omr
->messages
[omr
->msg_toget
].hEvent
;
1375 LeaveCriticalSection(&omr
->msg_crst
);
1379 /*======================================================================*
1380 * Low level WAVE OUT implementation *
1381 *======================================================================*/
1383 /**************************************************************************
1384 * wodNotifyClient [internal]
1386 static DWORD
wodNotifyClient(WINE_WAVEOUT
* wwo
, WORD wMsg
, DWORD dwParam1
, DWORD dwParam2
)
1388 TRACE("wMsg = 0x%04x (%s) dwParm1 = %04lX dwParam2 = %04lX\n", wMsg
,
1389 wMsg
== WOM_OPEN
? "WOM_OPEN" : wMsg
== WOM_CLOSE
? "WOM_CLOSE" :
1390 wMsg
== WOM_DONE
? "WOM_DONE" : "Unknown", dwParam1
, dwParam2
);
1396 if (wwo
->wFlags
!= DCB_NULL
&&
1397 !DriverCallback(wwo
->waveDesc
.dwCallback
, wwo
->wFlags
,
1398 (HDRVR
)wwo
->waveDesc
.hWave
, wMsg
,
1399 wwo
->waveDesc
.dwInstance
, dwParam1
, dwParam2
)) {
1400 WARN("can't notify client !\n");
1401 return MMSYSERR_ERROR
;
1405 FIXME("Unknown callback message %u\n", wMsg
);
1406 return MMSYSERR_INVALPARAM
;
1408 return MMSYSERR_NOERROR
;
1411 /**************************************************************************
1412 * wodUpdatePlayedTotal [internal]
1415 static BOOL
wodUpdatePlayedTotal(WINE_WAVEOUT
* wwo
, audio_buf_info
* info
)
1417 audio_buf_info dspspace
;
1418 if (!info
) info
= &dspspace
;
1420 if (ioctl(wwo
->ossdev
->fd
, SNDCTL_DSP_GETOSPACE
, info
) < 0) {
1421 ERR("ioctl(%s, SNDCTL_DSP_GETOSPACE) failed (%s)\n", wwo
->ossdev
->dev_name
, strerror(errno
));
1424 wwo
->dwPlayedTotal
= wwo
->dwWrittenTotal
- (wwo
->dwBufferSize
- info
->bytes
);
1428 /**************************************************************************
1429 * wodPlayer_BeginWaveHdr [internal]
1431 * Makes the specified lpWaveHdr the currently playing wave header.
1432 * If the specified wave header is a begin loop and we're not already in
1433 * a loop, setup the loop.
1435 static void wodPlayer_BeginWaveHdr(WINE_WAVEOUT
* wwo
, LPWAVEHDR lpWaveHdr
)
1437 wwo
->lpPlayPtr
= lpWaveHdr
;
1439 if (!lpWaveHdr
) return;
1441 if (lpWaveHdr
->dwFlags
& WHDR_BEGINLOOP
) {
1442 if (wwo
->lpLoopPtr
) {
1443 WARN("Already in a loop. Discarding loop on this header (%p)\n", lpWaveHdr
);
1445 TRACE("Starting loop (%ldx) with %p\n", lpWaveHdr
->dwLoops
, lpWaveHdr
);
1446 wwo
->lpLoopPtr
= lpWaveHdr
;
1447 /* Windows does not touch WAVEHDR.dwLoops,
1448 * so we need to make an internal copy */
1449 wwo
->dwLoops
= lpWaveHdr
->dwLoops
;
1452 wwo
->dwPartialOffset
= 0;
1455 /**************************************************************************
1456 * wodPlayer_PlayPtrNext [internal]
1458 * Advance the play pointer to the next waveheader, looping if required.
1460 static LPWAVEHDR
wodPlayer_PlayPtrNext(WINE_WAVEOUT
* wwo
)
1462 LPWAVEHDR lpWaveHdr
= wwo
->lpPlayPtr
;
1464 wwo
->dwPartialOffset
= 0;
1465 if ((lpWaveHdr
->dwFlags
& WHDR_ENDLOOP
) && wwo
->lpLoopPtr
) {
1466 /* We're at the end of a loop, loop if required */
1467 if (--wwo
->dwLoops
> 0) {
1468 wwo
->lpPlayPtr
= wwo
->lpLoopPtr
;
1470 /* Handle overlapping loops correctly */
1471 if (wwo
->lpLoopPtr
!= lpWaveHdr
&& (lpWaveHdr
->dwFlags
& WHDR_BEGINLOOP
)) {
1472 FIXME("Correctly handled case ? (ending loop buffer also starts a new loop)\n");
1473 /* shall we consider the END flag for the closing loop or for
1474 * the opening one or for both ???
1475 * code assumes for closing loop only
1478 lpWaveHdr
= lpWaveHdr
->lpNext
;
1480 wwo
->lpLoopPtr
= NULL
;
1481 wodPlayer_BeginWaveHdr(wwo
, lpWaveHdr
);
1484 /* We're not in a loop. Advance to the next wave header */
1485 wodPlayer_BeginWaveHdr(wwo
, lpWaveHdr
= lpWaveHdr
->lpNext
);
1491 /**************************************************************************
1492 * wodPlayer_DSPWait [internal]
1493 * Returns the number of milliseconds to wait for the DSP buffer to write
1496 static DWORD
wodPlayer_DSPWait(const WINE_WAVEOUT
*wwo
)
1498 /* time for one fragment to be played */
1499 return wwo
->dwFragmentSize
* 1000 / wwo
->waveFormat
.Format
.nAvgBytesPerSec
;
1502 /**************************************************************************
1503 * wodPlayer_NotifyWait [internal]
1504 * Returns the number of milliseconds to wait before attempting to notify
1505 * completion of the specified wavehdr.
1506 * This is based on the number of bytes remaining to be written in the
1509 static DWORD
wodPlayer_NotifyWait(const WINE_WAVEOUT
* wwo
, LPWAVEHDR lpWaveHdr
)
1513 if (lpWaveHdr
->reserved
< wwo
->dwPlayedTotal
) {
1516 dwMillis
= (lpWaveHdr
->reserved
- wwo
->dwPlayedTotal
) * 1000 / wwo
->waveFormat
.Format
.nAvgBytesPerSec
;
1517 if (!dwMillis
) dwMillis
= 1;
1524 /**************************************************************************
1525 * wodPlayer_WriteMaxFrags [internal]
1526 * Writes the maximum number of bytes possible to the DSP and returns
1527 * TRUE iff the current playPtr has been fully played
1529 static BOOL
wodPlayer_WriteMaxFrags(WINE_WAVEOUT
* wwo
, DWORD
* bytes
)
1531 DWORD dwLength
= wwo
->lpPlayPtr
->dwBufferLength
- wwo
->dwPartialOffset
;
1532 DWORD toWrite
= min(dwLength
, *bytes
);
1536 TRACE("Writing wavehdr %p.%lu[%lu]/%lu\n",
1537 wwo
->lpPlayPtr
, wwo
->dwPartialOffset
, wwo
->lpPlayPtr
->dwBufferLength
, toWrite
);
1541 written
= write(wwo
->ossdev
->fd
, wwo
->lpPlayPtr
->lpData
+ wwo
->dwPartialOffset
, toWrite
);
1543 TRACE("write(%s, %p, %ld) failed (%s) returned %d\n", wwo
->ossdev
->dev_name
,
1544 wwo
->lpPlayPtr
->lpData
+ wwo
->dwPartialOffset
, toWrite
, strerror(errno
), written
);
1551 if (written
>= dwLength
) {
1552 /* If we wrote all current wavehdr, skip to the next one */
1553 wodPlayer_PlayPtrNext(wwo
);
1556 /* Remove the amount written */
1557 wwo
->dwPartialOffset
+= written
;
1560 wwo
->dwWrittenTotal
+= written
;
1561 TRACE("dwWrittenTotal=%lu\n", wwo
->dwWrittenTotal
);
1566 /**************************************************************************
1567 * wodPlayer_NotifyCompletions [internal]
1569 * Notifies and remove from queue all wavehdrs which have been played to
1570 * the speaker (ie. they have cleared the OSS buffer). If force is true,
1571 * we notify all wavehdrs and remove them all from the queue even if they
1572 * are unplayed or part of a loop.
1574 static DWORD
wodPlayer_NotifyCompletions(WINE_WAVEOUT
* wwo
, BOOL force
)
1576 LPWAVEHDR lpWaveHdr
;
1578 /* Start from lpQueuePtr and keep notifying until:
1579 * - we hit an unwritten wavehdr
1580 * - we hit the beginning of a running loop
1581 * - we hit a wavehdr which hasn't finished playing
1583 while ((lpWaveHdr
= wwo
->lpQueuePtr
) &&
1585 (lpWaveHdr
!= wwo
->lpPlayPtr
&&
1586 lpWaveHdr
!= wwo
->lpLoopPtr
&&
1587 lpWaveHdr
->reserved
<= wwo
->dwPlayedTotal
))) {
1589 wwo
->lpQueuePtr
= lpWaveHdr
->lpNext
;
1591 lpWaveHdr
->dwFlags
&= ~WHDR_INQUEUE
;
1592 lpWaveHdr
->dwFlags
|= WHDR_DONE
;
1594 wodNotifyClient(wwo
, WOM_DONE
, (DWORD
)lpWaveHdr
, 0);
1596 return (lpWaveHdr
&& lpWaveHdr
!= wwo
->lpPlayPtr
&& lpWaveHdr
!= wwo
->lpLoopPtr
) ?
1597 wodPlayer_NotifyWait(wwo
, lpWaveHdr
) : INFINITE
;
1600 /**************************************************************************
1601 * wodPlayer_Reset [internal]
1603 * wodPlayer helper. Resets current output stream.
1605 static void wodPlayer_Reset(WINE_WAVEOUT
* wwo
, BOOL reset
)
1607 wodUpdatePlayedTotal(wwo
, NULL
);
1608 /* updates current notify list */
1609 wodPlayer_NotifyCompletions(wwo
, FALSE
);
1611 /* flush all possible output */
1612 if (OSS_ResetDevice(wwo
->ossdev
) != MMSYSERR_NOERROR
)
1615 wwo
->state
= WINE_WS_STOPPED
;
1620 enum win_wm_message msg
;
1624 /* remove any buffer */
1625 wodPlayer_NotifyCompletions(wwo
, TRUE
);
1627 wwo
->lpPlayPtr
= wwo
->lpQueuePtr
= wwo
->lpLoopPtr
= NULL
;
1628 wwo
->state
= WINE_WS_STOPPED
;
1629 wwo
->dwPlayedTotal
= wwo
->dwWrittenTotal
= 0;
1630 /* Clear partial wavehdr */
1631 wwo
->dwPartialOffset
= 0;
1633 /* remove any existing message in the ring */
1634 EnterCriticalSection(&wwo
->msgRing
.msg_crst
);
1635 /* return all pending headers in queue */
1636 while (OSS_RetrieveRingMessage(&wwo
->msgRing
, &msg
, ¶m
, &ev
))
1638 if (msg
!= WINE_WM_HEADER
)
1640 FIXME("shouldn't have headers left\n");
1644 ((LPWAVEHDR
)param
)->dwFlags
&= ~WHDR_INQUEUE
;
1645 ((LPWAVEHDR
)param
)->dwFlags
|= WHDR_DONE
;
1647 wodNotifyClient(wwo
, WOM_DONE
, param
, 0);
1649 RESET_OMR(&wwo
->msgRing
);
1650 LeaveCriticalSection(&wwo
->msgRing
.msg_crst
);
1652 if (wwo
->lpLoopPtr
) {
1653 /* complicated case, not handled yet (could imply modifying the loop counter */
1654 FIXME("Pausing while in loop isn't correctly handled yet, except strange results\n");
1655 wwo
->lpPlayPtr
= wwo
->lpLoopPtr
;
1656 wwo
->dwPartialOffset
= 0;
1657 wwo
->dwWrittenTotal
= wwo
->dwPlayedTotal
; /* this is wrong !!! */
1660 DWORD sz
= wwo
->dwPartialOffset
;
1662 /* reset all the data as if we had written only up to lpPlayedTotal bytes */
1663 /* compute the max size playable from lpQueuePtr */
1664 for (ptr
= wwo
->lpQueuePtr
; ptr
!= wwo
->lpPlayPtr
; ptr
= ptr
->lpNext
) {
1665 sz
+= ptr
->dwBufferLength
;
1667 /* because the reset lpPlayPtr will be lpQueuePtr */
1668 if (wwo
->dwWrittenTotal
> wwo
->dwPlayedTotal
+ sz
) ERR("grin\n");
1669 wwo
->dwPartialOffset
= sz
- (wwo
->dwWrittenTotal
- wwo
->dwPlayedTotal
);
1670 wwo
->dwWrittenTotal
= wwo
->dwPlayedTotal
;
1671 wwo
->lpPlayPtr
= wwo
->lpQueuePtr
;
1673 wwo
->state
= WINE_WS_PAUSED
;
1677 /**************************************************************************
1678 * wodPlayer_ProcessMessages [internal]
1680 static void wodPlayer_ProcessMessages(WINE_WAVEOUT
* wwo
)
1682 LPWAVEHDR lpWaveHdr
;
1683 enum win_wm_message msg
;
1687 while (OSS_RetrieveRingMessage(&wwo
->msgRing
, &msg
, ¶m
, &ev
)) {
1688 TRACE("Received %s %lx\n", getCmdString(msg
), param
);
1690 case WINE_WM_PAUSING
:
1691 wodPlayer_Reset(wwo
, FALSE
);
1694 case WINE_WM_RESTARTING
:
1695 if (wwo
->state
== WINE_WS_PAUSED
)
1697 wwo
->state
= WINE_WS_PLAYING
;
1701 case WINE_WM_HEADER
:
1702 lpWaveHdr
= (LPWAVEHDR
)param
;
1704 /* insert buffer at the end of queue */
1707 for (wh
= &(wwo
->lpQueuePtr
); *wh
; wh
= &((*wh
)->lpNext
));
1710 if (!wwo
->lpPlayPtr
)
1711 wodPlayer_BeginWaveHdr(wwo
,lpWaveHdr
);
1712 if (wwo
->state
== WINE_WS_STOPPED
)
1713 wwo
->state
= WINE_WS_PLAYING
;
1715 case WINE_WM_RESETTING
:
1716 wodPlayer_Reset(wwo
, TRUE
);
1719 case WINE_WM_UPDATE
:
1720 wodUpdatePlayedTotal(wwo
, NULL
);
1723 case WINE_WM_BREAKLOOP
:
1724 if (wwo
->state
== WINE_WS_PLAYING
&& wwo
->lpLoopPtr
!= NULL
) {
1725 /* ensure exit at end of current loop */
1730 case WINE_WM_CLOSING
:
1731 /* sanity check: this should not happen since the device must have been reset before */
1732 if (wwo
->lpQueuePtr
|| wwo
->lpPlayPtr
) ERR("out of sync\n");
1734 wwo
->state
= WINE_WS_CLOSED
;
1737 /* shouldn't go here */
1739 FIXME("unknown message %d\n", msg
);
1745 /**************************************************************************
1746 * wodPlayer_FeedDSP [internal]
1747 * Feed as much sound data as we can into the DSP and return the number of
1748 * milliseconds before it will be necessary to feed the DSP again.
1750 static DWORD
wodPlayer_FeedDSP(WINE_WAVEOUT
* wwo
)
1752 audio_buf_info dspspace
;
1755 wodUpdatePlayedTotal(wwo
, &dspspace
);
1756 availInQ
= dspspace
.bytes
;
1757 TRACE("fragments=%d/%d, fragsize=%d, bytes=%d\n",
1758 dspspace
.fragments
, dspspace
.fragstotal
, dspspace
.fragsize
, dspspace
.bytes
);
1760 /* input queue empty and output buffer with less than one fragment to play
1761 * actually some cards do not play the fragment before the last if this one is partially feed
1762 * so we need to test for full the availability of 2 fragments
1764 if (!wwo
->lpPlayPtr
&& wwo
->dwBufferSize
< availInQ
+ 2 * wwo
->dwFragmentSize
&&
1766 TRACE("Run out of wavehdr:s...\n");
1770 /* no more room... no need to try to feed */
1771 if (dspspace
.fragments
!= 0) {
1772 /* Feed from partial wavehdr */
1773 if (wwo
->lpPlayPtr
&& wwo
->dwPartialOffset
!= 0) {
1774 wodPlayer_WriteMaxFrags(wwo
, &availInQ
);
1777 /* Feed wavehdrs until we run out of wavehdrs or DSP space */
1778 if (wwo
->dwPartialOffset
== 0 && wwo
->lpPlayPtr
) {
1780 TRACE("Setting time to elapse for %p to %lu\n",
1781 wwo
->lpPlayPtr
, wwo
->dwWrittenTotal
+ wwo
->lpPlayPtr
->dwBufferLength
);
1782 /* note the value that dwPlayedTotal will return when this wave finishes playing */
1783 wwo
->lpPlayPtr
->reserved
= wwo
->dwWrittenTotal
+ wwo
->lpPlayPtr
->dwBufferLength
;
1784 } while (wodPlayer_WriteMaxFrags(wwo
, &availInQ
) && wwo
->lpPlayPtr
&& availInQ
> 0);
1787 if (wwo
->bNeedPost
) {
1788 /* OSS doesn't start before it gets either 2 fragments or a SNDCTL_DSP_POST;
1789 * if it didn't get one, we give it the other */
1790 if (wwo
->dwBufferSize
< availInQ
+ 2 * wwo
->dwFragmentSize
)
1791 ioctl(wwo
->ossdev
->fd
, SNDCTL_DSP_POST
, 0);
1792 wwo
->bNeedPost
= FALSE
;
1796 return wodPlayer_DSPWait(wwo
);
1800 /**************************************************************************
1801 * wodPlayer [internal]
1803 static DWORD CALLBACK
wodPlayer(LPVOID pmt
)
1805 WORD uDevID
= (DWORD
)pmt
;
1806 WINE_WAVEOUT
* wwo
= (WINE_WAVEOUT
*)&WOutDev
[uDevID
];
1807 DWORD dwNextFeedTime
= INFINITE
; /* Time before DSP needs feeding */
1808 DWORD dwNextNotifyTime
= INFINITE
; /* Time before next wave completion */
1811 wwo
->state
= WINE_WS_STOPPED
;
1812 SetEvent(wwo
->hStartUpEvent
);
1815 /** Wait for the shortest time before an action is required. If there
1816 * are no pending actions, wait forever for a command.
1818 dwSleepTime
= min(dwNextFeedTime
, dwNextNotifyTime
);
1819 TRACE("waiting %lums (%lu,%lu)\n", dwSleepTime
, dwNextFeedTime
, dwNextNotifyTime
);
1820 WAIT_OMR(&wwo
->msgRing
, dwSleepTime
);
1821 wodPlayer_ProcessMessages(wwo
);
1822 if (wwo
->state
== WINE_WS_PLAYING
) {
1823 dwNextFeedTime
= wodPlayer_FeedDSP(wwo
);
1824 dwNextNotifyTime
= wodPlayer_NotifyCompletions(wwo
, FALSE
);
1825 if (dwNextFeedTime
== INFINITE
) {
1826 /* FeedDSP ran out of data, but before flushing, */
1827 /* check that a notification didn't give us more */
1828 wodPlayer_ProcessMessages(wwo
);
1829 if (!wwo
->lpPlayPtr
) {
1830 TRACE("flushing\n");
1831 ioctl(wwo
->ossdev
->fd
, SNDCTL_DSP_SYNC
, 0);
1832 wwo
->dwPlayedTotal
= wwo
->dwWrittenTotal
;
1833 dwNextNotifyTime
= wodPlayer_NotifyCompletions(wwo
, FALSE
);
1835 TRACE("recovering\n");
1836 dwNextFeedTime
= wodPlayer_FeedDSP(wwo
);
1840 dwNextFeedTime
= dwNextNotifyTime
= INFINITE
;
1845 /**************************************************************************
1846 * wodGetDevCaps [internal]
1848 static DWORD
wodGetDevCaps(WORD wDevID
, LPWAVEOUTCAPSA lpCaps
, DWORD dwSize
)
1850 TRACE("(%u, %p, %lu);\n", wDevID
, lpCaps
, dwSize
);
1852 if (lpCaps
== NULL
) {
1853 WARN("not enabled\n");
1854 return MMSYSERR_NOTENABLED
;
1857 if (wDevID
>= numOutDev
) {
1858 WARN("numOutDev reached !\n");
1859 return MMSYSERR_BADDEVICEID
;
1862 if (WOutDev
[wDevID
].ossdev
->open_access
== O_RDWR
)
1863 memcpy(lpCaps
, &WOutDev
[wDevID
].ossdev
->duplex_out_caps
, min(dwSize
, sizeof(*lpCaps
)));
1865 memcpy(lpCaps
, &WOutDev
[wDevID
].ossdev
->out_caps
, min(dwSize
, sizeof(*lpCaps
)));
1867 return MMSYSERR_NOERROR
;
1870 /**************************************************************************
1871 * wodOpen [internal]
1873 static DWORD
wodOpen(WORD wDevID
, LPWAVEOPENDESC lpDesc
, DWORD dwFlags
)
1877 audio_buf_info info
;
1880 TRACE("(%u, %p[cb=%08lx], %08lX);\n", wDevID
, lpDesc
, lpDesc
->dwCallback
, dwFlags
);
1881 if (lpDesc
== NULL
) {
1882 WARN("Invalid Parameter !\n");
1883 return MMSYSERR_INVALPARAM
;
1885 if (wDevID
>= numOutDev
) {
1886 TRACE("MAX_WAVOUTDRV reached !\n");
1887 return MMSYSERR_BADDEVICEID
;
1890 /* only PCM format is supported so far... */
1891 if (!supportedFormat(lpDesc
->lpFormat
)) {
1892 WARN("Bad format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
1893 lpDesc
->lpFormat
->wFormatTag
, lpDesc
->lpFormat
->nChannels
,
1894 lpDesc
->lpFormat
->nSamplesPerSec
);
1895 return WAVERR_BADFORMAT
;
1898 if (dwFlags
& WAVE_FORMAT_QUERY
) {
1899 TRACE("Query format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
1900 lpDesc
->lpFormat
->wFormatTag
, lpDesc
->lpFormat
->nChannels
,
1901 lpDesc
->lpFormat
->nSamplesPerSec
);
1902 return MMSYSERR_NOERROR
;
1905 TRACE("OSS_OpenDevice requested this format: %ldx%dx%d %s\n",
1906 lpDesc
->lpFormat
->nSamplesPerSec
,
1907 lpDesc
->lpFormat
->wBitsPerSample
,
1908 lpDesc
->lpFormat
->nChannels
,
1909 lpDesc
->lpFormat
->wFormatTag
== WAVE_FORMAT_PCM
? "WAVE_FORMAT_PCM" :
1910 lpDesc
->lpFormat
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
? "WAVE_FORMAT_EXTENSIBLE" :
1913 wwo
= &WOutDev
[wDevID
];
1915 if ((dwFlags
& WAVE_DIRECTSOUND
) &&
1916 !(wwo
->ossdev
->duplex_out_caps
.dwSupport
& WAVECAPS_DIRECTSOUND
))
1917 /* not supported, ignore it */
1918 dwFlags
&= ~WAVE_DIRECTSOUND
;
1920 if (dwFlags
& WAVE_DIRECTSOUND
) {
1921 if (wwo
->ossdev
->duplex_out_caps
.dwSupport
& WAVECAPS_SAMPLEACCURATE
)
1922 /* we have realtime DirectSound, fragments just waste our time,
1923 * but a large buffer is good, so choose 64KB (32 * 2^11) */
1924 audio_fragment
= 0x0020000B;
1926 /* to approximate realtime, we must use small fragments,
1927 * let's try to fragment the above 64KB (256 * 2^8) */
1928 audio_fragment
= 0x01000008;
1930 /* A wave device must have a worst case latency of 10 ms so calculate
1931 * the largest fragment size less than 10 ms long.
1933 int fsize
= lpDesc
->lpFormat
->nAvgBytesPerSec
/ 100; /* 10 ms chunk */
1935 while ((1 << shift
) <= fsize
)
1938 audio_fragment
= 0x00100000 + shift
; /* 16 fragments of 2^shift */
1941 TRACE("requesting %d %d byte fragments (%ld ms/fragment)\n",
1942 audio_fragment
>> 16, 1 << (audio_fragment
& 0xffff),
1943 ((1 << (audio_fragment
& 0xffff)) * 1000) / lpDesc
->lpFormat
->nAvgBytesPerSec
);
1945 if (wwo
->state
!= WINE_WS_CLOSED
) {
1946 WARN("already allocated\n");
1947 return MMSYSERR_ALLOCATED
;
1950 /* we want to be able to mmap() the device, which means it must be opened readable,
1951 * otherwise mmap() will fail (at least under Linux) */
1952 ret
= OSS_OpenDevice(wwo
->ossdev
,
1953 (dwFlags
& WAVE_DIRECTSOUND
) ? O_RDWR
: O_WRONLY
,
1955 (dwFlags
& WAVE_DIRECTSOUND
) ? 0 : 1,
1956 lpDesc
->lpFormat
->nSamplesPerSec
,
1957 (lpDesc
->lpFormat
->nChannels
> 1) ? 1 : 0,
1958 (lpDesc
->lpFormat
->wBitsPerSample
== 16)
1959 ? AFMT_S16_LE
: AFMT_U8
);
1960 if ((ret
==MMSYSERR_NOERROR
) && (dwFlags
& WAVE_DIRECTSOUND
)) {
1961 lpDesc
->lpFormat
->nSamplesPerSec
=wwo
->ossdev
->sample_rate
;
1962 lpDesc
->lpFormat
->nChannels
=(wwo
->ossdev
->stereo
? 2 : 1);
1963 lpDesc
->lpFormat
->wBitsPerSample
=(wwo
->ossdev
->format
== AFMT_U8
? 8 : 16);
1964 lpDesc
->lpFormat
->nBlockAlign
=lpDesc
->lpFormat
->nChannels
*lpDesc
->lpFormat
->wBitsPerSample
/8;
1965 lpDesc
->lpFormat
->nAvgBytesPerSec
=lpDesc
->lpFormat
->nSamplesPerSec
*lpDesc
->lpFormat
->nBlockAlign
;
1966 TRACE("OSS_OpenDevice returned this format: %ldx%dx%d\n",
1967 lpDesc
->lpFormat
->nSamplesPerSec
,
1968 lpDesc
->lpFormat
->wBitsPerSample
,
1969 lpDesc
->lpFormat
->nChannels
);
1971 if (ret
!= 0) return ret
;
1972 wwo
->state
= WINE_WS_STOPPED
;
1974 wwo
->wFlags
= HIWORD(dwFlags
& CALLBACK_TYPEMASK
);
1976 memcpy(&wwo
->waveDesc
, lpDesc
, sizeof(WAVEOPENDESC
));
1977 copy_format(lpDesc
->lpFormat
, &wwo
->waveFormat
);
1979 if (wwo
->waveFormat
.Format
.wBitsPerSample
== 0) {
1980 WARN("Resetting zeroed wBitsPerSample\n");
1981 wwo
->waveFormat
.Format
.wBitsPerSample
= 8 *
1982 (wwo
->waveFormat
.Format
.nAvgBytesPerSec
/
1983 wwo
->waveFormat
.Format
.nSamplesPerSec
) /
1984 wwo
->waveFormat
.Format
.nChannels
;
1986 /* Read output space info for future reference */
1987 if (ioctl(wwo
->ossdev
->fd
, SNDCTL_DSP_GETOSPACE
, &info
) < 0) {
1988 ERR("ioctl(%s, SNDCTL_DSP_GETOSPACE) failed (%s)\n", wwo
->ossdev
->dev_name
, strerror(errno
));
1989 OSS_CloseDevice(wwo
->ossdev
);
1990 wwo
->state
= WINE_WS_CLOSED
;
1991 return MMSYSERR_NOTENABLED
;
1994 TRACE("got %d %d byte fragments (%d ms/fragment)\n", info
.fragstotal
,
1995 info
.fragsize
, (info
.fragsize
* 1000) / (wwo
->ossdev
->sample_rate
*
1996 (wwo
->ossdev
->stereo
? 2 : 1) *
1997 (wwo
->ossdev
->format
== AFMT_U8
? 1 : 2)));
1999 /* Check that fragsize is correct per our settings above */
2000 if ((info
.fragsize
> 1024) && (LOWORD(audio_fragment
) <= 10)) {
2001 /* we've tried to set 1K fragments or less, but it didn't work */
2002 ERR("fragment size set failed, size is now %d\n", info
.fragsize
);
2003 MESSAGE("Your Open Sound System driver did not let us configure small enough sound fragments.\n");
2004 MESSAGE("This may cause delays and other problems in audio playback with certain applications.\n");
2007 /* Remember fragsize and total buffer size for future use */
2008 wwo
->dwFragmentSize
= info
.fragsize
;
2009 wwo
->dwBufferSize
= info
.fragstotal
* info
.fragsize
;
2010 wwo
->dwPlayedTotal
= 0;
2011 wwo
->dwWrittenTotal
= 0;
2012 wwo
->bNeedPost
= TRUE
;
2014 TRACE("fd=%d fragstotal=%d fragsize=%d BufferSize=%ld\n",
2015 wwo
->ossdev
->fd
, info
.fragstotal
, info
.fragsize
, wwo
->dwBufferSize
);
2016 if (wwo
->dwFragmentSize
% wwo
->waveFormat
.Format
.nBlockAlign
) {
2017 ERR("Fragment doesn't contain an integral number of data blocks fragsize=%ld BlockAlign=%d\n",wwo
->dwFragmentSize
,wwo
->waveFormat
.Format
.nBlockAlign
);
2018 /* Some SoundBlaster 16 cards return an incorrect (odd) fragment
2019 * size for 16 bit sound. This will cause a system crash when we try
2020 * to write just the specified odd number of bytes. So if we
2021 * detect something is wrong we'd better fix it.
2023 wwo
->dwFragmentSize
-=wwo
->dwFragmentSize
% wwo
->waveFormat
.Format
.nBlockAlign
;
2026 OSS_InitRingMessage(&wwo
->msgRing
);
2028 wwo
->hStartUpEvent
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
2029 wwo
->hThread
= CreateThread(NULL
, 0, wodPlayer
, (LPVOID
)(DWORD
)wDevID
, 0, &(wwo
->dwThreadID
));
2030 WaitForSingleObject(wwo
->hStartUpEvent
, INFINITE
);
2031 CloseHandle(wwo
->hStartUpEvent
);
2032 wwo
->hStartUpEvent
= INVALID_HANDLE_VALUE
;
2034 TRACE("wBitsPerSample=%u, nAvgBytesPerSec=%lu, nSamplesPerSec=%lu, nChannels=%u nBlockAlign=%u!\n",
2035 wwo
->waveFormat
.Format
.wBitsPerSample
, wwo
->waveFormat
.Format
.nAvgBytesPerSec
,
2036 wwo
->waveFormat
.Format
.nSamplesPerSec
, wwo
->waveFormat
.Format
.nChannels
,
2037 wwo
->waveFormat
.Format
.nBlockAlign
);
2039 return wodNotifyClient(wwo
, WOM_OPEN
, 0L, 0L);
2042 /**************************************************************************
2043 * wodClose [internal]
2045 static DWORD
wodClose(WORD wDevID
)
2047 DWORD ret
= MMSYSERR_NOERROR
;
2050 TRACE("(%u);\n", wDevID
);
2052 if (wDevID
>= numOutDev
|| WOutDev
[wDevID
].state
== WINE_WS_CLOSED
) {
2053 WARN("bad device ID !\n");
2054 return MMSYSERR_BADDEVICEID
;
2057 wwo
= &WOutDev
[wDevID
];
2058 if (wwo
->lpQueuePtr
) {
2059 WARN("buffers still playing !\n");
2060 ret
= WAVERR_STILLPLAYING
;
2062 if (wwo
->hThread
!= INVALID_HANDLE_VALUE
) {
2063 OSS_AddRingMessage(&wwo
->msgRing
, WINE_WM_CLOSING
, 0, TRUE
);
2066 OSS_DestroyRingMessage(&wwo
->msgRing
);
2068 OSS_CloseDevice(wwo
->ossdev
);
2069 wwo
->state
= WINE_WS_CLOSED
;
2070 wwo
->dwFragmentSize
= 0;
2071 ret
= wodNotifyClient(wwo
, WOM_CLOSE
, 0L, 0L);
2076 /**************************************************************************
2077 * wodWrite [internal]
2080 static DWORD
wodWrite(WORD wDevID
, LPWAVEHDR lpWaveHdr
, DWORD dwSize
)
2082 TRACE("(%u, %p, %08lX);\n", wDevID
, lpWaveHdr
, dwSize
);
2084 /* first, do the sanity checks... */
2085 if (wDevID
>= numOutDev
|| WOutDev
[wDevID
].state
== WINE_WS_CLOSED
) {
2086 WARN("bad dev ID !\n");
2087 return MMSYSERR_BADDEVICEID
;
2090 if (lpWaveHdr
->lpData
== NULL
|| !(lpWaveHdr
->dwFlags
& WHDR_PREPARED
))
2091 return WAVERR_UNPREPARED
;
2093 if (lpWaveHdr
->dwFlags
& WHDR_INQUEUE
)
2094 return WAVERR_STILLPLAYING
;
2096 lpWaveHdr
->dwFlags
&= ~WHDR_DONE
;
2097 lpWaveHdr
->dwFlags
|= WHDR_INQUEUE
;
2098 lpWaveHdr
->lpNext
= 0;
2100 if ((lpWaveHdr
->dwBufferLength
& (WOutDev
[wDevID
].waveFormat
.Format
.nBlockAlign
- 1)) != 0)
2102 WARN("WaveHdr length isn't a multiple of the PCM block size: %ld %% %d\n",lpWaveHdr
->dwBufferLength
,WOutDev
[wDevID
].waveFormat
.Format
.nBlockAlign
);
2103 lpWaveHdr
->dwBufferLength
&= ~(WOutDev
[wDevID
].waveFormat
.Format
.nBlockAlign
- 1);
2106 OSS_AddRingMessage(&WOutDev
[wDevID
].msgRing
, WINE_WM_HEADER
, (DWORD
)lpWaveHdr
, FALSE
);
2108 return MMSYSERR_NOERROR
;
2111 /**************************************************************************
2112 * wodPrepare [internal]
2114 static DWORD
wodPrepare(WORD wDevID
, LPWAVEHDR lpWaveHdr
, DWORD dwSize
)
2116 TRACE("(%u, %p, %08lX);\n", wDevID
, lpWaveHdr
, dwSize
);
2118 if (wDevID
>= numOutDev
) {
2119 WARN("bad device ID !\n");
2120 return MMSYSERR_BADDEVICEID
;
2123 if (lpWaveHdr
->dwFlags
& WHDR_INQUEUE
)
2124 return WAVERR_STILLPLAYING
;
2126 lpWaveHdr
->dwFlags
|= WHDR_PREPARED
;
2127 lpWaveHdr
->dwFlags
&= ~WHDR_DONE
;
2128 return MMSYSERR_NOERROR
;
2131 /**************************************************************************
2132 * wodUnprepare [internal]
2134 static DWORD
wodUnprepare(WORD wDevID
, LPWAVEHDR lpWaveHdr
, DWORD dwSize
)
2136 TRACE("(%u, %p, %08lX);\n", wDevID
, lpWaveHdr
, dwSize
);
2138 if (wDevID
>= numOutDev
) {
2139 WARN("bad device ID !\n");
2140 return MMSYSERR_BADDEVICEID
;
2143 if (lpWaveHdr
->dwFlags
& WHDR_INQUEUE
)
2144 return WAVERR_STILLPLAYING
;
2146 lpWaveHdr
->dwFlags
&= ~WHDR_PREPARED
;
2147 lpWaveHdr
->dwFlags
|= WHDR_DONE
;
2149 return MMSYSERR_NOERROR
;
2152 /**************************************************************************
2153 * wodPause [internal]
2155 static DWORD
wodPause(WORD wDevID
)
2157 TRACE("(%u);!\n", wDevID
);
2159 if (wDevID
>= numOutDev
|| WOutDev
[wDevID
].state
== WINE_WS_CLOSED
) {
2160 WARN("bad device ID !\n");
2161 return MMSYSERR_BADDEVICEID
;
2164 OSS_AddRingMessage(&WOutDev
[wDevID
].msgRing
, WINE_WM_PAUSING
, 0, TRUE
);
2166 return MMSYSERR_NOERROR
;
2169 /**************************************************************************
2170 * wodRestart [internal]
2172 static DWORD
wodRestart(WORD wDevID
)
2174 TRACE("(%u);\n", wDevID
);
2176 if (wDevID
>= numOutDev
|| WOutDev
[wDevID
].state
== WINE_WS_CLOSED
) {
2177 WARN("bad device ID !\n");
2178 return MMSYSERR_BADDEVICEID
;
2181 OSS_AddRingMessage(&WOutDev
[wDevID
].msgRing
, WINE_WM_RESTARTING
, 0, TRUE
);
2183 /* FIXME: is NotifyClient with WOM_DONE right ? (Comet Busters 1.3.3 needs this notification) */
2184 /* FIXME: Myst crashes with this ... hmm -MM
2185 return wodNotifyClient(wwo, WOM_DONE, 0L, 0L);
2188 return MMSYSERR_NOERROR
;
2191 /**************************************************************************
2192 * wodReset [internal]
2194 static DWORD
wodReset(WORD wDevID
)
2196 TRACE("(%u);\n", wDevID
);
2198 if (wDevID
>= numOutDev
|| WOutDev
[wDevID
].state
== WINE_WS_CLOSED
) {
2199 WARN("bad device ID !\n");
2200 return MMSYSERR_BADDEVICEID
;
2203 OSS_AddRingMessage(&WOutDev
[wDevID
].msgRing
, WINE_WM_RESETTING
, 0, TRUE
);
2205 return MMSYSERR_NOERROR
;
2208 /**************************************************************************
2209 * wodGetPosition [internal]
2211 static DWORD
wodGetPosition(WORD wDevID
, LPMMTIME lpTime
, DWORD uSize
)
2215 TRACE("(%u, %p, %lu);\n", wDevID
, lpTime
, uSize
);
2217 if (wDevID
>= numOutDev
|| WOutDev
[wDevID
].state
== WINE_WS_CLOSED
) {
2218 WARN("bad device ID !\n");
2219 return MMSYSERR_BADDEVICEID
;
2222 if (lpTime
== NULL
) {
2223 WARN("invalid parameter: lpTime == NULL\n");
2224 return MMSYSERR_INVALPARAM
;
2227 wwo
= &WOutDev
[wDevID
];
2228 #ifdef EXACT_WODPOSITION
2229 if (wwo
->ossdev
->open_access
== O_RDWR
) {
2230 if (wwo
->ossdev
->duplex_out_caps
.dwSupport
& WAVECAPS_SAMPLEACCURATE
)
2231 OSS_AddRingMessage(&wwo
->msgRing
, WINE_WM_UPDATE
, 0, TRUE
);
2233 if (wwo
->ossdev
->out_caps
.dwSupport
& WAVECAPS_SAMPLEACCURATE
)
2234 OSS_AddRingMessage(&wwo
->msgRing
, WINE_WM_UPDATE
, 0, TRUE
);
2238 return bytes_to_mmtime(lpTime
, wwo
->dwPlayedTotal
, &wwo
->waveFormat
);
2241 /**************************************************************************
2242 * wodBreakLoop [internal]
2244 static DWORD
wodBreakLoop(WORD wDevID
)
2246 TRACE("(%u);\n", wDevID
);
2248 if (wDevID
>= numOutDev
|| WOutDev
[wDevID
].state
== WINE_WS_CLOSED
) {
2249 WARN("bad device ID !\n");
2250 return MMSYSERR_BADDEVICEID
;
2252 OSS_AddRingMessage(&WOutDev
[wDevID
].msgRing
, WINE_WM_BREAKLOOP
, 0, TRUE
);
2253 return MMSYSERR_NOERROR
;
2256 /**************************************************************************
2257 * wodGetVolume [internal]
2259 static DWORD
wodGetVolume(WORD wDevID
, LPDWORD lpdwVol
)
2264 DWORD last_left
, last_right
;
2266 TRACE("(%u, %p);\n", wDevID
, lpdwVol
);
2268 if (lpdwVol
== NULL
) {
2269 WARN("not enabled\n");
2270 return MMSYSERR_NOTENABLED
;
2272 if (wDevID
>= numOutDev
) {
2273 WARN("invalid parameter\n");
2274 return MMSYSERR_INVALPARAM
;
2277 if ((mixer
= open(WOutDev
[wDevID
].ossdev
->mixer_name
, O_RDONLY
|O_NDELAY
)) < 0) {
2278 WARN("mixer device not available !\n");
2279 return MMSYSERR_NOTENABLED
;
2281 if (ioctl(mixer
, SOUND_MIXER_READ_PCM
, &volume
) == -1) {
2282 WARN("ioctl(%s, SOUND_MIXER_READ_PCM) failed (%s)\n",
2283 WOutDev
[wDevID
].ossdev
->mixer_name
, strerror(errno
));
2284 return MMSYSERR_NOTENABLED
;
2288 left
= LOBYTE(volume
);
2289 right
= HIBYTE(volume
);
2290 TRACE("left=%ld right=%ld !\n", left
, right
);
2291 last_left
= (LOWORD(WOutDev
[wDevID
].volume
) * 100) / 0xFFFFl
;
2292 last_right
= (HIWORD(WOutDev
[wDevID
].volume
) * 100) / 0xFFFFl
;
2293 TRACE("last_left=%ld last_right=%ld !\n", last_left
, last_right
);
2294 if (last_left
== left
&& last_right
== right
)
2295 *lpdwVol
= WOutDev
[wDevID
].volume
;
2297 *lpdwVol
= ((left
* 0xFFFFl
) / 100) + (((right
* 0xFFFFl
) / 100) << 16);
2298 return MMSYSERR_NOERROR
;
2301 /**************************************************************************
2302 * wodSetVolume [internal]
2304 static DWORD
wodSetVolume(WORD wDevID
, DWORD dwParam
)
2310 TRACE("(%u, %08lX);\n", wDevID
, dwParam
);
2312 left
= (LOWORD(dwParam
) * 100) / 0xFFFFl
;
2313 right
= (HIWORD(dwParam
) * 100) / 0xFFFFl
;
2314 volume
= left
+ (right
<< 8);
2316 if (wDevID
>= numOutDev
) {
2317 WARN("invalid parameter: wDevID > %d\n", numOutDev
);
2318 return MMSYSERR_INVALPARAM
;
2320 if ((mixer
= open(WOutDev
[wDevID
].ossdev
->mixer_name
, O_WRONLY
|O_NDELAY
)) < 0) {
2321 WARN("mixer device not available !\n");
2322 return MMSYSERR_NOTENABLED
;
2324 if (ioctl(mixer
, SOUND_MIXER_WRITE_PCM
, &volume
) == -1) {
2325 WARN("ioctl(%s, SOUND_MIXER_WRITE_PCM) failed (%s)\n",
2326 WOutDev
[wDevID
].ossdev
->mixer_name
, strerror(errno
));
2327 return MMSYSERR_NOTENABLED
;
2329 TRACE("volume=%04x\n", (unsigned)volume
);
2333 /* save requested volume */
2334 WOutDev
[wDevID
].volume
= dwParam
;
2336 return MMSYSERR_NOERROR
;
2339 /**************************************************************************
2340 * wodMessage (WINEOSS.7)
2342 DWORD WINAPI
OSS_wodMessage(UINT wDevID
, UINT wMsg
, DWORD dwUser
,
2343 DWORD dwParam1
, DWORD dwParam2
)
2345 TRACE("(%u, %s, %08lX, %08lX, %08lX);\n",
2346 wDevID
, getMessage(wMsg
), dwUser
, dwParam1
, dwParam2
);
2353 /* FIXME: Pretend this is supported */
2355 case WODM_OPEN
: return wodOpen (wDevID
, (LPWAVEOPENDESC
)dwParam1
, dwParam2
);
2356 case WODM_CLOSE
: return wodClose (wDevID
);
2357 case WODM_WRITE
: return wodWrite (wDevID
, (LPWAVEHDR
)dwParam1
, dwParam2
);
2358 case WODM_PAUSE
: return wodPause (wDevID
);
2359 case WODM_GETPOS
: return wodGetPosition (wDevID
, (LPMMTIME
)dwParam1
, dwParam2
);
2360 case WODM_BREAKLOOP
: return wodBreakLoop (wDevID
);
2361 case WODM_PREPARE
: return wodPrepare (wDevID
, (LPWAVEHDR
)dwParam1
, dwParam2
);
2362 case WODM_UNPREPARE
: return wodUnprepare (wDevID
, (LPWAVEHDR
)dwParam1
, dwParam2
);
2363 case WODM_GETDEVCAPS
: return wodGetDevCaps (wDevID
, (LPWAVEOUTCAPSA
)dwParam1
, dwParam2
);
2364 case WODM_GETNUMDEVS
: return numOutDev
;
2365 case WODM_GETPITCH
: return MMSYSERR_NOTSUPPORTED
;
2366 case WODM_SETPITCH
: return MMSYSERR_NOTSUPPORTED
;
2367 case WODM_GETPLAYBACKRATE
: return MMSYSERR_NOTSUPPORTED
;
2368 case WODM_SETPLAYBACKRATE
: return MMSYSERR_NOTSUPPORTED
;
2369 case WODM_GETVOLUME
: return wodGetVolume (wDevID
, (LPDWORD
)dwParam1
);
2370 case WODM_SETVOLUME
: return wodSetVolume (wDevID
, dwParam1
);
2371 case WODM_RESTART
: return wodRestart (wDevID
);
2372 case WODM_RESET
: return wodReset (wDevID
);
2374 case DRV_QUERYDEVICEINTERFACESIZE
: return wdDevInterfaceSize (wDevID
, (LPDWORD
)dwParam1
);
2375 case DRV_QUERYDEVICEINTERFACE
: return wdDevInterface (wDevID
, (PWCHAR
)dwParam1
, dwParam2
);
2376 case DRV_QUERYDSOUNDIFACE
: return wodDsCreate (wDevID
, (PIDSDRIVER
*)dwParam1
);
2377 case DRV_QUERYDSOUNDDESC
: return wodDsDesc (wDevID
, (PDSDRIVERDESC
)dwParam1
);
2379 FIXME("unknown message %d!\n", wMsg
);
2381 return MMSYSERR_NOTSUPPORTED
;
2384 /*======================================================================*
2385 * Low level DSOUND definitions *
2386 *======================================================================*/
2388 typedef struct IDsDriverPropertySetImpl IDsDriverPropertySetImpl
;
2389 typedef struct IDsDriverNotifyImpl IDsDriverNotifyImpl
;
2390 typedef struct IDsDriverImpl IDsDriverImpl
;
2391 typedef struct IDsDriverBufferImpl IDsDriverBufferImpl
;
2393 struct IDsDriverPropertySetImpl
2395 /* IUnknown fields */
2396 IDsDriverPropertySetVtbl
*lpVtbl
;
2399 IDsDriverBufferImpl
* buffer
;
2402 struct IDsDriverNotifyImpl
2404 /* IUnknown fields */
2405 IDsDriverNotifyVtbl
*lpVtbl
;
2408 /* IDsDriverNotifyImpl fields */
2409 LPDSBPOSITIONNOTIFY notifies
;
2412 IDsDriverBufferImpl
* buffer
;
2415 struct IDsDriverImpl
2417 /* IUnknown fields */
2418 IDsDriverVtbl
*lpVtbl
;
2421 /* IDsDriverImpl fields */
2423 IDsDriverBufferImpl
* primary
;
2425 int nrofsecondaries
;
2426 IDsDriverBufferImpl
** secondaries
;
2429 struct IDsDriverBufferImpl
2431 /* IUnknown fields */
2432 IDsDriverBufferVtbl
*lpVtbl
;
2435 /* IDsDriverBufferImpl fields */
2438 WAVEFORMATPCMEX wfex
;
2444 /* IDsDriverNotifyImpl fields */
2445 IDsDriverNotifyImpl
* notify
;
2448 /* IDsDriverPropertySetImpl fields */
2449 IDsDriverPropertySetImpl
* property_set
;
2452 static HRESULT WINAPI
IDsDriverPropertySetImpl_Create(
2453 IDsDriverBufferImpl
* dsdb
,
2454 IDsDriverPropertySetImpl
**pdsdps
);
2456 static HRESULT WINAPI
IDsDriverNotifyImpl_Create(
2457 IDsDriverBufferImpl
* dsdb
,
2458 IDsDriverNotifyImpl
**pdsdn
);
2460 /*======================================================================*
2461 * Low level DSOUND property set implementation *
2462 *======================================================================*/
2464 static HRESULT WINAPI
IDsDriverPropertySetImpl_QueryInterface(
2465 PIDSDRIVERPROPERTYSET iface
,
2469 ICOM_THIS(IDsDriverPropertySetImpl
,iface
);
2470 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppobj
);
2472 if ( IsEqualGUID(riid
, &IID_IUnknown
) ||
2473 IsEqualGUID(riid
, &IID_IDsDriverPropertySet
) ) {
2474 IDsDriverPropertySet_AddRef(iface
);
2475 *ppobj
= (LPVOID
)This
;
2479 FIXME( "Unknown IID %s\n", debugstr_guid( riid
) );
2482 return E_NOINTERFACE
;
2485 static ULONG WINAPI
IDsDriverPropertySetImpl_AddRef(PIDSDRIVERPROPERTYSET iface
)
2487 ICOM_THIS(IDsDriverPropertySetImpl
,iface
);
2488 TRACE("(%p) ref was %ld\n", This
, This
->ref
);
2490 return InterlockedIncrement(&(This
->ref
));
2493 static ULONG WINAPI
IDsDriverPropertySetImpl_Release(PIDSDRIVERPROPERTYSET iface
)
2495 ICOM_THIS(IDsDriverPropertySetImpl
,iface
);
2497 TRACE("(%p) ref was %ld\n", This
, This
->ref
);
2499 ref
= InterlockedDecrement(&(This
->ref
));
2501 IDsDriverBuffer_Release((PIDSDRIVERBUFFER
)This
->buffer
);
2502 HeapFree(GetProcessHeap(),0,This
);
2503 TRACE("(%p) released\n",This
);
2508 static HRESULT WINAPI
IDsDriverPropertySetImpl_Get(
2509 PIDSDRIVERPROPERTYSET iface
,
2510 PDSPROPERTY pDsProperty
,
2511 LPVOID pPropertyParams
,
2512 ULONG cbPropertyParams
,
2513 LPVOID pPropertyData
,
2514 ULONG cbPropertyData
,
2515 PULONG pcbReturnedData
)
2517 ICOM_THIS(IDsDriverPropertySetImpl
,iface
);
2518 FIXME("(%p,%p,%p,%lx,%p,%lx,%p)\n",This
,pDsProperty
,pPropertyParams
,cbPropertyParams
,pPropertyData
,cbPropertyData
,pcbReturnedData
);
2519 return DSERR_UNSUPPORTED
;
2522 static HRESULT WINAPI
IDsDriverPropertySetImpl_Set(
2523 PIDSDRIVERPROPERTYSET iface
,
2524 PDSPROPERTY pDsProperty
,
2525 LPVOID pPropertyParams
,
2526 ULONG cbPropertyParams
,
2527 LPVOID pPropertyData
,
2528 ULONG cbPropertyData
)
2530 ICOM_THIS(IDsDriverPropertySetImpl
,iface
);
2531 FIXME("(%p,%p,%p,%lx,%p,%lx)\n",This
,pDsProperty
,pPropertyParams
,cbPropertyParams
,pPropertyData
,cbPropertyData
);
2532 return DSERR_UNSUPPORTED
;
2535 static HRESULT WINAPI
IDsDriverPropertySetImpl_QuerySupport(
2536 PIDSDRIVERPROPERTYSET iface
,
2537 REFGUID PropertySetId
,
2541 ICOM_THIS(IDsDriverPropertySetImpl
,iface
);
2542 FIXME("(%p,%s,%lx,%p)\n",This
,debugstr_guid(PropertySetId
),PropertyId
,pSupport
);
2543 return DSERR_UNSUPPORTED
;
2546 IDsDriverPropertySetVtbl dsdpsvt
=
2548 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
2549 IDsDriverPropertySetImpl_QueryInterface
,
2550 IDsDriverPropertySetImpl_AddRef
,
2551 IDsDriverPropertySetImpl_Release
,
2552 IDsDriverPropertySetImpl_Get
,
2553 IDsDriverPropertySetImpl_Set
,
2554 IDsDriverPropertySetImpl_QuerySupport
,
2557 /*======================================================================*
2558 * Low level DSOUND notify implementation *
2559 *======================================================================*/
2561 static HRESULT WINAPI
IDsDriverNotifyImpl_QueryInterface(
2562 PIDSDRIVERNOTIFY iface
,
2566 ICOM_THIS(IDsDriverNotifyImpl
,iface
);
2567 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppobj
);
2569 if ( IsEqualGUID(riid
, &IID_IUnknown
) ||
2570 IsEqualGUID(riid
, &IID_IDsDriverNotify
) ) {
2571 IDsDriverNotify_AddRef(iface
);
2576 FIXME( "Unknown IID %s\n", debugstr_guid( riid
) );
2579 return E_NOINTERFACE
;
2582 static ULONG WINAPI
IDsDriverNotifyImpl_AddRef(PIDSDRIVERNOTIFY iface
)
2584 ICOM_THIS(IDsDriverNotifyImpl
,iface
);
2585 TRACE("(%p) ref was %ld\n", This
, This
->ref
);
2587 return InterlockedIncrement(&(This
->ref
));
2590 static ULONG WINAPI
IDsDriverNotifyImpl_Release(PIDSDRIVERNOTIFY iface
)
2592 ICOM_THIS(IDsDriverNotifyImpl
,iface
);
2594 TRACE("(%p) ref was %ld\n", This
, This
->ref
);
2596 ref
= InterlockedDecrement(&(This
->ref
));
2598 IDsDriverBuffer_Release((PIDSDRIVERBUFFER
)This
->buffer
);
2599 if (This
->notifies
!= NULL
)
2600 HeapFree(GetProcessHeap(), 0, This
->notifies
);
2601 HeapFree(GetProcessHeap(),0,This
);
2602 TRACE("(%p) released\n",This
);
2607 static HRESULT WINAPI
IDsDriverNotifyImpl_SetNotificationPositions(
2608 PIDSDRIVERNOTIFY iface
,
2610 LPCDSBPOSITIONNOTIFY notify
)
2612 ICOM_THIS(IDsDriverNotifyImpl
,iface
);
2613 TRACE("(%p,0x%08lx,%p)\n",This
,howmuch
,notify
);
2616 WARN("invalid parameter\n");
2617 return DSERR_INVALIDPARAM
;
2620 if (TRACE_ON(wave
)) {
2622 for (i
=0;i
<howmuch
;i
++)
2623 TRACE("notify at %ld to 0x%08lx\n",
2624 notify
[i
].dwOffset
,(DWORD
)notify
[i
].hEventNotify
);
2627 /* Make an internal copy of the caller-supplied array.
2628 * Replace the existing copy if one is already present. */
2630 This
->notifies
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2631 This
->notifies
, howmuch
* sizeof(DSBPOSITIONNOTIFY
));
2633 This
->notifies
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
2634 howmuch
* sizeof(DSBPOSITIONNOTIFY
));
2636 memcpy(This
->notifies
, notify
, howmuch
* sizeof(DSBPOSITIONNOTIFY
));
2637 This
->nrofnotifies
= howmuch
;
2642 IDsDriverNotifyVtbl dsdnvt
=
2644 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
2645 IDsDriverNotifyImpl_QueryInterface
,
2646 IDsDriverNotifyImpl_AddRef
,
2647 IDsDriverNotifyImpl_Release
,
2648 IDsDriverNotifyImpl_SetNotificationPositions
,
2651 /*======================================================================*
2652 * Low level DSOUND implementation *
2653 *======================================================================*/
2655 static HRESULT
DSDB_MapBuffer(IDsDriverBufferImpl
*dsdb
)
2657 TRACE("(%p), format=%ldx%dx%d\n", dsdb
, dsdb
->wfex
.Format
.nSamplesPerSec
,
2658 dsdb
->wfex
.Format
.wBitsPerSample
, dsdb
->wfex
.Format
.nChannels
);
2659 if (!dsdb
->mapping
) {
2660 dsdb
->mapping
= mmap(NULL
, dsdb
->maplen
, PROT_WRITE
, MAP_SHARED
,
2662 if (dsdb
->mapping
== (LPBYTE
)-1) {
2663 ERR("Could not map sound device for direct access (%s)\n", strerror(errno
));
2664 ERR("Use: \"HardwareAcceleration\" = \"Emulation\" in the [dsound] section of your config file.\n");
2665 return DSERR_GENERIC
;
2667 TRACE("The sound device has been mapped for direct access at %p, size=%ld\n", dsdb
->mapping
, dsdb
->maplen
);
2669 /* for some reason, es1371 and sblive! sometimes have junk in here.
2670 * clear it, or we get junk noise */
2671 /* some libc implementations are buggy: their memset reads from the buffer...
2672 * to work around it, we have to zero the block by hand. We don't do the expected:
2673 * memset(dsdb->mapping,0, dsdb->maplen);
2676 unsigned char* p1
= dsdb
->mapping
;
2677 unsigned len
= dsdb
->maplen
;
2678 unsigned char silence
= (dsdb
->wfex
.Format
.wBitsPerSample
== 8) ? 128 : 0;
2679 unsigned long ulsilence
= (dsdb
->wfex
.Format
.wBitsPerSample
== 8) ? 0x80808080 : 0;
2681 if (len
>= 16) /* so we can have at least a 4 long area to store... */
2683 /* the mmap:ed value is (at least) dword aligned
2684 * so, start filling the complete unsigned long:s
2687 unsigned long* p4
= (unsigned long*)p1
;
2689 while (b
--) *p4
++ = ulsilence
;
2690 /* prepare for filling the rest */
2692 p1
= (unsigned char*)p4
;
2694 /* in all cases, fill the remaining bytes */
2695 while (len
-- != 0) *p1
++ = silence
;
2701 static HRESULT
DSDB_UnmapBuffer(IDsDriverBufferImpl
*dsdb
)
2703 TRACE("(%p)\n",dsdb
);
2704 if (dsdb
->mapping
) {
2705 if (munmap(dsdb
->mapping
, dsdb
->maplen
) < 0) {
2706 ERR("(%p): Could not unmap sound device (%s)\n", dsdb
, strerror(errno
));
2707 return DSERR_GENERIC
;
2709 dsdb
->mapping
= NULL
;
2710 TRACE("(%p): sound device unmapped\n", dsdb
);
2715 static HRESULT WINAPI
IDsDriverBufferImpl_QueryInterface(PIDSDRIVERBUFFER iface
, REFIID riid
, LPVOID
*ppobj
)
2717 ICOM_THIS(IDsDriverBufferImpl
,iface
);
2718 TRACE("(%p,%s,%p)\n",iface
,debugstr_guid(riid
),*ppobj
);
2720 if ( IsEqualGUID(riid
, &IID_IUnknown
) ||
2721 IsEqualGUID(riid
, &IID_IDsDriverBuffer
) ) {
2722 IDsDriverBuffer_AddRef(iface
);
2723 *ppobj
= (LPVOID
)This
;
2727 if ( IsEqualGUID( &IID_IDsDriverNotify
, riid
) ) {
2729 IDsDriverNotifyImpl_Create(This
, &(This
->notify
));
2731 IDsDriverNotify_AddRef((PIDSDRIVERNOTIFY
)This
->notify
);
2732 *ppobj
= (LPVOID
)This
->notify
;
2739 if ( IsEqualGUID( &IID_IDsDriverPropertySet
, riid
) ) {
2740 if (!This
->property_set
)
2741 IDsDriverPropertySetImpl_Create(This
, &(This
->property_set
));
2742 if (This
->property_set
) {
2743 IDsDriverPropertySet_AddRef((PIDSDRIVERPROPERTYSET
)This
->property_set
);
2744 *ppobj
= (LPVOID
)This
->property_set
;
2751 FIXME( "Unknown IID %s\n", debugstr_guid( riid
) );
2755 return E_NOINTERFACE
;
2758 static ULONG WINAPI
IDsDriverBufferImpl_AddRef(PIDSDRIVERBUFFER iface
)
2760 ICOM_THIS(IDsDriverBufferImpl
,iface
);
2761 TRACE("(%p) ref was %ld\n", This
, This
->ref
);
2763 return InterlockedIncrement(&(This
->ref
));
2766 static ULONG WINAPI
IDsDriverBufferImpl_Release(PIDSDRIVERBUFFER iface
)
2768 ICOM_THIS(IDsDriverBufferImpl
,iface
);
2770 TRACE("(%p) ref was %ld\n", This
, This
->ref
);
2772 ref
= InterlockedDecrement(&(This
->ref
));
2776 if (This
== This
->drv
->primary
)
2777 This
->drv
->primary
= NULL
;
2780 for (i
= 0; i
< This
->drv
->nrofsecondaries
; i
++)
2781 if (This
->drv
->secondaries
[i
] == This
)
2783 if (i
< This
->drv
->nrofsecondaries
) {
2784 /* Put the last buffer of the list in the (now empty) position */
2785 This
->drv
->secondaries
[i
] = This
->drv
->secondaries
[This
->drv
->nrofsecondaries
- 1];
2786 This
->drv
->nrofsecondaries
--;
2787 This
->drv
->secondaries
= HeapReAlloc(GetProcessHeap(),0,
2788 This
->drv
->secondaries
,
2789 sizeof(PIDSDRIVERBUFFER
)*This
->drv
->nrofsecondaries
);
2790 TRACE("(%p) buffer count is now %d\n", This
, This
->drv
->nrofsecondaries
);
2793 WOutDev
[This
->drv
->wDevID
].ossdev
->ds_caps
.dwFreeHwMixingAllBuffers
++;
2794 WOutDev
[This
->drv
->wDevID
].ossdev
->ds_caps
.dwFreeHwMixingStreamingBuffers
++;
2797 DSDB_UnmapBuffer(This
);
2798 HeapFree(GetProcessHeap(),0,This
);
2799 TRACE("(%p) released\n",This
);
2803 static HRESULT WINAPI
IDsDriverBufferImpl_Lock(PIDSDRIVERBUFFER iface
,
2804 LPVOID
*ppvAudio1
,LPDWORD pdwLen1
,
2805 LPVOID
*ppvAudio2
,LPDWORD pdwLen2
,
2806 DWORD dwWritePosition
,DWORD dwWriteLen
,
2809 /* ICOM_THIS(IDsDriverBufferImpl,iface); */
2810 /* since we (GetDriverDesc flags) have specified DSDDESC_DONTNEEDPRIMARYLOCK,
2811 * and that we don't support secondary buffers, this method will never be called */
2812 TRACE("(%p): stub\n",iface
);
2813 return DSERR_UNSUPPORTED
;
2816 static HRESULT WINAPI
IDsDriverBufferImpl_Unlock(PIDSDRIVERBUFFER iface
,
2817 LPVOID pvAudio1
,DWORD dwLen1
,
2818 LPVOID pvAudio2
,DWORD dwLen2
)
2820 /* ICOM_THIS(IDsDriverBufferImpl,iface); */
2821 TRACE("(%p): stub\n",iface
);
2822 return DSERR_UNSUPPORTED
;
2825 static HRESULT WINAPI
IDsDriverBufferImpl_SetFormat(PIDSDRIVERBUFFER iface
,
2826 LPWAVEFORMATEX pwfx
)
2828 /* ICOM_THIS(IDsDriverBufferImpl,iface); */
2830 TRACE("(%p,%p)\n",iface
,pwfx
);
2831 /* On our request (GetDriverDesc flags), DirectSound has by now used
2832 * waveOutClose/waveOutOpen to set the format...
2833 * unfortunately, this means our mmap() is now gone...
2834 * so we need to somehow signal to our DirectSound implementation
2835 * that it should completely recreate this HW buffer...
2836 * this unexpected error code should do the trick... */
2837 return DSERR_BUFFERLOST
;
2840 static HRESULT WINAPI
IDsDriverBufferImpl_SetFrequency(PIDSDRIVERBUFFER iface
, DWORD dwFreq
)
2842 /* ICOM_THIS(IDsDriverBufferImpl,iface); */
2843 TRACE("(%p,%ld): stub\n",iface
,dwFreq
);
2844 return DSERR_UNSUPPORTED
;
2847 static HRESULT WINAPI
IDsDriverBufferImpl_SetVolumePan(PIDSDRIVERBUFFER iface
, PDSVOLUMEPAN pVolPan
)
2850 ICOM_THIS(IDsDriverBufferImpl
,iface
);
2851 TRACE("(%p,%p)\n",This
,pVolPan
);
2853 vol
= pVolPan
->dwTotalLeftAmpFactor
| (pVolPan
->dwTotalRightAmpFactor
<< 16);
2855 if (wodSetVolume(This
->drv
->wDevID
, vol
) != MMSYSERR_NOERROR
) {
2856 WARN("wodSetVolume failed\n");
2857 return DSERR_INVALIDPARAM
;
2863 static HRESULT WINAPI
IDsDriverBufferImpl_SetPosition(PIDSDRIVERBUFFER iface
, DWORD dwNewPos
)
2865 /* ICOM_THIS(IDsDriverImpl,iface); */
2866 TRACE("(%p,%ld): stub\n",iface
,dwNewPos
);
2867 return DSERR_UNSUPPORTED
;
2870 static HRESULT WINAPI
IDsDriverBufferImpl_GetPosition(PIDSDRIVERBUFFER iface
,
2871 LPDWORD lpdwPlay
, LPDWORD lpdwWrite
)
2873 ICOM_THIS(IDsDriverBufferImpl
,iface
);
2877 TRACE("(%p)\n",iface
);
2878 if (WOutDev
[This
->drv
->wDevID
].state
== WINE_WS_CLOSED
) {
2879 ERR("device not open, but accessing?\n");
2880 return DSERR_UNINITIALIZED
;
2882 if (ioctl(This
->fd
, SNDCTL_DSP_GETOPTR
, &info
) < 0) {
2883 ERR("ioctl(%s, SNDCTL_DSP_GETOPTR) failed (%s)\n",
2884 WOutDev
[This
->drv
->wDevID
].ossdev
->dev_name
, strerror(errno
));
2885 return DSERR_GENERIC
;
2887 ptr
= info
.ptr
& ~3; /* align the pointer, just in case */
2888 if (lpdwPlay
) *lpdwPlay
= ptr
;
2890 /* add some safety margin (not strictly necessary, but...) */
2891 if (WOutDev
[This
->drv
->wDevID
].ossdev
->duplex_out_caps
.dwSupport
& WAVECAPS_SAMPLEACCURATE
)
2892 *lpdwWrite
= ptr
+ 32;
2894 *lpdwWrite
= ptr
+ WOutDev
[This
->drv
->wDevID
].dwFragmentSize
;
2895 while (*lpdwWrite
> This
->buflen
)
2896 *lpdwWrite
-= This
->buflen
;
2898 TRACE("playpos=%ld, writepos=%ld\n", lpdwPlay
?*lpdwPlay
:0, lpdwWrite
?*lpdwWrite
:0);
2902 static HRESULT WINAPI
IDsDriverBufferImpl_Play(PIDSDRIVERBUFFER iface
, DWORD dwRes1
, DWORD dwRes2
, DWORD dwFlags
)
2904 ICOM_THIS(IDsDriverBufferImpl
,iface
);
2906 TRACE("(%p,%lx,%lx,%lx)\n",iface
,dwRes1
,dwRes2
,dwFlags
);
2907 WOutDev
[This
->drv
->wDevID
].ossdev
->bOutputEnabled
= TRUE
;
2908 enable
= getEnables(WOutDev
[This
->drv
->wDevID
].ossdev
);
2909 if (ioctl(This
->fd
, SNDCTL_DSP_SETTRIGGER
, &enable
) < 0) {
2910 if (errno
== EINVAL
) {
2911 /* Don't give up yet. OSS trigger support is inconsistent. */
2912 if (WOutDev
[This
->drv
->wDevID
].ossdev
->open_count
== 1) {
2913 /* try the opposite input enable */
2914 if (WOutDev
[This
->drv
->wDevID
].ossdev
->bInputEnabled
== FALSE
)
2915 WOutDev
[This
->drv
->wDevID
].ossdev
->bInputEnabled
= TRUE
;
2917 WOutDev
[This
->drv
->wDevID
].ossdev
->bInputEnabled
= FALSE
;
2919 enable
= getEnables(WOutDev
[This
->drv
->wDevID
].ossdev
);
2920 if (ioctl(This
->fd
, SNDCTL_DSP_SETTRIGGER
, &enable
) >= 0)
2924 ERR("ioctl(%s, SNDCTL_DSP_SETTRIGGER) failed (%s)\n",
2925 WOutDev
[This
->drv
->wDevID
].ossdev
->dev_name
, strerror(errno
));
2926 WOutDev
[This
->drv
->wDevID
].ossdev
->bOutputEnabled
= FALSE
;
2927 return DSERR_GENERIC
;
2932 static HRESULT WINAPI
IDsDriverBufferImpl_Stop(PIDSDRIVERBUFFER iface
)
2934 ICOM_THIS(IDsDriverBufferImpl
,iface
);
2936 TRACE("(%p)\n",iface
);
2937 /* no more playing */
2938 WOutDev
[This
->drv
->wDevID
].ossdev
->bOutputEnabled
= FALSE
;
2939 enable
= getEnables(WOutDev
[This
->drv
->wDevID
].ossdev
);
2940 if (ioctl(This
->fd
, SNDCTL_DSP_SETTRIGGER
, &enable
) < 0) {
2941 ERR("ioctl(%s, SNDCTL_DSP_SETTRIGGER) failed (%s)\n", WOutDev
[This
->drv
->wDevID
].ossdev
->dev_name
, strerror(errno
));
2942 return DSERR_GENERIC
;
2945 /* the play position must be reset to the beginning of the buffer */
2946 if (ioctl(This
->fd
, SNDCTL_DSP_RESET
, 0) < 0) {
2947 ERR("ioctl(%s, SNDCTL_DSP_RESET) failed (%s)\n", WOutDev
[This
->drv
->wDevID
].ossdev
->dev_name
, strerror(errno
));
2948 return DSERR_GENERIC
;
2951 /* Most OSS drivers just can't stop the playback without closing the device...
2952 * so we need to somehow signal to our DirectSound implementation
2953 * that it should completely recreate this HW buffer...
2954 * this unexpected error code should do the trick... */
2955 /* FIXME: ...unless we are doing full duplex, then it's not nice to close the device */
2956 if (WOutDev
[This
->drv
->wDevID
].ossdev
->open_count
== 1)
2957 return DSERR_BUFFERLOST
;
2962 static IDsDriverBufferVtbl dsdbvt
=
2964 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
2965 IDsDriverBufferImpl_QueryInterface
,
2966 IDsDriverBufferImpl_AddRef
,
2967 IDsDriverBufferImpl_Release
,
2968 IDsDriverBufferImpl_Lock
,
2969 IDsDriverBufferImpl_Unlock
,
2970 IDsDriverBufferImpl_SetFormat
,
2971 IDsDriverBufferImpl_SetFrequency
,
2972 IDsDriverBufferImpl_SetVolumePan
,
2973 IDsDriverBufferImpl_SetPosition
,
2974 IDsDriverBufferImpl_GetPosition
,
2975 IDsDriverBufferImpl_Play
,
2976 IDsDriverBufferImpl_Stop
2979 static HRESULT WINAPI
IDsDriverImpl_QueryInterface(PIDSDRIVER iface
, REFIID riid
, LPVOID
*ppobj
)
2981 ICOM_THIS(IDsDriverImpl
,iface
);
2982 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppobj
);
2984 if ( IsEqualGUID(riid
, &IID_IUnknown
) ||
2985 IsEqualGUID(riid
, &IID_IDsDriver
) ) {
2986 IDsDriver_AddRef(iface
);
2987 *ppobj
= (LPVOID
)This
;
2991 FIXME( "Unknown IID %s\n", debugstr_guid( riid
) );
2995 return E_NOINTERFACE
;
2998 static ULONG WINAPI
IDsDriverImpl_AddRef(PIDSDRIVER iface
)
3000 ICOM_THIS(IDsDriverImpl
,iface
);
3001 TRACE("(%p) ref was %ld\n", This
, This
->ref
);
3003 return InterlockedIncrement(&(This
->ref
));
3006 static ULONG WINAPI
IDsDriverImpl_Release(PIDSDRIVER iface
)
3008 ICOM_THIS(IDsDriverImpl
,iface
);
3010 TRACE("(%p) ref was %ld\n", This
, This
->ref
);
3012 ref
= InterlockedDecrement(&(This
->ref
));
3014 HeapFree(GetProcessHeap(),0,This
);
3015 TRACE("(%p) released\n",This
);
3020 static HRESULT WINAPI
IDsDriverImpl_GetDriverDesc(PIDSDRIVER iface
,
3021 PDSDRIVERDESC pDesc
)
3023 ICOM_THIS(IDsDriverImpl
,iface
);
3024 TRACE("(%p,%p)\n",iface
,pDesc
);
3026 /* copy version from driver */
3027 memcpy(pDesc
, &(WOutDev
[This
->wDevID
].ossdev
->ds_desc
), sizeof(DSDRIVERDESC
));
3029 pDesc
->dwFlags
|= DSDDESC_DOMMSYSTEMOPEN
| DSDDESC_DOMMSYSTEMSETFORMAT
|
3030 DSDDESC_USESYSTEMMEMORY
| DSDDESC_DONTNEEDPRIMARYLOCK
|
3031 DSDDESC_DONTNEEDSECONDARYLOCK
;
3032 pDesc
->dnDevNode
= WOutDev
[This
->wDevID
].waveDesc
.dnDevNode
;
3034 pDesc
->wReserved
= 0;
3035 pDesc
->ulDeviceNum
= This
->wDevID
;
3036 pDesc
->dwHeapType
= DSDHEAP_NOHEAP
;
3037 pDesc
->pvDirectDrawHeap
= NULL
;
3038 pDesc
->dwMemStartAddress
= 0;
3039 pDesc
->dwMemEndAddress
= 0;
3040 pDesc
->dwMemAllocExtra
= 0;
3041 pDesc
->pvReserved1
= NULL
;
3042 pDesc
->pvReserved2
= NULL
;
3046 static HRESULT WINAPI
IDsDriverImpl_Open(PIDSDRIVER iface
)
3048 ICOM_THIS(IDsDriverImpl
,iface
);
3050 TRACE("(%p)\n",iface
);
3052 /* make sure the card doesn't start playing before we want it to */
3053 WOutDev
[This
->wDevID
].ossdev
->bOutputEnabled
= FALSE
;
3054 enable
= getEnables(WOutDev
[This
->wDevID
].ossdev
);
3055 if (ioctl(WOutDev
[This
->wDevID
].ossdev
->fd
, SNDCTL_DSP_SETTRIGGER
, &enable
) < 0) {
3056 ERR("ioctl(%s, SNDCTL_DSP_SETTRIGGER) failed (%s)\n",WOutDev
[This
->wDevID
].ossdev
->dev_name
, strerror(errno
));
3057 return DSERR_GENERIC
;
3062 static HRESULT WINAPI
IDsDriverImpl_Close(PIDSDRIVER iface
)
3064 ICOM_THIS(IDsDriverImpl
,iface
);
3065 TRACE("(%p)\n",iface
);
3066 if (This
->primary
) {
3067 ERR("problem with DirectSound: primary not released\n");
3068 return DSERR_GENERIC
;
3073 static HRESULT WINAPI
IDsDriverImpl_GetCaps(PIDSDRIVER iface
, PDSDRIVERCAPS pCaps
)
3075 ICOM_THIS(IDsDriverImpl
,iface
);
3076 TRACE("(%p,%p)\n",iface
,pCaps
);
3077 memcpy(pCaps
, &(WOutDev
[This
->wDevID
].ossdev
->ds_caps
), sizeof(DSDRIVERCAPS
));
3081 static HRESULT WINAPI
DSD_CreatePrimaryBuffer(PIDSDRIVER iface
,
3082 LPWAVEFORMATEX pwfx
,
3084 DWORD dwCardAddress
,
3085 LPDWORD pdwcbBufferSize
,
3089 ICOM_THIS(IDsDriverImpl
,iface
);
3090 IDsDriverBufferImpl
** ippdsdb
= (IDsDriverBufferImpl
**)ppvObj
;
3092 audio_buf_info info
;
3094 TRACE("(%p,%p,%lx,%lx,%p,%p,%p)\n",iface
,pwfx
,dwFlags
,dwCardAddress
,pdwcbBufferSize
,ppbBuffer
,ppvObj
);
3097 return DSERR_ALLOCATED
;
3098 if (dwFlags
& (DSBCAPS_CTRLFREQUENCY
| DSBCAPS_CTRLPAN
))
3099 return DSERR_CONTROLUNAVAIL
;
3101 *ippdsdb
= (IDsDriverBufferImpl
*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDsDriverBufferImpl
));
3102 if (*ippdsdb
== NULL
)
3103 return DSERR_OUTOFMEMORY
;
3104 (*ippdsdb
)->lpVtbl
= &dsdbvt
;
3105 (*ippdsdb
)->ref
= 1;
3106 (*ippdsdb
)->drv
= This
;
3107 copy_format(pwfx
, &(*ippdsdb
)->wfex
);
3108 (*ippdsdb
)->fd
= WOutDev
[This
->wDevID
].ossdev
->fd
;
3109 (*ippdsdb
)->dwFlags
= dwFlags
;
3111 /* check how big the DMA buffer is now */
3112 if (ioctl((*ippdsdb
)->fd
, SNDCTL_DSP_GETOSPACE
, &info
) < 0) {
3113 ERR("ioctl(%s, SNDCTL_DSP_GETOSPACE) failed (%s)\n",
3114 WOutDev
[This
->wDevID
].ossdev
->dev_name
, strerror(errno
));
3115 HeapFree(GetProcessHeap(),0,*ippdsdb
);
3117 return DSERR_GENERIC
;
3119 (*ippdsdb
)->maplen
= (*ippdsdb
)->buflen
= info
.fragstotal
* info
.fragsize
;
3121 /* map the DMA buffer */
3122 err
= DSDB_MapBuffer(*ippdsdb
);
3124 HeapFree(GetProcessHeap(),0,*ippdsdb
);
3129 /* primary buffer is ready to go */
3130 *pdwcbBufferSize
= (*ippdsdb
)->maplen
;
3131 *ppbBuffer
= (*ippdsdb
)->mapping
;
3133 /* some drivers need some extra nudging after mapping */
3134 WOutDev
[This
->wDevID
].ossdev
->bOutputEnabled
= FALSE
;
3135 enable
= getEnables(WOutDev
[This
->wDevID
].ossdev
);
3136 if (ioctl((*ippdsdb
)->fd
, SNDCTL_DSP_SETTRIGGER
, &enable
) < 0) {
3137 ERR("ioctl(%s, SNDCTL_DSP_SETTRIGGER) failed (%s)\n",
3138 WOutDev
[This
->wDevID
].ossdev
->dev_name
, strerror(errno
));
3139 return DSERR_GENERIC
;
3142 This
->primary
= *ippdsdb
;
3147 static HRESULT WINAPI
DSD_CreateSecondaryBuffer(PIDSDRIVER iface
,
3148 LPWAVEFORMATEX pwfx
,
3150 DWORD dwCardAddress
,
3151 LPDWORD pdwcbBufferSize
,
3155 ICOM_THIS(IDsDriverImpl
,iface
);
3156 IDsDriverBufferImpl
** ippdsdb
= (IDsDriverBufferImpl
**)ppvObj
;
3157 FIXME("(%p,%p,%lx,%lx,%p,%p,%p): stub\n",This
,pwfx
,dwFlags
,dwCardAddress
,pdwcbBufferSize
,ppbBuffer
,ppvObj
);
3160 return DSERR_UNSUPPORTED
;
3163 static HRESULT WINAPI
IDsDriverImpl_CreateSoundBuffer(PIDSDRIVER iface
,
3164 LPWAVEFORMATEX pwfx
,
3166 DWORD dwCardAddress
,
3167 LPDWORD pdwcbBufferSize
,
3171 TRACE("(%p,%p,%lx,%lx,%p,%p,%p)\n",iface
,pwfx
,dwFlags
,dwCardAddress
,pdwcbBufferSize
,ppbBuffer
,ppvObj
);
3173 if (dwFlags
& DSBCAPS_PRIMARYBUFFER
)
3174 return DSD_CreatePrimaryBuffer(iface
,pwfx
,dwFlags
,dwCardAddress
,pdwcbBufferSize
,ppbBuffer
,ppvObj
);
3176 return DSD_CreateSecondaryBuffer(iface
,pwfx
,dwFlags
,dwCardAddress
,pdwcbBufferSize
,ppbBuffer
,ppvObj
);
3179 static HRESULT WINAPI
IDsDriverImpl_DuplicateSoundBuffer(PIDSDRIVER iface
,
3180 PIDSDRIVERBUFFER pBuffer
,
3183 /* ICOM_THIS(IDsDriverImpl,iface); */
3184 TRACE("(%p,%p): stub\n",iface
,pBuffer
);
3185 return DSERR_INVALIDCALL
;
3188 static IDsDriverVtbl dsdvt
=
3190 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
3191 IDsDriverImpl_QueryInterface
,
3192 IDsDriverImpl_AddRef
,
3193 IDsDriverImpl_Release
,
3194 IDsDriverImpl_GetDriverDesc
,
3196 IDsDriverImpl_Close
,
3197 IDsDriverImpl_GetCaps
,
3198 IDsDriverImpl_CreateSoundBuffer
,
3199 IDsDriverImpl_DuplicateSoundBuffer
3202 static HRESULT WINAPI
IDsDriverPropertySetImpl_Create(
3203 IDsDriverBufferImpl
* dsdb
,
3204 IDsDriverPropertySetImpl
**pdsdps
)
3206 IDsDriverPropertySetImpl
* dsdps
;
3207 TRACE("(%p,%p)\n",dsdb
,pdsdps
);
3209 dsdps
= (IDsDriverPropertySetImpl
*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(dsdps
));
3210 if (dsdps
== NULL
) {
3211 WARN("out of memory\n");
3212 return DSERR_OUTOFMEMORY
;
3216 dsdps
->lpVtbl
= &dsdpsvt
;
3217 dsdps
->buffer
= dsdb
;
3218 dsdb
->property_set
= dsdps
;
3219 IDsDriverBuffer_AddRef((PIDSDRIVER
)dsdb
);
3225 static HRESULT WINAPI
IDsDriverNotifyImpl_Create(
3226 IDsDriverBufferImpl
* dsdb
,
3227 IDsDriverNotifyImpl
**pdsdn
)
3229 IDsDriverNotifyImpl
* dsdn
;
3230 TRACE("(%p,%p)\n",dsdb
,pdsdn
);
3232 dsdn
= (IDsDriverNotifyImpl
*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(dsdn
));
3235 WARN("out of memory\n");
3236 return DSERR_OUTOFMEMORY
;
3240 dsdn
->lpVtbl
= &dsdnvt
;
3241 dsdn
->buffer
= dsdb
;
3242 dsdb
->notify
= dsdn
;
3243 IDsDriverBuffer_AddRef((PIDSDRIVER
)dsdb
);
3249 static DWORD
wodDsCreate(UINT wDevID
, PIDSDRIVER
* drv
)
3251 IDsDriverImpl
** idrv
= (IDsDriverImpl
**)drv
;
3252 TRACE("(%d,%p)\n",wDevID
,drv
);
3254 /* the HAL isn't much better than the HEL if we can't do mmap() */
3255 if (!(WOutDev
[wDevID
].ossdev
->duplex_out_caps
.dwSupport
& WAVECAPS_DIRECTSOUND
)) {
3256 ERR("DirectSound flag not set\n");
3257 MESSAGE("This sound card's driver does not support direct access\n");
3258 MESSAGE("The (slower) DirectSound HEL mode will be used instead.\n");
3259 return MMSYSERR_NOTSUPPORTED
;
3262 *idrv
= (IDsDriverImpl
*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDsDriverImpl
));
3264 return MMSYSERR_NOMEM
;
3265 (*idrv
)->lpVtbl
= &dsdvt
;
3267 (*idrv
)->wDevID
= wDevID
;
3268 (*idrv
)->primary
= NULL
;
3269 (*idrv
)->nrofsecondaries
= 0;
3270 (*idrv
)->secondaries
= NULL
;
3272 return MMSYSERR_NOERROR
;
3275 static DWORD
wodDsDesc(UINT wDevID
, PDSDRIVERDESC desc
)
3277 TRACE("(%d,%p)\n",wDevID
,desc
);
3278 memcpy(desc
, &(WOutDev
[wDevID
].ossdev
->ds_desc
), sizeof(DSDRIVERDESC
));
3279 return MMSYSERR_NOERROR
;
3282 /*======================================================================*
3283 * Low level WAVE IN implementation *
3284 *======================================================================*/
3286 /**************************************************************************
3287 * widNotifyClient [internal]
3289 static DWORD
widNotifyClient(WINE_WAVEIN
* wwi
, WORD wMsg
, DWORD dwParam1
, DWORD dwParam2
)
3291 TRACE("wMsg = 0x%04x (%s) dwParm1 = %04lX dwParam2 = %04lX\n", wMsg
,
3292 wMsg
== WIM_OPEN
? "WIM_OPEN" : wMsg
== WIM_CLOSE
? "WIM_CLOSE" :
3293 wMsg
== WIM_DATA
? "WIM_DATA" : "Unknown", dwParam1
, dwParam2
);
3299 if (wwi
->wFlags
!= DCB_NULL
&&
3300 !DriverCallback(wwi
->waveDesc
.dwCallback
, wwi
->wFlags
,
3301 (HDRVR
)wwi
->waveDesc
.hWave
, wMsg
,
3302 wwi
->waveDesc
.dwInstance
, dwParam1
, dwParam2
)) {
3303 WARN("can't notify client !\n");
3304 return MMSYSERR_ERROR
;
3308 FIXME("Unknown callback message %u\n", wMsg
);
3309 return MMSYSERR_INVALPARAM
;
3311 return MMSYSERR_NOERROR
;
3314 /**************************************************************************
3315 * widGetDevCaps [internal]
3317 static DWORD
widGetDevCaps(WORD wDevID
, LPWAVEINCAPSA lpCaps
, DWORD dwSize
)
3319 TRACE("(%u, %p, %lu);\n", wDevID
, lpCaps
, dwSize
);
3321 if (lpCaps
== NULL
) return MMSYSERR_NOTENABLED
;
3323 if (wDevID
>= numInDev
) {
3324 TRACE("numOutDev reached !\n");
3325 return MMSYSERR_BADDEVICEID
;
3328 memcpy(lpCaps
, &WInDev
[wDevID
].ossdev
->in_caps
, min(dwSize
, sizeof(*lpCaps
)));
3329 return MMSYSERR_NOERROR
;
3332 /**************************************************************************
3333 * widRecorder_ReadHeaders [internal]
3335 static void widRecorder_ReadHeaders(WINE_WAVEIN
* wwi
)
3337 enum win_wm_message tmp_msg
;
3342 while (OSS_RetrieveRingMessage(&wwi
->msgRing
, &tmp_msg
, &tmp_param
, &tmp_ev
)) {
3343 if (tmp_msg
== WINE_WM_HEADER
) {
3345 lpWaveHdr
= (LPWAVEHDR
)tmp_param
;
3346 lpWaveHdr
->lpNext
= 0;
3348 if (wwi
->lpQueuePtr
== 0)
3349 wwi
->lpQueuePtr
= lpWaveHdr
;
3351 for (wh
= &(wwi
->lpQueuePtr
); *wh
; wh
= &((*wh
)->lpNext
));
3355 ERR("should only have headers left\n");
3360 /**************************************************************************
3361 * widRecorder [internal]
3363 static DWORD CALLBACK
widRecorder(LPVOID pmt
)
3365 WORD uDevID
= (DWORD
)pmt
;
3366 WINE_WAVEIN
* wwi
= (WINE_WAVEIN
*)&WInDev
[uDevID
];
3370 LPVOID buffer
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, wwi
->dwFragmentSize
);
3371 char *pOffset
= buffer
;
3372 audio_buf_info info
;
3374 enum win_wm_message msg
;
3379 wwi
->state
= WINE_WS_STOPPED
;
3380 wwi
->dwTotalRecorded
= 0;
3381 wwi
->dwTotalRead
= 0;
3382 wwi
->lpQueuePtr
= NULL
;
3384 SetEvent(wwi
->hStartUpEvent
);
3386 /* disable input so capture will begin when triggered */
3387 wwi
->ossdev
->bInputEnabled
= FALSE
;
3388 enable
= getEnables(wwi
->ossdev
);
3389 if (ioctl(wwi
->ossdev
->fd
, SNDCTL_DSP_SETTRIGGER
, &enable
) < 0)
3390 ERR("ioctl(%s, SNDCTL_DSP_SETTRIGGER) failed (%s)\n", wwi
->ossdev
->dev_name
, strerror(errno
));
3392 /* the soundblaster live needs a micro wake to get its recording started
3393 * (or GETISPACE will have 0 frags all the time)
3395 read(wwi
->ossdev
->fd
, &xs
, 4);
3397 /* make sleep time to be # of ms to output a fragment */
3398 dwSleepTime
= (wwi
->dwFragmentSize
* 1000) / wwi
->waveFormat
.Format
.nAvgBytesPerSec
;
3399 TRACE("sleeptime=%ld ms\n", dwSleepTime
);
3402 /* wait for dwSleepTime or an event in thread's queue */
3403 /* FIXME: could improve wait time depending on queue state,
3404 * ie, number of queued fragments
3407 if (wwi
->lpQueuePtr
!= NULL
&& wwi
->state
== WINE_WS_PLAYING
)
3409 lpWaveHdr
= wwi
->lpQueuePtr
;
3411 ioctl(wwi
->ossdev
->fd
, SNDCTL_DSP_GETISPACE
, &info
);
3412 TRACE("info={frag=%d fsize=%d ftotal=%d bytes=%d}\n", info
.fragments
, info
.fragsize
, info
.fragstotal
, info
.bytes
);
3414 /* read all the fragments accumulated so far */
3415 while ((info
.fragments
> 0) && (wwi
->lpQueuePtr
))
3419 if (lpWaveHdr
->dwBufferLength
- lpWaveHdr
->dwBytesRecorded
>= wwi
->dwFragmentSize
)
3421 /* directly read fragment in wavehdr */
3422 bytesRead
= read(wwi
->ossdev
->fd
,
3423 lpWaveHdr
->lpData
+ lpWaveHdr
->dwBytesRecorded
,
3424 wwi
->dwFragmentSize
);
3426 TRACE("bytesRead=%ld (direct)\n", bytesRead
);
3427 if (bytesRead
!= (DWORD
) -1)
3429 /* update number of bytes recorded in current buffer and by this device */
3430 lpWaveHdr
->dwBytesRecorded
+= bytesRead
;
3431 wwi
->dwTotalRead
+= bytesRead
;
3432 wwi
->dwTotalRecorded
= wwi
->dwTotalRead
;
3434 /* buffer is full. notify client */
3435 if (lpWaveHdr
->dwBytesRecorded
== lpWaveHdr
->dwBufferLength
)
3437 /* must copy the value of next waveHdr, because we have no idea of what
3438 * will be done with the content of lpWaveHdr in callback
3440 LPWAVEHDR lpNext
= lpWaveHdr
->lpNext
;
3442 lpWaveHdr
->dwFlags
&= ~WHDR_INQUEUE
;
3443 lpWaveHdr
->dwFlags
|= WHDR_DONE
;
3445 wwi
->lpQueuePtr
= lpNext
;
3446 widNotifyClient(wwi
, WIM_DATA
, (DWORD
)lpWaveHdr
, 0);
3450 TRACE("read(%s, %p, %ld) failed (%s)\n", wwi
->ossdev
->dev_name
,
3451 lpWaveHdr
->lpData
+ lpWaveHdr
->dwBytesRecorded
,
3452 wwi
->dwFragmentSize
, strerror(errno
));
3457 /* read the fragment in a local buffer */
3458 bytesRead
= read(wwi
->ossdev
->fd
, buffer
, wwi
->dwFragmentSize
);
3461 TRACE("bytesRead=%ld (local)\n", bytesRead
);
3463 if (bytesRead
== (DWORD
) -1) {
3464 TRACE("read(%s, %p, %ld) failed (%s)\n", wwi
->ossdev
->dev_name
,
3465 buffer
, wwi
->dwFragmentSize
, strerror(errno
));
3469 /* copy data in client buffers */
3470 while (bytesRead
!= (DWORD
) -1 && bytesRead
> 0)
3472 DWORD dwToCopy
= min (bytesRead
, lpWaveHdr
->dwBufferLength
- lpWaveHdr
->dwBytesRecorded
);
3474 memcpy(lpWaveHdr
->lpData
+ lpWaveHdr
->dwBytesRecorded
,
3478 /* update number of bytes recorded in current buffer and by this device */
3479 lpWaveHdr
->dwBytesRecorded
+= dwToCopy
;
3480 wwi
->dwTotalRead
+= dwToCopy
;
3481 wwi
->dwTotalRecorded
= wwi
->dwTotalRead
;
3482 bytesRead
-= dwToCopy
;
3483 pOffset
+= dwToCopy
;
3485 /* client buffer is full. notify client */
3486 if (lpWaveHdr
->dwBytesRecorded
== lpWaveHdr
->dwBufferLength
)
3488 /* must copy the value of next waveHdr, because we have no idea of what
3489 * will be done with the content of lpWaveHdr in callback
3491 LPWAVEHDR lpNext
= lpWaveHdr
->lpNext
;
3492 TRACE("lpNext=%p\n", lpNext
);
3494 lpWaveHdr
->dwFlags
&= ~WHDR_INQUEUE
;
3495 lpWaveHdr
->dwFlags
|= WHDR_DONE
;
3497 wwi
->lpQueuePtr
= lpNext
;
3498 widNotifyClient(wwi
, WIM_DATA
, (DWORD
)lpWaveHdr
, 0);
3501 if (!lpNext
&& bytesRead
) {
3502 /* before we give up, check for more header messages */
3503 while (OSS_PeekRingMessage(&wwi
->msgRing
, &msg
, ¶m
, &ev
))
3505 if (msg
== WINE_WM_HEADER
) {
3507 OSS_RetrieveRingMessage(&wwi
->msgRing
, &msg
, ¶m
, &ev
);
3508 hdr
= ((LPWAVEHDR
)param
);
3509 TRACE("msg = %s, hdr = %p, ev = %p\n", getCmdString(msg
), hdr
, ev
);
3511 if (lpWaveHdr
== 0) {
3512 /* new head of queue */
3513 wwi
->lpQueuePtr
= lpWaveHdr
= hdr
;
3515 /* insert buffer at the end of queue */
3517 for (wh
= &(wwi
->lpQueuePtr
); *wh
; wh
= &((*wh
)->lpNext
));
3524 if (lpWaveHdr
== 0) {
3525 /* no more buffer to copy data to, but we did read more.
3526 * what hasn't been copied will be dropped
3528 WARN("buffer under run! %lu bytes dropped.\n", bytesRead
);
3529 wwi
->lpQueuePtr
= NULL
;
3539 WAIT_OMR(&wwi
->msgRing
, dwSleepTime
);
3541 while (OSS_RetrieveRingMessage(&wwi
->msgRing
, &msg
, ¶m
, &ev
))
3543 TRACE("msg=%s param=0x%lx\n", getCmdString(msg
), param
);
3545 case WINE_WM_PAUSING
:
3546 wwi
->state
= WINE_WS_PAUSED
;
3547 /*FIXME("Device should stop recording\n");*/
3550 case WINE_WM_STARTING
:
3551 wwi
->state
= WINE_WS_PLAYING
;
3553 if (wwi
->ossdev
->bTriggerSupport
)
3555 /* start the recording */
3556 wwi
->ossdev
->bInputEnabled
= TRUE
;
3557 enable
= getEnables(wwi
->ossdev
);
3558 if (ioctl(wwi
->ossdev
->fd
, SNDCTL_DSP_SETTRIGGER
, &enable
) < 0) {
3559 wwi
->ossdev
->bInputEnabled
= FALSE
;
3560 ERR("ioctl(%s, SNDCTL_DSP_SETTRIGGER) failed (%s)\n", wwi
->ossdev
->dev_name
, strerror(errno
));
3565 unsigned char data
[4];
3566 /* read 4 bytes to start the recording */
3567 read(wwi
->ossdev
->fd
, data
, 4);
3572 case WINE_WM_HEADER
:
3573 lpWaveHdr
= (LPWAVEHDR
)param
;
3574 lpWaveHdr
->lpNext
= 0;
3576 /* insert buffer at the end of queue */
3579 for (wh
= &(wwi
->lpQueuePtr
); *wh
; wh
= &((*wh
)->lpNext
));
3583 case WINE_WM_STOPPING
:
3584 if (wwi
->state
!= WINE_WS_STOPPED
)
3586 if (wwi
->ossdev
->bTriggerSupport
)
3588 /* stop the recording */
3589 wwi
->ossdev
->bInputEnabled
= FALSE
;
3590 enable
= getEnables(wwi
->ossdev
);
3591 if (ioctl(wwi
->ossdev
->fd
, SNDCTL_DSP_SETTRIGGER
, &enable
) < 0) {
3592 wwi
->ossdev
->bInputEnabled
= FALSE
;
3593 ERR("ioctl(%s, SNDCTL_DSP_SETTRIGGER) failed (%s)\n", wwi
->ossdev
->dev_name
, strerror(errno
));
3597 /* read any headers in queue */
3598 widRecorder_ReadHeaders(wwi
);
3600 /* return current buffer to app */
3601 lpWaveHdr
= wwi
->lpQueuePtr
;
3604 LPWAVEHDR lpNext
= lpWaveHdr
->lpNext
;
3605 TRACE("stop %p %p\n", lpWaveHdr
, lpWaveHdr
->lpNext
);
3606 lpWaveHdr
->dwFlags
&= ~WHDR_INQUEUE
;
3607 lpWaveHdr
->dwFlags
|= WHDR_DONE
;
3608 wwi
->lpQueuePtr
= lpNext
;
3609 widNotifyClient(wwi
, WIM_DATA
, (DWORD
)lpWaveHdr
, 0);
3612 wwi
->state
= WINE_WS_STOPPED
;
3615 case WINE_WM_RESETTING
:
3616 if (wwi
->state
!= WINE_WS_STOPPED
)
3618 if (wwi
->ossdev
->bTriggerSupport
)
3620 /* stop the recording */
3621 wwi
->ossdev
->bInputEnabled
= FALSE
;
3622 enable
= getEnables(wwi
->ossdev
);
3623 if (ioctl(wwi
->ossdev
->fd
, SNDCTL_DSP_SETTRIGGER
, &enable
) < 0) {
3624 wwi
->ossdev
->bInputEnabled
= FALSE
;
3625 ERR("ioctl(%s, SNDCTL_DSP_SETTRIGGER) failed (%s)\n", wwi
->ossdev
->dev_name
, strerror(errno
));
3629 wwi
->state
= WINE_WS_STOPPED
;
3630 wwi
->dwTotalRecorded
= 0;
3631 wwi
->dwTotalRead
= 0;
3633 /* read any headers in queue */
3634 widRecorder_ReadHeaders(wwi
);
3636 /* return all buffers to the app */
3637 for (lpWaveHdr
= wwi
->lpQueuePtr
; lpWaveHdr
; lpWaveHdr
= lpWaveHdr
->lpNext
) {
3638 TRACE("reset %p %p\n", lpWaveHdr
, lpWaveHdr
->lpNext
);
3639 lpWaveHdr
->dwFlags
&= ~WHDR_INQUEUE
;
3640 lpWaveHdr
->dwFlags
|= WHDR_DONE
;
3641 wwi
->lpQueuePtr
= lpWaveHdr
->lpNext
;
3642 widNotifyClient(wwi
, WIM_DATA
, (DWORD
)lpWaveHdr
, 0);
3645 wwi
->lpQueuePtr
= NULL
;
3648 case WINE_WM_UPDATE
:
3649 if (wwi
->state
== WINE_WS_PLAYING
) {
3650 audio_buf_info tmp_info
;
3651 if (ioctl(wwi
->ossdev
->fd
, SNDCTL_DSP_GETISPACE
, &tmp_info
) < 0)
3652 ERR("ioctl(%s, SNDCTL_DSP_GETISPACE) failed (%s)\n", wwi
->ossdev
->dev_name
, strerror(errno
));
3654 wwi
->dwTotalRecorded
= wwi
->dwTotalRead
+ tmp_info
.bytes
;
3658 case WINE_WM_CLOSING
:
3660 wwi
->state
= WINE_WS_CLOSED
;
3662 HeapFree(GetProcessHeap(), 0, buffer
);
3664 /* shouldn't go here */
3666 FIXME("unknown message %d\n", msg
);
3672 /* just for not generating compilation warnings... should never be executed */
3677 /**************************************************************************
3678 * widOpen [internal]
3680 static DWORD
widOpen(WORD wDevID
, LPWAVEOPENDESC lpDesc
, DWORD dwFlags
)
3683 audio_buf_info info
;
3687 TRACE("(%u, %p, %08lX);\n", wDevID
, lpDesc
, dwFlags
);
3688 if (lpDesc
== NULL
) {
3689 WARN("Invalid Parameter !\n");
3690 return MMSYSERR_INVALPARAM
;
3692 if (wDevID
>= numInDev
) {
3693 WARN("bad device id: %d >= %d\n", wDevID
, numInDev
);
3694 return MMSYSERR_BADDEVICEID
;
3697 /* only PCM format is supported so far... */
3698 if (!supportedFormat(lpDesc
->lpFormat
)) {
3699 WARN("Bad format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
3700 lpDesc
->lpFormat
->wFormatTag
, lpDesc
->lpFormat
->nChannels
,
3701 lpDesc
->lpFormat
->nSamplesPerSec
);
3702 return WAVERR_BADFORMAT
;
3705 if (dwFlags
& WAVE_FORMAT_QUERY
) {
3706 TRACE("Query format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
3707 lpDesc
->lpFormat
->wFormatTag
, lpDesc
->lpFormat
->nChannels
,
3708 lpDesc
->lpFormat
->nSamplesPerSec
);
3709 return MMSYSERR_NOERROR
;
3712 TRACE("OSS_OpenDevice requested this format: %ldx%dx%d %s\n",
3713 lpDesc
->lpFormat
->nSamplesPerSec
,
3714 lpDesc
->lpFormat
->wBitsPerSample
,
3715 lpDesc
->lpFormat
->nChannels
,
3716 lpDesc
->lpFormat
->wFormatTag
== WAVE_FORMAT_PCM
? "WAVE_FORMAT_PCM" :
3717 lpDesc
->lpFormat
->wFormatTag
== WAVE_FORMAT_EXTENSIBLE
? "WAVE_FORMAT_EXTENSIBLE" :
3720 wwi
= &WInDev
[wDevID
];
3722 if (wwi
->state
!= WINE_WS_CLOSED
) return MMSYSERR_ALLOCATED
;
3724 if ((dwFlags
& WAVE_DIRECTSOUND
) &&
3725 !(wwi
->ossdev
->in_caps_support
& WAVECAPS_DIRECTSOUND
))
3726 /* not supported, ignore it */
3727 dwFlags
&= ~WAVE_DIRECTSOUND
;
3729 if (dwFlags
& WAVE_DIRECTSOUND
) {
3730 TRACE("has DirectSoundCapture driver\n");
3731 if (wwi
->ossdev
->in_caps_support
& WAVECAPS_SAMPLEACCURATE
)
3732 /* we have realtime DirectSound, fragments just waste our time,
3733 * but a large buffer is good, so choose 64KB (32 * 2^11) */
3734 audio_fragment
= 0x0020000B;
3736 /* to approximate realtime, we must use small fragments,
3737 * let's try to fragment the above 64KB (256 * 2^8) */
3738 audio_fragment
= 0x01000008;
3740 TRACE("doesn't have DirectSoundCapture driver\n");
3741 if (wwi
->ossdev
->open_count
> 0) {
3742 TRACE("Using output device audio_fragment\n");
3743 /* FIXME: This may not be optimal for capture but it allows us
3744 * to do hardware playback without hardware capture. */
3745 audio_fragment
= wwi
->ossdev
->audio_fragment
;
3747 /* A wave device must have a worst case latency of 10 ms so calculate
3748 * the largest fragment size less than 10 ms long.
3750 int fsize
= lpDesc
->lpFormat
->nAvgBytesPerSec
/ 100; /* 10 ms chunk */
3752 while ((1 << shift
) <= fsize
)
3755 audio_fragment
= 0x00100000 + shift
; /* 16 fragments of 2^shift */
3759 TRACE("requesting %d %d byte fragments (%ld ms)\n", audio_fragment
>> 16,
3760 1 << (audio_fragment
& 0xffff),
3761 ((1 << (audio_fragment
& 0xffff)) * 1000) / lpDesc
->lpFormat
->nAvgBytesPerSec
);
3763 ret
= OSS_OpenDevice(wwi
->ossdev
, O_RDONLY
, &audio_fragment
,
3765 lpDesc
->lpFormat
->nSamplesPerSec
,
3766 (lpDesc
->lpFormat
->nChannels
> 1) ? 1 : 0,
3767 (lpDesc
->lpFormat
->wBitsPerSample
== 16)
3768 ? AFMT_S16_LE
: AFMT_U8
);
3769 if (ret
!= 0) return ret
;
3770 wwi
->state
= WINE_WS_STOPPED
;
3772 if (wwi
->lpQueuePtr
) {
3773 WARN("Should have an empty queue (%p)\n", wwi
->lpQueuePtr
);
3774 wwi
->lpQueuePtr
= NULL
;
3776 wwi
->dwTotalRecorded
= 0;
3777 wwi
->dwTotalRead
= 0;
3778 wwi
->wFlags
= HIWORD(dwFlags
& CALLBACK_TYPEMASK
);
3780 memcpy(&wwi
->waveDesc
, lpDesc
, sizeof(WAVEOPENDESC
));
3781 copy_format(lpDesc
->lpFormat
, &wwi
->waveFormat
);
3783 if (wwi
->waveFormat
.Format
.wBitsPerSample
== 0) {
3784 WARN("Resetting zeroed wBitsPerSample\n");
3785 wwi
->waveFormat
.Format
.wBitsPerSample
= 8 *
3786 (wwi
->waveFormat
.Format
.nAvgBytesPerSec
/
3787 wwi
->waveFormat
.Format
.nSamplesPerSec
) /
3788 wwi
->waveFormat
.Format
.nChannels
;
3791 if (ioctl(wwi
->ossdev
->fd
, SNDCTL_DSP_GETISPACE
, &info
) < 0) {
3792 ERR("ioctl(%s, SNDCTL_DSP_GETISPACE) failed (%s)\n",
3793 wwi
->ossdev
->dev_name
, strerror(errno
));
3794 OSS_CloseDevice(wwi
->ossdev
);
3795 wwi
->state
= WINE_WS_CLOSED
;
3796 return MMSYSERR_NOTENABLED
;
3799 TRACE("got %d %d byte fragments (%d ms/fragment)\n", info
.fragstotal
,
3800 info
.fragsize
, (info
.fragsize
* 1000) / (wwi
->ossdev
->sample_rate
*
3801 (wwi
->ossdev
->stereo
? 2 : 1) *
3802 (wwi
->ossdev
->format
== AFMT_U8
? 1 : 2)));
3804 wwi
->dwFragmentSize
= info
.fragsize
;
3806 TRACE("dwFragmentSize=%lu\n", wwi
->dwFragmentSize
);
3807 TRACE("wBitsPerSample=%u, nAvgBytesPerSec=%lu, nSamplesPerSec=%lu, nChannels=%u nBlockAlign=%u!\n",
3808 wwi
->waveFormat
.Format
.wBitsPerSample
, wwi
->waveFormat
.Format
.nAvgBytesPerSec
,
3809 wwi
->waveFormat
.Format
.nSamplesPerSec
, wwi
->waveFormat
.Format
.nChannels
,
3810 wwi
->waveFormat
.Format
.nBlockAlign
);
3812 OSS_InitRingMessage(&wwi
->msgRing
);
3814 wwi
->hStartUpEvent
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
3815 wwi
->hThread
= CreateThread(NULL
, 0, widRecorder
, (LPVOID
)(DWORD
)wDevID
, 0, &(wwi
->dwThreadID
));
3816 WaitForSingleObject(wwi
->hStartUpEvent
, INFINITE
);
3817 CloseHandle(wwi
->hStartUpEvent
);
3818 wwi
->hStartUpEvent
= INVALID_HANDLE_VALUE
;
3820 return widNotifyClient(wwi
, WIM_OPEN
, 0L, 0L);
3823 /**************************************************************************
3824 * widClose [internal]
3826 static DWORD
widClose(WORD wDevID
)
3830 TRACE("(%u);\n", wDevID
);
3831 if (wDevID
>= numInDev
|| WInDev
[wDevID
].state
== WINE_WS_CLOSED
) {
3832 WARN("can't close !\n");
3833 return MMSYSERR_INVALHANDLE
;
3836 wwi
= &WInDev
[wDevID
];
3838 if (wwi
->lpQueuePtr
!= NULL
) {
3839 WARN("still buffers open !\n");
3840 return WAVERR_STILLPLAYING
;
3843 OSS_AddRingMessage(&wwi
->msgRing
, WINE_WM_CLOSING
, 0, TRUE
);
3844 OSS_CloseDevice(wwi
->ossdev
);
3845 wwi
->state
= WINE_WS_CLOSED
;
3846 wwi
->dwFragmentSize
= 0;
3847 OSS_DestroyRingMessage(&wwi
->msgRing
);
3848 return widNotifyClient(wwi
, WIM_CLOSE
, 0L, 0L);
3851 /**************************************************************************
3852 * widAddBuffer [internal]
3854 static DWORD
widAddBuffer(WORD wDevID
, LPWAVEHDR lpWaveHdr
, DWORD dwSize
)
3856 TRACE("(%u, %p, %08lX);\n", wDevID
, lpWaveHdr
, dwSize
);
3858 if (wDevID
>= numInDev
|| WInDev
[wDevID
].state
== WINE_WS_CLOSED
) {
3859 WARN("can't do it !\n");
3860 return MMSYSERR_INVALHANDLE
;
3862 if (!(lpWaveHdr
->dwFlags
& WHDR_PREPARED
)) {
3863 TRACE("never been prepared !\n");
3864 return WAVERR_UNPREPARED
;
3866 if (lpWaveHdr
->dwFlags
& WHDR_INQUEUE
) {
3867 TRACE("header already in use !\n");
3868 return WAVERR_STILLPLAYING
;
3871 lpWaveHdr
->dwFlags
|= WHDR_INQUEUE
;
3872 lpWaveHdr
->dwFlags
&= ~WHDR_DONE
;
3873 lpWaveHdr
->dwBytesRecorded
= 0;
3874 lpWaveHdr
->lpNext
= NULL
;
3876 OSS_AddRingMessage(&WInDev
[wDevID
].msgRing
, WINE_WM_HEADER
, (DWORD
)lpWaveHdr
, FALSE
);
3877 return MMSYSERR_NOERROR
;
3880 /**************************************************************************
3881 * widPrepare [internal]
3883 static DWORD
widPrepare(WORD wDevID
, LPWAVEHDR lpWaveHdr
, DWORD dwSize
)
3885 TRACE("(%u, %p, %08lX);\n", wDevID
, lpWaveHdr
, dwSize
);
3887 if (wDevID
>= numInDev
) return MMSYSERR_INVALHANDLE
;
3889 if (lpWaveHdr
->dwFlags
& WHDR_INQUEUE
)
3890 return WAVERR_STILLPLAYING
;
3892 lpWaveHdr
->dwFlags
|= WHDR_PREPARED
;
3893 lpWaveHdr
->dwFlags
&= ~WHDR_DONE
;
3894 lpWaveHdr
->dwBytesRecorded
= 0;
3895 TRACE("header prepared !\n");
3896 return MMSYSERR_NOERROR
;
3899 /**************************************************************************
3900 * widUnprepare [internal]
3902 static DWORD
widUnprepare(WORD wDevID
, LPWAVEHDR lpWaveHdr
, DWORD dwSize
)
3904 TRACE("(%u, %p, %08lX);\n", wDevID
, lpWaveHdr
, dwSize
);
3905 if (wDevID
>= numInDev
) return MMSYSERR_INVALHANDLE
;
3907 if (lpWaveHdr
->dwFlags
& WHDR_INQUEUE
)
3908 return WAVERR_STILLPLAYING
;
3910 lpWaveHdr
->dwFlags
&= ~WHDR_PREPARED
;
3911 lpWaveHdr
->dwFlags
|= WHDR_DONE
;
3913 return MMSYSERR_NOERROR
;
3916 /**************************************************************************
3917 * widStart [internal]
3919 static DWORD
widStart(WORD wDevID
)
3921 TRACE("(%u);\n", wDevID
);
3922 if (wDevID
>= numInDev
|| WInDev
[wDevID
].state
== WINE_WS_CLOSED
) {
3923 WARN("can't start recording !\n");
3924 return MMSYSERR_INVALHANDLE
;
3927 OSS_AddRingMessage(&WInDev
[wDevID
].msgRing
, WINE_WM_STARTING
, 0, TRUE
);
3928 return MMSYSERR_NOERROR
;
3931 /**************************************************************************
3932 * widStop [internal]
3934 static DWORD
widStop(WORD wDevID
)
3936 TRACE("(%u);\n", wDevID
);
3937 if (wDevID
>= numInDev
|| WInDev
[wDevID
].state
== WINE_WS_CLOSED
) {
3938 WARN("can't stop !\n");
3939 return MMSYSERR_INVALHANDLE
;
3942 OSS_AddRingMessage(&WInDev
[wDevID
].msgRing
, WINE_WM_STOPPING
, 0, TRUE
);
3944 return MMSYSERR_NOERROR
;
3947 /**************************************************************************
3948 * widReset [internal]
3950 static DWORD
widReset(WORD wDevID
)
3952 TRACE("(%u);\n", wDevID
);
3953 if (wDevID
>= numInDev
|| WInDev
[wDevID
].state
== WINE_WS_CLOSED
) {
3954 WARN("can't reset !\n");
3955 return MMSYSERR_INVALHANDLE
;
3957 OSS_AddRingMessage(&WInDev
[wDevID
].msgRing
, WINE_WM_RESETTING
, 0, TRUE
);
3958 return MMSYSERR_NOERROR
;
3961 /**************************************************************************
3962 * widGetPosition [internal]
3964 static DWORD
widGetPosition(WORD wDevID
, LPMMTIME lpTime
, DWORD uSize
)
3968 TRACE("(%u, %p, %lu);\n", wDevID
, lpTime
, uSize
);
3970 if (wDevID
>= numInDev
|| WInDev
[wDevID
].state
== WINE_WS_CLOSED
) {
3971 WARN("can't get pos !\n");
3972 return MMSYSERR_INVALHANDLE
;
3975 if (lpTime
== NULL
) {
3976 WARN("invalid parameter: lpTime == NULL\n");
3977 return MMSYSERR_INVALPARAM
;
3980 wwi
= &WInDev
[wDevID
];
3981 #ifdef EXACT_WIDPOSITION
3982 if (wwi
->ossdev
->in_caps_support
& WAVECAPS_SAMPLEACCURATE
)
3983 OSS_AddRingMessage(&(wwi
->msgRing
), WINE_WM_UPDATE
, 0, TRUE
);
3986 return bytes_to_mmtime(lpTime
, wwi
->dwTotalRecorded
, &wwi
->waveFormat
);
3989 /**************************************************************************
3990 * widMessage (WINEOSS.6)
3992 DWORD WINAPI
OSS_widMessage(WORD wDevID
, WORD wMsg
, DWORD dwUser
,
3993 DWORD dwParam1
, DWORD dwParam2
)
3995 TRACE("(%u, %s, %08lX, %08lX, %08lX);\n",
3996 wDevID
, getMessage(wMsg
), dwUser
, dwParam1
, dwParam2
);
4003 /* FIXME: Pretend this is supported */
4005 case WIDM_OPEN
: return widOpen (wDevID
, (LPWAVEOPENDESC
)dwParam1
, dwParam2
);
4006 case WIDM_CLOSE
: return widClose (wDevID
);
4007 case WIDM_ADDBUFFER
: return widAddBuffer (wDevID
, (LPWAVEHDR
)dwParam1
, dwParam2
);
4008 case WIDM_PREPARE
: return widPrepare (wDevID
, (LPWAVEHDR
)dwParam1
, dwParam2
);
4009 case WIDM_UNPREPARE
: return widUnprepare (wDevID
, (LPWAVEHDR
)dwParam1
, dwParam2
);
4010 case WIDM_GETDEVCAPS
: return widGetDevCaps (wDevID
, (LPWAVEINCAPSA
)dwParam1
, dwParam2
);
4011 case WIDM_GETNUMDEVS
: return numInDev
;
4012 case WIDM_GETPOS
: return widGetPosition(wDevID
, (LPMMTIME
)dwParam1
, dwParam2
);
4013 case WIDM_RESET
: return widReset (wDevID
);
4014 case WIDM_START
: return widStart (wDevID
);
4015 case WIDM_STOP
: return widStop (wDevID
);
4016 case DRV_QUERYDEVICEINTERFACESIZE
: return wdDevInterfaceSize (wDevID
, (LPDWORD
)dwParam1
);
4017 case DRV_QUERYDEVICEINTERFACE
: return wdDevInterface (wDevID
, (PWCHAR
)dwParam1
, dwParam2
);
4018 case DRV_QUERYDSOUNDIFACE
: return widDsCreate (wDevID
, (PIDSCDRIVER
*)dwParam1
);
4019 case DRV_QUERYDSOUNDDESC
: return widDsDesc (wDevID
, (PDSDRIVERDESC
)dwParam1
);
4021 FIXME("unknown message %u!\n", wMsg
);
4023 return MMSYSERR_NOTSUPPORTED
;
4026 /*======================================================================*
4027 * Low level DSOUND capture definitions *
4028 *======================================================================*/
4030 typedef struct IDsCaptureDriverPropertySetImpl IDsCaptureDriverPropertySetImpl
;
4031 typedef struct IDsCaptureDriverNotifyImpl IDsCaptureDriverNotifyImpl
;
4032 typedef struct IDsCaptureDriverImpl IDsCaptureDriverImpl
;
4033 typedef struct IDsCaptureDriverBufferImpl IDsCaptureDriverBufferImpl
;
4035 struct IDsCaptureDriverPropertySetImpl
4037 /* IUnknown fields */
4038 IDsDriverPropertySetVtbl
*lpVtbl
;
4041 IDsCaptureDriverBufferImpl
* capture_buffer
;
4044 struct IDsCaptureDriverNotifyImpl
4046 /* IUnknown fields */
4047 IDsDriverNotifyVtbl
*lpVtbl
;
4050 IDsCaptureDriverBufferImpl
* capture_buffer
;
4053 struct IDsCaptureDriverImpl
4055 /* IUnknown fields */
4056 IDsCaptureDriverVtbl
*lpVtbl
;
4059 /* IDsCaptureDriverImpl fields */
4061 IDsCaptureDriverBufferImpl
* capture_buffer
;
4064 struct IDsCaptureDriverBufferImpl
4066 /* IUnknown fields */
4067 IDsCaptureDriverBufferVtbl
*lpVtbl
;
4070 /* IDsCaptureDriverBufferImpl fields */
4071 IDsCaptureDriverImpl
* drv
;
4078 /* IDsDriverNotifyImpl fields */
4079 IDsCaptureDriverNotifyImpl
* notify
;
4081 LPDSBPOSITIONNOTIFY notifies
;
4084 /* IDsDriverPropertySetImpl fields */
4085 IDsCaptureDriverPropertySetImpl
* property_set
;
4091 static HRESULT WINAPI
IDsCaptureDriverPropertySetImpl_Create(
4092 IDsCaptureDriverBufferImpl
* dscdb
,
4093 IDsCaptureDriverPropertySetImpl
**pdscdps
);
4095 static HRESULT WINAPI
IDsCaptureDriverNotifyImpl_Create(
4096 IDsCaptureDriverBufferImpl
* dsdcb
,
4097 IDsCaptureDriverNotifyImpl
**pdscdn
);
4099 /*======================================================================*
4100 * Low level DSOUND capture property set implementation *
4101 *======================================================================*/
4103 static HRESULT WINAPI
IDsCaptureDriverPropertySetImpl_QueryInterface(
4104 PIDSDRIVERPROPERTYSET iface
,
4108 ICOM_THIS(IDsCaptureDriverPropertySetImpl
,iface
);
4109 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppobj
);
4111 if ( IsEqualGUID(riid
, &IID_IUnknown
) ||
4112 IsEqualGUID(riid
, &IID_IDsDriverPropertySet
) ) {
4113 IDsDriverPropertySet_AddRef(iface
);
4114 *ppobj
= (LPVOID
)This
;
4118 FIXME( "Unknown IID %s\n", debugstr_guid( riid
) );
4121 return E_NOINTERFACE
;
4124 static ULONG WINAPI
IDsCaptureDriverPropertySetImpl_AddRef(
4125 PIDSDRIVERPROPERTYSET iface
)
4127 ICOM_THIS(IDsCaptureDriverPropertySetImpl
,iface
);
4128 TRACE("(%p) ref was %ld\n", This
, This
->ref
);
4130 return InterlockedIncrement(&(This
->ref
));
4133 static ULONG WINAPI
IDsCaptureDriverPropertySetImpl_Release(
4134 PIDSDRIVERPROPERTYSET iface
)
4136 ICOM_THIS(IDsCaptureDriverPropertySetImpl
,iface
);
4138 TRACE("(%p) ref was %ld\n", This
, This
->ref
);
4140 ref
= InterlockedDecrement(&(This
->ref
));
4142 IDsCaptureDriverBuffer_Release((PIDSCDRIVERBUFFER
)This
->capture_buffer
);
4143 This
->capture_buffer
->property_set
= NULL
;
4144 HeapFree(GetProcessHeap(),0,This
);
4145 TRACE("(%p) released\n",This
);
4150 static HRESULT WINAPI
IDsCaptureDriverPropertySetImpl_Get(
4151 PIDSDRIVERPROPERTYSET iface
,
4152 PDSPROPERTY pDsProperty
,
4153 LPVOID pPropertyParams
,
4154 ULONG cbPropertyParams
,
4155 LPVOID pPropertyData
,
4156 ULONG cbPropertyData
,
4157 PULONG pcbReturnedData
)
4159 ICOM_THIS(IDsCaptureDriverPropertySetImpl
,iface
);
4160 FIXME("(%p,%p,%p,%lx,%p,%lx,%p)\n",This
,pDsProperty
,pPropertyParams
,
4161 cbPropertyParams
,pPropertyData
,cbPropertyData
,pcbReturnedData
);
4162 return DSERR_UNSUPPORTED
;
4165 static HRESULT WINAPI
IDsCaptureDriverPropertySetImpl_Set(
4166 PIDSDRIVERPROPERTYSET iface
,
4167 PDSPROPERTY pDsProperty
,
4168 LPVOID pPropertyParams
,
4169 ULONG cbPropertyParams
,
4170 LPVOID pPropertyData
,
4171 ULONG cbPropertyData
)
4173 ICOM_THIS(IDsCaptureDriverPropertySetImpl
,iface
);
4174 FIXME("(%p,%p,%p,%lx,%p,%lx)\n",This
,pDsProperty
,pPropertyParams
,
4175 cbPropertyParams
,pPropertyData
,cbPropertyData
);
4176 return DSERR_UNSUPPORTED
;
4179 static HRESULT WINAPI
IDsCaptureDriverPropertySetImpl_QuerySupport(
4180 PIDSDRIVERPROPERTYSET iface
,
4181 REFGUID PropertySetId
,
4185 ICOM_THIS(IDsCaptureDriverPropertySetImpl
,iface
);
4186 FIXME("(%p,%s,%lx,%p)\n",This
,debugstr_guid(PropertySetId
),PropertyId
,
4188 return DSERR_UNSUPPORTED
;
4191 IDsDriverPropertySetVtbl dscdpsvt
=
4193 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
4194 IDsCaptureDriverPropertySetImpl_QueryInterface
,
4195 IDsCaptureDriverPropertySetImpl_AddRef
,
4196 IDsCaptureDriverPropertySetImpl_Release
,
4197 IDsCaptureDriverPropertySetImpl_Get
,
4198 IDsCaptureDriverPropertySetImpl_Set
,
4199 IDsCaptureDriverPropertySetImpl_QuerySupport
,
4202 /*======================================================================*
4203 * Low level DSOUND capture notify implementation *
4204 *======================================================================*/
4206 static HRESULT WINAPI
IDsCaptureDriverNotifyImpl_QueryInterface(
4207 PIDSDRIVERNOTIFY iface
,
4211 ICOM_THIS(IDsCaptureDriverNotifyImpl
,iface
);
4212 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppobj
);
4214 if ( IsEqualGUID(riid
, &IID_IUnknown
) ||
4215 IsEqualGUID(riid
, &IID_IDsDriverNotify
) ) {
4216 IDsDriverNotify_AddRef(iface
);
4221 FIXME( "Unknown IID %s\n", debugstr_guid( riid
) );
4224 return E_NOINTERFACE
;
4227 static ULONG WINAPI
IDsCaptureDriverNotifyImpl_AddRef(
4228 PIDSDRIVERNOTIFY iface
)
4230 ICOM_THIS(IDsCaptureDriverNotifyImpl
,iface
);
4231 TRACE("(%p) ref was %ld\n", This
, This
->ref
);
4233 return InterlockedIncrement(&(This
->ref
));
4236 static ULONG WINAPI
IDsCaptureDriverNotifyImpl_Release(
4237 PIDSDRIVERNOTIFY iface
)
4239 ICOM_THIS(IDsCaptureDriverNotifyImpl
,iface
);
4241 TRACE("(%p) ref was %ld\n", This
, This
->ref
);
4243 ref
= InterlockedDecrement(&(This
->ref
));
4245 IDsCaptureDriverBuffer_Release((PIDSCDRIVERBUFFER
)This
->capture_buffer
);
4246 This
->capture_buffer
->notify
= NULL
;
4247 HeapFree(GetProcessHeap(),0,This
);
4248 TRACE("(%p) released\n",This
);
4253 static HRESULT WINAPI
IDsCaptureDriverNotifyImpl_SetNotificationPositions(
4254 PIDSDRIVERNOTIFY iface
,
4256 LPCDSBPOSITIONNOTIFY notify
)
4258 ICOM_THIS(IDsCaptureDriverNotifyImpl
,iface
);
4259 TRACE("(%p,0x%08lx,%p)\n",This
,howmuch
,notify
);
4262 WARN("invalid parameter\n");
4263 return DSERR_INVALIDPARAM
;
4266 if (TRACE_ON(wave
)) {
4268 for (i
=0;i
<howmuch
;i
++)
4269 TRACE("notify at %ld to 0x%08lx\n",
4270 notify
[i
].dwOffset
,(DWORD
)notify
[i
].hEventNotify
);
4273 /* Make an internal copy of the caller-supplied array.
4274 * Replace the existing copy if one is already present. */
4275 if (This
->capture_buffer
->notifies
)
4276 This
->capture_buffer
->notifies
= HeapReAlloc(GetProcessHeap(),
4277 HEAP_ZERO_MEMORY
, This
->capture_buffer
->notifies
,
4278 howmuch
* sizeof(DSBPOSITIONNOTIFY
));
4280 This
->capture_buffer
->notifies
= HeapAlloc(GetProcessHeap(),
4281 HEAP_ZERO_MEMORY
, howmuch
* sizeof(DSBPOSITIONNOTIFY
));
4283 memcpy(This
->capture_buffer
->notifies
, notify
,
4284 howmuch
* sizeof(DSBPOSITIONNOTIFY
));
4285 This
->capture_buffer
->nrofnotifies
= howmuch
;
4290 IDsDriverNotifyVtbl dscdnvt
=
4292 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
4293 IDsCaptureDriverNotifyImpl_QueryInterface
,
4294 IDsCaptureDriverNotifyImpl_AddRef
,
4295 IDsCaptureDriverNotifyImpl_Release
,
4296 IDsCaptureDriverNotifyImpl_SetNotificationPositions
,
4299 /*======================================================================*
4300 * Low level DSOUND capture implementation *
4301 *======================================================================*/
4303 static HRESULT
DSCDB_MapBuffer(IDsCaptureDriverBufferImpl
*dscdb
)
4305 if (!dscdb
->mapping
) {
4306 dscdb
->mapping
= mmap(NULL
, dscdb
->maplen
, PROT_READ
, MAP_SHARED
,
4307 WInDev
[dscdb
->drv
->wDevID
].ossdev
->fd
, 0);
4308 if (dscdb
->mapping
== (LPBYTE
)-1) {
4309 TRACE("(%p): Could not map sound device for direct access (%s)\n",
4310 dscdb
, strerror(errno
));
4311 return DSERR_GENERIC
;
4313 TRACE("(%p): sound device has been mapped for direct access at %p, size=%ld\n", dscdb
, dscdb
->mapping
, dscdb
->maplen
);
4318 static HRESULT
DSCDB_UnmapBuffer(IDsCaptureDriverBufferImpl
*dscdb
)
4320 if (dscdb
->mapping
) {
4321 if (munmap(dscdb
->mapping
, dscdb
->maplen
) < 0) {
4322 ERR("(%p): Could not unmap sound device (%s)\n",
4323 dscdb
, strerror(errno
));
4324 return DSERR_GENERIC
;
4326 dscdb
->mapping
= NULL
;
4327 TRACE("(%p): sound device unmapped\n", dscdb
);
4332 static HRESULT WINAPI
IDsCaptureDriverBufferImpl_QueryInterface(
4333 PIDSCDRIVERBUFFER iface
,
4337 ICOM_THIS(IDsCaptureDriverBufferImpl
,iface
);
4338 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppobj
);
4342 if ( IsEqualGUID(riid
, &IID_IUnknown
) ||
4343 IsEqualGUID(riid
, &IID_IDsCaptureDriverBuffer
) ) {
4344 IDsCaptureDriverBuffer_AddRef(iface
);
4345 *ppobj
= (LPVOID
)This
;
4349 if ( IsEqualGUID( &IID_IDsDriverNotify
, riid
) ) {
4351 IDsCaptureDriverNotifyImpl_Create(This
, &(This
->notify
));
4353 IDsDriverNotify_AddRef((PIDSDRIVERNOTIFY
)This
->notify
);
4354 *ppobj
= (LPVOID
)This
->notify
;
4360 if ( IsEqualGUID( &IID_IDsDriverPropertySet
, riid
) ) {
4361 if (!This
->property_set
)
4362 IDsCaptureDriverPropertySetImpl_Create(This
, &(This
->property_set
));
4363 if (This
->property_set
) {
4364 IDsDriverPropertySet_AddRef((PIDSDRIVERPROPERTYSET
)This
->property_set
);
4365 *ppobj
= (LPVOID
)This
->property_set
;
4371 FIXME("(%p,%s,%p) unsupported GUID\n", This
, debugstr_guid(riid
), ppobj
);
4372 return DSERR_UNSUPPORTED
;
4375 static ULONG WINAPI
IDsCaptureDriverBufferImpl_AddRef(PIDSCDRIVERBUFFER iface
)
4377 ICOM_THIS(IDsCaptureDriverBufferImpl
,iface
);
4378 TRACE("(%p) ref was %ld\n", This
, This
->ref
);
4380 return InterlockedIncrement(&(This
->ref
));
4383 static ULONG WINAPI
IDsCaptureDriverBufferImpl_Release(PIDSCDRIVERBUFFER iface
)
4385 ICOM_THIS(IDsCaptureDriverBufferImpl
,iface
);
4387 TRACE("(%p) ref was %ld\n", This
, This
->ref
);
4389 ref
= InterlockedDecrement(&(This
->ref
));
4391 DSCDB_UnmapBuffer(This
);
4392 if (This
->notifies
!= NULL
)
4393 HeapFree(GetProcessHeap(), 0, This
->notifies
);
4394 HeapFree(GetProcessHeap(),0,This
);
4395 TRACE("(%p) released\n",This
);
4400 static HRESULT WINAPI
IDsCaptureDriverBufferImpl_Lock(
4401 PIDSCDRIVERBUFFER iface
,
4406 DWORD dwWritePosition
,
4410 ICOM_THIS(IDsCaptureDriverBufferImpl
,iface
);
4411 FIXME("(%p,%p,%p,%p,%p,%ld,%ld,0x%08lx): stub!\n",This
,ppvAudio1
,pdwLen1
,
4412 ppvAudio2
,pdwLen2
,dwWritePosition
,dwWriteLen
,dwFlags
);
4416 static HRESULT WINAPI
IDsCaptureDriverBufferImpl_Unlock(
4417 PIDSCDRIVERBUFFER iface
,
4423 ICOM_THIS(IDsCaptureDriverBufferImpl
,iface
);
4424 FIXME("(%p,%p,%ld,%p,%ld): stub!\n",This
,pvAudio1
,dwLen1
,pvAudio2
,dwLen2
);
4428 static HRESULT WINAPI
IDsCaptureDriverBufferImpl_GetPosition(
4429 PIDSCDRIVERBUFFER iface
,
4430 LPDWORD lpdwCapture
,
4433 ICOM_THIS(IDsCaptureDriverBufferImpl
,iface
);
4436 TRACE("(%p,%p,%p)\n",This
,lpdwCapture
,lpdwRead
);
4438 if (WInDev
[This
->drv
->wDevID
].state
== WINE_WS_CLOSED
) {
4439 ERR("device not open, but accessing?\n");
4440 return DSERR_UNINITIALIZED
;
4443 if (!This
->is_capturing
) {
4450 if (ioctl(WInDev
[This
->drv
->wDevID
].ossdev
->fd
, SNDCTL_DSP_GETIPTR
, &info
) < 0) {
4451 ERR("ioctl(%s, SNDCTL_DSP_GETIPTR) failed (%s)\n",
4452 WInDev
[This
->drv
->wDevID
].ossdev
->dev_name
, strerror(errno
));
4453 return DSERR_GENERIC
;
4455 ptr
= info
.ptr
& ~3; /* align the pointer, just in case */
4456 if (lpdwCapture
) *lpdwCapture
= ptr
;
4458 /* add some safety margin (not strictly necessary, but...) */
4459 if (WInDev
[This
->drv
->wDevID
].ossdev
->in_caps_support
& WAVECAPS_SAMPLEACCURATE
)
4460 *lpdwRead
= ptr
+ 32;
4462 *lpdwRead
= ptr
+ WInDev
[This
->drv
->wDevID
].dwFragmentSize
;
4463 while (*lpdwRead
> This
->buflen
)
4464 *lpdwRead
-= This
->buflen
;
4466 TRACE("capturepos=%ld, readpos=%ld\n", lpdwCapture
?*lpdwCapture
:0, lpdwRead
?*lpdwRead
:0);
4470 static HRESULT WINAPI
IDsCaptureDriverBufferImpl_GetStatus(
4471 PIDSCDRIVERBUFFER iface
,
4474 ICOM_THIS(IDsCaptureDriverBufferImpl
,iface
);
4475 TRACE("(%p,%p)\n",This
,lpdwStatus
);
4477 if (This
->is_capturing
) {
4478 if (This
->is_looping
)
4479 *lpdwStatus
= DSCBSTATUS_CAPTURING
| DSCBSTATUS_LOOPING
;
4481 *lpdwStatus
= DSCBSTATUS_CAPTURING
;
4488 static HRESULT WINAPI
IDsCaptureDriverBufferImpl_Start(
4489 PIDSCDRIVERBUFFER iface
,
4492 ICOM_THIS(IDsCaptureDriverBufferImpl
,iface
);
4494 TRACE("(%p,%lx)\n",This
,dwFlags
);
4496 if (This
->is_capturing
)
4499 if (dwFlags
& DSCBSTART_LOOPING
)
4500 This
->is_looping
= TRUE
;
4502 WInDev
[This
->drv
->wDevID
].ossdev
->bInputEnabled
= TRUE
;
4503 enable
= getEnables(WInDev
[This
->drv
->wDevID
].ossdev
);
4504 if (ioctl(WInDev
[This
->drv
->wDevID
].ossdev
->fd
, SNDCTL_DSP_SETTRIGGER
, &enable
) < 0) {
4505 if (errno
== EINVAL
) {
4506 /* Don't give up yet. OSS trigger support is inconsistent. */
4507 if (WInDev
[This
->drv
->wDevID
].ossdev
->open_count
== 1) {
4508 /* try the opposite output enable */
4509 if (WInDev
[This
->drv
->wDevID
].ossdev
->bOutputEnabled
== FALSE
)
4510 WInDev
[This
->drv
->wDevID
].ossdev
->bOutputEnabled
= TRUE
;
4512 WInDev
[This
->drv
->wDevID
].ossdev
->bOutputEnabled
= FALSE
;
4514 enable
= getEnables(WInDev
[This
->drv
->wDevID
].ossdev
);
4515 if (ioctl(WInDev
[This
->drv
->wDevID
].ossdev
->fd
, SNDCTL_DSP_SETTRIGGER
, &enable
) >= 0) {
4516 This
->is_capturing
= TRUE
;
4521 ERR("ioctl(%s, SNDCTL_DSP_SETTRIGGER) failed (%s)\n",
4522 WInDev
[This
->drv
->wDevID
].ossdev
->dev_name
, strerror(errno
));
4523 WInDev
[This
->drv
->wDevID
].ossdev
->bInputEnabled
= FALSE
;
4524 return DSERR_GENERIC
;
4527 This
->is_capturing
= TRUE
;
4531 static HRESULT WINAPI
IDsCaptureDriverBufferImpl_Stop(PIDSCDRIVERBUFFER iface
)
4533 ICOM_THIS(IDsCaptureDriverBufferImpl
,iface
);
4535 TRACE("(%p)\n",This
);
4537 if (!This
->is_capturing
)
4540 /* no more captureing */
4541 WInDev
[This
->drv
->wDevID
].ossdev
->bInputEnabled
= FALSE
;
4542 enable
= getEnables(WInDev
[This
->drv
->wDevID
].ossdev
);
4543 if (ioctl(WInDev
[This
->drv
->wDevID
].ossdev
->fd
, SNDCTL_DSP_SETTRIGGER
, &enable
) < 0) {
4544 ERR("ioctl(%s, SNDCTL_DSP_SETTRIGGER) failed (%s)\n",
4545 WInDev
[This
->drv
->wDevID
].ossdev
->dev_name
, strerror(errno
));
4546 return DSERR_GENERIC
;
4549 /* send a final event if necessary */
4550 if (This
->nrofnotifies
> 0) {
4551 if (This
->notifies
[This
->nrofnotifies
- 1].dwOffset
== DSBPN_OFFSETSTOP
)
4552 SetEvent(This
->notifies
[This
->nrofnotifies
- 1].hEventNotify
);
4555 This
->is_capturing
= FALSE
;
4556 This
->is_looping
= FALSE
;
4558 /* Most OSS drivers just can't stop capturing without closing the device...
4559 * so we need to somehow signal to our DirectSound implementation
4560 * that it should completely recreate this HW buffer...
4561 * this unexpected error code should do the trick... */
4562 return DSERR_BUFFERLOST
;
4565 static HRESULT WINAPI
IDsCaptureDriverBufferImpl_SetFormat(
4566 PIDSCDRIVERBUFFER iface
,
4567 LPWAVEFORMATEX pwfx
)
4569 ICOM_THIS(IDsCaptureDriverBufferImpl
,iface
);
4570 FIXME("(%p): stub!\n",This
);
4571 return DSERR_UNSUPPORTED
;
4574 static IDsCaptureDriverBufferVtbl dscdbvt
=
4576 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
4577 IDsCaptureDriverBufferImpl_QueryInterface
,
4578 IDsCaptureDriverBufferImpl_AddRef
,
4579 IDsCaptureDriverBufferImpl_Release
,
4580 IDsCaptureDriverBufferImpl_Lock
,
4581 IDsCaptureDriverBufferImpl_Unlock
,
4582 IDsCaptureDriverBufferImpl_SetFormat
,
4583 IDsCaptureDriverBufferImpl_GetPosition
,
4584 IDsCaptureDriverBufferImpl_GetStatus
,
4585 IDsCaptureDriverBufferImpl_Start
,
4586 IDsCaptureDriverBufferImpl_Stop
4589 static HRESULT WINAPI
IDsCaptureDriverImpl_QueryInterface(
4594 ICOM_THIS(IDsCaptureDriverImpl
,iface
);
4595 TRACE("(%p,%s,%p)\n",This
,debugstr_guid(riid
),ppobj
);
4597 if ( IsEqualGUID(riid
, &IID_IUnknown
) ||
4598 IsEqualGUID(riid
, &IID_IDsCaptureDriver
) ) {
4599 IDsCaptureDriver_AddRef(iface
);
4600 *ppobj
= (LPVOID
)This
;
4604 FIXME( "Unknown IID %s\n", debugstr_guid( riid
) );
4608 return E_NOINTERFACE
;
4611 static ULONG WINAPI
IDsCaptureDriverImpl_AddRef(PIDSCDRIVER iface
)
4613 ICOM_THIS(IDsCaptureDriverImpl
,iface
);
4614 TRACE("(%p) ref was %ld\n", This
, This
->ref
);
4616 return InterlockedIncrement(&(This
->ref
));
4619 static ULONG WINAPI
IDsCaptureDriverImpl_Release(PIDSCDRIVER iface
)
4621 ICOM_THIS(IDsCaptureDriverImpl
,iface
);
4623 TRACE("(%p) ref was %ld\n", This
, This
->ref
);
4625 ref
= InterlockedDecrement(&(This
->ref
));
4627 HeapFree(GetProcessHeap(),0,This
);
4628 TRACE("(%p) released\n",This
);
4633 static HRESULT WINAPI
IDsCaptureDriverImpl_GetDriverDesc(
4635 PDSDRIVERDESC pDesc
)
4637 ICOM_THIS(IDsCaptureDriverImpl
,iface
);
4638 TRACE("(%p,%p)\n",This
,pDesc
);
4641 TRACE("invalid parameter\n");
4642 return DSERR_INVALIDPARAM
;
4645 /* copy version from driver */
4646 memcpy(pDesc
, &(WInDev
[This
->wDevID
].ossdev
->ds_desc
), sizeof(DSDRIVERDESC
));
4648 pDesc
->dwFlags
|= DSDDESC_USESYSTEMMEMORY
;
4649 pDesc
->dnDevNode
= WInDev
[This
->wDevID
].waveDesc
.dnDevNode
;
4651 pDesc
->wReserved
= 0;
4652 pDesc
->ulDeviceNum
= This
->wDevID
;
4653 pDesc
->dwHeapType
= DSDHEAP_NOHEAP
;
4654 pDesc
->pvDirectDrawHeap
= NULL
;
4655 pDesc
->dwMemStartAddress
= 0;
4656 pDesc
->dwMemEndAddress
= 0;
4657 pDesc
->dwMemAllocExtra
= 0;
4658 pDesc
->pvReserved1
= NULL
;
4659 pDesc
->pvReserved2
= NULL
;
4663 static HRESULT WINAPI
IDsCaptureDriverImpl_Open(PIDSCDRIVER iface
)
4665 ICOM_THIS(IDsCaptureDriverImpl
,iface
);
4666 TRACE("(%p)\n",This
);
4670 static HRESULT WINAPI
IDsCaptureDriverImpl_Close(PIDSCDRIVER iface
)
4672 ICOM_THIS(IDsCaptureDriverImpl
,iface
);
4673 TRACE("(%p)\n",This
);
4674 if (This
->capture_buffer
) {
4675 ERR("problem with DirectSound: capture buffer not released\n");
4676 return DSERR_GENERIC
;
4681 static HRESULT WINAPI
IDsCaptureDriverImpl_GetCaps(
4683 PDSCDRIVERCAPS pCaps
)
4685 ICOM_THIS(IDsCaptureDriverImpl
,iface
);
4686 TRACE("(%p,%p)\n",This
,pCaps
);
4687 memcpy(pCaps
, &(WInDev
[This
->wDevID
].ossdev
->dsc_caps
), sizeof(DSCDRIVERCAPS
));
4691 static HRESULT WINAPI
IDsCaptureDriverImpl_CreateCaptureBuffer(
4693 LPWAVEFORMATEX pwfx
,
4695 DWORD dwCardAddress
,
4696 LPDWORD pdwcbBufferSize
,
4700 ICOM_THIS(IDsCaptureDriverImpl
,iface
);
4701 IDsCaptureDriverBufferImpl
** ippdscdb
= (IDsCaptureDriverBufferImpl
**)ppvObj
;
4703 audio_buf_info info
;
4705 TRACE("(%p,%p,%lx,%lx,%p,%p,%p)\n",This
,pwfx
,dwFlags
,dwCardAddress
,
4706 pdwcbBufferSize
,ppbBuffer
,ppvObj
);
4708 if (This
->capture_buffer
) {
4709 TRACE("already allocated\n");
4710 return DSERR_ALLOCATED
;
4713 *ippdscdb
= (IDsCaptureDriverBufferImpl
*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDsCaptureDriverBufferImpl
));
4714 if (*ippdscdb
== NULL
) {
4715 TRACE("out of memory\n");
4716 return DSERR_OUTOFMEMORY
;
4719 (*ippdscdb
)->lpVtbl
= &dscdbvt
;
4720 (*ippdscdb
)->ref
= 1;
4721 (*ippdscdb
)->drv
= This
;
4722 (*ippdscdb
)->notify
= NULL
;
4723 (*ippdscdb
)->notify_index
= 0;
4724 (*ippdscdb
)->notifies
= NULL
;
4725 (*ippdscdb
)->nrofnotifies
= 0;
4726 (*ippdscdb
)->property_set
= NULL
;
4727 (*ippdscdb
)->is_capturing
= FALSE
;
4728 (*ippdscdb
)->is_looping
= FALSE
;
4730 if (WInDev
[This
->wDevID
].state
== WINE_WS_CLOSED
) {
4733 desc
.lpFormat
= pwfx
;
4734 desc
.dwCallback
= 0;
4735 desc
.dwInstance
= 0;
4736 desc
.uMappedDeviceID
= 0;
4738 err
= widOpen(This
->wDevID
, &desc
, dwFlags
| WAVE_DIRECTSOUND
);
4739 if (err
!= MMSYSERR_NOERROR
) {
4740 TRACE("widOpen failed\n");
4745 /* check how big the DMA buffer is now */
4746 if (ioctl(WInDev
[This
->wDevID
].ossdev
->fd
, SNDCTL_DSP_GETISPACE
, &info
) < 0) {
4747 ERR("ioctl(%s, SNDCTL_DSP_GETISPACE) failed (%s)\n",
4748 WInDev
[This
->wDevID
].ossdev
->dev_name
, strerror(errno
));
4749 HeapFree(GetProcessHeap(),0,*ippdscdb
);
4751 return DSERR_GENERIC
;
4753 (*ippdscdb
)->maplen
= (*ippdscdb
)->buflen
= info
.fragstotal
* info
.fragsize
;
4755 /* map the DMA buffer */
4756 err
= DSCDB_MapBuffer(*ippdscdb
);
4758 HeapFree(GetProcessHeap(),0,*ippdscdb
);
4763 /* capture buffer is ready to go */
4764 *pdwcbBufferSize
= (*ippdscdb
)->maplen
;
4765 *ppbBuffer
= (*ippdscdb
)->mapping
;
4767 /* some drivers need some extra nudging after mapping */
4768 WInDev
[This
->wDevID
].ossdev
->bInputEnabled
= FALSE
;
4769 enable
= getEnables(WInDev
[This
->wDevID
].ossdev
);
4770 if (ioctl(WInDev
[This
->wDevID
].ossdev
->fd
, SNDCTL_DSP_SETTRIGGER
, &enable
) < 0) {
4771 ERR("ioctl(%s, SNDCTL_DSP_SETTRIGGER) failed (%s)\n",
4772 WInDev
[This
->wDevID
].ossdev
->dev_name
, strerror(errno
));
4773 return DSERR_GENERIC
;
4776 This
->capture_buffer
= *ippdscdb
;
4781 static IDsCaptureDriverVtbl dscdvt
=
4783 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
4784 IDsCaptureDriverImpl_QueryInterface
,
4785 IDsCaptureDriverImpl_AddRef
,
4786 IDsCaptureDriverImpl_Release
,
4787 IDsCaptureDriverImpl_GetDriverDesc
,
4788 IDsCaptureDriverImpl_Open
,
4789 IDsCaptureDriverImpl_Close
,
4790 IDsCaptureDriverImpl_GetCaps
,
4791 IDsCaptureDriverImpl_CreateCaptureBuffer
4794 static HRESULT WINAPI
IDsCaptureDriverPropertySetImpl_Create(
4795 IDsCaptureDriverBufferImpl
* dscdb
,
4796 IDsCaptureDriverPropertySetImpl
**pdscdps
)
4798 IDsCaptureDriverPropertySetImpl
* dscdps
;
4799 TRACE("(%p,%p)\n",dscdb
,pdscdps
);
4801 dscdps
= (IDsCaptureDriverPropertySetImpl
*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(dscdps
));
4802 if (dscdps
== NULL
) {
4803 WARN("out of memory\n");
4804 return DSERR_OUTOFMEMORY
;
4808 dscdps
->lpVtbl
= &dscdpsvt
;
4809 dscdps
->capture_buffer
= dscdb
;
4810 dscdb
->property_set
= dscdps
;
4811 IDsCaptureDriverBuffer_AddRef((PIDSCDRIVER
)dscdb
);
4817 static HRESULT WINAPI
IDsCaptureDriverNotifyImpl_Create(
4818 IDsCaptureDriverBufferImpl
* dscdb
,
4819 IDsCaptureDriverNotifyImpl
**pdscdn
)
4821 IDsCaptureDriverNotifyImpl
* dscdn
;
4822 TRACE("(%p,%p)\n",dscdb
,pdscdn
);
4824 dscdn
= (IDsCaptureDriverNotifyImpl
*)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(dscdn
));
4825 if (dscdn
== NULL
) {
4826 WARN("out of memory\n");
4827 return DSERR_OUTOFMEMORY
;
4831 dscdn
->lpVtbl
= &dscdnvt
;
4832 dscdn
->capture_buffer
= dscdb
;
4833 dscdb
->notify
= dscdn
;
4834 IDsCaptureDriverBuffer_AddRef((PIDSCDRIVER
)dscdb
);
4840 static DWORD
widDsCreate(UINT wDevID
, PIDSCDRIVER
* drv
)
4842 IDsCaptureDriverImpl
** idrv
= (IDsCaptureDriverImpl
**)drv
;
4843 TRACE("(%d,%p)\n",wDevID
,drv
);
4845 /* the HAL isn't much better than the HEL if we can't do mmap() */
4846 if (!(WInDev
[wDevID
].ossdev
->in_caps_support
& WAVECAPS_DIRECTSOUND
)) {
4847 ERR("DirectSoundCapture flag not set\n");
4848 MESSAGE("This sound card's driver does not support direct access\n");
4849 MESSAGE("The (slower) DirectSound HEL mode will be used instead.\n");
4850 return MMSYSERR_NOTSUPPORTED
;
4853 *idrv
= (IDsCaptureDriverImpl
*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(IDsCaptureDriverImpl
));
4855 return MMSYSERR_NOMEM
;
4856 (*idrv
)->lpVtbl
= &dscdvt
;
4859 (*idrv
)->wDevID
= wDevID
;
4860 (*idrv
)->capture_buffer
= NULL
;
4861 return MMSYSERR_NOERROR
;
4864 static DWORD
widDsDesc(UINT wDevID
, PDSDRIVERDESC desc
)
4866 memcpy(desc
, &(WInDev
[wDevID
].ossdev
->ds_desc
), sizeof(DSDRIVERDESC
));
4867 return MMSYSERR_NOERROR
;
4870 #else /* !HAVE_OSS */
4872 /**************************************************************************
4873 * wodMessage (WINEOSS.7)
4875 DWORD WINAPI
OSS_wodMessage(WORD wDevID
, WORD wMsg
, DWORD dwUser
,
4876 DWORD dwParam1
, DWORD dwParam2
)
4878 FIXME("(%u, %04X, %08lX, %08lX, %08lX):stub\n", wDevID
, wMsg
, dwUser
, dwParam1
, dwParam2
);
4879 return MMSYSERR_NOTENABLED
;
4882 /**************************************************************************
4883 * widMessage (WINEOSS.6)
4885 DWORD WINAPI
OSS_widMessage(WORD wDevID
, WORD wMsg
, DWORD dwUser
,
4886 DWORD dwParam1
, DWORD dwParam2
)
4888 FIXME("(%u, %04X, %08lX, %08lX, %08lX):stub\n", wDevID
, wMsg
, dwUser
, dwParam1
, dwParam2
);
4889 return MMSYSERR_NOTENABLED
;
4892 #endif /* HAVE_OSS */