2 * MCI driver for audio CD (MCICDA)
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1998-99 Eric Pouech
6 * Copyright 2000 Andreas Mohr
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * 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
28 #define WIN32_NO_STATUS
38 #include "wine/debug.h"
39 #include "wine/unicode.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(mcicda
);
44 #define CDFRAMES_PERSEC 75
45 #define CDFRAMES_PERMIN (CDFRAMES_PERSEC * 60)
46 #define FRAME_OF_ADDR(a) ((a)[1] * CDFRAMES_PERMIN + (a)[2] * CDFRAMES_PERSEC + (a)[3])
47 #define FRAME_OF_TOC(toc, idx) FRAME_OF_ADDR((toc).TrackData[idx - (toc).FirstTrack].Address)
49 /* Defined by red-book standard; do not change! */
50 #define RAW_SECTOR_SIZE (2352)
52 /* Must be >= RAW_SECTOR_SIZE */
53 #define CDDA_FRAG_SIZE (32768)
55 #define CDDA_FRAG_COUNT (3)
59 int nUseCount
; /* Incremented for each shared open */
60 BOOL fShareable
; /* TRUE if first open was shareable */
61 WORD wNotifyDeviceID
; /* MCI device ID with a pending notification */
62 HANDLE hCallback
; /* Callback handle for pending notification */
66 /* The following are used for digital playback only */
72 IDirectSoundBuffer
*dsBuf
;
77 /*-----------------------------------------------------------------------*/
79 typedef HRESULT(WINAPI
*LPDIRECTSOUNDCREATE
)(LPCGUID
,LPDIRECTSOUND
*,LPUNKNOWN
);
80 static LPDIRECTSOUNDCREATE pDirectSoundCreate
;
82 static DWORD CALLBACK
MCICDA_playLoop(void *ptr
)
84 WINE_MCICDAUDIO
*wmcda
= (WINE_MCICDAUDIO
*)ptr
;
85 DWORD lastPos
, curPos
, endPos
, br
;
87 DWORD lockLen
, fragLen
;
92 memset(&caps
, 0, sizeof(caps
));
93 caps
.dwSize
= sizeof(caps
);
94 hr
= IDirectSoundBuffer_GetCaps(wmcda
->dsBuf
, &caps
);
96 fragLen
= caps
.dwBufferBytes
/CDDA_FRAG_COUNT
;
99 while (SUCCEEDED(hr
) && endPos
!= lastPos
&&
100 WaitForSingleObject(wmcda
->stopEvent
, 0) != WAIT_OBJECT_0
) {
101 hr
= IDirectSoundBuffer_GetCurrentPosition(wmcda
->dsBuf
, &curPos
, NULL
);
102 if ((curPos
-lastPos
+caps
.dwBufferBytes
)%caps
.dwBufferBytes
< fragLen
) {
107 EnterCriticalSection(&wmcda
->cs
);
108 rdInfo
.DiskOffset
.QuadPart
= wmcda
->start
<<11;
109 rdInfo
.SectorCount
= min(fragLen
/RAW_SECTOR_SIZE
, wmcda
->end
-wmcda
->start
);
110 rdInfo
.TrackMode
= CDDA
;
112 hr
= IDirectSoundBuffer_Lock(wmcda
->dsBuf
, lastPos
, fragLen
, &cdData
, &lockLen
, NULL
, NULL
, 0);
113 if (hr
== DSERR_BUFFERLOST
) {
114 if(FAILED(IDirectSoundBuffer_Restore(wmcda
->dsBuf
)) ||
115 FAILED(IDirectSoundBuffer_Play(wmcda
->dsBuf
, 0, 0, DSBPLAY_LOOPING
))) {
116 LeaveCriticalSection(&wmcda
->cs
);
119 hr
= IDirectSoundBuffer_Lock(wmcda
->dsBuf
, lastPos
, fragLen
, &cdData
, &lockLen
, NULL
, NULL
, 0);
123 if (rdInfo
.SectorCount
> 0) {
124 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_RAW_READ
, &rdInfo
, sizeof(rdInfo
), cdData
, lockLen
, &br
, NULL
))
125 WARN("CD read failed at sector %d: 0x%x\n", wmcda
->start
, GetLastError());
127 if (rdInfo
.SectorCount
*RAW_SECTOR_SIZE
< lockLen
) {
128 if(endPos
== ~0u) endPos
= lastPos
;
129 memset((BYTE
*)cdData
+ rdInfo
.SectorCount
*RAW_SECTOR_SIZE
, 0,
130 lockLen
- rdInfo
.SectorCount
*RAW_SECTOR_SIZE
);
132 hr
= IDirectSoundBuffer_Unlock(wmcda
->dsBuf
, cdData
, lockLen
, NULL
, 0);
136 lastPos
%= caps
.dwBufferBytes
;
137 wmcda
->start
+= rdInfo
.SectorCount
;
139 LeaveCriticalSection(&wmcda
->cs
);
141 IDirectSoundBuffer_Stop(wmcda
->dsBuf
);
142 SetEvent(wmcda
->stopEvent
);
144 EnterCriticalSection(&wmcda
->cs
);
145 if (wmcda
->hCallback
) {
146 mciDriverNotify(wmcda
->hCallback
, wmcda
->wNotifyDeviceID
,
147 FAILED(hr
) ? MCI_NOTIFY_FAILURE
:
148 ((endPos
!=lastPos
) ? MCI_NOTIFY_ABORTED
:
149 MCI_NOTIFY_SUCCESSFUL
));
150 wmcda
->hCallback
= NULL
;
152 LeaveCriticalSection(&wmcda
->cs
);
160 /**************************************************************************
161 * MCICDA_drvOpen [internal]
163 static DWORD
MCICDA_drvOpen(LPCWSTR str
, LPMCI_OPEN_DRIVER_PARMSW modp
)
165 static HMODULE dsHandle
;
166 WINE_MCICDAUDIO
* wmcda
;
168 if (!modp
) return 0xFFFFFFFF;
170 wmcda
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(WINE_MCICDAUDIO
));
176 dsHandle
= LoadLibraryA("dsound.dll");
178 pDirectSoundCreate
= (LPDIRECTSOUNDCREATE
)GetProcAddress(dsHandle
, "DirectSoundCreate");
181 wmcda
->wDevID
= modp
->wDeviceID
;
182 mciSetDriverData(wmcda
->wDevID
, (DWORD_PTR
)wmcda
);
183 modp
->wCustomCommandTable
= MCI_NO_COMMAND_TABLE
;
184 modp
->wType
= MCI_DEVTYPE_CD_AUDIO
;
185 InitializeCriticalSection(&wmcda
->cs
);
186 return modp
->wDeviceID
;
189 /**************************************************************************
190 * MCICDA_drvClose [internal]
192 static DWORD
MCICDA_drvClose(DWORD dwDevID
)
194 WINE_MCICDAUDIO
* wmcda
= (WINE_MCICDAUDIO
*)mciGetDriverData(dwDevID
);
197 DeleteCriticalSection(&wmcda
->cs
);
198 HeapFree(GetProcessHeap(), 0, wmcda
);
199 mciSetDriverData(dwDevID
, 0);
201 return (dwDevID
== 0xFFFFFFFF) ? 1 : 0;
204 /**************************************************************************
205 * MCICDA_GetOpenDrv [internal]
207 static WINE_MCICDAUDIO
* MCICDA_GetOpenDrv(UINT wDevID
)
209 WINE_MCICDAUDIO
* wmcda
= (WINE_MCICDAUDIO
*)mciGetDriverData(wDevID
);
211 if (wmcda
== NULL
|| wmcda
->nUseCount
== 0) {
212 WARN("Invalid wDevID=%u\n", wDevID
);
218 /**************************************************************************
219 * MCICDA_GetStatus [internal]
221 static DWORD
MCICDA_GetStatus(WINE_MCICDAUDIO
* wmcda
)
223 CDROM_SUB_Q_DATA_FORMAT fmt
;
224 SUB_Q_CHANNEL_DATA data
;
226 DWORD mode
= MCI_MODE_NOT_READY
;
228 fmt
.Format
= IOCTL_CDROM_CURRENT_POSITION
;
229 if(wmcda
->hThread
!= 0) {
233 hr
= IDirectSoundBuffer_GetStatus(wmcda
->dsBuf
, &status
);
235 if(!(status
&DSBSTATUS_PLAYING
)) {
236 if(WaitForSingleObject(wmcda
->stopEvent
, 0) == WAIT_OBJECT_0
)
237 mode
= MCI_MODE_STOP
;
239 mode
= MCI_MODE_PAUSE
;
242 mode
= MCI_MODE_PLAY
;
245 else if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_Q_CHANNEL
, &fmt
, sizeof(fmt
),
246 &data
, sizeof(data
), &br
, NULL
)) {
247 if (GetLastError() == ERROR_NOT_READY
) mode
= MCI_MODE_OPEN
;
249 switch (data
.CurrentPosition
.Header
.AudioStatus
)
251 case AUDIO_STATUS_IN_PROGRESS
: mode
= MCI_MODE_PLAY
; break;
252 case AUDIO_STATUS_PAUSED
: mode
= MCI_MODE_PAUSE
; break;
253 case AUDIO_STATUS_NO_STATUS
:
254 case AUDIO_STATUS_PLAY_COMPLETE
: mode
= MCI_MODE_STOP
; break;
255 case AUDIO_STATUS_PLAY_ERROR
:
256 case AUDIO_STATUS_NOT_SUPPORTED
:
264 /**************************************************************************
265 * MCICDA_GetError [internal]
267 static int MCICDA_GetError(WINE_MCICDAUDIO
* wmcda
)
269 switch (GetLastError())
271 case ERROR_NOT_READY
: return MCIERR_DEVICE_NOT_READY
;
272 case ERROR_IO_DEVICE
: return MCIERR_HARDWARE
;
274 FIXME("Unknown mode %u\n", GetLastError());
276 return MCIERR_DRIVER_INTERNAL
;
279 /**************************************************************************
280 * MCICDA_CalcFrame [internal]
282 static DWORD
MCICDA_CalcFrame(WINE_MCICDAUDIO
* wmcda
, DWORD dwTime
)
290 TRACE("(%p, %08X, %u);\n", wmcda
, wmcda
->dwTimeFormat
, dwTime
);
292 switch (wmcda
->dwTimeFormat
) {
293 case MCI_FORMAT_MILLISECONDS
:
294 dwFrame
= ((dwTime
- 1) * CDFRAMES_PERSEC
+ 500) / 1000;
295 TRACE("MILLISECONDS %u\n", dwFrame
);
298 TRACE("MSF %02u:%02u:%02u\n",
299 MCI_MSF_MINUTE(dwTime
), MCI_MSF_SECOND(dwTime
), MCI_MSF_FRAME(dwTime
));
300 dwFrame
+= CDFRAMES_PERMIN
* MCI_MSF_MINUTE(dwTime
);
301 dwFrame
+= CDFRAMES_PERSEC
* MCI_MSF_SECOND(dwTime
);
302 dwFrame
+= MCI_MSF_FRAME(dwTime
);
304 case MCI_FORMAT_TMSF
:
305 default: /* unknown format ! force TMSF ! ... */
306 wTrack
= MCI_TMSF_TRACK(dwTime
);
307 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_TOC
, NULL
, 0,
308 &toc
, sizeof(toc
), &br
, NULL
))
310 if (wTrack
< toc
.FirstTrack
|| wTrack
> toc
.LastTrack
)
312 TRACE("MSF %02u-%02u:%02u:%02u\n",
313 MCI_TMSF_TRACK(dwTime
), MCI_TMSF_MINUTE(dwTime
),
314 MCI_TMSF_SECOND(dwTime
), MCI_TMSF_FRAME(dwTime
));
315 addr
= toc
.TrackData
[wTrack
- toc
.FirstTrack
].Address
;
316 TRACE("TMSF trackpos[%u]=%d:%d:%d\n",
317 wTrack
, addr
[1], addr
[2], addr
[3]);
318 dwFrame
= CDFRAMES_PERMIN
* (addr
[1] + MCI_TMSF_MINUTE(dwTime
)) +
319 CDFRAMES_PERSEC
* (addr
[2] + MCI_TMSF_SECOND(dwTime
)) +
320 addr
[3] + MCI_TMSF_FRAME(dwTime
);
326 /**************************************************************************
327 * MCICDA_CalcTime [internal]
329 static DWORD
MCICDA_CalcTime(WINE_MCICDAUDIO
* wmcda
, DWORD tf
, DWORD dwFrame
, LPDWORD lpRet
)
339 TRACE("(%p, %08X, %u);\n", wmcda
, tf
, dwFrame
);
342 case MCI_FORMAT_MILLISECONDS
:
343 dwTime
= (dwFrame
* 1000) / CDFRAMES_PERSEC
+ 1;
344 TRACE("MILLISECONDS %u\n", dwTime
);
348 wMinutes
= dwFrame
/ CDFRAMES_PERMIN
;
349 wSeconds
= (dwFrame
- CDFRAMES_PERMIN
* wMinutes
) / CDFRAMES_PERSEC
;
350 wFrames
= dwFrame
- CDFRAMES_PERMIN
* wMinutes
- CDFRAMES_PERSEC
* wSeconds
;
351 dwTime
= MCI_MAKE_MSF(wMinutes
, wSeconds
, wFrames
);
352 TRACE("MSF %02u:%02u:%02u -> dwTime=%u\n",
353 wMinutes
, wSeconds
, wFrames
, dwTime
);
354 *lpRet
= MCI_COLONIZED3_RETURN
;
356 case MCI_FORMAT_TMSF
:
357 default: /* unknown format ! force TMSF ! ... */
358 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_TOC
, NULL
, 0,
359 &toc
, sizeof(toc
), &br
, NULL
))
361 if (dwFrame
< FRAME_OF_TOC(toc
, toc
.FirstTrack
) ||
362 dwFrame
> FRAME_OF_TOC(toc
, toc
.LastTrack
+ 1)) {
363 ERR("Out of range value %u [%u,%u]\n",
364 dwFrame
, FRAME_OF_TOC(toc
, toc
.FirstTrack
),
365 FRAME_OF_TOC(toc
, toc
.LastTrack
+ 1));
369 for (wTrack
= toc
.FirstTrack
; wTrack
<= toc
.LastTrack
; wTrack
++) {
370 if (FRAME_OF_TOC(toc
, wTrack
) > dwFrame
)
374 dwFrame
-= FRAME_OF_TOC(toc
, wTrack
);
375 wMinutes
= dwFrame
/ CDFRAMES_PERMIN
;
376 wSeconds
= (dwFrame
- CDFRAMES_PERMIN
* wMinutes
) / CDFRAMES_PERSEC
;
377 wFrames
= dwFrame
- CDFRAMES_PERMIN
* wMinutes
- CDFRAMES_PERSEC
* wSeconds
;
378 dwTime
= MCI_MAKE_TMSF(wTrack
, wMinutes
, wSeconds
, wFrames
);
379 TRACE("%02u-%02u:%02u:%02u\n", wTrack
, wMinutes
, wSeconds
, wFrames
);
380 *lpRet
= MCI_COLONIZED4_RETURN
;
386 static DWORD
MCICDA_Seek(UINT wDevID
, DWORD dwFlags
, LPMCI_SEEK_PARMS lpParms
);
387 static DWORD
MCICDA_Stop(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
);
389 /**************************************************************************
390 * MCICDA_Open [internal]
392 static DWORD
MCICDA_Open(UINT wDevID
, DWORD dwFlags
, LPMCI_OPEN_PARMSW lpOpenParms
)
395 DWORD ret
= MCIERR_HARDWARE
;
396 WINE_MCICDAUDIO
* wmcda
= (WINE_MCICDAUDIO
*)mciGetDriverData(wDevID
);
397 WCHAR root
[7], drive
= 0;
400 TRACE("(%04X, %08X, %p);\n", wDevID
, dwFlags
, lpOpenParms
);
402 if (lpOpenParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
403 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
405 dwDeviceID
= lpOpenParms
->wDeviceID
;
407 if (wmcda
->nUseCount
> 0) {
408 /* The driver is already open on this channel */
409 /* If the driver was opened shareable before and this open specifies */
410 /* shareable then increment the use count */
411 if (wmcda
->fShareable
&& (dwFlags
& MCI_OPEN_SHAREABLE
))
414 return MCIERR_MUST_USE_SHAREABLE
;
416 wmcda
->nUseCount
= 1;
417 wmcda
->fShareable
= dwFlags
& MCI_OPEN_SHAREABLE
;
419 if (dwFlags
& MCI_OPEN_ELEMENT
) {
420 if (dwFlags
& MCI_OPEN_ELEMENT_ID
) {
421 WARN("MCI_OPEN_ELEMENT_ID %p! Abort\n", lpOpenParms
->lpstrElementName
);
422 ret
= MCIERR_NO_ELEMENT_ALLOWED
;
425 TRACE("MCI_OPEN_ELEMENT element name: %s\n", debugstr_w(lpOpenParms
->lpstrElementName
));
426 if (!isalpha(lpOpenParms
->lpstrElementName
[0]) || lpOpenParms
->lpstrElementName
[1] != ':' ||
427 (lpOpenParms
->lpstrElementName
[2] && lpOpenParms
->lpstrElementName
[2] != '\\'))
429 WARN("MCI_OPEN_ELEMENT unsupported format: %s\n",
430 debugstr_w(lpOpenParms
->lpstrElementName
));
431 ret
= MCIERR_NO_ELEMENT_ALLOWED
;
434 drive
= toupper(lpOpenParms
->lpstrElementName
[0]);
435 root
[0] = drive
; root
[1] = ':'; root
[2] = '\\'; root
[3] = '\0';
436 if (GetDriveTypeW(root
) != DRIVE_CDROM
)
438 ret
= MCIERR_INVALID_DEVICE_NAME
;
444 /* drive letter isn't passed... get the dwDeviceID'th cdrom in the system */
445 root
[0] = 'A'; root
[1] = ':'; root
[2] = '\\'; root
[3] = '\0';
446 for (count
= 0; root
[0] <= 'Z'; root
[0]++)
448 if (GetDriveTypeW(root
) == DRIVE_CDROM
&& ++count
>= dwDeviceID
)
456 ret
= MCIERR_INVALID_DEVICE_ID
;
461 wmcda
->wNotifyDeviceID
= dwDeviceID
;
462 wmcda
->dwTimeFormat
= MCI_FORMAT_MSF
;
464 /* now, open the handle */
465 root
[0] = root
[1] = '\\'; root
[2] = '.'; root
[3] = '\\'; root
[4] = drive
; root
[5] = ':'; root
[6] = '\0';
466 wmcda
->handle
= CreateFileW(root
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0);
467 if (wmcda
->handle
== INVALID_HANDLE_VALUE
)
470 if (dwFlags
& MCI_NOTIFY
) {
471 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpOpenParms
->dwCallback
);
472 mciDriverNotify(HWND_32(LOWORD(lpOpenParms
->dwCallback
)),
473 wmcda
->wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
482 /**************************************************************************
483 * MCICDA_Close [internal]
485 static DWORD
MCICDA_Close(UINT wDevID
, DWORD dwParam
, LPMCI_GENERIC_PARMS lpParms
)
487 WINE_MCICDAUDIO
* wmcda
= MCICDA_GetOpenDrv(wDevID
);
489 TRACE("(%04X, %08X, %p);\n", wDevID
, dwParam
, lpParms
);
491 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
493 MCICDA_Stop(wDevID
, MCI_WAIT
, NULL
);
495 if (--wmcda
->nUseCount
== 0) {
496 CloseHandle(wmcda
->handle
);
501 /**************************************************************************
502 * MCICDA_GetDevCaps [internal]
504 static DWORD
MCICDA_GetDevCaps(UINT wDevID
, DWORD dwFlags
,
505 LPMCI_GETDEVCAPS_PARMS lpParms
)
509 TRACE("(%04X, %08X, %p);\n", wDevID
, dwFlags
, lpParms
);
511 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
513 if (dwFlags
& MCI_GETDEVCAPS_ITEM
) {
514 TRACE("MCI_GETDEVCAPS_ITEM dwItem=%08X;\n", lpParms
->dwItem
);
516 switch (lpParms
->dwItem
) {
517 case MCI_GETDEVCAPS_CAN_RECORD
:
518 lpParms
->dwReturn
= MAKEMCIRESOURCE(FALSE
, MCI_FALSE
);
519 ret
= MCI_RESOURCE_RETURNED
;
521 case MCI_GETDEVCAPS_HAS_AUDIO
:
522 lpParms
->dwReturn
= MAKEMCIRESOURCE(TRUE
, MCI_TRUE
);
523 ret
= MCI_RESOURCE_RETURNED
;
525 case MCI_GETDEVCAPS_HAS_VIDEO
:
526 lpParms
->dwReturn
= MAKEMCIRESOURCE(FALSE
, MCI_FALSE
);
527 ret
= MCI_RESOURCE_RETURNED
;
529 case MCI_GETDEVCAPS_DEVICE_TYPE
:
530 lpParms
->dwReturn
= MAKEMCIRESOURCE(MCI_DEVTYPE_CD_AUDIO
, MCI_DEVTYPE_CD_AUDIO
);
531 ret
= MCI_RESOURCE_RETURNED
;
533 case MCI_GETDEVCAPS_USES_FILES
:
534 lpParms
->dwReturn
= MAKEMCIRESOURCE(FALSE
, MCI_FALSE
);
535 ret
= MCI_RESOURCE_RETURNED
;
537 case MCI_GETDEVCAPS_COMPOUND_DEVICE
:
538 lpParms
->dwReturn
= MAKEMCIRESOURCE(FALSE
, MCI_FALSE
);
539 ret
= MCI_RESOURCE_RETURNED
;
541 case MCI_GETDEVCAPS_CAN_EJECT
:
542 lpParms
->dwReturn
= MAKEMCIRESOURCE(TRUE
, MCI_TRUE
);
543 ret
= MCI_RESOURCE_RETURNED
;
545 case MCI_GETDEVCAPS_CAN_PLAY
:
546 lpParms
->dwReturn
= MAKEMCIRESOURCE(TRUE
, MCI_TRUE
);
547 ret
= MCI_RESOURCE_RETURNED
;
549 case MCI_GETDEVCAPS_CAN_SAVE
:
550 lpParms
->dwReturn
= MAKEMCIRESOURCE(FALSE
, MCI_FALSE
);
551 ret
= MCI_RESOURCE_RETURNED
;
554 ERR("Unsupported %x devCaps item\n", lpParms
->dwItem
);
555 return MCIERR_UNRECOGNIZED_COMMAND
;
558 TRACE("No GetDevCaps-Item !\n");
559 return MCIERR_UNRECOGNIZED_COMMAND
;
561 TRACE("lpParms->dwReturn=%08X;\n", lpParms
->dwReturn
);
565 static DWORD
CDROM_Audio_GetSerial(CDROM_TOC
* toc
)
570 DWORD dwStart
, dwEnd
;
573 * wMagic collects the wFrames from track 1
574 * dwStart, dwEnd collect the beginning and end of the disc respectively, in
576 * There it is collected for correcting the serial when there are less than
579 wMagic
= toc
->TrackData
[0].Address
[3];
580 dwStart
= FRAME_OF_TOC(*toc
, toc
->FirstTrack
);
582 for (i
= 0; i
<= toc
->LastTrack
- toc
->FirstTrack
; i
++) {
583 serial
+= (toc
->TrackData
[i
].Address
[1] << 16) |
584 (toc
->TrackData
[i
].Address
[2] << 8) | toc
->TrackData
[i
].Address
[3];
586 dwEnd
= FRAME_OF_TOC(*toc
, toc
->LastTrack
+ 1);
588 if (toc
->LastTrack
- toc
->FirstTrack
+ 1 < 3)
589 serial
+= wMagic
+ (dwEnd
- dwStart
);
595 /**************************************************************************
596 * MCICDA_Info [internal]
598 static DWORD
MCICDA_Info(UINT wDevID
, DWORD dwFlags
, LPMCI_INFO_PARMSW lpParms
)
601 WINE_MCICDAUDIO
* wmcda
= MCICDA_GetOpenDrv(wDevID
);
605 TRACE("(%04X, %08X, %p);\n", wDevID
, dwFlags
, lpParms
);
607 if (lpParms
== NULL
|| lpParms
->lpstrReturn
== NULL
)
608 return MCIERR_NULL_PARAMETER_BLOCK
;
609 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
611 TRACE("buf=%p, len=%u\n", lpParms
->lpstrReturn
, lpParms
->dwRetSize
);
613 if (dwFlags
& MCI_INFO_PRODUCT
) {
614 static const WCHAR wszAudioCd
[] = {'W','i','n','e','\'','s',' ','a','u','d','i','o',' ','C','D',0};
616 } else if (dwFlags
& MCI_INFO_MEDIA_UPC
) {
617 ret
= MCIERR_NO_IDENTITY
;
618 } else if (dwFlags
& MCI_INFO_MEDIA_IDENTITY
) {
622 static const WCHAR wszLu
[] = {'%','l','u',0};
624 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_TOC
, NULL
, 0,
625 &toc
, sizeof(toc
), &br
, NULL
)) {
626 return MCICDA_GetError(wmcda
);
629 res
= CDROM_Audio_GetSerial(&toc
);
630 sprintfW(buffer
, wszLu
, res
);
633 WARN("Don't know this info command (%u)\n", dwFlags
);
634 ret
= MCIERR_UNRECOGNIZED_COMMAND
;
637 if (lpParms
->dwRetSize
<= strlenW(str
)) {
638 lstrcpynW(lpParms
->lpstrReturn
, str
, lpParms
->dwRetSize
- 1);
639 ret
= MCIERR_PARAM_OVERFLOW
;
641 strcpyW(lpParms
->lpstrReturn
, str
);
644 *lpParms
->lpstrReturn
= 0;
646 TRACE("=> %s (%d)\n", debugstr_w(lpParms
->lpstrReturn
), ret
);
650 /**************************************************************************
651 * MCICDA_Status [internal]
653 static DWORD
MCICDA_Status(UINT wDevID
, DWORD dwFlags
, LPMCI_STATUS_PARMS lpParms
)
655 WINE_MCICDAUDIO
* wmcda
= MCICDA_GetOpenDrv(wDevID
);
657 CDROM_SUB_Q_DATA_FORMAT fmt
;
658 SUB_Q_CHANNEL_DATA data
;
662 TRACE("(%04X, %08X, %p);\n", wDevID
, dwFlags
, lpParms
);
664 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
665 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
667 if (dwFlags
& MCI_NOTIFY
) {
668 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
669 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)),
670 wmcda
->wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
672 if (dwFlags
& MCI_STATUS_ITEM
) {
673 TRACE("dwItem = %x\n", lpParms
->dwItem
);
674 switch (lpParms
->dwItem
) {
675 case MCI_STATUS_CURRENT_TRACK
:
676 fmt
.Format
= IOCTL_CDROM_CURRENT_POSITION
;
677 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_Q_CHANNEL
, &fmt
, sizeof(fmt
),
678 &data
, sizeof(data
), &br
, NULL
))
680 return MCICDA_GetError(wmcda
);
682 lpParms
->dwReturn
= data
.CurrentPosition
.TrackNumber
;
683 TRACE("CURRENT_TRACK=%lu\n", lpParms
->dwReturn
);
685 case MCI_STATUS_LENGTH
:
686 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_TOC
, NULL
, 0,
687 &toc
, sizeof(toc
), &br
, NULL
)) {
688 WARN("error reading TOC !\n");
689 return MCICDA_GetError(wmcda
);
691 if (dwFlags
& MCI_TRACK
) {
692 TRACE("MCI_TRACK #%u LENGTH=??? !\n", lpParms
->dwTrack
);
693 if (lpParms
->dwTrack
< toc
.FirstTrack
|| lpParms
->dwTrack
> toc
.LastTrack
)
694 return MCIERR_OUTOFRANGE
;
695 lpParms
->dwReturn
= FRAME_OF_TOC(toc
, lpParms
->dwTrack
+ 1) -
696 FRAME_OF_TOC(toc
, lpParms
->dwTrack
);
697 /* Windows returns one frame less than the total track length for the
698 last track on the CD. See CDDB HOWTO. Verified on Win95OSR2. */
699 if (lpParms
->dwTrack
== toc
.LastTrack
)
702 /* Sum of the lengths of all of the tracks. Inherits the
703 'off by one frame' behavior from the length of the last track.
704 See above comment. */
705 lpParms
->dwReturn
= FRAME_OF_TOC(toc
, toc
.LastTrack
+ 1) -
706 FRAME_OF_TOC(toc
, toc
.FirstTrack
) - 1;
708 lpParms
->dwReturn
= MCICDA_CalcTime(wmcda
,
709 (wmcda
->dwTimeFormat
== MCI_FORMAT_TMSF
)
710 ? MCI_FORMAT_MSF
: wmcda
->dwTimeFormat
,
713 TRACE("LENGTH=%lu\n", lpParms
->dwReturn
);
715 case MCI_STATUS_MODE
:
716 lpParms
->dwReturn
= MCICDA_GetStatus(wmcda
);
717 TRACE("MCI_STATUS_MODE=%08lX\n", lpParms
->dwReturn
);
718 lpParms
->dwReturn
= MAKEMCIRESOURCE(lpParms
->dwReturn
, lpParms
->dwReturn
);
719 ret
= MCI_RESOURCE_RETURNED
;
721 case MCI_STATUS_MEDIA_PRESENT
:
722 lpParms
->dwReturn
= (MCICDA_GetStatus(wmcda
) == MCI_MODE_OPEN
) ?
723 MAKEMCIRESOURCE(FALSE
, MCI_FALSE
) : MAKEMCIRESOURCE(TRUE
, MCI_TRUE
);
724 TRACE("MCI_STATUS_MEDIA_PRESENT =%c!\n", LOWORD(lpParms
->dwReturn
) ? 'Y' : 'N');
725 ret
= MCI_RESOURCE_RETURNED
;
727 case MCI_STATUS_NUMBER_OF_TRACKS
:
728 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_TOC
, NULL
, 0,
729 &toc
, sizeof(toc
), &br
, NULL
)) {
730 WARN("error reading TOC !\n");
731 return MCICDA_GetError(wmcda
);
733 lpParms
->dwReturn
= toc
.LastTrack
- toc
.FirstTrack
+ 1;
734 TRACE("MCI_STATUS_NUMBER_OF_TRACKS = %lu\n", lpParms
->dwReturn
);
735 if (lpParms
->dwReturn
== (WORD
)-1)
736 return MCICDA_GetError(wmcda
);
738 case MCI_STATUS_POSITION
:
739 if (dwFlags
& MCI_STATUS_START
) {
740 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_TOC
, NULL
, 0,
741 &toc
, sizeof(toc
), &br
, NULL
)) {
742 WARN("error reading TOC !\n");
743 return MCICDA_GetError(wmcda
);
745 lpParms
->dwReturn
= FRAME_OF_TOC(toc
, toc
.FirstTrack
);
746 TRACE("get MCI_STATUS_START !\n");
747 } else if (dwFlags
& MCI_TRACK
) {
748 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_TOC
, NULL
, 0,
749 &toc
, sizeof(toc
), &br
, NULL
)) {
750 WARN("error reading TOC !\n");
751 return MCICDA_GetError(wmcda
);
753 if (lpParms
->dwTrack
< toc
.FirstTrack
|| lpParms
->dwTrack
> toc
.LastTrack
)
754 return MCIERR_OUTOFRANGE
;
755 lpParms
->dwReturn
= FRAME_OF_TOC(toc
, lpParms
->dwTrack
);
756 TRACE("get MCI_TRACK #%u !\n", lpParms
->dwTrack
);
758 fmt
.Format
= IOCTL_CDROM_CURRENT_POSITION
;
759 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_Q_CHANNEL
, &fmt
, sizeof(fmt
),
760 &data
, sizeof(data
), &br
, NULL
)) {
761 return MCICDA_GetError(wmcda
);
763 lpParms
->dwReturn
= FRAME_OF_ADDR(data
.CurrentPosition
.AbsoluteAddress
);
765 lpParms
->dwReturn
= MCICDA_CalcTime(wmcda
, wmcda
->dwTimeFormat
, lpParms
->dwReturn
, &ret
);
766 TRACE("MCI_STATUS_POSITION=%08lX\n", lpParms
->dwReturn
);
768 case MCI_STATUS_READY
:
769 TRACE("MCI_STATUS_READY !\n");
770 switch (MCICDA_GetStatus(wmcda
))
772 case MCI_MODE_NOT_READY
:
774 lpParms
->dwReturn
= MAKEMCIRESOURCE(FALSE
, MCI_FALSE
);
777 lpParms
->dwReturn
= MAKEMCIRESOURCE(TRUE
, MCI_TRUE
);
780 TRACE("MCI_STATUS_READY=%u!\n", LOWORD(lpParms
->dwReturn
));
781 ret
= MCI_RESOURCE_RETURNED
;
783 case MCI_STATUS_TIME_FORMAT
:
784 lpParms
->dwReturn
= MAKEMCIRESOURCE(wmcda
->dwTimeFormat
, MCI_FORMAT_RETURN_BASE
+ wmcda
->dwTimeFormat
);
785 TRACE("MCI_STATUS_TIME_FORMAT=%08x!\n", LOWORD(lpParms
->dwReturn
));
786 ret
= MCI_RESOURCE_RETURNED
;
788 case 4001: /* FIXME: for bogus FullCD */
789 case MCI_CDA_STATUS_TYPE_TRACK
:
790 if (!(dwFlags
& MCI_TRACK
))
791 ret
= MCIERR_MISSING_PARAMETER
;
793 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_TOC
, NULL
, 0,
794 &toc
, sizeof(toc
), &br
, NULL
)) {
795 WARN("error reading TOC !\n");
796 return MCICDA_GetError(wmcda
);
798 if (lpParms
->dwTrack
< toc
.FirstTrack
|| lpParms
->dwTrack
> toc
.LastTrack
)
799 ret
= MCIERR_OUTOFRANGE
;
801 lpParms
->dwReturn
= (toc
.TrackData
[lpParms
->dwTrack
- toc
.FirstTrack
].Control
& 0x04) ?
802 MCI_CDA_TRACK_OTHER
: MCI_CDA_TRACK_AUDIO
;
804 TRACE("MCI_CDA_STATUS_TYPE_TRACK[%d]=%ld\n", lpParms
->dwTrack
, lpParms
->dwReturn
);
807 FIXME("unknown command %08X !\n", lpParms
->dwItem
);
808 return MCIERR_UNRECOGNIZED_COMMAND
;
811 WARN("not MCI_STATUS_ITEM !\n");
816 /**************************************************************************
817 * MCICDA_SkipDataTracks [internal]
819 static DWORD
MCICDA_SkipDataTracks(WINE_MCICDAUDIO
* wmcda
,DWORD
*frame
)
824 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_TOC
, NULL
, 0,
825 &toc
, sizeof(toc
), &br
, NULL
)) {
826 WARN("error reading TOC !\n");
827 return MCICDA_GetError(wmcda
);
829 /* Locate first track whose starting frame is bigger than frame */
830 for(i
=toc
.FirstTrack
;i
<=toc
.LastTrack
+1;i
++)
831 if ( FRAME_OF_TOC(toc
, i
) > *frame
) break;
832 if (i
<= toc
.FirstTrack
&& i
>toc
.LastTrack
+1) {
833 i
= 0; /* requested address is out of range: go back to start */
834 *frame
= FRAME_OF_TOC(toc
,toc
.FirstTrack
);
838 /* i points to last track whose start address is not greater than frame.
839 * Now skip non-audio tracks */
840 for(;i
<=toc
.LastTrack
+1;i
++)
841 if ( ! (toc
.TrackData
[i
-toc
.FirstTrack
].Control
& 4) )
843 /* The frame will be an address in the next audio track or
844 * address of lead-out. */
845 if ( FRAME_OF_TOC(toc
, i
) > *frame
)
846 *frame
= FRAME_OF_TOC(toc
, i
);
850 /**************************************************************************
851 * MCICDA_Play [internal]
853 static DWORD
MCICDA_Play(UINT wDevID
, DWORD dwFlags
, LPMCI_PLAY_PARMS lpParms
)
855 WINE_MCICDAUDIO
* wmcda
= MCICDA_GetOpenDrv(wDevID
);
856 DWORD ret
= 0, start
, end
;
858 CDROM_PLAY_AUDIO_MSF play
;
859 CDROM_SUB_Q_DATA_FORMAT fmt
;
860 SUB_Q_CHANNEL_DATA data
;
863 TRACE("(%04X, %08X, %p);\n", wDevID
, dwFlags
, lpParms
);
866 return MCIERR_NULL_PARAMETER_BLOCK
;
869 return MCIERR_INVALID_DEVICE_ID
;
871 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_TOC
, NULL
, 0,
872 &toc
, sizeof(toc
), &br
, NULL
)) {
873 WARN("error reading TOC !\n");
874 return MCICDA_GetError(wmcda
);
877 if (dwFlags
& MCI_FROM
) {
878 start
= MCICDA_CalcFrame(wmcda
, lpParms
->dwFrom
);
879 if ( (ret
=MCICDA_SkipDataTracks(wmcda
, &start
)) )
881 TRACE("MCI_FROM=%08X -> %u\n", lpParms
->dwFrom
, start
);
883 fmt
.Format
= IOCTL_CDROM_CURRENT_POSITION
;
884 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_Q_CHANNEL
, &fmt
, sizeof(fmt
),
885 &data
, sizeof(data
), &br
, NULL
)) {
886 return MCICDA_GetError(wmcda
);
888 start
= FRAME_OF_ADDR(data
.CurrentPosition
.AbsoluteAddress
);
889 if ( (ret
=MCICDA_SkipDataTracks(wmcda
, &start
)) )
892 if (dwFlags
& MCI_TO
) {
893 end
= MCICDA_CalcFrame(wmcda
, lpParms
->dwTo
);
894 TRACE("MCI_TO=%08X -> %u\n", lpParms
->dwTo
, end
);
896 end
= FRAME_OF_TOC(toc
, toc
.LastTrack
+ 1) - 1;
898 TRACE("Playing from %u to %u\n", start
, end
);
900 if (wmcda
->hThread
!= 0) {
901 SetEvent(wmcda
->stopEvent
);
902 WaitForSingleObject(wmcda
->hThread
, INFINITE
);
904 CloseHandle(wmcda
->hThread
);
906 CloseHandle(wmcda
->stopEvent
);
907 wmcda
->stopEvent
= 0;
909 IDirectSoundBuffer_Stop(wmcda
->dsBuf
);
910 IDirectSoundBuffer_Release(wmcda
->dsBuf
);
912 IDirectSound_Release(wmcda
->dsObj
);
915 else if(wmcda
->hCallback
) {
916 mciDriverNotify(wmcda
->hCallback
, wmcda
->wNotifyDeviceID
,
918 wmcda
->hCallback
= NULL
;
921 if ((dwFlags
&MCI_NOTIFY
))
922 wmcda
->hCallback
= HWND_32(LOWORD(lpParms
->dwCallback
));
924 if (pDirectSoundCreate
) {
931 hr
= pDirectSoundCreate(NULL
, &wmcda
->dsObj
, NULL
);
933 IDirectSound_SetCooperativeLevel(wmcda
->dsObj
, GetDesktopWindow(), DSSCL_PRIORITY
);
935 /* The "raw" frame is relative to the start of the first track */
936 wmcda
->start
= start
- FRAME_OF_TOC(toc
, toc
.FirstTrack
);
937 wmcda
->end
= end
- FRAME_OF_TOC(toc
, toc
.FirstTrack
);
939 memset(&format
, 0, sizeof(format
));
940 format
.wFormatTag
= WAVE_FORMAT_PCM
;
941 format
.nChannels
= 2;
942 format
.nSamplesPerSec
= 44100;
943 format
.wBitsPerSample
= 16;
944 format
.nBlockAlign
= format
.nChannels
* format
.wBitsPerSample
/ 8;
945 format
.nAvgBytesPerSec
= format
.nSamplesPerSec
* format
.nBlockAlign
;
948 memset(&desc
, 0, sizeof(desc
));
949 desc
.dwSize
= sizeof(desc
);
950 desc
.dwFlags
= DSBCAPS_GETCURRENTPOSITION2
| DSBCAPS_GLOBALFOCUS
;
951 desc
.dwBufferBytes
= (CDDA_FRAG_SIZE
- (CDDA_FRAG_SIZE
%RAW_SECTOR_SIZE
)) * CDDA_FRAG_COUNT
;
952 desc
.lpwfxFormat
= &format
;
954 hr
= IDirectSound_CreateSoundBuffer(wmcda
->dsObj
, &desc
, &wmcda
->dsBuf
, NULL
);
957 hr
= IDirectSoundBuffer_Lock(wmcda
->dsBuf
, 0, 0, &cdData
, &lockLen
,
958 NULL
, NULL
, DSBLOCK_ENTIREBUFFER
);
961 RAW_READ_INFO rdInfo
;
964 rdInfo
.DiskOffset
.QuadPart
= wmcda
->start
<<11;
965 rdInfo
.SectorCount
= min(desc
.dwBufferBytes
/RAW_SECTOR_SIZE
,
966 wmcda
->end
-wmcda
->start
);
967 rdInfo
.TrackMode
= CDDA
;
969 readok
= DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_RAW_READ
,
970 &rdInfo
, sizeof(rdInfo
), cdData
, lockLen
,
972 IDirectSoundBuffer_Unlock(wmcda
->dsBuf
, cdData
, lockLen
, NULL
, 0);
975 wmcda
->start
+= rdInfo
.SectorCount
;
976 wmcda
->stopEvent
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
978 if (wmcda
->stopEvent
!= 0)
979 wmcda
->hThread
= CreateThread(NULL
, 0, MCICDA_playLoop
, wmcda
, 0, &br
);
980 if (wmcda
->hThread
!= 0) {
981 hr
= IDirectSoundBuffer_Play(wmcda
->dsBuf
, 0, 0, DSBPLAY_LOOPING
);
985 SetEvent(wmcda
->stopEvent
);
986 WaitForSingleObject(wmcda
->hThread
, INFINITE
);
987 CloseHandle(wmcda
->hThread
);
992 if (wmcda
->stopEvent
!= 0) {
993 CloseHandle(wmcda
->stopEvent
);
994 wmcda
->stopEvent
= 0;
997 IDirectSoundBuffer_Release(wmcda
->dsBuf
);
1001 IDirectSound_Release(wmcda
->dsObj
);
1002 wmcda
->dsObj
= NULL
;
1006 play
.StartingM
= start
/ CDFRAMES_PERMIN
;
1007 play
.StartingS
= (start
/ CDFRAMES_PERSEC
) % 60;
1008 play
.StartingF
= start
% CDFRAMES_PERSEC
;
1009 play
.EndingM
= end
/ CDFRAMES_PERMIN
;
1010 play
.EndingS
= (end
/ CDFRAMES_PERSEC
) % 60;
1011 play
.EndingF
= end
% CDFRAMES_PERSEC
;
1012 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_PLAY_AUDIO_MSF
, &play
, sizeof(play
),
1013 NULL
, 0, &br
, NULL
)) {
1014 wmcda
->hCallback
= NULL
;
1015 ret
= MCIERR_HARDWARE
;
1016 } else if (dwFlags
& MCI_NOTIFY
) {
1017 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
1019 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
1020 wmcda->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1026 /**************************************************************************
1027 * MCICDA_Stop [internal]
1029 static DWORD
MCICDA_Stop(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
1031 WINE_MCICDAUDIO
* wmcda
= MCICDA_GetOpenDrv(wDevID
);
1034 TRACE("(%04X, %08X, %p);\n", wDevID
, dwFlags
, lpParms
);
1036 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
1038 if (wmcda
->hThread
!= 0) {
1039 SetEvent(wmcda
->stopEvent
);
1040 WaitForSingleObject(wmcda
->hThread
, INFINITE
);
1042 CloseHandle(wmcda
->hThread
);
1044 CloseHandle(wmcda
->stopEvent
);
1045 wmcda
->stopEvent
= 0;
1047 IDirectSoundBuffer_Release(wmcda
->dsBuf
);
1048 wmcda
->dsBuf
= NULL
;
1049 IDirectSound_Release(wmcda
->dsObj
);
1050 wmcda
->dsObj
= NULL
;
1052 else if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_STOP_AUDIO
, NULL
, 0, NULL
, 0, &br
, NULL
))
1053 return MCIERR_HARDWARE
;
1055 if (wmcda
->hCallback
) {
1056 mciDriverNotify(wmcda
->hCallback
, wmcda
->wNotifyDeviceID
, MCI_NOTIFY_ABORTED
);
1057 wmcda
->hCallback
= NULL
;
1060 if (lpParms
&& (dwFlags
& MCI_NOTIFY
)) {
1061 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
1062 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)),
1063 wmcda
->wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
1068 /**************************************************************************
1069 * MCICDA_Pause [internal]
1071 static DWORD
MCICDA_Pause(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
1073 WINE_MCICDAUDIO
* wmcda
= MCICDA_GetOpenDrv(wDevID
);
1076 TRACE("(%04X, %08X, %p);\n", wDevID
, dwFlags
, lpParms
);
1078 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
1080 if (wmcda
->hThread
!= 0) {
1081 /* Don't bother calling stop if the playLoop thread has already stopped */
1082 if(WaitForSingleObject(wmcda
->stopEvent
, 0) != WAIT_OBJECT_0
&&
1083 FAILED(IDirectSoundBuffer_Stop(wmcda
->dsBuf
)))
1084 return MCIERR_HARDWARE
;
1086 else if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_PAUSE_AUDIO
, NULL
, 0, NULL
, 0, &br
, NULL
))
1087 return MCIERR_HARDWARE
;
1089 EnterCriticalSection(&wmcda
->cs
);
1090 if (wmcda
->hCallback
) {
1091 mciDriverNotify(wmcda
->hCallback
, wmcda
->wNotifyDeviceID
, MCI_NOTIFY_SUPERSEDED
);
1092 wmcda
->hCallback
= NULL
;
1094 LeaveCriticalSection(&wmcda
->cs
);
1096 if (lpParms
&& (dwFlags
& MCI_NOTIFY
)) {
1097 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
1098 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)),
1099 wmcda
->wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
1104 /**************************************************************************
1105 * MCICDA_Resume [internal]
1107 static DWORD
MCICDA_Resume(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
1109 WINE_MCICDAUDIO
* wmcda
= MCICDA_GetOpenDrv(wDevID
);
1112 TRACE("(%04X, %08X, %p);\n", wDevID
, dwFlags
, lpParms
);
1114 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
1116 if (wmcda
->hThread
!= 0) {
1117 /* Don't restart if the playLoop thread has already stopped */
1118 if(WaitForSingleObject(wmcda
->stopEvent
, 0) != WAIT_OBJECT_0
&&
1119 FAILED(IDirectSoundBuffer_Play(wmcda
->dsBuf
, 0, 0, DSBPLAY_LOOPING
)))
1120 return MCIERR_HARDWARE
;
1122 else if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_RESUME_AUDIO
, NULL
, 0, NULL
, 0, &br
, NULL
))
1123 return MCIERR_HARDWARE
;
1125 if (lpParms
&& (dwFlags
& MCI_NOTIFY
)) {
1126 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
1127 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)),
1128 wmcda
->wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
1133 /**************************************************************************
1134 * MCICDA_Seek [internal]
1136 static DWORD
MCICDA_Seek(UINT wDevID
, DWORD dwFlags
, LPMCI_SEEK_PARMS lpParms
)
1139 WINE_MCICDAUDIO
* wmcda
= MCICDA_GetOpenDrv(wDevID
);
1140 CDROM_SEEK_AUDIO_MSF seek
;
1144 TRACE("(%04X, %08X, %p);\n", wDevID
, dwFlags
, lpParms
);
1146 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
1147 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1149 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_TOC
, NULL
, 0,
1150 &toc
, sizeof(toc
), &br
, NULL
)) {
1151 WARN("error reading TOC !\n");
1152 return MCICDA_GetError(wmcda
);
1154 switch (dwFlags
& ~(MCI_NOTIFY
|MCI_WAIT
)) {
1155 case MCI_SEEK_TO_START
:
1156 TRACE("Seeking to start\n");
1157 at
= FRAME_OF_TOC(toc
,toc
.FirstTrack
);
1158 if ( (ret
=MCICDA_SkipDataTracks(wmcda
, &at
)) )
1161 case MCI_SEEK_TO_END
:
1162 TRACE("Seeking to end\n");
1163 at
= FRAME_OF_TOC(toc
, toc
.LastTrack
+ 1) - 1;
1164 if ( (ret
=MCICDA_SkipDataTracks(wmcda
, &at
)) )
1168 TRACE("Seeking to %u\n", lpParms
->dwTo
);
1169 at
= MCICDA_CalcFrame(wmcda
, lpParms
->dwTo
);
1170 if ( (ret
=MCICDA_SkipDataTracks(wmcda
, &at
)) )
1174 TRACE("Unknown seek action %08lX\n",
1175 (dwFlags
& ~(MCI_NOTIFY
|MCI_WAIT
)));
1176 return MCIERR_UNSUPPORTED_FUNCTION
;
1179 if (wmcda
->hThread
!= 0) {
1180 EnterCriticalSection(&wmcda
->cs
);
1181 wmcda
->start
= at
- FRAME_OF_TOC(toc
, toc
.FirstTrack
);
1182 /* Flush remaining data, or just let it play into the new data? */
1183 LeaveCriticalSection(&wmcda
->cs
);
1186 seek
.M
= at
/ CDFRAMES_PERMIN
;
1187 seek
.S
= (at
/ CDFRAMES_PERSEC
) % 60;
1188 seek
.F
= at
% CDFRAMES_PERSEC
;
1189 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_SEEK_AUDIO_MSF
, &seek
, sizeof(seek
),
1190 NULL
, 0, &br
, NULL
))
1191 return MCIERR_HARDWARE
;
1194 if (dwFlags
& MCI_NOTIFY
) {
1195 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
1196 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)),
1197 wmcda
->wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
1202 /**************************************************************************
1203 * MCICDA_SetDoor [internal]
1205 static DWORD
MCICDA_SetDoor(UINT wDevID
, BOOL open
)
1207 WINE_MCICDAUDIO
* wmcda
= MCICDA_GetOpenDrv(wDevID
);
1210 TRACE("(%04x, %s) !\n", wDevID
, (open
) ? "OPEN" : "CLOSE");
1212 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
1214 if (!DeviceIoControl(wmcda
->handle
,
1215 (open
) ? IOCTL_STORAGE_EJECT_MEDIA
: IOCTL_STORAGE_LOAD_MEDIA
,
1216 NULL
, 0, NULL
, 0, &br
, NULL
))
1217 return MCIERR_HARDWARE
;
1222 /**************************************************************************
1223 * MCICDA_Set [internal]
1225 static DWORD
MCICDA_Set(UINT wDevID
, DWORD dwFlags
, LPMCI_SET_PARMS lpParms
)
1227 WINE_MCICDAUDIO
* wmcda
= MCICDA_GetOpenDrv(wDevID
);
1229 TRACE("(%04X, %08X, %p);\n", wDevID
, dwFlags
, lpParms
);
1231 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
1233 if (dwFlags
& MCI_SET_DOOR_OPEN
) {
1234 MCICDA_SetDoor(wDevID
, TRUE
);
1236 if (dwFlags
& MCI_SET_DOOR_CLOSED
) {
1237 MCICDA_SetDoor(wDevID
, FALSE
);
1240 /* only functions which require valid lpParms below this line ! */
1241 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1243 TRACE("dwTimeFormat=%08lX\n", lpParms->dwTimeFormat);
1244 TRACE("dwAudio=%08lX\n", lpParms->dwAudio);
1246 if (dwFlags
& MCI_SET_TIME_FORMAT
) {
1247 switch (lpParms
->dwTimeFormat
) {
1248 case MCI_FORMAT_MILLISECONDS
:
1249 TRACE("MCI_FORMAT_MILLISECONDS !\n");
1251 case MCI_FORMAT_MSF
:
1252 TRACE("MCI_FORMAT_MSF !\n");
1254 case MCI_FORMAT_TMSF
:
1255 TRACE("MCI_FORMAT_TMSF !\n");
1258 WARN("bad time format !\n");
1259 return MCIERR_BAD_TIME_FORMAT
;
1261 wmcda
->dwTimeFormat
= lpParms
->dwTimeFormat
;
1263 if (dwFlags
& MCI_SET_VIDEO
) return MCIERR_UNSUPPORTED_FUNCTION
;
1264 if (dwFlags
& MCI_SET_ON
) return MCIERR_UNSUPPORTED_FUNCTION
;
1265 if (dwFlags
& MCI_SET_OFF
) return MCIERR_UNSUPPORTED_FUNCTION
;
1266 if (dwFlags
& MCI_NOTIFY
) {
1267 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n",
1268 lpParms
->dwCallback
);
1269 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)),
1270 wmcda
->wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
1275 /**************************************************************************
1276 * DriverProc (MCICDA.@)
1278 LRESULT CALLBACK
MCICDA_DriverProc(DWORD_PTR dwDevID
, HDRVR hDriv
, UINT wMsg
,
1279 LPARAM dwParam1
, LPARAM dwParam2
)
1282 case DRV_LOAD
: return 1;
1283 case DRV_FREE
: return 1;
1284 case DRV_OPEN
: return MCICDA_drvOpen((LPCWSTR
)dwParam1
, (LPMCI_OPEN_DRIVER_PARMSW
)dwParam2
);
1285 case DRV_CLOSE
: return MCICDA_drvClose(dwDevID
);
1286 case DRV_ENABLE
: return 1;
1287 case DRV_DISABLE
: return 1;
1288 case DRV_QUERYCONFIGURE
: return 1;
1289 case DRV_CONFIGURE
: MessageBoxA(0, "MCI audio CD driver !", "Wine Driver", MB_OK
); return 1;
1290 case DRV_INSTALL
: return DRVCNF_RESTART
;
1291 case DRV_REMOVE
: return DRVCNF_RESTART
;
1294 if (dwDevID
== 0xFFFFFFFF) return MCIERR_UNSUPPORTED_FUNCTION
;
1297 case MCI_OPEN_DRIVER
: return MCICDA_Open(dwDevID
, dwParam1
, (LPMCI_OPEN_PARMSW
)dwParam2
);
1298 case MCI_CLOSE_DRIVER
: return MCICDA_Close(dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
1299 case MCI_GETDEVCAPS
: return MCICDA_GetDevCaps(dwDevID
, dwParam1
, (LPMCI_GETDEVCAPS_PARMS
)dwParam2
);
1300 case MCI_INFO
: return MCICDA_Info(dwDevID
, dwParam1
, (LPMCI_INFO_PARMSW
)dwParam2
);
1301 case MCI_STATUS
: return MCICDA_Status(dwDevID
, dwParam1
, (LPMCI_STATUS_PARMS
)dwParam2
);
1302 case MCI_SET
: return MCICDA_Set(dwDevID
, dwParam1
, (LPMCI_SET_PARMS
)dwParam2
);
1303 case MCI_PLAY
: return MCICDA_Play(dwDevID
, dwParam1
, (LPMCI_PLAY_PARMS
)dwParam2
);
1304 case MCI_STOP
: return MCICDA_Stop(dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
1305 case MCI_PAUSE
: return MCICDA_Pause(dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
1306 case MCI_RESUME
: return MCICDA_Resume(dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
1307 case MCI_SEEK
: return MCICDA_Seek(dwDevID
, dwParam1
, (LPMCI_SEEK_PARMS
)dwParam2
);
1308 /* commands that should report an error as they are not supported in
1309 * the native version */
1310 case MCI_SET_DOOR_CLOSED
:
1311 case MCI_SET_DOOR_OPEN
:
1328 TRACE("Unsupported command [0x%x]\n", wMsg
);
1332 ERR("Shouldn't receive a MCI_OPEN or CLOSE message\n");
1335 TRACE("Sending msg [0x%x] to default driver proc\n", wMsg
);
1336 return DefDriverProc(dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);
1338 return MCIERR_UNRECOGNIZED_COMMAND
;
1341 /*-----------------------------------------------------------------------*/