blob: b6e5e61575319eb4b566968b08f4f8a0b5c78c93 [file] [log] [blame]
mflodman4cd27902016-08-05 06:28:45 -07001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020014#ifndef VIDEO_RTP_STREAMS_SYNCHRONIZER_H_
15#define VIDEO_RTP_STREAMS_SYNCHRONIZER_H_
mflodman4cd27902016-08-05 06:28:45 -070016
17#include <memory>
18
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "modules/include/module.h"
Steve Anton10542f22019-01-11 09:11:00 -080020#include "rtc_base/critical_section.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "rtc_base/thread_checker.h"
22#include "video/stream_synchronization.h"
mflodman4cd27902016-08-05 06:28:45 -070023
24namespace webrtc {
25
solenberg3ebbcb52017-01-31 03:58:40 -080026class Syncable;
mflodman4cd27902016-08-05 06:28:45 -070027
mflodman4cd27902016-08-05 06:28:45 -070028class RtpStreamsSynchronizer : public Module {
29 public:
solenberg3ebbcb52017-01-31 03:58:40 -080030 explicit RtpStreamsSynchronizer(Syncable* syncable_video);
Mirko Bonadei8fdcac32018-08-28 16:30:18 +020031 ~RtpStreamsSynchronizer() override;
mflodman4cd27902016-08-05 06:28:45 -070032
solenberg3ebbcb52017-01-31 03:58:40 -080033 void ConfigureSync(Syncable* syncable_audio);
mflodman4cd27902016-08-05 06:28:45 -070034
35 // Implements Module.
36 int64_t TimeUntilNextProcess() override;
37 void Process() override;
38
Åsa Perssonfcf79cc2019-10-22 15:23:44 +020039 // 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
asaperssonde9e5ff2016-11-02 07:14:03 -070043 // conversion.
Åsa Perssonfcf79cc2019-10-22 15:23:44 +020044 bool GetStreamSyncOffsetInMs(uint32_t rtp_timestamp,
solenberg3ebbcb52017-01-31 03:58:40 -080045 int64_t render_time_ms,
Åsa Perssonfcf79cc2019-10-22 15:23:44 +020046 int64_t* video_playout_ntp_ms,
asaperssonde9e5ff2016-11-02 07:14:03 -070047 int64_t* stream_offset_ms,
48 double* estimated_freq_khz) const;
mflodman4cd27902016-08-05 06:28:45 -070049
50 private:
solenberg3ebbcb52017-01-31 03:58:40 -080051 Syncable* syncable_video_;
mflodman4cd27902016-08-05 06:28:45 -070052
53 rtc::CriticalSection crit_;
danilchapa37de392017-09-09 04:17:22 -070054 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_);
mflodman4cd27902016-08-05 06:28:45 -070058
59 rtc::ThreadChecker process_thread_checker_;
Niels Möller1e062892018-02-07 10:18:32 +010060 int64_t last_sync_time_ RTC_GUARDED_BY(&process_thread_checker_);
mflodman4cd27902016-08-05 06:28:45 -070061};
62
63} // namespace webrtc
64
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020065#endif // VIDEO_RTP_STREAMS_SYNCHRONIZER_H_