Commit 2891d70b authored by Dmitry Kovalev's avatar Dmitry Kovalev
Browse files

Code cleanup.

Removing redundant code, introducing new functions for better
decomposition, adding 'clamp' function to vp9_common.h.

Change-Id: Ic3b8ca13bbc38f60f0c9c43910b5802005e31aaf
parent 9b4095c5
...@@ -51,4 +51,8 @@ static INLINE uint8_t clip_pixel(int val) { ...@@ -51,4 +51,8 @@ static INLINE uint8_t clip_pixel(int val) {
return (val > 255) ? 255u : (val < 0) ? 0u : val; return (val > 255) ? 255u : (val < 0) ? 0u : val;
} }
static INLINE int clamp(int value, int low, int high) {
return value < low ? low : (value > high ? high : value);
}
#endif // VP9_COMMON_VP9_COMMON_H_ #endif // VP9_COMMON_VP9_COMMON_H_
This diff is collapsed.
...@@ -9,7 +9,9 @@ ...@@ -9,7 +9,9 @@
*/ */
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#include "vpx_config.h" #include "vpx_config.h"
#include "vp9/common/vp9_common.h"
#include "vp9/encoder/vp9_lookahead.h" #include "vp9/encoder/vp9_lookahead.h"
#include "vp9/common/vp9_extend.h" #include "vp9/common/vp9_extend.h"
...@@ -25,10 +27,9 @@ struct lookahead_ctx { ...@@ -25,10 +27,9 @@ struct lookahead_ctx {
/* Return the buffer at the given absolute index and increment the index */ /* Return the buffer at the given absolute index and increment the index */
static struct lookahead_entry * static struct lookahead_entry * pop(struct lookahead_ctx *ctx,
pop(struct lookahead_ctx *ctx, unsigned int *idx) {
unsigned int *idx) { unsigned int index = *idx;
unsigned int index = *idx;
struct lookahead_entry *buf = ctx->buf + index; struct lookahead_entry *buf = ctx->buf + index;
assert(index < ctx->max_sz); assert(index < ctx->max_sz);
...@@ -39,8 +40,7 @@ pop(struct lookahead_ctx *ctx, ...@@ -39,8 +40,7 @@ pop(struct lookahead_ctx *ctx,
} }
void void vp9_lookahead_destroy(struct lookahead_ctx *ctx) {
vp9_lookahead_destroy(struct lookahead_ctx *ctx) {
if (ctx) { if (ctx) {
if (ctx->buf) { if (ctx->buf) {
unsigned int i; unsigned int i;
...@@ -54,23 +54,19 @@ vp9_lookahead_destroy(struct lookahead_ctx *ctx) { ...@@ -54,23 +54,19 @@ vp9_lookahead_destroy(struct lookahead_ctx *ctx) {
} }
struct lookahead_ctx * struct lookahead_ctx * vp9_lookahead_init(unsigned int width,
vp9_lookahead_init(unsigned int width, unsigned int height,
unsigned int height, unsigned int depth) {
unsigned int depth) {
struct lookahead_ctx *ctx = NULL; struct lookahead_ctx *ctx = NULL;
/* Clamp the lookahead queue depth */ // Clamp the lookahead queue depth
if (depth < 1) depth = clamp(depth, 1, MAX_LAG_BUFFERS);
depth = 1;
else if (depth > MAX_LAG_BUFFERS)
depth = MAX_LAG_BUFFERS;
/* Align the buffer dimensions */ // Align the buffer dimensions
width = (width + 15) &~15; width = (width + 15) &~15;
height = (height + 15) &~15; height = (height + 15) &~15;
/* Allocate the lookahead structures */ // Allocate the lookahead structures
ctx = calloc(1, sizeof(*ctx)); ctx = calloc(1, sizeof(*ctx));
if (ctx) { if (ctx) {
unsigned int i; unsigned int i;
...@@ -90,13 +86,9 @@ bail: ...@@ -90,13 +86,9 @@ bail:
} }
int int vp9_lookahead_push(struct lookahead_ctx *ctx, YV12_BUFFER_CONFIG *src,
vp9_lookahead_push(struct lookahead_ctx *ctx, int64_t ts_start, int64_t ts_end, unsigned int flags,
YV12_BUFFER_CONFIG *src, unsigned char *active_map) {
int64_t ts_start,
int64_t ts_end,
unsigned int flags,
unsigned char *active_map) {
struct lookahead_entry *buf; struct lookahead_entry *buf;
int row, col, active_end; int row, col, active_end;
int mb_rows = (src->y_height + 15) >> 4; int mb_rows = (src->y_height + 15) >> 4;
...@@ -156,9 +148,8 @@ vp9_lookahead_push(struct lookahead_ctx *ctx, ...@@ -156,9 +148,8 @@ vp9_lookahead_push(struct lookahead_ctx *ctx,
} }
struct lookahead_entry * struct lookahead_entry * vp9_lookahead_pop(struct lookahead_ctx *ctx,
vp9_lookahead_pop(struct lookahead_ctx *ctx, int drain) {
int drain) {
struct lookahead_entry *buf = NULL; struct lookahead_entry *buf = NULL;
if (ctx->sz && (drain || ctx->sz == ctx->max_sz)) { if (ctx->sz && (drain || ctx->sz == ctx->max_sz)) {
...@@ -169,9 +160,8 @@ vp9_lookahead_pop(struct lookahead_ctx *ctx, ...@@ -169,9 +160,8 @@ vp9_lookahead_pop(struct lookahead_ctx *ctx,
} }
struct lookahead_entry * struct lookahead_entry * vp9_lookahead_peek(struct lookahead_ctx *ctx,
vp9_lookahead_peek(struct lookahead_ctx *ctx, int index) {
int index) {
struct lookahead_entry *buf = NULL; struct lookahead_entry *buf = NULL;
assert(index < (int)ctx->max_sz); assert(index < (int)ctx->max_sz);
...@@ -184,8 +174,6 @@ vp9_lookahead_peek(struct lookahead_ctx *ctx, ...@@ -184,8 +174,6 @@ vp9_lookahead_peek(struct lookahead_ctx *ctx,
return buf; return buf;
} }
unsigned int vp9_lookahead_depth(struct lookahead_ctx *ctx) {
unsigned int
vp9_lookahead_depth(struct lookahead_ctx *ctx) {
return ctx->sz; return ctx->sz;
} }
...@@ -28,17 +28,13 @@ struct lookahead_ctx; ...@@ -28,17 +28,13 @@ struct lookahead_ctx;
* *
* The lookahead stage is a queue of frame buffers on which some analysis * The lookahead stage is a queue of frame buffers on which some analysis
* may be done when buffers are enqueued. * may be done when buffers are enqueued.
*
*
*/ */
struct lookahead_ctx *vp9_lookahead_init(unsigned int width, struct lookahead_ctx *vp9_lookahead_init(unsigned int width,
unsigned int height, unsigned int height,
unsigned int depth unsigned int depth);
);
/**\brief Destroys the lookahead stage /**\brief Destroys the lookahead stage
*
*/ */
void vp9_lookahead_destroy(struct lookahead_ctx *ctx); void vp9_lookahead_destroy(struct lookahead_ctx *ctx);
...@@ -58,13 +54,9 @@ void vp9_lookahead_destroy(struct lookahead_ctx *ctx); ...@@ -58,13 +54,9 @@ void vp9_lookahead_destroy(struct lookahead_ctx *ctx);
* \param[in] flags Flags set on this frame * \param[in] flags Flags set on this frame
* \param[in] active_map Map that specifies which macroblock is active * \param[in] active_map Map that specifies which macroblock is active
*/ */
int int vp9_lookahead_push(struct lookahead_ctx *ctx, YV12_BUFFER_CONFIG *src,
vp9_lookahead_push(struct lookahead_ctx *ctx, int64_t ts_start, int64_t ts_end, unsigned int flags,
YV12_BUFFER_CONFIG *src, unsigned char *active_map);
int64_t ts_start,
int64_t ts_end,
unsigned int flags,
unsigned char *active_map);
/**\brief Get the next source buffer to encode /**\brief Get the next source buffer to encode
...@@ -76,11 +68,9 @@ vp9_lookahead_push(struct lookahead_ctx *ctx, ...@@ -76,11 +68,9 @@ vp9_lookahead_push(struct lookahead_ctx *ctx,
* *
* \retval NULL, if drain set and queue is empty * \retval NULL, if drain set and queue is empty
* \retval NULL, if drain not set and queue not of the configured depth * \retval NULL, if drain not set and queue not of the configured depth
*
*/ */
struct lookahead_entry * struct lookahead_entry *vp9_lookahead_pop(struct lookahead_ctx *ctx,
vp9_lookahead_pop(struct lookahead_ctx *ctx, int drain);
int drain);
/**\brief Get a future source buffer to encode /**\brief Get a future source buffer to encode
...@@ -89,18 +79,15 @@ vp9_lookahead_pop(struct lookahead_ctx *ctx, ...@@ -89,18 +79,15 @@ vp9_lookahead_pop(struct lookahead_ctx *ctx,
* \param[in] index Index of the frame to be returned, 0 == next frame * \param[in] index Index of the frame to be returned, 0 == next frame
* *
* \retval NULL, if no buffer exists at the specified index * \retval NULL, if no buffer exists at the specified index
*
*/ */
struct lookahead_entry * struct lookahead_entry *vp9_lookahead_peek(struct lookahead_ctx *ctx,
vp9_lookahead_peek(struct lookahead_ctx *ctx, int index);
int index);
/**\brief Get the number of frames currently in the lookahead queue /**\brief Get the number of frames currently in the lookahead queue
* *
* \param[in] ctx Pointer to the lookahead context * \param[in] ctx Pointer to the lookahead context
*/ */
unsigned int unsigned int vp9_lookahead_depth(struct lookahead_ctx *ctx);
vp9_lookahead_depth(struct lookahead_ctx *ctx);
#endif // VP9_ENCODER_VP9_LOOKAHEAD_H_ #endif // VP9_ENCODER_VP9_LOOKAHEAD_H_
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment