43#define VP6_MAX_HUFF_SIZE 12
44#define AC_DC_HUFF_BITS 10
45#define RUN_HUFF_BITS 8
53 int parse_filter_info = 0;
60 int separated_coeff = buf[0] & 1;
69 sub_version = buf[1] >> 3;
72 s->filter_header = buf[1] & 0x06;
73 s->interlaced = buf[1] & 1;
78 if (separated_coeff || !
s->filter_header) {
79 coeff_offset =
AV_RB16(buf+2) - 2;
93 if (!
s->macroblocks ||
94 16*cols !=
s->avctx->coded_width ||
95 16*rows !=
s->avctx->coded_height) {
96 if (
s->avctx->extradata_size == 0 &&
97 FFALIGN(
s->avctx->width, 16) == 16 * cols &&
98 FFALIGN(
s->avctx->height, 16) == 16 * rows) {
102 s->avctx->coded_width = 16 * cols;
103 s->avctx->coded_height = 16 * rows;
109 if (
s->avctx->extradata_size == 1) {
110 s->avctx->width -=
s->avctx->extradata[0] >> 4;
111 s->avctx->height -=
s->avctx->extradata[0] & 0x0F;
122 parse_filter_info =
s->filter_header;
125 s->sub_version = sub_version;
128 if (!
s->sub_version || !
s->avctx->coded_width || !
s->avctx->coded_height)
131 if (separated_coeff || !
s->filter_header) {
132 coeff_offset =
AV_RB16(buf+1) - 2;
141 if (
s->filter_header) {
143 if (
s->deblock_filtering)
145 if (
s->sub_version > 7)
150 if (parse_filter_info) {
160 if (
s->sub_version > 7)
163 s->filter_selection = 16;
171 buf_size -= coeff_offset;
176 if (
s->use_huffman) {
202 s->modelp->coeff_index_to_pos[0] = 0;
205 if (
s->modelp->coeff_reorder[
pos] ==
i)
206 s->modelp->coeff_index_to_pos[idx++] =
pos;
208 for (idx = 0; idx < 64; idx++) {
210 for (
i = 0;
i <= idx;
i++) {
211 int v =
s->modelp->coeff_index_to_pos[
i];
215 if (
s->sub_version > 6)
217 s->modelp->coeff_index_to_idct_selector[idx] =
max;
253 for (node=0; node<7; node++)
258 for (node=0; node<8; node++)
266 const Node *
a = va, *
b = vb;
267 return (
a->count -
b->count)*16 + (
b->sym -
a->sym);
271 const uint8_t *
map,
unsigned size,
272 int nb_bits,
VLC *vlc)
280 a =
tmp[
i].count * coeff_model[
i] >> 8;
281 b =
tmp[
i].count * (255 - coeff_model[
i]) >> 8;
303 memset(def_prob, 0x80,
sizeof(def_prob));
306 for (node=0; node<11; node++)
321 for (cg=0; cg<2; cg++)
322 for (node=0; node<14; node++)
326 for (ct=0; ct<3; ct++)
328 for (cg=0; cg<6; cg++)
329 for (node=0; node<11; node++)
337 if (
s->use_huffman) {
349 for (ct=0; ct<3; ct++)
350 for (
int cg = 0; cg < 4; cg++) {
354 &
s->ract_vlc[
pt][ct][cg]);
359 memset(
s->nb_null, 0,
sizeof(
s->nb_null));
364 for (node=0; node<5; node++)
377 if (
s->vector_candidate_pos < 2)
378 *vect =
s->vector_candidate[0];
384 static const uint8_t prob_order[] = {0, 1, 2, 7, 6, 5, 4};
385 for (
i=0;
i<
sizeof(prob_order);
i++) {
386 int j = prob_order[
i];
427 uint8_t *
permute =
s->idct_scantable;
433 for (
b=0;
b<6;
b++) {
436 vlc_coeff = &
s->dccv_vlc[
pt];
438 for (coeff_idx = 0;;) {
440 if (coeff_idx<2 && s->nb_null[coeff_idx][
pt]) {
441 s->nb_null[coeff_idx][
pt]--;
450 int pt = (coeff_idx >= 6);
457 }
else if (
coeff == 11) {
465 ct = 1 + (coeff2 > 1);
467 coeff2 = (coeff2 ^ -sign) + sign;
469 coeff2 *=
s->dequant_ac;
471 s->block_coeff[
b][
permute[idx]] = coeff2;
478 vlc_coeff = &
s->ract_vlc[
pt][ct][cg];
489 uint8_t *
permute =
s->idct_scantable;
490 uint8_t *model1, *model2, *model3;
491 int coeff, sign, coeff_idx;
492 int b,
i, cg, idx,
ctx;
500 for (
b=0;
b<6;
b++) {
507 +
s->above_blocks[
s->above_block_idx[
b]].not_null_dc;
549 for (
run=9,
i=0;
i<6;
i++)
561 s->above_blocks[
s->above_block_idx[
b]].not_null_dc = !!
s->block_coeff[
b][0];
569 int sum = 0, square_sum = 0;
572 for (y=0; y<8; y+=2) {
573 for (x=0; x<8; x+=2) {
575 square_sum +=
src[x]*
src[x];
579 return (16*square_sum - sum*sum) >> 8;
587 for (y=0; y<8; y++) {
588 for (x=0; x<8; x++) {
600 ptrdiff_t
stride,
int h_weight,
int v_weight)
602 uint8_t *
tmp =
s->edge_emu_buffer+16;
603 s->h264chroma.put_h264_chroma_pixels_tab[0](
tmp,
src,
stride, 9, h_weight, 0);
604 s->h264chroma.put_h264_chroma_pixels_tab[0](
dst,
tmp,
stride, 8, 0, v_weight);
608 int offset1,
int offset2, ptrdiff_t
stride,
618 filter4 =
s->filter_mode;
620 if (
s->max_vector_length &&
621 (
FFABS(
mv.x) >
s->max_vector_length ||
622 FFABS(
mv.y) >
s->max_vector_length)) {
624 }
else if (
s->sample_variance_threshold
626 <
s->sample_variance_threshold)) {
632 if ((y8 && (offset2-offset1)*
s->flip<0) || (!y8 && offset1 > offset2)) {
650 s->h264chroma.put_h264_chroma_pixels_tab[0](
dst,
src + offset1,
stride, 8, x8, y8);
658 VP56Context *
s,
int flip,
int has_alpha)
666 s->deblock_filtering = 0;
690 s->alpha_context = &
s[1];
692 s->flip == -1,
s->has_alpha);
708 if (
s->alpha_context) {
710 s->alpha_context =
NULL;
720 for (
int pt = 0;
pt < 2; ++
pt) {
723 for (
int ct = 0; ct < 3; ++ct)
724 for (
int cg = 0; cg < 4; ++cg)
734 .priv_data_size =
sizeof(VP56Context),
748 .priv_data_size =
sizeof(VP56Context),
762 .priv_data_size = 2 *
sizeof(VP56Context),
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
static double val(void *priv, double ch)
const FFCodec ff_vp6f_decoder
const FFCodec ff_vp6a_decoder
const FFCodec ff_vp6_decoder
static AVFormatContext * ctx
static av_cold void close(AVCodecParserContext *s)
Libavcodec external API header.
#define i(width, name, range_min, range_max)
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static void permute(int16_t dst[64], const int16_t src[64], enum idct_permutation_type perm_type)
int ff_set_dimensions(AVCodecContext *s, int width, int height)
int(* init)(AVBSFContext *ctx)
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
bitstream reader API header.
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
static int get_bits_left(GetBitContext *gb)
static unsigned int get_bits1(GetBitContext *s)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const int weights[]
int ff_huff_build_tree(void *logctx, VLC *vlc, int nb_codes, int nb_bits, Node *nodes, HuffCmp cmp, int flags)
nodes size must be 2*nb_codes first nb_codes nodes.count must be set
huffman tree builder and VLC generator
#define FF_HUFFMAN_FLAG_HNODE_FIRST
const VDPAUPixFmtMap * map
static const int8_t mv[256][2]
static void flip(AVCodecContext *avctx, AVFrame *frame)
static const uint16_t mask[17]
main external API structure.
uint8_t coeff_runv[2][14]
uint8_t coeff_dcct[2][36][5]
uint8_t coeff_index_to_pos[64]
uint8_t mb_types_stats[3][10][2]
uint8_t coeff_dccv[2][11]
uint8_t coeff_index_to_idct_selector[64]
uint8_t coeff_reorder[64]
uint8_t coeff_ract[2][3][6][11]
static const double coeff[2][5]
void ff_vlc_free(VLC *vlc)
av_cold int ff_vp56_init_context(AVCodecContext *avctx, VP56Context *s, int flip, int has_alpha)
Initializes an VP56Context.
av_cold int ff_vp56_free_context(VP56Context *s)
void ff_vp56_init_dequant(VP56Context *s, int quantizer)
int ff_vp56_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, AVPacket *avpkt)
VP5 and VP6 compatible video decoder (common features)
static int vp56_rac_gets(VPXRangeCoder *c, int bits)
vp56 specific range coder implementation
static av_always_inline int vp56_rac_get_tree(VPXRangeCoder *c, const VP56Tree *tree, const uint8_t *probs)
static av_unused int vp56_rac_gets_nn(VPXRangeCoder *c, int bits)
const VP56Tree ff_vp56_pva_tree[]
const uint8_t ff_vp56_def_mb_types_stats[3][10][2]
const uint8_t ff_vp56_b6to4[]
const uint8_t ff_vp56_coeff_bias[]
const uint8_t ff_vp56_coeff_bit_length[]
const uint8_t ff_vp56_coeff_parse_table[6][11]
const VP56Tree ff_vp56_pc_tree[]
VP5 and VP6 compatible video decoder (common data)
void ff_vp6dsp_init(VP6DSPContext *s)
static void vp6_parse_vector_adjustment(VP56Context *s, VP56mv *vect)
static void vp6_coeff_order_table_init(VP56Context *s)
static av_cold int vp6_decode_init_context(AVCodecContext *avctx, VP56Context *s, int flip, int has_alpha)
static av_cold int vp6_decode_init(AVCodecContext *avctx)
static int vp6_huff_cmp(const void *va, const void *vb)
static av_cold int vp6_decode_free(AVCodecContext *avctx)
static int vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[], const uint8_t *map, unsigned size, int nb_bits, VLC *vlc)
static void vp6_default_models_init(VP56Context *s)
static void vp6_parse_vector_models(VP56Context *s)
static void vp6_filter_diag2(VP56Context *s, uint8_t *dst, uint8_t *src, ptrdiff_t stride, int h_weight, int v_weight)
static int vp6_parse_coeff_models(VP56Context *s)
static unsigned vp6_get_nb_null(VP56Context *s)
Read number of consecutive blocks with null DC or AC.
static int vp6_parse_coeff(VP56Context *s)
static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
static int vp6_parse_coeff_huffman(VP56Context *s)
static void vp6_filter(VP56Context *s, uint8_t *dst, uint8_t *src, int offset1, int offset2, ptrdiff_t stride, VP56mv mv, int mask, int select, int luma)
static av_cold void vp6_decode_free_context(VP56Context *s)
static void vp6_filter_hv4(uint8_t *dst, uint8_t *src, ptrdiff_t stride, int delta, const int16_t *weights)
static int vp6_block_variance(uint8_t *src, ptrdiff_t stride)
#define VP6_MAX_HUFF_SIZE
VP6 compatible video decoder.
static const uint8_t vp6_coeff_groups[]
static const uint8_t vp6_def_fdv_vector_model[2][8]
static const VP56Tree vp6_pcr_tree[]
static const uint8_t vp6_dccv_pct[2][11]
static const uint8_t vp6_huff_run_map[]
static const uint8_t vp6_def_coeff_reorder[]
static const int16_t vp6_block_copy_filter[17][8][4]
static const uint8_t vp6_coord_div[]
static const uint8_t vp6_def_pdv_vector_model[2][7]
static const uint8_t vp6_def_runv_coeff_model[2][14]
static const uint8_t vp6_pdv_pct[2][7]
static const uint8_t vp6_il_coeff_reorder[]
static const int vp6_dccv_lc[3][5][2]
static const uint8_t vp6_runv_pct[2][14]
static const uint8_t vp6_fdv_pct[2][8]
static const uint8_t vp6_ract_pct[3][2][6][11]
static const uint8_t vp6_sig_dct_pct[2][2]
static const uint8_t vp6_huff_coeff_map[]
static const uint8_t vp6_coeff_reorder_pct[]
int ff_vpx_init_range_decoder(VPXRangeCoder *c, const uint8_t *buf, int buf_size)
Common VP5-VP9 range decoder stuff.
static av_always_inline int vpx_rac_get_prob_branchy(VPXRangeCoder *c, int prob)
static av_always_inline int vpx_rac_get(VPXRangeCoder *c)
static av_always_inline int vpx_rac_is_end(VPXRangeCoder *c)
returns 1 if the end of the stream has been reached, 0 otherwise.