aboutsummaryrefslogtreecommitdiff
path: root/modules/rtp_rtcp/source/rtcp_receiver.cc
diff options
context:
space:
mode:
Diffstat (limited to 'modules/rtp_rtcp/source/rtcp_receiver.cc')
-rw-r--r--modules/rtp_rtcp/source/rtcp_receiver.cc193
1 files changed, 105 insertions, 88 deletions
diff --git a/modules/rtp_rtcp/source/rtcp_receiver.cc b/modules/rtp_rtcp/source/rtcp_receiver.cc
index ae0e9e5934..79f24c4779 100644
--- a/modules/rtp_rtcp/source/rtcp_receiver.cc
+++ b/modules/rtp_rtcp/source/rtcp_receiver.cc
@@ -39,6 +39,7 @@
#include "modules/rtp_rtcp/source/rtcp_packet/tmmbr.h"
#include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
#include "modules/rtp_rtcp/source/rtp_rtcp_config.h"
+#include "modules/rtp_rtcp/source/rtp_rtcp_impl2.h"
#include "modules/rtp_rtcp/source/time_util.h"
#include "modules/rtp_rtcp/source/tmmbr_help.h"
#include "rtc_base/checks.h"
@@ -67,22 +68,6 @@ const size_t kMaxNumberOfStoredRrtrs = 300;
constexpr TimeDelta kDefaultVideoReportInterval = TimeDelta::Seconds(1);
constexpr TimeDelta kDefaultAudioReportInterval = TimeDelta::Seconds(5);
-std::set<uint32_t> GetRegisteredSsrcs(
- const RtpRtcpInterface::Configuration& config) {
- std::set<uint32_t> ssrcs;
- ssrcs.insert(config.local_media_ssrc);
- if (config.rtx_send_ssrc) {
- ssrcs.insert(*config.rtx_send_ssrc);
- }
- if (config.fec_generator) {
- absl::optional<uint32_t> flexfec_ssrc = config.fec_generator->FecSsrc();
- if (flexfec_ssrc) {
- ssrcs.insert(*flexfec_ssrc);
- }
- }
- return ssrcs;
-}
-
// Returns true if the |timestamp| has exceeded the |interval *
// kRrTimeoutIntervals| period and was reset (set to PlusInfinity()). Returns
// false if the timer was either already reset or if it has not expired.
@@ -100,6 +85,43 @@ bool ResetTimestampIfExpired(const Timestamp now,
} // namespace
+constexpr size_t RTCPReceiver::RegisteredSsrcs::kMediaSsrcIndex;
+constexpr size_t RTCPReceiver::RegisteredSsrcs::kMaxSsrcs;
+
+RTCPReceiver::RegisteredSsrcs::RegisteredSsrcs(
+ bool disable_sequence_checker,
+ const RtpRtcpInterface::Configuration& config)
+ : packet_sequence_checker_(disable_sequence_checker) {
+ packet_sequence_checker_.Detach();
+ ssrcs_.push_back(config.local_media_ssrc);
+ if (config.rtx_send_ssrc) {
+ ssrcs_.push_back(*config.rtx_send_ssrc);
+ }
+ if (config.fec_generator) {
+ absl::optional<uint32_t> flexfec_ssrc = config.fec_generator->FecSsrc();
+ if (flexfec_ssrc) {
+ ssrcs_.push_back(*flexfec_ssrc);
+ }
+ }
+ // Ensure that the RegisteredSsrcs can inline the SSRCs.
+ RTC_DCHECK_LE(ssrcs_.size(), RTCPReceiver::RegisteredSsrcs::kMaxSsrcs);
+}
+
+bool RTCPReceiver::RegisteredSsrcs::contains(uint32_t ssrc) const {
+ RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
+ return absl::c_linear_search(ssrcs_, ssrc);
+}
+
+uint32_t RTCPReceiver::RegisteredSsrcs::media_ssrc() const {
+ RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
+ return ssrcs_[kMediaSsrcIndex];
+}
+
+void RTCPReceiver::RegisteredSsrcs::set_media_ssrc(uint32_t ssrc) {
+ RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
+ ssrcs_[kMediaSsrcIndex] = ssrc;
+}
+
struct RTCPReceiver::PacketInformation {
uint32_t packet_type_flags = 0; // RTCPPacketTypeFlags bit field.
@@ -116,43 +138,39 @@ struct RTCPReceiver::PacketInformation {
std::unique_ptr<rtcp::LossNotification> loss_notification;
};
-// Structure for handing TMMBR and TMMBN rtcp messages (RFC5104, section 3.5.4).
-struct RTCPReceiver::TmmbrInformation {
- struct TimedTmmbrItem {
- rtcp::TmmbItem tmmbr_item;
- int64_t last_updated_ms;
- };
-
- int64_t last_time_received_ms = 0;
-
- bool ready_for_delete = false;
-
- std::vector<rtcp::TmmbItem> tmmbn;
- std::map<uint32_t, TimedTmmbrItem> tmmbr;
-};
-
-// Structure for storing received RRTR RTCP messages (RFC3611, section 4.4).
-struct RTCPReceiver::RrtrInformation {
- RrtrInformation(uint32_t ssrc,
- uint32_t received_remote_mid_ntp_time,
- uint32_t local_receive_mid_ntp_time)
- : ssrc(ssrc),
- received_remote_mid_ntp_time(received_remote_mid_ntp_time),
- local_receive_mid_ntp_time(local_receive_mid_ntp_time) {}
-
- uint32_t ssrc;
- // Received NTP timestamp in compact representation.
- uint32_t received_remote_mid_ntp_time;
- // NTP time when the report was received in compact representation.
- uint32_t local_receive_mid_ntp_time;
-};
-
-struct RTCPReceiver::LastFirStatus {
- LastFirStatus(int64_t now_ms, uint8_t sequence_number)
- : request_ms(now_ms), sequence_number(sequence_number) {}
- int64_t request_ms;
- uint8_t sequence_number;
-};
+RTCPReceiver::RTCPReceiver(const RtpRtcpInterface::Configuration& config,
+ ModuleRtpRtcpImpl2* owner)
+ : clock_(config.clock),
+ receiver_only_(config.receiver_only),
+ rtp_rtcp_(owner),
+ main_ssrc_(config.local_media_ssrc),
+ registered_ssrcs_(false, config),
+ rtcp_bandwidth_observer_(config.bandwidth_callback),
+ rtcp_intra_frame_observer_(config.intra_frame_callback),
+ rtcp_loss_notification_observer_(config.rtcp_loss_notification_observer),
+ network_state_estimate_observer_(config.network_state_estimate_observer),
+ transport_feedback_observer_(config.transport_feedback_callback),
+ bitrate_allocation_observer_(config.bitrate_allocation_observer),
+ report_interval_(config.rtcp_report_interval_ms > 0
+ ? TimeDelta::Millis(config.rtcp_report_interval_ms)
+ : (config.audio ? kDefaultAudioReportInterval
+ : kDefaultVideoReportInterval)),
+ // TODO(bugs.webrtc.org/10774): Remove fallback.
+ remote_ssrc_(0),
+ remote_sender_rtp_time_(0),
+ remote_sender_packet_count_(0),
+ remote_sender_octet_count_(0),
+ remote_sender_reports_count_(0),
+ xr_rrtr_status_(config.non_sender_rtt_measurement),
+ xr_rr_rtt_ms_(0),
+ oldest_tmmbr_info_ms_(0),
+ cname_callback_(config.rtcp_cname_callback),
+ report_block_data_observer_(config.report_block_data_observer),
+ packet_type_counter_observer_(config.rtcp_packet_type_counter_observer),
+ num_skipped_packets_(0),
+ last_skipped_packets_warning_ms_(clock_->TimeInMilliseconds()) {
+ RTC_DCHECK(owner);
+}
RTCPReceiver::RTCPReceiver(const RtpRtcpInterface::Configuration& config,
ModuleRtpRtcp* owner)
@@ -160,7 +178,7 @@ RTCPReceiver::RTCPReceiver(const RtpRtcpInterface::Configuration& config,
receiver_only_(config.receiver_only),
rtp_rtcp_(owner),
main_ssrc_(config.local_media_ssrc),
- registered_ssrcs_(GetRegisteredSsrcs(config)),
+ registered_ssrcs_(true, config),
rtcp_bandwidth_observer_(config.bandwidth_callback),
rtcp_intra_frame_observer_(config.intra_frame_callback),
rtcp_loss_notification_observer_(config.rtcp_loss_notification_observer),
@@ -180,13 +198,25 @@ RTCPReceiver::RTCPReceiver(const RtpRtcpInterface::Configuration& config,
xr_rrtr_status_(config.non_sender_rtt_measurement),
xr_rr_rtt_ms_(0),
oldest_tmmbr_info_ms_(0),
- stats_callback_(config.rtcp_statistics_callback),
cname_callback_(config.rtcp_cname_callback),
report_block_data_observer_(config.report_block_data_observer),
packet_type_counter_observer_(config.rtcp_packet_type_counter_observer),
num_skipped_packets_(0),
last_skipped_packets_warning_ms_(clock_->TimeInMilliseconds()) {
RTC_DCHECK(owner);
+ // Dear reader - if you're here because of this log statement and are
+ // wondering what this is about, chances are that you are using an instance
+ // of RTCPReceiver without using the webrtc APIs. This creates a bit of a
+ // problem for WebRTC because this class is a part of an internal
+ // implementation that is constantly changing and being improved.
+ // The intention of this log statement is to give a heads up that changes
+ // are coming and encourage you to use the public APIs or be prepared that
+ // things might break down the line as more changes land. A thing you could
+ // try out for now is to replace the `CustomSequenceChecker` in the header
+ // with a regular `SequenceChecker` and see if that triggers an
+ // error in your code. If it does, chances are you have your own threading
+ // model that is not the same as WebRTC internally has.
+ RTC_LOG(LS_INFO) << "************** !!!DEPRECATION WARNING!! **************";
}
RTCPReceiver::~RTCPReceiver() {}
@@ -217,6 +247,14 @@ void RTCPReceiver::SetRemoteSSRC(uint32_t ssrc) {
remote_ssrc_ = ssrc;
}
+void RTCPReceiver::set_local_media_ssrc(uint32_t ssrc) {
+ registered_ssrcs_.set_media_ssrc(ssrc);
+}
+
+uint32_t RTCPReceiver::local_media_ssrc() const {
+ return registered_ssrcs_.media_ssrc();
+}
+
uint32_t RTCPReceiver::RemoteSSRC() const {
MutexLock lock(&rtcp_receiver_lock_);
return remote_ssrc_;
@@ -371,8 +409,7 @@ RTCPReceiver::ConsumeReceivedXrReferenceTimeInfo() {
std::vector<rtcp::ReceiveTimeInfo> last_xr_rtis;
last_xr_rtis.reserve(last_xr_rtis_size);
- const uint32_t now_ntp =
- CompactNtp(TimeMicrosToNtp(clock_->TimeInMicroseconds()));
+ const uint32_t now_ntp = CompactNtp(clock_->CurrentNtpTime());
for (size_t i = 0; i < last_xr_rtis_size; ++i) {
RrtrInformation& rrtr = received_rrtrs_.front();
@@ -520,7 +557,7 @@ void RTCPReceiver::HandleSenderReport(const CommonHeader& rtcp_block,
remote_sender_ntp_time_ = sender_report.ntp();
remote_sender_rtp_time_ = sender_report.rtp_timestamp();
- last_received_sr_ntp_ = TimeMicrosToNtp(clock_->TimeInMicroseconds());
+ last_received_sr_ntp_ = clock_->CurrentNtpTime();
remote_sender_packet_count_ = sender_report.sender_packet_count();
remote_sender_octet_count_ = sender_report.sender_octet_count();
remote_sender_reports_count_++;
@@ -567,7 +604,7 @@ void RTCPReceiver::HandleReportBlock(const ReportBlock& report_block,
// which the information in this reception report block pertains.
// Filter out all report blocks that are not for us.
- if (registered_ssrcs_.count(report_block.source_ssrc()) == 0)
+ if (!registered_ssrcs_.contains(report_block.source_ssrc()))
return;
last_received_rb_ = clock_->CurrentTime();
@@ -610,7 +647,7 @@ void RTCPReceiver::HandleReportBlock(const ReportBlock& report_block,
uint32_t delay_ntp = report_block.delay_since_last_sr();
// Local NTP time.
uint32_t receive_time_ntp =
- CompactNtp(TimeMicrosToNtp(last_received_rb_.us()));
+ CompactNtp(clock_->ConvertTimestampToNtpTime(last_received_rb_));
// RTT in 1/(2^16) seconds.
uint32_t rtt_ntp = receive_time_ntp - delay_ntp - send_time_ntp;
@@ -813,8 +850,7 @@ void RTCPReceiver::HandleXr(const CommonHeader& rtcp_block,
void RTCPReceiver::HandleXrReceiveReferenceTime(uint32_t sender_ssrc,
const rtcp::Rrtr& rrtr) {
uint32_t received_remote_mid_ntp_time = CompactNtp(rrtr.ntp());
- uint32_t local_receive_mid_ntp_time =
- CompactNtp(TimeMicrosToNtp(clock_->TimeInMicroseconds()));
+ uint32_t local_receive_mid_ntp_time = CompactNtp(clock_->CurrentNtpTime());
auto it = received_rrtrs_ssrc_it_.find(sender_ssrc);
if (it != received_rrtrs_ssrc_it_.end()) {
@@ -833,7 +869,7 @@ void RTCPReceiver::HandleXrReceiveReferenceTime(uint32_t sender_ssrc,
}
void RTCPReceiver::HandleXrDlrrReportBlock(const rtcp::ReceiveTimeInfo& rti) {
- if (registered_ssrcs_.count(rti.ssrc) == 0) // Not to us.
+ if (!registered_ssrcs_.contains(rti.ssrc)) // Not to us.
return;
// Caller should explicitly enable rtt calculation using extended reports.
@@ -848,7 +884,7 @@ void RTCPReceiver::HandleXrDlrrReportBlock(const rtcp::ReceiveTimeInfo& rti) {
return;
uint32_t delay_ntp = rti.delay_since_last_rr;
- uint32_t now_ntp = CompactNtp(TimeMicrosToNtp(clock_->TimeInMicroseconds()));
+ uint32_t now_ntp = CompactNtp(clock_->CurrentNtpTime());
uint32_t rtt_ntp = now_ntp - delay_ntp - send_time_ntp;
xr_rr_rtt_ms_ = CompactNtpRttToMs(rtt_ntp);
@@ -1056,14 +1092,7 @@ void RTCPReceiver::TriggerCallbacksFromRtcpPacket(
// Might trigger a OnReceivedBandwidthEstimateUpdate.
NotifyTmmbrUpdated();
}
- uint32_t local_ssrc;
- std::set<uint32_t> registered_ssrcs;
- {
- // We don't want to hold this critsect when triggering the callbacks below.
- MutexLock lock(&rtcp_receiver_lock_);
- local_ssrc = main_ssrc_;
- registered_ssrcs = registered_ssrcs_;
- }
+
if (!receiver_only_ && (packet_information.packet_type_flags & kRtcpSrReq)) {
rtp_rtcp_->OnRequestSendReport();
}
@@ -1090,7 +1119,7 @@ void RTCPReceiver::TriggerCallbacksFromRtcpPacket(
RTC_LOG(LS_VERBOSE)
<< "Incoming FIR from SSRC " << packet_information.remote_ssrc;
}
- rtcp_intra_frame_observer_->OnReceivedIntraFrameRequest(local_ssrc);
+ rtcp_intra_frame_observer_->OnReceivedIntraFrameRequest(main_ssrc_);
}
}
if (rtcp_loss_notification_observer_ &&
@@ -1098,7 +1127,7 @@ void RTCPReceiver::TriggerCallbacksFromRtcpPacket(
rtcp::LossNotification* loss_notification =
packet_information.loss_notification.get();
RTC_DCHECK(loss_notification);
- if (loss_notification->media_ssrc() == local_ssrc) {
+ if (loss_notification->media_ssrc() == main_ssrc_) {
rtcp_loss_notification_observer_->OnReceivedLossNotification(
loss_notification->media_ssrc(), loss_notification->last_decoded(),
loss_notification->last_received(),
@@ -1130,8 +1159,8 @@ void RTCPReceiver::TriggerCallbacksFromRtcpPacket(
(packet_information.packet_type_flags & kRtcpTransportFeedback)) {
uint32_t media_source_ssrc =
packet_information.transport_feedback->media_ssrc();
- if (media_source_ssrc == local_ssrc ||
- registered_ssrcs.find(media_source_ssrc) != registered_ssrcs.end()) {
+ if (media_source_ssrc == main_ssrc_ ||
+ registered_ssrcs_.contains(media_source_ssrc)) {
transport_feedback_observer_->OnTransportFeedback(
*packet_information.transport_feedback);
}
@@ -1150,18 +1179,6 @@ void RTCPReceiver::TriggerCallbacksFromRtcpPacket(
}
if (!receiver_only_) {
- if (stats_callback_) {
- for (const auto& report_block : packet_information.report_blocks) {
- RtcpStatistics stats;
- stats.packets_lost = report_block.packets_lost;
- stats.extended_highest_sequence_number =
- report_block.extended_highest_sequence_number;
- stats.fraction_lost = report_block.fraction_lost;
- stats.jitter = report_block.jitter;
-
- stats_callback_->StatisticsUpdated(stats, report_block.source_ssrc);
- }
- }
if (report_block_data_observer_) {
for (const auto& report_block_data :
packet_information.report_block_datas) {