From b0b1ea853ee9a62ac701ca819baed76a623682ca Mon Sep 17 00:00:00 2001 From: pstroffolino Date: Fri, 17 Jul 2026 13:22:53 -0400 Subject: [PATCH] Revert "VPAAMP-651: Trickplay skips incorrectly at cdai ad boundaries (#1674)" This reverts commit 70e8eefa7d4436c8ea0ebfd08ea19ef7e8587d56. --- mp4demux/AampMp4Demuxer.cpp | 32 ++++++++++++-------------------- mp4demux/AampMp4Demuxer.h | 8 -------- 2 files changed, 12 insertions(+), 28 deletions(-) diff --git a/mp4demux/AampMp4Demuxer.cpp b/mp4demux/AampMp4Demuxer.cpp index 71d9996449..5ee62ce588 100644 --- a/mp4demux/AampMp4Demuxer.cpp +++ b/mp4demux/AampMp4Demuxer.cpp @@ -126,20 +126,6 @@ AampMp4Demuxer::~AampMp4Demuxer() // std::unique_ptr automatically handles cleanup } -/** - * @brief Advance trickmode restamp timeline on discontinuity boundary. - */ -void AampMp4Demuxer::HandleTrickModeDiscontinuity() -{ - if (mTrickPhase == Mp4TrickPhase::STEADY) - { - mRestampedPts += mRestampedDuration; - mTrickPhase = Mp4TrickPhase::DISCONTINUITY; - AAMPLOG_WARN("[%s] Trickmode discontinuity: advancing restampedPts by %.6f to %.6f", - GetMediaTypeName(mMediaType), mRestampedDuration, mRestampedPts); - } -} - /** * @brief Apply trickmode PTS restamping to a sample, dynamically adjusting duration based on rate and frame rate * Similar to qtdemux approach but with dynamic duration calculation for smoother trickmode playback @@ -156,6 +142,18 @@ void AampMp4Demuxer::TrickmodePtsRestamp(AampMediaSample& sample, double duratio double fragmentPtsDelta = 0.0; double restampedDuration = 0.0; + // On the first keyframe of a discontinuous segment (while in STEADY state), advance + // the output PTS by the last known duration so the stream stays gapless, then switch + // to DISCONTINUITY so the switch below reuses that duration instead of computing a + // (potentially huge) cross-discontinuity PTS delta. + if (discontinuous && mTrickPhase == Mp4TrickPhase::STEADY) + { + mRestampedPts += mRestampedDuration; + mTrickPhase = Mp4TrickPhase::DISCONTINUITY; + AAMPLOG_WARN("[%s] Trickmode discontinuity: advancing restampedPts by %.6f to %.6f", + GetMediaTypeName(mMediaType), mRestampedDuration, mRestampedPts); + } + // All phase transitions are owned here. switch (mTrickPhase) { @@ -294,12 +292,6 @@ bool AampMp4Demuxer::sendSegment(std::vector&& buffer, double position, AAMPLOG_ERR("No samples for type:%d and invalid codec format:%d", mMediaType, codecInfo.mCodecFormat); ret = false; } - // Init segments can carry discontinuity without samples. - // Pre-mark discontinuity so next data sample avoids cross-period PTS delta spikes. - if (ret && mIsTrickMode && isInit && discontinuous) - { - HandleTrickModeDiscontinuity(); - } } } } diff --git a/mp4demux/AampMp4Demuxer.h b/mp4demux/AampMp4Demuxer.h index 2992a524df..0e23dcb041 100644 --- a/mp4demux/AampMp4Demuxer.h +++ b/mp4demux/AampMp4Demuxer.h @@ -152,14 +152,6 @@ class AampMp4Demuxer : public MediaProcessor */ void TrickmodePtsRestamp(AampMediaSample& sample, double duration, bool discontinuous); - /** - * @brief Handle trickmode discontinuity by pre-advancing state machine - * @note Called when a discontinuous init segment arrives to prevent large PTS - * deltas from being computed when the next data segment is processed. - * Transitions state from STEADY → DISCONTINUITY if discontinuous=true. - */ - void HandleTrickModeDiscontinuity(); - /** * @brief Reset only trickmode state variables. * Called internally whenever trickmode state must be cleared (e.g. on