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

Side by Side Diff: source/libvpx/vp9/encoder/vp9_lookahead.c

Issue 232133009: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 8 months 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/encoder/vp9_lookahead.h ('k') | source/libvpx/vp9/encoder/vp9_mbgraph.c » ('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) 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 10 matching lines...) Expand all
21 struct lookahead_ctx { 21 struct lookahead_ctx {
22 unsigned int max_sz; /* Absolute size of the queue */ 22 unsigned int max_sz; /* Absolute size of the queue */
23 unsigned int sz; /* Number of buffers currently in the queue */ 23 unsigned int sz; /* Number of buffers currently in the queue */
24 unsigned int read_idx; /* Read index */ 24 unsigned int read_idx; /* Read index */
25 unsigned int write_idx; /* Write index */ 25 unsigned int write_idx; /* Write index */
26 struct lookahead_entry *buf; /* Buffer list */ 26 struct lookahead_entry *buf; /* Buffer list */
27 }; 27 };
28 28
29 29
30 /* Return the buffer at the given absolute index and increment the index */ 30 /* Return the buffer at the given absolute index and increment the index */
31 static struct lookahead_entry * pop(struct lookahead_ctx *ctx, 31 static struct lookahead_entry *pop(struct lookahead_ctx *ctx,
32 unsigned int *idx) { 32 unsigned int *idx) {
33 unsigned int index = *idx; 33 unsigned int index = *idx;
34 struct lookahead_entry *buf = ctx->buf + index; 34 struct lookahead_entry *buf = ctx->buf + index;
35 35
36 assert(index < ctx->max_sz); 36 assert(index < ctx->max_sz);
37 if (++index >= ctx->max_sz) 37 if (++index >= ctx->max_sz)
38 index -= ctx->max_sz; 38 index -= ctx->max_sz;
39 *idx = index; 39 *idx = index;
40 return buf; 40 return buf;
41 } 41 }
42 42
43 43
44 void vp9_lookahead_destroy(struct lookahead_ctx *ctx) { 44 void vp9_lookahead_destroy(struct lookahead_ctx *ctx) {
45 if (ctx) { 45 if (ctx) {
46 if (ctx->buf) { 46 if (ctx->buf) {
47 unsigned int i; 47 unsigned int i;
48 48
49 for (i = 0; i < ctx->max_sz; i++) 49 for (i = 0; i < ctx->max_sz; i++)
50 vp9_free_frame_buffer(&ctx->buf[i].img); 50 vp9_free_frame_buffer(&ctx->buf[i].img);
51 free(ctx->buf); 51 free(ctx->buf);
52 } 52 }
53 free(ctx); 53 free(ctx);
54 } 54 }
55 } 55 }
56 56
57 57
58 struct lookahead_ctx * vp9_lookahead_init(unsigned int width, 58 struct lookahead_ctx *vp9_lookahead_init(unsigned int width,
59 unsigned int height, 59 unsigned int height,
60 unsigned int subsampling_x, 60 unsigned int subsampling_x,
61 unsigned int subsampling_y, 61 unsigned int subsampling_y,
62 unsigned int depth) { 62 unsigned int depth) {
63 struct lookahead_ctx *ctx = NULL; 63 struct lookahead_ctx *ctx = NULL;
64 64
65 // Clamp the lookahead queue depth 65 // Clamp the lookahead queue depth
66 depth = clamp(depth, 1, MAX_LAG_BUFFERS); 66 depth = clamp(depth, 1, MAX_LAG_BUFFERS);
67 67
68 // Allocate memory to keep previous source frames available.
69 depth += MAX_PRE_FRAMES;
70
68 // Allocate the lookahead structures 71 // Allocate the lookahead structures
69 ctx = calloc(1, sizeof(*ctx)); 72 ctx = calloc(1, sizeof(*ctx));
70 if (ctx) { 73 if (ctx) {
71 unsigned int i; 74 unsigned int i;
72 ctx->max_sz = depth; 75 ctx->max_sz = depth;
73 ctx->buf = calloc(depth, sizeof(*ctx->buf)); 76 ctx->buf = calloc(depth, sizeof(*ctx->buf));
74 if (!ctx->buf) 77 if (!ctx->buf)
75 goto bail; 78 goto bail;
76 for (i = 0; i < depth; i++) 79 for (i = 0; i < depth; i++)
77 if (vp9_alloc_frame_buffer(&ctx->buf[i].img, 80 if (vp9_alloc_frame_buffer(&ctx->buf[i].img,
(...skipping 11 matching lines...) Expand all
89 92
90 int vp9_lookahead_push(struct lookahead_ctx *ctx, YV12_BUFFER_CONFIG *src, 93 int vp9_lookahead_push(struct lookahead_ctx *ctx, YV12_BUFFER_CONFIG *src,
91 int64_t ts_start, int64_t ts_end, unsigned int flags) { 94 int64_t ts_start, int64_t ts_end, unsigned int flags) {
92 struct lookahead_entry *buf; 95 struct lookahead_entry *buf;
93 #if USE_PARTIAL_COPY 96 #if USE_PARTIAL_COPY
94 int row, col, active_end; 97 int row, col, active_end;
95 int mb_rows = (src->y_height + 15) >> 4; 98 int mb_rows = (src->y_height + 15) >> 4;
96 int mb_cols = (src->y_width + 15) >> 4; 99 int mb_cols = (src->y_width + 15) >> 4;
97 #endif 100 #endif
98 101
99 if (ctx->sz + 1 > ctx->max_sz) 102 if (ctx->sz + 1 + MAX_PRE_FRAMES > ctx->max_sz)
100 return 1; 103 return 1;
101 ctx->sz++; 104 ctx->sz++;
102 buf = pop(ctx, &ctx->write_idx); 105 buf = pop(ctx, &ctx->write_idx);
103 106
104 #if USE_PARTIAL_COPY 107 #if USE_PARTIAL_COPY
105 // TODO(jkoleszar): This is disabled for now, as 108 // TODO(jkoleszar): This is disabled for now, as
106 // vp9_copy_and_extend_frame_with_rect is not subsampling/alpha aware. 109 // vp9_copy_and_extend_frame_with_rect is not subsampling/alpha aware.
107 110
108 // Only do this partial copy if the following conditions are all met: 111 // Only do this partial copy if the following conditions are all met:
109 // 1. Lookahead queue has has size of 1. 112 // 1. Lookahead queue has has size of 1.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 vp9_copy_and_extend_frame(src, &buf->img); 155 vp9_copy_and_extend_frame(src, &buf->img);
153 #endif 156 #endif
154 157
155 buf->ts_start = ts_start; 158 buf->ts_start = ts_start;
156 buf->ts_end = ts_end; 159 buf->ts_end = ts_end;
157 buf->flags = flags; 160 buf->flags = flags;
158 return 0; 161 return 0;
159 } 162 }
160 163
161 164
162 struct lookahead_entry * vp9_lookahead_pop(struct lookahead_ctx *ctx, 165 struct lookahead_entry *vp9_lookahead_pop(struct lookahead_ctx *ctx,
163 int drain) { 166 int drain) {
164 struct lookahead_entry *buf = NULL; 167 struct lookahead_entry *buf = NULL;
165 168
166 if (ctx->sz && (drain || ctx->sz == ctx->max_sz)) { 169 if (ctx->sz && (drain || ctx->sz == ctx->max_sz - MAX_PRE_FRAMES)) {
167 buf = pop(ctx, &ctx->read_idx); 170 buf = pop(ctx, &ctx->read_idx);
168 ctx->sz--; 171 ctx->sz--;
169 } 172 }
170 return buf; 173 return buf;
171 } 174 }
172 175
173 176
174 struct lookahead_entry * vp9_lookahead_peek(struct lookahead_ctx *ctx, 177 struct lookahead_entry *vp9_lookahead_peek(struct lookahead_ctx *ctx,
175 int index) { 178 int index) {
176 struct lookahead_entry *buf = NULL; 179 struct lookahead_entry *buf = NULL;
177 180
178 if (index < (int)ctx->sz) { 181 if (index >= 0) {
179 index += ctx->read_idx; 182 // Forward peek
180 if (index >= (int)ctx->max_sz) 183 if (index < (int)ctx->sz) {
181 index -= ctx->max_sz; 184 index += ctx->read_idx;
182 buf = ctx->buf + index; 185 if (index >= (int)ctx->max_sz)
186 index -= ctx->max_sz;
187 buf = ctx->buf + index;
188 }
189 } else if (index < 0) {
190 // Backward peek
191 if (-index <= MAX_PRE_FRAMES) {
192 index += ctx->read_idx;
193 if (index < 0)
194 index += ctx->max_sz;
195 buf = ctx->buf + index;
196 }
183 } 197 }
198
184 return buf; 199 return buf;
185 } 200 }
186 201
187 unsigned int vp9_lookahead_depth(struct lookahead_ctx *ctx) { 202 unsigned int vp9_lookahead_depth(struct lookahead_ctx *ctx) {
188 return ctx->sz; 203 return ctx->sz;
189 } 204 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_lookahead.h ('k') | source/libvpx/vp9/encoder/vp9_mbgraph.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698