2013-12-19 15:31:52 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Jacek Caban for CodeWeavers
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2020-06-29 17:26:15 +02:00
|
|
|
#include "qcap_private.h"
|
2013-12-30 20:21:47 +01:00
|
|
|
#include "vfw.h"
|
2013-12-30 20:21:36 +01:00
|
|
|
#include "aviriff.h"
|
2013-12-19 15:31:52 +01:00
|
|
|
|
2021-07-10 05:14:39 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(quartz);
|
2013-12-19 15:31:52 +01:00
|
|
|
|
|
|
|
typedef struct {
|
2019-08-29 03:24:30 +02:00
|
|
|
struct strmbase_filter filter;
|
2013-12-30 16:37:47 +01:00
|
|
|
IPersistPropertyBag IPersistPropertyBag_iface;
|
2013-12-30 16:38:03 +01:00
|
|
|
|
2019-11-20 03:18:01 +01:00
|
|
|
struct strmbase_sink sink;
|
2019-09-12 21:28:25 +02:00
|
|
|
struct strmbase_source source;
|
2013-12-30 20:21:36 +01:00
|
|
|
|
|
|
|
DWORD fcc_handler;
|
2013-12-30 20:21:47 +01:00
|
|
|
HIC hic;
|
2013-12-30 20:21:58 +01:00
|
|
|
|
|
|
|
VIDEOINFOHEADER *videoinfo;
|
|
|
|
size_t videoinfo_size;
|
|
|
|
DWORD driver_flags;
|
2014-04-08 14:25:52 +02:00
|
|
|
DWORD max_frame_size;
|
2013-12-30 20:22:25 +01:00
|
|
|
|
|
|
|
DWORD frame_cnt;
|
2013-12-19 15:31:52 +01:00
|
|
|
} AVICompressor;
|
|
|
|
|
2019-08-29 03:24:30 +02:00
|
|
|
static inline AVICompressor *impl_from_strmbase_filter(struct strmbase_filter *filter)
|
2013-12-19 15:31:52 +01:00
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(filter, AVICompressor, filter);
|
|
|
|
}
|
|
|
|
|
2019-09-24 02:33:24 +02:00
|
|
|
static inline AVICompressor *impl_from_strmbase_pin(struct strmbase_pin *pin)
|
2013-12-30 16:38:03 +01:00
|
|
|
{
|
2019-09-06 02:02:15 +02:00
|
|
|
return impl_from_strmbase_filter(pin->filter);
|
2013-12-30 16:38:03 +01:00
|
|
|
}
|
|
|
|
|
2013-12-30 20:21:47 +01:00
|
|
|
static HRESULT ensure_driver(AVICompressor *This)
|
|
|
|
{
|
|
|
|
if(This->hic)
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
This->hic = ICOpen(FCC('v','i','d','c'), This->fcc_handler, ICMODE_COMPRESS);
|
|
|
|
if(!This->hic) {
|
|
|
|
FIXME("ICOpen failed\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2013-12-30 20:21:58 +01:00
|
|
|
static HRESULT fill_format_info(AVICompressor *This, VIDEOINFOHEADER *src_videoinfo)
|
|
|
|
{
|
|
|
|
DWORD size;
|
|
|
|
ICINFO icinfo;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = ensure_driver(This);
|
|
|
|
if(hres != S_OK)
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
size = ICGetInfo(This->hic, &icinfo, sizeof(icinfo));
|
|
|
|
if(size != sizeof(icinfo))
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
size = ICCompressGetFormatSize(This->hic, &src_videoinfo->bmiHeader);
|
|
|
|
if(!size) {
|
|
|
|
FIXME("ICCompressGetFormatSize failed\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
size += FIELD_OFFSET(VIDEOINFOHEADER, bmiHeader);
|
2020-11-27 05:34:36 +01:00
|
|
|
if (!(This->videoinfo = calloc(1, size)))
|
2013-12-30 20:21:58 +01:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
This->videoinfo_size = size;
|
|
|
|
This->driver_flags = icinfo.dwFlags;
|
|
|
|
ICCompressGetFormat(This->hic, &src_videoinfo->bmiHeader, &This->videoinfo->bmiHeader);
|
|
|
|
|
|
|
|
This->videoinfo->dwBitRate = 10000000/src_videoinfo->AvgTimePerFrame * This->videoinfo->bmiHeader.biSizeImage * 8;
|
|
|
|
This->videoinfo->AvgTimePerFrame = src_videoinfo->AvgTimePerFrame;
|
2014-04-08 14:25:52 +02:00
|
|
|
This->max_frame_size = This->videoinfo->bmiHeader.biSizeImage;
|
2013-12-30 20:21:58 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-11-23 04:13:59 +01:00
|
|
|
static struct strmbase_pin *avi_compressor_get_pin(struct strmbase_filter *iface, unsigned int index)
|
2013-12-19 15:31:52 +01:00
|
|
|
{
|
2019-08-29 03:24:30 +02:00
|
|
|
AVICompressor *filter = impl_from_strmbase_filter(iface);
|
2013-12-30 16:38:03 +01:00
|
|
|
|
2019-05-24 00:06:30 +02:00
|
|
|
if (index == 0)
|
2019-11-23 04:13:59 +01:00
|
|
|
return &filter->sink.pin;
|
2019-05-24 00:06:30 +02:00
|
|
|
else if (index == 1)
|
2019-11-23 04:13:59 +01:00
|
|
|
return &filter->source.pin;
|
2019-06-11 16:42:16 +02:00
|
|
|
return NULL;
|
2013-12-19 15:31:52 +01:00
|
|
|
}
|
|
|
|
|
2019-08-29 03:24:30 +02:00
|
|
|
static void avi_compressor_destroy(struct strmbase_filter *iface)
|
2019-05-25 22:21:23 +02:00
|
|
|
{
|
2019-08-29 03:24:30 +02:00
|
|
|
AVICompressor *filter = impl_from_strmbase_filter(iface);
|
2019-05-25 22:21:23 +02:00
|
|
|
|
|
|
|
if (filter->hic)
|
|
|
|
ICClose(filter->hic);
|
2020-11-27 05:34:36 +01:00
|
|
|
free(filter->videoinfo);
|
2019-06-13 01:58:37 +02:00
|
|
|
strmbase_sink_cleanup(&filter->sink);
|
2019-06-14 01:09:21 +02:00
|
|
|
strmbase_source_cleanup(&filter->source);
|
2019-05-25 22:21:23 +02:00
|
|
|
strmbase_filter_cleanup(&filter->filter);
|
2020-11-27 05:34:36 +01:00
|
|
|
free(filter);
|
2019-05-25 22:21:23 +02:00
|
|
|
}
|
|
|
|
|
2019-08-29 03:24:30 +02:00
|
|
|
static HRESULT avi_compressor_query_interface(struct strmbase_filter *iface, REFIID iid, void **out)
|
2019-06-04 17:01:16 +02:00
|
|
|
{
|
2019-08-29 03:24:30 +02:00
|
|
|
AVICompressor *filter = impl_from_strmbase_filter(iface);
|
2019-06-04 17:01:16 +02:00
|
|
|
|
|
|
|
if (IsEqualGUID(iid, &IID_IPersistPropertyBag))
|
|
|
|
*out = &filter->IPersistPropertyBag_iface;
|
|
|
|
else
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown *)*out);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-12-05 06:03:28 +01:00
|
|
|
static HRESULT avi_compressor_init_stream(struct strmbase_filter *iface)
|
|
|
|
{
|
|
|
|
AVICompressor *filter = impl_from_strmbase_filter(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (filter->source.pAllocator && FAILED(hr = IMemAllocator_Commit(filter->source.pAllocator)))
|
|
|
|
{
|
2022-02-09 03:04:42 +01:00
|
|
|
ERR("Failed to commit allocator, hr %#lx.\n", hr);
|
2019-12-05 06:03:28 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
filter->frame_cnt = 0;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT avi_compressor_cleanup_stream(struct strmbase_filter *iface)
|
|
|
|
{
|
|
|
|
AVICompressor *filter = impl_from_strmbase_filter(iface);
|
|
|
|
|
|
|
|
ICCompressEnd(filter->hic);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-08-29 03:24:29 +02:00
|
|
|
static const struct strmbase_filter_ops filter_ops =
|
|
|
|
{
|
2019-05-24 00:06:31 +02:00
|
|
|
.filter_get_pin = avi_compressor_get_pin,
|
2019-05-25 22:21:23 +02:00
|
|
|
.filter_destroy = avi_compressor_destroy,
|
2019-06-04 17:01:16 +02:00
|
|
|
.filter_query_interface = avi_compressor_query_interface,
|
2019-12-05 06:03:28 +01:00
|
|
|
.filter_init_stream = avi_compressor_init_stream,
|
|
|
|
.filter_cleanup_stream = avi_compressor_cleanup_stream,
|
2013-12-19 15:31:52 +01:00
|
|
|
};
|
|
|
|
|
2013-12-30 16:37:47 +01:00
|
|
|
static AVICompressor *impl_from_IPersistPropertyBag(IPersistPropertyBag *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, AVICompressor, IPersistPropertyBag_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AVICompressorPropertyBag_QueryInterface(IPersistPropertyBag *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
AVICompressor *This = impl_from_IPersistPropertyBag(iface);
|
|
|
|
return IBaseFilter_QueryInterface(&This->filter.IBaseFilter_iface, riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI AVICompressorPropertyBag_AddRef(IPersistPropertyBag *iface)
|
|
|
|
{
|
|
|
|
AVICompressor *This = impl_from_IPersistPropertyBag(iface);
|
|
|
|
return IBaseFilter_AddRef(&This->filter.IBaseFilter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI AVICompressorPropertyBag_Release(IPersistPropertyBag *iface)
|
|
|
|
{
|
|
|
|
AVICompressor *This = impl_from_IPersistPropertyBag(iface);
|
|
|
|
return IBaseFilter_Release(&This->filter.IBaseFilter_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AVICompressorPropertyBag_GetClassID(IPersistPropertyBag *iface, CLSID *pClassID)
|
|
|
|
{
|
|
|
|
AVICompressor *This = impl_from_IPersistPropertyBag(iface);
|
|
|
|
return IBaseFilter_GetClassID(&This->filter.IBaseFilter_iface, pClassID);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AVICompressorPropertyBag_InitNew(IPersistPropertyBag *iface)
|
|
|
|
{
|
|
|
|
AVICompressor *This = impl_from_IPersistPropertyBag(iface);
|
|
|
|
FIXME("(%p)->()\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AVICompressorPropertyBag_Load(IPersistPropertyBag *iface, IPropertyBag *pPropBag, IErrorLog *pErrorLog)
|
|
|
|
{
|
|
|
|
AVICompressor *This = impl_from_IPersistPropertyBag(iface);
|
2013-12-30 20:21:36 +01:00
|
|
|
BSTR str;
|
|
|
|
VARIANT v;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p %p)\n", This, pPropBag, pErrorLog);
|
|
|
|
|
2019-04-09 01:02:35 +02:00
|
|
|
V_VT(&v) = VT_BSTR;
|
2020-11-27 05:34:35 +01:00
|
|
|
hres = IPropertyBag_Read(pPropBag, L"FccHandler", &v, NULL);
|
2013-12-30 20:21:36 +01:00
|
|
|
if(FAILED(hres)) {
|
2022-02-09 03:04:42 +01:00
|
|
|
ERR("Failed to read FccHandler value, hr %#lx.\n", hres);
|
2013-12-30 20:21:36 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(V_VT(&v) != VT_BSTR) {
|
|
|
|
FIXME("Got vt %d\n", V_VT(&v));
|
|
|
|
VariantClear(&v);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
str = V_BSTR(&v);
|
|
|
|
TRACE("FccHandler = %s\n", debugstr_w(str));
|
|
|
|
if(SysStringLen(str) != 4) {
|
|
|
|
FIXME("Invalid FccHandler len\n");
|
|
|
|
SysFreeString(str);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
This->fcc_handler = FCC(str[0], str[1], str[2], str[3]);
|
|
|
|
SysFreeString(str);
|
|
|
|
return S_OK;
|
2013-12-30 16:37:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI AVICompressorPropertyBag_Save(IPersistPropertyBag *iface, IPropertyBag *pPropBag,
|
|
|
|
BOOL fClearDirty, BOOL fSaveAllProperties)
|
|
|
|
{
|
|
|
|
AVICompressor *This = impl_from_IPersistPropertyBag(iface);
|
|
|
|
FIXME("(%p)->(%p %x %x)\n", This, pPropBag, fClearDirty, fSaveAllProperties);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IPersistPropertyBagVtbl PersistPropertyBagVtbl = {
|
|
|
|
AVICompressorPropertyBag_QueryInterface,
|
|
|
|
AVICompressorPropertyBag_AddRef,
|
|
|
|
AVICompressorPropertyBag_Release,
|
|
|
|
AVICompressorPropertyBag_GetClassID,
|
|
|
|
AVICompressorPropertyBag_InitNew,
|
|
|
|
AVICompressorPropertyBag_Load,
|
|
|
|
AVICompressorPropertyBag_Save
|
|
|
|
};
|
|
|
|
|
2019-09-25 02:10:10 +02:00
|
|
|
static HRESULT sink_query_accept(struct strmbase_pin *base, const AM_MEDIA_TYPE *pmt)
|
2013-12-30 16:38:03 +01:00
|
|
|
{
|
2019-09-24 02:33:24 +02:00
|
|
|
AVICompressor *This = impl_from_strmbase_pin(base);
|
2013-12-30 20:21:47 +01:00
|
|
|
VIDEOINFOHEADER *videoinfo;
|
|
|
|
HRESULT hres;
|
|
|
|
DWORD res;
|
|
|
|
|
|
|
|
TRACE("(%p)->(AM_MEDIA_TYPE(%p))\n", base, pmt);
|
|
|
|
|
|
|
|
if(!IsEqualIID(&pmt->majortype, &MEDIATYPE_Video))
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
if(!IsEqualIID(&pmt->formattype, &FORMAT_VideoInfo)) {
|
|
|
|
FIXME("formattype %s unsupported\n", debugstr_guid(&pmt->formattype));
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = ensure_driver(This);
|
|
|
|
if(hres != S_OK)
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
videoinfo = (VIDEOINFOHEADER*)pmt->pbFormat;
|
|
|
|
res = ICCompressQuery(This->hic, &videoinfo->bmiHeader, NULL);
|
|
|
|
return res == ICERR_OK ? S_OK : S_FALSE;
|
2013-12-30 16:38:03 +01:00
|
|
|
}
|
|
|
|
|
2019-09-26 05:36:25 +02:00
|
|
|
static HRESULT sink_query_interface(struct strmbase_pin *iface, REFIID iid, void **out)
|
|
|
|
{
|
|
|
|
AVICompressor *filter = impl_from_strmbase_pin(iface);
|
|
|
|
|
|
|
|
if (IsEqualGUID(iid, &IID_IMemInputPin))
|
|
|
|
*out = &filter->sink.IMemInputPin_iface;
|
|
|
|
else
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown *)*out);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-11-20 03:18:01 +01:00
|
|
|
static HRESULT WINAPI AVICompressorIn_Receive(struct strmbase_sink *base, IMediaSample *pSample)
|
2013-12-30 16:38:03 +01:00
|
|
|
{
|
2019-09-24 02:33:24 +02:00
|
|
|
AVICompressor *This = impl_from_strmbase_pin(&base->pin);
|
2019-11-27 00:39:16 +01:00
|
|
|
IMemInputPin *meminput = This->source.pMemInputPin;
|
2014-01-02 15:29:01 +01:00
|
|
|
VIDEOINFOHEADER *src_videoinfo;
|
|
|
|
REFERENCE_TIME start, stop;
|
|
|
|
IMediaSample *out_sample;
|
|
|
|
AM_MEDIA_TYPE *mt;
|
|
|
|
IMediaSample2 *sample2;
|
|
|
|
DWORD comp_flags = 0;
|
|
|
|
BOOL is_preroll;
|
|
|
|
BOOL sync_point;
|
|
|
|
BYTE *ptr, *buf;
|
2022-02-09 03:04:42 +01:00
|
|
|
LRESULT res;
|
2014-01-02 15:29:01 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", base, pSample);
|
|
|
|
|
2019-11-27 00:39:16 +01:00
|
|
|
if (!meminput)
|
|
|
|
{
|
|
|
|
WARN("Source is not connected, returning VFW_E_NOT_CONNECTED.\n");
|
|
|
|
return VFW_E_NOT_CONNECTED;
|
|
|
|
}
|
|
|
|
|
2014-01-02 15:29:01 +01:00
|
|
|
if(!This->hic) {
|
|
|
|
FIXME("Driver not loaded\n");
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IMediaSample_QueryInterface(pSample, &IID_IMediaSample2, (void**)&sample2);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
FIXME("Use IMediaSample2\n");
|
|
|
|
IMediaSample2_Release(sample2);
|
|
|
|
}
|
|
|
|
|
|
|
|
is_preroll = IMediaSample_IsPreroll(pSample) == S_OK;
|
|
|
|
sync_point = IMediaSample_IsSyncPoint(pSample) == S_OK;
|
|
|
|
|
|
|
|
hres = IMediaSample_GetTime(pSample, &start, &stop);
|
|
|
|
if(FAILED(hres)) {
|
2022-02-09 03:04:42 +01:00
|
|
|
WARN("Failed to get sample time, hr %#lx.\n", hres);
|
2014-01-02 15:29:01 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IMediaSample_GetMediaType(pSample, &mt);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = IMediaSample_GetPointer(pSample, &ptr);
|
|
|
|
if(FAILED(hres)) {
|
2022-02-09 03:04:42 +01:00
|
|
|
ERR("Failed to get input buffer pointer, hr %#lx.\n", hres);
|
2014-01-02 15:29:01 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2022-02-07 03:59:42 +01:00
|
|
|
if (FAILED(hres = IMemAllocator_GetBuffer(This->source.pAllocator, &out_sample, &start, &stop, 0)))
|
|
|
|
{
|
2022-02-09 03:04:42 +01:00
|
|
|
ERR("Failed to get sample, hr %#lx.\n", hres);
|
2014-01-02 15:29:01 +01:00
|
|
|
return hres;
|
2022-02-07 03:59:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hres = IMediaSample_SetTime(out_sample, &start, &stop)))
|
2022-02-09 03:04:42 +01:00
|
|
|
ERR("Failed to set time, hr %#lx.\n", hres);
|
2014-01-02 15:29:01 +01:00
|
|
|
|
|
|
|
hres = IMediaSample_GetPointer(out_sample, &buf);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if((This->driver_flags & VIDCF_TEMPORAL) && !(This->driver_flags & VIDCF_FASTTEMPORALC))
|
|
|
|
FIXME("Unsupported temporal compression\n");
|
|
|
|
|
2019-11-19 01:51:20 +01:00
|
|
|
src_videoinfo = (VIDEOINFOHEADER *)This->sink.pin.mt.pbFormat;
|
2014-04-08 14:25:52 +02:00
|
|
|
This->videoinfo->bmiHeader.biSizeImage = This->max_frame_size;
|
2014-01-02 15:29:01 +01:00
|
|
|
res = ICCompress(This->hic, sync_point ? ICCOMPRESS_KEYFRAME : 0, &This->videoinfo->bmiHeader, buf,
|
|
|
|
&src_videoinfo->bmiHeader, ptr, 0, &comp_flags, This->frame_cnt, 0, 0, NULL, NULL);
|
|
|
|
if(res != ICERR_OK) {
|
2022-02-09 03:04:42 +01:00
|
|
|
ERR("Failed to compress frame, error %Id.\n", res);
|
2014-01-02 15:29:01 +01:00
|
|
|
IMediaSample_Release(out_sample);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMediaSample_SetActualDataLength(out_sample, This->videoinfo->bmiHeader.biSizeImage);
|
|
|
|
IMediaSample_SetPreroll(out_sample, is_preroll);
|
|
|
|
IMediaSample_SetSyncPoint(out_sample, (comp_flags&AVIIF_KEYFRAME) != 0);
|
|
|
|
IMediaSample_SetDiscontinuity(out_sample, (IMediaSample_IsDiscontinuity(pSample) == S_OK));
|
|
|
|
|
|
|
|
if (IMediaSample_GetMediaTime(pSample, &start, &stop) == S_OK)
|
|
|
|
IMediaSample_SetMediaTime(out_sample, &start, &stop);
|
|
|
|
else
|
|
|
|
IMediaSample_SetMediaTime(out_sample, NULL, NULL);
|
|
|
|
|
2019-11-27 00:39:16 +01:00
|
|
|
hres = IMemInputPin_Receive(meminput, out_sample);
|
2014-01-02 15:29:01 +01:00
|
|
|
if(FAILED(hres))
|
2022-02-09 03:04:42 +01:00
|
|
|
WARN("Failed to deliver sample, hr %#lx.\n", hres);
|
2014-01-02 15:29:01 +01:00
|
|
|
|
|
|
|
IMediaSample_Release(out_sample);
|
|
|
|
This->frame_cnt++;
|
|
|
|
return hres;
|
2013-12-30 16:38:03 +01:00
|
|
|
}
|
|
|
|
|
2019-12-11 04:53:36 +01:00
|
|
|
static HRESULT sink_connect(struct strmbase_sink *iface, IPin *peer, const AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
|
|
|
AVICompressor *filter = impl_from_strmbase_pin(&iface->pin);
|
|
|
|
return fill_format_info(filter, (VIDEOINFOHEADER *)mt->pbFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sink_disconnect(struct strmbase_sink *iface)
|
|
|
|
{
|
|
|
|
AVICompressor *filter = impl_from_strmbase_pin(&iface->pin);
|
2020-11-27 05:34:36 +01:00
|
|
|
free(filter->videoinfo);
|
2019-12-11 04:53:36 +01:00
|
|
|
filter->videoinfo = NULL;
|
|
|
|
}
|
|
|
|
|
2019-11-20 03:18:02 +01:00
|
|
|
static const struct strmbase_sink_ops sink_ops =
|
2019-09-25 02:10:10 +02:00
|
|
|
{
|
|
|
|
.base.pin_query_accept = sink_query_accept,
|
2019-09-26 05:36:25 +02:00
|
|
|
.base.pin_query_interface = sink_query_interface,
|
2019-09-25 02:10:10 +02:00
|
|
|
.pfnReceive = AVICompressorIn_Receive,
|
2019-12-11 04:53:36 +01:00
|
|
|
.sink_connect = sink_connect,
|
|
|
|
.sink_disconnect = sink_disconnect,
|
2013-12-30 16:38:03 +01:00
|
|
|
};
|
|
|
|
|
2019-09-25 02:10:12 +02:00
|
|
|
static HRESULT source_get_media_type(struct strmbase_pin *base, unsigned int iPosition, AM_MEDIA_TYPE *amt)
|
2013-12-30 16:38:18 +01:00
|
|
|
{
|
2019-09-06 02:02:15 +02:00
|
|
|
AVICompressor *This = impl_from_strmbase_filter(base->filter);
|
2013-12-30 20:22:07 +01:00
|
|
|
|
|
|
|
if(iPosition || !This->videoinfo)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
amt->majortype = MEDIATYPE_Video;
|
|
|
|
amt->subtype = MEDIASUBTYPE_PCM;
|
|
|
|
amt->bFixedSizeSamples = FALSE;
|
|
|
|
amt->bTemporalCompression = (This->driver_flags & VIDCF_TEMPORAL) != 0;
|
2019-11-19 01:51:20 +01:00
|
|
|
amt->lSampleSize = This->sink.pin.mt.lSampleSize;
|
2013-12-30 20:22:07 +01:00
|
|
|
amt->formattype = FORMAT_VideoInfo;
|
|
|
|
amt->pUnk = NULL;
|
|
|
|
amt->cbFormat = This->videoinfo_size;
|
|
|
|
amt->pbFormat = (BYTE*)This->videoinfo;
|
|
|
|
return S_OK;
|
2013-12-30 16:38:18 +01:00
|
|
|
}
|
|
|
|
|
2019-09-12 21:28:25 +02:00
|
|
|
static HRESULT WINAPI AVICompressorOut_DecideBufferSize(struct strmbase_source *base,
|
|
|
|
IMemAllocator *alloc, ALLOCATOR_PROPERTIES *ppropInputRequest)
|
2013-12-30 16:38:18 +01:00
|
|
|
{
|
2019-09-24 02:33:24 +02:00
|
|
|
AVICompressor *This = impl_from_strmbase_pin(&base->pin);
|
2013-12-30 20:22:17 +01:00
|
|
|
ALLOCATOR_PROPERTIES actual;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
if (!ppropInputRequest->cBuffers)
|
|
|
|
ppropInputRequest->cBuffers = 1;
|
2014-04-08 14:25:52 +02:00
|
|
|
if (ppropInputRequest->cbBuffer < This->max_frame_size)
|
|
|
|
ppropInputRequest->cbBuffer = This->max_frame_size;
|
2013-12-30 20:22:17 +01:00
|
|
|
if (!ppropInputRequest->cbAlign)
|
|
|
|
ppropInputRequest->cbAlign = 1;
|
|
|
|
|
|
|
|
return IMemAllocator_SetProperties(alloc, ppropInputRequest, &actual);
|
2013-12-30 16:38:18 +01:00
|
|
|
}
|
|
|
|
|
2019-09-12 21:28:25 +02:00
|
|
|
static HRESULT WINAPI AVICompressorOut_DecideAllocator(struct strmbase_source *base,
|
2013-12-30 16:38:18 +01:00
|
|
|
IMemInputPin *pPin, IMemAllocator **pAlloc)
|
|
|
|
{
|
|
|
|
TRACE("(%p)->(%p %p)\n", base, pPin, pAlloc);
|
|
|
|
return BaseOutputPinImpl_DecideAllocator(base, pPin, pAlloc);
|
|
|
|
}
|
|
|
|
|
2019-09-12 21:28:26 +02:00
|
|
|
static const struct strmbase_source_ops source_ops =
|
|
|
|
{
|
2019-09-25 02:10:11 +02:00
|
|
|
.base.pin_get_media_type = source_get_media_type,
|
|
|
|
.pfnAttemptConnection = BaseOutputPinImpl_AttemptConnection,
|
|
|
|
.pfnDecideBufferSize = AVICompressorOut_DecideBufferSize,
|
|
|
|
.pfnDecideAllocator = AVICompressorOut_DecideAllocator,
|
2013-12-30 16:38:18 +01:00
|
|
|
};
|
|
|
|
|
2020-03-08 20:05:08 +01:00
|
|
|
HRESULT avi_compressor_create(IUnknown *outer, IUnknown **out)
|
2013-12-19 15:31:52 +01:00
|
|
|
{
|
2020-03-08 20:05:08 +01:00
|
|
|
AVICompressor *object;
|
2013-12-19 15:31:52 +01:00
|
|
|
|
2020-11-27 05:34:36 +01:00
|
|
|
if (!(object = calloc(1, sizeof(*object))))
|
2020-03-08 20:05:08 +01:00
|
|
|
return E_OUTOFMEMORY;
|
2013-12-19 15:31:52 +01:00
|
|
|
|
2020-03-08 20:05:08 +01:00
|
|
|
strmbase_filter_init(&object->filter, outer, &CLSID_AVICo, &filter_ops);
|
|
|
|
object->IPersistPropertyBag_iface.lpVtbl = &PersistPropertyBagVtbl;
|
2013-12-30 16:37:47 +01:00
|
|
|
|
2020-11-27 05:34:35 +01:00
|
|
|
strmbase_sink_init(&object->sink, &object->filter, L"In", &sink_ops, NULL);
|
|
|
|
strmbase_source_init(&object->source, &object->filter, L"Out", &source_ops);
|
2013-12-30 16:38:18 +01:00
|
|
|
|
2020-03-08 20:05:08 +01:00
|
|
|
TRACE("Created AVI compressor %p.\n", object);
|
|
|
|
*out = &object->filter.IUnknown_inner;
|
|
|
|
return S_OK;
|
2013-12-19 15:31:52 +01:00
|
|
|
}
|