Code cleanup.

Writing all #define guards using the same style. Inlining macro
VP8DX_BOOL_DECODER_FILL into vp8dx_bool_decoder_fill. Removing unnecessary
includes.

Change-Id: I483fa979ab34008bf7835b5f34c6471c44daf956
This commit is contained in:
Dmitry Kovalev
2013-03-04 16:53:00 -08:00
parent 403145032d
commit 33efdfec3f
11 changed files with 62 additions and 79 deletions

View File

@@ -10,8 +10,6 @@
#include "dboolhuff.h" #include "dboolhuff.h"
#include "vpx_ports/mem.h"
#include "vpx_mem/vpx_mem.h"
int vp8dx_start_decode(BOOL_DECODER *br, int vp8dx_start_decode(BOOL_DECODER *br,
const unsigned char *source, const unsigned char *source,
@@ -32,19 +30,32 @@ int vp8dx_start_decode(BOOL_DECODER *br,
return 0; return 0;
} }
void vp8dx_bool_decoder_fill(BOOL_DECODER *br) void vp8dx_bool_decoder_fill(BOOL_DECODER *br)
{ {
const unsigned char *bufptr; const unsigned char *bufptr = br->user_buffer;
const unsigned char *bufend; const unsigned char *bufend = br->user_buffer_end;
VP8_BD_VALUE value; VP8_BD_VALUE value = br->value;
int count; int count = br->count;
bufend = br->user_buffer_end; int shift = VP8_BD_VALUE_SIZE - 8 - (count + 8);
bufptr = br->user_buffer; size_t bits_left = (bufend - bufptr)*CHAR_BIT;
value = br->value; int x = (int)(shift + CHAR_BIT - bits_left);
count = br->count; int loop_end = 0;
VP8DX_BOOL_DECODER_FILL(count, value, bufptr, bufend); if(x >= 0)
{
count += VP8_LOTS_OF_BITS;
loop_end = x;
}
if (x < 0 || bits_left)
{
while(shift >= loop_end)
{
count += CHAR_BIT;
value |= (VP8_BD_VALUE)*bufptr++ << shift;
shift -= CHAR_BIT;
}
}
br->user_buffer = bufptr; br->user_buffer = bufptr;
br->value = value; br->value = value;

View File

@@ -9,21 +9,24 @@
*/ */
#ifndef DBOOLHUFF_H #ifndef DBOOLHUFF_H_
#define DBOOLHUFF_H #define DBOOLHUFF_H_
#include <stddef.h> #include <stddef.h>
#include <limits.h> #include <limits.h>
#include "vpx_config.h" #include "vpx_config.h"
#include "vpx_ports/mem.h" #include "vpx_ports/mem.h"
#include "vpx/vpx_integer.h" #include "vpx/vpx_integer.h"
typedef size_t VP8_BD_VALUE; typedef size_t VP8_BD_VALUE;
# define VP8_BD_VALUE_SIZE ((int)sizeof(VP8_BD_VALUE)*CHAR_BIT) #define VP8_BD_VALUE_SIZE ((int)sizeof(VP8_BD_VALUE)*CHAR_BIT)
/*This is meant to be a large, positive constant that can still be efficiently /*This is meant to be a large, positive constant that can still be efficiently
loaded as an immediate (on platforms like ARM, for example). loaded as an immediate (on platforms like ARM, for example).
Even relatively modest values like 100 would work fine.*/ Even relatively modest values like 100 would work fine.*/
# define VP8_LOTS_OF_BITS (0x40000000) #define VP8_LOTS_OF_BITS (0x40000000)
typedef struct typedef struct
{ {
@@ -42,36 +45,6 @@ int vp8dx_start_decode(BOOL_DECODER *br,
void vp8dx_bool_decoder_fill(BOOL_DECODER *br); void vp8dx_bool_decoder_fill(BOOL_DECODER *br);
/*The refill loop is used in several places, so define it in a macro to make
sure they're all consistent.
An inline function would be cleaner, but has a significant penalty, because
multiple BOOL_DECODER fields must be modified, and the compiler is not smart
enough to eliminate the stores to those fields and the subsequent reloads
from them when inlining the function.*/
#define VP8DX_BOOL_DECODER_FILL(_count,_value,_bufptr,_bufend) \
do \
{ \
int shift = VP8_BD_VALUE_SIZE - 8 - ((_count) + 8); \
int loop_end, x; \
size_t bits_left = ((_bufend)-(_bufptr))*CHAR_BIT; \
\
x = (int)(shift + CHAR_BIT - bits_left); \
loop_end = 0; \
if(x >= 0) \
{ \
(_count) += VP8_LOTS_OF_BITS; \
loop_end = x; \
if(!bits_left) break; \
} \
while(shift >= loop_end) \
{ \
(_count) += CHAR_BIT; \
(_value) |= (VP8_BD_VALUE)*(_bufptr)++ << shift; \
shift -= CHAR_BIT; \
} \
} \
while(0) \
static int vp8dx_decode_bool(BOOL_DECODER *br, int probability) { static int vp8dx_decode_bool(BOOL_DECODER *br, int probability) {
unsigned int bit = 0; unsigned int bit = 0;
@@ -151,4 +124,5 @@ static int vp8dx_bool_error(BOOL_DECODER *br)
/* No error. */ /* No error. */
return 0; return 0;
} }
#endif
#endif // DBOOLHUFF_H_

View File

@@ -8,7 +8,11 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#ifndef DECODEMV_H_
#define DECODEMV_H_
#include "onyxd_int.h" #include "onyxd_int.h"
void vp8_decode_mode_mvs(VP8D_COMP *); void vp8_decode_mode_mvs(VP8D_COMP *);
#endif // DECODEMV_H_

View File

@@ -8,19 +8,15 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#ifndef DECODERTHREADING_H_
#define DECODERTHREADING_H_
#ifndef _DECODER_THREADING_H
#define _DECODER_THREADING_H
#if CONFIG_MULTITHREAD #if CONFIG_MULTITHREAD
extern void vp8mt_decode_mb_rows(VP8D_COMP *pbi, MACROBLOCKD *xd); void vp8mt_decode_mb_rows(VP8D_COMP *pbi, MACROBLOCKD *xd);
extern void vp8_decoder_remove_threads(VP8D_COMP *pbi); void vp8_decoder_remove_threads(VP8D_COMP *pbi);
extern void vp8_decoder_create_threads(VP8D_COMP *pbi); void vp8_decoder_create_threads(VP8D_COMP *pbi);
extern void vp8mt_alloc_temp_buffers(VP8D_COMP *pbi, int width, int prev_mb_rows); void vp8mt_alloc_temp_buffers(VP8D_COMP *pbi, int width, int prev_mb_rows);
extern void vp8mt_de_alloc_temp_buffers(VP8D_COMP *pbi, int mb_rows); void vp8mt_de_alloc_temp_buffers(VP8D_COMP *pbi, int mb_rows);
#endif #endif
#endif #endif // DECODERTHREADING_H_

View File

@@ -8,13 +8,12 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#ifndef DETOKENIZE_H_
#ifndef DETOKENIZE_H #define DETOKENIZE_H_
#define DETOKENIZE_H
#include "onyxd_int.h" #include "onyxd_int.h"
void vp8_reset_mb_tokens_context(MACROBLOCKD *x); void vp8_reset_mb_tokens_context(MACROBLOCKD *x);
int vp8_decode_mb_tokens(VP8D_COMP *, MACROBLOCKD *); int vp8_decode_mb_tokens(VP8D_COMP *, MACROBLOCKD *);
#endif /* DETOKENIZE_H */ #endif // DETOKENIZE_H

View File

@@ -14,7 +14,6 @@
#define MAX_OVERLAPS 16 #define MAX_OVERLAPS 16
/* The area (pixel area in Q6) the block pointed to by bmi overlaps /* The area (pixel area in Q6) the block pointed to by bmi overlaps
* another block with. * another block with.
*/ */
@@ -48,4 +47,4 @@ typedef struct
MV_REFERENCE_FRAME ref_frame; MV_REFERENCE_FRAME ref_frame;
} EC_BLOCK; } EC_BLOCK;
#endif /* VP8_DEC_EC_TYPES_H */ #endif // VP8_DEC_EC_TYPES_H

View File

@@ -8,14 +8,14 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include <assert.h>
#include "error_concealment.h" #include "error_concealment.h"
#include "onyxd_int.h" #include "onyxd_int.h"
#include "decodemv.h" #include "decodemv.h"
#include "vpx_mem/vpx_mem.h" #include "vpx_mem/vpx_mem.h"
#include "vp8/common/findnearmv.h" #include "vp8/common/findnearmv.h"
#include <assert.h>
#define MIN(x,y) (((x)<(y))?(x):(y)) #define MIN(x,y) (((x)<(y))?(x):(y))
#define MAX(x,y) (((x)>(y))?(x):(y)) #define MAX(x,y) (((x)>(y))?(x):(y))

View File

@@ -9,8 +9,8 @@
*/ */
#ifndef ERROR_CONCEALMENT_H #ifndef ERROR_CONCEALMENT_H_
#define ERROR_CONCEALMENT_H #define ERROR_CONCEALMENT_H_
#include "onyxd_int.h" #include "onyxd_int.h"
#include "ec_types.h" #include "ec_types.h"
@@ -38,4 +38,4 @@ void vp8_interpolate_motion(MACROBLOCKD *mb,
*/ */
void vp8_conceal_corrupt_mb(MACROBLOCKD *xd); void vp8_conceal_corrupt_mb(MACROBLOCKD *xd);
#endif #endif // ERROR_CONCEALMENT_H_

View File

@@ -9,8 +9,9 @@
*/ */
#ifndef __INC_VP8D_INT_H #ifndef ONYXD_INT_H_
#define __INC_VP8D_INT_H #define ONYXD_INT_H_
#include "vpx_config.h" #include "vpx_config.h"
#include "vp8/common/onyxd.h" #include "vp8/common/onyxd.h"
#include "treereader.h" #include "treereader.h"
@@ -145,4 +146,4 @@ int vp8_remove_decoder_instances(struct frame_buffers *fb);
} while(0) } while(0)
#endif #endif
#endif #endif // ONYXD_INT_H_

View File

@@ -36,7 +36,7 @@
} while (0) } while (0)
extern void vp8_mb_init_dequantizer(VP8D_COMP *pbi, MACROBLOCKD *xd); void vp8_mb_init_dequantizer(VP8D_COMP *pbi, MACROBLOCKD *xd);
static void setup_decoding_thread_data(VP8D_COMP *pbi, MACROBLOCKD *xd, MB_ROW_DEC *mbrd, int count) static void setup_decoding_thread_data(VP8D_COMP *pbi, MACROBLOCKD *xd, MB_ROW_DEC *mbrd, int count)
{ {

View File

@@ -9,18 +9,17 @@
*/ */
#ifndef tree_reader_h #ifndef TREEREADER_H_
#define tree_reader_h 1 #define TREEREADER_H_
#include "vp8/common/treecoder.h" #include "vp8/common/treecoder.h"
#include "dboolhuff.h" #include "dboolhuff.h"
typedef BOOL_DECODER vp8_reader; typedef BOOL_DECODER vp8_reader;
#define vp8_read vp8dx_decode_bool #define vp8_read vp8dx_decode_bool
#define vp8_read_literal vp8_decode_value #define vp8_read_literal vp8_decode_value
#define vp8_read_bit( R) vp8_read( R, vp8_prob_half) #define vp8_read_bit(R) vp8_read(R, vp8_prob_half)
/* Intent of tree data structure is to make decoding trivial. */ /* Intent of tree data structure is to make decoding trivial. */
@@ -38,4 +37,4 @@ static int vp8_treed_read(
return -i; return -i;
} }
#endif /* tree_reader_h */ #endif // TREEREADER_H_