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

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: fix test 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
« no previous file with comments | « media/cast/net/rtcp/mock_rtcp_receiver_feedback.cc ('k') | media/cast/net/rtcp/rtcp.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
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 // TODO(hclam): This should be renamed to RtcpSession.
56 class Rtcp { 51 class Rtcp {
57 public: 52 public:
58 // Rtcp accepts two transports, one to be used by Cast senders 53 Rtcp(const RtcpCastMessageCallback& cast_callback,
59 // (CastTransportSender) only, and the other (PacedPacketSender) should only 54 const RtcpRttCallback& rtt_callback,
60 // be used by the Cast receivers and test applications. 55 const RtcpLogMessageCallback& log_callback,
61 Rtcp(scoped_refptr<CastEnvironment> cast_environment, 56 base::TickClock* clock, // Not owned.
62 RtcpSenderFeedback* sender_feedback, 57 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, 58 uint32 local_ssrc,
69 uint32 remote_ssrc, 59 uint32 remote_ssrc,
70 const std::string& c_name, 60 const std::string& c_name);
71 EventMediaType event_media_type);
72 61
73 virtual ~Rtcp(); 62 virtual ~Rtcp();
74 63
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. 64 // Send a RTCP sender report.
82 // |current_time| is the current time reported by a tick clock. 65 // |current_time| is the current time reported by a tick clock.
83 // |current_time_as_rtp_timestamp| is the corresponding RTP timestamp. 66 // |current_time_as_rtp_timestamp| is the corresponding RTP timestamp.
84 void SendRtcpFromRtpSender(base::TimeTicks current_time, 67 // |send_packet_count| is the number of packets sent.
85 uint32 current_time_as_rtp_timestamp); 68 // |send_octet_count| is the number of octets sent.
69 void SendRtcpFromRtpSender(
70 base::TimeTicks current_time,
71 uint32 current_time_as_rtp_timestamp,
72 uint32 send_packet_count,
73 size_t send_octet_count);
86 74
87 // |cast_message| and |rtcp_events| is optional; if |cast_message| is 75 // |cast_message| and |rtcp_events| is optional; if |cast_message| is
88 // provided the RTCP receiver report will append a Cast message containing 76 // provided the RTCP receiver report will append a Cast message containing
89 // Acks and Nacks; if |rtcp_events| is provided the RTCP receiver report 77 // Acks and Nacks; |target_delay| is sent together with |cast_message|.
90 // will append the log messages. 78 // If |rtcp_events| is provided the RTCP receiver report will append the
79 // log messages.
91 void SendRtcpFromRtpReceiver( 80 void SendRtcpFromRtpReceiver(
92 const RtcpCastMessage* cast_message, 81 const RtcpCastMessage* cast_message,
93 const ReceiverRtcpEventSubscriber::RtcpEventMultiMap* rtcp_events); 82 base::TimeDelta target_delay,
83 const ReceiverRtcpEventSubscriber::RtcpEventMultiMap* rtcp_events,
84 RtpReceiverStatistics* rtp_receiver_statistics);
94 85
95 void IncomingRtcpPacket(const uint8* rtcp_buffer, size_t length); 86 // Submit a received packet to this object. The packet will be parsed
87 // and used to maintain a RTCP session.
88 // Returns false if this is not a RTCP packet or it is not directed to
89 // this session, e.g. SSRC doesn't match.
90 bool IncomingRtcpPacket(const uint8* data, size_t length);
96 91
97 // TODO(miu): Clean up this method and downstream code: Only VideoSender uses 92 // 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 93 // 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 94 // it's not clear that any of the downstream code is doing the right thing
100 // with this data. 95 // with this data.
101 bool Rtt(base::TimeDelta* rtt, 96 bool Rtt(base::TimeDelta* rtt,
102 base::TimeDelta* avg_rtt, 97 base::TimeDelta* avg_rtt,
103 base::TimeDelta* min_rtt, 98 base::TimeDelta* min_rtt,
104 base::TimeDelta* max_rtt) const; 99 base::TimeDelta* max_rtt) const;
105 100
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 101 // If available, returns true and sets the output arguments to the latest
109 // lip-sync timestamps gleaned from the sender reports. While the sender 102 // lip-sync timestamps gleaned from the sender reports. While the sender
110 // provides reference NTP times relative to its own wall clock, the 103 // provides reference NTP times relative to its own wall clock, the
111 // |reference_time| returned here has been translated to the local 104 // |reference_time| returned here has been translated to the local
112 // CastEnvironment clock. 105 // CastEnvironment clock.
113 bool GetLatestLipSyncTimes(uint32* rtp_timestamp, 106 bool GetLatestLipSyncTimes(uint32* rtp_timestamp,
114 base::TimeTicks* reference_time) const; 107 base::TimeTicks* reference_time) const;
115 108
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); 109 void OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log);
126 110
127 protected: 111 protected:
128 void OnReceivedNtp(uint32 ntp_seconds, uint32 ntp_fraction); 112 void OnReceivedNtp(uint32 ntp_seconds, uint32 ntp_fraction);
129 void OnReceivedLipSyncInfo(uint32 rtp_timestamp, 113 void OnReceivedLipSyncInfo(uint32 rtp_timestamp,
130 uint32 ntp_seconds, 114 uint32 ntp_seconds,
131 uint32 ntp_fraction); 115 uint32 ntp_fraction);
132 116
133 private: 117 private:
134 friend class LocalRtcpRttFeedback; 118 class RtcpMessageHandlerImpl;
135 friend class LocalRtcpReceiverFeedback;
136 119
137 void OnReceivedDelaySinceLastReport(uint32 receivers_ssrc, 120 void OnReceivedDelaySinceLastReport(uint32 last_report,
138 uint32 last_report,
139 uint32 delay_since_last_report); 121 uint32 delay_since_last_report);
140 122
141 void OnReceivedSendReportRequest(); 123 void OnReceivedCastFeedback(const RtcpCastMessage& cast_message);
142 124
143 void UpdateRtt(const base::TimeDelta& sender_delay, 125 void UpdateRtt(const base::TimeDelta& sender_delay,
144 const base::TimeDelta& receiver_delay); 126 const base::TimeDelta& receiver_delay);
145 127
146 void UpdateNextTimeToSendRtcp();
147
148 void SaveLastSentNtpTime(const base::TimeTicks& now, 128 void SaveLastSentNtpTime(const base::TimeTicks& now,
149 uint32 last_ntp_seconds, 129 uint32 last_ntp_seconds,
150 uint32 last_ntp_fraction); 130 uint32 last_ntp_fraction);
151 131
152 scoped_refptr<CastEnvironment> cast_environment_; 132 const RtcpCastMessageCallback cast_callback_;
153 CastTransportSender* const transport_sender_; 133 const RtcpRttCallback rtt_callback_;
154 const base::TimeDelta rtcp_interval_; 134 const RtcpLogMessageCallback log_callback_;
155 const RtcpMode rtcp_mode_; 135 base::TickClock* const clock_; // Not owned by this class.
136 const scoped_ptr<RtcpSender> rtcp_sender_;
156 const uint32 local_ssrc_; 137 const uint32 local_ssrc_;
157 const uint32 remote_ssrc_; 138 const uint32 remote_ssrc_;
158 const std::string c_name_; 139 const std::string c_name_;
159 const EventMediaType event_media_type_; 140 const scoped_ptr<RtcpMessageHandlerImpl> handler_;
141 const scoped_ptr<RtcpReceiver> rtcp_receiver_;
160 142
161 // Not owned by this class.
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_;
167 scoped_ptr<RtcpReceiver> rtcp_receiver_;
168
169 base::TimeTicks next_time_to_send_rtcp_;
170 RtcpSendTimeMap last_reports_sent_map_; 143 RtcpSendTimeMap last_reports_sent_map_;
171 RtcpSendTimeQueue last_reports_sent_queue_; 144 RtcpSendTimeQueue last_reports_sent_queue_;
172 145
173 // 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
174 // 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
175 // 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
176 // 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.
177 uint32 last_report_truncated_ntp_; 150 uint32 last_report_truncated_ntp_;
178 base::TimeTicks time_last_report_received_; 151 base::TimeTicks time_last_report_received_;
179 152
180 // 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.
181 // Calling this member's Current() method is only valid if 154 // Calling this member's Current() method is only valid if
182 // |time_last_report_received_| is not "null." 155 // |time_last_report_received_| is not "null."
183 ClockDriftSmoother local_clock_ahead_by_; 156 ClockDriftSmoother local_clock_ahead_by_;
184 157
185 // 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
186 // 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
187 // 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
188 // 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
189 // manner (e.g., about once per second). 162 // manner (e.g., about once per second).
190 uint32 lip_sync_rtp_timestamp_; 163 uint32 lip_sync_rtp_timestamp_;
191 uint64 lip_sync_ntp_timestamp_; 164 uint64 lip_sync_ntp_timestamp_;
192 165
193 base::TimeDelta rtt_; 166 base::TimeDelta rtt_;
194 base::TimeDelta min_rtt_; 167 base::TimeDelta min_rtt_;
195 base::TimeDelta max_rtt_; 168 base::TimeDelta max_rtt_;
196 int number_of_rtt_in_avg_; 169 int number_of_rtt_in_avg_;
197 base::TimeDelta avg_rtt_; 170 base::TimeDelta avg_rtt_;
198 base::TimeDelta target_delay_;
199 171
200 DISALLOW_COPY_AND_ASSIGN(Rtcp); 172 DISALLOW_COPY_AND_ASSIGN(Rtcp);
201 }; 173 };
202 174
203 } // namespace cast 175 } // namespace cast
204 } // namespace media 176 } // namespace media
205 177
206 #endif // MEDIA_CAST_RTCP_RTCP_H_ 178 #endif // MEDIA_CAST_RTCP_RTCP_H_
OLDNEW
« no previous file with comments | « media/cast/net/rtcp/mock_rtcp_receiver_feedback.cc ('k') | media/cast/net/rtcp/rtcp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698