2 * Copyright 1999 Marcus Meissner
3 * Copyright 2002-2003 Michael Günnewig
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "avifile_private.h"
24 /***********************************************************************
25 * for AVIBuildFilterW -- uses fixed size table
27 #define MAX_FILTERS 30 /* 30 => 7kB */
29 typedef struct _AVIFilter
{
31 WCHAR szExtensions
[MAX_FILTERS
* 7];
34 /***********************************************************************
41 LPAVICOMPRESSOPTIONS
*ppOptions
;
45 /***********************************************************************
46 * copied from dlls/ole32/compobj.c
48 static HRESULT
AVIFILE_CLSIDFromString(LPCSTR idstr
, LPCLSID id
)
56 memset(id
, 0, sizeof(CLSID
));
60 /* validate the CLSID string */
61 if (lstrlenA(idstr
) != 38)
62 return CO_E_CLASSSTRING
;
64 s
= (BYTE
const*)idstr
;
65 if ((s
[0]!='{') || (s
[9]!='-') || (s
[14]!='-') || (s
[19]!='-') ||
66 (s
[24]!='-') || (s
[37]!='}'))
67 return CO_E_CLASSSTRING
;
69 for (i
= 1; i
< 37; i
++) {
70 if ((i
== 9) || (i
== 14) || (i
== 19) || (i
== 24))
72 if (!(((s
[i
] >= '0') && (s
[i
] <= '9')) ||
73 ((s
[i
] >= 'a') && (s
[i
] <= 'f')) ||
74 ((s
[i
] >= 'A') && (s
[i
] <= 'F')))
76 return CO_E_CLASSSTRING
;
79 TRACE("%s -> %p\n", s
, id
);
81 /* quick lookup table */
82 memset(table
, 0, 256);
84 for (i
= 0; i
< 10; i
++)
87 for (i
= 0; i
< 6; i
++) {
88 table
['A' + i
] = i
+10;
89 table
['a' + i
] = i
+10;
92 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
95 s
++; /* skip leading brace */
96 for (i
= 0; i
< 4; i
++) {
97 p
[3 - i
] = table
[*s
]<<4 | table
[*(s
+1)];
103 for (i
= 0; i
< 2; i
++) {
104 p
[1-i
] = table
[*s
]<<4 | table
[*(s
+1)];
110 for (i
= 0; i
< 2; i
++) {
111 p
[1-i
] = table
[*s
]<<4 | table
[*(s
+1)];
117 /* these are just sequential bytes */
118 for (i
= 0; i
< 2; i
++) {
119 *p
++ = table
[*s
]<<4 | table
[*(s
+1)];
124 for (i
= 0; i
< 6; i
++) {
125 *p
++ = table
[*s
]<<4 | table
[*(s
+1)];
132 static BOOL
AVIFILE_GetFileHandlerByExtension(LPCWSTR szFile
, LPCLSID lpclsid
)
136 LPWSTR szExt
= strrchrW(szFile
, '.');
137 LONG len
= sizeof(szValue
) / sizeof(szValue
[0]);
144 wsprintfA(szRegKey
, "AVIFile\\Extensions\\%.3ls", szExt
);
145 if (RegQueryValueA(HKEY_CLASSES_ROOT
, szRegKey
, szValue
, &len
) != ERROR_SUCCESS
)
148 return (AVIFILE_CLSIDFromString(szValue
, lpclsid
) == S_OK
);
151 /***********************************************************************
152 * AVIFileInit (AVIFIL32.@)
154 void WINAPI
AVIFileInit(void) {
158 /***********************************************************************
159 * AVIFileExit (AVIFIL32.@)
161 void WINAPI
AVIFileExit(void) {
162 /* need to free ole32.dll if we are the last exit call */
163 /* OleUninitialize() */
164 FIXME("(): stub!\n");
167 /***********************************************************************
168 * AVIFileOpen (AVIFIL32.@)
169 * AVIFileOpenA (AVIFIL32.@)
171 HRESULT WINAPI
AVIFileOpenA(PAVIFILE
*ppfile
, LPCSTR szFile
, UINT uMode
,
174 LPWSTR wszFile
= NULL
;
178 TRACE("(%p,%s,0x%08X,%s)\n", ppfile
, debugstr_a(szFile
), uMode
,
179 debugstr_guid(lpHandler
));
181 /* check parameters */
182 if (ppfile
== NULL
|| szFile
== NULL
)
183 return AVIERR_BADPARAM
;
185 /* convert ASCII string to Unicode and call unicode function */
186 len
= MultiByteToWideChar(CP_ACP
, 0, szFile
, -1, NULL
, 0);
188 return AVIERR_BADPARAM
;
190 wszFile
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
192 return AVIERR_MEMORY
;
194 MultiByteToWideChar(CP_ACP
, 0, szFile
, -1, wszFile
, len
);
196 hr
= AVIFileOpenW(ppfile
, wszFile
, uMode
, lpHandler
);
198 HeapFree(GetProcessHeap(), 0, wszFile
);
203 /***********************************************************************
204 * AVIFileOpenW (AVIFIL32.@)
206 HRESULT WINAPI
AVIFileOpenW(PAVIFILE
*ppfile
, LPCWSTR szFile
, UINT uMode
,
209 IPersistFile
*ppersist
= NULL
;
213 TRACE("(%p,%s,0x%X,%s)\n", ppfile
, debugstr_w(szFile
), uMode
,
214 debugstr_guid(lpHandler
));
216 /* check parameters */
217 if (ppfile
== NULL
|| szFile
== NULL
)
218 return AVIERR_BADPARAM
;
222 /* if no handler then try guessing it by extension */
223 if (lpHandler
== NULL
) {
224 if (! AVIFILE_GetFileHandlerByExtension(szFile
, &clsidHandler
))
225 clsidHandler
= CLSID_AVIFile
;
227 clsidHandler
= *lpHandler
;
229 /* create instance of handler */
230 hr
= CoCreateInstance(&clsidHandler
, NULL
, CLSCTX_INPROC
, &IID_IAVIFile
, (LPVOID
*)ppfile
);
231 if (FAILED(hr
) || *ppfile
== NULL
)
234 /* ask for IPersistFile interface for loading/creating the file */
235 hr
= IAVIFile_QueryInterface(*ppfile
, &IID_IPersistFile
, (LPVOID
*)&ppersist
);
236 if (FAILED(hr
) || ppersist
== NULL
) {
237 IAVIFile_Release(*ppfile
);
242 hr
= IPersistFile_Load(ppersist
, szFile
, uMode
);
243 IPersistFile_Release(ppersist
);
245 IAVIFile_Release(*ppfile
);
252 /***********************************************************************
253 * AVIFileAddRef (AVIFIL32.@)
255 ULONG WINAPI
AVIFileAddRef(PAVIFILE pfile
)
257 TRACE("(%p)\n", pfile
);
260 ERR(": bad handle passed!\n");
264 return IAVIFile_AddRef(pfile
);
267 /***********************************************************************
268 * AVIFileRelease (AVIFIL32.@)
270 ULONG WINAPI
AVIFileRelease(PAVIFILE pfile
)
272 TRACE("(%p)\n", pfile
);
275 ERR(": bad handle passed!\n");
279 return IAVIFile_Release(pfile
);
282 /***********************************************************************
283 * AVIFileInfo (AVIFIL32.@)
284 * AVIFileInfoA (AVIFIL32.@)
286 HRESULT WINAPI
AVIFileInfoA(PAVIFILE pfile
, LPAVIFILEINFOA afi
, LONG size
)
291 TRACE("(%p,%p,%d)\n", pfile
, afi
, size
);
294 return AVIERR_BADHANDLE
;
295 if ((DWORD
)size
< sizeof(AVIFILEINFOA
))
296 return AVIERR_BADSIZE
;
298 hres
= IAVIFile_Info(pfile
, &afiw
, sizeof(afiw
));
300 memcpy(afi
, &afiw
, sizeof(*afi
) - sizeof(afi
->szFileType
));
301 WideCharToMultiByte(CP_ACP
, 0, afiw
.szFileType
, -1, afi
->szFileType
,
302 sizeof(afi
->szFileType
), NULL
, NULL
);
303 afi
->szFileType
[sizeof(afi
->szFileType
) - 1] = 0;
308 /***********************************************************************
309 * AVIFileInfoW (AVIFIL32.@)
311 HRESULT WINAPI
AVIFileInfoW(PAVIFILE pfile
, LPAVIFILEINFOW afiw
, LONG size
)
313 TRACE("(%p,%p,%d)\n", pfile
, afiw
, size
);
316 return AVIERR_BADHANDLE
;
318 return IAVIFile_Info(pfile
, afiw
, size
);
321 /***********************************************************************
322 * AVIFileGetStream (AVIFIL32.@)
324 HRESULT WINAPI
AVIFileGetStream(PAVIFILE pfile
, PAVISTREAM
*avis
,
325 DWORD fccType
, LONG lParam
)
327 TRACE("(%p,%p,'%4.4s',%d)\n", pfile
, avis
, (char*)&fccType
, lParam
);
330 return AVIERR_BADHANDLE
;
332 return IAVIFile_GetStream(pfile
, avis
, fccType
, lParam
);
335 /***********************************************************************
336 * AVIFileCreateStream (AVIFIL32.@)
337 * AVIFileCreateStreamA (AVIFIL32.@)
339 HRESULT WINAPI
AVIFileCreateStreamA(PAVIFILE pfile
, PAVISTREAM
*ppavi
,
340 LPAVISTREAMINFOA psi
)
344 TRACE("(%p,%p,%p)\n", pfile
, ppavi
, psi
);
347 return AVIERR_BADHANDLE
;
349 /* Only the szName at the end is different */
350 memcpy(&psiw
, psi
, sizeof(*psi
) - sizeof(psi
->szName
));
351 MultiByteToWideChar(CP_ACP
, 0, psi
->szName
, -1, psiw
.szName
,
352 sizeof(psiw
.szName
) / sizeof(psiw
.szName
[0]));
354 return IAVIFile_CreateStream(pfile
, ppavi
, &psiw
);
357 /***********************************************************************
358 * AVIFileCreateStreamW (AVIFIL32.@)
360 HRESULT WINAPI
AVIFileCreateStreamW(PAVIFILE pfile
, PAVISTREAM
*avis
,
361 LPAVISTREAMINFOW asi
)
363 TRACE("(%p,%p,%p)\n", pfile
, avis
, asi
);
366 return AVIERR_BADHANDLE
;
368 return IAVIFile_CreateStream(pfile
, avis
, asi
);
371 /***********************************************************************
372 * AVIFileWriteData (AVIFIL32.@)
374 HRESULT WINAPI
AVIFileWriteData(PAVIFILE pfile
,DWORD fcc
,LPVOID lp
,LONG size
)
376 TRACE("(%p,'%4.4s',%p,%d)\n", pfile
, (char*)&fcc
, lp
, size
);
379 return AVIERR_BADHANDLE
;
381 return IAVIFile_WriteData(pfile
, fcc
, lp
, size
);
384 /***********************************************************************
385 * AVIFileReadData (AVIFIL32.@)
387 HRESULT WINAPI
AVIFileReadData(PAVIFILE pfile
,DWORD fcc
,LPVOID lp
,LPLONG size
)
389 TRACE("(%p,'%4.4s',%p,%p)\n", pfile
, (char*)&fcc
, lp
, size
);
392 return AVIERR_BADHANDLE
;
394 return IAVIFile_ReadData(pfile
, fcc
, lp
, size
);
397 /***********************************************************************
398 * AVIFileEndRecord (AVIFIL32.@)
400 HRESULT WINAPI
AVIFileEndRecord(PAVIFILE pfile
)
402 TRACE("(%p)\n", pfile
);
405 return AVIERR_BADHANDLE
;
407 return IAVIFile_EndRecord(pfile
);
410 /***********************************************************************
411 * AVIStreamAddRef (AVIFIL32.@)
413 ULONG WINAPI
AVIStreamAddRef(PAVISTREAM pstream
)
415 TRACE("(%p)\n", pstream
);
417 if (pstream
== NULL
) {
418 ERR(": bad handle passed!\n");
422 return IAVIStream_AddRef(pstream
);
425 /***********************************************************************
426 * AVIStreamRelease (AVIFIL32.@)
428 ULONG WINAPI
AVIStreamRelease(PAVISTREAM pstream
)
430 TRACE("(%p)\n", pstream
);
432 if (pstream
== NULL
) {
433 ERR(": bad handle passed!\n");
437 return IAVIStream_Release(pstream
);
440 /***********************************************************************
441 * AVIStreamCreate (AVIFIL32.@)
443 HRESULT WINAPI
AVIStreamCreate(PAVISTREAM
*ppavi
, LONG lParam1
, LONG lParam2
,
444 LPCLSID pclsidHandler
)
448 TRACE("(%p,0x%08X,0x%08X,%s)\n", ppavi
, lParam1
, lParam2
,
449 debugstr_guid(pclsidHandler
));
452 return AVIERR_BADPARAM
;
455 if (pclsidHandler
== NULL
)
456 return AVIERR_UNSUPPORTED
;
458 hr
= CoCreateInstance(pclsidHandler
, NULL
, CLSCTX_INPROC
, &IID_IAVIStream
, (LPVOID
*)ppavi
);
459 if (FAILED(hr
) || *ppavi
== NULL
)
462 hr
= IAVIStream_Create(*ppavi
, lParam1
, lParam2
);
464 IAVIStream_Release(*ppavi
);
471 /***********************************************************************
472 * AVIStreamInfo (AVIFIL32.@)
473 * AVIStreamInfoA (AVIFIL32.@)
475 HRESULT WINAPI
AVIStreamInfoA(PAVISTREAM pstream
, LPAVISTREAMINFOA asi
,
481 TRACE("(%p,%p,%d)\n", pstream
, asi
, size
);
484 return AVIERR_BADHANDLE
;
485 if ((DWORD
)size
< sizeof(AVISTREAMINFOA
))
486 return AVIERR_BADSIZE
;
488 hres
= IAVIStream_Info(pstream
, &asiw
, sizeof(asiw
));
490 memcpy(asi
, &asiw
, sizeof(asiw
) - sizeof(asiw
.szName
));
491 WideCharToMultiByte(CP_ACP
, 0, asiw
.szName
, -1, asi
->szName
,
492 sizeof(asi
->szName
), NULL
, NULL
);
493 asi
->szName
[sizeof(asi
->szName
) - 1] = 0;
498 /***********************************************************************
499 * AVIStreamInfoW (AVIFIL32.@)
501 HRESULT WINAPI
AVIStreamInfoW(PAVISTREAM pstream
, LPAVISTREAMINFOW asi
,
504 TRACE("(%p,%p,%d)\n", pstream
, asi
, size
);
507 return AVIERR_BADHANDLE
;
509 return IAVIStream_Info(pstream
, asi
, size
);
512 /***********************************************************************
513 * AVIStreamFindSample (AVIFIL32.@)
515 LONG WINAPI
AVIStreamFindSample(PAVISTREAM pstream
, LONG pos
, LONG flags
)
517 TRACE("(%p,%d,0x%X)\n", pstream
, pos
, flags
);
522 return IAVIStream_FindSample(pstream
, pos
, flags
);
525 /***********************************************************************
526 * AVIStreamReadFormat (AVIFIL32.@)
528 HRESULT WINAPI
AVIStreamReadFormat(PAVISTREAM pstream
, LONG pos
,
529 LPVOID format
, LPLONG formatsize
)
531 TRACE("(%p,%d,%p,%p)\n", pstream
, pos
, format
, formatsize
);
534 return AVIERR_BADHANDLE
;
536 return IAVIStream_ReadFormat(pstream
, pos
, format
, formatsize
);
539 /***********************************************************************
540 * AVIStreamSetFormat (AVIFIL32.@)
542 HRESULT WINAPI
AVIStreamSetFormat(PAVISTREAM pstream
, LONG pos
,
543 LPVOID format
, LONG formatsize
)
545 TRACE("(%p,%d,%p,%d)\n", pstream
, pos
, format
, formatsize
);
548 return AVIERR_BADHANDLE
;
550 return IAVIStream_SetFormat(pstream
, pos
, format
, formatsize
);
553 /***********************************************************************
554 * AVIStreamRead (AVIFIL32.@)
556 HRESULT WINAPI
AVIStreamRead(PAVISTREAM pstream
, LONG start
, LONG samples
,
557 LPVOID buffer
, LONG buffersize
,
558 LPLONG bytesread
, LPLONG samplesread
)
560 TRACE("(%p,%d,%d,%p,%d,%p,%p)\n", pstream
, start
, samples
, buffer
,
561 buffersize
, bytesread
, samplesread
);
564 return AVIERR_BADHANDLE
;
566 return IAVIStream_Read(pstream
, start
, samples
, buffer
, buffersize
,
567 bytesread
, samplesread
);
570 /***********************************************************************
571 * AVIStreamWrite (AVIFIL32.@)
573 HRESULT WINAPI
AVIStreamWrite(PAVISTREAM pstream
, LONG start
, LONG samples
,
574 LPVOID buffer
, LONG buffersize
, DWORD flags
,
575 LPLONG sampwritten
, LPLONG byteswritten
)
577 TRACE("(%p,%d,%d,%p,%d,0x%X,%p,%p)\n", pstream
, start
, samples
, buffer
,
578 buffersize
, flags
, sampwritten
, byteswritten
);
581 return AVIERR_BADHANDLE
;
583 return IAVIStream_Write(pstream
, start
, samples
, buffer
, buffersize
,
584 flags
, sampwritten
, byteswritten
);
587 /***********************************************************************
588 * AVIStreamReadData (AVIFIL32.@)
590 HRESULT WINAPI
AVIStreamReadData(PAVISTREAM pstream
, DWORD fcc
, LPVOID lp
,
593 TRACE("(%p,'%4.4s',%p,%p)\n", pstream
, (char*)&fcc
, lp
, lpread
);
596 return AVIERR_BADHANDLE
;
598 return IAVIStream_ReadData(pstream
, fcc
, lp
, lpread
);
601 /***********************************************************************
602 * AVIStreamWriteData (AVIFIL32.@)
604 HRESULT WINAPI
AVIStreamWriteData(PAVISTREAM pstream
, DWORD fcc
, LPVOID lp
,
607 TRACE("(%p,'%4.4s',%p,%d)\n", pstream
, (char*)&fcc
, lp
, size
);
610 return AVIERR_BADHANDLE
;
612 return IAVIStream_WriteData(pstream
, fcc
, lp
, size
);
615 /***********************************************************************
616 * AVIStreamGetFrameOpen (AVIFIL32.@)
618 PGETFRAME WINAPI
AVIStreamGetFrameOpen(PAVISTREAM pstream
,
619 LPBITMAPINFOHEADER lpbiWanted
)
623 TRACE("(%p,%p)\n", pstream
, lpbiWanted
);
625 if (FAILED(IAVIStream_QueryInterface(pstream
, &IID_IGetFrame
, (LPVOID
*)&pg
)) ||
627 pg
= AVIFILE_CreateGetFrame(pstream
);
632 if (FAILED(IGetFrame_SetFormat(pg
, lpbiWanted
, NULL
, 0, 0, -1, -1))) {
633 IGetFrame_Release(pg
);
640 /***********************************************************************
641 * AVIStreamGetFrame (AVIFIL32.@)
643 LPVOID WINAPI
AVIStreamGetFrame(PGETFRAME pg
, LONG pos
)
645 TRACE("(%p,%d)\n", pg
, pos
);
650 return IGetFrame_GetFrame(pg
, pos
);
653 /***********************************************************************
654 * AVIStreamGetFrameClose (AVIFIL32.@)
656 HRESULT WINAPI
AVIStreamGetFrameClose(PGETFRAME pg
)
661 return IGetFrame_Release(pg
);
665 /***********************************************************************
666 * AVIMakeCompressedStream (AVIFIL32.@)
668 HRESULT WINAPI
AVIMakeCompressedStream(PAVISTREAM
*ppsCompressed
,
670 LPAVICOMPRESSOPTIONS aco
,
671 LPCLSID pclsidHandler
)
678 LONG size
= sizeof(szValue
);
680 TRACE("(%p,%p,%p,%s)\n", ppsCompressed
, psSource
, aco
,
681 debugstr_guid(pclsidHandler
));
683 if (ppsCompressed
== NULL
)
684 return AVIERR_BADPARAM
;
685 if (psSource
== NULL
)
686 return AVIERR_BADHANDLE
;
688 *ppsCompressed
= NULL
;
690 /* if no handler given get default ones based on streamtype */
691 if (pclsidHandler
== NULL
) {
692 hr
= IAVIStream_Info(psSource
, &asiw
, sizeof(asiw
));
696 wsprintfA(szRegKey
, "AVIFile\\Compressors\\%4.4s", (char*)&asiw
.fccType
);
697 if (RegQueryValueA(HKEY_CLASSES_ROOT
, szRegKey
, szValue
, &size
) != ERROR_SUCCESS
)
698 return AVIERR_UNSUPPORTED
;
699 if (AVIFILE_CLSIDFromString(szValue
, &clsidHandler
) != S_OK
)
700 return AVIERR_UNSUPPORTED
;
702 clsidHandler
= *pclsidHandler
;
704 hr
= CoCreateInstance(&clsidHandler
, NULL
, CLSCTX_INPROC
, &IID_IAVIStream
, (LPVOID
*)ppsCompressed
);
705 if (FAILED(hr
) || *ppsCompressed
== NULL
)
708 hr
= IAVIStream_Create(*ppsCompressed
, (LPARAM
)psSource
, (LPARAM
)aco
);
710 IAVIStream_Release(*ppsCompressed
);
711 *ppsCompressed
= NULL
;
717 /***********************************************************************
718 * AVIMakeFileFromStreams (AVIFIL32.@)
720 HRESULT WINAPI
AVIMakeFileFromStreams(PAVIFILE
*ppfile
, int nStreams
,
721 PAVISTREAM
*ppStreams
)
723 TRACE("(%p,%d,%p)\n", ppfile
, nStreams
, ppStreams
);
725 if (nStreams
< 0 || ppfile
== NULL
|| ppStreams
== NULL
)
726 return AVIERR_BADPARAM
;
728 *ppfile
= AVIFILE_CreateAVITempFile(nStreams
, ppStreams
);
730 return AVIERR_MEMORY
;
735 /***********************************************************************
736 * AVIStreamOpenFromFile (AVIFIL32.@)
737 * AVIStreamOpenFromFileA (AVIFIL32.@)
739 HRESULT WINAPI
AVIStreamOpenFromFileA(PAVISTREAM
*ppavi
, LPCSTR szFile
,
740 DWORD fccType
, LONG lParam
,
741 UINT mode
, LPCLSID pclsidHandler
)
743 PAVIFILE pfile
= NULL
;
746 TRACE("(%p,%s,'%4.4s',%d,0x%X,%s)\n", ppavi
, debugstr_a(szFile
),
747 (char*)&fccType
, lParam
, mode
, debugstr_guid(pclsidHandler
));
749 if (ppavi
== NULL
|| szFile
== NULL
)
750 return AVIERR_BADPARAM
;
754 hr
= AVIFileOpenA(&pfile
, szFile
, mode
, pclsidHandler
);
755 if (FAILED(hr
) || pfile
== NULL
)
758 hr
= IAVIFile_GetStream(pfile
, ppavi
, fccType
, lParam
);
759 IAVIFile_Release(pfile
);
764 /***********************************************************************
765 * AVIStreamOpenFromFileW (AVIFIL32.@)
767 HRESULT WINAPI
AVIStreamOpenFromFileW(PAVISTREAM
*ppavi
, LPCWSTR szFile
,
768 DWORD fccType
, LONG lParam
,
769 UINT mode
, LPCLSID pclsidHandler
)
771 PAVIFILE pfile
= NULL
;
774 TRACE("(%p,%s,'%4.4s',%d,0x%X,%s)\n", ppavi
, debugstr_w(szFile
),
775 (char*)&fccType
, lParam
, mode
, debugstr_guid(pclsidHandler
));
777 if (ppavi
== NULL
|| szFile
== NULL
)
778 return AVIERR_BADPARAM
;
782 hr
= AVIFileOpenW(&pfile
, szFile
, mode
, pclsidHandler
);
783 if (FAILED(hr
) || pfile
== NULL
)
786 hr
= IAVIFile_GetStream(pfile
, ppavi
, fccType
, lParam
);
787 IAVIFile_Release(pfile
);
792 /***********************************************************************
793 * AVIStreamBeginStreaming (AVIFIL32.@)
795 LONG WINAPI
AVIStreamBeginStreaming(PAVISTREAM pavi
, LONG lStart
, LONG lEnd
, LONG lRate
)
797 IAVIStreaming
* pstream
= NULL
;
800 TRACE("(%p,%d,%d,%d)\n", pavi
, lStart
, lEnd
, lRate
);
803 return AVIERR_BADHANDLE
;
805 hr
= IAVIStream_QueryInterface(pavi
, &IID_IAVIStreaming
, (LPVOID
*)&pstream
);
806 if (SUCCEEDED(hr
) && pstream
!= NULL
) {
807 hr
= IAVIStreaming_Begin(pstream
, lStart
, lEnd
, lRate
);
808 IAVIStreaming_Release(pstream
);
815 /***********************************************************************
816 * AVIStreamEndStreaming (AVIFIL32.@)
818 LONG WINAPI
AVIStreamEndStreaming(PAVISTREAM pavi
)
820 IAVIStreaming
* pstream
= NULL
;
823 TRACE("(%p)\n", pavi
);
825 hr
= IAVIStream_QueryInterface(pavi
, &IID_IAVIStreaming
, (LPVOID
*)&pstream
);
826 if (SUCCEEDED(hr
) && pstream
!= NULL
) {
827 IAVIStreaming_End(pstream
);
828 IAVIStreaming_Release(pstream
);
834 /***********************************************************************
835 * AVIStreamStart (AVIFIL32.@)
837 LONG WINAPI
AVIStreamStart(PAVISTREAM pstream
)
841 TRACE("(%p)\n", pstream
);
846 if (FAILED(IAVIStream_Info(pstream
, &asiw
, sizeof(asiw
))))
852 /***********************************************************************
853 * AVIStreamLength (AVIFIL32.@)
855 LONG WINAPI
AVIStreamLength(PAVISTREAM pstream
)
859 TRACE("(%p)\n", pstream
);
864 if (FAILED(IAVIStream_Info(pstream
, &asiw
, sizeof(asiw
))))
867 return asiw
.dwLength
;
870 /***********************************************************************
871 * AVIStreamSampleToTime (AVIFIL32.@)
873 LONG WINAPI
AVIStreamSampleToTime(PAVISTREAM pstream
, LONG lSample
)
878 TRACE("(%p,%d)\n", pstream
, lSample
);
883 if (FAILED(IAVIStream_Info(pstream
, &asiw
, sizeof(asiw
))))
885 if (asiw
.dwRate
== 0)
888 /* limit to stream bounds */
889 if (lSample
< asiw
.dwStart
)
890 lSample
= asiw
.dwStart
;
891 if (lSample
> asiw
.dwStart
+ asiw
.dwLength
)
892 lSample
= asiw
.dwStart
+ asiw
.dwLength
;
894 if (asiw
.dwRate
/ asiw
.dwScale
< 1000)
895 time
= (LONG
)(((float)lSample
* asiw
.dwScale
* 1000) / asiw
.dwRate
);
897 time
= (LONG
)(((float)lSample
* asiw
.dwScale
* 1000 + (asiw
.dwRate
- 1)) / asiw
.dwRate
);
899 TRACE(" -> %d\n",time
);
903 /***********************************************************************
904 * AVIStreamTimeToSample (AVIFIL32.@)
906 LONG WINAPI
AVIStreamTimeToSample(PAVISTREAM pstream
, LONG lTime
)
911 TRACE("(%p,%d)\n", pstream
, lTime
);
913 if (pstream
== NULL
|| lTime
< 0)
916 if (FAILED(IAVIStream_Info(pstream
, &asiw
, sizeof(asiw
))))
918 if (asiw
.dwScale
== 0)
921 if (asiw
.dwRate
/ asiw
.dwScale
< 1000)
922 sample
= (LONG
)((((float)asiw
.dwRate
* lTime
) / (asiw
.dwScale
* 1000)));
924 sample
= (LONG
)(((float)asiw
.dwRate
* lTime
+ (asiw
.dwScale
* 1000 - 1)) / (asiw
.dwScale
* 1000));
926 /* limit to stream bounds */
927 if (sample
< asiw
.dwStart
)
928 sample
= asiw
.dwStart
;
929 if (sample
> asiw
.dwStart
+ asiw
.dwLength
)
930 sample
= asiw
.dwStart
+ asiw
.dwLength
;
932 TRACE(" -> %d\n", sample
);
936 /***********************************************************************
937 * AVIBuildFilter (AVIFIL32.@)
938 * AVIBuildFilterA (AVIFIL32.@)
940 HRESULT WINAPI
AVIBuildFilterA(LPSTR szFilter
, LONG cbFilter
, BOOL fSaving
)
945 TRACE("(%p,%d,%d)\n", szFilter
, cbFilter
, fSaving
);
947 /* check parameters */
948 if (szFilter
== NULL
)
949 return AVIERR_BADPARAM
;
951 return AVIERR_BADSIZE
;
956 wszFilter
= HeapAlloc(GetProcessHeap(), 0, cbFilter
* sizeof(WCHAR
));
957 if (wszFilter
== NULL
)
958 return AVIERR_MEMORY
;
960 hr
= AVIBuildFilterW(wszFilter
, cbFilter
, fSaving
);
962 WideCharToMultiByte(CP_ACP
, 0, wszFilter
, cbFilter
,
963 szFilter
, cbFilter
, NULL
, NULL
);
966 HeapFree(GetProcessHeap(), 0, wszFilter
);
971 /***********************************************************************
972 * AVIBuildFilterW (AVIFIL32.@)
974 HRESULT WINAPI
AVIBuildFilterW(LPWSTR szFilter
, LONG cbFilter
, BOOL fSaving
)
976 static const WCHAR all_files
[] = { '*','.','*',0,0 };
977 static const WCHAR szClsid
[] = {'C','L','S','I','D',0};
978 static const WCHAR szExtensionFmt
[] = {';','*','.','%','s',0};
979 static const WCHAR szAVIFileExtensions
[] =
980 {'A','V','I','F','i','l','e','\\','E','x','t','e','n','s','i','o','n','s',0};
983 WCHAR szAllFiles
[40];
991 TRACE("(%p,%d,%d)\n", szFilter
, cbFilter
, fSaving
);
993 /* check parameters */
994 if (szFilter
== NULL
)
995 return AVIERR_BADPARAM
;
997 return AVIERR_BADSIZE
;
999 lp
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, MAX_FILTERS
* sizeof(AVIFilter
));
1001 return AVIERR_MEMORY
;
1004 * 1. iterate over HKEY_CLASSES_ROOT\\AVIFile\\Extensions and collect
1005 * extensions and CLSIDs
1006 * 2. iterate over collected CLSIDs and copy its description and its
1007 * extensions to szFilter if it fits
1009 * First filter is named "All multimedia files" and its filter is a
1010 * collection of all possible extensions except "*.*".
1012 if (RegOpenKeyW(HKEY_CLASSES_ROOT
, szAVIFileExtensions
, &hKey
) != ERROR_SUCCESS
) {
1013 HeapFree(GetProcessHeap(), 0, lp
);
1014 return AVIERR_ERROR
;
1016 for (n
= 0;RegEnumKeyW(hKey
, n
, szFileExt
, sizeof(szFileExt
)/sizeof(szFileExt
[0])) == ERROR_SUCCESS
;n
++) {
1017 /* get CLSID to extension */
1018 size
= sizeof(szValue
);
1019 if (RegQueryValueW(hKey
, szFileExt
, szValue
, &size
) != ERROR_SUCCESS
)
1022 /* search if the CLSID is already known */
1023 for (i
= 1; i
<= count
; i
++) {
1024 if (lstrcmpW(lp
[i
].szClsid
, szValue
) == 0)
1025 break; /* a new one */
1028 if (i
== count
+ 1) {
1029 /* it's a new CLSID */
1031 /* FIXME: How do we get info's about read/write capabilities? */
1033 if (count
>= MAX_FILTERS
) {
1034 /* try to inform user of our full fixed size table */
1035 ERR(": More than %d filters found! Adjust MAX_FILTERS in dlls/avifil32/api.c\n", MAX_FILTERS
);
1039 lstrcpyW(lp
[i
].szClsid
, szValue
);
1044 /* append extension to the filter */
1045 wsprintfW(szValue
, szExtensionFmt
, szFileExt
);
1046 if (lp
[i
].szExtensions
[0] == 0)
1047 lstrcatW(lp
[i
].szExtensions
, szValue
+ 1);
1049 lstrcatW(lp
[i
].szExtensions
, szValue
);
1051 /* also append to the "all multimedia"-filter */
1052 if (lp
[0].szExtensions
[0] == 0)
1053 lstrcatW(lp
[0].szExtensions
, szValue
+ 1);
1055 lstrcatW(lp
[0].szExtensions
, szValue
);
1059 /* 2. get descriptions for the CLSIDs and fill out szFilter */
1060 if (RegOpenKeyW(HKEY_CLASSES_ROOT
, szClsid
, &hKey
) != ERROR_SUCCESS
) {
1061 HeapFree(GetProcessHeap(), 0, lp
);
1062 return AVIERR_ERROR
;
1064 for (n
= 0; n
<= count
; n
++) {
1065 /* first the description */
1067 size
= sizeof(szValue
);
1068 if (RegQueryValueW(hKey
, lp
[n
].szClsid
, szValue
, &size
) == ERROR_SUCCESS
) {
1069 size
= lstrlenW(szValue
);
1070 lstrcpynW(szFilter
, szValue
, cbFilter
);
1073 size
= LoadStringW(AVIFILE_hModule
,IDS_ALLMULTIMEDIA
,szFilter
,cbFilter
);
1075 /* check for enough space */
1077 if (cbFilter
< size
+ lstrlenW(lp
[n
].szExtensions
) + 2) {
1080 HeapFree(GetProcessHeap(), 0, lp
);
1082 return AVIERR_BUFFERTOOSMALL
;
1087 /* and then the filter */
1088 lstrcpynW(szFilter
, lp
[n
].szExtensions
, cbFilter
);
1089 size
= lstrlenW(lp
[n
].szExtensions
) + 1;
1095 HeapFree(GetProcessHeap(), 0, lp
);
1097 /* add "All files" "*.*" filter if enough space left */
1098 size
= LoadStringW(AVIFILE_hModule
, IDS_ALLFILES
,
1099 szAllFiles
, (sizeof(szAllFiles
) - sizeof(all_files
))/sizeof(WCHAR
)) + 1;
1100 memcpy( szAllFiles
+ size
, all_files
, sizeof(all_files
) );
1101 size
+= sizeof(all_files
) / sizeof(WCHAR
);
1103 if (cbFilter
> size
) {
1104 memcpy(szFilter
, szAllFiles
, size
* sizeof(szAllFiles
[0]));
1108 return AVIERR_BUFFERTOOSMALL
;
1112 static BOOL
AVISaveOptionsFmtChoose(HWND hWnd
)
1114 LPAVICOMPRESSOPTIONS pOptions
= SaveOpts
.ppOptions
[SaveOpts
.nCurrent
];
1115 AVISTREAMINFOW sInfo
;
1117 TRACE("(%p)\n", hWnd
);
1119 if (pOptions
== NULL
|| SaveOpts
.ppavis
[SaveOpts
.nCurrent
] == NULL
) {
1120 ERR(": bad state!\n");
1124 if (FAILED(AVIStreamInfoW(SaveOpts
.ppavis
[SaveOpts
.nCurrent
],
1125 &sInfo
, sizeof(sInfo
)))) {
1126 ERR(": AVIStreamInfoW failed!\n");
1130 if (sInfo
.fccType
== streamtypeVIDEO
) {
1134 memset(&cv
, 0, sizeof(cv
));
1136 if ((pOptions
->dwFlags
& AVICOMPRESSF_VALID
) == 0) {
1137 memset(pOptions
, 0, sizeof(AVICOMPRESSOPTIONS
));
1138 pOptions
->fccType
= streamtypeVIDEO
;
1139 pOptions
->fccHandler
= comptypeDIB
;
1140 pOptions
->dwQuality
= (DWORD
)ICQUALITY_DEFAULT
;
1143 cv
.cbSize
= sizeof(cv
);
1144 cv
.dwFlags
= ICMF_COMPVARS_VALID
;
1145 /*cv.fccType = pOptions->fccType; */
1146 cv
.fccHandler
= pOptions
->fccHandler
;
1147 cv
.lQ
= pOptions
->dwQuality
;
1148 cv
.lpState
= pOptions
->lpParms
;
1149 cv
.cbState
= pOptions
->cbParms
;
1150 if (pOptions
->dwFlags
& AVICOMPRESSF_KEYFRAMES
)
1151 cv
.lKey
= pOptions
->dwKeyFrameEvery
;
1154 if (pOptions
->dwFlags
& AVICOMPRESSF_DATARATE
)
1155 cv
.lDataRate
= pOptions
->dwBytesPerSecond
/ 1024; /* need kBytes */
1159 ret
= ICCompressorChoose(hWnd
, SaveOpts
.uFlags
, NULL
,
1160 SaveOpts
.ppavis
[SaveOpts
.nCurrent
], &cv
, NULL
);
1163 pOptions
->fccHandler
= cv
.fccHandler
;
1164 pOptions
->lpParms
= cv
.lpState
;
1165 pOptions
->cbParms
= cv
.cbState
;
1166 pOptions
->dwQuality
= cv
.lQ
;
1168 pOptions
->dwKeyFrameEvery
= cv
.lKey
;
1169 pOptions
->dwFlags
|= AVICOMPRESSF_KEYFRAMES
;
1171 pOptions
->dwFlags
&= ~AVICOMPRESSF_KEYFRAMES
;
1172 if (cv
.lDataRate
!= 0) {
1173 pOptions
->dwBytesPerSecond
= cv
.lDataRate
* 1024; /* need bytes */
1174 pOptions
->dwFlags
|= AVICOMPRESSF_DATARATE
;
1176 pOptions
->dwFlags
&= ~AVICOMPRESSF_DATARATE
;
1177 pOptions
->dwFlags
|= AVICOMPRESSF_VALID
;
1179 ICCompressorFree(&cv
);
1182 } else if (sInfo
.fccType
== streamtypeAUDIO
) {
1183 ACMFORMATCHOOSEW afmtc
;
1187 /* FIXME: check ACM version -- Which version is needed? */
1189 memset(&afmtc
, 0, sizeof(afmtc
));
1190 afmtc
.cbStruct
= sizeof(afmtc
);
1192 afmtc
.hwndOwner
= hWnd
;
1194 acmMetrics(NULL
, ACM_METRIC_MAX_SIZE_FORMAT
, &size
);
1195 if ((pOptions
->cbFormat
== 0 || pOptions
->lpFormat
== NULL
) && size
!= 0) {
1196 pOptions
->lpFormat
= HeapAlloc(GetProcessHeap(), 0, size
);
1197 if (!pOptions
->lpFormat
) return FALSE
;
1198 pOptions
->cbFormat
= size
;
1199 } else if (pOptions
->cbFormat
< (DWORD
)size
) {
1200 void *new_buffer
= HeapReAlloc(GetProcessHeap(), 0, pOptions
->lpFormat
, size
);
1201 if (!new_buffer
) return FALSE
;
1202 pOptions
->lpFormat
= new_buffer
;
1203 pOptions
->cbFormat
= size
;
1205 afmtc
.pwfx
= pOptions
->lpFormat
;
1206 afmtc
.cbwfx
= pOptions
->cbFormat
;
1209 AVIStreamFormatSize(SaveOpts
.ppavis
[SaveOpts
.nCurrent
],
1210 sInfo
.dwStart
, &size
);
1211 if (size
< (LONG
)sizeof(PCMWAVEFORMAT
))
1212 size
= sizeof(PCMWAVEFORMAT
);
1213 afmtc
.pwfxEnum
= HeapAlloc(GetProcessHeap(), 0, size
);
1214 if (afmtc
.pwfxEnum
!= NULL
) {
1215 AVIStreamReadFormat(SaveOpts
.ppavis
[SaveOpts
.nCurrent
],
1216 sInfo
.dwStart
, afmtc
.pwfxEnum
, &size
);
1217 afmtc
.fdwEnum
= ACM_FORMATENUMF_CONVERT
;
1220 ret
= acmFormatChooseW(&afmtc
);
1222 pOptions
->dwFlags
|= AVICOMPRESSF_VALID
;
1224 HeapFree(GetProcessHeap(), 0, afmtc
.pwfxEnum
);
1227 ERR(": unknown streamtype 0x%08X\n", sInfo
.fccType
);
1232 static void AVISaveOptionsUpdate(HWND hWnd
)
1234 static const WCHAR szVideoFmt
[]={'%','l','d','x','%','l','d','x','%','d',0};
1235 static const WCHAR szAudioFmt
[]={'%','s',' ','%','s',0};
1237 WCHAR szFormat
[128];
1238 AVISTREAMINFOW sInfo
;
1242 TRACE("(%p)\n", hWnd
);
1244 SaveOpts
.nCurrent
= SendDlgItemMessageW(hWnd
,IDC_STREAM
,CB_GETCURSEL
,0,0);
1245 if (SaveOpts
.nCurrent
< 0)
1248 if (FAILED(AVIStreamInfoW(SaveOpts
.ppavis
[SaveOpts
.nCurrent
], &sInfo
, sizeof(sInfo
))))
1251 AVIStreamFormatSize(SaveOpts
.ppavis
[SaveOpts
.nCurrent
],sInfo
.dwStart
,&size
);
1255 /* read format to build format description string */
1256 lpFormat
= HeapAlloc(GetProcessHeap(), 0, size
);
1257 if (lpFormat
!= NULL
) {
1258 if (SUCCEEDED(AVIStreamReadFormat(SaveOpts
.ppavis
[SaveOpts
.nCurrent
],sInfo
.dwStart
,lpFormat
, &size
))) {
1259 if (sInfo
.fccType
== streamtypeVIDEO
) {
1260 LPBITMAPINFOHEADER lpbi
= lpFormat
;
1263 wsprintfW(szFormat
, szVideoFmt
, lpbi
->biWidth
,
1264 lpbi
->biHeight
, lpbi
->biBitCount
);
1266 if (lpbi
->biCompression
!= BI_RGB
) {
1269 hic
= ICLocate(ICTYPE_VIDEO
, sInfo
.fccHandler
, lpFormat
,
1270 NULL
, ICMODE_DECOMPRESS
);
1272 if (ICGetInfo(hic
, &icinfo
, sizeof(icinfo
)) == S_OK
)
1273 lstrcatW(szFormat
, icinfo
.szDescription
);
1277 LoadStringW(AVIFILE_hModule
, IDS_UNCOMPRESSED
,
1278 icinfo
.szDescription
,
1279 sizeof(icinfo
.szDescription
)/sizeof(icinfo
.szDescription
[0]));
1280 lstrcatW(szFormat
, icinfo
.szDescription
);
1282 } else if (sInfo
.fccType
== streamtypeAUDIO
) {
1283 ACMFORMATTAGDETAILSW aftd
;
1284 ACMFORMATDETAILSW afd
;
1286 memset(&aftd
, 0, sizeof(aftd
));
1287 memset(&afd
, 0, sizeof(afd
));
1289 aftd
.cbStruct
= sizeof(aftd
);
1290 aftd
.dwFormatTag
= afd
.dwFormatTag
=
1291 ((PWAVEFORMATEX
)lpFormat
)->wFormatTag
;
1292 aftd
.cbFormatSize
= afd
.cbwfx
= size
;
1294 afd
.cbStruct
= sizeof(afd
);
1295 afd
.pwfx
= lpFormat
;
1297 if (acmFormatTagDetailsW(NULL
, &aftd
,
1298 ACM_FORMATTAGDETAILSF_FORMATTAG
) == S_OK
) {
1299 if (acmFormatDetailsW(NULL
,&afd
,ACM_FORMATDETAILSF_FORMAT
) == S_OK
)
1300 wsprintfW(szFormat
, szAudioFmt
, afd
.szFormat
, aftd
.szFormatTag
);
1304 HeapFree(GetProcessHeap(), 0, lpFormat
);
1307 /* set text for format description */
1308 SetDlgItemTextW(hWnd
, IDC_FORMATTEXT
, szFormat
);
1310 /* Disable option button for unsupported streamtypes */
1311 if (sInfo
.fccType
== streamtypeVIDEO
||
1312 sInfo
.fccType
== streamtypeAUDIO
)
1313 EnableWindow(GetDlgItem(hWnd
, IDC_OPTIONS
), TRUE
);
1315 EnableWindow(GetDlgItem(hWnd
, IDC_OPTIONS
), FALSE
);
1320 static INT_PTR CALLBACK
AVISaveOptionsDlgProc(HWND hWnd
, UINT uMsg
,
1321 WPARAM wParam
, LPARAM lParam
)
1324 BOOL bIsInterleaved
;
1327 /*TRACE("(%p,%u,0x%04X,0x%08lX)\n", hWnd, uMsg, wParam, lParam);*/
1331 SaveOpts
.nCurrent
= 0;
1332 if (SaveOpts
.nStreams
== 1) {
1333 EndDialog(hWnd
, AVISaveOptionsFmtChoose(hWnd
));
1338 for (n
= 0; n
< SaveOpts
.nStreams
; n
++) {
1339 AVISTREAMINFOW sInfo
;
1341 AVIStreamInfoW(SaveOpts
.ppavis
[n
], &sInfo
, sizeof(sInfo
));
1342 SendDlgItemMessageW(hWnd
, IDC_STREAM
, CB_ADDSTRING
,
1343 0L, (LPARAM
)sInfo
.szName
);
1346 /* select first stream */
1347 SendDlgItemMessageW(hWnd
, IDC_STREAM
, CB_SETCURSEL
, 0, 0);
1348 SendMessageW(hWnd
, WM_COMMAND
, MAKELONG(IDC_STREAM
, CBN_SELCHANGE
), (LPARAM
)hWnd
);
1350 /* initialize interleave */
1351 if (SaveOpts
.ppOptions
[0] != NULL
&&
1352 (SaveOpts
.ppOptions
[0]->dwFlags
& AVICOMPRESSF_VALID
)) {
1353 bIsInterleaved
= (SaveOpts
.ppOptions
[0]->dwFlags
& AVICOMPRESSF_INTERLEAVE
);
1354 dwInterleave
= SaveOpts
.ppOptions
[0]->dwInterleaveEvery
;
1356 bIsInterleaved
= TRUE
;
1359 CheckDlgButton(hWnd
, IDC_INTERLEAVE
, bIsInterleaved
);
1360 SetDlgItemInt(hWnd
, IDC_INTERLEAVEEVERY
, dwInterleave
, FALSE
);
1361 EnableWindow(GetDlgItem(hWnd
, IDC_INTERLEAVEEVERY
), bIsInterleaved
);
1364 switch (LOWORD(wParam
)) {
1366 /* get data from controls and save them */
1367 dwInterleave
= GetDlgItemInt(hWnd
, IDC_INTERLEAVEEVERY
, NULL
, 0);
1368 bIsInterleaved
= IsDlgButtonChecked(hWnd
, IDC_INTERLEAVE
);
1369 for (n
= 0; n
< SaveOpts
.nStreams
; n
++) {
1370 if (SaveOpts
.ppOptions
[n
] != NULL
) {
1371 if (bIsInterleaved
) {
1372 SaveOpts
.ppOptions
[n
]->dwFlags
|= AVICOMPRESSF_INTERLEAVE
;
1373 SaveOpts
.ppOptions
[n
]->dwInterleaveEvery
= dwInterleave
;
1375 SaveOpts
.ppOptions
[n
]->dwFlags
&= ~AVICOMPRESSF_INTERLEAVE
;
1380 EndDialog(hWnd
, LOWORD(wParam
) == IDOK
);
1382 case IDC_INTERLEAVE
:
1383 EnableWindow(GetDlgItem(hWnd
, IDC_INTERLEAVEEVERY
),
1384 IsDlgButtonChecked(hWnd
, IDC_INTERLEAVE
));
1387 if (HIWORD(wParam
) == CBN_SELCHANGE
) {
1388 /* update control elements */
1389 AVISaveOptionsUpdate(hWnd
);
1393 AVISaveOptionsFmtChoose(hWnd
);
1402 /***********************************************************************
1403 * AVISaveOptions (AVIFIL32.@)
1405 BOOL WINAPI
AVISaveOptions(HWND hWnd
, UINT uFlags
, INT nStreams
,
1406 PAVISTREAM
*ppavi
, LPAVICOMPRESSOPTIONS
*ppOptions
)
1408 LPAVICOMPRESSOPTIONS pSavedOptions
= NULL
;
1411 TRACE("(%p,0x%X,%d,%p,%p)\n", hWnd
, uFlags
, nStreams
,
1414 /* check parameters */
1415 if (nStreams
<= 0 || ppavi
== NULL
|| ppOptions
== NULL
)
1416 return AVIERR_BADPARAM
;
1418 /* save options in case the user presses cancel */
1420 pSavedOptions
= HeapAlloc(GetProcessHeap(), 0, nStreams
* sizeof(AVICOMPRESSOPTIONS
));
1421 if (pSavedOptions
== NULL
)
1424 for (n
= 0; n
< nStreams
; n
++) {
1425 if (ppOptions
[n
] != NULL
)
1426 memcpy(pSavedOptions
+ n
, ppOptions
[n
], sizeof(AVICOMPRESSOPTIONS
));
1430 SaveOpts
.uFlags
= uFlags
;
1431 SaveOpts
.nStreams
= nStreams
;
1432 SaveOpts
.ppavis
= ppavi
;
1433 SaveOpts
.ppOptions
= ppOptions
;
1435 ret
= DialogBoxW(AVIFILE_hModule
, MAKEINTRESOURCEW(IDD_SAVEOPTIONS
),
1436 hWnd
, AVISaveOptionsDlgProc
);
1441 /* restore options when user pressed cancel */
1442 if (pSavedOptions
!= NULL
) {
1444 for (n
= 0; n
< nStreams
; n
++) {
1445 if (ppOptions
[n
] != NULL
)
1446 memcpy(ppOptions
[n
], pSavedOptions
+ n
, sizeof(AVICOMPRESSOPTIONS
));
1449 HeapFree(GetProcessHeap(), 0, pSavedOptions
);
1455 /***********************************************************************
1456 * AVISaveOptionsFree (AVIFIL32.@)
1458 HRESULT WINAPI
AVISaveOptionsFree(INT nStreams
,LPAVICOMPRESSOPTIONS
*ppOptions
)
1460 TRACE("(%d,%p)\n", nStreams
, ppOptions
);
1462 if (nStreams
< 0 || ppOptions
== NULL
)
1463 return AVIERR_BADPARAM
;
1465 for (nStreams
--; nStreams
>= 0; nStreams
--) {
1466 if (ppOptions
[nStreams
] != NULL
) {
1467 ppOptions
[nStreams
]->dwFlags
&= ~AVICOMPRESSF_VALID
;
1469 if (ppOptions
[nStreams
]->lpParms
!= NULL
) {
1470 HeapFree(GetProcessHeap(), 0, ppOptions
[nStreams
]->lpParms
);
1471 ppOptions
[nStreams
]->lpParms
= NULL
;
1472 ppOptions
[nStreams
]->cbParms
= 0;
1474 if (ppOptions
[nStreams
]->lpFormat
!= NULL
) {
1475 HeapFree(GetProcessHeap(), 0, ppOptions
[nStreams
]->lpFormat
);
1476 ppOptions
[nStreams
]->lpFormat
= NULL
;
1477 ppOptions
[nStreams
]->cbFormat
= 0;
1485 /***********************************************************************
1486 * AVISaveVA (AVIFIL32.@)
1488 HRESULT WINAPI
AVISaveVA(LPCSTR szFile
, CLSID
*pclsidHandler
,
1489 AVISAVECALLBACK lpfnCallback
, int nStream
,
1490 PAVISTREAM
*ppavi
, LPAVICOMPRESSOPTIONS
*plpOptions
)
1492 LPWSTR wszFile
= NULL
;
1496 TRACE("(%s,%p,%p,%d,%p,%p)\n", debugstr_a(szFile
), pclsidHandler
,
1497 lpfnCallback
, nStream
, ppavi
, plpOptions
);
1499 if (szFile
== NULL
|| ppavi
== NULL
|| plpOptions
== NULL
)
1500 return AVIERR_BADPARAM
;
1502 /* convert ASCII string to Unicode and call Unicode function */
1503 len
= MultiByteToWideChar(CP_ACP
, 0, szFile
, -1, NULL
, 0);
1505 return AVIERR_BADPARAM
;
1507 wszFile
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
1508 if (wszFile
== NULL
)
1509 return AVIERR_MEMORY
;
1511 MultiByteToWideChar(CP_ACP
, 0, szFile
, -1, wszFile
, len
);
1513 hr
= AVISaveVW(wszFile
, pclsidHandler
, lpfnCallback
,
1514 nStream
, ppavi
, plpOptions
);
1516 HeapFree(GetProcessHeap(), 0, wszFile
);
1521 /***********************************************************************
1522 * AVIFILE_AVISaveDefaultCallback (internal)
1524 static BOOL WINAPI
AVIFILE_AVISaveDefaultCallback(INT progress
)
1526 TRACE("(%d)\n", progress
);
1531 /***********************************************************************
1532 * AVISaveVW (AVIFIL32.@)
1534 HRESULT WINAPI
AVISaveVW(LPCWSTR szFile
, CLSID
*pclsidHandler
,
1535 AVISAVECALLBACK lpfnCallback
, int nStreams
,
1536 PAVISTREAM
*ppavi
, LPAVICOMPRESSOPTIONS
*plpOptions
)
1538 LONG lStart
[MAX_AVISTREAMS
];
1539 PAVISTREAM pOutStreams
[MAX_AVISTREAMS
];
1540 PAVISTREAM pInStreams
[MAX_AVISTREAMS
];
1542 AVISTREAMINFOW sInfo
;
1544 PAVIFILE pfile
= NULL
; /* the output AVI file */
1545 LONG lFirstVideo
= -1;
1548 /* for interleaving ... */
1549 DWORD dwInterleave
= 0; /* interleave rate */
1550 DWORD dwFileInitialFrames
;
1554 /* for reading/writing the data ... */
1555 LPVOID lpBuffer
= NULL
;
1556 LONG cbBuffer
; /* real size of lpBuffer */
1557 LONG lBufferSize
; /* needed bytes for format(s), etc. */
1562 TRACE("(%s,%p,%p,%d,%p,%p)\n", debugstr_w(szFile
), pclsidHandler
,
1563 lpfnCallback
, nStreams
, ppavi
, plpOptions
);
1565 if (szFile
== NULL
|| ppavi
== NULL
|| plpOptions
== NULL
)
1566 return AVIERR_BADPARAM
;
1567 if (nStreams
>= MAX_AVISTREAMS
) {
1568 WARN("Can't write AVI with %d streams only supports %d -- change MAX_AVISTREAMS!\n", nStreams
, MAX_AVISTREAMS
);
1569 return AVIERR_INTERNAL
;
1572 if (lpfnCallback
== NULL
)
1573 lpfnCallback
= AVIFILE_AVISaveDefaultCallback
;
1575 /* clear local variable(s) */
1576 for (curStream
= 0; curStream
< nStreams
; curStream
++) {
1577 pInStreams
[curStream
] = NULL
;
1578 pOutStreams
[curStream
] = NULL
;
1581 /* open output AVI file (create it if it doesn't exist) */
1582 hres
= AVIFileOpenW(&pfile
, szFile
, OF_CREATE
|OF_SHARE_EXCLUSIVE
|OF_WRITE
,
1586 AVIFileInfoW(pfile
, &fInfo
, sizeof(fInfo
)); /* for dwCaps */
1588 /* initialize our data structures part 1 */
1589 for (curStream
= 0; curStream
< nStreams
; curStream
++) {
1590 PAVISTREAM pCurStream
= ppavi
[curStream
];
1592 hres
= AVIStreamInfoW(pCurStream
, &sInfo
, sizeof(sInfo
));
1596 /* search first video stream and check for interleaving */
1597 if (sInfo
.fccType
== streamtypeVIDEO
) {
1598 /* remember first video stream -- needed for interleaving */
1599 if (lFirstVideo
< 0)
1600 lFirstVideo
= curStream
;
1601 } else if (!dwInterleave
) {
1602 /* check if any non-video stream wants to be interleaved */
1603 WARN("options.flags=0x%X options.dwInterleave=%u\n",plpOptions
[curStream
]->dwFlags
,plpOptions
[curStream
]->dwInterleaveEvery
);
1604 if (plpOptions
[curStream
] != NULL
&&
1605 plpOptions
[curStream
]->dwFlags
& AVICOMPRESSF_INTERLEAVE
)
1606 dwInterleave
= plpOptions
[curStream
]->dwInterleaveEvery
;
1609 /* create de-/compressed stream interface if needed */
1610 pInStreams
[curStream
] = NULL
;
1611 if (plpOptions
[curStream
] != NULL
) {
1612 if (plpOptions
[curStream
]->fccHandler
||
1613 plpOptions
[curStream
]->lpFormat
!= NULL
) {
1614 DWORD dwKeySave
= plpOptions
[curStream
]->dwKeyFrameEvery
;
1616 if (fInfo
.dwCaps
& AVIFILECAPS_ALLKEYFRAMES
)
1617 plpOptions
[curStream
]->dwKeyFrameEvery
= 1;
1619 hres
= AVIMakeCompressedStream(&pInStreams
[curStream
], pCurStream
,
1620 plpOptions
[curStream
], NULL
);
1621 plpOptions
[curStream
]->dwKeyFrameEvery
= dwKeySave
;
1622 if (FAILED(hres
) || pInStreams
[curStream
] == NULL
) {
1623 pInStreams
[curStream
] = NULL
;
1627 /* test stream interface and update stream-info */
1628 hres
= AVIStreamInfoW(pInStreams
[curStream
], &sInfo
, sizeof(sInfo
));
1634 /* now handle streams which will only be copied */
1635 if (pInStreams
[curStream
] == NULL
) {
1636 pCurStream
= pInStreams
[curStream
] = ppavi
[curStream
];
1637 AVIStreamAddRef(pCurStream
);
1639 pCurStream
= pInStreams
[curStream
];
1641 lStart
[curStream
] = sInfo
.dwStart
;
1642 } /* for all streams */
1644 /* check that first video stream is the first stream */
1645 if (lFirstVideo
> 0) {
1646 PAVISTREAM pTmp
= pInStreams
[lFirstVideo
];
1647 LONG lTmp
= lStart
[lFirstVideo
];
1649 pInStreams
[lFirstVideo
] = pInStreams
[0];
1650 pInStreams
[0] = pTmp
;
1651 lStart
[lFirstVideo
] = lStart
[0];
1656 /* allocate buffer for formats, data, etc. of an initial size of 64 kBytes*/
1657 cbBuffer
= 0x00010000;
1658 lpBuffer
= HeapAlloc(GetProcessHeap(), 0, cbBuffer
);
1659 if (lpBuffer
== NULL
) {
1660 hres
= AVIERR_MEMORY
;
1664 AVIStreamInfoW(pInStreams
[0], &sInfo
, sizeof(sInfo
));
1665 lFileLength
= sInfo
.dwLength
;
1666 dwFileInitialFrames
= 0;
1667 if (lFirstVideo
>= 0) {
1668 /* check for correct version of the format
1669 * -- need at least BITMAPINFOHEADER or newer
1672 lBufferSize
= cbBuffer
;
1673 hres
= AVIStreamReadFormat(pInStreams
[lFirstVideo
], AVIStreamStart(pInStreams
[lFirstVideo
]), lpBuffer
, &lBufferSize
);
1674 if (lBufferSize
< (LONG
)sizeof(BITMAPINFOHEADER
))
1675 hres
= AVIERR_INTERNAL
;
1678 } else /* use one second blocks for interleaving if no video present */
1679 lSampleInc
= AVIStreamTimeToSample(pInStreams
[0], 1000000);
1681 /* create output streams */
1682 for (curStream
= 0; curStream
< nStreams
; curStream
++) {
1683 AVIStreamInfoW(pInStreams
[curStream
], &sInfo
, sizeof(sInfo
));
1685 sInfo
.dwInitialFrames
= 0;
1686 if (dwInterleave
!= 0 && curStream
> 0 && sInfo
.fccType
!= streamtypeVIDEO
) {
1687 /* 750 ms initial frames for non-video streams */
1688 sInfo
.dwInitialFrames
= AVIStreamTimeToSample(pInStreams
[0], 750);
1691 hres
= AVIFileCreateStreamW(pfile
, &pOutStreams
[curStream
], &sInfo
);
1692 if (pOutStreams
[curStream
] != NULL
&& SUCCEEDED(hres
)) {
1693 /* copy initial format for this stream */
1694 lBufferSize
= cbBuffer
;
1695 hres
= AVIStreamReadFormat(pInStreams
[curStream
], sInfo
.dwStart
,
1696 lpBuffer
, &lBufferSize
);
1699 hres
= AVIStreamSetFormat(pOutStreams
[curStream
], 0, lpBuffer
, lBufferSize
);
1703 /* try to copy stream handler data */
1704 lBufferSize
= cbBuffer
;
1705 hres
= AVIStreamReadData(pInStreams
[curStream
], ckidSTREAMHANDLERDATA
,
1706 lpBuffer
, &lBufferSize
);
1707 if (SUCCEEDED(hres
) && lBufferSize
> 0) {
1708 hres
= AVIStreamWriteData(pOutStreams
[curStream
],ckidSTREAMHANDLERDATA
,
1709 lpBuffer
, lBufferSize
);
1714 if (dwFileInitialFrames
< sInfo
.dwInitialFrames
)
1715 dwFileInitialFrames
= sInfo
.dwInitialFrames
;
1717 AVIStreamSampleToSample(pOutStreams
[0], pInStreams
[curStream
],
1719 if (lFileLength
< lReadBytes
)
1720 lFileLength
= lReadBytes
;
1722 /* creation of de-/compression stream interface failed */
1723 WARN("creation of (de-)compression stream failed for stream %d\n",curStream
);
1724 AVIStreamRelease(pInStreams
[curStream
]);
1725 if (curStream
+ 1 >= nStreams
) {
1726 /* move the others one up */
1727 PAVISTREAM
*ppas
= &pInStreams
[curStream
];
1728 int n
= nStreams
- (curStream
+ 1);
1731 *ppas
= pInStreams
[curStream
+ 1];
1737 } /* create output streams for all input streams */
1739 /* have we still something to write, or lost everything? */
1744 LONG lCurFrame
= -dwFileInitialFrames
;
1746 /* interleaved file */
1747 if (dwInterleave
== 1)
1748 AVIFileEndRecord(pfile
);
1750 for (; lCurFrame
< lFileLength
; lCurFrame
+= lSampleInc
) {
1751 for (curStream
= 0; curStream
< nStreams
; curStream
++) {
1754 hres
= AVIStreamInfoW(pOutStreams
[curStream
], &sInfo
, sizeof(sInfo
));
1758 /* initial frames phase at the end for this stream? */
1759 if (-(LONG
)sInfo
.dwInitialFrames
> lCurFrame
)
1762 if ((lFileLength
- lSampleInc
) <= lCurFrame
) {
1763 lLastSample
= AVIStreamLength(pInStreams
[curStream
]);
1764 lFirstVideo
= lLastSample
+ AVIStreamStart(pInStreams
[curStream
]);
1766 if (curStream
!= 0) {
1768 AVIStreamSampleToSample(pInStreams
[curStream
], pInStreams
[0],
1769 (sInfo
.fccType
== streamtypeVIDEO
?
1770 (LONG
)dwInterleave
: lSampleInc
) +
1771 sInfo
.dwInitialFrames
+ lCurFrame
);
1773 lFirstVideo
= lSampleInc
+ (sInfo
.dwInitialFrames
+ lCurFrame
);
1775 lLastSample
= AVIStreamEnd(pInStreams
[curStream
]);
1776 if (lLastSample
<= lFirstVideo
)
1777 lFirstVideo
= lLastSample
;
1780 /* copy needed samples now */
1781 WARN("copy from stream %d samples %d to %d...\n",curStream
,
1782 lStart
[curStream
],lFirstVideo
);
1783 while (lFirstVideo
> lStart
[curStream
]) {
1786 /* copy format in case it can change */
1787 lBufferSize
= cbBuffer
;
1788 hres
= AVIStreamReadFormat(pInStreams
[curStream
], lStart
[curStream
],
1789 lpBuffer
, &lBufferSize
);
1792 AVIStreamSetFormat(pOutStreams
[curStream
], lStart
[curStream
],
1793 lpBuffer
, lBufferSize
);
1795 /* try to read data until we got it, or error */
1797 hres
= AVIStreamRead(pInStreams
[curStream
], lStart
[curStream
],
1798 lFirstVideo
- lStart
[curStream
], lpBuffer
,
1799 cbBuffer
, &lReadBytes
, &lReadSamples
);
1800 } while ((hres
== AVIERR_BUFFERTOOSMALL
) &&
1801 (lpBuffer
= HeapReAlloc(GetProcessHeap(), 0, lpBuffer
, cbBuffer
*= 2)) != NULL
);
1802 if (lpBuffer
== NULL
)
1803 hres
= AVIERR_MEMORY
;
1807 if (AVIStreamIsKeyFrame(pInStreams
[curStream
], (LONG
)sInfo
.dwStart
))
1808 flags
= AVIIF_KEYFRAME
;
1809 hres
= AVIStreamWrite(pOutStreams
[curStream
], -1, lReadSamples
,
1810 lpBuffer
, lReadBytes
, flags
, NULL
, NULL
);
1814 lStart
[curStream
] += lReadSamples
;
1816 lStart
[curStream
] = lFirstVideo
;
1817 } /* stream by stream */
1819 /* need to close this block? */
1820 if (dwInterleave
== 1) {
1821 hres
= AVIFileEndRecord(pfile
);
1827 if (lpfnCallback(MulDiv(dwFileInitialFrames
+ lCurFrame
, 100,
1828 dwFileInitialFrames
+ lFileLength
))) {
1829 hres
= AVIERR_USERABORT
;
1832 } /* copy frame by frame */
1834 /* non-interleaved file */
1836 for (curStream
= 0; curStream
< nStreams
; curStream
++) {
1838 if (lpfnCallback(MulDiv(curStream
, 100, nStreams
))) {
1839 hres
= AVIERR_USERABORT
;
1843 AVIStreamInfoW(pInStreams
[curStream
], &sInfo
, sizeof(sInfo
));
1845 if (sInfo
.dwSampleSize
!= 0) {
1846 /* sample-based data like audio */
1847 while (sInfo
.dwStart
< sInfo
.dwLength
) {
1848 LONG lSamples
= cbBuffer
/ sInfo
.dwSampleSize
;
1850 /* copy format in case it can change */
1851 lBufferSize
= cbBuffer
;
1852 hres
= AVIStreamReadFormat(pInStreams
[curStream
], sInfo
.dwStart
,
1853 lpBuffer
, &lBufferSize
);
1856 AVIStreamSetFormat(pOutStreams
[curStream
], sInfo
.dwStart
,
1857 lpBuffer
, lBufferSize
);
1859 /* limit to stream boundaries */
1860 if (lSamples
!= (LONG
)(sInfo
.dwLength
- sInfo
.dwStart
))
1861 lSamples
= sInfo
.dwLength
- sInfo
.dwStart
;
1863 /* now try to read until we get it, or an error occurs */
1865 lReadBytes
= cbBuffer
;
1867 hres
= AVIStreamRead(pInStreams
[curStream
],sInfo
.dwStart
,lSamples
,
1868 lpBuffer
,cbBuffer
,&lReadBytes
,&lReadSamples
);
1869 } while ((hres
== AVIERR_BUFFERTOOSMALL
) &&
1870 (lpBuffer
= HeapReAlloc(GetProcessHeap(), 0, lpBuffer
, cbBuffer
*= 2)) != NULL
);
1871 if (lpBuffer
== NULL
)
1872 hres
= AVIERR_MEMORY
;
1875 if (lReadSamples
!= 0) {
1876 sInfo
.dwStart
+= lReadSamples
;
1877 hres
= AVIStreamWrite(pOutStreams
[curStream
], -1, lReadSamples
,
1878 lpBuffer
, lReadBytes
, 0, NULL
, NULL
);
1883 if (lpfnCallback(MulDiv(sInfo
.dwStart
,100,nStreams
*sInfo
.dwLength
)+
1884 MulDiv(curStream
, 100, nStreams
))) {
1885 hres
= AVIERR_USERABORT
;
1889 if ((sInfo
.dwLength
- sInfo
.dwStart
) != 1) {
1890 hres
= AVIERR_FILEREAD
;
1896 /* block-based data like video */
1897 for (; sInfo
.dwStart
< sInfo
.dwLength
; sInfo
.dwStart
++) {
1900 /* copy format in case it can change */
1901 lBufferSize
= cbBuffer
;
1902 hres
= AVIStreamReadFormat(pInStreams
[curStream
], sInfo
.dwStart
,
1903 lpBuffer
, &lBufferSize
);
1906 AVIStreamSetFormat(pOutStreams
[curStream
], sInfo
.dwStart
,
1907 lpBuffer
, lBufferSize
);
1909 /* try to read block and resize buffer if necessary */
1912 lReadBytes
= cbBuffer
;
1913 hres
= AVIStreamRead(pInStreams
[curStream
], sInfo
.dwStart
, 1,
1914 lpBuffer
, cbBuffer
,&lReadBytes
,&lReadSamples
);
1915 } while ((hres
== AVIERR_BUFFERTOOSMALL
) &&
1916 (lpBuffer
= HeapReAlloc(GetProcessHeap(), 0, lpBuffer
, cbBuffer
*= 2)) != NULL
);
1917 if (lpBuffer
== NULL
)
1918 hres
= AVIERR_MEMORY
;
1921 if (lReadSamples
!= 1) {
1922 hres
= AVIERR_FILEREAD
;
1926 if (AVIStreamIsKeyFrame(pInStreams
[curStream
], (LONG
)sInfo
.dwStart
))
1927 flags
= AVIIF_KEYFRAME
;
1928 hres
= AVIStreamWrite(pOutStreams
[curStream
], -1, lReadSamples
,
1929 lpBuffer
, lReadBytes
, flags
, NULL
, NULL
);
1934 if (lpfnCallback(MulDiv(sInfo
.dwStart
,100,nStreams
*sInfo
.dwLength
)+
1935 MulDiv(curStream
, 100, nStreams
))) {
1936 hres
= AVIERR_USERABORT
;
1939 } /* copy all blocks */
1941 } /* copy data stream by stream */
1945 HeapFree(GetProcessHeap(), 0, lpBuffer
);
1946 if (pfile
!= NULL
) {
1947 for (curStream
= 0; curStream
< nStreams
; curStream
++) {
1948 if (pOutStreams
[curStream
] != NULL
)
1949 AVIStreamRelease(pOutStreams
[curStream
]);
1950 if (pInStreams
[curStream
] != NULL
)
1951 AVIStreamRelease(pInStreams
[curStream
]);
1954 AVIFileRelease(pfile
);
1960 /***********************************************************************
1961 * CreateEditableStream (AVIFIL32.@)
1963 HRESULT WINAPI
CreateEditableStream(PAVISTREAM
*ppEditable
, PAVISTREAM pSource
)
1965 IAVIEditStream
*pEdit
= NULL
;
1968 TRACE("(%p,%p)\n", ppEditable
, pSource
);
1970 if (ppEditable
== NULL
)
1971 return AVIERR_BADPARAM
;
1975 if (pSource
!= NULL
) {
1976 hr
= IAVIStream_QueryInterface(pSource
, &IID_IAVIEditStream
,
1978 if (SUCCEEDED(hr
) && pEdit
!= NULL
) {
1979 hr
= IAVIEditStream_Clone(pEdit
, ppEditable
);
1980 IAVIEditStream_Release(pEdit
);
1986 /* need own implementation of IAVIEditStream */
1987 pEdit
= AVIFILE_CreateEditStream(pSource
);
1989 return AVIERR_MEMORY
;
1991 hr
= IAVIEditStream_QueryInterface(pEdit
, &IID_IAVIStream
,
1992 (LPVOID
*)ppEditable
);
1993 IAVIEditStream_Release(pEdit
);
1998 /***********************************************************************
1999 * EditStreamClone (AVIFIL32.@)
2001 HRESULT WINAPI
EditStreamClone(PAVISTREAM pStream
, PAVISTREAM
*ppResult
)
2003 PAVIEDITSTREAM pEdit
= NULL
;
2006 TRACE("(%p,%p)\n", pStream
, ppResult
);
2008 if (pStream
== NULL
)
2009 return AVIERR_BADHANDLE
;
2010 if (ppResult
== NULL
)
2011 return AVIERR_BADPARAM
;
2015 hr
= IAVIStream_QueryInterface(pStream
, &IID_IAVIEditStream
,(LPVOID
*)&pEdit
);
2016 if (SUCCEEDED(hr
) && pEdit
!= NULL
) {
2017 hr
= IAVIEditStream_Clone(pEdit
, ppResult
);
2019 IAVIEditStream_Release(pEdit
);
2021 hr
= AVIERR_UNSUPPORTED
;
2026 /***********************************************************************
2027 * EditStreamCopy (AVIFIL32.@)
2029 HRESULT WINAPI
EditStreamCopy(PAVISTREAM pStream
, LONG
*plStart
,
2030 LONG
*plLength
, PAVISTREAM
*ppResult
)
2032 PAVIEDITSTREAM pEdit
= NULL
;
2035 TRACE("(%p,%p,%p,%p)\n", pStream
, plStart
, plLength
, ppResult
);
2037 if (pStream
== NULL
)
2038 return AVIERR_BADHANDLE
;
2039 if (plStart
== NULL
|| plLength
== NULL
|| ppResult
== NULL
)
2040 return AVIERR_BADPARAM
;
2044 hr
= IAVIStream_QueryInterface(pStream
, &IID_IAVIEditStream
,(LPVOID
*)&pEdit
);
2045 if (SUCCEEDED(hr
) && pEdit
!= NULL
) {
2046 hr
= IAVIEditStream_Copy(pEdit
, plStart
, plLength
, ppResult
);
2048 IAVIEditStream_Release(pEdit
);
2050 hr
= AVIERR_UNSUPPORTED
;
2055 /***********************************************************************
2056 * EditStreamCut (AVIFIL32.@)
2058 HRESULT WINAPI
EditStreamCut(PAVISTREAM pStream
, LONG
*plStart
,
2059 LONG
*plLength
, PAVISTREAM
*ppResult
)
2061 PAVIEDITSTREAM pEdit
= NULL
;
2064 TRACE("(%p,%p,%p,%p)\n", pStream
, plStart
, plLength
, ppResult
);
2066 if (ppResult
!= NULL
)
2068 if (pStream
== NULL
)
2069 return AVIERR_BADHANDLE
;
2070 if (plStart
== NULL
|| plLength
== NULL
)
2071 return AVIERR_BADPARAM
;
2073 hr
= IAVIStream_QueryInterface(pStream
, &IID_IAVIEditStream
,(LPVOID
*)&pEdit
);
2074 if (SUCCEEDED(hr
) && pEdit
!= NULL
) {
2075 hr
= IAVIEditStream_Cut(pEdit
, plStart
, plLength
, ppResult
);
2077 IAVIEditStream_Release(pEdit
);
2079 hr
= AVIERR_UNSUPPORTED
;
2084 /***********************************************************************
2085 * EditStreamPaste (AVIFIL32.@)
2087 HRESULT WINAPI
EditStreamPaste(PAVISTREAM pDest
, LONG
*plStart
, LONG
*plLength
,
2088 PAVISTREAM pSource
, LONG lStart
, LONG lEnd
)
2090 PAVIEDITSTREAM pEdit
= NULL
;
2093 TRACE("(%p,%p,%p,%p,%d,%d)\n", pDest
, plStart
, plLength
,
2094 pSource
, lStart
, lEnd
);
2096 if (pDest
== NULL
|| pSource
== NULL
)
2097 return AVIERR_BADHANDLE
;
2098 if (plStart
== NULL
|| plLength
== NULL
|| lStart
< 0)
2099 return AVIERR_BADPARAM
;
2101 hr
= IAVIStream_QueryInterface(pDest
, &IID_IAVIEditStream
,(LPVOID
*)&pEdit
);
2102 if (SUCCEEDED(hr
) && pEdit
!= NULL
) {
2103 hr
= IAVIEditStream_Paste(pEdit
, plStart
, plLength
, pSource
, lStart
, lEnd
);
2105 IAVIEditStream_Release(pEdit
);
2107 hr
= AVIERR_UNSUPPORTED
;
2112 /***********************************************************************
2113 * EditStreamSetInfoA (AVIFIL32.@)
2115 HRESULT WINAPI
EditStreamSetInfoA(PAVISTREAM pstream
, LPAVISTREAMINFOA asi
,
2118 AVISTREAMINFOW asiw
;
2120 TRACE("(%p,%p,%d)\n", pstream
, asi
, size
);
2122 if (size
>= 0 && size
< sizeof(AVISTREAMINFOA
))
2123 return AVIERR_BADSIZE
;
2125 memcpy(&asiw
, asi
, sizeof(asiw
) - sizeof(asiw
.szName
));
2126 MultiByteToWideChar(CP_ACP
, 0, asi
->szName
, -1,
2127 asiw
.szName
, sizeof(asiw
.szName
)/sizeof(WCHAR
));
2129 return EditStreamSetInfoW(pstream
, &asiw
, sizeof(asiw
));
2132 /***********************************************************************
2133 * EditStreamSetInfoW (AVIFIL32.@)
2135 HRESULT WINAPI
EditStreamSetInfoW(PAVISTREAM pstream
, LPAVISTREAMINFOW asi
,
2138 PAVIEDITSTREAM pEdit
= NULL
;
2141 TRACE("(%p,%p,%d)\n", pstream
, asi
, size
);
2143 if (size
>= 0 && size
< sizeof(AVISTREAMINFOA
))
2144 return AVIERR_BADSIZE
;
2146 hr
= IAVIStream_QueryInterface(pstream
, &IID_IAVIEditStream
,(LPVOID
*)&pEdit
);
2147 if (SUCCEEDED(hr
) && pEdit
!= NULL
) {
2148 hr
= IAVIEditStream_SetInfo(pEdit
, asi
, size
);
2150 IAVIEditStream_Release(pEdit
);
2152 hr
= AVIERR_UNSUPPORTED
;
2157 /***********************************************************************
2158 * EditStreamSetNameA (AVIFIL32.@)
2160 HRESULT WINAPI
EditStreamSetNameA(PAVISTREAM pstream
, LPCSTR szName
)
2162 AVISTREAMINFOA asia
;
2165 TRACE("(%p,%s)\n", pstream
, debugstr_a(szName
));
2167 if (pstream
== NULL
)
2168 return AVIERR_BADHANDLE
;
2170 return AVIERR_BADPARAM
;
2172 hres
= AVIStreamInfoA(pstream
, &asia
, sizeof(asia
));
2176 memset(asia
.szName
, 0, sizeof(asia
.szName
));
2177 lstrcpynA(asia
.szName
, szName
, sizeof(asia
.szName
)/sizeof(asia
.szName
[0]));
2179 return EditStreamSetInfoA(pstream
, &asia
, sizeof(asia
));
2182 /***********************************************************************
2183 * EditStreamSetNameW (AVIFIL32.@)
2185 HRESULT WINAPI
EditStreamSetNameW(PAVISTREAM pstream
, LPCWSTR szName
)
2187 AVISTREAMINFOW asiw
;
2190 TRACE("(%p,%s)\n", pstream
, debugstr_w(szName
));
2192 if (pstream
== NULL
)
2193 return AVIERR_BADHANDLE
;
2195 return AVIERR_BADPARAM
;
2197 hres
= IAVIStream_Info(pstream
, &asiw
, sizeof(asiw
));
2201 memset(asiw
.szName
, 0, sizeof(asiw
.szName
));
2202 lstrcpynW(asiw
.szName
, szName
, sizeof(asiw
.szName
)/sizeof(asiw
.szName
[0]));
2204 return EditStreamSetInfoW(pstream
, &asiw
, sizeof(asiw
));
2207 /***********************************************************************
2208 * AVIClearClipboard (AVIFIL32.@)
2210 HRESULT WINAPI
AVIClearClipboard(void)
2214 return AVIERR_UNSUPPORTED
; /* OleSetClipboard(NULL); */
2217 /***********************************************************************
2218 * AVIGetFromClipboard (AVIFIL32.@)
2220 HRESULT WINAPI
AVIGetFromClipboard(PAVIFILE
*ppfile
)
2222 FIXME("(%p), stub!\n", ppfile
);
2226 return AVIERR_UNSUPPORTED
;
2229 /***********************************************************************
2230 * AVIMakeStreamFromClipboard (AVIFIL32.@)
2232 HRESULT WINAPI
AVIMakeStreamFromClipboard(UINT cfFormat
, HANDLE hGlobal
,
2233 PAVISTREAM
* ppstream
)
2235 FIXME("(0x%08x,%p,%p), stub!\n", cfFormat
, hGlobal
, ppstream
);
2237 if (ppstream
== NULL
)
2238 return AVIERR_BADHANDLE
;
2240 return AVIERR_UNSUPPORTED
;
2243 /***********************************************************************
2244 * AVIPutFileOnClipboard (AVIFIL32.@)
2246 HRESULT WINAPI
AVIPutFileOnClipboard(PAVIFILE pfile
)
2248 FIXME("(%p), stub!\n", pfile
);
2251 return AVIERR_BADHANDLE
;
2253 return AVIERR_UNSUPPORTED
;
2256 HRESULT WINAPIV
AVISaveA(LPCSTR szFile
, CLSID
* pclsidHandler
, AVISAVECALLBACK lpfnCallback
,
2257 int nStreams
, PAVISTREAM pavi
, LPAVICOMPRESSOPTIONS lpOptions
, ...)
2259 FIXME("(%s,%p,%p,0x%08x,%p,%p), stub!\n", debugstr_a(szFile
), pclsidHandler
, lpfnCallback
,
2260 nStreams
, pavi
, lpOptions
);
2262 return AVIERR_UNSUPPORTED
;
2265 HRESULT WINAPIV
AVISaveW(LPCWSTR szFile
, CLSID
* pclsidHandler
, AVISAVECALLBACK lpfnCallback
,
2266 int nStreams
, PAVISTREAM pavi
, LPAVICOMPRESSOPTIONS lpOptions
, ...)
2268 FIXME("(%s,%p,%p,0x%08x,%p,%p), stub!\n", debugstr_w(szFile
), pclsidHandler
, lpfnCallback
,
2269 nStreams
, pavi
, lpOptions
);
2271 return AVIERR_UNSUPPORTED
;