ReactOS 0.4.15-dev-7924-g5949c20
extrachunk.c File Reference
#include <assert.h>
#include "extrachunk.h"
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
#include "vfw.h"
#include "wine/debug.h"
Include dependency graph for extrachunk.c:

Go to the source code of this file.

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (avifile)
 
HRESULT ReadExtraChunk (const EXTRACHUNKS *extra, FOURCC ckid, LPVOID lpData, LPLONG size)
 
HRESULT WriteExtraChunk (LPEXTRACHUNKS extra, FOURCC ckid, LPCVOID lpData, LONG size)
 
HRESULT ReadChunkIntoExtra (LPEXTRACHUNKS extra, HMMIO hmmio, const MMCKINFO *lpck)
 
HRESULT FindChunkAndKeepExtras (LPEXTRACHUNKS extra, HMMIO hmmio, MMCKINFO *lpck, MMCKINFO *lpckParent, UINT flags)
 

Function Documentation

◆ FindChunkAndKeepExtras()

HRESULT FindChunkAndKeepExtras ( LPEXTRACHUNKS  extra,
HMMIO  hmmio,
MMCKINFO lpck,
MMCKINFO lpckParent,
UINT  flags 
)

Definition at line 143 of file extrachunk.c.

145{
146 FOURCC ckid;
147 FOURCC fccType;
148 MMRESULT mmr;
149
150 /* pre-conditions */
151 assert(extra != NULL);
152 assert(hmmio != NULL);
153 assert(lpck != NULL);
154
155 TRACE("({%p,%u},%p,%p,%p,0x%X)\n", extra->lp, extra->cb, hmmio, lpck,
156 lpckParent, flags);
157
158 /* what chunk id and form/list type should we search? */
159 if (flags & MMIO_FINDCHUNK) {
160 ckid = lpck->ckid;
161 fccType = 0;
162 } else if (flags & MMIO_FINDLIST) {
163 ckid = FOURCC_LIST;
164 fccType = lpck->fccType;
165 } else if (flags & MMIO_FINDRIFF) {
166 ckid = FOURCC_RIFF;
167 fccType = lpck->fccType;
168 } else
169 ckid = fccType = (FOURCC)-1; /* collect everything into extra! */
170
171 TRACE(": find ckid=0x%08X fccType=0x%08X\n", ckid, fccType);
172
173 for (;;) {
174 mmr = mmioDescend(hmmio, lpck, lpckParent, 0);
175 if (mmr != MMSYSERR_NOERROR) {
176 /* No extra chunks in front of desired chunk? */
177 if (flags == 0 && mmr == MMIOERR_CHUNKNOTFOUND)
178 return AVIERR_OK;
179 else
180 return AVIERR_FILEREAD;
181 }
182
183 /* Have we found what we search for? */
184 if ((lpck->ckid == ckid) &&
185 (fccType == 0 || lpck->fccType == fccType))
186 return AVIERR_OK;
187
188 /* Skip padding chunks, the others put into the extrachunk-structure */
189 if (lpck->ckid == ckidAVIPADDING ||
190 lpck->ckid == mmioFOURCC('p','a','d','d'))
191 {
192 mmr = mmioAscend(hmmio, lpck, 0);
193 if (mmr != MMSYSERR_NOERROR) return AVIERR_FILEREAD;
194 }
195 else
196 {
197 HRESULT hr = ReadChunkIntoExtra(extra, hmmio, lpck);
198 if (FAILED(hr))
199 return hr;
200 }
201 }
202}
#define NULL
Definition: types.h:112
MMRESULT WINAPI mmioAscend(HMMIO hmmio, LPMMCKINFO lpck, UINT uFlags)
Definition: mmio.c:1205
MMRESULT WINAPI mmioDescend(HMMIO hmmio, LPMMCKINFO lpck, const MMCKINFO *lpckParent, UINT uFlags)
Definition: mmio.c:1107
#define assert(x)
Definition: debug.h:53
DWORD FOURCC
Definition: dmdls.h:25
HRESULT ReadChunkIntoExtra(LPEXTRACHUNKS extra, HMMIO hmmio, const MMCKINFO *lpck)
Definition: extrachunk.c:102
GLbitfield flags
Definition: glext.h:7161
@ extra
Definition: id3.c:95
#define FAILED(hr)
Definition: intsafe.h:51
#define FOURCC(a, b, c, d)
Definition: memtrack.h:4
#define MMIO_FINDRIFF
Definition: mmsystem.h:552
#define FOURCC_RIFF
Definition: mmsystem.h:564
#define MMIOERR_CHUNKNOTFOUND
Definition: mmsystem.h:517
UINT MMRESULT
Definition: mmsystem.h:962
#define MMIO_FINDCHUNK
Definition: mmsystem.h:551
#define FOURCC_LIST
Definition: mmsystem.h:565
#define MMSYSERR_NOERROR
Definition: mmsystem.h:96
#define mmioFOURCC(c0, c1, c2, c3)
Definition: mmsystem.h:38
#define MMIO_FINDLIST
Definition: mmsystem.h:553
HRESULT hr
Definition: shlfolder.c:183
#define TRACE(s)
Definition: solgame.cpp:4
FOURCC ckid
Definition: mmsystem.h:1507
FOURCC fccType
Definition: mmsystem.h:1509
#define AVIERR_FILEREAD
Definition: vfw.h:1751
#define ckidAVIPADDING
Definition: vfw.h:916
#define AVIERR_OK
Definition: vfw.h:1740

Referenced by AVIFILE_LoadFile().

◆ ReadChunkIntoExtra()

HRESULT ReadChunkIntoExtra ( LPEXTRACHUNKS  extra,
HMMIO  hmmio,
const MMCKINFO lpck 
)

Definition at line 102 of file extrachunk.c.

103{
104 LPDWORD lp;
105 DWORD cb;
106
107 /* pre-conditions */
108 assert(extra != NULL);
109 assert(hmmio != NULL);
110 assert(lpck != NULL);
111
112 cb = lpck->cksize + 2 * sizeof(DWORD);
113 cb += (cb & 1);
114
115 if (extra->lp != NULL)
117 else
119
120 if (lp == NULL)
121 return AVIERR_MEMORY;
122
123 extra->lp = lp;
124 lp = (LPDWORD) ((LPBYTE)lp + extra->cb);
125 extra->cb += cb;
126
127 /* insert chunk-header in block */
128 lp[0] = lpck->ckid;
129 lp[1] = lpck->cksize;
130
131 if (lpck->cksize > 0) {
132 if (mmioSeek(hmmio, lpck->dwDataOffset, SEEK_SET) == -1)
133 return AVIERR_FILEREAD;
134 if (mmioRead(hmmio, (HPSTR)&lp[2], lpck->cksize) != (LONG)lpck->cksize)
135 return AVIERR_FILEREAD;
136 }
137
138 return AVIERR_OK;
139}
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapReAlloc
Definition: compat.h:734
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
LONG WINAPI mmioSeek(HMMIO hmmio, LONG lOffset, INT iOrigin)
Definition: mmio.c:836
LONG WINAPI mmioRead(HMMIO hmmio, HPSTR pch, LONG cch)
Definition: mmio.c:733
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SEEK_SET
Definition: jmemansi.c:26
char * HPSTR
Definition: mmsystem.h:1477
static HMODULE MODULEINFO DWORD cb
Definition: module.c:33
#define LPDWORD
Definition: nt_native.h:46
#define DWORD
Definition: nt_native.h:44
long LONG
Definition: pedump.c:60
DWORD cksize
Definition: mmsystem.h:1508
DWORD dwDataOffset
Definition: mmsystem.h:1510
unsigned char * LPBYTE
Definition: typedefs.h:53
uint32_t * LPDWORD
Definition: typedefs.h:59
#define AVIERR_MEMORY
Definition: vfw.h:1745

Referenced by AVIFILE_LoadFile(), and FindChunkAndKeepExtras().

◆ ReadExtraChunk()

HRESULT ReadExtraChunk ( const EXTRACHUNKS extra,
FOURCC  ckid,
LPVOID  lpData,
LPLONG  size 
)

Definition at line 32 of file extrachunk.c.

33{
34 LPBYTE lp;
35 DWORD cb;
36
37 /* pre-conditions */
38 assert(extra != NULL);
39 assert(size != NULL);
40
41 lp = extra->lp;
42 cb = extra->cb;
43
44 if (lp != NULL) {
45 while (cb > 0) {
46 if (((FOURCC*)lp)[0] == ckid) {
47 /* found correct chunk */
48 if (lpData != NULL && *size > 0)
49 memcpy(lpData, lp + 2 * sizeof(DWORD),
50 min(((LPDWORD)lp)[1], *(LPDWORD)size));
51
52 *(LPDWORD)size = ((LPDWORD)lp)[1];
53
54 return AVIERR_OK;
55 } else {
56 /* skip to next chunk */
57 cb -= ((LPDWORD)lp)[1] + 2 * sizeof(DWORD);
58 lp += ((LPDWORD)lp)[1] + 2 * sizeof(DWORD);
59 }
60 }
61 }
62
63 /* wanted chunk doesn't exist */
64 *size = 0;
65
66 return AVIERR_NODATA;
67}
GLsizeiptr size
Definition: glext.h:5919
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define min(a, b)
Definition: monoChain.cc:55
#define AVIERR_NODATA
Definition: vfw.h:1757

Referenced by IAVIFile_fnReadData(), and IAVIStream_fnReadData().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( avifile  )

◆ WriteExtraChunk()

HRESULT WriteExtraChunk ( LPEXTRACHUNKS  extra,
FOURCC  ckid,
LPCVOID  lpData,
LONG  size 
)

Definition at line 70 of file extrachunk.c.

71{
72 LPDWORD lp;
73
74 /* pre-conditions */
75 assert(extra != NULL);
76 assert(lpData != NULL);
77 assert(size > 0);
78
79 if (extra->lp)
80 lp = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, extra->lp, extra->cb + size + 2 * sizeof(DWORD));
81 else
82 lp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + 2 * sizeof(DWORD));
83
84 if (lp == NULL)
85 return AVIERR_MEMORY;
86
87 extra->lp = lp;
88 lp = (LPDWORD) ((LPBYTE)lp + extra->cb);
89 extra->cb += size + 2 * sizeof(DWORD);
90
91 /* insert chunk-header in block */
92 lp[0] = ckid;
93 lp[1] = size;
94
95 if (lpData != NULL && size > 0)
96 memcpy(lp + 2, lpData, size);
97
98 return AVIERR_OK;
99}

Referenced by IAVIFile_fnWriteData(), and IAVIStream_fnWriteData().