2012-03-28 21:53:33 +02:00
|
|
|
/*
|
|
|
|
* Generic Implementation of strmbase Base Renderer classes
|
|
|
|
*
|
|
|
|
* Copyright 2012 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
|
|
|
|
*/
|
|
|
|
|
2012-04-02 14:52:15 +02:00
|
|
|
#include "strmbase_private.h"
|
2012-03-28 21:53:33 +02:00
|
|
|
|
2021-07-11 02:22:22 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(quartz);
|
2012-03-28 21:53:33 +02:00
|
|
|
|
2021-03-07 21:49:03 +01:00
|
|
|
/* The following quality-of-service code is based on GstBaseSink QoS code, which
|
|
|
|
* is covered by the following copyright information:
|
|
|
|
*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2005-2007 Wim Taymans <wim.taymans@gmail.com>
|
|
|
|
*
|
|
|
|
* gstbasesink.c: Base class for sink elements
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DO_RUNNING_AVG(avg,val,size) (((val) + ((size)-1) * (avg)) / (size))
|
|
|
|
|
|
|
|
/* Generic running average; this has a neutral window size. */
|
|
|
|
#define UPDATE_RUNNING_AVG(avg,val) DO_RUNNING_AVG(avg,val,8)
|
|
|
|
|
|
|
|
/* The windows for these running averages are experimentally obtained.
|
|
|
|
* Positive values get averaged more, while negative values use a small
|
|
|
|
* window so we can react faster to badness. */
|
|
|
|
#define UPDATE_RUNNING_AVG_P(avg,val) DO_RUNNING_AVG(avg,val,16)
|
|
|
|
#define UPDATE_RUNNING_AVG_N(avg,val) DO_RUNNING_AVG(avg,val,4)
|
|
|
|
|
2021-03-09 23:19:55 +01:00
|
|
|
static void reset_qos(struct strmbase_renderer *filter)
|
2021-03-07 21:49:03 +01:00
|
|
|
{
|
2021-03-09 23:19:55 +01:00
|
|
|
filter->last_left = filter->avg_duration = filter->avg_pt = -1;
|
|
|
|
filter->avg_rate = -1.0;
|
2021-03-07 21:49:03 +01:00
|
|
|
}
|
|
|
|
|
2021-03-09 23:19:57 +01:00
|
|
|
static void perform_qos(struct strmbase_renderer *filter,
|
|
|
|
const REFERENCE_TIME start, const REFERENCE_TIME stop, REFERENCE_TIME jitter)
|
2021-03-07 21:49:03 +01:00
|
|
|
{
|
2021-03-09 23:19:57 +01:00
|
|
|
REFERENCE_TIME pt, entered, left, duration;
|
2021-03-07 21:49:03 +01:00
|
|
|
double rate;
|
|
|
|
|
|
|
|
if (jitter < 0)
|
|
|
|
{
|
|
|
|
/* This is the time the buffer entered the sink. */
|
|
|
|
if (start < -jitter)
|
|
|
|
entered = 0;
|
|
|
|
else
|
|
|
|
entered = start + jitter;
|
|
|
|
left = start;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* This is the time the buffer entered the sink. */
|
|
|
|
entered = start + jitter;
|
|
|
|
/* This is the time the buffer left the sink. */
|
|
|
|
left = start + jitter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate the duration of the buffer. */
|
|
|
|
if (stop >= start)
|
|
|
|
duration = stop - start;
|
|
|
|
else
|
|
|
|
duration = 0;
|
|
|
|
|
|
|
|
/* If we have the time when the last buffer left us, calculate processing
|
|
|
|
* time. */
|
2021-03-09 23:19:55 +01:00
|
|
|
if (filter->last_left >= 0)
|
2021-03-07 21:49:03 +01:00
|
|
|
{
|
2021-03-09 23:19:55 +01:00
|
|
|
if (entered > filter->last_left)
|
|
|
|
pt = entered - filter->last_left;
|
2021-03-07 21:49:03 +01:00
|
|
|
else
|
|
|
|
pt = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-09 23:19:55 +01:00
|
|
|
pt = filter->avg_pt;
|
2021-03-07 21:49:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("start %s, entered %s, left %s, pt %s, duration %s, jitter %s.\n",
|
|
|
|
debugstr_time(start), debugstr_time(entered), debugstr_time(left),
|
|
|
|
debugstr_time(pt), debugstr_time(duration), debugstr_time(jitter));
|
|
|
|
|
|
|
|
TRACE("average duration %s, average pt %s, average rate %.16e.\n",
|
2021-03-09 23:19:55 +01:00
|
|
|
debugstr_time(filter->avg_duration), debugstr_time(filter->avg_pt), filter->avg_rate);
|
2021-03-07 21:49:03 +01:00
|
|
|
|
|
|
|
/* Collect running averages. For first observations, we copy the values. */
|
2021-03-09 23:19:55 +01:00
|
|
|
if (filter->avg_duration < 0)
|
|
|
|
filter->avg_duration = duration;
|
2021-03-07 21:49:03 +01:00
|
|
|
else
|
2021-03-09 23:19:55 +01:00
|
|
|
filter->avg_duration = UPDATE_RUNNING_AVG(filter->avg_duration, duration);
|
2021-03-07 21:49:03 +01:00
|
|
|
|
2021-03-09 23:19:55 +01:00
|
|
|
if (filter->avg_pt < 0)
|
|
|
|
filter->avg_pt = pt;
|
2021-03-07 21:49:03 +01:00
|
|
|
else
|
2021-03-09 23:19:55 +01:00
|
|
|
filter->avg_pt = UPDATE_RUNNING_AVG(filter->avg_pt, pt);
|
2021-03-07 21:49:03 +01:00
|
|
|
|
2021-03-09 23:19:55 +01:00
|
|
|
if (filter->avg_duration != 0)
|
|
|
|
rate = (double)filter->avg_pt / (double)filter->avg_duration;
|
2021-03-07 21:49:03 +01:00
|
|
|
else
|
|
|
|
rate = 0.0;
|
|
|
|
|
2021-03-09 23:19:55 +01:00
|
|
|
if (filter->last_left >= 0)
|
2021-03-07 21:49:03 +01:00
|
|
|
{
|
2021-03-09 23:19:55 +01:00
|
|
|
if (filter->avg_rate < 0.0)
|
2021-03-07 21:49:03 +01:00
|
|
|
{
|
2021-03-09 23:19:55 +01:00
|
|
|
filter->avg_rate = rate;
|
2021-03-07 21:49:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (rate > 1.0)
|
2021-03-09 23:19:55 +01:00
|
|
|
filter->avg_rate = UPDATE_RUNNING_AVG_N(filter->avg_rate, rate);
|
2021-03-07 21:49:03 +01:00
|
|
|
else
|
2021-03-09 23:19:55 +01:00
|
|
|
filter->avg_rate = UPDATE_RUNNING_AVG_P(filter->avg_rate, rate);
|
2021-03-07 21:49:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-09 23:19:55 +01:00
|
|
|
if (filter->avg_rate >= 0.0)
|
2021-03-07 21:49:03 +01:00
|
|
|
{
|
|
|
|
Quality q;
|
|
|
|
|
|
|
|
/* If we have a valid rate, start sending QoS messages. */
|
2021-03-09 23:19:57 +01:00
|
|
|
if (jitter < 0)
|
2021-03-07 21:49:03 +01:00
|
|
|
{
|
|
|
|
/* Make sure we never go below 0 when adding the jitter to the
|
|
|
|
* timestamp. */
|
2021-03-09 23:19:57 +01:00
|
|
|
if (start < -jitter)
|
|
|
|
jitter = -start;
|
2021-03-07 21:49:03 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-03-09 23:19:57 +01:00
|
|
|
jitter += stop - start;
|
2021-03-07 21:49:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
q.Type = (jitter > 0 ? Famine : Flood);
|
2021-03-09 23:19:55 +01:00
|
|
|
q.Proportion = 1000.0 / filter->avg_rate;
|
2021-03-07 21:49:03 +01:00
|
|
|
if (q.Proportion < 200)
|
|
|
|
q.Proportion = 200;
|
|
|
|
else if (q.Proportion > 5000)
|
|
|
|
q.Proportion = 5000;
|
2021-03-09 23:19:57 +01:00
|
|
|
q.Late = jitter;
|
|
|
|
q.TimeStamp = start;
|
2021-03-09 23:19:55 +01:00
|
|
|
IQualityControl_Notify(&filter->IQualityControl_iface, &filter->filter.IBaseFilter_iface, q);
|
2021-03-07 21:49:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Record when this buffer will leave us. */
|
2021-03-09 23:19:55 +01:00
|
|
|
filter->last_left = left;
|
2021-03-07 21:49:03 +01:00
|
|
|
}
|
|
|
|
|
2019-10-24 03:04:23 +02:00
|
|
|
static inline struct strmbase_renderer *impl_from_strmbase_filter(struct strmbase_filter *iface)
|
2012-03-28 21:53:33 +02:00
|
|
|
{
|
2019-10-24 03:04:23 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct strmbase_renderer, filter);
|
2012-03-28 21:53:33 +02:00
|
|
|
}
|
|
|
|
|
2019-10-24 03:04:23 +02:00
|
|
|
static inline struct strmbase_renderer *impl_from_IPin(IPin *iface)
|
2019-06-21 03:13:19 +02:00
|
|
|
{
|
2019-10-24 03:04:23 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct strmbase_renderer, sink.pin.IPin_iface);
|
2019-06-21 03:13:19 +02:00
|
|
|
}
|
|
|
|
|
2019-11-23 04:13:59 +01:00
|
|
|
static struct strmbase_pin *renderer_get_pin(struct strmbase_filter *iface, unsigned int index)
|
2012-03-28 21:53:33 +02:00
|
|
|
{
|
2019-10-24 03:04:23 +02:00
|
|
|
struct strmbase_renderer *filter = impl_from_strmbase_filter(iface);
|
2012-03-28 21:53:33 +02:00
|
|
|
|
2019-06-21 03:13:19 +02:00
|
|
|
if (index == 0)
|
2019-11-23 04:13:59 +01:00
|
|
|
return &filter->sink.pin;
|
2019-06-21 03:13:19 +02:00
|
|
|
return NULL;
|
2012-03-28 21:53:33 +02:00
|
|
|
}
|
|
|
|
|
2019-08-29 03:24:30 +02:00
|
|
|
static void renderer_destroy(struct strmbase_filter *iface)
|
2019-05-28 06:09:55 +02:00
|
|
|
{
|
2019-10-24 03:04:23 +02:00
|
|
|
struct strmbase_renderer *filter = impl_from_strmbase_filter(iface);
|
2021-03-12 00:22:00 +01:00
|
|
|
filter->ops->renderer_destroy(filter);
|
2019-05-28 06:09:55 +02:00
|
|
|
}
|
|
|
|
|
2019-08-29 03:24:30 +02:00
|
|
|
static HRESULT renderer_query_interface(struct strmbase_filter *iface, REFIID iid, void **out)
|
2019-05-28 06:09:55 +02:00
|
|
|
{
|
2019-10-24 03:04:23 +02:00
|
|
|
struct strmbase_renderer *filter = impl_from_strmbase_filter(iface);
|
2019-05-31 05:59:36 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2021-03-12 00:22:00 +01:00
|
|
|
if (filter->ops->renderer_query_interface
|
|
|
|
&& SUCCEEDED(hr = filter->ops->renderer_query_interface(filter, iid, out)))
|
2019-05-31 05:59:36 +02:00
|
|
|
{
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-03-13 03:34:10 +01:00
|
|
|
if (IsEqualGUID(iid, &IID_IMediaPosition))
|
|
|
|
*out = &filter->passthrough.IMediaPosition_iface;
|
|
|
|
else if (IsEqualGUID(iid, &IID_IMediaSeeking))
|
|
|
|
*out = &filter->passthrough.IMediaSeeking_iface;
|
|
|
|
else if (IsEqualGUID(iid, &IID_IQualityControl))
|
2021-03-09 23:19:55 +01:00
|
|
|
*out = &filter->IQualityControl_iface;
|
2020-03-13 03:34:10 +01:00
|
|
|
else
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
|
|
|
IUnknown_AddRef((IUnknown *)*out);
|
|
|
|
return S_OK;
|
2019-05-31 05:59:36 +02:00
|
|
|
}
|
|
|
|
|
2019-10-28 00:28:02 +01:00
|
|
|
static HRESULT renderer_init_stream(struct strmbase_filter *iface)
|
|
|
|
{
|
|
|
|
struct strmbase_renderer *filter = impl_from_strmbase_filter(iface);
|
|
|
|
|
|
|
|
if (filter->sink.pin.peer)
|
|
|
|
ResetEvent(filter->state_event);
|
2019-11-27 00:39:20 +01:00
|
|
|
filter->eos = FALSE;
|
2019-10-28 00:28:02 +01:00
|
|
|
ResetEvent(filter->flush_event);
|
2021-03-12 00:22:00 +01:00
|
|
|
if (filter->ops->renderer_init_stream)
|
|
|
|
filter->ops->renderer_init_stream(filter);
|
2019-10-28 00:28:02 +01:00
|
|
|
|
2020-02-20 03:44:53 +01:00
|
|
|
return filter->sink.pin.peer ? S_FALSE : S_OK;
|
2019-10-28 00:28:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT renderer_start_stream(struct strmbase_filter *iface, REFERENCE_TIME start)
|
|
|
|
{
|
|
|
|
struct strmbase_renderer *filter = impl_from_strmbase_filter(iface);
|
2021-05-26 18:46:43 +02:00
|
|
|
IFilterGraph *graph = filter->filter.graph;
|
|
|
|
IMediaEventSink *event_sink;
|
2019-10-28 00:28:02 +01:00
|
|
|
|
|
|
|
filter->stream_start = start;
|
|
|
|
SetEvent(filter->state_event);
|
2021-03-11 02:23:36 +01:00
|
|
|
SetEvent(filter->run_event);
|
2021-03-09 23:19:55 +01:00
|
|
|
reset_qos(filter);
|
2021-03-12 00:22:00 +01:00
|
|
|
if (filter->sink.pin.peer && filter->ops->renderer_start_stream)
|
|
|
|
filter->ops->renderer_start_stream(filter);
|
2019-10-28 00:28:02 +01:00
|
|
|
|
2021-11-01 01:04:08 +01:00
|
|
|
if ((filter->eos || !filter->sink.pin.peer) && graph
|
2021-05-26 18:46:43 +02:00
|
|
|
&& SUCCEEDED(IFilterGraph_QueryInterface(graph,
|
|
|
|
&IID_IMediaEventSink, (void **)&event_sink)))
|
|
|
|
{
|
|
|
|
IMediaEventSink_Notify(event_sink, EC_COMPLETE, S_OK,
|
|
|
|
(LONG_PTR)&filter->filter.IBaseFilter_iface);
|
|
|
|
IMediaEventSink_Release(event_sink);
|
|
|
|
}
|
|
|
|
|
2019-10-28 00:28:02 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT renderer_stop_stream(struct strmbase_filter *iface)
|
|
|
|
{
|
|
|
|
struct strmbase_renderer *filter = impl_from_strmbase_filter(iface);
|
|
|
|
|
2021-03-11 02:23:36 +01:00
|
|
|
ResetEvent(filter->run_event);
|
|
|
|
|
2021-03-12 00:22:00 +01:00
|
|
|
if (filter->sink.pin.peer && filter->ops->renderer_stop_stream)
|
|
|
|
filter->ops->renderer_stop_stream(filter);
|
2019-10-28 00:28:02 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT renderer_cleanup_stream(struct strmbase_filter *iface)
|
|
|
|
{
|
|
|
|
struct strmbase_renderer *filter = impl_from_strmbase_filter(iface);
|
|
|
|
|
2020-03-13 03:34:10 +01:00
|
|
|
strmbase_passthrough_invalidate_time(&filter->passthrough);
|
2019-10-28 00:28:02 +01:00
|
|
|
SetEvent(filter->state_event);
|
|
|
|
SetEvent(filter->flush_event);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT renderer_wait_state(struct strmbase_filter *iface, DWORD timeout)
|
|
|
|
{
|
|
|
|
struct strmbase_renderer *filter = impl_from_strmbase_filter(iface);
|
|
|
|
|
|
|
|
if (WaitForSingleObject(filter->state_event, timeout) == WAIT_TIMEOUT)
|
|
|
|
return VFW_S_STATE_INTERMEDIATE;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-08-29 03:24:29 +02:00
|
|
|
static const struct strmbase_filter_ops filter_ops =
|
|
|
|
{
|
2019-05-28 06:09:55 +02:00
|
|
|
.filter_get_pin = renderer_get_pin,
|
|
|
|
.filter_destroy = renderer_destroy,
|
2019-05-31 05:59:36 +02:00
|
|
|
.filter_query_interface = renderer_query_interface,
|
2019-10-28 00:28:02 +01:00
|
|
|
.filter_init_stream = renderer_init_stream,
|
|
|
|
.filter_start_stream = renderer_start_stream,
|
|
|
|
.filter_stop_stream = renderer_stop_stream,
|
|
|
|
.filter_cleanup_stream = renderer_cleanup_stream,
|
|
|
|
.filter_wait_state = renderer_wait_state,
|
2019-05-28 06:09:55 +02:00
|
|
|
};
|
|
|
|
|
2019-09-25 02:10:10 +02:00
|
|
|
static HRESULT sink_query_accept(struct strmbase_pin *pin, const AM_MEDIA_TYPE *mt)
|
2012-03-28 21:53:33 +02:00
|
|
|
{
|
2019-10-24 03:04:23 +02:00
|
|
|
struct strmbase_renderer *filter = impl_from_IPin(&pin->IPin_iface);
|
2021-03-12 00:22:00 +01:00
|
|
|
return filter->ops->renderer_query_accept(filter, mt);
|
2012-03-28 21:53:33 +02:00
|
|
|
}
|
|
|
|
|
2019-09-26 05:36:23 +02:00
|
|
|
static HRESULT sink_query_interface(struct strmbase_pin *iface, REFIID iid, void **out)
|
|
|
|
{
|
2019-10-24 03:04:23 +02:00
|
|
|
struct strmbase_renderer *filter = impl_from_IPin(&iface->IPin_iface);
|
2019-10-02 05:43:12 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2021-03-12 00:22:00 +01:00
|
|
|
if (filter->ops->renderer_pin_query_interface
|
|
|
|
&& SUCCEEDED(hr = filter->ops->renderer_pin_query_interface(filter, iid, out)))
|
2019-10-02 05:43:12 +02:00
|
|
|
return hr;
|
2019-09-26 05:36:23 +02:00
|
|
|
|
|
|
|
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 BaseRenderer_Receive(struct strmbase_sink *pin, IMediaSample *sample)
|
2012-03-28 21:53:33 +02:00
|
|
|
{
|
2019-10-24 03:04:23 +02:00
|
|
|
struct strmbase_renderer *filter = impl_from_IPin(&pin->pin.IPin_iface);
|
2020-07-21 00:49:06 +02:00
|
|
|
REFERENCE_TIME start, stop;
|
2020-07-21 00:49:07 +02:00
|
|
|
BOOL need_wait = FALSE;
|
|
|
|
FILTER_STATE state;
|
|
|
|
HRESULT hr = S_OK;
|
2020-07-21 00:49:06 +02:00
|
|
|
AM_MEDIA_TYPE *mt;
|
|
|
|
|
|
|
|
if (filter->eos || filter->sink.flushing)
|
|
|
|
return S_FALSE;
|
|
|
|
|
2020-07-21 00:49:07 +02:00
|
|
|
state = filter->filter.state;
|
|
|
|
if (state == State_Stopped)
|
2020-07-21 00:49:06 +02:00
|
|
|
return VFW_E_WRONG_STATE;
|
|
|
|
|
|
|
|
if (IMediaSample_GetMediaType(sample, &mt) == S_OK)
|
|
|
|
{
|
|
|
|
TRACE("Format change.\n");
|
|
|
|
strmbase_dump_media_type(mt);
|
|
|
|
|
2021-03-12 00:22:00 +01:00
|
|
|
if (FAILED(filter->ops->renderer_query_accept(filter, mt)))
|
2020-07-21 00:49:06 +02:00
|
|
|
return VFW_E_TYPE_NOT_ACCEPTED;
|
|
|
|
DeleteMediaType(mt);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (filter->filter.clock && SUCCEEDED(IMediaSample_GetTime(sample, &start, &stop)))
|
2020-07-21 00:49:07 +02:00
|
|
|
{
|
|
|
|
strmbase_passthrough_update_time(&filter->passthrough, start);
|
|
|
|
need_wait = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state == State_Paused)
|
2021-03-11 02:23:34 +01:00
|
|
|
{
|
2021-03-11 02:23:36 +01:00
|
|
|
HANDLE events[2] = {filter->run_event, filter->flush_event};
|
|
|
|
|
2021-03-11 02:23:34 +01:00
|
|
|
filter->current_sample = sample;
|
2021-03-11 02:23:36 +01:00
|
|
|
|
2021-03-12 00:22:00 +01:00
|
|
|
hr = filter->ops->renderer_render(filter, sample);
|
2021-03-11 02:23:36 +01:00
|
|
|
|
|
|
|
SetEvent(filter->state_event);
|
|
|
|
LeaveCriticalSection(&filter->filter.stream_cs);
|
|
|
|
WaitForMultipleObjects(2, events, FALSE, INFINITE);
|
|
|
|
EnterCriticalSection(&filter->filter.stream_cs);
|
|
|
|
|
2021-03-11 02:23:34 +01:00
|
|
|
filter->current_sample = NULL;
|
|
|
|
}
|
2020-07-21 00:49:07 +02:00
|
|
|
|
|
|
|
if (need_wait)
|
2020-07-21 00:49:06 +02:00
|
|
|
{
|
2021-03-09 23:19:57 +01:00
|
|
|
REFERENCE_TIME now, jitter;
|
2020-07-21 00:49:06 +02:00
|
|
|
DWORD_PTR cookie;
|
|
|
|
|
|
|
|
IReferenceClock_GetTime(filter->filter.clock, &now);
|
|
|
|
|
2021-03-09 23:19:57 +01:00
|
|
|
/* "jitter" describes how early (negative) or late (positive) this
|
|
|
|
* buffer arrived, relative to its PTS. */
|
|
|
|
jitter = (now - filter->stream_start) - start;
|
2021-03-09 23:19:56 +01:00
|
|
|
|
2021-03-09 23:19:57 +01:00
|
|
|
if (jitter <= -10000) /* if we are early by at least 1 ms */
|
2020-07-21 00:49:06 +02:00
|
|
|
{
|
|
|
|
HANDLE handles[2] = {filter->advise_event, filter->flush_event};
|
|
|
|
DWORD ret;
|
|
|
|
|
|
|
|
IReferenceClock_AdviseTime(filter->filter.clock, filter->stream_start,
|
|
|
|
start, (HEVENT)filter->advise_event, &cookie);
|
|
|
|
|
|
|
|
ret = WaitForMultipleObjects(2, handles, FALSE, INFINITE);
|
|
|
|
IReferenceClock_Unadvise(filter->filter.clock, cookie);
|
|
|
|
|
|
|
|
if (ret == 1)
|
|
|
|
{
|
|
|
|
TRACE("Flush signaled; discarding current sample.\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-09 23:19:56 +01:00
|
|
|
if (state == State_Running)
|
2021-03-12 00:22:00 +01:00
|
|
|
hr = filter->ops->renderer_render(filter, sample);
|
2021-03-09 23:19:56 +01:00
|
|
|
|
2021-03-09 23:19:57 +01:00
|
|
|
perform_qos(filter, start, stop, jitter);
|
2021-03-09 23:19:56 +01:00
|
|
|
}
|
|
|
|
else
|
2020-07-21 00:49:07 +02:00
|
|
|
{
|
2021-03-09 23:19:56 +01:00
|
|
|
if (state == State_Running)
|
2021-03-12 00:22:00 +01:00
|
|
|
hr = filter->ops->renderer_render(filter, sample);
|
2020-07-21 00:49:07 +02:00
|
|
|
}
|
|
|
|
|
2020-07-21 00:49:06 +02:00
|
|
|
return hr;
|
2012-03-28 21:53:33 +02:00
|
|
|
}
|
|
|
|
|
2019-12-10 17:35:15 +01:00
|
|
|
static HRESULT sink_connect(struct strmbase_sink *iface, IPin *peer, const AM_MEDIA_TYPE *mt)
|
|
|
|
{
|
|
|
|
struct strmbase_renderer *filter = impl_from_IPin(&iface->pin.IPin_iface);
|
|
|
|
|
2021-03-12 00:22:00 +01:00
|
|
|
if (filter->ops->renderer_connect)
|
|
|
|
return filter->ops->renderer_connect(filter, mt);
|
2019-12-10 17:35:15 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sink_disconnect(struct strmbase_sink *iface)
|
|
|
|
{
|
|
|
|
struct strmbase_renderer *filter = impl_from_IPin(&iface->pin.IPin_iface);
|
|
|
|
|
2021-03-12 00:22:00 +01:00
|
|
|
if (filter->ops->renderer_disconnect)
|
|
|
|
filter->ops->renderer_disconnect(filter);
|
2019-12-10 17:35:15 +01:00
|
|
|
}
|
|
|
|
|
2019-12-13 04:24:36 +01:00
|
|
|
static HRESULT sink_eos(struct strmbase_sink *iface)
|
|
|
|
{
|
|
|
|
struct strmbase_renderer *filter = impl_from_IPin(&iface->pin.IPin_iface);
|
2020-01-31 02:05:18 +01:00
|
|
|
IFilterGraph *graph = filter->filter.graph;
|
2019-12-13 04:24:36 +01:00
|
|
|
IMediaEventSink *event_sink;
|
|
|
|
|
|
|
|
filter->eos = TRUE;
|
|
|
|
|
2021-05-26 18:46:43 +02:00
|
|
|
if (filter->filter.state == State_Running && graph
|
|
|
|
&& SUCCEEDED(IFilterGraph_QueryInterface(graph,
|
2019-12-13 04:24:36 +01:00
|
|
|
&IID_IMediaEventSink, (void **)&event_sink)))
|
|
|
|
{
|
|
|
|
IMediaEventSink_Notify(event_sink, EC_COMPLETE, S_OK,
|
|
|
|
(LONG_PTR)&filter->filter.IBaseFilter_iface);
|
|
|
|
IMediaEventSink_Release(event_sink);
|
|
|
|
}
|
2020-03-13 03:34:10 +01:00
|
|
|
strmbase_passthrough_eos(&filter->passthrough);
|
2019-12-13 04:24:36 +01:00
|
|
|
SetEvent(filter->state_event);
|
|
|
|
|
2020-07-20 17:25:30 +02:00
|
|
|
return S_OK;
|
2019-12-13 04:24:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT sink_begin_flush(struct strmbase_sink *iface)
|
|
|
|
{
|
|
|
|
struct strmbase_renderer *filter = impl_from_IPin(&iface->pin.IPin_iface);
|
|
|
|
|
|
|
|
SetEvent(filter->flush_event);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT sink_end_flush(struct strmbase_sink *iface)
|
|
|
|
{
|
|
|
|
struct strmbase_renderer *filter = impl_from_IPin(&iface->pin.IPin_iface);
|
|
|
|
|
2021-01-19 04:57:20 +01:00
|
|
|
EnterCriticalSection(&filter->filter.stream_cs);
|
2019-12-13 04:24:36 +01:00
|
|
|
|
|
|
|
filter->eos = FALSE;
|
2021-03-09 23:19:55 +01:00
|
|
|
reset_qos(filter);
|
2020-03-13 03:34:10 +01:00
|
|
|
strmbase_passthrough_invalidate_time(&filter->passthrough);
|
2019-12-13 04:24:36 +01:00
|
|
|
ResetEvent(filter->flush_event);
|
|
|
|
|
2021-01-19 04:57:20 +01:00
|
|
|
LeaveCriticalSection(&filter->filter.stream_cs);
|
2020-07-20 17:25:30 +02:00
|
|
|
return S_OK;
|
2019-12-13 04:24:36 +01:00
|
|
|
}
|
|
|
|
|
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:23 +02:00
|
|
|
.base.pin_query_interface = sink_query_interface,
|
2019-09-25 02:10:10 +02:00
|
|
|
.pfnReceive = BaseRenderer_Receive,
|
2019-12-10 17:35:15 +01:00
|
|
|
.sink_connect = sink_connect,
|
|
|
|
.sink_disconnect = sink_disconnect,
|
2019-12-13 04:24:36 +01:00
|
|
|
.sink_eos = sink_eos,
|
|
|
|
.sink_begin_flush = sink_begin_flush,
|
|
|
|
.sink_end_flush = sink_end_flush,
|
2012-03-28 21:53:33 +02:00
|
|
|
};
|
|
|
|
|
2021-03-09 23:19:55 +01:00
|
|
|
static struct strmbase_renderer *impl_from_IQualityControl(IQualityControl *iface)
|
2021-03-07 21:49:03 +01:00
|
|
|
{
|
2021-03-09 23:19:55 +01:00
|
|
|
return CONTAINING_RECORD(iface, struct strmbase_renderer, IQualityControl_iface);
|
2021-03-07 21:49:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI quality_control_QueryInterface(IQualityControl *iface, REFIID iid, void **out)
|
|
|
|
{
|
2021-03-09 23:19:55 +01:00
|
|
|
struct strmbase_renderer *filter = impl_from_IQualityControl(iface);
|
|
|
|
return IUnknown_QueryInterface(filter->filter.outer_unk, iid, out);
|
2021-03-07 21:49:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI quality_control_AddRef(IQualityControl *iface)
|
|
|
|
{
|
2021-03-09 23:19:55 +01:00
|
|
|
struct strmbase_renderer *filter = impl_from_IQualityControl(iface);
|
|
|
|
return IUnknown_AddRef(filter->filter.outer_unk);
|
2021-03-07 21:49:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI quality_control_Release(IQualityControl *iface)
|
|
|
|
{
|
2021-03-09 23:19:55 +01:00
|
|
|
struct strmbase_renderer *filter = impl_from_IQualityControl(iface);
|
|
|
|
return IUnknown_Release(filter->filter.outer_unk);
|
2021-03-07 21:49:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI quality_control_Notify(IQualityControl *iface, IBaseFilter *sender, Quality q)
|
|
|
|
{
|
2021-03-09 23:19:55 +01:00
|
|
|
struct strmbase_renderer *filter = impl_from_IQualityControl(iface);
|
2021-03-07 21:49:03 +01:00
|
|
|
HRESULT hr = S_FALSE;
|
|
|
|
|
2022-02-08 06:22:48 +01:00
|
|
|
TRACE("filter %p, sender %p, type %#x, proportion %ld, late %s, timestamp %s.\n",
|
2021-03-09 23:19:55 +01:00
|
|
|
filter, sender, q.Type, q.Proportion, debugstr_time(q.Late), debugstr_time(q.TimeStamp));
|
2021-03-07 21:49:03 +01:00
|
|
|
|
2021-03-09 23:19:55 +01:00
|
|
|
if (filter->qc_sink)
|
|
|
|
return IQualityControl_Notify(filter->qc_sink, &filter->filter.IBaseFilter_iface, q);
|
2021-03-07 21:49:03 +01:00
|
|
|
|
2021-03-09 23:19:55 +01:00
|
|
|
if (filter->sink.pin.peer)
|
2021-03-07 21:49:03 +01:00
|
|
|
{
|
|
|
|
IQualityControl *peer_qc = NULL;
|
2021-03-09 23:19:55 +01:00
|
|
|
IPin_QueryInterface(filter->sink.pin.peer, &IID_IQualityControl, (void **)&peer_qc);
|
2021-03-07 21:49:03 +01:00
|
|
|
if (peer_qc)
|
|
|
|
{
|
2021-03-09 23:19:55 +01:00
|
|
|
hr = IQualityControl_Notify(peer_qc, &filter->filter.IBaseFilter_iface, q);
|
2021-03-07 21:49:03 +01:00
|
|
|
IQualityControl_Release(peer_qc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI quality_control_SetSink(IQualityControl *iface, IQualityControl *sink)
|
|
|
|
{
|
2021-03-09 23:19:55 +01:00
|
|
|
struct strmbase_renderer *filter = impl_from_IQualityControl(iface);
|
2021-03-07 21:49:03 +01:00
|
|
|
|
2021-03-09 23:19:55 +01:00
|
|
|
TRACE("filter %p, sink %p.\n", filter, sink);
|
2021-03-07 21:49:03 +01:00
|
|
|
|
2021-03-09 23:19:55 +01:00
|
|
|
filter->qc_sink = sink;
|
2021-03-07 21:49:03 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IQualityControlVtbl quality_control_vtbl =
|
|
|
|
{
|
|
|
|
quality_control_QueryInterface,
|
|
|
|
quality_control_AddRef,
|
|
|
|
quality_control_Release,
|
|
|
|
quality_control_Notify,
|
|
|
|
quality_control_SetSink,
|
|
|
|
};
|
|
|
|
|
2019-10-24 03:04:23 +02:00
|
|
|
void strmbase_renderer_cleanup(struct strmbase_renderer *filter)
|
2012-03-28 21:53:33 +02:00
|
|
|
{
|
2019-09-27 04:40:53 +02:00
|
|
|
if (filter->sink.pin.peer)
|
|
|
|
IPin_Disconnect(filter->sink.pin.peer);
|
2019-06-21 03:13:19 +02:00
|
|
|
IPin_Disconnect(&filter->sink.pin.IPin_iface);
|
|
|
|
strmbase_sink_cleanup(&filter->sink);
|
2012-03-28 21:53:33 +02:00
|
|
|
|
2020-03-13 03:34:10 +01:00
|
|
|
strmbase_passthrough_cleanup(&filter->passthrough);
|
2019-05-16 01:16:55 +02:00
|
|
|
|
2019-07-02 05:49:45 +02:00
|
|
|
CloseHandle(filter->state_event);
|
2019-07-02 05:49:48 +02:00
|
|
|
CloseHandle(filter->advise_event);
|
2021-03-11 02:23:35 +01:00
|
|
|
CloseHandle(filter->run_event);
|
2019-07-02 05:49:48 +02:00
|
|
|
CloseHandle(filter->flush_event);
|
2019-05-22 07:02:12 +02:00
|
|
|
strmbase_filter_cleanup(&filter->filter);
|
2012-03-28 21:53:33 +02:00
|
|
|
}
|
|
|
|
|
2020-03-28 18:02:07 +01:00
|
|
|
void strmbase_renderer_init(struct strmbase_renderer *filter, IUnknown *outer,
|
2019-10-24 03:04:24 +02:00
|
|
|
const CLSID *clsid, const WCHAR *sink_name, const struct strmbase_renderer_ops *ops)
|
2019-10-24 03:04:22 +02:00
|
|
|
{
|
|
|
|
memset(filter, 0, sizeof(*filter));
|
2019-12-05 06:03:31 +01:00
|
|
|
strmbase_filter_init(&filter->filter, outer, clsid, &filter_ops);
|
2020-03-13 03:34:10 +01:00
|
|
|
strmbase_passthrough_init(&filter->passthrough, (IUnknown *)&filter->filter.IBaseFilter_iface);
|
|
|
|
ISeekingPassThru_Init(&filter->passthrough.ISeekingPassThru_iface, TRUE, &filter->sink.pin.IPin_iface);
|
2021-03-09 23:19:55 +01:00
|
|
|
filter->IQualityControl_iface.lpVtbl = &quality_control_vtbl;
|
|
|
|
|
2021-03-12 00:22:00 +01:00
|
|
|
filter->ops = ops;
|
2019-10-24 03:04:22 +02:00
|
|
|
|
2019-12-13 04:24:39 +01:00
|
|
|
strmbase_sink_init(&filter->sink, &filter->filter, sink_name, &sink_ops, NULL);
|
2019-10-24 03:04:22 +02:00
|
|
|
|
|
|
|
filter->state_event = CreateEventW(NULL, TRUE, TRUE, NULL);
|
|
|
|
filter->advise_event = CreateEventW(NULL, FALSE, FALSE, NULL);
|
2021-03-11 02:23:35 +01:00
|
|
|
filter->run_event = CreateEventW(NULL, TRUE, FALSE, NULL);
|
2019-10-24 03:04:22 +02:00
|
|
|
filter->flush_event = CreateEventW(NULL, TRUE, TRUE, NULL);
|
|
|
|
}
|