Coverage Report

Created: 2025-08-28 07:12

/src/libvpx/vp8/common/alloccommon.c
Line
Count
Source (jump to first uncovered line)
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
32.5k
void vp8_de_alloc_frame_buffers(VP8_COMMON *oci) {
21
32.5k
  int i;
22
162k
  for (i = 0; i < NUM_YV12_BUFFERS; ++i) {
23
130k
    vp8_yv12_de_alloc_frame_buffer(&oci->yv12_fb[i]);
24
130k
  }
25
26
32.5k
  vp8_yv12_de_alloc_frame_buffer(&oci->temp_scale_frame);
27
32.5k
#if CONFIG_POSTPROC
28
32.5k
  vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer);
29
32.5k
  if (oci->post_proc_buffer_int_used) {
30
0
    vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer_int);
31
0
  }
32
33
32.5k
  vpx_free(oci->pp_limits_buffer);
34
32.5k
  oci->pp_limits_buffer = NULL;
35
36
32.5k
  vpx_free(oci->postproc_state.generated_noise);
37
32.5k
  oci->postproc_state.generated_noise = NULL;
38
32.5k
#endif
39
40
32.5k
  vpx_free(oci->above_context);
41
32.5k
  vpx_free(oci->mip);
42
#if CONFIG_ERROR_CONCEALMENT
43
  vpx_free(oci->prev_mip);
44
  oci->prev_mip = NULL;
45
#endif
46
47
32.5k
  oci->above_context = NULL;
48
32.5k
  oci->mip = NULL;
49
32.5k
}
50
51
13.2k
int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height) {
52
13.2k
  int i;
53
54
13.2k
  vp8_de_alloc_frame_buffers(oci);
55
56
  /* our internal buffers are always multiples of 16 */
57
13.2k
  if ((width & 0xf) != 0) width += 16 - (width & 0xf);
58
59
13.2k
  if ((height & 0xf) != 0) height += 16 - (height & 0xf);
60
61
66.3k
  for (i = 0; i < NUM_YV12_BUFFERS; ++i) {
62
53.0k
    oci->fb_idx_ref_cnt[i] = 0;
63
53.0k
    oci->yv12_fb[i].flags = 0;
64
53.0k
    if (vp8_yv12_alloc_frame_buffer(&oci->yv12_fb[i], width, height,
65
53.0k
                                    VP8BORDERINPIXELS) < 0) {
66
0
      goto allocation_fail;
67
0
    }
68
53.0k
  }
69
70
13.2k
  oci->new_fb_idx = 0;
71
13.2k
  oci->lst_fb_idx = 1;
72
13.2k
  oci->gld_fb_idx = 2;
73
13.2k
  oci->alt_fb_idx = 3;
74
75
13.2k
  oci->fb_idx_ref_cnt[0] = 1;
76
13.2k
  oci->fb_idx_ref_cnt[1] = 1;
77
13.2k
  oci->fb_idx_ref_cnt[2] = 1;
78
13.2k
  oci->fb_idx_ref_cnt[3] = 1;
79
80
13.2k
  if (vp8_yv12_alloc_frame_buffer(&oci->temp_scale_frame, width, 16,
81
13.2k
                                  VP8BORDERINPIXELS) < 0) {
82
0
    goto allocation_fail;
83
0
  }
84
85
13.2k
  oci->mb_rows = height >> 4;
86
13.2k
  oci->mb_cols = width >> 4;
87
13.2k
  oci->MBs = oci->mb_rows * oci->mb_cols;
88
13.2k
  oci->mode_info_stride = oci->mb_cols + 1;
89
13.2k
  oci->mip =
90
13.2k
      vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO));
91
92
13.2k
  if (!oci->mip) goto allocation_fail;
93
94
13.2k
  oci->mi = oci->mip + oci->mode_info_stride + 1;
95
96
  /* Allocation of previous mode info will be done in vp8_decode_frame()
97
   * as it is a decoder only data */
98
99
13.2k
  oci->above_context =
100
13.2k
      vpx_calloc(sizeof(ENTROPY_CONTEXT_PLANES) * oci->mb_cols, 1);
101
102
13.2k
  if (!oci->above_context) goto allocation_fail;
