Achieving synchronized audio and video playback is a complex but crucial task in multimedia programming. With a framework like PipeWire, which is designed to handle all types of media streams, synchronization is a core concept. The key to this is understanding the role of Presentation Timestamps (PTS) and a shared clock.
Here’s a breakdown of the concepts and a step-by-step guide on how to approach A/V sync when creating a C++ player with PipeWire.
Imagine you have two separate players: one for video frames and one for audio samples. To keep them in sync, you can't just play them as fast as possible. Instead, you need a shared "wall clock" that both players can look at.
- The Clock: PipeWire provides a global clock for the entire media graph. This clock is typically driven by an audio device (like your sound card) because audio playback is very sensitive to timing errors. If audio samples aren't delivered at a precise, steady rate, you get