24 #include "config_components.h"
50 #define VP9_SYNCCODE 0x498342
104 f->segmentation_map =
NULL;
116 sz = 64 *
s->sb_cols *
s->sb_rows;
117 if (sz !=
s->frame_extradata_pool_size) {
121 if (!
s->frame_extradata_pool) {
122 s->frame_extradata_pool_size = 0;
126 s->frame_extradata_pool_size = sz;
134 f->segmentation_map =
f->extradata;
151 dst->frame_header =
src->frame_header;
157 dst->segmentation_map =
src->segmentation_map;
159 dst->uses_2pass =
src->uses_2pass;
162 src->hwaccel_picture_private);
167 #define HWACCEL_MAX (CONFIG_VP9_DXVA2_HWACCEL + \
168 CONFIG_VP9_D3D11VA_HWACCEL * 2 + \
169 CONFIG_VP9_D3D12VA_HWACCEL + \
170 CONFIG_VP9_NVDEC_HWACCEL + \
171 CONFIG_VP9_NVDEC_CUARRAY_HWACCEL + \
172 CONFIG_VP9_VAAPI_HWACCEL + \
173 CONFIG_VP9_VDPAU_HWACCEL + \
174 CONFIG_VP9_VIDEOTOOLBOX_HWACCEL + \
175 CONFIG_VP9_VULKAN_HWACCEL)
179 int bytesperpixel =
s->bytesperpixel,
ret, cols, rows;
185 if (!(
s->pix_fmt ==
s->gf_fmt &&
w ==
s->w &&
h ==
s->h)) {
190 switch (
s->pix_fmt) {
193 #if CONFIG_VP9_DXVA2_HWACCEL
196 #if CONFIG_VP9_D3D11VA_HWACCEL
200 #if CONFIG_VP9_D3D12VA_HWACCEL
203 #if CONFIG_VP9_NVDEC_HWACCEL
206 #if CONFIG_VP9_NVDEC_CUARRAY_HWACCEL
209 #if CONFIG_VP9_VAAPI_HWACCEL
212 #if CONFIG_VP9_VDPAU_HWACCEL
215 #if CONFIG_VP9_VIDEOTOOLBOX_HWACCEL
218 #if CONFIG_VP9_VULKAN_HWACCEL
223 #if CONFIG_VP9_NVDEC_HWACCEL
226 #if CONFIG_VP9_NVDEC_CUARRAY_HWACCEL
229 #if CONFIG_VP9_VAAPI_HWACCEL
232 #if CONFIG_VP9_VDPAU_HWACCEL
235 #if CONFIG_VP9_VULKAN_HWACCEL
242 #if CONFIG_VP9_VAAPI_HWACCEL
245 #if CONFIG_VP9_VULKAN_HWACCEL
252 #if CONFIG_VP9_VAAPI_HWACCEL
255 #if CONFIG_VP9_VULKAN_HWACCEL
261 *fmtp++ =
s->pix_fmt;
271 s->gf_fmt =
s->pix_fmt;
279 if (
s->intra_pred_data[0] && cols ==
s->cols && rows ==
s->rows &&
s->pix_fmt ==
s->last_fmt)
282 s->last_fmt =
s->pix_fmt;
283 s->sb_cols = (
w + 63) >> 6;
284 s->sb_rows = (
h + 63) >> 6;
285 s->cols = (
w + 7) >> 3;
286 s->rows = (
h + 7) >> 3;
289 #define assign(var, type, n) var = (type) p; p += s->sb_cols * (n) * sizeof(*var)
293 p =
av_malloc(
s->sb_cols * (128 + 192 * bytesperpixel +
294 lflvl_len *
sizeof(*
s->lflvl) + 16 *
sizeof(*
s->above_mv_ctx)));
297 assign(
s->intra_pred_data[0], uint8_t *, 64 * bytesperpixel);
298 assign(
s->intra_pred_data[1], uint8_t *, 64 * bytesperpixel);
299 assign(
s->intra_pred_data[2], uint8_t *, 64 * bytesperpixel);
300 assign(
s->above_y_nnz_ctx, uint8_t *, 16);
301 assign(
s->above_mode_ctx, uint8_t *, 16);
303 assign(
s->above_uv_nnz_ctx[0], uint8_t *, 16);
304 assign(
s->above_uv_nnz_ctx[1], uint8_t *, 16);
305 assign(
s->above_partition_ctx, uint8_t *, 8);
306 assign(
s->above_skip_ctx, uint8_t *, 8);
307 assign(
s->above_txfm_ctx, uint8_t *, 8);
308 assign(
s->above_segpred_ctx, uint8_t *, 8);
309 assign(
s->above_intra_ctx, uint8_t *, 8);
310 assign(
s->above_comp_ctx, uint8_t *, 8);
311 assign(
s->above_ref_ctx, uint8_t *, 8);
312 assign(
s->above_filter_ctx, uint8_t *, 8);
317 for (
i = 0;
i <
s->active_tile_cols;
i++)
321 if (
s->s.h.bpp !=
s->last_bpp) {
324 s->last_bpp =
s->s.h.bpp;
335 int chroma_blocks, chroma_eobs, bytesperpixel =
s->bytesperpixel;
342 chroma_blocks = 64 * 64 >> (
s->ss_h +
s->ss_v);
343 chroma_eobs = 16 * 16 >> (
s->ss_h +
s->ss_v);
345 int sbs =
s->sb_cols *
s->sb_rows;
349 16 * 16 + 2 * chroma_eobs) * sbs);
364 for (
i = 1;
i <
s->active_tile_cols;
i++)
367 for (
i = 0;
i <
s->active_tile_cols;
i++) {
369 s->td[
i].block_base =
av_mallocz((64 * 64 + 2 * chroma_blocks) * bytesperpixel *
sizeof(int16_t) +
370 16 * 16 + 2 * chroma_eobs);
371 if (!
s->td[
i].b_base || !
s->td[
i].block_base)
373 s->td[
i].uvblock_base[0] =
s->td[
i].block_base + 64 * 64 * bytesperpixel;
374 s->td[
i].uvblock_base[1] =
s->td[
i].uvblock_base[0] + chroma_blocks * bytesperpixel;
375 s->td[
i].eob_base = (uint8_t *) (
s->td[
i].uvblock_base[1] + chroma_blocks * bytesperpixel);
376 s->td[
i].uveob_base[0] =
s->td[
i].eob_base + 16 * 16;
377 s->td[
i].uveob_base[1] =
s->td[
i].uveob_base[0] + chroma_eobs;
381 if (!
s->td[
i].block_structure)
386 s->block_alloc_using_2pass =
s->s.frames[
CUR_FRAME].uses_2pass;
403 return m - ((v + 1) >> 1);
410 static const uint8_t inv_map_table[255] = {
411 7, 20, 33, 46, 59, 72, 85, 98, 111, 124, 137, 150, 163, 176,
412 189, 202, 215, 228, 241, 254, 1, 2, 3, 4, 5, 6, 8, 9,
413 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24,
414 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39,
415 40, 41, 42, 43, 44, 45, 47, 48, 49, 50, 51, 52, 53, 54,
416 55, 56, 57, 58, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
417 70, 71, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
418 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 99, 100,
419 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 112, 113, 114, 115,
420 116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130,
421 131, 132, 133, 134, 135, 136, 138, 139, 140, 141, 142, 143, 144, 145,
422 146, 147, 148, 149, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
423 161, 162, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
424 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 190, 191,
425 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 203, 204, 205, 206,
426 207, 208, 209, 210, 211, 212, 213, 214, 216, 217, 218, 219, 220, 221,
427 222, 223, 224, 225, 226, 227, 229, 230, 231, 232, 233, 234, 235, 236,
428 237, 238, 239, 240, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251,
476 s->s.h.bpp = 8 +
bits * 2;
477 s->bytesperpixel = (7 +
s->s.h.bpp) >> 3;
483 s->ss_h =
s->ss_v = 0;
497 static const enum AVPixelFormat pix_fmt_for_ss[3][2 ][2 ] = {
509 s->pix_fmt = pix_fmt_for_ss[
bits][
s->ss_v][
s->ss_h];
520 s->ss_h =
s->ss_v = 1;
521 s->pix_fmt = pix_fmt_for_ss[
bits][1][1];
532 int c,
i, j, k, l, m, n,
w,
h,
max, size2,
ret, sharp;
534 const uint8_t *data2;
559 s->last_keyframe =
s->s.h.keyframe;
562 last_invisible =
s->s.h.invisible;
565 s->s.h.use_last_frame_mvs = !
s->s.h.errorres && !last_invisible;
567 if (
s->s.h.keyframe) {
575 s->s.h.refreshrefmask = 0xff;
581 s->s.h.intraonly =
s->s.h.invisible ?
get_bits1(&
s->gb) : 0;
582 s->s.h.resetctx =
s->s.h.errorres ? 0 :
get_bits(&
s->gb, 2);
583 if (
s->s.h.intraonly) {
592 s->ss_h =
s->ss_v = 1;
595 s->bytesperpixel = 1;
608 s->s.h.signbias[0] =
get_bits1(&
s->gb) && !
s->s.h.errorres;
610 s->s.h.signbias[1] =
get_bits1(&
s->gb) && !
s->s.h.errorres;
612 s->s.h.signbias[2] =
get_bits1(&
s->gb) && !
s->s.h.errorres;
613 if (!
s->s.refs[
s->s.h.refidx[0]].f ||
614 !
s->s.refs[
s->s.h.refidx[1]].f ||
615 !
s->s.refs[
s->s.h.refidx[2]].f) {
620 w =
s->s.refs[
s->s.h.refidx[0]].f->width;
621 h =
s->s.refs[
s->s.h.refidx[0]].f->height;
623 w =
s->s.refs[
s->s.h.refidx[1]].f->width;
624 h =
s->s.refs[
s->s.h.refidx[1]].f->height;
626 w =
s->s.refs[
s->s.h.refidx[2]].f->width;
627 h =
s->s.refs[
s->s.h.refidx[2]].f->height;
635 s->s.h.use_last_frame_mvs &=
s->s.frames[
CUR_FRAME].tf.f &&
643 s->s.h.allowcompinter =
s->s.h.signbias[0] !=
s->s.h.signbias[1] ||
644 s->s.h.signbias[0] !=
s->s.h.signbias[2];
645 if (
s->s.h.allowcompinter) {
646 if (
s->s.h.signbias[0] ==
s->s.h.signbias[1]) {
647 s->s.h.fixcompref = 2;
648 s->s.h.varcompref[0] = 0;
649 s->s.h.varcompref[1] = 1;
650 }
else if (
s->s.h.signbias[0] ==
s->s.h.signbias[2]) {
651 s->s.h.fixcompref = 1;
652 s->s.h.varcompref[0] = 0;
653 s->s.h.varcompref[1] = 2;
655 s->s.h.fixcompref = 0;
656 s->s.h.varcompref[0] = 1;
657 s->s.h.varcompref[1] = 2;
662 s->s.h.refreshctx =
s->s.h.errorres ? 0 :
get_bits1(&
s->gb);
663 s->s.h.parallelmode =
s->s.h.errorres ? 1 :
get_bits1(&
s->gb);
665 if (
s->s.h.keyframe ||
s->s.h.intraonly)
666 s->s.h.framectxid = 0;
669 if (
s->s.h.keyframe ||
s->s.h.errorres ||
s->s.h.intraonly) {
671 s->s.h.lf_delta.ref[0] = 1;
672 s->s.h.lf_delta.ref[1] = 0;
673 s->s.h.lf_delta.ref[2] = -1;
674 s->s.h.lf_delta.ref[3] = -1;
675 s->s.h.lf_delta.mode[0] = 0;
676 s->s.h.lf_delta.mode[1] = 0;
677 memset(
s->s.h.segmentation.feat, 0,
sizeof(
s->s.h.segmentation.feat));
683 if (
s->s.h.filter.sharpness != sharp) {
684 for (
i = 1;
i <= 63;
i++) {
688 limit >>= (sharp + 3) >> 2;
693 s->filter_lut.lim_lut[
i] =
limit;
694 s->filter_lut.mblim_lut[
i] = 2 * (
i + 2) +
limit;
697 s->s.h.filter.sharpness = sharp;
698 if ((
s->s.h.lf_delta.enabled =
get_bits1(&
s->gb))) {
699 if ((
s->s.h.lf_delta.updated =
get_bits1(&
s->gb))) {
700 for (
i = 0;
i < 4;
i++)
703 for (
i = 0;
i < 2;
i++)
714 s->s.h.lossless =
s->s.h.yac_qi == 0 &&
s->s.h.ydc_qdelta == 0 &&
715 s->s.h.uvdc_qdelta == 0 &&
s->s.h.uvac_qdelta == 0;
718 if ((
s->s.h.segmentation.enabled =
get_bits1(&
s->gb))) {
719 if ((
s->s.h.segmentation.update_map =
get_bits1(&
s->gb))) {
720 for (
i = 0;
i < 7;
i++)
723 if ((
s->s.h.segmentation.temporal =
get_bits1(&
s->gb)))
724 for (
i = 0;
i < 3;
i++)
730 s->s.h.segmentation.absolute_vals =
get_bits1(&
s->gb);
731 for (
i = 0;
i < 8;
i++) {
732 if ((
s->s.h.segmentation.feat[
i].q_enabled =
get_bits1(&
s->gb)))
734 if ((
s->s.h.segmentation.feat[
i].lf_enabled =
get_bits1(&
s->gb)))
736 if ((
s->s.h.segmentation.feat[
i].ref_enabled =
get_bits1(&
s->gb)))
737 s->s.h.segmentation.feat[
i].ref_val =
get_bits(&
s->gb, 2);
738 s->s.h.segmentation.feat[
i].skip_enabled =
get_bits1(&
s->gb);
745 s->s.h.segmentation.temporal = 0;
746 s->s.h.segmentation.update_map = 0;
750 for (
i = 0;
i < (
s->s.h.segmentation.enabled ? 8 : 1);
i++) {
751 int qyac, qydc, quvac, quvdc, lflvl, sh;
753 if (
s->s.h.segmentation.enabled &&
s->s.h.segmentation.feat[
i].q_enabled) {
754 if (
s->s.h.segmentation.absolute_vals)
759 qyac =
s->s.h.yac_qi;
771 sh =
s->s.h.filter.level >= 32;
772 if (
s->s.h.segmentation.enabled &&
s->s.h.segmentation.feat[
i].lf_enabled) {
773 if (
s->s.h.segmentation.absolute_vals)
776 lflvl =
av_clip_uintp2(
s->s.h.filter.level +
s->s.h.segmentation.feat[
i].lf_val, 6);
778 lflvl =
s->s.h.filter.level;
780 if (
s->s.h.lf_delta.enabled) {
781 s->s.h.segmentation.feat[
i].lflvl[0][0] =
782 s->s.h.segmentation.feat[
i].lflvl[0][1] =
784 for (j = 1; j < 4; j++) {
785 s->s.h.segmentation.feat[
i].lflvl[j][0] =
787 s->s.h.lf_delta.mode[0]) * (1 << sh)), 6);
788 s->s.h.segmentation.feat[
i].lflvl[j][1] =
790 s->s.h.lf_delta.mode[1]) * (1 << sh)), 6);
793 memset(
s->s.h.segmentation.feat[
i].lflvl, lflvl,
794 sizeof(
s->s.h.segmentation.feat[
i].lflvl));
804 for (
s->s.h.tiling.log2_tile_cols = 0;
805 s->sb_cols > (64 <<
s->s.h.tiling.log2_tile_cols);
806 s->s.h.tiling.log2_tile_cols++) ;
807 for (
max = 0; (
s->sb_cols >>
max) >= 4;
max++) ;
809 while (
max >
s->s.h.tiling.log2_tile_cols) {
811 s->s.h.tiling.log2_tile_cols++;
816 s->s.h.tiling.tile_rows = 1 <<
s->s.h.tiling.log2_tile_rows;
817 if (
s->s.h.tiling.tile_cols != (1 <<
s->s.h.tiling.log2_tile_cols) || changed) {
822 for (
i = 0;
i <
s->active_tile_cols;
i++)
827 s->s.h.tiling.tile_cols = 1 <<
s->s.h.tiling.log2_tile_cols;
829 s->s.h.tiling.tile_cols : 1;
834 n_range_coders =
s->s.h.tiling.tile_cols;
841 for (
i = 0;
i <
s->active_tile_cols;
i++) {
844 rc += n_range_coders;
849 if (!
s->s.h.keyframe && !
s->s.h.intraonly) {
850 int valid_ref_frame = 0;
851 for (
i = 0;
i < 3;
i++) {
853 int refw =
ref->width, refh =
ref->height;
857 "Ref pixfmt (%s) did not match current frame (%s)",
861 }
else if (refw ==
w && refh ==
h) {
862 s->mvscale[
i][0] =
s->mvscale[
i][1] = 0;
866 if (
w * 2 < refw ||
h * 2 < refh ||
w > 16 * refw ||
h > 16 * refh) {
868 "Invalid ref frame dimensions %dx%d for frame size %dx%d\n",
873 s->mvscale[
i][0] = (refw << 14) /
w;
874 s->mvscale[
i][1] = (refh << 14) /
h;
875 s->mvstep[
i][0] = 16 *
s->mvscale[
i][0] >> 14;
876 s->mvstep[
i][1] = 16 *
s->mvscale[
i][1] >> 14;
880 if (!valid_ref_frame) {
881 av_log(avctx,
AV_LOG_ERROR,
"No valid reference frame is found, bitstream not supported\n");
886 if (
s->s.h.keyframe ||
s->s.h.errorres || (
s->s.h.intraonly &&
s->s.h.resetctx == 3)) {
887 s->prob_ctx[0].p =
s->prob_ctx[1].p =
s->prob_ctx[2].p =
897 }
else if (
s->s.h.intraonly &&
s->s.h.resetctx == 2) {
904 s->s.h.compressed_header_size = size2 =
get_bits(&
s->gb, 16);
908 if (size2 >
size - (data2 -
data)) {
921 for (
i = 0;
i <
s->active_tile_cols;
i++) {
922 if (
s->s.h.keyframe ||
s->s.h.intraonly) {
923 memset(
s->td[
i].counts.coef, 0,
sizeof(
s->td[0].counts.coef));
924 memset(
s->td[
i].counts.eob, 0,
sizeof(
s->td[0].counts.eob));
926 memset(&
s->td[
i].counts, 0,
sizeof(
s->td[0].counts));
928 s->td[
i].nb_block_structure = 0;
934 s->prob.p =
s->prob_ctx[
c].p;
937 if (
s->s.h.lossless) {
941 if (
s->s.h.txfmmode == 3)
945 for (
i = 0;
i < 2;
i++)
948 for (
i = 0;
i < 2;
i++)
949 for (j = 0; j < 2; j++)
951 s->prob.p.tx16p[
i][j] =
953 for (
i = 0;
i < 2;
i++)
954 for (j = 0; j < 3; j++)
956 s->prob.p.tx32p[
i][j] =
962 for (
i = 0;
i < 4;
i++) {
963 uint8_t (*
ref)[2][6][6][3] =
s->prob_ctx[
c].coef[
i];
965 for (j = 0; j < 2; j++)
966 for (k = 0; k < 2; k++)
967 for (l = 0; l < 6; l++)
968 for (m = 0; m < 6; m++) {
969 uint8_t *
p =
s->prob.coef[
i][j][k][l][m];
970 uint8_t *
r =
ref[j][k][l][m];
971 if (m >= 3 && l == 0)
973 for (n = 0; n < 3; n++) {
982 for (j = 0; j < 2; j++)
983 for (k = 0; k < 2; k++)
984 for (l = 0; l < 6; l++)
985 for (m = 0; m < 6; m++) {
986 uint8_t *
p =
s->prob.coef[
i][j][k][l][m];
987 uint8_t *
r =
ref[j][k][l][m];
994 if (
s->s.h.txfmmode ==
i)
999 for (
i = 0;
i < 3;
i++)
1002 if (!
s->s.h.keyframe && !
s->s.h.intraonly) {
1003 for (
i = 0;
i < 7;
i++)
1004 for (j = 0; j < 3; j++)
1006 s->prob.p.mv_mode[
i][j] =
1010 for (
i = 0;
i < 4;
i++)
1011 for (j = 0; j < 2; j++)
1013 s->prob.p.filter[
i][j] =
1016 for (
i = 0;
i < 4;
i++)
1020 if (
s->s.h.allowcompinter) {
1022 if (
s->s.h.comppredmode)
1025 for (
i = 0;
i < 5;
i++)
1034 for (
i = 0;
i < 5;
i++) {
1036 s->prob.p.single_ref[
i][0] =
1039 s->prob.p.single_ref[
i][1] =
1045 for (
i = 0;
i < 5;
i++)
1047 s->prob.p.comp_ref[
i] =
1051 for (
i = 0;
i < 4;
i++)
1052 for (j = 0; j < 9; j++)
1054 s->prob.p.y_mode[
i][j] =
1057 for (
i = 0;
i < 4;
i++)
1058 for (j = 0; j < 4; j++)
1059 for (k = 0; k < 3; k++)
1061 s->prob.p.partition[3 -
i][j][k] =
1063 s->prob.p.partition[3 -
i][j][k]);
1066 for (
i = 0;
i < 3;
i++)
1070 for (
i = 0;
i < 2;
i++) {
1072 s->prob.p.mv_comp[
i].sign =
1075 for (j = 0; j < 10; j++)
1077 s->prob.p.mv_comp[
i].classes[j] =
1081 s->prob.p.mv_comp[
i].class0 =
1084 for (j = 0; j < 10; j++)
1086 s->prob.p.mv_comp[
i].bits[j] =
1090 for (
i = 0;
i < 2;
i++) {
1091 for (j = 0; j < 2; j++)
1092 for (k = 0; k < 3; k++)
1094 s->prob.p.mv_comp[
i].class0_fp[j][k] =
1097 for (j = 0; j < 3; j++)
1099 s->prob.p.mv_comp[
i].fp[j] =
1103 if (
s->s.h.highprecisionmvs) {
1104 for (
i = 0;
i < 2;
i++) {
1106 s->prob.p.mv_comp[
i].class0_hp =
1110 s->prob.p.mv_comp[
i].hp =
1116 return (data2 -
data) + size2;
1120 ptrdiff_t yoff, ptrdiff_t uvoff,
enum BlockLevel bl)
1123 int c = ((
s->above_partition_ctx[col] >> (3 - bl)) & 1) |
1126 s->prob.p.partition[bl][
c];
1128 ptrdiff_t hbs = 4 >> bl;
1130 ptrdiff_t y_stride =
f->linesize[0], uv_stride =
f->linesize[1];
1131 int bytesperpixel =
s->bytesperpixel;
1136 }
else if (col + hbs < s->cols) {
1137 if (row + hbs < s->rows) {
1145 yoff += hbs * 8 * y_stride;
1146 uvoff += hbs * 8 * uv_stride >>
s->ss_v;
1151 yoff += hbs * 8 * bytesperpixel;
1152 uvoff += hbs * 8 * bytesperpixel >>
s->ss_h;
1156 decode_sb(td, row, col, lflvl, yoff, uvoff, bl + 1);
1158 yoff + 8 * hbs * bytesperpixel,
1159 uvoff + (8 * hbs * bytesperpixel >>
s->ss_h), bl + 1);
1160 yoff += hbs * 8 * y_stride;
1161 uvoff += hbs * 8 * uv_stride >>
s->ss_v;
1162 decode_sb(td, row + hbs, col, lflvl, yoff, uvoff, bl + 1);
1163 decode_sb(td, row + hbs, col + hbs, lflvl,
1164 yoff + 8 * hbs * bytesperpixel,
1165 uvoff + (8 * hbs * bytesperpixel >>
s->ss_h), bl + 1);
1169 "the four PARTITION_* terminal codes");
1173 decode_sb(td, row, col, lflvl, yoff, uvoff, bl + 1);
1175 yoff + 8 * hbs * bytesperpixel,
1176 uvoff + (8 * hbs * bytesperpixel >>
s->ss_h), bl + 1);
1181 }
else if (row + hbs < s->rows) {
1184 decode_sb(td, row, col, lflvl, yoff, uvoff, bl + 1);
1185 yoff += hbs * 8 * y_stride;
1186 uvoff += hbs * 8 * uv_stride >>
s->ss_v;
1187 decode_sb(td, row + hbs, col, lflvl, yoff, uvoff, bl + 1);
1194 decode_sb(td, row, col, lflvl, yoff, uvoff, bl + 1);
1200 ptrdiff_t yoff, ptrdiff_t uvoff,
enum BlockLevel bl)
1204 ptrdiff_t hbs = 4 >> bl;
1206 ptrdiff_t y_stride =
f->linesize[0], uv_stride =
f->linesize[1];
1207 int bytesperpixel =
s->bytesperpixel;
1212 }
else if (td->
b->
bl == bl) {
1215 yoff += hbs * 8 * y_stride;
1216 uvoff += hbs * 8 * uv_stride >>
s->ss_v;
1218 }
else if (
b->bp ==
PARTITION_V && col + hbs < s->cols) {
1219 yoff += hbs * 8 * bytesperpixel;
1220 uvoff += hbs * 8 * bytesperpixel >>
s->ss_h;
1225 if (col + hbs < s->cols) {
1226 if (row + hbs < s->rows) {
1227 decode_sb_mem(td, row, col + hbs, lflvl, yoff + 8 * hbs * bytesperpixel,
1228 uvoff + (8 * hbs * bytesperpixel >>
s->ss_h), bl + 1);
1229 yoff += hbs * 8 * y_stride;
1230 uvoff += hbs * 8 * uv_stride >>
s->ss_v;
1231 decode_sb_mem(td, row + hbs, col, lflvl, yoff, uvoff, bl + 1);
1233 yoff + 8 * hbs * bytesperpixel,
1234 uvoff + (8 * hbs * bytesperpixel >>
s->ss_h), bl + 1);
1236 yoff += hbs * 8 * bytesperpixel;
1237 uvoff += hbs * 8 * bytesperpixel >>
s->ss_h;
1238 decode_sb_mem(td, row, col + hbs, lflvl, yoff, uvoff, bl + 1);
1240 }
else if (row + hbs < s->rows) {
1241 yoff += hbs * 8 * y_stride;
1242 uvoff += hbs * 8 * uv_stride >>
s->ss_v;
1243 decode_sb_mem(td, row + hbs, col, lflvl, yoff, uvoff, bl + 1);
1250 int sb_start = ( idx * n) >> log2_n;
1251 int sb_end = ((idx + 1) * n) >> log2_n;
1252 *start =
FFMIN(sb_start, n) << 3;
1253 *end =
FFMIN(sb_end, n) << 3;
1261 for (
i = 0;
i <
s->active_tile_cols;
i++)
1270 for (
int i = 0;
i < 3;
i++)
1273 for (
i = 0;
i < 8;
i++) {
1286 ff_cbs_fragment_free(&
s->current_frag);
1287 ff_cbs_close(&
s->cbc);
1298 int row, col, tile_row, tile_col,
ret;
1300 int tile_row_start, tile_row_end, tile_col_start, tile_col_end;
1302 ptrdiff_t yoff, uvoff, ls_y, ls_uv;
1305 ls_y =
f->linesize[0];
1306 ls_uv =
f->linesize[1];
1307 bytesperpixel =
s->bytesperpixel;
1310 for (tile_row = 0; tile_row <
s->s.h.tiling.tile_rows; tile_row++) {
1312 tile_row,
s->s.h.tiling.log2_tile_rows,
s->sb_rows);
1314 for (tile_col = 0; tile_col <
s->s.h.tiling.tile_cols; tile_col++) {
1317 if (tile_col ==
s->s.h.tiling.tile_cols - 1 &&
1318 tile_row ==
s->s.h.tiling.tile_rows - 1) {
1325 if (tile_size >
size)
1336 for (row = tile_row_start; row < tile_row_end;
1337 row += 8, yoff += ls_y * 64, uvoff += ls_uv * 64 >>
s->ss_v) {
1339 ptrdiff_t yoff2 = yoff, uvoff2 = uvoff;
1341 for (tile_col = 0; tile_col <
s->s.h.tiling.tile_cols; tile_col++) {
1343 tile_col,
s->s.h.tiling.log2_tile_cols,
s->sb_cols);
1348 if (
s->s.h.keyframe ||
s->s.h.intraonly) {
1357 td->
c = &td->
c_b[tile_col];
1360 for (col = tile_col_start;
1362 col += 8, yoff2 += 64 * bytesperpixel,
1363 uvoff2 += 64 * bytesperpixel >>
s->ss_h, lflvl_ptr++) {
1367 memset(lflvl_ptr->
mask, 0,
sizeof(lflvl_ptr->
mask));
1388 if (row + 8 <
s->rows) {
1389 memcpy(
s->intra_pred_data[0],
1390 f->data[0] + yoff + 63 * ls_y,
1391 8 *
s->cols * bytesperpixel);
1392 memcpy(
s->intra_pred_data[1],
1393 f->data[1] + uvoff + ((64 >>
s->ss_v) - 1) * ls_uv,
1394 8 *
s->cols * bytesperpixel >>
s->ss_h);
1395 memcpy(
s->intra_pred_data[2],
1396 f->data[2] + uvoff + ((64 >>
s->ss_v) - 1) * ls_uv,
1397 8 *
s->cols * bytesperpixel >>
s->ss_h);
1401 if (
s->s.h.filter.level) {
1404 lflvl_ptr =
s->lflvl;
1405 for (col = 0; col <
s->cols;
1406 col += 8, yoff2 += 64 * bytesperpixel,
1407 uvoff2 += 64 * bytesperpixel >>
s->ss_h, lflvl_ptr++) {
1424 int decode_tiles_mt(
AVCodecContext *avctx,
void *tdata,
int jobnr,
1429 ptrdiff_t uvoff, yoff, ls_y, ls_uv;
1430 int bytesperpixel =
s->bytesperpixel, row, col, tile_row;
1431 unsigned tile_cols_len;
1432 int tile_row_start, tile_row_end, tile_col_start, tile_col_end;
1437 ls_y =
f->linesize[0];
1438 ls_uv =
f->linesize[1];
1441 jobnr,
s->s.h.tiling.log2_tile_cols,
s->sb_cols);
1443 uvoff = (64 * bytesperpixel >>
s->ss_h)*(tile_col_start >> 3);
1444 yoff = (64 * bytesperpixel)*(tile_col_start >> 3);
1445 lflvl_ptr_base =
s->lflvl+(tile_col_start >> 3);
1447 for (tile_row = 0; tile_row <
s->s.h.tiling.tile_rows; tile_row++) {
1449 tile_row,
s->s.h.tiling.log2_tile_rows,
s->sb_rows);
1451 td->
c = &td->
c_b[tile_row];
1452 for (row = tile_row_start; row < tile_row_end;
1453 row += 8, yoff += ls_y * 64, uvoff += ls_uv * 64 >>
s->ss_v) {
1454 ptrdiff_t yoff2 = yoff, uvoff2 = uvoff;
1455 VP9Filter *lflvl_ptr = lflvl_ptr_base+
s->sb_cols*(row >> 3);
1459 if (
s->s.h.keyframe ||
s->s.h.intraonly) {
1468 for (col = tile_col_start;
1470 col += 8, yoff2 += 64 * bytesperpixel,
1471 uvoff2 += 64 * bytesperpixel >>
s->ss_h, lflvl_ptr++) {
1474 memset(lflvl_ptr->
mask, 0,
sizeof(lflvl_ptr->
mask));
1481 tile_cols_len = tile_col_end - tile_col_start;
1482 if (row + 8 <
s->rows) {
1483 memcpy(
s->intra_pred_data[0] + (tile_col_start * 8 * bytesperpixel),
1484 f->data[0] + yoff + 63 * ls_y,
1485 8 * tile_cols_len * bytesperpixel);
1486 memcpy(
s->intra_pred_data[1] + (tile_col_start * 8 * bytesperpixel >>
s->ss_h),
1487 f->data[1] + uvoff + ((64 >>
s->ss_v) - 1) * ls_uv,
1488 8 * tile_cols_len * bytesperpixel >>
s->ss_h);
1489 memcpy(
s->intra_pred_data[2] + (tile_col_start * 8 * bytesperpixel >>
s->ss_h),
1490 f->data[2] + uvoff + ((64 >>
s->ss_v) - 1) * ls_uv,
1491 8 * tile_cols_len * bytesperpixel >>
s->ss_h);
1494 vp9_report_tile_progress(
s, row >> 3, 1);
1504 ptrdiff_t uvoff, yoff, ls_y, ls_uv;
1506 int bytesperpixel =
s->bytesperpixel, col,
i;
1510 ls_y =
f->linesize[0];
1511 ls_uv =
f->linesize[1];
1513 for (
i = 0;
i <
s->sb_rows;
i++) {
1514 vp9_await_tile_progress(
s,
i,
s->s.h.tiling.tile_cols);
1516 if (
s->s.h.filter.level) {
1517 yoff = (ls_y * 64)*
i;
1518 uvoff = (ls_uv * 64 >>
s->ss_v)*
i;
1519 lflvl_ptr =
s->lflvl+
s->sb_cols*
i;
1520 for (col = 0; col <
s->cols;
1521 col += 8, yoff += 64 * bytesperpixel,
1522 uvoff += 64 * bytesperpixel >>
s->ss_h, lflvl_ptr++) {
1535 unsigned int tile, nb_blocks = 0;
1537 if (
s->s.h.segmentation.enabled) {
1539 nb_blocks +=
s->td[
tile].nb_block_structure;
1547 par->
qp =
s->s.h.yac_qi;
1548 par->
delta_qp[0][0] =
s->s.h.ydc_qdelta;
1549 par->
delta_qp[1][0] =
s->s.h.uvdc_qdelta;
1550 par->
delta_qp[2][0] =
s->s.h.uvdc_qdelta;
1551 par->
delta_qp[1][1] =
s->s.h.uvac_qdelta;
1552 par->
delta_qp[2][1] =
s->s.h.uvac_qdelta;
1555 unsigned int block = 0;
1556 unsigned int tile, block_tile;
1565 uint8_t seg_id =
frame->segmentation_map[row * 8 *
s->sb_cols + col];
1572 if (
s->s.h.segmentation.feat[seg_id].q_enabled) {
1573 b->delta_qp =
s->s.h.segmentation.feat[seg_id].q_val;
1574 if (
s->s.h.segmentation.absolute_vals)
1575 b->delta_qp -= par->
qp;
1595 (!
s->s.h.segmentation.enabled || !
s->s.h.segmentation.update_map);
1599 ret = ff_cbs_read_packet(
s->cbc, &
s->current_frag,
pkt);
1601 ff_cbs_fragment_reset(&
s->current_frag);
1606 unit = &
s->current_frag.units[0];
1610 s->frame_header = &rf->
header;
1613 ff_cbs_fragment_reset(&
s->current_frag);
1615 }
else if (
ret == 0) {
1616 if (!
s->s.refs[
ref].f) {
1618 ff_cbs_fragment_reset(&
s->current_frag);
1621 for (
int i = 0;
i < 8;
i++)
1625 ff_cbs_fragment_reset(&
s->current_frag);
1637 src = !
s->s.h.keyframe && !
s->s.h.intraonly && !
s->s.h.errorres ?
1639 if (!retain_segmap_ref ||
s->s.h.keyframe ||
s->s.h.intraonly)
1644 ff_cbs_fragment_reset(&
s->current_frag);
1649 s->s.frames[
CUR_FRAME].frame_header =
s->frame_header;
1652 if (
s->s.h.keyframe)
1656 if (
s->s.h.lossless)
1670 for (
i = 0;
i < 8;
i++) {
1672 s->s.h.refreshrefmask & (1 <<
i) ?
1688 for (
i = 0;
i < 8;
i++) {
1690 s->s.h.refreshrefmask & (1 <<
i) ?
1698 memset(
s->above_partition_ctx, 0,
s->cols);
1699 memset(
s->above_skip_ctx, 0,
s->cols);
1700 if (
s->s.h.keyframe ||
s->s.h.intraonly) {
1701 memset(
s->above_mode_ctx,
DC_PRED,
s->cols * 2);
1705 memset(
s->above_y_nnz_ctx, 0,
s->sb_cols * 16);
1706 memset(
s->above_uv_nnz_ctx[0], 0,
s->sb_cols * 16 >>
s->ss_h);
1707 memset(
s->above_uv_nnz_ctx[1], 0,
s->sb_cols * 16 >>
s->ss_h);
1708 memset(
s->above_segpred_ctx, 0,
s->cols);
1713 "Failed to allocate block buffers\n");
1716 if (
s->s.h.refreshctx &&
s->s.h.parallelmode) {
1719 for (
i = 0;
i < 4;
i++) {
1720 for (j = 0; j < 2; j++)
1721 for (k = 0; k < 2; k++)
1722 for (l = 0; l < 6; l++)
1723 for (m = 0; m < 6; m++)
1724 memcpy(
s->prob_ctx[
s->s.h.framectxid].coef[
i][j][k][l][m],
1725 s->prob.coef[
i][j][k][l][m], 3);
1726 if (
s->s.h.txfmmode ==
i)
1729 s->prob_ctx[
s->s.h.framectxid].p =
s->prob.p;
1731 }
else if (!
s->s.h.refreshctx) {
1737 for (
i = 0;
i <
s->sb_rows;
i++)
1743 for (
i = 0;
i <
s->active_tile_cols;
i++) {
1744 s->td[
i].b =
s->td[
i].b_base;
1745 s->td[
i].block =
s->td[
i].block_base;
1746 s->td[
i].uvblock[0] =
s->td[
i].uvblock_base[0];
1747 s->td[
i].uvblock[1] =
s->td[
i].uvblock_base[1];
1748 s->td[
i].eob =
s->td[
i].eob_base;
1749 s->td[
i].uveob[0] =
s->td[
i].uveob_base[0];
1750 s->td[
i].uveob[1] =
s->td[
i].uveob_base[1];
1751 s->td[
i].error_info = 0;
1756 int tile_row, tile_col;
1760 for (tile_row = 0; tile_row <
s->s.h.tiling.tile_rows; tile_row++) {
1761 for (tile_col = 0; tile_col <
s->s.h.tiling.tile_cols; tile_col++) {
1764 if (tile_col ==
s->s.h.tiling.tile_cols - 1 &&
1765 tile_row ==
s->s.h.tiling.tile_rows - 1) {
1772 if (tile_size >
size)
1795 for (
i = 1;
i <
s->s.h.tiling.tile_cols;
i++)
1796 for (j = 0; j <
sizeof(
s->td[
i].counts) /
sizeof(
unsigned); j++)
1797 ((
unsigned *)&
s->td[0].counts)[j] += ((
unsigned *)&
s->td[
i].counts)[j];
1799 if (
s->pass < 2 &&
s->s.h.refreshctx && !
s->s.h.parallelmode) {
1803 }
while (
s->pass++ == 1);
1805 if (
s->td->error_info < 0) {
1807 s->td->error_info = 0;
1818 ff_cbs_fragment_reset(&
s->current_frag);
1822 for (
int i = 0;
i < 8;
i++)
1825 if (!
s->s.h.invisible) {
1833 ff_cbs_fragment_reset(&
s->current_frag);
1843 for (
i = 0;
i < 3;
i++)
1846 for (
i = 0;
i < 8;
i++) {
1851 ff_cbs_fragment_reset(&
s->current_frag);
1852 ff_cbs_flush(
s->cbc);
1864 s->s.h.filter.sharpness = -1;
1886 for (
int i = 0;
i < 3;
i++)
1888 for (
int i = 0;
i < 8;
i++)
1891 s->frame_extradata_pool_size = ssrc->frame_extradata_pool_size;
1894 for (
int i = 0;
i < 8;
i++)
1897 s->frame_header = ssrc->frame_header;
1900 s->s.h.invisible = ssrc->s.h.invisible;
1901 s->s.h.keyframe = ssrc->s.h.keyframe;
1902 s->s.h.intraonly = ssrc->s.h.intraonly;
1903 s->ss_v = ssrc->ss_v;
1904 s->ss_h = ssrc->ss_h;
1905 s->s.h.segmentation.enabled = ssrc->s.h.segmentation.enabled;
1906 s->s.h.segmentation.update_map = ssrc->s.h.segmentation.update_map;
1907 s->s.h.segmentation.absolute_vals = ssrc->s.h.segmentation.absolute_vals;
1908 s->bytesperpixel = ssrc->bytesperpixel;
1909 s->gf_fmt = ssrc->gf_fmt;
1912 s->s.h.bpp = ssrc->s.h.bpp;
1913 s->bpp_index = ssrc->bpp_index;
1914 s->pix_fmt = ssrc->pix_fmt;
1915 memcpy(&
s->prob_ctx, &ssrc->prob_ctx,
sizeof(
s->prob_ctx));
1916 memcpy(&
s->s.h.lf_delta, &ssrc->s.h.lf_delta,
sizeof(
s->s.h.lf_delta));
1917 memcpy(&
s->s.h.segmentation.feat, &ssrc->s.h.segmentation.feat,
1918 sizeof(
s->s.h.segmentation.feat));
1940 .bsfs =
"vp9_superframe_split",
1942 #if CONFIG_VP9_DXVA2_HWACCEL
1945 #if CONFIG_VP9_D3D11VA_HWACCEL
1948 #if CONFIG_VP9_D3D11VA2_HWACCEL
1951 #if CONFIG_VP9_D3D12VA_HWACCEL
1954 #if CONFIG_VP9_NVDEC_HWACCEL
1957 #if CONFIG_VP9_NVDEC_CUARRAY_HWACCEL
1960 #if CONFIG_VP9_VAAPI_HWACCEL
1963 #if CONFIG_VP9_VDPAU_HWACCEL
1966 #if CONFIG_VP9_VIDEOTOOLBOX_HWACCEL
1969 #if CONFIG_VP9_VULKAN_HWACCEL