Commit 9348c093 authored by Michael Stefaniuc's avatar Michael Stefaniuc Committed by Alexandre Julliard

dmband: Reimplement ParseDescriptor() for DirectMusicBand.

parent 8e0f9498
...@@ -123,153 +123,43 @@ static const IDirectMusicBandVtbl dmband_vtbl = { ...@@ -123,153 +123,43 @@ static const IDirectMusicBandVtbl dmband_vtbl = {
}; };
/* IDirectMusicBandImpl IDirectMusicObject part: */ /* IDirectMusicBandImpl IDirectMusicObject part: */
static HRESULT WINAPI IDirectMusicObjectImpl_ParseDescriptor(IDirectMusicObject *iface, static HRESULT WINAPI band_IDirectMusicObject_ParseDescriptor(IDirectMusicObject *iface,
IStream *pStream, DMUS_OBJECTDESC *pDesc) IStream *stream, DMUS_OBJECTDESC *desc)
{ {
DMUS_PRIVATE_CHUNK Chunk; struct chunk_entry riff = {0};
DWORD StreamSize, StreamCount, ListSize[1], ListCount[1]; STATSTG stat;
LARGE_INTEGER liMove; /* used when skipping chunks */ HRESULT hr;
TRACE("(%p, %p)\n", pStream, pDesc); TRACE("(%p, %p, %p)\n", iface, stream, desc);
/* FIXME: should this be determined from stream? */ if (!stream || !desc)
pDesc->dwValidData |= DMUS_OBJ_CLASS; return E_POINTER;
pDesc->guidClass = CLSID_DirectMusicBand;
if ((hr = stream_get_chunk(stream, &riff)) != S_OK)
IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL); return hr;
TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize); if (riff.id != FOURCC_RIFF || riff.type != DMUS_FOURCC_BAND_FORM) {
switch (Chunk.fccID) { TRACE("loading failed: unexpected %s\n", debugstr_chunk(&riff));
case FOURCC_RIFF: { stream_skip_chunk(stream, &riff);
IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL); return DMUS_E_INVALID_BAND;
TRACE_(dmfile)(": RIFF chunk of type %s", debugstr_fourcc(Chunk.fccID)); }
StreamSize = Chunk.dwSize - sizeof(FOURCC);
StreamCount = 0; hr = dmobj_parsedescriptor(stream, &riff, desc,
if (Chunk.fccID == DMUS_FOURCC_BAND_FORM) { DMUS_OBJ_OBJECT|DMUS_OBJ_NAME|DMUS_OBJ_NAME_INAM|DMUS_OBJ_CATEGORY|DMUS_OBJ_VERSION);
TRACE_(dmfile)(": band form\n"); if (FAILED(hr))
do { return hr;
IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
StreamCount += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize; desc->guidClass = CLSID_DirectMusicBand;
TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize); desc->dwValidData |= DMUS_OBJ_CLASS;
switch (Chunk.fccID) {
case DMUS_FOURCC_GUID_CHUNK: { if (desc->dwValidData & DMUS_OBJ_CATEGORY) {
TRACE_(dmfile)(": GUID chunk\n"); IStream_Stat(stream, &stat, STATFLAG_NONAME);
pDesc->dwValidData |= DMUS_OBJ_OBJECT; desc->ftDate = stat.mtime;
IStream_Read (pStream, &pDesc->guidObject, Chunk.dwSize, NULL); desc->dwValidData |= DMUS_OBJ_DATE;
break; }
}
case DMUS_FOURCC_VERSION_CHUNK: { TRACE("returning descriptor:\n");
TRACE_(dmfile)(": version chunk\n"); debug_DMUS_OBJECTDESC(desc);
pDesc->dwValidData |= DMUS_OBJ_VERSION; return S_OK;
IStream_Read (pStream, &pDesc->vVersion, Chunk.dwSize, NULL);
break;
}
case DMUS_FOURCC_CATEGORY_CHUNK: {
TRACE_(dmfile)(": category chunk\n");
pDesc->dwValidData |= DMUS_OBJ_CATEGORY;
IStream_Read (pStream, pDesc->wszCategory, Chunk.dwSize, NULL);
break;
}
case FOURCC_LIST: {
IStream_Read (pStream, &Chunk.fccID, sizeof(FOURCC), NULL);
TRACE_(dmfile)(": LIST chunk of type %s", debugstr_fourcc(Chunk.fccID));
ListSize[0] = Chunk.dwSize - sizeof(FOURCC);
ListCount[0] = 0;
switch (Chunk.fccID) {
/* evil M$ UNFO list, which can (!?) contain INFO elements */
case DMUS_FOURCC_UNFO_LIST: {
TRACE_(dmfile)(": UNFO list\n");
do {
IStream_Read (pStream, &Chunk, sizeof(FOURCC)+sizeof(DWORD), NULL);
ListCount[0] += sizeof(FOURCC) + sizeof(DWORD) + Chunk.dwSize;
TRACE_(dmfile)(": %s chunk (size = 0x%04x)", debugstr_fourcc (Chunk.fccID), Chunk.dwSize);
switch (Chunk.fccID) {
/* don't ask me why, but M$ puts INFO elements in UNFO list sometimes
(though strings seem to be valid unicode) */
case mmioFOURCC('I','N','A','M'):
case DMUS_FOURCC_UNAM_CHUNK: {
TRACE_(dmfile)(": name chunk\n");
pDesc->dwValidData |= DMUS_OBJ_NAME;
IStream_Read (pStream, pDesc->wszName, Chunk.dwSize, NULL);
break;
}
case mmioFOURCC('I','A','R','T'):
case DMUS_FOURCC_UART_CHUNK: {
TRACE_(dmfile)(": artist chunk (ignored)\n");
liMove.QuadPart = Chunk.dwSize;
IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
break;
}
case mmioFOURCC('I','C','O','P'):
case DMUS_FOURCC_UCOP_CHUNK: {
TRACE_(dmfile)(": copyright chunk (ignored)\n");
liMove.QuadPart = Chunk.dwSize;
IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
break;
}
case mmioFOURCC('I','S','B','J'):
case DMUS_FOURCC_USBJ_CHUNK: {
TRACE_(dmfile)(": subject chunk (ignored)\n");
liMove.QuadPart = Chunk.dwSize;
IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
break;
}
case mmioFOURCC('I','C','M','T'):
case DMUS_FOURCC_UCMT_CHUNK: {
TRACE_(dmfile)(": comment chunk (ignored)\n");
liMove.QuadPart = Chunk.dwSize;
IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
break;
}
default: {
TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
liMove.QuadPart = Chunk.dwSize;
IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
break;
}
}
TRACE_(dmfile)(": ListCount[0] = %d < ListSize[0] = %d\n", ListCount[0], ListSize[0]);
} while (ListCount[0] < ListSize[0]);
break;
}
default: {
TRACE_(dmfile)(": unknown (skipping)\n");
liMove.QuadPart = Chunk.dwSize - sizeof(FOURCC);
IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
break;
}
}
break;
}
default: {
TRACE_(dmfile)(": unknown chunk (irrelevant & skipping)\n");
liMove.QuadPart = Chunk.dwSize;
IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL);
break;
}
}
TRACE_(dmfile)(": StreamCount[0] = %d < StreamSize[0] = %d\n", StreamCount, StreamSize);
} while (StreamCount < StreamSize);
} else {
TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
liMove.QuadPart = StreamSize;
IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
return E_FAIL;
}
TRACE_(dmfile)(": reading finished\n");
break;
}
default: {
TRACE_(dmfile)(": unexpected chunk; loading failed)\n");
liMove.QuadPart = Chunk.dwSize;
IStream_Seek (pStream, liMove, STREAM_SEEK_CUR, NULL); /* skip the rest of the chunk */
return DMUS_E_INVALIDFILE;
}
}
TRACE(": returning descriptor:\n"); debug_DMUS_OBJECTDESC (pDesc);
return S_OK;
} }
static const IDirectMusicObjectVtbl dmobject_vtbl = { static const IDirectMusicObjectVtbl dmobject_vtbl = {
...@@ -278,7 +168,7 @@ static const IDirectMusicObjectVtbl dmobject_vtbl = { ...@@ -278,7 +168,7 @@ static const IDirectMusicObjectVtbl dmobject_vtbl = {
dmobj_IDirectMusicObject_Release, dmobj_IDirectMusicObject_Release,
dmobj_IDirectMusicObject_GetDescriptor, dmobj_IDirectMusicObject_GetDescriptor,
dmobj_IDirectMusicObject_SetDescriptor, dmobj_IDirectMusicObject_SetDescriptor,
IDirectMusicObjectImpl_ParseDescriptor band_IDirectMusicObject_ParseDescriptor
}; };
/* IDirectMusicBandImpl IPersistStream part: */ /* IDirectMusicBandImpl IPersistStream part: */
......
...@@ -345,6 +345,7 @@ static void test_parsedescriptor(void) ...@@ -345,6 +345,7 @@ static void test_parsedescriptor(void)
FOURCC_LIST, DMUS_FOURCC_UNFO_LIST, mmioFOURCC('I','N','A','M'), 0, 0 FOURCC_LIST, DMUS_FOURCC_UNFO_LIST, mmioFOURCC('I','N','A','M'), 0, 0
}; };
FOURCC empty[] = {FOURCC_RIFF, DMUS_FOURCC_BAND_FORM, 0}; FOURCC empty[] = {FOURCC_RIFF, DMUS_FOURCC_BAND_FORM, 0};
FOURCC catdate[] = {FOURCC_RIFF, DMUS_FOURCC_BAND_FORM, DMUS_FOURCC_CATEGORY_CHUNK, 0};
FOURCC inam[] = FOURCC inam[] =
{ {
FOURCC_RIFF, DMUS_FOURCC_BAND_FORM, FOURCC_LIST, DMUS_FOURCC_UNFO_LIST, FOURCC_RIFF, DMUS_FOURCC_BAND_FORM, FOURCC_LIST, DMUS_FOURCC_UNFO_LIST,
...@@ -376,21 +377,36 @@ static void test_parsedescriptor(void) ...@@ -376,21 +377,36 @@ static void test_parsedescriptor(void)
wine_dbgstr_guid(&desc.guidClass)); wine_dbgstr_guid(&desc.guidClass));
IStream_Release(stream); IStream_Release(stream);
/* NULL pointers */
memset(&desc, 0, sizeof(desc));
hr = IDirectMusicObject_ParseDescriptor(dmo, NULL, &desc);
ok(hr == E_POINTER, "ParseDescriptor failed: %08x, expected E_POINTER\n", hr);
hr = IDirectMusicObject_ParseDescriptor(dmo, stream, NULL);
ok(hr == E_POINTER, "ParseDescriptor failed: %08x, expected E_POINTER\n", hr);
/* Wrong form */ /* Wrong form */
empty[1] = DMUS_FOURCC_CONTAINER_FORM; empty[1] = DMUS_FOURCC_CONTAINER_FORM;
stream = gen_riff_stream(empty); stream = gen_riff_stream(empty);
hr = IDirectMusicObject_ParseDescriptor(dmo, stream, &desc); hr = IDirectMusicObject_ParseDescriptor(dmo, stream, &desc);
todo_wine ok(hr == DMUS_E_INVALID_BAND, ok(hr == DMUS_E_INVALID_BAND,
"ParseDescriptor failed: %08x, expected DMUS_E_INVALID_BAND\n", hr); "ParseDescriptor failed: %08x, expected DMUS_E_INVALID_BAND\n", hr);
/* A category chunk adds DMUS_OBJ_DATE too */
stream = gen_riff_stream(catdate);
memset(&desc, 0, sizeof(desc));
hr = IDirectMusicObject_ParseDescriptor(dmo, stream, &desc);
ok(hr == S_OK, "ParseDescriptor failed: %08x, expected S_OK\n", hr);
valid = DMUS_OBJ_CLASS | DMUS_OBJ_CATEGORY | DMUS_OBJ_DATE;
ok(desc.dwValidData == valid, "Got valid data %#x, expected %#x\n", desc.dwValidData, valid);
IStream_Release(stream);
/* All desc chunks, extra DMUS_OBJ_DATE */ /* All desc chunks, extra DMUS_OBJ_DATE */
stream = gen_riff_stream(alldesc); stream = gen_riff_stream(alldesc);
memset(&desc, 0, sizeof(desc)); memset(&desc, 0, sizeof(desc));
hr = IDirectMusicObject_ParseDescriptor(dmo, stream, &desc); hr = IDirectMusicObject_ParseDescriptor(dmo, stream, &desc);
ok(hr == S_OK, "ParseDescriptor failed: %08x, expected S_OK\n", hr); ok(hr == S_OK, "ParseDescriptor failed: %08x, expected S_OK\n", hr);
valid = DMUS_OBJ_OBJECT|DMUS_OBJ_CLASS|DMUS_OBJ_NAME|DMUS_OBJ_CATEGORY|DMUS_OBJ_VERSION|DMUS_OBJ_DATE; valid = DMUS_OBJ_OBJECT|DMUS_OBJ_CLASS|DMUS_OBJ_NAME|DMUS_OBJ_CATEGORY|DMUS_OBJ_VERSION|DMUS_OBJ_DATE;
todo_wine ok(desc.dwValidData == valid, "Got valid data %#x, expected %#x\n", ok(desc.dwValidData == valid, "Got valid data %#x, expected %#x\n", desc.dwValidData, valid);
desc.dwValidData, valid);
ok(IsEqualGUID(&desc.guidClass, &CLSID_DirectMusicBand), ok(IsEqualGUID(&desc.guidClass, &CLSID_DirectMusicBand),
"Got class guid %s, expected CLSID_DirectMusicBand\n", "Got class guid %s, expected CLSID_DirectMusicBand\n",
wine_dbgstr_guid(&desc.guidClass)); wine_dbgstr_guid(&desc.guidClass));
...@@ -431,8 +447,7 @@ static void test_parsedescriptor(void) ...@@ -431,8 +447,7 @@ static void test_parsedescriptor(void)
hr = IDirectMusicObject_ParseDescriptor(dmo, stream, &desc); hr = IDirectMusicObject_ParseDescriptor(dmo, stream, &desc);
ok(hr == S_OK, "ParseDescriptor failed: %08x, expected S_OK\n", hr); ok(hr == S_OK, "ParseDescriptor failed: %08x, expected S_OK\n", hr);
valid = DMUS_OBJ_OBJECT|DMUS_OBJ_CLASS|DMUS_OBJ_NAME|DMUS_OBJ_CATEGORY|DMUS_OBJ_VERSION|DMUS_OBJ_DATE; valid = DMUS_OBJ_OBJECT|DMUS_OBJ_CLASS|DMUS_OBJ_NAME|DMUS_OBJ_CATEGORY|DMUS_OBJ_VERSION|DMUS_OBJ_DATE;
todo_wine ok(desc.dwValidData == valid, "Got valid data %#x, expected %#x\n", ok(desc.dwValidData == valid, "Got valid data %#x, expected %#x\n", desc.dwValidData, valid);
desc.dwValidData, valid);
ok(!memcmp(desc.wszName, s_inam, sizeof(s_inam)), "Got name '%s', expected 'INAM'\n", ok(!memcmp(desc.wszName, s_inam, sizeof(s_inam)), "Got name '%s', expected 'INAM'\n",
wine_dbgstr_w(desc.wszName)); wine_dbgstr_w(desc.wszName));
IStream_Release(stream); IStream_Release(stream);
......
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