1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
3 * Sample MCI CDAUDIO Wine Driver for Linux
5 * Copyright 1994 Martin Ayotte
6 * Copyright 1998-99 Eric Pouech
12 #include "multimedia.h"
17 int nUseCount
; /* Incremented for each shared open */
18 BOOL16 fShareable
; /* TRUE if first open was shareable */
19 WORD wNotifyDeviceID
; /* MCI device ID with a pending notification */
20 HANDLE16 hCallback
; /* Callback handle for pending notification */
21 MCI_OPEN_PARMS16 openParms
;
27 #define MAX_CDAUDIODRV (1)
28 static WINE_MCICDAUDIO CDADev
[MAX_CDAUDIODRV
];
30 /*-----------------------------------------------------------------------*/
32 /**************************************************************************
33 * CDAUDIO_mciGetOpenDrv [internal]
35 static WINE_MCICDAUDIO
* CDAUDIO_mciGetOpenDrv(UINT16 wDevID
)
37 if (wDevID
>= MAX_CDAUDIODRV
|| CDADev
[wDevID
].nUseCount
== 0 ||
38 CDADev
[wDevID
].wcda
.unixdev
<= 0) {
39 WARN(cdaudio
, "Invalid wDevID=%u\n", wDevID
);
42 return &CDADev
[wDevID
];
45 /**************************************************************************
46 * CDAUDIO_mciMode [internal]
48 static int CDAUDIO_mciMode(int wcdaMode
)
51 case WINE_CDA_DONTKNOW
: return MCI_MODE_STOP
;
52 case WINE_CDA_NOTREADY
: return MCI_MODE_STOP
;
53 case WINE_CDA_OPEN
: return MCI_MODE_OPEN
;
54 case WINE_CDA_PLAY
: return MCI_MODE_PLAY
;
55 case WINE_CDA_STOP
: return MCI_MODE_STOP
;
56 case WINE_CDA_PAUSE
: return MCI_MODE_PAUSE
;
58 FIXME(cdaudio
, "Unknown mode %04x\n", wcdaMode
);
63 /**************************************************************************
64 * CDAUDIO_mciGetError [internal]
66 static int CDAUDIO_mciGetError(WINE_MCICDAUDIO
* wmcda
)
68 switch (wmcda
->wcda
.cdaMode
) {
69 case WINE_CDA_DONTKNOW
:
70 case WINE_CDA_NOTREADY
: return MCIERR_DEVICE_NOT_READY
;
71 case WINE_CDA_OPEN
: return MCIERR_DEVICE_OPEN
;
74 case WINE_CDA_PAUSE
: break;
76 FIXME(cdaudio
, "Unknown mode %04x\n", wmcda
->wcda
.cdaMode
);
78 return MCIERR_DRIVER_INTERNAL
;
81 /**************************************************************************
82 * CDAUDIO_CalcFrame [internal]
84 static DWORD
CDAUDIO_CalcFrame(WINE_MCICDAUDIO
* wmcda
, DWORD dwTime
)
89 TRACE(cdaudio
,"(%p, %08lX, %lu);\n", wmcda
, wmcda
->dwTimeFormat
, dwTime
);
91 switch (wmcda
->dwTimeFormat
) {
92 case MCI_FORMAT_MILLISECONDS
:
93 dwFrame
= (dwTime
* CDFRAMES_PERSEC
) / 1000;
94 TRACE(cdaudio
, "MILLISECONDS %lu\n", dwFrame
);
97 TRACE(cdaudio
, "MSF %02u:%02u:%02u\n",
98 MCI_MSF_MINUTE(dwTime
), MCI_MSF_SECOND(dwTime
), MCI_MSF_FRAME(dwTime
));
99 dwFrame
+= CDFRAMES_PERMIN
* MCI_MSF_MINUTE(dwTime
);
100 dwFrame
+= CDFRAMES_PERSEC
* MCI_MSF_SECOND(dwTime
);
101 dwFrame
+= MCI_MSF_FRAME(dwTime
);
103 case MCI_FORMAT_TMSF
:
105 /* unknown format ! force TMSF ! ... */
106 wTrack
= MCI_TMSF_TRACK(dwTime
);
107 TRACE(cdaudio
, "MSF %02u-%02u:%02u:%02u\n",
108 MCI_TMSF_TRACK(dwTime
), MCI_TMSF_MINUTE(dwTime
),
109 MCI_TMSF_SECOND(dwTime
), MCI_TMSF_FRAME(dwTime
));
110 TRACE(cdaudio
, "TMSF trackpos[%u]=%lu\n",
111 wTrack
, wmcda
->wcda
.lpdwTrackPos
[wTrack
- 1]);
112 dwFrame
= wmcda
->wcda
.lpdwTrackPos
[wTrack
- 1];
113 dwFrame
+= CDFRAMES_PERMIN
* MCI_TMSF_MINUTE(dwTime
);
114 dwFrame
+= CDFRAMES_PERSEC
* MCI_TMSF_SECOND(dwTime
);
115 dwFrame
+= MCI_TMSF_FRAME(dwTime
);
121 /**************************************************************************
122 * CDAUDIO_CalcTime [internal]
124 static DWORD
CDAUDIO_CalcTime(WINE_MCICDAUDIO
* wmcda
, DWORD dwFrame
)
132 TRACE(cdaudio
,"(%p, %08lX, %lu);\n", wmcda
, wmcda
->dwTimeFormat
, dwFrame
);
134 switch (wmcda
->dwTimeFormat
) {
135 case MCI_FORMAT_MILLISECONDS
:
136 dwTime
= (dwFrame
* 1000) / CDFRAMES_PERSEC
;
137 TRACE(cdaudio
, "MILLISECONDS %lu\n", dwTime
);
140 wMinutes
= dwFrame
/ CDFRAMES_PERMIN
;
141 wSeconds
= (dwFrame
- CDFRAMES_PERMIN
* wMinutes
) / CDFRAMES_PERSEC
;
142 wFrames
= dwFrame
- CDFRAMES_PERMIN
* wMinutes
- CDFRAMES_PERSEC
* wSeconds
;
143 dwTime
= MCI_MAKE_MSF(wMinutes
, wSeconds
, wFrames
);
144 TRACE(cdaudio
,"MSF %02u:%02u:%02u -> dwTime=%lu\n",wMinutes
, wSeconds
, wFrames
, dwTime
);
146 case MCI_FORMAT_TMSF
:
148 /* unknown format ! force TMSF ! ... */
149 for (wTrack
= 0; wTrack
< wmcda
->wcda
.nTracks
; wTrack
++) {
150 /* dwTime += wmcda->lpdwTrackLen[wTrack - 1];
151 TRACE(cdaudio, "Adding trk#%u curpos=%u \n", dwTime);
152 if (dwTime >= dwFrame) break; */
153 if (wmcda
->wcda
.lpdwTrackPos
[wTrack
- 1] >= dwFrame
) break;
155 wMinutes
= dwFrame
/ CDFRAMES_PERMIN
;
156 wSeconds
= (dwFrame
- CDFRAMES_PERMIN
* wMinutes
) / CDFRAMES_PERSEC
;
157 wFrames
= dwFrame
- CDFRAMES_PERMIN
* wMinutes
- CDFRAMES_PERSEC
* wSeconds
;
158 dwTime
= MCI_MAKE_TMSF(wTrack
, wMinutes
, wSeconds
, wFrames
);
159 TRACE(cdaudio
, "%02u-%02u:%02u:%02u\n", wTrack
, wMinutes
, wSeconds
, wFrames
);
165 static DWORD
CDAUDIO_mciSeek(UINT16 wDevID
, DWORD dwFlags
, LPMCI_SEEK_PARMS lpParms
);
166 static DWORD
CDAUDIO_mciStop(UINT16 wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
);
168 /**************************************************************************
169 * CDAUDIO_mciOpen [internal]
171 static DWORD
CDAUDIO_mciOpen(UINT16 wDevID
, DWORD dwFlags
, LPMCI_OPEN_PARMSA lpOpenParms
)
174 WINE_MCICDAUDIO
* wmcda
;
175 MCI_SEEK_PARMS seekParms
;
177 TRACE(cdaudio
,"(%04X, %08lX, %p);\n", wDevID
, dwFlags
, lpOpenParms
);
179 if (lpOpenParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
180 if (wDevID
> MAX_CDAUDIODRV
) return MCIERR_INVALID_DEVICE_ID
;
182 dwDeviceID
= lpOpenParms
->wDeviceID
;
184 wmcda
= &CDADev
[wDevID
];
186 if (wmcda
->nUseCount
> 0) {
187 /* The driver is already open on this channel */
188 /* If the driver was opened shareable before and this open specifies */
189 /* shareable then increment the use count */
190 if (wmcda
->fShareable
&& (dwFlags
& MCI_OPEN_SHAREABLE
))
193 return MCIERR_MUST_USE_SHAREABLE
;
195 wmcda
->nUseCount
= 1;
196 wmcda
->fShareable
= dwFlags
& MCI_OPEN_SHAREABLE
;
198 if (dwFlags
& MCI_OPEN_ELEMENT
) {
199 TRACE(cdaudio
,"MCI_OPEN_ELEMENT !\n");
200 /* return MCIERR_NO_ELEMENT_ALLOWED; */
203 wmcda
->openParms
.dwCallback
= lpOpenParms
->dwCallback
;
204 wmcda
->openParms
.wDeviceID
= (WORD
)lpOpenParms
->wDeviceID
;
205 wmcda
->openParms
.wReserved0
= 0; /*????*/
206 wmcda
->openParms
.lpstrDeviceType
= lpOpenParms
->lpstrDeviceType
;
207 wmcda
->openParms
.lpstrElementName
= lpOpenParms
->lpstrElementName
;
208 wmcda
->openParms
.lpstrAlias
= lpOpenParms
->lpstrAlias
;
210 wmcda
->wNotifyDeviceID
= dwDeviceID
;
211 if (CDAUDIO_Open(&wmcda
->wcda
) == -1) {
213 return MCIERR_HARDWARE
;
215 wmcda
->mciMode
= MCI_MODE_STOP
;
216 wmcda
->dwTimeFormat
= MCI_FORMAT_TMSF
;
217 if (!CDAUDIO_GetTracksInfo(&wmcda
->wcda
)) {
218 WARN(cdaudio
,"error reading TracksInfo !\n");
219 /* return MCIERR_INTERNAL; */
222 CDAUDIO_mciSeek(wDevID
, MCI_SEEK_TO_START
, &seekParms
);
227 /**************************************************************************
228 * CDAUDIO_mciClose [internal]
230 static DWORD
CDAUDIO_mciClose(UINT16 wDevID
, DWORD dwParam
, LPMCI_GENERIC_PARMS lpParms
)
232 WINE_MCICDAUDIO
* wmcda
= CDAUDIO_mciGetOpenDrv(wDevID
);
234 TRACE(cdaudio
,"(%04X, %08lX, %p);\n", wDevID
, dwParam
, lpParms
);
236 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
238 if (wmcda
->nUseCount
== 1) {
239 CDAUDIO_mciStop(wDevID
, 0, NULL
);
240 CDAUDIO_Close(&wmcda
->wcda
);
246 /**************************************************************************
247 * CDAUDIO_mciGetDevCaps [internal]
249 static DWORD
CDAUDIO_mciGetDevCaps(UINT16 wDevID
, DWORD dwFlags
,
250 LPMCI_GETDEVCAPS_PARMS lpParms
)
252 TRACE(cdaudio
,"(%04X, %08lX, %p);\n", wDevID
, dwFlags
, lpParms
);
254 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
256 if (dwFlags
& MCI_GETDEVCAPS_ITEM
) {
257 TRACE(cdaudio
, "MCI_GETDEVCAPS_ITEM dwItem=%08lX;\n", lpParms
->dwItem
);
259 switch(lpParms
->dwItem
) {
260 case MCI_GETDEVCAPS_CAN_RECORD
:
261 lpParms
->dwReturn
= FALSE
;
263 case MCI_GETDEVCAPS_HAS_AUDIO
:
264 lpParms
->dwReturn
= TRUE
;
266 case MCI_GETDEVCAPS_HAS_VIDEO
:
267 lpParms
->dwReturn
= FALSE
;
269 case MCI_GETDEVCAPS_DEVICE_TYPE
:
270 lpParms
->dwReturn
= MCI_DEVTYPE_CD_AUDIO
;
272 case MCI_GETDEVCAPS_USES_FILES
:
273 lpParms
->dwReturn
= FALSE
;
275 case MCI_GETDEVCAPS_COMPOUND_DEVICE
:
276 lpParms
->dwReturn
= FALSE
;
278 case MCI_GETDEVCAPS_CAN_EJECT
:
279 lpParms
->dwReturn
= TRUE
;
281 case MCI_GETDEVCAPS_CAN_PLAY
:
282 lpParms
->dwReturn
= TRUE
;
284 case MCI_GETDEVCAPS_CAN_SAVE
:
285 lpParms
->dwReturn
= FALSE
;
288 return MCIERR_UNRECOGNIZED_COMMAND
;
291 TRACE(cdaudio
, "lpParms->dwReturn=%08lX;\n", lpParms
->dwReturn
);
295 /**************************************************************************
296 * CDAUDIO_mciInfo [internal]
298 static DWORD
CDAUDIO_mciInfo(UINT16 wDevID
, DWORD dwFlags
, LPMCI_INFO_PARMS16 lpParms
)
302 WINE_MCICDAUDIO
* wmcda
= CDAUDIO_mciGetOpenDrv(wDevID
);
304 TRACE(cdaudio
,"(%04X, %08lX, %p);\n", wDevID
, dwFlags
, lpParms
);
306 if (lpParms
== NULL
|| lpParms
->lpstrReturn
== NULL
) {
307 ret
= MCIERR_NULL_PARAMETER_BLOCK
;
308 } else if (wmcda
== NULL
) {
309 ret
= MCIERR_INVALID_DEVICE_ID
;
311 TRACE(cdaudio
, "buf=%p, len=%lu\n", lpParms
->lpstrReturn
, lpParms
->dwRetSize
);
314 case MCI_INFO_PRODUCT
:
315 str
= "Wine's audio CD";
318 WARN(cdaudio
, "Don't know this info command (%lu)\n", dwFlags
);
319 ret
= MCIERR_UNRECOGNIZED_COMMAND
;
323 ret
= MCI_WriteString(lpParms
->lpstrReturn
, lpParms
->dwRetSize
, str
);
325 lpParms
->lpstrReturn
[0] = 0;
331 /**************************************************************************
332 * CDAUDIO_mciStatus [internal]
334 static DWORD
CDAUDIO_mciStatus(UINT16 wDevID
, DWORD dwFlags
, LPMCI_STATUS_PARMS lpParms
)
336 WINE_MCICDAUDIO
* wmcda
= CDAUDIO_mciGetOpenDrv(wDevID
);
339 TRACE(cdaudio
,"(%04X, %08lX, %p);\n", wDevID
, dwFlags
, lpParms
);
341 if (lpParms
== NULL
) {
342 ret
= MCIERR_NULL_PARAMETER_BLOCK
;
343 } else if (wmcda
== NULL
) {
344 ret
= MCIERR_INVALID_DEVICE_ID
;
346 if (dwFlags
& MCI_NOTIFY
) {
347 TRACE(cdaudio
, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
348 mciDriverNotify16((HWND16
)LOWORD(lpParms
->dwCallback
),
349 wmcda
->wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
351 if (dwFlags
& MCI_STATUS_ITEM
) {
352 switch (lpParms
->dwItem
) {
353 case MCI_STATUS_CURRENT_TRACK
:
354 if (!CDAUDIO_GetCDStatus(&wmcda
->wcda
)) {
355 return CDAUDIO_mciGetError(wmcda
);
357 lpParms
->dwReturn
= wmcda
->wcda
.nCurTrack
;
358 TRACE(cdaudio
,"CURRENT_TRACK=%lu!\n", lpParms
->dwReturn
);
360 case MCI_STATUS_LENGTH
:
361 if (wmcda
->wcda
.nTracks
== 0) {
362 if (!CDAUDIO_GetTracksInfo(&wmcda
->wcda
)) {
363 WARN(cdaudio
, "error reading TracksInfo !\n");
364 return CDAUDIO_mciGetError(wmcda
);
367 if (dwFlags
& MCI_TRACK
) {
368 TRACE(cdaudio
,"MCI_TRACK #%lu LENGTH=??? !\n", lpParms
->dwTrack
);
369 if (lpParms
->dwTrack
> wmcda
->wcda
.nTracks
|| lpParms
->dwTrack
== 0)
370 return MCIERR_OUTOFRANGE
;
371 lpParms
->dwReturn
= wmcda
->wcda
.lpdwTrackLen
[lpParms
->dwTrack
- 1];
373 lpParms
->dwReturn
= wmcda
->wcda
.dwTotalLen
;
375 lpParms
->dwReturn
= CDAUDIO_CalcTime(wmcda
, lpParms
->dwReturn
);
376 TRACE(cdaudio
,"LENGTH=%lu !\n", lpParms
->dwReturn
);
378 case MCI_STATUS_MODE
:
379 if (!CDAUDIO_GetCDStatus(&wmcda
->wcda
))
380 return CDAUDIO_mciGetError(wmcda
);
381 lpParms
->dwReturn
= CDAUDIO_mciMode(wmcda
->wcda
.cdaMode
);
382 if (!lpParms
->dwReturn
) lpParms
->dwReturn
= wmcda
->mciMode
;
383 TRACE(cdaudio
,"MCI_STATUS_MODE=%08lX !\n", lpParms
->dwReturn
);
385 case MCI_STATUS_MEDIA_PRESENT
:
386 if (!CDAUDIO_GetCDStatus(&wmcda
->wcda
))
387 return CDAUDIO_mciGetError(wmcda
);
388 lpParms
->dwReturn
= (wmcda
->wcda
.nTracks
> 0) ? TRUE
: FALSE
;
389 TRACE(cdaudio
,"MCI_STATUS_MEDIA_PRESENT =%s!\n", lpParms
->dwReturn
? "Y" : "N");
391 case MCI_STATUS_NUMBER_OF_TRACKS
:
392 lpParms
->dwReturn
= CDAUDIO_GetNumberOfTracks(&wmcda
->wcda
);
393 TRACE(cdaudio
,"MCI_STATUS_NUMBER_OF_TRACKS = %lu !\n", lpParms
->dwReturn
);
394 if (lpParms
->dwReturn
== (WORD
)-1)
395 return CDAUDIO_mciGetError(wmcda
);
397 case MCI_STATUS_POSITION
:
398 if (!CDAUDIO_GetCDStatus(&wmcda
->wcda
))
399 return CDAUDIO_mciGetError(wmcda
);
400 lpParms
->dwReturn
= wmcda
->wcda
.dwCurFrame
;
401 if (dwFlags
& MCI_STATUS_START
) {
402 lpParms
->dwReturn
= wmcda
->wcda
.dwFirstOffset
;
403 TRACE(cdaudio
,"get MCI_STATUS_START !\n");
405 if (dwFlags
& MCI_TRACK
) {
406 if (lpParms
->dwTrack
> wmcda
->wcda
.nTracks
|| lpParms
->dwTrack
== 0)
407 return MCIERR_OUTOFRANGE
;
408 lpParms
->dwReturn
= wmcda
->wcda
.lpdwTrackPos
[lpParms
->dwTrack
- 1];
409 TRACE(cdaudio
,"get MCI_TRACK #%lu !\n", lpParms
->dwTrack
);
411 lpParms
->dwReturn
= CDAUDIO_CalcTime(wmcda
, lpParms
->dwReturn
);
412 TRACE(cdaudio
,"MCI_STATUS_POSITION=%08lX !\n", lpParms
->dwReturn
);
414 case MCI_STATUS_READY
:
415 TRACE(cdaudio
,"MCI_STATUS_READY !\n");
416 lpParms
->dwReturn
= (wmcda
->wcda
.cdaMode
!= WINE_CDA_DONTKNOW
&& wmcda
->wcda
.cdaMode
!= WINE_CDA_NOTREADY
);
417 TRACE(cdaudio
,"MCI_STATUS_READY=%ld!\n", lpParms
->dwReturn
);
419 case MCI_STATUS_TIME_FORMAT
:
420 lpParms
->dwReturn
= wmcda
->dwTimeFormat
;
421 TRACE(cdaudio
,"MCI_STATUS_TIME_FORMAT =%08lx!\n", lpParms
->dwReturn
);
423 case MCI_CDA_STATUS_TYPE_TRACK
:
424 if (!(dwFlags
& MCI_TRACK
))
425 return MCIERR_MISSING_PARAMETER
;
426 if (lpParms
->dwTrack
> wmcda
->wcda
.nTracks
|| lpParms
->dwTrack
== 0)
427 return MCIERR_OUTOFRANGE
;
428 lpParms
->dwReturn
= (wmcda
->wcda
.lpbTrackFlags
[lpParms
->dwTrack
- 1] &
429 CDROM_DATA_TRACK
) ? MCI_CDA_TRACK_OTHER
: MCI_CDA_TRACK_AUDIO
;
430 TRACE(cdaudio
, "MCI_CDA_STATUS_TYPE_TRACK[%ld]=%08lx\n", lpParms
->dwTrack
, lpParms
->dwReturn
);
433 WARN(cdaudio
, "unknown command %08lX !\n", lpParms
->dwItem
);
434 return MCIERR_UNRECOGNIZED_COMMAND
;
438 WARN(cdaudio
, "not MCI_STATUS_ITEM !\n");
442 /**************************************************************************
443 * CDAUDIO_mciPlay [internal]
445 static DWORD
CDAUDIO_mciPlay(UINT16 wDevID
, DWORD dwFlags
, LPMCI_PLAY_PARMS lpParms
)
448 WINE_MCICDAUDIO
* wmcda
= CDAUDIO_mciGetOpenDrv(wDevID
);
451 TRACE(cdaudio
,"(%04X, %08lX, %p);\n", wDevID
, dwFlags
, lpParms
);
453 if (lpParms
== NULL
) {
454 ret
= MCIERR_NULL_PARAMETER_BLOCK
;
455 } else if (wmcda
== NULL
) {
456 ret
= MCIERR_INVALID_DEVICE_ID
;
458 if (wmcda
->wcda
.nTracks
== 0) {
459 if (!CDAUDIO_GetTracksInfo(&wmcda
->wcda
)) {
460 WARN(cdaudio
, "error reading TracksInfo !\n");
461 return MCIERR_DRIVER_INTERNAL
;
464 end
= wmcda
->wcda
.dwTotalLen
;
465 wmcda
->wcda
.nCurTrack
= 1;
466 if (dwFlags
& MCI_FROM
) {
467 start
= CDAUDIO_CalcFrame(wmcda
, lpParms
->dwFrom
);
468 TRACE(cdaudio
,"MCI_FROM=%08lX -> %u \n", lpParms
->dwFrom
, start
);
470 if (!CDAUDIO_GetCDStatus(&wmcda
->wcda
)) return MCIERR_DRIVER_INTERNAL
;
471 start
= wmcda
->wcda
.dwCurFrame
;
473 if (dwFlags
& MCI_TO
) {
474 end
= CDAUDIO_CalcFrame(wmcda
, lpParms
->dwTo
);
475 TRACE(cdaudio
, "MCI_TO=%08lX -> %u \n", lpParms
->dwTo
, end
);
477 end
+= wmcda
->wcda
.dwFirstOffset
;
479 if (CDAUDIO_Play(&wmcda
->wcda
, start
, end
) == -1)
480 return MCIERR_HARDWARE
;
481 wmcda
->mciMode
= MCI_MODE_PLAY
;
482 if (dwFlags
& MCI_NOTIFY
) {
483 TRACE(cdaudio
, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
485 mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback),
486 wmcda->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
493 /**************************************************************************
494 * CDAUDIO_mciStop [internal]
496 static DWORD
CDAUDIO_mciStop(UINT16 wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
498 WINE_MCICDAUDIO
* wmcda
= CDAUDIO_mciGetOpenDrv(wDevID
);
500 TRACE(cdaudio
,"(%04X, %08lX, %p);\n", wDevID
, dwFlags
, lpParms
);
502 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
504 if (CDAUDIO_Stop(&wmcda
->wcda
) == -1)
505 return MCIERR_HARDWARE
;
506 wmcda
->mciMode
= MCI_MODE_STOP
;
507 if (lpParms
&& (dwFlags
& MCI_NOTIFY
)) {
508 TRACE(cdaudio
, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
509 mciDriverNotify16((HWND16
)LOWORD(lpParms
->dwCallback
),
510 wmcda
->wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
515 /**************************************************************************
516 * CDAUDIO_mciPause [internal]
518 static DWORD
CDAUDIO_mciPause(UINT16 wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
520 WINE_MCICDAUDIO
* wmcda
= CDAUDIO_mciGetOpenDrv(wDevID
);
522 TRACE(cdaudio
,"(%04X, %08lX, %p);\n", wDevID
, dwFlags
, lpParms
);
524 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
526 if (CDAUDIO_Pause(&wmcda
->wcda
, 1) == -1)
527 return MCIERR_HARDWARE
;
528 wmcda
->mciMode
= MCI_MODE_PAUSE
;
529 if (lpParms
&& (dwFlags
& MCI_NOTIFY
)) {
530 TRACE(cdaudio
, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
531 mciDriverNotify16((HWND16
)LOWORD(lpParms
->dwCallback
),
532 wmcda
->wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
537 /**************************************************************************
538 * CDAUDIO_mciResume [internal]
540 static DWORD
CDAUDIO_mciResume(UINT16 wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
542 WINE_MCICDAUDIO
* wmcda
= CDAUDIO_mciGetOpenDrv(wDevID
);
544 TRACE(cdaudio
,"(%04X, %08lX, %p);\n", wDevID
, dwFlags
, lpParms
);
546 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
548 if (CDAUDIO_Pause(&wmcda
->wcda
, 0) == -1)
549 return MCIERR_HARDWARE
;
550 wmcda
->mciMode
= MCI_MODE_STOP
;
551 if (lpParms
&& (dwFlags
& MCI_NOTIFY
)) {
552 TRACE(cdaudio
, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
553 mciDriverNotify16((HWND16
)LOWORD(lpParms
->dwCallback
),
554 wmcda
->wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
559 /**************************************************************************
560 * CDAUDIO_mciSeek [internal]
562 static DWORD
CDAUDIO_mciSeek(UINT16 wDevID
, DWORD dwFlags
, LPMCI_SEEK_PARMS lpParms
)
565 MCI_PLAY_PARMS playParms
;
567 WINE_MCICDAUDIO
* wmcda
= CDAUDIO_mciGetOpenDrv(wDevID
);
569 TRACE(cdaudio
,"(%04X, %08lX, %p);\n", wDevID
, dwFlags
, lpParms
);
571 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
572 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;
574 wmcda
->mciMode
= MCI_MODE_SEEK
;
575 switch (dwFlags
& ~(MCI_NOTIFY
|MCI_WAIT
)) {
576 case MCI_SEEK_TO_START
:
577 TRACE(cdaudio
, "Seeking to start\n");
578 playParms
.dwFrom
= 0;
580 case MCI_SEEK_TO_END
:
581 TRACE(cdaudio
, "Seeking to end\n");
582 playParms
.dwFrom
= wmcda
->wcda
.dwTotalLen
;
585 TRACE(cdaudio
, "Seeking to %lu\n", lpParms
->dwTo
);
586 playParms
.dwFrom
= lpParms
->dwTo
;
589 TRACE(cdaudio
, "Seeking to ??=%lu\n", dwFlags
);
590 return MCIERR_UNSUPPORTED_FUNCTION
;
592 dwRet
= CDAUDIO_mciPlay(wDevID
, MCI_WAIT
| MCI_FROM
, &playParms
);
593 if (dwRet
!= 0) return dwRet
;
594 dwRet
= CDAUDIO_mciStop(wDevID
, MCI_WAIT
, (LPMCI_GENERIC_PARMS
)&playParms
);
595 if (dwFlags
& MCI_NOTIFY
) {
596 TRACE(cdaudio
, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms
->dwCallback
);
597 mciDriverNotify16((HWND16
)LOWORD(lpParms
->dwCallback
),
598 wmcda
->wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
603 /**************************************************************************
604 * CDAUDIO_mciSetDoor [internal]
606 static DWORD
CDAUDIO_mciSetDoor(UINT16 wDevID
, int open
)
608 WINE_MCICDAUDIO
* wmcda
= CDAUDIO_mciGetOpenDrv(wDevID
);
610 TRACE(cdaudio
, "(%04x, %s) !\n", wDevID
, (open
) ? "OPEN" : "CLOSE");
612 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
614 if (CDAUDIO_SetDoor(&wmcda
->wcda
, open
) == -1)
615 return MCIERR_HARDWARE
;
616 wmcda
->mciMode
= (open
) ? MCI_MODE_OPEN
: MCI_MODE_STOP
;
620 /**************************************************************************
621 * CDAUDIO_mciSet [internal]
623 static DWORD
CDAUDIO_mciSet(UINT16 wDevID
, DWORD dwFlags
, LPMCI_SET_PARMS lpParms
)
625 WINE_MCICDAUDIO
* wmcda
= CDAUDIO_mciGetOpenDrv(wDevID
);
627 TRACE(cdaudio
,"(%04X, %08lX, %p);\n", wDevID
, dwFlags
, lpParms
);
629 if (wmcda
== NULL
) return MCIERR_INVALID_DEVICE_ID
;
630 if (lpParms
== NULL
) return MCIERR_NULL_PARAMETER_BLOCK
;;
632 TRACE(cdaudio,"dwTimeFormat=%08lX\n", lpParms->dwTimeFormat);
633 TRACE(cdaudio,"dwAudio=%08lX\n", lpParms->dwAudio);
635 if (dwFlags
& MCI_SET_TIME_FORMAT
) {
636 switch (lpParms
->dwTimeFormat
) {
637 case MCI_FORMAT_MILLISECONDS
:
638 TRACE(cdaudio
, "MCI_FORMAT_MILLISECONDS !\n");
641 TRACE(cdaudio
,"MCI_FORMAT_MSF !\n");
643 case MCI_FORMAT_TMSF
:
644 TRACE(cdaudio
,"MCI_FORMAT_TMSF !\n");
647 WARN(cdaudio
, "bad time format !\n");
648 return MCIERR_BAD_TIME_FORMAT
;
650 wmcda
->dwTimeFormat
= lpParms
->dwTimeFormat
;
652 if (dwFlags
& MCI_SET_DOOR_OPEN
) {
653 CDAUDIO_mciSetDoor(wDevID
, TRUE
);
655 if (dwFlags
& MCI_SET_DOOR_CLOSED
) {
656 CDAUDIO_mciSetDoor(wDevID
, FALSE
);
658 if (dwFlags
& MCI_SET_VIDEO
) return MCIERR_UNSUPPORTED_FUNCTION
;
659 if (dwFlags
& MCI_SET_ON
) return MCIERR_UNSUPPORTED_FUNCTION
;
660 if (dwFlags
& MCI_SET_OFF
) return MCIERR_UNSUPPORTED_FUNCTION
;
661 if (dwFlags
& MCI_NOTIFY
) {
662 TRACE(cdaudio
, "MCI_NOTIFY_SUCCESSFUL %08lX !\n",
663 lpParms
->dwCallback
);
664 mciDriverNotify16((HWND16
)LOWORD(lpParms
->dwCallback
),
665 wmcda
->wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
670 /**************************************************************************
671 * MCICDAUDIO_DriverProc32 [sample driver]
673 LONG
MCICDAUDIO_DriverProc(DWORD dwDevID
, HDRVR16 hDriv
, DWORD wMsg
,
674 DWORD dwParam1
, DWORD dwParam2
)
677 case DRV_LOAD
: return 1;
678 case DRV_FREE
: return 1;
679 case DRV_OPEN
: return 1;
680 case DRV_CLOSE
: return 1;
681 case DRV_ENABLE
: return 1;
682 case DRV_DISABLE
: return 1;
683 case DRV_QUERYCONFIGURE
: return 1;
684 case DRV_CONFIGURE
: MessageBoxA(0, "Sample Multimedia Linux Driver !", "MMLinux Driver", MB_OK
); return 1;
685 case DRV_INSTALL
: return DRVCNF_RESTART
;
686 case DRV_REMOVE
: return DRVCNF_RESTART
;
688 case MCI_OPEN_DRIVER
: return CDAUDIO_mciOpen(dwDevID
, dwParam1
, (LPMCI_OPEN_PARMSA
)dwParam2
);
689 case MCI_CLOSE_DRIVER
: return CDAUDIO_mciClose(dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
690 case MCI_GETDEVCAPS
: return CDAUDIO_mciGetDevCaps(dwDevID
, dwParam1
, (LPMCI_GETDEVCAPS_PARMS
)dwParam2
);
691 case MCI_INFO
: return CDAUDIO_mciInfo(dwDevID
, dwParam1
, (LPMCI_INFO_PARMS16
)dwParam2
);
692 case MCI_STATUS
: return CDAUDIO_mciStatus(dwDevID
, dwParam1
, (LPMCI_STATUS_PARMS
)dwParam2
);
693 case MCI_SET
: return CDAUDIO_mciSet(dwDevID
, dwParam1
, (LPMCI_SET_PARMS
)dwParam2
);
694 case MCI_PLAY
: return CDAUDIO_mciPlay(dwDevID
, dwParam1
, (LPMCI_PLAY_PARMS
)dwParam2
);
695 case MCI_STOP
: return CDAUDIO_mciStop(dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
696 case MCI_PAUSE
: return CDAUDIO_mciPause(dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
697 case MCI_RESUME
: return CDAUDIO_mciResume(dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)dwParam2
);
698 case MCI_SEEK
: return CDAUDIO_mciSeek(dwDevID
, dwParam1
, (LPMCI_SEEK_PARMS
)dwParam2
);
699 /* FIXME: I wonder if those two next items are really called ? */
700 case MCI_SET_DOOR_OPEN
: return CDAUDIO_mciSetDoor(dwDevID
, TRUE
);
701 case MCI_SET_DOOR_CLOSED
: return CDAUDIO_mciSetDoor(dwDevID
, FALSE
);
718 WARN(cdaudio
, "Unsupported command=%s\n", MCI_CommandToString(wMsg
));
722 FIXME(cdaudio
, "Shouldn't receive a MCI_OPEN or CLOSE message\n");
725 TRACE(cdaudio
, "Sending msg=%s to default driver proc\n", MCI_CommandToString(wMsg
));
726 return DefDriverProc(dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);
728 return MCIERR_UNRECOGNIZED_COMMAND
;
731 /*-----------------------------------------------------------------------*/