24 #include "config_components.h"
51 #define VP9_SYNCCODE 0x498342
105 f->segmentation_map =
NULL;
117 sz = 64 *
s->sb_cols *
s->sb_rows;
118 if (sz !=
s->frame_extradata_pool_size) {
122 if (!
s->frame_extradata_pool) {
123 s->frame_extradata_pool_size = 0;
127 s->frame_extradata_pool_size = sz;
135 f->segmentation_map =
f->extradata;
152 dst->frame_header =
src->frame_header;
158 dst->segmentation_map =
src->segmentation_map;
160 dst->uses_2pass =
src->uses_2pass;
163 src->hwaccel_picture_private);
168 #define HWACCEL_MAX (CONFIG_VP9_DXVA2_HWACCEL + \
169 CONFIG_VP9_D3D11VA_HWACCEL * 2 + \
170 CONFIG_VP9_D3D12VA_HWACCEL + \
171 CONFIG_VP9_NVDEC_HWACCEL + \
172 CONFIG_VP9_NVDEC_CUARRAY_HWACCEL + \
173 CONFIG_VP9_VAAPI_HWACCEL + \
174 CONFIG_VP9_VDPAU_HWACCEL + \
175 CONFIG_VP9_VIDEOTOOLBOX_HWACCEL + \
176 CONFIG_VP9_VULKAN_HWACCEL)
180 int bytesperpixel =
s->bytesperpixel,
ret, cols, rows;
186 if (!(
s->pix_fmt ==
s->gf_fmt &&
w ==
s->w &&
h ==
s->h)) {
191 switch (
s->pix_fmt) {
194 #if CONFIG_VP9_DXVA2_HWACCEL
197 #if CONFIG_VP9_D3D11VA_HWACCEL
201 #if CONFIG_VP9_D3D12VA_HWACCEL
204 #if CONFIG_VP9_NVDEC_HWACCEL
207 #if CONFIG_VP9_NVDEC_CUARRAY_HWACCEL
210 #if CONFIG_VP9_VAAPI_HWACCEL
213 #if CONFIG_VP9_VDPAU_HWACCEL
216 #if CONFIG_VP9_VIDEOTOOLBOX_HWACCEL
219 #if CONFIG_VP9_VULKAN_HWACCEL
224 #if CONFIG_VP9_NVDEC_HWACCEL
227 #if CONFIG_VP9_NVDEC_CUARRAY_HWACCEL
230 #if CONFIG_VP9_VAAPI_HWACCEL
233 #if CONFIG_VP9_VDPAU_HWACCEL
236 #if CONFIG_VP9_VULKAN_HWACCEL
243 #if CONFIG_VP9_VAAPI_HWACCEL
246 #if CONFIG_VP9_VULKAN_HWACCEL
253 #if CONFIG_VP9_VAAPI_HWACCEL
256 #if CONFIG_VP9_VULKAN_HWACCEL
262 *fmtp++ =
s->pix_fmt;
272 s->gf_fmt =
s->pix_fmt;
280 if (
s->intra_pred_data[0] && cols ==
s->cols && rows ==
s->rows &&
s->pix_fmt ==
s->last_fmt)
283 s->last_fmt =
s->pix_fmt;
284 s->sb_cols = (
w + 63) >> 6;
285 s->sb_rows = (
h + 63) >> 6;
286 s->cols = (
w + 7) >> 3;
287 s->rows = (
h + 7) >> 3;
290 #define assign(var, type, n) var = (type) p; p += s->sb_cols * (n) * sizeof(*var)
294 p =
av_malloc(
s->sb_cols * (128 + 192 * bytesperpixel +
295 lflvl_len *
sizeof(*
s->lflvl) + 16 *
sizeof(*
s->above_mv_ctx)));
298 assign(
s->intra_pred_data[0], uint8_t *, 64 * bytesperpixel);
299 assign(
s->intra_pred_data[1], uint8_t *, 64 * bytesperpixel);
300 assign(
s->intra_pred_data[2], uint8_t *, 64 * bytesperpixel);
301 assign(
s->above_y_nnz_ctx, uint8_t *, 16);
302 assign(
s->above_mode_ctx, uint8_t *, 16);
304 assign(
s->above_uv_nnz_ctx[0], uint8_t *, 16);
305 assign(
s->above_uv_nnz_ctx[1], uint8_t *, 16);
306 assign(
s->above_partition_ctx, uint8_t *, 8);
307 assign(
s->above_skip_ctx, uint8_t *, 8);
308 assign(
s->above_txfm_ctx, uint8_t *, 8);
309 assign(
s->above_segpred_ctx, uint8_t *, 8);
310 assign(
s->above_intra_ctx, uint8_t *, 8);
311 assign(
s->above_comp_ctx, uint8_t *, 8);
312 assign(
s->above_ref_ctx, uint8_t *, 8);
313 assign(
s->above_filter_ctx, uint8_t *, 8);
318 for (
i = 0;
i <
s->active_tile_cols;
i++)
322 if (
s->s.h.bpp !=
s->last_bpp) {
325 s->last_bpp =
s->s.h.bpp;
336 int chroma_blocks, chroma_eobs, bytesperpixel =
s->bytesperpixel;
343 chroma_blocks = 64 * 64 >> (
s->ss_h +
s->ss_v);
344 chroma_eobs = 16 * 16 >> (
s->ss_h +
s->ss_v);
346 int sbs =
s->sb_cols *
s->sb_rows;
350 16 * 16 + 2 * chroma_eobs) * sbs);
365 for (
i = 1;
i <
s->active_tile_cols;
i++)
368 for (
i = 0;
i <
s->active_tile_cols;
i++) {
370 s->td[
i].block_base =
av_mallocz((64 * 64 + 2 * chroma_blocks) * bytesperpixel *
sizeof(int16_t) +
371 16 * 16 + 2 * chroma_eobs);
372 if (!
s->td[
i].b_base || !
s->td[
i].block_base)
374 s->td[
i].uvblock_base[0] =
s->td[
i].block_base + 64 * 64 * bytesperpixel;
375 s->td[
i].uvblock_base[1] =
s->td[
i].uvblock_base[0] + chroma_blocks * bytesperpixel;
376 s->td[
i].eob_base = (uint8_t *) (
s->td[
i].uvblock_base[1] + chroma_blocks * bytesperpixel);
377 s->td[
i].uveob_base[0] =
s->td[
i].eob_base + 16 * 16;
378 s->td[
i].uveob_base[1] =
s->td[
i].uveob_base[0] + chroma_eobs;
382 if (!
s->td[
i].block_structure)
387 s->block_alloc_using_2pass =
s->s.frames[
CUR_FRAME].uses_2pass;
404 return m - ((v + 1) >> 1);
411 static const uint8_t inv_map_table[255] = {
412 7, 20, 33, 46, 59, 72, 85, 98, 111, 124, 137, 150, 163, 176,
413 189, 202, 215, 228, 241, 254, 1, 2, 3, 4, 5, 6, 8, 9,
414 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24,
415 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39,
416 40, 41, 42, 43, 44, 45, 47, 48, 49, 50, 51, 52, 53, 54,
417 55, 56, 57, 58, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
418 70, 71, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
419 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 99, 100,
420 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 112, 113, 114, 115,
421 116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130,
422 131, 132, 133, 134, 135, 136, 138, 139, 140, 141, 142, 143, 144, 145,
423 146, 147, 148, 149, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
424 161, 162, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
425 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 190, 191,
426 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 203, 204, 205, 206,
427 207, 208, 209, 210, 211, 212, 213, 214, 216, 217, 218, 219, 220, 221,
428 222, 223, 224, 225, 226, 227, 229, 230, 231, 232, 233, 234, 235, 236,
429 237, 238, 239, 240, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251,
477 s->s.h.bpp = 8 +
bits * 2;
478 s->bytesperpixel = (7 +
s->s.h.bpp) >> 3;
484 s->ss_h =
s->ss_v = 0;
498 static const enum AVPixelFormat pix_fmt_for_ss[3][2 ][2 ] = {
510 s->pix_fmt = pix_fmt_for_ss[
bits][
s->ss_v][
s->ss_h];
521 s->ss_h =
s->ss_v = 1;
522 s->pix_fmt = pix_fmt_for_ss[
bits][1][1];
533 int c,
i, j, k, l, m, n,
w,
h,
max, size2,
ret, sharp;
535 const uint8_t *data2;
560 s->last_keyframe =
s->s.h.keyframe;
563 last_invisible =
s->s.h.invisible;
566 s->s.h.use_last_frame_mvs = !
s->s.h.errorres && !last_invisible;
568 if (
s->s.h.keyframe) {
576 s->s.h.refreshrefmask = 0xff;
582 s->s.h.intraonly =
s->s.h.invisible ?
get_bits1(&
s->gb) : 0;
583 s->s.h.resetctx =
s->s.h.errorres ? 0 :
get_bits(&
s->gb, 2);
584 if (
s->s.h.intraonly) {
593 s->ss_h =
s->ss_v = 1;
596 s->bytesperpixel = 1;
609 s->s.h.signbias[0] =
get_bits1(&
s->gb) && !
s->s.h.errorres;
611 s->s.h.signbias[1] =
get_bits1(&
s->gb) && !
s->s.h.errorres;
613 s->s.h.signbias[2] =
get_bits1(&
s->gb) && !
s->s.h.errorres;
614 if (!
s->s.refs[
s->s.h.refidx[0]].f ||
615 !
s->s.refs[
s->s.h.refidx[1]].f ||
616 !
s->s.refs[
s->s.h.refidx[2]].f) {
621 w =
s->s.refs[
s->s.h.refidx[0]].f->width;
622 h =
s->s.refs[
s->s.h.refidx[0]].f->height;
624 w =
s->s.refs[
s->s.h.refidx[1]].f->width;
625 h =
s->s.refs[
s->s.h.refidx[1]].f->height;
627 w =
s->s.refs[
s->s.h.refidx[2]].f->width;
628 h =
s->s.refs[
s->s.h.refidx[2]].f->height;
636 s->s.h.use_last_frame_mvs &=
s->s.frames[
CUR_FRAME].tf.f &&
644 s->s.h.allowcompinter =
s->s.h.signbias[0] !=
s->s.h.signbias[1] ||
645 s->s.h.signbias[0] !=
s->s.h.signbias[2];
646 if (
s->s.h.allowcompinter) {
647 if (
s->s.h.signbias[0] ==
s->s.h.signbias[1]) {
648 s->s.h.fixcompref = 2;
649 s->s.h.varcompref[0] = 0;
650 s->s.h.varcompref[1] = 1;
651 }
else if (
s->s.h.signbias[0] ==
s->s.h.signbias[2]) {
652 s->s.h.fixcompref = 1;
653 s->s.h.varcompref[0] = 0;
654 s->s.h.varcompref[1] = 2;
656 s->s.h.fixcompref = 0;
657 s->s.h.varcompref[0] = 1;
658 s->s.h.varcompref[1] = 2;
663 s->s.h.refreshctx =
s->s.h.errorres ? 0 :
get_bits1(&
s->gb);
664 s->s.h.parallelmode =
s->s.h.errorres ? 1 :
get_bits1(&
s->gb);
666 if (
s->s.h.keyframe ||
s->s.h.intraonly)
667 s->s.h.framectxid = 0;
670 if (
s->s.h.keyframe ||
s->s.h.errorres ||
s->s.h.intraonly) {
672 s->s.h.lf_delta.ref[0] = 1;
673 s->s.h.lf_delta.ref[1] = 0;
674 s->s.h.lf_delta.ref[2] = -1;
675 s->s.h.lf_delta.ref[3] = -1;
676 s->s.h.lf_delta.mode[0] = 0;
677 s->s.h.lf_delta.mode[1] = 0;
678 memset(
s->s.h.segmentation.feat, 0,
sizeof(
s->s.h.segmentation.feat));
684 if (
s->s.h.filter.sharpness != sharp) {
685 for (
i = 1;
i <= 63;
i++) {
689 limit >>= (sharp + 3) >> 2;
694 s->filter_lut.lim_lut[
i] =
limit;
695 s->filter_lut.mblim_lut[
i] = 2 * (
i + 2) +
limit;
698 s->s.h.filter.sharpness = sharp;
699 if ((
s->s.h.lf_delta.enabled =
get_bits1(&
s->gb))) {
700 if ((
s->s.h.lf_delta.updated =
get_bits1(&
s->gb))) {
701 for (
i = 0;
i < 4;
i++)
704 for (
i = 0;
i < 2;
i++)
715 s->s.h.lossless =
s->s.h.yac_qi == 0 &&
s->s.h.ydc_qdelta == 0 &&
716 s->s.h.uvdc_qdelta == 0 &&
s->s.h.uvac_qdelta == 0;
719 if ((
s->s.h.segmentation.enabled =
get_bits1(&
s->gb))) {
720 if ((
s->s.h.segmentation.update_map =
get_bits1(&
s->gb))) {
721 for (
i = 0;
i < 7;
i++)
724 if ((
s->s.h.segmentation.temporal =
get_bits1(&
s->gb)))
725 for (
i = 0;
i < 3;
i++)
731 s->s.h.segmentation.absolute_vals =
get_bits1(&
s->gb);
732 for (
i = 0;
i < 8;
i++) {
733 if ((
s->s.h.segmentation.feat[
i].q_enabled =
get_bits1(&
s->gb)))
735 if ((
s->s.h.segmentation.feat[
i].lf_enabled =
get_bits1(&
s->gb)))
737 if ((
s->s.h.segmentation.feat[
i].ref_enabled =
get_bits1(&
s->gb)))
738 s->s.h.segmentation.feat[
i].ref_val =
get_bits(&
s->gb, 2);
739 s->s.h.segmentation.feat[
i].skip_enabled =
get_bits1(&
s->gb);
746 s->s.h.segmentation.temporal = 0;
747 s->s.h.segmentation.update_map = 0;
751 for (
i = 0;
i < (
s->s.h.segmentation.enabled ? 8 : 1);
i++) {
752 int qyac, qydc, quvac, quvdc, lflvl, sh;
754 if (
s->s.h.segmentation.enabled &&
s->s.h.segmentation.feat[
i].q_enabled) {
755 if (
s->s.h.segmentation.absolute_vals)
760 qyac =
s->s.h.yac_qi;
772 sh =
s->s.h.filter.level >= 32;
773 if (
s->s.h.segmentation.enabled &&
s->s.h.segmentation.feat[
i].lf_enabled) {
774 if (
s->s.h.segmentation.absolute_vals)
777 lflvl =
av_clip_uintp2(
s->s.h.filter.level +
s->s.h.segmentation.feat[
i].lf_val, 6);
779 lflvl =
s->s.h.filter.level;
781 if (
s->s.h.lf_delta.enabled) {
782 s->s.h.segmentation.feat[
i].lflvl[0][0] =
783 s->s.h.segmentation.feat[
i].lflvl[0][1] =
785 for (j = 1; j < 4; j++) {
786 s->s.h.segmentation.feat[
i].lflvl[j][0] =
788 s->s.h.lf_delta.mode[0]) * (1 << sh)), 6);
789 s->s.h.segmentation.feat[
i].lflvl[j][1] =
791 s->s.h.lf_delta.mode[1]) * (1 << sh)), 6);
794 memset(
s->s.h.segmentation.feat[
i].lflvl, lflvl,
795 sizeof(
s->s.h.segmentation.feat[
i].lflvl));
805 for (
s->s.h.tiling.log2_tile_cols = 0;
806 s->sb_cols > (64 <<
s->s.h.tiling.log2_tile_cols);
807 s->s.h.tiling.log2_tile_cols++) ;
808 for (
max = 0; (
s->sb_cols >>
max) >= 4;
max++) ;
810 while (
max >
s->s.h.tiling.log2_tile_cols) {
812 s->s.h.tiling.log2_tile_cols++;
817 s->s.h.tiling.tile_rows = 1 <<
s->s.h.tiling.log2_tile_rows;
818 if (
s->s.h.tiling.tile_cols != (1 <<
s->s.h.tiling.log2_tile_cols) || changed) {
823 for (
i = 0;
i <
s->active_tile_cols;
i++)
828 s->s.h.tiling.tile_cols = 1 <<
s->s.h.tiling.log2_tile_cols;
830 s->s.h.tiling.tile_cols : 1;
835 n_range_coders =
s->s.h.tiling.tile_cols;
842 for (
i = 0;
i <
s->active_tile_cols;
i++) {
845 rc += n_range_coders;
850 if (!
s->s.h.keyframe && !
s->s.h.intraonly) {
851 int valid_ref_frame = 0;
852 for (
i = 0;
i < 3;
i++) {
854 int refw =
ref->width, refh =
ref->height;
858 "Ref pixfmt (%s) did not match current frame (%s)",
862 }
else if (refw ==
w && refh ==
h) {
863 s->mvscale[
i][0] =
s->mvscale[
i][1] = 0;
867 if (
w * 2 < refw ||
h * 2 < refh ||
w > 16 * refw ||
h > 16 * refh) {
869 "Invalid ref frame dimensions %dx%d for frame size %dx%d\n",
874 s->mvscale[
i][0] = (refw << 14) /
w;
875 s->mvscale[
i][1] = (refh << 14) /
h;
876 s->mvstep[
i][0] = 16 *
s->mvscale[
i][0] >> 14;
877 s->mvstep[
i][1] = 16 *
s->mvscale[
i][1] >> 14;
881 if (!valid_ref_frame) {
882 av_log(avctx,
AV_LOG_ERROR,
"No valid reference frame is found, bitstream not supported\n");
887 if (
s->s.h.keyframe ||
s->s.h.errorres || (
s->s.h.intraonly &&
s->s.h.resetctx == 3)) {
888 s->prob_ctx[0].p =
s->prob_ctx[1].p =
s->prob_ctx[2].p =
898 }
else if (
s->s.h.intraonly &&
s->s.h.resetctx == 2) {
905 s->s.h.compressed_header_size = size2 =
get_bits(&
s->gb, 16);
909 if (size2 >
size - (data2 -
data)) {
922 for (
i = 0;
i <
s->active_tile_cols;
i++) {
923 if (
s->s.h.keyframe ||
s->s.h.intraonly) {
924 memset(
s->td[
i].counts.coef, 0,
sizeof(
s->td[0].counts.coef));
925 memset(
s->td[
i].counts.eob, 0,
sizeof(
s->td[0].counts.eob));
927 memset(&
s->td[
i].counts, 0,
sizeof(
s->td[0].counts));
929 s->td[
i].nb_block_structure = 0;
935 s->prob.p =
s->prob_ctx[
c].p;
938 if (
s->s.h.lossless) {
942 if (
s->s.h.txfmmode == 3)
946 for (
i = 0;
i < 2;
i++)
949 for (
i = 0;
i < 2;
i++)
950 for (j = 0; j < 2; j++)
952 s->prob.p.tx16p[
i][j] =
954 for (
i = 0;
i < 2;
i++)
955 for (j = 0; j < 3; j++)
957 s->prob.p.tx32p[
i][j] =
963 for (
i = 0;
i < 4;
i++) {
964 uint8_t (*
ref)[2][6][6][3] =
s->prob_ctx[
c].coef[
i];
966 for (j = 0; j < 2; j++)
967 for (k = 0; k < 2; k++)
968 for (l = 0; l < 6; l++)
969 for (m = 0; m < 6; m++) {
970 uint8_t *
p =
s->prob.coef[
i][j][k][l][m];
971 uint8_t *
r =
ref[j][k][l][m];
972 if (m >= 3 && l == 0)
974 for (n = 0; n < 3; n++) {
983 for (j = 0; j < 2; j++)
984 for (k = 0; k < 2; k++)
985 for (l = 0; l < 6; l++)
986 for (m = 0; m < 6; m++) {
987 uint8_t *
p =
s->prob.coef[
i][j][k][l][m];
988 uint8_t *
r =
ref[j][k][l][m];
995 if (
s->s.h.txfmmode ==
i)
1000 for (
i = 0;
i < 3;
i++)
1003 if (!
s->s.h.keyframe && !
s->s.h.intraonly) {
1004 for (
i = 0;
i < 7;
i++)
1005 for (j = 0; j < 3; j++)
1007 s->prob.p.mv_mode[
i][j] =
1011 for (
i = 0;
i < 4;
i++)
1012 for (j = 0; j < 2; j++)
1014 s->prob.p.filter[
i][j] =
1017 for (
i = 0;
i < 4;
i++)
1021 if (
s->s.h.allowcompinter) {
1023 if (
s->s.h.comppredmode)
1026 for (
i = 0;
i < 5;
i++)
1035 for (
i = 0;
i < 5;
i++) {
1037 s->prob.p.single_ref[
i][0] =
1040 s->prob.p.single_ref[
i][1] =
1046 for (
i = 0;
i < 5;
i++)
1048 s->prob.p.comp_ref[
i] =
1052 for (
i = 0;
i < 4;
i++)
1053 for (j = 0; j < 9; j++)
1055 s->prob.p.y_mode[
i][j] =
1058 for (
i = 0;
i < 4;
i++)
1059 for (j = 0; j < 4; j++)
1060 for (k = 0; k < 3; k++)
1062 s->prob.p.partition[3 -
i][j][k] =
1064 s->prob.p.partition[3 -
i][j][k]);
1067 for (
i = 0;
i < 3;
i++)
1071 for (
i = 0;
i < 2;
i++) {
1073 s->prob.p.mv_comp[
i].sign =
1076 for (j = 0; j < 10; j++)
1078 s->prob.p.mv_comp[
i].classes[j] =
1082 s->prob.p.mv_comp[
i].class0 =
1085 for (j = 0; j < 10; j++)
1087 s->prob.p.mv_comp[
i].bits[j] =
1091 for (
i = 0;
i < 2;
i++) {
1092 for (j = 0; j < 2; j++)
1093 for (k = 0; k < 3; k++)
1095 s->prob.p.mv_comp[
i].class0_fp[j][k] =
1098 for (j = 0; j < 3; j++)
1100 s->prob.p.mv_comp[
i].fp[j] =
1104 if (
s->s.h.highprecisionmvs) {
1105 for (
i = 0;
i < 2;
i++) {
1107 s->prob.p.mv_comp[
i].class0_hp =
1111 s->prob.p.mv_comp[
i].hp =
1117 return (data2 -
data) + size2;
1121 ptrdiff_t yoff, ptrdiff_t uvoff,
enum BlockLevel bl)
1124 int c = ((
s->above_partition_ctx[col] >> (3 - bl)) & 1) |
1127 s->prob.p.partition[bl][
c];
1129 ptrdiff_t hbs = 4 >> bl;
1131 ptrdiff_t y_stride =
f->linesize[0], uv_stride =
f->linesize[1];
1132 int bytesperpixel =
s->bytesperpixel;
1137 }
else if (col + hbs < s->cols) {
1138 if (row + hbs < s->rows) {
1146 yoff += hbs * 8 * y_stride;
1147 uvoff += hbs * 8 * uv_stride >>
s->ss_v;
1152 yoff += hbs * 8 * bytesperpixel;
1153 uvoff += hbs * 8 * bytesperpixel >>
s->ss_h;
1157 decode_sb(td, row, col, lflvl, yoff, uvoff, bl + 1);
1159 yoff + 8 * hbs * bytesperpixel,
1160 uvoff + (8 * hbs * bytesperpixel >>
s->ss_h), bl + 1);
1161 yoff += hbs * 8 * y_stride;
1162 uvoff += hbs * 8 * uv_stride >>
s->ss_v;
1163 decode_sb(td, row + hbs, col, lflvl, yoff, uvoff, bl + 1);
1164 decode_sb(td, row + hbs, col + hbs, lflvl,
1165 yoff + 8 * hbs * bytesperpixel,
1166 uvoff + (8 * hbs * bytesperpixel >>
s->ss_h), bl + 1);
1170 "the four PARTITION_* terminal codes");
1174 decode_sb(td, row, col, lflvl, yoff, uvoff, bl + 1);
1176 yoff + 8 * hbs * bytesperpixel,
1177 uvoff + (8 * hbs * bytesperpixel >>
s->ss_h), bl + 1);
1182 }
else if (row + hbs < s->rows) {
1185 decode_sb(td, row, col, lflvl, yoff, uvoff, bl + 1);
1186 yoff += hbs * 8 * y_stride;
1187 uvoff += hbs * 8 * uv_stride >>
s->ss_v;
1188 decode_sb(td, row + hbs, col, lflvl, yoff, uvoff, bl + 1);
1195 decode_sb(td, row, col, lflvl, yoff, uvoff, bl + 1);
1201 ptrdiff_t yoff, ptrdiff_t uvoff,
enum BlockLevel bl)
1205 ptrdiff_t hbs = 4 >> bl;
1207 ptrdiff_t y_stride =
f->linesize[0], uv_stride =
f->linesize[1];
1208 int bytesperpixel =
s->bytesperpixel;
1213 }
else if (td->
b->
bl == bl) {
1216 yoff += hbs * 8 * y_stride;
1217 uvoff += hbs * 8 * uv_stride >>
s->ss_v;
1219 }
else if (
b->bp ==
PARTITION_V && col + hbs < s->cols) {
1220 yoff += hbs * 8 * bytesperpixel;
1221 uvoff += hbs * 8 * bytesperpixel >>
s->ss_h;
1226 if (col + hbs < s->cols) {
1227 if (row + hbs < s->rows) {
1228 decode_sb_mem(td, row, col + hbs, lflvl, yoff + 8 * hbs * bytesperpixel,
1229 uvoff + (8 * hbs * bytesperpixel >>
s->ss_h), bl + 1);
1230 yoff += hbs * 8 * y_stride;
1231 uvoff += hbs * 8 * uv_stride >>
s->ss_v;
1232 decode_sb_mem(td, row + hbs, col, lflvl, yoff, uvoff, bl + 1);
1234 yoff + 8 * hbs * bytesperpixel,
1235 uvoff + (8 * hbs * bytesperpixel >>
s->ss_h), bl + 1);
1237 yoff += hbs * 8 * bytesperpixel;
1238 uvoff += hbs * 8 * bytesperpixel >>
s->ss_h;
1239 decode_sb_mem(td, row, col + hbs, lflvl, yoff, uvoff, bl + 1);
1241 }
else if (row + hbs < s->rows) {
1242 yoff += hbs * 8 * y_stride;
1243 uvoff += hbs * 8 * uv_stride >>
s->ss_v;
1244 decode_sb_mem(td, row + hbs, col, lflvl, yoff, uvoff, bl + 1);
1251 int sb_start = ( idx * n) >> log2_n;
1252 int sb_end = ((idx + 1) * n) >> log2_n;
1253 *start =
FFMIN(sb_start, n) << 3;
1254 *end =
FFMIN(sb_end, n) << 3;
1262 for (
i = 0;
i <
s->active_tile_cols;
i++)
1271 for (
int i = 0;
i < 3;
i++)
1274 for (
i = 0;
i < 8;
i++) {
1287 ff_cbs_fragment_free(&
s->current_frag);
1288 ff_cbs_close(&
s->cbc);
1299 int row, col, tile_row, tile_col,
ret;
1301 int tile_row_start, tile_row_end, tile_col_start, tile_col_end;
1303 ptrdiff_t yoff, uvoff, ls_y, ls_uv;
1306 ls_y =
f->linesize[0];
1307 ls_uv =
f->linesize[1];
1308 bytesperpixel =
s->bytesperpixel;
1311 for (tile_row = 0; tile_row <
s->s.h.tiling.tile_rows; tile_row++) {
1313 tile_row,
s->s.h.tiling.log2_tile_rows,
s->sb_rows);
1315 for (tile_col = 0; tile_col <
s->s.h.tiling.tile_cols; tile_col++) {
1318 if (tile_col ==
s->s.h.tiling.tile_cols - 1 &&
1319 tile_row ==
s->s.h.tiling.tile_rows - 1) {
1326 if (tile_size >
size)
1337 for (row = tile_row_start; row < tile_row_end;
1338 row += 8, yoff += ls_y * 64, uvoff += ls_uv * 64 >>
s->ss_v) {
1340 ptrdiff_t yoff2 = yoff, uvoff2 = uvoff;
1342 for (tile_col = 0; tile_col <
s->s.h.tiling.tile_cols; tile_col++) {
1344 tile_col,
s->s.h.tiling.log2_tile_cols,
s->sb_cols);
1349 if (
s->s.h.keyframe ||
s->s.h.intraonly) {
1358 td->
c = &td->
c_b[tile_col];
1361 for (col = tile_col_start;
1363 col += 8, yoff2 += 64 * bytesperpixel,
1364 uvoff2 += 64 * bytesperpixel >>
s->ss_h, lflvl_ptr++) {
1368 memset(lflvl_ptr->
mask, 0,
sizeof(lflvl_ptr->
mask));
1389 if (row + 8 <
s->rows) {
1390 memcpy(
s->intra_pred_data[0],
1391 f->data[0] + yoff + 63 * ls_y,
1392 8 *
s->cols * bytesperpixel);
1393 memcpy(
s->intra_pred_data[1],
1394 f->data[1] + uvoff + ((64 >>
s->ss_v) - 1) * ls_uv,
1395 8 *
s->cols * bytesperpixel >>
s->ss_h);
1396 memcpy(
s->intra_pred_data[2],
1397 f->data[2] + uvoff + ((64 >>
s->ss_v) - 1) * ls_uv,
1398 8 *
s->cols * bytesperpixel >>
s->ss_h);
1402 if (
s->s.h.filter.level) {
1405 lflvl_ptr =
s->lflvl;
1406 for (col = 0; col <
s->cols;
1407 col += 8, yoff2 += 64 * bytesperpixel,
1408 uvoff2 += 64 * bytesperpixel >>
s->ss_h, lflvl_ptr++) {
1425 int decode_tiles_mt(
AVCodecContext *avctx,
void *tdata,
int jobnr,
1430 ptrdiff_t uvoff, yoff, ls_y, ls_uv;
1431 int bytesperpixel =
s->bytesperpixel, row, col, tile_row;
1432 unsigned tile_cols_len;
1433 int tile_row_start, tile_row_end, tile_col_start, tile_col_end;
1438 ls_y =
f->linesize[0];
1439 ls_uv =
f->linesize[1];
1442 jobnr,
s->s.h.tiling.log2_tile_cols,
s->sb_cols);
1444 uvoff = (64 * bytesperpixel >>
s->ss_h)*(tile_col_start >> 3);
1445 yoff = (64 * bytesperpixel)*(tile_col_start >> 3);
1446 lflvl_ptr_base =
s->lflvl+(tile_col_start >> 3);
1448 for (tile_row = 0; tile_row <
s->s.h.tiling.tile_rows; tile_row++) {
1450 tile_row,
s->s.h.tiling.log2_tile_rows,
s->sb_rows);
1452 td->
c = &td->
c_b[tile_row];
1453 for (row = tile_row_start; row < tile_row_end;
1454 row += 8, yoff += ls_y * 64, uvoff += ls_uv * 64 >>
s->ss_v) {
1455 ptrdiff_t yoff2 = yoff, uvoff2 = uvoff;
1456 VP9Filter *lflvl_ptr = lflvl_ptr_base+
s->sb_cols*(row >> 3);
1460 if (
s->s.h.keyframe ||
s->s.h.intraonly) {
1469 for (col = tile_col_start;
1471 col += 8, yoff2 += 64 * bytesperpixel,
1472 uvoff2 += 64 * bytesperpixel >>
s->ss_h, lflvl_ptr++) {
1475 memset(lflvl_ptr->
mask, 0,
sizeof(lflvl_ptr->
mask));
1482 tile_cols_len = tile_col_end - tile_col_start;
1483 if (row + 8 <
s->rows) {
1484 memcpy(
s->intra_pred_data[0] + (tile_col_start * 8 * bytesperpixel),
1485 f->data[0] + yoff + 63 * ls_y,
1486 8 * tile_cols_len * bytesperpixel);
1487 memcpy(
s->intra_pred_data[1] + (tile_col_start * 8 * bytesperpixel >>
s->ss_h),
1488 f->data[1] + uvoff + ((64 >>
s->ss_v) - 1) * ls_uv,
1489 8 * tile_cols_len * bytesperpixel >>
s->ss_h);
1490 memcpy(
s->intra_pred_data[2] + (tile_col_start * 8 * bytesperpixel >>
s->ss_h),
1491 f->data[2] + uvoff + ((64 >>
s->ss_v) - 1) * ls_uv,
1492 8 * tile_cols_len * bytesperpixel >>
s->ss_h);
1495 vp9_report_tile_progress(
s, row >> 3, 1);
1505 ptrdiff_t uvoff, yoff, ls_y, ls_uv;
1507 int bytesperpixel =
s->bytesperpixel, col,
i;
1511 ls_y =
f->linesize[0];
1512 ls_uv =
f->linesize[1];
1514 for (
i = 0;
i <
s->sb_rows;
i++) {
1515 vp9_await_tile_progress(
s,
i,
s->s.h.tiling.tile_cols);
1517 if (
s->s.h.filter.level) {
1518 yoff = (ls_y * 64)*
i;
1519 uvoff = (ls_uv * 64 >>
s->ss_v)*
i;
1520 lflvl_ptr =
s->lflvl+
s->sb_cols*
i;
1521 for (col = 0; col <
s->cols;
1522 col += 8, yoff += 64 * bytesperpixel,
1523 uvoff += 64 * bytesperpixel >>
s->ss_h, lflvl_ptr++) {
1536 unsigned int tile, nb_blocks = 0;
1538 if (
s->s.h.segmentation.enabled) {
1540 nb_blocks +=
s->td[
tile].nb_block_structure;
1548 par->
qp =
s->s.h.yac_qi;
1549 par->
delta_qp[0][0] =
s->s.h.ydc_qdelta;
1550 par->
delta_qp[1][0] =
s->s.h.uvdc_qdelta;
1551 par->
delta_qp[2][0] =
s->s.h.uvdc_qdelta;
1552 par->
delta_qp[1][1] =
s->s.h.uvac_qdelta;
1553 par->
delta_qp[2][1] =
s->s.h.uvac_qdelta;
1556 unsigned int block = 0;
1557 unsigned int tile, block_tile;
1566 uint8_t seg_id =
frame->segmentation_map[row * 8 *
s->sb_cols + col];
1573 if (
s->s.h.segmentation.feat[seg_id].q_enabled) {
1574 b->delta_qp =
s->s.h.segmentation.feat[seg_id].q_val;
1575 if (
s->s.h.segmentation.absolute_vals)
1576 b->delta_qp -= par->
qp;
1594 if (!sd || sd_size < 8 ||
AV_RB64(sd) != 1)
1598 &
s->webm_alpha_warned,
1599 "Ignoring unsupported WebM alpha channel side data; use the "
1600 "libvpx-vp9 decoder to decode it.\n");
1614 (!
s->s.h.segmentation.enabled || !
s->s.h.segmentation.update_map);
1620 ret = ff_cbs_read_packet(
s->cbc, &
s->current_frag,
pkt);
1622 ff_cbs_fragment_reset(&
s->current_frag);
1627 unit = &
s->current_frag.units[0];
1631 s->frame_header = &rf->
header;
1634 ff_cbs_fragment_reset(&
s->current_frag);
1636 }
else if (
ret == 0) {
1637 if (!
s->s.refs[
ref].f) {
1639 ff_cbs_fragment_reset(&
s->current_frag);
1642 for (
int i = 0;
i < 8;
i++)
1646 ff_cbs_fragment_reset(&
s->current_frag);
1658 src = !
s->s.h.keyframe && !
s->s.h.intraonly && !
s->s.h.errorres ?
1660 if (!retain_segmap_ref ||
s->s.h.keyframe ||
s->s.h.intraonly)
1665 ff_cbs_fragment_reset(&
s->current_frag);
1670 s->s.frames[
CUR_FRAME].frame_header =
s->frame_header;
1673 if (
s->s.h.keyframe)
1677 if (
s->s.h.lossless)
1691 for (
i = 0;
i < 8;
i++) {
1693 s->s.h.refreshrefmask & (1 <<
i) ?
1709 for (
i = 0;
i < 8;
i++) {
1711 s->s.h.refreshrefmask & (1 <<
i) ?
1719 memset(
s->above_partition_ctx, 0,
s->cols);
1720 memset(
s->above_skip_ctx, 0,
s->cols);
1721 if (
s->s.h.keyframe ||
s->s.h.intraonly) {
1722 memset(
s->above_mode_ctx,
DC_PRED,
s->cols * 2);
1726 memset(
s->above_y_nnz_ctx, 0,
s->sb_cols * 16);
1727 memset(
s->above_uv_nnz_ctx[0], 0,
s->sb_cols * 16 >>
s->ss_h);
1728 memset(
s->above_uv_nnz_ctx[1], 0,
s->sb_cols * 16 >>
s->ss_h);
1729 memset(
s->above_segpred_ctx, 0,
s->cols);
1734 "Failed to allocate block buffers\n");
1737 if (
s->s.h.refreshctx &&
s->s.h.parallelmode) {
1740 for (
i = 0;
i < 4;
i++) {
1741 for (j = 0; j < 2; j++)
1742 for (k = 0; k < 2; k++)
1743 for (l = 0; l < 6; l++)
1744 for (m = 0; m < 6; m++)
1745 memcpy(
s->prob_ctx[
s->s.h.framectxid].coef[
i][j][k][l][m],
1746 s->prob.coef[
i][j][k][l][m], 3);
1747 if (
s->s.h.txfmmode ==
i)
1750 s->prob_ctx[
s->s.h.framectxid].p =
s->prob.p;
1752 }
else if (!
s->s.h.refreshctx) {
1758 for (
i = 0;
i <
s->sb_rows;
i++)
1764 for (
i = 0;
i <
s->active_tile_cols;
i++) {
1765 s->td[
i].b =
s->td[
i].b_base;
1766 s->td[
i].block =
s->td[
i].block_base;
1767 s->td[
i].uvblock[0] =
s->td[
i].uvblock_base[0];
1768 s->td[
i].uvblock[1] =
s->td[
i].uvblock_base[1];
1769 s->td[
i].eob =
s->td[
i].eob_base;
1770 s->td[
i].uveob[0] =
s->td[
i].uveob_base[0];
1771 s->td[
i].uveob[1] =
s->td[
i].uveob_base[1];
1772 s->td[
i].error_info = 0;
1777 int tile_row, tile_col;
1781 for (tile_row = 0; tile_row <
s->s.h.tiling.tile_rows; tile_row++) {
1782 for (tile_col = 0; tile_col <
s->s.h.tiling.tile_cols; tile_col++) {
1785 if (tile_col ==
s->s.h.tiling.tile_cols - 1 &&
1786 tile_row ==
s->s.h.tiling.tile_rows - 1) {
1793 if (tile_size >
size)
1816 for (
i = 1;
i <
s->s.h.tiling.tile_cols;
i++)
1817 for (j = 0; j <
sizeof(
s->td[
i].counts) /
sizeof(
unsigned); j++)
1818 ((
unsigned *)&
s->td[0].counts)[j] += ((
unsigned *)&
s->td[
i].counts)[j];
1820 if (
s->pass < 2 &&
s->s.h.refreshctx && !
s->s.h.parallelmode) {
1824 }
while (
s->pass++ == 1);
1826 if (
s->td->error_info < 0) {
1828 s->td->error_info = 0;
1839 ff_cbs_fragment_reset(&
s->current_frag);
1843 for (
int i = 0;
i < 8;
i++)
1846 if (!
s->s.h.invisible) {
1854 ff_cbs_fragment_reset(&
s->current_frag);
1864 for (
i = 0;
i < 3;
i++)
1867 for (
i = 0;
i < 8;
i++) {
1872 ff_cbs_fragment_reset(&
s->current_frag);
1873 ff_cbs_flush(
s->cbc);
1885 s->s.h.filter.sharpness = -1;
1907 for (
int i = 0;
i < 3;
i++)
1909 for (
int i = 0;
i < 8;
i++)
1912 s->frame_extradata_pool_size = ssrc->frame_extradata_pool_size;
1915 for (
int i = 0;
i < 8;
i++)
1918 s->frame_header = ssrc->frame_header;
1921 s->s.h.invisible = ssrc->s.h.invisible;
1922 s->s.h.keyframe = ssrc->s.h.keyframe;
1923 s->s.h.intraonly = ssrc->s.h.intraonly;
1924 s->ss_v = ssrc->ss_v;
1925 s->ss_h = ssrc->ss_h;
1926 s->s.h.segmentation.enabled = ssrc->s.h.segmentation.enabled;
1927 s->s.h.segmentation.update_map = ssrc->s.h.segmentation.update_map;
1928 s->s.h.segmentation.absolute_vals = ssrc->s.h.segmentation.absolute_vals;
1929 s->bytesperpixel = ssrc->bytesperpixel;
1930 s->gf_fmt = ssrc->gf_fmt;
1933 s->s.h.bpp = ssrc->s.h.bpp;
1934 s->bpp_index = ssrc->bpp_index;
1935 s->pix_fmt = ssrc->pix_fmt;
1936 s->webm_alpha_warned = ssrc->webm_alpha_warned;
1937 memcpy(&
s->prob_ctx, &ssrc->prob_ctx,
sizeof(
s->prob_ctx));
1938 memcpy(&
s->s.h.lf_delta, &ssrc->s.h.lf_delta,
sizeof(
s->s.h.lf_delta));
1939 memcpy(&
s->s.h.segmentation.feat, &ssrc->s.h.segmentation.feat,
1940 sizeof(
s->s.h.segmentation.feat));
1962 .bsfs =
"vp9_superframe_split",
1964 #if CONFIG_VP9_DXVA2_HWACCEL
1967 #if CONFIG_VP9_D3D11VA_HWACCEL
1970 #if CONFIG_VP9_D3D11VA2_HWACCEL
1973 #if CONFIG_VP9_D3D12VA_HWACCEL
1976 #if CONFIG_VP9_NVDEC_HWACCEL
1979 #if CONFIG_VP9_NVDEC_CUARRAY_HWACCEL
1982 #if CONFIG_VP9_VAAPI_HWACCEL
1985 #if CONFIG_VP9_VDPAU_HWACCEL
1988 #if CONFIG_VP9_VIDEOTOOLBOX_HWACCEL
1991 #if CONFIG_VP9_VULKAN_HWACCEL