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) {
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",
413 frame->hw_frames_ctx);
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;
642 if (CONFIG_VAAPI_1 ||
ctx->hwctx->driver_quirks &
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);