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>
31 #define SOUND_DEV "/dev/dsp"
32 #define CDAUDIO_DEV "/dev/cdrom"
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
];
71 /*-----------------------------------------------------------------------*/
74 /**************************************************************************
75 * CDAUDIO_GetNumberOfTracks [internal]
77 static UINT
CDAUDIO_GetNumberOfTracks(UINT wDevID
)
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",
88 CDADev
[wDevID
].nTracks
= hdr
.cdth_trk1
;
90 return CDADev
[wDevID
].nTracks
;
97 /**************************************************************************
98 * CDAUDIO_GetTracksInfo [internal]
100 static BOOL
CDAUDIO_GetTracksInfo(UINT wDevID
)
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");
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
;
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");
141 start
= CDFRAMES_PERSEC
* (SECONDS_PERMIN
*
142 entry
.cdte_addr
.msf
.minute
+ entry
.cdte_addr
.msf
.second
) +
143 entry
.cdte_addr
.msf
.frame
;
146 CDADev
[wDevID
].dwFirstOffset
= start
;
147 dprintf_cdaudio(stddeb
,
148 "CDAUDIO_GetTracksInfo // dwFirstOffset=%u\n",
152 length
= start
- last_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",
163 CDADev
[wDevID
].dwTotalLen
= total_length
;
164 dprintf_cdaudio(stddeb
,"CDAUDIO_GetTracksInfo // total_len=%u\n",
174 /**************************************************************************
175 * CDAUDIO_mciOpen [internal]
177 static DWORD
CDAUDIO_mciOpen(UINT wDevID
, DWORD dwFlags
, LPMCI_OPEN_PARMS lpParms
)
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
;
191 return MCIERR_MUST_USE_SHAREABLE
;
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
);
229 return MCIERR_HARDWARE
;
233 /**************************************************************************
234 * CDAUDIO_mciClose [internal]
236 static DWORD
CDAUDIO_mciClose(UINT wDevID
, DWORD dwParam
, LPMCI_GENERIC_PARMS lpParms
)
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
);
248 /**************************************************************************
249 * CDAUDIO_mciGetDevCaps [internal]
251 static DWORD
CDAUDIO_mciGetDevCaps(UINT wDevID
, DWORD dwFlags
,
252 LPMCI_GETDEVCAPS_PARMS lpParms
)
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",
262 switch(lpParms
->dwItem
) {
263 case MCI_GETDEVCAPS_CAN_RECORD
:
264 lpParms
->dwReturn
= FALSE
;
266 case MCI_GETDEVCAPS_HAS_AUDIO
:
267 lpParms
->dwReturn
= TRUE
;
269 case MCI_GETDEVCAPS_HAS_VIDEO
:
270 lpParms
->dwReturn
= FALSE
;
272 case MCI_GETDEVCAPS_DEVICE_TYPE
:
273 lpParms
->dwReturn
= MCI_DEVTYPE_CD_AUDIO
;
275 case MCI_GETDEVCAPS_USES_FILES
:
276 lpParms
->dwReturn
= FALSE
;
278 case MCI_GETDEVCAPS_COMPOUND_DEVICE
:
279 lpParms
->dwReturn
= FALSE
;
281 case MCI_GETDEVCAPS_CAN_EJECT
:
282 lpParms
->dwReturn
= TRUE
;
284 case MCI_GETDEVCAPS_CAN_PLAY
:
285 lpParms
->dwReturn
= TRUE
;
287 case MCI_GETDEVCAPS_CAN_SAVE
:
288 lpParms
->dwReturn
= FALSE
;
291 return MCIERR_UNRECOGNIZED_COMMAND
;
294 dprintf_cdaudio(stddeb
,
295 "CDAUDIO_mciGetDevCaps // lpParms->dwReturn=%08lX;\n",
299 return MCIERR_INTERNAL
;
303 /**************************************************************************
304 * CDAUDIO_mciInfo [internal]
306 static DWORD
CDAUDIO_mciInfo(UINT wDevID
, DWORD dwFlags
, LPMCI_INFO_PARMS lpParms
)
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
;
314 case MCI_INFO_PRODUCT
:
315 lpParms
->lpstrReturn
= "Linux CDROM 0.5";
318 return MCIERR_UNRECOGNIZED_COMMAND
;
320 if (lpParms
->lpstrReturn
!= NULL
)
321 lpParms
->dwRetSize
= strlen(lpParms
->lpstrReturn
);
323 lpParms
->dwRetSize
= 0;
326 return MCIERR_INTERNAL
;
331 /**************************************************************************
332 * CDAUDIO_CalcFrame [internal]
334 static DWORD
CDAUDIO_CalcFrame(UINT wDevID
, DWORD dwFormatType
, DWORD dwTime
)
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",
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
);
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
);
382 /**************************************************************************
383 * CDAUDIO_GetCDStatus [internal]
385 static BOOL
CDAUDIO_GetCDStatus(UINT wDevID
)
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
;
395 switch (CDADev
[wDevID
].sc
.cdsc_audiostatus
) {
396 case CDROM_AUDIO_INVALID
:
397 dprintf_cdaudio(stddeb
,"CDAUDIO_GetCDStatus // device doesn't support status !\n");
399 case CDROM_AUDIO_NO_STATUS
:
400 CDADev
[wDevID
].mode
= MCI_MODE_STOP
;
401 dprintf_cdaudio(stddeb
,"CDAUDIO_GetCDStatus // MCI_MODE_STOP !\n");
403 case CDROM_AUDIO_PLAY
:
404 CDADev
[wDevID
].mode
= MCI_MODE_PLAY
;
405 dprintf_cdaudio(stddeb
,"CDAUDIO_GetCDStatus // MCI_MODE_PLAY !\n");
407 case CDROM_AUDIO_PAUSED
:
408 CDADev
[wDevID
].mode
= MCI_MODE_PAUSE
;
409 dprintf_cdaudio(stddeb
,"CDAUDIO_GetCDStatus // MCI_MODE_PAUSE !\n");
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
;
438 /**************************************************************************
439 * CDAUDIO_CalcTime [internal]
441 static DWORD
CDAUDIO_CalcTime(UINT wDevID
, DWORD dwFormatType
, DWORD dwFrame
)
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",
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
);
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
);
493 /**************************************************************************
494 * CDAUDIO_mciStatus [internal]
496 static DWORD
CDAUDIO_mciStatus(UINT wDevID
, DWORD dwFlags
, LPMCI_STATUS_PARMS lpParms
)
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
);
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",
527 if (lpParms
->dwTrack
> CDADev
[wDevID
].nTracks
)
528 return MCIERR_OUTOFRANGE
;
529 lpParms
->dwReturn
= CDADev
[wDevID
].lpdwTrackLen
[lpParms
->dwTrack
];
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
);
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",
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");
548 dprintf_cdaudio(stddeb
,"CDAUDIO_mciStatus // MCI_STATUS_MEDIA_PRESENT !\n");
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",
554 if (lpParms
->dwReturn
== (WORD
)-1) return MCIERR_INTERNAL
;
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",
574 case MCI_STATUS_READY
:
575 dprintf_cdaudio(stddeb
,"CDAUDIO_mciStatus // MCI_STATUS_READY !\n");
576 lpParms
->dwReturn
= TRUE
;
578 case MCI_STATUS_TIME_FORMAT
:
579 dprintf_cdaudio(stddeb
,"CDAUDIO_mciStatus // MCI_STATUS_TIME_FORMAT !\n");
580 lpParms
->dwReturn
= CDADev
[wDevID
].dwTimeFormat
;
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");
590 return MMSYSERR_NOTENABLED
;
595 /**************************************************************************
596 * CDAUDIO_mciPlay [internal]
598 static DWORD
CDAUDIO_mciPlay(UINT wDevID
, DWORD dwFlags
, LPMCI_PLAY_PARMS lpParms
)
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",
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);
653 return MCIERR_HARDWARE
;
657 /**************************************************************************
658 * CDAUDIO_mciStop [internal]
660 static DWORD
CDAUDIO_mciStop(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
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
);
677 return MCIERR_HARDWARE
;
681 /**************************************************************************
682 * CDAUDIO_mciPause [internal]
684 static DWORD
CDAUDIO_mciPause(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
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
);
701 return MCIERR_HARDWARE
;
705 /**************************************************************************
706 * CDAUDIO_mciResume [internal]
708 static DWORD
CDAUDIO_mciResume(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
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
);
725 return MCIERR_HARDWARE
;
729 /**************************************************************************
730 * CDAUDIO_mciSeek [internal]
732 static DWORD
CDAUDIO_mciSeek(UINT wDevID
, DWORD dwFlags
, LPMCI_SEEK_PARMS lpParms
)
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
;
743 case MCI_SEEK_TO_START
:
744 PlayParms
.dwFrom
= 0;
746 case MCI_SEEK_TO_END
:
747 PlayParms
.dwFrom
= CDADev
[wDevID
].dwTotalLen
;
750 PlayParms
.dwFrom
= lpParms
->dwTo
;
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
);
765 return MCIERR_HARDWARE
;
770 /**************************************************************************
771 * CDAUDIO_mciSet [internal]
773 static DWORD
CDAUDIO_mciSet(UINT wDevID
, DWORD dwFlags
, LPMCI_SET_PARMS lpParms
)
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");
790 dprintf_cdaudio(stddeb
,"CDAUDIO_mciSet // MCI_FORMAT_MSF !\n");
792 case MCI_FORMAT_TMSF
:
793 dprintf_cdaudio(stddeb
,"CDAUDIO_mciSet // MCI_FORMAT_TMSF !\n");
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
);
825 return MCIERR_HARDWARE
;
830 /**************************************************************************
831 * CDAUDIO_DriverProc [sample driver]
833 LONG
CDAUDIO_DriverProc(DWORD dwDevID
, HDRVR hDriv
, WORD wMsg
,
834 DWORD dwParam1
, DWORD dwParam2
)
843 case MCI_OPEN_DRIVER
:
845 return CDAUDIO_mciOpen(dwDevID
, dwParam1
, (LPMCI_OPEN_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
847 case MCI_CLOSE_DRIVER
:
849 return CDAUDIO_mciClose(dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
854 case DRV_QUERYCONFIGURE
:
857 MessageBox((HWND
)NULL
, "Sample MultiMedia Linux Driver !",
858 "MMLinux Driver", MB_OK
);
861 return DRVCNF_RESTART
;
863 return DRVCNF_RESTART
;
865 return CDAUDIO_mciGetDevCaps(dwDevID
, dwParam1
,
866 (LPMCI_GETDEVCAPS_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
868 return CDAUDIO_mciInfo(dwDevID
, dwParam1
,
869 (LPMCI_INFO_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
871 return CDAUDIO_mciStatus(dwDevID
, dwParam1
,
872 (LPMCI_STATUS_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
874 return CDAUDIO_mciSet(dwDevID
, dwParam1
,
875 (LPMCI_SET_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
877 return CDAUDIO_mciPlay(dwDevID
, dwParam1
,
878 (LPMCI_PLAY_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
880 return CDAUDIO_mciStop(dwDevID
, dwParam1
,
881 (LPMCI_GENERIC_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
883 return CDAUDIO_mciPause(dwDevID
, dwParam1
,
884 (LPMCI_GENERIC_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
886 return CDAUDIO_mciResume(dwDevID
, dwParam1
,
887 (LPMCI_GENERIC_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
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;
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;
903 return DefDriverProc(dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);
906 return MCIERR_HARDWARE
;
911 /*-----------------------------------------------------------------------*/
913 #endif /* #ifdef BUILTIN_MMSYSTEM */