ReactOS 0.4.16-dev-91-g764881a
buffer.c File Reference
#include "dmusic_private.h"
#include "initguid.h"
#include "dmksctrl.h"
Include dependency graph for buffer.c:

Go to the source code of this file.

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (dmusic)
 
static IDirectMusicBufferImplimpl_from_IDirectMusicBuffer (IDirectMusicBuffer *iface)
 
static HRESULT WINAPI IDirectMusicBufferImpl_QueryInterface (LPDIRECTMUSICBUFFER iface, REFIID riid, LPVOID *ret_iface)
 
static ULONG WINAPI IDirectMusicBufferImpl_AddRef (LPDIRECTMUSICBUFFER iface)
 
static ULONG WINAPI IDirectMusicBufferImpl_Release (LPDIRECTMUSICBUFFER iface)
 
static HRESULT WINAPI IDirectMusicBufferImpl_Flush (LPDIRECTMUSICBUFFER iface)
 
static HRESULT WINAPI IDirectMusicBufferImpl_TotalTime (LPDIRECTMUSICBUFFER iface, LPREFERENCE_TIME prtTime)
 
static HRESULT WINAPI IDirectMusicBufferImpl_PackStructured (LPDIRECTMUSICBUFFER iface, REFERENCE_TIME ref_time, DWORD channel_group, DWORD channel_message)
 
static HRESULT WINAPI IDirectMusicBufferImpl_PackUnstructured (IDirectMusicBuffer *iface, REFERENCE_TIME ref_time, DWORD channel_group, DWORD len, BYTE *data)
 
static HRESULT WINAPI IDirectMusicBufferImpl_ResetReadPtr (LPDIRECTMUSICBUFFER iface)
 
static HRESULT WINAPI IDirectMusicBufferImpl_GetNextEvent (LPDIRECTMUSICBUFFER iface, LPREFERENCE_TIME prt, LPDWORD pdwChannelGroup, LPDWORD pdwLength, LPBYTE *ppData)
 
static HRESULT WINAPI IDirectMusicBufferImpl_GetRawBufferPtr (LPDIRECTMUSICBUFFER iface, LPBYTE *data)
 
static HRESULT WINAPI IDirectMusicBufferImpl_GetStartTime (LPDIRECTMUSICBUFFER iface, LPREFERENCE_TIME ref_time)
 
static HRESULT WINAPI IDirectMusicBufferImpl_GetUsedBytes (LPDIRECTMUSICBUFFER iface, LPDWORD used_bytes)
 
static HRESULT WINAPI IDirectMusicBufferImpl_GetMaxBytes (LPDIRECTMUSICBUFFER iface, LPDWORD max_bytes)
 
static HRESULT WINAPI IDirectMusicBufferImpl_GetBufferFormat (LPDIRECTMUSICBUFFER iface, LPGUID format)
 
static HRESULT WINAPI IDirectMusicBufferImpl_SetStartTime (LPDIRECTMUSICBUFFER iface, REFERENCE_TIME ref_time)
 
static HRESULT WINAPI IDirectMusicBufferImpl_SetUsedBytes (LPDIRECTMUSICBUFFER iface, DWORD used_bytes)
 
HRESULT DMUSIC_CreateDirectMusicBufferImpl (LPDMUS_BUFFERDESC desc, LPVOID *ret_iface)
 

Variables

static const IDirectMusicBufferVtbl DirectMusicBuffer_Vtbl
 

Function Documentation

◆ DMUSIC_CreateDirectMusicBufferImpl()

HRESULT DMUSIC_CreateDirectMusicBufferImpl ( LPDMUS_BUFFERDESC  desc,
LPVOID ret_iface 
)

Definition at line 294 of file buffer.c.

