Commit d565eec60f for aom
commit d565eec60f084421fa34fc0534b760c6452b6a6c
Author: Wan-Teh Chang <wtc@google.com>
Date: Wed Sep 2 17:50:06 2026 -0700
Flush the encoder as documented
The comments for aom_codec_encode() in aom/aom_encoder.h say:
When the last frame has been passed to the encoder, this function should
continue to be called in a loop, with the img parameter set to NULL. This
will signal the end-of-stream condition to the encoder and allow it to
encode any held buffers. Encoding is complete when aom_codec_encode() is
called with img set to NULL and aom_codec_get_cx_data() returns no data.
Change-Id: I854b1406e3f4222f8721648778f29d153d30a7a9
diff --git a/examples/av1_enc_fuzzer.cc b/examples/av1_enc_fuzzer.cc
index 48c00e8654..6868190fbc 100644
--- a/examples/av1_enc_fuzzer.cc
+++ b/examples/av1_enc_fuzzer.cc
@@ -109,10 +109,13 @@ int PickCpuUsed(unsigned int usage, uint8_t raw) {
return raw % (max_cpu_used + 1);
}
-void DrainPackets(aom_codec_ctx_t *codec) {
+bool DrainPackets(aom_codec_ctx_t *codec) {
+ bool got_data = false;
aom_codec_iter_t iter = nullptr;
while (aom_codec_get_cx_data(codec, &iter) != nullptr) {
+ got_data = true;
}
+ return got_data;
}
bool InitDefaultConfig(aom_codec_iface_t *iface, unsigned int usage,
@@ -214,7 +217,7 @@ bool EncodeFrame(aom_codec_ctx_t *codec, FuzzReader *reader, unsigned int width,
const aom_codec_err_t enc_ret =
aom_codec_encode(codec, &image, pts, 1, flags);
if (enc_ret == AOM_CODEC_OK) {
- DrainPackets(codec);
+ (void)DrainPackets(codec);
}
aom_img_free(&image);
@@ -316,10 +319,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
}
if (!config_failed) {
- const aom_codec_err_t flush_ret =
- aom_codec_encode(&codec, nullptr, 0, 0, 0);
- if (flush_ret == AOM_CODEC_OK) {
- DrainPackets(&codec);
+ while (aom_codec_encode(&codec, nullptr, 0, 0, 0) == AOM_CODEC_OK &&
+ DrainPackets(&codec)) {
}
}