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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 return true; | 89 return true; |
90 } | 90 } |
91 | 91 |
92 // Converts |rtp_timestamp| to the NTP time base using the NTP and RTP timestamp | 92 // Converts |rtp_timestamp| to the NTP time base using the NTP and RTP timestamp |
93 // pairs in |rtcp|. The converted timestamp is returned in | 93 // pairs in |rtcp|. The converted timestamp is returned in |
94 // |rtp_timestamp_in_ms|. This function compensates for wrap arounds in RTP | 94 // |rtp_timestamp_in_ms|. This function compensates for wrap arounds in RTP |
95 // timestamps and returns false if it can't do the conversion due to reordering. | 95 // timestamps and returns false if it can't do the conversion due to reordering. |
96 bool RtpToNtpMs(int64_t rtp_timestamp, | 96 bool RtpToNtpMs(int64_t rtp_timestamp, |
97 const RtcpList& rtcp, | 97 const RtcpList& rtcp, |
98 int64_t* rtp_timestamp_in_ms) { | 98 int64_t* rtp_timestamp_in_ms) { |
99 double frequency_khz; | |
100 return RtpToNtpMsAndReturnFreq(rtp_timestamp, rtcp, rtp_timestamp_in_ms, | |
101 &frequency_khz); | |
102 } | |
103 | |
104 bool RtpToNtpMsAndReturnFreq(int64_t rtp_timestamp, | |
stefan-webrtc
2016/10/05 14:35:46
Instead of introducing this slightly odd function,
åsapersson
2016/10/09 14:22:15
The old timestamp in the RctpList is used in RtpTo
| |
105 const RtcpList& rtcp, | |
106 int64_t* rtp_timestamp_in_ms, | |
107 double* estimated_frequency_khz) { | |
99 if (rtcp.size() != 2) | 108 if (rtcp.size() != 2) |
100 return false; | 109 return false; |
101 | 110 |
102 int64_t rtcp_ntp_ms_new = Clock::NtpToMs(rtcp.front().ntp_secs, | 111 int64_t rtcp_ntp_ms_new = Clock::NtpToMs(rtcp.front().ntp_secs, |
103 rtcp.front().ntp_frac); | 112 rtcp.front().ntp_frac); |
104 int64_t rtcp_ntp_ms_old = Clock::NtpToMs(rtcp.back().ntp_secs, | 113 int64_t rtcp_ntp_ms_old = Clock::NtpToMs(rtcp.back().ntp_secs, |
105 rtcp.back().ntp_frac); | 114 rtcp.back().ntp_frac); |
106 int64_t rtcp_timestamp_new = rtcp.front().rtp_timestamp; | 115 int64_t rtcp_timestamp_new = rtcp.front().rtp_timestamp; |
107 int64_t rtcp_timestamp_old = rtcp.back().rtp_timestamp; | 116 int64_t rtcp_timestamp_old = rtcp.back().rtp_timestamp; |
108 if (!CompensateForWrapAround(rtcp_timestamp_new, | 117 if (!CompensateForWrapAround(rtcp_timestamp_new, |
(...skipping 17 matching lines...) Expand all Loading... | |
126 if (!CompensateForWrapAround(rtp_timestamp, rtcp_timestamp_old, | 135 if (!CompensateForWrapAround(rtp_timestamp, rtcp_timestamp_old, |
127 &rtp_timestamp_unwrapped)) { | 136 &rtp_timestamp_unwrapped)) { |
128 return false; | 137 return false; |
129 } | 138 } |
130 double rtp_timestamp_ntp_ms = (static_cast<double>(rtp_timestamp_unwrapped) - | 139 double rtp_timestamp_ntp_ms = (static_cast<double>(rtp_timestamp_unwrapped) - |
131 offset) / freq_khz + 0.5f; | 140 offset) / freq_khz + 0.5f; |
132 if (rtp_timestamp_ntp_ms < 0) { | 141 if (rtp_timestamp_ntp_ms < 0) { |
133 return false; | 142 return false; |
134 } | 143 } |
135 *rtp_timestamp_in_ms = rtp_timestamp_ntp_ms; | 144 *rtp_timestamp_in_ms = rtp_timestamp_ntp_ms; |
145 *estimated_frequency_khz = freq_khz; | |
136 return true; | 146 return true; |
137 } | 147 } |
138 | 148 |
139 int CheckForWrapArounds(uint32_t new_timestamp, uint32_t old_timestamp) { | 149 int CheckForWrapArounds(uint32_t new_timestamp, uint32_t old_timestamp) { |
140 if (new_timestamp < old_timestamp) { | 150 if (new_timestamp < old_timestamp) { |
141 // This difference should be less than -2^31 if we have had a wrap around | 151 // This difference should be less than -2^31 if we have had a wrap around |
142 // (e.g. |new_timestamp| = 1, |rtcp_rtp_timestamp| = 2^32 - 1). Since it is | 152 // (e.g. |new_timestamp| = 1, |rtcp_rtp_timestamp| = 2^32 - 1). Since it is |
143 // cast to a int32_t, it should be positive. | 153 // cast to a int32_t, it should be positive. |
144 if (static_cast<int32_t>(new_timestamp - old_timestamp) > 0) { | 154 if (static_cast<int32_t>(new_timestamp - old_timestamp) > 0) { |
145 // Forward wrap around. | 155 // Forward wrap around. |
146 return 1; | 156 return 1; |
147 } | 157 } |
148 } else if (static_cast<int32_t>(old_timestamp - new_timestamp) > 0) { | 158 } else if (static_cast<int32_t>(old_timestamp - new_timestamp) > 0) { |
149 // This difference should be less than -2^31 if we have had a backward wrap | 159 // This difference should be less than -2^31 if we have had a backward wrap |
150 // around. Since it is cast to a int32_t, it should be positive. | 160 // around. Since it is cast to a int32_t, it should be positive. |
151 return -1; | 161 return -1; |
152 } | 162 } |
153 return 0; | 163 return 0; |
154 } | 164 } |
155 | 165 |
156 } // namespace webrtc | 166 } // namespace webrtc |
OLD | NEW |