Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: media/cast/net/rtcp/rtcp.h

Issue 1515433002: Replace uses of raw uint32's with a type-checked RtpTimeTicks data type. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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> 11 #include <stdint.h>
12 12
13 #include <map> 13 #include <map>
14 #include <queue> 14 #include <queue>
15 #include <string> 15 #include <string>
16 16
17 #include "base/macros.h" 17 #include "base/macros.h"
18 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
19 #include "base/memory/weak_ptr.h" 19 #include "base/memory/weak_ptr.h"
20 #include "base/time/tick_clock.h" 20 #include "base/time/tick_clock.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "media/cast/common/clock_drift_smoother.h" 22 #include "media/cast/common/clock_drift_smoother.h"
23 #include "media/cast/net/cast_transport_defines.h" 23 #include "media/cast/net/cast_transport_defines.h"
24 #include "media/cast/net/cast_transport_sender.h" 24 #include "media/cast/net/cast_transport_sender.h"
25 #include "media/cast/net/rtcp/receiver_rtcp_event_subscriber.h" 25 #include "media/cast/net/rtcp/receiver_rtcp_event_subscriber.h"
26 #include "media/cast/net/rtcp/rtcp_builder.h" 26 #include "media/cast/net/rtcp/rtcp_builder.h"
27 #include "media/cast/net/rtcp/rtcp_defines.h" 27 #include "media/cast/net/rtcp/rtcp_defines.h"
28 #include "media/cast/net/rtcp/rtcp_utility.h"
28 29
29 namespace media { 30 namespace media {
30 namespace cast { 31 namespace cast {
31 32
32 class LocalRtcpReceiverFeedback; 33 class LocalRtcpReceiverFeedback;
33 class PacedPacketSender; 34 class PacedPacketSender;
34 class RtcpReceiver; 35 class RtcpReceiver;
35 class RtcpBuilder; 36 class RtcpBuilder;
36 37
37 typedef std::pair<uint32_t, base::TimeTicks> RtcpSendTimePair; 38 typedef std::pair<uint32_t, base::TimeTicks> RtcpSendTimePair;
(...skipping 12 matching lines...) Expand all
50 uint32_t remote_ssrc); 51 uint32_t remote_ssrc);
51 52
52 virtual ~Rtcp(); 53 virtual ~Rtcp();
53 54
54 // Send a RTCP sender report. 55 // Send a RTCP sender report.
55 // |current_time| is the current time reported by a tick clock. 56 // |current_time| is the current time reported by a tick clock.
56 // |current_time_as_rtp_timestamp| is the corresponding RTP timestamp. 57 // |current_time_as_rtp_timestamp| is the corresponding RTP timestamp.
57 // |send_packet_count| is the number of packets sent. 58 // |send_packet_count| is the number of packets sent.
58 // |send_octet_count| is the number of octets sent. 59 // |send_octet_count| is the number of octets sent.
59 void SendRtcpFromRtpSender(base::TimeTicks current_time, 60 void SendRtcpFromRtpSender(base::TimeTicks current_time,
60 uint32_t current_time_as_rtp_timestamp, 61 RtpTimeTicks current_time_as_rtp_timestamp,
61 uint32_t send_packet_count, 62 uint32_t send_packet_count,
62 size_t send_octet_count); 63 size_t send_octet_count);
63 64
64 // This function is meant to be used in conjunction with 65 // This function is meant to be used in conjunction with
65 // SendRtcpFromRtpReceiver. 66 // SendRtcpFromRtpReceiver.
66 // |now| is converted to NTP and saved internally for 67 // |now| is converted to NTP and saved internally for
67 // future round-trip/lip-sync calculations. 68 // future round-trip/lip-sync calculations.
68 // This is done in a separate method so that SendRtcpFromRtpReceiver can 69 // This is done in a separate method so that SendRtcpFromRtpReceiver can
69 // be done on a separate (temporary) RTCP object. 70 // be done on a separate (temporary) RTCP object.
70 RtcpTimeData ConvertToNTPAndSave(base::TimeTicks now); 71 RtcpTimeData ConvertToNTPAndSave(base::TimeTicks now);
(...skipping 14 matching lines...) Expand all
85 // and used to maintain a RTCP session. 86 // and used to maintain a RTCP session.
86 // Returns false if this is not a RTCP packet or it is not directed to 87 // Returns false if this is not a RTCP packet or it is not directed to
87 // this session, e.g. SSRC doesn't match. 88 // this session, e.g. SSRC doesn't match.
88 bool IncomingRtcpPacket(const uint8* data, size_t length); 89 bool IncomingRtcpPacket(const uint8* data, size_t length);
89 90
90 // If available, returns true and sets the output arguments to the latest 91 // If available, returns true and sets the output arguments to the latest
91 // lip-sync timestamps gleaned from the sender reports. While the sender 92 // lip-sync timestamps gleaned from the sender reports. While the sender
92 // provides reference NTP times relative to its own wall clock, the 93 // provides reference NTP times relative to its own wall clock, the
93 // |reference_time| returned here has been translated to the local 94 // |reference_time| returned here has been translated to the local
94 // CastEnvironment clock. 95 // CastEnvironment clock.
95 bool GetLatestLipSyncTimes(uint32_t* rtp_timestamp, 96 bool GetLatestLipSyncTimes(RtpTimeTicks* rtp_timestamp,
96 base::TimeTicks* reference_time) const; 97 base::TimeTicks* reference_time) const;
97 98
98 void OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log); 99 void OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log);
99 100
100 // If greater than zero, this is the last measured network round trip time. 101 // If greater than zero, this is the last measured network round trip time.
101 base::TimeDelta current_round_trip_time() const { 102 base::TimeDelta current_round_trip_time() const {
102 return current_round_trip_time_; 103 return current_round_trip_time_;
103 } 104 }
104 105
105 static bool IsRtcpPacket(const uint8* packet, size_t length); 106 static bool IsRtcpPacket(const uint8* packet, size_t length);
106 static uint32_t GetSsrcOfSender(const uint8* rtcp_buffer, size_t length); 107 static uint32_t GetSsrcOfSender(const uint8* rtcp_buffer, size_t length);
107 108
108 uint32_t GetLocalSsrc() const { return local_ssrc_; } 109 uint32_t GetLocalSsrc() const { return local_ssrc_; }
109 uint32_t GetRemoteSsrc() const { return remote_ssrc_; } 110 uint32_t GetRemoteSsrc() const { return remote_ssrc_; }
110 111
111 protected: 112 protected:
112 void OnReceivedNtp(uint32_t ntp_seconds, uint32_t ntp_fraction); 113 void OnReceivedNtp(uint32_t ntp_seconds, uint32_t ntp_fraction);
113 void OnReceivedLipSyncInfo(uint32_t rtp_timestamp, 114 void OnReceivedLipSyncInfo(RtpTimeTicks rtp_timestamp,
114 uint32_t ntp_seconds, 115 uint32_t ntp_seconds,
115 uint32_t ntp_fraction); 116 uint32_t ntp_fraction);
116 117
117 private: 118 private:
118 void OnReceivedDelaySinceLastReport(uint32_t last_report, 119 void OnReceivedDelaySinceLastReport(uint32_t last_report,
119 uint32_t delay_since_last_report); 120 uint32_t delay_since_last_report);
120 121
121 void OnReceivedCastFeedback(const RtcpCastMessage& cast_message); 122 void OnReceivedCastFeedback(const RtcpCastMessage& cast_message);
122 123
123 void SaveLastSentNtpTime(const base::TimeTicks& now, 124 void SaveLastSentNtpTime(const base::TimeTicks& now,
124 uint32_t last_ntp_seconds, 125 uint32_t last_ntp_seconds,
125 uint32_t last_ntp_fraction); 126 uint32_t last_ntp_fraction);
126 127
127 // Remove duplicate events in |receiver_log|. 128 // Remove duplicate events in |receiver_log|.
128 // Returns true if any events remain. 129 // Returns true if any events remain.
129 bool DedupeReceiverLog(RtcpReceiverLogMessage* receiver_log); 130 bool DedupeReceiverLog(RtcpReceiverLogMessage* receiver_log);
130 131
131 const RtcpCastMessageCallback cast_callback_; 132 const RtcpCastMessageCallback cast_callback_;
132 const RtcpRttCallback rtt_callback_; 133 const RtcpRttCallback rtt_callback_;
133 const RtcpLogMessageCallback log_callback_; 134 const RtcpLogMessageCallback log_callback_;
134 base::TickClock* const clock_; // Not owned by this class. 135 base::TickClock* const clock_; // Not owned by this class.
135 RtcpBuilder rtcp_builder_; 136 RtcpBuilder rtcp_builder_;
136 PacedPacketSender* packet_sender_; // Not owned. 137 PacedPacketSender* packet_sender_; // Not owned.
137 const uint32_t local_ssrc_; 138 const uint32_t local_ssrc_;
138 const uint32_t remote_ssrc_; 139 const uint32_t remote_ssrc_;
139 140
141 RtcpParser parser_;
Irfan 2015/12/09 21:24:28 probably add a comment here that parser now rememb
miu 2015/12/10 00:38:37 Done.
142
140 RtcpSendTimeMap last_reports_sent_map_; 143 RtcpSendTimeMap last_reports_sent_map_;
141 RtcpSendTimeQueue last_reports_sent_queue_; 144 RtcpSendTimeQueue last_reports_sent_queue_;
142 145
143 // The truncated (i.e., 64-->32-bit) NTP timestamp provided in the last report 146 // The truncated (i.e., 64-->32-bit) NTP timestamp provided in the last report
144 // from the remote peer, along with the local time at which the report was 147 // from the remote peer, along with the local time at which the report was
145 // received. These values are used for ping-pong'ing NTP timestamps between 148 // received. These values are used for ping-pong'ing NTP timestamps between
146 // the peers so that they can estimate the network's round-trip time. 149 // the peers so that they can estimate the network's round-trip time.
147 uint32_t last_report_truncated_ntp_; 150 uint32_t last_report_truncated_ntp_;
148 base::TimeTicks time_last_report_received_; 151 base::TimeTicks time_last_report_received_;
149 152
150 // Maintains a smoothed offset between the local clock and the remote clock. 153 // Maintains a smoothed offset between the local clock and the remote clock.
151 // Calling this member's Current() method is only valid if 154 // Calling this member's Current() method is only valid if
152 // |time_last_report_received_| is not "null." 155 // |time_last_report_received_| is not "null."
153 ClockDriftSmoother local_clock_ahead_by_; 156 ClockDriftSmoother local_clock_ahead_by_;
154 157
155 // Latest "lip sync" info from the sender. The sender provides the RTP 158 // Latest "lip sync" info from the sender. The sender provides the RTP
156 // timestamp of some frame of its choosing and also a corresponding reference 159 // timestamp of some frame of its choosing and also a corresponding reference
157 // NTP timestamp sampled from a clock common to all media streams. It is 160 // NTP timestamp sampled from a clock common to all media streams. It is
158 // expected that the sender will update this data regularly and in a timely 161 // expected that the sender will update this data regularly and in a timely
159 // manner (e.g., about once per second). 162 // manner (e.g., about once per second).
160 uint32_t lip_sync_rtp_timestamp_; 163 RtpTimeTicks lip_sync_rtp_timestamp_;
161 uint64_t lip_sync_ntp_timestamp_; 164 uint64_t lip_sync_ntp_timestamp_;
162 165
163 // The last measured network round trip time. This is updated with each 166 // The last measured network round trip time. This is updated with each
164 // sender report --> receiver report round trip. If this is zero, then the 167 // sender report --> receiver report round trip. If this is zero, then the
165 // round trip time has not been measured yet. 168 // round trip time has not been measured yet.
166 base::TimeDelta current_round_trip_time_; 169 base::TimeDelta current_round_trip_time_;
167 170
168 base::TimeTicks largest_seen_timestamp_; 171 base::TimeTicks largest_seen_timestamp_;
169 172
170 // For extending received ACK frame IDs from 8-bit to 32-bit. 173 // For extending received ACK frame IDs from 8-bit to 32-bit.
171 FrameIdWrapHelper ack_frame_id_wrap_helper_; 174 FrameIdWrapHelper ack_frame_id_wrap_helper_;
172 175
173 // Maintains a history of receiver events. 176 // Maintains a history of receiver events.
174 typedef std::pair<uint64_t, uint64_t> ReceiverEventKey; 177 typedef std::pair<uint64_t, uint64_t> ReceiverEventKey;
175 base::hash_set<ReceiverEventKey> receiver_event_key_set_; 178 base::hash_set<ReceiverEventKey> receiver_event_key_set_;
176 std::queue<ReceiverEventKey> receiver_event_key_queue_; 179 std::queue<ReceiverEventKey> receiver_event_key_queue_;
177 180
178 DISALLOW_COPY_AND_ASSIGN(Rtcp); 181 DISALLOW_COPY_AND_ASSIGN(Rtcp);
179 }; 182 };
180 183
181 } // namespace cast 184 } // namespace cast
182 } // namespace media 185 } // namespace media
183 186
184 #endif // MEDIA_CAST_RTCP_RTCP_H_ 187 #endif // MEDIA_CAST_RTCP_RTCP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698