2017-03-25 13:10:13 +02:00
|
|
|
/*
|
|
|
|
* VP9 compatible video decoder
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Ronald S. Bultje <rsbultje gmail com>
|
|
|
|
* Copyright (C) 2013 Clément Bœsch <u pkh me>
|
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2022-02-06 08:08:01 +02:00
|
|
|
#include "threadframe.h"
|
2022-07-23 00:04:29 +02:00
|
|
|
#include "vp89_rac.h"
|
2017-03-25 13:10:13 +02:00
|
|
|
#include "vp9data.h"
|
2017-03-27 22:47:46 +02:00
|
|
|
#include "vp9dec.h"
|
2022-07-23 01:28:48 +02:00
|
|
|
#include "vpx_rac.h"
|
2017-03-25 13:10:13 +02:00
|
|
|
|
avcodec/vp8, vp9: Avoid using VP56mv and VP56Frame in VP8/9
Instead replace VP56mv by new and identical structures VP8mv and VP9mv.
Also replace VP56Frame by VP8FrameType in vp8.h and use that
in VP8 code. Also remove VP56_FRAME_GOLDEN2, as this has only
been used by VP8, and use VP8_FRAME_ALTREF as replacement for
its usage in VP8 as this is more in line with VP8 verbiage.
This allows to remove all inclusions of vp56.h from everything
that is not VP5/6. This also removes implicit inclusions
of hpeldsp.h, h264chroma.h, vp3dsp.h and vp56dsp.h from all VP8/9
files.
(This also fixes a build issue: If one compiles with -O0 and disables
everything except the VP8-VAAPI encoder, the file containing
ff_vpx_norm_shift is not compiled, yet this is used implicitly
by vp56_rac_gets_nn() which is defined in vp56.h; it is unused
by the VP8-VAAPI encoder and declared as av_unused, yet with -O0
unused noninline functions are not optimized away, leading to
linking failures. With this patch, said function is not included
in vaapi_encode_vp8.c any more.)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-23 02:01:41 +02:00
|
|
|
static av_always_inline void clamp_mv(VP9mv *dst, const VP9mv *src,
|
2017-09-07 23:02:49 +02:00
|
|
|
VP9TileData *td)
|
2017-03-25 13:10:13 +02:00
|
|
|
{
|
2017-09-07 23:02:49 +02:00
|
|
|
dst->x = av_clip(src->x, td->min_mv.x, td->max_mv.x);
|
|
|
|
dst->y = av_clip(src->y, td->min_mv.y, td->max_mv.y);
|
2017-03-25 13:10:13 +02:00
|
|
|
}
|
|
|
|
|
2017-09-07 23:02:49 +02:00
|
|
|
static void find_ref_mvs(VP9TileData *td,
|
avcodec/vp8, vp9: Avoid using VP56mv and VP56Frame in VP8/9
Instead replace VP56mv by new and identical structures VP8mv and VP9mv.
Also replace VP56Frame by VP8FrameType in vp8.h and use that
in VP8 code. Also remove VP56_FRAME_GOLDEN2, as this has only
been used by VP8, and use VP8_FRAME_ALTREF as replacement for
its usage in VP8 as this is more in line with VP8 verbiage.
This allows to remove all inclusions of vp56.h from everything
that is not VP5/6. This also removes implicit inclusions
of hpeldsp.h, h264chroma.h, vp3dsp.h and vp56dsp.h from all VP8/9
files.
(This also fixes a build issue: If one compiles with -O0 and disables
everything except the VP8-VAAPI encoder, the file containing
ff_vpx_norm_shift is not compiled, yet this is used implicitly
by vp56_rac_gets_nn() which is defined in vp56.h; it is unused
by the VP8-VAAPI encoder and declared as av_unused, yet with -O0
unused noninline functions are not optimized away, leading to
linking failures. With this patch, said function is not included
in vaapi_encode_vp8.c any more.)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-23 02:01:41 +02:00
|
|
|
VP9mv *pmv, int ref, int z, int idx, int sb)
|
2017-03-25 13:10:13 +02:00
|
|
|
{
|
|
|
|
static const int8_t mv_ref_blk_off[N_BS_SIZES][8][2] = {
|
2017-03-25 13:40:48 +02:00
|
|
|
[BS_64x64] = { { 3, -1 }, { -1, 3 }, { 4, -1 }, { -1, 4 },
|
|
|
|
{ -1, -1 }, { 0, -1 }, { -1, 0 }, { 6, -1 } },
|
|
|
|
[BS_64x32] = { { 0, -1 }, { -1, 0 }, { 4, -1 }, { -1, 2 },
|
|
|
|
{ -1, -1 }, { 0, -3 }, { -3, 0 }, { 2, -1 } },
|
|
|
|
[BS_32x64] = { { -1, 0 }, { 0, -1 }, { -1, 4 }, { 2, -1 },
|
|
|
|
{ -1, -1 }, { -3, 0 }, { 0, -3 }, { -1, 2 } },
|
|
|
|
[BS_32x32] = { { 1, -1 }, { -1, 1 }, { 2, -1 }, { -1, 2 },
|
|
|
|
{ -1, -1 }, { 0, -3 }, { -3, 0 }, { -3, -3 } },
|
|
|
|
[BS_32x16] = { { 0, -1 }, { -1, 0 }, { 2, -1 }, { -1, -1 },
|
|
|
|
{ -1, 1 }, { 0, -3 }, { -3, 0 }, { -3, -3 } },
|
|
|
|
[BS_16x32] = { { -1, 0 }, { 0, -1 }, { -1, 2 }, { -1, -1 },
|
|
|
|
{ 1, -1 }, { -3, 0 }, { 0, -3 }, { -3, -3 } },
|
|
|
|
[BS_16x16] = { { 0, -1 }, { -1, 0 }, { 1, -1 }, { -1, 1 },
|
|
|
|
{ -1, -1 }, { 0, -3 }, { -3, 0 }, { -3, -3 } },
|
|
|
|
[BS_16x8] = { { 0, -1 }, { -1, 0 }, { 1, -1 }, { -1, -1 },
|
|
|
|
{ 0, -2 }, { -2, 0 }, { -2, -1 }, { -1, -2 } },
|
|
|
|
[BS_8x16] = { { -1, 0 }, { 0, -1 }, { -1, 1 }, { -1, -1 },
|
|
|
|
{ -2, 0 }, { 0, -2 }, { -1, -2 }, { -2, -1 } },
|
|
|
|
[BS_8x8] = { { 0, -1 }, { -1, 0 }, { -1, -1 }, { 0, -2 },
|
|
|
|
{ -2, 0 }, { -1, -2 }, { -2, -1 }, { -2, -2 } },
|
|
|
|
[BS_8x4] = { { 0, -1 }, { -1, 0 }, { -1, -1 }, { 0, -2 },
|
|
|
|
{ -2, 0 }, { -1, -2 }, { -2, -1 }, { -2, -2 } },
|
|
|
|
[BS_4x8] = { { 0, -1 }, { -1, 0 }, { -1, -1 }, { 0, -2 },
|
|
|
|
{ -2, 0 }, { -1, -2 }, { -2, -1 }, { -2, -2 } },
|
|
|
|
[BS_4x4] = { { 0, -1 }, { -1, 0 }, { -1, -1 }, { 0, -2 },
|
|
|
|
{ -2, 0 }, { -1, -2 }, { -2, -1 }, { -2, -2 } },
|
2017-03-25 13:10:13 +02:00
|
|
|
};
|
2022-07-23 03:34:17 +02:00
|
|
|
const VP9Context *s = td->s;
|
2017-09-07 23:02:49 +02:00
|
|
|
VP9Block *b = td->b;
|
|
|
|
int row = td->row, col = td->col, row7 = td->row7;
|
2017-03-25 13:10:13 +02:00
|
|
|
const int8_t (*p)[2] = mv_ref_blk_off[b->bs];
|
|
|
|
#define INVALID_MV 0x80008000U
|
|
|
|
uint32_t mem = INVALID_MV, mem_sub8x8 = INVALID_MV;
|
|
|
|
int i;
|
|
|
|
|
2017-03-25 13:40:48 +02:00
|
|
|
#define RETURN_DIRECT_MV(mv) \
|
|
|
|
do { \
|
|
|
|
uint32_t m = AV_RN32A(&mv); \
|
|
|
|
if (!idx) { \
|
|
|
|
AV_WN32A(pmv, m); \
|
|
|
|
return; \
|
|
|
|
} else if (mem == INVALID_MV) { \
|
|
|
|
mem = m; \
|
|
|
|
} else if (m != mem) { \
|
|
|
|
AV_WN32A(pmv, m); \
|
|
|
|
return; \
|
|
|
|
} \
|
2017-03-25 13:10:13 +02:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
if (sb >= 0) {
|
|
|
|
if (sb == 2 || sb == 1) {
|
|
|
|
RETURN_DIRECT_MV(b->mv[0][z]);
|
|
|
|
} else if (sb == 3) {
|
|
|
|
RETURN_DIRECT_MV(b->mv[2][z]);
|
|
|
|
RETURN_DIRECT_MV(b->mv[1][z]);
|
|
|
|
RETURN_DIRECT_MV(b->mv[0][z]);
|
|
|
|
}
|
|
|
|
|
2017-03-25 13:40:48 +02:00
|
|
|
#define RETURN_MV(mv) \
|
|
|
|
do { \
|
|
|
|
if (sb > 0) { \
|
avcodec/vp8, vp9: Avoid using VP56mv and VP56Frame in VP8/9
Instead replace VP56mv by new and identical structures VP8mv and VP9mv.
Also replace VP56Frame by VP8FrameType in vp8.h and use that
in VP8 code. Also remove VP56_FRAME_GOLDEN2, as this has only
been used by VP8, and use VP8_FRAME_ALTREF as replacement for
its usage in VP8 as this is more in line with VP8 verbiage.
This allows to remove all inclusions of vp56.h from everything
that is not VP5/6. This also removes implicit inclusions
of hpeldsp.h, h264chroma.h, vp3dsp.h and vp56dsp.h from all VP8/9
files.
(This also fixes a build issue: If one compiles with -O0 and disables
everything except the VP8-VAAPI encoder, the file containing
ff_vpx_norm_shift is not compiled, yet this is used implicitly
by vp56_rac_gets_nn() which is defined in vp56.h; it is unused
by the VP8-VAAPI encoder and declared as av_unused, yet with -O0
unused noninline functions are not optimized away, leading to
linking failures. With this patch, said function is not included
in vaapi_encode_vp8.c any more.)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-23 02:01:41 +02:00
|
|
|
VP9mv tmp; \
|
2017-03-25 13:40:48 +02:00
|
|
|
uint32_t m; \
|
|
|
|
av_assert2(idx == 1); \
|
|
|
|
av_assert2(mem != INVALID_MV); \
|
|
|
|
if (mem_sub8x8 == INVALID_MV) { \
|
2017-09-07 23:02:49 +02:00
|
|
|
clamp_mv(&tmp, &mv, td); \
|
2017-03-25 13:40:48 +02:00
|
|
|
m = AV_RN32A(&tmp); \
|
|
|
|
if (m != mem) { \
|
|
|
|
AV_WN32A(pmv, m); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
mem_sub8x8 = AV_RN32A(&mv); \
|
|
|
|
} else if (mem_sub8x8 != AV_RN32A(&mv)) { \
|
2017-09-07 23:02:49 +02:00
|
|
|
clamp_mv(&tmp, &mv, td); \
|
2017-03-25 13:40:48 +02:00
|
|
|
m = AV_RN32A(&tmp); \
|
|
|
|
if (m != mem) { \
|
|
|
|
AV_WN32A(pmv, m); \
|
|
|
|
} else { \
|
2017-03-25 13:10:13 +02:00
|
|
|
/* BUG I'm pretty sure this isn't the intention */ \
|
2017-03-25 13:40:48 +02:00
|
|
|
AV_WN32A(pmv, 0); \
|
|
|
|
} \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} else { \
|
|
|
|
uint32_t m = AV_RN32A(&mv); \
|
|
|
|
if (!idx) { \
|
2017-09-07 23:02:49 +02:00
|
|
|
clamp_mv(pmv, &mv, td); \
|
2017-03-25 13:40:48 +02:00
|
|
|
return; \
|
|
|
|
} else if (mem == INVALID_MV) { \
|
|
|
|
mem = m; \
|
|
|
|
} else if (m != mem) { \
|
2017-09-07 23:02:49 +02:00
|
|
|
clamp_mv(pmv, &mv, td); \
|
2017-03-25 13:40:48 +02:00
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} \
|
2017-03-25 13:10:13 +02:00
|
|
|
} while (0)
|
|
|
|
|
|
|
|
if (row > 0) {
|
2017-03-25 14:19:52 +02:00
|
|
|
VP9mvrefPair *mv = &s->s.frames[CUR_FRAME].mv[(row - 1) * s->sb_cols * 8 + col];
|
2017-03-25 13:40:48 +02:00
|
|
|
if (mv->ref[0] == ref)
|
2017-03-25 13:10:13 +02:00
|
|
|
RETURN_MV(s->above_mv_ctx[2 * col + (sb & 1)][0]);
|
2017-03-25 13:40:48 +02:00
|
|
|
else if (mv->ref[1] == ref)
|
2017-03-25 13:10:13 +02:00
|
|
|
RETURN_MV(s->above_mv_ctx[2 * col + (sb & 1)][1]);
|
|
|
|
}
|
2017-09-07 23:02:49 +02:00
|
|
|
if (col > td->tile_col_start) {
|
2017-03-25 14:19:52 +02:00
|
|
|
VP9mvrefPair *mv = &s->s.frames[CUR_FRAME].mv[row * s->sb_cols * 8 + col - 1];
|
2017-03-25 13:40:48 +02:00
|
|
|
if (mv->ref[0] == ref)
|
2017-09-07 23:02:49 +02:00
|
|
|
RETURN_MV(td->left_mv_ctx[2 * row7 + (sb >> 1)][0]);
|
2017-03-25 13:40:48 +02:00
|
|
|
else if (mv->ref[1] == ref)
|
2017-09-07 23:02:49 +02:00
|
|
|
RETURN_MV(td->left_mv_ctx[2 * row7 + (sb >> 1)][1]);
|
2017-03-25 13:10:13 +02:00
|
|
|
}
|
|
|
|
i = 2;
|
|
|
|
} else {
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
|
2017-03-25 13:40:48 +02:00
|
|
|
// previously coded MVs in this neighborhood, using same reference frame
|
2017-03-25 13:10:13 +02:00
|
|
|
for (; i < 8; i++) {
|
|
|
|
int c = p[i][0] + col, r = p[i][1] + row;
|
|
|
|
|
2017-09-07 23:02:49 +02:00
|
|
|
if (c >= td->tile_col_start && c < s->cols &&
|
2017-03-25 13:40:48 +02:00
|
|
|
r >= 0 && r < s->rows) {
|
2017-03-25 14:19:52 +02:00
|
|
|
VP9mvrefPair *mv = &s->s.frames[CUR_FRAME].mv[r * s->sb_cols * 8 + c];
|
2017-03-25 13:10:13 +02:00
|
|
|
|
2017-03-25 13:40:48 +02:00
|
|
|
if (mv->ref[0] == ref)
|
2017-03-25 13:10:13 +02:00
|
|
|
RETURN_MV(mv->mv[0]);
|
2017-03-25 13:40:48 +02:00
|
|
|
else if (mv->ref[1] == ref)
|
2017-03-25 13:10:13 +02:00
|
|
|
RETURN_MV(mv->mv[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MV at this position in previous frame, using same reference frame
|
|
|
|
if (s->s.h.use_last_frame_mvs) {
|
2017-03-25 14:19:52 +02:00
|
|
|
VP9mvrefPair *mv = &s->s.frames[REF_FRAME_MVPAIR].mv[row * s->sb_cols * 8 + col];
|
2017-03-25 13:10:13 +02:00
|
|
|
|
|
|
|
if (!s->s.frames[REF_FRAME_MVPAIR].uses_2pass)
|
|
|
|
ff_thread_await_progress(&s->s.frames[REF_FRAME_MVPAIR].tf, row >> 3, 0);
|
2017-03-25 13:40:48 +02:00
|
|
|
if (mv->ref[0] == ref)
|
2017-03-25 13:10:13 +02:00
|
|
|
RETURN_MV(mv->mv[0]);
|
2017-03-25 13:40:48 +02:00
|
|
|
else if (mv->ref[1] == ref)
|
2017-03-25 13:10:13 +02:00
|
|
|
RETURN_MV(mv->mv[1]);
|
|
|
|
}
|
|
|
|
|
2017-03-25 13:40:48 +02:00
|
|
|
#define RETURN_SCALE_MV(mv, scale) \
|
|
|
|
do { \
|
|
|
|
if (scale) { \
|
avcodec/vp8, vp9: Avoid using VP56mv and VP56Frame in VP8/9
Instead replace VP56mv by new and identical structures VP8mv and VP9mv.
Also replace VP56Frame by VP8FrameType in vp8.h and use that
in VP8 code. Also remove VP56_FRAME_GOLDEN2, as this has only
been used by VP8, and use VP8_FRAME_ALTREF as replacement for
its usage in VP8 as this is more in line with VP8 verbiage.
This allows to remove all inclusions of vp56.h from everything
that is not VP5/6. This also removes implicit inclusions
of hpeldsp.h, h264chroma.h, vp3dsp.h and vp56dsp.h from all VP8/9
files.
(This also fixes a build issue: If one compiles with -O0 and disables
everything except the VP8-VAAPI encoder, the file containing
ff_vpx_norm_shift is not compiled, yet this is used implicitly
by vp56_rac_gets_nn() which is defined in vp56.h; it is unused
by the VP8-VAAPI encoder and declared as av_unused, yet with -O0
unused noninline functions are not optimized away, leading to
linking failures. With this patch, said function is not included
in vaapi_encode_vp8.c any more.)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-23 02:01:41 +02:00
|
|
|
VP9mv mv_temp = { -mv.x, -mv.y }; \
|
2017-03-25 13:40:48 +02:00
|
|
|
RETURN_MV(mv_temp); \
|
|
|
|
} else { \
|
|
|
|
RETURN_MV(mv); \
|
|
|
|
} \
|
2017-03-25 13:10:13 +02:00
|
|
|
} while (0)
|
|
|
|
|
2017-03-25 13:40:48 +02:00
|
|
|
// previously coded MVs in this neighborhood, using different reference frame
|
2017-03-25 13:10:13 +02:00
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
int c = p[i][0] + col, r = p[i][1] + row;
|
|
|
|
|
2017-09-07 23:02:49 +02:00
|
|
|
if (c >= td->tile_col_start && c < s->cols && r >= 0 && r < s->rows) {
|
2017-03-25 14:19:52 +02:00
|
|
|
VP9mvrefPair *mv = &s->s.frames[CUR_FRAME].mv[r * s->sb_cols * 8 + c];
|
2017-03-25 13:10:13 +02:00
|
|
|
|
2017-03-25 13:40:48 +02:00
|
|
|
if (mv->ref[0] != ref && mv->ref[0] >= 0)
|
|
|
|
RETURN_SCALE_MV(mv->mv[0],
|
|
|
|
s->s.h.signbias[mv->ref[0]] != s->s.h.signbias[ref]);
|
2017-03-25 13:10:13 +02:00
|
|
|
if (mv->ref[1] != ref && mv->ref[1] >= 0 &&
|
|
|
|
// BUG - libvpx has this condition regardless of whether
|
|
|
|
// we used the first ref MV and pre-scaling
|
|
|
|
AV_RN32A(&mv->mv[0]) != AV_RN32A(&mv->mv[1])) {
|
|
|
|
RETURN_SCALE_MV(mv->mv[1], s->s.h.signbias[mv->ref[1]] != s->s.h.signbias[ref]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MV at this position in previous frame, using different reference frame
|
|
|
|
if (s->s.h.use_last_frame_mvs) {
|
2017-03-25 14:19:52 +02:00
|
|
|
VP9mvrefPair *mv = &s->s.frames[REF_FRAME_MVPAIR].mv[row * s->sb_cols * 8 + col];
|
2017-03-25 13:10:13 +02:00
|
|
|
|
|
|
|
// no need to await_progress, because we already did that above
|
2017-03-25 13:40:48 +02:00
|
|
|
if (mv->ref[0] != ref && mv->ref[0] >= 0)
|
2017-03-25 13:10:13 +02:00
|
|
|
RETURN_SCALE_MV(mv->mv[0], s->s.h.signbias[mv->ref[0]] != s->s.h.signbias[ref]);
|
|
|
|
if (mv->ref[1] != ref && mv->ref[1] >= 0 &&
|
|
|
|
// BUG - libvpx has this condition regardless of whether
|
|
|
|
// we used the first ref MV and pre-scaling
|
|
|
|
AV_RN32A(&mv->mv[0]) != AV_RN32A(&mv->mv[1])) {
|
|
|
|
RETURN_SCALE_MV(mv->mv[1], s->s.h.signbias[mv->ref[1]] != s->s.h.signbias[ref]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AV_ZERO32(pmv);
|
2017-09-07 23:02:49 +02:00
|
|
|
clamp_mv(pmv, pmv, td);
|
2017-03-25 13:10:13 +02:00
|
|
|
#undef INVALID_MV
|
|
|
|
#undef RETURN_MV
|
|
|
|
#undef RETURN_SCALE_MV
|
|
|
|
}
|
|
|
|
|
2017-09-07 23:02:49 +02:00
|
|
|
static av_always_inline int read_mv_component(VP9TileData *td, int idx, int hp)
|
2017-03-25 13:10:13 +02:00
|
|
|
{
|
2022-07-23 03:34:17 +02:00
|
|
|
const VP9Context *s = td->s;
|
2022-07-23 01:28:48 +02:00
|
|
|
int bit, sign = vpx_rac_get_prob(td->c, s->prob.p.mv_comp[idx].sign);
|
2022-07-23 00:04:29 +02:00
|
|
|
int n, c = vp89_rac_get_tree(td->c, ff_vp9_mv_class_tree,
|
|
|
|
s->prob.p.mv_comp[idx].classes);
|
2017-03-25 13:10:13 +02:00
|
|
|
|
2017-09-07 23:02:49 +02:00
|
|
|
td->counts.mv_comp[idx].sign[sign]++;
|
|
|
|
td->counts.mv_comp[idx].classes[c]++;
|
2017-03-25 13:10:13 +02:00
|
|
|
if (c) {
|
|
|
|
int m;
|
|
|
|
|
|
|
|
for (n = 0, m = 0; m < c; m++) {
|
2022-07-23 01:28:48 +02:00
|
|
|
bit = vpx_rac_get_prob(td->c, s->prob.p.mv_comp[idx].bits[m]);
|
2017-03-25 13:10:13 +02:00
|
|
|
n |= bit << m;
|
2017-09-07 23:02:49 +02:00
|
|
|
td->counts.mv_comp[idx].bits[m][bit]++;
|
2017-03-25 13:10:13 +02:00
|
|
|
}
|
|
|
|
n <<= 3;
|
2022-07-23 00:04:29 +02:00
|
|
|
bit = vp89_rac_get_tree(td->c, ff_vp9_mv_fp_tree,
|
|
|
|
s->prob.p.mv_comp[idx].fp);
|
2017-03-25 13:40:48 +02:00
|
|
|
n |= bit << 1;
|
2017-09-07 23:02:49 +02:00
|
|
|
td->counts.mv_comp[idx].fp[bit]++;
|
2017-03-25 13:10:13 +02:00
|
|
|
if (hp) {
|
2022-07-23 01:28:48 +02:00
|
|
|
bit = vpx_rac_get_prob(td->c, s->prob.p.mv_comp[idx].hp);
|
2017-09-07 23:02:49 +02:00
|
|
|
td->counts.mv_comp[idx].hp[bit]++;
|
2017-03-25 13:10:13 +02:00
|
|
|
n |= bit;
|
|
|
|
} else {
|
|
|
|
n |= 1;
|
|
|
|
// bug in libvpx - we count for bw entropy purposes even if the
|
|
|
|
// bit wasn't coded
|
2017-09-07 23:02:49 +02:00
|
|
|
td->counts.mv_comp[idx].hp[1]++;
|
2017-03-25 13:10:13 +02:00
|
|
|
}
|
|
|
|
n += 8 << c;
|
|
|
|
} else {
|
2022-07-23 01:28:48 +02:00
|
|
|
n = vpx_rac_get_prob(td->c, s->prob.p.mv_comp[idx].class0);
|
2017-09-07 23:02:49 +02:00
|
|
|
td->counts.mv_comp[idx].class0[n]++;
|
2022-07-23 00:04:29 +02:00
|
|
|
bit = vp89_rac_get_tree(td->c, ff_vp9_mv_fp_tree,
|
|
|
|
s->prob.p.mv_comp[idx].class0_fp[n]);
|
2017-09-07 23:02:49 +02:00
|
|
|
td->counts.mv_comp[idx].class0_fp[n][bit]++;
|
2017-03-25 13:10:13 +02:00
|
|
|
n = (n << 3) | (bit << 1);
|
|
|
|
if (hp) {
|
2022-07-23 01:28:48 +02:00
|
|
|
bit = vpx_rac_get_prob(td->c, s->prob.p.mv_comp[idx].class0_hp);
|
2017-09-07 23:02:49 +02:00
|
|
|
td->counts.mv_comp[idx].class0_hp[bit]++;
|
2017-03-25 13:10:13 +02:00
|
|
|
n |= bit;
|
|
|
|
} else {
|
|
|
|
n |= 1;
|
|
|
|
// bug in libvpx - we count for bw entropy purposes even if the
|
|
|
|
// bit wasn't coded
|
2017-09-07 23:02:49 +02:00
|
|
|
td->counts.mv_comp[idx].class0_hp[1]++;
|
2017-03-25 13:10:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sign ? -(n + 1) : (n + 1);
|
|
|
|
}
|
|
|
|
|
avcodec/vp8, vp9: Avoid using VP56mv and VP56Frame in VP8/9
Instead replace VP56mv by new and identical structures VP8mv and VP9mv.
Also replace VP56Frame by VP8FrameType in vp8.h and use that
in VP8 code. Also remove VP56_FRAME_GOLDEN2, as this has only
been used by VP8, and use VP8_FRAME_ALTREF as replacement for
its usage in VP8 as this is more in line with VP8 verbiage.
This allows to remove all inclusions of vp56.h from everything
that is not VP5/6. This also removes implicit inclusions
of hpeldsp.h, h264chroma.h, vp3dsp.h and vp56dsp.h from all VP8/9
files.
(This also fixes a build issue: If one compiles with -O0 and disables
everything except the VP8-VAAPI encoder, the file containing
ff_vpx_norm_shift is not compiled, yet this is used implicitly
by vp56_rac_gets_nn() which is defined in vp56.h; it is unused
by the VP8-VAAPI encoder and declared as av_unused, yet with -O0
unused noninline functions are not optimized away, leading to
linking failures. With this patch, said function is not included
in vaapi_encode_vp8.c any more.)
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-07-23 02:01:41 +02:00
|
|
|
void ff_vp9_fill_mv(VP9TileData *td, VP9mv *mv, int mode, int sb)
|
2017-03-25 13:10:13 +02:00
|
|
|
{
|
2022-07-23 03:34:17 +02:00
|
|
|
const VP9Context *s = td->s;
|
2017-09-07 23:02:49 +02:00
|
|
|
VP9Block *b = td->b;
|
2017-03-25 13:10:13 +02:00
|
|
|
|
|
|
|
if (mode == ZEROMV) {
|
|
|
|
AV_ZERO64(mv);
|
|
|
|
} else {
|
|
|
|
int hp;
|
|
|
|
|
|
|
|
// FIXME cache this value and reuse for other subblocks
|
2017-09-07 23:02:49 +02:00
|
|
|
find_ref_mvs(td, &mv[0], b->ref[0], 0, mode == NEARMV,
|
2017-03-25 13:10:13 +02:00
|
|
|
mode == NEWMV ? -1 : sb);
|
|
|
|
// FIXME maybe move this code into find_ref_mvs()
|
|
|
|
if ((mode == NEWMV || sb == -1) &&
|
2017-03-25 13:40:48 +02:00
|
|
|
!(hp = s->s.h.highprecisionmvs &&
|
|
|
|
abs(mv[0].x) < 64 && abs(mv[0].y) < 64)) {
|
2017-03-25 13:10:13 +02:00
|
|
|
if (mv[0].y & 1) {
|
|
|
|
if (mv[0].y < 0)
|
|
|
|
mv[0].y++;
|
|
|
|
else
|
|
|
|
mv[0].y--;
|
|
|
|
}
|
|
|
|
if (mv[0].x & 1) {
|
|
|
|
if (mv[0].x < 0)
|
|
|
|
mv[0].x++;
|
|
|
|
else
|
|
|
|
mv[0].x--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mode == NEWMV) {
|
2022-07-23 00:04:29 +02:00
|
|
|
enum MVJoint j = vp89_rac_get_tree(td->c, ff_vp9_mv_joint_tree,
|
|
|
|
s->prob.p.mv_joint);
|
2017-03-25 13:10:13 +02:00
|
|
|
|
2017-09-07 23:02:49 +02:00
|
|
|
td->counts.mv_joint[j]++;
|
2017-03-25 13:10:13 +02:00
|
|
|
if (j >= MV_JOINT_V)
|
2017-09-07 23:02:49 +02:00
|
|
|
mv[0].y += read_mv_component(td, 0, hp);
|
2017-03-25 13:10:13 +02:00
|
|
|
if (j & 1)
|
2017-09-07 23:02:49 +02:00
|
|
|
mv[0].x += read_mv_component(td, 1, hp);
|
2017-03-25 13:10:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (b->comp) {
|
|
|
|
// FIXME cache this value and reuse for other subblocks
|
2017-09-07 23:02:49 +02:00
|
|
|
find_ref_mvs(td, &mv[1], b->ref[1], 1, mode == NEARMV,
|
2017-03-25 13:10:13 +02:00
|
|
|
mode == NEWMV ? -1 : sb);
|
|
|
|
if ((mode == NEWMV || sb == -1) &&
|
2017-03-25 13:40:48 +02:00
|
|
|
!(hp = s->s.h.highprecisionmvs &&
|
|
|
|
abs(mv[1].x) < 64 && abs(mv[1].y) < 64)) {
|
2017-03-25 13:10:13 +02:00
|
|
|
if (mv[1].y & 1) {
|
|
|
|
if (mv[1].y < 0)
|
|
|
|
mv[1].y++;
|
|
|
|
else
|
|
|
|
mv[1].y--;
|
|
|
|
}
|
|
|
|
if (mv[1].x & 1) {
|
|
|
|
if (mv[1].x < 0)
|
|
|
|
mv[1].x++;
|
|
|
|
else
|
|
|
|
mv[1].x--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mode == NEWMV) {
|
2022-07-23 00:04:29 +02:00
|
|
|
enum MVJoint j = vp89_rac_get_tree(td->c, ff_vp9_mv_joint_tree,
|
|
|
|
s->prob.p.mv_joint);
|
2017-03-25 13:10:13 +02:00
|
|
|
|
2017-09-07 23:02:49 +02:00
|
|
|
td->counts.mv_joint[j]++;
|
2017-03-25 13:10:13 +02:00
|
|
|
if (j >= MV_JOINT_V)
|
2017-09-07 23:02:49 +02:00
|
|
|
mv[1].y += read_mv_component(td, 0, hp);
|
2017-03-25 13:10:13 +02:00
|
|
|
if (j & 1)
|
2017-09-07 23:02:49 +02:00
|
|
|
mv[1].x += read_mv_component(td, 1, hp);
|
2017-03-25 13:10:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|