2 * Copyright 1999 Marcus Meissner
3 * Copyright 2001 Hidenori TAKESHIMA <hidenori@a2.ctktv.ne.jp>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(avifile);
34 #include "avifile_private.h"
37 /***********************************************************************
38 * AVIFileInit (AVIFILE.100)
39 * AVIFileInit (AVIFIL32.@)
41 void WINAPI AVIFileInit(void)
44 if ( AVIFILE_data.dwAVIFileRef == 0 )
46 if ( FAILED(CoInitialize(NULL)) )
47 AVIFILE_data.fInitCOM = FALSE;
49 AVIFILE_data.fInitCOM = TRUE;
51 AVIFILE_data.dwAVIFileRef ++;
54 /***********************************************************************
55 * AVIFileExit (AVIFILE.101)
56 * AVIFileExit (AVIFIL32.@)
58 void WINAPI AVIFileExit(void)
61 if ( AVIFILE_data.dwAVIFileRef == 0 )
63 ERR( "unexpected AVIFileExit()\n" );
67 AVIFILE_data.dwAVIFileRef --;
68 if ( AVIFILE_data.dwAVIFileRef == 0 )
70 if ( AVIFILE_data.fInitCOM )
73 AVIFILE_data.fInitCOM = FALSE;
78 /***********************************************************************
79 * AVIFileAddRef (AVIFIL32.@)
81 ULONG WINAPI AVIFileAddRef(PAVIFILE pfile)
83 return IAVIFile_AddRef( pfile );
86 /***********************************************************************
87 * AVIFileRelease (AVIFILE.141)
88 * AVIFileRelease (AVIFIL32.@)
90 ULONG WINAPI AVIFileRelease(PAVIFILE pfile)
92 return IAVIFile_Release( pfile );
95 /***********************************************************************
96 * AVIFileOpen (AVIFILE.102)
97 * AVIFileOpenA (AVIFIL32.@)
99 HRESULT WINAPI AVIFileOpenA(
100 PAVIFILE* ppfile,LPCSTR szFile,UINT uMode,LPCLSID lpHandler )
105 TRACE("(%p,%p,%u,%p)\n",ppfile,szFile,uMode,lpHandler);
106 pwsz = AVIFILE_strdupAtoW( szFile );
108 return AVIERR_MEMORY;
109 hr = AVIFileOpenW(ppfile,pwsz,uMode,lpHandler);
110 HeapFree( AVIFILE_data.hHeap, 0, pwsz );
114 /***********************************************************************
115 * AVIFileOpenW (AVIFIL32.@)
117 HRESULT WINAPI AVIFileOpenW(
118 PAVIFILE* ppfile,LPCWSTR szFile,UINT uMode,LPCLSID lpHandler )
124 TRACE("(%p,%p,%u,%p)\n",ppfile,szFile,uMode,lpHandler);
125 *ppfile = (PAVIFILE)NULL;
127 if ( lpHandler == NULL )
129 /* FIXME - check RIFF type and get a handler from registry
130 * if IAVIFile::Open is worked...
132 memcpy( &clsRIFF, &CLSID_AVIFile, sizeof(CLSID) );
133 lpHandler = &clsRIFF;
137 * FIXME - MS says IAVIFile::Open will be called,
138 * but no such method in vfw.h... why????
140 if ( !IsEqualGUID( lpHandler, &CLSID_AVIFile ) )
141 return REGDB_E_CLASSNOTREG;
143 hr = AVIFILE_DllGetClassObject(&CLSID_AVIFile,
144 &IID_IClassFactory,(void**)&pcf);
148 hr = IClassFactory_CreateInstance( pcf, NULL, &IID_IAVIFile,
150 IClassFactory_Release( pcf );
155 hr = AVIFILE_IAVIFile_Open( *ppfile, szFile, uMode );
158 IAVIFile_Release( (*ppfile) );
166 /***********************************************************************
167 * AVIFileInfoW (AVIFIL32.@)
169 HRESULT WINAPI AVIFileInfoW(PAVIFILE pfile,AVIFILEINFOW* pfi,LONG lSize)
171 return IAVIFile_Info( pfile, pfi, lSize );
174 /***********************************************************************
175 * AVIFileInfo (AVIFIL32.@)
176 * AVIFileInfoA (AVIFIL32.@)
178 HRESULT WINAPI AVIFileInfoA(PAVIFILE pfile,AVIFILEINFOA* pfi,LONG lSize)
183 if ( lSize < sizeof(AVIFILEINFOA) )
184 return AVIERR_BADSIZE;
185 hr = AVIFileInfoW( pfile, &fiw, sizeof(AVIFILEINFOW) );
188 memcpy( pfi,&fiw,sizeof(AVIFILEINFOA) );
189 AVIFILE_strncpyWtoA( pfi->szFileType, fiw.szFileType,
190 sizeof(pfi->szFileType) );
191 pfi->szFileType[sizeof(pfi->szFileType)-1] = 0;
196 /***********************************************************************
197 * AVIFileGetStream (AVIFILE.143)
198 * AVIFileGetStream (AVIFIL32.@)
200 HRESULT WINAPI AVIFileGetStream(PAVIFILE pfile,PAVISTREAM* pas,DWORD fccType,LONG lParam)
202 return IAVIFile_GetStream(pfile,pas,fccType,lParam);
205 /***********************************************************************
206 * AVIFileCreateStreamW (AVIFIL32.@)
208 HRESULT WINAPI AVIFileCreateStreamW(PAVIFILE pfile,PAVISTREAM* ppas,AVISTREAMINFOW* pasi)
210 return IAVIFile_CreateStream(pfile,ppas,pasi);
213 /***********************************************************************
214 * AVIFileCreateStreamA (AVIFIL32.@)
216 HRESULT WINAPI AVIFileCreateStreamA(PAVIFILE pfile,PAVISTREAM* ppas,AVISTREAMINFOA* pasi)
221 memcpy( &siw,pasi,sizeof(AVISTREAMINFOA) );
222 AVIFILE_strncpyAtoW( siw.szName, pasi->szName,
223 sizeof(siw.szName)/sizeof(siw.szName[0]) );
224 siw.szName[sizeof(siw.szName)/sizeof(siw.szName[0])-1] = 0;
226 hr = AVIFileCreateStreamW(pfile,ppas,&siw);
231 /***********************************************************************
232 * AVIFileWriteData (AVIFIL32.@)
234 HRESULT WINAPI AVIFileWriteData(
235 PAVIFILE pfile,DWORD dwChunkId,LPVOID lpvData,LONG cbData )
237 return IAVIFile_WriteData( pfile,dwChunkId,lpvData,cbData );
240 /***********************************************************************
241 * AVIFileReadData (AVIFIL32.@)
243 HRESULT WINAPI AVIFileReadData(
244 PAVIFILE pfile,DWORD dwChunkId,LPVOID lpvData,LPLONG pcbData )
246 return IAVIFile_ReadData( pfile,dwChunkId,lpvData,pcbData );
249 /***********************************************************************
250 * AVIFileEndRecord (AVIFIL32.@)
252 HRESULT WINAPI AVIFileEndRecord( PAVIFILE pfile )
254 return IAVIFile_EndRecord( pfile );
257 /***********************************************************************
258 * AVIStreamAddRef (AVIFIL32.@)
260 ULONG WINAPI AVIStreamAddRef(PAVISTREAM pas)
262 return IAVIStream_Release(pas);
265 /***********************************************************************
266 * AVIStreamRelease (AVIFIL32.@)
268 ULONG WINAPI AVIStreamRelease(PAVISTREAM pas)
270 return IAVIStream_Release(pas);
273 /***********************************************************************
274 * AVIStreamInfoW (AVIFIL32.@)
276 HRESULT WINAPI AVIStreamInfoW(PAVISTREAM pas,AVISTREAMINFOW* psi,LONG lSize)
278 return IAVIStream_Info(pas,psi,lSize);
281 /***********************************************************************
282 * AVIStreamInfo (AVIFIL32.@)
283 * AVIStreamInfoA (AVIFIL32.@)
285 HRESULT WINAPI AVIStreamInfoA(PAVISTREAM pas,AVISTREAMINFOA* psi,LONG lSize)
290 if (lSize < sizeof(AVISTREAMINFOA))
291 return AVIERR_BADSIZE;
292 hr = AVIStreamInfoW(pas,&siw,sizeof(AVISTREAMINFOW));
295 memcpy( psi,&siw,sizeof(AVIFILEINFOA) );
296 AVIFILE_strncpyWtoA( psi->szName, siw.szName, sizeof(psi->szName) );
297 psi->szName[sizeof(psi->szName)-1] = 0;
302 /***********************************************************************
303 * AVIStreamFindSample (AVIFIL32.@)
305 LONG WINAPI AVIStreamFindSample(PAVISTREAM pas,LONG lPos,LONG lFlags)
307 return IAVIStream_FindSample(pas,lPos,lFlags);
310 /***********************************************************************
311 * AVIStreamReadFormat (AVIFIL32.@)
313 HRESULT WINAPI AVIStreamReadFormat(PAVISTREAM pas,LONG pos,LPVOID format,LONG *formatsize) {
314 return IAVIStream_ReadFormat(pas,pos,format,formatsize);
317 /***********************************************************************
318 * AVIStreamSetFormat (AVIFIL32.@)
320 HRESULT WINAPI AVIStreamSetFormat(PAVISTREAM pas,LONG pos,LPVOID format,LONG formatsize) {
321 return IAVIStream_SetFormat(pas,pos,format,formatsize);
324 /***********************************************************************
325 * AVIStreamReadData (AVIFIL32.@)
327 HRESULT WINAPI AVIStreamReadData(PAVISTREAM pas,DWORD fcc,LPVOID lp,LONG *lpread) {
328 return IAVIStream_ReadData(pas,fcc,lp,lpread);
331 /***********************************************************************
332 * AVIStreamWriteData (AVIFIL32.@)
334 HRESULT WINAPI AVIStreamWriteData(PAVISTREAM pas,DWORD fcc,LPVOID lp,LONG size) {
335 return IAVIStream_WriteData(pas,fcc,lp,size);
338 /***********************************************************************
339 * AVIStreamRead (AVIFIL32.@)
341 HRESULT WINAPI AVIStreamRead(PAVISTREAM pas,LONG start,LONG samples,LPVOID buffer,LONG buffersize,LONG *bytesread,LONG *samplesread)
343 return IAVIStream_Read(pas,start,samples,buffer,buffersize,bytesread,samplesread);
346 /***********************************************************************
347 * AVIStreamWrite (AVIFIL32.@)
349 HRESULT WINAPI AVIStreamWrite(PAVISTREAM pas,LONG start,LONG samples,LPVOID buffer,LONG buffersize,DWORD flags,LONG *sampwritten,LONG *byteswritten) {
350 return IAVIStream_Write(pas,start,samples,buffer,buffersize,flags,sampwritten,byteswritten);
354 /***********************************************************************
355 * AVIStreamStart (AVIFIL32.@)
357 LONG WINAPI AVIStreamStart(PAVISTREAM pas)
362 hr = IAVIStream_Info(pas,&si,sizeof(si));
365 return (LONG)si.dwStart;
368 /***********************************************************************
369 * AVIStreamLength (AVIFIL32.@)
371 LONG WINAPI AVIStreamLength(PAVISTREAM pas)
376 hr = IAVIStream_Info(pas,&si,sizeof(si));
379 return (LONG)si.dwLength;
382 /***********************************************************************
383 * AVIStreamTimeToSample (AVIFIL32.@)
385 LONG WINAPI AVIStreamTimeToSample(PAVISTREAM pas,LONG lTime)
390 hr = IAVIStream_Info(pas,&si,sizeof(si));
394 /* I am too lazy... */
395 FIXME("(%p,%ld)",pas,lTime);
399 /***********************************************************************
400 * AVIStreamSampleToTime (AVIFIL32.@)
402 LONG WINAPI AVIStreamSampleToTime(PAVISTREAM pas,LONG lSample)
407 hr = IAVIStream_Info(pas,&si,sizeof(si));
411 /* I am too lazy... */
412 FIXME("(%p,%ld)",pas,lSample);
416 /***********************************************************************
417 * AVIStreamBeginStreaming (AVIFIL32.@)
419 HRESULT WINAPI AVIStreamBeginStreaming(PAVISTREAM pas,LONG lStart,LONG lEnd,LONG lRate)
421 FIXME("(%p)->(%ld,%ld,%ld),stub!\n",pas,lStart,lEnd,lRate);
425 /***********************************************************************
426 * AVIStreamEndStreaming (AVIFIL32.@)
428 HRESULT WINAPI AVIStreamEndStreaming(PAVISTREAM pas)
430 FIXME("(%p)->(),stub!\n",pas);
434 /***********************************************************************
435 * AVIStreamGetFrameOpen (AVIFIL32.@)
437 PGETFRAME WINAPI AVIStreamGetFrameOpen(PAVISTREAM pas,LPBITMAPINFOHEADER pbi)
443 FIXME("(%p,%p)\n",pas,pbi);
445 hr = IAVIStream_Info(pas,&si,sizeof(si));
449 hr = AVIFILE_CreateIGetFrame((void**)&pgf,pas,pbi);
452 hr = IGetFrame_Begin( pgf, si.dwStart, si.dwLength, 1000 );
455 IGetFrame_Release( pgf );
462 /***********************************************************************
463 * AVIStreamGetFrame (AVIFIL32.@)
465 LPVOID WINAPI AVIStreamGetFrame(PGETFRAME pgf, LONG lPos)
467 return IGetFrame_GetFrame(pgf,lPos);
470 /***********************************************************************
471 * AVIStreamGetFrameClose (AVIFIL32.@)
473 HRESULT WINAPI AVIStreamGetFrameClose(PGETFRAME pgf)
475 return IGetFrame_End(pgf);
478 /***********************************************************************
479 * AVIStreamOpenFromFileA (AVIFIL32.@)
481 HRESULT WINAPI AVIStreamOpenFromFileA(PAVISTREAM* ppas, LPCSTR szFile, DWORD fccType, LONG lParam, UINT uMode, CLSID* lpHandler)
486 pwsz = AVIFILE_strdupAtoW( szFile );
488 return AVIERR_MEMORY;
489 hr = AVIStreamOpenFromFileW(ppas,pwsz,fccType,lParam,uMode,lpHandler);
490 HeapFree( AVIFILE_data.hHeap, 0, pwsz );
494 /***********************************************************************
495 * AVIStreamOpenFromFileW (AVIFIL32.@)
497 HRESULT WINAPI AVIStreamOpenFromFileW(PAVISTREAM* ppas, LPCWSTR szFile, DWORD fccType, LONG lParam, UINT uMode, CLSID* lpHandler)
504 hr = AVIFileOpenW(&paf,szFile,uMode,lpHandler);
507 hr = AVIFileInfoW(paf,&fi,sizeof(AVIFILEINFOW));
509 hr = AVIFileGetStream(paf,ppas,fccType,lParam);
511 IAVIFile_Release(paf);
516 /***********************************************************************
517 * AVIStreamCreate (AVIFIL32.@)
519 HRESULT WINAPI AVIStreamCreate(PAVISTREAM* ppas, LONG lParam1, LONG lParam2, CLSID* lpHandler)
526 if ( lpHandler == NULL )
528 hr = AVIFILE_DllGetClassObject(&CLSID_AVIFile,
529 &IID_IClassFactory,(void**)&pcf);
533 if ( !AVIFILE_data.fInitCOM )
535 hr = CoGetClassObject(lpHandler,CLSCTX_INPROC_SERVER,
536 NULL,&IID_IClassFactory,(void**)&pcf);
541 hr = IClassFactory_CreateInstance( pcf, NULL, &IID_IAVIStream,
543 IClassFactory_Release( pcf );
547 hr = IAVIStream_Create((*ppas),lParam1,lParam2);
550 IAVIStream_Release((*ppas));
558 /***********************************************************************
559 * AVIMakeCompressedStream (AVIFIL32.@)
561 HRESULT WINAPI AVIMakeCompressedStream(PAVISTREAM *ppsCompressed,PAVISTREAM ppsSource,AVICOMPRESSOPTIONS *aco,CLSID *pclsidHandler)
563 FIXME("(%p,%p,%p,%p)\n",ppsCompressed,ppsSource,aco,pclsidHandler);