FFmpeg
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[] = {
66 #if CONFIG_VULKAN
68 #endif
69 };
70 
71 #define CHECK_CU(x) FF_CUDA_CHECK_DL(device_ctx, cu, x)
72 
74  const void *hwconfig,
75  AVHWFramesConstraints *constraints)
76 {
77  int i;
78 
80  sizeof(*constraints->valid_sw_formats));
81  if (!constraints->valid_sw_formats)
82  return AVERROR(ENOMEM);
83 
84  for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++)
85  constraints->valid_sw_formats[i] = supported_formats[i];
87 
88  constraints->valid_hw_formats = av_malloc_array(2, sizeof(*constraints->valid_hw_formats));
89  if (!constraints->valid_hw_formats)
90  return AVERROR(ENOMEM);
91 
92  constraints->valid_hw_formats[0] = AV_PIX_FMT_CUDA;
93  constraints->valid_hw_formats[1] = AV_PIX_FMT_NONE;
94 
95  return 0;
96 }
97 
98 static void cuda_buffer_free(void *opaque, uint8_t *data)
99 {
100  AVHWFramesContext *ctx = opaque;
101  AVHWDeviceContext *device_ctx = ctx->device_ctx;
102  AVCUDADeviceContext *hwctx = device_ctx->hwctx;
103  CudaFunctions *cu = hwctx->internal->cuda_dl;
104 
105  CUcontext dummy;
106 
107  CHECK_CU(cu->cuCtxPushCurrent(hwctx->cuda_ctx));
108 
109  CHECK_CU(cu->cuMemFree((CUdeviceptr)data));
110 
111  CHECK_CU(cu->cuCtxPopCurrent(&dummy));
112 }
113 
114 static AVBufferRef *cuda_pool_alloc(void *opaque, size_t size)
115 {
116  AVHWFramesContext *ctx = opaque;
117  AVHWDeviceContext *device_ctx = ctx->device_ctx;
118  AVCUDADeviceContext *hwctx = device_ctx->hwctx;
119  CudaFunctions *cu = hwctx->internal->cuda_dl;
120 
121  AVBufferRef *ret = NULL;
122  CUcontext dummy = NULL;
123  CUdeviceptr data;
124  int err;
125 
126  err = CHECK_CU(cu->cuCtxPushCurrent(hwctx->cuda_ctx));
127  if (err < 0)
128  return NULL;
129 
130  err = CHECK_CU(cu->cuMemAlloc(&data, size));
131  if (err < 0)
132  goto fail;
133 
134  ret = av_buffer_create((uint8_t*)data, size, cuda_buffer_free, ctx, 0);
135  if (!ret) {
136  CHECK_CU(cu->cuMemFree(data));
137  goto fail;
138  }
139 
140 fail:
141  CHECK_CU(cu->cuCtxPopCurrent(&dummy));
142  return ret;
143 }
144 
146 {
147  AVHWDeviceContext *device_ctx = ctx->device_ctx;
148  AVCUDADeviceContext *hwctx = device_ctx->hwctx;
149  CUDAFramesContext *priv = ctx->hwctx;
150  CudaFunctions *cu = hwctx->internal->cuda_dl;
151  int err, i;
152 
153  for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
154  if (ctx->sw_format == supported_formats[i])
155  break;
156  }
158  av_log(ctx, AV_LOG_ERROR, "Pixel format '%s' is not supported\n",
159  av_get_pix_fmt_name(ctx->sw_format));
160  return AVERROR(ENOSYS);
161  }
162 
163  err = CHECK_CU(cu->cuDeviceGetAttribute(&priv->tex_alignment,
164  14 /* CU_DEVICE_ATTRIBUTE_TEXTURE_ALIGNMENT */,
165  hwctx->internal->cuda_device));
166  if (err < 0)
167  return err;
168 
169  av_log(ctx, AV_LOG_DEBUG, "CUDA texture alignment: %d\n", priv->tex_alignment);
170 
171  // YUV420P is a special case.
172  // Since nvenc expects the U/V planes to have half the linesize of the Y plane
173  // alignment has to be doubled to ensure the U/V planes still end up aligned.
174  if (ctx->sw_format == AV_PIX_FMT_YUV420P)
175  priv->tex_alignment *= 2;
176 
177  av_pix_fmt_get_chroma_sub_sample(ctx->sw_format, &priv->shift_width, &priv->shift_height);
178 
179  if (!ctx->pool) {
180  int size = av_image_get_buffer_size(ctx->sw_format, ctx->width, ctx->height, priv->tex_alignment);
181  if (size < 0)
182  return size;
183 
186  if (!ffhwframesctx(ctx)->pool_internal)
187  return AVERROR(ENOMEM);
188  }
189 
190  return 0;
191 }
192 
194 {
195  CUDAFramesContext *priv = ctx->hwctx;
196  int res;
197 
198  frame->buf[0] = av_buffer_pool_get(ctx->pool);
199  if (!frame->buf[0])
200  return AVERROR(ENOMEM);
201 
202  res = av_image_fill_arrays(frame->data, frame->linesize, frame->buf[0]->data,
203  ctx->sw_format, ctx->width, ctx->height, priv->tex_alignment);
204  if (res < 0)
205  return res;
206 
207  // YUV420P is a special case.
208  // Nvenc expects the U/V planes in swapped order from how ffmpeg expects them, also chroma is half-aligned
209  if (ctx->sw_format == AV_PIX_FMT_YUV420P) {
210  frame->linesize[1] = frame->linesize[2] = frame->linesize[0] / 2;
211  frame->data[2] = frame->data[1];
212  frame->data[1] = frame->data[2] + frame->linesize[2] * (ctx->height / 2);
213  }
214 
215  frame->format = AV_PIX_FMT_CUDA;
216  frame->width = ctx->width;
217  frame->height = ctx->height;
218 
219  return 0;
220 }
221 
224  enum AVPixelFormat **formats)
225 {
226  enum AVPixelFormat *fmts;
227 
228  fmts = av_malloc_array(2, sizeof(*fmts));
229  if (!fmts)
230  return AVERROR(ENOMEM);
231 
232  fmts[0] = ctx->sw_format;
233  fmts[1] = AV_PIX_FMT_NONE;
234 
235  *formats = fmts;
236 
237  return 0;
238 }
239 
241  const AVFrame *src)
242 {
243  CUDAFramesContext *priv = ctx->hwctx;
244  AVHWDeviceContext *device_ctx = ctx->device_ctx;
245  AVCUDADeviceContext *hwctx = device_ctx->hwctx;
246  CudaFunctions *cu = hwctx->internal->cuda_dl;
247 
248  CUcontext dummy;
249  int i, ret;
250 
251  if ((src->hw_frames_ctx && ((AVHWFramesContext*)src->hw_frames_ctx->data)->format != AV_PIX_FMT_CUDA) ||
252  (dst->hw_frames_ctx && ((AVHWFramesContext*)dst->hw_frames_ctx->data)->format != AV_PIX_FMT_CUDA))
253  return AVERROR(ENOSYS);
254 
255  ret = CHECK_CU(cu->cuCtxPushCurrent(hwctx->cuda_ctx));
256  if (ret < 0)
257  return ret;
258 
259  for (i = 0; i < FF_ARRAY_ELEMS(src->data) && src->data[i]; i++) {
260  CUDA_MEMCPY2D cpy = {
261  .srcPitch = src->linesize[i],
262  .dstPitch = dst->linesize[i],
263  .WidthInBytes = FFMIN(src->linesize[i], dst->linesize[i]),
264  .Height = src->height >> ((i == 0 || i == 3) ? 0 : priv->shift_height),
265  };
266 
267  if (src->hw_frames_ctx) {
268  cpy.srcMemoryType = CU_MEMORYTYPE_DEVICE;
269  cpy.srcDevice = (CUdeviceptr)src->data[i];
270  } else {
271  cpy.srcMemoryType = CU_MEMORYTYPE_HOST;
272  cpy.srcHost = src->data[i];
273  }
274 
275  if (dst->hw_frames_ctx) {
276  cpy.dstMemoryType = CU_MEMORYTYPE_DEVICE;
277  cpy.dstDevice = (CUdeviceptr)dst->data[i];
278  } else {
279  cpy.dstMemoryType = CU_MEMORYTYPE_HOST;
280  cpy.dstHost = dst->data[i];
281  }
282 
283  ret = CHECK_CU(cu->cuMemcpy2DAsync(&cpy, hwctx->stream));
284  if (ret < 0)
285  goto exit;
286  }
287 
288  if (!dst->hw_frames_ctx) {
289  ret = CHECK_CU(cu->cuStreamSynchronize(hwctx->stream));
290  if (ret < 0)
291  goto exit;
292  }
293 
294 exit:
295  CHECK_CU(cu->cuCtxPopCurrent(&dummy));
296 
297  return 0;
298 }
299 
300 static void cuda_device_uninit(AVHWDeviceContext *device_ctx)
301 {
302  CUDADeviceContext *hwctx = device_ctx->hwctx;
303 
304  if (hwctx->p.internal) {
305  CudaFunctions *cu = hwctx->internal.cuda_dl;
306 
307  if (hwctx->internal.is_allocated && hwctx->p.cuda_ctx) {
309  CHECK_CU(cu->cuDevicePrimaryCtxRelease(hwctx->internal.cuda_device));
310  else if (!(hwctx->internal.flags & AV_CUDA_USE_CURRENT_CONTEXT))
311  CHECK_CU(cu->cuCtxDestroy(hwctx->p.cuda_ctx));
312 
313  hwctx->p.cuda_ctx = NULL;
314  }
315 
316  cuda_free_functions(&hwctx->internal.cuda_dl);
317  memset(&hwctx->internal, 0, sizeof(hwctx->internal));
318  hwctx->p.internal = NULL;
319  }
320 }
321 
323 {
324  CUDADeviceContext *hwctx = ctx->hwctx;
325  int ret;
326 
327  hwctx->p.internal = &hwctx->internal;
328 
329  if (!hwctx->internal.cuda_dl) {
330  ret = cuda_load_functions(&hwctx->internal.cuda_dl, ctx);
331  if (ret < 0) {
332  av_log(ctx, AV_LOG_ERROR, "Could not dynamically load CUDA\n");
333  goto error;
334  }
335  }
336 
337  return 0;
338 
339 error:
341  return ret;
342 }
343 
344 static int cuda_context_init(AVHWDeviceContext *device_ctx, int flags) {
345  AVCUDADeviceContext *hwctx = device_ctx->hwctx;
346  CudaFunctions *cu;
347  CUcontext dummy;
348  int ret, dev_active = 0;
349  unsigned int dev_flags = 0;
350 
351  const unsigned int desired_flags = CU_CTX_SCHED_BLOCKING_SYNC;
352 
353  cu = hwctx->internal->cuda_dl;
354 
355  hwctx->internal->flags = flags;
356 
358  ret = CHECK_CU(cu->cuDevicePrimaryCtxGetState(hwctx->internal->cuda_device,
359  &dev_flags, &dev_active));
360  if (ret < 0)
361  return ret;
362 
363  if (dev_active && dev_flags != desired_flags) {
364  av_log(device_ctx, AV_LOG_ERROR, "Primary context already active with incompatible flags.\n");
365  return AVERROR(ENOTSUP);
366  } else if (dev_flags != desired_flags) {
367  ret = CHECK_CU(cu->cuDevicePrimaryCtxSetFlags(hwctx->internal->cuda_device,
368  desired_flags));
369  if (ret < 0)
370  return ret;
371  }
372 
373  ret = CHECK_CU(cu->cuDevicePrimaryCtxRetain(&hwctx->cuda_ctx,
374  hwctx->internal->cuda_device));
375  if (ret < 0)
376  return ret;
377  } else if (flags & AV_CUDA_USE_CURRENT_CONTEXT) {
378  ret = CHECK_CU(cu->cuCtxGetCurrent(&hwctx->cuda_ctx));
379  if (ret < 0)
380  return ret;
381  av_log(device_ctx, AV_LOG_INFO, "Using current CUDA context.\n");
382  } else {
383  ret = CHECK_CU(cu->cuCtxCreate(&hwctx->cuda_ctx, desired_flags,
384  hwctx->internal->cuda_device));
385  if (ret < 0)
386  return ret;
387 
388  CHECK_CU(cu->cuCtxPopCurrent(&dummy));
389  }
390 
391  hwctx->internal->is_allocated = 1;
392 
393  // Setting stream to NULL will make functions automatically use the default CUstream
394  hwctx->stream = NULL;
395 
396  return 0;
397 }
398 
400  AVDictionary *opts, int *flags)
401 {
402  AVDictionaryEntry *primary_ctx_opt = av_dict_get(opts, "primary_ctx", NULL, 0);
403  AVDictionaryEntry *current_ctx_opt = av_dict_get(opts, "current_ctx", NULL, 0);
404 
405  int use_primary_ctx = 0, use_current_ctx = 0;
406  if (primary_ctx_opt)
407  use_primary_ctx = strtol(primary_ctx_opt->value, NULL, 10);
408 
409  if (current_ctx_opt)
410  use_current_ctx = strtol(current_ctx_opt->value, NULL, 10);
411 
412  if (use_primary_ctx && use_current_ctx) {
413  av_log(device_ctx, AV_LOG_ERROR, "Requested both primary and current CUDA context simultaneously.\n");
414  return AVERROR(EINVAL);
415  }
416 
417  if (primary_ctx_opt && use_primary_ctx) {
418  av_log(device_ctx, AV_LOG_VERBOSE, "Using CUDA primary device context\n");
420  } else if (primary_ctx_opt) {
421  av_log(device_ctx, AV_LOG_VERBOSE, "Disabling use of CUDA primary device context\n");
423  }
424 
425  if (current_ctx_opt && use_current_ctx) {
426  av_log(device_ctx, AV_LOG_VERBOSE, "Using CUDA current device context\n");
428  } else if (current_ctx_opt) {
429  av_log(device_ctx, AV_LOG_VERBOSE, "Disabling use of CUDA current device context\n");
431  }
432 
433  return 0;
434 }
435 
436 static int cuda_device_create(AVHWDeviceContext *device_ctx,
437  const char *device,
438  AVDictionary *opts, int flags)
439 {
440  AVCUDADeviceContext *hwctx = device_ctx->hwctx;
441  CudaFunctions *cu;
442  int ret, device_idx = 0;
443 
444  ret = cuda_flags_from_opts(device_ctx, opts, &flags);
445  if (ret < 0)
446  goto error;
447 
448  if (device)
449  device_idx = strtol(device, NULL, 0);
450 
451  ret = cuda_device_init(device_ctx);
452  if (ret < 0)
453  goto error;
454 
455  cu = hwctx->internal->cuda_dl;
456 
457  ret = CHECK_CU(cu->cuInit(0));
458  if (ret < 0)
459  goto error;
460 
461  ret = CHECK_CU(cu->cuDeviceGet(&hwctx->internal->cuda_device, device_idx));
462  if (ret < 0)
463  goto error;
464 
465  ret = cuda_context_init(device_ctx, flags);
466  if (ret < 0)
467  goto error;
468 
469  return 0;
470 
471 error:
472  cuda_device_uninit(device_ctx);
473  return ret;
474 }
475 
476 static int cuda_device_derive(AVHWDeviceContext *device_ctx,
478  int flags) {
479  AVCUDADeviceContext *hwctx = device_ctx->hwctx;
480  CudaFunctions *cu;
481  const char *src_uuid = NULL;
482 #if CONFIG_VULKAN
483  VkPhysicalDeviceIDProperties vk_idp;
484 #endif
485  int ret, i, device_count;
486 
487  ret = cuda_flags_from_opts(device_ctx, opts, &flags);
488  if (ret < 0)
489  goto error;
490 
491 #if CONFIG_VULKAN
492  vk_idp = (VkPhysicalDeviceIDProperties) {
493  .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES,
494  };
495 #endif
496 
497  switch (src_ctx->type) {
498 #if CONFIG_VULKAN
499 #define TYPE PFN_vkGetPhysicalDeviceProperties2
501  AVVulkanDeviceContext *vkctx = src_ctx->hwctx;
502  TYPE prop_fn = (TYPE)vkctx->get_proc_addr(vkctx->inst, "vkGetPhysicalDeviceProperties2");
503  VkPhysicalDeviceProperties2 vk_dev_props = {
504  .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2,
505  .pNext = &vk_idp,
506  };
507  prop_fn(vkctx->phys_dev, &vk_dev_props);
508  src_uuid = vk_idp.deviceUUID;
509  break;
510  }
511 #undef TYPE
512 #endif
513  default:
514  ret = AVERROR(ENOSYS);
515  goto error;
516  }
517 
518  if (!src_uuid) {
519  av_log(device_ctx, AV_LOG_ERROR,
520  "Failed to get UUID of source device.\n");
521  ret = AVERROR(EINVAL);
522  goto error;
523  }
524 
525  ret = cuda_device_init(device_ctx);
526  if (ret < 0)
527  goto error;
528 
529  cu = hwctx->internal->cuda_dl;
530 
531  ret = CHECK_CU(cu->cuInit(0));
532  if (ret < 0)
533  goto error;
534 
535  ret = CHECK_CU(cu->cuDeviceGetCount(&device_count));
536  if (ret < 0)
537  goto error;
538 
539  hwctx->internal->cuda_device = -1;
540  for (i = 0; i < device_count; i++) {
541  CUdevice dev;
542  CUuuid uuid;
543 
544  ret = CHECK_CU(cu->cuDeviceGet(&dev, i));
545  if (ret < 0)
546  goto error;
547 
548  ret = CHECK_CU(cu->cuDeviceGetUuid(&uuid, dev));
549  if (ret < 0)
550  goto error;
551 
552  if (memcmp(src_uuid, uuid.bytes, sizeof (uuid.bytes)) == 0) {
553  hwctx->internal->cuda_device = dev;
554  break;
555  }
556  }
557 
558  if (hwctx->internal->cuda_device == -1) {
559  av_log(device_ctx, AV_LOG_ERROR, "Could not derive CUDA device.\n");
560  goto error;
561  }
562 
563  ret = cuda_context_init(device_ctx, flags);
564  if (ret < 0)
565  goto error;
566 
567  return 0;
568 
569 error:
570  cuda_device_uninit(device_ctx);
571  return ret;
572 }
573 
576  .name = "CUDA",
577 
578  .device_hwctx_size = sizeof(CUDADeviceContext),
579  .frames_hwctx_size = sizeof(CUDAFramesContext),
580 
581  .device_create = cuda_device_create,
582  .device_derive = cuda_device_derive,
583  .device_init = cuda_device_init,
584  .device_uninit = cuda_device_uninit,
585  .frames_get_constraints = cuda_frames_get_constraints,
586  .frames_init = cuda_frames_init,
587  .frames_get_buffer = cuda_get_buffer,
588  .transfer_get_formats = cuda_transfer_get_formats,
589  .transfer_data_to = cuda_transfer_data,
590  .transfer_data_from = cuda_transfer_data,
591 
592  .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_CUDA, AV_PIX_FMT_NONE },
593 };
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:32
flags
const SwsFlags flags[]
Definition: swscale.c:85
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:344
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:476
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:222
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:399
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:71
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:466
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
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:539
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
dummy
static int dummy
Definition: ffplay.c:3751
AV_PIX_FMT_VULKAN
@ AV_PIX_FMT_VULKAN
Vulkan hardware images.
Definition: pixfmt.h:379
AV_PIX_FMT_P212
#define AV_PIX_FMT_P212
Definition: pixfmt.h:618
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
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:3484
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
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:542
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
static AVFormatContext * ctx
Definition: movenc.c:49
cuda_device_init
static int cuda_device_init(AVHWDeviceContext *ctx)
Definition: hwcontext_cuda.c:322
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
fail
#define fail
Definition: test.h:478
AVVulkanDeviceContext
Main Vulkan context, allocated as AVHWDeviceContext.hwctx.
Definition: hwcontext_vulkan.h:59
opts
static 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
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:540
cuda_transfer_data
static int cuda_transfer_data(AVHWFramesContext *ctx, AVFrame *dst, const AVFrame *src)
Definition: hwcontext_cuda.c:240
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
AV_PIX_FMT_P012
#define AV_PIX_FMT_P012
Definition: pixfmt.h:603
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
i
#define i(width, name, range_min, range_max)
Definition: cbs_h264.c:63
size
int size
Definition: twinvq_data.h:10344
ff_hwcontext_type_cuda
const HWContextType ff_hwcontext_type_cuda
Definition: hwcontext_cuda.c:574
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
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:300
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:98
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:436
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:193
AV_PIX_FMT_P010
#define AV_PIX_FMT_P010
Definition: pixfmt.h:602
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:77
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:114
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:73
cuda_frames_init
static int cuda_frames_init(AVHWFramesContext *ctx)
Definition: hwcontext_cuda.c:145
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:3376