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

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

Issue 387933005: Cast: Refactor RTCP handling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: smaller diff Created 6 years, 5 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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
6 // peer.
7
5 #ifndef MEDIA_CAST_RTCP_RTCP_H_ 8 #ifndef MEDIA_CAST_RTCP_RTCP_H_
6 #define MEDIA_CAST_RTCP_RTCP_H_ 9 #define MEDIA_CAST_RTCP_RTCP_H_
7 10
8 #include <map> 11 #include <map>
9 #include <queue> 12 #include <queue>
10 #include <string> 13 #include <string>
11 14
12 #include "base/basictypes.h" 15 #include "base/basictypes.h"
13 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/weak_ptr.h"
14 #include "base/time/tick_clock.h" 18 #include "base/time/tick_clock.h"
15 #include "base/time/time.h" 19 #include "base/time/time.h"
16 #include "media/cast/cast_config.h" 20 #include "media/cast/cast_config.h"
17 #include "media/cast/cast_defines.h" 21 #include "media/cast/cast_defines.h"
18 #include "media/cast/cast_environment.h"
19 #include "media/cast/common/clock_drift_smoother.h" 22 #include "media/cast/common/clock_drift_smoother.h"
20 #include "media/cast/net/cast_transport_defines.h" 23 #include "media/cast/net/cast_transport_defines.h"
21 #include "media/cast/net/cast_transport_sender.h" 24 #include "media/cast/net/cast_transport_sender.h"
22 #include "media/cast/net/pacing/paced_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_defines.h" 26 #include "media/cast/net/rtcp/rtcp_defines.h"
25 27
26 namespace media { 28 namespace media {
27 namespace cast { 29 namespace cast {
28 30
29 class LocalRtcpReceiverFeedback; 31 class LocalRtcpReceiverFeedback;
30 class LocalRtcpRttFeedback;
31 class PacedPacketSender; 32 class PacedPacketSender;
32 class RtcpReceiver; 33 class RtcpReceiver;
33 class RtcpSender; 34 class RtcpSender;
34 35
35 typedef std::pair<uint32, base::TimeTicks> RtcpSendTimePair; 36 typedef std::pair<uint32, base::TimeTicks> RtcpSendTimePair;
36 typedef std::map<uint32, base::TimeTicks> RtcpSendTimeMap; 37 typedef std::map<uint32, base::TimeTicks> RtcpSendTimeMap;
37 typedef std::queue<RtcpSendTimePair> RtcpSendTimeQueue; 38 typedef std::queue<RtcpSendTimePair> RtcpSendTimeQueue;
38 39
39 class RtcpSenderFeedback {
40 public:
41 virtual void OnReceivedCastFeedback(const RtcpCastMessage& cast_feedback) = 0;
42
43 virtual ~RtcpSenderFeedback() {}
44 };
45
46 class RtpReceiverStatistics { 40 class RtpReceiverStatistics {
47 public: 41 public:
48 virtual void GetStatistics(uint8* fraction_lost, 42 virtual void GetStatistics(uint8* fraction_lost,
49 uint32* cumulative_lost, // 24 bits valid. 43 uint32* cumulative_lost, // 24 bits valid.
50 uint32* extended_high_sequence_number, 44 uint32* extended_high_sequence_number,
51 uint32* jitter) = 0; 45 uint32* jitter) = 0;
52 46
53 virtual ~RtpReceiverStatistics() {} 47 virtual ~RtpReceiverStatistics() {}
54 }; 48 };
55 49
50 class RtcpMessageHandlerImpl;
miu 2014/07/16 00:09:31 Any reason why this isn't just an private internal
Alpha Left Google 2014/07/17 01:01:45 Done.
51
52 // TODO(hclam): This should be renamed to RtcpSession.
56 class Rtcp { 53 class Rtcp {
57 public: 54 public:
58 // Rtcp accepts two transports, one to be used by Cast senders 55 Rtcp(const RtcpCastMessageCallback& cast_callback,
59 // (CastTransportSender) only, and the other (PacedPacketSender) should only 56 const RtcpRttCallback& rtt_callback,
60 // be used by the Cast receivers and test applications. 57 const RtcpLogMessageCallback& log_callback,
61 Rtcp(scoped_refptr<CastEnvironment> cast_environment, 58 base::TickClock* clock, // Not owned.
62 RtcpSenderFeedback* sender_feedback, 59 PacedPacketSender* packet_sender, // Not owned.
63 CastTransportSender* const transport_sender, // Send-side.
64 PacedPacketSender* paced_packet_sender, // Receive side.
65 RtpReceiverStatistics* rtp_receiver_statistics,
66 RtcpMode rtcp_mode,
67 const base::TimeDelta& rtcp_interval,
68 uint32 local_ssrc, 60 uint32 local_ssrc,
69 uint32 remote_ssrc, 61 uint32 remote_ssrc,
70 const std::string& c_name, 62 const std::string& c_name);
71 EventMediaType event_media_type);
72 63
73 virtual ~Rtcp(); 64 virtual ~Rtcp();
74 65
75 static bool IsRtcpPacket(const uint8* rtcp_buffer, size_t length);
76
77 static uint32 GetSsrcOfSender(const uint8* rtcp_buffer, size_t length);
78
79 base::TimeTicks TimeToSendNextRtcpReport();
80
81 // Send a RTCP sender report. 66 // Send a RTCP sender report.
82 // |current_time| is the current time reported by a tick clock. 67 // |current_time| is the current time reported by a tick clock.
83 // |current_time_as_rtp_timestamp| is the corresponding RTP timestamp. 68 // |current_time_as_rtp_timestamp| is the corresponding RTP timestamp.
84 void SendRtcpFromRtpSender(base::TimeTicks current_time, 69 // |send_packet_count| is the number of packets sent.
85 uint32 current_time_as_rtp_timestamp); 70 // |send_octet_count| is the number of octets sent.
71 void SendRtcpFromRtpSender(
miu 2014/07/16 00:09:31 ditto re: method rename: SendSenderReport
Alpha Left Google 2014/07/17 01:01:45 I'd like to do this in a later change. This is so
72 base::TimeTicks current_time,
73 uint32 current_time_as_rtp_timestamp,
74 uint32 send_packet_count,
75 size_t send_octet_count);
86 76
87 // |cast_message| and |rtcp_events| is optional; if |cast_message| is 77 // |cast_message| and |rtcp_events| is optional; if |cast_message| is
88 // provided the RTCP receiver report will append a Cast message containing 78 // provided the RTCP receiver report will append a Cast message containing
89 // Acks and Nacks; if |rtcp_events| is provided the RTCP receiver report 79 // Acks and Nacks; |target_delay| is sent together with |cast_message|.
90 // will append the log messages. 80 // If |rtcp_events| is provided the RTCP receiver report will append the
81 // log messages.
91 void SendRtcpFromRtpReceiver( 82 void SendRtcpFromRtpReceiver(
92 const RtcpCastMessage* cast_message, 83 const RtcpCastMessage* cast_message,
93 const ReceiverRtcpEventSubscriber::RtcpEventMultiMap* rtcp_events); 84 base::TimeDelta target_delay,
85 const ReceiverRtcpEventSubscriber::RtcpEventMultiMap* rtcp_events,
86 RtpReceiverStatistics* rtp_receiver_statistics);
94 87
95 void IncomingRtcpPacket(const uint8* rtcp_buffer, size_t length); 88 // Submit a received packet to this object. The packet will be parsed
89 // and uesd to maintain a RTCP session.
miu 2014/07/16 00:09:31 s/uesd/used/
Alpha Left Google 2014/07/17 01:01:45 Done.
90 // Returns false if this is not a RTCP packet or it is not directed to
91 // this session, e.g. SSRC doesn't match.
92 bool IncomingRtcpPacket(const uint8* data, size_t length);
96 93
97 // TODO(miu): Clean up this method and downstream code: Only VideoSender uses 94 // TODO(miu): Clean up this method and downstream code: Only VideoSender uses
98 // this (for congestion control), and only the |rtt| and |avg_rtt| values, and 95 // this (for congestion control), and only the |rtt| and |avg_rtt| values, and
99 // it's not clear that any of the downstream code is doing the right thing 96 // it's not clear that any of the downstream code is doing the right thing
100 // with this data. 97 // with this data.
101 bool Rtt(base::TimeDelta* rtt, 98 bool Rtt(base::TimeDelta* rtt,
102 base::TimeDelta* avg_rtt, 99 base::TimeDelta* avg_rtt,
103 base::TimeDelta* min_rtt, 100 base::TimeDelta* min_rtt,
104 base::TimeDelta* max_rtt) const; 101 base::TimeDelta* max_rtt) const;
105 102
106 bool is_rtt_available() const { return number_of_rtt_in_avg_ > 0; }
107
108 // If available, returns true and sets the output arguments to the latest 103 // If available, returns true and sets the output arguments to the latest
109 // lip-sync timestamps gleaned from the sender reports. While the sender 104 // lip-sync timestamps gleaned from the sender reports. While the sender
110 // provides reference NTP times relative to its own wall clock, the 105 // provides reference NTP times relative to its own wall clock, the
111 // |reference_time| returned here has been translated to the local 106 // |reference_time| returned here has been translated to the local
112 // CastEnvironment clock. 107 // CastEnvironment clock.
113 bool GetLatestLipSyncTimes(uint32* rtp_timestamp, 108 bool GetLatestLipSyncTimes(uint32* rtp_timestamp,
114 base::TimeTicks* reference_time) const; 109 base::TimeTicks* reference_time) const;
115 110
116 // Set the history size to record Cast receiver events. The event history is
117 // used to remove duplicates. The history will store at most |size| events.
118 void SetCastReceiverEventHistorySize(size_t size);
119
120 // Update the target delay. Will be added to every report sent back to the
121 // sender.
122 // TODO(miu): Remove this deprecated functionality. The sender ignores this.
123 void SetTargetDelay(base::TimeDelta target_delay);
124
125 void OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log); 111 void OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log);
126 112
127 protected: 113 protected:
128 void OnReceivedNtp(uint32 ntp_seconds, uint32 ntp_fraction); 114 void OnReceivedNtp(uint32 ntp_seconds, uint32 ntp_fraction);
129 void OnReceivedLipSyncInfo(uint32 rtp_timestamp, 115 void OnReceivedLipSyncInfo(uint32 rtp_timestamp,
130 uint32 ntp_seconds, 116 uint32 ntp_seconds,
131 uint32 ntp_fraction); 117 uint32 ntp_fraction);
132 118
133 private: 119 private:
134 friend class LocalRtcpRttFeedback; 120 friend class RtcpMessageHandlerImpl;
miu 2014/07/16 00:09:31 s/friend // (see comment above)
Alpha Left Google 2014/07/17 01:01:45 Done.
135 friend class LocalRtcpReceiverFeedback;
136 121
137 void OnReceivedDelaySinceLastReport(uint32 receivers_ssrc, 122 void OnReceivedDelaySinceLastReport(uint32 last_report,
138 uint32 last_report,
139 uint32 delay_since_last_report); 123 uint32 delay_since_last_report);
140 124
141 void OnReceivedSendReportRequest(); 125 void OnReceivedCastFeedback(const RtcpCastMessage& cast_message);
142 126
143 void UpdateRtt(const base::TimeDelta& sender_delay, 127 void UpdateRtt(const base::TimeDelta& sender_delay,
144 const base::TimeDelta& receiver_delay); 128 const base::TimeDelta& receiver_delay);
145 129
146 void UpdateNextTimeToSendRtcp();
147
148 void SaveLastSentNtpTime(const base::TimeTicks& now, 130 void SaveLastSentNtpTime(const base::TimeTicks& now,
149 uint32 last_ntp_seconds, 131 uint32 last_ntp_seconds,
150 uint32 last_ntp_fraction); 132 uint32 last_ntp_fraction);
151 133
152 scoped_refptr<CastEnvironment> cast_environment_; 134 base::TickClock* clock_; // Not owned by this class.
miu 2014/07/16 00:09:31 nit: base::TickClock* const clock_;
Alpha Left Google 2014/07/17 01:01:45 Done.
153 CastTransportSender* const transport_sender_; 135 const RtcpCastMessageCallback cast_callback_;
154 const base::TimeDelta rtcp_interval_; 136 const RtcpRttCallback rtt_callback_;
155 const RtcpMode rtcp_mode_; 137 const RtcpLogMessageCallback log_callback_;
156 const uint32 local_ssrc_; 138 const uint32 local_ssrc_;
157 const uint32 remote_ssrc_; 139 const uint32 remote_ssrc_;
158 const std::string c_name_; 140 const std::string c_name_;
159 const EventMediaType event_media_type_;
160 141
161 // Not owned by this class. 142 scoped_ptr<RtcpMessageHandlerImpl> handler_;
miu 2014/07/16 00:09:31 nit: const scoped_ptr<RtcpMessageHandlerImpl> hand
162 RtpReceiverStatistics* const rtp_receiver_statistics_;
163
164 scoped_ptr<LocalRtcpRttFeedback> rtt_feedback_;
165 scoped_ptr<LocalRtcpReceiverFeedback> receiver_feedback_;
166 scoped_ptr<RtcpSender> rtcp_sender_; 143 scoped_ptr<RtcpSender> rtcp_sender_;
miu 2014/07/16 00:09:31 nit: const
Alpha Left Google 2014/07/17 01:01:45 Done.
167 scoped_ptr<RtcpReceiver> rtcp_receiver_; 144 scoped_ptr<RtcpReceiver> rtcp_receiver_;
168 145
169 base::TimeTicks next_time_to_send_rtcp_;
170 RtcpSendTimeMap last_reports_sent_map_; 146 RtcpSendTimeMap last_reports_sent_map_;
171 RtcpSendTimeQueue last_reports_sent_queue_; 147 RtcpSendTimeQueue last_reports_sent_queue_;
172 148
173 // The truncated (i.e., 64-->32-bit) NTP timestamp provided in the last report 149 // The truncated (i.e., 64-->32-bit) NTP timestamp provided in the last report
174 // from the remote peer, along with the local time at which the report was 150 // from the remote peer, along with the local time at which the report was
175 // received. These values are used for ping-pong'ing NTP timestamps between 151 // received. These values are used for ping-pong'ing NTP timestamps between
176 // the peers so that they can estimate the network's round-trip time. 152 // the peers so that they can estimate the network's round-trip time.
177 uint32 last_report_truncated_ntp_; 153 uint32 last_report_truncated_ntp_;
178 base::TimeTicks time_last_report_received_; 154 base::TimeTicks time_last_report_received_;
179 155
180 // Maintains a smoothed offset between the local clock and the remote clock. 156 // Maintains a smoothed offset between the local clock and the remote clock.
181 // Calling this member's Current() method is only valid if 157 // Calling this member's Current() method is only valid if
182 // |time_last_report_received_| is not "null." 158 // |time_last_report_received_| is not "null."
183 ClockDriftSmoother local_clock_ahead_by_; 159 ClockDriftSmoother local_clock_ahead_by_;
184 160
185 // Latest "lip sync" info from the sender. The sender provides the RTP 161 // Latest "lip sync" info from the sender. The sender provides the RTP
186 // timestamp of some frame of its choosing and also a corresponding reference 162 // timestamp of some frame of its choosing and also a corresponding reference
187 // NTP timestamp sampled from a clock common to all media streams. It is 163 // NTP timestamp sampled from a clock common to all media streams. It is
188 // expected that the sender will update this data regularly and in a timely 164 // expected that the sender will update this data regularly and in a timely
189 // manner (e.g., about once per second). 165 // manner (e.g., about once per second).
190 uint32 lip_sync_rtp_timestamp_; 166 uint32 lip_sync_rtp_timestamp_;
191 uint64 lip_sync_ntp_timestamp_; 167 uint64 lip_sync_ntp_timestamp_;
192 168
193 base::TimeDelta rtt_; 169 base::TimeDelta rtt_;
194 base::TimeDelta min_rtt_; 170 base::TimeDelta min_rtt_;
195 base::TimeDelta max_rtt_; 171 base::TimeDelta max_rtt_;
196 int number_of_rtt_in_avg_; 172 int number_of_rtt_in_avg_;
197 base::TimeDelta avg_rtt_; 173 base::TimeDelta avg_rtt_;
198 base::TimeDelta target_delay_;
199 174
200 DISALLOW_COPY_AND_ASSIGN(Rtcp); 175 DISALLOW_COPY_AND_ASSIGN(Rtcp);
201 }; 176 };
202 177
203 } // namespace cast 178 } // namespace cast
204 } // namespace media 179 } // namespace media
205 180
206 #endif // MEDIA_CAST_RTCP_RTCP_H_ 181 #endif // MEDIA_CAST_RTCP_RTCP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698