Commit b6f02c85 authored by Paul Wilkins's avatar Paul Wilkins

Code Simplification

Removal of code relating to token partitioning

Change-Id: Iaf3c88d6758639a55bd92c3be5c51e6bed407a3c
parent eb87b56e
......@@ -218,7 +218,6 @@ void vp8_create_common(VP8_COMMON *oci)
oci->filter_type = NORMAL_LOOPFILTER;
oci->use_bilinear_mc_filter = 0;
oci->full_pixel = 0;
oci->multi_token_partition = ONE_PARTITION;
oci->clr_type = REG_YUV;
oci->clamp_type = RECON_CLAMP_REQUIRED;
......
......@@ -166,8 +166,6 @@ extern "C"
int play_alternate;
int alt_freq;
int multi_threaded; // how many threads to run the encoder on
int token_partitions; // how many token partitions to create for multi core decoding
int encode_breakout; // early breakout encode threshold : for video conf recommend 800
int arnr_max_frames;
......
......@@ -62,14 +62,6 @@ typedef struct frame_contexts
MV_CONTEXT pre_mvc[2]; /* not to caculate the mvcost for the frame if mvc doesn't change. */
} FRAME_CONTEXT;
typedef enum
{
ONE_PARTITION = 0,
TWO_PARTITION = 1,
FOUR_PARTITION = 2,
EIGHT_PARTITION = 3
} TOKEN_PARTITION;
typedef enum
{
RECON_CLAMP_REQUIRED = 0,
......@@ -259,8 +251,6 @@ typedef struct VP8Common
int near_boffset[3];
int version;
TOKEN_PARTITION multi_token_partition;
#ifdef PACKET_TESTING
VP8_HEADER oh;
#endif
......
......@@ -692,43 +692,6 @@ static unsigned int read_partition_size(const unsigned char *cx_size)
return size;
}
static void setup_token_decoder_partition_input(VP8D_COMP *pbi)
{
vp8_reader *bool_decoder = &pbi->bc2;
int part_idx = 1;
int num_token_partitions;
TOKEN_PARTITION multi_token_partition =
(TOKEN_PARTITION)vp8_read_literal(&pbi->bc, 2);
if (!vp8dx_bool_error(&pbi->bc))
pbi->common.multi_token_partition = multi_token_partition;
num_token_partitions = 1 << pbi->common.multi_token_partition;
if (num_token_partitions + 1 > pbi->num_partitions)
vpx_internal_error(&pbi->common.error, VPX_CODEC_CORRUPT_FRAME,
"Partitions missing");
assert(vp8dx_bool_error(&pbi->bc) ||
multi_token_partition == pbi->common.multi_token_partition);
if (pbi->num_partitions > 2)
{
CHECK_MEM_ERROR(pbi->mbc, vpx_malloc((pbi->num_partitions - 1) *
sizeof(vp8_reader)));
bool_decoder = pbi->mbc;
}
for (; part_idx < pbi->num_partitions; ++part_idx)
{
if (vp8dx_start_decode(bool_decoder,
pbi->partitions[part_idx],
pbi->partition_sizes[part_idx]))
vpx_internal_error(&pbi->common.error, VPX_CODEC_MEM_ERROR,
"Failed to allocate bool decoder %d",
part_idx);
bool_decoder++;
}
}
static int read_is_valid(const unsigned char *start,
size_t len,
const unsigned char *end)
......@@ -740,88 +703,37 @@ static int read_is_valid(const unsigned char *start,
static void setup_token_decoder(VP8D_COMP *pbi,
const unsigned char *cx_data)
{
int num_part;
int i;
VP8_COMMON *pc = &pbi->common;
const unsigned char *user_data_end = pbi->Source + pbi->source_sz;
vp8_reader *bool_decoder;
const unsigned char *partition;
/* Parse number of token partitions to use */
const TOKEN_PARTITION multi_token_partition =
(TOKEN_PARTITION)vp8_read_literal(&pbi->bc, 2);
/* Only update the multi_token_partition field if we are sure the value
* is correct. */
if (!vp8dx_bool_error(&pbi->bc))
pc->multi_token_partition = multi_token_partition;
ptrdiff_t partition_size;
ptrdiff_t bytes_left;
num_part = 1 << pc->multi_token_partition;
// Dummy read for now
vp8_read_literal(&pbi->bc, 2);
/* Set up pointers to the first partition */
// Set up pointers to token partition
partition = cx_data;
bool_decoder = &pbi->bc2;
bytes_left = user_data_end - partition;
partition_size = bytes_left;
if (num_part > 1)
{
CHECK_MEM_ERROR(pbi->mbc, vpx_malloc(num_part * sizeof(vp8_reader)));
bool_decoder = pbi->mbc;
partition += 3 * (num_part - 1);
}
for (i = 0; i < num_part; i++)
/* Validate the calculated partition length. If the buffer
* described by the partition can't be fully read, then restrict
* it to the portion that can be (for EC mode) or throw an error.
*/
if (!read_is_valid(partition, partition_size, user_data_end))
{
const unsigned char *partition_size_ptr = cx_data + i * 3;
ptrdiff_t partition_size, bytes_left;
bytes_left = user_data_end - partition;
/* Calculate the length of this partition. The last partition
* size is implicit. If the partition size can't be read, then
* either use the remaining data in the buffer (for EC mode)
* or throw an error.
*/
if (i < num_part - 1)
{
if (read_is_valid(partition_size_ptr, 3, user_data_end))
partition_size = read_partition_size(partition_size_ptr);
else
vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
"Truncated partition size data");
}
else
partition_size = bytes_left;
/* Validate the calculated partition length. If the buffer
* described by the partition can't be fully read, then restrict
* it to the portion that can be (for EC mode) or throw an error.
*/
if (!read_is_valid(partition, partition_size, user_data_end))
{
vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
"Truncated packet or corrupt partition "
"%d length", i + 1);
}
if (vp8dx_start_decode(bool_decoder, partition, partition_size))
vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
"Failed to allocate bool decoder %d", i + 1);
/* Advance to the next partition */
partition += partition_size;
bool_decoder++;
vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME,
"Truncated packet or corrupt partition "
"%d length", 1);
}
}
static void stop_token_decoder(VP8D_COMP *pbi)
{
VP8_COMMON *pc = &pbi->common;
if (pc->multi_token_partition != ONE_PARTITION)
{
vpx_free(pbi->mbc);
pbi->mbc = NULL;
}
if (vp8dx_start_decode(bool_decoder, partition, partition_size))
vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR,
"Failed to allocate bool decoder %d", 1);
}
static void init_frame(VP8D_COMP *pbi)
......@@ -925,12 +837,6 @@ int vp8_decode_frame(VP8D_COMP *pbi)
int corrupt_tokens = 0;
int prev_independent_partitions = pbi->independent_partitions;
if (pbi->input_partition)
{
data = pbi->partitions[0];
data_end = data + pbi->partition_sizes[0];
}
/* start with no corruption of current frame */
xd->corrupted = 0;
pc->yv12_fb[pc->new_fb_idx].corrupted = 0;
......@@ -1218,14 +1124,8 @@ int vp8_decode_frame(VP8D_COMP *pbi)
}
}
if (pbi->input_partition)
{
setup_token_decoder_partition_input(pbi);
}
else
{
setup_token_decoder(pbi, data + first_partition_length_in_bytes);
}
setup_token_decoder(pbi, data + first_partition_length_in_bytes);
xd->current_bc = &pbi->bc2;
/* Read the default quantizers. */
......@@ -1390,47 +1290,22 @@ int vp8_decode_frame(VP8D_COMP *pbi)
// Resset the macroblock mode info context to the start of the list
xd->mode_info_context = pc->mi;
{
int ibc = 0;
int num_part = 1 << pc->multi_token_partition;
pbi->frame_corrupt_residual = 0;
pbi->frame_corrupt_residual = 0;
#if CONFIG_SUPERBLOCKS
/* Decode a row of super-blocks */
for (mb_row = 0; mb_row < pc->mb_rows; mb_row+=2)
{
if (num_part > 1)
{
xd->current_bc = & pbi->mbc[ibc];
ibc++;
if (ibc == num_part)
ibc = 0;
}
decode_sb_row(pbi, pc, mb_row, xd);
}
/* Decode a row of super-blocks */
for (mb_row = 0; mb_row < pc->mb_rows; mb_row+=2)
{
decode_sb_row(pbi, pc, mb_row, xd);
}
#else
/* Decode a row of macro blocks */
for (mb_row = 0; mb_row < pc->mb_rows; mb_row++)
{
if (num_part > 1)
{
xd->current_bc = & pbi->mbc[ibc];
ibc++;
if (ibc == num_part)
ibc = 0;
}
decode_mb_row(pbi, pc, mb_row, xd);
}
#endif /* CONFIG_SUPERBLOCKS */
corrupt_tokens |= xd->corrupted;
/* Decode a row of macro blocks */
for (mb_row = 0; mb_row < pc->mb_rows; mb_row++)
{
decode_mb_row(pbi, pc, mb_row, xd);
}
stop_token_decoder(pbi);
#endif /* CONFIG_SUPERBLOCKS */
corrupt_tokens |= xd->corrupted;
/* Collect information about decoder corruption. */
/* 1. Check first boolean decoder for errors. */
......
......@@ -161,7 +161,6 @@ VP8D_PTR vp8dx_create_decompressor(VP8D_CONFIG *oxcf)
pbi->decoded_key_frame = 0;
pbi->input_partition = oxcf->input_partition;
/* Independent partitions is activated when a frame updates the
* token probability table to have equal probabilities over the
......@@ -383,101 +382,55 @@ int vp8dx_receive_compressed_data(VP8D_PTR ptr, unsigned long size, const unsign
pbi->common.error.error_code = VPX_CODEC_OK;
if (pbi->input_partition && !(source == NULL && size == 0))
pbi->Source = source;
pbi->source_sz = size;
if (pbi->source_sz == 0)
{
/* Store a pointer to this partition and return. We haven't
* received the complete frame yet, so we will wait with decoding.
*/
assert(pbi->num_partitions < MAX_PARTITIONS);
pbi->partitions[pbi->num_partitions] = source;
pbi->partition_sizes[pbi->num_partitions] = size;
pbi->source_sz += size;
pbi->num_partitions++;
if (pbi->num_partitions > (1 << EIGHT_PARTITION) + 1)
{
pbi->common.error.error_code = VPX_CODEC_UNSUP_BITSTREAM;
pbi->common.error.setjmp = 0;
pbi->num_partitions = 0;
return -1;
}
return 0;
/* This is used to signal that we are missing frames.
* We do not know if the missing frame(s) was supposed to update
* any of the reference buffers, but we act conservative and
* mark only the last buffer as corrupted.
*/
cm->yv12_fb[cm->lst_fb_idx].corrupted = 1;
}
else
{
if (!pbi->input_partition)
{
pbi->Source = source;
pbi->source_sz = size;
}
else
{
assert(pbi->common.multi_token_partition <= EIGHT_PARTITION);
if (pbi->num_partitions == 0)
{
pbi->num_partitions = 1;
pbi->partitions[0] = NULL;
pbi->partition_sizes[0] = 0;
}
while (pbi->num_partitions < (1 << pbi->common.multi_token_partition) + 1)
{
// Reset all missing partitions
pbi->partitions[pbi->num_partitions] =
pbi->partitions[pbi->num_partitions - 1] +
pbi->partition_sizes[pbi->num_partitions - 1];
pbi->partition_sizes[pbi->num_partitions] = 0;
pbi->num_partitions++;
}
}
if (pbi->source_sz == 0)
{
/* This is used to signal that we are missing frames.
* We do not know if the missing frame(s) was supposed to update
* any of the reference buffers, but we act conservative and
* mark only the last buffer as corrupted.
*/
cm->yv12_fb[cm->lst_fb_idx].corrupted = 1;
}
#if HAVE_ARMV7
#if CONFIG_RUNTIME_CPU_DETECT
if (cm->rtcd.flags & HAS_NEON)
if (cm->rtcd.flags & HAS_NEON)
#endif
{
vp8_push_neon(dx_store_reg);
}
{
vp8_push_neon(dx_store_reg);
}
#endif
cm->new_fb_idx = get_free_fb (cm);
cm->new_fb_idx = get_free_fb (cm);
if (setjmp(pbi->common.error.jmp))
{
if (setjmp(pbi->common.error.jmp))
{
#if HAVE_ARMV7
#if CONFIG_RUNTIME_CPU_DETECT
if (cm->rtcd.flags & HAS_NEON)
if (cm->rtcd.flags & HAS_NEON)
#endif
{
vp8_pop_neon(dx_store_reg);
}
{
vp8_pop_neon(dx_store_reg);
}
#endif
pbi->common.error.setjmp = 0;
pbi->num_partitions = 0;
/* We do not know if the missing frame(s) was supposed to update
* any of the reference buffers, but we act conservative and
* mark only the last buffer as corrupted.
*/
cm->yv12_fb[cm->lst_fb_idx].corrupted = 1;
pbi->common.error.setjmp = 0;
if (cm->fb_idx_ref_cnt[cm->new_fb_idx] > 0)
cm->fb_idx_ref_cnt[cm->new_fb_idx]--;
return -1;
}
/* We do not know if the missing frame(s) was supposed to update
* any of the reference buffers, but we act conservative and
* mark only the last buffer as corrupted.
*/
cm->yv12_fb[cm->lst_fb_idx].corrupted = 1;
pbi->common.error.setjmp = 1;
if (cm->fb_idx_ref_cnt[cm->new_fb_idx] > 0)
cm->fb_idx_ref_cnt[cm->new_fb_idx]--;
return -1;
}
pbi->common.error.setjmp = 1;
retcode = vp8_decode_frame(pbi);
if (retcode < 0)
......@@ -492,7 +445,6 @@ int vp8dx_receive_compressed_data(VP8D_PTR ptr, unsigned long size, const unsign
#endif
pbi->common.error.error_code = VPX_CODEC_ERROR;
pbi->common.error.setjmp = 0;
pbi->num_partitions = 0;
if (cm->fb_idx_ref_cnt[cm->new_fb_idx] > 0)
cm->fb_idx_ref_cnt[cm->new_fb_idx]--;
return retcode;
......@@ -511,7 +463,6 @@ int vp8dx_receive_compressed_data(VP8D_PTR ptr, unsigned long size, const unsign
#endif
pbi->common.error.error_code = VPX_CODEC_ERROR;
pbi->common.error.setjmp = 0;
pbi->num_partitions = 0;
return -1;
}
......@@ -556,7 +507,6 @@ int vp8dx_receive_compressed_data(VP8D_PTR ptr, unsigned long size, const unsign
pbi->ready_for_new_data = 0;
pbi->last_time_stamp = time_stamp;
pbi->num_partitions = 0;
pbi->source_sz = 0;
#if 0
......
......@@ -100,7 +100,6 @@ typedef struct VP8Decompressor
vp8_prob prob_skip_false;
int input_partition;
int decoded_key_frame;
int independent_partitions;
int frame_corrupt_residual;
......
......@@ -353,415 +353,6 @@ static void write_partition_size(unsigned char *cx_data, int size)
}
static void pack_tokens_into_partitions_c(VP8_COMP *cpi, unsigned char *cx_data, int num_part, int *size)
{
int i;
unsigned char *ptr = cx_data;
unsigned int shift;
vp8_writer *w = &cpi->bc2;
*size = 3 * (num_part - 1);
cpi->partition_sz[0] += *size;
ptr = cx_data + (*size);
for (i = 0; i < num_part; i++)
{
vp8_start_encode(w, ptr);
{
unsigned int split;
int count = w->count;
unsigned int range = w->range;
unsigned int lowvalue = w->lowvalue;
int mb_row;
for (mb_row = i; mb_row < cpi->common.mb_rows; mb_row += num_part)
{
TOKENEXTRA *p = cpi->tplist[mb_row].start;
TOKENEXTRA *stop = cpi->tplist[mb_row].stop;
while (p < stop)
{
const int t = p->Token;
vp8_token *const a = vp8_coef_encodings + t;
const vp8_extra_bit_struct *const b = vp8_extra_bits + t;
int i = 0;
const unsigned char *pp = p->context_tree;
int v = a->value;
int n = a->Len;
if (p->skip_eob_node)
{
n--;
i = 2;
}
do
{
const int bb = (v >> --n) & 1;
split = 1 + (((range - 1) * pp[i>>1]) >> 8);
i = vp8_coef_tree[i+bb];
if (bb)
{
lowvalue += split;
range = range - split;
}
else
{
range = split;
}
shift = vp8_norm[range];
range <<= shift;
count += shift;
if (count >= 0)
{
int offset = shift - count;
if ((lowvalue << (offset - 1)) & 0x80000000)
{
int x = w->pos - 1;
while (x >= 0 && w->buffer[x] == 0xff)
{
w->buffer[x] = (unsigned char)0;
x--;
}
w->buffer[x] += 1;
}
w->buffer[w->pos++] = (lowvalue >> (24 - offset));
lowvalue <<= offset;
shift = count;
lowvalue &= 0xffffff;
count -= 8 ;
}
lowvalue <<= shift;
}
while (n);
if (b->base_val)
{
const int e = p->Extra, L = b->Len;
if (L)
{
const unsigned char *pp = b->prob;
int v = e >> 1;
int n = L; /* number of bits in v, assumed nonzero */
int i = 0;
do
{
const int bb = (v >> --n) & 1;
split = 1 + (((range - 1) * pp[i>>1]) >> 8);
i = b->tree[i+bb];
if (bb)
{
lowvalue += split;
range = range - split;
}
else
{
range = split;
}
shift = vp8_norm[range];
range <<= shift;
count += shift;
if (count >= 0)
{
int offset = shift - count;
if ((lowvalue << (offset - 1)) & 0x80000000)
{
int x = w->pos - 1;
while (x >= 0 && w->buffer[x] == 0xff)
{
w->buffer[x] = (unsigned char)0;
x--;
}
w->buffer[x] += 1;
}
w->buffer[w->pos++] = (lowvalue >> (24 - offset));
lowvalue <<= offset;
shift = count;
lowvalue &= 0xffffff;
count -= 8 ;
}
lowvalue <<= shift;
}
while (n);
}
{
split = (range + 1) >> 1;
if (e & 1)
{