Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/EXP-TsReader_noStopMod' into D…
Browse files Browse the repository at this point in the history
…isaster123MP
  • Loading branch information
disaster123 committed Apr 15, 2012
2 parents be8c4cc + 0fe9ac2 commit 692686a
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 71 deletions.
Binary file modified DirectShowFilters/TsReader/bin/Debug/TsReader.ax
Binary file not shown.
Binary file modified DirectShowFilters/TsReader/bin/Debug/TsReader.pdb
Binary file not shown.
Binary file modified DirectShowFilters/TsReader/bin/Release/TsReader.ax
Binary file not shown.
31 changes: 9 additions & 22 deletions DirectShowFilters/TsReader/source/AudioPin.cpp
Expand Up @@ -315,7 +315,6 @@ HRESULT CAudioPin::FillBuffer(IMediaSample *pSample)
//we dont try to read any packets, but simply return...
if (m_pTsReaderFilter->IsSeeking() || m_pTsReaderFilter->IsStopping())
{
//Sleep(20);
m_FillBuffSleepTime = 5;
CreateEmptySample(pSample);
m_bInFillBuffer = false;
Expand Down Expand Up @@ -349,7 +348,6 @@ HRESULT CAudioPin::FillBuffer(IMediaSample *pSample)
//Wait until we have audio (and video, if pin connected)
if (!m_pTsReaderFilter->m_bStreamCompensated || (buffer==NULL))
{
//Sleep(10);
m_FillBuffSleepTime = 5;
buffer=NULL; //Continue looping
if (!m_pTsReaderFilter->m_bStreamCompensated && (m_nNextASD != 0))
Expand All @@ -365,7 +363,7 @@ HRESULT CAudioPin::FillBuffer(IMediaSample *pSample)
bool HasTimestamp ;
double fTime = 0.0;
double clock = 0.0;
double stallPoint = 1.0;
double stallPoint = 1.5;
//check if it has a timestamp
if ((HasTimestamp=buffer->MediaTime(RefTime)))
{
Expand All @@ -383,7 +381,9 @@ HRESULT CAudioPin::FillBuffer(IMediaSample *pSample)
//and samples outside a sensible timing window during play
//(helps with signal corruption recovery)
cRefTime -= m_pTsReaderFilter->m_ClockOnStart.m_time;
if ((cRefTime.m_time >= PRESENT_DELAY) && (fTime > ((cRefTime.m_time >= FS_TIM_LIM) ? -0.3 : -0.5)) && (fTime < 2.0))

if ((cRefTime.m_time >= PRESENT_DELAY) &&
(fTime > ((cRefTime.m_time >= FS_TIM_LIM) ? -0.3 : -0.5)) && (fTime < 2.5))
{
if ((fTime < 0.3) && (m_dRateSeeking == 1.0) && (m_pTsReaderFilter->State() == State_Running))
{
Expand All @@ -395,13 +395,10 @@ HRESULT CAudioPin::FillBuffer(IMediaSample *pSample)
demux.m_bAudioSampleLate = true;
}

//Slowly increase stall point threshold over the first 8 seconds of play
//to allow audio renderer buffer to build up to 0.4s
// stallPoint = min(0.4, (0.2 + (((double)cRefTime.m_time)/400000000.0)));
if ((fTime > stallPoint) && (m_pTsReaderFilter->State() == State_Running))
if ((fTime > stallPoint) && (m_sampleCount > 2))
{
//Too early - stall to avoid over-filling of audio decode/renderer buffers
//Sleep(10);
//Too early - stall to avoid over-filling of audio decode/renderer buffers,
//but don't enable at start of play to make sure graph starts properly
m_FillBuffSleepTime = 10;
buffer = NULL;
earlyStall = true;
Expand All @@ -412,16 +409,8 @@ HRESULT CAudioPin::FillBuffer(IMediaSample *pSample)
{
// Sample is too late.
m_bPresentSample = false ;
//m_bDiscontinuity = TRUE; //Next good sample will be discontinuous
}
cRefTime += m_pTsReaderFilter->m_ClockOnStart.m_time;

//Calculate sleep times (average sample duration/4)
// m_sampleDuration = GetAverageSampleDur(RefTime.GetUnits());
// if ((m_dRateSeeking == 1.0) && (demux.GetAudioBufferCnt() < 10))
// {
// m_FillBuffSleepTime = (DWORD)min(20, max(1, m_sampleDuration/40000));
// }
cRefTime += m_pTsReaderFilter->m_ClockOnStart.m_time;
}

if (m_bPresentSample && (m_dRateSeeking == 1.0) && (buffer->Length() > 0))
Expand Down Expand Up @@ -487,17 +476,15 @@ HRESULT CAudioPin::FillBuffer(IMediaSample *pSample)
//delete the buffer and return
delete buffer;
demux.EraseAudioBuff();
//Sleep(sampSleepTime) ;
//m_sampleCount++ ;
}
else
{ // Buffer was not displayed because it was out of date, search for next.
delete buffer;
demux.EraseAudioBuff();
buffer=NULL ;
m_FillBuffSleepTime = (m_dRateSeeking == 1.0) ? 0 : 5;
m_FillBuffSleepTime = (m_dRateSeeking == 1.0) ? 1 : 2;
m_bDiscontinuity = TRUE; //Next good sample will be discontinuous
//Sleep(1) ;
}
}
earlyStall = false;
Expand Down
11 changes: 0 additions & 11 deletions DirectShowFilters/TsReader/source/DeMultiplexer.cpp
Expand Up @@ -2558,17 +2558,6 @@ void CDeMultiplexer::SetMediaChanging(bool onOff)
LogDebug("demux:Wait for media format change:%d", onOff);
m_bWaitForMediaChange=onOff;
m_tWaitForMediaChange=GET_TIME_NOW() ;

// if (m_filter.GetAudioPin())
// {
// m_filter.GetAudioPin()->SetDiscontinuity(true);
// m_filter.GetAudioPin()->SetAddPMT();
// }
// if (m_filter.GetVideoPin())
// {
// m_filter.GetVideoPin()->SetDiscontinuity(true);
// m_filter.GetVideoPin()->SetAddPMT();
// }
}

bool CDeMultiplexer::IsMediaChanging(void)
Expand Down
22 changes: 15 additions & 7 deletions DirectShowFilters/TsReader/source/TsReader.cpp
Expand Up @@ -181,7 +181,7 @@ CTsReaderFilter::CTsReaderFilter(IUnknown *pUnk, HRESULT *phr):
GetLogFile(filename);
::DeleteFile(filename);
LogDebug("----- Experimental noStopMod version -----");
LogDebug("---------- v0.0.52 XXX -------------------");
LogDebug("---------- v0.0.54 XXX -------------------");

m_fileReader=NULL;
m_fileDuration=NULL;
Expand Down Expand Up @@ -578,11 +578,15 @@ STDMETHODIMP CTsReaderFilter::Run(REFERENCE_TIME tStart)

m_demultiplexer.m_LastDataFromRtsp=GET_TIME_NOW();
//Set our StreamTime Reference offset to zero
HRESULT hr= CSource::Run(tStart);
SetMediaPosnUpdate(m_MediaPos) ; // reset offset.

HRESULT hr= CSource::Run(tStart);

FindSubtitleFilter();
m_bPauseOnClockTooFast=false ;

m_ShowBufferVideo = 3;
m_ShowBufferAudio = 3;

LogDebug("CTsReaderFilter::Run(%05.2f) state %d -->done",msec,m_State);
return hr;
Expand Down Expand Up @@ -672,11 +676,14 @@ bool CTsReaderFilter::IsLiveTV()

STDMETHODIMP CTsReaderFilter::Pause()
{
if (m_bPauseOnClockTooFast)
{
m_ShowBufferVideo = 2;
m_ShowBufferAudio = 2;
}
// if (m_bPauseOnClockTooFast)
// {
// m_ShowBufferVideo = 2;
// m_ShowBufferAudio = 2;
// }

m_ShowBufferVideo = 3;
m_ShowBufferAudio = 3;

LogDebug("CTsReaderFilter::Pause() - IsTimeShifting = %d - state = %d", IsTimeShifting(), m_State);
HRESULT hr = S_FALSE;
Expand Down Expand Up @@ -794,6 +801,7 @@ STDMETHODIMP CTsReaderFilter::Pause()
}

LogDebug("CTsReaderFilter::Pause() - END - state = %d", m_State);
SetMediaPosnUpdate(m_MediaPos) ; // reset offset.

m_bForcePosnUpdate = true;
WakeThread();
Expand Down
38 changes: 7 additions & 31 deletions DirectShowFilters/TsReader/source/VideoPin.cpp
Expand Up @@ -353,33 +353,14 @@ HRESULT CVideoPin::FillBuffer(IMediaSample *pSample)
//we dont try to read any packets, but simply return...
if (m_pTsReaderFilter->IsSeeking() || m_pTsReaderFilter->IsStopping())
{
//Sleep(5);
m_FillBuffSleepTime = 5;
CreateEmptySample(pSample);
m_bInFillBuffer = false;
return NOERROR;
}

if (m_pTsReaderFilter->m_bStreamCompensated && !demux.m_bFlushRunning)
{
// Avoid excessive video Fill buffer preemption
// and slow down emptying rate when data available gets really low
// double frameTime;
// int buffCnt = demux.GetVideoBuffCntFt(&frameTime);
// DWORD sampSleepTime = max(1,(DWORD)(frameTime/4.0));
// if ((buffCnt == 0) || (buffCnt > 5) || (m_dRateSeeking != 1.0))
// {
// sampSleepTime = 1;
// }
// //Sleep(min(10,sampSleepTime));
// m_FillBuffSleepTime = min(8,sampSleepTime);

// int buffCnt = demux.GetVideoBufferCnt();
// if ((buffCnt != 0) && (m_dRateSeeking == 1.0) && (m_pTsReaderFilter->State() == State_Running))
// {
// m_FillBuffSleepTime = 2;
// }

{
//CAutoLock flock (&demux.m_sectionFlushVideo);
// Get next video buffer from demultiplexer
buffer=demux.GetVideo(earlyStall);
Expand All @@ -404,7 +385,6 @@ HRESULT CVideoPin::FillBuffer(IMediaSample *pSample)

if (buffer == NULL)
{
//Sleep(10);
m_FillBuffSleepTime = 5;
}
else
Expand All @@ -414,7 +394,7 @@ HRESULT CVideoPin::FillBuffer(IMediaSample *pSample)
CRefTime RefTime, cRefTime;
double fTime = 0.0;
double clock = 0.0;
double stallPoint = 1.2;
double stallPoint = 2.5;
//check if it has a timestamp
bool HasTimestamp=buffer->MediaTime(RefTime);
if (HasTimestamp)
Expand Down Expand Up @@ -467,20 +447,16 @@ HRESULT CVideoPin::FillBuffer(IMediaSample *pSample)
demux.m_bVideoSampleLate = true;
}

//Slowly increase stall point threshold over the first 8 seconds of play
//stallPoint = min(1.8, (1.3 + (((double)cRefTime.m_time)/160000000.0)));
//stallPoint = min(1.3, (0.8 + (((double)cRefTime.m_time)/160000000.0)));
//stallPoint = min(1.1, (0.8 + (((double)cRefTime.m_time)/160000000.0)));

//Discard late samples at start of play,
//and samples outside a sensible timing window during play
//(helps with signal corruption recovery)
if ((fTime > (ForcePresent ? -0.5 : -0.3)) && (fTime < 3.5))
{
if ((fTime > stallPoint) && (m_pTsReaderFilter->State() == State_Running))
//if ((fTime > stallPoint) && (m_pTsReaderFilter->State() == State_Running))
if ((fTime > stallPoint) && (m_sampleCount > 10))
{
//Too early - stall for a while to avoid over-filling of video pipeline buffers
//Sleep(10);
//Too early - stall for a while to avoid over-filling of video pipeline buffers,
//but don't enable at start of play to make sure graph starts properly
m_FillBuffSleepTime = 10;
buffer = NULL;
earlyStall = true;
Expand Down Expand Up @@ -612,7 +588,7 @@ HRESULT CVideoPin::FillBuffer(IMediaSample *pSample)
demux.EraseVideoBuff();
m_bDiscontinuity = TRUE; //Next good sample will be discontinuous
buffer = NULL;
m_FillBuffSleepTime = (m_dRateSeeking == 1.0) ? 0 : 5;
m_FillBuffSleepTime = 1;
}
}
earlyStall = false;
Expand Down

0 comments on commit 692686a

Please sign in to comment.