stefan@webrtc.org | 64d9dec | 2012-09-26 16:47:40 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
kjellander | d56d68c | 2015-11-02 02:12:41 -0800 | [diff] [blame] | 11 | #ifndef SYSTEM_WRAPPERS_INCLUDE_RTP_TO_NTP_H_ |
| 12 | #define SYSTEM_WRAPPERS_INCLUDE_RTP_TO_NTP_H_ |
stefan@webrtc.org | 64d9dec | 2012-09-26 16:47:40 +0000 | [diff] [blame] | 13 | |
| 14 | #include <list> |
| 15 | |
pbos@webrtc.org | 47ce120 | 2013-05-27 12:41:33 +0000 | [diff] [blame] | 16 | #include "webrtc/typedefs.h" |
stefan@webrtc.org | 64d9dec | 2012-09-26 16:47:40 +0000 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | |
stefan@webrtc.org | 64d9dec | 2012-09-26 16:47:40 +0000 | [diff] [blame] | 20 | struct RtcpMeasurement { |
| 21 | RtcpMeasurement(); |
| 22 | RtcpMeasurement(uint32_t ntp_secs, uint32_t ntp_frac, uint32_t timestamp); |
asapersson | de9e5ff | 2016-11-02 07:14:03 -0700 | [diff] [blame] | 23 | bool IsEqual(const RtcpMeasurement& other) const; |
| 24 | |
stefan@webrtc.org | 64d9dec | 2012-09-26 16:47:40 +0000 | [diff] [blame] | 25 | uint32_t ntp_secs; |
| 26 | uint32_t ntp_frac; |
| 27 | uint32_t rtp_timestamp; |
| 28 | }; |
| 29 | |
asapersson | de9e5ff | 2016-11-02 07:14:03 -0700 | [diff] [blame] | 30 | struct RtcpMeasurements { |
| 31 | RtcpMeasurements(); |
| 32 | ~RtcpMeasurements(); |
| 33 | bool Contains(const RtcpMeasurement& other) const; |
| 34 | bool IsValid(const RtcpMeasurement& other) const; |
| 35 | void UpdateParameters(); |
stefan@webrtc.org | 64d9dec | 2012-09-26 16:47:40 +0000 | [diff] [blame] | 36 | |
asapersson | de9e5ff | 2016-11-02 07:14:03 -0700 | [diff] [blame] | 37 | // Estimated parameters from RTP and NTP timestamp pairs in |list|. |
| 38 | struct RtpToNtpParameters { |
| 39 | double frequency_khz = 0.0; |
| 40 | double offset_ms = 0.0; |
| 41 | bool calculated = false; |
| 42 | }; |
| 43 | |
| 44 | std::list<RtcpMeasurement> list; |
| 45 | RtpToNtpParameters params; |
| 46 | }; |
| 47 | |
| 48 | // Updates |list| in |rtcp_measurements| with timestamps from the RTCP SR. |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 49 | // |new_rtcp_sr| will be set to true if these are the timestamps which have |
asapersson | de9e5ff | 2016-11-02 07:14:03 -0700 | [diff] [blame] | 50 | // never be added to |list|. |
| 51 | // |rtcp_measurements.params| are estimated from the RTP and NTP timestamp pairs |
| 52 | // in the |list| when a new RTCP SR is inserted. |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 53 | bool UpdateRtcpList(uint32_t ntp_secs, |
| 54 | uint32_t ntp_frac, |
| 55 | uint32_t rtp_timestamp, |
asapersson | de9e5ff | 2016-11-02 07:14:03 -0700 | [diff] [blame] | 56 | RtcpMeasurements* rtcp_measurements, |
wu@webrtc.org | cd70119 | 2014-04-24 22:10:24 +0000 | [diff] [blame] | 57 | bool* new_rtcp_sr); |
| 58 | |
asapersson | de9e5ff | 2016-11-02 07:14:03 -0700 | [diff] [blame] | 59 | // Converts an RTP timestamp to the NTP domain in milliseconds using the |
| 60 | // estimated |rtcp_measurements.params|. |
| 61 | bool RtpToNtpMs(int64_t rtp_timestamp, |
| 62 | const RtcpMeasurements& rtcp_measurements, |
| 63 | int64_t* rtp_timestamp_in_ms); |
stefan@webrtc.org | 64d9dec | 2012-09-26 16:47:40 +0000 | [diff] [blame] | 64 | |
| 65 | // Returns 1 there has been a forward wrap around, 0 if there has been no wrap |
| 66 | // around and -1 if there has been a backwards wrap around (i.e. reordering). |
| 67 | int CheckForWrapArounds(uint32_t rtp_timestamp, uint32_t rtcp_rtp_timestamp); |
wu@webrtc.org | 66773a0 | 2014-05-07 17:09:44 +0000 | [diff] [blame] | 68 | |
stefan@webrtc.org | 64d9dec | 2012-09-26 16:47:40 +0000 | [diff] [blame] | 69 | } // namespace webrtc |
| 70 | |
kjellander | d56d68c | 2015-11-02 02:12:41 -0800 | [diff] [blame] | 71 | #endif // SYSTEM_WRAPPERS_INCLUDE_RTP_TO_NTP_H_ |