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_sender.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2012-06-07 08:10:14 +00:00
|
|
|
#include <string.h> // memcpy
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-07-20 15:26:59 +02:00
|
|
|
#include <utility>
|
|
|
|
|
|
2015-04-27 13:32:52 +02:00
|
|
|
#include "webrtc/base/checks.h"
|
2016-04-26 08:14:39 -07:00
|
|
|
#include "webrtc/base/constructormagic.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-01-21 05:42:04 -08:00
|
|
|
#include "webrtc/call.h"
|
2013-05-29 14:27:38 +00:00
|
|
|
#include "webrtc/common_types.h"
|
Moved RtcEventLog files from call/ to logging/
The RtcEventLog headers need to be accessible from any place which needs
logging, and the implementation needs access to data structures that are
logged.
After a discussion in the code review, we all agreed to move the RtcEventLog implementation into its own top level directory - which I called "logging/" in expectation that other types of logging may have similar requirements. The directory contains two main build targets - "rtc_event_log_api", which is just rtc_event_log.h, that has no external dependencies and can be used from anywhere, and "rtc_event_log_impl" which contains the rest of the implementation and has many dependencies (more in the future).
The "api" target can be referenced from anywhere, while the "impl" target is only needed at the place of instantiation (currently Call, soon to be moved to PeerConnection by https://codereview.webrtc.org/2353033005/).
This change allows using RtcEventLog in the p2p/ directory, so that we
can log STUN pings and ICE state transitions.
BUG=webrtc:6393
R=kjellander@webrtc.org, kwiberg@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, terelius@webrtc.org
Review URL: https://codereview.webrtc.org/2380683005 .
Cr-Commit-Position: refs/heads/master@{#14485}
2016-10-03 18:31:22 -07:00
|
|
|
#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
|
2015-11-18 05:56:53 -08:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/app.h"
|
2015-11-22 09:03:11 -08:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h"
|
2016-01-13 02:03:04 -08:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/compound_packet.h"
|
2016-01-15 14:16:24 +01:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/extended_reports.h"
|
2016-01-15 13:19:53 +01:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/fir.h"
|
2015-12-22 03:43:04 -08:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/nack.h"
|
2015-11-27 05:36:09 -08:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/pli.h"
|
2015-12-04 16:13:30 +01:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/receiver_report.h"
|
2016-01-15 12:40:15 +01:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.h"
|
2016-01-15 15:21:21 +01:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/rpsi.h"
|
2016-01-15 17:34:27 +01:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sdes.h"
|
2016-01-18 02:43:32 -08:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
|
2016-01-12 10:04:52 -08:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sli.h"
|
2016-01-11 03:31:08 -08:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbn.h"
|
2016-01-11 11:49:19 -08:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/tmmbr.h"
|
2015-09-08 13:25:16 -07: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/rtp_rtcp_impl.h"
|
2016-05-24 13:25:27 -07:00
|
|
|
#include "webrtc/modules/rtp_rtcp/source/tmmbr_help.h"
|
2011-09-20 13:52:04 +00:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
namespace webrtc {
|
2012-01-19 15:53:09 +00:00
|
|
|
|
2016-12-01 05:18:09 -08:00
|
|
|
namespace {
|
|
|
|
|
const uint32_t kRtcpAnyExtendedReports =
|
|
|
|
|
kRtcpXrVoipMetric | kRtcpXrReceiverReferenceTime | kRtcpXrDlrrReportBlock |
|
|
|
|
|
kRtcpXrTargetBitrate;
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2015-04-27 13:32:52 +02:00
|
|
|
NACKStringBuilder::NACKStringBuilder()
|
2015-12-10 02:39:40 -08:00
|
|
|
: stream_(""), count_(0), prevNack_(0), consecutive_(false) {}
|
2013-04-04 19:43:34 +00:00
|
|
|
|
2013-07-31 15:17:19 +00:00
|
|
|
NACKStringBuilder::~NACKStringBuilder() {}
|
|
|
|
|
|
2015-12-10 02:39:40 -08:00
|
|
|
void NACKStringBuilder::PushNACK(uint16_t nack) {
|
2015-05-11 10:17:43 +02:00
|
|
|
if (count_ == 0) {
|
|
|
|
|
stream_ << nack;
|
|
|
|
|
} else if (nack == prevNack_ + 1) {
|
|
|
|
|
consecutive_ = true;
|
2015-04-27 13:32:52 +02:00
|
|
|
} else {
|
2015-05-11 10:17:43 +02:00
|
|
|
if (consecutive_) {
|
|
|
|
|
stream_ << "-" << prevNack_;
|
|
|
|
|
consecutive_ = false;
|
2013-04-04 19:43:34 +00:00
|
|
|
}
|
2015-05-11 10:17:43 +02:00
|
|
|
stream_ << "," << nack;
|
2015-04-27 13:32:52 +02:00
|
|
|
}
|
2015-05-11 10:17:43 +02:00
|
|
|
count_++;
|
|
|
|
|
prevNack_ = nack;
|
2013-04-04 19:43:34 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-27 13:32:52 +02:00
|
|
|
std::string NACKStringBuilder::GetResult() {
|
2015-05-11 10:17:43 +02:00
|
|
|
if (consecutive_) {
|
|
|
|
|
stream_ << "-" << prevNack_;
|
|
|
|
|
consecutive_ = false;
|
2015-04-27 13:32:52 +02:00
|
|
|
}
|
2015-05-11 10:17:43 +02:00
|
|
|
return stream_.str();
|
2013-04-04 19:43:34 +00:00
|
|
|
}
|
|
|
|
|
|
2013-09-09 16:02:19 +00:00
|
|
|
RTCPSender::FeedbackState::FeedbackState()
|
|
|
|
|
: send_payload_type(0),
|
2014-07-15 15:25:39 +00:00
|
|
|
packets_sent(0),
|
|
|
|
|
media_bytes_sent(0),
|
2013-09-09 16:02:19 +00:00
|
|
|
send_bitrate(0),
|
|
|
|
|
last_rr_ntp_secs(0),
|
|
|
|
|
last_rr_ntp_frac(0),
|
2013-10-02 13:15:34 +00:00
|
|
|
remote_sr(0),
|
2015-04-27 13:32:52 +02:00
|
|
|
has_last_xr_rr(false),
|
2015-12-10 02:39:40 -08:00
|
|
|
module(nullptr) {}
|
2013-09-09 16:02:19 +00:00
|
|
|
|
2016-01-13 02:03:04 -08:00
|
|
|
class PacketContainer : public rtcp::CompoundPacket,
|
2015-12-04 10:40:35 +01:00
|
|
|
public rtcp::RtcpPacket::PacketReadyCallback {
|
|
|
|
|
public:
|
2016-01-21 05:42:04 -08:00
|
|
|
PacketContainer(Transport* transport, RtcEventLog* event_log)
|
|
|
|
|
: transport_(transport), event_log_(event_log), bytes_sent_(0) {}
|
2015-12-04 10:40:35 +01:00
|
|
|
virtual ~PacketContainer() {
|
|
|
|
|
for (RtcpPacket* packet : appended_packets_)
|
|
|
|
|
delete packet;
|
2015-05-11 10:17:43 +02:00
|
|
|
}
|
|
|
|
|
|
2015-06-22 15:21:24 +02:00
|
|
|
void OnPacketReady(uint8_t* data, size_t length) override {
|
2016-01-21 05:42:04 -08:00
|
|
|
if (transport_->SendRtcp(data, length)) {
|
2015-12-04 10:40:35 +01:00
|
|
|
bytes_sent_ += length;
|
2016-01-21 05:42:04 -08:00
|
|
|
if (event_log_) {
|
|
|
|
|
event_log_->LogRtcpPacket(kOutgoingPacket, MediaType::ANY, data,
|
|
|
|
|
length);
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-06-22 15:21:24 +02:00
|
|
|
}
|
2015-12-04 10:40:35 +01:00
|
|
|
|
2016-03-30 11:11:51 -07:00
|
|
|
size_t SendPackets(size_t max_payload_length) {
|
2016-11-28 15:58:53 -08:00
|
|
|
RTC_DCHECK_LE(max_payload_length, IP_PACKET_SIZE);
|
2016-03-30 11:11:51 -07:00
|
|
|
uint8_t buffer[IP_PACKET_SIZE];
|
|
|
|
|
BuildExternalBuffer(buffer, max_payload_length, this);
|
2015-12-04 10:40:35 +01:00
|
|
|
return bytes_sent_;
|
2015-07-31 16:16:02 +02:00
|
|
|
}
|
2015-06-22 15:21:24 +02:00
|
|
|
|
|
|
|
|
private:
|
2015-12-04 10:40:35 +01:00
|
|
|
Transport* transport_;
|
2016-01-21 05:42:04 -08:00
|
|
|
RtcEventLog* const event_log_;
|
2015-12-04 10:40:35 +01:00
|
|
|
size_t bytes_sent_;
|
2016-01-21 05:42:04 -08:00
|
|
|
|
|
|
|
|
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(PacketContainer);
|
2015-12-04 10:40:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class RTCPSender::RtcpContext {
|
|
|
|
|
public:
|
|
|
|
|
RtcpContext(const FeedbackState& feedback_state,
|
|
|
|
|
int32_t nack_size,
|
|
|
|
|
const uint16_t* nack_list,
|
|
|
|
|
bool repeat,
|
|
|
|
|
uint64_t picture_id,
|
|
|
|
|
uint32_t ntp_sec,
|
2016-03-22 11:14:09 -07:00
|
|
|
uint32_t ntp_frac)
|
2015-12-04 10:40:35 +01:00
|
|
|
: feedback_state_(feedback_state),
|
|
|
|
|
nack_size_(nack_size),
|
|
|
|
|
nack_list_(nack_list),
|
|
|
|
|
repeat_(repeat),
|
|
|
|
|
picture_id_(picture_id),
|
|
|
|
|
ntp_sec_(ntp_sec),
|
2016-03-22 11:14:09 -07:00
|
|
|
ntp_frac_(ntp_frac) {}
|
2015-12-04 10:40:35 +01:00
|
|
|
|
|
|
|
|
const FeedbackState& feedback_state_;
|
|
|
|
|
const int32_t nack_size_;
|
|
|
|
|
const uint16_t* nack_list_;
|
|
|
|
|
const bool repeat_;
|
|
|
|
|
const uint64_t picture_id_;
|
|
|
|
|
const uint32_t ntp_sec_;
|
|
|
|
|
const uint32_t ntp_frac_;
|
2015-06-22 15:21:24 +02:00
|
|
|
};
|
|
|
|
|
|
2015-02-19 12:47:00 +00:00
|
|
|
RTCPSender::RTCPSender(
|
|
|
|
|
bool audio,
|
|
|
|
|
Clock* clock,
|
|
|
|
|
ReceiveStatistics* receive_statistics,
|
2015-09-29 04:45:43 -07:00
|
|
|
RtcpPacketTypeCounterObserver* packet_type_counter_observer,
|
2016-01-21 05:42:04 -08:00
|
|
|
RtcEventLog* event_log,
|
2015-09-29 04:45:43 -07:00
|
|
|
Transport* outgoing_transport)
|
2015-09-17 23:03:57 +02:00
|
|
|
: audio_(audio),
|
2015-05-11 10:17:43 +02:00
|
|
|
clock_(clock),
|
2015-12-15 00:30:07 -08:00
|
|
|
random_(clock_->TimeInMicroseconds()),
|
2015-10-02 02:36:56 -07:00
|
|
|
method_(RtcpMode::kOff),
|
2016-01-21 05:42:04 -08:00
|
|
|
event_log_(event_log),
|
2015-09-29 04:45:43 -07:00
|
|
|
transport_(outgoing_transport),
|
2015-05-11 10:17:43 +02:00
|
|
|
using_nack_(false),
|
|
|
|
|
sending_(false),
|
|
|
|
|
remb_enabled_(false),
|
|
|
|
|
next_time_to_send_rtcp_(0),
|
2016-08-18 02:01:49 -07:00
|
|
|
timestamp_offset_(0),
|
2014-12-19 13:49:55 +00:00
|
|
|
last_rtp_timestamp_(0),
|
|
|
|
|
last_frame_capture_time_ms_(-1),
|
2015-05-11 10:17:43 +02:00
|
|
|
ssrc_(0),
|
|
|
|
|
remote_ssrc_(0),
|
2014-12-19 13:49:55 +00:00
|
|
|
receive_statistics_(receive_statistics),
|
|
|
|
|
|
2015-05-11 10:17:43 +02:00
|
|
|
sequence_number_fir_(0),
|
2014-12-19 13:49:55 +00:00
|
|
|
|
2015-05-11 10:17:43 +02:00
|
|
|
remb_bitrate_(0),
|
2014-12-19 13:49:55 +00:00
|
|
|
|
2016-08-18 06:17:42 -07:00
|
|
|
tmmbr_send_bps_(0),
|
2015-05-11 10:17:43 +02:00
|
|
|
packet_oh_send_(0),
|
2016-03-30 11:11:51 -07:00
|
|
|
max_payload_length_(IP_PACKET_SIZE - 28), // IPv4 + UDP by default.
|
2014-12-19 13:49:55 +00:00
|
|
|
|
2015-05-11 10:17:43 +02:00
|
|
|
app_sub_type_(0),
|
2015-06-22 15:21:24 +02:00
|
|
|
app_name_(0),
|
2015-05-11 10:17:43 +02:00
|
|
|
app_data_(nullptr),
|
|
|
|
|
app_length_(0),
|
2014-12-19 13:49:55 +00:00
|
|
|
|
2015-05-11 10:17:43 +02:00
|
|
|
xr_send_receiver_reference_time_enabled_(false),
|
2015-02-19 12:47:00 +00:00
|
|
|
packet_type_counter_observer_(packet_type_counter_observer) {
|
2015-09-29 04:45:43 -07:00
|
|
|
RTC_DCHECK(transport_ != nullptr);
|
2015-05-11 10:17:43 +02:00
|
|
|
|
|
|
|
|
builders_[kRtcpSr] = &RTCPSender::BuildSR;
|
|
|
|
|
builders_[kRtcpRr] = &RTCPSender::BuildRR;
|
2015-06-25 14:46:16 +02:00
|
|
|
builders_[kRtcpSdes] = &RTCPSender::BuildSDES;
|
2015-05-11 10:17:43 +02:00
|
|
|
builders_[kRtcpPli] = &RTCPSender::BuildPLI;
|
|
|
|
|
builders_[kRtcpFir] = &RTCPSender::BuildFIR;
|
|
|
|
|
builders_[kRtcpSli] = &RTCPSender::BuildSLI;
|
|
|
|
|
builders_[kRtcpRpsi] = &RTCPSender::BuildRPSI;
|
|
|
|
|
builders_[kRtcpRemb] = &RTCPSender::BuildREMB;
|
|
|
|
|
builders_[kRtcpBye] = &RTCPSender::BuildBYE;
|
|
|
|
|
builders_[kRtcpApp] = &RTCPSender::BuildAPP;
|
|
|
|
|
builders_[kRtcpTmmbr] = &RTCPSender::BuildTMMBR;
|
|
|
|
|
builders_[kRtcpTmmbn] = &RTCPSender::BuildTMMBN;
|
|
|
|
|
builders_[kRtcpNack] = &RTCPSender::BuildNACK;
|
2016-12-01 05:18:09 -08:00
|
|
|
builders_[kRtcpAnyExtendedReports] = &RTCPSender::BuildExtendedReports;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-12-10 02:39:40 -08:00
|
|
|
RTCPSender::~RTCPSender() {}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-10-02 02:36:56 -07:00
|
|
|
RtcpMode RTCPSender::Status() const {
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2015-05-11 10:17:43 +02:00
|
|
|
return method_;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-01 14:46:44 -07:00
|
|
|
void RTCPSender::SetRTCPStatus(RtcpMode new_method) {
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2014-12-19 13:49:55 +00:00
|
|
|
|
2016-04-01 14:46:44 -07:00
|
|
|
if (method_ == RtcpMode::kOff && new_method != RtcpMode::kOff) {
|
|
|
|
|
// When switching on, reschedule the next packet
|
|
|
|
|
next_time_to_send_rtcp_ =
|
2015-05-11 10:17:43 +02:00
|
|
|
clock_->TimeInMilliseconds() +
|
|
|
|
|
(audio_ ? RTCP_INTERVAL_AUDIO_MS / 2 : RTCP_INTERVAL_VIDEO_MS / 2);
|
2016-04-01 14:46:44 -07:00
|
|
|
}
|
|
|
|
|
method_ = new_method;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-27 13:32:52 +02:00
|
|
|
bool RTCPSender::Sending() const {
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2015-05-11 10:17:43 +02:00
|
|
|
return sending_;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-27 13:32:52 +02:00
|
|
|
int32_t RTCPSender::SetSendingStatus(const FeedbackState& feedback_state,
|
|
|
|
|
bool sending) {
|
|
|
|
|
bool sendRTCPBye = false;
|
|
|
|
|
{
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2015-04-27 13:32:52 +02:00
|
|
|
|
2015-10-02 02:36:56 -07:00
|
|
|
if (method_ != RtcpMode::kOff) {
|
2015-05-11 10:17:43 +02:00
|
|
|
if (sending == false && sending_ == true) {
|
2015-04-27 13:32:52 +02:00
|
|
|
// Trigger RTCP bye
|
|
|
|
|
sendRTCPBye = true;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2015-05-11 10:17:43 +02:00
|
|
|
sending_ = sending;
|
2015-04-27 13:32:52 +02:00
|
|
|
}
|
|
|
|
|
if (sendRTCPBye)
|
|
|
|
|
return SendRTCP(feedback_state, kRtcpBye);
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-27 13:32:52 +02:00
|
|
|
bool RTCPSender::REMB() const {
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2015-05-11 10:17:43 +02:00
|
|
|
return remb_enabled_;
|
2011-09-20 13:52:04 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-19 13:49:55 +00:00
|
|
|
void RTCPSender::SetREMBStatus(bool enable) {
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2015-05-11 10:17:43 +02:00
|
|
|
remb_enabled_ = enable;
|
2011-09-20 13:52:04 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-19 13:49:55 +00:00
|
|
|
void RTCPSender::SetREMBData(uint32_t bitrate,
|
|
|
|
|
const std::vector<uint32_t>& ssrcs) {
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2015-05-11 10:17:43 +02:00
|
|
|
remb_bitrate_ = bitrate;
|
2014-12-19 13:49:55 +00:00
|
|
|
remb_ssrcs_ = ssrcs;
|
2014-07-11 09:55:30 +00:00
|
|
|
|
2015-05-11 10:17:43 +02:00
|
|
|
if (remb_enabled_)
|
|
|
|
|
SetFlag(kRtcpRemb, false);
|
2014-12-19 13:49:55 +00:00
|
|
|
// Send a REMB immediately if we have a new REMB. The frequency of REMBs is
|
|
|
|
|
// throttled by the caller.
|
2015-05-11 10:17:43 +02:00
|
|
|
next_time_to_send_rtcp_ = clock_->TimeInMilliseconds();
|
2011-09-20 13:52:04 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-27 13:32:52 +02:00
|
|
|
bool RTCPSender::TMMBR() const {
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2015-05-11 10:17:43 +02:00
|
|
|
return IsFlagPresent(RTCPPacketType::kRtcpTmmbr);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-19 13:49:55 +00:00
|
|
|
void RTCPSender::SetTMMBRStatus(bool enable) {
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2015-05-11 10:17:43 +02:00
|
|
|
if (enable) {
|
|
|
|
|
SetFlag(RTCPPacketType::kRtcpTmmbr, false);
|
|
|
|
|
} else {
|
|
|
|
|
ConsumeFlag(RTCPPacketType::kRtcpTmmbr, true);
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-30 11:11:51 -07:00
|
|
|
void RTCPSender::SetMaxPayloadLength(size_t max_payload_length) {
|
|
|
|
|
max_payload_length_ = max_payload_length;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-18 02:01:49 -07:00
|
|
|
void RTCPSender::SetTimestampOffset(uint32_t timestamp_offset) {
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2016-08-18 02:01:49 -07:00
|
|
|
timestamp_offset_ = timestamp_offset;
|
2012-09-11 07:00:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RTCPSender::SetLastRtpTime(uint32_t rtp_timestamp,
|
|
|
|
|
int64_t capture_time_ms) {
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2012-09-11 07:00:42 +00:00
|
|
|
last_rtp_timestamp_ = rtp_timestamp;
|
|
|
|
|
if (capture_time_ms < 0) {
|
|
|
|
|
// We don't currently get a capture time from VoiceEngine.
|
2015-05-11 10:17:43 +02:00
|
|
|
last_frame_capture_time_ms_ = clock_->TimeInMilliseconds();
|
2012-09-11 07:00:42 +00:00
|
|
|
} else {
|
|
|
|
|
last_frame_capture_time_ms_ = capture_time_ms;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-19 13:49:55 +00:00
|
|
|
void RTCPSender::SetSSRC(uint32_t ssrc) {
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2015-04-27 13:32:52 +02:00
|
|
|
|
2015-05-11 10:17:43 +02:00
|
|
|
if (ssrc_ != 0) {
|
2015-04-27 13:32:52 +02:00
|
|
|
// not first SetSSRC, probably due to a collision
|
|
|
|
|
// schedule a new RTCP report
|
|
|
|
|
// make sure that we send a RTP packet
|
2015-05-11 10:17:43 +02:00
|
|
|
next_time_to_send_rtcp_ = clock_->TimeInMilliseconds() + 100;
|
2015-04-27 13:32:52 +02:00
|
|
|
}
|
2015-05-11 10:17:43 +02:00
|
|
|
ssrc_ = ssrc;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-27 13:32:52 +02:00
|
|
|
void RTCPSender::SetRemoteSSRC(uint32_t ssrc) {
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2015-05-11 10:17:43 +02:00
|
|
|
remote_ssrc_ = ssrc;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-06-01 14:12:28 +02:00
|
|
|
int32_t RTCPSender::SetCNAME(const char* c_name) {
|
|
|
|
|
if (!c_name)
|
2012-04-26 15:28:22 +00:00
|
|
|
return -1;
|
|
|
|
|
|
2016-11-28 15:58:53 -08:00
|
|
|
RTC_DCHECK_LT(strlen(c_name), RTCP_CNAME_SIZE);
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2015-06-25 14:46:16 +02:00
|
|
|
cname_ = c_name;
|
2012-01-19 15:53:09 +00:00
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-06-25 14:46:16 +02:00
|
|
|
int32_t RTCPSender::AddMixedCNAME(uint32_t SSRC, const char* c_name) {
|
2016-03-22 11:14:09 -07:00
|
|
|
RTC_DCHECK(c_name);
|
2016-11-28 15:58:53 -08:00
|
|
|
RTC_DCHECK_LT(strlen(c_name), RTCP_CNAME_SIZE);
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2015-06-25 14:46:16 +02:00
|
|
|
if (csrc_cnames_.size() >= kRtpCsrcSize)
|
2012-01-19 15:53:09 +00:00
|
|
|
return -1;
|
2015-06-25 14:46:16 +02:00
|
|
|
|
|
|
|
|
csrc_cnames_[SSRC] = c_name;
|
2012-01-19 15:53:09 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2014-12-19 13:49:55 +00:00
|
|
|
int32_t RTCPSender::RemoveMixedCNAME(uint32_t SSRC) {
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2015-06-25 14:46:16 +02:00
|
|
|
auto it = csrc_cnames_.find(SSRC);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-05-11 10:17:43 +02:00
|
|
|
if (it == csrc_cnames_.end())
|
2011-07-07 08:21:25 +00:00
|
|
|
return -1;
|
2015-04-27 13:32:52 +02:00
|
|
|
|
2015-05-11 10:17:43 +02:00
|
|
|
csrc_cnames_.erase(it);
|
2012-01-19 15:53:09 +00:00
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-19 13:49:55 +00:00
|
|
|
bool RTCPSender::TimeToSendRTCPReport(bool sendKeyframeBeforeRTP) const {
|
2015-12-10 02:39:40 -08:00
|
|
|
/*
|
|
|
|
|
For audio we use a fix 5 sec interval
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-10 02:39:40 -08:00
|
|
|
For video we use 1 sec interval fo a BW smaller than 360 kbit/s,
|
|
|
|
|
technicaly we break the max 5% RTCP BW for video below 10 kbit/s but
|
|
|
|
|
that should be extremely rare
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
|
2015-12-10 02:39:40 -08:00
|
|
|
From RFC 3550
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-10 02:39:40 -08:00
|
|
|
MAX RTCP BW is 5% if the session BW
|
|
|
|
|
A send report is approximately 65 bytes inc CNAME
|
|
|
|
|
A receiver report is approximately 28 bytes
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-10 02:39:40 -08:00
|
|
|
The RECOMMENDED value for the reduced minimum in seconds is 360
|
|
|
|
|
divided by the session bandwidth in kilobits/second. This minimum
|
|
|
|
|
is smaller than 5 seconds for bandwidths greater than 72 kb/s.
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-10 02:39:40 -08:00
|
|
|
If the participant has not yet sent an RTCP packet (the variable
|
|
|
|
|
initial is true), the constant Tmin is set to 2.5 seconds, else it
|
|
|
|
|
is set to 5 seconds.
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-10 02:39:40 -08:00
|
|
|
The interval between RTCP packets is varied randomly over the
|
|
|
|
|
range [0.5,1.5] times the calculated interval to avoid unintended
|
|
|
|
|
synchronization of all participants
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-10 02:39:40 -08:00
|
|
|
if we send
|
|
|
|
|
If the participant is a sender (we_sent true), the constant C is
|
|
|
|
|
set to the average RTCP packet size (avg_rtcp_size) divided by 25%
|
|
|
|
|
of the RTCP bandwidth (rtcp_bw), and the constant n is set to the
|
|
|
|
|
number of senders.
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-10 02:39:40 -08:00
|
|
|
if we receive only
|
|
|
|
|
If we_sent is not true, the constant C is set
|
|
|
|
|
to the average RTCP packet size divided by 75% of the RTCP
|
|
|
|
|
bandwidth. The constant n is set to the number of receivers
|
|
|
|
|
(members - senders). If the number of senders is greater than
|
|
|
|
|
25%, senders and receivers are treated together.
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-10 02:39:40 -08:00
|
|
|
reconsideration NOT required for peer-to-peer
|
|
|
|
|
"timer reconsideration" is
|
|
|
|
|
employed. This algorithm implements a simple back-off mechanism
|
|
|
|
|
which causes users to hold back RTCP packet transmission if the
|
|
|
|
|
group sizes are increasing.
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-10 02:39:40 -08:00
|
|
|
n = number of members
|
|
|
|
|
C = avg_size/(rtcpBW/4)
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-10 02:39:40 -08:00
|
|
|
3. The deterministic calculated interval Td is set to max(Tmin, n*C).
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-10 02:39:40 -08:00
|
|
|
4. The calculated interval T is set to a number uniformly distributed
|
|
|
|
|
between 0.5 and 1.5 times the deterministic calculated interval.
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-10 02:39:40 -08:00
|
|
|
5. The resulting value of T is divided by e-3/2=1.21828 to compensate
|
|
|
|
|
for the fact that the timer reconsideration algorithm converges to
|
|
|
|
|
a value of the RTCP bandwidth below the intended average
|
|
|
|
|
*/
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-05-11 10:17:43 +02:00
|
|
|
int64_t now = clock_->TimeInMilliseconds();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-10-02 02:36:56 -07:00
|
|
|
if (method_ == RtcpMode::kOff)
|
2011-07-07 08:21:25 +00:00
|
|
|
return false;
|
|
|
|
|
|
2015-05-11 10:17:43 +02:00
|
|
|
if (!audio_ && sendKeyframeBeforeRTP) {
|
2015-04-27 13:32:52 +02:00
|
|
|
// for video key-frames we want to send the RTCP before the large key-frame
|
|
|
|
|
// if we have a 100 ms margin
|
|
|
|
|
now += RTCP_SEND_BEFORE_KEY_FRAME_MS;
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-05-11 10:17:43 +02:00
|
|
|
if (now >= next_time_to_send_rtcp_) {
|
2015-04-27 13:32:52 +02:00
|
|
|
return true;
|
|
|
|
|
} else if (now < 0x0000ffff &&
|
2015-05-11 10:17:43 +02:00
|
|
|
next_time_to_send_rtcp_ > 0xffff0000) { // 65 sec margin
|
2015-04-27 13:32:52 +02:00
|
|
|
// wrap
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildSR(const RtcpContext& ctx) {
|
2016-07-20 15:26:59 +02:00
|
|
|
// Timestamp shouldn't be estimated before first media frame.
|
|
|
|
|
RTC_DCHECK_GE(last_frame_capture_time_ms_, 0);
|
2015-04-27 13:32:52 +02:00
|
|
|
// The timestamp of this RTCP packet should be estimated as the timestamp of
|
|
|
|
|
// the frame being captured at this moment. We are calculating that
|
|
|
|
|
// timestamp as the last frame's timestamp + the time since the last frame
|
|
|
|
|
// was captured.
|
2016-10-03 06:22:25 -07:00
|
|
|
uint32_t rtp_rate =
|
|
|
|
|
(audio_ ? kBogusRtpRateForAudioRtcp : kVideoPayloadTypeFrequency) / 1000;
|
2015-06-22 15:21:24 +02:00
|
|
|
uint32_t rtp_timestamp =
|
2016-08-18 02:01:49 -07:00
|
|
|
timestamp_offset_ + last_rtp_timestamp_ +
|
2016-10-03 06:22:25 -07:00
|
|
|
(clock_->TimeInMilliseconds() - last_frame_capture_time_ms_) * rtp_rate;
|
2015-06-22 15:21:24 +02:00
|
|
|
|
2015-12-04 10:40:35 +01:00
|
|
|
rtcp::SenderReport* report = new rtcp::SenderReport();
|
2016-09-27 09:27:47 -07:00
|
|
|
report->SetSenderSsrc(ssrc_);
|
|
|
|
|
report->SetNtp(NtpTime(ctx.ntp_sec_, ctx.ntp_frac_));
|
|
|
|
|
report->SetRtpTimestamp(rtp_timestamp);
|
|
|
|
|
report->SetPacketCount(ctx.feedback_state_.packets_sent);
|
|
|
|
|
report->SetOctetCount(ctx.feedback_state_.media_bytes_sent);
|
2015-06-22 15:21:24 +02:00
|
|
|
|
|
|
|
|
for (auto it : report_blocks_)
|
2016-09-27 09:27:47 -07:00
|
|
|
report->AddReportBlock(it.second);
|
2015-05-11 10:17:43 +02:00
|
|
|
|
2015-06-22 15:21:24 +02:00
|
|
|
report_blocks_.clear();
|
2015-12-04 10:40:35 +01:00
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
return std::unique_ptr<rtcp::RtcpPacket>(report);
|
2015-04-27 13:32:52 +02:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildSDES(
|
2015-12-04 10:40:35 +01:00
|
|
|
const RtcpContext& ctx) {
|
2015-06-25 14:46:16 +02:00
|
|
|
size_t length_cname = cname_.length();
|
2016-11-28 15:58:53 -08:00
|
|
|
RTC_CHECK_LT(length_cname, RTCP_CNAME_SIZE);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-04 10:40:35 +01:00
|
|
|
rtcp::Sdes* sdes = new rtcp::Sdes();
|
2016-09-27 09:27:47 -07:00
|
|
|
sdes->AddCName(ssrc_, cname_);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-06-25 14:46:16 +02:00
|
|
|
for (const auto it : csrc_cnames_)
|
2016-09-27 09:27:47 -07:00
|
|
|
sdes->AddCName(it.first, it.second);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
return std::unique_ptr<rtcp::RtcpPacket>(sdes);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildRR(const RtcpContext& ctx) {
|
2015-12-04 10:40:35 +01:00
|
|
|
rtcp::ReceiverReport* report = new rtcp::ReceiverReport();
|
2016-09-27 09:27:47 -07:00
|
|
|
report->SetSenderSsrc(ssrc_);
|
2015-06-22 15:21:24 +02:00
|
|
|
for (auto it : report_blocks_)
|
2016-09-27 09:27:47 -07:00
|
|
|
report->AddReportBlock(it.second);
|
2015-04-27 13:32:52 +02:00
|
|
|
|
2015-06-22 15:21:24 +02:00
|
|
|
report_blocks_.clear();
|
2016-03-22 11:14:09 -07:00
|
|
|
return std::unique_ptr<rtcp::RtcpPacket>(report);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildPLI(const RtcpContext& ctx) {
|
2015-12-04 10:40:35 +01:00
|
|
|
rtcp::Pli* pli = new rtcp::Pli();
|
2016-09-27 09:27:47 -07:00
|
|
|
pli->SetSenderSsrc(ssrc_);
|
|
|
|
|
pli->SetMediaSsrc(remote_ssrc_);
|
2015-05-11 10:17:43 +02:00
|
|
|
|
|
|
|
|
TRACE_EVENT_INSTANT0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"),
|
|
|
|
|
"RTCPSender::PLI");
|
|
|
|
|
++packet_type_counter_.pli_packets;
|
|
|
|
|
TRACE_COUNTER_ID1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RTCP_PLICount",
|
|
|
|
|
ssrc_, packet_type_counter_.pli_packets);
|
|
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
return std::unique_ptr<rtcp::RtcpPacket>(pli);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildFIR(const RtcpContext& ctx) {
|
2015-12-04 10:40:35 +01:00
|
|
|
if (!ctx.repeat_)
|
2015-08-05 02:35:35 -07:00
|
|
|
++sequence_number_fir_; // Do not increase if repetition.
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-04 10:40:35 +01:00
|
|
|
rtcp::Fir* fir = new rtcp::Fir();
|
2016-09-27 09:27:47 -07:00
|
|
|
fir->SetSenderSsrc(ssrc_);
|
|
|
|
|
fir->AddRequestTo(remote_ssrc_, sequence_number_fir_);
|
2015-05-11 10:17:43 +02:00
|
|
|
|
|
|
|
|
TRACE_EVENT_INSTANT0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"),
|
|
|
|
|
"RTCPSender::FIR");
|
|
|
|
|
++packet_type_counter_.fir_packets;
|
|
|
|
|
TRACE_COUNTER_ID1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RTCP_FIRCount",
|
|
|
|
|
ssrc_, packet_type_counter_.fir_packets);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
return std::unique_ptr<rtcp::RtcpPacket>(fir);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
0 1 2 3
|
|
|
|
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
| First | Number | PictureID |
|
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
*/
|
2016-03-22 11:14:09 -07:00
|
|
|
std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildSLI(const RtcpContext& ctx) {
|
2015-12-04 10:40:35 +01:00
|
|
|
rtcp::Sli* sli = new rtcp::Sli();
|
2016-09-27 09:27:47 -07:00
|
|
|
sli->SetSenderSsrc(ssrc_);
|
|
|
|
|
sli->SetMediaSsrc(remote_ssrc_);
|
2015-08-11 01:02:37 -07:00
|
|
|
// Crop picture id to 6 least significant bits.
|
2016-09-27 09:27:47 -07:00
|
|
|
sli->AddPictureId(ctx.picture_id_ & 0x3F);
|
2015-05-11 10:17:43 +02:00
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
return std::unique_ptr<rtcp::RtcpPacket>(sli);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
0 1 2 3
|
|
|
|
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
| PB |0| Payload Type| Native RPSI bit string |
|
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
| defined per codec ... | Padding (0) |
|
|
|
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
*/
|
|
|
|
|
/*
|
|
|
|
|
* Note: not generic made for VP8
|
|
|
|
|
*/
|
2016-03-22 11:14:09 -07:00
|
|
|
std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildRPSI(
|
2015-12-04 10:40:35 +01:00
|
|
|
const RtcpContext& ctx) {
|
|
|
|
|
if (ctx.feedback_state_.send_payload_type == 0xFF)
|
|
|
|
|
return nullptr;
|
2015-05-11 10:17:43 +02:00
|
|
|
|
2015-12-04 10:40:35 +01:00
|
|
|
rtcp::Rpsi* rpsi = new rtcp::Rpsi();
|
2016-09-27 09:27:47 -07:00
|
|
|
rpsi->SetSenderSsrc(ssrc_);
|
|
|
|
|
rpsi->SetMediaSsrc(remote_ssrc_);
|
|
|
|
|
rpsi->SetPayloadType(ctx.feedback_state_.send_payload_type);
|
|
|
|
|
rpsi->SetPictureId(ctx.picture_id_);
|
2015-04-27 13:32:52 +02:00
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
return std::unique_ptr<rtcp::RtcpPacket>(rpsi);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildREMB(
|
2015-12-04 10:40:35 +01:00
|
|
|
const RtcpContext& ctx) {
|
|
|
|
|
rtcp::Remb* remb = new rtcp::Remb();
|
2016-09-27 09:27:47 -07:00
|
|
|
remb->SetSenderSsrc(ssrc_);
|
|
|
|
|
remb->SetBitrateBps(remb_bitrate_);
|
|
|
|
|
remb->SetSsrcs(remb_ssrcs_);
|
2015-08-18 04:37:31 -07:00
|
|
|
|
2015-05-11 10:17:43 +02:00
|
|
|
TRACE_EVENT_INSTANT0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"),
|
|
|
|
|
"RTCPSender::REMB");
|
|
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
return std::unique_ptr<rtcp::RtcpPacket>(remb);
|
2011-09-20 13:52:04 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-27 13:32:52 +02:00
|
|
|
void RTCPSender::SetTargetBitrate(unsigned int target_bitrate) {
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2016-08-18 06:17:42 -07:00
|
|
|
tmmbr_send_bps_ = target_bitrate;
|
2012-01-13 08:52:58 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildTMMBR(
|
2015-12-04 10:40:35 +01:00
|
|
|
const RtcpContext& ctx) {
|
|
|
|
|
if (ctx.feedback_state_.module == nullptr)
|
|
|
|
|
return nullptr;
|
2015-04-27 13:32:52 +02:00
|
|
|
// Before sending the TMMBR check the received TMMBN, only an owner is
|
|
|
|
|
// allowed to raise the bitrate:
|
|
|
|
|
// * If the sender is an owner of the TMMBN -> send TMMBR
|
|
|
|
|
// * If not an owner but the TMMBR would enter the TMMBN -> send TMMBR
|
|
|
|
|
|
|
|
|
|
// get current bounding set from RTCP receiver
|
2016-08-18 06:17:42 -07:00
|
|
|
bool tmmbr_owner = false;
|
2015-04-27 13:32:52 +02:00
|
|
|
|
2015-05-11 10:17:43 +02:00
|
|
|
// holding critical_section_rtcp_sender_ while calling RTCPreceiver which
|
|
|
|
|
// will accuire criticalSectionRTCPReceiver_ is a potental deadlock but
|
2015-04-27 13:32:52 +02:00
|
|
|
// since RTCPreceiver is not doing the reverse we should be fine
|
2016-08-18 06:17:42 -07:00
|
|
|
std::vector<rtcp::TmmbItem> candidates =
|
|
|
|
|
ctx.feedback_state_.module->BoundingSet(&tmmbr_owner);
|
2015-04-27 13:32:52 +02:00
|
|
|
|
2016-08-18 06:17:42 -07:00
|
|
|
if (!candidates.empty()) {
|
|
|
|
|
for (const auto& candidate : candidates) {
|
|
|
|
|
if (candidate.bitrate_bps() == tmmbr_send_bps_ &&
|
|
|
|
|
candidate.packet_overhead() == packet_oh_send_) {
|
2015-12-04 10:40:35 +01:00
|
|
|
// Do not send the same tuple.
|
|
|
|
|
return nullptr;
|
2015-04-27 13:32:52 +02:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2016-08-18 06:17:42 -07:00
|
|
|
if (!tmmbr_owner) {
|
|
|
|
|
// Use received bounding set as candidate set.
|
|
|
|
|
// Add current tuple.
|
|
|
|
|
candidates.emplace_back(ssrc_, tmmbr_send_bps_, packet_oh_send_);
|
2015-04-27 13:32:52 +02:00
|
|
|
|
2016-08-18 06:17:42 -07:00
|
|
|
// Find bounding set.
|
2016-08-16 03:21:38 -07:00
|
|
|
std::vector<rtcp::TmmbItem> bounding =
|
|
|
|
|
TMMBRHelp::FindBoundingSet(std::move(candidates));
|
2016-08-18 06:17:42 -07:00
|
|
|
tmmbr_owner = TMMBRHelp::IsOwner(bounding, ssrc_);
|
|
|
|
|
if (!tmmbr_owner) {
|
2015-12-04 10:40:35 +01:00
|
|
|
// Did not enter bounding set, no meaning to send this request.
|
|
|
|
|
return nullptr;
|
2015-04-27 13:32:52 +02:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2015-04-27 13:32:52 +02:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-08-18 06:17:42 -07:00
|
|
|
if (!tmmbr_send_bps_)
|
2015-12-04 10:40:35 +01:00
|
|
|
return nullptr;
|
2015-08-21 05:30:11 -07:00
|
|
|
|
2015-12-04 10:40:35 +01:00
|
|
|
rtcp::Tmmbr* tmmbr = new rtcp::Tmmbr();
|
2016-09-27 09:27:47 -07:00
|
|
|
tmmbr->SetSenderSsrc(ssrc_);
|
2016-02-05 04:56:36 -08:00
|
|
|
rtcp::TmmbItem request;
|
|
|
|
|
request.set_ssrc(remote_ssrc_);
|
2016-08-18 06:17:42 -07:00
|
|
|
request.set_bitrate_bps(tmmbr_send_bps_);
|
2016-02-05 04:56:36 -08:00
|
|
|
request.set_packet_overhead(packet_oh_send_);
|
2016-09-27 09:27:47 -07:00
|
|
|
tmmbr->AddTmmbr(request);
|
2015-12-04 10:40:35 +01:00
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
return std::unique_ptr<rtcp::RtcpPacket>(tmmbr);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildTMMBN(
|
2015-12-04 10:40:35 +01:00
|
|
|
const RtcpContext& ctx) {
|
|
|
|
|
rtcp::Tmmbn* tmmbn = new rtcp::Tmmbn();
|
2016-09-27 09:27:47 -07:00
|
|
|
tmmbn->SetSenderSsrc(ssrc_);
|
2016-05-09 10:59:50 -07:00
|
|
|
for (const rtcp::TmmbItem& tmmbr : tmmbn_to_send_) {
|
|
|
|
|
if (tmmbr.bitrate_bps() > 0) {
|
2016-09-27 09:27:47 -07:00
|
|
|
tmmbn->AddTmmbr(tmmbr);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2015-04-27 13:32:52 +02:00
|
|
|
}
|
2015-08-27 01:05:08 -07:00
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
return std::unique_ptr<rtcp::RtcpPacket>(tmmbn);
|
2015-04-27 13:32:52 +02:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildAPP(const RtcpContext& ctx) {
|
2015-12-04 10:40:35 +01:00
|
|
|
rtcp::App* app = new rtcp::App();
|
2016-09-27 09:27:47 -07:00
|
|
|
app->SetSsrc(ssrc_);
|
|
|
|
|
app->SetSubType(app_sub_type_);
|
|
|
|
|
app->SetName(app_name_);
|
|
|
|
|
app->SetData(app_data_.get(), app_length_);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
return std::unique_ptr<rtcp::RtcpPacket>(app);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildNACK(
|
2015-12-04 10:40:35 +01:00
|
|
|
const RtcpContext& ctx) {
|
|
|
|
|
rtcp::Nack* nack = new rtcp::Nack();
|
2016-09-27 09:27:47 -07:00
|
|
|
nack->SetSenderSsrc(ssrc_);
|
|
|
|
|
nack->SetMediaSsrc(remote_ssrc_);
|
|
|
|
|
nack->SetPacketIds(ctx.nack_list_, ctx.nack_size_);
|
2014-10-29 12:42:30 +00:00
|
|
|
|
2015-04-27 13:32:52 +02:00
|
|
|
// Report stats.
|
|
|
|
|
NACKStringBuilder stringBuilder;
|
2015-12-04 10:40:35 +01:00
|
|
|
for (int idx = 0; idx < ctx.nack_size_; ++idx) {
|
|
|
|
|
stringBuilder.PushNACK(ctx.nack_list_[idx]);
|
|
|
|
|
nack_stats_.ReportRequest(ctx.nack_list_[idx]);
|
2015-04-27 13:32:52 +02:00
|
|
|
}
|
|
|
|
|
packet_type_counter_.nack_requests = nack_stats_.requests();
|
|
|
|
|
packet_type_counter_.unique_nack_requests = nack_stats_.unique_requests();
|
2015-05-11 10:17:43 +02:00
|
|
|
|
|
|
|
|
TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"),
|
|
|
|
|
"RTCPSender::NACK", "nacks",
|
|
|
|
|
TRACE_STR_COPY(stringBuilder.GetResult().c_str()));
|
|
|
|
|
++packet_type_counter_.nack_packets;
|
|
|
|
|
TRACE_COUNTER_ID1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RTCP_NACKCount",
|
|
|
|
|
ssrc_, packet_type_counter_.nack_packets);
|
|
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
return std::unique_ptr<rtcp::RtcpPacket>(nack);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildBYE(const RtcpContext& ctx) {
|
2015-12-04 10:40:35 +01:00
|
|
|
rtcp::Bye* bye = new rtcp::Bye();
|
2016-09-27 09:27:47 -07:00
|
|
|
bye->SetSenderSsrc(ssrc_);
|
|
|
|
|
bye->SetCsrcs(csrcs_);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
return std::unique_ptr<rtcp::RtcpPacket>(bye);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-12-01 05:18:09 -08:00
|
|
|
std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildExtendedReports(
|
2015-12-04 10:40:35 +01:00
|
|
|
const RtcpContext& ctx) {
|
2016-12-01 05:18:09 -08:00
|
|
|
std::unique_ptr<rtcp::ExtendedReports> xr(new rtcp::ExtendedReports());
|
2016-09-27 09:27:47 -07:00
|
|
|
xr->SetSenderSsrc(ssrc_);
|
2013-10-02 13:15:34 +00:00
|
|
|
|
2016-12-01 05:18:09 -08:00
|
|
|
if (!sending_ && xr_send_receiver_reference_time_enabled_) {
|
|
|
|
|
rtcp::Rrtr rrtr;
|
|
|
|
|
rrtr.SetNtp(NtpTime(ctx.ntp_sec_, ctx.ntp_frac_));
|
|
|
|
|
xr->SetRrtr(rrtr);
|
|
|
|
|
}
|
2015-08-31 14:00:50 +02:00
|
|
|
|
2016-12-01 05:18:09 -08:00
|
|
|
if (ctx.feedback_state_.has_last_xr_rr) {
|
|
|
|
|
xr->AddDlrrItem(ctx.feedback_state_.last_xr_rr);
|
|
|
|
|
}
|
2013-10-02 13:15:34 +00:00
|
|
|
|
2016-12-01 05:18:09 -08:00
|
|
|
if (video_bitrate_allocation_) {
|
|
|
|
|
rtcp::TargetBitrate target_bitrate;
|
2013-10-02 13:15:34 +00:00
|
|
|
|
2016-12-01 05:18:09 -08:00
|
|
|
for (int sl = 0; sl < kMaxSpatialLayers; ++sl) {
|
|
|
|
|
for (int tl = 0; tl < kMaxTemporalStreams; ++tl) {
|
|
|
|
|
uint32_t layer_bitrate_bps =
|
|
|
|
|
video_bitrate_allocation_->GetBitrate(sl, tl);
|
|
|
|
|
if (layer_bitrate_bps > 0)
|
|
|
|
|
target_bitrate.AddTargetBitrate(sl, tl, layer_bitrate_bps / 1000);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-10-02 13:15:34 +00:00
|
|
|
|
2016-12-01 05:18:09 -08:00
|
|
|
xr->SetTargetBitrate(target_bitrate);
|
|
|
|
|
video_bitrate_allocation_.reset();
|
|
|
|
|
}
|
2015-08-31 14:00:50 +02:00
|
|
|
|
2016-12-01 05:18:09 -08:00
|
|
|
if (xr_voip_metric_) {
|
|
|
|
|
rtcp::VoipMetric voip;
|
|
|
|
|
voip.SetMediaSsrc(remote_ssrc_);
|
|
|
|
|
voip.SetVoipMetric(*xr_voip_metric_);
|
|
|
|
|
xr_voip_metric_.reset();
|
2015-08-31 14:00:50 +02:00
|
|
|
|
2016-12-01 05:18:09 -08:00
|
|
|
xr->SetVoipMetric(voip);
|
|
|
|
|
}
|
2015-05-11 10:17:43 +02:00
|
|
|
|
2016-12-01 05:18:09 -08:00
|
|
|
return std::move(xr);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-09-09 16:02:19 +00:00
|
|
|
int32_t RTCPSender::SendRTCP(const FeedbackState& feedback_state,
|
2015-05-11 10:17:43 +02:00
|
|
|
RTCPPacketType packetType,
|
|
|
|
|
int32_t nack_size,
|
|
|
|
|
const uint16_t* nack_list,
|
2013-09-09 16:02:19 +00:00
|
|
|
bool repeat,
|
|
|
|
|
uint64_t pictureID) {
|
2015-05-11 10:17:43 +02:00
|
|
|
return SendCompoundRTCP(
|
|
|
|
|
feedback_state, std::set<RTCPPacketType>(&packetType, &packetType + 1),
|
|
|
|
|
nack_size, nack_list, repeat, pictureID);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t RTCPSender::SendCompoundRTCP(
|
|
|
|
|
const FeedbackState& feedback_state,
|
2015-12-04 10:40:35 +01:00
|
|
|
const std::set<RTCPPacketType>& packet_types,
|
2015-05-11 10:17:43 +02:00
|
|
|
int32_t nack_size,
|
|
|
|
|
const uint16_t* nack_list,
|
|
|
|
|
bool repeat,
|
|
|
|
|
uint64_t pictureID) {
|
2016-01-21 05:42:04 -08:00
|
|
|
PacketContainer container(transport_, event_log_);
|
2013-08-21 20:58:21 +00:00
|
|
|
{
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2015-10-02 02:36:56 -07:00
|
|
|
if (method_ == RtcpMode::kOff) {
|
2015-04-27 13:32:52 +02:00
|
|
|
LOG(LS_WARNING) << "Can't send rtcp if it is disabled.";
|
|
|
|
|
return -1;
|
2013-08-21 20:58:21 +00:00
|
|
|
}
|
2016-07-20 15:26:59 +02:00
|
|
|
// Add all flags as volatile. Non volatile entries will not be overwritten.
|
|
|
|
|
// All new volatile flags added will be consumed by the end of this call.
|
|
|
|
|
SetFlags(packet_types, true);
|
|
|
|
|
|
|
|
|
|
// Prevent sending streams to send SR before any media has been sent.
|
|
|
|
|
const bool can_calculate_rtp_timestamp = (last_frame_capture_time_ms_ >= 0);
|
|
|
|
|
if (!can_calculate_rtp_timestamp) {
|
|
|
|
|
bool consumed_sr_flag = ConsumeFlag(kRtcpSr);
|
|
|
|
|
bool consumed_report_flag = sending_ && ConsumeFlag(kRtcpReport);
|
|
|
|
|
bool sender_report = consumed_report_flag || consumed_sr_flag;
|
|
|
|
|
if (sender_report && AllVolatileFlagsConsumed()) {
|
|
|
|
|
// This call was for Sender Report and nothing else.
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (sending_ && method_ == RtcpMode::kCompound) {
|
|
|
|
|
// Not allowed to send any RTCP packet without sender report.
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (packet_type_counter_.first_packet_time_ms == -1)
|
|
|
|
|
packet_type_counter_.first_packet_time_ms = clock_->TimeInMilliseconds();
|
2015-04-27 13:32:52 +02:00
|
|
|
|
2015-12-04 10:40:35 +01:00
|
|
|
// We need to send our NTP even if we haven't received any reports.
|
|
|
|
|
uint32_t ntp_sec;
|
|
|
|
|
uint32_t ntp_frac;
|
|
|
|
|
clock_->CurrentNtp(ntp_sec, ntp_frac);
|
|
|
|
|
RtcpContext context(feedback_state, nack_size, nack_list, repeat, pictureID,
|
2016-03-22 11:14:09 -07:00
|
|
|
ntp_sec, ntp_frac);
|
2015-12-04 10:40:35 +01:00
|
|
|
|
2016-07-20 15:26:59 +02:00
|
|
|
PrepareReport(feedback_state);
|
2015-12-04 10:40:35 +01:00
|
|
|
|
2016-03-22 11:14:09 -07:00
|
|
|
std::unique_ptr<rtcp::RtcpPacket> packet_bye;
|
2016-02-18 08:33:26 -08:00
|
|
|
|
2015-12-04 10:40:35 +01:00
|
|
|
auto it = report_flags_.begin();
|
|
|
|
|
while (it != report_flags_.end()) {
|
|
|
|
|
auto builder_it = builders_.find(it->type);
|
2016-12-01 05:18:09 -08:00
|
|
|
RTC_DCHECK(builder_it != builders_.end())
|
|
|
|
|
<< "Could not find builder for packet type " << it->type;
|
2015-12-04 10:40:35 +01:00
|
|
|
if (it->is_volatile) {
|
|
|
|
|
report_flags_.erase(it++);
|
|
|
|
|
} else {
|
|
|
|
|
++it;
|
|
|
|
|
}
|
2015-04-27 13:32:52 +02:00
|
|
|
|
2015-12-04 10:40:35 +01:00
|
|
|
BuilderFunc func = builder_it->second;
|
2016-03-22 11:14:09 -07:00
|
|
|
std::unique_ptr<rtcp::RtcpPacket> packet = (this->*func)(context);
|
2015-12-04 10:40:35 +01:00
|
|
|
if (packet.get() == nullptr)
|
|
|
|
|
return -1;
|
2016-02-18 08:33:26 -08:00
|
|
|
// If there is a BYE, don't append now - save it and append it
|
|
|
|
|
// at the end later.
|
|
|
|
|
if (builder_it->first == kRtcpBye) {
|
|
|
|
|
packet_bye = std::move(packet);
|
|
|
|
|
} else {
|
|
|
|
|
container.Append(packet.release());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Append the BYE now at the end
|
|
|
|
|
if (packet_bye) {
|
|
|
|
|
container.Append(packet_bye.release());
|
2015-12-04 10:40:35 +01:00
|
|
|
}
|
2013-08-21 19:44:13 +00:00
|
|
|
|
2015-12-04 10:40:35 +01:00
|
|
|
if (packet_type_counter_observer_ != nullptr) {
|
|
|
|
|
packet_type_counter_observer_->RtcpPacketTypesCounterUpdated(
|
|
|
|
|
remote_ssrc_, packet_type_counter_);
|
|
|
|
|
}
|
2015-05-11 10:17:43 +02:00
|
|
|
|
2015-12-04 10:40:35 +01:00
|
|
|
RTC_DCHECK(AllVolatileFlagsConsumed());
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 11:11:51 -07:00
|
|
|
size_t bytes_sent = container.SendPackets(max_payload_length_);
|
2015-12-04 10:40:35 +01:00
|
|
|
return bytes_sent == 0 ? -1 : 0;
|
|
|
|
|
}
|
2013-08-21 19:44:13 +00:00
|
|
|
|
2016-07-20 15:26:59 +02:00
|
|
|
void RTCPSender::PrepareReport(const FeedbackState& feedback_state) {
|
2015-05-11 10:17:43 +02:00
|
|
|
bool generate_report;
|
|
|
|
|
if (IsFlagPresent(kRtcpSr) || IsFlagPresent(kRtcpRr)) {
|
|
|
|
|
// Report type already explicitly set, don't automatically populate.
|
|
|
|
|
generate_report = true;
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(ConsumeFlag(kRtcpReport) == false);
|
2015-05-11 10:17:43 +02:00
|
|
|
} else {
|
|
|
|
|
generate_report =
|
2015-10-02 02:36:56 -07:00
|
|
|
(ConsumeFlag(kRtcpReport) && method_ == RtcpMode::kReducedSize) ||
|
|
|
|
|
method_ == RtcpMode::kCompound;
|
2015-05-11 10:17:43 +02:00
|
|
|
if (generate_report)
|
|
|
|
|
SetFlag(sending_ ? kRtcpSr : kRtcpRr, true);
|
2013-08-21 20:58:21 +00:00
|
|
|
}
|
2015-05-11 10:17:43 +02:00
|
|
|
|
2015-06-25 14:46:16 +02:00
|
|
|
if (IsFlagPresent(kRtcpSr) || (IsFlagPresent(kRtcpRr) && !cname_.empty()))
|
2015-05-11 10:17:43 +02:00
|
|
|
SetFlag(kRtcpSdes, true);
|
|
|
|
|
|
|
|
|
|
if (generate_report) {
|
2016-12-01 05:18:09 -08:00
|
|
|
if ((!sending_ && xr_send_receiver_reference_time_enabled_) ||
|
|
|
|
|
feedback_state.has_last_xr_rr || video_bitrate_allocation_) {
|
|
|
|
|
SetFlag(kRtcpAnyExtendedReports, true);
|
|
|
|
|
}
|
2015-05-11 10:17:43 +02:00
|
|
|
|
|
|
|
|
// generate next time to send an RTCP report
|
2015-12-15 00:30:07 -08:00
|
|
|
uint32_t minIntervalMs = RTCP_INTERVAL_AUDIO_MS;
|
|
|
|
|
|
|
|
|
|
if (!audio_) {
|
2015-05-11 10:17:43 +02:00
|
|
|
if (sending_) {
|
2015-04-27 13:32:52 +02:00
|
|
|
// Calculate bandwidth for video; 360 / send bandwidth in kbit/s.
|
|
|
|
|
uint32_t send_bitrate_kbit = feedback_state.send_bitrate / 1000;
|
|
|
|
|
if (send_bitrate_kbit != 0)
|
|
|
|
|
minIntervalMs = 360000 / send_bitrate_kbit;
|
2013-08-21 20:58:21 +00:00
|
|
|
}
|
2015-04-27 13:32:52 +02:00
|
|
|
if (minIntervalMs > RTCP_INTERVAL_VIDEO_MS)
|
|
|
|
|
minIntervalMs = RTCP_INTERVAL_VIDEO_MS;
|
|
|
|
|
}
|
2015-12-15 00:30:07 -08:00
|
|
|
// The interval between RTCP packets is varied randomly over the
|
|
|
|
|
// range [1/2,3/2] times the calculated interval.
|
|
|
|
|
uint32_t timeToNext =
|
|
|
|
|
random_.Rand(minIntervalMs * 1 / 2, minIntervalMs * 3 / 2);
|
2015-05-11 10:17:43 +02:00
|
|
|
next_time_to_send_rtcp_ = clock_->TimeInMilliseconds() + timeToNext;
|
2013-08-21 19:44:13 +00:00
|
|
|
|
2016-04-15 14:59:13 +02:00
|
|
|
if (receive_statistics_) {
|
|
|
|
|
StatisticianMap statisticians =
|
|
|
|
|
receive_statistics_->GetActiveStatisticians();
|
|
|
|
|
RTC_DCHECK(report_blocks_.empty());
|
|
|
|
|
for (auto& it : statisticians) {
|
|
|
|
|
AddReportBlock(feedback_state, it.first, it.second);
|
|
|
|
|
}
|
2013-08-21 20:58:21 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-08-21 19:44:13 +00:00
|
|
|
|
2015-12-22 08:07:45 -08:00
|
|
|
bool RTCPSender::AddReportBlock(const FeedbackState& feedback_state,
|
|
|
|
|
uint32_t ssrc,
|
|
|
|
|
StreamStatistician* statistician) {
|
2013-08-21 20:58:21 +00:00
|
|
|
// Do we have receive statistics to send?
|
2013-12-19 13:26:02 +00:00
|
|
|
RtcpStatistics stats;
|
2013-08-21 20:58:21 +00:00
|
|
|
if (!statistician->GetStatistics(&stats, true))
|
|
|
|
|
return false;
|
2015-12-22 08:07:45 -08:00
|
|
|
|
|
|
|
|
if (report_blocks_.size() >= RTCP_MAX_REPORT_BLOCKS) {
|
|
|
|
|
LOG(LS_WARNING) << "Too many report blocks.";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
RTC_DCHECK(report_blocks_.find(ssrc) == report_blocks_.end());
|
|
|
|
|
rtcp::ReportBlock* block = &report_blocks_[ssrc];
|
2016-09-27 09:27:47 -07:00
|
|
|
block->SetMediaSsrc(ssrc);
|
|
|
|
|
block->SetFractionLost(stats.fraction_lost);
|
|
|
|
|
if (!block->SetCumulativeLost(stats.cumulative_lost)) {
|
2015-12-22 08:07:45 -08:00
|
|
|
report_blocks_.erase(ssrc);
|
|
|
|
|
LOG(LS_WARNING) << "Cumulative lost is oversized.";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-09-27 09:27:47 -07:00
|
|
|
block->SetExtHighestSeqNum(stats.extended_max_sequence_number);
|
|
|
|
|
block->SetJitter(stats.jitter);
|
|
|
|
|
block->SetLastSr(feedback_state.remote_sr);
|
2013-08-21 20:58:21 +00:00
|
|
|
|
2015-06-22 15:21:24 +02:00
|
|
|
// TODO(sprang): Do we really need separate time stamps for each report?
|
|
|
|
|
// Get our NTP as late as possible to avoid a race.
|
|
|
|
|
uint32_t ntp_secs;
|
|
|
|
|
uint32_t ntp_frac;
|
|
|
|
|
clock_->CurrentNtp(ntp_secs, ntp_frac);
|
2013-08-21 20:58:21 +00:00
|
|
|
|
2015-06-22 15:21:24 +02:00
|
|
|
// Delay since last received report.
|
2013-09-09 16:02:19 +00:00
|
|
|
if ((feedback_state.last_rr_ntp_secs != 0) ||
|
|
|
|
|
(feedback_state.last_rr_ntp_frac != 0)) {
|
2015-06-22 15:21:24 +02:00
|
|
|
// Get the 16 lowest bits of seconds and the 16 highest bits of fractions.
|
|
|
|
|
uint32_t now = ntp_secs & 0x0000FFFF;
|
2015-04-27 13:32:52 +02:00
|
|
|
now <<= 16;
|
2015-06-22 15:21:24 +02:00
|
|
|
now += (ntp_frac & 0xffff0000) >> 16;
|
2013-08-21 20:58:21 +00:00
|
|
|
|
2015-04-27 13:32:52 +02:00
|
|
|
uint32_t receiveTime = feedback_state.last_rr_ntp_secs & 0x0000FFFF;
|
|
|
|
|
receiveTime <<= 16;
|
|
|
|
|
receiveTime += (feedback_state.last_rr_ntp_frac & 0xffff0000) >> 16;
|
2013-08-21 20:58:21 +00:00
|
|
|
|
2016-09-27 09:27:47 -07:00
|
|
|
block->SetDelayLastSr(now - receiveTime);
|
2013-08-21 20:58:21 +00:00
|
|
|
}
|
|
|
|
|
return true;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-11-24 08:25:50 +00:00
|
|
|
void RTCPSender::SetCsrcs(const std::vector<uint32_t>& csrcs) {
|
2016-11-28 15:58:53 -08:00
|
|
|
RTC_DCHECK_LE(csrcs.size(), kRtpCsrcSize);
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2014-11-24 08:25:50 +00:00
|
|
|
csrcs_ = csrcs;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-19 13:49:55 +00:00
|
|
|
int32_t RTCPSender::SetApplicationSpecificData(uint8_t subType,
|
|
|
|
|
uint32_t name,
|
|
|
|
|
const uint8_t* data,
|
|
|
|
|
uint16_t length) {
|
2015-04-27 13:32:52 +02:00
|
|
|
if (length % 4 != 0) {
|
|
|
|
|
LOG(LS_ERROR) << "Failed to SetApplicationSpecificData.";
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2015-05-11 10:17:43 +02:00
|
|
|
|
|
|
|
|
SetFlag(kRtcpApp, true);
|
|
|
|
|
app_sub_type_ = subType;
|
|
|
|
|
app_name_ = name;
|
|
|
|
|
app_data_.reset(new uint8_t[length]);
|
|
|
|
|
app_length_ = length;
|
|
|
|
|
memcpy(app_data_.get(), data, length);
|
2015-04-27 13:32:52 +02:00
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-27 13:32:52 +02:00
|
|
|
int32_t RTCPSender::SetRTCPVoIPMetrics(const RTCPVoIPMetric* VoIPMetric) {
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2016-12-01 05:18:09 -08:00
|
|
|
xr_voip_metric_.emplace(*VoIPMetric);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-12-01 05:18:09 -08:00
|
|
|
SetFlag(kRtcpAnyExtendedReports, true);
|
2015-04-27 13:32:52 +02:00
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-02 13:15:34 +00:00
|
|
|
void RTCPSender::SendRtcpXrReceiverReferenceTime(bool enable) {
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2015-05-11 10:17:43 +02:00
|
|
|
xr_send_receiver_reference_time_enabled_ = enable;
|
2013-10-02 13:15:34 +00:00
|
|
|
}
|
|
|
|
|
|
2013-11-21 08:57:04 +00:00
|
|
|
bool RTCPSender::RtcpXrReceiverReferenceTime() const {
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2015-05-11 10:17:43 +02:00
|
|
|
return xr_send_receiver_reference_time_enabled_;
|
2013-11-21 08:57:04 +00:00
|
|
|
}
|
|
|
|
|
|
2016-08-22 08:26:15 -07:00
|
|
|
void RTCPSender::SetTmmbn(std::vector<rtcp::TmmbItem> bounding_set) {
|
2016-03-22 11:14:09 -07:00
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
2016-08-22 08:26:15 -07:00
|
|
|
tmmbn_to_send_ = std::move(bounding_set);
|
2016-05-09 10:59:50 -07:00
|
|
|
SetFlag(kRtcpTmmbn, true);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2015-04-27 13:32:52 +02:00
|
|
|
|
2016-12-01 05:18:09 -08:00
|
|
|
void RTCPSender::SetFlag(uint32_t type, bool is_volatile) {
|
|
|
|
|
if (type & kRtcpAnyExtendedReports) {
|
|
|
|
|
report_flags_.insert(ReportFlag(kRtcpAnyExtendedReports, is_volatile));
|
|
|
|
|
} else {
|
|
|
|
|
report_flags_.insert(ReportFlag(type, is_volatile));
|
|
|
|
|
}
|
2015-05-11 10:17:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RTCPSender::SetFlags(const std::set<RTCPPacketType>& types,
|
|
|
|
|
bool is_volatile) {
|
|
|
|
|
for (RTCPPacketType type : types)
|
|
|
|
|
SetFlag(type, is_volatile);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-01 05:18:09 -08:00
|
|
|
bool RTCPSender::IsFlagPresent(uint32_t type) const {
|
2015-05-11 10:17:43 +02:00
|
|
|
return report_flags_.find(ReportFlag(type, false)) != report_flags_.end();
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-01 05:18:09 -08:00
|
|
|
bool RTCPSender::ConsumeFlag(uint32_t type, bool forced) {
|
2015-05-11 10:17:43 +02:00
|
|
|
auto it = report_flags_.find(ReportFlag(type, false));
|
|
|
|
|
if (it == report_flags_.end())
|
|
|
|
|
return false;
|
|
|
|
|
if (it->is_volatile || forced)
|
|
|
|
|
report_flags_.erase((it));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RTCPSender::AllVolatileFlagsConsumed() const {
|
|
|
|
|
for (const ReportFlag& flag : report_flags_) {
|
|
|
|
|
if (flag.is_volatile)
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-01 05:18:09 -08:00
|
|
|
void RTCPSender::SetVideoBitrateAllocation(const BitrateAllocation& bitrate) {
|
|
|
|
|
rtc::CritScope lock(&critical_section_rtcp_sender_);
|
|
|
|
|
video_bitrate_allocation_.emplace(bitrate);
|
|
|
|
|
SetFlag(kRtcpAnyExtendedReports, true);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-08 13:25:16 -07:00
|
|
|
bool RTCPSender::SendFeedbackPacket(const rtcp::TransportFeedback& packet) {
|
|
|
|
|
class Sender : public rtcp::RtcpPacket::PacketReadyCallback {
|
|
|
|
|
public:
|
2016-01-21 05:42:04 -08:00
|
|
|
Sender(Transport* transport, RtcEventLog* event_log)
|
|
|
|
|
: transport_(transport), event_log_(event_log), send_failure_(false) {}
|
2015-09-08 13:25:16 -07:00
|
|
|
|
|
|
|
|
void OnPacketReady(uint8_t* data, size_t length) override {
|
2016-01-21 05:42:04 -08:00
|
|
|
if (transport_->SendRtcp(data, length)) {
|
|
|
|
|
if (event_log_) {
|
|
|
|
|
event_log_->LogRtcpPacket(kOutgoingPacket, MediaType::ANY, data,
|
|
|
|
|
length);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2015-09-08 13:25:16 -07:00
|
|
|
send_failure_ = true;
|
2016-01-21 05:42:04 -08:00
|
|
|
}
|
2015-09-08 13:25:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Transport* const transport_;
|
2016-01-21 05:42:04 -08:00
|
|
|
RtcEventLog* const event_log_;
|
2015-09-08 13:25:16 -07:00
|
|
|
bool send_failure_;
|
2016-01-21 05:42:04 -08:00
|
|
|
// TODO(terelius): We would like to
|
|
|
|
|
// RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(Sender);
|
|
|
|
|
// but we can't because of an incorrect warning (C4822) in MVS 2013.
|
|
|
|
|
} sender(transport_, event_log_);
|
2015-09-08 13:25:16 -07:00
|
|
|
|
2016-11-28 15:58:53 -08:00
|
|
|
RTC_DCHECK_LE(max_payload_length_, IP_PACKET_SIZE);
|
2015-09-08 13:25:16 -07:00
|
|
|
uint8_t buffer[IP_PACKET_SIZE];
|
2016-03-30 11:11:51 -07:00
|
|
|
return packet.BuildExternalBuffer(buffer, max_payload_length_, &sender) &&
|
2015-09-08 13:25:16 -07:00
|
|
|
!sender.send_failure_;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-03 15:12:26 +00:00
|
|
|
} // namespace webrtc
|