Coverage Report

Created: 2026-10-17 07:46

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
360
void vp8_de_alloc_frame_buffers(VP8_COMMON *oci) {
23
360
  int i;
24
1.80k
  for (i = 0; i < NUM_YV12_BUFFERS; ++i) {
25
1.44k
    vp8_yv12_de_alloc_frame_buffer(&oci->yv12_fb[i]);
26
1.44k
    oci->fb_idx_ref_cnt[i] = 0;
27
1.44k
  }
28
29
360
  vp8_yv12_de_alloc_frame_buffer(&oci->temp_scale_frame);
30
360
#if CONFIG_POSTPROC
31
360
  vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer);
32
360
  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
360
  vpx_free(oci->pp_limits_buffer);
38
360
  oci->pp_limits_buffer = NULL;
39
40
360
  vpx_free(oci->postproc_state.generated_noise);
41
360
  memset(&oci->postproc_state, 0, sizeof(oci->postproc_state));
42
360
#endif
43
44
360
  vpx_free(oci->above_context);
45
360
  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
360
  oci->above_context = NULL;
53
360
  oci->mip = NULL;
54
360
  oci->mi = NULL;
55
360
  oci->show_frame_mi = NULL;
56
360
  oci->frame_to_show = NULL;
57
360
}
58
59
181
int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height) {
60
181
  int i;
61
62
181
  vp8_de_alloc_frame_buffers(oci);
63
64
  /* our internal buffers are always multiples of 16 */
65
181
  if ((width & 0xf) != 0) width += 16 - (width & 0xf);
66
67
181
  if ((height & 0xf) != 0) height += 16 - (height & 0xf);
68
69
905
  for (i = 0; i < NUM_YV12_BUFFERS; ++i) {
70
724
    if (vp8_yv12_alloc_frame_buffer(&oci->yv12_fb[i], width, height,
71
724
                                    VP8BORDERINPIXELS) < 0) {
72
0
      goto allocation_fail;
73
0
    }
74
724
  }
75
76
181
  oci->new_fb_idx = 0;
77
181
  oci->lst_fb_idx = 1;
78
181
  oci->gld_fb_idx = 2;
79
181
  oci->alt_fb_idx = 3;
80
81
181
  oci->fb_idx_ref_cnt[0] = 1;
82
181
  oci->fb_idx_ref_cnt[1] = 1;
83
181
  oci->fb_idx_ref_cnt[2] = 1;
84
181
  oci->fb_idx_ref_cnt[3] = 1;
85
86
181
  if (vp8_yv12_alloc_frame_buffer(&oci->temp_scale_frame, width, 16,
87
181
                                  VP8BORDERINPIXELS) < 0) {
88
0
    goto allocation_fail;
89
0
  }
90
91
181
  oci->mb_rows = height >> 4;
92
181
  oci->mb_cols = width >> 4;
93
181
  oci->MBs = oci->mb_rows * oci->mb_cols;
94
181
  oci->mode_info_stride = oci->mb_cols + 1;
95
181
  oci->mip =
96
181
      vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO));
97
98
181
  if (!oci->mip) goto allocation_fail;
99
100
181
  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
181
  oci->above_context =
106
181
      vpx_calloc(sizeof(ENTROPY_CONTEXT_PLANES) * oci->mb_cols, 1);
107
108
181
  if (!oci->above_context) goto allocation_fail;
109
110
181
#if CONFIG_POSTPROC
111
181
  if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer, width, height,
112
181
                                  VP8BORDERINPIXELS) < 0) {
113
0
    goto allocation_fail;
114
0
  }
115
116
181
  memset(oci->post_proc_buffer.buffer_alloc, 128,
117
181
         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
181
  oci->pp_limits_buffer = vpx_memalign(16, 24 * ((oci->mb_cols + 1) & ~1));
124
181
  if (!oci->pp_limits_buffer) goto allocation_fail;
125
181
#endif
126
127
181
  return 0;
128
129
0
allocation_fail:
130
0
  vp8_de_alloc_frame_buffers(oci);
131
0
  return 1;
132
181
}
133
134
3.86k
void vp8_setup_version(VP8_COMMON *cm) {
135
3.86k
  switch (cm->version) {
136
3.69k
    case 0:
137
3.69k
      cm->no_lpf = 0;
138
3.69k
      cm->filter_type = NORMAL_LOOPFILTER;
139
3.69k
      cm->use_bilinear_mc_filter = 0;
140
3.69k
      cm->full_pixel = 0;
141
3.69k
      break;
142
2
    case 1:
143
2
      cm->no_lpf = 0;
144
2
      cm->filter_type = SIMPLE_LOOPFILTER;
145
2
      cm->use_bilinear_mc_filter = 1;
146
2
      cm->full_pixel = 0;
147
2
      break;
148
20
    case 2:
149
20
      cm->no_lpf = 1;
150
20
      cm->filter_type = NORMAL_LOOPFILTER;
151
20
      cm->use_bilinear_mc_filter = 1;
152
20
      cm->full_pixel = 0;
153
20
      break;
154
14
    case 3:
155
14
      cm->no_lpf = 1;
156
14
      cm->filter_type = SIMPLE_LOOPFILTER;
157
14
      cm->use_bilinear_mc_filter = 1;
158
14
      cm->full_pixel = 1;
159
14
      break;
160
137
    default:
161
      /*4,5,6,7 are reserved for future use*/
162
137
      cm->no_lpf = 0;
163
137
      cm->filter_type = NORMAL_LOOPFILTER;
164
137
      cm->use_bilinear_mc_filter = 0;
165
137
      cm->full_pixel = 0;
166
137
      break;
167
3.86k
  }
168
3.86k
}
169
179
void vp8_create_common(VP8_COMMON *oci) {
170
179
  vp8_machine_specific_config(oci);
171
172
179
  vp8_init_mbmode_probs(oci);
173
179
  vp8_default_bmode_probs(oci->fc.bmode_prob);
174
175
179
  oci->mb_no_coeff_skip = 1;
176
179
  oci->no_lpf = 0;
177
179
  oci->filter_type = NORMAL_LOOPFILTER;
178
179
  oci->use_bilinear_mc_filter = 0;
179
179
  oci->full_pixel = 0;
180
179
  oci->multi_token_partition = ONE_PARTITION;
181
179
  oci->clamp_type = RECON_CLAMP_REQUIRED;
182
183
  /* Initialize reference frame sign bias structure to defaults */
184
179
  memset(oci->ref_frame_sign_bias, 0, sizeof(oci->ref_frame_sign_bias));
185
186
  /* Default disable buffer to buffer copying */
187
179
  oci->copy_buffer_to_gf = 0;
188
179
  oci->copy_buffer_to_arf = 0;
189
179
}
190
191
179
void vp8_remove_common(VP8_COMMON *oci) { vp8_de_alloc_frame_buffers(oci); }