Permalink
Browse files

v59 - Fixed crash on filter close/destruct. Added video PES size sani…

…ty check.
  • Loading branch information...
1 parent 7f8be14 commit 59e445a2d0ed6888e3aaa2960d65d02826c7141a @owlsroost owlsroost committed May 13, 2012
Binary file not shown.
@@ -219,6 +219,7 @@ HRESULT CAudioPin::CompleteConnect(IPin *pReceivePin)
m_bAddPMT = true;
//LogDebug("audPin:CompleteConnect()");
HRESULT hr = CBaseOutputPin::CompleteConnect(pReceivePin);
+ if (!SUCCEEDED(hr)) return E_FAIL;
PIN_INFO pinInfo;
FILTER_INFO filterInfo;
@@ -717,7 +718,7 @@ HRESULT CAudioPin::OnThreadStartPlay()
DWORD thrdID = GetCurrentThreadId();
LogDebug("audPin:OnThreadStartPlay(%f), rate:%02.2f, threadID:0x%x, GET_TIME_NOW:0x%x", (float)m_rtStart.Millisecs()/1000.0f, m_dRateSeeking, thrdID, GET_TIME_NOW());
- m_pTsReaderFilter->CheckForMPAR();
+ //m_pTsReaderFilter->CheckForMPAR();
//set flag to compensate any differences in the stream time & file time
m_pTsReaderFilter->m_bStreamCompensated = false;
@@ -516,16 +516,19 @@ void CDeMultiplexer::Flush(bool clearAVready)
m_bFlushRunning = true; //Stall GetVideo()/GetAudio()/GetSubtitle() calls from pins
- //Wait for output pin data sample delivery to stop - timeout after 100 loop iterations in case pin delivery threads are stalled
- int i = 0;
- while ((i < 100) && (m_filter.GetAudioPin()->IsInFillBuffer() || m_filter.GetVideoPin()->IsInFillBuffer() || m_filter.GetSubtitlePin()->IsInFillBuffer()) )
+ if (!m_bShuttingDown)
{
- Sleep(5);
- i++;
- }
- if (i >= 100)
- {
- LogDebug("demux: Flush: InFillBuffer() wait timeout, %d %d %d", m_filter.GetAudioPin()->IsInFillBuffer(), m_filter.GetVideoPin()->IsInFillBuffer(), m_filter.GetSubtitlePin()->IsInFillBuffer());
+ //Wait for output pin data sample delivery to stop - timeout after 100 loop iterations in case pin delivery threads are stalled
+ int i = 0;
+ while ((i < 100) && (m_filter.GetAudioPin()->IsInFillBuffer() || m_filter.GetVideoPin()->IsInFillBuffer() || m_filter.GetSubtitlePin()->IsInFillBuffer()) )
+ {
+ Sleep(5);
+ i++;
+ }
+ if (i >= 100)
+ {
+ LogDebug("demux: Flush: InFillBuffer() wait timeout, %d %d %d", m_filter.GetAudioPin()->IsInFillBuffer(), m_filter.GetVideoPin()->IsInFillBuffer(), m_filter.GetSubtitlePin()->IsInFillBuffer());
+ }
}
m_iAudioReadCount = 0;
@@ -1096,7 +1099,7 @@ void CDeMultiplexer::OnTsPacket(byte* tsPacket)
}
//Buffers about to be flushed
- if (m_bFlushDelgNow || m_bFlushRunning)
+ if (m_bFlushDelgNow || m_bFlushRunning || m_bShuttingDown)
{
return;
}
@@ -1351,11 +1354,6 @@ void CDeMultiplexer::FillVideo(CTsHeader& header, byte* tsPacket)
m_VideoPrevCC = header.ContinuityCounter;
-
- if (m_bShuttingDown) return;
-
- //CAutoLock lock (&m_sectionVideo);
-
if (m_pids.videoPids[0].VideoServiceType == SERVICE_TYPE_VIDEO_MPEG1 ||
m_pids.videoPids[0].VideoServiceType == SERVICE_TYPE_VIDEO_MPEG2)
{
@@ -1399,9 +1397,25 @@ void CDeMultiplexer::FillVideoH264(CTsHeader& header, byte* tsPacket)
p->SetData(&tsPacket[headerlen],dataLen);
m_p->Append(*p);
+
+ if (m_p->GetCount() > 4194303) //Sanity check
+ {
+ //Let's start again...
+ m_p.Free();
+ m_pl.RemoveAll();
+ m_bSetVideoDiscontinuity = true;
+ m_mpegParserReset = true;
+ m_VideoValidPES = false;
+ m_mVideoValidPES = false;
+ m_WaitHeaderPES = -1;
+ LogDebug("DeMux: H264 PES size out-of-bounds");
+ return;
+ }
}
else
+ {
return;
+ }
if (m_WaitHeaderPES >= 0)
{
@@ -1545,13 +1559,17 @@ void CDeMultiplexer::FillVideoH264(CTsHeader& header, byte* tsPacket)
size -= 3; //Adjust to allow for start code
- if ((size < 0) || (size > 4194303)) //Sanity check
+ if ((size <= 0) || (size > 4194303)) //Sanity check
{
//Let's start again...
m_p.Free();
m_pl.RemoveAll();
m_bSetVideoDiscontinuity = true;
m_mpegParserReset = true;
+ m_VideoValidPES = false;
+ m_mVideoValidPES = false;
+ m_WaitHeaderPES = -1;
+ LogDebug("DeMux: H264 NALU size out-of-bounds %d", size);
return;
}
@@ -1884,6 +1902,20 @@ void CDeMultiplexer::FillVideoMPEG2(CTsHeader& header, byte* tsPacket)
p->SetData(&tsPacket[headerlen],dataLen);
m_p->Append(*p);
+
+ if (m_p->GetCount() > 4194303) //Sanity check
+ {
+ //Let's start again...
+ m_p.Free();
+ m_pl.RemoveAll();
+ m_bSetVideoDiscontinuity = true;
+ m_mpegParserReset = true;
+ m_VideoValidPES = false;
+ m_mVideoValidPES = false;
+ m_WaitHeaderPES = -1;
+ LogDebug("DeMux: MPEG2 PES size out-of-bounds");
+ return;
+ }
}
else
return;
@@ -236,6 +236,7 @@ HRESULT CSubtitlePin::CompleteConnect(IPin *pReceivePin)
m_bInFillBuffer=false;
//LogDebug("subPin:CompleteConnect()");
HRESULT hr = CBaseOutputPin::CompleteConnect(pReceivePin);
+ if (!SUCCEEDED(hr)) return E_FAIL;
PIN_INFO pinInfo;
FILTER_INFO filterInfo;
@@ -181,7 +181,7 @@ CTsReaderFilter::CTsReaderFilter(IUnknown *pUnk, HRESULT *phr):
GetLogFile(filename);
::DeleteFile(filename);
LogDebug("----- Experimental noStopMod version -----");
- LogDebug("---------- v0.0.58 XXX -------------------");
+ LogDebug("---------- v0.0.59 XXX -------------------");
m_fileReader=NULL;
m_fileDuration=NULL;
@@ -1618,20 +1618,12 @@ void CTsReaderFilter::ThreadProc()
{
CRefTime firstAudio, lastAudio;
CRefTime firstVideo, lastVideo;
- DWORD audSampleSleep = 0;
- float audSampleDur = 0.0;
int cntA = m_demultiplexer.GetAudioBufferPts(firstAudio, lastAudio);
int cntV = m_demultiplexer.GetVideoBufferPts(firstVideo, lastVideo);
-
- if (m_pAudioPin->IsConnected())
- {
- audSampleDur = ((float)m_pAudioPin->m_sampleDuration)/10000.0;
- audSampleSleep = m_pAudioPin->m_FillBuffSleepTime;
- }
-
- if ( ((cntA < 1) && (cntV < 1)) || (cntA > 100) || (cntV > 100))
+
+ if ((cntA > 100) || (cntV > 100))
{
- LogDebug("Buffers : A/V = %d/%d, A last : %03.3f, V Last : %03.3f, ADur : %03.3f ms, ASlp : %d ms", cntA, cntV, (float)lastAudio.Millisecs()/1000.0f,(float)lastVideo.Millisecs()/1000.0f, audSampleDur, audSampleSleep);
+ LogDebug("Buffers : A/V = %d/%d, A last : %03.3f, V Last : %03.3f", cntA, cntV, (float)lastAudio.Millisecs()/1000.0f, (float)lastVideo.Millisecs()/1000.0f);
}
}
@@ -205,6 +205,7 @@ HRESULT CVideoPin::CompleteConnect(IPin *pReceivePin)
m_bPinNoAddPMT = false;
m_bAddPMT = true;
HRESULT hr = CBaseOutputPin::CompleteConnect(pReceivePin);
+ if (!SUCCEEDED(hr)) return E_FAIL;
PIN_INFO pinInfo;
FILTER_INFO filterInfo;

0 comments on commit 59e445a

Please sign in to comment.