Synchronizing time media

With the time-media synchronization features, you can coordinate the playback and recording of multiple media streams. Because each player has an internal syncable clock, you can force one media stream to follow the timing of another. Players can be synchronized in two ways--they can be synchronized to the same external clock, or one player can be synchronized to another.

Each player's internal clock determines how fast and in what direction it plays. Ordinarily this clock is synchronized to a default clock, such as the real-time clock. Using the synchronization support provided by TPlayer, you can synchronize a media player to any clock. When a player is synchronized to a clock, its timing is dependent on that clock.

You can synchronize a media player to an external clock using the TPlayer::SyncTo function. For example, to synchronize a graphic player to an audio player, you would:

  1. Create a clock surrogate for the audio player.
    The audio player contains the clock that you're synchronizing the graphic player to--the audio player's clock will be the master clock.
  2. Using the clock surrogate, call SyncTo on the graphic player.
      // Synchronizing two players
      TSyncableClockSurrogate audioClock;
      anAudioPlayer.GetClock(audioClock);
      aGraphicPlayer.SyncTo(audioClock);
When you call SyncTo, you can also set the rate of the player. The rate represents how fast its time is flowing with respect to the clock to which it's synchronized; for example, it might be going the same speed (rate = 1.0), twice as fast (rate = 2.0), or half as fast (rate = 0.5). The rate acts as a floating point multiplier for the amount of time that is flowing. The default player rate is 1.0.

The current position of a player is controlled by it's clock time; however, the current position is always bound between zero and the duration of the loaded sequence. The internal player clock must read between zero and the duration for the player to play.

If a player is synchronized to an external clock, the player's current position is determined by the synchronization relationship. When you call SetRate, you can change a player's clock time using an offset from the external clock's clock time. By default, the offset is zero, which sets the clock time of the player to the time of the external clock. Alternatively, you can use SyncToKeepMyTime, which does not reset the player's time.


To play an audio or video sequence backward, you reverse the flow of time. If you're using delays, it's important to take into account the direction of the time flow when you compare times. The results of the comparison depend on the direction that time is flowing. If time is flowing toward the compared time, the compared time is directionally greater, or in the future. If time is flowing away from the compared time, the compared time is directionally less, or in the past. Delays unblock if at any time the delay time is directionally less than the compared time.

For more information about clocks and timing, see Chapter 11, "Time services."


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker