Index: webrtc/video/rtp_streams_synchronizer.cc |
diff --git a/webrtc/video/rtp_streams_synchronizer.cc b/webrtc/video/rtp_streams_synchronizer.cc |
index 0d026b310a492d0463f6d9ac12ff0d4f46bec1d3..9a30f29affcf148155ada0a99d01d93fff1a1ab3 100644 |
--- a/webrtc/video/rtp_streams_synchronizer.cc |
+++ b/webrtc/video/rtp_streams_synchronizer.cc |
@@ -14,17 +14,17 @@ |
#include "webrtc/base/logging.h" |
#include "webrtc/base/timeutils.h" |
#include "webrtc/base/trace_event.h" |
+#include "webrtc/call/syncable.h" |
#include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" |
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
#include "webrtc/modules/video_coding/video_coding_impl.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 UpdateMeasurements(StreamSynchronization::Measurements* stream, |
+bool UpdateVideoMeasurements(StreamSynchronization::Measurements* stream, |
RtpRtcp* rtp_rtcp, |
stefan-webrtc
2017/01/19 11:59:59
git cl format
|
RtpReceiver* receiver) { |
if (!receiver->Timestamp(&stream->latest_timestamp)) |
@@ -48,6 +48,20 @@ bool UpdateMeasurements(StreamSynchronization::Measurements* stream, |
return true; |
} |
+ |
+bool UpdateAudioMeasurements(StreamSynchronization::Measurements* stream, |
+ const Syncable::Info& info) { |
+ RTC_DCHECK(stream); |
+ stream->latest_timestamp = info.latest_timestamp; |
+ stream->latest_receive_time_ms = info.latest_receive_time_ms; |
+ bool new_rtcp_sr = false; |
+ if (!stream->rtp_to_ntp.UpdateMeasurements(info.ntp_secs, info.ntp_frac, |
+ info.rtp_timestamp, |
+ &new_rtcp_sr)) { |
+ return false; |
+ } |
+ return true; |
+} |
} // namespace |
RtpStreamsSynchronizer::RtpStreamsSynchronizer( |
@@ -57,40 +71,24 @@ RtpStreamsSynchronizer::RtpStreamsSynchronizer( |
video_receiver_(video_receiver), |
video_rtp_receiver_(rtp_stream_receiver->GetRtpReceiver()), |
video_rtp_rtcp_(rtp_stream_receiver->rtp_rtcp()), |
- voe_channel_id_(-1), |
- voe_sync_interface_(nullptr), |
- audio_rtp_receiver_(nullptr), |
- audio_rtp_rtcp_(nullptr), |
+ syncable_(nullptr), |
sync_(), |
last_sync_time_(rtc::TimeNanos()) { |
process_thread_checker_.DetachFromThread(); |
} |
-void RtpStreamsSynchronizer::ConfigureSync(int voe_channel_id, |
- VoEVideoSync* voe_sync_interface) { |
- if (voe_channel_id != -1) |
- RTC_DCHECK(voe_sync_interface); |
- |
+void RtpStreamsSynchronizer::ConfigureSync(Syncable* syncable) { |
rtc::CritScope lock(&crit_); |
- if (voe_channel_id_ == voe_channel_id && |
- voe_sync_interface_ == voe_sync_interface) { |
+ if (syncable == syncable_) { |
// This prevents expensive no-ops. |
return; |
} |
- voe_channel_id_ = voe_channel_id; |
- voe_sync_interface_ = voe_sync_interface; |
- audio_rtp_rtcp_ = nullptr; |
- audio_rtp_receiver_ = nullptr; |
+ syncable_ = syncable; |
sync_.reset(nullptr); |
- |
- if (voe_channel_id_ != -1) { |
- voe_sync_interface_->GetRtpRtcp(voe_channel_id_, &audio_rtp_rtcp_, |
- &audio_rtp_receiver_); |
- RTC_DCHECK(audio_rtp_rtcp_); |
- RTC_DCHECK(audio_rtp_receiver_); |
+ if (syncable_) { |
sync_.reset(new StreamSynchronization(video_rtp_rtcp_->SSRC(), |
- voe_channel_id_)); |
+ syncable_->id())); |
} |
} |
@@ -108,30 +106,22 @@ void RtpStreamsSynchronizer::Process() { |
last_sync_time_ = rtc::TimeNanos(); |
rtc::CritScope lock(&crit_); |
- if (voe_channel_id_ == -1) { |
+ if (!syncable_) { |
return; |
} |
- RTC_DCHECK(voe_sync_interface_); |
RTC_DCHECK(sync_.get()); |
- int audio_jitter_buffer_delay_ms = 0; |
- int playout_buffer_delay_ms = 0; |
- if (voe_sync_interface_->GetDelayEstimate(voe_channel_id_, |
- &audio_jitter_buffer_delay_ms, |
- &playout_buffer_delay_ms) != 0) { |
+ rtc::Optional<Syncable::Info> audio_sync_info = syncable_->GetInfo(); |
+ if (!audio_sync_info) { |
return; |
} |
- const int current_audio_delay_ms = audio_jitter_buffer_delay_ms + |
- playout_buffer_delay_ms; |
- |
- int64_t last_video_receive_ms = video_measurement_.latest_receive_time_ms; |
- if (!UpdateMeasurements(&video_measurement_, video_rtp_rtcp_, |
- video_rtp_receiver_)) { |
+ if (!UpdateAudioMeasurements(&audio_measurement_, *audio_sync_info)) { |
return; |
} |
- if (!UpdateMeasurements(&audio_measurement_, audio_rtp_rtcp_, |
- audio_rtp_receiver_)) { |
+ int64_t last_video_receive_ms = video_measurement_.latest_receive_time_ms; |
+ if (!UpdateVideoMeasurements(&video_measurement_, video_rtp_rtcp_, |
+ video_rtp_receiver_)) { |
return; |
} |
@@ -148,23 +138,21 @@ void RtpStreamsSynchronizer::Process() { |
} |
TRACE_COUNTER1("webrtc", "SyncCurrentVideoDelay", current_video_delay_ms); |
- TRACE_COUNTER1("webrtc", "SyncCurrentAudioDelay", current_audio_delay_ms); |
+ TRACE_COUNTER1("webrtc", "SyncCurrentAudioDelay", |
+ audio_sync_info->current_delay_ms); |
TRACE_COUNTER1("webrtc", "SyncRelativeDelay", relative_delay_ms); |
int target_audio_delay_ms = 0; |
int target_video_delay_ms = current_video_delay_ms; |
// Calculate the necessary extra audio delay and desired total video |
// delay to get the streams in sync. |
if (!sync_->ComputeDelays(relative_delay_ms, |
- current_audio_delay_ms, |
+ audio_sync_info->current_delay_ms, |
&target_audio_delay_ms, |
&target_video_delay_ms)) { |
return; |
} |
- if (voe_sync_interface_->SetMinimumPlayoutDelay( |
- voe_channel_id_, target_audio_delay_ms) == -1) { |
- LOG(LS_ERROR) << "Error setting voice delay."; |
- } |
+ syncable_->SetMinimumPlayoutDelay(target_audio_delay_ms); |
video_receiver_->SetMinimumPlayoutDelay(target_video_delay_ms); |
} |
@@ -173,15 +161,12 @@ bool RtpStreamsSynchronizer::GetStreamSyncOffsetInMs( |
int64_t* stream_offset_ms, |
double* estimated_freq_khz) const { |
rtc::CritScope lock(&crit_); |
- if (voe_channel_id_ == -1) |
- return false; |
- |
- uint32_t playout_timestamp = 0; |
- if (voe_sync_interface_->GetPlayoutTimestamp(voe_channel_id_, |
- playout_timestamp) != 0) { |
+ if (!syncable_) { |
return false; |
} |
+ uint32_t playout_timestamp = syncable_->GetPlayoutTimestamp(); |
+ |
int64_t latest_audio_ntp; |
if (!audio_measurement_.rtp_to_ntp.Estimate(playout_timestamp, |
&latest_audio_ntp)) { |