fresnel-fourier iter5b-β Phase 6 commit C: β refactor — OUTPUT lifecycle to CreateContext + CRIT-1 + CRIT-2

Strip OUTPUT-side V4L2 device-format lifecycle out of
RequestCreateSurfaces2 entirely. Move S_FMT(OUTPUT), CAPTURE-format
probe, cap_pool_init, per-surface destination_* fill into
RequestCreateContext where config_id (and therefore the bound
VAProfile) is known via config_object->pixelformat (wired by
commit B). The α' multi-CreateSurfaces2-mid-stream failure mode
disappears because β has no in-CreateSurfaces2 teardown branch;
each context cycle does its own setup, DestroyContext handles
teardown.

Phase 5 v2 review amendments:
- CRIT-1: removed video_format==NULL early-return at context.c:64-66
  (would have rejected every first β CreateContext).
- CRIT-2: added request_pool_destroy() to DestroyContext before
  REQBUFS(0). Pre-β only surface.c's resolution-change branch
  called request_pool_destroy; β strips that, so DestroyContext
  becomes the sole per-session teardown site.
- IMP-1: probe CAPTURE format first to derive output_type from
  video_format->v4l2_mplane (eliminates the hardcoded mplane=true
  hack from the Phase 4 v2 plan).
- IMP-2: surface_reset_format_cache() deleted (function + declaration
  in surface.h + call in DestroyContext + last_output_{width,height}
  fields in request.h). All dead under β.

CreateSurfaces2 now ~50 LOC (was ~250). Pure surface ID allocation
+ per-surface lifecycle bookkeeping; no V4L2 device state touched.

