You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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 synchronization audio and video for
  11. // a given voice engine channel 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/critical_section.h"
  17. #include "rtc_base/thread_checker.h"
  18. #include "video/stream_synchronization.h"
  19. namespace webrtc {
  20. class Syncable;
  21. class RtpStreamsSynchronizer : public Module {
  22. public:
  23. explicit RtpStreamsSynchronizer(Syncable* syncable_video);
  24. ~RtpStreamsSynchronizer() override;
  25. void ConfigureSync(Syncable* syncable_audio);
  26. // Implements Module.
  27. int64_t TimeUntilNextProcess() override;
  28. void Process() override;
  29. // Gets the sync offset between the current played out audio frame and the
  30. // video |frame|. Returns true on success, false otherwise.
  31. // The estimated frequency is the frequency used in the RTP to NTP timestamp
  32. // conversion.
  33. bool GetStreamSyncOffsetInMs(uint32_t timestamp,
  34. int64_t render_time_ms,
  35. int64_t* stream_offset_ms,
  36. double* estimated_freq_khz) const;
  37. private:
  38. Syncable* syncable_video_;
  39. rtc::CriticalSection crit_;
  40. Syncable* syncable_audio_ RTC_GUARDED_BY(crit_);
  41. std::unique_ptr<StreamSynchronization> sync_ RTC_GUARDED_BY(crit_);
  42. StreamSynchronization::Measurements audio_measurement_ RTC_GUARDED_BY(crit_);
  43. StreamSynchronization::Measurements video_measurement_ RTC_GUARDED_BY(crit_);
  44. rtc::ThreadChecker process_thread_checker_;
  45. int64_t last_sync_time_ RTC_GUARDED_BY(&process_thread_checker_);
  46. };
  47. } // namespace webrtc
  48. #endif // VIDEO_RTP_STREAMS_SYNCHRONIZER_H_