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