blob: 082bec7b6e0f4fd3c5d582a0ebc5ebb170b42bdd [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"
22#include "webrtc/video/rtp_stream_receiver.h"
23#include "webrtc/video/stream_synchronization.h"
24
25namespace webrtc {
26
27class Clock;
28class VideoFrame;
29class VoEVideoSync;
30
31namespace vcm {
32class VideoReceiver;
33} // namespace vcm
34
35class RtpStreamsSynchronizer : public Module {
36 public:
37 RtpStreamsSynchronizer(vcm::VideoReceiver* vcm,
38 RtpStreamReceiver* rtp_stream_receiver);
39
40 void ConfigureSync(int voe_channel_id,
41 VoEVideoSync* voe_sync_interface);
42
43 // Implements Module.
44 int64_t TimeUntilNextProcess() override;
45 void Process() override;
46
47 // Gets the sync offset between the current played out audio frame and the
48 // video |frame|. Returns true on success, false otherwise.
49 bool GetStreamSyncOffsetInMs(const VideoFrame& frame,
50 int64_t* stream_offset_ms) const;
51
52 private:
53 Clock* const clock_;
54 vcm::VideoReceiver* const video_receiver_;
55 RtpReceiver* const video_rtp_receiver_;
56 RtpRtcp* const video_rtp_rtcp_;
57
58 rtc::CriticalSection crit_;
59 int voe_channel_id_ GUARDED_BY(crit_);
60 VoEVideoSync* voe_sync_interface_ GUARDED_BY(crit_);
61 RtpReceiver* audio_rtp_receiver_ GUARDED_BY(crit_);
62 RtpRtcp* audio_rtp_rtcp_ GUARDED_BY(crit_);
63 std::unique_ptr<StreamSynchronization> sync_ GUARDED_BY(crit_);
64 StreamSynchronization::Measurements audio_measurement_ GUARDED_BY(crit_);
65 StreamSynchronization::Measurements video_measurement_ GUARDED_BY(crit_);
66
67 rtc::ThreadChecker process_thread_checker_;
68 int64_t last_sync_time_ ACCESS_ON(&process_thread_checker_);
69};
70
71} // namespace webrtc
72
73#endif // WEBRTC_VIDEO_RTP_STREAMS_SYNCHRONIZER_H_