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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 typedef struct AVIDecImpl
51 TransformFilterImpl tf;
53 BITMAPINFOHEADER* pBihIn;
54 BITMAPINFOHEADER* pBihOut;
57 static DWORD AVIDec_SendSampleData(TransformFilterImpl* pTransformFilter, LPBYTE data, DWORD size)
59 AVIDecImpl* This = (AVIDecImpl*)pTransformFilter;
60 VIDEOINFOHEADER* format;
64 IMediaSample* pSample = NULL;
68 TRACE("(%p)->(%p,%ld)\n", This, data, size);
70 hr = IPin_ConnectionMediaType(This->tf.ppPins[0], &amt);
72 ERR("Unable to retrieve media type\n");
75 format = (VIDEOINFOHEADER*)amt.pbFormat;
77 /* Update input size to match sample size */
78 This->pBihIn->biSizeImage = size;
80 hr = OutputPin_GetDeliveryBuffer((OutputPin*)This->tf.ppPins[1], &pSample, NULL, NULL, 0);
82 ERR("Unable to get delivery buffer (%lx)\n", hr);
86 hr = IMediaSample_SetActualDataLength(pSample, 0);
89 hr = IMediaSample_GetPointer(pSample, &pbDstStream);
91 ERR("Unable to get pointer to buffer (%lx)\n", hr);
94 cbDstStream = IMediaSample_GetSize(pSample);
95 if (cbDstStream < This->pBihOut->biSizeImage) {
96 ERR("Sample size is too small %ld < %ld\n", cbDstStream, This->pBihOut->biSizeImage);
101 res = ICDecompress(This->hvid, 0, This->pBihIn, data, This->pBihOut, pbDstStream);
103 ERR("Error occurred during the decompression (%lx)\n", res);
105 hr = OutputPin_SendSample((OutputPin*)This->tf.ppPins[1], pSample);
106 if (hr != S_OK && hr != VFW_E_NOT_CONNECTED) {
107 ERR("Error sending sample (%lx)\n", hr);
113 IMediaSample_Release(pSample);
118 static HRESULT AVIDec_ConnectInput(TransformFilterImpl* pTransformFilter, const AM_MEDIA_TYPE * pmt)
120 AVIDecImpl* This = (AVIDecImpl*)pTransformFilter;
122 TRACE("(%p)->(%p)\n", This, pmt);
124 if ((IsEqualIID(&pmt->majortype, &MEDIATYPE_Video)) &&
125 (!memcmp(((char*)&pmt->subtype)+4, ((char*)&MEDIATYPE_Video)+4, sizeof(GUID)-4)) && /* Check root (GUID w/o FOURCC) */
126 (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo)))
129 VIDEOINFOHEADER* format = (VIDEOINFOHEADER*)pmt->pbFormat;
131 drv = ICLocate(pmt->majortype.Data1, pmt->subtype.Data1, &format->bmiHeader, NULL, ICMODE_DECOMPRESS);
134 AM_MEDIA_TYPE* outpmt = &((OutputPin*)This->tf.ppPins[1])->pin.mtCurrent;
135 const CLSID* outsubtype;
138 switch(format->bmiHeader.biBitCount)
140 case 32: outsubtype = &MEDIASUBTYPE_RGB32; break;
141 case 24: outsubtype = &MEDIASUBTYPE_RGB24; break;
142 case 16: outsubtype = &MEDIASUBTYPE_RGB565; break;
143 case 8: outsubtype = &MEDIASUBTYPE_RGB8; break;
145 FIXME("Depth %d not supported\n", format->bmiHeader.biBitCount);
149 CopyMediaType(outpmt, pmt);
150 outpmt->subtype = *outsubtype;
153 /* Copy bitmap header from media type to 1 for input and 1 for output */
155 CoTaskMemFree(This->pBihIn);
156 CoTaskMemFree(This->pBihOut);
158 bih_size = format->bmiHeader.biSize + format->bmiHeader.biClrUsed * 4;
159 This->pBihIn = (BITMAPINFOHEADER*)CoTaskMemAlloc(bih_size);
163 return E_OUTOFMEMORY;
165 This->pBihOut = (BITMAPINFOHEADER*)CoTaskMemAlloc(bih_size);
168 CoTaskMemFree(This->pBihIn);
171 return E_OUTOFMEMORY;
173 memcpy(This->pBihIn, &format->bmiHeader, bih_size);
174 memcpy(This->pBihOut, &format->bmiHeader, bih_size);
176 /* Update output format as non compressed bitmap */
177 This->pBihOut->biCompression = 0;
178 This->pBihOut->biSizeImage = This->pBihOut->biWidth * This->pBihOut->biHeight * This->pBihOut->biBitCount / 8;
180 /* Update buffer size of media samples in output */
181 ((OutputPin*)This->tf.ppPins[1])->allocProps.cbBuffer = This->pBihOut->biSizeImage;
183 TRACE("Connection accepted\n");
186 TRACE("Unable to find a suitable VFW decompressor\n");
189 TRACE("Connection refused\n");
193 static HRESULT AVIDec_Cleanup(TransformFilterImpl* pTransformFilter)
195 AVIDecImpl* This = (AVIDecImpl*)pTransformFilter;
197 TRACE("(%p)->()\n", This);
203 CoTaskMemFree(This->pBihIn);
204 CoTaskMemFree(This->pBihOut);
213 HRESULT AVIDec_create(IUnknown * pUnkOuter, LPVOID * ppv)
218 TRACE("(%p, %p)\n", pUnkOuter, ppv);
223 return CLASS_E_NOAGGREGATION;
225 /* Note: This memory is managed by the transform filter once created */
226 This = CoTaskMemAlloc(sizeof(AVIDecImpl));
231 hr = TransformFilter_Create(&(This->tf), &CLSID_AVIDec, AVIDec_SendSampleData, AVIDec_ConnectInput, AVIDec_Cleanup);