2 * Copyright 2003 Michael Günnewig
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #define COM_NO_WINDOWS_H
33 #include "avifile_private.h"
34 #include "extrachunk.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(avifile
);
40 /***********************************************************************/
42 static HRESULT WINAPI
ITmpFile_fnQueryInterface(IAVIFile
* iface
,REFIID refiid
,LPVOID
*obj
);
43 static ULONG WINAPI
ITmpFile_fnAddRef(IAVIFile
* iface
);
44 static ULONG WINAPI
ITmpFile_fnRelease(IAVIFile
* iface
);
45 static HRESULT WINAPI
ITmpFile_fnInfo(IAVIFile
*iface
,AVIFILEINFOW
*afi
,LONG size
);
46 static HRESULT WINAPI
ITmpFile_fnGetStream(IAVIFile
*iface
,PAVISTREAM
*avis
,DWORD fccType
,LONG lParam
);
47 static HRESULT WINAPI
ITmpFile_fnCreateStream(IAVIFile
*iface
,PAVISTREAM
*avis
,AVISTREAMINFOW
*asi
);
48 static HRESULT WINAPI
ITmpFile_fnWriteData(IAVIFile
*iface
,DWORD ckid
,LPVOID lpData
,LONG size
);
49 static HRESULT WINAPI
ITmpFile_fnReadData(IAVIFile
*iface
,DWORD ckid
,LPVOID lpData
,LONG
*size
);
50 static HRESULT WINAPI
ITmpFile_fnEndRecord(IAVIFile
*iface
);
51 static HRESULT WINAPI
ITmpFile_fnDeleteStream(IAVIFile
*iface
,DWORD fccType
,LONG lParam
);
53 struct IAVIFileVtbl itmpft
= {
54 ITmpFile_fnQueryInterface
,
59 ITmpFile_fnCreateStream
,
63 ITmpFile_fnDeleteStream
66 typedef struct _ITmpFileImpl
{
73 PAVISTREAM
*ppStreams
;
76 PAVIFILE
AVIFILE_CreateAVITempFile(int nStreams
, PAVISTREAM
*ppStreams
) {
77 ITmpFileImpl
*tmpFile
;
80 tmpFile
= LocalAlloc(LPTR
, sizeof(ITmpFileImpl
));
84 tmpFile
->lpVtbl
= &itmpft
;
86 memset(&tmpFile
->fInfo
, 0, sizeof(tmpFile
->fInfo
));
88 tmpFile
->fInfo
.dwStreams
= nStreams
;
89 tmpFile
->ppStreams
= LocalAlloc(LPTR
, nStreams
* sizeof(PAVISTREAM
));
90 if (tmpFile
->ppStreams
== NULL
) {
91 LocalFree((HLOCAL
)tmpFile
);
95 for (i
= 0; i
< nStreams
; i
++) {
98 tmpFile
->ppStreams
[i
] = ppStreams
[i
];
100 AVIStreamAddRef(ppStreams
[i
]);
101 AVIStreamInfoW(ppStreams
[i
], &sInfo
, sizeof(sInfo
));
103 tmpFile
->fInfo
.dwScale
= sInfo
.dwScale
;
104 tmpFile
->fInfo
.dwRate
= sInfo
.dwRate
;
105 if (!sInfo
.dwScale
|| !sInfo
.dwRate
) {
106 tmpFile
->fInfo
.dwScale
= 1;
107 tmpFile
->fInfo
.dwRate
= 100;
111 if (tmpFile
->fInfo
.dwSuggestedBufferSize
< sInfo
.dwSuggestedBufferSize
)
112 tmpFile
->fInfo
.dwSuggestedBufferSize
= sInfo
.dwSuggestedBufferSize
;
117 tmp
= MulDiv(AVIStreamSampleToTime(ppStreams
[i
], sInfo
.dwLength
), \
118 tmpFile
->fInfo
.dwScale
, tmpFile
->fInfo
.dwRate
* 1000);
119 if (tmpFile
->fInfo
.dwLength
< tmp
)
120 tmpFile
->fInfo
.dwLength
= tmp
;
122 tmp
= sInfo
.rcFrame
.right
- sInfo
.rcFrame
.left
;
123 if (tmpFile
->fInfo
.dwWidth
< tmp
)
124 tmpFile
->fInfo
.dwWidth
= tmp
;
125 tmp
= sInfo
.rcFrame
.bottom
- sInfo
.rcFrame
.top
;
126 if (tmpFile
->fInfo
.dwHeight
< tmp
)
127 tmpFile
->fInfo
.dwHeight
= tmp
;
131 return (PAVIFILE
)tmpFile
;
134 static HRESULT WINAPI
ITmpFile_fnQueryInterface(IAVIFile
*iface
, REFIID refiid
,
137 ITmpFileImpl
*This
= (ITmpFileImpl
*)iface
;
139 TRACE("(%p,%s,%p)\n", This
, debugstr_guid(refiid
), obj
);
141 if (IsEqualGUID(&IID_IUnknown
, refiid
) ||
142 IsEqualGUID(&IID_IAVIFile
, refiid
)) {
144 IAVIFile_AddRef(iface
);
149 return OLE_E_ENUM_NOMORE
;
152 static ULONG WINAPI
ITmpFile_fnAddRef(IAVIFile
*iface
)
154 ITmpFileImpl
*This
= (ITmpFileImpl
*)iface
;
155 ULONG ref
= InterlockedIncrement(&This
->ref
);
157 TRACE("(%p) -> %ld\n", iface
, ref
);
162 static ULONG WINAPI
ITmpFile_fnRelease(IAVIFile
*iface
)
164 ITmpFileImpl
*This
= (ITmpFileImpl
*)iface
;
165 ULONG ref
= InterlockedDecrement(&This
->ref
);
167 TRACE("(%p) -> %ld\n", iface
, ref
);
172 for (i
= 0; i
< This
->fInfo
.dwStreams
; i
++) {
173 if (This
->ppStreams
[i
] != NULL
) {
174 AVIStreamRelease(This
->ppStreams
[i
]);
176 This
->ppStreams
[i
] = NULL
;
180 LocalFree((HLOCAL
)This
);
187 static HRESULT WINAPI
ITmpFile_fnInfo(IAVIFile
*iface
,
188 AVIFILEINFOW
*afi
, LONG size
)
190 ITmpFileImpl
*This
= (ITmpFileImpl
*)iface
;
192 TRACE("(%p,%p,%ld)\n",iface
,afi
,size
);
195 return AVIERR_BADPARAM
;
197 return AVIERR_BADSIZE
;
199 memcpy(afi
, &This
->fInfo
, min((DWORD
)size
, sizeof(This
->fInfo
)));
201 if ((DWORD
)size
< sizeof(This
->fInfo
))
202 return AVIERR_BUFFERTOOSMALL
;
206 static HRESULT WINAPI
ITmpFile_fnGetStream(IAVIFile
*iface
, PAVISTREAM
*avis
,
207 DWORD fccType
, LONG lParam
)
209 ITmpFileImpl
*This
= (ITmpFileImpl
*)iface
;
211 ULONG nStream
= (ULONG
)-1;
213 TRACE("(%p,%p,0x%08lX,%ld)\n", iface
, avis
, fccType
, lParam
);
215 if (avis
== NULL
|| lParam
< 0)
216 return AVIERR_BADPARAM
;
218 if (fccType
!= streamtypeANY
) {
219 /* search the number of the specified stream */
222 for (i
= 0; i
< This
->fInfo
.dwStreams
; i
++) {
223 AVISTREAMINFOW sInfo
;
226 hr
= AVIStreamInfoW(This
->ppStreams
[i
], &sInfo
, sizeof(sInfo
));
230 if (sInfo
.fccType
== fccType
) {
241 /* Does the requested stream exist ? */
242 if (nStream
< This
->fInfo
.dwStreams
&& This
->ppStreams
[nStream
] != NULL
) {
243 *avis
= This
->ppStreams
[nStream
];
244 AVIStreamAddRef(*avis
);
249 /* Sorry, but the specified stream doesn't exist */
250 return AVIERR_NODATA
;
253 static HRESULT WINAPI
ITmpFile_fnCreateStream(IAVIFile
*iface
,PAVISTREAM
*avis
,
256 TRACE("(%p,%p,%p)\n",iface
,avis
,asi
);
258 return AVIERR_UNSUPPORTED
;
261 static HRESULT WINAPI
ITmpFile_fnWriteData(IAVIFile
*iface
, DWORD ckid
,
262 LPVOID lpData
, LONG size
)
264 TRACE("(%p,0x%08lX,%p,%ld)\n", iface
, ckid
, lpData
, size
);
266 return AVIERR_UNSUPPORTED
;
269 static HRESULT WINAPI
ITmpFile_fnReadData(IAVIFile
*iface
, DWORD ckid
,
270 LPVOID lpData
, LONG
*size
)
272 TRACE("(%p,0x%08lX,%p,%p)\n", iface
, ckid
, lpData
, size
);
274 return AVIERR_UNSUPPORTED
;
277 static HRESULT WINAPI
ITmpFile_fnEndRecord(IAVIFile
*iface
)
279 TRACE("(%p)\n",iface
);
284 static HRESULT WINAPI
ITmpFile_fnDeleteStream(IAVIFile
*iface
, DWORD fccType
,
287 TRACE("(%p,0x%08lX,%ld)\n", iface
, fccType
, lParam
);
289 return AVIERR_UNSUPPORTED
;