Commit 6aabf5d3 authored by Maarten Lankhorst's avatar Maarten Lankhorst Committed by Alexandre Julliard

quartz: Create thread after connection is made.

parent 33294331
...@@ -217,7 +217,6 @@ HRESULT WINAPI Parser_GetClassID(IBaseFilter * iface, CLSID * pClsid) ...@@ -217,7 +217,6 @@ HRESULT WINAPI Parser_GetClassID(IBaseFilter * iface, CLSID * pClsid)
HRESULT WINAPI Parser_Stop(IBaseFilter * iface) HRESULT WINAPI Parser_Stop(IBaseFilter * iface)
{ {
HRESULT hr;
ParserImpl *This = (ParserImpl *)iface; ParserImpl *This = (ParserImpl *)iface;
PullPin *pin = (PullPin *)This->ppPins[0]; PullPin *pin = (PullPin *)This->ppPins[0];
...@@ -226,19 +225,11 @@ HRESULT WINAPI Parser_Stop(IBaseFilter * iface) ...@@ -226,19 +225,11 @@ HRESULT WINAPI Parser_Stop(IBaseFilter * iface)
EnterCriticalSection(&pin->thread_lock); EnterCriticalSection(&pin->thread_lock);
EnterCriticalSection(&This->csFilter); EnterCriticalSection(&This->csFilter);
{ {
if (This->state == State_Stopped)
{
LeaveCriticalSection(&This->csFilter);
LeaveCriticalSection(&pin->thread_lock);
return S_OK;
}
This->state = State_Stopped; This->state = State_Stopped;
} }
LeaveCriticalSection(&This->csFilter); LeaveCriticalSection(&This->csFilter);
hr = PullPin_StopProcessing(This->pInputPin);
LeaveCriticalSection(&pin->thread_lock); LeaveCriticalSection(&pin->thread_lock);
return hr; return S_OK;
} }
HRESULT WINAPI Parser_Pause(IBaseFilter * iface) HRESULT WINAPI Parser_Pause(IBaseFilter * iface)
...@@ -300,16 +291,9 @@ HRESULT WINAPI Parser_Run(IBaseFilter * iface, REFERENCE_TIME tStart) ...@@ -300,16 +291,9 @@ HRESULT WINAPI Parser_Run(IBaseFilter * iface, REFERENCE_TIME tStart)
if (SUCCEEDED(hr) && (This->state == State_Stopped)) if (SUCCEEDED(hr) && (This->state == State_Stopped))
{ {
LeaveCriticalSection(&This->csFilter); for (i = 1; i < (This->cStreams + 1); i++)
hr = PullPin_InitProcessing(This->pInputPin); {
EnterCriticalSection(&This->csFilter); OutputPin_CommitAllocator((OutputPin *)This->ppPins[i]);
if (SUCCEEDED(hr))
{
for (i = 1; i < (This->cStreams + 1); i++)
{
OutputPin_CommitAllocator((OutputPin *)This->ppPins[i]);
}
} }
} }
...@@ -714,7 +698,6 @@ static HRESULT WINAPI Parser_PullPin_Disconnect(IPin * iface) ...@@ -714,7 +698,6 @@ static HRESULT WINAPI Parser_PullPin_Disconnect(IPin * iface)
{ {
if (This->pin.pConnectedTo) if (This->pin.pConnectedTo)
{ {
PullPin *ppin = (PullPin *)This;
FILTER_STATE state; FILTER_STATE state;
ParserImpl *Parser = (ParserImpl *)This->pin.pinInfo.pFilter; ParserImpl *Parser = (ParserImpl *)This->pin.pinInfo.pFilter;
...@@ -724,11 +707,9 @@ static HRESULT WINAPI Parser_PullPin_Disconnect(IPin * iface) ...@@ -724,11 +707,9 @@ static HRESULT WINAPI Parser_PullPin_Disconnect(IPin * iface)
if (SUCCEEDED(hr) && (state == State_Stopped) && SUCCEEDED(Parser->fnDisconnect(Parser))) if (SUCCEEDED(hr) && (state == State_Stopped) && SUCCEEDED(Parser->fnDisconnect(Parser)))
{ {
IPin_Release(This->pin.pConnectedTo); LeaveCriticalSection(This->pin.pCritSec);
This->pin.pConnectedTo = NULL; PullPin_Disconnect(iface);
EnterCriticalSection(This->pin.pCritSec);
if (FAILED(hr = IMemAllocator_Decommit(ppin->pAlloc)))
ERR("Allocator decommit failed with error %x. Possible memory leak\n", hr);
hr = Parser_RemoveOutputPins((ParserImpl *)This->pin.pinInfo.pFilter); hr = Parser_RemoveOutputPins((ParserImpl *)This->pin.pinInfo.pFilter);
} }
else else
......
...@@ -1277,6 +1277,8 @@ HRESULT PullPin_Construct(const IPinVtbl *PullPin_Vtbl, const PIN_INFO * pPinInf ...@@ -1277,6 +1277,8 @@ HRESULT PullPin_Construct(const IPinVtbl *PullPin_Vtbl, const PIN_INFO * pPinInf
return E_FAIL; return E_FAIL;
} }
static HRESULT PullPin_InitProcessing(PullPin * This);
HRESULT WINAPI PullPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt) HRESULT WINAPI PullPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt)
{ {
PIN_DIRECTION pindirReceive; PIN_DIRECTION pindirReceive;
...@@ -1334,9 +1336,11 @@ HRESULT WINAPI PullPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const ...@@ -1334,9 +1336,11 @@ HRESULT WINAPI PullPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const
This->pin.pConnectedTo = pReceivePin; This->pin.pConnectedTo = pReceivePin;
IPin_AddRef(pReceivePin); IPin_AddRef(pReceivePin);
hr = IMemAllocator_Commit(This->pAlloc); hr = IMemAllocator_Commit(This->pAlloc);
} }
if (SUCCEEDED(hr))
hr = PullPin_InitProcessing(This);
if (FAILED(hr)) if (FAILED(hr))
{ {
if (This->pReader) if (This->pReader)
...@@ -1407,44 +1411,6 @@ ULONG WINAPI PullPin_Release(IPin *iface) ...@@ -1407,44 +1411,6 @@ 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;
...@@ -1465,8 +1431,6 @@ static void CALLBACK PullPin_Flush(PullPin *This) ...@@ -1465,8 +1431,6 @@ 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);
} }
...@@ -1476,7 +1440,7 @@ static void CALLBACK PullPin_Flush(PullPin *This) ...@@ -1476,7 +1440,7 @@ static void CALLBACK PullPin_Flush(PullPin *This)
LeaveCriticalSection(This->pin.pCritSec); LeaveCriticalSection(This->pin.pCritSec);
} }
static void CALLBACK PullPin_Thread_Process(PullPin *This) static void CALLBACK PullPin_Thread_Process(PullPin *This, BOOL pause)
{ {
HRESULT hr; HRESULT hr;
IMediaSample * pSample = NULL; IMediaSample * pSample = NULL;
...@@ -1498,18 +1462,19 @@ static void CALLBACK PullPin_Thread_Process(PullPin *This) ...@@ -1498,18 +1462,19 @@ static void CALLBACK PullPin_Thread_Process(PullPin *This)
} }
/* There is no sample in our buffer */ /* There is no sample in our buffer */
if (!This->fnCustomRequest) hr = This->fnCustomRequest(This->pin.pUserData);
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);
EnterCriticalSection(This->pin.pCritSec); if (!pause)
SetEvent(This->hEventStateChanged); {
LeaveCriticalSection(This->pin.pCritSec); EnterCriticalSection(This->pin.pCritSec);
SetEvent(This->hEventStateChanged);
LeaveCriticalSection(This->pin.pCritSec);
}
if (SUCCEEDED(hr))
do do
{ {
DWORD_PTR dwUser; DWORD_PTR dwUser;
...@@ -1518,41 +1483,10 @@ static void CALLBACK PullPin_Thread_Process(PullPin *This) ...@@ -1518,41 +1483,10 @@ static void CALLBACK PullPin_Thread_Process(PullPin *This)
hr = IAsyncReader_WaitForNext(This->pReader, 10000, &pSample, &dwUser); hr = IAsyncReader_WaitForNext(This->pReader, 10000, &pSample, &dwUser);
/* 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 */ /* 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)) if (SUCCEEDED(hr))
{ {
REFERENCE_TIME rtStart, rtStop; hr = This->fnSampleProc(This->pin.pUserData, pSample, dwUser);
BOOL rejected;
IMediaSample_GetTime(pSample, &rtStart, &rtStop);
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
{ {
...@@ -1580,21 +1514,17 @@ static void CALLBACK PullPin_Thread_Process(PullPin *This) ...@@ -1580,21 +1514,17 @@ static void CALLBACK PullPin_Thread_Process(PullPin *This)
if (This->fnDone) if (This->fnDone)
This->fnDone(This->pin.pUserData); This->fnDone(This->pin.pUserData);
PullPin_Flush(This);
TRACE("End: %08x, %d\n", hr, This->stop_playback);
}
static void CALLBACK PullPin_Thread_Pause(PullPin *This)
{
TRACE("(%p)->()\n", This);
EnterCriticalSection(This->pin.pCritSec); if (pause)
{ {
EnterCriticalSection(This->pin.pCritSec);
This->state = Req_Sleepy; This->state = Req_Sleepy;
SetEvent(This->hEventStateChanged); SetEvent(This->hEventStateChanged);
LeaveCriticalSection(This->pin.pCritSec);
} }
LeaveCriticalSection(This->pin.pCritSec);
TRACE("End: %08x, %d\n", hr, This->stop_playback);
} }
static void CALLBACK PullPin_Thread_Stop(PullPin *This) static void CALLBACK PullPin_Thread_Stop(PullPin *This)
...@@ -1620,6 +1550,8 @@ static DWORD WINAPI PullPin_Thread_Main(LPVOID pv) ...@@ -1620,6 +1550,8 @@ static DWORD WINAPI PullPin_Thread_Main(LPVOID pv)
PullPin *This = pv; PullPin *This = pv;
CoInitializeEx(NULL, COINIT_MULTITHREADED); CoInitializeEx(NULL, COINIT_MULTITHREADED);
PullPin_Flush(This);
for (;;) for (;;)
{ {
WaitForSingleObject(This->thread_sleepy, INFINITE); WaitForSingleObject(This->thread_sleepy, INFINITE);
...@@ -1629,15 +1561,15 @@ static DWORD WINAPI PullPin_Thread_Main(LPVOID pv) ...@@ -1629,15 +1561,15 @@ static DWORD WINAPI PullPin_Thread_Main(LPVOID pv)
switch (This->state) switch (This->state)
{ {
case Req_Die: PullPin_Thread_Stop(This); break; case Req_Die: PullPin_Thread_Stop(This); break;
case Req_Run: PullPin_Thread_Process(This); break; case Req_Run: PullPin_Thread_Process(This, FALSE); break;
case Req_Pause: PullPin_Thread_Pause(This); break; case Req_Pause: PullPin_Thread_Process(This, TRUE); break;
case Req_Sleepy: ERR("Should not be signalled with SLEEPY!\n"); break; case Req_Sleepy: ERR("Should not be signalled with SLEEPY!\n"); break;
default: ERR("Unknown state request: %d\n", This->state); break; default: ERR("Unknown state request: %d\n", This->state); break;
} }
} }
} }
HRESULT PullPin_InitProcessing(PullPin * This) static HRESULT PullPin_InitProcessing(PullPin * This)
{ {
HRESULT hr = S_OK; HRESULT hr = S_OK;
...@@ -1716,8 +1648,6 @@ HRESULT PullPin_PauseProcessing(PullPin * This) ...@@ -1716,8 +1648,6 @@ HRESULT PullPin_PauseProcessing(PullPin * This)
PullPin_WaitForStateChange(This, INFINITE); PullPin_WaitForStateChange(This, INFINITE);
EnterCriticalSection(This->pin.pCritSec); EnterCriticalSection(This->pin.pCritSec);
/* Faster! */
IAsyncReader_BeginFlush(This->pReader);
assert(!This->stop_playback); assert(!This->stop_playback);
assert(This->state == Req_Run|| This->state == Req_Sleepy); assert(This->state == Req_Run|| This->state == Req_Sleepy);
...@@ -1734,7 +1664,7 @@ HRESULT PullPin_PauseProcessing(PullPin * This) ...@@ -1734,7 +1664,7 @@ HRESULT PullPin_PauseProcessing(PullPin * This)
return S_OK; return S_OK;
} }
HRESULT PullPin_StopProcessing(PullPin * This) static HRESULT PullPin_StopProcessing(PullPin * This)
{ {
TRACE("(%p)->()\n", This); TRACE("(%p)->()\n", This);
...@@ -1840,6 +1770,7 @@ HRESULT WINAPI PullPin_Disconnect(IPin *iface) ...@@ -1840,6 +1770,7 @@ HRESULT WINAPI PullPin_Disconnect(IPin *iface)
{ {
IPin_Release(This->pin.pConnectedTo); IPin_Release(This->pin.pConnectedTo);
This->pin.pConnectedTo = NULL; This->pin.pConnectedTo = NULL;
PullPin_StopProcessing(This);
hr = S_OK; hr = S_OK;
} }
else else
......
...@@ -204,6 +204,7 @@ HRESULT WINAPI MemInputPin_ReceiveCanBlock(IMemInputPin * iface); ...@@ -204,6 +204,7 @@ HRESULT WINAPI MemInputPin_ReceiveCanBlock(IMemInputPin * iface);
/* Pull Pin */ /* Pull Pin */
HRESULT WINAPI PullPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt); HRESULT WINAPI PullPin_ReceiveConnection(IPin * iface, IPin * pReceivePin, const AM_MEDIA_TYPE * pmt);
HRESULT WINAPI PullPin_Disconnect(IPin * iface);
HRESULT WINAPI PullPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv); HRESULT WINAPI PullPin_QueryInterface(IPin * iface, REFIID riid, LPVOID * ppv);
ULONG WINAPI PullPin_Release(IPin * iface); ULONG WINAPI PullPin_Release(IPin * iface);
HRESULT WINAPI PullPin_EndOfStream(IPin * iface); HRESULT WINAPI PullPin_EndOfStream(IPin * iface);
...@@ -212,8 +213,6 @@ HRESULT WINAPI PullPin_EndFlush(IPin * iface); ...@@ -212,8 +213,6 @@ HRESULT WINAPI PullPin_EndFlush(IPin * iface);
HRESULT WINAPI PullPin_NewSegment(IPin * iface, REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate); HRESULT WINAPI PullPin_NewSegment(IPin * iface, REFERENCE_TIME tStart, REFERENCE_TIME tStop, double dRate);
/* Thread interaction functions: Hold the thread_lock before calling them */ /* Thread interaction functions: Hold the thread_lock before calling them */
HRESULT PullPin_InitProcessing(PullPin * This);
HRESULT PullPin_StartProcessing(PullPin * This); HRESULT PullPin_StartProcessing(PullPin * This);
HRESULT PullPin_StopProcessing(PullPin * This);
HRESULT PullPin_PauseProcessing(PullPin * This); HRESULT PullPin_PauseProcessing(PullPin * This);
HRESULT PullPin_WaitForStateChange(PullPin * This, DWORD dwMilliseconds); HRESULT PullPin_WaitForStateChange(PullPin * This, DWORD dwMilliseconds);
...@@ -381,7 +381,7 @@ static HRESULT WAVEParser_first_request(LPVOID iface) ...@@ -381,7 +381,7 @@ static HRESULT WAVEParser_first_request(LPVOID iface)
hr = IAsyncReader_Request(pin->pReader, sample, 0); hr = IAsyncReader_Request(pin->pReader, sample, 0);
} }
if (FAILED(hr)) if (FAILED(hr))
ERR("Horsemen of the apocalypse came to bring error 0x%08x\n", hr); ERR("Horsemen of the apocalypse came to bring error 0x%08x %p\n", hr, sample);
return hr; return hr;
} }
......
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