From e4827ce6153bfba84eb2d11a67c7aedb307267f2 Mon Sep 17 00:00:00 2001 From: Erik Zandvliet Date: Wed, 25 Oct 2017 16:42:13 +0200 Subject: [PATCH] Fixed TS PTS rollover support --- lib/ts_stream.cpp | 8 ++++++++ lib/ts_stream.h | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/lib/ts_stream.cpp b/lib/ts_stream.cpp index 37acb27d..b1d1d80a 100644 --- a/lib/ts_stream.cpp +++ b/lib/ts_stream.cpp @@ -430,6 +430,13 @@ namespace TS{ } } + timeStamp += (rolloverCount[tid] * TS_PTS_ROLLOVER); + + if ((timeStamp < lastms[tid]) && ((timeStamp + TS_PTS_ROLLOVER) > lastms[tid] )){ + ++rolloverCount[tid]; + timeStamp += TS_PTS_ROLLOVER; + } + if (pesHeader[7] & 0x20){// ESCR - ignored pesOffset += 6; @@ -454,6 +461,7 @@ namespace TS{ const char *pesPayload = pesHeader + pesOffset; parseBitstream(tid, pesPayload, realPayloadSize, timeStamp, timeOffset, bPos, pesHeader[6] & 0x04 ); + lastms[tid] = timeStamp; // Shift the offset by the payload size, the mandatory headers and the optional // headers/padding diff --git a/lib/ts_stream.h b/lib/ts_stream.h index 4402ed35..c17984e1 100644 --- a/lib/ts_stream.h +++ b/lib/ts_stream.h @@ -7,6 +7,7 @@ #include #include "shared_memory.h" +#define TS_PTS_ROLLOVER 95443718 namespace TS{ enum codecType{H264 = 0x1B, AAC = 0x0F, AC3 = 0x81, MP3 = 0x03, H265 = 0x24, ID3 = 0x15, MPEG2 = 0x02, MP2 = 0x03}; @@ -83,6 +84,11 @@ namespace TS{ std::map mpeg2SeqHdr; std::map mpeg2SeqExt; std::map mp2Hdr; + + + std::map rolloverCount; + std::map lastms; + mutable tthread::recursive_mutex tMutex; bool threaded;