Compare commits

...

36 Commits

Author SHA1 Message Date
John Koleszar
9e44920247 dixie: cosmetics (line length, braces, etc)
Pass code through AStyle transform, wrap long lines.

Change-Id: Icffa4fc3e9835ec152285ae0e98a1ff3f46e42e6
2011-03-08 13:00:10 -05:00
John Koleszar
246cc0881a dixie: remove unused variables
Change-Id: I9c9d83f441bbe1f268c2610e88d72f7a4adb353e
2011-02-08 09:50:20 -05:00
John Koleszar
51f9ef8e89 dixie: only use sixtap mc filter
Remove all the special case 2-tap, 4-tap, 16x16, 8x8, etc filters,
and instead just use one 2D 6-tap 4x4 filter.

Change-Id: I9ec560fb5609d1a3160e9a3d8b396911073517a0
2011-02-08 09:41:27 -05:00
John Koleszar
9f40e5650c dixie: simplify inter prediction
Always use 4x4 modes rather than special casing 2,4,16 blocks.

Change-Id: I0301da4b0ff1885d79c1ae07b084d2d9b7487f72
2011-02-07 11:53:00 -05:00
John Koleszar
252703291f dixie: simplify intra prediction
Removed all the special case intra prediction code for clarity.

Change-Id: I54c2435aedb2b5b00e668aa9e6d7c332af9cda3f
2011-02-07 09:25:22 -05:00
John Koleszar
26f91d31d1 dixie: simplify bool decoder
Use the simplified bool decoder from the bitstream guide, slightly
modified to prevent reading past the end of the buffer. Modified
the token decoder to use the normal bool decoder rather than
inlining its own.

Change-Id: Ic525e773e9f8331ba548a6505cc6d9e5372a5af0
2011-02-03 09:04:26 -05:00
John Koleszar
3688076d42 dixie: fix memory leaks
Implemented the decoder shutdown call to deallocate buffers when the
codec is destroyed.

Change-Id: I6cd62f40f34e0db91fb7eb8cb673f5d9726fe192
2011-02-03 00:26:37 -05:00
John Koleszar
52a1b7df97 dixie: handle buffer size changes
spatial resampling now supported.

Change-Id: Ifd959072b76ac3f8eeed00a0fd25acdde036defe
2011-02-03 00:07:32 -05:00
John Koleszar
def479510e dixie: support for simple lf, bilinear subpix
Initial support for simple loopfilter and bilinear subpixel motion
interpolation. This adds support for VP8 profiles 1-3 to dixie.

Change-Id: I76d45cf9843f6f7473783b7932af94f033eb6e82
2011-02-02 16:54:35 -05:00
John Koleszar
e75a400cd3 dixie: prevent read of uninitialized memory
When reallocating the framebuffer storage, clear references to the
freed memory to prevent it from being accessed.

Change-Id: Ib496b06be469328e8e269f905dc4c9cb6d453a27
2011-02-01 16:15:45 -05:00
John Koleszar
dbb7db5b43 dixie: correct reference buffer copies
The copy_{gf,arf} flags should copy the LAST buffer to the specified
buffer. The refresh_{gf,arf} flags should copy the CURRENT buffer to
the specified buffer.

Change-Id: I1fdf014c439b1ce584cda3d56841243fbfbb1f0a
2011-02-01 16:09:44 -05:00
John Koleszar
c565409a2a dixie: populate all dequant_factors
Missed incrementing the pointer, so only the first segment would be
populated.

Change-Id: I94419b2c678c8706ffe6e71bd134f3cf7853ba68
2011-02-01 16:07:52 -05:00
John Koleszar
6f2e4e1987 dixie: correct delta_q parsing
Cut and paste error caused UV delta Qs to overwrite Y1 DC delta Q.

Change-Id: I213506d830dbb54aa4cb100d56e0814ae10e0e2d
2011-02-01 16:06:16 -05:00
John Koleszar
f46f53d0de dixie: correct frame size check
Interframes have 3 byte headers, keyframes have 10 bytes.

Change-Id: I3886cb87dbc8ae175f82776f27c85603ca977af9
2011-02-01 14:12:41 -05:00
John Koleszar
37693cfd5a dixie: fix process_row when start_col>0
Change-Id: Ie3704c2ceb94fa3e49cd07a8c473b116b704a692
2010-08-06 15:30:51 -04:00
John Koleszar
0f15bbde8f dixie: add split four/six tap 2d filters
Change-Id: I7e2a20c129f9bb5a6a51833e0c5d659742c3b842
2010-08-06 15:30:51 -04:00
John Koleszar
754e60a64d dixie: fix 64 bit integer promotion issue.
Change-Id: I8efbed8fc79f9c1da3c84434c5b54c5100cbff0b
2010-08-06 15:30:50 -04:00
John Koleszar
da4255792a dixie: use emulated umv border
Change-Id: Ib6f6f2c20b11bc9b41847c097ab3a4a0025399b7
2010-08-06 15:30:49 -04:00
John Koleszar
421146312b dixie: add interframe reconstruction
This patch adds basic reconstruction for inter-predicted frames. It does
not properly handle clamping at the MV border.

Change-Id: Ib7e4395519aab0661a38f4e0f66972b5f08805cb
2010-08-05 10:46:13 -04:00
John Koleszar
829e2af0e1 dixie: add normal loopfilter
This is the more naive implementation as described in the bitstream guide,
rather than the masking version implemented in the reference code. However,
the core function prototypes were left as-is to make it easy to plug in the
reference assembly code.

Verified loopfiltered output matches reference decoder for 500 frames.

Change-Id: Ib4f197e864f07dbb918b6d5e742c6110d57c1f40
2010-07-12 16:36:57 -04:00
John Koleszar
06c0623219 dixie: add idct/add stage
Verified reconstructed (but not loopfiltered) output matches reference
decoder for 500 frames.

Change-Id: Iaa0c4bdd7733f1958cf2b8ed40d4c78f9028e298
2010-07-07 13:30:54 -04:00
John Koleszar
cf7705579b dixie: add intra prediction
This commit adds prediction functions for all the intra modes.

Change-Id: I626e245318f96ee2ce0d965d7454ac7dce0cff79
2010-07-07 13:29:42 -04:00
John Koleszar
940599ff2c dixie: combine dequant with token decode
Scales as O(number-of-tokens) rather than O(16).

Change-Id: Ic67b81289eeef7fedacd0b5973b7c06e5a507f29
2010-07-07 13:29:19 -04:00
John Koleszar
86262018ad dixie: implement token decoding
Verified decoded tokens match reference for all profile 0 test
vectors.

Change-Id: I3e5f7431cb0fbe7130331c82b434c4fd67f839cb
2010-06-24 15:00:26 -04:00
John Koleszar
b52ee87d2c dixie: sync bool decoder to latest
Incorporate the VP8DX_BOOL_DECODER_FILL macro, which is referenced by
the token decoder.

Change-Id: I32850279476d759e921634aa05c852217a571619
2010-06-24 15:00:25 -04:00
John Koleszar
9a63ff2243 dixie: move modemv data tables
Move these tables to their own file, to make modemv.c more readable.

Change-Id: I0c97e51c5b4601348f465be53e1c4b3c88cc7834
2010-06-24 15:00:24 -04:00
John Koleszar
41bad1f258 dixie: implement motion vector decoding
Verified decoded motion vectors match reference for all profile 0
test vectors.

Change-Id: Iee54bb4c37a32ca4493fa5694d7d29177fd6faa0
2010-06-24 15:00:24 -04:00
John Koleszar
29e1dea8cd dixie: implement keyframe mode decoding
Verified decoded modes matched reference decoder for 1 frame.

Change-Id: I69303aff8fa975dccc943bfe277ea86d55d75147
2010-06-24 15:00:22 -04:00
John Koleszar
c9ebe27ce4 dixie: decode entropy model header
Change-Id: I7a6cc0ac5656b50cac90c93a95adaecfe16efb72
2010-06-24 15:00:21 -04:00
John Koleszar
ca50290d6c dixie: decode reference frame header
Change-Id: I35a11c46d46430984cdcaf0ff7ef5f42f372d3c7
2010-06-24 15:00:20 -04:00
John Koleszar
476d59a304 dixie: decode quantizer level header
Change-Id: Ie8fe79280bcdae1b25ab69470d58ec4efee198d2
2010-06-24 15:00:19 -04:00
John Koleszar
f2274a34e6 dixie: decode token partitions header
Change-Id: Id894ef22c1a22a426fa4fcf3a3733711b723b9ec
2010-06-24 15:00:17 -04:00
John Koleszar
8d6fbc1bdf dixie: decode loopfilter header
Change-Id: Iab649cdb114d15e70ea632da911d8e3f5abbf36b
2010-06-24 15:00:15 -04:00
John Koleszar
948b1d4283 dixie: decode segmentation header
Change-Id: Id46c6f50ee60419ae1387baf74673af02475203d
2010-06-24 15:00:13 -04:00
John Koleszar
f766f3c8f3 dixie: simple validation of the frame header
Change-Id: Iae8c2d421eb686d652807d44d8053eaec8f72897
2010-06-24 15:00:12 -04:00
John Koleszar
5c263fa3ca dixie: initial interface
The "dixie" project will be a rewrite of much of the VP8 decoder core.
Some of the goals are:

  * Increase speed by paying more attention to data locality and
    cache layout, and by eliminating redundant work in general.

  * A different approach to multithreading, to treat all threads as
    equal and working on larger work units than a single MB.

  * Expose more of the bitstream to the application, essentially
    creating a vp8 parser utility. This could be useful for analyzing
    the complexity of a stream, to help set conformance points.

  * If the above goals are met successfully, replace the reference
    decoder.

For those interested in the etymology of the term "dixie:"
  decoder2 -> dx2 -> dxii -> dixie

Change-Id: I4ef0832b62ea96e9cfa1906c4a77f4b51e0c62d6
2010-06-24 15:00:06 -04:00
21 changed files with 5277 additions and 0 deletions

2
configure vendored
View File

