mcicda.c 48.2 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1
/*
2
 * MCI driver for audio CD (MCICDA)
Alexandre Julliard's avatar
Alexandre Julliard committed
3
 *
4 5
 * Copyright 1994    Martin Ayotte
 * Copyright 1998-99 Eric Pouech
6
 * Copyright 2000    Andreas Mohr
7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Alexandre Julliard's avatar
Alexandre Julliard committed
21 22
 */

23
#include "config.h"
24
#include <stdarg.h>
25
#include <stdio.h>
26
#include <string.h>
27

28
#define WIN32_NO_STATUS
29
#include "windef.h"
30
#include "winbase.h"
31
#include "wingdi.h"
32
#include "winuser.h"
33
#include "wownt32.h"
34
#include "mmddk.h"
35 36
#include "winioctl.h"
#include "ntddcdrm.h"
37
#include "winternl.h"
38
#include "wine/debug.h"
39
#include "wine/unicode.h"
40
#include "dsound.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
41

42
WINE_DEFAULT_DEBUG_CHANNEL(mcicda);
43

44 45 46 47 48
#define CDFRAMES_PERSEC                 75
#define CDFRAMES_PERMIN                 (CDFRAMES_PERSEC * 60)
#define FRAME_OF_ADDR(a) ((a)[1] * CDFRAMES_PERMIN + (a)[2] * CDFRAMES_PERSEC + (a)[3])
#define FRAME_OF_TOC(toc, idx)  FRAME_OF_ADDR((toc).TrackData[idx - (toc).FirstTrack].Address)

49 50 51 52 53 54 55 56
/* Defined by red-book standard; do not change! */
#define RAW_SECTOR_SIZE  (2352)

/* Must be >= RAW_SECTOR_SIZE */
#define CDDA_FRAG_SIZE   (32768)
/* Must be >= 2 */
#define CDDA_FRAG_COUNT  (3)

Alexandre Julliard's avatar
Alexandre Julliard committed
57
typedef struct {
58
    UINT		wDevID;
59
    int     		nUseCount;          /* Incremented for each shared open */
60
    BOOL  		fShareable;         /* TRUE if first open was shareable */
61
    MCIDEVICEID		wNotifyDeviceID;    /* MCI device ID with a pending notification */
62
    HANDLE 		hCallback;          /* Callback handle for pending notification */
63
    DWORD		dwTimeFormat;
64
    HANDLE              handle;
65 66 67 68 69 70 71 72 73 74

    /* The following are used for digital playback only */
    HANDLE hThread;
    HANDLE stopEvent;
    DWORD start, end;

    IDirectSound *dsObj;
    IDirectSoundBuffer *dsBuf;

    CRITICAL_SECTION cs;
75
} WINE_MCICDAUDIO;
Alexandre Julliard's avatar
Alexandre Julliard committed
76 77 78

/*-----------------------------------------------------------------------*/

79 80 81
typedef HRESULT(WINAPI*LPDIRECTSOUNDCREATE)(LPCGUID,LPDIRECTSOUND*,LPUNKNOWN);
static LPDIRECTSOUNDCREATE pDirectSoundCreate;

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
static BOOL device_io(HANDLE dev, DWORD code, void *inbuffer, DWORD insize, void *outbuffer, DWORD outsize, DWORD *retsize, OVERLAPPED *overlapped)
{
    const char *str;
    BOOL ret = DeviceIoControl(dev, code, inbuffer, insize, outbuffer, outsize, retsize, overlapped);

#define XX(x) case (x): str = #x; break
    switch (code)
    {
        XX(IOCTL_CDROM_RAW_READ);
        XX(IOCTL_CDROM_READ_TOC);
        XX(IOCTL_CDROM_READ_Q_CHANNEL);
        XX(IOCTL_CDROM_SEEK_AUDIO_MSF);
        XX(IOCTL_CDROM_PLAY_AUDIO_MSF);
        XX(IOCTL_CDROM_STOP_AUDIO);
        XX(IOCTL_CDROM_PAUSE_AUDIO);
        XX(IOCTL_CDROM_RESUME_AUDIO);
        XX(IOCTL_STORAGE_EJECT_MEDIA);
        XX(IOCTL_STORAGE_LOAD_MEDIA);
        default: str = wine_dbg_sprintf("UNKNOWN (0x%x)", code);
    };
#undef XX
    TRACE("Device %p, Code %s -> Return %d, Bytes %u\n", dev, str, ret, *retsize);
    return ret;
}

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
static DWORD CALLBACK MCICDA_playLoop(void *ptr)
{
    WINE_MCICDAUDIO *wmcda = (WINE_MCICDAUDIO*)ptr;
    DWORD lastPos, curPos, endPos, br;
    void *cdData;
    DWORD lockLen, fragLen;
    DSBCAPS caps;
    RAW_READ_INFO rdInfo;
    HRESULT hr = DS_OK;

    memset(&caps, 0, sizeof(caps));
    caps.dwSize = sizeof(caps);
    hr = IDirectSoundBuffer_GetCaps(wmcda->dsBuf, &caps);

    fragLen = caps.dwBufferBytes/CDDA_FRAG_COUNT;
    curPos = lastPos = 0;
    endPos = ~0u;
    while (SUCCEEDED(hr) && endPos != lastPos &&
           WaitForSingleObject(wmcda->stopEvent, 0) != WAIT_OBJECT_0) {
        hr = IDirectSoundBuffer_GetCurrentPosition(wmcda->dsBuf, &curPos, NULL);
        if ((curPos-lastPos+caps.dwBufferBytes)%caps.dwBufferBytes < fragLen) {
            Sleep(1);
            continue;
        }

        EnterCriticalSection(&wmcda->cs);
        rdInfo.DiskOffset.QuadPart = wmcda->start<<11;
        rdInfo.SectorCount = min(fragLen/RAW_SECTOR_SIZE, wmcda->end-wmcda->start);
        rdInfo.TrackMode = CDDA;

        hr = IDirectSoundBuffer_Lock(wmcda->dsBuf, lastPos, fragLen, &cdData, &lockLen, NULL, NULL, 0);
        if (hr == DSERR_BUFFERLOST) {
            if(FAILED(IDirectSoundBuffer_Restore(wmcda->dsBuf)) ||
               FAILED(IDirectSoundBuffer_Play(wmcda->dsBuf, 0, 0, DSBPLAY_LOOPING))) {
                LeaveCriticalSection(&wmcda->cs);
                break;
            }
            hr = IDirectSoundBuffer_Lock(wmcda->dsBuf, lastPos, fragLen, &cdData, &lockLen, NULL, NULL, 0);
        }

        if (SUCCEEDED(hr)) {
            if (rdInfo.SectorCount > 0) {
149
                if (!device_io(wmcda->handle, IOCTL_CDROM_RAW_READ, &rdInfo, sizeof(rdInfo), cdData, lockLen, &br, NULL))
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
                    WARN("CD read failed at sector %d: 0x%x\n", wmcda->start, GetLastError());
            }
            if (rdInfo.SectorCount*RAW_SECTOR_SIZE < lockLen) {
                if(endPos == ~0u) endPos = lastPos;
                memset((BYTE*)cdData + rdInfo.SectorCount*RAW_SECTOR_SIZE, 0,
                       lockLen - rdInfo.SectorCount*RAW_SECTOR_SIZE);
            }
            hr = IDirectSoundBuffer_Unlock(wmcda->dsBuf, cdData, lockLen, NULL, 0);
        }

        lastPos += fragLen;
        lastPos %= caps.dwBufferBytes;
        wmcda->start += rdInfo.SectorCount;

        LeaveCriticalSection(&wmcda->cs);
    }
    IDirectSoundBuffer_Stop(wmcda->dsBuf);
    SetEvent(wmcda->stopEvent);

169 170 171 172 173
    /* A design bug in native: the independent CD player called by the
     * MCI has no means to signal end of playing, therefore the MCI
     * notification is left hanging.  MCI_NOTIFY_SUPERSEDED will be
     * signaled by the next command that has MCI_NOTIFY set (or
     * MCI_NOTIFY_ABORTED for MCI_PLAY). */
174

175 176 177 178 179
    return 0;
}



180
/**************************************************************************
181
 * 				MCICDA_drvOpen			[internal]
182
 */
183
static	DWORD	MCICDA_drvOpen(LPCWSTR str, LPMCI_OPEN_DRIVER_PARMSW modp)
184
{
185
    static HMODULE dsHandle;
186 187 188
    WINE_MCICDAUDIO*	wmcda;

    if (!modp) return 0xFFFFFFFF;
189
    /* FIXME: MCIERR_CANNOT_LOAD_DRIVER if there's no drive of type CD-ROM */
190

191
    wmcda = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WINE_MCICDAUDIO));
192 193 194 195

    if (!wmcda)
	return 0;

196 197 198 199 200 201
    if (!dsHandle) {
        dsHandle = LoadLibraryA("dsound.dll");
        if(dsHandle)
            pDirectSoundCreate = (LPDIRECTSOUNDCREATE)GetProcAddress(dsHandle, "DirectSoundCreate");
    }

202
    wmcda->wDevID = modp->wDeviceID;
203
    mciSetDriverData(wmcda->wDevID, (DWORD_PTR)wmcda);
204
    modp->wCustomCommandTable = MCI_NO_COMMAND_TABLE;
205
    modp->wType = MCI_DEVTYPE_CD_AUDIO;
206
    InitializeCriticalSection(&wmcda->cs);
207
    wmcda->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": WINE_MCICDAUDIO.cs");
208
    return modp->wDeviceID;
209 210 211
}

/**************************************************************************
212
 * 				MCICDA_drvClose			[internal]
213
 */
214
static	DWORD	MCICDA_drvClose(DWORD dwDevID)
215
{
216
    WINE_MCICDAUDIO*  wmcda = (WINE_MCICDAUDIO*)mciGetDriverData(dwDevID);
217 218

    if (wmcda) {
219
	wmcda->cs.DebugInfo->Spare[0] = 0;
220
	DeleteCriticalSection(&wmcda->cs);
221 222
	HeapFree(GetProcessHeap(), 0, wmcda);
	mciSetDriverData(dwDevID, 0);
223
    }
224
    return (dwDevID == 0xFFFFFFFF) ? 1 : 0;
225 226
}

227
/**************************************************************************
228
 * 				MCICDA_GetOpenDrv		[internal]
229
 */
230
static WINE_MCICDAUDIO*  MCICDA_GetOpenDrv(UINT wDevID)
231
{
232
    WINE_MCICDAUDIO*	wmcda = (WINE_MCICDAUDIO*)mciGetDriverData(wDevID);
233

234
    if (wmcda == NULL || wmcda->nUseCount == 0) {
235
	WARN("Invalid wDevID=%u\n", wDevID);
236 237
	return 0;
    }
238
    return wmcda;
239
}
Alexandre Julliard's avatar
Alexandre Julliard committed
240

241 242 243 244 245 246 247 248 249 250 251 252 253 254
/**************************************************************************
 *				MCICDA_mciNotify		[internal]
 *
 * Notifications in MCI work like a 1-element queue.
 * Each new notification request supersedes the previous one.
 */
static void MCICDA_Notify(DWORD_PTR hWndCallBack, WINE_MCICDAUDIO* wmcda, UINT wStatus)
{
    MCIDEVICEID wDevID = wmcda->wNotifyDeviceID;
    HANDLE old = InterlockedExchangePointer(&wmcda->hCallback, NULL);
    if (old) mciDriverNotify(old, wDevID, MCI_NOTIFY_SUPERSEDED);
    mciDriverNotify(HWND_32(LOWORD(hWndCallBack)), wDevID, wStatus);
}

Alexandre Julliard's avatar
Alexandre Julliard committed
255
/**************************************************************************
256
 * 				MCICDA_GetStatus		[internal]
257
 */
258
static	DWORD    MCICDA_GetStatus(WINE_MCICDAUDIO* wmcda)
Alexandre Julliard's avatar
Alexandre Julliard committed
259
{
260 261 262 263 264 265
    CDROM_SUB_Q_DATA_FORMAT     fmt;
    SUB_Q_CHANNEL_DATA          data;
    DWORD                       br;
    DWORD                       mode = MCI_MODE_NOT_READY;

    fmt.Format = IOCTL_CDROM_CURRENT_POSITION;
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
    if(wmcda->hThread != 0) {
        DWORD status;
        HRESULT hr;

        hr = IDirectSoundBuffer_GetStatus(wmcda->dsBuf, &status);
        if(SUCCEEDED(hr)) {
            if(!(status&DSBSTATUS_PLAYING)) {
                if(WaitForSingleObject(wmcda->stopEvent, 0) == WAIT_OBJECT_0)
                    mode = MCI_MODE_STOP;
                else
                    mode = MCI_MODE_PAUSE;
            }
            else
                mode = MCI_MODE_PLAY;
        }
    }
282
    else if (!device_io(wmcda->handle, IOCTL_CDROM_READ_Q_CHANNEL, &fmt, sizeof(fmt),
283
                              &data, sizeof(data), &br, NULL)) {
284
        if (GetLastError() == ERROR_NOT_READY) mode = MCI_MODE_OPEN;
285 286 287 288 289
    } else {
        switch (data.CurrentPosition.Header.AudioStatus)
        {
        case AUDIO_STATUS_IN_PROGRESS:          mode = MCI_MODE_PLAY;   break;
        case AUDIO_STATUS_PAUSED:               mode = MCI_MODE_PAUSE;  break;
290
        case AUDIO_STATUS_NO_STATUS:
291 292 293 294 295 296
        case AUDIO_STATUS_PLAY_COMPLETE:        mode = MCI_MODE_STOP;   break;
        case AUDIO_STATUS_PLAY_ERROR:
        case AUDIO_STATUS_NOT_SUPPORTED:
        default:
            break;
        }
297
    }
298
    return mode;
Alexandre Julliard's avatar
Alexandre Julliard committed
299 300 301
}

/**************************************************************************
302
 * 				MCICDA_GetError			[internal]
303
 */
304
static	int	MCICDA_GetError(WINE_MCICDAUDIO* wmcda)
Alexandre Julliard's avatar
Alexandre Julliard committed
305
{
306 307
    switch (GetLastError())
    {
308
    case ERROR_NOT_READY:     return MCIERR_DEVICE_NOT_READY;
309
    case ERROR_NOT_SUPPORTED:
310
    case ERROR_IO_DEVICE:     return MCIERR_HARDWARE;
311
    default:
312
	FIXME("Unknown mode %u\n", GetLastError());
313
    }
314
    return MCIERR_DRIVER_INTERNAL;
Alexandre Julliard's avatar
Alexandre Julliard committed
315 316
}

Alexandre Julliard's avatar
Alexandre Julliard committed
317
/**************************************************************************
318
 * 			MCICDA_CalcFrame			[internal]
319
 */
320
static DWORD MCICDA_CalcFrame(WINE_MCICDAUDIO* wmcda, DWORD dwTime)
Alexandre Julliard's avatar
Alexandre Julliard committed
321
{
322
    DWORD	dwFrame = 0;
323
    UINT	wTrack;
324 325 326
    CDROM_TOC   toc;
    DWORD       br;
    BYTE*       addr;
327

328
    TRACE("(%p, %08X, %u);\n", wmcda, wmcda->dwTimeFormat, dwTime);
329

330
    switch (wmcda->dwTimeFormat) {
331
    case MCI_FORMAT_MILLISECONDS:
332
	dwFrame = ((dwTime - 1) * CDFRAMES_PERSEC + 500) / 1000;
333
	TRACE("MILLISECONDS %u\n", dwFrame);
334 335
	break;
    case MCI_FORMAT_MSF:
336
	TRACE("MSF %02u:%02u:%02u\n",
337
	      MCI_MSF_MINUTE(dwTime), MCI_MSF_SECOND(dwTime), MCI_MSF_FRAME(dwTime));
338 339 340 341
	dwFrame += CDFRAMES_PERMIN * MCI_MSF_MINUTE(dwTime);
	dwFrame += CDFRAMES_PERSEC * MCI_MSF_SECOND(dwTime);
	dwFrame += MCI_MSF_FRAME(dwTime);
	break;
342
    case MCI_FORMAT_TMSF:
343
    default: /* unknown format ! force TMSF ! ... */
344
	wTrack = MCI_TMSF_TRACK(dwTime);
345
        if (!device_io(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0,
346 347 348 349 350
                             &toc, sizeof(toc), &br, NULL))
            return 0;
        if (wTrack < toc.FirstTrack || wTrack > toc.LastTrack)
            return 0;
        TRACE("MSF %02u-%02u:%02u:%02u\n",
351
              MCI_TMSF_TRACK(dwTime), MCI_TMSF_MINUTE(dwTime),
352 353 354
              MCI_TMSF_SECOND(dwTime), MCI_TMSF_FRAME(dwTime));
        addr = toc.TrackData[wTrack - toc.FirstTrack].Address;
        TRACE("TMSF trackpos[%u]=%d:%d:%d\n",
355 356 357 358
              wTrack, addr[1], addr[2], addr[3]);
        dwFrame = CDFRAMES_PERMIN * (addr[1] + MCI_TMSF_MINUTE(dwTime)) +
            CDFRAMES_PERSEC * (addr[2] + MCI_TMSF_SECOND(dwTime)) +
            addr[3] + MCI_TMSF_FRAME(dwTime);
359 360 361
	break;
    }
    return dwFrame;
Alexandre Julliard's avatar
Alexandre Julliard committed
362 363
}

