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 {
39 
42 
45 } NVDECDecoder;
46 
47 typedef struct NVDECFramePool {
48  unsigned int dpb_size;
49  unsigned int nb_allocated;
51 
52 static int map_avcodec_id(enum AVCodecID id)
53 {
54  switch (id) {
64  }
65  return -1;
66 }
67 
69 {
70  int shift_h = 0, shift_v = 0;
71 
72  av_pix_fmt_get_chroma_sub_sample(pix_fmt, &shift_h, &shift_v);
73 
74  if (shift_h == 1 && shift_v == 1)
76  else if (shift_h == 1 && shift_v == 0)
78  else if (shift_h == 0 && shift_v == 0)
80 
81  return -1;
82 }
83 
85  CUVIDDECODECREATEINFO *params, void *logctx)
86 {
87  CUresult err;
88  CUVIDDECODECAPS caps = { 0 };
89 
90  caps.eCodecType = params->CodecType;
91  caps.eChromaFormat = params->ChromaFormat;
92  caps.nBitDepthMinus8 = params->bitDepthMinus8;
93 
94  if (!decoder->cvdl->cuvidGetDecoderCaps) {
95  av_log(logctx, AV_LOG_WARNING, "Used Nvidia driver is too old to perform a capability check.\n");
96  av_log(logctx, AV_LOG_WARNING, "The minimum required version is "
97 #if defined(_WIN32) || defined(__CYGWIN__)
98  "378.66"
99 #else
100  "378.13"
101 #endif
102  ". Continuing blind.\n");
103  return 0;
104  }
105 
106  err = decoder->cvdl->cuvidGetDecoderCaps(&caps);
107  if (err != CUDA_SUCCESS) {
108  av_log(logctx, AV_LOG_ERROR, "Failed querying decoder capabilities\n");
109  return AVERROR_UNKNOWN;
110  }
111 
112  av_log(logctx, AV_LOG_VERBOSE, "NVDEC capabilities:\n");
113  av_log(logctx, AV_LOG_VERBOSE, "format supported: %s, max_mb_count: %d\n",
114  caps.bIsSupported ? "yes" : "no", caps.nMaxMBCount);
115  av_log(logctx, AV_LOG_VERBOSE, "min_width: %d, max_width: %d\n",
116  caps.nMinWidth, caps.nMaxWidth);
117  av_log(logctx, AV_LOG_VERBOSE, "min_height: %d, max_height: %d\n",
118  caps.nMinHeight, caps.nMaxHeight);
119 
120  if (!caps.bIsSupported) {
121  av_log(logctx, AV_LOG_ERROR, "Hardware is lacking required capabilities\n");
122  return AVERROR(EINVAL);
123  }
124 
125  if (params->ulWidth > caps.nMaxWidth || params->ulWidth < caps.nMinWidth) {
126  av_log(logctx, AV_LOG_ERROR, "Video width %d not within range from %d to %d\n",
127  (int)params->ulWidth, caps.nMinWidth, caps.nMaxWidth);
128  return AVERROR(EINVAL);
129  }
130 
131  if (params->ulHeight > caps.nMaxHeight || params->ulHeight < caps.nMinHeight) {
132  av_log(logctx, AV_LOG_ERROR, "Video height %d not within range from %d to %d\n",
133  (int)params->ulHeight, caps.nMinHeight, caps.nMaxHeight);
134  return AVERROR(EINVAL);
135  }
136 
137  if ((params->ulWidth * params->ulHeight) / 256 > caps.nMaxMBCount) {
138  av_log(logctx, AV_LOG_ERROR, "Video macroblock count %d exceeds maximum of %d\n",
139  (int)(params->ulWidth * params->ulHeight) / 256, caps.nMaxMBCount);
140  return AVERROR(EINVAL);
141  }
142 
143  return 0;
144 }
145 
146 static void nvdec_decoder_free(void *opaque, uint8_t *data)
147 {
149 
150  if (decoder->decoder)
151  decoder->cvdl->cuvidDestroyDecoder(decoder->decoder);
152 
153  av_buffer_unref(&decoder->hw_device_ref);
154 
155  cuvid_free_functions(&decoder->cvdl);
156 
157  av_freep(&decoder);
158 }
159 
160 static int nvdec_decoder_create(AVBufferRef **out, AVBufferRef *hw_device_ref,
161  CUVIDDECODECREATEINFO *params, void *logctx)
162 {
164  AVCUDADeviceContext *device_hwctx = hw_device_ctx->hwctx;
165 
166  AVBufferRef *decoder_ref;
168 
170  CUresult err;
171  int ret;
172 
173  decoder = av_mallocz(sizeof(*decoder));
174  if (!decoder)
175  return AVERROR(ENOMEM);
176 
177  decoder_ref = av_buffer_create((uint8_t*)decoder, sizeof(*decoder),
179  if (!decoder_ref) {
180  av_freep(&decoder);
181  return AVERROR(ENOMEM);
182  }
183 
184  decoder->hw_device_ref = av_buffer_ref(hw_device_ref);
185  if (!decoder->hw_device_ref) {
186  ret = AVERROR(ENOMEM);
187  goto fail;
188  }
189  decoder->cuda_ctx = device_hwctx->cuda_ctx;
190  decoder->cudl = device_hwctx->internal->cuda_dl;
191 
192  ret = cuvid_load_functions(&decoder->cvdl, logctx);
193  if (ret < 0) {
194  av_log(logctx, AV_LOG_ERROR, "Failed loading nvcuvid.\n");
195  goto fail;
196  }
197 
198  err = decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx);
199  if (err != CUDA_SUCCESS) {
200  ret = AVERROR_UNKNOWN;
201  goto fail;
202  }
203 
204  ret = nvdec_test_capabilities(decoder, params, logctx);
205  if (ret < 0) {
206  decoder->cudl->cuCtxPopCurrent(&dummy);
207  goto fail;
208  }
209 
210  err = decoder->cvdl->cuvidCreateDecoder(&decoder->decoder, params);
211 
212  decoder->cudl->cuCtxPopCurrent(&dummy);
213 
214  if (err != CUDA_SUCCESS) {
215  av_log(logctx, AV_LOG_ERROR, "Error creating a NVDEC decoder: %d\n", err);
216  ret = AVERROR_UNKNOWN;
217  goto fail;
218  }
219 
220  *out = decoder_ref;
221 
222  return 0;
223 fail:
224  av_buffer_unref(&decoder_ref);
225  return ret;
226 }
227 
228 static AVBufferRef *nvdec_decoder_frame_alloc(void *opaque, int size)
229 {
230  NVDECFramePool *pool = opaque;
231  AVBufferRef *ret;
232 
233  if (pool->nb_allocated >= pool->dpb_size)
234  return NULL;
235 
236  ret = av_buffer_alloc(sizeof(unsigned int));
237  if (!ret)
238  return NULL;
239 
240  *(unsigned int*)ret->data = pool->nb_allocated++;
241 
242  return ret;
243 }
244 
246 {
248 
249  av_freep(&ctx->bitstream);
250  ctx->bitstream_len = 0;
251  ctx->bitstream_allocated = 0;
252 
253  av_freep(&ctx->slice_offsets);
254  ctx->nb_slices = 0;
255  ctx->slice_offsets_allocated = 0;
256 
259 
260  return 0;
261 }
262 
264 {
266 
267  NVDECFramePool *pool;
268  AVHWFramesContext *frames_ctx;
269  const AVPixFmtDescriptor *sw_desc;
270 
272 
273  int cuvid_codec_type, cuvid_chroma_format;
274  int ret = 0;
275 
276  sw_desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
277  if (!sw_desc)
278  return AVERROR_BUG;
279 
280  cuvid_codec_type = map_avcodec_id(avctx->codec_id);
281  if (cuvid_codec_type < 0) {
282  av_log(avctx, AV_LOG_ERROR, "Unsupported codec ID\n");
283  return AVERROR_BUG;
284  }
285 
286  cuvid_chroma_format = map_chroma_format(avctx->sw_pix_fmt);
287  if (cuvid_chroma_format < 0) {
288  av_log(avctx, AV_LOG_ERROR, "Unsupported chroma format\n");
289  return AVERROR(ENOSYS);
290  }
291 
292  if (!avctx->hw_frames_ctx) {
294  if (ret < 0)
295  return ret;
296  }
297 
298  frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
299 
300  params.ulWidth = avctx->coded_width;
301  params.ulHeight = avctx->coded_height;
302  params.ulTargetWidth = avctx->coded_width;
303  params.ulTargetHeight = avctx->coded_height;
304  params.bitDepthMinus8 = sw_desc->comp[0].depth - 8;
305  params.OutputFormat = params.bitDepthMinus8 ?
307  params.CodecType = cuvid_codec_type;
308  params.ChromaFormat = cuvid_chroma_format;
309  params.ulNumDecodeSurfaces = frames_ctx->initial_pool_size;
310  params.ulNumOutputSurfaces = 1;
311 
312  ret = nvdec_decoder_create(&ctx->decoder_ref, frames_ctx->device_ref, &params, avctx);
313  if (ret < 0) {
314  if (params.ulNumDecodeSurfaces > 32) {
315  av_log(avctx, AV_LOG_WARNING, "Using more than 32 (%d) decode surfaces might cause nvdec to fail.\n",
316  (int)params.ulNumDecodeSurfaces);
317  av_log(avctx, AV_LOG_WARNING, "Try lowering the amount of threads. Using %d right now.\n",
318  avctx->thread_count);
319  }
320  return ret;
321  }
322 
323  pool = av_mallocz(sizeof(*pool));
324  if (!pool) {
325  ret = AVERROR(ENOMEM);
326  goto fail;
327  }
328  pool->dpb_size = frames_ctx->initial_pool_size;
329 
330  ctx->decoder_pool = av_buffer_pool_init2(sizeof(int), pool,
332  if (!ctx->decoder_pool) {
333  ret = AVERROR(ENOMEM);
334  goto fail;
335  }
336 
337  return 0;
338 fail:
339  ff_nvdec_decode_uninit(avctx);
340  return ret;
341 }
342 
343 static void nvdec_fdd_priv_free(void *priv)
344 {
345  NVDECFrame *cf = priv;
346 
347  if (!cf)
348  return;
349 
350  av_buffer_unref(&cf->idx_ref);
352 
353  av_freep(&priv);
354 }
355 
356 static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
357 {
359  NVDECFrame *cf = (NVDECFrame*)fdd->hwaccel_priv;
360  NVDECDecoder *decoder = (NVDECDecoder*)cf->decoder_ref->data;
361 
362  CUVIDPROCPARAMS vpp = { .progressive_frame = 1 };
363 
364  CUresult err;
366  CUdeviceptr devptr;
367 
368  unsigned int pitch, i;
369  unsigned int offset = 0;
370  int ret = 0;
371 
372  err = decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx);
373  if (err != CUDA_SUCCESS)
374  return AVERROR_UNKNOWN;
375 
376  err = decoder->cvdl->cuvidMapVideoFrame(decoder->decoder, cf->idx, &devptr,
377  &pitch, &vpp);
378  if (err != CUDA_SUCCESS) {
379  av_log(logctx, AV_LOG_ERROR, "Error mapping a picture with CUVID: %d\n",
380  err);
381  ret = AVERROR_UNKNOWN;
382  goto finish;
383  }
384 
385  for (i = 0; frame->data[i]; i++) {
386  CUDA_MEMCPY2D cpy = {
388  .dstMemoryType = CU_MEMORYTYPE_DEVICE,
389  .srcDevice = devptr,
390  .dstDevice = (CUdeviceptr)frame->data[i],
391  .srcPitch = pitch,
392  .dstPitch = frame->linesize[i],
393  .srcY = offset,
394  .WidthInBytes = FFMIN(pitch, frame->linesize[i]),
395  .Height = frame->height >> (i ? 1 : 0),
396  };
397 
398  err = decoder->cudl->cuMemcpy2D(&cpy);
399  if (err != CUDA_SUCCESS) {
400  av_log(logctx, AV_LOG_ERROR, "Error copying decoded frame: %d\n",
401  err);
402  ret = AVERROR_UNKNOWN;
403  goto copy_fail;
404  }
405 
406  offset += cpy.Height;
407  }
408 
409 copy_fail:
410  decoder->cvdl->cuvidUnmapVideoFrame(decoder->decoder, devptr);
411 
412 finish:
413  decoder->cudl->cuCtxPopCurrent(&dummy);
414  return ret;
415 }
416 
418 {
421  NVDECFrame *cf = NULL;
422  int ret;
423 
424  ctx->bitstream_len = 0;
425  ctx->nb_slices = 0;
426 
427  if (fdd->hwaccel_priv)
428  return 0;
429 
430  cf = av_mallocz(sizeof(*cf));
431  if (!cf)
432  return AVERROR(ENOMEM);
433 
434  cf->decoder_ref = av_buffer_ref(ctx->decoder_ref);
435  if (!cf->decoder_ref) {
436  ret = AVERROR(ENOMEM);
437  goto fail;
438  }
439 
440  cf->idx_ref = av_buffer_pool_get(ctx->decoder_pool);
441  if (!cf->idx_ref) {
442  av_log(avctx, AV_LOG_ERROR, "No decoder surfaces left\n");
443  ret = AVERROR(ENOMEM);
444  goto fail;
445  }
446  cf->idx = *(unsigned int*)cf->idx_ref->data;
447 
448  fdd->hwaccel_priv = cf;
451 
452  return 0;
453 fail:
455  return ret;
456 
457 }
458 
460 {
463  CUVIDPICPARAMS *pp = &ctx->pic_params;
464 
465  CUresult err;
467 
468  int ret = 0;
469 
470  pp->nBitstreamDataLen = ctx->bitstream_len;
471  pp->pBitstreamData = ctx->bitstream;
472  pp->nNumSlices = ctx->nb_slices;
473  pp->pSliceDataOffsets = ctx->slice_offsets;
474 
475  err = decoder->cudl->cuCtxPushCurrent(decoder->cuda_ctx);
476  if (err != CUDA_SUCCESS)
477  return AVERROR_UNKNOWN;
478 
479  err = decoder->cvdl->cuvidDecodePicture(decoder->decoder, &ctx->pic_params);
480  if (err != CUDA_SUCCESS) {
481  av_log(avctx, AV_LOG_ERROR, "Error decoding a picture with NVDEC: %d\n",
482  err);
483  ret = AVERROR_UNKNOWN;
484  goto finish;
485  }
486 
487 finish:
488  decoder->cudl->cuCtxPopCurrent(&dummy);
489 
490  return ret;
491 }
492 
494 {
496  int ret = ff_nvdec_end_frame(avctx);
497  ctx->bitstream = NULL;
498  return ret;
499 }
500 
502  uint32_t size)
503 {
505  void *tmp;
506 
508  (ctx->nb_slices + 1) * sizeof(*ctx->slice_offsets));
509  if (!tmp)
510  return AVERROR(ENOMEM);
511  ctx->slice_offsets = tmp;
512 
513  if (!ctx->bitstream)
514  ctx->bitstream = (uint8_t*)buffer;
515 
516  ctx->slice_offsets[ctx->nb_slices] = buffer - ctx->bitstream;
517  ctx->bitstream_len += size;
518  ctx->nb_slices++;
519 
520  return 0;
521 }
522 
524  AVBufferRef *hw_frames_ctx,
525  int dpb_size)
526 {
527  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)hw_frames_ctx->data;
528  const AVPixFmtDescriptor *sw_desc;
529  int cuvid_codec_type, cuvid_chroma_format;
530 
531  sw_desc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
532  if (!sw_desc)
533  return AVERROR_BUG;
534 
535  cuvid_codec_type = map_avcodec_id(avctx->codec_id);
536  if (cuvid_codec_type < 0) {
537  av_log(avctx, AV_LOG_ERROR, "Unsupported codec ID\n");
538  return AVERROR_BUG;
539  }
540 
541  cuvid_chroma_format = map_chroma_format(avctx->sw_pix_fmt);
542  if (cuvid_chroma_format < 0) {
543  av_log(avctx, AV_LOG_VERBOSE, "Unsupported chroma format\n");
544  return AVERROR(EINVAL);
545  }
546 
547  frames_ctx->format = AV_PIX_FMT_CUDA;
548  frames_ctx->width = (avctx->coded_width + 1) & ~1;
549  frames_ctx->height = (avctx->coded_height + 1) & ~1;
550  frames_ctx->initial_pool_size = dpb_size;
551 
552  switch (sw_desc->comp[0].depth) {
553  case 8:
554  frames_ctx->sw_format = AV_PIX_FMT_NV12;
555  break;
556  case 10:
557  frames_ctx->sw_format = AV_PIX_FMT_P010;
558  break;
559  case 12:
560  frames_ctx->sw_format = AV_PIX_FMT_P016;
561  break;
562  default:
563  return AVERROR(EINVAL);
564  }
565 
566  return 0;
567 }
568 
570 {
571  FrameDecodeData *fdd;
572  NVDECFrame *cf;
573 
574  if (!frame || !frame->private_ref)
575  return -1;
576 
577  fdd = (FrameDecodeData*)frame->private_ref->data;
578  cf = (NVDECFrame*)fdd->hwaccel_priv;
579  if (!cf)
580  return -1;
581 
582  return cf->idx;
583 }
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e.
Definition: hwcontext.h:59
#define NULL
Definition: coverity.c:32
tcu_ulong bitDepthMinus8
IN: The value "BitDepth minus 8".
static enum AVPixelFormat pix_fmt
AVBufferRef * decoder_ref
Definition: nvdec.h:38
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:2363
This structure describes decoded (raw) audio or video data.
Definition: frame.h:201
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
tcu_ulong ulNumOutputSurfaces
IN: Maximum number of output surfaces simultaneously mapped.
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1675
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
unsigned * slice_offsets
Definition: nvdec.h:52
int width
The allocated dimensions of the frames in this pool.
Definition: hwcontext.h:227
This structure is used in cuvidGetDecoderCaps API.
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:207
void(* hwaccel_priv_free)(void *priv)
Definition: decode.h:56
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:493
int nb_slices
Definition: nvdec.h:53
static int nvdec_decoder_create(AVBufferRef **out, AVBufferRef *hw_device_ref, CUVIDDECODECREATEINFO *params, void *logctx)
Definition: nvdec.c:160
#define AV_PIX_FMT_P016
Definition: pixfmt.h:414
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:48
tcuvidGetDecoderCaps * cuvidGetDecoderCaps
#define AV_PIX_FMT_P010
Definition: pixfmt.h:413
cudaVideoCodec CodecType
IN: cudaVideoCodec_XXX.
uint8_t * bitstream
Definition: nvdec.h:48
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
cudaVideoSurfaceFormat OutputFormat
IN: cudaVideoSurfaceFormat_XXX.
uint8_t
tcuvidDestroyDecoder * cuvidDestroyDecoder
tcu_ulong ulTargetWidth
IN: Post-processed output width (Should be aligned to 2)
Picture parameters for postprocessing This structure is used in cuvidMapVideoFrame API...
CUVIDPICPARAMS pic_params
Definition: nvdec.h:42
unsigned int dpb_size
Definition: nvdec.c:48
AVBufferRef * private_ref
AVBufferRef for internal use by a single libav* library.
Definition: frame.h:578
int ff_nvdec_simple_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition: nvdec.c:501
static AVFrame * frame
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context.
Definition: hwcontext.h:90
static AVBufferRef * nvdec_decoder_frame_alloc(void *opaque, int size)
Definition: nvdec.c:228
static void finish(void)
Definition: movenc.c:345
unsigned short nMinWidth
OUT: Min supported coded width in pixels.
#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:46
ptrdiff_t size
Definition: opengl_enc.c:101
CUvideodecoder decoder
Definition: nvdec.c:38
tcuCtxPushCurrent_v2 * cuCtxPushCurrent
This structure is used in cuvidCreateDecoder API.
#define av_log(a,...)
static int nvdec_test_capabilities(NVDECDecoder *decoder, CUVIDDECODECREATEINFO *params, void *logctx)
Definition: nvdec.c:84
Picture parameters for decoding This structure is used in cuvidDecodePicture API IN for cuvidDecodePi...
CUcontext cuda_ctx
Definition: nvdec.c:41
static int map_chroma_format(enum AVPixelFormat pix_fmt)
Definition: nvdec.c:68
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:43
#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:2391
int ff_nvdec_end_frame(AVCodecContext *avctx)
Definition: nvdec.c:459
int ff_nvdec_start_frame(AVCodecContext *avctx, AVFrame *frame)
Definition: nvdec.c:417
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:85
tcuvidDecodePicture * cuvidDecodePicture
static void nvdec_fdd_priv_free(void *priv)
Definition: nvdec.c:343
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:36
#define fail()
Definition: checkasm.h:112
unsigned char bIsSupported
OUT: 1 if codec supported, 0 if not supported.
int ff_nvdec_decode_init(AVCodecContext *avctx)
Definition: nvdec.c:263
int progressive_frame
IN: Input is progressive (deinterlace_mode will be ignored)
int initial_pool_size
Initial size of the frame pool.
Definition: hwcontext.h:197
int ff_nvdec_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx, int dpb_size)
Definition: nvdec.c:523
#define FFMIN(a, b)
Definition: common.h:96
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:3154
int bitstream_len
Definition: nvdec.h:49
AVFormatContext * ctx
Definition: movenc.c:48
static void nvdec_decoder_free(void *opaque, uint8_t *data)
Definition: nvdec.c:146
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:231
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
unsigned int nMaxHeight
OUT: Max supported coded height in pixels.
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:220
unsigned short nMinHeight
OUT: Min supported coded height in pixels.
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
Definition: avcodec.h:2739
CuvidFunctions * cvdl
Definition: nvdec.c:44
unsigned int nBitDepthMinus8
IN: The Value "BitDepth minus 8".
CUmemorytype srcMemoryType
Definition: dynlink_cuda.h:65
tcu_ulong ulNumDecodeSurfaces
IN: Maximum number of internal decode surfaces.
Libavcodec external API header.
unsigned int bitstream_allocated
Definition: nvdec.h:50
unsigned int nMaxMBCount
OUT: Max supported macroblock count CodedWidth*CodedHeight/256 must be <= nMaxMBCount.
enum AVCodecID codec_id
Definition: avcodec.h:1498
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:232
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:1488
int ff_nvdec_decode_uninit(AVCodecContext *avctx)
Definition: nvdec.c:245
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:1675
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:54
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:122
AVBufferRef * idx_ref
Definition: nvdec.h:37
tcu_ulong ulWidth
IN: Coded sequence width in pixels.
cudaVideoCodec eCodecType
IN: cudaVideoCodec_XXX.
unsigned int nb_allocated
Definition: nvdec.c:49
static int map_avcodec_id(enum AVCodecID id)
Definition: nvdec.c:52
int ff_decode_get_hw_frames_ctx(AVCodecContext *avctx, enum AVHWDeviceType dev_type)
Make sure avctx.hw_frames_ctx is set.
Definition: decode.c:1149
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:215
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext.
Definition: hwcontext.h:139
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:37
common internal api header.
common internal and external API header
if(ret< 0)
Definition: vf_mcdeint.c:279
int ff_nvdec_get_ref_idx(AVFrame *frame)
Definition: nvdec.c:569
void * hwaccel_priv_data
hwaccel-specific private data
Definition: internal.h:188
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
tcuCtxPopCurrent_v2 * cuCtxPopCurrent
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
cudaVideoChromaFormat eChromaFormat
IN: cudaVideoChromaFormat_XXX.
pixel format definitions
#define av_free(p)
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:1523
tcu_ulong ulHeight
IN: Coded sequence height in pixels.
cudaVideoChromaFormat ChromaFormat
IN: cudaVideoChromaFormat_XXX.
tcu_ulong ulTargetHeight
IN: Post-processed output height (Should be aligbed to 2)
CudaFunctions * cudl
Definition: nvdec.c:43
AVBufferPool * decoder_pool
Definition: nvdec.h:44
int height
Definition: frame.h:259
FILE * out
Definition: movenc.c:54
#define av_freep(p)
static int nvdec_retrieve_data(void *logctx, AVFrame *frame)
Definition: nvdec.c:356
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:55
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:220
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:3005
AVBufferRef * hw_device_ref
Definition: nvdec.c:40
GLuint buffer
Definition: opengl_enc.c:102
unsigned int nMaxWidth
OUT: Max supported coded width in pixels.
static uint8_t tmp[11]
Definition: aes_ctr.c:26