stefan@webrtc.org | 5f28498 | 2012-06-28 07:51:16 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef VIDEO_STREAM_SYNCHRONIZATION_H_ |
| 12 | #define VIDEO_STREAM_SYNCHRONIZATION_H_ |
stefan@webrtc.org | 5f28498 | 2012-06-28 07:51:16 +0000 | [diff] [blame] | 13 | |
stefan@webrtc.org | 7c3523c | 2012-09-11 07:00:42 +0000 | [diff] [blame] | 14 | #include <list> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "system_wrappers/include/rtp_to_ntp_estimator.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 17 | #include "typedefs.h" // NOLINT(build/include) |
stefan@webrtc.org | 5f28498 | 2012-06-28 07:51:16 +0000 | [diff] [blame] | 18 | |
| 19 | namespace webrtc { |
| 20 | |
stefan@webrtc.org | 5f28498 | 2012-06-28 07:51:16 +0000 | [diff] [blame] | 21 | class StreamSynchronization { |
| 22 | public: |
| 23 | struct Measurements { |
asapersson | fe50b4d | 2016-12-22 07:53:51 -0800 | [diff] [blame] | 24 | Measurements() : latest_receive_time_ms(0), latest_timestamp(0) {} |
| 25 | RtpToNtpEstimator rtp_to_ntp; |
stefan@webrtc.org | 7c3523c | 2012-09-11 07:00:42 +0000 | [diff] [blame] | 26 | int64_t latest_receive_time_ms; |
| 27 | uint32_t latest_timestamp; |
stefan@webrtc.org | 5f28498 | 2012-06-28 07:51:16 +0000 | [diff] [blame] | 28 | }; |
| 29 | |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 30 | StreamSynchronization(int video_stream_id, int audio_stream_id); |
stefan@webrtc.org | 5f28498 | 2012-06-28 07:51:16 +0000 | [diff] [blame] | 31 | |
stefan@webrtc.org | 7c3523c | 2012-09-11 07:00:42 +0000 | [diff] [blame] | 32 | 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.org | ef9f76a | 2013-02-15 23:22:18 +0000 | [diff] [blame] | 43 | // 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.org | 5f28498 | 2012-06-28 07:51:16 +0000 | [diff] [blame] | 46 | |
| 47 | private: |
mflodman | 4cd2790 | 2016-08-05 06:28:45 -0700 | [diff] [blame] | 48 | 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_; |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 56 | const int video_stream_id_; |
| 57 | const int audio_stream_id_; |
mikhal@webrtc.org | ef9f76a | 2013-02-15 23:22:18 +0000 | [diff] [blame] | 58 | int base_target_delay_ms_; |
pwestin@webrtc.org | 6311733 | 2013-04-22 18:57:14 +0000 | [diff] [blame] | 59 | int avg_diff_ms_; |
stefan@webrtc.org | 5f28498 | 2012-06-28 07:51:16 +0000 | [diff] [blame] | 60 | }; |
stefan@webrtc.org | 5f28498 | 2012-06-28 07:51:16 +0000 | [diff] [blame] | 61 | } // namespace webrtc |
| 62 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 63 | #endif // VIDEO_STREAM_SYNCHRONIZATION_H_ |