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 vas = vaDestroyBuffer(
ctx->hwctx->display,
148 if (vas != VA_STATUS_SUCCESS) {
150 "parameter buffer %#x: %d (%s).\n",
156 vas = vaDestroyBuffer(
ctx->hwctx->display,
158 if (vas != VA_STATUS_SUCCESS) {
160 "slice buffer %#x: %d (%s).\n",
181 vas = vaBeginPicture(
ctx->hwctx->display,
ctx->va_context,
183 if (vas != VA_STATUS_SUCCESS) {
185 "issue: %d (%s).\n", vas, vaErrorStr(vas));
187 goto fail_with_picture;
190 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
192 if (vas != VA_STATUS_SUCCESS) {
194 "parameters: %d (%s).\n", vas, vaErrorStr(vas));
196 goto fail_with_picture;
199 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
201 if (vas != VA_STATUS_SUCCESS) {
203 "%d (%s).\n", vas, vaErrorStr(vas));
205 goto fail_with_picture;
208 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
209 if (vas != VA_STATUS_SUCCESS) {
211 "issue: %d (%s).\n", vas, vaErrorStr(vas));
213 if (CONFIG_VAAPI_1 ||
ctx->hwctx->driver_quirks &
220 if (CONFIG_VAAPI_1 ||
ctx->hwctx->driver_quirks &
228 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
229 if (vas != VA_STATUS_SUCCESS) {
231 "after error: %d (%s).\n", vas, vaErrorStr(vas));
266#define MAP(va, av) { VA_FOURCC_ ## va, AV_PIX_FMT_ ## av }
312 MAP(I010, YUV420P10),
319 VAConfigID config_id,
324 VASurfaceAttrib *attr;
326 uint32_t best_fourcc,
fourcc;
332 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
334 if (vas != VA_STATUS_SUCCESS) {
336 "%d (%s).\n", vas, vaErrorStr(vas));
344 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
346 if (vas != VA_STATUS_SUCCESS) {
348 "%d (%s).\n", vas, vaErrorStr(vas));
355 for (
i = 0;
i < nb_attr;
i++) {
356 if (attr[
i].
type != VASurfaceAttribPixelFormat)
359 fourcc = attr[
i].value.value.i;
374 source_format, 0,
NULL);
375 if (
format == best_format)
390 frames->sw_format = best_format;
395 ctx->pixel_format_attribute = (VASurfaceAttrib) {
396 .type = VASurfaceAttribPixelFormat,
397 .flags = VA_SURFACE_ATTRIB_SETTABLE,
398 .value.type = VAGenericValueTypeInteger,
399 .value.value.i = best_fourcc,
415#define MAP(c, p, v, ...) { AV_CODEC_ID_ ## c, AV_PROFILE_ ## p, VAProfile ## v, __VA_ARGS__ }
416 MAP(MPEG2VIDEO, MPEG2_SIMPLE, MPEG2Simple ),
417 MAP(MPEG2VIDEO, MPEG2_MAIN, MPEG2Main ),
419 MAP(MPEG4, MPEG4_SIMPLE, MPEG4Simple ),
420 MAP(MPEG4, MPEG4_ADVANCED_SIMPLE,
421 MPEG4AdvancedSimple),
422 MAP(MPEG4, MPEG4_MAIN, MPEG4Main ),
423#if VA_CHECK_VERSION(1, 18, 0)
424 MAP(H264, H264_HIGH_10_INTRA,
426 MAP(H264, H264_HIGH_10, H264High10 ),
428 MAP(H264, H264_CONSTRAINED_BASELINE,
429 H264ConstrainedBaseline),
430 MAP(H264, H264_MAIN, H264Main ),
431 MAP(H264, H264_HIGH, H264High ),
432#if VA_CHECK_VERSION(0, 37, 0)
433 MAP(HEVC, HEVC_MAIN, HEVCMain ),
434 MAP(HEVC, HEVC_MAIN_10, HEVCMain10 ),
435 MAP(HEVC, HEVC_MAIN_STILL_PICTURE,
438#if VA_CHECK_VERSION(1, 2, 0) && CONFIG_HEVC_VAAPI_HWACCEL
439 MAP(HEVC, HEVC_REXT, None,
441 MAP(HEVC, HEVC_SCC, None,
444 MAP(MJPEG, MJPEG_HUFFMAN_BASELINE_DCT,
446 MAP(WMV3, VC1_SIMPLE, VC1Simple ),
447 MAP(WMV3, VC1_MAIN, VC1Main ),
448 MAP(WMV3, VC1_COMPLEX, VC1Advanced ),
449 MAP(WMV3, VC1_ADVANCED, VC1Advanced ),
450 MAP(VC1, VC1_SIMPLE, VC1Simple ),
451 MAP(VC1, VC1_MAIN, VC1Main ),
452 MAP(VC1, VC1_COMPLEX, VC1Advanced ),
453 MAP(VC1, VC1_ADVANCED, VC1Advanced ),
455#if VA_CHECK_VERSION(0, 38, 0)
456 MAP(VP9, VP9_0, VP9Profile0 ),
458#if VA_CHECK_VERSION(0, 39, 0)
459 MAP(VP9, VP9_1, VP9Profile1 ),
460 MAP(VP9, VP9_2, VP9Profile2 ),
461 MAP(VP9, VP9_3, VP9Profile3 ),
463#if VA_CHECK_VERSION(1, 8, 0)
464 MAP(AV1, AV1_MAIN, AV1Profile0),
465 MAP(AV1, AV1_HIGH, AV1Profile1),
467#if VA_CHECK_VERSION(1, 22, 0)
468 MAP(H266, VVC_MAIN_10, VVCMain10),
480 VAConfigID *va_config,
489 int profile_count, exact_match, matched_ff_profile,
codec_profile;
500 profile_count = vaMaxNumProfiles(hwctx->
display);
508 vas = vaQueryConfigProfiles(hwctx->
display,
509 profile_list, &profile_count);
510 if (vas != VA_STATUS_SUCCESS) {
512 "%d (%s).\n", vas, vaErrorStr(vas));
517 matched_va_profile = VAProfileNone;
521 int profile_match = 0;
533 for (j = 0; j < profile_count; j++) {
535 exact_match = profile_match;
539 if (j < profile_count) {
548 if (matched_va_profile == VAProfileNone) {
550 "profile %d.\n", codec_desc->
name, avctx->
profile);
558 "supported for hardware decode.\n",
561 "incompatible profile %d instead.\n",
565 "supported for hardware decode.\n",
572 vas = vaCreateConfig(hwctx->
display, matched_va_profile,
573 VAEntrypointVLD,
NULL, 0,
575 if (vas != VA_STATUS_SUCCESS) {
577 "configuration: %d (%s).\n", vas, vaErrorStr(vas));
601 "size %dx%d (constraints: width %d-%d height %d-%d).\n",
611 "usable surface formats.\n");
629 frames->initial_pool_size = 0;
631 frames->initial_pool_size = 1;
638 frames->initial_pool_size += 16;
641 frames->initial_pool_size += 8;
644 frames->initial_pool_size += 3;
647 frames->initial_pool_size += 2;
660 if (*va_config != VA_INVALID_ID) {
661 vaDestroyConfig(hwctx->
display, *va_config);
662 *va_config = VA_INVALID_ID;
674 VAConfigID va_config = VA_INVALID_ID;
679 hwctx = device_ctx->
hwctx;
686 if (va_config != VA_INVALID_ID)
687 vaDestroyConfig(hwctx->
display, va_config);
698 ctx->va_config = VA_INVALID_ID;
699 ctx->va_context = VA_INVALID_ID;
706 ctx->hwfc =
ctx->frames->hwctx;
707 ctx->device =
ctx->frames->device_ctx;
708 ctx->hwctx =
ctx->device->hwctx;
715 vas = vaCreateContext(
ctx->hwctx->display,
ctx->va_config,
718 ctx->hwfc->surface_ids,
719 ctx->hwfc->nb_surfaces,
721 if (vas != VA_STATUS_SUCCESS) {
723 "context: %d (%s).\n", vas, vaErrorStr(vas));
729 "%#x/%#x.\n",
ctx->va_config,
ctx->va_context);
743 if (
ctx->va_context != VA_INVALID_ID) {
744 vas = vaDestroyContext(
ctx->hwctx->display,
ctx->va_context);
745 if (vas != VA_STATUS_SUCCESS) {
747 "context %#x: %d (%s).\n",
748 ctx->va_context, vas, vaErrorStr(vas));
751 if (
ctx->va_config != VA_INVALID_ID) {
752 vas = vaDestroyConfig(
ctx->hwctx->display,
ctx->va_config);
753 if (vas != VA_STATUS_SUCCESS) {
755 "configuration %#x: %d (%s).\n",
756 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)
static int vaapi_decode_make_config(AVCodecContext *avctx, AVBufferRef *device_ref, VAConfigID *va_config, AVBufferRef *frames_ref)
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[]
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)
static void ff_vaapi_decode_destroy_buffers(AVCodecContext *avctx, VAAPIDecodePicture *pic)
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)