@@ -242,6 +242,7 @@ CONFIG_LIST="
spatial_resampling
realtime_only
shared
dixie
"
CMDLINE_SELECT="
extra_warnings
@@ -280,6 +281,7 @@ CMDLINE_SELECT="
spatial_resampling
realtime_only
shared
dixie
"
process_cmdline() {

View File

@@ -29,6 +29,10 @@
static const char *exec_name;
#if CONFIG_DIXIE
extern vpx_codec_iface_t vpx_codec_vp8_dixie_algo;
#endif
static const struct
{
char const *name;
@@ -40,6 +44,9 @@ static const struct
#if CONFIG_VP8_DECODER
{"vp8", &vpx_codec_vp8_dx_algo, 0x00385056, 0x00FFFFFF},
#endif
#if CONFIG_DIXIE
{"dixie", &vpx_codec_vp8_dixie_algo, 0x00385056, 0x00FFFFFF},
#endif
};
#include "args.h"

19
vp8/dixie/bit_ops.h Normal file
View File

@@ -0,0 +1,19 @@
/*
* Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef BIT_OPS_H
#define BIT_OPS_H
/* Evaluates to a mask with n bits set */
#define BITS_MASK(n) ((1<<(n))-1)
/* Returns len bits, with the LSB at position bit */
#define BITS_GET(val, bit, len) (((val)>>(bit))&BITS_MASK(len))
#endif

144
vp8/dixie/bool_decoder.h Normal file
View File

@@ -0,0 +1,144 @@
/*
* Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license and
* patent grant that can be found in the LICENSE file in the root of
* the source tree. All contributing project authors may be found in
* the AUTHORS file in the root of the source tree.
*/
#ifndef BOOL_DECODER_H
#define BOOL_DECODER_H
#include <stddef.h>
struct bool_decoder
{
const unsigned char *input; /* next compressed data byte */
size_t input_len; /* length of the input buffer */
unsigned int range; /* identical to encoder's range */
unsigned int value; /* contains at least 8 significant
* bits */
int bit_count; /* # of bits shifted out of value,
* max 7 */
};
static void
init_bool_decoder(struct bool_decoder *d,
const unsigned char *start_partition,
size_t sz)
{
if (sz >= 2)
{
d->value = (start_partition[0] << 8) /* first 2 input bytes */
| start_partition[1];
d->input = start_partition + 2; /* ptr to next byte */
d->input_len = sz - 2;
}
else
{
d->value = 0;
d->input = NULL;
d->input_len = 0;
}
d->range = 255; /* initial range is full */
d->bit_count = 0; /* have not yet shifted out any bits */
}
static int bool_get(struct bool_decoder *d, int probability)
{
/* range and split are identical to the corresponding values
used by the encoder when this bool was written */
unsigned int split = 1 + (((d->range - 1) * probability) >> 8);
unsigned int SPLIT = split << 8;
int retval; /* will be 0 or 1 */
if (d->value >= SPLIT) /* encoded a one */
{
retval = 1;
d->range -= split; /* reduce range */
d->value -= SPLIT; /* subtract off left endpoint of interval */
}
else /* encoded a zero */
{
retval = 0;
d->range = split; /* reduce range, no change in left endpoint */
}
while (d->range < 128) /* shift out irrelevant value bits */
{
d->value <<= 1;
d->range <<= 1;
if (++d->bit_count == 8) /* shift in new bits 8 at a time */
{
d->bit_count = 0;
if (d->input_len)
{
d->value |= *d->input++;
d->input_len--;
}
}
}
return retval;
}
static int bool_get_bit(struct bool_decoder *br)
{
return bool_get(br, 128);
}
static int bool_get_uint(struct bool_decoder *br, int bits)
{
int z = 0;
int bit;
for (bit = bits - 1; bit >= 0; bit--)
{
z |= (bool_get_bit(br) << bit);
}
return z;
}
static int bool_get_int(struct bool_decoder *br, int bits)
{
int z = 0;
int bit;
for (bit = bits - 1; bit >= 0; bit--)
{
z |= (bool_get_bit(br) << bit);
}
return bool_get_bit(br) ? -z : z;
}
static int bool_maybe_get_int(struct bool_decoder *br, int bits)
{
return bool_get_bit(br) ? bool_get_int(br, bits) : 0;
}
static int
bool_read_tree(struct bool_decoder *bool,
const int *t,
const unsigned char *p)
{
int i = 0;
while ((i = t[ i + bool_get(bool, p[i>>1])]) > 0) ;
return -i;
}
#endif

38
vp8/dixie/dequant_data.h Normal file
View File

@@ -0,0 +1,38 @@
static const int dc_q_lookup[128] =
{
4, 5, 6, 7, 8, 9, 10, 10,
11, 12, 13, 14, 15, 16, 17, 17,
18, 19, 20, 20, 21, 21, 22, 22,
23, 23, 24, 25, 25, 26, 27, 28,
29, 30, 31, 32, 33, 34, 35, 36,
37, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 46, 47, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57, 58,
59, 60, 61, 62, 63, 64, 65, 66,
67, 68, 69, 70, 71, 72, 73, 74,
75, 76, 76, 77, 78, 79, 80, 81,
82, 83, 84, 85, 86, 87, 88, 89,
91, 93, 95, 96, 98, 100, 101, 102,
104, 106, 108, 110, 112, 114, 116, 118,
122, 124, 126, 128, 130, 132, 134, 136,
138, 140, 143, 145, 148, 151, 154, 157
};
static const int ac_q_lookup[128] =
{
4, 5, 6, 7, 8, 9, 10, 11,
12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43,
44, 45, 46, 47, 48, 49, 50, 51,
52, 53, 54, 55, 56, 57, 58, 60,
62, 64, 66, 68, 70, 72, 74, 76,
78, 80, 82, 84, 86, 88, 90, 92,
94, 96, 98, 100, 102, 104, 106, 108,
110, 112, 114, 116, 119, 122, 125, 128,
131, 134, 137, 140, 143, 146, 149, 152,
155, 158, 161, 164, 167, 170, 173, 177,
181, 185, 189, 193, 197, 201, 205, 209,
213, 217, 221, 225, 229, 234, 239, 245,
249, 254, 259, 264, 269, 274, 279, 284
};

560
vp8/dixie/dixie.c Normal file
View File

@@ -0,0 +1,560 @@
/*
* Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "vpx/internal/vpx_codec_internal.h"
#include "bit_ops.h"
#include "dixie.h"
#include "vp8_prob_data.h"
#include "dequant_data.h"
#include "modemv.h"
#include "tokens.h"
#include "predict.h"
#include "dixie_loopfilter.h"
#include <string.h>
#include <assert.h>
enum
{
FRAME_HEADER_SZ = 3,
KEYFRAME_HEADER_SZ = 7
};
#define ARRAY_COPY(a,b) {\
assert(sizeof(a)==sizeof(b));memcpy(a,b,sizeof(a));}
static void
decode_entropy_header(struct vp8_decoder_ctx *ctx,
struct bool_decoder *bool,
struct vp8_entropy_hdr *hdr)
{
int i, j, k, l;
/* Read coefficient probability updates */
for (i = 0; i < BLOCK_TYPES; i++)
for (j = 0; j < COEF_BANDS; j++)
for (k = 0; k < PREV_COEF_CONTEXTS; k++)
for (l = 0; l < ENTROPY_NODES; l++)
if (bool_get(bool,
k_coeff_entropy_update_probs
[i][j][k][l]))
hdr->coeff_probs[i][j][k][l] =
bool_get_uint(bool, 8);
/* Read coefficient skip mode probability */
hdr->coeff_skip_enabled = bool_get_bit(bool);
if (hdr->coeff_skip_enabled)
hdr->coeff_skip_prob = bool_get_uint(bool, 8);
/* Parse interframe probability updates */
if (!ctx->frame_hdr.is_keyframe)
{
hdr->prob_inter = bool_get_uint(bool, 8);
hdr->prob_last = bool_get_uint(bool, 8);
hdr->prob_gf = bool_get_uint(bool, 8);
if (bool_get_bit(bool))
for (i = 0; i < 4; i++)
hdr->y_mode_probs[i] = bool_get_uint(bool, 8);
if (bool_get_bit(bool))
for (i = 0; i < 3; i++)
hdr->uv_mode_probs[i] = bool_get_uint(bool, 8);
for (i = 0; i < 2; i++)
for (j = 0; j < MV_PROB_CNT; j++)
if (bool_get(bool, k_mv_entropy_update_probs[i][j]))
{
int x = bool_get_uint(bool, 7);
hdr->mv_probs[i][j] = x ? x << 1 : 1;
}
}
}
static void
decode_reference_header(struct vp8_decoder_ctx *ctx,
struct bool_decoder *bool,
struct vp8_reference_hdr *hdr)
{
unsigned int key = ctx->frame_hdr.is_keyframe;
hdr->refresh_gf = key ? 1 : bool_get_bit(bool);
hdr->refresh_arf = key ? 1 : bool_get_bit(bool);
hdr->copy_gf = key ? 0 : !hdr->refresh_gf
? bool_get_uint(bool, 2) : 0;
hdr->copy_arf = key ? 0 : !hdr->refresh_arf
? bool_get_uint(bool, 2) : 0;
hdr->sign_bias[GOLDEN_FRAME] = key ? 0 : bool_get_bit(bool);
hdr->sign_bias[ALTREF_FRAME] = key ? 0 : bool_get_bit(bool);
hdr->refresh_entropy = bool_get_bit(bool);
hdr->refresh_last = key ? 1 : bool_get_bit(bool);
}
static void
decode_quantizer_header(struct vp8_decoder_ctx *ctx,
struct bool_decoder *bool,
struct vp8_quant_hdr *hdr)
{
int update;
int last_q = hdr->q_index;
hdr->q_index = bool_get_uint(bool, 7);
update = last_q != hdr->q_index;
update |= (hdr->y1_dc_delta_q = bool_maybe_get_int(bool, 4));
update |= (hdr->y2_dc_delta_q = bool_maybe_get_int(bool, 4));
update |= (hdr->y2_ac_delta_q = bool_maybe_get_int(bool, 4));
update |= (hdr->uv_dc_delta_q = bool_maybe_get_int(bool, 4));
update |= (hdr->uv_ac_delta_q = bool_maybe_get_int(bool, 4));
hdr->delta_update = update;
}
static void
decode_and_init_token_partitions(struct vp8_decoder_ctx *ctx,
struct bool_decoder *bool,
const unsigned char *data,
unsigned int sz,
struct vp8_token_hdr *hdr)
{
int i;
hdr->partitions = 1 << bool_get_uint(bool, 2);
if (sz < 3 *(hdr->partitions - 1))
vpx_internal_error(&ctx->error, VPX_CODEC_CORRUPT_FRAME,
"Truncated packet found parsing partition"
" lengths.");
sz -= 3 * (hdr->partitions - 1);
for (i = 0; i < hdr->partitions; i++)
{
if (i < hdr->partitions - 1)
{
hdr->partition_sz[i] = (data[2] << 16)
| (data[1] << 8) | data[0];
data += 3;
}
else
hdr->partition_sz[i] = sz;
if (sz < hdr->partition_sz[i])
vpx_internal_error(&ctx->error, VPX_CODEC_CORRUPT_FRAME,
"Truncated partition %d", i);
sz -= hdr->partition_sz[i];
}
for (i = 0; i < ctx->token_hdr.partitions; i++)
{
init_bool_decoder(&ctx->tokens[i].bool, data,
ctx->token_hdr.partition_sz[i]);
data += ctx->token_hdr.partition_sz[i];
}
}
static void
decode_loopfilter_header(struct vp8_decoder_ctx *ctx,
struct bool_decoder *bool,
struct vp8_loopfilter_hdr *hdr)
{
if (ctx->frame_hdr.is_keyframe)
memset(hdr, 0, sizeof(*hdr));
hdr->use_simple = bool_get_bit(bool);
hdr->level = bool_get_uint(bool, 6);
hdr->sharpness = bool_get_uint(bool, 3);
hdr->delta_enabled = bool_get_bit(bool);
if (hdr->delta_enabled && bool_get_bit(bool))
{
int i;
for (i = 0; i < BLOCK_CONTEXTS; i++)
hdr->ref_delta[i] = bool_maybe_get_int(bool, 6);
for (i = 0; i < BLOCK_CONTEXTS; i++)
hdr->mode_delta[i] = bool_maybe_get_int(bool, 6);
}
}
static void
decode_segmentation_header(struct vp8_decoder_ctx *ctx,
struct bool_decoder *bool,
struct vp8_segment_hdr *hdr)
{
if (ctx->frame_hdr.is_keyframe)
memset(hdr, 0, sizeof(*hdr));
hdr->enabled = bool_get_bit(bool);
if (hdr->enabled)
{
int i;
hdr->update_map = bool_get_bit(bool);
hdr->update_data = bool_get_bit(bool);
if (hdr->update_data)
{
hdr->abs = bool_get_bit(bool);
for (i = 0; i < MAX_MB_SEGMENTS; i++)
hdr->quant_idx[i] = bool_maybe_get_int(bool, 7);
for (i = 0; i < MAX_MB_SEGMENTS; i++)
hdr->lf_level[i] = bool_maybe_get_int(bool, 6);
}
if (hdr->update_map)
{
for (i = 0; i < MB_FEATURE_TREE_PROBS; i++)
hdr->tree_probs[i] = bool_get_bit(bool)
? bool_get_uint(bool, 8)
: 255;
}
}
else
{
hdr->update_map = 0;
hdr->update_data = 0;
}
}
static void
dequant_global_init(struct dequant_factors dqf[MAX_MB_SEGMENTS])
{
int i;
for (i = 0; i < MAX_MB_SEGMENTS; i++)
dqf[i].quant_idx = -1;
}
static int
clamp_q(int q)
{
if (q < 0) return 0;
else if (q > 127) return 127;
return q;
}
static int
dc_q(int q)
{
return dc_q_lookup[clamp_q(q)];
}
static int
ac_q(int q)
{
return ac_q_lookup[clamp_q(q)];
}
static void
dequant_init(struct dequant_factors factors[MAX_MB_SEGMENTS],
const struct vp8_segment_hdr *seg,
const struct vp8_quant_hdr *quant_hdr)
{
int i, q;
struct dequant_factors *dqf = factors;
for (i = 0; i < (seg->enabled ? MAX_MB_SEGMENTS : 1); i++)
{
q = quant_hdr->q_index;
if (seg->enabled)
q = (!seg->abs) ? q + seg->quant_idx[i] : seg->quant_idx[i];
if (dqf->quant_idx != q || quant_hdr->delta_update)
{
dqf->factor[TOKEN_BLOCK_Y1][0] =
dc_q(q + quant_hdr->y1_dc_delta_q);
dqf->factor[TOKEN_BLOCK_Y1][1] =
ac_q(q);
dqf->factor[TOKEN_BLOCK_UV][0] =
dc_q(q + quant_hdr->uv_dc_delta_q);
dqf->factor[TOKEN_BLOCK_UV][1] =
ac_q(q + quant_hdr->uv_ac_delta_q);
dqf->factor[TOKEN_BLOCK_Y2][0] =
dc_q(q + quant_hdr->y2_dc_delta_q) * 2;
dqf->factor[TOKEN_BLOCK_Y2][1] =
ac_q(q + quant_hdr->y2_ac_delta_q) * 155 / 100;
if (dqf->factor[TOKEN_BLOCK_Y2][1] < 8)
dqf->factor[TOKEN_BLOCK_Y2][1] = 8;
if (dqf->factor[TOKEN_BLOCK_UV][0] > 132)
dqf->factor[TOKEN_BLOCK_UV][0] = 132;
dqf->quant_idx = q;
}
dqf++;
}
}
static void
decode_frame(struct vp8_decoder_ctx *ctx,
const unsigned char *data,
unsigned int sz)
{
vpx_codec_err_t res;
struct bool_decoder bool;
int i, row, partition;
ctx->saved_entropy_valid = 0;
if ((res = vp8_parse_frame_header(data, sz, &ctx->frame_hdr)))
vpx_internal_error(&ctx->error, res,
"Failed to parse frame header");
if (ctx->frame_hdr.is_experimental)
vpx_internal_error(&ctx->error, VPX_CODEC_UNSUP_BITSTREAM,
"Experimental bitstreams not supported.");
data += FRAME_HEADER_SZ;
sz -= FRAME_HEADER_SZ;
if (ctx->frame_hdr.is_keyframe)
{
data += KEYFRAME_HEADER_SZ;
sz -= KEYFRAME_HEADER_SZ;
ctx->mb_cols = (ctx->frame_hdr.kf.w + 15) / 16;
ctx->mb_rows = (ctx->frame_hdr.kf.h + 15) / 16;
}
/* Start the bitreader for the header/entropy partition */
init_bool_decoder(&bool, data, ctx->frame_hdr.part0_sz);
/* Skip the colorspace and clamping bits */
if (ctx->frame_hdr.is_keyframe)
if (bool_get_uint(&bool, 2))
vpx_internal_error(&ctx->error, VPX_CODEC_UNSUP_BITSTREAM,
"Reserved bits not supported.");
decode_segmentation_header(ctx, &bool, &ctx->segment_hdr);
decode_loopfilter_header(ctx, &bool, &ctx->loopfilter_hdr);
decode_and_init_token_partitions(ctx,
&bool,
data + ctx->frame_hdr.part0_sz,
sz - ctx->frame_hdr.part0_sz,
&ctx->token_hdr);
decode_quantizer_header(ctx, &bool, &ctx->quant_hdr);
decode_reference_header(ctx, &bool, &ctx->reference_hdr);
/* Set keyframe entropy defaults. These get updated on keyframes
* regardless of the refresh_entropy setting.
*/
if (ctx->frame_hdr.is_keyframe)
{
ARRAY_COPY(ctx->entropy_hdr.coeff_probs,
k_default_coeff_probs);
ARRAY_COPY(ctx->entropy_hdr.mv_probs,
k_default_mv_probs);
ARRAY_COPY(ctx->entropy_hdr.y_mode_probs,
k_default_y_mode_probs);
ARRAY_COPY(ctx->entropy_hdr.uv_mode_probs,
k_default_uv_mode_probs);
}
if (!ctx->reference_hdr.refresh_entropy)
{
ctx->saved_entropy = ctx->entropy_hdr;
ctx->saved_entropy_valid = 1;
}
decode_entropy_header(ctx, &bool, &ctx->entropy_hdr);
vp8_dixie_modemv_init(ctx);
vp8_dixie_tokens_init(ctx);
vp8_dixie_predict_init(ctx);
dequant_init(ctx->dequant_factors, &ctx->segment_hdr,
&ctx->quant_hdr);
for (row = 0, partition = 0; row < ctx->mb_rows; row++)
{
vp8_dixie_modemv_process_row(ctx, &bool, row, 0, ctx->mb_cols);
vp8_dixie_tokens_process_row(ctx, partition, row, 0,
ctx->mb_cols);
vp8_dixie_predict_process_row(ctx, row, 0, ctx->mb_cols);
if (ctx->loopfilter_hdr.level && row)
vp8_dixie_loopfilter_process_row(ctx, row - 1, 0,
ctx->mb_cols);
if (++partition == ctx->token_hdr.partitions)
partition = 0;
}
if (ctx->loopfilter_hdr.level)
vp8_dixie_loopfilter_process_row(ctx, row - 1, 0, ctx->mb_cols);
ctx->frame_cnt++;
if (!ctx->reference_hdr.refresh_entropy)
{
ctx->entropy_hdr = ctx->saved_entropy;
ctx->saved_entropy_valid = 0;
}
/* Handle reference frame updates */
if (ctx->reference_hdr.copy_arf == 1)
{
vp8_dixie_release_ref_frame(ctx->ref_frames[ALTREF_FRAME]);
ctx->ref_frames[ALTREF_FRAME] =
vp8_dixie_ref_frame(ctx->ref_frames[LAST_FRAME]);
}
else if (ctx->reference_hdr.copy_arf == 2)
{
vp8_dixie_release_ref_frame(ctx->ref_frames[ALTREF_FRAME]);
ctx->ref_frames[ALTREF_FRAME] =
vp8_dixie_ref_frame(ctx->ref_frames[GOLDEN_FRAME]);
}
if (ctx->reference_hdr.copy_gf == 1)
{
vp8_dixie_release_ref_frame(ctx->ref_frames[GOLDEN_FRAME]);
ctx->ref_frames[GOLDEN_FRAME] =
vp8_dixie_ref_frame(ctx->ref_frames[LAST_FRAME]);
}
else if (ctx->reference_hdr.copy_gf == 2)
{
vp8_dixie_release_ref_frame(ctx->ref_frames[GOLDEN_FRAME]);
ctx->ref_frames[GOLDEN_FRAME] =
vp8_dixie_ref_frame(ctx->ref_frames[ALTREF_FRAME]);
}
if (ctx->reference_hdr.refresh_gf)
{
vp8_dixie_release_ref_frame(ctx->ref_frames[GOLDEN_FRAME]);
ctx->ref_frames[GOLDEN_FRAME] =
vp8_dixie_ref_frame(ctx->ref_frames[CURRENT_FRAME]);
}
if (ctx->reference_hdr.refresh_arf)
{
vp8_dixie_release_ref_frame(ctx->ref_frames[ALTREF_FRAME]);
ctx->ref_frames[ALTREF_FRAME] =
vp8_dixie_ref_frame(ctx->ref_frames[CURRENT_FRAME]);
}
if (ctx->reference_hdr.refresh_last)
{
vp8_dixie_release_ref_frame(ctx->ref_frames[LAST_FRAME]);
ctx->ref_frames[LAST_FRAME] =
vp8_dixie_ref_frame(ctx->ref_frames[CURRENT_FRAME]);
}
}
void
vp8_dixie_decode_init(struct vp8_decoder_ctx *ctx)
{
dequant_global_init(ctx->dequant_factors);
}
#define CHECK_FOR_UPDATE(lval,rval,update_flag) do {\
unsigned int old = lval; \
update_flag |= (old != (lval = rval)); \
} while(0)
vpx_codec_err_t
vp8_parse_frame_header(const unsigned char *data,
unsigned int sz,
struct vp8_frame_hdr *hdr)
{
unsigned long raw;
if (sz < 10)
return VPX_CODEC_CORRUPT_FRAME;
/* The frame header is defined as a three byte little endian
* value
*/
raw = data[0] | (data[1] << 8) | (data[2] << 16);
hdr->is_keyframe = !BITS_GET(raw, 0, 1);
hdr->version = BITS_GET(raw, 1, 2);
hdr->is_experimental = BITS_GET(raw, 3, 1);
hdr->is_shown = BITS_GET(raw, 4, 1);
hdr->part0_sz = BITS_GET(raw, 5, 19);
if (sz <= hdr->part0_sz + (hdr->is_keyframe ? 10 : 3))
return VPX_CODEC_CORRUPT_FRAME;
hdr->frame_size_updated = 0;
if (hdr->is_keyframe)
{
unsigned int update = 0;
/* Keyframe header consists of a three byte sync code followed
* by the width and height and associated scaling factors.
*/
if (data[3] != 0x9d || data[4] != 0x01 || data[5] != 0x2a)
return VPX_CODEC_UNSUP_BITSTREAM;
raw = data[6] | (data[7] << 8)
| (data[8] << 16) | (data[9] << 24);
CHECK_FOR_UPDATE(hdr->kf.w, BITS_GET(raw, 0, 14),
update);
CHECK_FOR_UPDATE(hdr->kf.scale_w, BITS_GET(raw, 14, 2),
update);
CHECK_FOR_UPDATE(hdr->kf.h, BITS_GET(raw, 16, 14),
update);
CHECK_FOR_UPDATE(hdr->kf.scale_h, BITS_GET(raw, 30, 2),
update);
hdr->frame_size_updated = update;
if (!hdr->kf.w || !hdr->kf.h)
return VPX_CODEC_UNSUP_BITSTREAM;
}
return VPX_CODEC_OK;
}
vpx_codec_err_t
vp8_dixie_decode_frame(struct vp8_decoder_ctx *ctx,
const unsigned char *data,
unsigned int sz)
{
volatile struct vp8_decoder_ctx *ctx_ = ctx;
ctx->error.error_code = VPX_CODEC_OK;
ctx->error.has_detail = 0;
if (!setjmp(ctx->error.jmp))
decode_frame(ctx, data, sz);
return ctx_->error.error_code;
}
void
vp8_dixie_decode_destroy(struct vp8_decoder_ctx *ctx)
{
vp8_dixie_predict_destroy(ctx);
vp8_dixie_tokens_destroy(ctx);
vp8_dixie_modemv_destroy(ctx);
}

