mcicda: Use a helper to read the CD-ROM TOC.

Signed-off-by: Bruno Jesus <00cpxxx@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Bruno Jesus 2016-07-30 21:54:28 -03:00 committed by Alexandre Julliard
parent b9f552cbec
commit 9b13bb2296
1 changed files with 27 additions and 32 deletions

View File

@ -252,6 +252,18 @@ static void MCICDA_Notify(DWORD_PTR hWndCallBack, WINE_MCICDAUDIO* wmcda, UINT w
mciDriverNotify(HWND_32(LOWORD(hWndCallBack)), wDevID, wStatus); mciDriverNotify(HWND_32(LOWORD(hWndCallBack)), wDevID, wStatus);
} }
/**************************************************************************
* MCICDA_ReadTOC [internal]
*/
static BOOL MCICDA_ReadTOC(WINE_MCICDAUDIO* wmcda, CDROM_TOC *toc, DWORD *br)
{
if (!device_io(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0, toc, sizeof(*toc), br, NULL)) {
WARN("error reading TOC !\n");
return FALSE;
}
return TRUE;
}
/************************************************************************** /**************************************************************************
* MCICDA_GetStatus [internal] * MCICDA_GetStatus [internal]
*/ */
@ -722,11 +734,9 @@ static DWORD MCICDA_Status(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParm
TRACE("CURRENT_TRACK=%lu\n", lpParms->dwReturn); TRACE("CURRENT_TRACK=%lu\n", lpParms->dwReturn);
break; break;
case MCI_STATUS_LENGTH: case MCI_STATUS_LENGTH:
if (!device_io(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0, if (!MCICDA_ReadTOC(wmcda, &toc, &br))
&toc, sizeof(toc), &br, NULL)) {
WARN("error reading TOC !\n");
return MCICDA_GetError(wmcda); return MCICDA_GetError(wmcda);
}
if (dwFlags & MCI_TRACK) { if (dwFlags & MCI_TRACK) {
TRACE("MCI_TRACK #%u LENGTH=??? !\n", lpParms->dwTrack); TRACE("MCI_TRACK #%u LENGTH=??? !\n", lpParms->dwTrack);
if (lpParms->dwTrack < toc.FirstTrack || lpParms->dwTrack > toc.LastTrack) if (lpParms->dwTrack < toc.FirstTrack || lpParms->dwTrack > toc.LastTrack)
@ -764,11 +774,9 @@ static DWORD MCICDA_Status(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParm
ret = MCI_RESOURCE_RETURNED; ret = MCI_RESOURCE_RETURNED;
break; break;
case MCI_STATUS_NUMBER_OF_TRACKS: case MCI_STATUS_NUMBER_OF_TRACKS:
if (!device_io(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0, if (!MCICDA_ReadTOC(wmcda, &toc, &br))
&toc, sizeof(toc), &br, NULL)) {
WARN("error reading TOC !\n");
return MCICDA_GetError(wmcda); return MCICDA_GetError(wmcda);
}
lpParms->dwReturn = toc.LastTrack - toc.FirstTrack + 1; lpParms->dwReturn = toc.LastTrack - toc.FirstTrack + 1;
TRACE("MCI_STATUS_NUMBER_OF_TRACKS = %lu\n", lpParms->dwReturn); TRACE("MCI_STATUS_NUMBER_OF_TRACKS = %lu\n", lpParms->dwReturn);
if (lpParms->dwReturn == (WORD)-1) if (lpParms->dwReturn == (WORD)-1)
@ -777,20 +785,16 @@ static DWORD MCICDA_Status(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParm
case MCI_STATUS_POSITION: case MCI_STATUS_POSITION:
switch (dwFlags & (MCI_STATUS_START | MCI_TRACK)) { switch (dwFlags & (MCI_STATUS_START | MCI_TRACK)) {
case MCI_STATUS_START: case MCI_STATUS_START:
if (!device_io(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0, if (!MCICDA_ReadTOC(wmcda, &toc, &br))
&toc, sizeof(toc), &br, NULL)) {
WARN("error reading TOC !\n");
return MCICDA_GetError(wmcda); return MCICDA_GetError(wmcda);
}
lpParms->dwReturn = FRAME_OF_TOC(toc, toc.FirstTrack); lpParms->dwReturn = FRAME_OF_TOC(toc, toc.FirstTrack);
TRACE("get MCI_STATUS_START !\n"); TRACE("get MCI_STATUS_START !\n");
break; break;
case MCI_TRACK: case MCI_TRACK:
if (!device_io(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0, if (!MCICDA_ReadTOC(wmcda, &toc, &br))
&toc, sizeof(toc), &br, NULL)) {
WARN("error reading TOC !\n");
return MCICDA_GetError(wmcda); return MCICDA_GetError(wmcda);
}
if (lpParms->dwTrack < toc.FirstTrack || lpParms->dwTrack > toc.LastTrack) if (lpParms->dwTrack < toc.FirstTrack || lpParms->dwTrack > toc.LastTrack)
return MCIERR_OUTOFRANGE; return MCIERR_OUTOFRANGE;
lpParms->dwReturn = FRAME_OF_TOC(toc, lpParms->dwTrack); lpParms->dwReturn = FRAME_OF_TOC(toc, lpParms->dwTrack);
@ -835,11 +839,9 @@ static DWORD MCICDA_Status(UINT wDevID, DWORD dwFlags, LPMCI_STATUS_PARMS lpParm
if (!(dwFlags & MCI_TRACK)) if (!(dwFlags & MCI_TRACK))
ret = MCIERR_MISSING_PARAMETER; ret = MCIERR_MISSING_PARAMETER;
else { else {
if (!device_io(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0, if (!MCICDA_ReadTOC(wmcda, &toc, &br))
&toc, sizeof(toc), &br, NULL)) {
WARN("error reading TOC !\n");
return MCICDA_GetError(wmcda); return MCICDA_GetError(wmcda);
}
if (lpParms->dwTrack < toc.FirstTrack || lpParms->dwTrack > toc.LastTrack) if (lpParms->dwTrack < toc.FirstTrack || lpParms->dwTrack > toc.LastTrack)
ret = MCIERR_OUTOFRANGE; ret = MCIERR_OUTOFRANGE;
else else
@ -867,11 +869,9 @@ static DWORD MCICDA_SkipDataTracks(WINE_MCICDAUDIO* wmcda,DWORD *frame)
int i; int i;
DWORD br; DWORD br;
CDROM_TOC toc; CDROM_TOC toc;
if (!device_io(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0, if (!MCICDA_ReadTOC(wmcda, &toc, &br))
&toc, sizeof(toc), &br, NULL)) {
WARN("error reading TOC !\n");
return MCICDA_GetError(wmcda); return MCICDA_GetError(wmcda);
}
if (*frame < FRAME_OF_TOC(toc,toc.FirstTrack) || if (*frame < FRAME_OF_TOC(toc,toc.FirstTrack) ||
*frame >= FRAME_OF_TOC(toc,toc.LastTrack+1)) /* lead-out */ *frame >= FRAME_OF_TOC(toc,toc.LastTrack+1)) /* lead-out */
return MCIERR_OUTOFRANGE; return MCIERR_OUTOFRANGE;
@ -914,11 +914,8 @@ static DWORD MCICDA_Play(UINT wDevID, DWORD dwFlags, LPMCI_PLAY_PARMS lpParms)
if (wmcda == NULL) if (wmcda == NULL)
return MCIERR_INVALID_DEVICE_ID; return MCIERR_INVALID_DEVICE_ID;
if (!device_io(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0, if (!MCICDA_ReadTOC(wmcda, &toc, &br))
&toc, sizeof(toc), &br, NULL)) {
WARN("error reading TOC !\n");
return MCICDA_GetError(wmcda); return MCICDA_GetError(wmcda);
}
if (dwFlags & MCI_FROM) { if (dwFlags & MCI_FROM) {
start = MCICDA_CalcFrame(wmcda, lpParms->dwFrom); start = MCICDA_CalcFrame(wmcda, lpParms->dwFrom);
@ -1198,11 +1195,9 @@ static DWORD MCICDA_Seek(UINT wDevID, DWORD dwFlags, LPMCI_SEEK_PARMS lpParms)
* then only checks the position flags, then stops and seeks. */ * then only checks the position flags, then stops and seeks. */
MCICDA_Stop(wDevID, MCI_WAIT, 0); MCICDA_Stop(wDevID, MCI_WAIT, 0);
if (!device_io(wmcda->handle, IOCTL_CDROM_READ_TOC, NULL, 0, if (!MCICDA_ReadTOC(wmcda, &toc, &br))
&toc, sizeof(toc), &br, NULL)) {
WARN("error reading TOC !\n");
return MCICDA_GetError(wmcda); return MCICDA_GetError(wmcda);
}
switch (position) { switch (position) {
case MCI_SEEK_TO_START: case MCI_SEEK_TO_START:
TRACE("Seeking to start\n"); TRACE("Seeking to start\n");