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
20
22
26 .queue_flags = VK_QUEUE_VIDEO_DECODE_BIT_KHR,
27 .decode_op = VK_VIDEO_CODEC_OPERATION_DECODE_VP9_BIT_KHR,
28 .ext_props = {
29 .extensionName = VK_STD_VULKAN_VIDEO_CODEC_VP9_DECODE_EXTENSION_NAME,
30 .specVersion = VK_STD_VULKAN_VIDEO_CODEC_VP9_DECODE_SPEC_VERSION,
31 },
32 };
33
36
37 /* TODO: investigate if this can be removed to make decoding completely
38 * independent. */
40
41 /* Current picture */
47
49
54
56 VkVideoReferenceSlotInfoKHR *ref_slot, /* Main structure */
57 VkVideoPictureResourceInfoKHR *
ref,
/* Goes in ^ */
59 {
64
67 if (err < 0)
68 return err;
69
70 *
ref = (VkVideoPictureResourceInfoKHR) {
71 .sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,
72 .codedOffset = (VkOffset2D){ 0, 0 },
76 .imageViewBinding = vkpic->
view.
ref[0],
77 };
78
79 *ref_slot = (VkVideoReferenceSlotInfoKHR) {
80 .sType = VK_STRUCTURE_TYPE_VIDEO_REFERENCE_SLOT_INFO_KHR,
82 .pPictureResource =
ref,
83 };
84
85 if (ref_src)
86 *ref_src = pic;
87
88 return 0;
89 }
90
91 static enum StdVideoVP9InterpolationFilter
remap_interp(uint8_t is_filter_switchable,
92 uint8_t raw_interpolation_filter_type)
93 {
94 static const enum StdVideoVP9InterpolationFilter
remap[] = {
95 STD_VIDEO_VP9_INTERPOLATION_FILTER_EIGHTTAP_SMOOTH,
96 STD_VIDEO_VP9_INTERPOLATION_FILTER_EIGHTTAP,
97 STD_VIDEO_VP9_INTERPOLATION_FILTER_EIGHTTAP_SHARP,
98 STD_VIDEO_VP9_INTERPOLATION_FILTER_BILINEAR,
99 };
100 if (is_filter_switchable)
101 return STD_VIDEO_VP9_INTERPOLATION_FILTER_SWITCHABLE;
102 return remap[raw_interpolation_filter_type];
103 }
104
109 {
110 int err;
111 int ref_count = 0;
115 uint32_t frame_id_alloc_mask = 0;
116
120
123
124 /* Use the current frame_ids in ref_frames[] to decide occupied frame_ids */
125 for (
int i = 0;
i < STD_VIDEO_VP9_NUM_REF_FRAMES;
i++) {
127 if (rp)
128 frame_id_alloc_mask |= 1 << rp->
frame_id;
129 }
130
131 if (!ap->frame_id_set) {
132 unsigned slot_idx = 0;
133 for (
unsigned i = 0;
i < 32;
i++) {
134 if (!(frame_id_alloc_mask & (1 <<
i))) {
136 break;
137 }
138 }
139 ap->frame_id = slot_idx;
140 ap->frame_id_set = 1;
141 frame_id_alloc_mask |= (1 << slot_idx);
142 }
143
144 for (
int i = 0;
i < STD_VIDEO_VP9_REFS_PER_FRAME;
i++) {
148 int found = 0;
149
151 continue;
152
153 for (int j = 0; j < ref_count; j++) {
154 if (vp->ref_slots[j].slotIndex == hp->
frame_id) {
155 found = 1;
156 break;
157 }
158 }
159 if (found)
160 continue;
161
163 &vp->ref_slots[ref_count], &vp->
refs[ref_count],
165 if (err < 0)
166 return err;
167
168 ref_count++;
169 }
170
172 pic, 1);
173 if (err < 0)
174 return err;
175
176 ap->loop_filter = (StdVideoVP9LoopFilter) {
177 .flags = (StdVideoVP9LoopFilterFlags) {
180 },
183 .update_ref_delta = 0x0,
184 .update_mode_delta = 0x0,
185 };
186
187 for (
int i = 0;
i < STD_VIDEO_VP9_MAX_REF_FRAMES;
i++) {
190 }
191 for (
int i = 0;
i < STD_VIDEO_VP9_LOOP_FILTER_ADJUSTMENTS;
i++) {
194 }
195
196 ap->segmentation = (StdVideoVP9Segmentation) {
197 .flags = (StdVideoVP9SegmentationFlags) {
202 },
203 };
204
205 for (
int i = 0;
i < STD_VIDEO_VP9_MAX_SEGMENTATION_TREE_PROBS;
i++)
207 for (
int i = 0;
i < STD_VIDEO_VP9_MAX_SEGMENTATION_PRED_PROB;
i++)
209 for (
int i = 0;
i < STD_VIDEO_VP9_MAX_SEGMENTS;
i++) {
210 ap->segmentation.FeatureEnabled[
i] = 0x0;
211 for (int j = 0; j < STD_VIDEO_VP9_SEG_LVL_MAX; j++) {
216 }
217 }
218
219 ap->color_config = (StdVideoVP9ColorConfig) {
220 .flags = (StdVideoVP9ColorConfigFlags) {
222 },
228 };
229
230 ap->std_pic_info = (StdVideoDecodeVP9PictureInfo) {
231 .flags = (StdVideoDecodeVP9PictureInfoFlags) {
239 .UsePrevFrameMvs =
s->h.use_last_frame_mvs,
240 },
246 .ref_frame_sign_bias_mask = 0x0,
255 /* Reserved */
256 .pColorConfig = &ap->color_config,
257 .pLoopFilter = &ap->loop_filter,
258 .pSegmentation = &ap->segmentation,
259 };
260
263
264 ap->vp9_pic_info = (VkVideoDecodeVP9PictureInfoKHR) {
265 .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_VP9_PICTURE_INFO_KHR,
266 .pStdPictureInfo = &ap->std_pic_info,
267 .uncompressedHeaderOffset = 0,
268 .compressedHeaderOffset =
s->h.uncompressed_header_size,
269 .tilesOffset =
s->h.uncompressed_header_size +
270 s->h.compressed_header_size,
271 };
272
273 for (
int i = 0;
i < STD_VIDEO_VP9_REFS_PER_FRAME;
i++) {
277
279 ap->vp9_pic_info.referenceNameSlotIndices[
i] = -1;
280 else
281 ap->vp9_pic_info.referenceNameSlotIndices[
i] = hp->
frame_id;
282 }
283
284 vp->decode_info = (VkVideoDecodeInfoKHR) {
285 .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_INFO_KHR,
286 .pNext = &ap->vp9_pic_info,
287 .flags = 0x0,
288 .pSetupReferenceSlot = &vp->ref_slot,
289 .referenceSlotCount = ref_count,
290 .pReferenceSlots = vp->ref_slots,
291 .dstPictureResource = (VkVideoPictureResourceInfoKHR) {
292 .sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,
293 .codedOffset = (VkOffset2D){ 0, 0 },
295 .baseArrayLayer = 0,
296 .imageViewBinding = vp->view.out[0],
297 },
298 };
299
300 ap->dec = dec;
301
302 return 0;
303 }
304
308 {
309 int err;
313
315 if (err < 0)
316 return err;
317
318 return 0;
319 }
320
322 {
324
329 AVFrame *rav[STD_VIDEO_VP9_REFS_PER_FRAME] = { 0 };
330
334
337 }
338
341
343 }
344
346 {
349
350 /* Free frame resources, this also destroys the session parameters. */
352 }
353
355 .
p.
name =
"vp9_vulkan",
371 };