Browse code

avcodec/cuvid: add cuvid decoder

Timo Rothenpieler authored on 2016/06/05 02:06:52
Showing 7 changed files
... ...
@@ -40,6 +40,8 @@ version <next>:
40 40
 - MagicYUV decoder
41 41
 - OpenExr improvements (tile data and B44/B44A support)
42 42
 - BitJazz SheerVideo decoder
43
+- CUDA CUVID H264/HEVC decoder
44
+
43 45
 
44 46
 version 3.0:
45 47
 - Common Encryption (CENC) MP4 encoding and decoding support
... ...
@@ -163,6 +163,7 @@ Codecs:
163 163
   cpia.c                                Stephan Hilb
164 164
   crystalhd.c                           Philip Langdale
165 165
   cscd.c                                Reimar Doeffinger
166
+  cuvid.c                               Timo Rothenpieler
166 167
   dca.c                                 Kostya Shishkov, Benjamin Larsson
167 168
   dirac*                                Rostislav Pehlivanov
168 169
   dnxhd*                                Baptiste Coudurier
... ...
@@ -158,6 +158,7 @@ Hardware accelerators:
158 158
 
159 159
 Hardware-accelerated decoding/encoding:
160 160
   --enable-cuda            enable dynamically linked CUDA [no]
161
+  --enable-cuvid           enable CUVID support [autodetect]
161 162
   --enable-libmfx          enable HW acceleration through libmfx
162 163
   --enable-mmal            enable decoding via MMAL [no]
163 164
   --enable-nvenc           enable NVIDIA NVENC support [no]
... ...
@@ -1567,6 +1568,7 @@ FEATURE_LIST="
1567 1567
 
1568 1568
 HW_CODECS_LIST="
1569 1569
     cuda
1570
+    cuvid
1570 1571
     libmfx
1571 1572
     mmal
1572 1573
     nvenc
... ...
@@ -2522,6 +2524,7 @@ audiotoolbox_extralibs="-framework CoreFoundation -framework AudioToolbox -frame
2522 2522
 
2523 2523
 # hardware accelerators
2524 2524
 crystalhd_deps="libcrystalhd_libcrystalhd_if_h"
2525
+cuvid_deps="cuda"
2525 2526
 d3d11va_deps="d3d11_h dxva_h ID3D11VideoDecoder ID3D11VideoContext"
2526 2527
 dxva2_deps="dxva2api_h DXVA2_ConfigPictureDecode"
2527 2528
 vaapi_deps="va_va_h"
... ...
@@ -2539,6 +2542,7 @@ h263_vaapi_hwaccel_select="h263_decoder"
2539 2539
 h263_videotoolbox_hwaccel_deps="videotoolbox"
2540 2540
 h263_videotoolbox_hwaccel_select="h263_decoder"
2541 2541
 h264_crystalhd_decoder_select="crystalhd h264_mp4toannexb_bsf h264_parser"
2542
+h264_cuvid_hwaccel_deps="cuda cuvid CUVIDH264PICPARAMS"
2542 2543
 h264_d3d11va_hwaccel_deps="d3d11va"
2543 2544
 h264_d3d11va_hwaccel_select="h264_decoder"
2544 2545
 h264_dxva2_hwaccel_deps="dxva2"
... ...
@@ -2564,6 +2568,7 @@ h264_vdpau_hwaccel_deps="vdpau"
2564 2564
 h264_vdpau_hwaccel_select="h264_decoder"
2565 2565
 h264_videotoolbox_hwaccel_deps="videotoolbox"
2566 2566
 h264_videotoolbox_hwaccel_select="h264_decoder"
2567
+hevc_cuvid_hwaccel_deps="cuda cuvid CUVIDHEVCPICPARAMS"
2567 2568
 hevc_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_HEVC"
2568 2569
 hevc_d3d11va_hwaccel_select="hevc_decoder"
2569 2570
 hevc_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_HEVC"
... ...
@@ -2618,6 +2623,7 @@ mpeg4_videotoolbox_hwaccel_deps="videotoolbox"
2618 2618
 mpeg4_videotoolbox_hwaccel_select="mpeg4_decoder"
2619 2619
 msmpeg4_crystalhd_decoder_select="crystalhd"
2620 2620
 vc1_crystalhd_decoder_select="crystalhd"
2621
+vc1_cuvid_hwaccel_deps="cuda cuvid CUVIDVC1PICPARAMS"
2621 2622
 vc1_d3d11va_hwaccel_deps="d3d11va"
2622 2623
 vc1_d3d11va_hwaccel_select="vc1_decoder"
2623 2624
 vc1_dxva2_hwaccel_deps="dxva2"
... ...
@@ -2633,6 +2639,8 @@ vc1_vdpau_decoder_deps="vdpau"
2633 2633
 vc1_vdpau_decoder_select="vc1_decoder"
2634 2634
 vc1_vdpau_hwaccel_deps="vdpau"
2635 2635
 vc1_vdpau_hwaccel_select="vc1_decoder"
2636
+vp8_cuvid_hwaccel_deps="cuda cuvid CUVIDVP9PICPARAMS"
2637
+vp9_cuvid_hwaccel_deps="cuda cuvid CUVIDVP9PICPARAMS"
2636 2638
 vp9_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_VP9"
2637 2639
 vp9_d3d11va_hwaccel_select="vp9_decoder"
2638 2640
 vp9_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_VP9"
... ...
@@ -2657,6 +2665,8 @@ hwupload_cuda_filter_deps="cuda"
2657 2657
 scale_npp_filter_deps="cuda libnpp"
2658 2658
 
2659 2659
 nvenc_encoder_deps="nvenc"
2660
+h264_cuvid_decoder_deps="cuda cuvid CUVIDH264PICPARAMS"
2661
+h264_cuvid_decoder_select="h264_mp4toannexb_bsf h264_cuvid_hwaccel"
2660 2662
 h264_qsv_decoder_deps="libmfx"
2661 2663
 h264_qsv_decoder_select="h264_mp4toannexb_bsf h264_parser qsvdec h264_qsv_hwaccel"
2662 2664
 h264_qsv_encoder_deps="libmfx"
... ...
@@ -2664,6 +2674,8 @@ h264_qsv_encoder_select="qsvenc"
2664 2664
 h264_vaapi_encoder_deps="VAEncPictureParameterBufferH264"
2665 2665
 h264_vaapi_encoder_select="vaapi_encode golomb"
2666 2666
 
2667
+hevc_cuvid_decoder_deps="cuda cuvid CUVIDHEVCPICPARAMS"
2668
+hevc_cuvid_decoder_select="hevc_mp4toannexb_bsf hevc_cuvid_hwaccel"
2667 2669
 hevc_qsv_decoder_deps="libmfx"
2668 2670
 hevc_qsv_decoder_select="hevc_mp4toannexb_bsf hevc_parser qsvdec hevc_qsv_hwaccel"
2669 2671
 hevc_qsv_encoder_deps="libmfx"
... ...
@@ -2677,6 +2689,13 @@ mpeg2_qsv_encoder_select="qsvenc"
2677 2677
 nvenc_h264_encoder_deps="nvenc"
2678 2678
 nvenc_hevc_encoder_deps="nvenc"
2679 2679
 
2680
+vc1_cuvid_decoder_deps="cuda cuvid CUVIDVC1PICPARAMS"
2681
+vc1_cuvid_decoder_select="vc1_cuvid_hwaccel"
2682
+vp8_cuvid_decoder_deps="cuda cuvid CUVIDVP9PICPARAMS"
2683
+vp8_cuvid_decoder_select="vp8_cuvid_hwaccel"
2684
+vp9_cuvid_decoder_deps="cuda cuvid CUVIDVP9PICPARAMS"
2685
+vp9_cuvid_decoder_select="vp9_cuvid_hwaccel"
2686
+
2680 2687
 # parsers
2681 2688
 h264_parser_select="h264_decoder"
2682 2689
 hevc_parser_select="golomb"
... ...
@@ -5002,6 +5021,7 @@ die_license_disabled gpl libxvid
5002 5002
 die_license_disabled gpl x11grab
5003 5003
 
5004 5004
 die_license_disabled nonfree cuda
5005
+die_license_disabled nonfree cuvid
5005 5006
 die_license_disabled nonfree libfaac
5006 5007
 die_license_disabled nonfree libnpp
5007 5008
 enabled gpl && die_license_disabled_gpl nonfree libfdk_aac
... ...
@@ -5509,6 +5529,11 @@ check_type "va/va.h va/va_enc_jpeg.h" "VAEncPictureParameterBufferJPEG"
5509 5509
 
5510 5510
 check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC"
5511 5511
 
5512
+check_type "cuviddec.h" "CUVIDH264PICPARAMS"
5513
+check_type "cuviddec.h" "CUVIDHEVCPICPARAMS"
5514
+check_type "cuviddec.h" "CUVIDVC1PICPARAMS"
5515
+check_type "cuviddec.h" "CUVIDVP9PICPARAMS"
5516
+
5512 5517
 check_cpp_condition windows.h "!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)" && enable winrt || disable winrt
5513 5518
 
5514 5519
 if ! disabled w32threads && ! enabled pthreads; then
... ...
@@ -5572,6 +5597,11 @@ for func in $COMPLEX_FUNCS; do
5572 5572
     eval check_complexfunc $func \${${func}_args:-1}
5573 5573
 done
5574 5574
 
5575
+# Enable CUVID by default if CUDA is enabled
5576
+if enabled cuda && ! disabled cuvid; then
5577
+    enable cuvid
5578
+fi
5579
+
5575 5580
 # these are off by default, so fail if requested and not available
5576 5581
 enabled avfoundation_indev && { check_header_objcc AVFoundation/AVFoundation.h || disable avfoundation_indev; }
5577 5582
 enabled avfoundation_indev && { check_lib2 CoreGraphics/CoreGraphics.h CGGetActiveDisplayList -framework CoreGraphics ||
... ...
@@ -5581,6 +5611,10 @@ enabled avisynth          && { { check_lib2 "windows.h" LoadLibrary; } ||
5581 5581
                                die "ERROR: LoadLibrary/dlopen not found for avisynth"; }
5582 5582
 enabled cuda              && { check_lib cuda.h cuInit -lcuda ||
5583 5583
                                die "ERROR: CUDA not found"; }
5584
+enabled cuvid             && { check_lib cuviddec.h cuvidCreateDecoder -lnvcuvid ||
5585
+                               die "ERROR: CUVID not found"; } &&
5586
+                             { enabled cuda ||
5587
+                               die "ERROR: CUVID requires CUDA"; }
5584 5588
 enabled chromaprint       && require chromaprint chromaprint.h chromaprint_get_version -lchromaprint
5585 5589
 enabled coreimage_filter  && { check_header_objcc QuartzCore/CoreImage.h || disable coreimage_filter; }
5586 5590
 enabled coreimagesrc_filter && { check_header_objcc QuartzCore/CoreImage.h || disable coreimagesrc_filter; }
... ...
@@ -768,12 +768,14 @@ OBJS-$(CONFIG_QSV)                        += qsv.o
768 768
 OBJS-$(CONFIG_QSVDEC)                     += qsvdec.o
769 769
 OBJS-$(CONFIG_QSVENC)                     += qsvenc.o
770 770
 
771
+OBJS-$(CONFIG_H264_CUVID_DECODER)         += cuvid.o
771 772
 OBJS-$(CONFIG_H264_MMAL_DECODER)          += mmaldec.o
772 773
 OBJS-$(CONFIG_H264_VDA_DECODER)           += vda_h264_dec.o
773 774
 OBJS-$(CONFIG_H264_OMX_ENCODER)           += omx.o
774 775
 OBJS-$(CONFIG_H264_QSV_DECODER)           += qsvdec_h2645.o
775 776
 OBJS-$(CONFIG_H264_QSV_ENCODER)           += qsvenc_h264.o
776 777
 OBJS-$(CONFIG_H264_VAAPI_ENCODER)         += vaapi_encode_h264.o vaapi_encode_h26x.o
778
+OBJS-$(CONFIG_HEVC_CUVID_DECODER)         += cuvid.o
777 779
 OBJS-$(CONFIG_HEVC_QSV_DECODER)           += qsvdec_h2645.o
778 780
 OBJS-$(CONFIG_HEVC_QSV_ENCODER)           += qsvenc_hevc.o hevc_ps_enc.o h2645_parse.o
779 781
 OBJS-$(CONFIG_HEVC_VAAPI_ENCODER)         += vaapi_encode_h265.o vaapi_encode_h26x.o
... ...
@@ -784,6 +786,9 @@ OBJS-$(CONFIG_MPEG4_OMX_ENCODER)          += omx.o
784 784
 OBJS-$(CONFIG_NVENC_ENCODER)              += nvenc_h264.o
785 785
 OBJS-$(CONFIG_NVENC_H264_ENCODER)         += nvenc_h264.o
786 786
 OBJS-$(CONFIG_NVENC_HEVC_ENCODER)         += nvenc_hevc.o
787
+OBJS-$(CONFIG_VC1_CUVID_DECODER)          += cuvid.o
788
+OBJS-$(CONFIG_VP8_CUVID_DECODER)          += cuvid.o
789
+OBJS-$(CONFIG_VP9_CUVID_DECODER)          += cuvid.o
787 790
 
788 791
 # libavformat dependencies
789 792
 OBJS-$(CONFIG_ISO_MEDIA)               += mpeg4audio.o mpegaudiodata.o
... ...
@@ -69,6 +69,7 @@ void avcodec_register_all(void)
69 69
     /* hardware accelerators */
70 70
     REGISTER_HWACCEL(H263_VAAPI,        h263_vaapi);
71 71
     REGISTER_HWACCEL(H263_VIDEOTOOLBOX, h263_videotoolbox);
72
+    REGISTER_HWACCEL(H264_CUVID,        h264_cuvid);
72 73
     REGISTER_HWACCEL(H264_D3D11VA,      h264_d3d11va);
73 74
     REGISTER_HWACCEL(H264_DXVA2,        h264_dxva2);
74 75
     REGISTER_HWACCEL(H264_MMAL,         h264_mmal);
... ...
@@ -78,6 +79,7 @@ void avcodec_register_all(void)
78 78
     REGISTER_HWACCEL(H264_VDA_OLD,      h264_vda_old);
79 79
     REGISTER_HWACCEL(H264_VDPAU,        h264_vdpau);
80 80
     REGISTER_HWACCEL(H264_VIDEOTOOLBOX, h264_videotoolbox);
81
+    REGISTER_HWACCEL(HEVC_CUVID,        hevc_cuvid);
81 82
     REGISTER_HWACCEL(HEVC_D3D11VA,      hevc_d3d11va);
82 83
     REGISTER_HWACCEL(HEVC_DXVA2,        hevc_dxva2);
83 84
     REGISTER_HWACCEL(HEVC_QSV,          hevc_qsv);
... ...
@@ -98,12 +100,15 @@ void avcodec_register_all(void)
98 98
     REGISTER_HWACCEL(MPEG4_VAAPI,       mpeg4_vaapi);
99 99
     REGISTER_HWACCEL(MPEG4_VDPAU,       mpeg4_vdpau);
100 100
     REGISTER_HWACCEL(MPEG4_VIDEOTOOLBOX, mpeg4_videotoolbox);
101
+    REGISTER_HWACCEL(VC1_CUVID,         vc1_cuvid);
101 102
     REGISTER_HWACCEL(VC1_D3D11VA,       vc1_d3d11va);
102 103
     REGISTER_HWACCEL(VC1_DXVA2,         vc1_dxva2);
103 104
     REGISTER_HWACCEL(VC1_VAAPI,         vc1_vaapi);
104 105
     REGISTER_HWACCEL(VC1_VDPAU,         vc1_vdpau);
105 106
     REGISTER_HWACCEL(VC1_MMAL,          vc1_mmal);
106 107
     REGISTER_HWACCEL(VC1_QSV,           vc1_qsv);
108
+    REGISTER_HWACCEL(VP8_CUVID,         vp8_cuvid);
109
+    REGISTER_HWACCEL(VP9_CUVID,         vp9_cuvid);
107 110
     REGISTER_HWACCEL(VP9_D3D11VA,       vp9_d3d11va);
108 111
     REGISTER_HWACCEL(VP9_DXVA2,         vp9_dxva2);
109 112
     REGISTER_HWACCEL(VP9_VAAPI,         vp9_vaapi);
... ...
@@ -618,6 +623,7 @@ void avcodec_register_all(void)
618 618
     /* external libraries, that shouldn't be used by default if one of the
619 619
      * above is available */
620 620
     REGISTER_ENCODER(LIBOPENH264,       libopenh264);
621
+    REGISTER_DECODER(H264_CUVID,        h264_cuvid);
621 622
     REGISTER_ENCODER(H264_QSV,          h264_qsv);
622 623
     REGISTER_ENCODER(H264_VAAPI,        h264_vaapi);
623 624
     REGISTER_ENCODER(H264_VIDEOTOOLBOX, h264_videotoolbox);
... ...
@@ -625,11 +631,15 @@ void avcodec_register_all(void)
625 625
     REGISTER_ENCODER(H264_OMX,          h264_omx);
626 626
     REGISTER_ENCODER(NVENC_H264,        nvenc_h264);
627 627
     REGISTER_ENCODER(NVENC_HEVC,        nvenc_hevc);
628
+    REGISTER_DECODER(HEVC_CUVID,        hevc_cuvid);
628 629
     REGISTER_ENCODER(HEVC_QSV,          hevc_qsv);
629 630
     REGISTER_ENCODER(HEVC_VAAPI,        hevc_vaapi);
630 631
     REGISTER_ENCODER(LIBKVAZAAR,        libkvazaar);
631 632
     REGISTER_ENCODER(MJPEG_VAAPI,       mjpeg_vaapi);
632 633
     REGISTER_ENCODER(MPEG2_QSV,         mpeg2_qsv);
634
+    REGISTER_DECODER(VC1_CUVID,         vc1_cuvid);
635
+    REGISTER_DECODER(VP8_CUVID,         vp8_cuvid);
636
+    REGISTER_DECODER(VP9_CUVID,         vp9_cuvid);
633 637
 
634 638
     /* parsers */
635 639
     REGISTER_PARSER(AAC,                aac);
636 640
new file mode 100644
... ...
@@ -0,0 +1,698 @@
0
+/*
1
+ * Nvidia CUVID decoder
2
+ * Copyright (c) 2016 Timo Rothenpieler <timo@rothenpieler.org>
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
6
+ * FFmpeg is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * FFmpeg is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with FFmpeg; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+#include "libavutil/buffer.h"
22
+#include "libavutil/mathematics.h"
23
+#include "libavutil/hwcontext.h"
24
+#include "libavutil/hwcontext_cuda.h"
25
+#include "libavutil/fifo.h"
26
+#include "libavutil/log.h"
27
+
28
+#include "avcodec.h"
29
+#include "internal.h"
30
+
31
+#include <nvcuvid.h>
32
+
33
+#define MAX_FRAME_COUNT 20
34
+
35
+typedef struct CuvidContext
36
+{
37
+    CUvideodecoder cudecoder;
38
+    CUvideoparser cuparser;
39
+
40
+    AVBufferRef *hwdevice;
41
+    AVBufferRef *hwframe;
42
+
43
+    AVBSFContext *bsf;
44
+
45
+    AVFifoBuffer *frame_queue;
46
+
47
+    int internal_error;
48
+
49
+    cudaVideoCodec codec_type;
50
+    cudaVideoChromaFormat chroma_format;
51
+} CuvidContext;
52
+
53
+static int check_cu(AVCodecContext *avctx, CUresult err, const char *func)
54
+{
55
+    const char *err_name;
56
+    const char *err_string;
57
+
58
+    av_log(avctx, AV_LOG_TRACE, "Calling %s\n", func);
59
+
60
+    if (err == CUDA_SUCCESS)
61
+        return 0;
62
+
63
+    cuGetErrorName(err, &err_name);
64
+    cuGetErrorString(err, &err_string);
65
+
66
+    av_log(avctx, AV_LOG_ERROR, "%s failed", func);
67
+    if (err_name && err_string)
68
+        av_log(avctx, AV_LOG_ERROR, " -> %s: %s", err_name, err_string);
69
+    av_log(avctx, AV_LOG_ERROR, "\n");
70
+
71
+    return AVERROR_EXTERNAL;
72
+}
73
+
74
+#define CHECK_CU(x) check_cu(avctx, (x), #x)
75
+
76
+static int CUDAAPI cuvid_handle_video_sequence(void *opaque, CUVIDEOFORMAT* format)
77
+{
78
+    AVCodecContext *avctx = opaque;
79
+    CuvidContext *ctx = avctx->priv_data;
80
+    AVHWFramesContext *hwframe_ctx = (AVHWFramesContext*)ctx->hwframe->data;
81
+    CUVIDDECODECREATEINFO cuinfo;
82
+
83
+    av_log(avctx, AV_LOG_TRACE, "pfnSequenceCallback\n");
84
+
85
+    ctx->internal_error = 0;
86
+
87
+    avctx->width = format->display_area.right;
88
+    avctx->height = format->display_area.bottom;
89
+
90
+    ff_set_sar(avctx, av_div_q(
91
+        (AVRational){ format->display_aspect_ratio.x, format->display_aspect_ratio.y },
92
+        (AVRational){ avctx->width, avctx->height }));
93
+
94
+    if (!format->progressive_sequence)
95
+        avctx->flags |= AV_CODEC_FLAG_INTERLACED_DCT;
96
+    else
97
+        avctx->flags &= ~AV_CODEC_FLAG_INTERLACED_DCT;
98
+
99
+    if (format->video_signal_description.video_full_range_flag)
100
+        avctx->color_range = AVCOL_RANGE_JPEG;
101
+    else
102
+        avctx->color_range = AVCOL_RANGE_MPEG;
103
+
104
+    avctx->color_primaries = format->video_signal_description.color_primaries;
105
+    avctx->color_trc = format->video_signal_description.transfer_characteristics;
106
+    avctx->colorspace = format->video_signal_description.matrix_coefficients;
107
+
108
+    if (format->bitrate)
109
+        avctx->bit_rate = format->bitrate;
110
+
111
+    if (format->frame_rate.numerator && format->frame_rate.denominator) {
112
+        avctx->framerate.num = format->frame_rate.numerator;
113
+        avctx->framerate.den = format->frame_rate.denominator;
114
+    }
115
+
116
+    if (ctx->cudecoder
117
+            && avctx->coded_width == format->coded_width
118
+            && avctx->coded_height == format->coded_height
119
+            && ctx->chroma_format == format->chroma_format
120
+            && ctx->codec_type == format->codec)
121
+        return 1;
122
+
123
+    if (ctx->cudecoder) {
124
+        av_log(avctx, AV_LOG_ERROR, "re-initializing decoder is not supported\n");
125
+        ctx->internal_error = AVERROR(EINVAL);
126
+        return 0;
127
+    }
128
+
129
+    if (hwframe_ctx->pool) {
130
+        av_log(avctx, AV_LOG_ERROR, "AVHWFramesContext is already initialized\n");
131
+        ctx->internal_error = AVERROR(EINVAL);
132
+        return 0;
133
+    }
134
+
135
+    avctx->coded_width = format->coded_width;
136
+    avctx->coded_height = format->coded_height;
137
+
138
+    ctx->chroma_format = format->chroma_format;
139
+
140
+    memset(&cuinfo, 0, sizeof(cuinfo));
141
+
142
+    cuinfo.CodecType = ctx->codec_type = format->codec;
143
+    cuinfo.ChromaFormat = format->chroma_format;
144
+    cuinfo.OutputFormat = cudaVideoSurfaceFormat_NV12;
145
+
146
+    cuinfo.ulWidth = avctx->coded_width;
147
+    cuinfo.ulHeight = avctx->coded_height;
148
+    cuinfo.ulTargetWidth = cuinfo.ulWidth;
149
+    cuinfo.ulTargetHeight = cuinfo.ulHeight;
150
+
151
+    cuinfo.target_rect.left = 0;
152
+    cuinfo.target_rect.top = 0;
153
+    cuinfo.target_rect.right = cuinfo.ulWidth;
154
+    cuinfo.target_rect.bottom = cuinfo.ulHeight;
155
+
156
+    cuinfo.ulNumDecodeSurfaces = MAX_FRAME_COUNT;
157
+    cuinfo.ulNumOutputSurfaces = 1;
158
+    cuinfo.ulCreationFlags = cudaVideoCreate_PreferCUVID;
159
+
160
+    cuinfo.DeinterlaceMode = cudaVideoDeinterlaceMode_Weave;
161
+
162
+    ctx->internal_error = CHECK_CU(cuvidCreateDecoder(&ctx->cudecoder, &cuinfo));
163
+    if (ctx->internal_error < 0)
164
+        return 0;
165
+
166
+    hwframe_ctx->format = AV_PIX_FMT_CUDA;
167
+    hwframe_ctx->sw_format = AV_PIX_FMT_NV12;
168
+    hwframe_ctx->width = FFALIGN(avctx->coded_width, 32);
169
+    hwframe_ctx->height = FFALIGN(avctx->coded_height, 32);
170
+
171
+    if ((ctx->internal_error = av_hwframe_ctx_init(ctx->hwframe)) < 0) {
172
+        av_log(avctx, AV_LOG_ERROR, "av_hwframe_ctx_init failed\n");
173
+        return 0;
174
+    }
175
+
176
+    return 1;
177
+}
178
+
179
+static int CUDAAPI cuvid_handle_picture_decode(void *opaque, CUVIDPICPARAMS* picparams)
180
+{
181
+    AVCodecContext *avctx = opaque;
182
+    CuvidContext *ctx = avctx->priv_data;
183
+
184
+    av_log(avctx, AV_LOG_TRACE, "pfnDecodePicture\n");
185
+
186
+    ctx->internal_error = CHECK_CU(cuvidDecodePicture(ctx->cudecoder, picparams));
187
+    if (ctx->internal_error < 0)
188
+        return 0;
189
+
190
+    return 1;
191
+}
192
+
193
+static int CUDAAPI cuvid_handle_picture_display(void *opaque, CUVIDPARSERDISPINFO* dispinfo)
194
+{
195
+    AVCodecContext *avctx = opaque;
196
+    CuvidContext *ctx = avctx->priv_data;
197
+
198
+    av_log(avctx, AV_LOG_TRACE, "pfnDisplayPicture\n");
199
+
200
+    ctx->internal_error = 0;
201
+
202
+    av_fifo_generic_write(ctx->frame_queue, dispinfo, sizeof(CUVIDPARSERDISPINFO), NULL);
203
+
204
+    return 1;
205
+}
206
+
207
+static int cuvid_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
208
+{
209
+    CuvidContext *ctx = avctx->priv_data;
210
+    AVHWDeviceContext *device_ctx = (AVHWDeviceContext*)ctx->hwdevice->data;
211
+    AVCUDADeviceContext *device_hwctx = device_ctx->hwctx;
212
+    CUcontext dummy, cuda_ctx = device_hwctx->cuda_ctx;
213
+    AVFrame *frame = data;
214
+    CUVIDSOURCEDATAPACKET cupkt;
215
+    AVPacket filter_packet = { 0 };
216
+    AVPacket filtered_packet = { 0 };
217
+    CUdeviceptr mapped_frame = 0;
218
+    int ret = 0, eret = 0;
219
+
220
+    if (ctx->bsf && avpkt->size) {
221
+        if ((ret = av_packet_ref(&filter_packet, avpkt)) < 0) {
222
+            av_log(avctx, AV_LOG_ERROR, "av_packet_ref failed\n");
223
+            return ret;
224
+        }
225
+
226
+        if ((ret = av_bsf_send_packet(ctx->bsf, &filter_packet)) < 0) {
227
+            av_log(avctx, AV_LOG_ERROR, "av_bsf_send_packet failed\n");
228
+            av_packet_unref(&filter_packet);
229
+            return ret;
230
+        }
231
+
232
+        if ((ret = av_bsf_receive_packet(ctx->bsf, &filtered_packet)) < 0) {
233
+            av_log(avctx, AV_LOG_ERROR, "av_bsf_receive_packet failed\n");
234
+            return ret;
235
+        }
236
+
237
+        avpkt = &filtered_packet;
238
+    }
239
+
240
+    ret = CHECK_CU(cuCtxPushCurrent(cuda_ctx));
241
+    if (ret < 0) {
242
+        av_packet_unref(&filtered_packet);
243
+        return ret;
244
+    }
245
+
246
+    memset(&cupkt, 0, sizeof(cupkt));
247
+
248
+    if (avpkt->size) {
249
+        cupkt.payload_size = avpkt->size;
250
+        cupkt.payload = avpkt->data;
251
+
252
+        if (avpkt->pts != AV_NOPTS_VALUE) {
253
+            cupkt.flags = CUVID_PKT_TIMESTAMP;
254
+            cupkt.timestamp = av_rescale_q(avpkt->pts, avctx->time_base, (AVRational){1, 10000000});
255
+        }
256
+    } else {
257
+        cupkt.flags = CUVID_PKT_ENDOFSTREAM;
258
+    }
259
+
260
+    ret = CHECK_CU(cuvidParseVideoData(ctx->cuparser, &cupkt));
261
+
262
+    av_packet_unref(&filtered_packet);
263
+
264
+    if (ret < 0) {
265
+        if (ctx->internal_error)
266
+            ret = ctx->internal_error;
267
+        goto error;
268
+    }
269
+
270
+    if (av_fifo_size(ctx->frame_queue)) {
271
+        CUVIDPARSERDISPINFO dispinfo;
272
+        CUVIDPROCPARAMS params;
273
+        unsigned int pitch = 0;
274
+        int offset = 0;
275
+        int i;
276
+
277
+        av_fifo_generic_read(ctx->frame_queue, &dispinfo, sizeof(CUVIDPARSERDISPINFO), NULL);
278
+
279
+        memset(&params, 0, sizeof(params));
280
+        params.progressive_frame = dispinfo.progressive_frame;
281
+        params.second_field = 0;
282
+        params.top_field_first = dispinfo.top_field_first;
283
+
284
+        ret = CHECK_CU(cuvidMapVideoFrame(ctx->cudecoder, dispinfo.picture_index, &mapped_frame, &pitch, &params));
285
+        if (ret < 0)
286
+            goto error;
287
+
288
+        if (avctx->pix_fmt == AV_PIX_FMT_CUDA) {
289
+            ret = av_hwframe_get_buffer(ctx->hwframe, frame, 0);
290
+            if (ret < 0) {
291
+                av_log(avctx, AV_LOG_ERROR, "av_hwframe_get_buffer failed\n");
292
+                goto error;
293
+            }
294
+
295
+            ret = ff_decode_frame_props(avctx, frame);
296
+            if (ret < 0) {
297
+                av_log(avctx, AV_LOG_ERROR, "ff_decode_frame_props failed\n");
298
+                goto error;
299
+            }
300
+
301
+            for (i = 0; i < 2; i++) {
302
+                CUDA_MEMCPY2D cpy = {
303
+                    .srcMemoryType = CU_MEMORYTYPE_DEVICE,
304
+                    .dstMemoryType = CU_MEMORYTYPE_DEVICE,
305
+                    .srcDevice     = mapped_frame,
306
+                    .dstDevice     = (CUdeviceptr)frame->data[i],
307
+                    .srcPitch      = pitch,
308
+                    .dstPitch      = frame->linesize[i],
309
+                    .srcY          = offset,
310
+                    .WidthInBytes  = FFMIN(pitch, frame->linesize[i]),
311
+                    .Height        = avctx->coded_height >> (i ? 1 : 0),
312
+                };
313
+
314
+                ret = CHECK_CU(cuMemcpy2D(&cpy));
315
+                if (ret < 0)
316
+                    goto error;
317
+
318
+                offset += avctx->coded_height;
319
+            }
320
+        } else if (avctx->pix_fmt == AV_PIX_FMT_NV12) {
321
+            AVFrame *tmp_frame = av_frame_alloc();
322
+            if (!tmp_frame) {
323
+                av_log(avctx, AV_LOG_ERROR, "av_frame_alloc failed\n");
324
+                ret = AVERROR(ENOMEM);
325
+                goto error;
326
+            }
327
+
328
+            tmp_frame->format        = AV_PIX_FMT_CUDA;
329
+            tmp_frame->hw_frames_ctx = av_buffer_ref(ctx->hwframe);
330
+            tmp_frame->data[0]       = (uint8_t*)mapped_frame;
331
+            tmp_frame->linesize[0]   = pitch;
332
+            tmp_frame->data[1]       = (uint8_t*)(mapped_frame + avctx->coded_height * pitch);
333
+            tmp_frame->linesize[1]   = pitch;
334
+            tmp_frame->width         = avctx->width;
335
+            tmp_frame->height        = avctx->height;
336
+
337
+            ret = ff_get_buffer(avctx, frame, 0);
338
+            if (ret < 0) {
339
+                av_log(avctx, AV_LOG_ERROR, "ff_get_buffer failed\n");
340
+                av_frame_free(&tmp_frame);
341
+                goto error;
342
+            }
343
+
344
+            ret = av_hwframe_transfer_data(frame, tmp_frame, 0);
345
+            if (ret) {
346
+                av_log(avctx, AV_LOG_ERROR, "av_hwframe_transfer_data failed\n");
347
+                av_frame_free(&tmp_frame);
348
+                goto error;
349
+            }
350
+
351
+            av_frame_free(&tmp_frame);
352
+        } else {
353
+            ret = AVERROR_BUG;
354
+            goto error;
355
+        }
356
+
357
+        frame->width = avctx->width;
358
+        frame->height = avctx->height;
359
+        frame->pts = av_rescale_q(dispinfo.timestamp, (AVRational){1, 10000000}, avctx->time_base);
360
+
361
+        /* CUVIDs opaque reordering breaks the internal pkt logic.
362
+         * So set pkt_pts and clear all the other pkt_ fields.
363
+         */
364
+        frame->pkt_pts = frame->pts;
365
+        av_frame_set_pkt_pos(frame, -1);
366
+        av_frame_set_pkt_duration(frame, 0);
367
+        av_frame_set_pkt_size(frame, -1);
368
+
369
+        frame->interlaced_frame = !dispinfo.progressive_frame;
370
+
371
+        if (!dispinfo.progressive_frame)
372
+            frame->top_field_first = dispinfo.top_field_first;
373
+
374
+        *got_frame = 1;
375
+    } else {
376
+        *got_frame = 0;
377
+    }
378
+
379
+error:
380
+    if (mapped_frame)
381
+        eret = CHECK_CU(cuvidUnmapVideoFrame(ctx->cudecoder, mapped_frame));
382
+
383
+    eret = CHECK_CU(cuCtxPopCurrent(&dummy));
384
+
385
+    if (eret < 0)
386
+        return eret;
387
+    else
388
+        return ret;
389
+}
390
+
391
+static av_cold int cuvid_decode_end(AVCodecContext *avctx)
392
+{
393
+    CuvidContext *ctx = avctx->priv_data;
394
+
395
+    av_fifo_freep(&ctx->frame_queue);
396
+
397
+    if (ctx->bsf)
398
+        av_bsf_free(&ctx->bsf);
399
+
400
+    if (ctx->cuparser)
401
+        cuvidDestroyVideoParser(ctx->cuparser);
402
+
403
+    if (ctx->cudecoder)
404
+        cuvidDestroyDecoder(ctx->cudecoder);
405
+
406
+    av_buffer_unref(&ctx->hwframe);
407
+    av_buffer_unref(&ctx->hwdevice);
408
+
409
+    return 0;
410
+}
411
+
412
+static void cuvid_ctx_free(AVHWDeviceContext *ctx)
413
+{
414
+    AVCUDADeviceContext *hwctx = ctx->hwctx;
415
+    cuCtxDestroy(hwctx->cuda_ctx);
416
+}
417
+
418
+static int cuvid_test_dummy_decoder(AVCodecContext *avctx, CUVIDPARSERPARAMS *cuparseinfo)
419
+{
420
+    CUVIDDECODECREATEINFO cuinfo;
421
+    CUvideodecoder cudec = 0;
422
+    int ret = 0;
423
+
424
+    memset(&cuinfo, 0, sizeof(cuinfo));
425
+
426
+    cuinfo.CodecType = cuparseinfo->CodecType;
427
+    cuinfo.ChromaFormat = cudaVideoChromaFormat_420;
428
+    cuinfo.OutputFormat = cudaVideoSurfaceFormat_NV12;
429
+
430
+    cuinfo.ulWidth = 1280;
431
+    cuinfo.ulHeight = 720;
432
+    cuinfo.ulTargetWidth = cuinfo.ulWidth;
433
+    cuinfo.ulTargetHeight = cuinfo.ulHeight;
434
+
435
+    cuinfo.target_rect.left = 0;
436
+    cuinfo.target_rect.top = 0;
437
+    cuinfo.target_rect.right = cuinfo.ulWidth;
438
+    cuinfo.target_rect.bottom = cuinfo.ulHeight;
439
+
440
+    cuinfo.ulNumDecodeSurfaces = MAX_FRAME_COUNT;
441
+    cuinfo.ulNumOutputSurfaces = 1;
442
+    cuinfo.ulCreationFlags = cudaVideoCreate_PreferCUVID;
443
+
444
+    cuinfo.DeinterlaceMode = cudaVideoDeinterlaceMode_Weave;
445
+
446
+    ret = CHECK_CU(cuvidCreateDecoder(&cudec, &cuinfo));
447
+    if (ret < 0)
448
+        return ret;
449
+
450
+    ret = CHECK_CU(cuvidDestroyDecoder(cudec));
451
+    if (ret < 0)
452
+        return ret;
453
+
454
+    return 0;
455
+}
456
+
457
+static av_cold int cuvid_decode_init(AVCodecContext *avctx)
458
+{
459
+    CuvidContext *ctx = avctx->priv_data;
460
+    AVCUDADeviceContext *device_hwctx;
461
+    AVHWDeviceContext *device_ctx;
462
+    AVHWFramesContext *hwframe_ctx;
463
+    CUVIDPARSERPARAMS cuparseinfo;
464
+    CUVIDEOFORMATEX cuparse_ext;
465
+    CUVIDSOURCEDATAPACKET seq_pkt;
466
+    CUdevice device;
467
+    CUcontext cuda_ctx = NULL;
468
+    CUcontext dummy;
469
+    const AVBitStreamFilter *bsf;
470
+    int ret = 0;
471
+
472
+    enum AVPixelFormat pix_fmts[3] = { AV_PIX_FMT_CUDA,
473
+                                       AV_PIX_FMT_NV12,
474
+                                       AV_PIX_FMT_NONE };
475
+
476
+    ret = ff_get_format(avctx, pix_fmts);
477
+    if (ret < 0) {
478
+        av_log(avctx, AV_LOG_ERROR, "ff_get_format failed: %d\n", ret);
479
+        return ret;
480
+    }
481
+
482
+    ctx->frame_queue = av_fifo_alloc(MAX_FRAME_COUNT * sizeof(CUVIDPARSERDISPINFO));
483
+    if (!ctx->frame_queue) {
484
+        ret = AVERROR(ENOMEM);
485
+        goto error;
486
+    }
487
+
488
+    avctx->pix_fmt = ret;
489
+
490
+    if (avctx->hw_frames_ctx) {
491
+        ctx->hwframe = av_buffer_ref(avctx->hw_frames_ctx);
492
+        if (!ctx->hwframe) {
493
+            ret = AVERROR(ENOMEM);
494
+            goto error;
495
+        }
496
+
497
+        hwframe_ctx = (AVHWFramesContext*)ctx->hwframe->data;
498
+
499
+        ctx->hwdevice = av_buffer_ref(hwframe_ctx->device_ref);
500
+        if (!ctx->hwdevice) {
501
+            ret = AVERROR(ENOMEM);
502
+            goto error;
503
+        }
504
+
505
+        device_ctx = hwframe_ctx->device_ctx;
506
+        device_hwctx = device_ctx->hwctx;
507
+        cuda_ctx = device_hwctx->cuda_ctx;
508
+    } else {
509
+        ctx->hwdevice = av_hwdevice_ctx_alloc(AV_HWDEVICE_TYPE_CUDA);
510
+        if (!ctx->hwdevice) {
511
+            av_log(avctx, AV_LOG_ERROR, "Error allocating hwdevice\n");
512
+            ret = AVERROR(ENOMEM);
513
+            goto error;
514
+        }
515
+
516
+        ret = CHECK_CU(cuInit(0));
517
+        if (ret < 0)
518
+            goto error;
519
+
520
+        ret = CHECK_CU(cuDeviceGet(&device, 0));
521
+        if (ret < 0)
522
+            goto error;
523
+
524
+        ret = CHECK_CU(cuCtxCreate(&cuda_ctx, CU_CTX_SCHED_BLOCKING_SYNC, device));
525
+        if (ret < 0)
526
+            goto error;
527
+
528
+        device_ctx = (AVHWDeviceContext*)ctx->hwdevice->data;
529
+        device_ctx->free = cuvid_ctx_free;
530
+
531
+        device_hwctx = device_ctx->hwctx;
532
+        device_hwctx->cuda_ctx = cuda_ctx;
533
+
534
+        ret = CHECK_CU(cuCtxPopCurrent(&dummy));
535
+        if (ret < 0)
536
+            goto error;
537
+
538
+        ret = av_hwdevice_ctx_init(ctx->hwdevice);
539
+        if (ret < 0) {
540
+            av_log(avctx, AV_LOG_ERROR, "av_hwdevice_ctx_init failed\n");
541
+            goto error;
542
+        }
543
+
544
+        ctx->hwframe = av_hwframe_ctx_alloc(ctx->hwdevice);
545
+        if (!ctx->hwframe) {
546
+            av_log(avctx, AV_LOG_ERROR, "av_hwframe_ctx_alloc failed\n");
547
+            ret = AVERROR(ENOMEM);
548
+            goto error;
549
+        }
550
+    }
551
+
552
+    memset(&cuparseinfo, 0, sizeof(cuparseinfo));
553
+    memset(&cuparse_ext, 0, sizeof(cuparse_ext));
554
+    memset(&seq_pkt, 0, sizeof(seq_pkt));
555
+
556
+    cuparseinfo.pExtVideoInfo = &cuparse_ext;
557
+
558
+    switch (avctx->codec->id) {
559
+#if CONFIG_H264_CUVID_DECODER
560
+    case AV_CODEC_ID_H264:
561
+        cuparseinfo.CodecType = cudaVideoCodec_H264;
562
+        break;
563
+#endif
564
+#if CONFIG_HEVC_CUVID_DECODER
565
+    case AV_CODEC_ID_HEVC:
566
+        cuparseinfo.CodecType = cudaVideoCodec_HEVC;
567
+        break;
568
+#endif
569
+#if CONFIG_VP8_CUVID_DECODER
570
+    case AV_CODEC_ID_VP8:
571
+        cuparseinfo.CodecType = cudaVideoCodec_VP8;
572
+        break;
573
+#endif
574
+#if CONFIG_VP9_CUVID_DECODER
575
+    case AV_CODEC_ID_VP9:
576
+        cuparseinfo.CodecType = cudaVideoCodec_VP9;
577
+        break;
578
+#endif
579
+#if CONFIG_VC1_CUVID_DECODER
580
+    case AV_CODEC_ID_VC1:
581
+        cuparseinfo.CodecType = cudaVideoCodec_VC1;
582
+        break;
583
+#endif
584
+    default:
585
+        av_log(avctx, AV_LOG_ERROR, "Invalid CUVID codec!\n");
586
+        return AVERROR_BUG;
587
+    }
588
+
589
+    if (avctx->codec->id == AV_CODEC_ID_H264 || avctx->codec->id == AV_CODEC_ID_HEVC) {
590
+        if (avctx->codec->id == AV_CODEC_ID_H264)
591
+            bsf = av_bsf_get_by_name("h264_mp4toannexb");
592
+        else
593
+            bsf = av_bsf_get_by_name("hevc_mp4toannexb");
594
+
595
+        if (!bsf) {
596
+            ret = AVERROR_BSF_NOT_FOUND;
597
+            goto error;
598
+        }
599
+        if (ret = av_bsf_alloc(bsf, &ctx->bsf)) {
600
+            goto error;
601
+        }
602
+        if (((ret = avcodec_parameters_from_context(ctx->bsf->par_in, avctx)) < 0) || ((ret = av_bsf_init(ctx->bsf)) < 0)) {
603
+            av_bsf_free(&ctx->bsf);
604
+            goto error;
605
+        }
606
+
607
+        cuparse_ext.format.seqhdr_data_length = ctx->bsf->par_out->extradata_size;
608
+        memcpy(cuparse_ext.raw_seqhdr_data,
609
+               ctx->bsf->par_out->extradata,
610
+               FFMIN(sizeof(cuparse_ext.raw_seqhdr_data), ctx->bsf->par_out->extradata_size));
611
+    } else if (avctx->extradata_size > 0) {
612
+        cuparse_ext.format.seqhdr_data_length = avctx->extradata_size;
613
+        memcpy(cuparse_ext.raw_seqhdr_data,
614
+               avctx->extradata,
615
+               FFMIN(sizeof(cuparse_ext.raw_seqhdr_data), avctx->extradata_size));
616
+    }
617
+
618
+    cuparseinfo.ulMaxNumDecodeSurfaces = MAX_FRAME_COUNT;
619
+    cuparseinfo.ulMaxDisplayDelay = 4;
620
+    cuparseinfo.pUserData = avctx;
621
+    cuparseinfo.pfnSequenceCallback = cuvid_handle_video_sequence;
622
+    cuparseinfo.pfnDecodePicture = cuvid_handle_picture_decode;
623
+    cuparseinfo.pfnDisplayPicture = cuvid_handle_picture_display;
624
+
625
+    ret = CHECK_CU(cuCtxPushCurrent(cuda_ctx));
626
+    if (ret < 0)
627
+        goto error;
628
+
629
+    ret = cuvid_test_dummy_decoder(avctx, &cuparseinfo);
630
+    if (ret < 0)
631
+        goto error;
632
+
633
+    ret = CHECK_CU(cuvidCreateVideoParser(&ctx->cuparser, &cuparseinfo));
634
+    if (ret < 0)
635
+        goto error;
636
+
637
+    seq_pkt.payload = cuparse_ext.raw_seqhdr_data;
638
+    seq_pkt.payload_size = cuparse_ext.format.seqhdr_data_length;
639
+
640
+    if (seq_pkt.payload && seq_pkt.payload_size) {
641
+        ret = CHECK_CU(cuvidParseVideoData(ctx->cuparser, &seq_pkt));
642
+        if (ret < 0)
643
+            goto error;
644
+    }
645
+
646
+    ret = CHECK_CU(cuCtxPopCurrent(&dummy));
647
+    if (ret < 0)
648
+        goto error;
649
+
650
+    return 0;
651
+
652
+error:
653
+    cuvid_decode_end(avctx);
654
+    return ret;
655
+}
656
+
657
+#define DEFINE_CUVID_CODEC(x, X) \
658
+    AVHWAccel ff_##x##_cuvid_hwaccel = { \
659
+        .name           = #x "_cuvid", \
660
+        .type           = AVMEDIA_TYPE_VIDEO, \
661
+        .id             = AV_CODEC_ID_##X, \
662
+        .pix_fmt        = AV_PIX_FMT_CUDA, \
663
+    }; \
664
+    AVCodec ff_##x##_cuvid_decoder = { \
665
+        .name           = #x "_cuvid", \
666
+        .long_name      = NULL_IF_CONFIG_SMALL("Nvidia CUVID " #X " decoder"), \
667
+        .type           = AVMEDIA_TYPE_VIDEO, \
668
+        .id             = AV_CODEC_ID_##X, \
669
+        .priv_data_size = sizeof(CuvidContext), \
670
+        .init           = cuvid_decode_init, \
671
+        .close          = cuvid_decode_end, \
672
+        .decode         = cuvid_decode_frame, \
673
+        .capabilities   = AV_CODEC_CAP_DELAY, \
674
+        .pix_fmts       = (const enum AVPixelFormat[]){ AV_PIX_FMT_CUDA, \
675
+                                                        AV_PIX_FMT_NV12, \
676
+                                                        AV_PIX_FMT_NONE }, \
677
+    };
678
+
679
+#if CONFIG_HEVC_CUVID_DECODER
680
+DEFINE_CUVID_CODEC(hevc, HEVC)
681
+#endif
682
+
683
+#if CONFIG_H264_CUVID_DECODER
684
+DEFINE_CUVID_CODEC(h264, H264)
685
+#endif
686
+
687
+#if CONFIG_VP8_CUVID_DECODER
688
+DEFINE_CUVID_CODEC(vp8, VP8)
689
+#endif
690
+
691
+#if CONFIG_VP9_CUVID_DECODER
692
+DEFINE_CUVID_CODEC(vp9, VP9)
693
+#endif
694
+
695
+#if CONFIG_VC1_CUVID_DECODER
696
+DEFINE_CUVID_CODEC(vc1, VC1)
697
+#endif
... ...
@@ -28,7 +28,7 @@
28 28
 #include "libavutil/version.h"
29 29
 
30 30
 #define LIBAVCODEC_VERSION_MAJOR  57
31
-#define LIBAVCODEC_VERSION_MINOR  45
31
+#define LIBAVCODEC_VERSION_MINOR  46
32 32
 #define LIBAVCODEC_VERSION_MICRO 100
33 33
 
34 34
 #define LIBAVCODEC_VERSION_INT  AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \