Chromium Code Reviews| Index: webrtc/video/vie_sync_module.cc |
| diff --git a/webrtc/video/vie_sync_module.cc b/webrtc/video/vie_sync_module.cc |
| index f8376e53d1f6d0bf49b715ad09596bfd7201f556..780f5030629bc5b7f76aca5a5f00b972765e4d54 100644 |
| --- a/webrtc/video/vie_sync_module.cc |
| +++ b/webrtc/video/vie_sync_module.cc |
| @@ -10,16 +10,32 @@ |
| #include "webrtc/video/vie_sync_module.h" |
| +#include <algorithm> |
| + |
| #include "webrtc/base/checks.h" |
| #include "webrtc/base/logging.h" |
| #include "webrtc/base/trace_event.h" |
| #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" |
| #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
| #include "webrtc/modules/video_coding/include/video_coding.h" |
| +#include "webrtc/system_wrappers/include/clock.h" |
| #include "webrtc/video/stream_synchronization.h" |
| +#include "webrtc/video_frame.h" |
| #include "webrtc/voice_engine/include/voe_video_sync.h" |
| namespace webrtc { |
| +namespace { |
| +bool RtpTimestampToNtp(uint32_t timestamp, |
| + const RtcpList& rtcp_list, |
| + int64_t* timestamp_ms) { |
| + if (rtcp_list.size() != 2) |
| + return false; |
|
stefan-webrtc
2016/03/04 14:32:17
Maybe we should simply move this check into RtpToN
åsapersson
2016/03/09 15:44:35
Done.
|
| + |
| + if (!RtpToNtpMs(timestamp, rtcp_list, timestamp_ms)) |
| + return false; |
| + |
| + return true; |
| +} |
| int UpdateMeasurements(StreamSynchronization::Measurements* stream, |
| const RtpRtcp& rtp_rtcp, const RtpReceiver& receiver) { |
| @@ -47,16 +63,17 @@ int UpdateMeasurements(StreamSynchronization::Measurements* stream, |
| return 0; |
| } |
| +} // namespace |
| ViESyncModule::ViESyncModule(VideoCodingModule* vcm) |
| : vcm_(vcm), |
| + clock_(Clock::GetRealTimeClock()), |
| video_receiver_(NULL), |
| video_rtp_rtcp_(NULL), |
| voe_channel_id_(-1), |
| voe_sync_interface_(NULL), |
| last_sync_time_(TickTime::Now()), |
| - sync_() { |
| -} |
| + sync_() {} |
| ViESyncModule::~ViESyncModule() { |
| } |
| @@ -157,4 +174,32 @@ void ViESyncModule::Process() { |
| vcm_->SetMinimumPlayoutDelay(target_video_delay_ms); |
| } |
| +int64_t ViESyncModule::GetStreamSyncOffsetInMs(const VideoFrame& frame) { |
| + rtc::CritScope lock(&data_cs_); |
| + if (voe_channel_id_ == -1) |
| + return -1; |
| + |
| + uint32_t playout_timestamp = 0; |
| + if (voe_sync_interface_->GetPlayoutTimestamp(voe_channel_id_, |
| + playout_timestamp) != 0) { |
| + return -1; |
| + } |
| + int64_t latest_audio_ntp; |
| + if (!RtpTimestampToNtp(playout_timestamp, audio_measurement_.rtcp, |
| + &latest_audio_ntp)) { |
| + return -1; |
| + } |
| + int64_t latest_video_ntp; |
| + if (!RtpTimestampToNtp(frame.timestamp(), video_measurement_.rtcp, |
| + &latest_video_ntp)) { |
| + return -1; |
| + } |
| + int64_t time_to_render_ms = |
| + frame.render_time_ms() - clock_->TimeInMilliseconds(); |
| + if (time_to_render_ms > 0) |
| + latest_video_ntp += time_to_render_ms; |
| + |
| + return std::abs(latest_audio_ntp - latest_video_ntp); |
| +} |
| + |
| } // namespace webrtc |