# ECP-0010: time-synchronized chunking

Status: Draft

## Problem

To achieve byte-identical chunks across uncoordinated antennas, we need a shared timeline for chunk boundaries. If chunk boundaries are derived from local capture start time, identical broadcasts will diverge.

## Decision

Define a **time-synchronized chunking model** based on broadcast clocks:

1. **Primary clock: PCR**
   - Use MPEG-TS PCR (27 MHz) as the canonical timeline for chunk boundaries.
2. **UTC anchor (when available)**
   - ATSC: use PSIP STT to compute UTC time.
   - DVB: use TDT/TOT to compute UTC time.
3. **Chunk boundary rule**
   - Compute `chunk_index = floor((t_anchor) / D)` where `t_anchor` is UTC time when available, otherwise PCR time.
   - `D` is fixed chunk duration (e.g., 2000 ms).
4. **Alignment policy**
   - On ingest, drop data until the next full boundary.
   - Each chunk contains frames/packets whose PTS fall within `[chunk_start, chunk_end)`.
5. **Discontinuity handling**
   - If PCR/PTS discontinuity is detected, close the current group and start a new one at the next boundary.
6. **Sync status**
   - Streams with UTC anchor are marked `synced` and eligible for swarm convergence.
   - Streams without UTC anchor are `unsynced` and remain source-scoped.

## Consequences

- Identical broadcasts on different antennas converge to the same chunk boundaries and can produce byte-identical object streams.
- Early ingestion can begin unsynced and promote to synced when broadcast time appears.
- Chunk IDs become deterministic functions of (UTC or PCR timeline, duration).

## Alternatives considered

- Local wall clock (NTP/PTP): rejected as primary anchor because it is not broadcast-authoritative and varies between hosts.
- Capture-start-based chunking: rejected because it prevents convergence without coordination.

## Rollout / teardown

- Add a time model to the ingest pipeline (PCR + optional UTC anchor).
- Require chunkers to align to the computed boundary.
- Promote `StreamId` from source scope to broadcast scope only when `synced`.
- Supersede this ECP if MoQ introduces a standardized global timeline.
