FFmpeg
Loading...
Searching...
No Matches
nvdec.h
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#ifndef AVCODEC_NVDEC_H
24#define AVCODEC_NVDEC_H
25
27
28#include <stdint.h>
29
30#include "libavutil/buffer.h"
31#include "libavutil/frame.h"
32
33#include "avcodec.h"
34
35#if defined(NVDECAPI_MAJOR_VERSION) && defined(NVDECAPI_MINOR_VERSION)
36# define NVDECAPI_CHECK_VERSION(major, minor) \
37 ((major) < NVDECAPI_MAJOR_VERSION || ((major) == NVDECAPI_MAJOR_VERSION && (minor) <= NVDECAPI_MINOR_VERSION))
38#else
39/* version macros were added in SDK 8.1 ffnvcodec */
40# define NVDECAPI_CHECK_VERSION(major, minor) \
41 ((major) < 8 || ((major) == 8 && (minor) <= 0))
42#endif
43
44// SDK 13.0 compile time feature checks
45#if NVDECAPI_CHECK_VERSION(13, 0)
46#define NVDEC_HAVE_422_SUPPORT
47#endif
48
49// SDK 13.1 compile time feature checks
50#if NVDECAPI_CHECK_VERSION(13, 1)
51#define NVDEC_HAVE_OPAQUE_OUTPUT_SUPPORT
52#define NVDEC_HAVE_MVHEVC_DECODE
53/* Largest ulNumDecodeSurfaces the hardware can address; the SDK only names the
54 * limit from 13.1 on, where it also bounds cuvidRegisterDecodeSurfaces(). */
55#define NVDEC_MAX_DECODE_SURFACES MAX_NUM_REGISTERED_DECODE_SURFACES
56#else
57#define NVDEC_MAX_DECODE_SURFACES 32
58#endif
59
60typedef struct NVDECFrame {
61 unsigned int idx;
62 unsigned int ref_idx;
63 unsigned int *idx_ref; ///< RefStruct reference
64 unsigned int *ref_idx_ref; ///< RefStruct reference
65 struct NVDECDecoder *decoder; ///< RefStruct reference
67
68typedef struct NVDECContext {
69 CUVIDPICPARAMS pic_params;
70
72
73 struct NVDECDecoder *decoder; ///< RefStruct reference
74
75 const uint8_t *bitstream;
77 unsigned int bitstream_allocated;
79
80 unsigned *slice_offsets;
83
85
86 /* Nonzero when every requested decode surface is actually needed, in which
87 * case exceeding the hardware limit must fail instead of being capped.
88 * The value is the number of surfaces consumed per access unit. */
90
91 /* Decode surfaces the hwaccel requires, independent of the frames context
92 * in use. frame_params() is skipped for a caller-supplied context, so the
93 * pool it carries is not on its own proof that the stream fits. */
96
100int ff_nvdec_start_frame_sep_ref(AVCodecContext *avctx, AVFrame *frame, int has_sep_ref);
103int ff_nvdec_simple_decode_slice(AVCodecContext *avctx, const uint8_t *buffer,
104 uint32_t size);
106 AVBufferRef *hw_frames_ctx,
107 enum AVPixelFormat hw_format,
108 int dpb_size,
109 int supports_444);
111
112#ifdef NVDEC_HAVE_OPAQUE_OUTPUT_SUPPORT
113void ff_nvdec_fill_cuarray_desc(CUDA_ARRAY3D_DESCRIPTOR *desc,
114 AVCodecContext *avctx,
115 cudaVideoSurfaceFormat output_format);
116#endif
117
118#endif /* AVCODEC_NVDEC_H */
Libavcodec external API header.
refcounted data buffer API
static AVFrame * frame
static char * output_format
Definition ffprobe.c:145
reference-counted frame API
const char * desc
Definition libsvtav1.c:83
int ff_nvdec_start_frame_sep_ref(AVCodecContext *avctx, AVFrame *frame, int has_sep_ref)
Definition nvdec.c:1010
int ff_nvdec_simple_end_frame(AVCodecContext *avctx)
Definition nvdec.c:1077
int ff_nvdec_simple_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size)
Definition nvdec.c:1087
int ff_nvdec_decode_init(AVCodecContext *avctx)
Definition nvdec.c:404
int ff_nvdec_get_ref_idx(AVFrame *frame)
Definition nvdec.c:1206
int ff_nvdec_end_frame(AVCodecContext *avctx)
Definition nvdec.c:1040
int ff_nvdec_start_frame(AVCodecContext *avctx, AVFrame *frame)
Definition nvdec.c:972
int ff_nvdec_decode_uninit(AVCodecContext *avctx)
Definition nvdec.c:297
int ff_nvdec_frame_params(AVCodecContext *avctx, AVBufferRef *hw_frames_ctx, enum AVPixelFormat hw_format, int dpb_size, int supports_444)
Definition nvdec.c:1109
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
A reference to a data buffer.
Definition buffer.h:82
main external API structure.
Definition avcodec.h:443
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
AVRefStructPool is an API for a thread-safe pool of objects managed via the RefStruct API.
Definition refstruct.c:183
int strict_pool_min
Definition nvdec.h:94
unsigned int slice_offsets_allocated
Definition nvdec.h:82
unsigned * slice_offsets
Definition nvdec.h:80
int strict_pool_layers
Definition nvdec.h:89
int bitstream_len
Definition nvdec.h:76
unsigned int bitstream_allocated
Definition nvdec.h:77
struct NVDECDecoder * decoder
RefStruct reference.
Definition nvdec.h:73
int nb_slices
Definition nvdec.h:81
uint8_t * bitstream_internal
Definition nvdec.h:78
CUVIDPICPARAMS pic_params
Definition nvdec.h:69
int supports_444
Definition nvdec.h:84
const uint8_t * bitstream
Definition nvdec.h:75
struct AVRefStructPool * decoder_pool
Definition nvdec.h:71
struct NVDECDecoder * decoder
RefStruct reference.
Definition nvdec.h:65
unsigned int ref_idx
Definition nvdec.h:62
unsigned int idx
Definition nvdec.h:61
unsigned int * ref_idx_ref
RefStruct reference.
Definition nvdec.h:64
unsigned int * idx_ref
RefStruct reference.
Definition nvdec.h:63
int dpb_size
static char buffer[20]
Definition seek.c:32
int size