2 * Sample MCI CDAUDIO Wine Driver for Linux
4 * Copyright 1994 Martin Ayotte
8 #define BUILTIN_MMSYSTEM
11 #ifdef BUILTIN_MMSYSTEM
18 #include <sys/ioctl.h>
27 #include <linux/soundcard.h>
28 #include <linux/cdrom.h>
30 #include <machine/soundcard.h>
34 #define SOUND_DEV "/dev/dsp"
36 #define CDAUDIO_DEV "/dev/rcd0c"
38 #define CDAUDIO_DEV "/dev/cdrom"
42 #define IOCTL(a,b,c) ioctl(a,b,&c)
44 #define IOCTL(a,b,c) (c = ioctl(a,b,c) )
47 #define MAX_CDAUDIODRV 2
48 #define MAX_CDAUDIO_TRACKS 256
50 #define CDFRAMES_PERSEC 75
51 #define CDFRAMES_PERMIN 4500
52 #define SECONDS_PERMIN 60
54 #if defined(linux) || defined(__FreeBSD__)
56 int nUseCount; /* Incremented for each shared open */
57 BOOL fShareable; /* TRUE if first open was shareable */
58 WORD wNotifyDeviceID; /* MCI device ID with a pending notification */
59 HANDLE16 hCallback; /* Callback handle for pending notification */
60 MCI_OPEN_PARMS openParms;
64 struct cdrom_subchnl sc;
66 struct cd_sub_channel_info sc;
78 static LINUX_CDAUDIO CDADev[MAX_CDAUDIODRV];
82 /*-----------------------------------------------------------------------*/
85 /**************************************************************************
86 * CDAUDIO_GetNumberOfTracks [internal]
88 static UINT CDAUDIO_GetNumberOfTracks(UINT wDevID)
90 #if defined(linux) || defined(__FreeBSD__)
92 struct cdrom_tochdr hdr;
94 struct ioc_toc_header hdr;
96 if (CDADev[wDevID].nTracks == 0) {
97 if (ioctl(CDADev[wDevID].unixdev,
104 dprintf_cdaudio(stddeb,
105 "GetNumberOfTracks(%u) // Error occured !\n",
110 CDADev[wDevID].nTracks = hdr.cdth_trk1;
112 CDADev[wDevID].nTracks = hdr.ending_track - hdr.starting_track + 1;
115 return CDADev[wDevID].nTracks;
122 /**************************************************************************
123 * CDAUDIO_GetTracksInfo [internal]
125 static BOOL CDAUDIO_GetTracksInfo(UINT wDevID)
127 #if defined(linux) || defined(__FreeBSD__)
129 int start, last_start = 0;
130 int total_length = 0;
132 struct cdrom_tocentry entry;
134 struct ioc_read_toc_entry entry;
135 struct cd_toc_entry toc_buffer;
137 if (CDADev[wDevID].nTracks == 0) {
138 if (CDAUDIO_GetNumberOfTracks(wDevID) == (WORD)-1) return FALSE;
140 dprintf_cdaudio(stddeb,"CDAUDIO_GetTracksInfo // nTracks=%u\n",
141 CDADev[wDevID].nTracks);
142 if (CDADev[wDevID].lpdwTrackLen != NULL)
143 free(CDADev[wDevID].lpdwTrackLen);
144 CDADev[wDevID].lpdwTrackLen = (LPDWORD)malloc(
145 (CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
146 if (CDADev[wDevID].lpdwTrackPos != NULL)
147 free(CDADev[wDevID].lpdwTrackPos);
148 CDADev[wDevID].lpdwTrackPos = (LPDWORD)malloc(
149 (CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
150 if (CDADev[wDevID].lpdwTrackLen == NULL ||
151 CDADev[wDevID].lpdwTrackPos == NULL) {
152 dprintf_cdaudio(stddeb,
153 "CDAUDIO_GetTracksInfo // error allocating track table !\n");
156 memset(CDADev[wDevID].lpdwTrackLen, 0,
157 (CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
158 memset(CDADev[wDevID].lpdwTrackPos, 0,
159 (CDADev[wDevID].nTracks + 1) * sizeof(DWORD));
160 for (i = 0; i <= CDADev[wDevID].nTracks; i++) {
161 if (i == CDADev[wDevID].nTracks)
163 entry.cdte_track = CDROM_LEADOUT;
166 entry.starting_track = LEADOUT; /* XXX */
170 entry.cdte_track = i + 1;
172 entry.starting_track = i + 1;
175 entry.cdte_format = CDROM_MSF;
177 bzero((char *)&toc_buffer, sizeof(toc_buffer));
178 entry.address_format = CD_MSF_FORMAT;
179 entry.data_len = sizeof(toc_buffer);
180 entry.data = &toc_buffer;
182 if (ioctl(CDADev[wDevID].unixdev,
189 dprintf_cdaudio(stddeb,
190 "CDAUDIO_GetTracksInfo // error read entry\n");
194 start = CDFRAMES_PERSEC * (SECONDS_PERMIN *
195 entry.cdte_addr.msf.minute + entry.cdte_addr.msf.second) +
196 entry.cdte_addr.msf.frame;
198 start = CDFRAMES_PERSEC * (SECONDS_PERMIN *
199 toc_buffer.addr.msf.minute + toc_buffer.addr.msf.second) +
200 toc_buffer.addr.msf.frame;
204 CDADev[wDevID].dwFirstOffset = start;
205 dprintf_cdaudio(stddeb,
206 "CDAUDIO_GetTracksInfo // dwFirstOffset=%u\n",
210 length = start - last_start;
212 start = last_start - length;
213 total_length += length;
214 CDADev[wDevID].lpdwTrackLen[i - 1] = length;
215 CDADev[wDevID].lpdwTrackPos[i - 1] = start;
216 dprintf_cdaudio(stddeb,
217 "CDAUDIO_GetTracksInfo // track #%u start=%u len=%u\n",
221 CDADev[wDevID].dwTotalLen = total_length;
222 dprintf_cdaudio(stddeb,"CDAUDIO_GetTracksInfo // total_len=%u\n",
232 /**************************************************************************
233 * CDAUDIO_mciOpen [internal]
235 static DWORD CDAUDIO_mciOpen(UINT wDevID, DWORD dwFlags, LPMCI_OPEN_PARMS lpParms)
237 #if defined(linux) || defined(__FreeBSD__)
238 dprintf_cdaudio(stddeb,"CDAUDIO_mciOpen(%04X, %08lX, %p);\n",
239 wDevID, dwFlags, lpParms);
240 if (lpParms == NULL) return MCIERR_INTERNAL;
241 wDevID = lpParms->wDeviceID;
242 if (CDADev[wDevID].nUseCount > 0) {
243 /* The driver already open on this channel */
244 /* If the driver was opened shareable before and this open specifies */
245 /* shareable then increment the use count */
246 if (CDADev[wDevID].fShareable && (dwFlags & MCI_OPEN_SHAREABLE))
247 ++CDADev[wDevID].nUseCount;
249 return MCIERR_MUST_USE_SHAREABLE;
252 CDADev[wDevID].nUseCount = 1;
253 CDADev[wDevID].fShareable = dwFlags & MCI_OPEN_SHAREABLE;
255 if (dwFlags & MCI_OPEN_ELEMENT) {
256 dprintf_cdaudio(stddeb,"CDAUDIO_mciOpen // MCI_OPEN_ELEMENT !\n");
257 /* return MCIERR_NO_ELEMENT_ALLOWED; */
259 memcpy(&CDADev[wDevID].openParms, lpParms, sizeof(MCI_OPEN_PARMS));
260 CDADev[wDevID].wNotifyDeviceID = lpParms->wDeviceID;
261 CDADev[wDevID].unixdev = open (CDAUDIO_DEV, O_RDONLY, 0);
262 if (CDADev[wDevID].unixdev == -1) {
263 dprintf_cdaudio(stddeb,"CDAUDIO_mciOpen // can't open '%s' !\n", CDAUDIO_DEV);
264 return MCIERR_HARDWARE;
266 CDADev[wDevID].mode = 0;
267 CDADev[wDevID].dwTimeFormat = MCI_FORMAT_TMSF;
268 CDADev[wDevID].nCurTrack = 0;
269 CDADev[wDevID].nTracks = 0;
270 CDADev[wDevID].dwTotalLen = 0;
271 CDADev[wDevID].dwFirstOffset = 0;
272 CDADev[wDevID].lpdwTrackLen = NULL;
273 CDADev[wDevID].lpdwTrackPos = NULL;
274 if (!CDAUDIO_GetTracksInfo(wDevID)) {
275 dprintf_cdaudio(stddeb,"CDAUDIO_mciOpen // error reading TracksInfo !\n");
276 /* return MCIERR_INTERNAL; */
278 if (dwFlags & MCI_NOTIFY) {
279 dprintf_cdaudio(stddeb,
280 "CDAUDIO_mciOpen // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
281 lpParms->dwCallback);
282 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
283 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
287 return MCIERR_HARDWARE;
291 /**************************************************************************
292 * CDAUDIO_mciClose [internal]
294 static DWORD CDAUDIO_mciClose(UINT wDevID, DWORD dwParam, LPMCI_GENERIC_PARMS lpParms)
296 #if defined(linux) || defined(__FreeBSD__)
297 dprintf_cdaudio(stddeb,"CDAUDIO_mciClose(%u, %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(UINT wDevID, DWORD dwFlags,
310 LPMCI_GETDEVCAPS_PARMS lpParms)
312 #if defined(linux) || defined(__FreeBSD__)
313 dprintf_cdaudio(stddeb,"CDAUDIO_mciGetDevCaps(%u, %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(UINT wDevID, DWORD dwFlags, LPMCI_INFO_PARMS lpParms)
366 #if defined(linux) || defined(__FreeBSD__)
367 dprintf_cdaudio(stddeb,"CDAUDIO_mciInfo(%u, %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(UINT wDevID, DWORD dwFormatType, DWORD dwTime)
395 #if defined(linux) || defined(__FreeBSD__)
398 dprintf_cdaudio(stddeb,"CDAUDIO_CalcFrame(%u, %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 BOOL CDAUDIO_GetCDStatus(UINT 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(UINT wDevID, DWORD dwFormatType, DWORD dwFrame)
566 #if defined(linux) || defined(__FreeBSD__)
571 dprintf_cdaudio(stddeb,"CDAUDIO_CalcTime(%u, %08lX, %lu);\n",
572 wDevID, dwFormatType, dwFrame);
574 switch (dwFormatType) {
575 case MCI_FORMAT_MILLISECONDS:
576 dwTime = dwFrame / CDFRAMES_PERSEC * 1000;
577 dprintf_cdaudio(stddeb,
578 "CDAUDIO_CalcTime // MILLISECONDS %lu\n",
582 wMinutes = dwFrame / CDFRAMES_PERMIN;
583 wSeconds = (dwFrame - CDFRAMES_PERMIN * wMinutes) / CDFRAMES_PERSEC;
584 wFrames = dwFrame - CDFRAMES_PERMIN * wMinutes -
585 CDFRAMES_PERSEC * wSeconds;
586 dwTime = MCI_MAKE_MSF(wMinutes, wSeconds, wFrames);
587 dprintf_cdaudio(stddeb,"CDAUDIO_CalcTime // MSF %02u:%02u:%02u -> dwTime=%lu\n",
588 wMinutes, wSeconds, wFrames, dwTime);
591 /* unknown format ! force TMSF ! ... */
592 dwFormatType = MCI_FORMAT_TMSF;
593 case MCI_FORMAT_TMSF:
594 for (wTrack = 0; wTrack < CDADev[wDevID].nTracks; wTrack++) {
595 /* dwTime += CDADev[wDevID].lpdwTrackLen[wTrack - 1];
596 printf("Adding trk#%u curpos=%u \n", dwTime);
597 if (dwTime >= dwFrame) break; */
598 if (CDADev[wDevID].lpdwTrackPos[wTrack - 1] >= dwFrame) break;
600 wMinutes = dwFrame / CDFRAMES_PERMIN;
601 wSeconds = (dwFrame - CDFRAMES_PERMIN * wMinutes) / CDFRAMES_PERSEC;
602 wFrames = dwFrame - CDFRAMES_PERMIN * wMinutes -
603 CDFRAMES_PERSEC * wSeconds;
604 dwTime = MCI_MAKE_TMSF(wTrack, wMinutes, wSeconds, wFrames);
605 dprintf_cdaudio(stddeb,
606 "CDAUDIO_CalcTime // %02u-%02u:%02u:%02u\n",
607 wTrack, wMinutes, wSeconds, wFrames);
615 /**************************************************************************
616 * CDAUDIO_mciStatus [internal]
618 static DWORD CDAUDIO_mciStatus(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParms)
620 #if defined(linux) || defined(__FreeBSD__)
621 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus(%u, %08lX, %p);\n",
622 wDevID, dwFlags, lpParms);
623 if (lpParms == NULL) return MCIERR_INTERNAL;
624 if (CDADev[wDevID].unixdev == 0) return MMSYSERR_NOTENABLED;
625 if (dwFlags & MCI_NOTIFY) {
626 dprintf_cdaudio(stddeb,
627 "CDAUDIO_mciStatus // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
628 lpParms->dwCallback);
629 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
630 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
632 if (dwFlags & MCI_STATUS_ITEM) {
633 switch(lpParms->dwItem) {
634 case MCI_STATUS_CURRENT_TRACK:
635 if (!CDAUDIO_GetCDStatus(wDevID)) return MCIERR_INTERNAL;
636 lpParms->dwReturn = CDADev[wDevID].nCurTrack;
637 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // CURRENT_TRACK=%lu!\n", lpParms->dwReturn);
639 case MCI_STATUS_LENGTH:
640 if (CDADev[wDevID].nTracks == 0) {
641 if (!CDAUDIO_GetTracksInfo(wDevID)) {
642 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // error reading TracksInfo !\n");
643 return MCIERR_INTERNAL;
646 if (dwFlags & MCI_TRACK) {
647 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_TRACK #%lu LENGTH=??? !\n",
649 if (lpParms->dwTrack > CDADev[wDevID].nTracks)
650 return MCIERR_OUTOFRANGE;
651 lpParms->dwReturn = CDADev[wDevID].lpdwTrackLen[lpParms->dwTrack];
654 lpParms->dwReturn = CDADev[wDevID].dwTotalLen;
655 lpParms->dwReturn = CDAUDIO_CalcTime(wDevID,
656 CDADev[wDevID].dwTimeFormat, lpParms->dwReturn);
657 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // LENGTH=%lu !\n", lpParms->dwReturn);
659 case MCI_STATUS_MODE:
660 if (!CDAUDIO_GetCDStatus(wDevID)) return MCIERR_INTERNAL;
661 lpParms->dwReturn = CDADev[wDevID].mode;
662 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_MODE=%08lX !\n",
665 case MCI_STATUS_MEDIA_PRESENT:
666 lpParms->dwReturn = (CDADev[wDevID].nTracks > 0) ? TRUE : FALSE;
667 if (lpParms->dwReturn == FALSE)
668 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MEDIA_NOT_PRESENT !\n");
670 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_MEDIA_PRESENT !\n");
672 case MCI_STATUS_NUMBER_OF_TRACKS:
673 lpParms->dwReturn = CDAUDIO_GetNumberOfTracks(wDevID);
674 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_NUMBER_OF_TRACKS = %lu !\n",
676 if (lpParms->dwReturn == (WORD)-1) return MCIERR_INTERNAL;
678 case MCI_STATUS_POSITION:
679 if (!CDAUDIO_GetCDStatus(wDevID)) return MCIERR_INTERNAL;
680 lpParms->dwReturn = CDADev[wDevID].dwCurFrame;
681 if (dwFlags & MCI_STATUS_START) {
682 lpParms->dwReturn = CDADev[wDevID].dwFirstOffset;
683 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // get MCI_STATUS_START !\n");
685 if (dwFlags & MCI_TRACK) {
686 if (lpParms->dwTrack > CDADev[wDevID].nTracks)
687 return MCIERR_OUTOFRANGE;
688 lpParms->dwReturn = CDADev[wDevID].lpdwTrackPos[lpParms->dwTrack - 1];
689 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // get MCI_TRACK #%lu !\n", lpParms->dwTrack);
691 lpParms->dwReturn = CDAUDIO_CalcTime(wDevID,
692 CDADev[wDevID].dwTimeFormat, lpParms->dwReturn);
693 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_POSITION=%08lX !\n",
696 case MCI_STATUS_READY:
697 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_READY !\n");
698 lpParms->dwReturn = TRUE;
700 case MCI_STATUS_TIME_FORMAT:
701 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // MCI_STATUS_TIME_FORMAT !\n");
702 lpParms->dwReturn = CDADev[wDevID].dwTimeFormat;
705 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // unknown command %08lX !\n", lpParms->dwItem);
706 return MCIERR_UNRECOGNIZED_COMMAND;
709 dprintf_cdaudio(stddeb,"CDAUDIO_mciStatus // not MCI_STATUS_ITEM !\n");
712 return MMSYSERR_NOTENABLED;
717 /**************************************************************************
718 * CDAUDIO_mciPlay [internal]
720 static DWORD CDAUDIO_mciPlay(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
722 #if defined(linux) || defined(__FreeBSD__)
725 struct cdrom_msf msf;
727 struct ioc_play_msf msf;
729 dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay(%u, %08lX, %p);\n",
730 wDevID, dwFlags, lpParms);
731 if (lpParms == NULL) return MCIERR_INTERNAL;
732 if (CDADev[wDevID].unixdev == 0) return MMSYSERR_NOTENABLED;
733 start = 0; end = CDADev[wDevID].dwTotalLen;
734 CDADev[wDevID].nCurTrack = 1;
735 if (dwFlags & MCI_FROM) {
736 start = CDAUDIO_CalcFrame(wDevID,
737 CDADev[wDevID].dwTimeFormat, lpParms->dwFrom);
738 dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay // MCI_FROM=%08lX -> %u \n",
739 lpParms->dwFrom, start);
741 if (dwFlags & MCI_TO) {
742 end = CDAUDIO_CalcFrame(wDevID,
743 CDADev[wDevID].dwTimeFormat, lpParms->dwTo);
744 dprintf_cdaudio(stddeb,
745 "CDAUDIO_mciPlay // MCI_TO=%08lX -> %u \n",
748 start += CDADev[wDevID].dwFirstOffset;
749 end += CDADev[wDevID].dwFirstOffset;
751 msf.cdmsf_min0 = start / CDFRAMES_PERMIN;
752 msf.cdmsf_sec0 = (start % CDFRAMES_PERMIN) / CDFRAMES_PERSEC;
753 msf.cdmsf_frame0 = start % CDFRAMES_PERSEC;
754 msf.cdmsf_min1 = end / CDFRAMES_PERMIN;
755 msf.cdmsf_sec1 = (end % CDFRAMES_PERMIN) / CDFRAMES_PERSEC;
756 msf.cdmsf_frame1 = end % CDFRAMES_PERSEC;
758 msf.start_m = start / CDFRAMES_PERMIN;
759 msf.start_s = (start % CDFRAMES_PERMIN) / CDFRAMES_PERSEC;
760 msf.start_f = start % CDFRAMES_PERSEC;
761 msf.end_m = end / CDFRAMES_PERMIN;
762 msf.end_s = (end % CDFRAMES_PERMIN) / CDFRAMES_PERSEC;
763 msf.end_f = end % CDFRAMES_PERSEC;
765 if (ioctl(CDADev[wDevID].unixdev,
772 dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay // motor doesn't start !\n");
773 return MCIERR_HARDWARE;
775 if (ioctl(CDADev[wDevID].unixdev,
782 dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay // device doesn't play !\n");
783 return MCIERR_HARDWARE;
785 dprintf_cdaudio(stddeb,"CDAUDIO_mciPlay // msf = %d:%d:%d %d:%d:%d\n",
787 msf.cdmsf_min0, msf.cdmsf_sec0, msf.cdmsf_frame0,
788 msf.cdmsf_min1, msf.cdmsf_sec1, msf.cdmsf_frame1
790 msf.start_m, msf.start_s, msf.start_f,
791 msf.end_m, msf.end_s, msf.end_f
794 CDADev[wDevID].mode = MCI_MODE_PLAY;
795 if (dwFlags & MCI_NOTIFY) {
796 dprintf_cdaudio(stddeb,
797 "CDAUDIO_mciPlay // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
798 lpParms->dwCallback);
800 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
801 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
806 return MCIERR_HARDWARE;
810 /**************************************************************************
811 * CDAUDIO_mciStop [internal]
813 static DWORD CDAUDIO_mciStop(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
815 #if defined(linux) || defined(__FreeBSD__)
816 dprintf_cdaudio(stddeb,"CDAUDIO_mciStop(%u, %08lX, %p);\n",
817 wDevID, dwFlags, lpParms);
818 if (lpParms == NULL) return MCIERR_INTERNAL;
819 if (ioctl(CDADev[wDevID].unixdev,
825 )) return MCIERR_HARDWARE;
826 CDADev[wDevID].mode = MCI_MODE_STOP;
827 if (dwFlags & MCI_NOTIFY) {
828 dprintf_cdaudio(stddeb,
829 "CDAUDIO_mciStop // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
830 lpParms->dwCallback);
831 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
832 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
836 return MCIERR_HARDWARE;
840 /**************************************************************************
841 * CDAUDIO_mciPause [internal]
843 static DWORD CDAUDIO_mciPause(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
845 #if defined(linux) || defined(__FreeBSD__)
846 dprintf_cdaudio(stddeb,"CDAUDIO_mciPause(%u, %08lX, %p);\n",
847 wDevID, dwFlags, lpParms);
848 if (lpParms == NULL) return MCIERR_INTERNAL;
849 if (ioctl(CDADev[wDevID].unixdev,
855 )) return MCIERR_HARDWARE;
856 CDADev[wDevID].mode = MCI_MODE_PAUSE;
857 if (dwFlags & MCI_NOTIFY) {
858 dprintf_cdaudio(stddeb,
859 "CDAUDIO_mciPause // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
860 lpParms->dwCallback);
861 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
862 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
866 return MCIERR_HARDWARE;
870 /**************************************************************************
871 * CDAUDIO_mciResume [internal]
873 static DWORD CDAUDIO_mciResume(UINT wDevID, DWORD dwFlags, LPMCI_GENERIC_PARMS lpParms)
875 #if defined(linux) || defined(__FreeBSD__)
876 dprintf_cdaudio(stddeb,"CDAUDIO_mciResume(%u, %08lX, %p);\n",
877 wDevID, dwFlags, lpParms);
878 if (lpParms == NULL) return MCIERR_INTERNAL;
879 if (ioctl(CDADev[wDevID].unixdev,
885 )) return MCIERR_HARDWARE;
886 CDADev[wDevID].mode = MCI_MODE_STOP;
887 if (dwFlags & MCI_NOTIFY) {
888 dprintf_cdaudio(stddeb,
889 "CDAUDIO_mciResume // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
890 lpParms->dwCallback);
891 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
892 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
896 return MCIERR_HARDWARE;
900 /**************************************************************************
901 * CDAUDIO_mciSeek [internal]
903 static DWORD CDAUDIO_mciSeek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
905 #if defined(linux) || defined(__FreeBSD__)
907 MCI_PLAY_PARMS PlayParms;
908 dprintf_cdaudio(stddeb,"CDAUDIO_mciSeek(%u, %08lX, %p);\n",
909 wDevID, dwFlags, lpParms);
910 if (lpParms == NULL) return MCIERR_INTERNAL;
911 if (ioctl(CDADev[wDevID].unixdev,
918 perror("ioctl CDROMRESUME");
919 return MCIERR_HARDWARE;
921 CDADev[wDevID].mode = MCI_MODE_SEEK;
923 case MCI_SEEK_TO_START:
924 PlayParms.dwFrom = 0;
926 case MCI_SEEK_TO_END:
927 PlayParms.dwFrom = CDADev[wDevID].dwTotalLen;
930 PlayParms.dwFrom = lpParms->dwTo;
933 dwRet = CDAUDIO_mciPlay(wDevID, MCI_WAIT | MCI_FROM, &PlayParms);
934 if (dwRet != 0) return dwRet;
935 dwRet = CDAUDIO_mciStop(wDevID, MCI_WAIT, (LPMCI_GENERIC_PARMS)&PlayParms);
936 if (dwFlags & MCI_NOTIFY) {
937 dprintf_cdaudio(stddeb,
938 "CDAUDIO_mciSeek // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
939 lpParms->dwCallback);
940 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
941 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
945 return MCIERR_HARDWARE;
950 /**************************************************************************
951 * CDAUDIO_mciSet [internal]
953 static DWORD CDAUDIO_mciSet(UINT wDevID, DWORD dwFlags, LPMCI_SET_PARMS lpParms)
955 #if defined(linux) || defined(__FreeBSD__)
956 dprintf_cdaudio(stddeb,"CDAUDIO_mciSet(%u, %08lX, %p);\n",
957 wDevID, dwFlags, lpParms);
958 if (lpParms == NULL) return MCIERR_INTERNAL;
960 printf("CDAUDIO_mciSet // dwTimeFormat=%08lX\n", lpParms->dwTimeFormat);
961 printf("CDAUDIO_mciSet // dwAudio=%08lX\n", lpParms->dwAudio);
963 if (dwFlags & MCI_SET_TIME_FORMAT) {
964 switch (lpParms->dwTimeFormat) {
965 case MCI_FORMAT_MILLISECONDS:
966 dprintf_cdaudio(stddeb,
967 "CDAUDIO_mciSet // MCI_FORMAT_MILLISECONDS !\n");
970 dprintf_cdaudio(stddeb,"CDAUDIO_mciSet // MCI_FORMAT_MSF !\n");
972 case MCI_FORMAT_TMSF:
973 dprintf_cdaudio(stddeb,"CDAUDIO_mciSet // MCI_FORMAT_TMSF !\n");
976 dprintf_cdaudio(stddeb,"CDAUDIO_mciSet // bad time format !\n");
977 return MCIERR_BAD_TIME_FORMAT;
979 CDADev[wDevID].dwTimeFormat = lpParms->dwTimeFormat;
981 if (dwFlags & MCI_SET_DOOR_OPEN) {
982 dprintf_cdaudio(stddeb,
983 "CDAUDIO_mciSet // MCI_SET_DOOR_OPEN !\n");
985 if (ioctl(CDADev[wDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE;
986 if (ioctl(CDADev[wDevID].unixdev, CDIOCEJECT)) return MCIERR_HARDWARE;
987 if (ioctl(CDADev[wDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE;
989 if (ioctl(CDADev[wDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE;
991 CDADev[wDevID].nTracks = 0;
993 if (dwFlags & MCI_SET_DOOR_CLOSED) {
994 dprintf_cdaudio(stddeb,
995 "CDAUDIO_mciSet // MCI_SET_DOOR_CLOSED !\n");
997 if (ioctl(CDADev[wDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE;
998 if (ioctl(CDADev[wDevID].unixdev, CDIOCCLOSE)) return MCIERR_HARDWARE;
999 if (ioctl(CDADev[wDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE;
1001 if (ioctl(CDADev[wDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE;
1002 /* XXX should it be ",1" ??? */
1004 CDADev[wDevID].nTracks = 0;
1006 if (dwFlags & MCI_SET_VIDEO) return MCIERR_UNSUPPORTED_FUNCTION;
1007 if (dwFlags & MCI_SET_ON) return MCIERR_UNSUPPORTED_FUNCTION;
1008 if (dwFlags & MCI_SET_OFF) return MCIERR_UNSUPPORTED_FUNCTION;
1009 if (dwFlags & MCI_NOTIFY) {
1010 dprintf_cdaudio(stddeb,
1011 "CDAUDIO_mciSet // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
1012 lpParms->dwCallback);
1013 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
1014 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
1018 return MCIERR_HARDWARE;
1023 /**************************************************************************
1024 * CDAUDIO_DriverProc [sample driver]
1026 LONG CDAUDIO_DriverProc(DWORD dwDevID, HDRVR16 hDriv, WORD wMsg,
1027 DWORD dwParam1, DWORD dwParam2)
1029 #if defined(linux) || defined(__FreeBSD__)
1036 case MCI_OPEN_DRIVER:
1038 return CDAUDIO_mciOpen(dwDevID, dwParam1, (LPMCI_OPEN_PARMS)PTR_SEG_TO_LIN(dwParam2));
1040 case MCI_CLOSE_DRIVER:
1042 return CDAUDIO_mciClose(dwDevID, dwParam1, (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
1047 case DRV_QUERYCONFIGURE:
1050 MessageBox((HWND)NULL, "Sample MultiMedia Linux Driver !",
1051 "MMLinux Driver", MB_OK);
1054 return DRVCNF_RESTART;
1056 return DRVCNF_RESTART;
1057 case MCI_GETDEVCAPS:
1058 return CDAUDIO_mciGetDevCaps(dwDevID, dwParam1,
1059 (LPMCI_GETDEVCAPS_PARMS)PTR_SEG_TO_LIN(dwParam2));
1061 return CDAUDIO_mciInfo(dwDevID, dwParam1,
1062 (LPMCI_INFO_PARMS)PTR_SEG_TO_LIN(dwParam2));
1064 return CDAUDIO_mciStatus(dwDevID, dwParam1,
1065 (LPMCI_STATUS_PARMS)PTR_SEG_TO_LIN(dwParam2));
1067 return CDAUDIO_mciSet(dwDevID, dwParam1,
1068 (LPMCI_SET_PARMS)PTR_SEG_TO_LIN(dwParam2));
1070 return CDAUDIO_mciPlay(dwDevID, dwParam1,
1071 (LPMCI_PLAY_PARMS)PTR_SEG_TO_LIN(dwParam2));
1073 return CDAUDIO_mciStop(dwDevID, dwParam1,
1074 (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
1076 return CDAUDIO_mciPause(dwDevID, dwParam1,
1077 (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
1079 return CDAUDIO_mciResume(dwDevID, dwParam1,
1080 (LPMCI_GENERIC_PARMS)PTR_SEG_TO_LIN(dwParam2));
1082 return CDAUDIO_mciSeek(dwDevID, dwParam1,
1083 (LPMCI_SEEK_PARMS)PTR_SEG_TO_LIN(dwParam2));
1084 case MCI_SET_DOOR_OPEN:
1085 dprintf_cdaudio(stddeb,
1086 "CDAUDIO_DriverProc // MCI_SET_DOOR_OPEN !\n");
1088 if (ioctl(CDADev[dwDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE;
1089 if (ioctl(CDADev[dwDevID].unixdev, CDIOCEJECT)) return MCIERR_HARDWARE;
1090 if (ioctl(CDADev[dwDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE;
1092 if (ioctl(CDADev[dwDevID].unixdev, CDROMEJECT)) return MCIERR_HARDWARE;
1094 CDADev[dwDevID].nTracks = 0;
1096 case MCI_SET_DOOR_CLOSED:
1097 dprintf_cdaudio(stddeb,"CDAUDIO_DriverProc // MCI_SET_DOOR_CLOSED !\n");
1099 if (ioctl(CDADev[dwDevID].unixdev, CDIOCALLOW)) return MCIERR_HARDWARE;
1100 if (ioctl(CDADev[dwDevID].unixdev, CDIOCCLOSE)) return MCIERR_HARDWARE;
1101 if (ioctl(CDADev[dwDevID].unixdev, CDIOCPREVENT)) return MCIERR_HARDWARE;
1103 if (ioctl(CDADev[dwDevID].unixdev, CDROMEJECT, 1)) return MCIERR_HARDWARE;
1105 CDADev[dwDevID].nTracks = 0;
1108 return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
1111 return MCIERR_HARDWARE;
1116 /*-----------------------------------------------------------------------*/
1118 #endif /* #ifdef BUILTIN_MMSYSTEM */