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 "quartz_private.h"
|
|
|
|
|
|
|
|
#include "uuids.h"
|
|
|
|
#include "amvideo.h"
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "dshow.h"
|
|
|
|
#include "strmif.h"
|
|
|
|
#include "vfwmsgs.h"
|
|
|
|
#include "vfw.h"
|
2008-06-20 06:17:08 +02:00
|
|
|
#include "dvdmedia.h"
|
2004-08-24 04:28:35 +02:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
2005-01-31 17:24:00 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(quartz);
|
2004-08-24 04:28:35 +02:00
|
|
|
|
2020-04-01 06:48:16 +02:00
|
|
|
struct avi_decompressor
|
2004-08-24 04:28:35 +02:00
|
|
|
{
|
2020-03-11 04:03:29 +01:00
|
|
|
struct strmbase_filter filter;
|
|
|
|
CRITICAL_SECTION stream_cs;
|
2010-10-07 21:48:19 +02:00
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
struct strmbase_source source;
|
|
|
|
IQualityControl source_IQualityControl_iface;
|
2020-03-28 18:02:03 +01:00
|
|
|
struct strmbase_passthrough passthrough;
|
2020-03-11 04:03:29 +01:00
|
|
|
|
|
|
|
struct strmbase_sink sink;
|
|
|
|
|
2004-08-24 04:28:35 +02:00
|
|
|
HIC hvid;
|
2004-11-29 18:50:23 +01:00
|
|
|
BITMAPINFOHEADER* pBihIn;
|
2010-11-09 23:42:42 +01:00
|
|
|
REFERENCE_TIME late;
|
2020-04-01 06:48:16 +02:00
|
|
|
};
|
2004-08-24 04:28:35 +02:00
|
|
|
|
2020-04-01 06:48:16 +02:00
|
|
|
static struct avi_decompressor *impl_from_strmbase_filter(struct strmbase_filter *iface)
|
2012-03-31 03:10:15 +02:00
|
|
|
{
|
2020-04-01 06:48:16 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct avi_decompressor, filter);
|
2012-03-31 03:10:15 +02:00
|
|
|
}
|
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
static HRESULT avi_decompressor_sink_query_interface(struct strmbase_pin *iface, REFIID iid, void **out)
|
2005-02-21 21:37:45 +01:00
|
|
|
{
|
2020-04-01 06:48:16 +02:00
|
|
|
struct avi_decompressor *filter = impl_from_strmbase_filter(iface->filter);
|
2005-02-21 21:37:45 +01:00
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
if (IsEqualGUID(iid, &IID_IMemInputPin))
|
|
|
|
*out = &filter->sink.IMemInputPin_iface;
|
|
|
|
else
|
|
|
|
return E_NOINTERFACE;
|
2005-02-21 21:37:45 +01:00
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
IUnknown_AddRef((IUnknown *)*out);
|
2005-02-21 21:37:45 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
static HRESULT avi_decompressor_sink_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
2010-11-09 23:42:42 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
static HRESULT avi_decompressor_sink_end_flush(struct strmbase_sink *iface)
|
|
|
|
{
|
2020-04-01 06:48:16 +02:00
|
|
|
struct avi_decompressor *filter = impl_from_strmbase_filter(iface->pin.filter);
|
2020-03-11 04:03:29 +01:00
|
|
|
filter->late = -1;
|
|
|
|
if (filter->source.pin.peer)
|
|
|
|
return IPin_EndFlush(filter->source.pin.peer);
|
2010-11-09 23:42:42 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-04-01 06:48:16 +02:00
|
|
|
static int AVIDec_DropSample(struct avi_decompressor *This, REFERENCE_TIME tStart)
|
|
|
|
{
|
2010-11-09 23:42:42 +01:00
|
|
|
if (This->late < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (tStart < This->late) {
|
|
|
|
TRACE("Dropping sample\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
This->late = -1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
static HRESULT WINAPI avi_decompressor_sink_Receive(struct strmbase_sink *iface, IMediaSample *pSample)
|
2004-08-24 04:28:35 +02:00
|
|
|
{
|
2020-04-01 06:48:16 +02:00
|
|
|
struct avi_decompressor *This = impl_from_strmbase_filter(iface->pin.filter);
|
2020-03-24 16:44:49 +01:00
|
|
|
VIDEOINFOHEADER *source_format;
|
2004-08-24 04:28:35 +02:00
|
|
|
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;
|
2008-05-21 23:33:47 +02:00
|
|
|
LONGLONG tStart, tStop;
|
2010-11-09 23:42:42 +01:00
|
|
|
DWORD flags = 0;
|
2008-07-05 01:59:22 +02:00
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
/* We do not expect pin connection state to change while the filter is
|
|
|
|
* running. This guarantee is necessary, since otherwise we would have to
|
|
|
|
* take the filter lock, and we can't take the filter lock from a streaming
|
|
|
|
* thread. */
|
|
|
|
if (!This->source.pMemInputPin)
|
|
|
|
{
|
|
|
|
WARN("Source is not connected, returning VFW_E_NOT_CONNECTED.\n");
|
|
|
|
return VFW_E_NOT_CONNECTED;
|
|
|
|
}
|
|
|
|
|
2020-03-24 16:44:49 +01:00
|
|
|
source_format = (VIDEOINFOHEADER *)This->source.pin.mt.pbFormat;
|
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
if (This->filter.state == State_Stopped)
|
|
|
|
return VFW_E_WRONG_STATE;
|
|
|
|
|
|
|
|
if (This->sink.flushing)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
EnterCriticalSection(&This->stream_cs);
|
|
|
|
|
2007-04-07 11:32:45 +02:00
|
|
|
hr = IMediaSample_GetPointer(pSample, &pbSrcStream);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("Cannot get pointer to sample data (%x)\n", hr);
|
2020-03-11 04:03:29 +01:00
|
|
|
LeaveCriticalSection(&This->stream_cs);
|
2019-12-01 02:48:32 +01:00
|
|
|
return hr;
|
2007-04-07 11:32:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cbSrcStream = IMediaSample_GetActualDataLength(pSample);
|
|
|
|
|
2010-05-20 01:14:09 +02:00
|
|
|
TRACE("Sample data ptr = %p, size = %d\n", pbSrcStream, cbSrcStream);
|
2004-08-24 04:28:35 +02:00
|
|
|
|
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
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
hr = BaseOutputPinImpl_GetDeliveryBuffer(&This->source, &pOutSample, NULL, NULL, 0);
|
2004-08-24 04:28:35 +02:00
|
|
|
if (FAILED(hr)) {
|
2008-07-05 01:59:22 +02:00
|
|
|
ERR("Unable to get delivery buffer (%x)\n", hr);
|
2020-03-11 04:03:29 +01:00
|
|
|
LeaveCriticalSection(&This->stream_cs);
|
2019-12-01 02:48:32 +01:00
|
|
|
return hr;
|
2004-08-24 04:28:35 +02:00
|
|
|
}
|
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);
|
2019-12-01 02:48:32 +01:00
|
|
|
IMediaSample_Release(pOutSample);
|
2020-03-11 04:03:29 +01:00
|
|
|
LeaveCriticalSection(&This->stream_cs);
|
2019-12-01 02:48:32 +01:00
|
|
|
return hr;
|
2004-08-24 04:28:35 +02:00
|
|
|
}
|
2007-04-07 11:32:45 +02:00
|
|
|
cbDstStream = IMediaSample_GetSize(pOutSample);
|
2020-03-24 16:44:49 +01:00
|
|
|
if (cbDstStream < source_format->bmiHeader.biSizeImage)
|
|
|
|
{
|
|
|
|
ERR("Sample size is too small (%u < %u).\n", cbDstStream, source_format->bmiHeader.biSizeImage);
|
2019-12-01 02:48:32 +01:00
|
|
|
IMediaSample_Release(pOutSample);
|
2020-03-11 04:03:29 +01:00
|
|
|
LeaveCriticalSection(&This->stream_cs);
|
2019-12-01 02:48:32 +01:00
|
|
|
return E_FAIL;
|
2004-08-24 04:28:35 +02:00
|
|
|
}
|
|
|
|
|
2010-11-09 23:42:42 +01:00
|
|
|
if (IMediaSample_IsPreroll(pSample) == S_OK)
|
|
|
|
flags |= ICDECOMPRESS_PREROLL;
|
|
|
|
if (IMediaSample_IsSyncPoint(pSample) != S_OK)
|
|
|
|
flags |= ICDECOMPRESS_NOTKEYFRAME;
|
2010-11-29 10:44:17 +01:00
|
|
|
hr = IMediaSample_GetTime(pSample, &tStart, &tStop);
|
|
|
|
if (hr == S_OK && AVIDec_DropSample(This, tStart))
|
2010-11-09 23:42:42 +01:00
|
|
|
flags |= ICDECOMPRESS_HURRYUP;
|
|
|
|
|
2020-03-24 16:44:49 +01:00
|
|
|
res = ICDecompress(This->hvid, flags, This->pBihIn, pbSrcStream, &source_format->bmiHeader, 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
|
|
|
|
2016-08-04 09:57:45 +02:00
|
|
|
/* Drop sample if it's intended to be dropped */
|
2010-11-29 10:44:17 +01:00
|
|
|
if (flags & ICDECOMPRESS_HURRYUP) {
|
2019-12-01 02:48:32 +01:00
|
|
|
IMediaSample_Release(pOutSample);
|
2020-03-11 04:03:29 +01:00
|
|
|
LeaveCriticalSection(&This->stream_cs);
|
2019-12-01 02:48:32 +01:00
|
|
|
return S_OK;
|
2010-11-29 10:44:17 +01:00
|
|
|
}
|
2010-11-09 23:42:42 +01:00
|
|
|
|
2020-03-24 16:44:49 +01:00
|
|
|
IMediaSample_SetActualDataLength(pOutSample, source_format->bmiHeader.biSizeImage);
|
2008-05-21 23:33:47 +02:00
|
|
|
|
|
|
|
IMediaSample_SetPreroll(pOutSample, (IMediaSample_IsPreroll(pSample) == S_OK));
|
|
|
|
IMediaSample_SetDiscontinuity(pOutSample, (IMediaSample_IsDiscontinuity(pSample) == S_OK));
|
|
|
|
IMediaSample_SetSyncPoint(pOutSample, (IMediaSample_IsSyncPoint(pSample) == S_OK));
|
|
|
|
|
2010-11-29 10:44:17 +01:00
|
|
|
if (hr == S_OK)
|
2008-05-21 23:33:47 +02:00
|
|
|
IMediaSample_SetTime(pOutSample, &tStart, &tStop);
|
2010-11-29 10:44:17 +01:00
|
|
|
else if (hr == VFW_S_NO_STOP_TIME)
|
|
|
|
IMediaSample_SetTime(pOutSample, &tStart, NULL);
|
2008-05-21 23:33:47 +02:00
|
|
|
else
|
|
|
|
IMediaSample_SetTime(pOutSample, NULL, NULL);
|
|
|
|
|
2010-11-07 15:02:46 +01:00
|
|
|
if (IMediaSample_GetMediaTime(pSample, &tStart, &tStop) == S_OK)
|
|
|
|
IMediaSample_SetMediaTime(pOutSample, &tStart, &tStop);
|
|
|
|
else
|
|
|
|
IMediaSample_SetMediaTime(pOutSample, NULL, NULL);
|
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
hr = IMemInputPin_Receive(This->source.pMemInputPin, pOutSample);
|
2008-07-05 01:59:22 +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
|
|
|
|
2019-12-01 02:48:32 +01:00
|
|
|
IMediaSample_Release(pOutSample);
|
2020-03-11 04:03:29 +01:00
|
|
|
LeaveCriticalSection(&This->stream_cs);
|
2004-08-24 04:28:35 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
static HRESULT avi_decompressor_sink_connect(struct strmbase_sink *iface, IPin *peer, const AM_MEDIA_TYPE *pmt)
|
2005-02-21 21:37:45 +01:00
|
|
|
{
|
2020-04-01 06:48:16 +02:00
|
|
|
struct avi_decompressor *This = impl_from_strmbase_filter(iface->pin.filter);
|
2007-06-05 05:11:25 +02:00
|
|
|
HRESULT hr = VFW_E_TYPE_NOT_ACCEPTED;
|
2005-02-01 15:22:00 +01:00
|
|
|
|
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)) &&
|
2008-06-20 06:17:08 +02:00
|
|
|
(!memcmp(((const char *)&pmt->subtype)+4, ((const char *)&MEDIATYPE_Video)+4, sizeof(GUID)-4)))
|
2004-08-24 04:28:35 +02:00
|
|
|
{
|
2008-06-20 06:17:08 +02:00
|
|
|
VIDEOINFOHEADER *format1 = (VIDEOINFOHEADER *)pmt->pbFormat;
|
|
|
|
VIDEOINFOHEADER2 *format2 = (VIDEOINFOHEADER2 *)pmt->pbFormat;
|
|
|
|
BITMAPINFOHEADER *bmi;
|
|
|
|
|
|
|
|
if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo))
|
|
|
|
bmi = &format1->bmiHeader;
|
|
|
|
else if (IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo2))
|
|
|
|
bmi = &format2->bmiHeader;
|
|
|
|
else
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
This->hvid = ICLocate(pmt->majortype.Data1, pmt->subtype.Data1, bmi, NULL, ICMODE_DECOMPRESS);
|
2005-02-21 21:37:45 +01:00
|
|
|
if (This->hvid)
|
2004-11-29 18:50:23 +01:00
|
|
|
{
|
|
|
|
DWORD bih_size;
|
2005-02-21 21:37:45 +01:00
|
|
|
DWORD result;
|
2004-11-29 18:50:23 +01:00
|
|
|
|
|
|
|
/* Copy bitmap header from media type to 1 for input and 1 for output */
|
2008-06-20 06:17:08 +02:00
|
|
|
bih_size = bmi->biSize + bmi->biClrUsed * 4;
|
2007-06-27 00:12:07 +02:00
|
|
|
This->pBihIn = CoTaskMemAlloc(bih_size);
|
2005-02-01 15:22:00 +01:00
|
|
|
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
|
|
|
}
|
2008-06-20 06:17:08 +02:00
|
|
|
memcpy(This->pBihIn, bmi, bih_size);
|
2020-03-24 16:44:49 +01:00
|
|
|
|
|
|
|
if ((result = ICDecompressQuery(This->hvid, This->pBihIn, NULL)))
|
2005-02-21 21:37:45 +01:00
|
|
|
{
|
2020-03-24 16:44:49 +01:00
|
|
|
WARN("No decompressor found, error %d.\n", result);
|
|
|
|
return VFW_E_TYPE_NOT_ACCEPTED;
|
2005-02-21 21:37:45 +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:
|
2008-06-20 06:17:08 +02:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
static void avi_decompressor_sink_disconnect(struct strmbase_sink *iface)
|
2010-10-07 21:48:19 +02:00
|
|
|
{
|
2020-04-01 06:48:16 +02:00
|
|
|
struct avi_decompressor *filter = impl_from_strmbase_filter(iface->pin.filter);
|
2020-03-11 04:03:29 +01:00
|
|
|
|
|
|
|
if (filter->hvid)
|
|
|
|
ICClose(filter->hvid);
|
|
|
|
CoTaskMemFree(filter->pBihIn);
|
|
|
|
filter->hvid = NULL;
|
|
|
|
filter->pBihIn = NULL;
|
|
|
|
}
|
2005-02-01 15:22:00 +01:00
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
static const struct strmbase_sink_ops sink_ops =
|
|
|
|
{
|
|
|
|
.base.pin_query_interface = avi_decompressor_sink_query_interface,
|
|
|
|
.base.pin_query_accept = avi_decompressor_sink_query_accept,
|
|
|
|
.base.pin_get_media_type = strmbase_pin_get_media_type,
|
|
|
|
.pfnReceive = avi_decompressor_sink_Receive,
|
|
|
|
.sink_connect = avi_decompressor_sink_connect,
|
|
|
|
.sink_disconnect = avi_decompressor_sink_disconnect,
|
|
|
|
.sink_end_flush = avi_decompressor_sink_end_flush,
|
|
|
|
};
|
2004-08-24 04:28:35 +02:00
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
static HRESULT avi_decompressor_source_query_interface(struct strmbase_pin *iface, REFIID iid, void **out)
|
|
|
|
{
|
2020-04-01 06:48:16 +02:00
|
|
|
struct avi_decompressor *filter = impl_from_strmbase_filter(iface->filter);
|
2020-03-11 04:03:29 +01:00
|
|
|
|
|
|
|
if (IsEqualGUID(iid, &IID_IQualityControl))
|
|
|
|
*out = &filter->source_IQualityControl_iface;
|
|
|
|
else if (IsEqualGUID(iid, &IID_IMediaSeeking))
|
2020-03-28 18:02:03 +01:00
|
|
|
*out = &filter->passthrough.IMediaSeeking_iface;
|
2020-03-11 04:03:29 +01:00
|
|
|
else
|
|
|
|
return E_NOINTERFACE;
|
2004-08-24 04:28:35 +02:00
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
IUnknown_AddRef((IUnknown *)*out);
|
2005-01-31 17:24:00 +01:00
|
|
|
return S_OK;
|
2004-08-24 04:28:35 +02:00
|
|
|
}
|
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
static HRESULT avi_decompressor_source_query_accept(struct strmbase_pin *iface, const AM_MEDIA_TYPE *mt)
|
2010-10-13 17:46:27 +02:00
|
|
|
{
|
2020-04-01 06:48:16 +02:00
|
|
|
struct avi_decompressor *filter = impl_from_strmbase_filter(iface->filter);
|
2020-03-24 16:44:48 +01:00
|
|
|
VIDEOINFOHEADER *sink_format, *format;
|
2020-03-11 04:03:29 +01:00
|
|
|
|
2020-03-24 16:44:48 +01:00
|
|
|
if (!filter->sink.pin.peer || !IsEqualGUID(&mt->formattype, &FORMAT_VideoInfo))
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
sink_format = (VIDEOINFOHEADER *)filter->sink.pin.mt.pbFormat;
|
|
|
|
format = (VIDEOINFOHEADER *)mt->pbFormat;
|
|
|
|
|
|
|
|
if (ICDecompressQuery(filter->hvid, &sink_format->bmiHeader, &format->bmiHeader))
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
return S_OK;
|
2020-03-11 04:03:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT avi_decompressor_source_get_media_type(struct strmbase_pin *iface,
|
|
|
|
unsigned int index, AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
2020-03-24 16:44:47 +01:00
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const GUID *subtype;
|
|
|
|
DWORD compression;
|
|
|
|
WORD bpp;
|
|
|
|
}
|
|
|
|
formats[] =
|
|
|
|
{
|
|
|
|
{&MEDIASUBTYPE_CLJR, mmioFOURCC('C','L','J','R'), 8},
|
|
|
|
{&MEDIASUBTYPE_UYVY, mmioFOURCC('U','Y','V','Y'), 16},
|
|
|
|
{&MEDIASUBTYPE_YUY2, mmioFOURCC('Y','U','Y','2'), 16},
|
|
|
|
{&MEDIASUBTYPE_RGB32, BI_RGB, 32},
|
|
|
|
{&MEDIASUBTYPE_RGB24, BI_RGB, 24},
|
|
|
|
{&MEDIASUBTYPE_RGB565, BI_BITFIELDS, 16},
|
|
|
|
{&MEDIASUBTYPE_RGB555, BI_RGB, 16},
|
|
|
|
{&MEDIASUBTYPE_RGB8, BI_RGB, 8},
|
|
|
|
};
|
|
|
|
|
2020-04-01 06:48:16 +02:00
|
|
|
struct avi_decompressor *filter = impl_from_strmbase_filter(iface->filter);
|
2020-03-24 16:44:47 +01:00
|
|
|
const VIDEOINFOHEADER *sink_format;
|
|
|
|
VIDEOINFO *format;
|
2020-03-11 04:03:29 +01:00
|
|
|
|
2020-03-24 16:44:47 +01:00
|
|
|
if (!filter->sink.pin.peer)
|
2020-03-11 04:03:29 +01:00
|
|
|
return VFW_S_NO_MORE_ITEMS;
|
2020-03-24 16:44:47 +01:00
|
|
|
|
|
|
|
sink_format = (VIDEOINFOHEADER *)filter->sink.pin.mt.pbFormat;
|
|
|
|
|
|
|
|
memset(mt, 0, sizeof(AM_MEDIA_TYPE));
|
|
|
|
|
|
|
|
if (index < ARRAY_SIZE(formats))
|
|
|
|
{
|
|
|
|
if (!(format = CoTaskMemAlloc(offsetof(VIDEOINFO, dwBitMasks[3]))))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
memset(format, 0, offsetof(VIDEOINFO, dwBitMasks[3]));
|
|
|
|
|
|
|
|
format->rcSource = sink_format->rcSource;
|
|
|
|
format->rcTarget = sink_format->rcTarget;
|
|
|
|
format->dwBitRate = sink_format->dwBitRate;
|
|
|
|
format->dwBitErrorRate = sink_format->dwBitErrorRate;
|
|
|
|
format->AvgTimePerFrame = sink_format->AvgTimePerFrame;
|
|
|
|
|
|
|
|
format->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
|
|
format->bmiHeader.biWidth = sink_format->bmiHeader.biWidth;
|
|
|
|
format->bmiHeader.biHeight = sink_format->bmiHeader.biHeight;
|
|
|
|
format->bmiHeader.biPlanes = sink_format->bmiHeader.biPlanes;
|
|
|
|
format->bmiHeader.biBitCount = formats[index].bpp;
|
|
|
|
format->bmiHeader.biCompression = formats[index].compression;
|
|
|
|
format->bmiHeader.biSizeImage = format->bmiHeader.biWidth
|
|
|
|
* format->bmiHeader.biHeight * formats[index].bpp / 8;
|
|
|
|
|
|
|
|
if (IsEqualGUID(formats[index].subtype, &MEDIASUBTYPE_RGB565))
|
|
|
|
{
|
|
|
|
format->dwBitMasks[iRED] = 0xf800;
|
|
|
|
format->dwBitMasks[iGREEN] = 0x07e0;
|
|
|
|
format->dwBitMasks[iBLUE] = 0x001f;
|
|
|
|
mt->cbFormat = offsetof(VIDEOINFO, dwBitMasks[3]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mt->cbFormat = sizeof(VIDEOINFOHEADER);
|
|
|
|
|
|
|
|
mt->majortype = MEDIATYPE_Video;
|
|
|
|
mt->subtype = *formats[index].subtype;
|
|
|
|
mt->bFixedSizeSamples = TRUE;
|
|
|
|
mt->lSampleSize = format->bmiHeader.biSizeImage;
|
|
|
|
mt->formattype = FORMAT_VideoInfo;
|
|
|
|
mt->pbFormat = (BYTE *)format;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index == ARRAY_SIZE(formats))
|
|
|
|
{
|
|
|
|
size_t size = ICDecompressGetFormatSize(filter->hvid, &sink_format->bmiHeader);
|
|
|
|
|
|
|
|
if (!size)
|
|
|
|
return VFW_S_NO_MORE_ITEMS;
|
|
|
|
|
|
|
|
mt->cbFormat = offsetof(VIDEOINFOHEADER, bmiHeader) + size;
|
|
|
|
if (!(format = CoTaskMemAlloc(mt->cbFormat)))
|
|
|
|
return E_OUTOFMEMORY;
|
2020-03-24 16:44:49 +01:00
|
|
|
memset(format, 0, mt->cbFormat);
|
2020-03-24 16:44:47 +01:00
|
|
|
|
|
|
|
format->rcSource = sink_format->rcSource;
|
|
|
|
format->rcTarget = sink_format->rcTarget;
|
|
|
|
format->dwBitRate = sink_format->dwBitRate;
|
|
|
|
format->dwBitErrorRate = sink_format->dwBitErrorRate;
|
|
|
|
format->AvgTimePerFrame = sink_format->AvgTimePerFrame;
|
|
|
|
|
|
|
|
if (ICDecompressGetFormat(filter->hvid, &sink_format->bmiHeader, &format->bmiHeader))
|
|
|
|
{
|
|
|
|
CoTaskMemFree(format);
|
|
|
|
return VFW_S_NO_MORE_ITEMS;
|
|
|
|
}
|
|
|
|
|
|
|
|
mt->majortype = MEDIATYPE_Video;
|
|
|
|
mt->subtype = MEDIATYPE_Video;
|
|
|
|
mt->subtype.Data1 = format->bmiHeader.biCompression;
|
|
|
|
mt->bFixedSizeSamples = TRUE;
|
|
|
|
mt->lSampleSize = format->bmiHeader.biSizeImage;
|
|
|
|
mt->formattype = FORMAT_VideoInfo;
|
|
|
|
mt->pbFormat = (BYTE *)format;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return VFW_S_NO_MORE_ITEMS;
|
2020-03-11 04:03:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI avi_decompressor_source_DecideBufferSize(struct strmbase_source *iface,
|
|
|
|
IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *ppropInputRequest)
|
|
|
|
{
|
2020-03-24 16:44:49 +01:00
|
|
|
const VIDEOINFOHEADER *source_format = (VIDEOINFOHEADER *)iface->pin.mt.pbFormat;
|
2010-10-13 17:46:27 +02:00
|
|
|
ALLOCATOR_PROPERTIES actual;
|
|
|
|
|
|
|
|
if (!ppropInputRequest->cbAlign)
|
|
|
|
ppropInputRequest->cbAlign = 1;
|
|
|
|
|
2020-03-24 16:44:49 +01:00
|
|
|
if (ppropInputRequest->cbBuffer < source_format->bmiHeader.biSizeImage)
|
|
|
|
ppropInputRequest->cbBuffer = source_format->bmiHeader.biSizeImage;
|
2010-10-13 17:46:27 +02:00
|
|
|
|
|
|
|
if (!ppropInputRequest->cBuffers)
|
|
|
|
ppropInputRequest->cBuffers = 1;
|
|
|
|
|
|
|
|
return IMemAllocator_SetProperties(pAlloc, ppropInputRequest, &actual);
|
|
|
|
}
|
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
static const struct strmbase_source_ops source_ops =
|
|
|
|
{
|
|
|
|
.base.pin_query_interface = avi_decompressor_source_query_interface,
|
|
|
|
.base.pin_query_accept = avi_decompressor_source_query_accept,
|
|
|
|
.base.pin_get_media_type = avi_decompressor_source_get_media_type,
|
|
|
|
.pfnAttemptConnection = BaseOutputPinImpl_AttemptConnection,
|
|
|
|
.pfnDecideAllocator = BaseOutputPinImpl_DecideAllocator,
|
|
|
|
.pfnDecideBufferSize = avi_decompressor_source_DecideBufferSize,
|
|
|
|
};
|
|
|
|
|
2020-04-01 06:48:16 +02:00
|
|
|
static struct avi_decompressor *impl_from_source_IQualityControl(IQualityControl *iface)
|
2020-03-11 04:03:29 +01:00
|
|
|
{
|
2020-04-01 06:48:16 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct avi_decompressor, source_IQualityControl_iface);
|
2020-03-11 04:03:29 +01:00
|
|
|
}
|
|
|
|
|
2020-04-01 06:48:17 +02:00
|
|
|
static HRESULT WINAPI avi_decompressor_source_qc_QueryInterface(IQualityControl *iface,
|
2020-03-11 04:03:29 +01:00
|
|
|
REFIID iid, void **out)
|
|
|
|
{
|
2020-04-01 06:48:16 +02:00
|
|
|
struct avi_decompressor *filter = impl_from_source_IQualityControl(iface);
|
2020-03-11 04:03:29 +01:00
|
|
|
return IPin_QueryInterface(&filter->source.pin.IPin_iface, iid, out);
|
|
|
|
}
|
|
|
|
|
2020-04-01 06:48:17 +02:00
|
|
|
static ULONG WINAPI avi_decompressor_source_qc_AddRef(IQualityControl *iface)
|
2020-03-11 04:03:29 +01:00
|
|
|
{
|
2020-04-01 06:48:16 +02:00
|
|
|
struct avi_decompressor *filter = impl_from_source_IQualityControl(iface);
|
2020-03-11 04:03:29 +01:00
|
|
|
return IPin_AddRef(&filter->source.pin.IPin_iface);
|
|
|
|
}
|
|
|
|
|
2020-04-01 06:48:17 +02:00
|
|
|
static ULONG WINAPI avi_decompressor_source_qc_Release(IQualityControl *iface)
|
2020-03-11 04:03:29 +01:00
|
|
|
{
|
2020-04-01 06:48:16 +02:00
|
|
|
struct avi_decompressor *filter = impl_from_source_IQualityControl(iface);
|
2020-03-11 04:03:29 +01:00
|
|
|
return IPin_Release(&filter->source.pin.IPin_iface);
|
|
|
|
}
|
|
|
|
|
2020-04-01 06:48:17 +02:00
|
|
|
static HRESULT WINAPI avi_decompressor_source_qc_Notify(IQualityControl *iface,
|
2020-03-11 04:03:29 +01:00
|
|
|
IBaseFilter *sender, Quality q)
|
|
|
|
{
|
2020-04-01 06:48:16 +02:00
|
|
|
struct avi_decompressor *filter = impl_from_source_IQualityControl(iface);
|
2020-03-11 04:03:29 +01:00
|
|
|
|
|
|
|
TRACE("filter %p, sender %p, type %#x, proportion %u, late %s, timestamp %s.\n",
|
|
|
|
filter, sender, q.Type, q.Proportion, debugstr_time(q.Late), debugstr_time(q.TimeStamp));
|
|
|
|
|
|
|
|
EnterCriticalSection(&filter->stream_cs);
|
|
|
|
if (q.Late > 0)
|
|
|
|
filter->late = q.Late + q.TimeStamp;
|
|
|
|
else
|
|
|
|
filter->late = -1;
|
|
|
|
LeaveCriticalSection(&filter->stream_cs);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-04-01 06:48:17 +02:00
|
|
|
static HRESULT WINAPI avi_decompressor_source_qc_SetSink(IQualityControl *iface, IQualityControl *sink)
|
2020-03-11 04:03:29 +01:00
|
|
|
{
|
2020-04-01 06:48:16 +02:00
|
|
|
struct avi_decompressor *filter = impl_from_source_IQualityControl(iface);
|
2020-03-11 04:03:29 +01:00
|
|
|
|
|
|
|
TRACE("filter %p, sink %p.\n", filter, sink);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IQualityControlVtbl source_qc_vtbl =
|
|
|
|
{
|
2020-04-01 06:48:17 +02:00
|
|
|
avi_decompressor_source_qc_QueryInterface,
|
|
|
|
avi_decompressor_source_qc_AddRef,
|
|
|
|
avi_decompressor_source_qc_Release,
|
|
|
|
avi_decompressor_source_qc_Notify,
|
|
|
|
avi_decompressor_source_qc_SetSink,
|
2020-03-11 04:03:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct strmbase_pin *avi_decompressor_get_pin(struct strmbase_filter *iface, unsigned int index)
|
|
|
|
{
|
2020-04-01 06:48:16 +02:00
|
|
|
struct avi_decompressor *filter = impl_from_strmbase_filter(iface);
|
2020-03-11 04:03:29 +01:00
|
|
|
|
|
|
|
if (index == 0)
|
|
|
|
return &filter->sink.pin;
|
|
|
|
else if (index == 1)
|
|
|
|
return &filter->source.pin;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void avi_decompressor_destroy(struct strmbase_filter *iface)
|
|
|
|
{
|
2020-04-01 06:48:16 +02:00
|
|
|
struct avi_decompressor *filter = impl_from_strmbase_filter(iface);
|
2020-03-11 04:03:29 +01:00
|
|
|
|
|
|
|
if (filter->sink.pin.peer)
|
|
|
|
IPin_Disconnect(filter->sink.pin.peer);
|
|
|
|
IPin_Disconnect(&filter->sink.pin.IPin_iface);
|
|
|
|
|
|
|
|
if (filter->source.pin.peer)
|
|
|
|
IPin_Disconnect(filter->source.pin.peer);
|
|
|
|
IPin_Disconnect(&filter->source.pin.IPin_iface);
|
|
|
|
|
|
|
|
strmbase_sink_cleanup(&filter->sink);
|
|
|
|
strmbase_source_cleanup(&filter->source);
|
2020-03-28 18:02:03 +01:00
|
|
|
strmbase_passthrough_cleanup(&filter->passthrough);
|
2020-03-11 04:03:29 +01:00
|
|
|
|
|
|
|
filter->stream_cs.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection(&filter->stream_cs);
|
|
|
|
strmbase_filter_cleanup(&filter->filter);
|
|
|
|
free(filter);
|
2020-03-13 03:34:12 +01:00
|
|
|
|
|
|
|
InterlockedDecrement(&object_locks);
|
2020-03-11 04:03:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT avi_decompressor_init_stream(struct strmbase_filter *iface)
|
|
|
|
{
|
2020-04-01 06:48:16 +02:00
|
|
|
struct avi_decompressor *filter = impl_from_strmbase_filter(iface);
|
2020-03-24 16:44:49 +01:00
|
|
|
VIDEOINFOHEADER *source_format;
|
2020-03-11 04:03:29 +01:00
|
|
|
LRESULT res;
|
|
|
|
|
|
|
|
filter->late = -1;
|
|
|
|
|
2020-03-24 16:44:49 +01:00
|
|
|
source_format = (VIDEOINFOHEADER *)filter->sink.pin.mt.pbFormat;
|
|
|
|
if ((res = ICDecompressBegin(filter->hvid, filter->pBihIn, &source_format->bmiHeader)))
|
2020-03-11 04:03:29 +01:00
|
|
|
{
|
|
|
|
ERR("ICDecompressBegin() failed, error %ld.\n", res);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseOutputPinImpl_Active(&filter->source);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT avi_decompressor_cleanup_stream(struct strmbase_filter *iface)
|
|
|
|
{
|
2020-04-01 06:48:16 +02:00
|
|
|
struct avi_decompressor *filter = impl_from_strmbase_filter(iface);
|
2020-03-11 04:03:29 +01:00
|
|
|
LRESULT res;
|
|
|
|
|
|
|
|
if (filter->hvid && (res = ICDecompressEnd(filter->hvid)))
|
|
|
|
{
|
|
|
|
ERR("ICDecompressEnd() failed, error %ld.\n", res);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseOutputPinImpl_Inactive(&filter->source);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct strmbase_filter_ops filter_ops =
|
|
|
|
{
|
|
|
|
.filter_get_pin = avi_decompressor_get_pin,
|
|
|
|
.filter_destroy = avi_decompressor_destroy,
|
|
|
|
.filter_init_stream = avi_decompressor_init_stream,
|
|
|
|
.filter_cleanup_stream = avi_decompressor_cleanup_stream,
|
2005-02-21 21:37:45 +01:00
|
|
|
};
|
|
|
|
|
2020-03-12 03:10:10 +01:00
|
|
|
HRESULT avi_dec_create(IUnknown *outer, IUnknown **out)
|
2004-08-24 04:28:35 +02:00
|
|
|
{
|
2020-04-01 06:48:16 +02:00
|
|
|
struct avi_decompressor *object;
|
2004-08-24 04:28:35 +02:00
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
if (!(object = calloc(1, sizeof(*object))))
|
|
|
|
return E_OUTOFMEMORY;
|
2004-08-24 04:28:35 +02:00
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
strmbase_filter_init(&object->filter, outer, &CLSID_AVIDec, &filter_ops);
|
2010-10-07 21:48:19 +02:00
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
InitializeCriticalSection(&object->stream_cs);
|
|
|
|
object->stream_cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__": avi_decompressor.stream_cs");
|
|
|
|
|
|
|
|
strmbase_sink_init(&object->sink, &object->filter, L"In", &sink_ops, NULL);
|
|
|
|
|
|
|
|
strmbase_source_init(&object->source, &object->filter, L"Out", &source_ops);
|
|
|
|
object->source_IQualityControl_iface.lpVtbl = &source_qc_vtbl;
|
2020-03-28 18:02:03 +01:00
|
|
|
strmbase_passthrough_init(&object->passthrough, (IUnknown *)&object->source.pin.IPin_iface);
|
|
|
|
ISeekingPassThru_Init(&object->passthrough.ISeekingPassThru_iface, FALSE,
|
|
|
|
&object->sink.pin.IPin_iface);
|
2004-08-24 04:28:35 +02:00
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
TRACE("Created AVI decompressor %p.\n", object);
|
|
|
|
*out = &object->filter.IUnknown_inner;
|
2010-10-07 21:48:19 +02:00
|
|
|
|
2020-03-11 04:03:29 +01:00
|
|
|
return S_OK;
|
2010-10-07 21:48:19 +02:00
|
|
|
}
|