103
104
13.2k
#if CONFIG_POSTPROC
105
13.2k
  if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer, width, height,
106
13.2k
                                  VP8BORDERINPIXELS) < 0) {
107
0
    goto allocation_fail;
108
0
  }
109
110
13.2k
  oci->post_proc_buffer_int_used = 0;
111
13.2k
  memset(&oci->postproc_state, 0, sizeof(oci->postproc_state));
112
13.2k
  memset(oci->post_proc_buffer.buffer_alloc, 128,
113
13.2k
         oci->post_proc_buffer.frame_size);
114
115
  /* Allocate buffer to store post-processing filter coefficients.
116
   *
117
   * Note: Round up mb_cols to support SIMD reads
118
   */
119
13.2k
  oci->pp_limits_buffer = vpx_memalign(16, 24 * ((oci->mb_cols + 1) & ~1));
120
13.2k
  if (!oci->pp_limits_buffer) goto allocation_fail;
121
13.2k
#endif
122
123
13.2k
  return 0;
124
125
0
allocation_fail:
126
0
  vp8_de_alloc_frame_buffers(oci);
127
0
  return 1;
128
13.2k
}
129
130
42.8k
void vp8_setup_version(VP8_COMMON *cm) {
131
42.8k
  switch (cm->version) {
132
35.5k
    case 0:
133
35.5k
      cm->no_lpf = 0;
134
35.5k
      cm->filter_type = NORMAL_LOOPFILTER;
135
35.5k
      cm->use_bilinear_mc_filter = 0;
136
35.5k
      cm->full_pixel = 0;
137
35.5k
      break;
138
1.48k
    case 1:
139
1.48k
      cm->no_lpf = 0;
140
1.48k
      cm->filter_type = SIMPLE_LOOPFILTER;
141
1.48k
      cm->use_bilinear_mc_filter = 1;
142
1.48k
      cm->full_pixel = 0;
143
1.48k
      break;
144
210
    case 2:
145
210
      cm->no_lpf = 1;
146
210
      cm->filter_type = NORMAL_LOOPFILTER;
147
210
      cm->use_bilinear_mc_filter = 1;
148
210
      cm->full_pixel = 0;
149
210
      break;
150
3.85k
    case 3:
151
3.85k
      cm->no_lpf = 1;
152
3.85k
      cm->filter_type = SIMPLE_LOOPFILTER;
153
3.85k
      cm->use_bilinear_mc_filter = 1;
154
3.85k
      cm->full_pixel = 1;
155
3.85k
      break;
156
1.71k
    default:
157
      /*4,5,6,7 are reserved for future use*/
158
1.71k
      cm->no_lpf = 0;
159
1.71k
      cm->filter_type = NORMAL_LOOPFILTER;
160
1.71k
      cm->use_bilinear_mc_filter = 0;
161
1.71k
      cm->full_pixel = 0;
162
1.71k
      break;
163
42.8k
  }
164
42.8k
}
165
12.2k
void vp8_create_common(VP8_COMMON *oci) {
166
12.2k
  vp8_machine_specific_config(oci);
167
168
12.2k
  vp8_init_mbmode_probs(oci);
169
12.2k
  vp8_default_bmode_probs(oci->fc.bmode_prob);
170
171
12.2k
  oci->mb_no_coeff_skip = 1;
172
12.2k
  oci->no_lpf = 0;
173
12.2k
  oci->filter_type = NORMAL_LOOPFILTER;
174
12.2k
  oci->use_bilinear_mc_filter = 0;
175
12.2k
  oci->full_pixel = 0;
176
12.2k
  oci->multi_token_partition = ONE_PARTITION;
177
12.2k
  oci->clamp_type = RECON_CLAMP_REQUIRED;
178
179
  /* Initialize reference frame sign bias structure to defaults */
180
12.2k
  memset(oci->ref_frame_sign_bias, 0, sizeof(oci->ref_frame_sign_bias));
181
182
  /* Default disable buffer to buffer copying */
183
12.2k
  oci->copy_buffer_to_gf = 0;
184
12.2k
  oci->copy_buffer_to_arf = 0;
185
12.2k
}
186
187
12.2k
void vp8_remove_common(VP8_COMMON *oci) { vp8_de_alloc_frame_buffers(oci); }