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/include/video_coding.h" | 19 #include "webrtc/modules/video_coding/include/video_coding.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(VideoCodingModule* vcm) | 52 ViESyncModule::ViESyncModule(VideoCodingModule* vcm) |
52 : vcm_(vcm), | 53 : vcm_(vcm), |
53 clock_(Clock::GetRealTimeClock()), | 54 clock_(Clock::GetRealTimeClock()), |
54 video_receiver_(nullptr), | 55 video_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* video_receiver) { | 68 RtpReceiver* video_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 video_receiver_ == video_receiver && | 75 video_receiver_ == video_receiver && |
75 video_rtp_rtcp_ == video_rtcp_module) { | 76 video_rtp_rtcp_ == video_rtcp_module) { |
76 return; | 77 return; |
77 } | 78 } |
78 voe_channel_id_ = voe_channel_id; | 79 voe_channel_id_ = voe_channel_id; |
79 voe_sync_interface_ = voe_sync_interface; | 80 voe_sync_interface_ = voe_sync_interface; |
80 video_receiver_ = video_receiver; | 81 video_receiver_ = video_receiver; |
81 video_rtp_rtcp_ = video_rtcp_module; | 82 video_rtp_rtcp_ = video_rtcp_module; |
82 sync_.reset( | 83 sync_.reset( |
83 new StreamSynchronization(video_rtp_rtcp_->SSRC(), voe_channel_id)); | 84 new StreamSynchronization(video_rtp_rtcp_->SSRC(), voe_channel_id)); |
84 } | 85 } |
85 | 86 |
86 int64_t ViESyncModule::TimeUntilNextProcess() { | 87 int64_t ViESyncModule::TimeUntilNextProcess() { |
87 const int64_t kSyncIntervalMs = 1000; | 88 const int64_t kSyncIntervalMs = 1000; |
88 return kSyncIntervalMs - (TickTime::Now() - last_sync_time_).Milliseconds(); | 89 return kSyncIntervalMs - |
| 90 (rtc::TimeNanos() - last_sync_time_) / rtc::kNumNanosecsPerMillisec; |
89 } | 91 } |
90 | 92 |
91 void ViESyncModule::Process() { | 93 void ViESyncModule::Process() { |
92 rtc::CritScope lock(&data_cs_); | 94 rtc::CritScope lock(&data_cs_); |
93 last_sync_time_ = TickTime::Now(); | 95 last_sync_time_ = rtc::TimeNanos(); |
94 | 96 |
95 const int current_video_delay_ms = vcm_->Delay(); | 97 const int current_video_delay_ms = vcm_->Delay(); |
96 | 98 |
97 if (voe_channel_id_ == -1) { | 99 if (voe_channel_id_ == -1) { |
98 return; | 100 return; |
99 } | 101 } |
100 assert(video_rtp_rtcp_ && voe_sync_interface_); | 102 assert(video_rtp_rtcp_ && voe_sync_interface_); |
101 assert(sync_.get()); | 103 assert(sync_.get()); |
102 | 104 |
103 int audio_jitter_buffer_delay_ms = 0; | 105 int audio_jitter_buffer_delay_ms = 0; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 int64_t time_to_render_ms = | 186 int64_t time_to_render_ms = |
185 frame.render_time_ms() - clock_->TimeInMilliseconds(); | 187 frame.render_time_ms() - clock_->TimeInMilliseconds(); |
186 if (time_to_render_ms > 0) | 188 if (time_to_render_ms > 0) |
187 latest_video_ntp += time_to_render_ms; | 189 latest_video_ntp += time_to_render_ms; |
188 | 190 |
189 *stream_offset_ms = latest_audio_ntp - latest_video_ntp; | 191 *stream_offset_ms = latest_audio_ntp - latest_video_ntp; |
190 return true; | 192 return true; |
191 } | 193 } |
192 | 194 |
193 } // namespace webrtc | 195 } // namespace webrtc |
OLD | NEW |