winmm: Prevent some MIDI race conditions.
This commit is contained in:
parent
702fe6738b
commit
b0fc000ce1
|
@ -389,9 +389,9 @@ static DWORD WINAPI midRecThread(LPVOID arg)
|
|||
* to handle the case where ALSA split the sysex into several events */
|
||||
if ((lpMidiHdr->dwBytesRecorded == lpMidiHdr->dwBufferLength) ||
|
||||
(*(BYTE*)(lpMidiHdr->lpData + lpMidiHdr->dwBytesRecorded - 1) == 0xF7)) {
|
||||
MidiInDev[wDevID].lpQueueHdr = lpMidiHdr->lpNext;
|
||||
lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
|
||||
lpMidiHdr->dwFlags |= MHDR_DONE;
|
||||
MidiInDev[wDevID].lpQueueHdr = lpMidiHdr->lpNext;
|
||||
MIDI_NotifyClient(wDevID, MIM_LONGDATA, (DWORD_PTR)lpMidiHdr, dwTime);
|
||||
}
|
||||
} else {
|
||||
|
@ -478,6 +478,16 @@ static DWORD midOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags)
|
|||
return MMSYSERR_ERROR;
|
||||
}
|
||||
|
||||
MidiInDev[wDevID].wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
|
||||
|
||||
MidiInDev[wDevID].lpQueueHdr = NULL;
|
||||
MidiInDev[wDevID].dwTotalPlayed = 0;
|
||||
MidiInDev[wDevID].bufsize = 0x3FFF;
|
||||
MidiInDev[wDevID].midiDesc = *lpDesc;
|
||||
MidiInDev[wDevID].state = 0;
|
||||
MidiInDev[wDevID].incLen = 0;
|
||||
MidiInDev[wDevID].startTime = 0;
|
||||
|
||||
/* Connect our app port to the device port */
|
||||
if (snd_seq_connect_from(midiSeq, port_in, MidiInDev[wDevID].addr.client, MidiInDev[wDevID].addr.port) < 0)
|
||||
return MMSYSERR_NOTENABLED;
|
||||
|
@ -497,16 +507,6 @@ static DWORD midOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags)
|
|||
TRACE("Created thread for midi-in\n");
|
||||
}
|
||||
|
||||
MidiInDev[wDevID].wFlags = HIWORD(dwFlags & CALLBACK_TYPEMASK);
|
||||
|
||||
MidiInDev[wDevID].lpQueueHdr = NULL;
|
||||
MidiInDev[wDevID].dwTotalPlayed = 0;
|
||||
MidiInDev[wDevID].bufsize = 0x3FFF;
|
||||
MidiInDev[wDevID].midiDesc = *lpDesc;
|
||||
MidiInDev[wDevID].state = 0;
|
||||
MidiInDev[wDevID].incLen = 0;
|
||||
MidiInDev[wDevID].startTime = 0;
|
||||
|
||||
MIDI_NotifyClient(wDevID, MIM_OPEN, 0L, 0L);
|
||||
return MMSYSERR_NOERROR;
|
||||
}
|
||||
|
@ -644,12 +644,11 @@ static DWORD midReset(WORD wDevID)
|
|||
|
||||
EnterCriticalSection(&crit_sect);
|
||||
while (MidiInDev[wDevID].lpQueueHdr) {
|
||||
MidiInDev[wDevID].lpQueueHdr->dwFlags &= ~MHDR_INQUEUE;
|
||||
MidiInDev[wDevID].lpQueueHdr->dwFlags |= MHDR_DONE;
|
||||
/* FIXME: when called from 16 bit, lpQueueHdr needs to be a segmented ptr */
|
||||
MIDI_NotifyClient(wDevID, MIM_LONGDATA,
|
||||
(DWORD_PTR)MidiInDev[wDevID].lpQueueHdr, dwTime);
|
||||
MidiInDev[wDevID].lpQueueHdr = MidiInDev[wDevID].lpQueueHdr->lpNext;
|
||||
LPMIDIHDR lpMidiHdr = MidiInDev[wDevID].lpQueueHdr;
|
||||
MidiInDev[wDevID].lpQueueHdr = lpMidiHdr->lpNext;
|
||||
lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
|
||||
lpMidiHdr->dwFlags |= MHDR_DONE;
|
||||
MIDI_NotifyClient(wDevID, MIM_LONGDATA, (DWORD_PTR)lpMidiHdr, dwTime);
|
||||
}
|
||||
LeaveCriticalSection(&crit_sect);
|
||||
|
||||
|
@ -726,10 +725,6 @@ static DWORD modOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags)
|
|||
WARN("bad dwFlags\n");
|
||||
return MMSYSERR_INVALFLAG;
|
||||
}
|
||||
if (!MidiOutDev[wDevID].bEnabled) {
|
||||
TRACE("disabled wDevID\n");
|
||||
return MMSYSERR_NOTENABLED;
|
||||
}
|
||||
|
||||
MidiOutDev[wDevID].lpExtra = 0;
|
||||
|
||||
|
|
|
@ -563,9 +563,9 @@ static void midReceiveChar(WORD wDevID, unsigned char value, DWORD dwTime)
|
|||
}
|
||||
if (sbfb && lpMidiHdr != NULL) {
|
||||
lpMidiHdr = MidiInDev[wDevID].lpQueueHdr;
|
||||
MidiInDev[wDevID].lpQueueHdr = lpMidiHdr->lpNext;
|
||||
lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
|
||||
lpMidiHdr->dwFlags |= MHDR_DONE;
|
||||
MidiInDev[wDevID].lpQueueHdr = lpMidiHdr->lpNext;
|
||||
MIDI_NotifyClient(wDevID, MIM_LONGDATA, (DWORD_PTR)lpMidiHdr, dwTime);
|
||||
}
|
||||
LeaveCriticalSection(&crit_sect);
|
||||
|
@ -906,12 +906,11 @@ static DWORD midReset(WORD wDevID)
|
|||
|
||||
EnterCriticalSection(&crit_sect);
|
||||
while (MidiInDev[wDevID].lpQueueHdr) {
|
||||
MidiInDev[wDevID].lpQueueHdr->dwFlags &= ~MHDR_INQUEUE;
|
||||
MidiInDev[wDevID].lpQueueHdr->dwFlags |= MHDR_DONE;
|
||||
/* FIXME: when called from 16 bit, lpQueueHdr needs to be a segmented ptr */
|
||||
MIDI_NotifyClient(wDevID, MIM_LONGDATA,
|
||||
(DWORD_PTR)MidiInDev[wDevID].lpQueueHdr, dwTime);
|
||||
MidiInDev[wDevID].lpQueueHdr = MidiInDev[wDevID].lpQueueHdr->lpNext;
|
||||
LPMIDIHDR lpMidiHdr = MidiInDev[wDevID].lpQueueHdr;
|
||||
MidiInDev[wDevID].lpQueueHdr = lpMidiHdr->lpNext;
|
||||
lpMidiHdr->dwFlags &= ~MHDR_INQUEUE;
|
||||
lpMidiHdr->dwFlags |= MHDR_DONE;
|
||||
MIDI_NotifyClient(wDevID, MIM_LONGDATA, (DWORD_PTR)lpMidiHdr, dwTime);
|
||||
}
|
||||
LeaveCriticalSection(&crit_sect);
|
||||
|
||||
|
@ -1102,10 +1101,6 @@ static DWORD modOpen(WORD wDevID, LPMIDIOPENDESC lpDesc, DWORD dwFlags)
|
|||
WARN("bad dwFlags\n");
|
||||
return MMSYSERR_INVALFLAG;
|
||||
}
|
||||
if (!MidiOutDev[wDevID].bEnabled) {
|
||||
TRACE("disabled wDevID\n");
|
||||
return MMSYSERR_NOTENABLED;
|
||||
}
|
||||
|
||||
MidiOutDev[wDevID].lpExtra = 0;
|
||||
|
||||
|
|
Loading…
Reference in New Issue