Index: media/cast/net/rtcp/sender_rtcp_session.h |
diff --git a/media/cast/net/rtcp/rtcp.h b/media/cast/net/rtcp/sender_rtcp_session.h |
similarity index 36% |
rename from media/cast/net/rtcp/rtcp.h |
rename to media/cast/net/rtcp/sender_rtcp_session.h |
index 96f5147e5123b3f0d8042ed585cddc8b404a2c7b..f22dd589c681d707d74c4569b90a650295b032b5 100644 |
--- a/media/cast/net/rtcp/rtcp.h |
+++ b/media/cast/net/rtcp/sender_rtcp_session.h |
@@ -1,179 +1,114 @@ |
-// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-// This class maintains a bi-directional RTCP connection with a remote |
-// peer. |
- |
-#ifndef MEDIA_CAST_RTCP_RTCP_H_ |
-#define MEDIA_CAST_RTCP_RTCP_H_ |
- |
-#include <stddef.h> |
-#include <stdint.h> |
+#ifndef MEDIA_CAST_NET_RTCP_SENDER_RTCP_SESSION_H_ |
+#define MEDIA_CAST_NET_RTCP_SENDER_RTCP_SESSION_H_ |
#include <map> |
#include <queue> |
-#include <string> |
+#include <utility> |
-#include "base/macros.h" |
-#include "base/memory/scoped_ptr.h" |
-#include "base/memory/weak_ptr.h" |
-#include "base/time/tick_clock.h" |
+#include "base/containers/hash_tables.h" |
#include "base/time/time.h" |
-#include "media/cast/common/clock_drift_smoother.h" |
-#include "media/cast/net/cast_transport_defines.h" |
-#include "media/cast/net/cast_transport_sender.h" |
-#include "media/cast/net/rtcp/receiver_rtcp_event_subscriber.h" |
-#include "media/cast/net/rtcp/rtcp_builder.h" |
+#include "media/cast/net/pacing/paced_sender.h" |
#include "media/cast/net/rtcp/rtcp_defines.h" |
+#include "media/cast/net/rtcp/rtcp_session.h" |
#include "media/cast/net/rtcp/rtcp_utility.h" |
namespace media { |
namespace cast { |
-class LocalRtcpReceiverFeedback; |
-class PacedPacketSender; |
-class RtcpReceiver; |
-class RtcpBuilder; |
- |
typedef std::pair<uint32_t, base::TimeTicks> RtcpSendTimePair; |
typedef std::map<uint32_t, base::TimeTicks> RtcpSendTimeMap; |
typedef std::queue<RtcpSendTimePair> RtcpSendTimeQueue; |
-// TODO(hclam): This should be renamed to RtcpSession. |
-class Rtcp { |
+// This class represents a RTCP session on a RTP sender. It provides an |
+// interface to send RTCP sender report (SR). RTCP SR packets allow |
+// receiver to maintain clock offsets and synchronize between audio and video. |
+// |
+// RTCP session on sender handles the following incoming RTCP reports |
+// from receiver: |
+// - Receiver reference time report: Helps with tracking largest timestamp |
+// seen and as a result rejecting old RTCP reports. |
+// - Receiver logs: The sender receives log events from the receiver and |
+// invokes a callback passed. |
+// - cast message: Receives feedback from receiver on missing packets/frames |
+// and last frame id received and invokes a callback passed. |
+// - Last report: The receiver provides feedback on delay since last report |
+// received which helps it compute round trip time and invoke a callback. |
+class SenderRtcpSession : public RtcpSession { |
public: |
- Rtcp(const RtcpCastMessageCallback& cast_callback, |
- const RtcpRttCallback& rtt_callback, |
- const RtcpLogMessageCallback& log_callback, |
- base::TickClock* clock, // Not owned. |
- PacedPacketSender* packet_sender, // Not owned. |
- uint32_t local_ssrc, |
- uint32_t remote_ssrc); |
- |
- virtual ~Rtcp(); |
- |
- // Send a RTCP sender report. |
- // |current_time| is the current time reported by a tick clock. |
- // |current_time_as_rtp_timestamp| is the corresponding RTP timestamp. |
- // |send_packet_count| is the number of packets sent. |
- // |send_octet_count| is the number of octets sent. |
- void SendRtcpFromRtpSender(base::TimeTicks current_time, |
- RtpTimeTicks current_time_as_rtp_timestamp, |
- uint32_t send_packet_count, |
- size_t send_octet_count); |
- |
- // This function is meant to be used in conjunction with |
- // SendRtcpFromRtpReceiver. |
- // |now| is converted to NTP and saved internally for |
- // future round-trip/lip-sync calculations. |
- // This is done in a separate method so that SendRtcpFromRtpReceiver can |
- // be done on a separate (temporary) RTCP object. |
- RtcpTimeData ConvertToNTPAndSave(base::TimeTicks now); |
- |
- // |cast_message|, |rtcp_events| and |rtp_receiver_statistics| are optional; |
- // if |cast_message| is provided the RTCP receiver report will append a Cast |
- // message containing Acks and Nacks; |target_delay| is sent together with |
- // |cast_message|. If |rtcp_events| is provided the RTCP receiver report will |
- // append the log messages. |
- void SendRtcpFromRtpReceiver( |
- RtcpTimeData time_data, |
- const RtcpCastMessage* cast_message, |
- base::TimeDelta target_delay, |
- const ReceiverRtcpEventSubscriber::RtcpEvents* rtcp_events, |
- const RtpReceiverStatistics* rtp_receiver_statistics) const; |
- |
- // Submit a received packet to this object. The packet will be parsed |
- // and used to maintain a RTCP session. |
- // Returns false if this is not a RTCP packet or it is not directed to |
- // this session, e.g. SSRC doesn't match. |
- bool IncomingRtcpPacket(const uint8_t* data, size_t length); |
+ SenderRtcpSession(const RtcpCastMessageCallback& cast_callback, |
+ const RtcpRttCallback& rtt_callback, |
+ const RtcpLogMessageCallback& log_callback, |
+ base::TickClock* clock, // Not owned. |
+ PacedPacketSender* packet_sender, // Not owned. |
+ uint32_t local_ssrc, |
+ uint32_t remote_ssrc); |
- // If available, returns true and sets the output arguments to the latest |
- // lip-sync timestamps gleaned from the sender reports. While the sender |
- // provides reference NTP times relative to its own wall clock, the |
- // |reference_time| returned here has been translated to the local |
- // CastEnvironment clock. |
- bool GetLatestLipSyncTimes(RtpTimeTicks* rtp_timestamp, |
- base::TimeTicks* reference_time) const; |
- |
- void OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log); |
+ ~SenderRtcpSession() override; |
// If greater than zero, this is the last measured network round trip time. |
base::TimeDelta current_round_trip_time() const { |
return current_round_trip_time_; |
} |
- static bool IsRtcpPacket(const uint8_t* packet, size_t length); |
- static uint32_t GetSsrcOfSender(const uint8_t* rtcp_buffer, size_t length); |
- |
- uint32_t GetLocalSsrc() const { return local_ssrc_; } |
- uint32_t GetRemoteSsrc() const { return remote_ssrc_; } |
+ // Send a RTCP sender report. |
+ // |current_time| is the current time reported by a tick clock. |
+ // |current_time_as_rtp_timestamp| is the corresponding RTP timestamp. |
+ // |send_packet_count| is the number of packets sent. |
+ // |send_octet_count| is the number of octets sent. |
+ void SendRtcpReport(base::TimeTicks current_time, |
+ RtpTimeTicks current_time_as_rtp_timestamp, |
+ uint32_t send_packet_count, |
+ size_t send_octet_count); |
- protected: |
- void OnReceivedNtp(uint32_t ntp_seconds, uint32_t ntp_fraction); |
- void OnReceivedLipSyncInfo(RtpTimeTicks rtp_timestamp, |
- uint32_t ntp_seconds, |
- uint32_t ntp_fraction); |
+ // Handle incoming RTCP packet. |
+ // Returns false if it is not a RTCP packet or it is not directed to |
+ // this session, e.g. SSRC doesn't match. |
+ bool IncomingRtcpPacket(const uint8_t* data, size_t length) override; |
private: |
+ // Received last report information from RTP receiver which helps compute |
+ // round trip time. |
void OnReceivedDelaySinceLastReport(uint32_t last_report, |
uint32_t delay_since_last_report); |
+ // Received logs from RTP receiver. |
+ void OnReceivedReceiverLog(const RtcpReceiverLogMessage& receiver_log); |
+ |
+ // Received cast message containing details of missing packets/frames and |
+ // last frame id received. |
void OnReceivedCastFeedback(const RtcpCastMessage& cast_message); |
+ // Remove duplicate events in |receiver_log|. |
+ // Returns true if any events remain. |
+ bool DedupeReceiverLog(RtcpReceiverLogMessage* receiver_log); |
+ |
+ // Save last sent NTP time on RTPC SR. This helps map the sent time when a |
+ // last report is received from RTP receiver to compute RTT. |
void SaveLastSentNtpTime(const base::TimeTicks& now, |
uint32_t last_ntp_seconds, |
uint32_t last_ntp_fraction); |
- // Remove duplicate events in |receiver_log|. |
- // Returns true if any events remain. |
- bool DedupeReceiverLog(RtcpReceiverLogMessage* receiver_log); |
+ base::TickClock* const clock_; // Not owned. |
+ PacedPacketSender* packet_sender_; // Not owned. |
+ const uint32_t local_ssrc_; |
+ const uint32_t remote_ssrc_; |
const RtcpCastMessageCallback cast_callback_; |
const RtcpRttCallback rtt_callback_; |
const RtcpLogMessageCallback log_callback_; |
- base::TickClock* const clock_; // Not owned by this class. |
- RtcpBuilder rtcp_builder_; |
- PacedPacketSender* packet_sender_; // Not owned. |
- const uint32_t local_ssrc_; |
- const uint32_t remote_ssrc_; |
+ |
+ // Computed from RTCP RRTR report. |
+ base::TimeTicks largest_seen_timestamp_; |
// The RTCP packet parser is re-used when parsing each RTCP packet. It |
// remembers state about prior RTP timestamps and other sequence values to |
// re-construct "expanded" values. |
RtcpParser parser_; |
- RtcpSendTimeMap last_reports_sent_map_; |
- RtcpSendTimeQueue last_reports_sent_queue_; |
- |
- // The truncated (i.e., 64-->32-bit) NTP timestamp provided in the last report |
- // from the remote peer, along with the local time at which the report was |
- // received. These values are used for ping-pong'ing NTP timestamps between |
- // the peers so that they can estimate the network's round-trip time. |
- uint32_t last_report_truncated_ntp_; |
- base::TimeTicks time_last_report_received_; |
- |
- // Maintains a smoothed offset between the local clock and the remote clock. |
- // Calling this member's Current() method is only valid if |
- // |time_last_report_received_| is not "null." |
- ClockDriftSmoother local_clock_ahead_by_; |
- |
- // Latest "lip sync" info from the sender. The sender provides the RTP |
- // timestamp of some frame of its choosing and also a corresponding reference |
- // NTP timestamp sampled from a clock common to all media streams. It is |
- // expected that the sender will update this data regularly and in a timely |
- // manner (e.g., about once per second). |
- RtpTimeTicks lip_sync_rtp_timestamp_; |
- uint64_t lip_sync_ntp_timestamp_; |
- |
- // The last measured network round trip time. This is updated with each |
- // sender report --> receiver report round trip. If this is zero, then the |
- // round trip time has not been measured yet. |
- base::TimeDelta current_round_trip_time_; |
- |
- base::TimeTicks largest_seen_timestamp_; |
- |
// For extending received ACK frame IDs from 8-bit to 32-bit. |
FrameIdWrapHelper ack_frame_id_wrap_helper_; |
@@ -182,10 +117,20 @@ class Rtcp { |
base::hash_set<ReceiverEventKey> receiver_event_key_set_; |
std::queue<ReceiverEventKey> receiver_event_key_queue_; |
- DISALLOW_COPY_AND_ASSIGN(Rtcp); |
+ // The last measured network round trip time. This is updated with each |
+ // sender report --> receiver report round trip. If this is zero, then the |
+ // round trip time has not been measured yet. |
+ base::TimeDelta current_round_trip_time_; |
+ |
+ // Map of NTP timestamp to local time that helps with RTT calculation |
+ // when last report is received from RTP receiver. |
+ RtcpSendTimeMap last_reports_sent_map_; |
+ RtcpSendTimeQueue last_reports_sent_queue_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SenderRtcpSession); |
}; |
} // namespace cast |
} // namespace media |
-#endif // MEDIA_CAST_RTCP_RTCP_H_ |
+#endif // MEDIA_CAST_NET_RTCP_SENDER_RTCP_SESSION_H_ |