From: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Date: Mon, 22 Sep 2025 00:47:47 +0000 (+0000) Subject: Implement recovery mechanism instead of dropping packets on PTS_UNSET X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fheads%2Fcopilot%2Ffix-1876;p=thirdparty%2Ftvheadend.git Implement recovery mechanism instead of dropping packets on PTS_UNSET Replace packet dropping with intelligent recovery when pts_diff() returns PTS_UNSET. The new approach: 1. Re-establishes local reference timestamp when possible 2. Resets normalization state for potential rollover scenarios 3. Provides detailed trace logging for debugging 4. Maintains stream continuity instead of interrupting playback This addresses the underlying timestamp inconsistency issues that can occur during timeshift operations, particularly around timestamp rollover periods. Co-authored-by: Flole998 <9951871+Flole998@users.noreply.github.com> --- diff --git a/src/plumbing/tsfix.c b/src/plumbing/tsfix.c index dd393a278..afdd99fd6 100644 --- a/src/plumbing/tsfix.c +++ b/src/plumbing/tsfix.c @@ -242,10 +242,32 @@ normalize_ts(tsfix_t *tf, tfstream_t *tfs, th_pkt_t *pkt, int backlog) else dts = pts_diff(ref, pkt->pkt_dts); - /* Check for invalid DTS calculation result */ + /* Handle case where pts_diff returns PTS_UNSET due to inconsistent timestamps */ if (dts == PTS_UNSET) { - tsfix_packet_drop(tfs, pkt, "invalid dts calculation"); - return; + tvhtrace(LS_TSFIX, "%s: DTS calculation failed, attempting recovery (ref=%"PRId64" pkt_dts=%"PRId64")", + streaming_component_type2txt(tfs->tfs_type), ref, pkt->pkt_dts); + + /* Try to re-establish reference using current packet DTS */ + if (tfs->tfs_local_ref == PTS_UNSET) { + tfs->tfs_local_ref = pkt->pkt_dts & PTS_MASK; + tvhtrace(LS_TSFIX, "%s: Re-established local reference to %"PRId64, + streaming_component_type2txt(tfs->tfs_type), tfs->tfs_local_ref); + /* Recalculate with new reference */ + if (tf->dts_offset_apply) + dts = pts_diff(tfs->tfs_local_ref, pkt->pkt_dts + tf->dts_offset); + else + dts = pts_diff(tfs->tfs_local_ref, pkt->pkt_dts); + } + + /* If still failing, this might be a timestamp rollover case */ + if (dts == PTS_UNSET) { + /* Reset normalization state to handle potential rollover */ + tfs->tfs_last_dts_norm = PTS_UNSET; + tfs->tfs_dts_epoch = 0; + dts = 0; /* Start from zero for this stream */ + tvhtrace(LS_TSFIX, "%s: Reset normalization state due to timestamp inconsistency", + streaming_component_type2txt(tfs->tfs_type)); + } } if (tfs->tfs_last_dts_norm == PTS_UNSET) {