Coverage Report

Created: 2026-05-23 07:06

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