FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
hwcontext_cuda.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include "buffer.h"
20 #include "common.h"
21 #include "hwcontext.h"
22 #include "hwcontext_internal.h"
24 #if CONFIG_VULKAN
25 #include "hwcontext_vulkan.h"
26 #endif
27 #include "cuda_check.h"
28 #include "mem.h"
29 #include "pixdesc.h"
30 #include "pixfmt.h"
31 #include "imgutils.h"
32 
33 typedef struct CUDAFramesContext {
37 
38 typedef struct CUDADeviceContext {
42 
43 static const enum AVPixelFormat supported_formats[] = {
60 #if CONFIG_VULKAN
62 #endif
63 };
64 
65 #define CHECK_CU(x) FF_CUDA_CHECK_DL(device_ctx, cu, x)
66 
68  const void *hwconfig,
69  AVHWFramesConstraints *constraints)
70 {
71  int i;
72 
74  sizeof(*constraints->valid_sw_formats));
75  if (!constraints->valid_sw_formats)
76  return AVERROR(ENOMEM);
77 
78  for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++)
79  constraints->valid_sw_formats[i] = supported_formats[i];
81 
82  constraints->valid_hw_formats = av_malloc_array(2, sizeof(*constraints->valid_hw_formats));
83  if (!constraints->valid_hw_formats)
84  return AVERROR(ENOMEM);
85 
86  constraints->valid_hw_formats[0] = AV_PIX_FMT_CUDA;
87  constraints->valid_hw_formats[1] = AV_PIX_FMT_NONE;
88 
89  return 0;
90 }
91 
92 static void cuda_buffer_free(void *opaque, uint8_t *data)
93 {
94  AVHWFramesContext *ctx = opaque;
95  AVHWDeviceContext *device_ctx = ctx->device_ctx;
96  AVCUDADeviceContext *hwctx = device_ctx->hwctx;
97  CudaFunctions *cu = hwctx->internal->cuda_dl;
98 
99  CUcontext dummy;
100 
101  CHECK_CU(cu->cuCtxPushCurrent(hwctx->cuda_ctx));
102 
103  CHECK_CU(cu->cuMemFree((CUdeviceptr)data));
104 
105  CHECK_CU(cu->cuCtxPopCurrent(&dummy));
106 }
107 
108 static AVBufferRef *cuda_pool_alloc(void *opaque, size_t size)
109 {
110  AVHWFramesContext *ctx = opaque;
111  AVHWDeviceContext *device_ctx = ctx->device_ctx;
112  AVCUDADeviceContext *hwctx = device_ctx->hwctx;
113  CudaFunctions *cu = hwctx->internal->cuda_dl;
114 
115  AVBufferRef *ret = NULL;
116  CUcontext dummy = NULL;
117  CUdeviceptr data;
118  int err;
119 
120  err = CHECK_CU(cu->cuCtxPushCurrent(hwctx->cuda_ctx));
121  if (err < 0)
122  return NULL;
123 
124  err = CHECK_CU(cu->cuMemAlloc(&data, size));
125  if (err < 0)
126  goto fail;
127 
128  ret = av_buffer_create((uint8_t*)data, size, cuda_buffer_free, ctx, 0);
129  if (!ret) {
130  CHECK_CU(cu->cuMemFree(data));
131  goto fail;
132  }
133 
134 fail:
135  CHECK_CU(cu->cuCtxPopCurrent(&dummy));
136  return ret;
137 }
138 
140 {
141  AVHWDeviceContext *device_ctx = ctx->device_ctx;
142  AVCUDADeviceContext *hwctx = device_ctx->hwctx;
143  CUDAFramesContext *priv = ctx->hwctx;
144  CudaFunctions *cu = hwctx->internal->cuda_dl;
145  int err, i;
146 
147  for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
148  if (ctx->sw_format == supported_formats[i])
149  break;
150  }
152  av_log(ctx, AV_LOG_ERROR, "Pixel format '%s' is not supported\n",
153  av_get_pix_fmt_name(ctx->sw_format));
154  return AVERROR(ENOSYS);
155  }
156 
157  err = CHECK_CU(cu->cuDeviceGetAttribute(&priv->tex_alignment,
158  14 /* CU_DEVICE_ATTRIBUTE_TEXTURE_ALIGNMENT */,
159  hwctx->internal->cuda_device));
160  if (err < 0)
161  return err;
162 
163  av_log(ctx, AV_LOG_DEBUG, "CUDA texture alignment: %d\n", priv->tex_alignment);
164 
165  // YUV420P is a special case.
166  // Since nvenc expects the U/V planes to have half the linesize of the Y plane
167  // alignment has to be doubled to ensure the U/V planes still end up aligned.
168  if (ctx->sw_format == AV_PIX_FMT_YUV420P)
169  priv->tex_alignment *= 2;
170 
171  av_pix_fmt_get_chroma_sub_sample(ctx->sw_format, &priv->shift_width, &priv->shift_height);
172 
173  if (!ctx->pool) {
174  int size = av_image_get_buffer_size(ctx->sw_format, ctx->width, ctx->height, priv->tex_alignment);
175  if (size < 0)
176  return size;
177 
180  if (!ffhwframesctx(ctx)->pool_internal)
181  return AVERROR(ENOMEM);
182  }
183 
184  return 0;
185 }
186 
188 {
189  CUDAFramesContext *priv = ctx->hwctx;
190  int res;
191 
192  frame->buf[0] = av_buffer_pool_get(ctx->pool);
193  if (!frame->buf[0])
194  return AVERROR(ENOMEM);
195 
196  res = av_image_fill_arrays(frame->data, frame->linesize, frame->buf[0]->data,
197  ctx->sw_format, ctx->width, ctx->height, priv->tex_alignment);
198  if (res < 0)
199  return res;
200 
201  // YUV420P is a special case.
202  // Nvenc expects the U/V planes in swapped order from how ffmpeg expects them, also chroma is half-aligned
203  if (ctx->sw_format == AV_PIX_FMT_YUV420P) {
204  frame->linesize[1] = frame->linesize[2] = frame->linesize[0] / 2;
205  frame->data[2] = frame->data[1];
206  frame->data[1] = frame->data[2] + frame->linesize[2] * (ctx->height / 2);
207  }
208 
209  frame->format = AV_PIX_FMT_CUDA;
210  frame->width = ctx->width;
211  frame->height = ctx->height;
212 
213  return 0;
214 }
215 
218  enum AVPixelFormat **formats)
219 {
220  enum AVPixelFormat *fmts;
221 
222  fmts = av_malloc_array(2, sizeof(*fmts));
223  if (!fmts)
224  return AVERROR(ENOMEM);
225 
226  fmts[0] = ctx->sw_format;
227  fmts[1] = AV_PIX_FMT_NONE;
228 
229  *formats = fmts;
230 
231  return 0;
232 }
233 
235  const AVFrame *src)
236 {
237  CUDAFramesContext *priv = ctx->hwctx;
238  AVHWDeviceContext *device_ctx = ctx->device_ctx;
239  AVCUDADeviceContext *hwctx = device_ctx->hwctx;
240  CudaFunctions *cu = hwctx->internal->cuda_dl;
241 
242  CUcontext dummy;
243  int i, ret;
244 
245  if ((src->hw_frames_ctx && ((AVHWFramesContext*)src->hw_frames_ctx->data)->format != AV_PIX_FMT_CUDA) ||
246  (dst->hw_frames_ctx && ((AVHWFramesContext*)dst->hw_frames_ctx->data)->format != AV_PIX_FMT_CUDA))
247  return AVERROR(ENOSYS);
248 
249  ret = CHECK_CU(cu->cuCtxPushCurrent(hwctx->cuda_ctx));
250  if (ret < 0)
251  return ret;
252 
253  for (i = 0; i < FF_ARRAY_ELEMS(src->data) && src->data[i]; i++) {
254  CUDA_MEMCPY2D cpy = {
255  .srcPitch = src->linesize[i],
256  .dstPitch = dst->linesize[i],
257  .WidthInBytes = FFMIN(src->linesize[i], dst->linesize[i]),
258  .Height = src->height >> ((i == 0 || i == 3) ? 0 : priv->shift_height),
259  };
260 
261  if (src->hw_frames_ctx) {
262  cpy.srcMemoryType = CU_MEMORYTYPE_DEVICE;
263  cpy.srcDevice = (CUdeviceptr)src->data[i];
264  } else {
265  cpy.srcMemoryType = CU_MEMORYTYPE_HOST;
266  cpy.srcHost = src->data[i];
267  }
268 
269  if (dst->hw_frames_ctx) {
270  cpy.dstMemoryType = CU_MEMORYTYPE_DEVICE;
271  cpy.dstDevice = (CUdeviceptr)dst->data[i];
272  } else {
273  cpy.dstMemoryType = CU_MEMORYTYPE_HOST;
274  cpy.dstHost = dst->data[i];
275  }
276 
277  ret = CHECK_CU(cu->cuMemcpy2DAsync(&cpy, hwctx->stream));
278  if (ret < 0)
279  goto exit;
280  }
281 
282  if (!dst->hw_frames_ctx) {
283  ret = CHECK_CU(cu->cuStreamSynchronize(hwctx->stream));
284  if (ret < 0)
285  goto exit;
286  }
287 
288 exit:
289  CHECK_CU(cu->cuCtxPopCurrent(&dummy));
290 
291  return 0;
292 }
293 
294 static void cuda_device_uninit(AVHWDeviceContext *device_ctx)
295 {
296  CUDADeviceContext *hwctx = device_ctx->hwctx;
297 
298  if (hwctx->p.internal) {
299  CudaFunctions *cu = hwctx->internal.cuda_dl;
300 
301  if (hwctx->internal.is_allocated && hwctx->p.cuda_ctx) {
303  CHECK_CU(cu->cuDevicePrimaryCtxRelease(hwctx->internal.cuda_device));
304  else if (!(hwctx->internal.flags & AV_CUDA_USE_CURRENT_CONTEXT))
305  CHECK_CU(cu->cuCtxDestroy(hwctx->p.cuda_ctx));
306 
307  hwctx->p.cuda_ctx = NULL;
308  }
309 
310  cuda_free_functions(&hwctx->internal.cuda_dl);
311  memset(&hwctx->internal, 0, sizeof(hwctx->internal));
312  hwctx->p.internal = NULL;
313  }
314 }
315 
317 {
318  CUDADeviceContext *hwctx = ctx->hwctx;
319  int ret;
320 
321  hwctx->p.internal = &hwctx->internal;
322 
323  if (!hwctx->internal.cuda_dl) {
324  ret = cuda_load_functions(&hwctx->internal.cuda_dl, ctx);
325  if (ret < 0) {
326  av_log(ctx, AV_LOG_ERROR, "Could not dynamically load CUDA\n");
327  goto error;
328  }
329  }
330 
331  return 0;
332 
333 error:
335  return ret;
336 }
337 
338 static int cuda_context_init(AVHWDeviceContext *device_ctx, int flags) {
339  AVCUDADeviceContext *hwctx = device_ctx->hwctx;
340  CudaFunctions *cu;
341  CUcontext dummy;
342  int ret, dev_active = 0;
343  unsigned int dev_flags = 0;
344 
345  const unsigned int desired_flags = CU_CTX_SCHED_BLOCKING_SYNC;
346 
347  cu = hwctx->internal->cuda_dl;
348 
349  hwctx->internal->flags = flags;
350 
352  ret = CHECK_CU(cu->cuDevicePrimaryCtxGetState(hwctx->internal->cuda_device,
353  &dev_flags, &dev_active));
354  if (ret < 0)
355  return ret;
356 
357  if (dev_active && dev_flags != desired_flags) {
358  av_log(device_ctx, AV_LOG_ERROR, "Primary context already active with incompatible flags.\n");
359  return AVERROR(ENOTSUP);
360  } else if (dev_flags != desired_flags) {
361  ret = CHECK_CU(cu->cuDevicePrimaryCtxSetFlags(hwctx->internal->cuda_device,
362  desired_flags));
363  if (ret < 0)
364  return ret;
365  }
366 
367  ret = CHECK_CU(cu->cuDevicePrimaryCtxRetain(&hwctx->cuda_ctx,
368  hwctx->internal->cuda_device));
369  if (ret < 0)
370  return ret;
371  } else if (flags & AV_CUDA_USE_CURRENT_CONTEXT) {
372  ret = CHECK_CU(cu->cuCtxGetCurrent(&hwctx->cuda_ctx));
373  if (ret < 0)
374  return ret;
375  av_log(device_ctx, AV_LOG_INFO, "Using current CUDA context.\n");
376  } else {
377  ret = CHECK_CU(cu->cuCtxCreate(&hwctx->cuda_ctx, desired_flags,
378  hwctx->internal->cuda_device));
379  if (ret < 0)
380  return ret;
381 
382  CHECK_CU(cu->cuCtxPopCurrent(&dummy));
383  }
384 
385  hwctx->internal->is_allocated = 1;
386 
387  // Setting stream to NULL will make functions automatically use the default CUstream
388  hwctx->stream = NULL;
389 
390  return 0;
391 }
392 
394  AVDictionary *opts, int *flags)
395 {
396  AVDictionaryEntry *primary_ctx_opt = av_dict_get(opts, "primary_ctx", NULL, 0);
397  AVDictionaryEntry *current_ctx_opt = av_dict_get(opts, "current_ctx", NULL, 0);
398 
399  int use_primary_ctx = 0, use_current_ctx = 0;
400  if (primary_ctx_opt)
401  use_primary_ctx = strtol(primary_ctx_opt->value, NULL, 10);
402 
403  if (current_ctx_opt)
404  use_current_ctx = strtol(current_ctx_opt->value, NULL, 10);
405 
406  if (use_primary_ctx && use_current_ctx) {
407  av_log(device_ctx, AV_LOG_ERROR, "Requested both primary and current CUDA context simultaneously.\n");
408  return AVERROR(EINVAL);
409  }
410 
411  if (primary_ctx_opt && use_primary_ctx) {
412  av_log(device_ctx, AV_LOG_VERBOSE, "Using CUDA primary device context\n");
414  } else if (primary_ctx_opt) {
415  av_log(device_ctx, AV_LOG_VERBOSE, "Disabling use of CUDA primary device context\n");
417  }
418 
419  if (current_ctx_opt && use_current_ctx) {
420  av_log(device_ctx, AV_LOG_VERBOSE, "Using CUDA current device context\n");
422  } else if (current_ctx_opt) {
423  av_log(device_ctx, AV_LOG_VERBOSE, "Disabling use of CUDA current device context\n");
425  }
426 
427  return 0;
428 }
429 
430 static int cuda_device_create(AVHWDeviceContext *device_ctx,
431  const char *device,
432  AVDictionary *opts, int flags)
433 {
434  AVCUDADeviceContext *hwctx = device_ctx->hwctx;
435  CudaFunctions *cu;
436  int ret, device_idx = 0;
437 
438  ret = cuda_flags_from_opts(device_ctx, opts, &flags);
439  if (ret < 0)
440  goto error;
441 
442  if (device)
443  device_idx = strtol(device, NULL, 0);
444 
445  ret = cuda_device_init(device_ctx);
446  if (ret < 0)
447  goto error;
448 
449  cu = hwctx->internal->cuda_dl;
450 
451  ret = CHECK_CU(cu->cuInit(0));
452  if (ret < 0)
453  goto error;
454 
455  ret = CHECK_CU(cu->cuDeviceGet(&hwctx->internal->cuda_device, device_idx));
456  if (ret < 0)
457  goto error;
458 
459  ret = cuda_context_init(device_ctx, flags);
460  if (ret < 0)
461  goto error;
462 
463  return 0;
464 
465 error:
466  cuda_device_uninit(device_ctx);
467  return ret;
468 }
469 
470 static int cuda_device_derive(AVHWDeviceContext *device_ctx,
472  int flags) {
473  AVCUDADeviceContext *hwctx = device_ctx->hwctx;
474  CudaFunctions *cu;
475  const char *src_uuid = NULL;
476 #if CONFIG_VULKAN
477  VkPhysicalDeviceIDProperties vk_idp;
478 #endif
479  int ret, i, device_count;
480 
481  ret = cuda_flags_from_opts(device_ctx, opts, &flags);
482  if (ret < 0)
483  goto error;
484 
485 #if CONFIG_VULKAN
486  vk_idp = (VkPhysicalDeviceIDProperties) {
487  .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES,
488  };
489 #endif
490 
491  switch (src_ctx->type) {
492 #if CONFIG_VULKAN
493 #define TYPE PFN_vkGetPhysicalDeviceProperties2
495  AVVulkanDeviceContext *vkctx = src_ctx->hwctx;
496  TYPE prop_fn = (TYPE)vkctx->get_proc_addr(vkctx->inst, "vkGetPhysicalDeviceProperties2");
497  VkPhysicalDeviceProperties2 vk_dev_props = {
498  .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
499  .pNext = &vk_idp,
500  };
501  prop_fn(vkctx->phys_dev, &vk_dev_props);
502  src_uuid = vk_idp.deviceUUID;
503  break;
504  }
505 #undef TYPE
506 #endif
507  default:
508  ret = AVERROR(ENOSYS);
509  goto error;
510  }
511 
512  if (!src_uuid) {
513  av_log(device_ctx, AV_LOG_ERROR,
514  "Failed to get UUID of source device.\n");
515  ret = AVERROR(EINVAL);
516  goto error;
517  }
518 
519  ret = cuda_device_init(device_ctx);
520  if (ret < 0)
521  goto error;
522 
523  cu = hwctx->internal->cuda_dl;
524 
525  ret = CHECK_CU(cu->cuInit(0));
526  if (ret < 0)
527  goto error;
528 
529  ret = CHECK_CU(cu->cuDeviceGetCount(&device_count));
530  if (ret < 0)
531  goto error;
532 
533  hwctx->internal->cuda_device = -1;
534  for (i = 0; i < device_count; i++) {
535  CUdevice dev;
536  CUuuid uuid;
537 
538  ret = CHECK_CU(cu->cuDeviceGet(&dev, i));
539  if (ret < 0)
540  goto error;
541 
542  ret = CHECK_CU(cu->cuDeviceGetUuid(&uuid, dev));
543  if (ret < 0)
544  goto error;
545 
546  if (memcmp(src_uuid, uuid.bytes, sizeof (uuid.bytes)) == 0) {
547  hwctx->internal->cuda_device = dev;
548  break;
549  }
550  }
551 
552  if (hwctx->internal->cuda_device == -1) {
553  av_log(device_ctx, AV_LOG_ERROR, "Could not derive CUDA device.\n");
554  goto error;
555  }
556 
557  ret = cuda_context_init(device_ctx, flags);
558  if (ret < 0)
559  goto error;
560 
561  return 0;
562 
563 error:
564  cuda_device_uninit(device_ctx);
565  return ret;
566 }
567 
570  .name = "CUDA",
571 
572  .device_hwctx_size = sizeof(CUDADeviceContext),
573  .frames_hwctx_size = sizeof(CUDAFramesContext),
574 
575  .device_create = cuda_device_create,
576  .device_derive = cuda_device_derive,
577  .device_init = cuda_device_init,
578  .device_uninit = cuda_device_uninit,
579  .frames_get_constraints = cuda_frames_get_constraints,
580  .frames_init = cuda_frames_init,
581  .frames_get_buffer = cuda_get_buffer,
582  .transfer_get_formats = cuda_transfer_get_formats,
583  .transfer_data_to = cuda_transfer_data,
584  .transfer_data_from = cuda_transfer_data,
585 
586  .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_CUDA, AV_PIX_FMT_NONE },
587 };
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:32
flags
const SwsFlags flags[]
Definition: swscale.c:61
formats
formats
Definition: signature.h:47
AVHWDeviceContext::hwctx
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:88
FFHWFramesContext::pool_internal
AVBufferPool * pool_internal
Definition: hwcontext_internal.h:101
AVVulkanDeviceContext::phys_dev
VkPhysicalDevice phys_dev
Physical device.
Definition: hwcontext_vulkan.h:79
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:260
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
AVCUDADeviceContextInternal
Definition: hwcontext_cuda_internal.h:31
cuda_context_init
static int cuda_context_init(AVHWDeviceContext *device_ctx, int flags)
Definition: hwcontext_cuda.c:338
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
cuda_device_derive
static int cuda_device_derive(AVHWDeviceContext *device_ctx, AVHWDeviceContext *src_ctx, AVDictionary *opts, int flags)
Definition: hwcontext_cuda.c:470
hwcontext_cuda_internal.h
cuda_transfer_get_formats
static int cuda_transfer_get_formats(AVHWFramesContext *ctx, enum AVHWFrameTransferDirection dir, enum AVPixelFormat **formats)
Definition: hwcontext_cuda.c:216
AV_PIX_FMT_BGR32
#define AV_PIX_FMT_BGR32
Definition: pixfmt.h:513
cuda_flags_from_opts
static int cuda_flags_from_opts(AVHWDeviceContext *device_ctx, AVDictionary *opts, int *flags)
Definition: hwcontext_cuda.c:393
CUDAFramesContext
Definition: hwcontext_cuda.c:33
AV_PIX_FMT_YUV444P10MSB
#define AV_PIX_FMT_YUV444P10MSB
Definition: pixfmt.h:554
CHECK_CU
#define CHECK_CU(x)
Definition: hwcontext_cuda.c:65
AVCUDADeviceContextInternal::is_allocated
int is_allocated
Definition: hwcontext_cuda_internal.h:33
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:421
pixdesc.h
CUDADeviceContext::internal
AVCUDADeviceContextInternal internal
Definition: hwcontext_cuda.c:40
AVVulkanDeviceContext::get_proc_addr
PFN_vkGetInstanceProcAddr get_proc_addr
Pointer to a vkGetInstanceProcAddr loading function.
Definition: hwcontext_vulkan.h:69
data
const char data[16]
Definition: mxf.c:149
AVVulkanDeviceContext::inst
VkInstance inst
Vulkan instance.
Definition: hwcontext_vulkan.h:74
AV_LOG_VERBOSE
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:226
AVDictionary
Definition: dict.c:32
AVHWFramesConstraints::valid_hw_formats
enum AVPixelFormat * valid_hw_formats
A list of possible values for format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
Definition: hwcontext.h:449
AV_PIX_FMT_VULKAN
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
Definition: pixfmt.h:379
AV_PIX_FMT_YUV444P12MSB
#define AV_PIX_FMT_YUV444P12MSB
Definition: pixfmt.h:555
AV_HWDEVICE_TYPE_VULKAN
@ AV_HWDEVICE_TYPE_VULKAN
Definition: hwcontext.h:39
AVHWFramesConstraints
This struct describes the constraints on hardware frames attached to a given device with a hardware-s...
Definition: hwcontext.h:444
CUDADeviceContext::p
AVCUDADeviceContext p
Definition: hwcontext_cuda.c:39
AV_HWDEVICE_TYPE_CUDA
@ AV_HWDEVICE_TYPE_CUDA
Definition: hwcontext.h:30
fail
#define fail()
Definition: checkasm.h:199
dummy
int dummy
Definition: motion.c:66
av_buffer_pool_init2
AVBufferPool * av_buffer_pool_init2(size_t size, void *opaque, AVBufferRef *(*alloc)(void *opaque, size_t size), void(*pool_free)(void *opaque))
Allocate and initialize a buffer pool with a more complex allocator.
Definition: buffer.c:259
AVCUDADeviceContextInternal::cuda_device
CUdevice cuda_device
Definition: hwcontext_cuda_internal.h:34
av_pix_fmt_get_chroma_sub_sample
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
Definition: pixdesc.c:3469
AVCUDADeviceContext::cuda_ctx
CUcontext cuda_ctx
Definition: hwcontext_cuda.h:43
AVHWDeviceContext
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:63
HWContextType::type
enum AVHWDeviceType type
Definition: hwcontext_internal.h:30
ffhwframesctx
static FFHWFramesContext * ffhwframesctx(AVHWFramesContext *ctx)
Definition: hwcontext_internal.h:115
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
AVHWFramesConstraints::valid_sw_formats
enum AVPixelFormat * valid_sw_formats
A list of possible values for sw_format in the hw_frames_ctx, terminated by AV_PIX_FMT_NONE.
Definition: hwcontext.h:456
av_dict_get
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:60
av_buffer_pool_get
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
Definition: buffer.c:390
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:108
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:552
AV_PIX_FMT_0BGR32
#define AV_PIX_FMT_0BGR32
Definition: pixfmt.h:516
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:231
ctx
AVFormatContext * ctx
Definition: movenc.c:49
cuda_device_init
static int cuda_device_init(AVHWDeviceContext *ctx)
Definition: hwcontext_cuda.c:316
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
AVVulkanDeviceContext
Main Vulkan context, allocated as AVHWDeviceContext.hwctx.
Definition: hwcontext_vulkan.h:59
opts
AVDictionary * opts
Definition: movenc.c:51
TYPE
#define TYPE
Definition: ffv1dec.c:96
AV_CUDA_USE_CURRENT_CONTEXT
#define AV_CUDA_USE_CURRENT_CONTEXT
Use current device context instead of creating a new one.
Definition: hwcontext_cuda.h:68
NULL
#define NULL
Definition: coverity.c:32
AVCUDADeviceContextInternal::flags
int flags
Definition: hwcontext_cuda_internal.h:35
hwcontext_vulkan.h
CUDAFramesContext::shift_width
int shift_width
Definition: hwcontext_cuda.c:34
cuda_transfer_data
static int cuda_transfer_data(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
Definition: hwcontext_cuda.c:234
av_buffer_create
AVBufferRef * av_buffer_create(uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:55
AVCUDADeviceContext::stream
CUstream stream
Definition: hwcontext_cuda.h:44
AVCUDADeviceContext::internal
AVCUDADeviceContextInternal * internal
Definition: hwcontext_cuda.h:45
CUDAFramesContext::tex_alignment
int tex_alignment
Definition: hwcontext_cuda.c:35
av_image_fill_arrays
int av_image_fill_arrays(uint8_t *dst_data[4], int dst_linesize[4], const uint8_t *src, enum AVPixelFormat pix_fmt, int width, int height, int align)
Setup the data pointers and linesizes based on the specified image parameters and the provided array.
Definition: imgutils.c:446
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
CUDAFramesContext::shift_height
int shift_height
Definition: hwcontext_cuda.c:34
size
int size
Definition: twinvq_data.h:10344
ff_hwcontext_type_cuda
const HWContextType ff_hwcontext_type_cuda
Definition: hwcontext_cuda.c:568
AV_PIX_FMT_NV16
@ AV_PIX_FMT_NV16
interleaved chroma YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:198
buffer.h
AV_PIX_FMT_RGB32
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:511
av_image_get_buffer_size
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
Return the size in bytes of the amount of data required to store an image with the given parameters.
Definition: imgutils.c:466
AV_PIX_FMT_P216
#define AV_PIX_FMT_P216
Definition: pixfmt.h:620
AV_PIX_FMT_P210
#define AV_PIX_FMT_P210
Definition: pixfmt.h:616
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:221
AVCUDADeviceContextInternal::cuda_dl
CudaFunctions * cuda_dl
Definition: hwcontext_cuda_internal.h:32
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
common.h
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
cuda_device_uninit
static void cuda_device_uninit(AVHWDeviceContext *device_ctx)
Definition: hwcontext_cuda.c:294
AV_PIX_FMT_P016
#define AV_PIX_FMT_P016
Definition: pixfmt.h:604
AVHWFrameTransferDirection
AVHWFrameTransferDirection
Definition: hwcontext.h:406
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:118
AVCUDADeviceContext
This struct is allocated as AVHWDeviceContext.hwctx.
Definition: hwcontext_cuda.h:42
ret
ret
Definition: filter_design.txt:187
AVHWDeviceContext::type
enum AVHWDeviceType type
This field identifies the underlying API used for hardware access.
Definition: hwcontext.h:75
pixfmt.h
AV_PIX_FMT_NV12
@ AV_PIX_FMT_NV12
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:96
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:265
AV_PIX_FMT_0RGB32
#define AV_PIX_FMT_0RGB32
Definition: pixfmt.h:515
cuda_check.h
cuda_buffer_free
static void cuda_buffer_free(void *opaque, uint8_t *data)
Definition: hwcontext_cuda.c:92
AV_CUDA_USE_PRIMARY_CONTEXT
#define AV_CUDA_USE_PRIMARY_CONTEXT
Use primary device context instead of creating a new one.
Definition: hwcontext_cuda.h:63
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
cuda_device_create
static int cuda_device_create(AVHWDeviceContext *device_ctx, const char *device, AVDictionary *opts, int flags)
Definition: hwcontext_cuda.c:430
supported_formats
static enum AVPixelFormat supported_formats[]
Definition: hwcontext_cuda.c:43
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
cuda_get_buffer
static int cuda_get_buffer(AVHWFramesContext *ctx, AVFrame *frame)
Definition: hwcontext_cuda.c:187
AV_PIX_FMT_P010
#define AV_PIX_FMT_P010
Definition: pixfmt.h:602
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
cuda_pool_alloc
static AVBufferRef * cuda_pool_alloc(void *opaque, size_t size)
Definition: hwcontext_cuda.c:108
hwcontext_internal.h
AVDictionaryEntry
Definition: dict.h:90
imgutils.h
hwcontext.h
CUDADeviceContext
Definition: hwcontext_cuda.c:38
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
HWContextType
Definition: hwcontext_internal.h:29
cuda_frames_get_constraints
static int cuda_frames_get_constraints(AVHWDeviceContext *ctx, const void *hwconfig, AVHWFramesConstraints *constraints)
Definition: hwcontext_cuda.c:67
cuda_frames_init
static int cuda_frames_init(AVHWFramesContext *ctx)
Definition: hwcontext_cuda.c:139
AVDictionaryEntry::value
char * value
Definition: dict.h:92
src
#define src
Definition: vp8dsp.c:248
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:3361