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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 int audio_jitter_buffer_delay_ms = 0; | 116 int audio_jitter_buffer_delay_ms = 0; |
117 int playout_buffer_delay_ms = 0; | 117 int playout_buffer_delay_ms = 0; |
118 if (voe_sync_interface_->GetDelayEstimate(voe_channel_id_, | 118 if (voe_sync_interface_->GetDelayEstimate(voe_channel_id_, |
119 &audio_jitter_buffer_delay_ms, | 119 &audio_jitter_buffer_delay_ms, |
120 &playout_buffer_delay_ms) != 0) { | 120 &playout_buffer_delay_ms) != 0) { |
121 return; | 121 return; |
122 } | 122 } |
123 const int current_audio_delay_ms = audio_jitter_buffer_delay_ms + | 123 const int current_audio_delay_ms = audio_jitter_buffer_delay_ms + |
124 playout_buffer_delay_ms; | 124 playout_buffer_delay_ms; |
125 | 125 |
126 int64_t last_audio_receive_ms = audio_measurement_.latest_receive_time_ms; | |
127 int64_t last_video_receive_ms = video_measurement_.latest_receive_time_ms; | |
128 | |
126 if (UpdateMeasurements(&video_measurement_, video_rtp_rtcp_, | 129 if (UpdateMeasurements(&video_measurement_, video_rtp_rtcp_, |
127 video_rtp_receiver_) != 0) { | 130 video_rtp_receiver_) != 0) { |
128 return; | 131 return; |
129 } | 132 } |
130 | 133 |
131 if (UpdateMeasurements(&audio_measurement_, audio_rtp_rtcp_, | 134 if (UpdateMeasurements(&audio_measurement_, audio_rtp_rtcp_, |
132 audio_rtp_receiver_) != 0) { | 135 audio_rtp_receiver_) != 0) { |
133 return; | 136 return; |
134 } | 137 } |
135 | 138 |
139 if (last_audio_receive_ms == audio_measurement_.latest_receive_time_ms || | |
140 last_video_receive_ms == video_measurement_.latest_receive_time_ms) { | |
141 // No new audio or video packet has been received since last update. | |
142 return; | |
143 } | |
144 | |
136 int relative_delay_ms; | 145 int relative_delay_ms; |
137 // Calculate how much later or earlier the audio stream is compared to video. | 146 // Calculate how much later or earlier the audio stream is compared to video. |
138 if (!sync_->ComputeRelativeDelay(audio_measurement_, video_measurement_, | 147 if (!sync_->ComputeRelativeDelay(audio_measurement_, video_measurement_, |
139 &relative_delay_ms)) { | 148 &relative_delay_ms)) { |
140 return; | 149 return; |
141 } | 150 } |
142 | 151 |
143 TRACE_COUNTER1("webrtc", "SyncCurrentVideoDelay", current_video_delay_ms); | 152 TRACE_COUNTER1("webrtc", "SyncCurrentVideoDelay", current_video_delay_ms); |
144 TRACE_COUNTER1("webrtc", "SyncCurrentAudioDelay", current_audio_delay_ms); | 153 TRACE_COUNTER1("webrtc", "SyncCurrentAudioDelay", current_audio_delay_ms); |
145 TRACE_COUNTER1("webrtc", "SyncRelativeDelay", relative_delay_ms); | 154 TRACE_COUNTER1("webrtc", "SyncRelativeDelay", relative_delay_ms); |
146 int target_audio_delay_ms = 0; | 155 int target_audio_delay_ms = 0; |
147 int target_video_delay_ms = current_video_delay_ms; | 156 int target_video_delay_ms = current_video_delay_ms; |
148 // Calculate the necessary extra audio delay and desired total video | 157 // Calculate the necessary extra audio delay and desired total video |
149 // delay to get the streams in sync. | 158 // delay to get the streams in sync. |
150 if (!sync_->ComputeDelays(relative_delay_ms, | 159 if (!sync_->ComputeDelays(relative_delay_ms, |
151 current_audio_delay_ms, | 160 current_audio_delay_ms, |
152 &target_audio_delay_ms, | 161 &target_audio_delay_ms, |
153 &target_video_delay_ms)) { | 162 &target_video_delay_ms)) { |
154 return; | 163 return; |
155 } | 164 } |
156 | 165 |
157 if (voe_sync_interface_->SetMinimumPlayoutDelay( | 166 if (voe_sync_interface_->SetMinimumPlayoutDelay( |
158 voe_channel_id_, target_audio_delay_ms) == -1) { | 167 voe_channel_id_, target_audio_delay_ms) == -1) { |
159 LOG(LS_ERROR) << "Error setting voice delay."; | 168 LOG(LS_ERROR) << "Error setting voice delay."; |
160 } | 169 } |
161 video_receiver_->SetMinimumPlayoutDelay(target_video_delay_ms); | 170 video_receiver_->SetMinimumPlayoutDelay(target_video_delay_ms); |
162 } | 171 } |
163 | 172 |
164 bool RtpStreamsSynchronizer::GetStreamSyncOffsetInMs( | 173 bool RtpStreamsSynchronizer::GetStreamSyncOffsetInMs( |
mflodman
2016/09/14 13:19:08
Will this method also cause stats problems if it's
| |
165 const VideoFrame& frame, int64_t* stream_offset_ms) const { | 174 const VideoFrame& frame, int64_t* stream_offset_ms) const { |
166 rtc::CritScope lock(&crit_); | 175 rtc::CritScope lock(&crit_); |
167 if (voe_channel_id_ == -1) | 176 if (voe_channel_id_ == -1) |
168 return false; | 177 return false; |
169 | 178 |
170 uint32_t playout_timestamp = 0; | 179 uint32_t playout_timestamp = 0; |
171 if (voe_sync_interface_->GetPlayoutTimestamp(voe_channel_id_, | 180 if (voe_sync_interface_->GetPlayoutTimestamp(voe_channel_id_, |
172 playout_timestamp) != 0) { | 181 playout_timestamp) != 0) { |
173 return false; | 182 return false; |
174 } | 183 } |
(...skipping 13 matching lines...) Expand all Loading... | |
188 int64_t time_to_render_ms = | 197 int64_t time_to_render_ms = |
189 frame.render_time_ms() - clock_->TimeInMilliseconds(); | 198 frame.render_time_ms() - clock_->TimeInMilliseconds(); |
190 if (time_to_render_ms > 0) | 199 if (time_to_render_ms > 0) |
191 latest_video_ntp += time_to_render_ms; | 200 latest_video_ntp += time_to_render_ms; |
192 | 201 |
193 *stream_offset_ms = latest_audio_ntp - latest_video_ntp; | 202 *stream_offset_ms = latest_audio_ntp - latest_video_ntp; |
194 return true; | 203 return true; |
195 } | 204 } |
196 | 205 |
197 } // namespace webrtc | 206 } // namespace webrtc |
OLD | NEW |