blob: 4b176f8845c863aa143de886ca9b7fac1ae8eab3 [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
mflodmanfa666592016-04-28 23:15:33 -070011#ifndef WEBRTC_VIDEO_RTP_STREAM_RECEIVER_H_
12#define WEBRTC_VIDEO_RTP_STREAM_RECEIVER_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +000014#include <list>
kwiberg27f982b2016-03-01 11:52:33 -080015#include <memory>
Peter Boström9c017252016-02-26 16:26:20 +010016#include <string>
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +010017#include <vector>
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +000018
kwiberg4485ffb2016-04-26 08:14:39 -070019#include "webrtc/base/constructormagic.h"
Tommi97888bd2016-01-21 23:24:59 +010020#include "webrtc/base/criticalsection.h"
pwestin@webrtc.org82dcc9f2013-04-02 20:37:14 +000021#include "webrtc/engine_configurations.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010022#include "webrtc/modules/rtp_rtcp/include/receive_statistics.h"
Peter Boström4fa7eca2016-03-02 15:05:53 +010023#include "webrtc/modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
24#include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h"
mflodmanc0e58a32016-04-25 01:26:26 -070025#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
Henrik Kjellanderff761fb2015-11-04 08:31:52 +010026#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
mflodmancfc8e3b2016-05-03 21:22:04 -070027#include "webrtc/modules/video_coding/include/video_coding_defines.h"
pwestin@webrtc.org82dcc9f2013-04-02 20:37:14 +000028#include "webrtc/typedefs.h"
mflodmancfc8e3b2016-05-03 21:22:04 -070029#include "webrtc/video_receive_stream.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000030
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000031namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000032
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000033class FecReceiver;
mflodmanc0e58a32016-04-25 01:26:26 -070034class PacedSender;
35class PacketRouter;
mflodmandc7d0d22016-05-06 05:32:22 -070036class ProcessThread;
wu@webrtc.org88abf112014-05-14 16:53:51 +000037class RemoteNtpTimeEstimator;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000038class ReceiveStatistics;
mflodmancfc8e3b2016-05-03 21:22:04 -070039class ReceiveStatisticsProxy;
stefan@webrtc.org976a7e62012-09-21 13:20:21 +000040class RemoteBitrateEstimator;
mflodmanc0e58a32016-04-25 01:26:26 -070041class RtcpRttStats;
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000042class RtpHeaderParser;
wu@webrtc.org822fbd82013-08-15 23:38:54 +000043class RTPPayloadRegistry;
44class RtpReceiver;
mflodmanc0e58a32016-04-25 01:26:26 -070045class Transport;
mflodmandc7d0d22016-05-06 05:32:22 -070046class VieRemb;
Peter Boström0b250722016-04-22 18:23:15 +020047
48namespace vcm {
49class VideoReceiver;
50} // namespace vcm
niklase@google.com470e71d2011-07-07 08:21:25 +000051
mflodmancfc8e3b2016-05-03 21:22:04 -070052class RtpStreamReceiver : public RtpData, public RtpFeedback,
53 public VCMFrameTypeCallback,
54 public VCMPacketRequestCallback {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000055 public:
mflodmanfa666592016-04-28 23:15:33 -070056 RtpStreamReceiver(vcm::VideoReceiver* video_receiver,
57 RemoteBitrateEstimator* remote_bitrate_estimator,
58 Transport* transport,
59 RtcpRttStats* rtt_stats,
60 PacedSender* paced_sender,
mflodmancfc8e3b2016-05-03 21:22:04 -070061 PacketRouter* packet_router,
mflodmandc7d0d22016-05-06 05:32:22 -070062 VieRemb* remb,
mflodmancfc8e3b2016-05-03 21:22:04 -070063 const VideoReceiveStream::Config& config,
mflodmandc7d0d22016-05-06 05:32:22 -070064 ReceiveStatisticsProxy* receive_stats_proxy,
65 ProcessThread* process_thread);
mflodmanfa666592016-04-28 23:15:33 -070066 ~RtpStreamReceiver();
niklase@google.com470e71d2011-07-07 08:21:25 +000067
wu@webrtc.org822fbd82013-08-15 23:38:54 +000068 bool SetReceiveCodec(const VideoCodec& video_codec);
wu@webrtc.org822fbd82013-08-15 23:38:54 +000069
wu@webrtc.org822fbd82013-08-15 23:38:54 +000070 uint32_t GetRemoteSsrc() const;
71 int GetCsrcs(uint32_t* csrcs) const;
72
wu@webrtc.org822fbd82013-08-15 23:38:54 +000073 RtpReceiver* GetRtpReceiver() const;
mflodmanc0e58a32016-04-25 01:26:26 -070074 RtpRtcp* rtp_rtcp() const { return rtp_rtcp_.get(); }
wu@webrtc.org822fbd82013-08-15 23:38:54 +000075
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000076 void StartReceive();
77 void StopReceive();
niklase@google.com470e71d2011-07-07 08:21:25 +000078
Peter Boströmd1d66ba2016-02-08 14:07:14 +010079 bool DeliverRtp(const uint8_t* rtp_packet,
80 size_t rtp_packet_length,
81 const PacketTime& packet_time);
82 bool DeliverRtcp(const uint8_t* rtcp_packet, size_t rtcp_packet_length);
niklase@google.com470e71d2011-07-07 08:21:25 +000083
mflodmandc7d0d22016-05-06 05:32:22 -070084 void SignalNetworkState(NetworkState state);
85
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000086 // Implements RtpData.
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +000087 int32_t OnReceivedPayloadData(const uint8_t* payload_data,
88 const size_t payload_size,
89 const WebRtcRTPHeader* rtp_header) override;
90 bool OnRecoveredPacket(const uint8_t* packet, size_t packet_length) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000091
mflodmanfa666592016-04-28 23:15:33 -070092 // Implements RtpFeedback.
93 int32_t OnInitializeDecoder(const int8_t payload_type,
94 const char payload_name[RTP_PAYLOAD_NAME_SIZE],
95 const int frequency,
96 const size_t channels,
97 const uint32_t rate) override;
98 void OnIncomingSSRCChanged(const uint32_t ssrc) override;
99 void OnIncomingCSRCChanged(const uint32_t CSRC, const bool added) override {}
100
mflodmancfc8e3b2016-05-03 21:22:04 -0700101 // Implements VCMFrameTypeCallback.
102 int32_t RequestKeyFrame() override;
103 int32_t SliceLossIndicationRequest(const uint64_t picture_id) override;
104
mflodmandc7d0d22016-05-06 05:32:22 -0700105 bool IsFecEnabled() const;
106 bool IsRetransmissionsEnabled() const;
107 // Don't use, still experimental.
108 void RequestPacketRetransmit(const std::vector<uint16_t>& sequence_numbers);
109
mflodmancfc8e3b2016-05-03 21:22:04 -0700110 // Implements VCMPacketRequestCallback.
111 int32_t ResendPackets(const uint16_t* sequenceNumbers,
112 uint16_t length) override;
113
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000114 private:
sprang@webrtc.org0e932572014-01-23 10:00:39 +0000115 bool ReceivePacket(const uint8_t* packet,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000116 size_t packet_length,
sprang@webrtc.org0e932572014-01-23 10:00:39 +0000117 const RTPHeader& header,
118 bool in_order);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000119 // Parses and handles for instance RTX and RED headers.
120 // This function assumes that it's being called from only one thread.
121 bool ParseAndHandleEncapsulatingHeader(const uint8_t* packet,
pkasting@chromium.org4591fbd2014-11-20 22:28:14 +0000122 size_t packet_length,
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000123 const RTPHeader& header);
asapersson@webrtc.org37c05592015-01-28 13:58:27 +0000124 void NotifyReceiverOfFecPacket(const RTPHeader& header);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000125 bool IsPacketInOrder(const RTPHeader& header) const;
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000126 bool IsPacketRetransmitted(const RTPHeader& header, bool in_order) const;
asapersson@webrtc.org0800db72015-01-15 07:40:20 +0000127 void UpdateHistograms();
mflodmandc7d0d22016-05-06 05:32:22 -0700128 void EnableReceiveRtpHeaderExtension(const std::string& extension, int id);
niklase@google.com470e71d2011-07-07 08:21:25 +0000129
Peter Boström4fa7eca2016-03-02 15:05:53 +0100130 Clock* const clock_;
mflodmandc7d0d22016-05-06 05:32:22 -0700131 const VideoReceiveStream::Config config_;
Peter Boström0b250722016-04-22 18:23:15 +0200132 vcm::VideoReceiver* const video_receiver_;
Peter Boström4fa7eca2016-03-02 15:05:53 +0100133 RemoteBitrateEstimator* const remote_bitrate_estimator_;
mflodmanc0e58a32016-04-25 01:26:26 -0700134 PacketRouter* const packet_router_;
mflodmandc7d0d22016-05-06 05:32:22 -0700135 VieRemb* const remb_;
136 ProcessThread* const process_thread_;
Peter Boström4fa7eca2016-03-02 15:05:53 +0100137
138 RemoteNtpTimeEstimator ntp_estimator_;
139 RTPPayloadRegistry rtp_payload_registry_;
140
141 const std::unique_ptr<RtpHeaderParser> rtp_header_parser_;
142 const std::unique_ptr<RtpReceiver> rtp_receiver_;
kwiberg27f982b2016-03-01 11:52:33 -0800143 const std::unique_ptr<ReceiveStatistics> rtp_receive_statistics_;
144 std::unique_ptr<FecReceiver> fec_receiver_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000145
Peter Boström4fa7eca2016-03-02 15:05:53 +0100146 rtc::CriticalSection receive_cs_;
147 bool receiving_ GUARDED_BY(receive_cs_);
148 uint8_t restored_packet_[IP_PACKET_SIZE] GUARDED_BY(receive_cs_);
149 bool restored_packet_in_use_ GUARDED_BY(receive_cs_);
150 int64_t last_packet_log_ms_ GUARDED_BY(receive_cs_);
mflodmanc0e58a32016-04-25 01:26:26 -0700151
152 const std::unique_ptr<RtpRtcp> rtp_rtcp_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000153};
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000154
kjellander@webrtc.org0fcaf992015-11-26 15:24:52 +0100155} // namespace webrtc
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000156
mflodmanfa666592016-04-28 23:15:33 -0700157#endif // WEBRTC_VIDEO_RTP_STREAM_RECEIVER_H_