Index: /dsfilters/dec_mpc/dec_mpc.vcproj
===================================================================
--- /dsfilters/dec_mpc/dec_mpc.vcproj	(revision 372)
+++ /dsfilters/dec_mpc/dec_mpc.vcproj	(revision 373)
@@ -69,5 +69,5 @@
 				GenerateDebugInformation="true"
 				SubSystem="2"
-				EntryPointSymbol="DllEntryPoint@12"
+				EntryPointSymbol="FilterDllMain"
 				TargetMachine="1"
 			/>
@@ -150,5 +150,5 @@
 				OptimizeReferences="2"
 				EnableCOMDATFolding="2"
-				EntryPointSymbol="DllEntryPoint@12"
+				EntryPointSymbol="FilterDllMain"
 				TargetMachine="1"
 			/>
Index: /dsfilters/dec_mpc/src/mpc_filter.cpp
===================================================================
--- /dsfilters/dec_mpc/src/mpc_filter.cpp	(revision 372)
+++ /dsfilters/dec_mpc/src/mpc_filter.cpp	(revision 373)
@@ -7,4 +7,5 @@
 //-----------------------------------------------------------------------------
 #include "stdafx.h"
+
 
 
@@ -283,5 +284,13 @@
 HRESULT CMPCDecoder::Receive(IMediaSample *pSample)
 {
-	if (!m_pOutput->IsConnected()) return NOERROR;
+	if (!m_pOutput->IsConnected()) {
+		return E_FAIL;
+	}
+
+	// we don't accept data while flushing
+	if (m_pInput->IsFlushing()) {
+		return E_UNEXPECTED;
+	}
+
 
 	// we receive whole AP packets so just decode the frames :D
@@ -295,11 +304,4 @@
 	reader.AppendSE();
 
-	// manually clear the buffer for demuxer
-	demux->bytes_total = 0;
-	demux->bits_reader.buff = demux->buffer;
-	demux->bits_reader.count = 8;
-	demux->block_bits = 0;
-	demux->block_frames = 0;
-
 	// TODO: use some more clever way of doing this.
 	MPC_SAMPLE_FORMAT	samples[1152 * 8];
@@ -322,6 +324,15 @@
 	}
 
+	// manually clear the buffer for demuxer
+	demux->bytes_total = reader.size; // 0
+	demux->bits_reader.buff = reader.buf; //d->buffer;
+	demux->bits_reader.count = 8;
+	demux->block_bits = 0;
+	demux->block_frames = 0;
+	demux->d->decoded_samples = 0;
+
 	// now scan through the frames
