blob: 62f4f7e1db1e243fa7153781bf7e07ad22bf3d8c [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
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +000033ViEReceiver::ViEReceiver(const int32_t channel_id,
stefan@webrtc.org976a7e62012-09-21 13:20:21 +000034 VideoCodingModule* module_vcm,
wu@webrtc.org822fbd82013-08-15 23:38:54 +000035 RemoteBitrateEstimator* remote_bitrate_estimator,
36 RtpFeedback* rtp_feedback)
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +000037 : receive_cs_(CriticalSectionWrapper::CreateCriticalSection()),
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000038 rtp_header_parser_(RtpHeaderParser::Create()),
wu@webrtc.org822fbd82013-08-15 23:38:54 +000039 rtp_payload_registry_(new RTPPayloadRegistry(
andresp@webrtc.orgdc80bae2014-04-08 11:06:12 +000040 RTPPayloadStrategy::CreateStrategy(false))),
wu@webrtc.org822fbd82013-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.orgdc80bae2014-04-08 11:06:12 +000046 fec_receiver_(FecReceiver::Create(this)),
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +000047 rtp_rtcp_(NULL),
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000048 vcm_(module_vcm),
stefan@webrtc.org976a7e62012-09-21 13:20:21 +000049 remote_bitrate_estimator_(remote_bitrate_estimator),
wu@webrtc.org88abf112014-05-14 16:53:51 +000050 ntp_estimator_(new RemoteNtpTimeEstimator(Clock::GetRealTimeClock())),
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000051 rtp_dump_(NULL),
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000052 receiving_(false),
solenberg@webrtc.org3fb8f7b2014-03-24 20:28:11 +000053 restored_packet_in_use_(false),
54 receiving_ast_enabled_(false) {
stefan@webrtc.org976a7e62012-09-21 13:20:21 +000055 assert(remote_bitrate_estimator);
niklase@google.com470e71d2011-07-07 08:21:25 +000056}
57
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000058ViEReceiver::~ViEReceiver() {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000059 if (rtp_dump_) {
60 rtp_dump_->Stop();
61 RtpDump::DestroyRtpDump(rtp_dump_);
62 rtp_dump_ = NULL;
63 }
niklase@google.com470e71d2011-07-07 08:21:25 +000064}
65
wu@webrtc.org822fbd82013-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.org7bb8f022013-09-06 13:40:11 +000087void ViEReceiver::SetNackStatus(bool enable,
wu@webrtc.org822fbd82013-08-15 23:38:54 +000088 int max_nack_reordering_threshold) {
stefan@webrtc.org7bb8f022013-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.org822fbd82013-08-15 23:38:54 +000097}
98
99void ViEReceiver::SetRtxStatus(bool enable, uint32_t ssrc) {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000100 rtp_payload_registry_->SetRtxStatus(enable, ssrc);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000101}
102
103void ViEReceiver::SetRtxPayloadType(uint32_t payload_type) {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000104 rtp_payload_registry_->SetRtxPayloadType(payload_type);
wu@webrtc.org822fbd82013-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
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000115void ViEReceiver::SetRtpRtcpModule(RtpRtcp* module) {
116 rtp_rtcp_ = module;
117}
118
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000119RtpReceiver* ViEReceiver::GetRtpReceiver() const {
120 return rtp_receiver_.get();
121}
122
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000123void ViEReceiver::RegisterSimulcastRtpRtcpModules(
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000124 const std::list<RtpRtcp*>& rtp_modules) {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000125 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000126 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 }
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000133}
134
stefan@webrtc.org08994cc2013-05-29 13:28:21 +0000135bool ViEReceiver::SetReceiveTimestampOffsetStatus(bool enable, int id) {
stefan@webrtc.orga5cb98c2013-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.org08994cc2013-05-29 13:28:21 +0000145bool ViEReceiver::SetReceiveAbsoluteSendTimeStatus(bool enable, int id) {
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000146 if (enable) {
solenberg@webrtc.org3fb8f7b2014-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.orga5cb98c2013-05-29 12:12:51 +0000154 } else {
solenberg@webrtc.org3fb8f7b2014-03-24 20:28:11 +0000155 receiving_ast_enabled_ = false;
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000156 return rtp_header_parser_->DeregisterRtpHeaderExtension(
157 kRtpExtensionAbsoluteSendTime);
158 }
159}
160
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000161int ViEReceiver::ReceivedRTPPacket(const void* rtp_packet,
wu@webrtc.orga9890802013-12-13 00:21:03 +0000162 int rtp_packet_length,
163 const PacketTime& packet_time) {
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000164 return InsertRTPPacket(static_cast<const uint8_t*>(rtp_packet),
wu@webrtc.orga9890802013-12-13 00:21:03 +0000165 rtp_packet_length, packet_time);
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000166}
167
168int ViEReceiver::ReceivedRTCPPacket(const void* rtcp_packet,
169 int rtcp_packet_length) {
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000170 return InsertRTCPPacket(static_cast<const uint8_t*>(rtcp_packet),
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000171 rtcp_packet_length);
172}
173
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000174int32_t ViEReceiver::OnReceivedPayloadData(
175 const uint8_t* payload_data, const uint16_t payload_size,
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000176 const WebRtcRTPHeader* rtp_header) {
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000177 WebRtcRTPHeader rtp_header_with_ntp = *rtp_header;
wu@webrtc.org88abf112014-05-14 16:53:51 +0000178 rtp_header_with_ntp.ntp_time_ms =
179 ntp_estimator_->Estimate(rtp_header->header.timestamp);
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000180 if (vcm_->IncomingPacket(payload_data,
181 payload_size,
182 rtp_header_with_ntp) != 0) {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000183 // Check this...
184 return -1;
185 }
186 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000187}
188
wu@webrtc.org822fbd82013-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.org822fbd82013-08-15 23:38:54 +0000193 return false;
194 }
195 header.payload_type_frequency = kVideoPayloadTypeFrequency;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000196 return ReceivePacket(rtp_packet, rtp_packet_length, header, false);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000197}
198
solenberg@webrtc.org3fb8f7b2014-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.orgfc320462014-02-11 15:27:49 +0000210int ViEReceiver::InsertRTPPacket(const uint8_t* rtp_packet,
wu@webrtc.orga9890802013-12-13 00:21:03 +0000211 int rtp_packet_length,
212 const PacketTime& packet_time) {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000213 {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000214 CriticalSectionScoped cs(receive_cs_.get());
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000215 if (!receiving_) {
216 return -1;
217 }
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000218 if (rtp_dump_) {
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000219 rtp_dump_->DumpPacket(rtp_packet,
220 static_cast<uint16_t>(rtp_packet_length));
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000221 }
222 }
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000223
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000224 RTPHeader header;
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000225 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length,
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000226 &header)) {
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000227 return -1;
228 }
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000229 int payload_length = rtp_packet_length - header.headerLength;
wu@webrtc.orga9890802013-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.org7bb8f022013-09-06 13:40:11 +0000237 payload_length, header);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000238 header.payload_type_frequency = kVideoPayloadTypeFrequency;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000239
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000240 bool in_order = IsPacketInOrder(header);
sprang@webrtc.org0e932572014-01-23 10:00:39 +0000241 rtp_receive_statistics_->IncomingPacket(
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000242 header, rtp_packet_length, IsPacketRetransmitted(header, in_order));
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000243 rtp_payload_registry_->SetIncomingPayloadType(header);
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000244 return ReceivePacket(rtp_packet, rtp_packet_length, header, in_order)
245 ? 0
246 : -1;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000247}
248
249bool ViEReceiver::ReceivePacket(const uint8_t* packet,
250 int packet_length,
251 const RTPHeader& header,
252 bool in_order) {
253 if (rtp_payload_registry_->IsEncapsulated(header)) {
254 return ParseAndHandleEncapsulatingHeader(packet, packet_length, header);
255 }
256 const uint8_t* payload = packet + header.headerLength;
257 int payload_length = packet_length - header.headerLength;
258 assert(payload_length >= 0);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000259 PayloadUnion payload_specific;
260 if (!rtp_payload_registry_->GetPayloadSpecifics(header.payloadType,
261 &payload_specific)) {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000262 return false;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000263 }
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000264 return rtp_receiver_->IncomingRtpPacket(header, payload, payload_length,
265 payload_specific, in_order);
266}
267
268bool ViEReceiver::ParseAndHandleEncapsulatingHeader(const uint8_t* packet,
269 int packet_length,
270 const RTPHeader& header) {
271 if (rtp_payload_registry_->IsRed(header)) {
sprang@webrtc.org0e932572014-01-23 10:00:39 +0000272 int8_t ulpfec_pt = rtp_payload_registry_->ulpfec_payload_type();
273 if (packet[header.headerLength] == ulpfec_pt)
274 rtp_receive_statistics_->FecPacketReceived(header.ssrc);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000275 if (fec_receiver_->AddReceivedRedPacket(
sprang@webrtc.org0e932572014-01-23 10:00:39 +0000276 header, packet, packet_length, ulpfec_pt) != 0) {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000277 return false;
278 }
279 return fec_receiver_->ProcessReceivedFec() == 0;
280 } else if (rtp_payload_registry_->IsRtx(header)) {
stefan@webrtc.org7c6ff2d2014-03-19 18:14:52 +0000281 if (header.headerLength + header.paddingLength == packet_length) {
282 // This is an empty packet and should be silently dropped before trying to
283 // parse the RTX header.
284 return true;
285 }
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000286 // Remove the RTX header and parse the original RTP header.
287 if (packet_length < header.headerLength)
288 return false;
289 if (packet_length > static_cast<int>(sizeof(restored_packet_)))
290 return false;
291 CriticalSectionScoped cs(receive_cs_.get());
292 if (restored_packet_in_use_) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +0000293 LOG(LS_WARNING) << "Multiple RTX headers detected, dropping packet.";
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000294 return false;
295 }
296 uint8_t* restored_packet_ptr = restored_packet_;
297 if (!rtp_payload_registry_->RestoreOriginalPacket(
298 &restored_packet_ptr, packet, &packet_length, rtp_receiver_->SSRC(),
299 header)) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +0000300 LOG(LS_WARNING) << "Incoming RTX packet: Invalid RTP header";
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000301 return false;
302 }
303 restored_packet_in_use_ = true;
304 bool ret = OnRecoveredPacket(restored_packet_ptr, packet_length);
305 restored_packet_in_use_ = false;
306 return ret;
307 }
308 return false;
niklase@google.com470e71d2011-07-07 08:21:25 +0000309}
310
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000311int ViEReceiver::InsertRTCPPacket(const uint8_t* rtcp_packet,
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000312 int rtcp_packet_length) {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000313 {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000314 CriticalSectionScoped cs(receive_cs_.get());
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000315 if (!receiving_) {
316 return -1;
317 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000318
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000319 if (rtp_dump_) {
320 rtp_dump_->DumpPacket(
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000321 rtcp_packet, static_cast<uint16_t>(rtcp_packet_length));
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000322 }
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000323
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000324 std::list<RtpRtcp*>::iterator it = rtp_rtcp_simulcast_.begin();
325 while (it != rtp_rtcp_simulcast_.end()) {
326 RtpRtcp* rtp_rtcp = *it++;
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000327 rtp_rtcp->IncomingRtcpPacket(rtcp_packet, rtcp_packet_length);
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000328 }
329 }
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000330 assert(rtp_rtcp_); // Should be set by owner at construction time.
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000331 int ret = rtp_rtcp_->IncomingRtcpPacket(rtcp_packet, rtcp_packet_length);
332 if (ret != 0) {
333 return ret;
334 }
335
wu@webrtc.org88abf112014-05-14 16:53:51 +0000336 if (!ntp_estimator_->UpdateRtcpTimestamp(rtp_receiver_->SSRC(), rtp_rtcp_)) {
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000337 LOG(LS_WARNING) << "Failed to retrieve timestamp information from RTCP SR.";
338 }
339
340 return 0;
341}
342
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000343void ViEReceiver::StartReceive() {
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000344 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000345 receiving_ = true;
346}
347
348void ViEReceiver::StopReceive() {
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000349 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000350 receiving_ = false;
351}
352
353int ViEReceiver::StartRTPDump(const char file_nameUTF8[1024]) {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000354 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000355 if (rtp_dump_) {
356 // Restart it if it already exists and is started
357 rtp_dump_->Stop();
358 } else {
359 rtp_dump_ = RtpDump::CreateRtpDump();
360 if (rtp_dump_ == NULL) {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000361 return -1;
362 }
363 }
364 if (rtp_dump_->Start(file_nameUTF8) != 0) {
365 RtpDump::DestroyRtpDump(rtp_dump_);
366 rtp_dump_ = NULL;
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000367 return -1;
368 }
369 return 0;
370}
371
372int ViEReceiver::StopRTPDump() {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000373 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000374 if (rtp_dump_) {
375 if (rtp_dump_->IsActive()) {
376 rtp_dump_->Stop();
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000377 }
378 RtpDump::DestroyRtpDump(rtp_dump_);
379 rtp_dump_ = NULL;
380 } else {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000381 return -1;
382 }
383 return 0;
384}
385
jiayl@webrtc.org1f64f062014-02-10 19:12:14 +0000386void ViEReceiver::GetReceiveBandwidthEstimatorStats(
387 ReceiveBandwidthEstimatorStats* output) const {
388 remote_bitrate_estimator_->GetStats(output);
389}
390
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000391ReceiveStatistics* ViEReceiver::GetReceiveStatistics() const {
392 return rtp_receive_statistics_.get();
393}
394
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000395bool ViEReceiver::IsPacketInOrder(const RTPHeader& header) const {
396 StreamStatistician* statistician =
397 rtp_receive_statistics_->GetStatistician(header.ssrc);
398 if (!statistician)
399 return false;
400 return statistician->IsPacketInOrder(header.sequenceNumber);
401}
402
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000403bool ViEReceiver::IsPacketRetransmitted(const RTPHeader& header,
404 bool in_order) const {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000405 // Retransmissions are handled separately if RTX is enabled.
406 if (rtp_payload_registry_->RtxEnabled())
407 return false;
408 StreamStatistician* statistician =
409 rtp_receive_statistics_->GetStatistician(header.ssrc);
410 if (!statistician)
411 return false;
412 // Check if this is a retransmission.
413 uint16_t min_rtt = 0;
414 rtp_rtcp_->RTT(rtp_receiver_->SSRC(), NULL, NULL, &min_rtt, NULL);
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000415 return !in_order &&
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000416 statistician->IsRetransmitOfOldPacket(header, min_rtt);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000417}
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000418} // namespace webrtc