buffer.c 7.42 KB
Newer Older
1 2
/* IDirectMusicBuffer Implementation
 *
3
 * Copyright (C) 2003-2004 Rok Mandeljc
4
 *
5 6 7 8
 * 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.
9 10 11
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
14
 *
15 16 17
 * 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
18 19 20 21 22 23
 */

#include "dmusic_private.h"

WINE_DEFAULT_DEBUG_CHANNEL(dmusic);

24 25 26 27 28
static inline IDirectMusicBufferImpl *impl_from_IDirectMusicBuffer(IDirectMusicBuffer *iface)
{
    return CONTAINING_RECORD(iface, IDirectMusicBufferImpl, IDirectMusicBuffer_iface);
}

29
/* IDirectMusicBufferImpl IUnknown part: */
30 31 32
static HRESULT WINAPI IDirectMusicBufferImpl_QueryInterface(LPDIRECTMUSICBUFFER iface, REFIID riid, LPVOID *ppobj)
{
	IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
33
	TRACE("(%p, (%s, %p)\n",This,debugstr_dmguid(riid),ppobj);
34 35
	if (IsEqualIID (riid, &IID_IUnknown) 
		|| IsEqualIID (riid, &IID_IDirectMusicBuffer)) {
36
		IUnknown_AddRef(iface);
37 38 39
		*ppobj = This;
		return S_OK;
	}
40
	WARN("(%p, (%s, %p): not found\n",This,debugstr_dmguid(riid),ppobj);
41 42 43
	return E_NOINTERFACE;
}

44 45 46
static ULONG WINAPI IDirectMusicBufferImpl_AddRef (LPDIRECTMUSICBUFFER iface)
{
	IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
47 48
	ULONG refCount = InterlockedIncrement(&This->ref);

49
	TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
50

51 52
	DMUSIC_LockModule();

53
	return refCount;
54 55
}

56 57 58
static ULONG WINAPI IDirectMusicBufferImpl_Release(LPDIRECTMUSICBUFFER iface)
{
	IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);
59 60
	ULONG refCount = InterlockedDecrement(&This->ref);

61
	TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
62 63

	if (!refCount) {
64
		HeapFree(GetProcessHeap(), 0, This->data);
65 66
		HeapFree(GetProcessHeap(), 0, This);
	}
67 68 69

	DMUSIC_UnlockModule();
	
70
	return refCount;
71 72
}

73
/* IDirectMusicBufferImpl IDirectMusicBuffer part: */
74 75 76 77 78 79 80
static HRESULT WINAPI IDirectMusicBufferImpl_Flush(LPDIRECTMUSICBUFFER iface)
{
    IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);

    FIXME("(%p): stub\n", This);

    return S_OK;
81 82
}

83 84 85 86 87 88 89
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;
90 91
}

92 93 94 95 96 97 98
static HRESULT WINAPI IDirectMusicBufferImpl_PackStructured(LPDIRECTMUSICBUFFER iface, REFERENCE_TIME rt, DWORD dwChannelGroup, DWORD dwChannelMessage)
{
    IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);

    FIXME("(%p, 0x%s, %d, %d): stub\n", This, wine_dbgstr_longlong(rt), dwChannelGroup, dwChannelMessage);

    return S_OK;
99 100
}

101 102 103 104 105 106 107
static HRESULT WINAPI IDirectMusicBufferImpl_PackUnstructured(LPDIRECTMUSICBUFFER iface, REFERENCE_TIME rt, DWORD dwChannelGroup, DWORD cb, LPBYTE lpb)
{
    IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);

    FIXME("(%p, 0x%s, %d, %d, %p): stub\n", This, wine_dbgstr_longlong(rt), dwChannelGroup, cb, lpb);

    return S_OK;
108 109
}

