2004-08-24 04:28:35 +02:00
|
|
|
/*
|
|
|
|
* AVI Decompressor (VFW decompressors wrapper)
|
|
|
|
*
|
2005-01-31 17:24:00 +01:00
|
|
|
* Copyright 2004-2005 Christian Costa
|
2004-08-24 04:28:35 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-08-24 04:28:35 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "quartz_private.h"
|
|
|
|
#include "pin.h"
|
|
|
|
|
|
|
|
#include "uuids.h"
|
|
|
|
#include "vfwmsgs.h"
|
|
|
|
#include "amvideo.h"
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "dshow.h"
|
|
|
|
#include "strmif.h"
|
|
|
|
#include "vfwmsgs.h"
|
|
|
|
#include "vfw.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2005-01-31 17:24:00 +01:00
|
|
|
#include "transform.h"
|
2004-08-24 04:28:35 +02:00
|
|
|
|
2005-01-31 17:24:00 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(quartz);
|
2004-08-24 04:28:35 +02:00
|
|
|
|
2005-02-21 21:37:45 +01:00
|
|
|
static HRESULT AVIDec_Cleanup(TransformFilterImpl* pTransformFilter);
|
|
|
|
|
2004-08-24 04:28:35 +02:00
|
|
|
typedef struct AVIDecImpl
|
|
|
|
{
|
2005-01-31 17:24:00 +01:00
|
|
|
TransformFilterImpl tf;
|
2004-08-24 04:28:35 +02:00
|
|
|
HIC hvid;
|
2004-11-29 18:50:23 +01:00
|
|
|
BITMAPINFOHEADER* pBihIn;
|
|
|
|
BITMAPINFOHEADER* pBihOut;
|
2004-08-24 04:28:35 +02:00
|
|
|
} AVIDecImpl;
|
|
|
|
|
2005-02-21 21:37:45 +01:00
|
|
|
static HRESULT AVIDec_ProcessBegin(TransformFilterImpl* pTransformFilter)
|
|
|
|
{
|
|
|
|
AVIDecImpl* This = (AVIDecImpl*)pTransformFilter;
|
|
|
|
DWORD result;
|
|
|
|
|
|
|
|
TRACE("(%p)->()\n", This);
|
|
|
|
|
|
|
|
result = ICDecompressBegin(This->hvid, This->pBihIn, This->pBihOut);
|
|
|
|
if (result != ICERR_OK)
|
|
|
|
{
|
2006-10-12 20:57:23 +02:00
|
|
|
ERR("Cannot start processing (%d)\n", result);
|
2005-02-21 21:37:45 +01:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2007-04-07 11:32:45 +02:00
|
|
|
static HRESULT AVIDec_ProcessSampleData(TransformFilterImpl* pTransformFilter, IMediaSample *pSample)
|
2004-08-24 04:28:35 +02:00
|
|
|
{
|
2005-02-01 15:22:00 +01:00
|
|
|
AVIDecImpl* This = (AVIDecImpl*)pTransformFilter;
|
2004-08-24 04:28:35 +02:00
|
|
|
VIDEOINFOHEADER* format;
|
|
|
|
AM_MEDIA_TYPE amt;
|
|
|
|
HRESULT hr;
|
|
|
|
DWORD res;
|
2007-04-07 11:32:45 +02:00
|
|
|
IMediaSample* pOutSample = NULL;
|
2004-08-24 04:28:35 +02:00
|
|
|
DWORD cbDstStream;
|
|
|
|
LPBYTE pbDstStream;
|
2007-04-07 11:32:45 +02:00
|
|
|
DWORD cbSrcStream;
|
|
|
|
LPBYTE pbSrcStream;
|
|
|
|
|
|
|
|
hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("Cannot get pointer to sample data (%x)\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
cbSrcStream = IMediaSample_GetActualDataLength(pSample);
|
|
|
|
|
|
|
|
TRACE("Sample data ptr = %p, size = %ld\n", pbSrcStream, (long)cbSrcStream);
|
2004-08-24 04:28:35 +02:00
|
|
|
|
2005-01-31 17:24:00 +01:00
|
|
|
hr = IPin_ConnectionMediaType(This->tf.ppPins[0], &amt);
|
2004-08-24 04:28:35 +02:00
|
|
|
if (FAILED(hr)) {
|
2004-08-26 02:31:20 +02:00
|
|
|
ERR("Unable to retrieve media type\n");
|
2004-08-24 04:28:35 +02:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
format = (VIDEOINFOHEADER*)amt.pbFormat;
|
|
|
|
|
2004-11-29 18:50:23 +01:00
|
|
|
/* Update input size to match sample size */
|
2007-04-07 11:32:45 +02:00
|
|
|
This->pBihIn->biSizeImage = cbSrcStream;
|
2004-08-24 04:28:35 +02:00
|
|
|
|
2007-04-07 11:32:45 +02:00
|
|
|
hr = OutputPin_GetDeliveryBuffer((OutputPin*)This->tf.ppPins[1], &pOutSample, NULL, NULL, 0);
|
2004-08-24 04:28:35 +02:00
|
|
|
if (FAILED(hr)) {
|
2006-10-12 20:57:23 +02:00
|
|
|
ERR("Unable to get delivery buffer (%x)\n", hr);
|
2004-08-24 04:28:35 +02:00
|
|
|
goto error;
|
|
|
|
}
|
2005-01-31 17:24:00 +01:00
|
|
|
|
2007-04-07 11:32:45 +02:00
|
|
|
hr = IMediaSample_SetActualDataLength(pOutSample, 0);
|
2004-08-24 04:28:35 +02:00
|
|
|
assert(hr == S_OK);
|
|
|
|
|
2007-04-07 11:32:45 +02:00
|
|
|
hr = IMediaSample_GetPointer(pOutSample, &pbDstStream);
|
2004-08-24 04:28:35 +02:00
|
|
|
if (FAILED(hr)) {
|
2006-10-12 20:57:23 +02:00
|
|
|
ERR("Unable to get pointer to buffer (%x)\n", hr);
|
2004-08-24 04:28:35 +02:00
|
|
|
goto error;
|
|
|
|
}
|
2007-04-07 11:32:45 +02:00
|
|
|
cbDstStream = IMediaSample_GetSize(pOutSample);
|
2004-11-29 18:50:23 +01:00
|
|
|
if (cbDstStream < This->pBihOut->biSizeImage) {
|
2006-10-12 20:57:23 +02:00
|
|
|
ERR("Sample size is too small %d < %d\n", cbDstStream, This->pBihOut->biSizeImage);
|
2004-08-24 04:28:35 +02:00
|
|
|
hr = E_FAIL;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2007-04-07 11:32:45 +02:00
|
|
|
res = ICDecompress(This->hvid, 0, This->pBihIn, pbSrcStream, This->pBihOut, pbDstStream);
|
2004-08-24 04:28:35 +02:00
|
|
|
if (res != ICERR_OK)
|
2006-10-12 20:57:23 +02:00
|
|
|
ERR("Error occurred during the decompression (%x)\n", res);
|
2004-11-29 18:50:23 +01:00
|
|
|
|
2007-04-07 11:32:45 +02:00
|
|
|
hr = OutputPin_SendSample((OutputPin*)This->tf.ppPins[1], pOutSample);
|
2004-08-24 04:28:35 +02:00
|
|
|
if (hr != S_OK && hr != VFW_E_NOT_CONNECTED) {
|
2006-10-12 20:57:23 +02:00
|
|
|
ERR("Error sending sample (%x)\n", hr);
|
2004-08-24 04:28:35 +02:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
error:
|
2007-04-07 11:32:45 +02:00
|
|
|
if (pOutSample)
|
|
|
|
IMediaSample_Release(pOutSample);
|
2004-08-24 04:28:35 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2005-02-21 21:37:45 +01:00
|
|
|
static HRESULT AVIDec_ProcessEnd(TransformFilterImpl* pTransformFilter)
|
|
|
|
{
|
|
|
|
AVIDecImpl* This = (AVIDecImpl*)pTransformFilter;
|
|
|
|
DWORD result;
|
|
|
|
|
|
|
|
TRACE("(%p)->()\n", This);
|
|
|
|
|
|
|
|
result = ICDecompressEnd(This->hvid);
|
|
|
|
if (result != ICERR_OK)
|
|
|
|
{
|
2006-10-12 20:57:23 +02:00
|
|
|
ERR("Cannot stop processing (%d)\n", result);
|
2005-02-21 21:37:45 +01:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2005-02-01 15:22:00 +01:00
|
|
|
static HRESULT AVIDec_ConnectInput(TransformFilterImpl* pTransformFilter, const AM_MEDIA_TYPE * pmt)
|
2004-08-24 04:28:35 +02:00
|
|
|
{
|
2005-02-01 15:22:00 +01:00
|
|
|
AVIDecImpl* This = (AVIDecImpl*)pTransformFilter;
|
2007-06-05 05:11:25 +02:00
|
|
|
HRESULT hr = VFW_E_TYPE_NOT_ACCEPTED;
|
2005-02-01 15:22:00 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, pmt);
|
2004-08-24 04:28:35 +02:00
|
|
|
|
2005-02-21 21:37:45 +01:00
|
|
|
AVIDec_Cleanup(pTransformFilter);
|
2006-09-22 19:50:12 +02:00
|
|
|
|
|
|
|
/* Check root (GUID w/o FOURCC) */
|
2004-08-24 04:28:35 +02:00
|
|
|
if ((IsEqualIID(&pmt->majortype, &MEDIATYPE_Video)) &&
|
2006-09-22 19:50:12 +02:00
|
|
|
(!memcmp(((const char *)&pmt->subtype)+4, ((const char *)&MEDIATYPE_Video)+4, sizeof(GUID)-4)) &&
|
2004-11-29 18:50:23 +01:00
|
|
|
(IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo)))
|
2004-08-24 04:28:35 +02:00
|
|
|
{
|
|
|
|
VIDEOINFOHEADER* format = (VIDEOINFOHEADER*)pmt->pbFormat;
|
2005-01-31 17:24:00 +01:00
|
|
|
|
2005-02-21 21:37:45 +01:00
|
|
|
This->hvid = ICLocate(pmt->majortype.Data1, pmt->subtype.Data1, &format->bmiHeader, NULL, ICMODE_DECOMPRESS);
|
|
|
|
if (This->hvid)
|
2004-11-29 18:50:23 +01:00
|
|
|
{
|
2005-02-01 15:22:00 +01:00
|
|
|
AM_MEDIA_TYPE* outpmt = &((OutputPin*)This->tf.ppPins[1])->pin.mtCurrent;
|
2004-11-29 18:50:23 +01:00
|
|
|
const CLSID* outsubtype;
|
|
|
|
DWORD bih_size;
|
2005-02-21 21:37:45 +01:00
|
|
|
DWORD output_depth = format->bmiHeader.biBitCount;
|
|
|
|
DWORD result;
|
2004-11-29 18:50:23 +01:00
|
|
|
|
|
|
|
switch(format->bmiHeader.biBitCount)
|
2004-08-24 04:28:35 +02:00
|
|
|
{
|
2004-11-29 18:50:23 +01:00
|
|
|
case 32: outsubtype = &MEDIASUBTYPE_RGB32; break;
|
2004-08-24 04:28:35 +02:00
|
|
|
case 24: outsubtype = &MEDIASUBTYPE_RGB24; break;
|
|
|
|
case 16: outsubtype = &MEDIASUBTYPE_RGB565; break;
|
|
|
|
case 8: outsubtype = &MEDIASUBTYPE_RGB8; break;
|
|
|
|
default:
|
2005-02-21 21:37:45 +01:00
|
|
|
TRACE("Non standard input depth %d, forced ouptut depth to 32\n", format->bmiHeader.biBitCount);
|
|
|
|
outsubtype = &MEDIASUBTYPE_RGB32;
|
|
|
|
output_depth = 32;
|
|
|
|
break;
|
2004-08-24 04:28:35 +02:00
|
|
|
}
|
2004-11-29 18:50:23 +01:00
|
|
|
|
|
|
|
/* Copy bitmap header from media type to 1 for input and 1 for output */
|
|
|
|
bih_size = format->bmiHeader.biSize + format->bmiHeader.biClrUsed * 4;
|
2005-02-01 15:22:00 +01:00
|
|
|
This->pBihIn = (BITMAPINFOHEADER*)CoTaskMemAlloc(bih_size);
|
|
|
|
if (!This->pBihIn)
|
2004-11-29 18:50:23 +01:00
|
|
|
{
|
2005-02-21 21:37:45 +01:00
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto failed;
|
2004-11-29 18:50:23 +01:00
|
|
|
}
|
2005-02-01 15:22:00 +01:00
|
|
|
This->pBihOut = (BITMAPINFOHEADER*)CoTaskMemAlloc(bih_size);
|
|
|
|
if (!This->pBihOut)
|
2004-11-29 18:50:23 +01:00
|
|
|
{
|
2005-02-21 21:37:45 +01:00
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto failed;
|
2004-11-29 18:50:23 +01:00
|
|
|
}
|
2005-02-01 15:22:00 +01:00
|
|
|
memcpy(This->pBihIn, &format->bmiHeader, bih_size);
|
|
|
|
memcpy(This->pBihOut, &format->bmiHeader, bih_size);
|
2004-11-29 18:50:23 +01:00
|
|
|
|
|
|
|
/* Update output format as non compressed bitmap */
|
2005-02-01 15:22:00 +01:00
|
|
|
This->pBihOut->biCompression = 0;
|
2005-02-21 21:37:45 +01:00
|
|
|
This->pBihOut->biBitCount = output_depth;
|
2005-02-01 15:22:00 +01:00
|
|
|
This->pBihOut->biSizeImage = This->pBihOut->biWidth * This->pBihOut->biHeight * This->pBihOut->biBitCount / 8;
|
2004-11-29 18:50:23 +01:00
|
|
|
|
2005-02-21 21:37:45 +01:00
|
|
|
result = ICDecompressQuery(This->hvid, This->pBihIn, This->pBihOut);
|
|
|
|
if (result != ICERR_OK)
|
|
|
|
{
|
2006-10-12 20:57:23 +02:00
|
|
|
TRACE("Unable to found a suitable output format (%d)\n", result);
|
2005-02-21 21:37:45 +01:00
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update output media type */
|
|
|
|
CopyMediaType(outpmt, pmt);
|
|
|
|
outpmt->subtype = *outsubtype;
|
2005-06-07 22:29:23 +02:00
|
|
|
memcpy(&(((VIDEOINFOHEADER*)outpmt->pbFormat)->bmiHeader), This->pBihOut, This->pBihOut->biSize);
|
2005-02-21 21:37:45 +01:00
|
|
|
|
2005-01-03 21:23:14 +01:00
|
|
|
/* Update buffer size of media samples in output */
|
2005-02-01 15:22:00 +01:00
|
|
|
((OutputPin*)This->tf.ppPins[1])->allocProps.cbBuffer = This->pBihOut->biSizeImage;
|
2005-01-31 17:24:00 +01:00
|
|
|
|
2004-11-29 18:50:23 +01:00
|
|
|
TRACE("Connection accepted\n");
|
2004-08-24 04:28:35 +02:00
|
|
|
return S_OK;
|
2004-11-29 18:50:23 +01:00
|
|
|
}
|
2004-08-24 04:28:35 +02:00
|
|
|
TRACE("Unable to find a suitable VFW decompressor\n");
|
|
|
|
}
|
|
|
|
|
2005-02-21 21:37:45 +01:00
|
|
|
failed:
|
|
|
|
AVIDec_Cleanup(pTransformFilter);
|
|
|
|
|
2005-01-31 17:24:00 +01:00
|
|
|
TRACE("Connection refused\n");
|
2005-02-21 21:37:45 +01:00
|
|
|
return hr;
|
2004-08-24 04:28:35 +02:00
|
|
|
}
|
|
|
|
|
2005-02-01 15:22:00 +01:00
|
|
|
static HRESULT AVIDec_Cleanup(TransformFilterImpl* pTransformFilter)
|
2004-08-24 04:28:35 +02:00
|
|
|
{
|
2005-02-01 15:22:00 +01:00
|
|
|
AVIDecImpl* This = (AVIDecImpl*)pTransformFilter;
|
|
|
|
|
|
|
|
TRACE("(%p)->()\n", This);
|
|
|
|
|
|
|
|
if (This->hvid)
|
|
|
|
ICClose(This->hvid);
|
2005-02-21 21:37:45 +01:00
|
|
|
if (This->pBihIn)
|
2005-02-01 15:22:00 +01:00
|
|
|
CoTaskMemFree(This->pBihIn);
|
2005-02-21 21:37:45 +01:00
|
|
|
if (This->pBihOut)
|
2005-02-01 15:22:00 +01:00
|
|
|
CoTaskMemFree(This->pBihOut);
|
2004-08-24 04:28:35 +02:00
|
|
|
|
2005-02-01 15:22:00 +01:00
|
|
|
This->hvid = NULL;
|
|
|
|
This->pBihIn = NULL;
|
2005-02-21 21:37:45 +01:00
|
|
|
This->pBihOut = NULL;
|
2004-08-24 04:28:35 +02:00
|
|
|
|
2005-01-31 17:24:00 +01:00
|
|
|
return S_OK;
|
2004-08-24 04:28:35 +02:00
|
|
|
}
|
|
|
|
|
2006-11-29 11:05:43 +01:00
|
|
|
static const TransformFuncsTable AVIDec_FuncsTable = {
|
2005-02-21 21:37:45 +01:00
|
|
|
AVIDec_ProcessBegin,
|
|
|
|
AVIDec_ProcessSampleData,
|
|
|
|
AVIDec_ProcessEnd,
|
2007-04-03 09:06:16 +02:00
|
|
|
NULL,
|
2005-02-21 21:37:45 +01:00
|
|
|
AVIDec_ConnectInput,
|
|
|
|
AVIDec_Cleanup
|
|
|
|
};
|
|
|
|
|
2004-08-24 04:28:35 +02:00
|
|
|
HRESULT AVIDec_create(IUnknown * pUnkOuter, LPVOID * ppv)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
2005-02-01 15:22:00 +01:00
|
|
|
AVIDecImpl * This;
|
2004-08-24 04:28:35 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %p)\n", pUnkOuter, ppv);
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if (pUnkOuter)
|
|
|
|
return CLASS_E_NOAGGREGATION;
|
2005-01-31 17:24:00 +01:00
|
|
|
|
|
|
|
/* Note: This memory is managed by the transform filter once created */
|
2005-02-01 15:22:00 +01:00
|
|
|
This = CoTaskMemAlloc(sizeof(AVIDecImpl));
|
2004-08-24 04:28:35 +02:00
|
|
|
|
2005-02-01 15:22:00 +01:00
|
|
|
This->hvid = NULL;
|
|
|
|
This->pBihIn = NULL;
|
2005-02-21 21:37:45 +01:00
|
|
|
This->pBihOut = NULL;
|
2004-08-24 04:28:35 +02:00
|
|
|
|
2005-02-21 21:37:45 +01:00
|
|
|
hr = TransformFilter_Create(&(This->tf), &CLSID_AVIDec, &AVIDec_FuncsTable);
|
2004-08-24 04:28:35 +02:00
|
|
|
|
2005-01-31 17:24:00 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
2004-08-24 04:28:35 +02:00
|
|
|
|
2005-02-01 15:22:00 +01:00
|
|
|
*ppv = (LPVOID)This;
|
2004-08-24 04:28:35 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|