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, returning NOT_READY.\n");
398 CDADev
[wDevID
].mode
= MCI_MODE_NOT_READY
;
400 case CDROM_AUDIO_NO_STATUS
:
401 CDADev
[wDevID
].mode
= MCI_MODE_STOP
;
402 dprintf_cdaudio(stddeb
,"CDAUDIO_GetCDStatus // MCI_MODE_STOP !\n");
404 case CDROM_AUDIO_PLAY
:
405 CDADev
[wDevID
].mode
= MCI_MODE_PLAY
;
406 dprintf_cdaudio(stddeb
,"CDAUDIO_GetCDStatus // MCI_MODE_PLAY !\n");
408 case CDROM_AUDIO_PAUSED
:
409 CDADev
[wDevID
].mode
= MCI_MODE_PAUSE
;
410 dprintf_cdaudio(stddeb
,"CDAUDIO_GetCDStatus // MCI_MODE_PAUSE !\n");
413 dprintf_cdaudio(stddeb
,"CDAUDIO_GetCDStatus // status=%02X !\n",
414 CDADev
[wDevID
].sc
.cdsc_audiostatus
);
416 CDADev
[wDevID
].nCurTrack
= CDADev
[wDevID
].sc
.cdsc_trk
;
417 CDADev
[wDevID
].dwCurFrame
=
418 CDFRAMES_PERMIN
* CDADev
[wDevID
].sc
.cdsc_absaddr
.msf
.minute
+
419 CDFRAMES_PERSEC
* CDADev
[wDevID
].sc
.cdsc_absaddr
.msf
.second
+
420 CDADev
[wDevID
].sc
.cdsc_absaddr
.msf
.frame
;
421 dprintf_cdaudio(stddeb
,"CDAUDIO_GetCDStatus // %02u-%02u:%02u:%02u \n",
422 CDADev
[wDevID
].sc
.cdsc_trk
,
423 CDADev
[wDevID
].sc
.cdsc_absaddr
.msf
.minute
,
424 CDADev
[wDevID
].sc
.cdsc_absaddr
.msf
.second
,
425 CDADev
[wDevID
].sc
.cdsc_absaddr
.msf
.frame
);
426 if (oldmode
!= CDADev
[wDevID
].mode
&& oldmode
== MCI_MODE_OPEN
) {
427 if (!CDAUDIO_GetTracksInfo(wDevID
)) {
428 dprintf_cdaudio(stddeb
,"CDAUDIO_GetCDStatus // error updating TracksInfo !\n");
429 return MCIERR_INTERNAL
;
439 /**************************************************************************
440 * CDAUDIO_CalcTime [internal]
442 static DWORD
CDAUDIO_CalcTime(UINT wDevID
, DWORD dwFormatType
, DWORD dwFrame
)
450 dprintf_cdaudio(stddeb
,"CDAUDIO_CalcTime(%u, %08lX, %lu);\n",
451 wDevID
, dwFormatType
, dwFrame
);
453 switch (dwFormatType
) {
454 case MCI_FORMAT_MILLISECONDS
:
455 dwTime
= dwFrame
/ CDFRAMES_PERSEC
* 1000;
456 dprintf_cdaudio(stddeb
,
457 "CDAUDIO_CalcTime // MILLISECONDS %lu\n",
461 wMinutes
= dwFrame
/ CDFRAMES_PERMIN
;
462 wSeconds
= (dwFrame
- CDFRAMES_PERMIN
* wMinutes
) / CDFRAMES_PERSEC
;
463 wFrames
= dwFrame
- CDFRAMES_PERMIN
* wMinutes
-
464 CDFRAMES_PERSEC
* wSeconds
;
465 dwTime
= MCI_MAKE_MSF(wMinutes
, wSeconds
, wFrames
);
466 dprintf_cdaudio(stddeb
,"CDAUDIO_CalcTime // MSF %02u:%02u:%02u -> dwTime=%lu\n",
467 wMinutes
, wSeconds
, wFrames
, dwTime
);
470 /* unknown format ! force TMSF ! ... */
471 dwFormatType
= MCI_FORMAT_TMSF
;
472 case MCI_FORMAT_TMSF
:
473 for (wTrack
= 0; wTrack
< CDADev
[wDevID
].nTracks
; wTrack
++) {
474 /* dwTime += CDADev[wDevID].lpdwTrackLen[wTrack - 1];
475 printf("Adding trk#%u curpos=%u \n", dwTime);
476 if (dwTime >= dwFrame) break; */
477 if (CDADev
[wDevID
].lpdwTrackPos
[wTrack
- 1] >= dwFrame
) break;
479 wMinutes
= dwFrame
/ CDFRAMES_PERMIN
;
480 wSeconds
= (dwFrame
- CDFRAMES_PERMIN
* wMinutes
) / CDFRAMES_PERSEC
;
481 wFrames
= dwFrame
- CDFRAMES_PERMIN
* wMinutes
-
482 CDFRAMES_PERSEC
* wSeconds
;
483 dwTime
= MCI_MAKE_TMSF(wTrack
, wMinutes
, wSeconds
, wFrames
);
484 dprintf_cdaudio(stddeb
,
485 "CDAUDIO_CalcTime // %02u-%02u:%02u:%02u\n",
486 wTrack
, wMinutes
, wSeconds
, wFrames
);
494 /**************************************************************************
495 * CDAUDIO_mciStatus [internal]
497 static DWORD
CDAUDIO_mciStatus(UINT wDevID
, DWORD dwFlags
, LPMCI_STATUS_PARMS lpParms
)
500 dprintf_cdaudio(stddeb
,"CDAUDIO_mciStatus(%u, %08lX, %p);\n",
501 wDevID
, dwFlags
, lpParms
);
502 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
503 if (CDADev
[wDevID
].unixdev
== 0) return MMSYSERR_NOTENABLED
;
504 if (dwFlags
& MCI_NOTIFY
) {
505 dprintf_cdaudio(stddeb
,
506 "CDAUDIO_mciStatus // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
507 lpParms
->dwCallback
);
508 mciDriverNotify((HWND
)LOWORD(lpParms
->dwCallback
),
509 CDADev
[wDevID
].wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
511 if (dwFlags
& MCI_STATUS_ITEM
) {
512 switch(lpParms
->dwItem
) {
513 case MCI_STATUS_CURRENT_TRACK
:
514 if (!CDAUDIO_GetCDStatus(wDevID
)) return MCIERR_INTERNAL
;
515 lpParms
->dwReturn
= CDADev
[wDevID
].nCurTrack
;
516 dprintf_cdaudio(stddeb
,"CDAUDIO_mciStatus // CURRENT_TRACK=%lu!\n", lpParms
->dwReturn
);
518 case MCI_STATUS_LENGTH
:
519 if (CDADev
[wDevID
].nTracks
== 0) {
520 if (!CDAUDIO_GetTracksInfo(wDevID
)) {
521 dprintf_cdaudio(stddeb
,"CDAUDIO_mciStatus // error reading TracksInfo !\n");
522 return MCIERR_INTERNAL
;
525 if (dwFlags
& MCI_TRACK
) {
526 dprintf_cdaudio(stddeb
,"CDAUDIO_mciStatus // MCI_TRACK #%lu LENGTH=??? !\n",
528 if (lpParms
->dwTrack
> CDADev
[wDevID
].nTracks
)
529 return MCIERR_OUTOFRANGE
;
530 lpParms
->dwReturn
= CDADev
[wDevID
].lpdwTrackLen
[lpParms
->dwTrack
];
533 lpParms
->dwReturn
= CDADev
[wDevID
].dwTotalLen
;
534 lpParms
->dwReturn
= CDAUDIO_CalcTime(wDevID
,
535 CDADev
[wDevID
].dwTimeFormat
, lpParms
->dwReturn
);
536 dprintf_cdaudio(stddeb
,"CDAUDIO_mciStatus // LENGTH=%lu !\n", lpParms
->dwReturn
);
538 case MCI_STATUS_MODE
:
539 if (!CDAUDIO_GetCDStatus(wDevID
)) return MCIERR_INTERNAL
;
540 lpParms
->dwReturn
= CDADev
[wDevID
].mode
;
541 dprintf_cdaudio(stddeb
,"CDAUDIO_mciStatus // MCI_STATUS_MODE=%08lX !\n",
544 case MCI_STATUS_MEDIA_PRESENT
:
545 lpParms
->dwReturn
= (CDADev
[wDevID
].nTracks
> 0) ? TRUE
: FALSE
;
546 if (lpParms
->dwReturn
== FALSE
)
547 dprintf_cdaudio(stddeb
,"CDAUDIO_mciStatus // MEDIA_NOT_PRESENT !\n");
549 dprintf_cdaudio(stddeb
,"CDAUDIO_mciStatus // MCI_STATUS_MEDIA_PRESENT !\n");
551 case MCI_STATUS_NUMBER_OF_TRACKS
:
552 lpParms
->dwReturn
= CDAUDIO_GetNumberOfTracks(wDevID
);
553 dprintf_cdaudio(stddeb
,"CDAUDIO_mciStatus // MCI_STATUS_NUMBER_OF_TRACKS = %lu !\n",
555 if (lpParms
->dwReturn
== (WORD
)-1) return MCIERR_INTERNAL
;
557 case MCI_STATUS_POSITION
:
558 if (!CDAUDIO_GetCDStatus(wDevID
)) return MCIERR_INTERNAL
;
559 lpParms
->dwReturn
= CDADev
[wDevID
].dwCurFrame
;
560 if (dwFlags
& MCI_STATUS_START
) {
561 lpParms
->dwReturn
= CDADev
[wDevID
].dwFirstOffset
;
562 dprintf_cdaudio(stddeb
,"CDAUDIO_mciStatus // get MCI_STATUS_START !\n");
564 if (dwFlags
& MCI_TRACK
) {
565 if (lpParms
->dwTrack
> CDADev
[wDevID
].nTracks
)
566 return MCIERR_OUTOFRANGE
;
567 lpParms
->dwReturn
= CDADev
[wDevID
].lpdwTrackPos
[lpParms
->dwTrack
- 1];
568 dprintf_cdaudio(stddeb
,"CDAUDIO_mciStatus // get MCI_TRACK #%lu !\n", lpParms
->dwTrack
);
570 lpParms
->dwReturn
= CDAUDIO_CalcTime(wDevID
,
571 CDADev
[wDevID
].dwTimeFormat
, lpParms
->dwReturn
);
572 dprintf_cdaudio(stddeb
,"CDAUDIO_mciStatus // MCI_STATUS_POSITION=%08lX !\n",
575 case MCI_STATUS_READY
:
576 dprintf_cdaudio(stddeb
,"CDAUDIO_mciStatus // MCI_STATUS_READY !\n");
577 lpParms
->dwReturn
= TRUE
;
579 case MCI_STATUS_TIME_FORMAT
:
580 dprintf_cdaudio(stddeb
,"CDAUDIO_mciStatus // MCI_STATUS_TIME_FORMAT !\n");
581 lpParms
->dwReturn
= CDADev
[wDevID
].dwTimeFormat
;
584 dprintf_cdaudio(stddeb
,"CDAUDIO_mciStatus // unknown command %08lX !\n", lpParms
->dwItem
);
585 return MCIERR_UNRECOGNIZED_COMMAND
;
588 dprintf_cdaudio(stddeb
,"CDAUDIO_mciStatus // not MCI_STATUS_ITEM !\n");
591 return MMSYSERR_NOTENABLED
;
596 /**************************************************************************
597 * CDAUDIO_mciPlay [internal]
599 static DWORD
CDAUDIO_mciPlay(UINT wDevID
, DWORD dwFlags
, LPMCI_PLAY_PARMS lpParms
)
603 struct cdrom_msf msf
;
604 dprintf_cdaudio(stddeb
,"CDAUDIO_mciPlay(%u, %08lX, %p);\n",
605 wDevID
, dwFlags
, lpParms
);
606 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
607 if (CDADev
[wDevID
].unixdev
== 0) return MMSYSERR_NOTENABLED
;
608 start
= 0; end
= CDADev
[wDevID
].dwTotalLen
;
609 CDADev
[wDevID
].nCurTrack
= 1;
610 if (dwFlags
& MCI_FROM
) {
611 start
= CDAUDIO_CalcFrame(wDevID
,
612 CDADev
[wDevID
].dwTimeFormat
, lpParms
->dwFrom
);
613 dprintf_cdaudio(stddeb
,"CDAUDIO_mciPlay // MCI_FROM=%08lX -> %u \n",
614 lpParms
->dwFrom
, start
);
616 if (dwFlags
& MCI_TO
) {
617 end
= CDAUDIO_CalcFrame(wDevID
,
618 CDADev
[wDevID
].dwTimeFormat
, lpParms
->dwTo
);
619 dprintf_cdaudio(stddeb
,
620 "CDAUDIO_mciPlay // MCI_TO=%08lX -> %u \n",
623 start
+= CDADev
[wDevID
].dwFirstOffset
;
624 end
+= CDADev
[wDevID
].dwFirstOffset
;
625 msf
.cdmsf_min0
= start
/ CDFRAMES_PERMIN
;
626 msf
.cdmsf_sec0
= (start
% CDFRAMES_PERMIN
) / CDFRAMES_PERSEC
;
627 msf
.cdmsf_frame0
= start
% CDFRAMES_PERSEC
;
628 msf
.cdmsf_min1
= end
/ CDFRAMES_PERMIN
;
629 msf
.cdmsf_sec1
= (end
% CDFRAMES_PERMIN
) / CDFRAMES_PERSEC
;
630 msf
.cdmsf_frame1
= end
% CDFRAMES_PERSEC
;
631 if (ioctl(CDADev
[wDevID
].unixdev
, CDROMSTART
)) {
632 dprintf_cdaudio(stddeb
,"CDAUDIO_mciPlay // motor doesn't start !\n");
633 return MCIERR_HARDWARE
;
635 if (ioctl(CDADev
[wDevID
].unixdev
, CDROMPLAYMSF
, &msf
)) {
636 dprintf_cdaudio(stddeb
,"CDAUDIO_mciPlay // device doesn't play !\n");
637 return MCIERR_HARDWARE
;
639 dprintf_cdaudio(stddeb
,"CDAUDIO_mciPlay // msf = %d:%d:%d %d:%d:%d\n",
640 msf
.cdmsf_min0
, msf
.cdmsf_sec0
, msf
.cdmsf_frame0
,
641 msf
.cdmsf_min1
, msf
.cdmsf_sec1
, msf
.cdmsf_frame1
);
642 CDADev
[wDevID
].mode
= MCI_MODE_PLAY
;
643 if (dwFlags
& MCI_NOTIFY
) {
644 dprintf_cdaudio(stddeb
,
645 "CDAUDIO_mciPlay // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
646 lpParms
->dwCallback
);
648 mciDriverNotify((HWND)LOWORD(lpParms->dwCallback),
649 CDADev[wDevID].wNotifyDeviceID, MCI_NOTIFY_SUCCESSFUL);
654 return MCIERR_HARDWARE
;
658 /**************************************************************************
659 * CDAUDIO_mciStop [internal]
661 static DWORD
CDAUDIO_mciStop(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
664 dprintf_cdaudio(stddeb
,"CDAUDIO_mciStop(%u, %08lX, %p);\n",
665 wDevID
, dwFlags
, lpParms
);
666 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
667 if (ioctl(CDADev
[wDevID
].unixdev
, CDROMSTOP
)) return MCIERR_HARDWARE
;
668 CDADev
[wDevID
].mode
= MCI_MODE_STOP
;
669 if (dwFlags
& MCI_NOTIFY
) {
670 dprintf_cdaudio(stddeb
,
671 "CDAUDIO_mciStop // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
672 lpParms
->dwCallback
);
673 mciDriverNotify((HWND
)LOWORD(lpParms
->dwCallback
),
674 CDADev
[wDevID
].wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
678 return MCIERR_HARDWARE
;
682 /**************************************************************************
683 * CDAUDIO_mciPause [internal]
685 static DWORD
CDAUDIO_mciPause(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
688 dprintf_cdaudio(stddeb
,"CDAUDIO_mciPause(%u, %08lX, %p);\n",
689 wDevID
, dwFlags
, lpParms
);
690 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
691 if (ioctl(CDADev
[wDevID
].unixdev
, CDROMPAUSE
)) return MCIERR_HARDWARE
;
692 CDADev
[wDevID
].mode
= MCI_MODE_PAUSE
;
693 if (dwFlags
& MCI_NOTIFY
) {
694 dprintf_cdaudio(stddeb
,
695 "CDAUDIO_mciPause // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
696 lpParms
->dwCallback
);
697 mciDriverNotify((HWND
)LOWORD(lpParms
->dwCallback
),
698 CDADev
[wDevID
].wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
702 return MCIERR_HARDWARE
;
706 /**************************************************************************
707 * CDAUDIO_mciResume [internal]
709 static DWORD
CDAUDIO_mciResume(UINT wDevID
, DWORD dwFlags
, LPMCI_GENERIC_PARMS lpParms
)
712 dprintf_cdaudio(stddeb
,"CDAUDIO_mciResume(%u, %08lX, %p);\n",
713 wDevID
, dwFlags
, lpParms
);
714 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
715 if (ioctl(CDADev
[wDevID
].unixdev
, CDROMRESUME
)) return MCIERR_HARDWARE
;
716 CDADev
[wDevID
].mode
= MCI_MODE_STOP
;
717 if (dwFlags
& MCI_NOTIFY
) {
718 dprintf_cdaudio(stddeb
,
719 "CDAUDIO_mciResume // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
720 lpParms
->dwCallback
);
721 mciDriverNotify((HWND
)LOWORD(lpParms
->dwCallback
),
722 CDADev
[wDevID
].wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
726 return MCIERR_HARDWARE
;
730 /**************************************************************************
731 * CDAUDIO_mciSeek [internal]
733 static DWORD
CDAUDIO_mciSeek(UINT wDevID
, DWORD dwFlags
, LPMCI_SEEK_PARMS lpParms
)
737 MCI_PLAY_PARMS PlayParms
;
738 dprintf_cdaudio(stddeb
,"CDAUDIO_mciSeek(%u, %08lX, %p);\n",
739 wDevID
, dwFlags
, lpParms
);
740 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
741 if (ioctl(CDADev
[wDevID
].unixdev
, CDROMRESUME
)) {
742 perror("ioctl CDROMRESUME");
743 return MCIERR_HARDWARE
;
745 CDADev
[wDevID
].mode
= MCI_MODE_SEEK
;
747 case MCI_SEEK_TO_START
:
748 PlayParms
.dwFrom
= 0;
750 case MCI_SEEK_TO_END
:
751 PlayParms
.dwFrom
= CDADev
[wDevID
].dwTotalLen
;
754 PlayParms
.dwFrom
= lpParms
->dwTo
;
757 dwRet
= CDAUDIO_mciPlay(wDevID
, MCI_WAIT
| MCI_FROM
, &PlayParms
);
758 if (dwRet
!= 0) return dwRet
;
759 dwRet
= CDAUDIO_mciStop(wDevID
, MCI_WAIT
, (LPMCI_GENERIC_PARMS
)&PlayParms
);
760 if (dwFlags
& MCI_NOTIFY
) {
761 dprintf_cdaudio(stddeb
,
762 "CDAUDIO_mciSeek // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
763 lpParms
->dwCallback
);
764 mciDriverNotify((HWND
)LOWORD(lpParms
->dwCallback
),
765 CDADev
[wDevID
].wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
769 return MCIERR_HARDWARE
;
774 /**************************************************************************
775 * CDAUDIO_mciSet [internal]
777 static DWORD
CDAUDIO_mciSet(UINT wDevID
, DWORD dwFlags
, LPMCI_SET_PARMS lpParms
)
780 dprintf_cdaudio(stddeb
,"CDAUDIO_mciSet(%u, %08lX, %p);\n",
781 wDevID
, dwFlags
, lpParms
);
782 if (lpParms
== NULL
) return MCIERR_INTERNAL
;
784 printf("CDAUDIO_mciSet // dwTimeFormat=%08lX\n", lpParms->dwTimeFormat);
785 printf("CDAUDIO_mciSet // dwAudio=%08lX\n", lpParms->dwAudio);
787 if (dwFlags
& MCI_SET_TIME_FORMAT
) {
788 switch (lpParms
->dwTimeFormat
) {
789 case MCI_FORMAT_MILLISECONDS
:
790 dprintf_cdaudio(stddeb
,
791 "CDAUDIO_mciSet // MCI_FORMAT_MILLISECONDS !\n");
794 dprintf_cdaudio(stddeb
,"CDAUDIO_mciSet // MCI_FORMAT_MSF !\n");
796 case MCI_FORMAT_TMSF
:
797 dprintf_cdaudio(stddeb
,"CDAUDIO_mciSet // MCI_FORMAT_TMSF !\n");
800 dprintf_cdaudio(stddeb
,"CDAUDIO_mciSet // bad time format !\n");
801 return MCIERR_BAD_TIME_FORMAT
;
803 CDADev
[wDevID
].dwTimeFormat
= lpParms
->dwTimeFormat
;
805 if (dwFlags
& MCI_SET_DOOR_OPEN
) {
806 dprintf_cdaudio(stddeb
,
807 "CDAUDIO_mciSet // MCI_SET_DOOR_OPEN !\n");
808 if (ioctl(CDADev
[wDevID
].unixdev
, CDROMEJECT
)) return MCIERR_HARDWARE
;
809 CDADev
[wDevID
].nTracks
= 0;
811 if (dwFlags
& MCI_SET_DOOR_CLOSED
) {
812 dprintf_cdaudio(stddeb
,
813 "CDAUDIO_mciSet // MCI_SET_DOOR_CLOSED !\n");
814 if (ioctl(CDADev
[wDevID
].unixdev
, CDROMEJECT
)) return MCIERR_HARDWARE
;
815 CDADev
[wDevID
].nTracks
= 0;
817 if (dwFlags
& MCI_SET_VIDEO
) return MCIERR_UNSUPPORTED_FUNCTION
;
818 if (dwFlags
& MCI_SET_ON
) return MCIERR_UNSUPPORTED_FUNCTION
;
819 if (dwFlags
& MCI_SET_OFF
) return MCIERR_UNSUPPORTED_FUNCTION
;
820 if (dwFlags
& MCI_NOTIFY
) {
821 dprintf_cdaudio(stddeb
,
822 "CDAUDIO_mciSet // MCI_NOTIFY_SUCCESSFUL %08lX !\n",
823 lpParms
->dwCallback
);
824 mciDriverNotify((HWND
)LOWORD(lpParms
->dwCallback
),
825 CDADev
[wDevID
].wNotifyDeviceID
, MCI_NOTIFY_SUCCESSFUL
);
829 return MCIERR_HARDWARE
;
834 /**************************************************************************
835 * CDAUDIO_DriverProc [sample driver]
837 LONG
CDAUDIO_DriverProc(DWORD dwDevID
, HDRVR16 hDriv
, WORD wMsg
,
838 DWORD dwParam1
, DWORD dwParam2
)
847 case MCI_OPEN_DRIVER
:
849 return CDAUDIO_mciOpen(dwDevID
, dwParam1
, (LPMCI_OPEN_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
851 case MCI_CLOSE_DRIVER
:
853 return CDAUDIO_mciClose(dwDevID
, dwParam1
, (LPMCI_GENERIC_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
858 case DRV_QUERYCONFIGURE
:
861 MessageBox((HWND
)NULL
, "Sample MultiMedia Linux Driver !",
862 "MMLinux Driver", MB_OK
);
865 return DRVCNF_RESTART
;
867 return DRVCNF_RESTART
;
869 return CDAUDIO_mciGetDevCaps(dwDevID
, dwParam1
,
870 (LPMCI_GETDEVCAPS_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
872 return CDAUDIO_mciInfo(dwDevID
, dwParam1
,
873 (LPMCI_INFO_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
875 return CDAUDIO_mciStatus(dwDevID
, dwParam1
,
876 (LPMCI_STATUS_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
878 return CDAUDIO_mciSet(dwDevID
, dwParam1
,
879 (LPMCI_SET_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
881 return CDAUDIO_mciPlay(dwDevID
, dwParam1
,
882 (LPMCI_PLAY_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
884 return CDAUDIO_mciStop(dwDevID
, dwParam1
,
885 (LPMCI_GENERIC_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
887 return CDAUDIO_mciPause(dwDevID
, dwParam1
,
888 (LPMCI_GENERIC_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
890 return CDAUDIO_mciResume(dwDevID
, dwParam1
,
891 (LPMCI_GENERIC_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
893 return CDAUDIO_mciSeek(dwDevID
, dwParam1
,
894 (LPMCI_SEEK_PARMS
)PTR_SEG_TO_LIN(dwParam2
));
895 case MCI_SET_DOOR_OPEN
:
896 dprintf_cdaudio(stddeb
,
897 "CDAUDIO_DriverProc // MCI_SET_DOOR_OPEN !\n");
898 if (ioctl(CDADev
[dwDevID
].unixdev
, CDROMEJECT
)) return MCIERR_HARDWARE
;
899 CDADev
[dwDevID
].nTracks
= 0;
901 case MCI_SET_DOOR_CLOSED
:
902 dprintf_cdaudio(stddeb
,"CDAUDIO_DriverProc // MCI_SET_DOOR_CLOSED !\n");
903 if (ioctl(CDADev
[dwDevID
].unixdev
, CDROMEJECT
, 1)) return MCIERR_HARDWARE
;
904 CDADev
[dwDevID
].nTracks
= 0;
907 return DefDriverProc(dwDevID
, hDriv
, wMsg
, dwParam1
, dwParam2
);
910 return MCIERR_HARDWARE
;
915 /*-----------------------------------------------------------------------*/
917 #endif /* #ifdef BUILTIN_MMSYSTEM */