blob: 39a85e4c2b8d920f734c188aca35cada3bca2b33 [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
pwestin@webrtc.org82dcc9f2013-04-02 20:37:14 +000016#include "webrtc/engine_configurations.h"
wu@webrtc.org822fbd82013-08-15 23:38:54 +000017#include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h"
pwestin@webrtc.org82dcc9f2013-04-02 20:37:14 +000018#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.orga9890802013-12-13 00:21:03 +000021#include "webrtc/video_engine/include/vie_network.h"
pwestin@webrtc.org82dcc9f2013-04-02 20:37:14 +000022#include "webrtc/video_engine/vie_defines.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000023
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000024namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000025
niklase@google.com470e71d2011-07-07 08:21:25 +000026class CriticalSectionWrapper;
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;
niklase@google.com470e71d2011-07-07 08:21:25 +000031class RtpDump;
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000032class RtpHeaderParser;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000033class RTPPayloadRegistry;
34class RtpReceiver;
niklase@google.com470e71d2011-07-07 08:21:25 +000035class RtpRtcp;
36class VideoCodingModule;
jiayl@webrtc.org1f64f062014-02-10 19:12:14 +000037struct ReceiveBandwidthEstimatorStats;
niklase@google.com470e71d2011-07-07 08:21:25 +000038
pwestin@webrtc.org82dcc9f2013-04-02 20:37:14 +000039class ViEReceiver : public RtpData {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000040 public:
stefan@webrtc.org976a7e62012-09-21 13:20:21 +000041 ViEReceiver(const int32_t channel_id, VideoCodingModule* module_vcm,
wu@webrtc.org822fbd82013-08-15 23:38:54 +000042 RemoteBitrateEstimator* remote_bitrate_estimator,
43 RtpFeedback* rtp_feedback);
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000044 ~ViEReceiver();
niklase@google.com470e71d2011-07-07 08:21:25 +000045
wu@webrtc.org822fbd82013-08-15 23:38:54 +000046 bool SetReceiveCodec(const VideoCodec& video_codec);
47 bool RegisterPayload(const VideoCodec& video_codec);
48
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000049 void SetNackStatus(bool enable, int max_nack_reordering_threshold);
stefan@webrtc.orgef927552014-06-05 08:25:29 +000050 void SetRtxPayloadType(int payload_type);
51 void SetRtxSsrc(uint32_t ssrc);
asapersson@webrtc.orgd952c402014-11-27 07:38:56 +000052 bool GetRtxSsrc(uint32_t* ssrc) const;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000053
54 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
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000061 void RegisterSimulcastRtpRtcpModules(const std::list<RtpRtcp*>& rtp_modules);
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +000062
stefan@webrtc.org08994cc2013-05-29 13:28:21 +000063 bool SetReceiveTimestampOffsetStatus(bool enable, int id);
64 bool SetReceiveAbsoluteSendTimeStatus(bool enable, int id);
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000065
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000066 void StartReceive();
67 void StopReceive();
niklase@google.com470e71d2011-07-07 08:21:25 +000068
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000069 int StartRTPDump(const char file_nameUTF8[1024]);
70 int StopRTPDump();
niklase@google.com470e71d2011-07-07 08:21:25 +000071
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000072 // Receives packets from external transport.
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000073 int ReceivedRTPPacket(const void* rtp_packet, size_t rtp_packet_length,
wu@webrtc.orga9890802013-12-13 00:21:03 +000074 const PacketTime& packet_time);
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000075 int ReceivedRTCPPacket(const void* rtcp_packet, size_t rtcp_packet_length);
niklase@google.com470e71d2011-07-07 08:21:25 +000076
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000077 // Implements RtpData.
pbos@webrtc.orgb238d122013-04-09 13:41:51 +000078 virtual int32_t OnReceivedPayloadData(
79 const uint8_t* payload_data,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000080 const size_t payload_size,
stefan@webrtc.org6071b062014-09-12 07:42:33 +000081 const WebRtcRTPHeader* rtp_header) OVERRIDE;
82 virtual bool OnRecoveredPacket(const uint8_t* packet,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000083 size_t packet_length) OVERRIDE;
niklase@google.com470e71d2011-07-07 08:21:25 +000084
jiayl@webrtc.org1f64f062014-02-10 19:12:14 +000085 void GetReceiveBandwidthEstimatorStats(
86 ReceiveBandwidthEstimatorStats* output) const;
87
wu@webrtc.org822fbd82013-08-15 23:38:54 +000088 ReceiveStatistics* GetReceiveStatistics() const;
89
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000090 void ReceivedBWEPacket(int64_t arrival_time_ms, size_t payload_size,
solenberg@webrtc.org3fb8f7b2014-03-24 20:28:11 +000091 const RTPHeader& header);
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000092 private:
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000093 int InsertRTPPacket(const uint8_t* rtp_packet, size_t rtp_packet_length,
wu@webrtc.orga9890802013-12-13 00:21:03 +000094 const PacketTime& packet_time);
sprang@webrtc.org0e932572014-01-23 10:00:39 +000095 bool ReceivePacket(const uint8_t* packet,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +000096 size_t packet_length,
sprang@webrtc.org0e932572014-01-23 10:00:39 +000097 const RTPHeader& header,
98 bool in_order);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000099 // Parses and handles for instance RTX and RED headers.
100 // This function assumes that it's being called from only one thread.
101 bool ParseAndHandleEncapsulatingHeader(const uint8_t* packet,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000102 size_t packet_length,
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000103 const RTPHeader& header);
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000104 int InsertRTCPPacket(const uint8_t* rtcp_packet, size_t rtcp_packet_length);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000105 bool IsPacketInOrder(const RTPHeader& header) const;
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000106 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000107
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000108 scoped_ptr<CriticalSectionWrapper> receive_cs_;
stefan@webrtc.orgeb24b042014-10-14 11:40:13 +0000109 Clock* clock_;
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000110 scoped_ptr<RtpHeaderParser> rtp_header_parser_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000111 scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
112 scoped_ptr<RtpReceiver> rtp_receiver_;
113 scoped_ptr<ReceiveStatistics> rtp_receive_statistics_;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000114 scoped_ptr<FecReceiver> fec_receiver_;
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000115 RtpRtcp* rtp_rtcp_;
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000116 std::list<RtpRtcp*> rtp_rtcp_simulcast_;
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000117 VideoCodingModule* vcm_;
stefan@webrtc.org976a7e62012-09-21 13:20:21 +0000118 RemoteBitrateEstimator* remote_bitrate_estimator_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000119
wu@webrtc.org88abf112014-05-14 16:53:51 +0000120 scoped_ptr<RemoteNtpTimeEstimator> ntp_estimator_;
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000121
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000122 RtpDump* rtp_dump_;
123 bool receiving_;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000124 uint8_t restored_packet_[kViEMaxMtu];
125 bool restored_packet_in_use_;
solenberg@webrtc.org3fb8f7b2014-03-24 20:28:11 +0000126 bool receiving_ast_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
130} // namespace webrt
131
mflodman@webrtc.orge06ca3c2012-06-29 13:20:14 +0000132#endif // WEBRTC_VIDEO_ENGINE_VIE_RECEIVER_H_