blob: 61073cb4b25934046fab87ac31915533c05c5372 [file] [log] [blame]
stefan@webrtc.org5f284982012-06-28 07:51:161/*
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
Mirko Bonadei92ea95e2017-09-15 04:47:3111#ifndef VIDEO_STREAM_SYNCHRONIZATION_H_
12#define VIDEO_STREAM_SYNCHRONIZATION_H_
stefan@webrtc.org5f284982012-06-28 07:51:1613
Yves Gerey3e707812018-11-28 15:47:4914#include <stdint.h>
stefan@webrtc.org7c3523c2012-09-11 07:00:4215
Mirko Bonadei92ea95e2017-09-15 04:47:3116#include "system_wrappers/include/rtp_to_ntp_estimator.h"
stefan@webrtc.org5f284982012-06-28 07:51:1617
18namespace webrtc {
19
stefan@webrtc.org5f284982012-06-28 07:51:1620class StreamSynchronization {
21 public:
22 struct Measurements {
asaperssonfe50b4d2016-12-22 15:53:5123 Measurements() : latest_receive_time_ms(0), latest_timestamp(0) {}
24 RtpToNtpEstimator rtp_to_ntp;
stefan@webrtc.org7c3523c2012-09-11 07:00:4225 int64_t latest_receive_time_ms;
26 uint32_t latest_timestamp;
stefan@webrtc.org5f284982012-06-28 07:51:1627 };
28
Åsa Persson74d2b1d2020-02-10 15:33:2929 StreamSynchronization(uint32_t video_stream_id, uint32_t audio_stream_id);
stefan@webrtc.org5f284982012-06-28 07:51:1630
stefan@webrtc.org7c3523c2012-09-11 07:00:4231 bool ComputeDelays(int relative_delay_ms,
32 int current_audio_delay_ms,
Åsa Persson4fc52c82019-12-09 11:41:5633 int* total_audio_delay_target_ms,
stefan@webrtc.org7c3523c2012-09-11 07:00:4234 int* total_video_delay_target_ms);
35
Artem Titovab30d722021-07-27 14:22:1136 // On success `relative_delay_ms` contains the number of milliseconds later
Åsa Persson4fc52c82019-12-09 11:41:5637 // video is rendered relative audio. If audio is played back later than video
Artem Titovab30d722021-07-27 14:22:1138 // `relative_delay_ms` will be negative.
stefan@webrtc.org7c3523c2012-09-11 07:00:4239 static bool ComputeRelativeDelay(const Measurements& audio_measurement,
40 const Measurements& video_measurement,
41 int* relative_delay_ms);
Åsa Persson4fc52c82019-12-09 11:41:5642
43 // Set target buffering delay. Audio and video will be delayed by at least
Artem Titovab30d722021-07-27 14:22:1144 // `target_delay_ms`.
mikhal@webrtc.orgef9f76a2013-02-15 23:22:1845 void SetTargetBufferingDelay(int target_delay_ms);
stefan@webrtc.org5f284982012-06-28 07:51:1646
Ivo Creusenbef7b052020-09-08 14:30:2547 // Lowers the audio delay by 10%. Can be used to recover from errors.
48 void ReduceAudioDelay();
49
50 // Lowers the video delay by 10%. Can be used to recover from errors.
51 void ReduceVideoDelay();
52
Åsa Persson74d2b1d2020-02-10 15:33:2953 uint32_t audio_stream_id() const { return audio_stream_id_; }
54 uint32_t video_stream_id() const { return video_stream_id_; }
55
stefan@webrtc.org5f284982012-06-28 07:51:1656 private:
mflodman4cd27902016-08-05 13:28:4557 struct SynchronizationDelays {
Åsa Persson4fc52c82019-12-09 11:41:5658 int extra_ms = 0;
59 int last_ms = 0;
mflodman4cd27902016-08-05 13:28:4560 };
61
Åsa Persson74d2b1d2020-02-10 15:33:2962 const uint32_t video_stream_id_;
63 const uint32_t audio_stream_id_;
Åsa Persson4fc52c82019-12-09 11:41:5664 SynchronizationDelays audio_delay_;
65 SynchronizationDelays video_delay_;
mikhal@webrtc.orgef9f76a2013-02-15 23:22:1866 int base_target_delay_ms_;
pwestin@webrtc.org63117332013-04-22 18:57:1467 int avg_diff_ms_;
stefan@webrtc.org5f284982012-06-28 07:51:1668};
stefan@webrtc.org5f284982012-06-28 07:51:1669} // namespace webrtc
70
Mirko Bonadei92ea95e2017-09-15 04:47:3171#endif // VIDEO_STREAM_SYNCHRONIZATION_H_