2 * AVI Decompressor (VFW decompressors wrapper)
4 * Copyright 2004-2005 Christian Costa
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "quartz_private.h"
38 #include "wine/unicode.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(quartz
);
43 typedef struct AVIDecImpl
46 IUnknown
*seekthru_unk
;
49 BITMAPINFOHEADER
* pBihIn
;
50 BITMAPINFOHEADER
* pBihOut
;
53 static const IBaseFilterVtbl AVIDec_Vtbl
;
55 static HRESULT WINAPI
AVIDec_StartStreaming(TransformFilter
* pTransformFilter
)
57 AVIDecImpl
* This
= (AVIDecImpl
*)pTransformFilter
;
60 TRACE("(%p)->()\n", This
);
62 result
= ICDecompressBegin(This
->hvid
, This
->pBihIn
, This
->pBihOut
);
63 if (result
!= ICERR_OK
)
65 ERR("Cannot start processing (%d)\n", result
);
71 static HRESULT WINAPI
AVIDec_Receive(TransformFilter
*tf
, IMediaSample
*pSample
)
73 AVIDecImpl
* This
= (AVIDecImpl
*)tf
;
77 IMediaSample
* pOutSample
= NULL
;
82 LONGLONG tStart
, tStop
;
84 EnterCriticalSection(&This
->tf
.filter
.csFilter
);
85 hr
= IMediaSample_GetPointer(pSample
, &pbSrcStream
);
88 ERR("Cannot get pointer to sample data (%x)\n", hr
);
92 cbSrcStream
= IMediaSample_GetActualDataLength(pSample
);
94 TRACE("Sample data ptr = %p, size = %d\n", pbSrcStream
, cbSrcStream
);
96 hr
= IPin_ConnectionMediaType(This
->tf
.ppPins
[0], &amt
);
98 ERR("Unable to retrieve media type\n");
102 /* Update input size to match sample size */
103 This
->pBihIn
->biSizeImage
= cbSrcStream
;
105 hr
= BaseOutputPinImpl_GetDeliveryBuffer((BaseOutputPin
*)This
->tf
.ppPins
[1], &pOutSample
, NULL
, NULL
, 0);
107 ERR("Unable to get delivery buffer (%x)\n", hr
);
111 hr
= IMediaSample_SetActualDataLength(pOutSample
, 0);
114 hr
= IMediaSample_GetPointer(pOutSample
, &pbDstStream
);
116 ERR("Unable to get pointer to buffer (%x)\n", hr
);
119 cbDstStream
= IMediaSample_GetSize(pOutSample
);
120 if (cbDstStream
< This
->pBihOut
->biSizeImage
) {
121 ERR("Sample size is too small %d < %d\n", cbDstStream
, This
->pBihOut
->biSizeImage
);
126 res
= ICDecompress(This
->hvid
, 0, This
->pBihIn
, pbSrcStream
, This
->pBihOut
, pbDstStream
);
128 ERR("Error occurred during the decompression (%x)\n", res
);
130 IMediaSample_SetActualDataLength(pOutSample
, This
->pBihOut
->biSizeImage
);
132 IMediaSample_SetPreroll(pOutSample
, (IMediaSample_IsPreroll(pSample
) == S_OK
));
133 IMediaSample_SetDiscontinuity(pOutSample
, (IMediaSample_IsDiscontinuity(pSample
) == S_OK
));
134 IMediaSample_SetSyncPoint(pOutSample
, (IMediaSample_IsSyncPoint(pSample
) == S_OK
));
136 if (IMediaSample_GetTime(pSample
, &tStart
, &tStop
) == S_OK
)
137 IMediaSample_SetTime(pOutSample
, &tStart
, &tStop
);
139 IMediaSample_SetTime(pOutSample
, NULL
, NULL
);
141 LeaveCriticalSection(&This
->tf
.filter
.csFilter
);
142 hr
= BaseOutputPinImpl_Deliver((BaseOutputPin
*)This
->tf
.ppPins
[1], pOutSample
);
143 if (hr
!= S_OK
&& hr
!= VFW_E_NOT_CONNECTED
)
144 ERR("Error sending sample (%x)\n", hr
);
145 IMediaSample_Release(pOutSample
);
150 IMediaSample_Release(pOutSample
);
152 LeaveCriticalSection(&This
->tf
.filter
.csFilter
);
156 static HRESULT WINAPI
AVIDec_StopStreaming(TransformFilter
* pTransformFilter
)
158 AVIDecImpl
* This
= (AVIDecImpl
*)pTransformFilter
;
161 TRACE("(%p)->()\n", This
);
166 result
= ICDecompressEnd(This
->hvid
);
167 if (result
!= ICERR_OK
)
169 ERR("Cannot stop processing (%d)\n", result
);
175 static HRESULT WINAPI
AVIDec_SetMediaType(TransformFilter
*tf
, PIN_DIRECTION dir
, const AM_MEDIA_TYPE
* pmt
)
177 AVIDecImpl
* This
= (AVIDecImpl
*)tf
;
178 HRESULT hr
= VFW_E_TYPE_NOT_ACCEPTED
;
180 TRACE("(%p)->(%p)\n", This
, pmt
);
182 if (dir
!= PINDIR_INPUT
)
185 /* Check root (GUID w/o FOURCC) */
186 if ((IsEqualIID(&pmt
->majortype
, &MEDIATYPE_Video
)) &&
187 (!memcmp(((const char *)&pmt
->subtype
)+4, ((const char *)&MEDIATYPE_Video
)+4, sizeof(GUID
)-4)))
189 VIDEOINFOHEADER
*format1
= (VIDEOINFOHEADER
*)pmt
->pbFormat
;
190 VIDEOINFOHEADER2
*format2
= (VIDEOINFOHEADER2
*)pmt
->pbFormat
;
191 BITMAPINFOHEADER
*bmi
;
193 if (IsEqualIID(&pmt
->formattype
, &FORMAT_VideoInfo
))
194 bmi
= &format1
->bmiHeader
;
195 else if (IsEqualIID(&pmt
->formattype
, &FORMAT_VideoInfo2
))
196 bmi
= &format2
->bmiHeader
;
199 TRACE("Fourcc: %s\n", debugstr_an((const char *)&pmt
->subtype
.Data1
, 4));
201 This
->hvid
= ICLocate(pmt
->majortype
.Data1
, pmt
->subtype
.Data1
, bmi
, NULL
, ICMODE_DECOMPRESS
);
204 AM_MEDIA_TYPE
* outpmt
= &This
->tf
.pmt
;
205 const CLSID
* outsubtype
;
207 DWORD output_depth
= bmi
->biBitCount
;
209 FreeMediaType(outpmt
);
211 switch(bmi
->biBitCount
)
213 case 32: outsubtype
= &MEDIASUBTYPE_RGB32
; break;
214 case 24: outsubtype
= &MEDIASUBTYPE_RGB24
; break;
215 case 16: outsubtype
= &MEDIASUBTYPE_RGB565
; break;
216 case 8: outsubtype
= &MEDIASUBTYPE_RGB8
; break;
218 WARN("Non standard input depth %d, forced output depth to 32\n", bmi
->biBitCount
);
219 outsubtype
= &MEDIASUBTYPE_RGB32
;
224 /* Copy bitmap header from media type to 1 for input and 1 for output */
225 bih_size
= bmi
->biSize
+ bmi
->biClrUsed
* 4;
226 This
->pBihIn
= CoTaskMemAlloc(bih_size
);
232 This
->pBihOut
= CoTaskMemAlloc(bih_size
);
238 memcpy(This
->pBihIn
, bmi
, bih_size
);
239 memcpy(This
->pBihOut
, bmi
, bih_size
);
241 /* Update output format as non compressed bitmap */
242 This
->pBihOut
->biCompression
= 0;
243 This
->pBihOut
->biBitCount
= output_depth
;
244 This
->pBihOut
->biSizeImage
= This
->pBihOut
->biWidth
* This
->pBihOut
->biHeight
* This
->pBihOut
->biBitCount
/ 8;
245 TRACE("Size: %u\n", This
->pBihIn
->biSize
);
246 result
= ICDecompressQuery(This
->hvid
, This
->pBihIn
, This
->pBihOut
);
247 if (result
!= ICERR_OK
)
249 ERR("Unable to found a suitable output format (%d)\n", result
);
253 /* Update output media type */
254 CopyMediaType(outpmt
, pmt
);
255 outpmt
->subtype
= *outsubtype
;
257 if (IsEqualIID(&pmt
->formattype
, &FORMAT_VideoInfo
))
258 memcpy(&(((VIDEOINFOHEADER
*)outpmt
->pbFormat
)->bmiHeader
), This
->pBihOut
, This
->pBihOut
->biSize
);
259 else if (IsEqualIID(&pmt
->formattype
, &FORMAT_VideoInfo2
))
260 memcpy(&(((VIDEOINFOHEADER2
*)outpmt
->pbFormat
)->bmiHeader
), This
->pBihOut
, This
->pBihOut
->biSize
);
264 TRACE("Connection accepted\n");
267 TRACE("Unable to find a suitable VFW decompressor\n");
272 TRACE("Connection refused\n");
276 static HRESULT WINAPI
AVIDec_CompleteConnect(TransformFilter
*tf
, PIN_DIRECTION dir
, IPin
*pin
)
278 AVIDecImpl
* This
= (AVIDecImpl
*)tf
;
280 TRACE("(%p)\n", This
);
282 if (dir
== PINDIR_INPUT
)
284 /* Update buffer size of media samples in output */
285 ((BaseOutputPin
*)This
->tf
.ppPins
[1])->allocProps
.cbBuffer
= This
->pBihOut
->biSizeImage
;
290 static HRESULT WINAPI
AVIDec_BreakConnect(TransformFilter
*tf
, PIN_DIRECTION dir
)
292 AVIDecImpl
*This
= (AVIDecImpl
*)tf
;
294 TRACE("(%p)->()\n", This
);
296 if (dir
== PINDIR_INPUT
)
301 CoTaskMemFree(This
->pBihIn
);
303 CoTaskMemFree(This
->pBihOut
);
307 This
->pBihOut
= NULL
;
313 static const TransformFilterFuncTable AVIDec_FuncsTable
= {
314 AVIDec_StartStreaming
,
316 AVIDec_StopStreaming
,
319 AVIDec_CompleteConnect
,
327 HRESULT
AVIDec_create(IUnknown
* pUnkOuter
, LPVOID
* ppv
)
332 TRACE("(%p, %p)\n", pUnkOuter
, ppv
);
337 return CLASS_E_NOAGGREGATION
;
339 hr
= TransformFilter_Construct(&AVIDec_Vtbl
, sizeof(AVIDecImpl
), &CLSID_AVIDec
, &AVIDec_FuncsTable
, (IBaseFilter
**)&This
);
345 ISeekingPassThru
*passthru
;
346 hr
= CoCreateInstance(&CLSID_SeekingPassThru
, (IUnknown
*)This
, CLSCTX_INPROC_SERVER
, &IID_IUnknown
, (void**)&This
->seekthru_unk
);
347 IUnknown_QueryInterface(This
->seekthru_unk
, &IID_ISeekingPassThru
, (void**)&passthru
);
348 ISeekingPassThru_Init(passthru
, FALSE
, (IPin
*)This
->tf
.ppPins
[0]);
349 ISeekingPassThru_Release(passthru
);
354 This
->pBihOut
= NULL
;
361 HRESULT WINAPI
AVIDec_QueryInterface(IBaseFilter
* iface
, REFIID riid
, LPVOID
* ppv
)
364 AVIDecImpl
*This
= (AVIDecImpl
*)iface
;
365 TRACE("(%p/%p)->(%s, %p)\n", This
, iface
, qzdebugstr_guid(riid
), ppv
);
367 if (IsEqualIID(riid
, &IID_IMediaSeeking
))
368 return IUnknown_QueryInterface(This
->seekthru_unk
, riid
, ppv
);
370 hr
= TransformFilterImpl_QueryInterface(iface
, riid
, ppv
);
375 static const IBaseFilterVtbl AVIDec_Vtbl
=
377 AVIDec_QueryInterface
,
378 BaseFilterImpl_AddRef
,
379 TransformFilterImpl_Release
,
380 BaseFilterImpl_GetClassID
,
381 TransformFilterImpl_Stop
,
382 TransformFilterImpl_Pause
,
383 TransformFilterImpl_Run
,
384 BaseFilterImpl_GetState
,
385 BaseFilterImpl_SetSyncSource
,
386 BaseFilterImpl_GetSyncSource
,
387 BaseFilterImpl_EnumPins
,
388 TransformFilterImpl_FindPin
,
389 BaseFilterImpl_QueryFilterInfo
,
390 BaseFilterImpl_JoinFilterGraph
,
391 BaseFilterImpl_QueryVendorInfo