tests: fix benchmark (yuv420p fixture, identity probe frame counter)

This commit is contained in:
Matteo Benedetto
2026-03-23 23:37:23 +01:00
parent 9ab0ec4f44
commit 1a3549312e
2 changed files with 16 additions and 4 deletions
+16 -4
View File
@@ -77,7 +77,7 @@ def _generate_test_video(path: str, Gst, GLib) -> None:
print(f" (duration={GENERATE_DURATION}s, size=1920x1080, rate={GENERATE_FPS}/1)")
pipe_str = (
f"videotestsrc num-buffers={GENERATE_DURATION * GENERATE_FPS} "
f"! video/x-raw,width=1920,height=1080,framerate={GENERATE_FPS}/1 "
f"! video/x-raw,width=1920,height=1080,framerate={GENERATE_FPS}/1,format=I420 "
f"! avenc_h264 bitrate=4000000 "
f"! h264parse ! mp4mux ! filesink location={path}"
)
@@ -151,6 +151,16 @@ def _run_benchmark(
sink.set_property("max-buffers", 4)
sink.set_property("drop", False)
sink.connect("new-sample", on_new_sample)
else:
# fakesink path: count frames via identity handoff signal
probe = pipeline.get_by_name("probe")
if probe:
def on_handoff(elem, buf, pad):
n = frame_count[0]
frame_count[0] = n + 1
if n >= WARMUP_FRAMES:
frame_times.append(time.monotonic())
probe.connect("handoff", on_handoff)
loop = GLib.MainLoop()
@@ -180,7 +190,7 @@ def _run_benchmark(
wall = t_wall_end - t_wall_start
cpu_pct = _cpu_percent(*cpu_before, *cpu_after)
if is_appsink and len(frame_times) >= 2:
if len(frame_times) >= 2:
measure_frames = len(frame_times)
measure_wall = frame_times[-1] - frame_times[0]
fps = (measure_frames - 1) / measure_wall if measure_wall > 0 else 0
@@ -243,7 +253,8 @@ def main() -> None:
# 1. SW fakesink — pure decode throughput
if av_ok:
_set_mpp_rank(GST_RANK_NONE) # ensure avdec_h264 wins
pipe = f"filesrc location={video_path} ! decodebin ! fakesink sync=false"
pipe = (f"filesrc location={video_path} ! decodebin "
f"! identity name=probe signal-handoffs=true ! fakesink sync=false")
results.append(_run_benchmark(
"SW fakesink (avdec_h264 → discard)",
video_path, pipe, is_appsink=False, Gst=Gst, GLib=GLib,
@@ -265,7 +276,8 @@ def main() -> None:
# 3. HW fakesink — pure MPP decode throughput
if mpp_ok:
_set_mpp_rank(MPP_RANK_HIGH) # prefer mppvideodec
pipe = f"filesrc location={video_path} ! decodebin ! fakesink sync=false"
pipe = (f"filesrc location={video_path} ! decodebin "
f"! identity name=probe signal-handoffs=true ! fakesink sync=false")
results.append(_run_benchmark(
"HW fakesink (mppvideodec → discard)",
video_path, pipe, is_appsink=False, Gst=Gst, GLib=GLib,
Binary file not shown.