1 /* IDirectMusicContainerImpl
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 "dmloader_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(dmloader
);
23 WINE_DECLARE_DEBUG_CHANNEL(dmfile
);
25 #define DMUS_MAX_CATEGORY_SIZE DMUS_MAX_CATEGORY*sizeof(WCHAR)
26 #define DMUS_MAX_NAME_SIZE DMUS_MAX_NAME*sizeof(WCHAR)
27 #define DMUS_MAX_FILENAME_SIZE DMUS_MAX_FILENAME*sizeof(WCHAR)
29 typedef struct riff_chunk
{
34 /* contained object entry */
35 typedef struct container_entry
{
39 DWORD dwFlags
; /* DMUS_CONTAINED_OBJF_KEEP: keep object in loader's cache, even when container is released */
41 IDirectMusicObject
*pObject
; /* needed when releasing from loader's cache on container release */
42 } WINE_CONTAINER_ENTRY
, *LPWINE_CONTAINER_ENTRY
;
44 /*****************************************************************************
45 * IDirectMusicContainerImpl implementation
47 typedef struct IDirectMusicContainerImpl
{
48 IDirectMusicContainer IDirectMusicContainer_iface
;
49 struct dmobject dmobj
;
52 DMUS_IO_CONTAINER_HEADER Header
; /* header */
53 struct list
*pContainedObjects
; /* data */
54 } IDirectMusicContainerImpl
;
56 static inline IDirectMusicContainerImpl
*impl_from_IDirectMusicContainer(IDirectMusicContainer
*iface
)
58 return CONTAINING_RECORD(iface
, IDirectMusicContainerImpl
, IDirectMusicContainer_iface
);
61 static HRESULT
destroy_dmcontainer(IDirectMusicContainerImpl
*This
)
63 LPDIRECTMUSICLOADER pLoader
;
64 LPDIRECTMUSICGETLOADER pGetLoader
;
66 LPWINE_CONTAINER_ENTRY pContainedObject
;
68 /* get loader (from stream we loaded from) */
69 TRACE(": getting loader\n");
70 IStream_QueryInterface (This
->pStream
, &IID_IDirectMusicGetLoader
, (LPVOID
*)&pGetLoader
);
71 IDirectMusicGetLoader_GetLoader (pGetLoader
, &pLoader
);
72 IDirectMusicGetLoader_Release (pGetLoader
);
74 /* release objects from loader's cache (if appropriate) */
75 TRACE(": releasing objects from loader's cache\n");
76 LIST_FOR_EACH (pEntry
, This
->pContainedObjects
) {
77 pContainedObject
= LIST_ENTRY (pEntry
, WINE_CONTAINER_ENTRY
, entry
);
78 /* my tests indicate that container releases objects *only*
79 if they were loaded at its load-time (makes sense, it doesn't
80 have pointers to objects otherwise); BTW: native container seems
81 to ignore the flags (I won't) */
82 if (pContainedObject
->pObject
&& !(pContainedObject
->dwFlags
& DMUS_CONTAINED_OBJF_KEEP
)) {
83 /* flags say it shouldn't be kept in loader's cache */
84 IDirectMusicLoader_ReleaseObject (pLoader
, pContainedObject
->pObject
);
87 IDirectMusicLoader_Release (pLoader
);
89 /* release stream we loaded from */
90 IStream_Release (This
->pStream
);
92 /* FIXME: release allocated entries */
97 static HRESULT WINAPI
IDirectMusicContainerImpl_QueryInterface(IDirectMusicContainer
*iface
, REFIID riid
, void **ret_iface
)
99 IDirectMusicContainerImpl
*This
= impl_from_IDirectMusicContainer(iface
);
101 TRACE("(%p, %s, %p)\n", This
, debugstr_dmguid(riid
), ret_iface
);
103 if (IsEqualIID (riid
, &IID_IUnknown
) || IsEqualIID (riid
, &IID_IDirectMusicContainer
))
104 *ret_iface
= &This
->IDirectMusicContainer_iface
;
105 else if (IsEqualIID (riid
, &IID_IDirectMusicObject
))
106 *ret_iface
= &This
->dmobj
.IDirectMusicObject_iface
;
107 else if (IsEqualIID (riid
, &IID_IPersistStream
))
108 *ret_iface
= &This
->dmobj
.IPersistStream_iface
;
110 WARN("Unknown interface %s\n", debugstr_dmguid(riid
));
112 return E_NOINTERFACE
;
115 IUnknown_AddRef((IUnknown
*)*ret_iface
);
119 static ULONG WINAPI
IDirectMusicContainerImpl_AddRef(IDirectMusicContainer
*iface
)
121 IDirectMusicContainerImpl
*This
= impl_from_IDirectMusicContainer(iface
);
122 LONG ref
= InterlockedIncrement(&This
->ref
);
124 TRACE("(%p) ref=%d\n", This
, ref
);
129 static ULONG WINAPI
IDirectMusicContainerImpl_Release(IDirectMusicContainer
*iface
)
131 IDirectMusicContainerImpl
*This
= impl_from_IDirectMusicContainer(iface
);
132 LONG ref
= InterlockedDecrement(&This
->ref
);
134 TRACE("(%p) ref=%d\n", This
, ref
);
138 destroy_dmcontainer(This
);
139 HeapFree(GetProcessHeap(), 0, This
);
146 static HRESULT WINAPI
IDirectMusicContainerImpl_EnumObject(IDirectMusicContainer
*iface
,
147 REFGUID rguidClass
, DWORD dwIndex
, DMUS_OBJECTDESC
*pDesc
, WCHAR
*pwszAlias
)
149 IDirectMusicContainerImpl
*This
= impl_from_IDirectMusicContainer(iface
);
151 LPWINE_CONTAINER_ENTRY pContainedObject
;
154 TRACE("(%p, %s, %d, %p, %p)\n", This
, debugstr_dmguid(rguidClass
), dwIndex
, pDesc
, pwszAlias
);
158 if (pDesc
->dwSize
!= sizeof(DMUS_OBJECTDESC
)) {
159 ERR(": invalid pDesc->dwSize %d\n", pDesc
->dwSize
);
163 DM_STRUCT_INIT(pDesc
);
165 LIST_FOR_EACH (pEntry
, This
->pContainedObjects
) {
166 pContainedObject
= LIST_ENTRY (pEntry
, WINE_CONTAINER_ENTRY
, entry
);
168 if (IsEqualGUID (rguidClass
, &GUID_DirectMusicAllTypes
) || IsEqualGUID (rguidClass
, &pContainedObject
->Desc
.guidClass
)) {
169 if (dwCount
== dwIndex
) {
170 HRESULT result
= S_OK
;
172 lstrcpynW (pwszAlias
, pContainedObject
->wszAlias
, DMUS_MAX_FILENAME
);
173 if (lstrlenW (pContainedObject
->wszAlias
) > DMUS_MAX_FILENAME
)
174 result
= DMUS_S_STRING_TRUNCATED
;
176 *pDesc
= pContainedObject
->Desc
;
183 TRACE(": not found\n");
187 static const IDirectMusicContainerVtbl dmcontainer_vtbl
= {
188 IDirectMusicContainerImpl_QueryInterface
,
189 IDirectMusicContainerImpl_AddRef
,
190 IDirectMusicContainerImpl_Release
,
191 IDirectMusicContainerImpl_EnumObject
194 /* IDirectMusicObject part: */
195 static HRESULT WINAPI
cont_IDirectMusicObject_ParseDescriptor(IDirectMusicObject
*iface
,
196 IStream
*stream
, DMUS_OBJECTDESC
*desc
)
198 struct chunk_entry riff
= {0};
201 TRACE("(%p, %p, %p)\n", iface
, stream
, desc
);
205 if (!desc
|| desc
->dwSize
!= sizeof(*desc
))
208 if ((hr
= stream_get_chunk(stream
, &riff
)) != S_OK
)
210 if (riff
.id
!= FOURCC_RIFF
|| riff
.type
!= DMUS_FOURCC_CONTAINER_FORM
) {
211 TRACE("loading failed: unexpected %s\n", debugstr_chunk(&riff
));
212 stream_skip_chunk(stream
, &riff
);
213 return DMUS_E_DESCEND_CHUNK_FAIL
;
216 hr
= dmobj_parsedescriptor(stream
, &riff
, desc
,
217 DMUS_OBJ_OBJECT
|DMUS_OBJ_CLASS
|DMUS_OBJ_NAME
|DMUS_OBJ_CATEGORY
|DMUS_OBJ_VERSION
);
221 desc
->guidClass
= CLSID_DirectMusicContainer
;
222 desc
->dwValidData
|= DMUS_OBJ_CLASS
;
224 TRACE("returning descriptor:\n");
225 dump_DMUS_OBJECTDESC (desc
);
229 static const IDirectMusicObjectVtbl dmobject_vtbl
= {
230 dmobj_IDirectMusicObject_QueryInterface
,
231 dmobj_IDirectMusicObject_AddRef
,
232 dmobj_IDirectMusicObject_Release
,
233 dmobj_IDirectMusicObject_GetDescriptor
,
234 dmobj_IDirectMusicObject_SetDescriptor
,
235 cont_IDirectMusicObject_ParseDescriptor
238 /* IPersistStream part: */
239 static inline IDirectMusicContainerImpl
*impl_from_IPersistStream(IPersistStream
*iface
)
241 return CONTAINING_RECORD(iface
, IDirectMusicContainerImpl
, dmobj
.IPersistStream_iface
);
244 static HRESULT WINAPI
IPersistStreamImpl_Load(IPersistStream
*iface
, IStream
*pStm
)
246 IDirectMusicContainerImpl
*This
= impl_from_IPersistStream(iface
);
248 DWORD StreamSize
, StreamCount
, ListSize
[3], ListCount
[3];
249 LARGE_INTEGER liMove
; /* used when skipping chunks */
250 ULARGE_INTEGER uliPos
; /* needed when dealing with RIFF chunks */
251 LPDIRECTMUSICGETLOADER pGetLoader
;
252 LPDIRECTMUSICLOADER pLoader
;
253 HRESULT result
= S_OK
;
255 TRACE("(%p, %p):\n", This
, pStm
);
257 /* check whether pStm is valid read pointer */
258 if (IsBadReadPtr (pStm
, sizeof(LPVOID
))) {
259 ERR(": pStm bad read pointer\n");
262 /* if stream is already set, this means the container is already loaded */
264 TRACE(": stream is already set, which means container is already loaded\n");
265 return DMUS_E_ALREADY_LOADED
;
268 /* get loader since it will be needed later */
269 if (FAILED(IStream_QueryInterface (pStm
, &IID_IDirectMusicGetLoader
, (LPVOID
*)&pGetLoader
))) {
270 ERR(": stream not supported\n");
271 return DMUS_E_UNSUPPORTED_STREAM
;
273 IDirectMusicGetLoader_GetLoader (pGetLoader
, &pLoader
);
274 IDirectMusicGetLoader_Release (pGetLoader
);
276 This
->pStream
= pStm
;
277 IStream_AddRef (pStm
); /* add count for later references */
279 /* start with load */
280 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
281 TRACE_(dmfile
)(": %s chunk (size = 0x%08X)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
282 switch (Chunk
.fccID
) {
284 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
285 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
286 StreamSize
= Chunk
.dwSize
- sizeof(FOURCC
);
288 switch (Chunk
.fccID
) {
289 case DMUS_FOURCC_CONTAINER_FORM
: {
290 TRACE_(dmfile
)(": container form\n");
291 This
->dmobj
.desc
.guidClass
= CLSID_DirectMusicContainer
;
292 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_CLASS
;
294 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
295 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
296 TRACE_(dmfile
)(": %s chunk (size = 0x%08X)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
297 switch (Chunk
.fccID
) {
298 case DMUS_FOURCC_CONTAINER_CHUNK
: {
299 IStream_Read (pStm
, &This
->Header
, Chunk
.dwSize
, NULL
);
300 TRACE_(dmfile
)(": container header chunk:\n%s\n", debugstr_DMUS_IO_CONTAINER_HEADER(&This
->Header
));
303 case DMUS_FOURCC_GUID_CHUNK
: {
304 TRACE_(dmfile
)(": GUID chunk\n");
305 IStream_Read (pStm
, &This
->dmobj
.desc
.guidObject
, Chunk
.dwSize
, NULL
);
306 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_OBJECT
;
309 case DMUS_FOURCC_VERSION_CHUNK
: {
310 TRACE_(dmfile
)(": version chunk\n");
311 IStream_Read (pStm
, &This
->dmobj
.desc
.vVersion
, Chunk
.dwSize
, NULL
);
312 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_VERSION
;
315 case DMUS_FOURCC_DATE_CHUNK
: {
316 TRACE_(dmfile
)(": date chunk\n");
317 IStream_Read (pStm
, &This
->dmobj
.desc
.ftDate
, Chunk
.dwSize
, NULL
);
318 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_DATE
;
321 case DMUS_FOURCC_CATEGORY_CHUNK
: {
322 TRACE_(dmfile
)(": category chunk\n");
323 /* if it happens that string is too long,
324 read what we can and skip the rest*/
325 if (Chunk
.dwSize
> DMUS_MAX_CATEGORY_SIZE
) {
326 IStream_Read (pStm
, This
->dmobj
.desc
.wszCategory
, DMUS_MAX_CATEGORY_SIZE
, NULL
);
327 liMove
.QuadPart
= Chunk
.dwSize
- DMUS_MAX_CATEGORY_SIZE
;
328 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
330 IStream_Read (pStm
, This
->dmobj
.desc
.wszCategory
, Chunk
.dwSize
, NULL
);
332 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_CATEGORY
;
336 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
337 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
338 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
340 switch (Chunk
.fccID
) {
341 case DMUS_FOURCC_UNFO_LIST
: {
342 TRACE_(dmfile
)(": UNFO list\n");
344 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
345 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
346 TRACE_(dmfile
)(": %s chunk (size = 0x%08X)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
347 switch (Chunk
.fccID
) {
348 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
349 (though strings seem to be valid unicode) */
350 case mmioFOURCC('I','N','A','M'):
351 case DMUS_FOURCC_UNAM_CHUNK
: {
352 TRACE_(dmfile
)(": name chunk\n");
353 /* if it happens that string is too long,
354 read what we can and skip the rest*/
355 if (Chunk
.dwSize
> DMUS_MAX_NAME_SIZE
) {
356 IStream_Read (pStm
, This
->dmobj
.desc
.wszName
, DMUS_MAX_NAME_SIZE
, NULL
);
357 liMove
.QuadPart
= Chunk
.dwSize
- DMUS_MAX_NAME_SIZE
;
358 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
360 IStream_Read (pStm
, This
->dmobj
.desc
.wszName
, Chunk
.dwSize
, NULL
);
362 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_NAME
;
366 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
367 liMove
.QuadPart
= Chunk
.dwSize
;
368 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
372 TRACE_(dmfile
)(": ListCount[0] = 0x%08X < ListSize[0] = 0x%08X\n", ListCount
[0], ListSize
[0]);
373 } while (ListCount
[0] < ListSize
[0]);
376 case DMUS_FOURCC_CONTAINED_OBJECTS_LIST
: {
377 TRACE_(dmfile
)(": contained objects list\n");
379 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
380 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
381 TRACE_(dmfile
)(": %s chunk (size = 0x%08X)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
382 switch (Chunk
.fccID
) {
384 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
385 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
386 ListSize
[1] = Chunk
.dwSize
- sizeof(FOURCC
);
388 switch (Chunk
.fccID
) {
389 case DMUS_FOURCC_CONTAINED_OBJECT_LIST
: {
390 LPWINE_CONTAINER_ENTRY pNewEntry
;
391 TRACE_(dmfile
)(": contained object list\n");
392 pNewEntry
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(WINE_CONTAINER_ENTRY
));
393 DM_STRUCT_INIT(&pNewEntry
->Desc
);
395 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
396 ListCount
[1] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
397 TRACE_(dmfile
)(": %s chunk (size = 0x%08X)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
398 switch (Chunk
.fccID
) {
399 case DMUS_FOURCC_CONTAINED_ALIAS_CHUNK
: {
400 TRACE_(dmfile
)(": alias chunk\n");
401 pNewEntry
->wszAlias
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, Chunk
.dwSize
);
402 IStream_Read (pStm
, pNewEntry
->wszAlias
, Chunk
.dwSize
, NULL
);
403 TRACE_(dmfile
)(": alias: %s\n", debugstr_w(pNewEntry
->wszAlias
));
406 case DMUS_FOURCC_CONTAINED_OBJECT_CHUNK
: {
407 DMUS_IO_CONTAINED_OBJECT_HEADER tmpObjectHeader
;
408 IStream_Read (pStm
, &tmpObjectHeader
, Chunk
.dwSize
, NULL
);
409 TRACE_(dmfile
)(": contained object header:\n%s\n", debugstr_DMUS_IO_CONTAINED_OBJECT_HEADER(&tmpObjectHeader
));
411 pNewEntry
->Desc
.dwValidData
|= DMUS_OBJ_CLASS
;
412 pNewEntry
->Desc
.guidClass
= tmpObjectHeader
.guidClassID
;
414 pNewEntry
->dwFlags
= tmpObjectHeader
.dwFlags
;
417 /* now read data... it may be safe to read everything after object header chunk,
418 but I'm not comfortable with MSDN's "the header is *normally* followed by ..." */
420 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
421 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
422 ListSize
[2] = Chunk
.dwSize
- sizeof(FOURCC
);
424 switch (Chunk
.fccID
) {
425 case DMUS_FOURCC_REF_LIST
: {
426 TRACE_(dmfile
)(": reference list\n");
427 pNewEntry
->bIsRIFF
= 0;
429 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
430 ListCount
[2] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
431 TRACE_(dmfile
)(": %s chunk (size = 0x%08X)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
432 switch (Chunk
.fccID
) {
433 case DMUS_FOURCC_REF_CHUNK
: {
434 DMUS_IO_REFERENCE tmpReferenceHeader
; /* temporary structure */
435 TRACE_(dmfile
)(": reference header chunk\n");
436 memset (&tmpReferenceHeader
, 0, sizeof(DMUS_IO_REFERENCE
));
437 IStream_Read (pStm
, &tmpReferenceHeader
, Chunk
.dwSize
, NULL
);
438 /* copy retrieved data to DMUS_OBJECTDESC */
439 if (!IsEqualCLSID (&pNewEntry
->Desc
.guidClass
, &tmpReferenceHeader
.guidClassID
)) ERR(": object header declares different CLSID than reference header?\n");
440 /* it shouldn't be necessary to copy guidClass, since it was set in contained object header already...
441 yet if they happen to be different, I'd rather stick to this one */
442 pNewEntry
->Desc
.guidClass
= tmpReferenceHeader
.guidClassID
;
443 pNewEntry
->Desc
.dwValidData
|= tmpReferenceHeader
.dwValidData
;
446 case DMUS_FOURCC_GUID_CHUNK
: {
447 TRACE_(dmfile
)(": guid chunk\n");
448 /* no need to set flags since they were copied from reference header */
449 IStream_Read (pStm
, &pNewEntry
->Desc
.guidObject
, Chunk
.dwSize
, NULL
);
452 case DMUS_FOURCC_DATE_CHUNK
: {
453 TRACE_(dmfile
)(": file date chunk\n");
454 /* no need to set flags since they were copied from reference header */
455 IStream_Read (pStm
, &pNewEntry
->Desc
.ftDate
, Chunk
.dwSize
, NULL
);
458 case DMUS_FOURCC_NAME_CHUNK
: {
459 TRACE_(dmfile
)(": name chunk\n");
460 /* no need to set flags since they were copied from reference header */
461 IStream_Read (pStm
, pNewEntry
->Desc
.wszName
, Chunk
.dwSize
, NULL
);
464 case DMUS_FOURCC_FILE_CHUNK
: {
465 TRACE_(dmfile
)(": file name chunk\n");
466 /* no need to set flags since they were copied from reference header */
467 IStream_Read (pStm
, pNewEntry
->Desc
.wszFileName
, Chunk
.dwSize
, NULL
);
470 case DMUS_FOURCC_CATEGORY_CHUNK
: {
471 TRACE_(dmfile
)(": category chunk\n");
472 /* no need to set flags since they were copied from reference header */
473 IStream_Read (pStm
, pNewEntry
->Desc
.wszCategory
, Chunk
.dwSize
, NULL
);
476 case DMUS_FOURCC_VERSION_CHUNK
: {
477 TRACE_(dmfile
)(": version chunk\n");
478 /* no need to set flags since they were copied from reference header */
479 IStream_Read (pStm
, &pNewEntry
->Desc
.vVersion
, Chunk
.dwSize
, NULL
);
483 TRACE_(dmfile
)(": unknown chunk (skipping)\n");
484 liMove
.QuadPart
= Chunk
.dwSize
;
485 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip this chunk */
489 TRACE_(dmfile
)(": ListCount[2] = 0x%08X < ListSize[2] = 0x%08X\n", ListCount
[2], ListSize
[2]);
490 } while (ListCount
[2] < ListSize
[2]);
494 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
502 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
503 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
504 if (IS_VALID_DMFORM (Chunk
.fccID
)) {
505 TRACE_(dmfile
)(": valid DMUSIC form\n");
506 pNewEntry
->bIsRIFF
= 1;
507 /* we'll have to skip whole RIFF chunk after SetObject is called */
509 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, &uliPos
);
510 uliPos
.QuadPart
+= (Chunk
.dwSize
- sizeof(FOURCC
)); /* set uliPos at the end of RIFF chunk */
511 /* move at the beginning of RIFF chunk */
513 liMove
.QuadPart
-= (sizeof(FOURCC
)+sizeof(DWORD
)+sizeof(FOURCC
));
514 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
515 /* put pointer to stream in descriptor */
516 pNewEntry
->Desc
.dwValidData
|= DMUS_OBJ_STREAM
;
517 pNewEntry
->Desc
.pStream
= pStm
; /* we don't have to worry about cloning, since SetObject will perform it */
518 /* wait till we get on the end of object list */
520 TRACE_(dmfile
)(": invalid DMUSIC form (skipping)\n");
521 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
522 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
523 /* FIXME: should we return E_FAIL? */
528 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
529 liMove
.QuadPart
= Chunk
.dwSize
;
530 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
534 TRACE_(dmfile
)(": ListCount[1] = 0x%08X < ListSize[1] = 0x%08X\n", ListCount
[1], ListSize
[1]);
535 } while (ListCount
[1] < ListSize
[1]);
536 /* SetObject: this will fill descriptor with additional info and add alias in loader's cache */
537 IDirectMusicLoader_SetObject (pLoader
, &pNewEntry
->Desc
);
538 /* now that SetObject collected appropriate info into descriptor we can live happily ever after;
539 or not, since we have to clean evidence of loading through stream... *sigh*
540 and we have to skip rest of the chunk, if we loaded through RIFF */
541 if (pNewEntry
->bIsRIFF
) {
542 liMove
.QuadPart
= uliPos
.QuadPart
;
543 IStream_Seek (pStm
, liMove
, STREAM_SEEK_SET
, NULL
);
544 pNewEntry
->Desc
.dwValidData
&= ~DMUS_OBJ_STREAM
; /* clear flag (and with bitwise complement) */
545 pNewEntry
->Desc
.pStream
= NULL
;
547 /* add entry to list of objects */
548 list_add_tail (This
->pContainedObjects
, &pNewEntry
->entry
);
552 TRACE_(dmfile
)(": unknown (skipping)\n");
553 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
554 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
561 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
562 liMove
.QuadPart
= Chunk
.dwSize
;
563 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
567 TRACE_(dmfile
)(": ListCount[0] = 0x%08X < ListSize[0] = 0x%08X\n", ListCount
[0], ListSize
[0]);
568 } while (ListCount
[0] < ListSize
[0]);
572 TRACE_(dmfile
)(": unknown (skipping)\n");
573 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
574 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
581 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
582 liMove
.QuadPart
= Chunk
.dwSize
;
583 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
587 TRACE_(dmfile
)(": StreamCount[0] = 0x%08X < StreamSize[0] = 0x%08X\n", StreamCount
, StreamSize
);
588 } while (StreamCount
< StreamSize
);
592 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
593 liMove
.QuadPart
= StreamSize
;
594 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
598 TRACE_(dmfile
)(": reading finished\n");
599 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_LOADED
;
600 dump_DMUS_OBJECTDESC(&This
->dmobj
.desc
);
604 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
605 liMove
.QuadPart
= Chunk
.dwSize
;
606 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
611 /* now, if DMUS_CONTAINER_NOLOADS is not set, we are supposed to load contained objects;
612 so when we call GetObject later, they'll already be in cache */
613 if (!(This
->Header
.dwFlags
& DMUS_CONTAINER_NOLOADS
)) {
615 LPWINE_CONTAINER_ENTRY pContainedObject
;
617 TRACE(": DMUS_CONTAINER_NOLOADS not set... load all objects\n");
619 LIST_FOR_EACH (pEntry
, This
->pContainedObjects
) {
620 IDirectMusicObject
* pObject
;
621 pContainedObject
= LIST_ENTRY (pEntry
, WINE_CONTAINER_ENTRY
, entry
);
622 /* get object from loader and then release it */
623 if (SUCCEEDED(IDirectMusicLoader_GetObject (pLoader
, &pContainedObject
->Desc
, &IID_IDirectMusicObject
, (LPVOID
*)&pObject
))) {
624 pContainedObject
->pObject
= pObject
; /* for final release */
625 IDirectMusicObject_Release (pObject
); /* we don't really need this one */
627 WARN(": failed to load contained object\n");
628 result
= DMUS_S_PARTIALLOAD
;
633 IDirectMusicLoader_Release (pLoader
); /* release loader */
638 static const IPersistStreamVtbl persiststream_vtbl
= {
639 dmobj_IPersistStream_QueryInterface
,
640 dmobj_IPersistStream_AddRef
,
641 dmobj_IPersistStream_Release
,
642 dmobj_IPersistStream_GetClassID
,
643 unimpl_IPersistStream_IsDirty
,
644 IPersistStreamImpl_Load
,
645 unimpl_IPersistStream_Save
,
646 unimpl_IPersistStream_GetSizeMax
649 /* for ClassFactory */
650 HRESULT WINAPI
create_dmcontainer(REFIID lpcGUID
, void **ppobj
)
652 IDirectMusicContainerImpl
* obj
;
655 obj
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDirectMusicContainerImpl
));
658 return E_OUTOFMEMORY
;
660 obj
->IDirectMusicContainer_iface
.lpVtbl
= &dmcontainer_vtbl
;
662 dmobject_init(&obj
->dmobj
, &CLSID_DirectMusicContainer
,
663 (IUnknown
*)&obj
->IDirectMusicContainer_iface
);
664 obj
->dmobj
.IDirectMusicObject_iface
.lpVtbl
= &dmobject_vtbl
;
665 obj
->dmobj
.IPersistStream_iface
.lpVtbl
= &persiststream_vtbl
;
666 obj
->pContainedObjects
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(struct list
));
667 list_init (obj
->pContainedObjects
);
671 hr
= IDirectMusicContainer_QueryInterface(&obj
->IDirectMusicContainer_iface
, lpcGUID
, ppobj
);
672 IDirectMusicContainer_Release(&obj
->IDirectMusicContainer_iface
);