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 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
55 ITmpFile_fnQueryInterface
,
60 ITmpFile_fnCreateStream
,
64 ITmpFile_fnDeleteStream
67 typedef struct _ITmpFileImpl
{
74 PAVISTREAM
*ppStreams
;
77 PAVIFILE
AVIFILE_CreateAVITempFile(int nStreams
, PAVISTREAM
*ppStreams
) {
78 ITmpFileImpl
*tmpFile
;
81 tmpFile
= LocalAlloc(LPTR
, sizeof(ITmpFileImpl
));
85 tmpFile
->lpVtbl
= &itmpft
;
87 memset(&tmpFile
->fInfo
, 0, sizeof(tmpFile
->fInfo
));
89 tmpFile
->fInfo
.dwStreams
= nStreams
;
90 tmpFile
->ppStreams
= LocalAlloc(LPTR
, nStreams
* sizeof(PAVISTREAM
));
91 if (tmpFile
->ppStreams
== NULL
) {
92 LocalFree((HLOCAL
)tmpFile
);
96 for (i
= 0; i
< nStreams
; i
++) {
99 tmpFile
->ppStreams
[i
] = ppStreams
[i
];
101 AVIStreamAddRef(ppStreams
[i
]);
102 AVIStreamInfoW(ppStreams
[i
], &sInfo
, sizeof(sInfo
));
104 tmpFile
->fInfo
.dwScale
= sInfo
.dwScale
;
105 tmpFile
->fInfo
.dwRate
= sInfo
.dwRate
;
106 if (!sInfo
.dwScale
|| !sInfo
.dwRate
) {
107 tmpFile
->fInfo
.dwScale
= 1;
108 tmpFile
->fInfo
.dwRate
= 100;
112 if (tmpFile
->fInfo
.dwSuggestedBufferSize
< sInfo
.dwSuggestedBufferSize
)
113 tmpFile
->fInfo
.dwSuggestedBufferSize
= sInfo
.dwSuggestedBufferSize
;
118 tmp
= MulDiv(AVIStreamSampleToTime(ppStreams
[i
], sInfo
.dwLength
), \
119 tmpFile
->fInfo
.dwScale
, tmpFile
->fInfo
.dwRate
* 1000);
120 if (tmpFile
->fInfo
.dwLength
< tmp
)
121 tmpFile
->fInfo
.dwLength
= tmp
;
123 tmp
= sInfo
.rcFrame
.right
- sInfo
.rcFrame
.left
;
124 if (tmpFile
->fInfo
.dwWidth
< tmp
)
125 tmpFile
->fInfo
.dwWidth
= tmp
;
126 tmp
= sInfo
.rcFrame
.bottom
- sInfo
.rcFrame
.top
;
127 if (tmpFile
->fInfo
.dwHeight
< tmp
)
128 tmpFile
->fInfo
.dwHeight
= tmp
;
132 return (PAVIFILE
)tmpFile
;
135 static HRESULT WINAPI
ITmpFile_fnQueryInterface(IAVIFile
*iface
, REFIID refiid
,
138 ICOM_THIS(ITmpFileImpl
,iface
);
140 TRACE("(%p,%s,%p)\n", This
, debugstr_guid(refiid
), obj
);
142 if (IsEqualGUID(&IID_IUnknown
, refiid
) ||
143 IsEqualGUID(&IID_IAVIFile
, refiid
)) {
145 IAVIFile_AddRef(iface
);
150 return OLE_E_ENUM_NOMORE
;
153 static ULONG WINAPI
ITmpFile_fnAddRef(IAVIFile
*iface
)
155 ICOM_THIS(ITmpFileImpl
,iface
);
157 TRACE("(%p) -> %ld\n", iface
, This
->ref
+ 1);
158 return ++(This
->ref
);
161 static ULONG WINAPI
ITmpFile_fnRelease(IAVIFile
*iface
)
163 ICOM_THIS(ITmpFileImpl
,iface
);
165 TRACE("(%p) -> %ld\n", iface
, This
->ref
- 1);
167 if (!--(This
->ref
)) {
170 for (i
= 0; i
< This
->fInfo
.dwStreams
; i
++) {
171 if (This
->ppStreams
[i
] != NULL
) {
172 AVIStreamRelease(This
->ppStreams
[i
]);
174 This
->ppStreams
[i
] = NULL
;
178 LocalFree((HLOCAL
)This
);
185 static HRESULT WINAPI
ITmpFile_fnInfo(IAVIFile
*iface
,
186 AVIFILEINFOW
*afi
, LONG size
)
188 ICOM_THIS(ITmpFileImpl
,iface
);
190 TRACE("(%p,%p,%ld)\n",iface
,afi
,size
);
193 return AVIERR_BADPARAM
;
195 return AVIERR_BADSIZE
;
197 memcpy(afi
, &This
->fInfo
, min((DWORD
)size
, sizeof(This
->fInfo
)));
199 if ((DWORD
)size
< sizeof(This
->fInfo
))
200 return AVIERR_BUFFERTOOSMALL
;
204 static HRESULT WINAPI
ITmpFile_fnGetStream(IAVIFile
*iface
, PAVISTREAM
*avis
,
205 DWORD fccType
, LONG lParam
)
207 ICOM_THIS(ITmpFileImpl
,iface
);
209 ULONG nStream
= (ULONG
)-1;
211 TRACE("(%p,%p,0x%08lX,%ld)\n", iface
, avis
, fccType
, lParam
);
213 if (avis
== NULL
|| lParam
< 0)
214 return AVIERR_BADPARAM
;
216 if (fccType
!= streamtypeANY
) {
217 /* search the number of the specified stream */
220 for (i
= 0; i
< This
->fInfo
.dwStreams
; i
++) {
221 AVISTREAMINFOW sInfo
;
224 hr
= AVIStreamInfoW(This
->ppStreams
[i
], &sInfo
, sizeof(sInfo
));
228 if (sInfo
.fccType
== fccType
) {
239 /* Does the requested stream exist ? */
240 if (nStream
< This
->fInfo
.dwStreams
&& This
->ppStreams
[nStream
] != NULL
) {
241 *avis
= This
->ppStreams
[nStream
];
242 AVIStreamAddRef(*avis
);
247 /* Sorry, but the specified stream doesn't exist */
248 return AVIERR_NODATA
;
251 static HRESULT WINAPI
ITmpFile_fnCreateStream(IAVIFile
*iface
,PAVISTREAM
*avis
,
254 TRACE("(%p,%p,%p)\n",iface
,avis
,asi
);
256 return AVIERR_UNSUPPORTED
;
259 static HRESULT WINAPI
ITmpFile_fnWriteData(IAVIFile
*iface
, DWORD ckid
,
260 LPVOID lpData
, LONG size
)
262 TRACE("(%p,0x%08lX,%p,%ld)\n", iface
, ckid
, lpData
, size
);
264 return AVIERR_UNSUPPORTED
;
267 static HRESULT WINAPI
ITmpFile_fnReadData(IAVIFile
*iface
, DWORD ckid
,
268 LPVOID lpData
, LONG
*size
)
270 TRACE("(%p,0x%08lX,%p,%p)\n", iface
, ckid
, lpData
, size
);
272 return AVIERR_UNSUPPORTED
;
275 static HRESULT WINAPI
ITmpFile_fnEndRecord(IAVIFile
*iface
)
277 TRACE("(%p)\n",iface
);
282 static HRESULT WINAPI
ITmpFile_fnDeleteStream(IAVIFile
*iface
, DWORD fccType
,
285 TRACE("(%p,0x%08lX,%ld)\n", iface
, fccType
, lParam
);
287 return AVIERR_UNSUPPORTED
;