From 45d768384ba9c235819f392256764f2b483b6862 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Tue, 21 May 2024 20:49:36 +0000 Subject: [PATCH] Potential fix for PTS rollover --- src/videoomx.cc | 56 ++++++++++++++++++++++++++++++++++++++----------- src/videoomx.h | 1 + 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/src/videoomx.cc b/src/videoomx.cc index d07a93e..8c85707 100644 --- a/src/videoomx.cc +++ b/src/videoomx.cc @@ -2793,17 +2793,28 @@ long long VideoOMX::SetStartOffset(long long curreftime, bool* rsync) if ( (curreftime - lastrefvideotime) > 10000000LL || (curreftime - lastrefvideotime) < -10000000LL) //if pts jumps to big resync { - startoffset += curreftime - lastrefvideotime; - lastrefaudiotime += curreftime - lastrefvideotime; - //*rsync=true; - offsetaudionotset = true; - } - } - } + if ( (lastrefvideotime > 954400000000) + && (curreftime < 20000000)) + { + rolloveroffset = startoffset; + //logger->debug("SSO", "Rollover detected, saving rolloveroffset at {}", rolloveroffset); + TELEM(16, rolloveroffset); - lastrefvideotime = curreftime; + startoffset += curreftime - lastrefvideotime; + } + else + { + startoffset += curreftime - lastrefvideotime; + lastrefaudiotime += curreftime - lastrefvideotime; + //*rsync=true; + offsetaudionotset = true; + } + } + } + } - return startoffset; + lastrefvideotime = curreftime; + return startoffset; } long long VideoOMX::SetStartAudioOffset(long long curreftime, bool* rsync) @@ -2828,10 +2839,30 @@ long long VideoOMX::SetStartAudioOffset(long long curreftime, bool* rsync) if ( (curreftime - lastrefaudiotime) > 10000000LL || (curreftime - lastrefaudiotime) < -10000000LL) //if pts jumps to big resync { - startoffset += curreftime - lastrefaudiotime; - lastrefvideotime += curreftime - lastrefaudiotime; + if (rolloveroffset) + { + //logger->debug("SSA", "Rollover!!! curreftime {} startoffset {} rolloveroffset {}, lastrefaudiotime {}", + // curreftime, startoffset, rolloveroffset, lastrefaudiotime); + + rolloveroffset = 0; + TELEM(16, rolloveroffset); + } + else + { + startoffset += curreftime - lastrefaudiotime; + lastrefvideotime += curreftime - lastrefaudiotime; //*rsync=true; - offsetvideonotset = true; + offsetvideonotset = true; + } + } + else + { + // There hasn't been a big jump. + if (rolloveroffset) // let's stay in the previous system + { + lastrefaudiotime = curreftime; + return rolloveroffset; + } } } } @@ -2840,6 +2871,7 @@ long long VideoOMX::SetStartAudioOffset(long long curreftime, bool* rsync) return startoffset; } + void VideoOMX::ResetTimeOffsets() { offsetnotset = true; //called from demuxer diff --git a/src/videoomx.h b/src/videoomx.h index 27ce998..1a1e09e 100644 --- a/src/videoomx.h +++ b/src/videoomx.h @@ -158,6 +158,7 @@ class VideoOMX : public Video bool offsetvideonotset{true}; bool offsetaudionotset{true}; long long startoffset{}; + long long rolloveroffset{}; long long lastrefvideotime{}; long long lastrefaudiotime{}; // long long cur_pts; -- 2.39.2