blob: afa15015d4662e3b905717074ec9840ba5ca2874 [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
14#ifndef WEBRTC_VIDEO_RTP_STREAMS_SYNCHRONIZER_H_
15#define WEBRTC_VIDEO_RTP_STREAMS_SYNCHRONIZER_H_
16
17#include <memory>
18
19#include "webrtc/base/criticalsection.h"
20#include "webrtc/base/thread_checker.h"
21#include "webrtc/modules/include/module.h"
mflodman4cd27902016-08-05 06:28:45 -070022#include "webrtc/video/stream_synchronization.h"
23
24namespace webrtc {
25
solenberg3ebbcb52017-01-31 03:58:40 -080026class Syncable;
mflodman4cd27902016-08-05 06:28:45 -070027
28namespace vcm {
29class VideoReceiver;
30} // namespace vcm
31
32class RtpStreamsSynchronizer : public Module {
33 public:
solenberg3ebbcb52017-01-31 03:58:40 -080034 explicit RtpStreamsSynchronizer(Syncable* syncable_video);
mflodman4cd27902016-08-05 06:28:45 -070035
solenberg3ebbcb52017-01-31 03:58:40 -080036 void ConfigureSync(Syncable* syncable_audio);
mflodman4cd27902016-08-05 06:28:45 -070037
38 // Implements Module.
39 int64_t TimeUntilNextProcess() override;
40 void Process() override;
41
42 // Gets the sync offset between the current played out audio frame and the
43 // video |frame|. Returns true on success, false otherwise.
asaperssonde9e5ff2016-11-02 07:14:03 -070044 // The estimated frequency is the frequency used in the RTP to NTP timestamp
45 // conversion.
solenberg3ebbcb52017-01-31 03:58:40 -080046 bool GetStreamSyncOffsetInMs(uint32_t timestamp,
47 int64_t render_time_ms,
asaperssonde9e5ff2016-11-02 07:14:03 -070048 int64_t* stream_offset_ms,
49 double* estimated_freq_khz) const;
mflodman4cd27902016-08-05 06:28:45 -070050
51 private:
solenberg3ebbcb52017-01-31 03:58:40 -080052 Syncable* syncable_video_;
mflodman4cd27902016-08-05 06:28:45 -070053
54 rtc::CriticalSection crit_;
solenberg3ebbcb52017-01-31 03:58:40 -080055 Syncable* syncable_audio_ GUARDED_BY(crit_);
mflodman4cd27902016-08-05 06:28:45 -070056 std::unique_ptr<StreamSynchronization> sync_ GUARDED_BY(crit_);
57 StreamSynchronization::Measurements audio_measurement_ GUARDED_BY(crit_);
58 StreamSynchronization::Measurements video_measurement_ GUARDED_BY(crit_);
59
60 rtc::ThreadChecker process_thread_checker_;
61 int64_t last_sync_time_ ACCESS_ON(&process_thread_checker_);
62};
63
64} // namespace webrtc
65
66#endif // WEBRTC_VIDEO_RTP_STREAMS_SYNCHRONIZER_H_