2 * Copyright (c) 2010 The WebM 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"
21 extern void vp8_init_scan_order_mask();
23 static void update_mode_info_border(MODE_INFO
*mi
, int rows
, int cols
)
26 vpx_memset(mi
- cols
- 2, 0, sizeof(MODE_INFO
) * (cols
+ 1));
28 for (i
= 0; i
< rows
; i
++)
30 /* TODO(holmer): Bug? This updates the last element of each row
31 * rather than the border element!
33 vpx_memset(&mi
[i
*cols
-1], 0, sizeof(MODE_INFO
));
37 void vp8_de_alloc_frame_buffers(VP8_COMMON
*oci
)
41 for (i
= 0; i
< NUM_YV12_BUFFERS
; i
++)
42 vp8_yv12_de_alloc_frame_buffer(&oci
->yv12_fb
[i
]);
44 vp8_yv12_de_alloc_frame_buffer(&oci
->temp_scale_frame
);
45 vp8_yv12_de_alloc_frame_buffer(&oci
->post_proc_buffer
);
47 vpx_free(oci
->above_context
);
49 vpx_free(oci
->prev_mip
);
51 oci
->above_context
= 0;
57 int vp8_alloc_frame_buffers(VP8_COMMON
*oci
, int width
, int height
)
61 vp8_de_alloc_frame_buffers(oci
);
63 /* our internal buffers are always multiples of 16 */
64 if ((width
& 0xf) != 0)
65 width
+= 16 - (width
& 0xf);
67 if ((height
& 0xf) != 0)
68 height
+= 16 - (height
& 0xf);
71 for (i
= 0; i
< NUM_YV12_BUFFERS
; i
++)
73 oci
->fb_idx_ref_cnt
[i
] = 0;
74 oci
->yv12_fb
[i
].flags
= 0;
75 if (vp8_yv12_alloc_frame_buffer(&oci
->yv12_fb
[i
], width
, height
, VP8BORDERINPIXELS
) < 0)
77 vp8_de_alloc_frame_buffers(oci
);
87 oci
->fb_idx_ref_cnt
[0] = 1;
88 oci
->fb_idx_ref_cnt
[1] = 1;
89 oci
->fb_idx_ref_cnt
[2] = 1;
90 oci
->fb_idx_ref_cnt
[3] = 1;
92 if (vp8_yv12_alloc_frame_buffer(&oci
->temp_scale_frame
, width
, 16, VP8BORDERINPIXELS
) < 0)
94 vp8_de_alloc_frame_buffers(oci
);
98 if (vp8_yv12_alloc_frame_buffer(&oci
->post_proc_buffer
, width
, height
, VP8BORDERINPIXELS
) < 0)
100 vp8_de_alloc_frame_buffers(oci
);
104 oci
->mb_rows
= height
>> 4;
105 oci
->mb_cols
= width
>> 4;
106 oci
->MBs
= oci
->mb_rows
* oci
->mb_cols
;
107 oci
->mode_info_stride
= oci
->mb_cols
+ 1;
108 oci
->mip
= vpx_calloc((oci
->mb_cols
+ 1) * (oci
->mb_rows
+ 1), sizeof(MODE_INFO
));
112 vp8_de_alloc_frame_buffers(oci
);
116 oci
->mi
= oci
->mip
+ oci
->mode_info_stride
+ 1;
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
));
124 vp8_de_alloc_frame_buffers(oci
);
128 oci
->prev_mi
= oci
->prev_mip
+ oci
->mode_info_stride
+ 1;
130 oci
->prev_mip
= NULL
;
134 oci
->above_context
= vpx_calloc(sizeof(ENTROPY_CONTEXT_PLANES
) * oci
->mb_cols
, 1);
136 if (!oci
->above_context
)
138 vp8_de_alloc_frame_buffers(oci
);
142 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
);
149 void vp8_setup_version(VP8_COMMON
*cm
)
155 cm
->filter_type
= NORMAL_LOOPFILTER
;
156 cm
->use_bilinear_mc_filter
= 0;
161 cm
->filter_type
= SIMPLE_LOOPFILTER
;
162 cm
->use_bilinear_mc_filter
= 1;
167 cm
->filter_type
= NORMAL_LOOPFILTER
;
168 cm
->use_bilinear_mc_filter
= 1;
173 cm
->filter_type
= SIMPLE_LOOPFILTER
;
174 cm
->use_bilinear_mc_filter
= 1;
178 /*4,5,6,7 are reserved for future use*/
180 cm
->filter_type
= NORMAL_LOOPFILTER
;
181 cm
->use_bilinear_mc_filter
= 0;
186 void vp8_create_common(VP8_COMMON
*oci
)
188 vp8_machine_specific_config(oci
);
189 vp8_default_coef_probs(oci
);
190 vp8_init_mbmode_probs(oci
);
191 vp8_default_bmode_probs(oci
->fc
.bmode_prob
);
193 oci
->mb_no_coeff_skip
= 1;
195 oci
->filter_type
= NORMAL_LOOPFILTER
;
196 oci
->use_bilinear_mc_filter
= 0;
198 oci
->multi_token_partition
= ONE_PARTITION
;
199 oci
->clr_type
= REG_YUV
;
200 oci
->clamp_type
= RECON_CLAMP_REQUIRED
;
202 /* Initialise reference frame sign bias structure to defaults */
203 vpx_memset(oci
->ref_frame_sign_bias
, 0, sizeof(oci
->ref_frame_sign_bias
));
205 /* Default disable buffer to buffer copying */
206 oci
->copy_buffer_to_gf
= 0;
207 oci
->copy_buffer_to_arf
= 0;
210 void vp8_remove_common(VP8_COMMON
*oci
)
212 vp8_de_alloc_frame_buffers(oci
);
215 void vp8_initialize_common()
217 vp8_coef_tree_initialize();
219 vp8_entropy_mode_init();
221 vp8_init_scan_order_mask();