| 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..9feace79b930e189969d6fd4c4efd2b48866e86c 100644
|
| --- a/webrtc/video/vie_sync_module.cc
|
| +++ b/webrtc/video/vie_sync_module.cc
|
| @@ -16,11 +16,13 @@
|
| #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 {
|
| int UpdateMeasurements(StreamSynchronization::Measurements* stream,
|
| const RtpRtcp& rtp_rtcp, const RtpReceiver& receiver) {
|
| if (!receiver.Timestamp(&stream->latest_timestamp))
|
| @@ -47,16 +49,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 +160,37 @@ void ViESyncModule::Process() {
|
| vcm_->SetMinimumPlayoutDelay(target_video_delay_ms);
|
| }
|
|
|
| +bool ViESyncModule::GetStreamSyncOffsetInMs(const VideoFrame& frame,
|
| + int64_t* stream_offset_ms) const {
|
| + rtc::CritScope lock(&data_cs_);
|
| + if (voe_channel_id_ == -1)
|
| + return false;
|
| +
|
| + uint32_t playout_timestamp = 0;
|
| + if (voe_sync_interface_->GetPlayoutTimestamp(voe_channel_id_,
|
| + playout_timestamp) != 0) {
|
| + return false;
|
| + }
|
| +
|
| + int64_t latest_audio_ntp;
|
| + if (!RtpToNtpMs(playout_timestamp, audio_measurement_.rtcp,
|
| + &latest_audio_ntp)) {
|
| + return false;
|
| + }
|
| +
|
| + int64_t latest_video_ntp;
|
| + if (!RtpToNtpMs(frame.timestamp(), video_measurement_.rtcp,
|
| + &latest_video_ntp)) {
|
| + return false;
|
| + }
|
| +
|
| + 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;
|
| +
|
| + *stream_offset_ms = latest_audio_ntp - latest_video_ntp;
|
| + return true;
|
| +}
|
| +
|
| } // namespace webrtc
|
|
|