Alexandre Julliard's avatar
Alexandre Julliard committed
364
/**************************************************************************
365
 * 			MCICDA_CalcTime				[internal]
366
 */
367
static DWORD MCICDA_CalcTime(WINE_MCICDAUDIO* wmcda, DWORD tf, DWORD dwFrame, LPDWORD lpRet)
Alexandre Julliard's avatar
Alexandre Julliard committed
368
{
369
    DWORD	dwTime = 0;
370 371 372 373
    UINT	wTrack;
    UINT	wMinutes;
    UINT	wSeconds;
    UINT	wFrames;
374 375
    CDROM_TOC   toc;
    DWORD       br;
376

377
    TRACE("(%p, %08X, %u);\n", wmcda, tf, dwFrame);
378

379
    switch (tf) {
380
    case MCI_FORMAT_MILLISECONDS:
381
	dwTime = (dwFrame * 1000) / CDFRAMES_PERSEC + 1;
382
	TRACE("MILLISECONDS %u\n", dwTime);
383
	*lpRet = 0;
384 385 386 387
	break;
    case MCI_FORMAT_MSF:
	wMinutes = dwFrame / CDFRAMES_PERMIN;
	wSeconds = (dwFrame - CDFRAMES_PERMIN * wMinutes) / CDFRAMES_PERSEC;
388
	wFrames = dwFrame - CDFRAMES_PERMIN * wMinutes - CDFRAMES_PERSEC * wSeconds;
389
	dwTime = MCI_MAKE_MSF(wMinutes, wSeconds, wFrames);
390
	TRACE("MSF %02u:%02u:%02u -> dwTime=%u\n",
391
	      wMinutes, wSeconds, wFrames, dwTime);
392
	*lpRet = MCI_COLONIZED3_RETURN;
393
	break;
394
    case MCI_FORMAT_TMSF:
395
    default:	/* unknown format ! force TMSF ! ... */
396
        if (!device_io(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0,
397 398
                             &toc, sizeof(toc), &br, NULL))
            return 0;
399
	if (dwFrame < FRAME_OF_TOC(toc, toc.FirstTrack) ||
400
            dwFrame > FRAME_OF_TOC(toc, toc.LastTrack + 1)) {
401
            ERR("Out of range value %u [%u,%u]\n",
402
		dwFrame, FRAME_OF_TOC(toc, toc.FirstTrack),
403
                FRAME_OF_TOC(toc, toc.LastTrack + 1));
404 405 406
	    *lpRet = 0;
	    return 0;
	}
407 408
	for (wTrack = toc.FirstTrack; wTrack <= toc.LastTrack; wTrack++) {
	    if (FRAME_OF_TOC(toc, wTrack) > dwFrame)
409
		break;
410
	}
411 412
        wTrack--;
	dwFrame -= FRAME_OF_TOC(toc, wTrack);
413 414
	wMinutes = dwFrame / CDFRAMES_PERMIN;
	wSeconds = (dwFrame - CDFRAMES_PERMIN * wMinutes) / CDFRAMES_PERSEC;
415
	wFrames = dwFrame - CDFRAMES_PERMIN * wMinutes - CDFRAMES_PERSEC * wSeconds;
416
	dwTime = MCI_MAKE_TMSF(wTrack, wMinutes, wSeconds, wFrames);
417
	TRACE("%02u-%02u:%02u:%02u\n", wTrack, wMinutes, wSeconds, wFrames);
418
	*lpRet = MCI_COLONIZED4_RETURN;
419 420 421
	break;
    }
    return dwTime;
Alexandre Julliard's avatar
Alexandre Julliard committed
422 423
}

424
static DWORD MCICDA_Stop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms);
425 426

/**************************************************************************
427
 * 				MCICDA_Open			[internal]
428
 */
429
static DWORD MCICDA_Open(UINT wDevID, DWORD dwFlags, LPMCI_OPEN_PARMSW lpOpenParms)
430
{
431 432
    MCIDEVICEID		dwDeviceID;
    DWORD               ret;
433
    WINE_MCICDAUDIO* 	wmcda = (WINE_MCICDAUDIO*)mciGetDriverData(wDevID);
434
    WCHAR               root[7], drive = 0;
435

436
    TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpOpenParms);
437

438
    if (lpOpenParms == NULL) 		return MCIERR_NULL_PARAMETER_BLOCK;
439
    if (wmcda == NULL)			return MCIERR_INVALID_DEVICE_ID;
440 441 442

    dwDeviceID = lpOpenParms->wDeviceID;

443 444
    if (wmcda->nUseCount > 0) {
	/* The driver is already open on this channel */
445 446
	/* If the driver was opened shareable before and this open specifies */
	/* shareable then increment the use count */
447 448
	if (wmcda->fShareable && (dwFlags & MCI_OPEN_SHAREABLE))
	    ++wmcda->nUseCount;
449 450 451
	else
	    return MCIERR_MUST_USE_SHAREABLE;
    } else {
452 453
	wmcda->nUseCount = 1;
	wmcda->fShareable = dwFlags & MCI_OPEN_SHAREABLE;
454 455
    }
    if (dwFlags & MCI_OPEN_ELEMENT) {
456
        if (dwFlags & MCI_OPEN_ELEMENT_ID) {
457
            WARN("MCI_OPEN_ELEMENT_ID %p! Abort\n", lpOpenParms->lpstrElementName);
458
            ret = MCIERR_FLAGS_NOT_COMPATIBLE;
459
            goto the_error;
460
        }
461
        TRACE("MCI_OPEN_ELEMENT element name: %s\n", debugstr_w(lpOpenParms->lpstrElementName));
462 463 464 465
        /* Only the first letter counts since w2k
         * Win9x-NT accept only d: and w98SE accepts d:\foobar as well.
         * Play d:\Track03.cda plays from the first track, not #3. */
        if (!isalpha(lpOpenParms->lpstrElementName[0]))
466
        {
467
            ret = MCIERR_INVALID_FILE;
468 469 470
            goto the_error;
        }
        drive = toupper(lpOpenParms->lpstrElementName[0]);
471 472
        root[0] = drive; root[1] = ':'; root[2] = '\\'; root[3] = '\0';
        if (GetDriveTypeW(root) != DRIVE_CDROM)
473
        {
474
            ret = MCIERR_INVALID_FILE;
475 476 477 478 479
            goto the_error;
        }
    }
    else
    {
480
        root[0] = 'A'; root[1] = ':'; root[2] = '\\'; root[3] = '\0';
481
        for ( ; root[0] <= 'Z'; root[0]++)
482
        {
483
            if (GetDriveTypeW(root) == DRIVE_CDROM)
484 485 486 487 488 489 490
            {
                drive = root[0];
                break;
            }
        }
        if (!drive)
        {
491
            ret = MCIERR_CANNOT_LOAD_DRIVER; /* drvOpen should return this */
492 493
            goto the_error;
        }
494 495
    }

496
    wmcda->wNotifyDeviceID = dwDeviceID;
497
    wmcda->dwTimeFormat = MCI_FORMAT_MSF;
498

499
    /* now, open the handle */
500 501
    root[0] = root[1] = '\\'; root[2] = '.'; root[3] = '\\'; root[4] = drive; root[5] = ':'; root[6] = '\0';
    wmcda->handle = CreateFileW(root, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
502
    if (wmcda->handle == INVALID_HANDLE_VALUE)
503 504
    {
        ret = MCIERR_MUST_USE_SHAREABLE;
505
        goto the_error;
506
    }
507 508 509

    if (dwFlags & MCI_NOTIFY) {
	mciDriverNotify(HWND_32(LOWORD(lpOpenParms->dwCallback)),
510
			dwDeviceID, MCI_NOTIFY_SUCCESSFUL);
511 512
    }
    return 0;
513 514 515 516

 the_error:
    --wmcda->nUseCount;
    return ret;
517 518 519
}

/**************************************************************************
520
 * 				MCICDA_Close			[internal]
521
 */