295{
296 IDirectMusicBufferImpl* dmbuffer;
297
298 TRACE("(%p, %p)\n", desc, ret_iface);
299
300 *ret_iface = NULL;
301
303 if (!dmbuffer)
304 return E_OUTOFMEMORY;
305
307 dmbuffer->ref = 1;
308
309 if (IsEqualGUID(&desc->guidBufferFormat, &GUID_NULL))
311 else
312 dmbuffer->format = desc->guidBufferFormat;
313 dmbuffer->size = (desc->cbBuffer + 3) & ~3; /* Buffer size must be multiple of 4 bytes */
314
315 dmbuffer->data = HeapAlloc(GetProcessHeap(), 0, dmbuffer->size);
316 if (!dmbuffer->data) {
317 HeapFree(GetProcessHeap(), 0, dmbuffer);
318 return E_OUTOFMEMORY;
319 }
320
322 *ret_iface = &dmbuffer->IDirectMusicBuffer_iface;
323
324 return S_OK;
325}
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define NULL
Definition: types.h:112
static const IDirectMusicBufferVtbl DirectMusicBuffer_Vtbl
Definition: buffer.c:275
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
static void DMUSIC_LockModule(void)
#define S_OK
Definition: intsafe.h:52
#define GUID_NULL
Definition: ks.h:106
#define KSDATAFORMAT_SUBTYPE_MIDI
Definition: ksmedia.h:1016
static const WCHAR desc[]
Definition: protectdata.c:36
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define TRACE(s)
Definition: solgame.cpp:4
IDirectMusicBuffer IDirectMusicBuffer_iface

Referenced by IDirectMusic8Impl_CreateMusicBuffer().

◆ IDirectMusicBufferImpl_AddRef()

static ULONG WINAPI IDirectMusicBufferImpl_AddRef ( LPDIRECTMUSICBUFFER  iface)
static

Definition at line 53 of file buffer.c.

54{
57
58 TRACE("(%p)->(): new ref = %u\n", iface, ref);
59
60 return ref;
61}
#define InterlockedIncrement
Definition: armddk.h:53
static IDirectMusicBufferImpl * impl_from_IDirectMusicBuffer(IDirectMusicBuffer *iface)
Definition: buffer.c:28
Definition: send.c:48
uint32_t ULONG
Definition: typedefs.h:59

◆ IDirectMusicBufferImpl_Flush()

static HRESULT WINAPI IDirectMusicBufferImpl_Flush ( LPDIRECTMUSICBUFFER  iface)
static

Definition at line 80 of file buffer.c.

81{
83
84 TRACE("(%p)->()\n", iface);
85
86 This->write_pos = 0;
87
88 return S_OK;
89}

◆ IDirectMusicBufferImpl_GetBufferFormat()

static HRESULT WINAPI IDirectMusicBufferImpl_GetBufferFormat ( LPDIRECTMUSICBUFFER  iface,
LPGUID  format 
)
static

Definition at line 237 of file buffer.c.

238{
240
241 TRACE("(%p)->(%p)\n", iface, format);
242
243 if (!format)
244 return E_POINTER;
245
246 *format = This->format;
247 return S_OK;
248}
Definition: format.c:58
#define E_POINTER
Definition: winerror.h:2365

◆ IDirectMusicBufferImpl_GetMaxBytes()

static HRESULT WINAPI IDirectMusicBufferImpl_GetMaxBytes ( LPDIRECTMUSICBUFFER  iface,
LPDWORD  max_bytes 
)
static

Definition at line 223 of file buffer.c.

224{
226
227 TRACE("(%p)->(%p)\n", iface, max_bytes);
228
229 if (!max_bytes)
230 return E_POINTER;
231
232 *max_bytes = This->size;
233
234 return S_OK;
235}

◆ IDirectMusicBufferImpl_GetNextEvent()

static HRESULT WINAPI IDirectMusicBufferImpl_GetNextEvent ( LPDIRECTMUSICBUFFER  iface,
LPREFERENCE_TIME  prt,
LPDWORD  pdwChannelGroup,
LPDWORD  pdwLength,
LPBYTE ppData 
)
static

Definition at line 170 of file buffer.c.

171{
173
174 FIXME("(%p, %p, %p, %p, %p): stub\n", This, prt, pdwChannelGroup, pdwLength, ppData);
175
176 return S_OK;
177}
#define FIXME(fmt,...)
Definition: precomp.h:53
PSDBQUERYRESULT_VISTA PVOID * ppData
Definition: env.c:56

