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
)
475 /**************************************************************************
476 * MCICDA_Close [internal]
478 static DWORD
MCICDA_Close(UINT wDevID
, DWORD dwParam
, LPMCI_GENERIC_PARMS lpParms
)
480 WINE_MCICDAUDIO
* wmcda
= MCICDA_GetOpenDrv(wDevID
);
482 TRACE("(%04X, %08X, %p);\n", wDevID
, dwParam
, lpParms
);
484 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
486 MCICDA_Stop(wDevID
, MCI_WAIT
, NULL
);
488 if (--wmcda
->nUseCount
== 0) {
489 CloseHandle(wmcda
->handle
);
494 /**************************************************************************
495 * MCICDA_GetDevCaps [internal]
497 static DWORD
MCICDA_GetDevCaps(UINT wDevID
, DWORD dwFlags
,
498 LPMCI_GETDEVCAPS_PARMS lpParms
)
502 TRACE("(%04X, %08X, %p);\n", wDevID
, dwFlags
, lpParms
);
504 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
506 if (dwFlags
& MCI_GETDEVCAPS_ITEM
) {
507 TRACE("MCI_GETDEVCAPS_ITEM dwItem=%08X;\n", lpParms
->dwItem
);
509 switch (lpParms
->dwItem
) {
510 case MCI_GETDEVCAPS_CAN_RECORD
:
511 lpParms
->dwReturn
= MAKEMCIRESOURCE(FALSE
, MCI_FALSE
);
512 ret
= MCI_RESOURCE_RETURNED
;
514 case MCI_GETDEVCAPS_HAS_AUDIO
:
515 lpParms
->dwReturn
= MAKEMCIRESOURCE(TRUE
, MCI_TRUE
);
516 ret
= MCI_RESOURCE_RETURNED
;
518 case MCI_GETDEVCAPS_HAS_VIDEO
:
519 lpParms
->dwReturn
= MAKEMCIRESOURCE(FALSE
, MCI_FALSE
);
520 ret
= MCI_RESOURCE_RETURNED
;
522 case MCI_GETDEVCAPS_DEVICE_TYPE
:
523 lpParms
->dwReturn
= MAKEMCIRESOURCE(MCI_DEVTYPE_CD_AUDIO
, MCI_DEVTYPE_CD_AUDIO
);
524 ret
= MCI_RESOURCE_RETURNED
;
526 case MCI_GETDEVCAPS_USES_FILES
:
527 lpParms
->dwReturn
= MAKEMCIRESOURCE(FALSE
, MCI_FALSE
);
528 ret
= MCI_RESOURCE_RETURNED
;
530 case MCI_GETDEVCAPS_COMPOUND_DEVICE
:
531 lpParms
->dwReturn
= MAKEMCIRESOURCE(FALSE
, MCI_FALSE
);
532 ret
= MCI_RESOURCE_RETURNED
;
534 case MCI_GETDEVCAPS_CAN_EJECT
:
535 lpParms
->dwReturn
= MAKEMCIRESOURCE(TRUE
, MCI_TRUE
);
536 ret
= MCI_RESOURCE_RETURNED
;
538 case MCI_GETDEVCAPS_CAN_PLAY
:
539 lpParms
->dwReturn
= MAKEMCIRESOURCE(TRUE
, MCI_TRUE
);
540 ret
= MCI_RESOURCE_RETURNED
;
542 case MCI_GETDEVCAPS_CAN_SAVE
:
543 lpParms
->dwReturn
= MAKEMCIRESOURCE(FALSE
, MCI_FALSE
);
544 ret
= MCI_RESOURCE_RETURNED
;
547 ERR("Unsupported %x devCaps item\n", lpParms
->dwItem
);
548 return MCIERR_UNRECOGNIZED_COMMAND
;
551 TRACE("No GetDevCaps-Item !\n");
552 return MCIERR_UNRECOGNIZED_COMMAND
;
554 TRACE("lpParms->dwReturn=%08X;\n", lpParms
->dwReturn
);
558 static DWORD
CDROM_Audio_GetSerial(CDROM_TOC
* toc
)
560 unsigned long serial
= 0;
563 DWORD dwStart
, dwEnd
;
566 * wMagic collects the wFrames from track 1
567 * dwStart, dwEnd collect the beginning and end of the disc respectively, in
569 * There it is collected for correcting the serial when there are less than
572 wMagic
= toc
->TrackData
[0].Address
[3];
573 dwStart
= FRAME_OF_TOC(*toc
, toc
->FirstTrack
);
575 for (i
= 0; i
<= toc
->LastTrack
- toc
->FirstTrack
; i
++) {
576 serial
+= (toc
->TrackData
[i
].Address
[1] << 16) |
577 (toc
->TrackData
[i
].Address
[2] << 8) | toc
->TrackData
[i
].Address
[3];
579 dwEnd
= FRAME_OF_TOC(*toc
, toc
->LastTrack
+ 1);
581 if (toc
->LastTrack
- toc
->FirstTrack
+ 1 < 3)
582 serial
+= wMagic
+ (dwEnd
- dwStart
);
588 /**************************************************************************
589 * MCICDA_Info [internal]
591 static DWORD
MCICDA_Info(UINT wDevID
, DWORD dwFlags
, LPMCI_INFO_PARMSW lpParms
)
594 WINE_MCICDAUDIO
* wmcda
= MCICDA_GetOpenDrv(wDevID
);
598 TRACE("(%04X, %08X, %p);\n", wDevID
, dwFlags
, lpParms
);
600 if (lpParms
== NULL
|| lpParms
->lpstrReturn
== NULL
)
601 return MCIERR_NULL_PARAMETER_BLOCK
;
602 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
604 TRACE("buf=%p, len=%u\n", lpParms
->lpstrReturn
, lpParms
->dwRetSize
);
606 if (dwFlags
& MCI_INFO_PRODUCT
) {
607 static const WCHAR wszAudioCd
[] = {'W','i','n','e','\'','s',' ','a','u','d','i','o',' ','C','D',0};
609 } else if (dwFlags
& MCI_INFO_MEDIA_UPC
) {
610 ret
= MCIERR_NO_IDENTITY
;
611 } else if (dwFlags
& MCI_INFO_MEDIA_IDENTITY
) {
615 static const WCHAR wszLu
[] = {'%','l','u',0};
617 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_TOC
, NULL
, 0,
618 &toc
, sizeof(toc
), &br
, NULL
)) {
619 return MCICDA_GetError(wmcda
);
622 res
= CDROM_Audio_GetSerial(&toc
);
623 sprintfW(buffer
, wszLu
, res
);
626 WARN("Don't know this info command (%u)\n", dwFlags
);
627 ret
= MCIERR_UNRECOGNIZED_COMMAND
;
630 if (lpParms
->dwRetSize
<= strlenW(str
)) {
631 lstrcpynW(lpParms
->lpstrReturn
, str
, lpParms
->dwRetSize
- 1);
632 ret
= MCIERR_PARAM_OVERFLOW
;
634 strcpyW(lpParms
->lpstrReturn
, str
);
637 *lpParms
->lpstrReturn
= 0;
639 TRACE("=> %s (%d)\n", debugstr_w(lpParms
->lpstrReturn
), ret
);
643 /**************************************************************************
644 * MCICDA_Status [internal]
646 static DWORD
MCICDA_Status(UINT wDevID
, DWORD dwFlags
, LPMCI_STATUS_PARMS lpParms
)
648 WINE_MCICDAUDIO
* wmcda
= MCICDA_GetOpenDrv(wDevID
);
650 CDROM_SUB_Q_DATA_FORMAT fmt
;
651 SUB_Q_CHANNEL_DATA data
;
655 TRACE("(%04X, %08X, %p);\n", wDevID
, dwFlags
, lpParms
);
657 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
658 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
660 if (dwFlags
& MCI_NOTIFY
) {
661 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
662 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)),
663 wmcda
->wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
665 if (dwFlags
& MCI_STATUS_ITEM
) {
666 TRACE("dwItem = %x\n", lpParms
->dwItem
);
667 switch (lpParms
->dwItem
) {
668 case MCI_STATUS_CURRENT_TRACK
:
669 fmt
.Format
= IOCTL_CDROM_CURRENT_POSITION
;
670 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_Q_CHANNEL
, &fmt
, sizeof(fmt
),
671 &data
, sizeof(data
), &br
, NULL
))
673 return MCICDA_GetError(wmcda
);
675 lpParms
->dwReturn
= data
.CurrentPosition
.TrackNumber
;
676 TRACE("CURRENT_TRACK=%lu\n", lpParms
->dwReturn
);
678 case MCI_STATUS_LENGTH
:
679 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_TOC
, NULL
, 0,
680 &toc
, sizeof(toc
), &br
, NULL
)) {
681 WARN("error reading TOC !\n");
682 return MCICDA_GetError(wmcda
);
684 if (dwFlags
& MCI_TRACK
) {
685 TRACE("MCI_TRACK #%u LENGTH=??? !\n", lpParms
->dwTrack
);
686 if (lpParms
->dwTrack
< toc
.FirstTrack
|| lpParms
->dwTrack
> toc
.LastTrack
)
687 return MCIERR_OUTOFRANGE
;
688 lpParms
->dwReturn
= FRAME_OF_TOC(toc
, lpParms
->dwTrack
+ 1) -
689 FRAME_OF_TOC(toc
, lpParms
->dwTrack
);
690 /* Windows returns one frame less than the total track length for the
691 last track on the CD. See CDDB HOWTO. Verified on Win95OSR2. */
692 if (lpParms
->dwTrack
== toc
.LastTrack
)
695 /* Sum of the lengths of all of the tracks. Inherits the
696 'off by one frame' behavior from the length of the last track.
697 See above comment. */
698 lpParms
->dwReturn
= FRAME_OF_TOC(toc
, toc
.LastTrack
+ 1) -
699 FRAME_OF_TOC(toc
, toc
.FirstTrack
) - 1;
701 lpParms
->dwReturn
= MCICDA_CalcTime(wmcda
,
702 (wmcda
->dwTimeFormat
== MCI_FORMAT_TMSF
)
703 ? MCI_FORMAT_MSF
: wmcda
->dwTimeFormat
,
706 TRACE("LENGTH=%lu\n", lpParms
->dwReturn
);
708 case MCI_STATUS_MODE
:
709 lpParms
->dwReturn
= MCICDA_GetStatus(wmcda
);
710 TRACE("MCI_STATUS_MODE=%08lX\n", lpParms
->dwReturn
);
711 lpParms
->dwReturn
= MAKEMCIRESOURCE(lpParms
->dwReturn
, lpParms
->dwReturn
);
712 ret
= MCI_RESOURCE_RETURNED
;
714 case MCI_STATUS_MEDIA_PRESENT
:
715 lpParms
->dwReturn
= (MCICDA_GetStatus(wmcda
) == MCI_MODE_OPEN
) ?
716 MAKEMCIRESOURCE(FALSE
, MCI_FALSE
) : MAKEMCIRESOURCE(TRUE
, MCI_TRUE
);
717 TRACE("MCI_STATUS_MEDIA_PRESENT =%c!\n", LOWORD(lpParms
->dwReturn
) ? 'Y' : 'N');
718 ret
= MCI_RESOURCE_RETURNED
;
720 case MCI_STATUS_NUMBER_OF_TRACKS
:
721 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_TOC
, NULL
, 0,
722 &toc
, sizeof(toc
), &br
, NULL
)) {
723 WARN("error reading TOC !\n");
724 return MCICDA_GetError(wmcda
);
726 lpParms
->dwReturn
= toc
.LastTrack
- toc
.FirstTrack
+ 1;
727 TRACE("MCI_STATUS_NUMBER_OF_TRACKS = %lu\n", lpParms
->dwReturn
);
728 if (lpParms
->dwReturn
== (WORD
)-1)
729 return MCICDA_GetError(wmcda
);
731 case MCI_STATUS_POSITION
:
732 if (dwFlags
& MCI_STATUS_START
) {
733 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_TOC
, NULL
, 0,
734 &toc
, sizeof(toc
), &br
, NULL
)) {
735 WARN("error reading TOC !\n");
736 return MCICDA_GetError(wmcda
);
738 lpParms
->dwReturn
= FRAME_OF_TOC(toc
, toc
.FirstTrack
);
739 TRACE("get MCI_STATUS_START !\n");
740 } else if (dwFlags
& MCI_TRACK
) {
741 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_TOC
, NULL
, 0,
742 &toc
, sizeof(toc
), &br
, NULL
)) {
743 WARN("error reading TOC !\n");
744 return MCICDA_GetError(wmcda
);
746 if (lpParms
->dwTrack
< toc
.FirstTrack
|| lpParms
->dwTrack
> toc
.LastTrack
)
747 return MCIERR_OUTOFRANGE
;
748 lpParms
->dwReturn
= FRAME_OF_TOC(toc
, lpParms
->dwTrack
);
749 TRACE("get MCI_TRACK #%u !\n", lpParms
->dwTrack
);
751 fmt
.Format
= IOCTL_CDROM_CURRENT_POSITION
;
752 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_Q_CHANNEL
, &fmt
, sizeof(fmt
),
753 &data
, sizeof(data
), &br
, NULL
)) {
754 return MCICDA_GetError(wmcda
);
756 lpParms
->dwReturn
= FRAME_OF_ADDR(data
.CurrentPosition
.AbsoluteAddress
);
758 lpParms
->dwReturn
= MCICDA_CalcTime(wmcda
, wmcda
->dwTimeFormat
, lpParms
->dwReturn
, &ret
);
759 TRACE("MCI_STATUS_POSITION=%08lX\n", lpParms
->dwReturn
);
761 case MCI_STATUS_READY
:
762 TRACE("MCI_STATUS_READY !\n");
763 switch (MCICDA_GetStatus(wmcda
))
765 case MCI_MODE_NOT_READY
:
767 lpParms
->dwReturn
= MAKEMCIRESOURCE(FALSE
, MCI_FALSE
);
770 lpParms
->dwReturn
= MAKEMCIRESOURCE(TRUE
, MCI_TRUE
);
773 TRACE("MCI_STATUS_READY=%u!\n", LOWORD(lpParms
->dwReturn
));
774 ret
= MCI_RESOURCE_RETURNED
;
776 case MCI_STATUS_TIME_FORMAT
:
777 lpParms
->dwReturn
= MAKEMCIRESOURCE(wmcda
->dwTimeFormat
, MCI_FORMAT_RETURN_BASE
+ wmcda
->dwTimeFormat
);
778 TRACE("MCI_STATUS_TIME_FORMAT=%08x!\n", LOWORD(lpParms
->dwReturn
));
779 ret
= MCI_RESOURCE_RETURNED
;
781 case 4001: /* FIXME: for bogus FullCD */
782 case MCI_CDA_STATUS_TYPE_TRACK
:
783 if (!(dwFlags
& MCI_TRACK
))
784 ret
= MCIERR_MISSING_PARAMETER
;
786 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_TOC
, NULL
, 0,
787 &toc
, sizeof(toc
), &br
, NULL
)) {
788 WARN("error reading TOC !\n");
789 return MCICDA_GetError(wmcda
);
791 if (lpParms
->dwTrack
< toc
.FirstTrack
|| lpParms
->dwTrack
> toc
.LastTrack
)
792 ret
= MCIERR_OUTOFRANGE
;
794 lpParms
->dwReturn
= (toc
.TrackData
[lpParms
->dwTrack
- toc
.FirstTrack
].Control
& 0x04) ?
795 MCI_CDA_TRACK_OTHER
: MCI_CDA_TRACK_AUDIO
;
797 TRACE("MCI_CDA_STATUS_TYPE_TRACK[%d]=%ld\n", lpParms
->dwTrack
, lpParms
->dwReturn
);
800 FIXME("unknown command %08X !\n", lpParms
->dwItem
);
801 return MCIERR_UNRECOGNIZED_COMMAND
;
804 WARN("not MCI_STATUS_ITEM !\n");
809 /**************************************************************************
810 * MCICDA_SkipDataTracks [internal]
812 static DWORD
MCICDA_SkipDataTracks(WINE_MCICDAUDIO
* wmcda
,DWORD
*frame
)
817 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_TOC
, NULL
, 0,
818 &toc
, sizeof(toc
), &br
, NULL
)) {
819 WARN("error reading TOC !\n");
820 return MCICDA_GetError(wmcda
);
822 /* Locate first track whose starting frame is bigger than frame */
823 for(i
=toc
.FirstTrack
;i
<=toc
.LastTrack
+1;i
++)
824 if ( FRAME_OF_TOC(toc
, i
) > *frame
) break;
825 if (i
<= toc
.FirstTrack
&& i
>toc
.LastTrack
+1) {
826 i
= 0; /* requested address is out of range: go back to start */
827 *frame
= FRAME_OF_TOC(toc
,toc
.FirstTrack
);
831 /* i points to last track whose start address is not greater than frame.
832 * Now skip non-audio tracks */
833 for(;i
<=toc
.LastTrack
+1;i
++)
834 if ( ! (toc
.TrackData
[i
-toc
.FirstTrack
].Control
& 4) )
836 /* The frame will be an address in the next audio track or
837 * address of lead-out. */
838 if ( FRAME_OF_TOC(toc
, i
) > *frame
)
839 *frame
= FRAME_OF_TOC(toc
, i
);
843 /**************************************************************************
844 * MCICDA_Play [internal]
846 static DWORD
MCICDA_Play(UINT wDevID
, DWORD dwFlags
, LPMCI_PLAY_PARMS lpParms
)
848 WINE_MCICDAUDIO
* wmcda
= MCICDA_GetOpenDrv(wDevID
);
849 DWORD ret
= 0, start
, end
;
851 CDROM_PLAY_AUDIO_MSF play
;
852 CDROM_SUB_Q_DATA_FORMAT fmt
;
853 SUB_Q_CHANNEL_DATA data
;
856 TRACE("(%04X, %08X, %p);\n", wDevID
, dwFlags
, lpParms
);
859 return MCIERR_NULL_PARAMETER_BLOCK
;
862 return MCIERR_INVALID_DEVICE_ID
;
864 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_TOC
, NULL
, 0,
865 &toc
, sizeof(toc
), &br
, NULL
)) {
866 WARN("error reading TOC !\n");
867 return MCICDA_GetError(wmcda
);
870 if (dwFlags
& MCI_FROM
) {
871 start
= MCICDA_CalcFrame(wmcda
, lpParms
->dwFrom
);
872 if ( (ret
=MCICDA_SkipDataTracks(wmcda
, &start
)) )
874 TRACE("MCI_FROM=%08X -> %u\n", lpParms
->dwFrom
, start
);
876 fmt
.Format
= IOCTL_CDROM_CURRENT_POSITION
;
877 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_Q_CHANNEL
, &fmt
, sizeof(fmt
),
878 &data
, sizeof(data
), &br
, NULL
)) {
879 return MCICDA_GetError(wmcda
);
881 start
= FRAME_OF_ADDR(data
.CurrentPosition
.AbsoluteAddress
);
882 if ( (ret
=MCICDA_SkipDataTracks(wmcda
, &start
)) )
885 if (dwFlags
& MCI_TO
) {
886 end
= MCICDA_CalcFrame(wmcda
, lpParms
->dwTo
);
887 TRACE("MCI_TO=%08X -> %u\n", lpParms
->dwTo
, end
);
889 end
= FRAME_OF_TOC(toc
, toc
.LastTrack
+ 1) - 1;
891 TRACE("Playing from %u to %u\n", start
, end
);
893 if (wmcda
->hThread
!= 0) {
894 SetEvent(wmcda
->stopEvent
);
895 WaitForSingleObject(wmcda
->hThread
, INFINITE
);
897 CloseHandle(wmcda
->hThread
);
899 CloseHandle(wmcda
->stopEvent
);
900 wmcda
->stopEvent
= 0;
902 IDirectSoundBuffer_Stop(wmcda
->dsBuf
);
903 IDirectSoundBuffer_Release(wmcda
->dsBuf
);
905 IDirectSound_Release(wmcda
->dsObj
);
908 else if(wmcda
->hCallback
) {
909 mciDriverNotify(wmcda
->hCallback
, wmcda
->wNotifyDeviceID
,
911 wmcda
->hCallback
= NULL
;
914 if ((dwFlags
&MCI_NOTIFY
))
915 wmcda
->hCallback
= HWND_32(LOWORD(lpParms
->dwCallback
));
917 if (pDirectSoundCreate
) {
924 hr
= pDirectSoundCreate(NULL
, &wmcda
->dsObj
, NULL
);
926 IDirectSound_SetCooperativeLevel(wmcda
->dsObj
, GetDesktopWindow(), DSSCL_PRIORITY
);
928 /* The "raw" frame is relative to the start of the first track */
929 wmcda
->start
= start
- FRAME_OF_TOC(toc
, toc
.FirstTrack
);
930 wmcda
->end
= end
- FRAME_OF_TOC(toc
, toc
.FirstTrack
);
932 memset(&format
, 0, sizeof(format
));
933 format
.wFormatTag
= WAVE_FORMAT_PCM
;
934 format
.nChannels
= 2;
935 format
.nSamplesPerSec
= 44100;
936 format
.wBitsPerSample
= 16;
937 format
.nBlockAlign
= format
.nChannels
* format
.wBitsPerSample
/ 8;
938 format
.nAvgBytesPerSec
= format
.nSamplesPerSec
* format
.nBlockAlign
;
941 memset(&desc
, 0, sizeof(desc
));
942 desc
.dwSize
= sizeof(desc
);
943 desc
.dwFlags
= DSBCAPS_GETCURRENTPOSITION2
| DSBCAPS_GLOBALFOCUS
;
944 desc
.dwBufferBytes
= (CDDA_FRAG_SIZE
- (CDDA_FRAG_SIZE
%RAW_SECTOR_SIZE
)) * CDDA_FRAG_COUNT
;
945 desc
.lpwfxFormat
= &format
;
947 hr
= IDirectSound_CreateSoundBuffer(wmcda
->dsObj
, &desc
, &wmcda
->dsBuf
, NULL
);
950 hr
= IDirectSoundBuffer_Lock(wmcda
->dsBuf
, 0, 0, &cdData
, &lockLen
,
951 NULL
, NULL
, DSBLOCK_ENTIREBUFFER
);
954 RAW_READ_INFO rdInfo
;
957 rdInfo
.DiskOffset
.QuadPart
= wmcda
->start
<<11;
958 rdInfo
.SectorCount
= min(desc
.dwBufferBytes
/RAW_SECTOR_SIZE
,
959 wmcda
->end
-wmcda
->start
);
960 rdInfo
.TrackMode
= CDDA
;
962 readok
= DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_RAW_READ
,
963 &rdInfo
, sizeof(rdInfo
), cdData
, lockLen
,
965 IDirectSoundBuffer_Unlock(wmcda
->dsBuf
, cdData
, lockLen
, NULL
, 0);
968 wmcda
->start
+= rdInfo
.SectorCount
;
969 wmcda
->stopEvent
= CreateEventA(NULL
, TRUE
, FALSE
, NULL
);
971 if (wmcda
->stopEvent
!= 0)
972 wmcda
->hThread
= CreateThread(NULL
, 0, MCICDA_playLoop
, wmcda
, 0, &br
);
973 if (wmcda
->hThread
!= 0) {
974 hr
= IDirectSoundBuffer_Play(wmcda
->dsBuf
, 0, 0, DSBPLAY_LOOPING
);
978 SetEvent(wmcda
->stopEvent
);
979 WaitForSingleObject(wmcda
->hThread
, INFINITE
);
980 CloseHandle(wmcda
->hThread
);
985 if (wmcda
->stopEvent
!= 0) {
986 CloseHandle(wmcda
->stopEvent
);
987 wmcda
->stopEvent
= 0;
990 IDirectSoundBuffer_Release(wmcda
->dsBuf
);
994 IDirectSound_Release(wmcda
->dsObj
);
999 play
.StartingM
= start
/ CDFRAMES_PERMIN
;
1000 play
.StartingS
= (start
/ CDFRAMES_PERSEC
) % 60;
1001 play
.StartingF
= start
% CDFRAMES_PERSEC
;
1002 play
.EndingM
= end
/ CDFRAMES_PERMIN
;
1003 play
.EndingS
= (end
/ CDFRAMES_PERSEC
) % 60;
1004 play
.EndingF
= end
% CDFRAMES_PERSEC
;
1005 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_PLAY_AUDIO_MSF
, &play
, sizeof(play
),
1006 NULL
, 0, &br
, NULL
)) {
1007 wmcda
->hCallback
= NULL
;
1008 ret
= MCIERR_HARDWARE
;
1009 } else if (dwFlags
& MCI_NOTIFY
) {
1010 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
1012 mciDriverNotify(HWND_32(LOWORD(lpParms->dwCallback)),
1013 wmcda->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1019 /**************************************************************************
1020 * MCICDA_Stop [internal]
1022 static DWORD
MCICDA_Stop(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
1024 WINE_MCICDAUDIO
* wmcda
= MCICDA_GetOpenDrv(wDevID
);
1027 TRACE("(%04X, %08X, %p);\n", wDevID
, dwFlags
, lpParms
);
1029 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
1031 if (wmcda
->hThread
!= 0) {
1032 SetEvent(wmcda
->stopEvent
);
1033 WaitForSingleObject(wmcda
->hThread
, INFINITE
);
1035 CloseHandle(wmcda
->hThread
);
1037 CloseHandle(wmcda
->stopEvent
);
1038 wmcda
->stopEvent
= 0;
1040 IDirectSoundBuffer_Release(wmcda
->dsBuf
);
1041 wmcda
->dsBuf
= NULL
;
1042 IDirectSound_Release(wmcda
->dsObj
);
1043 wmcda
->dsObj
= NULL
;
1045 else if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_STOP_AUDIO
, NULL
, 0, NULL
, 0, &br
, NULL
))
1046 return MCIERR_HARDWARE
;
1048 if (wmcda
->hCallback
) {
1049 mciDriverNotify(wmcda
->hCallback
, wmcda
->wNotifyDeviceID
, MCI_NOTIFY_ABORTED
);
1050 wmcda
->hCallback
= NULL
;
1053 if (lpParms
&& (dwFlags
& MCI_NOTIFY
)) {
1054 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
1055 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)),
1056 wmcda
->wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
1061 /**************************************************************************
1062 * MCICDA_Pause [internal]
1064 static DWORD
MCICDA_Pause(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
1066 WINE_MCICDAUDIO
* wmcda
= MCICDA_GetOpenDrv(wDevID
);
1069 TRACE("(%04X, %08X, %p);\n", wDevID
, dwFlags
, lpParms
);
1071 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
1073 if (wmcda
->hThread
!= 0) {
1074 /* Don't bother calling stop if the playLoop thread has already stopped */
1075 if(WaitForSingleObject(wmcda
->stopEvent
, 0) != WAIT_OBJECT_0
&&
1076 FAILED(IDirectSoundBuffer_Stop(wmcda
->dsBuf
)))
1077 return MCIERR_HARDWARE
;
1079 else if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_PAUSE_AUDIO
, NULL
, 0, NULL
, 0, &br
, NULL
))
1080 return MCIERR_HARDWARE
;
1082 EnterCriticalSection(&wmcda
->cs
);
1083 if (wmcda
->hCallback
) {
1084 mciDriverNotify(wmcda
->hCallback
, wmcda
->wNotifyDeviceID
, MCI_NOTIFY_SUPERSEDED
);
1085 wmcda
->hCallback
= NULL
;
1087 LeaveCriticalSection(&wmcda
->cs
);
1089 if (lpParms
&& (dwFlags
& MCI_NOTIFY
)) {
1090 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
1091 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)),
1092 wmcda
->wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
1097 /**************************************************************************
1098 * MCICDA_Resume [internal]
1100 static DWORD
MCICDA_Resume(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
1102 WINE_MCICDAUDIO
* wmcda
= MCICDA_GetOpenDrv(wDevID
);
1105 TRACE("(%04X, %08X, %p);\n", wDevID
, dwFlags
, lpParms
);
1107 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
1109 if (wmcda
->hThread
!= 0) {
1110 /* Don't restart if the playLoop thread has already stopped */
1111 if(WaitForSingleObject(wmcda
->stopEvent
, 0) != WAIT_OBJECT_0
&&
1112 FAILED(IDirectSoundBuffer_Play(wmcda
->dsBuf
, 0, 0, DSBPLAY_LOOPING
)))
1113 return MCIERR_HARDWARE
;
1115 else if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_RESUME_AUDIO
, NULL
, 0, NULL
, 0, &br
, NULL
))
1116 return MCIERR_HARDWARE
;
1118 if (lpParms
&& (dwFlags
& MCI_NOTIFY
)) {
1119 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
1120 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)),
1121 wmcda
->wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
1126 /**************************************************************************
1127 * MCICDA_Seek [internal]
1129 static DWORD
MCICDA_Seek(UINT wDevID
, DWORD dwFlags
, LPMCI_SEEK_PARMS lpParms
)
1132 WINE_MCICDAUDIO
* wmcda
= MCICDA_GetOpenDrv(wDevID
);
1133 CDROM_SEEK_AUDIO_MSF seek
;
1137 TRACE("(%04X, %08X, %p);\n", wDevID
, dwFlags
, lpParms
);
1139 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
1140 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1142 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_READ_TOC
, NULL
, 0,
1143 &toc
, sizeof(toc
), &br
, NULL
)) {
1144 WARN("error reading TOC !\n");
1145 return MCICDA_GetError(wmcda
);
1147 switch (dwFlags
& ~(MCI_NOTIFY
|MCI_WAIT
)) {
1148 case MCI_SEEK_TO_START
:
1149 TRACE("Seeking to start\n");
1150 at
= FRAME_OF_TOC(toc
,toc
.FirstTrack
);
1151 if ( (ret
=MCICDA_SkipDataTracks(wmcda
, &at
)) )
1154 case MCI_SEEK_TO_END
:
1155 TRACE("Seeking to end\n");
1156 at
= FRAME_OF_TOC(toc
, toc
.LastTrack
+ 1) - 1;
1157 if ( (ret
=MCICDA_SkipDataTracks(wmcda
, &at
)) )
1161 TRACE("Seeking to %u\n", lpParms
->dwTo
);
1162 at
= MCICDA_CalcFrame(wmcda
, lpParms
->dwTo
);
1163 if ( (ret
=MCICDA_SkipDataTracks(wmcda
, &at
)) )
1167 TRACE("Unknown seek action %08lX\n",
1168 (dwFlags
& ~(MCI_NOTIFY
|MCI_WAIT
)));
1169 return MCIERR_UNSUPPORTED_FUNCTION
;
1172 if (wmcda
->hThread
!= 0) {
1173 EnterCriticalSection(&wmcda
->cs
);
1174 wmcda
->start
= at
- FRAME_OF_TOC(toc
, toc
.FirstTrack
);
1175 /* Flush remaining data, or just let it play into the new data? */
1176 LeaveCriticalSection(&wmcda
->cs
);
1179 seek
.M
= at
/ CDFRAMES_PERMIN
;
1180 seek
.S
= (at
/ CDFRAMES_PERSEC
) % 60;
1181 seek
.F
= at
% CDFRAMES_PERSEC
;
1182 if (!DeviceIoControl(wmcda
->handle
, IOCTL_CDROM_SEEK_AUDIO_MSF
, &seek
, sizeof(seek
),
1183 NULL
, 0, &br
, NULL
))
1184 return MCIERR_HARDWARE
;
1187 if (dwFlags
& MCI_NOTIFY
) {
1188 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
1189 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)),
1190 wmcda
->wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
1195 /**************************************************************************
1196 * MCICDA_SetDoor [internal]
1198 static DWORD
MCICDA_SetDoor(UINT wDevID
, BOOL open
)
1200 WINE_MCICDAUDIO
* wmcda
= MCICDA_GetOpenDrv(wDevID
);
1203 TRACE("(%04x, %s) !\n", wDevID
, (open
) ? "OPEN" : "CLOSE");
1205 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
1207 if (!DeviceIoControl(wmcda
->handle
,
1208 (open
) ? IOCTL_STORAGE_EJECT_MEDIA
: IOCTL_STORAGE_LOAD_MEDIA
,
1209 NULL
, 0, NULL
, 0, &br
, NULL
))
1210 return MCIERR_HARDWARE
;
1215 /**************************************************************************
1216 * MCICDA_Set [internal]
1218 static DWORD
MCICDA_Set(UINT wDevID
, DWORD dwFlags
, LPMCI_SET_PARMS lpParms
)
1220 WINE_MCICDAUDIO
* wmcda
= MCICDA_GetOpenDrv(wDevID
);
1222 TRACE("(%04X, %08X, %p);\n", wDevID
, dwFlags
, lpParms
);
1224 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
1226 if (dwFlags
& MCI_SET_DOOR_OPEN
) {
1227 MCICDA_SetDoor(wDevID
, TRUE
);
1229 if (dwFlags
& MCI_SET_DOOR_CLOSED
) {
1230 MCICDA_SetDoor(wDevID
, FALSE
);
1233 /* only functions which require valid lpParms below this line ! */
1234 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
1236 TRACE("dwTimeFormat=%08lX\n", lpParms->dwTimeFormat);
1237 TRACE("dwAudio=%08lX\n", lpParms->dwAudio);
1239 if (dwFlags
& MCI_SET_TIME_FORMAT
) {
1240 switch (lpParms
->dwTimeFormat
) {
1241 case MCI_FORMAT_MILLISECONDS
:
1242 TRACE("MCI_FORMAT_MILLISECONDS !\n");
1244 case MCI_FORMAT_MSF
:
1245 TRACE("MCI_FORMAT_MSF !\n");
1247 case MCI_FORMAT_TMSF
:
1248 TRACE("MCI_FORMAT_TMSF !\n");
1251 WARN("bad time format !\n");
1252 return MCIERR_BAD_TIME_FORMAT
;
1254 wmcda
->dwTimeFormat
= lpParms
->dwTimeFormat
;
1256 if (dwFlags
& MCI_SET_VIDEO
) return MCIERR_UNSUPPORTED_FUNCTION
;
1257 if (dwFlags
& MCI_SET_ON
) return MCIERR_UNSUPPORTED_FUNCTION
;
1258 if (dwFlags
& MCI_SET_OFF
) return MCIERR_UNSUPPORTED_FUNCTION
;
1259 if (dwFlags
& MCI_NOTIFY
) {
1260 TRACE("MCI_NOTIFY_SUCCESSFUL %08lX !\n",
1261 lpParms
->dwCallback
);
1262 mciDriverNotify(HWND_32(LOWORD(lpParms
->dwCallback
)),
1263 wmcda
->wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
1268 /**************************************************************************
1269 * DriverProc (MCICDA.@)
1271 LRESULT CALLBACK
MCICDA_DriverProc(DWORD_PTR dwDevID
, HDRVR hDriv
, UINT wMsg
,
1272 LPARAM dwParam1
, LPARAM dwParam2
)
1275 case DRV_LOAD
: return 1;
1276 case DRV_FREE
: return 1;
1277 case DRV_OPEN
: return MCICDA_drvOpen((LPCWSTR
)dwParam1
, (LPMCI_OPEN_DRIVER_PARMSW
)dwParam2
);
1278 case DRV_CLOSE
: return MCICDA_drvClose(dwDevID
);
1279 case DRV_ENABLE
: return 1;
1280 case DRV_DISABLE
: return 1;
1281 case DRV_QUERYCONFIGURE
: return 1;
1282 case DRV_CONFIGURE
: MessageBoxA(0, "MCI audio CD driver !", "Wine Driver", MB_OK
); return 1;
1283 case DRV_INSTALL
: return DRVCNF_RESTART
;
1284 case DRV_REMOVE
: return DRVCNF_RESTART
;
1287 if (dwDevID
== 0xFFFFFFFF) return MCIERR_UNSUPPORTED_FUNCTION
;
1290 case MCI_OPEN_DRIVER
: return MCICDA_Open(dwDevID
, dwParam1
, (LPMCI_OPEN_PARMSW
)dwParam2
);
1291 case MCI_CLOSE_DRIVER
: return MCICDA_Close(dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
1292 case MCI_GETDEVCAPS
: return MCICDA_GetDevCaps(dwDevID
, dwParam1
, (LPMCI_GETDEVCAPS_PARMS
)dwParam2
);
1293 case MCI_INFO
: return MCICDA_Info(dwDevID
, dwParam1
, (LPMCI_INFO_PARMSW
)dwParam2
);
1294 case MCI_STATUS
: return MCICDA_Status(dwDevID
, dwParam1
, (LPMCI_STATUS_PARMS
)dwParam2
);
1295 case MCI_SET
: return MCICDA_Set(dwDevID
, dwParam1
, (LPMCI_SET_PARMS
)dwParam2
);
1296 case MCI_PLAY
: return MCICDA_Play(dwDevID
, dwParam1
, (LPMCI_PLAY_PARMS
)dwParam2
);
1297 case MCI_STOP
: return MCICDA_Stop(dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
1298 case MCI_PAUSE
: return MCICDA_Pause(dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
1299 case MCI_RESUME
: return MCICDA_Resume(dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
1300 case MCI_SEEK
: return MCICDA_Seek(dwDevID
, dwParam1
, (LPMCI_SEEK_PARMS
)dwParam2
);
1301 /* commands that should report an error as they are not supported in
1302 * the native version */
1303 case MCI_SET_DOOR_CLOSED
:
1304 case MCI_SET_DOOR_OPEN
:
1321 TRACE("Unsupported command [0x%x]\n", wMsg
);
1325 ERR("Shouldn't receive a MCI_OPEN or CLOSE message\n");
1328 TRACE("Sending msg [0x%x] to default driver proc\n", wMsg
);
1329 return DefDriverProc(dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);
1331 return MCIERR_UNRECOGNIZED_COMMAND
;
1334 /*-----------------------------------------------------------------------*/