blob: 3aedeec009585cd77661bb6b2a1150edcdc1a5bc [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
pwestin@webrtc.orgf6bb77a2012-01-24 17:16:59 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/rtp_rtcp/source/rtcp_sender.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000012
Jiawei Ou8b5d9d82018-11-15 16:44:37 -080013#include <string.h> // memcpy
14#include <algorithm> // std::min
niklase@google.com470e71d2011-07-07 08:21:25 +000015
Danil Chapovalov70ffead2016-07-20 15:26:59 +020016#include <utility>
17
Karl Wiberg918f50c2018-07-05 11:40:33 +020018#include "absl/memory/memory.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020019#include "common_types.h" // NOLINT(build/include)
Elad Alon4a87e1c2017-10-03 16:11:34 +020020#include "logging/rtc_event_log/events/rtc_event_rtcp_packet_outgoing.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "logging/rtc_event_log/rtc_event_log.h"
22#include "modules/rtp_rtcp/source/rtcp_packet/app.h"
23#include "modules/rtp_rtcp/source/rtcp_packet/bye.h"
24#include "modules/rtp_rtcp/source/rtcp_packet/compound_packet.h"
25#include "modules/rtp_rtcp/source/rtcp_packet/extended_reports.h"
26#include "modules/rtp_rtcp/source/rtcp_packet/fir.h"
27#include "modules/rtp_rtcp/source/rtcp_packet/nack.h"
28#include "modules/rtp_rtcp/source/rtcp_packet/pli.h"
29#include "modules/rtp_rtcp/source/rtcp_packet/receiver_report.h"
30#include "modules/rtp_rtcp/source/rtcp_packet/remb.h"
31#include "modules/rtp_rtcp/source/rtcp_packet/sdes.h"
32#include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
33#include "modules/rtp_rtcp/source/rtcp_packet/tmmbn.h"
34#include "modules/rtp_rtcp/source/rtcp_packet/tmmbr.h"
35#include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
36#include "modules/rtp_rtcp/source/rtp_rtcp_impl.h"
37#include "modules/rtp_rtcp/source/time_util.h"
38#include "modules/rtp_rtcp/source/tmmbr_help.h"
39#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080040#include "rtc_base/constructor_magic.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020041#include "rtc_base/logging.h"
Jiawei Ou3587b832018-01-31 22:08:26 -080042#include "rtc_base/numerics/safe_conversions.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020043#include "rtc_base/trace_event.h"
pwestin@webrtc.org741da942011-09-20 13:52:04 +000044
niklase@google.com470e71d2011-07-07 08:21:25 +000045namespace webrtc {
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +000046
sprang5e38c962016-12-01 05:18:09 -080047namespace {
Niels Möller44b384d2018-10-05 11:15:57 +020048const uint32_t kRtcpAnyExtendedReports = kRtcpXrReceiverReferenceTime |
49 kRtcpXrDlrrReportBlock |
50 kRtcpXrTargetBitrate;
sprang5e38c962016-12-01 05:18:09 -080051} // namespace
52
pbos@webrtc.org59f20bb2013-09-09 16:02:19 +000053RTCPSender::FeedbackState::FeedbackState()
nisse40ba3ad2017-03-17 07:04:00 -070054 : packets_sent(0),
pbos@webrtc.org2f4b14e2014-07-15 15:25:39 +000055 media_bytes_sent(0),
pbos@webrtc.org59f20bb2013-09-09 16:02:19 +000056 send_bitrate(0),
57 last_rr_ntp_secs(0),
58 last_rr_ntp_frac(0),
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +000059 remote_sr(0),
danilchap162abd32015-12-10 02:39:40 -080060 module(nullptr) {}
pbos@webrtc.org59f20bb2013-09-09 16:02:19 +000061
Mirta Dvornicicb1f063d2018-04-16 11:16:21 +020062RTCPSender::FeedbackState::FeedbackState(const FeedbackState&) = default;
63
64RTCPSender::FeedbackState::FeedbackState(FeedbackState&&) = default;
65
66RTCPSender::FeedbackState::~FeedbackState() = default;
67
Danil Chapovalov5c3cc412017-12-07 10:15:53 +010068class PacketContainer : public rtcp::CompoundPacket {
Erik Språngf7c57762015-12-04 10:40:35 +010069 public:
terelius429c3452016-01-21 05:42:04 -080070 PacketContainer(Transport* transport, RtcEventLog* event_log)
Danil Chapovalov5c3cc412017-12-07 10:15:53 +010071 : transport_(transport), event_log_(event_log) {}
Danil Chapovalov2a5ce2b2018-02-07 09:38:31 +010072 ~PacketContainer() override {
Erik Språngf7c57762015-12-04 10:40:35 +010073 for (RtcpPacket* packet : appended_packets_)
74 delete packet;
75 }
76
danilchap41befce2016-03-30 11:11:51 -070077 size_t SendPackets(size_t max_payload_length) {
Danil Chapovalov5c3cc412017-12-07 10:15:53 +010078 size_t bytes_sent = 0;
79 Build(max_payload_length, [&](rtc::ArrayView<const uint8_t> packet) {
80 if (transport_->SendRtcp(packet.data(), packet.size())) {
81 bytes_sent += packet.size();
82 if (event_log_) {
Karl Wiberg918f50c2018-07-05 11:40:33 +020083 event_log_->Log(
84 absl::make_unique<RtcEventRtcpPacketOutgoing>(packet));
Danil Chapovalov5c3cc412017-12-07 10:15:53 +010085 }
86 }
87 });
88 return bytes_sent;
Erik Språngf7c57762015-12-04 10:40:35 +010089 }
90
91 private:
92 Transport* transport_;
terelius429c3452016-01-21 05:42:04 -080093 RtcEventLog* const event_log_;
terelius429c3452016-01-21 05:42:04 -080094
95 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(PacketContainer);
Erik Språngf7c57762015-12-04 10:40:35 +010096};
97
98class RTCPSender::RtcpContext {
99 public:
Erik Språng242e22b2015-05-11 10:17:43 +0200100 RtcpContext(const FeedbackState& feedback_state,
101 int32_t nack_size,
102 const uint16_t* nack_list,
Ilya Nikolaevskiy88c2c502018-10-26 16:00:08 +0200103 int64_t now_us)
Erik Språngf7c57762015-12-04 10:40:35 +0100104 : feedback_state_(feedback_state),
105 nack_size_(nack_size),
106 nack_list_(nack_list),
Ilya Nikolaevskiy88c2c502018-10-26 16:00:08 +0200107 now_us_(now_us) {}
Erik Språng242e22b2015-05-11 10:17:43 +0200108
Erik Språngf7c57762015-12-04 10:40:35 +0100109 const FeedbackState& feedback_state_;
110 const int32_t nack_size_;
111 const uint16_t* nack_list_;
Ilya Nikolaevskiy88c2c502018-10-26 16:00:08 +0200112 const int64_t now_us_;
Erik Språngbdc0b0d2015-06-22 15:21:24 +0200113};
114
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000115RTCPSender::RTCPSender(
pbos@webrtc.org1d0fa5d2015-02-19 12:47:00 +0000116 bool audio,
117 Clock* clock,
danilchapf5f793c2017-07-27 04:44:18 -0700118 ReceiveStatisticsProvider* receive_statistics,
sprang86fd9ed2015-09-29 04:45:43 -0700119 RtcpPacketTypeCounterObserver* packet_type_counter_observer,
terelius429c3452016-01-21 05:42:04 -0800120 RtcEventLog* event_log,
Jiawei Ou3587b832018-01-31 22:08:26 -0800121 Transport* outgoing_transport,
Jiawei Ou8b5d9d82018-11-15 16:44:37 -0800122 int report_interval_ms)
Peter Boströmac547a62015-09-17 23:03:57 +0200123 : audio_(audio),
Erik Språng242e22b2015-05-11 10:17:43 +0200124 clock_(clock),
danilchap47a740b2015-12-15 00:30:07 -0800125 random_(clock_->TimeInMicroseconds()),
pbosda903ea2015-10-02 02:36:56 -0700126 method_(RtcpMode::kOff),
terelius429c3452016-01-21 05:42:04 -0800127 event_log_(event_log),
sprang86fd9ed2015-09-29 04:45:43 -0700128 transport_(outgoing_transport),
Jiawei Ou8b5d9d82018-11-15 16:44:37 -0800129 report_interval_ms_(report_interval_ms),
Erik Språng242e22b2015-05-11 10:17:43 +0200130 sending_(false),
Erik Språng242e22b2015-05-11 10:17:43 +0200131 next_time_to_send_rtcp_(0),
danilchap71fead22016-08-18 02:01:49 -0700132 timestamp_offset_(0),
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000133 last_rtp_timestamp_(0),
134 last_frame_capture_time_ms_(-1),
Erik Språng242e22b2015-05-11 10:17:43 +0200135 ssrc_(0),
136 remote_ssrc_(0),
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000137 receive_statistics_(receive_statistics),
niklase@google.com470e71d2011-07-07 08:21:25 +0000138
Erik Språng242e22b2015-05-11 10:17:43 +0200139 sequence_number_fir_(0),
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000140
Erik Språng242e22b2015-05-11 10:17:43 +0200141 remb_bitrate_(0),
niklase@google.com470e71d2011-07-07 08:21:25 +0000142
danilchap2b616392016-08-18 06:17:42 -0700143 tmmbr_send_bps_(0),
Erik Språng242e22b2015-05-11 10:17:43 +0200144 packet_oh_send_(0),
nisse284542b2017-01-10 08:58:32 -0800145 max_packet_size_(IP_PACKET_SIZE - 28), // IPv4 + UDP by default.
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000146
Erik Språng242e22b2015-05-11 10:17:43 +0200147 app_sub_type_(0),
Erik Språngbdc0b0d2015-06-22 15:21:24 +0200148 app_name_(0),
Erik Språng242e22b2015-05-11 10:17:43 +0200149 app_data_(nullptr),
150 app_length_(0),
niklase@google.com470e71d2011-07-07 08:21:25 +0000151
Erik Språng242e22b2015-05-11 10:17:43 +0200152 xr_send_receiver_reference_time_enabled_(false),
Erik Språng8782a582018-10-04 15:36:06 +0200153 packet_type_counter_observer_(packet_type_counter_observer),
Ilya Nikolaevskiy5e58bcb2018-10-24 13:34:32 +0200154 send_video_bitrate_allocation_(false),
155 last_payload_type_(-1) {
sprang86fd9ed2015-09-29 04:45:43 -0700156 RTC_DCHECK(transport_ != nullptr);
Erik Språng242e22b2015-05-11 10:17:43 +0200157
158 builders_[kRtcpSr] = &RTCPSender::BuildSR;
159 builders_[kRtcpRr] = &RTCPSender::BuildRR;
Erik Språng0ea42d32015-06-25 14:46:16 +0200160 builders_[kRtcpSdes] = &RTCPSender::BuildSDES;
Erik Språng242e22b2015-05-11 10:17:43 +0200161 builders_[kRtcpPli] = &RTCPSender::BuildPLI;
162 builders_[kRtcpFir] = &RTCPSender::BuildFIR;
Erik Språng242e22b2015-05-11 10:17:43 +0200163 builders_[kRtcpRemb] = &RTCPSender::BuildREMB;
164 builders_[kRtcpBye] = &RTCPSender::BuildBYE;
165 builders_[kRtcpApp] = &RTCPSender::BuildAPP;
166 builders_[kRtcpTmmbr] = &RTCPSender::BuildTMMBR;
167 builders_[kRtcpTmmbn] = &RTCPSender::BuildTMMBN;
168 builders_[kRtcpNack] = &RTCPSender::BuildNACK;
sprang5e38c962016-12-01 05:18:09 -0800169 builders_[kRtcpAnyExtendedReports] = &RTCPSender::BuildExtendedReports;
niklase@google.com470e71d2011-07-07 08:21:25 +0000170}
171
danilchap162abd32015-12-10 02:39:40 -0800172RTCPSender::~RTCPSender() {}
niklase@google.com470e71d2011-07-07 08:21:25 +0000173
pbosda903ea2015-10-02 02:36:56 -0700174RtcpMode RTCPSender::Status() const {
danilchap56036ff2016-03-22 11:14:09 -0700175 rtc::CritScope lock(&critical_section_rtcp_sender_);
Erik Språng242e22b2015-05-11 10:17:43 +0200176 return method_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000177}
178
skvlad1c392cc2016-04-01 14:46:44 -0700179void RTCPSender::SetRTCPStatus(RtcpMode new_method) {
danilchap56036ff2016-03-22 11:14:09 -0700180 rtc::CritScope lock(&critical_section_rtcp_sender_);
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000181
skvlad1c392cc2016-04-01 14:46:44 -0700182 if (method_ == RtcpMode::kOff && new_method != RtcpMode::kOff) {
183 // When switching on, reschedule the next packet
Jiawei Ou8b5d9d82018-11-15 16:44:37 -0800184 next_time_to_send_rtcp_ =
185 clock_->TimeInMilliseconds() + (report_interval_ms_ / 2);
skvlad1c392cc2016-04-01 14:46:44 -0700186 }
187 method_ = new_method;
niklase@google.com470e71d2011-07-07 08:21:25 +0000188}
189
Erik Språng61be2a42015-04-27 13:32:52 +0200190bool RTCPSender::Sending() const {
danilchap56036ff2016-03-22 11:14:09 -0700191 rtc::CritScope lock(&critical_section_rtcp_sender_);
Erik Språng242e22b2015-05-11 10:17:43 +0200192 return sending_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000193}
194
Erik Språng61be2a42015-04-27 13:32:52 +0200195int32_t RTCPSender::SetSendingStatus(const FeedbackState& feedback_state,
196 bool sending) {
197 bool sendRTCPBye = false;
198 {
danilchap56036ff2016-03-22 11:14:09 -0700199 rtc::CritScope lock(&critical_section_rtcp_sender_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000200
pbosda903ea2015-10-02 02:36:56 -0700201 if (method_ != RtcpMode::kOff) {
Erik Språng242e22b2015-05-11 10:17:43 +0200202 if (sending == false && sending_ == true) {
Erik Språng61be2a42015-04-27 13:32:52 +0200203 // Trigger RTCP bye
204 sendRTCPBye = true;
205 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000206 }
Erik Språng242e22b2015-05-11 10:17:43 +0200207 sending_ = sending;
Erik Språng61be2a42015-04-27 13:32:52 +0200208 }
209 if (sendRTCPBye)
210 return SendRTCP(feedback_state, kRtcpBye);
211 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000212}
213
Danil Chapovalov1de4b622017-12-13 13:35:10 +0100214void RTCPSender::SetRemb(int64_t bitrate_bps, std::vector<uint32_t> ssrcs) {
215 RTC_CHECK_GE(bitrate_bps, 0);
danilchap56036ff2016-03-22 11:14:09 -0700216 rtc::CritScope lock(&critical_section_rtcp_sender_);
Danil Chapovalov1de4b622017-12-13 13:35:10 +0100217 remb_bitrate_ = bitrate_bps;
218 remb_ssrcs_ = std::move(ssrcs);
stefan@webrtc.org4ef438e2014-07-11 09:55:30 +0000219
Danil Chapovalovf74d6412017-10-18 13:32:57 +0200220 SetFlag(kRtcpRemb, /*is_volatile=*/false);
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000221 // Send a REMB immediately if we have a new REMB. The frequency of REMBs is
222 // throttled by the caller.
Erik Språng242e22b2015-05-11 10:17:43 +0200223 next_time_to_send_rtcp_ = clock_->TimeInMilliseconds();
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000224}
225
Danil Chapovalovf74d6412017-10-18 13:32:57 +0200226void RTCPSender::UnsetRemb() {
227 rtc::CritScope lock(&critical_section_rtcp_sender_);
228 // Stop sending REMB each report until it is reenabled and REMB data set.
229 ConsumeFlag(kRtcpRemb, /*forced=*/true);
230}
231
Erik Språng61be2a42015-04-27 13:32:52 +0200232bool RTCPSender::TMMBR() const {
danilchap56036ff2016-03-22 11:14:09 -0700233 rtc::CritScope lock(&critical_section_rtcp_sender_);
Erik Språng242e22b2015-05-11 10:17:43 +0200234 return IsFlagPresent(RTCPPacketType::kRtcpTmmbr);
niklase@google.com470e71d2011-07-07 08:21:25 +0000235}
236
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000237void RTCPSender::SetTMMBRStatus(bool enable) {
danilchap56036ff2016-03-22 11:14:09 -0700238 rtc::CritScope lock(&critical_section_rtcp_sender_);
Erik Språng242e22b2015-05-11 10:17:43 +0200239 if (enable) {
240 SetFlag(RTCPPacketType::kRtcpTmmbr, false);
241 } else {
242 ConsumeFlag(RTCPPacketType::kRtcpTmmbr, true);
243 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000244}
245
nisse284542b2017-01-10 08:58:32 -0800246void RTCPSender::SetMaxRtpPacketSize(size_t max_packet_size) {
nisse6f142eb2017-02-21 07:32:47 -0800247 rtc::CritScope lock(&critical_section_rtcp_sender_);
nisse284542b2017-01-10 08:58:32 -0800248 max_packet_size_ = max_packet_size;
danilchap41befce2016-03-30 11:11:51 -0700249}
250
danilchap71fead22016-08-18 02:01:49 -0700251void RTCPSender::SetTimestampOffset(uint32_t timestamp_offset) {
danilchap56036ff2016-03-22 11:14:09 -0700252 rtc::CritScope lock(&critical_section_rtcp_sender_);
danilchap71fead22016-08-18 02:01:49 -0700253 timestamp_offset_ = timestamp_offset;
stefan@webrtc.org7c3523c2012-09-11 07:00:42 +0000254}
255
256void RTCPSender::SetLastRtpTime(uint32_t rtp_timestamp,
Ilya Nikolaevskiy5e58bcb2018-10-24 13:34:32 +0200257 int64_t capture_time_ms,
258 int8_t payload_type) {
danilchap56036ff2016-03-22 11:14:09 -0700259 rtc::CritScope lock(&critical_section_rtcp_sender_);
Ilya Nikolaevskiy5e58bcb2018-10-24 13:34:32 +0200260 // For compatibility with clients who don't set payload type correctly on all
261 // calls.
262 if (payload_type != -1) {
263 last_payload_type_ = payload_type;
264 }
stefan@webrtc.org7c3523c2012-09-11 07:00:42 +0000265 last_rtp_timestamp_ = rtp_timestamp;
266 if (capture_time_ms < 0) {
267 // We don't currently get a capture time from VoiceEngine.
Erik Språng242e22b2015-05-11 10:17:43 +0200268 last_frame_capture_time_ms_ = clock_->TimeInMilliseconds();
stefan@webrtc.org7c3523c2012-09-11 07:00:42 +0000269 } else {
270 last_frame_capture_time_ms_ = capture_time_ms;
271 }
272}
273
Ilya Nikolaevskiy5e58bcb2018-10-24 13:34:32 +0200274void RTCPSender::SetRtpClockRate(int8_t payload_type, int rtp_clock_rate_hz) {
275 rtc::CritScope lock(&critical_section_rtcp_sender_);
276 rtp_clock_rates_khz_[payload_type] = rtp_clock_rate_hz / 1000;
277}
278
nisse14adba72017-03-20 03:52:39 -0700279uint32_t RTCPSender::SSRC() const {
280 rtc::CritScope lock(&critical_section_rtcp_sender_);
281 return ssrc_;
282}
283
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000284void RTCPSender::SetSSRC(uint32_t ssrc) {
danilchap56036ff2016-03-22 11:14:09 -0700285 rtc::CritScope lock(&critical_section_rtcp_sender_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000286
Erik Språng242e22b2015-05-11 10:17:43 +0200287 if (ssrc_ != 0) {
Erik Språng61be2a42015-04-27 13:32:52 +0200288 // not first SetSSRC, probably due to a collision
289 // schedule a new RTCP report
290 // make sure that we send a RTP packet
Erik Språng242e22b2015-05-11 10:17:43 +0200291 next_time_to_send_rtcp_ = clock_->TimeInMilliseconds() + 100;
Erik Språng61be2a42015-04-27 13:32:52 +0200292 }
Erik Språng242e22b2015-05-11 10:17:43 +0200293 ssrc_ = ssrc;
niklase@google.com470e71d2011-07-07 08:21:25 +0000294}
295
Erik Språng61be2a42015-04-27 13:32:52 +0200296void RTCPSender::SetRemoteSSRC(uint32_t ssrc) {
danilchap56036ff2016-03-22 11:14:09 -0700297 rtc::CritScope lock(&critical_section_rtcp_sender_);
Erik Språng242e22b2015-05-11 10:17:43 +0200298 remote_ssrc_ = ssrc;
niklase@google.com470e71d2011-07-07 08:21:25 +0000299}
300
Peter Boström9ba52f82015-06-01 14:12:28 +0200301int32_t RTCPSender::SetCNAME(const char* c_name) {
302 if (!c_name)
tommi@webrtc.orga990e122012-04-26 15:28:22 +0000303 return -1;
304
kwiberg352444f2016-11-28 15:58:53 -0800305 RTC_DCHECK_LT(strlen(c_name), RTCP_CNAME_SIZE);
danilchap56036ff2016-03-22 11:14:09 -0700306 rtc::CritScope lock(&critical_section_rtcp_sender_);
Erik Språng0ea42d32015-06-25 14:46:16 +0200307 cname_ = c_name;
pwestin@webrtc.orgf6bb77a2012-01-24 17:16:59 +0000308 return 0;
309}
310
Erik Språng0ea42d32015-06-25 14:46:16 +0200311int32_t RTCPSender::AddMixedCNAME(uint32_t SSRC, const char* c_name) {
danilchap56036ff2016-03-22 11:14:09 -0700312 RTC_DCHECK(c_name);
kwiberg352444f2016-11-28 15:58:53 -0800313 RTC_DCHECK_LT(strlen(c_name), RTCP_CNAME_SIZE);
danilchap56036ff2016-03-22 11:14:09 -0700314 rtc::CritScope lock(&critical_section_rtcp_sender_);
danilchap74e8df8f2017-03-16 08:04:08 -0700315 // One spot is reserved for ssrc_/cname_.
316 // TODO(danilchap): Add support for more than 30 contributes by sending
317 // several sdes packets.
318 if (csrc_cnames_.size() >= rtcp::Sdes::kMaxNumberOfChunks - 1)
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000319 return -1;
Erik Språng0ea42d32015-06-25 14:46:16 +0200320
321 csrc_cnames_[SSRC] = c_name;
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000322 return 0;
323}
324
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000325int32_t RTCPSender::RemoveMixedCNAME(uint32_t SSRC) {
danilchap56036ff2016-03-22 11:14:09 -0700326 rtc::CritScope lock(&critical_section_rtcp_sender_);
Erik Språng0ea42d32015-06-25 14:46:16 +0200327 auto it = csrc_cnames_.find(SSRC);
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000328
Erik Språng242e22b2015-05-11 10:17:43 +0200329 if (it == csrc_cnames_.end())
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000330 return -1;
Erik Språng61be2a42015-04-27 13:32:52 +0200331
Erik Språng242e22b2015-05-11 10:17:43 +0200332 csrc_cnames_.erase(it);
pwestin@webrtc.org26f8d9c2012-01-19 15:53:09 +0000333 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000334}
335
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000336bool RTCPSender::TimeToSendRTCPReport(bool sendKeyframeBeforeRTP) const {
danilchap162abd32015-12-10 02:39:40 -0800337 /*
Jiawei Ou3587b832018-01-31 22:08:26 -0800338 For audio we use a configurable interval (default: 5 seconds)
niklase@google.com470e71d2011-07-07 08:21:25 +0000339
Jiawei Ou3587b832018-01-31 22:08:26 -0800340 For video we use a configurable interval (default: 1 second) for a BW
341 smaller than 360 kbit/s, technicaly we break the max 5% RTCP BW for
342 video below 10 kbit/s but that should be extremely rare
niklase@google.com470e71d2011-07-07 08:21:25 +0000343
344
danilchap162abd32015-12-10 02:39:40 -0800345 From RFC 3550
niklase@google.com470e71d2011-07-07 08:21:25 +0000346
danilchap162abd32015-12-10 02:39:40 -0800347 MAX RTCP BW is 5% if the session BW
348 A send report is approximately 65 bytes inc CNAME
349 A receiver report is approximately 28 bytes
niklase@google.com470e71d2011-07-07 08:21:25 +0000350
danilchap162abd32015-12-10 02:39:40 -0800351 The RECOMMENDED value for the reduced minimum in seconds is 360
352 divided by the session bandwidth in kilobits/second. This minimum
353 is smaller than 5 seconds for bandwidths greater than 72 kb/s.
niklase@google.com470e71d2011-07-07 08:21:25 +0000354
danilchap162abd32015-12-10 02:39:40 -0800355 If the participant has not yet sent an RTCP packet (the variable
Jiawei Ou3587b832018-01-31 22:08:26 -0800356 initial is true), the constant Tmin is set to half of the configured
357 interval.
niklase@google.com470e71d2011-07-07 08:21:25 +0000358
danilchap162abd32015-12-10 02:39:40 -0800359 The interval between RTCP packets is varied randomly over the
360 range [0.5,1.5] times the calculated interval to avoid unintended
361 synchronization of all participants
niklase@google.com470e71d2011-07-07 08:21:25 +0000362
danilchap162abd32015-12-10 02:39:40 -0800363 if we send
364 If the participant is a sender (we_sent true), the constant C is
365 set to the average RTCP packet size (avg_rtcp_size) divided by 25%
366 of the RTCP bandwidth (rtcp_bw), and the constant n is set to the
367 number of senders.
niklase@google.com470e71d2011-07-07 08:21:25 +0000368
danilchap162abd32015-12-10 02:39:40 -0800369 if we receive only
370 If we_sent is not true, the constant C is set
371 to the average RTCP packet size divided by 75% of the RTCP
372 bandwidth. The constant n is set to the number of receivers
373 (members - senders). If the number of senders is greater than
374 25%, senders and receivers are treated together.
niklase@google.com470e71d2011-07-07 08:21:25 +0000375
danilchap162abd32015-12-10 02:39:40 -0800376 reconsideration NOT required for peer-to-peer
377 "timer reconsideration" is
378 employed. This algorithm implements a simple back-off mechanism
379 which causes users to hold back RTCP packet transmission if the
380 group sizes are increasing.
niklase@google.com470e71d2011-07-07 08:21:25 +0000381
danilchap162abd32015-12-10 02:39:40 -0800382 n = number of members
383 C = avg_size/(rtcpBW/4)
niklase@google.com470e71d2011-07-07 08:21:25 +0000384
danilchap162abd32015-12-10 02:39:40 -0800385 3. The deterministic calculated interval Td is set to max(Tmin, n*C).
niklase@google.com470e71d2011-07-07 08:21:25 +0000386
danilchap162abd32015-12-10 02:39:40 -0800387 4. The calculated interval T is set to a number uniformly distributed
388 between 0.5 and 1.5 times the deterministic calculated interval.
niklase@google.com470e71d2011-07-07 08:21:25 +0000389
danilchap162abd32015-12-10 02:39:40 -0800390 5. The resulting value of T is divided by e-3/2=1.21828 to compensate
391 for the fact that the timer reconsideration algorithm converges to
392 a value of the RTCP bandwidth below the intended average
393 */
niklase@google.com470e71d2011-07-07 08:21:25 +0000394
Erik Språng242e22b2015-05-11 10:17:43 +0200395 int64_t now = clock_->TimeInMilliseconds();
xians@webrtc.org8738d272011-11-25 13:43:53 +0000396
danilchap56036ff2016-03-22 11:14:09 -0700397 rtc::CritScope lock(&critical_section_rtcp_sender_);
xians@webrtc.org8738d272011-11-25 13:43:53 +0000398
pbosda903ea2015-10-02 02:36:56 -0700399 if (method_ == RtcpMode::kOff)
niklase@google.com470e71d2011-07-07 08:21:25 +0000400 return false;
niklase@google.com470e71d2011-07-07 08:21:25 +0000401
Erik Språng242e22b2015-05-11 10:17:43 +0200402 if (!audio_ && sendKeyframeBeforeRTP) {
Erik Språng61be2a42015-04-27 13:32:52 +0200403 // for video key-frames we want to send the RTCP before the large key-frame
404 // if we have a 100 ms margin
405 now += RTCP_SEND_BEFORE_KEY_FRAME_MS;
406 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000407
Erik Språng242e22b2015-05-11 10:17:43 +0200408 if (now >= next_time_to_send_rtcp_) {
Erik Språng61be2a42015-04-27 13:32:52 +0200409 return true;
410 } else if (now < 0x0000ffff &&
Erik Språng242e22b2015-05-11 10:17:43 +0200411 next_time_to_send_rtcp_ > 0xffff0000) { // 65 sec margin
Erik Språng61be2a42015-04-27 13:32:52 +0200412 // wrap
413 return true;
414 }
415 return false;
niklase@google.com470e71d2011-07-07 08:21:25 +0000416}
417
danilchap56036ff2016-03-22 11:14:09 -0700418std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildSR(const RtcpContext& ctx) {
Danil Chapovalov70ffead2016-07-20 15:26:59 +0200419 // Timestamp shouldn't be estimated before first media frame.
420 RTC_DCHECK_GE(last_frame_capture_time_ms_, 0);
Erik Språng61be2a42015-04-27 13:32:52 +0200421 // The timestamp of this RTCP packet should be estimated as the timestamp of
422 // the frame being captured at this moment. We are calculating that
423 // timestamp as the last frame's timestamp + the time since the last frame
424 // was captured.
Ilya Nikolaevskiy5e58bcb2018-10-24 13:34:32 +0200425 int rtp_rate = rtp_clock_rates_khz_[last_payload_type_];
426 if (rtp_rate <= 0) {
427 rtp_rate =
428 (audio_ ? kBogusRtpRateForAudioRtcp : kVideoPayloadTypeFrequency) /
429 1000;
430 }
Ilya Nikolaevskiy88c2c502018-10-26 16:00:08 +0200431 // Round now_us_ to the closest millisecond, because Ntp time is rounded
432 // when converted to milliseconds,
Erik Språngbdc0b0d2015-06-22 15:21:24 +0200433 uint32_t rtp_timestamp =
danilchap71fead22016-08-18 02:01:49 -0700434 timestamp_offset_ + last_rtp_timestamp_ +
Ilya Nikolaevskiy88c2c502018-10-26 16:00:08 +0200435 ((ctx.now_us_ + 500) / 1000 - last_frame_capture_time_ms_) * rtp_rate;
niklase@google.com470e71d2011-07-07 08:21:25 +0000436
Erik Språngf7c57762015-12-04 10:40:35 +0100437 rtcp::SenderReport* report = new rtcp::SenderReport();
danilchap822a16f2016-09-27 09:27:47 -0700438 report->SetSenderSsrc(ssrc_);
Ilya Nikolaevskiy88c2c502018-10-26 16:00:08 +0200439 report->SetNtp(TimeMicrosToNtp(ctx.now_us_));
danilchap822a16f2016-09-27 09:27:47 -0700440 report->SetRtpTimestamp(rtp_timestamp);
441 report->SetPacketCount(ctx.feedback_state_.packets_sent);
442 report->SetOctetCount(ctx.feedback_state_.media_bytes_sent);
danilchap96b69bd2017-07-25 09:15:14 -0700443 report->SetReportBlocks(CreateReportBlocks(ctx.feedback_state_));
Erik Språngf7c57762015-12-04 10:40:35 +0100444
danilchap56036ff2016-03-22 11:14:09 -0700445 return std::unique_ptr<rtcp::RtcpPacket>(report);
niklase@google.com470e71d2011-07-07 08:21:25 +0000446}
447
danilchap56036ff2016-03-22 11:14:09 -0700448std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildSDES(
Erik Språngf7c57762015-12-04 10:40:35 +0100449 const RtcpContext& ctx) {
Erik Språng0ea42d32015-06-25 14:46:16 +0200450 size_t length_cname = cname_.length();
kwiberg352444f2016-11-28 15:58:53 -0800451 RTC_CHECK_LT(length_cname, RTCP_CNAME_SIZE);
niklase@google.com470e71d2011-07-07 08:21:25 +0000452
Erik Språngf7c57762015-12-04 10:40:35 +0100453 rtcp::Sdes* sdes = new rtcp::Sdes();
danilchap822a16f2016-09-27 09:27:47 -0700454 sdes->AddCName(ssrc_, cname_);
Erik Språng0ea42d32015-06-25 14:46:16 +0200455
danilchap74e8df8f2017-03-16 08:04:08 -0700456 for (const auto& it : csrc_cnames_)
457 RTC_CHECK(sdes->AddCName(it.first, it.second));
Erik Språng0ea42d32015-06-25 14:46:16 +0200458
danilchap56036ff2016-03-22 11:14:09 -0700459 return std::unique_ptr<rtcp::RtcpPacket>(sdes);
niklase@google.com470e71d2011-07-07 08:21:25 +0000460}
461
danilchap56036ff2016-03-22 11:14:09 -0700462std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildRR(const RtcpContext& ctx) {
Erik Språngf7c57762015-12-04 10:40:35 +0100463 rtcp::ReceiverReport* report = new rtcp::ReceiverReport();
danilchap822a16f2016-09-27 09:27:47 -0700464 report->SetSenderSsrc(ssrc_);
danilchap96b69bd2017-07-25 09:15:14 -0700465 report->SetReportBlocks(CreateReportBlocks(ctx.feedback_state_));
Erik Språng61be2a42015-04-27 13:32:52 +0200466
danilchap56036ff2016-03-22 11:14:09 -0700467 return std::unique_ptr<rtcp::RtcpPacket>(report);
niklase@google.com470e71d2011-07-07 08:21:25 +0000468}
469
danilchap56036ff2016-03-22 11:14:09 -0700470std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildPLI(const RtcpContext& ctx) {
Erik Språngf7c57762015-12-04 10:40:35 +0100471 rtcp::Pli* pli = new rtcp::Pli();
danilchap822a16f2016-09-27 09:27:47 -0700472 pli->SetSenderSsrc(ssrc_);
473 pli->SetMediaSsrc(remote_ssrc_);
Erik Språng61be2a42015-04-27 13:32:52 +0200474
Erik Språng242e22b2015-05-11 10:17:43 +0200475 ++packet_type_counter_.pli_packets;
Erik Språng242e22b2015-05-11 10:17:43 +0200476
danilchap56036ff2016-03-22 11:14:09 -0700477 return std::unique_ptr<rtcp::RtcpPacket>(pli);
Erik Språng61be2a42015-04-27 13:32:52 +0200478}
479
danilchap56036ff2016-03-22 11:14:09 -0700480std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildFIR(const RtcpContext& ctx) {
danilchap498ee8e2017-02-08 05:24:31 -0800481 ++sequence_number_fir_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000482
Erik Språngf7c57762015-12-04 10:40:35 +0100483 rtcp::Fir* fir = new rtcp::Fir();
danilchap822a16f2016-09-27 09:27:47 -0700484 fir->SetSenderSsrc(ssrc_);
485 fir->AddRequestTo(remote_ssrc_, sequence_number_fir_);
Erik Språng242e22b2015-05-11 10:17:43 +0200486
Erik Språng242e22b2015-05-11 10:17:43 +0200487 ++packet_type_counter_.fir_packets;
Erik Språng242e22b2015-05-11 10:17:43 +0200488
danilchap56036ff2016-03-22 11:14:09 -0700489 return std::unique_ptr<rtcp::RtcpPacket>(fir);
niklase@google.com470e71d2011-07-07 08:21:25 +0000490}
491
danilchap56036ff2016-03-22 11:14:09 -0700492std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildREMB(
Erik Språngf7c57762015-12-04 10:40:35 +0100493 const RtcpContext& ctx) {
494 rtcp::Remb* remb = new rtcp::Remb();
danilchap822a16f2016-09-27 09:27:47 -0700495 remb->SetSenderSsrc(ssrc_);
496 remb->SetBitrateBps(remb_bitrate_);
497 remb->SetSsrcs(remb_ssrcs_);
Erik Språng61be2a42015-04-27 13:32:52 +0200498
danilchap56036ff2016-03-22 11:14:09 -0700499 return std::unique_ptr<rtcp::RtcpPacket>(remb);
pwestin@webrtc.org741da942011-09-20 13:52:04 +0000500}
501
Erik Språng61be2a42015-04-27 13:32:52 +0200502void RTCPSender::SetTargetBitrate(unsigned int target_bitrate) {
danilchap56036ff2016-03-22 11:14:09 -0700503 rtc::CritScope lock(&critical_section_rtcp_sender_);
danilchap2b616392016-08-18 06:17:42 -0700504 tmmbr_send_bps_ = target_bitrate;
mflodman@webrtc.org117c1192012-01-13 08:52:58 +0000505}
506
danilchap56036ff2016-03-22 11:14:09 -0700507std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildTMMBR(
Erik Språngf7c57762015-12-04 10:40:35 +0100508 const RtcpContext& ctx) {
509 if (ctx.feedback_state_.module == nullptr)
510 return nullptr;
Erik Språng61be2a42015-04-27 13:32:52 +0200511 // Before sending the TMMBR check the received TMMBN, only an owner is
512 // allowed to raise the bitrate:
513 // * If the sender is an owner of the TMMBN -> send TMMBR
514 // * If not an owner but the TMMBR would enter the TMMBN -> send TMMBR
niklase@google.com470e71d2011-07-07 08:21:25 +0000515
Erik Språng61be2a42015-04-27 13:32:52 +0200516 // get current bounding set from RTCP receiver
danilchap2b616392016-08-18 06:17:42 -0700517 bool tmmbr_owner = false;
niklase@google.com470e71d2011-07-07 08:21:25 +0000518
Erik Språng242e22b2015-05-11 10:17:43 +0200519 // holding critical_section_rtcp_sender_ while calling RTCPreceiver which
520 // will accuire criticalSectionRTCPReceiver_ is a potental deadlock but
Erik Språng61be2a42015-04-27 13:32:52 +0200521 // since RTCPreceiver is not doing the reverse we should be fine
danilchap2b616392016-08-18 06:17:42 -0700522 std::vector<rtcp::TmmbItem> candidates =
523 ctx.feedback_state_.module->BoundingSet(&tmmbr_owner);
niklase@google.com470e71d2011-07-07 08:21:25 +0000524
danilchap2b616392016-08-18 06:17:42 -0700525 if (!candidates.empty()) {
526 for (const auto& candidate : candidates) {
527 if (candidate.bitrate_bps() == tmmbr_send_bps_ &&
528 candidate.packet_overhead() == packet_oh_send_) {
Erik Språngf7c57762015-12-04 10:40:35 +0100529 // Do not send the same tuple.
530 return nullptr;
Erik Språng61be2a42015-04-27 13:32:52 +0200531 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000532 }
danilchap2b616392016-08-18 06:17:42 -0700533 if (!tmmbr_owner) {
534 // Use received bounding set as candidate set.
535 // Add current tuple.
536 candidates.emplace_back(ssrc_, tmmbr_send_bps_, packet_oh_send_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000537
danilchap2b616392016-08-18 06:17:42 -0700538 // Find bounding set.
danilchap2f69ce92016-08-16 03:21:38 -0700539 std::vector<rtcp::TmmbItem> bounding =
540 TMMBRHelp::FindBoundingSet(std::move(candidates));
danilchap2b616392016-08-18 06:17:42 -0700541 tmmbr_owner = TMMBRHelp::IsOwner(bounding, ssrc_);
542 if (!tmmbr_owner) {
Erik Språngf7c57762015-12-04 10:40:35 +0100543 // Did not enter bounding set, no meaning to send this request.
544 return nullptr;
Erik Språng61be2a42015-04-27 13:32:52 +0200545 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000546 }
Erik Språng61be2a42015-04-27 13:32:52 +0200547 }
niklase@google.com470e71d2011-07-07 08:21:25 +0000548
danilchap2b616392016-08-18 06:17:42 -0700549 if (!tmmbr_send_bps_)
Erik Språngf7c57762015-12-04 10:40:35 +0100550 return nullptr;
sprang81a3e602015-08-21 05:30:11 -0700551
Erik Språngf7c57762015-12-04 10:40:35 +0100552 rtcp::Tmmbr* tmmbr = new rtcp::Tmmbr();
danilchap822a16f2016-09-27 09:27:47 -0700553 tmmbr->SetSenderSsrc(ssrc_);
danilchapf174e3a2016-02-05 04:56:36 -0800554 rtcp::TmmbItem request;
555 request.set_ssrc(remote_ssrc_);
danilchap2b616392016-08-18 06:17:42 -0700556 request.set_bitrate_bps(tmmbr_send_bps_);
danilchapf174e3a2016-02-05 04:56:36 -0800557 request.set_packet_overhead(packet_oh_send_);
danilchap822a16f2016-09-27 09:27:47 -0700558 tmmbr->AddTmmbr(request);
Erik Språngf7c57762015-12-04 10:40:35 +0100559
danilchap56036ff2016-03-22 11:14:09 -0700560 return std::unique_ptr<rtcp::RtcpPacket>(tmmbr);
Erik Språng61be2a42015-04-27 13:32:52 +0200561}
562
danilchap56036ff2016-03-22 11:14:09 -0700563std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildTMMBN(
Erik Språngf7c57762015-12-04 10:40:35 +0100564 const RtcpContext& ctx) {
Erik Språngf7c57762015-12-04 10:40:35 +0100565 rtcp::Tmmbn* tmmbn = new rtcp::Tmmbn();
danilchap822a16f2016-09-27 09:27:47 -0700566 tmmbn->SetSenderSsrc(ssrc_);
danilchap6eaa3a42016-05-09 10:59:50 -0700567 for (const rtcp::TmmbItem& tmmbr : tmmbn_to_send_) {
568 if (tmmbr.bitrate_bps() > 0) {
danilchap822a16f2016-09-27 09:27:47 -0700569 tmmbn->AddTmmbr(tmmbr);
asapersson@webrtc.org2dd31342014-10-29 12:42:30 +0000570 }
Erik Språng61be2a42015-04-27 13:32:52 +0200571 }
sprangd83df502015-08-27 01:05:08 -0700572
danilchap56036ff2016-03-22 11:14:09 -0700573 return std::unique_ptr<rtcp::RtcpPacket>(tmmbn);
niklase@google.com470e71d2011-07-07 08:21:25 +0000574}
575
danilchap56036ff2016-03-22 11:14:09 -0700576std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildAPP(const RtcpContext& ctx) {
Erik Språngf7c57762015-12-04 10:40:35 +0100577 rtcp::App* app = new rtcp::App();
danilchap822a16f2016-09-27 09:27:47 -0700578 app->SetSsrc(ssrc_);
579 app->SetSubType(app_sub_type_);
580 app->SetName(app_name_);
581 app->SetData(app_data_.get(), app_length_);
Erik Språng521875a2015-09-01 10:11:16 +0200582
danilchap56036ff2016-03-22 11:14:09 -0700583 return std::unique_ptr<rtcp::RtcpPacket>(app);
Erik Språng61be2a42015-04-27 13:32:52 +0200584}
585
danilchap56036ff2016-03-22 11:14:09 -0700586std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildNACK(
Erik Språngf7c57762015-12-04 10:40:35 +0100587 const RtcpContext& ctx) {
588 rtcp::Nack* nack = new rtcp::Nack();
danilchap822a16f2016-09-27 09:27:47 -0700589 nack->SetSenderSsrc(ssrc_);
590 nack->SetMediaSsrc(remote_ssrc_);
591 nack->SetPacketIds(ctx.nack_list_, ctx.nack_size_);
Erik Språng61be2a42015-04-27 13:32:52 +0200592
593 // Report stats.
Erik Språngf7c57762015-12-04 10:40:35 +0100594 for (int idx = 0; idx < ctx.nack_size_; ++idx) {
Erik Språngf7c57762015-12-04 10:40:35 +0100595 nack_stats_.ReportRequest(ctx.nack_list_[idx]);
Erik Språng61be2a42015-04-27 13:32:52 +0200596 }
Erik Språng61be2a42015-04-27 13:32:52 +0200597 packet_type_counter_.nack_requests = nack_stats_.requests();
598 packet_type_counter_.unique_nack_requests = nack_stats_.unique_requests();
Erik Språng242e22b2015-05-11 10:17:43 +0200599
Erik Språng242e22b2015-05-11 10:17:43 +0200600 ++packet_type_counter_.nack_packets;
Erik Språng242e22b2015-05-11 10:17:43 +0200601
danilchap56036ff2016-03-22 11:14:09 -0700602 return std::unique_ptr<rtcp::RtcpPacket>(nack);
Erik Språng61be2a42015-04-27 13:32:52 +0200603}
604
danilchap56036ff2016-03-22 11:14:09 -0700605std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildBYE(const RtcpContext& ctx) {
Erik Språngf7c57762015-12-04 10:40:35 +0100606 rtcp::Bye* bye = new rtcp::Bye();
danilchap822a16f2016-09-27 09:27:47 -0700607 bye->SetSenderSsrc(ssrc_);
608 bye->SetCsrcs(csrcs_);
sprangd8ee4f92015-08-24 03:25:19 -0700609
danilchap56036ff2016-03-22 11:14:09 -0700610 return std::unique_ptr<rtcp::RtcpPacket>(bye);
niklase@google.com470e71d2011-07-07 08:21:25 +0000611}
612
sprang5e38c962016-12-01 05:18:09 -0800613std::unique_ptr<rtcp::RtcpPacket> RTCPSender::BuildExtendedReports(
Erik Språngf7c57762015-12-04 10:40:35 +0100614 const RtcpContext& ctx) {
sprang5e38c962016-12-01 05:18:09 -0800615 std::unique_ptr<rtcp::ExtendedReports> xr(new rtcp::ExtendedReports());
danilchap822a16f2016-09-27 09:27:47 -0700616 xr->SetSenderSsrc(ssrc_);
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000617
sprang5e38c962016-12-01 05:18:09 -0800618 if (!sending_ && xr_send_receiver_reference_time_enabled_) {
619 rtcp::Rrtr rrtr;
Ilya Nikolaevskiy88c2c502018-10-26 16:00:08 +0200620 rrtr.SetNtp(TimeMicrosToNtp(ctx.now_us_));
sprang5e38c962016-12-01 05:18:09 -0800621 xr->SetRrtr(rrtr);
622 }
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000623
Mirta Dvornicicb1f063d2018-04-16 11:16:21 +0200624 for (const rtcp::ReceiveTimeInfo& rti : ctx.feedback_state_.last_xr_rtis) {
625 xr->AddDlrrItem(rti);
sprang5e38c962016-12-01 05:18:09 -0800626 }
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000627
Erik Språng8782a582018-10-04 15:36:06 +0200628 if (send_video_bitrate_allocation_) {
sprang5e38c962016-12-01 05:18:09 -0800629 rtcp::TargetBitrate target_bitrate;
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000630
sprang5e38c962016-12-01 05:18:09 -0800631 for (int sl = 0; sl < kMaxSpatialLayers; ++sl) {
632 for (int tl = 0; tl < kMaxTemporalStreams; ++tl) {
Erik Språng8782a582018-10-04 15:36:06 +0200633 if (video_bitrate_allocation_.HasBitrate(sl, tl)) {
erikvarga@webrtc.org01f2ec32017-11-15 14:58:23 +0100634 target_bitrate.AddTargetBitrate(
Erik Språng8782a582018-10-04 15:36:06 +0200635 sl, tl, video_bitrate_allocation_.GetBitrate(sl, tl) / 1000);
erikvarga@webrtc.org01f2ec32017-11-15 14:58:23 +0100636 }
sprang5e38c962016-12-01 05:18:09 -0800637 }
638 }
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000639
sprang5e38c962016-12-01 05:18:09 -0800640 xr->SetTargetBitrate(target_bitrate);
Erik Språng8782a582018-10-04 15:36:06 +0200641 send_video_bitrate_allocation_ = false;
sprang5e38c962016-12-01 05:18:09 -0800642 }
Erik Språngca28fdc2015-08-31 14:00:50 +0200643
sprang5e38c962016-12-01 05:18:09 -0800644 return std::move(xr);
niklase@google.com470e71d2011-07-07 08:21:25 +0000645}
646
pbos@webrtc.org59f20bb2013-09-09 16:02:19 +0000647int32_t RTCPSender::SendRTCP(const FeedbackState& feedback_state,
Erik Språng242e22b2015-05-11 10:17:43 +0200648 RTCPPacketType packetType,
649 int32_t nack_size,
nissecd386eb2017-03-14 08:54:43 -0700650 const uint16_t* nack_list) {
Erik Språng242e22b2015-05-11 10:17:43 +0200651 return SendCompoundRTCP(
652 feedback_state, std::set<RTCPPacketType>(&packetType, &packetType + 1),
nissecd386eb2017-03-14 08:54:43 -0700653 nack_size, nack_list);
Erik Språng242e22b2015-05-11 10:17:43 +0200654}
655
656int32_t RTCPSender::SendCompoundRTCP(
657 const FeedbackState& feedback_state,
Erik Språngf7c57762015-12-04 10:40:35 +0100658 const std::set<RTCPPacketType>& packet_types,
Erik Språng242e22b2015-05-11 10:17:43 +0200659 int32_t nack_size,
nissecd386eb2017-03-14 08:54:43 -0700660 const uint16_t* nack_list) {
terelius429c3452016-01-21 05:42:04 -0800661 PacketContainer container(transport_, event_log_);
nisse6f142eb2017-02-21 07:32:47 -0800662 size_t max_packet_size;
663
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000664 {
danilchap56036ff2016-03-22 11:14:09 -0700665 rtc::CritScope lock(&critical_section_rtcp_sender_);
pbosda903ea2015-10-02 02:36:56 -0700666 if (method_ == RtcpMode::kOff) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100667 RTC_LOG(LS_WARNING) << "Can't send rtcp if it is disabled.";
Erik Språng61be2a42015-04-27 13:32:52 +0200668 return -1;
pwestin@webrtc.org8edb39d2011-12-22 07:40:33 +0000669 }
Danil Chapovalov70ffead2016-07-20 15:26:59 +0200670 // Add all flags as volatile. Non volatile entries will not be overwritten.
671 // All new volatile flags added will be consumed by the end of this call.
672 SetFlags(packet_types, true);
673
674 // Prevent sending streams to send SR before any media has been sent.
675 const bool can_calculate_rtp_timestamp = (last_frame_capture_time_ms_ >= 0);
676 if (!can_calculate_rtp_timestamp) {
677 bool consumed_sr_flag = ConsumeFlag(kRtcpSr);
678 bool consumed_report_flag = sending_ && ConsumeFlag(kRtcpReport);
679 bool sender_report = consumed_report_flag || consumed_sr_flag;
680 if (sender_report && AllVolatileFlagsConsumed()) {
681 // This call was for Sender Report and nothing else.
682 return 0;
683 }
684 if (sending_ && method_ == RtcpMode::kCompound) {
685 // Not allowed to send any RTCP packet without sender report.
686 return -1;
687 }
688 }
689
690 if (packet_type_counter_.first_packet_time_ms == -1)
691 packet_type_counter_.first_packet_time_ms = clock_->TimeInMilliseconds();
Erik Språngf7c57762015-12-04 10:40:35 +0100692
693 // We need to send our NTP even if we haven't received any reports.
nissecd386eb2017-03-14 08:54:43 -0700694 RtcpContext context(feedback_state, nack_size, nack_list,
Ilya Nikolaevskiy88c2c502018-10-26 16:00:08 +0200695 clock_->TimeInMicroseconds());
Erik Språngf7c57762015-12-04 10:40:35 +0100696
Danil Chapovalov70ffead2016-07-20 15:26:59 +0200697 PrepareReport(feedback_state);
Erik Språngf7c57762015-12-04 10:40:35 +0100698
danilchap56036ff2016-03-22 11:14:09 -0700699 std::unique_ptr<rtcp::RtcpPacket> packet_bye;
aleungbroadsoft0e2e50c2016-02-18 08:33:26 -0800700
Erik Språngf7c57762015-12-04 10:40:35 +0100701 auto it = report_flags_.begin();
702 while (it != report_flags_.end()) {
703 auto builder_it = builders_.find(it->type);
sprang5e38c962016-12-01 05:18:09 -0800704 RTC_DCHECK(builder_it != builders_.end())
705 << "Could not find builder for packet type " << it->type;
Erik Språngf7c57762015-12-04 10:40:35 +0100706 if (it->is_volatile) {
707 report_flags_.erase(it++);
708 } else {
709 ++it;
710 }
711
712 BuilderFunc func = builder_it->second;
danilchap56036ff2016-03-22 11:14:09 -0700713 std::unique_ptr<rtcp::RtcpPacket> packet = (this->*func)(context);
Erik Språngf7c57762015-12-04 10:40:35 +0100714 if (packet.get() == nullptr)
715 return -1;
aleungbroadsoft0e2e50c2016-02-18 08:33:26 -0800716 // If there is a BYE, don't append now - save it and append it
717 // at the end later.
718 if (builder_it->first == kRtcpBye) {
719 packet_bye = std::move(packet);
720 } else {
721 container.Append(packet.release());
722 }
723 }
724
725 // Append the BYE now at the end
726 if (packet_bye) {
727 container.Append(packet_bye.release());
Erik Språngf7c57762015-12-04 10:40:35 +0100728 }
729
730 if (packet_type_counter_observer_ != nullptr) {
731 packet_type_counter_observer_->RtcpPacketTypesCounterUpdated(
732 remote_ssrc_, packet_type_counter_);
733 }
734
735 RTC_DCHECK(AllVolatileFlagsConsumed());
nisse6f142eb2017-02-21 07:32:47 -0800736 max_packet_size = max_packet_size_;
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000737 }
Erik Språng61be2a42015-04-27 13:32:52 +0200738
nisse6f142eb2017-02-21 07:32:47 -0800739 size_t bytes_sent = container.SendPackets(max_packet_size);
Erik Språngf7c57762015-12-04 10:40:35 +0100740 return bytes_sent == 0 ? -1 : 0;
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000741}
742
Danil Chapovalov70ffead2016-07-20 15:26:59 +0200743void RTCPSender::PrepareReport(const FeedbackState& feedback_state) {
Erik Språng242e22b2015-05-11 10:17:43 +0200744 bool generate_report;
745 if (IsFlagPresent(kRtcpSr) || IsFlagPresent(kRtcpRr)) {
746 // Report type already explicitly set, don't automatically populate.
747 generate_report = true;
henrikg91d6ede2015-09-17 00:24:34 -0700748 RTC_DCHECK(ConsumeFlag(kRtcpReport) == false);
Erik Språng242e22b2015-05-11 10:17:43 +0200749 } else {
750 generate_report =
pbosda903ea2015-10-02 02:36:56 -0700751 (ConsumeFlag(kRtcpReport) && method_ == RtcpMode::kReducedSize) ||
752 method_ == RtcpMode::kCompound;
Erik Språng242e22b2015-05-11 10:17:43 +0200753 if (generate_report)
754 SetFlag(sending_ ? kRtcpSr : kRtcpRr, true);
asapersson@webrtc.orgd08d3892014-12-16 12:03:11 +0000755 }
756
Erik Språng0ea42d32015-06-25 14:46:16 +0200757 if (IsFlagPresent(kRtcpSr) || (IsFlagPresent(kRtcpRr) && !cname_.empty()))
Erik Språng242e22b2015-05-11 10:17:43 +0200758 SetFlag(kRtcpSdes, true);
759
Erik Språng242e22b2015-05-11 10:17:43 +0200760 if (generate_report) {
sprang5e38c962016-12-01 05:18:09 -0800761 if ((!sending_ && xr_send_receiver_reference_time_enabled_) ||
Erik Språng8782a582018-10-04 15:36:06 +0200762 !feedback_state.last_xr_rtis.empty() ||
763 send_video_bitrate_allocation_) {
sprang5e38c962016-12-01 05:18:09 -0800764 SetFlag(kRtcpAnyExtendedReports, true);
765 }
Erik Språng242e22b2015-05-11 10:17:43 +0200766
767 // generate next time to send an RTCP report
Jiawei Ou8b5d9d82018-11-15 16:44:37 -0800768 int min_interval_ms = report_interval_ms_;
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000769
Jiawei Ou8b5d9d82018-11-15 16:44:37 -0800770 if (!audio_ && sending_) {
771 // Calculate bandwidth for video; 360 / send bandwidth in kbit/s.
772 int send_bitrate_kbit = feedback_state.send_bitrate / 1000;
773 if (send_bitrate_kbit != 0) {
774 min_interval_ms = 360000 / send_bitrate_kbit;
775 min_interval_ms = std::min(min_interval_ms, report_interval_ms_);
Jiawei Ou3587b832018-01-31 22:08:26 -0800776 }
Erik Språng61be2a42015-04-27 13:32:52 +0200777 }
Jiawei Ou3587b832018-01-31 22:08:26 -0800778
danilchap47a740b2015-12-15 00:30:07 -0800779 // The interval between RTCP packets is varied randomly over the
780 // range [1/2,3/2] times the calculated interval.
Jiawei Ou8b5d9d82018-11-15 16:44:37 -0800781 int time_to_next =
782 random_.Rand(min_interval_ms * 1 / 2, min_interval_ms * 3 / 2);
783
784 RTC_DCHECK_GT(time_to_next, 0);
785 next_time_to_send_rtcp_ = clock_->TimeInMilliseconds() + time_to_next;
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000786
danilchap96b69bd2017-07-25 09:15:14 -0700787 // RtcpSender expected to be used for sending either just sender reports
788 // or just receiver reports.
789 RTC_DCHECK(!(IsFlagPresent(kRtcpSr) && IsFlagPresent(kRtcpRr)));
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000790 }
stefan@webrtc.org286fe0b2013-08-21 20:58:21 +0000791}
792
danilchap96b69bd2017-07-25 09:15:14 -0700793std::vector<rtcp::ReportBlock> RTCPSender::CreateReportBlocks(
794 const FeedbackState& feedback_state) {
795 std::vector<rtcp::ReportBlock> result;
796 if (!receive_statistics_)
797 return result;
danilchapa72e7342015-12-22 08:07:45 -0800798
danilchapf5f793c2017-07-27 04:44:18 -0700799 // TODO(danilchap): Support sending more than |RTCP_MAX_REPORT_BLOCKS| per
800 // compound rtcp packet when single rtcp module is used for multiple media
801 // streams.
802 result = receive_statistics_->RtcpReportBlocks(RTCP_MAX_REPORT_BLOCKS);
danilchap96b69bd2017-07-25 09:15:14 -0700803
804 if (!result.empty() && ((feedback_state.last_rr_ntp_secs != 0) ||
805 (feedback_state.last_rr_ntp_frac != 0))) {
806 // Get our NTP as late as possible to avoid a race.
Ilya Nikolaevskiy88c2c502018-10-26 16:00:08 +0200807 uint32_t now = CompactNtp(TimeMicrosToNtp(clock_->TimeInMicroseconds()));
danilchap96b69bd2017-07-25 09:15:14 -0700808
809 uint32_t receive_time = feedback_state.last_rr_ntp_secs & 0x0000FFFF;
810 receive_time <<= 16;
811 receive_time += (feedback_state.last_rr_ntp_frac & 0xffff0000) >> 16;
812
813 uint32_t delay_since_last_sr = now - receive_time;
814 // TODO(danilchap): Instead of setting same value on all report blocks,
815 // set only when media_ssrc match sender ssrc of the sender report
816 // remote times were taken from.
817 for (auto& report_block : result) {
818 report_block.SetLastSr(feedback_state.remote_sr);
819 report_block.SetDelayLastSr(delay_since_last_sr);
820 }
danilchapa72e7342015-12-22 08:07:45 -0800821 }
danilchap96b69bd2017-07-25 09:15:14 -0700822 return result;
niklase@google.com470e71d2011-07-07 08:21:25 +0000823}
824
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000825void RTCPSender::SetCsrcs(const std::vector<uint32_t>& csrcs) {
kwiberg352444f2016-11-28 15:58:53 -0800826 RTC_DCHECK_LE(csrcs.size(), kRtpCsrcSize);
danilchap56036ff2016-03-22 11:14:09 -0700827 rtc::CritScope lock(&critical_section_rtcp_sender_);
pbos@webrtc.org9334ac22014-11-24 08:25:50 +0000828 csrcs_ = csrcs;
niklase@google.com470e71d2011-07-07 08:21:25 +0000829}
830
pbos@webrtc.orgd16e8392014-12-19 13:49:55 +0000831int32_t RTCPSender::SetApplicationSpecificData(uint8_t subType,
832 uint32_t name,
833 const uint8_t* data,
834 uint16_t length) {
Erik Språng61be2a42015-04-27 13:32:52 +0200835 if (length % 4 != 0) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100836 RTC_LOG(LS_ERROR) << "Failed to SetApplicationSpecificData.";
Erik Språng61be2a42015-04-27 13:32:52 +0200837 return -1;
838 }
danilchap56036ff2016-03-22 11:14:09 -0700839 rtc::CritScope lock(&critical_section_rtcp_sender_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000840
Erik Språng242e22b2015-05-11 10:17:43 +0200841 SetFlag(kRtcpApp, true);
842 app_sub_type_ = subType;
843 app_name_ = name;
844 app_data_.reset(new uint8_t[length]);
845 app_length_ = length;
846 memcpy(app_data_.get(), data, length);
Erik Språng61be2a42015-04-27 13:32:52 +0200847 return 0;
niklase@google.com470e71d2011-07-07 08:21:25 +0000848}
849
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000850void RTCPSender::SendRtcpXrReceiverReferenceTime(bool enable) {
danilchap56036ff2016-03-22 11:14:09 -0700851 rtc::CritScope lock(&critical_section_rtcp_sender_);
Erik Språng242e22b2015-05-11 10:17:43 +0200852 xr_send_receiver_reference_time_enabled_ = enable;
asapersson@webrtc.org8469f7b2013-10-02 13:15:34 +0000853}
854
asapersson@webrtc.org8d02f5d2013-11-21 08:57:04 +0000855bool RTCPSender::RtcpXrReceiverReferenceTime() const {
danilchap56036ff2016-03-22 11:14:09 -0700856 rtc::CritScope lock(&critical_section_rtcp_sender_);
Erik Språng242e22b2015-05-11 10:17:43 +0200857 return xr_send_receiver_reference_time_enabled_;
asapersson@webrtc.org8d02f5d2013-11-21 08:57:04 +0000858}
859
danilchap853ecb22016-08-22 08:26:15 -0700860void RTCPSender::SetTmmbn(std::vector<rtcp::TmmbItem> bounding_set) {
danilchap56036ff2016-03-22 11:14:09 -0700861 rtc::CritScope lock(&critical_section_rtcp_sender_);
danilchap853ecb22016-08-22 08:26:15 -0700862 tmmbn_to_send_ = std::move(bounding_set);
danilchap6eaa3a42016-05-09 10:59:50 -0700863 SetFlag(kRtcpTmmbn, true);
niklase@google.com470e71d2011-07-07 08:21:25 +0000864}
Erik Språng61be2a42015-04-27 13:32:52 +0200865
sprang5e38c962016-12-01 05:18:09 -0800866void RTCPSender::SetFlag(uint32_t type, bool is_volatile) {
867 if (type & kRtcpAnyExtendedReports) {
868 report_flags_.insert(ReportFlag(kRtcpAnyExtendedReports, is_volatile));
869 } else {
870 report_flags_.insert(ReportFlag(type, is_volatile));
871 }
Erik Språng242e22b2015-05-11 10:17:43 +0200872}
873
874void RTCPSender::SetFlags(const std::set<RTCPPacketType>& types,
875 bool is_volatile) {
876 for (RTCPPacketType type : types)
877 SetFlag(type, is_volatile);
878}
879
sprang5e38c962016-12-01 05:18:09 -0800880bool RTCPSender::IsFlagPresent(uint32_t type) const {
Erik Språng242e22b2015-05-11 10:17:43 +0200881 return report_flags_.find(ReportFlag(type, false)) != report_flags_.end();
882}
883
sprang5e38c962016-12-01 05:18:09 -0800884bool RTCPSender::ConsumeFlag(uint32_t type, bool forced) {
Erik Språng242e22b2015-05-11 10:17:43 +0200885 auto it = report_flags_.find(ReportFlag(type, false));
886 if (it == report_flags_.end())
887 return false;
888 if (it->is_volatile || forced)
889 report_flags_.erase((it));
890 return true;
891}
892
893bool RTCPSender::AllVolatileFlagsConsumed() const {
894 for (const ReportFlag& flag : report_flags_) {
895 if (flag.is_volatile)
896 return false;
897 }
898 return true;
899}
900
Erik Språng566124a2018-04-23 12:32:22 +0200901void RTCPSender::SetVideoBitrateAllocation(
902 const VideoBitrateAllocation& bitrate) {
sprang5e38c962016-12-01 05:18:09 -0800903 rtc::CritScope lock(&critical_section_rtcp_sender_);
Erik Språng8782a582018-10-04 15:36:06 +0200904 // Check if this allocation is first ever, or has a different set of
905 // spatial/temporal layers signaled and enabled, if so trigger an rtcp report
906 // as soon as possible.
Erik Språng1cd73912018-10-05 12:57:59 +0200907 absl::optional<VideoBitrateAllocation> new_bitrate =
908 CheckAndUpdateLayerStructure(bitrate);
909 if (new_bitrate) {
910 video_bitrate_allocation_ = *new_bitrate;
Erik Språng8782a582018-10-04 15:36:06 +0200911 next_time_to_send_rtcp_ = clock_->TimeInMilliseconds();
Erik Språng1cd73912018-10-05 12:57:59 +0200912 } else {
913 video_bitrate_allocation_ = bitrate;
Erik Språng8782a582018-10-04 15:36:06 +0200914 }
915
Erik Språng8782a582018-10-04 15:36:06 +0200916 send_video_bitrate_allocation_ = true;
sprang5e38c962016-12-01 05:18:09 -0800917 SetFlag(kRtcpAnyExtendedReports, true);
918}
919
Erik Språng1cd73912018-10-05 12:57:59 +0200920absl::optional<VideoBitrateAllocation> RTCPSender::CheckAndUpdateLayerStructure(
Erik Språng8782a582018-10-04 15:36:06 +0200921 const VideoBitrateAllocation& bitrate) const {
Erik Språng1cd73912018-10-05 12:57:59 +0200922 absl::optional<VideoBitrateAllocation> updated_bitrate;
Erik Språng8782a582018-10-04 15:36:06 +0200923 for (size_t si = 0; si < kMaxSpatialLayers; ++si) {
924 for (size_t ti = 0; ti < kMaxTemporalStreams; ++ti) {
Erik Språng1cd73912018-10-05 12:57:59 +0200925 if (!updated_bitrate &&
926 (bitrate.HasBitrate(si, ti) !=
927 video_bitrate_allocation_.HasBitrate(si, ti) ||
928 (bitrate.GetBitrate(si, ti) == 0) !=
929 (video_bitrate_allocation_.GetBitrate(si, ti) == 0))) {
930 updated_bitrate = bitrate;
931 }
932 if (video_bitrate_allocation_.GetBitrate(si, ti) > 0 &&
933 bitrate.GetBitrate(si, ti) == 0) {
934 // Make sure this stream disabling is explicitly signaled.
935 updated_bitrate->SetBitrate(si, ti, 0);
Erik Språng8782a582018-10-04 15:36:06 +0200936 }
937 }
938 }
939
Erik Språng1cd73912018-10-05 12:57:59 +0200940 return updated_bitrate;
Erik Språng8782a582018-10-04 15:36:06 +0200941}
942
sprang233bd872015-09-08 13:25:16 -0700943bool RTCPSender::SendFeedbackPacket(const rtcp::TransportFeedback& packet) {
nisse6f142eb2017-02-21 07:32:47 -0800944 size_t max_packet_size;
stefanb77c7162017-02-06 06:29:38 -0800945 {
946 rtc::CritScope lock(&critical_section_rtcp_sender_);
947 if (method_ == RtcpMode::kOff)
948 return false;
nisse6f142eb2017-02-21 07:32:47 -0800949 max_packet_size = max_packet_size_;
stefanb77c7162017-02-06 06:29:38 -0800950 }
951
nisse6f142eb2017-02-21 07:32:47 -0800952 RTC_DCHECK_LE(max_packet_size, IP_PACKET_SIZE);
Danil Chapovalov5c3cc412017-12-07 10:15:53 +0100953 bool send_failure = false;
954 auto callback = [&](rtc::ArrayView<const uint8_t> packet) {
955 if (transport_->SendRtcp(packet.data(), packet.size())) {
956 if (event_log_)
Karl Wiberg918f50c2018-07-05 11:40:33 +0200957 event_log_->Log(absl::make_unique<RtcEventRtcpPacketOutgoing>(packet));
Danil Chapovalov5c3cc412017-12-07 10:15:53 +0100958 } else {
959 send_failure = true;
960 }
961 };
962 return packet.Build(max_packet_size, callback) && !send_failure;
sprang233bd872015-09-08 13:25:16 -0700963}
964
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +0000965} // namespace webrtc