308
vp8/dixie/dixie.h Normal file
View File

@@ -0,0 +1,308 @@
/*
* Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef DIXIE_H
#define DIXIE_H
#include "vpx/internal/vpx_codec_internal.h"
#include "bool_decoder.h"
struct vp8_frame_hdr
{
unsigned int is_keyframe; /* Frame is a keyframe */
unsigned int is_experimental; /* Frame is a keyframe */
unsigned int version; /* Bitstream version */
unsigned int is_shown; /* Frame is to be displayed. */
unsigned int part0_sz; /* Partition 0 length, in bytes */
struct vp8_kf_hdr
{
unsigned int w; /* Width */
unsigned int h; /* Height */
unsigned int scale_w; /* Scaling factor, Width */
unsigned int scale_h; /* Scaling factor, Height */
} kf;
unsigned int frame_size_updated; /* Flag to indicate a resolution
* update.
*/
};
enum
{
MB_FEATURE_TREE_PROBS = 3,
MAX_MB_SEGMENTS = 4
};
struct vp8_segment_hdr
{
unsigned int enabled;
unsigned int update_data;
unsigned int update_map;
unsigned int abs; /* 0=deltas, 1=absolute values */
unsigned int tree_probs[MB_FEATURE_TREE_PROBS];
int lf_level[MAX_MB_SEGMENTS];
int quant_idx[MAX_MB_SEGMENTS];
};
enum
{
BLOCK_CONTEXTS = 4
};
struct vp8_loopfilter_hdr
{
unsigned int use_simple;
unsigned int level;
unsigned int sharpness;
unsigned int delta_enabled;
int ref_delta[BLOCK_CONTEXTS];
int mode_delta[BLOCK_CONTEXTS];
};
enum
{
MAX_PARTITIONS = 8
};
struct vp8_token_hdr
{
unsigned int partitions;
unsigned int partition_sz[MAX_PARTITIONS];
};
struct vp8_quant_hdr
{
unsigned int q_index;
int delta_update;
int y1_dc_delta_q;
int y2_dc_delta_q;
int y2_ac_delta_q;
int uv_dc_delta_q;
int uv_ac_delta_q;
};
struct vp8_reference_hdr
{
unsigned int refresh_last;
unsigned int refresh_gf;
unsigned int refresh_arf;
unsigned int copy_gf;
unsigned int copy_arf;
unsigned int sign_bias[4];
unsigned int refresh_entropy;
};
enum
{
BLOCK_TYPES = 4,
PREV_COEF_CONTEXTS = 3,
COEF_BANDS = 8,
ENTROPY_NODES = 11,
};
typedef unsigned char coeff_probs_table_t[BLOCK_TYPES][COEF_BANDS]
[PREV_COEF_CONTEXTS]
[ENTROPY_NODES];
enum
{
MV_PROB_CNT = 2 + 8 - 1 + 10 /* from entropymv.h */
};
typedef unsigned char mv_component_probs_t[MV_PROB_CNT];
struct vp8_entropy_hdr
{
coeff_probs_table_t coeff_probs;
mv_component_probs_t mv_probs[2];
unsigned int coeff_skip_enabled;
unsigned char coeff_skip_prob;
unsigned char y_mode_probs[4];
unsigned char uv_mode_probs[3];
unsigned char prob_inter;
unsigned char prob_last;
unsigned char prob_gf;
};
enum reference_frame
{
CURRENT_FRAME,
LAST_FRAME,
GOLDEN_FRAME,
ALTREF_FRAME,
NUM_REF_FRAMES
};
enum prediction_mode
{
/* 16x16 intra modes */
DC_PRED, V_PRED, H_PRED, TM_PRED, B_PRED,
/* 16x16 inter modes */
NEARESTMV, NEARMV, ZEROMV, NEWMV, SPLITMV,
MB_MODE_COUNT,
/* 4x4 intra modes */
B_DC_PRED = 0, B_TM_PRED, B_VE_PRED, B_HE_PRED, B_LD_PRED,
B_RD_PRED, B_VR_PRED, B_VL_PRED, B_HD_PRED, B_HU_PRED,
/* 4x4 inter modes */
LEFT4X4, ABOVE4X4, ZERO4X4, NEW4X4,
B_MODE_COUNT
};
enum splitmv_partitioning
{
SPLITMV_16X8,
SPLITMV_8X16,
SPLITMV_8X8,
SPLITMV_4X4
};
typedef short filter_t[6];
typedef union mv
{
struct
{
int16_t x, y;
} d;
uint32_t raw;
} mv_t;
struct mb_base_info
{
unsigned char y_mode : 4;
unsigned char uv_mode : 4;
unsigned char segment_id : 2;
unsigned char ref_frame : 2;
unsigned char skip_coeff : 1;
unsigned char need_mc_border : 1;
enum splitmv_partitioning partitioning : 2;
union mv mv;
unsigned int eob_mask;
};
struct mb_info
{
struct mb_base_info base;
union
{
union mv mvs[16];
enum prediction_mode modes[16];
} split;
};
/* A "token entropy context" has 4 Y values, 2 U, 2 V, and 1 Y2 */
typedef int token_entropy_ctx_t[4 + 2 + 2 + 1];
struct token_decoder
{
struct bool_decoder bool;
token_entropy_ctx_t left_token_entropy_ctx;
short *coeffs;
};
enum token_block_type
{
TOKEN_BLOCK_Y1,
TOKEN_BLOCK_UV,
TOKEN_BLOCK_Y2,
TOKEN_BLOCK_TYPES,
};
struct dequant_factors
{
int quant_idx;
short factor[TOKEN_BLOCK_TYPES][2]; /* [ Y1, UV, Y2 ] [ DC, AC ] */
};
struct ref_cnt_img
{
vpx_image_t img;
unsigned int ref_cnt;
};
struct vp8_decoder_ctx
{
struct vpx_internal_error_info error;
unsigned int frame_cnt;
struct vp8_frame_hdr frame_hdr;
struct vp8_segment_hdr segment_hdr;
struct vp8_loopfilter_hdr loopfilter_hdr;
struct vp8_token_hdr token_hdr;
struct vp8_quant_hdr quant_hdr;
struct vp8_reference_hdr reference_hdr;
struct vp8_entropy_hdr entropy_hdr;
struct vp8_entropy_hdr saved_entropy;
unsigned int saved_entropy_valid;
unsigned int mb_rows;
unsigned int mb_cols;
struct mb_info *mb_info_storage;
struct mb_info **mb_info_rows_storage;
struct mb_info **mb_info_rows;
token_entropy_ctx_t *above_token_entropy_ctx;
struct token_decoder tokens[MAX_PARTITIONS];
struct dequant_factors dequant_factors[MAX_MB_SEGMENTS];
struct ref_cnt_img frame_strg[NUM_REF_FRAMES];
struct ref_cnt_img *ref_frames[NUM_REF_FRAMES];
ptrdiff_t ref_frame_offsets[4];
const filter_t *subpixel_filters;
};
void
vp8_dixie_decode_init(struct vp8_decoder_ctx *ctx);
void
vp8_dixie_decode_destroy(struct vp8_decoder_ctx *ctx);
vpx_codec_err_t
vp8_parse_frame_header(const unsigned char *data,
unsigned int sz,
struct vp8_frame_hdr *hdr);
vpx_codec_err_t
vp8_dixie_decode_frame(struct vp8_decoder_ctx *ctx,
const unsigned char *data,
unsigned int sz);
#define CLAMP_255(x) ((x)<0?0:((x)>255?255:(x)))
#endif

View File

@@ -0,0 +1,530 @@
/*
* Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "dixie.h"
#include "dixie_loopfilter.h"
#define ABS(x) ((x) >= 0 ? (x) : -(x))
#define p3 pixels[-4*stride]
#define p2 pixels[-3*stride]
#define p1 pixels[-2*stride]
#define p0 pixels[-1*stride]
#define q0 pixels[ 0*stride]
#define q1 pixels[ 1*stride]
#define q2 pixels[ 2*stride]
#define q3 pixels[ 3*stride]
#define static
static int
saturate_int8(int x)
{
if (x < -128)
return -128;
if (x > 127)
return 127;
return x;
}
static int
saturate_uint8(int x)
{
if (x < 0)
return 0;
if (x > 255)
return 255;
return x;
}
static int
high_edge_variance(unsigned char *pixels,
int stride,
int hev_threshold)
{
return ABS(p1 - p0) > hev_threshold || ABS(q1 - q0) > hev_threshold;
}
static int
simple_threshold(unsigned char *pixels,
int stride,
int filter_limit)
{
return (ABS(p0 - q0) * 2 + (ABS(p1 - q1) >> 1)) <= filter_limit;
}
static int
normal_threshold(unsigned char *pixels,
int stride,
int edge_limit,
int interior_limit)
{
int E = edge_limit;
int I = interior_limit;
return simple_threshold(pixels, stride, 2 * E + I)
&& ABS(p3 - p2) <= I && ABS(p2 - p1) <= I
&& ABS(p1 - p0) <= I && ABS(q3 - q2) <= I
&& ABS(q2 - q1) <= I && ABS(q1 - q0) <= I;
}
static void
filter_common(unsigned char *pixels,
int stride,
int use_outer_taps)
{
int a, f1, f2;
a = 3 * (q0 - p0);
if (use_outer_taps)
a += saturate_int8(p1 - q1);
a = saturate_int8(a);
f1 = ((a + 4 > 127) ? 127 : a + 4) >> 3;
f2 = ((a + 3 > 127) ? 127 : a + 3) >> 3;
p0 = saturate_uint8(p0 + f2);
q0 = saturate_uint8(q0 - f1);
if (!use_outer_taps)
{
/* This handles the case of subblock_filter()
* (from the bitstream guide.
*/
a = (f1 + 1) >> 1;
p1 = saturate_uint8(p1 + a);
q1 = saturate_uint8(q1 - a);
}
}
static void
filter_mb_edge(unsigned char *pixels,
int stride)
{
int w, a;
w = saturate_int8(saturate_int8(p1 - q1) + 3 * (q0 - p0));
a = (27 * w + 63) >> 7;
p0 = saturate_uint8(p0 + a);
q0 = saturate_uint8(q0 - a);
a = (18 * w + 63) >> 7;
p1 = saturate_uint8(p1 + a);
q1 = saturate_uint8(q1 - a);
a = (9 * w + 63) >> 7;
p2 = saturate_uint8(p2 + a);
q2 = saturate_uint8(q2 - a);
}
static void
filter_mb_v_edge(unsigned char *src,
int stride,
int edge_limit,
int interior_limit,
int hev_threshold,
int size)
{
int i;
for (i = 0; i < 8 * size; i++)
{
if (normal_threshold(src, 1, edge_limit, interior_limit))
{
if (high_edge_variance(src, 1, hev_threshold))
filter_common(src, 1, 1);
else
filter_mb_edge(src, 1);
}
src += stride;
}
}
static void
filter_subblock_v_edge(unsigned char *src,
int stride,
int edge_limit,
int interior_limit,
int hev_threshold,
int size)
{
int i;
for (i = 0; i < 8 * size; i++)
{
if (normal_threshold(src, 1, edge_limit, interior_limit))
filter_common(src, 1,
high_edge_variance(src, 1, hev_threshold));
src += stride;
}
}
static void
filter_mb_h_edge(unsigned char *src,
int stride,
int edge_limit,
int interior_limit,
int hev_threshold,
int size)
{
int i;
for (i = 0; i < 8 * size; i++)
{
if (normal_threshold(src, stride, edge_limit, interior_limit))
{
if (high_edge_variance(src, stride, hev_threshold))
filter_common(src, stride, 1);
else
filter_mb_edge(src, stride);
}
src += 1;
}
}
static void
filter_subblock_h_edge(unsigned char *src,
int stride,
int edge_limit,
int interior_limit,
int hev_threshold,
int size)
{
int i;
for (i = 0; i < 8 * size; i++)
{
if (normal_threshold(src, stride, edge_limit, interior_limit))
filter_common(src, stride,
high_edge_variance(src, stride,
hev_threshold));
src += 1;
}
}
static void
filter_v_edge_simple(unsigned char *src,
int stride,
int filter_limit)
{
int i;
for (i = 0; i < 16; i++)
{
if (simple_threshold(src, 1, filter_limit))
filter_common(src, 1, 1);
src += stride;
}
}
static void
filter_h_edge_simple(unsigned char *src,
int stride,
int filter_limit)
{
int i;
for (i = 0; i < 16; i++)
{
if (simple_threshold(src, stride, filter_limit))
filter_common(src, stride, 1);
src += 1;
}
}
static void
calculate_filter_parameters(struct vp8_decoder_ctx *ctx,
struct mb_info *mbi,
int *edge_limit_,
int *interior_limit_,
int *hev_threshold_)
{
int filter_level, interior_limit, hev_threshold;
/* Reference code/spec seems to conflate filter_level and
* edge_limit
*/
filter_level = ctx->loopfilter_hdr.level;
if (ctx->segment_hdr.enabled)
{
if (!ctx->segment_hdr.abs)
filter_level +=
ctx->segment_hdr.lf_level[mbi->base.segment_id];
else
filter_level =
ctx->segment_hdr.lf_level[mbi->base.segment_id];
}
if (ctx->loopfilter_hdr.delta_enabled)
{
filter_level +=
ctx->loopfilter_hdr.ref_delta[mbi->base.ref_frame];
if (mbi->base.ref_frame == CURRENT_FRAME)
{
if (mbi->base.y_mode == B_PRED)
filter_level += ctx->loopfilter_hdr.mode_delta[0];
}
else if (mbi->base.y_mode == ZEROMV)
filter_level += ctx->loopfilter_hdr.mode_delta[1];
else if (mbi->base.y_mode == SPLITMV)
filter_level += ctx->loopfilter_hdr.mode_delta[3];
else
filter_level += ctx->loopfilter_hdr.mode_delta[2];
}
if (filter_level > 63)
filter_level = 63;
else if (filter_level < 0)
filter_level = 0;
interior_limit = filter_level;
if (ctx->loopfilter_hdr.sharpness)
{
interior_limit >>= ctx->loopfilter_hdr.sharpness > 4 ? 2 : 1;
if (interior_limit > 9 - ctx->loopfilter_hdr.sharpness)
interior_limit = 9 - ctx->loopfilter_hdr.sharpness;
}
if (interior_limit < 1)
interior_limit = 1;
hev_threshold = (filter_level >= 15);
if (filter_level >= 40)
hev_threshold++;
if (filter_level >= 20 && !ctx->frame_hdr.is_keyframe)
hev_threshold++;
*edge_limit_ = filter_level;
*interior_limit_ = interior_limit;
*hev_threshold_ = hev_threshold;
}
static void
filter_row_normal(struct vp8_decoder_ctx *ctx,
unsigned int row,
unsigned int start_col,
unsigned int num_cols)
{
unsigned char *y, *u, *v;
int stride, uv_stride;
struct mb_info *mbi;
unsigned int col;
/* Adjust pointers based on row, start_col */
stride = ctx->ref_frames[CURRENT_FRAME]->img.stride[PLANE_Y];
uv_stride = ctx->ref_frames[CURRENT_FRAME]->img.stride[PLANE_U];
y = ctx->ref_frames[CURRENT_FRAME]->img.planes[PLANE_Y];
u = ctx->ref_frames[CURRENT_FRAME]->img.planes[PLANE_U];
v = ctx->ref_frames[CURRENT_FRAME]->img.planes[PLANE_V];
y += (stride * row + start_col) * 16;
u += (uv_stride * row + start_col) * 8;
v += (uv_stride * row + start_col) * 8;
mbi = ctx->mb_info_rows[row] + start_col;
for (col = start_col; col < start_col + num_cols; col++)
{
int edge_limit, interior_limit, hev_threshold;
/* TODO: only need to recalculate every MB if segmentation is
* enabled.
*/
calculate_filter_parameters(ctx, mbi, &edge_limit,
&interior_limit, &hev_threshold);
if (edge_limit)
{
if (col)
{
filter_mb_v_edge(y, stride, edge_limit + 2,
interior_limit, hev_threshold, 2);
filter_mb_v_edge(u, uv_stride, edge_limit + 2,
interior_limit, hev_threshold, 1);
filter_mb_v_edge(v, uv_stride, edge_limit + 2,
interior_limit, hev_threshold, 1);
}
/* NOTE: This conditional is actually dependent on the
* number of coefficients decoded, not the skip flag as
* coded in the bitstream. The tokens task is expected to
* set 31 if there is *any* non-zero data.
*/
if (mbi->base.eob_mask
|| mbi->base.y_mode == SPLITMV
|| mbi->base.y_mode == B_PRED)
{
filter_subblock_v_edge(y + 4, stride, edge_limit,
interior_limit, hev_threshold,
2);
filter_subblock_v_edge(y + 8, stride, edge_limit,
interior_limit, hev_threshold,
2);
filter_subblock_v_edge(y + 12, stride, edge_limit,
interior_limit, hev_threshold,
2);
filter_subblock_v_edge(u + 4, uv_stride, edge_limit,
interior_limit, hev_threshold,
1);
filter_subblock_v_edge(v + 4, uv_stride, edge_limit,
interior_limit, hev_threshold,
1);
}
if (row)
{
filter_mb_h_edge(y, stride, edge_limit + 2,
interior_limit, hev_threshold, 2);
filter_mb_h_edge(u, uv_stride, edge_limit + 2,
interior_limit, hev_threshold, 1);
filter_mb_h_edge(v, uv_stride, edge_limit + 2,
interior_limit, hev_threshold, 1);
}
if (mbi->base.eob_mask
|| mbi->base.y_mode == SPLITMV
|| mbi->base.y_mode == B_PRED)
{
filter_subblock_h_edge(y + 4 * stride, stride,
edge_limit, interior_limit,
hev_threshold, 2);
filter_subblock_h_edge(y + 8 * stride, stride,
edge_limit, interior_limit,
hev_threshold, 2);
filter_subblock_h_edge(y + 12 * stride, stride,
edge_limit, interior_limit,
hev_threshold, 2);
filter_subblock_h_edge(u + 4 * uv_stride, uv_stride,
edge_limit, interior_limit,
hev_threshold, 1);
filter_subblock_h_edge(v + 4 * uv_stride, uv_stride,
edge_limit, interior_limit,
hev_threshold, 1);
}
}
y += 16;
u += 8;
v += 8;
mbi++;
}
}
static void
filter_row_simple(struct vp8_decoder_ctx *ctx,
unsigned int row,
unsigned int start_col,
unsigned int num_cols)
{
unsigned char *y;
int stride;
struct mb_info *mbi;
unsigned int col;
/* Adjust pointers based on row, start_col */
stride = ctx->ref_frames[CURRENT_FRAME]->img.stride[PLANE_Y];
y = ctx->ref_frames[CURRENT_FRAME]->img.planes[PLANE_Y];
y += (stride * row + start_col) * 16;
mbi = ctx->mb_info_rows[row] + start_col;
for (col = start_col; col < start_col + num_cols; col++)
{
int edge_limit, interior_limit, hev_threshold;
/* TODO: only need to recalculate every MB if segmentation is
* enabled.
*/
calculate_filter_parameters(ctx, mbi, &edge_limit,
&interior_limit, &hev_threshold);
if (edge_limit)
{
/* NOTE: This conditional is actually dependent on the
* number of coefficients decoded, not the skip flag as
* coded in the bitstream. The tokens task is expected to
* set 31 if there is *any* non-zero data.
*/
int filter_subblocks = (mbi->base.eob_mask
|| mbi->base.y_mode == SPLITMV
|| mbi->base.y_mode == B_PRED);
int mb_limit = (edge_limit + 2) * 2 + interior_limit;
int b_limit = edge_limit * 2 + interior_limit;
if (col)
filter_v_edge_simple(y, stride, mb_limit);
if (filter_subblocks)
{
filter_v_edge_simple(y + 4, stride, b_limit);
filter_v_edge_simple(y + 8, stride, b_limit);
filter_v_edge_simple(y + 12, stride, b_limit);
}
if (row)
filter_h_edge_simple(y, stride, mb_limit);
if (filter_subblocks)
{
filter_h_edge_simple(y + 4 * stride, stride, b_limit);
filter_h_edge_simple(y + 8 * stride, stride, b_limit);
filter_h_edge_simple(y + 12 * stride, stride, b_limit);
}
}
y += 16;
mbi++;
}
}
void
vp8_dixie_loopfilter_process_row(struct vp8_decoder_ctx *ctx,
unsigned int row,
unsigned int start_col,
unsigned int num_cols)
{
if (ctx->loopfilter_hdr.use_simple)
filter_row_simple(ctx, row, start_col, num_cols);
else
filter_row_normal(ctx, row, start_col, num_cols);
}

View File

@@ -0,0 +1,19 @@
/*
* Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef DIXIE_LOOPFILTER_H
#define DIXIE_LOOPFILTER_H
void
vp8_dixie_loopfilter_process_row(struct vp8_decoder_ctx *ctx,
unsigned int row,
unsigned int start_col,
unsigned int num_cols);
#endif

142
vp8/dixie/idct_add.c Normal file
View File

@@ -0,0 +1,142 @@
/*
* Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "dixie.h"
#include "idct_add.h"
#include <assert.h>
void
vp8_dixie_walsh(const short *input, short *output)
{
int i;
int a1, b1, c1, d1;
int a2, b2, c2, d2;
const short *ip = input;
short *op = output;
for (i = 0; i < 4; i++)
{
a1 = ip[0] + ip[12];
b1 = ip[4] + ip[8];
c1 = ip[4] - ip[8];
d1 = ip[0] - ip[12];
op[0] = a1 + b1;
op[4] = c1 + d1;
op[8] = a1 - b1;
op[12] = d1 - c1;
ip++;
op++;
}
ip = output;
op = output;
for (i = 0; i < 4; i++)
{
a1 = ip[0] + ip[3];
b1 = ip[1] + ip[2];
c1 = ip[1] - ip[2];
d1 = ip[0] - ip[3];
a2 = a1 + b1;
b2 = c1 + d1;
c2 = a1 - b1;
d2 = d1 - c1;
op[0] = (a2 + 3) >> 3;
op[1] = (b2 + 3) >> 3;
op[2] = (c2 + 3) >> 3;
op[3] = (d2 + 3) >> 3;
ip += 4;
op += 4;
}
}
#define cospi8sqrt2minus1 20091
#define sinpi8sqrt2 35468
#define rounding 0
static void
idct_columns(const short *input, short *output)
{
int i;
int a1, b1, c1, d1;
const short *ip = input;
short *op = output;
int temp1, temp2;
int shortpitch = 4;
for (i = 0; i < 4; i++)
{
a1 = ip[0] + ip[8];
b1 = ip[0] - ip[8];
temp1 = (ip[4] * sinpi8sqrt2 + rounding) >> 16;
temp2 = ip[12] +
((ip[12] * cospi8sqrt2minus1 + rounding) >> 16);
c1 = temp1 - temp2;
temp1 = ip[4] +
((ip[4] * cospi8sqrt2minus1 + rounding) >> 16);
temp2 = (ip[12] * sinpi8sqrt2 + rounding) >> 16;
d1 = temp1 + temp2;
op[shortpitch*0] = a1 + d1;
op[shortpitch*3] = a1 - d1;
op[shortpitch*1] = b1 + c1;
op[shortpitch*2] = b1 - c1;
ip++;
op++;
}
}
void
vp8_dixie_idct_add(unsigned char *recon,
const unsigned char *predict,
int stride,
const short *coeffs)
{
int i;
int a1, b1, c1, d1, temp1, temp2;
short tmp[16];
idct_columns(coeffs, tmp);
coeffs = tmp;
for (i = 0; i < 4; i++)
{
a1 = coeffs[0] + coeffs[2];
b1 = coeffs[0] - coeffs[2];
temp1 = (coeffs[1] * sinpi8sqrt2 + rounding) >> 16;
temp2 = coeffs[3] +
((coeffs[3] * cospi8sqrt2minus1 + rounding) >> 16);
c1 = temp1 - temp2;
temp1 = coeffs[1] +
((coeffs[1] * cospi8sqrt2minus1 + rounding) >> 16);
temp2 = (coeffs[3] * sinpi8sqrt2 + rounding) >> 16;
d1 = temp1 + temp2;
recon[0] = CLAMP_255(predict[0] + ((a1 + d1 + 4) >> 3));
recon[3] = CLAMP_255(predict[3] + ((a1 - d1 + 4) >> 3));
recon[1] = CLAMP_255(predict[1] + ((b1 + c1 + 4) >> 3));
recon[2] = CLAMP_255(predict[2] + ((b1 - c1 + 4) >> 3));
coeffs += 4;
recon += stride;
predict += stride;
}
}

35
vp8/dixie/idct_add.h Normal file
View File

@@ -0,0 +1,35 @@
/*
* Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef IDCT_ADD_H
#define IDCT_ADD_H
void
vp8_dixie_idct_add_init(struct vp8_decoder_ctx *ctx);
void
vp8_dixie_idct_add(unsigned char *recon,
const unsigned char *predict,
int stride,
const short *coeffs);
void
vp8_dixie_walsh(const short *in, short *out);
void
vp8_dixie_idct_add_process_row(struct vp8_decoder_ctx *ctx,
short *coeffs,
unsigned int row,
unsigned int start_col,
unsigned int num_cols);
#endif

686
vp8/dixie/modemv.c Normal file
View File

@@ -0,0 +1,686 @@
/*
* Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "dixie.h"
#include "modemv_data.h"
#include <stdlib.h>
#include <assert.h>
struct mv_clamp_rect
{
int to_left, to_right, to_top, to_bottom;
};
static union mv
clamp_mv(union mv raw, const struct mv_clamp_rect *bounds)
{
union mv newmv;
newmv.d.x = (raw.d.x < bounds->to_left)
? bounds->to_left : raw.d.x;
newmv.d.x = (raw.d.x > bounds->to_right)
? bounds->to_right : newmv.d.x;
newmv.d.y = (raw.d.y < bounds->to_top)
? bounds->to_top : raw.d.y;
newmv.d.y = (raw.d.y > bounds->to_bottom)
? bounds->to_bottom : newmv.d.y;
return newmv;
}
static int
read_segment_id(struct bool_decoder *bool, struct vp8_segment_hdr *seg)
{
return bool_get(bool, seg->tree_probs[0])
? 2 + bool_get(bool, seg->tree_probs[2])
: bool_get(bool, seg->tree_probs[1]);
}
static enum prediction_mode
above_block_mode(const struct mb_info *this,
const struct mb_info *above,
unsigned int b)
{
if (b < 4)
{
switch (above->base.y_mode)
{
case DC_PRED:
return B_DC_PRED;
case V_PRED:
return B_VE_PRED;
case H_PRED:
return B_HE_PRED;
case TM_PRED:
return B_TM_PRED;
case B_PRED:
return above->split.modes[b+12];
default:
assert(0);
}
}
return this->split.modes[b-4];
}
static enum prediction_mode
left_block_mode(const struct mb_info *this,
const struct mb_info *left,
unsigned int b)
{
if (!(b & 3))
{
switch (left->base.y_mode)
{
case DC_PRED:
return B_DC_PRED;
case V_PRED:
return B_VE_PRED;
case H_PRED:
return B_HE_PRED;
case TM_PRED:
return B_TM_PRED;
case B_PRED:
return left->split.modes[b+3];
default:
assert(0);
}
}
return this->split.modes[b-1];
}
static void
decode_kf_mb_mode(struct mb_info *this,
struct mb_info *left,
struct mb_info *above,
struct bool_decoder *bool)
{
int y_mode, uv_mode;
y_mode = bool_read_tree(bool, kf_y_mode_tree, kf_y_mode_probs);
if (y_mode == B_PRED)
{
unsigned int i;
for (i = 0; i < 16; i++)
{
enum prediction_mode a = above_block_mode(this, above, i);
enum prediction_mode l = left_block_mode(this, left, i);
enum prediction_mode b;
b = bool_read_tree(bool, b_mode_tree,
kf_b_mode_probs[a][l]);
this->split.modes[i] = b;
}
}
uv_mode = bool_read_tree(bool, uv_mode_tree, kf_uv_mode_probs);
this->base.y_mode = y_mode;
this->base.uv_mode = uv_mode;
this->base.mv.raw = 0;
this->base.ref_frame = 0;
}
static void
decode_intra_mb_mode(struct mb_info *this,
struct vp8_entropy_hdr *hdr,
struct bool_decoder *bool)
{
/* Like decode_kf_mb_mode, but with probabilities transmitted in the
* bitstream and no context on the above/left block mode.
*/
int y_mode, uv_mode;
y_mode = bool_read_tree(bool, y_mode_tree, hdr->y_mode_probs);
if (y_mode == B_PRED)
{
unsigned int i;
for (i = 0; i < 16; i++)
{
enum prediction_mode b;
b = bool_read_tree(bool, b_mode_tree, default_b_mode_probs);
this->split.modes[i] = b;
}
}
uv_mode = bool_read_tree(bool, uv_mode_tree, hdr->uv_mode_probs);
this->base.y_mode = y_mode;
this->base.uv_mode = uv_mode;
this->base.mv.raw = 0;
this->base.ref_frame = CURRENT_FRAME;
}
static int
read_mv_component(struct bool_decoder *bool,
const unsigned char mvc[MV_PROB_CNT])
{
enum {IS_SHORT, SIGN, SHORT, BITS = SHORT + 8 - 1, LONG_WIDTH = 10};
int x = 0;
if (bool_get(bool, mvc[IS_SHORT])) /* Large */
{
int i = 0;
for (i = 0; i < 3; i++)
x += bool_get(bool, mvc[BITS + i]) << i;
/* Skip bit 3, which is sometimes implicit */
for (i = LONG_WIDTH - 1; i > 3; i--)
x += bool_get(bool, mvc[BITS + i]) << i;
if (!(x & 0xFFF0) || bool_get(bool, mvc[BITS + 3]))
x += 8;
}
else /* small */
x = bool_read_tree(bool, small_mv_tree, mvc + SHORT);
if (x && bool_get(bool, mvc[SIGN]))
x = -x;
return x << 1;
}
static mv_t
above_block_mv(const struct mb_info *this,
const struct mb_info *above,
unsigned int b)
{
if (b < 4)
{
if (above->base.y_mode == SPLITMV)
return above->split.mvs[b+12];
return above->base.mv;
}
return this->split.mvs[b-4];
}
static mv_t
left_block_mv(const struct mb_info *this,
const struct mb_info *left,
unsigned int b)
{
if (!(b & 3))
{
if (left->base.y_mode == SPLITMV)
return left->split.mvs[b+3];
return left->base.mv;
}
return this->split.mvs[b-1];
}
static enum prediction_mode
submv_ref(struct bool_decoder *bool, union mv l, union mv a)
{
enum subblock_mv_ref
{
SUBMVREF_NORMAL,
SUBMVREF_LEFT_ZED,
SUBMVREF_ABOVE_ZED,
SUBMVREF_LEFT_ABOVE_SAME,
SUBMVREF_LEFT_ABOVE_ZED
};
int lez = !(l.raw);
int aez = !(a.raw);
int lea = l.raw == a.raw;
enum subblock_mv_ref ctx = SUBMVREF_NORMAL;
if (lea && lez)
ctx = SUBMVREF_LEFT_ABOVE_ZED;
else if (lea)
ctx = SUBMVREF_LEFT_ABOVE_SAME;
else if (aez)
ctx = SUBMVREF_ABOVE_ZED;
else if (lez)
ctx = SUBMVREF_LEFT_ZED;
return bool_read_tree(bool, submv_ref_tree, submv_ref_probs2[ctx]);
}
static void
read_mv(struct bool_decoder *bool,
union mv *mv,
mv_component_probs_t mvc[2])
{
mv->d.y = read_mv_component(bool, mvc[0]);
mv->d.x = read_mv_component(bool, mvc[1]);
}
static void
mv_bias(const struct mb_info *mb,
const unsigned int sign_bias[3],
enum reference_frame ref_frame,
union mv *mv)
{
if (sign_bias[mb->base.ref_frame] ^ sign_bias[ref_frame])
{
mv->d.x *= -1;
mv->d.y *= -1;
}
}
enum near_mv_v
{
CNT_BEST = 0,
CNT_ZEROZERO = 0,
CNT_NEAREST,
CNT_NEAR,
CNT_SPLITMV
};
static void
find_near_mvs(const struct mb_info *this,
const struct mb_info *left,
const struct mb_info *above,
const unsigned int sign_bias[3],
union mv near_mvs[4],
int cnt[4])
{
const struct mb_info *aboveleft = above - 1;
union mv *mv = near_mvs;
int *cntx = cnt;
/* Zero accumulators */
mv[0].raw = mv[1].raw = mv[2].raw = 0;
cnt[0] = cnt[1] = cnt[2] = cnt[3] = 0;
/* Process above */
if (above->base.ref_frame != CURRENT_FRAME)
{
if (above->base.mv.raw)
{
(++mv)->raw = above->base.mv.raw;
mv_bias(above, sign_bias, this->base.ref_frame, mv);
++cntx;
}
*cntx += 2;
}
/* Process left */
if (left->base.ref_frame != CURRENT_FRAME)
{
if (left->base.mv.raw)
{
union mv this_mv;
this_mv.raw = left->base.mv.raw;
mv_bias(left, sign_bias, this->base.ref_frame, &this_mv);
if (this_mv.raw != mv->raw)
{
(++mv)->raw = this_mv.raw;
++cntx;
}
*cntx += 2;
}
else
cnt[CNT_ZEROZERO] += 2;
}
/* Process above left */
if (aboveleft->base.ref_frame != CURRENT_FRAME)
{
if (aboveleft->base.mv.raw)
{
union mv this_mv;
this_mv.raw = aboveleft->base.mv.raw;
mv_bias(aboveleft, sign_bias, this->base.ref_frame,
&this_mv);
if (this_mv.raw != mv->raw)
{
(++mv)->raw = this_mv.raw;
++cntx;
}
*cntx += 1;
}
else
cnt[CNT_ZEROZERO] += 1;
}
/* If we have three distinct MV's ... */
if (cnt[CNT_SPLITMV])
{
/* See if above-left MV can be merged with NEAREST */
if (mv->raw == near_mvs[CNT_NEAREST].raw)
cnt[CNT_NEAREST] += 1;
}
cnt[CNT_SPLITMV] = ((above->base.y_mode == SPLITMV)
+ (left->base.y_mode == SPLITMV)) * 2
+ (aboveleft->base.y_mode == SPLITMV);
/* Swap near and nearest if necessary */
if (cnt[CNT_NEAR] > cnt[CNT_NEAREST])
{
int tmp;
tmp = cnt[CNT_NEAREST];
cnt[CNT_NEAREST] = cnt[CNT_NEAR];
cnt[CNT_NEAR] = tmp;
tmp = near_mvs[CNT_NEAREST].raw;
near_mvs[CNT_NEAREST].raw = near_mvs[CNT_NEAR].raw;
near_mvs[CNT_NEAR].raw = tmp;
}
/* Use near_mvs[CNT_BEST] to store the "best" MV. Note that this
* storage shares the same address as near_mvs[CNT_ZEROZERO].
*/
if (cnt[CNT_NEAREST] >= cnt[CNT_BEST])
near_mvs[CNT_BEST] = near_mvs[CNT_NEAREST];
}
static void
decode_split_mv(struct mb_info *this,
const struct mb_info *left,
const struct mb_info *above,
struct vp8_entropy_hdr *hdr,
union mv *best_mv,
struct bool_decoder *bool)
{
const int *partition;
int j, k, mask, partition_id;
partition_id = bool_read_tree(bool, split_mv_tree, split_mv_probs);
partition = mv_partitions[partition_id];
this->base.partitioning = partition_id;
for (j = 0, mask = 0; mask < 65535; j++)
{
union mv mv, left_mv, above_mv;
enum prediction_mode subblock_mode;
/* Find the first subblock in this partition. */
for (k = 0; j != partition[k]; k++);
/* Decode the next MV */
left_mv = left_block_mv(this, left, k);
above_mv = above_block_mv(this, above, k);
subblock_mode = submv_ref(bool, left_mv, above_mv);
switch (subblock_mode)
{
case LEFT4X4:
mv = left_mv;
break;
case ABOVE4X4:
mv = above_mv;
break;
case ZERO4X4:
mv.raw = 0;
break;
case NEW4X4:
read_mv(bool, &mv, hdr->mv_probs);
mv.d.x += best_mv->d.x;
mv.d.y += best_mv->d.y;
break;
default:
assert(0);
}
/* Fill the MV's for this partition */
for (; k < 16; k++)
if (j == partition[k])
{
this->split.mvs[k] = mv;
mask |= 1 << k;
}
}
}
static int
need_mc_border(union mv mv, int l, int t, int b_w, int w, int h)
{
int b, r;
/* Get distance to edge for top-left pixel */
l += (mv.d.x >> 3);
t += (mv.d.y >> 3);
/* Get distance to edge for bottom-right pixel */
r = w - (l + b_w);
b = h - (t + b_w);
return (l >> 1 < 2 || r >> 1 < 3 || t >> 1 < 2 || b >> 1 < 3);
}
static void
decode_mvs(struct vp8_decoder_ctx *ctx,
struct mb_info *this,
const struct mb_info *left,
const struct mb_info *above,
const struct mv_clamp_rect *bounds,
struct bool_decoder *bool)
{
struct vp8_entropy_hdr *hdr = &ctx->entropy_hdr;
union mv near_mvs[4];
union mv clamped_best_mv;
int mv_cnts[4];
unsigned char probs[4];
enum {BEST, NEAREST, NEAR};
int x, y, w, h, b;
this->base.ref_frame = bool_get(bool, hdr->prob_last)
? 2 + bool_get(bool, hdr->prob_gf)
: 1;
find_near_mvs(this, this - 1, above, ctx->reference_hdr.sign_bias,
near_mvs, mv_cnts);
probs[0] = mv_counts_to_probs[mv_cnts[0]][0];
probs[1] = mv_counts_to_probs[mv_cnts[1]][1];
probs[2] = mv_counts_to_probs[mv_cnts[2]][2];
probs[3] = mv_counts_to_probs[mv_cnts[3]][3];
this->base.y_mode = bool_read_tree(bool, mv_ref_tree, probs);
this->base.uv_mode = this->base.y_mode;
this->base.need_mc_border = 0;
x = (-bounds->to_left - 128) >> 3;
y = (-bounds->to_top - 128) >> 3;
w = ctx->mb_cols * 16;
h = ctx->mb_rows * 16;
switch (this->base.y_mode)
{
case NEARESTMV:
this->base.mv = clamp_mv(near_mvs[NEAREST], bounds);
break;
case NEARMV:
this->base.mv = clamp_mv(near_mvs[NEAR], bounds);
break;
case ZEROMV:
this->base.mv.raw = 0;
return; //skip need_mc_border check
case NEWMV:
clamped_best_mv = clamp_mv(near_mvs[BEST], bounds);
read_mv(bool, &this->base.mv, hdr->mv_probs);
this->base.mv.d.x += clamped_best_mv.d.x;
this->base.mv.d.y += clamped_best_mv.d.y;
break;
case SPLITMV:
{
union mv chroma_mv[4] = {{{0}}};
clamped_best_mv = clamp_mv(near_mvs[BEST], bounds);
decode_split_mv(this, left, above, hdr, &clamped_best_mv, bool);
this->base.mv = this->split.mvs[15];
for (b = 0; b < 16; b++)
{
chroma_mv[(b>>1&1) + (b>>2&2)].d.x +=
this->split.mvs[b].d.x;
chroma_mv[(b>>1&1) + (b>>2&2)].d.y +=
this->split.mvs[b].d.y;
if (need_mc_border(this->split.mvs[b],
x + (b & 3) * 4, y + (b & ~3), 4, w, h))
{
this->base.need_mc_border = 1;
break;
}
}
for (b = 0; b < 4; b++)
{
chroma_mv[b].d.x += 4 + 8 * (chroma_mv[b].d.x >> 31);
chroma_mv[b].d.y += 4 + 8 * (chroma_mv[b].d.y >> 31);
chroma_mv[b].d.x /= 4;
chroma_mv[b].d.y /= 4;
//note we're passing in non-subsampled coordinates
if (need_mc_border(chroma_mv[b],
x + (b & 1) * 8, y + (b >> 1) * 8, 16, w, h))
{
this->base.need_mc_border = 1;
break;
}
}
return; //skip need_mc_border check
}
default:
assert(0);
}
if (need_mc_border(this->base.mv, x, y, 16, w, h))
this->base.need_mc_border = 1;
}
void
vp8_dixie_modemv_process_row(struct vp8_decoder_ctx *ctx,
struct bool_decoder *bool,
int row,
int start_col,
int num_cols)
{
struct mb_info *above, *this;
unsigned int col;
struct mv_clamp_rect bounds;
this = ctx->mb_info_rows[row] + start_col;
above = ctx->mb_info_rows[row - 1] + start_col;
/* Calculate the eighth-pel MV bounds using a 1 MB border. */
bounds.to_left = -((start_col + 1) << 7);
bounds.to_right = (ctx->mb_cols - start_col) << 7;
bounds.to_top = -((row + 1) << 7);
bounds.to_bottom = (ctx->mb_rows - row) << 7;
for (col = start_col; col < start_col + num_cols; col++)
{
if (ctx->segment_hdr.update_map)
this->base.segment_id = read_segment_id(bool,
&ctx->segment_hdr);
if (ctx->entropy_hdr.coeff_skip_enabled)
this->base.skip_coeff = bool_get(bool,
ctx->entropy_hdr.coeff_skip_prob);
if (ctx->frame_hdr.is_keyframe)
{
if (!ctx->segment_hdr.update_map)
this->base.segment_id = 0;
decode_kf_mb_mode(this, this - 1, above, bool);
}
else
{
if (bool_get(bool, ctx->entropy_hdr.prob_inter))
decode_mvs(ctx, this, this - 1, above, &bounds, bool);
else
decode_intra_mb_mode(this, &ctx->entropy_hdr, bool);
bounds.to_left -= 16 << 3;
bounds.to_right -= 16 << 3;
}
/* Advance to next mb */
this++;
above++;
}
}
void
vp8_dixie_modemv_init(struct vp8_decoder_ctx *ctx)
{
unsigned int mbi_w, mbi_h, i;
struct mb_info *mbi;
mbi_w = ctx->mb_cols + 1; /* For left border col */
mbi_h = ctx->mb_rows + 1; /* For above border row */
if (ctx->frame_hdr.frame_size_updated)
{
free(ctx->mb_info_storage);
ctx->mb_info_storage = NULL;
free(ctx->mb_info_rows_storage);
ctx->mb_info_rows_storage = NULL;
}
if (!ctx->mb_info_storage)
ctx->mb_info_storage = calloc(mbi_w * mbi_h,
sizeof(*ctx->mb_info_storage));
if (!ctx->mb_info_rows_storage)
ctx->mb_info_rows_storage = calloc(mbi_h,
sizeof(*ctx->mb_info_rows_storage));
/* Set up row pointers */
mbi = ctx->mb_info_storage + 1;
for (i = 0; i < mbi_h; i++)
{
ctx->mb_info_rows_storage[i] = mbi;
mbi += mbi_w;
}
ctx->mb_info_rows = ctx->mb_info_rows_storage + 1;
}
void
vp8_dixie_modemv_destroy(struct vp8_decoder_ctx *ctx)
{
free(ctx->mb_info_storage);
ctx->mb_info_storage = NULL;
free(ctx->mb_info_rows_storage);
ctx->mb_info_rows_storage = NULL;
}

28
vp8/dixie/modemv.h Normal file
View File

