webrtc/test/fuzzers/rtp_packetizer_av1_fuzzer.cc
Philipp Hancke acfd279a14 av1: make packetization generate more evenly sized packets
Implements a two-pass approach to packetization which creates
packets of an even size similar to RtpPacketizer::SplitAboutEqually.
This improves the bandwidth estimation.

The algorithm does a first pass with the existing packetizer, then
iterates through the resulting packet sizes and sums up the bytes left unused in each packet.
It then calculates a new maximum packet length as
  configured_max_packet_len - ((unused_bytes - packets + 1) / packets)
adjusts for the overhead and re-runs the packetization algorithm.

For example, a list of OBUs with sizes
  {1206, 1476, 1431}
currently gets packetized greedily as payload sizes
  {1200, 1200, 1200, 523}
With this change, it gets packetized as
  {1032, 1032, 1032, 1028}

This change is guarded by the field trial
  WebRTC-Video-AV1EvenPayloadSizes
which is acting as a rollout flag.

BUG=webrtc:15927

Co-authored-by: Shyam Sadhwani <shyamsadhwani@meta.com>
Change-Id: I4f0b3c27de6f06104908dd769c4dd1f34115712c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/348100
Commit-Queue: Philipp Hancke <phancke@meta.com>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Per Kjellander <perkj@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#42203}
2024-04-30 15:46:06 +00:00

74 lines
3.1 KiB
C++

/*
* Copyright (c) 2019 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 <stddef.h>
#include <stdint.h>
#include "api/video/video_frame_type.h"
#include "modules/rtp_rtcp/source/rtp_format.h"
#include "modules/rtp_rtcp/source/rtp_packet_to_send.h"
#include "modules/rtp_rtcp/source/rtp_packetizer_av1.h"
#include "rtc_base/checks.h"
#include "test/fuzzers/fuzz_data_helper.h"
namespace webrtc {
void FuzzOneInput(const uint8_t* data, size_t size) {
test::FuzzDataHelper fuzz_input(rtc::MakeArrayView(data, size));
RtpPacketizer::PayloadSizeLimits limits;
limits.max_payload_len = 1200;
// Read uint8_t to be sure reduction_lens are much smaller than
// max_payload_len and thus limits structure is valid.
limits.first_packet_reduction_len = fuzz_input.ReadOrDefaultValue<uint8_t>(0);
limits.last_packet_reduction_len = fuzz_input.ReadOrDefaultValue<uint8_t>(0);
limits.single_packet_reduction_len =
fuzz_input.ReadOrDefaultValue<uint8_t>(0);
const VideoFrameType kFrameTypes[] = {VideoFrameType::kVideoFrameKey,
VideoFrameType::kVideoFrameDelta};
VideoFrameType frame_type = fuzz_input.SelectOneOf(kFrameTypes);
// Main function under test: RtpPacketizerAv1's constructor.
// "even distribution" is transitional and still exercises the other code path
// so does not require another fuzzer.
RtpPacketizerAv1 packetizer(fuzz_input.ReadByteArray(fuzz_input.BytesLeft()),
limits, frame_type,
/*is_last_frame_in_picture=*/true,
/*even_distribution=*/true);
size_t num_packets = packetizer.NumPackets();
if (num_packets == 0) {
return;
}
// When packetization was successful, validate NextPacket function too.
// While at it, check that packets respect the payload size limits.
RtpPacketToSend rtp_packet(nullptr);
// Single packet.
if (num_packets == 1) {
RTC_CHECK(packetizer.NextPacket(&rtp_packet));
RTC_CHECK_LE(rtp_packet.payload_size(),
limits.max_payload_len - limits.single_packet_reduction_len);
return;
}
// First packet.
RTC_CHECK(packetizer.NextPacket(&rtp_packet));
RTC_CHECK_LE(rtp_packet.payload_size(),
limits.max_payload_len - limits.first_packet_reduction_len);
// Middle packets.
for (size_t i = 1; i < num_packets - 1; ++i) {
RTC_CHECK(packetizer.NextPacket(&rtp_packet))
<< "Failed to get packet#" << i;
RTC_CHECK_LE(rtp_packet.payload_size(), limits.max_payload_len)
<< "Packet #" << i << " exceeds it's limit";
}
// Last packet.
RTC_CHECK(packetizer.NextPacket(&rtp_packet));
RTC_CHECK_LE(rtp_packet.payload_size(),
limits.max_payload_len - limits.last_packet_reduction_len);
}
} // namespace webrtc