Permalink
Browse files

Merge remote-tracking branch 'upstream/EXP-TsReader_noStopMod' into D…

…isaster123MP
  • Loading branch information...
2 parents 1e1b40d + 7f8be14 commit 1ee7fe1f1fc5fb6d7c0d22e1b8679433d7ac6356 @disaster123 committed May 13, 2012
Binary file not shown.
@@ -117,7 +117,7 @@ HRESULT CAudioPin::CheckMediaType(const CMediaType* pmt)
if(*pmt == *ppmti)
{
- LogDebug("audPin:CheckMediaType() ok");
+ //LogDebug("audPin:CheckMediaType() ok");
return S_OK;
}
@@ -219,14 +219,29 @@ HRESULT CAudioPin::CompleteConnect(IPin *pReceivePin)
m_bAddPMT = true;
//LogDebug("audPin:CompleteConnect()");
HRESULT hr = CBaseOutputPin::CompleteConnect(pReceivePin);
- if (SUCCEEDED(hr))
+
+ PIN_INFO pinInfo;
+ FILTER_INFO filterInfo;
+ hr=pReceivePin->QueryPinInfo(&pinInfo);
+ if (!SUCCEEDED(hr)) return E_FAIL;
+ else if (pinInfo.pFilter==NULL) return E_FAIL;
+ else pinInfo.pFilter->Release(); // we dont need the filter just the info
+
+ hr=pinInfo.pFilter->QueryFilterInfo(&filterInfo);
+ filterInfo.pGraph->Release();
+
+ if (SUCCEEDED(hr))
{
- LogDebug("audPin:CompleteConnect() ok");
+ char szName[MAX_FILTER_NAME];
+ int cch = WideCharToMultiByte(CP_ACP, 0, filterInfo.achName, MAX_FILTER_NAME, szName, MAX_FILTER_NAME, 0, 0);
+ LogDebug("audPin:CompleteConnect() ok, filter: %s", szName);
+
m_bConnected=true;
}
else
{
LogDebug("audPin:CompleteConnect() failed:%x",hr);
+ return E_FAIL;
}
if (m_pTsReaderFilter->IsTimeShifting())
@@ -242,7 +257,7 @@ HRESULT CAudioPin::CompleteConnect(IPin *pReceivePin)
m_pTsReaderFilter->GetDuration(&refTime);
m_rtDuration=CRefTime(refTime);
}
- LogDebug("audPin:CompleteConnect() end");
+ //LogDebug("audPin:CompleteConnect() end");
return hr;
}
@@ -1486,12 +1486,12 @@ void CDeMultiplexer::FillVideoH264(CTsHeader& header, byte* tsPacket)
{
d += 0.0366 ;
}
- d += (m_bVideoPTSroff ? 0.0015 : -0.0015); //Ensure PTS always changes
+ d += (m_bVideoPTSroff ? 0.0015 : 0.0025); //Ensure PTS always changes
m_bVideoPTSroff = !m_bVideoPTSroff;
pts.FromClock(d);
pts.IsValid=true;
isSamePTS = true;
- }
+ }
LOG_SAMPLES("DeMultiplexer::FillVideoH264 pts: %f, dts: %f, diff %f, minDiff %f, rtStart : %d ", (float)pts.ToClock(), (float)dts.ToClock(), (float) diff, (float)m_minVideoPTSdiff, pts.PcrReferenceBase);
}
}
@@ -1545,6 +1545,16 @@ void CDeMultiplexer::FillVideoH264(CTsHeader& header, byte* tsPacket)
size -= 3; //Adjust to allow for start code
+ if ((size < 0) || (size > 4194303)) //Sanity check
+ {
+ //Let's start again...
+ m_p.Free();
+ m_pl.RemoveAll();
+ m_bSetVideoDiscontinuity = true;
+ m_mpegParserReset = true;
+ return;
+ }
+
DWORD dwNalLength =
((size >> 24) & 0x000000ff) |
((size >> 8) & 0x0000ff00) |
@@ -1610,7 +1620,7 @@ void CDeMultiplexer::FillVideoH264(CTsHeader& header, byte* tsPacket)
//LogDebug("Fake AUD: %x %x %x %x %x %x", p->GetAt(0), p->GetAt(1), p->GetAt(2), p->GetAt(3), p->GetAt(4), p->GetAt(5));
}
- while(m_pl.GetCount())
+ while(m_pl.GetCount()>0)
{
CAutoPtr<Packet> p4(new Packet());
p4 = m_pl.RemoveHead();
@@ -1631,7 +1641,7 @@ void CDeMultiplexer::FillVideoH264(CTsHeader& header, byte* tsPacket)
p->rtStart = p4->rtStart;
//LogDebug("Fake AUD2: %x %x %x %x %x %x", p4->GetAt(0), p4->GetAt(1), p4->GetAt(2), p4->GetAt(3), p4->GetAt(4), p4->GetAt(5));
}
- if (p->GetCount())
+ if (p->GetCount()>0)
{
p->Append(*p4);
}
@@ -1263,19 +1263,22 @@ bool CFrameHeaderParser::Read(avchdr& h, int len, CMediaType* pmt, bool reset)
// Copy the full SPS packet in case the PPS is not found in the same packet,
// but make sure we don't change the current position in the buffer.
- if (h.spslen != 0)
+ if (h.sps != NULL)
{
free(h.sps);
}
h.spslen = next_nal - pos; //length excluding length and ID bytes
+ if ((h.spslen <= 0) || (h.spslen > 65534)) return(false); //Sanity check
h.sps = (BYTE*) malloc(h.spslen);
+ if (h.sps == NULL) return(false); //malloc error...
ByteRead(h.sps, h.spslen);
Seek(pos);
//LogDebug("h.spslen = %d, bytes = %x %x %x %x, last byte = %x", h.spslen, *h.sps, *(h.sps+1), *(h.sps+2), *(h.sps+3), *(h.sps+(h.spslen-1)));
// Manage H264 escape codes (see "remove escapes (very rare 1:2^22)" in ffmpeg h264.c file)
//ByteRead((BYTE*)SPSTemp, min(MAX_SPS, GetRemaining()));
BYTE* buff = (BYTE*) malloc(h.spslen);
+ if (buff == NULL) return(false); //malloc error...
CGolombBuffer gb (buff, h.spslen);
RemoveMpegEscapeCode (buff, h.sps, h.spslen);
@@ -1412,34 +1415,28 @@ bool CFrameHeaderParser::Read(avchdr& h, int len, CMediaType* pmt, bool reset)
h.ppsid = id;
__int64 pos = GetPos();
- if (h.ppslen != 0)
+ if (h.pps != NULL)
{
free(h.pps);
}
h.ppslen = next_nal - pos; //length excluding length and ID bytes
+ if ((h.ppslen <= 0) || (h.ppslen > 65534)) return(false); //Sanity check
h.pps = (BYTE*) malloc(h.ppslen);
+ if (h.pps == NULL) return(false); //malloc error...
ByteRead(h.pps, h.ppslen);
//LogDebug("h.ppslen = %d, bytes = %x %x %x %x, last byte = %x", h.ppslen, *h.pps, *(h.pps+1), *(h.pps+2), *(h.pps+3), *(h.pps+h.ppslen-1));
}
- BitByteAlign();
+ //BitByteAlign();
//Seek(next_nal);
- } // end while main
+ }
- if(!h.spslen || !h.ppslen || h.height<100 || h.width<100 || h.AvgTimePerFrame<=0)
+ if(h.spslen<=0 || h.ppslen<=0 || h.height<100 || h.width<100 || h.AvgTimePerFrame<=0)
return(false);
if(!pmt)
{
- if (h.spslen != 0)
- {
- free(h.sps);
- }
- if (h.ppslen != 0)
- {
- free(h.pps);
- }
return(true);
}
else
@@ -1540,16 +1537,7 @@ bool CFrameHeaderParser::Read(avchdr& h, int len, CMediaType* pmt, bool reset)
*p++ = (h.ppslen+1) & 0xff;
*p++ = h.ppsid;
memcpy(p, h.pps, h.ppslen);
- p += h.ppslen;
-
- if (h.spslen != 0)
- {
- free(h.sps);
- }
- if (h.ppslen != 0)
- {
- free(h.pps);
- }
+ //p += h.ppslen;
pmt->SetFormat((BYTE*)vi, len);
}
@@ -320,6 +320,8 @@ struct pshdr
avchdr()
{
progressive = true;
+ sps = NULL;
+ pps = NULL;
spslen = 0;
ppslen = 0;
AvgTimePerFrame = 0;
@@ -88,11 +88,57 @@ STDMETHODIMP CSubtitlePin::NonDelegatingQueryInterface( REFIID riid, void ** ppv
return CSourceStream::NonDelegatingQueryInterface(riid, ppv);
}
+HRESULT CSubtitlePin::CheckMediaType(const CMediaType* pmt)
+{
+ CheckPointer(pmt, E_POINTER);
+
+ CDeMultiplexer& demux=m_pTsReaderFilter->GetDemultiplexer();
+
+ if (!m_pTsReaderFilter->CheckCallback())
+ {
+ //LogDebug("subPin: Not running in MP - CheckMediaType() fail");
+ return E_FAIL;
+ }
+
+ if (!demux.PatParsed())
+ {
+ return E_FAIL;
+ }
+
+ CMediaType pmti;
+ CMediaType* ppmti = &pmti;
+
+ ppmti->InitMediaType();
+ ppmti->SetType (& MEDIATYPE_Stream);
+ ppmti->SetSubtype (& MEDIASUBTYPE_MPEG2_TRANSPORT);
+ ppmti->SetSampleSize(1);
+ ppmti->SetTemporalCompression(FALSE);
+ ppmti->SetVariableSize();
+
+ if(*pmt == *ppmti)
+ {
+ //LogDebug("subPin:CheckMediaType() ok");
+ return S_OK;
+ }
+
+ //LogDebug("subPin:CheckMediaType() fail");
+ return E_FAIL;
+}
+
+
HRESULT CSubtitlePin::GetMediaType(CMediaType *pmt)
{
CheckPointer(pmt, E_POINTER);
//LogDebug("subPin:GetMediaType()");
+
+ if (!m_pTsReaderFilter->CheckCallback())
+ {
+ //LogDebug("sub pin: Not running in MP - GetMediaType() fail");
+ //Return a null media type
+ pmt->InitMediaType();
+ return E_UNEXPECTED;
+ }
CDeMultiplexer& demux=m_pTsReaderFilter->GetDemultiplexer();
@@ -153,6 +199,12 @@ HRESULT CSubtitlePin::CheckConnect(IPin *pReceivePin)
HRESULT hr;
PIN_INFO pinInfo;
FILTER_INFO filterInfo;
+
+ if (!m_pTsReaderFilter->CheckCallback())
+ {
+ //LogDebug("sub pin: Not running in MP - CheckConnect() fail");
+ return E_FAIL;
+ }
hr=pReceivePin->QueryPinInfo(&pinInfo);
if (!SUCCEEDED(hr)) return E_FAIL;
@@ -171,7 +223,7 @@ HRESULT CSubtitlePin::CheckConnect(IPin *pReceivePin)
filterInfo.pGraph->Release();
if (!SUCCEEDED(hr)) return E_FAIL;
- if (wcscmp(filterInfo.achName,L"MediaPortal DVBSub2") !=0 )
+ if ((wcscmp(filterInfo.achName,L"MediaPortal DVBSub2") !=0 ) && (wcscmp(filterInfo.achName,L"MediaPortal DVBSub3") !=0 ))
{
//LogDebug("sub pin: Cant connect to filter name %s", filterInfo.achName);
return E_FAIL;
@@ -185,14 +237,28 @@ HRESULT CSubtitlePin::CompleteConnect(IPin *pReceivePin)
//LogDebug("subPin:CompleteConnect()");
HRESULT hr = CBaseOutputPin::CompleteConnect(pReceivePin);
- if (SUCCEEDED(hr))
+ PIN_INFO pinInfo;
+ FILTER_INFO filterInfo;
+ hr=pReceivePin->QueryPinInfo(&pinInfo);
+ if (!SUCCEEDED(hr)) return E_FAIL;
+ else if (pinInfo.pFilter==NULL) return E_FAIL;
+ else pinInfo.pFilter->Release(); // we dont need the filter just the info
+
+ hr=pinInfo.pFilter->QueryFilterInfo(&filterInfo);
+ filterInfo.pGraph->Release();
+
+ if (SUCCEEDED(hr))
{
- LogDebug("subPin:CompleteConnect() ok");
+ char szName[MAX_FILTER_NAME];
+ int cch = WideCharToMultiByte(CP_ACP, 0, filterInfo.achName, MAX_FILTER_NAME, szName, MAX_FILTER_NAME, 0, 0);
+ LogDebug("subPin:CompleteConnect() ok, filter: %s", szName);
+
m_bConnected=true;
}
else
{
LogDebug("subPin:CompleteConnect() failed:%x",hr);
+ return E_FAIL;
}
if (m_pTsReaderFilter->IsTimeShifting())
@@ -208,7 +274,8 @@ HRESULT CSubtitlePin::CompleteConnect(IPin *pReceivePin)
m_pTsReaderFilter->GetDuration(&refTime);
m_rtDuration=CRefTime(refTime);
}
- LogDebug("subPin:CompleteConnect() end");
+
+ //LogDebug("subPin:CompleteConnect() end");
return hr;
}
@@ -33,6 +33,7 @@ class CSubtitlePin: public CSourceStream, public CSourceSeeking
//CSourceStream
HRESULT GetMediaType(CMediaType *pMediaType);
+ HRESULT CheckMediaType(const CMediaType* pmt);
HRESULT DecideBufferSize(IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *pRequest);
HRESULT CompleteConnect(IPin *pReceivePin);
HRESULT CheckConnect(IPin *pReceivePin);
@@ -181,7 +181,7 @@ CTsReaderFilter::CTsReaderFilter(IUnknown *pUnk, HRESULT *phr):
GetLogFile(filename);
::DeleteFile(filename);
LogDebug("----- Experimental noStopMod version -----");
- LogDebug("---------- v0.0.57 XXX -------------------");
+ LogDebug("---------- v0.0.58 XXX -------------------");
m_fileReader=NULL;
m_fileDuration=NULL;
@@ -505,18 +505,13 @@ STDMETHODIMP CTsReaderFilter::GetState(DWORD dwMilliSecsTimeout, FILTER_STATE *p
}
}
- // bool isAVReady = m_bStreamCompensated
- // && GetVideoPin()->HasDeliveredSample()
- // && GetAudioPin()->HasDeliveredSample()
- // && (GET_TIME_NOW() > m_demultiplexer. m_targetAVready);
-
bool isAVReady = m_bStreamCompensated
&& (GET_TIME_NOW() > m_demultiplexer.m_targetAVready);
//FFWD is more responsive if we return VFW_S_CANT_CUE when rate != 1.0
if (isAVReady || (playRate != 1.0))
{
- LogDebug("CTsReaderFilter::GetState(), VFW_S_CANT_CUE, playRate %f",(float)playRate);
+ //LogDebug("CTsReaderFilter::GetState(), VFW_S_CANT_CUE, playRate %f",(float)playRate);
return VFW_S_CANT_CUE;
}
else
@@ -1834,11 +1829,11 @@ HRESULT CTsReaderFilter::FindSubtitleFilter()
FILTER_INFO filterInfo;
if (pFilter->QueryFilterInfo(&filterInfo) == S_OK)
{
- if (!wcsicmp(L"MediaPortal DVBSub2", filterInfo.achName))
+ if ((!wcsicmp(L"MediaPortal DVBSub2", filterInfo.achName)) || (!wcsicmp(L"MediaPortal DVBSub3", filterInfo.achName)))
{
HRESULT fhr = pFilter->QueryInterface( IID_IDVBSubtitle2, ( void**)&m_pDVBSubtitle );
assert( fhr == S_OK);
- //LogDebug("Testing that DVBSub2 works");
+ //LogDebug("Testing that DVBSub2/DVBSub3 works");
m_pDVBSubtitle->Test(1);
}
filterInfo.pGraph->Release();
Oops, something went wrong.

0 comments on commit 1ee7fe1

Please sign in to comment.