Commit 39bf2a1cfb for ffmpeg
commit 39bf2a1cfb37977b29d161bc3c949474773d36bd
Author: Michael Niedermayer <michael@niedermayer.cc>
Date: Fri Oct 2 11:47:02 2026 +0000
avcodec/tests: cover hardware encoder timestamp fixup at EOF
Exercise empty input and short streams around the decode delay without requiring hardware. Print results for FATE comparison, including the EOF state and timestamp difference.
Assisted-by: Fairy
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index b30c263fae..bb2c32c250 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -1397,6 +1397,7 @@ TESTPROGS-$(CONFIG_APV_DECODER) += apv
TESTPROGS-$(CONFIG_AV1_VAAPI_ENCODER) += av1_levels
TESTPROGS-$(CONFIG_CABAC) += cabac
TESTPROGS-$(CONFIG_CELP_MATH) += celp_math
+TESTPROGS-$(CONFIG_ENCODERS) += hw_base_encode
TESTPROGS-$(CONFIG_GOLOMB) += golomb
TESTPROGS-$(CONFIG_IDCTDSP) += dct
TESTPROGS-$(CONFIG_DXV_ENCODER) += hashtable
diff --git a/libavcodec/tests/hw_base_encode.c b/libavcodec/tests/hw_base_encode.c
new file mode 100644
index 0000000000..578a97919b
--- /dev/null
+++ b/libavcodec/tests/hw_base_encode.c
@@ -0,0 +1,49 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+
+#include "libavcodec/hw_base_encode.c"
+
+int main(void)
+{
+ AVCodecContext avctx = { 0 };
+
+ for (int delay = 0; delay <= 3; delay++) {
+ for (int count = 0; count <= 4; count++) {
+ FFHWBaseEncodePicture pic = { 0 };
+ FFHWBaseEncodeContext ctx = { 0 };
+ int ret;
+
+ ctx.decode_delay = delay;
+ ctx.input_order = count;
+ ctx.first_pts = 100;
+ if (count) {
+ pic.pts = ctx.first_pts + 10 * (count - 1);
+ ctx.pic_end = &pic;
+ }
+ if (count > delay)
+ ctx.dts_pts_diff = 10 * delay;
+
+ ret = hw_base_encode_send_frame(&avctx, &ctx, NULL);
+ printf("delay=%d frames=%d return=%d eof=%d pts_diff=%"PRId64"\n",
+ delay, count, ret, ctx.end_of_stream, ctx.dts_pts_diff);
+ }
+ }
+ return 0;
+}
diff --git a/tests/fate/libavcodec.mak b/tests/fate/libavcodec.mak
index 713b1feb36..82cdb041d1 100644
--- a/tests/fate/libavcodec.mak
+++ b/tests/fate/libavcodec.mak
@@ -56,6 +56,10 @@ fate-hashtable: libavcodec/tests/hashtable$(EXESUF)
fate-hashtable: CMD = run libavcodec/tests/hashtable$(EXESUF)
fate-hashtable: CMP = null
+FATE_LIBAVCODEC-$(CONFIG_ENCODERS) += fate-hw-base-encode
+fate-hw-base-encode: libavcodec/tests/hw_base_encode$(EXESUF)
+fate-hw-base-encode: CMD = run libavcodec/tests/hw_base_encode$(EXESUF)
+
FATE_LIBAVCODEC-$(CONFIG_IDCTDSP) += fate-idct8x8-0 fate-idct8x8-1 fate-idct8x8-2 fate-idct248
fate-idct8x8-0: libavcodec/tests/dct$(EXESUF)
diff --git a/tests/ref/fate/hw-base-encode b/tests/ref/fate/hw-base-encode
new file mode 100644
index 0000000000..9f0725473f
--- /dev/null
+++ b/tests/ref/fate/hw-base-encode
@@ -0,0 +1,20 @@
+delay=0 frames=0 return=0 eof=1 pts_diff=0
+delay=0 frames=1 return=0 eof=1 pts_diff=0
+delay=0 frames=2 return=0 eof=1 pts_diff=0
+delay=0 frames=3 return=0 eof=1 pts_diff=0
+delay=0 frames=4 return=0 eof=1 pts_diff=0
+delay=1 frames=0 return=0 eof=1 pts_diff=0
+delay=1 frames=1 return=0 eof=1 pts_diff=0
+delay=1 frames=2 return=0 eof=1 pts_diff=10
+delay=1 frames=3 return=0 eof=1 pts_diff=10
+delay=1 frames=4 return=0 eof=1 pts_diff=10
+delay=2 frames=0 return=0 eof=1 pts_diff=0
+delay=2 frames=1 return=0 eof=1 pts_diff=0
+delay=2 frames=2 return=0 eof=1 pts_diff=10
+delay=2 frames=3 return=0 eof=1 pts_diff=20
+delay=2 frames=4 return=0 eof=1 pts_diff=20
+delay=3 frames=0 return=0 eof=1 pts_diff=0
+delay=3 frames=1 return=0 eof=1 pts_diff=0
+delay=3 frames=2 return=0 eof=1 pts_diff=10
+delay=3 frames=3 return=0 eof=1 pts_diff=20
+delay=3 frames=4 return=0 eof=1 pts_diff=30