Coverage Report

Created: 2026-09-04 06:43

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