OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This class maintains a bi-directional RTCP connection with a remote | 5 // This class maintains a bi-directional RTCP connection with a remote |
6 // peer. | 6 // peer. |
7 | 7 |
8 #ifndef MEDIA_CAST_RTCP_RTCP_H_ | 8 #ifndef MEDIA_CAST_RTCP_RTCP_H_ |
9 #define MEDIA_CAST_RTCP_RTCP_H_ | 9 #define MEDIA_CAST_RTCP_RTCP_H_ |
10 | 10 |
| 11 #include <stdint.h> |
| 12 |
11 #include <map> | 13 #include <map> |
12 #include <queue> | 14 #include <queue> |
13 #include <string> | 15 #include <string> |
14 | 16 |
15 #include "base/basictypes.h" | 17 #include "base/macros.h" |
16 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
17 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
18 #include "base/time/tick_clock.h" | 20 #include "base/time/tick_clock.h" |
19 #include "base/time/time.h" | 21 #include "base/time/time.h" |
20 #include "media/cast/common/clock_drift_smoother.h" | 22 #include "media/cast/common/clock_drift_smoother.h" |
21 #include "media/cast/net/cast_transport_defines.h" | 23 #include "media/cast/net/cast_transport_defines.h" |
22 #include "media/cast/net/cast_transport_sender.h" | 24 #include "media/cast/net/cast_transport_sender.h" |
23 #include "media/cast/net/rtcp/receiver_rtcp_event_subscriber.h" | 25 #include "media/cast/net/rtcp/receiver_rtcp_event_subscriber.h" |
24 #include "media/cast/net/rtcp/rtcp_builder.h" | 26 #include "media/cast/net/rtcp/rtcp_builder.h" |
25 #include "media/cast/net/rtcp/rtcp_defines.h" | 27 #include "media/cast/net/rtcp/rtcp_defines.h" |
26 | 28 |
27 namespace media { | 29 namespace media { |
28 namespace cast { | 30 namespace cast { |
29 | 31 |
30 class LocalRtcpReceiverFeedback; | 32 class LocalRtcpReceiverFeedback; |
31 class PacedPacketSender; | 33 class PacedPacketSender; |
32 class RtcpReceiver; | 34 class RtcpReceiver; |
33 class RtcpBuilder; | 35 class RtcpBuilder; |
34 | 36 |
35 typedef std::pair<uint32, base::TimeTicks> RtcpSendTimePair; | 37 typedef std::pair<uint32_t, base::TimeTicks> RtcpSendTimePair; |
36 typedef std::map<uint32, base::TimeTicks> RtcpSendTimeMap; | 38 typedef std::map<uint32_t, base::TimeTicks> RtcpSendTimeMap; |
37 typedef std::queue<RtcpSendTimePair> RtcpSendTimeQueue; | 39 typedef std::queue<RtcpSendTimePair> RtcpSendTimeQueue; |
38 | 40 |
39 // TODO(hclam): This should be renamed to RtcpSession. | 41 // TODO(hclam): This should be renamed to RtcpSession. |
40 class Rtcp { | 42 class Rtcp { |
41 public: | 43 public: |
42 Rtcp(const RtcpCastMessageCallback& cast_callback, | 44 Rtcp(const RtcpCastMessageCallback& cast_callback, |
43 const RtcpRttCallback& rtt_callback, | 45 const RtcpRttCallback& rtt_callback, |
44 const RtcpLogMessageCallback& log_callback, | 46 const RtcpLogMessageCallback& log_callback, |
45 base::TickClock* clock, // Not owned. | 47 base::TickClock* clock, // Not owned. |
46 PacedPacketSender* packet_sender, // Not owned. | 48 PacedPacketSender* packet_sender, // Not owned. |
47 uint32 local_ssrc, | 49 uint32_t local_ssrc, |
48 uint32 remote_ssrc); | 50 uint32_t remote_ssrc); |
49 | 51 |
50 virtual ~Rtcp(); | 52 virtual ~Rtcp(); |
51 | 53 |
52 // Send a RTCP sender report. | 54 // Send a RTCP sender report. |
53 // |current_time| is the current time reported by a tick clock. | 55 // |current_time| is the current time reported by a tick clock. |
54 // |current_time_as_rtp_timestamp| is the corresponding RTP timestamp. | 56 // |current_time_as_rtp_timestamp| is the corresponding RTP timestamp. |
55 // |send_packet_count| is the number of packets sent. | 57 // |send_packet_count| is the number of packets sent. |
56 // |send_octet_count| is the number of octets sent. | 58 // |send_octet_count| is the number of octets sent. |
57 void SendRtcpFromRtpSender( | 59 void SendRtcpFromRtpSender(base::TimeTicks current_time, |
58 base::TimeTicks current_time, | 60 uint32_t current_time_as_rtp_timestamp, |
59 uint32 current_time_as_rtp_timestamp, | 61 uint32_t send_packet_count, |
60 uint32 send_packet_count, | 62 size_t send_octet_count); |
61 size_t send_octet_count); | |
62 | 63 |
63 // This function is meant to be used in conjunction with | 64 // This function is meant to be used in conjunction with |
64 // SendRtcpFromRtpReceiver. | 65 // SendRtcpFromRtpReceiver. |
65 // |now| is converted to NTP and saved internally for | 66 // |now| is converted to NTP and saved internally for |
66 // future round-trip/lip-sync calculations. | 67 // future round-trip/lip-sync calculations. |
67 // This is done in a separate method so that SendRtcpFromRtpReceiver can | 68 // This is done in a separate method so that SendRtcpFromRtpReceiver can |
68 // be done on a separate (temporary) RTCP object. | 69 // be done on a separate (temporary) RTCP object. |
69 RtcpTimeData ConvertToNTPAndSave(base::TimeTicks now); | 70 RtcpTimeData ConvertToNTPAndSave(base::TimeTicks now); |
70 | 71 |
71 // |cast_message|, |rtcp_events| and |rtp_receiver_statistics| are optional; | 72 // |cast_message|, |rtcp_events| and |rtp_receiver_statistics| are optional; |
(...skipping 12 matching lines...) Expand all Loading... |
84 // and used to maintain a RTCP session. | 85 // and used to maintain a RTCP session. |
85 // Returns false if this is not a RTCP packet or it is not directed to | 86 // Returns false if this is not a RTCP packet or it is not directed to |
86 // this session, e.g. SSRC doesn't match. | 87 // this session, e.g. SSRC doesn't match. |
87 bool IncomingRtcpPacket(const uint8* data, size_t length); | 88 bool IncomingRtcpPacket(const uint8* data, size_t length); |
88 | 89 |
89 // If available, returns true and sets the output arguments to the latest | 90 // If available, returns true and sets the output arguments to the latest |
90 // lip-sync timestamps gleaned from the sender reports. While the sender | 91 // lip-sync timestamps gleaned from the sender reports. While the sender |
91 // provides reference NTP times relative to its own wall clock, the | 92 // provides reference NTP times relative to its own wall clock, the |
92 // |reference_time| returned here has been translated to the local | 93 // |reference_time| returned here has been translated to the local |
93 // CastEnvironment clock. | 94 // CastEnvironment clock. |
94 bool GetLatestLipSyncTimes(uint32* rtp_timestamp, | 95 bool GetLatestLipSyncTimes(uint32_t* rtp_timestamp, |
95 base::TimeTicks* reference_time) const; | 96 base::TimeTicks* reference_time) const; |
96 | 97 |
97 void OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log); | 98 void OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log); |
98 | 99 |
99 // If greater than zero, this is the last measured network round trip time. | 100 // If greater than zero, this is the last measured network round trip time. |
100 base::TimeDelta current_round_trip_time() const { | 101 base::TimeDelta current_round_trip_time() const { |
101 return current_round_trip_time_; | 102 return current_round_trip_time_; |
102 } | 103 } |
103 | 104 |
104 static bool IsRtcpPacket(const uint8* packet, size_t length); | 105 static bool IsRtcpPacket(const uint8* packet, size_t length); |
105 static uint32 GetSsrcOfSender(const uint8* rtcp_buffer, size_t length); | 106 static uint32_t GetSsrcOfSender(const uint8* rtcp_buffer, size_t length); |
106 | 107 |
107 uint32 GetLocalSsrc() const { return local_ssrc_; } | 108 uint32_t GetLocalSsrc() const { return local_ssrc_; } |
108 uint32 GetRemoteSsrc() const { return remote_ssrc_; } | 109 uint32_t GetRemoteSsrc() const { return remote_ssrc_; } |
109 | 110 |
110 protected: | 111 protected: |
111 void OnReceivedNtp(uint32 ntp_seconds, uint32 ntp_fraction); | 112 void OnReceivedNtp(uint32_t ntp_seconds, uint32_t ntp_fraction); |
112 void OnReceivedLipSyncInfo(uint32 rtp_timestamp, | 113 void OnReceivedLipSyncInfo(uint32_t rtp_timestamp, |
113 uint32 ntp_seconds, | 114 uint32_t ntp_seconds, |
114 uint32 ntp_fraction); | 115 uint32_t ntp_fraction); |
115 | 116 |
116 private: | 117 private: |
117 void OnReceivedDelaySinceLastReport(uint32 last_report, | 118 void OnReceivedDelaySinceLastReport(uint32_t last_report, |
118 uint32 delay_since_last_report); | 119 uint32_t delay_since_last_report); |
119 | 120 |
120 void OnReceivedCastFeedback(const RtcpCastMessage& cast_message); | 121 void OnReceivedCastFeedback(const RtcpCastMessage& cast_message); |
121 | 122 |
122 void SaveLastSentNtpTime(const base::TimeTicks& now, | 123 void SaveLastSentNtpTime(const base::TimeTicks& now, |
123 uint32 last_ntp_seconds, | 124 uint32_t last_ntp_seconds, |
124 uint32 last_ntp_fraction); | 125 uint32_t last_ntp_fraction); |
125 | 126 |
126 // Remove duplicate events in |receiver_log|. | 127 // Remove duplicate events in |receiver_log|. |
127 // Returns true if any events remain. | 128 // Returns true if any events remain. |
128 bool DedupeReceiverLog(RtcpReceiverLogMessage* receiver_log); | 129 bool DedupeReceiverLog(RtcpReceiverLogMessage* receiver_log); |
129 | 130 |
130 const RtcpCastMessageCallback cast_callback_; | 131 const RtcpCastMessageCallback cast_callback_; |
131 const RtcpRttCallback rtt_callback_; | 132 const RtcpRttCallback rtt_callback_; |
132 const RtcpLogMessageCallback log_callback_; | 133 const RtcpLogMessageCallback log_callback_; |
133 base::TickClock* const clock_; // Not owned by this class. | 134 base::TickClock* const clock_; // Not owned by this class. |
134 RtcpBuilder rtcp_builder_; | 135 RtcpBuilder rtcp_builder_; |
135 PacedPacketSender* packet_sender_; // Not owned. | 136 PacedPacketSender* packet_sender_; // Not owned. |
136 const uint32 local_ssrc_; | 137 const uint32_t local_ssrc_; |
137 const uint32 remote_ssrc_; | 138 const uint32_t remote_ssrc_; |
138 | 139 |
139 RtcpSendTimeMap last_reports_sent_map_; | 140 RtcpSendTimeMap last_reports_sent_map_; |
140 RtcpSendTimeQueue last_reports_sent_queue_; | 141 RtcpSendTimeQueue last_reports_sent_queue_; |
141 | 142 |
142 // The truncated (i.e., 64-->32-bit) NTP timestamp provided in the last report | 143 // The truncated (i.e., 64-->32-bit) NTP timestamp provided in the last report |
143 // from the remote peer, along with the local time at which the report was | 144 // from the remote peer, along with the local time at which the report was |
144 // received. These values are used for ping-pong'ing NTP timestamps between | 145 // received. These values are used for ping-pong'ing NTP timestamps between |
145 // the peers so that they can estimate the network's round-trip time. | 146 // the peers so that they can estimate the network's round-trip time. |
146 uint32 last_report_truncated_ntp_; | 147 uint32_t last_report_truncated_ntp_; |
147 base::TimeTicks time_last_report_received_; | 148 base::TimeTicks time_last_report_received_; |
148 | 149 |
149 // Maintains a smoothed offset between the local clock and the remote clock. | 150 // Maintains a smoothed offset between the local clock and the remote clock. |
150 // Calling this member's Current() method is only valid if | 151 // Calling this member's Current() method is only valid if |
151 // |time_last_report_received_| is not "null." | 152 // |time_last_report_received_| is not "null." |
152 ClockDriftSmoother local_clock_ahead_by_; | 153 ClockDriftSmoother local_clock_ahead_by_; |
153 | 154 |
154 // Latest "lip sync" info from the sender. The sender provides the RTP | 155 // Latest "lip sync" info from the sender. The sender provides the RTP |
155 // timestamp of some frame of its choosing and also a corresponding reference | 156 // timestamp of some frame of its choosing and also a corresponding reference |
156 // NTP timestamp sampled from a clock common to all media streams. It is | 157 // NTP timestamp sampled from a clock common to all media streams. It is |
157 // expected that the sender will update this data regularly and in a timely | 158 // expected that the sender will update this data regularly and in a timely |
158 // manner (e.g., about once per second). | 159 // manner (e.g., about once per second). |
159 uint32 lip_sync_rtp_timestamp_; | 160 uint32_t lip_sync_rtp_timestamp_; |
160 uint64 lip_sync_ntp_timestamp_; | 161 uint64_t lip_sync_ntp_timestamp_; |
161 | 162 |
162 // The last measured network round trip time. This is updated with each | 163 // The last measured network round trip time. This is updated with each |
163 // sender report --> receiver report round trip. If this is zero, then the | 164 // sender report --> receiver report round trip. If this is zero, then the |
164 // round trip time has not been measured yet. | 165 // round trip time has not been measured yet. |
165 base::TimeDelta current_round_trip_time_; | 166 base::TimeDelta current_round_trip_time_; |
166 | 167 |
167 base::TimeTicks largest_seen_timestamp_; | 168 base::TimeTicks largest_seen_timestamp_; |
168 | 169 |
169 // For extending received ACK frame IDs from 8-bit to 32-bit. | 170 // For extending received ACK frame IDs from 8-bit to 32-bit. |
170 FrameIdWrapHelper ack_frame_id_wrap_helper_; | 171 FrameIdWrapHelper ack_frame_id_wrap_helper_; |
171 | 172 |
172 // Maintains a history of receiver events. | 173 // Maintains a history of receiver events. |
173 typedef std::pair<uint64, uint64> ReceiverEventKey; | 174 typedef std::pair<uint64_t, uint64_t> ReceiverEventKey; |
174 base::hash_set<ReceiverEventKey> receiver_event_key_set_; | 175 base::hash_set<ReceiverEventKey> receiver_event_key_set_; |
175 std::queue<ReceiverEventKey> receiver_event_key_queue_; | 176 std::queue<ReceiverEventKey> receiver_event_key_queue_; |
176 | 177 |
177 DISALLOW_COPY_AND_ASSIGN(Rtcp); | 178 DISALLOW_COPY_AND_ASSIGN(Rtcp); |
178 }; | 179 }; |
179 | 180 |
180 } // namespace cast | 181 } // namespace cast |
181 } // namespace media | 182 } // namespace media |
182 | 183 |
183 #endif // MEDIA_CAST_RTCP_RTCP_H_ | 184 #endif // MEDIA_CAST_RTCP_RTCP_H_ |
OLD | NEW |