2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-01-24 17:16:59 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-29 14:27:38 +00:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_receiver.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-04-23 17:53:17 +02:00
|
|
|
#include <assert.h>
|
|
|
|
|
#include <string.h>
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-08-16 03:21:38 -07:00
|
|
|
#include <limits>
|
2016-09-23 10:36:03 -07:00
|
|
|
#include <memory>
|
|
|
|
|
#include <utility>
|
2016-08-16 03:21:38 -07:00
|
|
|
|
2015-04-23 17:53:17 +02:00
|
|
|
#include "webrtc/base/checks.h"
|
2015-10-28 16:39:33 +01:00
|
|
|
#include "webrtc/base/logging.h"
|
2015-10-20 23:00:48 -07:00
|
|
|
#include "webrtc/base/trace_event.h"
|
2016-09-20 01:39:54 -07:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h"
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h"
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/compound_packet.h"
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/extended_reports.h"
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/fir.h"
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/nack.h"
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/pli.h"
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/rapid_resync_request.h"
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/receiver_report.h"
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.h"
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi.h"
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sdes.h"
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sli.h"
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbn.h"
|
|
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr.h"
|
2015-09-24 15:06:57 +02:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
|
2015-10-20 23:00:48 -07:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
|
2016-02-22 18:59:36 +01:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/time_util.h"
|
2016-05-24 13:25:27 -07:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h"
|
2016-02-22 18:59:36 +01:00
|
|
|
#include "webrtc/system_wrappers/include/ntp_time.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2016-09-20 01:39:54 -07:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
using rtcp::CommonHeader;
|
|
|
|
|
using rtcp::ReportBlock;
|
2015-12-10 12:39:08 -08:00
|
|
|
using RTCPHelp::RTCPReceiveInformation;
|
|
|
|
|
using RTCPHelp::RTCPReportBlockInformation;
|
|
|
|
|
using RTCPUtility::RTCPCnameInformation;
|
|
|
|
|
using RTCPUtility::RTCPPacketReportBlockItem;
|
|
|
|
|
using RTCPUtility::RTCPPacketTypes;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-01-09 13:54:43 +00:00
|
|
|
// The number of RTCP time intervals needed to trigger a timeout.
|
|
|
|
|
const int kRrTimeoutIntervals = 3;
|
|
|
|
|
|
2015-09-24 15:06:57 +02:00
|
|
|
const int64_t kMaxWarningLogIntervalMs = 10000;
|
|
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
} // namespace
|
|
|
|
|
|
2016-09-23 10:36:03 -07:00
|
|
|
struct RTCPReceiver::PacketInformation {
|
|
|
|
|
uint32_t packet_type_flags = 0; // RTCPPacketTypeFlags bit field.
|
|
|
|
|
|
|
|
|
|
uint32_t remote_ssrc = 0;
|
|
|
|
|
std::vector<uint16_t> nack_sequence_numbers;
|
|
|
|
|
ReportBlockList report_blocks;
|
|
|
|
|
int64_t rtt_ms = 0;
|
|
|
|
|
uint8_t sli_picture_id = 0;
|
|
|
|
|
uint64_t rpsi_picture_id = 0;
|
|
|
|
|
uint32_t receiver_estimated_max_bitrate_bps = 0;
|
|
|
|
|
std::unique_ptr<rtcp::TransportFeedback> transport_feedback;
|
|
|
|
|
};
|
|
|
|
|
|
2015-02-19 12:47:00 +00:00
|
|
|
RTCPReceiver::RTCPReceiver(
|
|
|
|
|
Clock* clock,
|
2015-04-23 17:53:17 +02:00
|
|
|
bool receiver_only,
|
2015-02-19 12:47:00 +00:00
|
|
|
RtcpPacketTypeCounterObserver* packet_type_counter_observer,
|
2015-02-25 13:50:10 +00:00
|
|
|
RtcpBandwidthObserver* rtcp_bandwidth_observer,
|
|
|
|
|
RtcpIntraFrameObserver* rtcp_intra_frame_observer,
|
2015-09-24 15:06:57 +02:00
|
|
|
TransportFeedbackObserver* transport_feedback_observer,
|
2016-08-29 11:08:47 -07:00
|
|
|
ModuleRtpRtcp* owner)
|
2016-05-24 13:25:27 -07:00
|
|
|
: _clock(clock),
|
2015-04-23 17:53:17 +02:00
|
|
|
receiver_only_(receiver_only),
|
2014-12-19 13:49:55 +00:00
|
|
|
_rtpRtcp(*owner),
|
2015-02-25 13:50:10 +00:00
|
|
|
_cbRtcpBandwidthObserver(rtcp_bandwidth_observer),
|
|
|
|
|
_cbRtcpIntraFrameObserver(rtcp_intra_frame_observer),
|
2015-09-24 15:06:57 +02:00
|
|
|
_cbTransportFeedbackObserver(transport_feedback_observer),
|
2014-12-19 13:49:55 +00:00
|
|
|
main_ssrc_(0),
|
|
|
|
|
_remoteSSRC(0),
|
|
|
|
|
_remoteSenderInfo(),
|
|
|
|
|
_lastReceivedSRNTPsecs(0),
|
|
|
|
|
_lastReceivedSRNTPfrac(0),
|
|
|
|
|
_lastReceivedXRNTPsecs(0),
|
|
|
|
|
_lastReceivedXRNTPfrac(0),
|
2016-03-09 15:14:35 +01:00
|
|
|
xr_rrtr_status_(false),
|
2014-12-19 13:49:55 +00:00
|
|
|
xr_rr_rtt_ms_(0),
|
|
|
|
|
_receivedInfoMap(),
|
|
|
|
|
_lastReceivedRrMs(0),
|
|
|
|
|
_lastIncreasedSequenceNumberMs(0),
|
2015-02-19 12:47:00 +00:00
|
|
|
stats_callback_(NULL),
|
2015-09-24 15:06:57 +02:00
|
|
|
packet_type_counter_observer_(packet_type_counter_observer),
|
|
|
|
|
num_skipped_packets_(0),
|
|
|
|
|
last_skipped_packets_warning_(clock->TimeInMilliseconds()) {
|
2015-01-21 13:07:04 +00:00
|
|
|
memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo));
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-19 15:53:09 +00:00
|
|
|
RTCPReceiver::~RTCPReceiver() {
|
2014-12-18 14:30:32 +00:00
|
|
|
ReportBlockMap::iterator it = _receivedReportBlockMap.begin();
|
|
|
|
|
for (; it != _receivedReportBlockMap.end(); ++it) {
|
|
|
|
|
ReportBlockInfoMap* info_map = &(it->second);
|
|
|
|
|
while (!info_map->empty()) {
|
|
|
|
|
ReportBlockInfoMap::iterator it_info = info_map->begin();
|
|
|
|
|
delete it_info->second;
|
|
|
|
|
info_map->erase(it_info);
|
|
|
|
|
}
|
2012-01-19 15:53:09 +00:00
|
|
|
}
|
|
|
|
|
while (!_receivedInfoMap.empty()) {
|
2013-04-08 11:08:41 +00:00
|
|
|
std::map<uint32_t, RTCPReceiveInformation*>::iterator first =
|
2012-01-19 15:53:09 +00:00
|
|
|
_receivedInfoMap.begin();
|
|
|
|
|
delete first->second;
|
|
|
|
|
_receivedInfoMap.erase(first);
|
|
|
|
|
}
|
|
|
|
|
while (!_receivedCnameMap.empty()) {
|
2013-04-08 11:08:41 +00:00
|
|
|
std::map<uint32_t, RTCPCnameInformation*>::iterator first =
|
2012-01-19 15:53:09 +00:00
|
|
|
_receivedCnameMap.begin();
|
|
|
|
|
delete first->second;
|
|
|
|
|
_receivedCnameMap.erase(first);
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-08-29 11:08:47 -07:00
|
|
|
bool RTCPReceiver::IncomingPacket(const uint8_t* packet, size_t packet_size) {
|
2016-09-20 01:39:54 -07:00
|
|
|
if (packet_size == 0) {
|
|
|
|
|
LOG(LS_WARNING) << "Incoming empty RTCP packet";
|
2016-08-29 11:08:47 -07:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-23 10:36:03 -07:00
|
|
|
PacketInformation packet_information;
|
2016-09-20 01:39:54 -07:00
|
|
|
if (!ParseCompoundPacket(packet, packet + packet_size, &packet_information))
|
|
|
|
|
return false;
|
|
|
|
|
TriggerCallbacksFromRTCPPacket(packet_information);
|
|
|
|
|
return true;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-21 13:07:04 +00:00
|
|
|
int64_t RTCPReceiver::LastReceivedReceiverReport() const {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
2015-01-21 13:07:04 +00:00
|
|
|
int64_t last_received_rr = -1;
|
|
|
|
|
for (ReceivedInfoMap::const_iterator it = _receivedInfoMap.begin();
|
|
|
|
|
it != _receivedInfoMap.end(); ++it) {
|
2016-08-18 06:17:42 -07:00
|
|
|
if (it->second->last_time_received_ms > last_received_rr) {
|
|
|
|
|
last_received_rr = it->second->last_time_received_ms;
|
2013-02-01 14:33:42 +00:00
|
|
|
}
|
2015-01-21 13:07:04 +00:00
|
|
|
}
|
|
|
|
|
return last_received_rr;
|
2013-02-01 14:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-21 13:07:04 +00:00
|
|
|
void RTCPReceiver::SetRemoteSSRC(uint32_t ssrc) {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-01-21 13:07:04 +00:00
|
|
|
// new SSRC reset old reports
|
|
|
|
|
memset(&_remoteSenderInfo, 0, sizeof(_remoteSenderInfo));
|
|
|
|
|
_lastReceivedSRNTPsecs = 0;
|
|
|
|
|
_lastReceivedSRNTPfrac = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-01-21 13:07:04 +00:00
|
|
|
_remoteSSRC = ssrc;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-15 23:38:54 +00:00
|
|
|
uint32_t RTCPReceiver::RemoteSSRC() const {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
2013-08-15 23:38:54 +00:00
|
|
|
return _remoteSSRC;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-17 07:49:56 +00:00
|
|
|
void RTCPReceiver::SetSsrcs(uint32_t main_ssrc,
|
|
|
|
|
const std::set<uint32_t>& registered_ssrcs) {
|
2013-04-08 11:08:41 +00:00
|
|
|
uint32_t old_ssrc = 0;
|
2012-10-05 16:17:41 +00:00
|
|
|
{
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
2013-09-17 07:49:56 +00:00
|
|
|
old_ssrc = main_ssrc_;
|
|
|
|
|
main_ssrc_ = main_ssrc;
|
|
|
|
|
registered_ssrcs_ = registered_ssrcs;
|
2012-10-05 16:17:41 +00:00
|
|
|
}
|
|
|
|
|
{
|
2013-09-17 07:49:56 +00:00
|
|
|
if (_cbRtcpIntraFrameObserver && old_ssrc != main_ssrc) {
|
|
|
|
|
_cbRtcpIntraFrameObserver->OnLocalSsrcChanged(old_ssrc, main_ssrc);
|
2012-10-05 16:17:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-15 23:38:54 +00:00
|
|
|
int32_t RTCPReceiver::RTT(uint32_t remoteSSRC,
|
2015-01-12 21:51:21 +00:00
|
|
|
int64_t* RTT,
|
|
|
|
|
int64_t* avgRTT,
|
|
|
|
|
int64_t* minRTT,
|
|
|
|
|
int64_t* maxRTT) const {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
2012-01-11 13:00:08 +00:00
|
|
|
|
|
|
|
|
RTCPReportBlockInformation* reportBlock =
|
2014-12-18 14:30:32 +00:00
|
|
|
GetReportBlockInformation(remoteSSRC, main_ssrc_);
|
2012-01-11 13:00:08 +00:00
|
|
|
|
|
|
|
|
if (reportBlock == NULL) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
if (RTT) {
|
|
|
|
|
*RTT = reportBlock->RTT;
|
|
|
|
|
}
|
|
|
|
|
if (avgRTT) {
|
|
|
|
|
*avgRTT = reportBlock->avgRTT;
|
|
|
|
|
}
|
|
|
|
|
if (minRTT) {
|
|
|
|
|
*minRTT = reportBlock->minRTT;
|
|
|
|
|
}
|
|
|
|
|
if (maxRTT) {
|
|
|
|
|
*maxRTT = reportBlock->maxRTT;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-09 15:14:35 +01:00
|
|
|
void RTCPReceiver::SetRtcpXrRrtrStatus(bool enable) {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
2016-03-09 15:14:35 +01:00
|
|
|
xr_rrtr_status_ = enable;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-12 21:51:21 +00:00
|
|
|
bool RTCPReceiver::GetAndResetXrRrRtt(int64_t* rtt_ms) {
|
2013-10-31 12:14:34 +00:00
|
|
|
assert(rtt_ms);
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
2013-10-31 12:14:34 +00:00
|
|
|
if (xr_rr_rtt_ms_ == 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
*rtt_ms = xr_rr_rtt_ms_;
|
|
|
|
|
xr_rr_rtt_ms_ = 0;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-15 15:25:39 +00:00
|
|
|
// TODO(pbos): Make this fail when we haven't received NTP.
|
|
|
|
|
bool RTCPReceiver::NTP(uint32_t* ReceivedNTPsecs,
|
|
|
|
|
uint32_t* ReceivedNTPfrac,
|
|
|
|
|
uint32_t* RTCPArrivalTimeSecs,
|
|
|
|
|
uint32_t* RTCPArrivalTimeFrac,
|
2016-08-19 07:29:46 -07:00
|
|
|
uint32_t* rtcp_timestamp) const {
|
|
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
|
|
|
|
if (ReceivedNTPsecs) {
|
|
|
|
|
*ReceivedNTPsecs =
|
|
|
|
|
_remoteSenderInfo.NTPseconds; // NTP from incoming SendReport
|
|
|
|
|
}
|
|
|
|
|
if (ReceivedNTPfrac) {
|
|
|
|
|
*ReceivedNTPfrac = _remoteSenderInfo.NTPfraction;
|
|
|
|
|
}
|
|
|
|
|
if (RTCPArrivalTimeFrac) {
|
|
|
|
|
*RTCPArrivalTimeFrac = _lastReceivedSRNTPfrac; // local NTP time when we
|
|
|
|
|
// received a RTCP packet
|
|
|
|
|
// with a send block
|
|
|
|
|
}
|
|
|
|
|
if (RTCPArrivalTimeSecs) {
|
|
|
|
|
*RTCPArrivalTimeSecs = _lastReceivedSRNTPsecs;
|
|
|
|
|
}
|
|
|
|
|
if (rtcp_timestamp) {
|
|
|
|
|
*rtcp_timestamp = _remoteSenderInfo.RTPtimeStamp;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-02 13:15:34 +00:00
|
|
|
bool RTCPReceiver::LastReceivedXrReferenceTimeInfo(
|
|
|
|
|
RtcpReceiveTimeInfo* info) const {
|
|
|
|
|
assert(info);
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
2013-10-02 13:15:34 +00:00
|
|
|
if (_lastReceivedXRNTPsecs == 0 && _lastReceivedXRNTPfrac == 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
info->sourceSSRC = _remoteXRReceiveTimeInfo.sourceSSRC;
|
|
|
|
|
info->lastRR = _remoteXRReceiveTimeInfo.lastRR;
|
|
|
|
|
|
|
|
|
|
// Get the delay since last received report (RFC 3611).
|
2016-08-19 07:29:46 -07:00
|
|
|
uint32_t receive_time =
|
|
|
|
|
RTCPUtility::MidNtp(_lastReceivedXRNTPsecs, _lastReceivedXRNTPfrac);
|
2013-10-02 13:15:34 +00:00
|
|
|
|
|
|
|
|
uint32_t ntp_sec = 0;
|
|
|
|
|
uint32_t ntp_frac = 0;
|
|
|
|
|
_clock->CurrentNtp(ntp_sec, ntp_frac);
|
|
|
|
|
uint32_t now = RTCPUtility::MidNtp(ntp_sec, ntp_frac);
|
|
|
|
|
|
|
|
|
|
info->delaySinceLastRR = now - receive_time;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-08 11:06:12 +00:00
|
|
|
int32_t RTCPReceiver::SenderInfoReceived(RTCPSenderInfo* senderInfo) const {
|
|
|
|
|
assert(senderInfo);
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
2014-04-08 11:06:12 +00:00
|
|
|
if (_lastReceivedSRNTPsecs == 0) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
memcpy(senderInfo, &(_remoteSenderInfo), sizeof(RTCPSenderInfo));
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// statistics
|
|
|
|
|
// we can get multiple receive reports when we receive the report from a CE
|
2013-04-08 11:08:41 +00:00
|
|
|
int32_t RTCPReceiver::StatisticsReceived(
|
2012-01-11 13:00:08 +00:00
|
|
|
std::vector<RTCPReportBlock>* receiveBlocks) const {
|
2012-01-19 15:53:09 +00:00
|
|
|
assert(receiveBlocks);
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
2014-12-18 14:30:32 +00:00
|
|
|
ReportBlockMap::const_iterator it = _receivedReportBlockMap.begin();
|
|
|
|
|
for (; it != _receivedReportBlockMap.end(); ++it) {
|
|
|
|
|
const ReportBlockInfoMap* info_map = &(it->second);
|
|
|
|
|
ReportBlockInfoMap::const_iterator it_info = info_map->begin();
|
|
|
|
|
for (; it_info != info_map->end(); ++it_info) {
|
|
|
|
|
receiveBlocks->push_back(it_info->second->remoteReceiveBlock);
|
|
|
|
|
}
|
2012-01-11 13:00:08 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-23 10:36:03 -07:00
|
|
|
bool RTCPReceiver::ParseCompoundPacket(const uint8_t* packet_begin,
|
|
|
|
|
const uint8_t* packet_end,
|
|
|
|
|
PacketInformation* packet_information) {
|
2016-08-19 07:29:46 -07:00
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
CommonHeader rtcp_block;
|
|
|
|
|
for (const uint8_t* next_block = packet_begin; next_block != packet_end;
|
|
|
|
|
next_block = rtcp_block.NextPacket()) {
|
|
|
|
|
ptrdiff_t remaining_blocks_size = packet_end - next_block;
|
|
|
|
|
RTC_DCHECK_GT(remaining_blocks_size, 0);
|
|
|
|
|
if (!rtcp_block.Parse(next_block, remaining_blocks_size)) {
|
|
|
|
|
if (next_block == packet_begin) {
|
|
|
|
|
// Failed to parse 1st header, nothing was extracted from this packet.
|
|
|
|
|
LOG(LS_WARNING) << "Incoming invalid RTCP packet";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
++num_skipped_packets_;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-08-19 07:29:46 -07:00
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
if (packet_type_counter_.first_packet_time_ms == -1)
|
|
|
|
|
packet_type_counter_.first_packet_time_ms = _clock->TimeInMilliseconds();
|
2016-08-19 07:29:46 -07:00
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
switch (rtcp_block.type()) {
|
|
|
|
|
case rtcp::SenderReport::kPacketType:
|
2016-09-23 10:36:03 -07:00
|
|
|
HandleSenderReport(rtcp_block, packet_information);
|
2016-08-19 07:29:46 -07:00
|
|
|
break;
|
2016-09-20 01:39:54 -07:00
|
|
|
case rtcp::ReceiverReport::kPacketType:
|
2016-09-23 10:36:03 -07:00
|
|
|
HandleReceiverReport(rtcp_block, packet_information);
|
2016-08-19 07:29:46 -07:00
|
|
|
break;
|
2016-09-20 01:39:54 -07:00
|
|
|
case rtcp::Sdes::kPacketType:
|
2016-09-23 10:36:03 -07:00
|
|
|
HandleSDES(rtcp_block, packet_information);
|
2016-08-19 07:29:46 -07:00
|
|
|
break;
|
2016-09-20 01:39:54 -07:00
|
|
|
case rtcp::ExtendedReports::kPacketType:
|
2016-09-23 10:36:03 -07:00
|
|
|
HandleXr(rtcp_block, packet_information);
|
2016-08-19 07:29:46 -07:00
|
|
|
break;
|
2016-09-20 01:39:54 -07:00
|
|
|
case rtcp::Bye::kPacketType:
|
|
|
|
|
HandleBYE(rtcp_block);
|
2016-08-19 07:29:46 -07:00
|
|
|
break;
|
2016-09-20 01:39:54 -07:00
|
|
|
case rtcp::Rtpfb::kPacketType:
|
|
|
|
|
switch (rtcp_block.fmt()) {
|
|
|
|
|
case rtcp::Nack::kFeedbackMessageType:
|
2016-09-23 10:36:03 -07:00
|
|
|
HandleNACK(rtcp_block, packet_information);
|
2016-09-20 01:39:54 -07:00
|
|
|
break;
|
|
|
|
|
case rtcp::Tmmbr::kFeedbackMessageType:
|
2016-09-23 10:36:03 -07:00
|
|
|
HandleTMMBR(rtcp_block, packet_information);
|
2016-09-20 01:39:54 -07:00
|
|
|
break;
|
|
|
|
|
case rtcp::Tmmbn::kFeedbackMessageType:
|
2016-09-23 10:36:03 -07:00
|
|
|
HandleTMMBN(rtcp_block, packet_information);
|
2016-09-20 01:39:54 -07:00
|
|
|
break;
|
|
|
|
|
case rtcp::RapidResyncRequest::kFeedbackMessageType:
|
2016-09-23 10:36:03 -07:00
|
|
|
HandleSR_REQ(rtcp_block, packet_information);
|
2016-09-20 01:39:54 -07:00
|
|
|
break;
|
|
|
|
|
case rtcp::TransportFeedback::kFeedbackMessageType:
|
|
|
|
|
HandleTransportFeedback(rtcp_block, packet_information);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
++num_skipped_packets_;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-08-19 07:29:46 -07:00
|
|
|
break;
|
2016-09-20 01:39:54 -07:00
|
|
|
case rtcp::Psfb::kPacketType:
|
|
|
|
|
switch (rtcp_block.fmt()) {
|
|
|
|
|
case rtcp::Pli::kFeedbackMessageType:
|
2016-09-23 10:36:03 -07:00
|
|
|
HandlePLI(rtcp_block, packet_information);
|
2016-09-20 01:39:54 -07:00
|
|
|
break;
|
|
|
|
|
case rtcp::Sli::kFeedbackMessageType:
|
2016-09-23 10:36:03 -07:00
|
|
|
HandleSLI(rtcp_block, packet_information);
|
2016-09-20 01:39:54 -07:00
|
|
|
break;
|
|
|
|
|
case rtcp::Rpsi::kFeedbackMessageType:
|
2016-09-23 10:36:03 -07:00
|
|
|
HandleRPSI(rtcp_block, packet_information);
|
2016-09-20 01:39:54 -07:00
|
|
|
break;
|
|
|
|
|
case rtcp::Fir::kFeedbackMessageType:
|
2016-09-23 10:36:03 -07:00
|
|
|
HandleFIR(rtcp_block, packet_information);
|
2016-09-20 01:39:54 -07:00
|
|
|
break;
|
|
|
|
|
case rtcp::Remb::kFeedbackMessageType:
|
2016-09-23 10:36:03 -07:00
|
|
|
HandlePsfbApp(rtcp_block, packet_information);
|
2016-09-20 01:39:54 -07:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
++num_skipped_packets_;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-08-19 07:29:46 -07:00
|
|
|
break;
|
|
|
|
|
default:
|
2016-09-20 01:39:54 -07:00
|
|
|
++num_skipped_packets_;
|
2016-08-19 07:29:46 -07:00
|
|
|
break;
|
2014-12-16 12:03:11 +00:00
|
|
|
}
|
2016-08-19 07:29:46 -07:00
|
|
|
}
|
2014-12-16 12:03:11 +00:00
|
|
|
|
2016-08-19 07:29:46 -07:00
|
|
|
if (packet_type_counter_observer_ != NULL) {
|
|
|
|
|
packet_type_counter_observer_->RtcpPacketTypesCounterUpdated(
|
|
|
|
|
main_ssrc_, packet_type_counter_);
|
|
|
|
|
}
|
2015-02-19 12:47:00 +00:00
|
|
|
|
2016-08-19 07:29:46 -07:00
|
|
|
int64_t now = _clock->TimeInMilliseconds();
|
|
|
|
|
if (now - last_skipped_packets_warning_ >= kMaxWarningLogIntervalMs &&
|
|
|
|
|
num_skipped_packets_ > 0) {
|
|
|
|
|
last_skipped_packets_warning_ = now;
|
|
|
|
|
LOG(LS_WARNING) << num_skipped_packets_
|
|
|
|
|
<< " RTCP blocks were skipped due to being malformed or of "
|
|
|
|
|
"unrecognized/unsupported type, during the past "
|
|
|
|
|
<< (kMaxWarningLogIntervalMs / 1000) << " second period.";
|
|
|
|
|
}
|
2015-09-24 15:06:57 +02:00
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
return true;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-23 10:36:03 -07:00
|
|
|
void RTCPReceiver::HandleSenderReport(const CommonHeader& rtcp_block,
|
|
|
|
|
PacketInformation* packet_information) {
|
2016-09-20 01:39:54 -07:00
|
|
|
rtcp::SenderReport sender_report;
|
|
|
|
|
if (!sender_report.Parse(rtcp_block)) {
|
|
|
|
|
++num_skipped_packets_;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
const uint32_t remoteSSRC = sender_report.sender_ssrc();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-09-23 10:36:03 -07:00
|
|
|
packet_information->remote_ssrc = remoteSSRC;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-08-19 07:29:46 -07:00
|
|
|
RTCPReceiveInformation* ptrReceiveInfo = CreateReceiveInformation(remoteSSRC);
|
2016-09-20 01:39:54 -07:00
|
|
|
if (!ptrReceiveInfo)
|
2016-08-19 07:29:46 -07:00
|
|
|
return;
|
2013-07-15 21:08:27 +00:00
|
|
|
|
2016-09-15 16:24:02 +02:00
|
|
|
TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "SR",
|
|
|
|
|
"remote_ssrc", remoteSSRC, "ssrc", main_ssrc_);
|
|
|
|
|
|
|
|
|
|
// Have I received RTP packets from this party?
|
|
|
|
|
if (_remoteSSRC == remoteSSRC) {
|
|
|
|
|
// Only signal that we have received a SR when we accept one.
|
2016-09-23 10:36:03 -07:00
|
|
|
packet_information->packet_type_flags |= kRtcpSr;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-09-15 16:24:02 +02:00
|
|
|
// Save the NTP time of this report.
|
2016-09-20 01:39:54 -07:00
|
|
|
_remoteSenderInfo.NTPseconds = sender_report.ntp().seconds();
|
|
|
|
|
_remoteSenderInfo.NTPfraction = sender_report.ntp().fractions();
|
|
|
|
|
_remoteSenderInfo.RTPtimeStamp = sender_report.rtp_timestamp();
|
|
|
|
|
_remoteSenderInfo.sendPacketCount = sender_report.sender_packet_count();
|
|
|
|
|
_remoteSenderInfo.sendOctetCount = sender_report.sender_octet_count();
|
2016-09-15 16:24:02 +02:00
|
|
|
|
|
|
|
|
_clock->CurrentNtp(_lastReceivedSRNTPsecs, _lastReceivedSRNTPfrac);
|
|
|
|
|
} else {
|
|
|
|
|
// We will only store the send report from one source, but
|
|
|
|
|
// we will store all the receive blocks.
|
2016-09-23 10:36:03 -07:00
|
|
|
packet_information->packet_type_flags |= kRtcpRr;
|
2016-08-19 07:29:46 -07:00
|
|
|
}
|
|
|
|
|
// Update that this remote is alive.
|
|
|
|
|
ptrReceiveInfo->last_time_received_ms = _clock->TimeInMilliseconds();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
for (const rtcp::ReportBlock report_block : sender_report.report_blocks())
|
2016-09-23 10:36:03 -07:00
|
|
|
HandleReportBlock(report_block, packet_information, remoteSSRC);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-23 10:36:03 -07:00
|
|
|
void RTCPReceiver::HandleReceiverReport(const CommonHeader& rtcp_block,
|
|
|
|
|
PacketInformation* packet_information) {
|
2016-09-20 01:39:54 -07:00
|
|
|
rtcp::ReceiverReport receiver_report;
|
|
|
|
|
if (!receiver_report.Parse(rtcp_block)) {
|
|
|
|
|
++num_skipped_packets_;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-09-15 16:24:02 +02:00
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
const uint32_t remoteSSRC = receiver_report.sender_ssrc();
|
2016-09-15 16:24:02 +02:00
|
|
|
|
2016-09-23 10:36:03 -07:00
|
|
|
packet_information->remote_ssrc = remoteSSRC;
|
2016-09-15 16:24:02 +02:00
|
|
|
|
|
|
|
|
RTCPReceiveInformation* ptrReceiveInfo = CreateReceiveInformation(remoteSSRC);
|
2016-09-20 01:39:54 -07:00
|
|
|
if (!ptrReceiveInfo)
|
2016-09-15 16:24:02 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR",
|
|
|
|
|
"remote_ssrc", remoteSSRC, "ssrc", main_ssrc_);
|
|
|
|
|
|
2016-09-23 10:36:03 -07:00
|
|
|
packet_information->packet_type_flags |= kRtcpRr;
|
2016-09-15 16:24:02 +02:00
|
|
|
|
|
|
|
|
// Update that this remote is alive.
|
|
|
|
|
ptrReceiveInfo->last_time_received_ms = _clock->TimeInMilliseconds();
|
|
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
for (const ReportBlock& report_block : receiver_report.report_blocks())
|
2016-09-23 10:36:03 -07:00
|
|
|
HandleReportBlock(report_block, packet_information, remoteSSRC);
|
2016-09-15 16:24:02 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-23 10:36:03 -07:00
|
|
|
void RTCPReceiver::HandleReportBlock(const ReportBlock& report_block,
|
|
|
|
|
PacketInformation* packet_information,
|
|
|
|
|
uint32_t remoteSSRC) {
|
2012-01-11 13:00:08 +00:00
|
|
|
// This will be called once per report block in the RTCP packet.
|
|
|
|
|
// We filter out all report blocks that are not for us.
|
|
|
|
|
// Each packet has max 31 RR blocks.
|
|
|
|
|
//
|
|
|
|
|
// We can calc RTT if we send a send report and get a report block back.
|
|
|
|
|
|
|
|
|
|
// |rtcpPacket.ReportBlockItem.SSRC| is the SSRC identifier of the source to
|
|
|
|
|
// which the information in this reception report block pertains.
|
|
|
|
|
|
|
|
|
|
// Filter out all report blocks that are not for us.
|
2016-09-20 01:39:54 -07:00
|
|
|
if (registered_ssrcs_.count(report_block.source_ssrc()) == 0)
|
2012-01-11 13:00:08 +00:00
|
|
|
return;
|
|
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
RTCPReportBlockInformation* reportBlock =
|
|
|
|
|
CreateOrGetReportBlockInformation(remoteSSRC, report_block.source_ssrc());
|
2012-01-11 13:00:08 +00:00
|
|
|
if (reportBlock == NULL) {
|
2016-08-19 07:29:46 -07:00
|
|
|
LOG(LS_WARNING) << "Failed to CreateReportBlockInformation(" << remoteSSRC
|
|
|
|
|
<< ")";
|
2012-01-11 13:00:08 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2013-01-09 13:54:43 +00:00
|
|
|
|
2013-01-21 07:42:11 +00:00
|
|
|
_lastReceivedRrMs = _clock->TimeInMilliseconds();
|
2012-01-11 13:00:08 +00:00
|
|
|
reportBlock->remoteReceiveBlock.remoteSSRC = remoteSSRC;
|
2016-09-20 01:39:54 -07:00
|
|
|
reportBlock->remoteReceiveBlock.sourceSSRC = report_block.source_ssrc();
|
|
|
|
|
reportBlock->remoteReceiveBlock.fractionLost = report_block.fraction_lost();
|
2012-01-11 13:00:08 +00:00
|
|
|
reportBlock->remoteReceiveBlock.cumulativeLost =
|
2016-09-20 01:39:54 -07:00
|
|
|
report_block.cumulative_lost();
|
|
|
|
|
if (report_block.extended_high_seq_num() >
|
2013-01-09 13:54:43 +00:00
|
|
|
reportBlock->remoteReceiveBlock.extendedHighSeqNum) {
|
|
|
|
|
// We have successfully delivered new RTP packets to the remote side after
|
|
|
|
|
// the last RR was sent from the remote side.
|
|
|
|
|
_lastIncreasedSequenceNumberMs = _lastReceivedRrMs;
|
|
|
|
|
}
|
2012-01-11 13:00:08 +00:00
|
|
|
reportBlock->remoteReceiveBlock.extendedHighSeqNum =
|
2016-09-20 01:39:54 -07:00
|
|
|
report_block.extended_high_seq_num();
|
|
|
|
|
reportBlock->remoteReceiveBlock.jitter = report_block.jitter();
|
|
|
|
|
reportBlock->remoteReceiveBlock.delaySinceLastSR =
|
|
|
|
|
report_block.delay_since_last_sr();
|
|
|
|
|
reportBlock->remoteReceiveBlock.lastSR = report_block.last_sr();
|
2012-01-11 13:00:08 +00:00
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
if (report_block.jitter() > reportBlock->remoteMaxJitter)
|
|
|
|
|
reportBlock->remoteMaxJitter = report_block.jitter();
|
2012-01-11 13:00:08 +00:00
|
|
|
|
2016-03-09 15:14:35 +01:00
|
|
|
int64_t rtt = 0;
|
2016-09-20 01:39:54 -07:00
|
|
|
uint32_t send_time = report_block.last_sr();
|
2016-03-09 15:14:35 +01:00
|
|
|
// RFC3550, section 6.4.1, LSR field discription states:
|
|
|
|
|
// If no SR has been received yet, the field is set to zero.
|
|
|
|
|
// Receiver rtp_rtcp module is not expected to calculate rtt using
|
|
|
|
|
// Sender Reports even if it accidentally can.
|
|
|
|
|
if (!receiver_only_ && send_time != 0) {
|
2016-09-20 01:39:54 -07:00
|
|
|
uint32_t delay = report_block.delay_since_last_sr();
|
2016-02-22 18:59:36 +01:00
|
|
|
// Local NTP time.
|
|
|
|
|
uint32_t receive_time = CompactNtp(NtpTime(*_clock));
|
2012-01-11 13:00:08 +00:00
|
|
|
|
2016-02-22 18:59:36 +01:00
|
|
|
// RTT in 1/(2^16) seconds.
|
|
|
|
|
uint32_t rtt_ntp = receive_time - delay - send_time;
|
|
|
|
|
// Convert to 1/1000 seconds (milliseconds).
|
2016-03-09 15:14:35 +01:00
|
|
|
rtt = CompactNtpRttToMs(rtt_ntp);
|
2016-02-22 18:59:36 +01:00
|
|
|
if (rtt > reportBlock->maxRTT) {
|
|
|
|
|
// Store max RTT.
|
|
|
|
|
reportBlock->maxRTT = rtt;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2012-01-11 13:00:08 +00:00
|
|
|
if (reportBlock->minRTT == 0) {
|
2016-02-22 18:59:36 +01:00
|
|
|
// First RTT.
|
|
|
|
|
reportBlock->minRTT = rtt;
|
|
|
|
|
} else if (rtt < reportBlock->minRTT) {
|
|
|
|
|
// Store min RTT.
|
|
|
|
|
reportBlock->minRTT = rtt;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2016-02-22 18:59:36 +01:00
|
|
|
// Store last RTT.
|
|
|
|
|
reportBlock->RTT = rtt;
|
2012-01-11 13:00:08 +00:00
|
|
|
|
|
|
|
|
// store average RTT
|
|
|
|
|
if (reportBlock->numAverageCalcs != 0) {
|
2015-01-12 21:51:21 +00:00
|
|
|
float ac = static_cast<float>(reportBlock->numAverageCalcs);
|
|
|
|
|
float newAverage =
|
2016-02-22 18:59:36 +01:00
|
|
|
((ac / (ac + 1)) * reportBlock->avgRTT) + ((1 / (ac + 1)) * rtt);
|
2015-01-12 21:51:21 +00:00
|
|
|
reportBlock->avgRTT = static_cast<int64_t>(newAverage + 0.5f);
|
2012-01-11 13:00:08 +00:00
|
|
|
} else {
|
2016-02-22 18:59:36 +01:00
|
|
|
// First RTT.
|
|
|
|
|
reportBlock->avgRTT = rtt;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2012-01-11 13:00:08 +00:00
|
|
|
reportBlock->numAverageCalcs++;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
TRACE_COUNTER_ID1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RR_RTT",
|
|
|
|
|
report_block.source_ssrc(), rtt);
|
2012-01-11 13:00:08 +00:00
|
|
|
|
2016-09-23 10:36:03 -07:00
|
|
|
packet_information->rtt_ms = rtt;
|
|
|
|
|
packet_information->report_blocks.push_back(reportBlock->remoteReceiveBlock);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-18 14:30:32 +00:00
|
|
|
RTCPReportBlockInformation* RTCPReceiver::CreateOrGetReportBlockInformation(
|
|
|
|
|
uint32_t remote_ssrc,
|
|
|
|
|
uint32_t source_ssrc) {
|
2015-01-21 13:07:04 +00:00
|
|
|
RTCPReportBlockInformation* info =
|
|
|
|
|
GetReportBlockInformation(remote_ssrc, source_ssrc);
|
|
|
|
|
if (info == NULL) {
|
|
|
|
|
info = new RTCPReportBlockInformation;
|
|
|
|
|
_receivedReportBlockMap[source_ssrc][remote_ssrc] = info;
|
2012-01-19 15:53:09 +00:00
|
|
|
}
|
2014-12-18 14:30:32 +00:00
|
|
|
return info;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-18 14:30:32 +00:00
|
|
|
RTCPReportBlockInformation* RTCPReceiver::GetReportBlockInformation(
|
|
|
|
|
uint32_t remote_ssrc,
|
|
|
|
|
uint32_t source_ssrc) const {
|
|
|
|
|
ReportBlockMap::const_iterator it = _receivedReportBlockMap.find(source_ssrc);
|
2012-01-19 15:53:09 +00:00
|
|
|
if (it == _receivedReportBlockMap.end()) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2014-12-18 14:30:32 +00:00
|
|
|
const ReportBlockInfoMap* info_map = &(it->second);
|
|
|
|
|
ReportBlockInfoMap::const_iterator it_info = info_map->find(remote_ssrc);
|
|
|
|
|
if (it_info == info_map->end()) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
return it_info->second;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-08-19 07:29:46 -07:00
|
|
|
RTCPCnameInformation* RTCPReceiver::CreateCnameInformation(
|
|
|
|
|
uint32_t remoteSSRC) {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-04-08 11:08:41 +00:00
|
|
|
std::map<uint32_t, RTCPCnameInformation*>::iterator it =
|
2012-01-19 15:53:09 +00:00
|
|
|
_receivedCnameMap.find(remoteSSRC);
|
|
|
|
|
|
|
|
|
|
if (it != _receivedCnameMap.end()) {
|
|
|
|
|
return it->second;
|
|
|
|
|
}
|
|
|
|
|
RTCPCnameInformation* cnameInfo = new RTCPCnameInformation;
|
2012-01-24 17:16:59 +00:00
|
|
|
memset(cnameInfo->name, 0, RTCP_CNAME_SIZE);
|
2012-01-19 15:53:09 +00:00
|
|
|
_receivedCnameMap[remoteSSRC] = cnameInfo;
|
|
|
|
|
return cnameInfo;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-08-19 07:29:46 -07:00
|
|
|
RTCPCnameInformation* RTCPReceiver::GetCnameInformation(
|
|
|
|
|
uint32_t remoteSSRC) const {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-04-08 11:08:41 +00:00
|
|
|
std::map<uint32_t, RTCPCnameInformation*>::const_iterator it =
|
2012-01-19 15:53:09 +00:00
|
|
|
_receivedCnameMap.find(remoteSSRC);
|
|
|
|
|
|
|
|
|
|
if (it == _receivedCnameMap.end()) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
return it->second;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-08-19 07:29:46 -07:00
|
|
|
RTCPReceiveInformation* RTCPReceiver::CreateReceiveInformation(
|
|
|
|
|
uint32_t remoteSSRC) {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-04-08 11:08:41 +00:00
|
|
|
std::map<uint32_t, RTCPReceiveInformation*>::iterator it =
|
2012-01-19 15:53:09 +00:00
|
|
|
_receivedInfoMap.find(remoteSSRC);
|
|
|
|
|
|
|
|
|
|
if (it != _receivedInfoMap.end()) {
|
|
|
|
|
return it->second;
|
|
|
|
|
}
|
|
|
|
|
RTCPReceiveInformation* receiveInfo = new RTCPReceiveInformation;
|
|
|
|
|
_receivedInfoMap[remoteSSRC] = receiveInfo;
|
|
|
|
|
return receiveInfo;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-08-19 07:29:46 -07:00
|
|
|
RTCPReceiveInformation* RTCPReceiver::GetReceiveInformation(
|
|
|
|
|
uint32_t remoteSSRC) {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-04-08 11:08:41 +00:00
|
|
|
std::map<uint32_t, RTCPReceiveInformation*>::iterator it =
|
2012-01-19 15:53:09 +00:00
|
|
|
_receivedInfoMap.find(remoteSSRC);
|
|
|
|
|
if (it == _receivedInfoMap.end()) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
return it->second;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-01-09 13:54:43 +00:00
|
|
|
bool RTCPReceiver::RtcpRrTimeout(int64_t rtcp_interval_ms) {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
2013-01-09 13:54:43 +00:00
|
|
|
if (_lastReceivedRrMs == 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
int64_t time_out_ms = kRrTimeoutIntervals * rtcp_interval_ms;
|
2013-01-21 07:42:11 +00:00
|
|
|
if (_clock->TimeInMilliseconds() > _lastReceivedRrMs + time_out_ms) {
|
2013-01-09 13:54:43 +00:00
|
|
|
// Reset the timer to only trigger one log.
|
|
|
|
|
_lastReceivedRrMs = 0;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RTCPReceiver::RtcpRrSequenceNumberTimeout(int64_t rtcp_interval_ms) {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
2013-01-09 13:54:43 +00:00
|
|
|
if (_lastIncreasedSequenceNumberMs == 0)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
int64_t time_out_ms = kRrTimeoutIntervals * rtcp_interval_ms;
|
2016-08-19 07:29:46 -07:00
|
|
|
if (_clock->TimeInMilliseconds() >
|
|
|
|
|
_lastIncreasedSequenceNumberMs + time_out_ms) {
|
2013-01-09 13:54:43 +00:00
|
|
|
// Reset the timer to only trigger one log.
|
|
|
|
|
_lastIncreasedSequenceNumberMs = 0;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-19 15:53:09 +00:00
|
|
|
bool RTCPReceiver::UpdateRTCPReceiveInformationTimers() {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2012-01-19 15:53:09 +00:00
|
|
|
bool updateBoundingSet = false;
|
2013-04-08 11:08:41 +00:00
|
|
|
int64_t timeNow = _clock->TimeInMilliseconds();
|
2012-01-19 15:53:09 +00:00
|
|
|
|
2013-04-08 11:08:41 +00:00
|
|
|
std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt =
|
2012-01-19 15:53:09 +00:00
|
|
|
_receivedInfoMap.begin();
|
|
|
|
|
|
|
|
|
|
while (receiveInfoIt != _receivedInfoMap.end()) {
|
|
|
|
|
RTCPReceiveInformation* receiveInfo = receiveInfoIt->second;
|
|
|
|
|
if (receiveInfo == NULL) {
|
|
|
|
|
return updateBoundingSet;
|
|
|
|
|
}
|
|
|
|
|
// time since last received rtcp packet
|
|
|
|
|
// when we dont have a lastTimeReceived and the object is marked
|
|
|
|
|
// readyForDelete it's removed from the map
|
2016-08-18 06:17:42 -07:00
|
|
|
if (receiveInfo->last_time_received_ms > 0) {
|
2012-01-19 15:53:09 +00:00
|
|
|
/// use audio define since we don't know what interval the remote peer is
|
|
|
|
|
// using
|
2016-08-18 06:17:42 -07:00
|
|
|
if ((timeNow - receiveInfo->last_time_received_ms) >
|
2012-01-19 15:53:09 +00:00
|
|
|
5 * RTCP_INTERVAL_AUDIO_MS) {
|
|
|
|
|
// no rtcp packet for the last five regular intervals, reset limitations
|
2016-08-18 06:17:42 -07:00
|
|
|
receiveInfo->ClearTmmbr();
|
2012-01-19 15:53:09 +00:00
|
|
|
// prevent that we call this over and over again
|
2016-08-18 06:17:42 -07:00
|
|
|
receiveInfo->last_time_received_ms = 0;
|
2012-01-19 15:53:09 +00:00
|
|
|
// send new TMMBN to all channels using the default codec
|
|
|
|
|
updateBoundingSet = true;
|
|
|
|
|
}
|
|
|
|
|
receiveInfoIt++;
|
2016-08-18 06:17:42 -07:00
|
|
|
} else if (receiveInfo->ready_for_delete) {
|
2012-01-19 15:53:09 +00:00
|
|
|
// store our current receiveInfoItem
|
2013-04-08 11:08:41 +00:00
|
|
|
std::map<uint32_t, RTCPReceiveInformation*>::iterator
|
2016-08-19 07:29:46 -07:00
|
|
|
receiveInfoItemToBeErased = receiveInfoIt;
|
2012-01-19 15:53:09 +00:00
|
|
|
receiveInfoIt++;
|
|
|
|
|
delete receiveInfoItemToBeErased->second;
|
|
|
|
|
_receivedInfoMap.erase(receiveInfoItemToBeErased);
|
|
|
|
|
} else {
|
|
|
|
|
receiveInfoIt++;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2012-01-19 15:53:09 +00:00
|
|
|
}
|
|
|
|
|
return updateBoundingSet;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-08-18 06:17:42 -07:00
|
|
|
std::vector<rtcp::TmmbItem> RTCPReceiver::BoundingSet(bool* tmmbr_owner) {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2013-04-08 11:08:41 +00:00
|
|
|
std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt =
|
2012-01-19 15:53:09 +00:00
|
|
|
_receivedInfoMap.find(_remoteSSRC);
|
|
|
|
|
|
|
|
|
|
if (receiveInfoIt == _receivedInfoMap.end()) {
|
2016-08-18 06:17:42 -07:00
|
|
|
return std::vector<rtcp::TmmbItem>();
|
2012-01-19 15:53:09 +00:00
|
|
|
}
|
|
|
|
|
RTCPReceiveInformation* receiveInfo = receiveInfoIt->second;
|
2016-08-18 06:17:42 -07:00
|
|
|
RTC_DCHECK(receiveInfo);
|
|
|
|
|
|
|
|
|
|
*tmmbr_owner = TMMBRHelp::IsOwner(receiveInfo->tmmbn, main_ssrc_);
|
|
|
|
|
return receiveInfo->tmmbn;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
void RTCPReceiver::HandleSDES(const CommonHeader& rtcp_block,
|
2016-09-23 10:36:03 -07:00
|
|
|
PacketInformation* packet_information) {
|
2016-09-20 01:39:54 -07:00
|
|
|
rtcp::Sdes sdes;
|
|
|
|
|
if (!sdes.Parse(rtcp_block)) {
|
|
|
|
|
++num_skipped_packets_;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const rtcp::Sdes::Chunk& chunk : sdes.chunks()) {
|
|
|
|
|
RTCPCnameInformation* cnameInfo = CreateCnameInformation(chunk.ssrc);
|
2016-09-15 18:41:02 +02:00
|
|
|
RTC_DCHECK(cnameInfo);
|
|
|
|
|
|
|
|
|
|
cnameInfo->name[RTCP_CNAME_SIZE - 1] = 0;
|
2016-09-20 01:39:54 -07:00
|
|
|
strncpy(cnameInfo->name, chunk.cname.c_str(), RTCP_CNAME_SIZE - 1);
|
2016-09-15 18:41:02 +02:00
|
|
|
{
|
|
|
|
|
rtc::CritScope lock(&_criticalSectionFeedbacks);
|
2016-09-20 01:39:54 -07:00
|
|
|
if (stats_callback_)
|
|
|
|
|
stats_callback_->CNameChanged(chunk.cname.c_str(), chunk.ssrc);
|
2016-09-15 18:41:02 +02:00
|
|
|
}
|
2015-01-21 13:07:04 +00:00
|
|
|
}
|
2016-09-23 10:36:03 -07:00
|
|
|
packet_information->packet_type_flags |= kRtcpSdes;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
void RTCPReceiver::HandleNACK(const CommonHeader& rtcp_block,
|
2016-09-23 10:36:03 -07:00
|
|
|
PacketInformation* packet_information) {
|
2016-09-20 01:39:54 -07:00
|
|
|
rtcp::Nack nack;
|
|
|
|
|
if (!nack.Parse(rtcp_block)) {
|
|
|
|
|
++num_skipped_packets_;
|
2015-01-21 13:07:04 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
if (receiver_only_ || main_ssrc_ != nack.media_ssrc()) // Not to us.
|
|
|
|
|
return;
|
2016-09-15 18:41:02 +02:00
|
|
|
|
2016-09-23 10:36:03 -07:00
|
|
|
packet_information->nack_sequence_numbers = nack.packet_ids();
|
2016-09-20 01:39:54 -07:00
|
|
|
for (uint16_t packet_id : nack.packet_ids())
|
|
|
|
|
nack_stats_.ReportRequest(packet_id);
|
2014-02-19 11:59:02 +00:00
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
if (!nack.packet_ids().empty()) {
|
2016-09-23 10:36:03 -07:00
|
|
|
packet_information->packet_type_flags |= kRtcpNack;
|
2015-01-21 13:07:04 +00:00
|
|
|
++packet_type_counter_.nack_packets;
|
|
|
|
|
packet_type_counter_.nack_requests = nack_stats_.requests();
|
|
|
|
|
packet_type_counter_.unique_nack_requests = nack_stats_.unique_requests();
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
void RTCPReceiver::HandleBYE(const CommonHeader& rtcp_block) {
|
|
|
|
|
rtcp::Bye bye;
|
|
|
|
|
if (!bye.Parse(rtcp_block)) {
|
|
|
|
|
++num_skipped_packets_;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2012-01-19 15:53:09 +00:00
|
|
|
// clear our lists
|
2014-12-18 14:30:32 +00:00
|
|
|
ReportBlockMap::iterator it = _receivedReportBlockMap.begin();
|
|
|
|
|
for (; it != _receivedReportBlockMap.end(); ++it) {
|
|
|
|
|
ReportBlockInfoMap* info_map = &(it->second);
|
2016-09-20 01:39:54 -07:00
|
|
|
ReportBlockInfoMap::iterator it_info = info_map->find(bye.sender_ssrc());
|
2014-12-18 14:30:32 +00:00
|
|
|
if (it_info != info_map->end()) {
|
|
|
|
|
delete it_info->second;
|
|
|
|
|
info_map->erase(it_info);
|
|
|
|
|
}
|
2012-01-19 15:53:09 +00:00
|
|
|
}
|
2014-12-18 14:30:32 +00:00
|
|
|
|
2012-01-19 15:53:09 +00:00
|
|
|
// we can't delete it due to TMMBR
|
2013-04-08 11:08:41 +00:00
|
|
|
std::map<uint32_t, RTCPReceiveInformation*>::iterator receiveInfoIt =
|
2016-09-20 01:39:54 -07:00
|
|
|
_receivedInfoMap.find(bye.sender_ssrc());
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
if (receiveInfoIt != _receivedInfoMap.end())
|
2016-08-18 06:17:42 -07:00
|
|
|
receiveInfoIt->second->ready_for_delete = true;
|
2012-01-19 15:53:09 +00:00
|
|
|
|
2013-04-08 11:08:41 +00:00
|
|
|
std::map<uint32_t, RTCPCnameInformation*>::iterator cnameInfoIt =
|
2016-09-20 01:39:54 -07:00
|
|
|
_receivedCnameMap.find(bye.sender_ssrc());
|
2012-01-19 15:53:09 +00:00
|
|
|
|
|
|
|
|
if (cnameInfoIt != _receivedCnameMap.end()) {
|
|
|
|
|
delete cnameInfoIt->second;
|
|
|
|
|
_receivedCnameMap.erase(cnameInfoIt);
|
|
|
|
|
}
|
2013-10-31 12:14:34 +00:00
|
|
|
xr_rr_rtt_ms_ = 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
void RTCPReceiver::HandleXr(const CommonHeader& rtcp_block,
|
2016-09-23 10:36:03 -07:00
|
|
|
PacketInformation* packet_information) {
|
2016-09-20 01:39:54 -07:00
|
|
|
rtcp::ExtendedReports xr;
|
|
|
|
|
if (!xr.Parse(rtcp_block)) {
|
|
|
|
|
++num_skipped_packets_;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-10-02 13:15:34 +00:00
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
for (const rtcp::Rrtr& rrtr : xr.rrtrs())
|
2016-09-23 10:36:03 -07:00
|
|
|
HandleXrReceiveReferenceTime(xr.sender_ssrc(), rrtr);
|
2013-10-02 13:15:34 +00:00
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
for (const rtcp::Dlrr& dlrr : xr.dlrrs()) {
|
|
|
|
|
for (const rtcp::ReceiveTimeInfo& time_info : dlrr.sub_blocks())
|
2016-09-23 10:36:03 -07:00
|
|
|
HandleXrDlrrReportBlock(time_info);
|
2016-09-20 01:39:54 -07:00
|
|
|
}
|
2013-10-02 13:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RTCPReceiver::HandleXrReceiveReferenceTime(
|
2016-09-23 10:36:03 -07:00
|
|
|
uint32_t sender_ssrc,
|
|
|
|
|
const rtcp::Rrtr& rrtr) {
|
|
|
|
|
_remoteXRReceiveTimeInfo.sourceSSRC = sender_ssrc;
|
2016-09-20 01:39:54 -07:00
|
|
|
_remoteXRReceiveTimeInfo.lastRR = CompactNtp(rrtr.ntp());
|
2013-10-02 13:15:34 +00:00
|
|
|
_clock->CurrentNtp(_lastReceivedXRNTPsecs, _lastReceivedXRNTPfrac);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-23 10:36:03 -07:00
|
|
|
void RTCPReceiver::HandleXrDlrrReportBlock(const rtcp::ReceiveTimeInfo& rti) {
|
2016-09-20 01:39:54 -07:00
|
|
|
if (registered_ssrcs_.count(rti.ssrc) == 0) // Not to us.
|
|
|
|
|
return;
|
2013-10-02 13:15:34 +00:00
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
// Caller should explicitly enable rtt calculation using extended reports.
|
|
|
|
|
if (!xr_rrtr_status_)
|
|
|
|
|
return;
|
2016-03-09 15:14:35 +01:00
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
// The send_time and delay_rr fields are in units of 1/2^16 sec.
|
|
|
|
|
uint32_t send_time = rti.last_rr;
|
|
|
|
|
// RFC3611, section 4.5, LRR field discription states:
|
|
|
|
|
// If no such block has been received, the field is set to zero.
|
|
|
|
|
if (send_time == 0)
|
|
|
|
|
return;
|
2013-10-31 12:14:34 +00:00
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
uint32_t delay_rr = rti.delay_since_last_rr;
|
|
|
|
|
uint32_t now = CompactNtp(NtpTime(*_clock));
|
2013-10-02 13:15:34 +00:00
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
uint32_t rtt_ntp = now - delay_rr - send_time;
|
|
|
|
|
xr_rr_rtt_ms_ = CompactNtpRttToMs(rtt_ntp);
|
2013-10-02 13:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
void RTCPReceiver::HandlePLI(const CommonHeader& rtcp_block,
|
2016-09-23 10:36:03 -07:00
|
|
|
PacketInformation* packet_information) {
|
2016-09-20 01:39:54 -07:00
|
|
|
rtcp::Pli pli;
|
|
|
|
|
if (!pli.Parse(rtcp_block)) {
|
|
|
|
|
++num_skipped_packets_;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (main_ssrc_ == pli.media_ssrc()) {
|
2015-02-16 12:06:00 +00:00
|
|
|
TRACE_EVENT_INSTANT0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "PLI");
|
2013-05-13 22:59:00 +00:00
|
|
|
|
2014-02-19 11:59:02 +00:00
|
|
|
++packet_type_counter_.pli_packets;
|
2012-05-21 12:00:49 +00:00
|
|
|
// Received a signal that we need to send a new key frame.
|
2016-09-23 10:36:03 -07:00
|
|
|
packet_information->packet_type_flags |= kRtcpPli;
|
2012-05-21 12:00:49 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
void RTCPReceiver::HandleTMMBR(const CommonHeader& rtcp_block,
|
2016-09-23 10:36:03 -07:00
|
|
|
PacketInformation* packet_information) {
|
2016-09-20 01:39:54 -07:00
|
|
|
rtcp::Tmmbr tmmbr;
|
|
|
|
|
if (!tmmbr.Parse(rtcp_block)) {
|
|
|
|
|
++num_skipped_packets_;
|
2015-01-21 13:07:04 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
uint32_t senderSSRC = tmmbr.sender_ssrc();
|
|
|
|
|
RTCPReceiveInformation* ptrReceiveInfo = GetReceiveInformation(senderSSRC);
|
|
|
|
|
if (!ptrReceiveInfo) // This remote SSRC must be saved before.
|
2015-01-21 13:07:04 +00:00
|
|
|
return;
|
2016-09-20 01:39:54 -07:00
|
|
|
|
|
|
|
|
if (tmmbr.media_ssrc()) {
|
|
|
|
|
// media_ssrc() SHOULD be 0 if same as SenderSSRC.
|
|
|
|
|
// In relay mode this is a valid number.
|
|
|
|
|
senderSSRC = tmmbr.media_ssrc();
|
2015-01-21 13:07:04 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
for (const rtcp::TmmbItem& request : tmmbr.requests()) {
|
|
|
|
|
if (main_ssrc_ == request.ssrc() && request.bitrate_bps()) {
|
|
|
|
|
ptrReceiveInfo->InsertTmmbrItem(senderSSRC, request,
|
|
|
|
|
_clock->TimeInMilliseconds());
|
2016-09-23 10:36:03 -07:00
|
|
|
packet_information->packet_type_flags |= kRtcpTmmbr;
|
2016-09-15 18:41:02 +02:00
|
|
|
}
|
2015-01-21 13:07:04 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
void RTCPReceiver::HandleTMMBN(const CommonHeader& rtcp_block,
|
2016-09-23 10:36:03 -07:00
|
|
|
PacketInformation* packet_information) {
|
2016-09-20 01:39:54 -07:00
|
|
|
rtcp::Tmmbn tmmbn;
|
|
|
|
|
if (!tmmbn.Parse(rtcp_block)) {
|
|
|
|
|
++num_skipped_packets_;
|
2015-01-21 13:07:04 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2016-09-20 01:39:54 -07:00
|
|
|
|
|
|
|
|
RTCPReceiveInformation* ptrReceiveInfo =
|
|
|
|
|
GetReceiveInformation(tmmbn.sender_ssrc());
|
|
|
|
|
if (!ptrReceiveInfo) // This remote SSRC must be saved before.
|
2015-01-21 13:07:04 +00:00
|
|
|
return;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-09-23 10:36:03 -07:00
|
|
|
packet_information->packet_type_flags |= kRtcpTmmbn;
|
2016-09-20 01:39:54 -07:00
|
|
|
|
|
|
|
|
for (const auto& item : tmmbn.items())
|
|
|
|
|
ptrReceiveInfo->tmmbn.push_back(item);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
void RTCPReceiver::HandleSR_REQ(const CommonHeader& rtcp_block,
|
2016-09-23 10:36:03 -07:00
|
|
|
PacketInformation* packet_information) {
|
2016-09-20 01:39:54 -07:00
|
|
|
rtcp::RapidResyncRequest sr_req;
|
|
|
|
|
if (!sr_req.Parse(rtcp_block)) {
|
|
|
|
|
++num_skipped_packets_;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-23 10:36:03 -07:00
|
|
|
packet_information->packet_type_flags |= kRtcpSrReq;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
void RTCPReceiver::HandleSLI(const CommonHeader& rtcp_block,
|
2016-09-23 10:36:03 -07:00
|
|
|
PacketInformation* packet_information) {
|
2016-09-20 01:39:54 -07:00
|
|
|
rtcp::Sli sli;
|
|
|
|
|
if (!sli.Parse(rtcp_block)) {
|
|
|
|
|
++num_skipped_packets_;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-09-15 18:41:02 +02:00
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
for (const rtcp::Sli::Macroblocks& item : sli.macroblocks()) {
|
|
|
|
|
// In theory there could be multiple slices lost.
|
|
|
|
|
// Received signal that we need to refresh a slice.
|
2016-09-23 10:36:03 -07:00
|
|
|
packet_information->packet_type_flags |= kRtcpSli;
|
|
|
|
|
packet_information->sli_picture_id = item.picture_id();
|
2015-01-21 13:07:04 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-23 10:36:03 -07:00
|
|
|
void RTCPReceiver::HandleRPSI(const CommonHeader& rtcp_block,
|
|
|
|
|
PacketInformation* packet_information) {
|
2016-09-20 01:39:54 -07:00
|
|
|
rtcp::Rpsi rpsi;
|
|
|
|
|
if (!rpsi.Parse(rtcp_block)) {
|
|
|
|
|
++num_skipped_packets_;
|
|
|
|
|
return;
|
2016-08-19 07:29:46 -07:00
|
|
|
}
|
2016-09-20 01:39:54 -07:00
|
|
|
|
|
|
|
|
// Received signal that we have a confirmed reference picture.
|
2016-09-23 10:36:03 -07:00
|
|
|
packet_information->packet_type_flags |= kRtcpRpsi;
|
|
|
|
|
packet_information->rpsi_picture_id = rpsi.picture_id();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
void RTCPReceiver::HandlePsfbApp(const CommonHeader& rtcp_block,
|
2016-09-23 10:36:03 -07:00
|
|
|
PacketInformation* packet_information) {
|
2016-09-20 01:39:54 -07:00
|
|
|
rtcp::Remb remb;
|
|
|
|
|
if (remb.Parse(rtcp_block)) {
|
2016-09-23 10:36:03 -07:00
|
|
|
packet_information->packet_type_flags |= kRtcpRemb;
|
|
|
|
|
packet_information->receiver_estimated_max_bitrate_bps = remb.bitrate_bps();
|
2016-09-20 01:39:54 -07:00
|
|
|
return;
|
2012-04-27 05:25:53 +00:00
|
|
|
}
|
2016-09-20 01:39:54 -07:00
|
|
|
|
|
|
|
|
++num_skipped_packets_;
|
2011-09-20 13:52:04 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
void RTCPReceiver::HandleFIR(const CommonHeader& rtcp_block,
|
2016-09-23 10:36:03 -07:00
|
|
|
PacketInformation* packet_information) {
|
2016-09-20 01:39:54 -07:00
|
|
|
rtcp::Fir fir;
|
|
|
|
|
if (!fir.Parse(rtcp_block)) {
|
|
|
|
|
++num_skipped_packets_;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-21 12:00:49 +00:00
|
|
|
RTCPReceiveInformation* ptrReceiveInfo =
|
2016-09-20 01:39:54 -07:00
|
|
|
GetReceiveInformation(fir.sender_ssrc());
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-09-20 01:39:54 -07:00
|
|
|
for (const rtcp::Fir::Request& fir_request : fir.requests()) {
|
2016-09-15 18:41:02 +02:00
|
|
|
// Is it our sender that is requested to generate a new keyframe
|
2016-09-20 01:39:54 -07:00
|
|
|
if (main_ssrc_ != fir_request.ssrc)
|
|
|
|
|
continue;
|
2014-02-19 11:59:02 +00:00
|
|
|
|
2016-09-15 18:41:02 +02:00
|
|
|
++packet_type_counter_.fir_packets;
|
|
|
|
|
|
|
|
|
|
// rtcpPacket.FIR.MediaSSRC SHOULD be 0 but we ignore to check it
|
|
|
|
|
// we don't know who this originate from
|
|
|
|
|
if (ptrReceiveInfo) {
|
|
|
|
|
// check if we have reported this FIRSequenceNumber before
|
2016-09-20 01:39:54 -07:00
|
|
|
if (fir_request.seq_nr != ptrReceiveInfo->last_fir_sequence_number) {
|
2016-09-15 18:41:02 +02:00
|
|
|
int64_t now = _clock->TimeInMilliseconds();
|
|
|
|
|
// sanity; don't go crazy with the callbacks
|
|
|
|
|
if ((now - ptrReceiveInfo->last_fir_request_ms) >
|
|
|
|
|
RTCP_MIN_FRAME_LENGTH_MS) {
|
|
|
|
|
ptrReceiveInfo->last_fir_request_ms = now;
|
2016-09-20 01:39:54 -07:00
|
|
|
ptrReceiveInfo->last_fir_sequence_number = fir_request.seq_nr;
|
2016-09-15 18:41:02 +02:00
|
|
|
// received signal that we need to send a new key frame
|
2016-09-23 10:36:03 -07:00
|
|
|
packet_information->packet_type_flags |= kRtcpFir;
|
2016-09-15 18:41:02 +02:00
|
|
|
}
|
2012-05-21 12:00:49 +00:00
|
|
|
}
|
2016-09-15 18:41:02 +02:00
|
|
|
} else {
|
|
|
|
|
// received signal that we need to send a new key frame
|
2016-09-23 10:36:03 -07:00
|
|
|
packet_information->packet_type_flags |= kRtcpFir;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2012-05-21 12:00:49 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-09-24 15:06:57 +02:00
|
|
|
void RTCPReceiver::HandleTransportFeedback(
|
2016-09-20 01:39:54 -07:00
|
|
|
const CommonHeader& rtcp_block,
|
2016-09-23 10:36:03 -07:00
|
|
|
PacketInformation* packet_information) {
|
2016-09-20 01:39:54 -07:00
|
|
|
std::unique_ptr<rtcp::TransportFeedback> transport_feedback(
|
|
|
|
|
new rtcp::TransportFeedback());
|
|
|
|
|
if (!transport_feedback->Parse(rtcp_block)) {
|
|
|
|
|
++num_skipped_packets_;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-09-24 15:06:57 +02:00
|
|
|
|
2016-09-23 10:36:03 -07:00
|
|
|
packet_information->packet_type_flags |= kRtcpTransportFeedback;
|
|
|
|
|
packet_information->transport_feedback = std::move(transport_feedback);
|
2015-09-24 15:06:57 +02:00
|
|
|
}
|
2016-08-16 15:15:39 -07:00
|
|
|
|
2016-08-22 08:26:15 -07:00
|
|
|
void RTCPReceiver::UpdateTmmbr() {
|
|
|
|
|
// Find bounding set.
|
2016-08-16 03:21:38 -07:00
|
|
|
std::vector<rtcp::TmmbItem> bounding =
|
2016-08-22 08:26:15 -07:00
|
|
|
TMMBRHelp::FindBoundingSet(TmmbrReceived());
|
|
|
|
|
|
|
|
|
|
if (!bounding.empty() && _cbRtcpBandwidthObserver) {
|
|
|
|
|
// We have a new bandwidth estimate on this channel.
|
2016-08-16 03:21:38 -07:00
|
|
|
uint64_t bitrate_bps = TMMBRHelp::CalcMinBitrateBps(bounding);
|
|
|
|
|
if (bitrate_bps <= std::numeric_limits<uint32_t>::max())
|
|
|
|
|
_cbRtcpBandwidthObserver->OnReceivedEstimatedBitrate(bitrate_bps);
|
2012-04-05 08:30:10 +00:00
|
|
|
}
|
2016-08-22 08:26:15 -07:00
|
|
|
|
|
|
|
|
// Set bounding set: inform remote clients about the new bandwidth.
|
|
|
|
|
_rtpRtcp.SetTmmbn(std::move(bounding));
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-12-05 09:48:44 +00:00
|
|
|
void RTCPReceiver::RegisterRtcpStatisticsCallback(
|
|
|
|
|
RtcpStatisticsCallback* callback) {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope cs(&_criticalSectionFeedbacks);
|
2013-12-05 09:48:44 +00:00
|
|
|
stats_callback_ = callback;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RtcpStatisticsCallback* RTCPReceiver::GetRtcpStatisticsCallback() {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope cs(&_criticalSectionFeedbacks);
|
2013-12-05 09:48:44 +00:00
|
|
|
return stats_callback_;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
// Holding no Critical section
|
2012-01-05 08:40:56 +00:00
|
|
|
void RTCPReceiver::TriggerCallbacksFromRTCPPacket(
|
2016-09-23 10:36:03 -07:00
|
|
|
const PacketInformation& packet_information) {
|
2012-04-27 05:25:53 +00:00
|
|
|
// Process TMMBR and REMB first to avoid multiple callbacks
|
|
|
|
|
// to OnNetworkChanged.
|
2016-09-23 10:36:03 -07:00
|
|
|
if (packet_information.packet_type_flags & kRtcpTmmbr) {
|
2012-04-27 05:25:53 +00:00
|
|
|
// Might trigger a OnReceivedBandwidthEstimateUpdate.
|
2016-08-22 08:26:15 -07:00
|
|
|
UpdateTmmbr();
|
2012-04-27 05:25:53 +00:00
|
|
|
}
|
2015-10-13 09:17:48 -07:00
|
|
|
uint32_t local_ssrc;
|
|
|
|
|
std::set<uint32_t> registered_ssrcs;
|
2012-10-05 16:17:41 +00:00
|
|
|
{
|
|
|
|
|
// We don't want to hold this critsect when triggering the callbacks below.
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
2013-09-17 07:49:56 +00:00
|
|
|
local_ssrc = main_ssrc_;
|
2015-10-13 09:17:48 -07:00
|
|
|
registered_ssrcs = registered_ssrcs_;
|
2012-10-05 16:17:41 +00:00
|
|
|
}
|
2016-09-23 10:36:03 -07:00
|
|
|
if (!receiver_only_ && (packet_information.packet_type_flags & kRtcpSrReq)) {
|
2012-04-27 05:25:53 +00:00
|
|
|
_rtpRtcp.OnRequestSendReport();
|
|
|
|
|
}
|
2016-09-23 10:36:03 -07:00
|
|
|
if (!receiver_only_ && (packet_information.packet_type_flags & kRtcpNack)) {
|
|
|
|
|
if (!packet_information.nack_sequence_numbers.empty()) {
|
2014-06-04 09:05:30 +00:00
|
|
|
LOG(LS_VERBOSE) << "Incoming NACK length: "
|
2016-09-23 10:36:03 -07:00
|
|
|
<< packet_information.nack_sequence_numbers.size();
|
|
|
|
|
_rtpRtcp.OnReceivedNack(packet_information.nack_sequence_numbers);
|
2012-01-05 08:40:56 +00:00
|
|
|
}
|
2012-04-27 05:25:53 +00:00
|
|
|
}
|
|
|
|
|
{
|
|
|
|
|
// We need feedback that we have received a report block(s) so that we
|
|
|
|
|
// can generate a new packet in a conference relay scenario, one received
|
|
|
|
|
// report can generate several RTCP packets, based on number relayed/mixed
|
|
|
|
|
// a send report block should go out to all receivers.
|
|
|
|
|
if (_cbRtcpIntraFrameObserver) {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(!receiver_only_);
|
2016-09-23 10:36:03 -07:00
|
|
|
if ((packet_information.packet_type_flags & kRtcpPli) ||
|
|
|
|
|
(packet_information.packet_type_flags & kRtcpFir)) {
|
|
|
|
|
if (packet_information.packet_type_flags & kRtcpPli) {
|
2014-06-04 09:05:30 +00:00
|
|
|
LOG(LS_VERBOSE) << "Incoming PLI from SSRC "
|
2016-09-23 10:36:03 -07:00
|
|
|
<< packet_information.remote_ssrc;
|
2012-04-27 05:25:53 +00:00
|
|
|
} else {
|
2014-06-04 09:05:30 +00:00
|
|
|
LOG(LS_VERBOSE) << "Incoming FIR from SSRC "
|
2016-09-23 10:36:03 -07:00
|
|
|
<< packet_information.remote_ssrc;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2012-10-05 16:17:41 +00:00
|
|
|
_cbRtcpIntraFrameObserver->OnReceivedIntraFrameRequest(local_ssrc);
|
2012-04-27 05:25:53 +00:00
|
|
|
}
|
2016-09-23 10:36:03 -07:00
|
|
|
if (packet_information.packet_type_flags & kRtcpSli) {
|
2012-04-27 05:25:53 +00:00
|
|
|
_cbRtcpIntraFrameObserver->OnReceivedSLI(
|
2016-09-23 10:36:03 -07:00
|
|
|
local_ssrc, packet_information.sli_picture_id);
|
2012-04-27 05:25:53 +00:00
|
|
|
}
|
2016-09-23 10:36:03 -07:00
|
|
|
if (packet_information.packet_type_flags & kRtcpRpsi) {
|
2012-04-27 05:25:53 +00:00
|
|
|
_cbRtcpIntraFrameObserver->OnReceivedRPSI(
|
2016-09-23 10:36:03 -07:00
|
|
|
local_ssrc, packet_information.rpsi_picture_id);
|
2012-04-27 05:25:53 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2012-04-27 05:25:53 +00:00
|
|
|
if (_cbRtcpBandwidthObserver) {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(!receiver_only_);
|
2016-09-23 10:36:03 -07:00
|
|
|
if (packet_information.packet_type_flags & kRtcpRemb) {
|
|
|
|
|
LOG(LS_VERBOSE)
|
|
|
|
|
<< "Incoming REMB: "
|
|
|
|
|
<< packet_information.receiver_estimated_max_bitrate_bps;
|
2012-04-27 05:25:53 +00:00
|
|
|
_cbRtcpBandwidthObserver->OnReceivedEstimatedBitrate(
|
2016-09-23 10:36:03 -07:00
|
|
|
packet_information.receiver_estimated_max_bitrate_bps);
|
2012-04-27 05:25:53 +00:00
|
|
|
}
|
2016-09-23 10:36:03 -07:00
|
|
|
if ((packet_information.packet_type_flags & kRtcpSr) ||
|
|
|
|
|
(packet_information.packet_type_flags & kRtcpRr)) {
|
2013-04-08 11:08:41 +00:00
|
|
|
int64_t now = _clock->TimeInMilliseconds();
|
2012-04-27 05:25:53 +00:00
|
|
|
_cbRtcpBandwidthObserver->OnReceivedRtcpReceiverReport(
|
2016-09-23 10:36:03 -07:00
|
|
|
packet_information.report_blocks, packet_information.rtt_ms, now);
|
2012-04-27 05:25:53 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2016-09-23 10:36:03 -07:00
|
|
|
if ((packet_information.packet_type_flags & kRtcpSr) ||
|
|
|
|
|
(packet_information.packet_type_flags & kRtcpRr)) {
|
|
|
|
|
_rtpRtcp.OnReceivedRtcpReportBlocks(packet_information.report_blocks);
|
2016-06-08 00:24:21 -07:00
|
|
|
}
|
|
|
|
|
|
2015-09-24 15:06:57 +02:00
|
|
|
if (_cbTransportFeedbackObserver &&
|
2016-09-23 10:36:03 -07:00
|
|
|
(packet_information.packet_type_flags & kRtcpTransportFeedback)) {
|
2015-09-24 15:06:57 +02:00
|
|
|
uint32_t media_source_ssrc =
|
2016-09-23 10:36:03 -07:00
|
|
|
packet_information.transport_feedback->media_ssrc();
|
2015-10-13 09:17:48 -07:00
|
|
|
if (media_source_ssrc == local_ssrc ||
|
|
|
|
|
registered_ssrcs.find(media_source_ssrc) != registered_ssrcs.end()) {
|
2015-09-24 15:06:57 +02:00
|
|
|
_cbTransportFeedbackObserver->OnTransportFeedback(
|
2016-09-23 10:36:03 -07:00
|
|
|
*packet_information.transport_feedback);
|
2015-09-24 15:06:57 +02:00
|
|
|
}
|
|
|
|
|
}
|
2012-04-27 05:25:53 +00:00
|
|
|
}
|
2013-12-05 09:48:44 +00:00
|
|
|
|
2015-04-23 17:53:17 +02:00
|
|
|
if (!receiver_only_) {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope cs(&_criticalSectionFeedbacks);
|
2013-12-05 09:48:44 +00:00
|
|
|
if (stats_callback_) {
|
2016-09-23 10:36:03 -07:00
|
|
|
for (const auto& report_block : packet_information.report_blocks) {
|
2013-12-05 09:48:44 +00:00
|
|
|
RtcpStatistics stats;
|
2016-09-23 10:36:03 -07:00
|
|
|
stats.cumulative_lost = report_block.cumulativeLost;
|
|
|
|
|
stats.extended_max_sequence_number = report_block.extendedHighSeqNum;
|
|
|
|
|
stats.fraction_lost = report_block.fractionLost;
|
|
|
|
|
stats.jitter = report_block.jitter;
|
2013-12-05 09:48:44 +00:00
|
|
|
|
2016-09-23 10:36:03 -07:00
|
|
|
stats_callback_->StatisticsUpdated(stats, report_block.sourceSSRC);
|
2013-12-05 09:48:44 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-19 13:49:55 +00:00
|
|
|
int32_t RTCPReceiver::CNAME(uint32_t remoteSSRC,
|
2013-04-08 11:08:41 +00:00
|
|
|
char cName[RTCP_CNAME_SIZE]) const {
|
2012-04-27 05:25:53 +00:00
|
|
|
assert(cName);
|
|
|
|
|
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
2012-01-24 17:16:59 +00:00
|
|
|
RTCPCnameInformation* cnameInfo = GetCnameInformation(remoteSSRC);
|
2012-04-27 05:25:53 +00:00
|
|
|
if (cnameInfo == NULL) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2012-01-24 17:16:59 +00:00
|
|
|
cName[RTCP_CNAME_SIZE - 1] = 0;
|
|
|
|
|
strncpy(cName, cnameInfo->name, RTCP_CNAME_SIZE - 1);
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-08-22 08:26:15 -07:00
|
|
|
std::vector<rtcp::TmmbItem> RTCPReceiver::TmmbrReceived() const {
|
2016-04-14 03:05:31 -07:00
|
|
|
rtc::CritScope lock(&_criticalSectionRTCPReceiver);
|
2016-08-16 15:15:39 -07:00
|
|
|
std::vector<rtcp::TmmbItem> candidates;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-08-16 15:15:39 -07:00
|
|
|
int64_t now_ms = _clock->TimeInMilliseconds();
|
|
|
|
|
|
|
|
|
|
for (const auto& kv : _receivedInfoMap) {
|
|
|
|
|
RTCPReceiveInformation* receive_info = kv.second;
|
|
|
|
|
RTC_DCHECK(receive_info);
|
2016-08-18 06:17:42 -07:00
|
|
|
receive_info->GetTmmbrSet(now_ms, &candidates);
|
2012-01-19 15:53:09 +00:00
|
|
|
}
|
2016-08-16 15:15:39 -07:00
|
|
|
return candidates;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace webrtc
|