42 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
44 if (vas != VA_STATUS_SUCCESS) {
46 "buffer (type %d): %d (%s).\n",
47 type, vas, vaErrorStr(vas));
61 const void *params_data,
63 const void *slice_data,
88 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
89 VASliceParameterBufferType,
90 params_size, 1, (
void*)params_data,
92 if (vas != VA_STATUS_SUCCESS) {
94 "parameter buffer: %d (%s).\n", vas, vaErrorStr(vas));
102 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
103 VASliceDataBufferType,
104 slice_size, 1, (
void*)slice_data,
106 if (vas != VA_STATUS_SUCCESS) {
108 "data buffer (size %zu): %d (%s).\n",
109 slice_size, vas, vaErrorStr(vas));
110 vaDestroyBuffer(
ctx->hwctx->display,
131 vas = vaDestroyBuffer(
ctx->hwctx->display,
133 if (vas != VA_STATUS_SUCCESS) {
135 "parameter buffer %#x: %d (%s).\n",
141 vas = vaDestroyBuffer(
ctx->hwctx->display,
143 if (vas != VA_STATUS_SUCCESS) {
145 "slice buffer %#x: %d (%s).\n",
166 vas = vaBeginPicture(
ctx->hwctx->display,
ctx->va_context,
168 if (vas != VA_STATUS_SUCCESS) {
170 "issue: %d (%s).\n", vas, vaErrorStr(vas));
172 goto fail_with_picture;
175 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
177 if (vas != VA_STATUS_SUCCESS) {
179 "parameters: %d (%s).\n", vas, vaErrorStr(vas));
181 goto fail_with_picture;
184 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
186 if (vas != VA_STATUS_SUCCESS) {
188 "%d (%s).\n", vas, vaErrorStr(vas));
190 goto fail_with_picture;
193 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
194 if (vas != VA_STATUS_SUCCESS) {
196 "issue: %d (%s).\n", vas, vaErrorStr(vas));
213 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
214 if (vas != VA_STATUS_SUCCESS) {
216 "after error: %d (%s).\n", vas, vaErrorStr(vas));
243 static const struct {
247 #define MAP(va, av) { VA_FOURCC_ ## va, AV_PIX_FMT_ ## av }
254 #ifdef VA_FOURCC_I420
262 #ifdef VA_FOURCC_YV16
266 #ifdef VA_FOURCC_Y210
274 #ifdef VA_FOURCC_P010
277 #ifdef VA_FOURCC_I010
278 MAP(I010, YUV420P10),
285 VAConfigID config_id,
290 VASurfaceAttrib *attr;
292 uint32_t best_fourcc,
fourcc;
298 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
300 if (vas != VA_STATUS_SUCCESS) {
302 "%d (%s).\n", vas, vaErrorStr(vas));
310 vas = vaQuerySurfaceAttributes(hwctx->
display, config_id,
312 if (vas != VA_STATUS_SUCCESS) {
314 "%d (%s).\n", vas, vaErrorStr(vas));
321 for (
i = 0;
i < nb_attr;
i++) {
322 if (attr[
i].
type != VASurfaceAttribPixelFormat)
325 fourcc = attr[
i].value.value.i;
340 source_format, 0,
NULL);
341 if (
format == best_format)
356 frames->sw_format = best_format;
361 ctx->pixel_format_attribute = (VASurfaceAttrib) {
362 .type = VASurfaceAttribPixelFormat,
363 .value.value.i = best_fourcc,
373 static const struct {
379 #define MAP(c, p, v, ...) { AV_CODEC_ID_ ## c, FF_PROFILE_ ## p, VAProfile ## v, __VA_ARGS__ }
380 MAP(MPEG2VIDEO, MPEG2_SIMPLE, MPEG2Simple ),
381 MAP(MPEG2VIDEO, MPEG2_MAIN, MPEG2Main ),
383 MAP(MPEG4, MPEG4_SIMPLE, MPEG4Simple ),
384 MAP(MPEG4, MPEG4_ADVANCED_SIMPLE,
385 MPEG4AdvancedSimple),
386 MAP(MPEG4, MPEG4_MAIN, MPEG4Main ),
387 MAP(H264, H264_CONSTRAINED_BASELINE,
388 H264ConstrainedBaseline),
389 MAP(H264, H264_MAIN, H264Main ),
390 MAP(H264, H264_HIGH, H264High ),
391 #if VA_CHECK_VERSION(0, 37, 0)
392 MAP(HEVC, HEVC_MAIN, HEVCMain ),
393 MAP(HEVC, HEVC_MAIN_10, HEVCMain10 ),
394 MAP(HEVC, HEVC_MAIN_STILL_PICTURE,
397 #if VA_CHECK_VERSION(1, 2, 0) && CONFIG_HEVC_VAAPI_HWACCEL
398 MAP(HEVC, HEVC_REXT, None,
401 MAP(MJPEG, MJPEG_HUFFMAN_BASELINE_DCT,
403 MAP(WMV3, VC1_SIMPLE, VC1Simple ),
404 MAP(WMV3, VC1_MAIN, VC1Main ),
405 MAP(WMV3, VC1_COMPLEX, VC1Advanced ),
406 MAP(WMV3, VC1_ADVANCED, VC1Advanced ),
407 MAP(VC1, VC1_SIMPLE, VC1Simple ),
408 MAP(VC1, VC1_MAIN, VC1Main ),
409 MAP(VC1, VC1_COMPLEX, VC1Advanced ),
410 MAP(VC1, VC1_ADVANCED, VC1Advanced ),
412 #if VA_CHECK_VERSION(0, 38, 0)
413 MAP(VP9, VP9_0, VP9Profile0 ),
415 #if VA_CHECK_VERSION(0, 39, 0)
416 MAP(VP9, VP9_2, VP9Profile2 ),
418 #if VA_CHECK_VERSION(1, 8, 0)
419 MAP(AV1, AV1_MAIN, AV1Profile0),
420 MAP(AV1, AV1_HIGH, AV1Profile1),
432 VAConfigID *va_config,
441 int profile_count, exact_match, matched_ff_profile,
codec_profile;
452 profile_count = vaMaxNumProfiles(hwctx->display);
460 vas = vaQueryConfigProfiles(hwctx->display,
461 profile_list, &profile_count);
462 if (vas != VA_STATUS_SUCCESS) {
464 "%d (%s).\n", vas, vaErrorStr(vas));
469 matched_va_profile = VAProfileNone;
473 int profile_match = 0;
485 for (j = 0; j < profile_count; j++) {
487 exact_match = profile_match;
491 if (j < profile_count) {
500 if (matched_va_profile == VAProfileNone) {
502 "profile %d.\n", codec_desc->
name, avctx->
profile);
510 "supported for hardware decode.\n",
513 "incompatible profile %d instead.\n",
517 "supported for hardware decode.\n",
524 vas = vaCreateConfig(hwctx->display, matched_va_profile,
525 VAEntrypointVLD,
NULL, 0,
527 if (vas != VA_STATUS_SUCCESS) {
529 "configuration: %d (%s).\n", vas, vaErrorStr(vas));
553 "size %dx%d (constraints: width %d-%d height %d-%d).\n",
563 "usable surface formats.\n");
580 frames->initial_pool_size = 1;
586 frames->initial_pool_size += 16;
589 frames->initial_pool_size += 8;
592 frames->initial_pool_size += 3;
595 frames->initial_pool_size += 2;
607 if (*va_config != VA_INVALID_ID) {
608 vaDestroyConfig(hwctx->display, *va_config);
609 *va_config = VA_INVALID_ID;
621 VAConfigID va_config = VA_INVALID_ID;
626 hwctx = device_ctx->hwctx;
633 if (va_config != VA_INVALID_ID)
634 vaDestroyConfig(hwctx->display, va_config);
645 ctx->va_config = VA_INVALID_ID;
646 ctx->va_context = VA_INVALID_ID;
648 #if FF_API_STRUCT_VAAPI_CONTEXT
651 "vaapi_context in decode.\n");
653 ctx->have_old_context = 1;
661 if (!
ctx->device_ref) {
666 ctx->hwctx =
ctx->device->hwctx;
668 ctx->hwctx->display =
ctx->old_context->display;
672 ctx->hwctx->driver_quirks =
678 #if FF_API_STRUCT_VAAPI_CONTEXT
679 if (
ctx->have_old_context) {
680 ctx->va_config =
ctx->old_context->config_id;
681 ctx->va_context =
ctx->old_context->context_id;
684 "context: %#x/%#x.\n",
ctx->va_config,
ctx->va_context);
693 ctx->hwfc =
ctx->frames->hwctx;
694 ctx->device =
ctx->frames->device_ctx;
695 ctx->hwctx =
ctx->device->hwctx;
702 vas = vaCreateContext(
ctx->hwctx->display,
ctx->va_config,
705 ctx->hwfc->surface_ids,
706 ctx->hwfc->nb_surfaces,
708 if (vas != VA_STATUS_SUCCESS) {
710 "context: %d (%s).\n", vas, vaErrorStr(vas));
716 "%#x/%#x.\n",
ctx->va_config,
ctx->va_context);
717 #if FF_API_STRUCT_VAAPI_CONTEXT
733 #if FF_API_STRUCT_VAAPI_CONTEXT
734 if (
ctx->have_old_context) {
739 if (
ctx->va_context != VA_INVALID_ID) {
740 vas = vaDestroyContext(
ctx->hwctx->display,
ctx->va_context);
741 if (vas != VA_STATUS_SUCCESS) {
743 "context %#x: %d (%s).\n",
744 ctx->va_context, vas, vaErrorStr(vas));
747 if (
ctx->va_config != VA_INVALID_ID) {
748 vas = vaDestroyConfig(
ctx->hwctx->display,
ctx->va_config);
749 if (vas != VA_STATUS_SUCCESS) {
751 "configuration %#x: %d (%s).\n",
752 ctx->va_config, vas, vaErrorStr(vas));
756 #if FF_API_STRUCT_VAAPI_CONTEXT
static const char *const format[]
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 FF_PROFILE_UNKNOWN
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.
AVCodecID
Identify the syntax and semantics of the bitstream.
const AVCodecDescriptor * avcodec_descriptor_get(enum AVCodecID id)
#define AV_HWACCEL_FLAG_ALLOW_PROFILE_MISMATCH
Hardware acceleration should still be attempted for decoding when the codec profile does not match th...
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
#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)
Allocate, reallocate, or free an array.
AVBufferRef * av_hwdevice_ctx_alloc(enum AVHWDeviceType type)
Allocate an AVHWDeviceContext for a given hardware type.
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
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.
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.
AVPixelFormat
Pixel format.
#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.
void * hwaccel_context
Hardware accelerator context.
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.
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 * slice_buffers
VABufferID param_buffers[MAX_PARAM_BUFFERS]
VASurfaceID output_surface
#define av_malloc_array(a, b)
int ff_vaapi_decode_make_slice_buffer(AVCodecContext *avctx, VAAPIDecodePicture *pic, const void *params_data, size_t params_size, const void *slice_data, size_t slice_size)
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)
enum AVPixelFormat pix_fmt
int ff_vaapi_common_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx)
int ff_vaapi_decode_issue(AVCodecContext *avctx, VAAPIDecodePicture *pic)
VAProfile(* profile_parser)(AVCodecContext *avctx)
static const struct @149 vaapi_format_map[]
int ff_vaapi_decode_init(AVCodecContext *avctx)
static const struct @150 vaapi_profile_map[]
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)
VAProfile ff_vaapi_parse_hevc_rext_profile(AVCodecContext *avctx)