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=%ld\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=%ld\n", This
, ref
);
138 destroy_dmcontainer(This
);
145 static HRESULT WINAPI
IDirectMusicContainerImpl_EnumObject(IDirectMusicContainer
*iface
,
146 REFGUID rguidClass
, DWORD dwIndex
, DMUS_OBJECTDESC
*pDesc
, WCHAR
*pwszAlias
)
148 IDirectMusicContainerImpl
*This
= impl_from_IDirectMusicContainer(iface
);
150 LPWINE_CONTAINER_ENTRY pContainedObject
;
153 TRACE("(%p, %s, %ld, %p, %p)\n", This
, debugstr_dmguid(rguidClass
), dwIndex
, pDesc
, pwszAlias
);
157 if (pDesc
->dwSize
!= sizeof(DMUS_OBJECTDESC
)) {
158 ERR(": invalid pDesc->dwSize %ld\n", pDesc
->dwSize
);
162 DM_STRUCT_INIT(pDesc
);
164 LIST_FOR_EACH (pEntry
, This
->pContainedObjects
) {
165 pContainedObject
= LIST_ENTRY (pEntry
, WINE_CONTAINER_ENTRY
, entry
);
167 if (IsEqualGUID (rguidClass
, &GUID_DirectMusicAllTypes
) || IsEqualGUID (rguidClass
, &pContainedObject
->Desc
.guidClass
)) {
168 if (dwCount
== dwIndex
) {
169 HRESULT result
= S_OK
;
171 lstrcpynW (pwszAlias
, pContainedObject
->wszAlias
, DMUS_MAX_FILENAME
);
172 if (lstrlenW (pContainedObject
->wszAlias
) > DMUS_MAX_FILENAME
)
173 result
= DMUS_S_STRING_TRUNCATED
;
175 *pDesc
= pContainedObject
->Desc
;
182 TRACE(": not found\n");
186 static const IDirectMusicContainerVtbl dmcontainer_vtbl
= {
187 IDirectMusicContainerImpl_QueryInterface
,
188 IDirectMusicContainerImpl_AddRef
,
189 IDirectMusicContainerImpl_Release
,
190 IDirectMusicContainerImpl_EnumObject
193 /* IDirectMusicObject part: */
194 static HRESULT WINAPI
cont_IDirectMusicObject_ParseDescriptor(IDirectMusicObject
*iface
,
195 IStream
*stream
, DMUS_OBJECTDESC
*desc
)
197 struct chunk_entry riff
= {0};
200 TRACE("(%p, %p, %p)\n", iface
, stream
, desc
);
204 if (!desc
|| desc
->dwSize
!= sizeof(*desc
))
207 if ((hr
= stream_get_chunk(stream
, &riff
)) != S_OK
)
209 if (riff
.id
!= FOURCC_RIFF
|| riff
.type
!= DMUS_FOURCC_CONTAINER_FORM
) {
210 TRACE("loading failed: unexpected %s\n", debugstr_chunk(&riff
));
211 stream_skip_chunk(stream
, &riff
);
212 return DMUS_E_DESCEND_CHUNK_FAIL
;
215 hr
= dmobj_parsedescriptor(stream
, &riff
, desc
,
216 DMUS_OBJ_OBJECT
|DMUS_OBJ_CLASS
|DMUS_OBJ_NAME
|DMUS_OBJ_CATEGORY
|DMUS_OBJ_VERSION
);
220 desc
->guidClass
= CLSID_DirectMusicContainer
;
221 desc
->dwValidData
|= DMUS_OBJ_CLASS
;
223 TRACE("returning descriptor:\n");
224 dump_DMUS_OBJECTDESC (desc
);
228 static const IDirectMusicObjectVtbl dmobject_vtbl
= {
229 dmobj_IDirectMusicObject_QueryInterface
,
230 dmobj_IDirectMusicObject_AddRef
,
231 dmobj_IDirectMusicObject_Release
,
232 dmobj_IDirectMusicObject_GetDescriptor
,
233 dmobj_IDirectMusicObject_SetDescriptor
,
234 cont_IDirectMusicObject_ParseDescriptor
237 /* IPersistStream part: */
238 static inline IDirectMusicContainerImpl
*impl_from_IPersistStream(IPersistStream
*iface
)
240 return CONTAINING_RECORD(iface
, IDirectMusicContainerImpl
, dmobj
.IPersistStream_iface
);
243 static HRESULT WINAPI
IPersistStreamImpl_Load(IPersistStream
*iface
, IStream
*pStm
)
245 IDirectMusicContainerImpl
*This
= impl_from_IPersistStream(iface
);
247 DWORD StreamSize
, StreamCount
, ListSize
[3], ListCount
[3];
248 LARGE_INTEGER liMove
; /* used when skipping chunks */
249 ULARGE_INTEGER uliPos
; /* needed when dealing with RIFF chunks */
250 LPDIRECTMUSICGETLOADER pGetLoader
;
251 LPDIRECTMUSICLOADER pLoader
;
252 HRESULT result
= S_OK
;
254 TRACE("(%p, %p):\n", This
, pStm
);
256 /* check whether pStm is valid read pointer */
257 if (IsBadReadPtr (pStm
, sizeof(LPVOID
))) {
258 ERR(": pStm bad read pointer\n");
261 /* if stream is already set, this means the container is already loaded */
263 TRACE(": stream is already set, which means container is already loaded\n");
264 return DMUS_E_ALREADY_LOADED
;
267 /* get loader since it will be needed later */
268 if (FAILED(IStream_QueryInterface (pStm
, &IID_IDirectMusicGetLoader
, (LPVOID
*)&pGetLoader
))) {
269 ERR(": stream not supported\n");
270 return DMUS_E_UNSUPPORTED_STREAM
;
272 IDirectMusicGetLoader_GetLoader (pGetLoader
, &pLoader
);
273 IDirectMusicGetLoader_Release (pGetLoader
);
275 This
->pStream
= pStm
;
276 IStream_AddRef (pStm
); /* add count for later references */
278 /* start with load */
279 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
280 TRACE_(dmfile
)(": %s chunk (size = %#lx)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
281 switch (Chunk
.fccID
) {
283 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
284 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
285 StreamSize
= Chunk
.dwSize
- sizeof(FOURCC
);
287 switch (Chunk
.fccID
) {
288 case DMUS_FOURCC_CONTAINER_FORM
: {
289 TRACE_(dmfile
)(": container form\n");
290 This
->dmobj
.desc
.guidClass
= CLSID_DirectMusicContainer
;
291 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_CLASS
;
293 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
294 StreamCount
+= sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
295 TRACE_(dmfile
)(": %s chunk (size = %#lx)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
296 switch (Chunk
.fccID
) {
297 case DMUS_FOURCC_CONTAINER_CHUNK
: {
298 IStream_Read (pStm
, &This
->Header
, Chunk
.dwSize
, NULL
);
299 TRACE_(dmfile
)(": container header chunk:\n%s\n", debugstr_DMUS_IO_CONTAINER_HEADER(&This
->Header
));
302 case DMUS_FOURCC_GUID_CHUNK
: {
303 TRACE_(dmfile
)(": GUID chunk\n");
304 IStream_Read (pStm
, &This
->dmobj
.desc
.guidObject
, Chunk
.dwSize
, NULL
);
305 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_OBJECT
;
308 case DMUS_FOURCC_VERSION_CHUNK
: {
309 TRACE_(dmfile
)(": version chunk\n");
310 IStream_Read (pStm
, &This
->dmobj
.desc
.vVersion
, Chunk
.dwSize
, NULL
);
311 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_VERSION
;
314 case DMUS_FOURCC_DATE_CHUNK
: {
315 TRACE_(dmfile
)(": date chunk\n");
316 IStream_Read (pStm
, &This
->dmobj
.desc
.ftDate
, Chunk
.dwSize
, NULL
);
317 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_DATE
;
320 case DMUS_FOURCC_CATEGORY_CHUNK
: {
321 TRACE_(dmfile
)(": category chunk\n");
322 /* if it happens that string is too long,
323 read what we can and skip the rest*/
324 if (Chunk
.dwSize
> DMUS_MAX_CATEGORY_SIZE
) {
325 IStream_Read (pStm
, This
->dmobj
.desc
.wszCategory
, DMUS_MAX_CATEGORY_SIZE
, NULL
);
326 liMove
.QuadPart
= Chunk
.dwSize
- DMUS_MAX_CATEGORY_SIZE
;
327 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
329 IStream_Read (pStm
, This
->dmobj
.desc
.wszCategory
, Chunk
.dwSize
, NULL
);
331 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_CATEGORY
;
335 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
336 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
337 ListSize
[0] = Chunk
.dwSize
- sizeof(FOURCC
);
339 switch (Chunk
.fccID
) {
340 case DMUS_FOURCC_UNFO_LIST
: {
341 TRACE_(dmfile
)(": UNFO list\n");
343 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
344 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
345 TRACE_(dmfile
)(": %s chunk (size = %#lx)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
346 switch (Chunk
.fccID
) {
347 /* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
348 (though strings seem to be valid unicode) */
349 case mmioFOURCC('I','N','A','M'):
350 case DMUS_FOURCC_UNAM_CHUNK
: {
351 TRACE_(dmfile
)(": name chunk\n");
352 /* if it happens that string is too long,
353 read what we can and skip the rest*/
354 if (Chunk
.dwSize
> DMUS_MAX_NAME_SIZE
) {
355 IStream_Read (pStm
, This
->dmobj
.desc
.wszName
, DMUS_MAX_NAME_SIZE
, NULL
);
356 liMove
.QuadPart
= Chunk
.dwSize
- DMUS_MAX_NAME_SIZE
;
357 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
359 IStream_Read (pStm
, This
->dmobj
.desc
.wszName
, Chunk
.dwSize
, NULL
);
361 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_NAME
;
365 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
366 liMove
.QuadPart
= Chunk
.dwSize
;
367 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
371 TRACE_(dmfile
)(": ListCount[0] = %#lx < ListSize[0] = %#lx\n", ListCount
[0], ListSize
[0]);
372 } while (ListCount
[0] < ListSize
[0]);
375 case DMUS_FOURCC_CONTAINED_OBJECTS_LIST
: {
376 TRACE_(dmfile
)(": contained objects list\n");
378 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
379 ListCount
[0] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
380 TRACE_(dmfile
)(": %s chunk (size = %#lx)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
381 switch (Chunk
.fccID
) {
383 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
384 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
385 ListSize
[1] = Chunk
.dwSize
- sizeof(FOURCC
);
387 switch (Chunk
.fccID
) {
388 case DMUS_FOURCC_CONTAINED_OBJECT_LIST
: {
389 LPWINE_CONTAINER_ENTRY pNewEntry
;
390 TRACE_(dmfile
)(": contained object list\n");
391 pNewEntry
= calloc(1, sizeof(*pNewEntry
));
392 DM_STRUCT_INIT(&pNewEntry
->Desc
);
394 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
395 ListCount
[1] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
396 TRACE_(dmfile
)(": %s chunk (size = %#lx)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
397 switch (Chunk
.fccID
) {
398 case DMUS_FOURCC_CONTAINED_ALIAS_CHUNK
: {
399 TRACE_(dmfile
)(": alias chunk\n");
400 pNewEntry
->wszAlias
= calloc(1, Chunk
.dwSize
);
401 IStream_Read (pStm
, pNewEntry
->wszAlias
, Chunk
.dwSize
, NULL
);
402 TRACE_(dmfile
)(": alias: %s\n", debugstr_w(pNewEntry
->wszAlias
));
405 case DMUS_FOURCC_CONTAINED_OBJECT_CHUNK
: {
406 DMUS_IO_CONTAINED_OBJECT_HEADER tmpObjectHeader
;
407 IStream_Read (pStm
, &tmpObjectHeader
, Chunk
.dwSize
, NULL
);
408 TRACE_(dmfile
)(": contained object header:\n%s\n", debugstr_DMUS_IO_CONTAINED_OBJECT_HEADER(&tmpObjectHeader
));
410 pNewEntry
->Desc
.dwValidData
|= DMUS_OBJ_CLASS
;
411 pNewEntry
->Desc
.guidClass
= tmpObjectHeader
.guidClassID
;
413 pNewEntry
->dwFlags
= tmpObjectHeader
.dwFlags
;
416 /* now read data... it may be safe to read everything after object header chunk,
417 but I'm not comfortable with MSDN's "the header is *normally* followed by ..." */
419 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
420 TRACE_(dmfile
)(": LIST chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
421 ListSize
[2] = Chunk
.dwSize
- sizeof(FOURCC
);
423 switch (Chunk
.fccID
) {
424 case DMUS_FOURCC_REF_LIST
: {
425 TRACE_(dmfile
)(": reference list\n");
426 pNewEntry
->bIsRIFF
= 0;
428 IStream_Read (pStm
, &Chunk
, sizeof(FOURCC
)+sizeof(DWORD
), NULL
);
429 ListCount
[2] += sizeof(FOURCC
) + sizeof(DWORD
) + Chunk
.dwSize
;
430 TRACE_(dmfile
)(": %s chunk (size = %#lx)", debugstr_fourcc (Chunk
.fccID
), Chunk
.dwSize
);
431 switch (Chunk
.fccID
) {
432 case DMUS_FOURCC_REF_CHUNK
: {
433 DMUS_IO_REFERENCE tmpReferenceHeader
; /* temporary structure */
434 TRACE_(dmfile
)(": reference header chunk\n");
435 memset (&tmpReferenceHeader
, 0, sizeof(DMUS_IO_REFERENCE
));
436 IStream_Read (pStm
, &tmpReferenceHeader
, Chunk
.dwSize
, NULL
);
437 /* copy retrieved data to DMUS_OBJECTDESC */
438 if (!IsEqualCLSID (&pNewEntry
->Desc
.guidClass
, &tmpReferenceHeader
.guidClassID
)) ERR(": object header declares different CLSID than reference header?\n");
439 /* it shouldn't be necessary to copy guidClass, since it was set in contained object header already...
440 yet if they happen to be different, I'd rather stick to this one */
441 pNewEntry
->Desc
.guidClass
= tmpReferenceHeader
.guidClassID
;
442 pNewEntry
->Desc
.dwValidData
|= tmpReferenceHeader
.dwValidData
;
445 case DMUS_FOURCC_GUID_CHUNK
: {
446 TRACE_(dmfile
)(": guid chunk\n");
447 /* no need to set flags since they were copied from reference header */
448 IStream_Read (pStm
, &pNewEntry
->Desc
.guidObject
, Chunk
.dwSize
, NULL
);
451 case DMUS_FOURCC_DATE_CHUNK
: {
452 TRACE_(dmfile
)(": file date chunk\n");
453 /* no need to set flags since they were copied from reference header */
454 IStream_Read (pStm
, &pNewEntry
->Desc
.ftDate
, Chunk
.dwSize
, NULL
);
457 case DMUS_FOURCC_NAME_CHUNK
: {
458 TRACE_(dmfile
)(": name chunk\n");
459 /* no need to set flags since they were copied from reference header */
460 IStream_Read (pStm
, pNewEntry
->Desc
.wszName
, Chunk
.dwSize
, NULL
);
463 case DMUS_FOURCC_FILE_CHUNK
: {
464 TRACE_(dmfile
)(": file name chunk\n");
465 /* no need to set flags since they were copied from reference header */
466 IStream_Read (pStm
, pNewEntry
->Desc
.wszFileName
, Chunk
.dwSize
, NULL
);
469 case DMUS_FOURCC_CATEGORY_CHUNK
: {
470 TRACE_(dmfile
)(": category chunk\n");
471 /* no need to set flags since they were copied from reference header */
472 IStream_Read (pStm
, pNewEntry
->Desc
.wszCategory
, Chunk
.dwSize
, NULL
);
475 case DMUS_FOURCC_VERSION_CHUNK
: {
476 TRACE_(dmfile
)(": version chunk\n");
477 /* no need to set flags since they were copied from reference header */
478 IStream_Read (pStm
, &pNewEntry
->Desc
.vVersion
, Chunk
.dwSize
, NULL
);
482 TRACE_(dmfile
)(": unknown chunk (skipping)\n");
483 liMove
.QuadPart
= Chunk
.dwSize
;
484 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip this chunk */
488 TRACE_(dmfile
)(": ListCount[2] = %#lx < ListSize[2] = %#lx\n", ListCount
[2], ListSize
[2]);
489 } while (ListCount
[2] < ListSize
[2]);
493 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
501 IStream_Read (pStm
, &Chunk
.fccID
, sizeof(FOURCC
), NULL
);
502 TRACE_(dmfile
)(": RIFF chunk of type %s", debugstr_fourcc(Chunk
.fccID
));
503 if (IS_VALID_DMFORM (Chunk
.fccID
)) {
504 TRACE_(dmfile
)(": valid DMUSIC form\n");
505 pNewEntry
->bIsRIFF
= 1;
506 /* we'll have to skip whole RIFF chunk after SetObject is called */
508 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, &uliPos
);
509 uliPos
.QuadPart
+= (Chunk
.dwSize
- sizeof(FOURCC
)); /* set uliPos at the end of RIFF chunk */
510 /* move at the beginning of RIFF chunk */
512 liMove
.QuadPart
-= (sizeof(FOURCC
)+sizeof(DWORD
)+sizeof(FOURCC
));
513 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
514 /* put pointer to stream in descriptor */
515 pNewEntry
->Desc
.dwValidData
|= DMUS_OBJ_STREAM
;
516 pNewEntry
->Desc
.pStream
= pStm
; /* we don't have to worry about cloning, since SetObject will perform it */
517 /* wait till we get on the end of object list */
519 TRACE_(dmfile
)(": invalid DMUSIC form (skipping)\n");
520 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
521 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
522 /* FIXME: should we return E_FAIL? */
527 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
528 liMove
.QuadPart
= Chunk
.dwSize
;
529 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
533 TRACE_(dmfile
)(": ListCount[1] = %#lx < ListSize[1] = %#lx\n", ListCount
[1], ListSize
[1]);
534 } while (ListCount
[1] < ListSize
[1]);
535 /* SetObject: this will fill descriptor with additional info and add alias in loader's cache */
536 IDirectMusicLoader_SetObject (pLoader
, &pNewEntry
->Desc
);
537 /* now that SetObject collected appropriate info into descriptor we can live happily ever after;
538 or not, since we have to clean evidence of loading through stream... *sigh*
539 and we have to skip rest of the chunk, if we loaded through RIFF */
540 if (pNewEntry
->bIsRIFF
) {
541 liMove
.QuadPart
= uliPos
.QuadPart
;
542 IStream_Seek (pStm
, liMove
, STREAM_SEEK_SET
, NULL
);
543 pNewEntry
->Desc
.dwValidData
&= ~DMUS_OBJ_STREAM
; /* clear flag (and with bitwise complement) */
544 pNewEntry
->Desc
.pStream
= NULL
;
546 /* add entry to list of objects */
547 list_add_tail (This
->pContainedObjects
, &pNewEntry
->entry
);
551 TRACE_(dmfile
)(": unknown (skipping)\n");
552 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
553 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
560 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
561 liMove
.QuadPart
= Chunk
.dwSize
;
562 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
566 TRACE_(dmfile
)(": ListCount[0] = %#lx < ListSize[0] = %#lx\n", ListCount
[0], ListSize
[0]);
567 } while (ListCount
[0] < ListSize
[0]);
571 TRACE_(dmfile
)(": unknown (skipping)\n");
572 liMove
.QuadPart
= Chunk
.dwSize
- sizeof(FOURCC
);
573 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
580 TRACE_(dmfile
)(": unknown chunk (irrelevant & skipping)\n");
581 liMove
.QuadPart
= Chunk
.dwSize
;
582 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
);
586 TRACE_(dmfile
)(": StreamCount[0] = %#lx < StreamSize[0] = %#lx\n", StreamCount
, StreamSize
);
587 } while (StreamCount
< StreamSize
);
591 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
592 liMove
.QuadPart
= StreamSize
;
593 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
597 TRACE_(dmfile
)(": reading finished\n");
598 This
->dmobj
.desc
.dwValidData
|= DMUS_OBJ_LOADED
;
599 dump_DMUS_OBJECTDESC(&This
->dmobj
.desc
);
603 TRACE_(dmfile
)(": unexpected chunk; loading failed)\n");
604 liMove
.QuadPart
= Chunk
.dwSize
;
605 IStream_Seek (pStm
, liMove
, STREAM_SEEK_CUR
, NULL
); /* skip the rest of the chunk */
610 /* now, if DMUS_CONTAINER_NOLOADS is not set, we are supposed to load contained objects;
611 so when we call GetObject later, they'll already be in cache */
612 if (!(This
->Header
.dwFlags
& DMUS_CONTAINER_NOLOADS
)) {
614 LPWINE_CONTAINER_ENTRY pContainedObject
;
616 TRACE(": DMUS_CONTAINER_NOLOADS not set... load all objects\n");
618 LIST_FOR_EACH (pEntry
, This
->pContainedObjects
) {
619 IDirectMusicObject
* pObject
;
620 pContainedObject
= LIST_ENTRY (pEntry
, WINE_CONTAINER_ENTRY
, entry
);
621 /* get object from loader and then release it */
622 if (SUCCEEDED(IDirectMusicLoader_GetObject (pLoader
, &pContainedObject
->Desc
, &IID_IDirectMusicObject
, (LPVOID
*)&pObject
))) {
623 pContainedObject
->pObject
= pObject
; /* for final release */
624 IDirectMusicObject_Release (pObject
); /* we don't really need this one */
626 WARN(": failed to load contained object\n");
627 result
= DMUS_S_PARTIALLOAD
;
632 IDirectMusicLoader_Release (pLoader
); /* release loader */
637 static const IPersistStreamVtbl persiststream_vtbl
= {
638 dmobj_IPersistStream_QueryInterface
,
639 dmobj_IPersistStream_AddRef
,
640 dmobj_IPersistStream_Release
,
641 dmobj_IPersistStream_GetClassID
,
642 unimpl_IPersistStream_IsDirty
,
643 IPersistStreamImpl_Load
,
644 unimpl_IPersistStream_Save
,
645 unimpl_IPersistStream_GetSizeMax
648 /* for ClassFactory */
649 HRESULT
create_dmcontainer(REFIID lpcGUID
, void **ppobj
)
651 IDirectMusicContainerImpl
* obj
;
655 if (!(obj
= calloc(1, sizeof(*obj
)))) return E_OUTOFMEMORY
;
656 obj
->IDirectMusicContainer_iface
.lpVtbl
= &dmcontainer_vtbl
;
658 dmobject_init(&obj
->dmobj
, &CLSID_DirectMusicContainer
,
659 (IUnknown
*)&obj
->IDirectMusicContainer_iface
);
660 obj
->dmobj
.IDirectMusicObject_iface
.lpVtbl
= &dmobject_vtbl
;
661 obj
->dmobj
.IPersistStream_iface
.lpVtbl
= &persiststream_vtbl
;
662 obj
->pContainedObjects
= HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY
, sizeof(struct list
));
663 list_init (obj
->pContainedObjects
);
665 hr
= IDirectMusicContainer_QueryInterface(&obj
->IDirectMusicContainer_iface
, lpcGUID
, ppobj
);
666 IDirectMusicContainer_Release(&obj
->IDirectMusicContainer_iface
);