| 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/trace_event.h" | 15 #include "webrtc/base/trace_event.h" |
| 16 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" | 16 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" |
| 17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
| 18 #include "webrtc/modules/video_coding/include/video_coding.h" | 18 #include "webrtc/modules/video_coding/include/video_coding.h" |
| 19 #include "webrtc/system_wrappers/include/clock.h" |
| 19 #include "webrtc/video/stream_synchronization.h" | 20 #include "webrtc/video/stream_synchronization.h" |
| 21 #include "webrtc/video_frame.h" |
| 20 #include "webrtc/voice_engine/include/voe_video_sync.h" | 22 #include "webrtc/voice_engine/include/voe_video_sync.h" |
| 21 | 23 |
| 22 namespace webrtc { | 24 namespace webrtc { |
| 23 | 25 namespace { |
| 24 int UpdateMeasurements(StreamSynchronization::Measurements* stream, | 26 int UpdateMeasurements(StreamSynchronization::Measurements* stream, |
| 25 const RtpRtcp& rtp_rtcp, const RtpReceiver& receiver) { | 27 const RtpRtcp& rtp_rtcp, const RtpReceiver& receiver) { |
| 26 if (!receiver.Timestamp(&stream->latest_timestamp)) | 28 if (!receiver.Timestamp(&stream->latest_timestamp)) |
| 27 return -1; | 29 return -1; |
| 28 if (!receiver.LastReceivedTimeMs(&stream->latest_receive_time_ms)) | 30 if (!receiver.LastReceivedTimeMs(&stream->latest_receive_time_ms)) |
| 29 return -1; | 31 return -1; |
| 30 | 32 |
| 31 uint32_t ntp_secs = 0; | 33 uint32_t ntp_secs = 0; |
| 32 uint32_t ntp_frac = 0; | 34 uint32_t ntp_frac = 0; |
| 33 uint32_t rtp_timestamp = 0; | 35 uint32_t rtp_timestamp = 0; |
| 34 if (0 != rtp_rtcp.RemoteNTP(&ntp_secs, | 36 if (0 != rtp_rtcp.RemoteNTP(&ntp_secs, |
| 35 &ntp_frac, | 37 &ntp_frac, |
| 36 NULL, | 38 NULL, |
| 37 NULL, | 39 NULL, |
| 38 &rtp_timestamp)) { | 40 &rtp_timestamp)) { |
| 39 return -1; | 41 return -1; |
| 40 } | 42 } |
| 41 | 43 |
| 42 bool new_rtcp_sr = false; | 44 bool new_rtcp_sr = false; |
| 43 if (!UpdateRtcpList( | 45 if (!UpdateRtcpList( |
| 44 ntp_secs, ntp_frac, rtp_timestamp, &stream->rtcp, &new_rtcp_sr)) { | 46 ntp_secs, ntp_frac, rtp_timestamp, &stream->rtcp, &new_rtcp_sr)) { |
| 45 return -1; | 47 return -1; |
| 46 } | 48 } |
| 47 | 49 |
| 48 return 0; | 50 return 0; |
| 49 } | 51 } |
| 52 } // namespace |
| 50 | 53 |
| 51 ViESyncModule::ViESyncModule(VideoCodingModule* vcm) | 54 ViESyncModule::ViESyncModule(VideoCodingModule* vcm) |
| 52 : vcm_(vcm), | 55 : vcm_(vcm), |
| 56 clock_(Clock::GetRealTimeClock()), |
| 53 video_receiver_(NULL), | 57 video_receiver_(NULL), |
| 54 video_rtp_rtcp_(NULL), | 58 video_rtp_rtcp_(NULL), |
| 55 voe_channel_id_(-1), | 59 voe_channel_id_(-1), |
| 56 voe_sync_interface_(NULL), | 60 voe_sync_interface_(NULL), |
| 57 last_sync_time_(TickTime::Now()), | 61 last_sync_time_(TickTime::Now()), |
| 58 sync_() { | 62 sync_() {} |
| 59 } | |
| 60 | 63 |
| 61 ViESyncModule::~ViESyncModule() { | 64 ViESyncModule::~ViESyncModule() { |
| 62 } | 65 } |
| 63 | 66 |
| 64 void ViESyncModule::ConfigureSync(int voe_channel_id, | 67 void ViESyncModule::ConfigureSync(int voe_channel_id, |
| 65 VoEVideoSync* voe_sync_interface, | 68 VoEVideoSync* voe_sync_interface, |
| 66 RtpRtcp* video_rtcp_module, | 69 RtpRtcp* video_rtcp_module, |
| 67 RtpReceiver* video_receiver) { | 70 RtpReceiver* video_receiver) { |
| 68 if (voe_channel_id != -1) | 71 if (voe_channel_id != -1) |
| 69 RTC_DCHECK(voe_sync_interface); | 72 RTC_DCHECK(voe_sync_interface); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 return; | 153 return; |
| 151 } | 154 } |
| 152 | 155 |
| 153 if (voe_sync_interface_->SetMinimumPlayoutDelay( | 156 if (voe_sync_interface_->SetMinimumPlayoutDelay( |
| 154 voe_channel_id_, target_audio_delay_ms) == -1) { | 157 voe_channel_id_, target_audio_delay_ms) == -1) { |
| 155 LOG(LS_ERROR) << "Error setting voice delay."; | 158 LOG(LS_ERROR) << "Error setting voice delay."; |
| 156 } | 159 } |
| 157 vcm_->SetMinimumPlayoutDelay(target_video_delay_ms); | 160 vcm_->SetMinimumPlayoutDelay(target_video_delay_ms); |
| 158 } | 161 } |
| 159 | 162 |
| 163 bool ViESyncModule::GetStreamSyncOffsetInMs(const VideoFrame& frame, |
| 164 int64_t* stream_offset_ms) const { |
| 165 rtc::CritScope lock(&data_cs_); |
| 166 if (voe_channel_id_ == -1) |
| 167 return false; |
| 168 |
| 169 uint32_t playout_timestamp = 0; |
| 170 if (voe_sync_interface_->GetPlayoutTimestamp(voe_channel_id_, |
| 171 playout_timestamp) != 0) { |
| 172 return false; |
| 173 } |
| 174 |
| 175 int64_t latest_audio_ntp; |
| 176 if (!RtpToNtpMs(playout_timestamp, audio_measurement_.rtcp, |
| 177 &latest_audio_ntp)) { |
| 178 return false; |
| 179 } |
| 180 |
| 181 int64_t latest_video_ntp; |
| 182 if (!RtpToNtpMs(frame.timestamp(), video_measurement_.rtcp, |
| 183 &latest_video_ntp)) { |
| 184 return false; |
| 185 } |
| 186 |
| 187 int64_t time_to_render_ms = |
| 188 frame.render_time_ms() - clock_->TimeInMilliseconds(); |
| 189 if (time_to_render_ms > 0) |
| 190 latest_video_ntp += time_to_render_ms; |
| 191 |
| 192 *stream_offset_ms = latest_audio_ntp - latest_video_ntp; |
| 193 return true; |
| 194 } |
| 195 |
| 160 } // namespace webrtc | 196 } // namespace webrtc |
| OLD | NEW |