| 573 | } |
| 574 | |
| 575 | static int vaapi_frames_init(AVHWFramesContext *hwfc) |
| 576 | { |
| 577 | VAAPIFramesContext *ctx = hwfc->hwctx; |
| 578 | AVVAAPIFramesContext *avfc = &ctx->p; |
| 579 | AVVAAPIDeviceContext *hwctx = hwfc->device_ctx->hwctx; |
| 580 | const VAAPIFormatDescriptor *desc = NULL; |
| 581 | VAImageFormat *expected_format = NULL; |
| 582 | AVBufferRef *test_surface = NULL; |
| 583 | VASurfaceID test_surface_id; |
| 584 | VAImage test_image; |
| 585 | VAStatus vas; |
| 586 | int err, i; |
| 587 | |
| 588 | err = vaapi_get_img_desc_and_format(hwfc->device_ctx, hwfc->sw_format, |
| 589 | &desc, &expected_format); |
| 590 | if (err < 0) { |
| 591 | // Use a relaxed check when pool exist. It can be an external pool. |
| 592 | if (!hwfc->pool || !vaapi_format_from_pix_fmt(hwfc->sw_format, NULL)) { |
| 593 | av_log(hwfc, AV_LOG_ERROR, "Unsupported format: %s.\n", |
| 594 | av_get_pix_fmt_name(hwfc->sw_format)); |
| 595 | return AVERROR(EINVAL); |
| 596 | } |
| 597 | } |
| 598 | |
| 599 | if (!hwfc->pool) { |
| 600 | if (!(hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_SURFACE_ATTRIBUTES)) { |
| 601 | int need_memory_type = !(hwctx->driver_quirks & AV_VAAPI_DRIVER_QUIRK_ATTRIB_MEMTYPE); |
| 602 | int need_pixel_format = 1; |
| 603 | for (i = 0; i < avfc->nb_attributes; i++) { |
| 604 | if (avfc->attributes[i].type == VASurfaceAttribMemoryType) |
| 605 | need_memory_type = 0; |
| 606 | if (avfc->attributes[i].type == VASurfaceAttribPixelFormat) |
| 607 | need_pixel_format = 0; |
| 608 | } |
| 609 | ctx->nb_attributes = |
| 610 | avfc->nb_attributes + need_memory_type + need_pixel_format; |
| 611 | |
| 612 | ctx->attributes = av_malloc(ctx->nb_attributes * |
| 613 | sizeof(*ctx->attributes)); |
| 614 | if (!ctx->attributes) { |
| 615 | err = AVERROR(ENOMEM); |
| 616 | goto fail; |
| 617 | } |
| 618 | |
| 619 | for (i = 0; i < avfc->nb_attributes; i++) |
| 620 | ctx->attributes[i] = avfc->attributes[i]; |
| 621 | if (need_memory_type) { |
| 622 | ctx->attributes[i++] = (VASurfaceAttrib) { |
| 623 | .type = VASurfaceAttribMemoryType, |
| 624 | .flags = VA_SURFACE_ATTRIB_SETTABLE, |
| 625 | .value.type = VAGenericValueTypeInteger, |
| 626 | .value.value.i = VA_SURFACE_ATTRIB_MEM_TYPE_VA, |
| 627 | }; |
| 628 | } |
| 629 | if (need_pixel_format) { |
| 630 | ctx->attributes[i++] = (VASurfaceAttrib) { |
| 631 | .type = VASurfaceAttribPixelFormat, |
| 632 | .flags = VA_SURFACE_ATTRIB_SETTABLE, |
nothing calls this directly
no test coverage detected