1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include <va/va.h>
20 #include <va/va_enc_vp9.h>
21
27
31
32 #define VP9_MAX_QUANT 255
33
34 #define VP9_MAX_TILE_WIDTH 4096
35
39
42
43 // User options.
46
47 // Derived settings.
52
53
55 {
58 VAEncSequenceParameterBufferVP9 *vseq =
ctx->codec_sequence_params;
59 VAEncPictureParameterBufferVP9 *vpic =
ctx->codec_picture_params;
60
61 vseq->max_frame_width = avctx->
width;
62 vseq->max_frame_height = avctx->
height;
63
64 vseq->kf_auto = 0;
65
66 if (!(
ctx->va_rc_mode & VA_RC_CQP)) {
67 vseq->bits_per_second =
ctx->va_bit_rate;
68 vseq->intra_period = base_ctx->
gop_size;
69 }
70
71 vpic->frame_width_src = avctx->
width;
72 vpic->frame_height_src = avctx->
height;
73 vpic->frame_width_dst = avctx->
width;
74 vpic->frame_height_dst = avctx->
height;
75
76 return 0;
77 }
78
81 {
88 int num_tile_columns;
89
92
93 // Maximum width of a tile in units of superblocks is MAX_TILE_WIDTH_B64(64)
94 // So the number of tile columns is related to the width of the picture.
95 // We set the minimum possible number for num_tile_columns as default value.
97 vpic->log2_tile_columns = num_tile_columns == 1 ? 0 :
av_log2(num_tile_columns - 1) + 1;
98
102 vpic->ref_flags.bits.force_kf = 1;
103 vpic->refresh_frame_flags = 0xff;
105 break;
108 {
111
114 vpic->refresh_frame_flags = 1 << hpic->
slot | 0xfc;
115 } else {
117 vpic->refresh_frame_flags = 0xff;
118 }
119 vpic->ref_flags.bits.ref_frame_ctrl_l0 = 1;
120 vpic->ref_flags.bits.ref_last_idx = href->
slot;
121 vpic->ref_flags.bits.ref_last_sign_bias = 1;
122 }
123 break;
126 {
130 href1->slot < pic->
b_depth + 1);
131
133 // Unreferenced frame.
134 vpic->refresh_frame_flags = 0x00;
136 } else {
137 vpic->refresh_frame_flags = 0xfe << pic->
b_depth & 0xff;
139 }
140 vpic->ref_flags.bits.ref_frame_ctrl_l0 = 1;
141 vpic->ref_flags.bits.ref_frame_ctrl_l1 = 2;
142 vpic->ref_flags.bits.ref_last_idx = href0->
slot;
143 vpic->ref_flags.bits.ref_last_sign_bias = 1;
144 vpic->ref_flags.bits.ref_gf_idx = href1->slot;
145 vpic->ref_flags.bits.ref_gf_sign_bias = 0;
146 }
147 break;
148 default:
150 }
151 if (vpic->refresh_frame_flags == 0x00) {
154 } else {
157 }
158
160 vpic->reference_frames[
i] = VA_INVALID_SURFACE;
161
163 for (
int j = 0; j < pic->
nb_refs[
i]; j++) {
165 int slot;
167 av_assert0(vpic->reference_frames[slot] == VA_INVALID_SURFACE);
169 }
170 }
171
174
178 vpic->luma_ac_qindex = priv->
q_idx_p;
179 else
180 vpic->luma_ac_qindex = priv->
q_idx_b;
181 vpic->luma_dc_qindex_delta = 0;
182 vpic->chroma_ac_qindex_delta = 0;
183 vpic->chroma_dc_qindex_delta = 0;
184
187
188 return 0;
189 }
190
192 {
194
195 // Surfaces must be aligned to 64x64 superblock boundaries.
198
199 return 0;
200 }
201
203 {
206
207 if (
ctx->rc_mode->quality) {
214 else
221 else
223 } else {
224 // Arbitrary value.
226 }
227
229
230 return 0;
231 }
232
239 };
240
243
246
247 .default_quality = 100,
248
250
253
254 .sequence_params_size = sizeof(VAEncSequenceParameterBufferVP9),
256
257 .picture_params_size = sizeof(VAEncPictureParameterBufferVP9),
259 };
260
262 {
264
266
267 // No packed headers are currently desired. They could be written,
268 // but there isn't any reason to do so - the one usable driver (i965)
269 // can write its own headers and there is no metadata to include.
270 ctx->desired_packed_headers = 0;
271
273 }
274
275 #define OFFSET(x) offsetof(VAAPIEncodeVP9Context, x)
276 #define FLAGS (AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
281
282 { "loop_filter_level", "Loop filter level",
284 { "loop_filter_sharpness", "Loop filter sharpness",
287 };
288
290 { "b", "0" },
291 { "bf", "0" },
292 { "g", "250" },
293 { "qmin", "-1" },
294 { "qmax", "-1" },
296 };
297
303 };
304
306 .
p.
name =
"vp9_vaapi",
324 },
326 .p.wrapper_name = "vaapi",
327 };