﻿# RTP timestamp wrap: preserve media continuity with bounded extended state

RTP timestamp wrap: preserve media continuity with bounded extended state. A practical streaming-video guide with failure mechanisms, a controlled scenario, acceptance evidence and primary references.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/sv-rtp-timestamp-wrap-extended-state/
Language: en

A long-running receiver interprets a wrapped RTP timestamp as a large backward jump. Event windows close incorrectly or old frames are accepted as new after a numeric counter rollover.

## The media mechanism

RTP timestamps are finite modular counters. Extending them requires source/session context and bounded assumptions about elapsed observation, not ordinary unbounded integer sorting across arbitrary disconnections.

## Establish the pipeline boundary

Extend modular timestamps only under stated continuity assumptions. The receiver needs the payload clock, source generation and a bounded observation gap to distinguish a supported rollover from an unknown number of elapsed cycles.

Test reordered and duplicate packets around the counter boundary. A small numerical timestamp after wrap can represent later media, but ordinary ascending integer sorting places it incorrectly. Conversely, a source reset must not automatically be interpreted as another wrap.

Store the extended mapping with its session context and invalidate it when continuity is no longer justified. Include a long disconnection as an unresolved case rather than inventing elapsed cycles. Compare known media duration and accepted frame order. Correct extension inside the fixture does not establish global wall-clock time or physical-camera continuity across a replacement source.

## A constructed failure case

Cross the counter boundary in a short known-duration sequence, then test a reset in a new source epoch. The receiver must distinguish supported rollover from an unsupported continuity assumption after source replacement.

## A practical validation procedure

Generate a controlled fixture spanning rollover under the declared payload clock. Preserve extended timestamp state with source generation and test duplicate or reordered packets near the boundary. Mark intervals unresolved when a long observation gap makes wrap count ambiguous.

Keep an unchanged control and a deliberate failure case. Change the relevant setting or interruption independently, then compare observed frame identities and state transitions. Measure through recovery as well as the first error; a restarted worker can retain obsolete results or references.

## Evidence for acceptance

Keep raw counters, extension state, clock units and the supported observation-gap bound.

## Recovery and limits

A rollover rule cannot reconstruct arbitrary missing history or distinguish every reset without lifecycle evidence.

Define whether recovery drains, discards or isolates pending frames before resuming ordinary service. Preserve compact diagnostic identities and the fixture configuration. Avoid treating a new connection or a live process as proof that previous in-flight work has finished safely.

## References and interpretation

Primary references: [RTP and RTCP protocol specification](https://www.rfc-editor.org/rfc/rfc3550.html); [GStreamer RTP jitter buffering](https://gstreamer.freedesktop.org/documentation/rtpmanager/rtpjitterbuffer.html).

This is a proposed operational validation, not an executed Retrivium benchmark. Documentation defines interfaces and supported behavior; the actual pipeline needs its own evidence. Repeat the check after relevant plugin, decoder, source or preprocessing changes.

## Related reading

Continue with [PyAV video datasets: presentation timestamps are safer than frame-number clocks](/journal/data-guide-pyav-video-pts-timebase/); [RTP timestamp clock rates: convert media time without substituting camera FPS](/journal/sv-rtp-clock-rate-not-frame-rate/). Their adjacent context does not replace the specific frame-flow acceptance check described here.
