Signed-off-by: Timo Rothenpieler <timo@rothenpieler.org>
Timo Rothenpieler authored on 2015/12/20 04:31:00... | ... |
@@ -2577,6 +2577,8 @@ vp9_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_VP9" |
2577 | 2577 |
vp9_d3d11va_hwaccel_select="vp9_decoder" |
2578 | 2578 |
vp9_dxva2_hwaccel_deps="dxva2 DXVA_PicParams_VP9" |
2579 | 2579 |
vp9_dxva2_hwaccel_select="vp9_decoder" |
2580 |
+vp9_vaapi_hwaccel_deps="vaapi VADecPictureParameterBufferVP9" |
|
2581 |
+vp9_vaapi_hwaccel_select="vp9_decoder" |
|
2580 | 2582 |
wmv3_crystalhd_decoder_select="crystalhd" |
2581 | 2583 |
wmv3_d3d11va_hwaccel_select="vc1_d3d11va_hwaccel" |
2582 | 2584 |
wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel" |
... | ... |
@@ -5319,6 +5321,7 @@ check_type "windows.h d3d11.h" "ID3D11VideoContext" |
5319 | 5319 |
check_type "d3d9.h dxva2api.h" DXVA2_ConfigPictureDecode -D_WIN32_WINNT=0x0602 |
5320 | 5320 |
|
5321 | 5321 |
check_type "va/va.h" "VAPictureParameterBufferHEVC" |
5322 |
+check_type "va/va.h" "VADecPictureParameterBufferVP9" |
|
5322 | 5323 |
|
5323 | 5324 |
check_type "vdpau/vdpau.h" "VdpPictureInfoHEVC" |
5324 | 5325 |
|
... | ... |
@@ -751,6 +751,7 @@ OBJS-$(CONFIG_VC1_VAAPI_HWACCEL) += vaapi_vc1.o |
751 | 751 |
OBJS-$(CONFIG_VC1_VDPAU_HWACCEL) += vdpau_vc1.o |
752 | 752 |
OBJS-$(CONFIG_VP9_D3D11VA_HWACCEL) += dxva2_vp9.o |
753 | 753 |
OBJS-$(CONFIG_VP9_DXVA2_HWACCEL) += dxva2_vp9.o |
754 |
+OBJS-$(CONFIG_VP9_VAAPI_HWACCEL) += vaapi_vp9.o |
|
754 | 755 |
|
755 | 756 |
# libavformat dependencies |
756 | 757 |
OBJS-$(CONFIG_ADTS_MUXER) += mpeg4audio.o |
... | ... |
@@ -112,6 +112,7 @@ void avcodec_register_all(void) |
112 | 112 |
REGISTER_HWACCEL(VC1_QSV, vc1_qsv); |
113 | 113 |
REGISTER_HWACCEL(VP9_D3D11VA, vp9_d3d11va); |
114 | 114 |
REGISTER_HWACCEL(VP9_DXVA2, vp9_dxva2); |
115 |
+ REGISTER_HWACCEL(VP9_VAAPI, vp9_vaapi); |
|
115 | 116 |
REGISTER_HWACCEL(WMV3_D3D11VA, wmv3_d3d11va); |
116 | 117 |
REGISTER_HWACCEL(WMV3_DXVA2, wmv3_dxva2); |
117 | 118 |
REGISTER_HWACCEL(WMV3_VAAPI, wmv3_vaapi); |
118 | 119 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,168 @@ |
0 |
+/* |
|
1 |
+ * VP9 HW decode acceleration through VA API |
|
2 |
+ * |
|
3 |
+ * Copyright (C) 2015 Timo Rothenpieler <timo@rothenpieler.org> |
|
4 |
+ * |
|
5 |
+ * This file is part of FFmpeg. |
|
6 |
+ * |
|
7 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
8 |
+ * modify it under the terms of the GNU Lesser General Public |
|
9 |
+ * License as published by the Free Software Foundation; either |
|
10 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
11 |
+ * |
|
12 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
13 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
15 |
+ * Lesser General Public License for more details. |
|
16 |
+ * |
|
17 |
+ * You should have received a copy of the GNU Lesser General Public |
|
18 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
19 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
20 |
+ */ |
|
21 |
+ |
|
22 |
+#include "libavutil/pixdesc.h" |
|
23 |
+#include "vaapi_internal.h" |
|
24 |
+#include "vp9.h" |
|
25 |
+ |
|
26 |
+static void fill_picture_parameters(AVCodecContext *avctx, |
|
27 |
+ const VP9SharedContext *h, |
|
28 |
+ VADecPictureParameterBufferVP9 *pp) |
|
29 |
+{ |
|
30 |
+ const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->sw_pix_fmt); |
|
31 |
+ int i; |
|
32 |
+ |
|
33 |
+ pp->frame_width = avctx->width; |
|
34 |
+ pp->frame_height = avctx->height; |
|
35 |
+ |
|
36 |
+ pp->frame_header_length_in_bytes = h->h.uncompressed_header_size; |
|
37 |
+ pp->first_partition_size = h->h.compressed_header_size; |
|
38 |
+ |
|
39 |
+ pp->profile = h->h.profile; |
|
40 |
+ |
|
41 |
+ pp->filter_level = h->h.filter.level; |
|
42 |
+ pp->sharpness_level = h->h.filter.sharpness; |
|
43 |
+ pp->log2_tile_rows = h->h.tiling.log2_tile_rows; |
|
44 |
+ pp->log2_tile_columns = h->h.tiling.log2_tile_cols; |
|
45 |
+ |
|
46 |
+ pp->pic_fields.bits.subsampling_x = pixdesc->log2_chroma_w; |
|
47 |
+ pp->pic_fields.bits.subsampling_y = pixdesc->log2_chroma_h; |
|
48 |
+ pp->pic_fields.bits.frame_type = !h->h.keyframe; |
|
49 |
+ pp->pic_fields.bits.show_frame = !h->h.invisible; |
|
50 |
+ pp->pic_fields.bits.error_resilient_mode = h->h.errorres; |
|
51 |
+ pp->pic_fields.bits.intra_only = h->h.intraonly; |
|
52 |
+ pp->pic_fields.bits.allow_high_precision_mv = h->h.keyframe ? 0 : h->h.highprecisionmvs; |
|
53 |
+ pp->pic_fields.bits.mcomp_filter_type = h->h.filtermode ^ (h->h.filtermode <= 1); |
|
54 |
+ pp->pic_fields.bits.frame_parallel_decoding_mode = h->h.parallelmode; |
|
55 |
+ pp->pic_fields.bits.reset_frame_context = h->h.resetctx; |
|
56 |
+ pp->pic_fields.bits.refresh_frame_context = h->h.refreshctx; |
|
57 |
+ pp->pic_fields.bits.frame_context_idx = h->h.framectxid; |
|
58 |
+ |
|
59 |
+ pp->pic_fields.bits.segmentation_enabled = h->h.segmentation.enabled; |
|
60 |
+ pp->pic_fields.bits.segmentation_temporal_update = h->h.segmentation.temporal; |
|
61 |
+ pp->pic_fields.bits.segmentation_update_map = h->h.segmentation.update_map; |
|
62 |
+ |
|
63 |
+ pp->pic_fields.bits.last_ref_frame = h->h.refidx[0]; |
|
64 |
+ pp->pic_fields.bits.last_ref_frame_sign_bias = h->h.signbias[0]; |
|
65 |
+ pp->pic_fields.bits.golden_ref_frame = h->h.refidx[1]; |
|
66 |
+ pp->pic_fields.bits.golden_ref_frame_sign_bias = h->h.signbias[1]; |
|
67 |
+ pp->pic_fields.bits.alt_ref_frame = h->h.refidx[2]; |
|
68 |
+ pp->pic_fields.bits.alt_ref_frame_sign_bias = h->h.signbias[2]; |
|
69 |
+ pp->pic_fields.bits.lossless_flag = h->h.lossless; |
|
70 |
+ |
|
71 |
+ for (i = 0; i < 7; i++) |
|
72 |
+ pp->mb_segment_tree_probs[i] = h->h.segmentation.prob[i]; |
|
73 |
+ |
|
74 |
+ if (h->h.segmentation.temporal) { |
|
75 |
+ for (i = 0; i < 3; i++) |
|
76 |
+ pp->segment_pred_probs[i] = h->h.segmentation.pred_prob[i]; |
|
77 |
+ } else { |
|
78 |
+ memset(pp->segment_pred_probs, 255, sizeof(pp->segment_pred_probs)); |
|
79 |
+ } |
|
80 |
+ |
|
81 |
+ for (i = 0; i < 8; i++) { |
|
82 |
+ if (h->refs[i].f->buf[0]) { |
|
83 |
+ pp->reference_frames[i] = ff_vaapi_get_surface_id(h->refs[i].f); |
|
84 |
+ } else { |
|
85 |
+ pp->reference_frames[i] = VA_INVALID_ID; |
|
86 |
+ } |
|
87 |
+ } |
|
88 |
+} |
|
89 |
+ |
|
90 |
+static int vaapi_vp9_start_frame(AVCodecContext *avctx, |
|
91 |
+ av_unused const uint8_t *buffer, |
|
92 |
+ av_unused uint32_t size) |
|
93 |
+{ |
|
94 |
+ const VP9SharedContext *h = avctx->priv_data; |
|
95 |
+ FFVAContext * const vactx = ff_vaapi_get_context(avctx); |
|
96 |
+ VADecPictureParameterBufferVP9 *pic_param; |
|
97 |
+ |
|
98 |
+ vactx->slice_param_size = sizeof(VASliceParameterBufferVP9); |
|
99 |
+ |
|
100 |
+ pic_param = ff_vaapi_alloc_pic_param(vactx, sizeof(VADecPictureParameterBufferVP9)); |
|
101 |
+ if (!pic_param) |
|
102 |
+ return -1; |
|
103 |
+ fill_picture_parameters(avctx, h, pic_param); |
|
104 |
+ |
|
105 |
+ return 0; |
|
106 |
+} |
|
107 |
+ |
|
108 |
+static int vaapi_vp9_end_frame(AVCodecContext *avctx) |
|
109 |
+{ |
|
110 |
+ FFVAContext * const vactx = ff_vaapi_get_context(avctx); |
|
111 |
+ const VP9SharedContext *h = avctx->priv_data; |
|
112 |
+ int ret; |
|
113 |
+ |
|
114 |
+ ret = ff_vaapi_commit_slices(vactx); |
|
115 |
+ if (ret < 0) |
|
116 |
+ goto finish; |
|
117 |
+ |
|
118 |
+ ret = ff_vaapi_render_picture(vactx, ff_vaapi_get_surface_id(h->frames[CUR_FRAME].tf.f)); |
|
119 |
+ if (ret < 0) |
|
120 |
+ goto finish; |
|
121 |
+ |
|
122 |
+finish: |
|
123 |
+ ff_vaapi_common_end_frame(avctx); |
|
124 |
+ return ret; |
|
125 |
+} |
|
126 |
+ |
|
127 |
+static int vaapi_vp9_decode_slice(AVCodecContext *avctx, |
|
128 |
+ const uint8_t *buffer, |
|
129 |
+ uint32_t size) |
|
130 |
+{ |
|
131 |
+ FFVAContext * const vactx = ff_vaapi_get_context(avctx); |
|
132 |
+ const VP9SharedContext *h = avctx->priv_data; |
|
133 |
+ VASliceParameterBufferVP9 *slice_param; |
|
134 |
+ int i; |
|
135 |
+ |
|
136 |
+ slice_param = (VASliceParameterBufferVP9*)ff_vaapi_alloc_slice(vactx, buffer, size); |
|
137 |
+ if (!slice_param) |
|
138 |
+ return -1; |
|
139 |
+ |
|
140 |
+ for (i = 0; i < 8; i++) { |
|
141 |
+ slice_param->seg_param[i].segment_flags.fields.segment_reference_enabled = h->h.segmentation.feat[i].ref_enabled; |
|
142 |
+ slice_param->seg_param[i].segment_flags.fields.segment_reference = h->h.segmentation.feat[i].ref_val; |
|
143 |
+ slice_param->seg_param[i].segment_flags.fields.segment_reference_skipped = h->h.segmentation.feat[i].skip_enabled; |
|
144 |
+ |
|
145 |
+ memcpy(slice_param->seg_param[i].filter_level, h->h.segmentation.feat[i].lflvl, sizeof(slice_param->seg_param[i].filter_level)); |
|
146 |
+ |
|
147 |
+ slice_param->seg_param[i].luma_dc_quant_scale = h->h.segmentation.feat[i].qmul[0][0]; |
|
148 |
+ slice_param->seg_param[i].luma_ac_quant_scale = h->h.segmentation.feat[i].qmul[0][1]; |
|
149 |
+ slice_param->seg_param[i].chroma_dc_quant_scale = h->h.segmentation.feat[i].qmul[1][0]; |
|
150 |
+ slice_param->seg_param[i].chroma_ac_quant_scale = h->h.segmentation.feat[i].qmul[1][1]; |
|
151 |
+ } |
|
152 |
+ |
|
153 |
+ return 0; |
|
154 |
+} |
|
155 |
+ |
|
156 |
+AVHWAccel ff_vp9_vaapi_hwaccel = { |
|
157 |
+ .name = "vp9_vaapi", |
|
158 |
+ .type = AVMEDIA_TYPE_VIDEO, |
|
159 |
+ .id = AV_CODEC_ID_VP9, |
|
160 |
+ .pix_fmt = AV_PIX_FMT_VAAPI, |
|
161 |
+ .start_frame = vaapi_vp9_start_frame, |
|
162 |
+ .end_frame = vaapi_vp9_end_frame, |
|
163 |
+ .decode_slice = vaapi_vp9_decode_slice, |
|
164 |
+ .init = ff_vaapi_context_init, |
|
165 |
+ .uninit = ff_vaapi_context_fini, |
|
166 |
+ .priv_data_size = sizeof(FFVAContext), |
|
167 |
+}; |
... | ... |
@@ -29,7 +29,7 @@ |
29 | 29 |
#include "libavutil/version.h" |
30 | 30 |
|
31 | 31 |
#define LIBAVCODEC_VERSION_MAJOR 57 |
32 |
-#define LIBAVCODEC_VERSION_MINOR 19 |
|
32 |
+#define LIBAVCODEC_VERSION_MINOR 20 |
|
33 | 33 |
#define LIBAVCODEC_VERSION_MICRO 100 |
34 | 34 |
|
35 | 35 |
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ |
... | ... |
@@ -240,7 +240,7 @@ fail: |
240 | 240 |
|
241 | 241 |
static int update_size(AVCodecContext *ctx, int w, int h) |
242 | 242 |
{ |
243 |
-#define HWACCEL_MAX (CONFIG_VP9_DXVA2_HWACCEL + CONFIG_VP9_D3D11VA_HWACCEL) |
|
243 |
+#define HWACCEL_MAX (CONFIG_VP9_DXVA2_HWACCEL + CONFIG_VP9_D3D11VA_HWACCEL + CONFIG_VP9_VAAPI_HWACCEL) |
|
244 | 244 |
enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmtp = pix_fmts; |
245 | 245 |
VP9Context *s = ctx->priv_data; |
246 | 246 |
uint8_t *p; |
... | ... |
@@ -261,6 +261,9 @@ static int update_size(AVCodecContext *ctx, int w, int h) |
261 | 261 |
#if CONFIG_VP9_D3D11VA_HWACCEL |
262 | 262 |
*fmtp++ = AV_PIX_FMT_D3D11VA_VLD; |
263 | 263 |
#endif |
264 |
+#if CONFIG_VP9_VAAPI_HWACCEL |
|
265 |
+ *fmtp++ = AV_PIX_FMT_VAAPI; |
|
266 |
+#endif |
|
264 | 267 |
} |
265 | 268 |
|
266 | 269 |
*fmtp++ = s->pix_fmt; |