Commit aac5fa34 authored by Alexandre Julliard's avatar Alexandre Julliard

Revert "quartz: Clean up pullpin code."

This reverts commit 3066116f.
parent 7a4d5750
...@@ -1233,7 +1233,6 @@ static HRESULT PullPin_Init(const IPinVtbl *PullPin_Vtbl, const PIN_INFO * pPinI ...@@ -1233,7 +1233,6 @@ static HRESULT PullPin_Init(const IPinVtbl *PullPin_Vtbl, const PIN_INFO * pPinI
pPinImpl->rtStop = ((LONGLONG)0x7fffffff << 32) | 0xffffffff; pPinImpl->rtStop = ((LONGLONG)0x7fffffff << 32) | 0xffffffff;
pPinImpl->dRate = 1.0; pPinImpl->dRate = 1.0;
pPinImpl->state = Req_Die; pPinImpl->state = Req_Die;
assert(pCustomRequest);
pPinImpl->fnCustomRequest = pCustomRequest; pPinImpl->fnCustomRequest = pCustomRequest;
pPinImpl->stop_playback = 1; pPinImpl->stop_playback = 1;
...@@ -1400,6 +1399,44 @@ ULONG WINAPI PullPin_Release(IPin *iface) ...@@ -1400,6 +1399,44 @@ ULONG WINAPI PullPin_Release(IPin *iface)
return refCount; return refCount;
} }
static HRESULT PullPin_Standard_Request(PullPin *This, BOOL start)
{
REFERENCE_TIME rtSampleStart;
REFERENCE_TIME rtSampleStop;
IMediaSample *sample = NULL;
HRESULT hr;
TRACE("Requesting sample!\n");
if (start)
This->rtNext = This->rtCurrent;
if (This->rtNext >= This->rtStop)
/* Last sample has already been queued, request nothing more */
return S_OK;
hr = IMemAllocator_GetBuffer(This->pAlloc, &sample, NULL, NULL, 0);
if (SUCCEEDED(hr))
{
rtSampleStart = This->rtNext;
rtSampleStop = rtSampleStart + MEDIATIME_FROM_BYTES(IMediaSample_GetSize(sample));
if (rtSampleStop > This->rtStop)
rtSampleStop = MEDIATIME_FROM_BYTES(ALIGNUP(BYTES_FROM_MEDIATIME(This->rtStop), This->cbAlign));
hr = IMediaSample_SetTime(sample, &rtSampleStart, &rtSampleStop);
This->rtCurrent = This->rtNext;
This->rtNext = rtSampleStop;
if (SUCCEEDED(hr))
hr = IAsyncReader_Request(This->pReader, sample, 0);
}
if (FAILED(hr))
FIXME("Failed to queue sample : %08x\n", hr);
return hr;
}
static void CALLBACK PullPin_Flush(PullPin *This) static void CALLBACK PullPin_Flush(PullPin *This)
{ {
IMediaSample *pSample; IMediaSample *pSample;
...@@ -1408,8 +1445,6 @@ static void CALLBACK PullPin_Flush(PullPin *This) ...@@ -1408,8 +1445,6 @@ static void CALLBACK PullPin_Flush(PullPin *This)
EnterCriticalSection(This->pin.pCritSec); EnterCriticalSection(This->pin.pCritSec);
if (This->pReader) if (This->pReader)
{ {
SendFurther((IPin *)This, deliver_beginflush, NULL, NULL );
/* Flush outstanding samples */ /* Flush outstanding samples */
IAsyncReader_BeginFlush(This->pReader); IAsyncReader_BeginFlush(This->pReader);
for (;;) for (;;)
...@@ -1422,12 +1457,13 @@ static void CALLBACK PullPin_Flush(PullPin *This) ...@@ -1422,12 +1457,13 @@ static void CALLBACK PullPin_Flush(PullPin *This)
break; break;
assert(!IMediaSample_GetActualDataLength(pSample)); assert(!IMediaSample_GetActualDataLength(pSample));
if (This->fnCustomRequest)
This->fnSampleProc(This->pin.pUserData, pSample, dwUser);
IMediaSample_Release(pSample); IMediaSample_Release(pSample);
} }
IAsyncReader_EndFlush(This->pReader); IAsyncReader_EndFlush(This->pReader);
SendFurther((IPin *)This, deliver_endflush, NULL, NULL );
This->fnCleanProc(This->pin.pUserData);
} }
LeaveCriticalSection(This->pin.pCritSec); LeaveCriticalSection(This->pin.pCritSec);
} }
...@@ -1454,7 +1490,10 @@ static void CALLBACK PullPin_Thread_Process(PullPin *This) ...@@ -1454,7 +1490,10 @@ static void CALLBACK PullPin_Thread_Process(PullPin *This)
} }
/* There is no sample in our buffer */ /* There is no sample in our buffer */
hr = This->fnCustomRequest(This->pin.pUserData); if (!This->fnCustomRequest)
hr = PullPin_Standard_Request(This, TRUE);
else
hr = This->fnCustomRequest(This->pin.pUserData);
if (FAILED(hr)) if (FAILED(hr))
ERR("Request error: %x\n", hr); ERR("Request error: %x\n", hr);
...@@ -1471,18 +1510,46 @@ static void CALLBACK PullPin_Thread_Process(PullPin *This) ...@@ -1471,18 +1510,46 @@ static void CALLBACK PullPin_Thread_Process(PullPin *This)
hr = IAsyncReader_WaitForNext(This->pReader, 10000, &pSample, &dwUser); hr = IAsyncReader_WaitForNext(This->pReader, 10000, &pSample, &dwUser);
if (SUCCEEDED(hr)) /* Calling fnCustomRequest is not specifically useful here: It can be handled inside fnSampleProc */
if (pSample && !This->fnCustomRequest)
hr = PullPin_Standard_Request(This, FALSE);
/* Return an empty sample on error to the implementation in case it does custom parsing, so it knows it's gone */
if (SUCCEEDED(hr) || (This->fnCustomRequest && pSample))
{ {
REFERENCE_TIME rtStart, rtStop; REFERENCE_TIME rtStart, rtStop;
BOOL rejected;
IMediaSample_GetTime(pSample, &rtStart, &rtStop); IMediaSample_GetTime(pSample, &rtStart, &rtStop);
hr = This->fnSampleProc(This->pin.pUserData, pSample, dwUser); do
{
hr = This->fnSampleProc(This->pin.pUserData, pSample, dwUser);
if (This->fnCustomRequest)
break;
rejected = FALSE;
if (This->rtCurrent == rtStart)
{
rejected = TRUE;
TRACE("DENIED!\n");
Sleep(10);
/* Maybe it's transient? */
}
/* rtNext = rtCurrent, because the next sample is already queued */
else if (rtStop != This->rtCurrent && rtStop < This->rtStop)
{
WARN("Position changed! rtStop: %u, rtCurrent: %u\n", (DWORD)BYTES_FROM_MEDIATIME(rtStop), (DWORD)BYTES_FROM_MEDIATIME(This->rtCurrent));
PullPin_Flush(This);
hr = PullPin_Standard_Request(This, TRUE);
}
} while (rejected && (This->rtCurrent < This->rtStop && hr == S_OK && !This->stop_playback));
} }
else else
{ {
/* FIXME: This is not well handled yet! */ /* FIXME: This is not well handled yet! */
ERR("Processing/wait error: %x\n", hr); ERR("Processing error: %x\n", hr);
} }
if (pSample) if (pSample)
...@@ -1697,6 +1764,12 @@ HRESULT WINAPI PullPin_BeginFlush(IPin * iface) ...@@ -1697,6 +1764,12 @@ HRESULT WINAPI PullPin_BeginFlush(IPin * iface)
PullPin *This = (PullPin *)iface; PullPin *This = (PullPin *)iface;
TRACE("(%p)->()\n", This); TRACE("(%p)->()\n", This);
EnterCriticalSection(This->pin.pCritSec);
{
SendFurther( iface, deliver_beginflush, NULL, NULL );
}
LeaveCriticalSection(This->pin.pCritSec);
EnterCriticalSection(&This->thread_lock); EnterCriticalSection(&This->thread_lock);
{ {
PullPin_WaitForStateChange(This, INFINITE); PullPin_WaitForStateChange(This, INFINITE);
...@@ -1706,14 +1779,15 @@ HRESULT WINAPI PullPin_BeginFlush(IPin * iface) ...@@ -1706,14 +1779,15 @@ HRESULT WINAPI PullPin_BeginFlush(IPin * iface)
PullPin_PauseProcessing(This); PullPin_PauseProcessing(This);
PullPin_WaitForStateChange(This, INFINITE); PullPin_WaitForStateChange(This, INFINITE);
} }
EnterCriticalSection(This->pin.pCritSec);
SendFurther( iface, deliver_beginflush, NULL, NULL );
LeaveCriticalSection(This->pin.pCritSec);
} }
LeaveCriticalSection(&This->thread_lock); LeaveCriticalSection(&This->thread_lock);
EnterCriticalSection(This->pin.pCritSec);
{
This->fnCleanProc(This->pin.pUserData);
}
LeaveCriticalSection(This->pin.pCritSec);
return S_OK; return S_OK;
} }
...@@ -1728,18 +1802,17 @@ HRESULT WINAPI PullPin_EndFlush(IPin * iface) ...@@ -1728,18 +1802,17 @@ HRESULT WINAPI PullPin_EndFlush(IPin * iface)
FILTER_STATE state; FILTER_STATE state;
IBaseFilter_GetState(This->pin.pinInfo.pFilter, INFINITE, &state); IBaseFilter_GetState(This->pin.pinInfo.pFilter, INFINITE, &state);
EnterCriticalSection(This->pin.pCritSec);
SendFurther( iface, deliver_endflush, NULL, NULL );
LeaveCriticalSection(This->pin.pCritSec);
if (This->stop_playback && state == State_Running) if (This->stop_playback && state == State_Running)
{
PullPin_StartProcessing(This); PullPin_StartProcessing(This);
PullPin_WaitForStateChange(This, INFINITE);
} PullPin_WaitForStateChange(This, INFINITE);
} }
LeaveCriticalSection(&This->thread_lock); LeaveCriticalSection(&This->thread_lock);
EnterCriticalSection(This->pin.pCritSec);
SendFurther( iface, deliver_endflush, NULL, NULL );
LeaveCriticalSection(This->pin.pCritSec);
return S_OK; return S_OK;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment