96     const char *err_string;
 
  107     if (err_name && err_string)
 
  114 #define CHECK_CU(x) check_cu(avctx, (x), #x) 
  124     int old_width = avctx->
width;
 
  125     int old_height = avctx->
height;
 
  133     memset(&cuinfo, 0, 
sizeof(cuinfo));
 
  135     ctx->internal_error = 0;
 
  137     avctx->coded_width = cuinfo.ulWidth = 
format->coded_width;
 
  138     avctx->coded_height = cuinfo.ulHeight = 
format->coded_height;
 
  141     cuinfo.display_area.left = 
format->display_area.left + 
ctx->crop.left;
 
  142     cuinfo.display_area.top = 
format->display_area.top + 
ctx->crop.top;
 
  143     cuinfo.display_area.right = 
format->display_area.right - 
ctx->crop.right;
 
  144     cuinfo.display_area.bottom = 
format->display_area.bottom - 
ctx->crop.bottom;
 
  147     if (
ctx->resize_expr) {
 
  148         avctx->width = 
ctx->resize.width;
 
  149         avctx->height = 
ctx->resize.height;
 
  151         avctx->width = cuinfo.display_area.right - cuinfo.display_area.left;
 
  152         avctx->height = cuinfo.display_area.bottom - cuinfo.display_area.top;
 
  156     cuinfo.ulTargetWidth = avctx->width = (avctx->width + 1) & ~1;
 
  157     cuinfo.ulTargetHeight = avctx->height = (avctx->height + 1) & ~1;
 
  160     cuinfo.target_rect.left = 0;
 
  161     cuinfo.target_rect.top = 0;
 
  162     cuinfo.target_rect.right = cuinfo.ulTargetWidth;
 
  163     cuinfo.target_rect.bottom = cuinfo.ulTargetHeight;
 
  165     switch (
format->bit_depth_luma_minus8) {
 
  177                format->bit_depth_luma_minus8 + 8);
 
  182     if (surface_fmt < 0) {
 
  193     avctx->pix_fmt = surface_fmt;
 
  196     if (avctx->hw_frames_ctx) {
 
  210         (
AVRational){ avctx->width, avctx->height }));
 
  212     ctx->deint_mode_current = 
format->progressive_sequence
 
  221     if (
format->video_signal_description.video_full_range_flag)
 
  226     avctx->color_primaries = 
format->video_signal_description.color_primaries;
 
  227     avctx->color_trc = 
format->video_signal_description.transfer_characteristics;
 
  228     avctx->colorspace = 
format->video_signal_description.matrix_coefficients;
 
  231         avctx->bit_rate = 
format->bitrate;
 
  233     if (
format->frame_rate.numerator && 
format->frame_rate.denominator) {
 
  234         avctx->framerate.num = 
format->frame_rate.numerator;
 
  235         avctx->framerate.den = 
format->frame_rate.denominator;
 
  239             && avctx->coded_width == 
format->coded_width
 
  240             && avctx->coded_height == 
format->coded_height
 
  241             && avctx->width == old_width
 
  242             && avctx->height == old_height
 
  243             && 
ctx->chroma_format == 
format->chroma_format
 
  247     if (
ctx->cudecoder) {
 
  250         if (
ctx->internal_error < 0)
 
  255     if (hwframe_ctx->pool && (
 
  256             hwframe_ctx->width < avctx->width ||
 
  257             hwframe_ctx->height < avctx->height ||
 
  259             hwframe_ctx->sw_format != avctx->sw_pix_fmt)) {
 
  260         av_log(avctx, 
AV_LOG_ERROR, 
"AVHWFramesContext is already initialized with incompatible parameters\n");
 
  262         av_log(avctx, 
AV_LOG_DEBUG, 
"height: %d <-> %d\n", hwframe_ctx->height, avctx->height);
 
  276     ctx->chroma_format = 
format->chroma_format;
 
  278     cuinfo.CodecType = 
ctx->codec_type = 
format->codec;
 
  279     cuinfo.ChromaFormat = 
format->chroma_format;
 
  281     switch (avctx->sw_pix_fmt) {
 
  290         av_log(avctx, 
AV_LOG_ERROR, 
"Output formats other than NV12, P010 or P016 are not supported\n");
 
  295     cuinfo.ulNumDecodeSurfaces = 
ctx->nb_surfaces;
 
  296     cuinfo.ulNumOutputSurfaces = 1;
 
  298     cuinfo.bitDepthMinus8 = 
format->bit_depth_luma_minus8;
 
  299     cuinfo.DeinterlaceMode = 
ctx->deint_mode_current;
 
  304     ctx->internal_error = 
CHECK_CU(
ctx->cvdl->cuvidCreateDecoder(&
ctx->cudecoder, &cuinfo));
 
  305     if (
ctx->internal_error < 0)
 
  308     if (!hwframe_ctx->pool) {
 
  310         hwframe_ctx->sw_format = avctx->sw_pix_fmt;
 
  311         hwframe_ctx->width = avctx->width;
 
  312         hwframe_ctx->height = avctx->height;
 
  369     int ret = 0, eret = 0, is_flush = 
ctx->decoder_flushing;
 
  373     if (is_flush && avpkt && avpkt->size)
 
  379     if (
ctx->bsf && avpkt && avpkt->size) {
 
  396         avpkt = &filtered_packet;
 
  399     ret = 
CHECK_CU(
ctx->cudl->cuCtxPushCurrent(cuda_ctx));
 
  405     memset(&cupkt, 0, 
sizeof(cupkt));
 
  407     if (avpkt && avpkt->size) {
 
  408         cupkt.payload_size = avpkt->size;
 
  409         cupkt.payload = avpkt->data;
 
  413             if (avctx->pkt_timebase.num && avctx->pkt_timebase.den)
 
  416                 cupkt.timestamp = avpkt->pts;
 
  420         ctx->decoder_flushing = 1;
 
  423     ret = 
CHECK_CU(
ctx->cvdl->cuvidParseVideoData(
ctx->cuparser, &cupkt));
 
  431     if (
ctx->internal_error) {
 
  433         ret = 
ctx->internal_error;
 
  457     int ret = 0, eret = 0;
 
  474         unsigned int pitch = 0;
 
  480         memset(¶ms, 0, 
sizeof(params));
 
  502             for (i = 0; i < 2; i++) {
 
  506                     .srcDevice     = mapped_frame,
 
  512                     .Height        = avctx->
height >> (i ? 1 : 0),
 
  573                 frame->
pts += pts_diff;
 
  633     } 
else if (ret < 0) {
 
  677     memset(&cuinfo, 0, 
sizeof(cuinfo));
 
  798     device_hwctx = device_ctx->
hwctx;
 
  805     memset(&seq_pkt, 0, 
sizeof(seq_pkt));
 
  810 #if CONFIG_H264_CUVID_DECODER 
  815 #if CONFIG_HEVC_CUVID_DECODER 
  820 #if CONFIG_MJPEG_CUVID_DECODER 
  825 #if CONFIG_MPEG1_CUVID_DECODER 
  830 #if CONFIG_MPEG2_CUVID_DECODER 
  835 #if CONFIG_MPEG4_CUVID_DECODER 
  840 #if CONFIG_VP8_CUVID_DECODER 
  845 #if CONFIG_VP9_CUVID_DECODER 
  850 #if CONFIG_VC1_CUVID_DECODER 
  944     ret = 
CHECK_CU(
ctx->cudl->cuCtxPushCurrent(cuda_ctx));
 
  951     if (!
ctx->frame_queue) {
 
  956     if (
ctx->cudecoder) {
 
  957         ctx->cvdl->cuvidDestroyDecoder(
ctx->cudecoder);
 
  962         ctx->cvdl->cuvidDestroyVideoParser(
ctx->cuparser);
 
  966     ret = 
CHECK_CU(
ctx->cvdl->cuvidCreateVideoParser(&
ctx->cuparser, &
ctx->cuparseinfo));
 
  970     seq_pkt.payload = 
ctx->cuparse_ext.raw_seqhdr_data;
 
  971     seq_pkt.payload_size = 
ctx->cuparse_ext.format.seqhdr_data_length;
 
  973     if (seq_pkt.payload && seq_pkt.payload_size) {
 
  974         ret = 
CHECK_CU(
ctx->cvdl->cuvidParseVideoData(
ctx->cuparser, &seq_pkt));
 
  983     ctx->prev_pts = INT64_MIN;
 
  984     ctx->decoder_flushing = 0;
 
  991 #define OFFSET(x) offsetof(CuvidContext, x) 
  992 #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM 
  999     { 
"surfaces", 
"Maximum surfaces to be used for decoding", 
OFFSET(nb_surfaces), 
AV_OPT_TYPE_INT, { .i64 = 25 }, 0, INT_MAX, 
VD },
 
 1000     { 
"drop_second_field", 
"Drop second field when deinterlacing", 
OFFSET(drop_second_field), 
AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, 
VD },
 
 1006 #define DEFINE_CUVID_CODEC(x, X) \ 
 1007     static const AVClass x##_cuvid_class = { \ 
 1008         .class_name = #x "_cuvid", \ 
 1009         .item_name = av_default_item_name, \ 
 1010         .option = options, \ 
 1011         .version = LIBAVUTIL_VERSION_INT, \ 
 1013     AVHWAccel ff_##x##_cuvid_hwaccel = { \ 
 1014         .name           = #x "_cuvid", \ 
 1015         .type           = AVMEDIA_TYPE_VIDEO, \ 
 1016         .id             = AV_CODEC_ID_##X, \ 
 1017         .pix_fmt        = AV_PIX_FMT_CUDA, \ 
 1019     AVCodec ff_##x##_cuvid_decoder = { \ 
 1020         .name           = #x "_cuvid", \ 
 1021         .long_name      = NULL_IF_CONFIG_SMALL("Nvidia CUVID " #X " decoder"), \ 
 1022         .type           = AVMEDIA_TYPE_VIDEO, \ 
 1023         .id             = AV_CODEC_ID_##X, \ 
 1024         .priv_data_size = sizeof(CuvidContext), \ 
 1025         .priv_class     = &x##_cuvid_class, \ 
 1026         .init           = cuvid_decode_init, \ 
 1027         .close          = cuvid_decode_end, \ 
 1028         .decode         = cuvid_decode_frame, \ 
 1029         .send_packet    = cuvid_decode_packet, \ 
 1030         .receive_frame  = cuvid_output_frame, \ 
 1031         .flush          = cuvid_flush, \ 
 1032         .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING, \ 
 1033         .pix_fmts       = (const enum AVPixelFormat[]){ AV_PIX_FMT_CUDA, \ 
 1037                                                         AV_PIX_FMT_NONE }, \ 
 1040 #if CONFIG_HEVC_CUVID_DECODER 
 1044 #if CONFIG_H264_CUVID_DECODER 
 1048 #if CONFIG_MJPEG_CUVID_DECODER 
 1052 #if CONFIG_MPEG1_CUVID_DECODER 
 1056 #if CONFIG_MPEG2_CUVID_DECODER 
 1060 #if CONFIG_MPEG4_CUVID_DECODER 
 1064 #if CONFIG_VP8_CUVID_DECODER 
 1068 #if CONFIG_VP9_CUVID_DECODER 
 1072 #if CONFIG_VC1_CUVID_DECODER 
This struct aggregates all the (hardware/vendor-specific) "high-level" state, i.e. 
void av_bsf_free(AVBSFContext **ctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
const struct AVCodec * codec
AVCodecParameters * par_out
Parameters of the output stream. 
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another. 
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
This structure describes decoded (raw) audio or video data. 
tcu_ulong payload_size
number of bytes in the payload (may be zero if EOS flag is set) 
ptrdiff_t const GLvoid * data
#define AV_CODEC_FLAG_INTERLACED_DCT
Use interlaced DCT. 
tcu_ulong ulNumOutputSurfaces
Maximum number of output surfaces simultaneously mapped. 
int coded_width
Bitstream width / height, may be different from width/height e.g. 
#define AV_LOG_WARNING
Something somehow does not look correct. 
static void cuvid_free_functions(CuvidFunctions **functions)
AVCUDADeviceContextInternal * internal
The bitstream filter state. 
static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT *format)
tcuvidUnmapVideoFrame * cuvidUnmapVideoFrame
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx. 
void av_frame_set_pkt_duration(AVFrame *frame, int64_t val)
struct CUVIDDECODECREATEINFO::@25 target_rect
target rectangle in the output frame (for aspect ratio conversion) if a null rectangle is specified...
#define DEFINE_CUVID_CODEC(x, X)
CUVIDPARSERPARAMS cuparseinfo
Use dedicated video engines directly. 
void av_frame_set_pkt_size(AVFrame *frame, int val)
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set. 
static int check_cu(AVCodecContext *avctx, CUresult err, const char *func)
int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int(*func)(void *, void *, int))
Feed data from a user-supplied callback to an AVFifoBuffer. 
cudaVideoDeinterlaceMode DeinterlaceMode
cudaVideoDeinterlaceMode_XXX 
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame...
Set when this is the last packet for this stream. 
int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **ctx)
Allocate a context for a given bitstream filter. 
static void cuvid_flush(AVCodecContext *avctx)
cudaVideoCodec CodecType
cudaVideoCodec_XXX 
tcuvidCreateVideoParser * cuvidCreateVideoParser
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet. 
tcuvidMapVideoFrame * cuvidMapVideoFrame
cudaVideoSurfaceFormat OutputFormat
cudaVideoSurfaceFormat_XXX 
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values. 
tcuvidDestroyDecoder * cuvidDestroyDecoder
static int cuvid_test_dummy_decoder(AVCodecContext *avctx, const CUVIDPARSERPARAMS *cuparseinfo, int probed_width, int probed_height)
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development. 
tcu_ulong ulTargetWidth
Post-processed Output Width (Should be aligned to 2) 
static int cuvid_decode_packet(AVCodecContext *avctx, const AVPacket *avpkt)
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
Set various frame properties from the codec context / packet data. 
static av_cold int cuvid_decode_init(AVCodecContext *avctx)
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user). 
AVFifoBuffer * frame_queue
uint8_t * extradata
some codecs need / can use extradata like Huffman tables. 
void * hwctx
The format-specific data, allocated and freed by libavutil along with this context. 
CUVIDEOFORMATEX * pExtVideoInfo
[Optional] sequence header data from system layer 
int av_hwdevice_ctx_create(AVBufferRef **pdevice_ref, enum AVHWDeviceType type, const char *device, AVDictionary *opts, int flags)
Open a device of the specified type and create an AVHWDeviceContext for it. 
int flags
Flags modifying the (de)muxer behaviour. 
static av_cold int cuvid_decode_end(AVCodecContext *avctx)
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context. 
#define AVERROR_EOF
End of file. 
#define AV_LOG_VERBOSE
Detailed information. 
int interlaced_frame
The content of the picture is interlaced. 
tcuCtxPushCurrent_v2 * cuCtxPushCurrent
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet. 
Weave both fields (no deinterlacing) 
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers. 
AVRational pkt_timebase
Timebase in which pkt_dts/pts and AVPacket.dts/pts are. 
cudaVideoChromaFormat chroma_format
int width
width and height of the video frame 
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered. 
cudaVideoCodec codec_type
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g. 
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers. 
int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void(*func)(void *, void *, int))
Feed data from an AVFifoBuffer to a user-supplied callback. 
tcuvidDecodePicture * cuvidDecodePicture
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
int av_hwframe_ctx_init(AVBufferRef *ref)
Finalize the context before use. 
static const uint8_t offset[127][2]
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext. 
tcuvidParseVideoData * cuvidParseVideoData
int extradata_size
Size of the extradata content in bytes. 
static int cuvid_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags)
Copy data to or from a hw surface. 
int progressive_frame
Input is progressive (deinterlace_mode will be ignored) 
tcu_ulong ulCreationFlags
Decoder creation flags (cudaVideoCreateFlags_XXX) 
AVHWDeviceContext * device_ctx
The parent AVHWDeviceContext. 
int second_field
Output the second field (ignored if deinterlace mode is Weave) 
int width
picture width / height. 
tcuvidCreateDecoder * cuvidCreateDecoder
static int filter_packet(AVFormatContext *avf, ConcatStream *cs, AVPacket *pkt)
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames...
int top_field_first
Input frame is top field first (1st field is top, 2nd field is bottom) 
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering. 
void av_frame_set_pkt_pos(AVFrame *frame, int64_t val)
tcuGetErrorString * cuGetErrorString
#define AVERROR_BSF_NOT_FOUND
Bitstream filter not found. 
FFmpeg internal API for CUDA. 
static int CUDAAPI cuvid_handle_picture_display(void *opaque, CUVIDPARSERDISPINFO *dispinfo)
HW acceleration through CUDA. 
preferred ID for MPEG-1/2 video decoding 
static void error(const char *err)
the normal 2^n-1 "JPEG" YUV ranges 
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format. 
tcuGetErrorName * cuGetErrorName
CUmemorytype srcMemoryType
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
tcu_ulong ulNumDecodeSurfaces
Maximum number of internal decode surfaces. 
Libavcodec external API header. 
PFNVIDSEQUENCECALLBACK pfnSequenceCallback
Called before decoding frames and/or whenever there is a format change. 
int av_fifo_size(const AVFifoBuffer *f)
Return the amount of data in bytes in the AVFifoBuffer, that is the amount of data you can read from ...
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line. 
main external API structure. 
void av_packet_unref(AVPacket *pkt)
Wipe the packet. 
uint8_t * data
The data buffer. 
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame. 
a very simple circular buffer FIFO implementation 
struct CuvidContext::@51 crop
tcuMemcpy2D_v2 * cuMemcpy2D
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2. 
This struct is allocated as AVHWDeviceContext.hwctx. 
static const char * format
Describe the class of an AVClass context structure. 
const unsigned char * payload
Pointer to packet payload data (may be NULL if EOS flag is set) 
Rational number (pair of numerator and denominator). 
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context. 
This struct describes a set or pool of "hardware" frames (i.e. 
CUvideotimestamp timestamp
static const AVOption options[]
int(* func)(AVBPrint *dst, const char *in, const char *arg)
refcounted data buffer API 
tcu_ulong ulWidth
Coded Sequence Width. 
struct CuvidContext::@52 resize
static enum AVPixelFormat pix_fmts[]
cudaVideoCodec CodecType
cudaVideoCodec_XXX 
CUVIDPARSERDISPINFO dispinfo
static int cuvid_output_frame(AVCodecContext *avctx, AVFrame *frame)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes. 
AVBufferRef * device_ref
A reference to the parent AVHWDeviceContext. 
attribute_deprecated int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame. 
the normal 219*2^(n-8) "MPEG" YUV ranges 
A reference to a data buffer. 
PFNVIDDECODECALLBACK pfnDecodePicture
Called when a picture is ready to be decoded (decode order) 
void * pUserData
User data for callbacks. 
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header. 
AVBufferRef * av_hwframe_ctx_alloc(AVBufferRef *device_ref_in)
Allocate an AVHWFramesContext tied to a given device context. 
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer. 
static int CUDAAPI cuvid_handle_picture_decode(void *opaque, CUVIDPICPARAMS *picparams)
tcuCtxPopCurrent_v2 * cuCtxPopCurrent
unsigned int ulMaxNumDecodeSurfaces
Max # of decode surfaces (parser will cycle through these) 
tcuvidDestroyVideoParser * cuvidDestroyVideoParser
AVFifoBuffer * av_fifo_alloc(unsigned int size)
Initialize an AVFifoBuffer. 
#define FF_ENABLE_DEPRECATION_WARNINGS
int top_field_first
If the content is interlaced, is top field displayed first. 
tcu_ulong ulHeight
Coded Sequence Height. 
cudaVideoChromaFormat ChromaFormat
cudaVideoChromaFormat_XXX (only 4:2:0 is currently supported) 
tcu_ulong ulTargetHeight
Post-processed Output Height (Should be aligbed to 2) 
PFNVIDDISPLAYCALLBACK pfnDisplayPicture
Called whenever a picture is ready to be displayed (display order) 
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent. 
AVRational av_mul_q(AVRational b, AVRational c)
Multiply two rationals. 
unsigned int ulMaxDisplayDelay
Max display queue delay (improves pipelining of decode with display) - 0=no delay (recommended values...
static int cuvid_load_functions(CuvidFunctions **functions)
CUVIDEOFORMATEX cuparse_ext
void av_fifo_freep(AVFifoBuffer **f)
Free an AVFifoBuffer and reset pointer to NULL. 
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. 
#define AVERROR_EXTERNAL
Generic error in an external library. 
AVPixelFormat
Pixel format. 
This structure stores compressed data. 
AVCodecParameters * par_in
Parameters of the input stream. 
#define AV_NOPTS_VALUE
Undefined timestamp value.