34 #define VP9_SYNCCODE 0x498342
63 s->
cols = (w + 7) >> 3;
64 s->
rows = (h + 7) >> 3;
66 #define assign(var, type, n) var = (type)p; p += s->sb_cols * n * sizeof(*var)
70 64 * s->
sb_rows * (1 +
sizeof(*s->
mv[0]) * 2)));
110 return m - ((v + 1) >> 1);
117 static const int inv_map_table[
MAX_PROB - 1] = {
118 7, 20, 33, 46, 59, 72, 85, 98, 111, 124, 137, 150, 163, 176,
119 189, 202, 215, 228, 241, 254, 1, 2, 3, 4, 5, 6, 8, 9,
120 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24,
121 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39,
122 40, 41, 42, 43, 44, 45, 47, 48, 49, 50, 51, 52, 53, 54,
123 55, 56, 57, 58, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
124 70, 71, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
125 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 99, 100,
126 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 112, 113, 114, 115,
127 116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130,
128 131, 132, 133, 134, 135, 136, 138, 139, 140, 141, 142, 143, 144, 145,
129 146, 147, 148, 149, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
130 161, 162, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
131 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 190, 191,
132 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 203, 204, 205, 206,
133 207, 208, 209, 210, 211, 212, 213, 214, 216, 217, 218, 219, 220, 221,
134 222, 223, 224, 225, 226, 227, 229, 230, 231, 232, 233, 234, 235, 236,
135 237, 238, 239, 240, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251,
165 d = av_clip(d, 0,
MAX_PROB - 65 - 1);
179 int c, i, j, k, l, m, n, w, h, max, size2, ret, sharp;
253 "Not all references are available\n");
308 for (i = 0; i < 4; i++)
311 for (i = 0; i < 2; i++)
330 for (i = 0; i < 7; i++)
334 for (i = 0; i < 3; i++)
341 for (i = 0; i < 8; i++) {
360 int qyac, qydc, quvac, quvdc, lflvl, sh;
370 qydc = av_clip_uintp2(qyac + s->
ydc_qdelta, 8);
373 qyac = av_clip_uintp2(qyac, 8);
391 av_clip_uintp2(lflvl + (s->
lf_delta.
ref[0] << sh), 6);
392 for (j = 1; j < 4; j++) {
405 "Failed to initialize decoder for %dx%d\n", w, h);
411 for (max = 0; (s->
sb_cols >> max) >= 4; max++) ;
412 max =
FFMAX(0, max - 1);
428 "Ran out of memory during range coder init\n");
451 if (size2 > size - (data2 - data)) {
481 for (i = 0; i < 2; i++)
484 for (i = 0; i < 2; i++)
485 for (j = 0; j < 2; j++)
489 for (i = 0; i < 2; i++)
490 for (j = 0; j < 3; j++)
498 for (i = 0; i < 4; i++) {
501 for (j = 0; j < 2; j++)
502 for (k = 0; k < 2; k++)
503 for (l = 0; l < 6; l++)
504 for (m = 0; m < 6; m++) {
507 if (m >= 3 && l == 0)
509 for (n = 0; n < 3; n++) {
518 for (j = 0; j < 2; j++)
519 for (k = 0; k < 2; k++)
520 for (l = 0; l < 6; l++)
521 for (m = 0; m < 6; m++) {
535 for (i = 0; i < 3; i++)
539 for (i = 0; i < 7; i++)
540 for (j = 0; j < 3; j++)
546 for (i = 0; i < 4; i++)
547 for (j = 0; j < 2; j++)
552 for (i = 0; i < 4; i++)
561 for (i = 0; i < 5; i++)
570 for (i = 0; i < 5; i++) {
581 for (i = 0; i < 5; i++)
587 for (i = 0; i < 4; i++)
588 for (j = 0; j < 9; j++)
593 for (i = 0; i < 4; i++)
594 for (j = 0; j < 4; j++)
595 for (k = 0; k < 3; k++)
602 for (i = 0; i < 3; i++)
606 for (i = 0; i < 2; i++) {
611 for (j = 0; j < 10; j++)
620 for (j = 0; j < 10; j++)
626 for (i = 0; i < 2; i++) {
627 for (j = 0; j < 2; j++)
628 for (k = 0; k < 3; k++)
633 for (j = 0; j < 3; j++)
640 for (i = 0; i < 2; i++) {
652 return (data2 - data) + size2;
657 ptrdiff_t yoff, ptrdiff_t uvoff,
enum BlockLevel bl)
666 ptrdiff_t hbs = 4 >> bl;
671 }
else if (col + hbs < s->cols) {
672 if (row + hbs < s->rows) {
686 yoff, uvoff, bl, bp);
696 yoff, uvoff, bl, bp);
701 yoff, uvoff, bl + 1);
704 yoff + 8 * hbs, uvoff + 4 * hbs,
710 yoff, uvoff, bl + 1);
713 lflvl, yoff + 8 * hbs,
714 uvoff + 4 * hbs, bl + 1);
728 yoff + 8 * hbs, uvoff + 4 * hbs, bl + 1);
734 }
else if (row + hbs < s->rows) {
742 yoff, uvoff, bl + 1);
760 ptrdiff_t yoff, ptrdiff_t uvoff)
774 for (y = 0; y < 8; y += 2, dst += 16 * ls_y, lvl += 16) {
775 uint8_t *ptr = dst, *l = lvl, *hmask1 = lflvl->
mask[0][0][y];
777 unsigned hm1 = hmask1[0] | hmask1[1] | hmask1[2], hm13 = hmask1[3];
778 unsigned hm2 = hmask2[1] | hmask2[2], hm23 = hmask2[3];
779 unsigned hm = hm1 | hm2 | hm13 | hm23;
781 for (x = 1; hm & ~(x - 1); x <<= 1, ptr += 8, l++) {
783 int L = *l,
H = L >> 4;
794 }
else if (hm2 & x) {
801 [0](ptr, ls_y,
E, I,
H);
804 [0](ptr, ls_y, E, I, H);
807 }
else if (hm2 & x) {
808 int L = l[8],
H = L >> 4;
813 [0](ptr + 8 * ls_y, ls_y, E, I, H);
817 int L = *l,
H = L >> 4;
829 }
else if (hm23 & x) {
830 int L = l[8],
H = L >> 4;
843 for (y = 0; y < 8; y++, dst += 8 * ls_y, lvl += 8) {
844 uint8_t *ptr = dst, *l = lvl, *vmask = lflvl->
mask[0][1][y];
845 unsigned vm = vmask[0] | vmask[1] | vmask[2], vm3 = vmask[3];
847 for (x = 1; vm & ~(x - 1); x <<= 2, ptr += 16, l += 2) {
850 int L = *l,
H = L >> 4;
854 if (vmask[0] & (x << 1)) {
860 }
else if (vm & (x << 1)) {
866 [!!(vmask[1] & (x << 1))]
867 [1](ptr, ls_y, E, I, H);
870 [1](ptr, ls_y, E, I, H);
872 }
else if (vm & (x << 1)) {
873 int L = l[1],
H = L >> 4;
877 [1](ptr + 8, ls_y,
E, I,
H);
881 int L = *l,
H = L >> 4;
884 if (vm3 & (x << 1)) {
893 }
else if (vm3 & (x << 1)) {
894 int L = l[1],
H = L >> 4;
903 for (p = 0; p < 2; p++) {
906 for (y = 0; y < 8; y += 4, dst += 16 * ls_uv, lvl += 32) {
907 uint8_t *ptr = dst, *l = lvl, *hmask1 = lflvl->
mask[1][0][y];
909 unsigned hm1 = hmask1[0] | hmask1[1] | hmask1[2];
910 unsigned hm2 = hmask2[1] | hmask2[2], hm = hm1 | hm2;
912 for (x = 1; hm & ~(x - 1); x <<= 1, ptr += 4) {
915 int L = *l,
H = L >> 4;
926 }
else if (hm2 & x) {
933 [0](ptr, ls_uv,
E, I,
H);
936 [0](ptr, ls_uv, E, I, H);
938 }
else if (hm2 & x) {
939 int L = l[16],
H = L >> 4;
944 [0](ptr + 8 * ls_uv, ls_uv, E, I, H);
953 for (y = 0; y < 8; y++, dst += 4 * ls_uv) {
954 uint8_t *ptr = dst, *l = lvl, *vmask = lflvl->
mask[1][1][y];
955 unsigned vm = vmask[0] | vmask[1] | vmask[2];
957 for (x = 1; vm & ~(x - 1); x <<= 4, ptr += 16, l += 4) {
960 int L = *l,
H = L >> 4;
965 if (vmask[0] & (x << 2)) {
971 }
else if (vm & (x << 2)) {
977 [!!(vmask[1] & (x << 2))]
978 [1](ptr, ls_uv, E, I, H);
981 [1](ptr, ls_uv, E, I, H);
983 }
else if (vm & (x << 2)) {
984 int L = l[2],
H = L >> 4;
989 [1](ptr + 8, ls_uv,
E, I,
H);
1001 int sb_start = (idx * n) >> log2_n;
1002 int sb_end = ((idx + 1) * n) >> log2_n;
1003 *start =
FFMIN(sb_start, n) << 3;
1004 *end =
FFMIN(sb_end, n) << 3;
1011 int ret, tile_row, tile_col, i, ref = -1, row, col;
1012 ptrdiff_t yoff = 0, uvoff = 0;
1020 "Requested reference %d not available\n", ref);
1068 if (tile_size > size)
1078 row < s->tiling.tile_row_end;
1082 ptrdiff_t yoff2 = yoff, uvoff2 = uvoff;
1099 memcpy(&s->
c, &s->
c_b[tile_col],
sizeof(s->
c));
1101 col < s->tiling.tile_col_end;
1102 col += 8, yoff2 += 64, uvoff2 += 32, lflvl++) {
1105 memset(lflvl->
mask, 0,
sizeof(lflvl->
mask));
1111 memcpy(&s->
c_b[tile_col], &s->
c,
sizeof(s->
c));
1116 if (row + 8 < s->
rows) {
1136 for (col = 0; col < s->
cols;
1137 col += 8, yoff2 += 64, uvoff2 += 32, lflvl++)
1148 for (i = 0; i < 4; i++) {
1149 for (j = 0; j < 2; j++)
1150 for (k = 0; k < 2; k++)
1151 for (l = 0; l < 6; l++)
1152 for (m = 0; m < 6; m++)
1166 for (i = 0; i < 8; i++)
1191 marker = data[size - 1];
1192 if ((marker & 0xe0) == 0xc0) {
1193 int nbytes = 1 + ((marker >> 3) & 0x3);
1194 int n_frames = 1 + (marker & 0x7);
1195 int idx_sz = 2 + n_frames * nbytes;
1197 if (size >= idx_sz && data[size - idx_sz] == marker) {
1198 const uint8_t *idx = data + size + 1 - idx_sz;
1200 while (n_frames--) {
1204 sz &= (1 << (8 * nbytes)) - 1;
1209 "Superframe packet size too big: %u > %d\n",
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
const uint8_t ff_vp9_default_kf_partition_probs[4][4][3]
static void vp9_decode_flush(AVCodecContext *avctx)
This structure describes decoded (raw) audio or video data.
static void set_tile_offset(int *start, int *end, int idx, int log2_n, int n)
uint8_t left_segpred_ctx[8]
VP5 and VP6 compatible video decoder (common features)
struct VP9Context::@72 filter
static int vp9_decode_packet(AVCodecContext *avctx, void *frame, int *got_frame, AVPacket *avpkt)
uint8_t * above_y_nnz_ctx
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
struct VP9Context::@74 segmentation
static av_always_inline int vp8_rac_get_tree(VP56RangeCoder *c, const int8_t(*tree)[2], const uint8_t *probs)
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
static av_cold int vp9_decode_init(AVCodecContext *avctx)
struct VP9Context::@76 prob_ctx[4]
uint8_t left_uv_nnz_ctx[2][8]
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
#define FF_ARRAY_ELEMS(a)
uint8_t * above_partition_ctx
static void loopfilter_subblock(AVCodecContext *avctx, VP9Filter *lflvl, int row, int col, ptrdiff_t yoff, ptrdiff_t uvoff)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
uint8_t * intra_pred_data[3]
static av_always_inline int get_bits_with_sign(GetBitContext *gb, int n)
uint8_t coef[4][2][2][6][6][3]
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
const int8_t ff_vp9_partition_tree[3][2]
const int16_t ff_vp9_dc_qlookup[256]
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static int update_size(AVCodecContext *avctx, int w, int h)
uint8_t * above_segpred_ctx
bitstream reader API header.
struct VP9Context::@73 lf_delta
static av_cold int vp9_decode_free(AVCodecContext *avctx)
uint8_t partition[4][4][3]
int width
width and height of the video frame
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
static int decode_frame_header(AVCodecContext *avctx, const uint8_t *data, int size, int *ref)
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given block if it is not large enough, otherwise do nothing.
enum CompPredMode comppredmode
uint8_t left_partition_ctx[8]
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
simple assert() macros that are a bit more flexible than ISO C assert().
void av_log(void *avcl, int level, const char *fmt,...)
const char * name
Name of the codec implementation.
uint8_t use_last_frame_mvs
int ff_vp9_decode_block(AVCodecContext *avctx, int row, int col, VP9Filter *lflvl, ptrdiff_t yoff, ptrdiff_t uvoff, enum BlockLevel bl, enum BlockPartition bp)
uint8_t * above_filter_ctx
av_cold void ff_videodsp_init(VideoDSPContext *ctx, int bpc)
enum AVPictureType pict_type
Picture type of the frame.
uint8_t left_y_nnz_ctx[16]
struct VP9Context::@74::@79 feat[8]
int width
picture width / height.
uint8_t left_mode_ctx[16]
unsigned eob[4][2][2][6][6][2]
static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, const uint8_t *data, int size)
void(* loop_filter_16[2])(uint8_t *dst, ptrdiff_t stride, int mb_lim, int lim, int hev_thr)
enum FilterMode filtermode
static av_unused int vp8_rac_get_uint(VP56RangeCoder *c, int bits)
void(* loop_filter_mix2[2][2][2])(uint8_t *dst, ptrdiff_t stride, int mb_lim, int lim, int hev_thr)
static av_always_inline int vp56_rac_get_prob_branchy(VP56RangeCoder *c, int prob)
void(* loop_filter_8[3][2])(uint8_t *dst, ptrdiff_t stride, int mb_lim, int lim, int hev_thr)
VP56mv(* above_mv_ctx)[2]
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
main external API structure.
static void close(AVCodecParserContext *s)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static unsigned int get_bits1(GetBitContext *s)
unsigned partition[4][4][4]
void ff_vp9_adapt_probs(VP9Context *s)
static void skip_bits(GetBitContext *s, int n)
static int decode_subblock(AVCodecContext *avctx, int row, int col, VP9Filter *lflvl, ptrdiff_t yoff, ptrdiff_t uvoff, enum BlockLevel bl)
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
struct ProbContext::@71 mv_comp[2]
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void ff_vp56_init_range_decoder(VP56RangeCoder *c, const uint8_t *buf, int buf_size)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
uint8_t * segmentation_map
static av_always_inline int inv_recenter_nonneg(int v, int m)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
static av_cold void flush(AVCodecContext *avctx)
Flush (reset) the frame ID after seeking.
#define assign(var, type, n)
static av_always_inline int vp8_rac_get(VP56RangeCoder *c)
static av_cold int init(AVCodecParserContext *s)
Core video DSP helper functions.
static int decode012(GetBitContext *gb)
int key_frame
1 -> keyframe, 0-> not
static const uint8_t * align_get_bits(GetBitContext *s)
uint8_t * above_intra_ctx
struct VP9Context::@77 prob
struct VP9Context::@78 counts
struct VP9Context::@75 tiling
static int update_prob(VP56RangeCoder *c, int p)
#define FFSWAP(type, a, b)
const ProbContext ff_vp9_default_probs
const uint8_t ff_vp9_default_coef_probs[4][2][2][6][6][3]
uint8_t * above_uv_nnz_ctx[2]
This structure stores compressed data.
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
const int16_t ff_vp9_ac_qlookup[256]
void ff_vp9dsp_init(VP9DSPContext *dsp)