blob: 611db40faaa7b842d00e86b1bed0c9fcce348ffd [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.org822fbd82013-08-15 23:38:54 +000028class ReceiveStatistics;
stefan@webrtc.org976a7e62012-09-21 13:20:21 +000029class RemoteBitrateEstimator;
niklase@google.com470e71d2011-07-07 08:21:25 +000030class RtpDump;
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;
jiayl@webrtc.org1f64f062014-02-10 19:12:14 +000036struct ReceiveBandwidthEstimatorStats;
niklase@google.com470e71d2011-07-07 08:21:25 +000037
pwestin@webrtc.org82dcc9f2013-04-02 20:37:14 +000038class ViEReceiver : public RtpData {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000039 public:
stefan@webrtc.org976a7e62012-09-21 13:20:21 +000040 ViEReceiver(const int32_t channel_id, VideoCodingModule* module_vcm,
wu@webrtc.org822fbd82013-08-15 23:38:54 +000041 RemoteBitrateEstimator* remote_bitrate_estimator,
42 RtpFeedback* rtp_feedback);
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000043 ~ViEReceiver();
niklase@google.com470e71d2011-07-07 08:21:25 +000044
wu@webrtc.org822fbd82013-08-15 23:38:54 +000045 bool SetReceiveCodec(const VideoCodec& video_codec);
46 bool RegisterPayload(const VideoCodec& video_codec);
47
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000048 void SetNackStatus(bool enable, int max_nack_reordering_threshold);
wu@webrtc.org822fbd82013-08-15 23:38:54 +000049 void SetRtxStatus(bool enable, uint32_t ssrc);
50 void SetRtxPayloadType(uint32_t payload_type);
51
52 uint32_t GetRemoteSsrc() const;
53 int GetCsrcs(uint32_t* csrcs) const;
54
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +000055 void SetRtpRtcpModule(RtpRtcp* module);
56
wu@webrtc.org822fbd82013-08-15 23:38:54 +000057 RtpReceiver* GetRtpReceiver() const;
58
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000059 void RegisterSimulcastRtpRtcpModules(const std::list<RtpRtcp*>& rtp_modules);
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +000060
stefan@webrtc.org08994cc2013-05-29 13:28:21 +000061 bool SetReceiveTimestampOffsetStatus(bool enable, int id);
62 bool SetReceiveAbsoluteSendTimeStatus(bool enable, int id);
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000063
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000064 void StartReceive();
65 void StopReceive();
niklase@google.com470e71d2011-07-07 08:21:25 +000066
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000067 int StartRTPDump(const char file_nameUTF8[1024]);
68 int StopRTPDump();
niklase@google.com470e71d2011-07-07 08:21:25 +000069
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000070 // Receives packets from external transport.
wu@webrtc.orga9890802013-12-13 00:21:03 +000071 int ReceivedRTPPacket(const void* rtp_packet, int rtp_packet_length,
72 const PacketTime& packet_time);
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000073 int ReceivedRTCPPacket(const void* rtcp_packet, int rtcp_packet_length);
wu@webrtc.org822fbd82013-08-15 23:38:54 +000074 virtual bool OnRecoveredPacket(const uint8_t* packet,
75 int packet_length) OVERRIDE;
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,
80 const uint16_t payload_size,
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000081 const WebRtcRTPHeader* rtp_header);
niklase@google.com470e71d2011-07-07 08:21:25 +000082
mflodman@webrtc.org4fd55272013-02-06 17:46:39 +000083 void EstimatedReceiveBandwidth(unsigned int* available_bandwidth) const;
stefan@webrtc.orgb5865072013-02-01 14:33:42 +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
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000090 private:
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +000091 int InsertRTPPacket(const uint8_t* rtp_packet, int rtp_packet_length,
wu@webrtc.orga9890802013-12-13 00:21:03 +000092 const PacketTime& packet_time);
sprang@webrtc.org0e932572014-01-23 10:00:39 +000093 bool ReceivePacket(const uint8_t* packet,
94 int packet_length,
95 const RTPHeader& header,
96 bool in_order);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000097 // Parses and handles for instance RTX and RED headers.
98 // This function assumes that it's being called from only one thread.
99 bool ParseAndHandleEncapsulatingHeader(const uint8_t* packet,
100 int packet_length,
101 const RTPHeader& header);
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000102 int InsertRTCPPacket(const uint8_t* rtcp_packet, int 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;
niklase@google.com470e71d2011-07-07 08:21:25 +0000105
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000106 scoped_ptr<CriticalSectionWrapper> receive_cs_;
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000107 const int32_t channel_id_;
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000108 scoped_ptr<RtpHeaderParser> rtp_header_parser_;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000109 scoped_ptr<RTPPayloadRegistry> rtp_payload_registry_;
110 scoped_ptr<RtpReceiver> rtp_receiver_;
111 scoped_ptr<ReceiveStatistics> rtp_receive_statistics_;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000112 scoped_ptr<FecReceiver> fec_receiver_;
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000113 RtpRtcp* rtp_rtcp_;
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000114 std::list<RtpRtcp*> rtp_rtcp_simulcast_;
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000115 VideoCodingModule* vcm_;
stefan@webrtc.org976a7e62012-09-21 13:20:21 +0000116 RemoteBitrateEstimator* remote_bitrate_estimator_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000117
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000118 RtpDump* rtp_dump_;
119 bool receiving_;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000120 uint8_t restored_packet_[kViEMaxMtu];
121 bool restored_packet_in_use_;
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_