22 #include <va/va_vpp.h>
37 #define MAX_REFERENCES 8
61 VAProcFilterCapDeinterlacing
77 #define D(name) case VAProcDeinterlacing ## name: return #name
144 "required to associate the processing device.\n");
158 VAProcFilterParameterBufferDeinterlacing
params;
164 VAProcFilterDeinterlacing,
167 if (vas != VA_STATUS_SUCCESS) {
169 "caps: %d (%s).\n", vas, vaErrorStr(vas));
173 if (ctx->
mode == VAProcDeinterlacingNone) {
179 "deinterlacing mode.\n", ctx->
mode,
188 "not supported.\n", ctx->
mode,
193 params.type = VAProcFilterDeinterlacing;
194 params.algorithm = ctx->
mode;
199 VAProcFilterParameterBufferType,
200 sizeof(params), 1, ¶ms,
202 if (vas != VA_STATUS_SUCCESS) {
204 "parameter buffer: %d (%s).\n", vas, vaErrorStr(vas));
212 if (vas != VA_STATUS_SUCCESS) {
214 "caps: %d (%s).\n", vas, vaErrorStr(vas));
226 "references (%u forward, %u back).\n",
256 vas = vaCreateConfig(ctx->
hwctx->
display, VAProfileNone,
257 VAEntrypointVideoProc, 0, 0, &ctx->
va_config);
258 if (vas != VA_STATUS_SUCCESS) {
260 "config: %d (%s).\n", vas, vaErrorStr(vas));
284 "deinterlacing to size %dx%d "
285 "(constraints: width %d-%d height %d-%d).\n",
316 "context for output: %d\n", err);
327 if (vas != VA_STATUS_SUCCESS) {
329 "context: %d (%s).\n", vas, vaErrorStr(vas));
338 outlink->
w = inlink->
w;
339 outlink->
h = inlink->
h;
343 outlink->frame_rate =
av_mul_q(inlink->frame_rate,
347 if (!outlink->hw_frames_ctx) {
366 #define CS(av, va) case AVCOL_SPC_ ## av: return VAProcColorStandard ## va;
368 CS(BT470BG, BT470BG);
369 CS(SMPTE170M, SMPTE170M);
370 CS(SMPTE240M, SMPTE240M);
373 return VAProcColorStandardNone;
383 VASurfaceID input_surface, output_surface;
386 VAProcPipelineParameterBuffer
params;
387 VAProcFilterParameterBufferDeinterlacing *filter_params;
388 VARectangle input_region;
389 VABufferID params_id;
391 void *filter_params_addr =
NULL;
392 int err, i, field, current_frame_index;
411 current_frame_index = ctx->
pipeline_caps.num_forward_references;
413 input_frame = ctx->
frame_queue[current_frame_index];
414 input_surface = (VASurfaceID)(uintptr_t)input_frame->
data[3];
415 for (i = 0; i < ctx->
pipeline_caps.num_forward_references; i++)
416 forward_references[i] = (VASurfaceID)(uintptr_t)
419 backward_references[i] = (VASurfaceID)(uintptr_t)
423 "deinterlace input.\n", input_surface);
425 for (i = 0; i < ctx->
pipeline_caps.num_backward_references; i++)
429 for (i = 0; i < ctx->
pipeline_caps.num_forward_references; i++)
433 for (field = 0; field < ctx->
field_rate; field++) {
441 output_surface = (VASurfaceID)(uintptr_t)output_frame->
data[3];
443 "deinterlace output.\n", output_surface);
445 memset(¶ms, 0,
sizeof(params));
447 input_region = (VARectangle) {
450 .width = input_frame->
width,
451 .height = input_frame->
height,
454 params.surface = input_surface;
455 params.surface_region = &input_region;
456 params.surface_color_standard =
459 params.output_region =
NULL;
460 params.output_background_color = 0xff000000;
461 params.output_color_standard = params.surface_color_standard;
463 params.pipeline_flags = 0;
464 params.filter_flags = VA_FRAME_PICTURE;
468 &filter_params_addr);
469 if (vas != VA_STATUS_SUCCESS) {
471 "buffer: %d (%s).\n", vas, vaErrorStr(vas));
475 filter_params = filter_params_addr;
476 filter_params->flags = 0;
478 filter_params->flags |= field ? VA_DEINTERLACING_BOTTOM_FIELD : 0;
480 filter_params->flags |= VA_DEINTERLACING_BOTTOM_FIELD_FIRST;
481 filter_params->flags |= field ? 0 : VA_DEINTERLACING_BOTTOM_FIELD;
483 filter_params_addr =
NULL;
485 if (vas != VA_STATUS_SUCCESS)
487 "buffer: %d (%s).\n", vas, vaErrorStr(vas));
490 params.num_filters = 1;
492 params.forward_references = forward_references;
493 params.num_forward_references =
495 params.backward_references = backward_references;
496 params.num_backward_references =
500 params.filters =
NULL;
501 params.num_filters = 0;
506 if (vas != VA_STATUS_SUCCESS) {
508 "%d (%s).\n", vas, vaErrorStr(vas));
514 VAProcPipelineParameterBufferType,
515 sizeof(params), 1, ¶ms, ¶ms_id);
516 if (vas != VA_STATUS_SUCCESS) {
518 "%d (%s).\n", vas, vaErrorStr(vas));
520 goto fail_after_begin;
527 if (vas != VA_STATUS_SUCCESS) {
529 "%d (%s).\n", vas, vaErrorStr(vas));
531 goto fail_after_begin;
535 if (vas != VA_STATUS_SUCCESS) {
537 "%d (%s).\n", vas, vaErrorStr(vas));
539 goto fail_after_render;
545 if (vas != VA_STATUS_SUCCESS) {
547 "%d (%s).\n", vas, vaErrorStr(vas));
558 output_frame->
pts = 2 * input_frame->
pts;
560 output_frame->
pts = input_frame->
pts +
581 if (filter_params_addr)
611 #define OFFSET(x) offsetof(DeintVAAPIContext, x)
612 #define FLAGS (AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM)
614 {
"mode",
"Deinterlacing mode",
616 VAProcDeinterlacingNone, VAProcDeinterlacingCount - 1,
FLAGS,
"mode" },
617 {
"default",
"Use the highest-numbered (and therefore possibly most advanced) deinterlacing algorithm",
619 {
"bob",
"Use the bob deinterlacing algorithm",
621 {
"weave",
"Use the weave deinterlacing algorithm",
623 {
"motion_adaptive",
"Use the motion adaptive deinterlacing algorithm",
624 0,
AV_OPT_TYPE_CONST, { .i64 = VAProcDeinterlacingMotionAdaptive }, .unit =
"mode" },
625 {
"motion_compensated",
"Use the motion compensated deinterlacing algorithm",
626 0,
AV_OPT_TYPE_CONST, { .i64 = VAProcDeinterlacingMotionCompensated }, .unit =
"mode" },
628 {
"rate",
"Generate output at frame rate or field rate",
630 {
"frame",
"Output at frame rate (one frame of output for each field-pair)",
632 {
"field",
"Output at field rate (one frame of output for each field)",
635 {
"auto",
"Only deinterlace fields, passing frames through unchanged",
668 .
name =
"deinterlace_vaapi",
674 .
inputs = deint_vaapi_inputs,
675 .
outputs = deint_vaapi_outputs,
676 .priv_class = &deint_vaapi_class,
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
#define FF_FILTER_FLAG_HWFRAME_AWARE
The filter is aware of hardware frames, and any hardware frame context should not be automatically pr...
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
VAAPI-specific data associated with a frame pool.
This structure describes decoded (raw) audio or video data.
The driver does not destroy parameter buffers when they are used by vaRenderPicture().
#define LIBAVUTIL_VERSION_INT
Main libavfilter public API header.
Memory handling functions.
static av_cold int init(AVCodecContext *avctx)
int h
agreed upon image height
VAProcFilterCapDeinterlacing deint_caps[VAProcDeinterlacingCount]
static int deint_vaapi_filter_frame(AVFilterLink *inlink, AVFrame *input_frame)
int width
The allocated dimensions of the frames in this pool.
void * av_hwdevice_hwconfig_alloc(AVBufferRef *ref)
Allocate a HW-specific configuration structure for a given HW device.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static int deint_vaapi_build_filter_params(AVFilterContext *avctx)
int max_width
The maximum size of frames in this hw_frames_ctx.
API-specific header for AV_HWDEVICE_TYPE_VAAPI.
void av_hwframe_constraints_free(AVHWFramesConstraints **constraints)
Free an AVHWFrameConstraints structure.
const char * name
Pad name.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
AVFilterLink ** inputs
array of pointers to input links
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
AVVAAPIDeviceContext * hwctx
static av_cold int uninit(AVCodecContext *avctx)
AVColorSpace
YUV colorspace type.
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
AVFilter ff_vf_deinterlace_vaapi
#define AV_LOG_VERBOSE
Detailed information.
int interlaced_frame
The content of the picture is interlaced.
static int deint_vaapi_query_formats(AVFilterContext *avctx)
A filter pad used for either input or output.
A link between two filters.
AVHWFramesContext * input_frames
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
VAAPI hardware pipeline configuration details.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
enum AVColorSpace colorspace
YUV colorspace type.
AVRational time_base
Define the time base used by the PTS of the frames/samples which will pass through this link...
simple assert() macros that are a bit more flexible than ISO C assert().
AVFilterFormats * in_formats
Lists of formats and channel layouts supported by the input and output filters respectively.
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use.
static int deint_vaapi_config_output(AVFilterLink *outlink)
int w
agreed upon image width
int initial_pool_size
Initial size of the frame pool.
AVFrame * frame_queue[MAX_REFERENCES]
AVBufferRef * hw_frames_ctx
For hwaccel pixel formats, this should be a reference to the AVHWFramesContext describing the frames...
static const char * deint_vaapi_mode_name(int mode)
int extra_delay_for_timestamps
static int deint_vaapi_config_input(AVFilterLink *inlink)
AVFilterContext * src
source filter
static const AVFilterPad outputs[]
AVBufferRef * input_frames_ref
VAProcPipelineCaps pipeline_caps
VADisplay display
The VADisplay handle, to be filled by the user.
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
int min_width
The minimum size of frames in this hw_frames_ctx.
static const AVFilterPad inputs[]
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
AVBufferRef * output_frames_ref
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...
uint8_t * data
The data buffer.
void * hwctx
The format-specific data, allocated and freed automatically along with this context.
unsigned int driver_quirks
Driver quirks to apply - this is filled by av_hwdevice_ctx_init(), with reference to a table of known...
static int output_frame(H264Context *h, AVFrame *dst, H264Picture *srcp)
AVHWFramesContext * output_frames
Describe the class of an AVClass context structure.
Rational number (pair of numerator and denominator).
This struct describes a set or pool of "hardware" frames (i.e.
const char * name
Filter name.
static const AVClass deint_vaapi_class
AVFilterLink ** outputs
array of pointers to output links
static enum AVPixelFormat pix_fmts[]
static int deint_vaapi_pipeline_uninit(AVFilterContext *avctx)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
A reference to a data buffer.
static av_cold int deint_vaapi_init(AVFilterContext *avctx)
static const AVFilterPad deint_vaapi_inputs[]
static int query_formats(AVFilterContext *ctx)
common internal and external API header
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context.
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
static const AVFilterPad deint_vaapi_outputs[]
int top_field_first
If the content is interlaced, is top field displayed first.
AVFilterContext * dst
dest filter
VAAPI connection details.
VAConfigID config_id
ID of a VAAPI pipeline configuration.
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals.
VASurfaceID * surface_ids
The surfaces IDs of all surfaces in the pool after creation.
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 sw_format
The pixel format identifying the actual data layout of the hardware frames.
AVPixelFormat
Pixel format.
mode
Use these values in ebur128_init (or'ed).
static int vaapi_proc_colour_standard(enum AVColorSpace av_cs)
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
AVFilterFormats * out_formats
static av_cold void deint_vaapi_uninit(AVFilterContext *avctx)
static const AVOption deint_vaapi_options[]