gdi32: Avoid signed-unsigned integer comparisons.
[wine] / dlls / strmbase / renderer.c
1 /*
2  * Generic Implementation of strmbase Base Renderer classes
3  *
4  * Copyright 2012 Aric Stewart, CodeWeavers
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #define COBJMACROS
22
23 #include "dshow.h"
24 #include "wine/debug.h"
25 #include "wine/unicode.h"
26 #include "wine/strmbase.h"
27 #include "uuids.h"
28 #include "vfwmsgs.h"
29 #include "strmbase_private.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(strmbase);
32
33 static const WCHAR wcsInputPinName[] = {'i','n','p','u','t',' ','p','i','n',0};
34 static const WCHAR wcsAltInputPinName[] = {'I','n',0};
35
36 static inline BaseInputPin *impl_BaseInputPin_from_IPin( IPin *iface )
37 {
38     return CONTAINING_RECORD(iface, BaseInputPin, pin.IPin_iface);
39 }
40
41 static inline BaseRenderer *impl_from_IBaseFilter(IBaseFilter *iface)
42 {
43     return CONTAINING_RECORD(iface, BaseRenderer, filter.IBaseFilter_iface);
44 }
45
46 static inline BaseRenderer *impl_from_BaseFilter(BaseFilter *iface)
47 {
48     return CONTAINING_RECORD(iface, BaseRenderer, filter);
49 }
50
51 static const IQualityControlVtbl Renderer_QualityControl_Vtbl = {
52     QualityControlImpl_QueryInterface,
53     QualityControlImpl_AddRef,
54     QualityControlImpl_Release,
55     QualityControlImpl_Notify,
56     QualityControlImpl_SetSink
57 };
58
59 static HRESULT WINAPI BaseRenderer_InputPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
60 {
61     BaseInputPin *This = impl_BaseInputPin_from_IPin(iface);
62     BaseRenderer *renderer = impl_from_IBaseFilter(This->pin.pinInfo.pFilter);
63     HRESULT hr = S_OK;
64
65     TRACE("(%p/%p)->(%p, %p)\n", This, renderer, pReceivePin, pmt);
66
67     EnterCriticalSection(This->pin.pCritSec);
68     hr = BaseInputPinImpl_ReceiveConnection(iface, pReceivePin, pmt);
69     if (SUCCEEDED(hr))
70     {
71         if (renderer->pFuncsTable->pfnCompleteConnect)
72             hr = renderer->pFuncsTable->pfnCompleteConnect(renderer, pReceivePin);
73     }
74     LeaveCriticalSection(This->pin.pCritSec);
75
76     return hr;
77 }
78
79 static HRESULT WINAPI BaseRenderer_InputPin_Disconnect(IPin * iface)
80 {
81     BaseInputPin *This = impl_BaseInputPin_from_IPin(iface);
82     BaseRenderer *renderer = impl_from_IBaseFilter(This->pin.pinInfo.pFilter);
83     HRESULT hr;
84
85     TRACE("(%p/%p)\n", This, renderer);
86
87     EnterCriticalSection(This->pin.pCritSec);
88     hr = BasePinImpl_Disconnect(iface);
89     if (SUCCEEDED(hr))
90     {
91         if (renderer->pFuncsTable->pfnBreakConnect)
92             hr = renderer->pFuncsTable->pfnBreakConnect(renderer);
93     }
94     BaseRendererImpl_ClearPendingSample(renderer);
95     LeaveCriticalSection(This->pin.pCritSec);
96
97     return hr;
98 }
99
100 static HRESULT WINAPI BaseRenderer_InputPin_EndOfStream(IPin * iface)
101 {
102     HRESULT hr = S_OK;
103     BaseInputPin* This = impl_BaseInputPin_from_IPin(iface);
104     BaseRenderer *pFilter = impl_from_IBaseFilter(This->pin.pinInfo.pFilter);
105
106     TRACE("(%p/%p)->()\n", This, pFilter);
107
108     EnterCriticalSection(&pFilter->filter.csFilter);
109     EnterCriticalSection(&pFilter->csRenderLock);
110     hr = BaseInputPinImpl_EndOfStream(iface);
111     EnterCriticalSection(This->pin.pCritSec);
112     if (SUCCEEDED(hr))
113     {
114         if (pFilter->pFuncsTable->pfnEndOfStream)
115             hr = pFilter->pFuncsTable->pfnEndOfStream(pFilter);
116         else
117             hr = BaseRendererImpl_EndOfStream(pFilter);
118     }
119     LeaveCriticalSection(This->pin.pCritSec);
120     LeaveCriticalSection(&pFilter->csRenderLock);
121     LeaveCriticalSection(&pFilter->filter.csFilter);
122     return hr;
123 }
124
125 static HRESULT WINAPI BaseRenderer_InputPin_BeginFlush(IPin * iface)
126 {
127     BaseInputPin* This = impl_BaseInputPin_from_IPin(iface);
128     BaseRenderer *pFilter = impl_from_IBaseFilter(This->pin.pinInfo.pFilter);
129     HRESULT hr = S_OK;
130
131     TRACE("(%p/%p)->()\n", This, iface);
132
133     EnterCriticalSection(&pFilter->filter.csFilter);
134     EnterCriticalSection(&pFilter->csRenderLock);
135     EnterCriticalSection(This->pin.pCritSec);
136     hr = BaseInputPinImpl_BeginFlush(iface);
137     if (SUCCEEDED(hr))
138     {
139         if (pFilter->pFuncsTable->pfnBeginFlush)
140             hr = pFilter->pFuncsTable->pfnBeginFlush(pFilter);
141         else
142             hr = BaseRendererImpl_BeginFlush(pFilter);
143     }
144     LeaveCriticalSection(This->pin.pCritSec);
145     LeaveCriticalSection(&pFilter->filter.csFilter);
146     LeaveCriticalSection(&pFilter->csRenderLock);
147     return hr;
148 }
149
150 static HRESULT WINAPI BaseRenderer_InputPin_EndFlush(IPin * iface)
151 {
152     BaseInputPin* This = impl_BaseInputPin_from_IPin(iface);
153     BaseRenderer *pFilter = impl_from_IBaseFilter(This->pin.pinInfo.pFilter);
154     HRESULT hr = S_OK;
155
156     TRACE("(%p/%p)->()\n", This, pFilter);
157
158     EnterCriticalSection(&pFilter->filter.csFilter);
159     EnterCriticalSection(&pFilter->csRenderLock);
160     EnterCriticalSection(This->pin.pCritSec);
161     hr = BaseInputPinImpl_EndFlush(iface);
162     if (SUCCEEDED(hr))
163     {
164         if (pFilter->pFuncsTable->pfnEndFlush)
165             hr = pFilter->pFuncsTable->pfnEndFlush(pFilter);
166         else
167             hr = BaseRendererImpl_EndFlush(pFilter);
168     }
169     LeaveCriticalSection(This->pin.pCritSec);
170     LeaveCriticalSection(&pFilter->csRenderLock);
171     LeaveCriticalSection(&pFilter->filter.csFilter);
172     return hr;
173 }
174
175 static const IPinVtbl BaseRenderer_InputPin_Vtbl =
176 {
177     BaseInputPinImpl_QueryInterface,
178     BasePinImpl_AddRef,
179     BaseInputPinImpl_Release,
180     BaseInputPinImpl_Connect,
181     BaseRenderer_InputPin_ReceiveConnection,
182     BaseRenderer_InputPin_Disconnect,
183     BasePinImpl_ConnectedTo,
184     BasePinImpl_ConnectionMediaType,
185     BasePinImpl_QueryPinInfo,
186     BasePinImpl_QueryDirection,
187     BasePinImpl_QueryId,
188     BaseInputPinImpl_QueryAccept,
189     BasePinImpl_EnumMediaTypes,
190     BasePinImpl_QueryInternalConnections,
191     BaseRenderer_InputPin_EndOfStream,
192     BaseRenderer_InputPin_BeginFlush,
193     BaseRenderer_InputPin_EndFlush,
194     BaseInputPinImpl_NewSegment
195 };
196
197 static IPin* WINAPI BaseRenderer_GetPin(BaseFilter *iface, int pos)
198 {
199     BaseRenderer *This = impl_from_BaseFilter(iface);
200
201     if (pos >= 1 || pos < 0)
202         return NULL;
203
204     IPin_AddRef(&This->pInputPin->pin.IPin_iface);
205     return &This->pInputPin->pin.IPin_iface;
206 }
207
208 static LONG WINAPI BaseRenderer_GetPinCount(BaseFilter *iface)
209 {
210     return 1;
211 }
212
213 static HRESULT WINAPI BaseRenderer_Input_CheckMediaType(BasePin *pin, const AM_MEDIA_TYPE * pmt)
214 {
215     BaseRenderer *This = impl_from_IBaseFilter(pin->pinInfo.pFilter);
216     return This->pFuncsTable->pfnCheckMediaType(This, pmt);
217 }
218
219 static HRESULT WINAPI BaseRenderer_Receive(BaseInputPin *pin, IMediaSample * pSample)
220 {
221     BaseRenderer *This = impl_from_IBaseFilter(pin->pin.pinInfo.pFilter);
222     return BaseRendererImpl_Receive(This, pSample);
223 }
224
225 static const BaseFilterFuncTable RendererBaseFilterFuncTable = {
226     BaseRenderer_GetPin,
227     BaseRenderer_GetPinCount
228 };
229
230 static const  BasePinFuncTable input_BaseFuncTable = {
231     BaseRenderer_Input_CheckMediaType,
232     NULL,
233     BasePinImpl_GetMediaTypeVersion,
234     BasePinImpl_GetMediaType
235 };
236
237 static const BaseInputPinFuncTable input_BaseInputFuncTable = {
238    BaseRenderer_Receive
239 };
240
241
242 HRESULT WINAPI BaseRenderer_Init(BaseRenderer * This, const IBaseFilterVtbl *Vtbl, IUnknown *pUnkOuter, const CLSID *pClsid, DWORD_PTR DebugInfo, const BaseRendererFuncTable* pBaseFuncsTable)
243 {
244     PIN_INFO piInput;
245     HRESULT hr;
246
247     BaseFilter_Init(&This->filter, Vtbl, pClsid, DebugInfo, &RendererBaseFilterFuncTable);
248
249     This->pFuncsTable = pBaseFuncsTable;
250
251     /* construct input pin */
252     piInput.dir = PINDIR_INPUT;
253     piInput.pFilter = &This->filter.IBaseFilter_iface;
254     lstrcpynW(piInput.achName, wcsInputPinName, sizeof(piInput.achName) / sizeof(piInput.achName[0]));
255
256     hr = BaseInputPin_Construct(&BaseRenderer_InputPin_Vtbl, &piInput, &input_BaseFuncTable, &input_BaseInputFuncTable, &This->filter.csFilter, NULL, (IPin **)&This->pInputPin);
257
258     if (SUCCEEDED(hr))
259     {
260         hr = CreatePosPassThru(pUnkOuter ? pUnkOuter: (IUnknown*)This, TRUE, &This->pInputPin->pin.IPin_iface, &This->pPosition);
261         if (FAILED(hr))
262             return hr;
263
264         InitializeCriticalSection(&This->csRenderLock);
265         This->csRenderLock.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__": BaseRenderer.csRenderLock");
266         This->evComplete = CreateEventW(NULL, TRUE, TRUE, NULL);
267         This->ThreadSignal = CreateEventW(NULL, TRUE, TRUE, NULL);
268         This->RenderEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
269         This->pMediaSample = NULL;
270
271         QualityControlImpl_Create(&This->pInputPin->pin.IPin_iface, &This->filter.IBaseFilter_iface, &This->qcimpl);
272         This->qcimpl->IQualityControl_iface.lpVtbl = &Renderer_QualityControl_Vtbl;
273     }
274
275     return hr;
276 }
277
278 HRESULT WINAPI BaseRendererImpl_QueryInterface(IBaseFilter* iface, REFIID riid, LPVOID * ppv)
279 {
280     BaseRenderer *This = impl_from_IBaseFilter(iface);
281
282     if (IsEqualIID(riid, &IID_IMediaSeeking) || IsEqualIID(riid, &IID_IMediaPosition))
283         return IUnknown_QueryInterface(This->pPosition, riid, ppv);
284     else if (IsEqualIID(riid, &IID_IQualityControl))
285     {
286         *ppv = &This->qcimpl->IQualityControl_iface;
287         IUnknown_AddRef((IUnknown *)(*ppv));
288         return S_OK;
289     }
290     else
291         return BaseFilterImpl_QueryInterface(iface, riid, ppv);
292 }
293
294 ULONG WINAPI BaseRendererImpl_Release(IBaseFilter* iface)
295 {
296     BaseRenderer *This = impl_from_IBaseFilter(iface);
297     ULONG refCount = BaseFilterImpl_Release(iface);
298
299     if (!refCount)
300     {
301         IPin *pConnectedTo;
302
303         if (SUCCEEDED(IPin_ConnectedTo(&This->pInputPin->pin.IPin_iface, &pConnectedTo)))
304         {
305             IPin_Disconnect(pConnectedTo);
306             IPin_Release(pConnectedTo);
307         }
308         IPin_Disconnect(&This->pInputPin->pin.IPin_iface);
309         IPin_Release(&This->pInputPin->pin.IPin_iface);
310
311         if (This->pPosition)
312             IUnknown_Release(This->pPosition);
313
314         This->csRenderLock.DebugInfo->Spare[0] = 0;
315         DeleteCriticalSection(&This->csRenderLock);
316
317         BaseRendererImpl_ClearPendingSample(This);
318         CloseHandle(This->evComplete);
319         CloseHandle(This->ThreadSignal);
320         CloseHandle(This->RenderEvent);
321         QualityControlImpl_Destroy(This->qcimpl);
322     }
323     return refCount;
324 }
325
326 HRESULT WINAPI BaseRendererImpl_Receive(BaseRenderer *This, IMediaSample * pSample)
327 {
328     HRESULT hr = S_OK;
329     REFERENCE_TIME start, stop;
330     AM_MEDIA_TYPE *pmt;
331
332     TRACE("(%p)->%p\n", This, pSample);
333
334     if (This->pInputPin->end_of_stream || This->pInputPin->flushing)
335         return S_FALSE;
336
337     if (This->filter.state == State_Stopped)
338         return VFW_E_WRONG_STATE;
339
340     if (IMediaSample_GetMediaType(pSample, &pmt) == S_OK)
341     {
342         if (FAILED(This->pFuncsTable->pfnCheckMediaType(This, pmt)))
343         {
344             return VFW_E_TYPE_NOT_ACCEPTED;
345         }
346     }
347
348     This->pMediaSample = pSample;
349     IMediaSample_AddRef(pSample);
350
351     if (This->pFuncsTable->pfnPrepareReceive)
352         hr = This->pFuncsTable->pfnPrepareReceive(This, pSample);
353     if (FAILED(hr))
354     {
355         if (hr == VFW_E_SAMPLE_REJECTED)
356             return S_OK;
357         else
358             return hr;
359     }
360
361     if (This->pFuncsTable->pfnPrepareRender)
362         This->pFuncsTable->pfnPrepareRender(This);
363
364     EnterCriticalSection(&This->csRenderLock);
365     if ( This->filter.state == State_Paused )
366     {
367         if (This->pFuncsTable->pfnOnReceiveFirstSample)
368             This->pFuncsTable->pfnOnReceiveFirstSample(This, pSample);
369
370         SetEvent(This->evComplete);
371     }
372
373     /* Wait for render Time */
374     if (SUCCEEDED(IMediaSample_GetMediaTime(pSample, &start, &stop)))
375     {
376         hr = S_FALSE;
377         RendererPosPassThru_RegisterMediaTime(This->pPosition, start);
378         if (This->pFuncsTable->pfnShouldDrawSampleNow)
379             hr = This->pFuncsTable->pfnShouldDrawSampleNow(This, pSample, &start, &stop);
380
381         if (hr == S_OK)
382             ;/* Do not wait: drop through */
383         else if (hr == S_FALSE)
384         {
385             if (This->pFuncsTable->pfnOnWaitStart)
386                 This->pFuncsTable->pfnOnWaitStart(This);
387
388             LeaveCriticalSection(&This->csRenderLock);
389             hr = QualityControlRender_WaitFor(This->qcimpl, pSample, This->RenderEvent);
390             EnterCriticalSection(&This->csRenderLock);
391
392             if (This->pFuncsTable->pfnOnWaitEnd)
393                 This->pFuncsTable->pfnOnWaitEnd(This);
394         }
395         else
396         {
397             LeaveCriticalSection(&This->csRenderLock);
398             /* Drop Sample */
399             return S_OK;
400         }
401     }
402
403     if (SUCCEEDED(hr))
404     {
405         QualityControlRender_BeginRender(This->qcimpl);
406         hr = This->pFuncsTable->pfnDoRenderSample(This, pSample);
407         QualityControlRender_EndRender(This->qcimpl);
408     }
409
410     QualityControlRender_DoQOS(This->qcimpl);
411
412     BaseRendererImpl_ClearPendingSample(This);
413     LeaveCriticalSection(&This->csRenderLock);
414
415     return hr;
416 }
417
418 HRESULT WINAPI BaseRendererImpl_FindPin(IBaseFilter * iface, LPCWSTR Id, IPin **ppPin)
419 {
420     BaseRenderer *This = impl_from_IBaseFilter(iface);
421
422     TRACE("(%p)->(%s,%p)\n", This, debugstr_w(Id), ppPin);
423
424     if (!Id || !ppPin)
425         return E_POINTER;
426
427     if (!lstrcmpiW(Id,wcsInputPinName) || !lstrcmpiW(Id,wcsAltInputPinName))
428     {
429         *ppPin = &This->pInputPin->pin.IPin_iface;
430         IPin_AddRef(*ppPin);
431         return S_OK;
432     }
433     *ppPin = NULL;
434     return VFW_E_NOT_FOUND;
435 }
436
437 HRESULT WINAPI BaseRendererImpl_Stop(IBaseFilter * iface)
438 {
439     BaseRenderer *This = impl_from_IBaseFilter(iface);
440
441     TRACE("(%p)->()\n", This);
442
443     EnterCriticalSection(&This->csRenderLock);
444     {
445         RendererPosPassThru_ResetMediaTime(This->pPosition);
446         if (This->pFuncsTable->pfnOnStopStreaming)
447             This->pFuncsTable->pfnOnStopStreaming(This);
448         This->filter.state = State_Stopped;
449         SetEvent(This->evComplete);
450         SetEvent(This->ThreadSignal);
451         SetEvent(This->RenderEvent);
452     }
453     LeaveCriticalSection(&This->csRenderLock);
454
455     return S_OK;
456 }
457
458 HRESULT WINAPI BaseRendererImpl_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
459 {
460     HRESULT hr = S_OK;
461     BaseRenderer *This = impl_from_IBaseFilter(iface);
462     TRACE("(%p)->(%s)\n", This, wine_dbgstr_longlong(tStart));
463
464     EnterCriticalSection(&This->csRenderLock);
465     This->filter.rtStreamStart = tStart;
466     if (This->filter.state == State_Running)
467         goto out;
468
469     SetEvent(This->evComplete);
470     ResetEvent(This->ThreadSignal);
471
472     if (This->pInputPin->pin.pConnectedTo)
473     {
474         This->pInputPin->end_of_stream = 0;
475     }
476     else if (This->filter.filterInfo.pGraph)
477     {
478         IMediaEventSink *pEventSink;
479         hr = IFilterGraph_QueryInterface(This->filter.filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
480         if (SUCCEEDED(hr))
481         {
482             hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, (LONG_PTR)This);
483             IMediaEventSink_Release(pEventSink);
484         }
485         hr = S_OK;
486     }
487     if (SUCCEEDED(hr))
488     {
489         QualityControlRender_Start(This->qcimpl, This->filter.rtStreamStart);
490         if (This->pFuncsTable->pfnOnStartStreaming)
491             This->pFuncsTable->pfnOnStartStreaming(This);
492         if (This->filter.state == State_Stopped)
493             BaseRendererImpl_ClearPendingSample(This);
494         SetEvent(This->RenderEvent);
495         This->filter.state = State_Running;
496     }
497 out:
498     LeaveCriticalSection(&This->csRenderLock);
499
500     return hr;
501 }
502
503 HRESULT WINAPI BaseRendererImpl_Pause(IBaseFilter * iface)
504 {
505     BaseRenderer *This = impl_from_IBaseFilter(iface);
506
507     TRACE("(%p)->()\n", This);
508
509     EnterCriticalSection(&This->csRenderLock);
510     {
511      if (This->filter.state != State_Paused)
512         {
513             if (This->filter.state == State_Stopped)
514             {
515                 if (This->pInputPin->pin.pConnectedTo)
516                     ResetEvent(This->evComplete);
517                 This->pInputPin->end_of_stream = 0;
518             }
519             else if (This->pFuncsTable->pfnOnStopStreaming)
520                 This->pFuncsTable->pfnOnStopStreaming(This);
521
522             if (This->filter.state == State_Stopped)
523                 BaseRendererImpl_ClearPendingSample(This);
524             ResetEvent(This->RenderEvent);
525             This->filter.state = State_Paused;
526         }
527     }
528     ResetEvent(This->ThreadSignal);
529     LeaveCriticalSection(&This->csRenderLock);
530
531     return S_OK;
532 }
533
534 HRESULT WINAPI BaseRendererImpl_SetSyncSource(IBaseFilter *iface, IReferenceClock *clock)
535 {
536     BaseRenderer *This = impl_from_IBaseFilter(iface);
537     HRESULT hr;
538
539     EnterCriticalSection(&This->filter.csFilter);
540     QualityControlRender_SetClock(This->qcimpl, clock);
541     hr = BaseFilterImpl_SetSyncSource(iface, clock);
542     LeaveCriticalSection(&This->filter.csFilter);
543     return hr;
544 }
545
546
547 HRESULT WINAPI BaseRendererImpl_GetState(IBaseFilter * iface, DWORD dwMilliSecsTimeout, FILTER_STATE *pState)
548 {
549     HRESULT hr;
550     BaseRenderer *This = impl_from_IBaseFilter(iface);
551
552     TRACE("(%p)->(%d, %p)\n", This, dwMilliSecsTimeout, pState);
553
554     if (WaitForSingleObject(This->evComplete, dwMilliSecsTimeout) == WAIT_TIMEOUT)
555         hr = VFW_S_STATE_INTERMEDIATE;
556     else
557         hr = S_OK;
558
559     BaseFilterImpl_GetState(iface, dwMilliSecsTimeout, pState);
560
561     return hr;
562 }
563
564 HRESULT WINAPI BaseRendererImpl_EndOfStream(BaseRenderer* iface)
565 {
566     IMediaEventSink* pEventSink;
567     IFilterGraph *graph;
568     HRESULT hr = S_OK;
569
570     TRACE("(%p)\n", iface);
571
572     graph = iface->filter.filterInfo.pGraph;
573     if (graph)
574     {        hr = IFilterGraph_QueryInterface(iface->filter.filterInfo.pGraph, &IID_IMediaEventSink, (LPVOID*)&pEventSink);
575         if (SUCCEEDED(hr))
576         {
577             hr = IMediaEventSink_Notify(pEventSink, EC_COMPLETE, S_OK, (LONG_PTR)iface);
578             IMediaEventSink_Release(pEventSink);
579         }
580     }
581     RendererPosPassThru_EOS(iface->pPosition);
582     SetEvent(iface->evComplete);
583
584     return hr;
585 }
586
587 HRESULT WINAPI BaseRendererImpl_BeginFlush(BaseRenderer* iface)
588 {
589     TRACE("(%p)\n", iface);
590     BaseRendererImpl_ClearPendingSample(iface);
591     SetEvent(iface->ThreadSignal);
592     SetEvent(iface->RenderEvent);
593     return S_OK;
594 }
595
596 HRESULT WINAPI BaseRendererImpl_EndFlush(BaseRenderer* iface)
597 {
598     TRACE("(%p)\n", iface);
599     QualityControlRender_Start(iface->qcimpl, iface->filter.rtStreamStart);
600     RendererPosPassThru_ResetMediaTime(iface->pPosition);
601     ResetEvent(iface->ThreadSignal);
602     ResetEvent(iface->RenderEvent);
603     return S_OK;
604 }
605
606 HRESULT WINAPI BaseRendererImpl_ClearPendingSample(BaseRenderer *iface)
607 {
608     if (iface->pMediaSample)
609     {
610         IMediaSample_Release(iface->pMediaSample);
611         iface->pMediaSample = NULL;
612     }
613     return S_OK;
614 }