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
30
31
33 {
37 return 10;
38 else
39 return 8;
40 }
41
43 {
48
50 CUVIDPICPARAMS *pp = &
ctx->pic_params;
51 CUVIDAV1PICPARAMS *ppc = &pp->CodecSpecific.av1;
55
57
60
64
67
68 *pp = (CUVIDPICPARAMS) {
69 .PicWidthInMbs = (cur_frame->
width + 15) / 16,
70 .FrameHeightInMbs = (cur_frame->
height + 15) / 16,
71 .CurrPicIdx = cf->
idx,
75
76 .CodecSpecific.av1 = {
77 .width = cur_frame->
width,
78 .height = cur_frame->
height,
79
82
83 /* Sequence Header */
103
104 /* Frame Header */
108 .allow_screen_content_tools =
frame_header->allow_screen_content_tools,
109 .force_integer_mv =
s->cur_frame.force_integer_mv,
112 .allow_high_precision_mv =
frame_header->allow_high_precision_mv,
114 .switchable_motion_mode =
frame_header->is_motion_mode_switchable,
116 .disable_frame_end_update_cdf =
frame_header->disable_frame_end_update_cdf,
120 .coded_lossless =
s->cur_frame.coded_lossless,
124 .allow_warped_motion =
frame_header->allow_warped_motion,
127
128 /* Tiling Info */
131 .context_update_tile_id =
frame_header->context_update_tile_id,
132
133 /* CDEF */
134 .cdef_damping_minus_3 =
frame_header->cdef_damping_minus_3,
136
137 /* SkipModeFrames */
139 s->cur_frame.skip_mode_frame_idx[0] : 0,
141 s->cur_frame.skip_mode_frame_idx[1] : 0,
142
143 /* QP Information */
153
154 /* Segmentation */
155 .segmentation_enabled =
frame_header->segmentation_enabled,
156 .segmentation_update_map =
frame_header->segmentation_update_map,
157 .segmentation_update_data =
frame_header->segmentation_update_data,
158 .segmentation_temporal_update =
frame_header->segmentation_temporal_update,
159
160 /* Loopfilter */
161 .loop_filter_level[0] =
frame_header->loop_filter_level[0],
162 .loop_filter_level[1] =
frame_header->loop_filter_level[1],
163 .loop_filter_level_u =
frame_header->loop_filter_level[2],
164 .loop_filter_level_v =
frame_header->loop_filter_level[3],
165 .loop_filter_sharpness =
frame_header->loop_filter_sharpness,
166 .loop_filter_delta_enabled =
frame_header->loop_filter_delta_enabled,
167 .loop_filter_delta_update =
frame_header->loop_filter_delta_update,
168 .loop_filter_mode_deltas[0] =
frame_header->loop_filter_mode_deltas[0],
169 .loop_filter_mode_deltas[1] =
frame_header->loop_filter_mode_deltas[1],
173
174 /* Restoration */
181
182 /* Reference Frames */
183 .temporal_layer_id =
s->cur_frame.temporal_id,
184 .spatial_layer_id =
s->cur_frame.spatial_id,
185
186 /* Film Grain Params */
187 .apply_grain = apply_grain,
199 .cb_mult = film_grain->
cb_mult,
202 .cr_mult = film_grain->
cr_mult,
205 }
206 };
207
208 /* Tiling Info */
211 }
213 ppc->tile_heights[
i] =
frame_header->height_in_sbs_minus_1[
i] + 1;
214 }
215
216 /* CDEF */
220 }
221
222 /* Segmentation */
224 ppc->segmentation_feature_mask[
i] = 0;
226 ppc->segmentation_feature_mask[
i] |=
frame_header->feature_enabled[
i][j] << j;
227 ppc->segmentation_feature_data[
i][j] =
frame_header->feature_value[
i][j];
228 }
229 }
230
232 /* Loopfilter */
233 ppc->loop_filter_ref_deltas[
i] =
frame_header->loop_filter_ref_deltas[
i];
234
235 /* Reference Frames */
237 }
238
240 ppc->primary_ref_frame = -1;
241 } else {
243 ppc->primary_ref_frame = ppc->ref_frame_map[pri_ref_idx];
244 }
245
247 /* Ref Frame List */
250
251 ppc->ref_frame[
i].index = ppc->ref_frame_map[ref_idx];
254
255 /* Global Motion */
258 for (j = 0; j < 6; ++j) {
260 }
261 }
262
263 /* Film Grain Params */
264 if (apply_grain) {
265 for (
i = 0;
i < 14; ++
i) {
268 }
269 for (
i = 0;
i < 10; ++
i) {
274 }
275 for (
i = 0;
i < 24; ++
i) {
277 }
278 for (
i = 0;
i < 25; ++
i) {
281 }
282 }
283
284 return 0;
285 }
286
288 {
293
295
297 ctx->nb_slices * 2 *
sizeof(*
ctx->slice_offsets));
300 }
302
303 /* Shortcut if all tiles are in the same buffer */
304 if (
ctx->nb_slices ==
s->tg_end -
s->tg_start + 1) {
307
308 for (
int i = 0;
i <
ctx->nb_slices; ++
i) {
309 ctx->slice_offsets[
i*2 ] =
s->tile_group_info[
i].tile_offset;
310 ctx->slice_offsets[
i*2 + 1] =
ctx->slice_offsets[
i*2] +
s->tile_group_info[
i].tile_size;
311 }
312
313 return 0;
314 }
315
320 }
321 ctx->bitstream =
ctx->bitstream_internal =
tmp;
322
324
325 for (uint32_t tile_num =
s->tg_start; tile_num <= s->tg_end; ++tile_num) {
326 ctx->slice_offsets[tile_num*2 ] =
ctx->bitstream_len +
s->tile_group_info[tile_num].tile_offset;
327 ctx->slice_offsets[tile_num*2 + 1] =
ctx->slice_offsets[tile_num*2] +
s->tile_group_info[tile_num].tile_size;
328 }
330
331 return 0;
332 }
333
335 {
336 /* Maximum of 8 reference frames, but potentially stored twice due to film grain */
338 }
339
341 .
p.
name =
"av1_nvdec",
352 };