blob: fd6d9ecca48580f962343ec12e0046099409bc36 [file] [log] [blame]
Michael Günnewig4c04e1f2002-10-18 00:24:41 +00001/*
Alexandre Julliard4f324b32008-10-18 19:19:02 +02002 * Copyright 2002 Michael Günnewig
Michael Günnewig4c04e1f2002-10-18 00:24:41 +00003 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
Jonathan Ernst360a3f92006-05-18 14:49:52 +020016 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Michael Günnewig4c04e1f2002-10-18 00:24:41 +000017 */
18
19#include <assert.h>
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000020#include <stdarg.h>
Michael Günnewig4c04e1f2002-10-18 00:24:41 +000021
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000022#include "windef.h"
Michael Günnewig4c04e1f2002-10-18 00:24:41 +000023#include "winbase.h"
Alexandre Julliarde37c6e12003-09-05 23:08:26 +000024#include "wingdi.h"
Michael Günnewig4c04e1f2002-10-18 00:24:41 +000025#include "winuser.h"
26#include "winnls.h"
27#include "winerror.h"
Michael Günnewig4c04e1f2002-10-18 00:24:41 +000028#include "mmsystem.h"
29#include "vfw.h"
Michael Günnewig45af4922002-10-19 00:12:06 +000030#include "msacm.h"
Michael Günnewig4c04e1f2002-10-18 00:24:41 +000031
32#include "avifile_private.h"
33#include "extrachunk.h"
34
Mike McCormack87bacf42004-07-04 00:11:31 +000035#include "wine/unicode.h"
Michael Günnewig4c04e1f2002-10-18 00:24:41 +000036#include "wine/debug.h"
37
38WINE_DEFAULT_DEBUG_CHANNEL(avifile);
39
40/***********************************************************************/
41
42#define formtypeWAVE mmioFOURCC('W','A','V','E')
43#define ckidWAVEFORMAT mmioFOURCC('f','m','t',' ')
44#define ckidWAVEFACT mmioFOURCC('f','a','c','t')
45#define ckidWAVEDATA mmioFOURCC('d','a','t','a')
46
47/***********************************************************************/
48
Michael Günnewig645a36c2003-07-21 20:00:36 +000049#define ENDIAN_SWAPWORD(x) ((((x) >> 8) & 0xFF) | (((x) & 0xFF) << 8))
50#define ENDIAN_SWAPDWORD(x) (ENDIAN_SWAPWORD((x >> 16) & 0xFFFF) | \
51 ENDIAN_SWAPWORD(x & 0xFFFF) << 16)
52
53#ifdef WORDS_BIGENDIAN
54#define BE2H_WORD(x) (x)
55#define BE2H_DWORD(x) (x)
56#define LE2H_WORD(x) ENDIAN_SWAPWORD(x)
57#define LE2H_DWORD(x) ENDIAN_SWAPDWORD(x)
58#else
59#define BE2H_WORD(x) ENDIAN_SWAPWORD(x)
60#define BE2H_DWORD(x) ENDIAN_SWAPDWORD(x)
61#define LE2H_WORD(x) (x)
62#define LE2H_DWORD(x) (x)
63#endif
64
65typedef struct {
66 FOURCC fccType;
67 DWORD offset;
68 DWORD size;
69 INT encoding;
70 DWORD sampleRate;
71 DWORD channels;
72} SUNAUDIOHEADER;
73
74#define AU_ENCODING_ULAW_8 1
75#define AU_ENCODING_PCM_8 2
76#define AU_ENCODING_PCM_16 3
77#define AU_ENCODING_PCM_24 4
78#define AU_ENCODING_PCM_32 5
79#define AU_ENCODING_FLOAT 6
80#define AU_ENCODING_DOUBLE 7
81#define AU_ENCODING_ADPCM_G721_32 23
82#define AU_ENCODING_ADPCM_G722 24
83#define AU_ENCODING_ADPCM_G723_24 25
84#define AU_ENCODING_ADPCM_G723_5 26
85#define AU_ENCODING_ALAW_8 27
86
87/***********************************************************************/
88
Michael Günnewig4c04e1f2002-10-18 00:24:41 +000089static HRESULT WINAPI IAVIFile_fnQueryInterface(IAVIFile* iface,REFIID refiid,LPVOID *obj);
90static ULONG WINAPI IAVIFile_fnAddRef(IAVIFile* iface);
91static ULONG WINAPI IAVIFile_fnRelease(IAVIFile* iface);
92static HRESULT WINAPI IAVIFile_fnInfo(IAVIFile*iface,AVIFILEINFOW*afi,LONG size);
93static HRESULT WINAPI IAVIFile_fnGetStream(IAVIFile*iface,PAVISTREAM*avis,DWORD fccType,LONG lParam);
94static HRESULT WINAPI IAVIFile_fnCreateStream(IAVIFile*iface,PAVISTREAM*avis,AVISTREAMINFOW*asi);
95static HRESULT WINAPI IAVIFile_fnWriteData(IAVIFile*iface,DWORD ckid,LPVOID lpData,LONG size);
96static HRESULT WINAPI IAVIFile_fnReadData(IAVIFile*iface,DWORD ckid,LPVOID lpData,LONG *size);
97static HRESULT WINAPI IAVIFile_fnEndRecord(IAVIFile*iface);
98static HRESULT WINAPI IAVIFile_fnDeleteStream(IAVIFile*iface,DWORD fccType,LONG lParam);
99
Dmitry Timoshkov46256282005-05-27 20:17:35 +0000100static const struct IAVIFileVtbl iwavft = {
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000101 IAVIFile_fnQueryInterface,
102 IAVIFile_fnAddRef,
103 IAVIFile_fnRelease,
104 IAVIFile_fnInfo,
105 IAVIFile_fnGetStream,
106 IAVIFile_fnCreateStream,
107 IAVIFile_fnWriteData,
108 IAVIFile_fnReadData,
109 IAVIFile_fnEndRecord,
110 IAVIFile_fnDeleteStream
111};
112
113static HRESULT WINAPI IPersistFile_fnQueryInterface(IPersistFile*iface,REFIID refiid,LPVOID*obj);
114static ULONG WINAPI IPersistFile_fnAddRef(IPersistFile*iface);
115static ULONG WINAPI IPersistFile_fnRelease(IPersistFile*iface);
116static HRESULT WINAPI IPersistFile_fnGetClassID(IPersistFile*iface,CLSID*pClassID);
117static HRESULT WINAPI IPersistFile_fnIsDirty(IPersistFile*iface);
118static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile*iface,LPCOLESTR pszFileName,DWORD dwMode);
119static HRESULT WINAPI IPersistFile_fnSave(IPersistFile*iface,LPCOLESTR pszFileName,BOOL fRemember);
120static HRESULT WINAPI IPersistFile_fnSaveCompleted(IPersistFile*iface,LPCOLESTR pszFileName);
121static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile*iface,LPOLESTR*ppszFileName);
122
Dmitry Timoshkov46256282005-05-27 20:17:35 +0000123static const struct IPersistFileVtbl iwavpft = {
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000124 IPersistFile_fnQueryInterface,
125 IPersistFile_fnAddRef,
126 IPersistFile_fnRelease,
127 IPersistFile_fnGetClassID,
128 IPersistFile_fnIsDirty,
129 IPersistFile_fnLoad,
130 IPersistFile_fnSave,
131 IPersistFile_fnSaveCompleted,
132 IPersistFile_fnGetCurFile
133};
134
135static HRESULT WINAPI IAVIStream_fnQueryInterface(IAVIStream*iface,REFIID refiid,LPVOID *obj);
136static ULONG WINAPI IAVIStream_fnAddRef(IAVIStream*iface);
137static ULONG WINAPI IAVIStream_fnRelease(IAVIStream* iface);
138static HRESULT WINAPI IAVIStream_fnCreate(IAVIStream*iface,LPARAM lParam1,LPARAM lParam2);
139static HRESULT WINAPI IAVIStream_fnInfo(IAVIStream*iface,AVISTREAMINFOW *psi,LONG size);
140static LONG WINAPI IAVIStream_fnFindSample(IAVIStream*iface,LONG pos,LONG flags);
141static HRESULT WINAPI IAVIStream_fnReadFormat(IAVIStream*iface,LONG pos,LPVOID format,LONG *formatsize);
142static HRESULT WINAPI IAVIStream_fnSetFormat(IAVIStream*iface,LONG pos,LPVOID format,LONG formatsize);
143static HRESULT WINAPI IAVIStream_fnRead(IAVIStream*iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,LONG *bytesread,LONG *samplesread);
144static HRESULT WINAPI IAVIStream_fnWrite(IAVIStream*iface,LONG start,LONG samples,LPVOID buffer,LONG buffersize,DWORD flags,LONG *sampwritten,LONG *byteswritten);
145static HRESULT WINAPI IAVIStream_fnDelete(IAVIStream*iface,LONG start,LONG samples);
146static HRESULT WINAPI IAVIStream_fnReadData(IAVIStream*iface,DWORD fcc,LPVOID lp,LONG *lpread);
147static HRESULT WINAPI IAVIStream_fnWriteData(IAVIStream*iface,DWORD fcc,LPVOID lp,LONG size);
148static HRESULT WINAPI IAVIStream_fnSetInfo(IAVIStream*iface,AVISTREAMINFOW*info,LONG infolen);
149
Dmitry Timoshkov46256282005-05-27 20:17:35 +0000150static const struct IAVIStreamVtbl iwavst = {
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000151 IAVIStream_fnQueryInterface,
152 IAVIStream_fnAddRef,
153 IAVIStream_fnRelease,
154 IAVIStream_fnCreate,
155 IAVIStream_fnInfo,
156 IAVIStream_fnFindSample,
157 IAVIStream_fnReadFormat,
158 IAVIStream_fnSetFormat,
159 IAVIStream_fnRead,
160 IAVIStream_fnWrite,
161 IAVIStream_fnDelete,
162 IAVIStream_fnReadData,
163 IAVIStream_fnWriteData,
164 IAVIStream_fnSetInfo
165};
166
167typedef struct _IAVIFileImpl IAVIFileImpl;
168
169typedef struct _IPersistFileImpl {
170 /* IUnknown stuff */
Dmitry Timoshkov46256282005-05-27 20:17:35 +0000171 const IPersistFileVtbl *lpVtbl;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000172
173 /* IPersistFile stuff */
174 IAVIFileImpl *paf;
175} IPersistFileImpl;
176
177typedef struct _IAVIStreamImpl {
178 /* IUnknown stuff */
Dmitry Timoshkov46256282005-05-27 20:17:35 +0000179 const IAVIStreamVtbl *lpVtbl;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000180
181 /* IAVIStream stuff */
182 IAVIFileImpl *paf;
183} IAVIStreamImpl;
184
185struct _IAVIFileImpl {
186 /* IUnknown stuff */
Dmitry Timoshkov46256282005-05-27 20:17:35 +0000187 const IAVIFileVtbl *lpVtbl;
Mike McCormack723ee0a2005-07-05 14:26:54 +0000188 LONG ref;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000189
190 /* IAVIFile, IAVIStream stuff... */
191 IPersistFileImpl iPersistFile;
192 IAVIStreamImpl iAVIStream;
193
194 AVIFILEINFOW fInfo;
195 AVISTREAMINFOW sInfo;
196
197 LPWAVEFORMATEX lpFormat;
198 LONG cbFormat;
199
200 MMCKINFO ckData;
201
202 EXTRACHUNKS extra;
203
204 /* IPersistFile stuff ... */
205 HMMIO hmmio;
206 LPWSTR szFileName;
207 UINT uMode;
208 BOOL fDirty;
209};
210
211/***********************************************************************/
212
213static HRESULT AVIFILE_LoadFile(IAVIFileImpl *This);
214static HRESULT AVIFILE_LoadSunFile(IAVIFileImpl *This);
Andrew Talbotb01c2c82007-04-02 22:50:46 +0100215static HRESULT AVIFILE_SaveFile(const IAVIFileImpl *This);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000216
217HRESULT AVIFILE_CreateWAVFile(REFIID riid, LPVOID *ppv)
218{
219 IAVIFileImpl *pfile;
220 HRESULT hr;
221
222 assert(riid != NULL && ppv != NULL);
223
224 *ppv = NULL;
225
Mike McCormackaebc88d2006-04-11 20:44:02 +0900226 pfile = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IAVIFileImpl));
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000227 if (pfile == NULL)
228 return AVIERR_MEMORY;
229
Alexandre Julliardc2ebe1f2003-04-10 18:17:34 +0000230 pfile->lpVtbl = &iwavft;
231 pfile->iPersistFile.lpVtbl = &iwavpft;
232 pfile->iAVIStream.lpVtbl = &iwavst;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000233 pfile->ref = 0;
234 pfile->iPersistFile.paf = pfile;
235 pfile->iAVIStream.paf = pfile;
236
Francois Gougeta8d2ba92004-10-05 18:10:21 +0000237 hr = IAVIFile_QueryInterface((IAVIFile*)pfile, riid, ppv);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000238 if (FAILED(hr))
Mike McCormack610fc082006-03-11 00:21:42 +0900239 HeapFree(GetProcessHeap(), 0, pfile);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000240
241 return hr;
242}
243
244static HRESULT WINAPI IAVIFile_fnQueryInterface(IAVIFile *iface, REFIID refiid,
245 LPVOID *obj)
246{
Alexandre Julliard39a696a2004-09-06 20:34:29 +0000247 IAVIFileImpl *This = (IAVIFileImpl *)iface;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000248
249 TRACE("(%p,%s,%p)\n", This, debugstr_guid(refiid), obj);
250
251 if (IsEqualGUID(&IID_IUnknown, refiid) ||
252 IsEqualGUID(&IID_IAVIFile, refiid)) {
253 *obj = iface;
Francois Gougetf884cf02009-03-10 12:38:20 +0100254 IAVIFile_AddRef(iface);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000255 return S_OK;
256 } else if (This->fInfo.dwStreams == 1 &&
257 IsEqualGUID(&IID_IAVIStream, refiid)) {
258 *obj = &This->iAVIStream;
Francois Gougetf884cf02009-03-10 12:38:20 +0100259 IAVIFile_AddRef(iface);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000260 return S_OK;
261 } else if (IsEqualGUID(&IID_IPersistFile, refiid)) {
262 *obj = &This->iPersistFile;
Francois Gougetf884cf02009-03-10 12:38:20 +0100263 IAVIFile_AddRef(iface);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000264 return S_OK;
265 }
266
267 return OLE_E_ENUM_NOMORE;
268}
269
270static ULONG WINAPI IAVIFile_fnAddRef(IAVIFile *iface)
271{
Alexandre Julliard39a696a2004-09-06 20:34:29 +0000272 IAVIFileImpl *This = (IAVIFileImpl *)iface;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000273
274 TRACE("(%p)\n",iface);
275
Paul Vriensc905d692005-01-14 15:10:52 +0000276 return InterlockedIncrement(&This->ref);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000277}
278
279static ULONG WINAPI IAVIFile_fnRelease(IAVIFile *iface)
280{
Alexandre Julliard39a696a2004-09-06 20:34:29 +0000281 IAVIFileImpl *This = (IAVIFileImpl *)iface;
Paul Vriensc905d692005-01-14 15:10:52 +0000282 ULONG ref = InterlockedDecrement(&This->ref);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000283
284 TRACE("(%p)\n",iface);
285
Paul Vriensc905d692005-01-14 15:10:52 +0000286 if (!ref) {
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000287 if (This->fDirty) {
288 /* need to write headers to file */
289 AVIFILE_SaveFile(This);
290 }
291
292 if (This->lpFormat != NULL) {
Mike McCormack610fc082006-03-11 00:21:42 +0900293 HeapFree(GetProcessHeap(), 0, This->lpFormat);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000294 This->lpFormat = NULL;
295 This->cbFormat = 0;
296 }
297 if (This->extra.lp != NULL) {
Mike McCormack610fc082006-03-11 00:21:42 +0900298 HeapFree(GetProcessHeap(), 0, This->extra.lp);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000299 This->extra.lp = NULL;
300 This->extra.cb = 0;
301 }
Michael Stefaniucfee72b62006-06-12 00:11:36 +0200302 HeapFree(GetProcessHeap(), 0, This->szFileName);
303 This->szFileName = NULL;
Francois Gougetd2667a42002-12-02 18:10:57 +0000304 if (This->hmmio != NULL) {
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000305 mmioClose(This->hmmio, 0);
Francois Gougetd2667a42002-12-02 18:10:57 +0000306 This->hmmio = NULL;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000307 }
308
Mike McCormack610fc082006-03-11 00:21:42 +0900309 HeapFree(GetProcessHeap(), 0, This);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000310 return 0;
311 }
Paul Vriensc905d692005-01-14 15:10:52 +0000312 return ref;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000313}
314
315static HRESULT WINAPI IAVIFile_fnInfo(IAVIFile *iface, LPAVIFILEINFOW afi,
316 LONG size)
317{
Alexandre Julliard39a696a2004-09-06 20:34:29 +0000318 IAVIFileImpl *This = (IAVIFileImpl *)iface;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000319
Michael Stefaniucf041a2b2006-10-10 01:07:06 +0200320 TRACE("(%p,%p,%d)\n",iface,afi,size);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000321
322 if (afi == NULL)
323 return AVIERR_BADPARAM;
324 if (size < 0)
325 return AVIERR_BADSIZE;
326
327 /* update file info */
328 This->fInfo.dwFlags = 0;
329 This->fInfo.dwCaps = AVIFILECAPS_CANREAD|AVIFILECAPS_CANWRITE;
330 if (This->lpFormat != NULL) {
Michael Günnewig45af4922002-10-19 00:12:06 +0000331 assert(This->sInfo.dwScale != 0);
332
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000333 This->fInfo.dwStreams = 1;
334 This->fInfo.dwScale = This->sInfo.dwScale;
335 This->fInfo.dwRate = This->sInfo.dwRate;
336 This->fInfo.dwLength = This->sInfo.dwLength;
337 This->fInfo.dwSuggestedBufferSize = This->ckData.cksize;
Michael Günnewig45af4922002-10-19 00:12:06 +0000338 This->fInfo.dwMaxBytesPerSec =
339 MulDiv(This->sInfo.dwSampleSize,This->sInfo.dwRate,This->sInfo.dwScale);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000340 }
341
Michael Günnewig9f67cfe2003-06-23 18:10:06 +0000342 memcpy(afi, &This->fInfo, min((DWORD)size, sizeof(This->fInfo)));
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000343
Michael Günnewig9f67cfe2003-06-23 18:10:06 +0000344 if ((DWORD)size < sizeof(This->fInfo))
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000345 return AVIERR_BUFFERTOOSMALL;
346 return AVIERR_OK;
347}
348
349static HRESULT WINAPI IAVIFile_fnGetStream(IAVIFile *iface, PAVISTREAM *avis,
350 DWORD fccType, LONG lParam)
351{
Alexandre Julliard39a696a2004-09-06 20:34:29 +0000352 IAVIFileImpl *This = (IAVIFileImpl *)iface;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000353
Michael Stefaniucf041a2b2006-10-10 01:07:06 +0200354 TRACE("(%p,%p,0x%08X,%d)\n", iface, avis, fccType, lParam);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000355
356 /* check parameter */
357 if (avis == NULL)
358 return AVIERR_BADPARAM;
359
360 *avis = NULL;
361
362 /* Does our stream exists? */
363 if (lParam != 0 || This->fInfo.dwStreams == 0)
364 return AVIERR_NODATA;
365 if (fccType != 0 && fccType != streamtypeAUDIO)
366 return AVIERR_NODATA;
367
368 *avis = (PAVISTREAM)&This->iAVIStream;
369 IAVIFile_AddRef(iface);
370
371 return AVIERR_OK;
372}
373
374static HRESULT WINAPI IAVIFile_fnCreateStream(IAVIFile *iface,PAVISTREAM *avis,
375 LPAVISTREAMINFOW asi)
376{
Alexandre Julliard39a696a2004-09-06 20:34:29 +0000377 IAVIFileImpl *This = (IAVIFileImpl *)iface;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000378
379 TRACE("(%p,%p,%p)\n", iface, avis, asi);
380
381 /* check parameters */
382 if (avis == NULL || asi == NULL)
383 return AVIERR_BADPARAM;
384
385 *avis = NULL;
386
387 /* We only support one audio stream */
388 if (This->fInfo.dwStreams != 0 || This->lpFormat != NULL)
389 return AVIERR_UNSUPPORTED;
390 if (asi->fccType != streamtypeAUDIO)
391 return AVIERR_UNSUPPORTED;
392
393 /* Does the user have write permission? */
394 if ((This->uMode & MMIO_RWMODE) == 0)
395 return AVIERR_READONLY;
396
397 This->cbFormat = 0;
398 This->lpFormat = NULL;
399
400 memcpy(&This->sInfo, asi, sizeof(This->sInfo));
401
402 /* make sure streaminfo if okay for us */
403 This->sInfo.fccHandler = 0;
404 This->sInfo.dwFlags = 0;
405 This->sInfo.dwCaps = AVIFILECAPS_CANREAD|AVIFILECAPS_CANWRITE;
406 This->sInfo.dwStart = 0;
407 This->sInfo.dwInitialFrames = 0;
408 This->sInfo.dwFormatChangeCount = 0;
409 memset(&This->sInfo.rcFrame, 0, sizeof(This->sInfo.rcFrame));
410
411 This->fInfo.dwStreams = 1;
412 This->fInfo.dwScale = This->sInfo.dwScale;
413 This->fInfo.dwRate = This->sInfo.dwRate;
414 This->fInfo.dwLength = This->sInfo.dwLength;
415
416 This->ckData.dwDataOffset = 0;
417 This->ckData.cksize = 0;
418
419 *avis = (PAVISTREAM)&This->iAVIStream;
420 IAVIFile_AddRef(iface);
421
422 return AVIERR_OK;
423}
424
425static HRESULT WINAPI IAVIFile_fnWriteData(IAVIFile *iface, DWORD ckid,
426 LPVOID lpData, LONG size)
427{
Alexandre Julliard39a696a2004-09-06 20:34:29 +0000428 IAVIFileImpl *This = (IAVIFileImpl *)iface;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000429
Michael Stefaniucf041a2b2006-10-10 01:07:06 +0200430 TRACE("(%p,0x%08X,%p,%d)\n", iface, ckid, lpData, size);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000431
432 /* check parameters */
433 if (lpData == NULL)
434 return AVIERR_BADPARAM;
435 if (size < 0)
436 return AVIERR_BADSIZE;
437
438 /* Do we have write permission? */
439 if ((This->uMode & MMIO_RWMODE) == 0)
440 return AVIERR_READONLY;
441
442 This->fDirty = TRUE;
443
444 return WriteExtraChunk(&This->extra, ckid, lpData, size);
445}
446
447static HRESULT WINAPI IAVIFile_fnReadData(IAVIFile *iface, DWORD ckid,
448 LPVOID lpData, LONG *size)
449{
Alexandre Julliard39a696a2004-09-06 20:34:29 +0000450 IAVIFileImpl *This = (IAVIFileImpl *)iface;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000451
Michael Stefaniucf041a2b2006-10-10 01:07:06 +0200452 TRACE("(%p,0x%08X,%p,%p)\n", iface, ckid, lpData, size);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000453
454 return ReadExtraChunk(&This->extra, ckid, lpData, size);
455}
456
457static HRESULT WINAPI IAVIFile_fnEndRecord(IAVIFile *iface)
458{
459 TRACE("(%p)\n",iface);
460
461 /* This is only needed for interleaved files.
462 * We have only one stream, which can't be interleaved.
463 */
464 return AVIERR_OK;
465}
466
467static HRESULT WINAPI IAVIFile_fnDeleteStream(IAVIFile *iface, DWORD fccType,
468 LONG lParam)
469{
Alexandre Julliard39a696a2004-09-06 20:34:29 +0000470 IAVIFileImpl *This = (IAVIFileImpl *)iface;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000471
Michael Stefaniucf041a2b2006-10-10 01:07:06 +0200472 TRACE("(%p,0x%08X,%d)\n", iface, fccType, lParam);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000473
474 /* check parameter */
475 if (lParam < 0)
476 return AVIERR_BADPARAM;
477
Francois Gouget6fb1a202004-12-20 19:27:06 +0000478 /* Do we have our audio stream? */
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000479 if (lParam != 0 || This->fInfo.dwStreams == 0 ||
480 (fccType != 0 && fccType != streamtypeAUDIO))
481 return AVIERR_NODATA;
482
483 /* Have user write permissions? */
484 if ((This->uMode & MMIO_RWMODE) == 0)
485 return AVIERR_READONLY;
486
Mike McCormack610fc082006-03-11 00:21:42 +0900487 HeapFree(GetProcessHeap(), 0, This->lpFormat);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000488 This->lpFormat = NULL;
489 This->cbFormat = 0;
490
491 /* update infos */
492 This->ckData.dwDataOffset = 0;
493 This->ckData.cksize = 0;
494
495 This->sInfo.dwScale = 0;
496 This->sInfo.dwRate = 0;
497 This->sInfo.dwLength = 0;
498 This->sInfo.dwSuggestedBufferSize = 0;
499
500 This->fInfo.dwStreams = 0;
501 This->fInfo.dwEditCount++;
502
503 This->fDirty = TRUE;
504
505 return AVIERR_OK;
506}
507
508/***********************************************************************/
509
510static HRESULT WINAPI IPersistFile_fnQueryInterface(IPersistFile *iface,
511 REFIID refiid, LPVOID *obj)
512{
Alexandre Julliard39a696a2004-09-06 20:34:29 +0000513 IPersistFileImpl *This = (IPersistFileImpl *)iface;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000514
515 assert(This->paf != NULL);
516
517 return IAVIFile_QueryInterface((PAVIFILE)This->paf, refiid, obj);
518}
519
520static ULONG WINAPI IPersistFile_fnAddRef(IPersistFile *iface)
521{
Alexandre Julliard39a696a2004-09-06 20:34:29 +0000522 IPersistFileImpl *This = (IPersistFileImpl *)iface;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000523
524 assert(This->paf != NULL);
525
526 return IAVIFile_AddRef((PAVIFILE)This->paf);
527}
528
529static ULONG WINAPI IPersistFile_fnRelease(IPersistFile *iface)
530{
Alexandre Julliard39a696a2004-09-06 20:34:29 +0000531 IPersistFileImpl *This = (IPersistFileImpl *)iface;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000532
533 assert(This->paf != NULL);
534
535 return IAVIFile_Release((PAVIFILE)This->paf);
536}
537
538static HRESULT WINAPI IPersistFile_fnGetClassID(IPersistFile *iface,
539 LPCLSID pClassID)
540{
541 TRACE("(%p,%p)\n", iface, pClassID);
542
543 if (pClassID == NULL)
544 return AVIERR_BADPARAM;
545
Andrew Talbot292fd132008-02-11 20:48:51 +0000546 *pClassID = CLSID_WAVFile;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000547
548 return AVIERR_OK;
549}
550
551static HRESULT WINAPI IPersistFile_fnIsDirty(IPersistFile *iface)
552{
Alexandre Julliard39a696a2004-09-06 20:34:29 +0000553 IPersistFileImpl *This = (IPersistFileImpl *)iface;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000554
555 TRACE("(%p)\n", iface);
556
557 assert(This->paf != NULL);
558
559 return (This->paf->fDirty ? S_OK : S_FALSE);
560}
561
562static HRESULT WINAPI IPersistFile_fnLoad(IPersistFile *iface,
563 LPCOLESTR pszFileName, DWORD dwMode)
564{
565 IAVIFileImpl *This = ((IPersistFileImpl*)iface)->paf;
566
567 WCHAR wszStreamFmt[50];
568 INT len;
569
Michael Stefaniucf041a2b2006-10-10 01:07:06 +0200570 TRACE("(%p,%s,0x%08X)\n", iface, debugstr_w(pszFileName), dwMode);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000571
572 /* check parameter */
573 if (pszFileName == NULL)
574 return AVIERR_BADPARAM;
575
576 assert(This != NULL);
Francois Gougetd2667a42002-12-02 18:10:57 +0000577 if (This->hmmio != NULL)
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000578 return AVIERR_ERROR; /* No reuse of this object for another file! */
579
Austin Englishf6caf1b2008-01-16 17:04:38 -0600580 /* remember mode and name */
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000581 This->uMode = dwMode;
582
583 len = lstrlenW(pszFileName) + 1;
Mike McCormack610fc082006-03-11 00:21:42 +0900584 This->szFileName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000585 if (This->szFileName == NULL)
586 return AVIERR_MEMORY;
587 lstrcpyW(This->szFileName, pszFileName);
588
589 /* try to open the file */
590 This->hmmio = mmioOpenW(This->szFileName, NULL, MMIO_ALLOCBUF | dwMode);
Michael Günnewig645a36c2003-07-21 20:00:36 +0000591 if (This->hmmio == NULL) {
592 /* mmioOpenW not in native DLLs of Win9x -- try mmioOpenA */
Mike McCormack87bacf42004-07-04 00:11:31 +0000593 LPSTR szFileName;
594 len = WideCharToMultiByte(CP_ACP, 0, This->szFileName, -1,
595 NULL, 0, NULL, NULL);
Mike McCormack610fc082006-03-11 00:21:42 +0900596 szFileName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(CHAR));
Michael Günnewig645a36c2003-07-21 20:00:36 +0000597 if (szFileName == NULL)
598 return AVIERR_MEMORY;
599
600 WideCharToMultiByte(CP_ACP, 0, This->szFileName, -1, szFileName,
601 len, NULL, NULL);
602
603 This->hmmio = mmioOpenA(szFileName, NULL, MMIO_ALLOCBUF | dwMode);
Mike McCormack610fc082006-03-11 00:21:42 +0900604 HeapFree(GetProcessHeap(), 0, szFileName);
Michael Günnewig645a36c2003-07-21 20:00:36 +0000605 if (This->hmmio == NULL)
606 return AVIERR_FILEOPEN;
607 }
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000608
609 memset(& This->fInfo, 0, sizeof(This->fInfo));
610 memset(& This->sInfo, 0, sizeof(This->sInfo));
611
612 LoadStringW(AVIFILE_hModule, IDS_WAVEFILETYPE, This->fInfo.szFileType,
Rob Shearman89a2eab2008-02-13 16:21:53 +0000613 sizeof(This->fInfo.szFileType)/sizeof(This->fInfo.szFileType[0]));
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000614 if (LoadStringW(AVIFILE_hModule, IDS_WAVESTREAMFORMAT,
Rob Shearman89a2eab2008-02-13 16:21:53 +0000615 wszStreamFmt, sizeof(wszStreamFmt)/sizeof(wszStreamFmt[0])) > 0) {
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000616 wsprintfW(This->sInfo.szName, wszStreamFmt,
617 AVIFILE_BasenameW(This->szFileName));
618 }
619
620 /* should we create a new file? */
621 if (dwMode & OF_CREATE) {
622 /* nothing more to do */
623 return AVIERR_OK;
624 } else
625 return AVIFILE_LoadFile(This);
626}
627
628static HRESULT WINAPI IPersistFile_fnSave(IPersistFile *iface,
629 LPCOLESTR pszFileName,BOOL fRemember)
630{
631 TRACE("(%p,%s,%d)\n", iface, debugstr_w(pszFileName), fRemember);
632
633 /* We write directly to disk, so nothing to do. */
634
635 return AVIERR_OK;
636}
637
638static HRESULT WINAPI IPersistFile_fnSaveCompleted(IPersistFile *iface,
639 LPCOLESTR pszFileName)
640{
641 TRACE("(%p,%s)\n", iface, debugstr_w(pszFileName));
642
643 /* We write directly to disk, so nothing to do. */
644
645 return AVIERR_OK;
646}
647
648static HRESULT WINAPI IPersistFile_fnGetCurFile(IPersistFile *iface,
649 LPOLESTR *ppszFileName)
650{
Alexandre Julliard39a696a2004-09-06 20:34:29 +0000651 IPersistFileImpl *This = (IPersistFileImpl *)iface;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000652
653 TRACE("(%p,%p)\n", iface, ppszFileName);
654
655 if (ppszFileName == NULL)
656 return AVIERR_BADPARAM;
657
658 *ppszFileName = NULL;
659
660 assert(This->paf != NULL);
661
662 if (This->paf->szFileName != NULL) {
Mike McCormack87bacf42004-07-04 00:11:31 +0000663 int len = lstrlenW(This->paf->szFileName) + 1;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000664
Mike McCormack29212d82006-03-11 00:21:30 +0900665 *ppszFileName = CoTaskMemAlloc(len * sizeof(WCHAR));
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000666 if (*ppszFileName == NULL)
667 return AVIERR_MEMORY;
668
Mike McCormack87bacf42004-07-04 00:11:31 +0000669 strcpyW(*ppszFileName, This->paf->szFileName);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000670 }
671
672 return AVIERR_OK;
673}
674
675/***********************************************************************/
676
677static HRESULT WINAPI IAVIStream_fnQueryInterface(IAVIStream *iface,
678 REFIID refiid, LPVOID *obj)
679{
Alexandre Julliard39a696a2004-09-06 20:34:29 +0000680 IAVIStreamImpl *This = (IAVIStreamImpl *)iface;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000681
682 assert(This->paf != NULL);
683
684 return IAVIFile_QueryInterface((PAVIFILE)This->paf, refiid, obj);
685}
686
687static ULONG WINAPI IAVIStream_fnAddRef(IAVIStream *iface)
688{
Alexandre Julliard39a696a2004-09-06 20:34:29 +0000689 IAVIStreamImpl *This = (IAVIStreamImpl *)iface;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000690
691 assert(This->paf != NULL);
692
693 return IAVIFile_AddRef((PAVIFILE)This->paf);
694}
695
696static ULONG WINAPI IAVIStream_fnRelease(IAVIStream* iface)
697{
Alexandre Julliard39a696a2004-09-06 20:34:29 +0000698 IAVIStreamImpl *This = (IAVIStreamImpl *)iface;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000699
700 assert(This->paf != NULL);
701
702 return IAVIFile_Release((PAVIFILE)This->paf);
703}
704
705static HRESULT WINAPI IAVIStream_fnCreate(IAVIStream *iface, LPARAM lParam1,
706 LPARAM lParam2)
707{
708 TRACE("(%p,0x%08lX,0x%08lX)\n", iface, lParam1, lParam2);
709
710 /* This IAVIStream interface needs an WAVFile */
711 return AVIERR_UNSUPPORTED;
712}
713
714static HRESULT WINAPI IAVIStream_fnInfo(IAVIStream *iface,LPAVISTREAMINFOW psi,
715 LONG size)
716{
Alexandre Julliard39a696a2004-09-06 20:34:29 +0000717 IAVIStreamImpl *This = (IAVIStreamImpl *)iface;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000718
Michael Stefaniucf041a2b2006-10-10 01:07:06 +0200719 TRACE("(%p,%p,%d)\n", iface, psi, size);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000720
721 if (psi == NULL)
722 return AVIERR_BADPARAM;
723 if (size < 0)
724 return AVIERR_BADSIZE;
725
Michael Günnewig9f67cfe2003-06-23 18:10:06 +0000726 memcpy(psi, &This->paf->sInfo, min((DWORD)size, sizeof(This->paf->sInfo)));
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000727
Michael Günnewig9f67cfe2003-06-23 18:10:06 +0000728 if ((DWORD)size < sizeof(This->paf->sInfo))
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000729 return AVIERR_BUFFERTOOSMALL;
730 return AVIERR_OK;
731}
732
733static LONG WINAPI IAVIStream_fnFindSample(IAVIStream *iface, LONG pos,
734 LONG flags)
735{
736 IAVIFileImpl *This = ((IAVIStreamImpl*)iface)->paf;
737
Michael Stefaniucf041a2b2006-10-10 01:07:06 +0200738 TRACE("(%p,%d,0x%08X)\n",iface,pos,flags);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000739
740 /* Do we have data? */
741 if (This->lpFormat == NULL)
742 return -1;
743
744 /* We don't have an index */
745 if (flags & FIND_INDEX)
746 return -1;
747
748 if (flags & FIND_FROM_START) {
749 pos = This->sInfo.dwStart;
750 flags &= ~(FIND_FROM_START|FIND_PREV);
751 flags |= FIND_NEXT;
752 }
753
754 if (flags & FIND_FORMAT) {
755 if ((flags & FIND_NEXT) && pos > 0)
756 pos = -1;
757 else
758 pos = 0;
759 }
760
Michael Günnewigedd8bc32003-11-26 22:04:29 +0000761 if ((flags & FIND_RET) == FIND_LENGTH ||
762 (flags & FIND_RET) == FIND_SIZE)
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000763 return This->sInfo.dwSampleSize;
Michael Günnewigedd8bc32003-11-26 22:04:29 +0000764 if ((flags & FIND_RET) == FIND_OFFSET)
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000765 return This->ckData.dwDataOffset + pos * This->sInfo.dwSampleSize;
766
767 return pos;
768}
769
770static HRESULT WINAPI IAVIStream_fnReadFormat(IAVIStream *iface, LONG pos,
771 LPVOID format, LONG *formatsize)
772{
Alexandre Julliard39a696a2004-09-06 20:34:29 +0000773 IAVIStreamImpl *This = (IAVIStreamImpl *)iface;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000774
Michael Stefaniucf041a2b2006-10-10 01:07:06 +0200775 TRACE("(%p,%d,%p,%p)\n", iface, pos, format, formatsize);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000776
777 if (formatsize == NULL)
778 return AVIERR_BADPARAM;
779
780 /* only interested in needed buffersize? */
781 if (format == NULL || *formatsize <= 0) {
782 *formatsize = This->paf->cbFormat;
783
784 return AVIERR_OK;
785 }
786
787 /* copy initial format (only as much as will fit) */
788 memcpy(format, This->paf->lpFormat, min(*formatsize, This->paf->cbFormat));
789 if (*formatsize < This->paf->cbFormat) {
790 *formatsize = This->paf->cbFormat;
791 return AVIERR_BUFFERTOOSMALL;
792 }
793
794 *formatsize = This->paf->cbFormat;
795 return AVIERR_OK;
796}
797
798static HRESULT WINAPI IAVIStream_fnSetFormat(IAVIStream *iface, LONG pos,
799 LPVOID format, LONG formatsize)
800{
801 IAVIFileImpl *This = ((IAVIStreamImpl*)iface)->paf;
802
Michael Stefaniucf041a2b2006-10-10 01:07:06 +0200803 TRACE("(%p,%d,%p,%d)\n", iface, pos, format, formatsize);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000804
805 /* check parameters */
806 if (format == NULL || formatsize <= sizeof(PCMWAVEFORMAT))
807 return AVIERR_BADPARAM;
808
809 /* We can only do this to an empty wave file, but ignore call
810 * if still same format */
811 if (This->lpFormat != NULL) {
812 if (formatsize != This->cbFormat ||
813 memcmp(format, This->lpFormat, formatsize) != 0)
814 return AVIERR_UNSUPPORTED;
815
816 return AVIERR_OK;
817 }
818
819 /* only support start at position 0 */
820 if (pos != 0)
821 return AVIERR_UNSUPPORTED;
822
823 /* Do we have write permission? */
824 if ((This->uMode & MMIO_RWMODE) == 0)
825 return AVIERR_READONLY;
826
827 /* get memory for format and copy it */
Mike McCormack610fc082006-03-11 00:21:42 +0900828 This->lpFormat = HeapAlloc(GetProcessHeap(), 0, formatsize);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000829 if (This->lpFormat == NULL)
830 return AVIERR_MEMORY;
831
832 This->cbFormat = formatsize;
833 memcpy(This->lpFormat, format, formatsize);
834
835 /* update info's about 'data' chunk */
836 This->ckData.dwDataOffset = formatsize + 7 * sizeof(DWORD);
837 This->ckData.cksize = 0;
838
839 /* for non-pcm format we need also a 'fact' chunk */
840 if (This->lpFormat->wFormatTag != WAVE_FORMAT_PCM)
841 This->ckData.dwDataOffset += 3 * sizeof(DWORD);
842
843 /* update stream and file info */
844 This->sInfo.dwSampleSize = This->lpFormat->nBlockAlign;
845 This->sInfo.dwScale = This->lpFormat->nBlockAlign;
846 This->sInfo.dwRate = This->lpFormat->nAvgBytesPerSec;
847 This->sInfo.dwLength = 0;
848 This->sInfo.dwSuggestedBufferSize = 0;
849
850 return AVIERR_OK;
851}
852
853static HRESULT WINAPI IAVIStream_fnRead(IAVIStream *iface, LONG start,
854 LONG samples, LPVOID buffer,
855 LONG buffersize, LPLONG bytesread,
856 LPLONG samplesread)
857{
858 IAVIFileImpl *This = ((IAVIStreamImpl*)iface)->paf;
859
Michael Stefaniucf041a2b2006-10-10 01:07:06 +0200860 TRACE("(%p,%d,%d,%p,%d,%p,%p)\n", iface, start, samples, buffer,
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000861 buffersize, bytesread, samplesread);
862
863 /* clear return parameters if given */
864 if (bytesread != NULL)
865 *bytesread = 0;
866 if (samplesread != NULL)
867 *samplesread = 0;
868
869 /* positions without data */
Michael Günnewig9f67cfe2003-06-23 18:10:06 +0000870 if (start < 0 || (DWORD)start > This->sInfo.dwLength)
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000871 return AVIERR_OK;
872
873 /* check samples */
874 if (samples < 0)
875 samples = 0;
876 if (buffersize > 0) {
877 if (samples > 0)
Michael Günnewig9f67cfe2003-06-23 18:10:06 +0000878 samples = min((DWORD)samples, buffersize / This->sInfo.dwSampleSize);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000879 else
880 samples = buffersize / This->sInfo.dwSampleSize;
881 }
882
883 /* limit to end of stream */
Michael Günnewig9f67cfe2003-06-23 18:10:06 +0000884 if ((DWORD)(start + samples) > This->sInfo.dwLength)
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000885 samples = This->sInfo.dwLength - start;
886
887 /* request only the sizes? */
888 if (buffer == NULL || buffersize <= 0) {
Francois Gouget6fb1a202004-12-20 19:27:06 +0000889 /* then I need at least one parameter for it */
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000890 if (bytesread == NULL && samplesread == NULL)
891 return AVIERR_BADPARAM;
892
893 if (bytesread != NULL)
894 *bytesread = samples * This->sInfo.dwSampleSize;
895 if (samplesread != NULL)
896 *samplesread = samples;
897
898 return AVIERR_OK;
899 }
900
901 /* nothing to read? */
902 if (samples == 0)
903 return AVIERR_OK;
904
Francois Gouget6fb1a202004-12-20 19:27:06 +0000905 /* Can I read at least one sample? */
Michael Günnewig9f67cfe2003-06-23 18:10:06 +0000906 if ((DWORD)buffersize < This->sInfo.dwSampleSize)
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000907 return AVIERR_BUFFERTOOSMALL;
908
909 buffersize = samples * This->sInfo.dwSampleSize;
910
911 if (mmioSeek(This->hmmio, This->ckData.dwDataOffset
912 + start * This->sInfo.dwSampleSize, SEEK_SET) == -1)
913 return AVIERR_FILEREAD;
Michael Stefaniuc905ff8f2009-01-27 11:36:14 +0100914 if (mmioRead(This->hmmio, buffer, buffersize) != buffersize)
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000915 return AVIERR_FILEREAD;
916
917 /* fill out return parameters if given */
918 if (bytesread != NULL)
919 *bytesread = buffersize;
920 if (samplesread != NULL)
921 *samplesread = samples;
922
923 return AVIERR_OK;
924}
925
926static HRESULT WINAPI IAVIStream_fnWrite(IAVIStream *iface, LONG start,
927 LONG samples, LPVOID buffer,
928 LONG buffersize, DWORD flags,
929 LPLONG sampwritten,
930 LPLONG byteswritten)
931{
932 IAVIFileImpl *This = ((IAVIStreamImpl*)iface)->paf;
933
Michael Stefaniucf041a2b2006-10-10 01:07:06 +0200934 TRACE("(%p,%d,%d,%p,%d,0x%08X,%p,%p)\n", iface, start, samples,
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000935 buffer, buffersize, flags, sampwritten, byteswritten);
936
937 /* clear return parameters if given */
938 if (sampwritten != NULL)
939 *sampwritten = 0;
940 if (byteswritten != NULL)
941 *byteswritten = 0;
942
943 /* check parameters */
944 if (buffer == NULL && (buffersize > 0 || samples > 0))
945 return AVIERR_BADPARAM;
946
Francois Gouget6fb1a202004-12-20 19:27:06 +0000947 /* Do we have write permission? */
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000948 if ((This->uMode & MMIO_RWMODE) == 0)
949 return AVIERR_READONLY;
950
951 /* < 0 means "append" */
952 if (start < 0)
953 start = This->sInfo.dwStart + This->sInfo.dwLength;
954
955 /* check buffersize -- must multiple of samplesize */
956 if (buffersize & ~(This->sInfo.dwSampleSize - 1))
957 return AVIERR_BADSIZE;
958
Francois Gouget6fb1a202004-12-20 19:27:06 +0000959 /* do we have anything to write? */
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000960 if (buffer != NULL && buffersize > 0) {
961 This->fDirty = 1;
962
963 if (mmioSeek(This->hmmio, This->ckData.dwDataOffset +
964 start * This->sInfo.dwSampleSize, SEEK_SET) == -1)
965 return AVIERR_FILEWRITE;
Michael Stefaniuc905ff8f2009-01-27 11:36:14 +0100966 if (mmioWrite(This->hmmio, buffer, buffersize) != buffersize)
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000967 return AVIERR_FILEWRITE;
968
Michael Günnewig9f67cfe2003-06-23 18:10:06 +0000969 This->sInfo.dwLength = max(This->sInfo.dwLength, (DWORD)start + samples);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000970 This->ckData.cksize = max(This->ckData.cksize,
971 start * This->sInfo.dwSampleSize + buffersize);
972
973 /* fill out return parameters if given */
974 if (sampwritten != NULL)
975 *sampwritten = samples;
976 if (byteswritten != NULL)
977 *byteswritten = buffersize;
978 }
979
980 return AVIERR_OK;
981}
982
983static HRESULT WINAPI IAVIStream_fnDelete(IAVIStream *iface, LONG start,
984 LONG samples)
985{
986 IAVIFileImpl *This = ((IAVIStreamImpl*)iface)->paf;
987
Michael Stefaniucf041a2b2006-10-10 01:07:06 +0200988 TRACE("(%p,%d,%d)\n", iface, start, samples);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000989
990 /* check parameters */
991 if (start < 0 || samples < 0)
992 return AVIERR_BADPARAM;
993
994 /* Delete before start of stream? */
Michael Günnewig9f67cfe2003-06-23 18:10:06 +0000995 if ((DWORD)(start + samples) < This->sInfo.dwStart)
Michael Günnewig4c04e1f2002-10-18 00:24:41 +0000996 return AVIERR_OK;
997
998 /* Delete after end of stream? */
Michael Günnewig9f67cfe2003-06-23 18:10:06 +0000999 if ((DWORD)start > This->sInfo.dwLength)
Michael Günnewig4c04e1f2002-10-18 00:24:41 +00001000 return AVIERR_OK;
1001
1002 /* For the rest we need write permissions */
1003 if ((This->uMode & MMIO_RWMODE) == 0)
1004 return AVIERR_READONLY;
1005
Michael Günnewig9f67cfe2003-06-23 18:10:06 +00001006 if ((DWORD)(start + samples) >= This->sInfo.dwLength) {
Michael Günnewig4c04e1f2002-10-18 00:24:41 +00001007 /* deletion at end */
1008 samples = This->sInfo.dwLength - start;
1009 This->sInfo.dwLength -= samples;
1010 This->ckData.cksize -= samples * This->sInfo.dwSampleSize;
Michael Günnewig9f67cfe2003-06-23 18:10:06 +00001011 } else if ((DWORD)start <= This->sInfo.dwStart) {
Michael Günnewig4c04e1f2002-10-18 00:24:41 +00001012 /* deletion at start */
1013 samples = This->sInfo.dwStart - start;
1014 start = This->sInfo.dwStart;
1015 This->ckData.dwDataOffset += samples * This->sInfo.dwSampleSize;
1016 This->ckData.cksize -= samples * This->sInfo.dwSampleSize;
1017 } else {
1018 /* deletion inside stream -- needs playlist and cue's */
1019 FIXME(": deletion inside of stream not supported!\n");
1020
1021 return AVIERR_UNSUPPORTED;
1022 }
1023
1024 This->fDirty = 1;
1025
1026 return AVIERR_OK;
1027}
1028
1029static HRESULT WINAPI IAVIStream_fnReadData(IAVIStream *iface, DWORD fcc,
1030 LPVOID lp, LPLONG lpread)
1031{
Alexandre Julliard39a696a2004-09-06 20:34:29 +00001032 IAVIStreamImpl *This = (IAVIStreamImpl *)iface;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +00001033
1034 assert(This->paf != NULL);
1035
1036 return IAVIFile_ReadData((PAVIFILE)This->paf, fcc, lp, lpread);
1037}
1038
1039static HRESULT WINAPI IAVIStream_fnWriteData(IAVIStream *iface, DWORD fcc,
1040 LPVOID lp, LONG size)
1041{
Alexandre Julliard39a696a2004-09-06 20:34:29 +00001042 IAVIStreamImpl *This = (IAVIStreamImpl *)iface;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +00001043
1044 return IAVIFile_WriteData((PAVIFILE)This->paf, fcc, lp, size);
1045}
1046
1047static HRESULT WINAPI IAVIStream_fnSetInfo(IAVIStream *iface,
1048 LPAVISTREAMINFOW info, LONG infolen)
1049{
Michael Stefaniucf041a2b2006-10-10 01:07:06 +02001050 FIXME("(%p,%p,%d): stub\n", iface, info, infolen);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +00001051
1052 return E_FAIL;
1053}
1054
1055/***********************************************************************/
1056
1057static HRESULT AVIFILE_LoadFile(IAVIFileImpl *This)
1058{
1059 MMCKINFO ckRIFF;
1060 MMCKINFO ck;
1061
1062 This->sInfo.dwLength = 0; /* just to be sure */
1063 This->fDirty = FALSE;
1064
1065 /* search for RIFF chunk */
Michael Günnewig45af4922002-10-19 00:12:06 +00001066 ckRIFF.fccType = 0; /* find any */
Michael Günnewig4c04e1f2002-10-18 00:24:41 +00001067 if (mmioDescend(This->hmmio, &ckRIFF, NULL, MMIO_FINDRIFF) != S_OK) {
1068 return AVIFILE_LoadSunFile(This);
1069 }
1070
1071 if (ckRIFF.fccType != formtypeWAVE)
1072 return AVIERR_BADFORMAT;
1073
1074 /* search WAVE format chunk */
1075 ck.ckid = ckidWAVEFORMAT;
1076 if (FindChunkAndKeepExtras(&This->extra, This->hmmio, &ck,
Michael Günnewig45af4922002-10-19 00:12:06 +00001077 &ckRIFF, MMIO_FINDCHUNK) != S_OK)
Michael Günnewig4c04e1f2002-10-18 00:24:41 +00001078 return AVIERR_FILEREAD;
1079
1080 /* get memory for format and read it */
Mike McCormack610fc082006-03-11 00:21:42 +09001081 This->lpFormat = HeapAlloc(GetProcessHeap(), 0, ck.cksize);
Michael Günnewig4c04e1f2002-10-18 00:24:41 +00001082 if (This->lpFormat == NULL)
1083 return AVIERR_FILEREAD;
1084 This->cbFormat = ck.cksize;
1085
1086 if (mmioRead(This->hmmio, (HPSTR)This->lpFormat, ck.cksize) != ck.cksize)
1087 return AVIERR_FILEREAD;
1088 if (mmioAscend(This->hmmio, &ck, 0) != S_OK)
1089 return AVIERR_FILEREAD;
1090
Michael Günnewig45af4922002-10-19 00:12:06 +00001091 /* Non-pcm formats have a fact chunk.
1092 * We don't need it, so simply add it to the extra chunks.
1093 */
Michael Günnewig4c04e1f2002-10-18 00:24:41 +00001094
1095 /* find the big data chunk */
1096 This->ckData.ckid = ckidWAVEDATA;
1097 if (FindChunkAndKeepExtras(&This->extra, This->hmmio, &This->ckData,
1098 &ckRIFF, MMIO_FINDCHUNK) != S_OK)
1099 return AVIERR_FILEREAD;
1100
1101 memset(&This->sInfo, 0, sizeof(This->sInfo));
1102 This->sInfo.fccType = streamtypeAUDIO;
1103 This->sInfo.dwRate = This->lpFormat->nAvgBytesPerSec;
1104 This->sInfo.dwSampleSize =
1105 This->sInfo.dwScale = This->lpFormat->nBlockAlign;
1106 This->sInfo.dwLength = This->ckData.cksize / This->lpFormat->nBlockAlign;
1107 This->sInfo.dwSuggestedBufferSize = This->ckData.cksize;
1108
Michael Günnewig45af4922002-10-19 00:12:06 +00001109 This->fInfo.dwStreams = 1;
1110
Michael Günnewig4c04e1f2002-10-18 00:24:41 +00001111 if (mmioAscend(This->hmmio, &This->ckData, 0) != S_OK) {
1112 /* seems to be truncated */
1113 WARN(": file seems to be truncated!\n");
1114 This->ckData.cksize = mmioSeek(This->hmmio, 0, SEEK_END) -
1115 This->ckData.dwDataOffset;
1116 This->sInfo.dwLength = This->ckData.cksize / This->lpFormat->nBlockAlign;
1117 This->sInfo.dwSuggestedBufferSize = This->ckData.cksize;
1118 }
1119
1120 /* ignore errors */
1121 FindChunkAndKeepExtras(&This->extra, This->hmmio, &ck, &ckRIFF, 0);
1122
1123 return AVIERR_OK;
1124}
1125
1126static HRESULT AVIFILE_LoadSunFile(IAVIFileImpl *This)
1127{
Michael Günnewig645a36c2003-07-21 20:00:36 +00001128 SUNAUDIOHEADER auhdr;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +00001129
Michael Günnewig645a36c2003-07-21 20:00:36 +00001130 mmioSeek(This->hmmio, 0, SEEK_SET);
1131 if (mmioRead(This->hmmio, (HPSTR)&auhdr, sizeof(auhdr)) != sizeof(auhdr))
1132 return AVIERR_FILEREAD;
1133
1134 if (auhdr.fccType == 0x0064732E) {
1135 /* header in little endian */
1136 This->ckData.dwDataOffset = LE2H_DWORD(auhdr.offset);
1137 This->ckData.cksize = LE2H_DWORD(auhdr.size);
1138
1139 auhdr.encoding = LE2H_DWORD(auhdr.encoding);
1140 auhdr.sampleRate = LE2H_DWORD(auhdr.sampleRate);
1141 auhdr.channels = LE2H_DWORD(auhdr.channels);
1142 } else if (auhdr.fccType == mmioFOURCC('.','s','n','d')) {
1143 /* header in big endian */
1144 This->ckData.dwDataOffset = BE2H_DWORD(auhdr.offset);
1145 This->ckData.cksize = BE2H_DWORD(auhdr.size);
1146
1147 auhdr.encoding = BE2H_DWORD(auhdr.encoding);
1148 auhdr.sampleRate = BE2H_DWORD(auhdr.sampleRate);
1149 auhdr.channels = BE2H_DWORD(auhdr.channels);
1150 } else
1151 return AVIERR_FILEREAD;
1152
1153 if (auhdr.channels < 1)
1154 return AVIERR_BADFORMAT;
1155
1156 /* get size of header */
1157 switch(auhdr.encoding) {
1158 case AU_ENCODING_ADPCM_G721_32:
1159 This->cbFormat = sizeof(G721_ADPCMWAVEFORMAT); break;
1160 case AU_ENCODING_ADPCM_G723_24:
1161 This->cbFormat = sizeof(G723_ADPCMWAVEFORMAT); break;
1162 case AU_ENCODING_ADPCM_G722:
1163 case AU_ENCODING_ADPCM_G723_5:
1164 WARN("unsupported Sun audio format %d\n", auhdr.encoding);
1165 return AVIERR_UNSUPPORTED; /* FIXME */
1166 default:
1167 This->cbFormat = sizeof(WAVEFORMATEX); break;
1168 };
1169
Mike McCormack610fc082006-03-11 00:21:42 +09001170 This->lpFormat = HeapAlloc(GetProcessHeap(), 0, This->cbFormat);
Michael Günnewig645a36c2003-07-21 20:00:36 +00001171 if (This->lpFormat == NULL)
1172 return AVIERR_MEMORY;
1173
1174 This->lpFormat->nChannels = auhdr.channels;
1175 This->lpFormat->nSamplesPerSec = auhdr.sampleRate;
1176 switch(auhdr.encoding) {
1177 case AU_ENCODING_ULAW_8:
1178 This->lpFormat->wFormatTag = WAVE_FORMAT_MULAW;
1179 This->lpFormat->wBitsPerSample = 8;
1180 break;
1181 case AU_ENCODING_PCM_8:
1182 This->lpFormat->wFormatTag = WAVE_FORMAT_PCM;
1183 This->lpFormat->wBitsPerSample = 8;
1184 break;
1185 case AU_ENCODING_PCM_16:
1186 This->lpFormat->wFormatTag = WAVE_FORMAT_PCM;
1187 This->lpFormat->wBitsPerSample = 16;
1188 break;
1189 case AU_ENCODING_PCM_24:
1190 This->lpFormat->wFormatTag = WAVE_FORMAT_PCM;
1191 This->lpFormat->wBitsPerSample = 24;
1192 break;
1193 case AU_ENCODING_PCM_32:
1194 This->lpFormat->wFormatTag = WAVE_FORMAT_PCM;
1195 This->lpFormat->wBitsPerSample = 32;
1196 break;
1197 case AU_ENCODING_ALAW_8:
1198 This->lpFormat->wFormatTag = WAVE_FORMAT_ALAW;
1199 This->lpFormat->wBitsPerSample = 8;
1200 break;
1201 case AU_ENCODING_ADPCM_G721_32:
1202 This->lpFormat->wFormatTag = WAVE_FORMAT_G721_ADPCM;
1203 This->lpFormat->wBitsPerSample = (3*5*8);
1204 This->lpFormat->nBlockAlign = 15*15*8;
1205 This->lpFormat->cbSize = sizeof(WORD);
1206 ((LPG721_ADPCMWAVEFORMAT)This->lpFormat)->nAuxBlockSize = 0;
1207 break;
1208 case AU_ENCODING_ADPCM_G723_24:
1209 This->lpFormat->wFormatTag = WAVE_FORMAT_G723_ADPCM;
1210 This->lpFormat->wBitsPerSample = (3*5*8);
1211 This->lpFormat->nBlockAlign = 15*15*8;
1212 This->lpFormat->cbSize = 2*sizeof(WORD);
1213 ((LPG723_ADPCMWAVEFORMAT)This->lpFormat)->cbExtraSize = 0;
1214 ((LPG723_ADPCMWAVEFORMAT)This->lpFormat)->nAuxBlockSize = 0;
1215 break;
1216 default:
1217 WARN("unsupported Sun audio format %d\n", auhdr.encoding);
1218 return AVIERR_UNSUPPORTED;
1219 };
1220
1221 This->lpFormat->nBlockAlign =
1222 (This->lpFormat->nChannels * This->lpFormat->wBitsPerSample) / 8;
1223 if (This->lpFormat->nBlockAlign == 0 && This->lpFormat->wBitsPerSample < 8)
1224 This->lpFormat->nBlockAlign++;
1225 This->lpFormat->nAvgBytesPerSec =
1226 This->lpFormat->nBlockAlign * This->lpFormat->nSamplesPerSec;
1227
1228 This->fDirty = 0;
1229
1230 This->sInfo.fccType = streamtypeAUDIO;
1231 This->sInfo.fccHandler = 0;
1232 This->sInfo.dwFlags = 0;
1233 This->sInfo.wPriority = 0;
1234 This->sInfo.wLanguage = 0;
1235 This->sInfo.dwInitialFrames = 0;
1236 This->sInfo.dwScale = This->lpFormat->nBlockAlign;
1237 This->sInfo.dwRate = This->lpFormat->nAvgBytesPerSec;
1238 This->sInfo.dwStart = 0;
1239 This->sInfo.dwLength =
1240 This->ckData.cksize / This->lpFormat->nBlockAlign;
1241 This->sInfo.dwSuggestedBufferSize = This->sInfo.dwLength;
1242 This->sInfo.dwSampleSize = This->lpFormat->nBlockAlign;
1243
1244 This->fInfo.dwStreams = 1;
1245 This->fInfo.dwScale = 1;
1246 This->fInfo.dwRate = This->lpFormat->nSamplesPerSec;
1247 This->fInfo.dwLength =
1248 MulDiv(This->ckData.cksize, This->lpFormat->nSamplesPerSec,
1249 This->lpFormat->nAvgBytesPerSec);
1250
1251 return AVIERR_OK;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +00001252}
1253
Andrew Talbotb01c2c82007-04-02 22:50:46 +01001254static HRESULT AVIFILE_SaveFile(const IAVIFileImpl *This)
Michael Günnewig4c04e1f2002-10-18 00:24:41 +00001255{
Michael Günnewig45af4922002-10-19 00:12:06 +00001256 MMCKINFO ckRIFF;
1257 MMCKINFO ck;
1258
1259 mmioSeek(This->hmmio, 0, SEEK_SET);
1260
1261 /* create the RIFF chunk with formtype WAVE */
1262 ckRIFF.fccType = formtypeWAVE;
1263 ckRIFF.cksize = 0;
1264 if (mmioCreateChunk(This->hmmio, &ckRIFF, MMIO_CREATERIFF) != S_OK)
1265 return AVIERR_FILEWRITE;
1266
1267 /* the next chunk is the format */
1268 ck.ckid = ckidWAVEFORMAT;
1269 ck.cksize = This->cbFormat;
1270 if (mmioCreateChunk(This->hmmio, &ck, 0) != S_OK)
1271 return AVIERR_FILEWRITE;
1272 if (This->lpFormat != NULL && This->cbFormat > 0) {
1273 if (mmioWrite(This->hmmio, (HPSTR)This->lpFormat, ck.cksize) != ck.cksize)
1274 return AVIERR_FILEWRITE;
1275 }
1276 if (mmioAscend(This->hmmio, &ck, 0) != S_OK)
1277 return AVIERR_FILEWRITE;
1278
1279 /* fact chunk is needed for non-pcm waveforms */
1280 if (This->lpFormat != NULL && This->cbFormat > sizeof(PCMWAVEFORMAT) &&
1281 This->lpFormat->wFormatTag != WAVE_FORMAT_PCM) {
1282 WAVEFORMATEX wfx;
1283 DWORD dwFactLength;
1284 HACMSTREAM has;
1285
1286 /* try to open an appropriate audio codec to figure out
1287 * data for fact-chunk */
1288 wfx.wFormatTag = WAVE_FORMAT_PCM;
Francois Gougetd2667a42002-12-02 18:10:57 +00001289 if (acmFormatSuggest(NULL, This->lpFormat, &wfx,
Michael Günnewig45af4922002-10-19 00:12:06 +00001290 sizeof(wfx), ACM_FORMATSUGGESTF_WFORMATTAG)) {
Francois Gougetd2667a42002-12-02 18:10:57 +00001291 acmStreamOpen(&has, NULL, This->lpFormat, &wfx, NULL,
Michael Günnewig45af4922002-10-19 00:12:06 +00001292 0, 0, ACM_STREAMOPENF_NONREALTIME);
1293 acmStreamSize(has, This->ckData.cksize, &dwFactLength,
1294 ACM_STREAMSIZEF_SOURCE);
1295 dwFactLength /= wfx.nBlockAlign;
1296 acmStreamClose(has, 0);
1297
Francois Gouget6fb1a202004-12-20 19:27:06 +00001298 /* create the fact chunk */
Michael Günnewig45af4922002-10-19 00:12:06 +00001299 ck.ckid = ckidWAVEFACT;
1300 ck.cksize = sizeof(dwFactLength);
1301
1302 /* test for enough space before data chunk */
1303 if (mmioSeek(This->hmmio, 0, SEEK_CUR) > This->ckData.dwDataOffset
1304 - ck.cksize - 4 * sizeof(DWORD))
1305 return AVIERR_FILEWRITE;
1306 if (mmioCreateChunk(This->hmmio, &ck, 0) != S_OK)
1307 return AVIERR_FILEWRITE;
1308 if (mmioWrite(This->hmmio, (HPSTR)&dwFactLength, ck.cksize) != ck.cksize)
1309 return AVIERR_FILEWRITE;
1310 if (mmioAscend(This->hmmio, &ck, 0) != S_OK)
1311 return AVIERR_FILEWRITE;
1312 } else
1313 ERR(": fact chunk is needed for non-pcm files -- currently no codec found, so skipped!\n");
1314 }
1315
Francois Gouget6fb1a202004-12-20 19:27:06 +00001316 /* if there was extra stuff, we need to fill it with JUNK */
Michael Günnewig45af4922002-10-19 00:12:06 +00001317 if (mmioSeek(This->hmmio, 0, SEEK_CUR) + 2 * sizeof(DWORD) < This->ckData.dwDataOffset) {
1318 ck.ckid = ckidAVIPADDING;
1319 ck.cksize = 0;
1320 if (mmioCreateChunk(This->hmmio, &ck, 0) != S_OK)
1321 return AVIERR_FILEWRITE;
1322
1323 if (mmioSeek(This->hmmio, This->ckData.dwDataOffset
1324 - 2 * sizeof(DWORD), SEEK_SET) == -1)
1325 return AVIERR_FILEWRITE;
1326 if (mmioAscend(This->hmmio, &ck, 0) != S_OK)
1327 return AVIERR_FILEWRITE;
1328 }
1329
Francois Gouget6fb1a202004-12-20 19:27:06 +00001330 /* create the data chunk */
Michael Günnewig45af4922002-10-19 00:12:06 +00001331 ck.ckid = ckidWAVEDATA;
1332 ck.cksize = This->ckData.cksize;
1333 if (mmioCreateChunk(This->hmmio, &ck, 0) != S_OK)
1334 return AVIERR_FILEWRITE;
1335 if (mmioSeek(This->hmmio, This->ckData.cksize, SEEK_CUR) == -1)
1336 return AVIERR_FILEWRITE;
1337 if (mmioAscend(This->hmmio, &ck, 0) != S_OK)
1338 return AVIERR_FILEWRITE;
1339
1340 /* some optional extra chunks? */
1341 if (This->extra.lp != NULL && This->extra.cb > 0) {
1342 /* chunk headers are already in structure */
1343 if (mmioWrite(This->hmmio, This->extra.lp, This->extra.cb) != This->extra.cb)
1344 return AVIERR_FILEWRITE;
1345 }
1346
1347 /* close RIFF chunk */
1348 if (mmioAscend(This->hmmio, &ckRIFF, 0) != S_OK)
1349 return AVIERR_FILEWRITE;
1350 if (mmioFlush(This->hmmio, 0) != S_OK)
1351 return AVIERR_FILEWRITE;
1352
1353 return AVIERR_OK;
Michael Günnewig4c04e1f2002-10-18 00:24:41 +00001354}