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