Signed-off-by: claude-noether <claude-noether@reauktion.de>
This commit is contained in:
claude-noether
2026-05-12 14:41:35 +00:00
parent cc077a0c06
commit 7055b14f5e
4 changed files with 240 additions and 282 deletions
+204 -20
View File
@@ -54,26 +54,195 @@ VAStatus RequestCreateContext(VADriverContextP context, VAConfigID config_id,
struct request_data *driver_data = context->pDriverData;
struct object_config *config_object;
struct object_context *context_object = NULL;
struct object_surface *surface_object;
struct video_format *video_format;
unsigned int destination_sizes[VIDEO_MAX_PLANES];
unsigned int destination_bytesperlines[VIDEO_MAX_PLANES];
unsigned int destination_planes_count;
unsigned int format_width, format_height;
unsigned int pixelformat;
VASurfaceID *ids = NULL;
VAContextID id;
VAStatus status;
unsigned int output_type, capture_type;
unsigned int i, j;
bool found;
int rc;
video_format = driver_data->video_format;
if (video_format == NULL)
return VA_STATUS_ERROR_OPERATION_FAILED;
output_type = v4l2_type_video_output(video_format->v4l2_mplane);
capture_type = v4l2_type_video_capture(video_format->v4l2_mplane);
/*
* iter5b-β: CreateContext owns the V4L2 OUTPUT-side device-format
* lifecycle (S_FMT, CAPTURE-format probe, cap_pool_init, per-surface
* destination_* fill). Pre-β these lived in CreateSurfaces2 with a
* resolution-change gate; β moves them here because (a) config_id
* is known so the right OUTPUT pixel format can be derived from
* the bound profile, and (b) STREAMON happens at the end of this
* function, so the queue is never streaming when we do S_FMT.
*
* DestroyContext is the only per-session teardown site under β
* (no in-CreateSurfaces2 teardown branch). It STREAMOFFs both
* queues, calls request_pool_destroy + cap_pool_destroy, and
* REQBUFS(0) — leaving the V4L2 device in a clean slate for the
* next CreateContext.
*/
config_object = CONFIG(driver_data, config_id);
if (config_object == NULL) {
status = VA_STATUS_ERROR_INVALID_CONFIG;
goto error;
}
pixelformat = config_object->pixelformat;
if (pixelformat == 0) {
/*
* Defensive: CreateConfig rejects unhandled profiles, so
* pixelformat is always non-zero by the time we get here.
* Belt-and-suspenders.
*/
status = VA_STATUS_ERROR_UNSUPPORTED_PROFILE;
goto error;
}
/*
* Probe the CAPTURE-side V4L2 format. video_format is a static
* pointer into video.c's formats[]; it stays valid for the life of
* the driver_data and is cached across CreateContext cycles. The
* probe doesn't require any prior S_FMT — v4l2_find_format
* enumerates the device's supported formats directly.
*/
if (!driver_data->video_format) {
video_format = NULL;
found = v4l2_find_format(driver_data->video_fd,
V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_PIX_FMT_SUNXI_TILED_NV12);
if (found)
video_format = video_format_find(V4L2_PIX_FMT_SUNXI_TILED_NV12);
found = v4l2_find_format(driver_data->video_fd,
V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
V4L2_PIX_FMT_NV12);
if (found)
video_format = video_format_find(V4L2_PIX_FMT_NV12);
if (video_format == NULL) {
status = VA_STATUS_ERROR_OPERATION_FAILED;
goto error;
}
driver_data->video_format = video_format;
}
video_format = driver_data->video_format;
output_type = v4l2_type_video_output(video_format->v4l2_mplane);
capture_type = v4l2_type_video_capture(video_format->v4l2_mplane);
/*
* Commit the OUTPUT pixel format. picture_width/picture_height
* are the kernel-facing dimensions for this decode session. With
* profile-derived pixelformat, hantro's CAPTURE-format derivation
* dispatches to the right codec_mode (pre-β hardcoded H264_SLICE
* meant hantro silently substituted MPEG2_DECODER for HEVC/VP8/VP9
* → all-zero CAPTURE; rkvdec silently dropped HEVC/VP9 → same
* outcome).
*/
rc = v4l2_set_format(driver_data->video_fd, output_type, pixelformat,
picture_width, picture_height);
if (rc < 0) {
status = VA_STATUS_ERROR_OPERATION_FAILED;
goto error;
}
/*
* Query CAPTURE-side bytesperline/sizes after S_FMT(OUTPUT). On
* hantro the CAPTURE format derives from OUTPUT; G_FMT reflects
* that. Do NOT VIDIOC_S_FMT on CAPTURE — hantro reads the SPS
* from the OUTPUT request to set CAPTURE shape internally;
* explicitly setting CAPTURE puts the driver into an inconsistent
* state (GStreamer v4l2slh264dec only G_FMTs CAPTURE per
* gst-plugins-bad/sys/v4l2codecs/gstv4l2decoder.c::
* gst_v4l2_decoder_negotiate_src_format).
*/
rc = v4l2_get_format(driver_data->video_fd, capture_type, &format_width,
&format_height, destination_bytesperlines,
destination_sizes, NULL);
if (rc < 0) {
status = VA_STATUS_ERROR_OPERATION_FAILED;
goto error;
}
destination_planes_count = video_format->planes_count;
/*
* Initialize the CAPTURE buffer pool (cap_pool). Pool size =
* max(surfaces_count, MIN_CAP_POOL). The headroom gives LRU
* recycling enough margin to never reuse a buffer within the
* consumer's compositor-hold window for typical playback
* patterns. cap_pool_init does the V4L2 CREATE_BUFS + per-slot
* mmap.
*
* `pool->initialized` is reset to false by cap_pool_destroy in
* DestroyContext; subsequent CreateContext re-inits at the new
* resolution.
*/
if (!driver_data->capture_pool.initialized) {
unsigned int pool_count = surfaces_count > MIN_CAP_POOL ?
surfaces_count : MIN_CAP_POOL;
rc = cap_pool_init(&driver_data->capture_pool,
driver_data->video_fd, capture_type,
pool_count, video_format->v4l2_buffers_count);
if (rc < 0) {
status = VA_STATUS_ERROR_ALLOCATION_FAILED;
goto error;
}
}
/*
* Compute format-uniform destination_* values. Same for all
* surfaces of this format; written once per surface here, never
* changed by BeginPicture's slot acquisition.
*/
if (video_format->v4l2_buffers_count == 1) {
destination_sizes[0] = destination_bytesperlines[0] *
format_height;
for (j = 1; j < destination_planes_count; j++)
destination_sizes[j] = destination_sizes[0] / 2;
}
/*
* Walk surfaces_ids and populate the format-uniform fields on each
* object_surface. CreateSurfaces2 (β) left these zeroed.
*/
for (i = 0; i < (unsigned int)surfaces_count; i++) {
surface_object = SURFACE(driver_data, surfaces_ids[i]);
if (surface_object == NULL) {
status = VA_STATUS_ERROR_INVALID_SURFACE;
goto error;
}
surface_object->destination_planes_count = destination_planes_count;
surface_object->destination_buffers_count =
video_format->v4l2_buffers_count;
if (video_format->v4l2_buffers_count == 1) {
for (j = 0; j < destination_planes_count; j++) {
surface_object->destination_offsets[j] =
j > 0 ? destination_sizes[j - 1] : 0;
surface_object->destination_sizes[j] =
destination_sizes[j];
surface_object->destination_bytesperlines[j] =
destination_bytesperlines[0];
}
} else if (video_format->v4l2_buffers_count == destination_planes_count) {
for (j = 0; j < destination_planes_count; j++) {
surface_object->destination_offsets[j] = 0;
surface_object->destination_sizes[j] =
destination_sizes[j];
surface_object->destination_bytesperlines[j] =
destination_bytesperlines[j];
}
} else {
status = VA_STATUS_ERROR_ALLOCATION_FAILED;
goto error;
}
}
id = object_heap_allocate(&driver_data->context_heap);
context_object = CONTEXT(driver_data, id);
if (context_object == NULL) {
@@ -293,30 +462,45 @@ VAStatus RequestDestroyContext(VADriverContextP context, VAContextID context_id)
object_heap_free(&driver_data->context_heap,
(struct object_base *)context_object);
/*
* iter5b-β: tear down the OUTPUT pool (mmap unmaps) BEFORE
* REQBUFS(0) frees the kernel-side buffers. Pre-β this was done
* only by surface.c's resolution-change branch — which β removed.
* Without this here, the next CreateContext's request_pool_init
* sees pool->initialized=true with stale slot pointers, returns
* 0 without re-CREATE_BUFS, and the next QBUF EINVALs because
* the slots reference buffer indices that no longer exist
* (Phase 5 v2 review CRIT-2).
*/
if (driver_data->output_pool.initialized)
request_pool_destroy(&driver_data->output_pool);
rc = v4l2_request_buffers(driver_data->video_fd, output_type, 0);
if (rc < 0)
return VA_STATUS_ERROR_OPERATION_FAILED;
/*
* Iter2 Fix 3: cap_pool owns the CAPTURE buffers' mmaps + any
* outstanding our_export_fds. Tear it down (which also issues
* REQBUFS(0) on CAPTURE), so the next CreateSurfaces2 cycle sees
* a clean slate and rebuilds the pool at the new resolution.
* Iter2 Fix 3 (still relevant under β): cap_pool owns the
* CAPTURE buffers' mmaps + any outstanding our_export_fds. Tear
* it down (which also issues REQBUFS(0) on CAPTURE), so the next
* CreateContext cycle sees a clean slate.
*/
cap_pool_destroy(&driver_data->capture_pool, driver_data->video_fd,
capture_type);
/*
* Iteration 2 Fix 1: the kernel CAPTURE format state is no longer
* guaranteed after the dual REQBUFS(0). Invalidate the
* LAST_OUTPUT_WIDTH/HEIGHT cache so the next CreateSurfaces2 will
* unconditionally re-S_FMT on OUTPUT. Without this, multi-video
* Firefox sessions on mozilla.org corrupted the next session's
* CAPTURE format query (kernel returned 48x48 instead of the
* cached "already 1920x1088"); the exported descriptor encoded
* wrong pitch/offset.
* iter5b-β: driver_data->video_format is a static-ref pointer
* into video.c's formats[]; it stays valid for the life of the
* driver_data and intentionally survives DestroyContext cycles.
* The next CreateContext's `if (!driver_data->video_format)`
* guard skips the probe — correct, because the device's CAPTURE
* format menu doesn't change.
*
* The pre-β surface_reset_format_cache() call here is removed:
* β doesn't have a last_output_{width,height,pixelformat} cache
* (those fields are deleted). Each CreateContext is a fresh
* S_FMT(OUTPUT) cycle.
*/
surface_reset_format_cache(driver_data);
return VA_STATUS_SUCCESS;
}
+8 -16
View File
@@ -82,23 +82,15 @@ struct request_data {
struct cap_pool capture_pool;
/*
* Per-driver-data cache of the OUTPUT format we've set on the
* V4L2 device (iter5 Track E: was process-global static
* LAST_OUTPUT_WIDTH/HEIGHT, which would race when two libva
* driver_data instances share a process — e.g. Firefox playing
* one tab while Chromium plays another, or two mpv processes
* via the same dlopened backend). Kept per-driver_data because
* the V4L2 device fd is per-driver_data; one fd, one current
* format. Process-global was always wrong, just didn't surface
* until iter5's audit.
*
* See surface.c::CreateSurfaces2 for the consumer pattern (mpv
* probes with small surfaces then re-allocates at real
* resolution; we re-set the OUTPUT format whenever this pair
* changes).
* iter5b-β: the pre-β last_output_{width,height} cache fields
* and surface_reset_format_cache() helper are deleted. They
* existed because CreateSurfaces2 owned the OUTPUT-side V4L2
* device-format lifecycle and needed to gate re-S_FMT on
* resolution change. β moves that lifecycle to CreateContext,
* which is naturally one-shot per context cycle; no caching is
* required. DestroyContext + next CreateContext rebuild from
* scratch.
*/
unsigned int last_output_width;
unsigned int last_output_height;
};
VAStatus VA_DRIVER_INIT_FUNC(VADriverContextP context);
+28 -228
View File
@@ -48,36 +48,19 @@
#include "video.h"
/*
* Per-driver-data cache of the OUTPUT format we've set on the V4L2
* device. iter5 Track E: was process-global static
* LAST_OUTPUT_WIDTH/HEIGHT before this commit. See request.h
* struct request_data.last_output_width/height for the rationale.
*
* The previous SET_FORMAT_OF_OUTPUT_ONCE pattern was a latent bug
* (Sonnet Phase 5 review finding 7.3): mpv probes with small surfaces
* (e.g. 128x128) before requesting the real resolution (e.g.
* 1920x1088). The once-only set kept the OUTPUT — and consequently
* the kernel-derived CAPTURE — format pinned to the probe size.
* Subsequent v4l2_get_format on CAPTURE then returned the small
* format, the VADRMPRIMESurfaceDescriptor was filled with width=1920
* height=1088 but pitch=128 offset=16384, and Mesa rejected the
* import with "WSI pitch too small." That manifested as the
* solid-blue render in mpv vaapi mode and the SW fallback in Firefox
* after frame 0.
*
* Fix: track (width, height) per driver_data and re-set the OUTPUT
* format whenever the resolution changes. Re-setting requires
* REQBUFS(0) on both queues first because S_FMT after CREATE_BUFS is
* rejected by V4L2; we tear down and let the next allocation cycle
* recreate buffers at the new resolution.
* iter5b-β: the OUTPUT-side V4L2 device-format lifecycle moved out
* of this file. Pre-β CreateSurfaces2 owned the S_FMT(OUTPUT) +
* CAPTURE-format probe + cap_pool_init + per-surface destination_*
* fill; now that responsibility lives in context.c::RequestCreateContext
* where the bound config (and therefore the active VAProfile) is
* known via config_id. CreateSurfaces2 retains only surface object
* ID allocation and per-surface bookkeeping. The previous
* `surface_reset_format_cache` helper and `last_output_width/height`
* fields are deleted (β doesn't gate re-S_FMT on
* resolution — the lifecycle is CreateContext-centric and natural
* setup/teardown happens at each context cycle).
*/
void surface_reset_format_cache(struct request_data *driver_data)
{
driver_data->last_output_width = 0;
driver_data->last_output_height = 0;
}
/*
* Iter2 Fix 3 helpers — bind / unbind a cap_pool_slot to an
* object_surface. Called from BeginPicture (acquire+bind) and
@@ -141,190 +124,29 @@ VAStatus RequestCreateSurfaces2(VADriverContextP context, unsigned int format,
{
struct request_data *driver_data = context->pDriverData;
struct object_surface *surface_object;
struct video_format *video_format = NULL;
unsigned int destination_sizes[VIDEO_MAX_PLANES];
unsigned int destination_bytesperlines[VIDEO_MAX_PLANES];
unsigned int destination_planes_count;
unsigned int format_width, format_height;
unsigned int capture_type;
unsigned int i, j;
unsigned int i;
VASurfaceID id;
bool found;
int rc;
/*
* Set the OUTPUT format on (re)allocation when the resolution
* differs from the last set value. Without this, mpv's small
* probe surfaces (128x128) pin the CAPTURE format and the
* subsequent real-resolution surface ends up with wrong pitch
* in the export descriptor — causing Mesa to reject the
* DMA-BUF import. Detail in the LAST_OUTPUT_WIDTH/HEIGHT
* comment block at the top of this file.
* iter5b-β: only RT-format-level validation here. All V4L2
* device state (OUTPUT format, CAPTURE format probe,
* cap_pool_init, per-surface destination_* fill) is deferred
* to RequestCreateContext where the bound VAConfigID
* (and therefore the active VAProfile) is known. CreateSurfaces2
* has no config_id parameter; the VA-API contract is
* CreateConfig → CreateSurfaces → CreateContext, and we
* can't know the OUTPUT pixel format until CreateContext binds.
*
* TODO: this is still not a clean architecture — v4l2_set_format
* after CREATE_BUFS requires REQBUFS(0) first (kernel returns
* EBUSY otherwise). For mpv's pattern (probe with small, then
* allocate big) the small probe surfaces have not been streamed
* yet, so REQBUFS(0) on them works. For consumers that legitimately
* stream multiple resolutions in sequence, we'd need to STREAMOFF
* + REQBUFS(0) + new S_FMT + new CREATE_BUFS — that's a context-
* level redesign for the next iteration.
* Surface objects allocated here hold only the requested
* width/height and per-surface lifecycle bookkeeping
* (current_slot, status, params, etc). The format-uniform
* destination_* fields are filled by CreateContext via
* surface_bind_format_uniform_fields(); the per-slot
* destination_* fields fill at BeginPicture via surface_bind_slot.
*/
unsigned int pixelformat = V4L2_PIX_FMT_H264_SLICE;
unsigned int output_type = v4l2_type_video_output(true);
if (driver_data->last_output_width != width ||
driver_data->last_output_height != height) {
/*
* If we've previously allocated buffers at a different
* resolution, tear them down on BOTH queues before re-setting
* the OUTPUT format. S_FMT is rejected by V4L2 while buffers
* exist; hantro derives CAPTURE format from OUTPUT format, so
* leftover CAPTURE buffers from the prior resolution would
* also block the implicit format change. Sonnet Phase 5
* review (iter2 9.1) flagged this as a missing REQBUFS(0)
* gap on the CAPTURE side of the resolution-change path.
*
* Iter2 Fix 3 corollary: cap_pool owns the CAPTURE buffers'
* mmaps and slot states. Destroy it (which issues REQBUFS(0)
* on capture) before the format change so the next
* CreateSurfaces2 step can rebuild the pool at the new
* resolution. Without this, pool->initialized stays true,
* cap_pool_init below is skipped, and the slots' v4l2_index
* fields point to dead buffers from the prior resolution.
*/
if (driver_data->last_output_width != 0) {
if (driver_data->capture_pool.initialized)
cap_pool_destroy(&driver_data->capture_pool,
driver_data->video_fd,
v4l2_type_video_capture(true));
else
(void)v4l2_request_buffers(driver_data->video_fd,
v4l2_type_video_capture(true), 0);
/*
* iter7: tear down the OUTPUT pool too. Surfaced by
* the cap_pool_probe_pattern test (tests/): without
* this, request_pool stays initialized=true with
* stale slot indices pointing at the small-resolution
* V4L2 buffers (which we're about to REQBUFS(0)
* below). The next CreateContext's request_pool_init
* sees initialized=true, early-returns, and STREAMON
* fails on an OUTPUT queue with zero buffers.
*
* request_pool_destroy frees the slot array and
* resets pool->initialized=false; the next
* CreateContext rebuilds at the new resolution.
* Mirrors the cap_pool teardown above.
*/
if (driver_data->output_pool.initialized)
request_pool_destroy(&driver_data->output_pool);
(void)v4l2_request_buffers(driver_data->video_fd,
output_type, 0);
}
rc = v4l2_set_format(driver_data->video_fd, output_type, pixelformat,
width, height);
if (rc < 0)
return VA_STATUS_ERROR_OPERATION_FAILED;
driver_data->last_output_width = width;
driver_data->last_output_height = height;
}
if (format != VA_RT_FORMAT_YUV420)
return VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT;
if (!driver_data->video_format) {
found = v4l2_find_format(driver_data->video_fd,
V4L2_BUF_TYPE_VIDEO_CAPTURE,
V4L2_PIX_FMT_SUNXI_TILED_NV12);
if (found)
video_format = video_format_find(V4L2_PIX_FMT_SUNXI_TILED_NV12);
found = v4l2_find_format(driver_data->video_fd,
V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
V4L2_PIX_FMT_NV12);
if (found)
video_format = video_format_find(V4L2_PIX_FMT_NV12);
if (video_format == NULL)
return VA_STATUS_ERROR_OPERATION_FAILED;
driver_data->video_format = video_format;
capture_type = v4l2_type_video_capture(video_format->v4l2_mplane);
/*
* Do not VIDIOC_S_FMT on the CAPTURE queue. The hantro
* stateless decoder derives the CAPTURE format from the
* SPS attached to the OUTPUT request; explicitly setting
* it here can put the driver into an inconsistent state.
* GStreamer's v4l2slh264dec only G_FMTs CAPTURE (see
* gst-plugins-bad/sys/v4l2codecs/gstv4l2decoder.c::
* gst_v4l2_decoder_negotiate_src_format), and that
* variant produces correct decoded NV12 on the same
* hardware where this driver currently emits zeros.
*
* v4l2_get_format() below queries the driver's current
* state and gives us the bytesperline/sizes we need.
*/
} else {
video_format = driver_data->video_format;
capture_type = v4l2_type_video_capture(video_format->v4l2_mplane);
}
rc = v4l2_get_format(driver_data->video_fd, capture_type, &format_width,
&format_height, destination_bytesperlines,
destination_sizes, NULL);
if (rc < 0)
return VA_STATUS_ERROR_OPERATION_FAILED;
destination_planes_count = video_format->planes_count;
/*
* DEBUG INSTRUMENTATION (surface-export diagnosis 2026-05-04):
* dump what v4l2_get_format returned. Sonnet's Phase 5 review
* hypothesis #4 was that format_height might be 1080 (stream-
* signaled) vs 1088 (MB-aligned), causing UV offset to land
* 15360 bytes early. Earlier ftrace shows hantro returns
* height=1088 — but verify in-driver to be sure.
*/
/*
* Iter2 Fix 3: initialize the CAPTURE buffer pool on first call.
* Pool size = max(surfaces_count, MIN_CAP_POOL); the +headroom
* gives LRU recycling enough margin to never reuse a buffer
* within the consumer's compositor-hold window for typical
* playback patterns.
*
* If the pool already exists from a prior CreateSurfaces2 (e.g.
* mpv probe surfaces vs. real-resolution surfaces), it stays —
* but if the resolution changed (Fix 1's REQBUFS(0) on CAPTURE
* fired before this point), the pool was destroyed and we
* rebuild here.
*/
if (!driver_data->capture_pool.initialized) {
unsigned int pool_count = surfaces_count > MIN_CAP_POOL ?
surfaces_count : MIN_CAP_POOL;
rc = cap_pool_init(&driver_data->capture_pool,
driver_data->video_fd, capture_type,
pool_count, video_format->v4l2_buffers_count);
if (rc < 0)
return VA_STATUS_ERROR_ALLOCATION_FAILED;
}
/*
* Compute format-uniform destination_* values (sizes, offsets,
* bytesperlines, planes_count). These are the same for all
* surfaces of this format, set once per surface here, never
* changed by BeginPicture's slot acquisition.
*/
if (video_format->v4l2_buffers_count == 1) {
destination_sizes[0] = destination_bytesperlines[0] *
format_height;
for (j = 1; j < destination_planes_count; j++)
destination_sizes[j] = destination_sizes[0] / 2;
}
for (i = 0; i < surfaces_count; i++) {
id = object_heap_allocate(&driver_data->surface_heap);
surface_object = SURFACE(driver_data, id);
@@ -333,30 +155,8 @@ VAStatus RequestCreateSurfaces2(VADriverContextP context, unsigned int format,
surface_object->current_slot = NULL; /* iter2 Fix 3 */
surface_object->destination_index = 0; /* set on bind */
surface_object->destination_planes_count = destination_planes_count;
surface_object->destination_buffers_count =
video_format->v4l2_buffers_count;
if (video_format->v4l2_buffers_count == 1) {
for (j = 0; j < destination_planes_count; j++) {
surface_object->destination_offsets[j] =
j > 0 ? destination_sizes[j - 1] : 0;
surface_object->destination_sizes[j] =
destination_sizes[j];
surface_object->destination_bytesperlines[j] =
destination_bytesperlines[0];
}
} else if (video_format->v4l2_buffers_count == destination_planes_count) {
for (j = 0; j < destination_planes_count; j++) {
surface_object->destination_offsets[j] = 0;
surface_object->destination_sizes[j] =
destination_sizes[j];
surface_object->destination_bytesperlines[j] =
destination_bytesperlines[j];
}
} else {
return VA_STATUS_ERROR_ALLOCATION_FAILED;
}
surface_object->destination_planes_count = 0; /* set at CreateContext */
surface_object->destination_buffers_count = 0; /* set at CreateContext */
surface_object->status = VASurfaceReady;
surface_object->width = width;
-18
View File
@@ -165,24 +165,6 @@ VAStatus RequestExportSurfaceHandle(VADriverContextP context,
VASurfaceID surface_id, uint32_t mem_type,
uint32_t flags, void *descriptor);
/*
* Iteration 2 Fix 1: invalidate the LAST_OUTPUT_WIDTH/HEIGHT cache used
* by RequestCreateSurfaces2 to skip redundant v4l2_set_format calls.
*
* Must be called when the kernel's CAPTURE format state is no longer
* guaranteed to match what we last set on OUTPUT — at minimum, on
* RequestDestroyContext after REQBUFS(0). Without this, Firefox
* playing a multi-video page (mozilla.org with 864-wide intro
* videos at varying resolutions) corrupts the next session's CAPTURE
* format query: the cache says "already 1920x1088" while the kernel
* has reset to defaults, our subsequent G_FMT returns 48x48, and the
* exported descriptor encodes wrong pitch/offset.
*
* Iter5 Track E: cache lives per-driver_data (request_data.last_output_*),
* resolving the Sonnet review 7.3 / 9.6 multi-context race.
*/
void surface_reset_format_cache(struct request_data *driver_data);
/*
* Iter2 Fix 3: bind / unbind a CAPTURE-pool slot to an object_surface.
* Called from picture.c::RequestBeginPicture (acquire+bind) and