110 111 112 113 114 115 116
static HRESULT WINAPI IDirectMusicBufferImpl_ResetReadPtr(LPDIRECTMUSICBUFFER iface)
{
    IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);

    FIXME("(%p): stub\n", This);

    return S_OK;
117 118
}

119 120 121 122 123 124 125
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;
126 127
}

128 129 130 131 132 133 134
static HRESULT WINAPI IDirectMusicBufferImpl_GetRawBufferPtr(LPDIRECTMUSICBUFFER iface, LPBYTE* ppData)
{
    IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);

    FIXME("(%p, %p): stub\n", This, ppData);

    return S_OK;
135 136
}

137 138 139 140 141 142 143
static HRESULT WINAPI IDirectMusicBufferImpl_GetStartTime(LPDIRECTMUSICBUFFER iface, LPREFERENCE_TIME prt)
{
    IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);

    FIXME("(%p, %p): stub\n", This, prt);

    return S_OK;
144 145
}

146 147 148 149 150 151 152
static HRESULT WINAPI IDirectMusicBufferImpl_GetUsedBytes(LPDIRECTMUSICBUFFER iface, LPDWORD pcb)
{
    IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);

    FIXME("(%p, %p): stub\n", This, pcb);

    return S_OK;
153 154
}

155 156 157 158 159 160 161
static HRESULT WINAPI IDirectMusicBufferImpl_GetMaxBytes(LPDIRECTMUSICBUFFER iface, LPDWORD pcb)
{
    IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);

    FIXME("(%p, %p): stub\n", This, pcb);

    return S_OK;
162 163
}

164 165 166 167 168 169 170
static HRESULT WINAPI IDirectMusicBufferImpl_GetBufferFormat(LPDIRECTMUSICBUFFER iface, LPGUID pGuidFormat)
{
    IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);

    FIXME("(%p, %p): stub\n", This, pGuidFormat);

    return S_OK;
171 172
}

173 174 175 176 177 178 179
static HRESULT WINAPI IDirectMusicBufferImpl_SetStartTime(LPDIRECTMUSICBUFFER iface, REFERENCE_TIME rt)
{
    IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);

    FIXME("(%p, 0x%s): stub\n", This, wine_dbgstr_longlong(rt));

    return S_OK;
180 181
}

182 183 184 185 186 187 188
static HRESULT WINAPI IDirectMusicBufferImpl_SetUsedBytes (LPDIRECTMUSICBUFFER iface, DWORD cb)
{
    IDirectMusicBufferImpl *This = impl_from_IDirectMusicBuffer(iface);

    FIXME("(%p, %d): stub\n", This, cb);

    return S_OK;
189 190
}

191
static const IDirectMusicBufferVtbl DirectMusicBuffer_Vtbl = {
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
	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
};

210
HRESULT DMUSIC_CreateDirectMusicBufferImpl(LPDMUS_BUFFERDESC desc, LPVOID* ret_iface)
211 212 213 214 215 216 217 218 219 220 221 222
{
    IDirectMusicBufferImpl* dmbuffer;
    HRESULT hr;

    TRACE("(%p, %p)\n", desc, ret_iface);

    *ret_iface = NULL;

    dmbuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicBufferImpl));
    if (!dmbuffer)
        return E_OUTOFMEMORY;

223
    dmbuffer->IDirectMusicBuffer_iface.lpVtbl = &DirectMusicBuffer_Vtbl;
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
    dmbuffer->ref = 0; /* Will be inited by QueryInterface */

    memcpy(&dmbuffer->format, &desc->guidBufferFormat, sizeof(GUID));
    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;
    }

    hr = IDirectMusicBufferImpl_QueryInterface((LPDIRECTMUSICBUFFER)dmbuffer, &IID_IDirectMusicBuffer, ret_iface);
    if (FAILED(hr))
    {
        HeapFree(GetProcessHeap(), 0, dmbuffer->data);
        HeapFree(GetProcessHeap(), 0, dmbuffer);
    }

    return hr;
243
}