2 * Sample MCI CDAUDIO Wine Driver for Linux
4 * Copyright 1994 Martin Ayotte
6 static char Copyright
[] = "Copyright Martin Ayotte, 1994";
9 #define BUILTIN_MMSYSTEM
12 #ifdef BUILTIN_MMSYSTEM
25 #include <sys/ioctl.h>
27 #include <linux/soundcard.h>
28 #include <linux/cdrom.h>
31 #define SOUND_DEV "/dev/dsp"
32 #define CDAUDIO_DEV "/dev/sbpcd"
35 #define IOCTL(a,b,c) ioctl(a,b,&c)
37 #define IOCTL(a,b,c) (c = ioctl(a,b,c) )
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
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
;
56 struct cdrom_subchnl sc
;
67 static LINUX_CDAUDIO CDADev
[MAX_CDAUDIODRV
];
70 UINT
CDAUDIO_GetNumberOfTracks(UINT wDevID
);
71 BOOL
CDAUDIO_GetTracksInfo(UINT wDevID
);
72 BOOL
CDAUDIO_GetCDStatus(UINT wDevID
);
73 DWORD
CDAUDIO_CalcTime(UINT wDevID
, DWORD dwFormatType
, DWORD dwFrame
);
76 /*-----------------------------------------------------------------------*/
79 /**************************************************************************
80 * CDAUDIO_mciOpen [internal]
82 DWORD
CDAUDIO_mciOpen(DWORD dwFlags
, LPMCI_OPEN_PARMS lpParms
)
88 printf("CDAUDIO_mciOpen(%08X, %08X);\n", dwFlags
, lpParms
);
90 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
91 wDevID
= lpParms
->wDeviceID
;
92 if (CDADev
[wDevID
].nUseCount
> 0) {
93 /* The driver already open on this channel */
94 /* If the driver was% op, ened shareable before and this open specifies */
95 /* shareable then increment the use count */
96 if (CDADev
[wDevID
].fShareable
&& (dwFlags
& MCI_OPEN_SHAREABLE
))
97 ++CDADev
[wDevID
].nUseCount
;
99 return MCIERR_MUST_USE_SHAREABLE
;
102 CDADev
[wDevID
].nUseCount
= 1;
103 CDADev
[wDevID
].fShareable
= dwFlags
& MCI_OPEN_SHAREABLE
;
105 if (dwFlags
& MCI_OPEN_ELEMENT
) {
106 printf("CDAUDIO_mciOpen // MCI_OPEN_ELEMENT !\n");
107 /* return MCIERR_NO_ELEMENT_ALLOWED; */
109 memcpy(&CDADev
[wDevID
].openParms
, lpParms
, sizeof(MCI_OPEN_PARMS
));
110 CDADev
[wDevID
].wNotifyDeviceID
= lpParms
->wDeviceID
;
111 CDADev
[wDevID
].unixdev
= open (CDAUDIO_DEV
, O_RDONLY
, 0);
112 if (CDADev
[wDevID
].unixdev
== -1) {
113 printf("CDAUDIO_mciOpen // can't open '%s' !\n", CDAUDIO_DEV
);
114 return MCIERR_HARDWARE
;
116 CDADev
[wDevID
].mode
= 0;
117 CDADev
[wDevID
].dwTimeFormat
= MCI_FORMAT_TMSF
;
118 CDADev
[wDevID
].nCurTrack
= 0;
119 CDADev
[wDevID
].nTracks
= 0;
120 CDADev
[wDevID
].dwTotalLen
= 0;
121 CDADev
[wDevID
].dwFirstOffset
= 0;
122 CDADev
[wDevID
].lpdwTrackLen
= NULL
;
123 CDADev
[wDevID
].lpdwTrackPos
= NULL
;
124 if (!CDAUDIO_GetTracksInfo(wDevID
)) {
125 printf("CDAUDIO_mciOpen // error reading TracksInfo !\n");
126 /* return MCIERR_INTERNAL; */
128 if (dwFlags
& MCI_NOTIFY
) {
129 printf("CDAUDIO_mciOpen // MCI_NOTIFY_SUCCESSFUL %08X !\n", lpParms
->dwCallback
);
130 mciDriverNotify((HWND
)LOWORD(lpParms
->dwCallback
),
131 CDADev
[wDevID
].wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
135 return MCIERR_HARDWARE
;
139 /**************************************************************************
140 * CDAUDIO_mciClose [internal]
142 DWORD
CDAUDIO_mciClose(UINT wDevID
, DWORD dwParam
, LPMCI_GENERIC_PARMS lpParms
)
146 printf("CDAUDIO_mciClose(%u, %08X, %08X);\n", wDevID
, dwParam
, lpParms
);
148 if (CDADev
[wDevID
].lpdwTrackLen
!= NULL
) free(CDADev
[wDevID
].lpdwTrackLen
);
149 if (CDADev
[wDevID
].lpdwTrackPos
!= NULL
) free(CDADev
[wDevID
].lpdwTrackPos
);
150 close(CDADev
[wDevID
].unixdev
);
154 /**************************************************************************
155 * CDAUDIO_mciGetDevCaps [internal]
157 DWORD
CDAUDIO_mciGetDevCaps(UINT wDevID
, DWORD dwFlags
,
158 LPMCI_GETDEVCAPS_PARMS lpParms
)
162 printf("CDAUDIO_mciGetDevCaps(%u, %08X, %08X);\n", wDevID
, dwFlags
, lpParms
);
164 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
165 if (dwFlags
& MCI_GETDEVCAPS_ITEM
) {
166 printf("CDAUDIO_mciGetDevCaps // MCI_GETDEVCAPS_ITEM dwItem=%08X;\n",
168 switch(lpParms
->dwItem
) {
169 case MCI_GETDEVCAPS_CAN_RECORD
:
170 lpParms
->dwReturn
= FALSE
;
172 case MCI_GETDEVCAPS_HAS_AUDIO
:
173 lpParms
->dwReturn
= TRUE
;
175 case MCI_GETDEVCAPS_HAS_VIDEO
:
176 lpParms
->dwReturn
= FALSE
;
178 case MCI_GETDEVCAPS_DEVICE_TYPE
:
179 lpParms
->dwReturn
= MCI_DEVTYPE_CD_AUDIO
;
181 case MCI_GETDEVCAPS_USES_FILES
:
182 lpParms
->dwReturn
= FALSE
;
184 case MCI_GETDEVCAPS_COMPOUND_DEVICE
:
185 lpParms
->dwReturn
= FALSE
;
187 case MCI_GETDEVCAPS_CAN_EJECT
:
188 lpParms
->dwReturn
= TRUE
;
190 case MCI_GETDEVCAPS_CAN_PLAY
:
191 lpParms
->dwReturn
= TRUE
;
193 case MCI_GETDEVCAPS_CAN_SAVE
:
194 lpParms
->dwReturn
= FALSE
;
197 return MCIERR_UNRECOGNIZED_COMMAND
;
200 printf("CDAUDIO_mciGetDevCaps // lpParms->dwReturn=%08X;\n", lpParms
->dwReturn
);
203 return MCIERR_INTERNAL
;
207 /**************************************************************************
208 * CDAUDIO_mciInfo [internal]
210 DWORD
CDAUDIO_mciInfo(UINT wDevID
, DWORD dwFlags
, LPMCI_INFO_PARMS lpParms
)
214 printf("CDAUDIO_mciInfo(%u, %08X, %08X);\n", wDevID
, dwFlags
, lpParms
);
216 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
217 lpParms
->lpstrReturn
= NULL
;
219 case MCI_INFO_PRODUCT
:
220 lpParms
->lpstrReturn
= "Linux CDROM 0.5";
223 return MCIERR_UNRECOGNIZED_COMMAND
;
225 if (lpParms
->lpstrReturn
!= NULL
)
226 lpParms
->dwRetSize
= strlen(lpParms
->lpstrReturn
);
228 lpParms
->dwRetSize
= 0;
231 return MCIERR_INTERNAL
;
235 /**************************************************************************
236 * CDAUDIO_mciStatus [internal]
238 DWORD
CDAUDIO_mciStatus(UINT wDevID
, DWORD dwFlags
, LPMCI_STATUS_PARMS lpParms
)
242 printf("CDAUDIO_mciStatus(%u, %08X, %08X);\n", wDevID
, dwFlags
, lpParms
);
244 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
245 if (CDADev
[wDevID
].unixdev
== 0) return MMSYSERR_NOTENABLED
;
246 if (dwFlags
& MCI_NOTIFY
) {
248 printf("CDAUDIO_mciStatus // MCI_NOTIFY_SUCCESSFUL %08X !\n", lpParms
->dwCallback
);
250 mciDriverNotify((HWND
)LOWORD(lpParms
->dwCallback
),
251 CDADev
[wDevID
].wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
253 if (dwFlags
& MCI_STATUS_ITEM
) {
254 switch(lpParms
->dwItem
) {
255 case MCI_STATUS_CURRENT_TRACK
:
256 if (!CDAUDIO_GetCDStatus(wDevID
)) return MCIERR_INTERNAL
;
257 lpParms
->dwReturn
= CDADev
[wDevID
].nCurTrack
;
259 printf("CDAUDIO_mciStatus // CURRENT_TRACK=%u!\n", lpParms
->dwReturn
);
262 case MCI_STATUS_LENGTH
:
263 if (CDADev
[wDevID
].nTracks
== 0) {
264 if (!CDAUDIO_GetTracksInfo(wDevID
)) {
265 printf("CDAUDIO_mciStatus // error reading TracksInfo !\n");
266 return MCIERR_INTERNAL
;
269 if (dwFlags
& MCI_TRACK
) {
270 printf("CDAUDIO_mciStatus // MCI_TRACK #%u LENGTH=??? !\n",
272 if (lpParms
->dwTrack
> CDADev
[wDevID
].nTracks
)
273 return MCIERR_OUTOFRANGE
;
274 lpParms
->dwReturn
= CDADev
[wDevID
].lpdwTrackLen
[lpParms
->dwTrack
];
277 lpParms
->dwReturn
= CDADev
[wDevID
].dwTotalLen
;
278 lpParms
->dwReturn
= CDAUDIO_CalcTime(wDevID
,
279 CDADev
[wDevID
].dwTimeFormat
, lpParms
->dwReturn
);
280 printf("CDAUDIO_mciStatus // LENGTH=%u !\n", lpParms
->dwReturn
);
282 case MCI_STATUS_MODE
:
283 if (!CDAUDIO_GetCDStatus(wDevID
)) return MCIERR_INTERNAL
;
284 lpParms
->dwReturn
= CDADev
[wDevID
].mode
;
286 printf("CDAUDIO_mciStatus // MCI_STATUS_MODE=%08X !\n",
290 case MCI_STATUS_MEDIA_PRESENT
:
291 lpParms
->dwReturn
= (CDADev
[wDevID
].nTracks
> 0) ? TRUE
: FALSE
;
292 if (lpParms
->dwReturn
== FALSE
)
293 printf("CDAUDIO_mciStatus // MEDIA_NOT_PRESENT !\n");
295 printf("CDAUDIO_mciStatus // MCI_STATUS_MEDIA_PRESENT !\n");
297 case MCI_STATUS_NUMBER_OF_TRACKS
:
298 lpParms
->dwReturn
= CDAUDIO_GetNumberOfTracks(wDevID
);
299 printf("CDAUDIO_mciStatus // MCI_STATUS_NUMBER_OF_TRACKS = %u !\n",
301 if (lpParms
->dwReturn
== (WORD
)-1) return MCIERR_INTERNAL
;
303 case MCI_STATUS_POSITION
:
304 if (!CDAUDIO_GetCDStatus(wDevID
)) return MCIERR_INTERNAL
;
305 lpParms
->dwReturn
= CDADev
[wDevID
].dwCurFrame
;
306 if (dwFlags
& MCI_STATUS_START
) {
307 lpParms
->dwReturn
= CDADev
[wDevID
].dwFirstOffset
;
309 printf("CDAUDIO_mciStatus // get MCI_STATUS_START !\n");
312 if (dwFlags
& MCI_TRACK
) {
313 if (lpParms
->dwTrack
> CDADev
[wDevID
].nTracks
)
314 return MCIERR_OUTOFRANGE
;
315 lpParms
->dwReturn
= CDADev
[wDevID
].lpdwTrackPos
[lpParms
->dwTrack
- 1];
317 printf("CDAUDIO_mciStatus // get MCI_TRACK #%u !\n", lpParms
->dwTrack
);
320 lpParms
->dwReturn
= CDAUDIO_CalcTime(wDevID
,
321 CDADev
[wDevID
].dwTimeFormat
, lpParms
->dwReturn
);
323 printf("CDAUDIO_mciStatus // MCI_STATUS_POSITION=%08X !\n",
327 case MCI_STATUS_READY
:
328 printf("CDAUDIO_mciStatus // MCI_STATUS_READY !\n");
329 lpParms
->dwReturn
= TRUE
;
331 case MCI_STATUS_TIME_FORMAT
:
332 printf("CDAUDIO_mciStatus // MCI_STATUS_TIME_FORMAT !\n");
333 lpParms
->dwReturn
= MCI_FORMAT_MILLISECONDS
;
336 printf("CDAUDIO_mciStatus // unknowm command %04X !\n", lpParms
->dwItem
);
337 return MCIERR_UNRECOGNIZED_COMMAND
;
340 printf("CDAUDIO_mciStatus // not MCI_STATUS_ITEM !\n");
343 return MMSYSERR_NOTENABLED
;
348 /**************************************************************************
349 * CDAUDIO_CalcTime [internal]
351 DWORD
CDAUDIO_CalcTime(UINT wDevID
, DWORD dwFormatType
, DWORD dwFrame
)
360 printf("CDAUDIO_CalcTime(%u, %08X, %lu);\n", wDevID
, dwFormatType
, dwFrame
);
363 switch (dwFormatType
) {
364 case MCI_FORMAT_MILLISECONDS
:
365 dwTime
= dwFrame
/ CDFRAMES_PERSEC
* 1000;
367 printf("CDAUDIO_CalcTime // MILLISECONDS %u\n", dwTime
);
371 wMinutes
= dwFrame
/ CDFRAMES_PERMIN
;
372 wSeconds
= (dwFrame
- CDFRAMES_PERMIN
* wMinutes
) / CDFRAMES_PERSEC
;
373 wFrames
= dwFrame
- CDFRAMES_PERMIN
* wMinutes
-
374 CDFRAMES_PERSEC
* wSeconds
;
375 dwTime
= MCI_MAKE_MSF(wMinutes
, wSeconds
, wFrames
);
377 printf("CDAUDIO_CalcTime // MSF %02u:%02u:%02u -> dwTime=%u\n",
378 wMinutes
, wSeconds
, wFrames
, dwTime
);
381 case MCI_FORMAT_TMSF
:
382 for (wTrack
= 0; wTrack
< CDADev
[wDevID
].nTracks
; wTrack
++) {
383 /* dwTime += CDADev[wDevID].lpdwTrackLen[wTrack - 1];
384 printf("Adding trk#%u curpos=%u \n", dwTime);
385 if (dwTime >= dwFrame) break; */
386 if (CDADev
[wDevID
].lpdwTrackPos
[wTrack
- 1] >= dwFrame
) break;
388 wMinutes
= dwFrame
/ CDFRAMES_PERMIN
;
389 wSeconds
= (dwFrame
- CDFRAMES_PERMIN
* wMinutes
) / CDFRAMES_PERSEC
;
390 wFrames
= dwFrame
- CDFRAMES_PERMIN
* wMinutes
-
391 CDFRAMES_PERSEC
* wSeconds
;
392 dwTime
= MCI_MAKE_TMSF(wTrack
, wMinutes
, wSeconds
, wFrames
);
394 printf("CDAUDIO_CalcTime // %02u-%02u:%02u:%02u\n",
395 wTrack
, wMinutes
, wSeconds
, wFrames
);
399 /* unknown format ! force TMSF ! ... */
400 dwFormatType
= MCI_FORMAT_TMSF
;
408 /**************************************************************************
409 * CDAUDIO_CalcFrame [internal]
411 DWORD
CDAUDIO_CalcFrame(UINT wDevID
, DWORD dwFormatType
, DWORD dwTime
)
417 printf("CDAUDIO_CalcFrame(%u, %08X, %lu);\n", wDevID
, dwFormatType
, dwTime
);
420 switch (dwFormatType
) {
421 case MCI_FORMAT_MILLISECONDS
:
422 dwFrame
= dwTime
* CDFRAMES_PERSEC
/ 1000;
424 printf("CDAUDIO_CalcFrame // MILLISECONDS %u\n", dwFrame
);
429 printf("CDAUDIO_CalcFrame // MSF %02u:%02u:%02u\n",
430 MCI_MSF_MINUTE(dwTime
), MCI_MSF_SECOND(dwTime
),
431 MCI_MSF_FRAME(dwTime
));
433 dwFrame
+= CDFRAMES_PERMIN
* MCI_MSF_MINUTE(dwTime
);
434 dwFrame
+= CDFRAMES_PERSEC
* MCI_MSF_SECOND(dwTime
);
435 dwFrame
+= MCI_MSF_FRAME(dwTime
);
437 case MCI_FORMAT_TMSF
:
438 wTrack
= MCI_TMSF_TRACK(dwTime
);
440 printf("CDAUDIO_CalcFrame // TMSF %02u-%02u:%02u:%02u\n",
441 MCI_TMSF_TRACK(dwTime
), MCI_TMSF_MINUTE(dwTime
),
442 MCI_TMSF_SECOND(dwTime
), MCI_TMSF_FRAME(dwTime
));
443 printf("CDAUDIO_CalcFrame // TMSF trackpos[%u]=%u\n",
444 wTrack
, CDADev
[wDevID
].lpdwTrackPos
[wTrack
- 1]);
446 dwFrame
= CDADev
[wDevID
].lpdwTrackPos
[wTrack
- 1];
447 dwFrame
+= CDFRAMES_PERMIN
* MCI_TMSF_MINUTE(dwTime
);
448 dwFrame
+= CDFRAMES_PERSEC
* MCI_TMSF_SECOND(dwTime
);
449 dwFrame
+= MCI_TMSF_FRAME(dwTime
);
452 /* unknown format ! force TMSF ! ... */
453 dwFormatType
= MCI_FORMAT_TMSF
;
461 /**************************************************************************
462 * CDAUDIO_GetNumberOfTracks [internal]
464 UINT
CDAUDIO_GetNumberOfTracks(UINT wDevID
)
467 struct cdrom_tochdr hdr
;
468 if (CDADev
[wDevID
].nTracks
== 0) {
469 if (ioctl(CDADev
[wDevID
].unixdev
, CDROMREADTOCHDR
, &hdr
)) {
470 printf("GetNumberOfTracks(%u) // Error occured !\n", wDevID
);
473 CDADev
[wDevID
].nTracks
= hdr
.cdth_trk1
;
475 return CDADev
[wDevID
].nTracks
;
481 /**************************************************************************
482 * CDAUDIO_GetNumberOfTracks [internal]
484 BOOL
CDAUDIO_GetTracksInfo(UINT wDevID
)
488 int start
, last_start
;
489 int total_length
= 0;
490 struct cdrom_tocentry entry
;
491 if (CDADev
[wDevID
].nTracks
== 0) {
492 if (CDAUDIO_GetNumberOfTracks(wDevID
) == (WORD
)-1) return FALSE
;
494 printf("CDAUDIO_GetTracksInfo // nTracks=%u\n", CDADev
[wDevID
].nTracks
);
495 if (CDADev
[wDevID
].lpdwTrackLen
!= NULL
)
496 free(CDADev
[wDevID
].lpdwTrackLen
);
497 CDADev
[wDevID
].lpdwTrackLen
= (LPDWORD
)malloc(
498 (CDADev
[wDevID
].nTracks
+ 1) * sizeof(DWORD
));
499 if (CDADev
[wDevID
].lpdwTrackPos
!= NULL
)
500 free(CDADev
[wDevID
].lpdwTrackPos
);
501 CDADev
[wDevID
].lpdwTrackPos
= (LPDWORD
)malloc(
502 (CDADev
[wDevID
].nTracks
+ 1) * sizeof(DWORD
));
503 if (CDADev
[wDevID
].lpdwTrackLen
== NULL
||
504 CDADev
[wDevID
].lpdwTrackPos
== NULL
) {
505 printf("CDAUDIO_GetTracksInfo // error allocating track table !\n");
508 memset(CDADev
[wDevID
].lpdwTrackLen
, 0,
509 (CDADev
[wDevID
].nTracks
+ 1) * sizeof(DWORD
));
510 memset(CDADev
[wDevID
].lpdwTrackPos
, 0,
511 (CDADev
[wDevID
].nTracks
+ 1) * sizeof(DWORD
));
512 for (i
= 0; i
<= CDADev
[wDevID
].nTracks
; i
++) {
513 if (i
== CDADev
[wDevID
].nTracks
)
514 entry
.cdte_track
= CDROM_LEADOUT
;
516 entry
.cdte_track
= i
+ 1;
517 entry
.cdte_format
= CDROM_MSF
;
518 if (ioctl(CDADev
[wDevID
].unixdev
, CDROMREADTOCENTRY
, &entry
)) {
519 printf("CDAUDIO_GetTracksInfo // error read entry\n");
522 start
= CDFRAMES_PERSEC
* (SECONDS_PERMIN
*
523 entry
.cdte_addr
.msf
.minute
+ entry
.cdte_addr
.msf
.second
) +
524 entry
.cdte_addr
.msf
.frame
;
526 CDADev
[wDevID
].dwFirstOffset
= last_start
= start
;
527 printf("CDAUDIO_GetTracksInfo // dwFirstOffset=%u\n", start
);
530 length
= start
- last_start
;
532 start
= last_start
- length
;
533 total_length
+= length
;
534 CDADev
[wDevID
].lpdwTrackLen
[i
- 1] = length
;
535 CDADev
[wDevID
].lpdwTrackPos
[i
- 1] = start
;
536 printf("CDAUDIO_GetTracksInfo // track #%u start=%u len=%u\n",
540 CDADev
[wDevID
].dwTotalLen
= total_length
;
541 printf("CDAUDIO_GetTracksInfo // total_len=%u\n", total_length
);
550 /**************************************************************************
551 * CDAUDIO_GetNumberOfTracks [internal]
553 BOOL
CDAUDIO_GetCDStatus(UINT wDevID
)
556 int oldmode
= CDADev
[wDevID
].mode
;
557 CDADev
[wDevID
].sc
.cdsc_format
= CDROM_MSF
;
558 if (ioctl(CDADev
[wDevID
].unixdev
, CDROMSUBCHNL
, &CDADev
[wDevID
].sc
)) {
560 printf("CDAUDIO_GetCDStatus // opened or no_media !\n");
562 CDADev
[wDevID
].mode
= MCI_MODE_NOT_READY
;
565 switch (CDADev
[wDevID
].sc
.cdsc_audiostatus
) {
566 case CDROM_AUDIO_INVALID
:
567 printf("CDAUDIO_GetCDStatus // device doesn't support status !\n");
569 case CDROM_AUDIO_NO_STATUS
:
570 CDADev
[wDevID
].mode
= MCI_MODE_STOP
;
572 printf("CDAUDIO_GetCDStatus // MCI_MODE_STOP !\n");
575 case CDROM_AUDIO_PLAY
:
576 CDADev
[wDevID
].mode
= MCI_MODE_PLAY
;
578 printf("CDAUDIO_GetCDStatus // MCI_MODE_PLAY !\n");
581 case CDROM_AUDIO_PAUSED
:
582 CDADev
[wDevID
].mode
= MCI_MODE_PAUSE
;
584 printf("CDAUDIO_GetCDStatus // MCI_MODE_PAUSE !\n");
588 printf("CDAUDIO_GetCDStatus // status=%02X !\n",
589 CDADev
[wDevID
].sc
.cdsc_audiostatus
);
591 CDADev
[wDevID
].nCurTrack
= CDADev
[wDevID
].sc
.cdsc_trk
;
592 CDADev
[wDevID
].dwCurFrame
=
593 CDFRAMES_PERMIN
* CDADev
[wDevID
].sc
.cdsc_absaddr
.msf
.minute
+
594 CDFRAMES_PERSEC
* CDADev
[wDevID
].sc
.cdsc_absaddr
.msf
.second
+
595 CDADev
[wDevID
].sc
.cdsc_absaddr
.msf
.frame
;
597 printf("CDAUDIO_GetCDStatus // %02u-%02u:%02u:%02u \n",
598 CDADev
[wDevID
].sc
.cdsc_trk
,
599 CDADev
[wDevID
].sc
.cdsc_absaddr
.msf
.minute
,
600 CDADev
[wDevID
].sc
.cdsc_absaddr
.msf
.second
,
601 CDADev
[wDevID
].sc
.cdsc_absaddr
.msf
.frame
);
603 if (oldmode
!= CDADev
[wDevID
].mode
&& oldmode
== MCI_MODE_OPEN
) {
604 if (!CDAUDIO_GetTracksInfo(wDevID
)) {
605 printf("CDAUDIO_GetCDStatus // error updating TracksInfo !\n");
606 return MCIERR_INTERNAL
;
615 /**************************************************************************
616 * CDAUDIO_mciPlay [internal]
618 DWORD
CDAUDIO_mciPlay(UINT wDevID
, DWORD dwFlags
, LPMCI_PLAY_PARMS lpParms
)
622 struct cdrom_msf msf
;
624 printf("CDAUDIO_mciPlay(%u, %08X, %08X);\n", wDevID
, dwFlags
, lpParms
);
626 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
627 if (CDADev
[wDevID
].unixdev
== 0) return MMSYSERR_NOTENABLED
;
628 start
= 0; end
= CDADev
[wDevID
].dwTotalLen
;
629 CDADev
[wDevID
].nCurTrack
= 1;
630 if (dwFlags
& MCI_FROM
) {
631 start
= CDAUDIO_CalcFrame(wDevID
,
632 CDADev
[wDevID
].dwTimeFormat
, lpParms
->dwFrom
);
634 printf("CDAUDIO_mciPlay // MCI_FROM=%08X -> %u \n",
635 lpParms
->dwFrom
, start
);
638 if (dwFlags
& MCI_TO
) {
639 end
= CDAUDIO_CalcFrame(wDevID
,
640 CDADev
[wDevID
].dwTimeFormat
, lpParms
->dwTo
);
642 printf("CDAUDIO_mciPlay // MCI_TO=%08X -> %u \n",
646 start
+= CDADev
[wDevID
].dwFirstOffset
;
647 end
+= CDADev
[wDevID
].dwFirstOffset
;
648 msf
.cdmsf_min0
= start
/ CDFRAMES_PERMIN
;
649 msf
.cdmsf_sec0
= (start
% CDFRAMES_PERMIN
) / CDFRAMES_PERSEC
;
650 msf
.cdmsf_frame0
= start
% CDFRAMES_PERSEC
;
651 msf
.cdmsf_min1
= end
/ CDFRAMES_PERMIN
;
652 msf
.cdmsf_sec1
= (end
% CDFRAMES_PERMIN
) / CDFRAMES_PERSEC
;
653 msf
.cdmsf_frame1
= end
% CDFRAMES_PERSEC
;
654 if (ioctl(CDADev
[wDevID
].unixdev
, CDROMSTART
)) {
655 printf("CDAUDIO_mciPlay // motor doesn't start !\n");
656 return MCIERR_HARDWARE
;
658 if (ioctl(CDADev
[wDevID
].unixdev
, CDROMPLAYMSF
, &msf
)) {
659 printf("CDAUDIO_mciPlay // device doesn't play !\n");
660 return MCIERR_HARDWARE
;
663 printf("CDAUDIO_mciPlay // msf = %d:%d:%d %d:%d:%d\n",
664 msf
.cdmsf_min0
, msf
.cdmsf_sec0
, msf
.cdmsf_frame0
,
665 msf
.cdmsf_min1
, msf
.cdmsf_sec1
, msf
.cdmsf_frame1
);
667 CDADev
[wDevID
].mode
= MCI_MODE_PLAY
;
668 if (dwFlags
& MCI_NOTIFY
) {
669 printf("CDAUDIO_mciPlay // MCI_NOTIFY_SUCCESSFUL %08X !\n", lpParms
->dwCallback
);
670 mciDriverNotify((HWND
)LOWORD(lpParms
->dwCallback
),
671 CDADev
[wDevID
].wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
675 return MCIERR_HARDWARE
;
679 /**************************************************************************
680 * CDAUDIO_mciStop [internal]
682 DWORD
CDAUDIO_mciStop(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
686 printf("CDAUDIO_mciStop(%u, %08X, %08X);\n", wDevID
, dwFlags
, lpParms
);
688 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
689 if (ioctl(CDADev
[wDevID
].unixdev
, CDROMSTOP
)) return MCIERR_HARDWARE
;
690 CDADev
[wDevID
].mode
= MCI_MODE_STOP
;
691 if (dwFlags
& MCI_NOTIFY
) {
692 printf("CDAUDIO_mciStop // MCI_NOTIFY_SUCCESSFUL %08X !\n", lpParms
->dwCallback
);
693 mciDriverNotify((HWND
)LOWORD(lpParms
->dwCallback
),
694 CDADev
[wDevID
].wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
698 return MCIERR_HARDWARE
;
702 /**************************************************************************
703 * CDAUDIO_mciPause [internal]
705 DWORD
CDAUDIO_mciPause(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
709 printf("CDAUDIO_mciPause(%u, %08X, %08X);\n", wDevID
, dwFlags
, lpParms
);
711 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
712 if (ioctl(CDADev
[wDevID
].unixdev
, CDROMPAUSE
)) return MCIERR_HARDWARE
;
713 CDADev
[wDevID
].mode
= MCI_MODE_PAUSE
;
714 if (dwFlags
& MCI_NOTIFY
) {
715 printf("CDAUDIO_mciPause // MCI_NOTIFY_SUCCESSFUL %08X !\n", lpParms
->dwCallback
);
716 mciDriverNotify((HWND
)LOWORD(lpParms
->dwCallback
),
717 CDADev
[wDevID
].wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
721 return MCIERR_HARDWARE
;
725 /**************************************************************************
726 * CDAUDIO_mciResume [internal]
728 DWORD
CDAUDIO_mciResume(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
732 printf("CDAUDIO_mciResume(%u, %08X, %08X);\n", wDevID
, dwFlags
, lpParms
);
734 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
735 if (ioctl(CDADev
[wDevID
].unixdev
, CDROMRESUME
)) return MCIERR_HARDWARE
;
736 CDADev
[wDevID
].mode
= MCI_MODE_STOP
;
737 if (dwFlags
& MCI_NOTIFY
) {
738 printf("CDAUDIO_mciResume // MCI_NOTIFY_SUCCESSFUL %08X !\n", lpParms
->dwCallback
);
739 mciDriverNotify((HWND
)LOWORD(lpParms
->dwCallback
),
740 CDADev
[wDevID
].wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
744 return MCIERR_HARDWARE
;
748 /**************************************************************************
749 * CDAUDIO_mciSeek [internal]
751 DWORD
CDAUDIO_mciSeek(UINT wDevID
, DWORD dwFlags
, LPMCI_SEEK_PARMS lpParms
)
755 MCI_PLAY_PARMS PlayParms
;
757 printf("CDAUDIO_mciSeek(%u, %08X, %08X);\n", wDevID
, dwFlags
, lpParms
);
759 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
760 if (ioctl(CDADev
[wDevID
].unixdev
, CDROMRESUME
)) return MCIERR_HARDWARE
;
761 CDADev
[wDevID
].mode
= MCI_MODE_SEEK
;
763 case MCI_SEEK_TO_START
:
764 PlayParms
.dwFrom
= 0;
766 case MCI_SEEK_TO_END
:
767 PlayParms
.dwFrom
= CDADev
[wDevID
].dwTotalLen
;
770 PlayParms
.dwFrom
= lpParms
->dwTo
;
773 dwRet
= CDAUDIO_mciPlay(wDevID
, MCI_WAIT
| MCI_FROM
, &PlayParms
);
774 if (dwRet
!= 0) return dwRet
;
775 dwRet
= CDAUDIO_mciStop(wDevID
, MCI_WAIT
, (LPMCI_GENERIC_PARMS
)&PlayParms
);
776 if (dwFlags
& MCI_NOTIFY
) {
777 printf("CDAUDIO_mciSeek // MCI_NOTIFY_SUCCESSFUL %08X !\n", lpParms
->dwCallback
);
778 mciDriverNotify((HWND
)LOWORD(lpParms
->dwCallback
),
779 CDADev
[wDevID
].wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
783 return MCIERR_HARDWARE
;
788 /**************************************************************************
789 * CDAUDIO_mciSet [internal]
791 DWORD
CDAUDIO_mciSet(UINT wDevID
, DWORD dwFlags
, LPMCI_SET_PARMS lpParms
)
795 printf("CDAUDIO_mciSet(%u, %08X, %08X);\n", wDevID
, dwFlags
, lpParms
);
797 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
799 printf("CDAUDIO_mciSet // dwTimeFormat=%08X\n", lpParms->dwTimeFormat);
800 printf("CDAUDIO_mciSet // dwAudio=%08X\n", lpParms->dwAudio);
802 if (dwFlags
& MCI_SET_TIME_FORMAT
) {
803 switch (lpParms
->dwTimeFormat
) {
804 case MCI_FORMAT_MILLISECONDS
:
806 printf("CDAUDIO_mciSet // MCI_FORMAT_MILLISECONDS !\n");
811 printf("CDAUDIO_mciSet // MCI_FORMAT_MSF !\n");
814 case MCI_FORMAT_TMSF
:
816 printf("CDAUDIO_mciSet // MCI_FORMAT_TMSF !\n");
820 printf("CDAUDIO_mciSet // bad time format !\n");
821 return MCIERR_BAD_TIME_FORMAT
;
823 CDADev
[wDevID
].dwTimeFormat
= lpParms
->dwTimeFormat
;
825 if (dwFlags
& MCI_SET_DOOR_OPEN
) {
826 printf("CDAUDIO_mciSet // MCI_SET_DOOR_OPEN !\n");
827 if (ioctl(CDADev
[wDevID
].unixdev
, CDROMEJECT
)) return MCIERR_HARDWARE
;
828 CDADev
[wDevID
].nTracks
= 0;
830 if (dwFlags
& MCI_SET_DOOR_CLOSED
) {
831 printf("CDAUDIO_mciSet // MCI_SET_DOOR_CLOSED !\n");
832 if (ioctl(CDADev
[wDevID
].unixdev
, CDROMEJECT
)) return MCIERR_HARDWARE
;
833 CDADev
[wDevID
].nTracks
= 0;
835 if (dwFlags
& MCI_SET_VIDEO
) return MCIERR_UNSUPPORTED_FUNCTION
;
836 if (dwFlags
& MCI_SET_ON
) return MCIERR_UNSUPPORTED_FUNCTION
;
837 if (dwFlags
& MCI_SET_OFF
) return MCIERR_UNSUPPORTED_FUNCTION
;
838 if (dwFlags
& MCI_NOTIFY
) {
839 printf("CDAUDIO_mciSet // MCI_NOTIFY_SUCCESSFUL %08X !\n", lpParms
->dwCallback
);
840 mciDriverNotify((HWND
)LOWORD(lpParms
->dwCallback
),
841 CDADev
[wDevID
].wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
845 return MCIERR_HARDWARE
;
850 /**************************************************************************
851 * CDAUDIO_DriverProc [sample driver]
853 LRESULT
CDAUDIO_DriverProc(DWORD dwDevID
, HDRVR hDriv
, WORD wMsg
,
854 DWORD dwParam1
, DWORD dwParam2
)
863 case MCI_OPEN_DRIVER
:
865 return CDAUDIO_mciOpen(dwParam1
, (LPMCI_OPEN_PARMS
)dwParam2
);
867 case MCI_CLOSE_DRIVER
:
869 return CDAUDIO_mciClose(dwDevID
, dwParam1
,
870 (LPMCI_GENERIC_PARMS
)dwParam2
);
875 case DRV_QUERYCONFIGURE
:
878 MessageBox((HWND
)NULL
, "Sample MultiMedia Linux Driver !",
879 "MMLinux Driver", MB_OK
);
882 return (LRESULT
)DRVCNF_RESTART
;
884 return (LRESULT
)DRVCNF_RESTART
;
886 return CDAUDIO_mciGetDevCaps(dwDevID
, dwParam1
,
887 (LPMCI_GETDEVCAPS_PARMS
)dwParam2
);
889 return CDAUDIO_mciInfo(dwDevID
, dwParam1
,
890 (LPMCI_INFO_PARMS
)dwParam2
);
892 return CDAUDIO_mciStatus(dwDevID
, dwParam1
,
893 (LPMCI_STATUS_PARMS
)dwParam2
);
895 return CDAUDIO_mciSet(dwDevID
, dwParam1
,
896 (LPMCI_SET_PARMS
)dwParam2
);
898 return CDAUDIO_mciPlay(dwDevID
, dwParam1
,
899 (LPMCI_PLAY_PARMS
)dwParam2
);
901 return CDAUDIO_mciStop(dwDevID
, dwParam1
,
902 (LPMCI_GENERIC_PARMS
)dwParam2
);
904 return CDAUDIO_mciPause(dwDevID
, dwParam1
,
905 (LPMCI_GENERIC_PARMS
)dwParam2
);
907 return CDAUDIO_mciResume(dwDevID
, dwParam1
,
908 (LPMCI_GENERIC_PARMS
)dwParam2
);
910 return CDAUDIO_mciSeek(dwDevID
, dwParam1
,
911 (LPMCI_SEEK_PARMS
)dwParam2
);
912 case MCI_SET_DOOR_OPEN
:
913 printf("CDAUDIO_DriverProc // MCI_SET_DOOR_OPEN !\n");
914 if (ioctl(CDADev
[dwDevID
].unixdev
, CDROMEJECT
)) return MCIERR_HARDWARE
;
915 CDADev
[dwDevID
].nTracks
= 0;
917 case MCI_SET_DOOR_CLOSED
:
918 printf("CDAUDIO_DriverProc // MCI_SET_DOOR_CLOSED !\n");
919 if (ioctl(CDADev
[dwDevID
].unixdev
, CDROMEJECT
, 1)) return MCIERR_HARDWARE
;
920 CDADev
[dwDevID
].nTracks
= 0;
923 return DefDriverProc(dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);
926 return MCIERR_HARDWARE
;
931 /*-----------------------------------------------------------------------*/
933 #endif /* #ifdef BUILTIN_MMSYSTEM */