/*
- * Copyright 2002 Michael Günnewig
+ * Copyright 2002 Michael Günnewig
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
-#define COM_NO_WINDOWS_H
#include <assert.h>
+#include <stdarg.h>
+#include "windef.h"
#include "winbase.h"
+#include "wingdi.h"
#include "winuser.h"
-#include "winnls.h"
#include "winerror.h"
-#include "windowsx.h"
#include "mmsystem.h"
#include "vfw.h"
-#include "msacm.h"
#include "avifile_private.h"
/***********************************************************************/
-static HRESULT WINAPI ICMStream_fnQueryInterface(IAVIStream*iface,REFIID refiid,LPVOID *obj);
-static ULONG WINAPI ICMStream_fnAddRef(IAVIStream*iface);
-static ULONG WINAPI ICMStream_fnRelease(IAVIStream* iface);
-static HRESULT WINAPI ICMStream_fnCreate(IAVIStream*iface,LPARAM lParam1,LPARAM lParam2);
-static HRESULT WINAPI ICMStream_fnInfo(IAVIStream*iface,AVISTREAMINFOW *psi,LONG size);
-static LONG WINAPI ICMStream_fnFindSample(IAVIStream*iface,LONG pos,LONG flags);
-static HRESULT WINAPI ICMStream_fnReadFormat(IAVIStream*iface,LONG pos,LPVOID format,LONG *formatsize);
-static HRESULT WINAPI ICMStream_fnSetFormat(IAVIStream*iface,LONG pos,LPVOID format,LONG formatsize);
-static HRESULT WINAPI ICMStream_fnRead(IAVIStream*iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,LONG *bytesread,LONG *samplesread);
-static HRESULT WINAPI ICMStream_fnWrite(IAVIStream*iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,DWORD flags,LONG *sampwritten,LONG *byteswritten);
-static HRESULT WINAPI ICMStream_fnDelete(IAVIStream*iface,LONG start,LONG samples);
-static HRESULT WINAPI ICMStream_fnReadData(IAVIStream*iface,DWORD fcc,LPVOID lp,LONG *lpread);
-static HRESULT WINAPI ICMStream_fnWriteData(IAVIStream*iface,DWORD fcc,LPVOID lp,LONG size);
-static HRESULT WINAPI ICMStream_fnSetInfo(IAVIStream*iface,AVISTREAMINFOW*info,LONG infolen);
-
-struct ICOM_VTABLE(IAVIStream) iicmst = {
- ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
- ICMStream_fnQueryInterface,
- ICMStream_fnAddRef,
- ICMStream_fnRelease,
- ICMStream_fnCreate,
- ICMStream_fnInfo,
- ICMStream_fnFindSample,
- ICMStream_fnReadFormat,
- ICMStream_fnSetFormat,
- ICMStream_fnRead,
- ICMStream_fnWrite,
- ICMStream_fnDelete,
- ICMStream_fnReadData,
- ICMStream_fnWriteData,
- ICMStream_fnSetInfo
-};
-
typedef struct _IAVIStreamImpl {
/* IUnknown stuff */
- ICOM_VFIELD(IAVIStream);
- DWORD ref;
+ IAVIStream IAVIStream_iface;
+ LONG ref;
/* IAVIStream stuff */
PAVISTREAM pStream;
LPBITMAPINFOHEADER lpbi, LPVOID lpBits);
static HRESULT AVIFILE_OpenGetFrame(IAVIStreamImpl *This);
-inline void AVIFILE_Reset(IAVIStreamImpl *This)
+static inline IAVIStreamImpl *impl_from_IAVIStream(IAVIStream *iface)
+{
+ return CONTAINING_RECORD(iface, IAVIStreamImpl, IAVIStream_iface);
+}
+
+static inline void AVIFILE_Reset(IAVIStreamImpl *This)
{
This->lCurrent = -1;
This->lLastKey = 0;
This->dwUnusedBytes = 0;
}
-HRESULT AVIFILE_CreateICMStream(REFIID riid, LPVOID *ppv)
-{
- IAVIStreamImpl *pstream;
- HRESULT hr;
-
- assert(riid != NULL && ppv != NULL);
-
- *ppv = NULL;
-
- pstream = (IAVIStreamImpl*)LocalAlloc(LPTR, sizeof(IAVIStreamImpl));
- if (pstream == NULL)
- return AVIERR_MEMORY;
-
- ICOM_VTBL(pstream) = &iicmst;
- AVIFILE_Reset(pstream);
-
- hr = IUnknown_QueryInterface((IUnknown*)pstream, riid, ppv);
- if (FAILED(hr))
- LocalFree((HLOCAL)pstream);
-
- return hr;
-}
-
static HRESULT WINAPI ICMStream_fnQueryInterface(IAVIStream *iface,
REFIID refiid, LPVOID *obj)
{
- ICOM_THIS(IAVIStreamImpl,iface);
+ IAVIStreamImpl *This = impl_from_IAVIStream(iface);
TRACE("(%p,%s,%p)\n", iface, debugstr_guid(refiid), obj);
static ULONG WINAPI ICMStream_fnAddRef(IAVIStream *iface)
{
- ICOM_THIS(IAVIStreamImpl,iface);
+ IAVIStreamImpl *This = impl_from_IAVIStream(iface);
+ ULONG ref = InterlockedIncrement(&This->ref);
- TRACE("(%p) -> %ld\n", iface, This->ref + 1);
+ TRACE("(%p) -> %d\n", iface, ref);
/* also add reference to the nested stream */
if (This->pStream != NULL)
IAVIStream_AddRef(This->pStream);
- return ++(This->ref);
+ return ref;
}
static ULONG WINAPI ICMStream_fnRelease(IAVIStream* iface)
{
- ICOM_THIS(IAVIStreamImpl,iface);
+ IAVIStreamImpl *This = impl_from_IAVIStream(iface);
+ ULONG ref = InterlockedDecrement(&This->ref);
- TRACE("(%p) -> %ld\n", iface, This->ref - 1);
+ TRACE("(%p) -> %d\n", iface, ref);
- if (This->ref == 0) {
+ if (ref == 0) {
/* destruct */
if (This->pg != NULL) {
AVIStreamGetFrameClose(This->pg);
if (This->hic != NULL) {
if (This->lpbiPrev != NULL) {
ICDecompressEnd(This->hic);
- GlobalFreePtr(This->lpbiPrev);
+ HeapFree(GetProcessHeap(), 0, This->lpbiPrev);
This->lpbiPrev = NULL;
This->lpPrev = NULL;
}
This->hic = NULL;
}
if (This->lpbiCur != NULL) {
- GlobalFreePtr(This->lpbiCur);
+ HeapFree(GetProcessHeap(), 0, This->lpbiCur);
This->lpbiCur = NULL;
This->lpCur = NULL;
}
if (This->lpbiOutput != NULL) {
- GlobalFreePtr(This->lpbiOutput);
+ HeapFree(GetProcessHeap(), 0, This->lpbiOutput);
This->lpbiOutput = NULL;
This->cbOutput = 0;
}
if (This->lpbiInput != NULL) {
- GlobalFreePtr(This->lpbiInput);
+ HeapFree(GetProcessHeap(), 0, This->lpbiInput);
This->lpbiInput = NULL;
This->cbInput = 0;
}
- LocalFree((HLOCAL)This);
+ HeapFree(GetProcessHeap(), 0, This);
return 0;
}
if (This->pStream != NULL)
IAVIStream_Release(This->pStream);
- return --This->ref;
+ return ref;
}
/* lParam1: PAVISTREAM
static HRESULT WINAPI ICMStream_fnCreate(IAVIStream *iface, LPARAM lParam1,
LPARAM lParam2)
{
- ICOM_THIS(IAVIStreamImpl,iface);
+ IAVIStreamImpl *This = impl_from_IAVIStream(iface);
ICINFO icinfo;
ICCOMPRESSFRAMES icFrames;
static HRESULT WINAPI ICMStream_fnInfo(IAVIStream *iface,LPAVISTREAMINFOW psi,
LONG size)
{
- ICOM_THIS(IAVIStreamImpl,iface);
+ IAVIStreamImpl *This = impl_from_IAVIStream(iface);
- TRACE("(%p,%p,%ld)\n", iface, psi, size);
+ TRACE("(%p,%p,%d)\n", iface, psi, size);
if (psi == NULL)
return AVIERR_BADPARAM;
if (size < 0)
return AVIERR_BADSIZE;
- memcpy(psi, &This->sInfo, min(size, sizeof(This->sInfo)));
+ memcpy(psi, &This->sInfo, min((DWORD)size, sizeof(This->sInfo)));
- if (size < sizeof(This->sInfo))
+ if ((DWORD)size < sizeof(This->sInfo))
return AVIERR_BUFFERTOOSMALL;
return AVIERR_OK;
}
static LONG WINAPI ICMStream_fnFindSample(IAVIStream *iface, LONG pos,
LONG flags)
{
- ICOM_THIS(IAVIStreamImpl,iface);
+ IAVIStreamImpl *This = impl_from_IAVIStream(iface);
- TRACE("(%p,%ld,0x%08lX)\n",iface,pos,flags);
+ TRACE("(%p,%d,0x%08X)\n",iface,pos,flags);
if (flags & FIND_FROM_START) {
pos = This->sInfo.dwStart;
static HRESULT WINAPI ICMStream_fnReadFormat(IAVIStream *iface, LONG pos,
LPVOID format, LONG *formatsize)
{
- ICOM_THIS(IAVIStreamImpl,iface);
+ IAVIStreamImpl *This = impl_from_IAVIStream(iface);
LPBITMAPINFOHEADER lpbi;
HRESULT hr;
- TRACE("(%p,%ld,%p,%p)\n", iface, pos, format, formatsize);
+ TRACE("(%p,%d,%p,%p)\n", iface, pos, format, formatsize);
if (formatsize == NULL)
return AVIERR_BADPARAM;
return hr;
}
- lpbi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(This->pg, pos);
+ lpbi = AVIStreamGetFrame(This->pg, pos);
if (lpbi == NULL)
return AVIERR_MEMORY;
static HRESULT WINAPI ICMStream_fnSetFormat(IAVIStream *iface, LONG pos,
LPVOID format, LONG formatsize)
{
- ICOM_THIS(IAVIStreamImpl,iface);
+ IAVIStreamImpl *This = impl_from_IAVIStream(iface);
- TRACE("(%p,%ld,%p,%ld)\n", iface, pos, format, formatsize);
+ TRACE("(%p,%d,%p,%d)\n", iface, pos, format, formatsize);
/* check parameters */
if (format == NULL || formatsize <= 0)
/* initial format setting? */
if (This->lpbiInput == NULL) {
- LONG size;
+ ULONG size;
assert(This->hic != NULL);
/* get memory for input format */
- This->lpbiInput = (LPBITMAPINFOHEADER)GlobalAllocPtr(GHND, formatsize);
+ This->lpbiInput = HeapAlloc(GetProcessHeap(), 0, formatsize);
if (This->lpbiInput == NULL)
return AVIERR_MEMORY;
This->cbInput = formatsize;
size = ICCompressGetFormatSize(This->hic, This->lpbiInput);
if (size < sizeof(BITMAPINFOHEADER))
return AVIERR_COMPRESSOR;
- This->lpbiOutput = (LPBITMAPINFOHEADER)GlobalAllocPtr(GHND, size);
+ This->lpbiOutput = HeapAlloc(GetProcessHeap(), 0, size);
if (This->lpbiOutput == NULL)
return AVIERR_MEMORY;
This->cbOutput = size;
/* allocate memory for compressed frame */
size = ICCompressGetSize(This->hic, This->lpbiInput, This->lpbiOutput);
- This->lpbiCur =
- (LPBITMAPINFOHEADER)GlobalAllocPtr(GMEM_MOVEABLE, This->cbOutput + size);
+ This->lpbiCur = HeapAlloc(GetProcessHeap(), 0, This->cbOutput + size);
if (This->lpbiCur == NULL)
return AVIERR_MEMORY;
memcpy(This->lpbiCur, This->lpbiOutput, This->cbOutput);
if (This->lKeyFrameEvery != 1 &&
(This->dwICMFlags & VIDCF_FASTTEMPORALC) == 0) {
size = ICDecompressGetFormatSize(This->hic, This->lpbiOutput);
- This->lpbiPrev = (LPBITMAPINFOHEADER)GlobalAllocPtr(GHND, size);
+ This->lpbiPrev = HeapAlloc(GetProcessHeap(), 0, size);
if (This->lpbiPrev == NULL)
return AVIERR_MEMORY;
if (ICDecompressGetFormat(This->hic, This->lpbiOutput, This->lpbiPrev) < S_OK)
/* get memory for format and picture */
size += This->lpbiPrev->biSizeImage;
- This->lpbiPrev =
- (LPBITMAPINFOHEADER)GlobalReAllocPtr(This->lpbiPrev,size,GMEM_MOVEABLE);
+ This->lpbiPrev = HeapReAlloc(GetProcessHeap(), 0, This->lpbiPrev, size);
if (This->lpbiPrev == NULL)
return AVIERR_MEMORY;
This->lpPrev = DIBPTR(This->lpbiPrev);
}
} else {
/* format change -- check that's only the palette */
- LPBITMAPINFOHEADER lpbi = (LPBITMAPINFOHEADER)format;
+ LPBITMAPINFOHEADER lpbi = format;
if (lpbi->biSize != This->lpbiInput->biSize ||
lpbi->biWidth != This->lpbiInput->biWidth ||
if (ICCompressBegin(This->hic, lpbi, This->lpbiOutput) != S_OK)
return AVIERR_COMPRESSOR;
- /* check if we need to restart decompresion also */
+ /* check if we need to restart decompression also */
if (This->lKeyFrameEvery != 1 &&
(This->dwICMFlags & VIDCF_FASTTEMPORALC) == 0) {
ICDecompressEnd(This->hic);
LONG buffersize, LPLONG bytesread,
LPLONG samplesread)
{
- ICOM_THIS(IAVIStreamImpl,iface);
+ IAVIStreamImpl *This = impl_from_IAVIStream(iface);
LPBITMAPINFOHEADER lpbi;
- TRACE("(%p,%ld,%ld,%p,%ld,%p,%p)\n", iface, start, samples, buffer,
+ TRACE("(%p,%d,%d,%p,%d,%p,%p)\n", iface, start, samples, buffer,
buffersize, bytesread, samplesread);
/* clear return parameters if given */
/* compress or decompress? */
if (This->hic == NULL) {
/* decompress */
- lpbi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(This->pg, start);
+ lpbi = AVIStreamGetFrame(This->pg, start);
if (lpbi == NULL)
return AVIERR_MEMORY;
while (start > This->lCurrent) {
HRESULT hr;
- lpbi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(This->pg, ++This->lCurrent);
+ lpbi = AVIStreamGetFrame(This->pg, ++This->lCurrent);
if (lpbi == NULL) {
AVIFILE_Reset(This);
return AVIERR_MEMORY;
LPLONG sampwritten,
LPLONG byteswritten)
{
- ICOM_THIS(IAVIStreamImpl,iface);
+ IAVIStreamImpl *This = impl_from_IAVIStream(iface);
HRESULT hr;
- TRACE("(%p,%ld,%ld,%p,%ld,0x%08lX,%p,%p)\n", iface, start, samples,
+ TRACE("(%p,%d,%d,%p,%d,0x%08X,%p,%p)\n", iface, start, samples,
buffer, buffersize, flags, sampwritten, byteswritten);
/* clear return parameters if given */
static HRESULT WINAPI ICMStream_fnDelete(IAVIStream *iface, LONG start,
LONG samples)
{
- ICOM_THIS(IAVIStreamImpl,iface);
+ IAVIStreamImpl *This = impl_from_IAVIStream(iface);
- TRACE("(%p,%ld,%ld)\n", iface, start, samples);
+ TRACE("(%p,%d,%d)\n", iface, start, samples);
return IAVIStream_Delete(This->pStream, start, samples);
}
static HRESULT WINAPI ICMStream_fnReadData(IAVIStream *iface, DWORD fcc,
LPVOID lp, LPLONG lpread)
{
- ICOM_THIS(IAVIStreamImpl,iface);
+ IAVIStreamImpl *This = impl_from_IAVIStream(iface);
- TRACE("(%p,0x%08lX,%p,%p)\n", iface, fcc, lp, lpread);
+ TRACE("(%p,0x%08X,%p,%p)\n", iface, fcc, lp, lpread);
assert(This->pStream != NULL);
static HRESULT WINAPI ICMStream_fnWriteData(IAVIStream *iface, DWORD fcc,
LPVOID lp, LONG size)
{
- ICOM_THIS(IAVIStreamImpl,iface);
+ IAVIStreamImpl *This = impl_from_IAVIStream(iface);
- TRACE("(%p,0x%08lx,%p,%ld)\n", iface, fcc, lp, size);
+ TRACE("(%p,0x%08x,%p,%d)\n", iface, fcc, lp, size);
assert(This->pStream != NULL);
static HRESULT WINAPI ICMStream_fnSetInfo(IAVIStream *iface,
LPAVISTREAMINFOW info, LONG infolen)
{
- FIXME("(%p,%p,%ld): stub\n", iface, info, infolen);
+ FIXME("(%p,%p,%d): stub\n", iface, info, infolen);
return E_FAIL;
}
+static const struct IAVIStreamVtbl iicmst = {
+ ICMStream_fnQueryInterface,
+ ICMStream_fnAddRef,
+ ICMStream_fnRelease,
+ ICMStream_fnCreate,
+ ICMStream_fnInfo,
+ ICMStream_fnFindSample,
+ ICMStream_fnReadFormat,
+ ICMStream_fnSetFormat,
+ ICMStream_fnRead,
+ ICMStream_fnWrite,
+ ICMStream_fnDelete,
+ ICMStream_fnReadData,
+ ICMStream_fnWriteData,
+ ICMStream_fnSetInfo
+};
+
+HRESULT AVIFILE_CreateICMStream(REFIID riid, LPVOID *ppv)
+{
+ IAVIStreamImpl *pstream;
+ HRESULT hr;
+
+ assert(riid != NULL && ppv != NULL);
+
+ *ppv = NULL;
+
+ pstream = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IAVIStreamImpl));
+ if (pstream == NULL)
+ return AVIERR_MEMORY;
+
+ pstream->IAVIStream_iface.lpVtbl = &iicmst;
+ AVIFILE_Reset(pstream);
+
+ hr = IAVIStream_QueryInterface(&pstream->IAVIStream_iface, riid, ppv);
+ if (FAILED(hr))
+ HeapFree(GetProcessHeap(), 0, pstream);
+
+ return hr;
+}
+
/***********************************************************************/
static HRESULT AVIFILE_EncodeFrame(IAVIStreamImpl *This,
do {
DWORD idxCkid = 0;
- HRESULT hr;
+ DWORD res;
- hr = ICCompress(This->hic,icmFlags,This->lpbiCur,This->lpCur,lpbi,lpBits,
- &idxCkid, &idxFlags, This->lCurrent, dwRequest, dwCurQual,
- noPrev ? NULL:This->lpbiPrev, noPrev ? NULL:This->lpPrev);
- if (hr == ICERR_NEWPALETTE) {
+ res = ICCompress(This->hic,icmFlags,This->lpbiCur,This->lpCur,lpbi,lpBits,
+ &idxCkid, &idxFlags, This->lCurrent, dwRequest, dwCurQual,
+ noPrev ? NULL:This->lpbiPrev, noPrev ? NULL:This->lpPrev);
+ if (res == ICERR_NEWPALETTE) {
FIXME(": codec has changed palette -- unhandled!\n");
- } else if (hr != ICERR_OK)
+ } else if (res != ICERR_OK)
return AVIERR_COMPRESSOR;
/* need to check for framesize */
if (bDecreasedQual || dwCurQual == This->dwLastQuality)
dwCurQual = (dwMinQual + dwMaxQual) / 2;
else
- FIXME(": no new quality computed min=%lu cur=%lu max=%lu last=%lu\n",
+ FIXME(": no new quality computed min=%u cur=%u max=%u last=%u\n",
dwMinQual, dwCurQual, dwMaxQual, This->dwLastQuality);
bDecreasedQual = TRUE;
static HRESULT AVIFILE_OpenGetFrame(IAVIStreamImpl *This)
{
LPBITMAPINFOHEADER lpbi;
- LONG size;
+ DWORD size;
/* pre-conditions */
assert(This != NULL);
assert(This->lpbiOutput == NULL);
/* get input format */
- lpbi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(This->pg, This->sInfo.dwStart);
+ lpbi = AVIStreamGetFrame(This->pg, This->sInfo.dwStart);
if (lpbi == NULL)
return AVIERR_MEMORY;
/* get memory for output format */
size = ICCompressGetFormatSize(This->hic, lpbi);
- if (size < sizeof(BITMAPINFOHEADER))
+ if ((LONG)size < (LONG)sizeof(BITMAPINFOHEADER))
return AVIERR_COMPRESSOR;
- This->lpbiOutput = (LPBITMAPINFOHEADER)GlobalAllocPtr(GHND, size);
+ This->lpbiOutput = HeapAlloc(GetProcessHeap(), 0, size);
if (This->lpbiOutput == NULL)
return AVIERR_MEMORY;
This->cbOutput = size;
/* allocate memory for current frame */
size += This->sInfo.dwSuggestedBufferSize;
- This->lpbiCur = (LPBITMAPINFOHEADER)GlobalAllocPtr(GMEM_MOVEABLE, size);
+ This->lpbiCur = HeapAlloc(GetProcessHeap(), 0, size);
if (This->lpbiCur == NULL)
return AVIERR_MEMORY;
memcpy(This->lpbiCur, This->lpbiOutput, This->cbOutput);
if (This->lKeyFrameEvery != 1 &&
(This->dwICMFlags & VIDCF_FASTTEMPORALC) == 0) {
size = ICDecompressGetFormatSize(This->hic, This->lpbiOutput);
- This->lpbiPrev = (LPBITMAPINFOHEADER)GlobalAllocPtr(GHND, size);
+ This->lpbiPrev = HeapAlloc(GetProcessHeap(), 0, size);
if (This->lpbiPrev == NULL)
return AVIERR_MEMORY;
if (ICDecompressGetFormat(This->hic, This->lpbiOutput, This->lpbiPrev) < S_OK)
/* get memory for format and picture */
size += This->lpbiPrev->biSizeImage;
- This->lpbiPrev =
- (LPBITMAPINFOHEADER)GlobalReAllocPtr(This->lpbiPrev,size,GMEM_MOVEABLE);
+ This->lpbiPrev = HeapReAlloc(GetProcessHeap(), 0, This->lpbiPrev, size );
if (This->lpbiPrev == NULL)
return AVIERR_MEMORY;
This->lpPrev = DIBPTR(This->lpbiPrev);