blob: 0501ec31af5ef51633815323cf9d82a849d9ddcb [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
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000011#include "webrtc/video_engine/vie_receiver.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
mflodman@webrtc.org4fd55272013-02-06 17:46:39 +000013#include <vector>
14
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000015#include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000016#include "webrtc/modules/rtp_rtcp/interface/fec_receiver.h"
wu@webrtc.org822fbd82013-08-15 23:38:54 +000017#include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h"
wu@webrtc.org88abf112014-05-14 16:53:51 +000018#include "webrtc/modules/rtp_rtcp/interface/remote_ntp_time_estimator.h"
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000019#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
wu@webrtc.org822fbd82013-08-15 23:38:54 +000020#include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h"
21#include "webrtc/modules/rtp_rtcp/interface/rtp_receiver.h"
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000022#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
23#include "webrtc/modules/utility/interface/rtp_dump.h"
24#include "webrtc/modules/video_coding/main/interface/video_coding.h"
25#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
wu@webrtc.orgcd701192014-04-24 22:10:24 +000026#include "webrtc/system_wrappers/interface/logging.h"
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000027#include "webrtc/system_wrappers/interface/tick_util.h"
wu@webrtc.org66773a02014-05-07 17:09:44 +000028#include "webrtc/system_wrappers/interface/timestamp_extrapolator.h"
wu@webrtc.org88abf112014-05-14 16:53:51 +000029#include "webrtc/system_wrappers/interface/trace.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000030
31namespace webrtc {
32
stefan@webrtc.orgeb24b042014-10-14 11:40:13 +000033static const int kPacketLogIntervalMs = 10000;
34
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +000035ViEReceiver::ViEReceiver(const int32_t channel_id,
stefan@webrtc.org976a7e62012-09-21 13:20:21 +000036 VideoCodingModule* module_vcm,
wu@webrtc.org822fbd82013-08-15 23:38:54 +000037 RemoteBitrateEstimator* remote_bitrate_estimator,
38 RtpFeedback* rtp_feedback)
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +000039 : receive_cs_(CriticalSectionWrapper::CreateCriticalSection()),
stefan@webrtc.orgeb24b042014-10-14 11:40:13 +000040 clock_(Clock::GetRealTimeClock()),
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000041 rtp_header_parser_(RtpHeaderParser::Create()),
stefan@webrtc.orgeb24b042014-10-14 11:40:13 +000042 rtp_payload_registry_(
43 new RTPPayloadRegistry(RTPPayloadStrategy::CreateStrategy(false))),
44 rtp_receiver_(
45 RtpReceiver::CreateVideoReceiver(channel_id,
46 clock_,
47 this,
48 rtp_feedback,
49 rtp_payload_registry_.get())),
50 rtp_receive_statistics_(ReceiveStatistics::Create(clock_)),
andresp@webrtc.orgdc80bae2014-04-08 11:06:12 +000051 fec_receiver_(FecReceiver::Create(this)),
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +000052 rtp_rtcp_(NULL),
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000053 vcm_(module_vcm),
stefan@webrtc.org976a7e62012-09-21 13:20:21 +000054 remote_bitrate_estimator_(remote_bitrate_estimator),
stefan@webrtc.orgeb24b042014-10-14 11:40:13 +000055 ntp_estimator_(new RemoteNtpTimeEstimator(clock_)),
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000056 rtp_dump_(NULL),
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000057 receiving_(false),
solenberg@webrtc.org3fb8f7b2014-03-24 20:28:11 +000058 restored_packet_in_use_(false),
stefan@webrtc.orgeb24b042014-10-14 11:40:13 +000059 receiving_ast_enabled_(false),
60 last_packet_log_ms_(-1) {
stefan@webrtc.org976a7e62012-09-21 13:20:21 +000061 assert(remote_bitrate_estimator);
niklase@google.com470e71d2011-07-07 08:21:25 +000062}
63
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000064ViEReceiver::~ViEReceiver() {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000065 if (rtp_dump_) {
66 rtp_dump_->Stop();
67 RtpDump::DestroyRtpDump(rtp_dump_);
68 rtp_dump_ = NULL;
69 }
niklase@google.com470e71d2011-07-07 08:21:25 +000070}
71
wu@webrtc.org822fbd82013-08-15 23:38:54 +000072bool ViEReceiver::SetReceiveCodec(const VideoCodec& video_codec) {
73 int8_t old_pltype = -1;
74 if (rtp_payload_registry_->ReceivePayloadType(video_codec.plName,
75 kVideoPayloadTypeFrequency,
76 0,
77 video_codec.maxBitrate,
78 &old_pltype) != -1) {
79 rtp_payload_registry_->DeRegisterReceivePayload(old_pltype);
80 }
81
82 return RegisterPayload(video_codec);
83}
84
85bool ViEReceiver::RegisterPayload(const VideoCodec& video_codec) {
86 return rtp_receiver_->RegisterReceivePayload(video_codec.plName,
87 video_codec.plType,
88 kVideoPayloadTypeFrequency,
89 0,
90 video_codec.maxBitrate) == 0;
91}
92
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000093void ViEReceiver::SetNackStatus(bool enable,
wu@webrtc.org822fbd82013-08-15 23:38:54 +000094 int max_nack_reordering_threshold) {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000095 if (!enable) {
96 // Reset the threshold back to the lower default threshold when NACK is
97 // disabled since we no longer will be receiving retransmissions.
98 max_nack_reordering_threshold = kDefaultMaxReorderingThreshold;
99 }
100 rtp_receive_statistics_->SetMaxReorderingThreshold(
101 max_nack_reordering_threshold);
102 rtp_receiver_->SetNACKStatus(enable ? kNackRtcp : kNackOff);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000103}
104
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000105void ViEReceiver::SetRtxPayloadType(int payload_type) {
106 rtp_payload_registry_->SetRtxPayloadType(payload_type);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000107}
108
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000109void ViEReceiver::SetRtxSsrc(uint32_t ssrc) {
110 rtp_payload_registry_->SetRtxSsrc(ssrc);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000111}
112
113uint32_t ViEReceiver::GetRemoteSsrc() const {
114 return rtp_receiver_->SSRC();
115}
116
117int ViEReceiver::GetCsrcs(uint32_t* csrcs) const {
118 return rtp_receiver_->CSRCs(csrcs);
119}
120
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000121void ViEReceiver::SetRtpRtcpModule(RtpRtcp* module) {
122 rtp_rtcp_ = module;
123}
124
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000125RtpReceiver* ViEReceiver::GetRtpReceiver() const {
126 return rtp_receiver_.get();
127}
128
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000129void ViEReceiver::RegisterSimulcastRtpRtcpModules(
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000130 const std::list<RtpRtcp*>& rtp_modules) {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000131 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000132 rtp_rtcp_simulcast_.clear();
133
134 if (!rtp_modules.empty()) {
135 rtp_rtcp_simulcast_.insert(rtp_rtcp_simulcast_.begin(),
136 rtp_modules.begin(),
137 rtp_modules.end());
138 }
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000139}
140
stefan@webrtc.org08994cc2013-05-29 13:28:21 +0000141bool ViEReceiver::SetReceiveTimestampOffsetStatus(bool enable, int id) {
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000142 if (enable) {
143 return rtp_header_parser_->RegisterRtpHeaderExtension(
144 kRtpExtensionTransmissionTimeOffset, id);
145 } else {
146 return rtp_header_parser_->DeregisterRtpHeaderExtension(
147 kRtpExtensionTransmissionTimeOffset);
148 }
149}
150
stefan@webrtc.org08994cc2013-05-29 13:28:21 +0000151bool ViEReceiver::SetReceiveAbsoluteSendTimeStatus(bool enable, int id) {
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000152 if (enable) {
solenberg@webrtc.org3fb8f7b2014-03-24 20:28:11 +0000153 if (rtp_header_parser_->RegisterRtpHeaderExtension(
154 kRtpExtensionAbsoluteSendTime, id)) {
155 receiving_ast_enabled_ = true;
156 return true;
157 } else {
158 return false;
159 }
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000160 } else {
solenberg@webrtc.org3fb8f7b2014-03-24 20:28:11 +0000161 receiving_ast_enabled_ = false;
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000162 return rtp_header_parser_->DeregisterRtpHeaderExtension(
163 kRtpExtensionAbsoluteSendTime);
164 }
165}
166
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000167int ViEReceiver::ReceivedRTPPacket(const void* rtp_packet,
wu@webrtc.orga9890802013-12-13 00:21:03 +0000168 int rtp_packet_length,
169 const PacketTime& packet_time) {
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000170 return InsertRTPPacket(static_cast<const uint8_t*>(rtp_packet),
wu@webrtc.orga9890802013-12-13 00:21:03 +0000171 rtp_packet_length, packet_time);
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000172}
173
174int ViEReceiver::ReceivedRTCPPacket(const void* rtcp_packet,
175 int rtcp_packet_length) {
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000176 return InsertRTCPPacket(static_cast<const uint8_t*>(rtcp_packet),
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000177 rtcp_packet_length);
178}
179
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000180int32_t ViEReceiver::OnReceivedPayloadData(
181 const uint8_t* payload_data, const uint16_t payload_size,
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000182 const WebRtcRTPHeader* rtp_header) {
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000183 WebRtcRTPHeader rtp_header_with_ntp = *rtp_header;
wu@webrtc.org88abf112014-05-14 16:53:51 +0000184 rtp_header_with_ntp.ntp_time_ms =
185 ntp_estimator_->Estimate(rtp_header->header.timestamp);
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000186 if (vcm_->IncomingPacket(payload_data,
187 payload_size,
188 rtp_header_with_ntp) != 0) {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000189 // Check this...
190 return -1;
191 }
192 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000193}
194
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000195bool ViEReceiver::OnRecoveredPacket(const uint8_t* rtp_packet,
196 int rtp_packet_length) {
197 RTPHeader header;
198 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length, &header)) {
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000199 return false;
200 }
201 header.payload_type_frequency = kVideoPayloadTypeFrequency;
stefan@webrtc.org01581da2014-09-04 06:48:14 +0000202 bool in_order = IsPacketInOrder(header);
203 return ReceivePacket(rtp_packet, rtp_packet_length, header, in_order);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000204}
205
solenberg@webrtc.org3fb8f7b2014-03-24 20:28:11 +0000206void ViEReceiver::ReceivedBWEPacket(
207 int64_t arrival_time_ms, int payload_size, const RTPHeader& header) {
208 // Only forward if the incoming packet *and* the channel are both configured
209 // to receive absolute sender time. RTP time stamps may have different rates
210 // for audio and video and shouldn't be mixed.
211 if (header.extension.hasAbsoluteSendTime && receiving_ast_enabled_) {
212 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size,
213 header);
214 }
215}
216
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000217int ViEReceiver::InsertRTPPacket(const uint8_t* rtp_packet,
wu@webrtc.orga9890802013-12-13 00:21:03 +0000218 int rtp_packet_length,
219 const PacketTime& packet_time) {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000220 {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000221 CriticalSectionScoped cs(receive_cs_.get());
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000222 if (!receiving_) {
223 return -1;
224 }
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000225 if (rtp_dump_) {
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000226 rtp_dump_->DumpPacket(rtp_packet,
227 static_cast<uint16_t>(rtp_packet_length));
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000228 }
229 }
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000230
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000231 RTPHeader header;
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000232 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length,
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000233 &header)) {
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000234 return -1;
235 }
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000236 int payload_length = rtp_packet_length - header.headerLength;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000237 int64_t arrival_time_ms;
stefan@webrtc.orgeb24b042014-10-14 11:40:13 +0000238 int64_t now_ms = clock_->TimeInMilliseconds();
wu@webrtc.orga9890802013-12-13 00:21:03 +0000239 if (packet_time.timestamp != -1)
240 arrival_time_ms = (packet_time.timestamp + 500) / 1000;
241 else
stefan@webrtc.orgeb24b042014-10-14 11:40:13 +0000242 arrival_time_ms = now_ms;
243
244 {
245 // Periodically log the RTP header of incoming packets.
246 CriticalSectionScoped cs(receive_cs_.get());
247 if (now_ms - last_packet_log_ms_ > kPacketLogIntervalMs) {
248 std::stringstream ss;
249 ss << "Packet received on SSRC: " << header.ssrc << " with payload type: "
250 << static_cast<int>(header.payloadType) << ", timestamp: "
251 << header.timestamp << ", sequence number: " << header.sequenceNumber
252 << ", arrival time: " << arrival_time_ms;
253 if (header.extension.hasTransmissionTimeOffset)
254 ss << ", toffset: " << header.extension.transmissionTimeOffset;
255 if (header.extension.hasAbsoluteSendTime)
256 ss << ", abs send time: " << header.extension.absoluteSendTime;
257 LOG(LS_INFO) << ss.str();
258 last_packet_log_ms_ = now_ms;
259 }
260 }
wu@webrtc.orga9890802013-12-13 00:21:03 +0000261
262 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms,
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000263 payload_length, header);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000264 header.payload_type_frequency = kVideoPayloadTypeFrequency;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000265
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000266 bool in_order = IsPacketInOrder(header);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000267 rtp_payload_registry_->SetIncomingPayloadType(header);
asapersson@webrtc.org1457b472014-05-26 13:06:04 +0000268 int ret = ReceivePacket(rtp_packet, rtp_packet_length, header, in_order)
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000269 ? 0
270 : -1;
asapersson@webrtc.org1457b472014-05-26 13:06:04 +0000271 // Update receive statistics after ReceivePacket.
272 // Receive statistics will be reset if the payload type changes (make sure
273 // that the first packet is included in the stats).
274 rtp_receive_statistics_->IncomingPacket(
275 header, rtp_packet_length, IsPacketRetransmitted(header, in_order));
276 return ret;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000277}
278
279bool ViEReceiver::ReceivePacket(const uint8_t* packet,
280 int packet_length,
281 const RTPHeader& header,
282 bool in_order) {
283 if (rtp_payload_registry_->IsEncapsulated(header)) {
284 return ParseAndHandleEncapsulatingHeader(packet, packet_length, header);
285 }
286 const uint8_t* payload = packet + header.headerLength;
287 int payload_length = packet_length - header.headerLength;
288 assert(payload_length >= 0);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000289 PayloadUnion payload_specific;
290 if (!rtp_payload_registry_->GetPayloadSpecifics(header.payloadType,
291 &payload_specific)) {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000292 return false;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000293 }
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000294 return rtp_receiver_->IncomingRtpPacket(header, payload, payload_length,
295 payload_specific, in_order);
296}
297
298bool ViEReceiver::ParseAndHandleEncapsulatingHeader(const uint8_t* packet,
299 int packet_length,
300 const RTPHeader& header) {
301 if (rtp_payload_registry_->IsRed(header)) {
sprang@webrtc.org0e932572014-01-23 10:00:39 +0000302 int8_t ulpfec_pt = rtp_payload_registry_->ulpfec_payload_type();
303 if (packet[header.headerLength] == ulpfec_pt)
304 rtp_receive_statistics_->FecPacketReceived(header.ssrc);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000305 if (fec_receiver_->AddReceivedRedPacket(
sprang@webrtc.org0e932572014-01-23 10:00:39 +0000306 header, packet, packet_length, ulpfec_pt) != 0) {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000307 return false;
308 }
309 return fec_receiver_->ProcessReceivedFec() == 0;
310 } else if (rtp_payload_registry_->IsRtx(header)) {
stefan@webrtc.org7c6ff2d2014-03-19 18:14:52 +0000311 if (header.headerLength + header.paddingLength == packet_length) {
312 // This is an empty packet and should be silently dropped before trying to
313 // parse the RTX header.
314 return true;
315 }
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000316 // Remove the RTX header and parse the original RTP header.
317 if (packet_length < header.headerLength)
318 return false;
319 if (packet_length > static_cast<int>(sizeof(restored_packet_)))
320 return false;
321 CriticalSectionScoped cs(receive_cs_.get());
322 if (restored_packet_in_use_) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +0000323 LOG(LS_WARNING) << "Multiple RTX headers detected, dropping packet.";
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000324 return false;
325 }
326 uint8_t* restored_packet_ptr = restored_packet_;
327 if (!rtp_payload_registry_->RestoreOriginalPacket(
328 &restored_packet_ptr, packet, &packet_length, rtp_receiver_->SSRC(),
329 header)) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +0000330 LOG(LS_WARNING) << "Incoming RTX packet: Invalid RTP header";
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000331 return false;
332 }
333 restored_packet_in_use_ = true;
334 bool ret = OnRecoveredPacket(restored_packet_ptr, packet_length);
335 restored_packet_in_use_ = false;
336 return ret;
337 }
338 return false;
niklase@google.com470e71d2011-07-07 08:21:25 +0000339}
340
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000341int ViEReceiver::InsertRTCPPacket(const uint8_t* rtcp_packet,
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000342 int rtcp_packet_length) {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000343 {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000344 CriticalSectionScoped cs(receive_cs_.get());
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000345 if (!receiving_) {
346 return -1;
347 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000348
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000349 if (rtp_dump_) {
350 rtp_dump_->DumpPacket(
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000351 rtcp_packet, static_cast<uint16_t>(rtcp_packet_length));
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000352 }
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000353
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000354 std::list<RtpRtcp*>::iterator it = rtp_rtcp_simulcast_.begin();
355 while (it != rtp_rtcp_simulcast_.end()) {
356 RtpRtcp* rtp_rtcp = *it++;
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000357 rtp_rtcp->IncomingRtcpPacket(rtcp_packet, rtcp_packet_length);
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000358 }
359 }
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000360 assert(rtp_rtcp_); // Should be set by owner at construction time.
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000361 int ret = rtp_rtcp_->IncomingRtcpPacket(rtcp_packet, rtcp_packet_length);
362 if (ret != 0) {
363 return ret;
364 }
365
minyue@webrtc.org2c0cdbc2014-10-09 10:52:43 +0000366 uint16_t rtt = 0;
367 rtp_rtcp_->RTT(rtp_receiver_->SSRC(), &rtt, NULL, NULL, NULL);
368 if (rtt == 0) {
369 // Waiting for valid rtt.
370 return 0;
371 }
372 uint32_t ntp_secs = 0;
373 uint32_t ntp_frac = 0;
374 uint32_t rtp_timestamp = 0;
375 if (0 != rtp_rtcp_->RemoteNTP(&ntp_secs, &ntp_frac, NULL, NULL,
376 &rtp_timestamp)) {
377 // Waiting for RTCP.
378 return 0;
379 }
380 ntp_estimator_->UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp);
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000381
382 return 0;
383}
384
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000385void ViEReceiver::StartReceive() {
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000386 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000387 receiving_ = true;
388}
389
390void ViEReceiver::StopReceive() {
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000391 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000392 receiving_ = false;
393}
394
395int ViEReceiver::StartRTPDump(const char file_nameUTF8[1024]) {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000396 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000397 if (rtp_dump_) {
398 // Restart it if it already exists and is started
399 rtp_dump_->Stop();
400 } else {
401 rtp_dump_ = RtpDump::CreateRtpDump();
402 if (rtp_dump_ == NULL) {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000403 return -1;
404 }
405 }
406 if (rtp_dump_->Start(file_nameUTF8) != 0) {
407 RtpDump::DestroyRtpDump(rtp_dump_);
408 rtp_dump_ = NULL;
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000409 return -1;
410 }
411 return 0;
412}
413
414int ViEReceiver::StopRTPDump() {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000415 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000416 if (rtp_dump_) {
417 if (rtp_dump_->IsActive()) {
418 rtp_dump_->Stop();
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000419 }
420 RtpDump::DestroyRtpDump(rtp_dump_);
421 rtp_dump_ = NULL;
422 } else {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000423 return -1;
424 }
425 return 0;
426}
427
jiayl@webrtc.org1f64f062014-02-10 19:12:14 +0000428void ViEReceiver::GetReceiveBandwidthEstimatorStats(
429 ReceiveBandwidthEstimatorStats* output) const {
430 remote_bitrate_estimator_->GetStats(output);
431}
432
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000433ReceiveStatistics* ViEReceiver::GetReceiveStatistics() const {
434 return rtp_receive_statistics_.get();
435}
436
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000437bool ViEReceiver::IsPacketInOrder(const RTPHeader& header) const {
438 StreamStatistician* statistician =
439 rtp_receive_statistics_->GetStatistician(header.ssrc);
440 if (!statistician)
441 return false;
442 return statistician->IsPacketInOrder(header.sequenceNumber);
443}
444
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000445bool ViEReceiver::IsPacketRetransmitted(const RTPHeader& header,
446 bool in_order) const {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000447 // Retransmissions are handled separately if RTX is enabled.
448 if (rtp_payload_registry_->RtxEnabled())
449 return false;
450 StreamStatistician* statistician =
451 rtp_receive_statistics_->GetStatistician(header.ssrc);
452 if (!statistician)
453 return false;
454 // Check if this is a retransmission.
455 uint16_t min_rtt = 0;
456 rtp_rtcp_->RTT(rtp_receiver_->SSRC(), NULL, NULL, &min_rtt, NULL);
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000457 return !in_order &&
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000458 statistician->IsRetransmitOfOldPacket(header, min_rtt);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000459}
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000460} // namespace webrtc