ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

extrachunk.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2002 Michael Günnewig
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00017  */
00018 
00019 #include <assert.h>
00020 
00021 #include "extrachunk.h"
00022 #include "winbase.h"
00023 #include "wingdi.h"
00024 #include "winuser.h"
00025 #include "vfw.h"
00026 
00027 #include "wine/debug.h"
00028 
00029 WINE_DEFAULT_DEBUG_CHANNEL(avifile);
00030 
00031 /* reads a chunk outof the extrachunk-structure */
00032 HRESULT ReadExtraChunk(const EXTRACHUNKS *extra,FOURCC ckid,LPVOID lpData,LPLONG size)
00033 {
00034   LPBYTE lp;
00035   DWORD  cb;
00036 
00037   /* pre-conditions */
00038   assert(extra != NULL);
00039   assert(size != NULL);
00040 
00041   lp = extra->lp;
00042   cb = extra->cb;
00043 
00044   if (lp != NULL) {
00045     while (cb > 0) {
00046       if (((FOURCC*)lp)[0] == ckid) {
00047     /* found correct chunk */
00048     if (lpData != NULL && *size > 0)
00049       memcpy(lpData, lp + 2 * sizeof(DWORD),
00050          min(((LPDWORD)lp)[1], *(LPDWORD)size));
00051 
00052     *(LPDWORD)size = ((LPDWORD)lp)[1];
00053 
00054     return AVIERR_OK;
00055       } else {
00056     /* skip to next chunk */
00057     cb -= ((LPDWORD)lp)[1] + 2 * sizeof(DWORD);
00058     lp += ((LPDWORD)lp)[1] + 2 * sizeof(DWORD);
00059       }
00060     }
00061   }
00062 
00063   /* wanted chunk doesn't exist */
00064   *size = 0;
00065 
00066   return AVIERR_NODATA;
00067 }
00068 
00069 /* writes a chunk into the extrachunk-structure */
00070 HRESULT WriteExtraChunk(LPEXTRACHUNKS extra,FOURCC ckid,LPCVOID lpData, LONG size)
00071 {
00072   LPDWORD lp;
00073 
00074   /* pre-conditions */
00075   assert(extra != NULL);
00076   assert(lpData != NULL);
00077   assert(size > 0);
00078 
00079   if (extra->lp)
00080     lp = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, extra->lp, extra->cb + size + 2 * sizeof(DWORD));
00081   else
00082     lp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + 2 * sizeof(DWORD));
00083 
00084   if (lp == NULL)
00085     return AVIERR_MEMORY;
00086 
00087   extra->lp  = lp;
00088   lp = (LPDWORD) ((LPBYTE)lp + extra->cb);
00089   extra->cb += size + 2 * sizeof(DWORD);
00090 
00091   /* insert chunk-header in block */
00092   lp[0] = ckid;
00093   lp[1] = size;
00094 
00095   if (lpData != NULL && size > 0)
00096     memcpy(lp + 2, lpData, size);
00097 
00098   return AVIERR_OK;
00099 }
00100 
00101 /* reads a chunk fomr the HMMIO into the extrachunk-structure */
00102 HRESULT ReadChunkIntoExtra(LPEXTRACHUNKS extra,HMMIO hmmio,const MMCKINFO *lpck)
00103 {
00104   LPDWORD lp;
00105   DWORD   cb;
00106 
00107   /* pre-conditions */
00108   assert(extra != NULL);
00109   assert(hmmio != NULL);
00110   assert(lpck  != NULL);
00111 
00112   cb  = lpck->cksize + 2 * sizeof(DWORD);
00113   cb += (cb & 1);
00114 
00115   if (extra->lp != NULL)
00116     lp = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, extra->lp, extra->cb + cb);
00117   else
00118     lp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cb);
00119 
00120   if (lp == NULL)
00121     return AVIERR_MEMORY;
00122 
00123   extra->lp  = lp;
00124   lp = (LPDWORD) ((LPBYTE)lp + extra->cb);
00125   extra->cb += cb;
00126 
00127   /* insert chunk-header in block */
00128   lp[0] = lpck->ckid;
00129   lp[1] = lpck->cksize;
00130 
00131   if (lpck->cksize > 0) {
00132     if (mmioSeek(hmmio, lpck->dwDataOffset, SEEK_SET) == -1)
00133       return AVIERR_FILEREAD;
00134     if (mmioRead(hmmio, (HPSTR)&lp[2], lpck->cksize) != (LONG)lpck->cksize)
00135       return AVIERR_FILEREAD;
00136   }
00137 
00138   return AVIERR_OK;
00139 }
00140 
00141 /* reads all non-junk chunks into the extrachunk-structure until it finds
00142  * the given chunk or the optional parent-chunk is at the end */
00143 HRESULT FindChunkAndKeepExtras(LPEXTRACHUNKS extra,HMMIO hmmio,MMCKINFO *lpck,
00144                    MMCKINFO *lpckParent,UINT flags)
00145 {
00146   FOURCC  ckid;
00147   FOURCC  fccType;
00148   MMRESULT mmr;
00149 
00150   /* pre-conditions */
00151   assert(extra != NULL);
00152   assert(hmmio != NULL);
00153   assert(lpck  != NULL);
00154 
00155   TRACE("({%p,%u},%p,%p,%p,0x%X)\n", extra->lp, extra->cb, hmmio, lpck,
00156     lpckParent, flags);
00157 
00158   /* what chunk id and form/list type should we search? */
00159   if (flags & MMIO_FINDCHUNK) {
00160     ckid    = lpck->ckid;
00161     fccType = 0;
00162   } else if (flags & MMIO_FINDLIST) {
00163     ckid    = FOURCC_LIST;
00164     fccType = lpck->fccType;
00165   } else if (flags & MMIO_FINDRIFF) {
00166     ckid    = FOURCC_RIFF;
00167     fccType = lpck->fccType;
00168   } else
00169     ckid = fccType = (FOURCC)-1; /* collect everything into extra! */
00170 
00171   TRACE(": find ckid=0x%08X fccType=0x%08X\n", ckid, fccType);
00172 
00173   for (;;) {
00174     mmr = mmioDescend(hmmio, lpck, lpckParent, 0);
00175     if (mmr != MMSYSERR_NOERROR) {
00176       /* No extra chunks in front of desired chunk? */
00177       if (flags == 0 && mmr == MMIOERR_CHUNKNOTFOUND)
00178     return AVIERR_OK;
00179       else
00180         return AVIERR_FILEREAD;
00181     }
00182 
00183     /* Have we found what we search for? */
00184     if ((lpck->ckid == ckid) &&
00185     (fccType == 0 || lpck->fccType == fccType))
00186       return AVIERR_OK;
00187 
00188     /* Skip padding chunks, the others put into the extrachunk-structure */
00189     if (lpck->ckid == ckidAVIPADDING ||
00190     lpck->ckid == mmioFOURCC('p','a','d','d'))
00191     {
00192       mmr = mmioAscend(hmmio, lpck, 0);
00193       if (mmr != MMSYSERR_NOERROR) return AVIERR_FILEREAD;
00194     }
00195     else
00196     {
00197       HRESULT hr = ReadChunkIntoExtra(extra, hmmio, lpck);
00198       if (FAILED(hr))
00199         return hr;
00200     }
00201   }
00202 }

Generated on Sat May 26 2012 04:21:23 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.