Eager CAPTURE format probe in RequestInit

Chromium's vaapi_video_decoder may call vaCreateContext with surfaces=NULL,
surfaces_count=0 and then create surfaces afterwards via vaCreateSurfaces2.
In that order driver_data->video_format is still NULL when CreateContext
runs and our early `video_format == NULL` guard returns OPERATION_FAILED.
Confirmed via temporary request_log() — Brave hits exactly that path on
ohm.

Move the probe out of RequestCreateSurfaces into a new
video_format_probe() helper in video.c, and call it eagerly from
RequestInit. RequestCreateSurfaces still re-probes if init came up NULL,
which preserves the original lazy behaviour for any caller that needs it.

Also small clean-up of surface.c since the probe block moved out: drop
the now-dead `bool found` local.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-25 22:03:38 +00:00
parent ac674b84ec
commit 0a3432ad64
4 changed files with 66 additions and 39 deletions
+14
View File
@@ -39,6 +39,7 @@
#include "request.h"
#include "utils.h"
#include "v4l2.h"
#include "video.h"
#include <assert.h>
#include <stdio.h>
@@ -179,6 +180,19 @@ VAStatus VA_DRIVER_INIT_FUNC(VADriverContextP context)
driver_data->video_fd = video_fd;
driver_data->media_fd = media_fd;
/* Probe the CAPTURE pixel format eagerly so vaCreateContext doesn't
* race ahead of vaCreateSurfaces. Fine if this returns NULL — we
* still let the driver init succeed and let surface creation try
* again later (preserves the original lazy behaviour for any caller
* that needs it). */
driver_data->video_format = video_format_probe(video_fd);
if (driver_data->video_format != NULL)
request_log("Init: detected CAPTURE format %s (mplane=%d)\n",
driver_data->video_format->description,
driver_data->video_format->v4l2_mplane);
else
request_log("Init: no CAPTURE format detected at probe time\n");
status = VA_STATUS_SUCCESS;
goto complete;