summaryrefslogtreecommitdiff
path: root/vp8/encoder/bitstream.c
diff options
context:
space:
mode:
authorJohn Koleszar <jkoleszar@google.com>2012-02-21 10:09:23 -0800
committerGerrit Code Review <gerrit@gerrit.golo.chromium.org>2012-02-21 10:09:23 -0800
commitdadc9189ed3e6a1b5efd77333e6037d2b0e2f398 (patch)
treed6359aed62c1165b41b033115991e91e99a423f4 /vp8/encoder/bitstream.c
parentf05feab7b967ffd717d9437b7803bfbcaeced9a4 (diff)
parentd02e74a0732896b632880884b3d839a316473ae0 (diff)
downloadlibvpx-dadc9189ed3e6a1b5efd77333e6037d2b0e2f398.tar
libvpx-dadc9189ed3e6a1b5efd77333e6037d2b0e2f398.tar.gz
libvpx-dadc9189ed3e6a1b5efd77333e6037d2b0e2f398.tar.bz2
libvpx-dadc9189ed3e6a1b5efd77333e6037d2b0e2f398.zip
Merge changes I0341554f,I64e110c8
* changes: Consolidate C version of token packing functions Multithreaded encoder, late sync loopfilter
Diffstat (limited to 'vp8/encoder/bitstream.c')
-rw-r--r--vp8/encoder/bitstream.c416
1 files changed, 14 insertions, 402 deletions
diff --git a/vp8/encoder/bitstream.c b/vp8/encoder/bitstream.c
index 512c5d193..f26b4e4eb 100644
--- a/vp8/encoder/bitstream.c
+++ b/vp8/encoder/bitstream.c
@@ -382,219 +382,23 @@ static void pack_tokens_into_partitions_c(VP8_COMP *cpi, unsigned char *cx_data,
int i;
unsigned char *ptr = cx_data;
unsigned char *ptr_end = cx_data_end;
- unsigned int shift;
- vp8_writer *w;
- ptr = cx_data;
+ vp8_writer * w;
for (i = 0; i < num_part; i++)
{
- w = cpi->bc + i + 1;
- vp8_start_encode(w, ptr, ptr_end);
- {
- 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;
+ int mb_row;
- 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;
- }
-
- validate_buffer(w->buffer + w->pos,
- 1,
- cx_data_end,
- &cpi->common.error);
-
- 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;
- }
-
- validate_buffer(w->buffer + w->pos,
- 1,
- cx_data_end,
- &cpi->common.error);
-
- 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)
- {
- lowvalue += split;
- range = range - split;
- }
- else
- {
- range = split;
- }
-
- range <<= 1;
-
- if ((lowvalue & 0x80000000))
- {
- int x = w->pos - 1;
-
- while (x >= 0 && w->buffer[x] == 0xff)
- {
- w->buffer[x] = (unsigned char)0;
- x--;
- }
-
- w->buffer[x] += 1;
-
- }
-
- lowvalue <<= 1;
-
- if (!++count)
- {
- count = -8;
- validate_buffer(w->buffer + w->pos,
- 1,
- cx_data_end,
- &cpi->common.error);
-
- w->buffer[w->pos++] = (lowvalue >> 24);
-
- lowvalue &= 0xffffff;
- }
- }
-
- }
+ w = cpi->bc + i + 1;
- ++p;
- }
- }
+ vp8_start_encode(w, ptr, ptr_end);
- w->count = count;
- w->lowvalue = lowvalue;
- w->range = range;
+ for (mb_row = i; mb_row < cpi->common.mb_rows; mb_row += num_part)
+ {
+ const TOKENEXTRA *p = cpi->tplist[mb_row].start;
+ const TOKENEXTRA *stop = cpi->tplist[mb_row].stop;
+ int tokens = stop - p;
+ pack_tokens_c(w, p, tokens);
}
vp8_stop_encode(w);
@@ -605,209 +409,17 @@ static void pack_tokens_into_partitions_c(VP8_COMP *cpi, unsigned char *cx_data,
static void pack_mb_row_tokens_c(VP8_COMP *cpi, vp8_writer *w)
{
-
- unsigned int split;
- int count = w->count;
- unsigned int range = w->range;
- unsigned int lowvalue = w->lowvalue;
- unsigned int shift;
int mb_row;
for (mb_row = 0; mb_row < cpi->common.mb_rows; mb_row++)
{
- 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;
- }
-
- validate_buffer(w->buffer + w->pos,
- 1,
- w->buffer_end,
- w->error);
-
- 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;
- }
-
- validate_buffer(w->buffer + w->pos,
- 1,
- w->buffer_end,
- w->error);
+ const TOKENEXTRA *p = cpi->tplist[mb_row].start;
+ const TOKENEXTRA *stop = cpi->tplist[mb_row].stop;
+ int tokens = stop - p;
- 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)
- {
- lowvalue += split;
- range = range - split;
- }
- else
- {
- range = split;
- }
-
- range <<= 1;
-
- if ((lowvalue & 0x80000000))
- {
- int x = w->pos - 1;
-
- while (x >= 0 && w->buffer[x] == 0xff)
- {
- w->buffer[x] = (unsigned char)0;
- x--;
- }
-
- w->buffer[x] += 1;
-
- }
-
- lowvalue <<= 1;
-
- if (!++count)
- {
- count = -8;
-
- validate_buffer(w->buffer + w->pos,
- 1,
- w->buffer_end,
- w->error);
-
- w->buffer[w->pos++] = (lowvalue >> 24);
- lowvalue &= 0xffffff;
- }
- }
-
- }
-
- ++p;
- }
+ pack_tokens_c(w, p, tokens);
}
- w->count = count;
- w->lowvalue = lowvalue;
- w->range = range;
-
}
static void write_mv_ref