... | ... |
@@ -2746,6 +2746,8 @@ vc1_vaapi_hwaccel_deps="vaapi" |
2746 | 2746 |
vc1_vaapi_hwaccel_select="vc1_decoder" |
2747 | 2747 |
vc1_vdpau_hwaccel_deps="vdpau" |
2748 | 2748 |
vc1_vdpau_hwaccel_select="vc1_decoder" |
2749 |
+vp8_vaapi_hwaccel_deps="vaapi VAPictureParameterBufferVP8" |
|
2750 |
+vp8_vaapi_hwaccel_select="vp8_decoder" |
|
2749 | 2751 |
vp9_d3d11va_hwaccel_deps="d3d11va DXVA_PicParams_VP9" |
2750 | 2752 |
vp9_d3d11va_hwaccel_select="vp9_decoder" |
2751 | 2753 |
vp9_d3d11va2_hwaccel_deps="d3d11va DXVA_PicParams_VP9" |
... | ... |
@@ -5719,6 +5721,7 @@ check_type "windows.h d3d11.h" "ID3D11VideoContext" |
5719 | 5719 |
check_type "d3d9.h dxva2api.h" DXVA2_ConfigPictureDecode -D_WIN32_WINNT=0x0602 |
5720 | 5720 |
|
5721 | 5721 |
check_type "va/va.h va/va_dec_hevc.h" "VAPictureParameterBufferHEVC" |
5722 |
+check_type "va/va.h va/va_dec_vp8.h" "VAPictureParameterBufferVP8" |
|
5722 | 5723 |
check_struct "va/va.h" "VADecPictureParameterBufferVP9" bit_depth |
5723 | 5724 |
check_type "va/va.h va/va_vpp.h" "VAProcPipelineParameterBuffer" |
5724 | 5725 |
check_type "va/va.h va/va_enc_h264.h" "VAEncPictureParameterBufferH264" |
... | ... |
@@ -871,6 +871,7 @@ OBJS-$(CONFIG_VC1_NVDEC_HWACCEL) += nvdec_vc1.o |
871 | 871 |
OBJS-$(CONFIG_VC1_QSV_HWACCEL) += qsvdec_other.o |
872 | 872 |
OBJS-$(CONFIG_VC1_VAAPI_HWACCEL) += vaapi_vc1.o |
873 | 873 |
OBJS-$(CONFIG_VC1_VDPAU_HWACCEL) += vdpau_vc1.o |
874 |
+OBJS-$(CONFIG_VP8_VAAPI_HWACCEL) += vaapi_vp8.o |
|
874 | 875 |
OBJS-$(CONFIG_VP9_D3D11VA_HWACCEL) += dxva2_vp9.o |
875 | 876 |
OBJS-$(CONFIG_VP9_DXVA2_HWACCEL) += dxva2_vp9.o |
876 | 877 |
OBJS-$(CONFIG_VP9_NVDEC_HWACCEL) += nvdec_vp9.o |
... | ... |
@@ -59,6 +59,7 @@ extern const AVHWAccel ff_vc1_dxva2_hwaccel; |
59 | 59 |
extern const AVHWAccel ff_vc1_nvdec_hwaccel; |
60 | 60 |
extern const AVHWAccel ff_vc1_vaapi_hwaccel; |
61 | 61 |
extern const AVHWAccel ff_vc1_vdpau_hwaccel; |
62 |
+extern const AVHWAccel ff_vp8_vaapi_hwaccel; |
|
62 | 63 |
extern const AVHWAccel ff_vp9_d3d11va_hwaccel; |
63 | 64 |
extern const AVHWAccel ff_vp9_d3d11va2_hwaccel; |
64 | 65 |
extern const AVHWAccel ff_vp9_dxva2_hwaccel; |
65 | 66 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,237 @@ |
0 |
+/* |
|
1 |
+ * This file is part of FFmpeg. |
|
2 |
+ * |
|
3 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
4 |
+ * modify it under the terms of the GNU Lesser General Public |
|
5 |
+ * License as published by the Free Software Foundation; either |
|
6 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
7 |
+ * |
|
8 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
9 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
11 |
+ * Lesser General Public License for more details. |
|
12 |
+ * |
|
13 |
+ * You should have received a copy of the GNU Lesser General Public |
|
14 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
15 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
16 |
+ */ |
|
17 |
+ |
|
18 |
+#include <va/va.h> |
|
19 |
+#include <va/va_dec_vp8.h> |
|
20 |
+ |
|
21 |
+#include "hwaccel.h" |
|
22 |
+#include "vaapi_decode.h" |
|
23 |
+#include "vp8.h" |
|
24 |
+ |
|
25 |
+static VASurfaceID vaapi_vp8_surface_id(VP8Frame *vf) |
|
26 |
+{ |
|
27 |
+ if (vf) |
|
28 |
+ return ff_vaapi_get_surface_id(vf->tf.f); |
|
29 |
+ else |
|
30 |
+ return VA_INVALID_SURFACE; |
|
31 |
+} |
|
32 |
+ |
|
33 |
+static int vaapi_vp8_start_frame(AVCodecContext *avctx, |
|
34 |
+ av_unused const uint8_t *buffer, |
|
35 |
+ av_unused uint32_t size) |
|
36 |
+{ |
|
37 |
+ const VP8Context *s = avctx->priv_data; |
|
38 |
+ VAAPIDecodePicture *pic = s->framep[VP56_FRAME_CURRENT]->hwaccel_picture_private; |
|
39 |
+ VAPictureParameterBufferVP8 pp; |
|
40 |
+ VAProbabilityDataBufferVP8 prob; |
|
41 |
+ VAIQMatrixBufferVP8 quant; |
|
42 |
+ int err, i, j, k; |
|
43 |
+ |
|
44 |
+ pic->output_surface = vaapi_vp8_surface_id(s->framep[VP56_FRAME_CURRENT]); |
|
45 |
+ |
|
46 |
+ pp = (VAPictureParameterBufferVP8) { |
|
47 |
+ .frame_width = avctx->width, |
|
48 |
+ .frame_height = avctx->height, |
|
49 |
+ |
|
50 |
+ .last_ref_frame = vaapi_vp8_surface_id(s->framep[VP56_FRAME_PREVIOUS]), |
|
51 |
+ .golden_ref_frame = vaapi_vp8_surface_id(s->framep[VP56_FRAME_GOLDEN]), |
|
52 |
+ .alt_ref_frame = vaapi_vp8_surface_id(s->framep[VP56_FRAME_GOLDEN2]), |
|
53 |
+ .out_of_loop_frame = VA_INVALID_SURFACE, |
|
54 |
+ |
|
55 |
+ .pic_fields.bits = { |
|
56 |
+ .key_frame = !s->keyframe, |
|
57 |
+ .version = s->profile, |
|
58 |
+ |
|
59 |
+ .segmentation_enabled = s->segmentation.enabled, |
|
60 |
+ .update_mb_segmentation_map = s->segmentation.update_map, |
|
61 |
+ .update_segment_feature_data = s->segmentation.update_feature_data, |
|
62 |
+ |
|
63 |
+ .filter_type = s->filter.simple, |
|
64 |
+ .sharpness_level = s->filter.sharpness, |
|
65 |
+ |
|
66 |
+ .loop_filter_adj_enable = s->lf_delta.enabled, |
|
67 |
+ .mode_ref_lf_delta_update = s->lf_delta.update, |
|
68 |
+ |
|
69 |
+ .sign_bias_golden = s->sign_bias[VP56_FRAME_GOLDEN], |
|
70 |
+ .sign_bias_alternate = s->sign_bias[VP56_FRAME_GOLDEN2], |
|
71 |
+ |
|
72 |
+ .mb_no_coeff_skip = s->mbskip_enabled, |
|
73 |
+ .loop_filter_disable = s->filter.level == 0, |
|
74 |
+ }, |
|
75 |
+ |
|
76 |
+ .prob_skip_false = s->prob->mbskip, |
|
77 |
+ .prob_intra = s->prob->intra, |
|
78 |
+ .prob_last = s->prob->last, |
|
79 |
+ .prob_gf = s->prob->golden, |
|
80 |
+ }; |
|
81 |
+ |
|
82 |
+ for (i = 0; i < 3; i++) |
|
83 |
+ pp.mb_segment_tree_probs[i] = s->prob->segmentid[i]; |
|
84 |
+ |
|
85 |
+ for (i = 0; i < 4; i++) { |
|
86 |
+ if (s->segmentation.enabled) { |
|
87 |
+ pp.loop_filter_level[i] = s->segmentation.filter_level[i]; |
|
88 |
+ if (!s->segmentation.absolute_vals) |
|
89 |
+ pp.loop_filter_level[i] += s->filter.level; |
|
90 |
+ } else { |
|
91 |
+ pp.loop_filter_level[i] = s->filter.level; |
|
92 |
+ } |
|
93 |
+ pp.loop_filter_level[i] = av_clip_uintp2(pp.loop_filter_level[i], 6); |
|
94 |
+ } |
|
95 |
+ |
|
96 |
+ for (i = 0; i < 4; i++) { |
|
97 |
+ pp.loop_filter_deltas_ref_frame[i] = s->lf_delta.ref[i]; |
|
98 |
+ pp.loop_filter_deltas_mode[i] = s->lf_delta.mode[i + 4]; |
|
99 |
+ } |
|
100 |
+ |
|
101 |
+ if (s->keyframe) { |
|
102 |
+ static const uint8_t keyframe_y_mode_probs[4] = { |
|
103 |
+ 145, 156, 163, 128 |
|
104 |
+ }; |
|
105 |
+ static const uint8_t keyframe_uv_mode_probs[3] = { |
|
106 |
+ 142, 114, 183 |
|
107 |
+ }; |
|
108 |
+ memcpy(pp.y_mode_probs, keyframe_y_mode_probs, 4); |
|
109 |
+ memcpy(pp.uv_mode_probs, keyframe_uv_mode_probs, 3); |
|
110 |
+ } else { |
|
111 |
+ for (i = 0; i < 4; i++) |
|
112 |
+ pp.y_mode_probs[i] = s->prob->pred16x16[i]; |
|
113 |
+ for (i = 0; i < 3; i++) |
|
114 |
+ pp.uv_mode_probs[i] = s->prob->pred8x8c[i]; |
|
115 |
+ } |
|
116 |
+ for (i = 0; i < 2; i++) |
|
117 |
+ for (j = 0; j < 19; j++) |
|
118 |
+ pp.mv_probs[i][j] = s->prob->mvc[i][j]; |
|
119 |
+ |
|
120 |
+ pp.bool_coder_ctx.range = s->coder_state_at_header_end.range; |
|
121 |
+ pp.bool_coder_ctx.value = s->coder_state_at_header_end.value; |
|
122 |
+ pp.bool_coder_ctx.count = s->coder_state_at_header_end.bit_count; |
|
123 |
+ |
|
124 |
+ err = ff_vaapi_decode_make_param_buffer(avctx, pic, |
|
125 |
+ VAPictureParameterBufferType, |
|
126 |
+ &pp, sizeof(pp)); |
|
127 |
+ if (err < 0) |
|
128 |
+ goto fail; |
|
129 |
+ |
|
130 |
+ for (i = 0; i < 4; i++) { |
|
131 |
+ for (j = 0; j < 8; j++) { |
|
132 |
+ static const int coeff_bands_inverse[8] = { |
|
133 |
+ 0, 1, 2, 3, 5, 6, 4, 15 |
|
134 |
+ }; |
|
135 |
+ int coeff_pos = coeff_bands_inverse[j]; |
|
136 |
+ |
|
137 |
+ for (k = 0; k < 3; k++) { |
|
138 |
+ memcpy(prob.dct_coeff_probs[i][j][k], |
|
139 |
+ s->prob->token[i][coeff_pos][k], 11); |
|
140 |
+ } |
|
141 |
+ } |
|
142 |
+ } |
|
143 |
+ |
|
144 |
+ err = ff_vaapi_decode_make_param_buffer(avctx, pic, |
|
145 |
+ VAProbabilityBufferType, |
|
146 |
+ &prob, sizeof(prob)); |
|
147 |
+ if (err < 0) |
|
148 |
+ goto fail; |
|
149 |
+ |
|
150 |
+ for (i = 0; i < 4; i++) { |
|
151 |
+ int base_qi = s->segmentation.base_quant[i]; |
|
152 |
+ if (!s->segmentation.absolute_vals) |
|
153 |
+ base_qi += s->quant.yac_qi; |
|
154 |
+ |
|
155 |
+ quant.quantization_index[i][0] = av_clip_uintp2(base_qi, 7); |
|
156 |
+ quant.quantization_index[i][1] = av_clip_uintp2(base_qi + s->quant.ydc_delta, 7); |
|
157 |
+ quant.quantization_index[i][2] = av_clip_uintp2(base_qi + s->quant.y2dc_delta, 7); |
|
158 |
+ quant.quantization_index[i][3] = av_clip_uintp2(base_qi + s->quant.y2ac_delta, 7); |
|
159 |
+ quant.quantization_index[i][4] = av_clip_uintp2(base_qi + s->quant.uvdc_delta, 7); |
|
160 |
+ quant.quantization_index[i][5] = av_clip_uintp2(base_qi + s->quant.uvac_delta, 7); |
|
161 |
+ } |
|
162 |
+ |
|
163 |
+ err = ff_vaapi_decode_make_param_buffer(avctx, pic, |
|
164 |
+ VAIQMatrixBufferType, |
|
165 |
+ &quant, sizeof(quant)); |
|
166 |
+ if (err < 0) |
|
167 |
+ goto fail; |
|
168 |
+ |
|
169 |
+ return 0; |
|
170 |
+ |
|
171 |
+fail: |
|
172 |
+ ff_vaapi_decode_cancel(avctx, pic); |
|
173 |
+ return err; |
|
174 |
+} |
|
175 |
+ |
|
176 |
+static int vaapi_vp8_end_frame(AVCodecContext *avctx) |
|
177 |
+{ |
|
178 |
+ const VP8Context *s = avctx->priv_data; |
|
179 |
+ VAAPIDecodePicture *pic = s->framep[VP56_FRAME_CURRENT]->hwaccel_picture_private; |
|
180 |
+ |
|
181 |
+ return ff_vaapi_decode_issue(avctx, pic); |
|
182 |
+} |
|
183 |
+ |
|
184 |
+static int vaapi_vp8_decode_slice(AVCodecContext *avctx, |
|
185 |
+ const uint8_t *buffer, |
|
186 |
+ uint32_t size) |
|
187 |
+{ |
|
188 |
+ const VP8Context *s = avctx->priv_data; |
|
189 |
+ VAAPIDecodePicture *pic = s->framep[VP56_FRAME_CURRENT]->hwaccel_picture_private; |
|
190 |
+ VASliceParameterBufferVP8 sp; |
|
191 |
+ int err, i; |
|
192 |
+ |
|
193 |
+ unsigned int header_size = 3 + 7 * s->keyframe; |
|
194 |
+ const uint8_t *data = buffer + header_size; |
|
195 |
+ unsigned int data_size = size - header_size; |
|
196 |
+ |
|
197 |
+ sp = (VASliceParameterBufferVP8) { |
|
198 |
+ .slice_data_size = data_size, |
|
199 |
+ .slice_data_offset = 0, |
|
200 |
+ .slice_data_flag = VA_SLICE_DATA_FLAG_ALL, |
|
201 |
+ |
|
202 |
+ .macroblock_offset = (8 * (s->coder_state_at_header_end.input - data) - |
|
203 |
+ s->coder_state_at_header_end.bit_count - 8), |
|
204 |
+ .num_of_partitions = s->num_coeff_partitions + 1, |
|
205 |
+ }; |
|
206 |
+ |
|
207 |
+ sp.partition_size[0] = s->header_partition_size - ((sp.macroblock_offset + 7) / 8); |
|
208 |
+ for (i = 0; i < 8; i++) |
|
209 |
+ sp.partition_size[i+1] = s->coeff_partition_size[i]; |
|
210 |
+ |
|
211 |
+ err = ff_vaapi_decode_make_slice_buffer(avctx, pic, &sp, sizeof(sp), data, data_size); |
|
212 |
+ if (err) |
|
213 |
+ goto fail; |
|
214 |
+ |
|
215 |
+ return 0; |
|
216 |
+ |
|
217 |
+fail: |
|
218 |
+ ff_vaapi_decode_cancel(avctx, pic); |
|
219 |
+ return err; |
|
220 |
+} |
|
221 |
+ |
|
222 |
+const AVHWAccel ff_vp8_vaapi_hwaccel = { |
|
223 |
+ .name = "vp8_vaapi", |
|
224 |
+ .type = AVMEDIA_TYPE_VIDEO, |
|
225 |
+ .id = AV_CODEC_ID_VP8, |
|
226 |
+ .pix_fmt = AV_PIX_FMT_VAAPI, |
|
227 |
+ .start_frame = &vaapi_vp8_start_frame, |
|
228 |
+ .end_frame = &vaapi_vp8_end_frame, |
|
229 |
+ .decode_slice = &vaapi_vp8_decode_slice, |
|
230 |
+ .frame_priv_data_size = sizeof(VAAPIDecodePicture), |
|
231 |
+ .init = &ff_vaapi_decode_init, |
|
232 |
+ .uninit = &ff_vaapi_decode_uninit, |
|
233 |
+ .frame_params = &ff_vaapi_common_frame_params, |
|
234 |
+ .priv_data_size = sizeof(VAAPIDecodeContext), |
|
235 |
+ .caps_internal = HWACCEL_CAP_ASYNC_SAFE, |
|
236 |
+}; |
... | ... |
@@ -2599,6 +2599,9 @@ int vp78_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, |
2599 | 2599 |
// avctx->pix_fmt already set in caller. |
2600 | 2600 |
} else if (!is_vp7 && s->pix_fmt == AV_PIX_FMT_NONE) { |
2601 | 2601 |
enum AVPixelFormat pix_fmts[] = { |
2602 |
+#if CONFIG_VP8_VAAPI_HWACCEL |
|
2603 |
+ AV_PIX_FMT_VAAPI, |
|
2604 |
+#endif |
|
2602 | 2605 |
AV_PIX_FMT_YUV420P, |
2603 | 2606 |
AV_PIX_FMT_NONE, |
2604 | 2607 |
}; |
... | ... |
@@ -2944,6 +2947,9 @@ AVCodec ff_vp8_decoder = { |
2944 | 2944 |
.init_thread_copy = ONLY_IF_THREADS_ENABLED(vp8_decode_init_thread_copy), |
2945 | 2945 |
.update_thread_context = ONLY_IF_THREADS_ENABLED(vp8_decode_update_thread_context), |
2946 | 2946 |
.hw_configs = (const AVCodecHWConfigInternal*[]) { |
2947 |
+#if CONFIG_VP8_VAAPI_HWACCEL |
|
2948 |
+ HWACCEL_VAAPI(vp8), |
|
2949 |
+#endif |
|
2947 | 2950 |
NULL |
2948 | 2951 |
}, |
2949 | 2952 |
}; |