@@ -0,0 +1,28 @@
/*
* Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MODEMV_H
#define MODEMV_H
void
vp8_dixie_modemv_init(struct vp8_decoder_ctx *ctx);
void
vp8_dixie_modemv_destroy(struct vp8_decoder_ctx *ctx);
void
vp8_dixie_modemv_process_row(struct vp8_decoder_ctx *ctx,
struct bool_decoder *bool,
int row,
int start_col,
int num_cols);
#endif

216
vp8/dixie/modemv_data.h Normal file
View File

@@ -0,0 +1,216 @@
static const unsigned char kf_y_mode_probs[] = { 145, 156, 163, 128};
static const unsigned char kf_uv_mode_probs[] = { 142, 114, 183};
static const unsigned char kf_b_mode_probs[10][10][9] =
{
{ /* above mode 0 */
{ /* left mode 0 */ 231, 120, 48, 89, 115, 113, 120, 152, 112},
{ /* left mode 1 */ 152, 179, 64, 126, 170, 118, 46, 70, 95},
{ /* left mode 2 */ 175, 69, 143, 80, 85, 82, 72, 155, 103},
{ /* left mode 3 */ 56, 58, 10, 171, 218, 189, 17, 13, 152},
{ /* left mode 4 */ 144, 71, 10, 38, 171, 213, 144, 34, 26},
{ /* left mode 5 */ 114, 26, 17, 163, 44, 195, 21, 10, 173},
{ /* left mode 6 */ 121, 24, 80, 195, 26, 62, 44, 64, 85},
{ /* left mode 7 */ 170, 46, 55, 19, 136, 160, 33, 206, 71},
{ /* left mode 8 */ 63, 20, 8, 114, 114, 208, 12, 9, 226},
{ /* left mode 9 */ 81, 40, 11, 96, 182, 84, 29, 16, 36}
},
{ /* above mode 1 */
{ /* left mode 0 */ 134, 183, 89, 137, 98, 101, 106, 165, 148},
{ /* left mode 1 */ 72, 187, 100, 130, 157, 111, 32, 75, 80},
{ /* left mode 2 */ 66, 102, 167, 99, 74, 62, 40, 234, 128},
{ /* left mode 3 */ 41, 53, 9, 178, 241, 141, 26, 8, 107},
{ /* left mode 4 */ 104, 79, 12, 27, 217, 255, 87, 17, 7},
{ /* left mode 5 */ 74, 43, 26, 146, 73, 166, 49, 23, 157},
{ /* left mode 6 */ 65, 38, 105, 160, 51, 52, 31, 115, 128},
{ /* left mode 7 */ 87, 68, 71, 44, 114, 51, 15, 186, 23},
{ /* left mode 8 */ 47, 41, 14, 110, 182, 183, 21, 17, 194},
{ /* left mode 9 */ 66, 45, 25, 102, 197, 189, 23, 18, 22}
},
{ /* above mode 2 */
{ /* left mode 0 */ 88, 88, 147, 150, 42, 46, 45, 196, 205},
{ /* left mode 1 */ 43, 97, 183, 117, 85, 38, 35, 179, 61},
{ /* left mode 2 */ 39, 53, 200, 87, 26, 21, 43, 232, 171},
{ /* left mode 3 */ 56, 34, 51, 104, 114, 102, 29, 93, 77},
{ /* left mode 4 */ 107, 54, 32, 26, 51, 1, 81, 43, 31},
{ /* left mode 5 */ 39, 28, 85, 171, 58, 165, 90, 98, 64},
{ /* left mode 6 */ 34, 22, 116, 206, 23, 34, 43, 166, 73},
{ /* left mode 7 */ 68, 25, 106, 22, 64, 171, 36, 225, 114},
{ /* left mode 8 */ 34, 19, 21, 102, 132, 188, 16, 76, 124},
{ /* left mode 9 */ 62, 18, 78, 95, 85, 57, 50, 48, 51}
},
{ /* above mode 3 */
{ /* left mode 0 */ 193, 101, 35, 159, 215, 111, 89, 46, 111},
{ /* left mode 1 */ 60, 148, 31, 172, 219, 228, 21, 18, 111},
{ /* left mode 2 */ 112, 113, 77, 85, 179, 255, 38, 120, 114},
{ /* left mode 3 */ 40, 42, 1, 196, 245, 209, 10, 25, 109},
{ /* left mode 4 */ 100, 80, 8, 43, 154, 1, 51, 26, 71},
{ /* left mode 5 */ 88, 43, 29, 140, 166, 213, 37, 43, 154},
{ /* left mode 6 */ 61, 63, 30, 155, 67, 45, 68, 1, 209},
{ /* left mode 7 */ 142, 78, 78, 16, 255, 128, 34, 197, 171},
{ /* left mode 8 */ 41, 40, 5, 102, 211, 183, 4, 1, 221},
{ /* left mode 9 */ 51, 50, 17, 168, 209, 192, 23, 25, 82}
},
{ /* above mode 4 */
{ /* left mode 0 */ 125, 98, 42, 88, 104, 85, 117, 175, 82},
{ /* left mode 1 */ 95, 84, 53, 89, 128, 100, 113, 101, 45},
{ /* left mode 2 */ 75, 79, 123, 47, 51, 128, 81, 171, 1},
{ /* left mode 3 */ 57, 17, 5, 71, 102, 57, 53, 41, 49},
{ /* left mode 4 */ 115, 21, 2, 10, 102, 255, 166, 23, 6},
{ /* left mode 5 */ 38, 33, 13, 121, 57, 73, 26, 1, 85},
{ /* left mode 6 */ 41, 10, 67, 138, 77, 110, 90, 47, 114},
{ /* left mode 7 */ 101, 29, 16, 10, 85, 128, 101, 196, 26},
{ /* left mode 8 */ 57, 18, 10, 102, 102, 213, 34, 20, 43},
{ /* left mode 9 */ 117, 20, 15, 36, 163, 128, 68, 1, 26}
},
{ /* above mode 5 */
{ /* left mode 0 */ 138, 31, 36, 171, 27, 166, 38, 44, 229},
{ /* left mode 1 */ 67, 87, 58, 169, 82, 115, 26, 59, 179},
{ /* left mode 2 */ 63, 59, 90, 180, 59, 166, 93, 73, 154},
{ /* left mode 3 */ 40, 40, 21, 116, 143, 209, 34, 39, 175},
{ /* left mode 4 */ 57, 46, 22, 24, 128, 1, 54, 17, 37},
{ /* left mode 5 */ 47, 15, 16, 183, 34, 223, 49, 45, 183},
{ /* left mode 6 */ 46, 17, 33, 183, 6, 98, 15, 32, 183},
{ /* left mode 7 */ 65, 32, 73, 115, 28, 128, 23, 128, 205},
{ /* left mode 8 */ 40, 3, 9, 115, 51, 192, 18, 6, 223},
{ /* left mode 9 */ 87, 37, 9, 115, 59, 77, 64, 21, 47}
},
{ /* above mode 6 */
{ /* left mode 0 */ 104, 55, 44, 218, 9, 54, 53, 130, 226},
{ /* left mode 1 */ 64, 90, 70, 205, 40, 41, 23, 26, 57},
{ /* left mode 2 */ 54, 57, 112, 184, 5, 41, 38, 166, 213},
{ /* left mode 3 */ 30, 34, 26, 133, 152, 116, 10, 32, 134},
{ /* left mode 4 */ 75, 32, 12, 51, 192, 255, 160, 43, 51},
{ /* left mode 5 */ 39, 19, 53, 221, 26, 114, 32, 73, 255},
{ /* left mode 6 */ 31, 9, 65, 234, 2, 15, 1, 118, 73},
{ /* left mode 7 */ 88, 31, 35, 67, 102, 85, 55, 186, 85},
{ /* left mode 8 */ 56, 21, 23, 111, 59, 205, 45, 37, 192},
{ /* left mode 9 */ 55, 38, 70, 124, 73, 102, 1, 34, 98}
},
{ /* above mode 7 */
{ /* left mode 0 */ 102, 61, 71, 37, 34, 53, 31, 243, 192},
{ /* left mode 1 */ 69, 60, 71, 38, 73, 119, 28, 222, 37},
{ /* left mode 2 */ 68, 45, 128, 34, 1, 47, 11, 245, 171},
{ /* left mode 3 */ 62, 17, 19, 70, 146, 85, 55, 62, 70},
{ /* left mode 4 */ 75, 15, 9, 9, 64, 255, 184, 119, 16},
{ /* left mode 5 */ 37, 43, 37, 154, 100, 163, 85, 160, 1},
{ /* left mode 6 */ 63, 9, 92, 136, 28, 64, 32, 201, 85},
{ /* left mode 7 */ 86, 6, 28, 5, 64, 255, 25, 248, 1},
{ /* left mode 8 */ 56, 8, 17, 132, 137, 255, 55, 116, 128},
{ /* left mode 9 */ 58, 15, 20, 82, 135, 57, 26, 121, 40}
},
{ /* above mode 8 */
{ /* left mode 0 */ 164, 50, 31, 137, 154, 133, 25, 35, 218},
{ /* left mode 1 */ 51, 103, 44, 131, 131, 123, 31, 6, 158},
{ /* left mode 2 */ 86, 40, 64, 135, 148, 224, 45, 183, 128},
{ /* left mode 3 */ 22, 26, 17, 131, 240, 154, 14, 1, 209},
{ /* left mode 4 */ 83, 12, 13, 54, 192, 255, 68, 47, 28},
{ /* left mode 5 */ 45, 16, 21, 91, 64, 222, 7, 1, 197},
{ /* left mode 6 */ 56, 21, 39, 155, 60, 138, 23, 102, 213},
{ /* left mode 7 */ 85, 26, 85, 85, 128, 128, 32, 146, 171},
{ /* left mode 8 */ 18, 11, 7, 63, 144, 171, 4, 4, 246},
{ /* left mode 9 */ 35, 27, 10, 146, 174, 171, 12, 26, 128}
},
{ /* above mode 9 */
{ /* left mode 0 */ 190, 80, 35, 99, 180, 80, 126, 54, 45},
{ /* left mode 1 */ 85, 126, 47, 87, 176, 51, 41, 20, 32},
{ /* left mode 2 */ 101, 75, 128, 139, 118, 146, 116, 128, 85},
{ /* left mode 3 */ 56, 41, 15, 176, 236, 85, 37, 9, 62},
{ /* left mode 4 */ 146, 36, 19, 30, 171, 255, 97, 27, 20},
{ /* left mode 5 */ 71, 30, 17, 119, 118, 255, 17, 18, 138},
{ /* left mode 6 */ 101, 38, 60, 138, 55, 70, 43, 26, 142},
{ /* left mode 7 */ 138, 45, 61, 62, 219, 1, 81, 188, 64},
{ /* left mode 8 */ 32, 41, 20, 117, 151, 142, 20, 21, 163},
{ /* left mode 9 */ 112, 19, 12, 61, 195, 128, 48, 4, 24}
}
};
static const int kf_y_mode_tree[] =
{
-B_PRED, 2,
4, 6,
-DC_PRED, -V_PRED,
-H_PRED, -TM_PRED
};
static const int y_mode_tree[] =
{
-DC_PRED, 2,
4, 6,
-V_PRED, -H_PRED,
-TM_PRED, -B_PRED
};
static const int uv_mode_tree[6] =
{
-DC_PRED, 2,
-V_PRED, 4,
-H_PRED, -TM_PRED
};
static const int b_mode_tree[18] =
{
-B_DC_PRED, 2, /* 0 = DC_NODE */
-B_TM_PRED, 4, /* 1 = TM_NODE */
-B_VE_PRED, 6, /* 2 = VE_NODE */
8, 12, /* 3 = COM_NODE */
-B_HE_PRED, 10, /* 4 = HE_NODE */
-B_RD_PRED, -B_VR_PRED, /* 5 = RD_NODE */
-B_LD_PRED, 14, /* 6 = LD_NODE */
-B_VL_PRED, 16, /* 7 = VL_NODE */
-B_HD_PRED, -B_HU_PRED /* 8 = HD_NODE */
};
static const int small_mv_tree[14] =
{
2, 8,
4, 6,
-0, -1,
-2, -3,
10, 12,
-4, -5,
-6, -7
};
static const int mv_ref_tree[8] =
{
-ZEROMV, 2,
-NEARESTMV, 4,
-NEARMV, 6,
-NEWMV, -SPLITMV
};
static const int submv_ref_tree[6] =
{
-LEFT4X4, 2,
-ABOVE4X4, 4,
-ZERO4X4, -NEW4X4
};
static const int split_mv_tree[6] =
{
-3, 2,
-2, 4,
-0, -1
};
static const unsigned char default_b_mode_probs[] =
{ 120, 90, 79, 133, 87, 85, 80, 111, 151};
static const unsigned char mv_counts_to_probs[6][4] =
{
{ 7, 1, 1, 143 },
{ 14, 18, 14, 107 },
{ 135, 64, 57, 68 },
{ 60, 56, 128, 65 },
{ 159, 134, 128, 34 },
{ 234, 188, 128, 28 }
};
static const unsigned char split_mv_probs[3] =
{ 110, 111, 150};
static const unsigned char submv_ref_probs2[5][3] =
{
{ 147, 136, 18 },
{ 106, 145, 1 },
{ 179, 121, 1 },
{ 223, 1, 34 },
{ 208, 1, 1 }
};
const static int mv_partitions[4][16] =
{
{0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1 },
{0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1 },
{0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 3, 3, 2, 2, 3, 3 },
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }
};

1420
vp8/dixie/predict.c Normal file

File diff suppressed because it is too large Load Diff

36
vp8/dixie/predict.h Normal file
View File

