Files
libva-v4l2-request-fourier/src/buffer.c
T
claude-noether e1aca9cc6b fresnel-fourier iter3 Phase 6 commit D: buffer.c whitelist for
VAProbabilityBufferType

Phase 2 source-read assumed buffer.c was type-agnostic ("the buffer
registry is type-agnostic" per phase2_iter3_situation.md non-bugs
list). FALSE. RequestCreateBuffer at buffer.c:59-70 has an explicit
allow-list switch:

  case VAPictureParameterBufferType:
  case VAIQMatrixBufferType:
  case VASliceParameterBufferType:
  case VASliceDataBufferType:
  case VAImageBufferType:
      break;
  default:
      return VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;

Without VAProbabilityBufferType in the allow-list, the consumer gets
VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE on vaCreateBuffer for the
probability buffer, BEFORE codec_store_buffer is ever reached.
ffmpeg-vaapi log:

  [vp8] Failed to create parameter buffer (type 13): 15
        (the requested VABufferType is not supported).

Same iter1 Commit D pattern: Phase 2 grep didn't find this, runtime
enumerated authoritatively. Per memory feedback_header_deletion_
check.md ("let the compiler enumerate them") — but extended here:
runtime enumerates allow-list violations the same way the compiler
enumerates include-site violations.

Fix: add `case VAProbabilityBufferType:` to the buffer.c allow-list.
+1 line, mechanical.

Refs:
  ../fresnel-fourier/phase2_iter3_situation.md (incorrect non-bug
                                                 claim about buffer.c)
  ../fresnel-fourier/phase4_iter3_plan.md (Commit D placeholder for
                                            fix-forward — used)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-08 23:03:59 +00:00

273 lines
7.4 KiB
C

