Added
Link Here
|
1 |
commit 1054752c563cbe978f16010ed57dfa23a41ee490 |
2 |
Author: ManojGuptaBonda <mbonda@nvidia.com> |
3 |
Date: Fri Oct 25 11:00:13 2019 +0530 |
4 |
|
5 |
Add support for VP9 VDPAU hwaccel decode |
6 |
|
7 |
Support for VDPAU accelerated VP9 decoding was added with libvdpau-1.3. |
8 |
Support for the same in ffmpeg is added with this patch. Profiles |
9 |
related to VDPAU VP9 can be found in latest vdpau.h present in |
10 |
libvdpau-1.3. DRC clips are not supported yet due to |
11 |
http://trac.ffmpeg.org/ticket/8068 |
12 |
|
13 |
Add VP9 VDPAU to list of hwaccels and supported formats |
14 |
Added file vdpau_vp9.c and Modified configure to add VDPAU VP9 support. |
15 |
Mapped VP9 profiles to VDPAU VP9 profiles. Populated the codec specific |
16 |
params that need to be passed to VDPAU. |
17 |
|
18 |
Signed-off-by: Philip Langdale <philipl@overt.org> |
19 |
|
20 |
--- configure.orig 2019-12-18 11:42:25 UTC |
21 |
+++ configure |
22 |
@@ -2976,6 +2976,8 @@ vp9_nvdec_hwaccel_deps="nvdec" |
23 |
vp9_nvdec_hwaccel_select="vp9_decoder" |
24 |
vp9_vaapi_hwaccel_deps="vaapi VADecPictureParameterBufferVP9_bit_depth" |
25 |
vp9_vaapi_hwaccel_select="vp9_decoder" |
26 |
+vp9_vdpau_hwaccel_deps="vdpau VdpPictureInfoVP9" |
27 |
+vp9_vdpau_hwaccel_select="vp9_decoder" |
28 |
wmv3_d3d11va_hwaccel_select="vc1_d3d11va_hwaccel" |
29 |
wmv3_d3d11va2_hwaccel_select="vc1_d3d11va2_hwaccel" |
30 |
wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel" |
31 |
@@ -6083,6 +6085,7 @@ check_type "windows.h d3d11.h" "ID3D11VideoContext" |
32 |
check_type "d3d9.h dxva2api.h" DXVA2_ConfigPictureDecode -D_WIN32_WINNT=0x0602 |
33 |
|
34 |
check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC" |
35 |
+check_type "vdpau/vdpau.h" "VdpPictureInfoVP9" |
36 |
|
37 |
if [ -z "$nvccflags" ]; then |
38 |
nvccflags=$nvccflags_default |
39 |
--- libavcodec/Makefile.orig 2019-12-18 11:42:25 UTC |
40 |
+++ libavcodec/Makefile |
41 |
@@ -910,6 +910,7 @@ OBJS-$(CONFIG_VP9_D3D11VA_HWACCEL) += dxva2_vp9 |
42 |
OBJS-$(CONFIG_VP9_DXVA2_HWACCEL) += dxva2_vp9.o |
43 |
OBJS-$(CONFIG_VP9_NVDEC_HWACCEL) += nvdec_vp9.o |
44 |
OBJS-$(CONFIG_VP9_VAAPI_HWACCEL) += vaapi_vp9.o |
45 |
+OBJS-$(CONFIG_VP9_VDPAU_HWACCEL) += vdpau_vp9.o |
46 |
OBJS-$(CONFIG_VP8_QSV_HWACCEL) += qsvdec_other.o |
47 |
|
48 |
# libavformat dependencies |
49 |
--- libavcodec/hwaccels.h.orig 2019-07-08 17:45:25 UTC |
50 |
+++ libavcodec/hwaccels.h |
51 |
@@ -68,6 +68,7 @@ extern const AVHWAccel ff_vp9_d3d11va2_hwaccel; |
52 |
extern const AVHWAccel ff_vp9_dxva2_hwaccel; |
53 |
extern const AVHWAccel ff_vp9_nvdec_hwaccel; |
54 |
extern const AVHWAccel ff_vp9_vaapi_hwaccel; |
55 |
+extern const AVHWAccel ff_vp9_vdpau_hwaccel; |
56 |
extern const AVHWAccel ff_wmv3_d3d11va_hwaccel; |
57 |
extern const AVHWAccel ff_wmv3_d3d11va2_hwaccel; |
58 |
extern const AVHWAccel ff_wmv3_dxva2_hwaccel; |
59 |
--- libavcodec/vdpau_internal.h.orig 2019-08-05 20:52:21 UTC |
60 |
+++ libavcodec/vdpau_internal.h |
61 |
@@ -54,6 +54,9 @@ union VDPAUPictureInfo { |
62 |
#ifdef VDP_YCBCR_FORMAT_Y_U_V_444 |
63 |
VdpPictureInfoHEVC444 hevc_444; |
64 |
#endif |
65 |
+#ifdef VDP_DECODER_PROFILE_VP9_PROFILE_0 |
66 |
+ VdpPictureInfoVP9 vp9; |
67 |
+#endif |
68 |
}; |
69 |
|
70 |
typedef struct VDPAUHWContext { |
71 |
--- libavcodec/vdpau_vp9.c.orig 2019-12-18 11:42:25 UTC |
72 |
+++ libavcodec/vdpau_vp9.c |
73 |
@@ -0,0 +1,242 @@ |
74 |
+/* |
75 |
+ * VP9 HW decode acceleration through VDPAU |
76 |
+ * |
77 |
+ * Copyright (c) 2019 Manoj Gupta Bonda |
78 |
+ * |
79 |
+ * This file is part of FFmpeg. |
80 |
+ * |
81 |
+ * FFmpeg is free software; you can redistribute it and/or |
82 |
+ * modify it under the terms of the GNU Lesser General Public |
83 |
+ * License as published by the Free Software Foundation; either |
84 |
+ * version 2.1 of the License, or (at your option) any later version. |
85 |
+ * |
86 |
+ * FFmpeg is distributed in the hope that it will be useful, |
87 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
88 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
89 |
+ * Lesser General Public License for more details. |
90 |
+ * |
91 |
+ * You should have received a copy of the GNU Lesser General Public |
92 |
+ * License along with FFmpeg; if not, write to the Free Software Foundation, |
93 |
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
94 |
+ */ |
95 |
+ |
96 |
+#include <vdpau/vdpau.h> |
97 |
+#include "libavutil/pixdesc.h" |
98 |
+#include "avcodec.h" |
99 |
+#include "internal.h" |
100 |
+#include "vp9data.h" |
101 |
+#include "vp9dec.h" |
102 |
+#include "hwaccel.h" |
103 |
+#include "vdpau.h" |
104 |
+#include "vdpau_internal.h" |
105 |
+ |
106 |
+static int vdpau_vp9_start_frame(AVCodecContext *avctx, |
107 |
+ const uint8_t *buffer, uint32_t size) |
108 |
+{ |
109 |
+ VP9Context *s = avctx->priv_data; |
110 |
+ VP9SharedContext *h = &(s->s); |
111 |
+ const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->sw_pix_fmt); |
112 |
+ if (!pixdesc) { |
113 |
+ return AV_PIX_FMT_NONE; |
114 |
+ } |
115 |
+ |
116 |
+ VP9Frame pic = h->frames[CUR_FRAME]; |
117 |
+ struct vdpau_picture_context *pic_ctx = pic.hwaccel_picture_private; |
118 |
+ int i; |
119 |
+ |
120 |
+ VdpPictureInfoVP9 *info = &pic_ctx->info.vp9; |
121 |
+ |
122 |
+ info->width = avctx->width; |
123 |
+ info->height = avctx->height; |
124 |
+ /* fill LvPictureInfoVP9 struct */ |
125 |
+ info->lastReference = VDP_INVALID_HANDLE; |
126 |
+ info->goldenReference = VDP_INVALID_HANDLE; |
127 |
+ info->altReference = VDP_INVALID_HANDLE; |
128 |
+ |
129 |
+ if (h->refs[h->h.refidx[0]].f && h->refs[h->h.refidx[0]].f->private_ref) { |
130 |
+ info->lastReference = ff_vdpau_get_surface_id(h->refs[h->h.refidx[0]].f); |
131 |
+ } |
132 |
+ if (h->refs[h->h.refidx[1]].f && h->refs[h->h.refidx[1]].f->private_ref) { |
133 |
+ info->goldenReference = ff_vdpau_get_surface_id(h->refs[h->h.refidx[1]].f); |
134 |
+ } |
135 |
+ if (h->refs[h->h.refidx[2]].f && h->refs[h->h.refidx[2]].f->private_ref) { |
136 |
+ info->altReference = ff_vdpau_get_surface_id(h->refs[h->h.refidx[2]].f); |
137 |
+ } |
138 |
+ |
139 |
+ info->profile = h->h.profile; |
140 |
+ info->frameContextIdx = h->h.framectxid; |
141 |
+ info->keyFrame = h->h.keyframe; |
142 |
+ info->showFrame = !h->h.invisible; |
143 |
+ info->errorResilient = h->h.errorres; |
144 |
+ info->frameParallelDecoding = h->h.parallelmode; |
145 |
+ |
146 |
+ info->subSamplingX = pixdesc->log2_chroma_w; |
147 |
+ info->subSamplingY = pixdesc->log2_chroma_h; |
148 |
+ |
149 |
+ info->intraOnly = h->h.intraonly; |
150 |
+ info->allowHighPrecisionMv = h->h.keyframe ? 0 : h->h.highprecisionmvs; |
151 |
+ info->refreshEntropyProbs = h->h.refreshctx; |
152 |
+ |
153 |
+ info->bitDepthMinus8Luma = pixdesc->comp[0].depth - 8; |
154 |
+ info->bitDepthMinus8Chroma = pixdesc->comp[1].depth - 8; |
155 |
+ |
156 |
+ info->loopFilterLevel = h->h.filter.level; |
157 |
+ info->loopFilterSharpness = h->h.filter.sharpness; |
158 |
+ info->modeRefLfEnabled = h->h.lf_delta.enabled; |
159 |
+ |
160 |
+ info->log2TileColumns = h->h.tiling.log2_tile_cols; |
161 |
+ info->log2TileRows = h->h.tiling.log2_tile_rows; |
162 |
+ |
163 |
+ info->segmentEnabled = h->h.segmentation.enabled; |
164 |
+ info->segmentMapUpdate = h->h.segmentation.update_map; |
165 |
+ info->segmentMapTemporalUpdate = h->h.segmentation.temporal; |
166 |
+ info->segmentFeatureMode = h->h.segmentation.absolute_vals; |
167 |
+ |
168 |
+ info->qpYAc = h->h.yac_qi; |
169 |
+ info->qpYDc = h->h.ydc_qdelta; |
170 |
+ info->qpChDc = h->h.uvdc_qdelta; |
171 |
+ info->qpChAc = h->h.uvac_qdelta; |
172 |
+ |
173 |
+ info->resetFrameContext = h->h.resetctx; |
174 |
+ info->mcompFilterType = h->h.filtermode ^ (h->h.filtermode <= 1); |
175 |
+ info->uncompressedHeaderSize = h->h.uncompressed_header_size; |
176 |
+ info->compressedHeaderSize = h->h.compressed_header_size; |
177 |
+ info->refFrameSignBias[0] = 0; |
178 |
+ |
179 |
+ |
180 |
+ for (i = 0; i < FF_ARRAY_ELEMS(info->mbModeLfDelta); i++) |
181 |
+ info->mbModeLfDelta[i] = h->h.lf_delta.mode[i]; |
182 |
+ |
183 |
+ for (i = 0; i < FF_ARRAY_ELEMS(info->mbRefLfDelta); i++) |
184 |
+ info->mbRefLfDelta[i] = h->h.lf_delta.ref[i]; |
185 |
+ |
186 |
+ for (i = 0; i < FF_ARRAY_ELEMS(info->mbSegmentTreeProbs); i++) |
187 |
+ info->mbSegmentTreeProbs[i] = h->h.segmentation.prob[i]; |
188 |
+ |
189 |
+ for (i = 0; i < FF_ARRAY_ELEMS(info->activeRefIdx); i++) { |
190 |
+ info->activeRefIdx[i] = h->h.refidx[i]; |
191 |
+ info->segmentPredProbs[i] = h->h.segmentation.pred_prob[i]; |
192 |
+ info->refFrameSignBias[i + 1] = h->h.signbias[i]; |
193 |
+ } |
194 |
+ |
195 |
+ for (i = 0; i < FF_ARRAY_ELEMS(info->segmentFeatureEnable); i++) { |
196 |
+ info->segmentFeatureEnable[i][0] = h->h.segmentation.feat[i].q_enabled; |
197 |
+ info->segmentFeatureEnable[i][1] = h->h.segmentation.feat[i].lf_enabled; |
198 |
+ info->segmentFeatureEnable[i][2] = h->h.segmentation.feat[i].ref_enabled; |
199 |
+ info->segmentFeatureEnable[i][3] = h->h.segmentation.feat[i].skip_enabled; |
200 |
+ |
201 |
+ info->segmentFeatureData[i][0] = h->h.segmentation.feat[i].q_val; |
202 |
+ info->segmentFeatureData[i][1] = h->h.segmentation.feat[i].lf_val; |
203 |
+ info->segmentFeatureData[i][2] = h->h.segmentation.feat[i].ref_val; |
204 |
+ info->segmentFeatureData[i][3] = 0; |
205 |
+ } |
206 |
+ |
207 |
+ switch (avctx->colorspace) { |
208 |
+ default: |
209 |
+ case AVCOL_SPC_UNSPECIFIED: |
210 |
+ info->colorSpace = 0; |
211 |
+ break; |
212 |
+ case AVCOL_SPC_BT470BG: |
213 |
+ info->colorSpace = 1; |
214 |
+ break; |
215 |
+ case AVCOL_SPC_BT709: |
216 |
+ info->colorSpace = 2; |
217 |
+ break; |
218 |
+ case AVCOL_SPC_SMPTE170M: |
219 |
+ info->colorSpace = 3; |
220 |
+ break; |
221 |
+ case AVCOL_SPC_SMPTE240M: |
222 |
+ info->colorSpace = 4; |
223 |
+ break; |
224 |
+ case AVCOL_SPC_BT2020_NCL: |
225 |
+ info->colorSpace = 5; |
226 |
+ break; |
227 |
+ case AVCOL_SPC_RESERVED: |
228 |
+ info->colorSpace = 6; |
229 |
+ break; |
230 |
+ case AVCOL_SPC_RGB: |
231 |
+ info->colorSpace = 7; |
232 |
+ break; |
233 |
+ } |
234 |
+ |
235 |
+ return ff_vdpau_common_start_frame(pic_ctx, buffer, size); |
236 |
+ |
237 |
+} |
238 |
+ |
239 |
+static const uint8_t start_code_prefix[3] = { 0x00, 0x00, 0x01 }; |
240 |
+ |
241 |
+static int vdpau_vp9_decode_slice(AVCodecContext *avctx, |
242 |
+ const uint8_t *buffer, uint32_t size) |
243 |
+{ |
244 |
+ VP9SharedContext *h = avctx->priv_data; |
245 |
+ VP9Frame pic = h->frames[CUR_FRAME]; |
246 |
+ struct vdpau_picture_context *pic_ctx = pic.hwaccel_picture_private; |
247 |
+ |
248 |
+ int val; |
249 |
+ |
250 |
+ val = ff_vdpau_add_buffer(pic_ctx, start_code_prefix, 3); |
251 |
+ if (val) |
252 |
+ return val; |
253 |
+ |
254 |
+ val = ff_vdpau_add_buffer(pic_ctx, buffer, size); |
255 |
+ if (val) |
256 |
+ return val; |
257 |
+ |
258 |
+ return 0; |
259 |
+} |
260 |
+ |
261 |
+static int vdpau_vp9_end_frame(AVCodecContext *avctx) |
262 |
+{ |
263 |
+ VP9SharedContext *h = avctx->priv_data; |
264 |
+ VP9Frame pic = h->frames[CUR_FRAME]; |
265 |
+ struct vdpau_picture_context *pic_ctx = pic.hwaccel_picture_private; |
266 |
+ |
267 |
+ int val; |
268 |
+ |
269 |
+ val = ff_vdpau_common_end_frame(avctx, pic.tf.f, pic_ctx); |
270 |
+ if (val < 0) |
271 |
+ return val; |
272 |
+ |
273 |
+ return 0; |
274 |
+} |
275 |
+ |
276 |
+static int vdpau_vp9_init(AVCodecContext *avctx) |
277 |
+{ |
278 |
+ VdpDecoderProfile profile; |
279 |
+ uint32_t level = avctx->level; |
280 |
+ |
281 |
+ switch (avctx->profile) { |
282 |
+ case FF_PROFILE_VP9_0: |
283 |
+ profile = VDP_DECODER_PROFILE_VP9_PROFILE_0; |
284 |
+ break; |
285 |
+ case FF_PROFILE_VP9_1: |
286 |
+ profile = VDP_DECODER_PROFILE_VP9_PROFILE_1; |
287 |
+ break; |
288 |
+ case FF_PROFILE_VP9_2: |
289 |
+ profile = VDP_DECODER_PROFILE_VP9_PROFILE_2; |
290 |
+ break; |
291 |
+ case FF_PROFILE_VP9_3: |
292 |
+ profile = VDP_DECODER_PROFILE_VP9_PROFILE_3; |
293 |
+ break; |
294 |
+ default: |
295 |
+ return AVERROR(ENOTSUP); |
296 |
+ } |
297 |
+ |
298 |
+ return ff_vdpau_common_init(avctx, profile, level); |
299 |
+} |
300 |
+ |
301 |
+const AVHWAccel ff_vp9_vdpau_hwaccel = { |
302 |
+ .name = "vp9_vdpau", |
303 |
+ .type = AVMEDIA_TYPE_VIDEO, |
304 |
+ .id = AV_CODEC_ID_VP9, |
305 |
+ .pix_fmt = AV_PIX_FMT_VDPAU, |
306 |
+ .start_frame = vdpau_vp9_start_frame, |
307 |
+ .end_frame = vdpau_vp9_end_frame, |
308 |
+ .decode_slice = vdpau_vp9_decode_slice, |
309 |
+ .frame_priv_data_size = sizeof(struct vdpau_picture_context), |
310 |
+ .init = vdpau_vp9_init, |
311 |
+ .uninit = ff_vdpau_common_uninit, |
312 |
+ .frame_params = ff_vdpau_common_frame_params, |
313 |
+ .priv_data_size = sizeof(VDPAUContext), |
314 |
+ .caps_internal = HWACCEL_CAP_ASYNC_SAFE, |
315 |
+}; |
316 |
--- libavcodec/vp9.c.orig 2019-08-05 20:52:21 UTC |
317 |
+++ libavcodec/vp9.c |
318 |
@@ -173,7 +173,8 @@ static int update_size(AVCodecContext *avctx, int w, i |
319 |
#define HWACCEL_MAX (CONFIG_VP9_DXVA2_HWACCEL + \ |
320 |
CONFIG_VP9_D3D11VA_HWACCEL * 2 + \ |
321 |
CONFIG_VP9_NVDEC_HWACCEL + \ |
322 |
- CONFIG_VP9_VAAPI_HWACCEL) |
323 |
+ CONFIG_VP9_VAAPI_HWACCEL + \ |
324 |
+ CONFIG_VP9_VDPAU_HWACCEL) |
325 |
enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmtp = pix_fmts; |
326 |
VP9Context *s = avctx->priv_data; |
327 |
uint8_t *p; |
328 |
@@ -188,6 +189,9 @@ static int update_size(AVCodecContext *avctx, int w, i |
329 |
|
330 |
switch (s->pix_fmt) { |
331 |
case AV_PIX_FMT_YUV420P: |
332 |
+#if CONFIG_VP9_VDPAU_HWACCEL |
333 |
+ *fmtp++ = AV_PIX_FMT_VDPAU; |
334 |
+#endif |
335 |
case AV_PIX_FMT_YUV420P10: |
336 |
#if CONFIG_VP9_DXVA2_HWACCEL |
337 |
*fmtp++ = AV_PIX_FMT_DXVA2_VLD; |
338 |
@@ -1816,6 +1820,9 @@ AVCodec ff_vp9_decoder = { |
339 |
#endif |
340 |
#if CONFIG_VP9_VAAPI_HWACCEL |
341 |
HWACCEL_VAAPI(vp9), |
342 |
+#endif |
343 |
+#if CONFIG_VP9_VDPAU_HWACCEL |
344 |
+ HWACCEL_VDPAU(vp9), |
345 |
#endif |
346 |
NULL |
347 |
}, |