blob: 781f14f3c60931f5a562003fe7684f2d3a108f68 [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ömd6f1a382015-07-14 16:08:02 +020061 void RegisterRtpRtcpModules(const std::vector<RtpRtcp*>& rtp_modules);
Peter Boström6cff9cf2015-04-21 13:47:17 +020062
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);
sprang867fb522015-08-03 04:38:41 -070066 bool SetReceiveTransportSequenceNumber(bool enable, int id);
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000067
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000068 void StartReceive();
69 void StopReceive();
niklase@google.com470e71d2011-07-07 08:21:25 +000070
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000071 // Receives packets from external transport.
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000072 int ReceivedRTPPacket(const void* rtp_packet, size_t rtp_packet_length,
wu@webrtc.orga9890802013-12-13 00:21:03 +000073 const PacketTime& packet_time);
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000074 int ReceivedRTCPPacket(const void* rtcp_packet, size_t rtcp_packet_length);
niklase@google.com470e71d2011-07-07 08:21:25 +000075
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000076 // Implements RtpData.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000077 int32_t OnReceivedPayloadData(const uint8_t* payload_data,
78 const size_t payload_size,
79 const WebRtcRTPHeader* rtp_header) override;
80 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000081
wu@webrtc.org822fbd82013-08-15 23:38:54 +000082 ReceiveStatistics* GetReceiveStatistics() const;
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000083 private:
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000084 int InsertRTPPacket(const uint8_t* rtp_packet, size_t rtp_packet_length,
wu@webrtc.orga9890802013-12-13 00:21:03 +000085 const PacketTime& packet_time);
sprang@webrtc.org0e932572014-01-23 10:00:39 +000086 bool ReceivePacket(const uint8_t* packet,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000087 size_t packet_length,
sprang@webrtc.org0e932572014-01-23 10:00:39 +000088 const RTPHeader& header,
89 bool in_order);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000090 // Parses and handles for instance RTX and RED headers.
91 // This function assumes that it's being called from only one thread.
92 bool ParseAndHandleEncapsulatingHeader(const uint8_t* packet,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000093 size_t packet_length,
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000094 const RTPHeader& header);
asapersson@webrtc.org37c05592015-01-28 13:58:27 +000095 void NotifyReceiverOfFecPacket(const RTPHeader& header);
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000096 int InsertRTCPPacket(const uint8_t* rtcp_packet, size_t rtcp_packet_length);
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
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000101 rtc::scoped_ptr<CriticalSectionWrapper> receive_cs_;
stefan@webrtc.orgeb24b042014-10-14 11:40:13 +0000102 Clock* clock_;
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000103 rtc::scoped_ptr<RtpHeaderParser> rtp_header_parser_;
104 rtc::scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
105 rtc::scoped_ptr<RtpReceiver> rtp_receiver_;
Peter Boströmd6f1a382015-07-14 16:08:02 +0200106 const rtc::scoped_ptr<ReceiveStatistics> rtp_receive_statistics_;
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000107 rtc::scoped_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
kwiberg@webrtc.org00b8f6b2015-02-26 14:34:55 +0000113 rtc::scoped_ptr<RemoteNtpTimeEstimator> ntp_estimator_;
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000114
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000115 bool receiving_;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000116 uint8_t restored_packet_[kViEMaxMtu];
117 bool restored_packet_in_use_;
solenberg@webrtc.org3fb8f7b2014-03-24 20:28:11 +0000118 bool receiving_ast_enabled_;
guoweis@webrtc.orgfdd10572015-03-12 20:50:57 +0000119 bool receiving_cvo_enabled_;
sprang867fb522015-08-03 04:38:41 -0700120 bool receiving_tsn_enabled_;
stefan@webrtc.orgeb24b042014-10-14 11:40:13 +0000121 int64_t last_packet_log_ms_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000122};
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000123
124} // namespace webrt
125
mflodman@webrtc.orge06ca3c2012-06-29 13:20:14 +0000126#endif // WEBRTC_VIDEO_ENGINE_VIE_RECEIVER_H_