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"
37 #include "wine/unicode.h"
38 #include "wine/debug.h"
40 #include "transform.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(quartz
);
44 static HRESULT
AVIDec_Cleanup(TransformFilterImpl
* pTransformFilter
);
46 typedef struct AVIDecImpl
48 TransformFilterImpl tf
;
50 BITMAPINFOHEADER
* pBihIn
;
51 BITMAPINFOHEADER
* pBihOut
;
54 static HRESULT
AVIDec_ProcessBegin(TransformFilterImpl
* pTransformFilter
)
56 AVIDecImpl
* This
= (AVIDecImpl
*)pTransformFilter
;
59 TRACE("(%p)->()\n", This
);
61 result
= ICDecompressBegin(This
->hvid
, This
->pBihIn
, This
->pBihOut
);
62 if (result
!= ICERR_OK
)
64 ERR("Cannot start processing (%d)\n", result
);
70 static HRESULT
AVIDec_ProcessSampleData(TransformFilterImpl
* pTransformFilter
, IMediaSample
*pSample
)
72 AVIDecImpl
* This
= (AVIDecImpl
*)pTransformFilter
;
76 IMediaSample
* pOutSample
= NULL
;
81 LONGLONG tStart
, tStop
;
83 hr
= IMediaSample_GetPointer(pSample
, &pbSrcStream
);
86 ERR("Cannot get pointer to sample data (%x)\n", hr
);
90 cbSrcStream
= IMediaSample_GetActualDataLength(pSample
);
92 TRACE("Sample data ptr = %p, size = %ld\n", pbSrcStream
, (long)cbSrcStream
);
94 hr
= IPin_ConnectionMediaType(This
->tf
.ppPins
[0], &amt
);
96 ERR("Unable to retrieve media type\n");
100 /* Update input size to match sample size */
101 This
->pBihIn
->biSizeImage
= cbSrcStream
;
103 hr
= OutputPin_GetDeliveryBuffer((OutputPin
*)This
->tf
.ppPins
[1], &pOutSample
, NULL
, NULL
, 0);
105 ERR("Unable to get delivery buffer (%x)\n", hr
);
109 hr
= IMediaSample_SetActualDataLength(pOutSample
, 0);
112 hr
= IMediaSample_GetPointer(pOutSample
, &pbDstStream
);
114 ERR("Unable to get pointer to buffer (%x)\n", hr
);
117 cbDstStream
= IMediaSample_GetSize(pOutSample
);
118 if (cbDstStream
< This
->pBihOut
->biSizeImage
) {
119 ERR("Sample size is too small %d < %d\n", cbDstStream
, This
->pBihOut
->biSizeImage
);
124 res
= ICDecompress(This
->hvid
, 0, This
->pBihIn
, pbSrcStream
, This
->pBihOut
, pbDstStream
);
126 ERR("Error occurred during the decompression (%x)\n", res
);
129 IMediaSample_SetPreroll(pOutSample
, (IMediaSample_IsPreroll(pSample
) == S_OK
));
130 IMediaSample_SetDiscontinuity(pOutSample
, (IMediaSample_IsDiscontinuity(pSample
) == S_OK
));
131 IMediaSample_SetSyncPoint(pOutSample
, (IMediaSample_IsSyncPoint(pSample
) == S_OK
));
133 if (IMediaSample_GetTime(pSample
, &tStart
, &tStop
) == S_OK
)
134 IMediaSample_SetTime(pOutSample
, &tStart
, &tStop
);
136 IMediaSample_SetTime(pOutSample
, NULL
, NULL
);
138 hr
= OutputPin_SendSample((OutputPin
*)This
->tf
.ppPins
[1], pOutSample
);
139 if (hr
!= S_OK
&& hr
!= VFW_E_NOT_CONNECTED
) {
140 ERR("Error sending sample (%x)\n", hr
);
146 IMediaSample_Release(pOutSample
);
151 static HRESULT
AVIDec_ProcessEnd(TransformFilterImpl
* pTransformFilter
)
153 AVIDecImpl
* This
= (AVIDecImpl
*)pTransformFilter
;
156 TRACE("(%p)->()\n", This
);
161 result
= ICDecompressEnd(This
->hvid
);
162 if (result
!= ICERR_OK
)
164 ERR("Cannot stop processing (%d)\n", result
);
170 static HRESULT
AVIDec_ConnectInput(TransformFilterImpl
* pTransformFilter
, const AM_MEDIA_TYPE
* pmt
)
172 AVIDecImpl
* This
= (AVIDecImpl
*)pTransformFilter
;
173 HRESULT hr
= VFW_E_TYPE_NOT_ACCEPTED
;
175 TRACE("(%p)->(%p)\n", This
, pmt
);
177 AVIDec_Cleanup(pTransformFilter
);
179 /* Check root (GUID w/o FOURCC) */
180 if ((IsEqualIID(&pmt
->majortype
, &MEDIATYPE_Video
)) &&
181 (!memcmp(((const char *)&pmt
->subtype
)+4, ((const char *)&MEDIATYPE_Video
)+4, sizeof(GUID
)-4)) &&
182 (IsEqualIID(&pmt
->formattype
, &FORMAT_VideoInfo
)))
184 VIDEOINFOHEADER
* format
= (VIDEOINFOHEADER
*)pmt
->pbFormat
;
186 This
->hvid
= ICLocate(pmt
->majortype
.Data1
, pmt
->subtype
.Data1
, &format
->bmiHeader
, NULL
, ICMODE_DECOMPRESS
);
189 AM_MEDIA_TYPE
* outpmt
= &((OutputPin
*)This
->tf
.ppPins
[1])->pin
.mtCurrent
;
190 const CLSID
* outsubtype
;
192 DWORD output_depth
= format
->bmiHeader
.biBitCount
;
195 switch(format
->bmiHeader
.biBitCount
)
197 case 32: outsubtype
= &MEDIASUBTYPE_RGB32
; break;
198 case 24: outsubtype
= &MEDIASUBTYPE_RGB24
; break;
199 case 16: outsubtype
= &MEDIASUBTYPE_RGB565
; break;
200 case 8: outsubtype
= &MEDIASUBTYPE_RGB8
; break;
202 TRACE("Non standard input depth %d, forced ouptut depth to 32\n", format
->bmiHeader
.biBitCount
);
203 outsubtype
= &MEDIASUBTYPE_RGB32
;
208 /* Copy bitmap header from media type to 1 for input and 1 for output */
209 bih_size
= format
->bmiHeader
.biSize
+ format
->bmiHeader
.biClrUsed
* 4;
210 This
->pBihIn
= CoTaskMemAlloc(bih_size
);
216 This
->pBihOut
= CoTaskMemAlloc(bih_size
);
222 memcpy(This
->pBihIn
, &format
->bmiHeader
, bih_size
);
223 memcpy(This
->pBihOut
, &format
->bmiHeader
, bih_size
);
225 /* Update output format as non compressed bitmap */
226 This
->pBihOut
->biCompression
= 0;
227 This
->pBihOut
->biBitCount
= output_depth
;
228 This
->pBihOut
->biSizeImage
= This
->pBihOut
->biWidth
* This
->pBihOut
->biHeight
* This
->pBihOut
->biBitCount
/ 8;
230 result
= ICDecompressQuery(This
->hvid
, This
->pBihIn
, This
->pBihOut
);
231 if (result
!= ICERR_OK
)
233 TRACE("Unable to found a suitable output format (%d)\n", result
);
237 /* Update output media type */
238 CopyMediaType(outpmt
, pmt
);
239 outpmt
->subtype
= *outsubtype
;
240 memcpy(&(((VIDEOINFOHEADER
*)outpmt
->pbFormat
)->bmiHeader
), This
->pBihOut
, This
->pBihOut
->biSize
);
242 /* Update buffer size of media samples in output */
243 ((OutputPin
*)This
->tf
.ppPins
[1])->allocProps
.cbBuffer
= This
->pBihOut
->biSizeImage
;
245 TRACE("Connection accepted\n");
248 TRACE("Unable to find a suitable VFW decompressor\n");
252 AVIDec_Cleanup(pTransformFilter
);
254 TRACE("Connection refused\n");
258 static HRESULT
AVIDec_Cleanup(TransformFilterImpl
* pTransformFilter
)
260 AVIDecImpl
* This
= (AVIDecImpl
*)pTransformFilter
;
262 TRACE("(%p)->()\n", This
);
267 CoTaskMemFree(This
->pBihIn
);
269 CoTaskMemFree(This
->pBihOut
);
273 This
->pBihOut
= NULL
;
278 static const TransformFuncsTable AVIDec_FuncsTable
= {
280 AVIDec_ProcessSampleData
,
287 HRESULT
AVIDec_create(IUnknown
* pUnkOuter
, LPVOID
* ppv
)
292 TRACE("(%p, %p)\n", pUnkOuter
, ppv
);
297 return CLASS_E_NOAGGREGATION
;
299 /* Note: This memory is managed by the transform filter once created */
300 This
= CoTaskMemAlloc(sizeof(AVIDecImpl
));
304 This
->pBihOut
= NULL
;
306 hr
= TransformFilter_Create(&(This
->tf
), &CLSID_AVIDec
, &AVIDec_FuncsTable
, NULL
, NULL
, NULL
);