1 /* IDirectMusicBuffer Implementation
3 * Copyright (C) 2003-2004 Rok Mandeljc
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "dmusic_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
24 static inline IDirectMusicBufferImpl *impl_from_IDirectMusicBuffer(IDirectMusicBuffer *iface)
26 return CONTAINING_RECORD(iface, IDirectMusicBufferImpl, IDirectMusicBuffer_iface);
29 /* IDirectMusicBufferImpl IUnknown part: */
30 static HRESULT WINAPI IDirectMusicBufferImpl_QueryInterface(LPDIRECTMUSICBUFFER iface, REFIID riid, LPVOID *ppobj)
32 IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
33 TRACE("(%p, (%s, %p)\n",This,debugstr_dmguid(riid),ppobj);
34 if (IsEqualIID (riid, &IID_IUnknown)
35 || IsEqualIID (riid, &IID_IDirectMusicBuffer)) {
36 IUnknown_AddRef(iface);
40 WARN("(%p, (%s, %p): not found\n",This,debugstr_dmguid(riid),ppobj);
44 static ULONG WINAPI IDirectMusicBufferImpl_AddRef (LPDIRECTMUSICBUFFER iface)
46 IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
47 ULONG refCount = InterlockedIncrement(&This->ref);
49 TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
56 static ULONG WINAPI IDirectMusicBufferImpl_Release(LPDIRECTMUSICBUFFER iface)
58 IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
59 ULONG refCount = InterlockedDecrement(&This->ref);
61 TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
64 HeapFree(GetProcessHeap(), 0, This->data);
65 HeapFree(GetProcessHeap(), 0, This);
68 DMUSIC_UnlockModule();
73 /* IDirectMusicBufferImpl IDirectMusicBuffer part: */
74 static HRESULT WINAPI IDirectMusicBufferImpl_Flush(LPDIRECTMUSICBUFFER iface)
76 IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
78 FIXME("(%p): stub\n", This);
83 static HRESULT WINAPI IDirectMusicBufferImpl_TotalTime(LPDIRECTMUSICBUFFER iface, LPREFERENCE_TIME prtTime)
85 IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
87 FIXME("(%p, %p): stub\n", This, prtTime);
92 static HRESULT WINAPI IDirectMusicBufferImpl_PackStructured(LPDIRECTMUSICBUFFER iface, REFERENCE_TIME rt, DWORD dwChannelGroup, DWORD dwChannelMessage)
94 IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
96 FIXME("(%p, 0x%s, %d, %d): stub\n", This, wine_dbgstr_longlong(rt), dwChannelGroup, dwChannelMessage);
101 static HRESULT WINAPI IDirectMusicBufferImpl_PackUnstructured(LPDIRECTMUSICBUFFER iface, REFERENCE_TIME rt, DWORD dwChannelGroup, DWORD cb, LPBYTE lpb)
103 IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
105 FIXME("(%p, 0x%s, %d, %d, %p): stub\n", This, wine_dbgstr_longlong(rt), dwChannelGroup, cb, lpb);
110 static HRESULT WINAPI IDirectMusicBufferImpl_ResetReadPtr(LPDIRECTMUSICBUFFER iface)
112 IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
114 FIXME("(%p): stub\n", This);
119 static HRESULT WINAPI IDirectMusicBufferImpl_GetNextEvent(LPDIRECTMUSICBUFFER iface, LPREFERENCE_TIME prt, LPDWORD pdwChannelGroup, LPDWORD pdwLength, LPBYTE* ppData)
121 IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
123 FIXME("(%p, %p, %p, %p, %p): stub\n", This, prt, pdwChannelGroup, pdwLength, ppData);
128 static HRESULT WINAPI IDirectMusicBufferImpl_GetRawBufferPtr(LPDIRECTMUSICBUFFER iface, LPBYTE* ppData)
130 IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
132 FIXME("(%p, %p): stub\n", This, ppData);
137 static HRESULT WINAPI IDirectMusicBufferImpl_GetStartTime(LPDIRECTMUSICBUFFER iface, LPREFERENCE_TIME prt)
139 IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
141 FIXME("(%p, %p): stub\n", This, prt);
146 static HRESULT WINAPI IDirectMusicBufferImpl_GetUsedBytes(LPDIRECTMUSICBUFFER iface, LPDWORD pcb)
148 IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
150 FIXME("(%p, %p): stub\n", This, pcb);
155 static HRESULT WINAPI IDirectMusicBufferImpl_GetMaxBytes(LPDIRECTMUSICBUFFER iface, LPDWORD max_bytes)
157 IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
159 TRACE("(%p)->(%p)\n", iface, max_bytes);
164 *max_bytes = This->size;
169 static HRESULT WINAPI IDirectMusicBufferImpl_GetBufferFormat(LPDIRECTMUSICBUFFER iface, LPGUID format)
171 IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
173 TRACE("(%p)->(%p)\n", iface, format);
178 *format = This->format;
182 static HRESULT WINAPI IDirectMusicBufferImpl_SetStartTime(LPDIRECTMUSICBUFFER iface, REFERENCE_TIME rt)
184 IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
186 FIXME("(%p, 0x%s): stub\n", This, wine_dbgstr_longlong(rt));
191 static HRESULT WINAPI IDirectMusicBufferImpl_SetUsedBytes (LPDIRECTMUSICBUFFER iface, DWORD cb)
193 IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
195 FIXME("(%p, %d): stub\n", This, cb);
200 static const IDirectMusicBufferVtbl DirectMusicBuffer_Vtbl = {
201 IDirectMusicBufferImpl_QueryInterface,
202 IDirectMusicBufferImpl_AddRef,
203 IDirectMusicBufferImpl_Release,
204 IDirectMusicBufferImpl_Flush,
205 IDirectMusicBufferImpl_TotalTime,
206 IDirectMusicBufferImpl_PackStructured,
207 IDirectMusicBufferImpl_PackUnstructured,
208 IDirectMusicBufferImpl_ResetReadPtr,
209 IDirectMusicBufferImpl_GetNextEvent,
210 IDirectMusicBufferImpl_GetRawBufferPtr,
211 IDirectMusicBufferImpl_GetStartTime,
212 IDirectMusicBufferImpl_GetUsedBytes,
213 IDirectMusicBufferImpl_GetMaxBytes,
214 IDirectMusicBufferImpl_GetBufferFormat,
215 IDirectMusicBufferImpl_SetStartTime,
216 IDirectMusicBufferImpl_SetUsedBytes
219 HRESULT DMUSIC_CreateDirectMusicBufferImpl(LPDMUS_BUFFERDESC desc, LPVOID* ret_iface)
221 IDirectMusicBufferImpl* dmbuffer;
224 TRACE("(%p, %p)\n", desc, ret_iface);
228 dmbuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicBufferImpl));
230 return E_OUTOFMEMORY;
232 dmbuffer->IDirectMusicBuffer_iface.lpVtbl = &DirectMusicBuffer_Vtbl;
233 dmbuffer->ref = 0; /* Will be inited by QueryInterface */
235 memcpy(&dmbuffer->format, &desc->guidBufferFormat, sizeof(GUID));
236 dmbuffer->size = (desc->cbBuffer + 3) & ~3; /* Buffer size must be multiple of 4 bytes */
238 dmbuffer->data = HeapAlloc(GetProcessHeap(), 0, dmbuffer->size);
239 if (!dmbuffer->data) {
240 HeapFree(GetProcessHeap(), 0, dmbuffer);
241 return E_OUTOFMEMORY;
244 hr = IDirectMusicBufferImpl_QueryInterface((LPDIRECTMUSICBUFFER)dmbuffer, &IID_IDirectMusicBuffer, ret_iface);
247 HeapFree(GetProcessHeap(), 0, dmbuffer->data);
248 HeapFree(GetProcessHeap(), 0, dmbuffer);