How Does SMIL syncMaster Synchronize Streams?
In Synchronized Multimedia Integration Language (SMIL), the
syncMaster="true" attribute designates a specific media
stream as the primary clock source for a synchronized presentation. When
parallel media elements such as audio, video, and text captions play
simultaneously, hardware timing differences, network latency, and
decoding overhead can cause streams to drift out of sync. Assigning
syncMaster="true" forces the SMIL playback engine to tie
the presentation's timeline directly to that designated master element,
ensuring that all dependent sibling elements adjust their playback to
stay strictly aligned.
The Challenge of Multi-Stream Media Drift
When multiple continuous media objects run inside a parallel
container (<par>), each file typically possesses its
own internal playback clock and decoding pipeline. Over time, slight
deviations occur:
- Buffer Stalls: A video stream might pause to fetch more data while an audio stream continues unhindered.
- Hardware & Processing Delays: Rendering high-resolution video frames requires more processing power than rendering subtitles or plain text, leading to lagging visuals.
- Clock Skew: Slight clock frequency discrepancies between audio and video hardware outputs can accumulate over long presentations.
Without a master clock, the playback engine either allows elements to drift independently or relies on a generic presentation clock that may not reflect whether a specific media stream has stalled or skipped.
How syncMaster Establishes the Master Clock
When you assign syncMaster="true" to a continuous media
element—most commonly the main audio or video track—it becomes the
authoritative reference for its parent container.
<par>
<video src="presentation.mp4" syncMaster="true" />
<audio src="commentary.mp3" syncBehavior="locked" />
<textstream src="subtitles.rt" syncBehavior="locked" />
</par>Under this configuration:
- Master Dictates Time: The playback engine polls the time code directly from the designated master element rather than relying on an abstract internal timer.
- Buffer Synchronization: If the sync master encounters a buffer underflow and pauses playback, the entire synchronization context pauses. Dependent streams freeze on their current frame or silence until the master resumes.
- Seek Coordination: When a user seeks or skips forward within the sync master, all synchronized child elements immediately adjust their positions to match the master's new timestamp.
- Speed and Rate Matching: If the master element changes playback rate (such as 1.5x fast-forward), dependent elements scale their playback rates accordingly to preserve alignment.
Relationship with syncBehavior and syncTolerance
The syncMaster attribute works in tandem with two other
SMIL synchronization attributes: syncBehavior and
syncTolerance.
syncBehavior Settings
The syncBehavior attribute defines how strictly
dependent elements must follow the timeline:
locked: The element must strictly adhere to the sync master's clock. If the element falls behind, it must drop frames or skip ahead; if it gets ahead, it must wait.canSlip: The element is allowed to drift if necessary, prioritizing smooth playback of its own content over strict temporal alignment.default: The element inherits the synchronization rules defined by the runtime environment or parent container.
syncTolerance Thresholds
The syncTolerance attribute specifies an acceptable time
window (e.g., syncTolerance="0.2s") within which a stream
is allowed to deviate before the engine forces a resynchronization. This
prevents jarring micro-adjustments and stuttering caused by minor,
imperceptible frame delays.
Precedence and Scope Rules
SMIL enforces strict constraints on master designation to prevent conflicting timing instructions:
- Single Master per Scope: Only one active media element can serve as the sync master within a single synchronization context at any given time.
- Document Order Precedence: If multiple elements
within the same
<par>container declaresyncMaster="true", the SMIL player gives precedence to the first active element encountered in document order, ignoring subsequent master declarations until the first finishes. - Hierarchical Scope: The master designation applies to the immediate synchronization container and its children, allowing nested containers to manage sub-timelines if necessary.