Commit 7ab9b308 authored by Andreas Rheinhardt's avatar Andreas Rheinhardt

avcodec/vp56: Move VP5-9 range coder functions to a header of their own

Also use a vpx prefix for them.
Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@outlook.com>
parent 80ad06ab
......@@ -737,11 +737,11 @@ OBJS-$(CONFIG_VORBIS_DECODER) += vorbisdec.o vorbisdsp.o vorbis.o \
OBJS-$(CONFIG_VORBIS_ENCODER) += vorbisenc.o vorbis.o \
vorbis_data.o
OBJS-$(CONFIG_VP3_DECODER) += vp3.o
OBJS-$(CONFIG_VP5_DECODER) += vp5.o vp56.o vp56data.o vp56rac.o
OBJS-$(CONFIG_VP5_DECODER) += vp5.o vp56.o vp56data.o vpx_rac.o
OBJS-$(CONFIG_VP6_DECODER) += vp6.o vp56.o vp56data.o \
vp6dsp.o vp56rac.o
OBJS-$(CONFIG_VP7_DECODER) += vp8.o vp56rac.o
OBJS-$(CONFIG_VP8_DECODER) += vp8.o vp56rac.o
vp6dsp.o vpx_rac.o
OBJS-$(CONFIG_VP7_DECODER) += vp8.o vpx_rac.o
OBJS-$(CONFIG_VP8_DECODER) += vp8.o vpx_rac.o
OBJS-$(CONFIG_VP8_CUVID_DECODER) += cuviddec.o
OBJS-$(CONFIG_VP8_MEDIACODEC_DECODER) += mediacodecdec.o
OBJS-$(CONFIG_VP8_QSV_DECODER) += qsvdec.o
......@@ -750,7 +750,7 @@ OBJS-$(CONFIG_VP8_VAAPI_ENCODER) += vaapi_encode_vp8.o
OBJS-$(CONFIG_VP8_V4L2M2M_DECODER) += v4l2_m2m_dec.o
OBJS-$(CONFIG_VP8_V4L2M2M_ENCODER) += v4l2_m2m_enc.o
OBJS-$(CONFIG_VP9_DECODER) += vp9.o vp9data.o vp9dsp.o vp9lpf.o vp9recon.o \
vp9block.o vp9prob.o vp9mvs.o vp56rac.o \
vp9block.o vp9prob.o vp9mvs.o vpx_rac.o \
vp9dsp_8bpp.o vp9dsp_10bpp.o vp9dsp_12bpp.o
OBJS-$(CONFIG_VP9_CUVID_DECODER) += cuviddec.o
OBJS-$(CONFIG_VP9_MEDIACODEC_DECODER) += mediacodecdec.o
......@@ -1234,7 +1234,7 @@ SKIPHEADERS += %_tablegen.h \
aaccoder_trellis.h \
aacenc_quantization.h \
aacenc_quantization_misc.h \
$(ARCH)/vp56_arith.h \
$(ARCH)/vpx_arith.h \
SKIPHEADERS-$(CONFIG_AMF) += amfenc.h
SKIPHEADERS-$(CONFIG_D3D11VA) += d3d11va.h dxva2_internal.h
......
......@@ -22,12 +22,12 @@
#include <stdint.h>
#include "config.h"
#include "libavcodec/vp56.h"
#include "libavcodec/vpx_rac.h"
#include "libavcodec/vp8.h"
#if HAVE_ARMV6_EXTERNAL
#define vp8_decode_block_coeffs_internal ff_decode_block_coeffs_armv6
int ff_decode_block_coeffs_armv6(VP56RangeCoder *rc, int16_t block[16],
int ff_decode_block_coeffs_armv6(VPXRangeCoder *rc, int16_t block[16],
uint8_t probs[8][3][NUM_DCT_TOKENS-1],
int i, uint8_t *token_prob, int16_t qmul[2]);
#endif
......
......@@ -65,7 +65,7 @@ T orrcs \cw, \cw, \t1
function ff_decode_block_coeffs_armv6, export=1
push {r0,r1,r4-r11,lr}
movrelx lr, X(ff_vp56_norm_shift)
movrelx lr, X(ff_vpx_norm_shift)
ldrd r4, r5, [sp, #44] @ token_prob, qmul
cmp r3, #0
ldr r11, [r5]
......
......@@ -18,8 +18,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_ARM_VP56_ARITH_H
#define AVCODEC_ARM_VP56_ARITH_H
#ifndef AVCODEC_ARM_VPX_ARITH_H
#define AVCODEC_ARM_VPX_ARITH_H
#if CONFIG_THUMB
# define A(x)
......@@ -39,10 +39,10 @@
#if HAVE_ARMV6_INLINE
#define vp56_rac_get_prob vp56_rac_get_prob_armv6
static inline int vp56_rac_get_prob_armv6(VP56RangeCoder *c, int pr)
#define vpx_rac_get_prob vp56_rac_get_prob_armv6
static inline int vp56_rac_get_prob_armv6(VPXRangeCoder *c, int pr)
{
unsigned shift = ff_vp56_norm_shift[c->high];
unsigned shift = ff_vpx_norm_shift[c->high];
unsigned code_word = c->code_word << shift;
unsigned high = c->high << shift;
unsigned bit;
......@@ -76,10 +76,10 @@ static inline int vp56_rac_get_prob_armv6(VP56RangeCoder *c, int pr)
return bit;
}
#define vp56_rac_get_prob_branchy vp56_rac_get_prob_branchy_armv6
static inline int vp56_rac_get_prob_branchy_armv6(VP56RangeCoder *c, int pr)
#define vpx_rac_get_prob_branchy vp56_rac_get_prob_branchy_armv6
static inline int vp56_rac_get_prob_branchy_armv6(VPXRangeCoder *c, int pr)
{
unsigned shift = ff_vp56_norm_shift[c->high];
unsigned shift = ff_vpx_norm_shift[c->high];
unsigned code_word = c->code_word << shift;
unsigned high = c->high << shift;
unsigned low;
......@@ -118,4 +118,4 @@ static inline int vp56_rac_get_prob_branchy_armv6(VP56RangeCoder *c, int pr)
#endif
#endif /* AVCODEC_ARM_VP56_ARITH_H */
#endif /* AVCODEC_ARM_VPX_ARITH_H */
......@@ -33,19 +33,20 @@
#include "vp56.h"
#include "vp56data.h"
#include "vp5data.h"
#include "vpx_rac.h"
static int vp5_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
{
VP56RangeCoder *c = &s->c;
VPXRangeCoder *c = &s->c;
int rows, cols;
int ret;
ret = ff_vp56_init_range_decoder(&s->c, buf, buf_size);
ret = ff_vpx_init_range_decoder(&s->c, buf, buf_size);
if (ret < 0)
return ret;
s->frames[VP56_FRAME_CURRENT]->key_frame = !vp56_rac_get(c);
vp56_rac_get(c);
s->frames[VP56_FRAME_CURRENT]->key_frame = !vpx_rac_get(c);
vpx_rac_get(c);
ff_vp56_init_dequant(s, vp56_rac_gets(c, 6));
if (s->frames[VP56_FRAME_CURRENT]->key_frame)
{
......@@ -55,7 +56,7 @@ static int vp5_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
if(vp56_rac_gets(c, 5) > 5)
return AVERROR_INVALIDDATA;
vp56_rac_gets(c, 2);
if (vp56_rac_get(c)) {
if (vpx_rac_get(c)) {
avpriv_report_missing_feature(s->avctx, "Interlacing");
return AVERROR_PATCHWELCOME;
}
......@@ -87,16 +88,16 @@ static int vp5_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
static void vp5_parse_vector_adjustment(VP56Context *s, VP56mv *vect)
{
VP56RangeCoder *c = &s->c;
VPXRangeCoder *c = &s->c;
VP56Model *model = s->modelp;
int comp, di;
for (comp=0; comp<2; comp++) {
int delta = 0;
if (vp56_rac_get_prob_branchy(c, model->vector_dct[comp])) {
int sign = vp56_rac_get_prob(c, model->vector_sig[comp]);
di = vp56_rac_get_prob(c, model->vector_pdi[comp][0]);
di |= vp56_rac_get_prob(c, model->vector_pdi[comp][1]) << 1;
if (vpx_rac_get_prob_branchy(c, model->vector_dct[comp])) {
int sign = vpx_rac_get_prob(c, model->vector_sig[comp]);
di = vpx_rac_get_prob(c, model->vector_pdi[comp][0]);
di |= vpx_rac_get_prob(c, model->vector_pdi[comp][1]) << 1;
delta = vp56_rac_get_tree(c, ff_vp56_pva_tree,
model->vector_pdv[comp]);
delta = di | (delta << 2);
......@@ -111,30 +112,30 @@ static void vp5_parse_vector_adjustment(VP56Context *s, VP56mv *vect)
static void vp5_parse_vector_models(VP56Context *s)
{
VP56RangeCoder *c = &s->c;
VPXRangeCoder *c = &s->c;
VP56Model *model = s->modelp;
int comp, node;
for (comp=0; comp<2; comp++) {
if (vp56_rac_get_prob_branchy(c, vp5_vmc_pct[comp][0]))
if (vpx_rac_get_prob_branchy(c, vp5_vmc_pct[comp][0]))
model->vector_dct[comp] = vp56_rac_gets_nn(c, 7);
if (vp56_rac_get_prob_branchy(c, vp5_vmc_pct[comp][1]))
if (vpx_rac_get_prob_branchy(c, vp5_vmc_pct[comp][1]))
model->vector_sig[comp] = vp56_rac_gets_nn(c, 7);
if (vp56_rac_get_prob_branchy(c, vp5_vmc_pct[comp][2]))
if (vpx_rac_get_prob_branchy(c, vp5_vmc_pct[comp][2]))
model->vector_pdi[comp][0] = vp56_rac_gets_nn(c, 7);
if (vp56_rac_get_prob_branchy(c, vp5_vmc_pct[comp][3]))
if (vpx_rac_get_prob_branchy(c, vp5_vmc_pct[comp][3]))
model->vector_pdi[comp][1] = vp56_rac_gets_nn(c, 7);
}
for (comp=0; comp<2; comp++)
for (node=0; node<7; node++)
if (vp56_rac_get_prob_branchy(c, vp5_vmc_pct[comp][4 + node]))
if (vpx_rac_get_prob_branchy(c, vp5_vmc_pct[comp][4 + node]))
model->vector_pdv[comp][node] = vp56_rac_gets_nn(c, 7);
}
static int vp5_parse_coeff_models(VP56Context *s)
{
VP56RangeCoder *c = &s->c;
VPXRangeCoder *c = &s->c;
VP56Model *model = s->modelp;
uint8_t def_prob[11];
int node, cg, ctx;
......@@ -145,7 +146,7 @@ static int vp5_parse_coeff_models(VP56Context *s)
for (pt=0; pt<2; pt++)
for (node=0; node<11; node++)
if (vp56_rac_get_prob_branchy(c, vp5_dccv_pct[pt][node])) {
if (vpx_rac_get_prob_branchy(c, vp5_dccv_pct[pt][node])) {
def_prob[node] = vp56_rac_gets_nn(c, 7);
model->coeff_dccv[pt][node] = def_prob[node];
} else if (s->frames[VP56_FRAME_CURRENT]->key_frame) {
......@@ -156,7 +157,7 @@ static int vp5_parse_coeff_models(VP56Context *s)
for (pt=0; pt<2; pt++)
for (cg=0; cg<6; cg++)
for (node=0; node<11; node++)
if (vp56_rac_get_prob_branchy(c, vp5_ract_pct[ct][pt][cg][node])) {
if (vpx_rac_get_prob_branchy(c, vp5_ract_pct[ct][pt][cg][node])) {
def_prob[node] = vp56_rac_gets_nn(c, 7);
model->coeff_ract[pt][ct][cg][node] = def_prob[node];
} else if (s->frames[VP56_FRAME_CURRENT]->key_frame) {
......@@ -181,7 +182,7 @@ static int vp5_parse_coeff_models(VP56Context *s)
static int vp5_parse_coeff(VP56Context *s)
{
VP56RangeCoder *c = &s->c;
VPXRangeCoder *c = &s->c;
VP56Model *model = s->modelp;
uint8_t *permute = s->idct_scantable;
uint8_t *model1, *model2;
......@@ -189,7 +190,7 @@ static int vp5_parse_coeff(VP56Context *s)
int b, i, cg, idx, ctx, ctx_last;
int pt = 0; /* plane type (0 for Y, 1 for U or V) */
if (vpX_rac_is_end(c)) {
if (vpx_rac_is_end(c)) {
av_log(s->avctx, AV_LOG_ERROR, "End of AC stream reached in vp5_parse_coeff\n");
return AVERROR_INVALIDDATA;
}
......@@ -206,30 +207,30 @@ static int vp5_parse_coeff(VP56Context *s)
coeff_idx = 0;
for (;;) {
if (vp56_rac_get_prob_branchy(c, model2[0])) {
if (vp56_rac_get_prob_branchy(c, model2[2])) {
if (vp56_rac_get_prob_branchy(c, model2[3])) {
if (vpx_rac_get_prob_branchy(c, model2[0])) {
if (vpx_rac_get_prob_branchy(c, model2[2])) {
if (vpx_rac_get_prob_branchy(c, model2[3])) {
s->coeff_ctx[ff_vp56_b6to4[b]][coeff_idx] = 4;
idx = vp56_rac_get_tree(c, ff_vp56_pc_tree, model1);
sign = vp56_rac_get(c);
sign = vpx_rac_get(c);
coeff = ff_vp56_coeff_bias[idx+5];
for (i=ff_vp56_coeff_bit_length[idx]; i>=0; i--)
coeff += vp56_rac_get_prob(c, ff_vp56_coeff_parse_table[idx][i]) << i;
coeff += vpx_rac_get_prob(c, ff_vp56_coeff_parse_table[idx][i]) << i;
} else {
if (vp56_rac_get_prob_branchy(c, model2[4])) {
coeff = 3 + vp56_rac_get_prob(c, model1[5]);
if (vpx_rac_get_prob_branchy(c, model2[4])) {
coeff = 3 + vpx_rac_get_prob(c, model1[5]);
s->coeff_ctx[ff_vp56_b6to4[b]][coeff_idx] = 3;
} else {
coeff = 2;
s->coeff_ctx[ff_vp56_b6to4[b]][coeff_idx] = 2;
}
sign = vp56_rac_get(c);
sign = vpx_rac_get(c);
}
ct = 2;
} else {
ct = 1;
s->coeff_ctx[ff_vp56_b6to4[b]][coeff_idx] = 1;
sign = vp56_rac_get(c);
sign = vpx_rac_get(c);
coeff = 1;
}
coeff = (coeff ^ -sign) + sign;
......@@ -237,7 +238,7 @@ static int vp5_parse_coeff(VP56Context *s)
coeff *= s->dequant_ac;
s->block_coeff[b][permute[coeff_idx]] = coeff;
} else {
if (ct && !vp56_rac_get_prob_branchy(c, model2[1]))
if (ct && !vpx_rac_get_prob_branchy(c, model2[1]))
break;
ct = 0;
s->coeff_ctx[ff_vp56_b6to4[b]][coeff_idx] = 0;
......
......@@ -29,6 +29,7 @@
#include "h264chroma.h"
#include "vp56.h"
#include "vp56data.h"
#include "vpx_rac.h"
void ff_vp56_init_dequant(VP56Context *s, int quantizer)
......@@ -80,22 +81,22 @@ static int vp56_get_vectors_predictors(VP56Context *s, int row, int col,
static void vp56_parse_mb_type_models(VP56Context *s)
{
VP56RangeCoder *c = &s->c;
VPXRangeCoder *c = &s->c;
VP56Model *model = s->modelp;
int i, ctx, type;
for (ctx=0; ctx<3; ctx++) {
if (vp56_rac_get_prob_branchy(c, 174)) {
if (vpx_rac_get_prob_branchy(c, 174)) {
int idx = vp56_rac_gets(c, 4);
memcpy(model->mb_types_stats[ctx],
ff_vp56_pre_def_mb_type_stats[idx][ctx],
sizeof(model->mb_types_stats[ctx]));
}
if (vp56_rac_get_prob_branchy(c, 254)) {
if (vpx_rac_get_prob_branchy(c, 254)) {
for (type=0; type<10; type++) {
for(i=0; i<2; i++) {
if (vp56_rac_get_prob_branchy(c, 205)) {
int delta, sign = vp56_rac_get(c);
if (vpx_rac_get_prob_branchy(c, 205)) {
int delta, sign = vpx_rac_get(c);
delta = vp56_rac_get_tree(c, ff_vp56_pmbtm_tree,
ff_vp56_mb_type_model_model);
......@@ -153,9 +154,9 @@ static VP56mb vp56_parse_mb_type(VP56Context *s,
VP56mb prev_type, int ctx)
{
uint8_t *mb_type_model = s->modelp->mb_type[ctx][prev_type];
VP56RangeCoder *c = &s->c;
VPXRangeCoder *c = &s->c;
if (vp56_rac_get_prob_branchy(c, mb_type_model[0]))
if (vpx_rac_get_prob_branchy(c, mb_type_model[0]))
return prev_type;
else
return vp56_rac_get_tree(c, ff_vp56_pmbt_tree, mb_type_model);
......
......@@ -31,11 +31,11 @@
#include "avcodec.h"
#include "get_bits.h"
#include "hpeldsp.h"
#include "bytestream.h"
#include "h264chroma.h"
#include "videodsp.h"
#include "vp3dsp.h"
#include "vp56dsp.h"
#include "vpx_rac.h"
typedef struct vp56_context VP56Context;
......@@ -84,16 +84,6 @@ typedef int (*VP56ParseCoeffModels)(VP56Context *s);
typedef int (*VP56ParseHeader)(VP56Context *s, const uint8_t *buf,
int buf_size);
typedef struct VP56RangeCoder {
int high;
int bits; /* stored negated (i.e. negative "bits" is a positive number of
bits left) in order to eliminate a negate in cache refilling */
const uint8_t *buffer;
const uint8_t *end;
unsigned int code_word;
int end_reached;
} VP56RangeCoder;
typedef struct VP56RefDc {
uint8_t not_null_dc;
VP56Frame ref_frame;
......@@ -134,9 +124,9 @@ struct vp56_context {
AVFrame *frames[4];
uint8_t *edge_emu_buffer_alloc;
uint8_t *edge_emu_buffer;
VP56RangeCoder c;
VP56RangeCoder cc;
VP56RangeCoder *ccp;
VPXRangeCoder c;
VPXRangeCoder cc;
VPXRangeCoder *ccp;
int sub_version;
/* frame info */
......@@ -232,121 +222,31 @@ int ff_vp56_decode_frame(AVCodecContext *avctx, AVFrame *frame,
* vp56 specific range coder implementation
*/
extern const uint8_t ff_vp56_norm_shift[256];
int ff_vp56_init_range_decoder(VP56RangeCoder *c, const uint8_t *buf, int buf_size);
/**
* vp5689 returns 1 if the end of the stream has been reached, 0 otherwise.
*/
static av_always_inline int vpX_rac_is_end(VP56RangeCoder *c)
{
if (c->end <= c->buffer && c->bits >= 0)
c->end_reached ++;
return c->end_reached > 10;
}
static av_always_inline unsigned int vp56_rac_renorm(VP56RangeCoder *c)
{
int shift = ff_vp56_norm_shift[c->high];
int bits = c->bits;
unsigned int code_word = c->code_word;
c->high <<= shift;
code_word <<= shift;
bits += shift;
if(bits >= 0 && c->buffer < c->end) {
code_word |= bytestream_get_be16(&c->buffer) << bits;
bits -= 16;
}
c->bits = bits;
return code_word;
}
#if ARCH_ARM
#include "arm/vp56_arith.h"
#elif ARCH_X86
#include "x86/vp56_arith.h"
#endif
#ifndef vp56_rac_get_prob
#define vp56_rac_get_prob vp56_rac_get_prob
static av_always_inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob)
{
unsigned int code_word = vp56_rac_renorm(c);
unsigned int low = 1 + (((c->high - 1) * prob) >> 8);
unsigned int low_shift = low << 16;
int bit = code_word >= low_shift;
c->high = bit ? c->high - low : low;
c->code_word = bit ? code_word - low_shift : code_word;
return bit;
}
#endif
#ifndef vp56_rac_get_prob_branchy
// branchy variant, to be used where there's a branch based on the bit decoded
static av_always_inline int vp56_rac_get_prob_branchy(VP56RangeCoder *c, int prob)
{
unsigned long code_word = vp56_rac_renorm(c);
unsigned low = 1 + (((c->high - 1) * prob) >> 8);
unsigned low_shift = low << 16;
if (code_word >= low_shift) {
c->high -= low;
c->code_word = code_word - low_shift;
return 1;
}
c->high = low;
c->code_word = code_word;
return 0;
}
#endif
static av_always_inline int vp56_rac_get(VP56RangeCoder *c)
{
unsigned int code_word = vp56_rac_renorm(c);
/* equiprobable */
int low = (c->high + 1) >> 1;
unsigned int low_shift = low << 16;
int bit = code_word >= low_shift;
if (bit) {
c->high -= low;
code_word -= low_shift;
} else {
c->high = low;
}
c->code_word = code_word;
return bit;
}
static int vp56_rac_gets(VP56RangeCoder *c, int bits)
static int vp56_rac_gets(VPXRangeCoder *c, int bits)
{
int value = 0;
while (bits--) {
value = (value << 1) | vp56_rac_get(c);
value = (value << 1) | vpx_rac_get(c);
}
return value;
}
// P(7)
static av_unused int vp56_rac_gets_nn(VP56RangeCoder *c, int bits)
static av_unused int vp56_rac_gets_nn(VPXRangeCoder *c, int bits)
{
int v = vp56_rac_gets(c, 7) << 1;
return v + !v;
}
static av_always_inline
int vp56_rac_get_tree(VP56RangeCoder *c,
int vp56_rac_get_tree(VPXRangeCoder *c,
const VP56Tree *tree,
const uint8_t *probs)
{
while (tree->val > 0) {
if (vp56_rac_get_prob_branchy(c, probs[tree->prob_idx]))
if (vpx_rac_get_prob_branchy(c, probs[tree->prob_idx]))
tree += tree->val;
else
tree++;
......
This diff is collapsed.
This diff is collapsed.
......@@ -36,6 +36,7 @@
#include "threadframe.h"
#include "vp56.h"
#include "vp8dsp.h"
#include "vpx_rac.h"
#define VP8_MAX_QUANT 127
......@@ -245,7 +246,7 @@ typedef struct VP8Context {
uint8_t (*top_border)[16 + 8 + 8];
uint8_t (*top_nnz)[9];
VP56RangeCoder c; ///< header context, includes mb modes and motion vectors
VPXRangeCoder c; ///< header context, includes mb modes and motion vectors
/* This contains the entropy coder state at the end of the header
* block, in the form specified by the standard. For use by
......@@ -297,7 +298,7 @@ typedef struct VP8Context {
* There can be 1, 2, 4, or 8 of these after the header context.
*/
int num_coeff_partitions;
VP56RangeCoder coeff_partition[8];
VPXRangeCoder coeff_partition[8];
int coeff_partition_size[8];
VideoDSPContext vdsp;
VP8DSPContext vp8dsp;
......
......@@ -30,15 +30,15 @@
#include "libavutil/attributes.h"
#include "vp56.h"
#include "vpx_rac.h"
// rounding is different than vp56_rac_get, is vp56_rac_get wrong?
static av_always_inline int vp89_rac_get(VP56RangeCoder *c)
// rounding is different than vpx_rac_get, is vpx_rac_get wrong?
static av_always_inline int vp89_rac_get(VPXRangeCoder *c)
{
return vp56_rac_get_prob(c, 128);
return vpx_rac_get_prob(c, 128);
}
static av_unused int vp89_rac_get_uint(VP56RangeCoder *c, int bits)
static av_unused int vp89_rac_get_uint(VPXRangeCoder *c, int bits)
{
int value = 0;
......@@ -51,13 +51,13 @@ static av_unused int vp89_rac_get_uint(VP56RangeCoder *c, int bits)
// how probabilities are associated with decisions is different I think
// well, the new scheme fits in the old but this way has one fewer branches per decision
static av_always_inline int vp89_rac_get_tree(VP56RangeCoder *c, const int8_t (*tree)[2],
static av_always_inline int vp89_rac_get_tree(VPXRangeCoder *c, const int8_t (*tree)[2],
const uint8_t *probs)
{
int i = 0;
do {
i = tree[i][vp56_rac_get_prob(c, probs[i])];
i = tree[i][vpx_rac_get_prob(c, probs[i])];
} while (i > 0);
return -i;
......
This diff is collapsed.
This diff is collapsed.
......@@ -36,6 +36,7 @@
#include "vp9.h"
#include "vp9dsp.h"
#include "vp9shared.h"
#include "vpx_rac.h"
#define REF_INVALID_SCALE 0xFFFF
......@@ -98,7 +99,7 @@ typedef struct VP9Context {
VP9DSPContext dsp;
VideoDSPContext vdsp;
GetBitContext gb;
VP56RangeCoder c;
VPXRangeCoder c;
int pass, active_tile_cols;
#if HAVE_THREADS
......@@ -166,8 +167,8 @@ struct VP9TileData {
//VP9Context should be const, but because of the threading API(generates
//a lot of warnings) it's not.
VP9Context *s;
VP56RangeCoder *c_b;
VP56RangeCoder *c;
VPXRangeCoder *c_b;
VPXRangeCoder *c;
int row, row7, col, col7;
uint8_t *dst[3];
ptrdiff_t y_stride, uv_stride;
......
......@@ -24,9 +24,9 @@
#include "threadframe.h"
#include "vp56.h"
#include "vp89_rac.h"
#include "vp9.h"
#include "vp9data.h"
#include "vp9dec.h"
#include "vpx_rac.h"
static av_always_inline void clamp_mv(VP56mv *dst, const VP56mv *src,
VP9TileData *td)
......@@ -237,7 +237,7 @@ static void find_ref_mvs(VP9TileData *td,
static av_always_inline int read_mv_component(VP9TileData *td, int idx, int hp)
{
VP9Context *s = td->s;
int bit, sign = vp56_rac_get_prob(td->c, s->prob.p.mv_comp[idx].sign);
int bit, sign = vpx_rac_get_prob(td->c, s->prob.p.mv_comp[idx].sign);
int n, c = vp89_rac_get_tree(td->c, ff_vp9_mv_class_tree,
s->prob.p.mv_comp[idx].classes);
......@@ -247,7 +247,7 @@ static av_always_inline int read_mv_component(VP9TileData *td, int idx, int hp)
int m;
for (n = 0, m = 0; m < c; m++) {
bit = vp56_rac_get_prob(td->c, s->prob.p.mv_comp[idx].bits[m]);
bit = vpx_rac_get_prob(td->c, s->prob.p.mv_comp[idx].bits[m]);
n |= bit << m;
td->counts.mv_comp[idx].bits[m][bit]++;
}
......@@ -257,7 +257,7 @@ static av_always_inline int read_mv_component(VP9TileData *td, int idx, int hp)
n |= bit << 1;
td->counts.mv_comp[idx].fp[bit]++;
if (hp) {
bit = vp56_rac_get_prob(td->c, s->prob.p.mv_comp[idx].hp);
bit = vpx_rac_get_prob(td->c, s->prob.p.mv_comp[idx].hp);
td->counts.mv_comp[idx].hp[bit]++;
n |= bit;
} else {
......@@ -268,14 +268,14 @@ static av_always_inline int read_mv_component(VP9TileData *td, int idx, int hp)
}
n += 8 << c;
} else {
n = vp56_rac_get_prob(td->c, s->prob.p.mv_comp[idx].class0);
n = vpx_rac_get_prob(td->c, s->prob.p.mv_comp[idx].class0);
td->counts.mv_comp[idx].class0[n]++;
bit = vp89_rac_get_tree(td->c, ff_vp9_mv_fp_tree,
s->prob.p.mv_comp[idx].class0_fp[n]);
td->counts.mv_comp[idx].class0_fp[n][bit]++;
n = (n << 3) | (bit << 1);
if (hp) {
bit = vp56_rac_get_prob(td->c, s->prob.p.mv_comp[idx].class0_hp);
bit = vpx_rac_get_prob(td->c, s->prob.p.mv_comp[idx].class0_hp);
td->counts.mv_comp[idx].class0_hp[bit]++;
n |= bit;
} else {
......
......@@ -22,9 +22,9 @@
#include <stdint.h>
#include "libavutil/error.h"
#include "bytestream.h"
#include "vp56.h"
#include "vpx_rac.h"
const uint8_t ff_vp56_norm_shift[256]= {
const uint8_t ff_vpx_norm_shift[256]= {
8,7,6,6,5,5,5,5,4,4,4,4,4,4,4,4,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
......@@ -39,7 +39,7 @@ const uint8_t ff_vp56_norm_shift[256]= {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
};
int ff_vp56_init_range_decoder(VP56RangeCoder *c, const uint8_t *buf, int buf_size)
int ff_vpx_init_range_decoder(VPXRangeCoder *c, const uint8_t *buf, int buf_size)
{
c->high = 255;
c->bits = -16;
......
/*
* Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Common VP5-VP9 range decoder stuff
*/
#ifndef AVCODEC_VPX_RAC_H
#define AVCODEC_VPX_RAC_H
#include <stdint.h>
#include "config.h"
#include "libavutil/attributes.h"
#include "bytestream.h"
typedef struct VPXRangeCoder {
int high;
int bits; /* stored negated (i.e. negative "bits" is a positive number of
bits left) in order to eliminate a negate in cache refilling */
const uint8_t *buffer;
const uint8_t *end;
unsigned int code_word;
int end_reached;
} VPXRangeCoder;
extern const uint8_t ff_vpx_norm_shift[256];
int ff_vpx_init_range_decoder(VPXRangeCoder *c, const uint8_t *buf, int buf_size);
/**
* returns 1 if the end of the stream has been reached, 0 otherwise.
*/
static av_always_inline int vpx_rac_is_end(VPXRangeCoder *c)
{
if (c->end <= c->buffer && c->bits >= 0)
c->end_reached ++;
return c->end_reached > 10;
}
static av_always_inline unsigned int vpx_rac_renorm(VPXRangeCoder *c)
{
int shift = ff_vpx_norm_shift[c->high];
int bits = c->bits;
unsigned int code_word = c->code_word;
c->high <<= shift;
code_word <<= shift;
bits += shift;
if(bits >= 0 && c->buffer < c->end) {
code_word |= bytestream_get_be16(&c->buffer) << bits;
bits -= 16;
}
c->bits = bits;
return code_word;
}
#if ARCH_ARM
#include "arm/vpx_arith.h"
#elif ARCH_X86
#include "x86/vpx_arith.h"
#endif
#ifndef vpx_rac_get_prob
#define vpx_rac_get_prob vpx_rac_get_prob
static av_always_inline int vpx_rac_get_prob(VPXRangeCoder *c, uint8_t prob)
{
unsigned int code_word = vpx_rac_renorm(c);
unsigned int low = 1 + (((c->high - 1) * prob) >> 8);
unsigned int low_shift = low << 16;
int bit = code_word >= low_shift;
c->high = bit ? c->high - low : low;
c->code_word = bit ? code_word - low_shift : code_word;
return bit;
}
#endif
#ifndef vpx_rac_get_prob_branchy
// branchy variant, to be used where there's a branch based on the bit decoded
static av_always_inline int vpx_rac_get_prob_branchy(VPXRangeCoder *c, int prob)
{
unsigned long code_word = vpx_rac_renorm(c);
unsigned low = 1 + (((c->high - 1) * prob) >> 8);
unsigned low_shift = low << 16;
if (code_word >= low_shift) {
c->high -= low;
c->code_word = code_word - low_shift;
return 1;
}
c->high = low;
c->code_word = code_word;
return 0;
}
#endif
static av_always_inline int vpx_rac_get(VPXRangeCoder *c)
{
unsigned int code_word = vpx_rac_renorm(c);
/* equiprobable */
int low = (c->high + 1) >> 1;
unsigned int low_shift = low << 16;
int bit = code_word >= low_shift;
if (bit) {
c->high -= low;
code_word -= low_shift;
} else {
c->high = low;
}
c->code_word = code_word;
return bit;
}
#endif /* AVCODEC_VPX_RAC_H */
......@@ -21,16 +21,18 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef AVCODEC_X86_VP56_ARITH_H
#define AVCODEC_X86_VP56_ARITH_H
#ifndef AVCODEC_X86_VPX_ARITH_H
#define AVCODEC_X86_VPX_ARITH_H
#include "libavutil/x86/asm.h"
#if HAVE_INLINE_ASM && HAVE_FAST_CMOV && HAVE_6REGS
#include "libavutil/attributes.h"
#define vp56_rac_get_prob vp56_rac_get_prob
static av_always_inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob)
#define vpx_rac_get_prob vpx_rac_get_prob
static av_always_inline int vpx_rac_get_prob(VPXRangeCoder *c, uint8_t prob)
{
unsigned int code_word = vp56_rac_renorm(c);
unsigned int code_word = vpx_rac_renorm(c);
unsigned int low = 1 + (((c->high - 1) * prob) >> 8);
unsigned int low_shift = low << 16;
int bit = 0;
......@@ -50,4 +52,4 @@ static av_always_inline int vp56_rac_get_prob(VP56RangeCoder *c, uint8_t prob)
}
#endif
#endif /* AVCODEC_X86_VP56_ARITH_H */
#endif /* AVCODEC_X86_VPX_ARITH_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment