Coverage Report

Created: 2026-11-12 07:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/contrib/contrib-build/libvpx/vp8/common/alloccommon.c
Line
Count
Source
1
/*
2
 *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5
 *  that can be found in the LICENSE file in the root of the source
6
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS.  All contributing project authors may
8
 *  be found in the AUTHORS file in the root of the source tree.
9
 */
10
11
#include "vpx_config.h"
12
#include "alloccommon.h"
13
#include "blockd.h"
14
#include "vpx_mem/vpx_mem.h"
15
#include "onyxc_int.h"
16
#include "findnearmv.h"
17
#include "entropymode.h"
18
#include "systemdependent.h"
19
20
// This function frees all frame and post processing buffers, as well as
21
// indirect references to them via context and mode info allocations.
22
535
void vp8_de_alloc_frame_buffers(VP8_COMMON *oci) {
23
535
  int i;
24
2.67k
  for (i = 0; i < NUM_YV12_BUFFERS; ++i) {
25
2.14k
    vp8_yv12_de_alloc_frame_buffer(&oci->yv12_fb[i]);
26
2.14k
    oci->fb_idx_ref_cnt[i] = 0;
27
2.14k
  }
28
29
535
  vp8_yv12_de_alloc_frame_buffer(&oci->temp_scale_frame);
30
535
#if CONFIG_POSTPROC
31
535
  vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer);
32
535
  if (oci->post_proc_buffer_int_used) {
33
0
    vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer_int);
34
0
    oci->post_proc_buffer_int_used = 0;
35
0
  }
36
37
535
  vpx_free(oci->pp_limits_buffer);
38
535
  oci->pp_limits_buffer = NULL;
39
40
535
  vpx_free(oci->postproc_state.generated_noise);
41
535
  memset(&oci->postproc_state, 0, sizeof(oci->postproc_state));
42
535
#endif
43
44
535
  vpx_free(oci->above_context);
45
535
  vpx_free(oci->mip);
46
#if CONFIG_ERROR_CONCEALMENT
47
  vpx_free(oci->prev_mip);
48
  oci->prev_mip = NULL;
49
  oci->prev_mi = NULL;
50
#endif
51
52
535
  oci->above_context = NULL;
53
535
  oci->mip = NULL;
54
535
  oci->mi = NULL;
55
535
  oci->show_frame_mi = NULL;
56
535
  oci->frame_to_show = NULL;
57
535
}
58
59
269
int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height) {
60
269
  int i;
61
62
269
  vp8_de_alloc_frame_buffers(oci);
63
64
  /* our internal buffers are always multiples of 16 */
65
269
  if ((width & 0xf) != 0) width += 16 - (width & 0xf);
66
67
269
  if ((height & 0xf) != 0) height += 16 - (height & 0xf);
68
69
1.34k
  for (i = 0; i < NUM_YV12_BUFFERS; ++i) {
70
1.07k
    if (vp8_yv12_alloc_frame_buffer(&oci->yv12_fb[i], width, height,
71
1.07k
                                    VP8BORDERINPIXELS) < 0) {
72
0
      goto allocation_fail;
73
0
    }
74
1.07k
  }
75
76
269
  oci->new_fb_idx = 0;
77
269
  oci->lst_fb_idx = 1;
78
269
  oci->gld_fb_idx = 2;
79
269
  oci->alt_fb_idx = 3;
80
81
269
  oci->fb_idx_ref_cnt[0] = 1;
82
269
  oci->fb_idx_ref_cnt[1] = 1;
83
269
  oci->fb_idx_ref_cnt[2] = 1;
84
269
  oci->fb_idx_ref_cnt[3] = 1;
85
86
269
  if (vp8_yv12_alloc_frame_buffer(&oci->temp_scale_frame, width, 16,
87
269
                                  VP8BORDERINPIXELS) < 0) {
88
0
    goto allocation_fail;
89
0
  }
90
91
269
  oci->mb_rows = height >> 4;
92
269
  oci->mb_cols = width >> 4;
93
269
  oci->MBs = oci->mb_rows * oci->mb_cols;
94
269
  oci->mode_info_stride = oci->mb_cols + 1;
95
269
  oci->mip =
96
269
      vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO));
