19#include "config_components.h"
57 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
60 if (vas != VA_STATUS_SUCCESS) {
62 "buffer (type %d): %d (%s).\n",
63 type, vas, vaErrorStr(vas));
77 const void *params_data,
80 const void *slice_data,
103 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
104 VASliceParameterBufferType,
105 params_size, nb_params, (
void*)params_data,
107 if (vas != VA_STATUS_SUCCESS) {
109 "parameter buffer: %d (%s).\n", vas, vaErrorStr(vas));
114 "is %#x.\n", pic->
nb_slices, params_size,
117 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
118 VASliceDataBufferType,
119 slice_size, 1, (
void*)slice_data,
121 if (vas != VA_STATUS_SUCCESS) {
123 "data buffer (size %zu): %d (%s).\n",
124 slice_size, vas, vaErrorStr(vas));
125 vaDestroyBuffer(
ctx->hwctx->display,
146 if (vas != VA_STATUS_SUCCESS) {
148 "parameter buffer %#x: %d (%s).\n",
155 if (vas != VA_STATUS_SUCCESS) {
157 "slice buffer %#x: %d (%s).\n",
191 vas = vaBeginPicture(
ctx->hwctx->display,
ctx->va_context,
193 if (vas != VA_STATUS_SUCCESS) {
195 "issue: %d (%s).\n", vas, vaErrorStr(vas));
197 goto fail_with_picture;
200 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
202 if (vas != VA_STATUS_SUCCESS) {
204 "parameters: %d (%s).\n", vas, vaErrorStr(vas));
206 goto fail_with_picture;
209 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
211 if (vas != VA_STATUS_SUCCESS) {
213 "%d (%s).\n", vas, vaErrorStr(vas));
215 goto fail_with_picture;
218 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
219 if (vas != VA_STATUS_SUCCESS) {
221 "issue: %d (%s).\n", vas, vaErrorStr(vas));
223 if (CONFIG_VAAPI_1 ||
ctx->hwctx->driver_quirks &
230 if (CONFIG_VAAPI_1 ||
ctx->hwctx->driver_quirks &
238 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
239 if (vas != VA_STATUS_SUCCESS) {
241 "after error: %d (%s).\n", vas, vaErrorStr(vas));
279#define MAP(va, av) { VA_FOURCC_ ## va, AV_PIX_FMT_ ## av }
325 MAP(I010, YUV420P10),
332 VAConfigID config_id,
337 VASurfaceAttrib *attr;
339 uint32_t best_fourcc,
fourcc;
345 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
347 if (vas != VA_STATUS_SUCCESS) {
349 "%d (%s).\n", vas, vaErrorStr(vas));
357 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
359 if (vas != VA_STATUS_SUCCESS) {
361 "%d (%s).\n", vas, vaErrorStr(vas));
368 for (
i = 0;
i < nb_attr;
i++) {
369 if (attr[
i].
type != VASurfaceAttribPixelFormat)
372 fourcc = attr[
i].value.value.i;
387 source_format, 0,
NULL);
388 if (
format == best_format)
403 frames->sw_format = best_format;
408 ctx->pixel_format_attribute = (VASurfaceAttrib) {
409 .type = VASurfaceAttribPixelFormat,
410 .flags = VA_SURFACE_ATTRIB_SETTABLE,
411 .value.type = VAGenericValueTypeInteger,
412 .value.value.i = best_fourcc,
428#define MAP(c, p, v, ...) { AV_CODEC_ID_ ## c, AV_PROFILE_ ## p, VAProfile ## v, __VA_ARGS__ }
429 MAP(MPEG2VIDEO, MPEG2_SIMPLE, MPEG2Simple ),
430 MAP(MPEG2VIDEO, MPEG2_MAIN, MPEG2Main ),
432 MAP(MPEG4, MPEG4_SIMPLE, MPEG4Simple ),
433 MAP(MPEG4, MPEG4_ADVANCED_SIMPLE,
434 MPEG4AdvancedSimple),
435 MAP(MPEG4, MPEG4_MAIN, MPEG4Main ),
436#if VA_CHECK_VERSION(1, 18, 0)
437 MAP(H264, H264_HIGH_10_INTRA,
439 MAP(H264, H264_HIGH_10, H264High10 ),
441 MAP(H264, H264_CONSTRAINED_BASELINE,
442 H264ConstrainedBaseline),
443 MAP(H264, H264_MAIN, H264Main ),
444 MAP(H264, H264_HIGH, H264High ),
445#if VA_CHECK_VERSION(0, 37, 0)
446 MAP(HEVC, HEVC_MAIN, HEVCMain ),
447 MAP(HEVC, HEVC_MAIN_10, HEVCMain10 ),
448 MAP(HEVC, HEVC_MAIN_STILL_PICTURE,
451#if VA_CHECK_VERSION(1, 2, 0) && CONFIG_HEVC_VAAPI_HWACCEL
452 MAP(HEVC, HEVC_REXT, None,
454 MAP(HEVC, HEVC_SCC, None,
457 MAP(MJPEG, MJPEG_HUFFMAN_BASELINE_DCT,
459 MAP(WMV3, VC1_SIMPLE, VC1Simple ),
460 MAP(WMV3, VC1_MAIN, VC1Main ),
461 MAP(WMV3, VC1_COMPLEX, VC1Advanced ),
462 MAP(WMV3, VC1_ADVANCED, VC1Advanced ),
463 MAP(VC1, VC1_SIMPLE, VC1Simple ),
464 MAP(VC1, VC1_MAIN, VC1Main ),
465 MAP(VC1, VC1_COMPLEX, VC1Advanced ),
466 MAP(VC1, VC1_ADVANCED, VC1Advanced ),
468#if VA_CHECK_VERSION(0, 38, 0)
469 MAP(VP9, VP9_0, VP9Profile0 ),
471#if VA_CHECK_VERSION(0, 39, 0)
472 MAP(VP9, VP9_1, VP9Profile1 ),
473 MAP(VP9, VP9_2, VP9Profile2 ),
474 MAP(VP9, VP9_3, VP9Profile3 ),
476#if VA_CHECK_VERSION(1, 8, 0)
477 MAP(AV1, AV1_MAIN, AV1Profile0),
478 MAP(AV1, AV1_HIGH, AV1Profile1),
480#if VA_CHECK_VERSION(1, 22, 0)
481 MAP(H266, VVC_MAIN_10, VVCMain10),
493 VAConfigID *va_config,
502 int profile_count, exact_match, matched_ff_profile,
codec_profile;
513 profile_count = vaMaxNumProfiles(hwctx->
display);
521 vas = vaQueryConfigProfiles(hwctx->
display,
522 profile_list, &profile_count);
523 if (vas != VA_STATUS_SUCCESS) {
525 "%d (%s).\n", vas, vaErrorStr(vas));
530 matched_va_profile = VAProfileNone;
534 int profile_match = 0;
546 for (j = 0; j < profile_count; j++) {
548 exact_match = profile_match;
552 if (j < profile_count) {
561 if (matched_va_profile == VAProfileNone) {
563 "profile %d.\n", codec_desc->
name, avctx->
profile);
571 "supported for hardware decode.\n",
574 "incompatible profile %d instead.\n",
578 "supported for hardware decode.\n",
585 vas = vaCreateConfig(hwctx->
display, matched_va_profile,
586 VAEntrypointVLD,
NULL, 0,
588 if (vas != VA_STATUS_SUCCESS) {
590 "configuration: %d (%s).\n", vas, vaErrorStr(vas));
614 "size %dx%d (constraints: width %d-%d height %d-%d).\n",
624 "usable surface formats.\n");
642 frames->initial_pool_size = 0;
644 frames->initial_pool_size = 1;
651 frames->initial_pool_size += 16;
654 frames->initial_pool_size += 8;
657 frames->initial_pool_size += 3;
660 frames->initial_pool_size += 2;
673 if (*va_config != VA_INVALID_ID) {
674 vaDestroyConfig(hwctx->
display, *va_config);
675 *va_config = VA_INVALID_ID;
687 VAConfigID va_config = VA_INVALID_ID;
692 hwctx = device_ctx->
hwctx;
699 if (va_config != VA_INVALID_ID)
700 vaDestroyConfig(hwctx->
display, va_config);
711 ctx->va_config = VA_INVALID_ID;
712 ctx->va_context = VA_INVALID_ID;
719 ctx->hwfc =
ctx->frames->hwctx;
720 ctx->device =
ctx->frames->device_ctx;
721 ctx->hwctx =
ctx->device->hwctx;
728 vas = vaCreateContext(
ctx->hwctx->display,
ctx->va_config,
731 ctx->hwfc->surface_ids,
732 ctx->hwfc->nb_surfaces,
734 if (vas != VA_STATUS_SUCCESS) {
736 "context: %d (%s).\n", vas, vaErrorStr(vas));
742 "%#x/%#x.\n",
ctx->va_config,
ctx->va_context);
756 if (
ctx->va_context != VA_INVALID_ID) {
757 vas = vaDestroyContext(
ctx->hwctx->display,
ctx->va_context);
758 if (vas != VA_STATUS_SUCCESS) {
760 "context %#x: %d (%s).\n",
761 ctx->va_context, vas, vaErrorStr(vas));
764 if (
ctx->va_config != VA_INVALID_ID) {
765 vas = vaDestroyConfig(
ctx->hwctx->display,
ctx->va_config);
766 if (vas != VA_STATUS_SUCCESS) {
768 "configuration %#x: %d (%s).\n",
769 ctx->va_config, vas, vaErrorStr(vas));
static const char *const format[]
static AVFormatContext * ctx
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define i(width, name, range_min, range_max)
common internal and external API header
int ff_decode_get_hw_frames_ctx(AVCodecContext *avctx, enum AVHWDeviceType dev_type)
Make sure avctx.hw_frames_ctx is set.
#define AV_PROFILE_UNKNOWN
static enum AVPixelFormat pix_fmt
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
AVCodecID
Identify the syntax and semantics of the bitstream.
#define AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH
Hardware acceleration should still be attempted for decoding when the codec profile does not match th...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_VERBOSE
Detailed information.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
void av_hwframe_constraints_free(AVHWFramesConstraints **constraints)
Free an AVHWFrameConstraints structure.
AVHWFramesConstraints * av_hwdevice_get_hwframe_constraints(AVBufferRef *ref, const void *hwconfig)
Get the constraints on HW frames given a device and the HW-specific configuration to be used with tha...
void * av_hwdevice_hwconfig_alloc(AVBufferRef *ref)
Allocate a HW-specific configuration structure for a given HW device.
@ AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS
The driver does not destroy parameter buffers when they are used by vaRenderPicture().
common internal api header.
Memory handling functions.
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
enum AVPixelFormat av_find_best_pix_fmt_of_2(enum AVPixelFormat dst_pix_fmt1, enum AVPixelFormat dst_pix_fmt2, enum AVPixelFormat src_pix_fmt, int has_alpha, int *loss_ptr)
Compute what kind of losses will occur when converting from one specific pixel format to another.
AVPixelFormat
Pixel format.
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
uint8_t * data
The data buffer.
main external API structure.
int hwaccel_flags
Bit set of AV_HWACCEL_FLAG_* flags, which affect hardware accelerated decoding (if active).
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
int coded_width
Bitstream width / height, may be different from width/height e.g.
struct AVCodecInternal * internal
Private context used for internal data.
This struct describes the properties of a single codec described by an AVCodecID.
const char * name
Name of the codec described by this descriptor.
void * hwaccel_priv_data
hwaccel-specific private data
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
int max_width
The maximum size of frames in this hw_frames_ctx.
enum AVPixelFormat * valid_sw_formats
A list of possible values for sw_format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
int min_width
The minimum size of frames in this hw_frames_ctx.
This struct describes a set or pool of "hardware" frames (i.e.
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext.
VAAPI connection details.
VADisplay display
The VADisplay handle, to be filled by the user.
VAAPI-specific data associated with a frame pool.
VASurfaceAttrib * attributes
Set by the user to apply surface attributes to all surfaces in the frame pool.
VAAPI hardware pipeline configuration details.
VAConfigID config_id
ID of a VAAPI pipeline configuration.
VABufferID * param_buffers
int nb_slice_buffers_allocated
VABufferID * slice_buffers
int nb_param_buffers_allocated
VASurfaceID output_surface
#define av_malloc_array(a, b)
RefStruct is an API for creating reference-counted objects with minimal overhead.
static int vaapi_decode_make_config(AVCodecContext *avctx, AVBufferRef *device_ref, VAConfigID *va_config, AVBufferRef *frames_ref)
static void ff_vaapi_decode_destroy_buffers(void *logctx, VADisplay display, VAAPIDecodePicture *pic)
int ff_vaapi_decode_make_param_buffer(AVCodecContext *avctx, VAAPIDecodePicture *pic, int type, const void *data, size_t size)
static const struct @255370265033273361374341050074042335024152335074 vaapi_profile_map[]
static void vaapi_decode_free_buffers(void *logctx, VADisplay display, VAAPIDecodePicture *pic)
int ff_vaapi_common_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
static const struct @375310172260344333305017135226063207373101217274 vaapi_format_map[]
int ff_vaapi_decode_issue(AVCodecContext *avctx, VAAPIDecodePicture *pic)
VAProfile(* profile_parser)(AVCodecContext *avctx)
int ff_vaapi_decode_init(AVCodecContext *avctx)
int ff_vaapi_decode_uninit(AVCodecContext *avctx)
static int vaapi_decode_find_best_format(AVCodecContext *avctx, AVHWDeviceContext *device, VAConfigID config_id, AVHWFramesContext *frames)
int ff_vaapi_decode_cancel(AVCodecContext *avctx, VAAPIDecodePicture *pic)
void ff_vaapi_decode_free_frame_priv(AVRefStructOpaque hwctx, void *data)
int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx, VAAPIDecodePicture *pic, const void *params_data, int nb_params, size_t params_size, const void *slice_data, size_t slice_size)
VAProfile ff_vaapi_parse_hevc_rext_scc_profile(AVCodecContext *avctx)