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 #include "transform.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(quartz
);
45 static HRESULT
AVIDec_Cleanup(TransformFilterImpl
* pTransformFilter
);
47 typedef struct AVIDecImpl
49 TransformFilterImpl tf
;
51 BITMAPINFOHEADER
* pBihIn
;
52 BITMAPINFOHEADER
* pBihOut
;
55 static HRESULT
AVIDec_ProcessBegin(TransformFilterImpl
* 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
AVIDec_ProcessSampleData(TransformFilterImpl
* pTransformFilter
, IMediaSample
*pSample
)
73 AVIDecImpl
* This
= (AVIDecImpl
*)pTransformFilter
;
74 VIDEOINFOHEADER
* format
;
78 IMediaSample
* pOutSample
= NULL
;
84 hr
= IMediaSample_GetPointer(pSample
, &pbSrcStream
);
87 ERR("Cannot get pointer to sample data (%x)\n", hr
);
91 cbSrcStream
= IMediaSample_GetActualDataLength(pSample
);
93 TRACE("Sample data ptr = %p, size = %ld\n", pbSrcStream
, (long)cbSrcStream
);
95 hr
= IPin_ConnectionMediaType(This
->tf
.ppPins
[0], &amt
);
97 ERR("Unable to retrieve media type\n");
100 format
= (VIDEOINFOHEADER
*)amt
.pbFormat
;
102 /* Update input size to match sample size */
103 This
->pBihIn
->biSizeImage
= cbSrcStream
;
105 hr
= OutputPin_GetDeliveryBuffer((OutputPin
*)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 hr
= OutputPin_SendSample((OutputPin
*)This
->tf
.ppPins
[1], pOutSample
);
131 if (hr
!= S_OK
&& hr
!= VFW_E_NOT_CONNECTED
) {
132 ERR("Error sending sample (%x)\n", hr
);
138 IMediaSample_Release(pOutSample
);
143 static HRESULT
AVIDec_ProcessEnd(TransformFilterImpl
* pTransformFilter
)
145 AVIDecImpl
* This
= (AVIDecImpl
*)pTransformFilter
;
148 TRACE("(%p)->()\n", This
);
150 result
= ICDecompressEnd(This
->hvid
);
151 if (result
!= ICERR_OK
)
153 ERR("Cannot stop processing (%d)\n", result
);
159 static HRESULT
AVIDec_ConnectInput(TransformFilterImpl
* pTransformFilter
, const AM_MEDIA_TYPE
* pmt
)
161 AVIDecImpl
* This
= (AVIDecImpl
*)pTransformFilter
;
162 HRESULT hr
= S_FALSE
;
164 TRACE("(%p)->(%p)\n", This
, pmt
);
166 AVIDec_Cleanup(pTransformFilter
);
168 /* Check root (GUID w/o FOURCC) */
169 if ((IsEqualIID(&pmt
->majortype
, &MEDIATYPE_Video
)) &&
170 (!memcmp(((const char *)&pmt
->subtype
)+4, ((const char *)&MEDIATYPE_Video
)+4, sizeof(GUID
)-4)) &&
171 (IsEqualIID(&pmt
->formattype
, &FORMAT_VideoInfo
)))
173 VIDEOINFOHEADER
* format
= (VIDEOINFOHEADER
*)pmt
->pbFormat
;
175 This
->hvid
= ICLocate(pmt
->majortype
.Data1
, pmt
->subtype
.Data1
, &format
->bmiHeader
, NULL
, ICMODE_DECOMPRESS
);
178 AM_MEDIA_TYPE
* outpmt
= &((OutputPin
*)This
->tf
.ppPins
[1])->pin
.mtCurrent
;
179 const CLSID
* outsubtype
;
181 DWORD output_depth
= format
->bmiHeader
.biBitCount
;
184 switch(format
->bmiHeader
.biBitCount
)
186 case 32: outsubtype
= &MEDIASUBTYPE_RGB32
; break;
187 case 24: outsubtype
= &MEDIASUBTYPE_RGB24
; break;
188 case 16: outsubtype
= &MEDIASUBTYPE_RGB565
; break;
189 case 8: outsubtype
= &MEDIASUBTYPE_RGB8
; break;
191 TRACE("Non standard input depth %d, forced ouptut depth to 32\n", format
->bmiHeader
.biBitCount
);
192 outsubtype
= &MEDIASUBTYPE_RGB32
;
197 /* Copy bitmap header from media type to 1 for input and 1 for output */
198 bih_size
= format
->bmiHeader
.biSize
+ format
->bmiHeader
.biClrUsed
* 4;
199 This
->pBihIn
= (BITMAPINFOHEADER
*)CoTaskMemAlloc(bih_size
);
205 This
->pBihOut
= (BITMAPINFOHEADER
*)CoTaskMemAlloc(bih_size
);
211 memcpy(This
->pBihIn
, &format
->bmiHeader
, bih_size
);
212 memcpy(This
->pBihOut
, &format
->bmiHeader
, bih_size
);
214 /* Update output format as non compressed bitmap */
215 This
->pBihOut
->biCompression
= 0;
216 This
->pBihOut
->biBitCount
= output_depth
;
217 This
->pBihOut
->biSizeImage
= This
->pBihOut
->biWidth
* This
->pBihOut
->biHeight
* This
->pBihOut
->biBitCount
/ 8;
219 result
= ICDecompressQuery(This
->hvid
, This
->pBihIn
, This
->pBihOut
);
220 if (result
!= ICERR_OK
)
222 TRACE("Unable to found a suitable output format (%d)\n", result
);
226 /* Update output media type */
227 CopyMediaType(outpmt
, pmt
);
228 outpmt
->subtype
= *outsubtype
;
229 memcpy(&(((VIDEOINFOHEADER
*)outpmt
->pbFormat
)->bmiHeader
), This
->pBihOut
, This
->pBihOut
->biSize
);
231 /* Update buffer size of media samples in output */
232 ((OutputPin
*)This
->tf
.ppPins
[1])->allocProps
.cbBuffer
= This
->pBihOut
->biSizeImage
;
234 TRACE("Connection accepted\n");
237 TRACE("Unable to find a suitable VFW decompressor\n");
241 AVIDec_Cleanup(pTransformFilter
);
243 TRACE("Connection refused\n");
247 static HRESULT
AVIDec_Cleanup(TransformFilterImpl
* pTransformFilter
)
249 AVIDecImpl
* This
= (AVIDecImpl
*)pTransformFilter
;
251 TRACE("(%p)->()\n", This
);
256 CoTaskMemFree(This
->pBihIn
);
258 CoTaskMemFree(This
->pBihOut
);
262 This
->pBihOut
= NULL
;
267 static const TransformFuncsTable AVIDec_FuncsTable
= {
269 AVIDec_ProcessSampleData
,
276 HRESULT
AVIDec_create(IUnknown
* pUnkOuter
, LPVOID
* ppv
)
281 TRACE("(%p, %p)\n", pUnkOuter
, ppv
);
286 return CLASS_E_NOAGGREGATION
;
288 /* Note: This memory is managed by the transform filter once created */
289 This
= CoTaskMemAlloc(sizeof(AVIDecImpl
));
293 This
->pBihOut
= NULL
;
295 hr
= TransformFilter_Create(&(This
->tf
), &CLSID_AVIDec
, &AVIDec_FuncsTable
);