1 /* 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef WEBRTC_VIDEO_VIE_RECEIVER_H_ 12 #define WEBRTC_VIDEO_VIE_RECEIVER_H_ 13 14 #include <list> 15 #include <vector> 16 17 #include "webrtc/base/scoped_ptr.h" 18 #include "webrtc/engine_configurations.h" 19 #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" 20 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 21 #include "webrtc/typedefs.h" 22 23 namespace webrtc { 24 25 class CriticalSectionWrapper; 26 class FecReceiver; 27 class RemoteNtpTimeEstimator; 28 class ReceiveStatistics; 29 class RemoteBitrateEstimator; 30 class RtpHeaderParser; 31 class RTPPayloadRegistry; 32 class RtpReceiver; 33 class RtpRtcp; 34 class VideoCodingModule; 35 struct ReceiveBandwidthEstimatorStats; 36 37 class ViEReceiver : public RtpData { 38 public: 39 ViEReceiver(VideoCodingModule* module_vcm, 40 RemoteBitrateEstimator* remote_bitrate_estimator, 41 RtpFeedback* rtp_feedback); 42 ~ViEReceiver(); 43 44 bool SetReceiveCodec(const VideoCodec& video_codec); 45 bool RegisterPayload(const VideoCodec& video_codec); 46 47 void SetNackStatus(bool enable, int max_nack_reordering_threshold); 48 void SetRtxPayloadType(int payload_type, int associated_payload_type); 49 // If set to true, the RTX payload type mapping supplied in 50 // |SetRtxPayloadType| will be used when restoring RTX packets. Without it, 51 // RTX packets will always be restored to the last non-RTX packet payload type 52 // received. 53 void SetUseRtxPayloadMappingOnRestore(bool val); 54 void SetRtxSsrc(uint32_t ssrc); 55 bool GetRtxSsrc(uint32_t* ssrc) const; 56 57 bool IsFecEnabled() const; 58 59 uint32_t GetRemoteSsrc() const; 60 int GetCsrcs(uint32_t* csrcs) const; 61 62 void SetRtpRtcpModule(RtpRtcp* module); 63 64 RtpReceiver* GetRtpReceiver() const; 65 66 void RegisterRtpRtcpModules(const std::vector<RtpRtcp*>& rtp_modules); 67 68 bool SetReceiveTimestampOffsetStatus(bool enable, int id); 69 bool SetReceiveAbsoluteSendTimeStatus(bool enable, int id); 70 bool SetReceiveVideoRotationStatus(bool enable, int id); 71 bool SetReceiveTransportSequenceNumber(bool enable, int id); 72 73 void StartReceive(); 74 void StopReceive(); 75 76 // Receives packets from external transport. 77 int ReceivedRTPPacket(const void* rtp_packet, size_t rtp_packet_length, 78 const PacketTime& packet_time); 79 int ReceivedRTCPPacket(const void* rtcp_packet, size_t rtcp_packet_length); 80 81 // Implements RtpData. 82 int32_t OnReceivedPayloadData(const uint8_t* payload_data, 83 const size_t payload_size, 84 const WebRtcRTPHeader* rtp_header) override; 85 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override; 86 87 ReceiveStatistics* GetReceiveStatistics() const; 88 89 private: 90 int InsertRTPPacket(const uint8_t* rtp_packet, size_t rtp_packet_length, 91 const PacketTime& packet_time); 92 bool ReceivePacket(const uint8_t* packet, 93 size_t packet_length, 94 const RTPHeader& header, 95 bool in_order); 96 // Parses and handles for instance RTX and RED headers. 97 // This function assumes that it's being called from only one thread. 98 bool ParseAndHandleEncapsulatingHeader(const uint8_t* packet, 99 size_t packet_length, 100 const RTPHeader& header); 101 void NotifyReceiverOfFecPacket(const RTPHeader& header); 102 int InsertRTCPPacket(const uint8_t* rtcp_packet, size_t rtcp_packet_length); 103 bool IsPacketInOrder(const RTPHeader& header) const; 104 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const; 105 void UpdateHistograms(); 106 107 rtc::scoped_ptr<CriticalSectionWrapper> receive_cs_; 108 Clock* clock_; 109 rtc::scoped_ptr<RtpHeaderParser> rtp_header_parser_; 110 rtc::scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_; 111 rtc::scoped_ptr<RtpReceiver> rtp_receiver_; 112 const rtc::scoped_ptr<ReceiveStatistics> rtp_receive_statistics_; 113 rtc::scoped_ptr<FecReceiver> fec_receiver_; 114 RtpRtcp* rtp_rtcp_; 115 std::vector<RtpRtcp*> rtp_rtcp_simulcast_; 116 VideoCodingModule* vcm_; 117 RemoteBitrateEstimator* remote_bitrate_estimator_; 118 119 rtc::scoped_ptr<RemoteNtpTimeEstimator> ntp_estimator_; 120 121 bool receiving_; 122 uint8_t restored_packet_[IP_PACKET_SIZE]; 123 bool restored_packet_in_use_; 124 bool receiving_ast_enabled_; 125 bool receiving_cvo_enabled_; 126 bool receiving_tsn_enabled_; 127 int64_t last_packet_log_ms_; 128 }; 129 130 } // namespace webrtc 131 132 #endif // WEBRTC_VIDEO_VIE_RECEIVER_H_ 133