48 for (
i = 0;
i <
ctx->nb_filter_buffers;
i++) {
49 if (
ctx->filter_buffers[
i] != VA_INVALID_ID) {
50 vaDestroyBuffer(
ctx->hwctx->display,
ctx->filter_buffers[
i]);
51 ctx->filter_buffers[
i] = VA_INVALID_ID;
54 ctx->nb_filter_buffers = 0;
56 if (
ctx->va_context != VA_INVALID_ID) {
57 vaDestroyContext(
ctx->hwctx->display,
ctx->va_context);
58 ctx->va_context = VA_INVALID_ID;
61 if (
ctx->va_config != VA_INVALID_ID) {
62 vaDestroyConfig(
ctx->hwctx->display,
ctx->va_config);
63 ctx->va_config = VA_INVALID_ID;
75 if (
ctx->pipeline_uninit)
76 ctx->pipeline_uninit(avctx);
80 "required to associate the processing device.\n");
85 if (!
ctx->input_frames_ref) {
106 if (
ctx->pipeline_uninit)
107 ctx->pipeline_uninit(avctx);
109 if (!
ctx->output_width)
111 if (!
ctx->output_height)
116 if (!
ctx->device_ref) {
124 vas = vaCreateConfig(
ctx->hwctx->display, VAProfileNone,
125 VAEntrypointVideoProc,
NULL, 0, &
ctx->va_config);
126 if (vas != VA_STATUS_SUCCESS) {
128 "config: %d (%s).\n", vas, vaErrorStr(vas));
148 ctx->output_format =
ctx->input_frames->sw_format;
167 "size %dx%d (constraints: width %d-%d height %d-%d).\n",
168 ctx->output_width,
ctx->output_height,
187 output_frames->
width =
ctx->output_width;
188 output_frames->
height =
ctx->output_height;
199 "context for output: %d\n", err);
203 va_frames = output_frames->
hwctx;
206 vas = vaCreateContext(
ctx->hwctx->display,
ctx->va_config,
207 ctx->output_width,
ctx->output_height,
211 if (vas != VA_STATUS_SUCCESS) {
213 "context: %d (%s).\n", vas, vaErrorStr(vas));
217 outlink->
w =
ctx->output_width;
218 outlink->
h =
ctx->output_height;
220 if (
ctx->build_filter_params) {
221 err =
ctx->build_filter_params(avctx);
252 { VAProcColorStandardBT601, 5, 6, 5 },
253 { VAProcColorStandardBT601, 6, 6, 6 },
254 { VAProcColorStandardBT709, 1, 1, 1 },
255 { VAProcColorStandardBT470M, 4, 4, 4 },
256 { VAProcColorStandardBT470BG, 5, 5, 5 },
257 { VAProcColorStandardSMPTE170M, 6, 6, 6 },
258 { VAProcColorStandardSMPTE240M, 7, 7, 7 },
259 { VAProcColorStandardGenericFilm, 8, 1, 1 },
260 #if VA_CHECK_VERSION(1, 1, 0)
261 { VAProcColorStandardSRGB, 1, 13, 0 },
262 { VAProcColorStandardXVYCC601, 1, 11, 5 },
263 { VAProcColorStandardXVYCC709, 1, 11, 1 },
264 { VAProcColorStandardBT2020, 9, 14, 9 },
269 VAProcColorStandardType *vacs,
273 int i, j, score, best_score, worst_score;
274 VAProcColorStandardType best_standard;
276 #if VA_CHECK_VERSION(1, 3, 0)
281 for (
i = 0;
i < nb_vacs;
i++) {
282 if (vacs[
i] == VAProcColorStandardExplicit) {
294 best_standard = VAProcColorStandardNone;
301 if (worst_score == 0) {
308 for (
i = 0;
i < nb_vacs;
i++) {
324 if (score < worst_score &&
325 (best_score == -1 || score < best_score)) {
336 #if VA_CHECK_VERSION(1, 1, 0)
337 static const struct {
343 VA_CHROMA_SITING_HORIZONTAL_LEFT },
345 VA_CHROMA_SITING_HORIZONTAL_CENTER },
347 VA_CHROMA_SITING_HORIZONTAL_LEFT },
349 VA_CHROMA_SITING_HORIZONTAL_CENTER },
351 VA_CHROMA_SITING_HORIZONTAL_LEFT },
353 VA_CHROMA_SITING_HORIZONTAL_CENTER },
371 #if VA_CHECK_VERSION(1, 1, 0)
390 VAProcColorStandardType *vacs,
398 "to VA standard %d chroma siting %#x range %#x.\n",
421 VAProcPipelineParameterBuffer *params,
427 VAProcPipelineCaps caps;
430 vas = vaQueryVideoProcPipelineCaps(
ctx->hwctx->display,
ctx->va_context,
431 ctx->filter_buffers,
ctx->nb_filter_buffers,
433 if (vas != VA_STATUS_SUCCESS) {
435 "colour standard support: %d (%s).\n", vas, vaErrorStr(vas));
449 caps.input_color_standards,
450 caps.num_input_color_standards);
458 .chroma_sample_location =
output_frame->chroma_location,
461 caps.output_color_standards,
462 caps.num_output_color_standards);
466 #if VA_CHECK_VERSION(1, 3, 0)
480 if (output_standard) {
491 #if VA_CHECK_VERSION(1, 1, 0)
492 params->input_color_properties = (VAProcColorProperties) {
495 #if VA_CHECK_VERSION(1, 3, 0)
497 .transfer_characteristics = input_props.
color_trc,
498 .matrix_coefficients = input_props.
colorspace,
501 params->output_color_properties = (VAProcColorProperties) {
504 #if VA_CHECK_VERSION(1, 3, 0)
506 .transfer_characteristics = output_props.
color_trc,
507 .matrix_coefficients = output_props.
colorspace,
516 VAProcPipelineParameterBuffer *params,
521 VASurfaceID input_surface;
524 ctx->input_region = (VARectangle) {
527 .width = input_frame->
width -
537 input_surface = (VASurfaceID)(uintptr_t)input_frame->
data[3],
539 *params = (VAProcPipelineParameterBuffer) {
540 .surface = input_surface,
541 .surface_region = &
ctx->input_region,
542 .output_region =
NULL,
545 .filter_flags = VA_FRAME_PICTURE,
549 #if VA_CHECK_VERSION(1, 1, 0)
550 .rotation_state = VA_ROTATION_NONE,
551 .mirror_state = VA_MIRROR_NONE,
575 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
577 if (vas != VA_STATUS_SUCCESS) {
579 "buffer (type %d): %d (%s).\n",
580 type, vas, vaErrorStr(vas));
593 VAProcPipelineParameterBuffer *params,
597 VASurfaceID output_surface;
598 VABufferID params_id;
602 output_surface = (VASurfaceID)(uintptr_t)
output_frame->data[3];
604 vas = vaBeginPicture(
ctx->hwctx->display,
605 ctx->va_context, output_surface);
606 if (vas != VA_STATUS_SUCCESS) {
608 "%d (%s).\n", vas, vaErrorStr(vas));
613 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
614 VAProcPipelineParameterBufferType,
615 sizeof(*params), 1, params, ¶ms_id);
616 if (vas != VA_STATUS_SUCCESS) {
618 "%d (%s).\n", vas, vaErrorStr(vas));
620 goto fail_after_begin;
625 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context,
627 if (vas != VA_STATUS_SUCCESS) {
629 "%d (%s).\n", vas, vaErrorStr(vas));
631 goto fail_after_begin;
634 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
635 if (vas != VA_STATUS_SUCCESS) {
637 "%d (%s).\n", vas, vaErrorStr(vas));
639 goto fail_after_render;
644 vas = vaDestroyBuffer(
ctx->hwctx->display, params_id);
645 if (vas != VA_STATUS_SUCCESS) {
647 "%d (%s).\n", vas, vaErrorStr(vas));
659 vaRenderPicture(
ctx->hwctx->display,
ctx->va_context, ¶ms_id, 1);
661 vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
671 ctx->va_config = VA_INVALID_ID;
672 ctx->va_context = VA_INVALID_ID;
675 for (
i = 0;
i < VAProcFilterCount;
i++)
676 ctx->filter_buffers[
i] = VA_INVALID_ID;
677 ctx->nb_filter_buffers = 0;
683 if (
ctx->valid_ids &&
ctx->pipeline_uninit)
684 ctx->pipeline_uninit(avctx);
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link, int default_pool_size)
Perform any additional setup required for hardware frames.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
#define AVERROR_EXTERNAL
Generic error in an external library.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_hwframe_constraints_free(AVHWFramesConstraints **constraints)
Free an AVHWFrameConstraints structure.
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
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.
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
@ AV_VAAPI_DRIVER_QUIRK_RENDER_PARAM_BUFFERS
The driver does not destroy parameter buffers when they are used by vaRenderPicture().
static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp)
common internal API header
static enum AVPixelFormat pix_fmts[]
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
const char * av_chroma_location_name(enum AVChromaLocation location)
const char * av_color_range_name(enum AVColorRange range)
const char * av_color_space_name(enum AVColorSpace space)
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
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.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
AVChromaLocation
Location of chroma samples.
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
@ AVCHROMA_LOC_BOTTOMLEFT
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
@ AVCHROMA_LOC_UNSPECIFIED
AVColorRange
Visual content value range.
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
@ AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_JPEG
Full range content.
AVPixelFormat
Pixel format.
AVColorPrimaries
Chromaticity coordinates of the source primaries.
AVColorTransferCharacteristic
Color Transfer Characteristic.
AVColorSpace
YUV colorspace type.
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
#define FF_ARRAY_ELEMS(a)
uint8_t * data
The data buffer.
AVFilterLink ** inputs
array of pointers to input links
void * priv
private data for use by the filter
AVFilterLink ** outputs
array of pointers to output links
A link between two filters.
AVFilterFormatsConfig incfg
Lists of supported formats / etc.
int w
agreed upon image width
int h
agreed upon image height
AVFilterFormatsConfig outcfg
Lists of supported formats / etc.
AVFilterContext * src
source filter
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames.
AVFilterContext * dst
dest filter
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
enum AVChromaLocation chroma_location
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
enum AVColorPrimaries color_primaries
enum AVColorRange color_range
MPEG vs JPEG YUV range.
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
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.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
int initial_pool_size
Initial size of the frame pool.
int width
The allocated dimensions of the frames in this pool.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
VAAPI-specific data associated with a frame pool.
VASurfaceID * surface_ids
The surfaces IDs of all surfaces in the pool after creation.
VAAPI hardware pipeline configuration details.
VAConfigID config_id
ID of a VAAPI pipeline configuration.
enum AVColorSpace colorspace
VAProcColorStandardType va_color_standard
enum AVColorPrimaries color_primaries
uint8_t va_chroma_sample_location
enum AVColorRange color_range
enum AVColorTransferCharacteristic color_trc
enum AVChromaLocation chroma_sample_location
static void vaapi_vpp_fill_colour_range(VAAPIColourProperties *props)
int ff_vaapi_vpp_config_output(AVFilterLink *outlink)
static void vaapi_vpp_fill_colour_properties(AVFilterContext *avctx, VAAPIColourProperties *props, VAProcColorStandardType *vacs, int nb_vacs)
static const VAAPIColourProperties vaapi_colour_standard_map[]
static void vaapi_vpp_fill_colour_standard(VAAPIColourProperties *props, VAProcColorStandardType *vacs, int nb_vacs)
int ff_vaapi_vpp_config_input(AVFilterLink *inlink)
void ff_vaapi_vpp_pipeline_uninit(AVFilterContext *avctx)
void ff_vaapi_vpp_ctx_init(AVFilterContext *avctx)
int ff_vaapi_vpp_make_param_buffers(AVFilterContext *avctx, int type, const void *data, size_t size, int count)
static int vaapi_vpp_colour_properties(AVFilterContext *avctx, VAProcPipelineParameterBuffer *params, const AVFrame *input_frame, AVFrame *output_frame)
static int vaapi_vpp_frame_is_rgb(const AVFrame *frame)
int ff_vaapi_vpp_init_params(AVFilterContext *avctx, VAProcPipelineParameterBuffer *params, const AVFrame *input_frame, AVFrame *output_frame)
int ff_vaapi_vpp_render_picture(AVFilterContext *avctx, VAProcPipelineParameterBuffer *params, AVFrame *output_frame)
void ff_vaapi_vpp_ctx_uninit(AVFilterContext *avctx)
int ff_vaapi_vpp_query_formats(AVFilterContext *avctx)
static void vaapi_vpp_fill_chroma_sample_location(VAAPIColourProperties *props)
#define VAAPI_VPP_BACKGROUND_BLACK