wine/dlls/avifil32: new functions, stubs, ...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi.

I have prepared the current avifil32 implementation to use the COM
interface as needed.

- Move the API into a new api.c file.
- Added IClassFactory implementation (in factory.c)
- Added IPersistFile implementation to the AVI-file handler.


Index: dlls/Makefile.in
===================================================================
RCS file: /home/wine/wine/dlls/Makefile.in,v
retrieving revision 1.154
diff -u -r1.154 Makefile.in
--- dlls/Makefile.in	8 Oct 2002 00:40:06 -0000	1.154
+++ dlls/Makefile.in	10 Oct 2002 18:05:54 -0000
@@ -763,7 +763,7 @@
 
 advapi32: kernel32.dll$(DLLEXT) ntdll.dll$(DLLEXT)
 avicap32: ntdll.dll$(DLLEXT)
-avifil32: msvfw32.dll$(DLLEXT) kernel32.dll$(DLLEXT)
+avifil32: msvfw32.dll$(DLLEXT) advapi32.dll$(DLLEXT) shell32.dll$(DLLEXT) user32.dll$(DLLEXT) kernel32.dll$(DLLEXT)
 comcat:   ole32.dll$(DLLEXT) user32.dll$(DLLEXT) advapi32.dll$(DLLEXT) kernel32.dll$(DLLEXT)
 comctl32: user32.dll$(DLLEXT) gdi32.dll$(DLLEXT) advapi32.dll$(DLLEXT) kernel32.dll$(DLLEXT) \
           winmm.dll$(DLLEXT)
Index: dlls/avifil32/Makefile.in
===================================================================
RCS file: /home/wine/wine/dlls/avifil32/Makefile.in,v
retrieving revision 1.20
diff -u -r1.20 Makefile.in
--- dlls/avifil32/Makefile.in	17 May 2002 03:37:12 -0000	1.20
+++ dlls/avifil32/Makefile.in	10 Oct 2002 18:05:54 -0000
@@ -3,7 +3,7 @@
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = avifil32.dll
-IMPORTS   = msvfw32 kernel32
+IMPORTS   = msvfw32 advapi32 shell32 user32 kernel32
 ALTNAMES  = avifile.dll
 EXTRALIBS = $(LIBUUID)
 
@@ -11,7 +11,9 @@
 SYMBOLFILE = $(MODULE).tmp.o
 
 C_SRCS = \
-	avifile.c
+	api.c \
+	avifile.c \
+	factory.c
 
 @MAKE_DLL_RULES@
 
Index: dlls/avifil32/avifil32.spec
===================================================================
RCS file: /home/wine/wine/dlls/avifil32/avifil32.spec,v
retrieving revision 1.12
diff -u -r1.12 avifil32.spec
--- dlls/avifil32/avifil32.spec	21 Jun 2002 19:15:46 -0000	1.12
+++ dlls/avifil32/avifil32.spec	10 Oct 2002 18:05:54 -0000
@@ -2,11 +2,11 @@
 @ stub    AVIBuildFilterA
 @ stub    AVIBuildFilterW
 @ stub    AVIClearClipboard
-@ stub    AVIFileAddRef
+@ stdcall AVIFileAddRef(ptr) AVIFileAddRef
 @ stub    AVIFileCreateStream
 @ stdcall AVIFileCreateStreamA(ptr ptr ptr) AVIFileCreateStreamA
 @ stdcall AVIFileCreateStreamW(ptr ptr ptr) AVIFileCreateStreamW
-@ stub    AVIFileEndRecord
+@ stdcall AVIFileEndRecord(ptr) AVIFileEndRecord
 @ stdcall AVIFileExit() AVIFileExit
 @ stdcall AVIFileGetStream(ptr ptr long long) AVIFileGetStream
 @ stdcall AVIFileInfo (ptr ptr long) AVIFileInfoA # A in both Win95 and NT
@@ -15,10 +15,10 @@
 @ stdcall AVIFileInit() AVIFileInit
 @ stub    AVIFileOpen
 @ stdcall AVIFileOpenA(ptr str long ptr) AVIFileOpenA
-@ stub    AVIFileOpenW
-@ stub    AVIFileReadData
+@ stdcall AVIFileOpenW(ptr str long ptr) AVIFileOpenW
+@ stdcall AVIFileReadData(ptr long ptr ptr) AVIFileReadData
 @ stdcall AVIFileRelease(ptr) AVIFileRelease
-@ stub    AVIFileWriteData
+@ stdcall AVIFileWriteData(ptr long ptr long) AVIFileWriteData
 @ stub    AVIGetFromClipboard
 @ stdcall AVIMakeCompressedStream(ptr ptr ptr ptr) AVIMakeCompressedStream
 @ stub    AVIMakeFileFromStreams
@@ -32,11 +32,11 @@
 @ stub    AVISaveVA
 @ stub    AVISaveVW
 @ stub    AVISaveW
-@ stub    AVIStreamAddRef
+@ stdcall AVIStreamAddRef(ptr) AVIStreamAddRef
 @ stub    AVIStreamBeginStreaming
-@ stub    AVIStreamCreate
+@ stdcall AVIStreamCreate(ptr long long ptr) AVIStreamCreate
 @ stub    AVIStreamEndStreaming
-@ stub    AVIStreamFindSample
+@ stdcall AVIStreamFindSample(ptr long long) AVIStreamFindSample
 @ stdcall AVIStreamGetFrame(ptr long) AVIStreamGetFrame
 @ stdcall AVIStreamGetFrameClose(ptr) AVIStreamGetFrameClose
 @ stdcall AVIStreamGetFrameOpen(ptr ptr) AVIStreamGetFrameOpen
@@ -45,16 +45,16 @@
 @ stdcall AVIStreamInfoW(ptr ptr long) AVIStreamInfoW
 @ stdcall AVIStreamLength(ptr) AVIStreamLength
 @ stub    AVIStreamOpenFromFile
-@ stub    AVIStreamOpenFromFileA
-@ stub    AVIStreamOpenFromFileW
+@ stdcall AVIStreamOpenFromFileA(ptr str long long long ptr) AVIStreamOpenFromFileA
+@ stdcall AVIStreamOpenFromFileW(ptr wstr long long long ptr) AVIStreamOpenFromFileW
 @ stdcall AVIStreamRead(ptr long long ptr long ptr ptr) AVIStreamRead
 @ stdcall AVIStreamReadData(ptr long ptr ptr) AVIStreamReadData
 @ stdcall AVIStreamReadFormat(ptr long ptr long) AVIStreamReadFormat
 @ stdcall AVIStreamRelease(ptr) AVIStreamRelease
-@ stub    AVIStreamSampleToTime
+@ stdcall AVIStreamSampleToTime(ptr long) AVIStreamSampleToTime
 @ stdcall AVIStreamSetFormat(ptr long ptr long) AVIStreamSetFormat
 @ stdcall AVIStreamStart(ptr) AVIStreamStart
-@ stub    AVIStreamTimeToSample
+@ stdcall AVIStreamTimeToSample(ptr long) AVIStreamTimeToSample
 @ stdcall AVIStreamWrite(ptr long long ptr long long ptr ptr) AVIStreamWrite
 @ stdcall AVIStreamWriteData(ptr long ptr long) AVIStreamWriteData
 @ stub    CLSID_AVISimpleUnMarshal
Index: dlls/avifil32/avifile.c
===================================================================
RCS file: /home/wine/wine/dlls/avifil32/avifile.c,v
retrieving revision 1.25
diff -u -r1.25 avifile.c
--- dlls/avifil32/avifile.c	31 May 2002 23:25:43 -0000	1.25
+++ dlls/avifil32/avifile.c	10 Oct 2002 18:05:55 -0000
@@ -1,5 +1,6 @@
 /*
  * Copyright 1999 Marcus Meissner
+ * 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
@@ -16,22 +17,26 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include <string.h>
-#include <stdio.h>
 #include <assert.h>
 
 #include "winbase.h"
 #include "winnls.h"
-#include "mmsystem.h"
 #include "winerror.h"
+#include "windowsx.h"
+#include "mmsystem.h"
 #include "vfw.h"
+
+#include "avifile_private.h"
+
 #include "wine/debug.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(avifile);
 
+/***********************************************************************/
+
 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 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);
