OLD | NEW |
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 |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 class LocalRtcpReceiverFeedback; | 32 class LocalRtcpReceiverFeedback; |
33 class PacedPacketSender; | 33 class PacedPacketSender; |
34 class RtcpReceiver; | 34 class RtcpReceiver; |
35 class RtcpBuilder; | 35 class RtcpBuilder; |
36 | 36 |
37 typedef std::pair<uint32, base::TimeTicks> RtcpSendTimePair; | 37 typedef std::pair<uint32, base::TimeTicks> RtcpSendTimePair; |
38 typedef std::map<uint32, base::TimeTicks> RtcpSendTimeMap; | 38 typedef std::map<uint32, base::TimeTicks> RtcpSendTimeMap; |
39 typedef std::queue<RtcpSendTimePair> RtcpSendTimeQueue; | 39 typedef std::queue<RtcpSendTimePair> RtcpSendTimeQueue; |
40 | 40 |
41 struct RtpReceiverStatistics { | |
42 RtpReceiverStatistics(); | |
43 uint8 fraction_lost; | |
44 uint32 cumulative_lost; // 24 bits valid. | |
45 uint32 extended_high_sequence_number; | |
46 uint32 jitter; | |
47 }; | |
48 | |
49 // TODO(hclam): This should be renamed to RtcpSession. | 41 // TODO(hclam): This should be renamed to RtcpSession. |
50 class Rtcp { | 42 class Rtcp { |
51 public: | 43 public: |
52 Rtcp(const RtcpCastMessageCallback& cast_callback, | 44 Rtcp(const RtcpCastMessageCallback& cast_callback, |
53 const RtcpRttCallback& rtt_callback, | 45 const RtcpRttCallback& rtt_callback, |
54 const RtcpLogMessageCallback& log_callback, | 46 const RtcpLogMessageCallback& log_callback, |
55 base::TickClock* clock, // Not owned. | 47 base::TickClock* clock, // Not owned. |
56 PacedPacketSender* packet_sender, // Not owned. | 48 PacedPacketSender* packet_sender, // Not owned. |
57 uint32 local_ssrc, | 49 uint32 local_ssrc, |
58 uint32 remote_ssrc); | 50 uint32 remote_ssrc); |
59 | 51 |
60 virtual ~Rtcp(); | 52 virtual ~Rtcp(); |
61 | 53 |
62 // Send a RTCP sender report. | 54 // Send a RTCP sender report. |
63 // |current_time| is the current time reported by a tick clock. | 55 // |current_time| is the current time reported by a tick clock. |
64 // |current_time_as_rtp_timestamp| is the corresponding RTP timestamp. | 56 // |current_time_as_rtp_timestamp| is the corresponding RTP timestamp. |
65 // |send_packet_count| is the number of packets sent. | 57 // |send_packet_count| is the number of packets sent. |
66 // |send_octet_count| is the number of octets sent. | 58 // |send_octet_count| is the number of octets sent. |
67 void SendRtcpFromRtpSender( | 59 void SendRtcpFromRtpSender( |
68 base::TimeTicks current_time, | 60 base::TimeTicks current_time, |
69 uint32 current_time_as_rtp_timestamp, | 61 uint32 current_time_as_rtp_timestamp, |
70 uint32 send_packet_count, | 62 uint32 send_packet_count, |
71 size_t send_octet_count); | 63 size_t send_octet_count); |
72 | 64 |
73 // |cast_message| and |rtcp_events| is optional; if |cast_message| is | 65 // This function is meant to be used in conjunction with |
74 // provided the RTCP receiver report will append a Cast message containing | 66 // SendRtcpFromRtpReceiver. |
75 // Acks and Nacks; |target_delay| is sent together with |cast_message|. | 67 // |now| is converted to NTP and saved internally for |
76 // If |rtcp_events| is provided the RTCP receiver report will append the | 68 // future round-trip/lip-sync calculations. |
77 // log messages. | 69 // This is done in a separate method so that SendRtcpFromRtpReceiver can |
| 70 // be done on a separate (temporary) RTCP object. |
| 71 RtcpTimeData ConvertToNTPAndSave(base::TimeTicks now); |
| 72 |
| 73 // |cast_message|, |rtcp_events| and |rtp_receiver_statistics| are optional; |
| 74 // if |cast_message| is provided the RTCP receiver report will append a Cast |
| 75 // message containing Acks and Nacks; |target_delay| is sent together with |
| 76 // |cast_message|. If |rtcp_events| is provided the RTCP receiver report will |
| 77 // append the log messages. |
78 void SendRtcpFromRtpReceiver( | 78 void SendRtcpFromRtpReceiver( |
| 79 RtcpTimeData time_data, |
79 const RtcpCastMessage* cast_message, | 80 const RtcpCastMessage* cast_message, |
80 base::TimeDelta target_delay, | 81 base::TimeDelta target_delay, |
81 const ReceiverRtcpEventSubscriber::RtcpEventMultiMap* rtcp_events, | 82 const ReceiverRtcpEventSubscriber::RtcpEvents* rtcp_events, |
82 RtpReceiverStatistics* rtp_receiver_statistics); | 83 const RtpReceiverStatistics* rtp_receiver_statistics) const; |
83 | 84 |
84 // Submit a received packet to this object. The packet will be parsed | 85 // Submit a received packet to this object. The packet will be parsed |
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* rtp_timestamp, | 96 bool GetLatestLipSyncTimes(uint32* 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 GetSsrcOfSender(const uint8* rtcp_buffer, size_t length); | 107 static uint32 GetSsrcOfSender(const uint8* rtcp_buffer, size_t length); |
107 | 108 |
| 109 uint32 GetLocalSsrc() const { return local_ssrc_; } |
| 110 uint32 GetRemoteSsrc() const { return remote_ssrc_; } |
| 111 |
108 protected: | 112 protected: |
109 void OnReceivedNtp(uint32 ntp_seconds, uint32 ntp_fraction); | 113 void OnReceivedNtp(uint32 ntp_seconds, uint32 ntp_fraction); |
110 void OnReceivedLipSyncInfo(uint32 rtp_timestamp, | 114 void OnReceivedLipSyncInfo(uint32 rtp_timestamp, |
111 uint32 ntp_seconds, | 115 uint32 ntp_seconds, |
112 uint32 ntp_fraction); | 116 uint32 ntp_fraction); |
113 | 117 |
114 private: | 118 private: |
115 void OnReceivedDelaySinceLastReport(uint32 last_report, | 119 void OnReceivedDelaySinceLastReport(uint32 last_report, |
116 uint32 delay_since_last_report); | 120 uint32 delay_since_last_report); |
117 | 121 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 base::hash_set<ReceiverEventKey> receiver_event_key_set_; | 176 base::hash_set<ReceiverEventKey> receiver_event_key_set_; |
173 std::queue<ReceiverEventKey> receiver_event_key_queue_; | 177 std::queue<ReceiverEventKey> receiver_event_key_queue_; |
174 | 178 |
175 DISALLOW_COPY_AND_ASSIGN(Rtcp); | 179 DISALLOW_COPY_AND_ASSIGN(Rtcp); |
176 }; | 180 }; |
177 | 181 |
178 } // namespace cast | 182 } // namespace cast |
179 } // namespace media | 183 } // namespace media |
180 | 184 |
181 #endif // MEDIA_CAST_RTCP_RTCP_H_ | 185 #endif // MEDIA_CAST_RTCP_RTCP_H_ |
OLD | NEW |