tests: fix benchmark pipelines (decodebin + rank steering, LD_PRELOAD note)

This commit is contained in:
Matteo Benedetto
2026-03-23 23:26:42 +01:00
parent 4a0275d145
commit 9ab0ec4f44
+22 -13
View File
@@ -224,17 +224,26 @@ def main() -> None:
size = os.path.getsize(video_path) size = os.path.getsize(video_path)
print(f" Using existing: {video_path} ({size // 1024}KB)") print(f" Using existing: {video_path} ({size // 1024}KB)")
def _set_mpp_rank(rank: int) -> None:
"""Temporarily set mppvideodec factory rank to steer decodebin selection."""
factory = reg.find_feature("mppvideodec", Gst.ElementFactory.__gtype__)
if factory:
factory.set_rank(rank)
# --- benchmark runs ----------------------------------------------------- # --- benchmark runs -----------------------------------------------------
_section("Benchmarks (sync=false, as fast as possible)") _section("Benchmarks (sync=false, as fast as possible)")
results = [] results = []
# Pipeline note: qtdemux has dynamic src pads so we use decodebin.
# decodebin rank manipulation steers it toward SW or HW decoder.
GST_RANK_NONE = 0
MPP_RANK_HIGH = 257 # above avdec_h264 (256)
# 1. SW fakesink — pure decode throughput # 1. SW fakesink — pure decode throughput
if av_ok: if av_ok:
pipe = ( _set_mpp_rank(GST_RANK_NONE) # ensure avdec_h264 wins
f"filesrc location={video_path} ! qtdemux ! h264parse " pipe = f"filesrc location={video_path} ! decodebin ! fakesink sync=false"
f"! avdec_h264 ! fakesink sync=false"
)
results.append(_run_benchmark( results.append(_run_benchmark(
"SW fakesink (avdec_h264 → discard)", "SW fakesink (avdec_h264 → discard)",
video_path, pipe, is_appsink=False, Gst=Gst, GLib=GLib, video_path, pipe, is_appsink=False, Gst=Gst, GLib=GLib,
@@ -242,10 +251,10 @@ def main() -> None:
# 2. SW appsink — full BGRA path (as used by app without HW decode) # 2. SW appsink — full BGRA path (as used by app without HW decode)
if av_ok: if av_ok:
_set_mpp_rank(GST_RANK_NONE)
pipe = ( pipe = (
f"filesrc location={video_path} ! qtdemux ! h264parse " f"filesrc location={video_path} ! decodebin "
f"! avdec_h264 ! videoconvert " f"! videoconvert ! video/x-raw,format=BGRA "
f"! video/x-raw,format=BGRA "
f"! appsink name=bench_sink" f"! appsink name=bench_sink"
) )
results.append(_run_benchmark( results.append(_run_benchmark(
@@ -255,10 +264,8 @@ def main() -> None:
# 3. HW fakesink — pure MPP decode throughput # 3. HW fakesink — pure MPP decode throughput
if mpp_ok: if mpp_ok:
pipe = ( _set_mpp_rank(MPP_RANK_HIGH) # prefer mppvideodec
f"filesrc location={video_path} ! qtdemux ! h264parse " pipe = f"filesrc location={video_path} ! decodebin ! fakesink sync=false"
f"! mppvideodec ! fakesink sync=false"
)
results.append(_run_benchmark( results.append(_run_benchmark(
"HW fakesink (mppvideodec → discard)", "HW fakesink (mppvideodec → discard)",
video_path, pipe, is_appsink=False, Gst=Gst, GLib=GLib, video_path, pipe, is_appsink=False, Gst=Gst, GLib=GLib,
@@ -266,9 +273,9 @@ def main() -> None:
# 4. HW appsink NV12 — full app path with HW + zero-copy SDL upload # 4. HW appsink NV12 — full app path with HW + zero-copy SDL upload
if mpp_ok: if mpp_ok:
_set_mpp_rank(MPP_RANK_HIGH)
pipe = ( pipe = (
f"filesrc location={video_path} ! qtdemux ! h264parse " f"filesrc location={video_path} ! decodebin "
f"! mppvideodec "
f"! appsink name=bench_sink caps=video/x-raw,format=NV12" f"! appsink name=bench_sink caps=video/x-raw,format=NV12"
) )
results.append(_run_benchmark( results.append(_run_benchmark(
@@ -276,6 +283,8 @@ def main() -> None:
video_path, pipe, is_appsink=True, Gst=Gst, GLib=GLib, video_path, pipe, is_appsink=True, Gst=Gst, GLib=GLib,
)) ))
_set_mpp_rank(64) # restore default marginal rank
# --- summary table ------------------------------------------------------- # --- summary table -------------------------------------------------------
_section("Results") _section("Results")
print(f" {'Path':<45} {'FPS':>6} {'CPU%':>5}") print(f" {'Path':<45} {'FPS':>6} {'CPU%':>5}")