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"
24 #include "control_private.h"
42 #include "wine/unicode.h"
43 #include "wine/debug.h"
45 #include "transform.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(quartz
);
49 static HRESULT
AVIDec_Cleanup(TransformFilterImpl
* pTransformFilter
);
51 typedef struct AVIDecImpl
53 TransformFilterImpl tf
;
55 BITMAPINFOHEADER
* pBihIn
;
56 BITMAPINFOHEADER
* pBihOut
;
59 static HRESULT
AVIDec_ProcessBegin(TransformFilterImpl
* pTransformFilter
)
61 AVIDecImpl
* This
= (AVIDecImpl
*)pTransformFilter
;
64 TRACE("(%p)->()\n", This
);
66 result
= ICDecompressBegin(This
->hvid
, This
->pBihIn
, This
->pBihOut
);
67 if (result
!= ICERR_OK
)
69 ERR("Cannot start processing (%d)\n", result
);
75 static HRESULT
AVIDec_ProcessSampleData(TransformFilterImpl
* pTransformFilter
, LPBYTE data
, DWORD size
)
77 AVIDecImpl
* This
= (AVIDecImpl
*)pTransformFilter
;
78 VIDEOINFOHEADER
* format
;
82 IMediaSample
* pSample
= NULL
;
86 TRACE("(%p)->(%p,%d)\n", This
, data
, size
);
88 hr
= IPin_ConnectionMediaType(This
->tf
.ppPins
[0], &amt
);
90 ERR("Unable to retrieve media type\n");
93 format
= (VIDEOINFOHEADER
*)amt
.pbFormat
;
95 /* Update input size to match sample size */
96 This
->pBihIn
->biSizeImage
= size
;
98 hr
= OutputPin_GetDeliveryBuffer((OutputPin
*)This
->tf
.ppPins
[1], &pSample
, NULL
, NULL
, 0);
100 ERR("Unable to get delivery buffer (%x)\n", hr
);
104 hr
= IMediaSample_SetActualDataLength(pSample
, 0);
107 hr
= IMediaSample_GetPointer(pSample
, &pbDstStream
);
109 ERR("Unable to get pointer to buffer (%x)\n", hr
);
112 cbDstStream
= IMediaSample_GetSize(pSample
);
113 if (cbDstStream
< This
->pBihOut
->biSizeImage
) {
114 ERR("Sample size is too small %d < %d\n", cbDstStream
, This
->pBihOut
->biSizeImage
);
119 res
= ICDecompress(This
->hvid
, 0, This
->pBihIn
, data
, This
->pBihOut
, pbDstStream
);
121 ERR("Error occurred during the decompression (%x)\n", res
);
123 hr
= OutputPin_SendSample((OutputPin
*)This
->tf
.ppPins
[1], pSample
);
124 if (hr
!= S_OK
&& hr
!= VFW_E_NOT_CONNECTED
) {
125 ERR("Error sending sample (%x)\n", hr
);
131 IMediaSample_Release(pSample
);
136 static HRESULT
AVIDec_ProcessEnd(TransformFilterImpl
* pTransformFilter
)
138 AVIDecImpl
* This
= (AVIDecImpl
*)pTransformFilter
;
141 TRACE("(%p)->()\n", This
);
143 result
= ICDecompressEnd(This
->hvid
);
144 if (result
!= ICERR_OK
)
146 ERR("Cannot stop processing (%d)\n", result
);
152 static HRESULT
AVIDec_ConnectInput(TransformFilterImpl
* pTransformFilter
, const AM_MEDIA_TYPE
* pmt
)
154 AVIDecImpl
* This
= (AVIDecImpl
*)pTransformFilter
;
155 HRESULT hr
= S_FALSE
;
157 TRACE("(%p)->(%p)\n", This
, pmt
);
159 AVIDec_Cleanup(pTransformFilter
);
161 /* Check root (GUID w/o FOURCC) */
162 if ((IsEqualIID(&pmt
->majortype
, &MEDIATYPE_Video
)) &&
163 (!memcmp(((const char *)&pmt
->subtype
)+4, ((const char *)&MEDIATYPE_Video
)+4, sizeof(GUID
)-4)) &&
164 (IsEqualIID(&pmt
->formattype
, &FORMAT_VideoInfo
)))
166 VIDEOINFOHEADER
* format
= (VIDEOINFOHEADER
*)pmt
->pbFormat
;
168 This
->hvid
= ICLocate(pmt
->majortype
.Data1
, pmt
->subtype
.Data1
, &format
->bmiHeader
, NULL
, ICMODE_DECOMPRESS
);
171 AM_MEDIA_TYPE
* outpmt
= &((OutputPin
*)This
->tf
.ppPins
[1])->pin
.mtCurrent
;
172 const CLSID
* outsubtype
;
174 DWORD output_depth
= format
->bmiHeader
.biBitCount
;
177 switch(format
->bmiHeader
.biBitCount
)
179 case 32: outsubtype
= &MEDIASUBTYPE_RGB32
; break;
180 case 24: outsubtype
= &MEDIASUBTYPE_RGB24
; break;
181 case 16: outsubtype
= &MEDIASUBTYPE_RGB565
; break;
182 case 8: outsubtype
= &MEDIASUBTYPE_RGB8
; break;
184 TRACE("Non standard input depth %d, forced ouptut depth to 32\n", format
->bmiHeader
.biBitCount
);
185 outsubtype
= &MEDIASUBTYPE_RGB32
;
190 /* Copy bitmap header from media type to 1 for input and 1 for output */
191 bih_size
= format
->bmiHeader
.biSize
+ format
->bmiHeader
.biClrUsed
* 4;
192 This
->pBihIn
= (BITMAPINFOHEADER
*)CoTaskMemAlloc(bih_size
);
198 This
->pBihOut
= (BITMAPINFOHEADER
*)CoTaskMemAlloc(bih_size
);
204 memcpy(This
->pBihIn
, &format
->bmiHeader
, bih_size
);
205 memcpy(This
->pBihOut
, &format
->bmiHeader
, bih_size
);
207 /* Update output format as non compressed bitmap */
208 This
->pBihOut
->biCompression
= 0;
209 This
->pBihOut
->biBitCount
= output_depth
;
210 This
->pBihOut
->biSizeImage
= This
->pBihOut
->biWidth
* This
->pBihOut
->biHeight
* This
->pBihOut
->biBitCount
/ 8;
212 result
= ICDecompressQuery(This
->hvid
, This
->pBihIn
, This
->pBihOut
);
213 if (result
!= ICERR_OK
)
215 TRACE("Unable to found a suitable output format (%d)\n", result
);
219 /* Update output media type */
220 CopyMediaType(outpmt
, pmt
);
221 outpmt
->subtype
= *outsubtype
;
222 memcpy(&(((VIDEOINFOHEADER
*)outpmt
->pbFormat
)->bmiHeader
), This
->pBihOut
, This
->pBihOut
->biSize
);
224 /* Update buffer size of media samples in output */
225 ((OutputPin
*)This
->tf
.ppPins
[1])->allocProps
.cbBuffer
= This
->pBihOut
->biSizeImage
;
227 TRACE("Connection accepted\n");
230 TRACE("Unable to find a suitable VFW decompressor\n");
234 AVIDec_Cleanup(pTransformFilter
);
236 TRACE("Connection refused\n");
240 static HRESULT
AVIDec_Cleanup(TransformFilterImpl
* pTransformFilter
)
242 AVIDecImpl
* This
= (AVIDecImpl
*)pTransformFilter
;
244 TRACE("(%p)->()\n", This
);
249 CoTaskMemFree(This
->pBihIn
);
251 CoTaskMemFree(This
->pBihOut
);
255 This
->pBihOut
= NULL
;
260 static const TransformFuncsTable AVIDec_FuncsTable
= {
262 AVIDec_ProcessSampleData
,
268 HRESULT
AVIDec_create(IUnknown
* pUnkOuter
, LPVOID
* ppv
)
273 TRACE("(%p, %p)\n", pUnkOuter
, ppv
);
278 return CLASS_E_NOAGGREGATION
;
280 /* Note: This memory is managed by the transform filter once created */
281 This
= CoTaskMemAlloc(sizeof(AVIDecImpl
));
285 This
->pBihOut
= NULL
;
287 hr
= TransformFilter_Create(&(This
->tf
), &CLSID_AVIDec
, &AVIDec_FuncsTable
);