◆ IDirectMusicBufferImpl_GetRawBufferPtr()

static HRESULT WINAPI IDirectMusicBufferImpl_GetRawBufferPtr ( LPDIRECTMUSICBUFFER  iface,
LPBYTE data 
)
static

Definition at line 179 of file buffer.c.

180{
182
183 TRACE("(%p)->(%p)\n", iface, data);
184
185 if (!data)
186 return E_POINTER;
187
188 *data = This->data;
189
190 return S_OK;
191}
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950

◆ IDirectMusicBufferImpl_GetStartTime()

static HRESULT WINAPI IDirectMusicBufferImpl_GetStartTime ( LPDIRECTMUSICBUFFER  iface,
LPREFERENCE_TIME  ref_time 
)
static

Definition at line 193 of file buffer.c.

194{
196
197 TRACE("(%p)->(%p)\n", iface, ref_time);
198
199 if (!ref_time)
200 return E_POINTER;
201 if (!This->write_pos)
202 return DMUS_E_BUFFER_EMPTY;
203
204 *ref_time = This->start_time;
205
206 return S_OK;
207}
#define DMUS_E_BUFFER_EMPTY
Definition: dmerror.h:90

◆ IDirectMusicBufferImpl_GetUsedBytes()

static HRESULT WINAPI IDirectMusicBufferImpl_GetUsedBytes ( LPDIRECTMUSICBUFFER  iface,
LPDWORD  used_bytes 
)
static

Definition at line 209 of file buffer.c.

210{
212
213 TRACE("(%p)->(%p)\n", iface, used_bytes);
214
215 if (!used_bytes)
216 return E_POINTER;
217
218 *used_bytes = This->write_pos;
219
220 return S_OK;
221}

◆ IDirectMusicBufferImpl_PackStructured()

static HRESULT WINAPI IDirectMusicBufferImpl_PackStructured ( LPDIRECTMUSICBUFFER  iface,
REFERENCE_TIME  ref_time,
DWORD  channel_group,
DWORD  channel_message 
)
static

Definition at line 100 of file buffer.c.

101{
103 DWORD new_write_pos = This->write_pos + DMUS_EVENT_SIZE(sizeof(channel_message));
105
106 TRACE("(%p)->(0x%s, %u, 0x%x)\n", iface, wine_dbgstr_longlong(ref_time), channel_group, channel_message);
107
108 if (new_write_pos > This->size)
109 return DMUS_E_BUFFER_FULL;
110
111 /* Channel_message 0xZZYYXX (3 bytes) is a midi message where XX = status byte, YY = byte 1 and ZZ = byte 2 */
112
113 if (!(channel_message & 0x80))
114 {
115 /* Status byte MSB is always set */
117 }
118
119 if (!This->write_pos)
120 This->start_time = ref_time;
121
122 header = (DMUS_EVENTHEADER*)&This->data[This->write_pos];
123 header->cbEvent = 3; /* Midi message takes 4 bytes space but only 3 are relevant */
124 header->dwChannelGroup = channel_group;
125 header->rtDelta = ref_time - This->start_time;
126 header->dwFlags = DMUS_EVENT_STRUCTURED;
127
128 *(DWORD*)&header[1] = channel_message;
129 This->write_pos = new_write_pos;
130
131 return S_OK;
132}
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:49
#define DMUS_E_BUFFER_FULL
Definition: dmerror.h:91
#define DMUS_E_INVALID_EVENT
Definition: dmerror.h:100
#define DMUS_EVENT_STRUCTURED
Definition: dmusbuff.h:4
#define DMUS_EVENT_SIZE(cb)
Definition: dmusbuff.h:6
unsigned long DWORD
Definition: ntddk_ex.h:95

◆ IDirectMusicBufferImpl_PackUnstructured()

static HRESULT WINAPI IDirectMusicBufferImpl_PackUnstructured ( IDirectMusicBuffer *  iface,
REFERENCE_TIME  ref_time,
DWORD  channel_group,
DWORD  len,
BYTE data 
)
static

