Permalink
Browse files

vdr-plugin-vnsiserver: do not set pts for dts on video streams

  • Loading branch information...
1 parent 608495e commit 0681d570769c3e19bdb1bc57b3eae77310969a27 @FernetMenta FernetMenta committed Dec 1, 2013
@@ -50,7 +50,7 @@ void cVNSIDemuxer::Open(const cChannel &channel, cVideoBuffer *videoBuffer)
else
m_WaitIFrame = false;
- m_FirstFrameDTS = 0;
+ m_FirstFramePTS = 0;
m_PtsWrap.m_Wrap = false;
m_PtsWrap.m_NoOfWraps = 0;
@@ -137,11 +137,12 @@ int cVNSIDemuxer::Read(sStreamPacket *packet)
{
if (m_WaitIFrame)
{
- m_FirstFrameDTS = packet->dts;
+ if (packet->pts != DVD_NOPTS_VALUE)
+ m_FirstFramePTS = packet->pts;
m_WaitIFrame = false;
}
- if (packet->dts < m_FirstFrameDTS)
+ if (packet->pts < m_FirstFramePTS)
return 0;
packet->serial = m_MuxPacketSerial;
@@ -78,7 +78,7 @@ class cVNSIDemuxer
cPatPmtParser m_PatPmtParser;
int m_OldPmtVersion;
bool m_WaitIFrame;
- int64_t m_FirstFrameDTS;
+ int64_t m_FirstFramePTS;
cVideoBuffer *m_VideoBuffer;
cMutex m_Mutex;
uint32_t m_MuxPacketSerial;
@@ -164,7 +164,7 @@ int cParser::ParsePESHeader(uint8_t *buf, size_t len)
}
}
else
- m_curDTS = m_curPTS;
+ m_curDTS = DVD_NOPTS_VALUE;
return hdr_len;
}
@@ -548,12 +548,11 @@ int cTSStream::ProcessTSPacket(uint8_t *data, sStreamPacket *pkt, bool iframe)
int64_t dts = pkt->dts;
int64_t pts = pkt->pts;
- if (dts == DVD_NOPTS_VALUE)
- dts = pts;
-
// Rescale for XBMC
- pkt->dts = Rescale(dts, DVD_TIME_BASE, 90000);
- pkt->pts = Rescale(pts, DVD_TIME_BASE, 90000);
+ if (pkt->dts != DVD_NOPTS_VALUE)
+ pkt->dts = Rescale(dts, DVD_TIME_BASE, 90000);
+ if (pkt->pts != DVD_NOPTS_VALUE)
+ pkt->pts = Rescale(pts, DVD_TIME_BASE, 90000);
pkt->duration = Rescale(pkt->duration, DVD_TIME_BASE, 90000);
return 0;
}
@@ -578,13 +577,19 @@ bool cTSStream::ReadTime(uint8_t *data, int64_t *dts)
data += TS_SIZE-payloadSize;
if (payloadSize >= 6 && m_pesParser->IsValidStartCode(data, payloadSize))
{
+ m_pesParser->m_curPTS = DVD_NOPTS_VALUE;
m_pesParser->m_curDTS = DVD_NOPTS_VALUE;
m_pesParser->ParsePESHeader(data, payloadSize);
if (m_pesParser->m_curDTS != DVD_NOPTS_VALUE)
{
*dts = m_pesParser->m_curDTS;
return true;
}
+ else if (m_pesParser->m_curPTS != DVD_NOPTS_VALUE)
+ {
+ *dts = m_pesParser->m_curPTS;
+ return true;
+ }
}
m_pesParser->m_IsPusi = false;
}
@@ -57,6 +57,7 @@ cParserMPEG2Video::cParserMPEG2Video(int pID, cTSStream *stream, sPtsWrap *ptsWr
m_Height = 0;
m_Width = 0;
m_Dar = 0.0;
+ m_FpsScale = 0;
m_PesBufferInitialSize = 80000;
m_IsVideo = true;
Reset();
@@ -93,8 +94,14 @@ void cParserMPEG2Video::Parse(sStreamPacket *pkt)
{
if (!m_NeedSPS && !m_NeedIFrame)
{
- int fpsScale = m_Stream->Rescale(m_FrameDuration, DVD_TIME_BASE, 90000);
- bool streamChange = m_Stream->SetVideoInformation(fpsScale,DVD_TIME_BASE, m_Height, m_Width, m_Dar);
+ if (m_FpsScale == 0)
+ {
+ if (m_FrameDuration != DVD_NOPTS_VALUE)
+ m_FpsScale = m_Stream->Rescale(m_FrameDuration, DVD_TIME_BASE, 90000);
+ else
+ m_FpsScale = 40000;
+ }
+ bool streamChange = m_Stream->SetVideoInformation(m_FpsScale, DVD_TIME_BASE, m_Height, m_Width, m_Dar);
pkt->id = m_pID;
pkt->size = m_PesNextFramePtr;
@@ -148,13 +155,12 @@ int cParserMPEG2Video::Parse_MPEG2Video(uint32_t startcode, int buf_ptr, bool &c
m_AuPrevDTS = m_AuDTS;
if (buf_ptr - 4 >= m_PesTimePos)
{
-
- m_AuDTS = m_curDTS;
+ m_AuDTS = m_curDTS != DVD_NOPTS_VALUE ? m_curDTS : m_curPTS;
m_AuPTS = m_curPTS;
}
else
{
- m_AuDTS = m_prevDTS;
+ m_AuDTS = m_prevDTS != DVD_NOPTS_VALUE ? m_prevDTS : m_prevPTS;;
m_AuPTS = m_prevPTS;
}
}
@@ -46,6 +46,7 @@ class cParserMPEG2Video : public cParser
int m_TemporalReference;
int m_TrLastTime;
int m_PicNumber;
+ int m_FpsScale;
int Parse_MPEG2Video(uint32_t startcode, int buf_ptr, bool &complete);
bool Parse_MPEG2Video_SeqStart(uint8_t *buf);
@@ -99,19 +99,28 @@ void cParserH264::Parse(sStreamPacket *pkt)
double DAR = (PAR * m_Width) / m_Height;
DEBUGLOG("H.264 SPS: PAR %i:%i", m_PixelAspect.num, m_PixelAspect.den);
DEBUGLOG("H.264 SPS: DAR %.2f", DAR);
-// int fpsScale = DVD_TIME_BASE / m_FPS;
+
if (m_FpsScale == 0)
{
- m_FpsScale = m_Stream->Rescale(m_curDTS - m_prevDTS, DVD_TIME_BASE, 90000);
+ if (m_curDTS != DVD_NOPTS_VALUE && m_prevDTS != DVD_NOPTS_VALUE)
+ m_FpsScale = m_Stream->Rescale(m_curDTS - m_prevDTS, DVD_TIME_BASE, 90000);
+ else
+ m_FpsScale = 40000;
}
- bool streamChange = m_Stream->SetVideoInformation(m_FpsScale,DVD_TIME_BASE, m_Height, m_Width, DAR);
+ bool streamChange = m_Stream->SetVideoInformation(m_FpsScale, DVD_TIME_BASE, m_Height, m_Width, DAR);
+
+ int duration;
+ if (m_curDTS != DVD_NOPTS_VALUE && m_prevDTS != DVD_NOPTS_VALUE)
+ duration = m_curDTS - m_prevDTS;
+ else
+ duration = m_Stream->Rescale(m_FpsScale, 90000, DVD_TIME_BASE);
pkt->id = m_pID;
pkt->size = m_PesNextFramePtr;
pkt->data = m_PesBuffer;
pkt->dts = m_DTS;
pkt->pts = m_PTS;
- pkt->duration = m_curDTS - m_prevDTS;
+ pkt->duration = duration;
pkt->streamChange = streamChange;
}
m_StartCode = 0xffffffff;
@@ -226,7 +235,7 @@ int cParserH264::Parse_H264(uint32_t startcode, int buf_ptr, bool &complete)
}
case NAL_AUD:
- if (m_FoundFrame && (m_prevDTS != DVD_NOPTS_VALUE))
+ if (m_FoundFrame && (m_prevPTS != DVD_NOPTS_VALUE))
{
complete = true;
m_PesNextFramePtr = buf_ptr - 4;

0 comments on commit 0681d57

Please sign in to comment.