Reject XR TargetBitrate items with unsupported layer indices
Specifically, reject any bitrate allocated for a layer not representable by the BitrateAllocation struct. BUG=chromium:671312 Review-Url: https://codereview.webrtc.org/2549233005 Cr-Commit-Position: refs/heads/master@{#15447}
This commit is contained in:
@ -154,9 +154,9 @@ BitrateAllocation::BitrateAllocation() : sum_(0), bitrates_{} {}
|
||||
bool BitrateAllocation::SetBitrate(size_t spatial_index,
|
||||
size_t temporal_index,
|
||||
uint32_t bitrate_bps) {
|
||||
RTC_DCHECK_LT(spatial_index, kMaxSpatialLayers);
|
||||
RTC_DCHECK_LT(temporal_index, kMaxTemporalStreams);
|
||||
RTC_DCHECK_LE(bitrates_[spatial_index][temporal_index], sum_);
|
||||
RTC_CHECK_LT(spatial_index, kMaxSpatialLayers);
|
||||
RTC_CHECK_LT(temporal_index, kMaxTemporalStreams);
|
||||
RTC_CHECK_LE(bitrates_[spatial_index][temporal_index], sum_);
|
||||
uint64_t new_bitrate_sum_bps = sum_;
|
||||
new_bitrate_sum_bps -= bitrates_[spatial_index][temporal_index];
|
||||
new_bitrate_sum_bps += bitrate_bps;
|
||||
@ -170,14 +170,14 @@ bool BitrateAllocation::SetBitrate(size_t spatial_index,
|
||||
|
||||
uint32_t BitrateAllocation::GetBitrate(size_t spatial_index,
|
||||
size_t temporal_index) const {
|
||||
RTC_DCHECK_LT(spatial_index, kMaxSpatialLayers);
|
||||
RTC_DCHECK_LT(temporal_index, kMaxTemporalStreams);
|
||||
RTC_CHECK_LT(spatial_index, kMaxSpatialLayers);
|
||||
RTC_CHECK_LT(temporal_index, kMaxTemporalStreams);
|
||||
return bitrates_[spatial_index][temporal_index];
|
||||
}
|
||||
|
||||
// Get the sum of all the temporal layer for a specific spatial layer.
|
||||
uint32_t BitrateAllocation::GetSpatialLayerSum(size_t spatial_index) const {
|
||||
RTC_DCHECK_LT(spatial_index, kMaxSpatialLayers);
|
||||
RTC_CHECK_LT(spatial_index, kMaxSpatialLayers);
|
||||
uint32_t sum = 0;
|
||||
for (int i = 0; i < kMaxTemporalStreams; ++i)
|
||||
sum += bitrates_[spatial_index][i];
|
||||
|
||||
@ -22,6 +22,7 @@
|
||||
#include "webrtc/base/checks.h"
|
||||
#include "webrtc/base/logging.h"
|
||||
#include "webrtc/base/trace_event.h"
|
||||
#include "webrtc/common_types.h"
|
||||
#include "webrtc/common_video/include/video_bitrate_allocator.h"
|
||||
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/bye.h"
|
||||
#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h"
|
||||
@ -737,9 +738,17 @@ void RTCPReceiver::HandleXrTargetBitrate(
|
||||
PacketInformation* packet_information) {
|
||||
BitrateAllocation bitrate_allocation;
|
||||
for (const auto& item : target_bitrate.GetTargetBitrates()) {
|
||||
if (item.spatial_layer >= kMaxSpatialLayers ||
|
||||
item.temporal_layer >= kMaxTemporalStreams) {
|
||||
LOG(LS_WARNING)
|
||||
<< "Invalid layer in XR target bitrate pack: spatial index "
|
||||
<< item.spatial_layer << ", temporal index " << item.temporal_layer
|
||||
<< ", dropping.";
|
||||
} else {
|
||||
bitrate_allocation.SetBitrate(item.spatial_layer, item.temporal_layer,
|
||||
item.target_bitrate_kbps * 1000);
|
||||
}
|
||||
}
|
||||
packet_information->target_bitrate_allocation.emplace(bitrate_allocation);
|
||||
}
|
||||
|
||||
|
||||
@ -1297,4 +1297,21 @@ TEST_F(RtcpReceiverTest, ReceivesTargetBitrate) {
|
||||
InjectRtcpPacket(xr);
|
||||
}
|
||||
|
||||
TEST_F(RtcpReceiverTest, HandlesIncorrectTargetBitrate) {
|
||||
BitrateAllocation expected_allocation;
|
||||
expected_allocation.SetBitrate(0, 0, 10000);
|
||||
|
||||
rtcp::TargetBitrate bitrate;
|
||||
bitrate.AddTargetBitrate(0, 0, expected_allocation.GetBitrate(0, 0) / 1000);
|
||||
bitrate.AddTargetBitrate(0, kMaxTemporalStreams, 20000);
|
||||
bitrate.AddTargetBitrate(kMaxSpatialLayers, 0, 40000);
|
||||
|
||||
rtcp::ExtendedReports xr;
|
||||
xr.SetTargetBitrate(bitrate);
|
||||
|
||||
EXPECT_CALL(bitrate_allocation_observer_,
|
||||
OnBitrateAllocationUpdated(expected_allocation));
|
||||
InjectRtcpPacket(xr);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
Reference in New Issue
Block a user