| 584 | } |
| 585 | |
| 586 | static int vulkan_encode_create_dpb(AVCodecContext *avctx, FFVulkanEncodeContext *ctx) |
| 587 | { |
| 588 | int err; |
| 589 | FFHWBaseEncodeContext *base_ctx = &ctx->base; |
| 590 | AVVulkanFramesContext *hwfc; |
| 591 | |
| 592 | enum AVPixelFormat dpb_format; |
| 593 | err = ff_hw_base_get_recon_format(base_ctx, NULL, &dpb_format); |
| 594 | if (err < 0) |
| 595 | return err; |
| 596 | |
| 597 | base_ctx->recon_frames_ref = av_hwframe_ctx_alloc(base_ctx->device_ref); |
| 598 | if (!base_ctx->recon_frames_ref) |
| 599 | return AVERROR(ENOMEM); |
| 600 | |
| 601 | base_ctx->recon_frames = (AVHWFramesContext *)base_ctx->recon_frames_ref->data; |
| 602 | hwfc = (AVVulkanFramesContext *)base_ctx->recon_frames->hwctx; |
| 603 | |
| 604 | base_ctx->recon_frames->format = AV_PIX_FMT_VULKAN; |
| 605 | base_ctx->recon_frames->sw_format = dpb_format; |
| 606 | base_ctx->recon_frames->width = avctx->width; |
| 607 | base_ctx->recon_frames->height = avctx->height; |
| 608 | |
| 609 | hwfc->format[0] = ctx->pic_format; |
| 610 | hwfc->create_pnext = &ctx->profile_list; |
| 611 | hwfc->tiling = VK_IMAGE_TILING_OPTIMAL; |
| 612 | hwfc->usage = VK_IMAGE_USAGE_VIDEO_ENCODE_DPB_BIT_KHR; |
| 613 | |
| 614 | if (ctx->common.layered_dpb) |
| 615 | hwfc->nb_layers = ctx->caps.maxDpbSlots; |
| 616 | |
| 617 | err = av_hwframe_ctx_init(base_ctx->recon_frames_ref); |
| 618 | if (err < 0) { |
| 619 | av_log(avctx, AV_LOG_ERROR, "Failed to initialise DPB frame context: %s\n", |
| 620 | av_err2str(err)); |
| 621 | return err; |
| 622 | } |
| 623 | |
| 624 | if (ctx->common.layered_dpb) { |
| 625 | ctx->common.layered_frame = av_frame_alloc(); |
| 626 | if (!ctx->common.layered_frame) |
| 627 | return AVERROR(ENOMEM); |
| 628 | |
| 629 | err = av_hwframe_get_buffer(base_ctx->recon_frames_ref, |
| 630 | ctx->common.layered_frame, 0); |
| 631 | if (err < 0) |
| 632 | return AVERROR(ENOMEM); |
| 633 | |
| 634 | err = ff_vk_create_view(&ctx->s, &ctx->common, |
| 635 | &ctx->common.layered_view, |
| 636 | &ctx->common.layered_aspect, |
| 637 | (AVVkFrame *)ctx->common.layered_frame->data[0], |
| 638 | hwfc->format[0], VK_IMAGE_USAGE_VIDEO_ENCODE_DPB_BIT_KHR); |
| 639 | if (err < 0) |
| 640 | return err; |
| 641 | |
| 642 | av_buffer_unref(&base_ctx->recon_frames_ref); |
| 643 | } |
no test coverage detected