Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlia Valiakhmetov <zakne0ne@gmail.com>2017-09-08 00:02:49 +0300
committerRonald S. Bultje <rsbultje@gmail.com>2017-09-08 17:25:40 +0300
commite59da0f7ff129d570adb72c6479f7ce07cf5a0f9 (patch)
treecbcc6765a25e8ef9076e1fd00d147e7a886d885e /libavcodec/vp9mvs.c
parent83c12fefd22fc2326a000019e5c1a33e90a874e8 (diff)
avcodec/vp9: Add tile threading support
Signed-off-by: Ilia Valiakhmetov <zakne0ne@gmail.com> Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
Diffstat (limited to 'libavcodec/vp9mvs.c')
-rw-r--r--libavcodec/vp9mvs.c97
1 files changed, 50 insertions, 47 deletions
diff --git a/libavcodec/vp9mvs.c b/libavcodec/vp9mvs.c
index e323bacc49..88db1c341c 100644
--- a/libavcodec/vp9mvs.c
+++ b/libavcodec/vp9mvs.c
@@ -28,13 +28,13 @@
#include "vp9dec.h"
static av_always_inline void clamp_mv(VP56mv *dst, const VP56mv *src,
- VP9Context *s)
+ VP9TileData *td)
{
- dst->x = av_clip(src->x, s->min_mv.x, s->max_mv.x);
- dst->y = av_clip(src->y, s->min_mv.y, s->max_mv.y);
+ 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);
}
-static void find_ref_mvs(VP9Context *s,
+static void find_ref_mvs(VP9TileData *td,
VP56mv *pmv, int ref, int z, int idx, int sb)
{
static const int8_t mv_ref_blk_off[N_BS_SIZES][8][2] = {
@@ -65,8 +65,9 @@ static void find_ref_mvs(VP9Context *s,
[BS_4x4] = { { 0, -1 }, { -1, 0 }, { -1, -1 }, { 0, -2 },
{ -2, 0 }, { -1, -2 }, { -2, -1 }, { -2, -2 } },
};
- VP9Block *b = s->b;
- int row = s->row, col = s->col, row7 = s->row7;
+ VP9Context *s = td->s;
+ VP9Block *b = td->b;
+ int row = td->row, col = td->col, row7 = td->row7;
const int8_t (*p)[2] = mv_ref_blk_off[b->bs];
#define INVALID_MV 0x80008000U
uint32_t mem = INVALID_MV, mem_sub8x8 = INVALID_MV;
@@ -103,7 +104,7 @@ static void find_ref_mvs(VP9Context *s,
av_assert2(idx == 1); \
av_assert2(mem != INVALID_MV); \
if (mem_sub8x8 == INVALID_MV) { \
- clamp_mv(&tmp, &mv, s); \
+ clamp_mv(&tmp, &mv, td); \
m = AV_RN32A(&tmp); \
if (m != mem) { \
AV_WN32A(pmv, m); \
@@ -111,7 +112,7 @@ static void find_ref_mvs(VP9Context *s,
} \
mem_sub8x8 = AV_RN32A(&mv); \
} else if (mem_sub8x8 != AV_RN32A(&mv)) { \
- clamp_mv(&tmp, &mv, s); \
+ clamp_mv(&tmp, &mv, td); \
m = AV_RN32A(&tmp); \
if (m != mem) { \
AV_WN32A(pmv, m); \
@@ -124,12 +125,12 @@ static void find_ref_mvs(VP9Context *s,
} else { \
uint32_t m = AV_RN32A(&mv); \
if (!idx) { \
- clamp_mv(pmv, &mv, s); \
+ clamp_mv(pmv, &mv, td); \
return; \
} else if (mem == INVALID_MV) { \
mem = m; \
} else if (m != mem) { \
- clamp_mv(pmv, &mv, s); \
+ clamp_mv(pmv, &mv, td); \
return; \
} \
} \
@@ -142,12 +143,12 @@ static void find_ref_mvs(VP9Context *s,
else if (mv->ref[1] == ref)
RETURN_MV(s->above_mv_ctx[2 * col + (sb & 1)][1]);
}
- if (col > s->tile_col_start) {
+ if (col > td->tile_col_start) {
VP9mvrefPair *mv = &s->s.frames[CUR_FRAME].mv[row * s->sb_cols * 8 + col - 1];
if (mv->ref[0] == ref)
- RETURN_MV(s->left_mv_ctx[2 * row7 + (sb >> 1)][0]);
+ RETURN_MV(td->left_mv_ctx[2 * row7 + (sb >> 1)][0]);
else if (mv->ref[1] == ref)
- RETURN_MV(s->left_mv_ctx[2 * row7 + (sb >> 1)][1]);
+ RETURN_MV(td->left_mv_ctx[2 * row7 + (sb >> 1)][1]);
}
i = 2;
} else {
@@ -158,7 +159,7 @@ static void find_ref_mvs(VP9Context *s,
for (; i < 8; i++) {
int c = p[i][0] + col, r = p[i][1] + row;
- if (c >= s->tile_col_start && c < s->cols &&
+ if (c >= td->tile_col_start && c < s->cols &&
r >= 0 && r < s->rows) {
VP9mvrefPair *mv = &s->s.frames[CUR_FRAME].mv[r * s->sb_cols * 8 + c];
@@ -195,7 +196,7 @@ static void find_ref_mvs(VP9Context *s,
for (i = 0; i < 8; i++) {
int c = p[i][0] + col, r = p[i][1] + row;
- if (c >= s->tile_col_start && c < s->cols && r >= 0 && r < s->rows) {
+ if (c >= td->tile_col_start && c < s->cols && r >= 0 && r < s->rows) {
VP9mvrefPair *mv = &s->s.frames[CUR_FRAME].mv[r * s->sb_cols * 8 + c];
if (mv->ref[0] != ref && mv->ref[0] >= 0)
@@ -226,69 +227,71 @@ static void find_ref_mvs(VP9Context *s,
}
AV_ZERO32(pmv);
- clamp_mv(pmv, pmv, s);
+ clamp_mv(pmv, pmv, td);
#undef INVALID_MV
#undef RETURN_MV
#undef RETURN_SCALE_MV
}
-static av_always_inline int read_mv_component(VP9Context *s, int idx, int hp)
+static av_always_inline int read_mv_component(VP9TileData *td, int idx, int hp)
{
- int bit, sign = vp56_rac_get_prob(&s->c, s->prob.p.mv_comp[idx].sign);
- int n, c = vp8_rac_get_tree(&s->c, ff_vp9_mv_class_tree,
+ VP9Context *s = td->s;
+ int bit, sign = vp56_rac_get_prob(td->c, s->prob.p.mv_comp[idx].sign);
+ int n, c = vp8_rac_get_tree(td->c, ff_vp9_mv_class_tree,
s->prob.p.mv_comp[idx].classes);
- s->counts.mv_comp[idx].sign[sign]++;
- s->counts.mv_comp[idx].classes[c]++;
+ td->counts.mv_comp[idx].sign[sign]++;
+ td->counts.mv_comp[idx].classes[c]++;
if (c) {
int m;
for (n = 0, m = 0; m < c; m++) {
- bit = vp56_rac_get_prob(&s->c, s->prob.p.mv_comp[idx].bits[m]);
+ bit = vp56_rac_get_prob(td->c, s->prob.p.mv_comp[idx].bits[m]);
n |= bit << m;
- s->counts.mv_comp[idx].bits[m][bit]++;
+ td->counts.mv_comp[idx].bits[m][bit]++;
}
n <<= 3;
- bit = vp8_rac_get_tree(&s->c, ff_vp9_mv_fp_tree,
+ bit = vp8_rac_get_tree(td->c, ff_vp9_mv_fp_tree,
s->prob.p.mv_comp[idx].fp);
n |= bit << 1;
- s->counts.mv_comp[idx].fp[bit]++;
+ td->counts.mv_comp[idx].fp[bit]++;
if (hp) {
- bit = vp56_rac_get_prob(&s->c, s->prob.p.mv_comp[idx].hp);
- s->counts.mv_comp[idx].hp[bit]++;
+ bit = vp56_rac_get_prob(td->c, s->prob.p.mv_comp[idx].hp);
+ td->counts.mv_comp[idx].hp[bit]++;
n |= bit;
} else {
n |= 1;
// bug in libvpx - we count for bw entropy purposes even if the
// bit wasn't coded
- s->counts.mv_comp[idx].hp[1]++;
+ td->counts.mv_comp[idx].hp[1]++;
}
n += 8 << c;
} else {
- n = vp56_rac_get_prob(&s->c, s->prob.p.mv_comp[idx].class0);
- s->counts.mv_comp[idx].class0[n]++;
- bit = vp8_rac_get_tree(&s->c, ff_vp9_mv_fp_tree,
+ n = vp56_rac_get_prob(td->c, s->prob.p.mv_comp[idx].class0);
+ td->counts.mv_comp[idx].class0[n]++;
+ bit = vp8_rac_get_tree(td->c, ff_vp9_mv_fp_tree,
s->prob.p.mv_comp[idx].class0_fp[n]);
- s->counts.mv_comp[idx].class0_fp[n][bit]++;
+ td->counts.mv_comp[idx].class0_fp[n][bit]++;
n = (n << 3) | (bit << 1);
if (hp) {
- bit = vp56_rac_get_prob(&s->c, s->prob.p.mv_comp[idx].class0_hp);
- s->counts.mv_comp[idx].class0_hp[bit]++;
+ bit = vp56_rac_get_prob(td->c, s->prob.p.mv_comp[idx].class0_hp);
+ td->counts.mv_comp[idx].class0_hp[bit]++;
n |= bit;
} else {
n |= 1;
// bug in libvpx - we count for bw entropy purposes even if the
// bit wasn't coded
- s->counts.mv_comp[idx].class0_hp[1]++;
+ td->counts.mv_comp[idx].class0_hp[1]++;
}
}
return sign ? -(n + 1) : (n + 1);
}
-void ff_vp9_fill_mv(VP9Context *s, VP56mv *mv, int mode, int sb)
+void ff_vp9_fill_mv(VP9TileData *td, VP56mv *mv, int mode, int sb)
{
- VP9Block *b = s->b;
+ VP9Context *s = td->s;
+ VP9Block *b = td->b;
if (mode == ZEROMV) {
AV_ZERO64(mv);
@@ -296,7 +299,7 @@ void ff_vp9_fill_mv(VP9Context *s, VP56mv *mv, int mode, int sb)
int hp;
// FIXME cache this value and reuse for other subblocks
- find_ref_mvs(s, &mv[0], b->ref[0], 0, mode == NEARMV,
+ find_ref_mvs(td, &mv[0], b->ref[0], 0, mode == NEARMV,
mode == NEWMV ? -1 : sb);
// FIXME maybe move this code into find_ref_mvs()
if ((mode == NEWMV || sb == -1) &&
@@ -316,19 +319,19 @@ void ff_vp9_fill_mv(VP9Context *s, VP56mv *mv, int mode, int sb)
}
}
if (mode == NEWMV) {
- enum MVJoint j = vp8_rac_get_tree(&s->c, ff_vp9_mv_joint_tree,
+ enum MVJoint j = vp8_rac_get_tree(td->c, ff_vp9_mv_joint_tree,
s->prob.p.mv_joint);
- s->counts.mv_joint[j]++;
+ td->counts.mv_joint[j]++;
if (j >= MV_JOINT_V)
- mv[0].y += read_mv_component(s, 0, hp);
+ mv[0].y += read_mv_component(td, 0, hp);
if (j & 1)
- mv[0].x += read_mv_component(s, 1, hp);
+ mv[0].x += read_mv_component(td, 1, hp);
}
if (b->comp) {
// FIXME cache this value and reuse for other subblocks
- find_ref_mvs(s, &mv[1], b->ref[1], 1, mode == NEARMV,
+ find_ref_mvs(td, &mv[1], b->ref[1], 1, mode == NEARMV,
mode == NEWMV ? -1 : sb);
if ((mode == NEWMV || sb == -1) &&
!(hp = s->s.h.highprecisionmvs &&
@@ -347,14 +350,14 @@ void ff_vp9_fill_mv(VP9Context *s, VP56mv *mv, int mode, int sb)
}
}
if (mode == NEWMV) {
- enum MVJoint j = vp8_rac_get_tree(&s->c, ff_vp9_mv_joint_tree,
+ enum MVJoint j = vp8_rac_get_tree(td->c, ff_vp9_mv_joint_tree,
s->prob.p.mv_joint);
- s->counts.mv_joint[j]++;
+ td->counts.mv_joint[j]++;
if (j >= MV_JOINT_V)
- mv[1].y += read_mv_component(s, 0, hp);
+ mv[1].y += read_mv_component(td, 0, hp);
if (j & 1)
- mv[1].x += read_mv_component(s, 1, hp);
+ mv[1].x += read_mv_component(td, 1, hp);
}
}
}