Commit 1fc8a8f2 authored by Brendan Shanks's avatar Brendan Shanks Committed by Alexandre Julliard

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: 's avatarBrendan Shanks <bshanks@codeweavers.com> Signed-off-by: 's avatarAndrew Eikum <aeikum@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent da8079b3
......@@ -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);
}
......
......@@ -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
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment