FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
nvdec.c
Go to the documentation of this file.
1 /*
2  * HW decode acceleration through NVDEC
3  *
4  * Copyright (c) 2016 Anton Khirnov
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "config.h"
24 
25 #include "libavutil/common.h"
26 #include "libavutil/error.h"
27 #include "libavutil/hwcontext.h"
29 #include "libavutil/pixdesc.h"
30 #include "libavutil/pixfmt.h"
31 
32 #include "avcodec.h"
33 #include "decode.h"
34 #include "nvdec.h"
35 #include "internal.h"
36 
37 typedef struct NVDECDecoder {
38  CUvideodecoder decoder;
39 
41  CUcontext cuda_ctx;
42  CUstream stream;
43 
44  CudaFunctions *cudl;
45  CuvidFunctions *cvdl;
46 } NVDECDecoder;
47 
48 typedef struct NVDECFramePool {
49  unsigned int dpb_size;
50  unsigned int nb_allocated;
52 
53 static int map_avcodec_id(enum AVCodecID id)
54 {
55  switch (id) {
56  case AV_CODEC_ID_H264: return cudaVideoCodec_H264;
57  case AV_CODEC_ID_HEVC: return cudaVideoCodec_HEVC;
58  case AV_CODEC_ID_MJPEG: return cudaVideoCodec_JPEG;
59  case AV_CODEC_ID_MPEG1VIDEO: return cudaVideoCodec_MPEG1;
60  case AV_CODEC_ID_MPEG2VIDEO: return cudaVideoCodec_MPEG2;
61  case AV_CODEC_ID_MPEG4: return cudaVideoCodec_MPEG4;
62  case AV_CODEC_ID_VC1: return cudaVideoCodec_VC1;
63  case AV_CODEC_ID_VP8: return cudaVideoCodec_VP8;
64  case AV_CODEC_ID_VP9: return cudaVideoCodec_VP9;
65  case AV_CODEC_ID_WMV3: return cudaVideoCodec_VC1;
66  }
67  return -1;
68 }
69 
71 {
72  int shift_h = 0, shift_v = 0;
73 
74  av_pix_fmt_get_chroma_sub_sample(pix_fmt, &shift_h, &shift_v);
75 
76  if (shift_h == 1 && shift_v == 1)
77  return cudaVideoChromaFormat_420;
78  else if (shift_h == 1 && shift_v == 0)
79  return cudaVideoChromaFormat_422;
80  else if (shift_h == 0 && shift_v == 0)
81  return cudaVideoChromaFormat_444;
82 
83  return -1;
84 }
85 
87  CUVIDDECODECREATEINFO *params, void *logctx)
88 {
89  CUresult err;
90  CUVIDDECODECAPS caps = { 0 };
91 
92  caps.eCodecType = params->CodecType;
93  caps.eChromaFormat = params->ChromaFormat;
94  caps.nBitDepthMinus8 = params->bitDepthMinus8;
95 
96  if (!decoder->cvdl->cuvidGetDecoderCaps) {
97  av_log(logctx, AV_LOG_WARNING, "Used Nvidia driver is too old to perform a capability check.\n");
98  av_log(logctx, AV_LOG_WARNING, "The minimum required version is "
99 #if defined(_WIN32) || defined(__CYGWIN__)
100  "378.66"
101 #else
102  "378.13"
103 #endif
104  ". Continuing blind.\n");
105  return 0;
106  }
107 
108  err = decoder->cvdl->cuvidGetDecoderCaps(&caps);
109  if (err != CUDA_SUCCESS) {
110  av_log(logctx, AV_LOG_ERROR, "Failed querying decoder capabilities\n");
111  return AVERROR_UNKNOWN;
112  }
113 
114  av_log(logctx, AV_LOG_VERBOSE, "NVDEC capabilities:\n");
115  av_log(logctx, AV_LOG_VERBOSE, "format supported: %s, max_mb_count: %d\n",
116  caps.bIsSupported ? "yes" : "no", caps.nMaxMBCount);
117  av_log(logctx, AV_LOG_VERBOSE, "min_width: %d, max_width: %d\n",
118  caps.nMinWidth, caps.nMaxWidth);
119  av_log(logctx, AV_LOG_VERBOSE, "min_height: %d, max_height: %d\n",
120  caps.nMinHeight, caps.nMaxHeight);
121 
122  if (!caps.bIsSupported) {
123  av_log(logctx, AV_LOG_ERROR, "Hardware is lacking required capabilities\n");
124  return AVERROR(EINVAL);
125  }
126 
127  if (params->ulWidth > caps.nMaxWidth || params->ulWidth < caps.nMinWidth) {
128  av_log(logctx, AV_LOG_ERROR, "Video width %d not within range from %d to %d\n",
129  (int)params->ulWidth, caps.nMinWidth, caps.nMaxWidth);
130  return AVERROR(EINVAL);
131  }
132 
133  if (params->ulHeight > caps.nMaxHeight || params->ulHeight < caps.nMinHeight) {
134  av_log(logctx, AV_LOG_ERROR, "Video height %d not within range from %d to %d\n",
135  (int)params->ulHeight, caps.nMinHeight, caps.nMaxHeight);
136  return AVERROR(EINVAL);
137  }
138 
139  if ((params->ulWidth * params->ulHeight) / 256 > caps.nMaxMBCount) {
140  av_log(logctx, AV_LOG_ERROR, "Video macroblock count %d exceeds maximum of %d\n",
141  (int)(params->ulWidth * params->ulHeight) / 256, caps.nMaxMBCount);
142  return AVERROR(EINVAL);
143  }
144 
145  return 0;
146 }
147 
148 static void nvdec_decoder_free(void *opaque, uint8_t *data)
149 {
151 
152  if (decoder->decoder) {
153  CUcontext dummy;
154  decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx);
155  decoder->cvdl->cuvidDestroyDecoder(decoder->decoder);
156  decoder->cudl->cuCtxPopCurrent(&dummy);
157  }
158 
159  av_buffer_unref(&decoder->hw_device_ref);
160 
161  cuvid_free_functions(&decoder->cvdl);
162 
163  av_freep(&decoder);
164 }
165 
166 static int nvdec_decoder_create(AVBufferRef **out, AVBufferRef *hw_device_ref,
167  CUVIDDECODECREATEINFO *params, void *logctx)
168 {
170  AVCUDADeviceContext *device_hwctx = hw_device_ctx->hwctx;
171 
172  AVBufferRef *decoder_ref;
174 
175  CUcontext dummy;
176  CUresult err;
177  int ret;
178 
179  decoder = av_mallocz(sizeof(*decoder));
180  if (!decoder)
181  return AVERROR(ENOMEM);
182 
183  decoder_ref = av_buffer_create((uint8_t*)decoder, sizeof(*decoder),
185  if (!decoder_ref) {
186  av_freep(&decoder);
187  return AVERROR(ENOMEM);
188  }
189 
190  decoder->hw_device_ref = av_buffer_ref(hw_device_ref);
191  if (!decoder->hw_device_ref) {
192  ret = AVERROR(ENOMEM);
193  goto fail;
194  }
195  decoder->cuda_ctx = device_hwctx->cuda_ctx;
196  decoder->cudl = device_hwctx->internal->cuda_dl;
197  decoder->stream = device_hwctx->stream;
198 
199  ret = cuvid_load_functions(&decoder->cvdl, logctx);
200  if (ret < 0) {
201  av_log(logctx, AV_LOG_ERROR, "Failed loading nvcuvid.\n");
202  goto fail;
203  }
204 
205  err = decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx);
206  if (err != CUDA_SUCCESS) {
207  ret = AVERROR_UNKNOWN;
208  goto fail;
209  }
210 
211  ret = nvdec_test_capabilities(decoder, params, logctx);
212  if (ret < 0) {
213  decoder->cudl->cuCtxPopCurrent(&dummy);
214  goto fail;
215  }
216 
217  err = decoder->cvdl->cuvidCreateDecoder(&decoder->decoder, params);
218 
219  decoder->cudl->cuCtxPopCurrent(&dummy);
220 
221  if (err != CUDA_SUCCESS) {
222  av_log(logctx, AV_LOG_ERROR, "Error creating a NVDEC decoder: %d\n", err);
223  ret = AVERROR_UNKNOWN;
224  goto fail;
225  }
226 
227  *out = decoder_ref;
228 
229  return 0;
230 fail:
231  av_buffer_unref(&decoder_ref);
232  return ret;
233 }
234 
235 static AVBufferRef *nvdec_decoder_frame_alloc(void *opaque, int size)
236 {
237  NVDECFramePool *pool = opaque;
238  AVBufferRef *ret;
239 
240  if (pool->nb_allocated >= pool->dpb_size)
241  return NULL;
242 
243  ret = av_buffer_alloc(sizeof(unsigned int));
244  if (!ret)
245  return NULL;
246 
247  *(unsigned int*)ret->data = pool->nb_allocated++;
248 
249  return ret;
250 }
251 
253 {
255 
256  av_freep(&ctx->bitstream);
257  ctx->bitstream_len = 0;
258  ctx->bitstream_allocated = 0;
259 
260  av_freep(&ctx->slice_offsets);
261  ctx->nb_slices = 0;
262  ctx->slice_offsets_allocated = 0;
263 
266 
267  return 0;
268 }
269 
271 {
273 
274  NVDECFramePool *pool;
275  AVHWFramesContext *frames_ctx;
276  const AVPixFmtDescriptor *sw_desc;
277 
278  CUVIDDECODECREATEINFO params = { 0 };
279 
280  int cuvid_codec_type, cuvid_chroma_format;
281  int ret = 0;
282 
283  sw_desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
284  if (!sw_desc)
285  return AVERROR_BUG;
286 
287  cuvid_codec_type = map_avcodec_id(avctx->codec_id);
288  if (cuvid_codec_type < 0) {
289  av_log(avctx, AV_LOG_ERROR, "Unsupported codec ID\n");
290  return AVERROR_BUG;
291  }
292 
293  cuvid_chroma_format = map_chroma_format(avctx->sw_pix_fmt);
294  if (cuvid_chroma_format < 0) {
295  av_log(avctx, AV_LOG_ERROR, "Unsupported chroma format\n");
296  return AVERROR(ENOSYS);
297  }
298 
299  if (!avctx->hw_frames_ctx) {
301  if (ret < 0)
302  return ret;
303  }
304 
305  frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
306 
307  params.ulWidth = avctx->coded_width;
308  params.ulHeight = avctx->coded_height;
309  params.ulTargetWidth = avctx->coded_width;
310  params.ulTargetHeight = avctx->coded_height;
311  params.bitDepthMinus8 = sw_desc->comp[0].depth - 8;
312  params.OutputFormat = params.bitDepthMinus8 ?
313  cudaVideoSurfaceFormat_P016 : cudaVideoSurfaceFormat_NV12;
314  params.CodecType = cuvid_codec_type;
315  params.ChromaFormat = cuvid_chroma_format;
316  params.ulNumDecodeSurfaces = frames_ctx->initial_pool_size;
317  params.ulNumOutputSurfaces = frames_ctx->initial_pool_size;
318 
319  ret = nvdec_decoder_create(&ctx->decoder_ref, frames_ctx->device_ref, &params, avctx);
320  if (ret < 0) {
321  if (params.ulNumDecodeSurfaces > 32) {
322  av_log(avctx, AV_LOG_WARNING, "Using more than 32 (%d) decode surfaces might cause nvdec to fail.\n",
323  (int)params.ulNumDecodeSurfaces);
324  av_log(avctx, AV_LOG_WARNING, "Try lowering the amount of threads. Using %d right now.\n",
325  avctx->thread_count);
326  }
327  return ret;
328  }
329 
330  pool = av_mallocz(sizeof(*pool));
331  if (!pool) {
332  ret = AVERROR(ENOMEM);
333  goto fail;
334  }
335  pool->dpb_size = frames_ctx->initial_pool_size;
336 
337  ctx->decoder_pool = av_buffer_pool_init2(sizeof(int), pool,
339  if (!ctx->decoder_pool) {
340  ret = AVERROR(ENOMEM);
341  goto fail;
342  }
343 
344  return 0;
345 fail:
346  ff_nvdec_decode_uninit(avctx);
347  return ret;
348 }
349 
350 static void nvdec_fdd_priv_free(void *priv)
351 {
352  NVDECFrame *cf = priv;
353 
354  if (!cf)
355  return;
356 
357  av_buffer_unref(&cf->idx_ref);
359 
360  av_freep(&priv);
361 }
362 
363 static void nvdec_unmap_mapped_frame(void *opaque, uint8_t *data)
364 {
365  NVDECFrame *unmap_data = (NVDECFrame*)data;
367  CUdeviceptr devptr = (CUdeviceptr)opaque;
368  CUresult err;
369  CUcontext dummy;
370 
371  err = decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx);
372  if (err != CUDA_SUCCESS) {
373  av_log(NULL, AV_LOG_ERROR, "cuCtxPushCurrent failed\n");
374  goto finish;
375  }
376 
377  err = decoder->cvdl->cuvidUnmapVideoFrame(decoder->decoder, devptr);
378  if (err != CUDA_SUCCESS)
379  av_log(NULL, AV_LOG_ERROR, "cuvidUnmapVideoFrame failed\n");
380 
381  decoder->cudl->cuCtxPopCurrent(&dummy);
382 
383 finish:
384  av_buffer_unref(&unmap_data->idx_ref);
385  av_buffer_unref(&unmap_data->decoder_ref);
386  av_free(unmap_data);
387 }
388 
389 static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
390 {
392  NVDECFrame *cf = (NVDECFrame*)fdd->hwaccel_priv;
393  NVDECDecoder *decoder = (NVDECDecoder*)cf->decoder_ref->data;
394 
395  CUVIDPROCPARAMS vpp = { 0 };
396  NVDECFrame *unmap_data = NULL;
397 
398  CUresult err;
399  CUcontext dummy;
400  CUdeviceptr devptr;
401 
402  unsigned int pitch, i;
403  unsigned int offset = 0;
404  int ret = 0;
405 
406  vpp.progressive_frame = 1;
407  vpp.output_stream = decoder->stream;
408 
409  err = decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx);
410  if (err != CUDA_SUCCESS)
411  return AVERROR_UNKNOWN;
412 
413  err = decoder->cvdl->cuvidMapVideoFrame(decoder->decoder, cf->idx, &devptr,
414  &pitch, &vpp);
415  if (err != CUDA_SUCCESS) {
416  av_log(logctx, AV_LOG_ERROR, "Error mapping a picture with CUVID: %d\n",
417  err);
418  ret = AVERROR_UNKNOWN;
419  goto finish;
420  }
421 
422  unmap_data = av_mallocz(sizeof(*unmap_data));
423  if (!unmap_data) {
424  ret = AVERROR(ENOMEM);
425  goto copy_fail;
426  }
427 
428  frame->buf[1] = av_buffer_create((uint8_t *)unmap_data, sizeof(*unmap_data),
429  nvdec_unmap_mapped_frame, (void*)devptr,
431  if (!frame->buf[1]) {
432  ret = AVERROR(ENOMEM);
433  goto copy_fail;
434  }
435 
436  unmap_data->idx = cf->idx;
437  unmap_data->idx_ref = av_buffer_ref(cf->idx_ref);
438  unmap_data->decoder_ref = av_buffer_ref(cf->decoder_ref);
439 
440  for (i = 0; frame->linesize[i]; i++) {
441  frame->data[i] = (uint8_t*)(devptr + offset);
442  frame->linesize[i] = pitch;
443  offset += pitch * (frame->height >> (i ? 1 : 0));
444  }
445 
446  goto finish;
447 
448 copy_fail:
449  if (!frame->buf[1]) {
450  decoder->cvdl->cuvidUnmapVideoFrame(decoder->decoder, devptr);
451  av_freep(&unmap_data);
452  } else {
453  av_buffer_unref(&frame->buf[1]);
454  }
455 
456 finish:
457  decoder->cudl->cuCtxPopCurrent(&dummy);
458  return ret;
459 }
460 
462 {
465  NVDECFrame *cf = NULL;
466  int ret;
467 
468  ctx->bitstream_len = 0;
469  ctx->nb_slices = 0;
470 
471  if (fdd->hwaccel_priv)
472  return 0;
473 
474  cf = av_mallocz(sizeof(*cf));
475  if (!cf)
476  return AVERROR(ENOMEM);
477 
478  cf->decoder_ref = av_buffer_ref(ctx->decoder_ref);
479  if (!cf->decoder_ref) {
480  ret = AVERROR(ENOMEM);
481  goto fail;
482  }
483 
484  cf->idx_ref = av_buffer_pool_get(ctx->decoder_pool);
485  if (!cf->idx_ref) {
486  av_log(avctx, AV_LOG_ERROR, "No decoder surfaces left\n");
487  ret = AVERROR(ENOMEM);
488  goto fail;
489  }
490  cf->idx = *(unsigned int*)cf->idx_ref->data;
491 
492  fdd->hwaccel_priv = cf;
495 
496  return 0;
497 fail:
499  return ret;
500 
501 }
502 
504 {
507  CUVIDPICPARAMS *pp = &ctx->pic_params;
508 
509  CUresult err;
510  CUcontext dummy;
511 
512  int ret = 0;
513 
514  pp->nBitstreamDataLen = ctx->bitstream_len;
515  pp->pBitstreamData = ctx->bitstream;
516  pp->nNumSlices = ctx->nb_slices;
517  pp->pSliceDataOffsets = ctx->slice_offsets;
518 
519  err = decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx);
520  if (err != CUDA_SUCCESS)
521  return AVERROR_UNKNOWN;
522 
523  err = decoder->cvdl->cuvidDecodePicture(decoder->decoder, &ctx->pic_params);
524  if (err != CUDA_SUCCESS) {
525  av_log(avctx, AV_LOG_ERROR, "Error decoding a picture with NVDEC: %d\n",
526  err);
527  ret = AVERROR_UNKNOWN;
528  goto finish;
529  }
530 
531 finish:
532  decoder->cudl->cuCtxPopCurrent(&dummy);
533 
534  return ret;
535 }
536 
538 {
540  int ret = ff_nvdec_end_frame(avctx);
541  ctx->bitstream = NULL;
542  return ret;
543 }
544 
546  uint32_t size)
547 {
549  void *tmp;
550 
552  (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets));
553  if (!tmp)
554  return AVERROR(ENOMEM);
555  ctx->slice_offsets = tmp;
556 
557  if (!ctx->bitstream)
558  ctx->bitstream = (uint8_t*)buffer;
559 
560  ctx->slice_offsets[ctx->nb_slices] = buffer - ctx->bitstream;
561  ctx->bitstream_len += size;
562  ctx->nb_slices++;
563 
564  return 0;
565 }
566 
568 {
570 }
571 
573 {
574  return av_buffer_create(NULL, 0, NULL, NULL, 0);
575 }
576 
578  AVBufferRef *hw_frames_ctx,
579  int dpb_size)
580 {
581  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)hw_frames_ctx->data;
582  const AVPixFmtDescriptor *sw_desc;
583  int cuvid_codec_type, cuvid_chroma_format;
584 
585  sw_desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
586  if (!sw_desc)
587  return AVERROR_BUG;
588 
589  cuvid_codec_type = map_avcodec_id(avctx->codec_id);
590  if (cuvid_codec_type < 0) {
591  av_log(avctx, AV_LOG_ERROR, "Unsupported codec ID\n");
592  return AVERROR_BUG;
593  }
594 
595  cuvid_chroma_format = map_chroma_format(avctx->sw_pix_fmt);
596  if (cuvid_chroma_format < 0) {
597  av_log(avctx, AV_LOG_VERBOSE, "Unsupported chroma format\n");
598  return AVERROR(EINVAL);
599  }
600 
601  frames_ctx->format = AV_PIX_FMT_CUDA;
602  frames_ctx->width = (avctx->coded_width + 1) & ~1;
603  frames_ctx->height = (avctx->coded_height + 1) & ~1;
604  /*
605  * We add two extra frames to the pool to account for deinterlacing filters
606  * holding onto their frames.
607  */
608  frames_ctx->initial_pool_size = dpb_size + 2;
609 
610  frames_ctx->free = nvdec_free_dummy;
611  frames_ctx->pool = av_buffer_pool_init(0, nvdec_alloc_dummy);
612 
613  if (!frames_ctx->pool)
614  return AVERROR(ENOMEM);
615 
616  switch (sw_desc->comp[0].depth) {
617  case 8:
618  frames_ctx->sw_format = AV_PIX_FMT_NV12;
619  break;
620  case 10:
621  frames_ctx->sw_format = AV_PIX_FMT_P010;
622  break;
623  case 12:
624  frames_ctx->sw_format = AV_PIX_FMT_P016;
625  break;
626  default:
627  return AVERROR(EINVAL);
628  }
629 
630  return 0;
631 }
632 
634 {
635  FrameDecodeData *fdd;
636  NVDECFrame *cf;
637 
638  if (!frame || !frame->private_ref)
639  return -1;
640 
641  fdd = (FrameDecodeData*)frame->private_ref->data;
642  cf = (NVDECFrame*)fdd->hwaccel_priv;
643  if (!cf)
644  return -1;
645 
646  return cf->idx;
647 }
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:60
#define NULL
Definition: coverity.c:32
static enum AVPixelFormat pix_fmt
AVBufferRef * decoder_ref
Definition: nvdec.h:47
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
Definition: buffer.c:125
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2446
This structure describes decoded (raw) audio or video data.
Definition: frame.h:226
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1721
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:418
unsigned * slice_offsets
Definition: nvdec.h:61
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:228
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:208
void(* hwaccel_priv_free)(void *priv)
Definition: decode.h:53
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:236
int ff_nvdec_simple_end_frame(AVCodecContext *avctx)
Definition: nvdec.c:537
int nb_slices
Definition: nvdec.h:62
static int nvdec_decoder_create(AVBufferRef **out, AVBufferRef *hw_device_ref, CUVIDDECODECREATEINFO *params, void *logctx)
Definition: nvdec.c:166
#define AV_PIX_FMT_P016
Definition: pixfmt.h:427
int(* post_process)(void *logctx, AVFrame *frame)
The callback to perform some delayed processing on the frame right before it is returned to the calle...
Definition: decode.h:45
#define AV_PIX_FMT_P010
Definition: pixfmt.h:426
uint8_t * bitstream
Definition: nvdec.h:57
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
CUVIDPICPARAMS pic_params
Definition: nvdec.h:51
unsigned int dpb_size
Definition: nvdec.c:49
AVBufferRef * private_ref
AVBufferRef for internal use by a single libav* library.
Definition: frame.h:604
int ff_nvdec_simple_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: nvdec.c:545
static AVFrame * frame
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:91
static AVBufferRef * nvdec_decoder_frame_alloc(void *opaque, int size)
Definition: nvdec.c:235
static void finish(void)
Definition: movenc.c:345
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
#define AV_BUFFER_FLAG_READONLY
Always treat the buffer as read-only, even when it has only one reference.
Definition: buffer.h:113
AVBufferRef * decoder_ref
Definition: nvdec.h:55
ptrdiff_t size
Definition: opengl_enc.c:101
CUvideodecoder decoder
Definition: nvdec.c:38
#define av_log(a,...)
static int nvdec_test_capabilities(NVDECDecoder *decoder, CUVIDDECODECREATEINFO *params, void *logctx)
Definition: nvdec.c:86
void(* free)(struct AVHWFramesContext *ctx)
This field may be set by the caller before calling av_hwframe_ctx_init().
Definition: hwcontext.h:169
CUcontext cuda_ctx
Definition: nvdec.c:41
static void nvdec_unmap_mapped_frame(void *opaque, uint8_t *data)
Definition: nvdec.c:363
static void nvdec_free_dummy(struct AVHWFramesContext *ctx)
Definition: nvdec.c:567
static int map_chroma_format(enum AVPixelFormat pix_fmt)
Definition: nvdec.c:70
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:215
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
error code definitions
static AVBufferRef * hw_device_ctx
Definition: hw_decode.c:45
#define AVERROR(e)
Definition: error.h:43
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:2474
int ff_nvdec_end_frame(AVCodecContext *avctx)
Definition: nvdec.c:503
int ff_nvdec_start_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: nvdec.c:461
GLenum GLint * params
Definition: opengl_enc.c:114
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:89
static void nvdec_fdd_priv_free(void *priv)
Definition: nvdec.c:350
AVBufferRef * av_buffer_create(uint8_t *data, int size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags)
Create an AVBuffer from an existing array.
Definition: buffer.c:28
static const uint8_t offset[127][2]
Definition: vf_spp.c:92
unsigned int idx
Definition: nvdec.h:45
#define fail()
Definition: checkasm.h:117
int ff_nvdec_decode_init(AVCodecContext *avctx)
Definition: nvdec.c:270
int initial_pool_size
Initial size of the frame pool.
Definition: hwcontext.h:198
int dpb_size
Definition: h264_levels.c:65
int ff_nvdec_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx, int dpb_size)
Definition: nvdec.c:577
CUstream stream
Definition: nvdec.c:42
static const chunk_decoder decoder[8]
Definition: dfa.c:330
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames...
Definition: avcodec.h:3213
int bitstream_len
Definition: nvdec.h:58
AVFormatContext * ctx
Definition: movenc.c:48
static void nvdec_decoder_free(void *opaque, uint8_t *data)
Definition: nvdec.c:148
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
Definition: mem.c:464
FFmpeg internal API for CUDA.
int dummy
Definition: motion.c:64
HW acceleration through CUDA.
Definition: pixfmt.h:235
AVBufferPool * av_buffer_pool_init2(int size, void *opaque, AVBufferRef *(*alloc)(void *opaque, int size), void(*pool_free)(void *opaque))
Allocate and initialize a buffer pool with a more complex allocator.
Definition: buffer.c:218
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:220
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
Definition: avcodec.h:2785
CuvidFunctions * cvdl
Definition: nvdec.c:45
Libavcodec external API header.
unsigned int bitstream_allocated
Definition: nvdec.h:59
enum AVCodecID codec_id
Definition: avcodec.h:1543
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
Definition: buffer.c:67
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:257
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
main external API structure.
Definition: avcodec.h:1533
int ff_nvdec_decode_uninit(AVCodecContext *avctx)
Definition: nvdec.c:252
uint8_t * data
The data buffer.
Definition: buffer.h:89
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
This struct is allocated as AVHWDeviceContext.hwctx.
int coded_height
Definition: avcodec.h:1721
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
Definition: buffer.c:275
unsigned int slice_offsets_allocated
Definition: nvdec.h:63
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:123
static AVBufferRef * nvdec_alloc_dummy(int size)
Definition: nvdec.c:572
AVBufferRef * idx_ref
Definition: nvdec.h:46
unsigned int nb_allocated
Definition: nvdec.c:50
static int map_avcodec_id(enum AVCodecID id)
Definition: nvdec.c:53
int ff_decode_get_hw_frames_ctx(AVCodecContext *avctx, enum AVHWDeviceType dev_type)
Make sure avctx.hw_frames_ctx is set.
Definition: decode.c:1177
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:240
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
Definition: hwcontext.h:140
A reference to a data buffer.
Definition: buffer.h:81
This struct stores per-frame lavc-internal data and is attached to it via private_ref.
Definition: decode.h:34
common internal api header.
common internal and external API header
if(ret< 0)
Definition: vf_mcdeint.c:279
AVBufferPool * av_buffer_pool_init(int size, AVBufferRef *(*alloc)(int size))
Allocate and initialize a buffer pool.
Definition: buffer.c:238
int ff_nvdec_get_ref_idx(AVFrame *frame)
Definition: nvdec.c:633
void * hwaccel_priv_data
hwaccel-specific private data
Definition: internal.h:190
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
pixel format definitions
AVBufferPool * pool
A pool from which the frames are allocated by av_hwframe_get_buffer().
Definition: hwcontext.h:189
#define av_free(p)
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:1568
CudaFunctions * cudl
Definition: nvdec.c:44
AVBufferPool * decoder_pool
Definition: nvdec.h:53
int height
Definition: frame.h:284
FILE * out
Definition: movenc.c:54
#define av_freep(p)
static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
Definition: nvdec.c:389
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
Definition: buffer.c:334
void * hwaccel_priv
Per-frame private data for hwaccels.
Definition: decode.h:52
int depth
Number of bits in the component.
Definition: pixdesc.h:58
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:221
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:3063
AVBufferRef * hw_device_ref
Definition: nvdec.c:40
GLuint buffer
Definition: opengl_enc.c:102
static uint8_t tmp[11]
Definition: aes_ctr.c:26