blob: 5d90ac678abe2b04fe742ae21447d875d705a92e [file] [log] [blame]
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +00001/*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
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.org281cff82013-05-17 13:44:48 +000011#include "webrtc/video_engine/vie_receiver.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000012
mflodman@webrtc.orgcd1ac8b2013-02-06 17:46:39 +000013#include <vector>
14
pbos@webrtc.org281cff82013-05-17 13:44:48 +000015#include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +000016#include "webrtc/modules/rtp_rtcp/interface/fec_receiver.h"
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +000017#include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h"
wu@webrtc.org2fae0d12014-05-14 16:53:51 +000018#include "webrtc/modules/rtp_rtcp/interface/remote_ntp_time_estimator.h"
stefan@webrtc.org6696fba2013-05-29 12:12:51 +000019#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
wu@webrtc.org7fc75bb2013-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.org281cff82013-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.org093fc0b2014-04-24 22:10:24 +000026#include "webrtc/system_wrappers/interface/logging.h"
pbos@webrtc.org281cff82013-05-17 13:44:48 +000027#include "webrtc/system_wrappers/interface/tick_util.h"
wu@webrtc.orgd2fb2592014-05-07 17:09:44 +000028#include "webrtc/system_wrappers/interface/timestamp_extrapolator.h"
wu@webrtc.org2fae0d12014-05-14 16:53:51 +000029#include "webrtc/system_wrappers/interface/trace.h"
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000030
31namespace webrtc {
32
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000033ViEReceiver::ViEReceiver(const int32_t channel_id,
34 VideoCodingModule* module_vcm,
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +000035 RemoteBitrateEstimator* remote_bitrate_estimator,
36 RtpFeedback* rtp_feedback)
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000037 : receive_cs_(CriticalSectionWrapper::CreateCriticalSection()),
stefan@webrtc.org6696fba2013-05-29 12:12:51 +000038 rtp_header_parser_(RtpHeaderParser::Create()),
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +000039 rtp_payload_registry_(new RTPPayloadRegistry(
andresp@webrtc.org99681312014-04-08 11:06:12 +000040 RTPPayloadStrategy::CreateStrategy(false))),
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +000041 rtp_receiver_(RtpReceiver::CreateVideoReceiver(
42 channel_id, Clock::GetRealTimeClock(), this, rtp_feedback,
43 rtp_payload_registry_.get())),
44 rtp_receive_statistics_(ReceiveStatistics::Create(
45 Clock::GetRealTimeClock())),
andresp@webrtc.org99681312014-04-08 11:06:12 +000046 fec_receiver_(FecReceiver::Create(this)),
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000047 rtp_rtcp_(NULL),
48 vcm_(module_vcm),
49 remote_bitrate_estimator_(remote_bitrate_estimator),
wu@webrtc.org2fae0d12014-05-14 16:53:51 +000050 ntp_estimator_(new RemoteNtpTimeEstimator(Clock::GetRealTimeClock())),
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000051 rtp_dump_(NULL),
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +000052 receiving_(false),
solenberg@webrtc.org2d3624c2014-03-24 20:28:11 +000053 restored_packet_in_use_(false),
54 receiving_ast_enabled_(false) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000055 assert(remote_bitrate_estimator);
56}
57
58ViEReceiver::~ViEReceiver() {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +000059 if (rtp_dump_) {
60 rtp_dump_->Stop();
61 RtpDump::DestroyRtpDump(rtp_dump_);
62 rtp_dump_ = NULL;
63 }
64}
65
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +000066bool ViEReceiver::SetReceiveCodec(const VideoCodec& video_codec) {
67 int8_t old_pltype = -1;
68 if (rtp_payload_registry_->ReceivePayloadType(video_codec.plName,
69 kVideoPayloadTypeFrequency,
70 0,
71 video_codec.maxBitrate,
72 &old_pltype) != -1) {
73 rtp_payload_registry_->DeRegisterReceivePayload(old_pltype);
74 }
75
76 return RegisterPayload(video_codec);
77}
78
79bool ViEReceiver::RegisterPayload(const VideoCodec& video_codec) {
80 return rtp_receiver_->RegisterReceivePayload(video_codec.plName,
81 video_codec.plType,
82 kVideoPayloadTypeFrequency,
83 0,
84 video_codec.maxBitrate) == 0;
85}
86
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +000087void ViEReceiver::SetNackStatus(bool enable,
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +000088 int max_nack_reordering_threshold) {
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +000089 if (!enable) {
90 // Reset the threshold back to the lower default threshold when NACK is
91 // disabled since we no longer will be receiving retransmissions.
92 max_nack_reordering_threshold = kDefaultMaxReorderingThreshold;
93 }
94 rtp_receive_statistics_->SetMaxReorderingThreshold(
95 max_nack_reordering_threshold);
96 rtp_receiver_->SetNACKStatus(enable ? kNackRtcp : kNackOff);
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +000097}
98
stefan@webrtc.org903e7462014-06-05 08:25:29 +000099void ViEReceiver::SetRtxPayloadType(int payload_type) {
100 rtp_payload_registry_->SetRtxPayloadType(payload_type);
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +0000101}
102
stefan@webrtc.org903e7462014-06-05 08:25:29 +0000103void ViEReceiver::SetRtxSsrc(uint32_t ssrc) {
104 rtp_payload_registry_->SetRtxSsrc(ssrc);
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +0000105}
106
107uint32_t ViEReceiver::GetRemoteSsrc() const {
108 return rtp_receiver_->SSRC();
109}
110
111int ViEReceiver::GetCsrcs(uint32_t* csrcs) const {
112 return rtp_receiver_->CSRCs(csrcs);
113}
114
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000115void ViEReceiver::SetRtpRtcpModule(RtpRtcp* module) {
116 rtp_rtcp_ = module;
117}
118
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +0000119RtpReceiver* ViEReceiver::GetRtpReceiver() const {
120 return rtp_receiver_.get();
121}
122
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000123void ViEReceiver::RegisterSimulcastRtpRtcpModules(
124 const std::list<RtpRtcp*>& rtp_modules) {
125 CriticalSectionScoped cs(receive_cs_.get());
126 rtp_rtcp_simulcast_.clear();
127
128 if (!rtp_modules.empty()) {
129 rtp_rtcp_simulcast_.insert(rtp_rtcp_simulcast_.begin(),
130 rtp_modules.begin(),
131 rtp_modules.end());
132 }
133}
134
stefan@webrtc.org4e5f9832013-05-29 13:28:21 +0000135bool ViEReceiver::SetReceiveTimestampOffsetStatus(bool enable, int id) {
stefan@webrtc.org6696fba2013-05-29 12:12:51 +0000136 if (enable) {
137 return rtp_header_parser_->RegisterRtpHeaderExtension(
138 kRtpExtensionTransmissionTimeOffset, id);
139 } else {
140 return rtp_header_parser_->DeregisterRtpHeaderExtension(
141 kRtpExtensionTransmissionTimeOffset);
142 }
143}
144
stefan@webrtc.org4e5f9832013-05-29 13:28:21 +0000145bool ViEReceiver::SetReceiveAbsoluteSendTimeStatus(bool enable, int id) {
stefan@webrtc.org6696fba2013-05-29 12:12:51 +0000146 if (enable) {
solenberg@webrtc.org2d3624c2014-03-24 20:28:11 +0000147 if (rtp_header_parser_->RegisterRtpHeaderExtension(
148 kRtpExtensionAbsoluteSendTime, id)) {
149 receiving_ast_enabled_ = true;
150 return true;
151 } else {
152 return false;
153 }
stefan@webrtc.org6696fba2013-05-29 12:12:51 +0000154 } else {
solenberg@webrtc.org2d3624c2014-03-24 20:28:11 +0000155 receiving_ast_enabled_ = false;
stefan@webrtc.org6696fba2013-05-29 12:12:51 +0000156 return rtp_header_parser_->DeregisterRtpHeaderExtension(
157 kRtpExtensionAbsoluteSendTime);
158 }
159}
160
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000161int ViEReceiver::ReceivedRTPPacket(const void* rtp_packet,
wu@webrtc.orgefeb8ce2013-12-13 00:21:03 +0000162 int rtp_packet_length,
163 const PacketTime& packet_time) {
solenberg@webrtc.org800136d2014-02-11 15:27:49 +0000164 return InsertRTPPacket(static_cast<const uint8_t*>(rtp_packet),
wu@webrtc.orgefeb8ce2013-12-13 00:21:03 +0000165 rtp_packet_length, packet_time);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000166}
167
168int ViEReceiver::ReceivedRTCPPacket(const void* rtcp_packet,
169 int rtcp_packet_length) {
solenberg@webrtc.org800136d2014-02-11 15:27:49 +0000170 return InsertRTCPPacket(static_cast<const uint8_t*>(rtcp_packet),
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000171 rtcp_packet_length);
172}
173
pbos@webrtc.org67879bc2013-04-09 13:41:51 +0000174int32_t ViEReceiver::OnReceivedPayloadData(
175 const uint8_t* payload_data, const uint16_t payload_size,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000176 const WebRtcRTPHeader* rtp_header) {
wu@webrtc.org093fc0b2014-04-24 22:10:24 +0000177 WebRtcRTPHeader rtp_header_with_ntp = *rtp_header;
wu@webrtc.org2fae0d12014-05-14 16:53:51 +0000178 rtp_header_with_ntp.ntp_time_ms =
179 ntp_estimator_->Estimate(rtp_header->header.timestamp);
wu@webrtc.org093fc0b2014-04-24 22:10:24 +0000180 if (vcm_->IncomingPacket(payload_data,
181 payload_size,
182 rtp_header_with_ntp) != 0) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000183 // Check this...
184 return -1;
185 }
186 return 0;
187}
188
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +0000189bool ViEReceiver::OnRecoveredPacket(const uint8_t* rtp_packet,
190 int rtp_packet_length) {
191 RTPHeader header;
192 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length, &header)) {
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +0000193 return false;
194 }
195 header.payload_type_frequency = kVideoPayloadTypeFrequency;
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +0000196 return ReceivePacket(rtp_packet, rtp_packet_length, header, false);
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +0000197}
198
solenberg@webrtc.org2d3624c2014-03-24 20:28:11 +0000199void ViEReceiver::ReceivedBWEPacket(
200 int64_t arrival_time_ms, int payload_size, const RTPHeader& header) {
201 // Only forward if the incoming packet *and* the channel are both configured
202 // to receive absolute sender time. RTP time stamps may have different rates
203 // for audio and video and shouldn't be mixed.
204 if (header.extension.hasAbsoluteSendTime && receiving_ast_enabled_) {
205 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size,
206 header);
207 }
208}
209
solenberg@webrtc.org800136d2014-02-11 15:27:49 +0000210int ViEReceiver::InsertRTPPacket(const uint8_t* rtp_packet,
wu@webrtc.orgefeb8ce2013-12-13 00:21:03 +0000211 int rtp_packet_length,
212 const PacketTime& packet_time) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000213 {
214 CriticalSectionScoped cs(receive_cs_.get());
braveyao@webrtc.orgd69e2f42013-07-26 09:02:46 +0000215 if (!receiving_) {
216 return -1;
217 }
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000218 if (rtp_dump_) {
solenberg@webrtc.org800136d2014-02-11 15:27:49 +0000219 rtp_dump_->DumpPacket(rtp_packet,
220 static_cast<uint16_t>(rtp_packet_length));
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000221 }
222 }
solenberg@webrtc.org800136d2014-02-11 15:27:49 +0000223
stefan@webrtc.org6696fba2013-05-29 12:12:51 +0000224 RTPHeader header;
solenberg@webrtc.org800136d2014-02-11 15:27:49 +0000225 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length,
stefan@webrtc.org6696fba2013-05-29 12:12:51 +0000226 &header)) {
stefan@webrtc.org6696fba2013-05-29 12:12:51 +0000227 return -1;
228 }
solenberg@webrtc.org800136d2014-02-11 15:27:49 +0000229 int payload_length = rtp_packet_length - header.headerLength;
wu@webrtc.orgefeb8ce2013-12-13 00:21:03 +0000230 int64_t arrival_time_ms;
231 if (packet_time.timestamp != -1)
232 arrival_time_ms = (packet_time.timestamp + 500) / 1000;
233 else
234 arrival_time_ms = TickTime::MillisecondTimestamp();
235
236 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms,
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +0000237 payload_length, header);
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +0000238 header.payload_type_frequency = kVideoPayloadTypeFrequency;
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +0000239
stefan@webrtc.org7e97e4c2013-11-08 15:18:52 +0000240 bool in_order = IsPacketInOrder(header);
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +0000241 rtp_payload_registry_->SetIncomingPayloadType(header);
asapersson@webrtc.org99153ba2014-05-26 13:06:04 +0000242 int ret = ReceivePacket(rtp_packet, rtp_packet_length, header, in_order)
solenberg@webrtc.org800136d2014-02-11 15:27:49 +0000243 ? 0
244 : -1;
asapersson@webrtc.org99153ba2014-05-26 13:06:04 +0000245 // Update receive statistics after ReceivePacket.
246 // Receive statistics will be reset if the payload type changes (make sure
247 // that the first packet is included in the stats).
248 rtp_receive_statistics_->IncomingPacket(
249 header, rtp_packet_length, IsPacketRetransmitted(header, in_order));
250 return ret;
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +0000251}
252
253bool ViEReceiver::ReceivePacket(const uint8_t* packet,
254 int packet_length,
255 const RTPHeader& header,
256 bool in_order) {
257 if (rtp_payload_registry_->IsEncapsulated(header)) {
258 return ParseAndHandleEncapsulatingHeader(packet, packet_length, header);
259 }
260 const uint8_t* payload = packet + header.headerLength;
261 int payload_length = packet_length - header.headerLength;
262 assert(payload_length >= 0);
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +0000263 PayloadUnion payload_specific;
264 if (!rtp_payload_registry_->GetPayloadSpecifics(header.payloadType,
265 &payload_specific)) {
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +0000266 return false;
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +0000267 }
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +0000268 return rtp_receiver_->IncomingRtpPacket(header, payload, payload_length,
269 payload_specific, in_order);
270}
271
272bool ViEReceiver::ParseAndHandleEncapsulatingHeader(const uint8_t* packet,
273 int packet_length,
274 const RTPHeader& header) {
275 if (rtp_payload_registry_->IsRed(header)) {
sprang@webrtc.org7d99cd42014-01-23 10:00:39 +0000276 int8_t ulpfec_pt = rtp_payload_registry_->ulpfec_payload_type();
277 if (packet[header.headerLength] == ulpfec_pt)
278 rtp_receive_statistics_->FecPacketReceived(header.ssrc);
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +0000279 if (fec_receiver_->AddReceivedRedPacket(
sprang@webrtc.org7d99cd42014-01-23 10:00:39 +0000280 header, packet, packet_length, ulpfec_pt) != 0) {
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +0000281 return false;
282 }
283 return fec_receiver_->ProcessReceivedFec() == 0;
284 } else if (rtp_payload_registry_->IsRtx(header)) {
stefan@webrtc.orgfbd6f472014-03-19 18:14:52 +0000285 if (header.headerLength + header.paddingLength == packet_length) {
286 // This is an empty packet and should be silently dropped before trying to
287 // parse the RTX header.
288 return true;
289 }
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +0000290 // Remove the RTX header and parse the original RTP header.
291 if (packet_length < header.headerLength)
292 return false;
293 if (packet_length > static_cast<int>(sizeof(restored_packet_)))
294 return false;
295 CriticalSectionScoped cs(receive_cs_.get());
296 if (restored_packet_in_use_) {
pbos@webrtc.org3468f202014-05-14 08:02:22 +0000297 LOG(LS_WARNING) << "Multiple RTX headers detected, dropping packet.";
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +0000298 return false;
299 }
300 uint8_t* restored_packet_ptr = restored_packet_;
301 if (!rtp_payload_registry_->RestoreOriginalPacket(
302 &restored_packet_ptr, packet, &packet_length, rtp_receiver_->SSRC(),
303 header)) {
pbos@webrtc.org3468f202014-05-14 08:02:22 +0000304 LOG(LS_WARNING) << "Incoming RTX packet: Invalid RTP header";
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +0000305 return false;
306 }
307 restored_packet_in_use_ = true;
308 bool ret = OnRecoveredPacket(restored_packet_ptr, packet_length);
309 restored_packet_in_use_ = false;
310 return ret;
311 }
312 return false;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000313}
314
solenberg@webrtc.org800136d2014-02-11 15:27:49 +0000315int ViEReceiver::InsertRTCPPacket(const uint8_t* rtcp_packet,
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000316 int rtcp_packet_length) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000317 {
318 CriticalSectionScoped cs(receive_cs_.get());
braveyao@webrtc.orgd69e2f42013-07-26 09:02:46 +0000319 if (!receiving_) {
320 return -1;
321 }
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000322
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000323 if (rtp_dump_) {
324 rtp_dump_->DumpPacket(
solenberg@webrtc.org800136d2014-02-11 15:27:49 +0000325 rtcp_packet, static_cast<uint16_t>(rtcp_packet_length));
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000326 }
solenberg@webrtc.org800136d2014-02-11 15:27:49 +0000327
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000328 std::list<RtpRtcp*>::iterator it = rtp_rtcp_simulcast_.begin();
329 while (it != rtp_rtcp_simulcast_.end()) {
330 RtpRtcp* rtp_rtcp = *it++;
solenberg@webrtc.org800136d2014-02-11 15:27:49 +0000331 rtp_rtcp->IncomingRtcpPacket(rtcp_packet, rtcp_packet_length);
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000332 }
333 }
334 assert(rtp_rtcp_); // Should be set by owner at construction time.
wu@webrtc.org093fc0b2014-04-24 22:10:24 +0000335 int ret = rtp_rtcp_->IncomingRtcpPacket(rtcp_packet, rtcp_packet_length);
336 if (ret != 0) {
337 return ret;
338 }
339
wu@webrtc.orgdd0f8b22014-05-14 23:06:23 +0000340 ntp_estimator_->UpdateRtcpTimestamp(rtp_receiver_->SSRC(), rtp_rtcp_);
wu@webrtc.org093fc0b2014-04-24 22:10:24 +0000341
342 return 0;
343}
344
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000345void ViEReceiver::StartReceive() {
braveyao@webrtc.orgd69e2f42013-07-26 09:02:46 +0000346 CriticalSectionScoped cs(receive_cs_.get());
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000347 receiving_ = true;
348}
349
350void ViEReceiver::StopReceive() {
braveyao@webrtc.orgd69e2f42013-07-26 09:02:46 +0000351 CriticalSectionScoped cs(receive_cs_.get());
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000352 receiving_ = false;
353}
354
355int ViEReceiver::StartRTPDump(const char file_nameUTF8[1024]) {
356 CriticalSectionScoped cs(receive_cs_.get());
357 if (rtp_dump_) {
358 // Restart it if it already exists and is started
359 rtp_dump_->Stop();
360 } else {
361 rtp_dump_ = RtpDump::CreateRtpDump();
362 if (rtp_dump_ == NULL) {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000363 return -1;
364 }
365 }
366 if (rtp_dump_->Start(file_nameUTF8) != 0) {
367 RtpDump::DestroyRtpDump(rtp_dump_);
368 rtp_dump_ = NULL;
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000369 return -1;
370 }
371 return 0;
372}
373
374int ViEReceiver::StopRTPDump() {
375 CriticalSectionScoped cs(receive_cs_.get());
376 if (rtp_dump_) {
377 if (rtp_dump_->IsActive()) {
378 rtp_dump_->Stop();
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000379 }
380 RtpDump::DestroyRtpDump(rtp_dump_);
381 rtp_dump_ = NULL;
382 } else {
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000383 return -1;
384 }
385 return 0;
386}
387
jiayl@webrtc.orgd1e7fac2014-02-10 19:12:14 +0000388void ViEReceiver::GetReceiveBandwidthEstimatorStats(
389 ReceiveBandwidthEstimatorStats* output) const {
390 remote_bitrate_estimator_->GetStats(output);
391}
392
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +0000393ReceiveStatistics* ViEReceiver::GetReceiveStatistics() const {
394 return rtp_receive_statistics_.get();
395}
396
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +0000397bool ViEReceiver::IsPacketInOrder(const RTPHeader& header) const {
398 StreamStatistician* statistician =
399 rtp_receive_statistics_->GetStatistician(header.ssrc);
400 if (!statistician)
401 return false;
402 return statistician->IsPacketInOrder(header.sequenceNumber);
403}
404
stefan@webrtc.org7e97e4c2013-11-08 15:18:52 +0000405bool ViEReceiver::IsPacketRetransmitted(const RTPHeader& header,
406 bool in_order) const {
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +0000407 // Retransmissions are handled separately if RTX is enabled.
408 if (rtp_payload_registry_->RtxEnabled())
409 return false;
410 StreamStatistician* statistician =
411 rtp_receive_statistics_->GetStatistician(header.ssrc);
412 if (!statistician)
413 return false;
414 // Check if this is a retransmission.
415 uint16_t min_rtt = 0;
416 rtp_rtcp_->RTT(rtp_receiver_->SSRC(), NULL, NULL, &min_rtt, NULL);
stefan@webrtc.org7e97e4c2013-11-08 15:18:52 +0000417 return !in_order &&
stefan@webrtc.orgdb74c612013-09-06 13:40:11 +0000418 statistician->IsRetransmitOfOldPacket(header, min_rtt);
wu@webrtc.org7fc75bb2013-08-15 23:38:54 +0000419}
andrew@webrtc.orgb015cbe2012-10-22 18:19:23 +0000420} // namespace webrtc