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.

62 lines
2.0 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. #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(int video_stream_id, int audio_stream_id);
  24. bool ComputeDelays(int relative_delay_ms,
  25. int current_audio_delay_ms,
  26. int* extra_audio_delay_ms,
  27. int* total_video_delay_target_ms);
  28. // On success |relative_delay| contains the number of milliseconds later video
  29. // is rendered relative audio. If audio is played back later than video a
  30. // |relative_delay| 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 - All audio and video will be delayed by at
  35. // least target_delay_ms.
  36. void SetTargetBufferingDelay(int target_delay_ms);
  37. private:
  38. struct SynchronizationDelays {
  39. int extra_video_delay_ms = 0;
  40. int last_video_delay_ms = 0;
  41. int extra_audio_delay_ms = 0;
  42. int last_audio_delay_ms = 0;
  43. };
  44. SynchronizationDelays channel_delay_;
  45. const int video_stream_id_;
  46. const int audio_stream_id_;
  47. int base_target_delay_ms_;
  48. int avg_diff_ms_;
  49. };
  50. } // namespace webrtc
  51. #endif // VIDEO_STREAM_SYNCHRONIZATION_H_