2 * Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license and patent
5 * grant that can be found in the LICENSE file in the root of the source
6 * tree. All contributing project authors may be found in the AUTHORS
7 * file in the root of the source tree.
12 #include "vpx_mem/vpx_mem.h"
13 #include "onyxc_int.h"
14 #include "findnearmv.h"
15 #include "entropymode.h"
16 #include "systemdependent.h"
17 #include "vpxerrors.h"
20 #include "vpx_config.h"
23 extern void vp8_init_scan_order_mask();
25 void vp8_update_mode_info_border(MODE_INFO
*mi
, int rows
, int cols
)
28 vpx_memset(mi
- cols
- 1, 0, sizeof(MODE_INFO
) * cols
+ 1);
30 for (i
= 0; i
< rows
; i
++)
32 vpx_memset(&mi
[i
*cols
-1], 0, sizeof(MODE_INFO
));
35 void vp8_de_alloc_frame_buffers(VP8_COMMON
*oci
)
37 vp8_yv12_de_alloc_frame_buffer(&oci
->temp_scale_frame
);
38 vp8_yv12_de_alloc_frame_buffer(&oci
->new_frame
);
39 vp8_yv12_de_alloc_frame_buffer(&oci
->last_frame
);
40 vp8_yv12_de_alloc_frame_buffer(&oci
->golden_frame
);
41 vp8_yv12_de_alloc_frame_buffer(&oci
->alt_ref_frame
);
42 vp8_yv12_de_alloc_frame_buffer(&oci
->post_proc_buffer
);
44 vpx_free(oci
->above_context
[Y1CONTEXT
]);
45 vpx_free(oci
->above_context
[UCONTEXT
]);
46 vpx_free(oci
->above_context
[VCONTEXT
]);
47 vpx_free(oci
->above_context
[Y2CONTEXT
]);
50 oci
->above_context
[Y1CONTEXT
] = 0;
51 oci
->above_context
[UCONTEXT
] = 0;
52 oci
->above_context
[VCONTEXT
] = 0;
53 oci
->above_context
[Y2CONTEXT
] = 0;
56 // Structure used to minitor GF useage
57 if (oci
->gf_active_flags
!= 0)
58 vpx_free(oci
->gf_active_flags
);
60 oci
->gf_active_flags
= 0;
63 int vp8_alloc_frame_buffers(VP8_COMMON
*oci
, int width
, int height
)
65 vp8_de_alloc_frame_buffers(oci
);
67 // our internal buffers are always multiples of 16
68 if ((width
& 0xf) != 0)
69 width
+= 16 - (width
& 0xf);
71 if ((height
& 0xf) != 0)
72 height
+= 16 - (height
& 0xf);
75 if (vp8_yv12_alloc_frame_buffer(&oci
->temp_scale_frame
, width
, 16, VP8BORDERINPIXELS
) < 0)
77 vp8_de_alloc_frame_buffers(oci
);
82 if (vp8_yv12_alloc_frame_buffer(&oci
->new_frame
, width
, height
, VP8BORDERINPIXELS
) < 0)
84 vp8_de_alloc_frame_buffers(oci
);
88 if (vp8_yv12_alloc_frame_buffer(&oci
->last_frame
, width
, height
, VP8BORDERINPIXELS
) < 0)
90 vp8_de_alloc_frame_buffers(oci
);
94 if (vp8_yv12_alloc_frame_buffer(&oci
->golden_frame
, width
, height
, VP8BORDERINPIXELS
) < 0)
96 vp8_de_alloc_frame_buffers(oci
);
100 if (vp8_yv12_alloc_frame_buffer(&oci
->alt_ref_frame
, width
, height
, VP8BORDERINPIXELS
) < 0)
102 vp8_de_alloc_frame_buffers(oci
);
103 return ALLOC_FAILURE
;
106 if (vp8_yv12_alloc_frame_buffer(&oci
->post_proc_buffer
, width
, height
, VP8BORDERINPIXELS
) < 0)
108 vp8_de_alloc_frame_buffers(oci
);
109 return ALLOC_FAILURE
;
112 oci
->mb_rows
= height
>> 4;
113 oci
->mb_cols
= width
>> 4;
114 oci
->MBs
= oci
->mb_rows
* oci
->mb_cols
;
115 oci
->mode_info_stride
= oci
->mb_cols
+ 1;
116 oci
->mip
= vpx_calloc((oci
->mb_cols
+ 1) * (oci
->mb_rows
+ 1), sizeof(MODE_INFO
));
120 vp8_de_alloc_frame_buffers(oci
);
121 return ALLOC_FAILURE
;
124 oci
->mi
= oci
->mip
+ oci
->mode_info_stride
+ 1;
127 oci
->above_context
[Y1CONTEXT
] = vpx_calloc(sizeof(ENTROPY_CONTEXT
) * oci
->mb_cols
* 4 , 1);
129 if (!oci
->above_context
[Y1CONTEXT
])
131 vp8_de_alloc_frame_buffers(oci
);
132 return ALLOC_FAILURE
;
135 oci
->above_context
[UCONTEXT
] = vpx_calloc(sizeof(ENTROPY_CONTEXT
) * oci
->mb_cols
* 2 , 1);
137 if (!oci
->above_context
[UCONTEXT
])
139 vp8_de_alloc_frame_buffers(oci
);
140 return ALLOC_FAILURE
;
143 oci
->above_context
[VCONTEXT
] = vpx_calloc(sizeof(ENTROPY_CONTEXT
) * oci
->mb_cols
* 2 , 1);
145 if (!oci
->above_context
[VCONTEXT
])
147 vp8_de_alloc_frame_buffers(oci
);
148 return ALLOC_FAILURE
;
151 oci
->above_context
[Y2CONTEXT
] = vpx_calloc(sizeof(ENTROPY_CONTEXT
) * oci
->mb_cols
, 1);
153 if (!oci
->above_context
[Y2CONTEXT
])
155 vp8_de_alloc_frame_buffers(oci
);
156 return ALLOC_FAILURE
;
159 vp8_update_mode_info_border(oci
->mi
, oci
->mb_rows
, oci
->mb_cols
);
161 // Structures used to minitor GF usage
162 if (oci
->gf_active_flags
!= 0)
163 vpx_free(oci
->gf_active_flags
);
165 oci
->gf_active_flags
= (unsigned char *)vpx_calloc(oci
->mb_rows
* oci
->mb_cols
, 1);
167 if (!oci
->gf_active_flags
)
169 vp8_de_alloc_frame_buffers(oci
);
170 return ALLOC_FAILURE
;
173 oci
->gf_active_count
= oci
->mb_rows
* oci
->mb_cols
;
177 void vp8_setup_version(VP8_COMMON
*cm
)
184 cm
->use_bilinear_mc_filter
= 0;
190 cm
->use_bilinear_mc_filter
= 1;
196 cm
->use_bilinear_mc_filter
= 1;
202 cm
->use_bilinear_mc_filter
= 1;
206 //4,5,6,7 are reserved for future use
209 cm
->use_bilinear_mc_filter
= 0;
214 void vp8_create_common(VP8_COMMON
*oci
)
216 vp8_machine_specific_config(oci
);
217 vp8_default_coef_probs(oci
);
218 vp8_init_mbmode_probs(oci
);
219 vp8_default_bmode_probs(oci
->fc
.bmode_prob
);
221 oci
->mb_no_coeff_skip
= 1;
223 oci
->simpler_lpf
= 0;
224 oci
->use_bilinear_mc_filter
= 0;
226 oci
->multi_token_partition
= ONE_PARTITION
;
227 oci
->clr_type
= REG_YUV
;
228 oci
->clamp_type
= RECON_CLAMP_REQUIRED
;
230 // Initialise reference frame sign bias structure to defaults
231 vpx_memset(oci
->ref_frame_sign_bias
, 0, sizeof(oci
->ref_frame_sign_bias
));
233 // Default disable buffer to buffer copying
234 oci
->copy_buffer_to_gf
= 0;
235 oci
->copy_buffer_to_arf
= 0;
238 void vp8_remove_common(VP8_COMMON
*oci
)
240 vp8_de_alloc_frame_buffers(oci
);
243 void vp8_initialize_common()
245 vp8_coef_tree_initialize();
247 vp8_entropy_mode_init();
249 vp8_init_scan_order_mask();