include: Add event trace flags and guid to evntrace.h.
[wine.git] / dlls / dmime / audiopath.c
blobe6654a4a4be7478685588b981cca504a498553b6
1 /* IDirectMusicAudioPath 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 "dmime_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(dmime);
23 WINE_DECLARE_DEBUG_CHANNEL(dmfile);
25 struct IDirectMusicAudioPathImpl {
26 IDirectMusicAudioPath IDirectMusicAudioPath_iface;
27 IDirectMusicObject IDirectMusicObject_iface;
28 IPersistStream IPersistStream_iface;
29 LONG ref;
31 /* IDirectMusicAudioPathImpl fields */
32 LPDMUS_OBJECTDESC pDesc;
34 IDirectMusicPerformance8* pPerf;
35 IDirectMusicGraph* pToolGraph;
36 IDirectSoundBuffer* pDSBuffer;
37 IDirectSoundBuffer* pPrimary;
39 BOOL fActive;
42 static inline struct IDirectMusicAudioPathImpl *impl_from_IDirectMusicAudioPath(IDirectMusicAudioPath *iface)
44 return CONTAINING_RECORD(iface, struct IDirectMusicAudioPathImpl, IDirectMusicAudioPath_iface);
47 static inline struct IDirectMusicAudioPathImpl *impl_from_IDirectMusicObject(IDirectMusicObject *iface)
49 return CONTAINING_RECORD(iface, struct IDirectMusicAudioPathImpl, IDirectMusicObject_iface);
52 static inline struct IDirectMusicAudioPathImpl *impl_from_IPersistStream(IPersistStream *iface)
54 return CONTAINING_RECORD(iface, struct IDirectMusicAudioPathImpl, IPersistStream_iface);
57 void set_audiopath_perf_pointer(IDirectMusicAudioPath *iface, IDirectMusicPerformance8 *performance)
59 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
60 This->pPerf = performance;
63 void set_audiopath_dsound_buffer(IDirectMusicAudioPath *iface, IDirectSoundBuffer *buffer)
65 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
66 This->pDSBuffer = buffer;
69 void set_audiopath_primary_dsound_buffer(IDirectMusicAudioPath *iface, IDirectSoundBuffer *buffer)
71 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
72 This->pPrimary = buffer;
75 /*****************************************************************************
76 * IDirectMusicAudioPathImpl implementation
78 static HRESULT WINAPI IDirectMusicAudioPathImpl_QueryInterface (IDirectMusicAudioPath *iface, REFIID riid, void **ppobj)
80 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
82 TRACE("(%p, %s, %p)\n", This, debugstr_dmguid(riid), ppobj);
84 *ppobj = NULL;
86 if (IsEqualIID (riid, &IID_IDirectMusicAudioPath) || IsEqualIID (riid, &IID_IUnknown))
87 *ppobj = &This->IDirectMusicAudioPath_iface;
88 else if (IsEqualIID (riid, &IID_IDirectMusicObject))
89 *ppobj = &This->IDirectMusicObject_iface;
90 else if (IsEqualIID (riid, &IID_IPersistStream))
91 *ppobj = &This->IPersistStream_iface;
93 if (*ppobj) {
94 IUnknown_AddRef((IUnknown*)*ppobj);
95 return S_OK;
98 WARN("(%p, %s, %p): not found\n", This, debugstr_dmguid(riid), ppobj);
99 return E_NOINTERFACE;
102 static ULONG WINAPI IDirectMusicAudioPathImpl_AddRef (IDirectMusicAudioPath *iface)
104 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
105 ULONG ref = InterlockedIncrement(&This->ref);
107 TRACE("(%p): AddRef from %d\n", This, ref - 1);
109 DMIME_LockModule();
110 return ref;
113 static ULONG WINAPI IDirectMusicAudioPathImpl_Release (IDirectMusicAudioPath *iface)
115 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
116 ULONG ref = InterlockedDecrement(&This->ref);
118 TRACE("(%p): ReleaseRef to %d\n", This, ref);
120 if (ref == 0) {
121 if (This->pDSBuffer)
122 IDirectSoundBuffer8_Release(This->pDSBuffer);
123 This->pPerf = NULL;
124 HeapFree(GetProcessHeap(), 0, This);
127 DMIME_UnlockModule();
128 return ref;
131 static HRESULT WINAPI IDirectMusicAudioPathImpl_GetObjectInPath (IDirectMusicAudioPath *iface, DWORD dwPChannel, DWORD dwStage, DWORD dwBuffer,
132 REFGUID guidObject, WORD dwIndex, REFGUID iidInterface, void** ppObject)
134 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
135 HRESULT hr;
137 FIXME("(%p, %d, %d, %d, %s, %d, %s, %p): stub\n", This, dwPChannel, dwStage, dwBuffer, debugstr_dmguid(guidObject),
138 dwIndex, debugstr_dmguid(iidInterface), ppObject);
140 switch (dwStage) {
141 case DMUS_PATH_BUFFER:
142 if (This->pDSBuffer)
144 if (IsEqualIID (iidInterface, &IID_IDirectSoundBuffer8)) {
145 IDirectSoundBuffer8_QueryInterface (This->pDSBuffer, &IID_IDirectSoundBuffer8, ppObject);
146 TRACE("returning %p\n",*ppObject);
147 return S_OK;
148 } else if (IsEqualIID (iidInterface, &IID_IDirectSound3DBuffer)) {
149 IDirectSoundBuffer8_QueryInterface (This->pDSBuffer, &IID_IDirectSound3DBuffer, ppObject);
150 TRACE("returning %p\n",*ppObject);
151 return S_OK;
152 } else {
153 FIXME("Bad iid\n");
156 break;
158 case DMUS_PATH_PRIMARY_BUFFER: {
159 if (IsEqualIID (iidInterface, &IID_IDirectSound3DListener)) {
160 IDirectSoundBuffer8_QueryInterface (This->pPrimary, &IID_IDirectSound3DListener, ppObject);
161 return S_OK;
162 } else {
163 FIXME("bad iid...\n");
166 break;
168 case DMUS_PATH_AUDIOPATH_GRAPH:
170 if (IsEqualIID (iidInterface, &IID_IDirectMusicGraph)) {
171 if (NULL == This->pToolGraph) {
172 IDirectMusicGraphImpl* pGraph;
173 hr = create_dmgraph(&IID_IDirectMusicGraph, (void**)&pGraph);
174 if (FAILED(hr))
175 return hr;
176 This->pToolGraph = (IDirectMusicGraph*) pGraph;
178 *ppObject = This->pToolGraph;
179 IDirectMusicGraph_AddRef((LPDIRECTMUSICGRAPH) *ppObject);
180 return S_OK;
183 break;
185 case DMUS_PATH_AUDIOPATH_TOOL:
187 /* TODO */
189 break;
191 case DMUS_PATH_PERFORMANCE:
193 /* TODO check wanted GUID */
194 *ppObject = This->pPerf;
195 IUnknown_AddRef((LPUNKNOWN) *ppObject);
196 return S_OK;
198 break;
200 case DMUS_PATH_PERFORMANCE_GRAPH:
202 IDirectMusicGraph* pPerfoGraph = NULL;
203 IDirectMusicPerformance8_GetGraph(This->pPerf, &pPerfoGraph);
204 if (NULL == pPerfoGraph) {
205 IDirectMusicGraphImpl* pGraph = NULL;
206 hr = create_dmgraph(&IID_IDirectMusicGraph, (void**)&pGraph);
207 if (FAILED(hr))
208 return hr;
209 IDirectMusicPerformance8_SetGraph(This->pPerf, (IDirectMusicGraph*) pGraph);
210 /* we need release as SetGraph do an AddRef */
211 IDirectMusicGraph_Release((LPDIRECTMUSICGRAPH) pGraph);
212 pPerfoGraph = (LPDIRECTMUSICGRAPH) pGraph;
214 *ppObject = pPerfoGraph;
215 return S_OK;
217 break;
219 case DMUS_PATH_PERFORMANCE_TOOL:
220 default:
221 break;
224 *ppObject = NULL;
225 return E_INVALIDARG;
228 static HRESULT WINAPI IDirectMusicAudioPathImpl_Activate (IDirectMusicAudioPath *iface, BOOL fActivate)
230 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
231 FIXME("(%p, %d): stub\n", This, fActivate);
232 if (!fActivate) {
233 if (!This->fActive) return S_OK;
234 This->fActive = FALSE;
235 } else {
236 if (This->fActive) return S_OK;
237 This->fActive = TRUE;
238 if (NULL != This->pDSBuffer) {
239 IDirectSoundBuffer_Stop(This->pDSBuffer);
242 return S_OK;
245 static HRESULT WINAPI IDirectMusicAudioPathImpl_SetVolume (IDirectMusicAudioPath *iface, LONG lVolume, DWORD dwDuration)
247 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
248 FIXME("(%p, %i, %d): stub\n", This, lVolume, dwDuration);
249 return S_OK;
252 static HRESULT WINAPI IDirectMusicAudioPathImpl_ConvertPChannel (IDirectMusicAudioPath *iface, DWORD dwPChannelIn, DWORD* pdwPChannelOut)
254 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicAudioPath(iface);
255 FIXME("(%p, %d, %p): stub\n", This, dwPChannelIn, pdwPChannelOut);
256 return S_OK;
259 static const IDirectMusicAudioPathVtbl DirectMusicAudioPathVtbl = {
260 IDirectMusicAudioPathImpl_QueryInterface,
261 IDirectMusicAudioPathImpl_AddRef,
262 IDirectMusicAudioPathImpl_Release,
263 IDirectMusicAudioPathImpl_GetObjectInPath,
264 IDirectMusicAudioPathImpl_Activate,
265 IDirectMusicAudioPathImpl_SetVolume,
266 IDirectMusicAudioPathImpl_ConvertPChannel
269 /* IDirectMusicObject */
270 static HRESULT WINAPI DirectMusicObject_QueryInterface(IDirectMusicObject *iface, REFIID riid, void **ppobj)
272 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicObject(iface);
273 return IDirectMusicAudioPath_QueryInterface(&This->IDirectMusicAudioPath_iface, riid, ppobj);
276 static ULONG WINAPI DirectMusicObject_AddRef(IDirectMusicObject *iface)
278 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicObject(iface);
279 return IDirectMusicAudioPath_AddRef(&This->IDirectMusicAudioPath_iface);
282 static ULONG WINAPI DirectMusicObject_Release(IDirectMusicObject *iface)
284 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicObject(iface);
285 return IDirectMusicAudioPath_Release(&This->IDirectMusicAudioPath_iface);
288 static HRESULT WINAPI DirectMusicObject_GetDescriptor(IDirectMusicObject *iface, LPDMUS_OBJECTDESC pDesc)
290 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicObject(iface);
291 TRACE("(%p, %p)\n", This, pDesc);
292 /* I think we shouldn't return pointer here since then values can be changed; it'd be a mess */
293 memcpy (pDesc, This->pDesc, This->pDesc->dwSize);
294 return S_OK;
297 static HRESULT WINAPI DirectMusicObject_SetDescriptor(IDirectMusicObject *iface, LPDMUS_OBJECTDESC pDesc)
299 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicObject(iface);
301 TRACE("(%p, %p): setting descriptor:\n%s\n", This, pDesc, debugstr_DMUS_OBJECTDESC (pDesc));
303 /* According to MSDN, we should copy only given values, not whole struct */
304 if (pDesc->dwValidData & DMUS_OBJ_OBJECT)
305 This->pDesc->guidObject = pDesc->guidObject;
306 if (pDesc->dwValidData & DMUS_OBJ_CLASS)
307 This->pDesc->guidClass = pDesc->guidClass;
308 if (pDesc->dwValidData & DMUS_OBJ_NAME)
309 lstrcpynW (This->pDesc->wszName, pDesc->wszName, DMUS_MAX_NAME);
310 if (pDesc->dwValidData & DMUS_OBJ_CATEGORY)
311 lstrcpynW (This->pDesc->wszCategory, pDesc->wszCategory, DMUS_MAX_CATEGORY);
312 if (pDesc->dwValidData & DMUS_OBJ_FILENAME)
313 lstrcpynW (This->pDesc->wszFileName, pDesc->wszFileName, DMUS_MAX_FILENAME);
314 if (pDesc->dwValidData & DMUS_OBJ_VERSION)
315 This->pDesc->vVersion = pDesc->vVersion;
316 if (pDesc->dwValidData & DMUS_OBJ_DATE)
317 This->pDesc->ftDate = pDesc->ftDate;
318 if (pDesc->dwValidData & DMUS_OBJ_MEMORY) {
319 This->pDesc->llMemLength = pDesc->llMemLength;
320 memcpy (This->pDesc->pbMemData, pDesc->pbMemData, pDesc->llMemLength);
322 if (pDesc->dwValidData & DMUS_OBJ_STREAM) {
323 /* according to MSDN, we copy the stream */
324 IStream_Clone (pDesc->pStream, &This->pDesc->pStream);
327 /* add new flags */
328 This->pDesc->dwValidData |= pDesc->dwValidData;
330 return S_OK;
333 static HRESULT WINAPI DirectMusicObject_ParseDescriptor(IDirectMusicObject *iface, IStream *pStream, DMUS_OBJECTDESC *pDesc)
335 struct IDirectMusicAudioPathImpl *This = impl_from_IDirectMusicObject(iface);
336 DMUS_PRIVATE_CHUNK Chunk;
337 DWORD StreamSize, StreamCount, ListSize[1], ListCount[1];
338 LARGE_INTEGER liMove; /* used when skipping chunks */
340 TRACE("(%p, %p, %p)\n", This, pStream, pDesc);
342 /* FIXME: should this be determined from stream? */
343 pDesc->dwValidData |= DMUS_OBJ_CLASS;
344 pDesc->guidClass = This->pDesc->guidClass;
346 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
347 TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
348 switch (Chunk.fccID) {
349 case FOURCC_RIFF: {
350 IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
351 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID));
352 StreamSize = Chunk.dwSize - sizeof(FOURCC);
353 StreamCount = 0;
354 if (Chunk.fccID == DMUS_FOURCC_AUDIOPATH_FORM) {
355 TRACE_(dmfile)(": audio path form\n");
356 do {
357 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
358 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
359 TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
360 switch (Chunk.fccID) {
361 case DMUS_FOURCC_GUID_CHUNK: {
362 TRACE_(dmfile)(": GUID chunk\n");
363 pDesc->dwValidData |= DMUS_OBJ_OBJECT;
364 IStream_Read (pStream, &pDesc->guidObject, Chunk.dwSize, NULL);
365 break;
367 case DMUS_FOURCC_VERSION_CHUNK: {
368 TRACE_(dmfile)(": version chunk\n");
369 pDesc->dwValidData |= DMUS_OBJ_VERSION;
370 IStream_Read (pStream, &pDesc->vVersion, Chunk.dwSize, NULL);
371 break;
373 case DMUS_FOURCC_CATEGORY_CHUNK: {
374 TRACE_(dmfile)(": category chunk\n");
375 pDesc->dwValidData |= DMUS_OBJ_CATEGORY;
376 IStream_Read (pStream, pDesc->wszCategory, Chunk.dwSize, NULL);
377 break;
379 case FOURCC_LIST: {
380 IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
381 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
382 ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
383 ListCount[0] = 0;
384 switch (Chunk.fccID) {
385 /* evil M$ UNFO list, which can (!?) contain INFO elements */
386 case DMUS_FOURCC_UNFO_LIST: {
387 TRACE_(dmfile)(": UNFO list\n");
388 do {
389 IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
390 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
391 TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
392 switch (Chunk.fccID) {
393 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
394 (though strings seem to be valid unicode) */
395 case mmioFOURCC('I','N','A','M'):
396 case DMUS_FOURCC_UNAM_CHUNK: {
397 TRACE_(dmfile)(": name chunk\n");
398 pDesc->dwValidData |= DMUS_OBJ_NAME;
399 IStream_Read (pStream, pDesc->wszName, Chunk.dwSize, NULL);
400 break;
402 case mmioFOURCC('I','A','R','T'):
403 case DMUS_FOURCC_UART_CHUNK: {
404 TRACE_(dmfile)(": artist chunk (ignored)\n");
405 liMove.QuadPart = Chunk.dwSize;
406 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
407 break;
409 case mmioFOURCC('I','C','O','P'):
410 case DMUS_FOURCC_UCOP_CHUNK: {
411 TRACE_(dmfile)(": copyright chunk (ignored)\n");
412 liMove.QuadPart = Chunk.dwSize;
413 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
414 break;
416 case mmioFOURCC('I','S','B','J'):
417 case DMUS_FOURCC_USBJ_CHUNK: {
418 TRACE_(dmfile)(": subject chunk (ignored)\n");
419 liMove.QuadPart = Chunk.dwSize;
420 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
421 break;
423 case mmioFOURCC('I','C','M','T'):
424 case DMUS_FOURCC_UCMT_CHUNK: {
425 TRACE_(dmfile)(": comment chunk (ignored)\n");
426 liMove.QuadPart = Chunk.dwSize;
427 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
428 break;
430 default: {
431 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
432 liMove.QuadPart = Chunk.dwSize;
433 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
434 break;
437 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
438 } while (ListCount[0] < ListSize[0]);
439 break;
441 default: {
442 TRACE_(dmfile)(": unknown (skipping)\n");
443 liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
444 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
445 break;
448 break;
450 default: {
451 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
452 liMove.QuadPart = Chunk.dwSize;
453 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
454 break;
457 TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
458 } while (StreamCount < StreamSize);
459 } else {
460 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
461 liMove.QuadPart = StreamSize;
462 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
463 return E_FAIL;
466 TRACE_(dmfile)(": reading finished\n");
467 break;
469 default: {
470 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
471 liMove.QuadPart = Chunk.dwSize;
472 IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
473 return DMUS_E_INVALIDFILE;
477 TRACE(": returning descriptor:\n%s\n", debugstr_DMUS_OBJECTDESC (pDesc));
479 return S_OK;
482 static const IDirectMusicObjectVtbl DirectMusicObjectVtbl = {
483 DirectMusicObject_QueryInterface,
484 DirectMusicObject_AddRef,
485 DirectMusicObject_Release,
486 DirectMusicObject_GetDescriptor,
487 DirectMusicObject_SetDescriptor,
488 DirectMusicObject_ParseDescriptor
491 /* IPersistStream */
492 static HRESULT WINAPI PersistStream_QueryInterface(IPersistStream *iface, REFIID riid, void **ppobj)
494 struct IDirectMusicAudioPathImpl *This = impl_from_IPersistStream(iface);
495 return IDirectMusicAudioPath_QueryInterface(&This->IDirectMusicAudioPath_iface, riid, ppobj);
498 static ULONG WINAPI PersistStream_AddRef(IPersistStream *iface)
500 struct IDirectMusicAudioPathImpl *This = impl_from_IPersistStream(iface);
501 return IDirectMusicAudioPath_AddRef(&This->IDirectMusicAudioPath_iface);
504 static ULONG WINAPI PersistStream_Release(IPersistStream *iface)
506 struct IDirectMusicAudioPathImpl *This = impl_from_IPersistStream(iface);
507 return IDirectMusicAudioPath_Release(&This->IDirectMusicAudioPath_iface);
510 static HRESULT WINAPI PersistStream_GetClassID(IPersistStream *iface, CLSID* pClassID)
512 return E_NOTIMPL;
515 static HRESULT WINAPI PersistStream_IsDirty(IPersistStream *iface)
517 return E_NOTIMPL;
520 static HRESULT WINAPI PersistStream_Load(IPersistStream *iface, IStream *pStm)
522 struct IDirectMusicAudioPathImpl *This = impl_from_IPersistStream(iface);
524 FOURCC chunkID;
525 DWORD chunkSize, StreamSize, StreamCount, ListSize[3], ListCount[3];
526 LARGE_INTEGER liMove; /* used when skipping chunks */
528 FIXME("(%p, %p): Loading not implemented yet\n", This, pStm);
529 IStream_Read (pStm, &chunkID, sizeof(FOURCC), NULL);
530 IStream_Read (pStm, &chunkSize, sizeof(DWORD), NULL);
531 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (chunkID), chunkSize);
532 switch (chunkID) {
533 case FOURCC_RIFF: {
534 IStream_Read (pStm, &chunkID, sizeof(FOURCC), NULL);
535 TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(chunkID));
536 StreamSize = chunkSize - sizeof(FOURCC);
537 StreamCount = 0;
538 switch (chunkID) {
539 case DMUS_FOURCC_AUDIOPATH_FORM: {
540 TRACE_(dmfile)(": audio path form\n");
541 do {
542 IStream_Read (pStm, &chunkID, sizeof(FOURCC), NULL);
543 IStream_Read (pStm, &chunkSize, sizeof(FOURCC), NULL);
544 StreamCount += sizeof(FOURCC) + sizeof(DWORD) + chunkSize;
545 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (chunkID), chunkSize);
546 switch (chunkID) {
547 case DMUS_FOURCC_GUID_CHUNK: {
548 TRACE_(dmfile)(": GUID chunk\n");
549 This->pDesc->dwValidData |= DMUS_OBJ_OBJECT;
550 IStream_Read (pStm, &This->pDesc->guidObject, chunkSize, NULL);
551 break;
553 case DMUS_FOURCC_VERSION_CHUNK: {
554 TRACE_(dmfile)(": version chunk\n");
555 This->pDesc->dwValidData |= DMUS_OBJ_VERSION;
556 IStream_Read (pStm, &This->pDesc->vVersion, chunkSize, NULL);
557 break;
559 case DMUS_FOURCC_CATEGORY_CHUNK: {
560 TRACE_(dmfile)(": category chunk\n");
561 This->pDesc->dwValidData |= DMUS_OBJ_CATEGORY;
562 IStream_Read (pStm, This->pDesc->wszCategory, chunkSize, NULL);
563 break;
565 case FOURCC_LIST: {
566 IStream_Read (pStm, &chunkID, sizeof(FOURCC), NULL);
567 TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(chunkID));
568 ListSize[0] = chunkSize - sizeof(FOURCC);
569 ListCount[0] = 0;
570 switch (chunkID) {
571 case DMUS_FOURCC_UNFO_LIST: {
572 TRACE_(dmfile)(": UNFO list\n");
573 do {
574 IStream_Read (pStm, &chunkID, sizeof(FOURCC), NULL);
575 IStream_Read (pStm, &chunkSize, sizeof(FOURCC), NULL);
576 ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + chunkSize;
577 TRACE_(dmfile)(": %s chunk (size = %d)", debugstr_fourcc (chunkID), chunkSize);
578 switch (chunkID) {
579 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
580 (though strings seem to be valid unicode) */
581 case mmioFOURCC('I','N','A','M'):
582 case DMUS_FOURCC_UNAM_CHUNK: {
583 TRACE_(dmfile)(": name chunk\n");
584 This->pDesc->dwValidData |= DMUS_OBJ_NAME;
585 IStream_Read (pStm, This->pDesc->wszName, chunkSize, NULL);
586 break;
588 case mmioFOURCC('I','A','R','T'):
589 case DMUS_FOURCC_UART_CHUNK: {
590 TRACE_(dmfile)(": artist chunk (ignored)\n");
591 liMove.QuadPart = chunkSize;
592 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
593 break;
595 case mmioFOURCC('I','C','O','P'):
596 case DMUS_FOURCC_UCOP_CHUNK: {
597 TRACE_(dmfile)(": copyright chunk (ignored)\n");
598 liMove.QuadPart = chunkSize;
599 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
600 break;
602 case mmioFOURCC('I','S','B','J'):
603 case DMUS_FOURCC_USBJ_CHUNK: {
604 TRACE_(dmfile)(": subject chunk (ignored)\n");
605 liMove.QuadPart = chunkSize;
606 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
607 break;
609 case mmioFOURCC('I','C','M','T'):
610 case DMUS_FOURCC_UCMT_CHUNK: {
611 TRACE_(dmfile)(": comment chunk (ignored)\n");
612 liMove.QuadPart = chunkSize;
613 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
614 break;
616 default: {
617 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
618 liMove.QuadPart = chunkSize;
619 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
620 break;
623 TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
624 } while (ListCount[0] < ListSize[0]);
625 break;
627 default: {
628 TRACE_(dmfile)(": unknown (skipping)\n");
629 liMove.QuadPart = chunkSize - sizeof(FOURCC);
630 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
631 break;
634 break;
636 default: {
637 TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
638 liMove.QuadPart = chunkSize;
639 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL);
640 break;
643 TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
644 } while (StreamCount < StreamSize);
645 break;
647 default: {
648 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
649 liMove.QuadPart = StreamSize;
650 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
651 return E_FAIL;
654 TRACE_(dmfile)(": reading finished\n");
655 break;
657 default: {
658 TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
659 liMove.QuadPart = chunkSize;
660 IStream_Seek (pStm, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
661 return E_FAIL;
665 return S_OK;
668 static HRESULT WINAPI PersistStream_Save(IPersistStream *iface, IStream *pStm, BOOL fClearDirty)
670 return E_NOTIMPL;
673 static HRESULT WINAPI PersistStream_GetSizeMax(IPersistStream *iface, ULARGE_INTEGER *pcbSize)
675 return E_NOTIMPL;
678 static const IPersistStreamVtbl PersistStreamVtbl = {
679 PersistStream_QueryInterface,
680 PersistStream_AddRef,
681 PersistStream_Release,
682 PersistStream_GetClassID,
683 PersistStream_IsDirty,
684 PersistStream_Load,
685 PersistStream_Save,
686 PersistStream_GetSizeMax
689 /* for ClassFactory */
690 HRESULT WINAPI create_dmaudiopath(REFIID riid, void **ppobj)
692 IDirectMusicAudioPathImpl* obj;
693 HRESULT hr;
695 obj = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirectMusicAudioPathImpl));
696 if (NULL == obj) {
697 *ppobj = NULL;
698 return E_OUTOFMEMORY;
700 obj->IDirectMusicAudioPath_iface.lpVtbl = &DirectMusicAudioPathVtbl;
701 obj->IDirectMusicObject_iface.lpVtbl = &DirectMusicObjectVtbl;
702 obj->IPersistStream_iface.lpVtbl = &PersistStreamVtbl;
703 obj->pDesc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DMUS_OBJECTDESC));
704 DM_STRUCT_INIT(obj->pDesc);
705 obj->pDesc->dwValidData |= DMUS_OBJ_CLASS;
706 obj->pDesc->guidClass = CLSID_DirectMusicAudioPathConfig;
707 obj->ref = 1;
709 hr = IDirectMusicAudioPath_QueryInterface(&obj->IDirectMusicAudioPath_iface, riid, ppobj);
710 IDirectMusicAudioPath_Release(&obj->IDirectMusicAudioPath_iface);
711 return hr;