blob: b0c5749f6ab6cce17ef15d28915df1c6ec8cfc1a [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
mflodman@webrtc.orge06ca3c2012-06-29 13:20:14 +000011#ifndef WEBRTC_VIDEO_ENGINE_VIE_RECEIVER_H_
12#define WEBRTC_VIDEO_ENGINE_VIE_RECEIVER_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +000014#include <list>
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +010015#include <vector>
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +000016
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000017#include "webrtc/base/scoped_ptr.h"
pwestin@webrtc.org82dcc9f2013-04-02 20:37:14 +000018#include "webrtc/engine_configurations.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010019#include "webrtc/modules/rtp_rtcp/include/receive_statistics.h"
20#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
pwestin@webrtc.org82dcc9f2013-04-02 20:37:14 +000021#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000022
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000023namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000024
niklase@google.com470e71d2011-07-07 08:21:25 +000025class CriticalSectionWrapper;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000026class FecReceiver;
wu@webrtc.org88abf112014-05-14 16:53:51 +000027class RemoteNtpTimeEstimator;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000028class ReceiveStatistics;
stefan@webrtc.org976a7e62012-09-21 13:20:21 +000029class RemoteBitrateEstimator;
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000030class RtpHeaderParser;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000031class RTPPayloadRegistry;
32class RtpReceiver;
niklase@google.com470e71d2011-07-07 08:21:25 +000033class RtpRtcp;
34class VideoCodingModule;
jiayl@webrtc.org1f64f062014-02-10 19:12:14 +000035struct ReceiveBandwidthEstimatorStats;
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
stefan@webrtc.org08994cc2013-05-29 13:28:21 +000068 bool SetReceiveTimestampOffsetStatus(bool enable, int id);
69 bool SetReceiveAbsoluteSendTimeStatus(bool enable, int id);
guoweis@webrtc.orgfdd10572015-03-12 20:50:57 +000070 bool SetReceiveVideoRotationStatus(bool enable, int id);
sprang867fb522015-08-03 04:38:41 -070071 bool SetReceiveTransportSequenceNumber(bool enable, int id);
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000072
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000073 void StartReceive();
74 void StopReceive();
niklase@google.com470e71d2011-07-07 08:21:25 +000075
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000076 // Receives packets from external transport.
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000077 int ReceivedRTPPacket(const void* rtp_packet, size_t rtp_packet_length,
wu@webrtc.orga9890802013-12-13 00:21:03 +000078 const PacketTime& packet_time);
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000079 int ReceivedRTCPPacket(const void* rtcp_packet, size_t rtcp_packet_length);
niklase@google.com470e71d2011-07-07 08:21:25 +000080
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000081 // Implements RtpData.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000082 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;
niklase@google.com470e71d2011-07-07 08:21:25 +000086
wu@webrtc.org822fbd82013-08-15 23:38:54 +000087 ReceiveStatistics* GetReceiveStatistics() const;
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +010088
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000089 private:
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000090 int InsertRTPPacket(const uint8_t* rtp_packet, size_t rtp_packet_length,
wu@webrtc.orga9890802013-12-13 00:21:03 +000091 const PacketTime& packet_time);
sprang@webrtc.org0e932572014-01-23 10:00:39 +000092 bool ReceivePacket(const uint8_t* packet,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000093 size_t packet_length,
sprang@webrtc.org0e932572014-01-23 10:00:39 +000094 const RTPHeader& header,
95 bool in_order);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000096 // 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,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000099 size_t packet_length,
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000100 const RTPHeader& header);
asapersson@webrtc.org37c05592015-01-28 13:58:27 +0000101 void NotifyReceiverOfFecPacket(const RTPHeader& header);
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000102 int InsertRTCPPacket(const uint8_t* rtcp_packet, size_t rtcp_packet_length);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000103 bool IsPacketInOrder(const RTPHeader& header) const;
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000104 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
asapersson@webrtc.org0800db72015-01-15 07:40:20 +0000105 void UpdateHistograms();
niklase@google.com470e71d2011-07-07 08:21:25 +0000106
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000107 rtc::scoped_ptr<CriticalSectionWrapper> receive_cs_;
stefan@webrtc.orgeb24b042014-10-14 11:40:13 +0000108 Clock* clock_;
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000109 rtc::scoped_ptr<RtpHeaderParser> rtp_header_parser_;
110 rtc::scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
111 rtc::scoped_ptr<RtpReceiver> rtp_receiver_;
Peter Boströmd6f1a382015-07-14 16:08:02 +0200112 const rtc::scoped_ptr<ReceiveStatistics> rtp_receive_statistics_;
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000113 rtc::scoped_ptr<FecReceiver> fec_receiver_;
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000114 RtpRtcp* rtp_rtcp_;
Peter Boströmd6f1a382015-07-14 16:08:02 +0200115 std::vector<RtpRtcp*> rtp_rtcp_simulcast_;
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000116 VideoCodingModule* vcm_;
stefan@webrtc.org976a7e62012-09-21 13:20:21 +0000117 RemoteBitrateEstimator* remote_bitrate_estimator_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000118
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000119 rtc::scoped_ptr<RemoteNtpTimeEstimator> ntp_estimator_;
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000120
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000121 bool receiving_;
mflodmanc4a1c372015-11-06 04:33:51 -0800122 uint8_t restored_packet_[IP_PACKET_SIZE];
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000123 bool restored_packet_in_use_;
solenberg@webrtc.org3fb8f7b2014-03-24 20:28:11 +0000124 bool receiving_ast_enabled_;
guoweis@webrtc.orgfdd10572015-03-12 20:50:57 +0000125 bool receiving_cvo_enabled_;
sprang867fb522015-08-03 04:38:41 -0700126 bool receiving_tsn_enabled_;
stefan@webrtc.orgeb24b042014-10-14 11:40:13 +0000127 int64_t last_packet_log_ms_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000128};
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000129
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100130} // namespace webrtc
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000131
mflodman@webrtc.orge06ca3c2012-06-29 13:20:14 +0000132#endif // WEBRTC_VIDEO_ENGINE_VIE_RECEIVER_H_