-	while (true) {
+	int frame_cnt = 1 << stream_info.block_pwr;
+	for (int i=0; i<frame_cnt; i++) {
 
 		//---------------------------------------------------------------------
@@ -336,6 +347,11 @@
 		// decode one frame
 		err = mpc_demux_decode(demux, &frame);
-		if (err != MPC_STATUS_OK) break;
-		if (frame.bits == -1) break;				// done.
+		if (err != MPC_STATUS_OK) {
+			break;
+		}
+		if (frame.bits == -1) {
+			break;				// done.
+		}
+
 
 		//---------------------------------------------------------------------
@@ -352,4 +368,5 @@
 				__int64 to_skip = min(frame.samples, samples_to_skip);
 				decoded_time_samples -= to_skip;
+				samples_to_skip		 -= to_skip;
 				current_sample	 	 += to_skip;
 				src_samples			 += (to_skip * stream_info.channels);
Index: /dsfilters/dec_mpc/src/mpc_reg.cpp
===================================================================
--- /dsfilters/dec_mpc/src/mpc_reg.cpp	(revision 372)
+++ /dsfilters/dec_mpc/src/mpc_reg.cpp	(revision 373)
@@ -101,2 +101,15 @@
 }
 
+// The one and only application object
+CWinApp theApp;
+using namespace std;
+
+
+extern "C" BOOL WINAPI _DllMainCRTStartup(HINSTANCE, ULONG, LPVOID);
+extern "C" BOOL WINAPI DllEntryPoint(HINSTANCE, ULONG, LPVOID);
+
+BOOL APIENTRY FilterDllMain(HANDLE hModule, DWORD  dwReason, LPVOID lpReserved)
+{
+	_DllMainCRTStartup((HINSTANCE)hModule, dwReason, lpReserved);
+	return DllEntryPoint((HINSTANCE)(hModule), dwReason, lpReserved);
+}
Index: /dsfilters/dec_mpc/src/stdafx.h
===================================================================
--- /dsfilters/dec_mpc/src/stdafx.h	(revision 372)
+++ /dsfilters/dec_mpc/src/stdafx.h	(revision 373)
@@ -59,5 +59,5 @@
 #include "mpc\streaminfo.h"
 #include "internal.h"
-
+#include "decoder.h"
 
 
Index: /dsfilters/demux_mpc/demux_mpc.vcproj
===================================================================
--- /dsfilters/demux_mpc/demux_mpc.vcproj	(revision 372)
+++ /dsfilters/demux_mpc/demux_mpc.vcproj	(revision 373)
@@ -69,5 +69,5 @@
 				GenerateDebugInformation="true"
 				SubSystem="2"
-				EntryPointSymbol="DllEntryPoint@12"
+				EntryPointSymbol="FilterDllMain"
 				TargetMachine="1"
 			/>
@@ -150,5 +150,5 @@
 				OptimizeReferences="2"
 				EnableCOMDATFolding="2"
-				EntryPointSymbol="DllEntryPoint@12"
+				EntryPointSymbol="FilterDllMain"
 				TargetMachine="1"
 			/>
Index: /dsfilters/demux_mpc/src/mpc_file.cpp
===================================================================
--- /dsfilters/demux_mpc/src/mpc_file.cpp	(revision 372)
+++ /dsfilters/demux_mpc/src/mpc_file.cpp	(revision 373)
@@ -329,9 +329,11 @@
 	// seek to position
 	uint32 pos = seek_table[i] >> 3;
+	CString f;
+	f.Format(_T("CMPCFile::Seek : %d"), pos);
 	reader->Seek(pos);
 
 	// shift back
 	i = i << (seek_pwr - block_pwr);
-	current_sample = i*audio_block_frames;
+	current_sample = i*1152*audio_block_frames;
 
 	return 0;
Index: /dsfilters/demux_mpc/src/mpc_filter.cpp
===================================================================
--- /dsfilters/demux_mpc/src/mpc_filter.cpp	(revision 372)
+++ /dsfilters/demux_mpc/src/mpc_filter.cpp	(revision 373)
@@ -54,5 +54,6 @@
 	rtStop(0xFFFFFFFFFFFFFF),
 	rate(1.0),
-	ev_abort(TRUE)
+	ev_abort(TRUE),
+	ev_seek_ready(TRUE)
 {
 	input = new CMPCInputPin(NAME("MPC Input Pin"), this, phr, L"In");
@@ -61,4 +62,5 @@
 
 	ev_abort.Reset();
+	ev_seek_ready.Set();
 }
 
@@ -311,4 +313,229 @@
 }
 
