Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygentmpfile.c
Go to the documentation of this file.
00001 /* 00002 * Copyright 2003 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 <stdarg.h> 00020 00021 #include "windef.h" 00022 #include "winbase.h" 00023 #include "wingdi.h" 00024 #include "winuser.h" 00025 #include "winerror.h" 00026 #include "vfw.h" 00027 00028 #include "avifile_private.h" 00029 #include "extrachunk.h" 00030 00031 #include "wine/debug.h" 00032 00033 WINE_DEFAULT_DEBUG_CHANNEL(avifile); 00034 00035 /***********************************************************************/ 00036 00037 typedef struct _ITmpFileImpl { 00038 IAVIFile IAVIFile_iface; 00039 LONG ref; 00040 00041 AVIFILEINFOW fInfo; 00042 PAVISTREAM *ppStreams; 00043 } ITmpFileImpl; 00044 00045 static inline ITmpFileImpl *impl_from_IAVIFile(IAVIFile *iface) 00046 { 00047 return CONTAINING_RECORD(iface, ITmpFileImpl, IAVIFile_iface); 00048 } 00049 00050 static HRESULT WINAPI ITmpFile_fnQueryInterface(IAVIFile *iface, REFIID refiid, 00051 LPVOID *obj) 00052 { 00053 ITmpFileImpl *This = impl_from_IAVIFile(iface); 00054 00055 TRACE("(%p,%s,%p)\n", This, debugstr_guid(refiid), obj); 00056 00057 if (IsEqualGUID(&IID_IUnknown, refiid) || 00058 IsEqualGUID(&IID_IAVIFile, refiid)) { 00059 *obj = iface; 00060 IAVIFile_AddRef(iface); 00061 00062 return S_OK; 00063 } 00064 00065 return OLE_E_ENUM_NOMORE; 00066 } 00067 00068 static ULONG WINAPI ITmpFile_fnAddRef(IAVIFile *iface) 00069 { 00070 ITmpFileImpl *This = impl_from_IAVIFile(iface); 00071 ULONG ref = InterlockedIncrement(&This->ref); 00072 00073 TRACE("(%p) -> %d\n", iface, ref); 00074 00075 return ref; 00076 } 00077 00078 static ULONG WINAPI ITmpFile_fnRelease(IAVIFile *iface) 00079 { 00080 ITmpFileImpl *This = impl_from_IAVIFile(iface); 00081 ULONG ref = InterlockedDecrement(&This->ref); 00082 00083 TRACE("(%p) -> %d\n", iface, ref); 00084 00085 if (!ref) { 00086 unsigned int i; 00087 00088 for (i = 0; i < This->fInfo.dwStreams; i++) { 00089 if (This->ppStreams[i] != NULL) { 00090 AVIStreamRelease(This->ppStreams[i]); 00091 00092 This->ppStreams[i] = NULL; 00093 } 00094 } 00095 00096 HeapFree(GetProcessHeap(), 0, This); 00097 return 0; 00098 } 00099 00100 return ref; 00101 } 00102 00103 static HRESULT WINAPI ITmpFile_fnInfo(IAVIFile *iface, 00104 AVIFILEINFOW *afi, LONG size) 00105 { 00106 ITmpFileImpl *This = impl_from_IAVIFile(iface); 00107 00108 TRACE("(%p,%p,%d)\n",iface,afi,size); 00109 00110 if (afi == NULL) 00111 return AVIERR_BADPARAM; 00112 if (size < 0) 00113 return AVIERR_BADSIZE; 00114 00115 memcpy(afi, &This->fInfo, min((DWORD)size, sizeof(This->fInfo))); 00116 00117 if ((DWORD)size < sizeof(This->fInfo)) 00118 return AVIERR_BUFFERTOOSMALL; 00119 return AVIERR_OK; 00120 } 00121 00122 static HRESULT WINAPI ITmpFile_fnGetStream(IAVIFile *iface, PAVISTREAM *avis, 00123 DWORD fccType, LONG lParam) 00124 { 00125 ITmpFileImpl *This = impl_from_IAVIFile(iface); 00126 00127 ULONG nStream = (ULONG)-1; 00128 00129 TRACE("(%p,%p,0x%08X,%d)\n", iface, avis, fccType, lParam); 00130 00131 if (avis == NULL || lParam < 0) 00132 return AVIERR_BADPARAM; 00133 00134 if (fccType != streamtypeANY) { 00135 /* search the number of the specified stream */ 00136 ULONG i; 00137 00138 for (i = 0; i < This->fInfo.dwStreams; i++) { 00139 AVISTREAMINFOW sInfo; 00140 HRESULT hr; 00141 00142 hr = AVIStreamInfoW(This->ppStreams[i], &sInfo, sizeof(sInfo)); 00143 if (FAILED(hr)) 00144 return hr; 00145 00146 if (sInfo.fccType == fccType) { 00147 if (lParam == 0) { 00148 nStream = i; 00149 break; 00150 } else 00151 lParam--; 00152 } 00153 } 00154 } else 00155 nStream = lParam; 00156 00157 /* Does the requested stream exist ? */ 00158 if (nStream < This->fInfo.dwStreams && This->ppStreams[nStream] != NULL) { 00159 *avis = This->ppStreams[nStream]; 00160 AVIStreamAddRef(*avis); 00161 00162 return AVIERR_OK; 00163 } 00164 00165 /* Sorry, but the specified stream doesn't exist */ 00166 return AVIERR_NODATA; 00167 } 00168 00169 static HRESULT WINAPI ITmpFile_fnCreateStream(IAVIFile *iface,PAVISTREAM *avis, 00170 AVISTREAMINFOW *asi) 00171 { 00172 TRACE("(%p,%p,%p)\n",iface,avis,asi); 00173 00174 return AVIERR_UNSUPPORTED; 00175 } 00176 00177 static HRESULT WINAPI ITmpFile_fnWriteData(IAVIFile *iface, DWORD ckid, 00178 LPVOID lpData, LONG size) 00179 { 00180 TRACE("(%p,0x%08X,%p,%d)\n", iface, ckid, lpData, size); 00181 00182 return AVIERR_UNSUPPORTED; 00183 } 00184 00185 static HRESULT WINAPI ITmpFile_fnReadData(IAVIFile *iface, DWORD ckid, 00186 LPVOID lpData, LONG *size) 00187 { 00188 TRACE("(%p,0x%08X,%p,%p)\n", iface, ckid, lpData, size); 00189 00190 return AVIERR_UNSUPPORTED; 00191 } 00192 00193 static HRESULT WINAPI ITmpFile_fnEndRecord(IAVIFile *iface) 00194 { 00195 TRACE("(%p)\n",iface); 00196 00197 return AVIERR_OK; 00198 } 00199 00200 static HRESULT WINAPI ITmpFile_fnDeleteStream(IAVIFile *iface, DWORD fccType, 00201 LONG lParam) 00202 { 00203 TRACE("(%p,0x%08X,%d)\n", iface, fccType, lParam); 00204 00205 return AVIERR_UNSUPPORTED; 00206 } 00207 00208 static const struct IAVIFileVtbl itmpft = { 00209 ITmpFile_fnQueryInterface, 00210 ITmpFile_fnAddRef, 00211 ITmpFile_fnRelease, 00212 ITmpFile_fnInfo, 00213 ITmpFile_fnGetStream, 00214 ITmpFile_fnCreateStream, 00215 ITmpFile_fnWriteData, 00216 ITmpFile_fnReadData, 00217 ITmpFile_fnEndRecord, 00218 ITmpFile_fnDeleteStream 00219 }; 00220 00221 PAVIFILE AVIFILE_CreateAVITempFile(int nStreams, const PAVISTREAM *ppStreams) 00222 { 00223 ITmpFileImpl *tmpFile; 00224 int i; 00225 00226 tmpFile = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ITmpFileImpl)); 00227 if (tmpFile == NULL) 00228 return NULL; 00229 00230 tmpFile->IAVIFile_iface.lpVtbl = &itmpft; 00231 tmpFile->ref = 1; 00232 memset(&tmpFile->fInfo, 0, sizeof(tmpFile->fInfo)); 00233 00234 tmpFile->fInfo.dwStreams = nStreams; 00235 tmpFile->ppStreams = HeapAlloc(GetProcessHeap(), 0, nStreams * sizeof(PAVISTREAM)); 00236 if (tmpFile->ppStreams == NULL) { 00237 HeapFree(GetProcessHeap(), 0, tmpFile); 00238 return NULL; 00239 } 00240 00241 for (i = 0; i < nStreams; i++) { 00242 AVISTREAMINFOW sInfo; 00243 00244 tmpFile->ppStreams[i] = ppStreams[i]; 00245 00246 AVIStreamAddRef(ppStreams[i]); 00247 AVIStreamInfoW(ppStreams[i], &sInfo, sizeof(sInfo)); 00248 if (i == 0) { 00249 tmpFile->fInfo.dwScale = sInfo.dwScale; 00250 tmpFile->fInfo.dwRate = sInfo.dwRate; 00251 if (!sInfo.dwScale || !sInfo.dwRate) { 00252 tmpFile->fInfo.dwScale = 1; 00253 tmpFile->fInfo.dwRate = 100; 00254 } 00255 } 00256 00257 if (tmpFile->fInfo.dwSuggestedBufferSize < sInfo.dwSuggestedBufferSize) 00258 tmpFile->fInfo.dwSuggestedBufferSize = sInfo.dwSuggestedBufferSize; 00259 00260 { 00261 register DWORD tmp; 00262 00263 tmp = MulDiv(AVIStreamSampleToTime(ppStreams[i], sInfo.dwLength), 00264 tmpFile->fInfo.dwScale, tmpFile->fInfo.dwRate * 1000); 00265 if (tmpFile->fInfo.dwLength < tmp) 00266 tmpFile->fInfo.dwLength = tmp; 00267 00268 tmp = sInfo.rcFrame.right - sInfo.rcFrame.left; 00269 if (tmpFile->fInfo.dwWidth < tmp) 00270 tmpFile->fInfo.dwWidth = tmp; 00271 tmp = sInfo.rcFrame.bottom - sInfo.rcFrame.top; 00272 if (tmpFile->fInfo.dwHeight < tmp) 00273 tmpFile->fInfo.dwHeight = tmp; 00274 } 00275 } 00276 00277 return (PAVIFILE)tmpFile; 00278 } Generated on Sat May 26 2012 04:21:23 for ReactOS by
1.7.6.1
|