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 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 video_rtp_rtcp_ = video_rtcp_module; | 81 video_rtp_rtcp_ = video_rtcp_module; |
82 sync_.reset( | 82 sync_.reset( |
83 new StreamSynchronization(video_rtp_rtcp_->SSRC(), voe_channel_id)); | 83 new StreamSynchronization(video_rtp_rtcp_->SSRC(), voe_channel_id)); |
84 } | 84 } |
85 | 85 |
86 int64_t ViESyncModule::TimeUntilNextProcess() { | 86 int64_t ViESyncModule::TimeUntilNextProcess() { |
87 const int64_t kSyncIntervalMs = 1000; | 87 const int64_t kSyncIntervalMs = 1000; |
88 return kSyncIntervalMs - (TickTime::Now() - last_sync_time_).Milliseconds(); | 88 return kSyncIntervalMs - (TickTime::Now() - last_sync_time_).Milliseconds(); |
89 } | 89 } |
90 | 90 |
91 int32_t ViESyncModule::Process() { | 91 void ViESyncModule::Process() { |
92 rtc::CritScope lock(&data_cs_); | 92 rtc::CritScope lock(&data_cs_); |
93 last_sync_time_ = TickTime::Now(); | 93 last_sync_time_ = TickTime::Now(); |
94 | 94 |
95 const int current_video_delay_ms = vcm_->Delay(); | 95 const int current_video_delay_ms = vcm_->Delay(); |
96 | 96 |
97 if (voe_channel_id_ == -1) { | 97 if (voe_channel_id_ == -1) { |
98 return 0; | 98 return; |
99 } | 99 } |
100 assert(video_rtp_rtcp_ && voe_sync_interface_); | 100 assert(video_rtp_rtcp_ && voe_sync_interface_); |
101 assert(sync_.get()); | 101 assert(sync_.get()); |
102 | 102 |
103 int audio_jitter_buffer_delay_ms = 0; | 103 int audio_jitter_buffer_delay_ms = 0; |
104 int playout_buffer_delay_ms = 0; | 104 int playout_buffer_delay_ms = 0; |
105 if (voe_sync_interface_->GetDelayEstimate(voe_channel_id_, | 105 if (voe_sync_interface_->GetDelayEstimate(voe_channel_id_, |
106 &audio_jitter_buffer_delay_ms, | 106 &audio_jitter_buffer_delay_ms, |
107 &playout_buffer_delay_ms) != 0) { | 107 &playout_buffer_delay_ms) != 0) { |
108 return 0; | 108 return; |
109 } | 109 } |
110 const int current_audio_delay_ms = audio_jitter_buffer_delay_ms + | 110 const int current_audio_delay_ms = audio_jitter_buffer_delay_ms + |
111 playout_buffer_delay_ms; | 111 playout_buffer_delay_ms; |
112 | 112 |
113 RtpRtcp* voice_rtp_rtcp = NULL; | 113 RtpRtcp* voice_rtp_rtcp = NULL; |
114 RtpReceiver* voice_receiver = NULL; | 114 RtpReceiver* voice_receiver = NULL; |
115 if (0 != voe_sync_interface_->GetRtpRtcp(voe_channel_id_, &voice_rtp_rtcp, | 115 if (0 != voe_sync_interface_->GetRtpRtcp(voe_channel_id_, &voice_rtp_rtcp, |
116 &voice_receiver)) { | 116 &voice_receiver)) { |
117 return 0; | 117 return; |
118 } | 118 } |
119 assert(voice_rtp_rtcp); | 119 assert(voice_rtp_rtcp); |
120 assert(voice_receiver); | 120 assert(voice_receiver); |
121 | 121 |
122 if (UpdateMeasurements(&video_measurement_, *video_rtp_rtcp_, | 122 if (UpdateMeasurements(&video_measurement_, *video_rtp_rtcp_, |
123 *video_receiver_) != 0) { | 123 *video_receiver_) != 0) { |
124 return 0; | 124 return; |
125 } | 125 } |
126 | 126 |
127 if (UpdateMeasurements(&audio_measurement_, *voice_rtp_rtcp, | 127 if (UpdateMeasurements(&audio_measurement_, *voice_rtp_rtcp, |
128 *voice_receiver) != 0) { | 128 *voice_receiver) != 0) { |
129 return 0; | 129 return; |
130 } | 130 } |
131 | 131 |
132 int relative_delay_ms; | 132 int relative_delay_ms; |
133 // Calculate how much later or earlier the audio stream is compared to video. | 133 // Calculate how much later or earlier the audio stream is compared to video. |
134 if (!sync_->ComputeRelativeDelay(audio_measurement_, video_measurement_, | 134 if (!sync_->ComputeRelativeDelay(audio_measurement_, video_measurement_, |
135 &relative_delay_ms)) { | 135 &relative_delay_ms)) { |
136 return 0; | 136 return; |
137 } | 137 } |
138 | 138 |
139 TRACE_COUNTER1("webrtc", "SyncCurrentVideoDelay", current_video_delay_ms); | 139 TRACE_COUNTER1("webrtc", "SyncCurrentVideoDelay", current_video_delay_ms); |
140 TRACE_COUNTER1("webrtc", "SyncCurrentAudioDelay", current_audio_delay_ms); | 140 TRACE_COUNTER1("webrtc", "SyncCurrentAudioDelay", current_audio_delay_ms); |
141 TRACE_COUNTER1("webrtc", "SyncRelativeDelay", relative_delay_ms); | 141 TRACE_COUNTER1("webrtc", "SyncRelativeDelay", relative_delay_ms); |
142 int target_audio_delay_ms = 0; | 142 int target_audio_delay_ms = 0; |
143 int target_video_delay_ms = current_video_delay_ms; | 143 int target_video_delay_ms = current_video_delay_ms; |
144 // Calculate the necessary extra audio delay and desired total video | 144 // Calculate the necessary extra audio delay and desired total video |
145 // delay to get the streams in sync. | 145 // delay to get the streams in sync. |
146 if (!sync_->ComputeDelays(relative_delay_ms, | 146 if (!sync_->ComputeDelays(relative_delay_ms, |
147 current_audio_delay_ms, | 147 current_audio_delay_ms, |
148 &target_audio_delay_ms, | 148 &target_audio_delay_ms, |
149 &target_video_delay_ms)) { | 149 &target_video_delay_ms)) { |
150 return 0; | 150 return; |
151 } | 151 } |
152 | 152 |
153 if (voe_sync_interface_->SetMinimumPlayoutDelay( | 153 if (voe_sync_interface_->SetMinimumPlayoutDelay( |
154 voe_channel_id_, target_audio_delay_ms) == -1) { | 154 voe_channel_id_, target_audio_delay_ms) == -1) { |
155 LOG(LS_ERROR) << "Error setting voice delay."; | 155 LOG(LS_ERROR) << "Error setting voice delay."; |
156 } | 156 } |
157 vcm_->SetMinimumPlayoutDelay(target_video_delay_ms); | 157 vcm_->SetMinimumPlayoutDelay(target_video_delay_ms); |
158 return 0; | |
159 } | 158 } |
160 | 159 |
161 } // namespace webrtc | 160 } // namespace webrtc |
OLD | NEW |