OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/video/vie_sync_module.h" | 11 #include "webrtc/video/vie_sync_module.h" |
12 | 12 |
13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
14 #include "webrtc/base/logging.h" | 14 #include "webrtc/base/logging.h" |
| 15 #include "webrtc/base/timeutils.h" |
15 #include "webrtc/base/trace_event.h" | 16 #include "webrtc/base/trace_event.h" |
16 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" | 17 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" |
17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 18 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
18 #include "webrtc/modules/video_coding/video_coding_impl.h" | 19 #include "webrtc/modules/video_coding/video_coding_impl.h" |
19 #include "webrtc/system_wrappers/include/clock.h" | 20 #include "webrtc/system_wrappers/include/clock.h" |
20 #include "webrtc/video/stream_synchronization.h" | 21 #include "webrtc/video/stream_synchronization.h" |
21 #include "webrtc/video_frame.h" | 22 #include "webrtc/video_frame.h" |
22 #include "webrtc/voice_engine/include/voe_video_sync.h" | 23 #include "webrtc/voice_engine/include/voe_video_sync.h" |
23 | 24 |
24 namespace webrtc { | 25 namespace webrtc { |
(...skipping 23 matching lines...) Expand all Loading... |
48 } | 49 } |
49 } // namespace | 50 } // namespace |
50 | 51 |
51 ViESyncModule::ViESyncModule(vcm::VideoReceiver* video_receiver) | 52 ViESyncModule::ViESyncModule(vcm::VideoReceiver* video_receiver) |
52 : video_receiver_(video_receiver), | 53 : video_receiver_(video_receiver), |
53 clock_(Clock::GetRealTimeClock()), | 54 clock_(Clock::GetRealTimeClock()), |
54 rtp_receiver_(nullptr), | 55 rtp_receiver_(nullptr), |
55 video_rtp_rtcp_(nullptr), | 56 video_rtp_rtcp_(nullptr), |
56 voe_channel_id_(-1), | 57 voe_channel_id_(-1), |
57 voe_sync_interface_(nullptr), | 58 voe_sync_interface_(nullptr), |
58 last_sync_time_(TickTime::Now()), | 59 last_sync_time_(rtc::TimeNanos()), |
59 sync_() {} | 60 sync_() {} |
60 | 61 |
61 ViESyncModule::~ViESyncModule() { | 62 ViESyncModule::~ViESyncModule() { |
62 } | 63 } |
63 | 64 |
64 void ViESyncModule::ConfigureSync(int voe_channel_id, | 65 void ViESyncModule::ConfigureSync(int voe_channel_id, |
65 VoEVideoSync* voe_sync_interface, | 66 VoEVideoSync* voe_sync_interface, |
66 RtpRtcp* video_rtcp_module, | 67 RtpRtcp* video_rtcp_module, |
67 RtpReceiver* rtp_receiver) { | 68 RtpReceiver* rtp_receiver) { |
68 if (voe_channel_id != -1) | 69 if (voe_channel_id != -1) |
69 RTC_DCHECK(voe_sync_interface); | 70 RTC_DCHECK(voe_sync_interface); |
70 rtc::CritScope lock(&data_cs_); | 71 rtc::CritScope lock(&data_cs_); |
71 // Prevent expensive no-ops. | 72 // Prevent expensive no-ops. |
72 if (voe_channel_id_ == voe_channel_id && | 73 if (voe_channel_id_ == voe_channel_id && |
73 voe_sync_interface_ == voe_sync_interface && | 74 voe_sync_interface_ == voe_sync_interface && |
74 rtp_receiver_ == rtp_receiver && video_rtp_rtcp_ == video_rtcp_module) { | 75 rtp_receiver_ == rtp_receiver && video_rtp_rtcp_ == video_rtcp_module) { |
75 return; | 76 return; |
76 } | 77 } |
77 voe_channel_id_ = voe_channel_id; | 78 voe_channel_id_ = voe_channel_id; |
78 voe_sync_interface_ = voe_sync_interface; | 79 voe_sync_interface_ = voe_sync_interface; |
79 rtp_receiver_ = rtp_receiver; | 80 rtp_receiver_ = rtp_receiver; |
80 video_rtp_rtcp_ = video_rtcp_module; | 81 video_rtp_rtcp_ = video_rtcp_module; |
81 sync_.reset( | 82 sync_.reset( |
82 new StreamSynchronization(video_rtp_rtcp_->SSRC(), voe_channel_id)); | 83 new StreamSynchronization(video_rtp_rtcp_->SSRC(), voe_channel_id)); |
83 } | 84 } |
84 | 85 |
85 int64_t ViESyncModule::TimeUntilNextProcess() { | 86 int64_t ViESyncModule::TimeUntilNextProcess() { |
86 const int64_t kSyncIntervalMs = 1000; | 87 const int64_t kSyncIntervalMs = 1000; |
87 return kSyncIntervalMs - (TickTime::Now() - last_sync_time_).Milliseconds(); | 88 return kSyncIntervalMs - |
| 89 (rtc::TimeNanos() - last_sync_time_) / rtc::kNumNanosecsPerMillisec; |
88 } | 90 } |
89 | 91 |
90 void ViESyncModule::Process() { | 92 void ViESyncModule::Process() { |
91 rtc::CritScope lock(&data_cs_); | 93 rtc::CritScope lock(&data_cs_); |
92 last_sync_time_ = TickTime::Now(); | 94 last_sync_time_ = rtc::TimeNanos(); |
93 | 95 |
94 const int current_video_delay_ms = video_receiver_->Delay(); | 96 const int current_video_delay_ms = video_receiver_->Delay(); |
95 | 97 |
96 if (voe_channel_id_ == -1) { | 98 if (voe_channel_id_ == -1) { |
97 return; | 99 return; |
98 } | 100 } |
99 assert(video_rtp_rtcp_ && voe_sync_interface_); | 101 assert(video_rtp_rtcp_ && voe_sync_interface_); |
100 assert(sync_.get()); | 102 assert(sync_.get()); |
101 | 103 |
102 int audio_jitter_buffer_delay_ms = 0; | 104 int audio_jitter_buffer_delay_ms = 0; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 int64_t time_to_render_ms = | 185 int64_t time_to_render_ms = |
184 frame.render_time_ms() - clock_->TimeInMilliseconds(); | 186 frame.render_time_ms() - clock_->TimeInMilliseconds(); |
185 if (time_to_render_ms > 0) | 187 if (time_to_render_ms > 0) |
186 latest_video_ntp += time_to_render_ms; | 188 latest_video_ntp += time_to_render_ms; |
187 | 189 |
188 *stream_offset_ms = latest_audio_ntp - latest_video_ntp; | 190 *stream_offset_ms = latest_audio_ntp - latest_video_ntp; |
189 return true; | 191 return true; |
190 } | 192 } |
191 | 193 |
192 } // namespace webrtc | 194 } // namespace webrtc |
OLD | NEW |