2 * Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
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.
12 #include "vpx_ports/config.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 #include "vpxerrors.h"
22 extern void vp8_init_scan_order_mask();
24 void vp8_update_mode_info_border(MODE_INFO *mi, int rows, int cols)
27 vpx_memset(mi - cols - 1, 0, sizeof(MODE_INFO) * cols + 1);
29 for (i = 0; i < rows; i++)
31 vpx_memset(&mi[i*cols-1], 0, sizeof(MODE_INFO));
35 void vp8_de_alloc_frame_buffers(VP8_COMMON *oci)
39 for (i = 0; i < NUM_YV12_BUFFERS; i++)
40 vp8_yv12_de_alloc_frame_buffer(&oci->yv12_fb[i]);
42 vp8_yv12_de_alloc_frame_buffer(&oci->temp_scale_frame);
43 vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer);
45 vpx_free(oci->above_context[Y1CONTEXT]);
46 vpx_free(oci->above_context[UCONTEXT]);
47 vpx_free(oci->above_context[VCONTEXT]);
48 vpx_free(oci->above_context[Y2CONTEXT]);
51 oci->above_context[Y1CONTEXT] = 0;
52 oci->above_context[UCONTEXT] = 0;
53 oci->above_context[VCONTEXT] = 0;
54 oci->above_context[Y2CONTEXT] = 0;
57 // Structure used to minitor GF useage
58 if (oci->gf_active_flags != 0)
59 vpx_free(oci->gf_active_flags);
61 oci->gf_active_flags = 0;
64 int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height)
68 vp8_de_alloc_frame_buffers(oci);
70 // our internal buffers are always multiples of 16
71 if ((width & 0xf) != 0)
72 width += 16 - (width & 0xf);
74 if ((height & 0xf) != 0)
75 height += 16 - (height & 0xf);
78 for (i = 0; i < NUM_YV12_BUFFERS; i++)
80 oci->fb_idx_ref_cnt[0] = 0;
82 if (vp8_yv12_alloc_frame_buffer(&oci->yv12_fb[i], width, height, VP8BORDERINPIXELS) < 0)
84 vp8_de_alloc_frame_buffers(oci);
94 oci->fb_idx_ref_cnt[0] = 1;
95 oci->fb_idx_ref_cnt[1] = 1;
96 oci->fb_idx_ref_cnt[2] = 1;
97 oci->fb_idx_ref_cnt[3] = 1;
99 if (vp8_yv12_alloc_frame_buffer(&oci->temp_scale_frame, width, 16, VP8BORDERINPIXELS) < 0)
101 vp8_de_alloc_frame_buffers(oci);
102 return ALLOC_FAILURE;
105 if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer, width, height, VP8BORDERINPIXELS) < 0)
107 vp8_de_alloc_frame_buffers(oci);
108 return ALLOC_FAILURE;
111 oci->mb_rows = height >> 4;
112 oci->mb_cols = width >> 4;
113 oci->MBs = oci->mb_rows * oci->mb_cols;
114 oci->mode_info_stride = oci->mb_cols + 1;
115 oci->mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO));
119 vp8_de_alloc_frame_buffers(oci);
120 return ALLOC_FAILURE;
123 oci->mi = oci->mip + oci->mode_info_stride + 1;
126 oci->above_context[Y1CONTEXT] = vpx_calloc(sizeof(ENTROPY_CONTEXT) * oci->mb_cols * 4 , 1);
128 if (!oci->above_context[Y1CONTEXT])
130 vp8_de_alloc_frame_buffers(oci);
131 return ALLOC_FAILURE;
134 oci->above_context[UCONTEXT] = vpx_calloc(sizeof(ENTROPY_CONTEXT) * oci->mb_cols * 2 , 1);
136 if (!oci->above_context[UCONTEXT])
138 vp8_de_alloc_frame_buffers(oci);
139 return ALLOC_FAILURE;
142 oci->above_context[VCONTEXT] = vpx_calloc(sizeof(ENTROPY_CONTEXT) * oci->mb_cols * 2 , 1);
144 if (!oci->above_context[VCONTEXT])
146 vp8_de_alloc_frame_buffers(oci);
147 return ALLOC_FAILURE;
150 oci->above_context[Y2CONTEXT] = vpx_calloc(sizeof(ENTROPY_CONTEXT) * oci->mb_cols , 1);
152 if (!oci->above_context[Y2CONTEXT])
154 vp8_de_alloc_frame_buffers(oci);
155 return ALLOC_FAILURE;
158 vp8_update_mode_info_border(oci->mi, oci->mb_rows, oci->mb_cols);
160 // Structures used to minitor GF usage
161 if (oci->gf_active_flags != 0)
162 vpx_free(oci->gf_active_flags);
164 oci->gf_active_flags = (unsigned char *)vpx_calloc(oci->mb_rows * oci->mb_cols, 1);
166 if (!oci->gf_active_flags)
168 vp8_de_alloc_frame_buffers(oci);
169 return ALLOC_FAILURE;
172 oci->gf_active_count = oci->mb_rows * oci->mb_cols;
176 void vp8_setup_version(VP8_COMMON *cm)
183 cm->use_bilinear_mc_filter = 0;
189 cm->use_bilinear_mc_filter = 1;
195 cm->use_bilinear_mc_filter = 1;
201 cm->use_bilinear_mc_filter = 1;
205 //4,5,6,7 are reserved for future use
208 cm->use_bilinear_mc_filter = 0;
213 void vp8_create_common(VP8_COMMON *oci)
215 vp8_machine_specific_config(oci);
216 vp8_default_coef_probs(oci);
217 vp8_init_mbmode_probs(oci);
218 vp8_default_bmode_probs(oci->fc.bmode_prob);
220 oci->mb_no_coeff_skip = 1;
222 oci->simpler_lpf = 0;
223 oci->use_bilinear_mc_filter = 0;
225 oci->multi_token_partition = ONE_PARTITION;
226 oci->clr_type = REG_YUV;
227 oci->clamp_type = RECON_CLAMP_REQUIRED;
229 // Initialise reference frame sign bias structure to defaults
230 vpx_memset(oci->ref_frame_sign_bias, 0, sizeof(oci->ref_frame_sign_bias));
232 // Default disable buffer to buffer copying
233 oci->copy_buffer_to_gf = 0;
234 oci->copy_buffer_to_arf = 0;
237 void vp8_remove_common(VP8_COMMON *oci)
239 vp8_de_alloc_frame_buffers(oci);
242 void vp8_initialize_common()
244 vp8_coef_tree_initialize();
246 vp8_entropy_mode_init();
248 vp8_init_scan_order_mask();