/*
* Copyright (C) 2007 Intel Corporation
* Copyright (C) 2016 Florent Revest <florent.revest@free-electrons.com>
* Copyright (C) 2018 Paul Kocialkowski <paul.kocialkowski@bootlin.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sub license, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice (including the
* next paragraph) shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
* IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "buffer.h"
#include "context.h"
#include "request.h"
#include "surface.h"
#include "video.h"
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <va/va_drmcommon.h>
#include <linux/videodev2.h>
#include "utils.h"
#include "v4l2.h"
VAStatus RequestCreateBuffer(VADriverContextP context, VAContextID context_id,
VABufferType type, unsigned int size,
unsigned int count, void *data,
VABufferID *buffer_id)
{
struct request_data *driver_data = context->pDriverData;
struct object_buffer *buffer_object = NULL;
void *buffer_data;
VAStatus status;
VABufferID id;
switch (type) {
case VAPictureParameterBufferType:
case VAIQMatrixBufferType:
case VASliceParameterBufferType:
case VASliceDataBufferType:
case VAImageBufferType:
case VAProbabilityBufferType:
break;
default:
status = VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE;
goto error;
}
id = object_heap_allocate(&driver_data->buffer_heap);
buffer_object = BUFFER(driver_data, id);
if (buffer_object == NULL) {
status = VA_STATUS_ERROR_ALLOCATION_FAILED;
goto error;
}
buffer_data = malloc(size * count);
if (buffer_data == NULL) {
status = VA_STATUS_ERROR_ALLOCATION_FAILED;
goto error;
}
if (data != NULL)
memcpy(buffer_data, data, size * count);
buffer_object->type = type;
buffer_object->initial_count = count;
buffer_object->count = count;
buffer_object->data = buffer_data;
buffer_object->size = size;
buffer_object->derived_surface_id = VA_INVALID_ID;
buffer_object->info.handle = (uintptr_t) -1;
*buffer_id = id;
status = VA_STATUS_SUCCESS;
goto complete;
error:
if (buffer_object != NULL)
object_heap_free(&driver_data->buffer_heap,
(struct object_base *)buffer_object);
complete:
return status;
}
VAStatus RequestDestroyBuffer(VADriverContextP context, VABufferID buffer_id)
{
struct request_data *driver_data = context->pDriverData;
struct object_buffer *buffer_object;
buffer_object = BUFFER(driver_data, buffer_id);
if (buffer_object == NULL)
return VA_STATUS_ERROR_INVALID_BUFFER;
if (buffer_object->data != NULL)
free(buffer_object->data);
object_heap_free(&driver_data->buffer_heap,
(struct object_base *)buffer_object);
return VA_STATUS_SUCCESS;
}
VAStatus RequestMapBuffer(VADriverContextP context, VABufferID buffer_id,
void **data_map)
{
struct request_data *driver_data = context->pDriverData;
struct object_buffer *buffer_object;
buffer_object = BUFFER(driver_data, buffer_id);
if (buffer_object == NULL || buffer_object->data == NULL)
return VA_STATUS_ERROR_INVALID_BUFFER;
/* Our buffers are always mapped. */
*data_map = buffer_object->data;
return VA_STATUS_SUCCESS;
}
VAStatus RequestUnmapBuffer(VADriverContextP context, VABufferID buffer_id)
{
struct request_data *driver_data = context->pDriverData;
struct object_buffer *buffer_object;
buffer_object = BUFFER(driver_data, buffer_id);
if (buffer_object == NULL || buffer_object->data == NULL)
return VA_STATUS_ERROR_INVALID_BUFFER;
/* Our buffers are always mapped. */
return VA_STATUS_SUCCESS;
}
VAStatus RequestBufferSetNumElements(VADriverContextP context,
VABufferID buffer_id, unsigned int count)
{
struct request_data *driver_data = context->pDriverData;
struct object_buffer *buffer_object;
buffer_object = BUFFER(driver_data, buffer_id);
if (buffer_object == NULL)
return VA_STATUS_ERROR_INVALID_BUFFER;
if (count > buffer_object->initial_count)
return VA_STATUS_ERROR_INVALID_PARAMETER;
buffer_object->count = count;
return VA_STATUS_SUCCESS;
}
VAStatus RequestBufferInfo(VADriverContextP context, VABufferID buffer_id,
VABufferType *type, unsigned int *size,
unsigned int *count)
{
struct request_data *driver_data = context->pDriverData;
struct object_buffer *buffer_object;
buffer_object = BUFFER(driver_data, buffer_id);
if (buffer_object == NULL)
return VA_STATUS_ERROR_INVALID_BUFFER;
*type = buffer_object->type;
*size = buffer_object->size;
*count = buffer_object->count;
return VA_STATUS_SUCCESS;
}
VAStatus RequestAcquireBufferHandle(VADriverContextP context,
VABufferID buffer_id,
VABufferInfo *buffer_info)
{
struct request_data *driver_data = context->pDriverData;
struct object_buffer *buffer_object;
struct object_surface *surface_object;
struct video_format *video_format;
unsigned int capture_type;
int export_fd;
int rc;
video_format = driver_data->video_format;
if (video_format == NULL)
return VA_STATUS_ERROR_OPERATION_FAILED;
capture_type = v4l2_type_video_capture(video_format->v4l2_mplane);
if (buffer_info->mem_type != VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME ||
!video_format_is_linear(driver_data->video_format))
return VA_STATUS_ERROR_UNSUPPORTED_MEMORY_TYPE;
buffer_object = BUFFER(driver_data, buffer_id);
if (buffer_object == NULL || buffer_object->type != VAImageBufferType)
return VA_STATUS_ERROR_INVALID_BUFFER;
if (buffer_object->derived_surface_id == VA_INVALID_ID)
return VA_STATUS_ERROR_INVALID_BUFFER;
surface_object = SURFACE(driver_data, buffer_object->derived_surface_id);
if (surface_object == NULL)
return VA_STATUS_ERROR_INVALID_BUFFER;
if (surface_object->destination_buffers_count > 1)
return VA_STATUS_ERROR_OPERATION_FAILED;
rc = v4l2_export_buffer(driver_data->video_fd, capture_type,
surface_object->destination_index, O_RDONLY,
&export_fd, 1);
if (rc < 0)
return VA_STATUS_ERROR_OPERATION_FAILED;
buffer_info->handle = (uintptr_t) export_fd;
buffer_info->type = buffer_object->type;
buffer_info->mem_size = buffer_object->size * buffer_object->count;
buffer_object->info = *buffer_info;
return VA_STATUS_SUCCESS;
}
VAStatus RequestReleaseBufferHandle(VADriverContextP context,
VABufferID buffer_id)
{
struct request_data *driver_data = context->pDriverData;
struct object_buffer *buffer_object;
int export_fd;
buffer_object = BUFFER(driver_data, buffer_id);
if (buffer_object == NULL)
return VA_STATUS_ERROR_INVALID_BUFFER;
if (buffer_object->info.handle == (uintptr_t) -1)
return VA_STATUS_SUCCESS;
export_fd = (int) buffer_object->info.handle;
close(export_fd);
buffer_object->info.handle = (uintptr_t) -1;
return VA_STATUS_SUCCESS;
}