2002-10-18 02:24:41 +02:00
|
|
|
|
/*
|
|
|
|
|
* Copyright 2002 Michael G<EFBFBD>nnewig
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*/
|
|
|
|
|
|
2003-01-03 20:12:55 +01:00
|
|
|
|
#define COM_NO_WINDOWS_H
|
2002-10-18 02:24:41 +02:00
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
|
|
#include "extrachunk.h"
|
|
|
|
|
#include "winbase.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
|
#include "wingdi.h"
|
2003-09-09 21:39:31 +02:00
|
|
|
|
#include "winuser.h"
|
2002-10-18 02:24:41 +02:00
|
|
|
|
#include "vfw.h"
|
|
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(avifile);
|
|
|
|
|
|
|
|
|
|
/* reads a chunk outof the extrachunk-structure */
|
|
|
|
|
HRESULT ReadExtraChunk(LPEXTRACHUNKS extra,FOURCC ckid,LPVOID lpData,
|
|
|
|
|
LPLONG size)
|
|
|
|
|
{
|
|
|
|
|
LPBYTE lp;
|
2003-06-23 20:10:06 +02:00
|
|
|
|
DWORD cb;
|
2002-10-18 02:24:41 +02:00
|
|
|
|
|
|
|
|
|
/* pre-conditions */
|
|
|
|
|
assert(extra != NULL);
|
|
|
|
|
assert(size != NULL);
|
|
|
|
|
|
|
|
|
|
lp = extra->lp;
|
|
|
|
|
cb = extra->cb;
|
|
|
|
|
|
|
|
|
|
if (lp != NULL) {
|
|
|
|
|
while (cb > 0) {
|
|
|
|
|
if (((FOURCC*)lp)[0] == ckid) {
|
|
|
|
|
/* found correct chunk */
|
|
|
|
|
if (lpData != NULL && *size > 0)
|
2003-06-23 20:10:06 +02:00
|
|
|
|
memcpy(lpData, lp + 2 * sizeof(DWORD),
|
|
|
|
|
min(((LPDWORD)lp)[1], *(LPDWORD)size));
|
2002-10-18 02:24:41 +02:00
|
|
|
|
|
2003-06-23 20:10:06 +02:00
|
|
|
|
*(LPDWORD)size = ((LPDWORD)lp)[1];
|
2002-10-18 02:24:41 +02:00
|
|
|
|
|
|
|
|
|
return AVIERR_OK;
|
|
|
|
|
} else {
|
|
|
|
|
/* skip to next chunk */
|
|
|
|
|
cb -= ((LPDWORD)lp)[1] + 2 * sizeof(DWORD);
|
|
|
|
|
lp += ((LPDWORD)lp)[1] + 2 * sizeof(DWORD);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* wanted chunk doesn't exist */
|
|
|
|
|
*size = 0;
|
|
|
|
|
|
|
|
|
|
return AVIERR_NODATA;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* writes a chunk into the extrachunk-structure */
|
|
|
|
|
HRESULT WriteExtraChunk(LPEXTRACHUNKS extra,FOURCC ckid,LPVOID lpData,
|
|
|
|
|
LONG size)
|
|
|
|
|
{
|
|
|
|
|
LPDWORD lp;
|
|
|
|
|
|
|
|
|
|
/* pre-conditions */
|
|
|
|
|
assert(extra != NULL);
|
|
|
|
|
assert(lpData != NULL);
|
|
|
|
|
assert(size > 0);
|
|
|
|
|
|
|
|
|
|
if (extra->lp)
|
2006-04-11 13:44:02 +02:00
|
|
|
|
lp = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, extra->lp, extra->cb + size + 2 * sizeof(DWORD));
|
2002-10-18 02:24:41 +02:00
|
|
|
|
else
|
2006-04-11 13:44:02 +02:00
|
|
|
|
lp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + 2 * sizeof(DWORD));
|
2002-10-18 02:24:41 +02:00
|
|
|
|
|
|
|
|
|
if (lp == NULL)
|
|
|
|
|
return AVIERR_MEMORY;
|
|
|
|
|
|
|
|
|
|
extra->lp = lp;
|
2004-07-22 21:43:14 +02:00
|
|
|
|
lp = (LPDWORD) ((LPBYTE)lp + extra->cb);
|
2002-10-18 02:24:41 +02:00
|
|
|
|
extra->cb += size + 2 * sizeof(DWORD);
|
|
|
|
|
|
|
|
|
|
/* insert chunk-header in block */
|
|
|
|
|
lp[0] = ckid;
|
|
|
|
|
lp[1] = size;
|
|
|
|
|
|
|
|
|
|
if (lpData != NULL && size > 0)
|
|
|
|
|
memcpy(lp + 2, lpData, size);
|
|
|
|
|
|
|
|
|
|
return AVIERR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* reads a chunk fomr the HMMIO into the extrachunk-structure */
|
|
|
|
|
HRESULT ReadChunkIntoExtra(LPEXTRACHUNKS extra,HMMIO hmmio,MMCKINFO *lpck)
|
|
|
|
|
{
|
|
|
|
|
LPDWORD lp;
|
2003-06-23 20:10:06 +02:00
|
|
|
|
DWORD cb;
|
2002-10-18 02:24:41 +02:00
|
|
|
|
|
|
|
|
|
/* pre-conditions */
|
|
|
|
|
assert(extra != NULL);
|
2002-12-02 19:10:57 +01:00
|
|
|
|
assert(hmmio != NULL);
|
2002-10-18 02:24:41 +02:00
|
|
|
|
assert(lpck != NULL);
|
|
|
|
|
|
|
|
|
|
cb = lpck->cksize + 2 * sizeof(DWORD);
|
|
|
|
|
cb += (cb & 1);
|
|
|
|
|
|
2006-03-11 06:42:01 +01:00
|
|
|
|
if (extra->lp != NULL)
|
2006-04-11 13:44:02 +02:00
|
|
|
|
lp = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, extra->lp, extra->cb + cb);
|
2006-03-11 06:42:01 +01:00
|
|
|
|
else
|
2006-04-11 13:44:02 +02:00
|
|
|
|
lp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cb);
|
2002-10-18 02:24:41 +02:00
|
|
|
|
|
|
|
|
|
if (lp == NULL)
|
|
|
|
|
return AVIERR_MEMORY;
|
|
|
|
|
|
|
|
|
|
extra->lp = lp;
|
2004-07-22 21:43:14 +02:00
|
|
|
|
lp = (LPDWORD) ((LPBYTE)lp + extra->cb);
|
2002-10-18 02:24:41 +02:00
|
|
|
|
extra->cb += cb;
|
|
|
|
|
|
|
|
|
|
/* insert chunk-header in block */
|
|
|
|
|
lp[0] = lpck->ckid;
|
|
|
|
|
lp[1] = lpck->cksize;
|
|
|
|
|
|
|
|
|
|
if (lpck->cksize > 0) {
|
|
|
|
|
if (mmioSeek(hmmio, lpck->dwDataOffset, SEEK_SET) == -1)
|
|
|
|
|
return AVIERR_FILEREAD;
|
2003-06-23 20:10:06 +02:00
|
|
|
|
if (mmioRead(hmmio, (HPSTR)&lp[2], lpck->cksize) != (LONG)lpck->cksize)
|
2002-10-18 02:24:41 +02:00
|
|
|
|
return AVIERR_FILEREAD;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return AVIERR_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-30 05:42:26 +02:00
|
|
|
|
/* reads all non-junk chunks into the extrachunk-structure until it finds
|
2002-10-18 02:24:41 +02:00
|
|
|
|
* the given chunk or the optional parent-chunk is at the end */
|
|
|
|
|
HRESULT FindChunkAndKeepExtras(LPEXTRACHUNKS extra,HMMIO hmmio,MMCKINFO *lpck,
|
|
|
|
|
MMCKINFO *lpckParent,UINT flags)
|
|
|
|
|
{
|
|
|
|
|
FOURCC ckid;
|
|
|
|
|
FOURCC fccType;
|
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
|
|
/* pre-conditions */
|
|
|
|
|
assert(extra != NULL);
|
2002-12-02 19:10:57 +01:00
|
|
|
|
assert(hmmio != NULL);
|
2002-10-18 02:24:41 +02:00
|
|
|
|
assert(lpck != NULL);
|
|
|
|
|
|
2002-10-19 01:48:57 +02:00
|
|
|
|
TRACE("({%p,%lu},%p,%p,%p,0x%X)\n", extra->lp, extra->cb, hmmio, lpck,
|
2002-10-18 02:24:41 +02:00
|
|
|
|
lpckParent, flags);
|
|
|
|
|
|
2004-10-23 00:27:51 +02:00
|
|
|
|
/* what chunk id and form/list type should we search? */
|
2002-10-18 02:24:41 +02:00
|
|
|
|
if (flags & MMIO_FINDCHUNK) {
|
|
|
|
|
ckid = lpck->ckid;
|
|
|
|
|
fccType = 0;
|
|
|
|
|
} else if (flags & MMIO_FINDLIST) {
|
|
|
|
|
ckid = FOURCC_LIST;
|
|
|
|
|
fccType = lpck->fccType;
|
|
|
|
|
} else if (flags & MMIO_FINDRIFF) {
|
|
|
|
|
ckid = FOURCC_RIFF;
|
|
|
|
|
fccType = lpck->fccType;
|
|
|
|
|
} else
|
|
|
|
|
ckid = fccType = (FOURCC)-1; /* collect everything into extra! */
|
|
|
|
|
|
|
|
|
|
TRACE(": find ckid=0x%08lX fccType=0x%08lX\n", ckid, fccType);
|
|
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
hr = mmioDescend(hmmio, lpck, lpckParent, 0);
|
|
|
|
|
if (hr != S_OK) {
|
2004-10-23 00:27:51 +02:00
|
|
|
|
/* No extra chunks in front of desired chunk? */
|
2002-10-18 02:24:41 +02:00
|
|
|
|
if (flags == 0 && hr == MMIOERR_CHUNKNOTFOUND)
|
|
|
|
|
hr = AVIERR_OK;
|
|
|
|
|
return hr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Have we found what we search for? */
|
|
|
|
|
if ((lpck->ckid == ckid) &&
|
|
|
|
|
(fccType == (FOURCC)0 || lpck->fccType == fccType))
|
|
|
|
|
return AVIERR_OK;
|
|
|
|
|
|
|
|
|
|
/* Skip padding chunks, the others put into the extrachunk-structure */
|
|
|
|
|
if (lpck->ckid == ckidAVIPADDING ||
|
|
|
|
|
lpck->ckid == mmioFOURCC('p','a','d','d'))
|
|
|
|
|
hr = mmioAscend(hmmio, lpck, 0);
|
|
|
|
|
else
|
|
|
|
|
hr = ReadChunkIntoExtra(extra, hmmio, lpck);
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
|
return hr;
|
|
|
|
|
}
|
|
|
|
|
}
|