41 #define VP6_MAX_HUFF_SIZE 12
49 int parse_filter_info = 0;
55 int separated_coeff = buf[0] & 1;
61 sub_version = buf[1] >> 3;
64 s->filter_header = buf[1] & 0x06;
69 if (separated_coeff || !s->filter_header) {
70 coeff_offset =
AV_RB16(buf+2) - 2;
84 if (!s->macroblocks ||
85 16*cols != s->avctx->coded_width ||
86 16*rows != s->avctx->coded_height) {
87 if (s->avctx->extradata_size == 0 &&
88 FFALIGN(s->avctx->width, 16) == 16 * cols &&
89 FFALIGN(s->avctx->height, 16) == 16 * rows) {
93 s->avctx->coded_width = 16 * cols;
94 s->avctx->coded_height = 16 * rows;
100 if (s->avctx->extradata_size == 1) {
101 s->avctx->width -= s->avctx->extradata[0] >> 4;
102 s->avctx->height -= s->avctx->extradata[0] & 0x0F;
111 parse_filter_info = s->filter_header;
114 s->sub_version = sub_version;
117 if (!s->sub_version || !s->avctx->coded_width || !s->avctx->coded_height)
120 if (separated_coeff || !s->filter_header) {
121 coeff_offset =
AV_RB16(buf+1) - 2;
128 if (s->filter_header) {
130 if (s->deblock_filtering)
132 if (s->sub_version > 7)
137 if (parse_filter_info) {
140 s->sample_variance_threshold =
vp56_rac_gets(c, 5) << vrt_shift;
147 if (s->sub_version > 7)
150 s->filter_selection = 16;
158 buf_size -= coeff_offset;
164 if (s->use_huffman) {
182 s->modelp->coeff_index_to_pos[0] = 0;
184 for (pos=1; pos<64; pos++)
185 if (s->modelp->coeff_reorder[pos] == i)
186 s->modelp->coeff_index_to_pos[idx++] = pos;
213 for (comp=0; comp<2; comp++) {
220 for (comp=0; comp<2; comp++)
221 for (node=0; node<7; node++)
225 for (comp=0; comp<2; comp++)
226 for (node=0; node<8; node++)
234 const Node *
a = va, *
b = vb;
235 return (a->
count - b->count)*16 + (b->sym - a->
sym);
246 for (i=0; i<size-1; i++) {
247 a = tmp[i].
count * coeff_model[i] >> 8;
248 b = tmp[i].
count * (255 - coeff_model[i]) >> 8;
249 nodes[map[2*i ]].
count = a + !
a;
250 nodes[map[2*i+1]].
count = b + !
b;
265 int node, cg,
ctx, pos;
269 memset(def_prob, 0x80,
sizeof(def_prob));
271 for (pt=0; pt<2; pt++)
272 for (node=0; node<11; node++)
281 for (pos=1; pos<64; pos++)
287 for (cg=0; cg<2; cg++)
288 for (node=0; node<14; node++)
292 for (ct=0; ct<3; ct++)
293 for (pt=0; pt<2; pt++)
294 for (cg=0; cg<6; cg++)
295 for (node=0; node<11; node++)
303 if (s->use_huffman) {
304 for (pt=0; pt<2; pt++) {
311 for (ct=0; ct<3; ct++)
312 for (cg = 0; cg < 6; cg++)
315 &s->ract_vlc[pt][ct][cg]))
318 memset(s->nb_null, 0,
sizeof(s->nb_null));
321 for (pt=0; pt<2; pt++)
322 for (ctx=0; ctx<3; ctx++)
323 for (node=0; node<5; node++)
336 if (s->vector_candidate_pos < 2)
337 *vect = s->vector_candidate[0];
339 for (comp=0; comp<2; comp++) {
343 static const uint8_t prob_order[] = {0, 1, 2, 7, 6, 5, 4};
344 for (i=0; i<
sizeof(prob_order); i++) {
345 int j = prob_order[i];
378 val = 6+val +
get_bits(&s->gb, 2+val);
388 int coeff, sign, coeff_idx;
392 for (b=0; b<6; b++) {
395 vlc_coeff = &s->dccv_vlc[
pt];
397 for (coeff_idx = 0;;) {
399 if (coeff_idx<2 && s->nb_null[coeff_idx][pt]) {
400 s->nb_null[coeff_idx][
pt]--;
409 int pt = (coeff_idx >= 6);
416 }
else if (coeff == 11) {
423 coeff2 +=
get_bits(&s->gb, coeff <= 9 ? coeff - 4 : 11);
424 ct = 1 + (coeff2 > 1);
426 coeff2 = (coeff2 ^ -sign) + sign;
428 coeff2 *= s->dequant_ac;
430 s->block_coeff[
b][permute[idx]] = coeff2;
437 vlc_coeff = &s->ract_vlc[
pt][ct][cg];
447 uint8_t *model1, *model2, *model3;
448 int coeff, sign, coeff_idx;
449 int b, i, cg, idx,
ctx;
452 for (b=0; b<6; b++) {
459 + s->above_blocks[s->above_block_idx[
b]].not_null_dc;
485 coeff = (coeff ^ -sign) + sign;
487 coeff *= s->dequant_ac;
489 s->block_coeff[
b][permute[idx]] =
coeff;
501 for (run=9, i=0; i<6; i++)
513 s->above_blocks[s->above_block_idx[
b]].not_null_dc = !!s->block_coeff[
b][0];
519 int sum = 0, square_sum = 0;
522 for (y=0; y<8; y+=2) {
523 for (x=0; x<8; x+=2) {
525 square_sum += src[x]*src[x];
529 return (16*square_sum - sum*sum) >> 8;
533 int delta,
const int16_t *weights)
537 for (y=0; y<8; y++) {
538 for (x=0; x<8; x++) {
539 dst[x] = av_clip_uint8(( src[x-delta ] * weights[0]
540 + src[x ] * weights[1]
541 + src[x+delta ] * weights[2]
542 + src[x+2*delta] * weights[3] + 64) >> 7);
550 int stride,
int h_weight,
int v_weight)
552 uint8_t *tmp = s->edge_emu_buffer+16;
553 s->h264chroma.put_h264_chroma_pixels_tab[0](tmp,
src,
stride, 9, h_weight, 0);
554 s->h264chroma.put_h264_chroma_pixels_tab[0](dst, tmp,
stride, 8, 0, v_weight);
558 int offset1,
int offset2,
int stride,
562 int x8 = mv.
x &
mask;
563 int y8 = mv.
y &
mask;
568 filter4 = s->filter_mode;
570 if (s->max_vector_length &&
571 (
FFABS(mv.
x) > s->max_vector_length ||
572 FFABS(mv.
y) > s->max_vector_length)) {
574 }
else if (s->sample_variance_threshold
576 < s->sample_variance_threshold)) {
582 if ((y8 && (offset2-offset1)*s->flip<0) || (!y8 && offset1 > offset2)) {
594 s->vp56dsp.vp6_filter_diag4(dst, src+offset1+((mv.
x^mv.
y)>>31), stride,
600 s->h264chroma.put_h264_chroma_pixels_tab[0](dst, src + offset1,
stride, 8, x8, y8);
621 s->alpha_context =
av_mallocz(
sizeof(VP56Context));
623 s->flip == -1, s->has_alpha);
632 s->deblock_filtering = 0;
651 if (s->alpha_context) {
664 for (pt=0; pt<2; pt++) {
667 for (ct=0; ct<3; ct++)
668 for (cg=0; cg<6; cg++)
678 .priv_data_size =
sizeof(VP56Context),
691 .priv_data_size =
sizeof(VP56Context),
704 .priv_data_size =
sizeof(VP56Context),
av_cold int ff_vp56_free(AVCodecContext *avctx)
const struct AVCodec * codec
const char const char void * val
static void vp6_coeff_order_table_init(VP56Context *s)
uint8_t coeff_ract[2][3][6][11]
static const uint8_t vp6_ract_pct[3][2][6][11]
static av_cold int vp6_decode_init(AVCodecContext *avctx)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define FF_HUFFMAN_FLAG_HNODE_FIRST
static const uint8_t vp6_runv_pct[2][14]
static int vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[], const uint8_t *map, unsigned size, VLC *vlc)
uint8_t coeff_index_to_pos[64]
VP5 and VP6 compatible video decoder (common features)
static const int16_t vp6_block_copy_filter[17][8][4]
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static const uint8_t vp6_def_fdv_vector_model[2][8]
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
const uint8_t ff_vp56_coeff_bias[]
uint8_t coeff_dccv[2][11]
int ff_huff_build_tree(AVCodecContext *avctx, 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
static av_cold int init(AVCodecContext *avctx)
uint8_t mb_types_stats[3][10][2]
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
static const uint8_t vp6_huff_coeff_map[]
av_cold int ff_vp56_init(AVCodecContext *avctx, int flip, int has_alpha)
static av_cold void vp6_decode_free_context(VP56Context *s)
static void vp6_filter(VP56Context *s, uint8_t *dst, uint8_t *src, int offset1, int offset2, int stride, VP56mv mv, int mask, int select, int luma)
static const uint8_t vp6_def_runv_coeff_model[2][14]
static const uint8_t vp6_def_coeff_reorder[]
static int vp6_parse_coeff_models(VP56Context *s)
av_cold int ff_vp56_init_context(AVCodecContext *avctx, VP56Context *s, int flip, int has_alpha)
#define VP6_MAX_HUFF_SIZE
static void permute(int16_t dst[64], const int16_t src[64], enum idct_permutation_type perm_type)
bitstream reader API header.
static const uint8_t vp6_dccv_pct[2][11]
static av_always_inline int vp56_rac_get_tree(VP56RangeCoder *c, const VP56Tree *tree, const uint8_t *probs)
uint8_t coeff_reorder[64]
static int get_bits_left(GetBitContext *gb)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const uint16_t mask[17]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static av_always_inline int vp56_rac_get(VP56RangeCoder *c)
const char * name
Name of the codec implementation.
void ff_vp56_init_dequant(VP56Context *s, int quantizer)
const uint8_t ff_vp56_b6to4[]
static int vp6_huff_cmp(const void *va, const void *vb)
static void vp6_parse_vector_models(VP56Context *s)
VP5 and VP6 compatible video decoder (common data)
static av_unused int vp56_rac_gets_nn(VP56RangeCoder *c, int bits)
static void vp6_filter_diag2(VP56Context *s, uint8_t *dst, uint8_t *src, int stride, int h_weight, int v_weight)
static av_cold void vp6_decode_init_context(VP56Context *s)
VP6 compatible video decoder.
static void vp6_default_models_init(VP56Context *s)
static const uint8_t vp6_huff_run_map[]
static void vp6_parse_coeff_huffman(VP56Context *s)
int ff_vp56_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
const uint8_t ff_vp56_coeff_bit_length[]
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
#define vp56_rac_get_prob
static const VP56Tree vp6_pcr_tree[]
static void vp6_filter_hv4(uint8_t *dst, uint8_t *src, int stride, int delta, const int16_t *weights)
uint8_t coeff_runv[2][14]
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
static const int8_t mv[256][2]
static av_always_inline int vp56_rac_get_prob_branchy(VP56RangeCoder *c, int prob)
Libavcodec external API header.
static const uint8_t vp6_coeff_reorder_pct[]
const VP56Tree ff_vp56_pc_tree[]
main external API structure.
static void vp6_parse_coeff(VP56Context *s)
static const uint8_t vp6_fdv_pct[2][8]
static const uint8_t vp6_coord_div[]
static unsigned vp6_get_nb_null(VP56Context *s)
Read number of consecutive blocks with null DC or AC.
static const uint8_t vp6_sig_dct_pct[2][2]
const uint8_t ff_vp56_coeff_parse_table[6][11]
uint8_t coeff_dcct[2][36][5]
static unsigned int get_bits1(GetBitContext *s)
static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size)
static av_cold int vp6_decode_free(AVCodecContext *avctx)
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
huffman tree builder and VLC generator
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
void ff_vp56_init_range_decoder(VP56RangeCoder *c, const uint8_t *buf, int buf_size)
av_cold int ff_vp56_free_context(VP56Context *s)
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
static const int vp6_dccv_lc[3][5][2]
const VP56Tree ff_vp56_pva_tree[]
GLint GLenum GLboolean GLsizei stride
common internal api header.
static void vp6_parse_vector_adjustment(VP56Context *s, VP56mv *vect)
static const uint8_t vp6_coeff_groups[]
static const uint8_t vp6_def_pdv_vector_model[2][7]
VLC_TYPE(* table)[2]
code, bits
static const double coeff[2][5]
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
const uint8_t ff_vp56_def_mb_types_stats[3][10][2]
void ff_free_vlc(VLC *vlc)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static const uint8_t vp6_pdv_pct[2][7]
static int vp56_rac_gets(VP56RangeCoder *c, int bits)
static int vp6_block_variance(uint8_t *src, int stride)