522
static DWORD MCICDA_Close(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
523
{
524
    WINE_MCICDAUDIO*	wmcda = MCICDA_GetOpenDrv(wDevID);
525

526
    TRACE("(%04X, %08X, %p);\n", wDevID, dwParam, lpParms);
527

528
    if (wmcda == NULL) 	return MCIERR_INVALID_DEVICE_ID;
529

530 531
    MCICDA_Stop(wDevID, MCI_WAIT, NULL);

532 533
    if (--wmcda->nUseCount == 0) {
	CloseHandle(wmcda->handle);
534
    }
535 536
    if ((dwParam & MCI_NOTIFY) && lpParms)
	MCICDA_Notify(lpParms->dwCallback, wmcda, MCI_NOTIFY_SUCCESSFUL);
537 538 539 540
    return 0;
}

/**************************************************************************
541
 * 				MCICDA_GetDevCaps		[internal]
542
 */
543
static DWORD MCICDA_GetDevCaps(UINT wDevID, DWORD dwFlags,
544 545
				   LPMCI_GETDEVCAPS_PARMS lpParms)
{
546
    WINE_MCICDAUDIO* 	wmcda = (WINE_MCICDAUDIO*)mciGetDriverData(wDevID);
547 548
    DWORD	ret = 0;

549
    TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
550 551

    if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
552
    if (wmcda == NULL)			return MCIERR_INVALID_DEVICE_ID;
553 554

    if (dwFlags & MCI_GETDEVCAPS_ITEM) {
555
	TRACE("MCI_GETDEVCAPS_ITEM dwItem=%08X;\n", lpParms->dwItem);
556

557
	switch (lpParms->dwItem) {
558
	case MCI_GETDEVCAPS_CAN_RECORD:
559 560
	    lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
	    ret = MCI_RESOURCE_RETURNED;
561 562
	    break;
	case MCI_GETDEVCAPS_HAS_AUDIO:
563 564
	    lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
	    ret = MCI_RESOURCE_RETURNED;
565 566
	    break;
	case MCI_GETDEVCAPS_HAS_VIDEO:
567 568
	    lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
	    ret = MCI_RESOURCE_RETURNED;
569 570
	    break;
	case MCI_GETDEVCAPS_DEVICE_TYPE:
571 572
	    lpParms->dwReturn = MAKEMCIRESOURCE(MCI_DEVTYPE_CD_AUDIO, MCI_DEVTYPE_CD_AUDIO);
	    ret = MCI_RESOURCE_RETURNED;
573 574
	    break;
	case MCI_GETDEVCAPS_USES_FILES:
575 576
	    lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
	    ret = MCI_RESOURCE_RETURNED;
577 578
	    break;
	case MCI_GETDEVCAPS_COMPOUND_DEVICE:
579 580
	    lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
	    ret = MCI_RESOURCE_RETURNED;
581 582
	    break;
	case MCI_GETDEVCAPS_CAN_EJECT:
583 584
	    lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
	    ret = MCI_RESOURCE_RETURNED;
585 586
	    break;
	case MCI_GETDEVCAPS_CAN_PLAY:
587 588
	    lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
	    ret = MCI_RESOURCE_RETURNED;
589 590
	    break;
	case MCI_GETDEVCAPS_CAN_SAVE:
591 592
	    lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
	    ret = MCI_RESOURCE_RETURNED;
593 594
	    break;
	default:
595 596
            WARN("Unsupported %x devCaps item\n", lpParms->dwItem);
	    return MCIERR_UNSUPPORTED_FUNCTION;
597
	}
598 599
    } else {
	TRACE("No GetDevCaps-Item !\n");
600
	return MCIERR_MISSING_PARAMETER;
601
    }
602
    TRACE("lpParms->dwReturn=%08X;\n", lpParms->dwReturn);
603 604 605
    if (dwFlags & MCI_NOTIFY) {
	MCICDA_Notify(lpParms->dwCallback, wmcda, MCI_NOTIFY_SUCCESSFUL);
    }
606
    return ret;
607 608
}

609 610
static DWORD CDROM_Audio_GetSerial(CDROM_TOC* toc)
{
611
    DWORD serial = 0;
612 613 614
    int i;
    WORD wMagic;
    DWORD dwStart, dwEnd;
615

616 617 618 619 620 621 622 623 624 625 626
    /*
     * wMagic collects the wFrames from track 1
     * dwStart, dwEnd collect the beginning and end of the disc respectively, in
     * frames.
     * There it is collected for correcting the serial when there are less than
     * 3 tracks.
     */
    wMagic = toc->TrackData[0].Address[3];
    dwStart = FRAME_OF_TOC(*toc, toc->FirstTrack);

    for (i = 0; i <= toc->LastTrack - toc->FirstTrack; i++) {
627
        serial += (toc->TrackData[i].Address[1] << 16) |
628 629 630
            (toc->TrackData[i].Address[2] << 8) | toc->TrackData[i].Address[3];
    }
    dwEnd = FRAME_OF_TOC(*toc, toc->LastTrack + 1);
631

632 633 634 635 636
    if (toc->LastTrack - toc->FirstTrack + 1 < 3)
        serial += wMagic + (dwEnd - dwStart);

    return serial;
}
637

638

639
/**************************************************************************
640
 * 				MCICDA_Info			[internal]
641
 */
642
static DWORD MCICDA_Info(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMSW lpParms)
643
{
644
    LPCWSTR		str = NULL;
645
    WINE_MCICDAUDIO*	wmcda = MCICDA_GetOpenDrv(wDevID);
646
    DWORD		ret = 0;
647
    WCHAR		buffer[16];
648

649
    TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
650

651 652 653 654
    if (lpParms == NULL || lpParms->lpstrReturn == NULL)
	return MCIERR_NULL_PARAMETER_BLOCK;
    if (wmcda == NULL) return MCIERR_INVALID_DEVICE_ID;

655
    TRACE("buf=%p, len=%u\n", lpParms->lpstrReturn, lpParms->dwRetSize);
656

657
    if (dwFlags & MCI_INFO_PRODUCT) {
658 659
        static const WCHAR wszAudioCd[] = {'W','i','n','e','\'','s',' ','a','u','d','i','o',' ','C','D',0};
        str = wszAudioCd;
660 661 662
    } else if (dwFlags & MCI_INFO_MEDIA_UPC) {
	ret = MCIERR_NO_IDENTITY;
    } else if (dwFlags & MCI_INFO_MEDIA_IDENTITY) {
663 664 665
	DWORD	    res = 0;
        CDROM_TOC   toc;
        DWORD       br;
666
	static const WCHAR wszLu[] = {'%','l','u',0};
667

668
        if (!device_io(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0,
669
                             &toc, sizeof(toc), &br, NULL)) {
670
	    return MCICDA_GetError(wmcda);
671
	}
672 673

	res = CDROM_Audio_GetSerial(&toc);
674
	sprintfW(buffer, wszLu, res);
675 676
	str = buffer;
    } else {
677
	WARN("Don't know this info command (%u)\n", dwFlags);
678
	ret = MCIERR_MISSING_PARAMETER;
679
    }
680 681 682 683 684
    if (!ret) {
	TRACE("=> %s\n", debugstr_w(str));
	if (lpParms->dwRetSize) {
	    /* FIXME? Since NT, mciwave, mciseq and mcicda set dwRetSize
	     *        to the number of characters written, excluding \0. */
685
	    lstrcpynW(lpParms->lpstrReturn, str, lpParms->dwRetSize);
686
	} else ret = MCIERR_PARAM_OVERFLOW;
687
    }
688 689
    if (MMSYSERR_NOERROR==ret && (dwFlags & MCI_NOTIFY))
	MCICDA_Notify(lpParms->dwCallback, wmcda, MCI_NOTIFY_SUCCESSFUL);
690
    return ret;
691
}
Alexandre Julliard's avatar
Alexandre Julliard committed
692 693

/**************************************************************************
694
 * 				MCICDA_Status			[internal]
695
 */
696
static DWORD MCICDA_Status(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
Alexandre Julliard's avatar
Alexandre Julliard committed
697
{
698 699 700 701 702 703
    WINE_MCICDAUDIO*	        wmcda = MCICDA_GetOpenDrv(wDevID);
    DWORD	                ret = 0;
    CDROM_SUB_Q_DATA_FORMAT     fmt;
    SUB_Q_CHANNEL_DATA          data;
    CDROM_TOC                   toc;
    DWORD                       br;
704

705
    TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
706

707 708 709 710
    if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
    if (wmcda == NULL) return MCIERR_INVALID_DEVICE_ID;

    if (dwFlags & MCI_STATUS_ITEM) {
711
	TRACE("dwItem = %x\n", lpParms->dwItem);
712 713
	switch (lpParms->dwItem) {
	case MCI_STATUS_CURRENT_TRACK:
714
            fmt.Format = IOCTL_CDROM_CURRENT_POSITION;
715
            if (!device_io(wmcda->handle, IOCTL_CDROM_READ_Q_CHANNEL, &fmt, sizeof(fmt),
716 717
                                 &data, sizeof(data), &br, NULL))
            {
718
		return MCICDA_GetError(wmcda);
719
		/* alt. data.CurrentPosition.TrackNumber = 1; -- what native yields */
720
	    }
721
	    lpParms->dwReturn = data.CurrentPosition.TrackNumber;
722
            TRACE("CURRENT_TRACK=%lu\n", lpParms->dwReturn);
723 724
	    break;
	case MCI_STATUS_LENGTH:
725
            if (!device_io(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0,
726 727 728
                                 &toc, sizeof(toc), &br, NULL)) {
                WARN("error reading TOC !\n");
                return MCICDA_GetError(wmcda);
729 730
	    }
	    if (dwFlags & MCI_TRACK) {
731
		TRACE("MCI_TRACK #%u LENGTH=??? !\n", lpParms->dwTrack);
732
		if (lpParms->dwTrack < toc.FirstTrack || lpParms->dwTrack > toc.LastTrack)
733
		    return MCIERR_OUTOFRANGE;
734
		lpParms->dwReturn = FRAME_OF_TOC(toc, lpParms->dwTrack + 1) -
735
                    FRAME_OF_TOC(toc, lpParms->dwTrack);
736 737
		/* Windows returns one frame less than the total track length for the
		   last track on the CD.  See CDDB HOWTO.  Verified on Win95OSR2. */
738
		if (lpParms->dwTrack == toc.LastTrack)
739
		    lpParms->dwReturn--;
740
	    } else {
741 742 743
		/* Sum of the lengths of all of the tracks.  Inherits the
		   'off by one frame' behavior from the length of the last track.
		   See above comment. */
744 745
		lpParms->dwReturn = FRAME_OF_TOC(toc, toc.LastTrack + 1) -
                    FRAME_OF_TOC(toc, toc.FirstTrack) - 1;
746
	    }
747 748
	    lpParms->dwReturn = MCICDA_CalcTime(wmcda,
						 (wmcda->dwTimeFormat == MCI_FORMAT_TMSF)
749 750 751
						    ? MCI_FORMAT_MSF : wmcda->dwTimeFormat,
						 lpParms->dwReturn,
						 &ret);
752
            TRACE("LENGTH=%lu\n", lpParms->dwReturn);
753 754
	    break;
	case MCI_STATUS_MODE:
755
            lpParms->dwReturn = MCICDA_GetStatus(wmcda);
756
            TRACE("MCI_STATUS_MODE=%08lX\n", lpParms->dwReturn);
757 758 759 760
	    lpParms->dwReturn = MAKEMCIRESOURCE(lpParms->dwReturn, lpParms->dwReturn);
	    ret = MCI_RESOURCE_RETURNED;
	    break;
	case MCI_STATUS_MEDIA_PRESENT:
761
	    lpParms->dwReturn = (MCICDA_GetStatus(wmcda) == MCI_MODE_OPEN) ?
762
		MAKEMCIRESOURCE(FALSE, MCI_FALSE) : MAKEMCIRESOURCE(TRUE, MCI_TRUE);
763
	    TRACE("MCI_STATUS_MEDIA_PRESENT =%c!\n", LOWORD(lpParms->dwReturn) ? 'Y' : 'N');
764 765 766
	    ret = MCI_RESOURCE_RETURNED;
	    break;
	case MCI_STATUS_NUMBER_OF_TRACKS:
767
            if (!device_io(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0,
768 769 770 771 772
                                 &toc, sizeof(toc), &br, NULL)) {
                WARN("error reading TOC !\n");
                return MCICDA_GetError(wmcda);
	    }
	    lpParms->dwReturn = toc.LastTrack - toc.FirstTrack + 1;
773
            TRACE("MCI_STATUS_NUMBER_OF_TRACKS = %lu\n", lpParms->dwReturn);
774
	    if (lpParms->dwReturn == (WORD)-1)
775
		return MCICDA_GetError(wmcda);
776 777
	    break;
	case MCI_STATUS_POSITION:
778 779
            switch (dwFlags & (MCI_STATUS_START | MCI_TRACK)) {
            case MCI_STATUS_START:
780
                if (!device_io(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0,
781 782 783 784 785
                                     &toc, sizeof(toc), &br, NULL)) {
                    WARN("error reading TOC !\n");
                    return MCICDA_GetError(wmcda);
                }
		lpParms->dwReturn = FRAME_OF_TOC(toc, toc.FirstTrack);
786
		TRACE("get MCI_STATUS_START !\n");
787 788
                break;
            case MCI_TRACK:
789
                if (!device_io(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0,
790 791 792 793 794
                                     &toc, sizeof(toc), &br, NULL)) {
                    WARN("error reading TOC !\n");
                    return MCICDA_GetError(wmcda);
                }
		if (lpParms->dwTrack < toc.FirstTrack || lpParms->dwTrack > toc.LastTrack)
795
		    return MCIERR_OUTOFRANGE;
796
		lpParms->dwReturn = FRAME_OF_TOC(toc, lpParms->dwTrack);
797
		TRACE("get MCI_TRACK #%u !\n", lpParms->dwTrack);
798 799
                break;
            case 0:
800
                fmt.Format = IOCTL_CDROM_CURRENT_POSITION;
801
                if (!device_io(wmcda->handle, IOCTL_CDROM_READ_Q_CHANNEL, &fmt, sizeof(fmt),
802 803 804 805
                                     &data, sizeof(data), &br, NULL)) {
                    return MCICDA_GetError(wmcda);
                }
                lpParms->dwReturn = FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress);
806 807 808
                break;
            default:
                return MCIERR_FLAGS_NOT_COMPATIBLE;
809
            }
810
	    lpParms->dwReturn = MCICDA_CalcTime(wmcda, wmcda->dwTimeFormat, lpParms->dwReturn, &ret);
811
            TRACE("MCI_STATUS_POSITION=%08lX\n", lpParms->dwReturn);
812 813 814
	    break;
	case MCI_STATUS_READY:
	    TRACE("MCI_STATUS_READY !\n");
815 816 817 818 819 820 821 822 823 824
            switch (MCICDA_GetStatus(wmcda))
            {
            case MCI_MODE_NOT_READY:
            case MCI_MODE_OPEN:
                lpParms->dwReturn = MAKEMCIRESOURCE(FALSE, MCI_FALSE);
                break;
            default:
                lpParms->dwReturn = MAKEMCIRESOURCE(TRUE, MCI_TRUE);
                break;
            }
825 826 827 828
	    TRACE("MCI_STATUS_READY=%u!\n", LOWORD(lpParms->dwReturn));
	    ret = MCI_RESOURCE_RETURNED;
	    break;
	case MCI_STATUS_TIME_FORMAT:
829
	    lpParms->dwReturn = MAKEMCIRESOURCE(wmcda->dwTimeFormat, MCI_FORMAT_RETURN_BASE + wmcda->dwTimeFormat);
830 831 832
	    TRACE("MCI_STATUS_TIME_FORMAT=%08x!\n", LOWORD(lpParms->dwReturn));
	    ret = MCI_RESOURCE_RETURNED;
	    break;
833
	case 4001: /* FIXME: for bogus FullCD */
834
	case MCI_CDA_STATUS_TYPE_TRACK:
835
	    if (!(dwFlags & MCI_TRACK))
836
		ret = MCIERR_MISSING_PARAMETER;
837
	    else {
838
                if (!device_io(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0,
839 840 841 842 843
                                     &toc, sizeof(toc), &br, NULL)) {
                    WARN("error reading TOC !\n");
                    return MCICDA_GetError(wmcda);
                }
		if (lpParms->dwTrack < toc.FirstTrack || lpParms->dwTrack > toc.LastTrack)
844 845
		    ret = MCIERR_OUTOFRANGE;
		else
846 847
		    lpParms->dwReturn = (toc.TrackData[lpParms->dwTrack - toc.FirstTrack].Control & 0x04) ?
                                         MCI_CDA_TRACK_OTHER : MCI_CDA_TRACK_AUDIO;
848
		    /* FIXME: MAKEMCIRESOURCE "audio" | "other", localised */
849
	    }
850
            TRACE("MCI_CDA_STATUS_TYPE_TRACK[%d]=%ld\n", lpParms->dwTrack, lpParms->dwReturn);
851 852
	    break;
	default:
853
            FIXME("unknown command %08X !\n", lpParms->dwItem);
854
	    return MCIERR_UNSUPPORTED_FUNCTION;
855
	}
856
    } else return MCIERR_MISSING_PARAMETER;
857 858
    if ((dwFlags & MCI_NOTIFY) && HRESULT_CODE(ret)==0)
	MCICDA_Notify(lpParms->dwCallback, wmcda, MCI_NOTIFY_SUCCESSFUL);
859
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
860 861
}

862 863 864 865 866 867 868 869
/**************************************************************************
 * 				MCICDA_SkipDataTracks		[internal]
 */
static DWORD MCICDA_SkipDataTracks(WINE_MCICDAUDIO* wmcda,DWORD *frame)
{
  int i;
  DWORD br;
  CDROM_TOC toc;
870
  if (!device_io(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0,
871 872 873 874
                      &toc, sizeof(toc), &br, NULL)) {
    WARN("error reading TOC !\n");
    return MCICDA_GetError(wmcda);
  }
Jörg Höhle's avatar
Jörg Höhle committed
875 876 877 878 879
  if (*frame < FRAME_OF_TOC(toc,toc.FirstTrack) ||
      *frame >= FRAME_OF_TOC(toc,toc.LastTrack+1)) /* lead-out */
    return MCIERR_OUTOFRANGE;
  for(i=toc.LastTrack+1;i>toc.FirstTrack;i--)
    if ( FRAME_OF_TOC(toc, i) <= *frame ) break;
880 881
  /* i points to last track whose start address is not greater than frame.
   * Now skip non-audio tracks */
Jörg Höhle's avatar
Jörg Höhle committed
882
  for(;i<=toc.LastTrack;i++)
883 884 885 886 887 888
    if ( ! (toc.TrackData[i-toc.FirstTrack].Control & 4) )
      break;
  /* The frame will be an address in the next audio track or
   * address of lead-out. */
  if ( FRAME_OF_TOC(toc, i) > *frame )
    *frame = FRAME_OF_TOC(toc, i);
Jörg Höhle's avatar
Jörg Höhle committed
889 890 891
  /* Lead-out is an invalid seek position (on Linux as well). */
  if (*frame == FRAME_OF_TOC(toc,toc.LastTrack+1))
     (*frame)--;
892 893 894
  return 0;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
895
/**************************************************************************
896
 * 				MCICDA_Play			[internal]
897
 */
898
static DWORD MCICDA_Play(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
Alexandre Julliard's avatar
Alexandre Julliard committed
899
{
900 901
    WINE_MCICDAUDIO*	        wmcda = MCICDA_GetOpenDrv(wDevID);
    DWORD		        ret = 0, start, end;
902
    HANDLE                      oldcb;
903 904 905 906
    DWORD                       br;
    CDROM_PLAY_AUDIO_MSF        play;
    CDROM_SUB_Q_DATA_FORMAT     fmt;
    SUB_Q_CHANNEL_DATA          data;
907
    CDROM_TOC			toc;
908

909
    TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
910

911 912 913 914 915 916
    if (lpParms == NULL)
	return MCIERR_NULL_PARAMETER_BLOCK;

    if (wmcda == NULL)
	return MCIERR_INVALID_DEVICE_ID;

917
    if (!device_io(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0,
918 919 920 921 922
                         &toc, sizeof(toc), &br, NULL)) {
        WARN("error reading TOC !\n");
        return MCICDA_GetError(wmcda);
    }

923 924
    if (dwFlags & MCI_FROM) {
	start = MCICDA_CalcFrame(wmcda, lpParms->dwFrom);
925 926
	if ( (ret=MCICDA_SkipDataTracks(wmcda, &start)) )
	  return ret;
927
	TRACE("MCI_FROM=%08X -> %u\n", lpParms->dwFrom, start);
928
    } else {
929
        fmt.Format = IOCTL_CDROM_CURRENT_POSITION;
930
        if (!device_io(wmcda->handle, IOCTL_CDROM_READ_Q_CHANNEL, &fmt, sizeof(fmt),
931 932 933 934
                             &data, sizeof(data), &br, NULL)) {
            return MCICDA_GetError(wmcda);
        }
        start = FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress);
935 936
	if ( (ret=MCICDA_SkipDataTracks(wmcda, &start)) )
	  return ret;
937 938 939
    }
    if (dwFlags & MCI_TO) {
	end = MCICDA_CalcFrame(wmcda, lpParms->dwTo);
940 941
	if ( (ret=MCICDA_SkipDataTracks(wmcda, &end)) )
	  return ret;
942
	TRACE("MCI_TO=%08X -> %u\n", lpParms->dwTo, end);
943 944
    } else {
	end = FRAME_OF_TOC(toc, toc.LastTrack + 1) - 1;
945
    }
946
    if (end < start) return MCIERR_OUTOFRANGE;
947
    TRACE("Playing from %u to %u\n", start, end);
948

949 950 951 952
    oldcb = InterlockedExchangePointer(&wmcda->hCallback,
	(dwFlags & MCI_NOTIFY) ? HWND_32(LOWORD(lpParms->dwCallback)) : NULL);
    if (oldcb) mciDriverNotify(oldcb, wmcda->wNotifyDeviceID, MCI_NOTIFY_ABORTED);

Jörg Höhle's avatar
Jörg Höhle committed
953 954 955 956 957 958 959 960
    if (start == end || start == FRAME_OF_TOC(toc,toc.LastTrack+1)-1) {
        if (dwFlags & MCI_NOTIFY) {
            oldcb = InterlockedExchangePointer(&wmcda->hCallback, NULL);
            if (oldcb) mciDriverNotify(oldcb, wDevID, MCI_NOTIFY_SUCCESSFUL);
        }
        return MMSYSERR_NOERROR;
    }

961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
    if (wmcda->hThread != 0) {
        SetEvent(wmcda->stopEvent);
        WaitForSingleObject(wmcda->hThread, INFINITE);

        CloseHandle(wmcda->hThread);
        wmcda->hThread = 0;
        CloseHandle(wmcda->stopEvent);
        wmcda->stopEvent = 0;

        IDirectSoundBuffer_Stop(wmcda->dsBuf);
        IDirectSoundBuffer_Release(wmcda->dsBuf);
        wmcda->dsBuf = NULL;
        IDirectSound_Release(wmcda->dsObj);
        wmcda->dsObj = NULL;
    }

    if (pDirectSoundCreate) {
        WAVEFORMATEX format;
        DSBUFFERDESC desc;
        DWORD lockLen;
        void *cdData;
        HRESULT hr;

        hr = pDirectSoundCreate(NULL, &wmcda->dsObj, NULL);
        if (SUCCEEDED(hr)) {
            IDirectSound_SetCooperativeLevel(wmcda->dsObj, GetDesktopWindow(), DSSCL_PRIORITY);

            /* The "raw" frame is relative to the start of the first track */
            wmcda->start = start - FRAME_OF_TOC(toc, toc.FirstTrack);
            wmcda->end = end - FRAME_OF_TOC(toc, toc.FirstTrack);

            memset(&format, 0, sizeof(format));
            format.wFormatTag = WAVE_FORMAT_PCM;
            format.nChannels = 2;
            format.nSamplesPerSec = 44100;
            format.wBitsPerSample = 16;
            format.nBlockAlign = format.nChannels * format.wBitsPerSample / 8;
            format.nAvgBytesPerSec = format.nSamplesPerSec * format.nBlockAlign;
            format.cbSize = 0;

            memset(&desc, 0, sizeof(desc));
            desc.dwSize = sizeof(desc);
            desc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS;
            desc.dwBufferBytes = (CDDA_FRAG_SIZE - (CDDA_FRAG_SIZE%RAW_SECTOR_SIZE)) * CDDA_FRAG_COUNT;
            desc.lpwfxFormat = &format;

            hr = IDirectSound_CreateSoundBuffer(wmcda->dsObj, &desc, &wmcda->dsBuf, NULL);
        }
        if (SUCCEEDED(hr)) {
            hr = IDirectSoundBuffer_Lock(wmcda->dsBuf, 0, 0, &cdData, &lockLen,
                                         NULL, NULL, DSBLOCK_ENTIREBUFFER);
        }
        if (SUCCEEDED(hr)) {
            RAW_READ_INFO rdInfo;
            int readok;

            rdInfo.DiskOffset.QuadPart = wmcda->start<<11;
            rdInfo.SectorCount = min(desc.dwBufferBytes/RAW_SECTOR_SIZE,
                                     wmcda->end-wmcda->start);
            rdInfo.TrackMode = CDDA;

1022
            readok = device_io(wmcda->handle, IOCTL_CDROM_RAW_READ,
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034
                                     &rdInfo, sizeof(rdInfo), cdData, lockLen,
                                     &br, NULL);
            IDirectSoundBuffer_Unlock(wmcda->dsBuf, cdData, lockLen, NULL, 0);

            if (readok) {
                wmcda->start += rdInfo.SectorCount;
                wmcda->stopEvent = CreateEventA(NULL, TRUE, FALSE, NULL);
            }
            if (wmcda->stopEvent != 0)
                wmcda->hThread = CreateThread(NULL, 0, MCICDA_playLoop, wmcda, 0, &br);
            if (wmcda->hThread != 0) {
                hr = IDirectSoundBuffer_Play(wmcda->dsBuf, 0, 0, DSBPLAY_LOOPING);
1035 1036 1037 1038 1039 1040 1041
                if (SUCCEEDED(hr)) {
                    /* FIXME: implement MCI_WAIT and send notification only in that case */
                    if (0) {
                        oldcb = InterlockedExchangePointer(&wmcda->hCallback, NULL);
                        if (oldcb) mciDriverNotify(oldcb, wmcda->wNotifyDeviceID,
                            FAILED(hr) ? MCI_NOTIFY_FAILURE : MCI_NOTIFY_SUCCESSFUL);
                    }
1042
                    return ret;
1043
                }
1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065

                SetEvent(wmcda->stopEvent);
                WaitForSingleObject(wmcda->hThread, INFINITE);
                CloseHandle(wmcda->hThread);
                wmcda->hThread = 0;
            }
        }

        if (wmcda->stopEvent != 0) {
            CloseHandle(wmcda->stopEvent);
            wmcda->stopEvent = 0;
        }
        if (wmcda->dsBuf) {
            IDirectSoundBuffer_Release(wmcda->dsBuf);
            wmcda->dsBuf = NULL;
        }
        if (wmcda->dsObj) {
            IDirectSound_Release(wmcda->dsObj);
            wmcda->dsObj = NULL;
        }
    }

1066 1067 1068 1069 1070 1071
    play.StartingM = start / CDFRAMES_PERMIN;
    play.StartingS = (start / CDFRAMES_PERSEC) % 60;
    play.StartingF = start % CDFRAMES_PERSEC;
    play.EndingM   = end / CDFRAMES_PERMIN;
    play.EndingS   = (end / CDFRAMES_PERSEC) % 60;
    play.EndingF   = end % CDFRAMES_PERSEC;
1072
    if (!device_io(wmcda->handle, IOCTL_CDROM_PLAY_AUDIO_MSF, &play, sizeof(play),
1073
                         NULL, 0, &br, NULL)) {
1074
	wmcda->hCallback = NULL;
1075
	ret = MCIERR_HARDWARE;
1076
    }
1077 1078
    /* The independent CD player has no means to signal MCI_NOTIFY when it's done.
     * Native sends a notification with MCI_WAIT only. */
1079
    return ret;
Alexandre Julliard's avatar
Alexandre Julliard committed
1080 1081 1082
}

/**************************************************************************
1083
 * 				MCICDA_Stop			[internal]
1084
 */
1085
static DWORD MCICDA_Stop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
Alexandre Julliard's avatar
Alexandre Julliard committed
1086
{
1087
    WINE_MCICDAUDIO*	wmcda = MCICDA_GetOpenDrv(wDevID);
1088
    HANDLE		oldcb;
1089 1090
    DWORD               br;

1091
    TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
1092

1093
    if (wmcda == NULL)	return MCIERR_INVALID_DEVICE_ID;
1094

1095 1096 1097
    oldcb = InterlockedExchangePointer(&wmcda->hCallback, NULL);
    if (oldcb) mciDriverNotify(oldcb, wmcda->wNotifyDeviceID, MCI_NOTIFY_ABORTED);

1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111
    if (wmcda->hThread != 0) {
        SetEvent(wmcda->stopEvent);
        WaitForSingleObject(wmcda->hThread, INFINITE);

        CloseHandle(wmcda->hThread);
        wmcda->hThread = 0;
        CloseHandle(wmcda->stopEvent);
        wmcda->stopEvent = 0;

        IDirectSoundBuffer_Release(wmcda->dsBuf);
        wmcda->dsBuf = NULL;
        IDirectSound_Release(wmcda->dsObj);
        wmcda->dsObj = NULL;
    }
1112
    else if (!device_io(wmcda->handle, IOCTL_CDROM_STOP_AUDIO, NULL, 0, NULL, 0, &br, NULL))
1113
        return MCIERR_HARDWARE;
1114

1115 1116
    if ((dwFlags & MCI_NOTIFY) && lpParms)
	MCICDA_Notify(lpParms->dwCallback, wmcda, MCI_NOTIFY_SUCCESSFUL);
1117
    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1118 1119 1120
}

/**************************************************************************
1121
 * 				MCICDA_Pause			[internal]
1122
 */
1123
static DWORD MCICDA_Pause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
Alexandre Julliard's avatar
Alexandre Julliard committed
1124
{
1125
    WINE_MCICDAUDIO*	wmcda = MCICDA_GetOpenDrv(wDevID);
1126
    HANDLE		oldcb;
1127 1128
    DWORD               br;

1129
    TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
1130

1131
    if (wmcda == NULL)	return MCIERR_INVALID_DEVICE_ID;
1132

1133 1134 1135
    oldcb = InterlockedExchangePointer(&wmcda->hCallback, NULL);
    if (oldcb) mciDriverNotify(oldcb, wmcda->wNotifyDeviceID, MCI_NOTIFY_ABORTED);

1136 1137 1138 1139 1140 1141
    if (wmcda->hThread != 0) {
        /* Don't bother calling stop if the playLoop thread has already stopped */
        if(WaitForSingleObject(wmcda->stopEvent, 0) != WAIT_OBJECT_0 &&
           FAILED(IDirectSoundBuffer_Stop(wmcda->dsBuf)))
            return MCIERR_HARDWARE;
    }
1142
    else if (!device_io(wmcda->handle, IOCTL_CDROM_PAUSE_AUDIO, NULL, 0, NULL, 0, &br, NULL))
1143
        return MCIERR_HARDWARE;
1144

1145 1146
    if ((dwFlags & MCI_NOTIFY) && lpParms)
	MCICDA_Notify(lpParms->dwCallback, wmcda, MCI_NOTIFY_SUCCESSFUL);
1147
    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1148 1149 1150
}

/**************************************************************************
1151
 * 				MCICDA_Resume			[internal]
1152
 */
1153
static DWORD MCICDA_Resume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
Alexandre Julliard's avatar
Alexandre Julliard committed
1154
{
1155
    WINE_MCICDAUDIO*	wmcda = MCICDA_GetOpenDrv(wDevID);
1156
    DWORD               br;
1157

1158
    TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
1159

1160
    if (wmcda == NULL)	return MCIERR_INVALID_DEVICE_ID;
1161

1162 1163 1164 1165 1166 1167
    if (wmcda->hThread != 0) {
        /* Don't restart if the playLoop thread has already stopped */
        if(WaitForSingleObject(wmcda->stopEvent, 0) != WAIT_OBJECT_0 &&
           FAILED(IDirectSoundBuffer_Play(wmcda->dsBuf, 0, 0, DSBPLAY_LOOPING)))
            return MCIERR_HARDWARE;
    }
1168
    else if (!device_io(wmcda->handle, IOCTL_CDROM_RESUME_AUDIO, NULL, 0, NULL, 0, &br, NULL))
1169
        return MCIERR_HARDWARE;
1170

1171 1172
    if ((dwFlags & MCI_NOTIFY) && lpParms)
	MCICDA_Notify(lpParms->dwCallback, wmcda, MCI_NOTIFY_SUCCESSFUL);
1173
    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1174 1175 1176
}

/**************************************************************************
1177
 * 				MCICDA_Seek			[internal]
1178
 */
1179
static DWORD MCICDA_Seek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
Alexandre Julliard's avatar
Alexandre Julliard committed
1180
{
1181 1182 1183
    DWORD		        at;
    WINE_MCICDAUDIO*	        wmcda = MCICDA_GetOpenDrv(wDevID);
    CDROM_SEEK_AUDIO_MSF        seek;
1184
    DWORD                       br, position, ret;
1185
    CDROM_TOC			toc;
1186

1187
    TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
1188

1189
    if (wmcda == NULL)	return MCIERR_INVALID_DEVICE_ID;
1190
    if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1191

1192 1193 1194 1195
    position = dwFlags & (MCI_SEEK_TO_START|MCI_SEEK_TO_END|MCI_TO);
    if (!position)		return MCIERR_MISSING_PARAMETER;
    if (position&(position-1))	return MCIERR_FLAGS_NOT_COMPATIBLE;

Jörg Höhle's avatar
Jörg Höhle committed
1196 1197 1198 1199 1200
    /* Stop sends MCI_NOTIFY_ABORTED when needed.
     * Tests show that native first sends ABORTED and reads the TOC,
     * then only checks the position flags, then stops and seeks. */
    MCICDA_Stop(wDevID, MCI_WAIT, 0);

1201
    if (!device_io(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0,
1202 1203 1204 1205
                         &toc, sizeof(toc), &br, NULL)) {
        WARN("error reading TOC !\n");
        return MCICDA_GetError(wmcda);
    }
1206
    switch (position) {
1207
    case MCI_SEEK_TO_START:
1208
	TRACE("Seeking to start\n");
1209 1210 1211
	at = FRAME_OF_TOC(toc,toc.FirstTrack);
	if ( (ret=MCICDA_SkipDataTracks(wmcda, &at)) )
	  return ret;
1212 1213
	break;
    case MCI_SEEK_TO_END:
1214
	TRACE("Seeking to end\n");
Jörg Höhle's avatar
Jörg Höhle committed
1215 1216
	/* End is prior to lead-out
	 * yet Win9X seeks to even one frame less than that. */
1217
	at = FRAME_OF_TOC(toc, toc.LastTrack + 1) - 1;
1218 1219
	if ( (ret=MCICDA_SkipDataTracks(wmcda, &at)) )
	  return ret;
1220 1221
	break;
    case MCI_TO:
1222
	TRACE("Seeking to %u\n", lpParms->dwTo);
1223 1224 1225
        at = MCICDA_CalcFrame(wmcda, lpParms->dwTo);
	if ( (ret=MCICDA_SkipDataTracks(wmcda, &at)) )
	  return ret;
1226
	break;
1227
    default:
1228
	return MCIERR_FLAGS_NOT_COMPATIBLE;
1229
    }
1230

Jörg Höhle's avatar
Jörg Höhle committed
1231
    {
1232 1233 1234
        seek.M = at / CDFRAMES_PERMIN;
        seek.S = (at / CDFRAMES_PERSEC) % 60;
        seek.F = at % CDFRAMES_PERSEC;
1235
        if (!device_io(wmcda->handle, IOCTL_CDROM_SEEK_AUDIO_MSF, &seek, sizeof(seek),
1236 1237 1238
                             NULL, 0, &br, NULL))
            return MCIERR_HARDWARE;
    }
1239

1240 1241
    if (dwFlags & MCI_NOTIFY)
	MCICDA_Notify(lpParms->dwCallback, wmcda, MCI_NOTIFY_SUCCESSFUL);
1242
    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1243 1244
}

1245
/**************************************************************************
1246
 * 				MCICDA_SetDoor			[internal]
1247
 */
1248
static DWORD	MCICDA_SetDoor(UINT wDevID, BOOL open)
1249
{
1250
    WINE_MCICDAUDIO*	wmcda = MCICDA_GetOpenDrv(wDevID);
1251 1252
    DWORD               br;

1253
    TRACE("(%04x, %s) !\n", wDevID, (open) ? "OPEN" : "CLOSE");
1254

1255
    if (wmcda == NULL) return MCIERR_INVALID_DEVICE_ID;
1256

1257
    if (!device_io(wmcda->handle,
1258 1259
                         (open) ? IOCTL_STORAGE_EJECT_MEDIA : IOCTL_STORAGE_LOAD_MEDIA,
                         NULL, 0, NULL, 0, &br, NULL))
1260
	return MCIERR_HARDWARE;
1261

1262 1263
    return 0;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1264 1265

/**************************************************************************
1266
 * 				MCICDA_Set			[internal]
1267
 */
1268
static DWORD MCICDA_Set(UINT wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms)
Alexandre Julliard's avatar
Alexandre Julliard committed
1269
{
1270
    WINE_MCICDAUDIO*	wmcda = MCICDA_GetOpenDrv(wDevID);
1271

1272
    TRACE("(%04X, %08X, %p);\n", wDevID, dwFlags, lpParms);
1273

1274
    if (wmcda == NULL)	return MCIERR_INVALID_DEVICE_ID;
1275 1276 1277 1278 1279 1280 1281 1282 1283

    if (dwFlags & MCI_SET_DOOR_OPEN) {
	MCICDA_SetDoor(wDevID, TRUE);
    }
    if (dwFlags & MCI_SET_DOOR_CLOSED) {
	MCICDA_SetDoor(wDevID, FALSE);
    }

    /* only functions which require valid lpParms below this line ! */
1284
    if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
1285
    /*
1286
      TRACE("dwTimeFormat=%08lX\n", lpParms->dwTimeFormat);
1287 1288 1289 1290
    */
    if (dwFlags & MCI_SET_TIME_FORMAT) {
	switch (lpParms->dwTimeFormat) {
	case MCI_FORMAT_MILLISECONDS:
1291
	    TRACE("MCI_FORMAT_MILLISECONDS !\n");
1292 1293
	    break;
	case MCI_FORMAT_MSF:
1294
	    TRACE("MCI_FORMAT_MSF !\n");
1295 1296
	    break;
	case MCI_FORMAT_TMSF:
1297
	    TRACE("MCI_FORMAT_TMSF !\n");
1298 1299 1300 1301
	    break;
	default:
	    return MCIERR_BAD_TIME_FORMAT;
	}
1302
	wmcda->dwTimeFormat = lpParms->dwTimeFormat;
1303
    }
1304 1305
    if (dwFlags & MCI_SET_AUDIO) /* one xp machine ignored it */
	TRACE("SET_AUDIO %X %x\n", dwFlags, lpParms->dwAudio);
1306 1307 1308

    if (dwFlags & MCI_NOTIFY)
	MCICDA_Notify(lpParms->dwCallback, wmcda, MCI_NOTIFY_SUCCESSFUL);
1309
    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1310 1311 1312
}

/**************************************************************************
Patrik Stridvall's avatar
Patrik Stridvall committed
1313
 * 			DriverProc (MCICDA.@)
1314
 */
1315 1316
LRESULT CALLBACK MCICDA_DriverProc(DWORD_PTR dwDevID, HDRVR hDriv, UINT wMsg,
                                   LPARAM dwParam1, LPARAM dwParam2)
1317 1318 1319 1320
{
    switch(wMsg) {
    case DRV_LOAD:		return 1;
    case DRV_FREE:		return 1;
1321
    case DRV_OPEN:		return MCICDA_drvOpen((LPCWSTR)dwParam1, (LPMCI_OPEN_DRIVER_PARMSW)dwParam2);
1322
    case DRV_CLOSE:		return MCICDA_drvClose(dwDevID);
1323
    case DRV_ENABLE:		return 1;
1324 1325
    case DRV_DISABLE:		return 1;
    case DRV_QUERYCONFIGURE:	return 1;
1326
    case DRV_CONFIGURE:		MessageBoxA(0, "MCI audio CD driver !", "Wine Driver", MB_OK); return 1;
1327 1328
    case DRV_INSTALL:		return DRVCNF_RESTART;
    case DRV_REMOVE:		return DRVCNF_RESTART;
1329
    }
1330

1331 1332 1333
    if (dwDevID == 0xFFFFFFFF) return MCIERR_UNSUPPORTED_FUNCTION;

    switch (wMsg) {
1334
    case MCI_OPEN_DRIVER:	return MCICDA_Open(dwDevID, dwParam1, (LPMCI_OPEN_PARMSW)dwParam2);
1335 1336
    case MCI_CLOSE_DRIVER:	return MCICDA_Close(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
    case MCI_GETDEVCAPS:	return MCICDA_GetDevCaps(dwDevID, dwParam1, (LPMCI_GETDEVCAPS_PARMS)dwParam2);
1337
    case MCI_INFO:		return MCICDA_Info(dwDevID, dwParam1, (LPMCI_INFO_PARMSW)dwParam2);
1338 1339 1340 1341 1342 1343 1344
    case MCI_STATUS:		return MCICDA_Status(dwDevID, dwParam1, (LPMCI_STATUS_PARMS)dwParam2);
    case MCI_SET:		return MCICDA_Set(dwDevID, dwParam1, (LPMCI_SET_PARMS)dwParam2);
    case MCI_PLAY:		return MCICDA_Play(dwDevID, dwParam1, (LPMCI_PLAY_PARMS)dwParam2);
    case MCI_STOP:		return MCICDA_Stop(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
    case MCI_PAUSE:		return MCICDA_Pause(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
    case MCI_RESUME:		return MCICDA_Resume(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)dwParam2);
    case MCI_SEEK:		return MCICDA_Seek(dwDevID, dwParam1, (LPMCI_SEEK_PARMS)dwParam2);
1345 1346
    /* commands that should report an error as they are not supported in
     * the native version */
1347
    case MCI_RECORD:
1348 1349
    case MCI_LOAD:
    case MCI_SAVE:
1350 1351
	return MCIERR_UNSUPPORTED_FUNCTION;
    case MCI_BREAK:
1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365
    case MCI_FREEZE:
    case MCI_PUT:
    case MCI_REALIZE:
    case MCI_UNFREEZE:
    case MCI_UPDATE:
    case MCI_WHERE:
    case MCI_STEP:
    case MCI_SPIN:
    case MCI_ESCAPE:
    case MCI_COPY:
    case MCI_CUT:
    case MCI_DELETE:
    case MCI_PASTE:
    case MCI_WINDOW:
1366
	TRACE("Unsupported command [0x%x]\n", wMsg);
1367 1368 1369
	break;
    case MCI_OPEN:
    case MCI_CLOSE:
1370
	ERR("Shouldn't receive a MCI_OPEN or CLOSE message\n");
1371
	break;
1372
    default:
1373
	TRACE("Sending msg [0x%x] to default driver proc\n", wMsg);
1374
	return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1375
    }
1376
    return MCIERR_UNRECOGNIZED_COMMAND;
Alexandre Julliard's avatar
Alexandre Julliard committed
1377 1378 1379
}

/*-----------------------------------------------------------------------*/