Definition at line 134 of file buffer.c.

136{
138 DWORD new_write_pos = This->write_pos + DMUS_EVENT_SIZE(len);
140
141 TRACE("(%p, 0x%s, %d, %d, %p)\n", This, wine_dbgstr_longlong(ref_time), channel_group, len, data);
142
143 if (new_write_pos > This->size)
144 return DMUS_E_BUFFER_FULL;
145
146 if (!This->write_pos)
147 This->start_time = ref_time;
148
149 header = (DMUS_EVENTHEADER*)&This->data[This->write_pos];
150 header->cbEvent = len;
151 header->dwChannelGroup = channel_group;
152 header->rtDelta = ref_time - This->start_time;
153 header->dwFlags = 0;
154
155 memcpy(&header[1], data, len);
156 This->write_pos = new_write_pos;
157
158 return S_OK;
159}
GLenum GLsizei len
Definition: glext.h:6722
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

◆ IDirectMusicBufferImpl_QueryInterface()

static HRESULT WINAPI IDirectMusicBufferImpl_QueryInterface ( LPDIRECTMUSICBUFFER  iface,
REFIID  riid,
LPVOID ret_iface 
)
static

Definition at line 34 of file buffer.c.

35{
36 TRACE("(%p)->(%s, %p)\n", iface, debugstr_dmguid(riid), ret_iface);
37
39 IsEqualIID(riid, &IID_IDirectMusicBuffer))
40 {
42 *ret_iface = iface;
43 return S_OK;
44 }
45
46 *ret_iface = NULL;
47
48 WARN("(%p)->(%s, %p): not found\n", iface, debugstr_dmguid(riid), ret_iface);
49
50 return E_NOINTERFACE;
51}
#define WARN(fmt,...)
Definition: precomp.h:61
const GUID IID_IUnknown
const char * debugstr_dmguid(const GUID *id)
Definition: dmusic_main.c:237
#define IDirectMusicBuffer_AddRef(p)
Definition: dmusicc.h:487
REFIID riid
Definition: atlbase.h:39
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
#define E_NOINTERFACE
Definition: winerror.h:2364

◆ IDirectMusicBufferImpl_Release()

static ULONG WINAPI IDirectMusicBufferImpl_Release ( LPDIRECTMUSICBUFFER  iface)
static

Definition at line 63 of file buffer.c.

64{
67
68 TRACE("(%p)->(): new ref = %u\n", iface, ref);
69
70 if (!ref) {
71 HeapFree(GetProcessHeap(), 0, This->data);
74 }
75
76 return ref;
77}
#define InterlockedDecrement
Definition: armddk.h:52
static void DMUSIC_UnlockModule(void)

◆ IDirectMusicBufferImpl_ResetReadPtr()

static HRESULT WINAPI IDirectMusicBufferImpl_ResetReadPtr ( LPDIRECTMUSICBUFFER  iface)
static

Definition at line 161 of file buffer.c.

162{
164
165 FIXME("(%p): stub\n", This);
166
167 return S_OK;
168}

◆ IDirectMusicBufferImpl_SetStartTime()

static HRESULT WINAPI IDirectMusicBufferImpl_SetStartTime ( LPDIRECTMUSICBUFFER  iface,
REFERENCE_TIME  ref_time 
)
static

Definition at line 250 of file buffer.c.

251{
253
254 TRACE("(%p)->(0x%s)\n", This, wine_dbgstr_longlong(ref_time));
255
256 This->start_time = ref_time;
257
258 return S_OK;
259}

◆ IDirectMusicBufferImpl_SetUsedBytes()

static HRESULT WINAPI IDirectMusicBufferImpl_SetUsedBytes ( LPDIRECTMUSICBUFFER  iface,
DWORD  used_bytes 
)
static

Definition at line 261 of file buffer.c.

262{
264
265 TRACE("(%p)->(%u)\n", iface, used_bytes);
266
267 if (used_bytes > This->size)
268 return DMUS_E_BUFFER_FULL;
269
270 This->write_pos = used_bytes;
271
272 return S_OK;
273}

◆ IDirectMusicBufferImpl_TotalTime()

static HRESULT WINAPI IDirectMusicBufferImpl_TotalTime ( LPDIRECTMUSICBUFFER  iface,
LPREFERENCE_TIME  prtTime 
)
static

Definition at line 91 of file buffer.c.

92{
94
95 FIXME("(%p, %p): stub\n", This, prtTime);
96
97 return S_OK;
98}

◆ impl_from_IDirectMusicBuffer()

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( dmusic  )

Variable Documentation

◆ DirectMusicBuffer_Vtbl

const IDirectMusicBufferVtbl DirectMusicBuffer_Vtbl
static
Initial value:
= {
}
static HRESULT WINAPI IDirectMusicBufferImpl_PackUnstructured(IDirectMusicBuffer *iface, REFERENCE_TIME ref_time, DWORD channel_group, DWORD len, BYTE *data)
Definition: buffer.c:134
static HRESULT WINAPI IDirectMusicBufferImpl_GetNextEvent(LPDIRECTMUSICBUFFER iface, LPREFERENCE_TIME prt, LPDWORD pdwChannelGroup, LPDWORD pdwLength, LPBYTE *ppData)
Definition: buffer.c:170
static HRESULT WINAPI IDirectMusicBufferImpl_Flush(LPDIRECTMUSICBUFFER iface)
Definition: buffer.c:80
static HRESULT WINAPI IDirectMusicBufferImpl_SetUsedBytes(LPDIRECTMUSICBUFFER iface, DWORD used_bytes)
Definition: buffer.c:261
static ULONG WINAPI IDirectMusicBufferImpl_Release(LPDIRECTMUSICBUFFER iface)
Definition: buffer.c:63
static HRESULT WINAPI IDirectMusicBufferImpl_GetUsedBytes(LPDIRECTMUSICBUFFER iface, LPDWORD used_bytes)
Definition: buffer.c:209
static HRESULT WINAPI IDirectMusicBufferImpl_QueryInterface(LPDIRECTMUSICBUFFER iface, REFIID riid, LPVOID *ret_iface)
Definition: buffer.c:34
static HRESULT WINAPI IDirectMusicBufferImpl_GetStartTime(LPDIRECTMUSICBUFFER iface, LPREFERENCE_TIME ref_time)
Definition: buffer.c:193
static HRESULT WINAPI IDirectMusicBufferImpl_SetStartTime(LPDIRECTMUSICBUFFER iface, REFERENCE_TIME ref_time)
Definition: buffer.c:250
static HRESULT WINAPI IDirectMusicBufferImpl_GetRawBufferPtr(LPDIRECTMUSICBUFFER iface, LPBYTE *data)
Definition: buffer.c:179
static ULONG WINAPI IDirectMusicBufferImpl_AddRef(LPDIRECTMUSICBUFFER iface)
Definition: buffer.c:53
static HRESULT WINAPI IDirectMusicBufferImpl_PackStructured(LPDIRECTMUSICBUFFER iface, REFERENCE_TIME ref_time, DWORD channel_group, DWORD channel_message)
Definition: buffer.c:100
static HRESULT WINAPI IDirectMusicBufferImpl_GetMaxBytes(LPDIRECTMUSICBUFFER iface, LPDWORD max_bytes)
Definition: buffer.c:223
static HRESULT WINAPI IDirectMusicBufferImpl_TotalTime(LPDIRECTMUSICBUFFER iface, LPREFERENCE_TIME prtTime)
Definition: buffer.c:91
static HRESULT WINAPI IDirectMusicBufferImpl_ResetReadPtr(LPDIRECTMUSICBUFFER iface)
Definition: buffer.c:161
static HRESULT WINAPI IDirectMusicBufferImpl_GetBufferFormat(LPDIRECTMUSICBUFFER iface, LPGUID format)
Definition: buffer.c:237

Definition at line 275 of file buffer.c.

Referenced by DMUSIC_CreateDirectMusicBufferImpl().