2012-08-24 16:44:01 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2012 The WebM project authors. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
*/
|
|
|
|
|
2012-11-28 19:41:40 +01:00
|
|
|
#include "vp9/common/vp9_mvref_common.h"
|
2012-08-24 16:44:01 +02:00
|
|
|
|
|
|
|
#define MVREF_NEIGHBOURS 8
|
2013-03-05 23:12:16 +01:00
|
|
|
|
2012-11-16 15:31:53 +01:00
|
|
|
static int mb_mv_ref_search[MVREF_NEIGHBOURS][2] = {
|
|
|
|
{0, -1}, {-1, 0}, {-1, -1}, {0, -2},
|
|
|
|
{-2, 0}, {-1, -2}, {-2, -1}, {-2, -2}
|
|
|
|
};
|
2013-03-05 23:12:16 +01:00
|
|
|
|
2012-11-16 15:31:53 +01:00
|
|
|
static int mb_ref_distance_weight[MVREF_NEIGHBOURS] =
|
|
|
|
{ 3, 3, 2, 1, 1, 1, 1, 1 };
|
2013-03-05 23:12:16 +01:00
|
|
|
|
2012-11-16 15:31:53 +01:00
|
|
|
static int sb_mv_ref_search[MVREF_NEIGHBOURS][2] = {
|
|
|
|
{0, -1}, {-1, 0}, {1, -1}, {-1, 1},
|
|
|
|
{-1, -1}, {0, -2}, {-2, 0}, {-1, -2}
|
|
|
|
};
|
2013-03-05 23:12:16 +01:00
|
|
|
|
2012-11-16 15:31:53 +01:00
|
|
|
static int sb_ref_distance_weight[MVREF_NEIGHBOURS] =
|
|
|
|
{ 3, 3, 2, 2, 2, 1, 1, 1 };
|
2013-01-03 16:14:36 +01:00
|
|
|
|
2013-01-24 13:52:13 +01:00
|
|
|
// clamp_mv_ref
|
2012-08-24 16:44:01 +02:00
|
|
|
#define MV_BORDER (16 << 3) // Allow 16 pels in 1/8th pel units
|
|
|
|
|
2013-03-05 23:12:16 +01:00
|
|
|
static void clamp_mv_ref(const MACROBLOCKD *xd, int_mv *mv) {
|
2012-08-24 16:44:01 +02:00
|
|
|
if (mv->as_mv.col < (xd->mb_to_left_edge - MV_BORDER))
|
|
|
|
mv->as_mv.col = xd->mb_to_left_edge - MV_BORDER;
|
|
|
|
else if (mv->as_mv.col > xd->mb_to_right_edge + MV_BORDER)
|
|
|
|
mv->as_mv.col = xd->mb_to_right_edge + MV_BORDER;
|
|
|
|
|
|
|
|
if (mv->as_mv.row < (xd->mb_to_top_edge - MV_BORDER))
|
|
|
|
mv->as_mv.row = xd->mb_to_top_edge - MV_BORDER;
|
|
|
|
else if (mv->as_mv.row > xd->mb_to_bottom_edge + MV_BORDER)
|
|
|
|
mv->as_mv.row = xd->mb_to_bottom_edge + MV_BORDER;
|
|
|
|
}
|
|
|
|
|
2013-01-03 16:14:36 +01:00
|
|
|
// Gets a candidate refenence motion vector from the given mode info
|
|
|
|
// structure if one exists that matches the given reference frame.
|
2013-03-05 23:12:16 +01:00
|
|
|
static int get_matching_candidate(const MODE_INFO *candidate_mi,
|
2013-01-03 16:14:36 +01:00
|
|
|
MV_REFERENCE_FRAME ref_frame,
|
2013-03-05 23:12:16 +01:00
|
|
|
int_mv *c_mv) {
|
2013-01-03 16:14:36 +01:00
|
|
|
int ret_val = TRUE;
|
|
|
|
|
|
|
|
if (ref_frame == candidate_mi->mbmi.ref_frame) {
|
|
|
|
c_mv->as_int = candidate_mi->mbmi.mv[0].as_int;
|
|
|
|
} else if (ref_frame == candidate_mi->mbmi.second_ref_frame) {
|
|
|
|
c_mv->as_int = candidate_mi->mbmi.mv[1].as_int;
|
|
|
|
} else {
|
|
|
|
ret_val = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret_val;
|
|
|
|
}
|
2012-08-24 16:44:01 +02:00
|
|
|
|
2013-01-03 16:14:36 +01:00
|
|
|
// Gets candidate refenence motion vector(s) from the given mode info
|
|
|
|
// structure if they exists and do NOT match the given reference frame.
|
|
|
|
static void get_non_matching_candidates(
|
2012-08-24 16:44:01 +02:00
|
|
|
const MODE_INFO *candidate_mi,
|
|
|
|
MV_REFERENCE_FRAME ref_frame,
|
2012-09-07 13:46:41 +02:00
|
|
|
MV_REFERENCE_FRAME *c_ref_frame,
|
|
|
|
int_mv *c_mv,
|
|
|
|
MV_REFERENCE_FRAME *c2_ref_frame,
|
|
|
|
int_mv *c2_mv
|
2012-08-24 16:44:01 +02:00
|
|
|
) {
|
|
|
|
|
2013-01-03 16:14:36 +01:00
|
|
|
c_mv->as_int = 0;
|
2012-09-07 13:46:41 +02:00
|
|
|
c2_mv->as_int = 0;
|
2013-01-03 16:14:36 +01:00
|
|
|
*c_ref_frame = INTRA_FRAME;
|
2012-09-07 13:46:41 +02:00
|
|
|
*c2_ref_frame = INTRA_FRAME;
|
2012-08-24 16:44:01 +02:00
|
|
|
|
2013-01-03 16:14:36 +01:00
|
|
|
// If first candidate not valid neither will be.
|
|
|
|
if (candidate_mi->mbmi.ref_frame > INTRA_FRAME) {
|
|
|
|
// First candidate
|
|
|
|
if (candidate_mi->mbmi.ref_frame != ref_frame) {
|
|
|
|
*c_ref_frame = candidate_mi->mbmi.ref_frame;
|
|
|
|
c_mv->as_int = candidate_mi->mbmi.mv[0].as_int;
|
2012-09-07 13:46:41 +02:00
|
|
|
}
|
|
|
|
|
2013-01-03 16:14:36 +01:00
|
|
|
// Second candidate
|
2012-11-07 15:50:25 +01:00
|
|
|
if ((candidate_mi->mbmi.second_ref_frame > INTRA_FRAME) &&
|
2013-01-24 13:52:13 +01:00
|
|
|
(candidate_mi->mbmi.second_ref_frame != ref_frame) &&
|
|
|
|
(candidate_mi->mbmi.mv[1].as_int !=
|
|
|
|
candidate_mi->mbmi.mv[0].as_int)) {
|
2012-09-07 13:46:41 +02:00
|
|
|
*c2_ref_frame = candidate_mi->mbmi.second_ref_frame;
|
2013-01-03 16:14:36 +01:00
|
|
|
c2_mv->as_int = candidate_mi->mbmi.mv[1].as_int;
|
2012-09-07 13:46:41 +02:00
|
|
|
}
|
2012-08-24 16:44:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-24 13:52:13 +01:00
|
|
|
|
|
|
|
// Performs mv sign inversion if indicated by the reference frame combination.
|
2012-10-29 14:44:18 +01:00
|
|
|
static void scale_mv(
|
2012-08-24 16:44:01 +02:00
|
|
|
MACROBLOCKD *xd,
|
|
|
|
MV_REFERENCE_FRAME this_ref_frame,
|
|
|
|
MV_REFERENCE_FRAME candidate_ref_frame,
|
|
|
|
int_mv *candidate_mv,
|
|
|
|
int *ref_sign_bias
|
|
|
|
) {
|
2013-01-24 13:52:13 +01:00
|
|
|
// int frame_distances[MAX_REF_FRAMES];
|
|
|
|
// int last_distance = 1;
|
|
|
|
// int gf_distance = xd->frames_since_golden;
|
|
|
|
// int arf_distance = xd->frames_till_alt_ref_frame;
|
|
|
|
|
|
|
|
// Sign inversion where appropriate.
|
|
|
|
if (ref_sign_bias[candidate_ref_frame] != ref_sign_bias[this_ref_frame]) {
|
|
|
|
candidate_mv->as_mv.row = -candidate_mv->as_mv.row;
|
|
|
|
candidate_mv->as_mv.col = -candidate_mv->as_mv.col;
|
2012-08-24 16:44:01 +02:00
|
|
|
}
|
|
|
|
|
2013-01-24 13:52:13 +01:00
|
|
|
/*
|
|
|
|
// Scale based on frame distance if the reference frames not the same.
|
|
|
|
frame_distances[INTRA_FRAME] = 1; // should never be used
|
|
|
|
frame_distances[LAST_FRAME] = 1;
|
|
|
|
frame_distances[GOLDEN_FRAME] =
|
|
|
|
(xd->frames_since_golden) ? xd->frames_si nce_golden : 1;
|
|
|
|
frame_distances[ALTREF_FRAME] =
|
|
|
|
(xd->frames_till_alt_ref_frame) ? xd->frames_till_alt_ref_frame : 1;
|
|
|
|
|
|
|
|
if (frame_distances[this_ref_frame] &&
|
|
|
|
frame_distances[candidate_ref_frame]) {
|
|
|
|
candidate_mv->as_mv.row =
|
|
|
|
(short)(((int)(candidate_mv->as_mv.row) *
|
|
|
|
frame_distances[this_ref_frame]) /
|
|
|
|
frame_distances[candidate_ref_frame]);
|
|
|
|
|
|
|
|
candidate_mv->as_mv.col =
|
|
|
|
(short)(((int)(candidate_mv->as_mv.col) *
|
|
|
|
frame_distances[this_ref_frame]) /
|
|
|
|
frame_distances[candidate_ref_frame]);
|
|
|
|
}
|
|
|
|
*/
|
2012-08-24 16:44:01 +02:00
|
|
|
}
|
|
|
|
|
2013-01-24 13:52:13 +01:00
|
|
|
/*
|
|
|
|
// Adds a new candidate reference vector to the sorted list.
|
|
|
|
// If it is a repeat the weight of the existing entry is increased
|
|
|
|
// and the order of the list is resorted.
|
|
|
|
// This method of add plus sort has been deprecated for now as there is a
|
|
|
|
// further sort of the best candidates in vp9_find_best_ref_mvs() and the
|
|
|
|
// incremental benefit of both is small. If the decision is made to remove
|
|
|
|
// the sort in vp9_find_best_ref_mvs() for performance reasons then it may be
|
|
|
|
// worth re-instating some sort of list reordering by weight here.
|
|
|
|
//
|
2012-10-29 14:44:18 +01:00
|
|
|
static void addmv_and_shuffle(
|
2012-08-24 16:44:01 +02:00
|
|
|
int_mv *mv_list,
|
|
|
|
int *mv_scores,
|
2013-01-24 13:52:13 +01:00
|
|
|
int *refmv_count,
|
2012-08-24 16:44:01 +02:00
|
|
|
int_mv candidate_mv,
|
|
|
|
int weight
|
|
|
|
) {
|
|
|
|
|
2012-12-04 18:21:05 +01:00
|
|
|
int i;
|
|
|
|
int insert_point;
|
2012-08-24 16:44:01 +02:00
|
|
|
int duplicate_found = FALSE;
|
|
|
|
|
2012-12-04 18:21:05 +01:00
|
|
|
// Check for duplicates. If there is one increase its score.
|
|
|
|
// We only compare vs the current top candidates.
|
2013-01-24 13:52:13 +01:00
|
|
|
insert_point = (*refmv_count < (MAX_MV_REF_CANDIDATES - 1))
|
|
|
|
? *refmv_count : (MAX_MV_REF_CANDIDATES - 1);
|
2012-12-04 18:21:05 +01:00
|
|
|
|
|
|
|
i = insert_point;
|
2013-01-24 13:52:13 +01:00
|
|
|
if (*refmv_count > i)
|
2012-12-04 18:21:05 +01:00
|
|
|
i++;
|
2012-08-24 16:44:01 +02:00
|
|
|
while (i > 0) {
|
|
|
|
i--;
|
|
|
|
if (candidate_mv.as_int == mv_list[i].as_int) {
|
|
|
|
duplicate_found = TRUE;
|
|
|
|
mv_scores[i] += weight;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-04 18:21:05 +01:00
|
|
|
// If no duplicate and the new candidate is good enough then add it.
|
|
|
|
if (!duplicate_found ) {
|
|
|
|
if (weight > mv_scores[insert_point]) {
|
|
|
|
mv_list[insert_point].as_int = candidate_mv.as_int;
|
|
|
|
mv_scores[insert_point] = weight;
|
|
|
|
i = insert_point;
|
|
|
|
}
|
2013-01-24 13:52:13 +01:00
|
|
|
(*refmv_count)++;
|
2012-08-24 16:44:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Reshuffle the list so that highest scoring mvs at the top.
|
|
|
|
while (i > 0) {
|
|
|
|
if (mv_scores[i] > mv_scores[i-1]) {
|
|
|
|
int tmp_score = mv_scores[i-1];
|
|
|
|
int_mv tmp_mv = mv_list[i-1];
|
|
|
|
|
|
|
|
mv_scores[i-1] = mv_scores[i];
|
|
|
|
mv_list[i-1] = mv_list[i];
|
|
|
|
mv_scores[i] = tmp_score;
|
|
|
|
mv_list[i] = tmp_mv;
|
|
|
|
i--;
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-01-24 13:52:13 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
// Adds a new candidate reference vector to the list.
|
|
|
|
// The mv is thrown out if it is already in the list.
|
|
|
|
// Unlike the addmv_and_shuffle() this does not reorder the list
|
|
|
|
// but assumes that candidates are added in the order most likely to
|
|
|
|
// match distance and reference frame bias.
|
|
|
|
static void add_candidate_mv(
|
|
|
|
int_mv *mv_list,
|
|
|
|
int *mv_scores,
|
|
|
|
int *candidate_count,
|
|
|
|
int_mv candidate_mv,
|
|
|
|
int weight
|
|
|
|
) {
|
|
|
|
int i;
|
|
|
|
int insert_point;
|
|
|
|
|
|
|
|
// Make sure we dont insert off the end of the list
|
|
|
|
insert_point = (*candidate_count < (MAX_MV_REF_CANDIDATES - 1))
|
|
|
|
? *candidate_count : (MAX_MV_REF_CANDIDATES - 1);
|
|
|
|
|
|
|
|
// Look for duplicates
|
|
|
|
for (i = 0; i <= insert_point; ++i) {
|
|
|
|
if (candidate_mv.as_int == mv_list[i].as_int)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the candidate. If the list is already full it is only desirable that
|
|
|
|
// it should overwrite if it has a higher weight than the last entry.
|
|
|
|
if ((i >= insert_point) &&
|
|
|
|
(weight > mv_scores[insert_point])) {
|
|
|
|
mv_list[insert_point].as_int = candidate_mv.as_int;
|
|
|
|
mv_scores[insert_point] = weight;
|
|
|
|
*candidate_count += (*candidate_count < MAX_MV_REF_CANDIDATES);
|
|
|
|
}
|
|
|
|
}
|
2012-08-24 16:44:01 +02:00
|
|
|
|
|
|
|
// This function searches the neighbourhood of a given MB/SB and populates a
|
|
|
|
// list of candidate reference vectors.
|
|
|
|
//
|
2012-10-29 14:44:18 +01:00
|
|
|
void vp9_find_mv_refs(
|
[WIP] Add column-based tiling.
This patch adds column-based tiling. The idea is to make each tile
independently decodable (after reading the common frame header) and
also independendly encodable (minus within-frame cost adjustments in
the RD loop) to speed-up hardware & software en/decoders if they used
multi-threading. Column-based tiling has the added advantage (over
other tiling methods) that it minimizes realtime use-case latency,
since all threads can start encoding data as soon as the first SB-row
worth of data is available to the encoder.
There is some test code that does random tile ordering in the decoder,
to confirm that each tile is indeed independently decodable from other
tiles in the same frame. At tile edges, all contexts assume default
values (i.e. 0, 0 motion vector, no coefficients, DC intra4x4 mode),
and motion vector search and ordering do not cross tiles in the same
frame.
t log
Tile independence is not maintained between frames ATM, i.e. tile 0 of
frame 1 is free to use motion vectors that point into any tile of frame
0. We support 1 (i.e. no tiling), 2 or 4 column-tiles.
The loopfilter crosses tile boundaries. I discussed this briefly with Aki
and he says that's OK. An in-loop loopfilter would need to do some sync
between tile threads, but that shouldn't be a big issue.
Resuls: with tiling disabled, we go up slightly because of improved edge
use in the intra4x4 prediction. With 2 tiles, we lose about ~1% on derf,
~0.35% on HD and ~0.55% on STD/HD. With 4 tiles, we lose another ~1.5%
on derf ~0.77% on HD and ~0.85% on STD/HD. Most of this loss is
concentrated in the low-bitrate end of clips, and most of it is because
of the loss of edges at tile boundaries and the resulting loss of intra
predictors.
TODO:
- more tiles (perhaps allow row-based tiling also, and max. 8 tiles)?
- maybe optionally (for EC purposes), motion vectors themselves
should not cross tile edges, or we should emulate such borders as
if they were off-frame, to limit error propagation to within one
tile only. This doesn't have to be the default behaviour but could
be an optional bitstream flag.
Change-Id: I5951c3a0742a767b20bc9fb5af685d9892c2c96f
2013-02-01 18:35:28 +01:00
|
|
|
VP9_COMMON *cm,
|
2012-08-24 16:44:01 +02:00
|
|
|
MACROBLOCKD *xd,
|
|
|
|
MODE_INFO *here,
|
|
|
|
MODE_INFO *lf_here,
|
|
|
|
MV_REFERENCE_FRAME ref_frame,
|
|
|
|
int_mv *mv_ref_list,
|
|
|
|
int *ref_sign_bias
|
|
|
|
) {
|
|
|
|
|
|
|
|
int i;
|
|
|
|
MODE_INFO *candidate_mi;
|
2012-11-12 16:09:25 +01:00
|
|
|
MB_MODE_INFO * mbmi = &xd->mode_info_context->mbmi;
|
2012-12-04 18:21:05 +01:00
|
|
|
int_mv candidate_mvs[MAX_MV_REF_CANDIDATES];
|
2012-08-24 16:44:01 +02:00
|
|
|
int_mv c_refmv;
|
2012-09-07 13:46:41 +02:00
|
|
|
int_mv c2_refmv;
|
2012-12-04 18:21:05 +01:00
|
|
|
MV_REFERENCE_FRAME c_ref_frame;
|
2012-09-07 13:46:41 +02:00
|
|
|
MV_REFERENCE_FRAME c2_ref_frame;
|
2012-12-04 18:21:05 +01:00
|
|
|
int candidate_scores[MAX_MV_REF_CANDIDATES];
|
2013-01-24 13:52:13 +01:00
|
|
|
int refmv_count = 0;
|
2012-11-16 17:31:32 +01:00
|
|
|
int split_count = 0;
|
2012-11-16 15:31:53 +01:00
|
|
|
int (*mv_ref_search)[2];
|
|
|
|
int *ref_distance_weight;
|
2013-01-24 13:52:13 +01:00
|
|
|
int zero_seen = FALSE;
|
[WIP] Add column-based tiling.
This patch adds column-based tiling. The idea is to make each tile
independently decodable (after reading the common frame header) and
also independendly encodable (minus within-frame cost adjustments in
the RD loop) to speed-up hardware & software en/decoders if they used
multi-threading. Column-based tiling has the added advantage (over
other tiling methods) that it minimizes realtime use-case latency,
since all threads can start encoding data as soon as the first SB-row
worth of data is available to the encoder.
There is some test code that does random tile ordering in the decoder,
to confirm that each tile is indeed independently decodable from other
tiles in the same frame. At tile edges, all contexts assume default
values (i.e. 0, 0 motion vector, no coefficients, DC intra4x4 mode),
and motion vector search and ordering do not cross tiles in the same
frame.
t log
Tile independence is not maintained between frames ATM, i.e. tile 0 of
frame 1 is free to use motion vectors that point into any tile of frame
0. We support 1 (i.e. no tiling), 2 or 4 column-tiles.
The loopfilter crosses tile boundaries. I discussed this briefly with Aki
and he says that's OK. An in-loop loopfilter would need to do some sync
between tile threads, but that shouldn't be a big issue.
Resuls: with tiling disabled, we go up slightly because of improved edge
use in the intra4x4 prediction. With 2 tiles, we lose about ~1% on derf,
~0.35% on HD and ~0.55% on STD/HD. With 4 tiles, we lose another ~1.5%
on derf ~0.77% on HD and ~0.85% on STD/HD. Most of this loss is
concentrated in the low-bitrate end of clips, and most of it is because
of the loss of edges at tile boundaries and the resulting loss of intra
predictors.
TODO:
- more tiles (perhaps allow row-based tiling also, and max. 8 tiles)?
- maybe optionally (for EC purposes), motion vectors themselves
should not cross tile edges, or we should emulate such borders as
if they were off-frame, to limit error propagation to within one
tile only. This doesn't have to be the default behaviour but could
be an optional bitstream flag.
Change-Id: I5951c3a0742a767b20bc9fb5af685d9892c2c96f
2013-02-01 18:35:28 +01:00
|
|
|
const int mb_col = (-xd->mb_to_left_edge) >> 7;
|
2012-08-24 16:44:01 +02:00
|
|
|
|
|
|
|
// Blank the reference vector lists and other local structures.
|
2012-12-04 18:21:05 +01:00
|
|
|
vpx_memset(mv_ref_list, 0, sizeof(int_mv) * MAX_MV_REF_CANDIDATES);
|
|
|
|
vpx_memset(candidate_mvs, 0, sizeof(int_mv) * MAX_MV_REF_CANDIDATES);
|
2012-08-24 16:44:01 +02:00
|
|
|
vpx_memset(candidate_scores, 0, sizeof(candidate_scores));
|
|
|
|
|
2013-01-06 03:20:25 +01:00
|
|
|
if (mbmi->sb_type) {
|
2012-11-16 15:31:53 +01:00
|
|
|
mv_ref_search = sb_mv_ref_search;
|
|
|
|
ref_distance_weight = sb_ref_distance_weight;
|
|
|
|
} else {
|
|
|
|
mv_ref_search = mb_mv_ref_search;
|
|
|
|
ref_distance_weight = mb_ref_distance_weight;
|
|
|
|
}
|
2013-01-03 16:14:36 +01:00
|
|
|
|
|
|
|
// We first scan for candidate vectors that match the current reference frame
|
|
|
|
// Look at nearest neigbours
|
2012-08-24 16:44:01 +02:00
|
|
|
for (i = 0; i < 2; ++i) {
|
[WIP] Add column-based tiling.
This patch adds column-based tiling. The idea is to make each tile
independently decodable (after reading the common frame header) and
also independendly encodable (minus within-frame cost adjustments in
the RD loop) to speed-up hardware & software en/decoders if they used
multi-threading. Column-based tiling has the added advantage (over
other tiling methods) that it minimizes realtime use-case latency,
since all threads can start encoding data as soon as the first SB-row
worth of data is available to the encoder.
There is some test code that does random tile ordering in the decoder,
to confirm that each tile is indeed independently decodable from other
tiles in the same frame. At tile edges, all contexts assume default
values (i.e. 0, 0 motion vector, no coefficients, DC intra4x4 mode),
and motion vector search and ordering do not cross tiles in the same
frame.
t log
Tile independence is not maintained between frames ATM, i.e. tile 0 of
frame 1 is free to use motion vectors that point into any tile of frame
0. We support 1 (i.e. no tiling), 2 or 4 column-tiles.
The loopfilter crosses tile boundaries. I discussed this briefly with Aki
and he says that's OK. An in-loop loopfilter would need to do some sync
between tile threads, but that shouldn't be a big issue.
Resuls: with tiling disabled, we go up slightly because of improved edge
use in the intra4x4 prediction. With 2 tiles, we lose about ~1% on derf,
~0.35% on HD and ~0.55% on STD/HD. With 4 tiles, we lose another ~1.5%
on derf ~0.77% on HD and ~0.85% on STD/HD. Most of this loss is
concentrated in the low-bitrate end of clips, and most of it is because
of the loss of edges at tile boundaries and the resulting loss of intra
predictors.
TODO:
- more tiles (perhaps allow row-based tiling also, and max. 8 tiles)?
- maybe optionally (for EC purposes), motion vectors themselves
should not cross tile edges, or we should emulate such borders as
if they were off-frame, to limit error propagation to within one
tile only. This doesn't have to be the default behaviour but could
be an optional bitstream flag.
Change-Id: I5951c3a0742a767b20bc9fb5af685d9892c2c96f
2013-02-01 18:35:28 +01:00
|
|
|
const int mb_search_col = mb_col + mv_ref_search[i][0];
|
|
|
|
|
|
|
|
if ((mb_search_col >= cm->cur_tile_mb_col_start) &&
|
|
|
|
(mb_search_col < cm->cur_tile_mb_col_end) &&
|
2012-08-24 16:44:01 +02:00
|
|
|
((mv_ref_search[i][1] << 7) >= xd->mb_to_top_edge)) {
|
|
|
|
|
|
|
|
candidate_mi = here + mv_ref_search[i][0] +
|
|
|
|
(mv_ref_search[i][1] * xd->mode_info_stride);
|
|
|
|
|
2013-01-03 16:14:36 +01:00
|
|
|
if (get_matching_candidate(candidate_mi, ref_frame, &c_refmv)) {
|
2013-01-24 13:52:13 +01:00
|
|
|
add_candidate_mv(candidate_mvs, candidate_scores,
|
|
|
|
&refmv_count, c_refmv, ref_distance_weight[i] + 16);
|
2012-08-24 16:44:01 +02:00
|
|
|
}
|
2013-01-03 16:14:36 +01:00
|
|
|
split_count += (candidate_mi->mbmi.mode == SPLITMV);
|
2012-08-24 16:44:01 +02:00
|
|
|
}
|
|
|
|
}
|
2013-01-15 15:43:35 +01:00
|
|
|
// Look in the last frame if it exists
|
|
|
|
if (lf_here) {
|
|
|
|
candidate_mi = lf_here;
|
|
|
|
if (get_matching_candidate(candidate_mi, ref_frame, &c_refmv)) {
|
2013-01-24 13:52:13 +01:00
|
|
|
add_candidate_mv(candidate_mvs, candidate_scores,
|
|
|
|
&refmv_count, c_refmv, 18);
|
2013-01-15 15:43:35 +01:00
|
|
|
}
|
2012-08-24 16:44:01 +02:00
|
|
|
}
|
2013-01-03 16:14:36 +01:00
|
|
|
// More distant neigbours
|
|
|
|
for (i = 2; (i < MVREF_NEIGHBOURS) &&
|
2013-01-24 13:52:13 +01:00
|
|
|
(refmv_count < (MAX_MV_REF_CANDIDATES - 1)); ++i) {
|
[WIP] Add column-based tiling.
This patch adds column-based tiling. The idea is to make each tile
independently decodable (after reading the common frame header) and
also independendly encodable (minus within-frame cost adjustments in
the RD loop) to speed-up hardware & software en/decoders if they used
multi-threading. Column-based tiling has the added advantage (over
other tiling methods) that it minimizes realtime use-case latency,
since all threads can start encoding data as soon as the first SB-row
worth of data is available to the encoder.
There is some test code that does random tile ordering in the decoder,
to confirm that each tile is indeed independently decodable from other
tiles in the same frame. At tile edges, all contexts assume default
values (i.e. 0, 0 motion vector, no coefficients, DC intra4x4 mode),
and motion vector search and ordering do not cross tiles in the same
frame.
t log
Tile independence is not maintained between frames ATM, i.e. tile 0 of
frame 1 is free to use motion vectors that point into any tile of frame
0. We support 1 (i.e. no tiling), 2 or 4 column-tiles.
The loopfilter crosses tile boundaries. I discussed this briefly with Aki
and he says that's OK. An in-loop loopfilter would need to do some sync
between tile threads, but that shouldn't be a big issue.
Resuls: with tiling disabled, we go up slightly because of improved edge
use in the intra4x4 prediction. With 2 tiles, we lose about ~1% on derf,
~0.35% on HD and ~0.55% on STD/HD. With 4 tiles, we lose another ~1.5%
on derf ~0.77% on HD and ~0.85% on STD/HD. Most of this loss is
concentrated in the low-bitrate end of clips, and most of it is because
of the loss of edges at tile boundaries and the resulting loss of intra
predictors.
TODO:
- more tiles (perhaps allow row-based tiling also, and max. 8 tiles)?
- maybe optionally (for EC purposes), motion vectors themselves
should not cross tile edges, or we should emulate such borders as
if they were off-frame, to limit error propagation to within one
tile only. This doesn't have to be the default behaviour but could
be an optional bitstream flag.
Change-Id: I5951c3a0742a767b20bc9fb5af685d9892c2c96f
2013-02-01 18:35:28 +01:00
|
|
|
const int mb_search_col = mb_col + mv_ref_search[i][0];
|
|
|
|
|
|
|
|
if ((mb_search_col >= cm->cur_tile_mb_col_start) &&
|
|
|
|
(mb_search_col < cm->cur_tile_mb_col_end) &&
|
2012-08-24 16:44:01 +02:00
|
|
|
((mv_ref_search[i][1] << 7) >= xd->mb_to_top_edge)) {
|
|
|
|
candidate_mi = here + mv_ref_search[i][0] +
|
|
|
|
(mv_ref_search[i][1] * xd->mode_info_stride);
|
|
|
|
|
2013-01-03 16:14:36 +01:00
|
|
|
if (get_matching_candidate(candidate_mi, ref_frame, &c_refmv)) {
|
2013-01-24 13:52:13 +01:00
|
|
|
add_candidate_mv(candidate_mvs, candidate_scores,
|
|
|
|
&refmv_count, c_refmv, ref_distance_weight[i] + 16);
|
2013-01-03 16:14:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-24 16:44:01 +02:00
|
|
|
|
2013-01-03 16:14:36 +01:00
|
|
|
// If we have not found enough candidates consider ones where the
|
|
|
|
// reference frame does not match. Break out when we have
|
|
|
|
// MAX_MV_REF_CANDIDATES candidates.
|
|
|
|
// Look first at spatial neighbours
|
2013-01-24 13:52:13 +01:00
|
|
|
if (refmv_count < (MAX_MV_REF_CANDIDATES - 1)) {
|
2013-01-03 16:14:36 +01:00
|
|
|
for (i = 0; i < MVREF_NEIGHBOURS; ++i) {
|
[WIP] Add column-based tiling.
This patch adds column-based tiling. The idea is to make each tile
independently decodable (after reading the common frame header) and
also independendly encodable (minus within-frame cost adjustments in
the RD loop) to speed-up hardware & software en/decoders if they used
multi-threading. Column-based tiling has the added advantage (over
other tiling methods) that it minimizes realtime use-case latency,
since all threads can start encoding data as soon as the first SB-row
worth of data is available to the encoder.
There is some test code that does random tile ordering in the decoder,
to confirm that each tile is indeed independently decodable from other
tiles in the same frame. At tile edges, all contexts assume default
values (i.e. 0, 0 motion vector, no coefficients, DC intra4x4 mode),
and motion vector search and ordering do not cross tiles in the same
frame.
t log
Tile independence is not maintained between frames ATM, i.e. tile 0 of
frame 1 is free to use motion vectors that point into any tile of frame
0. We support 1 (i.e. no tiling), 2 or 4 column-tiles.
The loopfilter crosses tile boundaries. I discussed this briefly with Aki
and he says that's OK. An in-loop loopfilter would need to do some sync
between tile threads, but that shouldn't be a big issue.
Resuls: with tiling disabled, we go up slightly because of improved edge
use in the intra4x4 prediction. With 2 tiles, we lose about ~1% on derf,
~0.35% on HD and ~0.55% on STD/HD. With 4 tiles, we lose another ~1.5%
on derf ~0.77% on HD and ~0.85% on STD/HD. Most of this loss is
concentrated in the low-bitrate end of clips, and most of it is because
of the loss of edges at tile boundaries and the resulting loss of intra
predictors.
TODO:
- more tiles (perhaps allow row-based tiling also, and max. 8 tiles)?
- maybe optionally (for EC purposes), motion vectors themselves
should not cross tile edges, or we should emulate such borders as
if they were off-frame, to limit error propagation to within one
tile only. This doesn't have to be the default behaviour but could
be an optional bitstream flag.
Change-Id: I5951c3a0742a767b20bc9fb5af685d9892c2c96f
2013-02-01 18:35:28 +01:00
|
|
|
const int mb_search_col = mb_col + mv_ref_search[i][0];
|
|
|
|
|
|
|
|
if ((mb_search_col >= cm->cur_tile_mb_col_start) &&
|
|
|
|
(mb_search_col < cm->cur_tile_mb_col_end) &&
|
2013-01-03 16:14:36 +01:00
|
|
|
((mv_ref_search[i][1] << 7) >= xd->mb_to_top_edge)) {
|
2012-09-07 13:46:41 +02:00
|
|
|
|
2013-01-03 16:14:36 +01:00
|
|
|
candidate_mi = here + mv_ref_search[i][0] +
|
|
|
|
(mv_ref_search[i][1] * xd->mode_info_stride);
|
2012-09-07 13:46:41 +02:00
|
|
|
|
2013-01-03 16:14:36 +01:00
|
|
|
get_non_matching_candidates(candidate_mi, ref_frame,
|
|
|
|
&c_ref_frame, &c_refmv,
|
|
|
|
&c2_ref_frame, &c2_refmv);
|
2012-08-24 16:44:01 +02:00
|
|
|
|
2013-01-03 16:14:36 +01:00
|
|
|
if (c_ref_frame != INTRA_FRAME) {
|
|
|
|
scale_mv(xd, ref_frame, c_ref_frame, &c_refmv, ref_sign_bias);
|
2013-01-24 13:52:13 +01:00
|
|
|
add_candidate_mv(candidate_mvs, candidate_scores,
|
|
|
|
&refmv_count, c_refmv, ref_distance_weight[i]);
|
2013-01-03 16:14:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (c2_ref_frame != INTRA_FRAME) {
|
|
|
|
scale_mv(xd, ref_frame, c2_ref_frame, &c2_refmv, ref_sign_bias);
|
2013-01-24 13:52:13 +01:00
|
|
|
add_candidate_mv(candidate_mvs, candidate_scores,
|
|
|
|
&refmv_count, c2_refmv, ref_distance_weight[i]);
|
2012-09-07 13:46:41 +02:00
|
|
|
}
|
2012-08-24 16:44:01 +02:00
|
|
|
}
|
2013-01-03 16:14:36 +01:00
|
|
|
|
2013-01-24 13:52:13 +01:00
|
|
|
if (refmv_count >= (MAX_MV_REF_CANDIDATES - 1)) {
|
2013-01-03 16:14:36 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-15 15:43:35 +01:00
|
|
|
// Look at the last frame if it exists
|
2013-01-24 13:52:13 +01:00
|
|
|
if (refmv_count < (MAX_MV_REF_CANDIDATES - 1) && lf_here) {
|
2013-01-03 16:14:36 +01:00
|
|
|
candidate_mi = lf_here;
|
|
|
|
get_non_matching_candidates(candidate_mi, ref_frame,
|
|
|
|
&c_ref_frame, &c_refmv,
|
|
|
|
&c2_ref_frame, &c2_refmv);
|
|
|
|
|
|
|
|
if (c_ref_frame != INTRA_FRAME) {
|
|
|
|
scale_mv(xd, ref_frame, c_ref_frame, &c_refmv, ref_sign_bias);
|
2013-01-24 13:52:13 +01:00
|
|
|
add_candidate_mv(candidate_mvs, candidate_scores,
|
|
|
|
&refmv_count, c_refmv, 2);
|
2013-01-03 16:14:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (c2_ref_frame != INTRA_FRAME) {
|
|
|
|
scale_mv(xd, ref_frame, c2_ref_frame, &c2_refmv, ref_sign_bias);
|
2013-01-24 13:52:13 +01:00
|
|
|
add_candidate_mv(candidate_mvs, candidate_scores,
|
|
|
|
&refmv_count, c2_refmv, 2);
|
2012-08-24 16:44:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-16 17:31:32 +01:00
|
|
|
// Define inter mode coding context.
|
|
|
|
// 0,0 was best
|
2012-11-12 16:09:25 +01:00
|
|
|
if (candidate_mvs[0].as_int == 0) {
|
2012-11-16 17:31:32 +01:00
|
|
|
// 0,0 is only candidate
|
2013-01-24 13:52:13 +01:00
|
|
|
if (refmv_count <= 1) {
|
2012-11-12 16:09:25 +01:00
|
|
|
mbmi->mb_mode_context[ref_frame] = 0;
|
2012-11-16 17:31:32 +01:00
|
|
|
// non zero candidates candidates available
|
|
|
|
} else if (split_count == 0) {
|
2012-11-12 16:09:25 +01:00
|
|
|
mbmi->mb_mode_context[ref_frame] = 1;
|
|
|
|
} else {
|
|
|
|
mbmi->mb_mode_context[ref_frame] = 2;
|
|
|
|
}
|
2012-11-16 17:31:32 +01:00
|
|
|
// Non zero best, No Split MV cases
|
|
|
|
} else if (split_count == 0) {
|
2013-01-24 13:52:13 +01:00
|
|
|
if (candidate_scores[0] >= 16) {
|
2012-11-12 16:09:25 +01:00
|
|
|
mbmi->mb_mode_context[ref_frame] = 3;
|
|
|
|
} else {
|
|
|
|
mbmi->mb_mode_context[ref_frame] = 4;
|
|
|
|
}
|
2012-11-16 17:31:32 +01:00
|
|
|
// Non zero best, some split mv
|
2012-11-12 16:09:25 +01:00
|
|
|
} else {
|
2013-01-24 13:52:13 +01:00
|
|
|
if (candidate_scores[0] >= 16) {
|
2012-11-16 17:31:32 +01:00
|
|
|
mbmi->mb_mode_context[ref_frame] = 5;
|
|
|
|
} else {
|
|
|
|
mbmi->mb_mode_context[ref_frame] = 6;
|
|
|
|
}
|
2012-11-12 16:09:25 +01:00
|
|
|
}
|
|
|
|
|
2013-01-24 13:52:13 +01:00
|
|
|
// Scan for 0,0 case and clamp non zero choices
|
2012-12-04 18:21:05 +01:00
|
|
|
for (i = 0; i < MAX_MV_REF_CANDIDATES; ++i) {
|
2013-01-24 13:52:13 +01:00
|
|
|
if (candidate_mvs[i].as_int == 0) {
|
|
|
|
zero_seen = TRUE;
|
|
|
|
} else {
|
|
|
|
clamp_mv_ref(xd, &candidate_mvs[i]);
|
|
|
|
}
|
2012-11-16 17:31:32 +01:00
|
|
|
}
|
2013-01-24 13:52:13 +01:00
|
|
|
// 0,0 is always a valid reference. Add it if not already seen.
|
|
|
|
if (!zero_seen) {
|
2012-12-04 18:21:05 +01:00
|
|
|
candidate_mvs[MAX_MV_REF_CANDIDATES-1].as_int = 0;
|
2012-08-24 16:44:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Copy over the candidate list.
|
|
|
|
vpx_memcpy(mv_ref_list, candidate_mvs, sizeof(candidate_mvs));
|
|
|
|
}
|