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);
78 if (!
inlink->hw_frames_ctx) {
80 "required to associate the processing device.\n");
85 if (!
ctx->input_frames_ref) {
107 if (
ctx->pipeline_uninit)
108 ctx->pipeline_uninit(avctx);
110 if (!
ctx->output_width)
112 if (!
ctx->output_height)
115 outlink->
w =
ctx->output_width;
116 outlink->
h =
ctx->output_height;
118 if (
ctx->passthrough) {
119 if (
inlink->hw_frames_ctx)
128 if (!
ctx->device_ref) {
136 vas = vaCreateConfig(
ctx->hwctx->display, VAProfileNone,
137 VAEntrypointVideoProc,
NULL, 0, &
ctx->va_config);
138 if (vas != VA_STATUS_SUCCESS) {
140 "config: %d (%s).\n", vas, vaErrorStr(vas));
160 ctx->output_format =
ctx->input_frames->sw_format;
179 "size %dx%d (constraints: width %d-%d height %d-%d).\n",
180 ctx->output_width,
ctx->output_height,
199 output_frames->
width =
ctx->output_width;
200 output_frames->
height =
ctx->output_height;
211 "context for output: %d\n", err);
215 va_frames = output_frames->
hwctx;
218 vas = vaCreateContext(
ctx->hwctx->display,
ctx->va_config,
219 ctx->output_width,
ctx->output_height,
223 if (vas != VA_STATUS_SUCCESS) {
225 "context: %d (%s).\n", vas, vaErrorStr(vas));
229 if (
ctx->build_filter_params) {
230 err =
ctx->build_filter_params(avctx);
261 { VAProcColorStandardBT601, 5, 6, 5 },
262 { VAProcColorStandardBT601, 6, 6, 6 },
263 { VAProcColorStandardBT709, 1, 1, 1 },
264 { VAProcColorStandardBT470M, 4, 4, 4 },
265 { VAProcColorStandardBT470BG, 5, 5, 5 },
266 { VAProcColorStandardSMPTE170M, 6, 6, 6 },
267 { VAProcColorStandardSMPTE240M, 7, 7, 7 },
268 { VAProcColorStandardGenericFilm, 8, 1, 1 },
269 #if VA_CHECK_VERSION(1, 1, 0)
270 { VAProcColorStandardSRGB, 1, 13, 0 },
271 { VAProcColorStandardXVYCC601, 1, 11, 5 },
272 { VAProcColorStandardXVYCC709, 1, 11, 1 },
273 { VAProcColorStandardBT2020, 9, 14, 9 },
278 VAProcColorStandardType *vacs,
282 int i, j, score, best_score, worst_score;
283 VAProcColorStandardType best_standard;
285 #if VA_CHECK_VERSION(1, 3, 0)
290 for (
i = 0;
i < nb_vacs;
i++) {
291 if (vacs[
i] == VAProcColorStandardExplicit) {
303 best_standard = VAProcColorStandardNone;
310 if (worst_score == 0) {
317 for (
i = 0;
i < nb_vacs;
i++) {
333 if (score < worst_score &&
334 (best_score == -1 || score < best_score)) {
345 #if VA_CHECK_VERSION(1, 1, 0)
346 static const struct {
352 VA_CHROMA_SITING_HORIZONTAL_LEFT },
354 VA_CHROMA_SITING_HORIZONTAL_CENTER },
356 VA_CHROMA_SITING_HORIZONTAL_LEFT },
358 VA_CHROMA_SITING_HORIZONTAL_CENTER },
360 VA_CHROMA_SITING_HORIZONTAL_LEFT },
362 VA_CHROMA_SITING_HORIZONTAL_CENTER },
380 #if VA_CHECK_VERSION(1, 1, 0)
399 VAProcColorStandardType *vacs,
407 "to VA standard %d chroma siting %#x range %#x.\n",
430 VAProcPipelineParameterBuffer *params,
436 VAProcPipelineCaps caps;
439 vas = vaQueryVideoProcPipelineCaps(
ctx->hwctx->display,
ctx->va_context,
440 ctx->filter_buffers,
ctx->nb_filter_buffers,
442 if (vas != VA_STATUS_SUCCESS) {
444 "colour standard support: %d (%s).\n", vas, vaErrorStr(vas));
458 caps.input_color_standards,
459 caps.num_input_color_standards);
467 .chroma_sample_location =
output_frame->chroma_location,
470 caps.output_color_standards,
471 caps.num_output_color_standards);
475 #if VA_CHECK_VERSION(1, 3, 0)
489 if (output_standard) {
500 #if VA_CHECK_VERSION(1, 1, 0)
501 params->input_color_properties = (VAProcColorProperties) {
504 #if VA_CHECK_VERSION(1, 3, 0)
506 .transfer_characteristics = input_props.
color_trc,
507 .matrix_coefficients = input_props.
colorspace,
510 params->output_color_properties = (VAProcColorProperties) {
513 #if VA_CHECK_VERSION(1, 3, 0)
515 .transfer_characteristics = output_props.
color_trc,
516 .matrix_coefficients = output_props.
colorspace,
525 VAProcPipelineParameterBuffer *params,
532 ctx->input_region = (VARectangle) {
535 .width = input_frame->
width -
545 *params = (VAProcPipelineParameterBuffer) {
547 .surface_region = &
ctx->input_region,
548 .output_region =
NULL,
551 .filter_flags = VA_FRAME_PICTURE,
555 #if VA_CHECK_VERSION(1, 1, 0)
556 .rotation_state = VA_ROTATION_NONE,
557 .mirror_state = VA_MIRROR_NONE,
585 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
587 if (vas != VA_STATUS_SUCCESS) {
589 "buffer (type %d): %d (%s).\n",
590 type, vas, vaErrorStr(vas));
602 VAProcPipelineParameterBuffer *params,
603 VABufferID *params_id)
608 vas = vaCreateBuffer(
ctx->hwctx->display,
ctx->va_context,
609 VAProcPipelineParameterBufferType,
610 sizeof(*params), 1, params, params_id);
611 if (vas != VA_STATUS_SUCCESS) {
613 "%d (%s).\n", vas, vaErrorStr(vas));
614 *params_id = VA_INVALID_ID;
620 vas = vaRenderPicture(
ctx->hwctx->display,
ctx->va_context, params_id, 1);
621 if (vas != VA_STATUS_SUCCESS) {
623 "%d (%s).\n", vas, vaErrorStr(vas));
631 VAProcPipelineParameterBuffer *params_list,
636 VABufferID *params_ids;
644 for (
int i = 0;
i < cout;
i++)
645 params_ids[
i] = VA_INVALID_ID;
647 vas = vaBeginPicture(
ctx->hwctx->display,
649 if (vas != VA_STATUS_SUCCESS) {
651 "%d (%s).\n", vas, vaErrorStr(vas));
656 for (
int i = 0;
i < cout;
i++) {
659 goto fail_after_begin;
662 vas = vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
663 if (vas != VA_STATUS_SUCCESS) {
665 "%d (%s).\n", vas, vaErrorStr(vas));
667 goto fail_after_render;
670 if (CONFIG_VAAPI_1 ||
ctx->hwctx->driver_quirks &
672 for (
int i = 0;
i < cout && params_ids[
i] != VA_INVALID_ID;
i++) {
673 vas = vaDestroyBuffer(
ctx->hwctx->display, params_ids[
i]);
674 if (vas != VA_STATUS_SUCCESS) {
676 "%d (%s).\n", vas, vaErrorStr(vas));
690 vaRenderPicture(
ctx->hwctx->display,
ctx->va_context, ¶ms_ids[0], 1);
692 vaEndPicture(
ctx->hwctx->display,
ctx->va_context);
699 VAProcPipelineParameterBuffer *params,
710 ctx->va_config = VA_INVALID_ID;
711 ctx->va_context = VA_INVALID_ID;
714 for (
i = 0;
i < VAProcFilterCount;
i++)
715 ctx->filter_buffers[
i] = VA_INVALID_ID;
716 ctx->nb_filter_buffers = 0;
722 if (
ctx->valid_ids &&
ctx->pipeline_uninit)
723 ctx->pipeline_uninit(avctx);