| 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 |
| 11 #include "webrtc/video/rtp_streams_synchronizer.h" | 11 #include "webrtc/video/rtp_streams_synchronizer.h" |
| 12 | 12 |
| 13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
| 14 #include "webrtc/base/logging.h" | 14 #include "webrtc/base/logging.h" |
| 15 #include "webrtc/base/timeutils.h" | 15 #include "webrtc/base/timeutils.h" |
| 16 #include "webrtc/base/trace_event.h" | 16 #include "webrtc/base/trace_event.h" |
| 17 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" | 17 #include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h" |
| 18 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 18 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
| 19 #include "webrtc/modules/video_coding/video_coding_impl.h" | 19 #include "webrtc/modules/video_coding/video_coding_impl.h" |
| 20 #include "webrtc/system_wrappers/include/clock.h" | 20 #include "webrtc/system_wrappers/include/clock.h" |
| 21 #include "webrtc/video/stream_synchronization.h" | 21 #include "webrtc/video/stream_synchronization.h" |
| 22 #include "webrtc/video_frame.h" | 22 #include "webrtc/video_frame.h" |
| 23 #include "webrtc/voice_engine/include/voe_video_sync.h" | 23 #include "webrtc/voice_engine/include/voe_video_sync.h" |
| 24 | 24 |
| 25 namespace webrtc { | 25 namespace webrtc { |
| 26 namespace { | 26 namespace { |
| 27 int UpdateMeasurements(StreamSynchronization::Measurements* stream, | 27 bool UpdateMeasurements(StreamSynchronization::Measurements* stream, |
| 28 RtpRtcp* rtp_rtcp, RtpReceiver* receiver) { | 28 RtpRtcp* rtp_rtcp, |
| 29 RtpReceiver* receiver) { |
| 29 if (!receiver->Timestamp(&stream->latest_timestamp)) | 30 if (!receiver->Timestamp(&stream->latest_timestamp)) |
| 30 return -1; | 31 return false; |
| 31 if (!receiver->LastReceivedTimeMs(&stream->latest_receive_time_ms)) | 32 if (!receiver->LastReceivedTimeMs(&stream->latest_receive_time_ms)) |
| 32 return -1; | 33 return false; |
| 33 | 34 |
| 34 uint32_t ntp_secs = 0; | 35 uint32_t ntp_secs = 0; |
| 35 uint32_t ntp_frac = 0; | 36 uint32_t ntp_frac = 0; |
| 36 uint32_t rtp_timestamp = 0; | 37 uint32_t rtp_timestamp = 0; |
| 37 if (rtp_rtcp->RemoteNTP(&ntp_secs, &ntp_frac, nullptr, nullptr, | 38 if (rtp_rtcp->RemoteNTP(&ntp_secs, &ntp_frac, nullptr, nullptr, |
| 38 &rtp_timestamp) != 0) { | 39 &rtp_timestamp) != 0) { |
| 39 return -1; | 40 return false; |
| 40 } | 41 } |
| 41 | 42 |
| 42 bool new_rtcp_sr = false; | 43 bool new_rtcp_sr = false; |
| 43 if (!UpdateRtcpList(ntp_secs, ntp_frac, rtp_timestamp, &stream->rtcp, | 44 if (!UpdateRtcpList(ntp_secs, ntp_frac, rtp_timestamp, &stream->rtcp, |
| 44 &new_rtcp_sr)) { | 45 &new_rtcp_sr)) { |
| 45 return -1; | 46 return false; |
| 46 } | 47 } |
| 47 | 48 |
| 48 return 0; | 49 return true; |
| 49 } | 50 } |
| 50 } // namespace | 51 } // namespace |
| 51 | 52 |
| 52 RtpStreamsSynchronizer::RtpStreamsSynchronizer( | 53 RtpStreamsSynchronizer::RtpStreamsSynchronizer( |
| 53 vcm::VideoReceiver* video_receiver, | 54 vcm::VideoReceiver* video_receiver, |
| 54 RtpStreamReceiver* rtp_stream_receiver) | 55 RtpStreamReceiver* rtp_stream_receiver) |
| 55 : clock_(Clock::GetRealTimeClock()), | 56 : clock_(Clock::GetRealTimeClock()), |
| 56 video_receiver_(video_receiver), | 57 video_receiver_(video_receiver), |
| 57 video_rtp_receiver_(rtp_stream_receiver->GetRtpReceiver()), | 58 video_rtp_receiver_(rtp_stream_receiver->GetRtpReceiver()), |
| 58 video_rtp_rtcp_(rtp_stream_receiver->rtp_rtcp()), | 59 video_rtp_rtcp_(rtp_stream_receiver->rtp_rtcp()), |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 int playout_buffer_delay_ms = 0; | 118 int playout_buffer_delay_ms = 0; |
| 118 if (voe_sync_interface_->GetDelayEstimate(voe_channel_id_, | 119 if (voe_sync_interface_->GetDelayEstimate(voe_channel_id_, |
| 119 &audio_jitter_buffer_delay_ms, | 120 &audio_jitter_buffer_delay_ms, |
| 120 &playout_buffer_delay_ms) != 0) { | 121 &playout_buffer_delay_ms) != 0) { |
| 121 return; | 122 return; |
| 122 } | 123 } |
| 123 const int current_audio_delay_ms = audio_jitter_buffer_delay_ms + | 124 const int current_audio_delay_ms = audio_jitter_buffer_delay_ms + |
| 124 playout_buffer_delay_ms; | 125 playout_buffer_delay_ms; |
| 125 | 126 |
| 126 int64_t last_video_receive_ms = video_measurement_.latest_receive_time_ms; | 127 int64_t last_video_receive_ms = video_measurement_.latest_receive_time_ms; |
| 127 if (UpdateMeasurements(&video_measurement_, video_rtp_rtcp_, | 128 if (!UpdateMeasurements(&video_measurement_, video_rtp_rtcp_, |
| 128 video_rtp_receiver_) != 0) { | 129 video_rtp_receiver_)) { |
| 129 return; | 130 return; |
| 130 } | 131 } |
| 131 | 132 |
| 132 if (UpdateMeasurements(&audio_measurement_, audio_rtp_rtcp_, | 133 if (!UpdateMeasurements(&audio_measurement_, audio_rtp_rtcp_, |
| 133 audio_rtp_receiver_) != 0) { | 134 audio_rtp_receiver_)) { |
| 134 return; | 135 return; |
| 135 } | 136 } |
| 136 | 137 |
| 137 if (last_video_receive_ms == video_measurement_.latest_receive_time_ms) { | 138 if (last_video_receive_ms == video_measurement_.latest_receive_time_ms) { |
| 138 // No new video packet has been received since last update. | 139 // No new video packet has been received since last update. |
| 139 return; | 140 return; |
| 140 } | 141 } |
| 141 | 142 |
| 142 int relative_delay_ms; | 143 int relative_delay_ms; |
| 143 // Calculate how much later or earlier the audio stream is compared to video. | 144 // Calculate how much later or earlier the audio stream is compared to video. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 frame.render_time_ms() - clock_->TimeInMilliseconds(); | 198 frame.render_time_ms() - clock_->TimeInMilliseconds(); |
| 198 if (time_to_render_ms > 0) | 199 if (time_to_render_ms > 0) |
| 199 latest_video_ntp += time_to_render_ms; | 200 latest_video_ntp += time_to_render_ms; |
| 200 | 201 |
| 201 *stream_offset_ms = latest_audio_ntp - latest_video_ntp; | 202 *stream_offset_ms = latest_audio_ntp - latest_video_ntp; |
| 202 *estimated_freq_khz = video_measurement_.rtcp.params.frequency_khz; | 203 *estimated_freq_khz = video_measurement_.rtcp.params.frequency_khz; |
| 203 return true; | 204 return true; |
| 204 } | 205 } |
| 205 | 206 |
| 206 } // namespace webrtc | 207 } // namespace webrtc |
| OLD | NEW |