Bug Summary

File:root/firefox-clang/media/ffvpx/libavcodec/vulkan_vp9.c
Warning:line 142, column 9
Value stored to 'frame_id_alloc_mask' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -O2 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name vulkan_vp9.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -ffp-contract=off -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/media/ffvpx/libavcodec -fcoverage-compilation-dir=/root/firefox-clang/obj-x86_64-pc-linux-gnu/media/ffvpx/libavcodec -resource-dir /usr/lib/llvm-23/lib/clang/23 -include /root/firefox-clang/obj-x86_64-pc-linux-gnu/mozilla-config.h -include libavutil_visibility.h -U _FORTIFY_SOURCE -D _FORTIFY_SOURCE=2 -D DEBUG=1 -D HAVE_AV_CONFIG_H -D ASSERT_LEVEL=2 -I /root/firefox-clang/media/ffvpx/libavcodec -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/media/ffvpx/libavcodec -I /root/firefox-clang/modules/fdlibm/inexact-math-override -I /root/firefox-clang/third_party/khronos/vulkan-headers/include -I /root/firefox-clang/media/mozva -I /root/firefox-clang/media/libopus/include -I /root/firefox-clang/media/libvorbis -I /root/firefox-clang/media/libvpx -I /root/firefox-clang/media/ffvpx -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nspr -I /root/firefox-clang/obj-x86_64-pc-linux-gnu/dist/include/nss -D MOZILLA_CLIENT -internal-isystem /usr/lib/llvm-23/lib/clang/23/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-error=tautological-type-limit-compare -Wno-range-loop-analysis -Wno-error=deprecated-declarations -Wno-error=array-bounds -Wno-error=free-nonheap-object -Wno-error=atomic-alignment -Wno-error=deprecated-builtins -Wno-psabi -Wno-error=builtin-macro-redefined -Wno-unknown-warning-option -Wno-character-conversion -Wno-parentheses -Wno-pointer-sign -Wno-sign-compare -Wno-switch -Wno-type-limits -Wno-unused-function -Wno-deprecated-declarations -Wno-absolute-value -Wno-incompatible-pointer-types -Wno-string-conversion -Wno-visibility -ferror-limit 19 -fstrict-flex-arrays=1 -stack-protector 2 -fstack-clash-protection -ftrivial-auto-var-init=pattern -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fdiagnostics-absolute-paths -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -mllvm -dwarf-linkage-names=Abstract -faddrsig -fdwarf2-cfi-asm -o /tmp/scan-build-2026-09-01-224014-2642839-1 -x c /root/firefox-clang/media/ffvpx/libavcodec/vulkan_vp9.c
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 "vp9dec.h"
20
21#include "vulkan_decode.h"
22
23const FFVulkanDecodeDescriptor ff_vk_dec_vp9_desc = {
24 .codec_id = AV_CODEC_ID_VP9,
25 .decode_extension = FF_VK_EXT_VIDEO_DECODE_VP9(1ULL << 43),
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"VK_STD_vulkan_video_codec_vp9_decode",
30 .specVersion = VK_STD_VULKAN_VIDEO_CODEC_VP9_DECODE_SPEC_VERSION((((uint32_t)(1)) << 22) | (((uint32_t)(0)) << 12
) | ((uint32_t)(0)))
,
31 },
32};
33
34typedef struct VP9VulkanDecodePicture {
35 FFVulkanDecodePicture vp;
36
37 /* TODO: investigate if this can be removed to make decoding completely
38 * independent. */
39 FFVulkanDecodeContext *dec;
40
41 /* Current picture */
42 StdVideoVP9ColorConfig color_config;
43 StdVideoVP9Segmentation segmentation;
44 StdVideoVP9LoopFilter loop_filter;
45 StdVideoDecodeVP9PictureInfo std_pic_info;
46 VkVideoDecodeVP9PictureInfoKHR vp9_pic_info;
47
48 const VP9Frame *ref_src[8];
49
50 uint8_t frame_id_set;
51 uint8_t frame_id;
52 uint8_t ref_frame_sign_bias_mask;
53} VP9VulkanDecodePicture;
54
55static int vk_vp9_fill_pict(AVCodecContext *avctx, const VP9Frame **ref_src,
56 VkVideoReferenceSlotInfoKHR *ref_slot, /* Main structure */
57 VkVideoPictureResourceInfoKHR *ref, /* Goes in ^ */
58 const VP9Frame *pic, int is_current)
59{
60 FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
61 FFVulkanDecodeShared *ctx = dec->shared_ctx;
62 VP9VulkanDecodePicture *hp = pic->hwaccel_picture_private;
63 FFVulkanDecodePicture *vkpic = &hp->vp;
64
65 int err = ff_vk_decode_prepare_frame(dec, pic->tf.f, vkpic, is_current,
66 dec->dedicated_dpb);
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 },
73 .codedExtent = (VkExtent2D){ pic->tf.f->width, pic->tf.f->height },
74 .baseArrayLayer = (dec->dedicated_dpb && ctx->common.layered_dpb) ?
75 hp->frame_id : 0,
76 .imageViewBinding = vkpic->view.ref[0],
77 };
78
79 *ref_slot = (VkVideoReferenceSlotInfoKHR) {
80 .sType = VK_STRUCTURE_TYPE_VIDEO_REFERENCE_SLOT_INFO_KHR,
81 .slotIndex = hp->frame_id,
82 .pPictureResource = ref,
83 };
84
85 if (ref_src)
86 *ref_src = pic;
87
88 return 0;
89}
90
91static 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
105static int vk_vp9_start_frame(AVCodecContext *avctx,
106 av_unused__attribute__((unused)) const AVBufferRef *buffer_ref,
107 av_unused__attribute__((unused)) const uint8_t *buffer,
108 av_unused__attribute__((unused)) uint32_t size)
109{
110 int err;
111 int ref_count = 0;
112 const VP9Context *priv = avctx->priv_data;
113 const CodedBitstreamVP9Context *vp9 = priv->cbc->priv_data;
114 const VP9SharedContext *s = &priv->s;
115 uint32_t frame_id_alloc_mask = 0;
116
117 const VP9Frame *pic = &s->frames[CUR_FRAME0];
118 const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->sw_pix_fmt);
119 FFVulkanDecodeContext *dec = avctx->internal->hwaccel_priv_data;
120 uint8_t profile = (pic->frame_header->profile_high_bit << 1) | pic->frame_header->profile_low_bit;
121
122 VP9VulkanDecodePicture *ap = pic->hwaccel_picture_private;
123 FFVulkanDecodePicture *vp = &ap->vp;
124
125 /* Use the current frame_ids in ref_frames[] to decide occupied frame_ids */
126 for (int i = 0; i < STD_VIDEO_VP9_NUM_REF_FRAMES8U; i++) {
127 const VP9VulkanDecodePicture* rp = s->ref_frames[i].hwaccel_picture_private;
128 if (rp)
129 frame_id_alloc_mask |= 1 << rp->frame_id;
130 }
131
132 if (!ap->frame_id_set) {
133 unsigned slot_idx = 0;
134 for (unsigned i = 0; i < 32; i++) {
135 if (!(frame_id_alloc_mask & (1 << i))) {
136 slot_idx = i;
137 break;
138 }
139 }
140 ap->frame_id = slot_idx;
141 ap->frame_id_set = 1;
142 frame_id_alloc_mask |= (1 << slot_idx);
Value stored to 'frame_id_alloc_mask' is never read
143 }
144
145 for (int i = 0; i < STD_VIDEO_VP9_REFS_PER_FRAME3U; i++) {
146 const int idx = pic->frame_header->ref_frame_idx[i];
147 const VP9Frame *ref_frame = &s->ref_frames[idx];
148 VP9VulkanDecodePicture *hp = ref_frame->hwaccel_picture_private;
149 int found = 0;
150
151 if (!ref_frame->tf.f)
152 continue;
153
154 for (int j = 0; j < ref_count; j++) {
155 if (vp->ref_slots[j].slotIndex == hp->frame_id) {
156 found = 1;
157 break;
158 }
159 }
160 if (found)
161 continue;
162
163 err = vk_vp9_fill_pict(avctx, &ap->ref_src[ref_count],
164 &vp->ref_slots[ref_count], &vp->refs[ref_count],
165 ref_frame, 0);
166 if (err < 0)
167 return err;
168
169 ref_count++;
170 }
171
172 err = vk_vp9_fill_pict(avctx, NULL((void*)0), &vp->ref_slot, &vp->ref,
173 pic, 1);
174 if (err < 0)
175 return err;
176
177 ap->loop_filter = (StdVideoVP9LoopFilter) {
178 .flags = (StdVideoVP9LoopFilterFlags) {
179 .loop_filter_delta_enabled = pic->frame_header->loop_filter_delta_enabled,
180 .loop_filter_delta_update = pic->frame_header->loop_filter_delta_update,
181 },
182 .loop_filter_level = pic->frame_header->loop_filter_level,
183 .loop_filter_sharpness = pic->frame_header->loop_filter_sharpness,
184 .update_ref_delta = 0x0,
185 .update_mode_delta = 0x0,
186 };
187
188 for (int i = 0; i < STD_VIDEO_VP9_MAX_REF_FRAMES4U; i++) {
189 ap->loop_filter.loop_filter_ref_deltas[i] = vp9->loop_filter_ref_deltas[i];
190 ap->loop_filter.update_ref_delta |= pic->frame_header->update_ref_delta[i];
191 }
192 for (int i = 0; i < STD_VIDEO_VP9_LOOP_FILTER_ADJUSTMENTS2U; i++) {
193 ap->loop_filter.loop_filter_mode_deltas[i] = vp9->loop_filter_mode_deltas[i];
194 ap->loop_filter.update_mode_delta |= pic->frame_header->update_mode_delta[i];
195 }
196
197 ap->segmentation = (StdVideoVP9Segmentation) {
198 .flags = (StdVideoVP9SegmentationFlags) {
199 .segmentation_update_map = pic->frame_header->segmentation_update_map,
200 .segmentation_temporal_update = pic->frame_header->segmentation_temporal_update,
201 .segmentation_update_data = pic->frame_header->segmentation_update_data,
202 .segmentation_abs_or_delta_update = pic->frame_header->segmentation_abs_or_delta_update,
203 },
204 };
205
206 for (int i = 0; i < STD_VIDEO_VP9_MAX_SEGMENTATION_TREE_PROBS7U; i++)
207 ap->segmentation.segmentation_tree_probs[i] = vp9->segmentation_tree_probs[i];
208 for (int i = 0; i < STD_VIDEO_VP9_MAX_SEGMENTATION_PRED_PROB3U; i++)
209 ap->segmentation.segmentation_pred_prob[i] = vp9->segmentation_pred_prob[i];
210 for (int i = 0; i < STD_VIDEO_VP9_MAX_SEGMENTS8U; i++) {
211 ap->segmentation.FeatureEnabled[i] = 0x0;
212 for (int j = 0; j < STD_VIDEO_VP9_SEG_LVL_MAX4U; j++) {
213 ap->segmentation.FeatureEnabled[i] |= vp9->feature_enabled[i][j] << j;
214 ap->segmentation.FeatureData[i][j] = vp9->feature_sign[i][j] ?
215 -vp9->feature_value[i][j] :
216 +vp9->feature_value[i][j];
217 }
218 }
219
220 ap->color_config = (StdVideoVP9ColorConfig) {
221 .flags = (StdVideoVP9ColorConfigFlags) {
222 .color_range = pic->frame_header->color_range,
223 },
224 .BitDepth = profile < 2 ? 8 :
225 pic->frame_header->ten_or_twelve_bit ? 12 : 10,
226 .subsampling_x = pixdesc->log2_chroma_w,
227 .subsampling_y = pixdesc->log2_chroma_h,
228
229 .color_space = pic->frame_header->color_space,
230 };
231
232 ap->std_pic_info = (StdVideoDecodeVP9PictureInfo) {
233 .flags = (StdVideoDecodeVP9PictureInfoFlags) {
234 .error_resilient_mode = pic->frame_header->error_resilient_mode,
235 .intra_only = pic->frame_header->intra_only,
236 .allow_high_precision_mv = pic->frame_header->allow_high_precision_mv,
237 .refresh_frame_context = pic->frame_header->refresh_frame_context,
238 .frame_parallel_decoding_mode = pic->frame_header->frame_parallel_decoding_mode,
239 .segmentation_enabled = pic->frame_header->segmentation_enabled,
240 .show_frame = !s->h.invisible,
241 .UsePrevFrameMvs = s->h.use_last_frame_mvs,
242 },
243 .profile = profile,
244 .frame_type = pic->frame_header->frame_type,
245 .frame_context_idx = pic->frame_header->frame_context_idx,
246 .reset_frame_context = pic->frame_header->reset_frame_context,
247 .refresh_frame_flags = pic->frame_header->refresh_frame_flags,
248 .ref_frame_sign_bias_mask = 0x0,
249 .interpolation_filter = remap_interp(pic->frame_header->is_filter_switchable,
250 pic->frame_header->raw_interpolation_filter_type),
251 .base_q_idx = pic->frame_header->base_q_idx,
252 .delta_q_y_dc = pic->frame_header->delta_q_y_dc,
253 .delta_q_uv_dc = pic->frame_header->delta_q_uv_dc,
254 .delta_q_uv_ac = pic->frame_header->delta_q_uv_ac,
255 .tile_cols_log2 = pic->frame_header->tile_cols_log2,
256 .tile_rows_log2 = pic->frame_header->tile_rows_log2,
257 /* Reserved */
258 .pColorConfig = &ap->color_config,
259 .pLoopFilter = &ap->loop_filter,
260 .pSegmentation = &ap->segmentation,
261 };
262
263 for (int i = VP9_LAST_FRAME; i <= VP9_ALTREF_FRAME; i++)
264 ap->std_pic_info.ref_frame_sign_bias_mask |= pic->frame_header->ref_frame_sign_bias[i] << i;
265
266 ap->vp9_pic_info = (VkVideoDecodeVP9PictureInfoKHR) {
267 .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_VP9_PICTURE_INFO_KHR,
268 .pStdPictureInfo = &ap->std_pic_info,
269 .uncompressedHeaderOffset = 0,
270 .compressedHeaderOffset = s->h.uncompressed_header_size,
271 .tilesOffset = s->h.uncompressed_header_size +
272 s->h.compressed_header_size,
273 };
274
275 for (int i = 0; i < STD_VIDEO_VP9_REFS_PER_FRAME3U; i++) {
276 const int idx = pic->frame_header->ref_frame_idx[i];
277 const VP9Frame *ref_frame = &s->ref_frames[idx];
278 VP9VulkanDecodePicture *hp = ref_frame->hwaccel_picture_private;
279
280 if (!ref_frame->tf.f)
281 ap->vp9_pic_info.referenceNameSlotIndices[i] = -1;
282 else
283 ap->vp9_pic_info.referenceNameSlotIndices[i] = hp->frame_id;
284 }
285
286 vp->decode_info = (VkVideoDecodeInfoKHR) {
287 .sType = VK_STRUCTURE_TYPE_VIDEO_DECODE_INFO_KHR,
288 .pNext = &ap->vp9_pic_info,
289 .flags = 0x0,
290 .pSetupReferenceSlot = &vp->ref_slot,
291 .referenceSlotCount = ref_count,
292 .pReferenceSlots = vp->ref_slots,
293 .dstPictureResource = (VkVideoPictureResourceInfoKHR) {
294 .sType = VK_STRUCTURE_TYPE_VIDEO_PICTURE_RESOURCE_INFO_KHR,
295 .codedOffset = (VkOffset2D){ 0, 0 },
296 .codedExtent = (VkExtent2D){ pic->tf.f->width, pic->tf.f->height },
297 .baseArrayLayer = 0,
298 .imageViewBinding = vp->view.out[0],
299 },
300 };
301
302 ap->dec = dec;
303
304 return 0;
305}
306
307static int vk_vp9_decode_slice(AVCodecContext *avctx,
308 const uint8_t *data,
309 uint32_t size)
310{
311 int err;
312 const VP9SharedContext *s = avctx->priv_data;
313 VP9VulkanDecodePicture *ap = s->frames[CUR_FRAME0].hwaccel_picture_private;
314 FFVulkanDecodePicture *vp = &ap->vp;
315
316 err = ff_vk_decode_add_slice(avctx, vp, data, size, 0, NULL((void*)0), NULL((void*)0));
317 if (err < 0)
318 return err;
319
320 return 0;
321}
322
323static int vk_vp9_end_frame(AVCodecContext *avctx)
324{
325 const VP9SharedContext *s = avctx->priv_data;
326
327 const VP9Frame *pic = &s->frames[CUR_FRAME0];
328 VP9VulkanDecodePicture *ap = pic->hwaccel_picture_private;
329 FFVulkanDecodePicture *vp = &ap->vp;
330 FFVulkanDecodePicture *rvp[STD_VIDEO_VP9_REFS_PER_FRAME3U] = { 0 };
331 AVFrame *rav[STD_VIDEO_VP9_REFS_PER_FRAME3U] = { 0 };
332
333 for (int i = 0; i < vp->decode_info.referenceSlotCount; i++) {
334 const VP9Frame *rp = ap->ref_src[i];
335 VP9VulkanDecodePicture *rhp = rp->hwaccel_picture_private;
336
337 rvp[i] = &rhp->vp;
338 rav[i] = ap->ref_src[i]->tf.f;
339 }
340
341 av_log(avctx, AV_LOG_VERBOSE40, "Decoding frame, %zu bytes\n",
342 vp->slices_size);
343
344 return ff_vk_decode_frame(avctx, pic->tf.f, vp, rav, rvp);
345}
346
347static void vk_vp9_free_frame_priv(AVRefStructOpaque _hwctx, void *data)
348{
349 AVHWDeviceContext *hwctx = _hwctx.nc;
350 VP9VulkanDecodePicture *ap = data;
351
352 /* Free frame resources, this also destroys the session parameters. */
353 ff_vk_decode_free_frame(hwctx, &ap->vp);
354}
355
356const FFHWAccel ff_vp9_vulkan_hwaccel = {
357 .p.name = "vp9_vulkan",
358 .p.type = AVMEDIA_TYPE_VIDEO,
359 .p.id = AV_CODEC_ID_VP9,
360 .p.pix_fmt = AV_PIX_FMT_VULKAN,
361 .start_frame = &vk_vp9_start_frame,
362 .decode_slice = &vk_vp9_decode_slice,
363 .end_frame = &vk_vp9_end_frame,
364 .free_frame_priv = &vk_vp9_free_frame_priv,
365 .frame_priv_data_size = sizeof(VP9VulkanDecodePicture),
366 .init = &ff_vk_decode_init,
367 .update_thread_context = &ff_vk_update_thread_context,
368 .uninit = &ff_vk_decode_uninit,
369 .frame_params = &ff_vk_frame_params,
370 .priv_data_size = sizeof(FFVulkanDecodeContext),
371 .caps_internal = HWACCEL_CAP_ASYNC_SAFE(1 << 0),
372};