#ifndef AVCODEC_VP8_H
#define AVCODEC_VP8_H
#include <stdatomic.h>
#include "libavutil/buffer.h"
#include "libavutil/thread.h"
#include "h264pred.h"
#include "thread.h"
#include "vp56.h"
#include "vp8dsp.h"
#define VP8_MAX_QUANT 127
enum dct_token {
DCT_0,
DCT_1,
DCT_2,
DCT_3,
DCT_4,
DCT_CAT1,
DCT_CAT2,
DCT_CAT3,
DCT_CAT4,
DCT_CAT5,
DCT_CAT6,
DCT_EOB,
NUM_DCT_TOKENS
};
#define MODE_I4x4 4
enum inter_mvmode {
VP8_MVMODE_ZERO = MODE_I4x4 + 1,
VP8_MVMODE_MV,
VP8_MVMODE_SPLIT
};
enum inter_splitmvmode {
VP8_SPLITMVMODE_16x8 = 0,
VP8_SPLITMVMODE_8x16,
VP8_SPLITMVMODE_8x8,
VP8_SPLITMVMODE_4x4,
VP8_SPLITMVMODE_NONE,
};
typedef struct VP8FilterStrength {
uint8_t filter_level;
uint8_t inner_limit;
uint8_t inner_filter;
} VP8FilterStrength;
typedef struct VP8Macroblock {
uint8_t skip;
uint8_t mode;
uint8_t ref_frame;
uint8_t partitioning;
uint8_t chroma_pred_mode;
uint8_t segment;
uint8_t intra4x4_pred_mode_mb[16];
DECLARE_ALIGNED(4, uint8_t, intra4x4_pred_mode_top)[4];
VP56mv mv;
VP56mv bmv[16];
} VP8Macroblock;
typedef struct VP8intmv {
int x;
int y;
} VP8intmv;
typedef struct VP8mvbounds {
VP8intmv mv_min;
VP8intmv mv_max;
} VP8mvbounds;
typedef struct VP8ThreadData {
DECLARE_ALIGNED(16, int16_t, block)[6][4][16];
DECLARE_ALIGNED(16, int16_t, block_dc)[16];
DECLARE_ALIGNED(16, uint8_t, non_zero_count_cache)[6][4];
DECLARE_ALIGNED(8, uint8_t, left_nnz)[9];
int thread_nr;
#if HAVE_THREADS
pthread_mutex_t lock;
pthread_cond_t cond;
#endif
atomic_int thread_mb_pos;
atomic_int wait_mb_pos;
#define EDGE_EMU_LINESIZE 32
DECLARE_ALIGNED(16, uint8_t, edge_emu_buffer)[21 * EDGE_EMU_LINESIZE];
VP8FilterStrength *filter_strength;
VP8mvbounds mv_bounds;
} VP8ThreadData;
typedef struct VP8Frame {
ThreadFrame tf;
AVBufferRef *seg_map;
AVBufferRef *hwaccel_priv_buf;
void *hwaccel_picture_private;
} VP8Frame;
#define MAX_THREADS 8
typedef struct VP8Context {
VP8ThreadData *thread_data;
AVCodecContext *avctx;
enum AVPixelFormat pix_fmt;
int actually_webp;
VP8Frame *framep[4];
VP8Frame *next_framep[4];
VP8Frame *curframe;
VP8Frame *prev_frame;
uint16_t mb_width;
uint16_t mb_height;
ptrdiff_t linesize;
ptrdiff_t uvlinesize;
uint8_t keyframe;
uint8_t deblock_filter;
uint8_t mbskip_enabled;
uint8_t profile;
VP8mvbounds mv_bounds;
int8_t sign_bias[4];
int ref_count[3];
struct {
uint8_t enabled;
uint8_t absolute_vals;
uint8_t update_map;
uint8_t update_feature_data;
int8_t base_quant[4];
int8_t filter_level[4];
} segmentation;
struct {
uint8_t simple;
uint8_t level;
uint8_t sharpness;
} filter;
VP8Macroblock *macroblocks;
uint8_t *intra4x4_pred_mode_top;
uint8_t intra4x4_pred_mode_left[4];
struct {
int16_t luma_qmul[2];
int16_t luma_dc_qmul[2];
int16_t chroma_qmul[2];
} qmat[4];
struct {
int yac_qi;
int ydc_delta;
int y2dc_delta;
int y2ac_delta;
int uvdc_delta;
int uvac_delta;
} quant;
struct {
uint8_t enabled;
uint8_t update;
int8_t mode[VP8_MVMODE_SPLIT + 1];
int8_t ref[4];
} lf_delta;
uint8_t (*top_border)[16 + 8 + 8];
uint8_t (*top_nnz)[9];
VP56RangeCoder c;
struct {
const uint8_t *input;
uint32_t range;
uint32_t value;
int bit_count;
} coder_state_at_header_end;
int header_partition_size;
struct {
uint8_t segmentid[3];
uint8_t mbskip;
uint8_t intra;
uint8_t last;
uint8_t golden;
uint8_t pred16x16[4];
uint8_t pred8x8c[3];
uint8_t token[4][16][3][NUM_DCT_TOKENS - 1];
uint8_t mvc[2][19];
uint8_t scan[16];
} prob[2];
VP8Macroblock *macroblocks_base;
int invisible;
int update_last;
int update_golden;
int update_altref;
int update_probabilities;
int num_coeff_partitions;
VP56RangeCoder coeff_partition[8];
int coeff_partition_size[8];
VideoDSPContext vdsp;
VP8DSPContext vp8dsp;
H264PredContext hpc;
vp8_mc_func put_pixels_tab[3][3][3];
VP8Frame frames[5];
uint8_t colorspace;
uint8_t fullrange;
int num_jobs;
int mb_layout;
int (*decode_mb_row_no_filter)(AVCodecContext *avctx, void *tdata, int jobnr, int threadnr);
void (*filter_mb_row)(AVCodecContext *avctx, void *tdata, int jobnr, int threadnr);
int vp7;
int fade_present;
uint16_t inter_dc_pred[2][2];
uint8_t feature_enabled[4];
uint8_t feature_present_prob[4];
uint8_t feature_index_prob[4][3];
uint8_t feature_value[4][4];
} VP8Context;
int ff_vp8_decode_init(AVCodecContext *avctx);
int ff_vp8_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
AVPacket *avpkt);
int ff_vp8_decode_free(AVCodecContext *avctx);
#endif