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

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

Issue 1520613004: cast: Split Rtcp into two for sender and receiver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@timestamp
Patch Set: Rebased Created 4 years, 11 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
« no previous file with comments | « media/cast/net/rtcp/receiver_rtcp_session.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
(Empty)
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
3 // found in the LICENSE file.
4
5 // This class maintains a bi-directional RTCP connection with a remote
6 // peer.
7
8 #ifndef MEDIA_CAST_RTCP_RTCP_H_
9 #define MEDIA_CAST_RTCP_RTCP_H_
10
11 #include <stddef.h>
12 #include <stdint.h>
13
14 #include <map>
15 #include <queue>
16 #include <string>
17
18 #include "base/macros.h"
19 #include "base/memory/scoped_ptr.h"
20 #include "base/memory/weak_ptr.h"
21 #include "base/time/tick_clock.h"
22 #include "base/time/time.h"
23 #include "media/cast/common/clock_drift_smoother.h"
24 #include "media/cast/net/cast_transport_defines.h"
25 #include "media/cast/net/cast_transport_sender.h"
26 #include "media/cast/net/rtcp/receiver_rtcp_event_subscriber.h"
27 #include "media/cast/net/rtcp/rtcp_builder.h"
28 #include "media/cast/net/rtcp/rtcp_defines.h"
29 #include "media/cast/net/rtcp/rtcp_utility.h"
30
31 namespace media {
32 namespace cast {
33
34 class LocalRtcpReceiverFeedback;
35 class PacedPacketSender;
36 class RtcpReceiver;
37 class RtcpBuilder;
38
39 typedef std::pair<uint32_t, base::TimeTicks> RtcpSendTimePair;
40 typedef std::map<uint32_t, base::TimeTicks> RtcpSendTimeMap;
41 typedef std::queue<RtcpSendTimePair> RtcpSendTimeQueue;
42
43 // TODO(hclam): This should be renamed to RtcpSession.
44 class Rtcp {
45 public:
46 Rtcp(const RtcpCastMessageCallback& cast_callback,
47 const RtcpRttCallback& rtt_callback,
48 const RtcpLogMessageCallback& log_callback,
49 base::TickClock* clock, // Not owned.
50 PacedPacketSender* packet_sender, // Not owned.
51 uint32_t local_ssrc,
52 uint32_t remote_ssrc);
53
54 virtual ~Rtcp();
55
56 // Send a RTCP sender report.
57 // |current_time| is the current time reported by a tick clock.
58 // |current_time_as_rtp_timestamp| is the corresponding RTP timestamp.
59 // |send_packet_count| is the number of packets sent.
60 // |send_octet_count| is the number of octets sent.
61 void SendRtcpFromRtpSender(base::TimeTicks current_time,
62 RtpTimeTicks current_time_as_rtp_timestamp,
63 uint32_t send_packet_count,
64 size_t send_octet_count);
65
66 // This function is meant to be used in conjunction with
67 // SendRtcpFromRtpReceiver.
68 // |now| is converted to NTP and saved internally for
69 // future round-trip/lip-sync calculations.
70 // This is done in a separate method so that SendRtcpFromRtpReceiver can
71 // be done on a separate (temporary) RTCP object.
72 RtcpTimeData ConvertToNTPAndSave(base::TimeTicks now);
73
74 // |cast_message|, |rtcp_events| and |rtp_receiver_statistics| are optional;
75 // if |cast_message| is provided the RTCP receiver report will append a Cast
76 // message containing Acks and Nacks; |target_delay| is sent together with
77 // |cast_message|. If |rtcp_events| is provided the RTCP receiver report will
78 // append the log messages.
79 void SendRtcpFromRtpReceiver(
80 RtcpTimeData time_data,
81 const RtcpCastMessage* cast_message,
82 base::TimeDelta target_delay,
83 const ReceiverRtcpEventSubscriber::RtcpEvents* rtcp_events,
84 const RtpReceiverStatistics* rtp_receiver_statistics) const;
85
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_t* data, size_t length);
91
92 // If available, returns true and sets the output arguments to the latest
93 // lip-sync timestamps gleaned from the sender reports. While the sender
94 // provides reference NTP times relative to its own wall clock, the
95 // |reference_time| returned here has been translated to the local
96 // CastEnvironment clock.
97 bool GetLatestLipSyncTimes(RtpTimeTicks* rtp_timestamp,
98 base::TimeTicks* reference_time) const;
99
100 void OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log);
101
102 // If greater than zero, this is the last measured network round trip time.
103 base::TimeDelta current_round_trip_time() const {
104 return current_round_trip_time_;
105 }
106
107 static bool IsRtcpPacket(const uint8_t* packet, size_t length);
108 static uint32_t GetSsrcOfSender(const uint8_t* rtcp_buffer, size_t length);
109
110 uint32_t GetLocalSsrc() const { return local_ssrc_; }
111 uint32_t GetRemoteSsrc() const { return remote_ssrc_; }
112
113 protected:
114 void OnReceivedNtp(uint32_t ntp_seconds, uint32_t ntp_fraction);
115 void OnReceivedLipSyncInfo(RtpTimeTicks rtp_timestamp,
116 uint32_t ntp_seconds,
117 uint32_t ntp_fraction);
118
119 private:
120 void OnReceivedDelaySinceLastReport(uint32_t last_report,
121 uint32_t delay_since_last_report);
122
123 void OnReceivedCastFeedback(const RtcpCastMessage& cast_message);
124
125 void SaveLastSentNtpTime(const base::TimeTicks& now,
126 uint32_t last_ntp_seconds,
127 uint32_t last_ntp_fraction);
128
129 // Remove duplicate events in |receiver_log|.
130 // Returns true if any events remain.
131 bool DedupeReceiverLog(RtcpReceiverLogMessage* receiver_log);
132
133 const RtcpCastMessageCallback cast_callback_;
134 const RtcpRttCallback rtt_callback_;
135 const RtcpLogMessageCallback log_callback_;
136 base::TickClock* const clock_; // Not owned by this class.
137 RtcpBuilder rtcp_builder_;
138 PacedPacketSender* packet_sender_; // Not owned.
139 const uint32_t local_ssrc_;
140 const uint32_t remote_ssrc_;
141
142 // The RTCP packet parser is re-used when parsing each RTCP packet. It
143 // remembers state about prior RTP timestamps and other sequence values to
144 // re-construct "expanded" values.
145 RtcpParser parser_;
146
147 RtcpSendTimeMap last_reports_sent_map_;
148 RtcpSendTimeQueue last_reports_sent_queue_;
149
150 // The truncated (i.e., 64-->32-bit) NTP timestamp provided in the last report
151 // from the remote peer, along with the local time at which the report was
152 // received. These values are used for ping-pong'ing NTP timestamps between
153 // the peers so that they can estimate the network's round-trip time.
154 uint32_t last_report_truncated_ntp_;
155 base::TimeTicks time_last_report_received_;
156
157 // Maintains a smoothed offset between the local clock and the remote clock.
158 // Calling this member's Current() method is only valid if
159 // |time_last_report_received_| is not "null."
160 ClockDriftSmoother local_clock_ahead_by_;
161
162 // Latest "lip sync" info from the sender. The sender provides the RTP
163 // timestamp of some frame of its choosing and also a corresponding reference
164 // NTP timestamp sampled from a clock common to all media streams. It is
165 // expected that the sender will update this data regularly and in a timely
166 // manner (e.g., about once per second).
167 RtpTimeTicks lip_sync_rtp_timestamp_;
168 uint64_t lip_sync_ntp_timestamp_;
169
170 // The last measured network round trip time. This is updated with each
171 // sender report --> receiver report round trip. If this is zero, then the
172 // round trip time has not been measured yet.
173 base::TimeDelta current_round_trip_time_;
174
175 base::TimeTicks largest_seen_timestamp_;
176
177 // For extending received ACK frame IDs from 8-bit to 32-bit.
178 FrameIdWrapHelper ack_frame_id_wrap_helper_;
179
180 // Maintains a history of receiver events.
181 typedef std::pair<uint64_t, uint64_t> ReceiverEventKey;
182 base::hash_set<ReceiverEventKey> receiver_event_key_set_;
183 std::queue<ReceiverEventKey> receiver_event_key_queue_;
184
185 DISALLOW_COPY_AND_ASSIGN(Rtcp);
186 };
187
188 } // namespace cast
189 } // namespace media
190
191 #endif // MEDIA_CAST_RTCP_RTCP_H_
OLDNEW
« no previous file with comments | « media/cast/net/rtcp/receiver_rtcp_session.cc ('k') | media/cast/net/rtcp/rtcp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698