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

Side by Side Diff: source/libvpx/vp8/encoder/lookahead.c

Issue 7671004: Update libvpx snapshot to v0.9.7-p1 (Cayuga). (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/libvpx/
Patch Set: '' Created 9 years, 4 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/vp8/encoder/lookahead.h ('k') | source/libvpx/vp8/encoder/mcomp.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2011 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 #include <assert.h>
11 #include <stdlib.h>
12 #include "vpx_config.h"
13 #include "lookahead.h"
14 #include "vp8/common/extend.h"
15
16 #define MAX_LAG_BUFFERS (CONFIG_REALTIME_ONLY? 1 : 25)
17
18 struct lookahead_ctx
19 {
20 unsigned int max_sz; /* Absolute size of the queue */
21 unsigned int sz; /* Number of buffers currently in the queue */
22 unsigned int read_idx; /* Read index */
23 unsigned int write_idx; /* Write index */
24 struct lookahead_entry *buf; /* Buffer list */
25 };
26
27
28 /* Return the buffer at the given absolute index and increment the index */
29 static struct lookahead_entry *
30 pop(struct lookahead_ctx *ctx,
31 unsigned int *idx)
32 {
33 unsigned int index = *idx;
34 struct lookahead_entry *buf = ctx->buf + index;
35
36 assert(index < ctx->max_sz);
37 if(++index >= ctx->max_sz)
38 index -= ctx->max_sz;
39 *idx = index;
40 return buf;
41 }
42
43
44 void
45 vp8_lookahead_destroy(struct lookahead_ctx *ctx)
46 {
47 if(ctx)
48 {
49 if(ctx->buf)
50 {
51 int i;
52
53 for(i = 0; i < ctx->max_sz; i++)
54 vp8_yv12_de_alloc_frame_buffer(&ctx->buf[i].img);
55 free(ctx->buf);
56 }
57 free(ctx);
58 }
59 }
60
61
62 struct lookahead_ctx*
63 vp8_lookahead_init(unsigned int width,
64 unsigned int height,
65 unsigned int depth)
66 {
67 struct lookahead_ctx *ctx = NULL;
68 int i;
69
70 /* Clamp the lookahead queue depth */
71 if(depth < 1)
72 depth = 1;
73 else if(depth > MAX_LAG_BUFFERS)
74 depth = MAX_LAG_BUFFERS;
75
76 /* Align the buffer dimensions */
77 width = (width + 15) & ~15;
78 height = (height + 15) & ~15;
79
80 /* Allocate the lookahead structures */
81 ctx = calloc(1, sizeof(*ctx));
82 if(ctx)
83 {
84 ctx->max_sz = depth;
85 ctx->buf = calloc(depth, sizeof(*ctx->buf));
86 if(!ctx->buf)
87 goto bail;
88 for(i=0; i<depth; i++)
89 if (vp8_yv12_alloc_frame_buffer(&ctx->buf[i].img,
90 width, height, VP8BORDERINPIXELS))
91 goto bail;
92 }
93 return ctx;
94 bail:
95 vp8_lookahead_destroy(ctx);
96 return NULL;
97 }
98
99
100 int
101 vp8_lookahead_push(struct lookahead_ctx *ctx,
102 YV12_BUFFER_CONFIG *src,
103 int64_t ts_start,
104 int64_t ts_end,
105 unsigned int flags)
106 {
107 struct lookahead_entry* buf;
108
109 if(ctx->sz + 1 > ctx->max_sz)
110 return 1;
111 ctx->sz++;
112 buf = pop(ctx, &ctx->write_idx);
113 vp8_copy_and_extend_frame(src, &buf->img);
114 buf->ts_start = ts_start;
115 buf->ts_end = ts_end;
116 buf->flags = flags;
117 return 0;
118 }
119
120
121 struct lookahead_entry*
122 vp8_lookahead_pop(struct lookahead_ctx *ctx,
123 int drain)
124 {
125 struct lookahead_entry* buf = NULL;
126
127 if(ctx->sz && (drain || ctx->sz == ctx->max_sz))
128 {
129 buf = pop(ctx, &ctx->read_idx);
130 ctx->sz--;
131 }
132 return buf;
133 }
134
135
136 struct lookahead_entry*
137 vp8_lookahead_peek(struct lookahead_ctx *ctx,
138 int index)
139 {
140 struct lookahead_entry* buf = NULL;
141
142 assert(index < ctx->max_sz);
143 if(index < ctx->sz)
144 {
145 index += ctx->read_idx;
146 if(index >= ctx->max_sz)
147 index -= ctx->max_sz;
148 buf = ctx->buf + index;
149 }
150 return buf;
151 }
152
153
154 unsigned int
155 vp8_lookahead_depth(struct lookahead_ctx *ctx)
156 {
157 return ctx->sz;
158 }
OLDNEW
« no previous file with comments | « source/libvpx/vp8/encoder/lookahead.h ('k') | source/libvpx/vp8/encoder/mcomp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698