mflodman | 4cd2790 | 2016-08-05 06:28:45 -0700 | [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 | |
| 11 | // RtpStreamsSynchronizer is responsible for synchronization audio and video for |
| 12 | // a given voice engine channel and video receive stream. |
| 13 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #ifndef VIDEO_RTP_STREAMS_SYNCHRONIZER_H_ |
| 15 | #define VIDEO_RTP_STREAMS_SYNCHRONIZER_H_ |
mflodman | 4cd2790 | 2016-08-05 06:28:45 -0700 | [diff] [blame] | 16 | |
| 17 | #include <memory> |
| 18 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "modules/include/module.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 20 | #include "rtc_base/critical_section.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "rtc_base/thread_checker.h" |
| 22 | #include "video/stream_synchronization.h" |
mflodman | 4cd2790 | 2016-08-05 06:28:45 -0700 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 26 | class Syncable; |
mflodman | 4cd2790 | 2016-08-05 06:28:45 -0700 | [diff] [blame] | 27 | |
mflodman | 4cd2790 | 2016-08-05 06:28:45 -0700 | [diff] [blame] | 28 | class RtpStreamsSynchronizer : public Module { |
| 29 | public: |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 30 | explicit RtpStreamsSynchronizer(Syncable* syncable_video); |
Mirko Bonadei | 8fdcac3 | 2018-08-28 16:30:18 +0200 | [diff] [blame] | 31 | ~RtpStreamsSynchronizer() override; |
mflodman | 4cd2790 | 2016-08-05 06:28:45 -0700 | [diff] [blame] | 32 | |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 33 | void ConfigureSync(Syncable* syncable_audio); |
mflodman | 4cd2790 | 2016-08-05 06:28:45 -0700 | [diff] [blame] | 34 | |
| 35 | // Implements Module. |
| 36 | int64_t TimeUntilNextProcess() override; |
| 37 | void Process() override; |
| 38 | |
Åsa Persson | fcf79cc | 2019-10-22 15:23:44 +0200 | [diff] [blame] | 39 | // Gets the estimated playout NTP timestamp for the video frame with |
| 40 | // |rtp_timestamp| and the sync offset between the current played out audio |
| 41 | // frame and the video frame. Returns true on success, false otherwise. |
| 42 | // The |estimated_freq_khz| is the frequency used in the RTP to NTP timestamp |
asapersson | de9e5ff | 2016-11-02 07:14:03 -0700 | [diff] [blame] | 43 | // conversion. |
Åsa Persson | fcf79cc | 2019-10-22 15:23:44 +0200 | [diff] [blame] | 44 | bool GetStreamSyncOffsetInMs(uint32_t rtp_timestamp, |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 45 | int64_t render_time_ms, |
Åsa Persson | fcf79cc | 2019-10-22 15:23:44 +0200 | [diff] [blame] | 46 | int64_t* video_playout_ntp_ms, |
asapersson | de9e5ff | 2016-11-02 07:14:03 -0700 | [diff] [blame] | 47 | int64_t* stream_offset_ms, |
| 48 | double* estimated_freq_khz) const; |
mflodman | 4cd2790 | 2016-08-05 06:28:45 -0700 | [diff] [blame] | 49 | |
| 50 | private: |
solenberg | 3ebbcb5 | 2017-01-31 03:58:40 -0800 | [diff] [blame] | 51 | Syncable* syncable_video_; |
mflodman | 4cd2790 | 2016-08-05 06:28:45 -0700 | [diff] [blame] | 52 | |
| 53 | rtc::CriticalSection crit_; |
danilchap | a37de39 | 2017-09-09 04:17:22 -0700 | [diff] [blame] | 54 | Syncable* syncable_audio_ RTC_GUARDED_BY(crit_); |
| 55 | std::unique_ptr<StreamSynchronization> sync_ RTC_GUARDED_BY(crit_); |
| 56 | StreamSynchronization::Measurements audio_measurement_ RTC_GUARDED_BY(crit_); |
| 57 | StreamSynchronization::Measurements video_measurement_ RTC_GUARDED_BY(crit_); |
mflodman | 4cd2790 | 2016-08-05 06:28:45 -0700 | [diff] [blame] | 58 | |
| 59 | rtc::ThreadChecker process_thread_checker_; |
Niels Möller | 1e06289 | 2018-02-07 10:18:32 +0100 | [diff] [blame] | 60 | int64_t last_sync_time_ RTC_GUARDED_BY(&process_thread_checker_); |
mflodman | 4cd2790 | 2016-08-05 06:28:45 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | } // namespace webrtc |
| 64 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 65 | #endif // VIDEO_RTP_STREAMS_SYNCHRONIZER_H_ |