webrtc_m130/call/rtp_config.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

204 lines
6.2 KiB
C++
Raw Normal View History

/*
* Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
*
* 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.
*/
#include "call/rtp_config.h"
#include <cstdint>
[Stats] Explicit RTP-RTX and RTP-FEC mappings. Unblocks simulcast stats. --- Background --- The webrtc::VideoSendStream::StreamStats are converted into VideoSenderInfo objects which turn into "outbound-rtp" stats objects in getStats() (or "ssrc" objects in legacy getStats()). StreamStats are created for each type of substream: RTP media streams, RTX streams and FlexFEC streams - each with individual packet counters. The RTX stream is responsible for retransmissions of a referenced media stream and the FlexFEC stream is responsible for FEC of a referenced media stream. RTX/FEC streams do not show up as separate objects in getStats(). Only the media streams become "outbound-rtp" objects, but their packet and byte counters have to include the RTX and FEC counters. --- Overview of this CL --- This CL adds MergeInfoAboutOutboundRtpSubstreams(). It takes StreamStats of all kinds as input, and outputs media-only StreamStats - incorporating the RTX and FEC counters into the relevant media StreamStats. The merged StreamStats objects is a smaller set of objects than the non-merged counterparts, but when aggregating all packet counters together we end up with exact same packet and count as before. Because WebRtcVideoSendStream::GetVideoSenderInfo() currently aggregates the StreamStats into a single VideoSenderInfo (single "outbound-rtp"), this CL should not have any observable side-effects. Prior to this CL: aggregate StreamStats. After this CL: merge StreamStats and then aggregate them. However, when simulcast stats are implemented (WIP CL: https://webrtc-review.googlesource.com/c/src/+/168120) each RTP media stream should turn into an individual "outbound-rtp" object. We will then no longer aggregate all StreamStats into a single "info". This CL unblocks simulcast stats by providing StreamStats objects that could be turned into individual VideoSenderInfos. --- The Changes --- 1. Methods added to RtpConfig to be able to easily tell the relationship between RTP, RTX and FEC ssrcs. 2. StreamStats gets a StreamType (kMedia, kRtx or kFlexfec) that replaces the booleans (is_rtx, is_flexfec). 3. "referenced_media_ssrc" is added to StreamStats, making it possible to tell which kRtx/kFlexFec stream stats need to be merged with which kMedia StreamStats. 4. MergeInfoAboutOutboundRtpSubstreams() added and used. Bug: webrtc:11439 Change-Id: Iaf9002041169a054ddfd32c7ea06bd1dc36c6bca Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/170826 Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Stefan Holmer <stefan@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30869}
2020-03-24 13:30:50 +01:00
#include "absl/algorithm/container.h"
#include "api/array_view.h"
[Stats] Explicit RTP-RTX and RTP-FEC mappings. Unblocks simulcast stats. --- Background --- The webrtc::VideoSendStream::StreamStats are converted into VideoSenderInfo objects which turn into "outbound-rtp" stats objects in getStats() (or "ssrc" objects in legacy getStats()). StreamStats are created for each type of substream: RTP media streams, RTX streams and FlexFEC streams - each with individual packet counters. The RTX stream is responsible for retransmissions of a referenced media stream and the FlexFEC stream is responsible for FEC of a referenced media stream. RTX/FEC streams do not show up as separate objects in getStats(). Only the media streams become "outbound-rtp" objects, but their packet and byte counters have to include the RTX and FEC counters. --- Overview of this CL --- This CL adds MergeInfoAboutOutboundRtpSubstreams(). It takes StreamStats of all kinds as input, and outputs media-only StreamStats - incorporating the RTX and FEC counters into the relevant media StreamStats. The merged StreamStats objects is a smaller set of objects than the non-merged counterparts, but when aggregating all packet counters together we end up with exact same packet and count as before. Because WebRtcVideoSendStream::GetVideoSenderInfo() currently aggregates the StreamStats into a single VideoSenderInfo (single "outbound-rtp"), this CL should not have any observable side-effects. Prior to this CL: aggregate StreamStats. After this CL: merge StreamStats and then aggregate them. However, when simulcast stats are implemented (WIP CL: https://webrtc-review.googlesource.com/c/src/+/168120) each RTP media stream should turn into an individual "outbound-rtp" object. We will then no longer aggregate all StreamStats into a single "info". This CL unblocks simulcast stats by providing StreamStats objects that could be turned into individual VideoSenderInfos. --- The Changes --- 1. Methods added to RtpConfig to be able to easily tell the relationship between RTP, RTX and FEC ssrcs. 2. StreamStats gets a StreamType (kMedia, kRtx or kFlexfec) that replaces the booleans (is_rtx, is_flexfec). 3. "referenced_media_ssrc" is added to StreamStats, making it possible to tell which kRtx/kFlexFec stream stats need to be merged with which kMedia StreamStats. 4. MergeInfoAboutOutboundRtpSubstreams() added and used. Bug: webrtc:11439 Change-Id: Iaf9002041169a054ddfd32c7ea06bd1dc36c6bca Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/170826 Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Stefan Holmer <stefan@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30869}
2020-03-24 13:30:50 +01:00
#include "rtc_base/checks.h"
#include "rtc_base/strings/string_builder.h"
namespace webrtc {
[Stats] Explicit RTP-RTX and RTP-FEC mappings. Unblocks simulcast stats. --- Background --- The webrtc::VideoSendStream::StreamStats are converted into VideoSenderInfo objects which turn into "outbound-rtp" stats objects in getStats() (or "ssrc" objects in legacy getStats()). StreamStats are created for each type of substream: RTP media streams, RTX streams and FlexFEC streams - each with individual packet counters. The RTX stream is responsible for retransmissions of a referenced media stream and the FlexFEC stream is responsible for FEC of a referenced media stream. RTX/FEC streams do not show up as separate objects in getStats(). Only the media streams become "outbound-rtp" objects, but their packet and byte counters have to include the RTX and FEC counters. --- Overview of this CL --- This CL adds MergeInfoAboutOutboundRtpSubstreams(). It takes StreamStats of all kinds as input, and outputs media-only StreamStats - incorporating the RTX and FEC counters into the relevant media StreamStats. The merged StreamStats objects is a smaller set of objects than the non-merged counterparts, but when aggregating all packet counters together we end up with exact same packet and count as before. Because WebRtcVideoSendStream::GetVideoSenderInfo() currently aggregates the StreamStats into a single VideoSenderInfo (single "outbound-rtp"), this CL should not have any observable side-effects. Prior to this CL: aggregate StreamStats. After this CL: merge StreamStats and then aggregate them. However, when simulcast stats are implemented (WIP CL: https://webrtc-review.googlesource.com/c/src/+/168120) each RTP media stream should turn into an individual "outbound-rtp" object. We will then no longer aggregate all StreamStats into a single "info". This CL unblocks simulcast stats by providing StreamStats objects that could be turned into individual VideoSenderInfos. --- The Changes --- 1. Methods added to RtpConfig to be able to easily tell the relationship between RTP, RTX and FEC ssrcs. 2. StreamStats gets a StreamType (kMedia, kRtx or kFlexfec) that replaces the booleans (is_rtx, is_flexfec). 3. "referenced_media_ssrc" is added to StreamStats, making it possible to tell which kRtx/kFlexFec stream stats need to be merged with which kMedia StreamStats. 4. MergeInfoAboutOutboundRtpSubstreams() added and used. Bug: webrtc:11439 Change-Id: Iaf9002041169a054ddfd32c7ea06bd1dc36c6bca Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/170826 Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Stefan Holmer <stefan@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30869}
2020-03-24 13:30:50 +01:00
namespace {
uint32_t FindAssociatedSsrc(uint32_t ssrc,
const std::vector<uint32_t>& ssrcs,
const std::vector<uint32_t>& associated_ssrcs) {
RTC_DCHECK_EQ(ssrcs.size(), associated_ssrcs.size());
for (size_t i = 0; i < ssrcs.size(); ++i) {
if (ssrcs[i] == ssrc)
return associated_ssrcs[i];
}
RTC_DCHECK_NOTREACHED();
[Stats] Explicit RTP-RTX and RTP-FEC mappings. Unblocks simulcast stats. --- Background --- The webrtc::VideoSendStream::StreamStats are converted into VideoSenderInfo objects which turn into "outbound-rtp" stats objects in getStats() (or "ssrc" objects in legacy getStats()). StreamStats are created for each type of substream: RTP media streams, RTX streams and FlexFEC streams - each with individual packet counters. The RTX stream is responsible for retransmissions of a referenced media stream and the FlexFEC stream is responsible for FEC of a referenced media stream. RTX/FEC streams do not show up as separate objects in getStats(). Only the media streams become "outbound-rtp" objects, but their packet and byte counters have to include the RTX and FEC counters. --- Overview of this CL --- This CL adds MergeInfoAboutOutboundRtpSubstreams(). It takes StreamStats of all kinds as input, and outputs media-only StreamStats - incorporating the RTX and FEC counters into the relevant media StreamStats. The merged StreamStats objects is a smaller set of objects than the non-merged counterparts, but when aggregating all packet counters together we end up with exact same packet and count as before. Because WebRtcVideoSendStream::GetVideoSenderInfo() currently aggregates the StreamStats into a single VideoSenderInfo (single "outbound-rtp"), this CL should not have any observable side-effects. Prior to this CL: aggregate StreamStats. After this CL: merge StreamStats and then aggregate them. However, when simulcast stats are implemented (WIP CL: https://webrtc-review.googlesource.com/c/src/+/168120) each RTP media stream should turn into an individual "outbound-rtp" object. We will then no longer aggregate all StreamStats into a single "info". This CL unblocks simulcast stats by providing StreamStats objects that could be turned into individual VideoSenderInfos. --- The Changes --- 1. Methods added to RtpConfig to be able to easily tell the relationship between RTP, RTX and FEC ssrcs. 2. StreamStats gets a StreamType (kMedia, kRtx or kFlexfec) that replaces the booleans (is_rtx, is_flexfec). 3. "referenced_media_ssrc" is added to StreamStats, making it possible to tell which kRtx/kFlexFec stream stats need to be merged with which kMedia StreamStats. 4. MergeInfoAboutOutboundRtpSubstreams() added and used. Bug: webrtc:11439 Change-Id: Iaf9002041169a054ddfd32c7ea06bd1dc36c6bca Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/170826 Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Stefan Holmer <stefan@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30869}
2020-03-24 13:30:50 +01:00
return 0;
}
} // namespace
std::string LntfConfig::ToString() const {
return enabled ? "{enabled: true}" : "{enabled: false}";
}
std::string NackConfig::ToString() const {
char buf[1024];
rtc::SimpleStringBuilder ss(buf);
ss << "{rtp_history_ms: " << rtp_history_ms;
ss << '}';
return ss.str();
}
std::string UlpfecConfig::ToString() const {
char buf[1024];
rtc::SimpleStringBuilder ss(buf);
ss << "{ulpfec_payload_type: " << ulpfec_payload_type;
ss << ", red_payload_type: " << red_payload_type;
ss << ", red_rtx_payload_type: " << red_rtx_payload_type;
ss << '}';
return ss.str();
}
bool UlpfecConfig::operator==(const UlpfecConfig& other) const {
return ulpfec_payload_type == other.ulpfec_payload_type &&
red_payload_type == other.red_payload_type &&
red_rtx_payload_type == other.red_rtx_payload_type;
}
RtpConfig::RtpConfig() = default;
RtpConfig::RtpConfig(const RtpConfig&) = default;
RtpConfig::~RtpConfig() = default;
RtpConfig::Flexfec::Flexfec() = default;
RtpConfig::Flexfec::Flexfec(const Flexfec&) = default;
RtpConfig::Flexfec::~Flexfec() = default;
std::string RtpConfig::ToString() const {
char buf[2 * 1024];
rtc::SimpleStringBuilder ss(buf);
ss << "{ssrcs: [";
for (size_t i = 0; i < ssrcs.size(); ++i) {
ss << ssrcs[i];
if (i != ssrcs.size() - 1)
ss << ", ";
}
ss << "], rids: [";
for (size_t i = 0; i < rids.size(); ++i) {
ss << rids[i];
if (i != rids.size() - 1)
ss << ", ";
}
ss << "], mid: '" << mid << "'";
ss << ", rtcp_mode: "
<< (rtcp_mode == RtcpMode::kCompound ? "RtcpMode::kCompound"
: "RtcpMode::kReducedSize");
ss << ", max_packet_size: " << max_packet_size;
ss << ", extmap-allow-mixed: " << (extmap_allow_mixed ? "true" : "false");
ss << ", extensions: [";
for (size_t i = 0; i < extensions.size(); ++i) {
ss << extensions[i].ToString();
if (i != extensions.size() - 1)
ss << ", ";
}
ss << ']';
ss << ", lntf: " << lntf.ToString();
ss << ", nack: {rtp_history_ms: " << nack.rtp_history_ms << '}';
ss << ", ulpfec: " << ulpfec.ToString();
ss << ", payload_name: " << payload_name;
ss << ", payload_type: " << payload_type;
ss << ", raw_payload: " << (raw_payload ? "true" : "false");
ss << ", flexfec: {payload_type: " << flexfec.payload_type;
ss << ", ssrc: " << flexfec.ssrc;
ss << ", protected_media_ssrcs: [";
for (size_t i = 0; i < flexfec.protected_media_ssrcs.size(); ++i) {
ss << flexfec.protected_media_ssrcs[i];
if (i != flexfec.protected_media_ssrcs.size() - 1)
ss << ", ";
}
ss << "]}";
ss << ", rtx: " << rtx.ToString();
ss << ", c_name: " << c_name;
ss << '}';
return ss.str();
}
RtpConfig::Rtx::Rtx() = default;
RtpConfig::Rtx::Rtx(const Rtx&) = default;
RtpConfig::Rtx::~Rtx() = default;
std::string RtpConfig::Rtx::ToString() const {
char buf[1024];
rtc::SimpleStringBuilder ss(buf);
ss << "{ssrcs: [";
for (size_t i = 0; i < ssrcs.size(); ++i) {
ss << ssrcs[i];
if (i != ssrcs.size() - 1)
ss << ", ";
}
ss << ']';
ss << ", payload_type: " << payload_type;
ss << '}';
return ss.str();
}
[Stats] Explicit RTP-RTX and RTP-FEC mappings. Unblocks simulcast stats. --- Background --- The webrtc::VideoSendStream::StreamStats are converted into VideoSenderInfo objects which turn into "outbound-rtp" stats objects in getStats() (or "ssrc" objects in legacy getStats()). StreamStats are created for each type of substream: RTP media streams, RTX streams and FlexFEC streams - each with individual packet counters. The RTX stream is responsible for retransmissions of a referenced media stream and the FlexFEC stream is responsible for FEC of a referenced media stream. RTX/FEC streams do not show up as separate objects in getStats(). Only the media streams become "outbound-rtp" objects, but their packet and byte counters have to include the RTX and FEC counters. --- Overview of this CL --- This CL adds MergeInfoAboutOutboundRtpSubstreams(). It takes StreamStats of all kinds as input, and outputs media-only StreamStats - incorporating the RTX and FEC counters into the relevant media StreamStats. The merged StreamStats objects is a smaller set of objects than the non-merged counterparts, but when aggregating all packet counters together we end up with exact same packet and count as before. Because WebRtcVideoSendStream::GetVideoSenderInfo() currently aggregates the StreamStats into a single VideoSenderInfo (single "outbound-rtp"), this CL should not have any observable side-effects. Prior to this CL: aggregate StreamStats. After this CL: merge StreamStats and then aggregate them. However, when simulcast stats are implemented (WIP CL: https://webrtc-review.googlesource.com/c/src/+/168120) each RTP media stream should turn into an individual "outbound-rtp" object. We will then no longer aggregate all StreamStats into a single "info". This CL unblocks simulcast stats by providing StreamStats objects that could be turned into individual VideoSenderInfos. --- The Changes --- 1. Methods added to RtpConfig to be able to easily tell the relationship between RTP, RTX and FEC ssrcs. 2. StreamStats gets a StreamType (kMedia, kRtx or kFlexfec) that replaces the booleans (is_rtx, is_flexfec). 3. "referenced_media_ssrc" is added to StreamStats, making it possible to tell which kRtx/kFlexFec stream stats need to be merged with which kMedia StreamStats. 4. MergeInfoAboutOutboundRtpSubstreams() added and used. Bug: webrtc:11439 Change-Id: Iaf9002041169a054ddfd32c7ea06bd1dc36c6bca Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/170826 Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Stefan Holmer <stefan@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30869}
2020-03-24 13:30:50 +01:00
bool RtpConfig::IsMediaSsrc(uint32_t ssrc) const {
return absl::c_linear_search(ssrcs, ssrc);
}
bool RtpConfig::IsRtxSsrc(uint32_t ssrc) const {
return absl::c_linear_search(rtx.ssrcs, ssrc);
}
bool RtpConfig::IsFlexfecSsrc(uint32_t ssrc) const {
return flexfec.payload_type != -1 && ssrc == flexfec.ssrc;
}
absl::optional<uint32_t> RtpConfig::GetRtxSsrcAssociatedWithMediaSsrc(
uint32_t media_ssrc) const {
RTC_DCHECK(IsMediaSsrc(media_ssrc));
// If we don't use RTX there is no association.
if (rtx.ssrcs.empty())
return absl::nullopt;
// If we use RTX there MUST be an association ssrcs[i] <-> rtx.ssrcs[i].
RTC_DCHECK_EQ(ssrcs.size(), rtx.ssrcs.size());
return FindAssociatedSsrc(media_ssrc, ssrcs, rtx.ssrcs);
}
uint32_t RtpConfig::GetMediaSsrcAssociatedWithRtxSsrc(uint32_t rtx_ssrc) const {
RTC_DCHECK(IsRtxSsrc(rtx_ssrc));
// If we use RTX there MUST be an association ssrcs[i] <-> rtx.ssrcs[i].
RTC_DCHECK_EQ(ssrcs.size(), rtx.ssrcs.size());
return FindAssociatedSsrc(rtx_ssrc, rtx.ssrcs, ssrcs);
}
uint32_t RtpConfig::GetMediaSsrcAssociatedWithFlexfecSsrc(
uint32_t flexfec_ssrc) const {
RTC_DCHECK(IsFlexfecSsrc(flexfec_ssrc));
// If we use FlexFEC there MUST be an associated media ssrc.
//
// TODO(brandtr/hbos): The current implementation only supports an association
// with a single media ssrc. If multiple ssrcs are to be supported in the
// future, in order not to break GetStats()'s packet and byte counters, we
// must be able to tell how many packets and bytes have contributed to which
// SSRC.
RTC_DCHECK_EQ(1u, flexfec.protected_media_ssrcs.size());
uint32_t media_ssrc = flexfec.protected_media_ssrcs[0];
RTC_DCHECK(IsMediaSsrc(media_ssrc));
return media_ssrc;
}
Reland "Improve outbound-rtp statistics for simulcast" This reverts commit 9a925c9ce33a6ccdd11b545b11ba68e985c2a65d. Reason for revert: The original CL is updated in PS #2 to fix the googRtt issue which was that when the legacy sender stats were put in "aggregated_senders" we forgot to update rtt_ms the same way that we do it for "senders". Original change's description: > Revert "Improve outbound-rtp statistics for simulcast" > > This reverts commit da6cda839dac7d9d18eba8d365188fa94831e0b1. > > Reason for revert: Breaks googRtt in legacy getStats API > > Original change's description: > > Improve outbound-rtp statistics for simulcast > > > > Bug: webrtc:9547 > > Change-Id: Iec4eb976aa11ee743805425bedb77dcea7c2c9be > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168120 > > Reviewed-by: Sebastian Jansson <srte@webrtc.org> > > Reviewed-by: Erik Språng <sprang@webrtc.org> > > Reviewed-by: Henrik Boström <hbos@webrtc.org> > > Reviewed-by: Harald Alvestrand <hta@webrtc.org> > > Commit-Queue: Eldar Rello <elrello@microsoft.com> > > Cr-Commit-Position: refs/heads/master@{#31097} > > TBR=hbos@webrtc.org,sprang@webrtc.org,stefan@webrtc.org,srte@webrtc.org,hta@webrtc.org,elrello@microsoft.com > > # Not skipping CQ checks because original CL landed > 1 day ago. > > Bug: webrtc:9547 > Change-Id: I06673328c2a5293a7eef03b3aaf2ded9d13df1b3 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/174443 > Reviewed-by: Henrik Boström <hbos@webrtc.org> > Commit-Queue: Henrik Boström <hbos@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#31165} TBR=hbos@webrtc.org,sprang@webrtc.org,stefan@webrtc.org,srte@webrtc.org,hta@webrtc.org,elrello@microsoft.com # Not skipping CQ checks because this is a reland. Bug: webrtc:9547 Change-Id: I723744c496c3c65f95ab6a8940862c8b9f544338 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/174480 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Henrik Boström <hbos@webrtc.org> Commit-Queue: Henrik Boström <hbos@webrtc.org> Cr-Commit-Position: refs/heads/master@{#31169}
2020-05-05 15:54:46 +02:00
absl::optional<std::string> RtpConfig::GetRidForSsrc(uint32_t ssrc) const {
auto it = std::find(ssrcs.begin(), ssrcs.end(), ssrc);
if (it != ssrcs.end()) {
size_t ssrc_index = std::distance(ssrcs.begin(), it);
if (ssrc_index < rids.size()) {
return rids[ssrc_index];
}
}
return absl::nullopt;
}
} // namespace webrtc