2 * Sample MCI CDAUDIO Wine Driver for Linux
4 * Copyright 1994 Martin Ayotte
12 #include <sys/ioctl.h>
21 #include <linux/soundcard.h>
22 #include <linux/cdrom.h>
24 #include <machine/soundcard.h>
28 #define SOUND_DEV "/dev/dsp"
30 #define CDAUDIO_DEV "/dev/rcd0c"
32 #define CDAUDIO_DEV "/dev/cdrom"
36 #define IOCTL(a,b,c) ioctl(a,b,&c)
38 #define IOCTL(a,b,c) (c = ioctl(a,b,c) )
41 #define MAX_CDAUDIODRV (1)
42 #define MAX_CDAUDIO_TRACKS 256
44 #define CDFRAMES_PERSEC 75
45 #define CDFRAMES_PERMIN 4500
46 #define SECONDS_PERMIN 60
48 #if defined(linux) || defined(__FreeBSD__)
50 int nUseCount; /* Incremented for each shared open */
51 BOOL16 fShareable; /* TRUE if first open was shareable */
52 WORD wNotifyDeviceID; /* MCI device ID with a pending notification */
53 HANDLE16 hCallback; /* Callback handle for pending notification */
54 MCI_OPEN_PARMS16 openParms;
58 struct cdrom_subchnl sc;
60 struct cd_sub_channel_info sc;
72 static LINUX_CDAUDIO CDADev[MAX_CDAUDIODRV];
76 /*-----------------------------------------------------------------------*/
79 /**************************************************************************
80 * CDAUDIO_GetNumberOfTracks [internal]
82 static UINT16 CDAUDIO_GetNumberOfTracks(UINT16 wDevID)
84 #if defined(linux) || defined(__FreeBSD__)
86 struct cdrom_tochdr hdr;
88 struct ioc_toc_header hdr;
91 if (CDADev[wDevID].nTracks == 0) {
92 if (ioctl(CDADev[wDevID].unixdev,
99 dprintf_cdaudio(stddeb,
100 "GetNumberOfTracks(%04X) // Error occured !\n",
105 CDADev[wDevID].nTracks = hdr.cdth_trk1;
107 CDADev[wDevID].nTracks = hdr.ending_track - hdr.starting_track + 1;
110 return CDADev[wDevID].nTracks;
117 /**************************************************************************
118 * CDAUDIO_GetTracksInfo [internal]
120 static BOOL32 CDAUDIO_GetTracksInfo(UINT16 wDevID)
122 #if defined(linux) || defined(__FreeBSD__)
124 int start, last_start = 0;
125 int total_length = 0;
127 struct cdrom_tocentry entry;
129 struct ioc_read_toc_entry entry;
130 struct cd_toc_entry toc_buffer;
133 if (CDADev[wDevID].nTracks == 0) {
134 if (CDAUDIO_GetNumberOfTracks(wDevID) == (WORD)-1) return FALSE;
136 dprintf_cdaudio(stddeb,"CDAUDIO_GetTracksInfo // nTracks=%u\n",
137 CDADev[wDevID].nTracks);
138 if (CDADev[wDevID].lpdwTrackLen != NULL)
139 free(CDADev[wDevID].lpdwTrackLen);
140 CDADev[wDevID].lpdwTrackLen = (LPDWORD)malloc(
141 (CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
142 if (CDADev[wDevID].lpdwTrackPos != NULL)
143 free(CDADev[wDevID].lpdwTrackPos);
144 CDADev[wDevID].lpdwTrackPos = (LPDWORD)malloc(
145 (CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
146 if (CDADev[wDevID].lpdwTrackLen == NULL ||
147 CDADev[wDevID].lpdwTrackPos == NULL) {
148 dprintf_cdaudio(stddeb,
149 "CDAUDIO_GetTracksInfo // error allocating track table !\n");
152 memset(CDADev[wDevID].lpdwTrackLen, 0,
153 (CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
154 memset(CDADev[wDevID].lpdwTrackPos, 0,
155 (CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
156 for (i = 0; i <= CDADev[wDevID].nTracks; i++) {
157 if (i == CDADev[wDevID].nTracks)
159 entry.cdte_track = CDROM_LEADOUT;
162 entry.starting_track = LEADOUT; /* XXX */
166 entry.cdte_track = i + 1;
168 entry.starting_track = i + 1;
171 entry.cdte_format = CDROM_MSF;
173 bzero((char *)&toc_buffer, sizeof(toc_buffer));
174 entry.address_format = CD_MSF_FORMAT;
175 entry.data_len = sizeof(toc_buffer);
176 entry.data = &toc_buffer;
178 if (ioctl(CDADev[wDevID].unixdev,
185 dprintf_cdaudio(stddeb,
186 "CDAUDIO_GetTracksInfo // error read entry\n");
190 start = CDFRAMES_PERSEC * (SECONDS_PERMIN *
191 entry.cdte_addr.msf.minute + entry.cdte_addr.msf.second) +
192 entry.cdte_addr.msf.frame;
194 start = CDFRAMES_PERSEC * (SECONDS_PERMIN *
195 toc_buffer.addr.msf.minute + toc_buffer.addr.msf.second) +
196 toc_buffer.addr.msf.frame;
200 CDADev[wDevID].dwFirstOffset = start;
201 dprintf_cdaudio(stddeb,
202 "CDAUDIO_GetTracksInfo // dwFirstOffset=%u\n",
206 length = start - last_start;
208 start = last_start - length;
209 total_length += length;
210 CDADev[wDevID].lpdwTrackLen[i - 1] = length;
211 CDADev[wDevID].lpdwTrackPos[i - 1] = start;
212 dprintf_cdaudio(stddeb,
213 "CDAUDIO_GetTracksInfo // track #%u start=%u len=%u\n",
217 CDADev[wDevID].dwTotalLen = total_length;
218 dprintf_cdaudio(stddeb,"CDAUDIO_GetTracksInfo // total_len=%u\n",
227 /**************************************************************************
228 * CDAUDIO_mciOpen [internal]
230 static DWORD CDAUDIO_mciOpen(UINT16 wDevID, DWORD dwFlags, LPMCI_OPEN_PARMS16 lpParms)
232 #if defined(linux) || defined(__FreeBSD__)
233 dprintf_cdaudio(stddeb,"CDAUDIO_mciOpen(%04X, %08lX, %p);\n",
234 wDevID, dwFlags, lpParms);
235 if (lpParms == NULL) return MCIERR_INTERNAL;
237 if (CDADev[wDevID].nUseCount > 0) {
238 /* The driver already open on this channel */
239 /* If the driver was opened shareable before and this open specifies */
240 /* shareable then increment the use count */
241 if (CDADev[wDevID].fShareable && (dwFlags & MCI_OPEN_SHAREABLE))
242 ++CDADev[wDevID].nUseCount;
244 return MCIERR_MUST_USE_SHAREABLE;
247 CDADev[wDevID].nUseCount = 1;
248 CDADev[wDevID].fShareable = dwFlags & MCI_OPEN_SHAREABLE;
250 if (dwFlags & MCI_OPEN_ELEMENT) {
251 dprintf_cdaudio(stddeb,"CDAUDIO_mciOpen // MCI_OPEN_ELEMENT !\n");
252 /* return MCIERR_NO_ELEMENT_ALLOWED; */
254 memcpy(&CDADev[wDevID].openParms, lpParms, sizeof(MCI_OPEN_PARMS16));
255 CDADev[wDevID].wNotifyDeviceID = lpParms->wDeviceID;
256 CDADev[wDevID].unixdev = open (CDAUDIO_DEV, O_RDONLY, 0);
257 if (CDADev[wDevID].unixdev == -1) {
258 dprintf_cdaudio(stddeb,"CDAUDIO_mciOpen // can't open '%s' !\n", CDAUDIO_DEV);
259 return MCIERR_HARDWARE;
261 CDADev[wDevID].mode = 0;
262 CDADev[wDevID].dwTimeFormat = MCI_FORMAT_TMSF;
263 CDADev[wDevID].nCurTrack = 0;
264 CDADev[wDevID].nTracks = 0;
265 CDADev[wDevID].dwTotalLen = 0;
266 CDADev[wDevID].dwFirstOffset = 0;
267 CDADev[wDevID].lpdwTrackLen = NULL;
268 CDADev[wDevID].lpdwTrackPos = NULL;
269 if (!CDAUDIO_GetTracksInfo(wDevID)) {
270 dprintf_cdaudio(stddeb,"CDAUDIO_mciOpen // error reading TracksInfo !\n");
271 /* return MCIERR_INTERNAL; */
275 Moved to mmsystem.c mciOpen routine
277 if (dwFlags & MCI_NOTIFY) {
278 dprintf_cdaudio(stddeb,
279 "CDAUDIO_mciOpen // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
280 lpParms->dwCallback);
281 mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback),
282 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
287 return MCIERR_HARDWARE;
291 /**************************************************************************
292 * CDAUDIO_mciClose [internal]
294 static DWORD CDAUDIO_mciClose(UINT16 wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
296 #if defined(linux) || defined(__FreeBSD__)
297 dprintf_cdaudio(stddeb,"CDAUDIO_mciClose(%04X, %08lX, %p);\n",
298 wDevID, dwParam, lpParms);
299 if (CDADev[wDevID].lpdwTrackLen != NULL) free(CDADev[wDevID].lpdwTrackLen);
300 if (CDADev[wDevID].lpdwTrackPos != NULL) free(CDADev[wDevID].lpdwTrackPos);
301 close(CDADev[wDevID].unixdev);
306 /**************************************************************************
307 * CDAUDIO_mciGetDevCaps [internal]
309 static DWORD CDAUDIO_mciGetDevCaps(UINT16 wDevID, DWORD dwFlags,
310 LPMCI_GETDEVCAPS_PARMS lpParms)
312 #if defined(linux) || defined(__FreeBSD__)
313 dprintf_cdaudio(stddeb,"CDAUDIO_mciGetDevCaps(%04X, %08lX, %p);\n",
314 wDevID, dwFlags, lpParms);
315 if (lpParms == NULL) return MCIERR_INTERNAL;
316 if (dwFlags & MCI_GETDEVCAPS_ITEM) {
317 dprintf_cdaudio(stddeb,
318 "CDAUDIO_mciGetDevCaps // MCI_GETDEVCAPS_ITEM dwItem=%08lX;\n",
320 switch(lpParms->dwItem) {
321 case MCI_GETDEVCAPS_CAN_RECORD:
322 lpParms->dwReturn = FALSE;
324 case MCI_GETDEVCAPS_HAS_AUDIO:
325 lpParms->dwReturn = TRUE;
327 case MCI_GETDEVCAPS_HAS_VIDEO:
328 lpParms->dwReturn = FALSE;
330 case MCI_GETDEVCAPS_DEVICE_TYPE:
331 lpParms->dwReturn = MCI_DEVTYPE_CD_AUDIO;
333 case MCI_GETDEVCAPS_USES_FILES:
334 lpParms->dwReturn = FALSE;
336 case MCI_GETDEVCAPS_COMPOUND_DEVICE:
337 lpParms->dwReturn = FALSE;
339 case MCI_GETDEVCAPS_CAN_EJECT:
340 lpParms->dwReturn = TRUE;
342 case MCI_GETDEVCAPS_CAN_PLAY:
343 lpParms->dwReturn = TRUE;
345 case MCI_GETDEVCAPS_CAN_SAVE:
346 lpParms->dwReturn = FALSE;
349 return MCIERR_UNRECOGNIZED_COMMAND;
352 dprintf_cdaudio(stddeb,
353 "CDAUDIO_mciGetDevCaps // lpParms->dwReturn=%08lX;\n",
357 return MCIERR_INTERNAL;
361 /**************************************************************************
362 * CDAUDIO_mciInfo [internal]
364 static DWORD CDAUDIO_mciInfo(UINT16 wDevID, DWORD dwFlags, LPMCI_INFO_PARMS16 lpParms)
366 #if defined(linux) || defined(__FreeBSD__)
367 dprintf_cdaudio(stddeb,"CDAUDIO_mciInfo(%04X, %08lX, %p);\n",
368 wDevID, dwFlags, lpParms);
369 if (lpParms == NULL) return MCIERR_INTERNAL;
370 lpParms->lpstrReturn = NULL;
372 case MCI_INFO_PRODUCT:
373 lpParms->lpstrReturn = "Linux CDROM 0.5";
376 return MCIERR_UNRECOGNIZED_COMMAND;
378 if (lpParms->lpstrReturn != NULL)
379 lpParms->dwRetSize = strlen(lpParms->lpstrReturn);
381 lpParms->dwRetSize = 0;
384 return MCIERR_INTERNAL;
389 /**************************************************************************
390 * CDAUDIO_CalcFrame [internal]
392 static DWORD CDAUDIO_CalcFrame(UINT16 wDevID, DWORD dwFormatType, DWORD dwTime)
395 #if defined(linux) || defined(__FreeBSD__)
398 dprintf_cdaudio(stddeb,"CDAUDIO_CalcFrame(%04X, %08lX, %lu);\n",
399 wDevID, dwFormatType, dwTime);
401 switch (dwFormatType) {
402 case MCI_FORMAT_MILLISECONDS:
403 dwFrame = dwTime * CDFRAMES_PERSEC / 1000;
404 dprintf_cdaudio(stddeb,
405 "CDAUDIO_CalcFrame // MILLISECONDS %lu\n",
409 dprintf_cdaudio(stddeb,
410 "CDAUDIO_CalcFrame // MSF %02u:%02u:%02u\n",
411 MCI_MSF_MINUTE(dwTime), MCI_MSF_SECOND(dwTime),
412 MCI_MSF_FRAME(dwTime));
413 dwFrame += CDFRAMES_PERMIN * MCI_MSF_MINUTE(dwTime);
414 dwFrame += CDFRAMES_PERSEC * MCI_MSF_SECOND(dwTime);
415 dwFrame += MCI_MSF_FRAME(dwTime);
418 /* unknown format ! force TMSF ! ... */
419 dwFormatType = MCI_FORMAT_TMSF;
420 case MCI_FORMAT_TMSF:
421 wTrack = MCI_TMSF_TRACK(dwTime);
422 dprintf_cdaudio(stddeb,
423 "CDAUDIO_CalcFrame // TMSF %02u-%02u:%02u:%02u\n",
424 MCI_TMSF_TRACK(dwTime), MCI_TMSF_MINUTE(dwTime),
425 MCI_TMSF_SECOND(dwTime), MCI_TMSF_FRAME(dwTime));
426 dprintf_cdaudio(stddeb,
427 "CDAUDIO_CalcFrame // TMSF trackpos[%u]=%lu\n",
428 wTrack, CDADev[wDevID].lpdwTrackPos[wTrack - 1]);
429 dwFrame = CDADev[wDevID].lpdwTrackPos[wTrack - 1];
430 dwFrame += CDFRAMES_PERMIN * MCI_TMSF_MINUTE(dwTime);
431 dwFrame += CDFRAMES_PERSEC * MCI_TMSF_SECOND(dwTime);
432 dwFrame += MCI_TMSF_FRAME(dwTime);
440 /**************************************************************************
441 * CDAUDIO_GetCDStatus [internal]
443 static BOOL32 CDAUDIO_GetCDStatus(UINT16 wDevID)
445 #if defined(linux) || defined(__FreeBSD__)
446 int oldmode = CDADev[wDevID].mode;
448 struct ioc_read_subchannel read_sc;
450 read_sc.address_format = CD_MSF_FORMAT;
451 read_sc.data_format = CD_CURRENT_POSITION;
453 read_sc.data_len = sizeof(CDADev[wDevID].sc);
454 read_sc.data = (struct cd_sub_channel_info *)&CDADev[wDevID].sc;
456 CDADev[wDevID].sc.cdsc_format = CDROM_MSF;
458 if (ioctl(CDADev[wDevID].unixdev,
460 CDROMSUBCHNL, &CDADev[wDevID].sc
462 CDIOCREADSUBCHANNEL, &read_sc
465 dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // opened or no_media !\n");
466 CDADev[wDevID].mode = MCI_MODE_NOT_READY;
471 CDADev[wDevID].sc.cdsc_audiostatus
473 CDADev[wDevID].sc.header.audio_status
477 case CDROM_AUDIO_INVALID:
479 case CD_AS_AUDIO_INVALID:
481 dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // device doesn't support status, returning NOT_READY.\n");
483 CDADev[wDevID].mode = MCI_MODE_NOT_READY;
485 CDADev[wDevID].mode = MCI_MODE_STOP;
489 case CDROM_AUDIO_NO_STATUS:
491 case CD_AS_NO_STATUS:
493 CDADev[wDevID].mode = MCI_MODE_STOP;
494 dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // MCI_MODE_STOP !\n");
497 case CDROM_AUDIO_PLAY:
499 case CD_AS_PLAY_IN_PROGRESS:
501 CDADev[wDevID].mode = MCI_MODE_PLAY;
502 dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // MCI_MODE_PLAY !\n");
505 case CDROM_AUDIO_PAUSED:
507 case CD_AS_PLAY_PAUSED:
509 CDADev[wDevID].mode = MCI_MODE_PAUSE;
510 dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // MCI_MODE_PAUSE !\n");
513 dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // status=%02X !\n",
515 CDADev[wDevID].sc.cdsc_audiostatus
517 CDADev[wDevID].sc.header.audio_status
522 CDADev[wDevID].nCurTrack = CDADev[wDevID].sc.cdsc_trk;
523 CDADev[wDevID].dwCurFrame =
524 CDFRAMES_PERMIN * CDADev[wDevID].sc.cdsc_absaddr.msf.minute +
525 CDFRAMES_PERSEC * CDADev[wDevID].sc.cdsc_absaddr.msf.second +
526 CDADev[wDevID].sc.cdsc_absaddr.msf.frame;
528 CDADev[wDevID].nCurTrack = CDADev[wDevID].sc.what.position.track_number;
529 CDADev[wDevID].dwCurFrame =
530 CDFRAMES_PERMIN * CDADev[wDevID].sc.what.position.absaddr.msf.minute +
531 CDFRAMES_PERSEC * CDADev[wDevID].sc.what.position.absaddr.msf.second +
532 CDADev[wDevID].sc.what.position.absaddr.msf.frame;
534 dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // %02u-%02u:%02u:%02u \n",
536 CDADev[wDevID].sc.cdsc_trk,
537 CDADev[wDevID].sc.cdsc_absaddr.msf.minute,
538 CDADev[wDevID].sc.cdsc_absaddr.msf.second,
539 CDADev[wDevID].sc.cdsc_absaddr.msf.frame
541 CDADev[wDevID].sc.what.position.track_number,
542 CDADev[wDevID].sc.what.position.absaddr.msf.minute,
543 CDADev[wDevID].sc.what.position.absaddr.msf.second,
544 CDADev[wDevID].sc.what.position.absaddr.msf.frame
547 if (oldmode != CDADev[wDevID].mode && oldmode == MCI_MODE_OPEN) {
548 if (!CDAUDIO_GetTracksInfo(wDevID)) {
549 dprintf_cdaudio(stddeb,"CDAUDIO_GetCDStatus // error updating TracksInfo !\n");
550 return MCIERR_INTERNAL;
560 /**************************************************************************
561 * CDAUDIO_CalcTime [internal]
563 static DWORD CDAUDIO_CalcTime(UINT16 wDevID, DWORD dwFormatType, DWORD dwFrame)
566 #if defined(linux) || defined(__FreeBSD__)
572 dprintf_cdaudio(stddeb,"CDAUDIO_CalcTime(%04X, %08lX, %lu);\n",
573 wDevID, dwFormatType, dwFrame);
575 switch (dwFormatType) {
576 case MCI_FORMAT_MILLISECONDS:
577 dwTime = dwFrame / CDFRAMES_PERSEC * 1000;
578 dprintf_cdaudio(stddeb,
579 "CDAUDIO_CalcTime // MILLISECONDS %lu\n",
583 wMinutes = dwFrame / CDFRAMES_PERMIN;
584 wSeconds = (dwFrame - CDFRAMES_PERMIN * wMinutes) / CDFRAMES_PERSEC;
585 wFrames = dwFrame - CDFRAMES_PERMIN * wMinutes -
586 CDFRAMES_PERSEC * wSeconds;
587 dwTime = MCI_MAKE_MSF(wMinutes, wSeconds, wFrames);
588 dprintf_cdaudio(stddeb,"CDAUDIO_CalcTime // MSF %02u:%02u:%02u -> dwTime=%lu\n",
589 wMinutes, wSeconds, wFrames, dwTime);
592 /* unknown format ! force TMSF ! ... */
593 dwFormatType = MCI_FORMAT_TMSF;
594 case MCI_FORMAT_TMSF:
595 for (wTrack = 0; wTrack < CDADev[wDevID].nTracks; wTrack++) {
596 /* dwTime += CDADev[wDevID].lpdwTrackLen[wTrack - 1];
597 printf("Adding trk#%u curpos=%u \n", dwTime);
598 if (dwTime >= dwFrame) break; */
599 if (CDADev[wDevID].lpdwTrackPos[wTrack - 1] >= dwFrame) break;
601 wMinutes = dwFrame / CDFRAMES_PERMIN;
602 wSeconds = (dwFrame - CDFRAMES_PERMIN * wMinutes) / CDFRAMES_PERSEC;
603 wFrames = dwFrame - CDFRAMES_PERMIN * wMinutes -
604 CDFRAMES_PERSEC * wSeconds;
605 dwTime = MCI_MAKE_TMSF(wTrack, wMinutes, wSeconds, wFrames);
606 dprintf_cdaudio(stddeb,
607 "CDAUDIO_CalcTime // %02u-%02u:%02u:%02u\n",
608 wTrack, wMinutes, wSeconds, wFrames);
616 /**************************************************************************
617 * CDAUDIO_mciStatus [internal]
619 static DWORD CDAUDIO_mciStatus(UINT16 wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
621 #if defined(linux) || defined(__FreeBSD__)
622 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus(%04X, %08lX, %p);\n",
623 wDevID, dwFlags, lpParms);
624 if (lpParms == NULL) return MCIERR_INTERNAL;
625 if (CDADev[wDevID].unixdev == 0) return MMSYSERR_NOTENABLED;
626 if (dwFlags & MCI_NOTIFY) {
627 dprintf_cdaudio(stddeb,
628 "CDAUDIO_mciStatus // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
629 lpParms->dwCallback);
630 mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback),
631 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
633 if (dwFlags & MCI_STATUS_ITEM) {
634 switch(lpParms->dwItem) {
635 case MCI_STATUS_CURRENT_TRACK:
636 if (!CDAUDIO_GetCDStatus(wDevID)) return MCIERR_INTERNAL;
637 lpParms->dwReturn = CDADev[wDevID].nCurTrack;
638 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // CURRENT_TRACK=%lu!\n", lpParms->dwReturn);
640 case MCI_STATUS_LENGTH:
641 if (CDADev[wDevID].nTracks == 0) {
642 if (!CDAUDIO_GetTracksInfo(wDevID)) {
643 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // error reading TracksInfo !\n");
644 return MCIERR_INTERNAL;
647 if (dwFlags & MCI_TRACK) {
648 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_TRACK #%lu LENGTH=??? !\n",
650 if (lpParms->dwTrack > CDADev[wDevID].nTracks)
651 return MCIERR_OUTOFRANGE;
652 lpParms->dwReturn = CDADev[wDevID].lpdwTrackLen[lpParms->dwTrack];
655 lpParms->dwReturn = CDADev[wDevID].dwTotalLen;
656 lpParms->dwReturn = CDAUDIO_CalcTime(wDevID,
657 CDADev[wDevID].dwTimeFormat, lpParms->dwReturn);
658 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // LENGTH=%lu !\n", lpParms->dwReturn);
660 case MCI_STATUS_MODE:
661 if (!CDAUDIO_GetCDStatus(wDevID)) return MCIERR_INTERNAL;
662 lpParms->dwReturn = CDADev[wDevID].mode;
663 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_MODE=%08lX !\n",
666 case MCI_STATUS_MEDIA_PRESENT:
667 lpParms->dwReturn = (CDADev[wDevID].nTracks > 0) ? TRUE : FALSE;
668 if (lpParms->dwReturn == FALSE)
669 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MEDIA_NOT_PRESENT !\n");
671 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_MEDIA_PRESENT !\n");
673 case MCI_STATUS_NUMBER_OF_TRACKS:
674 lpParms->dwReturn = CDAUDIO_GetNumberOfTracks(wDevID);
675 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_NUMBER_OF_TRACKS = %lu !\n",
677 if (lpParms->dwReturn == (WORD)-1) return MCIERR_INTERNAL;
679 case MCI_STATUS_POSITION:
680 if (!CDAUDIO_GetCDStatus(wDevID)) return MCIERR_INTERNAL;
681 lpParms->dwReturn = CDADev[wDevID].dwCurFrame;
682 if (dwFlags & MCI_STATUS_START) {
683 lpParms->dwReturn = CDADev[wDevID].dwFirstOffset;
684 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // get MCI_STATUS_START !\n");
686 if (dwFlags & MCI_TRACK) {
687 if (lpParms->dwTrack > CDADev[wDevID].nTracks)
688 return MCIERR_OUTOFRANGE;
689 lpParms->dwReturn = CDADev[wDevID].lpdwTrackPos[lpParms->dwTrack - 1];
690 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // get MCI_TRACK #%lu !\n", lpParms->dwTrack);
692 lpParms->dwReturn = CDAUDIO_CalcTime(wDevID,
693 CDADev[wDevID].dwTimeFormat, lpParms->dwReturn);
694 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_POSITION=%08lX !\n",
697 case MCI_STATUS_READY:
698 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_READY !\n");
699 lpParms->dwReturn = TRUE;
701 case MCI_STATUS_TIME_FORMAT:
702 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_TIME_FORMAT !\n");
703 lpParms->dwReturn = CDADev[wDevID].dwTimeFormat;
706 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // unknown command %08lX !\n", lpParms->dwItem);
707 return MCIERR_UNRECOGNIZED_COMMAND;
710 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // not MCI_STATUS_ITEM !\n");
713 return MMSYSERR_NOTENABLED;
718 /**************************************************************************
719 * CDAUDIO_mciPlay [internal]
721 static DWORD CDAUDIO_mciPlay(UINT16 wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
723 #if defined(linux) || defined(__FreeBSD__)
726 struct cdrom_msf msf;
728 struct ioc_play_msf msf;
731 dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay(%04X, %08lX, %p);\n",
732 wDevID, dwFlags, lpParms);
733 if (lpParms == NULL) return MCIERR_INTERNAL;
734 if (CDADev[wDevID].unixdev == 0) return MMSYSERR_NOTENABLED;
735 start = 0; end = CDADev[wDevID].dwTotalLen;
736 CDADev[wDevID].nCurTrack = 1;
737 if (dwFlags & MCI_FROM) {
738 start = CDAUDIO_CalcFrame(wDevID,
739 CDADev[wDevID].dwTimeFormat, lpParms->dwFrom);
740 dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay // MCI_FROM=%08lX -> %u \n",
741 lpParms->dwFrom, start);
743 if (dwFlags & MCI_TO) {
744 end = CDAUDIO_CalcFrame(wDevID,
745 CDADev[wDevID].dwTimeFormat, lpParms->dwTo);
746 dprintf_cdaudio(stddeb,
747 "CDAUDIO_mciPlay // MCI_TO=%08lX -> %u \n",
750 start += CDADev[wDevID].dwFirstOffset;
751 end += CDADev[wDevID].dwFirstOffset;
753 msf.cdmsf_min0 = start / CDFRAMES_PERMIN;
754 msf.cdmsf_sec0 = (start % CDFRAMES_PERMIN) / CDFRAMES_PERSEC;
755 msf.cdmsf_frame0 = start % CDFRAMES_PERSEC;
756 msf.cdmsf_min1 = end / CDFRAMES_PERMIN;
757 msf.cdmsf_sec1 = (end % CDFRAMES_PERMIN) / CDFRAMES_PERSEC;
758 msf.cdmsf_frame1 = end % CDFRAMES_PERSEC;
760 msf.start_m = start / CDFRAMES_PERMIN;
761 msf.start_s = (start % CDFRAMES_PERMIN) / CDFRAMES_PERSEC;
762 msf.start_f = start % CDFRAMES_PERSEC;
763 msf.end_m = end / CDFRAMES_PERMIN;
764 msf.end_s = (end % CDFRAMES_PERMIN) / CDFRAMES_PERSEC;
765 msf.end_f = end % CDFRAMES_PERSEC;
767 if (ioctl(CDADev[wDevID].unixdev,
774 dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay // motor doesn't start !\n");
775 return MCIERR_HARDWARE;
777 if (ioctl(CDADev[wDevID].unixdev,
784 dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay // device doesn't play !\n");
785 return MCIERR_HARDWARE;
787 dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay // msf = %d:%d:%d %d:%d:%d\n",
789 msf.cdmsf_min0, msf.cdmsf_sec0, msf.cdmsf_frame0,
790 msf.cdmsf_min1, msf.cdmsf_sec1, msf.cdmsf_frame1
792 msf.start_m, msf.start_s, msf.start_f,
793 msf.end_m, msf.end_s, msf.end_f
796 CDADev[wDevID].mode = MCI_MODE_PLAY;
797 if (dwFlags & MCI_NOTIFY) {
798 dprintf_cdaudio(stddeb,
799 "CDAUDIO_mciPlay // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
800 lpParms->dwCallback);
802 mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback),
803 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
808 return MCIERR_HARDWARE;
812 /**************************************************************************
813 * CDAUDIO_mciStop [internal]
815 static DWORD CDAUDIO_mciStop(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
817 #if defined(linux) || defined(__FreeBSD__)
818 dprintf_cdaudio(stddeb,"CDAUDIO_mciStop(%04X, %08lX, %p);\n",
819 wDevID, dwFlags, lpParms);
820 if (lpParms == NULL) return MCIERR_INTERNAL;
821 if (ioctl(CDADev[wDevID].unixdev,
827 )) return MCIERR_HARDWARE;
828 CDADev[wDevID].mode = MCI_MODE_STOP;
829 if (dwFlags & MCI_NOTIFY) {
830 dprintf_cdaudio(stddeb,
831 "CDAUDIO_mciStop // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
832 lpParms->dwCallback);
833 mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback),
834 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
838 return MCIERR_HARDWARE;
842 /**************************************************************************
843 * CDAUDIO_mciPause [internal]
845 static DWORD CDAUDIO_mciPause(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
847 #if defined(linux) || defined(__FreeBSD__)
848 dprintf_cdaudio(stddeb,"CDAUDIO_mciPause(%04X, %08lX, %p);\n",
849 wDevID, dwFlags, lpParms);
850 if (lpParms == NULL) return MCIERR_INTERNAL;
851 if (ioctl(CDADev[wDevID].unixdev,
857 )) return MCIERR_HARDWARE;
858 CDADev[wDevID].mode = MCI_MODE_PAUSE;
859 if (dwFlags & MCI_NOTIFY) {
860 dprintf_cdaudio(stddeb,
861 "CDAUDIO_mciPause // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
862 lpParms->dwCallback);
863 mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback),
864 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
868 return MCIERR_HARDWARE;
872 /**************************************************************************
873 * CDAUDIO_mciResume [internal]
875 static DWORD CDAUDIO_mciResume(UINT16 wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
877 #if defined(linux) || defined(__FreeBSD__)
878 dprintf_cdaudio(stddeb,"CDAUDIO_mciResume(%04X, %08lX, %p);\n",
879 wDevID, dwFlags, lpParms);
880 if (lpParms == NULL) return MCIERR_INTERNAL;
881 if (ioctl(CDADev[wDevID].unixdev,
887 )) return MCIERR_HARDWARE;
888 CDADev[wDevID].mode = MCI_MODE_STOP;
889 if (dwFlags & MCI_NOTIFY) {
890 dprintf_cdaudio(stddeb,
891 "CDAUDIO_mciResume // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
892 lpParms->dwCallback);
893 mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback),
894 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
898 return MCIERR_HARDWARE;
902 /**************************************************************************
903 * CDAUDIO_mciSeek [internal]
905 static DWORD CDAUDIO_mciSeek(UINT16 wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
907 #if defined(linux) || defined(__FreeBSD__)
909 MCI_PLAY_PARMS PlayParms;
910 dprintf_cdaudio(stddeb,"CDAUDIO_mciSeek(%04X, %08lX, %p);\n",
911 wDevID, dwFlags, lpParms);
912 if (lpParms == NULL) return MCIERR_INTERNAL;
913 if (ioctl(CDADev[wDevID].unixdev,
920 perror("ioctl CDROMRESUME");
921 return MCIERR_HARDWARE;
923 CDADev[wDevID].mode = MCI_MODE_SEEK;
925 case MCI_SEEK_TO_START:
926 PlayParms.dwFrom = 0;
928 case MCI_SEEK_TO_END:
929 PlayParms.dwFrom = CDADev[wDevID].dwTotalLen;
932 PlayParms.dwFrom = lpParms->dwTo;
935 dwRet = CDAUDIO_mciPlay(wDevID, MCI_WAIT | MCI_FROM, &PlayParms);
936 if (dwRet != 0) return dwRet;
937 dwRet = CDAUDIO_mciStop(wDevID, MCI_WAIT, (LPMCI_GENERIC_PARMS)&PlayParms);
938 if (dwFlags & MCI_NOTIFY) {
939 dprintf_cdaudio(stddeb,
940 "CDAUDIO_mciSeek // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
941 lpParms->dwCallback);
942 mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback),
943 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
947 return MCIERR_HARDWARE;
952 /**************************************************************************
953 * CDAUDIO_mciSet [internal]
955 static DWORD CDAUDIO_mciSet(UINT16 wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms)
957 #if defined(linux) || defined(__FreeBSD__)
958 dprintf_cdaudio(stddeb,"CDAUDIO_mciSet(%04X, %08lX, %p);\n",
959 wDevID, dwFlags, lpParms);
960 if (lpParms == NULL) return MCIERR_INTERNAL;
962 printf("CDAUDIO_mciSet // dwTimeFormat=%08lX\n", lpParms->dwTimeFormat);
963 printf("CDAUDIO_mciSet // dwAudio=%08lX\n", lpParms->dwAudio);
965 if (dwFlags & MCI_SET_TIME_FORMAT) {
966 switch (lpParms->dwTimeFormat) {
967 case MCI_FORMAT_MILLISECONDS:
968 dprintf_cdaudio(stddeb,
969 "CDAUDIO_mciSet // MCI_FORMAT_MILLISECONDS !\n");
972 dprintf_cdaudio(stddeb,"CDAUDIO_mciSet // MCI_FORMAT_MSF !\n");
974 case MCI_FORMAT_TMSF:
975 dprintf_cdaudio(stddeb,"CDAUDIO_mciSet // MCI_FORMAT_TMSF !\n");
978 dprintf_cdaudio(stddeb,"CDAUDIO_mciSet // bad time format !\n");
979 return MCIERR_BAD_TIME_FORMAT;
981 CDADev[wDevID].dwTimeFormat = lpParms->dwTimeFormat;
983 if (dwFlags & MCI_SET_DOOR_OPEN) {
984 dprintf_cdaudio(stddeb,
985 "CDAUDIO_mciSet // MCI_SET_DOOR_OPEN !\n");
987 if (ioctl(CDADev[wDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE;
988 if (ioctl(CDADev[wDevID].unixdev, CDIOCEJECT)) return MCIERR_HARDWARE;
989 if (ioctl(CDADev[wDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE;
991 if (ioctl(CDADev[wDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE;
993 CDADev[wDevID].nTracks = 0;
995 if (dwFlags & MCI_SET_DOOR_CLOSED) {
996 dprintf_cdaudio(stddeb,
997 "CDAUDIO_mciSet // MCI_SET_DOOR_CLOSED !\n");
999 if (ioctl(CDADev[wDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE;
1000 if (ioctl(CDADev[wDevID].unixdev, CDIOCCLOSE)) return MCIERR_HARDWARE;
1001 if (ioctl(CDADev[wDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE;
1003 if (ioctl(CDADev[wDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE;
1004 /* XXX should it be ",1" ??? */
1006 CDADev[wDevID].nTracks = 0;
1008 if (dwFlags & MCI_SET_VIDEO) return MCIERR_UNSUPPORTED_FUNCTION;
1009 if (dwFlags & MCI_SET_ON) return MCIERR_UNSUPPORTED_FUNCTION;
1010 if (dwFlags & MCI_SET_OFF) return MCIERR_UNSUPPORTED_FUNCTION;
1011 if (dwFlags & MCI_NOTIFY) {
1012 dprintf_cdaudio(stddeb,
1013 "CDAUDIO_mciSet // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
1014 lpParms->dwCallback);
1015 mciDriverNotify((HWND16)LOWORD(lpParms->dwCallback),
1016 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1020 return MCIERR_HARDWARE;
1025 /**************************************************************************
1026 * CDAUDIO_DriverProc [sample driver]
1028 LONG CDAUDIO_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg,
1029 DWORD dwParam1, DWORD dwParam2)
1031 #if defined(linux) || defined(__FreeBSD__)
1038 case MCI_OPEN_DRIVER:
1040 return CDAUDIO_mciOpen(dwDevID, dwParam1, (LPMCI_OPEN_PARMS16)PTR_SEG_TO_LIN(dwParam2));
1042 case MCI_CLOSE_DRIVER:
1044 return CDAUDIO_mciClose(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
1049 case DRV_QUERYCONFIGURE:
1052 MessageBox16(0, "Sample MultiMedia Linux Driver !",
1053 "MMLinux Driver", MB_OK);
1056 return DRVCNF_RESTART;
1058 return DRVCNF_RESTART;
1059 case MCI_GETDEVCAPS:
1060 return CDAUDIO_mciGetDevCaps(dwDevID, dwParam1,
1061 (LPMCI_GETDEVCAPS_PARMS)PTR_SEG_TO_LIN(dwParam2));
1063 return CDAUDIO_mciInfo(dwDevID, dwParam1,
1064 (LPMCI_INFO_PARMS16)PTR_SEG_TO_LIN(dwParam2));
1066 return CDAUDIO_mciStatus(dwDevID, dwParam1,
1067 (LPMCI_STATUS_PARMS)PTR_SEG_TO_LIN(dwParam2));
1069 return CDAUDIO_mciSet(dwDevID, dwParam1,
1070 (LPMCI_SET_PARMS)PTR_SEG_TO_LIN(dwParam2));
1072 return CDAUDIO_mciPlay(dwDevID, dwParam1,
1073 (LPMCI_PLAY_PARMS)PTR_SEG_TO_LIN(dwParam2));
1075 return CDAUDIO_mciStop(dwDevID, dwParam1,
1076 (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
1078 return CDAUDIO_mciPause(dwDevID, dwParam1,
1079 (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
1081 return CDAUDIO_mciResume(dwDevID, dwParam1,
1082 (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
1084 return CDAUDIO_mciSeek(dwDevID, dwParam1,
1085 (LPMCI_SEEK_PARMS)PTR_SEG_TO_LIN(dwParam2));
1086 case MCI_SET_DOOR_OPEN:
1087 dprintf_cdaudio(stddeb,
1088 "CDAUDIO_DriverProc // MCI_SET_DOOR_OPEN !\n");
1090 if (ioctl(CDADev[dwDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE;
1091 if (ioctl(CDADev[dwDevID].unixdev, CDIOCEJECT)) return MCIERR_HARDWARE;
1092 if (ioctl(CDADev[dwDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE;
1094 if (ioctl(CDADev[dwDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE;
1096 CDADev[dwDevID].nTracks = 0;
1098 case MCI_SET_DOOR_CLOSED:
1099 dprintf_cdaudio(stddeb,"CDAUDIO_DriverProc // MCI_SET_DOOR_CLOSED !\n");
1101 if (ioctl(CDADev[dwDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE;
1102 if (ioctl(CDADev[dwDevID].unixdev, CDIOCCLOSE)) return MCIERR_HARDWARE;
1103 if (ioctl(CDADev[dwDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE;
1105 if (ioctl(CDADev[dwDevID].unixdev, CDROMEJECT, 1)) return MCIERR_HARDWARE;
1107 CDADev[dwDevID].nTracks = 0;
1110 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1113 return MCIERR_HARDWARE;
1118 /*-----------------------------------------------------------------------*/