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)
11 * pause in waveOut does not work correctly in loop mode
12 * experimental full duplex mode
13 * only one sound card is currently supported
16 /*#define EMULATE_SB16*/
26 #include <sys/ioctl.h>
27 #ifdef HAVE_SYS_MMAN_H
28 # include <sys/mman.h>
33 #include "wine/winuser16.h"
38 #include "debugtools.h"
40 DEFAULT_DEBUG_CHANNEL(wave);
42 /* Allow 1% deviation for sample rates (some ES137x cards) */
43 #define NEAR_MATCH(rate1,rate2) (((100*((int)(rate1)-(int)(rate2)))/(rate1))==0)
47 #define SOUND_DEV "/dev/dsp"
48 #define MIXER_DEV "/dev/mixer"
50 #define MAX_WAVEOUTDRV (1)
51 #define MAX_WAVEINDRV (1)
53 /* state diagram for waveOut writing:
55 * +---------+-------------+---------------+---------------------------------+
56 * | state | function | event | new state |
57 * +---------+-------------+---------------+---------------------------------+
58 * | | open() | | STOPPED |
59 * | PAUSED | write() | | PAUSED |
60 * | STOPPED | write() | <thrd create> | PLAYING |
61 * | PLAYING | write() | HEADER | PLAYING |
62 * | (other) | write() | <error> | |
63 * | (any) | pause() | PAUSING | PAUSED |
64 * | PAUSED | restart() | RESTARTING | PLAYING (if no thrd => STOPPED) |
65 * | (any) | reset() | RESETTING | STOPPED |
66 * | (any) | close() | CLOSING | CLOSED |
67 * +---------+-------------+---------------+---------------------------------+
70 /* states of the playing device */
71 #define WINE_WS_PLAYING 0
72 #define WINE_WS_PAUSED 1
73 #define WINE_WS_STOPPED 2
74 #define WINE_WS_CLOSED 3
76 /* events to be send to device */
78 WINE_WM_PAUSING = WM_USER + 1, WINE_WM_RESTARTING, WINE_WM_RESETTING, WINE_WM_HEADER,
79 WINE_WM_UPDATE, WINE_WM_BREAKLOOP, WINE_WM_CLOSING
83 enum win_wm_message msg; /* message identifier */
84 DWORD param; /* parameter for this message */
85 HANDLE hEvent; /* if message is synchronous, handle of event for synchro */
88 /* implement an in-process message ring for better performance
89 * (compared to passing thru the server)
90 * this ring will be used by the input (resp output) record (resp playback) routine
93 /* FIXME: this could be made a dynamically growing array (if needed) */
94 #define OSS_RING_BUFFER_SIZE 30
95 OSS_MSG messages[OSS_RING_BUFFER_SIZE];
99 CRITICAL_SECTION msg_crst;
104 volatile int state; /* one of the WINE_WS_ manifest constants */
105 WAVEOPENDESC waveDesc;
107 PCMWAVEFORMAT format;
110 /* OSS information */
111 DWORD dwFragmentSize; /* size of OSS buffer fragment */
112 DWORD dwBufferSize; /* size of whole OSS buffer in bytes */
113 LPWAVEHDR lpQueuePtr; /* start of queued WAVEHDRs (waiting to be notified) */
114 LPWAVEHDR lpPlayPtr; /* start of not yet fully played buffers */
115 DWORD dwPartialOffset; /* Offset of not yet written bytes in lpPlayPtr */
117 LPWAVEHDR lpLoopPtr; /* pointer of first buffer in loop, if any */
118 DWORD dwLoops; /* private copy of loop counter */
120 DWORD dwPlayedTotal; /* number of bytes actually played since opening */
121 DWORD dwWrittenTotal; /* number of bytes written to OSS buffer since opening */
123 /* synchronization stuff */
124 HANDLE hStartUpEvent;
127 OSS_MSG_RING msgRing;
129 /* DirectSound stuff */
137 DWORD dwFragmentSize; /* OpenSound '/dev/dsp' give us that size */
138 WAVEOPENDESC waveDesc;
140 PCMWAVEFORMAT format;
141 LPWAVEHDR lpQueuePtr;
142 DWORD dwTotalRecorded;
144 BOOL bTriggerSupport;
146 /* synchronization stuff */
149 HANDLE hStartUpEvent;
150 OSS_MSG_RING msgRing;
153 static WINE_WAVEOUT WOutDev [MAX_WAVEOUTDRV];
154 static WINE_WAVEIN WInDev [MAX_WAVEINDRV ];
156 static DWORD wodDsCreate(UINT wDevID, PIDSDRIVER* drv);
158 /* These strings used only for tracing */
159 static const char *wodPlayerCmdString[] = {
161 "WINE_WM_RESTARTING",
169 /*======================================================================*
170 * Low level WAVE implementation *
171 *======================================================================*/
172 #define USE_FULLDUPLEX
173 #ifdef USE_FULLDUPLEX
174 static unsigned OSS_OpenCount /* = 0 */; /* number of times fd has been opened */
175 static unsigned OSS_OpenAccess /* = 0 */; /* access used for opening... used to handle compat */
176 static int OSS_OpenFD;
177 static DWORD OSS_OwnerThreadID /* = 0 */;
179 static BOOL OSS_FullDuplex; /* set to non-zero if the device supports full duplex */
181 /******************************************************************
184 * since OSS has poor capabilities in full duplex, we try here to let a program
185 * open the device for both waveout and wavein streams...
186 * this is hackish, but it's the way OSS interface is done...
188 static int OSS_OpenDevice(unsigned req_access)
190 #ifdef USE_FULLDUPLEX
192 if (OSS_OpenCount == 0)
194 if (access(SOUND_DEV, 0) != 0 ||
195 (OSS_OpenFD = open(SOUND_DEV, req_access|O_NDELAY, 0)) == -1)
197 WARN("Couldn't open out %s (%s)\n", SOUND_DEV, strerror(errno));
200 /* turn full duplex on if it has been requested */
201 if (req_access == O_RDWR && OSS_FullDuplex)
202 ioctl(OSS_OpenFD, SNDCTL_DSP_SETDUPLEX, 0);
203 OSS_OpenAccess = req_access;
204 OSS_OwnerThreadID = GetCurrentThreadId();
208 if (OSS_OpenAccess != req_access)
210 WARN("Mismatch in access...\n");
213 if (GetCurrentThreadId() != OSS_OwnerThreadID)
215 WARN("Another thread is trying to access audio...\n");
224 if (access(SOUND_DEV, 0) != 0 || (fd = open(SOUND_DEV, req_access|O_NDELAY, 0)) == -1)
226 WARN("Couldn't open out %s (%s)\n", SOUND_DEV, strerror(errno));
233 /******************************************************************
238 static void OSS_CloseDevice(int fd)
240 #ifdef USE_FULLDUPLEX
241 if (fd != OSS_OpenFD) FIXME("What the heck????\n");
242 if (--OSS_OpenCount == 0)
251 /******************************************************************
254 * Initialize internal structures from OSS information
256 LONG OSS_WaveInit(void)
268 /* start with output device */
270 /* initialize all device handles to -1 */
271 for (i = 0; i < MAX_WAVEOUTDRV; ++i)
273 WOutDev[i].unixdev = -1;
276 /* FIXME: only one device is supported */
277 memset(&WOutDev[0].caps, 0, sizeof(WOutDev[0].caps));
279 if ((audio = OSS_OpenDevice(O_WRONLY)) == -1) return -1;
281 ioctl(audio, SNDCTL_DSP_RESET, 0);
283 /* FIXME: some programs compare this string against the content of the registry
284 * for MM drivers. The names have to match in order for the program to work
285 * (e.g. MS win9x mplayer.exe)
288 WOutDev[0].caps.wMid = 0x0002;
289 WOutDev[0].caps.wPid = 0x0104;
290 strcpy(WOutDev[0].caps.szPname, "SB16 Wave Out");
292 WOutDev[0].caps.wMid = 0x00FF; /* Manufac ID */
293 WOutDev[0].caps.wPid = 0x0001; /* Product ID */
294 /* strcpy(WOutDev[0].caps.szPname, "OpenSoundSystem WAVOUT Driver");*/
295 strcpy(WOutDev[0].caps.szPname, "CS4236/37/38");
297 WOutDev[0].caps.vDriverVersion = 0x0100;
298 WOutDev[0].caps.dwFormats = 0x00000000;
299 WOutDev[0].caps.dwSupport = WAVECAPS_VOLUME;
301 IOCTL(audio, SNDCTL_DSP_GETFMTS, mask);
302 TRACE("OSS dsp out mask=%08x\n", mask);
304 /* First bytespersampl, then stereo */
305 bytespersmpl = (IOCTL(audio, SNDCTL_DSP_SAMPLESIZE, samplesize) != 0) ? 1 : 2;
307 WOutDev[0].caps.wChannels = (IOCTL(audio, SNDCTL_DSP_STEREO, dsp_stereo) != 0) ? 1 : 2;
308 if (WOutDev[0].caps.wChannels > 1) WOutDev[0].caps.dwSupport |= WAVECAPS_LRVOLUME;
311 if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) {
312 if (mask & AFMT_U8) {
313 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_4M08;
314 if (WOutDev[0].caps.wChannels > 1)
315 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_4S08;
317 if ((mask & AFMT_S16_LE) && bytespersmpl > 1) {
318 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_4M16;
319 if (WOutDev[0].caps.wChannels > 1)
320 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_4S16;
324 if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) {
325 if (mask & AFMT_U8) {
326 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_2M08;
327 if (WOutDev[0].caps.wChannels > 1)
328 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_2S08;
330 if ((mask & AFMT_S16_LE) && bytespersmpl > 1) {
331 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_2M16;
332 if (WOutDev[0].caps.wChannels > 1)
333 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_2S16;
337 if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) {
338 if (mask & AFMT_U8) {
339 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_1M08;
340 if (WOutDev[0].caps.wChannels > 1)
341 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_1S08;
343 if ((mask & AFMT_S16_LE) && bytespersmpl > 1) {
344 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_1M16;
345 if (WOutDev[0].caps.wChannels > 1)
346 WOutDev[0].caps.dwFormats |= WAVE_FORMAT_1S16;
349 if (IOCTL(audio, SNDCTL_DSP_GETCAPS, caps) == 0) {
350 TRACE("OSS dsp out caps=%08X\n", caps);
351 if ((caps & DSP_CAP_REALTIME) && !(caps & DSP_CAP_BATCH)) {
352 WOutDev[0].caps.dwSupport |= WAVECAPS_SAMPLEACCURATE;
354 /* well, might as well use the DirectSound cap flag for something */
355 if ((caps & DSP_CAP_TRIGGER) && (caps & DSP_CAP_MMAP) &&
356 !(caps & DSP_CAP_BATCH))
357 WOutDev[0].caps.dwSupport |= WAVECAPS_DIRECTSOUND;
359 OSS_CloseDevice(audio);
360 TRACE("out dwFormats = %08lX, dwSupport = %08lX\n",
361 WOutDev[0].caps.dwFormats, WOutDev[0].caps.dwSupport);
363 /* then do input device */
367 for (i = 0; i < MAX_WAVEINDRV; ++i)
369 WInDev[i].unixdev = -1;
372 memset(&WInDev[0].caps, 0, sizeof(WInDev[0].caps));
374 if ((audio = OSS_OpenDevice(O_RDONLY)) == -1) return -1;
376 ioctl(audio, SNDCTL_DSP_RESET, 0);
379 WInDev[0].caps.wMid = 0x0002;
380 WInDev[0].caps.wPid = 0x0004;
381 strcpy(WInDev[0].caps.szPname, "SB16 Wave In");
383 WInDev[0].caps.wMid = 0x00FF; /* Manufac ID */
384 WInDev[0].caps.wPid = 0x0001; /* Product ID */
385 strcpy(WInDev[0].caps.szPname, "OpenSoundSystem WAVIN Driver");
387 WInDev[0].caps.dwFormats = 0x00000000;
388 WInDev[0].caps.wChannels = (IOCTL(audio, SNDCTL_DSP_STEREO, dsp_stereo) != 0) ? 1 : 2;
390 WInDev[0].bTriggerSupport = FALSE;
391 if (IOCTL(audio, SNDCTL_DSP_GETCAPS, caps) == 0) {
392 TRACE("OSS dsp in caps=%08X\n", caps);
393 if (caps & DSP_CAP_TRIGGER)
394 WInDev[0].bTriggerSupport = TRUE;
397 IOCTL(audio, SNDCTL_DSP_GETFMTS, mask);
398 TRACE("OSS in dsp mask=%08x\n", mask);
400 bytespersmpl = (IOCTL(audio, SNDCTL_DSP_SAMPLESIZE, samplesize) != 0) ? 1 : 2;
402 if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) {
403 if (mask & AFMT_U8) {
404 WInDev[0].caps.dwFormats |= WAVE_FORMAT_4M08;
405 if (WInDev[0].caps.wChannels > 1)
406 WInDev[0].caps.dwFormats |= WAVE_FORMAT_4S08;
408 if ((mask & AFMT_S16_LE) && bytespersmpl > 1) {
409 WInDev[0].caps.dwFormats |= WAVE_FORMAT_4M16;
410 if (WInDev[0].caps.wChannels > 1)
411 WInDev[0].caps.dwFormats |= WAVE_FORMAT_4S16;
415 if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) {
416 if (mask & AFMT_U8) {
417 WInDev[0].caps.dwFormats |= WAVE_FORMAT_2M08;
418 if (WInDev[0].caps.wChannels > 1)
419 WInDev[0].caps.dwFormats |= WAVE_FORMAT_2S08;
421 if ((mask & AFMT_S16_LE) && bytespersmpl > 1) {
422 WInDev[0].caps.dwFormats |= WAVE_FORMAT_2M16;
423 if (WInDev[0].caps.wChannels > 1)
424 WInDev[0].caps.dwFormats |= WAVE_FORMAT_2S16;
428 if (IOCTL(audio, SNDCTL_DSP_SPEED, smplrate) == 0) {
429 if (mask & AFMT_U8) {
430 WInDev[0].caps.dwFormats |= WAVE_FORMAT_1M08;
431 if (WInDev[0].caps.wChannels > 1)
432 WInDev[0].caps.dwFormats |= WAVE_FORMAT_1S08;
434 if ((mask & AFMT_S16_LE) && bytespersmpl > 1) {
435 WInDev[0].caps.dwFormats |= WAVE_FORMAT_1M16;
436 if (WInDev[0].caps.wChannels > 1)
437 WInDev[0].caps.dwFormats |= WAVE_FORMAT_1S16;
440 OSS_CloseDevice(audio);
441 TRACE("in dwFormats = %08lX\n", WInDev[0].caps.dwFormats);
443 #ifdef USE_FULLDUPLEX
444 if ((audio = OSS_OpenDevice(O_RDWR)) == -1) return -1;
445 if (IOCTL(audio, SNDCTL_DSP_GETCAPS, caps) == 0) {
446 OSS_FullDuplex = (caps & DSP_CAP_DUPLEX);
448 OSS_CloseDevice(audio);
454 /******************************************************************
455 * OSS_InitRingMessage
457 * Initialize the ring of messages for passing between driver's caller and playback/record
460 static int OSS_InitRingMessage(OSS_MSG_RING* omr)
464 omr->msg_event = CreateEventA(NULL, FALSE, FALSE, NULL);
465 memset(omr->messages, 0, sizeof(OSS_MSG) * OSS_RING_BUFFER_SIZE);
466 InitializeCriticalSection(&omr->msg_crst);
470 /******************************************************************
471 * OSS_DestroyRingMessage
474 static int OSS_DestroyRingMessage(OSS_MSG_RING* omr)
476 CloseHandle(omr->msg_event);
477 DeleteCriticalSection(&omr->msg_crst);
481 /******************************************************************
484 * Inserts a new message into the ring (should be called from DriverProc derivated routines)
486 static int OSS_AddRingMessage(OSS_MSG_RING* omr, enum win_wm_message msg, DWORD param, BOOL wait)
488 HANDLE hEvent = INVALID_HANDLE_VALUE;
490 EnterCriticalSection(&omr->msg_crst);
491 if ((omr->msg_toget == ((omr->msg_tosave + 1) % OSS_RING_BUFFER_SIZE))) /* buffer overflow ? */
493 ERR("buffer overflow !?\n");
494 LeaveCriticalSection(&omr->msg_crst);
499 hEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
500 if (hEvent == INVALID_HANDLE_VALUE)
502 ERR("can't create event !?\n");
503 LeaveCriticalSection(&omr->msg_crst);
506 if (omr->msg_toget != omr->msg_tosave && omr->messages[omr->msg_toget].msg != WINE_WM_HEADER)
507 FIXME("two fast messages in the queue!!!!\n");
509 /* fast messages have to be added at the start of the queue */
510 omr->msg_toget = (omr->msg_toget + OSS_RING_BUFFER_SIZE - 1) % OSS_RING_BUFFER_SIZE;
512 omr->messages[omr->msg_toget].msg = msg;
513 omr->messages[omr->msg_toget].param = param;
514 omr->messages[omr->msg_toget].hEvent = hEvent;
518 omr->messages[omr->msg_tosave].msg = msg;
519 omr->messages[omr->msg_tosave].param = param;
520 omr->messages[omr->msg_tosave].hEvent = INVALID_HANDLE_VALUE;
521 omr->msg_tosave = (omr->msg_tosave + 1) % OSS_RING_BUFFER_SIZE;
523 LeaveCriticalSection(&omr->msg_crst);
524 /* signal a new message */
525 SetEvent(omr->msg_event);
528 /* wait for playback/record thread to have processed the message */
529 WaitForSingleObject(hEvent, INFINITE);
535 /******************************************************************
536 * OSS_RetrieveRingMessage
538 * Get a message from the ring. Should be called by the playback/record thread.
540 static int OSS_RetrieveRingMessage(OSS_MSG_RING* omr,
541 enum win_wm_message *msg, DWORD *param, HANDLE *hEvent)
543 EnterCriticalSection(&omr->msg_crst);
545 if (omr->msg_toget == omr->msg_tosave) /* buffer empty ? */
547 LeaveCriticalSection(&omr->msg_crst);
551 *msg = omr->messages[omr->msg_toget].msg;
552 omr->messages[omr->msg_toget].msg = 0;
553 *param = omr->messages[omr->msg_toget].param;
554 *hEvent = omr->messages[omr->msg_toget].hEvent;
555 omr->msg_toget = (omr->msg_toget + 1) % OSS_RING_BUFFER_SIZE;
556 LeaveCriticalSection(&omr->msg_crst);
560 /*======================================================================*
561 * Low level WAVE OUT implementation *
562 *======================================================================*/
564 /**************************************************************************
565 * wodNotifyClient [internal]
567 static DWORD wodNotifyClient(WINE_WAVEOUT* wwo, WORD wMsg, DWORD dwParam1, DWORD dwParam2)
569 TRACE("wMsg = 0x%04x dwParm1 = %04lX dwParam2 = %04lX\n", wMsg, dwParam1, dwParam2);
575 if (wwo->wFlags != DCB_NULL &&
576 !DriverCallback(wwo->waveDesc.dwCallback, wwo->wFlags, wwo->waveDesc.hWave,
577 wMsg, wwo->waveDesc.dwInstance, dwParam1, dwParam2)) {
578 WARN("can't notify client !\n");
579 return MMSYSERR_ERROR;
583 FIXME("Unknown callback message %u\n", wMsg);
584 return MMSYSERR_INVALPARAM;
586 return MMSYSERR_NOERROR;
589 /**************************************************************************
590 * wodUpdatePlayedTotal [internal]
593 static BOOL wodUpdatePlayedTotal(WINE_WAVEOUT* wwo, audio_buf_info* info)
595 audio_buf_info dspspace;
596 if (!info) info = &dspspace;
598 if (ioctl(wwo->unixdev, SNDCTL_DSP_GETOSPACE, info) < 0) {
599 ERR("IOCTL can't 'SNDCTL_DSP_GETOSPACE' !\n");
602 wwo->dwPlayedTotal = wwo->dwWrittenTotal - (wwo->dwBufferSize - info->bytes);
606 /**************************************************************************
607 * wodPlayer_BeginWaveHdr [internal]
609 * Makes the specified lpWaveHdr the currently playing wave header.
610 * If the specified wave header is a begin loop and we're not already in
611 * a loop, setup the loop.
613 static void wodPlayer_BeginWaveHdr(WINE_WAVEOUT* wwo, LPWAVEHDR lpWaveHdr)
615 wwo->lpPlayPtr = lpWaveHdr;
617 if (!lpWaveHdr) return;
619 if (lpWaveHdr->dwFlags & WHDR_BEGINLOOP) {
620 if (wwo->lpLoopPtr) {
621 WARN("Already in a loop. Discarding loop on this header (%p)\n", lpWaveHdr);
623 TRACE("Starting loop (%ldx) with %p\n", lpWaveHdr->dwLoops, lpWaveHdr);
624 wwo->lpLoopPtr = lpWaveHdr;
625 /* Windows does not touch WAVEHDR.dwLoops,
626 * so we need to make an internal copy */
627 wwo->dwLoops = lpWaveHdr->dwLoops;
630 wwo->dwPartialOffset = 0;
633 /**************************************************************************
634 * wodPlayer_PlayPtrNext [internal]
636 * Advance the play pointer to the next waveheader, looping if required.
638 static LPWAVEHDR wodPlayer_PlayPtrNext(WINE_WAVEOUT* wwo)
640 LPWAVEHDR lpWaveHdr = wwo->lpPlayPtr;
642 wwo->dwPartialOffset = 0;
643 if ((lpWaveHdr->dwFlags & WHDR_ENDLOOP) && wwo->lpLoopPtr) {
644 /* We're at the end of a loop, loop if required */
645 if (--wwo->dwLoops > 0) {
646 wwo->lpPlayPtr = wwo->lpLoopPtr;
648 /* Handle overlapping loops correctly */
649 if (wwo->lpLoopPtr != lpWaveHdr && (lpWaveHdr->dwFlags & WHDR_BEGINLOOP)) {
650 FIXME("Correctly handled case ? (ending loop buffer also starts a new loop)\n");
651 /* shall we consider the END flag for the closing loop or for
652 * the opening one or for both ???
653 * code assumes for closing loop only
656 lpWaveHdr = lpWaveHdr->lpNext;
658 wwo->lpLoopPtr = NULL;
659 wodPlayer_BeginWaveHdr(wwo, lpWaveHdr);
662 /* We're not in a loop. Advance to the next wave header */
663 wodPlayer_BeginWaveHdr(wwo, lpWaveHdr = lpWaveHdr->lpNext);
669 /**************************************************************************
670 * wodPlayer_DSPWait [internal]
671 * Returns the number of milliseconds to wait for the DSP buffer to write
674 static DWORD wodPlayer_DSPWait(const WINE_WAVEOUT *wwo)
676 /* time for one fragment to be played */
677 return wwo->dwFragmentSize * 1000 / wwo->format.wf.nAvgBytesPerSec;
680 /**************************************************************************
681 * wodPlayer_NotifyWait [internal]
682 * Returns the number of milliseconds to wait before attempting to notify
683 * completion of the specified wavehdr.
684 * This is based on the number of bytes remaining to be written in the
687 static DWORD wodPlayer_NotifyWait(const WINE_WAVEOUT* wwo, LPWAVEHDR lpWaveHdr)
691 if (lpWaveHdr->reserved < wwo->dwPlayedTotal) {
694 dwMillis = (lpWaveHdr->reserved - wwo->dwPlayedTotal) * 1000 / wwo->format.wf.nAvgBytesPerSec;
695 if (!dwMillis) dwMillis = 1;
702 /**************************************************************************
703 * wodPlayer_WriteMaxFrags [internal]
704 * Writes the maximum number of bytes possible to the DSP and returns
705 * the number of bytes written.
707 static int wodPlayer_WriteMaxFrags(WINE_WAVEOUT* wwo, DWORD* bytes)
709 /* Only attempt to write to free bytes */
710 DWORD dwLength = wwo->lpPlayPtr->dwBufferLength - wwo->dwPartialOffset;
711 int toWrite = min(dwLength, *bytes);
714 TRACE("Writing wavehdr %p.%lu[%lu]\n",
715 wwo->lpPlayPtr, wwo->dwPartialOffset, wwo->lpPlayPtr->dwBufferLength);
716 written = write(wwo->unixdev, wwo->lpPlayPtr->lpData + wwo->dwPartialOffset, toWrite);
717 if (written <= 0) return written;
719 if (written >= dwLength) {
720 /* If we wrote all current wavehdr, skip to the next one */
721 wodPlayer_PlayPtrNext(wwo);
723 /* Remove the amount written */
724 wwo->dwPartialOffset += written;
727 wwo->dwWrittenTotal += written;
733 /**************************************************************************
734 * wodPlayer_NotifyCompletions [internal]
736 * Notifies and remove from queue all wavehdrs which have been played to
737 * the speaker (ie. they have cleared the OSS buffer). If force is true,
738 * we notify all wavehdrs and remove them all from the queue even if they
739 * are unplayed or part of a loop.
741 static DWORD wodPlayer_NotifyCompletions(WINE_WAVEOUT* wwo, BOOL force)
745 /* Start from lpQueuePtr and keep notifying until:
746 * - we hit an unwritten wavehdr
747 * - we hit the beginning of a running loop
748 * - we hit a wavehdr which hasn't finished playing
750 while ((lpWaveHdr = wwo->lpQueuePtr) &&
752 (lpWaveHdr != wwo->lpPlayPtr &&
753 lpWaveHdr != wwo->lpLoopPtr &&
754 lpWaveHdr->reserved <= wwo->dwPlayedTotal))) {
756 wwo->lpQueuePtr = lpWaveHdr->lpNext;
758 lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
759 lpWaveHdr->dwFlags |= WHDR_DONE;
761 wodNotifyClient(wwo, WOM_DONE, (DWORD)lpWaveHdr, 0);
763 return (lpWaveHdr && lpWaveHdr != wwo->lpPlayPtr && lpWaveHdr != wwo->lpLoopPtr) ?
764 wodPlayer_NotifyWait(wwo, lpWaveHdr) : INFINITE;
767 /**************************************************************************
768 * wodPlayer_Reset [internal]
770 * wodPlayer helper. Resets current output stream.
772 static void wodPlayer_Reset(WINE_WAVEOUT* wwo, BOOL reset)
774 wodUpdatePlayedTotal(wwo, NULL);
775 /* updates current notify list */
776 wodPlayer_NotifyCompletions(wwo, FALSE);
778 /* flush all possible output */
779 if (ioctl(wwo->unixdev, SNDCTL_DSP_RESET, 0) == -1) {
780 perror("ioctl SNDCTL_DSP_RESET");
782 wwo->state = WINE_WS_STOPPED;
787 enum win_wm_message msg;
791 /* remove any buffer */
792 wodPlayer_NotifyCompletions(wwo, TRUE);
794 wwo->lpPlayPtr = wwo->lpQueuePtr = wwo->lpLoopPtr = NULL;
795 wwo->state = WINE_WS_STOPPED;
796 wwo->dwPlayedTotal = wwo->dwWrittenTotal = 0;
797 /* Clear partial wavehdr */
798 wwo->dwPartialOffset = 0;
800 /* remove any existing message in the ring */
801 EnterCriticalSection(&wwo->msgRing.msg_crst);
802 /* return all pending headers in queue */
803 while (OSS_RetrieveRingMessage(&wwo->msgRing, &msg, ¶m, &ev))
805 if (msg != WINE_WM_HEADER)
807 FIXME("shouldn't have headers left\n");
811 ((LPWAVEHDR)param)->dwFlags &= ~WHDR_INQUEUE;
812 ((LPWAVEHDR)param)->dwFlags |= WHDR_DONE;
814 wodNotifyClient(wwo, WOM_DONE, param, 0);
816 ResetEvent(wwo->msgRing.msg_event);
817 LeaveCriticalSection(&wwo->msgRing.msg_crst);
819 if (wwo->lpLoopPtr) {
820 /* complicated case, not handled yet (could imply modifying the loop counter */
821 FIXME("Pausing while in loop isn't correctly handled yet, except strange results\n");
822 wwo->lpPlayPtr = wwo->lpLoopPtr;
823 wwo->dwPartialOffset = 0;
824 wwo->dwWrittenTotal = wwo->dwPlayedTotal; /* this is wrong !!! */
827 DWORD sz = wwo->dwPartialOffset;
829 /* reset all the data as if we had written only up to lpPlayedTotal bytes */
830 /* compute the max size playable from lpQueuePtr */
831 for (ptr = wwo->lpQueuePtr; ptr != wwo->lpPlayPtr; ptr = ptr->lpNext) {
832 sz += ptr->dwBufferLength;
834 /* because the reset lpPlayPtr will be lpQueuePtr */
835 if (wwo->dwWrittenTotal > wwo->dwPlayedTotal + sz) ERR("grin\n");
836 wwo->dwPartialOffset = sz - (wwo->dwWrittenTotal - wwo->dwPlayedTotal);
837 wwo->dwWrittenTotal = wwo->dwPlayedTotal;
838 wwo->lpPlayPtr = wwo->lpQueuePtr;
840 wwo->state = WINE_WS_PAUSED;
844 /**************************************************************************
845 * wodPlayer_ProcessMessages [internal]
847 static void wodPlayer_ProcessMessages(WINE_WAVEOUT* wwo)
850 enum win_wm_message msg;
854 while (OSS_RetrieveRingMessage(&wwo->msgRing, &msg, ¶m, &ev)) {
855 TRACE("Received %s %lx\n", wodPlayerCmdString[msg - WM_USER - 1], param);
857 case WINE_WM_PAUSING:
858 wodPlayer_Reset(wwo, FALSE);
861 case WINE_WM_RESTARTING:
862 wwo->state = WINE_WS_PLAYING;
866 lpWaveHdr = (LPWAVEHDR)param;
868 /* insert buffer at the end of queue */
871 for (wh = &(wwo->lpQueuePtr); *wh; wh = &((*wh)->lpNext));
875 wodPlayer_BeginWaveHdr(wwo,lpWaveHdr);
876 if (wwo->state == WINE_WS_STOPPED)
877 wwo->state = WINE_WS_PLAYING;
879 case WINE_WM_RESETTING:
880 wodPlayer_Reset(wwo, TRUE);
884 wodUpdatePlayedTotal(wwo, NULL);
887 case WINE_WM_BREAKLOOP:
888 if (wwo->state == WINE_WS_PLAYING && wwo->lpLoopPtr != NULL) {
889 /* ensure exit at end of current loop */
894 case WINE_WM_CLOSING:
895 /* sanity check: this should not happen since the device must have been reset before */
896 if (wwo->lpQueuePtr || wwo->lpPlayPtr) ERR("out of sync\n");
898 wwo->state = WINE_WS_CLOSED;
901 /* shouldn't go here */
903 FIXME("unknown message %d\n", msg);
909 /**************************************************************************
910 * wodPlayer_FeedDSP [internal]
911 * Feed as much sound data as we can into the DSP and return the number of
912 * milliseconds before it will be necessary to feed the DSP again.
914 static DWORD wodPlayer_FeedDSP(WINE_WAVEOUT* wwo)
916 audio_buf_info dspspace;
919 wodUpdatePlayedTotal(wwo, &dspspace);
920 availInQ = dspspace.bytes;
921 TRACE("fragments=%d/%d, fragsize=%d, bytes=%d\n",
922 dspspace.fragments, dspspace.fragstotal, dspspace.fragsize, dspspace.bytes);
924 /* input queue empty and output buffer with less than one fragment to play */
925 if (!wwo->lpPlayPtr && wwo->dwBufferSize < availInQ + 2 * wwo->dwFragmentSize) {
926 TRACE("Run out of wavehdr:s... flushing\n");
927 ioctl(wwo->unixdev, SNDCTL_DSP_SYNC, 0);
928 wwo->dwPlayedTotal = wwo->dwWrittenTotal;
932 /* no more room... no need to try to feed */
933 if (dspspace.fragments != 0) {
934 /* Feed from partial wavehdr */
935 if (wwo->lpPlayPtr && wwo->dwPartialOffset != 0) {
936 wodPlayer_WriteMaxFrags(wwo, &availInQ);
939 /* Feed wavehdrs until we run out of wavehdrs or DSP space */
940 if (wwo->dwPartialOffset == 0) {
941 while (wwo->lpPlayPtr && availInQ > 0) {
942 /* note the value that dwPlayedTotal will return when this wave finishes playing */
943 wwo->lpPlayPtr->reserved = wwo->dwWrittenTotal + wwo->lpPlayPtr->dwBufferLength;
944 wodPlayer_WriteMaxFrags(wwo, &availInQ);
949 return wodPlayer_DSPWait(wwo);
953 /**************************************************************************
954 * wodPlayer [internal]
956 static DWORD CALLBACK wodPlayer(LPVOID pmt)
958 WORD uDevID = (DWORD)pmt;
959 WINE_WAVEOUT* wwo = (WINE_WAVEOUT*)&WOutDev[uDevID];
960 DWORD dwNextFeedTime = INFINITE; /* Time before DSP needs feeding */
961 DWORD dwNextNotifyTime = INFINITE; /* Time before next wave completion */
964 wwo->state = WINE_WS_STOPPED;
965 SetEvent(wwo->hStartUpEvent);
968 /** Wait for the shortest time before an action is required. If there
969 * are no pending actions, wait forever for a command.
971 dwSleepTime = min(dwNextFeedTime, dwNextNotifyTime);
972 TRACE("waiting %lums (%lu,%lu)\n", dwSleepTime, dwNextFeedTime, dwNextNotifyTime);
973 WaitForSingleObject(wwo->msgRing.msg_event, dwSleepTime);
974 wodPlayer_ProcessMessages(wwo);
975 if (wwo->state == WINE_WS_PLAYING) {
976 dwNextFeedTime = wodPlayer_FeedDSP(wwo);
977 dwNextNotifyTime = wodPlayer_NotifyCompletions(wwo, FALSE);
979 dwNextFeedTime = dwNextNotifyTime = INFINITE;
984 /**************************************************************************
985 * wodGetDevCaps [internal]
987 static DWORD wodGetDevCaps(WORD wDevID, LPWAVEOUTCAPSA lpCaps, DWORD dwSize)
989 TRACE("(%u, %p, %lu);\n", wDevID, lpCaps, dwSize);
991 if (lpCaps == NULL) return MMSYSERR_NOTENABLED;
993 if (wDevID >= MAX_WAVEOUTDRV) {
994 TRACE("MAX_WAVOUTDRV reached !\n");
995 return MMSYSERR_BADDEVICEID;
998 memcpy(lpCaps, &WOutDev[wDevID].caps, min(dwSize, sizeof(*lpCaps)));
999 return MMSYSERR_NOERROR;
1002 /**************************************************************************
1003 * wodOpen [internal]
1005 static DWORD wodOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags)
1012 audio_buf_info info;
1014 TRACE("(%u, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
1015 if (lpDesc == NULL) {
1016 WARN("Invalid Parameter !\n");
1017 return MMSYSERR_INVALPARAM;
1019 if (wDevID >= MAX_WAVEOUTDRV) {
1020 TRACE("MAX_WAVOUTDRV reached !\n");
1021 return MMSYSERR_BADDEVICEID;
1024 /* only PCM format is supported so far... */
1025 if (lpDesc->lpFormat->wFormatTag != WAVE_FORMAT_PCM ||
1026 lpDesc->lpFormat->nChannels == 0 ||
1027 lpDesc->lpFormat->nSamplesPerSec == 0) {
1028 WARN("Bad format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
1029 lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
1030 lpDesc->lpFormat->nSamplesPerSec);
1031 return WAVERR_BADFORMAT;
1034 if (dwFlags & WAVE_FORMAT_QUERY) {
1035 TRACE("Query format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
1036 lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
1037 lpDesc->lpFormat->nSamplesPerSec);
1038 return MMSYSERR_NOERROR;
1041 wwo = &WOutDev[wDevID];
1043 if ((dwFlags & WAVE_DIRECTSOUND) && !(wwo->caps.dwSupport & WAVECAPS_DIRECTSOUND))
1044 /* not supported, ignore it */
1045 dwFlags &= ~WAVE_DIRECTSOUND;
1047 if (access(SOUND_DEV, 0) != 0)
1048 return MMSYSERR_NOTENABLED;
1049 /* we want to be able to mmap() the device, which means it must be opened readable,
1050 * otherwise mmap() will fail (at least under Linux) */
1051 wwo->unixdev = OSS_OpenDevice(((dwFlags & WAVE_DIRECTSOUND) || OSS_FullDuplex) ?
1053 if (wwo->unixdev == -1) return MMSYSERR_ALLOCATED;
1055 fcntl(wwo->unixdev, F_SETFD, 1); /* set close on exec flag */
1056 wwo->wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
1058 memcpy(&wwo->waveDesc, lpDesc, sizeof(WAVEOPENDESC));
1059 memcpy(&wwo->format, lpDesc->lpFormat, sizeof(PCMWAVEFORMAT));
1061 if (wwo->format.wBitsPerSample == 0) {
1062 WARN("Resetting zeroed wBitsPerSample\n");
1063 wwo->format.wBitsPerSample = 8 *
1064 (wwo->format.wf.nAvgBytesPerSec /
1065 wwo->format.wf.nSamplesPerSec) /
1066 wwo->format.wf.nChannels;
1069 if (dwFlags & WAVE_DIRECTSOUND) {
1070 if (wwo->caps.dwSupport & WAVECAPS_SAMPLEACCURATE)
1071 /* we have realtime DirectSound, fragments just waste our time,
1072 * but a large buffer is good, so choose 64KB (32 * 2^11) */
1073 audio_fragment = 0x0020000B;
1075 /* to approximate realtime, we must use small fragments,
1076 * let's try to fragment the above 64KB (256 * 2^8) */
1077 audio_fragment = 0x01000008;
1079 /* shockwave player uses only 4 1k-fragments at a rate of 22050 bytes/sec
1080 * thus leading to 46ms per fragment, and a turnaround time of 185ms
1082 /* 16 fragments max, 2^10=1024 bytes per fragment */
1083 audio_fragment = 0x000F000A;
1085 sample_rate = wwo->format.wf.nSamplesPerSec;
1086 dsp_stereo = (wwo->format.wf.nChannels > 1) ? 1 : 0;
1087 format = (wwo->format.wBitsPerSample == 16) ? AFMT_S16_LE : AFMT_U8;
1089 IOCTL(wwo->unixdev, SNDCTL_DSP_SETFRAGMENT, audio_fragment);
1090 /* First size and stereo then samplerate */
1091 IOCTL(wwo->unixdev, SNDCTL_DSP_SETFMT, format);
1092 IOCTL(wwo->unixdev, SNDCTL_DSP_STEREO, dsp_stereo);
1093 IOCTL(wwo->unixdev, SNDCTL_DSP_SPEED, sample_rate);
1095 /* paranoid checks */
1096 if (format != ((wwo->format.wBitsPerSample == 16) ? AFMT_S16_LE : AFMT_U8))
1097 ERR("Can't set format to %d (%d)\n",
1098 (wwo->format.wBitsPerSample == 16) ? AFMT_S16_LE : AFMT_U8, format);
1099 if (dsp_stereo != (wwo->format.wf.nChannels > 1) ? 1 : 0)
1100 ERR("Can't set stereo to %u (%d)\n",
1101 (wwo->format.wf.nChannels > 1) ? 1 : 0, dsp_stereo);
1102 if (!NEAR_MATCH(sample_rate, wwo->format.wf.nSamplesPerSec))
1103 ERR("Can't set sample_rate to %lu (%d)\n",
1104 wwo->format.wf.nSamplesPerSec, sample_rate);
1106 /* Read output space info for future reference */
1107 if (ioctl(wwo->unixdev, SNDCTL_DSP_GETOSPACE, &info) < 0) {
1108 ERR("IOCTL can't 'SNDCTL_DSP_GETOSPACE' !\n");
1109 OSS_CloseDevice(wwo->unixdev);
1111 return MMSYSERR_NOTENABLED;
1114 /* Check that fragsize is correct per our settings above */
1115 if ((info.fragsize > 1024) && (LOWORD(audio_fragment) <= 10)) {
1116 /* we've tried to set 1K fragments or less, but it didn't work */
1117 ERR("fragment size set failed, size is now %d\n", info.fragsize);
1118 MESSAGE("Your Open Sound System driver did not let us configure small enough sound fragments.\n");
1119 MESSAGE("This may cause delays and other problems in audio playback with certain applications.\n");
1122 /* Remember fragsize and total buffer size for future use */
1123 wwo->dwFragmentSize = info.fragsize;
1124 wwo->dwBufferSize = info.fragstotal * info.fragsize;
1125 wwo->dwPlayedTotal = 0;
1126 wwo->dwWrittenTotal = 0;
1128 OSS_InitRingMessage(&wwo->msgRing);
1130 if (!(dwFlags & WAVE_DIRECTSOUND)) {
1131 wwo->hStartUpEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
1132 wwo->hThread = CreateThread(NULL, 0, wodPlayer, (LPVOID)(DWORD)wDevID, 0, &(wwo->dwThreadID));
1133 WaitForSingleObject(wwo->hStartUpEvent, INFINITE);
1134 CloseHandle(wwo->hStartUpEvent);
1136 wwo->hThread = INVALID_HANDLE_VALUE;
1137 wwo->dwThreadID = 0;
1139 wwo->hStartUpEvent = INVALID_HANDLE_VALUE;
1141 TRACE("fd=%d fragmentSize=%ld\n",
1142 wwo->unixdev, wwo->dwFragmentSize);
1143 if (wwo->dwFragmentSize % wwo->format.wf.nBlockAlign)
1144 ERR("Fragment doesn't contain an integral number of data blocks\n");
1146 TRACE("wBitsPerSample=%u, nAvgBytesPerSec=%lu, nSamplesPerSec=%lu, nChannels=%u nBlockAlign=%u!\n",
1147 wwo->format.wBitsPerSample, wwo->format.wf.nAvgBytesPerSec,
1148 wwo->format.wf.nSamplesPerSec, wwo->format.wf.nChannels,
1149 wwo->format.wf.nBlockAlign);
1151 return wodNotifyClient(wwo, WOM_OPEN, 0L, 0L);
1154 /**************************************************************************
1155 * wodClose [internal]
1157 static DWORD wodClose(WORD wDevID)
1159 DWORD ret = MMSYSERR_NOERROR;
1162 TRACE("(%u);\n", wDevID);
1164 if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].unixdev == -1) {
1165 WARN("bad device ID !\n");
1166 return MMSYSERR_BADDEVICEID;
1169 wwo = &WOutDev[wDevID];
1170 if (wwo->lpQueuePtr) {
1171 WARN("buffers still playing !\n");
1172 ret = WAVERR_STILLPLAYING;
1174 if (wwo->hThread != INVALID_HANDLE_VALUE) {
1175 OSS_AddRingMessage(&wwo->msgRing, WINE_WM_CLOSING, 0, TRUE);
1178 munmap(wwo->mapping, wwo->maplen);
1179 wwo->mapping = NULL;
1182 OSS_DestroyRingMessage(&wwo->msgRing);
1184 OSS_CloseDevice(wwo->unixdev);
1186 wwo->dwFragmentSize = 0;
1187 ret = wodNotifyClient(wwo, WOM_CLOSE, 0L, 0L);
1192 /**************************************************************************
1193 * wodWrite [internal]
1196 static DWORD wodWrite(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
1198 TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
1200 /* first, do the sanity checks... */
1201 if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].unixdev == -1) {
1202 WARN("bad dev ID !\n");
1203 return MMSYSERR_BADDEVICEID;
1206 if (lpWaveHdr->lpData == NULL || !(lpWaveHdr->dwFlags & WHDR_PREPARED))
1207 return WAVERR_UNPREPARED;
1209 if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
1210 return WAVERR_STILLPLAYING;
1212 lpWaveHdr->dwFlags &= ~WHDR_DONE;
1213 lpWaveHdr->dwFlags |= WHDR_INQUEUE;
1214 lpWaveHdr->lpNext = 0;
1216 OSS_AddRingMessage(&WOutDev[wDevID].msgRing, WINE_WM_HEADER, (DWORD)lpWaveHdr, FALSE);
1218 return MMSYSERR_NOERROR;
1221 /**************************************************************************
1222 * wodPrepare [internal]
1224 static DWORD wodPrepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
1226 TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
1228 if (wDevID >= MAX_WAVEOUTDRV) {
1229 WARN("bad device ID !\n");
1230 return MMSYSERR_BADDEVICEID;
1233 if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
1234 return WAVERR_STILLPLAYING;
1236 lpWaveHdr->dwFlags |= WHDR_PREPARED;
1237 lpWaveHdr->dwFlags &= ~WHDR_DONE;
1238 return MMSYSERR_NOERROR;
1241 /**************************************************************************
1242 * wodUnprepare [internal]
1244 static DWORD wodUnprepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
1246 TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
1248 if (wDevID >= MAX_WAVEOUTDRV) {
1249 WARN("bad device ID !\n");
1250 return MMSYSERR_BADDEVICEID;
1253 if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
1254 return WAVERR_STILLPLAYING;
1256 lpWaveHdr->dwFlags &= ~WHDR_PREPARED;
1257 lpWaveHdr->dwFlags |= WHDR_DONE;
1259 return MMSYSERR_NOERROR;
1262 /**************************************************************************
1263 * wodPause [internal]
1265 static DWORD wodPause(WORD wDevID)
1267 TRACE("(%u);!\n", wDevID);
1269 if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].unixdev == -1) {
1270 WARN("bad device ID !\n");
1271 return MMSYSERR_BADDEVICEID;
1274 OSS_AddRingMessage(&WOutDev[wDevID].msgRing, WINE_WM_PAUSING, 0, TRUE);
1276 return MMSYSERR_NOERROR;
1279 /**************************************************************************
1280 * wodRestart [internal]
1282 static DWORD wodRestart(WORD wDevID)
1284 TRACE("(%u);\n", wDevID);
1286 if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].unixdev == -1) {
1287 WARN("bad device ID !\n");
1288 return MMSYSERR_BADDEVICEID;
1291 if (WOutDev[wDevID].state == WINE_WS_PAUSED) {
1292 OSS_AddRingMessage(&WOutDev[wDevID].msgRing, WINE_WM_RESTARTING, 0, TRUE);
1295 /* FIXME: is NotifyClient with WOM_DONE right ? (Comet Busters 1.3.3 needs this notification) */
1296 /* FIXME: Myst crashes with this ... hmm -MM
1297 return wodNotifyClient(wwo, WOM_DONE, 0L, 0L);
1300 return MMSYSERR_NOERROR;
1303 /**************************************************************************
1304 * wodReset [internal]
1306 static DWORD wodReset(WORD wDevID)
1308 TRACE("(%u);\n", wDevID);
1310 if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].unixdev == -1) {
1311 WARN("bad device ID !\n");
1312 return MMSYSERR_BADDEVICEID;
1315 OSS_AddRingMessage(&WOutDev[wDevID].msgRing, WINE_WM_RESETTING, 0, TRUE);
1317 return MMSYSERR_NOERROR;
1320 /**************************************************************************
1321 * wodGetPosition [internal]
1323 static DWORD wodGetPosition(WORD wDevID, LPMMTIME lpTime, DWORD uSize)
1329 TRACE("(%u, %p, %lu);\n", wDevID, lpTime, uSize);
1331 if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].unixdev == -1) {
1332 WARN("bad device ID !\n");
1333 return MMSYSERR_BADDEVICEID;
1336 if (lpTime == NULL) return MMSYSERR_INVALPARAM;
1338 wwo = &WOutDev[wDevID];
1339 OSS_AddRingMessage(&wwo->msgRing, WINE_WM_UPDATE, 0, TRUE);
1340 val = wwo->dwPlayedTotal;
1342 TRACE("wType=%04X wBitsPerSample=%u nSamplesPerSec=%lu nChannels=%u nAvgBytesPerSec=%lu\n",
1343 lpTime->wType, wwo->format.wBitsPerSample,
1344 wwo->format.wf.nSamplesPerSec, wwo->format.wf.nChannels,
1345 wwo->format.wf.nAvgBytesPerSec);
1346 TRACE("dwPlayedTotal=%lu\n", val);
1348 switch (lpTime->wType) {
1351 TRACE("TIME_BYTES=%lu\n", lpTime->u.cb);
1354 lpTime->u.sample = val * 8 / wwo->format.wBitsPerSample /wwo->format.wf.nChannels;
1355 TRACE("TIME_SAMPLES=%lu\n", lpTime->u.sample);
1358 time = val / (wwo->format.wf.nAvgBytesPerSec / 1000);
1359 lpTime->u.smpte.hour = time / 108000;
1360 time -= lpTime->u.smpte.hour * 108000;
1361 lpTime->u.smpte.min = time / 1800;
1362 time -= lpTime->u.smpte.min * 1800;
1363 lpTime->u.smpte.sec = time / 30;
1364 time -= lpTime->u.smpte.sec * 30;
1365 lpTime->u.smpte.frame = time;
1366 lpTime->u.smpte.fps = 30;
1367 TRACE("TIME_SMPTE=%02u:%02u:%02u:%02u\n",
1368 lpTime->u.smpte.hour, lpTime->u.smpte.min,
1369 lpTime->u.smpte.sec, lpTime->u.smpte.frame);
1372 FIXME("Format %d not supported ! use TIME_MS !\n", lpTime->wType);
1373 lpTime->wType = TIME_MS;
1375 lpTime->u.ms = val / (wwo->format.wf.nAvgBytesPerSec / 1000);
1376 TRACE("TIME_MS=%lu\n", lpTime->u.ms);
1379 return MMSYSERR_NOERROR;
1382 /**************************************************************************
1383 * wodBreakLoop [internal]
1385 static DWORD wodBreakLoop(WORD wDevID)
1387 TRACE("(%u);\n", wDevID);
1389 if (wDevID >= MAX_WAVEOUTDRV || WOutDev[wDevID].unixdev == -1) {
1390 WARN("bad device ID !\n");
1391 return MMSYSERR_BADDEVICEID;
1393 OSS_AddRingMessage(&WOutDev[wDevID].msgRing, WINE_WM_BREAKLOOP, 0, TRUE);
1394 return MMSYSERR_NOERROR;
1397 /**************************************************************************
1398 * wodGetVolume [internal]
1400 static DWORD wodGetVolume(WORD wDevID, LPDWORD lpdwVol)
1406 TRACE("(%u, %p);\n", wDevID, lpdwVol);
1408 if (lpdwVol == NULL)
1409 return MMSYSERR_NOTENABLED;
1410 if ((mixer = open(MIXER_DEV, O_RDONLY|O_NDELAY)) < 0) {
1411 WARN("mixer device not available !\n");
1412 return MMSYSERR_NOTENABLED;
1414 if (ioctl(mixer, SOUND_MIXER_READ_PCM, &volume) == -1) {
1415 WARN("unable to read mixer !\n");
1416 return MMSYSERR_NOTENABLED;
1419 left = LOBYTE(volume);
1420 right = HIBYTE(volume);
1421 TRACE("left=%ld right=%ld !\n", left, right);
1422 *lpdwVol = ((left * 0xFFFFl) / 100) + (((right * 0xFFFFl) / 100) << 16);
1423 return MMSYSERR_NOERROR;
1426 /**************************************************************************
1427 * wodSetVolume [internal]
1429 static DWORD wodSetVolume(WORD wDevID, DWORD dwParam)
1435 TRACE("(%u, %08lX);\n", wDevID, dwParam);
1437 left = (LOWORD(dwParam) * 100) / 0xFFFFl;
1438 right = (HIWORD(dwParam) * 100) / 0xFFFFl;
1439 volume = left + (right << 8);
1441 if ((mixer = open(MIXER_DEV, O_WRONLY|O_NDELAY)) < 0) {
1442 WARN("mixer device not available !\n");
1443 return MMSYSERR_NOTENABLED;
1445 if (ioctl(mixer, SOUND_MIXER_WRITE_PCM, &volume) == -1) {
1446 WARN("unable to set mixer !\n");
1447 return MMSYSERR_NOTENABLED;
1449 TRACE("volume=%04x\n", (unsigned)volume);
1452 return MMSYSERR_NOERROR;
1455 /**************************************************************************
1456 * wodGetNumDevs [internal]
1458 static DWORD wodGetNumDevs(void)
1461 /* FIXME: For now, only one sound device (SOUND_DEV) is allowed */
1462 int audio = OSS_OpenDevice(OSS_FullDuplex ? O_RDWR : O_WRONLY);
1468 OSS_CloseDevice(audio);
1473 /**************************************************************************
1474 * wodMessage (WINEOSS.7)
1476 DWORD WINAPI OSS_wodMessage(UINT wDevID, UINT wMsg, DWORD dwUser,
1477 DWORD dwParam1, DWORD dwParam2)
1479 TRACE("(%u, %04X, %08lX, %08lX, %08lX);\n",
1480 wDevID, wMsg, dwUser, dwParam1, dwParam2);
1487 /* FIXME: Pretend this is supported */
1489 case WODM_OPEN: return wodOpen (wDevID, (LPWAVEOPENDESC)dwParam1, dwParam2);
1490 case WODM_CLOSE: return wodClose (wDevID);
1491 case WODM_WRITE: return wodWrite (wDevID, (LPWAVEHDR)dwParam1, dwParam2);
1492 case WODM_PAUSE: return wodPause (wDevID);
1493 case WODM_GETPOS: return wodGetPosition (wDevID, (LPMMTIME)dwParam1, dwParam2);
1494 case WODM_BREAKLOOP: return wodBreakLoop (wDevID);
1495 case WODM_PREPARE: return wodPrepare (wDevID, (LPWAVEHDR)dwParam1, dwParam2);
1496 case WODM_UNPREPARE: return wodUnprepare (wDevID, (LPWAVEHDR)dwParam1, dwParam2);
1497 case WODM_GETDEVCAPS: return wodGetDevCaps (wDevID, (LPWAVEOUTCAPSA)dwParam1, dwParam2);
1498 case WODM_GETNUMDEVS: return wodGetNumDevs ();
1499 case WODM_GETPITCH: return MMSYSERR_NOTSUPPORTED;
1500 case WODM_SETPITCH: return MMSYSERR_NOTSUPPORTED;
1501 case WODM_GETPLAYBACKRATE: return MMSYSERR_NOTSUPPORTED;
1502 case WODM_SETPLAYBACKRATE: return MMSYSERR_NOTSUPPORTED;
1503 case WODM_GETVOLUME: return wodGetVolume (wDevID, (LPDWORD)dwParam1);
1504 case WODM_SETVOLUME: return wodSetVolume (wDevID, dwParam1);
1505 case WODM_RESTART: return wodRestart (wDevID);
1506 case WODM_RESET: return wodReset (wDevID);
1508 case DRV_QUERYDSOUNDIFACE: return wodDsCreate(wDevID, (PIDSDRIVER*)dwParam1);
1510 FIXME("unknown message %d!\n", wMsg);
1512 return MMSYSERR_NOTSUPPORTED;
1515 /*======================================================================*
1516 * Low level DSOUND implementation *
1517 *======================================================================*/
1519 typedef struct IDsDriverImpl IDsDriverImpl;
1520 typedef struct IDsDriverBufferImpl IDsDriverBufferImpl;
1522 struct IDsDriverImpl
1524 /* IUnknown fields */
1525 ICOM_VFIELD(IDsDriver);
1527 /* IDsDriverImpl fields */
1529 IDsDriverBufferImpl*primary;
1532 struct IDsDriverBufferImpl
1534 /* IUnknown fields */
1535 ICOM_VFIELD(IDsDriverBuffer);
1537 /* IDsDriverBufferImpl fields */
1542 static HRESULT DSDB_MapPrimary(IDsDriverBufferImpl *dsdb)
1544 WINE_WAVEOUT *wwo = &(WOutDev[dsdb->drv->wDevID]);
1545 if (!wwo->mapping) {
1546 wwo->mapping = mmap(NULL, wwo->maplen, PROT_WRITE, MAP_SHARED,
1548 if (wwo->mapping == (LPBYTE)-1) {
1549 ERR("(%p): Could not map sound device for direct access (%s)\n", dsdb, strerror(errno));
1550 return DSERR_GENERIC;
1552 TRACE("(%p): sound device has been mapped for direct access at %p, size=%ld\n", dsdb, wwo->mapping, wwo->maplen);
1554 /* for some reason, es1371 and sblive! sometimes have junk in here.
1555 * clear it, or we get junk noise */
1556 /* some libc implementations are buggy: their memset reads from the buffer...
1557 * to work around it, we have to zero the block by hand. We don't do the expected:
1558 * memset(wwo->mapping,0, wwo->maplen);
1561 char* p1 = wwo->mapping;
1562 unsigned len = wwo->maplen;
1564 if (len >= 16) /* so we can have at least a 4 long area to store... */
1566 /* the mmap:ed value is (at least) dword aligned
1567 * so, start filling the complete unsigned long:s
1570 unsigned long* p4 = (unsigned long*)p1;
1572 while (b--) *p4++ = 0;
1573 /* prepare for filling the rest */
1575 p1 = (unsigned char*)p4;
1577 /* in all cases, fill the remaining bytes */
1578 while (len-- != 0) *p1++ = 0;
1584 static HRESULT DSDB_UnmapPrimary(IDsDriverBufferImpl *dsdb)
1586 WINE_WAVEOUT *wwo = &(WOutDev[dsdb->drv->wDevID]);
1588 if (munmap(wwo->mapping, wwo->maplen) < 0) {
1589 ERR("(%p): Could not unmap sound device (errno=%d)\n", dsdb, errno);
1590 return DSERR_GENERIC;
1592 wwo->mapping = NULL;
1593 TRACE("(%p): sound device unmapped\n", dsdb);
1598 static HRESULT WINAPI IDsDriverBufferImpl_QueryInterface(PIDSDRIVERBUFFER iface, REFIID riid, LPVOID *ppobj)
1600 /* ICOM_THIS(IDsDriverBufferImpl,iface); */
1601 FIXME("(): stub!\n");
1602 return DSERR_UNSUPPORTED;
1605 static ULONG WINAPI IDsDriverBufferImpl_AddRef(PIDSDRIVERBUFFER iface)
1607 ICOM_THIS(IDsDriverBufferImpl,iface);
1612 static ULONG WINAPI IDsDriverBufferImpl_Release(PIDSDRIVERBUFFER iface)
1614 ICOM_THIS(IDsDriverBufferImpl,iface);
1617 if (This == This->drv->primary)
1618 This->drv->primary = NULL;
1619 DSDB_UnmapPrimary(This);
1620 HeapFree(GetProcessHeap(),0,This);
1624 static HRESULT WINAPI IDsDriverBufferImpl_Lock(PIDSDRIVERBUFFER iface,
1625 LPVOID*ppvAudio1,LPDWORD pdwLen1,
1626 LPVOID*ppvAudio2,LPDWORD pdwLen2,
1627 DWORD dwWritePosition,DWORD dwWriteLen,
1630 /* ICOM_THIS(IDsDriverBufferImpl,iface); */
1631 /* since we (GetDriverDesc flags) have specified DSDDESC_DONTNEEDPRIMARYLOCK,
1632 * and that we don't support secondary buffers, this method will never be called */
1633 TRACE("(%p): stub\n",iface);
1634 return DSERR_UNSUPPORTED;
1637 static HRESULT WINAPI IDsDriverBufferImpl_Unlock(PIDSDRIVERBUFFER iface,
1638 LPVOID pvAudio1,DWORD dwLen1,
1639 LPVOID pvAudio2,DWORD dwLen2)
1641 /* ICOM_THIS(IDsDriverBufferImpl,iface); */
1642 TRACE("(%p): stub\n",iface);
1643 return DSERR_UNSUPPORTED;
1646 static HRESULT WINAPI IDsDriverBufferImpl_SetFormat(PIDSDRIVERBUFFER iface,
1647 LPWAVEFORMATEX pwfx)
1649 /* ICOM_THIS(IDsDriverBufferImpl,iface); */
1651 TRACE("(%p,%p)\n",iface,pwfx);
1652 /* On our request (GetDriverDesc flags), DirectSound has by now used
1653 * waveOutClose/waveOutOpen to set the format...
1654 * unfortunately, this means our mmap() is now gone...
1655 * so we need to somehow signal to our DirectSound implementation
1656 * that it should completely recreate this HW buffer...
1657 * this unexpected error code should do the trick... */
1658 return DSERR_BUFFERLOST;
1661 static HRESULT WINAPI IDsDriverBufferImpl_SetFrequency(PIDSDRIVERBUFFER iface, DWORD dwFreq)
1663 /* ICOM_THIS(IDsDriverBufferImpl,iface); */
1664 TRACE("(%p,%ld): stub\n",iface,dwFreq);
1665 return DSERR_UNSUPPORTED;
1668 static HRESULT WINAPI IDsDriverBufferImpl_SetVolumePan(PIDSDRIVERBUFFER iface, PDSVOLUMEPAN pVolPan)
1670 /* ICOM_THIS(IDsDriverBufferImpl,iface); */
1671 FIXME("(%p,%p): stub!\n",iface,pVolPan);
1672 return DSERR_UNSUPPORTED;
1675 static HRESULT WINAPI IDsDriverBufferImpl_SetPosition(PIDSDRIVERBUFFER iface, DWORD dwNewPos)
1677 /* ICOM_THIS(IDsDriverImpl,iface); */
1678 TRACE("(%p,%ld): stub\n",iface,dwNewPos);
1679 return DSERR_UNSUPPORTED;
1682 static HRESULT WINAPI IDsDriverBufferImpl_GetPosition(PIDSDRIVERBUFFER iface,
1683 LPDWORD lpdwPlay, LPDWORD lpdwWrite)
1685 ICOM_THIS(IDsDriverBufferImpl,iface);
1689 TRACE("(%p)\n",iface);
1690 if (WOutDev[This->drv->wDevID].unixdev == -1) {
1691 ERR("device not open, but accessing?\n");
1692 return DSERR_UNINITIALIZED;
1694 if (ioctl(WOutDev[This->drv->wDevID].unixdev, SNDCTL_DSP_GETOPTR, &info) < 0) {
1695 ERR("ioctl failed (%d)\n", errno);
1696 return DSERR_GENERIC;
1698 ptr = info.ptr & ~3; /* align the pointer, just in case */
1699 if (lpdwPlay) *lpdwPlay = ptr;
1701 /* add some safety margin (not strictly necessary, but...) */
1702 if (WOutDev[This->drv->wDevID].caps.dwSupport & WAVECAPS_SAMPLEACCURATE)
1703 *lpdwWrite = ptr + 32;
1705 *lpdwWrite = ptr + WOutDev[This->drv->wDevID].dwFragmentSize;
1706 while (*lpdwWrite > This->buflen)
1707 *lpdwWrite -= This->buflen;
1709 TRACE("playpos=%ld, writepos=%ld\n", lpdwPlay?*lpdwPlay:0, lpdwWrite?*lpdwWrite:0);
1713 static HRESULT WINAPI IDsDriverBufferImpl_Play(PIDSDRIVERBUFFER iface, DWORD dwRes1, DWORD dwRes2, DWORD dwFlags)
1715 ICOM_THIS(IDsDriverBufferImpl,iface);
1716 int enable = PCM_ENABLE_OUTPUT;
1717 TRACE("(%p,%lx,%lx,%lx)\n",iface,dwRes1,dwRes2,dwFlags);
1718 if (ioctl(WOutDev[This->drv->wDevID].unixdev, SNDCTL_DSP_SETTRIGGER, &enable) < 0) {
1719 ERR("ioctl failed (%d)\n", errno);
1720 return DSERR_GENERIC;
1725 static HRESULT WINAPI IDsDriverBufferImpl_Stop(PIDSDRIVERBUFFER iface)
1727 ICOM_THIS(IDsDriverBufferImpl,iface);
1729 TRACE("(%p)\n",iface);
1730 /* no more playing */
1731 if (ioctl(WOutDev[This->drv->wDevID].unixdev, SNDCTL_DSP_SETTRIGGER, &enable) < 0) {
1732 ERR("ioctl failed (%d)\n", errno);
1733 return DSERR_GENERIC;
1736 /* the play position must be reset to the beginning of the buffer */
1737 if (ioctl(WOutDev[This->drv->wDevID].unixdev, SNDCTL_DSP_RESET, 0) < 0) {
1738 ERR("ioctl failed (%d)\n", errno);
1739 return DSERR_GENERIC;
1742 /* Most OSS drivers just can't stop the playback without closing the device...
1743 * so we need to somehow signal to our DirectSound implementation
1744 * that it should completely recreate this HW buffer...
1745 * this unexpected error code should do the trick... */
1746 return DSERR_BUFFERLOST;
1749 static ICOM_VTABLE(IDsDriverBuffer) dsdbvt =
1751 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1752 IDsDriverBufferImpl_QueryInterface,
1753 IDsDriverBufferImpl_AddRef,
1754 IDsDriverBufferImpl_Release,
1755 IDsDriverBufferImpl_Lock,
1756 IDsDriverBufferImpl_Unlock,
1757 IDsDriverBufferImpl_SetFormat,
1758 IDsDriverBufferImpl_SetFrequency,
1759 IDsDriverBufferImpl_SetVolumePan,
1760 IDsDriverBufferImpl_SetPosition,
1761 IDsDriverBufferImpl_GetPosition,
1762 IDsDriverBufferImpl_Play,
1763 IDsDriverBufferImpl_Stop
1766 static HRESULT WINAPI IDsDriverImpl_QueryInterface(PIDSDRIVER iface, REFIID riid, LPVOID *ppobj)
1768 /* ICOM_THIS(IDsDriverImpl,iface); */
1769 FIXME("(%p): stub!\n",iface);
1770 return DSERR_UNSUPPORTED;
1773 static ULONG WINAPI IDsDriverImpl_AddRef(PIDSDRIVER iface)
1775 ICOM_THIS(IDsDriverImpl,iface);
1780 static ULONG WINAPI IDsDriverImpl_Release(PIDSDRIVER iface)
1782 ICOM_THIS(IDsDriverImpl,iface);
1785 HeapFree(GetProcessHeap(),0,This);
1789 static HRESULT WINAPI IDsDriverImpl_GetDriverDesc(PIDSDRIVER iface, PDSDRIVERDESC pDesc)
1791 ICOM_THIS(IDsDriverImpl,iface);
1792 TRACE("(%p,%p)\n",iface,pDesc);
1793 pDesc->dwFlags = DSDDESC_DOMMSYSTEMOPEN | DSDDESC_DOMMSYSTEMSETFORMAT |
1794 DSDDESC_USESYSTEMMEMORY | DSDDESC_DONTNEEDPRIMARYLOCK;
1795 strcpy(pDesc->szDesc,"WineOSS DirectSound Driver");
1796 strcpy(pDesc->szDrvName,"wineoss.drv");
1797 pDesc->dnDevNode = WOutDev[This->wDevID].waveDesc.dnDevNode;
1799 pDesc->wReserved = 0;
1800 pDesc->ulDeviceNum = This->wDevID;
1801 pDesc->dwHeapType = DSDHEAP_NOHEAP;
1802 pDesc->pvDirectDrawHeap = NULL;
1803 pDesc->dwMemStartAddress = 0;
1804 pDesc->dwMemEndAddress = 0;
1805 pDesc->dwMemAllocExtra = 0;
1806 pDesc->pvReserved1 = NULL;
1807 pDesc->pvReserved2 = NULL;
1811 static HRESULT WINAPI IDsDriverImpl_Open(PIDSDRIVER iface)
1813 ICOM_THIS(IDsDriverImpl,iface);
1816 TRACE("(%p)\n",iface);
1817 /* make sure the card doesn't start playing before we want it to */
1818 if (ioctl(WOutDev[This->wDevID].unixdev, SNDCTL_DSP_SETTRIGGER, &enable) < 0) {
1819 ERR("ioctl failed (%d)\n", errno);
1820 return DSERR_GENERIC;
1825 static HRESULT WINAPI IDsDriverImpl_Close(PIDSDRIVER iface)
1827 ICOM_THIS(IDsDriverImpl,iface);
1828 TRACE("(%p)\n",iface);
1829 if (This->primary) {
1830 ERR("problem with DirectSound: primary not released\n");
1831 return DSERR_GENERIC;
1836 static HRESULT WINAPI IDsDriverImpl_GetCaps(PIDSDRIVER iface, PDSDRIVERCAPS pCaps)
1838 /* ICOM_THIS(IDsDriverImpl,iface); */
1839 TRACE("(%p,%p)\n",iface,pCaps);
1840 memset(pCaps, 0, sizeof(*pCaps));
1841 /* FIXME: need to check actual capabilities */
1842 pCaps->dwFlags = DSCAPS_PRIMARYMONO | DSCAPS_PRIMARYSTEREO |
1843 DSCAPS_PRIMARY8BIT | DSCAPS_PRIMARY16BIT;
1844 pCaps->dwPrimaryBuffers = 1;
1845 /* the other fields only apply to secondary buffers, which we don't support
1846 * (unless we want to mess with wavetable synthesizers and MIDI) */
1850 static HRESULT WINAPI IDsDriverImpl_CreateSoundBuffer(PIDSDRIVER iface,
1851 LPWAVEFORMATEX pwfx,
1852 DWORD dwFlags, DWORD dwCardAddress,
1853 LPDWORD pdwcbBufferSize,
1857 ICOM_THIS(IDsDriverImpl,iface);
1858 IDsDriverBufferImpl** ippdsdb = (IDsDriverBufferImpl**)ppvObj;
1860 audio_buf_info info;
1863 TRACE("(%p,%p,%lx,%lx)\n",iface,pwfx,dwFlags,dwCardAddress);
1864 /* we only support primary buffers */
1865 if (!(dwFlags & DSBCAPS_PRIMARYBUFFER))
1866 return DSERR_UNSUPPORTED;
1868 return DSERR_ALLOCATED;
1869 if (dwFlags & (DSBCAPS_CTRLFREQUENCY | DSBCAPS_CTRLPAN))
1870 return DSERR_CONTROLUNAVAIL;
1872 *ippdsdb = (IDsDriverBufferImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDsDriverBufferImpl));
1873 if (*ippdsdb == NULL)
1874 return DSERR_OUTOFMEMORY;
1875 ICOM_VTBL(*ippdsdb) = &dsdbvt;
1876 (*ippdsdb)->ref = 1;
1877 (*ippdsdb)->drv = This;
1879 /* check how big the DMA buffer is now */
1880 if (ioctl(WOutDev[This->wDevID].unixdev, SNDCTL_DSP_GETOSPACE, &info) < 0) {
1881 ERR("ioctl failed (%d)\n", errno);
1882 HeapFree(GetProcessHeap(),0,*ippdsdb);
1884 return DSERR_GENERIC;
1886 WOutDev[This->wDevID].maplen = (*ippdsdb)->buflen = info.fragstotal * info.fragsize;
1888 /* map the DMA buffer */
1889 err = DSDB_MapPrimary(*ippdsdb);
1891 HeapFree(GetProcessHeap(),0,*ippdsdb);
1896 /* primary buffer is ready to go */
1897 *pdwcbBufferSize = WOutDev[This->wDevID].maplen;
1898 *ppbBuffer = WOutDev[This->wDevID].mapping;
1900 /* some drivers need some extra nudging after mapping */
1901 if (ioctl(WOutDev[This->wDevID].unixdev, SNDCTL_DSP_SETTRIGGER, &enable) < 0) {
1902 ERR("ioctl failed (%d)\n", errno);
1903 return DSERR_GENERIC;
1906 This->primary = *ippdsdb;
1911 static HRESULT WINAPI IDsDriverImpl_DuplicateSoundBuffer(PIDSDRIVER iface,
1912 PIDSDRIVERBUFFER pBuffer,
1915 /* ICOM_THIS(IDsDriverImpl,iface); */
1916 TRACE("(%p,%p): stub\n",iface,pBuffer);
1917 return DSERR_INVALIDCALL;
1920 static ICOM_VTABLE(IDsDriver) dsdvt =
1922 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
1923 IDsDriverImpl_QueryInterface,
1924 IDsDriverImpl_AddRef,
1925 IDsDriverImpl_Release,
1926 IDsDriverImpl_GetDriverDesc,
1928 IDsDriverImpl_Close,
1929 IDsDriverImpl_GetCaps,
1930 IDsDriverImpl_CreateSoundBuffer,
1931 IDsDriverImpl_DuplicateSoundBuffer
1934 static DWORD wodDsCreate(UINT wDevID, PIDSDRIVER* drv)
1936 IDsDriverImpl** idrv = (IDsDriverImpl**)drv;
1938 /* the HAL isn't much better than the HEL if we can't do mmap() */
1939 if (!(WOutDev[wDevID].caps.dwSupport & WAVECAPS_DIRECTSOUND)) {
1940 ERR("DirectSound flag not set\n");
1941 MESSAGE("This sound card's driver does not support direct access\n");
1942 MESSAGE("The (slower) DirectSound HEL mode will be used instead.\n");
1943 return MMSYSERR_NOTSUPPORTED;
1946 *idrv = (IDsDriverImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IDsDriverImpl));
1948 return MMSYSERR_NOMEM;
1949 ICOM_VTBL(*idrv) = &dsdvt;
1952 (*idrv)->wDevID = wDevID;
1953 (*idrv)->primary = NULL;
1954 return MMSYSERR_NOERROR;
1957 /*======================================================================*
1958 * Low level WAVE IN implementation *
1959 *======================================================================*/
1961 /**************************************************************************
1962 * widNotifyClient [internal]
1964 static DWORD widNotifyClient(WINE_WAVEIN* wwi, WORD wMsg, DWORD dwParam1, DWORD dwParam2)
1966 TRACE("wMsg = 0x%04x dwParm1 = %04lX dwParam2 = %04lX\n", wMsg, dwParam1, dwParam2);
1972 if (wwi->wFlags != DCB_NULL &&
1973 !DriverCallback(wwi->waveDesc.dwCallback, wwi->wFlags, wwi->waveDesc.hWave,
1974 wMsg, wwi->waveDesc.dwInstance, dwParam1, dwParam2)) {
1975 WARN("can't notify client !\n");
1976 return MMSYSERR_ERROR;
1980 FIXME("Unknown callback message %u\n", wMsg);
1981 return MMSYSERR_INVALPARAM;
1983 return MMSYSERR_NOERROR;
1986 /**************************************************************************
1987 * widGetDevCaps [internal]
1989 static DWORD widGetDevCaps(WORD wDevID, LPWAVEINCAPSA lpCaps, DWORD dwSize)
1991 TRACE("(%u, %p, %lu);\n", wDevID, lpCaps, dwSize);
1993 if (lpCaps == NULL) return MMSYSERR_NOTENABLED;
1995 if (wDevID >= MAX_WAVEINDRV) {
1996 TRACE("MAX_WAVINDRV reached !\n");
1997 return MMSYSERR_BADDEVICEID;
2000 memcpy(lpCaps, &WInDev[wDevID].caps, min(dwSize, sizeof(*lpCaps)));
2001 return MMSYSERR_NOERROR;
2004 /**************************************************************************
2005 * widRecorder [internal]
2007 static DWORD CALLBACK widRecorder(LPVOID pmt)
2009 WORD uDevID = (DWORD)pmt;
2010 WINE_WAVEIN* wwi = (WINE_WAVEIN*)&WInDev[uDevID];
2014 LPVOID buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, wwi->dwFragmentSize);
2015 LPVOID pOffset = buffer;
2016 audio_buf_info info;
2018 enum win_wm_message msg;
2022 wwi->state = WINE_WS_STOPPED;
2023 wwi->dwTotalRecorded = 0;
2025 SetEvent(wwi->hStartUpEvent);
2027 /* the soundblaster live needs a micro wake to get its recording started
2028 * (or GETISPACE will have 0 frags all the time)
2030 read(wwi->unixdev,&xs,4);
2032 /* make sleep time to be # of ms to output a fragment */
2033 dwSleepTime = (wwi->dwFragmentSize * 1000) / wwi->format.wf.nAvgBytesPerSec;
2034 TRACE("sleeptime=%ld ms\n", dwSleepTime);
2037 /* wait for dwSleepTime or an event in thread's queue */
2038 /* FIXME: could improve wait time depending on queue state,
2039 * ie, number of queued fragments
2042 if (wwi->lpQueuePtr != NULL && wwi->state == WINE_WS_PLAYING)
2044 lpWaveHdr = wwi->lpQueuePtr;
2046 ioctl(wwi->unixdev, SNDCTL_DSP_GETISPACE, &info);
2047 TRACE("info={frag=%d fsize=%d ftotal=%d bytes=%d}\n", info.fragments, info.fragsize, info.fragstotal, info.bytes);
2049 /* read all the fragments accumulated so far */
2050 while ((info.fragments > 0) && (wwi->lpQueuePtr))
2054 if (lpWaveHdr->dwBufferLength - lpWaveHdr->dwBytesRecorded >= wwi->dwFragmentSize)
2056 /* directly read fragment in wavehdr */
2057 bytesRead = read(wwi->unixdev,
2058 lpWaveHdr->lpData + lpWaveHdr->dwBytesRecorded,
2059 wwi->dwFragmentSize);
2061 TRACE("bytesRead=%ld (direct)\n", bytesRead);
2062 if (bytesRead != (DWORD) -1)
2064 /* update number of bytes recorded in current buffer and by this device */
2065 lpWaveHdr->dwBytesRecorded += bytesRead;
2066 wwi->dwTotalRecorded += bytesRead;
2068 /* buffer is full. notify client */
2069 if (lpWaveHdr->dwBytesRecorded == lpWaveHdr->dwBufferLength)
2071 /* must copy the value of next waveHdr, because we have no idea of what
2072 * will be done with the content of lpWaveHdr in callback
2074 LPWAVEHDR lpNext = lpWaveHdr->lpNext;
2076 lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
2077 lpWaveHdr->dwFlags |= WHDR_DONE;
2079 widNotifyClient(wwi, WIM_DATA, (DWORD)lpWaveHdr, 0);
2080 lpWaveHdr = wwi->lpQueuePtr = lpNext;
2086 /* read the fragment in a local buffer */
2087 bytesRead = read(wwi->unixdev, buffer, wwi->dwFragmentSize);
2090 TRACE("bytesRead=%ld (local)\n", bytesRead);
2092 /* copy data in client buffers */
2093 while (bytesRead != (DWORD) -1 && bytesRead > 0)
2095 DWORD dwToCopy = min (bytesRead, lpWaveHdr->dwBufferLength - lpWaveHdr->dwBytesRecorded);
2097 memcpy(lpWaveHdr->lpData + lpWaveHdr->dwBytesRecorded,
2101 /* update number of bytes recorded in current buffer and by this device */
2102 lpWaveHdr->dwBytesRecorded += dwToCopy;
2103 wwi->dwTotalRecorded += dwToCopy;
2104 bytesRead -= dwToCopy;
2105 pOffset += dwToCopy;
2107 /* client buffer is full. notify client */
2108 if (lpWaveHdr->dwBytesRecorded == lpWaveHdr->dwBufferLength)
2110 /* must copy the value of next waveHdr, because we have no idea of what
2111 * will be done with the content of lpWaveHdr in callback
2113 LPWAVEHDR lpNext = lpWaveHdr->lpNext;
2114 TRACE("lpNext=%p\n", lpNext);
2116 lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
2117 lpWaveHdr->dwFlags |= WHDR_DONE;
2119 widNotifyClient(wwi, WIM_DATA, (DWORD)lpWaveHdr, 0);
2121 wwi->lpQueuePtr = lpWaveHdr = lpNext;
2122 if (!lpNext && bytesRead) {
2123 /* no more buffer to copy data to, but we did read more.
2124 * what hasn't been copied will be dropped
2126 WARN("buffer under run! %lu bytes dropped.\n", bytesRead);
2127 wwi->lpQueuePtr = NULL;
2136 WaitForSingleObject(wwi->msgRing.msg_event, dwSleepTime);
2138 while (OSS_RetrieveRingMessage(&wwi->msgRing, &msg, ¶m, &ev))
2141 TRACE("msg=0x%x param=0x%lx\n", msg, param);
2143 case WINE_WM_PAUSING:
2144 wwi->state = WINE_WS_PAUSED;
2145 /*FIXME("Device should stop recording\n");*/
2148 case WINE_WM_RESTARTING:
2150 int enable = PCM_ENABLE_INPUT;
2151 wwi->state = WINE_WS_PLAYING;
2153 if (wwi->bTriggerSupport)
2155 /* start the recording */
2156 if (ioctl(wwi->unixdev, SNDCTL_DSP_SETTRIGGER, &enable) < 0)
2158 ERR("ioctl(SNDCTL_DSP_SETTRIGGER) failed (%d)\n", errno);
2163 unsigned char data[4];
2164 /* read 4 bytes to start the recording */
2165 read(wwi->unixdev, data, 4);
2171 case WINE_WM_HEADER:
2172 lpWaveHdr = (LPWAVEHDR)param;
2173 lpWaveHdr->lpNext = 0;
2175 /* insert buffer at the end of queue */
2178 for (wh = &(wwi->lpQueuePtr); *wh; wh = &((*wh)->lpNext));
2182 case WINE_WM_RESETTING:
2183 wwi->state = WINE_WS_STOPPED;
2184 /* return all buffers to the app */
2185 for (lpWaveHdr = wwi->lpQueuePtr; lpWaveHdr; lpWaveHdr = lpWaveHdr->lpNext) {
2186 TRACE("reset %p %p\n", lpWaveHdr, lpWaveHdr->lpNext);
2187 lpWaveHdr->dwFlags &= ~WHDR_INQUEUE;
2188 lpWaveHdr->dwFlags |= WHDR_DONE;
2190 widNotifyClient(wwi, WIM_DATA, (DWORD)lpWaveHdr, 0);
2192 wwi->lpQueuePtr = NULL;
2195 case WINE_WM_CLOSING:
2197 wwi->state = WINE_WS_CLOSED;
2199 HeapFree(GetProcessHeap(), 0, buffer);
2201 /* shouldn't go here */
2203 FIXME("unknown message %d\n", msg);
2209 /* just for not generating compilation warnings... should never be executed */
2214 /**************************************************************************
2215 * widOpen [internal]
2217 static DWORD widOpen(WORD wDevID, LPWAVEOPENDESC lpDesc, DWORD dwFlags)
2226 TRACE("(%u, %p, %08lX);\n", wDevID, lpDesc, dwFlags);
2227 if (lpDesc == NULL) {
2228 WARN("Invalid Parameter !\n");
2229 return MMSYSERR_INVALPARAM;
2231 if (wDevID >= MAX_WAVEINDRV) return MMSYSERR_BADDEVICEID;
2233 /* only PCM format is supported so far... */
2234 if (lpDesc->lpFormat->wFormatTag != WAVE_FORMAT_PCM ||
2235 lpDesc->lpFormat->nChannels == 0 ||
2236 lpDesc->lpFormat->nSamplesPerSec == 0) {
2237 WARN("Bad format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
2238 lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
2239 lpDesc->lpFormat->nSamplesPerSec);
2240 return WAVERR_BADFORMAT;
2243 if (dwFlags & WAVE_FORMAT_QUERY) {
2244 TRACE("Query format: tag=%04X nChannels=%d nSamplesPerSec=%ld !\n",
2245 lpDesc->lpFormat->wFormatTag, lpDesc->lpFormat->nChannels,
2246 lpDesc->lpFormat->nSamplesPerSec);
2247 return MMSYSERR_NOERROR;
2250 wwi = &WInDev[wDevID];
2251 if ((wwi->unixdev = OSS_OpenDevice(OSS_FullDuplex ? O_RDWR : O_RDONLY)) == -1)
2252 return MMSYSERR_ALLOCATED;
2253 fcntl(wwi->unixdev, F_SETFD, 1); /* set close on exec flag */
2254 if (wwi->lpQueuePtr) {
2255 WARN("Should have an empty queue (%p)\n", wwi->lpQueuePtr);
2256 wwi->lpQueuePtr = NULL;
2258 wwi->dwTotalRecorded = 0;
2259 wwi->wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
2261 memcpy(&wwi->waveDesc, lpDesc, sizeof(WAVEOPENDESC));
2262 memcpy(&wwi->format, lpDesc->lpFormat, sizeof(PCMWAVEFORMAT));
2264 if (wwi->format.wBitsPerSample == 0) {
2265 WARN("Resetting zeroed wBitsPerSample\n");
2266 wwi->format.wBitsPerSample = 8 *
2267 (wwi->format.wf.nAvgBytesPerSec /
2268 wwi->format.wf.nSamplesPerSec) /
2269 wwi->format.wf.nChannels;
2272 sample_rate = wwi->format.wf.nSamplesPerSec;
2273 dsp_stereo = (wwi->format.wf.nChannels > 1) ? TRUE : FALSE;
2274 format = (wwi->format.wBitsPerSample == 16) ? AFMT_S16_LE : AFMT_U8;
2276 IOCTL(wwi->unixdev, SNDCTL_DSP_SETFMT, format);
2277 IOCTL(wwi->unixdev, SNDCTL_DSP_STEREO, dsp_stereo);
2278 IOCTL(wwi->unixdev, SNDCTL_DSP_SPEED, sample_rate);
2280 /* This is actually hand tuned to work so that my SB Live:
2282 * - does not buffer too much
2283 * when sending with the Shoutcast winamp plugin
2285 /* 7 fragments max, 2^10 = 1024 bytes per fragment */
2286 audio_fragment = 0x0007000A;
2287 IOCTL(wwi->unixdev, SNDCTL_DSP_SETFRAGMENT, audio_fragment);
2289 /* paranoid checks */
2290 if (format != ((wwi->format.wBitsPerSample == 16) ? AFMT_S16_LE : AFMT_U8))
2291 ERR("Can't set format to %d (%d)\n",
2292 (wwi->format.wBitsPerSample == 16) ? AFMT_S16_LE : AFMT_U8, format);
2293 if (dsp_stereo != (wwi->format.wf.nChannels > 1) ? 1 : 0)
2294 ERR("Can't set stereo to %u (%d)\n",
2295 (wwi->format.wf.nChannels > 1) ? 1 : 0, dsp_stereo);
2296 if (!NEAR_MATCH(sample_rate, wwi->format.wf.nSamplesPerSec))
2297 ERR("Can't set sample_rate to %lu (%d)\n",
2298 wwi->format.wf.nSamplesPerSec, sample_rate);
2300 IOCTL(wwi->unixdev, SNDCTL_DSP_GETBLKSIZE, fragment_size);
2301 if (fragment_size == -1) {
2302 WARN("IOCTL can't 'SNDCTL_DSP_GETBLKSIZE' !\n");
2303 OSS_CloseDevice(wwi->unixdev);
2305 return MMSYSERR_NOTENABLED;
2307 wwi->dwFragmentSize = fragment_size;
2309 TRACE("wBitsPerSample=%u, nAvgBytesPerSec=%lu, nSamplesPerSec=%lu, nChannels=%u nBlockAlign=%u!\n",
2310 wwi->format.wBitsPerSample, wwi->format.wf.nAvgBytesPerSec,
2311 wwi->format.wf.nSamplesPerSec, wwi->format.wf.nChannels,
2312 wwi->format.wf.nBlockAlign);
2314 OSS_InitRingMessage(&wwi->msgRing);
2316 wwi->hStartUpEvent = CreateEventA(NULL, FALSE, FALSE, NULL);
2317 wwi->hThread = CreateThread(NULL, 0, widRecorder, (LPVOID)(DWORD)wDevID, 0, &(wwi->dwThreadID));
2318 WaitForSingleObject(wwi->hStartUpEvent, INFINITE);
2319 CloseHandle(wwi->hStartUpEvent);
2320 wwi->hStartUpEvent = INVALID_HANDLE_VALUE;
2322 return widNotifyClient(wwi, WIM_OPEN, 0L, 0L);
2325 /**************************************************************************
2326 * widClose [internal]
2328 static DWORD widClose(WORD wDevID)
2332 TRACE("(%u);\n", wDevID);
2333 if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].unixdev == -1) {
2334 WARN("can't close !\n");
2335 return MMSYSERR_INVALHANDLE;
2338 wwi = &WInDev[wDevID];
2340 if (wwi->lpQueuePtr != NULL) {
2341 WARN("still buffers open !\n");
2342 return WAVERR_STILLPLAYING;
2345 OSS_AddRingMessage(&wwi->msgRing, WINE_WM_CLOSING, 0, TRUE);
2346 OSS_CloseDevice(wwi->unixdev);
2348 wwi->dwFragmentSize = 0;
2349 OSS_DestroyRingMessage(&wwi->msgRing);
2350 return widNotifyClient(wwi, WIM_CLOSE, 0L, 0L);
2353 /**************************************************************************
2354 * widAddBuffer [internal]
2356 static DWORD widAddBuffer(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
2358 TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
2360 if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].unixdev == -1) {
2361 WARN("can't do it !\n");
2362 return MMSYSERR_INVALHANDLE;
2364 if (!(lpWaveHdr->dwFlags & WHDR_PREPARED)) {
2365 TRACE("never been prepared !\n");
2366 return WAVERR_UNPREPARED;
2368 if (lpWaveHdr->dwFlags & WHDR_INQUEUE) {
2369 TRACE("header already in use !\n");
2370 return WAVERR_STILLPLAYING;
2373 lpWaveHdr->dwFlags |= WHDR_INQUEUE;
2374 lpWaveHdr->dwFlags &= ~WHDR_DONE;
2375 lpWaveHdr->dwBytesRecorded = 0;
2376 lpWaveHdr->lpNext = NULL;
2378 OSS_AddRingMessage(&WInDev[wDevID].msgRing, WINE_WM_HEADER, (DWORD)lpWaveHdr, FALSE);
2379 return MMSYSERR_NOERROR;
2382 /**************************************************************************
2383 * widPrepare [internal]
2385 static DWORD widPrepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
2387 TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
2389 if (wDevID >= MAX_WAVEINDRV) return MMSYSERR_INVALHANDLE;
2391 if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
2392 return WAVERR_STILLPLAYING;
2394 lpWaveHdr->dwFlags |= WHDR_PREPARED;
2395 lpWaveHdr->dwFlags &= ~WHDR_DONE;
2396 lpWaveHdr->dwBytesRecorded = 0;
2397 TRACE("header prepared !\n");
2398 return MMSYSERR_NOERROR;
2401 /**************************************************************************
2402 * widUnprepare [internal]
2404 static DWORD widUnprepare(WORD wDevID, LPWAVEHDR lpWaveHdr, DWORD dwSize)
2406 TRACE("(%u, %p, %08lX);\n", wDevID, lpWaveHdr, dwSize);
2407 if (wDevID >= MAX_WAVEINDRV) return MMSYSERR_INVALHANDLE;
2409 if (lpWaveHdr->dwFlags & WHDR_INQUEUE)
2410 return WAVERR_STILLPLAYING;
2412 lpWaveHdr->dwFlags &= ~WHDR_PREPARED;
2413 lpWaveHdr->dwFlags |= WHDR_DONE;
2415 return MMSYSERR_NOERROR;
2418 /**************************************************************************
2419 * widStart [internal]
2421 static DWORD widStart(WORD wDevID)
2423 TRACE("(%u);\n", wDevID);
2424 if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].unixdev == -1) {
2425 WARN("can't start recording !\n");
2426 return MMSYSERR_INVALHANDLE;
2429 OSS_AddRingMessage(&WInDev[wDevID].msgRing, WINE_WM_RESTARTING, 0, TRUE);
2430 return MMSYSERR_NOERROR;
2433 /**************************************************************************
2434 * widStop [internal]
2436 static DWORD widStop(WORD wDevID)
2438 TRACE("(%u);\n", wDevID);
2439 if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].unixdev == -1) {
2440 WARN("can't stop !\n");
2441 return MMSYSERR_INVALHANDLE;
2443 /* FIXME: reset aint stop */
2444 OSS_AddRingMessage(&WInDev[wDevID].msgRing, WINE_WM_RESETTING, 0, TRUE);
2446 return MMSYSERR_NOERROR;
2449 /**************************************************************************
2450 * widReset [internal]
2452 static DWORD widReset(WORD wDevID)
2454 TRACE("(%u);\n", wDevID);
2455 if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].unixdev == -1) {
2456 WARN("can't reset !\n");
2457 return MMSYSERR_INVALHANDLE;
2459 OSS_AddRingMessage(&WInDev[wDevID].msgRing, WINE_WM_RESETTING, 0, TRUE);
2460 return MMSYSERR_NOERROR;
2463 /**************************************************************************
2464 * widGetPosition [internal]
2466 static DWORD widGetPosition(WORD wDevID, LPMMTIME lpTime, DWORD uSize)
2471 TRACE("(%u, %p, %lu);\n", wDevID, lpTime, uSize);
2473 if (wDevID >= MAX_WAVEINDRV || WInDev[wDevID].unixdev == -1) {
2474 WARN("can't get pos !\n");
2475 return MMSYSERR_INVALHANDLE;
2477 if (lpTime == NULL) return MMSYSERR_INVALPARAM;
2479 wwi = &WInDev[wDevID];
2481 TRACE("wType=%04X !\n", lpTime->wType);
2482 TRACE("wBitsPerSample=%u\n", wwi->format.wBitsPerSample);
2483 TRACE("nSamplesPerSec=%lu\n", wwi->format.wf.nSamplesPerSec);
2484 TRACE("nChannels=%u\n", wwi->format.wf.nChannels);
2485 TRACE("nAvgBytesPerSec=%lu\n", wwi->format.wf.nAvgBytesPerSec);
2486 switch (lpTime->wType) {
2488 lpTime->u.cb = wwi->dwTotalRecorded;
2489 TRACE("TIME_BYTES=%lu\n", lpTime->u.cb);
2492 lpTime->u.sample = wwi->dwTotalRecorded * 8 /
2493 wwi->format.wBitsPerSample;
2494 TRACE("TIME_SAMPLES=%lu\n", lpTime->u.sample);
2497 time = wwi->dwTotalRecorded /
2498 (wwi->format.wf.nAvgBytesPerSec / 1000);
2499 lpTime->u.smpte.hour = time / 108000;
2500 time -= lpTime->u.smpte.hour * 108000;
2501 lpTime->u.smpte.min = time / 1800;
2502 time -= lpTime->u.smpte.min * 1800;
2503 lpTime->u.smpte.sec = time / 30;
2504 time -= lpTime->u.smpte.sec * 30;
2505 lpTime->u.smpte.frame = time;
2506 lpTime->u.smpte.fps = 30;
2507 TRACE("TIME_SMPTE=%02u:%02u:%02u:%02u\n",
2508 lpTime->u.smpte.hour, lpTime->u.smpte.min,
2509 lpTime->u.smpte.sec, lpTime->u.smpte.frame);
2512 lpTime->u.ms = wwi->dwTotalRecorded /
2513 (wwi->format.wf.nAvgBytesPerSec / 1000);
2514 TRACE("TIME_MS=%lu\n", lpTime->u.ms);
2517 FIXME("format not supported (%u) ! use TIME_MS !\n", lpTime->wType);
2518 lpTime->wType = TIME_MS;
2520 return MMSYSERR_NOERROR;
2523 /**************************************************************************
2524 * widMessage (WINEOSS.6)
2526 DWORD WINAPI OSS_widMessage(WORD wDevID, WORD wMsg, DWORD dwUser,
2527 DWORD dwParam1, DWORD dwParam2)
2529 TRACE("(%u, %04X, %08lX, %08lX, %08lX);\n",
2530 wDevID, wMsg, dwUser, dwParam1, dwParam2);
2537 /* FIXME: Pretend this is supported */
2539 case WIDM_OPEN: return widOpen (wDevID, (LPWAVEOPENDESC)dwParam1, dwParam2);
2540 case WIDM_CLOSE: return widClose (wDevID);
2541 case WIDM_ADDBUFFER: return widAddBuffer (wDevID, (LPWAVEHDR)dwParam1, dwParam2);
2542 case WIDM_PREPARE: return widPrepare (wDevID, (LPWAVEHDR)dwParam1, dwParam2);
2543 case WIDM_UNPREPARE: return widUnprepare (wDevID, (LPWAVEHDR)dwParam1, dwParam2);
2544 case WIDM_GETDEVCAPS: return widGetDevCaps (wDevID, (LPWAVEINCAPSA)dwParam1, dwParam2);
2545 case WIDM_GETNUMDEVS: return wodGetNumDevs (); /* same number of devices in output as in input */
2546 case WIDM_GETPOS: return widGetPosition(wDevID, (LPMMTIME)dwParam1, dwParam2);
2547 case WIDM_RESET: return widReset (wDevID);
2548 case WIDM_START: return widStart (wDevID);
2549 case WIDM_STOP: return widStop (wDevID);
2551 FIXME("unknown message %u!\n", wMsg);
2553 return MMSYSERR_NOTSUPPORTED;
2556 #else /* !HAVE_OSS */
2558 /**************************************************************************
2559 * wodMessage (WINEOSS.7)
2561 DWORD WINAPI OSS_wodMessage(WORD wDevID, WORD wMsg, DWORD dwUser,
2562 DWORD dwParam1, DWORD dwParam2)
2564 FIXME("(%u, %04X, %08lX, %08lX, %08lX):stub\n", wDevID, wMsg, dwUser, dwParam1, dwParam2);
2565 return MMSYSERR_NOTENABLED;
2568 /**************************************************************************
2569 * widMessage (WINEOSS.6)
2571 DWORD WINAPI OSS_widMessage(WORD wDevID, WORD wMsg, DWORD dwUser,
2572 DWORD dwParam1, DWORD dwParam2)
2574 FIXME("(%u, %04X, %08lX, %08lX, %08lX):stub\n", wDevID, wMsg, dwUser, dwParam1, dwParam2);
2575 return MMSYSERR_NOTENABLED;
2578 #endif /* HAVE_OSS */