@@ -0,0 +1,36 @@
/*
* Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef PREDICT_H
#define PREDICT_H
void
vp8_dixie_predict_init(struct vp8_decoder_ctx *ctx);
void
vp8_dixie_predict_destroy(struct vp8_decoder_ctx *ctx);
void
vp8_dixie_predict_process_row(struct vp8_decoder_ctx *ctx,
unsigned int row,
unsigned int start_col,
unsigned int num_cols);
void
vp8_dixie_release_ref_frame(struct ref_cnt_img *rcimg);
struct ref_cnt_img *
vp8_dixie_ref_frame(struct ref_cnt_img *rcimg);
struct ref_cnt_img *
vp8_dixie_find_free_ref_frame(struct ref_cnt_img *frames);
#endif

443
vp8/dixie/tokens.c Normal file
View File

@@ -0,0 +1,443 @@
/*
* Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "vpx/internal/vpx_codec_internal.h"
#include "dixie.h"
#include "tokens.h"
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
enum
{
EOB_CONTEXT_NODE,
ZERO_CONTEXT_NODE,
ONE_CONTEXT_NODE,
LOW_VAL_CONTEXT_NODE,
TWO_CONTEXT_NODE,
THREE_CONTEXT_NODE,
HIGH_LOW_CONTEXT_NODE,
CAT_ONE_CONTEXT_NODE,
CAT_THREEFOUR_CONTEXT_NODE,
CAT_THREE_CONTEXT_NODE,
CAT_FIVE_CONTEXT_NODE
};
enum
{
ZERO_TOKEN,
ONE_TOKEN,
TWO_TOKEN,
THREE_TOKEN,
FOUR_TOKEN,
DCT_VAL_CATEGORY1,
DCT_VAL_CATEGORY2,
DCT_VAL_CATEGORY3,
DCT_VAL_CATEGORY4,
DCT_VAL_CATEGORY5,
DCT_VAL_CATEGORY6,
DCT_EOB_TOKEN,
MAX_ENTROPY_TOKENS
};
struct extrabits
{
short min_val;
short length;
unsigned char probs[12];
};
static const unsigned int left_context_index[25] =
{
0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3,
4, 4, 5, 5, 6, 6, 7, 7, 8
};
static const unsigned int above_context_index[25] =
{
0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3,
4, 5, 4, 5, 6, 7, 6, 7, 8
};
#define X(n) ((n) * PREV_COEF_CONTEXTS * ENTROPY_NODES)
static const unsigned int bands_x[16] =
{
X(0), X(1), X(2), X(3), X(6), X(4), X(5), X(6),
X(6), X(6), X(6), X(6), X(6), X(6), X(6), X(7)
};
#undef X
static const struct extrabits extrabits[MAX_ENTROPY_TOKENS] =
{
{ 0, -1, { 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0 } }, //ZERO_TOKEN
{ 1, 0, { 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0 } }, //ONE_TOKEN
{ 2, 0, { 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0 } }, //TWO_TOKEN
{ 3, 0, { 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0 } }, //THREE_TOKEN
{ 4, 0, { 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0 } }, //FOUR_TOKEN
{ 5, 0, { 159, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0 } }, //DCT_VAL_CATEGORY1
{ 7, 1, { 145, 165, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0 } }, //DCT_VAL_CATEGORY2
{ 11, 2, { 140, 148, 173, 0, 0, 0,
0, 0, 0, 0, 0, 0 } }, //DCT_VAL_CATEGORY3
{ 19, 3, { 135, 140, 155, 176, 0, 0,
0, 0, 0, 0, 0, 0 } }, //DCT_VAL_CATEGORY4
{ 35, 4, { 130, 134, 141, 157, 180, 0,
0, 0, 0, 0, 0, 0 } }, //DCT_VAL_CATEGORY5
{ 67, 10, { 129, 130, 133, 140, 153, 177,
196, 230, 243, 254, 254, 0 } }, //DCT_VAL_CATEGORY6
{ 0, -1, { 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0 } }, // EOB TOKEN
};
static const unsigned int zigzag[16] =
{
0, 1, 4, 8, 5, 2, 3, 6, 9, 12, 13, 10, 7, 11, 14, 15
};
#define DECODE_AND_APPLYSIGN(value_to_sign) \
v = (bool_get_bit(bool) ? -value_to_sign \
: value_to_sign) * dqf[!!c];
#define DECODE_AND_BRANCH_IF_ZERO(probability,branch) \
if (!bool_get(bool, probability)) goto branch;
#define DECODE_AND_LOOP_IF_ZERO(probability,branch) \
if (!bool_get(bool, probability)) \
{ \
prob = type_probs; \
if(c<15) {\
++c; \
prob += bands_x[c]; \
goto branch; \
}\
else \
goto BLOCK_FINISHED; /*for malformed input */\
}
#define DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val) \
DECODE_AND_APPLYSIGN(val) \
prob = type_probs + (ENTROPY_NODES*2); \
if(c < 15){\
b_tokens[zigzag[c]] = v; \
++c; \
goto DO_WHILE; }\
b_tokens[zigzag[15]] = v; \
goto BLOCK_FINISHED;
#define DECODE_EXTRABIT_AND_ADJUST_VAL(t,bits_count)\
val += bool_get(bool, extrabits[t].probs[bits_count]) << bits_count;
static int
decode_mb_tokens(struct bool_decoder *bool,
token_entropy_ctx_t left,
token_entropy_ctx_t above,
short *tokens,
enum prediction_mode mode,
coeff_probs_table_t probs,
short factor[TOKEN_BLOCK_TYPES][2])
{
int i, stop, type;
int c, t, v;
int val, bits_count;
int eob_mask;
short *b_tokens; /* tokens for this block */
unsigned char *type_probs; /* probabilities for this block type */
unsigned char *prob;
short *dqf;
eob_mask = 0;
if (mode != B_PRED && mode != SPLITMV)
{
i = 24;
stop = 24;
type = 1;
b_tokens = tokens + 24 * 16;
dqf = factor[TOKEN_BLOCK_Y2];
}
else
{
i = 0;
stop = 16;
type = 3;
b_tokens = tokens;
dqf = factor[TOKEN_BLOCK_Y1];
}
/* Save a pointer to the coefficient probs for the current type.
* Need to repeat this whenever type changes.
*/
type_probs = probs[type][0][0];
BLOCK_LOOP:
t = left[left_context_index[i]] + above[above_context_index[i]];
c = !type; /* all blocks start at 0 except type 0, which starts
* at 1. */
prob = type_probs;
prob += t * ENTROPY_NODES;
DO_WHILE:
prob += bands_x[c];
DECODE_AND_BRANCH_IF_ZERO(prob[EOB_CONTEXT_NODE], BLOCK_FINISHED);
CHECK_0_:
DECODE_AND_LOOP_IF_ZERO(prob[ZERO_CONTEXT_NODE], CHECK_0_);
DECODE_AND_BRANCH_IF_ZERO(prob[ONE_CONTEXT_NODE],
ONE_CONTEXT_NODE_0_);
DECODE_AND_BRANCH_IF_ZERO(prob[LOW_VAL_CONTEXT_NODE],
LOW_VAL_CONTEXT_NODE_0_);
DECODE_AND_BRANCH_IF_ZERO(prob[HIGH_LOW_CONTEXT_NODE],
HIGH_LOW_CONTEXT_NODE_0_);
DECODE_AND_BRANCH_IF_ZERO(prob[CAT_THREEFOUR_CONTEXT_NODE],
CAT_THREEFOUR_CONTEXT_NODE_0_);
DECODE_AND_BRANCH_IF_ZERO(prob[CAT_FIVE_CONTEXT_NODE],
CAT_FIVE_CONTEXT_NODE_0_);
val = extrabits[DCT_VAL_CATEGORY6].min_val;
bits_count = extrabits[DCT_VAL_CATEGORY6].length;
do
{
DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY6, bits_count);
bits_count -- ;
}
while (bits_count >= 0);
DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val);
CAT_FIVE_CONTEXT_NODE_0_:
val = extrabits[DCT_VAL_CATEGORY5].min_val;
DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY5, 4);
DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY5, 3);
DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY5, 2);
DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY5, 1);
DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY5, 0);
DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val);
CAT_THREEFOUR_CONTEXT_NODE_0_:
DECODE_AND_BRANCH_IF_ZERO(prob[CAT_THREE_CONTEXT_NODE],
CAT_THREE_CONTEXT_NODE_0_);
val = extrabits[DCT_VAL_CATEGORY4].min_val;
DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY4, 3);
DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY4, 2);
DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY4, 1);
DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY4, 0);
DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val);
CAT_THREE_CONTEXT_NODE_0_:
val = extrabits[DCT_VAL_CATEGORY3].min_val;
DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY3, 2);
DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY3, 1);
DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY3, 0);
DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val);
HIGH_LOW_CONTEXT_NODE_0_:
DECODE_AND_BRANCH_IF_ZERO(prob[CAT_ONE_CONTEXT_NODE],
CAT_ONE_CONTEXT_NODE_0_);
val = extrabits[DCT_VAL_CATEGORY2].min_val;
DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY2, 1);
DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY2, 0);
DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val);
CAT_ONE_CONTEXT_NODE_0_:
val = extrabits[DCT_VAL_CATEGORY1].min_val;
DECODE_EXTRABIT_AND_ADJUST_VAL(DCT_VAL_CATEGORY1, 0);
DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(val);
LOW_VAL_CONTEXT_NODE_0_:
DECODE_AND_BRANCH_IF_ZERO(prob[TWO_CONTEXT_NODE],
TWO_CONTEXT_NODE_0_);
DECODE_AND_BRANCH_IF_ZERO(prob[THREE_CONTEXT_NODE],
THREE_CONTEXT_NODE_0_);
DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(4);
THREE_CONTEXT_NODE_0_:
DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(3);
TWO_CONTEXT_NODE_0_:
DECODE_SIGN_WRITE_COEFF_AND_CHECK_EXIT(2);
ONE_CONTEXT_NODE_0_:
DECODE_AND_APPLYSIGN(1);
prob = type_probs + ENTROPY_NODES;
if (c < 15)
{
b_tokens[zigzag[c]] = v;
++c;
goto DO_WHILE;
}
b_tokens[zigzag[15]] = v;
BLOCK_FINISHED:
eob_mask |= (c > 1) << i;
t = (c != !type); // any nonzero data?
eob_mask |= t << 31;
left[left_context_index[i]] = above[above_context_index[i]] = t;
b_tokens += 16;
i++;
if (i < stop)
goto BLOCK_LOOP;
if (i == 25)
{
type = 0;
i = 0;
stop = 16;
type_probs = probs[type][0][0];
b_tokens = tokens;
dqf = factor[TOKEN_BLOCK_Y1];
goto BLOCK_LOOP;
}
if (i == 16)
{
type = 2;
type_probs = probs[type][0][0];
stop = 24;
dqf = factor[TOKEN_BLOCK_UV];
goto BLOCK_LOOP;
}
return eob_mask;
}
static void
reset_row_context(token_entropy_ctx_t *left)
{
memset(left, 0, sizeof(*left));
}
static void
reset_above_context(token_entropy_ctx_t *above, unsigned int cols)
{
memset(above, 0, cols * sizeof(*above));
}
static void
reset_mb_context(token_entropy_ctx_t *left,
token_entropy_ctx_t *above,
enum prediction_mode mode)
{
/* Reset the macroblock context on the left and right. We have to
* preserve the context of the second order block if this mode
* would not have updated it.
*/
memset(left, 0, sizeof((*left)[0]) * 8);
memset(above, 0, sizeof((*above)[0]) * 8);
if (mode != B_PRED && mode != SPLITMV)
{
(*left)[8] = 0;
(*above)[8] = 0;
}
}
void
vp8_dixie_tokens_process_row(struct vp8_decoder_ctx *ctx,
unsigned int partition,
unsigned int row,
unsigned int start_col,
unsigned int num_cols)
{
struct token_decoder *tokens = &ctx->tokens[partition];
short *coeffs = tokens->coeffs + 25 * 16 * start_col;
unsigned int col;
token_entropy_ctx_t *above = ctx->above_token_entropy_ctx
+ start_col;
token_entropy_ctx_t *left = &tokens->left_token_entropy_ctx;
struct mb_info *mbi = ctx->mb_info_rows[row] + start_col;
if (row == 0)
reset_above_context(above, num_cols);
if (start_col == 0)
reset_row_context(left);
for (col = start_col; col < start_col + num_cols; col++)
{
memset(coeffs, 0, 25 * 16 * sizeof(short));
if (mbi->base.skip_coeff)
{
reset_mb_context(left, above, mbi->base.y_mode);
mbi->base.eob_mask = 0;
}
else
{
struct dequant_factors *dqf;
dqf = ctx->dequant_factors + mbi->base.segment_id;
mbi->base.eob_mask =
decode_mb_tokens(&tokens->bool,
*left, *above,
coeffs,
mbi->base.y_mode,
ctx->entropy_hdr.coeff_probs,
dqf->factor);
}
above++;
mbi++;
coeffs += 25 * 16;
}
}
void
vp8_dixie_tokens_init(struct vp8_decoder_ctx *ctx)
{
unsigned int partitions = ctx->token_hdr.partitions;
if (ctx->frame_hdr.frame_size_updated)
{
unsigned int i;
unsigned int coeff_row_sz =
ctx->mb_cols * 25 * 16 * sizeof(short);
for (i = 0; i < partitions; i++)
{
free(ctx->tokens[i].coeffs);
ctx->tokens[i].coeffs = memalign(16, coeff_row_sz);
if (!ctx->tokens[i].coeffs)
vpx_internal_error(&ctx->error, VPX_CODEC_MEM_ERROR,
NULL);
}
free(ctx->above_token_entropy_ctx);
ctx->above_token_entropy_ctx =
calloc(ctx->mb_cols, sizeof(*ctx->above_token_entropy_ctx));
if (!ctx->above_token_entropy_ctx)
vpx_internal_error(&ctx->error, VPX_CODEC_MEM_ERROR, NULL);
}
}
void
vp8_dixie_tokens_destroy(struct vp8_decoder_ctx *ctx)
{
int i;
for (i = 0; i < MAX_PARTITIONS; i++)
free(ctx->tokens[i].coeffs);
free(ctx->above_token_entropy_ctx);
}

28
vp8/dixie/tokens.h Normal file
View File

