rtp_streams_synchronizer.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. // RtpStreamsSynchronizer is responsible for synchronizing audio and video for
  11. // a given audio receive stream and video receive stream.
  12. #ifndef VIDEO_RTP_STREAMS_SYNCHRONIZER_H_
  13. #define VIDEO_RTP_STREAMS_SYNCHRONIZER_H_
  14. #include <memory>
  15. #include "modules/include/module.h"
  16. #include "rtc_base/synchronization/mutex.h"
  17. #include "rtc_base/thread_checker.h"
  18. #include "video/stream_synchronization.h"
  19. namespace webrtc {
  20. class Syncable;
  21. // DEPRECATED.
  22. class RtpStreamsSynchronizer : public Module {
  23. public:
  24. explicit RtpStreamsSynchronizer(Syncable* syncable_video);
  25. ~RtpStreamsSynchronizer() override;
  26. void ConfigureSync(Syncable* syncable_audio);
  27. // Implements Module.
  28. int64_t TimeUntilNextProcess() override;
  29. void Process() override;
  30. // Gets the estimated playout NTP timestamp for the video frame with
  31. // |rtp_timestamp| and the sync offset between the current played out audio
  32. // frame and the video frame. Returns true on success, false otherwise.
  33. // The |estimated_freq_khz| is the frequency used in the RTP to NTP timestamp
  34. // conversion.
  35. bool GetStreamSyncOffsetInMs(uint32_t rtp_timestamp,
  36. int64_t render_time_ms,
  37. int64_t* video_playout_ntp_ms,
  38. int64_t* stream_offset_ms,
  39. double* estimated_freq_khz) const;
  40. private:
  41. Syncable* syncable_video_;
  42. mutable Mutex mutex_;
  43. Syncable* syncable_audio_ RTC_GUARDED_BY(mutex_);
  44. std::unique_ptr<StreamSynchronization> sync_ RTC_GUARDED_BY(mutex_);
  45. StreamSynchronization::Measurements audio_measurement_ RTC_GUARDED_BY(mutex_);
  46. StreamSynchronization::Measurements video_measurement_ RTC_GUARDED_BY(mutex_);
  47. rtc::ThreadChecker process_thread_checker_;
  48. int64_t last_sync_time_ RTC_GUARDED_BY(&process_thread_checker_);
  49. int64_t last_stats_log_ms_ RTC_GUARDED_BY(&process_thread_checker_);
  50. };
  51. } // namespace webrtc
  52. #endif // VIDEO_RTP_STREAMS_SYNCHRONIZER_H_