blob: c700ee3bf70641fc792edcbdea45e23a67da8fd9 [file] [log] [blame]
stefan@webrtc.org5f284982012-06-28 07:51:16 +00001/*
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
Peter Boström7623ce42015-12-09 12:13:30 +010011#ifndef WEBRTC_VIDEO_STREAM_SYNCHRONIZATION_H_
12#define WEBRTC_VIDEO_STREAM_SYNCHRONIZATION_H_
stefan@webrtc.org5f284982012-06-28 07:51:16 +000013
stefan@webrtc.org7c3523c2012-09-11 07:00:42 +000014#include <list>
15
Henrik Kjellander98f53512015-10-28 18:17:40 +010016#include "webrtc/system_wrappers/include/rtp_to_ntp.h"
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000017#include "webrtc/typedefs.h"
stefan@webrtc.org5f284982012-06-28 07:51:16 +000018
19namespace webrtc {
20
stefan@webrtc.org5f284982012-06-28 07:51:16 +000021class StreamSynchronization {
22 public:
23 struct Measurements {
stefan@webrtc.org7c3523c2012-09-11 07:00:42 +000024 Measurements() : rtcp(), latest_receive_time_ms(0), latest_timestamp(0) {}
asaperssonde9e5ff2016-11-02 07:14:03 -070025 RtcpMeasurements rtcp;
stefan@webrtc.org7c3523c2012-09-11 07:00:42 +000026 int64_t latest_receive_time_ms;
27 uint32_t latest_timestamp;
stefan@webrtc.org5f284982012-06-28 07:51:16 +000028 };
29
Peter Boström36a14382015-05-21 17:00:24 +020030 StreamSynchronization(uint32_t video_primary_ssrc, int audio_channel_id);
stefan@webrtc.org5f284982012-06-28 07:51:16 +000031
stefan@webrtc.org7c3523c2012-09-11 07:00:42 +000032 bool ComputeDelays(int relative_delay_ms,
33 int current_audio_delay_ms,
34 int* extra_audio_delay_ms,
35 int* total_video_delay_target_ms);
36
37 // On success |relative_delay| contains the number of milliseconds later video
38 // is rendered relative audio. If audio is played back later than video a
39 // |relative_delay| will be negative.
40 static bool ComputeRelativeDelay(const Measurements& audio_measurement,
41 const Measurements& video_measurement,
42 int* relative_delay_ms);
mikhal@webrtc.orgef9f76a2013-02-15 23:22:18 +000043 // Set target buffering delay - All audio and video will be delayed by at
44 // least target_delay_ms.
45 void SetTargetBufferingDelay(int target_delay_ms);
stefan@webrtc.org5f284982012-06-28 07:51:16 +000046
47 private:
mflodman4cd27902016-08-05 06:28:45 -070048 struct SynchronizationDelays {
49 int extra_video_delay_ms = 0;
50 int last_video_delay_ms = 0;
51 int extra_audio_delay_ms = 0;
52 int last_audio_delay_ms = 0;
53 };
54
55 SynchronizationDelays channel_delay_;
Peter Boström36a14382015-05-21 17:00:24 +020056 const uint32_t video_primary_ssrc_;
57 const int audio_channel_id_;
mikhal@webrtc.orgef9f76a2013-02-15 23:22:18 +000058 int base_target_delay_ms_;
pwestin@webrtc.org63117332013-04-22 18:57:14 +000059 int avg_diff_ms_;
stefan@webrtc.org5f284982012-06-28 07:51:16 +000060};
stefan@webrtc.org5f284982012-06-28 07:51:16 +000061} // namespace webrtc
62
Peter Boström7623ce42015-12-09 12:13:30 +010063#endif // WEBRTC_VIDEO_STREAM_SYNCHRONIZATION_H_