97
98
269
  if (!oci->mip) goto allocation_fail;
99
100
269
  oci->mi = oci->mip + oci->mode_info_stride + 1;
101
102
  /* Allocation of previous mode info will be done in vp8_decode_frame()
103
   * as it is a decoder only data */
104
105
269
  oci->above_context =
106
269
      vpx_calloc(sizeof(ENTROPY_CONTEXT_PLANES) * oci->mb_cols, 1);
107
108
269
  if (!oci->above_context) goto allocation_fail;
109
110
269
#if CONFIG_POSTPROC
111
269
  if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer, width, height,
112
269
                                  VP8BORDERINPIXELS) < 0) {
113
0
    goto allocation_fail;
114
0
  }
115
116
269
  memset(oci->post_proc_buffer.buffer_alloc, 128,
117
269
         oci->post_proc_buffer.frame_size);
118
119
  /* Allocate buffer to store post-processing filter coefficients.
120
   *
121
   * Note: Round up mb_cols to support SIMD reads
122
   */
123
269
  oci->pp_limits_buffer = vpx_memalign(16, 24 * ((oci->mb_cols + 1) & ~1));
124
269
  if (!oci->pp_limits_buffer) goto allocation_fail;
125
269
#endif
126
127
269
  return 0;
128
129
0
allocation_fail:
130
0
  vp8_de_alloc_frame_buffers(oci);
131
0
  return 1;
132
269
}
133
134
4.21k
void vp8_setup_version(VP8_COMMON *cm) {
135
4.21k
  switch (cm->version) {
136
3.93k
    case 0:
137
3.93k
      cm->no_lpf = 0;
138
3.93k
      cm->filter_type = NORMAL_LOOPFILTER;
139
3.93k
      cm->use_bilinear_mc_filter = 0;
140
3.93k
      cm->full_pixel = 0;
141
3.93k
      break;
142
8
    case 1:
143
8
      cm->no_lpf = 0;
144
8
      cm->filter_type = SIMPLE_LOOPFILTER;
145
8
      cm->use_bilinear_mc_filter = 1;
146
8
      cm->full_pixel = 0;
147
8
      break;
148
95
    case 2:
149
95
      cm->no_lpf = 1;
150
95
      cm->filter_type = NORMAL_LOOPFILTER;
151
95
      cm->use_bilinear_mc_filter = 1;
152
95
      cm->full_pixel = 0;
153
95
      break;
154
41
    case 3:
155
41
      cm->no_lpf = 1;
156
41
      cm->filter_type = SIMPLE_LOOPFILTER;
157
41
      cm->use_bilinear_mc_filter = 1;
158
41
      cm->full_pixel = 1;
159
41
      break;
160
130
    default:
161
      /*4,5,6,7 are reserved for future use*/
162
130
      cm->no_lpf = 0;
163
130
      cm->filter_type = NORMAL_LOOPFILTER;
164
130
      cm->use_bilinear_mc_filter = 0;
165
130
      cm->full_pixel = 0;
166
130
      break;
167
4.21k
  }
168
4.21k
}
169
266
void vp8_create_common(VP8_COMMON *oci) {
170
266
  vp8_machine_specific_config(oci);
171
172
266
  vp8_init_mbmode_probs(oci);
173
266
  vp8_default_bmode_probs(oci->fc.bmode_prob);
174
175
266
  oci->mb_no_coeff_skip = 1;
176
266
  oci->no_lpf = 0;
177
266
  oci->filter_type = NORMAL_LOOPFILTER;
178
266
  oci->use_bilinear_mc_filter = 0;
179
266
  oci->full_pixel = 0;
180
266
  oci->multi_token_partition = ONE_PARTITION;
181
266
  oci->clamp_type = RECON_CLAMP_REQUIRED;
182
183
  /* Initialize reference frame sign bias structure to defaults */
184
266
  memset(oci->ref_frame_sign_bias, 0, sizeof(oci->ref_frame_sign_bias));
185
186
  /* Default disable buffer to buffer copying */
187
266
  oci->copy_buffer_to_gf = 0;
188
266
  oci->copy_buffer_to_arf = 0;
189
266
}
190
191
266
void vp8_remove_common(VP8_COMMON *oci) { vp8_de_alloc_frame_buffers(oci); }