blob: cb574665ca11baabb82f05f95fe363719bd9d249 [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
stefan@webrtc.orgef927552014-06-05 08:25:29 +000099void ViEReceiver::SetRtxPayloadType(int payload_type) {
100 rtp_payload_registry_->SetRtxPayloadType(payload_type);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000101}
102
stefan@webrtc.orgef927552014-06-05 08:25:29 +0000103void ViEReceiver::SetRtxSsrc(uint32_t ssrc) {
104 rtp_payload_registry_->SetRtxSsrc(ssrc);
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.org01581da2014-09-04 06:48:14 +0000196 bool in_order = IsPacketInOrder(header);
197 return ReceivePacket(rtp_packet, rtp_packet_length, header, in_order);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000198}
199
solenberg@webrtc.org3fb8f7b2014-03-24 20:28:11 +0000200void ViEReceiver::ReceivedBWEPacket(
201 int64_t arrival_time_ms, int payload_size, const RTPHeader& header) {
202 // Only forward if the incoming packet *and* the channel are both configured
203 // to receive absolute sender time. RTP time stamps may have different rates
204 // for audio and video and shouldn't be mixed.
205 if (header.extension.hasAbsoluteSendTime && receiving_ast_enabled_) {
206 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms, payload_size,
207 header);
208 }
209}
210
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000211int ViEReceiver::InsertRTPPacket(const uint8_t* rtp_packet,
wu@webrtc.orga9890802013-12-13 00:21:03 +0000212 int rtp_packet_length,
213 const PacketTime& packet_time) {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000214 {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000215 CriticalSectionScoped cs(receive_cs_.get());
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000216 if (!receiving_) {
217 return -1;
218 }
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000219 if (rtp_dump_) {
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000220 rtp_dump_->DumpPacket(rtp_packet,
221 static_cast<uint16_t>(rtp_packet_length));
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000222 }
223 }
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000224
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000225 RTPHeader header;
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000226 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length,
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000227 &header)) {
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000228 return -1;
229 }
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000230 int payload_length = rtp_packet_length - header.headerLength;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000231 int64_t arrival_time_ms;
232 if (packet_time.timestamp != -1)
233 arrival_time_ms = (packet_time.timestamp + 500) / 1000;
234 else
235 arrival_time_ms = TickTime::MillisecondTimestamp();
236
237 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms,
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000238 payload_length, header);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000239 header.payload_type_frequency = kVideoPayloadTypeFrequency;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000240
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000241 bool in_order = IsPacketInOrder(header);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000242 rtp_payload_registry_->SetIncomingPayloadType(header);
asapersson@webrtc.org1457b472014-05-26 13:06:04 +0000243 int ret = ReceivePacket(rtp_packet, rtp_packet_length, header, in_order)
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000244 ? 0
245 : -1;
asapersson@webrtc.org1457b472014-05-26 13:06:04 +0000246 // Update receive statistics after ReceivePacket.
247 // Receive statistics will be reset if the payload type changes (make sure
248 // that the first packet is included in the stats).
249 rtp_receive_statistics_->IncomingPacket(
250 header, rtp_packet_length, IsPacketRetransmitted(header, in_order));
251 return ret;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000252}
253
254bool ViEReceiver::ReceivePacket(const uint8_t* packet,
255 int packet_length,
256 const RTPHeader& header,
257 bool in_order) {
258 if (rtp_payload_registry_->IsEncapsulated(header)) {
259 return ParseAndHandleEncapsulatingHeader(packet, packet_length, header);
260 }
261 const uint8_t* payload = packet + header.headerLength;
262 int payload_length = packet_length - header.headerLength;
263 assert(payload_length >= 0);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000264 PayloadUnion payload_specific;
265 if (!rtp_payload_registry_->GetPayloadSpecifics(header.payloadType,
266 &payload_specific)) {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000267 return false;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000268 }
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000269 return rtp_receiver_->IncomingRtpPacket(header, payload, payload_length,
270 payload_specific, in_order);
271}
272
273bool ViEReceiver::ParseAndHandleEncapsulatingHeader(const uint8_t* packet,
274 int packet_length,
275 const RTPHeader& header) {
276 if (rtp_payload_registry_->IsRed(header)) {
sprang@webrtc.org0e932572014-01-23 10:00:39 +0000277 int8_t ulpfec_pt = rtp_payload_registry_->ulpfec_payload_type();
278 if (packet[header.headerLength] == ulpfec_pt)
279 rtp_receive_statistics_->FecPacketReceived(header.ssrc);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000280 if (fec_receiver_->AddReceivedRedPacket(
sprang@webrtc.org0e932572014-01-23 10:00:39 +0000281 header, packet, packet_length, ulpfec_pt) != 0) {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000282 return false;
283 }
284 return fec_receiver_->ProcessReceivedFec() == 0;
285 } else if (rtp_payload_registry_->IsRtx(header)) {
stefan@webrtc.org7c6ff2d2014-03-19 18:14:52 +0000286 if (header.headerLength + header.paddingLength == packet_length) {
287 // This is an empty packet and should be silently dropped before trying to
288 // parse the RTX header.
289 return true;
290 }
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000291 // Remove the RTX header and parse the original RTP header.
292 if (packet_length < header.headerLength)
293 return false;
294 if (packet_length > static_cast<int>(sizeof(restored_packet_)))
295 return false;
296 CriticalSectionScoped cs(receive_cs_.get());
297 if (restored_packet_in_use_) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +0000298 LOG(LS_WARNING) << "Multiple RTX headers detected, dropping packet.";
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000299 return false;
300 }
301 uint8_t* restored_packet_ptr = restored_packet_;
302 if (!rtp_payload_registry_->RestoreOriginalPacket(
303 &restored_packet_ptr, packet, &packet_length, rtp_receiver_->SSRC(),
304 header)) {
pbos@webrtc.org4e2806d2014-05-14 08:02:22 +0000305 LOG(LS_WARNING) << "Incoming RTX packet: Invalid RTP header";
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000306 return false;
307 }
308 restored_packet_in_use_ = true;
309 bool ret = OnRecoveredPacket(restored_packet_ptr, packet_length);
310 restored_packet_in_use_ = false;
311 return ret;
312 }
313 return false;
niklase@google.com470e71d2011-07-07 08:21:25 +0000314}
315
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000316int ViEReceiver::InsertRTCPPacket(const uint8_t* rtcp_packet,
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000317 int rtcp_packet_length) {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000318 {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000319 CriticalSectionScoped cs(receive_cs_.get());
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000320 if (!receiving_) {
321 return -1;
322 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000323
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000324 if (rtp_dump_) {
325 rtp_dump_->DumpPacket(
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000326 rtcp_packet, static_cast<uint16_t>(rtcp_packet_length));
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000327 }
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000328
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000329 std::list<RtpRtcp*>::iterator it = rtp_rtcp_simulcast_.begin();
330 while (it != rtp_rtcp_simulcast_.end()) {
331 RtpRtcp* rtp_rtcp = *it++;
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000332 rtp_rtcp->IncomingRtcpPacket(rtcp_packet, rtcp_packet_length);
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000333 }
334 }
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000335 assert(rtp_rtcp_); // Should be set by owner at construction time.
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000336 int ret = rtp_rtcp_->IncomingRtcpPacket(rtcp_packet, rtcp_packet_length);
337 if (ret != 0) {
338 return ret;
339 }
340
minyue@webrtc.org2c0cdbc2014-10-09 10:52:43 +0000341 uint16_t rtt = 0;
342 rtp_rtcp_->RTT(rtp_receiver_->SSRC(), &rtt, NULL, NULL, NULL);
343 if (rtt == 0) {
344 // Waiting for valid rtt.
345 return 0;
346 }
347 uint32_t ntp_secs = 0;
348 uint32_t ntp_frac = 0;
349 uint32_t rtp_timestamp = 0;
350 if (0 != rtp_rtcp_->RemoteNTP(&ntp_secs, &ntp_frac, NULL, NULL,
351 &rtp_timestamp)) {
352 // Waiting for RTCP.
353 return 0;
354 }
355 ntp_estimator_->UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp);
wu@webrtc.orgcd701192014-04-24 22:10:24 +0000356
357 return 0;
358}
359
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000360void ViEReceiver::StartReceive() {
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000361 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000362 receiving_ = true;
363}
364
365void ViEReceiver::StopReceive() {
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000366 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000367 receiving_ = false;
368}
369
370int ViEReceiver::StartRTPDump(const char file_nameUTF8[1024]) {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000371 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000372 if (rtp_dump_) {
373 // Restart it if it already exists and is started
374 rtp_dump_->Stop();
375 } else {
376 rtp_dump_ = RtpDump::CreateRtpDump();
377 if (rtp_dump_ == NULL) {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000378 return -1;
379 }
380 }
381 if (rtp_dump_->Start(file_nameUTF8) != 0) {
382 RtpDump::DestroyRtpDump(rtp_dump_);
383 rtp_dump_ = NULL;
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000384 return -1;
385 }
386 return 0;
387}
388
389int ViEReceiver::StopRTPDump() {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000390 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000391 if (rtp_dump_) {
392 if (rtp_dump_->IsActive()) {
393 rtp_dump_->Stop();
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000394 }
395 RtpDump::DestroyRtpDump(rtp_dump_);
396 rtp_dump_ = NULL;
397 } else {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000398 return -1;
399 }
400 return 0;
401}
402
jiayl@webrtc.org1f64f062014-02-10 19:12:14 +0000403void ViEReceiver::GetReceiveBandwidthEstimatorStats(
404 ReceiveBandwidthEstimatorStats* output) const {
405 remote_bitrate_estimator_->GetStats(output);
406}
407
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000408ReceiveStatistics* ViEReceiver::GetReceiveStatistics() const {
409 return rtp_receive_statistics_.get();
410}
411
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000412bool ViEReceiver::IsPacketInOrder(const RTPHeader& header) const {
413 StreamStatistician* statistician =
414 rtp_receive_statistics_->GetStatistician(header.ssrc);
415 if (!statistician)
416 return false;
417 return statistician->IsPacketInOrder(header.sequenceNumber);
418}
419
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000420bool ViEReceiver::IsPacketRetransmitted(const RTPHeader& header,
421 bool in_order) const {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000422 // Retransmissions are handled separately if RTX is enabled.
423 if (rtp_payload_registry_->RtxEnabled())
424 return false;
425 StreamStatistician* statistician =
426 rtp_receive_statistics_->GetStatistician(header.ssrc);
427 if (!statistician)
428 return false;
429 // Check if this is a retransmission.
430 uint16_t min_rtt = 0;
431 rtp_rtcp_->RTT(rtp_receiver_->SSRC(), NULL, NULL, &min_rtt, NULL);
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000432 return !in_order &&
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000433 statistician->IsRetransmitOfOldPacket(header, min_rtt);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000434}
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000435} // namespace webrtc