@@ -41,25 +46,48 @@
 static HRESULT WINAPI IAVIFile_fnDeleteStream(IAVIFile*iface,DWORD fccType,LONG lParam);
 
 struct ICOM_VTABLE(IAVIFile) iavift = {
-    ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
-    IAVIFile_fnQueryInterface,
-    IAVIFile_fnAddRef,
-    IAVIFile_fnRelease,
-    IAVIFile_fnInfo,
-    IAVIFile_fnGetStream,
-    IAVIFile_fnCreateStream,
-    IAVIFile_fnWriteData,
-    IAVIFile_fnReadData,
-    IAVIFile_fnEndRecord,
-    IAVIFile_fnDeleteStream
+  ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
+  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);
+
+struct ICOM_VTABLE(IPersistFile) ipersistft = {
+  ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
+  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 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 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);
@@ -70,547 +98,476 @@
 static HRESULT WINAPI IAVIStream_fnSetInfo(IAVIStream*iface,AVISTREAMINFOW*info,LONG infolen);
 
 struct ICOM_VTABLE(IAVIStream) iavist = {
-    ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
-    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
+  ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
+  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 IAVIStreamImpl {
-	/* IUnknown stuff */
-	ICOM_VFIELD(IAVIStream);
-	DWORD		ref;
-	/* IAVIStream stuff */
-	LPVOID		lpInputFormat;
-	DWORD		inputformatsize;
-	BOOL		iscompressing;
-	DWORD		curframe;
-
-	    /* Compressor stuff */
-	    HIC	hic;
-	    LPVOID	lpCompressFormat;
-	    ICINFO	icinfo;
-	    DWORD	compbufsize;
-	    LPVOID	compbuffer;
-
-	    DWORD	decompbufsize;
-	    LPVOID	decompbuffer;
-	    LPVOID	decompformat;
-	    AVICOMPRESSOPTIONS	aco;
+typedef struct _IAVIFileImpl IAVIFileImpl;
 
-	    LPVOID	lpPrev;	/* pointer to decompressed frame later */
-	    LPVOID	lpPrevFormat; /* pointer to decompressed info later */
+typedef struct _IPersistFileImpl {
+  /* IUnknown stuff */
+  ICOM_VFIELD(IPersistFile);
+
+  /* IPersistFile stuff */
+  IAVIFileImpl     *paf;
+} IPersistFileImpl;
+
+typedef struct _IAVIStreamImpl {
+  /* IUnknown stuff */
+  ICOM_VFIELD(IAVIStream);
+  DWORD		    ref;
+
+  /* IAVIStream stuff */
+  IAVIFileImpl     *paf;
+  AVISTREAMINFOW    sInfo;
 } IAVIStreamImpl;
 
-/***********************************************************************
- *		AVIFileInit (AVIFIL32.@)
- *		AVIFileInit (AVIFILE.100)
- */
-void WINAPI
-AVIFileInit(void) {
-	FIXME("(),stub!\n");
+struct _IAVIFileImpl {
+  /* IUnknown stuff */
+  ICOM_VFIELD(IAVIFile);
+  DWORD		    ref;
+
+  /* IAVIFile stuff... */
+  IPersistFileImpl  iPersistFile;
+
+  AVIFILEINFOW      fInfo;
+  IAVIStreamImpl   *ppStreams[MAX_AVISTREAMS];
+
+  /* IPersistFile stuff ... */
+  HMMIO             hmmio;
+  LPWSTR            szFileName;
+  UINT              uMode;
+  BOOL              fDirty;
+};
+
+/***********************************************************************/
+
+HRESULT AVIFILE_CreateAVIFile(REFIID riid, LPVOID *ppv)
+{
+  IAVIFileImpl *pfile;
+  HRESULT       hr;
+
+  assert(riid != NULL && ppv != NULL);
+
+  *ppv = NULL;
+
+  pfile = (IAVIFileImpl*)LocalAlloc(LPTR, sizeof(IAVIFileImpl));
+  if (pfile == NULL)
+    return AVIERR_MEMORY;
+
+  ICOM_VTBL(pfile)               = &iavift;
+  ICOM_VTBL(&pfile->iPersistFile) = &ipersistft;
+  pfile->ref = 0;
+  pfile->iPersistFile.paf = pfile;
+
+  hr = IUnknown_QueryInterface((IUnknown*)pfile, riid, ppv);
+  if (FAILED(hr))
+    LocalFree((HLOCAL)pfile);
+
+  return hr;
 }
 
-typedef struct IAVIFileImpl {
-	/* IUnknown stuff */
-	ICOM_VFIELD(IAVIFile);
-	DWORD				ref;
-	/* IAVIFile stuff... */
-} IAVIFileImpl;
+static HRESULT WINAPI IAVIFile_fnQueryInterface(IAVIFile *iface, REFIID refiid,
+						LPVOID *obj)
+{
+  ICOM_THIS(IAVIFileImpl,iface);
+
+  TRACE("(%p,%s,%p)\n", This, debugstr_guid(refiid), obj);
 
-static HRESULT WINAPI IAVIFile_fnQueryInterface(IAVIFile* iface,REFIID refiid,LPVOID *obj) {
-	ICOM_THIS(IAVIFileImpl,iface);
+  if (IsEqualGUID(&IID_IUnknown, refiid) ||
+      IsEqualGUID(&IID_IAVIFile, refiid)) {
+    *obj = iface;
+    return S_OK;
+  } else if (IsEqualGUID(&IID_IPersistFile, refiid)) {
+    *obj = &This->iPersistFile;
+    return S_OK;
+  }
 
-	TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(refiid),obj);
-	if (	!memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
-		!memcmp(&IID_IAVIFile,refiid,sizeof(IID_IAVIFile))
-	) {
-		*obj = iface;
-		return S_OK;
-	}
-	return OLE_E_ENUM_NOMORE;
+  return OLE_E_ENUM_NOMORE;
 }
 
-static ULONG WINAPI IAVIFile_fnAddRef(IAVIFile* iface) {
-	ICOM_THIS(IAVIFileImpl,iface);
+static ULONG WINAPI IAVIFile_fnAddRef(IAVIFile *iface)
+{
+  ICOM_THIS(IAVIFileImpl,iface);
 
-	FIXME("(%p)->AddRef()\n",iface);
-	return ++(This->ref);
+  TRACE("(%p)\n",iface);
+  return ++(This->ref);
 }
 
-static ULONG WINAPI IAVIFile_fnRelease(IAVIFile* iface) {
-	ICOM_THIS(IAVIFileImpl,iface);
+static ULONG WINAPI IAVIFile_fnRelease(IAVIFile *iface)
+{
+  ICOM_THIS(IAVIFileImpl,iface);
 
-	FIXME("(%p)->Release()\n",iface);
-	if (!--(This->ref)) {
-		HeapFree(GetProcessHeap(),0,iface);
-		return 0;
-	}
-	return This->ref;
+  FIXME("(%p): partial stub!\n",iface);
+  if (!--(This->ref)) {
+    if (This->fDirty) {
+      /* FIXME: write headers to disk */
+    }
+
+    HeapFree(GetProcessHeap(),0,iface);
+    return 0;
+  }
+  return This->ref;
 }
 
-static HRESULT WINAPI IAVIFile_fnInfo(IAVIFile*iface,AVIFILEINFOW*afi,LONG size) {
-	FIXME("(%p)->Info(%p,%ld)\n",iface,afi,size);
+static HRESULT WINAPI IAVIFile_fnInfo(IAVIFile *iface, LPAVIFILEINFOW afi,
+				      LONG size)
+{
+  ICOM_THIS(IAVIFileImpl,iface);
+
+  TRACE("(%p,%p,%ld)\n",iface,afi,size);
+
+  if (afi == NULL)
+    return AVIERR_BADPARAM;
+  if (size < 0)
+    return AVIERR_BADSIZE;
 
-	/* FIXME: fill out struct? */
-	return E_FAIL;
+  memcpy(afi, &This->fInfo, min(size, sizeof(This->fInfo)));
+
+  if (size < sizeof(This->fInfo))
+    return AVIERR_BUFFERTOOSMALL;
+  return AVIERR_OK;
 }
 
-static HRESULT WINAPI IAVIFile_fnGetStream(IAVIFile*iface,PAVISTREAM*avis,DWORD fccType,LONG lParam) {
-	FIXME("(%p)->GetStream(%p,0x%08lx,%ld)\n",iface,avis,fccType,lParam);
-	/* FIXME: create interface etc. */
-	return E_FAIL;
+static HRESULT WINAPI IAVIFile_fnGetStream(IAVIFile *iface, PAVISTREAM *avis,
+					   DWORD fccType, LONG lParam)
+{
+  FIXME("(%p,%p,0x%08lX,%ld): stub\n", iface, avis, fccType, lParam);
+  /* FIXME: create interface etc. */
+  return E_FAIL;
 }
 
-static HRESULT WINAPI IAVIFile_fnCreateStream(IAVIFile*iface,PAVISTREAM*avis,AVISTREAMINFOW*asi) {
-	ICOM_THIS(IAVIStreamImpl,iface);
-	char		fcc[5];
-	IAVIStreamImpl	*istream;
+static HRESULT WINAPI IAVIFile_fnCreateStream(IAVIFile *iface,PAVISTREAM *avis,
+					      LPAVISTREAMINFOW asi)
+{
+  ICOM_THIS(IAVIStreamImpl,iface);
 
-	FIXME("(%p,%p,%p)\n",This,avis,asi);
-	istream = (IAVIStreamImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IAVIStreamImpl));
-	istream->ref = 1;
-	ICOM_VTBL(istream) = &iavist;
-	fcc[4]='\0';
-	memcpy(fcc,(char*)&(asi->fccType),4);
-	FIXME("\tfccType '%s'\n",fcc);
-	memcpy(fcc,(char*)&(asi->fccHandler),4);
-	FIXME("\tfccHandler '%s'\n",fcc);
-	FIXME("\tdwFlags 0x%08lx\n",asi->dwFlags);
-	FIXME("\tdwCaps 0x%08lx\n",asi->dwCaps);
-	FIXME("\tname %s\n",debugstr_w(asi->szName));
+  FIXME("(%p,%p,%p): stub\n", iface, avis, asi);
 
-	istream->curframe = 0;
-	*avis = (PAVISTREAM)istream;
-	return S_OK;
+  return AVIERR_UNSUPPORTED;
 }
 
-static HRESULT WINAPI IAVIFile_fnWriteData(IAVIFile*iface,DWORD ckid,LPVOID lpData,LONG size) {
-	FIXME("(%p)->WriteData(0x%08lx,%p,%ld)\n",iface,ckid,lpData,size);
-	/* FIXME: write data to file */
-	return E_FAIL;
+static HRESULT WINAPI IAVIFile_fnWriteData(IAVIFile *iface, DWORD ckid,
+					   LPVOID lpData, LONG size)
+{
+  FIXME("(%p,0x%08lX,%p,%ld): stub\n", iface, ckid, lpData, size);
+  /* FIXME: write data to file */
+  return E_FAIL;
 }
 
-static HRESULT WINAPI IAVIFile_fnReadData(IAVIFile*iface,DWORD ckid,LPVOID lpData,LONG *size) {
-	FIXME("(%p)->ReadData(0x%08lx,%p,%p)\n",iface,ckid,lpData,size);
-	/* FIXME: read at most size bytes from file */
-	return E_FAIL;
+static HRESULT WINAPI IAVIFile_fnReadData(IAVIFile *iface, DWORD ckid,
+					  LPVOID lpData, LONG *size)
+{
+  FIXME("(%p,0x%08lX,%p,%p): stub\n", iface, ckid, lpData, size);
+  /* FIXME: read at most size bytes from file */
+  return E_FAIL;
 }
 
-static HRESULT WINAPI IAVIFile_fnEndRecord(IAVIFile*iface) {
-	FIXME("(%p)->EndRecord()\n",iface);
-	/* FIXME: end record? */
-	return E_FAIL;
+static HRESULT WINAPI IAVIFile_fnEndRecord(IAVIFile *iface)
+{
+  FIXME("(%p): stub\n",iface);
+  /* FIXME: end record -- for interleaved files */
+  return E_FAIL;
 }
 
-static HRESULT WINAPI IAVIFile_fnDeleteStream(IAVIFile*iface,DWORD fccType,LONG lParam) {
-	FIXME("(%p)->DeleteStream(0x%08lx,%ld)\n",iface,fccType,lParam);
-	/* FIXME: delete stream? */
-	return E_FAIL;
+static HRESULT WINAPI IAVIFile_fnDeleteStream(IAVIFile *iface, DWORD fccType,
+					      LONG lParam)
+{
+  FIXME("(%p,0x%08lX,%ld): stub\n", iface, fccType, lParam);
+  /* FIXME: delete stream */
+  return E_FAIL;
 }
 
-/***********************************************************************
- *		AVIFileOpenA (AVIFIL32.@)
- *		AVIFileOpen  (AVIFILE.102)
- */
-HRESULT WINAPI AVIFileOpenA(
-	PAVIFILE * ppfile,LPCSTR szFile,UINT uMode,LPCLSID lpHandler
-) {
-	IAVIFileImpl	*iavi;
+/***********************************************************************/
 
-	FIXME("(%p,%s,0x%08lx,%s),stub!\n",ppfile,szFile,(DWORD)uMode,debugstr_guid(lpHandler));
-	iavi = (IAVIFileImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IAVIFileImpl));
-	iavi->ref = 1;
-	ICOM_VTBL(iavi) = &iavift;
-	*ppfile = (LPVOID)iavi;
-	return S_OK;
-}
+static HRESULT WINAPI IPersistFile_fnQueryInterface(IPersistFile *iface,
+						    REFIID refiid, LPVOID *obj)
+{
+  ICOM_THIS(IPersistFileImpl,iface);
 
-static HRESULT WINAPI IAVIStream_fnQueryInterface(IAVIStream*iface,REFIID refiid,LPVOID *obj) {
-	ICOM_THIS(IAVIStreamImpl,iface);
+  assert(This->paf != NULL);
 
-	TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(refiid),obj);
-	if (	!memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
-		!memcmp(&IID_IAVIStream,refiid,sizeof(IID_IAVIStream))
-	) {
-		*obj = This;
-		return S_OK;
-	}
-	/* can return IGetFrame interface too */
-	return OLE_E_ENUM_NOMORE;
+  return IAVIFile_QueryInterface((PAVIFILE)This->paf, refiid, obj);
 }
 
-static ULONG WINAPI IAVIStream_fnAddRef(IAVIStream*iface) {
-	ICOM_THIS(IAVIStreamImpl,iface);
+static ULONG   WINAPI IPersistFile_fnAddRef(IPersistFile *iface)
+{
+  ICOM_THIS(IPersistFileImpl,iface);
 
-	FIXME("(%p)->AddRef()\n",iface);
-	return ++(This->ref);
+  assert(This->paf != NULL);
+
+  return IAVIFile_AddRef((PAVIFILE)This->paf);
 }
 
-static ULONG WINAPI IAVIStream_fnRelease(IAVIStream* iface) {
-	ICOM_THIS(IAVIStreamImpl,iface);
+static ULONG   WINAPI IPersistFile_fnRelease(IPersistFile *iface)
+{
+  ICOM_THIS(IPersistFileImpl,iface);
 
-	FIXME("(%p)->Release()\n",iface);
-	if (!--(This->ref)) {
-		HeapFree(GetProcessHeap(),0,This);
-		return 0;
-	}
-	return This->ref;
-}
+  assert(This->paf != NULL);
 
-static HRESULT WINAPI IAVIStream_fnCreate(IAVIStream*iface,LPARAM lParam1,LPARAM lParam2) {
-	FIXME("(%p)->Create(0x%08lx,0x%08lx)\n",iface,lParam1,lParam2);
-	return E_FAIL;
+  return IAVIFile_Release((PAVIFILE)This->paf);
 }
 
-static HRESULT WINAPI IAVIStream_fnInfo(IAVIStream*iface,AVISTREAMINFOW *psi,LONG size) {
-	FIXME("(%p)->Info(%p,%ld)\n",iface,psi,size);
-	return E_FAIL;
-}
+static HRESULT WINAPI IPersistFile_fnGetClassID(IPersistFile *iface,
+						LPCLSID pClassID)
+{
+  TRACE("(%p,%p)\n", iface, pClassID);
 
-static LONG WINAPI IAVIStream_fnFindSample(IAVIStream*iface,LONG pos,LONG flags) {
-	FIXME("(%p)->FindSample(%ld,0x%08lx)\n",iface,pos,flags);
-	return E_FAIL;
-}
+  if (pClassID == NULL)
+    return AVIERR_BADPARAM;
+
+  memcpy(pClassID, &CLSID_AVIFile, sizeof(CLSID_AVIFile));
 
-static HRESULT WINAPI IAVIStream_fnReadFormat(IAVIStream*iface,LONG pos,LPVOID format,LONG *formatsize) {
-	FIXME("(%p)->ReadFormat(%ld,%p,%p)\n",iface,pos,format,formatsize);
-	return E_FAIL;
+  return AVIERR_OK;
 }
 
-/***********************************************************************
- *		IAVIStream::SetFormat
- */
-static HRESULT WINAPI IAVIStream_fnSetFormat(IAVIStream*iface,LONG pos,LPVOID format,LONG formatsize) {
-	IAVIStreamImpl	*as = (IAVIStreamImpl*)iface;
+static HRESULT WINAPI IPersistFile_fnIsDirty(IPersistFile *iface)
+{
+  ICOM_THIS(IPersistFileImpl,iface);
 
-	FIXME("(%p)->SetFormat(%ld,%p,%ld)\n",iface,pos,format,formatsize);
-	if (as->lpInputFormat) HeapFree(GetProcessHeap(),0,as->lpInputFormat);
-	as->inputformatsize = formatsize;
-	as->lpInputFormat = HeapAlloc(GetProcessHeap(),0,formatsize);
-	memcpy(as->lpInputFormat,format,formatsize);
-	if (as->iscompressing) {
-		int	xsize;
-		/* Set up the Compressor part */
-		xsize = ICCompressGetFormatSize(as->hic,as->lpInputFormat);
-		as->lpCompressFormat = HeapAlloc(GetProcessHeap(),0,xsize);
-		ICCompressGetFormat(as->hic,as->lpInputFormat,as->lpCompressFormat);
-		ICCompressBegin(as->hic,as->lpInputFormat,as->lpCompressFormat);
-		as->compbufsize = ICCompressGetSize(as->hic,as->lpInputFormat,as->lpCompressFormat);
-		as->compbuffer = HeapAlloc(GetProcessHeap(),0,as->compbufsize);
-
-		/* Set up the Decompressor part (for prev frames?) */
-		xsize=ICDecompressGetFormatSize(as->hic,as->lpCompressFormat);
-		as->decompformat = HeapAlloc(GetProcessHeap(),0,xsize);
-		ICDecompressGetFormat(as->hic,as->lpCompressFormat,as->decompformat);
-		as->decompbufsize=((LPBITMAPINFOHEADER)as->decompbuffer)->biSizeImage;
-		as->decompbuffer = HeapReAlloc(GetProcessHeap(),0,as->decompbuffer,as->decompbufsize);
-		memset(as->decompbuffer,0xff,as->decompbufsize);
-		assert(HeapValidate(GetProcessHeap(),0,NULL));
-
-		ICDecompressGetFormat(as->hic,as->lpCompressFormat,as->decompformat);
-		ICDecompressBegin(as->hic,as->lpCompressFormat,as->decompformat);
-		as->lpPrev = as->lpPrevFormat = NULL;
-	}
-	return S_OK;
-}
-
-static HRESULT WINAPI IAVIStream_fnRead(IAVIStream*iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,LONG *bytesread,LONG *samplesread) {
-	FIXME("(%p)->Read(%ld,%ld,%p,%ld,%p,%p)\n",iface,start,samples,buffer,buffersize,bytesread,samplesread);
-	return E_FAIL;
-}
-
-static HRESULT WINAPI IAVIStream_fnWrite(IAVIStream*iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,DWORD flags,LONG *sampwritten,LONG *byteswritten) {
-	IAVIStreamImpl	*as = (IAVIStreamImpl*)iface;
-	DWORD		ckid,xflags;
-
-	FIXME("(%p)->Write(%ld,%ld,%p,%ld,0x%08lx,%p,%p)\n",iface,start,samples,buffer,buffersize,flags,sampwritten,byteswritten);
-
-	ICCompress(
-		as->hic,flags,
-		as->lpCompressFormat,
-		as->compbuffer,
-		as->lpInputFormat,buffer,
-		&ckid,&xflags,
-		as->curframe,0xffffff/*framesize*/,as->aco.dwQuality,
-		as->lpPrevFormat,as->lpPrev
-	);
-	ICDecompress(
-		as->hic,
-		flags,	/* FIXME: check */
-		as->lpCompressFormat,
-		as->compbuffer,
-		as->decompformat,
-		as->decompbuffer
-	);
-	/* We now have a prev format for the next compress ... */
-	as->lpPrevFormat = as->decompformat;
-	as->lpPrev = as->decompbuffer;
-	return S_OK;
-}
-
-static HRESULT WINAPI IAVIStream_fnDelete(IAVIStream*iface,LONG start,LONG samples) {
-	FIXME("(%p)->Delete(%ld,%ld)\n",iface,start,samples);
-	return E_FAIL;
-}
-static HRESULT WINAPI IAVIStream_fnReadData(IAVIStream*iface,DWORD fcc,LPVOID lp,LONG *lpread) {
-	FIXME("(%p)->ReadData(0x%08lx,%p,%p)\n",iface,fcc,lp,lpread);
-	return E_FAIL;
-}
-
-static HRESULT WINAPI IAVIStream_fnWriteData(IAVIStream*iface,DWORD fcc,LPVOID lp,LONG size) {
-	FIXME("(%p)->WriteData(0x%08lx,%p,%ld)\n",iface,fcc,lp,size);
-	return E_FAIL;
-}
-
-static HRESULT WINAPI IAVIStream_fnSetInfo(IAVIStream*iface,AVISTREAMINFOW*info,LONG infolen) {
-	FIXME("(%p)->SetInfo(%p,%ld)\n",iface,info,infolen);
-	return E_FAIL;
-}
+  TRACE("(%p)\n", iface);
 
-/***********************************************************************
- *		AVIFileCreateStreamA (AVIFIL32.@)
- */
-HRESULT WINAPI AVIFileCreateStreamA(PAVIFILE iface,PAVISTREAM *ppavi,AVISTREAMINFOA * psi) {
-	AVISTREAMINFOW	psiw;
+  assert(This->paf != NULL);
 
-	/* Only the szName at the end is different */
-	memcpy(&psiw,psi,sizeof(*psi)-sizeof(psi->szName));
-        MultiByteToWideChar( CP_ACP, 0, psi->szName, -1,
-                             psiw.szName, sizeof(psiw.szName) / sizeof(WCHAR) );
-	return IAVIFile_CreateStream(iface,ppavi,&psiw);
+  return (This->paf->fDirty ? S_OK : S_FALSE);
 }
 
-/***********************************************************************
- *		AVIFileCreateStreamW (AVIFIL32.@)
- */
-HRESULT WINAPI AVIFileCreateStreamW(IAVIFile*iface,PAVISTREAM*avis,AVISTREAMINFOW*asi) {
-	return IAVIFile_CreateStream(iface,avis,asi);
-}
+static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile *iface,
+					  LPCOLESTR pszFileName, DWORD dwMode)
+{
+  ICOM_THIS(IPersistFileImpl,iface);
 
+  FIXME("(%p,%s,0x%08lX): stub\n", iface, debugstr_w(pszFileName), dwMode);
 
-/***********************************************************************
- *		AVIFileGetStream (AVIFIL32.@)
- *		AVIFileGetStream (AVIFILE.143)
- */
-HRESULT WINAPI AVIFileGetStream(IAVIFile*iface,PAVISTREAM*avis,DWORD fccType,LONG lParam) {
-	return IAVIFile_GetStream(iface,avis,fccType,lParam);
-}
+  assert(This->paf != NULL);
 
-/***********************************************************************
- *		AVIFileInfoA (AVIFIL32.@)
- */
-HRESULT WINAPI AVIFileInfoA(PAVIFILE iface,LPAVIFILEINFOA afi,LONG size) {
-	AVIFILEINFOW	afiw;
-	HRESULT		hres;
-
-	if (size < sizeof(AVIFILEINFOA))
-		return AVIERR_BADSIZE;
-	hres = IAVIFile_Info(iface,&afiw,sizeof(afiw));
-	memcpy(afi,&afiw,sizeof(*afi)-sizeof(afi->szFileType));
-        WideCharToMultiByte( CP_ACP, 0, afiw.szFileType, -1,
-                             afi->szFileType, sizeof(afi->szFileType), NULL, NULL );
-        afi->szFileType[sizeof(afi->szFileType)-1] = 0;
-	return hres;
+  return AVIERR_ERROR;
 }
 
-/***********************************************************************
- *		AVIStreamInfoW (AVIFIL32.@)
- */
-HRESULT WINAPI AVIStreamInfoW(PAVISTREAM iface,AVISTREAMINFOW *asi,LONG
- size) {
- 	return IAVIFile_Info(iface,asi,size);
-}
+static HRESULT WINAPI IPersistFile_fnSave(IPersistFile *iface,
+					  LPCOLESTR pszFileName,BOOL fRemember)
+{
+  TRACE("(%p,%s,%d)\n", iface, debugstr_w(pszFileName), fRemember);
 
-/***********************************************************************
- *		AVIStreamInfoA (AVIFIL32.@)
- */
-HRESULT WINAPI AVIStreamInfoA(PAVISTREAM iface,AVISTREAMINFOA *asi,LONG
- size) {
- 	AVISTREAMINFOW	asiw;
-	HRESULT			hres;
-
-	if (size<sizeof(AVISTREAMINFOA))
-		return AVIERR_BADSIZE;
- 	hres = IAVIFile_Info(iface,&asiw,sizeof(asiw));
-	memcpy(asi,&asiw,sizeof(asiw)-sizeof(asiw.szName));
-        WideCharToMultiByte( CP_ACP, 0, asiw.szName, -1,
-                             asi->szName, sizeof(asi->szName), NULL, NULL );
-        asi->szName[sizeof(asi->szName)-1] = 0;
-	return hres;
+  /* We write directly to disk, so nothing to do. */
+
+  return AVIERR_OK;
 }
 
-/***********************************************************************
- *		AVIFileInfoW (AVIFIL32.@)
- */
-HRESULT WINAPI AVIFileInfoW(PAVIFILE iface,LPAVIFILEINFOW afi,LONG size) {
-	return IAVIFile_Info(iface,afi,size);
+static HRESULT WINAPI IPersistFile_fnSaveCompleted(IPersistFile *iface,
+						   LPCOLESTR pszFileName)
+{
+  TRACE("(%p,%s)\n", iface, debugstr_w(pszFileName));
+
+  /* We write directly to disk, so nothing to do. */
+
+  return AVIERR_OK;
 }
 
-/***********************************************************************
- *		AVIMakeCompressedStream (AVIFIL32.@)
- */
-HRESULT WINAPI AVIMakeCompressedStream(PAVISTREAM *ppsCompressed,PAVISTREAM ppsSource,AVICOMPRESSOPTIONS *aco,CLSID *pclsidHandler) {
-	char			fcc[5];
-	IAVIStreamImpl	*as;
-	FIXME("(%p,%p,%p,%p)\n",ppsCompressed,ppsSource,aco,pclsidHandler);
-	fcc[4]='\0';
-	memcpy(fcc,&(aco->fccType),4);
-	FIXME("\tfccType: '%s'\n",fcc);
-	memcpy(fcc,&(aco->fccHandler),4);
-	FIXME("\tfccHandler: '%s'\n",fcc);
-	FIXME("\tdwFlags: 0x%08lx\n",aco->dwFlags);
-
-	/* we just create a duplicate for now */
-	IAVIStream_AddRef(ppsSource);
-	*ppsCompressed = ppsSource;
-	as = (IAVIStreamImpl*)ppsSource;
-
-	/* this is where the fun begins. Open a compressor and prepare it. */
-	as->hic = ICOpen(aco->fccType,aco->fccHandler,ICMODE_COMPRESS);
-
-	/* May happen. for instance if the codec is not able to compress */
-	if (!as->hic)
-		return AVIERR_UNSUPPORTED;
-
-	ICGetInfo(as->hic,&(as->icinfo),sizeof(ICINFO));
-	FIXME("Opened compressor: %s %s\n",debugstr_w(as->icinfo.szName),debugstr_w(as->icinfo.szDescription));
-	as->iscompressing = TRUE;
-	memcpy(&(as->aco),aco,sizeof(*aco));
-	if (as->icinfo.dwFlags & VIDCF_COMPRESSFRAMES) {
-		ICCOMPRESSFRAMES	icf;
-
-		/* now what to fill in there ... Hmm */
-		memset(&icf,0,sizeof(icf));
-		icf.lDataRate 	= aco->dwBytesPerSecond;
-		icf.lQuality 	= aco->dwQuality;
-		icf.lKeyRate 	= aco->dwKeyFrameEvery;
-
-		icf.GetData = (void *)0xdead4242;
-		icf.PutData = (void *)0xdead4243;
-		ICSendMessage(as->hic,ICM_COMPRESS_FRAMES_INFO,(LPARAM)&icf,sizeof(icf));
-	}
-	return S_OK;
+static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile *iface,
+						LPOLESTR *ppszFileName)
+{
+  ICOM_THIS(IPersistFileImpl,iface);
+
+  TRACE("(%p,%p)\n", iface, ppszFileName);
+
+  if (ppszFileName == NULL)
+    return AVIERR_BADPARAM;
+
+  *ppszFileName = NULL;
+
+  assert(This->paf != NULL);
+
+  if (This->paf->szFileName != NULL) {
+    int len = lstrlenW(This->paf->szFileName);
+
+    *ppszFileName = (LPOLESTR)GlobalAllocPtr(GHND, len * sizeof(WCHAR));
+    if (*ppszFileName == NULL)
+      return AVIERR_MEMORY;
+
+    memcpy(*ppszFileName, This->paf->szFileName, len * sizeof(WCHAR));
+  }
+
+  return AVIERR_OK;
 }
 
-/***********************************************************************
- *		AVIStreamSetFormat (AVIFIL32.@)
- */
-HRESULT WINAPI AVIStreamSetFormat(PAVISTREAM iface,LONG pos,LPVOID format,LONG formatsize) {
-	return IAVIStream_SetFormat(iface,pos,format,formatsize);
+/***********************************************************************/
+
+static HRESULT WINAPI IAVIStream_fnQueryInterface(IAVIStream *iface,
+						  REFIID refiid, LPVOID *obj)
+{
+  ICOM_THIS(IAVIStreamImpl,iface);
+
+  TRACE("(%p,%s,%p)\n", iface, debugstr_guid(refiid), obj);
+
+  if (IsEqualGUID(&IID_IUnknown, refiid) ||
+      IsEqualGUID(&IID_IAVIStream, refiid)) {
+    *obj = This;
+    return S_OK;
+  }
+  /* FIXME: IAVIStreaming interface */
+
+  return OLE_E_ENUM_NOMORE;
 }
 
-/***********************************************************************
- *		AVIStreamReadFormat (AVIFIL32.@)
- */
-HRESULT WINAPI AVIStreamReadFormat(PAVISTREAM iface,LONG pos,LPVOID format,LONG *formatsize) {
-	return IAVIStream_ReadFormat(iface,pos,format,formatsize);
+static ULONG WINAPI IAVIStream_fnAddRef(IAVIStream *iface)
+{
+  ICOM_THIS(IAVIStreamImpl,iface);
+
+  TRACE("(%p)\n",iface);
+  return ++(This->ref);
 }
 
-/***********************************************************************
- *		AVIStreamWrite (AVIFIL32.@)
- */
-HRESULT WINAPI AVIStreamWrite(PAVISTREAM iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,DWORD flags,LONG *sampwritten,LONG *byteswritten) {
-	return IAVIStream_Write(iface,start,samples,buffer,buffersize,flags,sampwritten,byteswritten);
+static ULONG WINAPI IAVIStream_fnRelease(IAVIStream* iface)
+{
+  ICOM_THIS(IAVIStreamImpl,iface);
+
+  TRACE("(%p)\n",iface);
+
+  /* we belong to the AVIFile, which must free us! */
+  if (This->ref == 0) {
+    ERR(": already released!\n");
+    return 0;
+  }
+
+  return --This->ref;
 }
 
-/***********************************************************************
- *		AVIStreamRead (AVIFIL32.@)
- */
-HRESULT WINAPI AVIStreamRead(PAVISTREAM iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,LONG *bytesread,LONG *samplesread) {
-	return IAVIStream_Read(iface,start,samples,buffer,buffersize,bytesread,samplesread);
+static HRESULT WINAPI IAVIStream_fnCreate(IAVIStream *iface, LPARAM lParam1,
+					  LPARAM lParam2)
+{
+  TRACE("(%p,0x%08lX,0x%08lX)\n", iface, lParam1, lParam2);
+
+  /* This IAVIStream interface needs an AVIFile */
+  return AVIERR_UNSUPPORTED;
 }
 
-/***********************************************************************
- *		AVIStreamWriteData (AVIFIL32.@)
- */
-HRESULT WINAPI AVIStreamWriteData(PAVISTREAM iface,DWORD fcc,LPVOID lp,LONG size) {
-	return IAVIStream_WriteData(iface,fcc,lp,size);
+static HRESULT WINAPI IAVIStream_fnInfo(IAVIStream *iface,LPAVISTREAMINFOW psi,
+					LONG size)
+{
+  ICOM_THIS(IAVIStreamImpl,iface);
+
+  TRACE("(%p,%p,%ld)\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)));
+
+  if (size < sizeof(This->sInfo))
+    return AVIERR_BUFFERTOOSMALL;
+  return AVIERR_OK;
 }
 
-/***********************************************************************
- *		AVIStreamReadData (AVIFIL32.@)
- */
-HRESULT WINAPI AVIStreamReadData(PAVISTREAM iface,DWORD fcc,LPVOID lp,LONG *lpread) {
-	return IAVIStream_ReadData(iface,fcc,lp,lpread);
+static LONG WINAPI IAVIStream_fnFindSample(IAVIStream *iface, LONG pos,
+					   LONG flags)
+{
+  FIXME("(%p,%ld,0x%08lX): stub\n",iface,pos,flags);
+
+  return -1;
 }
 
-/***********************************************************************
- *		AVIStreamStart (AVIFIL32.@)
- */
-LONG WINAPI AVIStreamStart(PAVISTREAM iface) {
-	AVISTREAMINFOW	si;
+static HRESULT WINAPI IAVIStream_fnReadFormat(IAVIStream *iface, LONG pos,
+					      LPVOID format, LONG *formatsize)
+{
+  FIXME("(%p,%ld,%p,%p): stub\n", iface, pos, format, formatsize);
 
-	IAVIStream_Info(iface,&si,sizeof(si));
-	return si.dwStart;
+  return E_FAIL;
 }
 
-/***********************************************************************
- *		AVIStreamLength (AVIFIL32.@)
- */
-LONG WINAPI AVIStreamLength(PAVISTREAM iface) {
-	AVISTREAMINFOW	si;
-	HRESULT			ret;
-
-	ret = IAVIStream_Info(iface,&si,sizeof(si));
-	if (ret) /* error */
-		return 1;
-	return si.dwLength;
+static HRESULT WINAPI IAVIStream_fnSetFormat(IAVIStream *iface, LONG pos,
+					     LPVOID format, LONG formatsize)
+{
+  ICOM_THIS(IAVIStreamImpl,iface);
+
+  FIXME("(%p,%ld,%p,%ld): stub\n", iface, pos, format, formatsize);
+
+  return E_FAIL;
 }
 
-/***********************************************************************
- *		AVIStreamRelease (AVIFIL32.@)
- */
-ULONG WINAPI AVIStreamRelease(PAVISTREAM iface) {
-	return IAVIStream_Release(iface);
+static HRESULT WINAPI IAVIStream_fnRead(IAVIStream *iface, LONG start,
+					LONG samples, LPVOID buffer,
+					LONG buffersize, LPLONG bytesread,
+					LPLONG samplesread)
+{
+  ICOM_THIS(IAVIStreamImpl,iface);
+
+  FIXME("(%p,%ld,%ld,%p,%ld,%p,%p): stub\n", iface, start, samples, buffer,
+	buffersize, bytesread, samplesread);
+
+  if (bytesread != NULL)
+    *bytesread = 0;
+  if (samplesread != NULL)
+    *samplesread = 0;
+
+  return E_FAIL;
 }
 
-/***********************************************************************
- *		AVIStreamGetFrameOpen (AVIFIL32.@)
- */
-PGETFRAME WINAPI AVIStreamGetFrameOpen(PAVISTREAM iface,LPBITMAPINFOHEADER bmi) {
-	FIXME("(%p)->(%p),stub!\n",iface,bmi);
-	return NULL;
+static HRESULT WINAPI IAVIStream_fnWrite(IAVIStream *iface, LONG start,
+					 LONG samples, LPVOID buffer,
+					 LONG buffersize, DWORD flags,
+					 LPLONG sampwritten,
+					 LPLONG byteswritten)
+{
+  ICOM_THIS(IAVIStreamImpl,iface);
+
+  FIXME("(%p,%ld,%ld,%p,%ld,0x%08lX,%p,%p): stub\n", iface, start, samples,
+	buffer, buffersize, flags, sampwritten, byteswritten);
+
+  if (sampwritten != NULL)
+    *sampwritten = 0;
+  if (byteswritten != NULL)
+    *byteswritten = 0;
+
+  if (buffer == NULL && buffersize > 0)
+    return AVIERR_BADPARAM;
+
+  return E_FAIL;
 }
 
-/***********************************************************************
- *		AVIStreamGetFrame (AVIFIL32.@)
- */
-LPVOID WINAPI AVIStreamGetFrame(PGETFRAME pg,LONG pos) {
-	return IGetFrame_GetFrame(pg,pos);
+static HRESULT WINAPI IAVIStream_fnDelete(IAVIStream *iface, LONG start,
+					  LONG samples)
+{
+  FIXME("(%p,%ld,%ld): stub\n", iface, start, samples);
+
+  return E_FAIL;
 }
 
-/***********************************************************************
- *		AVIStreamGetFrameClose (AVIFIL32.@)
- */
-HRESULT WINAPI AVIStreamGetFrameClose(PGETFRAME pg) {
-	if (pg) IGetFrame_Release(pg);
-	return 0;
+static HRESULT WINAPI IAVIStream_fnReadData(IAVIStream *iface, DWORD fcc,
+					    LPVOID lp, LPLONG lpread)
+{
+  FIXME("(%p,0x%08lX,%p,%p): stub\n", iface, fcc, lp, lpread);
+
+  return E_FAIL;
 }
 
-/***********************************************************************
- *		AVIFileRelease (AVIFIL32.@)
- *		AVIFileRelease (AVIFILE.141)
- */
-ULONG WINAPI AVIFileRelease(PAVIFILE iface) {
-	return IAVIFile_Release(iface);
+static HRESULT WINAPI IAVIStream_fnWriteData(IAVIStream *iface, DWORD fcc,
+					     LPVOID lp, LONG size)
+{
+  FIXME("(%p,0x%08lx,%p,%ld): stub\n", iface, fcc, lp, size);
+
+  return E_FAIL;
 }
 
-/***********************************************************************
- *		AVIFileExit (AVIFIL32.@)
- *		AVIFileExit (AVIFILE.101)
- */
-void WINAPI AVIFileExit(void) {
-	FIXME("(), stub.\n");
+static HRESULT WINAPI IAVIStream_fnSetInfo(IAVIStream *iface,
+					   LPAVISTREAMINFOW info, LONG infolen)
+{
+  FIXME("(%p,%p,%ld): stub\n", iface, info, infolen);
+
+  return E_FAIL;
 }
Index: dlls/avifil32/avifile.spec
===================================================================
RCS file: /home/wine/wine/dlls/avifil32/avifile.spec,v
retrieving revision 1.4
diff -u -r1.4 avifile.spec
--- dlls/avifil32/avifile.spec	21 Jun 2002 19:15:46 -0000	1.4
+++ dlls/avifil32/avifile.spec	10 Oct 2002 18:05:55 -0000
@@ -15,8 +15,8 @@
 100 pascal   AVIFileInit() AVIFileInit
 101 pascal   AVIFileExit() AVIFileExit
 102 pascal   AVIFileOpen(ptr str word ptr) AVIFileOpenA
-103 stub     AVISTREAMOPENFROMFILE
-104 stub     AVISTREAMCREATE
+103  pascal   AVIStreamOpenFromFile(ptr str long word ptr) AVIStreamOpenFromFileA
+104 pascal   AVIStreamCreate(ptr long long ptr) AVIStreamCreate
 105 stub     AVIMAKECOMPRESSEDSTREAM
 106 stub     AVIMAKEFILEFROMSTREAMS
 107 stub     AVIMAKESTREAMFROMCLIPBOARD
@@ -28,20 +28,20 @@
 122 stub     AVISAVEOPTIONS
 123 stub     AVIBUILDFILTER
 124 stub     AVISAVEOPTIONSFREE
-130 stub     AVISTREAMSTART
-131 stub     AVISTREAMLENGTH
-132 stub     AVISTREAMTIMETOSAMPLE
-133 stub     AVISTREAMSAMPLETOTIME
-140 stub     AVIFILEADDREF
+130 pascal   AVIStreamStart(long) AVIStreamStart
+131 pascal   AVIStreamLength(long) AVIStreamLength
+132 pascal   AVIStreamTimeToSample(long long) AVIStreamTimeToSample
+133 pascal   AVIStreamSampleToTime(long long) AVIStreamSampleToTime
+140 pascal   AVIFileAddRef(long) AVIFileAddRef
 141 pascal   AVIFileRelease(long) AVIFileRelease
-142 stub     AVIFILEINFO
+142 pascal   AVIFileInfo(long ptr long) AVIFileInfoA
 143 pascal   AVIFileGetStream(long ptr long long) AVIFileGetStream
 144 stub     AVIFILECREATESTREAM
 146 stub     AVIFILEWRITEDATA
 147 stub     AVIFILEREADDATA
-148 stub     AVIFILEENDRECORD
-160 stub     AVISTREAMADDREF
-161 stub     AVISTREAMRELEASE
+148 pascal   AVIFileEndRecord(long) AVIFileEndRecord
+160 pascal   AVIStreamAddRef(long) AVIStreamAddRef
+161 pascal   AVIStreamRelease(long) AVIStreamRelease
 162 stub     AVISTREAMINFO
 163 stub     AVISTREAMFINDSAMPLE
 164 stub     AVISTREAMREADFORMAT
Index: include/vfw.h
===================================================================
RCS file: /home/wine/wine/include/vfw.h,v
retrieving revision 1.27
diff -u -r1.27 vfw.h
--- include/vfw.h	31 May 2002 23:06:49 -0000	1.27
+++ include/vfw.h	10 Oct 2002 18:05:59 -0000
@@ -1020,24 +1020,26 @@
 #define IAVIStream_WriteData(p,a,b,c)     ICOM_CALL3(WriteData,p,a,b,c)
 #define IAVIStream_SetInfo(p,a,b)         ICOM_CALL2(SetInfo,p,a,b)
 
-HRESULT WINAPI AVIMakeCompressedStream(PAVISTREAM*ppsCompressed,PAVISTREAM ppsSource,AVICOMPRESSOPTIONS *lpOptions,CLSID*pclsidHandler);
-
+ULONG WINAPI AVIStreamAddRef(PAVISTREAM iface);
+ULONG WINAPI AVIStreamRelease(PAVISTREAM iface);
 HRESULT WINAPI AVIStreamCreate(PAVISTREAM*,LONG,LONG,CLSID*);
 HRESULT WINAPI AVIStreamInfoA(PAVISTREAM iface,AVISTREAMINFOA *asi,LONG size);
 HRESULT WINAPI AVIStreamInfoW(PAVISTREAM iface,AVISTREAMINFOW *asi,LONG size);
 #define AVIStreamInfo WINELIB_NAME_AW(AVIStreamInfo)
-LPVOID WINAPI AVIStreamGetFrame(PGETFRAME pg,LONG pos);
-HRESULT WINAPI AVIStreamGetFrameClose(PGETFRAME pg);
-PGETFRAME WINAPI AVIStreamGetFrameOpen(PAVISTREAM pavi,LPBITMAPINFOHEADER lpbiWanted);
-LONG WINAPI AVIStreamLength(PAVISTREAM iface);
-HRESULT WINAPI AVIStreamRead(PAVISTREAM iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,LONG *bytesread,LONG *samplesread);
-HRESULT WINAPI AVIStreamReadData(PAVISTREAM iface,DWORD fcc,LPVOID lp,LONG *lpread);
+HRESULT WINAPI AVIStreamFindSample(PAVISTREAM pstream, LONG pos, DWORD flags);
 HRESULT WINAPI AVIStreamReadFormat(PAVISTREAM iface,LONG pos,LPVOID format,LONG *formatsize);
-ULONG WINAPI AVIStreamRelease(PAVISTREAM iface);
 HRESULT WINAPI AVIStreamSetFormat(PAVISTREAM iface,LONG pos,LPVOID format,LONG formatsize);
-LONG WINAPI AVIStreamStart(PAVISTREAM iface);
+HRESULT WINAPI AVIStreamRead(PAVISTREAM iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,LONG *bytesread,LONG *samplesread);
 HRESULT WINAPI AVIStreamWrite(PAVISTREAM iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,DWORD flags,LONG *sampwritten,LONG *byteswritten);
+HRESULT WINAPI AVIStreamReadData(PAVISTREAM iface,DWORD fcc,LPVOID lp,LONG *lpread);
 HRESULT WINAPI AVIStreamWriteData(PAVISTREAM iface,DWORD fcc,LPVOID lp,LONG size);
+
+PGETFRAME WINAPI AVIStreamGetFrameOpen(PAVISTREAM pavi,LPBITMAPINFOHEADER lpbiWanted);
+LPVOID  WINAPI AVIStreamGetFrame(PGETFRAME pg,LONG pos);
+HRESULT WINAPI AVIStreamGetFrameClose(PGETFRAME pg);
+
+HRESULT WINAPI AVIMakeCompressedStream(PAVISTREAM*ppsCompressed,PAVISTREAM ppsSource,AVICOMPRESSOPTIONS *lpOptions,CLSID*pclsidHandler);
+
 HRESULT WINAPI AVIStreamOpenFromFileA(PAVISTREAM *ppavi, LPCSTR szFile,
 				      DWORD fccType, LONG lParam,
 				      UINT mode, CLSID *pclsidHandler);
@@ -1046,6 +1048,11 @@
 				      UINT mode, CLSID *pclsidHandler);
 #define AVIStreamOpenFromFile WINELIB_NAME_AW(AVIStreamOpenFromFile)
 
+LONG WINAPI AVIStreamStart(PAVISTREAM iface);
+LONG WINAPI AVIStreamLength(PAVISTREAM iface);
+LONG WINAPI AVIStreamSampleToTime(PAVISTREAM pstream, LONG lSample);
+LONG WINAPI AVIStreamTimeToSample(PAVISTREAM pstream, LONG lTime);
+
 #define AVIStreamFormatSize(pavi, lPos, plSize) \
     AVIStreamReadFormat(pavi, lPos, NULL, plSize)
 
@@ -1081,20 +1088,25 @@
 #define IAVIFile_EndRecord(p)        ICOM_CALL (EndRecord,p)
 #define IAVIFile_DeleteStream(p,a,b) ICOM_CALL2(DeleteStream,p,a,b)
 
-HRESULT WINAPI AVIFileCreateStreamA(PAVIFILE pfile,PAVISTREAM* ppavi,AVISTREAMINFOA* psi);
-HRESULT WINAPI AVIFileCreateStreamW(PAVIFILE pfile,PAVISTREAM* ppavi,AVISTREAMINFOW* psi);
-#define AVIFileCreateStream WINELIB_NAME_AW(AVIFileCreateStream)
-void WINAPI AVIFileExit(void);
-HRESULT WINAPI AVIFileGetStream(PAVIFILE pfile,PAVISTREAM* avis,DWORD fccType,LONG lParam);
-HRESULT WINAPI AVIFileInfoA(PAVIFILE pfile,PAVIFILEINFOA pfi,LONG lSize);
-HRESULT WINAPI AVIFileInfoW(PAVIFILE pfile,PAVIFILEINFOW pfi,LONG lSize);
-#define AVIFileInfo WINELIB_NAME_AW(AVIFileInfo)
 void WINAPI AVIFileInit(void);
+void WINAPI AVIFileExit(void);
+
 HRESULT WINAPI AVIFileOpenA(PAVIFILE* ppfile,LPCSTR szFile,UINT uMode,LPCLSID lpHandler);
 HRESULT WINAPI AVIFileOpenW(PAVIFILE* ppfile,LPCWSTR szFile,UINT uMode,LPCLSID lpHandler);
 #define AVIFileOpen WINELIB_NAME_AW(AVIFileOpen)
-ULONG WINAPI AVIFileRelease(PAVIFILE iface);
 
+ULONG   WINAPI AVIFileAddRef(PAVIFILE pfile);
+ULONG   WINAPI AVIFileRelease(PAVIFILE pfile);
+HRESULT WINAPI AVIFileInfoA(PAVIFILE pfile,PAVIFILEINFOA pfi,LONG lSize);
+HRESULT WINAPI AVIFileInfoW(PAVIFILE pfile,PAVIFILEINFOW pfi,LONG lSize);
+#define AVIFileInfo WINELIB_NAME_AW(AVIFileInfo)
+HRESULT WINAPI AVIFileGetStream(PAVIFILE pfile,PAVISTREAM* avis,DWORD fccType,LONG lParam);
+HRESULT WINAPI AVIFileCreateStreamA(PAVIFILE pfile,PAVISTREAM* ppavi,AVISTREAMINFOA* psi);
+HRESULT WINAPI AVIFileCreateStreamW(PAVIFILE pfile,PAVISTREAM* ppavi,AVISTREAMINFOW* psi);
+#define AVIFileCreateStream WINELIB_NAME_AW(AVIFileCreateStream)
+HRESULT WINAPI AVIFileWriteData(PAVIFILE pfile,DWORD fcc,LPVOID lp,LONG size);
+HRESULT WINAPI AVIFileReadData(PAVIFILE pfile,DWORD fcc,LPVOID lp,LPLONG size);
+HRESULT WINAPI AVIFileEndRecord(PAVIFILE pfile);
 
 /*****************************************************************************
  * IGetFrame interface
--- /dev/null	Sat Feb 23 16:05:24 2002
+++ dlls/avifil32/factory.c	Thu Oct 10 19:53:47 2002
@@ -0,0 +1,200 @@
+/*
+ * 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * 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
+ */
+
+#include <assert.h>
+
+#include "winbase.h"
+#include "winerror.h"
+
+#include "ole2.h"
+#include "vfw.h"
+
+#include "wine/debug.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(avifile);
+
+#include "initguid.h"
+#include "avifile_private.h"
+
+HMODULE AVIFILE_hModule   = (HMODULE)NULL;
+
+BOOL    AVIFILE_bLocked   = FALSE;
+UINT    AVIFILE_uUseCount = 0;
+
+static HRESULT WINAPI IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj);
+static ULONG   WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface);
+static ULONG   WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface);
+static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,LPUNKNOWN pOuter,REFIID riid,LPVOID *ppobj);
+static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock);
+
+static ICOM_VTABLE(IClassFactory) iclassfact = {
+  ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
+  IClassFactory_fnQueryInterface,
+  IClassFactory_fnAddRef,
+  IClassFactory_fnRelease,
+  IClassFactory_fnCreateInstance,
+  IClassFactory_fnLockServer
+};
+
+typedef struct
+{
+  /* IUnknown fields */
+  ICOM_VFIELD(IClassFactory);
+  DWORD	 dwRef;
+
+  CLSID  clsid;
+} IClassFactoryImpl;
+
+static HRESULT AVIFILE_CreateClassFactory(const CLSID *pclsid, const IID *riid,
+					  LPVOID *ppv)
+{
+  IClassFactoryImpl *pClassFactory = NULL;
+  HRESULT            hr;
+
+  *ppv = NULL;
+
+  pClassFactory = (IClassFactoryImpl*)LocalAlloc(LPTR, sizeof(*pClassFactory));
+  if (pClassFactory == NULL)
+    return E_OUTOFMEMORY;
+
+  ICOM_VTBL(pClassFactory) = &iclassfact;
+  pClassFactory->dwRef     = 0;
+  memcpy(&pClassFactory->clsid, pclsid, sizeof(pClassFactory->clsid));
+
+  hr = IUnknown_QueryInterface((IUnknown*)pClassFactory, riid, ppv);
+  if (FAILED(hr)) {
+    LocalFree((HLOCAL)pClassFactory);
+    *ppv = NULL;
+  }
+
+  return hr;
+}
+
+static HRESULT WINAPI IClassFactory_fnQueryInterface(LPCLASSFACTORY iface,
+						     REFIID riid,LPVOID *ppobj)
+{
+  TRACE("(%p,%p,%p)\n", iface, riid, ppobj);
+
+  if ((IsEqualGUID(&IID_IUnknown, riid)) ||
+      (IsEqualGUID(&IID_IClassFactory, riid))) {
+    *ppobj = iface;
+    IClassFactory_AddRef(iface);
+    return S_OK;
+  }
+
+  return E_NOINTERFACE;
+}
+
+static ULONG WINAPI IClassFactory_fnAddRef(LPCLASSFACTORY iface)
+{
+  ICOM_THIS(IClassFactoryImpl,iface);
+
+  TRACE("(%p)\n", iface);
+
+  return ++(This->dwRef);
+}
+
+static ULONG WINAPI IClassFactory_fnRelease(LPCLASSFACTORY iface)
+{
+  ICOM_THIS(IClassFactoryImpl,iface);
+
+  TRACE("(%p)\n", iface);
+  if ((--(This->dwRef)) > 0)
+    return This->dwRef;
+
+  return 0;
+}
+
+static HRESULT WINAPI IClassFactory_fnCreateInstance(LPCLASSFACTORY iface,
+						     LPUNKNOWN pOuter,
+						     REFIID riid,LPVOID *ppobj)
+{
+  ICOM_THIS(IClassFactoryImpl,iface);
+
+  FIXME("(%p,%p,%s,%p): stub!\n", iface, pOuter, debugstr_guid(riid), ppobj);
+
+  if (ppobj == NULL || pOuter != NULL)
+    return E_FAIL;
+  *ppobj = NULL;
+
+  if (IsEqualGUID(&CLSID_AVIFile, &This->clsid))
+    return AVIFILE_CreateAVIFile(riid,ppobj);
+/*   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); */
+
+  return E_NOINTERFACE;
+}
+
+static HRESULT WINAPI IClassFactory_fnLockServer(LPCLASSFACTORY iface,BOOL dolock)
+{
+  TRACE("(%p,%d)\n",iface,dolock);
+
+  AVIFILE_bLocked = dolock;
+
+  return S_OK;
+}
+
+
+/***********************************************************************
+ *		DllGetClassObject (AVIFIL32.@)
+ */
+HRESULT WINAPI AVIFILE_DllGetClassObject(const CLSID* pclsid,REFIID piid,LPVOID *ppv)
+{
+  TRACE("(%s,%s,%p)\n", debugstr_guid(pclsid), debugstr_guid(piid), ppv);
+
+  if (pclsid == NULL || piid == NULL || ppv == NULL)
+    return E_FAIL;
+
+  return AVIFILE_CreateClassFactory(pclsid,piid,ppv);
+}
+
+/*****************************************************************************
+ *		DllCanUnloadNow		(AVIFIL32.@)
+ */
+DWORD WINAPI AVIFILE_DllCanUnloadNow(void)
+{
+  return ((AVIFILE_bLocked || AVIFILE_uUseCount) ? S_FALSE : S_OK);
+}
+
+/*****************************************************************************
+ *		AVIFILE_DllMain		[internal]
+ */
+BOOL WINAPI AVIFILE_DllMain(HINSTANCE hInstDll, DWORD fdwReason,
+			    LPVOID lpvReserved)
+{
+  TRACE("(%d,%lu,%p)\n", hInstDll, fdwReason, lpvReserved);
+
+  switch (fdwReason) {
+  case DLL_PROCESS_ATTACH:
+    if (AVIFILE_hModule == (HMODULE)NULL)
+      AVIFILE_hModule = (HMODULE)hInstDll;
+    break;
+  case DLL_PROCESS_DETACH:
+    break;
+  case DLL_THREAD_ATTACH:
+    break;
+  case DLL_THREAD_DETACH:
+    break;
+  };
+
+  return TRUE;
+}
--- /dev/null	Sat Feb 23 16:05:24 2002
+++ dlls/avifil32/avifile_private.h	Thu Oct 10 19:53:39 2002
@@ -0,0 +1,37 @@
+/*
+ * 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * 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
+ */
+
+#ifndef __AVIFILE_PRIVATE_H
+#define __AVIFILE_PRIVATE_H
+
+#ifndef MAX_AVISTREAMS
+#define MAX_AVISTREAMS 4
+#endif
+
+DEFINE_AVIGUID(CLSID_ICMStream, 0x00020001, 0, 0);
+DEFINE_AVIGUID(CLSID_WAVFile,   0x00020003, 0, 0);
+DEFINE_AVIGUID(CLSID_ACMStream, 0x0002000F, 0, 0);
+
+extern HMODULE AVIFILE_hModule;
+
+extern HRESULT AVIFILE_CreateAVIFile(REFIID riid, LPVOID *ppobj);
+extern HRESULT AVIFILE_CreateWAVFile(REFIID riid, LPVOID *ppobj);
+extern HRESULT AVIFILE_CreateACMStream(REFIID riid, LPVOID *ppobj);
+extern HRESULT AVIFILE_CreateICMStream(REFIID riid, LPVOID *ppobj);
+
+#endif
--- /dev/null	Sat Feb 23 16:05:24 2002
+++ dlls/avifil32/api.c	Thu Oct 10 19:53:58 2002
@@ -0,0 +1,823 @@
+/*
+ * Copyright 1999 Marcus Meissner
+ * 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * 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
+ */
+
+#include <assert.h>
+
+#include "winbase.h"
+#include "winnls.h"
+#include "winuser.h"
+#include "winreg.h"
+#include "winerror.h"
+
+#include "ole2.h"
+#include "shellapi.h"
+#include "vfw.h"
+
+#include "wine/debug.h"
+#include "wine/unicode.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(avifile);
+
+/***********************************************************************
+ * copied from rewind/dlls/shell32/undocshell.h
+ */
+HRESULT WINAPI SHCoCreateInstance(LPCSTR lpszClsid,REFCLSID rClsid,
+				  LPUNKNOWN pUnkOuter,REFIID riid,LPVOID *ppv);
+
+/***********************************************************************
+ * copied from rewind/dlls/ole32/compobj.c
+ */
+static HRESULT AVIFILE_CLSIDFromString(LPCSTR idstr, LPCLSID id)
+{
+  BYTE *s = (BYTE*)idstr;
+  BYTE *p;
+  INT   i;
+  BYTE table[256];
+
+  if (!s) {
+    memset(s, 0, sizeof(CLSID));
+    return S_OK;
+  } else {  /* validate the CLSID string */
+    if (lstrlenA(s) != 38)
+      return CO_E_CLASSSTRING;
+
+    if ((s[0]!='{') || (s[9]!='-') || (s[14]!='-') || (s[19]!='-') ||
+	(s[24]!='-') || (s[37]!='}'))
+      return CO_E_CLASSSTRING;
+
+    for (i = 1; i < 37; i++) {
+      if ((i == 9) || (i == 14) || (i == 19) || (i == 24))
+	continue;
+      if (!(((s[i] >= '0') && (s[i] <= '9'))  ||
+	    ((s[i] >= 'a') && (s[i] <= 'f'))  ||
+	    ((s[i] >= 'A') && (s[i] <= 'F')))
+	  )
+	return CO_E_CLASSSTRING;
+    }
+  }
+
+  TRACE("%s -> %p\n", s, id);
+
+  /* quick lookup table */
+  memset(table, 0, 256);
+
+  for (i = 0; i < 10; i++)
+    table['0' + i] = i;
+
+  for (i = 0; i < 6; i++) {
+    table['A' + i] = i+10;
+    table['a' + i] = i+10;
+  }
+
+  /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
+  p = (BYTE *) id;
+
+  s++;	/* skip leading brace  */
+  for (i = 0; i < 4; i++) {
+    p[3 - i] = table[*s]<<4 | table[*(s+1)];
+    s += 2;
+  }
+  p += 4;
+  s++;	/* skip - */
+
+  for (i = 0; i < 2; i++) {
+    p[1-i] = table[*s]<<4 | table[*(s+1)];
+    s += 2;
+  }
+  p += 2;
+  s++;	/* skip - */
+
+  for (i = 0; i < 2; i++) {
+    p[1-i] = table[*s]<<4 | table[*(s+1)];
+    s += 2;
+  }
+  p += 2;
+  s++;	/* skip - */
+
+  /* these are just sequential bytes */
+  for (i = 0; i < 2; i++) {
+    *p++ = table[*s]<<4 | table[*(s+1)];
+    s += 2;
+  }
+  s++;	/* skip - */
+
+  for (i = 0; i < 6; i++) {
+    *p++ = table[*s]<<4 | table[*(s+1)];
+    s += 2;
+  }
+
+  return S_OK;
+}
+
+/***********************************************************************
+ *		AVIFileInit		(AVIFIL32.@)
+ *		AVIFileInit		(AVIFILE.100)
+ */
+void WINAPI AVIFileInit(void) {
+  /* need to load ole32.dll if not already done and get some functions */
+  FIXME("(): stub!\n");
+}
+
+/***********************************************************************
+ *		AVIFileExit		(AVIFIL32.@)
+ *		AVIFileExit		(AVIFILE.101)
+ */
+void WINAPI AVIFileExit(void) {
+  /* need to free ole32.dll if we are the last exit call */
+  FIXME("(): stub!\n");
+}
+
+/***********************************************************************
+ *		AVIFileOpenA		(AVIFIL32.@)
+ *		AVIFileOpenA		(AVIFILE.102)
+ */
+HRESULT WINAPI AVIFileOpenA(PAVIFILE *ppfile, LPCSTR szFile, UINT uMode,
+			    LPCLSID lpHandler)
+{
+  LPWSTR  wszFile = NULL;
+  HRESULT hr;
+  int     len;
+
+  TRACE("(%p,%s,0x%08X,%s)\n", ppfile, debugstr_a(szFile), uMode,
+	debugstr_guid(lpHandler));
+
+  /* check parameters */
+  if (ppfile == NULL || szFile == NULL)
+    return AVIERR_BADPARAM;
+
+  /* convert ASCII string to Unicode and call unicode function */
+  len = lstrlenA(szFile);
+  if (len <= 0)
+    return AVIERR_BADPARAM;
+
+  wszFile = (LPWSTR)LocalAlloc(LPTR, (len + 1) * sizeof(WCHAR));
+  if (wszFile == NULL)
+    return AVIERR_MEMORY;
+
+  MultiByteToWideChar(CP_ACP, 0, szFile, -1, wszFile, len + 1);
+  wszFile[len + 1] = 0;
+
+  hr = AVIFileOpenW(ppfile, wszFile, uMode, lpHandler);
+
+  LocalFree((HLOCAL)wszFile);
+
+  return hr;
+}
+
+/***********************************************************************
+ *		AVIFileOpenW		(AVIFIL32.@)
+ */
+HRESULT WINAPI AVIFileOpenW(PAVIFILE *ppfile, LPCWSTR szFile, UINT uMode,
+			    LPCLSID lpHandler)
+{
+  IPersistFile *ppersist = NULL;
+  CLSID         clsidHandler;
+  HRESULT       hr;
+
+  FIXME("(%p,%s,0x%X,%s): stub!\n", ppfile, debugstr_w(szFile), uMode,
+	debugstr_guid(lpHandler));
+
+  /* check parameters */
+  if (ppfile == NULL || szFile == NULL)
+    return AVIERR_BADPARAM;
+
+  *ppfile = NULL;
+
+  /* if no handler then try guessing it by extension */
+  if (lpHandler == NULL) {
+    FIXME(": must read HKEY_CLASSES_ROOT\\AVIFile\\Extensions\\%s\n", debugstr_w(strrchrW(szFile, L'.')));
+  } else
+    memcpy(&clsidHandler, lpHandler, sizeof(clsidHandler));
+
+  /* crete instance of handler */
+  hr = SHCoCreateInstance(NULL, &clsidHandler, NULL,
+			  &IID_IAVIFile, (LPVOID*)ppfile);
+  if (FAILED(hr) || *ppfile == NULL)
+    return hr;
+
+  /* ask for IPersistFile interface for loading/creating the file */
+  hr = IAVIFile_QueryInterface(*ppfile, &IID_IPersistFile, (LPVOID*)&ppersist);
+  if (FAILED(hr) || ppersist == NULL) {
+    IAVIFile_Release(*ppfile);
+    *ppfile = NULL;
+    return hr;
+  }
+
+  hr = IPersistFile_Load(ppersist, szFile, uMode);
+  IPersistFile_Release(ppersist);
+  if (FAILED(hr)) {
+    IAVIFile_Release(*ppfile);
+    *ppfile = NULL;
+  }
+
+  return hr;
+}
+
+/***********************************************************************
+ *		AVIFileAddRef		(AVIFIL32.@)
+ *		AVIFileAddRef		(AVIFILE.140)
+ */
+ULONG WINAPI AVIFileAddRef(PAVIFILE pfile)
+{
+  TRACE("(%p)\n", pfile);
+
+  if (pfile == NULL) {
+    ERR(": bad handle passed!\n");
+    return 0;
+  }
+
+  return IAVIFile_AddRef(pfile);
+}
+
+/***********************************************************************
+ *		AVIFileRelease		(AVIFIL32.@)
+ *		AVIFileRelease		(AVIFILE.141)
+ */
+ULONG WINAPI AVIFileRelease(PAVIFILE pfile)
+{
+  TRACE("(%p)\n", pfile);
+
+  if (pfile == NULL) {
+    ERR(": bad handle passed!\n");
+    return 0;
+  }
+
+  return IAVIFile_Release(pfile);
+}
+
+/***********************************************************************
+ *		AVIFileInfoA		(AVIFIL32.@)
+ */
+HRESULT WINAPI AVIFileInfoA(PAVIFILE pfile, LPAVIFILEINFOA afi, LONG size)
+{
+  AVIFILEINFOW afiw;
+  HRESULT      hres;
+
+  TRACE("(%p,%p,%ld)\n", pfile, afi, size);
+
+  if (pfile == NULL)
+    return AVIERR_BADHANDLE;
+  if (size < sizeof(AVIFILEINFOA))
+    return AVIERR_BADSIZE;
+
+  hres = IAVIFile_Info(pfile, &afiw, sizeof(afiw));
+
+  memcpy(afi, &afiw, sizeof(*afi) - sizeof(afi->szFileType));
+  WideCharToMultiByte(CP_ACP, 0, afiw.szFileType, -1, afi->szFileType,
+		      sizeof(afi->szFileType), NULL, NULL);
+  afi->szFileType[sizeof(afi->szFileType) - 1] = 0;
+
+  return hres;
+}
+
+/***********************************************************************
+ *		AVIFileInfoW		(AVIFIL32.@)
+ */
+HRESULT WINAPI AVIFileInfoW(PAVIFILE pfile, LPAVIFILEINFOW afiw, LONG size)
+{
+  TRACE("(%p,%p,%ld)\n", pfile, afiw, size);
+
+  if (pfile == NULL)
+    return AVIERR_BADHANDLE;
+
+  return IAVIFile_Info(pfile, afiw, size);
+}
+
+/***********************************************************************
+ *		AVIFileGetStream	(AVIFIL32.@)
+ *		AVIFileGetStream	(AVIFILE.143)
+ */
+HRESULT WINAPI AVIFileGetStream(PAVIFILE pfile, PAVISTREAM *avis,
+				DWORD fccType, LONG lParam)
+{
+  TRACE("(%p,%p,'%4.4s',%ld)\n", pfile, avis, (char*)&fccType, lParam);
+
+  if (pfile == NULL)
+    return AVIERR_BADHANDLE;
+
+  return IAVIFile_GetStream(pfile, avis, fccType, lParam);
+}
+
+/***********************************************************************
+ *		AVIFileCreateStreamA	(AVIFIL32.@)
+ */
+HRESULT WINAPI AVIFileCreateStreamA(PAVIFILE pfile, PAVISTREAM *ppavi,
+				    LPAVISTREAMINFOA psi)
+{
+  AVISTREAMINFOW	psiw;
+
+  TRACE("(%p,%p,%p)\n", pfile, ppavi, psi);
+
+  if (pfile == NULL)
+    return AVIERR_BADHANDLE;
+
+  /* Only the szName at the end is different */
+  memcpy(&psiw, psi, sizeof(*psi) - sizeof(psi->szName));
+  MultiByteToWideChar(CP_ACP, 0, psi->szName, -1, psiw.szName,
+		      sizeof(psiw.szName) / sizeof(psiw.szName[0]));
+
+  return IAVIFile_CreateStream(pfile, ppavi, &psiw);
+}
+
+/***********************************************************************
+ *		AVIFileCreateStreamW	(AVIFIL32.@)
+ */
+HRESULT WINAPI AVIFileCreateStreamW(PAVIFILE pfile, PAVISTREAM *avis,
+				    LPAVISTREAMINFOW asi)
+{
+  TRACE("(%p,%p,%p)\n", pfile, avis, asi);
+
+  return IAVIFile_CreateStream(pfile, avis, asi);
+}
+
+/***********************************************************************
+ *		AVIFileWriteData	(AVIFIL32.@)
+ */
+HRESULT WINAPI AVIFileWriteData(PAVIFILE pfile,DWORD fcc,LPVOID lp,LONG size)
+{
+  TRACE("(%p,'%4.4s',%p,%ld)\n", pfile, (char*)&fcc, lp, size);
+
+  if (pfile == NULL)
+    return AVIERR_BADHANDLE;
+
+  return IAVIFile_WriteData(pfile, fcc, lp, size);
+}
+
+/***********************************************************************
+ *		AVIFileReadData		(AVIFIL32.@)
+ */
+HRESULT WINAPI AVIFileReadData(PAVIFILE pfile,DWORD fcc,LPVOID lp,LPLONG size)
+{
+  TRACE("(%p,'%4.4s',%p,%p)\n", pfile, (char*)&fcc, lp, size);
+
+  if (pfile == NULL)
+    return AVIERR_BADHANDLE;
+
+  return IAVIFile_ReadData(pfile, fcc, lp, size);
+}
+
+/***********************************************************************
+ *		AVIFileEndRecord	(AVIFIL32.@)
+ */
+HRESULT WINAPI AVIFileEndRecord(PAVIFILE pfile)
+{
+  TRACE("(%p)\n", pfile);
+
+  if (pfile == NULL)
+    return AVIERR_BADHANDLE;
+
+  return IAVIFile_EndRecord(pfile);
+}
+
+/***********************************************************************
+ *		AVIStreamAddRef		(AVIFIL32.@)
+ */
+ULONG WINAPI AVIStreamAddRef(PAVISTREAM pstream)
+{
+  TRACE("(%p)\n", pstream);
+
+  if (pstream == NULL) {
+    ERR(": bad handle passed!\n");
+    return 0;
+  }
+
+  return IAVIStream_AddRef(pstream);
+}
+
+/***********************************************************************
+ *		AVIStreamRelease	(AVIFIL32.@)
+ */
+ULONG WINAPI AVIStreamRelease(PAVISTREAM pstream)
+{
+  TRACE("(%p)\n", pstream);
+
+  if (pstream == NULL) {
+    ERR(": bad handle passed!\n");
+    return 0;
+  }
+
+  return IAVIStream_Release(pstream);
+}
+
+HRESULT WINAPI AVIStreamCreate(PAVISTREAM *ppavi, LONG lParam1, LONG lParam2,
+			       LPCLSID pclsidHandler)
+{
+  HRESULT hr;
+
+  TRACE("(%p,0x%08lX,0x%08lX,%s)\n", ppavi, lParam1, lParam2,
+	debugstr_guid(pclsidHandler));
+
+  if (ppavi == NULL)
+    return AVIERR_BADPARAM;
+
+  *ppavi = NULL;
+  if (pclsidHandler == NULL)
+    return AVIERR_UNSUPPORTED;
+
+  hr = SHCoCreateInstance(NULL, pclsidHandler, NULL,
+			  &IID_IAVIStream, (LPVOID*)ppavi);
+  if (FAILED(hr) || *ppavi == NULL)
+    return hr;
+
+  hr = IAVIStream_Create(*ppavi, lParam1, lParam2);
+  if (FAILED(hr)) {
+    IAVIStream_Release(*ppavi);
+    *ppavi = NULL;
+  }
+
+  return hr;
+}
+
+/***********************************************************************
+ *		AVIStreamInfoA		(AVIFIL32.@)
+ */
+HRESULT WINAPI AVIStreamInfoA(PAVISTREAM pstream, LPAVISTREAMINFOA asi,
+			      LONG size)
+{
+  AVISTREAMINFOW asiw;
+  HRESULT	 hres;
+
+  TRACE("(%p,%p,%ld)\n", pstream, asi, size);
+
+  if (pstream == NULL)
+    return AVIERR_BADHANDLE;
+  if (size < sizeof(AVISTREAMINFOA))
+    return AVIERR_BADSIZE;
+
+  hres = IAVIStream_Info(pstream, &asiw, sizeof(asiw));
+
+  memcpy(asi, &asiw, sizeof(asiw) - sizeof(asiw.szName));
+  WideCharToMultiByte(CP_ACP, 0, asiw.szName, -1, asi->szName,
+		      sizeof(asi->szName), NULL, NULL);
+  asi->szName[sizeof(asi->szName) - 1] = 0;
+
+  return hres;
+}
+
+/***********************************************************************
+ *		AVIStreamInfoW		(AVIFIL32.@)
+ */
+HRESULT WINAPI AVIStreamInfoW(PAVISTREAM pstream, LPAVISTREAMINFOW asi,
+			      LONG size)
+{
+  TRACE("(%p,%p,%ld)\n", pstream, asi, size);
+
+  if (pstream == NULL)
+    return AVIERR_BADHANDLE;
+
+  return IAVIStream_Info(pstream, asi, size);
+}
+
+/***********************************************************************
+ *		AVIStreamFindSample	(AVIFIL32.@)
+ */
+HRESULT WINAPI AVIStreamFindSample(PAVISTREAM pstream, LONG pos, DWORD flags)
+{
+  TRACE("(%p,%ld,0x%lX)\n", pstream, pos, flags);
+
+  if (pstream == NULL)
+    return -1;
+
+  return IAVIStream_FindSample(pstream, pos, flags);
+}
+
+/***********************************************************************
+ *		AVIStreamReadFormat	(AVIFIL32.@)
+ */
+HRESULT WINAPI AVIStreamReadFormat(PAVISTREAM pstream, LONG pos,
+				   LPVOID format, LPLONG formatsize)
+{
+  TRACE("(%p,%ld,%p,%p)\n", pstream, pos, format, formatsize);
+
+  if (pstream == NULL)
+    return AVIERR_BADHANDLE;
+
+  return IAVIStream_ReadFormat(pstream, pos, format, formatsize);
+}
+
+/***********************************************************************
+ *		AVIStreamSetFormat	(AVIFIL32.@)
+ */
+HRESULT WINAPI AVIStreamSetFormat(PAVISTREAM pstream, LONG pos,
+				  LPVOID format, LONG formatsize)
+{
+  TRACE("(%p,%ld,%p,%ld)\n", pstream, pos, format, formatsize);
+
+  if (pstream == NULL)
+    return AVIERR_BADHANDLE;
+
+  return IAVIStream_SetFormat(pstream, pos, format, formatsize);
+}
+
+/***********************************************************************
+ *		AVIStreamRead		(AVIFIL32.@)
+ */
+HRESULT WINAPI AVIStreamRead(PAVISTREAM pstream, LONG start, LONG samples,
+			     LPVOID buffer, LONG buffersize,
+			     LPLONG bytesread, LPLONG samplesread)
+{
+  TRACE("(%p,%ld,%ld,%p,%ld,%p,%p)\n", pstream, start, samples, buffer,
+	buffersize, bytesread, samplesread);
+
+  if (pstream == NULL)
+    return AVIERR_BADHANDLE;
+
+  return IAVIStream_Read(pstream, start, samples, buffer, buffersize,
+			 bytesread, samplesread);
+}
+
+/***********************************************************************
+ *		AVIStreamWrite		(AVIFIL32.@)
+ */
+HRESULT WINAPI AVIStreamWrite(PAVISTREAM pstream, LONG start, LONG samples,
+			      LPVOID buffer, LONG buffersize, DWORD flags,
+			      LPLONG sampwritten, LPLONG byteswritten)
+{
+  TRACE("(%p,%ld,%ld,%p,%ld,0x%lX,%p,%p)\n", pstream, start, samples, buffer,
+	buffersize, flags, sampwritten, byteswritten);
+
+  if (pstream == NULL)
+    return AVIERR_BADHANDLE;
+
+  return IAVIStream_Write(pstream, start, samples, buffer, buffersize,
+			  flags, sampwritten, byteswritten);
+}
+
+/***********************************************************************
+ *		AVIStreamReadData	(AVIFIL32.@)
+ */
+HRESULT WINAPI AVIStreamReadData(PAVISTREAM pstream, DWORD fcc, LPVOID lp,
+				 LPLONG lpread)
+{
+  TRACE("(%p,'%4.4s',%p,%p)\n", pstream, (char*)&fcc, lp, lpread);
+
+  if (pstream == NULL)
+    return AVIERR_BADHANDLE;
+
+  return IAVIStream_ReadData(pstream, fcc, lp, lpread);
+}
+
+/***********************************************************************
+ *		AVIStreamWriteData	(AVIFIL32.@)
+ */
+HRESULT WINAPI AVIStreamWriteData(PAVISTREAM pstream, DWORD fcc, LPVOID lp,
+				  LONG size)
+{
+  TRACE("(%p,'%4.4s',%p,%ld)\n", pstream, (char*)&fcc, lp, size);
+
+  if (pstream == NULL)
+    return AVIERR_BADHANDLE;
+
+  return IAVIStream_WriteData(pstream, fcc, lp, size);
+}
+
+/***********************************************************************
+ *		AVIStreamGetFrameOpen	(AVIFIL32.@)
+ */
+PGETFRAME WINAPI AVIStreamGetFrameOpen(PAVISTREAM pstream,
+				       LPBITMAPINFOHEADER lpbiWanted)
+{
+  PGETFRAME pg = NULL;
+
+  TRACE("(%p,%p)\n", pstream, lpbiWanted);
+
+  if (FAILED(IAVIStream_QueryInterface(pstream, &IID_IGetFrame, (LPVOID*)&pg)) ||
+      pg == NULL) {
+    FIXME(": need internal class for IGetFrame!\n");
+    return NULL;
+  }
+
+  if (FAILED(IGetFrame_SetFormat(pg, lpbiWanted, NULL, 0, 0, -1, -1))) {
+    IGetFrame_Release(pg);
+    return NULL;
+  }
+
+  return pg;
+}
+
+/***********************************************************************
+ *		AVIStreamGetFrame	(AVIFIL32.@)
+ */
+LPVOID WINAPI AVIStreamGetFrame(PGETFRAME pg, LONG pos)
+{
+  TRACE("(%p,%ld)\n", pg, pos);
+
+  if (pg == NULL)
+    return NULL;
+
+  return IGetFrame_GetFrame(pg, pos);
+}
+
+/***********************************************************************
+ *		AVIStreamGetFrameClose (AVIFIL32.@)
+ */
+HRESULT WINAPI AVIStreamGetFrameClose(PGETFRAME pg)
+{
+  TRACE("(%p)\n", pg);
+
+  if (pg != NULL)
+    return IGetFrame_Release(pg);
+  return 0;
+}
+
+/***********************************************************************
+ *		AVIMakeCompressedStream	(AVIFIL32.@)
+ */
+HRESULT WINAPI AVIMakeCompressedStream(PAVISTREAM *ppsCompressed,
+				       PAVISTREAM psSource,
+				       LPAVICOMPRESSOPTIONS aco,
+				       LPCLSID pclsidHandler)
+{
+  AVISTREAMINFOW asiw;
+  CHAR           szRegKey[25];
+  CHAR           szValue[100];
+  CLSID          clsidHandler;
+  HRESULT        hr;
+  LONG           size = sizeof(szValue);
+
+  TRACE("(%p,%p,%p,%s)\n", ppsCompressed, psSource, aco,
+	debugstr_guid(pclsidHandler));
+
+  if (ppsCompressed == NULL)
+    return AVIERR_BADPARAM;
+  if (psSource == NULL)
+    return AVIERR_BADHANDLE;
+
+  *ppsCompressed = NULL;
+
+  /* if no handler given get default ones based on streamtype */
+  if (pclsidHandler == NULL) {
+    hr = IAVIStream_Info(psSource, &asiw, sizeof(asiw));
+    if (FAILED(hr))
+      return hr;
+
+    wsprintfA(szRegKey, "AVIFile\\Compressors\\%4.4s", (char*)&asiw.fccHandler);
+    if (RegQueryValueA(HKEY_CLASSES_ROOT, szRegKey, szValue, &size) != ERROR_SUCCESS)
+      return AVIERR_UNSUPPORTED;
+    if (AVIFILE_CLSIDFromString(szValue, &clsidHandler) != S_OK)
+      return AVIERR_UNSUPPORTED;
+  } else
+    memcpy(&clsidHandler, pclsidHandler, sizeof(clsidHandler));
+
+  hr = SHCoCreateInstance(NULL, &clsidHandler, NULL,
+			  &IID_IAVIStream, (LPVOID*)ppsCompressed);
+  if (FAILED(hr) || *ppsCompressed == NULL)
+    return hr;
+
+  hr = IAVIStream_Create(*ppsCompressed, (LPARAM)psSource, (LPARAM)aco);
+  if (FAILED(hr)) {
+    IAVIStream_Release(*ppsCompressed);
+    *ppsCompressed = NULL;
+  }
+
+  return hr;
+}
+
+/***********************************************************************
+ *		AVIStreamOpenFromFileA	(AVIFIL32.@)
+ */
+HRESULT WINAPI AVIStreamOpenFromFileA(PAVISTREAM *ppavi, LPCSTR szFile,
+				      DWORD fccType, LONG lParam,
+				      UINT mode, LPCLSID pclsidHandler)
+{
+  PAVIFILE pfile = NULL;
+  HRESULT  hr;
+
+  TRACE("(%p,%s,'%4.4s',%ld,0x%X,%s)\n", ppavi, debugstr_a(szFile),
+	(char*)&fccType, lParam, mode, debugstr_guid(pclsidHandler));
+
+  if (ppavi == NULL || szFile == NULL)
+    return AVIERR_BADPARAM;
+
+  *ppavi = NULL;
+
+  hr = AVIFileOpenA(&pfile, szFile, mode, pclsidHandler);
+  if (FAILED(hr) || pfile == NULL)
+    return hr;
+
+  hr = IAVIFile_GetStream(pfile, ppavi, fccType, lParam);
+  IAVIFile_Release(pfile);
+
+  return hr;
+}
+
+/***********************************************************************
+ *		AVIStreamOpenFromFileW	(AVIFIL32.@)
+ */
+HRESULT WINAPI AVIStreamOpenFromFileW(PAVISTREAM *ppavi, LPCWSTR szFile,
+				      DWORD fccType, LONG lParam,
+				      UINT mode, LPCLSID pclsidHandler)
+{
+  PAVIFILE pfile = NULL;
+  HRESULT  hr;
+
+  TRACE("(%p,%s,'%4.4s',%ld,0x%X,%s)\n", ppavi, debugstr_w(szFile),
+	(char*)&fccType, lParam, mode, debugstr_guid(pclsidHandler));
+
+  if (ppavi == NULL || szFile == NULL)
+    return AVIERR_BADPARAM;
+
+  *ppavi = NULL;
+
+  hr = AVIFileOpenW(&pfile, szFile, mode, pclsidHandler);
+  if (FAILED(hr) || pfile == NULL)
+    return hr;
+
+  hr = IAVIFile_GetStream(pfile, ppavi, fccType, lParam);
+  IAVIFile_Release(pfile);
+
+  return hr;
+}
+
+/***********************************************************************
+ *		AVIStreamStart		(AVIFIL32.@)
+ */
+LONG WINAPI AVIStreamStart(PAVISTREAM pstream)
+{
+  AVISTREAMINFOW asiw;
+
+  TRACE("(%p)\n", pstream);
+
+  if (pstream == NULL)
+    return 0;
+
+  if (FAILED(IAVIStream_Info(pstream, &asiw, sizeof(asiw))))
+    return 0;
+
+  return asiw.dwLength;
+}
+
+/***********************************************************************
+ *		AVIStreamLength		(AVIFIL32.@)
+ */
+LONG WINAPI AVIStreamLength(PAVISTREAM pstream)
+{
+  AVISTREAMINFOW asiw;
+
+  TRACE("(%p)\n", pstream);
+
+  if (pstream == NULL)
+    return 0;
+
+  if (FAILED(IAVIStream_Info(pstream, &asiw, sizeof(asiw))))
+    return 0;
+
+  return asiw.dwLength;
+}
+
+/***********************************************************************
+ *		AVIStreamSampleToTime	(AVIFIL32.@)
+ */
+LONG WINAPI AVIStreamSampleToTime(PAVISTREAM pstream, LONG lSample)
+{
+  AVISTREAMINFOW asiw;
+
+  TRACE("(%p,%ld)\n", pstream, lSample);
+
+  if (pstream == NULL)
+    return -1;
+
+  if (FAILED(IAVIStream_Info(pstream, &asiw, sizeof(asiw))))
+    return -1;
+  if (asiw.dwRate == 0)
+    return -1;
+
+  return (LONG)(((float)lSample * asiw.dwScale * 1000.0) / asiw.dwRate);
+}
+
+/***********************************************************************
+ *		AVIStreamTimeToSample	(AVIFIL32.@)
+ */
+LONG WINAPI AVIStreamTimeToSample(PAVISTREAM pstream, LONG lTime)
+{
+  AVISTREAMINFOW asiw;
+
+  TRACE("(%p,%ld)\n", pstream, lTime);
+
+  if (pstream == NULL)
+    return -1;
+
+  if (FAILED(IAVIStream_Info(pstream, &asiw, sizeof(asiw))))
+    return -1;
+  if (asiw.dwScale == 0)
+    return -1;
+
+  return (LONG)(((float)lTime * asiw.dwRate) / asiw.dwScale / 1000.0);
+}
+


  Michael Günnewig

[Index of Archives]     [Gimp for Windows]     [Red Hat]     [Samba]     [Yosemite Camping]     [Graphics Cards]     [Wine Home]

  Powered by Linux