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

Side by Side Diff: media/cast/net/rtcp/sender_rtcp_session.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: Add missing rtcp_session.h and a few comments 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
(Empty)
1 // Copyright 2015 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 #ifndef MEDIA_CAST_NET_RTCP_SENDER_RTCP_SESSION_H_
6 #define MEDIA_CAST_NET_RTCP_SENDER_RTCP_SESSION_H_
7
8 #include <hash_set>
9 #include <map>
10 #include <queue>
11 #include <utility>
12
13 #include "base/time/time.h"
14 #include "media/cast/net/pacing/paced_sender.h"
15 #include "media/cast/net/rtcp/rtcp_defines.h"
16 #include "media/cast/net/rtcp/rtcp_session.h"
17 #include "media/cast/net/rtcp/rtcp_utility.h"
18
19 namespace media {
20 namespace cast {
21
22 typedef std::pair<uint32_t, base::TimeTicks> RtcpSendTimePair;
23 typedef std::map<uint32_t, base::TimeTicks> RtcpSendTimeMap;
24 typedef std::queue<RtcpSendTimePair> RtcpSendTimeQueue;
25
26 // This class represents a RTCP session on a RTP sender. It provides an
27 // interface to send RTCP sender report (SR). RTCP SR packets allow
28 // receiver to maintain clock offsets and synchronize between audio and video.
29 //
30 // RTCP session on sender handles the following incoming RTCP reports
31 // from receiver:
32 // - Receiver reference time report: Helps with tracking largest timestamp
33 // seen and as a result rejecting old RTCP reports.
34 // - Receiver logs: The sender receives log events from the receiver and
35 // invokes a callback passed.
36 // - cast message: Receives feedback from receiver on missing packets/frames
37 // and last frame id received and invokes a callback passed.
38 // - Last report: The receiver provides feedback on delay since last report
39 // received which helps it compute round trip time and invoke a callback.
40 class SenderRtcpSession : public RtcpSession {
41 public:
42 SenderRtcpSession(const RtcpCastMessageCallback& cast_callback,
43 const RtcpRttCallback& rtt_callback,
44 const RtcpLogMessageCallback& log_callback,
45 base::TickClock* clock, // Not owned.
46 PacedPacketSender* packet_sender, // Not owned.
47 uint32_t local_ssrc,
48 uint32_t remote_ssrc);
49
50 ~SenderRtcpSession() override;
51
52 // If greater than zero, this is the last measured network round trip time.
53 base::TimeDelta current_round_trip_time() const {
54 return current_round_trip_time_;
55 }
56
57 // Send a RTCP sender report.
58 // |current_time| is the current time reported by a tick clock.
59 // |current_time_as_rtp_timestamp| is the corresponding RTP timestamp.
60 // |send_packet_count| is the number of packets sent.
61 // |send_octet_count| is the number of octets sent.
62 void SendRtcpReport(base::TimeTicks current_time,
63 RtpTimeTicks current_time_as_rtp_timestamp,
64 uint32_t send_packet_count,
65 size_t send_octet_count);
66
67 // Handle incoming RTCP packet.
68 // Returns false if it is not a RTCP packet or it is not directed to
69 // this session, e.g. SSRC doesn't match.
70 bool IncomingRtcpPacket(const uint8* data, size_t length) override;
71
72 private:
73 // Received last report information from RTP receiver which helps compute
74 // round trip time.
75 void OnReceivedDelaySinceLastReport(uint32_t last_report,
76 uint32_t delay_since_last_report);
77
78 // Received logs from RTP receiver.
79 void OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log);
80
81 // Received cast message containing details of missing packets/frames and
82 // last frame id received.
83 void OnReceivedCastFeedback(const RtcpCastMessage& cast_message);
84
85 // Remove duplicate events in |receiver_log|.
86 // Returns true if any events remain.
87 bool DedupeReceiverLog(RtcpReceiverLogMessage* receiver_log);
88
89 // Save last sent NTP time on RTPC SR. This helps map the sent time when a
90 // last report is received from RTP receiver to compute RTT.
91 void SaveLastSentNtpTime(const base::TimeTicks& now,
92 uint32_t last_ntp_seconds,
93 uint32_t last_ntp_fraction);
94
95 base::TickClock* const clock_; // Not owned.
96 PacedPacketSender* packet_sender_; // Not owned.
97 const uint32_t local_ssrc_;
98 const uint32_t remote_ssrc_;
99
100 const RtcpCastMessageCallback cast_callback_;
101 const RtcpRttCallback rtt_callback_;
102 const RtcpLogMessageCallback log_callback_;
103
104 // Computed from RTCP RRTR report.
105 base::TimeTicks largest_seen_timestamp_;
106
107 // The RTCP packet parser is re-used when parsing each RTCP packet. It
108 // remembers state about prior RTP timestamps and other sequence values to
109 // re-construct "expanded" values.
110 RtcpParser parser_;
111
112 // For extending received ACK frame IDs from 8-bit to 32-bit.
113 FrameIdWrapHelper ack_frame_id_wrap_helper_;
114
115 // Maintains a history of receiver events.
116 typedef std::pair<uint64_t, uint64_t> ReceiverEventKey;
117 base::hash_set<ReceiverEventKey> receiver_event_key_set_;
118 std::queue<ReceiverEventKey> receiver_event_key_queue_;
119
120 // The last measured network round trip time. This is updated with each
121 // sender report --> receiver report round trip. If this is zero, then the
122 // round trip time has not been measured yet.
123 base::TimeDelta current_round_trip_time_;
124
125 // Map of NTP timestamp to local time that helps with RTT calculation
126 // when last report is received from RTP receiver.
127 RtcpSendTimeMap last_reports_sent_map_;
128 RtcpSendTimeQueue last_reports_sent_queue_;
129
130 DISALLOW_COPY_AND_ASSIGN(SenderRtcpSession);
131 };
132
133 } // namespace cast
134 } // namespace media
135
136 #endif // MEDIA_CAST_NET_RTCP_SENDER_RTCP_SESSION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698