Commit bb2a8312 authored by Rémi Bernon's avatar Rémi Bernon Committed by Alexandre Julliard

dmusic: Rewrite collection lins list parsing.

parent 4b787aa9
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
*/ */
#include "dmusic_private.h" #include "dmusic_private.h"
#include "dmobject.h"
#include "initguid.h" #include "initguid.h"
#include "dmksctrl.h" #include "dmksctrl.h"
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
*/ */
#include "dmusic_private.h" #include "dmusic_private.h"
#include "dmobject.h"
WINE_DEFAULT_DEBUG_CHANNEL(dmusic); WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
*/ */
#include "dmusic_private.h" #include "dmusic_private.h"
#include "dmobject.h"
WINE_DEFAULT_DEBUG_CHANNEL(dmusic); WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
WINE_DECLARE_DEBUG_CHANNEL(dmfile); WINE_DECLARE_DEBUG_CHANNEL(dmfile);
...@@ -177,6 +176,34 @@ static const IDirectMusicCollectionVtbl collection_vtbl = ...@@ -177,6 +176,34 @@ static const IDirectMusicCollectionVtbl collection_vtbl =
collection_EnumInstrument, collection_EnumInstrument,
}; };
static HRESULT parse_lins_list(struct collection *This, IStream *stream, struct chunk_entry *parent)
{
struct chunk_entry chunk = {.parent = parent};
struct instrument_entry *entry;
HRESULT hr;
while ((hr = stream_next_chunk(stream, &chunk)) == S_OK)
{
switch (MAKE_IDTYPE(chunk.id, chunk.type))
{
case MAKE_IDTYPE(FOURCC_LIST, FOURCC_INS):
if (!(entry = malloc(sizeof(*entry)))) return E_OUTOFMEMORY;
hr = instrument_create_from_chunk(stream, &chunk, &entry->instrument);
if (SUCCEEDED(hr)) list_add_tail(&This->instruments, &entry->entry);
else free(entry);
break;
default:
FIXME("Ignoring chunk %s %s\n", debugstr_fourcc(chunk.id), debugstr_fourcc(chunk.type));
break;
}
if (FAILED(hr)) break;
}
return hr;
}
static HRESULT WINAPI collection_object_ParseDescriptor(IDirectMusicObject *iface, static HRESULT WINAPI collection_object_ParseDescriptor(IDirectMusicObject *iface,
IStream *stream, DMUS_OBJECTDESC *desc) IStream *stream, DMUS_OBJECTDESC *desc)
{ {
...@@ -373,39 +400,13 @@ static HRESULT WINAPI collection_stream_Load(IPersistStream *iface, ...@@ -373,39 +400,13 @@ static HRESULT WINAPI collection_stream_Load(IPersistStream *iface,
break; break;
} }
case FOURCC_LINS: { case FOURCC_LINS: {
struct chunk_entry lins_chunk = {.id = FOURCC_LIST, .size = chunk.dwSize, .type = chunk.fccID};
TRACE_(dmfile)(": instruments list\n"); TRACE_(dmfile)(": instruments list\n");
do { liMove.QuadPart = 0;
IStream_Read(stream, &chunk, sizeof(FOURCC) + sizeof(DWORD), NULL); IStream_Seek(stream, liMove, STREAM_SEEK_CUR, &lins_chunk.offset);
ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + chunk.dwSize; lins_chunk.offset.QuadPart -= 12;
TRACE_(dmfile)(": %s chunk (size = %#04lx)", debugstr_fourcc(chunk.fccID), chunk.dwSize); parse_lins_list(This, stream, &lins_chunk);
switch (chunk.fccID) { stream_skip_chunk(stream, &lins_chunk);
case FOURCC_LIST: {
IStream_Read(stream, &chunk.fccID, sizeof(FOURCC), NULL);
TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(chunk.fccID));
ListSize[1] = chunk.dwSize - sizeof(FOURCC);
ListCount[1] = 0;
switch (chunk.fccID) {
case FOURCC_INS: {
struct instrument_entry *entry = calloc(1, sizeof(*entry));
TRACE_(dmfile)(": instrument list\n");
liMove.QuadPart = -12;
IStream_Seek(stream, liMove, STREAM_SEEK_CUR, NULL);
if (FAILED(instrument_create_from_stream(stream, &entry->instrument))) free(entry);
else list_add_tail(&This->instruments, &entry->entry);
break;
}
}
break;
}
default: {
TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
liMove.QuadPart = chunk.dwSize;
IStream_Seek(stream, liMove, STREAM_SEEK_CUR, NULL);
break;
}
}
TRACE_(dmfile)(": ListCount[0] = %ld < ListSize[0] = %ld\n", ListCount[0], ListSize[0]);
} while (ListCount[0] < ListSize[0]);
break; break;
} }
default: { default: {
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include <stdio.h> #include <stdio.h>
#include "dmusic_private.h" #include "dmusic_private.h"
#include "dmobject.h"
WINE_DEFAULT_DEBUG_CHANNEL(dmusic); WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
......
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
#include "dmusici.h" #include "dmusici.h"
#include "dmusic_private.h" #include "dmusic_private.h"
#include "dmobject.h"
WINE_DEFAULT_DEBUG_CHANNEL(dmusic); WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
......
...@@ -41,6 +41,8 @@ ...@@ -41,6 +41,8 @@
#include "dmusics.h" #include "dmusics.h"
#include "dmksctrl.h" #include "dmksctrl.h"
#include "dmobject.h"
/***************************************************************************** /*****************************************************************************
* Interfaces * Interfaces
*/ */
...@@ -95,7 +97,8 @@ extern HRESULT DMUSIC_CreateReferenceClockImpl (LPCGUID lpcGUID, LPVOID* ppobj, ...@@ -95,7 +97,8 @@ extern HRESULT DMUSIC_CreateReferenceClockImpl (LPCGUID lpcGUID, LPVOID* ppobj,
extern HRESULT download_create(DWORD size, IDirectMusicDownload **ret_iface); extern HRESULT download_create(DWORD size, IDirectMusicDownload **ret_iface);
extern HRESULT instrument_create_from_stream(IStream *stream, IDirectMusicInstrument **ret_iface); extern HRESULT instrument_create_from_chunk(IStream *stream, struct chunk_entry *parent,
IDirectMusicInstrument **ret_iface);
/***************************************************************************** /*****************************************************************************
* IDirectMusic8Impl implementation structure * IDirectMusic8Impl implementation structure
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
*/ */
#include "dmusic_private.h" #include "dmusic_private.h"
#include "dmobject.h"
WINE_DEFAULT_DEBUG_CHANNEL(dmusic); WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
*/ */
#include "dmusic_private.h" #include "dmusic_private.h"
#include "dmobject.h"
WINE_DEFAULT_DEBUG_CHANNEL(dmusic); WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
...@@ -303,9 +302,9 @@ static HRESULT parse_ins_chunk(struct instrument *This, IStream *stream, struct ...@@ -303,9 +302,9 @@ static HRESULT parse_ins_chunk(struct instrument *This, IStream *stream, struct
return hr; return hr;
} }
HRESULT instrument_create_from_stream(IStream *stream, IDirectMusicInstrument **ret_iface) HRESULT instrument_create_from_chunk(IStream *stream, struct chunk_entry *parent,
IDirectMusicInstrument **ret_iface)
{ {
struct chunk_entry chunk = {0};
IDirectMusicInstrument *iface; IDirectMusicInstrument *iface;
struct instrument *This; struct instrument *This;
HRESULT hr; HRESULT hr;
...@@ -315,23 +314,12 @@ HRESULT instrument_create_from_stream(IStream *stream, IDirectMusicInstrument ** ...@@ -315,23 +314,12 @@ HRESULT instrument_create_from_stream(IStream *stream, IDirectMusicInstrument **
if (FAILED(hr = instrument_create(&iface))) return hr; if (FAILED(hr = instrument_create(&iface))) return hr;
This = impl_from_IDirectMusicInstrument(iface); This = impl_from_IDirectMusicInstrument(iface);
if ((hr = stream_next_chunk(stream, &chunk)) == S_OK) if (FAILED(hr = parse_ins_chunk(This, stream, parent)))
{ {
switch (MAKE_IDTYPE(chunk.id, chunk.type)) IDirectMusicInstrument_Release(iface);
{ return DMUS_E_UNSUPPORTED_STREAM;
case MAKE_IDTYPE(FOURCC_LIST, FOURCC_INS):
hr = parse_ins_chunk(This, stream, &chunk);
break;
default:
WARN("Invalid instrument chunk %s %s\n", debugstr_fourcc(chunk.id), debugstr_fourcc(chunk.type));
hr = E_INVALIDARG;
break;
}
} }
if (FAILED(hr)) goto error;
if (TRACE_ON(dmusic)) if (TRACE_ON(dmusic))
{ {
TRACE("Created DirectMusicInstrument (%p) ***\n", This); TRACE("Created DirectMusicInstrument (%p) ***\n", This);
...@@ -347,10 +335,4 @@ HRESULT instrument_create_from_stream(IStream *stream, IDirectMusicInstrument ** ...@@ -347,10 +335,4 @@ HRESULT instrument_create_from_stream(IStream *stream, IDirectMusicInstrument **
*ret_iface = iface; *ret_iface = iface;
return S_OK; return S_OK;
error:
IDirectMusicInstrument_Release(iface);
stream_skip_chunk(stream, &chunk);
return DMUS_E_UNSUPPORTED_STREAM;
} }
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include <assert.h> #include <assert.h>
#include "dmusic_private.h" #include "dmusic_private.h"
#include "dmobject.h"
WINE_DEFAULT_DEBUG_CHANNEL(dmusic); WINE_DEFAULT_DEBUG_CHANNEL(dmusic);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment