stream_synchronization.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #ifndef VIDEO_STREAM_SYNCHRONIZATION_H_
  11. #define VIDEO_STREAM_SYNCHRONIZATION_H_
  12. #include <stdint.h>
  13. #include "system_wrappers/include/rtp_to_ntp_estimator.h"
  14. namespace webrtc {
  15. class StreamSynchronization {
  16. public:
  17. struct Measurements {
  18. Measurements() : latest_receive_time_ms(0), latest_timestamp(0) {}
  19. RtpToNtpEstimator rtp_to_ntp;
  20. int64_t latest_receive_time_ms;
  21. uint32_t latest_timestamp;
  22. };
  23. StreamSynchronization(uint32_t video_stream_id, uint32_t audio_stream_id);
  24. bool ComputeDelays(int relative_delay_ms,
  25. int current_audio_delay_ms,
  26. int* total_audio_delay_target_ms,
  27. int* total_video_delay_target_ms);
  28. // On success |relative_delay_ms| contains the number of milliseconds later
  29. // video is rendered relative audio. If audio is played back later than video
  30. // |relative_delay_ms| will be negative.
  31. static bool ComputeRelativeDelay(const Measurements& audio_measurement,
  32. const Measurements& video_measurement,
  33. int* relative_delay_ms);
  34. // Set target buffering delay. Audio and video will be delayed by at least
  35. // |target_delay_ms|.
  36. void SetTargetBufferingDelay(int target_delay_ms);
  37. // Lowers the audio delay by 10%. Can be used to recover from errors.
  38. void ReduceAudioDelay();
  39. // Lowers the video delay by 10%. Can be used to recover from errors.
  40. void ReduceVideoDelay();
  41. uint32_t audio_stream_id() const { return audio_stream_id_; }
  42. uint32_t video_stream_id() const { return video_stream_id_; }
  43. private:
  44. struct SynchronizationDelays {
  45. int extra_ms = 0;
  46. int last_ms = 0;
  47. };
  48. const uint32_t video_stream_id_;
  49. const uint32_t audio_stream_id_;
  50. SynchronizationDelays audio_delay_;
  51. SynchronizationDelays video_delay_;
  52. int base_target_delay_ms_;
  53. int avg_diff_ms_;
  54. };
  55. } // namespace webrtc
  56. #endif // VIDEO_STREAM_SYNCHRONIZATION_H_