MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / cuda_frames_init

Function cuda_frames_init

libavutil/hwcontext_cuda.c:143–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

141}
142
143static int cuda_frames_init(AVHWFramesContext *ctx)
144{
145 AVHWDeviceContext *device_ctx = ctx->device_ctx;
146 AVCUDADeviceContext *hwctx = device_ctx->hwctx;
147 CUDAFramesContext *priv = ctx->hwctx;
148 CudaFunctions *cu = hwctx->internal->cuda_dl;
149 int err, i;
150
151 for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
152 if (ctx->sw_format == supported_formats[i])
153 break;
154 }
155 if (i == FF_ARRAY_ELEMS(supported_formats)) {
156 av_log(ctx, AV_LOG_ERROR, "Pixel format '%s' is not supported\n",
157 av_get_pix_fmt_name(ctx->sw_format));
158 return AVERROR(ENOSYS);
159 }
160
161 err = CHECK_CU(cu->cuDeviceGetAttribute(&priv->tex_alignment,
162 14 /* CU_DEVICE_ATTRIBUTE_TEXTURE_ALIGNMENT */,
163 hwctx->internal->cuda_device));
164 if (err < 0)
165 return err;
166
167 av_log(ctx, AV_LOG_DEBUG, "CUDA texture alignment: %d\n", priv->tex_alignment);
168
169 // YUV420P is a special case.
170 // Since nvenc expects the U/V planes to have half the linesize of the Y plane
171 // alignment has to be doubled to ensure the U/V planes still end up aligned.
172 if (ctx->sw_format == AV_PIX_FMT_YUV420P)
173 priv->tex_alignment *= 2;
174
175 av_pix_fmt_get_chroma_sub_sample(ctx->sw_format, &priv->shift_width, &priv->shift_height);
176
177 if (!ctx->pool) {
178 int size = av_image_get_buffer_size(ctx->sw_format, ctx->width, ctx->height, priv->tex_alignment);
179 if (size < 0)
180 return size;
181
182 ffhwframesctx(ctx)->pool_internal =
183 av_buffer_pool_init2(size, ctx, cuda_pool_alloc, NULL);
184 if (!ffhwframesctx(ctx)->pool_internal)
185 return AVERROR(ENOMEM);
186 }
187
188 return 0;
189}
190
191static int cuda_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
192{

Callers

nothing calls this directly

Calls 6

av_logFunction · 0.85
av_get_pix_fmt_nameFunction · 0.85
av_image_get_buffer_sizeFunction · 0.85
ffhwframesctxFunction · 0.85
av_buffer_pool_init2Function · 0.85

Tested by

no test coverage detected