blob: 4e6a1b2319755989eb3e0069b526a881176371a0 [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"
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000018#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
wu@webrtc.org822fbd82013-08-15 23:38:54 +000019#include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h"
20#include "webrtc/modules/rtp_rtcp/interface/rtp_receiver.h"
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000021#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
22#include "webrtc/modules/utility/interface/rtp_dump.h"
23#include "webrtc/modules/video_coding/main/interface/video_coding.h"
24#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
25#include "webrtc/system_wrappers/interface/tick_util.h"
26#include "webrtc/system_wrappers/interface/trace.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000027
28namespace webrtc {
29
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +000030ViEReceiver::ViEReceiver(const int32_t channel_id,
stefan@webrtc.org976a7e62012-09-21 13:20:21 +000031 VideoCodingModule* module_vcm,
wu@webrtc.org822fbd82013-08-15 23:38:54 +000032 RemoteBitrateEstimator* remote_bitrate_estimator,
33 RtpFeedback* rtp_feedback)
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +000034 : receive_cs_(CriticalSectionWrapper::CreateCriticalSection()),
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000035 channel_id_(channel_id),
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000036 rtp_header_parser_(RtpHeaderParser::Create()),
wu@webrtc.org822fbd82013-08-15 23:38:54 +000037 rtp_payload_registry_(new RTPPayloadRegistry(
38 channel_id, RTPPayloadStrategy::CreateStrategy(false))),
39 rtp_receiver_(RtpReceiver::CreateVideoReceiver(
40 channel_id, Clock::GetRealTimeClock(), this, rtp_feedback,
41 rtp_payload_registry_.get())),
42 rtp_receive_statistics_(ReceiveStatistics::Create(
43 Clock::GetRealTimeClock())),
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000044 fec_receiver_(FecReceiver::Create(channel_id, this)),
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +000045 rtp_rtcp_(NULL),
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000046 vcm_(module_vcm),
stefan@webrtc.org976a7e62012-09-21 13:20:21 +000047 remote_bitrate_estimator_(remote_bitrate_estimator),
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000048 rtp_dump_(NULL),
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000049 receiving_(false),
50 restored_packet_in_use_(false) {
stefan@webrtc.org976a7e62012-09-21 13:20:21 +000051 assert(remote_bitrate_estimator);
niklase@google.com470e71d2011-07-07 08:21:25 +000052}
53
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000054ViEReceiver::~ViEReceiver() {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000055 if (rtp_dump_) {
56 rtp_dump_->Stop();
57 RtpDump::DestroyRtpDump(rtp_dump_);
58 rtp_dump_ = NULL;
59 }
niklase@google.com470e71d2011-07-07 08:21:25 +000060}
61
wu@webrtc.org822fbd82013-08-15 23:38:54 +000062bool ViEReceiver::SetReceiveCodec(const VideoCodec& video_codec) {
63 int8_t old_pltype = -1;
64 if (rtp_payload_registry_->ReceivePayloadType(video_codec.plName,
65 kVideoPayloadTypeFrequency,
66 0,
67 video_codec.maxBitrate,
68 &old_pltype) != -1) {
69 rtp_payload_registry_->DeRegisterReceivePayload(old_pltype);
70 }
71
72 return RegisterPayload(video_codec);
73}
74
75bool ViEReceiver::RegisterPayload(const VideoCodec& video_codec) {
76 return rtp_receiver_->RegisterReceivePayload(video_codec.plName,
77 video_codec.plType,
78 kVideoPayloadTypeFrequency,
79 0,
80 video_codec.maxBitrate) == 0;
81}
82
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000083void ViEReceiver::SetNackStatus(bool enable,
wu@webrtc.org822fbd82013-08-15 23:38:54 +000084 int max_nack_reordering_threshold) {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000085 if (!enable) {
86 // Reset the threshold back to the lower default threshold when NACK is
87 // disabled since we no longer will be receiving retransmissions.
88 max_nack_reordering_threshold = kDefaultMaxReorderingThreshold;
89 }
90 rtp_receive_statistics_->SetMaxReorderingThreshold(
91 max_nack_reordering_threshold);
92 rtp_receiver_->SetNACKStatus(enable ? kNackRtcp : kNackOff);
wu@webrtc.org822fbd82013-08-15 23:38:54 +000093}
94
95void ViEReceiver::SetRtxStatus(bool enable, uint32_t ssrc) {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +000096 rtp_payload_registry_->SetRtxStatus(enable, ssrc);
wu@webrtc.org822fbd82013-08-15 23:38:54 +000097}
98
99void ViEReceiver::SetRtxPayloadType(uint32_t payload_type) {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000100 rtp_payload_registry_->SetRtxPayloadType(payload_type);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000101}
102
103uint32_t ViEReceiver::GetRemoteSsrc() const {
104 return rtp_receiver_->SSRC();
105}
106
107int ViEReceiver::GetCsrcs(uint32_t* csrcs) const {
108 return rtp_receiver_->CSRCs(csrcs);
109}
110
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000111void ViEReceiver::SetRtpRtcpModule(RtpRtcp* module) {
112 rtp_rtcp_ = module;
113}
114
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000115RtpReceiver* ViEReceiver::GetRtpReceiver() const {
116 return rtp_receiver_.get();
117}
118
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000119void ViEReceiver::RegisterSimulcastRtpRtcpModules(
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000120 const std::list<RtpRtcp*>& rtp_modules) {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000121 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000122 rtp_rtcp_simulcast_.clear();
123
124 if (!rtp_modules.empty()) {
125 rtp_rtcp_simulcast_.insert(rtp_rtcp_simulcast_.begin(),
126 rtp_modules.begin(),
127 rtp_modules.end());
128 }
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000129}
130
stefan@webrtc.org08994cc2013-05-29 13:28:21 +0000131bool ViEReceiver::SetReceiveTimestampOffsetStatus(bool enable, int id) {
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000132 if (enable) {
133 return rtp_header_parser_->RegisterRtpHeaderExtension(
134 kRtpExtensionTransmissionTimeOffset, id);
135 } else {
136 return rtp_header_parser_->DeregisterRtpHeaderExtension(
137 kRtpExtensionTransmissionTimeOffset);
138 }
139}
140
stefan@webrtc.org08994cc2013-05-29 13:28:21 +0000141bool ViEReceiver::SetReceiveAbsoluteSendTimeStatus(bool enable, int id) {
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000142 if (enable) {
143 return rtp_header_parser_->RegisterRtpHeaderExtension(
144 kRtpExtensionAbsoluteSendTime, id);
145 } else {
146 return rtp_header_parser_->DeregisterRtpHeaderExtension(
147 kRtpExtensionAbsoluteSendTime);
148 }
149}
150
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000151int ViEReceiver::ReceivedRTPPacket(const void* rtp_packet,
wu@webrtc.orga9890802013-12-13 00:21:03 +0000152 int rtp_packet_length,
153 const PacketTime& packet_time) {
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000154 return InsertRTPPacket(static_cast<const uint8_t*>(rtp_packet),
wu@webrtc.orga9890802013-12-13 00:21:03 +0000155 rtp_packet_length, packet_time);
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000156}
157
158int ViEReceiver::ReceivedRTCPPacket(const void* rtcp_packet,
159 int rtcp_packet_length) {
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000160 return InsertRTCPPacket(static_cast<const uint8_t*>(rtcp_packet),
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000161 rtcp_packet_length);
162}
163
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000164int32_t ViEReceiver::OnReceivedPayloadData(
165 const uint8_t* payload_data, const uint16_t payload_size,
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000166 const WebRtcRTPHeader* rtp_header) {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000167 if (vcm_->IncomingPacket(payload_data, payload_size, *rtp_header) != 0) {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000168 // Check this...
169 return -1;
170 }
171 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000172}
173
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000174bool ViEReceiver::OnRecoveredPacket(const uint8_t* rtp_packet,
175 int rtp_packet_length) {
176 RTPHeader header;
177 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length, &header)) {
178 WEBRTC_TRACE(kTraceDebug, webrtc::kTraceVideo, channel_id_,
179 "IncomingPacket invalid RTP header");
180 return false;
181 }
182 header.payload_type_frequency = kVideoPayloadTypeFrequency;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000183 return ReceivePacket(rtp_packet, rtp_packet_length, header, false);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000184}
185
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000186int ViEReceiver::InsertRTPPacket(const uint8_t* rtp_packet,
wu@webrtc.orga9890802013-12-13 00:21:03 +0000187 int rtp_packet_length,
188 const PacketTime& packet_time) {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000189 {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000190 CriticalSectionScoped cs(receive_cs_.get());
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000191 if (!receiving_) {
192 return -1;
193 }
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000194 if (rtp_dump_) {
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000195 rtp_dump_->DumpPacket(rtp_packet,
196 static_cast<uint16_t>(rtp_packet_length));
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000197 }
198 }
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000199
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000200 RTPHeader header;
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000201 if (!rtp_header_parser_->Parse(rtp_packet, rtp_packet_length,
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000202 &header)) {
203 WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideo, channel_id_,
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000204 "Incoming packet: Invalid RTP header");
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000205 return -1;
206 }
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000207 int payload_length = rtp_packet_length - header.headerLength;
wu@webrtc.orga9890802013-12-13 00:21:03 +0000208 int64_t arrival_time_ms;
209 if (packet_time.timestamp != -1)
210 arrival_time_ms = (packet_time.timestamp + 500) / 1000;
211 else
212 arrival_time_ms = TickTime::MillisecondTimestamp();
213
214 remote_bitrate_estimator_->IncomingPacket(arrival_time_ms,
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000215 payload_length, header);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000216 header.payload_type_frequency = kVideoPayloadTypeFrequency;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000217
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000218 bool in_order = IsPacketInOrder(header);
sprang@webrtc.org0e932572014-01-23 10:00:39 +0000219 rtp_receive_statistics_->IncomingPacket(
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000220 header, rtp_packet_length, IsPacketRetransmitted(header, in_order));
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000221 rtp_payload_registry_->SetIncomingPayloadType(header);
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000222 return ReceivePacket(rtp_packet, rtp_packet_length, header, in_order)
223 ? 0
224 : -1;
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000225}
226
227bool ViEReceiver::ReceivePacket(const uint8_t* packet,
228 int packet_length,
229 const RTPHeader& header,
230 bool in_order) {
231 if (rtp_payload_registry_->IsEncapsulated(header)) {
232 return ParseAndHandleEncapsulatingHeader(packet, packet_length, header);
233 }
234 const uint8_t* payload = packet + header.headerLength;
235 int payload_length = packet_length - header.headerLength;
236 assert(payload_length >= 0);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000237 PayloadUnion payload_specific;
238 if (!rtp_payload_registry_->GetPayloadSpecifics(header.payloadType,
239 &payload_specific)) {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000240 return false;
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000241 }
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000242 return rtp_receiver_->IncomingRtpPacket(header, payload, payload_length,
243 payload_specific, in_order);
244}
245
246bool ViEReceiver::ParseAndHandleEncapsulatingHeader(const uint8_t* packet,
247 int packet_length,
248 const RTPHeader& header) {
249 if (rtp_payload_registry_->IsRed(header)) {
sprang@webrtc.org0e932572014-01-23 10:00:39 +0000250 int8_t ulpfec_pt = rtp_payload_registry_->ulpfec_payload_type();
251 if (packet[header.headerLength] == ulpfec_pt)
252 rtp_receive_statistics_->FecPacketReceived(header.ssrc);
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000253 if (fec_receiver_->AddReceivedRedPacket(
sprang@webrtc.org0e932572014-01-23 10:00:39 +0000254 header, packet, packet_length, ulpfec_pt) != 0) {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000255 WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideo, channel_id_,
256 "Incoming RED packet error");
257 return false;
258 }
259 return fec_receiver_->ProcessReceivedFec() == 0;
260 } else if (rtp_payload_registry_->IsRtx(header)) {
261 // Remove the RTX header and parse the original RTP header.
262 if (packet_length < header.headerLength)
263 return false;
264 if (packet_length > static_cast<int>(sizeof(restored_packet_)))
265 return false;
266 CriticalSectionScoped cs(receive_cs_.get());
267 if (restored_packet_in_use_) {
268 WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideo, channel_id_,
269 "Multiple RTX headers detected, dropping packet");
270 return false;
271 }
272 uint8_t* restored_packet_ptr = restored_packet_;
273 if (!rtp_payload_registry_->RestoreOriginalPacket(
274 &restored_packet_ptr, packet, &packet_length, rtp_receiver_->SSRC(),
275 header)) {
276 WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideo, channel_id_,
277 "Incoming RTX packet: invalid RTP header");
278 return false;
279 }
280 restored_packet_in_use_ = true;
281 bool ret = OnRecoveredPacket(restored_packet_ptr, packet_length);
282 restored_packet_in_use_ = false;
283 return ret;
284 }
285 return false;
niklase@google.com470e71d2011-07-07 08:21:25 +0000286}
287
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000288int ViEReceiver::InsertRTCPPacket(const uint8_t* rtcp_packet,
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000289 int rtcp_packet_length) {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000290 {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000291 CriticalSectionScoped cs(receive_cs_.get());
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000292 if (!receiving_) {
293 return -1;
294 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000295
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000296 if (rtp_dump_) {
297 rtp_dump_->DumpPacket(
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000298 rtcp_packet, static_cast<uint16_t>(rtcp_packet_length));
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000299 }
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000300
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000301 std::list<RtpRtcp*>::iterator it = rtp_rtcp_simulcast_.begin();
302 while (it != rtp_rtcp_simulcast_.end()) {
303 RtpRtcp* rtp_rtcp = *it++;
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000304 rtp_rtcp->IncomingRtcpPacket(rtcp_packet, rtcp_packet_length);
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000305 }
306 }
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000307 assert(rtp_rtcp_); // Should be set by owner at construction time.
solenberg@webrtc.orgfc320462014-02-11 15:27:49 +0000308 return rtp_rtcp_->IncomingRtcpPacket(rtcp_packet, rtcp_packet_length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000309}
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000310
311void ViEReceiver::StartReceive() {
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000312 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000313 receiving_ = true;
314}
315
316void ViEReceiver::StopReceive() {
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000317 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000318 receiving_ = false;
319}
320
321int ViEReceiver::StartRTPDump(const char file_nameUTF8[1024]) {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000322 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000323 if (rtp_dump_) {
324 // Restart it if it already exists and is started
325 rtp_dump_->Stop();
326 } else {
327 rtp_dump_ = RtpDump::CreateRtpDump();
328 if (rtp_dump_ == NULL) {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000329 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, channel_id_,
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000330 "StartRTPDump: Failed to create RTP dump");
331 return -1;
332 }
333 }
334 if (rtp_dump_->Start(file_nameUTF8) != 0) {
335 RtpDump::DestroyRtpDump(rtp_dump_);
336 rtp_dump_ = NULL;
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000337 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, channel_id_,
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000338 "StartRTPDump: Failed to start RTP dump");
339 return -1;
340 }
341 return 0;
342}
343
344int ViEReceiver::StopRTPDump() {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000345 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000346 if (rtp_dump_) {
347 if (rtp_dump_->IsActive()) {
348 rtp_dump_->Stop();
349 } else {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000350 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, channel_id_,
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000351 "StopRTPDump: Dump not active");
352 }
353 RtpDump::DestroyRtpDump(rtp_dump_);
354 rtp_dump_ = NULL;
355 } else {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000356 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, channel_id_,
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000357 "StopRTPDump: RTP dump not started");
358 return -1;
359 }
360 return 0;
361}
362
stefan@webrtc.orgb5865072013-02-01 14:33:42 +0000363// TODO(holmer): To be moved to ViEChannelGroup.
mflodman@webrtc.org4fd55272013-02-06 17:46:39 +0000364void ViEReceiver::EstimatedReceiveBandwidth(
stefan@webrtc.orgb5865072013-02-01 14:33:42 +0000365 unsigned int* available_bandwidth) const {
366 std::vector<unsigned int> ssrcs;
mflodman@webrtc.org4fd55272013-02-06 17:46:39 +0000367
368 // LatestEstimate returns an error if there is no valid bitrate estimate, but
369 // ViEReceiver instead returns a zero estimate.
370 remote_bitrate_estimator_->LatestEstimate(&ssrcs, available_bandwidth);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000371 if (std::find(ssrcs.begin(), ssrcs.end(), rtp_receiver_->SSRC()) !=
mflodman@webrtc.orga066cbf2013-05-28 15:00:15 +0000372 ssrcs.end()) {
stefan@webrtc.orgb5865072013-02-01 14:33:42 +0000373 *available_bandwidth /= ssrcs.size();
mflodman@webrtc.org4fd55272013-02-06 17:46:39 +0000374 } else {
375 *available_bandwidth = 0;
stefan@webrtc.orgb5865072013-02-01 14:33:42 +0000376 }
stefan@webrtc.orgb5865072013-02-01 14:33:42 +0000377}
378
jiayl@webrtc.org1f64f062014-02-10 19:12:14 +0000379void ViEReceiver::GetReceiveBandwidthEstimatorStats(
380 ReceiveBandwidthEstimatorStats* output) const {
381 remote_bitrate_estimator_->GetStats(output);
382}
383
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000384ReceiveStatistics* ViEReceiver::GetReceiveStatistics() const {
385 return rtp_receive_statistics_.get();
386}
387
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000388bool ViEReceiver::IsPacketInOrder(const RTPHeader& header) const {
389 StreamStatistician* statistician =
390 rtp_receive_statistics_->GetStatistician(header.ssrc);
391 if (!statistician)
392 return false;
393 return statistician->IsPacketInOrder(header.sequenceNumber);
394}
395
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000396bool ViEReceiver::IsPacketRetransmitted(const RTPHeader& header,
397 bool in_order) const {
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000398 // Retransmissions are handled separately if RTX is enabled.
399 if (rtp_payload_registry_->RtxEnabled())
400 return false;
401 StreamStatistician* statistician =
402 rtp_receive_statistics_->GetStatistician(header.ssrc);
403 if (!statistician)
404 return false;
405 // Check if this is a retransmission.
406 uint16_t min_rtt = 0;
407 rtp_rtcp_->RTT(rtp_receiver_->SSRC(), NULL, NULL, &min_rtt, NULL);
stefan@webrtc.org48df3812013-11-08 15:18:52 +0000408 return !in_order &&
stefan@webrtc.org7bb8f022013-09-06 13:40:11 +0000409 statistician->IsRetransmitOfOldPacket(header, min_rtt);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000410}
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000411} // namespace webrtc