2012-05-14 08:06:39 +02:00
|
|
|
/*
|
|
|
|
* IDirectMusicBuffer Implementation
|
2003-07-22 00:10:14 +02:00
|
|
|
*
|
2004-01-20 01:21:40 +01:00
|
|
|
* Copyright (C) 2003-2004 Rok Mandeljc
|
2012-05-14 08:06:39 +02:00
|
|
|
* Copyright (C) 2012 Christian Costa
|
2003-07-22 00:10:14 +02:00
|
|
|
*
|
2007-05-30 12:54:07 +02:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2003-07-22 00:10:14 +02:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-05-30 12:54:07 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2003-07-22 00:10:14 +02:00
|
|
|
*
|
2007-05-30 12:54:07 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-07-22 00:10:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "dmusic_private.h"
|
2019-12-13 00:29:06 +01:00
|
|
|
#include "dmobject.h"
|
2012-04-26 08:08:26 +02:00
|
|
|
#include "initguid.h"
|
|
|
|
#include "dmksctrl.h"
|
2003-07-22 00:10:14 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
|
|
|
|
|
2012-04-23 21:26:02 +02:00
|
|
|
static inline IDirectMusicBufferImpl *impl_from_IDirectMusicBuffer(IDirectMusicBuffer *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, IDirectMusicBufferImpl, IDirectMusicBuffer_iface);
|
|
|
|
}
|
|
|
|
|
2004-01-20 01:21:40 +01:00
|
|
|
/* IDirectMusicBufferImpl IUnknown part: */
|
2012-04-24 22:33:01 +02:00
|
|
|
static HRESULT WINAPI IDirectMusicBufferImpl_QueryInterface(LPDIRECTMUSICBUFFER iface, REFIID riid, LPVOID *ret_iface)
|
2012-04-23 21:26:02 +02:00
|
|
|
{
|
2012-04-24 22:33:01 +02:00
|
|
|
TRACE("(%p)->(%s, %p)\n", iface, debugstr_dmguid(riid), ret_iface);
|
|
|
|
|
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IDirectMusicBuffer))
|
|
|
|
{
|
|
|
|
IDirectMusicBuffer_AddRef(iface);
|
|
|
|
*ret_iface = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ret_iface = NULL;
|
|
|
|
|
|
|
|
WARN("(%p)->(%s, %p): not found\n", iface, debugstr_dmguid(riid), ret_iface);
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|
|
|
|
|
2012-04-24 22:32:52 +02:00
|
|
|
static ULONG WINAPI IDirectMusicBufferImpl_AddRef(LPDIRECTMUSICBUFFER iface)
|
2012-04-23 21:26:02 +02:00
|
|
|
{
|
2012-04-24 22:32:52 +02:00
|
|
|
IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&This->ref);
|
2005-01-14 17:02:20 +01:00
|
|
|
|
2012-04-24 22:32:52 +02:00
|
|
|
TRACE("(%p)->(): new ref = %u\n", iface, ref);
|
2005-01-14 17:02:20 +01:00
|
|
|
|
2012-04-24 22:32:52 +02:00
|
|
|
return ref;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|
|
|
|
|
2012-04-23 21:26:02 +02:00
|
|
|
static ULONG WINAPI IDirectMusicBufferImpl_Release(LPDIRECTMUSICBUFFER iface)
|
|
|
|
{
|
2012-04-24 22:32:52 +02:00
|
|
|
IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&This->ref);
|
2005-01-14 17:02:20 +01:00
|
|
|
|
2012-04-24 22:32:52 +02:00
|
|
|
TRACE("(%p)->(): new ref = %u\n", iface, ref);
|
2005-01-14 17:02:20 +01:00
|
|
|
|
2012-04-24 22:32:52 +02:00
|
|
|
if (!ref) {
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->data);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
2014-05-31 19:18:55 +02:00
|
|
|
DMUSIC_UnlockModule();
|
2012-04-24 22:32:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|
|
|
|
|
2004-01-20 01:21:40 +01:00
|
|
|
/* IDirectMusicBufferImpl IDirectMusicBuffer part: */
|
2012-04-23 21:26:02 +02:00
|
|
|
static HRESULT WINAPI IDirectMusicBufferImpl_Flush(LPDIRECTMUSICBUFFER iface)
|
|
|
|
{
|
|
|
|
IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
|
|
|
|
|
2012-04-26 08:09:01 +02:00
|
|
|
TRACE("(%p)->()\n", iface);
|
|
|
|
|
|
|
|
This->write_pos = 0;
|
2012-04-23 21:26:02 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|
|
|
|
|
2012-04-23 21:26:02 +02:00
|
|
|
static HRESULT WINAPI IDirectMusicBufferImpl_TotalTime(LPDIRECTMUSICBUFFER iface, LPREFERENCE_TIME prtTime)
|
|
|
|
{
|
|
|
|
IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
|
|
|
|
|
|
|
|
FIXME("(%p, %p): stub\n", This, prtTime);
|
|
|
|
|
|
|
|
return S_OK;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|
|
|
|
|
2012-04-26 08:08:34 +02:00
|
|
|
static HRESULT WINAPI IDirectMusicBufferImpl_PackStructured(LPDIRECTMUSICBUFFER iface, REFERENCE_TIME ref_time, DWORD channel_group, DWORD channel_message)
|
2012-04-23 21:26:02 +02:00
|
|
|
{
|
|
|
|
IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
|
2017-05-01 02:15:50 +02:00
|
|
|
DWORD new_write_pos = This->write_pos + DMUS_EVENT_SIZE(sizeof(channel_message));
|
2017-05-01 23:58:50 +02:00
|
|
|
DMUS_EVENTHEADER *header;
|
2012-04-23 21:26:02 +02:00
|
|
|
|
2012-04-26 08:08:34 +02:00
|
|
|
TRACE("(%p)->(0x%s, %u, 0x%x)\n", iface, wine_dbgstr_longlong(ref_time), channel_group, channel_message);
|
|
|
|
|
|
|
|
if (new_write_pos > This->size)
|
|
|
|
return DMUS_E_BUFFER_FULL;
|
|
|
|
|
2012-05-04 08:40:38 +02:00
|
|
|
/* Channel_message 0xZZYYXX (3 bytes) is a midi message where XX = status byte, YY = byte 1 and ZZ = byte 2 */
|
2012-04-26 08:08:34 +02:00
|
|
|
|
|
|
|
if (!(channel_message & 0x80))
|
|
|
|
{
|
|
|
|
/* Status byte MSB is always set */
|
|
|
|
return DMUS_E_INVALID_EVENT;
|
|
|
|
}
|
|
|
|
|
2012-04-26 08:08:51 +02:00
|
|
|
if (!This->write_pos)
|
|
|
|
This->start_time = ref_time;
|
|
|
|
|
2017-05-01 23:58:50 +02:00
|
|
|
header = (DMUS_EVENTHEADER*)&This->data[This->write_pos];
|
|
|
|
header->cbEvent = 3; /* Midi message takes 4 bytes space but only 3 are relevant */
|
|
|
|
header->dwChannelGroup = channel_group;
|
|
|
|
header->rtDelta = ref_time - This->start_time;
|
|
|
|
header->dwFlags = DMUS_EVENT_STRUCTURED;
|
2012-04-26 08:08:34 +02:00
|
|
|
|
2017-05-01 23:58:50 +02:00
|
|
|
*(DWORD*)&header[1] = channel_message;
|
2012-04-26 08:08:34 +02:00
|
|
|
This->write_pos = new_write_pos;
|
2012-04-23 21:26:02 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|
|
|
|
|
2017-05-01 18:51:30 +02:00
|
|
|
static HRESULT WINAPI IDirectMusicBufferImpl_PackUnstructured(IDirectMusicBuffer *iface,
|
|
|
|
REFERENCE_TIME ref_time, DWORD channel_group, DWORD len, BYTE *data)
|
2012-04-23 21:26:02 +02:00
|
|
|
{
|
|
|
|
IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
|
2017-05-01 18:51:30 +02:00
|
|
|
DWORD new_write_pos = This->write_pos + DMUS_EVENT_SIZE(len);
|
|
|
|
DMUS_EVENTHEADER *header;
|
2012-04-23 21:26:02 +02:00
|
|
|
|
2017-05-01 18:51:30 +02:00
|
|
|
TRACE("(%p, 0x%s, %d, %d, %p)\n", This, wine_dbgstr_longlong(ref_time), channel_group, len, data);
|
|
|
|
|
|
|
|
if (new_write_pos > This->size)
|
|
|
|
return DMUS_E_BUFFER_FULL;
|
|
|
|
|
|
|
|
if (!This->write_pos)
|
|
|
|
This->start_time = ref_time;
|
|
|
|
|
|
|
|
header = (DMUS_EVENTHEADER*)&This->data[This->write_pos];
|
|
|
|
header->cbEvent = len;
|
|
|
|
header->dwChannelGroup = channel_group;
|
|
|
|
header->rtDelta = ref_time - This->start_time;
|
|
|
|
header->dwFlags = 0;
|
|
|
|
|
|
|
|
memcpy(&header[1], data, len);
|
|
|
|
This->write_pos = new_write_pos;
|
2012-04-23 21:26:02 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|
|
|
|
|
2012-04-23 21:26:02 +02:00
|
|
|
static HRESULT WINAPI IDirectMusicBufferImpl_ResetReadPtr(LPDIRECTMUSICBUFFER iface)
|
|
|
|
{
|
|
|
|
IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
|
|
|
|
|
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
|
|
|
|
return S_OK;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|
|
|
|
|
2012-04-23 21:26:02 +02:00
|
|
|
static HRESULT WINAPI IDirectMusicBufferImpl_GetNextEvent(LPDIRECTMUSICBUFFER iface, LPREFERENCE_TIME prt, LPDWORD pdwChannelGroup, LPDWORD pdwLength, LPBYTE* ppData)
|
|
|
|
{
|
|
|
|
IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
|
|
|
|
|
|
|
|
FIXME("(%p, %p, %p, %p, %p): stub\n", This, prt, pdwChannelGroup, pdwLength, ppData);
|
|
|
|
|
|
|
|
return S_OK;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|
|
|
|
|
2012-04-24 22:32:44 +02:00
|
|
|
static HRESULT WINAPI IDirectMusicBufferImpl_GetRawBufferPtr(LPDIRECTMUSICBUFFER iface, LPBYTE* data)
|
2012-04-23 21:26:02 +02:00
|
|
|
{
|
|
|
|
IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
|
|
|
|
|
2012-04-24 22:32:44 +02:00
|
|
|
TRACE("(%p)->(%p)\n", iface, data);
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*data = This->data;
|
2012-04-23 21:26:02 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|
|
|
|
|
2012-04-26 08:08:51 +02:00
|
|
|
static HRESULT WINAPI IDirectMusicBufferImpl_GetStartTime(LPDIRECTMUSICBUFFER iface, LPREFERENCE_TIME ref_time)
|
2012-04-23 21:26:02 +02:00
|
|
|
{
|
|
|
|
IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
|
|
|
|
|
2012-04-26 08:08:51 +02:00
|
|
|
TRACE("(%p)->(%p)\n", iface, ref_time);
|
|
|
|
|
|
|
|
if (!ref_time)
|
|
|
|
return E_POINTER;
|
|
|
|
if (!This->write_pos)
|
|
|
|
return DMUS_E_BUFFER_EMPTY;
|
|
|
|
|
|
|
|
*ref_time = This->start_time;
|
2012-04-23 21:26:02 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|
|
|
|
|
2012-04-26 08:08:43 +02:00
|
|
|
static HRESULT WINAPI IDirectMusicBufferImpl_GetUsedBytes(LPDIRECTMUSICBUFFER iface, LPDWORD used_bytes)
|
2012-04-23 21:26:02 +02:00
|
|
|
{
|
|
|
|
IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
|
|
|
|
|
2012-04-26 08:08:43 +02:00
|
|
|
TRACE("(%p)->(%p)\n", iface, used_bytes);
|
|
|
|
|
|
|
|
if (!used_bytes)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*used_bytes = This->write_pos;
|
2012-04-23 21:26:02 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|
|
|
|
|
2012-04-24 22:32:36 +02:00
|
|
|
static HRESULT WINAPI IDirectMusicBufferImpl_GetMaxBytes(LPDIRECTMUSICBUFFER iface, LPDWORD max_bytes)
|
2012-04-23 21:26:02 +02:00
|
|
|
{
|
|
|
|
IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
|
|
|
|
|
2012-04-24 22:32:36 +02:00
|
|
|
TRACE("(%p)->(%p)\n", iface, max_bytes);
|
|
|
|
|
|
|
|
if (!max_bytes)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*max_bytes = This->size;
|
2012-04-23 21:26:02 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|
|
|
|
|
2012-04-24 22:32:27 +02:00
|
|
|
static HRESULT WINAPI IDirectMusicBufferImpl_GetBufferFormat(LPDIRECTMUSICBUFFER iface, LPGUID format)
|
2012-04-23 21:26:02 +02:00
|
|
|
{
|
|
|
|
IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
|
|
|
|
|
2012-04-24 22:32:27 +02:00
|
|
|
TRACE("(%p)->(%p)\n", iface, format);
|
2012-04-23 21:26:02 +02:00
|
|
|
|
2012-04-24 22:32:27 +02:00
|
|
|
if (!format)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
*format = This->format;
|
2012-04-23 21:26:02 +02:00
|
|
|
return S_OK;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|
|
|
|
|
2012-04-26 08:08:51 +02:00
|
|
|
static HRESULT WINAPI IDirectMusicBufferImpl_SetStartTime(LPDIRECTMUSICBUFFER iface, REFERENCE_TIME ref_time)
|
2012-04-23 21:26:02 +02:00
|
|
|
{
|
|
|
|
IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
|
|
|
|
|
2012-04-26 08:08:51 +02:00
|
|
|
TRACE("(%p)->(0x%s)\n", This, wine_dbgstr_longlong(ref_time));
|
|
|
|
|
|
|
|
This->start_time = ref_time;
|
2012-04-23 21:26:02 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 08:06:39 +02:00
|
|
|
static HRESULT WINAPI IDirectMusicBufferImpl_SetUsedBytes(LPDIRECTMUSICBUFFER iface, DWORD used_bytes)
|
2012-04-23 21:26:02 +02:00
|
|
|
{
|
|
|
|
IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
|
|
|
|
|
2012-05-14 08:06:39 +02:00
|
|
|
TRACE("(%p)->(%u)\n", iface, used_bytes);
|
|
|
|
|
|
|
|
if (used_bytes > This->size)
|
|
|
|
return DMUS_E_BUFFER_FULL;
|
|
|
|
|
|
|
|
This->write_pos = used_bytes;
|
2012-04-23 21:26:02 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|
|
|
|
|
2005-06-01 21:57:42 +02:00
|
|
|
static const IDirectMusicBufferVtbl DirectMusicBuffer_Vtbl = {
|
2003-07-22 00:10:14 +02:00
|
|
|
IDirectMusicBufferImpl_QueryInterface,
|
|
|
|
IDirectMusicBufferImpl_AddRef,
|
|
|
|
IDirectMusicBufferImpl_Release,
|
|
|
|
IDirectMusicBufferImpl_Flush,
|
|
|
|
IDirectMusicBufferImpl_TotalTime,
|
|
|
|
IDirectMusicBufferImpl_PackStructured,
|
|
|
|
IDirectMusicBufferImpl_PackUnstructured,
|
|
|
|
IDirectMusicBufferImpl_ResetReadPtr,
|
|
|
|
IDirectMusicBufferImpl_GetNextEvent,
|
|
|
|
IDirectMusicBufferImpl_GetRawBufferPtr,
|
|
|
|
IDirectMusicBufferImpl_GetStartTime,
|
|
|
|
IDirectMusicBufferImpl_GetUsedBytes,
|
|
|
|
IDirectMusicBufferImpl_GetMaxBytes,
|
|
|
|
IDirectMusicBufferImpl_GetBufferFormat,
|
|
|
|
IDirectMusicBufferImpl_SetStartTime,
|
|
|
|
IDirectMusicBufferImpl_SetUsedBytes
|
|
|
|
};
|
|
|
|
|
2012-04-24 11:37:20 +02:00
|
|
|
HRESULT DMUSIC_CreateDirectMusicBufferImpl(LPDMUS_BUFFERDESC desc, LPVOID* ret_iface)
|
2012-04-23 21:25:53 +02:00
|
|
|
{
|
|
|
|
IDirectMusicBufferImpl* dmbuffer;
|
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", desc, ret_iface);
|
|
|
|
|
|
|
|
*ret_iface = NULL;
|
|
|
|
|
|
|
|
dmbuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicBufferImpl));
|
|
|
|
if (!dmbuffer)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2012-04-23 21:26:02 +02:00
|
|
|
dmbuffer->IDirectMusicBuffer_iface.lpVtbl = &DirectMusicBuffer_Vtbl;
|
2014-05-31 19:18:55 +02:00
|
|
|
dmbuffer->ref = 1;
|
2012-04-23 21:25:53 +02:00
|
|
|
|
2012-04-26 08:08:26 +02:00
|
|
|
if (IsEqualGUID(&desc->guidBufferFormat, &GUID_NULL))
|
|
|
|
dmbuffer->format = KSDATAFORMAT_SUBTYPE_MIDI;
|
|
|
|
else
|
|
|
|
dmbuffer->format = desc->guidBufferFormat;
|
2012-04-23 21:25:53 +02:00
|
|
|
dmbuffer->size = (desc->cbBuffer + 3) & ~3; /* Buffer size must be multiple of 4 bytes */
|
|
|
|
|
|
|
|
dmbuffer->data = HeapAlloc(GetProcessHeap(), 0, dmbuffer->size);
|
|
|
|
if (!dmbuffer->data) {
|
|
|
|
HeapFree(GetProcessHeap(), 0, dmbuffer);
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2014-05-31 19:18:55 +02:00
|
|
|
DMUSIC_LockModule();
|
|
|
|
*ret_iface = &dmbuffer->IDirectMusicBuffer_iface;
|
2012-04-23 21:25:53 +02:00
|
|
|
|
2014-05-31 19:18:55 +02:00
|
|
|
return S_OK;
|
2003-07-22 00:10:14 +02:00
|
|
|
}
|