1 /*
2 * AV1 HW decode acceleration through NVDEC
3 *
4 * Copyright (c) 2020 Timo Rothenpieler
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
29
30
32 {
36 return 10;
37 else
38 return 8;
39 }
40
42 {
47
49 CUVIDPICPARAMS *pp = &
ctx->pic_params;
50 CUVIDAV1PICPARAMS *ppc = &pp->CodecSpecific.av1;
54
56
59
63
66
67 *pp = (CUVIDPICPARAMS) {
68 .PicWidthInMbs = (cur_frame->
width + 15) / 16,
69 .FrameHeightInMbs = (cur_frame->
height + 15) / 16,
70 .CurrPicIdx = cf->
idx,
74
75 .CodecSpecific.av1 = {
76 .width = cur_frame->
width,
77 .height = cur_frame->
height,
78
81
82 /* Sequence Header */
102
103 /* Frame Header */
107 .allow_screen_content_tools =
frame_header->allow_screen_content_tools,
113 .allow_high_precision_mv =
frame_header->allow_high_precision_mv,
115 .switchable_motion_mode =
frame_header->is_motion_mode_switchable,
117 .disable_frame_end_update_cdf =
frame_header->disable_frame_end_update_cdf,
121 .coded_lossless =
s->cur_frame.coded_lossless,
125 .allow_warped_motion =
frame_header->allow_warped_motion,
128
129 /* Tiling Info */
132 .context_update_tile_id =
frame_header->context_update_tile_id,
133
134 /* CDEF */
135 .cdef_damping_minus_3 =
frame_header->cdef_damping_minus_3,
137
138 /* SkipModeFrames */
140 s->cur_frame.skip_mode_frame_idx[0] : 0,
142 s->cur_frame.skip_mode_frame_idx[1] : 0,
143
144 /* QP Information */
154
155 /* Segmentation */
156 .segmentation_enabled =
frame_header->segmentation_enabled,
157 .segmentation_update_map =
frame_header->segmentation_update_map,
158 .segmentation_update_data =
frame_header->segmentation_update_data,
159 .segmentation_temporal_update =
frame_header->segmentation_temporal_update,
160
161 /* Loopfilter */
162 .loop_filter_level[0] =
frame_header->loop_filter_level[0],
163 .loop_filter_level[1] =
frame_header->loop_filter_level[1],
164 .loop_filter_level_u =
frame_header->loop_filter_level[2],
165 .loop_filter_level_v =
frame_header->loop_filter_level[3],
166 .loop_filter_sharpness =
frame_header->loop_filter_sharpness,
167 .loop_filter_delta_enabled =
frame_header->loop_filter_delta_enabled,
168 .loop_filter_delta_update =
frame_header->loop_filter_delta_update,
169 .loop_filter_mode_deltas[0] =
frame_header->loop_filter_mode_deltas[0],
170 .loop_filter_mode_deltas[1] =
frame_header->loop_filter_mode_deltas[1],
174
175 /* Restoration */
182
183 /* Reference Frames */
184 .temporal_layer_id =
s->cur_frame.temporal_id,
185 .spatial_layer_id =
s->cur_frame.spatial_id,
186
187 /* Film Grain Params */
188 .apply_grain = apply_grain,
200 .cb_mult = film_grain->
cb_mult,
203 .cr_mult = film_grain->
cr_mult,
206 }
207 };
208
209 /* Tiling Info */
212 }
214 ppc->tile_heights[
i] =
frame_header->height_in_sbs_minus_1[
i] + 1;
215 }
216
217 /* CDEF */
221 }
222
223 /* Segmentation */
225 ppc->segmentation_feature_mask[
i] = 0;
227 ppc->segmentation_feature_mask[
i] |=
frame_header->feature_enabled[
i][j] << j;
228 ppc->segmentation_feature_data[
i][j] =
frame_header->feature_value[
i][j];
229 }
230 }
231
233 /* Loopfilter */
234 ppc->loop_filter_ref_deltas[
i] =
frame_header->loop_filter_ref_deltas[
i];
235
236 /* Reference Frames */
238 }
239
241 ppc->primary_ref_frame = -1;
242 } else {
244 ppc->primary_ref_frame = ppc->ref_frame_map[pri_ref_idx];
245 }
246
248 /* Ref Frame List */
251
252 ppc->ref_frame[
i].index = ppc->ref_frame_map[ref_idx];
255
256 /* Global Motion */
259 for (j = 0; j < 6; ++j) {
261 }
262 }
263
264 /* Film Grain Params */
265 if (apply_grain) {
266 for (
i = 0;
i < 14; ++
i) {
269 }
270 for (
i = 0;
i < 10; ++
i) {
275 }
276 for (
i = 0;
i < 24; ++
i) {
278 }
279 for (
i = 0;
i < 25; ++
i) {
282 }
283 }
284
285 return 0;
286 }
287
289 {
294
296
298 ctx->nb_slices * 2 *
sizeof(*
ctx->slice_offsets));
301 }
303
304 /* Shortcut if all tiles are in the same buffer */
305 if (
ctx->nb_slices ==
s->tg_end -
s->tg_start + 1) {
308
309 for (
int i = 0;
i <
ctx->nb_slices; ++
i) {
310 ctx->slice_offsets[
i*2 ] =
s->tile_group_info[
i].tile_offset;
311 ctx->slice_offsets[
i*2 + 1] =
ctx->slice_offsets[
i*2] +
s->tile_group_info[
i].tile_size;
312 }
313
314 return 0;
315 }
316
321 }
322 ctx->bitstream =
ctx->bitstream_internal =
tmp;
323
325
326 for (uint32_t tile_num =
s->tg_start; tile_num <= s->tg_end; ++tile_num) {
327 ctx->slice_offsets[tile_num*2 ] =
ctx->bitstream_len +
s->tile_group_info[tile_num].tile_offset;
328 ctx->slice_offsets[tile_num*2 + 1] =
ctx->slice_offsets[tile_num*2] +
s->tile_group_info[tile_num].tile_size;
329 }
331
332 return 0;
333 }
334
336 {
337 /* Maximum of 8 reference frames, but potentially stored twice due to film grain */
339 }
340
342 .
p.
name =
"av1_nvdec",
353 };