X-Git-Url: https://git.reactos.org/?p=reactos.git;a=blobdiff_plain;f=dll%2Fwin32%2Favifil32%2Facmstream.c;h=e77b4f98fa0cfe062d3ac88a3e0cdbc36bb0eb3e;hp=7794f54ab067d7c7c264275f6bef7b86d132d977;hb=609ba8d717a023afd92609eaffce2aafd4c1d774;hpb=b1d8a4df819c95bcb81cd8d6e8d9a397125147a9 diff --git a/dll/win32/avifil32/acmstream.c b/dll/win32/avifil32/acmstream.c index 7794f54ab06..e77b4f98fa0 100644 --- a/dll/win32/avifil32/acmstream.c +++ b/dll/win32/avifil32/acmstream.c @@ -16,61 +16,13 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -#include -#include - -#include "windef.h" -#include "winbase.h" -#include "wingdi.h" -#include "winuser.h" -#include "winerror.h" -#include "mmsystem.h" -#include "vfw.h" -#include "msacm.h" - #include "avifile_private.h" -#include "wine/debug.h" - -WINE_DEFAULT_DEBUG_CHANNEL(avifile); - /***********************************************************************/ -static HRESULT WINAPI ACMStream_fnQueryInterface(IAVIStream*iface,REFIID refiid,LPVOID *obj); -static ULONG WINAPI ACMStream_fnAddRef(IAVIStream*iface); -static ULONG WINAPI ACMStream_fnRelease(IAVIStream* iface); -static HRESULT WINAPI ACMStream_fnCreate(IAVIStream*iface,LPARAM lParam1,LPARAM lParam2); -static HRESULT WINAPI ACMStream_fnInfo(IAVIStream*iface,AVISTREAMINFOW *psi,LONG size); -static LONG WINAPI ACMStream_fnFindSample(IAVIStream*iface,LONG pos,LONG flags); -static HRESULT WINAPI ACMStream_fnReadFormat(IAVIStream*iface,LONG pos,LPVOID format,LONG *formatsize); -static HRESULT WINAPI ACMStream_fnSetFormat(IAVIStream*iface,LONG pos,LPVOID format,LONG formatsize); -static HRESULT WINAPI ACMStream_fnRead(IAVIStream*iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,LONG *bytesread,LONG *samplesread); -static HRESULT WINAPI ACMStream_fnWrite(IAVIStream*iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,DWORD flags,LONG *sampwritten,LONG *byteswritten); -static HRESULT WINAPI ACMStream_fnDelete(IAVIStream*iface,LONG start,LONG samples); -static HRESULT WINAPI ACMStream_fnReadData(IAVIStream*iface,DWORD fcc,LPVOID lp,LONG *lpread); -static HRESULT WINAPI ACMStream_fnWriteData(IAVIStream*iface,DWORD fcc,LPVOID lp,LONG size); -static HRESULT WINAPI ACMStream_fnSetInfo(IAVIStream*iface,AVISTREAMINFOW*info,LONG infolen); - -static const struct IAVIStreamVtbl iacmst = { - ACMStream_fnQueryInterface, - ACMStream_fnAddRef, - ACMStream_fnRelease, - ACMStream_fnCreate, - ACMStream_fnInfo, - ACMStream_fnFindSample, - ACMStream_fnReadFormat, - ACMStream_fnSetFormat, - ACMStream_fnRead, - ACMStream_fnWrite, - ACMStream_fnDelete, - ACMStream_fnReadData, - ACMStream_fnWriteData, - ACMStream_fnSetInfo -}; - typedef struct _IAVIStreamImpl { /* IUnknown stuff */ - const IAVIStreamVtbl *lpVtbl; + IAVIStream IAVIStream_iface; LONG ref; /* IAVIStream stuff */ @@ -102,34 +54,74 @@ typedef struct _IAVIStreamImpl { &__bytes, ACM_STREAMSIZEF_DESTINATION); \ *(a) = __bytes / This->lpInFormat->nBlockAlign; } while(0) -static HRESULT AVIFILE_OpenCompressor(IAVIStreamImpl *This); - -HRESULT AVIFILE_CreateACMStream(REFIID riid, LPVOID *ppv) +static HRESULT AVIFILE_OpenCompressor(IAVIStreamImpl *This) { - IAVIStreamImpl *pstream; - HRESULT hr; + HRESULT hr; - assert(riid != NULL && ppv != NULL); + /* pre-conditions */ + assert(This != NULL); + assert(This->pStream != NULL); - *ppv = NULL; + if (This->has != NULL) + return AVIERR_OK; - pstream = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IAVIStreamImpl)); - if (pstream == NULL) - return AVIERR_MEMORY; + if (This->lpInFormat == NULL) { + /* decode or encode the data from pStream */ + hr = AVIStreamFormatSize(This->pStream, This->sInfo.dwStart, &This->cbInFormat); + if (FAILED(hr)) + return hr; + This->lpInFormat = HeapAlloc(GetProcessHeap(), 0, This->cbInFormat); + if (This->lpInFormat == NULL) + return AVIERR_MEMORY; - pstream->lpVtbl = &iacmst; + hr = IAVIStream_ReadFormat(This->pStream, This->sInfo.dwStart, + This->lpInFormat, &This->cbInFormat); + if (FAILED(hr)) + return hr; - hr = IAVIStream_QueryInterface((IAVIStream*)pstream, riid, ppv); - if (FAILED(hr)) - HeapFree(GetProcessHeap(), 0, pstream); + if (This->lpOutFormat == NULL) { + /* we must decode to default format */ + This->cbOutFormat = sizeof(PCMWAVEFORMAT); + This->lpOutFormat = HeapAlloc(GetProcessHeap(), 0, This->cbOutFormat); + if (This->lpOutFormat == NULL) + return AVIERR_MEMORY; - return hr; + This->lpOutFormat->wFormatTag = WAVE_FORMAT_PCM; + if (acmFormatSuggest(NULL, This->lpInFormat, This->lpOutFormat, + This->cbOutFormat, ACM_FORMATSUGGESTF_WFORMATTAG) != S_OK) + return AVIERR_NOCOMPRESSOR; + } + } else if (This->lpOutFormat == NULL) + return AVIERR_ERROR; /* To what should I encode? */ + + if (acmStreamOpen(&This->has, NULL, This->lpInFormat, This->lpOutFormat, + NULL, 0, 0, ACM_STREAMOPENF_NONREALTIME) != S_OK) + return AVIERR_NOCOMPRESSOR; + + /* update AVISTREAMINFO structure */ + This->sInfo.dwSampleSize = This->lpOutFormat->nBlockAlign; + This->sInfo.dwScale = This->lpOutFormat->nBlockAlign; + This->sInfo.dwRate = This->lpOutFormat->nAvgBytesPerSec; + This->sInfo.dwQuality = (DWORD)ICQUALITY_DEFAULT; + SetRectEmpty(&This->sInfo.rcFrame); + + /* convert positions and sizes to output format */ + CONVERT_STREAM_to_THIS(&This->sInfo.dwStart); + CONVERT_STREAM_to_THIS(&This->sInfo.dwLength); + CONVERT_STREAM_to_THIS(&This->sInfo.dwSuggestedBufferSize); + + return AVIERR_OK; +} + +static inline IAVIStreamImpl *impl_from_IAVIStream(IAVIStream *iface) +{ + return CONTAINING_RECORD(iface, IAVIStreamImpl, IAVIStream_iface); } static HRESULT WINAPI ACMStream_fnQueryInterface(IAVIStream *iface, REFIID refiid, LPVOID *obj) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); TRACE("(%p,%s,%p)\n", iface, debugstr_guid(refiid), obj); @@ -146,7 +138,7 @@ static HRESULT WINAPI ACMStream_fnQueryInterface(IAVIStream *iface, static ULONG WINAPI ACMStream_fnAddRef(IAVIStream *iface) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); ULONG ref = InterlockedIncrement(&This->ref); TRACE("(%p) -> %d\n", iface, ref); @@ -160,7 +152,7 @@ static ULONG WINAPI ACMStream_fnAddRef(IAVIStream *iface) static ULONG WINAPI ACMStream_fnRelease(IAVIStream* iface) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); ULONG ref = InterlockedDecrement(&This->ref); TRACE("(%p) -> %d\n", iface, ref); @@ -209,14 +201,14 @@ static ULONG WINAPI ACMStream_fnRelease(IAVIStream* iface) static HRESULT WINAPI ACMStream_fnCreate(IAVIStream *iface, LPARAM lParam1, LPARAM lParam2) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); TRACE("(%p,0x%08lX,0x%08lX)\n", iface, lParam1, lParam2); /* check for swapped parameters */ if ((LPVOID)lParam1 != NULL && ((LPAVICOMPRESSOPTIONS)lParam1)->fccType == streamtypeAUDIO) { - register LPARAM tmp = lParam1; + LPARAM tmp = lParam1; lParam1 = lParam2; lParam2 = tmp; @@ -262,7 +254,7 @@ static HRESULT WINAPI ACMStream_fnCreate(IAVIStream *iface, LPARAM lParam1, static HRESULT WINAPI ACMStream_fnInfo(IAVIStream *iface,LPAVISTREAMINFOW psi, LONG size) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); TRACE("(%p,%p,%d)\n", iface, psi, size); @@ -289,7 +281,7 @@ static HRESULT WINAPI ACMStream_fnInfo(IAVIStream *iface,LPAVISTREAMINFOW psi, static LONG WINAPI ACMStream_fnFindSample(IAVIStream *iface, LONG pos, LONG flags) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); TRACE("(%p,%d,0x%08X)\n",iface,pos,flags); @@ -317,7 +309,7 @@ static LONG WINAPI ACMStream_fnFindSample(IAVIStream *iface, LONG pos, static HRESULT WINAPI ACMStream_fnReadFormat(IAVIStream *iface, LONG pos, LPVOID format, LONG *formatsize) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); TRACE("(%p,%d,%p,%p)\n", iface, pos, format, formatsize); @@ -352,7 +344,7 @@ static HRESULT WINAPI ACMStream_fnReadFormat(IAVIStream *iface, LONG pos, static HRESULT WINAPI ACMStream_fnSetFormat(IAVIStream *iface, LONG pos, LPVOID format, LONG formatsize) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); HRESULT hr; @@ -399,7 +391,7 @@ static HRESULT WINAPI ACMStream_fnRead(IAVIStream *iface, LONG start, LONG buffersize, LPLONG bytesread, LPLONG samplesread) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); HRESULT hr; DWORD size; @@ -520,7 +512,7 @@ static HRESULT WINAPI ACMStream_fnWrite(IAVIStream *iface, LONG start, LPLONG sampwritten, LPLONG byteswritten) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); HRESULT hr; ULONG size; @@ -613,7 +605,7 @@ static HRESULT WINAPI ACMStream_fnWrite(IAVIStream *iface, LONG start, static HRESULT WINAPI ACMStream_fnDelete(IAVIStream *iface, LONG start, LONG samples) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); TRACE("(%p,%d,%d)\n", iface, start, samples); @@ -647,7 +639,7 @@ static HRESULT WINAPI ACMStream_fnDelete(IAVIStream *iface, LONG start, static HRESULT WINAPI ACMStream_fnReadData(IAVIStream *iface, DWORD fcc, LPVOID lp, LPLONG lpread) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); TRACE("(%p,0x%08X,%p,%p)\n", iface, fcc, lp, lpread); @@ -659,7 +651,7 @@ static HRESULT WINAPI ACMStream_fnReadData(IAVIStream *iface, DWORD fcc, static HRESULT WINAPI ACMStream_fnWriteData(IAVIStream *iface, DWORD fcc, LPVOID lp, LONG size) { - IAVIStreamImpl *This = (IAVIStreamImpl *)iface; + IAVIStreamImpl *This = impl_from_IAVIStream(iface); TRACE("(%p,0x%08x,%p,%d)\n", iface, fcc, lp, size); @@ -676,63 +668,41 @@ static HRESULT WINAPI ACMStream_fnSetInfo(IAVIStream *iface, return E_FAIL; } -/***********************************************************************/ +static const struct IAVIStreamVtbl iacmst = { + ACMStream_fnQueryInterface, + ACMStream_fnAddRef, + ACMStream_fnRelease, + ACMStream_fnCreate, + ACMStream_fnInfo, + ACMStream_fnFindSample, + ACMStream_fnReadFormat, + ACMStream_fnSetFormat, + ACMStream_fnRead, + ACMStream_fnWrite, + ACMStream_fnDelete, + ACMStream_fnReadData, + ACMStream_fnWriteData, + ACMStream_fnSetInfo +}; -static HRESULT AVIFILE_OpenCompressor(IAVIStreamImpl *This) +HRESULT AVIFILE_CreateACMStream(REFIID riid, LPVOID *ppv) { - HRESULT hr; - - /* pre-conditions */ - assert(This != NULL); - assert(This->pStream != NULL); - - if (This->has != NULL) - return AVIERR_OK; - - if (This->lpInFormat == NULL) { - /* decode or encode the data from pStream */ - hr = AVIStreamFormatSize(This->pStream, This->sInfo.dwStart, &This->cbInFormat); - if (FAILED(hr)) - return hr; - This->lpInFormat = HeapAlloc(GetProcessHeap(), 0, This->cbInFormat); - if (This->lpInFormat == NULL) - return AVIERR_MEMORY; - - hr = IAVIStream_ReadFormat(This->pStream, This->sInfo.dwStart, - This->lpInFormat, &This->cbInFormat); - if (FAILED(hr)) - return hr; + IAVIStreamImpl *pstream; + HRESULT hr; - if (This->lpOutFormat == NULL) { - /* we must decode to default format */ - This->cbOutFormat = sizeof(PCMWAVEFORMAT); - This->lpOutFormat = HeapAlloc(GetProcessHeap(), 0, This->cbOutFormat); - if (This->lpOutFormat == NULL) - return AVIERR_MEMORY; + assert(riid != NULL && ppv != NULL); - This->lpOutFormat->wFormatTag = WAVE_FORMAT_PCM; - if (acmFormatSuggest(NULL, This->lpInFormat, This->lpOutFormat, - This->cbOutFormat, ACM_FORMATSUGGESTF_WFORMATTAG) != S_OK) - return AVIERR_NOCOMPRESSOR; - } - } else if (This->lpOutFormat == NULL) - return AVIERR_ERROR; /* To what should I encode? */ + *ppv = NULL; - if (acmStreamOpen(&This->has, NULL, This->lpInFormat, This->lpOutFormat, - NULL, 0, 0, ACM_STREAMOPENF_NONREALTIME) != S_OK) - return AVIERR_NOCOMPRESSOR; + pstream = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IAVIStreamImpl)); + if (pstream == NULL) + return AVIERR_MEMORY; - /* update AVISTREAMINFO structure */ - This->sInfo.dwSampleSize = This->lpOutFormat->nBlockAlign; - This->sInfo.dwScale = This->lpOutFormat->nBlockAlign; - This->sInfo.dwRate = This->lpOutFormat->nAvgBytesPerSec; - This->sInfo.dwQuality = (DWORD)ICQUALITY_DEFAULT; - SetRectEmpty(&This->sInfo.rcFrame); + pstream->IAVIStream_iface.lpVtbl = &iacmst; - /* convert positions and sizes to output format */ - CONVERT_STREAM_to_THIS(&This->sInfo.dwStart); - CONVERT_STREAM_to_THIS(&This->sInfo.dwLength); - CONVERT_STREAM_to_THIS(&This->sInfo.dwSuggestedBufferSize); + hr = IAVIStream_QueryInterface(&pstream->IAVIStream_iface, riid, ppv); + if (FAILED(hr)) + HeapFree(GetProcessHeap(), 0, pstream); - return AVIERR_OK; + return hr; }