blob: b6e19cb26e27ffc51f60cf3f1c8c8c58c99553c8 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
leozwang@webrtc.org39e96592012-03-01 18:22:48 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
Peter Boström7623ce42015-12-09 12:13:30 +010011#ifndef WEBRTC_VIDEO_VIE_RECEIVER_H_
12#define WEBRTC_VIDEO_VIE_RECEIVER_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +000014#include <list>
kwiberg27f982b2016-03-01 11:52:33 -080015#include <memory>
Peter Boström9c017252016-02-26 16:26:20 +010016#include <string>
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +010017#include <vector>
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +000018
Tommi97888bd2016-01-21 23:24:59 +010019#include "webrtc/base/criticalsection.h"
pwestin@webrtc.org82dcc9f2013-04-02 20:37:14 +000020#include "webrtc/engine_configurations.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010021#include "webrtc/modules/rtp_rtcp/include/receive_statistics.h"
22#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
pwestin@webrtc.org82dcc9f2013-04-02 20:37:14 +000023#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000024
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000025namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000026
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000027class FecReceiver;
wu@webrtc.org88abf112014-05-14 16:53:51 +000028class RemoteNtpTimeEstimator;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000029class ReceiveStatistics;
stefan@webrtc.org976a7e62012-09-21 13:20:21 +000030class RemoteBitrateEstimator;
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000031class RtpHeaderParser;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000032class RTPPayloadRegistry;
33class RtpReceiver;
niklase@google.com470e71d2011-07-07 08:21:25 +000034class RtpRtcp;
35class VideoCodingModule;
niklase@google.com470e71d2011-07-07 08:21:25 +000036
pwestin@webrtc.org82dcc9f2013-04-02 20:37:14 +000037class ViEReceiver : public RtpData {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000038 public:
Peter Boströmac547a62015-09-17 23:03:57 +020039 ViEReceiver(VideoCodingModule* module_vcm,
wu@webrtc.org822fbd82013-08-15 23:38:54 +000040 RemoteBitrateEstimator* remote_bitrate_estimator,
41 RtpFeedback* rtp_feedback);
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000042 ~ViEReceiver();
niklase@google.com470e71d2011-07-07 08:21:25 +000043
wu@webrtc.org822fbd82013-08-15 23:38:54 +000044 bool SetReceiveCodec(const VideoCodec& video_codec);
45 bool RegisterPayload(const VideoCodec& video_codec);
46
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000047 void SetNackStatus(bool enable, int max_nack_reordering_threshold);
Shao Changbine62202f2015-04-21 20:24:50 +080048 void SetRtxPayloadType(int payload_type, int associated_payload_type);
noahric65220a72015-10-14 11:29:49 -070049 // 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);
stefan@webrtc.orgef927552014-06-05 08:25:29 +000054 void SetRtxSsrc(uint32_t ssrc);
asapersson@webrtc.orgd952c402014-11-27 07:38:56 +000055 bool GetRtxSsrc(uint32_t* ssrc) const;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000056
asapersson@webrtc.org273fbbb2015-01-27 12:17:29 +000057 bool IsFecEnabled() const;
58
wu@webrtc.org822fbd82013-08-15 23:38:54 +000059 uint32_t GetRemoteSsrc() const;
60 int GetCsrcs(uint32_t* csrcs) const;
61
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +000062 void SetRtpRtcpModule(RtpRtcp* module);
63
wu@webrtc.org822fbd82013-08-15 23:38:54 +000064 RtpReceiver* GetRtpReceiver() const;
65
Peter Boströmd6f1a382015-07-14 16:08:02 +020066 void RegisterRtpRtcpModules(const std::vector<RtpRtcp*>& rtp_modules);
Peter Boström6cff9cf2015-04-21 13:47:17 +020067
Peter Boström9c017252016-02-26 16:26:20 +010068 void EnableReceiveRtpHeaderExtension(const std::string& extension, int id);
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000069
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000070 void StartReceive();
71 void StopReceive();
niklase@google.com470e71d2011-07-07 08:21:25 +000072
Peter Boströmd1d66ba2016-02-08 14:07:14 +010073 bool DeliverRtp(const uint8_t* rtp_packet,
74 size_t rtp_packet_length,
75 const PacketTime& packet_time);
76 bool DeliverRtcp(const uint8_t* rtcp_packet, size_t rtcp_packet_length);
niklase@google.com470e71d2011-07-07 08:21:25 +000077
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000078 // Implements RtpData.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000079 int32_t OnReceivedPayloadData(const uint8_t* payload_data,
80 const size_t payload_size,
81 const WebRtcRTPHeader* rtp_header) override;
82 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000083
wu@webrtc.org822fbd82013-08-15 23:38:54 +000084 ReceiveStatistics* GetReceiveStatistics() const;
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +010085
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000086 private:
sprang@webrtc.org0e932572014-01-23 10:00:39 +000087 bool ReceivePacket(const uint8_t* packet,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000088 size_t packet_length,
sprang@webrtc.org0e932572014-01-23 10:00:39 +000089 const RTPHeader& header,
90 bool in_order);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000091 // Parses and handles for instance RTX and RED headers.
92 // This function assumes that it's being called from only one thread.
93 bool ParseAndHandleEncapsulatingHeader(const uint8_t* packet,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000094 size_t packet_length,
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000095 const RTPHeader& header);
asapersson@webrtc.org37c05592015-01-28 13:58:27 +000096 void NotifyReceiverOfFecPacket(const RTPHeader& header);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000097 bool IsPacketInOrder(const RTPHeader& header) const;
stefan@webrtc.org48df3812013-11-08 15:18:52 +000098 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
asapersson@webrtc.org0800db72015-01-15 07:40:20 +000099 void UpdateHistograms();
niklase@google.com470e71d2011-07-07 08:21:25 +0000100
Tommi97888bd2016-01-21 23:24:59 +0100101 rtc::CriticalSection receive_cs_;
stefan@webrtc.orgeb24b042014-10-14 11:40:13 +0000102 Clock* clock_;
kwiberg27f982b2016-03-01 11:52:33 -0800103 std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
104 std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
105 std::unique_ptr<RtpReceiver> rtp_receiver_;
106 const std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
107 std::unique_ptr<FecReceiver> fec_receiver_;
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000108 RtpRtcp* rtp_rtcp_;
Peter Boströmd6f1a382015-07-14 16:08:02 +0200109 std::vector<RtpRtcp*> rtp_rtcp_simulcast_;
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000110 VideoCodingModule* vcm_;
stefan@webrtc.org976a7e62012-09-21 13:20:21 +0000111 RemoteBitrateEstimator* remote_bitrate_estimator_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000112
kwiberg27f982b2016-03-01 11:52:33 -0800113 std::unique_ptr<RemoteNtpTimeEstimator> ntp_estimator_;
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000114
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000115 bool receiving_;
mflodmanc4a1c372015-11-06 04:33:51 -0800116 uint8_t restored_packet_[IP_PACKET_SIZE];
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000117 bool restored_packet_in_use_;
stefan@webrtc.orgeb24b042014-10-14 11:40:13 +0000118 int64_t last_packet_log_ms_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000119};
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000120
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100121} // namespace webrtc
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000122
Peter Boström7623ce42015-12-09 12:13:30 +0100123#endif // WEBRTC_VIDEO_VIE_RECEIVER_H_