blob: 8c1506fca1c7e60630a363b09d3b2a1965ca50b3 [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>
15
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +000016#include "webrtc/base/scoped_ptr.h"
pwestin@webrtc.org82dcc9f2013-04-02 20:37:14 +000017#include "webrtc/engine_configurations.h"
wu@webrtc.org822fbd82013-08-15 23:38:54 +000018#include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h"
pwestin@webrtc.org82dcc9f2013-04-02 20:37:14 +000019#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
pwestin@webrtc.org82dcc9f2013-04-02 20:37:14 +000020#include "webrtc/typedefs.h"
21#include "webrtc/video_engine/vie_defines.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:
stefan@webrtc.org976a7e62012-09-21 13:20:21 +000039 ViEReceiver(const int32_t channel_id, 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);
stefan@webrtc.orgef927552014-06-05 08:25:29 +000049 void SetRtxSsrc(uint32_t ssrc);
asapersson@webrtc.orgd952c402014-11-27 07:38:56 +000050 bool GetRtxSsrc(uint32_t* ssrc) const;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000051
asapersson@webrtc.org273fbbb2015-01-27 12:17:29 +000052 bool IsFecEnabled() const;
53
wu@webrtc.org822fbd82013-08-15 23:38:54 +000054 uint32_t GetRemoteSsrc() const;
55 int GetCsrcs(uint32_t* csrcs) const;
56
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +000057 void SetRtpRtcpModule(RtpRtcp* module);
58
wu@webrtc.org822fbd82013-08-15 23:38:54 +000059 RtpReceiver* GetRtpReceiver() const;
60
Peter Boström6cff9cf2015-04-21 13:47:17 +020061 void RegisterSimulcastRtpRtcpModules(const std::list<RtpRtcp*>& rtp_modules);
62
stefan@webrtc.org08994cc2013-05-29 13:28:21 +000063 bool SetReceiveTimestampOffsetStatus(bool enable, int id);
64 bool SetReceiveAbsoluteSendTimeStatus(bool enable, int id);
guoweis@webrtc.orgfdd10572015-03-12 20:50:57 +000065 bool SetReceiveVideoRotationStatus(bool enable, int id);
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000066
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000067 void StartReceive();
68 void StopReceive();
niklase@google.com470e71d2011-07-07 08:21:25 +000069
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000070 // Receives packets from external transport.
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000071 int ReceivedRTPPacket(const void* rtp_packet, size_t rtp_packet_length,
wu@webrtc.orga9890802013-12-13 00:21:03 +000072 const PacketTime& packet_time);
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000073 int ReceivedRTCPPacket(const void* rtcp_packet, size_t rtcp_packet_length);
niklase@google.com470e71d2011-07-07 08:21:25 +000074
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000075 // Implements RtpData.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000076 int32_t OnReceivedPayloadData(const uint8_t* payload_data,
77 const size_t payload_size,
78 const WebRtcRTPHeader* rtp_header) override;
79 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000080
wu@webrtc.org822fbd82013-08-15 23:38:54 +000081 ReceiveStatistics* GetReceiveStatistics() const;
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000082 private:
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000083 int InsertRTPPacket(const uint8_t* rtp_packet, size_t rtp_packet_length,
wu@webrtc.orga9890802013-12-13 00:21:03 +000084 const PacketTime& packet_time);
sprang@webrtc.org0e932572014-01-23 10:00:39 +000085 bool ReceivePacket(const uint8_t* packet,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000086 size_t packet_length,
sprang@webrtc.org0e932572014-01-23 10:00:39 +000087 const RTPHeader& header,
88 bool in_order);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000089 // Parses and handles for instance RTX and RED headers.
90 // This function assumes that it's being called from only one thread.
91 bool ParseAndHandleEncapsulatingHeader(const uint8_t* packet,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000092 size_t packet_length,
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000093 const RTPHeader& header);
asapersson@webrtc.org37c05592015-01-28 13:58:27 +000094 void NotifyReceiverOfFecPacket(const RTPHeader& header);
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000095 int InsertRTCPPacket(const uint8_t* rtcp_packet, size_t rtcp_packet_length);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000096 bool IsPacketInOrder(const RTPHeader& header) const;
stefan@webrtc.org48df3812013-11-08 15:18:52 +000097 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
asapersson@webrtc.org0800db72015-01-15 07:40:20 +000098 void UpdateHistograms();
niklase@google.com470e71d2011-07-07 08:21:25 +000099
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000100 rtc::scoped_ptr<CriticalSectionWrapper> receive_cs_;
stefan@webrtc.orgeb24b042014-10-14 11:40:13 +0000101 Clock* clock_;
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000102 rtc::scoped_ptr<RtpHeaderParser> rtp_header_parser_;
103 rtc::scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
104 rtc::scoped_ptr<RtpReceiver> rtp_receiver_;
105 rtc::scoped_ptr<ReceiveStatistics> rtp_receive_statistics_;
106 rtc::scoped_ptr<FecReceiver> fec_receiver_;
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000107 RtpRtcp* rtp_rtcp_;
Peter Boström6cff9cf2015-04-21 13:47:17 +0200108 std::list<RtpRtcp*> rtp_rtcp_simulcast_;
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000109 VideoCodingModule* vcm_;
stefan@webrtc.org976a7e62012-09-21 13:20:21 +0000110 RemoteBitrateEstimator* remote_bitrate_estimator_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000111
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000112 rtc::scoped_ptr<RemoteNtpTimeEstimator> ntp_estimator_;
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000113
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000114 bool receiving_;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000115 uint8_t restored_packet_[kViEMaxMtu];
116 bool restored_packet_in_use_;
solenberg@webrtc.org3fb8f7b2014-03-24 20:28:11 +0000117 bool receiving_ast_enabled_;
guoweis@webrtc.orgfdd10572015-03-12 20:50:57 +0000118 bool receiving_cvo_enabled_;
stefan@webrtc.orgeb24b042014-10-14 11:40:13 +0000119 int64_t last_packet_log_ms_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000120};
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000121
122} // namespace webrt
123
mflodman@webrtc.orge06ca3c2012-06-29 13:20:14 +0000124#endif // WEBRTC_VIDEO_ENGINE_VIE_RECEIVER_H_