OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2011 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 #include <assert.h> | 10 #include <assert.h> |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 83 } |
84 return ctx; | 84 return ctx; |
85 bail: | 85 bail: |
86 vp9_lookahead_destroy(ctx); | 86 vp9_lookahead_destroy(ctx); |
87 return NULL; | 87 return NULL; |
88 } | 88 } |
89 | 89 |
90 #define USE_PARTIAL_COPY 0 | 90 #define USE_PARTIAL_COPY 0 |
91 | 91 |
92 int vp9_lookahead_push(struct lookahead_ctx *ctx, YV12_BUFFER_CONFIG *src, | 92 int vp9_lookahead_push(struct lookahead_ctx *ctx, YV12_BUFFER_CONFIG *src, |
93 int64_t ts_start, int64_t ts_end, | 93 int64_t ts_start, int64_t ts_end, unsigned int flags) { |
94 #if CONFIG_VP9_HIGHBITDEPTH | |
95 int use_highbitdepth, | |
96 #endif | |
97 unsigned int flags) { | |
98 struct lookahead_entry *buf; | 94 struct lookahead_entry *buf; |
99 #if USE_PARTIAL_COPY | 95 #if USE_PARTIAL_COPY |
100 int row, col, active_end; | 96 int row, col, active_end; |
101 int mb_rows = (src->y_height + 15) >> 4; | 97 int mb_rows = (src->y_height + 15) >> 4; |
102 int mb_cols = (src->y_width + 15) >> 4; | 98 int mb_cols = (src->y_width + 15) >> 4; |
103 #endif | 99 #endif |
104 int width = src->y_crop_width; | |
105 int height = src->y_crop_height; | |
106 int uv_width = src->uv_crop_width; | |
107 int uv_height = src->uv_crop_height; | |
108 int subsampling_x = src->subsampling_x; | |
109 int subsampling_y = src->subsampling_y; | |
110 int larger_dimensions, new_dimensions; | |
111 | 100 |
112 if (ctx->sz + 1 + MAX_PRE_FRAMES > ctx->max_sz) | 101 if (ctx->sz + 1 + MAX_PRE_FRAMES > ctx->max_sz) |
113 return 1; | 102 return 1; |
114 ctx->sz++; | 103 ctx->sz++; |
115 buf = pop(ctx, &ctx->write_idx); | 104 buf = pop(ctx, &ctx->write_idx); |
116 | 105 |
117 new_dimensions = width != buf->img.y_crop_width || | |
118 height != buf->img.y_crop_height || | |
119 uv_width != buf->img.uv_crop_width || | |
120 uv_height != buf->img.uv_crop_height; | |
121 larger_dimensions = width > buf->img.y_width || | |
122 height > buf->img.y_height || | |
123 uv_width > buf->img.uv_width || | |
124 uv_height > buf->img.uv_height; | |
125 assert(!larger_dimensions || new_dimensions); | |
126 | |
127 #if USE_PARTIAL_COPY | 106 #if USE_PARTIAL_COPY |
128 // TODO(jkoleszar): This is disabled for now, as | 107 // TODO(jkoleszar): This is disabled for now, as |
129 // vp9_copy_and_extend_frame_with_rect is not subsampling/alpha aware. | 108 // vp9_copy_and_extend_frame_with_rect is not subsampling/alpha aware. |
130 | 109 |
131 // Only do this partial copy if the following conditions are all met: | 110 // Only do this partial copy if the following conditions are all met: |
132 // 1. Lookahead queue has has size of 1. | 111 // 1. Lookahead queue has has size of 1. |
133 // 2. Active map is provided. | 112 // 2. Active map is provided. |
134 // 3. This is not a key frame, golden nor altref frame. | 113 // 3. This is not a key frame, golden nor altref frame. |
135 if (!new_dimensions && ctx->max_sz == 1 && active_map && !flags) { | 114 if (ctx->max_sz == 1 && active_map && !flags) { |
136 for (row = 0; row < mb_rows; ++row) { | 115 for (row = 0; row < mb_rows; ++row) { |
137 col = 0; | 116 col = 0; |
138 | 117 |
139 while (1) { | 118 while (1) { |
140 // Find the first active macroblock in this row. | 119 // Find the first active macroblock in this row. |
141 for (; col < mb_cols; ++col) { | 120 for (; col < mb_cols; ++col) { |
142 if (active_map[col]) | 121 if (active_map[col]) |
143 break; | 122 break; |
144 } | 123 } |
145 | 124 |
(...skipping 15 matching lines...) Expand all Loading... |
161 col << 4, 16, | 140 col << 4, 16, |
162 (active_end - col) << 4); | 141 (active_end - col) << 4); |
163 | 142 |
164 // Start again from the end of this active region. | 143 // Start again from the end of this active region. |
165 col = active_end; | 144 col = active_end; |
166 } | 145 } |
167 | 146 |
168 active_map += mb_cols; | 147 active_map += mb_cols; |
169 } | 148 } |
170 } else { | 149 } else { |
171 #endif | |
172 if (larger_dimensions) { | |
173 YV12_BUFFER_CONFIG new_img; | |
174 memset(&new_img, 0, sizeof(new_img)); | |
175 if (vp9_alloc_frame_buffer(&new_img, | |
176 width, height, subsampling_x, subsampling_y, | |
177 #if CONFIG_VP9_HIGHBITDEPTH | |
178 use_highbitdepth, | |
179 #endif | |
180 VP9_ENC_BORDER_IN_PIXELS, | |
181 0)) | |
182 return 1; | |
183 vp9_free_frame_buffer(&buf->img); | |
184 buf->img = new_img; | |
185 } else if (new_dimensions) { | |
186 buf->img.y_crop_width = src->y_crop_width; | |
187 buf->img.y_crop_height = src->y_crop_height; | |
188 buf->img.uv_crop_width = src->uv_crop_width; | |
189 buf->img.uv_crop_height = src->uv_crop_height; | |
190 buf->img.subsampling_x = src->subsampling_x; | |
191 buf->img.subsampling_y = src->subsampling_y; | |
192 } | |
193 // Partial copy not implemented yet | |
194 vp9_copy_and_extend_frame(src, &buf->img); | 150 vp9_copy_and_extend_frame(src, &buf->img); |
195 #if USE_PARTIAL_COPY | |
196 } | 151 } |
| 152 #else |
| 153 // Partial copy not implemented yet |
| 154 vp9_copy_and_extend_frame(src, &buf->img); |
197 #endif | 155 #endif |
198 | 156 |
199 buf->ts_start = ts_start; | 157 buf->ts_start = ts_start; |
200 buf->ts_end = ts_end; | 158 buf->ts_end = ts_end; |
201 buf->flags = flags; | 159 buf->flags = flags; |
202 return 0; | 160 return 0; |
203 } | 161 } |
204 | 162 |
205 | 163 |
206 struct lookahead_entry *vp9_lookahead_pop(struct lookahead_ctx *ctx, | 164 struct lookahead_entry *vp9_lookahead_pop(struct lookahead_ctx *ctx, |
(...skipping 29 matching lines...) Expand all Loading... |
236 buf = ctx->buf + index; | 194 buf = ctx->buf + index; |
237 } | 195 } |
238 } | 196 } |
239 | 197 |
240 return buf; | 198 return buf; |
241 } | 199 } |
242 | 200 |
243 unsigned int vp9_lookahead_depth(struct lookahead_ctx *ctx) { | 201 unsigned int vp9_lookahead_depth(struct lookahead_ctx *ctx) { |
244 return ctx->sz; | 202 return ctx->sz; |
245 } | 203 } |
OLD | NEW |