+
+
+// IMediaSeeking
+
+STDMETHODIMP CMPCDemux::GetCapabilities(DWORD* pCapabilities)
+{
+	return pCapabilities ? *pCapabilities =	
+			AM_SEEKING_CanGetStopPos|AM_SEEKING_CanGetDuration|AM_SEEKING_CanSeekAbsolute|AM_SEEKING_CanSeekForwards|AM_SEEKING_CanSeekBackwards, 
+			S_OK : E_POINTER;
+}
+STDMETHODIMP CMPCDemux::CheckCapabilities(DWORD* pCapabilities)
+{
+	CheckPointer(pCapabilities, E_POINTER);
+	if (*pCapabilities == 0) return S_OK;
+	DWORD caps;
+	GetCapabilities(&caps);
+	if ((caps&*pCapabilities) == 0) return E_FAIL;
+	if (caps == *pCapabilities) return S_OK;
+	return S_FALSE;
+}
+STDMETHODIMP CMPCDemux::IsFormatSupported(const GUID* pFormat) {return !pFormat ? E_POINTER : *pFormat == TIME_FORMAT_MEDIA_TIME ? S_OK : S_FALSE;}
+STDMETHODIMP CMPCDemux::QueryPreferredFormat(GUID* pFormat) {return GetTimeFormat(pFormat);}
+STDMETHODIMP CMPCDemux::GetTimeFormat(GUID* pFormat) {return pFormat ? *pFormat = TIME_FORMAT_MEDIA_TIME, S_OK : E_POINTER;}
+STDMETHODIMP CMPCDemux::IsUsingTimeFormat(const GUID* pFormat) {return IsFormatSupported(pFormat);}
+STDMETHODIMP CMPCDemux::SetTimeFormat(const GUID* pFormat) {return S_OK == IsFormatSupported(pFormat) ? S_OK : E_INVALIDARG;}
+STDMETHODIMP CMPCDemux::GetStopPosition(LONGLONG* pStop) {return this->rtStop; }
+STDMETHODIMP CMPCDemux::GetCurrentPosition(LONGLONG* pCurrent) {return E_NOTIMPL;}
+STDMETHODIMP CMPCDemux::ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat) {return E_NOTIMPL;}
+
+STDMETHODIMP CMPCDemux::SetPositions(LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags)
+{
+	return SetPositionsInternal(0, pCurrent, dwCurrentFlags, pStop, dwStopFlags);
+}
+
+STDMETHODIMP CMPCDemux::GetPositions(LONGLONG* pCurrent, LONGLONG* pStop)
+{
+	if(pCurrent) *pCurrent = rtCurrent;
+	if(pStop) *pStop = rtStop;
+	return S_OK;
+}
+STDMETHODIMP CMPCDemux::GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest)
+{
+	if(pEarliest) *pEarliest = 0;
+	return GetDuration(pLatest);
+}
+STDMETHODIMP CMPCDemux::SetRate(double dRate) {return dRate > 0 ? rate = dRate, S_OK : E_INVALIDARG;}
+STDMETHODIMP CMPCDemux::GetRate(double* pdRate) {return pdRate ? *pdRate = rate, S_OK : E_POINTER;}
+STDMETHODIMP CMPCDemux::GetPreroll(LONGLONG* pllPreroll) {return pllPreroll ? *pllPreroll = 0, S_OK : E_POINTER;}
+
+STDMETHODIMP CMPCDemux::GetDuration(LONGLONG* pDuration) 
+{	
+	CheckPointer(pDuration, E_POINTER); 
+	*pDuration = 0;
+
+	if (file) {
+		if (pDuration) *pDuration = file->duration_10mhz;
+	}
+	return S_OK;
+}
+
+STDMETHODIMP CMPCDemux::SetPositionsInternal(int iD, LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags)
+{
+	// only our first pin can seek
+	if (iD != 0) return NOERROR;
+
+
+	CAutoLock cAutoLock(&lock_filter);
+
+	if (!pCurrent && !pStop || (dwCurrentFlags&AM_SEEKING_PositioningBitsMask) == AM_SEEKING_NoPositioning 
+		&& (dwStopFlags&AM_SEEKING_PositioningBitsMask) == AM_SEEKING_NoPositioning)
+		return S_OK;
+
+	REFERENCE_TIME rtCurrent = this->rtCurrent, rtStop = this->rtStop;
+
+	if (pCurrent) {
+		switch(dwCurrentFlags&AM_SEEKING_PositioningBitsMask) {
+		case AM_SEEKING_NoPositioning: break;
+		case AM_SEEKING_AbsolutePositioning: rtCurrent = *pCurrent; break;
+		case AM_SEEKING_RelativePositioning: rtCurrent = rtCurrent + *pCurrent; break;
+		case AM_SEEKING_IncrementalPositioning: rtCurrent = rtCurrent + *pCurrent; break;
+		}
+	}
+
+	if (pStop) {
+		switch(dwStopFlags&AM_SEEKING_PositioningBitsMask) {
+		case AM_SEEKING_NoPositioning: break;
+		case AM_SEEKING_AbsolutePositioning: rtStop = *pStop; break;
+		case AM_SEEKING_RelativePositioning: rtStop += *pStop; break;
+		case AM_SEEKING_IncrementalPositioning: rtStop = rtCurrent + *pStop; break;
+		}
+	}
+
+	if (this->rtCurrent == rtCurrent && this->rtStop == rtStop) {
+		return S_OK;
+	}
+
+	this->rtCurrent = rtCurrent;
+	this->rtStop = rtStop;
+
+	// now there are new valid Current and Stop positions
+	ev_seek_ready.Wait();
+	ev_seek_ready.Reset();
+	HRESULT hr = DoNewSeek();
+	ev_seek_ready.Set();
+	return hr;
+}
+
+
+STDMETHODIMP CMPCDemux::Pause()
+{
+	CAutoLock	lck(&lock_filter);
+
+	if (m_State == State_Stopped) {
+
+		ev_abort.Reset();
+
+		// activate pins
+		for (int i=0; i<output.GetCount(); i++) output[i]->Active();
+		if (input) input->Active();
+
+		// seekneme na danu poziciu
+		DoNewSeek();
+
+		// pustime parser thread
+		if (!ThreadExists()) {
+			Create();
+			CallWorker(CMD_RUN);
+		}
+	}
+
+	m_State = State_Paused;
+	return NOERROR;
+}
+
+STDMETHODIMP CMPCDemux::Stop()
+{
+	CAutoLock	lock(&lock_filter);
+	HRESULT		hr = NOERROR;
+
+	if (m_State != State_Stopped) {
+
+		// set abort
+		ev_abort.Set();
+		if (reader) reader->BeginFlush();
+
+		// deaktivujeme piny
+		if (input) input->Inactive();
+		for (int i=0; i<output.GetCount(); i++) output[i]->Inactive();
+
+		// zrusime parser thread
+		if (ThreadExists()) {
+			CallWorker(CMD_EXIT);
+			Close();
+		}
+
+		if (reader) reader->EndFlush();
+		ev_abort.Reset();
+	}
+
+
+	m_State = State_Stopped;
+	return hr;
+}
+
+
+HRESULT CMPCDemux::DoNewSeek()
+{
+	CMPCOutputPin	*pin = output[0];
+	HRESULT			hr;
+
+	if (!pin->IsConnected()) return NOERROR;
+
+	// stop first
+	ev_abort.Set();
+	if (reader) reader->BeginFlush();
+
+	FILTER_STATE	state = m_State;
+
+	// abort
+	if (state != State_Stopped) {
+		if (pin->ThreadExists()) {
+			pin->ev_abort.Set();
+			hr = pin->DeliverBeginFlush();
+			if (FAILED(hr)) {
+				ASSERT(FALSE);
+			}
+			if (ThreadExists()) {
+				CallWorker(CMD_STOP);
+			}
+			pin->CallWorker(CMD_STOP);
+
+			hr = pin->DeliverEndFlush();
+			if (FAILED(hr)) {
+				ASSERT(FALSE);
+			}
+			pin->FlushQueue();
+		}
+	}
+
+	pin->DoNewSegment(rtCurrent, rtStop, rate);
+	if (reader) reader->EndFlush();
+
+	// seek the file
+	if (file) {
+		int64 sample_pos = (rtCurrent * file->sample_rate) / 10000000;
+		file->Seek(sample_pos);
+	}
+
+	ev_abort.Reset();
+
+	if (state != State_Stopped) {
+		// spustime aj jeho thread
+		pin->FlushQueue();
+		pin->ev_abort.Reset();
+		if (pin->ThreadExists()) {
+			pin->CallWorker(CMD_RUN);
+		}
+		if (ThreadExists()) {
+			CallWorker(CMD_RUN);
+		}
+	}
+
+	return NOERROR;
+}
+
 DWORD CMPCDemux::ThreadProc()
 {
@@ -318,5 +545,9 @@
 		switch (cmd) {
 		case CMD_EXIT:	Reply(NOERROR); return 0;
-		case CMD_STOP:	Reply(NOERROR); break;
+		case CMD_STOP:	
+			{
+				Reply(NOERROR); 
+			}
+			break;
 		case CMD_RUN:
 			{
@@ -361,10 +592,13 @@
 						REFERENCE_TIME	tStart = (current_sample * 10000000) / file->sample_rate;
 						REFERENCE_TIME	tStop  = ((current_sample + 1152*file->audio_block_frames) * 10000000) / file->sample_rate;
-						packet.tStart = tStart;
-						packet.tStop  = tStop;
+
+						packet.tStart = tStart - rtCurrent;
+						packet.tStop  = tStop  - rtCurrent;
 
 						// deliver packet
 						hr = output[0]->DeliverPacket(packet);
-						if (FAILED(hr)) break;
+						if (FAILED(hr)) {
+							break;
+						}
 
 						delivered++;
@@ -382,219 +616,2 @@
 }
 
-
-// IMediaSeeking
-
-STDMETHODIMP CMPCDemux::GetCapabilities(DWORD* pCapabilities)
-{
-	return pCapabilities ? *pCapabilities =	
-			AM_SEEKING_CanGetStopPos|AM_SEEKING_CanGetDuration|AM_SEEKING_CanSeekAbsolute|AM_SEEKING_CanSeekForwards|AM_SEEKING_CanSeekBackwards, 
-			S_OK : E_POINTER;
-}
-STDMETHODIMP CMPCDemux::CheckCapabilities(DWORD* pCapabilities)
-{
-	CheckPointer(pCapabilities, E_POINTER);
-	if (*pCapabilities == 0) return S_OK;
-	DWORD caps;
-	GetCapabilities(&caps);
-	if ((caps&*pCapabilities) == 0) return E_FAIL;
-	if (caps == *pCapabilities) return S_OK;
-	return S_FALSE;
-}
-STDMETHODIMP CMPCDemux::IsFormatSupported(const GUID* pFormat) {return !pFormat ? E_POINTER : *pFormat == TIME_FORMAT_MEDIA_TIME ? S_OK : S_FALSE;}
-STDMETHODIMP CMPCDemux::QueryPreferredFormat(GUID* pFormat) {return GetTimeFormat(pFormat);}
-STDMETHODIMP CMPCDemux::GetTimeFormat(GUID* pFormat) {return pFormat ? *pFormat = TIME_FORMAT_MEDIA_TIME, S_OK : E_POINTER;}
-STDMETHODIMP CMPCDemux::IsUsingTimeFormat(const GUID* pFormat) {return IsFormatSupported(pFormat);}
-STDMETHODIMP CMPCDemux::SetTimeFormat(const GUID* pFormat) {return S_OK == IsFormatSupported(pFormat) ? S_OK : E_INVALIDARG;}
-STDMETHODIMP CMPCDemux::GetStopPosition(LONGLONG* pStop) {return this->rtStop; }
-STDMETHODIMP CMPCDemux::GetCurrentPosition(LONGLONG* pCurrent) {return E_NOTIMPL;}
-STDMETHODIMP CMPCDemux::ConvertTimeFormat(LONGLONG* pTarget, const GUID* pTargetFormat, LONGLONG Source, const GUID* pSourceFormat) {return E_NOTIMPL;}
-
-STDMETHODIMP CMPCDemux::SetPositions(LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags)
-{
-	return SetPositionsInternal(0, pCurrent, dwCurrentFlags, pStop, dwStopFlags);
-}
-
-STDMETHODIMP CMPCDemux::GetPositions(LONGLONG* pCurrent, LONGLONG* pStop)
-{
-	if(pCurrent) *pCurrent = rtCurrent;
-	if(pStop) *pStop = rtStop;
-	return S_OK;
-}
-STDMETHODIMP CMPCDemux::GetAvailable(LONGLONG* pEarliest, LONGLONG* pLatest)
-{
-	if(pEarliest) *pEarliest = 0;
-	return GetDuration(pLatest);
-}
-STDMETHODIMP CMPCDemux::SetRate(double dRate) {return dRate > 0 ? rate = dRate, S_OK : E_INVALIDARG;}
-STDMETHODIMP CMPCDemux::GetRate(double* pdRate) {return pdRate ? *pdRate = rate, S_OK : E_POINTER;}
-STDMETHODIMP CMPCDemux::GetPreroll(LONGLONG* pllPreroll) {return pllPreroll ? *pllPreroll = 0, S_OK : E_POINTER;}
-
-STDMETHODIMP CMPCDemux::GetDuration(LONGLONG* pDuration) 
-{	
-	CheckPointer(pDuration, E_POINTER); 
-	*pDuration = 0;
-
-	if (file) {
-		if (pDuration) *pDuration = file->duration_10mhz;
-	}
-	return S_OK;
-}
-
-STDMETHODIMP CMPCDemux::SetPositionsInternal(int iD, LONGLONG* pCurrent, DWORD dwCurrentFlags, LONGLONG* pStop, DWORD dwStopFlags)
-{
-	// only our first pin can seek
-	if (iD != 0) return NOERROR;
-	CAutoLock cAutoLock(&lock_filter);
-
-	if (!pCurrent && !pStop || (dwCurrentFlags&AM_SEEKING_PositioningBitsMask) == AM_SEEKING_NoPositioning 
-		&& (dwStopFlags&AM_SEEKING_PositioningBitsMask) == AM_SEEKING_NoPositioning)
-		return S_OK;
-
-	REFERENCE_TIME rtCurrent = this->rtCurrent, rtStop = this->rtStop;
-
-	if (pCurrent) {
-		switch(dwCurrentFlags&AM_SEEKING_PositioningBitsMask) {
-		case AM_SEEKING_NoPositioning: break;
-		case AM_SEEKING_AbsolutePositioning: rtCurrent = *pCurrent; break;
-		case AM_SEEKING_RelativePositioning: rtCurrent = rtCurrent + *pCurrent; break;
-		case AM_SEEKING_IncrementalPositioning: rtCurrent = rtCurrent + *pCurrent; break;
-		}
-	}
-
-	if (pStop) {
-		switch(dwStopFlags&AM_SEEKING_PositioningBitsMask) {
-		case AM_SEEKING_NoPositioning: break;
-		case AM_SEEKING_AbsolutePositioning: rtStop = *pStop; break;
-		case AM_SEEKING_RelativePositioning: rtStop += *pStop; break;
-		case AM_SEEKING_IncrementalPositioning: rtStop = rtCurrent + *pStop; break;
-		}
-	}
-
-	if (this->rtCurrent == rtCurrent && this->rtStop == rtStop) return S_OK;
-
-	this->rtCurrent = rtCurrent;
-	this->rtStop = rtStop;
-
-	// now there are new valid Current and Stop positions
-	HRESULT hr = DoNewSeek();
-	return hr;
-}
-
-HRESULT CMPCDemux::DoNewSeek()
-{
-	// stop first
-	ev_abort.Set();
-	if (reader) reader->BeginFlush();
-
-	CMPCOutputPin	*pin = output[0];
-	FILTER_STATE	state = m_State;
-
-	if (pin->IsConnected()) {
-		// abort
-		if (state != State_Stopped) {
-			if (pin->ThreadExists()) {
-				pin->ev_abort.Set();
-				pin->DeliverBeginFlush();
-
-				pin->CallWorker(CMD_STOP);
-				pin->FlushQueue();
-			}
-		}
-	}
-
-	if (reader) reader->EndFlush();
-
-	if (pin->IsConnected()) {
-		if (state != State_Stopped) {
-			if (pin->ThreadExists()) {
-				pin->ev_abort.Reset();
-				pin->DeliverEndFlush();
-			}
-		}
-		pin->DoNewSegment(rtCurrent, rtStop, rate);
-	}
-
-	if (ThreadExists()) {
-		CallWorker(CMD_STOP);
-	}
-
-	// seek the file
-	if (file) {
-		int64 sample_pos = rtCurrent * file->sample_rate / 10000000;
-		file->Seek(sample_pos);
-	}
-
-	ev_abort.Reset();
-	if (ThreadExists()) {
-		CallWorker(CMD_RUN);
-	}
-
-	if (pin->IsConnected()) {
-		if (state != State_Stopped) {
-			// spustime aj jeho thread
-			if (pin->ThreadExists()) {
-				pin->FlushQueue();
-				pin->CallWorker(CMD_RUN);
-			}
-		}
-	}
-
-	return NOERROR;
-}
-
-
-STDMETHODIMP CMPCDemux::Pause()
-{
-	CAutoLock	lck(&lock_filter);
-
-	if (m_State == State_Stopped) {
-
-		ev_abort.Reset();
-
-		// activate pins
-		for (int i=0; i<output.GetCount(); i++) output[i]->Active();
-		if (input) input->Active();
-
-		// seekneme na danu poziciu
-		DoNewSeek();
-
-		// pustime parser thread
-		if (!ThreadExists()) {
-			Create();
-			CallWorker(CMD_RUN);
-		}
-	}
-
-	m_State = State_Paused;
-	return NOERROR;
-}
-
-STDMETHODIMP CMPCDemux::Stop()
-{
-	CAutoLock	lock(&lock_filter);
-	HRESULT		hr = NOERROR;
-
-	if (m_State != State_Stopped) {
-
-		// set abort
-		ev_abort.Set();
-		if (reader) reader->BeginFlush();
-
-		// deaktivujeme piny
-		if (input) input->Inactive();
-		for (int i=0; i<output.GetCount(); i++) output[i]->Inactive();
-
-		// zrusime parser thread
-		if (ThreadExists()) {
-			CallWorker(CMD_EXIT);
-			Close();
-		}
-
-		if (reader) reader->EndFlush();
-		ev_abort.Reset();
-	}
-
-
-	m_State = State_Stopped;
-	return hr;
-}
Index: /dsfilters/demux_mpc/src/mpc_filter.h
===================================================================
--- /dsfilters/demux_mpc/src/mpc_filter.h	(revision 372)
+++ /dsfilters/demux_mpc/src/mpc_filter.h	(revision 373)
@@ -36,4 +36,5 @@
 
 	CAMEvent					ev_abort;
+	CAMEvent					ev_seek_ready;
 
 	// times
Index: /dsfilters/demux_mpc/src/mpc_pin.cpp
===================================================================
--- /dsfilters/demux_mpc/src/mpc_pin.cpp	(revision 372)
+++ /dsfilters/demux_mpc/src/mpc_pin.cpp	(revision 373)
@@ -270,7 +270,4 @@
 HRESULT CMPCOutputPin::DoNewSegment(REFERENCE_TIME rtStart, REFERENCE_TIME rtStop, double dRate)
 {
-	DataPacket	*packet;
-	int ret = GetDataPacket(&packet);
-	if (ret < 0 || !packet) return E_FAIL;
 
 	// queue the EOS packet
@@ -280,15 +277,22 @@
 	eos_delivered = false;
 
-	{
-		CAutoLock	lck(&lock_queue);
-		packet->type = DataPacket::PACKET_TYPE_NEW_SEGMENT;
-		packet->rtStart = rtStart;
-		packet->rtStop = rtStop;
-		packet->rate = rate;
-		queue.AddTail(packet);
-		ev_can_read.Set();
+
+	if (1) {
+		return DeliverNewSegment(rtStart, rtStop, rate);
 		discontinuity = true;
-	}
-
+
+	} else {
+		DataPacket	*packet = new DataPacket();
+		{
+			CAutoLock	lck(&lock_queue);
+			packet->type = DataPacket::PACKET_TYPE_NEW_SEGMENT;
+			packet->rtStart = rtStart;
+			packet->rtStop = rtStop;
+			packet->rate = rate;
+			queue.AddTail(packet);
+			ev_can_read.Set();
+			discontinuity = true;
+		}
+	}
 	return NOERROR;
 }
@@ -352,6 +356,4 @@
 	if (ret < 0 || !outp) return E_FAIL;
 
-	REFERENCE_TIME start, stop;
-
 	outp->type	  = DataPacket::PACKET_TYPE_DATA;
 
@@ -421,5 +423,7 @@
 	IMediaSample	*sample;
 	HRESULT hr = GetDeliveryBuffer(&sample, NULL, NULL, 0);
-	if (FAILED(hr)) return E_FAIL;
+	if (FAILED(hr)) {
+		return E_FAIL;
+	}
 
 	// we should have enough space in there
@@ -496,5 +500,9 @@
 		switch (cmd) {
 		case CMD_EXIT:		Reply(0); return 0; break;
-		case CMD_STOP:		Reply(0); break;
+		case CMD_STOP:
+			{
+				Reply(0); 
+			}
+			break;
 		case CMD_RUN:
 			{
@@ -530,4 +538,7 @@
 							DeliverEndOfStream();
 						} else 
+						if (packet->type == DataPacket::PACKET_TYPE_NEW_SEGMENT) {
+							hr = DeliverNewSegment(packet->rtStart, packet->rtStop, packet->rate);
+						} else
 						if (packet->type == DataPacket::PACKET_TYPE_DATA) {
 							hr = DeliverDataPacket(*packet);
@@ -541,4 +552,5 @@
 					}
 				} while (!CheckRequest(&cmd2));
+
 			}
 			break;
@@ -614,4 +626,5 @@
 
 	// TODO: Caching here !!!!
+	//TRACE("    - read, %I64d, %d\n", position, size);
 
 	HRESULT hr = reader->SyncRead(position, size, (BYTE*)buf);
Index: /dsfilters/demux_mpc/src/mpc_reg.cpp
===================================================================
--- /dsfilters/demux_mpc/src/mpc_reg.cpp	(revision 372)
+++ /dsfilters/demux_mpc/src/mpc_reg.cpp	(revision 373)
@@ -136,2 +136,15 @@
 }
 
+// The one and only application object
+CWinApp theApp;
+using namespace std;
+
+
+extern "C" BOOL WINAPI _DllMainCRTStartup(HINSTANCE, ULONG, LPVOID);
+extern "C" BOOL WINAPI DllEntryPoint(HINSTANCE, ULONG, LPVOID);
+
+BOOL APIENTRY FilterDllMain(HANDLE hModule, DWORD  dwReason, LPVOID lpReserved)
+{
+	_DllMainCRTStartup((HINSTANCE)hModule, dwReason, lpReserved);
+	return DllEntryPoint((HINSTANCE)(hModule), dwReason, lpReserved);
+}
