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 :
12 : #include "vpx_ports/config.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 :
21 : extern void vp8_init_scan_order_mask();
22 :
23 0 : static void update_mode_info_border(MODE_INFO *mi, int rows, int cols)
24 : {
25 : int i;
26 0 : vpx_memset(mi - cols - 2, 0, sizeof(MODE_INFO) * (cols + 1));
27 :
28 0 : for (i = 0; i < rows; i++)
29 : {
30 : /* TODO(holmer): Bug? This updates the last element of each row
31 : * rather than the border element!
32 : */
33 0 : vpx_memset(&mi[i*cols-1], 0, sizeof(MODE_INFO));
34 : }
35 0 : }
36 :
37 0 : void vp8_de_alloc_frame_buffers(VP8_COMMON *oci)
38 : {
39 : int i;
40 :
41 0 : for (i = 0; i < NUM_YV12_BUFFERS; i++)
42 0 : vp8_yv12_de_alloc_frame_buffer(&oci->yv12_fb[i]);
43 :
44 0 : vp8_yv12_de_alloc_frame_buffer(&oci->temp_scale_frame);
45 0 : vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer);
46 :
47 0 : vpx_free(oci->above_context);
48 0 : vpx_free(oci->mip);
49 0 : vpx_free(oci->prev_mip);
50 :
51 0 : oci->above_context = 0;
52 0 : oci->mip = 0;
53 0 : oci->prev_mip = 0;
54 :
55 0 : }
56 :
57 0 : int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height)
58 : {
59 : int i;
60 :
61 0 : vp8_de_alloc_frame_buffers(oci);
62 :
63 : /* our internal buffers are always multiples of 16 */
64 0 : if ((width & 0xf) != 0)
65 0 : width += 16 - (width & 0xf);
66 :
67 0 : if ((height & 0xf) != 0)
68 0 : height += 16 - (height & 0xf);
69 :
70 :
71 0 : for (i = 0; i < NUM_YV12_BUFFERS; i++)
72 : {
73 0 : oci->fb_idx_ref_cnt[i] = 0;
74 0 : oci->yv12_fb[i].flags = 0;
75 0 : if (vp8_yv12_alloc_frame_buffer(&oci->yv12_fb[i], width, height, VP8BORDERINPIXELS) < 0)
76 : {
77 0 : vp8_de_alloc_frame_buffers(oci);
78 0 : return 1;
79 : }
80 : }
81 :
82 0 : oci->new_fb_idx = 0;
83 0 : oci->lst_fb_idx = 1;
84 0 : oci->gld_fb_idx = 2;
85 0 : oci->alt_fb_idx = 3;
86 :
87 0 : oci->fb_idx_ref_cnt[0] = 1;
88 0 : oci->fb_idx_ref_cnt[1] = 1;
89 0 : oci->fb_idx_ref_cnt[2] = 1;
90 0 : oci->fb_idx_ref_cnt[3] = 1;
91 :
92 0 : if (vp8_yv12_alloc_frame_buffer(&oci->temp_scale_frame, width, 16, VP8BORDERINPIXELS) < 0)
93 : {
94 0 : vp8_de_alloc_frame_buffers(oci);
95 0 : return 1;
96 : }
97 :
98 0 : if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer, width, height, VP8BORDERINPIXELS) < 0)
99 : {
100 0 : vp8_de_alloc_frame_buffers(oci);
101 0 : return 1;
102 : }
103 :
104 0 : oci->mb_rows = height >> 4;
105 0 : oci->mb_cols = width >> 4;
106 0 : oci->MBs = oci->mb_rows * oci->mb_cols;
107 0 : oci->mode_info_stride = oci->mb_cols + 1;
108 0 : oci->mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO));
109 :
110 0 : if (!oci->mip)
111 : {
112 0 : vp8_de_alloc_frame_buffers(oci);
113 0 : return 1;
114 : }
115 :
116 0 : oci->mi = oci->mip + oci->mode_info_stride + 1;
117 :
118 : /* allocate memory for last frame MODE_INFO array */
119 : #if CONFIG_ERROR_CONCEALMENT
120 : oci->prev_mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO));
121 :
122 : if (!oci->prev_mip)
123 : {
124 : vp8_de_alloc_frame_buffers(oci);
125 : return 1;
126 : }
127 :
128 : oci->prev_mi = oci->prev_mip + oci->mode_info_stride + 1;
129 : #else
130 0 : oci->prev_mip = NULL;
131 0 : oci->prev_mi = NULL;
132 : #endif
133 :
134 0 : oci->above_context = vpx_calloc(sizeof(ENTROPY_CONTEXT_PLANES) * oci->mb_cols, 1);
135 :
136 0 : if (!oci->above_context)
137 : {
138 0 : vp8_de_alloc_frame_buffers(oci);
139 0 : return 1;
140 : }
141 :
142 0 : update_mode_info_border(oci->mi, oci->mb_rows, oci->mb_cols);
143 : #if CONFIG_ERROR_CONCEALMENT
144 : update_mode_info_border(oci->prev_mi, oci->mb_rows, oci->mb_cols);
145 : #endif
146 :
147 0 : return 0;
148 : }
149 0 : void vp8_setup_version(VP8_COMMON *cm)
150 : {
151 0 : switch (cm->version)
152 : {
153 : case 0:
154 0 : cm->no_lpf = 0;
155 0 : cm->filter_type = NORMAL_LOOPFILTER;
156 0 : cm->use_bilinear_mc_filter = 0;
157 0 : cm->full_pixel = 0;
158 0 : break;
159 : case 1:
160 0 : cm->no_lpf = 0;
161 0 : cm->filter_type = SIMPLE_LOOPFILTER;
162 0 : cm->use_bilinear_mc_filter = 1;
163 0 : cm->full_pixel = 0;
164 0 : break;
165 : case 2:
166 0 : cm->no_lpf = 1;
167 0 : cm->filter_type = NORMAL_LOOPFILTER;
168 0 : cm->use_bilinear_mc_filter = 1;
169 0 : cm->full_pixel = 0;
170 0 : break;
171 : case 3:
172 0 : cm->no_lpf = 1;
173 0 : cm->filter_type = SIMPLE_LOOPFILTER;
174 0 : cm->use_bilinear_mc_filter = 1;
175 0 : cm->full_pixel = 1;
176 0 : break;
177 : default:
178 : /*4,5,6,7 are reserved for future use*/
179 0 : cm->no_lpf = 0;
180 0 : cm->filter_type = NORMAL_LOOPFILTER;
181 0 : cm->use_bilinear_mc_filter = 0;
182 0 : cm->full_pixel = 0;
183 0 : break;
184 : }
185 0 : }
186 0 : void vp8_create_common(VP8_COMMON *oci)
187 : {
188 0 : vp8_machine_specific_config(oci);
189 0 : vp8_default_coef_probs(oci);
190 0 : vp8_init_mbmode_probs(oci);
191 0 : vp8_default_bmode_probs(oci->fc.bmode_prob);
192 :
193 0 : oci->mb_no_coeff_skip = 1;
194 0 : oci->no_lpf = 0;
195 0 : oci->filter_type = NORMAL_LOOPFILTER;
196 0 : oci->use_bilinear_mc_filter = 0;
197 0 : oci->full_pixel = 0;
198 0 : oci->multi_token_partition = ONE_PARTITION;
199 0 : oci->clr_type = REG_YUV;
200 0 : oci->clamp_type = RECON_CLAMP_REQUIRED;
201 :
202 : /* Initialise reference frame sign bias structure to defaults */
203 0 : vpx_memset(oci->ref_frame_sign_bias, 0, sizeof(oci->ref_frame_sign_bias));
204 :
205 : /* Default disable buffer to buffer copying */
206 0 : oci->copy_buffer_to_gf = 0;
207 0 : oci->copy_buffer_to_arf = 0;
208 0 : }
209 :
210 0 : void vp8_remove_common(VP8_COMMON *oci)
211 : {
212 0 : vp8_de_alloc_frame_buffers(oci);
213 0 : }
214 :
215 0 : void vp8_initialize_common()
216 : {
217 0 : vp8_coef_tree_initialize();
218 :
219 0 : vp8_entropy_mode_init();
220 :
221 0 : vp8_init_scan_order_mask();
222 :
223 0 : }
|