2 * Copyright 1999 Marcus Meissner
10 #include "wine/winestring.h"
14 #include "debugtools.h"
16 DEFAULT_DEBUG_CHANNEL(avifile);
18 static HRESULT WINAPI IAVIFile_fnQueryInterface(IAVIFile* iface,REFIID refiid,LPVOID *obj);
19 static ULONG WINAPI IAVIFile_fnAddRef(IAVIFile* iface);
20 static ULONG WINAPI IAVIFile_fnRelease(IAVIFile* iface);
21 static HRESULT WINAPI IAVIFile_fnInfo(IAVIFile*iface,AVIFILEINFOW*afi,LONG size);
22 static HRESULT WINAPI IAVIFile_fnGetStream(IAVIFile*iface,PAVISTREAM*avis,DWORD fccType,LONG lParam);
23 static HRESULT WINAPI IAVIFile_fnCreateStream(IAVIFile*iface,PAVISTREAM*avis,AVISTREAMINFOW*asi);
24 static HRESULT WINAPI IAVIFile_fnWriteData(IAVIFile*iface,DWORD ckid,LPVOID lpData,LONG size);
25 static HRESULT WINAPI IAVIFile_fnReadData(IAVIFile*iface,DWORD ckid,LPVOID lpData,LONG *size);
26 static HRESULT WINAPI IAVIFile_fnEndRecord(IAVIFile*iface);
27 static HRESULT WINAPI IAVIFile_fnDeleteStream(IAVIFile*iface,DWORD fccType,LONG lParam);
29 struct ICOM_VTABLE(IAVIFile) iavift = {
30 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
31 IAVIFile_fnQueryInterface,
36 IAVIFile_fnCreateStream,
40 IAVIFile_fnDeleteStream
43 static HRESULT WINAPI IAVIStream_fnQueryInterface(IAVIStream*iface,REFIID refiid,LPVOID *obj);
44 static ULONG WINAPI IAVIStream_fnAddRef(IAVIStream*iface);
45 static ULONG WINAPI IAVIStream_fnRelease(IAVIStream* iface);
46 static HRESULT WINAPI IAVIStream_fnCreate(IAVIStream*iface,LPARAM lParam1,LPARAM lParam2);
47 static HRESULT WINAPI IAVIStream_fnInfo(IAVIStream*iface,AVISTREAMINFOW *psi,LONG size);
48 static LONG WINAPI IAVIStream_fnFindSample(IAVIStream*iface,LONG pos,LONG flags);
49 static HRESULT WINAPI IAVIStream_fnReadFormat(IAVIStream*iface,LONG pos,LPVOID format,LONG *formatsize);
50 static HRESULT WINAPI IAVIStream_fnSetFormat(IAVIStream*iface,LONG pos,LPVOID format,LONG formatsize);
51 static HRESULT WINAPI IAVIStream_fnRead(IAVIStream*iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,LONG *bytesread,LONG *samplesread);
52 static HRESULT WINAPI IAVIStream_fnWrite(IAVIStream*iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,DWORD flags,LONG *sampwritten,LONG *byteswritten);
53 static HRESULT WINAPI IAVIStream_fnDelete(IAVIStream*iface,LONG start,LONG samples);
54 static HRESULT WINAPI IAVIStream_fnReadData(IAVIStream*iface,DWORD fcc,LPVOID lp,LONG *lpread);
55 static HRESULT WINAPI IAVIStream_fnWriteData(IAVIStream*iface,DWORD fcc,LPVOID lp,LONG size);
56 static HRESULT WINAPI IAVIStream_fnSetInfo(IAVIStream*iface,AVISTREAMINFOW*info,LONG infolen);
58 struct ICOM_VTABLE(IAVIStream) iavist = {
59 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
60 IAVIStream_fnQueryInterface,
65 IAVIStream_fnFindSample,
66 IAVIStream_fnReadFormat,
67 IAVIStream_fnSetFormat,
71 IAVIStream_fnReadData,
72 IAVIStream_fnWriteData,
76 typedef struct IAVIStreamImpl {
78 ICOM_VFIELD(IAVIStream);
80 /* IAVIStream stuff */
82 DWORD inputformatsize;
86 /* Compressor stuff */
88 LPVOID lpCompressFormat;
96 AVICOMPRESSOPTIONS aco;
98 LPVOID lpPrev; /* pointer to decompressed frame later */
99 LPVOID lpPrevFormat; /* pointer to decompressed info later */
102 /***********************************************************************
110 typedef struct IAVIFileImpl {
112 ICOM_VFIELD(IAVIFile);
114 /* IAVIFile stuff... */
117 static HRESULT WINAPI IAVIFile_fnQueryInterface(IAVIFile* iface,REFIID refiid,LPVOID *obj) {
118 ICOM_THIS(IAVIFileImpl,iface);
120 TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(refiid),obj);
121 if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
122 !memcmp(&IID_IAVIFile,refiid,sizeof(IID_IAVIFile))
127 return OLE_E_ENUM_NOMORE;
130 static ULONG WINAPI IAVIFile_fnAddRef(IAVIFile* iface) {
131 ICOM_THIS(IAVIFileImpl,iface);
133 FIXME("(%p)->AddRef()\n",iface);
134 return ++(This->ref);
137 static ULONG WINAPI IAVIFile_fnRelease(IAVIFile* iface) {
138 ICOM_THIS(IAVIFileImpl,iface);
140 FIXME("(%p)->Release()\n",iface);
141 if (!--(This->ref)) {
142 HeapFree(GetProcessHeap(),0,iface);
148 static HRESULT WINAPI IAVIFile_fnInfo(IAVIFile*iface,AVIFILEINFOW*afi,LONG size) {
149 FIXME("(%p)->Info(%p,%ld)\n",iface,afi,size);
151 /* FIXME: fill out struct? */
155 static HRESULT WINAPI IAVIFile_fnGetStream(IAVIFile*iface,PAVISTREAM*avis,DWORD fccType,LONG lParam) {
156 FIXME("(%p)->GetStream(%p,0x%08lx,%ld)\n",iface,avis,fccType,lParam);
157 /* FIXME: create interface etc. */
161 static HRESULT WINAPI IAVIFile_fnCreateStream(IAVIFile*iface,PAVISTREAM*avis,AVISTREAMINFOW*asi) {
162 ICOM_THIS(IAVIStreamImpl,iface);
164 IAVIStreamImpl *istream;
166 FIXME("(%p,%p,%p)\n",This,avis,asi);
167 istream = (IAVIStreamImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IAVIStreamImpl));
169 ICOM_VTBL(istream) = &iavist;
171 memcpy(fcc,(char*)&(asi->fccType),4);
172 FIXME("\tfccType '%s'\n",fcc);
173 memcpy(fcc,(char*)&(asi->fccHandler),4);
174 FIXME("\tfccHandler '%s'\n",fcc);
175 FIXME("\tdwFlags 0x%08lx\n",asi->dwFlags);
176 FIXME("\tdwCaps 0x%08lx\n",asi->dwCaps);
177 FIXME("\tname '%s'\n",debugstr_w(asi->szName));
179 istream->curframe = 0;
180 *avis = (PAVISTREAM)istream;
184 static HRESULT WINAPI IAVIFile_fnWriteData(IAVIFile*iface,DWORD ckid,LPVOID lpData,LONG size) {
185 FIXME("(%p)->WriteData(0x%08lx,%p,%ld)\n",iface,ckid,lpData,size);
186 /* FIXME: write data to file */
190 static HRESULT WINAPI IAVIFile_fnReadData(IAVIFile*iface,DWORD ckid,LPVOID lpData,LONG *size) {
191 FIXME("(%p)->ReadData(0x%08lx,%p,%p)\n",iface,ckid,lpData,size);
192 /* FIXME: read at most size bytes from file */
196 static HRESULT WINAPI IAVIFile_fnEndRecord(IAVIFile*iface) {
197 FIXME("(%p)->EndRecord()\n",iface);
198 /* FIXME: end record? */
202 static HRESULT WINAPI IAVIFile_fnDeleteStream(IAVIFile*iface,DWORD fccType,LONG lParam) {
203 FIXME("(%p)->DeleteStream(0x%08lx,%ld)\n",iface,fccType,lParam);
204 /* FIXME: delete stream? */
208 /***********************************************************************
211 HRESULT WINAPI AVIFileOpenA(
212 PAVIFILE * ppfile,LPCSTR szFile,UINT uMode,LPCLSID lpHandler
216 FIXME("(%p,%s,0x%08lx,%s),stub!\n",ppfile,szFile,(DWORD)uMode,debugstr_guid(lpHandler));
217 iavi = (IAVIFileImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(IAVIFileImpl));
219 ICOM_VTBL(iavi) = &iavift;
220 *ppfile = (LPVOID)iavi;
224 static HRESULT WINAPI IAVIStream_fnQueryInterface(IAVIStream*iface,REFIID refiid,LPVOID *obj) {
225 ICOM_THIS(IAVIStreamImpl,iface);
227 TRACE("(%p)->QueryInterface(%s,%p)\n",This,debugstr_guid(refiid),obj);
228 if ( !memcmp(&IID_IUnknown,refiid,sizeof(IID_IUnknown)) ||
229 !memcmp(&IID_IAVIStream,refiid,sizeof(IID_IAVIStream))
234 /* can return IGetFrame interface too */
235 return OLE_E_ENUM_NOMORE;
238 static ULONG WINAPI IAVIStream_fnAddRef(IAVIStream*iface) {
239 ICOM_THIS(IAVIStreamImpl,iface);
241 FIXME("(%p)->AddRef()\n",iface);
242 return ++(This->ref);
245 static ULONG WINAPI IAVIStream_fnRelease(IAVIStream* iface) {
246 ICOM_THIS(IAVIStreamImpl,iface);
248 FIXME("(%p)->Release()\n",iface);
249 if (!--(This->ref)) {
250 HeapFree(GetProcessHeap(),0,This);
256 static HRESULT WINAPI IAVIStream_fnCreate(IAVIStream*iface,LPARAM lParam1,LPARAM lParam2) {
257 FIXME("(%p)->Create(0x%08lx,0x%08lx)\n",iface,lParam1,lParam2);
261 static HRESULT WINAPI IAVIStream_fnInfo(IAVIStream*iface,AVISTREAMINFOW *psi,LONG size) {
262 FIXME("(%p)->Info(%p,%ld)\n",iface,psi,size);
266 static LONG WINAPI IAVIStream_fnFindSample(IAVIStream*iface,LONG pos,LONG flags) {
267 FIXME("(%p)->FindSample(%ld,0x%08lx)\n",iface,pos,flags);
271 static HRESULT WINAPI IAVIStream_fnReadFormat(IAVIStream*iface,LONG pos,LPVOID format,LONG *formatsize) {
272 FIXME("(%p)->ReadFormat(%ld,%p,%p)\n",iface,pos,format,formatsize);
276 /***********************************************************************
277 * IAVIStream::SetFormat
279 static HRESULT WINAPI IAVIStream_fnSetFormat(IAVIStream*iface,LONG pos,LPVOID format,LONG formatsize) {
280 IAVIStreamImpl *as = (IAVIStreamImpl*)iface;
282 FIXME("(%p)->SetFormat(%ld,%p,%ld)\n",iface,pos,format,formatsize);
283 if (as->lpInputFormat) HeapFree(GetProcessHeap(),0,as->lpInputFormat);
284 as->inputformatsize = formatsize;
285 as->lpInputFormat = HeapAlloc(GetProcessHeap(),0,formatsize);
286 memcpy(as->lpInputFormat,format,formatsize);
287 if (as->iscompressing) {
289 /* Set up the Compressor part */
290 xsize = ICCompressGetFormatSize(as->hic,as->lpInputFormat);
291 as->lpCompressFormat = HeapAlloc(GetProcessHeap(),0,xsize);
292 ICCompressGetFormat(as->hic,as->lpInputFormat,as->lpCompressFormat);
293 ICCompressBegin(as->hic,as->lpInputFormat,as->lpCompressFormat);
294 as->compbufsize = ICCompressGetSize(as->hic,as->lpInputFormat,as->lpCompressFormat);
295 as->compbuffer = HeapAlloc(GetProcessHeap(),0,as->compbufsize);
297 /* Set up the Decompressor part (for prev frames?) */
298 xsize=ICDecompressGetFormatSize(as->hic,as->lpCompressFormat);
299 as->decompformat = HeapAlloc(GetProcessHeap(),0,xsize);
300 ICDecompressGetFormat(as->hic,as->lpCompressFormat,as->decompformat);
301 as->decompbufsize=((LPBITMAPINFOHEADER)as->decompbuffer)->biSizeImage;
302 as->decompbuffer = HeapReAlloc(GetProcessHeap(),0,as->decompbuffer,as->decompbufsize);
303 memset(as->decompbuffer,0xff,as->decompbufsize);
304 assert(HeapValidate(GetProcessHeap(),0,NULL));
306 ICDecompressGetFormat(as->hic,as->lpCompressFormat,as->decompformat);
307 ICDecompressBegin(as->hic,as->lpCompressFormat,as->decompformat);
308 as->lpPrev = as->lpPrevFormat = NULL;
313 static HRESULT WINAPI IAVIStream_fnRead(IAVIStream*iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,LONG *bytesread,LONG *samplesread) {
314 FIXME("(%p)->Read(%ld,%ld,%p,%ld,%p,%p)\n",iface,start,samples,buffer,buffersize,bytesread,samplesread);
318 static HRESULT WINAPI IAVIStream_fnWrite(IAVIStream*iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,DWORD flags,LONG *sampwritten,LONG *byteswritten) {
319 IAVIStreamImpl *as = (IAVIStreamImpl*)iface;
322 FIXME("(%p)->Write(%ld,%ld,%p,%ld,0x%08lx,%p,%p)\n",iface,start,samples,buffer,buffersize,flags,sampwritten,byteswritten);
326 as->lpCompressFormat,
328 as->lpInputFormat,buffer,
330 as->curframe,0xffffff/*framesize*/,as->aco.dwQuality,
331 as->lpPrevFormat,as->lpPrev
335 flags, /* FIXME: check */
336 as->lpCompressFormat,
341 /* We now have a prev format for the next compress ... */
342 as->lpPrevFormat = as->decompformat;
343 as->lpPrev = as->decompbuffer;
347 static HRESULT WINAPI IAVIStream_fnDelete(IAVIStream*iface,LONG start,LONG samples) {
348 FIXME("(%p)->Delete(%ld,%ld)\n",iface,start,samples);
351 static HRESULT WINAPI IAVIStream_fnReadData(IAVIStream*iface,DWORD fcc,LPVOID lp,LONG *lpread) {
352 FIXME("(%p)->ReadData(0x%08lx,%p,%p)\n",iface,fcc,lp,lpread);
356 static HRESULT WINAPI IAVIStream_fnWriteData(IAVIStream*iface,DWORD fcc,LPVOID lp,LONG size) {
357 FIXME("(%p)->WriteData(0x%08lx,%p,%ld)\n",iface,fcc,lp,size);
361 static HRESULT WINAPI IAVIStream_fnSetInfo(IAVIStream*iface,AVISTREAMINFOW*info,LONG infolen) {
362 FIXME("(%p)->SetInfo(%p,%ld)\n",iface,info,infolen);
366 /***********************************************************************
367 * AVIFileCreateStreamA
369 HRESULT WINAPI AVIFileCreateStreamA(PAVIFILE iface,PAVISTREAM *ppavi,AVISTREAMINFOA * psi) {
372 /* Only the szName at the end is different */
373 memcpy(&psiw,psi,sizeof(*psi)-sizeof(psi->szName));
374 lstrcpynAtoW(psiw.szName,psi->szName,sizeof(psi->szName));
375 return IAVIFile_CreateStream(iface,ppavi,&psiw);
378 /***********************************************************************
379 * AVIFileCreateStreamW
381 HRESULT WINAPI AVIFileCreateStreamW(IAVIFile*iface,PAVISTREAM*avis,AVISTREAMINFOW*asi) {
382 return IAVIFile_CreateStream(iface,avis,asi);
386 /***********************************************************************
389 HRESULT WINAPI AVIFileGetStream(IAVIFile*iface,PAVISTREAM*avis,DWORD fccType,LONG lParam) {
390 return IAVIFile_GetStream(iface,avis,fccType,lParam);
393 /***********************************************************************
396 HRESULT WINAPI AVIFileInfoA(PAVIFILE iface,LPAVIFILEINFOA afi,LONG size) {
400 if (size < sizeof(AVIFILEINFOA))
401 return AVIERR_BADSIZE;
402 hres = IAVIFile_Info(iface,&afiw,sizeof(afiw));
403 memcpy(afi,&afiw,sizeof(*afi)-sizeof(afi->szFileType));
404 lstrcpynWtoA(afi->szFileType,afiw.szFileType,sizeof(afi->szFileType));
408 /***********************************************************************
411 HRESULT WINAPI AVIStreamInfoW(PAVISTREAM iface,AVISTREAMINFOW *asi,LONG
413 return IAVIFile_Info(iface,asi,size);
416 /***********************************************************************
419 HRESULT WINAPI AVIStreamInfoA(PAVISTREAM iface,AVISTREAMINFOA *asi,LONG
424 if (size<sizeof(AVISTREAMINFOA))
425 return AVIERR_BADSIZE;
426 hres = IAVIFile_Info(iface,&asiw,sizeof(asiw));
427 memcpy(asi,&asiw,sizeof(asiw)-sizeof(asiw.szName));
428 lstrcpynWtoA(asi->szName,asiw.szName,sizeof(asi->szName));
432 /***********************************************************************
435 HRESULT WINAPI AVIFileInfoW(PAVIFILE iface,LPAVIFILEINFOW afi,LONG size) {
436 return IAVIFile_Info(iface,afi,size);
439 /***********************************************************************
440 * AVIMakeCompressedStream
442 HRESULT WINAPI AVIMakeCompressedStream(PAVISTREAM *ppsCompressed,PAVISTREAM ppsSource,AVICOMPRESSOPTIONS *aco,CLSID *pclsidHandler) {
445 FIXME("(%p,%p,%p,%p)\n",ppsCompressed,ppsSource,aco,pclsidHandler);
447 memcpy(fcc,&(aco->fccType),4);
448 FIXME("\tfccType: '%s'\n",fcc);
449 memcpy(fcc,&(aco->fccHandler),4);
450 FIXME("\tfccHandler: '%s'\n",fcc);
451 FIXME("\tdwFlags: 0x%08lx\n",aco->dwFlags);
453 /* we just create a duplicate for now */
454 IAVIStream_AddRef(ppsSource);
455 *ppsCompressed = ppsSource;
456 as = (IAVIStreamImpl*)ppsSource;
458 /* this is where the fun begins. Open a compressor and prepare it. */
459 as->hic = ICOpen(aco->fccType,aco->fccHandler,ICMODE_COMPRESS);
461 /* May happen. for instance if the codec is not able to compress */
463 return AVIERR_UNSUPPORTED;
465 ICGetInfo(as->hic,&(as->icinfo),sizeof(ICINFO));
466 FIXME("Opened compressor: '%s' '%s'\n",debugstr_w(as->icinfo.szName),debugstr_w(as->icinfo.szDescription));
467 as->iscompressing = TRUE;
468 memcpy(&(as->aco),aco,sizeof(*aco));
469 if (as->icinfo.dwFlags & VIDCF_COMPRESSFRAMES) {
470 ICCOMPRESSFRAMES icf;
472 /* now what to fill in there ... Hmm */
473 memset(&icf,0,sizeof(icf));
474 icf.lDataRate = aco->dwBytesPerSecond;
475 icf.lQuality = aco->dwQuality;
476 icf.lKeyRate = aco->dwKeyFrameEvery;
478 icf.GetData = (LONG (*)(LPARAM,LONG,LPVOID,LONG)) 0xdead4242;
479 icf.PutData = (LONG (*)(LPARAM,LONG,LPVOID,LONG)) 0xdead4243;
480 ICSendMessage(as->hic,ICM_COMPRESS_FRAMES_INFO,(LPARAM)&icf,sizeof(icf));
485 /***********************************************************************
488 HRESULT WINAPI AVIStreamSetFormat(PAVISTREAM iface,LONG pos,LPVOID format,LONG formatsize) {
489 return IAVIStream_SetFormat(iface,pos,format,formatsize);
492 /***********************************************************************
493 * AVIStreamReadFormat
495 HRESULT WINAPI AVIStreamReadFormat(PAVISTREAM iface,LONG pos,LPVOID format,LONG *formatsize) {
496 return IAVIStream_ReadFormat(iface,pos,format,formatsize);
499 /***********************************************************************
502 HRESULT WINAPI AVIStreamWrite(PAVISTREAM iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,DWORD flags,LONG *sampwritten,LONG *byteswritten) {
503 return IAVIStream_Write(iface,start,samples,buffer,buffersize,flags,sampwritten,byteswritten);
506 /***********************************************************************
509 HRESULT WINAPI AVIStreamRead(PAVISTREAM iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,LONG *bytesread,LONG *samplesread) {
510 return IAVIStream_Read(iface,start,samples,buffer,buffersize,bytesread,samplesread);
513 /***********************************************************************
516 HRESULT WINAPI AVIStreamWriteData(PAVISTREAM iface,DWORD fcc,LPVOID lp,LONG size) {
517 return IAVIStream_WriteData(iface,fcc,lp,size);
520 /***********************************************************************
523 HRESULT WINAPI AVIStreamReadData(PAVISTREAM iface,DWORD fcc,LPVOID lp,LONG *lpread) {
524 return IAVIStream_ReadData(iface,fcc,lp,lpread);
527 /***********************************************************************
530 LONG WINAPI AVIStreamStart(PAVISTREAM iface) {
533 IAVIStream_Info(iface,&si,sizeof(si));
537 /***********************************************************************
540 LONG WINAPI AVIStreamLength(PAVISTREAM iface) {
544 ret = IAVIStream_Info(iface,&si,sizeof(si));
550 /***********************************************************************
553 ULONG WINAPI AVIStreamRelease(PAVISTREAM iface) {
554 return IAVIStream_Release(iface);
557 /***********************************************************************
558 * AVIStreamGetFrameOpen
560 PGETFRAME WINAPI AVIStreamGetFrameOpen(PAVISTREAM iface,LPBITMAPINFOHEADER bmi) {
561 FIXME("(%p)->(%p),stub!\n",iface,bmi);
565 /***********************************************************************
568 LPVOID WINAPI AVIStreamGetFrame(PGETFRAME pg,LONG pos) {
569 return IGetFrame_GetFrame(pg,pos);
572 /***********************************************************************
573 * AVIStreamGetFrameClose
575 HRESULT WINAPI AVIStreamGetFrameClose(PGETFRAME pg) {
576 if (pg) IGetFrame_Release(pg);
580 /***********************************************************************
583 ULONG WINAPI AVIFileRelease(PAVIFILE iface) {
584 return IAVIFile_Release(iface);
587 /***********************************************************************
590 void WINAPI AVIFileExit(void) {
591 FIXME("(), stub.\n");