24 #include "config_components.h"
49 #define VP9_SYNCCODE 0x498342
103 f->segmentation_map =
NULL;
115 sz = 64 *
s->sb_cols *
s->sb_rows;
116 if (sz !=
s->frame_extradata_pool_size) {
120 if (!
s->frame_extradata_pool) {
121 s->frame_extradata_pool_size = 0;
125 s->frame_extradata_pool_size = sz;
133 f->segmentation_map =
f->extradata;
150 dst->frame_header =
src->frame_header;
156 dst->segmentation_map =
src->segmentation_map;
158 dst->uses_2pass =
src->uses_2pass;
161 src->hwaccel_picture_private);
166 #define HWACCEL_MAX (CONFIG_VP9_DXVA2_HWACCEL + \
167 CONFIG_VP9_D3D11VA_HWACCEL * 2 + \
168 CONFIG_VP9_D3D12VA_HWACCEL + \
169 CONFIG_VP9_NVDEC_HWACCEL + \
170 CONFIG_VP9_VAAPI_HWACCEL + \
171 CONFIG_VP9_VDPAU_HWACCEL + \
172 CONFIG_VP9_VIDEOTOOLBOX_HWACCEL + \
173 CONFIG_VP9_VULKAN_HWACCEL)
177 int bytesperpixel =
s->bytesperpixel,
ret, cols, rows;
182 if (!(
s->pix_fmt ==
s->gf_fmt &&
w ==
s->w &&
h ==
s->h)) {
186 switch (
s->pix_fmt) {
189 #if CONFIG_VP9_DXVA2_HWACCEL
192 #if CONFIG_VP9_D3D11VA_HWACCEL
196 #if CONFIG_VP9_D3D12VA_HWACCEL
199 #if CONFIG_VP9_NVDEC_HWACCEL
202 #if CONFIG_VP9_VAAPI_HWACCEL
205 #if CONFIG_VP9_VDPAU_HWACCEL
208 #if CONFIG_VP9_VIDEOTOOLBOX_HWACCEL
211 #if CONFIG_VP9_VULKAN_HWACCEL
216 #if CONFIG_VP9_NVDEC_HWACCEL
219 #if CONFIG_VP9_VAAPI_HWACCEL
222 #if CONFIG_VP9_VDPAU_HWACCEL
225 #if CONFIG_VP9_VULKAN_HWACCEL
232 #if CONFIG_VP9_VAAPI_HWACCEL
235 #if CONFIG_VP9_VULKAN_HWACCEL
242 #if CONFIG_VP9_VAAPI_HWACCEL
245 #if CONFIG_VP9_VULKAN_HWACCEL
251 *fmtp++ =
s->pix_fmt;
259 s->gf_fmt =
s->pix_fmt;
267 if (
s->intra_pred_data[0] && cols ==
s->cols && rows ==
s->rows &&
s->pix_fmt ==
s->last_fmt)
270 s->last_fmt =
s->pix_fmt;
271 s->sb_cols = (
w + 63) >> 6;
272 s->sb_rows = (
h + 63) >> 6;
273 s->cols = (
w + 7) >> 3;
274 s->rows = (
h + 7) >> 3;
277 #define assign(var, type, n) var = (type) p; p += s->sb_cols * (n) * sizeof(*var)
281 p =
av_malloc(
s->sb_cols * (128 + 192 * bytesperpixel +
282 lflvl_len *
sizeof(*
s->lflvl) + 16 *
sizeof(*
s->above_mv_ctx)));
285 assign(
s->intra_pred_data[0], uint8_t *, 64 * bytesperpixel);
286 assign(
s->intra_pred_data[1], uint8_t *, 64 * bytesperpixel);
287 assign(
s->intra_pred_data[2], uint8_t *, 64 * bytesperpixel);
288 assign(
s->above_y_nnz_ctx, uint8_t *, 16);
289 assign(
s->above_mode_ctx, uint8_t *, 16);
291 assign(
s->above_uv_nnz_ctx[0], uint8_t *, 16);
292 assign(
s->above_uv_nnz_ctx[1], uint8_t *, 16);
293 assign(
s->above_partition_ctx, uint8_t *, 8);
294 assign(
s->above_skip_ctx, uint8_t *, 8);
295 assign(
s->above_txfm_ctx, uint8_t *, 8);
296 assign(
s->above_segpred_ctx, uint8_t *, 8);
297 assign(
s->above_intra_ctx, uint8_t *, 8);
298 assign(
s->above_comp_ctx, uint8_t *, 8);
299 assign(
s->above_ref_ctx, uint8_t *, 8);
300 assign(
s->above_filter_ctx, uint8_t *, 8);
305 for (
i = 0;
i <
s->active_tile_cols;
i++)
309 if (
s->s.h.bpp !=
s->last_bpp) {
312 s->last_bpp =
s->s.h.bpp;
322 int chroma_blocks, chroma_eobs, bytesperpixel =
s->bytesperpixel;
329 chroma_blocks = 64 * 64 >> (
s->ss_h +
s->ss_v);
330 chroma_eobs = 16 * 16 >> (
s->ss_h +
s->ss_v);
332 int sbs =
s->sb_cols *
s->sb_rows;
336 16 * 16 + 2 * chroma_eobs) * sbs);
351 for (
i = 1;
i <
s->active_tile_cols;
i++)
354 for (
i = 0;
i <
s->active_tile_cols;
i++) {
356 s->td[
i].block_base =
av_mallocz((64 * 64 + 2 * chroma_blocks) * bytesperpixel *
sizeof(int16_t) +
357 16 * 16 + 2 * chroma_eobs);
358 if (!
s->td[
i].b_base || !
s->td[
i].block_base)
360 s->td[
i].uvblock_base[0] =
s->td[
i].block_base + 64 * 64 * bytesperpixel;
361 s->td[
i].uvblock_base[1] =
s->td[
i].uvblock_base[0] + chroma_blocks * bytesperpixel;
362 s->td[
i].eob_base = (uint8_t *) (
s->td[
i].uvblock_base[1] + chroma_blocks * bytesperpixel);
363 s->td[
i].uveob_base[0] =
s->td[
i].eob_base + 16 * 16;
364 s->td[
i].uveob_base[1] =
s->td[
i].uveob_base[0] + chroma_eobs;
368 if (!
s->td[
i].block_structure)
373 s->block_alloc_using_2pass =
s->s.frames[
CUR_FRAME].uses_2pass;
390 return m - ((v + 1) >> 1);
397 static const uint8_t inv_map_table[255] = {
398 7, 20, 33, 46, 59, 72, 85, 98, 111, 124, 137, 150, 163, 176,
399 189, 202, 215, 228, 241, 254, 1, 2, 3, 4, 5, 6, 8, 9,
400 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24,
401 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39,
402 40, 41, 42, 43, 44, 45, 47, 48, 49, 50, 51, 52, 53, 54,
403 55, 56, 57, 58, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
404 70, 71, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
405 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 99, 100,
406 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 112, 113, 114, 115,
407 116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130,
408 131, 132, 133, 134, 135, 136, 138, 139, 140, 141, 142, 143, 144, 145,
409 146, 147, 148, 149, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
410 161, 162, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
411 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 190, 191,
412 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 203, 204, 205, 206,
413 207, 208, 209, 210, 211, 212, 213, 214, 216, 217, 218, 219, 220, 221,
414 222, 223, 224, 225, 226, 227, 229, 230, 231, 232, 233, 234, 235, 236,
415 237, 238, 239, 240, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251,
463 s->s.h.bpp = 8 +
bits * 2;
464 s->bytesperpixel = (7 +
s->s.h.bpp) >> 3;
470 s->ss_h =
s->ss_v = 0;
484 static const enum AVPixelFormat pix_fmt_for_ss[3][2 ][2 ] = {
496 s->pix_fmt = pix_fmt_for_ss[
bits][
s->ss_v][
s->ss_h];
507 s->ss_h =
s->ss_v = 1;
508 s->pix_fmt = pix_fmt_for_ss[
bits][1][1];
519 int c,
i, j, k, l, m, n,
w,
h,
max, size2,
ret, sharp;
521 const uint8_t *data2;
545 s->last_keyframe =
s->s.h.keyframe;
548 last_invisible =
s->s.h.invisible;
551 s->s.h.use_last_frame_mvs = !
s->s.h.errorres && !last_invisible;
553 if (
s->s.h.keyframe) {
561 s->s.h.refreshrefmask = 0xff;
567 s->s.h.intraonly =
s->s.h.invisible ?
get_bits1(&
s->gb) : 0;
568 s->s.h.resetctx =
s->s.h.errorres ? 0 :
get_bits(&
s->gb, 2);
569 if (
s->s.h.intraonly) {
578 s->ss_h =
s->ss_v = 1;
581 s->bytesperpixel = 1;
594 s->s.h.signbias[0] =
get_bits1(&
s->gb) && !
s->s.h.errorres;
596 s->s.h.signbias[1] =
get_bits1(&
s->gb) && !
s->s.h.errorres;
598 s->s.h.signbias[2] =
get_bits1(&
s->gb) && !
s->s.h.errorres;
599 if (!
s->s.refs[
s->s.h.refidx[0]].f ||
600 !
s->s.refs[
s->s.h.refidx[1]].f ||
601 !
s->s.refs[
s->s.h.refidx[2]].f) {
606 w =
s->s.refs[
s->s.h.refidx[0]].f->width;
607 h =
s->s.refs[
s->s.h.refidx[0]].f->height;
609 w =
s->s.refs[
s->s.h.refidx[1]].f->width;
610 h =
s->s.refs[
s->s.h.refidx[1]].f->height;
612 w =
s->s.refs[
s->s.h.refidx[2]].f->width;
613 h =
s->s.refs[
s->s.h.refidx[2]].f->height;
621 s->s.h.use_last_frame_mvs &=
s->s.frames[
CUR_FRAME].tf.f &&
629 s->s.h.allowcompinter =
s->s.h.signbias[0] !=
s->s.h.signbias[1] ||
630 s->s.h.signbias[0] !=
s->s.h.signbias[2];
631 if (
s->s.h.allowcompinter) {
632 if (
s->s.h.signbias[0] ==
s->s.h.signbias[1]) {
633 s->s.h.fixcompref = 2;
634 s->s.h.varcompref[0] = 0;
635 s->s.h.varcompref[1] = 1;
636 }
else if (
s->s.h.signbias[0] ==
s->s.h.signbias[2]) {
637 s->s.h.fixcompref = 1;
638 s->s.h.varcompref[0] = 0;
639 s->s.h.varcompref[1] = 2;
641 s->s.h.fixcompref = 0;
642 s->s.h.varcompref[0] = 1;
643 s->s.h.varcompref[1] = 2;
648 s->s.h.refreshctx =
s->s.h.errorres ? 0 :
get_bits1(&
s->gb);
649 s->s.h.parallelmode =
s->s.h.errorres ? 1 :
get_bits1(&
s->gb);
651 if (
s->s.h.keyframe ||
s->s.h.intraonly)
652 s->s.h.framectxid = 0;
655 if (
s->s.h.keyframe ||
s->s.h.errorres ||
s->s.h.intraonly) {
657 s->s.h.lf_delta.ref[0] = 1;
658 s->s.h.lf_delta.ref[1] = 0;
659 s->s.h.lf_delta.ref[2] = -1;
660 s->s.h.lf_delta.ref[3] = -1;
661 s->s.h.lf_delta.mode[0] = 0;
662 s->s.h.lf_delta.mode[1] = 0;
663 memset(
s->s.h.segmentation.feat, 0,
sizeof(
s->s.h.segmentation.feat));
669 if (
s->s.h.filter.sharpness != sharp) {
670 for (
i = 1;
i <= 63;
i++) {
674 limit >>= (sharp + 3) >> 2;
679 s->filter_lut.lim_lut[
i] =
limit;
680 s->filter_lut.mblim_lut[
i] = 2 * (
i + 2) +
limit;
683 s->s.h.filter.sharpness = sharp;
684 if ((
s->s.h.lf_delta.enabled =
get_bits1(&
s->gb))) {
685 if ((
s->s.h.lf_delta.updated =
get_bits1(&
s->gb))) {
686 for (
i = 0;
i < 4;
i++)
689 for (
i = 0;
i < 2;
i++)
700 s->s.h.lossless =
s->s.h.yac_qi == 0 &&
s->s.h.ydc_qdelta == 0 &&
701 s->s.h.uvdc_qdelta == 0 &&
s->s.h.uvac_qdelta == 0;
702 #if FF_API_CODEC_PROPS
710 if ((
s->s.h.segmentation.enabled =
get_bits1(&
s->gb))) {
711 if ((
s->s.h.segmentation.update_map =
get_bits1(&
s->gb))) {
712 for (
i = 0;
i < 7;
i++)
715 if ((
s->s.h.segmentation.temporal =
get_bits1(&
s->gb)))
716 for (
i = 0;
i < 3;
i++)
722 s->s.h.segmentation.absolute_vals =
get_bits1(&
s->gb);
723 for (
i = 0;
i < 8;
i++) {
724 if ((
s->s.h.segmentation.feat[
i].q_enabled =
get_bits1(&
s->gb)))
726 if ((
s->s.h.segmentation.feat[
i].lf_enabled =
get_bits1(&
s->gb)))
728 if ((
s->s.h.segmentation.feat[
i].ref_enabled =
get_bits1(&
s->gb)))
729 s->s.h.segmentation.feat[
i].ref_val =
get_bits(&
s->gb, 2);
730 s->s.h.segmentation.feat[
i].skip_enabled =
get_bits1(&
s->gb);
737 s->s.h.segmentation.temporal = 0;
738 s->s.h.segmentation.update_map = 0;
742 for (
i = 0;
i < (
s->s.h.segmentation.enabled ? 8 : 1);
i++) {
743 int qyac, qydc, quvac, quvdc, lflvl, sh;
745 if (
s->s.h.segmentation.enabled &&
s->s.h.segmentation.feat[
i].q_enabled) {
746 if (
s->s.h.segmentation.absolute_vals)
751 qyac =
s->s.h.yac_qi;
763 sh =
s->s.h.filter.level >= 32;
764 if (
s->s.h.segmentation.enabled &&
s->s.h.segmentation.feat[
i].lf_enabled) {
765 if (
s->s.h.segmentation.absolute_vals)
768 lflvl =
av_clip_uintp2(
s->s.h.filter.level +
s->s.h.segmentation.feat[
i].lf_val, 6);
770 lflvl =
s->s.h.filter.level;
772 if (
s->s.h.lf_delta.enabled) {
773 s->s.h.segmentation.feat[
i].lflvl[0][0] =
774 s->s.h.segmentation.feat[
i].lflvl[0][1] =
776 for (j = 1; j < 4; j++) {
777 s->s.h.segmentation.feat[
i].lflvl[j][0] =
779 s->s.h.lf_delta.mode[0]) * (1 << sh)), 6);
780 s->s.h.segmentation.feat[
i].lflvl[j][1] =
782 s->s.h.lf_delta.mode[1]) * (1 << sh)), 6);
785 memset(
s->s.h.segmentation.feat[
i].lflvl, lflvl,
786 sizeof(
s->s.h.segmentation.feat[
i].lflvl));
796 for (
s->s.h.tiling.log2_tile_cols = 0;
797 s->sb_cols > (64 <<
s->s.h.tiling.log2_tile_cols);
798 s->s.h.tiling.log2_tile_cols++) ;
799 for (
max = 0; (
s->sb_cols >>
max) >= 4;
max++) ;
801 while (
max >
s->s.h.tiling.log2_tile_cols) {
803 s->s.h.tiling.log2_tile_cols++;
808 s->s.h.tiling.tile_rows = 1 <<
s->s.h.tiling.log2_tile_rows;
809 if (
s->s.h.tiling.tile_cols != (1 <<
s->s.h.tiling.log2_tile_cols)) {
814 for (
i = 0;
i <
s->active_tile_cols;
i++)
819 s->s.h.tiling.tile_cols = 1 <<
s->s.h.tiling.log2_tile_cols;
821 s->s.h.tiling.tile_cols : 1;
826 n_range_coders =
s->s.h.tiling.tile_cols;
833 for (
i = 0;
i <
s->active_tile_cols;
i++) {
836 rc += n_range_coders;
841 if (!
s->s.h.keyframe && !
s->s.h.intraonly) {
842 int valid_ref_frame = 0;
843 for (
i = 0;
i < 3;
i++) {
845 int refw =
ref->width, refh =
ref->height;
849 "Ref pixfmt (%s) did not match current frame (%s)",
853 }
else if (refw ==
w && refh ==
h) {
854 s->mvscale[
i][0] =
s->mvscale[
i][1] = 0;
858 if (
w * 2 < refw ||
h * 2 < refh ||
w > 16 * refw ||
h > 16 * refh) {
860 "Invalid ref frame dimensions %dx%d for frame size %dx%d\n",
865 s->mvscale[
i][0] = (refw << 14) /
w;
866 s->mvscale[
i][1] = (refh << 14) /
h;
867 s->mvstep[
i][0] = 16 *
s->mvscale[
i][0] >> 14;
868 s->mvstep[
i][1] = 16 *
s->mvscale[
i][1] >> 14;
872 if (!valid_ref_frame) {
873 av_log(avctx,
AV_LOG_ERROR,
"No valid reference frame is found, bitstream not supported\n");
878 if (
s->s.h.keyframe ||
s->s.h.errorres || (
s->s.h.intraonly &&
s->s.h.resetctx == 3)) {
879 s->prob_ctx[0].p =
s->prob_ctx[1].p =
s->prob_ctx[2].p =
889 }
else if (
s->s.h.intraonly &&
s->s.h.resetctx == 2) {
896 s->s.h.compressed_header_size = size2 =
get_bits(&
s->gb, 16);
900 if (size2 >
size - (data2 -
data)) {
913 for (
i = 0;
i <
s->active_tile_cols;
i++) {
914 if (
s->s.h.keyframe ||
s->s.h.intraonly) {
915 memset(
s->td[
i].counts.coef, 0,
sizeof(
s->td[0].counts.coef));
916 memset(
s->td[
i].counts.eob, 0,
sizeof(
s->td[0].counts.eob));
918 memset(&
s->td[
i].counts, 0,
sizeof(
s->td[0].counts));
920 s->td[
i].nb_block_structure = 0;
926 s->prob.p =
s->prob_ctx[
c].p;
929 if (
s->s.h.lossless) {
933 if (
s->s.h.txfmmode == 3)
937 for (
i = 0;
i < 2;
i++)
940 for (
i = 0;
i < 2;
i++)
941 for (j = 0; j < 2; j++)
943 s->prob.p.tx16p[
i][j] =
945 for (
i = 0;
i < 2;
i++)
946 for (j = 0; j < 3; j++)
948 s->prob.p.tx32p[
i][j] =
954 for (
i = 0;
i < 4;
i++) {
955 uint8_t (*
ref)[2][6][6][3] =
s->prob_ctx[
c].coef[
i];
957 for (j = 0; j < 2; j++)
958 for (k = 0; k < 2; k++)
959 for (l = 0; l < 6; l++)
960 for (m = 0; m < 6; m++) {
961 uint8_t *p =
s->prob.coef[
i][j][k][l][m];
962 uint8_t *
r =
ref[j][k][l][m];
963 if (m >= 3 && l == 0)
965 for (n = 0; n < 3; n++) {
974 for (j = 0; j < 2; j++)
975 for (k = 0; k < 2; k++)
976 for (l = 0; l < 6; l++)
977 for (m = 0; m < 6; m++) {
978 uint8_t *p =
s->prob.coef[
i][j][k][l][m];
979 uint8_t *
r =
ref[j][k][l][m];
986 if (
s->s.h.txfmmode ==
i)
991 for (
i = 0;
i < 3;
i++)
994 if (!
s->s.h.keyframe && !
s->s.h.intraonly) {
995 for (
i = 0;
i < 7;
i++)
996 for (j = 0; j < 3; j++)
998 s->prob.p.mv_mode[
i][j] =
1002 for (
i = 0;
i < 4;
i++)
1003 for (j = 0; j < 2; j++)
1005 s->prob.p.filter[
i][j] =
1008 for (
i = 0;
i < 4;
i++)
1012 if (
s->s.h.allowcompinter) {
1014 if (
s->s.h.comppredmode)
1017 for (
i = 0;
i < 5;
i++)
1026 for (
i = 0;
i < 5;
i++) {
1028 s->prob.p.single_ref[
i][0] =
1031 s->prob.p.single_ref[
i][1] =
1037 for (
i = 0;
i < 5;
i++)
1039 s->prob.p.comp_ref[
i] =
1043 for (
i = 0;
i < 4;
i++)
1044 for (j = 0; j < 9; j++)
1046 s->prob.p.y_mode[
i][j] =
1049 for (
i = 0;
i < 4;
i++)
1050 for (j = 0; j < 4; j++)
1051 for (k = 0; k < 3; k++)
1053 s->prob.p.partition[3 -
i][j][k] =
1055 s->prob.p.partition[3 -
i][j][k]);
1058 for (
i = 0;
i < 3;
i++)
1062 for (
i = 0;
i < 2;
i++) {
1064 s->prob.p.mv_comp[
i].sign =
1067 for (j = 0; j < 10; j++)
1069 s->prob.p.mv_comp[
i].classes[j] =
1073 s->prob.p.mv_comp[
i].class0 =
1076 for (j = 0; j < 10; j++)
1078 s->prob.p.mv_comp[
i].bits[j] =
1082 for (
i = 0;
i < 2;
i++) {
1083 for (j = 0; j < 2; j++)
1084 for (k = 0; k < 3; k++)
1086 s->prob.p.mv_comp[
i].class0_fp[j][k] =
1089 for (j = 0; j < 3; j++)
1091 s->prob.p.mv_comp[
i].fp[j] =
1095 if (
s->s.h.highprecisionmvs) {
1096 for (
i = 0;
i < 2;
i++) {
1098 s->prob.p.mv_comp[
i].class0_hp =
1102 s->prob.p.mv_comp[
i].hp =
1108 return (data2 -
data) + size2;
1112 ptrdiff_t yoff, ptrdiff_t uvoff,
enum BlockLevel bl)
1115 int c = ((
s->above_partition_ctx[col] >> (3 - bl)) & 1) |
1118 s->prob.p.partition[bl][
c];
1120 ptrdiff_t hbs = 4 >> bl;
1122 ptrdiff_t y_stride =
f->linesize[0], uv_stride =
f->linesize[1];
1123 int bytesperpixel =
s->bytesperpixel;
1128 }
else if (col + hbs < s->cols) {
1129 if (row + hbs < s->rows) {
1137 yoff += hbs * 8 * y_stride;
1138 uvoff += hbs * 8 * uv_stride >>
s->ss_v;
1143 yoff += hbs * 8 * bytesperpixel;
1144 uvoff += hbs * 8 * bytesperpixel >>
s->ss_h;
1148 decode_sb(td, row, col, lflvl, yoff, uvoff, bl + 1);
1150 yoff + 8 * hbs * bytesperpixel,
1151 uvoff + (8 * hbs * bytesperpixel >>
s->ss_h), bl + 1);
1152 yoff += hbs * 8 * y_stride;
1153 uvoff += hbs * 8 * uv_stride >>
s->ss_v;
1154 decode_sb(td, row + hbs, col, lflvl, yoff, uvoff, bl + 1);
1155 decode_sb(td, row + hbs, col + hbs, lflvl,
1156 yoff + 8 * hbs * bytesperpixel,
1157 uvoff + (8 * hbs * bytesperpixel >>
s->ss_h), bl + 1);
1161 "the four PARTITION_* terminal codes");
1165 decode_sb(td, row, col, lflvl, yoff, uvoff, bl + 1);
1167 yoff + 8 * hbs * bytesperpixel,
1168 uvoff + (8 * hbs * bytesperpixel >>
s->ss_h), bl + 1);
1173 }
else if (row + hbs < s->rows) {
1176 decode_sb(td, row, col, lflvl, yoff, uvoff, bl + 1);
1177 yoff += hbs * 8 * y_stride;
1178 uvoff += hbs * 8 * uv_stride >>
s->ss_v;
1179 decode_sb(td, row + hbs, col, lflvl, yoff, uvoff, bl + 1);
1186 decode_sb(td, row, col, lflvl, yoff, uvoff, bl + 1);
1192 ptrdiff_t yoff, ptrdiff_t uvoff,
enum BlockLevel bl)
1196 ptrdiff_t hbs = 4 >> bl;
1198 ptrdiff_t y_stride =
f->linesize[0], uv_stride =
f->linesize[1];
1199 int bytesperpixel =
s->bytesperpixel;
1204 }
else if (td->
b->
bl == bl) {
1207 yoff += hbs * 8 * y_stride;
1208 uvoff += hbs * 8 * uv_stride >>
s->ss_v;
1210 }
else if (
b->bp ==
PARTITION_V && col + hbs < s->cols) {
1211 yoff += hbs * 8 * bytesperpixel;
1212 uvoff += hbs * 8 * bytesperpixel >>
s->ss_h;
1217 if (col + hbs < s->cols) {
1218 if (row + hbs < s->rows) {
1219 decode_sb_mem(td, row, col + hbs, lflvl, yoff + 8 * hbs * bytesperpixel,
1220 uvoff + (8 * hbs * bytesperpixel >>
s->ss_h), bl + 1);
1221 yoff += hbs * 8 * y_stride;
1222 uvoff += hbs * 8 * uv_stride >>
s->ss_v;
1223 decode_sb_mem(td, row + hbs, col, lflvl, yoff, uvoff, bl + 1);
1225 yoff + 8 * hbs * bytesperpixel,
1226 uvoff + (8 * hbs * bytesperpixel >>
s->ss_h), bl + 1);
1228 yoff += hbs * 8 * bytesperpixel;
1229 uvoff += hbs * 8 * bytesperpixel >>
s->ss_h;
1230 decode_sb_mem(td, row, col + hbs, lflvl, yoff, uvoff, bl + 1);
1232 }
else if (row + hbs < s->rows) {
1233 yoff += hbs * 8 * y_stride;
1234 uvoff += hbs * 8 * uv_stride >>
s->ss_v;
1235 decode_sb_mem(td, row + hbs, col, lflvl, yoff, uvoff, bl + 1);
1242 int sb_start = ( idx * n) >> log2_n;
1243 int sb_end = ((idx + 1) * n) >> log2_n;
1244 *start =
FFMIN(sb_start, n) << 3;
1245 *end =
FFMIN(sb_end, n) << 3;
1253 for (
i = 0;
i <
s->active_tile_cols;
i++)
1262 for (
int i = 0;
i < 3;
i++)
1265 for (
i = 0;
i < 8;
i++) {
1278 ff_cbs_fragment_free(&
s->current_frag);
1279 ff_cbs_close(&
s->cbc);
1290 int row, col, tile_row, tile_col,
ret;
1292 int tile_row_start, tile_row_end, tile_col_start, tile_col_end;
1294 ptrdiff_t yoff, uvoff, ls_y, ls_uv;
1297 ls_y =
f->linesize[0];
1298 ls_uv =
f->linesize[1];
1299 bytesperpixel =
s->bytesperpixel;
1302 for (tile_row = 0; tile_row <
s->s.h.tiling.tile_rows; tile_row++) {
1304 tile_row,
s->s.h.tiling.log2_tile_rows,
s->sb_rows);
1306 for (tile_col = 0; tile_col <
s->s.h.tiling.tile_cols; tile_col++) {
1309 if (tile_col ==
s->s.h.tiling.tile_cols - 1 &&
1310 tile_row ==
s->s.h.tiling.tile_rows - 1) {
1317 if (tile_size >
size)
1328 for (row = tile_row_start; row < tile_row_end;
1329 row += 8, yoff += ls_y * 64, uvoff += ls_uv * 64 >>
s->ss_v) {
1331 ptrdiff_t yoff2 = yoff, uvoff2 = uvoff;
1333 for (tile_col = 0; tile_col <
s->s.h.tiling.tile_cols; tile_col++) {
1335 tile_col,
s->s.h.tiling.log2_tile_cols,
s->sb_cols);
1340 if (
s->s.h.keyframe ||
s->s.h.intraonly) {
1349 td->
c = &td->
c_b[tile_col];
1352 for (col = tile_col_start;
1354 col += 8, yoff2 += 64 * bytesperpixel,
1355 uvoff2 += 64 * bytesperpixel >>
s->ss_h, lflvl_ptr++) {
1359 memset(lflvl_ptr->
mask, 0,
sizeof(lflvl_ptr->
mask));
1380 if (row + 8 <
s->rows) {
1381 memcpy(
s->intra_pred_data[0],
1382 f->data[0] + yoff + 63 * ls_y,
1383 8 *
s->cols * bytesperpixel);
1384 memcpy(
s->intra_pred_data[1],
1385 f->data[1] + uvoff + ((64 >>
s->ss_v) - 1) * ls_uv,
1386 8 *
s->cols * bytesperpixel >>
s->ss_h);
1387 memcpy(
s->intra_pred_data[2],
1388 f->data[2] + uvoff + ((64 >>
s->ss_v) - 1) * ls_uv,
1389 8 *
s->cols * bytesperpixel >>
s->ss_h);
1393 if (
s->s.h.filter.level) {
1396 lflvl_ptr =
s->lflvl;
1397 for (col = 0; col <
s->cols;
1398 col += 8, yoff2 += 64 * bytesperpixel,
1399 uvoff2 += 64 * bytesperpixel >>
s->ss_h, lflvl_ptr++) {
1416 int decode_tiles_mt(
AVCodecContext *avctx,
void *tdata,
int jobnr,
1421 ptrdiff_t uvoff, yoff, ls_y, ls_uv;
1422 int bytesperpixel =
s->bytesperpixel, row, col, tile_row;
1423 unsigned tile_cols_len;
1424 int tile_row_start, tile_row_end, tile_col_start, tile_col_end;
1429 ls_y =
f->linesize[0];
1430 ls_uv =
f->linesize[1];
1433 jobnr,
s->s.h.tiling.log2_tile_cols,
s->sb_cols);
1435 uvoff = (64 * bytesperpixel >>
s->ss_h)*(tile_col_start >> 3);
1436 yoff = (64 * bytesperpixel)*(tile_col_start >> 3);
1437 lflvl_ptr_base =
s->lflvl+(tile_col_start >> 3);
1439 for (tile_row = 0; tile_row <
s->s.h.tiling.tile_rows; tile_row++) {
1441 tile_row,
s->s.h.tiling.log2_tile_rows,
s->sb_rows);
1443 td->
c = &td->
c_b[tile_row];
1444 for (row = tile_row_start; row < tile_row_end;
1445 row += 8, yoff += ls_y * 64, uvoff += ls_uv * 64 >>
s->ss_v) {
1446 ptrdiff_t yoff2 = yoff, uvoff2 = uvoff;
1447 VP9Filter *lflvl_ptr = lflvl_ptr_base+
s->sb_cols*(row >> 3);
1451 if (
s->s.h.keyframe ||
s->s.h.intraonly) {
1460 for (col = tile_col_start;
1462 col += 8, yoff2 += 64 * bytesperpixel,
1463 uvoff2 += 64 * bytesperpixel >>
s->ss_h, lflvl_ptr++) {
1466 memset(lflvl_ptr->
mask, 0,
sizeof(lflvl_ptr->
mask));
1473 tile_cols_len = tile_col_end - tile_col_start;
1474 if (row + 8 <
s->rows) {
1475 memcpy(
s->intra_pred_data[0] + (tile_col_start * 8 * bytesperpixel),
1476 f->data[0] + yoff + 63 * ls_y,
1477 8 * tile_cols_len * bytesperpixel);
1478 memcpy(
s->intra_pred_data[1] + (tile_col_start * 8 * bytesperpixel >>
s->ss_h),
1479 f->data[1] + uvoff + ((64 >>
s->ss_v) - 1) * ls_uv,
1480 8 * tile_cols_len * bytesperpixel >>
s->ss_h);
1481 memcpy(
s->intra_pred_data[2] + (tile_col_start * 8 * bytesperpixel >>
s->ss_h),
1482 f->data[2] + uvoff + ((64 >>
s->ss_v) - 1) * ls_uv,
1483 8 * tile_cols_len * bytesperpixel >>
s->ss_h);
1486 vp9_report_tile_progress(
s, row >> 3, 1);
1496 ptrdiff_t uvoff, yoff, ls_y, ls_uv;
1498 int bytesperpixel =
s->bytesperpixel, col,
i;
1502 ls_y =
f->linesize[0];
1503 ls_uv =
f->linesize[1];
1505 for (
i = 0;
i <
s->sb_rows;
i++) {
1506 vp9_await_tile_progress(
s,
i,
s->s.h.tiling.tile_cols);
1508 if (
s->s.h.filter.level) {
1509 yoff = (ls_y * 64)*
i;
1510 uvoff = (ls_uv * 64 >>
s->ss_v)*
i;
1511 lflvl_ptr =
s->lflvl+
s->sb_cols*
i;
1512 for (col = 0; col <
s->cols;
1513 col += 8, yoff += 64 * bytesperpixel,
1514 uvoff += 64 * bytesperpixel >>
s->ss_h, lflvl_ptr++) {
1527 unsigned int tile, nb_blocks = 0;
1529 if (
s->s.h.segmentation.enabled) {
1531 nb_blocks +=
s->td[
tile].nb_block_structure;
1539 par->
qp =
s->s.h.yac_qi;
1540 par->
delta_qp[0][0] =
s->s.h.ydc_qdelta;
1541 par->
delta_qp[1][0] =
s->s.h.uvdc_qdelta;
1542 par->
delta_qp[2][0] =
s->s.h.uvdc_qdelta;
1543 par->
delta_qp[1][1] =
s->s.h.uvac_qdelta;
1544 par->
delta_qp[2][1] =
s->s.h.uvac_qdelta;
1547 unsigned int block = 0;
1548 unsigned int tile, block_tile;
1557 uint8_t seg_id =
frame->segmentation_map[row * 8 *
s->sb_cols + col];
1564 if (
s->s.h.segmentation.feat[seg_id].q_enabled) {
1565 b->delta_qp =
s->s.h.segmentation.feat[seg_id].q_val;
1566 if (
s->s.h.segmentation.absolute_vals)
1567 b->delta_qp -= par->
qp;
1587 (!
s->s.h.segmentation.enabled || !
s->s.h.segmentation.update_map);
1591 ret = ff_cbs_read_packet(
s->cbc, &
s->current_frag,
pkt);
1593 ff_cbs_fragment_reset(&
s->current_frag);
1598 unit = &
s->current_frag.units[0];
1602 s->frame_header = &rf->
header;
1606 }
else if (
ret == 0) {
1607 if (!
s->s.refs[
ref].f) {
1611 for (
int i = 0;
i < 8;
i++)
1615 ff_cbs_fragment_reset(&
s->current_frag);
1627 src = !
s->s.h.keyframe && !
s->s.h.intraonly && !
s->s.h.errorres ?
1629 if (!retain_segmap_ref ||
s->s.h.keyframe ||
s->s.h.intraonly)
1637 s->s.frames[
CUR_FRAME].frame_header =
s->frame_header;
1640 if (
s->s.h.keyframe)
1644 if (
s->s.h.lossless)
1658 for (
i = 0;
i < 8;
i++) {
1660 s->s.h.refreshrefmask & (1 <<
i) ?
1676 for (
i = 0;
i < 8;
i++) {
1678 s->s.h.refreshrefmask & (1 <<
i) ?
1686 memset(
s->above_partition_ctx, 0,
s->cols);
1687 memset(
s->above_skip_ctx, 0,
s->cols);
1688 if (
s->s.h.keyframe ||
s->s.h.intraonly) {
1689 memset(
s->above_mode_ctx,
DC_PRED,
s->cols * 2);
1693 memset(
s->above_y_nnz_ctx, 0,
s->sb_cols * 16);
1694 memset(
s->above_uv_nnz_ctx[0], 0,
s->sb_cols * 16 >>
s->ss_h);
1695 memset(
s->above_uv_nnz_ctx[1], 0,
s->sb_cols * 16 >>
s->ss_h);
1696 memset(
s->above_segpred_ctx, 0,
s->cols);
1701 "Failed to allocate block buffers\n");
1704 if (
s->s.h.refreshctx &&
s->s.h.parallelmode) {
1707 for (
i = 0;
i < 4;
i++) {
1708 for (j = 0; j < 2; j++)
1709 for (k = 0; k < 2; k++)
1710 for (l = 0; l < 6; l++)
1711 for (m = 0; m < 6; m++)
1712 memcpy(
s->prob_ctx[
s->s.h.framectxid].coef[
i][j][k][l][m],
1713 s->prob.coef[
i][j][k][l][m], 3);
1714 if (
s->s.h.txfmmode ==
i)
1717 s->prob_ctx[
s->s.h.framectxid].p =
s->prob.p;
1719 }
else if (!
s->s.h.refreshctx) {
1725 for (
i = 0;
i <
s->sb_rows;
i++)
1731 for (
i = 0;
i <
s->active_tile_cols;
i++) {
1732 s->td[
i].b =
s->td[
i].b_base;
1733 s->td[
i].block =
s->td[
i].block_base;
1734 s->td[
i].uvblock[0] =
s->td[
i].uvblock_base[0];
1735 s->td[
i].uvblock[1] =
s->td[
i].uvblock_base[1];
1736 s->td[
i].eob =
s->td[
i].eob_base;
1737 s->td[
i].uveob[0] =
s->td[
i].uveob_base[0];
1738 s->td[
i].uveob[1] =
s->td[
i].uveob_base[1];
1739 s->td[
i].error_info = 0;
1744 int tile_row, tile_col;
1748 for (tile_row = 0; tile_row <
s->s.h.tiling.tile_rows; tile_row++) {
1749 for (tile_col = 0; tile_col <
s->s.h.tiling.tile_cols; tile_col++) {
1752 if (tile_col ==
s->s.h.tiling.tile_cols - 1 &&
1753 tile_row ==
s->s.h.tiling.tile_rows - 1) {
1760 if (tile_size >
size)
1783 for (
i = 1;
i <
s->s.h.tiling.tile_cols;
i++)
1784 for (j = 0; j <
sizeof(
s->td[
i].counts) /
sizeof(
unsigned); j++)
1785 ((
unsigned *)&
s->td[0].counts)[j] += ((
unsigned *)&
s->td[
i].counts)[j];
1787 if (
s->pass < 2 &&
s->s.h.refreshctx && !
s->s.h.parallelmode) {
1791 }
while (
s->pass++ == 1);
1793 if (
s->td->error_info < 0) {
1795 s->td->error_info = 0;
1806 ff_cbs_fragment_reset(&
s->current_frag);
1810 for (
int i = 0;
i < 8;
i++)
1813 if (!
s->s.h.invisible) {
1830 for (
i = 0;
i < 3;
i++)
1833 for (
i = 0;
i < 8;
i++) {
1838 ff_cbs_fragment_reset(&
s->current_frag);
1839 ff_cbs_flush(
s->cbc);
1851 s->s.h.filter.sharpness = -1;
1873 for (
int i = 0;
i < 3;
i++)
1875 for (
int i = 0;
i < 8;
i++)
1878 s->frame_extradata_pool_size = ssrc->frame_extradata_pool_size;
1881 for (
int i = 0;
i < 8;
i++)
1884 s->frame_header = ssrc->frame_header;
1887 s->s.h.invisible = ssrc->s.h.invisible;
1888 s->s.h.keyframe = ssrc->s.h.keyframe;
1889 s->s.h.intraonly = ssrc->s.h.intraonly;
1890 s->ss_v = ssrc->ss_v;
1891 s->ss_h = ssrc->ss_h;
1892 s->s.h.segmentation.enabled = ssrc->s.h.segmentation.enabled;
1893 s->s.h.segmentation.update_map = ssrc->s.h.segmentation.update_map;
1894 s->s.h.segmentation.absolute_vals = ssrc->s.h.segmentation.absolute_vals;
1895 s->bytesperpixel = ssrc->bytesperpixel;
1896 s->gf_fmt = ssrc->gf_fmt;
1899 s->s.h.bpp = ssrc->s.h.bpp;
1900 s->bpp_index = ssrc->bpp_index;
1901 s->pix_fmt = ssrc->pix_fmt;
1902 memcpy(&
s->prob_ctx, &ssrc->prob_ctx,
sizeof(
s->prob_ctx));
1903 memcpy(&
s->s.h.lf_delta, &ssrc->s.h.lf_delta,
sizeof(
s->s.h.lf_delta));
1904 memcpy(&
s->s.h.segmentation.feat, &ssrc->s.h.segmentation.feat,
1905 sizeof(
s->s.h.segmentation.feat));
1927 .bsfs =
"vp9_superframe_split",
1929 #if CONFIG_VP9_DXVA2_HWACCEL
1932 #if CONFIG_VP9_D3D11VA_HWACCEL
1935 #if CONFIG_VP9_D3D11VA2_HWACCEL
1938 #if CONFIG_VP9_D3D12VA_HWACCEL
1941 #if CONFIG_VP9_NVDEC_HWACCEL
1944 #if CONFIG_VP9_VAAPI_HWACCEL
1947 #if CONFIG_VP9_VDPAU_HWACCEL
1950 #if CONFIG_VP9_VIDEOTOOLBOX_HWACCEL
1953 #if CONFIG_VP9_VULKAN_HWACCEL