2010-10-07 21:47:33 +02:00
|
|
|
/*
|
|
|
|
* Generic Implementation of IBaseFilter Interface
|
|
|
|
*
|
|
|
|
* Copyright 2010 Aric Stewart, 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
|
|
|
|
*/
|
|
|
|
|
2019-05-09 17:12:32 +02:00
|
|
|
#include "strmbase_private.h"
|
2010-10-07 21:47:33 +02:00
|
|
|
|
2021-07-11 02:22:22 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(quartz);
|
2010-10-07 21:47:33 +02:00
|
|
|
|
2020-01-29 06:36:53 +01:00
|
|
|
struct enum_pins
|
|
|
|
{
|
|
|
|
IEnumPins IEnumPins_iface;
|
|
|
|
LONG refcount;
|
|
|
|
|
|
|
|
unsigned int index, count;
|
|
|
|
int version;
|
|
|
|
struct strmbase_filter *filter;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const IEnumPinsVtbl enum_pins_vtbl;
|
|
|
|
|
|
|
|
static HRESULT enum_pins_create(struct strmbase_filter *filter, IEnumPins **out)
|
|
|
|
{
|
|
|
|
struct enum_pins *object;
|
|
|
|
|
|
|
|
if (!out)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
if (!(object = heap_alloc_zero(sizeof(*object))))
|
|
|
|
{
|
|
|
|
*out = NULL;
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
object->IEnumPins_iface.lpVtbl = &enum_pins_vtbl;
|
|
|
|
object->refcount = 1;
|
|
|
|
object->filter = filter;
|
|
|
|
IBaseFilter_AddRef(&filter->IBaseFilter_iface);
|
|
|
|
object->version = filter->pin_version;
|
|
|
|
|
|
|
|
while (filter->ops->filter_get_pin(filter, object->count))
|
|
|
|
++object->count;
|
|
|
|
|
|
|
|
TRACE("Created enumerator %p.\n", object);
|
|
|
|
*out = &object->IEnumPins_iface;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct enum_pins *impl_from_IEnumPins(IEnumPins *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct enum_pins, IEnumPins_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enum_pins_QueryInterface(IEnumPins *iface, REFIID iid, void **out)
|
|
|
|
{
|
|
|
|
TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
|
|
|
|
|
|
|
|
if (IsEqualGUID(iid, &IID_IUnknown) || IsEqualGUID(iid, &IID_IEnumPins))
|
|
|
|
{
|
|
|
|
IEnumPins_AddRef(iface);
|
|
|
|
*out = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
|
|
|
|
*out = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI enum_pins_AddRef(IEnumPins *iface)
|
|
|
|
{
|
|
|
|
struct enum_pins *enum_pins = impl_from_IEnumPins(iface);
|
|
|
|
ULONG refcount = InterlockedIncrement(&enum_pins->refcount);
|
|
|
|
TRACE("%p increasing refcount to %u.\n", enum_pins, refcount);
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI enum_pins_Release(IEnumPins *iface)
|
|
|
|
{
|
|
|
|
struct enum_pins *enum_pins = impl_from_IEnumPins(iface);
|
|
|
|
ULONG refcount = InterlockedDecrement(&enum_pins->refcount);
|
|
|
|
|
|
|
|
TRACE("%p decreasing refcount to %u.\n", enum_pins, refcount);
|
|
|
|
if (!refcount)
|
|
|
|
{
|
|
|
|
IBaseFilter_Release(&enum_pins->filter->IBaseFilter_iface);
|
|
|
|
heap_free(enum_pins);
|
|
|
|
}
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enum_pins_Next(IEnumPins *iface, ULONG count, IPin **pins, ULONG *ret_count)
|
|
|
|
{
|
|
|
|
struct enum_pins *enum_pins = impl_from_IEnumPins(iface);
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
TRACE("iface %p, count %u, pins %p, ret_count %p.\n", iface, count, pins, ret_count);
|
|
|
|
|
|
|
|
if (!pins)
|
|
|
|
return E_POINTER;
|
|
|
|
|
|
|
|
if (count > 1 && !ret_count)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if (ret_count)
|
|
|
|
*ret_count = 0;
|
|
|
|
|
|
|
|
if (enum_pins->version != enum_pins->filter->pin_version)
|
2020-01-29 06:36:54 +01:00
|
|
|
return S_FALSE;
|
2020-01-29 06:36:53 +01:00
|
|
|
|
|
|
|
for (i = 0; i < count; ++i)
|
|
|
|
{
|
|
|
|
struct strmbase_pin *pin = enum_pins->filter->ops->filter_get_pin(enum_pins->filter, enum_pins->index + i);
|
|
|
|
|
|
|
|
if (!pin)
|
|
|
|
break;
|
|
|
|
|
|
|
|
IPin_AddRef(pins[i] = &pin->IPin_iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret_count)
|
|
|
|
*ret_count = i;
|
|
|
|
enum_pins->index += i;
|
|
|
|
return i == count ? S_OK : S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enum_pins_Skip(IEnumPins *iface, ULONG count)
|
|
|
|
{
|
|
|
|
struct enum_pins *enum_pins = impl_from_IEnumPins(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p, count %u.\n", iface, count);
|
|
|
|
|
|
|
|
if (enum_pins->version != enum_pins->filter->pin_version)
|
|
|
|
return VFW_E_ENUM_OUT_OF_SYNC;
|
|
|
|
|
|
|
|
if (enum_pins->index + count > enum_pins->count)
|
|
|
|
return S_FALSE;
|
|
|
|
|
|
|
|
enum_pins->index += count;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enum_pins_Reset(IEnumPins *iface)
|
|
|
|
{
|
|
|
|
struct enum_pins *enum_pins = impl_from_IEnumPins(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p.\n", iface);
|
|
|
|
|
|
|
|
if (enum_pins->version != enum_pins->filter->pin_version)
|
|
|
|
{
|
|
|
|
enum_pins->count = 0;
|
|
|
|
while (enum_pins->filter->ops->filter_get_pin(enum_pins->filter, enum_pins->count))
|
|
|
|
++enum_pins->count;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum_pins->version = enum_pins->filter->pin_version;
|
|
|
|
enum_pins->index = 0;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI enum_pins_Clone(IEnumPins *iface, IEnumPins **out)
|
|
|
|
{
|
|
|
|
struct enum_pins *enum_pins = impl_from_IEnumPins(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("iface %p, out %p.\n", iface, out);
|
|
|
|
|
|
|
|
if (FAILED(hr = enum_pins_create(enum_pins->filter, out)))
|
|
|
|
return hr;
|
|
|
|
return IEnumPins_Skip(*out, enum_pins->index);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IEnumPinsVtbl enum_pins_vtbl =
|
|
|
|
{
|
|
|
|
enum_pins_QueryInterface,
|
|
|
|
enum_pins_AddRef,
|
|
|
|
enum_pins_Release,
|
|
|
|
enum_pins_Next,
|
|
|
|
enum_pins_Skip,
|
|
|
|
enum_pins_Reset,
|
|
|
|
enum_pins_Clone,
|
|
|
|
};
|
|
|
|
|
2019-08-29 03:24:30 +02:00
|
|
|
static inline struct strmbase_filter *impl_from_IUnknown(IUnknown *iface)
|
2012-03-24 17:42:27 +01:00
|
|
|
{
|
2019-08-29 03:24:30 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct strmbase_filter, IUnknown_inner);
|
2012-03-24 17:42:27 +01:00
|
|
|
}
|
|
|
|
|
2019-06-04 17:01:17 +02:00
|
|
|
static HRESULT WINAPI filter_inner_QueryInterface(IUnknown *iface, REFIID iid, void **out)
|
2010-10-07 21:47:33 +02:00
|
|
|
{
|
2019-08-29 03:24:30 +02:00
|
|
|
struct strmbase_filter *filter = impl_from_IUnknown(iface);
|
2019-05-30 03:52:56 +02:00
|
|
|
HRESULT hr;
|
2010-10-07 21:47:33 +02:00
|
|
|
|
2020-01-31 02:05:20 +01:00
|
|
|
TRACE("filter %p %s, iid %s, out %p.\n", filter, debugstr_w(filter->name), debugstr_guid(iid), out);
|
2010-10-07 21:47:33 +02:00
|
|
|
|
2019-05-30 03:52:56 +02:00
|
|
|
*out = NULL;
|
|
|
|
|
2019-10-24 03:04:25 +02:00
|
|
|
if (filter->ops->filter_query_interface
|
|
|
|
&& SUCCEEDED(hr = filter->ops->filter_query_interface(filter, iid, out)))
|
2019-05-30 03:52:56 +02:00
|
|
|
{
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2019-06-04 17:01:17 +02:00
|
|
|
if (IsEqualIID(iid, &IID_IUnknown))
|
|
|
|
*out = iface;
|
|
|
|
else if (IsEqualIID(iid, &IID_IPersist)
|
2019-05-30 03:52:56 +02:00
|
|
|
|| IsEqualIID(iid, &IID_IMediaFilter)
|
|
|
|
|| IsEqualIID(iid, &IID_IBaseFilter))
|
2010-10-07 21:47:33 +02:00
|
|
|
{
|
2019-06-04 17:01:17 +02:00
|
|
|
*out = &filter->IBaseFilter_iface;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
|
|
|
|
return E_NOINTERFACE;
|
2010-10-07 21:47:33 +02:00
|
|
|
}
|
|
|
|
|
2019-06-04 17:01:17 +02:00
|
|
|
IUnknown_AddRef((IUnknown *)*out);
|
|
|
|
return S_OK;
|
2010-10-07 21:47:33 +02:00
|
|
|
}
|
|
|
|
|
2019-06-04 17:01:17 +02:00
|
|
|
static ULONG WINAPI filter_inner_AddRef(IUnknown *iface)
|
2010-10-07 21:47:33 +02:00
|
|
|
{
|
2019-08-29 03:24:30 +02:00
|
|
|
struct strmbase_filter *filter = impl_from_IUnknown(iface);
|
2019-06-04 17:01:17 +02:00
|
|
|
ULONG refcount = InterlockedIncrement(&filter->refcount);
|
2010-10-07 21:47:33 +02:00
|
|
|
|
2019-06-04 17:01:17 +02:00
|
|
|
TRACE("%p increasing refcount to %u.\n", filter, refcount);
|
2010-10-07 21:47:33 +02:00
|
|
|
|
2019-06-04 17:01:17 +02:00
|
|
|
return refcount;
|
2010-10-07 21:47:33 +02:00
|
|
|
}
|
|
|
|
|
2019-06-04 17:01:17 +02:00
|
|
|
static ULONG WINAPI filter_inner_Release(IUnknown *iface)
|
2010-10-07 21:47:33 +02:00
|
|
|
{
|
2019-08-29 03:24:30 +02:00
|
|
|
struct strmbase_filter *filter = impl_from_IUnknown(iface);
|
2019-06-04 17:01:17 +02:00
|
|
|
ULONG refcount = InterlockedDecrement(&filter->refcount);
|
|
|
|
|
|
|
|
TRACE("%p decreasing refcount to %u.\n", filter, refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
2019-10-24 03:04:25 +02:00
|
|
|
filter->ops->filter_destroy(filter);
|
2019-06-04 17:01:17 +02:00
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IUnknownVtbl filter_inner_vtbl =
|
|
|
|
{
|
|
|
|
filter_inner_QueryInterface,
|
|
|
|
filter_inner_AddRef,
|
|
|
|
filter_inner_Release,
|
|
|
|
};
|
2010-10-07 21:47:33 +02:00
|
|
|
|
2019-08-29 03:24:30 +02:00
|
|
|
static inline struct strmbase_filter *impl_from_IBaseFilter(IBaseFilter *iface)
|
2019-06-04 17:01:17 +02:00
|
|
|
{
|
2019-08-29 03:24:30 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct strmbase_filter, IBaseFilter_iface);
|
2019-06-04 17:01:17 +02:00
|
|
|
}
|
2010-10-07 21:47:33 +02:00
|
|
|
|
2019-12-05 06:03:31 +01:00
|
|
|
static HRESULT WINAPI filter_QueryInterface(IBaseFilter *iface, REFIID iid, void **out)
|
2019-06-04 17:01:17 +02:00
|
|
|
{
|
2019-08-29 03:24:30 +02:00
|
|
|
struct strmbase_filter *filter = impl_from_IBaseFilter(iface);
|
2019-06-04 17:01:17 +02:00
|
|
|
return IUnknown_QueryInterface(filter->outer_unk, iid, out);
|
|
|
|
}
|
2010-10-07 21:47:33 +02:00
|
|
|
|
2019-12-05 06:03:31 +01:00
|
|
|
static ULONG WINAPI filter_AddRef(IBaseFilter *iface)
|
2019-06-04 17:01:17 +02:00
|
|
|
{
|
2019-08-29 03:24:30 +02:00
|
|
|
struct strmbase_filter *filter = impl_from_IBaseFilter(iface);
|
2019-06-04 17:01:17 +02:00
|
|
|
return IUnknown_AddRef(filter->outer_unk);
|
|
|
|
}
|
|
|
|
|
2019-12-05 06:03:31 +01:00
|
|
|
static ULONG WINAPI filter_Release(IBaseFilter *iface)
|
2019-06-04 17:01:17 +02:00
|
|
|
{
|
2019-08-29 03:24:30 +02:00
|
|
|
struct strmbase_filter *filter = impl_from_IBaseFilter(iface);
|
2019-06-04 17:01:17 +02:00
|
|
|
return IUnknown_Release(filter->outer_unk);
|
2010-10-07 21:47:33 +02:00
|
|
|
}
|
|
|
|
|
2020-01-31 02:05:20 +01:00
|
|
|
static HRESULT WINAPI filter_GetClassID(IBaseFilter *iface, CLSID *clsid)
|
2010-10-07 21:47:33 +02:00
|
|
|
{
|
2020-01-31 02:05:20 +01:00
|
|
|
struct strmbase_filter *filter = impl_from_IBaseFilter(iface);
|
2010-10-07 21:47:33 +02:00
|
|
|
|
2020-01-31 02:05:20 +01:00
|
|
|
TRACE("filter %p %s, clsid %p.\n", filter, debugstr_w(filter->name), clsid);
|
|
|
|
|
|
|
|
*clsid = filter->clsid;
|
2010-10-07 21:47:33 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-12-05 06:03:31 +01:00
|
|
|
static HRESULT WINAPI filter_Stop(IBaseFilter *iface)
|
2019-06-22 05:35:38 +02:00
|
|
|
{
|
2019-08-29 03:24:30 +02:00
|
|
|
struct strmbase_filter *filter = impl_from_IBaseFilter(iface);
|
2019-10-24 03:04:26 +02:00
|
|
|
HRESULT hr = S_OK;
|
2019-06-22 05:35:38 +02:00
|
|
|
|
2020-01-31 02:05:20 +01:00
|
|
|
TRACE("filter %p %s.\n", filter, debugstr_w(filter->name));
|
2019-06-22 05:35:38 +02:00
|
|
|
|
2021-01-19 04:57:19 +01:00
|
|
|
EnterCriticalSection(&filter->filter_cs);
|
2019-10-24 03:04:26 +02:00
|
|
|
|
|
|
|
if (filter->state == State_Running && filter->ops->filter_stop_stream)
|
|
|
|
hr = filter->ops->filter_stop_stream(filter);
|
|
|
|
if (SUCCEEDED(hr) && filter->ops->filter_cleanup_stream)
|
|
|
|
hr = filter->ops->filter_cleanup_stream(filter);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
filter->state = State_Stopped;
|
|
|
|
|
2021-01-19 04:57:19 +01:00
|
|
|
LeaveCriticalSection(&filter->filter_cs);
|
2019-06-22 05:35:38 +02:00
|
|
|
|
2019-10-24 03:04:26 +02:00
|
|
|
return hr;
|
2019-06-22 05:35:38 +02:00
|
|
|
}
|
|
|
|
|
2019-12-05 06:03:31 +01:00
|
|
|
static HRESULT WINAPI filter_Pause(IBaseFilter *iface)
|
2019-06-22 05:35:38 +02:00
|
|
|
{
|
2019-08-29 03:24:30 +02:00
|
|
|
struct strmbase_filter *filter = impl_from_IBaseFilter(iface);
|
2019-10-24 03:04:26 +02:00
|
|
|
HRESULT hr = S_OK;
|
2019-06-22 05:35:38 +02:00
|
|
|
|
2020-01-31 02:05:20 +01:00
|
|
|
TRACE("filter %p %s.\n", filter, debugstr_w(filter->name));
|
2019-06-22 05:35:38 +02:00
|
|
|
|
2021-01-19 04:57:19 +01:00
|
|
|
EnterCriticalSection(&filter->filter_cs);
|
2019-10-24 03:04:26 +02:00
|
|
|
|
|
|
|
if (filter->state == State_Stopped && filter->ops->filter_init_stream)
|
|
|
|
hr = filter->ops->filter_init_stream(filter);
|
|
|
|
else if (filter->state == State_Running && filter->ops->filter_stop_stream)
|
|
|
|
hr = filter->ops->filter_stop_stream(filter);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
filter->state = State_Paused;
|
|
|
|
|
2021-01-19 04:57:19 +01:00
|
|
|
LeaveCriticalSection(&filter->filter_cs);
|
2019-06-22 05:35:38 +02:00
|
|
|
|
2019-10-24 03:04:26 +02:00
|
|
|
return hr;
|
2019-06-22 05:35:38 +02:00
|
|
|
}
|
|
|
|
|
2019-12-05 06:03:31 +01:00
|
|
|
static HRESULT WINAPI filter_Run(IBaseFilter *iface, REFERENCE_TIME start)
|
2019-06-22 05:35:38 +02:00
|
|
|
{
|
2019-08-29 03:24:30 +02:00
|
|
|
struct strmbase_filter *filter = impl_from_IBaseFilter(iface);
|
2019-10-24 03:04:26 +02:00
|
|
|
HRESULT hr = S_OK;
|
2019-06-22 05:35:38 +02:00
|
|
|
|
2020-01-31 02:05:20 +01:00
|
|
|
TRACE("filter %p %s, start %s.\n", filter, debugstr_w(filter->name), debugstr_time(start));
|
2019-06-22 05:35:38 +02:00
|
|
|
|
2021-01-19 04:57:19 +01:00
|
|
|
EnterCriticalSection(&filter->filter_cs);
|
2019-10-24 03:04:26 +02:00
|
|
|
|
|
|
|
if (filter->state == State_Stopped && filter->ops->filter_init_stream)
|
|
|
|
hr = filter->ops->filter_init_stream(filter);
|
|
|
|
if (SUCCEEDED(hr) && filter->ops->filter_start_stream)
|
|
|
|
hr = filter->ops->filter_start_stream(filter, start);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
filter->state = State_Running;
|
|
|
|
|
2021-01-19 04:57:19 +01:00
|
|
|
LeaveCriticalSection(&filter->filter_cs);
|
2019-06-22 05:35:38 +02:00
|
|
|
|
2019-10-24 03:04:26 +02:00
|
|
|
return hr;
|
2019-06-22 05:35:38 +02:00
|
|
|
}
|
|
|
|
|
2019-12-05 06:03:31 +01:00
|
|
|
static HRESULT WINAPI filter_GetState(IBaseFilter *iface, DWORD timeout, FILTER_STATE *state)
|
2010-10-07 21:47:33 +02:00
|
|
|
{
|
2019-10-24 03:04:26 +02:00
|
|
|
struct strmbase_filter *filter = impl_from_IBaseFilter(iface);
|
|
|
|
HRESULT hr = S_OK;
|
2010-10-07 21:47:33 +02:00
|
|
|
|
2020-01-31 02:05:20 +01:00
|
|
|
TRACE("filter %p %s, timeout %u, state %p.\n", filter, debugstr_w(filter->name), timeout, state);
|
2010-10-07 21:47:33 +02:00
|
|
|
|
2021-01-19 04:57:19 +01:00
|
|
|
EnterCriticalSection(&filter->filter_cs);
|
2019-10-24 03:04:26 +02:00
|
|
|
|
|
|
|
if (filter->ops->filter_wait_state)
|
|
|
|
hr = filter->ops->filter_wait_state(filter, timeout);
|
|
|
|
*state = filter->state;
|
|
|
|
|
2021-01-19 04:57:19 +01:00
|
|
|
LeaveCriticalSection(&filter->filter_cs);
|
2019-10-24 03:04:26 +02:00
|
|
|
|
|
|
|
return hr;
|
2010-10-07 21:47:33 +02:00
|
|
|
}
|
|
|
|
|
2020-01-31 02:05:19 +01:00
|
|
|
static HRESULT WINAPI filter_SetSyncSource(IBaseFilter *iface, IReferenceClock *clock)
|
2010-10-07 21:47:33 +02:00
|
|
|
{
|
2020-01-31 02:05:19 +01:00
|
|
|
struct strmbase_filter *filter = impl_from_IBaseFilter(iface);
|
2010-10-07 21:47:33 +02:00
|
|
|
|
2020-01-31 02:05:20 +01:00
|
|
|
TRACE("filter %p %s, clock %p.\n", filter, debugstr_w(filter->name), clock);
|
2020-01-31 02:05:19 +01:00
|
|
|
|
2021-01-19 04:57:19 +01:00
|
|
|
EnterCriticalSection(&filter->filter_cs);
|
2020-01-31 02:05:19 +01:00
|
|
|
|
|
|
|
if (filter->clock)
|
|
|
|
IReferenceClock_Release(filter->clock);
|
|
|
|
filter->clock = clock;
|
|
|
|
if (filter->clock)
|
|
|
|
IReferenceClock_AddRef(filter->clock);
|
|
|
|
|
2021-01-19 04:57:19 +01:00
|
|
|
LeaveCriticalSection(&filter->filter_cs);
|
2010-10-07 21:47:33 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-01-31 02:05:19 +01:00
|
|
|
static HRESULT WINAPI filter_GetSyncSource(IBaseFilter *iface, IReferenceClock **clock)
|
2010-10-07 21:47:33 +02:00
|
|
|
{
|
2020-01-31 02:05:19 +01:00
|
|
|
struct strmbase_filter *filter = impl_from_IBaseFilter(iface);
|
2010-10-07 21:47:33 +02:00
|
|
|
|
2020-01-31 02:05:20 +01:00
|
|
|
TRACE("filter %p %s, clock %p.\n", filter, debugstr_w(filter->name), clock);
|
2020-01-31 02:05:19 +01:00
|
|
|
|
2021-01-19 04:57:19 +01:00
|
|
|
EnterCriticalSection(&filter->filter_cs);
|
2020-01-31 02:05:19 +01:00
|
|
|
|
|
|
|
*clock = filter->clock;
|
|
|
|
if (filter->clock)
|
|
|
|
IReferenceClock_AddRef(filter->clock);
|
|
|
|
|
2021-01-19 04:57:19 +01:00
|
|
|
LeaveCriticalSection(&filter->filter_cs);
|
2010-10-07 21:47:33 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-12-05 06:03:31 +01:00
|
|
|
static HRESULT WINAPI filter_EnumPins(IBaseFilter *iface, IEnumPins **enum_pins)
|
2010-10-07 21:48:01 +02:00
|
|
|
{
|
2019-08-29 03:24:30 +02:00
|
|
|
struct strmbase_filter *filter = impl_from_IBaseFilter(iface);
|
2010-10-07 21:48:01 +02:00
|
|
|
|
2020-01-31 02:05:20 +01:00
|
|
|
TRACE("filter %p %s, enum_pins %p.\n", filter, debugstr_w(filter->name), enum_pins);
|
2010-10-07 21:48:01 +02:00
|
|
|
|
2019-05-14 05:17:54 +02:00
|
|
|
return enum_pins_create(filter, enum_pins);
|
2010-10-07 21:48:01 +02:00
|
|
|
}
|
|
|
|
|
2019-12-05 06:03:31 +01:00
|
|
|
static HRESULT WINAPI filter_FindPin(IBaseFilter *iface, const WCHAR *id, IPin **ret)
|
2018-07-03 23:56:51 +02:00
|
|
|
{
|
2020-01-31 02:05:20 +01:00
|
|
|
struct strmbase_filter *filter = impl_from_IBaseFilter(iface);
|
2019-11-23 04:13:59 +01:00
|
|
|
struct strmbase_pin *pin;
|
2019-05-24 00:06:30 +02:00
|
|
|
unsigned int i;
|
2018-07-03 23:56:51 +02:00
|
|
|
|
2020-01-31 02:05:20 +01:00
|
|
|
TRACE("filter %p %s, id %s, ret %p.\n", filter, debugstr_w(filter->name), debugstr_w(id), ret);
|
2018-07-03 23:56:51 +02:00
|
|
|
|
2020-01-31 02:05:20 +01:00
|
|
|
for (i = 0; (pin = filter->ops->filter_get_pin(filter, i)); ++i)
|
2018-07-03 23:56:51 +02:00
|
|
|
{
|
2019-11-23 04:13:59 +01:00
|
|
|
if (!lstrcmpW(id, pin->name))
|
2018-07-03 23:56:51 +02:00
|
|
|
{
|
2019-11-23 04:13:59 +01:00
|
|
|
IPin_AddRef(*ret = &pin->IPin_iface);
|
2018-07-03 23:56:51 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return VFW_E_NOT_FOUND;
|
|
|
|
}
|
2010-10-07 21:48:01 +02:00
|
|
|
|
2020-01-31 02:05:18 +01:00
|
|
|
static HRESULT WINAPI filter_QueryFilterInfo(IBaseFilter *iface, FILTER_INFO *info)
|
2010-10-07 21:47:33 +02:00
|
|
|
{
|
2020-01-31 02:05:18 +01:00
|
|
|
struct strmbase_filter *filter = impl_from_IBaseFilter(iface);
|
2010-10-07 21:47:33 +02:00
|
|
|
|
2020-01-31 02:05:20 +01:00
|
|
|
TRACE("filter %p %s, info %p.\n", filter, debugstr_w(filter->name), info);
|
2010-10-07 21:47:33 +02:00
|
|
|
|
2020-01-31 02:05:18 +01:00
|
|
|
lstrcpyW(info->achName, filter->name);
|
|
|
|
info->pGraph = filter->graph;
|
|
|
|
|
|
|
|
if (info->pGraph)
|
|
|
|
IFilterGraph_AddRef(info->pGraph);
|
2010-10-07 21:47:33 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2020-01-31 02:05:18 +01:00
|
|
|
static HRESULT WINAPI filter_JoinFilterGraph(IBaseFilter *iface, IFilterGraph *graph, const WCHAR *name)
|
2010-10-07 21:47:33 +02:00
|
|
|
{
|
2020-01-31 02:05:18 +01:00
|
|
|
struct strmbase_filter *filter = impl_from_IBaseFilter(iface);
|
2010-10-07 21:47:33 +02:00
|
|
|
|
2020-01-31 02:05:20 +01:00
|
|
|
TRACE("filter %p %s, graph %p, name %s.\n", filter, debugstr_w(filter->name), graph, debugstr_w(name));
|
2010-10-07 21:47:33 +02:00
|
|
|
|
2021-01-19 04:57:19 +01:00
|
|
|
EnterCriticalSection(&filter->filter_cs);
|
2020-01-31 02:05:18 +01:00
|
|
|
|
|
|
|
if (name)
|
|
|
|
lstrcpynW(filter->name, name, ARRAY_SIZE(filter->name));
|
|
|
|
else
|
|
|
|
filter->name[0] = 0;
|
|
|
|
/* The graph references us, so we cannot also reference the graph. */
|
|
|
|
filter->graph = graph;
|
|
|
|
|
2021-01-19 04:57:19 +01:00
|
|
|
LeaveCriticalSection(&filter->filter_cs);
|
2010-10-07 21:47:33 +02:00
|
|
|
|
2015-10-19 10:57:50 +02:00
|
|
|
return S_OK;
|
2010-10-07 21:47:33 +02:00
|
|
|
}
|
|
|
|
|
2020-01-31 02:05:20 +01:00
|
|
|
static HRESULT WINAPI filter_QueryVendorInfo(IBaseFilter *iface, WCHAR **info)
|
2010-10-07 21:47:33 +02:00
|
|
|
{
|
2020-01-31 02:05:20 +01:00
|
|
|
struct strmbase_filter *filter = impl_from_IBaseFilter(iface);
|
|
|
|
|
|
|
|
TRACE("filter %p %s, info %p.\n", filter, debugstr_w(filter->name), info);
|
|
|
|
|
2010-10-07 21:47:33 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2019-12-05 06:03:31 +01:00
|
|
|
static const IBaseFilterVtbl filter_vtbl =
|
|
|
|
{
|
|
|
|
filter_QueryInterface,
|
|
|
|
filter_AddRef,
|
|
|
|
filter_Release,
|
|
|
|
filter_GetClassID,
|
|
|
|
filter_Stop,
|
|
|
|
filter_Pause,
|
|
|
|
filter_Run,
|
|
|
|
filter_GetState,
|
|
|
|
filter_SetSyncSource,
|
|
|
|
filter_GetSyncSource,
|
|
|
|
filter_EnumPins,
|
|
|
|
filter_FindPin,
|
|
|
|
filter_QueryFilterInfo,
|
|
|
|
filter_JoinFilterGraph,
|
|
|
|
filter_QueryVendorInfo,
|
|
|
|
};
|
|
|
|
|
2019-08-29 03:24:30 +02:00
|
|
|
VOID WINAPI BaseFilterImpl_IncrementPinVersion(struct strmbase_filter *filter)
|
2010-10-07 21:48:01 +02:00
|
|
|
{
|
2019-05-14 05:17:54 +02:00
|
|
|
InterlockedIncrement(&filter->pin_version);
|
2010-10-07 21:48:01 +02:00
|
|
|
}
|
|
|
|
|
2019-12-05 06:03:31 +01:00
|
|
|
void strmbase_filter_init(struct strmbase_filter *filter, IUnknown *outer,
|
2019-10-24 03:04:25 +02:00
|
|
|
const CLSID *clsid, const struct strmbase_filter_ops *ops)
|
2010-10-07 21:47:33 +02:00
|
|
|
{
|
2019-06-04 17:01:17 +02:00
|
|
|
memset(filter, 0, sizeof(*filter));
|
|
|
|
|
2019-12-05 06:03:31 +01:00
|
|
|
filter->IBaseFilter_iface.lpVtbl = &filter_vtbl;
|
2019-06-04 17:01:17 +02:00
|
|
|
filter->IUnknown_inner.lpVtbl = &filter_inner_vtbl;
|
|
|
|
filter->outer_unk = outer ? outer : &filter->IUnknown_inner;
|
|
|
|
filter->refcount = 1;
|
|
|
|
|
2021-01-19 04:57:19 +01:00
|
|
|
InitializeCriticalSection(&filter->filter_cs);
|
|
|
|
if (filter->filter_cs.DebugInfo != (RTL_CRITICAL_SECTION_DEBUG *)-1)
|
|
|
|
filter->filter_cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": strmbase_filter.filter_cs");
|
2021-01-19 04:57:20 +01:00
|
|
|
InitializeCriticalSection(&filter->stream_cs);
|
|
|
|
if (filter->stream_cs.DebugInfo != (RTL_CRITICAL_SECTION_DEBUG *)-1)
|
|
|
|
filter->stream_cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": strmbase_filter.stream_cs");
|
2019-06-04 17:01:17 +02:00
|
|
|
filter->clsid = *clsid;
|
|
|
|
filter->pin_version = 1;
|
2019-10-24 03:04:25 +02:00
|
|
|
filter->ops = ops;
|
2010-10-07 21:47:33 +02:00
|
|
|
}
|
2014-07-18 22:19:40 +02:00
|
|
|
|
2020-06-06 23:03:13 +02:00
|
|
|
void strmbase_filter_cleanup(struct strmbase_filter *filter)
|
2014-07-18 22:19:40 +02:00
|
|
|
{
|
2020-06-06 23:03:13 +02:00
|
|
|
if (filter->clock)
|
|
|
|
IReferenceClock_Release(filter->clock);
|
2014-07-18 22:19:40 +02:00
|
|
|
|
2020-06-06 23:03:13 +02:00
|
|
|
filter->IBaseFilter_iface.lpVtbl = NULL;
|
2021-01-19 04:57:19 +01:00
|
|
|
if (filter->filter_cs.DebugInfo != (RTL_CRITICAL_SECTION_DEBUG *)-1)
|
|
|
|
filter->filter_cs.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection(&filter->filter_cs);
|
2021-01-19 04:57:20 +01:00
|
|
|
if (filter->stream_cs.DebugInfo != (RTL_CRITICAL_SECTION_DEBUG *)-1)
|
|
|
|
filter->stream_cs.DebugInfo->Spare[0] = 0;
|
|
|
|
DeleteCriticalSection(&filter->stream_cs);
|
2014-07-18 22:19:40 +02:00
|
|
|
}
|