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 /* FIXME: I don't think we have to stop CD on exit
240 * CDAUDIO_mciStop(wDevID, 0, NULL);
242 CDAUDIO_Close(&wmcda->wcda);
248 /**************************************************************************
249 * CDAUDIO_mciGetDevCaps [internal]
251 static DWORD CDAUDIO_mciGetDevCaps(UINT16 wDevID, DWORD dwFlags,
252 LPMCI_GETDEVCAPS_PARMS lpParms)
254 TRACE(cdaudio,"(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
256 if (lpParms == NULL) return MCIERR_NULL_PARAMETER_BLOCK;
258 if (dwFlags & MCI_GETDEVCAPS_ITEM) {
259 TRACE(cdaudio, "MCI_GETDEVCAPS_ITEM dwItem=%08lX;\n", lpParms->dwItem);
261 switch(lpParms->dwItem) {
262 case MCI_GETDEVCAPS_CAN_RECORD:
263 lpParms->dwReturn = FALSE;
265 case MCI_GETDEVCAPS_HAS_AUDIO:
266 lpParms->dwReturn = TRUE;
268 case MCI_GETDEVCAPS_HAS_VIDEO:
269 lpParms->dwReturn = FALSE;
271 case MCI_GETDEVCAPS_DEVICE_TYPE:
272 lpParms->dwReturn = MCI_DEVTYPE_CD_AUDIO;
274 case MCI_GETDEVCAPS_USES_FILES:
275 lpParms->dwReturn = FALSE;
277 case MCI_GETDEVCAPS_COMPOUND_DEVICE:
278 lpParms->dwReturn = FALSE;
280 case MCI_GETDEVCAPS_CAN_EJECT:
281 lpParms->dwReturn = TRUE;
283 case MCI_GETDEVCAPS_CAN_PLAY:
284 lpParms->dwReturn = TRUE;
286 case MCI_GETDEVCAPS_CAN_SAVE:
287 lpParms->dwReturn = FALSE;
290 return MCIERR_UNRECOGNIZED_COMMAND;
293 TRACE(cdaudio, "lpParms->dwReturn=%08lX;\n", lpParms->dwReturn);
297 /**************************************************************************
298 * CDAUDIO_mciInfo [internal]
300 static DWORD CDAUDIO_mciInfo(UINT16 wDevID, DWORD dwFlags, LPMCI_INFO_PARMS16 lpParms)
304 WINE_MCICDAUDIO* wmcda = CDAUDIO_mciGetOpenDrv(wDevID);
306 TRACE(cdaudio,"(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
308 if (lpParms == NULL || lpParms->lpstrReturn == NULL) {
309 ret = MCIERR_NULL_PARAMETER_BLOCK;
310 } else if (wmcda == NULL) {
311 ret = MCIERR_INVALID_DEVICE_ID;
313 TRACE(cdaudio, "buf=%p, len=%lu\n", lpParms->lpstrReturn, lpParms->dwRetSize);
316 case MCI_INFO_PRODUCT:
317 str = "Wine's audio CD";
320 WARN(cdaudio, "Don't know this info command (%lu)\n", dwFlags);
321 ret = MCIERR_UNRECOGNIZED_COMMAND;
325 ret = MCI_WriteString(lpParms->lpstrReturn, lpParms->dwRetSize, str);
327 lpParms->lpstrReturn[0] = 0;
333 /**************************************************************************
334 * CDAUDIO_mciStatus [internal]
336 static DWORD CDAUDIO_mciStatus(UINT16 wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
338 WINE_MCICDAUDIO* wmcda = CDAUDIO_mciGetOpenDrv(wDevID);
341 TRACE(cdaudio,"(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
343 if (lpParms == NULL) {
344 ret = MCIERR_NULL_PARAMETER_BLOCK;
345 } else if (wmcda == NULL) {
346 ret = MCIERR_INVALID_DEVICE_ID;
348 if (dwFlags & MCI_NOTIFY) {
349 TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
350 mciDriverNotify16((HWND16)LOWORD(lpParms->dwCallback),
351 wmcda->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
353 if (dwFlags & MCI_STATUS_ITEM) {
354 switch (lpParms->dwItem) {
355 case MCI_STATUS_CURRENT_TRACK:
356 if (!CDAUDIO_GetCDStatus(&wmcda->wcda)) {
357 return CDAUDIO_mciGetError(wmcda);
359 lpParms->dwReturn = wmcda->wcda.nCurTrack;
360 TRACE(cdaudio,"CURRENT_TRACK=%lu!\n", lpParms->dwReturn);
362 case MCI_STATUS_LENGTH:
363 if (wmcda->wcda.nTracks == 0) {
364 if (!CDAUDIO_GetTracksInfo(&wmcda->wcda)) {
365 WARN(cdaudio, "error reading TracksInfo !\n");
366 return CDAUDIO_mciGetError(wmcda);
369 if (dwFlags & MCI_TRACK) {
370 TRACE(cdaudio,"MCI_TRACK #%lu LENGTH=??? !\n", lpParms->dwTrack);
371 if (lpParms->dwTrack > wmcda->wcda.nTracks || lpParms->dwTrack == 0)
372 return MCIERR_OUTOFRANGE;
373 lpParms->dwReturn = wmcda->wcda.lpdwTrackLen[lpParms->dwTrack - 1];
375 lpParms->dwReturn = wmcda->wcda.dwTotalLen;
377 lpParms->dwReturn = CDAUDIO_CalcTime(wmcda, lpParms->dwReturn);
378 TRACE(cdaudio,"LENGTH=%lu !\n", lpParms->dwReturn);
380 case MCI_STATUS_MODE:
381 if (!CDAUDIO_GetCDStatus(&wmcda->wcda))
382 return CDAUDIO_mciGetError(wmcda);
383 lpParms->dwReturn = CDAUDIO_mciMode(wmcda->wcda.cdaMode);
384 if (!lpParms->dwReturn) lpParms->dwReturn = wmcda->mciMode;
385 TRACE(cdaudio,"MCI_STATUS_MODE=%08lX !\n", lpParms->dwReturn);
387 case MCI_STATUS_MEDIA_PRESENT:
388 if (!CDAUDIO_GetCDStatus(&wmcda->wcda))
389 return CDAUDIO_mciGetError(wmcda);
390 lpParms->dwReturn = (wmcda->wcda.nTracks > 0) ? TRUE : FALSE;
391 TRACE(cdaudio,"MCI_STATUS_MEDIA_PRESENT =%s!\n", lpParms->dwReturn ? "Y" : "N");
393 case MCI_STATUS_NUMBER_OF_TRACKS:
394 lpParms->dwReturn = CDAUDIO_GetNumberOfTracks(&wmcda->wcda);
395 TRACE(cdaudio,"MCI_STATUS_NUMBER_OF_TRACKS = %lu !\n", lpParms->dwReturn);
396 if (lpParms->dwReturn == (WORD)-1)
397 return CDAUDIO_mciGetError(wmcda);
399 case MCI_STATUS_POSITION:
400 if (!CDAUDIO_GetCDStatus(&wmcda->wcda))
401 return CDAUDIO_mciGetError(wmcda);
402 lpParms->dwReturn = wmcda->wcda.dwCurFrame;
403 if (dwFlags & MCI_STATUS_START) {
404 lpParms->dwReturn = wmcda->wcda.dwFirstOffset;
405 TRACE(cdaudio,"get MCI_STATUS_START !\n");
407 if (dwFlags & MCI_TRACK) {
408 if (lpParms->dwTrack > wmcda->wcda.nTracks || lpParms->dwTrack == 0)
409 return MCIERR_OUTOFRANGE;
410 lpParms->dwReturn = wmcda->wcda.lpdwTrackPos[lpParms->dwTrack - 1];
411 TRACE(cdaudio,"get MCI_TRACK #%lu !\n", lpParms->dwTrack);
413 lpParms->dwReturn = CDAUDIO_CalcTime(wmcda, lpParms->dwReturn);
414 TRACE(cdaudio,"MCI_STATUS_POSITION=%08lX !\n", lpParms->dwReturn);
416 case MCI_STATUS_READY:
417 TRACE(cdaudio,"MCI_STATUS_READY !\n");
418 lpParms->dwReturn = (wmcda->wcda.cdaMode != WINE_CDA_DONTKNOW && wmcda->wcda.cdaMode != WINE_CDA_NOTREADY);
419 TRACE(cdaudio,"MCI_STATUS_READY=%ld!\n", lpParms->dwReturn);
421 case MCI_STATUS_TIME_FORMAT:
422 lpParms->dwReturn = wmcda->dwTimeFormat;
423 TRACE(cdaudio,"MCI_STATUS_TIME_FORMAT =%08lx!\n", lpParms->dwReturn);
425 case MCI_CDA_STATUS_TYPE_TRACK:
426 if (!(dwFlags & MCI_TRACK))
427 return MCIERR_MISSING_PARAMETER;
428 if (lpParms->dwTrack > wmcda->wcda.nTracks || lpParms->dwTrack == 0)
429 return MCIERR_OUTOFRANGE;
430 lpParms->dwReturn = (wmcda->wcda.lpbTrackFlags[lpParms->dwTrack - 1] &
431 CDROM_DATA_TRACK) ? MCI_CDA_TRACK_OTHER : MCI_CDA_TRACK_AUDIO;
432 TRACE(cdaudio, "MCI_CDA_STATUS_TYPE_TRACK[%ld]=%08lx\n", lpParms->dwTrack, lpParms->dwReturn);
435 WARN(cdaudio, "unknown command %08lX !\n", lpParms->dwItem);
436 return MCIERR_UNRECOGNIZED_COMMAND;
440 WARN(cdaudio, "not MCI_STATUS_ITEM !\n");
444 /**************************************************************************
445 * CDAUDIO_mciPlay [internal]
447 static DWORD CDAUDIO_mciPlay(UINT16 wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
450 WINE_MCICDAUDIO* wmcda = CDAUDIO_mciGetOpenDrv(wDevID);
453 TRACE(cdaudio,"(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
455 if (lpParms == NULL) {
456 ret = MCIERR_NULL_PARAMETER_BLOCK;
457 } else if (wmcda == NULL) {
458 ret = MCIERR_INVALID_DEVICE_ID;
460 if (wmcda->wcda.nTracks == 0) {
461 if (!CDAUDIO_GetTracksInfo(&wmcda->wcda)) {
462 WARN(cdaudio, "error reading TracksInfo !\n");
463 return MCIERR_DRIVER_INTERNAL;
466 end = wmcda->wcda.dwTotalLen;
467 wmcda->wcda.nCurTrack = 1;
468 if (dwFlags & MCI_FROM) {
469 start = CDAUDIO_CalcFrame(wmcda, lpParms->dwFrom);
470 TRACE(cdaudio,"MCI_FROM=%08lX -> %u \n", lpParms->dwFrom, start);
472 if (!CDAUDIO_GetCDStatus(&wmcda->wcda)) return MCIERR_DRIVER_INTERNAL;
473 start = wmcda->wcda.dwCurFrame;
475 if (dwFlags & MCI_TO) {
476 end = CDAUDIO_CalcFrame(wmcda, lpParms->dwTo);
477 TRACE(cdaudio, "MCI_TO=%08lX -> %u \n", lpParms->dwTo, end);
479 end += wmcda->wcda.dwFirstOffset;
481 if (CDAUDIO_Play(&wmcda->wcda, start, end) == -1)
482 return MCIERR_HARDWARE;
483 wmcda->mciMode = MCI_MODE_PLAY;
484 if (dwFlags & MCI_NOTIFY) {
485 TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
487 mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback),
488 wmcda->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
495 /**************************************************************************
496 * CDAUDIO_mciStop [internal]
498 static DWORD CDAUDIO_mciStop(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
500 WINE_MCICDAUDIO* wmcda = CDAUDIO_mciGetOpenDrv(wDevID);
502 TRACE(cdaudio,"(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
504 if (wmcda == NULL) return MCIERR_INVALID_DEVICE_ID;
506 if (CDAUDIO_Stop(&wmcda->wcda) == -1)
507 return MCIERR_HARDWARE;
508 wmcda->mciMode = MCI_MODE_STOP;
509 if (lpParms && (dwFlags & MCI_NOTIFY)) {
510 TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
511 mciDriverNotify16((HWND16)LOWORD(lpParms->dwCallback),
512 wmcda->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
517 /**************************************************************************
518 * CDAUDIO_mciPause [internal]
520 static DWORD CDAUDIO_mciPause(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
522 WINE_MCICDAUDIO* wmcda = CDAUDIO_mciGetOpenDrv(wDevID);
524 TRACE(cdaudio,"(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
526 if (wmcda == NULL) return MCIERR_INVALID_DEVICE_ID;
528 if (CDAUDIO_Pause(&wmcda->wcda, 1) == -1)
529 return MCIERR_HARDWARE;
530 wmcda->mciMode = MCI_MODE_PAUSE;
531 if (lpParms && (dwFlags & MCI_NOTIFY)) {
532 TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
533 mciDriverNotify16((HWND16)LOWORD(lpParms->dwCallback),
534 wmcda->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
539 /**************************************************************************
540 * CDAUDIO_mciResume [internal]
542 static DWORD CDAUDIO_mciResume(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
544 WINE_MCICDAUDIO* wmcda = CDAUDIO_mciGetOpenDrv(wDevID);
546 TRACE(cdaudio,"(%04X, %08lX, %p);\n", wDevID, dwFlags, lpParms);
548 if (wmcda == NULL) return MCIERR_INVALID_DEVICE_ID;
550 if (CDAUDIO_Pause(&wmcda->wcda, 0) == -1)
551 return MCIERR_HARDWARE;
552 wmcda->mciMode = MCI_MODE_STOP;
553 if (lpParms && (dwFlags & MCI_NOTIFY)) {
554 TRACE(cdaudio, "MCI_NOTIFY_SUCCESSFUL %08lX !\n", lpParms->dwCallback);
555 mciDriverNotify16((HWND16)LOWORD(lpParms->dwCallback),
556 wmcda->wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
561 /**************************************************************************
562 * CDAUDIO_mciSeek [internal]
564 static DWORD CDAUDIO_mciSeek(UINT16 wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
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");
580 case MCI_SEEK_TO_END:
581 TRACE(cdaudio, "Seeking to end\n");
582 at = wmcda->wcda.dwTotalLen;
585 TRACE(cdaudio, "Seeking to %lu\n", lpParms->dwTo);
589 TRACE(cdaudio, "Seeking to ??=%lu\n", dwFlags);
590 return MCIERR_UNSUPPORTED_FUNCTION;
592 if (CDAUDIO_Seek(&wmcda->wcda, at) == -1) {
593 return MCIERR_HARDWARE;
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_DriverProc [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 /*-----------------------------------------------------------------------*/