blob: 2edf68b767f9418e5b39a10ff698b76f9dfb74d1 [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"
wu@webrtc.org822fbd82013-08-15 23:38:54 +000016#include "webrtc/modules/rtp_rtcp/interface/receive_statistics.h"
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000017#include "webrtc/modules/rtp_rtcp/interface/rtp_header_parser.h"
wu@webrtc.org822fbd82013-08-15 23:38:54 +000018#include "webrtc/modules/rtp_rtcp/interface/rtp_payload_registry.h"
19#include "webrtc/modules/rtp_rtcp/interface/rtp_receiver.h"
pbos@webrtc.orgf5d4cb12013-05-17 13:44:48 +000020#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp.h"
21#include "webrtc/modules/utility/interface/rtp_dump.h"
22#include "webrtc/modules/video_coding/main/interface/video_coding.h"
23#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
24#include "webrtc/system_wrappers/interface/tick_util.h"
25#include "webrtc/system_wrappers/interface/trace.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000026
27namespace webrtc {
28
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +000029ViEReceiver::ViEReceiver(const int32_t channel_id,
stefan@webrtc.org976a7e62012-09-21 13:20:21 +000030 VideoCodingModule* module_vcm,
wu@webrtc.org822fbd82013-08-15 23:38:54 +000031 RemoteBitrateEstimator* remote_bitrate_estimator,
32 RtpFeedback* rtp_feedback)
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +000033 : receive_cs_(CriticalSectionWrapper::CreateCriticalSection()),
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000034 channel_id_(channel_id),
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +000035 rtp_header_parser_(RtpHeaderParser::Create()),
wu@webrtc.org822fbd82013-08-15 23:38:54 +000036 rtp_payload_registry_(new RTPPayloadRegistry(
37 channel_id, RTPPayloadStrategy::CreateStrategy(false))),
38 rtp_receiver_(RtpReceiver::CreateVideoReceiver(
39 channel_id, Clock::GetRealTimeClock(), this, rtp_feedback,
40 rtp_payload_registry_.get())),
41 rtp_receive_statistics_(ReceiveStatistics::Create(
42 Clock::GetRealTimeClock())),
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +000043 rtp_rtcp_(NULL),
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000044 vcm_(module_vcm),
stefan@webrtc.org976a7e62012-09-21 13:20:21 +000045 remote_bitrate_estimator_(remote_bitrate_estimator),
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000046 external_decryption_(NULL),
47 decryption_buffer_(NULL),
48 rtp_dump_(NULL),
49 receiving_(false) {
stefan@webrtc.org976a7e62012-09-21 13:20:21 +000050 assert(remote_bitrate_estimator);
niklase@google.com470e71d2011-07-07 08:21:25 +000051}
52
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000053ViEReceiver::~ViEReceiver() {
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +000054 if (decryption_buffer_) {
55 delete[] decryption_buffer_;
56 decryption_buffer_ = NULL;
57 }
58 if (rtp_dump_) {
59 rtp_dump_->Stop();
60 RtpDump::DestroyRtpDump(rtp_dump_);
61 rtp_dump_ = NULL;
62 }
niklase@google.com470e71d2011-07-07 08:21:25 +000063}
64
wu@webrtc.org822fbd82013-08-15 23:38:54 +000065bool ViEReceiver::SetReceiveCodec(const VideoCodec& video_codec) {
66 int8_t old_pltype = -1;
67 if (rtp_payload_registry_->ReceivePayloadType(video_codec.plName,
68 kVideoPayloadTypeFrequency,
69 0,
70 video_codec.maxBitrate,
71 &old_pltype) != -1) {
72 rtp_payload_registry_->DeRegisterReceivePayload(old_pltype);
73 }
74
75 return RegisterPayload(video_codec);
76}
77
78bool ViEReceiver::RegisterPayload(const VideoCodec& video_codec) {
79 return rtp_receiver_->RegisterReceivePayload(video_codec.plName,
80 video_codec.plType,
81 kVideoPayloadTypeFrequency,
82 0,
83 video_codec.maxBitrate) == 0;
84}
85
86bool ViEReceiver::SetNackStatus(bool enable,
87 int max_nack_reordering_threshold) {
88 return rtp_receiver_->SetNACKStatus(enable ? kNackRtcp : kNackOff,
89 max_nack_reordering_threshold) == 0;
90}
91
92void ViEReceiver::SetRtxStatus(bool enable, uint32_t ssrc) {
93 rtp_receiver_->SetRTXStatus(true, ssrc);
94}
95
96void ViEReceiver::SetRtxPayloadType(uint32_t payload_type) {
97 rtp_receiver_->SetRtxPayloadType(payload_type);
98}
99
100uint32_t ViEReceiver::GetRemoteSsrc() const {
101 return rtp_receiver_->SSRC();
102}
103
104int ViEReceiver::GetCsrcs(uint32_t* csrcs) const {
105 return rtp_receiver_->CSRCs(csrcs);
106}
107
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000108int ViEReceiver::RegisterExternalDecryption(Encryption* decryption) {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000109 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000110 if (external_decryption_) {
111 return -1;
112 }
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000113 decryption_buffer_ = new uint8_t[kViEMaxMtu];
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000114 if (decryption_buffer_ == NULL) {
115 return -1;
116 }
117 external_decryption_ = decryption;
118 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000119}
120
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000121int ViEReceiver::DeregisterExternalDecryption() {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000122 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000123 if (external_decryption_ == NULL) {
124 return -1;
125 }
126 external_decryption_ = NULL;
127 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000128}
129
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000130void ViEReceiver::SetRtpRtcpModule(RtpRtcp* module) {
131 rtp_rtcp_ = module;
132}
133
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000134RtpReceiver* ViEReceiver::GetRtpReceiver() const {
135 return rtp_receiver_.get();
136}
137
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000138void ViEReceiver::RegisterSimulcastRtpRtcpModules(
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000139 const std::list<RtpRtcp*>& rtp_modules) {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000140 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000141 rtp_rtcp_simulcast_.clear();
142
143 if (!rtp_modules.empty()) {
144 rtp_rtcp_simulcast_.insert(rtp_rtcp_simulcast_.begin(),
145 rtp_modules.begin(),
146 rtp_modules.end());
147 }
pwestin@webrtc.org1da1ce02011-10-13 15:19:55 +0000148}
149
stefan@webrtc.org08994cc2013-05-29 13:28:21 +0000150bool ViEReceiver::SetReceiveTimestampOffsetStatus(bool enable, int id) {
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000151 if (enable) {
152 return rtp_header_parser_->RegisterRtpHeaderExtension(
153 kRtpExtensionTransmissionTimeOffset, id);
154 } else {
155 return rtp_header_parser_->DeregisterRtpHeaderExtension(
156 kRtpExtensionTransmissionTimeOffset);
157 }
158}
159
stefan@webrtc.org08994cc2013-05-29 13:28:21 +0000160bool ViEReceiver::SetReceiveAbsoluteSendTimeStatus(bool enable, int id) {
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000161 if (enable) {
162 return rtp_header_parser_->RegisterRtpHeaderExtension(
163 kRtpExtensionAbsoluteSendTime, id);
164 } else {
165 return rtp_header_parser_->DeregisterRtpHeaderExtension(
166 kRtpExtensionAbsoluteSendTime);
167 }
168}
169
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000170int ViEReceiver::ReceivedRTPPacket(const void* rtp_packet,
171 int rtp_packet_length) {
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000172 return InsertRTPPacket(static_cast<const int8_t*>(rtp_packet),
173 rtp_packet_length);
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000174}
175
176int ViEReceiver::ReceivedRTCPPacket(const void* rtcp_packet,
177 int rtcp_packet_length) {
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000178 return InsertRTCPPacket(static_cast<const int8_t*>(rtcp_packet),
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000179 rtcp_packet_length);
180}
181
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000182int32_t ViEReceiver::OnReceivedPayloadData(
183 const uint8_t* payload_data, const uint16_t payload_size,
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000184 const WebRtcRTPHeader* rtp_header) {
185 if (rtp_header == NULL) {
niklase@google.com470e71d2011-07-07 08:21:25 +0000186 return 0;
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000187 }
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000188 if (vcm_->IncomingPacket(payload_data, payload_size, *rtp_header) != 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)) {
199 WEBRTC_TRACE(kTraceDebug, webrtc::kTraceVideo, channel_id_,
200 "IncomingPacket invalid RTP header");
201 return false;
202 }
203 header.payload_type_frequency = kVideoPayloadTypeFrequency;
204 PayloadUnion payload_specific;
205 if (!rtp_payload_registry_->GetPayloadSpecifics(header.payloadType,
206 &payload_specific)) {
207 return false;
208 }
209 return rtp_receiver_->IncomingRtpPacket(&header, rtp_packet,
210 rtp_packet_length,
211 payload_specific, false);
212}
213
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000214int ViEReceiver::InsertRTPPacket(const int8_t* rtp_packet,
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000215 int rtp_packet_length) {
216 // TODO(mflodman) Change decrypt to get rid of this cast.
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000217 int8_t* tmp_ptr = const_cast<int8_t*>(rtp_packet);
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000218 unsigned char* received_packet = reinterpret_cast<unsigned char*>(tmp_ptr);
219 int received_packet_length = rtp_packet_length;
niklase@google.com470e71d2011-07-07 08:21:25 +0000220
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000221 {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000222 CriticalSectionScoped cs(receive_cs_.get());
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000223 if (!receiving_) {
224 return -1;
225 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000226
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000227 if (external_decryption_) {
mflodman@webrtc.org34e83b82012-10-17 11:05:54 +0000228 int decrypted_length = kViEMaxMtu;
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000229 external_decryption_->decrypt(channel_id_, received_packet,
230 decryption_buffer_, received_packet_length,
231 &decrypted_length);
232 if (decrypted_length <= 0) {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000233 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, channel_id_,
234 "RTP decryption failed");
niklase@google.com470e71d2011-07-07 08:21:25 +0000235 return -1;
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000236 } else if (decrypted_length > kViEMaxMtu) {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000237 WEBRTC_TRACE(webrtc::kTraceCritical, webrtc::kTraceVideo, channel_id_,
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000238 "InsertRTPPacket: %d bytes is allocated as RTP decrytption"
239 " output, external decryption used %d bytes. => memory is "
240 " now corrupted", kViEMaxMtu, decrypted_length);
241 return -1;
242 }
243 received_packet = decryption_buffer_;
244 received_packet_length = decrypted_length;
niklase@google.com470e71d2011-07-07 08:21:25 +0000245 }
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000246
247 if (rtp_dump_) {
248 rtp_dump_->DumpPacket(received_packet,
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000249 static_cast<uint16_t>(received_packet_length));
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000250 }
251 }
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000252 RTPHeader header;
253 if (!rtp_header_parser_->Parse(received_packet, received_packet_length,
254 &header)) {
255 WEBRTC_TRACE(webrtc::kTraceDebug, webrtc::kTraceVideo, channel_id_,
256 "IncomingPacket invalid RTP header");
257 return -1;
258 }
stefan@webrtc.orgde984782013-06-04 12:15:40 +0000259 const int payload_size = received_packet_length - header.headerLength;
260 remote_bitrate_estimator_->IncomingPacket(TickTime::MillisecondTimestamp(),
261 payload_size, header);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000262 header.payload_type_frequency = kVideoPayloadTypeFrequency;
263 bool in_order = rtp_receiver_->InOrderPacket(header.sequenceNumber);
264 bool retransmitted = !in_order && IsPacketRetransmitted(header);
265 rtp_receive_statistics_->IncomingPacket(header, received_packet_length,
266 retransmitted, in_order);
267 PayloadUnion payload_specific;
268 if (!rtp_payload_registry_->GetPayloadSpecifics(header.payloadType,
269 &payload_specific)) {
270 return -1;
271 }
272 return rtp_receiver_->IncomingRtpPacket(&header, received_packet,
273 received_packet_length,
274 payload_specific, in_order) ? 0 : -1;
niklase@google.com470e71d2011-07-07 08:21:25 +0000275}
276
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000277int ViEReceiver::InsertRTCPPacket(const int8_t* rtcp_packet,
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000278 int rtcp_packet_length) {
279 // TODO(mflodman) Change decrypt to get rid of this cast.
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000280 int8_t* tmp_ptr = const_cast<int8_t*>(rtcp_packet);
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000281 unsigned char* received_packet = reinterpret_cast<unsigned char*>(tmp_ptr);
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000282 int received_packet_length = rtcp_packet_length;
283 {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000284 CriticalSectionScoped cs(receive_cs_.get());
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000285 if (!receiving_) {
286 return -1;
287 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000288
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000289 if (external_decryption_) {
mflodman@webrtc.org34e83b82012-10-17 11:05:54 +0000290 int decrypted_length = kViEMaxMtu;
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000291 external_decryption_->decrypt_rtcp(channel_id_, received_packet,
292 decryption_buffer_,
293 received_packet_length,
294 &decrypted_length);
295 if (decrypted_length <= 0) {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000296 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, channel_id_,
297 "RTP decryption failed");
niklase@google.com470e71d2011-07-07 08:21:25 +0000298 return -1;
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000299 } else if (decrypted_length > kViEMaxMtu) {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000300 WEBRTC_TRACE(webrtc::kTraceCritical, webrtc::kTraceVideo, channel_id_,
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000301 "InsertRTCPPacket: %d bytes is allocated as RTP "
302 " decrytption output, external decryption used %d bytes. "
303 " => memory is now corrupted",
304 kViEMaxMtu, decrypted_length);
305 return -1;
306 }
307 received_packet = decryption_buffer_;
308 received_packet_length = decrypted_length;
niklase@google.com470e71d2011-07-07 08:21:25 +0000309 }
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000310
311 if (rtp_dump_) {
312 rtp_dump_->DumpPacket(
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000313 received_packet, static_cast<uint16_t>(received_packet_length));
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000314 }
315 }
316 {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000317 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000318 std::list<RtpRtcp*>::iterator it = rtp_rtcp_simulcast_.begin();
319 while (it != rtp_rtcp_simulcast_.end()) {
320 RtpRtcp* rtp_rtcp = *it++;
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000321 rtp_rtcp->IncomingRtcpPacket(received_packet, received_packet_length);
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000322 }
323 }
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000324 assert(rtp_rtcp_); // Should be set by owner at construction time.
stefan@webrtc.orga5cb98c2013-05-29 12:12:51 +0000325 return rtp_rtcp_->IncomingRtcpPacket(received_packet, received_packet_length);
niklase@google.com470e71d2011-07-07 08:21:25 +0000326}
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000327
328void ViEReceiver::StartReceive() {
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000329 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000330 receiving_ = true;
331}
332
333void ViEReceiver::StopReceive() {
braveyao@webrtc.orgb6433b72013-07-26 09:02:46 +0000334 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000335 receiving_ = false;
336}
337
338int ViEReceiver::StartRTPDump(const char file_nameUTF8[1024]) {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000339 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000340 if (rtp_dump_) {
341 // Restart it if it already exists and is started
342 rtp_dump_->Stop();
343 } else {
344 rtp_dump_ = RtpDump::CreateRtpDump();
345 if (rtp_dump_ == NULL) {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000346 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, channel_id_,
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000347 "StartRTPDump: Failed to create RTP dump");
348 return -1;
349 }
350 }
351 if (rtp_dump_->Start(file_nameUTF8) != 0) {
352 RtpDump::DestroyRtpDump(rtp_dump_);
353 rtp_dump_ = NULL;
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000354 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, channel_id_,
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000355 "StartRTPDump: Failed to start RTP dump");
356 return -1;
357 }
358 return 0;
359}
360
361int ViEReceiver::StopRTPDump() {
mflodman@webrtc.orgd32c4472011-12-22 14:17:53 +0000362 CriticalSectionScoped cs(receive_cs_.get());
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000363 if (rtp_dump_) {
364 if (rtp_dump_->IsActive()) {
365 rtp_dump_->Stop();
366 } else {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000367 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, channel_id_,
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000368 "StopRTPDump: Dump not active");
369 }
370 RtpDump::DestroyRtpDump(rtp_dump_);
371 rtp_dump_ = NULL;
372 } else {
pwestin@webrtc.org2853dde2012-05-11 11:08:54 +0000373 WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideo, channel_id_,
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000374 "StopRTPDump: RTP dump not started");
375 return -1;
376 }
377 return 0;
378}
379
stefan@webrtc.orgb5865072013-02-01 14:33:42 +0000380// TODO(holmer): To be moved to ViEChannelGroup.
mflodman@webrtc.org4fd55272013-02-06 17:46:39 +0000381void ViEReceiver::EstimatedReceiveBandwidth(
stefan@webrtc.orgb5865072013-02-01 14:33:42 +0000382 unsigned int* available_bandwidth) const {
383 std::vector<unsigned int> ssrcs;
mflodman@webrtc.org4fd55272013-02-06 17:46:39 +0000384
385 // LatestEstimate returns an error if there is no valid bitrate estimate, but
386 // ViEReceiver instead returns a zero estimate.
387 remote_bitrate_estimator_->LatestEstimate(&ssrcs, available_bandwidth);
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000388 if (std::find(ssrcs.begin(), ssrcs.end(), rtp_receiver_->SSRC()) !=
mflodman@webrtc.orga066cbf2013-05-28 15:00:15 +0000389 ssrcs.end()) {
stefan@webrtc.orgb5865072013-02-01 14:33:42 +0000390 *available_bandwidth /= ssrcs.size();
mflodman@webrtc.org4fd55272013-02-06 17:46:39 +0000391 } else {
392 *available_bandwidth = 0;
stefan@webrtc.orgb5865072013-02-01 14:33:42 +0000393 }
stefan@webrtc.orgb5865072013-02-01 14:33:42 +0000394}
395
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000396ReceiveStatistics* ViEReceiver::GetReceiveStatistics() const {
397 return rtp_receive_statistics_.get();
398}
399
400bool ViEReceiver::IsPacketRetransmitted(const RTPHeader& header) const {
401 bool rtx_enabled = false;
402 uint32_t rtx_ssrc = 0;
403 int rtx_payload_type = 0;
404 rtp_receiver_->RTXStatus(&rtx_enabled, &rtx_ssrc, &rtx_payload_type);
405 if (!rtx_enabled) {
406 // Check if this is a retransmission.
407 ReceiveStatistics::RtpReceiveStatistics stats;
408 if (rtp_receive_statistics_->Statistics(&stats, false)) {
409 uint16_t min_rtt = 0;
410 rtp_rtcp_->RTT(rtp_receiver_->SSRC(), NULL, NULL, &min_rtt, NULL);
411 return rtp_receiver_->RetransmitOfOldPacket(header, stats.jitter,
412 min_rtt);
413 }
414 }
415 return false;
416}
mflodman@webrtc.orgad4ee362011-11-28 22:39:24 +0000417} // namespace webrtc