2002-10-18 02:24:41 +02:00
|
|
|
/*
|
2008-10-18 19:19:02 +02:00
|
|
|
* Copyright 2002 Michael Günnewig
|
2002-10-18 02:24:41 +02:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
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);
|
|
|
|
|
2012-05-15 10:15:32 +02:00
|
|
|
/* reads a chunk out of the extrachunk-structure */
|
2007-04-02 23:50:46 +02:00
|
|
|
HRESULT ReadExtraChunk(const EXTRACHUNKS *extra,FOURCC ckid,LPVOID lpData,LPLONG size)
|
2002-10-18 02:24:41 +02:00
|
|
|
{
|
|
|
|
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 */
|
2007-03-13 22:42:48 +01:00
|
|
|
HRESULT WriteExtraChunk(LPEXTRACHUNKS extra,FOURCC ckid,LPCVOID lpData, LONG size)
|
2002-10-18 02:24:41 +02:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-05-15 10:15:32 +02:00
|
|
|
/* reads a chunk from the HMMIO into the extrachunk-structure */
|
2007-04-02 23:50:46 +02:00
|
|
|
HRESULT ReadChunkIntoExtra(LPEXTRACHUNKS extra,HMMIO hmmio,const MMCKINFO *lpck)
|
2002-10-18 02:24:41 +02:00
|
|
|
{
|
|
|
|
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;
|
2008-09-30 14:55:35 +02:00
|
|
|
MMRESULT mmr;
|
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);
|
|
|
|
|
2006-10-10 01:07:06 +02:00
|
|
|
TRACE("({%p,%u},%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! */
|
|
|
|
|
2006-10-10 01:07:06 +02:00
|
|
|
TRACE(": find ckid=0x%08X fccType=0x%08X\n", ckid, fccType);
|
2002-10-18 02:24:41 +02:00
|
|
|
|
|
|
|
for (;;) {
|
2008-09-30 14:55:35 +02:00
|
|
|
mmr = mmioDescend(hmmio, lpck, lpckParent, 0);
|
|
|
|
if (mmr != MMSYSERR_NOERROR) {
|
2004-10-23 00:27:51 +02:00
|
|
|
/* No extra chunks in front of desired chunk? */
|
2008-09-30 14:55:35 +02:00
|
|
|
if (flags == 0 && mmr == MMIOERR_CHUNKNOTFOUND)
|
|
|
|
return AVIERR_OK;
|
|
|
|
else
|
|
|
|
return AVIERR_FILEREAD;
|
2002-10-18 02:24:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Have we found what we search for? */
|
|
|
|
if ((lpck->ckid == ckid) &&
|
2008-12-08 09:25:44 +01:00
|
|
|
(fccType == 0 || lpck->fccType == fccType))
|
2002-10-18 02:24:41 +02:00
|
|
|
return AVIERR_OK;
|
|
|
|
|
|
|
|
/* Skip padding chunks, the others put into the extrachunk-structure */
|
|
|
|
if (lpck->ckid == ckidAVIPADDING ||
|
|
|
|
lpck->ckid == mmioFOURCC('p','a','d','d'))
|
2008-09-30 14:55:35 +02:00
|
|
|
{
|
|
|
|
mmr = mmioAscend(hmmio, lpck, 0);
|
|
|
|
if (mmr != MMSYSERR_NOERROR) return AVIERR_FILEREAD;
|
|
|
|
}
|
2002-10-18 02:24:41 +02:00
|
|
|
else
|
2008-09-30 14:55:35 +02:00
|
|
|
{
|
|
|
|
HRESULT hr = ReadChunkIntoExtra(extra, hmmio, lpck);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
}
|
2002-10-18 02:24:41 +02:00
|
|
|
}
|
|
|
|
}
|