niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
leozwang@webrtc.org | 39e9659 | 2012-03-01 18:22:48 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
mflodman@webrtc.org | e06ca3c | 2012-06-29 13:20:14 +0000 | [diff] [blame] | 11 | #ifndef WEBRTC_VIDEO_ENGINE_VIE_RECEIVER_H_ |
| 12 | #define WEBRTC_VIDEO_ENGINE_VIE_RECEIVER_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
pwestin@webrtc.org | 1da1ce0 | 2011-10-13 15:19:55 +0000 | [diff] [blame] | 14 | #include <list> |
| 15 | |
pwestin@webrtc.org | 82dcc9f | 2013-04-02 20:37:14 +0000 | [diff] [blame] | 16 | #include "webrtc/engine_configurations.h" |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 17 | #include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h" |
pwestin@webrtc.org | 82dcc9f | 2013-04-02 20:37:14 +0000 | [diff] [blame] | 18 | #include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h" |
| 19 | #include "webrtc/system_wrappers/interface/scoped_ptr.h" |
| 20 | #include "webrtc/typedefs.h" |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 21 | #include "webrtc/video_engine/include/vie_network.h" |
pwestin@webrtc.org | 82dcc9f | 2013-04-02 20:37:14 +0000 | [diff] [blame] | 22 | #include "webrtc/video_engine/vie_defines.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | |
mflodman@webrtc.org | ad4ee36 | 2011-11-28 22:39:24 +0000 | [diff] [blame] | 24 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 25 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | class CriticalSectionWrapper; |
mflodman@webrtc.org | ad4ee36 | 2011-11-28 22:39:24 +0000 | [diff] [blame] | 27 | class Encryption; |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 28 | class FecReceiver; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 29 | class ReceiveStatistics; |
stefan@webrtc.org | 976a7e6 | 2012-09-21 13:20:21 +0000 | [diff] [blame] | 30 | class RemoteBitrateEstimator; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | class RtpDump; |
stefan@webrtc.org | a5cb98c | 2013-05-29 12:12:51 +0000 | [diff] [blame] | 32 | class RtpHeaderParser; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 33 | class RTPPayloadRegistry; |
| 34 | class RtpReceiver; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | class RtpRtcp; |
| 36 | class VideoCodingModule; |
jiayl@webrtc.org | 1f64f06 | 2014-02-10 19:12:14 +0000 | [diff] [blame] | 37 | struct ReceiveBandwidthEstimatorStats; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 38 | |
pwestin@webrtc.org | 82dcc9f | 2013-04-02 20:37:14 +0000 | [diff] [blame] | 39 | class ViEReceiver : public RtpData { |
mflodman@webrtc.org | ad4ee36 | 2011-11-28 22:39:24 +0000 | [diff] [blame] | 40 | public: |
stefan@webrtc.org | 976a7e6 | 2012-09-21 13:20:21 +0000 | [diff] [blame] | 41 | ViEReceiver(const int32_t channel_id, VideoCodingModule* module_vcm, |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 42 | RemoteBitrateEstimator* remote_bitrate_estimator, |
| 43 | RtpFeedback* rtp_feedback); |
mflodman@webrtc.org | ad4ee36 | 2011-11-28 22:39:24 +0000 | [diff] [blame] | 44 | ~ViEReceiver(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 45 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 46 | bool SetReceiveCodec(const VideoCodec& video_codec); |
| 47 | bool RegisterPayload(const VideoCodec& video_codec); |
| 48 | |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 49 | void SetNackStatus(bool enable, int max_nack_reordering_threshold); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 50 | void SetRtxStatus(bool enable, uint32_t ssrc); |
| 51 | void SetRtxPayloadType(uint32_t payload_type); |
| 52 | |
| 53 | uint32_t GetRemoteSsrc() const; |
| 54 | int GetCsrcs(uint32_t* csrcs) const; |
| 55 | |
mflodman@webrtc.org | ad4ee36 | 2011-11-28 22:39:24 +0000 | [diff] [blame] | 56 | int RegisterExternalDecryption(Encryption* decryption); |
| 57 | int DeregisterExternalDecryption(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 59 | void SetRtpRtcpModule(RtpRtcp* module); |
| 60 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 61 | RtpReceiver* GetRtpReceiver() const; |
| 62 | |
mflodman@webrtc.org | ad4ee36 | 2011-11-28 22:39:24 +0000 | [diff] [blame] | 63 | void RegisterSimulcastRtpRtcpModules(const std::list<RtpRtcp*>& rtp_modules); |
pwestin@webrtc.org | 1da1ce0 | 2011-10-13 15:19:55 +0000 | [diff] [blame] | 64 | |
stefan@webrtc.org | 08994cc | 2013-05-29 13:28:21 +0000 | [diff] [blame] | 65 | bool SetReceiveTimestampOffsetStatus(bool enable, int id); |
| 66 | bool SetReceiveAbsoluteSendTimeStatus(bool enable, int id); |
stefan@webrtc.org | a5cb98c | 2013-05-29 12:12:51 +0000 | [diff] [blame] | 67 | |
mflodman@webrtc.org | ad4ee36 | 2011-11-28 22:39:24 +0000 | [diff] [blame] | 68 | void StartReceive(); |
| 69 | void StopReceive(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 70 | |
mflodman@webrtc.org | ad4ee36 | 2011-11-28 22:39:24 +0000 | [diff] [blame] | 71 | int StartRTPDump(const char file_nameUTF8[1024]); |
| 72 | int StopRTPDump(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 73 | |
mflodman@webrtc.org | ad4ee36 | 2011-11-28 22:39:24 +0000 | [diff] [blame] | 74 | // Receives packets from external transport. |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 75 | int ReceivedRTPPacket(const void* rtp_packet, int rtp_packet_length, |
| 76 | const PacketTime& packet_time); |
mflodman@webrtc.org | ad4ee36 | 2011-11-28 22:39:24 +0000 | [diff] [blame] | 77 | int ReceivedRTCPPacket(const void* rtcp_packet, int rtcp_packet_length); |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 78 | virtual bool OnRecoveredPacket(const uint8_t* packet, |
| 79 | int packet_length) OVERRIDE; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 80 | |
mflodman@webrtc.org | ad4ee36 | 2011-11-28 22:39:24 +0000 | [diff] [blame] | 81 | // Implements RtpData. |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 82 | virtual int32_t OnReceivedPayloadData( |
| 83 | const uint8_t* payload_data, |
| 84 | const uint16_t payload_size, |
mflodman@webrtc.org | ad4ee36 | 2011-11-28 22:39:24 +0000 | [diff] [blame] | 85 | const WebRtcRTPHeader* rtp_header); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 86 | |
mflodman@webrtc.org | 4fd5527 | 2013-02-06 17:46:39 +0000 | [diff] [blame] | 87 | void EstimatedReceiveBandwidth(unsigned int* available_bandwidth) const; |
stefan@webrtc.org | b586507 | 2013-02-01 14:33:42 +0000 | [diff] [blame] | 88 | |
jiayl@webrtc.org | 1f64f06 | 2014-02-10 19:12:14 +0000 | [diff] [blame] | 89 | void GetReceiveBandwidthEstimatorStats( |
| 90 | ReceiveBandwidthEstimatorStats* output) const; |
| 91 | |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 92 | ReceiveStatistics* GetReceiveStatistics() const; |
| 93 | |
mflodman@webrtc.org | ad4ee36 | 2011-11-28 22:39:24 +0000 | [diff] [blame] | 94 | private: |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 +0000 | [diff] [blame] | 95 | int InsertRTPPacket(const int8_t* rtp_packet, int rtp_packet_length, |
| 96 | const PacketTime& packet_time); |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 97 | bool ReceivePacket(const uint8_t* packet, |
| 98 | int packet_length, |
| 99 | const RTPHeader& header, |
| 100 | bool in_order); |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 101 | // Parses and handles for instance RTX and RED headers. |
| 102 | // This function assumes that it's being called from only one thread. |
| 103 | bool ParseAndHandleEncapsulatingHeader(const uint8_t* packet, |
| 104 | int packet_length, |
| 105 | const RTPHeader& header); |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 106 | int InsertRTCPPacket(const int8_t* rtcp_packet, int rtcp_packet_length); |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 107 | bool IsPacketInOrder(const RTPHeader& header) const; |
stefan@webrtc.org | 48df381 | 2013-11-08 15:18:52 +0000 | [diff] [blame] | 108 | bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 109 | |
mflodman@webrtc.org | d32c447 | 2011-12-22 14:17:53 +0000 | [diff] [blame] | 110 | scoped_ptr<CriticalSectionWrapper> receive_cs_; |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 111 | const int32_t channel_id_; |
stefan@webrtc.org | a5cb98c | 2013-05-29 12:12:51 +0000 | [diff] [blame] | 112 | scoped_ptr<RtpHeaderParser> rtp_header_parser_; |
wu@webrtc.org | 822fbd8 | 2013-08-15 23:38:54 +0000 | [diff] [blame] | 113 | scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_; |
| 114 | scoped_ptr<RtpReceiver> rtp_receiver_; |
| 115 | scoped_ptr<ReceiveStatistics> rtp_receive_statistics_; |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 116 | scoped_ptr<FecReceiver> fec_receiver_; |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 117 | RtpRtcp* rtp_rtcp_; |
mflodman@webrtc.org | ad4ee36 | 2011-11-28 22:39:24 +0000 | [diff] [blame] | 118 | std::list<RtpRtcp*> rtp_rtcp_simulcast_; |
pwestin@webrtc.org | 2853dde | 2012-05-11 11:08:54 +0000 | [diff] [blame] | 119 | VideoCodingModule* vcm_; |
stefan@webrtc.org | 976a7e6 | 2012-09-21 13:20:21 +0000 | [diff] [blame] | 120 | RemoteBitrateEstimator* remote_bitrate_estimator_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 121 | |
mflodman@webrtc.org | ad4ee36 | 2011-11-28 22:39:24 +0000 | [diff] [blame] | 122 | Encryption* external_decryption_; |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 +0000 | [diff] [blame] | 123 | uint8_t* decryption_buffer_; |
mflodman@webrtc.org | ad4ee36 | 2011-11-28 22:39:24 +0000 | [diff] [blame] | 124 | RtpDump* rtp_dump_; |
| 125 | bool receiving_; |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 126 | uint8_t restored_packet_[kViEMaxMtu]; |
| 127 | bool restored_packet_in_use_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 128 | }; |
mflodman@webrtc.org | ad4ee36 | 2011-11-28 22:39:24 +0000 | [diff] [blame] | 129 | |
| 130 | } // namespace webrt |
| 131 | |
mflodman@webrtc.org | e06ca3c | 2012-06-29 13:20:14 +0000 | [diff] [blame] | 132 | #endif // WEBRTC_VIDEO_ENGINE_VIE_RECEIVER_H_ |