@@ -0,0 +1,28 @@
/*
* Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef TOKENS_H
#define TOKENS_H
void
vp8_dixie_tokens_init(struct vp8_decoder_ctx *ctx);
void
vp8_dixie_tokens_destroy(struct vp8_decoder_ctx *ctx);
void
vp8_dixie_tokens_process_row(struct vp8_decoder_ctx *ctx,
unsigned int partition,
unsigned int row,
unsigned int start_col,
unsigned int num_cols);
#endif

396
vp8/dixie/vp8_prob_data.h Normal file
View File

@@ -0,0 +1,396 @@
static const
unsigned char k_coeff_entropy_update_probs[BLOCK_TYPES][COEF_BANDS]
[PREV_COEF_CONTEXTS]
[ENTROPY_NODES] =
{
{
{
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
},
{
{176, 246, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{223, 241, 252, 255, 255, 255, 255, 255, 255, 255, 255, },
{249, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 244, 252, 255, 255, 255, 255, 255, 255, 255, 255, },
{234, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
{253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 246, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
{239, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
{254, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 248, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
{251, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
{251, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
{254, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 254, 253, 255, 254, 255, 255, 255, 255, 255, 255, },
{250, 255, 254, 255, 254, 255, 255, 255, 255, 255, 255, },
{254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
},
},
{
{
{217, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{225, 252, 241, 253, 255, 255, 254, 255, 255, 255, 255, },
{234, 250, 241, 250, 253, 255, 253, 254, 255, 255, 255, },
},
{
{255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{223, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
{238, 253, 254, 254, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 248, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
{249, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 253, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{247, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
{252, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
{253, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 254, 253, 255, 255, 255, 255, 255, 255, 255, 255, },
{250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
},
},
{
{
{186, 251, 250, 255, 255, 255, 255, 255, 255, 255, 255, },
{234, 251, 244, 254, 255, 255, 255, 255, 255, 255, 255, },
{251, 251, 243, 253, 254, 255, 254, 255, 255, 255, 255, },
},
{
{255, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
{236, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
{251, 253, 253, 254, 254, 255, 255, 255, 255, 255, 255, },
},
{
{255, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
{254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
},
},
{
{
{248, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{250, 254, 252, 254, 255, 255, 255, 255, 255, 255, 255, },
{248, 254, 249, 253, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255, },
{246, 253, 253, 255, 255, 255, 255, 255, 255, 255, 255, },
{252, 254, 251, 254, 254, 255, 255, 255, 255, 255, 255, },
},
{
{255, 254, 252, 255, 255, 255, 255, 255, 255, 255, 255, },
{248, 254, 253, 255, 255, 255, 255, 255, 255, 255, 255, },
{253, 255, 254, 254, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 251, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
{245, 251, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
{253, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 251, 253, 255, 255, 255, 255, 255, 255, 255, 255, },
{252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 252, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{249, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 255, 254, 255, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 255, 253, 255, 255, 255, 255, 255, 255, 255, 255, },
{250, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
},
{
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, },
},
},
};
static const
unsigned char k_default_y_mode_probs [] =
{ 112, 86, 140, 37};
static const
unsigned char k_default_uv_mode_probs [] =
{ 162, 101, 204};
static const
unsigned char k_default_coeff_probs [BLOCK_TYPES][COEF_BANDS]
[PREV_COEF_CONTEXTS][ENTROPY_NODES] =
{
{ /* block type 0 */
{ /* coeff band 0 */
{ 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128},
{ 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128},
{ 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128}
},
{ /* coeff band 1 */
{ 253, 136, 254, 255, 228, 219, 128, 128, 128, 128, 128},
{ 189, 129, 242, 255, 227, 213, 255, 219, 128, 128, 128},
{ 106, 126, 227, 252, 214, 209, 255, 255, 128, 128, 128}
},
{ /* coeff band 2 */
{ 1, 98, 248, 255, 236, 226, 255, 255, 128, 128, 128},
{ 181, 133, 238, 254, 221, 234, 255, 154, 128, 128, 128},
{ 78, 134, 202, 247, 198, 180, 255, 219, 128, 128, 128}
},
{ /* coeff band 3 */
{ 1, 185, 249, 255, 243, 255, 128, 128, 128, 128, 128},
{ 184, 150, 247, 255, 236, 224, 128, 128, 128, 128, 128},
{ 77, 110, 216, 255, 236, 230, 128, 128, 128, 128, 128}
},
{ /* coeff band 4 */
{ 1, 101, 251, 255, 241, 255, 128, 128, 128, 128, 128},
{ 170, 139, 241, 252, 236, 209, 255, 255, 128, 128, 128},
{ 37, 116, 196, 243, 228, 255, 255, 255, 128, 128, 128}
},
{ /* coeff band 5 */
{ 1, 204, 254, 255, 245, 255, 128, 128, 128, 128, 128},
{ 207, 160, 250, 255, 238, 128, 128, 128, 128, 128, 128},
{ 102, 103, 231, 255, 211, 171, 128, 128, 128, 128, 128}
},
{ /* coeff band 6 */
{ 1, 152, 252, 255, 240, 255, 128, 128, 128, 128, 128},
{ 177, 135, 243, 255, 234, 225, 128, 128, 128, 128, 128},
{ 80, 129, 211, 255, 194, 224, 128, 128, 128, 128, 128}
},
{ /* coeff band 7 */
{ 1, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128},
{ 246, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128},
{ 255, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128}
}
},
{ /* block type 1 */
{ /* coeff band 0 */
{ 198, 35, 237, 223, 193, 187, 162, 160, 145, 155, 62},
{ 131, 45, 198, 221, 172, 176, 220, 157, 252, 221, 1},
{ 68, 47, 146, 208, 149, 167, 221, 162, 255, 223, 128}
},
{ /* coeff band 1 */
{ 1, 149, 241, 255, 221, 224, 255, 255, 128, 128, 128},
{ 184, 141, 234, 253, 222, 220, 255, 199, 128, 128, 128},
{ 81, 99, 181, 242, 176, 190, 249, 202, 255, 255, 128}
},
{ /* coeff band 2 */
{ 1, 129, 232, 253, 214, 197, 242, 196, 255, 255, 128},
{ 99, 121, 210, 250, 201, 198, 255, 202, 128, 128, 128},
{ 23, 91, 163, 242, 170, 187, 247, 210, 255, 255, 128}
},
{ /* coeff band 3 */
{ 1, 200, 246, 255, 234, 255, 128, 128, 128, 128, 128},
{ 109, 178, 241, 255, 231, 245, 255, 255, 128, 128, 128},
{ 44, 130, 201, 253, 205, 192, 255, 255, 128, 128, 128}
},
{ /* coeff band 4 */
{ 1, 132, 239, 251, 219, 209, 255, 165, 128, 128, 128},
{ 94, 136, 225, 251, 218, 190, 255, 255, 128, 128, 128},
{ 22, 100, 174, 245, 186, 161, 255, 199, 128, 128, 128}
},
{ /* coeff band 5 */
{ 1, 182, 249, 255, 232, 235, 128, 128, 128, 128, 128},
{ 124, 143, 241, 255, 227, 234, 128, 128, 128, 128, 128},
{ 35, 77, 181, 251, 193, 211, 255, 205, 128, 128, 128}
},
{ /* coeff band 6 */
{ 1, 157, 247, 255, 236, 231, 255, 255, 128, 128, 128},
{ 121, 141, 235, 255, 225, 227, 255, 255, 128, 128, 128},
{ 45, 99, 188, 251, 195, 217, 255, 224, 128, 128, 128}
},
{ /* coeff band 7 */
{ 1, 1, 251, 255, 213, 255, 128, 128, 128, 128, 128},
{ 203, 1, 248, 255, 255, 128, 128, 128, 128, 128, 128},
{ 137, 1, 177, 255, 224, 255, 128, 128, 128, 128, 128}
}
},
{ /* block type 2 */
{ /* coeff band 0 */
{ 253, 9, 248, 251, 207, 208, 255, 192, 128, 128, 128},
{ 175, 13, 224, 243, 193, 185, 249, 198, 255, 255, 128},
{ 73, 17, 171, 221, 161, 179, 236, 167, 255, 234, 128}
},
{ /* coeff band 1 */
{ 1, 95, 247, 253, 212, 183, 255, 255, 128, 128, 128},
{ 239, 90, 244, 250, 211, 209, 255, 255, 128, 128, 128},
{ 155, 77, 195, 248, 188, 195, 255, 255, 128, 128, 128}
},
{ /* coeff band 2 */
{ 1, 24, 239, 251, 218, 219, 255, 205, 128, 128, 128},
{ 201, 51, 219, 255, 196, 186, 128, 128, 128, 128, 128},
{ 69, 46, 190, 239, 201, 218, 255, 228, 128, 128, 128}
},
{ /* coeff band 3 */
{ 1, 191, 251, 255, 255, 128, 128, 128, 128, 128, 128},
{ 223, 165, 249, 255, 213, 255, 128, 128, 128, 128, 128},
{ 141, 124, 248, 255, 255, 128, 128, 128, 128, 128, 128}
},
{ /* coeff band 4 */
{ 1, 16, 248, 255, 255, 128, 128, 128, 128, 128, 128},
{ 190, 36, 230, 255, 236, 255, 128, 128, 128, 128, 128},
{ 149, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128}
},
{ /* coeff band 5 */
{ 1, 226, 255, 128, 128, 128, 128, 128, 128, 128, 128},
{ 247, 192, 255, 128, 128, 128, 128, 128, 128, 128, 128},
{ 240, 128, 255, 128, 128, 128, 128, 128, 128, 128, 128}
},
{ /* coeff band 6 */
{ 1, 134, 252, 255, 255, 128, 128, 128, 128, 128, 128},
{ 213, 62, 250, 255, 255, 128, 128, 128, 128, 128, 128},
{ 55, 93, 255, 128, 128, 128, 128, 128, 128, 128, 128}
},
{ /* coeff band 7 */
{ 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128},
{ 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128},
{ 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128}
}
},
{ /* block type 3 */
{ /* coeff band 0 */
{ 202, 24, 213, 235, 186, 191, 220, 160, 240, 175, 255},
{ 126, 38, 182, 232, 169, 184, 228, 174, 255, 187, 128},
{ 61, 46, 138, 219, 151, 178, 240, 170, 255, 216, 128}
},
{ /* coeff band 1 */
{ 1, 112, 230, 250, 199, 191, 247, 159, 255, 255, 128},
{ 166, 109, 228, 252, 211, 215, 255, 174, 128, 128, 128},
{ 39, 77, 162, 232, 172, 180, 245, 178, 255, 255, 128}
},
{ /* coeff band 2 */
{ 1, 52, 220, 246, 198, 199, 249, 220, 255, 255, 128},
{ 124, 74, 191, 243, 183, 193, 250, 221, 255, 255, 128},
{ 24, 71, 130, 219, 154, 170, 243, 182, 255, 255, 128}
},
{ /* coeff band 3 */
{ 1, 182, 225, 249, 219, 240, 255, 224, 128, 128, 128},
{ 149, 150, 226, 252, 216, 205, 255, 171, 128, 128, 128},
{ 28, 108, 170, 242, 183, 194, 254, 223, 255, 255, 128}
},
{ /* coeff band 4 */
{ 1, 81, 230, 252, 204, 203, 255, 192, 128, 128, 128},
{ 123, 102, 209, 247, 188, 196, 255, 233, 128, 128, 128},
{ 20, 95, 153, 243, 164, 173, 255, 203, 128, 128, 128}
},
{ /* coeff band 5 */
{ 1, 222, 248, 255, 216, 213, 128, 128, 128, 128, 128},
{ 168, 175, 246, 252, 235, 205, 255, 255, 128, 128, 128},
{ 47, 116, 215, 255, 211, 212, 255, 255, 128, 128, 128}
},
{ /* coeff band 6 */
{ 1, 121, 236, 253, 212, 214, 255, 255, 128, 128, 128},
{ 141, 84, 213, 252, 201, 202, 255, 219, 128, 128, 128},
{ 42, 80, 160, 240, 162, 185, 255, 205, 128, 128, 128}
},
{ /* coeff band 7 */
{ 1, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128},
{ 244, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128},
{ 238, 1, 255, 128, 128, 128, 128, 128, 128, 128, 128}
}
}
};
static const
unsigned char k_mv_entropy_update_probs[2][MV_PROB_CNT] =
{
{
237,
246,
253, 253, 254, 254, 254, 254, 254,
254, 254, 254, 254, 254, 250, 250, 252, 254, 254
},
{
231,
243,
245, 253, 254, 254, 254, 254, 254,
254, 254, 254, 254, 254, 251, 251, 254, 254, 254
}
};
static const
unsigned char k_default_mv_probs[2][MV_PROB_CNT] =
{
{ /* row */
162, /* is short */
128, /* sign */
225, 146, 172, 147, 214, 39, 156, /* short tree */
128, 129, 132, 75, 145, 178, 206, 239, 254, 254 /* long bits */
},
{
164,
128,
204, 170, 119, 235, 140, 230, 228,
128, 130, 130, 74, 148, 180, 203, 236, 254, 254
}
};

204
vp8/vp8_dixie_iface.c Normal file
View File

@@ -0,0 +1,204 @@
/*
* Copyright (c) 2010 The VP8 project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <stdlib.h>
#include <string.h>
#include "vpx/vpx_decoder.h"
#include "vpx/vp8dx.h"
#include "vpx/internal/vpx_codec_internal.h"
#include "vpx_mem/vpx_mem.h"
#include "vpx_version.h"
#include "dixie/dixie.h"
typedef vpx_codec_stream_info_t vp8_stream_info_t;
struct vpx_codec_alg_priv
{
vpx_codec_priv_t base;
vpx_codec_dec_cfg_t cfg;
vp8_stream_info_t si;
struct vp8_decoder_ctx decoder_ctx;
vpx_image_t *img;
int img_avail;
};
static vpx_codec_err_t
update_error_state(vpx_codec_alg_priv_t *ctx,
const struct vpx_internal_error_info *error)
{
vpx_codec_err_t res;
if ((res = error->error_code))
ctx->base.err_detail = error->has_detail
? error->detail
: NULL;
return res;
}
static vpx_codec_err_t vp8_init(vpx_codec_ctx_t *ctx)
{
vpx_codec_err_t res = VPX_CODEC_OK;
/* This function only allocates space for the vpx_codec_alg_priv_t
* structure. More memory may be required at the time the stream
* information becomes known.
*/
if (!ctx->priv)
{
void *priv = vpx_calloc(1, sizeof(vpx_codec_alg_priv_t));
ctx->priv = priv;
if (!ctx->priv)
return VPX_CODEC_MEM_ERROR;
ctx->priv->sz = sizeof(vpx_codec_alg_priv_t);
ctx->priv->iface = ctx->iface;
ctx->priv->alg_priv = priv;
ctx->priv->init_flags = ctx->init_flags;
if (ctx->config.dec)
{
/* Update the reference to the config structure to our copy. */
ctx->priv->alg_priv->cfg = *ctx->config.dec;
ctx->config.dec = &ctx->priv->alg_priv->cfg;
}
}
return res;
}
static vpx_codec_err_t vp8_destroy(vpx_codec_alg_priv_t *ctx)
{
vp8_dixie_decode_destroy(&ctx->decoder_ctx);
vpx_free(ctx->base.alg_priv);
return VPX_CODEC_OK;
}
static vpx_codec_err_t vp8_peek_si(const uint8_t *data,
unsigned int data_sz,
vpx_codec_stream_info_t *si)
{
struct vp8_frame_hdr hdr;
vpx_codec_err_t res = VPX_CODEC_OK;
if (!(res = vp8_parse_frame_header(data, data_sz, &hdr)))
{
si->is_kf = hdr.is_keyframe;
if (si->is_kf)
{
si->w = hdr.kf.w;
si->h = hdr.kf.h;
}
else
{
si->w = 0;
si->h = 0;
}
}
return res;
}
static vpx_codec_err_t vp8_get_si(vpx_codec_alg_priv_t *ctx,
vpx_codec_stream_info_t *si)
{
unsigned int sz;
if (si->sz >= sizeof(vp8_stream_info_t))
sz = sizeof(vp8_stream_info_t);
else
sz = sizeof(vpx_codec_stream_info_t);
memcpy(si, &ctx->si, sz);
si->sz = sz;
return VPX_CODEC_OK;
}
static vpx_codec_err_t vp8_decode(vpx_codec_alg_priv_t *ctx,
const uint8_t *data,
unsigned int data_sz,
void *user_priv,
long deadline)
{
vpx_codec_err_t res = VPX_CODEC_OK;
res = vp8_dixie_decode_frame(&ctx->decoder_ctx, data, data_sz);
if(res)
update_error_state(ctx, &ctx->decoder_ctx.error);
ctx->img_avail = ctx->decoder_ctx.frame_hdr.is_shown;
ctx->img = &ctx->decoder_ctx.ref_frames[CURRENT_FRAME]->img;
return res;
}
static vpx_image_t *vp8_get_frame(vpx_codec_alg_priv_t *ctx,
vpx_codec_iter_t *iter)
{
vpx_image_t *img = NULL;
if (ctx->img_avail)
{
/* iter acts as a flip flop, so an image is only returned on the first
* call to get_frame.
*/
if (!(*iter))
{
img = ctx->img;
*iter = img;
}
}
return img;
}
static vpx_codec_ctrl_fn_map_t ctf_maps[] =
{
{ -1, NULL},
};
#ifndef VERSION_STRING
#define VERSION_STRING
#endif
vpx_codec_iface_t vpx_codec_vp8_dixie_algo =
{
"VP8 \"Dixie\" Decoder" VERSION_STRING,
VPX_CODEC_INTERNAL_ABI_VERSION,
VPX_CODEC_CAP_DECODER,
/* vpx_codec_caps_t caps; */
vp8_init, /* vpx_codec_init_fn_t init; */
vp8_destroy, /* vpx_codec_destroy_fn_t destroy; */
ctf_maps, /* vpx_codec_ctrl_fn_map_t *ctrl_maps; */
NULL, /* vpx_codec_get_mmap_fn_t get_mmap; */
NULL, /* vpx_codec_set_mmap_fn_t set_mmap; */
{
vp8_peek_si, /* vpx_codec_peek_si_fn_t peek_si; */
vp8_get_si, /* vpx_codec_get_si_fn_t get_si; */
vp8_decode, /* vpx_codec_decode_fn_t decode; */
vp8_get_frame, /* vpx_codec_frame_get_fn_t frame_get; */
},
{NOT_IMPLEMENTED} /* encoder functions */
};

View File

@@ -23,6 +23,22 @@ ifeq ($(ARCH_ARM),yes)
endif
VP8_DX_SRCS-yes += vp8_dx_iface.c
VP8_DX_SRCS-$(CONFIG_DIXIE) += vp8_dixie_iface.c
VP8_DX_SRCS-$(CONFIG_DIXIE) += dixie/bit_ops.h
VP8_DX_SRCS-$(CONFIG_DIXIE) += dixie/dixie.h
VP8_DX_SRCS-$(CONFIG_DIXIE) += dixie/dixie.c
VP8_DX_SRCS-$(CONFIG_DIXIE) += dixie/bool_decoder.h
VP8_DX_SRCS-$(CONFIG_DIXIE) += dixie/modemv.c
VP8_DX_SRCS-$(CONFIG_DIXIE) += dixie/modemv.h
VP8_DX_SRCS-$(CONFIG_DIXIE) += dixie/modemv_data.h
VP8_DX_SRCS-$(CONFIG_DIXIE) += dixie/tokens.c
VP8_DX_SRCS-$(CONFIG_DIXIE) += dixie/tokens.h
VP8_DX_SRCS-$(CONFIG_DIXIE) += dixie/predict.c
VP8_DX_SRCS-$(CONFIG_DIXIE) += dixie/predict.h
VP8_DX_SRCS-$(CONFIG_DIXIE) += dixie/idct_add.c
VP8_DX_SRCS-$(CONFIG_DIXIE) += dixie/idct_add.h
VP8_DX_SRCS-$(CONFIG_DIXIE) += dixie/dixie_loopfilter.c
VP8_DX_SRCS-$(CONFIG_DIXIE) += dixie/dixie_loopfilter.h
CFLAGS+=-I$(SRC_PATH_BARE)/$(VP8_PREFIX)decoder