34 #define VP9_SYNCCODE 0x498342 119 int nb_blocks, nb_superblocks;
126 if (w <= 0 || h <= 0)
133 s->
cols = (w + 7) >> 3;
134 s->
rows = (h + 7) >> 3;
136 #define assign(var, type, n) var = (type)p; p += s->sb_cols * n * sizeof(*var) 168 nb_blocks = nb_superblocks = 1;
199 return m - ((v + 1) >> 1);
206 static const int inv_map_table[
MAX_PROB - 1] = {
207 7, 20, 33, 46, 59, 72, 85, 98, 111, 124, 137, 150, 163, 176,
208 189, 202, 215, 228, 241, 254, 1, 2, 3, 4, 5, 6, 8, 9,
209 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24,
210 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39,
211 40, 41, 42, 43, 44, 45, 47, 48, 49, 50, 51, 52, 53, 54,
212 55, 56, 57, 58, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
213 70, 71, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
214 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 99, 100,
215 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 112, 113, 114, 115,
216 116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130,
217 131, 132, 133, 134, 135, 136, 138, 139, 140, 141, 142, 143, 144, 145,
218 146, 147, 148, 149, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
219 161, 162, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
220 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 190, 191,
221 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 203, 204, 205, 206,
222 207, 208, 209, 210, 211, 212, 213, 214, 216, 217, 218, 219, 220, 221,
223 222, 223, 224, 225, 226, 227, 229, 230, 231, 232, 233, 234, 235, 236,
224 237, 238, 239, 240, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251,
254 d = av_clip(d, 0,
MAX_PROB - 65 - 1);
268 int c, i, j, k, l, m, n, w, h, max, size2, ret, sharp;
317 "4:2:0 color not supported in profile 1 or 3\n");
363 "Not all references are available\n");
418 for (i = 0; i < 4; i++)
421 for (i = 0; i < 2; i++)
440 for (i = 0; i < 7; i++)
444 for (i = 0; i < 3; i++)
451 for (i = 0; i < 8; i++) {
470 int qyac, qydc, quvac, quvdc, lflvl, sh;
480 qydc = av_clip_uintp2(qyac + s->
ydc_qdelta, 8);
483 qyac = av_clip_uintp2(qyac, 8);
501 av_clip_uintp2(lflvl + (s->
lf_delta.
ref[0] << sh), 6);
502 for (j = 1; j < 4; j++) {
515 "Failed to initialize decoder for %dx%d\n", w, h);
521 for (max = 0; (s->
sb_cols >> max) >= 4; max++) ;
522 max =
FFMAX(0, max - 1);
538 "Ran out of memory during range coder init\n");
561 if (size2 > size - (data2 - data)) {
591 for (i = 0; i < 2; i++)
594 for (i = 0; i < 2; i++)
595 for (j = 0; j < 2; j++)
599 for (i = 0; i < 2; i++)
600 for (j = 0; j < 3; j++)
608 for (i = 0; i < 4; i++) {
611 for (j = 0; j < 2; j++)
612 for (k = 0; k < 2; k++)
613 for (l = 0; l < 6; l++)
614 for (m = 0; m < 6; m++) {
617 if (m >= 3 && l == 0)
619 for (n = 0; n < 3; n++) {
628 for (j = 0; j < 2; j++)
629 for (k = 0; k < 2; k++)
630 for (l = 0; l < 6; l++)
631 for (m = 0; m < 6; m++) {
645 for (i = 0; i < 3; i++)
649 for (i = 0; i < 7; i++)
650 for (j = 0; j < 3; j++)
656 for (i = 0; i < 4; i++)
657 for (j = 0; j < 2; j++)
662 for (i = 0; i < 4; i++)
671 for (i = 0; i < 5; i++)
680 for (i = 0; i < 5; i++) {
691 for (i = 0; i < 5; i++)
697 for (i = 0; i < 4; i++)
698 for (j = 0; j < 9; j++)
703 for (i = 0; i < 4; i++)
704 for (j = 0; j < 4; j++)
705 for (k = 0; k < 3; k++)
712 for (i = 0; i < 3; i++)
716 for (i = 0; i < 2; i++) {
721 for (j = 0; j < 10; j++)
730 for (j = 0; j < 10; j++)
736 for (i = 0; i < 2; i++) {
737 for (j = 0; j < 2; j++)
738 for (k = 0; k < 3; k++)
743 for (j = 0; j < 3; j++)
750 for (i = 0; i < 2; i++) {
762 return (data2 - data) + size2;
767 ptrdiff_t yoff, ptrdiff_t uvoff,
enum BlockLevel bl)
777 ptrdiff_t hbs = 4 >> bl;
782 }
else if (col + hbs < s->cols) {
783 if (row + hbs < s->rows) {
797 yoff, uvoff, bl, bp);
807 yoff, uvoff, bl, bp);
812 yoff, uvoff, bl + 1);
815 yoff + 8 * hbs, uvoff + 4 * hbs,
821 yoff, uvoff, bl + 1);
824 lflvl, yoff + 8 * hbs,
825 uvoff + 4 * hbs, bl + 1);
839 yoff + 8 * hbs, uvoff + 4 * hbs, bl + 1);
845 }
else if (row + hbs < s->rows) {
853 yoff, uvoff, bl + 1);
870 ptrdiff_t yoff, ptrdiff_t uvoff,
enum BlockLevel bl)
874 ptrdiff_t hbs = 4 >> bl;
882 }
else if (s->
b->
bl == bl) {
886 yoff += hbs * 8 * y_stride;
887 uvoff += hbs * 4 * uv_stride;
897 if (col + hbs < s->cols) {
898 if (row + hbs < s->rows) {
900 uvoff + 4 * hbs, bl + 1)) < 0)
902 yoff += hbs * 8 * y_stride;
903 uvoff += hbs * 4 * uv_stride;
908 yoff + 8 * hbs, uvoff + 4 * hbs, bl + 1);
914 }
else if (row + hbs < s->rows) {
915 yoff += hbs * 8 * y_stride;
916 uvoff += hbs * 4 * uv_stride;
926 ptrdiff_t yoff, ptrdiff_t uvoff)
942 for (y = 0; y < 8; y += 2, dst += 16 * ls_y, lvl += 16) {
943 uint8_t *ptr = dst, *l = lvl, *hmask1 = lflvl->
mask[0][0][y];
945 unsigned hm1 = hmask1[0] | hmask1[1] | hmask1[2], hm13 = hmask1[3];
946 unsigned hm2 = hmask2[1] | hmask2[2], hm23 = hmask2[3];
947 unsigned hm = hm1 | hm2 | hm13 | hm23;
949 for (x = 1; hm & ~(x - 1); x <<= 1, ptr += 8, l++) {
951 int L = *l,
H = L >> 4;
962 }
else if (hm2 & x) {
969 [0](ptr, ls_y,
E, I,
H);
972 [0](ptr, ls_y, E, I, H);
975 }
else if (hm2 & x) {
976 int L = l[8],
H = L >> 4;
981 [0](ptr + 8 * ls_y, ls_y, E, I, H);
985 int L = *l,
H = L >> 4;
997 }
else if (hm23 & x) {
998 int L = l[8],
H = L >> 4;
1009 dst = f->
data[0] + yoff;
1011 for (y = 0; y < 8; y++, dst += 8 * ls_y, lvl += 8) {
1012 uint8_t *ptr = dst, *l = lvl, *vmask = lflvl->
mask[0][1][y];
1013 unsigned vm = vmask[0] | vmask[1] | vmask[2], vm3 = vmask[3];
1015 for (x = 1; vm & ~(x - 1); x <<= 2, ptr += 16, l += 2) {
1018 int L = *l,
H = L >> 4;
1022 if (vmask[0] & (x << 1)) {
1028 }
else if (vm & (x << 1)) {
1034 [!!(vmask[1] & (x << 1))]
1035 [1](ptr, ls_y, E, I, H);
1038 [1](ptr, ls_y, E, I, H);
1040 }
else if (vm & (x << 1)) {
1041 int L = l[1],
H = L >> 4;
1045 [1](ptr + 8, ls_y,
E, I,
H);
1049 int L = *l,
H = L >> 4;
1052 if (vm3 & (x << 1)) {
1061 }
else if (vm3 & (x << 1)) {
1062 int L = l[1],
H = L >> 4;
1071 for (p = 0; p < 2; p++) {
1073 dst = f->
data[1 + p] + uvoff;
1074 for (y = 0; y < 8; y += 4, dst += 16 * ls_uv, lvl += 32) {
1075 uint8_t *ptr = dst, *l = lvl, *hmask1 = lflvl->
mask[1][0][y];
1077 unsigned hm1 = hmask1[0] | hmask1[1] | hmask1[2];
1078 unsigned hm2 = hmask2[1] | hmask2[2], hm = hm1 | hm2;
1080 for (x = 1; hm & ~(x - 1); x <<= 1, ptr += 4) {
1083 int L = *l,
H = L >> 4;
1087 if (hmask1[0] & x) {
1088 if (hmask2[0] & x) {
1094 }
else if (hm2 & x) {
1101 [0](ptr, ls_uv,
E, I,
H);
1104 [0](ptr, ls_uv, E, I, H);
1106 }
else if (hm2 & x) {
1107 int L = l[16],
H = L >> 4;
1112 [0](ptr + 8 * ls_uv, ls_uv, E, I, H);
1120 dst = f->
data[1 + p] + uvoff;
1121 for (y = 0; y < 8; y++, dst += 4 * ls_uv) {
1122 uint8_t *ptr = dst, *l = lvl, *vmask = lflvl->
mask[1][1][y];
1123 unsigned vm = vmask[0] | vmask[1] | vmask[2];
1125 for (x = 1; vm & ~(x - 1); x <<= 4, ptr += 16, l += 4) {
1128 int L = *l,
H = L >> 4;
1133 if (vmask[0] & (x << 2)) {
1139 }
else if (vm & (x << 2)) {
1145 [!!(vmask[1] & (x << 2))]
1146 [1](ptr, ls_uv, E, I, H);
1149 [1](ptr, ls_uv, E, I, H);
1151 }
else if (vm & (x << 2)) {
1152 int L = l[2],
H = L >> 4;
1157 [1](ptr + 8, ls_uv,
E, I,
H);
1169 int sb_start = (idx * n) >> log2_n;
1170 int sb_end = ((idx + 1) * n) >> log2_n;
1171 *start =
FFMIN(sb_start, n) << 3;
1172 *end =
FFMIN(sb_end, n) << 3;
1193 int can_finish_setup)
1197 int ret, tile_row, tile_col, i, ref = -1, row, col;
1205 "Requested reference %d not available\n", ref);
1251 for (i = 0; i < 4; i++) {
1252 for (j = 0; j < 2; j++)
1253 for (k = 0; k < 2; k++)
1254 for (l = 0; l < 6; l++)
1255 for (m = 0; m < 6; m++)
1282 ptrdiff_t yoff = 0, uvoff = 0;
1307 if (tile_size > size) {
1322 row < s->tiling.tile_row_end;
1323 row += 8, yoff += f->
linesize[0] * 64,
1326 ptrdiff_t yoff2 = yoff, uvoff2 = uvoff;
1343 memcpy(&s->
c, &s->
c_b[tile_col],
sizeof(s->
c));
1345 col < s->tiling.tile_col_end;
1346 col += 8, yoff2 += 64, uvoff2 += 32, lflvl++) {
1350 memset(lflvl->
mask, 0,
sizeof(lflvl->
mask));
1363 memcpy(&s->
c_b[tile_col], &s->
c,
sizeof(s->
c));
1371 if (row + 8 < s->
rows) {
1377 f->
data[1] + uvoff +
1381 f->
data[2] + uvoff +
1391 for (col = 0; col < s->
cols;
1392 col += 8, yoff2 += 64, uvoff2 += 32, lflvl++)
1410 }
while (s->
pass++ == 1);
1446 marker = data[size - 1];
1447 if ((marker & 0xe0) == 0xc0) {
1448 int nbytes = 1 + ((marker >> 3) & 0x3);
1449 int n_frames = 1 + (marker & 0x7);
1450 int idx_sz = 2 + n_frames * nbytes;
1452 if (size >= idx_sz && data[size - idx_sz] == marker) {
1453 const uint8_t *idx = data + size + 1 - idx_sz;
1455 while (n_frames--) {
1459 sz &= (1 << (8 * nbytes)) - 1;
1464 "Superframe packet size too big: %u > %d\n",
1515 memset(s, 0,
sizeof(*s));
1548 ret =
update_size(dst, ssrc->alloc_width, ssrc->alloc_height);
1552 for (i = 0; i < 2; i++) {
1555 if (ssrc->frames[i].tf.f->data[0]) {
1562 if (ssrc->refs[i].f->buf[0]) {
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
struct ProbContext::@100 mv_comp[2]
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
uint8_t * segmentation_map
const uint8_t ff_vp9_default_kf_partition_probs[4][4][3]
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
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)
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.
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.
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
static av_cold int vp9_decode_init(AVCodecContext *avctx)
enum AVColorRange color_range
MPEG vs JPEG YUV range.
av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (%s)\, len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic ? ac->func_descr_generic :ac->func_descr)
uint8_t left_uv_nnz_ctx[2][8]
struct VP9Context::@106 prob
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
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)
functionally identical to above
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]
const int8_t ff_vp9_partition_tree[3][2]
static int vp9_decode_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
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.
struct VP9Context::@103::@109 feat[MAX_SEGMENT]
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
static int update_size(AVCodecContext *avctx, int w, int h)
int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src)
uint8_t * above_segpred_ctx
bitstream reader API header.
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
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.
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
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. ...
int active_thread_type
Which multithreading methods are in use by the codec.
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
int16_t * uvblock_base[2]
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)
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
struct VP9Context::@101 filter
uint8_t * above_filter_ctx
av_cold void ff_videodsp_init(VideoDSPContext *ctx, int bpc)
enum AVPictureType pict_type
Picture type of the frame.
#define FF_THREAD_FRAME
Decode more than one frame at once.
uint8_t left_y_nnz_ctx[16]
struct VP9Context::@107 counts
int width
picture width / height.
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
uint8_t left_mode_ctx[16]
unsigned eob[4][2][2][6][6][2]
void(* loop_filter_16[2])(uint8_t *dst, ptrdiff_t stride, int mb_lim, int lim, int hev_thr)
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
enum FilterMode filtermode
the normal 2^n-1 "JPEG" YUV ranges
if(ac->has_optimized_func)
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
struct VP9Context::@103 segmentation
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.
AVBufferRef * segmentation_map_buf
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.
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, const uint8_t *data, int size, int can_finish_setup)
main external API structure.
uint8_t * data
The data buffer.
struct VP9Context::@105 prob_ctx[4]
AVBufferRef * av_buffer_allocz(int size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
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)
enum AVColorSpace colorspace
YUV colorspace type.
static int update_refs(AVCodecContext *avctx)
static int decode_subblock(AVCodecContext *avctx, int row, int col, VP9Filter *lflvl, ptrdiff_t yoff, ptrdiff_t uvoff, enum BlockLevel bl)
int allocate_progress
Whether to allocate progress for frame threading.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static int vp8_rac_get_uint(VP56RangeCoder *c, int bits)
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
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)
static void vp9_frame_unref(AVCodecContext *avctx, VP9Frame *f)
static void * av_malloc_array(size_t nmemb, size_t size)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
the normal 219*2^(n-8) "MPEG" YUV ranges
static int vp9_frame_ref(VP9Frame *dst, VP9Frame *src)
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)
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
static av_always_inline int vp8_rac_get(VP56RangeCoder *c)
static av_cold int init(AVCodecParserContext *s)
Core video DSP helper functions.
static int vp9_frame_alloc(AVCodecContext *avctx, VP9Frame *f)
struct AVCodecInternal * internal
Private context used for internal data.
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
static void * av_mallocz_array(size_t nmemb, size_t size)
static int update_prob(VP56RangeCoder *c, int p)
const ProbContext ff_vp9_default_probs
struct VP9Context::@104 tiling
struct VP9Context::@102 lf_delta
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.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
const int16_t ff_vp9_ac_qlookup[256]
static int decode_superblock_mem(AVCodecContext *avctx, int row, int col, struct VP9Filter *lflvl, ptrdiff_t yoff, ptrdiff_t uvoff, enum BlockLevel bl)
void ff_vp9dsp_init(VP9DSPContext *dsp)