| 707 | } |
| 708 | |
| 709 | int ff_nvdec_frame_params(AVCodecContext *avctx, |
| 710 | AVBufferRef *hw_frames_ctx, |
| 711 | int dpb_size, |
| 712 | int supports_444) |
| 713 | { |
| 714 | AVHWFramesContext *frames_ctx = (AVHWFramesContext*)hw_frames_ctx->data; |
| 715 | const AVPixFmtDescriptor *sw_desc; |
| 716 | int cuvid_codec_type, cuvid_chroma_format, chroma_444; |
| 717 | |
| 718 | sw_desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt); |
| 719 | if (!sw_desc) |
| 720 | return AVERROR_BUG; |
| 721 | |
| 722 | cuvid_codec_type = map_avcodec_id(avctx->codec_id); |
| 723 | if (cuvid_codec_type < 0) { |
| 724 | av_log(avctx, AV_LOG_ERROR, "Unsupported codec ID\n"); |
| 725 | return AVERROR_BUG; |
| 726 | } |
| 727 | |
| 728 | cuvid_chroma_format = map_chroma_format(avctx->sw_pix_fmt); |
| 729 | if (cuvid_chroma_format < 0) { |
| 730 | av_log(avctx, AV_LOG_VERBOSE, "Unsupported chroma format\n"); |
| 731 | return AVERROR(EINVAL); |
| 732 | } |
| 733 | chroma_444 = supports_444 && cuvid_chroma_format == cudaVideoChromaFormat_444; |
| 734 | |
| 735 | frames_ctx->format = AV_PIX_FMT_CUDA; |
| 736 | frames_ctx->width = (avctx->coded_width + 1) & ~1; |
| 737 | frames_ctx->height = (avctx->coded_height + 1) & ~1; |
| 738 | /* |
| 739 | * We add two extra frames to the pool to account for deinterlacing filters |
| 740 | * holding onto their frames. |
| 741 | */ |
| 742 | frames_ctx->initial_pool_size = dpb_size + 2; |
| 743 | |
| 744 | switch (sw_desc->comp[0].depth) { |
| 745 | case 8: |
| 746 | if (chroma_444) { |
| 747 | frames_ctx->sw_format = AV_PIX_FMT_YUV444P; |
| 748 | #ifdef NVDEC_HAVE_422_SUPPORT |
| 749 | } else if (cuvid_chroma_format == cudaVideoChromaFormat_422) { |
| 750 | frames_ctx->sw_format = AV_PIX_FMT_NV16; |
| 751 | #endif |
| 752 | } else { |
| 753 | frames_ctx->sw_format = AV_PIX_FMT_NV12; |
| 754 | } |
| 755 | break; |
| 756 | case 10: |
| 757 | if (chroma_444) { |
| 758 | #if FF_API_NVDEC_OLD_PIX_FMTS |
| 759 | frames_ctx->sw_format = AV_PIX_FMT_YUV444P16; |
| 760 | #else |
| 761 | frames_ctx->sw_format = AV_PIX_FMT_YUV444P10MSB; |
| 762 | #endif |
| 763 | #ifdef NVDEC_HAVE_422_SUPPORT |
| 764 | } else if (cuvid_chroma_format == cudaVideoChromaFormat_422) { |
| 765 | frames_ctx->sw_format = AV_PIX_FMT_P210; |
| 766 | #endif |
no test coverage detected