1 // Copyright 2013 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_RTCP_RTCP_RECEIVER_H_ 6 #define MEDIA_CAST_RTCP_RTCP_RECEIVER_H_ 7 8 #include <queue> 9 10 #include "base/containers/hash_tables.h" 11 #include "media/cast/rtcp/rtcp.h" 12 #include "media/cast/rtcp/rtcp_defines.h" 13 #include "media/cast/rtcp/rtcp_utility.h" 14 #include "media/cast/transport/cast_transport_defines.h" 15 16 namespace media { 17 namespace cast { 18 19 class RtcpReceiverFeedback { 20 public: 21 virtual void OnReceivedSenderReport( 22 const transport::RtcpSenderInfo& remote_sender_info) = 0; 23 24 virtual void OnReceiverReferenceTimeReport( 25 const RtcpReceiverReferenceTimeReport& remote_time_report) = 0; 26 27 virtual void OnReceivedSendReportRequest() = 0; 28 29 virtual void OnReceivedReceiverLog( 30 const RtcpReceiverLogMessage& receiver_log) = 0; 31 ~RtcpReceiverFeedback()32 virtual ~RtcpReceiverFeedback() {} 33 }; 34 35 class RtcpRttFeedback { 36 public: 37 virtual void OnReceivedDelaySinceLastReport( 38 uint32 receivers_ssrc, 39 uint32 last_report, 40 uint32 delay_since_last_report) = 0; 41 ~RtcpRttFeedback()42 virtual ~RtcpRttFeedback() {} 43 }; 44 45 class RtcpReceiver { 46 public: 47 explicit RtcpReceiver(scoped_refptr<CastEnvironment> cast_environment, 48 RtcpSenderFeedback* sender_feedback, 49 RtcpReceiverFeedback* receiver_feedback, 50 RtcpRttFeedback* rtt_feedback, 51 uint32 local_ssrc); 52 virtual ~RtcpReceiver(); 53 54 void SetRemoteSSRC(uint32 ssrc); 55 56 // Set the history size to record Cast receiver events. Event history is 57 // used to remove duplicates. The history has no more than |size| events. 58 void SetCastReceiverEventHistorySize(size_t size); 59 60 void IncomingRtcpPacket(RtcpParser* rtcp_parser); 61 62 private: 63 void HandleSenderReport(RtcpParser* rtcp_parser); 64 65 void HandleReceiverReport(RtcpParser* rtcp_parser); 66 67 void HandleReportBlock(const RtcpField* rtcp_field, uint32 remote_ssrc); 68 69 void HandleSDES(RtcpParser* rtcp_parser); 70 void HandleSDESChunk(RtcpParser* rtcp_parser); 71 72 void HandleBYE(RtcpParser* rtcp_parser); 73 74 void HandleXr(RtcpParser* rtcp_parser); 75 void HandleRrtr(RtcpParser* rtcp_parser, uint32 remote_ssrc); 76 void HandleDlrr(RtcpParser* rtcp_parser); 77 78 // Generic RTP Feedback. 79 void HandleNACK(RtcpParser* rtcp_parser); 80 void HandleNACKItem(const RtcpField* rtcp_field, 81 std::list<uint16>* nack_sequence_numbers); 82 83 void HandleSendReportRequest(RtcpParser* rtcp_parser); 84 85 // Payload-specific. 86 void HandlePLI(RtcpParser* rtcp_parser); 87 88 void HandleSLI(RtcpParser* rtcp_parser); 89 void HandleSLIItem(RtcpField* rtcpPacket); 90 91 void HandleRpsi(RtcpParser* rtcp_parser); 92 93 void HandleFIR(RtcpParser* rtcp_parser); 94 void HandleFIRItem(const RtcpField* rtcp_field); 95 96 void HandlePayloadSpecificApp(RtcpParser* rtcp_parser); 97 void HandlePayloadSpecificRembItem(RtcpParser* rtcp_parser); 98 void HandlePayloadSpecificCastItem(RtcpParser* rtcp_parser); 99 void HandlePayloadSpecificCastNackItem( 100 const RtcpField* rtcp_field, 101 MissingFramesAndPacketsMap* missing_frames_and_packets); 102 103 void HandleApplicationSpecificCastReceiverLog(RtcpParser* rtcp_parser); 104 void HandleApplicationSpecificCastSenderLog(RtcpParser* rtcp_parser); 105 void HandleApplicationSpecificCastReceiverEventLog( 106 uint32 frame_rtp_timestamp, 107 RtcpParser* rtcp_parser, 108 RtcpReceiverEventLogMessages* event_log_messages); 109 110 const uint32 ssrc_; 111 uint32 remote_ssrc_; 112 113 // Not owned by this class. 114 RtcpSenderFeedback* const sender_feedback_; 115 RtcpReceiverFeedback* const receiver_feedback_; 116 RtcpRttFeedback* const rtt_feedback_; 117 scoped_refptr<CastEnvironment> cast_environment_; 118 119 transport::FrameIdWrapHelper ack_frame_id_wrap_helper_; 120 121 // Maintains a history of receiver events. 122 size_t receiver_event_history_size_; 123 typedef std::pair<uint64, uint64> ReceiverEventKey; 124 base::hash_set<ReceiverEventKey> receiver_event_key_set_; 125 std::queue<ReceiverEventKey> receiver_event_key_queue_; 126 127 DISALLOW_COPY_AND_ASSIGN(RtcpReceiver); 128 }; 129 130 } // namespace cast 131 } // namespace media 132 133 #endif // MEDIA_CAST_RTCP_RTCP_RECEIVER_H_ 134