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