diff --git a/reactos/dll/win32/avifil32/api.c b/reactos/dll/win32/avifil32/api.c index c5c4dcf3cd6..9ae26b94311 100644 --- a/reactos/dll/win32/avifil32/api.c +++ b/reactos/dll/win32/avifil32/api.c @@ -1493,7 +1493,7 @@ HRESULT WINAPI AVISaveVA(LPCSTR szFile, CLSID *pclsidHandler, HRESULT hr; int len; - TRACE("%s,%p,%p,%d,%p,%p)\n", debugstr_a(szFile), pclsidHandler, + TRACE("(%s,%p,%p,%d,%p,%p)\n", debugstr_a(szFile), pclsidHandler, lpfnCallback, nStream, ppavi, plpOptions); if (szFile == NULL || ppavi == NULL || plpOptions == NULL) diff --git a/reactos/dll/win32/avifil32/avifil32.idl b/reactos/dll/win32/avifil32/avifil32.idl index b4c563f4d71..1f50f154ae1 100644 --- a/reactos/dll/win32/avifil32/avifil32.idl +++ b/reactos/dll/win32/avifil32/avifil32.idl @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ +#pragma makedep register + [ helpstring("Microsoft AVI Files"), threading(apartment), diff --git a/reactos/dll/win32/avifil32/avifile.c b/reactos/dll/win32/avifil32/avifile.c index 28766e97062..fa71eb11d9e 100644 --- a/reactos/dll/win32/avifil32/avifile.c +++ b/reactos/dll/win32/avifil32/avifile.c @@ -36,46 +36,12 @@ #define IDX_PER_BLOCK 2730 #endif -static HRESULT WINAPI IAVIStream_fnQueryInterface(IAVIStream*iface,REFIID refiid,LPVOID *obj); -static ULONG WINAPI IAVIStream_fnAddRef(IAVIStream*iface); -static ULONG WINAPI IAVIStream_fnRelease(IAVIStream* iface); -static HRESULT WINAPI IAVIStream_fnCreate(IAVIStream*iface,LPARAM lParam1,LPARAM lParam2); -static HRESULT WINAPI IAVIStream_fnInfo(IAVIStream*iface,AVISTREAMINFOW *psi,LONG size); -static LONG WINAPI IAVIStream_fnFindSample(IAVIStream*iface,LONG pos,LONG flags); -static HRESULT WINAPI IAVIStream_fnReadFormat(IAVIStream*iface,LONG pos,LPVOID format,LONG *formatsize); -static HRESULT WINAPI IAVIStream_fnSetFormat(IAVIStream*iface,LONG pos,LPVOID format,LONG formatsize); -static HRESULT WINAPI IAVIStream_fnRead(IAVIStream*iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,LONG *bytesread,LONG *samplesread); -static HRESULT WINAPI IAVIStream_fnWrite(IAVIStream*iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,DWORD flags,LONG *sampwritten,LONG *byteswritten); -static HRESULT WINAPI IAVIStream_fnDelete(IAVIStream*iface,LONG start,LONG samples); -static HRESULT WINAPI IAVIStream_fnReadData(IAVIStream*iface,DWORD fcc,LPVOID lp,LONG *lpread); -static HRESULT WINAPI IAVIStream_fnWriteData(IAVIStream*iface,DWORD fcc,LPVOID lp,LONG size); -static HRESULT WINAPI IAVIStream_fnSetInfo(IAVIStream*iface,AVISTREAMINFOW*info,LONG infolen); - -static const struct IAVIStreamVtbl iavist = { - IAVIStream_fnQueryInterface, - IAVIStream_fnAddRef, - IAVIStream_fnRelease, - IAVIStream_fnCreate, - IAVIStream_fnInfo, - IAVIStream_fnFindSample, - IAVIStream_fnReadFormat, - IAVIStream_fnSetFormat, - IAVIStream_fnRead, - IAVIStream_fnWrite, - IAVIStream_fnDelete, - IAVIStream_fnReadData, - IAVIStream_fnWriteData, - IAVIStream_fnSetInfo -}; - typedef struct _IAVIFileImpl IAVIFileImpl; typedef struct _IAVIStreamImpl { - /* IUnknown stuff */ - const IAVIStreamVtbl *lpVtbl; - LONG ref; + IAVIStream IAVIStream_iface; + LONG ref; - /* IAVIStream stuff */ IAVIFileImpl *paf; DWORD nStream; /* the n-th stream in file */ AVISTREAMINFOW sInfo; @@ -99,6 +65,11 @@ typedef struct _IAVIStreamImpl { DWORD nIdxFmtChanges; /* upper index limit of idxFmtChanges */ } IAVIStreamImpl; +static inline IAVIStreamImpl *impl_from_IAVIStream(IAVIStream *iface) +{ + return CONTAINING_RECORD(iface, IAVIStreamImpl, IAVIStream_iface); +} + struct _IAVIFileImpl { IUnknown IUnknown_inner; IAVIFile IAVIFile_iface; @@ -319,7 +290,7 @@ static HRESULT WINAPI IAVIFile_fnGetStream(IAVIFile *iface, IAVIStream **avis, D /* Does the requested stream exist? */ if (nStream < This->fInfo.dwStreams && This->ppStreams[nStream] != NULL) { - *avis = (PAVISTREAM)This->ppStreams[nStream]; + *avis = &This->ppStreams[nStream]->IAVIStream_iface; IAVIStream_AddRef(*avis); return AVIERR_OK; @@ -376,7 +347,7 @@ static HRESULT WINAPI IAVIFile_fnCreateStream(IAVIFile *iface, IAVIStream **avis AVIFILE_UpdateInfo(This); /* return it */ - *avis = (PAVISTREAM)This->ppStreams[n]; + *avis = &This->ppStreams[n]->IAVIStream_iface; IAVIStream_AddRef(*avis); return AVIERR_OK; @@ -679,31 +650,35 @@ HRESULT AVIFILE_CreateAVIFile(IUnknown *pUnkOuter, REFIID riid, void **ppv) } -static HRESULT WINAPI IAVIStream_fnQueryInterface(IAVIStream *iface, - REFIID refiid, LPVOID *obj) +static HRESULT WINAPI IAVIStream_fnQueryInterface(IAVIStream *iface, REFIID riid, void **ppv) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); - TRACE("(%p,%s,%p)\n", iface, debugstr_guid(refiid), obj); + TRACE("(%p,%s,%p)\n", This, debugstr_guid(riid), ppv); - if (IsEqualGUID(&IID_IUnknown, refiid) || - IsEqualGUID(&IID_IAVIStream, refiid)) { - *obj = This; + if (!ppv) { + WARN("invalid parameter\n"); + return E_INVALIDARG; + } + *ppv = NULL; + + if (IsEqualGUID(&IID_IUnknown, riid) || IsEqualGUID(&IID_IAVIStream, riid)) { + *ppv = iface; IAVIStream_AddRef(iface); return S_OK; } /* FIXME: IAVIStreaming interface */ - return OLE_E_ENUM_NOMORE; + return E_NOINTERFACE; } static ULONG WINAPI IAVIStream_fnAddRef(IAVIStream *iface) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); ULONG ref = InterlockedIncrement(&This->ref); - TRACE("(%p) -> %d\n", iface, ref); + TRACE("(%p) ref=%d\n", This, ref); /* also add ref to parent, so that it doesn't kill us */ if (This->paf != NULL) @@ -712,12 +687,12 @@ static ULONG WINAPI IAVIStream_fnAddRef(IAVIStream *iface) return ref; } -static ULONG WINAPI IAVIStream_fnRelease(IAVIStream* iface) +static ULONG WINAPI IAVIStream_fnRelease(IAVIStream *iface) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); ULONG ref = InterlockedDecrement(&This->ref); - TRACE("(%p) -> %d\n", iface, ref); + TRACE("(%p) ref=%d\n", This, ref); if (This->paf != NULL) IAVIFile_Release(&This->paf->IAVIFile_iface); @@ -725,8 +700,7 @@ static ULONG WINAPI IAVIStream_fnRelease(IAVIStream* iface) return ref; } -static HRESULT WINAPI IAVIStream_fnCreate(IAVIStream *iface, LPARAM lParam1, - LPARAM lParam2) +static HRESULT WINAPI IAVIStream_fnCreate(IAVIStream *iface, LPARAM lParam1, LPARAM lParam2) { TRACE("(%p,0x%08lX,0x%08lX)\n", iface, lParam1, lParam2); @@ -734,10 +708,9 @@ static HRESULT WINAPI IAVIStream_fnCreate(IAVIStream *iface, LPARAM lParam1, return AVIERR_UNSUPPORTED; } -static HRESULT WINAPI IAVIStream_fnInfo(IAVIStream *iface,LPAVISTREAMINFOW psi, - LONG size) +static HRESULT WINAPI IAVIStream_fnInfo(IAVIStream *iface, AVISTREAMINFOW *psi, LONG size) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); TRACE("(%p,%p,%d)\n", iface, psi, size); @@ -753,11 +726,9 @@ static HRESULT WINAPI IAVIStream_fnInfo(IAVIStream *iface,LPAVISTREAMINFOW psi, return AVIERR_OK; } -static LONG WINAPI IAVIStream_fnFindSample(IAVIStream *iface, LONG pos, - LONG flags) +static LONG WINAPI IAVIStream_fnFindSample(IAVIStream *iface, LONG pos, LONG flags) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; - + IAVIStreamImpl *This = impl_from_IAVIStream(iface); LONG offset = 0; TRACE("(%p,%d,0x%08X)\n",iface,pos,flags); @@ -853,10 +824,10 @@ static LONG WINAPI IAVIStream_fnFindSample(IAVIStream *iface, LONG pos, return pos; } -static HRESULT WINAPI IAVIStream_fnReadFormat(IAVIStream *iface, LONG pos, - LPVOID format, LONG *formatsize) +static HRESULT WINAPI IAVIStream_fnReadFormat(IAVIStream *iface, LONG pos, void *format, + LONG *formatsize) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); TRACE("(%p,%d,%p,%p)\n", iface, pos, format, formatsize); @@ -892,12 +863,11 @@ static HRESULT WINAPI IAVIStream_fnReadFormat(IAVIStream *iface, LONG pos, return AVIERR_OK; } -static HRESULT WINAPI IAVIStream_fnSetFormat(IAVIStream *iface, LONG pos, - LPVOID format, LONG formatsize) +static HRESULT WINAPI IAVIStream_fnSetFormat(IAVIStream *iface, LONG pos, void *format, + LONG formatsize) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; - - LPBITMAPINFOHEADER lpbiNew = format; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); + BITMAPINFOHEADER *lpbiNew = format; TRACE("(%p,%d,%p,%d)\n", iface, pos, format, formatsize); @@ -1001,15 +971,12 @@ static HRESULT WINAPI IAVIStream_fnSetFormat(IAVIStream *iface, LONG pos, } } -static HRESULT WINAPI IAVIStream_fnRead(IAVIStream *iface, LONG start, - LONG samples, LPVOID buffer, - LONG buffersize, LPLONG bytesread, - LPLONG samplesread) +static HRESULT WINAPI IAVIStream_fnRead(IAVIStream *iface, LONG start, LONG samples, void *buffer, + LONG buffersize, LONG *bytesread, LONG *samplesread) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; - - DWORD size; - HRESULT hr; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); + DWORD size; + HRESULT hr; TRACE("(%p,%d,%d,%p,%d,%p,%p)\n", iface, start, samples, buffer, buffersize, bytesread, samplesread); @@ -1123,15 +1090,11 @@ static HRESULT WINAPI IAVIStream_fnRead(IAVIStream *iface, LONG start, } } -static HRESULT WINAPI IAVIStream_fnWrite(IAVIStream *iface, LONG start, - LONG samples, LPVOID buffer, - LONG buffersize, DWORD flags, - LPLONG sampwritten, - LPLONG byteswritten) +static HRESULT WINAPI IAVIStream_fnWrite(IAVIStream *iface, LONG start, LONG samples, void *buffer, + LONG buffersize, DWORD flags, LONG *sampwritten, LONG *byteswritten) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; - - FOURCC ckid; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); + FOURCC ckid; HRESULT hr; TRACE("(%p,%d,%d,%p,%d,0x%08X,%p,%p)\n", iface, start, samples, @@ -1217,10 +1180,9 @@ static HRESULT WINAPI IAVIStream_fnWrite(IAVIStream *iface, LONG start, return hr; } -static HRESULT WINAPI IAVIStream_fnDelete(IAVIStream *iface, LONG start, - LONG samples) +static HRESULT WINAPI IAVIStream_fnDelete(IAVIStream *iface, LONG start, LONG samples) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); FIXME("(%p,%d,%d): stub\n", iface, start, samples); @@ -1256,10 +1218,9 @@ static HRESULT WINAPI IAVIStream_fnDelete(IAVIStream *iface, LONG start, return AVIERR_UNSUPPORTED; } -static HRESULT WINAPI IAVIStream_fnReadData(IAVIStream *iface, DWORD fcc, - LPVOID lp, LPLONG lpread) +static HRESULT WINAPI IAVIStream_fnReadData(IAVIStream *iface, DWORD fcc, void *lp, LONG *lpread) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); TRACE("(%p,0x%08X,%p,%p)\n", iface, fcc, lp, lpread); @@ -1280,10 +1241,9 @@ static HRESULT WINAPI IAVIStream_fnReadData(IAVIStream *iface, DWORD fcc, return ReadExtraChunk(&This->extra, fcc, lp, lpread); } -static HRESULT WINAPI IAVIStream_fnWriteData(IAVIStream *iface, DWORD fcc, - LPVOID lp, LONG size) +static HRESULT WINAPI IAVIStream_fnWriteData(IAVIStream *iface, DWORD fcc, void *lp, LONG size) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); TRACE("(%p,0x%08x,%p,%d)\n", iface, fcc, lp, size); @@ -1313,7 +1273,7 @@ static HRESULT WINAPI IAVIStream_fnWriteData(IAVIStream *iface, DWORD fcc, if (fcc == ckidSTREAMHANDLERDATA) { if (This->lpHandlerData != NULL) { - FIXME(": handler data already set -- overwirte?\n"); + FIXME(": handler data already set -- overwrite?\n"); return AVIERR_UNSUPPORTED; } @@ -1328,15 +1288,30 @@ static HRESULT WINAPI IAVIStream_fnWriteData(IAVIStream *iface, DWORD fcc, return WriteExtraChunk(&This->extra, fcc, lp, size); } -static HRESULT WINAPI IAVIStream_fnSetInfo(IAVIStream *iface, - LPAVISTREAMINFOW info, LONG infolen) +static HRESULT WINAPI IAVIStream_fnSetInfo(IAVIStream *iface, AVISTREAMINFOW *info, LONG infolen) { FIXME("(%p,%p,%d): stub\n", iface, info, infolen); return E_FAIL; } -/***********************************************************************/ +static const struct IAVIStreamVtbl avist_vt = { + IAVIStream_fnQueryInterface, + IAVIStream_fnAddRef, + IAVIStream_fnRelease, + IAVIStream_fnCreate, + IAVIStream_fnInfo, + IAVIStream_fnFindSample, + IAVIStream_fnReadFormat, + IAVIStream_fnSetFormat, + IAVIStream_fnRead, + IAVIStream_fnWrite, + IAVIStream_fnDelete, + IAVIStream_fnReadData, + IAVIStream_fnWriteData, + IAVIStream_fnSetInfo +}; + static HRESULT AVIFILE_AddFrame(IAVIStreamImpl *This, DWORD ckid, DWORD size, DWORD offset, DWORD flags) { @@ -1495,7 +1470,7 @@ static void AVIFILE_ConstructAVIStream(IAVIFileImpl *paf, DWORD nr, const AVISTR pstream = paf->ppStreams[nr]; - pstream->lpVtbl = &iavist; + pstream->IAVIStream_iface.lpVtbl = &avist_vt; pstream->ref = 0; pstream->paf = paf; pstream->nStream = nr; @@ -2102,7 +2077,7 @@ static HRESULT AVIFILE_SaveFile(IAVIFileImpl *This) if (This->dwMoviChunkPos == 0) AVIFILE_ComputeMoviStart(This); - /* written one record to much? */ + /* written one record too much? */ if (This->ckLastRecord.dwFlags & MMIO_DIRTY) { This->dwNextFramePos -= 3 * sizeof(DWORD); if (This->nIdxRecords > 0) @@ -2334,7 +2309,7 @@ static HRESULT AVIFILE_SaveIndex(const IAVIFileImpl *This) if (This->ppStreams[0]->sInfo.dwSampleSize == 0) stepsize = 1; else - stepsize = AVIStreamTimeToSample((PAVISTREAM)This->ppStreams[0], 1000000); + stepsize = AVIStreamTimeToSample(&This->ppStreams[0]->IAVIStream_iface, 1000000); assert(stepsize > 0); @@ -2504,8 +2479,8 @@ static void AVIFILE_UpdateInfo(IAVIFileImpl *This) This->fInfo.dwRate = psi->dwRate; This->fInfo.dwLength = psi->dwLength; } else { - n = AVIStreamSampleToSample((PAVISTREAM)This->ppStreams[0], - (PAVISTREAM)This->ppStreams[i],psi->dwLength); + n = AVIStreamSampleToSample(&This->ppStreams[0]->IAVIStream_iface, + &This->ppStreams[i]->IAVIStream_iface, psi->dwLength); if (This->fInfo.dwLength < n) This->fInfo.dwLength = n; } diff --git a/reactos/dll/win32/avifil32/avifile_private.h b/reactos/dll/win32/avifil32/avifile_private.h index 605866edd8e..45fe468fa78 100644 --- a/reactos/dll/win32/avifil32/avifile_private.h +++ b/reactos/dll/win32/avifil32/avifile_private.h @@ -62,7 +62,7 @@ DEFINE_AVIGUID(CLSID_ACMStream, 0x0002000F, 0, 0); extern HMODULE AVIFILE_hModule DECLSPEC_HIDDEN; extern HRESULT AVIFILE_CreateAVIFile(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppobj) DECLSPEC_HIDDEN; -extern HRESULT AVIFILE_CreateWAVFile(REFIID riid, LPVOID *ppobj) DECLSPEC_HIDDEN; +extern HRESULT AVIFILE_CreateWAVFile(IUnknown *outer_unk, REFIID riid, void **ret_iface) DECLSPEC_HIDDEN; extern HRESULT AVIFILE_CreateACMStream(REFIID riid, LPVOID *ppobj) DECLSPEC_HIDDEN; extern HRESULT AVIFILE_CreateICMStream(REFIID riid, LPVOID *ppobj) DECLSPEC_HIDDEN; extern PAVIEDITSTREAM AVIFILE_CreateEditStream(PAVISTREAM pstream) DECLSPEC_HIDDEN; diff --git a/reactos/dll/win32/avifil32/factory.c b/reactos/dll/win32/avifil32/factory.c index e99359868c3..d0eb1efdb3b 100644 --- a/reactos/dll/win32/avifil32/factory.c +++ b/reactos/dll/win32/avifil32/factory.c @@ -133,14 +133,14 @@ static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface, if (IsEqualGUID(&CLSID_AVIFile, &This->clsid)) return AVIFILE_CreateAVIFile(pOuter, riid, ppobj); + if (IsEqualGUID(&CLSID_WAVFile, &This->clsid)) + return AVIFILE_CreateWAVFile(pOuter, riid, ppobj); if (pOuter) return CLASS_E_NOAGGREGATION; if (IsEqualGUID(&CLSID_ICMStream, &This->clsid)) return AVIFILE_CreateICMStream(riid,ppobj); - if (IsEqualGUID(&CLSID_WAVFile, &This->clsid)) - return AVIFILE_CreateWAVFile(riid,ppobj); if (IsEqualGUID(&CLSID_ACMStream, &This->clsid)) return AVIFILE_CreateACMStream(riid,ppobj); diff --git a/reactos/dll/win32/avifil32/icmstream.c b/reactos/dll/win32/avifil32/icmstream.c index bb4155b0582..94df1d9116f 100644 --- a/reactos/dll/win32/avifil32/icmstream.c +++ b/reactos/dll/win32/avifil32/icmstream.c @@ -299,7 +299,7 @@ static LONG WINAPI ICMStream_fnFindSample(IAVIStream *iface, LONG pos, return This->lLastKey; } } else if (flags & FIND_ANY) { - return pos; /* We really don't know, reread is to expensive, so guess. */ + return pos; /* We really don't know, reread is too expensive, so guess. */ } else if (flags & FIND_FORMAT) { if (flags & FIND_PREV) return 0; diff --git a/reactos/dll/win32/avifil32/wavfile.c b/reactos/dll/win32/avifil32/wavfile.c index 42637e3af88..4376ffba679 100644 --- a/reactos/dll/win32/avifil32/wavfile.c +++ b/reactos/dll/win32/avifil32/wavfile.c @@ -67,111 +67,14 @@ typedef struct { /***********************************************************************/ -static HRESULT WINAPI IAVIFile_fnQueryInterface(IAVIFile* iface,REFIID refiid,LPVOID *obj); -static ULONG WINAPI IAVIFile_fnAddRef(IAVIFile* iface); -static ULONG WINAPI IAVIFile_fnRelease(IAVIFile* iface); -static HRESULT WINAPI IAVIFile_fnInfo(IAVIFile*iface,AVIFILEINFOW*afi,LONG size); -static HRESULT WINAPI IAVIFile_fnGetStream(IAVIFile*iface,PAVISTREAM*avis,DWORD fccType,LONG lParam); -static HRESULT WINAPI IAVIFile_fnCreateStream(IAVIFile*iface,PAVISTREAM*avis,AVISTREAMINFOW*asi); -static HRESULT WINAPI IAVIFile_fnWriteData(IAVIFile*iface,DWORD ckid,LPVOID lpData,LONG size); -static HRESULT WINAPI IAVIFile_fnReadData(IAVIFile*iface,DWORD ckid,LPVOID lpData,LONG *size); -static HRESULT WINAPI IAVIFile_fnEndRecord(IAVIFile*iface); -static HRESULT WINAPI IAVIFile_fnDeleteStream(IAVIFile*iface,DWORD fccType,LONG lParam); - -static const struct IAVIFileVtbl iwavft = { - IAVIFile_fnQueryInterface, - IAVIFile_fnAddRef, - IAVIFile_fnRelease, - IAVIFile_fnInfo, - IAVIFile_fnGetStream, - IAVIFile_fnCreateStream, - IAVIFile_fnWriteData, - IAVIFile_fnReadData, - IAVIFile_fnEndRecord, - IAVIFile_fnDeleteStream -}; - -static HRESULT WINAPI IPersistFile_fnQueryInterface(IPersistFile*iface,REFIID refiid,LPVOID*obj); -static ULONG WINAPI IPersistFile_fnAddRef(IPersistFile*iface); -static ULONG WINAPI IPersistFile_fnRelease(IPersistFile*iface); -static HRESULT WINAPI IPersistFile_fnGetClassID(IPersistFile*iface,CLSID*pClassID); -static HRESULT WINAPI IPersistFile_fnIsDirty(IPersistFile*iface); -static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile*iface,LPCOLESTR pszFileName,DWORD dwMode); -static HRESULT WINAPI IPersistFile_fnSave(IPersistFile*iface,LPCOLESTR pszFileName,BOOL fRemember); -static HRESULT WINAPI IPersistFile_fnSaveCompleted(IPersistFile*iface,LPCOLESTR pszFileName); -static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile*iface,LPOLESTR*ppszFileName); - -static const struct IPersistFileVtbl iwavpft = { - IPersistFile_fnQueryInterface, - IPersistFile_fnAddRef, - IPersistFile_fnRelease, - IPersistFile_fnGetClassID, - IPersistFile_fnIsDirty, - IPersistFile_fnLoad, - IPersistFile_fnSave, - IPersistFile_fnSaveCompleted, - IPersistFile_fnGetCurFile -}; - -static HRESULT WINAPI IAVIStream_fnQueryInterface(IAVIStream*iface,REFIID refiid,LPVOID *obj); -static ULONG WINAPI IAVIStream_fnAddRef(IAVIStream*iface); -static ULONG WINAPI IAVIStream_fnRelease(IAVIStream* iface); -static HRESULT WINAPI IAVIStream_fnCreate(IAVIStream*iface,LPARAM lParam1,LPARAM lParam2); -static HRESULT WINAPI IAVIStream_fnInfo(IAVIStream*iface,AVISTREAMINFOW *psi,LONG size); -static LONG WINAPI IAVIStream_fnFindSample(IAVIStream*iface,LONG pos,LONG flags); -static HRESULT WINAPI IAVIStream_fnReadFormat(IAVIStream*iface,LONG pos,LPVOID format,LONG *formatsize); -static HRESULT WINAPI IAVIStream_fnSetFormat(IAVIStream*iface,LONG pos,LPVOID format,LONG formatsize); -static HRESULT WINAPI IAVIStream_fnRead(IAVIStream*iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,LONG *bytesread,LONG *samplesread); -static HRESULT WINAPI IAVIStream_fnWrite(IAVIStream*iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,DWORD flags,LONG *sampwritten,LONG *byteswritten); -static HRESULT WINAPI IAVIStream_fnDelete(IAVIStream*iface,LONG start,LONG samples); -static HRESULT WINAPI IAVIStream_fnReadData(IAVIStream*iface,DWORD fcc,LPVOID lp,LONG *lpread); -static HRESULT WINAPI IAVIStream_fnWriteData(IAVIStream*iface,DWORD fcc,LPVOID lp,LONG size); -static HRESULT WINAPI IAVIStream_fnSetInfo(IAVIStream*iface,AVISTREAMINFOW*info,LONG infolen); - -static const struct IAVIStreamVtbl iwavst = { - IAVIStream_fnQueryInterface, - IAVIStream_fnAddRef, - IAVIStream_fnRelease, - IAVIStream_fnCreate, - IAVIStream_fnInfo, - IAVIStream_fnFindSample, - IAVIStream_fnReadFormat, - IAVIStream_fnSetFormat, - IAVIStream_fnRead, - IAVIStream_fnWrite, - IAVIStream_fnDelete, - IAVIStream_fnReadData, - IAVIStream_fnWriteData, - IAVIStream_fnSetInfo -}; - -typedef struct _IAVIFileImpl IAVIFileImpl; - -typedef struct _IPersistFileImpl { - /* IUnknown stuff */ - const IPersistFileVtbl *lpVtbl; - - /* IPersistFile stuff */ - IAVIFileImpl *paf; -} IPersistFileImpl; - -typedef struct _IAVIStreamImpl { - /* IUnknown stuff */ - const IAVIStreamVtbl *lpVtbl; - - /* IAVIStream stuff */ - IAVIFileImpl *paf; -} IAVIStreamImpl; - -struct _IAVIFileImpl { - /* IUnknown stuff */ - const IAVIFileVtbl *lpVtbl; - LONG ref; - +typedef struct _IAVIFileImpl { + IUnknown IUnknown_inner; + IAVIFile IAVIFile_iface; + IPersistFile IPersistFile_iface; + IAVIStream IAVIStream_iface; + IUnknown *outer_unk; + LONG ref; /* IAVIFile, IAVIStream stuff... */ - IPersistFileImpl iPersistFile; - IAVIStreamImpl iAVIStream; - AVIFILEINFOW fInfo; AVISTREAMINFOW sInfo; @@ -187,7 +90,7 @@ struct _IAVIFileImpl { LPWSTR szFileName; UINT uMode; BOOL fDirty; -}; +} IAVIFileImpl; /***********************************************************************/ @@ -195,108 +98,112 @@ static HRESULT AVIFILE_LoadFile(IAVIFileImpl *This); static HRESULT AVIFILE_LoadSunFile(IAVIFileImpl *This); static HRESULT AVIFILE_SaveFile(const IAVIFileImpl *This); -HRESULT AVIFILE_CreateWAVFile(REFIID riid, LPVOID *ppv) +static inline IAVIFileImpl *impl_from_IUnknown(IUnknown *iface) { - IAVIFileImpl *pfile; - HRESULT hr; - - assert(riid != NULL && ppv != NULL); - - *ppv = NULL; - - pfile = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IAVIFileImpl)); - if (pfile == NULL) - return AVIERR_MEMORY; - - pfile->lpVtbl = &iwavft; - pfile->iPersistFile.lpVtbl = &iwavpft; - pfile->iAVIStream.lpVtbl = &iwavst; - pfile->ref = 0; - pfile->iPersistFile.paf = pfile; - pfile->iAVIStream.paf = pfile; - - hr = IAVIFile_QueryInterface((IAVIFile*)pfile, riid, ppv); - if (FAILED(hr)) - HeapFree(GetProcessHeap(), 0, pfile); - - return hr; + return CONTAINING_RECORD(iface, IAVIFileImpl, IUnknown_inner); } -static HRESULT WINAPI IAVIFile_fnQueryInterface(IAVIFile *iface, REFIID refiid, - LPVOID *obj) +static HRESULT WINAPI IUnknown_fnQueryInterface(IUnknown *iface, REFIID riid, void **ret_iface) { - IAVIFileImpl *This = (IAVIFileImpl *)iface; + IAVIFileImpl *This = impl_from_IUnknown(iface); - TRACE("(%p,%s,%p)\n", This, debugstr_guid(refiid), obj); + TRACE("(%p,%s,%p)\n", This, debugstr_guid(riid), ret_iface); - if (IsEqualGUID(&IID_IUnknown, refiid) || - IsEqualGUID(&IID_IAVIFile, refiid)) { - *obj = iface; - IAVIFile_AddRef(iface); - return S_OK; - } else if (This->fInfo.dwStreams == 1 && - IsEqualGUID(&IID_IAVIStream, refiid)) { - *obj = &This->iAVIStream; - IAVIFile_AddRef(iface); - return S_OK; - } else if (IsEqualGUID(&IID_IPersistFile, refiid)) { - *obj = &This->iPersistFile; - IAVIFile_AddRef(iface); - return S_OK; - } + if (IsEqualGUID(&IID_IUnknown, riid)) + *ret_iface = &This->IUnknown_inner; + else if (IsEqualGUID(&IID_IAVIFile, riid)) + *ret_iface = &This->IAVIFile_iface; + else if (IsEqualGUID(&IID_IAVIStream, riid)) + *ret_iface = &This->IAVIStream_iface; + else if (IsEqualGUID(&IID_IPersistFile, riid)) + *ret_iface = &This->IPersistFile_iface; + else { + WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ret_iface); + *ret_iface = NULL; + return E_NOINTERFACE; + } - return OLE_E_ENUM_NOMORE; + /* Violation of the COM aggregation ref counting rule */ + IUnknown_AddRef(&This->IUnknown_inner); + return S_OK; +} + +static ULONG WINAPI IUnknown_fnAddRef(IUnknown *iface) +{ + IAVIFileImpl *This = impl_from_IUnknown(iface); + ULONG ref = InterlockedIncrement(&This->ref); + + TRACE("(%p) ref=%d\n", This, ref); + + return ref; +} + +static ULONG WINAPI IUnknown_fnRelease(IUnknown *iface) +{ + IAVIFileImpl *This = impl_from_IUnknown(iface); + ULONG ref = InterlockedDecrement(&This->ref); + + TRACE("(%p) ref=%d\n", This, ref); + + if (!ref) { + /* need to write headers to file */ + if (This->fDirty) + AVIFILE_SaveFile(This); + + HeapFree(GetProcessHeap(), 0, This->lpFormat); + This->lpFormat = NULL; + This->cbFormat = 0; + HeapFree(GetProcessHeap(), 0, This->extra.lp); + This->extra.lp = NULL; + This->extra.cb = 0; + HeapFree(GetProcessHeap(), 0, This->szFileName); + This->szFileName = NULL; + if (This->hmmio) { + mmioClose(This->hmmio, 0); + This->hmmio = NULL; + } + HeapFree(GetProcessHeap(), 0, This); + } + + return ref; +} + +static const IUnknownVtbl unk_vtbl = +{ + IUnknown_fnQueryInterface, + IUnknown_fnAddRef, + IUnknown_fnRelease +}; + +static inline IAVIFileImpl *impl_from_IAVIFile(IAVIFile *iface) +{ + return CONTAINING_RECORD(iface, IAVIFileImpl, IAVIFile_iface); +} + +static HRESULT WINAPI IAVIFile_fnQueryInterface(IAVIFile *iface, REFIID riid, void **ret_iface) +{ + IAVIFileImpl *This = impl_from_IAVIFile(iface); + + return IUnknown_QueryInterface(This->outer_unk, riid, ret_iface); } static ULONG WINAPI IAVIFile_fnAddRef(IAVIFile *iface) { - IAVIFileImpl *This = (IAVIFileImpl *)iface; + IAVIFileImpl *This = impl_from_IAVIFile(iface); - TRACE("(%p)\n",iface); - - return InterlockedIncrement(&This->ref); + return IUnknown_AddRef(This->outer_unk); } static ULONG WINAPI IAVIFile_fnRelease(IAVIFile *iface) { - IAVIFileImpl *This = (IAVIFileImpl *)iface; - ULONG ref = InterlockedDecrement(&This->ref); + IAVIFileImpl *This = impl_from_IAVIFile(iface); - TRACE("(%p)\n",iface); - - if (!ref) { - if (This->fDirty) { - /* need to write headers to file */ - AVIFILE_SaveFile(This); - } - - if (This->lpFormat != NULL) { - HeapFree(GetProcessHeap(), 0, This->lpFormat); - This->lpFormat = NULL; - This->cbFormat = 0; - } - if (This->extra.lp != NULL) { - HeapFree(GetProcessHeap(), 0, This->extra.lp); - This->extra.lp = NULL; - This->extra.cb = 0; - } - HeapFree(GetProcessHeap(), 0, This->szFileName); - This->szFileName = NULL; - if (This->hmmio != NULL) { - mmioClose(This->hmmio, 0); - This->hmmio = NULL; - } - - HeapFree(GetProcessHeap(), 0, This); - return 0; - } - return ref; + return IUnknown_Release(This->outer_unk); } -static HRESULT WINAPI IAVIFile_fnInfo(IAVIFile *iface, LPAVIFILEINFOW afi, - LONG size) +static HRESULT WINAPI IAVIFile_fnInfo(IAVIFile *iface, AVIFILEINFOW *afi, LONG size) { - IAVIFileImpl *This = (IAVIFileImpl *)iface; + IAVIFileImpl *This = impl_from_IAVIFile(iface); TRACE("(%p,%p,%d)\n",iface,afi,size); @@ -327,10 +234,10 @@ static HRESULT WINAPI IAVIFile_fnInfo(IAVIFile *iface, LPAVIFILEINFOW afi, return AVIERR_OK; } -static HRESULT WINAPI IAVIFile_fnGetStream(IAVIFile *iface, PAVISTREAM *avis, - DWORD fccType, LONG lParam) +static HRESULT WINAPI IAVIFile_fnGetStream(IAVIFile *iface, IAVIStream **avis, DWORD fccType, + LONG lParam) { - IAVIFileImpl *This = (IAVIFileImpl *)iface; + IAVIFileImpl *This = impl_from_IAVIFile(iface); TRACE("(%p,%p,0x%08X,%d)\n", iface, avis, fccType, lParam); @@ -346,16 +253,16 @@ static HRESULT WINAPI IAVIFile_fnGetStream(IAVIFile *iface, PAVISTREAM *avis, if (fccType != 0 && fccType != streamtypeAUDIO) return AVIERR_NODATA; - *avis = (PAVISTREAM)&This->iAVIStream; - IAVIFile_AddRef(iface); + *avis = &This->IAVIStream_iface; + IAVIStream_AddRef(*avis); return AVIERR_OK; } -static HRESULT WINAPI IAVIFile_fnCreateStream(IAVIFile *iface,PAVISTREAM *avis, - LPAVISTREAMINFOW asi) +static HRESULT WINAPI IAVIFile_fnCreateStream(IAVIFile *iface, IAVIStream **avis, + AVISTREAMINFOW *asi) { - IAVIFileImpl *This = (IAVIFileImpl *)iface; + IAVIFileImpl *This = impl_from_IAVIFile(iface); TRACE("(%p,%p,%p)\n", iface, avis, asi); @@ -397,16 +304,15 @@ static HRESULT WINAPI IAVIFile_fnCreateStream(IAVIFile *iface,PAVISTREAM *avis, This->ckData.dwDataOffset = 0; This->ckData.cksize = 0; - *avis = (PAVISTREAM)&This->iAVIStream; - IAVIFile_AddRef(iface); + *avis = &This->IAVIStream_iface; + IAVIStream_AddRef(*avis); return AVIERR_OK; } -static HRESULT WINAPI IAVIFile_fnWriteData(IAVIFile *iface, DWORD ckid, - LPVOID lpData, LONG size) +static HRESULT WINAPI IAVIFile_fnWriteData(IAVIFile *iface, DWORD ckid, void *lpData, LONG size) { - IAVIFileImpl *This = (IAVIFileImpl *)iface; + IAVIFileImpl *This = impl_from_IAVIFile(iface); TRACE("(%p,0x%08X,%p,%d)\n", iface, ckid, lpData, size); @@ -425,10 +331,9 @@ static HRESULT WINAPI IAVIFile_fnWriteData(IAVIFile *iface, DWORD ckid, return WriteExtraChunk(&This->extra, ckid, lpData, size); } -static HRESULT WINAPI IAVIFile_fnReadData(IAVIFile *iface, DWORD ckid, - LPVOID lpData, LONG *size) +static HRESULT WINAPI IAVIFile_fnReadData(IAVIFile *iface, DWORD ckid, void *lpData, LONG *size) { - IAVIFileImpl *This = (IAVIFileImpl *)iface; + IAVIFileImpl *This = impl_from_IAVIFile(iface); TRACE("(%p,0x%08X,%p,%p)\n", iface, ckid, lpData, size); @@ -445,10 +350,9 @@ static HRESULT WINAPI IAVIFile_fnEndRecord(IAVIFile *iface) return AVIERR_OK; } -static HRESULT WINAPI IAVIFile_fnDeleteStream(IAVIFile *iface, DWORD fccType, - LONG lParam) +static HRESULT WINAPI IAVIFile_fnDeleteStream(IAVIFile *iface, DWORD fccType, LONG lParam) { - IAVIFileImpl *This = (IAVIFileImpl *)iface; + IAVIFileImpl *This = impl_from_IAVIFile(iface); TRACE("(%p,0x%08X,%d)\n", iface, fccType, lParam); @@ -486,34 +390,46 @@ static HRESULT WINAPI IAVIFile_fnDeleteStream(IAVIFile *iface, DWORD fccType, return AVIERR_OK; } +static const struct IAVIFileVtbl iwavft = { + IAVIFile_fnQueryInterface, + IAVIFile_fnAddRef, + IAVIFile_fnRelease, + IAVIFile_fnInfo, + IAVIFile_fnGetStream, + IAVIFile_fnCreateStream, + IAVIFile_fnWriteData, + IAVIFile_fnReadData, + IAVIFile_fnEndRecord, + IAVIFile_fnDeleteStream +}; + /***********************************************************************/ -static HRESULT WINAPI IPersistFile_fnQueryInterface(IPersistFile *iface, - REFIID refiid, LPVOID *obj) +static inline IAVIFileImpl *impl_from_IPersistFile(IPersistFile *iface) { - IPersistFileImpl *This = (IPersistFileImpl *)iface; + return CONTAINING_RECORD(iface, IAVIFileImpl, IPersistFile_iface); +} - assert(This->paf != NULL); +static HRESULT WINAPI IPersistFile_fnQueryInterface(IPersistFile *iface, REFIID riid, + void **ret_iface) +{ + IAVIFileImpl *This = impl_from_IPersistFile(iface); - return IAVIFile_QueryInterface((PAVIFILE)This->paf, refiid, obj); + return IUnknown_QueryInterface(This->outer_unk, riid, ret_iface); } static ULONG WINAPI IPersistFile_fnAddRef(IPersistFile *iface) { - IPersistFileImpl *This = (IPersistFileImpl *)iface; + IAVIFileImpl *This = impl_from_IPersistFile(iface); - assert(This->paf != NULL); - - return IAVIFile_AddRef((PAVIFILE)This->paf); + return IUnknown_AddRef(This->outer_unk); } static ULONG WINAPI IPersistFile_fnRelease(IPersistFile *iface) { - IPersistFileImpl *This = (IPersistFileImpl *)iface; + IAVIFileImpl *This = impl_from_IPersistFile(iface); - assert(This->paf != NULL); - - return IAVIFile_Release((PAVIFILE)This->paf); + return IUnknown_Release(This->outer_unk); } static HRESULT WINAPI IPersistFile_fnGetClassID(IPersistFile *iface, @@ -531,20 +447,16 @@ static HRESULT WINAPI IPersistFile_fnGetClassID(IPersistFile *iface, static HRESULT WINAPI IPersistFile_fnIsDirty(IPersistFile *iface) { - IPersistFileImpl *This = (IPersistFileImpl *)iface; + IAVIFileImpl *This = impl_from_IPersistFile(iface); - TRACE("(%p)\n", iface); + TRACE("(%p)\n", iface); - assert(This->paf != NULL); - - return (This->paf->fDirty ? S_OK : S_FALSE); + return (This->fDirty ? S_OK : S_FALSE); } -static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile *iface, - LPCOLESTR pszFileName, DWORD dwMode) +static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile *iface, LPCOLESTR pszFileName, DWORD dwMode) { - IAVIFileImpl *This = ((IPersistFileImpl*)iface)->paf; - + IAVIFileImpl *This = impl_from_IPersistFile(iface); WCHAR wszStreamFmt[50]; INT len; @@ -554,7 +466,6 @@ static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile *iface, if (pszFileName == NULL) return AVIERR_BADPARAM; - assert(This != NULL); if (This->hmmio != NULL) return AVIERR_ERROR; /* No reuse of this object for another file! */ @@ -626,10 +537,9 @@ static HRESULT WINAPI IPersistFile_fnSaveCompleted(IPersistFile *iface, return AVIERR_OK; } -static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile *iface, - LPOLESTR *ppszFileName) +static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile *iface, LPOLESTR *ppszFileName) { - IPersistFileImpl *This = (IPersistFileImpl *)iface; + IAVIFileImpl *This = impl_from_IPersistFile(iface); TRACE("(%p,%p)\n", iface, ppszFileName); @@ -638,49 +548,57 @@ static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile *iface, *ppszFileName = NULL; - assert(This->paf != NULL); - - if (This->paf->szFileName != NULL) { - int len = lstrlenW(This->paf->szFileName) + 1; + if (This->szFileName) { + int len = lstrlenW(This->szFileName) + 1; *ppszFileName = CoTaskMemAlloc(len * sizeof(WCHAR)); if (*ppszFileName == NULL) return AVIERR_MEMORY; - strcpyW(*ppszFileName, This->paf->szFileName); + strcpyW(*ppszFileName, This->szFileName); } return AVIERR_OK; } +static const struct IPersistFileVtbl iwavpft = { + IPersistFile_fnQueryInterface, + IPersistFile_fnAddRef, + IPersistFile_fnRelease, + IPersistFile_fnGetClassID, + IPersistFile_fnIsDirty, + IPersistFile_fnLoad, + IPersistFile_fnSave, + IPersistFile_fnSaveCompleted, + IPersistFile_fnGetCurFile +}; + /***********************************************************************/ -static HRESULT WINAPI IAVIStream_fnQueryInterface(IAVIStream *iface, - REFIID refiid, LPVOID *obj) +static inline IAVIFileImpl *impl_from_IAVIStream(IAVIStream *iface) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + return CONTAINING_RECORD(iface, IAVIFileImpl, IAVIStream_iface); +} - assert(This->paf != NULL); +static HRESULT WINAPI IAVIStream_fnQueryInterface(IAVIStream *iface, REFIID riid, void **ret_iface) +{ + IAVIFileImpl *This = impl_from_IAVIStream(iface); - return IAVIFile_QueryInterface((PAVIFILE)This->paf, refiid, obj); + return IUnknown_QueryInterface(This->outer_unk, riid, ret_iface); } static ULONG WINAPI IAVIStream_fnAddRef(IAVIStream *iface) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIFileImpl *This = impl_from_IAVIStream(iface); - assert(This->paf != NULL); - - return IAVIFile_AddRef((PAVIFILE)This->paf); + return IUnknown_AddRef(This->outer_unk); } static ULONG WINAPI IAVIStream_fnRelease(IAVIStream* iface) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIFileImpl *This = impl_from_IAVIStream(iface); - assert(This->paf != NULL); - - return IAVIFile_Release((PAVIFILE)This->paf); + return IUnknown_Release(This->outer_unk); } static HRESULT WINAPI IAVIStream_fnCreate(IAVIStream *iface, LPARAM lParam1, @@ -692,10 +610,9 @@ static HRESULT WINAPI IAVIStream_fnCreate(IAVIStream *iface, LPARAM lParam1, return AVIERR_UNSUPPORTED; } -static HRESULT WINAPI IAVIStream_fnInfo(IAVIStream *iface,LPAVISTREAMINFOW psi, - LONG size) +static HRESULT WINAPI IAVIStream_fnInfo(IAVIStream *iface, AVISTREAMINFOW *psi, LONG size) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIFileImpl *This = impl_from_IAVIStream(iface); TRACE("(%p,%p,%d)\n", iface, psi, size); @@ -704,17 +621,16 @@ static HRESULT WINAPI IAVIStream_fnInfo(IAVIStream *iface,LPAVISTREAMINFOW psi, if (size < 0) return AVIERR_BADSIZE; - memcpy(psi, &This->paf->sInfo, min((DWORD)size, sizeof(This->paf->sInfo))); + memcpy(psi, &This->sInfo, min((DWORD)size, sizeof(This->sInfo))); - if ((DWORD)size < sizeof(This->paf->sInfo)) + if ((DWORD)size < sizeof(This->sInfo)) return AVIERR_BUFFERTOOSMALL; return AVIERR_OK; } -static LONG WINAPI IAVIStream_fnFindSample(IAVIStream *iface, LONG pos, - LONG flags) +static LONG WINAPI IAVIStream_fnFindSample(IAVIStream *iface, LONG pos, LONG flags) { - IAVIFileImpl *This = ((IAVIStreamImpl*)iface)->paf; + IAVIFileImpl *This = impl_from_IAVIStream(iface); TRACE("(%p,%d,0x%08X)\n",iface,pos,flags); @@ -748,10 +664,10 @@ static LONG WINAPI IAVIStream_fnFindSample(IAVIStream *iface, LONG pos, return pos; } -static HRESULT WINAPI IAVIStream_fnReadFormat(IAVIStream *iface, LONG pos, - LPVOID format, LONG *formatsize) +static HRESULT WINAPI IAVIStream_fnReadFormat(IAVIStream *iface, LONG pos, void *format, + LONG *formatsize) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIFileImpl *This = impl_from_IAVIStream(iface); TRACE("(%p,%d,%p,%p)\n", iface, pos, format, formatsize); @@ -760,26 +676,26 @@ static HRESULT WINAPI IAVIStream_fnReadFormat(IAVIStream *iface, LONG pos, /* only interested in needed buffersize? */ if (format == NULL || *formatsize <= 0) { - *formatsize = This->paf->cbFormat; + *formatsize = This->cbFormat; return AVIERR_OK; } /* copy initial format (only as much as will fit) */ - memcpy(format, This->paf->lpFormat, min(*formatsize, This->paf->cbFormat)); - if (*formatsize < This->paf->cbFormat) { - *formatsize = This->paf->cbFormat; + memcpy(format, This->lpFormat, min(*formatsize, This->cbFormat)); + if (*formatsize < This->cbFormat) { + *formatsize = This->cbFormat; return AVIERR_BUFFERTOOSMALL; } - *formatsize = This->paf->cbFormat; + *formatsize = This->cbFormat; return AVIERR_OK; } -static HRESULT WINAPI IAVIStream_fnSetFormat(IAVIStream *iface, LONG pos, - LPVOID format, LONG formatsize) +static HRESULT WINAPI IAVIStream_fnSetFormat(IAVIStream *iface, LONG pos, void *format, + LONG formatsize) { - IAVIFileImpl *This = ((IAVIStreamImpl*)iface)->paf; + IAVIFileImpl *This = impl_from_IAVIStream(iface); TRACE("(%p,%d,%p,%d)\n", iface, pos, format, formatsize); @@ -831,12 +747,10 @@ static HRESULT WINAPI IAVIStream_fnSetFormat(IAVIStream *iface, LONG pos, return AVIERR_OK; } -static HRESULT WINAPI IAVIStream_fnRead(IAVIStream *iface, LONG start, - LONG samples, LPVOID buffer, - LONG buffersize, LPLONG bytesread, - LPLONG samplesread) +static HRESULT WINAPI IAVIStream_fnRead(IAVIStream *iface, LONG start, LONG samples, void *buffer, + LONG buffersize, LONG *bytesread, LONG *samplesread) { - IAVIFileImpl *This = ((IAVIStreamImpl*)iface)->paf; + IAVIFileImpl *This = impl_from_IAVIStream(iface); TRACE("(%p,%d,%d,%p,%d,%p,%p)\n", iface, start, samples, buffer, buffersize, bytesread, samplesread); @@ -904,13 +818,10 @@ static HRESULT WINAPI IAVIStream_fnRead(IAVIStream *iface, LONG start, return AVIERR_OK; } -static HRESULT WINAPI IAVIStream_fnWrite(IAVIStream *iface, LONG start, - LONG samples, LPVOID buffer, - LONG buffersize, DWORD flags, - LPLONG sampwritten, - LPLONG byteswritten) +static HRESULT WINAPI IAVIStream_fnWrite(IAVIStream *iface, LONG start, LONG samples, void *buffer, + LONG buffersize, DWORD flags, LONG *sampwritten, LONG *byteswritten) { - IAVIFileImpl *This = ((IAVIStreamImpl*)iface)->paf; + IAVIFileImpl *This = impl_from_IAVIStream(iface); TRACE("(%p,%d,%d,%p,%d,0x%08X,%p,%p)\n", iface, start, samples, buffer, buffersize, flags, sampwritten, byteswritten); @@ -939,7 +850,7 @@ static HRESULT WINAPI IAVIStream_fnWrite(IAVIStream *iface, LONG start, /* do we have anything to write? */ if (buffer != NULL && buffersize > 0) { - This->fDirty = 1; + This->fDirty = TRUE; if (mmioSeek(This->hmmio, This->ckData.dwDataOffset + start * This->sInfo.dwSampleSize, SEEK_SET) == -1) @@ -961,10 +872,9 @@ static HRESULT WINAPI IAVIStream_fnWrite(IAVIStream *iface, LONG start, return AVIERR_OK; } -static HRESULT WINAPI IAVIStream_fnDelete(IAVIStream *iface, LONG start, - LONG samples) +static HRESULT WINAPI IAVIStream_fnDelete(IAVIStream *iface, LONG start, LONG samples) { - IAVIFileImpl *This = ((IAVIStreamImpl*)iface)->paf; + IAVIFileImpl *This = impl_from_IAVIStream(iface); TRACE("(%p,%d,%d)\n", iface, start, samples); @@ -1002,27 +912,23 @@ static HRESULT WINAPI IAVIStream_fnDelete(IAVIStream *iface, LONG start, return AVIERR_UNSUPPORTED; } - This->fDirty = 1; + This->fDirty = TRUE; return AVIERR_OK; } -static HRESULT WINAPI IAVIStream_fnReadData(IAVIStream *iface, DWORD fcc, - LPVOID lp, LPLONG lpread) +static HRESULT WINAPI IAVIStream_fnReadData(IAVIStream *iface, DWORD fcc, void *lp, LONG *lpread) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIFileImpl *This = impl_from_IAVIStream(iface); - assert(This->paf != NULL); - - return IAVIFile_ReadData((PAVIFILE)This->paf, fcc, lp, lpread); + return IAVIFile_ReadData(&This->IAVIFile_iface, fcc, lp, lpread); } -static HRESULT WINAPI IAVIStream_fnWriteData(IAVIStream *iface, DWORD fcc, - LPVOID lp, LONG size) +static HRESULT WINAPI IAVIStream_fnWriteData(IAVIStream *iface, DWORD fcc, void *lp, LONG size) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIFileImpl *This = impl_from_IAVIStream(iface); - return IAVIFile_WriteData((PAVIFILE)This->paf, fcc, lp, size); + return IAVIFile_WriteData(&This->IAVIFile_iface, fcc, lp, size); } static HRESULT WINAPI IAVIStream_fnSetInfo(IAVIStream *iface, @@ -1033,6 +939,50 @@ static HRESULT WINAPI IAVIStream_fnSetInfo(IAVIStream *iface, return E_FAIL; } +static const struct IAVIStreamVtbl iwavst = { + IAVIStream_fnQueryInterface, + IAVIStream_fnAddRef, + IAVIStream_fnRelease, + IAVIStream_fnCreate, + IAVIStream_fnInfo, + IAVIStream_fnFindSample, + IAVIStream_fnReadFormat, + IAVIStream_fnSetFormat, + IAVIStream_fnRead, + IAVIStream_fnWrite, + IAVIStream_fnDelete, + IAVIStream_fnReadData, + IAVIStream_fnWriteData, + IAVIStream_fnSetInfo +}; + +HRESULT AVIFILE_CreateWAVFile(IUnknown *outer_unk, REFIID riid, void **ret_iface) +{ + IAVIFileImpl *pfile; + HRESULT hr; + + *ret_iface = NULL; + + pfile = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*pfile)); + if (!pfile) + return AVIERR_MEMORY; + + pfile->IUnknown_inner.lpVtbl = &unk_vtbl; + pfile->IAVIFile_iface.lpVtbl = &iwavft; + pfile->IPersistFile_iface.lpVtbl = &iwavpft; + pfile->IAVIStream_iface.lpVtbl = &iwavst; + pfile->ref = 1; + if (outer_unk) + pfile->outer_unk = outer_unk; + else + pfile->outer_unk = &pfile->IUnknown_inner; + + hr = IUnknown_QueryInterface(&pfile->IUnknown_inner, riid, ret_iface); + IUnknown_Release(&pfile->IUnknown_inner); + + return hr; +} + /***********************************************************************/ static HRESULT AVIFILE_LoadFile(IAVIFileImpl *This) @@ -1206,7 +1156,7 @@ static HRESULT AVIFILE_LoadSunFile(IAVIFileImpl *This) This->lpFormat->nAvgBytesPerSec = This->lpFormat->nBlockAlign * This->lpFormat->nSamplesPerSec; - This->fDirty = 0; + This->fDirty = FALSE; This->sInfo.fccType = streamtypeAUDIO; This->sInfo.fccHandler = 0; diff --git a/reactos/media/doc/README.WINE b/reactos/media/doc/README.WINE index 1ce8eb8f6aa..6b460562b5e 100644 --- a/reactos/media/doc/README.WINE +++ b/reactos/media/doc/README.WINE @@ -54,7 +54,7 @@ reactos/dll/win32/advpack # Synced to Wine-1.7.1 reactos/dll/win32/atl # Synced to Wine-1.7.1 reactos/dll/win32/atl100 # Synced to Wine-1.7.1 reactos/dll/win32/atl80 # Synced to Wine-1.7.1 -reactos/dll/win32/avifil32 # Synced to Wine-1.7.1 +reactos/dll/win32/avifil32 # Synced to Wine-1.7.17 reactos/dll/win32/bcrypt # Synced to Wine-1.7.1 reactos/dll/win32/browseui # Out of sync reactos/dll/win32/cabinet # Synced to Wine-1.7.1