winecoreaudio.drv: Only read 'length' bytes from received MIDIPackets.

The Core MIDI MIDIPacket struct is declared with a 256-byte data array,
but this is just for convenience. There may be only one accessible byte,
or there may be more than 256.
Only read 'length' bytes from the packet, and correctly handle a
length > 256.

Signed-off-by: Brendan Shanks <bshanks@codeweavers.com>
Signed-off-by: Andrew Eikum <aeikum@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Brendan Shanks 2020-10-28 17:29:13 -07:00 committed by Alexandre Julliard
parent da8079b3da
commit 1fc8a8f234
3 changed files with 18 additions and 15 deletions

View File

@ -57,15 +57,12 @@ void CoreMIDI_GetObjectName(MIDIObjectRef obj, char *name, int size)
void MIDIIn_ReadProc(const MIDIPacketList *pktlist, void *refCon, void *connRefCon)
{
unsigned int i;
MIDIMessage msg;
MIDIPacket *packet = (MIDIPacket *)pktlist->packet;
for (i = 0; i < pktlist->numPackets; ++i) {
msg.devID = *((UInt16 *)connRefCon);
msg.length = packet->length;
memcpy(msg.data, packet->data, sizeof(packet->data));
UInt16 devID = *((UInt16 *)connRefCon);
MIDIIn_SendMessage(msg);
MIDIIn_SendMessage(devID, packet->data, packet->length);
packet = MIDIPacketNext(packet);
}

View File

@ -65,12 +65,6 @@ extern int AudioUnit_SetVolume(AudioUnit au, float left, float right);
extern int AudioUnit_GetVolume(AudioUnit au, float *left, float *right);
#endif
typedef struct {
UInt16 devID;
UInt16 length;
Byte data[256];
} MIDIMessage;
/* coremidi.c */
extern MIDIClientRef CoreMIDI_CreateClient(CFStringRef name);
extern void CoreMIDI_GetObjectName(MIDIObjectRef obj, char *name, int size);
@ -79,6 +73,6 @@ extern void MIDIIn_ReadProc(const MIDIPacketList *pktlist, void *refCon, void *c
extern void MIDIOut_Send(MIDIPortRef port, MIDIEndpointRef dest, UInt8 *buffer, unsigned length);
/* midi.c */
void MIDIIn_SendMessage(MIDIMessage msg);
void MIDIIn_SendMessage(UInt16 devID, const void *buffer, UInt16 length);
#endif

View File

@ -78,6 +78,12 @@ typedef struct tagMIDISource {
DWORD startTime;
} MIDISource;
typedef struct {
UInt16 devID;
UInt16 length;
Byte data[];
} MIDIMessage;
static CRITICAL_SECTION midiInLock; /* Critical section for MIDI In */
static CFStringRef MIDIInThreadPortName = NULL;
@ -797,16 +803,22 @@ static DWORD MIDIIn_Reset(WORD wDevID)
* Call from CoreMIDI IO threaded callback,
* we can't call Wine debug channels, critical section or anything using NtCurrentTeb here.
*/
void MIDIIn_SendMessage(MIDIMessage msg)
void MIDIIn_SendMessage(UInt16 devID, const void *buffer, UInt16 length)
{
CFDataRef data;
MIDIMessage msg;
CFMutableDataRef data;
CFMessagePortRef messagePort;
messagePort = CFMessagePortCreateRemote(kCFAllocatorDefault, MIDIInThreadPortName);
data = CFDataCreate(kCFAllocatorDefault, (UInt8 *) &msg, sizeof(msg));
msg.devID = devID;
msg.length = length;
data = CFDataCreateMutable(kCFAllocatorDefault, sizeof(msg) + length);
if (data)
{
CFDataAppendBytes(data, (UInt8 *) &msg, sizeof(msg));
CFDataAppendBytes(data, buffer, length);
CFMessagePortSendRequest(messagePort, 0, data, 0.0, 0.0, NULL, NULL);
CFRelease(data);
}