Release 960516
[wine.git] / multimedia / mcicda.c
blobe517fe633b8a2fd785efce24b489aaf50e264eb2
1 /*
2 * Sample MCI CDAUDIO Wine Driver for Linux
4 * Copyright 1994 Martin Ayotte
5 */
7 #ifndef WINELIB
8 #define BUILTIN_MMSYSTEM
9 #endif
11 #ifdef BUILTIN_MMSYSTEM
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <unistd.h>
16 #include <string.h>
17 #include <fcntl.h>
18 #include <sys/ioctl.h>
19 #include "windows.h"
20 #include "user.h"
21 #include "driver.h"
22 #include "mmsystem.h"
23 #include "stddebug.h"
24 #include "debug.h"
26 #ifdef linux
27 #include <linux/soundcard.h>
28 #include <linux/cdrom.h>
29 #endif
31 #define SOUND_DEV "/dev/dsp"
32 #define CDAUDIO_DEV "/dev/cdrom"
34 #ifdef SOUND_VERSION
35 #define IOCTL(a,b,c) ioctl(a,b,&c)
36 #else
37 #define IOCTL(a,b,c) (c = ioctl(a,b,c) )
38 #endif
40 #define MAX_CDAUDIODRV 2
41 #define MAX_CDAUDIO_TRACKS 256
43 #define CDFRAMES_PERSEC 75
44 #define CDFRAMES_PERMIN 4500
45 #define SECONDS_PERMIN 60
47 #ifdef linux
48 typedef struct {
49 int nUseCount; /* Incremented for each shared open */
50 BOOL fShareable; /* TRUE if first open was shareable */
51 WORD wNotifyDeviceID; /* MCI device ID with a pending notification */
52 HANDLE hCallback; /* Callback handle for pending notification */
53 MCI_OPEN_PARMS openParms;
54 DWORD dwTimeFormat;
55 int unixdev;
56 struct cdrom_subchnl sc;
57 int mode;
58 UINT nCurTrack;
59 DWORD dwCurFrame;
60 UINT nTracks;
61 DWORD dwTotalLen;
62 LPDWORD lpdwTrackLen;
63 LPDWORD lpdwTrackPos;
64 DWORD dwFirstOffset;
65 } LINUX_CDAUDIO;
67 static LINUX_CDAUDIO CDADev[MAX_CDAUDIODRV];
68 #endif
71 /*-----------------------------------------------------------------------*/
74 /**************************************************************************
75 * CDAUDIO_GetNumberOfTracks [internal]
77 static UINT CDAUDIO_GetNumberOfTracks(UINT wDevID)
79 #ifdef linux
80 struct cdrom_tochdr hdr;
81 if (CDADev[wDevID].nTracks == 0) {
82 if (ioctl(CDADev[wDevID].unixdev, CDROMREADTOCHDR, &hdr)) {
83 dprintf_cdaudio(stddeb,
84 "GetNumberOfTracks(%u) // Error occured !\n",
85 wDevID);
86 return (WORD)-1;
88 CDADev[wDevID].nTracks = hdr.cdth_trk1;
90 return CDADev[wDevID].nTracks;
91 #else
92 return (WORD)-1;
93 #endif
97 /**************************************************************************
98 * CDAUDIO_GetTracksInfo [internal]
100 static BOOL CDAUDIO_GetTracksInfo(UINT wDevID)
102 #ifdef linux
103 int i, length;
104 int start, last_start = 0;
105 int total_length = 0;
106 struct cdrom_tocentry entry;
107 if (CDADev[wDevID].nTracks == 0) {
108 if (CDAUDIO_GetNumberOfTracks(wDevID) == (WORD)-1) return FALSE;
110 dprintf_cdaudio(stddeb,"CDAUDIO_GetTracksInfo // nTracks=%u\n",
111 CDADev[wDevID].nTracks);
112 if (CDADev[wDevID].lpdwTrackLen != NULL)
113 free(CDADev[wDevID].lpdwTrackLen);
114 CDADev[wDevID].lpdwTrackLen = (LPDWORD)malloc(
115 (CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
116 if (CDADev[wDevID].lpdwTrackPos != NULL)
117 free(CDADev[wDevID].lpdwTrackPos);
118 CDADev[wDevID].lpdwTrackPos = (LPDWORD)malloc(
119 (CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
120 if (CDADev[wDevID].lpdwTrackLen == NULL ||
121 CDADev[wDevID].lpdwTrackPos == NULL) {
122 dprintf_cdaudio(stddeb,
123 "CDAUDIO_GetTracksInfo // error allocating track table !\n");
124 return FALSE;
126 memset(CDADev[wDevID].lpdwTrackLen, 0,
127 (CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
128 memset(CDADev[wDevID].lpdwTrackPos, 0,
129 (CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
130 for (i = 0; i <= CDADev[wDevID].nTracks; i++) {
131 if (i == CDADev[wDevID].nTracks)
132 entry.cdte_track = CDROM_LEADOUT;
133 else
134 entry.cdte_track = i + 1;
135 entry.cdte_format = CDROM_MSF;
136 if (ioctl(CDADev[wDevID].unixdev, CDROMREADTOCENTRY, &entry)) {
137 dprintf_cdaudio(stddeb,
138 "CDAUDIO_GetTracksInfo // error read entry\n");
139 return FALSE;
141 start = CDFRAMES_PERSEC * (SECONDS_PERMIN *
142 entry.cdte_addr.msf.minute + entry.cdte_addr.msf.second) +
143 entry.cdte_addr.msf.frame;
144 if (i == 0) {
145 last_start = start;
146 CDADev[wDevID].dwFirstOffset = start;
147 dprintf_cdaudio(stddeb,
148 "CDAUDIO_GetTracksInfo // dwFirstOffset=%u\n",
149 start);
151 else {
152 length = start - last_start;
153 last_start = start;
154 start = last_start - length;
155 total_length += length;
156 CDADev[wDevID].lpdwTrackLen[i - 1] = length;
157 CDADev[wDevID].lpdwTrackPos[i - 1] = start;
158 dprintf_cdaudio(stddeb,
159 "CDAUDIO_GetTracksInfo // track #%u start=%u len=%u\n",
160 i, start, length);
163 CDADev[wDevID].dwTotalLen = total_length;
164 dprintf_cdaudio(stddeb,"CDAUDIO_GetTracksInfo // total_len=%u\n",
165 total_length);
166 fflush(stdout);
167 return TRUE;
168 #else
169 return FALSE;
170 #endif
174 /**************************************************************************
175 * CDAUDIO_mciOpen [internal]
177 static DWORD CDAUDIO_mciOpen(UINT wDevID, DWORD dwFlags, LPMCI_OPEN_PARMS lpParms)
179 #ifdef linux
180 dprintf_cdaudio(stddeb,"CDAUDIO_mciOpen(%04X, %08lX, %p);\n",
181 wDevID, dwFlags, lpParms);
182 if (lpParms == NULL) return MCIERR_INTERNAL;
183 wDevID = lpParms->wDeviceID;
184 if (CDADev[wDevID].nUseCount > 0) {
185 /* The driver already open on this channel */
186 /* If the driver was opened shareable before and this open specifies */
187 /* shareable then increment the use count */
188 if (CDADev[wDevID].fShareable && (dwFlags & MCI_OPEN_SHAREABLE))
189 ++CDADev[wDevID].nUseCount;
190 else
191 return MCIERR_MUST_USE_SHAREABLE;
193 else {
194 CDADev[wDevID].nUseCount = 1;
195 CDADev[wDevID].fShareable = dwFlags & MCI_OPEN_SHAREABLE;
197 if (dwFlags & MCI_OPEN_ELEMENT) {
198 dprintf_cdaudio(stddeb,"CDAUDIO_mciOpen // MCI_OPEN_ELEMENT !\n");
199 /* return MCIERR_NO_ELEMENT_ALLOWED; */
201 memcpy(&CDADev[wDevID].openParms, lpParms, sizeof(MCI_OPEN_PARMS));
202 CDADev[wDevID].wNotifyDeviceID = lpParms->wDeviceID;
203 CDADev[wDevID].unixdev = open (CDAUDIO_DEV, O_RDONLY, 0);
204 if (CDADev[wDevID].unixdev == -1) {
205 dprintf_cdaudio(stddeb,"CDAUDIO_mciOpen // can't open '%s' !\n", CDAUDIO_DEV);
206 return MCIERR_HARDWARE;
208 CDADev[wDevID].mode = 0;
209 CDADev[wDevID].dwTimeFormat = MCI_FORMAT_TMSF;
210 CDADev[wDevID].nCurTrack = 0;
211 CDADev[wDevID].nTracks = 0;
212 CDADev[wDevID].dwTotalLen = 0;
213 CDADev[wDevID].dwFirstOffset = 0;
214 CDADev[wDevID].lpdwTrackLen = NULL;
215 CDADev[wDevID].lpdwTrackPos = NULL;
216 if (!CDAUDIO_GetTracksInfo(wDevID)) {
217 dprintf_cdaudio(stddeb,"CDAUDIO_mciOpen // error reading TracksInfo !\n");
218 /* return MCIERR_INTERNAL; */
220 if (dwFlags & MCI_NOTIFY) {
221 dprintf_cdaudio(stddeb,
222 "CDAUDIO_mciOpen // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
223 lpParms->dwCallback);
224 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
225 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
227 return 0;
228 #else
229 return MCIERR_HARDWARE;
230 #endif
233 /**************************************************************************
234 * CDAUDIO_mciClose [internal]
236 static DWORD CDAUDIO_mciClose(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
238 #ifdef linux
239 dprintf_cdaudio(stddeb,"CDAUDIO_mciClose(%u, %08lX, %p);\n",
240 wDevID, dwParam, lpParms);
241 if (CDADev[wDevID].lpdwTrackLen != NULL) free(CDADev[wDevID].lpdwTrackLen);
242 if (CDADev[wDevID].lpdwTrackPos != NULL) free(CDADev[wDevID].lpdwTrackPos);
243 close(CDADev[wDevID].unixdev);
244 #endif
245 return 0;
248 /**************************************************************************
249 * CDAUDIO_mciGetDevCaps [internal]
251 static DWORD CDAUDIO_mciGetDevCaps(UINT wDevID, DWORD dwFlags,
252 LPMCI_GETDEVCAPS_PARMS lpParms)
254 #ifdef linux
255 dprintf_cdaudio(stddeb,"CDAUDIO_mciGetDevCaps(%u, %08lX, %p);\n",
256 wDevID, dwFlags, lpParms);
257 if (lpParms == NULL) return MCIERR_INTERNAL;
258 if (dwFlags & MCI_GETDEVCAPS_ITEM) {
259 dprintf_cdaudio(stddeb,
260 "CDAUDIO_mciGetDevCaps // MCI_GETDEVCAPS_ITEM dwItem=%08lX;\n",
261 lpParms->dwItem);
262 switch(lpParms->dwItem) {
263 case MCI_GETDEVCAPS_CAN_RECORD:
264 lpParms->dwReturn = FALSE;
265 break;
266 case MCI_GETDEVCAPS_HAS_AUDIO:
267 lpParms->dwReturn = TRUE;
268 break;
269 case MCI_GETDEVCAPS_HAS_VIDEO:
270 lpParms->dwReturn = FALSE;
271 break;
272 case MCI_GETDEVCAPS_DEVICE_TYPE:
273 lpParms->dwReturn = MCI_DEVTYPE_CD_AUDIO;
274 break;
275 case MCI_GETDEVCAPS_USES_FILES:
276 lpParms->dwReturn = FALSE;
277 break;
278 case MCI_GETDEVCAPS_COMPOUND_DEVICE:
279 lpParms->dwReturn = FALSE;
280 break;
281 case MCI_GETDEVCAPS_CAN_EJECT:
282 lpParms->dwReturn = TRUE;
283 break;
284 case MCI_GETDEVCAPS_CAN_PLAY:
285 lpParms->dwReturn = TRUE;
286 break;
287 case MCI_GETDEVCAPS_CAN_SAVE:
288 lpParms->dwReturn = FALSE;
289 break;
290 default:
291 return MCIERR_UNRECOGNIZED_COMMAND;
294 dprintf_cdaudio(stddeb,
295 "CDAUDIO_mciGetDevCaps // lpParms->dwReturn=%08lX;\n",
296 lpParms->dwReturn);
297 return 0;
298 #else
299 return MCIERR_INTERNAL;
300 #endif
303 /**************************************************************************
304 * CDAUDIO_mciInfo [internal]
306 static DWORD CDAUDIO_mciInfo(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMS lpParms)
308 #ifdef linux
309 dprintf_cdaudio(stddeb,"CDAUDIO_mciInfo(%u, %08lX, %p);\n",
310 wDevID, dwFlags, lpParms);
311 if (lpParms == NULL) return MCIERR_INTERNAL;
312 lpParms->lpstrReturn = NULL;
313 switch(dwFlags) {
314 case MCI_INFO_PRODUCT:
315 lpParms->lpstrReturn = "Linux CDROM 0.5";
316 break;
317 default:
318 return MCIERR_UNRECOGNIZED_COMMAND;
320 if (lpParms->lpstrReturn != NULL)
321 lpParms->dwRetSize = strlen(lpParms->lpstrReturn);
322 else
323 lpParms->dwRetSize = 0;
324 return 0;
325 #else
326 return MCIERR_INTERNAL;
327 #endif
331 /**************************************************************************
332 * CDAUDIO_CalcFrame [internal]
334 static DWORD CDAUDIO_CalcFrame(UINT wDevID, DWORD dwFormatType, DWORD dwTime)
336 DWORD dwFrame = 0;
337 #ifdef linux
338 UINT wTrack;
340 dprintf_cdaudio(stddeb,"CDAUDIO_CalcFrame(%u, %08lX, %lu);\n",
341 wDevID, dwFormatType, dwTime);
343 switch (dwFormatType) {
344 case MCI_FORMAT_MILLISECONDS:
345 dwFrame = dwTime * CDFRAMES_PERSEC / 1000;
346 dprintf_cdaudio(stddeb,
347 "CDAUDIO_CalcFrame // MILLISECONDS %lu\n",
348 dwFrame);
349 break;
350 case MCI_FORMAT_MSF:
351 dprintf_cdaudio(stddeb,
352 "CDAUDIO_CalcFrame // MSF %02u:%02u:%02u\n",
353 MCI_MSF_MINUTE(dwTime), MCI_MSF_SECOND(dwTime),
354 MCI_MSF_FRAME(dwTime));
355 dwFrame += CDFRAMES_PERMIN * MCI_MSF_MINUTE(dwTime);
356 dwFrame += CDFRAMES_PERSEC * MCI_MSF_SECOND(dwTime);
357 dwFrame += MCI_MSF_FRAME(dwTime);
358 break;
359 default:
360 /* unknown format ! force TMSF ! ... */
361 dwFormatType = MCI_FORMAT_TMSF;
362 case MCI_FORMAT_TMSF:
363 wTrack = MCI_TMSF_TRACK(dwTime);
364 dprintf_cdaudio(stddeb,
365 "CDAUDIO_CalcFrame // TMSF %02u-%02u:%02u:%02u\n",
366 MCI_TMSF_TRACK(dwTime), MCI_TMSF_MINUTE(dwTime),
367 MCI_TMSF_SECOND(dwTime), MCI_TMSF_FRAME(dwTime));
368 dprintf_cdaudio(stddeb,
369 "CDAUDIO_CalcFrame // TMSF trackpos[%u]=%lu\n",
370 wTrack, CDADev[wDevID].lpdwTrackPos[wTrack - 1]);
371 dwFrame = CDADev[wDevID].lpdwTrackPos[wTrack - 1];
372 dwFrame += CDFRAMES_PERMIN * MCI_TMSF_MINUTE(dwTime);
373 dwFrame += CDFRAMES_PERSEC * MCI_TMSF_SECOND(dwTime);
374 dwFrame += MCI_TMSF_FRAME(dwTime);
375 break;
377 #endif
378 return dwFrame;
382 /**************************************************************************
383 * CDAUDIO_GetCDStatus [internal]
385 static BOOL CDAUDIO_GetCDStatus(UINT wDevID)
387 #ifdef linux
388 int oldmode = CDADev[wDevID].mode;
389 CDADev[wDevID].sc.cdsc_format = CDROM_MSF;
390 if (ioctl(CDADev[wDevID].unixdev, CDROMSUBCHNL, &CDADev[wDevID].sc)) {
391 dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // opened or no_media !\n");
392 CDADev[wDevID].mode = MCI_MODE_NOT_READY;
393 return TRUE;
395 switch (CDADev[wDevID].sc.cdsc_audiostatus) {
396 case CDROM_AUDIO_INVALID:
397 dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // device doesn't support status !\n");
398 return FALSE;
399 case CDROM_AUDIO_NO_STATUS:
400 CDADev[wDevID].mode = MCI_MODE_STOP;
401 dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // MCI_MODE_STOP !\n");
402 break;
403 case CDROM_AUDIO_PLAY:
404 CDADev[wDevID].mode = MCI_MODE_PLAY;
405 dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // MCI_MODE_PLAY !\n");
406 break;
407 case CDROM_AUDIO_PAUSED:
408 CDADev[wDevID].mode = MCI_MODE_PAUSE;
409 dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // MCI_MODE_PAUSE !\n");
410 break;
411 default:
412 dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // status=%02X !\n",
413 CDADev[wDevID].sc.cdsc_audiostatus);
415 CDADev[wDevID].nCurTrack = CDADev[wDevID].sc.cdsc_trk;
416 CDADev[wDevID].dwCurFrame =
417 CDFRAMES_PERMIN * CDADev[wDevID].sc.cdsc_absaddr.msf.minute +
418 CDFRAMES_PERSEC * CDADev[wDevID].sc.cdsc_absaddr.msf.second +
419 CDADev[wDevID].sc.cdsc_absaddr.msf.frame;
420 dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // %02u-%02u:%02u:%02u \n",
421 CDADev[wDevID].sc.cdsc_trk,
422 CDADev[wDevID].sc.cdsc_absaddr.msf.minute,
423 CDADev[wDevID].sc.cdsc_absaddr.msf.second,
424 CDADev[wDevID].sc.cdsc_absaddr.msf.frame);
425 if (oldmode != CDADev[wDevID].mode && oldmode == MCI_MODE_OPEN) {
426 if (!CDAUDIO_GetTracksInfo(wDevID)) {
427 dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // error updating TracksInfo !\n");
428 return MCIERR_INTERNAL;
431 return TRUE;
432 #else
433 return FALSE;
434 #endif
438 /**************************************************************************
439 * CDAUDIO_CalcTime [internal]
441 static DWORD CDAUDIO_CalcTime(UINT wDevID, DWORD dwFormatType, DWORD dwFrame)
443 DWORD dwTime = 0;
444 #ifdef linux
445 UINT wTrack;
446 UINT wMinutes;
447 UINT wSeconds;
448 UINT wFrames;
449 dprintf_cdaudio(stddeb,"CDAUDIO_CalcTime(%u, %08lX, %lu);\n",
450 wDevID, dwFormatType, dwFrame);
452 switch (dwFormatType) {
453 case MCI_FORMAT_MILLISECONDS:
454 dwTime = dwFrame / CDFRAMES_PERSEC * 1000;
455 dprintf_cdaudio(stddeb,
456 "CDAUDIO_CalcTime // MILLISECONDS %lu\n",
457 dwTime);
458 break;
459 case MCI_FORMAT_MSF:
460 wMinutes = dwFrame / CDFRAMES_PERMIN;
461 wSeconds = (dwFrame - CDFRAMES_PERMIN * wMinutes) / CDFRAMES_PERSEC;
462 wFrames = dwFrame - CDFRAMES_PERMIN * wMinutes -
463 CDFRAMES_PERSEC * wSeconds;
464 dwTime = MCI_MAKE_MSF(wMinutes, wSeconds, wFrames);
465 dprintf_cdaudio(stddeb,"CDAUDIO_CalcTime // MSF %02u:%02u:%02u -> dwTime=%lu\n",
466 wMinutes, wSeconds, wFrames, dwTime);
467 break;
468 default:
469 /* unknown format ! force TMSF ! ... */
470 dwFormatType = MCI_FORMAT_TMSF;
471 case MCI_FORMAT_TMSF:
472 for (wTrack = 0; wTrack < CDADev[wDevID].nTracks; wTrack++) {
473 /* dwTime += CDADev[wDevID].lpdwTrackLen[wTrack - 1];
474 printf("Adding trk#%u curpos=%u \n", dwTime);
475 if (dwTime >= dwFrame) break; */
476 if (CDADev[wDevID].lpdwTrackPos[wTrack - 1] >= dwFrame) break;
478 wMinutes = dwFrame / CDFRAMES_PERMIN;
479 wSeconds = (dwFrame - CDFRAMES_PERMIN * wMinutes) / CDFRAMES_PERSEC;
480 wFrames = dwFrame - CDFRAMES_PERMIN * wMinutes -
481 CDFRAMES_PERSEC * wSeconds;
482 dwTime = MCI_MAKE_TMSF(wTrack, wMinutes, wSeconds, wFrames);
483 dprintf_cdaudio(stddeb,
484 "CDAUDIO_CalcTime // %02u-%02u:%02u:%02u\n",
485 wTrack, wMinutes, wSeconds, wFrames);
486 break;
488 #endif
489 return dwTime;
493 /**************************************************************************
494 * CDAUDIO_mciStatus [internal]
496 static DWORD CDAUDIO_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
498 #ifdef linux
499 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus(%u, %08lX, %p);\n",
500 wDevID, dwFlags, lpParms);
501 if (lpParms == NULL) return MCIERR_INTERNAL;
502 if (CDADev[wDevID].unixdev == 0) return MMSYSERR_NOTENABLED;
503 if (dwFlags & MCI_NOTIFY) {
504 dprintf_cdaudio(stddeb,
505 "CDAUDIO_mciStatus // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
506 lpParms->dwCallback);
507 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
508 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
510 if (dwFlags & MCI_STATUS_ITEM) {
511 switch(lpParms->dwItem) {
512 case MCI_STATUS_CURRENT_TRACK:
513 if (!CDAUDIO_GetCDStatus(wDevID)) return MCIERR_INTERNAL;
514 lpParms->dwReturn = CDADev[wDevID].nCurTrack;
515 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // CURRENT_TRACK=%lu!\n", lpParms->dwReturn);
516 return 0;
517 case MCI_STATUS_LENGTH:
518 if (CDADev[wDevID].nTracks == 0) {
519 if (!CDAUDIO_GetTracksInfo(wDevID)) {
520 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // error reading TracksInfo !\n");
521 return MCIERR_INTERNAL;
524 if (dwFlags & MCI_TRACK) {
525 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_TRACK #%lu LENGTH=??? !\n",
526 lpParms->dwTrack);
527 if (lpParms->dwTrack > CDADev[wDevID].nTracks)
528 return MCIERR_OUTOFRANGE;
529 lpParms->dwReturn = CDADev[wDevID].lpdwTrackLen[lpParms->dwTrack];
531 else
532 lpParms->dwReturn = CDADev[wDevID].dwTotalLen;
533 lpParms->dwReturn = CDAUDIO_CalcTime(wDevID,
534 CDADev[wDevID].dwTimeFormat, lpParms->dwReturn);
535 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // LENGTH=%lu !\n", lpParms->dwReturn);
536 return 0;
537 case MCI_STATUS_MODE:
538 if (!CDAUDIO_GetCDStatus(wDevID)) return MCIERR_INTERNAL;
539 lpParms->dwReturn = CDADev[wDevID].mode;
540 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_MODE=%08lX !\n",
541 lpParms->dwReturn);
542 return 0;
543 case MCI_STATUS_MEDIA_PRESENT:
544 lpParms->dwReturn = (CDADev[wDevID].nTracks > 0) ? TRUE : FALSE;
545 if (lpParms->dwReturn == FALSE)
546 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MEDIA_NOT_PRESENT !\n");
547 else
548 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_MEDIA_PRESENT !\n");
549 return 0;
550 case MCI_STATUS_NUMBER_OF_TRACKS:
551 lpParms->dwReturn = CDAUDIO_GetNumberOfTracks(wDevID);
552 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_NUMBER_OF_TRACKS = %lu !\n",
553 lpParms->dwReturn);
554 if (lpParms->dwReturn == (WORD)-1) return MCIERR_INTERNAL;
555 return 0;
556 case MCI_STATUS_POSITION:
557 if (!CDAUDIO_GetCDStatus(wDevID)) return MCIERR_INTERNAL;
558 lpParms->dwReturn = CDADev[wDevID].dwCurFrame;
559 if (dwFlags & MCI_STATUS_START) {
560 lpParms->dwReturn = CDADev[wDevID].dwFirstOffset;
561 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // get MCI_STATUS_START !\n");
563 if (dwFlags & MCI_TRACK) {
564 if (lpParms->dwTrack > CDADev[wDevID].nTracks)
565 return MCIERR_OUTOFRANGE;
566 lpParms->dwReturn = CDADev[wDevID].lpdwTrackPos[lpParms->dwTrack - 1];
567 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // get MCI_TRACK #%lu !\n", lpParms->dwTrack);
569 lpParms->dwReturn = CDAUDIO_CalcTime(wDevID,
570 CDADev[wDevID].dwTimeFormat, lpParms->dwReturn);
571 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_POSITION=%08lX !\n",
572 lpParms->dwReturn);
573 return 0;
574 case MCI_STATUS_READY:
575 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_READY !\n");
576 lpParms->dwReturn = TRUE;
577 return 0;
578 case MCI_STATUS_TIME_FORMAT:
579 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_TIME_FORMAT !\n");
580 lpParms->dwReturn = CDADev[wDevID].dwTimeFormat;
581 return 0;
582 default:
583 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // unknown command %08lX !\n", lpParms->dwItem);
584 return MCIERR_UNRECOGNIZED_COMMAND;
587 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // not MCI_STATUS_ITEM !\n");
588 return 0;
589 #else
590 return MMSYSERR_NOTENABLED;
591 #endif
595 /**************************************************************************
596 * CDAUDIO_mciPlay [internal]
598 static DWORD CDAUDIO_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
600 #ifdef linux
601 int start, end;
602 struct cdrom_msf msf;
603 dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay(%u, %08lX, %p);\n",
604 wDevID, dwFlags, lpParms);
605 if (lpParms == NULL) return MCIERR_INTERNAL;
606 if (CDADev[wDevID].unixdev == 0) return MMSYSERR_NOTENABLED;
607 start = 0; end = CDADev[wDevID].dwTotalLen;
608 CDADev[wDevID].nCurTrack = 1;
609 if (dwFlags & MCI_FROM) {
610 start = CDAUDIO_CalcFrame(wDevID,
611 CDADev[wDevID].dwTimeFormat, lpParms->dwFrom);
612 dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay // MCI_FROM=%08lX -> %u \n",
613 lpParms->dwFrom, start);
615 if (dwFlags & MCI_TO) {
616 end = CDAUDIO_CalcFrame(wDevID,
617 CDADev[wDevID].dwTimeFormat, lpParms->dwTo);
618 dprintf_cdaudio(stddeb,
619 "CDAUDIO_mciPlay // MCI_TO=%08lX -> %u \n",
620 lpParms->dwTo, end);
622 start += CDADev[wDevID].dwFirstOffset;
623 end += CDADev[wDevID].dwFirstOffset;
624 msf.cdmsf_min0 = start / CDFRAMES_PERMIN;
625 msf.cdmsf_sec0 = (start % CDFRAMES_PERMIN) / CDFRAMES_PERSEC;
626 msf.cdmsf_frame0 = start % CDFRAMES_PERSEC;
627 msf.cdmsf_min1 = end / CDFRAMES_PERMIN;
628 msf.cdmsf_sec1 = (end % CDFRAMES_PERMIN) / CDFRAMES_PERSEC;
629 msf.cdmsf_frame1 = end % CDFRAMES_PERSEC;
630 if (ioctl(CDADev[wDevID].unixdev, CDROMSTART)) {
631 dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay // motor doesn't start !\n");
632 return MCIERR_HARDWARE;
634 if (ioctl(CDADev[wDevID].unixdev, CDROMPLAYMSF, &msf)) {
635 dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay // device doesn't play !\n");
636 return MCIERR_HARDWARE;
638 dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay // msf = %d:%d:%d %d:%d:%d\n",
639 msf.cdmsf_min0, msf.cdmsf_sec0, msf.cdmsf_frame0,
640 msf.cdmsf_min1, msf.cdmsf_sec1, msf.cdmsf_frame1);
641 CDADev[wDevID].mode = MCI_MODE_PLAY;
642 if (dwFlags & MCI_NOTIFY) {
643 dprintf_cdaudio(stddeb,
644 "CDAUDIO_mciPlay // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
645 lpParms->dwCallback);
647 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
648 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
651 return 0;
652 #else
653 return MCIERR_HARDWARE;
654 #endif
657 /**************************************************************************
658 * CDAUDIO_mciStop [internal]
660 static DWORD CDAUDIO_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
662 #ifdef linux
663 dprintf_cdaudio(stddeb,"CDAUDIO_mciStop(%u, %08lX, %p);\n",
664 wDevID, dwFlags, lpParms);
665 if (lpParms == NULL) return MCIERR_INTERNAL;
666 if (ioctl(CDADev[wDevID].unixdev, CDROMSTOP)) return MCIERR_HARDWARE;
667 CDADev[wDevID].mode = MCI_MODE_STOP;
668 if (dwFlags & MCI_NOTIFY) {
669 dprintf_cdaudio(stddeb,
670 "CDAUDIO_mciStop // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
671 lpParms->dwCallback);
672 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
673 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
675 return 0;
676 #else
677 return MCIERR_HARDWARE;
678 #endif
681 /**************************************************************************
682 * CDAUDIO_mciPause [internal]
684 static DWORD CDAUDIO_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
686 #ifdef linux
687 dprintf_cdaudio(stddeb,"CDAUDIO_mciPause(%u, %08lX, %p);\n",
688 wDevID, dwFlags, lpParms);
689 if (lpParms == NULL) return MCIERR_INTERNAL;
690 if (ioctl(CDADev[wDevID].unixdev, CDROMPAUSE)) return MCIERR_HARDWARE;
691 CDADev[wDevID].mode = MCI_MODE_PAUSE;
692 if (dwFlags & MCI_NOTIFY) {
693 dprintf_cdaudio(stddeb,
694 "CDAUDIO_mciPause // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
695 lpParms->dwCallback);
696 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
697 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
699 return 0;
700 #else
701 return MCIERR_HARDWARE;
702 #endif
705 /**************************************************************************
706 * CDAUDIO_mciResume [internal]
708 static DWORD CDAUDIO_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
710 #ifdef linux
711 dprintf_cdaudio(stddeb,"CDAUDIO_mciResume(%u, %08lX, %p);\n",
712 wDevID, dwFlags, lpParms);
713 if (lpParms == NULL) return MCIERR_INTERNAL;
714 if (ioctl(CDADev[wDevID].unixdev, CDROMRESUME)) return MCIERR_HARDWARE;
715 CDADev[wDevID].mode = MCI_MODE_STOP;
716 if (dwFlags & MCI_NOTIFY) {
717 dprintf_cdaudio(stddeb,
718 "CDAUDIO_mciResume // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
719 lpParms->dwCallback);
720 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
721 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
723 return 0;
724 #else
725 return MCIERR_HARDWARE;
726 #endif
729 /**************************************************************************
730 * CDAUDIO_mciSeek [internal]
732 static DWORD CDAUDIO_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
734 #ifdef linux
735 DWORD dwRet;
736 MCI_PLAY_PARMS PlayParms;
737 dprintf_cdaudio(stddeb,"CDAUDIO_mciSeek(%u, %08lX, %p);\n",
738 wDevID, dwFlags, lpParms);
739 if (lpParms == NULL) return MCIERR_INTERNAL;
740 if (ioctl(CDADev[wDevID].unixdev, CDROMRESUME)) return MCIERR_HARDWARE;
741 CDADev[wDevID].mode = MCI_MODE_SEEK;
742 switch(dwFlags) {
743 case MCI_SEEK_TO_START:
744 PlayParms.dwFrom = 0;
745 break;
746 case MCI_SEEK_TO_END:
747 PlayParms.dwFrom = CDADev[wDevID].dwTotalLen;
748 break;
749 case MCI_TO:
750 PlayParms.dwFrom = lpParms->dwTo;
751 break;
753 dwRet = CDAUDIO_mciPlay(wDevID, MCI_WAIT | MCI_FROM, &PlayParms);
754 if (dwRet != 0) return dwRet;
755 dwRet = CDAUDIO_mciStop(wDevID, MCI_WAIT, (LPMCI_GENERIC_PARMS)&PlayParms);
756 if (dwFlags & MCI_NOTIFY) {
757 dprintf_cdaudio(stddeb,
758 "CDAUDIO_mciSeek // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
759 lpParms->dwCallback);
760 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
761 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
763 return dwRet;
764 #else
765 return MCIERR_HARDWARE;
766 #endif
770 /**************************************************************************
771 * CDAUDIO_mciSet [internal]
773 static DWORD CDAUDIO_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms)
775 #ifdef linux
776 dprintf_cdaudio(stddeb,"CDAUDIO_mciSet(%u, %08lX, %p);\n",
777 wDevID, dwFlags, lpParms);
778 if (lpParms == NULL) return MCIERR_INTERNAL;
780 printf("CDAUDIO_mciSet // dwTimeFormat=%08lX\n", lpParms->dwTimeFormat);
781 printf("CDAUDIO_mciSet // dwAudio=%08lX\n", lpParms->dwAudio);
783 if (dwFlags & MCI_SET_TIME_FORMAT) {
784 switch (lpParms->dwTimeFormat) {
785 case MCI_FORMAT_MILLISECONDS:
786 dprintf_cdaudio(stddeb,
787 "CDAUDIO_mciSet // MCI_FORMAT_MILLISECONDS !\n");
788 break;
789 case MCI_FORMAT_MSF:
790 dprintf_cdaudio(stddeb,"CDAUDIO_mciSet // MCI_FORMAT_MSF !\n");
791 break;
792 case MCI_FORMAT_TMSF:
793 dprintf_cdaudio(stddeb,"CDAUDIO_mciSet // MCI_FORMAT_TMSF !\n");
794 break;
795 default:
796 dprintf_cdaudio(stddeb,"CDAUDIO_mciSet // bad time format !\n");
797 return MCIERR_BAD_TIME_FORMAT;
799 CDADev[wDevID].dwTimeFormat = lpParms->dwTimeFormat;
801 if (dwFlags & MCI_SET_DOOR_OPEN) {
802 dprintf_cdaudio(stddeb,
803 "CDAUDIO_mciSet // MCI_SET_DOOR_OPEN !\n");
804 if (ioctl(CDADev[wDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE;
805 CDADev[wDevID].nTracks = 0;
807 if (dwFlags & MCI_SET_DOOR_CLOSED) {
808 dprintf_cdaudio(stddeb,
809 "CDAUDIO_mciSet // MCI_SET_DOOR_CLOSED !\n");
810 if (ioctl(CDADev[wDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE;
811 CDADev[wDevID].nTracks = 0;
813 if (dwFlags & MCI_SET_VIDEO) return MCIERR_UNSUPPORTED_FUNCTION;
814 if (dwFlags & MCI_SET_ON) return MCIERR_UNSUPPORTED_FUNCTION;
815 if (dwFlags & MCI_SET_OFF) return MCIERR_UNSUPPORTED_FUNCTION;
816 if (dwFlags & MCI_NOTIFY) {
817 dprintf_cdaudio(stddeb,
818 "CDAUDIO_mciSet // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
819 lpParms->dwCallback);
820 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
821 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
823 return 0;
824 #else
825 return MCIERR_HARDWARE;
826 #endif
830 /**************************************************************************
831 * CDAUDIO_DriverProc [sample driver]
833 LONG CDAUDIO_DriverProc(DWORD dwDevID, HDRVR hDriv, WORD wMsg,
834 DWORD dwParam1, DWORD dwParam2)
836 #ifdef linux
837 switch(wMsg) {
838 case DRV_LOAD:
839 return 1;
840 case DRV_FREE:
841 return 1;
842 case DRV_OPEN:
843 case MCI_OPEN_DRIVER:
844 case MCI_OPEN:
845 return CDAUDIO_mciOpen(dwDevID, dwParam1, (LPMCI_OPEN_PARMS)PTR_SEG_TO_LIN(dwParam2));
846 case DRV_CLOSE:
847 case MCI_CLOSE_DRIVER:
848 case MCI_CLOSE:
849 return CDAUDIO_mciClose(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
850 case DRV_ENABLE:
851 return 1;
852 case DRV_DISABLE:
853 return 1;
854 case DRV_QUERYCONFIGURE:
855 return 1;
856 case DRV_CONFIGURE:
857 MessageBox((HWND)NULL, "Sample MultiMedia Linux Driver !",
858 "MMLinux Driver", MB_OK);
859 return 1;
860 case DRV_INSTALL:
861 return DRVCNF_RESTART;
862 case DRV_REMOVE:
863 return DRVCNF_RESTART;
864 case MCI_GETDEVCAPS:
865 return CDAUDIO_mciGetDevCaps(dwDevID, dwParam1,
866 (LPMCI_GETDEVCAPS_PARMS)PTR_SEG_TO_LIN(dwParam2));
867 case MCI_INFO:
868 return CDAUDIO_mciInfo(dwDevID, dwParam1,
869 (LPMCI_INFO_PARMS)PTR_SEG_TO_LIN(dwParam2));
870 case MCI_STATUS:
871 return CDAUDIO_mciStatus(dwDevID, dwParam1,
872 (LPMCI_STATUS_PARMS)PTR_SEG_TO_LIN(dwParam2));
873 case MCI_SET:
874 return CDAUDIO_mciSet(dwDevID, dwParam1,
875 (LPMCI_SET_PARMS)PTR_SEG_TO_LIN(dwParam2));
876 case MCI_PLAY:
877 return CDAUDIO_mciPlay(dwDevID, dwParam1,
878 (LPMCI_PLAY_PARMS)PTR_SEG_TO_LIN(dwParam2));
879 case MCI_STOP:
880 return CDAUDIO_mciStop(dwDevID, dwParam1,
881 (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
882 case MCI_PAUSE:
883 return CDAUDIO_mciPause(dwDevID, dwParam1,
884 (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
885 case MCI_RESUME:
886 return CDAUDIO_mciResume(dwDevID, dwParam1,
887 (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
888 case MCI_SEEK:
889 return CDAUDIO_mciSeek(dwDevID, dwParam1,
890 (LPMCI_SEEK_PARMS)PTR_SEG_TO_LIN(dwParam2));
891 case MCI_SET_DOOR_OPEN:
892 dprintf_cdaudio(stddeb,
893 "CDAUDIO_DriverProc // MCI_SET_DOOR_OPEN !\n");
894 if (ioctl(CDADev[dwDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE;
895 CDADev[dwDevID].nTracks = 0;
896 return 0;
897 case MCI_SET_DOOR_CLOSED:
898 dprintf_cdaudio(stddeb,"CDAUDIO_DriverProc // MCI_SET_DOOR_CLOSED !\n");
899 if (ioctl(CDADev[dwDevID].unixdev, CDROMEJECT, 1)) return MCIERR_HARDWARE;
900 CDADev[dwDevID].nTracks = 0;
901 return 0;
902 default:
903 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
905 #else
906 return MCIERR_HARDWARE;
907 #endif
911 /*-----------------------------------------------------------------------*/
913 #endif /* #ifdef BUILTIN_MMSYSTEM */