Add packaging files for Tizen
[profile/ivi/libvpx.git] / vp8 / common / alloccommon.c
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_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 void vp8_de_alloc_frame_buffers(VP8_COMMON *oci)
21 {
22     int i;
23     for (i = 0; i < NUM_YV12_BUFFERS; i++)
24         vp8_yv12_de_alloc_frame_buffer(&oci->yv12_fb[i]);
25
26     vp8_yv12_de_alloc_frame_buffer(&oci->temp_scale_frame);
27 #if CONFIG_POSTPROC
28     vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer);
29     if (oci->post_proc_buffer_int_used)
30         vp8_yv12_de_alloc_frame_buffer(&oci->post_proc_buffer_int);
31 #endif
32
33     vpx_free(oci->above_context);
34     vpx_free(oci->mip);
35 #if CONFIG_ERROR_CONCEALMENT
36     vpx_free(oci->prev_mip);
37     oci->prev_mip = NULL;
38 #endif
39
40     oci->above_context = NULL;
41     oci->mip = NULL;
42 }
43
44 int vp8_alloc_frame_buffers(VP8_COMMON *oci, int width, int height)
45 {
46     int i;
47
48     vp8_de_alloc_frame_buffers(oci);
49
50     /* our internal buffers are always multiples of 16 */
51     if ((width & 0xf) != 0)
52         width += 16 - (width & 0xf);
53
54     if ((height & 0xf) != 0)
55         height += 16 - (height & 0xf);
56
57
58     for (i = 0; i < NUM_YV12_BUFFERS; i++)
59     {
60         oci->fb_idx_ref_cnt[i] = 0;
61         oci->yv12_fb[i].flags = 0;
62         if (vp8_yv12_alloc_frame_buffer(&oci->yv12_fb[i], width, height, VP8BORDERINPIXELS) < 0)
63         {
64             vp8_de_alloc_frame_buffers(oci);
65             return 1;
66         }
67     }
68
69     oci->new_fb_idx = 0;
70     oci->lst_fb_idx = 1;
71     oci->gld_fb_idx = 2;
72     oci->alt_fb_idx = 3;
73
74     oci->fb_idx_ref_cnt[0] = 1;
75     oci->fb_idx_ref_cnt[1] = 1;
76     oci->fb_idx_ref_cnt[2] = 1;
77     oci->fb_idx_ref_cnt[3] = 1;
78
79     if (vp8_yv12_alloc_frame_buffer(&oci->temp_scale_frame,   width, 16, VP8BORDERINPIXELS) < 0)
80     {
81         vp8_de_alloc_frame_buffers(oci);
82         return 1;
83     }
84
85 #if CONFIG_POSTPROC
86     if (vp8_yv12_alloc_frame_buffer(&oci->post_proc_buffer, width, height, VP8BORDERINPIXELS) < 0)
87     {
88         vp8_de_alloc_frame_buffers(oci);
89         return 1;
90     }
91
92     oci->post_proc_buffer_int_used = 0;
93     vpx_memset(&oci->postproc_state, 0, sizeof(oci->postproc_state));
94     vpx_memset((&oci->post_proc_buffer)->buffer_alloc,128,(&oci->post_proc_buffer)->frame_size);
95 #endif
96
97     oci->mb_rows = height >> 4;
98     oci->mb_cols = width >> 4;
99     oci->MBs = oci->mb_rows * oci->mb_cols;
100     oci->mode_info_stride = oci->mb_cols + 1;
101     oci->mip = vpx_calloc((oci->mb_cols + 1) * (oci->mb_rows + 1), sizeof(MODE_INFO));
102
103     if (!oci->mip)
104     {
105         vp8_de_alloc_frame_buffers(oci);
106         return 1;
107     }
108
109     oci->mi = oci->mip + oci->mode_info_stride + 1;
110
111     /* Allocation of previous mode info will be done in vp8_decode_frame()
112      * as it is a decoder only data */
113
114     oci->above_context = vpx_calloc(sizeof(ENTROPY_CONTEXT_PLANES) * oci->mb_cols, 1);
115
116     if (!oci->above_context)
117     {
118         vp8_de_alloc_frame_buffers(oci);
119         return 1;
120     }
121
122     return 0;
123 }
124 void vp8_setup_version(VP8_COMMON *cm)
125 {
126     switch (cm->version)
127     {
128     case 0:
129         cm->no_lpf = 0;
130         cm->filter_type = NORMAL_LOOPFILTER;
131         cm->use_bilinear_mc_filter = 0;
132         cm->full_pixel = 0;
133         break;
134     case 1:
135         cm->no_lpf = 0;
136         cm->filter_type = SIMPLE_LOOPFILTER;
137         cm->use_bilinear_mc_filter = 1;
138         cm->full_pixel = 0;
139         break;
140     case 2:
141         cm->no_lpf = 1;
142         cm->filter_type = NORMAL_LOOPFILTER;
143         cm->use_bilinear_mc_filter = 1;
144         cm->full_pixel = 0;
145         break;
146     case 3:
147         cm->no_lpf = 1;
148         cm->filter_type = SIMPLE_LOOPFILTER;
149         cm->use_bilinear_mc_filter = 1;
150         cm->full_pixel = 1;
151         break;
152     default:
153         /*4,5,6,7 are reserved for future use*/
154         cm->no_lpf = 0;
155         cm->filter_type = NORMAL_LOOPFILTER;
156         cm->use_bilinear_mc_filter = 0;
157         cm->full_pixel = 0;
158         break;
159     }
160 }
161 void vp8_create_common(VP8_COMMON *oci)
162 {
163     vp8_machine_specific_config(oci);
164
165     vp8_init_mbmode_probs(oci);
166     vp8_default_bmode_probs(oci->fc.bmode_prob);
167
168     oci->mb_no_coeff_skip = 1;
169     oci->no_lpf = 0;
170     oci->filter_type = NORMAL_LOOPFILTER;
171     oci->use_bilinear_mc_filter = 0;
172     oci->full_pixel = 0;
173     oci->multi_token_partition = ONE_PARTITION;
174     oci->clr_type = REG_YUV;
175     oci->clamp_type = RECON_CLAMP_REQUIRED;
176
177     /* Initialize reference frame sign bias structure to defaults */
178     vpx_memset(oci->ref_frame_sign_bias, 0, sizeof(oci->ref_frame_sign_bias));
179
180     /* Default disable buffer to buffer copying */
181     oci->copy_buffer_to_gf = 0;
182     oci->copy_buffer_to_arf = 0;
183 }
184
185 void vp8_remove_common(VP8_COMMON *oci)
186 {
187     vp8_de_alloc_frame_buffers(oci);
188 }