Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(475)

Side by Side Diff: source/libvpx/vp9/common/vp9_alloccommon.c

Issue 756673003: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp9/common/vp9_alloccommon.h ('k') | source/libvpx/vp9/common/vp9_blockd.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "./vpx_config.h" 11 #include "./vpx_config.h"
12 #include "vpx_mem/vpx_mem.h" 12 #include "vpx_mem/vpx_mem.h"
13 13
14 #include "vp9/common/vp9_blockd.h" 14 #include "vp9/common/vp9_blockd.h"
15 #include "vp9/common/vp9_entropymode.h" 15 #include "vp9/common/vp9_entropymode.h"
16 #include "vp9/common/vp9_entropymv.h" 16 #include "vp9/common/vp9_entropymv.h"
17 #include "vp9/common/vp9_onyxc_int.h" 17 #include "vp9/common/vp9_onyxc_int.h"
18 #include "vp9/common/vp9_systemdependent.h" 18 #include "vp9/common/vp9_systemdependent.h"
19 19
20 static void clear_mi_border(const VP9_COMMON *cm, MODE_INFO *mi) {
21 int i;
22
23 // Top border row
24 vpx_memset(mi, 0, sizeof(*mi) * cm->mi_stride);
25
26 // Left border column
27 for (i = 1; i < cm->mi_rows + 1; ++i)
28 vpx_memset(&mi[i * cm->mi_stride], 0, sizeof(*mi));
29 }
30
31 void vp9_set_mb_mi(VP9_COMMON *cm, int width, int height) { 20 void vp9_set_mb_mi(VP9_COMMON *cm, int width, int height) {
32 const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2); 21 const int aligned_width = ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2);
33 const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2); 22 const int aligned_height = ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2);
34 23
35 cm->mi_cols = aligned_width >> MI_SIZE_LOG2; 24 cm->mi_cols = aligned_width >> MI_SIZE_LOG2;
36 cm->mi_rows = aligned_height >> MI_SIZE_LOG2; 25 cm->mi_rows = aligned_height >> MI_SIZE_LOG2;
37 cm->mi_stride = calc_mi_size(cm->mi_cols); 26 cm->mi_stride = calc_mi_size(cm->mi_cols);
38 27
39 cm->mb_cols = (cm->mi_cols + 1) >> 1; 28 cm->mb_cols = (cm->mi_cols + 1) >> 1;
40 cm->mb_rows = (cm->mi_rows + 1) >> 1; 29 cm->mb_rows = (cm->mi_rows + 1) >> 1;
41 cm->MBs = cm->mb_rows * cm->mb_cols; 30 cm->MBs = cm->mb_rows * cm->mb_cols;
42 } 31 }
43 32
44 static void setup_mi(VP9_COMMON *cm) {
45 cm->mi = cm->mip + cm->mi_stride + 1;
46 cm->prev_mi = cm->prev_mip + cm->mi_stride + 1;
47
48 vpx_memset(cm->mip, 0, cm->mi_stride * (cm->mi_rows + 1) * sizeof(*cm->mip));
49 clear_mi_border(cm, cm->prev_mip);
50 }
51
52 static int alloc_mi(VP9_COMMON *cm, int mi_size) {
53 int i;
54
55 for (i = 0; i < 2; ++i) {
56 cm->mip_array[i] =
57 (MODE_INFO *)vpx_calloc(mi_size, sizeof(MODE_INFO));
58 if (cm->mip_array[i] == NULL)
59 return 1;
60 }
61
62 cm->mi_alloc_size = mi_size;
63
64 // Init the index.
65 cm->mi_idx = 0;
66 cm->prev_mi_idx = 1;
67
68 cm->mip = cm->mip_array[cm->mi_idx];
69 cm->prev_mip = cm->mip_array[cm->prev_mi_idx];
70
71 return 0;
72 }
73
74 static void free_mi(VP9_COMMON *cm) {
75 int i;
76
77 for (i = 0; i < 2; ++i) {
78 vpx_free(cm->mip_array[i]);
79 cm->mip_array[i] = NULL;
80 }
81
82 cm->mip = NULL;
83 cm->prev_mip = NULL;
84 }
85
86 void vp9_free_ref_frame_buffers(VP9_COMMON *cm) { 33 void vp9_free_ref_frame_buffers(VP9_COMMON *cm) {
87 int i; 34 int i;
88 35
89 for (i = 0; i < FRAME_BUFFERS; ++i) { 36 for (i = 0; i < FRAME_BUFFERS; ++i) {
90 vp9_free_frame_buffer(&cm->frame_bufs[i].buf);
91
92 if (cm->frame_bufs[i].ref_count > 0 && 37 if (cm->frame_bufs[i].ref_count > 0 &&
93 cm->frame_bufs[i].raw_frame_buffer.data != NULL) { 38 cm->frame_bufs[i].raw_frame_buffer.data != NULL) {
94 cm->release_fb_cb(cm->cb_priv, &cm->frame_bufs[i].raw_frame_buffer); 39 cm->release_fb_cb(cm->cb_priv, &cm->frame_bufs[i].raw_frame_buffer);
95 cm->frame_bufs[i].ref_count = 0; 40 cm->frame_bufs[i].ref_count = 0;
96 } 41 }
42 vpx_free(cm->frame_bufs[i].mvs);
43 cm->frame_bufs[i].mvs = NULL;
44 vp9_free_frame_buffer(&cm->frame_bufs[i].buf);
97 } 45 }
98 46
99 vp9_free_frame_buffer(&cm->post_proc_buffer); 47 vp9_free_frame_buffer(&cm->post_proc_buffer);
100 } 48 }
101 49
102 void vp9_free_context_buffers(VP9_COMMON *cm) { 50 void vp9_free_context_buffers(VP9_COMMON *cm) {
103 free_mi(cm); 51 cm->free_mi(cm);
104
105 vpx_free(cm->last_frame_seg_map); 52 vpx_free(cm->last_frame_seg_map);
106 cm->last_frame_seg_map = NULL; 53 cm->last_frame_seg_map = NULL;
107
108 vpx_free(cm->above_context); 54 vpx_free(cm->above_context);
109 cm->above_context = NULL; 55 cm->above_context = NULL;
110
111 vpx_free(cm->above_seg_context); 56 vpx_free(cm->above_seg_context);
112 cm->above_seg_context = NULL; 57 cm->above_seg_context = NULL;
113 } 58 }
114 59
115 int vp9_alloc_context_buffers(VP9_COMMON *cm, int width, int height) { 60 int vp9_alloc_context_buffers(VP9_COMMON *cm, int width, int height) {
116 vp9_free_context_buffers(cm); 61 vp9_free_context_buffers(cm);
117 62
118 vp9_set_mb_mi(cm, width, height); 63 vp9_set_mb_mi(cm, width, height);
119 if (alloc_mi(cm, cm->mi_stride * calc_mi_size(cm->mi_rows))) 64 if (cm->alloc_mi(cm, cm->mi_stride * calc_mi_size(cm->mi_rows)))
120 goto fail; 65 goto fail;
121 66
122 cm->last_frame_seg_map = (uint8_t *)vpx_calloc(cm->mi_rows * cm->mi_cols, 1); 67 cm->last_frame_seg_map = (uint8_t *)vpx_calloc(cm->mi_rows * cm->mi_cols, 1);
123 if (!cm->last_frame_seg_map) goto fail; 68 if (!cm->last_frame_seg_map) goto fail;
124 69
125 cm->above_context = (ENTROPY_CONTEXT *)vpx_calloc( 70 cm->above_context = (ENTROPY_CONTEXT *)vpx_calloc(
126 2 * mi_cols_aligned_to_sb(cm->mi_cols) * MAX_MB_PLANE, 71 2 * mi_cols_aligned_to_sb(cm->mi_cols) * MAX_MB_PLANE,
127 sizeof(*cm->above_context)); 72 sizeof(*cm->above_context));
128 if (!cm->above_context) goto fail; 73 if (!cm->above_context) goto fail;
129 74
(...skipping 29 matching lines...) Expand all
159 104
160 for (i = 0; i < FRAME_BUFFERS; ++i) { 105 for (i = 0; i < FRAME_BUFFERS; ++i) {
161 cm->frame_bufs[i].ref_count = 0; 106 cm->frame_bufs[i].ref_count = 0;
162 if (vp9_alloc_frame_buffer(&cm->frame_bufs[i].buf, width, height, 107 if (vp9_alloc_frame_buffer(&cm->frame_bufs[i].buf, width, height,
163 ss_x, ss_y, 108 ss_x, ss_y,
164 #if CONFIG_VP9_HIGHBITDEPTH 109 #if CONFIG_VP9_HIGHBITDEPTH
165 cm->use_highbitdepth, 110 cm->use_highbitdepth,
166 #endif 111 #endif
167 VP9_ENC_BORDER_IN_PIXELS) < 0) 112 VP9_ENC_BORDER_IN_PIXELS) < 0)
168 goto fail; 113 goto fail;
114 if (cm->frame_bufs[i].mvs == NULL) {
115 cm->frame_bufs[i].mvs =
116 (MV_REF *)vpx_calloc(cm->mi_rows * cm->mi_cols,
117 sizeof(*cm->frame_bufs[i].mvs));
118 if (cm->frame_bufs[i].mvs == NULL)
119 goto fail;
120
121 cm->frame_bufs[i].mi_rows = cm->mi_rows;
122 cm->frame_bufs[i].mi_cols = cm->mi_cols;
123 }
169 } 124 }
170 125
171 init_frame_bufs(cm); 126 init_frame_bufs(cm);
172 127
173 #if CONFIG_INTERNAL_STATS || CONFIG_VP9_POSTPROC 128 #if CONFIG_INTERNAL_STATS || CONFIG_VP9_POSTPROC
174 if (vp9_alloc_frame_buffer(&cm->post_proc_buffer, width, height, ss_x, ss_y, 129 if (vp9_alloc_frame_buffer(&cm->post_proc_buffer, width, height, ss_x, ss_y,
175 #if CONFIG_VP9_HIGHBITDEPTH 130 #if CONFIG_VP9_HIGHBITDEPTH
176 cm->use_highbitdepth, 131 cm->use_highbitdepth,
177 #endif 132 #endif
178 VP9_ENC_BORDER_IN_PIXELS) < 0) 133 VP9_ENC_BORDER_IN_PIXELS) < 0)
179 goto fail; 134 goto fail;
180 #endif 135 #endif
181 136
182 return 0; 137 return 0;
183 138
184 fail: 139 fail:
185 vp9_free_ref_frame_buffers(cm); 140 vp9_free_ref_frame_buffers(cm);
186 return 1; 141 return 1;
187 } 142 }
188 143
189 void vp9_remove_common(VP9_COMMON *cm) { 144 void vp9_remove_common(VP9_COMMON *cm) {
190 vp9_free_ref_frame_buffers(cm); 145 vp9_free_ref_frame_buffers(cm);
191 vp9_free_context_buffers(cm); 146 vp9_free_context_buffers(cm);
192 vp9_free_internal_frame_buffers(&cm->int_frame_buffers); 147 vp9_free_internal_frame_buffers(&cm->int_frame_buffers);
148
149 vpx_free(cm->fc);
150 cm->fc = NULL;
151 vpx_free(cm->frame_contexts);
152 cm->frame_contexts = NULL;
193 } 153 }
194 154
195 void vp9_init_context_buffers(VP9_COMMON *cm) { 155 void vp9_init_context_buffers(VP9_COMMON *cm) {
196 setup_mi(cm); 156 cm->setup_mi(cm);
197 if (cm->last_frame_seg_map) 157 if (cm->last_frame_seg_map)
198 vpx_memset(cm->last_frame_seg_map, 0, cm->mi_rows * cm->mi_cols); 158 vpx_memset(cm->last_frame_seg_map, 0, cm->mi_rows * cm->mi_cols);
199 } 159 }
200
201 void vp9_swap_mi_and_prev_mi(VP9_COMMON *cm) {
202 // Swap indices.
203 const int tmp = cm->mi_idx;
204 cm->mi_idx = cm->prev_mi_idx;
205 cm->prev_mi_idx = tmp;
206
207 // Current mip will be the prev_mip for the next frame.
208 cm->mip = cm->mip_array[cm->mi_idx];
209 cm->prev_mip = cm->mip_array[cm->prev_mi_idx];
210
211 // Update the upper left visible macroblock ptrs.
212 cm->mi = cm->mip + cm->mi_stride + 1;
213 cm->prev_mi = cm->prev_mip + cm->mi_stride + 1;
214 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/common/vp9_alloccommon.h ('k') | source/libvpx/vp9/common/vp9_blockd.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698