1 /* 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 // RtpStreamsSynchronizer is responsible for synchronizing audio and video for 12 // a given audio receive stream and video receive stream. 13 14 #ifndef VIDEO_RTP_STREAMS_SYNCHRONIZER_H_ 15 #define VIDEO_RTP_STREAMS_SYNCHRONIZER_H_ 16 17 #include <memory> 18 19 #include "modules/include/module.h" 20 #include "rtc_base/synchronization/mutex.h" 21 #include "rtc_base/thread_checker.h" 22 #include "video/stream_synchronization.h" 23 24 namespace webrtc { 25 26 class Syncable; 27 28 // DEPRECATED. 29 class RtpStreamsSynchronizer : public Module { 30 public: 31 explicit RtpStreamsSynchronizer(Syncable* syncable_video); 32 ~RtpStreamsSynchronizer() override; 33 34 void ConfigureSync(Syncable* syncable_audio); 35 36 // Implements Module. 37 int64_t TimeUntilNextProcess() override; 38 void Process() override; 39 40 // Gets the estimated playout NTP timestamp for the video frame with 41 // |rtp_timestamp| and the sync offset between the current played out audio 42 // frame and the video frame. Returns true on success, false otherwise. 43 // The |estimated_freq_khz| is the frequency used in the RTP to NTP timestamp 44 // conversion. 45 bool GetStreamSyncOffsetInMs(uint32_t rtp_timestamp, 46 int64_t render_time_ms, 47 int64_t* video_playout_ntp_ms, 48 int64_t* stream_offset_ms, 49 double* estimated_freq_khz) const; 50 51 private: 52 Syncable* syncable_video_; 53 54 mutable Mutex mutex_; 55 Syncable* syncable_audio_ RTC_GUARDED_BY(mutex_); 56 std::unique_ptr<StreamSynchronization> sync_ RTC_GUARDED_BY(mutex_); 57 StreamSynchronization::Measurements audio_measurement_ RTC_GUARDED_BY(mutex_); 58 StreamSynchronization::Measurements video_measurement_ RTC_GUARDED_BY(mutex_); 59 60 rtc::ThreadChecker process_thread_checker_; 61 int64_t last_sync_time_ RTC_GUARDED_BY(&process_thread_checker_); 62 int64_t last_stats_log_ms_ RTC_GUARDED_BY(&process_thread_checker_); 63 }; 64 65 } // namespace webrtc 66 67 #endif // VIDEO_RTP_STREAMS_SYNCHRONIZER_H_ 68