Skip to content

VAAPI interop: accept VA surface ID 0 - #1532

Merged
kmdewaal merged 1 commit into
MythTV:masterfrom
rosenbergj:vaapi-surface-zero
Nov 2, 2026
Merged

kmdewaal merged 1 commit into
MythTV:masterfrom
rosenbergj:vaapi-surface-zero

Conversation

@rosenbergj

@rosenbergj rosenbergj commented Nov 2, 2026 •

Copy link
Copy Markdown

MythVAAPIInterop::VerifySurface() rejected a frame whose m_buffer was null and also returned 0 to signal failure. m_buffer holds the VASurfaceID cast to a pointer, and 0 is a valid surface ID: the Intel iHD driver issues it to the first surface created.

FFmpeg preallocates the hardware frame pool in order and returns the frames to its LIFO free list in the same order, so surface 0 sits at the bottom of the list. It is handed out only when every surface is in use at once. When that happens, it stays in rotation and every frame decoded into it is silently dropped. The previous image is held for one extra frame, roughly every 12-15 frames (about 0.4 s for 1080i). With the VAAPI deinterlacer, the gap in frame numbers also triggers the discontinuity check, so the deinterlacer is destroyed and recreated every cycle.

Use VA_INVALID_SURFACE as the failure value instead of 0, and stop treating a null m_buffer as an invalid VAAPI frame. Also use VA_INVALID_SURFACE for the "no last filtered frame" state in the deinterlacer, so a filtered surface with ID 0 is handled the same way.

Fixes #1530

Testing

  • Build: master 33ecf7b plus this commit, on Ubuntu 24.04 with GCC 13.3, Qt 5.15 and the qt5 CMake preset (Debug), with VAAPI (DRM, GLX, X11) and EGL enabled. libmythtv and mythfrontend compile and link. The three changed files produce no warnings under the project's flags (-Wall -Wextra -Wshadow -Wnull-dereference and others).
  • Runtime: I have not run this build. My frontend is on v36 packages (Ubuntu 26.04, iHD 26.1.2), and as a stopgap it uses an LD_PRELOAD shim. The shim keeps surface 0 out of the pool by holding it and giving the pool a different surface, so VerifySurface() never sees ID 0. That tests the diagnosis, not this patch.
  • Results so far: with the shim, about 1 h 45 min of 1080i playback with 0 "Using existing framebuffer" pairs. Without it, the same setup logged 2,759 pairs in one afternoon session and 108 in an evening session. That's one evening, so not conclusive, as episodes can be hours apart.

Original Template

Thank you for contributing to MythTV!

Please review the checklist below to ensure that your contribution
to MythTV is ready for review by our developers.

It is helpful to regularly rebase your pull request to ensure changes
apply cleanly to the current MythTV development branch.

Checklist

MythVAAPIInterop::VerifySurface() rejected a frame whose m_buffer was
null and also returned 0 to signal failure. m_buffer holds the
VASurfaceID cast to a pointer, and 0 is a valid surface ID: the Intel
iHD driver issues it to the first surface created.

FFmpeg preallocates the hardware frame pool in order and returns the
frames to its LIFO free list in the same order, so surface 0 sits at the
bottom of the list. It is handed out only when every surface is in use
at once. When that happens, it stays in rotation and every frame decoded
into it is silently dropped. The previous image is held for one extra
frame, roughly every 12-15 frames (about 0.4 s for 1080i). With the VAAPI
deinterlacer, the gap in frame numbers also triggers the discontinuity
check, so the deinterlacer is destroyed and recreated every cycle.

Use VA_INVALID_SURFACE as the failure value instead of 0, and stop
treating a null m_buffer as an invalid VAAPI frame. Also use
VA_INVALID_SURFACE for the "no last filtered frame" state in the
deinterlacer, so a filtered surface with ID 0 is handled the same way.

Fixes MythTV#1530

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@kmdewaal kmdewaal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@kmdewaal
kmdewaal merged commit 417fafc into MythTV:master Nov 2, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

VAAPI: periodic frame skips / deinterlacer rebuilt every 0.4 s, possibly VA surface ID 0 rejected as null

2 participants