...
 
Commits (14)
  • Jingning Han's avatar
    Set up decoder end coding statistics tracker · c39736a5
    Jingning Han authored
    This commit allows the decoder to track the percentage of intra
    coding mode and sub pixel filter usage, when it is configured. This
    provides a measurable approach to generate the VP9 decoder
    performance test suite.
    
    Change-Id: I26d40b991f41b1408de2b206ecb0a322cdb561b8
    c39736a5
  • Jingning Han's avatar
    Set up decoder end coding statistics tracker · b75e4d0f
    Jingning Han authored
    This commit allows the decoder to track the percentage of intra
    coding mode and sub pixel filter usage, when it is configured. This
    provides a measurable approach to generate the VP9 decoder
    performance test suite.
    
    Change-Id: I26d40b991f41b1408de2b206ecb0a322cdb561b8
    b75e4d0f
  • Jingning Han's avatar
    Merge "Set up decoder end coding statistics tracker" into... · 006085d4
    Jingning Han authored
    Merge "Set up decoder end coding statistics tracker" into sandbox/jingning@google.com/decoder_test_suite
    006085d4
  • Jingning Han's avatar
    Add more coding staticstics tracker · 9cec9cb2
    Jingning Han authored
    Count the average sub-pixel motion vector, sub8x8 block, intra
    prediction mode use case.
    
    Change-Id: Idbccc67a7eb4d2447b02b1fc158fdc8a344c2f21
    9cec9cb2
  • Jingning Han's avatar
  • Jingning Han's avatar
    VP9 decoder performance test suite - buffer process · cb8b7d0d
    Jingning Han authored
    This commit hacks the vp9 encoder to produce bit-streams that
    exercise maximum reference frame buffers at decoder, as part of
    the VP9 decoder performance test suite. It fullfills all the 8
    reference frame buffers first and then temporarily suspends the
    buffer update. It selects the frames from this static buffer pool
    as reference frames for the next a few coding frames. When all
    the frames in the reference frame buffer are covered, the codec
    resumes the buffer update process. Such pattern repeats every
    64 frames.
    
    It verifies the decoder capability to handle up to 8 reference
    frames in buffer.
    
    Change-Id: I796701eba53ed19ae73351d23d676311f12c43a1
    cb8b7d0d
  • Jingning Han's avatar
    Merge "VP9 decoder performance test suite - buffer process" into... · f4e1933c
    Jingning Han authored
    Merge "VP9 decoder performance test suite - buffer process" into sandbox/jingning@google.com/decoder_test_suite
    f4e1933c
  • Debargha Mukherjee's avatar
    Expose params min-gf-interval/max-gf-interval · 29a325f7
    Debargha Mukherjee authored
    Adds two new vp9 parameters --min-gf-interval and --max-gf-interval
    to enable testing based on frequency of alt-ref frames.
    
    Also adds a unit-test to test enforcement of min-gf-interval.
    
    For both these parameters the default value is 0, which indicates
    they are picked by the encoder, based on resolution and framerate
    considerations. If they are greater than zero, the specified
    parameter is honored.
    
    (Additional note by paulwilkins)
    Note that there is a slight oddity in that key frames are also GFs and
    considered part of  GF only group. However they are treated as not
    being part of an arf group because for arf groups the previous GF is
    assumed to be the terminal or overlay frame for the previous group.
    
    (end note)
    
    Change-Id: Ibf0c30b72074b3f71918ab278ccccc02a95a70a0
    (cherry picked from commit 98526433)
    29a325f7
  • Jingning Han's avatar
    Exercise internal frame resizing · fb27ffbb
    Jingning Han authored
    This commit enables the encoder to exercise internal frame resizing
    and to use scaled reference frame for sub8x8 block motion compensated
    prediction.
    
    Change-Id: I42703da4a4b075c6aefe9a9f687374af65c3c73f
    fb27ffbb
  • hui su's avatar
    Add moving-average bit rate stats · e38e2b83
    hui su authored
    Change-Id: Id764e573776d4d0ee2c400a4eca0832268e1e2b1
    e38e2b83
  • Jingning Han's avatar
    Fix high bit depth with scaled reference frame · db731248
    Jingning Han authored
    This commit fixes an encoder issue in high bit depth implementation
    that causes enc/dec mismatch in scaled reference frame.
    
    Change-Id: I97655aa213f830d8e2dcd98253c3008abda30eea
    db731248
  • Jingning Han's avatar
    Fix sub8x8 motion search on scaled reference frame · e50c37ba
    Jingning Han authored
    This commit fixes a buffer overflow issue related to sub8x8 motion
    search on scaled reference frame.
    
    Change-Id: Iffeebc8787c1ed2b0cb3a7821349e028639d9eb5
    e50c37ba
  • Jingning Han's avatar
    Merge "Fix high bit depth with scaled reference frame" into... · 35b121b0
    Jingning Han authored
    Merge "Fix high bit depth with scaled reference frame" into sandbox/jingning@google.com/decoder_test_suite
    35b121b0
  • Jingning Han's avatar
    Merge "Fix sub8x8 motion search on scaled reference frame" into... · 0fe7ee6d
    Jingning Han authored
    Merge "Fix sub8x8 motion search on scaled reference frame" into sandbox/jingning@google.com/decoder_test_suite
    0fe7ee6d
......@@ -251,6 +251,8 @@ HAVE_LIST="
EXPERIMENT_LIST="
spatial_svc
fp_mb_stats
full_buffer_test
internal_resize
emulate_hardware
"
CONFIG_LIST="
......
......@@ -159,6 +159,7 @@ endif
ifeq ($(CONFIG_VP9_ENCODER)$(CONFIG_VP9_TEMPORAL_DENOISING),yesyes)
LIBVPX_TEST_SRCS-$(HAVE_SSE2) += vp9_denoiser_sse2_test.cc
endif
LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += vp9_arf_freq_test.cc
endif # VP9
......
......@@ -135,6 +135,7 @@ TEST_P(TestVectorTest, MD5Match) {
// Test VP8 decode in serial mode with single thread.
// NOTE: VP8 only support serial mode.
#if CONFIG_VP8_DECODER
VP8_INSTANTIATE_TEST_CASE(
TestVectorTest,
::testing::Combine(
......@@ -143,8 +144,10 @@ VP8_INSTANTIATE_TEST_CASE(
::testing::ValuesIn(libvpx_test::kVP8TestVectors,
libvpx_test::kVP8TestVectors +
libvpx_test::kNumVP8TestVectors)));
#endif
// Test VP9 decode in serial mode with single thread.
#if CONFIG_VP9_DECODER
VP9_INSTANTIATE_TEST_CASE(
TestVectorTest,
::testing::Combine(
......@@ -154,8 +157,6 @@ VP9_INSTANTIATE_TEST_CASE(
libvpx_test::kVP9TestVectors +
libvpx_test::kNumVP9TestVectors)));
#if CONFIG_VP9_DECODER
// Test VP9 decode in frame parallel mode with different number of threads.
INSTANTIATE_TEST_CASE_P(
VP9MultiThreadedFrameParallel, TestVectorTest,
......
/*
* Copyright (c) 2015 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.
*/
#include "test/codec_factory.h"
#include "test/encode_test_driver.h"
#include "test/y4m_video_source.h"
#include "test/yuv_video_source.h"
#include "test/util.h"
#include "third_party/googletest/src/include/gtest/gtest.h"
#include "vp9/encoder/vp9_ratectrl.h"
namespace {
const unsigned int kFrames = 100;
const int kBitrate = 500;
#define ARF_NOT_SEEN 1000001
#define ARF_SEEN_ONCE 1000000
typedef struct {
const char *filename;
unsigned int width;
unsigned int height;
unsigned int framerate_num;
unsigned int framerate_den;
unsigned int input_bit_depth;
vpx_img_fmt fmt;
vpx_bit_depth_t bit_depth;
unsigned int profile;
} TestVideoParam;
typedef struct {
libvpx_test::TestMode mode;
int cpu_used;
} TestEncodeParam;
const TestVideoParam kTestVectors[] = {
// artificially increase framerate to trigger default check
{"hantro_collage_w352h288.yuv", 352, 288, 5000, 1,
8, VPX_IMG_FMT_I420, VPX_BITS_8, 0},
{"hantro_collage_w352h288.yuv", 352, 288, 30, 1,
8, VPX_IMG_FMT_I420, VPX_BITS_8, 0},
{"rush_hour_444.y4m", 352, 288, 30, 1,
8, VPX_IMG_FMT_I444, VPX_BITS_8, 1},
#if CONFIG_VP9_HIGHBITDEPTH
// Add list of profile 2/3 test videos here ...
#endif // CONFIG_VP9_HIGHBITDEPTH
};
const TestEncodeParam kEncodeVectors[] = {
{::libvpx_test::kOnePassGood, 2},
{::libvpx_test::kOnePassGood, 5},
{::libvpx_test::kTwoPassGood, 1},
{::libvpx_test::kTwoPassGood, 2},
{::libvpx_test::kTwoPassGood, 5},
{::libvpx_test::kRealTime, 5},
};
const int kMinArfVectors[] = {
// NOTE: 0 refers to the default built-in logic in:
// vp9_rc_get_default_min_gf_interval(...)
0, 4, 8, 12, 15
};
int is_extension_y4m(const char *filename) {
const char *dot = strrchr(filename, '.');
if (!dot || dot == filename)
return 0;
else
return !strcmp(dot, ".y4m");
}
class ArfFreqTest
: public ::libvpx_test::EncoderTest,
public ::libvpx_test::CodecTestWith3Params<TestVideoParam, \
TestEncodeParam, int> {
protected:
ArfFreqTest()
: EncoderTest(GET_PARAM(0)),
test_video_param_(GET_PARAM(1)),
test_encode_param_(GET_PARAM(2)),
min_arf_requested_(GET_PARAM(3)) {
}
virtual ~ArfFreqTest() {}
virtual void SetUp() {
InitializeConfig();
SetMode(test_encode_param_.mode);
if (test_encode_param_.mode != ::libvpx_test::kRealTime) {
cfg_.g_lag_in_frames = 25;
cfg_.rc_end_usage = VPX_VBR;
} else {
cfg_.g_lag_in_frames = 0;
cfg_.rc_end_usage = VPX_CBR;
cfg_.rc_buf_sz = 1000;
cfg_.rc_buf_initial_sz = 500;
cfg_.rc_buf_optimal_sz = 600;
}
dec_cfg_.threads = 4;
}
virtual void BeginPassHook(unsigned int) {
min_arf_ = ARF_NOT_SEEN;
run_of_visible_frames_ = 0;
}
int GetNumFramesInPkt(const vpx_codec_cx_pkt_t *pkt) {
const uint8_t *buffer = reinterpret_cast<uint8_t*>(pkt->data.frame.buf);
const uint8_t marker = buffer[pkt->data.frame.sz - 1];
const int mag = ((marker >> 3) & 3) + 1;
int frames = (marker & 0x7) + 1;
const unsigned int index_sz = 2 + mag * frames;
// Check for superframe or not.
// Assume superframe has only one visible frame, the rest being
// invisible. If superframe index is not found, then there is only
// one frame.
if (!((marker & 0xe0) == 0xc0 &&
pkt->data.frame.sz >= index_sz &&
buffer[pkt->data.frame.sz - index_sz] == marker)) {
frames = 1;
}
return frames;
}
virtual void FramePktHook(const vpx_codec_cx_pkt_t *pkt) {
if (pkt->kind != VPX_CODEC_CX_FRAME_PKT)
return;
const int frames = GetNumFramesInPkt(pkt);
if (frames == 1) {
run_of_visible_frames_++;
} else if (frames == 2) {
if (min_arf_ == ARF_NOT_SEEN) {
min_arf_ = ARF_SEEN_ONCE;
} else if (min_arf_ == ARF_SEEN_ONCE ||
run_of_visible_frames_ < min_arf_) {
min_arf_ = run_of_visible_frames_;
}
run_of_visible_frames_ = 1;
} else {
min_arf_ = 0;
run_of_visible_frames_ = 1;
}
}
virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video,
::libvpx_test::Encoder *encoder) {
if (video->frame() == 0) {
encoder->Control(VP9E_SET_FRAME_PARALLEL_DECODING, 1);
encoder->Control(VP9E_SET_TILE_COLUMNS, 4);
encoder->Control(VP8E_SET_CPUUSED, test_encode_param_.cpu_used);
encoder->Control(VP9E_SET_MIN_GF_INTERVAL, min_arf_requested_);
if (test_encode_param_.mode != ::libvpx_test::kRealTime) {
encoder->Control(VP8E_SET_ENABLEAUTOALTREF, 1);
encoder->Control(VP8E_SET_ARNR_MAXFRAMES, 7);
encoder->Control(VP8E_SET_ARNR_STRENGTH, 5);
encoder->Control(VP8E_SET_ARNR_TYPE, 3);
}
}
}
int GetMinArfDistance() const {
return min_arf_;
}
int GetMinArfDistanceRequested() const {
if (min_arf_requested_)
return min_arf_requested_;
else
return vp9_rc_get_default_min_gf_interval(
test_video_param_.width, test_video_param_.height,
(double)test_video_param_.framerate_num /
test_video_param_.framerate_den);
}
TestVideoParam test_video_param_;
TestEncodeParam test_encode_param_;
private:
int min_arf_requested_;
int min_arf_;
int run_of_visible_frames_;
};
TEST_P(ArfFreqTest, MinArfFreqTest) {
cfg_.rc_target_bitrate = kBitrate;
cfg_.g_error_resilient = 0;
cfg_.g_profile = test_video_param_.profile;
cfg_.g_input_bit_depth = test_video_param_.input_bit_depth;
cfg_.g_bit_depth = test_video_param_.bit_depth;
init_flags_ = VPX_CODEC_USE_PSNR;
if (cfg_.g_bit_depth > 8)
init_flags_ |= VPX_CODEC_USE_HIGHBITDEPTH;
libvpx_test::VideoSource *video;
if (is_extension_y4m(test_video_param_.filename)) {
video = new libvpx_test::Y4mVideoSource(test_video_param_.filename,
0, kFrames);
} else {
video = new libvpx_test::YUVVideoSource(test_video_param_.filename,
test_video_param_.fmt,
test_video_param_.width,
test_video_param_.height,
test_video_param_.framerate_num,
test_video_param_.framerate_den,
0, kFrames);
}
ASSERT_NO_FATAL_FAILURE(RunLoop(video));
const int min_arf_dist = GetMinArfDistance();
const int min_arf_dist_requested = GetMinArfDistanceRequested();
if (min_arf_dist != ARF_NOT_SEEN && min_arf_dist != ARF_SEEN_ONCE) {
EXPECT_GE(min_arf_dist, min_arf_dist_requested);
}
delete(video);
}
VP9_INSTANTIATE_TEST_CASE(
ArfFreqTest,
::testing::ValuesIn(kTestVectors),
::testing::ValuesIn(kEncodeVectors),
::testing::ValuesIn(kMinArfVectors));
} // namespace
......@@ -168,9 +168,9 @@ MV average_split_mvs(const struct macroblockd_plane *pd,
}
void build_inter_predictors(MACROBLOCKD *xd, int plane, int block,
int bw, int bh,
int x, int y, int w, int h,
int mi_x, int mi_y) {
int bw, int bh,
int x, int y, int w, int h,
int mi_x, int mi_y) {
struct macroblockd_plane *const pd = &xd->plane[plane];
const MODE_INFO *mi = xd->mi[0];
const int is_compound = has_second_ref(&mi->mbmi);
......@@ -201,7 +201,20 @@ void build_inter_predictors(MACROBLOCKD *xd, int plane, int block,
const int is_scaled = vp9_is_scaled(sf);
if (is_scaled) {
pre = pre_buf->buf + scaled_buffer_offset(x, y, pre_buf->stride, sf);
// Co-ordinate of containing block to pixel precision.
int x_start = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x));
int y_start = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y));
if (plane == 0)
pre_buf->buf = xd->block_refs[ref]->buf->y_buffer;
else if (plane == 1)
pre_buf->buf = xd->block_refs[ref]->buf->u_buffer;
else
pre_buf->buf = xd->block_refs[ref]->buf->v_buffer;
pre_buf->buf += scaled_buffer_offset(x_start + x, y_start + y,
pre_buf->stride, sf);
pre = pre_buf->buf;
scaled_mv = vp9_scale_mv(&mv_q4, mi_x + x, mi_y + y, sf);
xs = sf->x_step_q4;
ys = sf->y_step_q4;
......
......@@ -746,6 +746,12 @@ static void decode_block(VP9Decoder *const pbi, MACROBLOCKD *const xd,
if (less8x8)
bsize = BLOCK_8X8;
#if CONFIG_INTERNAL_STATS
pbi->total_block_in_8x8 += (1 << (num_pels_log2_lookup[bsize] - 6));
if (!is_inter_block(mbmi))
pbi->intra_block_in_8x8 += (1 << (num_pels_log2_lookup[bsize] - 6));
#endif
if (mbmi->skip) {
reset_skip_context(xd, bsize);
}
......@@ -754,6 +760,9 @@ static void decode_block(VP9Decoder *const pbi, MACROBLOCKD *const xd,
struct intra_args arg = {xd, r, mbmi->segment_id};
vp9_foreach_transformed_block(xd, bsize,
predict_and_reconstruct_intra_block, &arg);
#if CONFIG_INTERNAL_STATS
pbi->sub8x8_intra += less8x8;
#endif
} else {
// Prediction
dec_build_inter_predictors_sb(pbi, xd, mi_row, mi_col, bsize);
......@@ -766,6 +775,10 @@ static void decode_block(VP9Decoder *const pbi, MACROBLOCKD *const xd,
if (!less8x8 && eobtotal == 0)
mbmi->skip = 1; // skip loopfilter
}
#if CONFIG_INTERNAL_STATS
pbi->sub8x8_inter += less8x8;
#endif
}
xd->corrupted |= vp9_reader_has_error(r);
......@@ -1681,6 +1694,7 @@ static size_t read_uncompressed_header(VP9Decoder *pbi,
for (i = 0; i < REF_FRAMES; ++i)
cm->next_ref_frame_map[i] = cm->ref_frame_map[i];
}
return 0;
}
......@@ -1793,6 +1807,17 @@ static size_t read_uncompressed_header(VP9Decoder *pbi,
// below, forcing the use of context 0 for those frame types.
cm->frame_context_idx = vp9_rb_read_literal(rb, FRAME_CONTEXTS_LOG2);
#if CONFIG_FULL_BUFFER_TEST
{
int k;
fprintf(stderr, "\nDecode frame index %d, is_show_frame %d, new_fb_idx %d\n",
cm->current_video_frame, cm->show_frame, cm->new_fb_idx);
for (k = 0; k < 8; ++k)
fprintf(stderr, "%d ", cm->ref_frame_map[k]);
fprintf(stderr, "\n");
}
#endif
// Generate next_ref_frame_map.
lock_buffer_pool(pool);
for (mask = pbi->refresh_frame_flags; mask; mask >>= 1) {
......@@ -1979,6 +2004,9 @@ void vp9_decode_frame(VP9Decoder *pbi,
init_read_bit_buffer(pbi, &rb, data, data_end, clear_data));
const int tile_rows = 1 << cm->log2_tile_rows;
const int tile_cols = 1 << cm->log2_tile_cols;
#if CONFIG_INTERNAL_STATS
const int64_t data_size = data_end - data;
#endif
YV12_BUFFER_CONFIG *const new_fb = get_frame_new_buffer(cm);
xd->cur_buf = new_fb;
......@@ -2008,6 +2036,23 @@ void vp9_decode_frame(VP9Decoder *pbi,
"Uninitialized entropy context.");
vp9_zero(cm->counts);
#if CONFIG_INTERNAL_STATS
// Reset internal stats
if (cm->current_video_frame == 0) {
int i;
for (i = 0; i < BR_MOVING_AVERAGE_SIZE; ++i)
pbi->br_data.bit_rate[i] = 0;
pbi->br_data.index = 0;
pbi->peak_average_br = 0;
pbi->total_block_in_8x8 = 0;
pbi->subpel_mc_block_in_4x4_h = 0;
pbi->subpel_mc_block_in_4x4_v = 0;
pbi->sub8x8_inter = 0;
pbi->sub8x8_intra = 0;
pbi->intra_block_in_8x8 = 0;
pbi->compound_inter_block_in_8x8 = 0;
}
#endif
xd->corrupted = 0;
new_fb->corrupted = read_compressed_header(pbi, data, first_partition_size);
......@@ -2024,6 +2069,7 @@ void vp9_decode_frame(VP9Decoder *pbi,
if (pbi->frame_parallel_decode && cm->frame_parallel_decoding_mode) {
VP9Worker *const worker = pbi->frame_worker_owner;
FrameWorkerData *const frame_worker_data = worker->data1;
if (cm->refresh_frame_context) {
context_updated = 1;
cm->frame_contexts[cm->frame_context_idx] = *cm->fc;
......@@ -2076,4 +2122,43 @@ void vp9_decode_frame(VP9Decoder *pbi,
// Non frame parallel update frame context here.
if (cm->refresh_frame_context && !context_updated)
cm->frame_contexts[cm->frame_context_idx] = *cm->fc;
#if CONFIG_INTERNAL_STATS
vp9_clear_system_state();
{
FILE *pf = fopen("frame_level_stats.stt", "a");
int i;
double subpel_mc_h = (double)pbi->subpel_mc_block_in_4x4_h /
(double)pbi->total_block_in_8x8;
double subpel_mc_v = (double)pbi->subpel_mc_block_in_4x4_v /
(double)pbi->total_block_in_8x8;
double intra_mode = (double)pbi->intra_block_in_8x8 /
(double)pbi->total_block_in_8x8;
double compound_block = (double)pbi->compound_inter_block_in_8x8 /
(double)pbi->total_block_in_8x8;
double sub8x8_inter = (double)pbi->sub8x8_inter /
(double)pbi->total_block_in_8x8;
double sub8x8_intra = (double)pbi->sub8x8_intra /
(double)pbi->total_block_in_8x8;
double average_bit_rate = 0;
pbi->br_data.bit_rate[pbi->br_data.index] = data_size;
++pbi->br_data.index;
if (pbi->br_data.index >= BR_MOVING_AVERAGE_SIZE)
pbi->br_data.index = 0;
for (i = 0; i < BR_MOVING_AVERAGE_SIZE; ++i) {
average_bit_rate += (double)pbi->br_data.bit_rate[i];
}
average_bit_rate /= BR_MOVING_AVERAGE_SIZE;
if ((int64_t)average_bit_rate > pbi->peak_average_br)
pbi->peak_average_br = (int64_t)average_bit_rate;
fprintf(pf, "frame index %d, sub-pel mc (%7.3f, %7.3f)\tintra mode%7.3f\tcompound inter block%7.3f\t",
cm->current_video_frame, 25 * subpel_mc_h, 25 * subpel_mc_v, 100 * intra_mode,
100 * compound_block);
fprintf(pf, "sub8x8 inter %7.3f intra %7.3f average-br %7.3f peak-average-br %7.3f\n",
100 * sub8x8_inter, 100 * sub8x8_intra, average_bit_rate, (double)pbi->peak_average_br / 1000);
fclose(pf);
}
#endif
}
......@@ -479,6 +479,10 @@ static void read_inter_block_mode_info(VP9Decoder *const pbi,
read_ref_frames(cm, xd, r, mbmi->segment_id, mbmi->ref_frame);
is_compound = has_second_ref(mbmi);
#if CONFIG_INTERNAL_STATS
pbi->compound_inter_block_in_8x8 += is_compound;
#endif
for (ref = 0; ref < 1 + is_compound; ++ref) {
const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref];
RefBuffer *ref_buf = &cm->frame_refs[frame - LAST_FRAME];
......@@ -547,7 +551,22 @@ static void read_inter_block_mode_info(VP9Decoder *const pbi,
mi->bmi[j].as_mv[0].as_int = block[0].as_int;
if (is_compound)
mi->bmi[j].as_mv[1].as_int = block[1].as_int;
#if CONFIG_INTERNAL_STATS
if (mi->bmi[j].as_mv[0].as_mv.row & 0x07)
pbi->subpel_mc_block_in_4x4_v +=
(1 << (num_pels_log2_lookup[bsize] - 4));
if (mi->bmi[j].as_mv[0].as_mv.col & 0x07)
pbi->subpel_mc_block_in_4x4_h +=
(1 << (num_pels_log2_lookup[bsize] - 4));
if (is_compound) {
if (mi->bmi[j].as_mv[1].as_mv.row & 0x07)
pbi->subpel_mc_block_in_4x4_v +=
(1 << (num_pels_log2_lookup[bsize] - 4));
if (mi->bmi[j].as_mv[1].as_mv.col & 0x07)
pbi->subpel_mc_block_in_4x4_h +=
(1 << (num_pels_log2_lookup[bsize] - 4));
}
#endif
if (num_4x4_h == 2)
mi->bmi[j + 2] = mi->bmi[j];
if (num_4x4_w == 2)
......@@ -562,6 +581,18 @@ static void read_inter_block_mode_info(VP9Decoder *const pbi,
} else {
xd->corrupted |= !assign_mv(cm, xd, mbmi->mode, mbmi->mv, nearestmv,
nearestmv, nearmv, is_compound, allow_hp, r);
#if CONFIG_INTERNAL_STATS
if (mbmi->mv[0].as_mv.row & 0x07)
pbi->subpel_mc_block_in_4x4_v += (1 << (num_pels_log2_lookup[bsize] - 4));
if (mbmi->mv[0].as_mv.col & 0x07)
pbi->subpel_mc_block_in_4x4_h += (1 << (num_pels_log2_lookup[bsize] - 4));
if (is_compound) {
if (mbmi->mv[1].as_mv.row & 0x07)
pbi->subpel_mc_block_in_4x4_v += (1 << (num_pels_log2_lookup[bsize] - 4));
if (mbmi->mv[1].as_mv.col & 0x07)
pbi->subpel_mc_block_in_4x4_h += (1 << (num_pels_log2_lookup[bsize] - 4));
}
#endif
}
}
......
......@@ -26,6 +26,14 @@
extern "C" {
#endif
#if CONFIG_INTERNAL_STATS
#define BR_MOVING_AVERAGE_SIZE 4
typedef struct BR_DATA {
int64_t bit_rate[BR_MOVING_AVERAGE_SIZE];
int index;
} BR_DATA;
#endif
// TODO(hkuang): combine this with TileWorkerData.
typedef struct TileData {
VP9_COMMON *cm;
......@@ -75,6 +83,31 @@ typedef struct VP9Decoder {
int inv_tile_order;
int need_resync; // wait for key/intra-only frame.
int hold_ref_buf; // hold the reference buffer.
#if CONFIG_INTERNAL_STATS
// total blocks in unit of 8x8 inside the frame.
int64_t total_block_in_8x8;
// sub8x8 blocks in unit of 8x8.
int64_t sub8x8_inter;
int64_t sub8x8_intra;
// number of blocks using 1-D sub-pixel filtering for motion compensated
// prediction. if a block is using sub-pixel filter in both vertical and
// horizontal directions, it counts as using 1-D sub-pixel filter twice.
int64_t subpel_mc_block_in_4x4_h;
int64_t subpel_mc_block_in_4x4_v;
// nubmer of blocks using intra prediction mode.
int64_t intra_block_in_8x8;
// number of blocks using compound prediction mode.
int64_t compound_inter_block_in_8x8;
// peak N-frame-average bit rate
int64_t peak_average_br;
BR_DATA br_data;
#endif
} VP9Decoder;
int vp9_receive_compressed_data(struct VP9Decoder *pbi,
......
......@@ -897,6 +897,21 @@ static void write_tile_info(const VP9_COMMON *const cm,
}
static int get_refresh_mask(VP9_COMP *cpi) {
int lst_fb_idx = cpi->lst_fb_idx;
#if CONFIG_FULL_BUFFER_TEST
if (cpi->common.frame_type == KEY_FRAME) {
lst_fb_idx = 0;
} else {
if (cpi->lst_fb_idx == 0)
lst_fb_idx = 3;
else if (cpi->lst_fb_idx == 7)
lst_fb_idx = 0;
else
lst_fb_idx = cpi->lst_fb_idx + 1;
}
#endif
if (vp9_preserve_existing_gf(cpi)) {
// We have decided to preserve the previously existing golden frame as our
// new ARF frame. However, in the short term we leave it in the GF slot and,
......@@ -908,7 +923,7 @@ static int get_refresh_mask(VP9_COMP *cpi) {
// Note: This is highly specific to the use of ARF as a forward reference,
// and this needs to be generalized as other uses are implemented
// (like RTC/temporal scalability).
return (cpi->refresh_last_frame << cpi->lst_fb_idx) |
return (cpi->refresh_last_frame << lst_fb_idx) |
(cpi->refresh_golden_frame << cpi->alt_fb_idx);
} else {
int arf_idx = cpi->alt_fb_idx;
......@@ -916,7 +931,7 @@ static int get_refresh_mask(VP9_COMP *cpi) {
const GF_GROUP *const gf_group = &cpi->twopass.gf_group;
arf_idx = gf_group->arf_update_idx[gf_group->index];
}
return (cpi->refresh_last_frame << cpi->lst_fb_idx) |
return (cpi->refresh_last_frame << lst_fb_idx) |
(cpi->refresh_golden_frame << cpi->gld_fb_idx) |
(cpi->refresh_alt_ref_frame << arf_idx);
}
......
......@@ -1447,7 +1447,7 @@ void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) {
cpi->td.mb.e_mbd.bd = (int)cm->bit_depth;
#endif // CONFIG_VP9_HIGHBITDEPTH
rc->baseline_gf_interval = DEFAULT_GF_INTERVAL;
rc->baseline_gf_interval = (MIN_GF_INTERVAL + MAX_GF_INTERVAL) / 2;
cpi->refresh_golden_frame = 0;
cpi->refresh_last_frame = 1;
......@@ -2697,13 +2697,61 @@ void vp9_update_reference_frames(VP9_COMP *cpi) {
}
if (cpi->refresh_last_frame) {
#if CONFIG_FULL_BUFFER_TEST
int ref_index;
if (cm->frame_type == KEY_FRAME) {
cpi->lst_fb_idx = 0;
ref_index = cm->ref_frame_map[cpi->lst_fb_idx];
if (ref_index >= 0 && pool->frame_bufs[ref_index].ref_count > 0)
pool->frame_bufs[ref_index].ref_count--;
cm->ref_frame_map[cpi->lst_fb_idx] = cm->new_fb_idx;
pool->frame_bufs[cm->new_fb_idx].ref_count++;
} else {
if (cpi->lst_fb_idx == 0)
cpi->lst_fb_idx = 3;
else if (cpi->lst_fb_idx == 7)
cpi->lst_fb_idx = 0;
else
++cpi->lst_fb_idx;
ref_index = cm->ref_frame_map[cpi->lst_fb_idx];
if (ref_index >= 0 && pool->frame_bufs[ref_index].ref_count > 0)
pool->frame_bufs[ref_index].ref_count--;
ref_index = cm->ref_frame_map[cpi->lst_fb_idx];
cm->ref_frame_map[cpi->lst_fb_idx] = cm->new_fb_idx;
pool->frame_bufs[cm->new_fb_idx].ref_count++;
}
#else
ref_cnt_fb(pool->frame_bufs,
&cm->ref_frame_map[cpi->lst_fb_idx], cm->new_fb_idx);
#endif
if (!cpi->rc.is_src_frame_alt_ref)
memcpy(cpi->interp_filter_selected[LAST_FRAME],
cpi->interp_filter_selected[0],
sizeof(cpi->interp_filter_selected[0]));
}
#if CONFIG_FULL_BUFFER_TEST
// {
// int k;
// fprintf(stderr, "\nEecode frame index %d, is_show_frame %d, new_fb_idx %d\n",
// cm->current_video_frame, cm->show_frame, cm->new_fb_idx);
// for (k = 0; k < 8; ++k)
// fprintf(stderr, "%d ", cm->ref_frame_map[k]);
// fprintf(stderr, "\n");
// if (cm->frame_type == KEY_FRAME)
// fprintf(stderr, "key frame\n\n");
//
// for (k = 0; k < 16; ++k)
// fprintf(stderr, "%d ", pool->frame_bufs[cm->new_fb_idx].buf.y_buffer[k]);
// }
#endif
#if CONFIG_VP9_TEMPORAL_DENOISING
if (cpi->oxcf.noise_sensitivity > 0) {
vp9_denoiser_update_frame_info(&cpi->denoiser,
......@@ -2786,7 +2834,6 @@ void vp9_scale_references(VP9_COMP *cpi) {
if (cm->new_fb_idx == INVALID_IDX)
return;
new_fb_ptr = &pool->frame_bufs[new_fb];
cm->cur_frame = &pool->frame_bufs[new_fb];
vp9_realloc_frame_buffer(&pool->frame_bufs[new_fb].buf,
cm->width, cm->height,
cm->subsampling_x, cm->subsampling_y,
......@@ -3023,6 +3070,17 @@ static void set_frame_size(VP9_COMP *cpi) {
VP9EncoderConfig *const oxcf = &cpi->oxcf;
MACROBLOCKD *const xd = &cpi->td.mb.e_mbd;
#if CONFIG_INTERNAL_RESIZE
if (oxcf->pass == 2 && oxcf->resize_mode == RESIZE_DYNAMIC) {
if ((cm->current_video_frame % 15) == 3) {
cpi->resize_pending = 1;
cpi->rc.frame_size_selector = (cm->current_video_frame / 15) & 0x01;
} else {
cpi->resize_pending = 0;
}
}
#endif
if (oxcf->pass == 2 &&
oxcf->rc_mode == VPX_VBR &&
((oxcf->resize_mode == RESIZE_FIXED && cm->current_video_frame == 0) ||
......@@ -3035,6 +3093,11 @@ static void set_frame_size(VP9_COMP *cpi) {
oxcf->scaled_frame_height);
}
#if CONFIG_INTERNAL_RESIZE
fprintf(stderr, "%d %d\n", oxcf->scaled_frame_width,
oxcf->scaled_frame_height);
#endif
if (oxcf->pass == 0 &&
oxcf->rc_mode == VPX_CBR &&
!cpi->use_svc &&
......@@ -4197,6 +4260,26 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags,
set_frame_size(cpi);
}
#if CONFIG_FULL_BUFFER_TEST
if (cm->current_video_frame > 12 && oxcf->pass == 2) {
int mod_idx = cm->current_video_frame & 0x3F;
if (mod_idx > 12 && mod_idx < 20) {
cpi->refresh_last_frame = 0;
if (cpi->common.frame_type == KEY_FRAME) {
cpi->lst_fb_idx = 0;
} else {
if (cpi->lst_fb_idx == 0)
cpi->lst_fb_idx = 3;
else if (cpi->lst_fb_idx == 7)
cpi->lst_fb_idx = 0;
else
++cpi->lst_fb_idx;
}
}
}
#endif
for (i = 0; i < MAX_REF_FRAMES; ++i)
cpi->scaled_ref_idx[i] = INVALID_IDX;
......
......@@ -50,8 +50,6 @@
extern "C" {
#endif
#define DEFAULT_GF_INTERVAL 10
typedef struct {
int nmvjointcost[MV_JOINTS];
int nmvcosts[2][MV_VALS];
......@@ -219,6 +217,9 @@ typedef struct VP9EncoderConfig {
int arnr_max_frames;
int arnr_strength;
int min_gf_interval;
int max_gf_interval;
int tile_columns;
int tile_rows;
......
......@@ -1849,7 +1849,8 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
int64_t gf_group_bits;
double gf_group_error_left;
int gf_arf_bits;
int is_key_frame = frame_is_intra_only(cm);
const int is_key_frame = frame_is_intra_only(cm);
const int kf_or_arf_active = is_key_frame || rc->source_alt_ref_active;
// Reset the GF group data structures unless this is a key
// frame in which case it will already have been done.
......@@ -1902,7 +1903,10 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
// bits to spare and are better with a smaller interval and smaller boost.
// At high Q when there are few bits to spare we are better with a longer
// interval to spread the cost of the GF.
active_max_gf_interval = 12 + MIN(4, (int_lbq / 6));
active_max_gf_interval = rc->max_gf_interval - 4 + MIN(4, (int_lbq / 6));
if (active_max_gf_interval < active_min_gf_interval)
active_max_gf_interval = active_min_gf_interval;
if (active_max_gf_interval > rc->max_gf_interval)
active_max_gf_interval = rc->max_gf_interval;
if (active_max_gf_interval < active_min_gf_interval)
......@@ -1964,10 +1968,11 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
// Break out conditions.
if (
// Break at active_max_gf_interval unless almost totally static.
(i >= active_max_gf_interval && (zero_motion_accumulator < 0.995)) ||
((i >= active_max_gf_interval + kf_or_arf_active) &&
(zero_motion_accumulator < 0.995)) ||
(
// Don't break out with a very short interval.
(i > active_min_gf_interval) &&
(i >= active_min_gf_interval + kf_or_arf_active) &&
(!flash_detected) &&
((mv_ratio_accumulator > mv_ratio_accumulator_thresh) ||
(abs_mv_in_out_accumulator > 3.0) ||
......
......@@ -276,6 +276,27 @@ static void update_buffer_level(VP9_COMP *cpi, int encoded_frame_size) {
}
}
int vp9_rc_get_default_min_gf_interval(
int width, int height, double framerate) {
// Assume we do not need any constraint lower than 4K 20 fps
static const double factor_safe = 3840 * 2160 * 20.0;
const double factor = width * height * framerate;
if (factor <= factor_safe)
return MIN_GF_INTERVAL;
else
return (int)(MIN_GF_INTERVAL * factor / factor_safe + 0.5);
// Note this logic makes:
// 4K24: 5
// 4K30: 6
// 4K60: 12
}
int vp9_rc_get_default_max_gf_interval(double framerate, int min_gf_interval) {
int interval = MIN(MAX_GF_INTERVAL, (int)(framerate * 0.75));
return MAX(interval, min_gf_interval);
}
void vp9_rc_init(const VP9EncoderConfig *oxcf, int pass, RATE_CONTROL *rc) {
int i;
......@@ -284,9 +305,9 @@ void vp9_rc_init(const VP9EncoderConfig *oxcf, int pass, RATE_CONTROL *rc) {
rc->avg_frame_qindex[INTER_FRAME] = oxcf->worst_allowed_q;
} else {
rc->avg_frame_qindex[KEY_FRAME] = (oxcf->worst_allowed_q +
oxcf->best_allowed_q) / 2;
oxcf->best_allowed_q) / 2;
rc->avg_frame_qindex[INTER_FRAME] = (oxcf->worst_allowed_q +
oxcf->best_allowed_q) / 2;
oxcf->best_allowed_q) / 2;
}
rc->last_q[KEY_FRAME] = oxcf->best_allowed_q;
......@@ -304,7 +325,6 @@ void vp9_rc_init(const VP9EncoderConfig *oxcf, int pass, RATE_CONTROL *rc) {
rc->total_target_bits = 0;
rc->total_target_vs_actual = 0;
rc->baseline_gf_interval = DEFAULT_GF_INTERVAL;
rc->frames_since_key = 8; // Sensible default for first frame.
rc->this_key_frame_forced = 0;
rc->next_key_frame_forced = 0;
......@@ -322,6 +342,16 @@ void vp9_rc_init(const VP9EncoderConfig *oxcf, int pass, RATE_CONTROL *rc) {
for (i = 0; i < RATE_FACTOR_LEVELS; ++i) {
rc->rate_correction_factors[i] = 1.0;
}
rc->min_gf_interval = oxcf->min_gf_interval;
rc->max_gf_interval = oxcf->max_gf_interval;
if (rc->min_gf_interval == 0)
rc->min_gf_interval = vp9_rc_get_default_min_gf_interval(
oxcf->width, oxcf->height, oxcf->init_framerate);
if (rc->max_gf_interval == 0)
rc->max_gf_interval = vp9_rc_get_default_max_gf_interval(
oxcf->init_framerate, rc->min_gf_interval);
rc->baseline_gf_interval = (rc->min_gf_interval + rc->max_gf_interval) / 2;
}
int vp9_rc_drop_frame(VP9_COMP *cpi) {
......@@ -1382,7 +1412,7 @@ void vp9_rc_get_one_pass_vbr_params(VP9_COMP *cpi) {
cm->frame_type = INTER_FRAME;
}
if (rc->frames_till_gf_update_due == 0) {
rc->baseline_gf_interval = DEFAULT_GF_INTERVAL;
rc->baseline_gf_interval = (rc->min_gf_interval + rc->max_gf_interval) / 2;
rc->frames_till_gf_update_due = rc->baseline_gf_interval;
// NOTE: frames_till_gf_update_due must be <= frames_to_key.
if (rc->frames_till_gf_update_due > rc->frames_to_key) {
......@@ -1576,7 +1606,8 @@ void vp9_rc_get_one_pass_cbr_params(VP9_COMP *cpi) {
if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
vp9_cyclic_refresh_set_golden_update(cpi);
else
rc->baseline_gf_interval = DEFAULT_GF_INTERVAL;
rc->baseline_gf_interval =
(rc->min_gf_interval + rc->max_gf_interval) / 2;
rc->frames_till_gf_update_due = rc->baseline_gf_interval;
// NOTE: frames_till_gf_update_due must be <= frames_to_key.
if (rc->frames_till_gf_update_due > rc->frames_to_key)
......@@ -1649,20 +1680,19 @@ int vp9_compute_qdelta_by_rate(const RATE_CONTROL *rc, FRAME_TYPE frame_type,
return target_index - qindex;
}
#define MIN_GF_INTERVAL 4
#define MAX_GF_INTERVAL 16
void vp9_rc_set_gf_interval_range(const VP9_COMP *const cpi,
RATE_CONTROL *const rc) {
const VP9EncoderConfig *const oxcf = &cpi->oxcf;
// Set a minimum interval.
rc->min_gf_interval =
MIN(MAX_GF_INTERVAL, MAX(MIN_GF_INTERVAL, (int)(cpi->framerate * 0.125)));
// Set Maximum gf/arf interval.
rc->max_gf_interval =
MIN(MAX_GF_INTERVAL, (int)(cpi->framerate * 0.75));
// Round up to next even number if odd.
// Set Maximum gf/arf interval
rc->max_gf_interval = oxcf->max_gf_interval;
rc->min_gf_interval = oxcf->min_gf_interval;
if (rc->min_gf_interval == 0)
rc->min_gf_interval = vp9_rc_get_default_min_gf_interval(
oxcf->width, oxcf->height, cpi->framerate);
if (rc->max_gf_interval == 0)
rc->max_gf_interval = vp9_rc_get_default_max_gf_interval(
cpi->framerate, rc->min_gf_interval);
rc->max_gf_interval += (rc->max_gf_interval & 0x01);
// Extended interval for genuinely static scenes
......
......@@ -24,6 +24,9 @@ extern "C" {
// Bits Per MB at different Q (Multiplied by 512)
#define BPER_MB_NORMBITS 9
#define MIN_GF_INTERVAL 4
#define MAX_GF_INTERVAL 16
typedef enum {
INTER_NORMAL = 0,
INTER_HIGH = 1,
......@@ -155,6 +158,12 @@ double vp9_convert_qindex_to_q(int qindex, vpx_bit_depth_t bit_depth);
void vp9_rc_init_minq_luts(void);
int vp9_rc_get_default_min_gf_interval(int width, int height, double framerate);
// Note vp9_rc_get_default_max_gf_interval() requires the min_gf_interval to
// be passed in to ensure that the max_gf_interval returned is at least as bis
// as that.
int vp9_rc_get_default_max_gf_interval(double framerate, int min_frame_rate);
// Generally at the high level, the following flow is expected
// to be enforced for rate control:
// First call per frame, one of:
......
......@@ -1359,11 +1359,25 @@ static int64_t encode_inter_mb_segment(VP9_COMP *cpi,
const InterpKernel *kernel = vp9_get_interp_kernel(mi->mbmi.interp_filter);
for (ref = 0; ref < 1 + is_compound; ++ref) {
const uint8_t *pre = &pd->pre[ref].buf[vp9_raster_block_offset(BLOCK_8X8, i,
pd->pre[ref].stride)];
const int bw = b_width_log2_lookup[BLOCK_8X8];
const int h = 4 * (i >> bw);
const int w = 4 * (i & ((1 << bw) - 1));
const struct scale_factors *sf = &xd->block_refs[ref]->sf;
int y_stride = pd->pre[ref].stride;
uint8_t *pre = pd->pre[ref].buf + (h * pd->pre[ref].stride + w);
if (vp9_is_scaled(sf)) {
const int x_start = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x));
const int y_start = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y));
y_stride = xd->block_refs[ref]->buf->y_stride;
pre = xd->block_refs[ref]->buf->y_buffer;
pre += scaled_buffer_offset(x_start + w, y_start + h,
y_stride, sf);
}
#if CONFIG_VP9_HIGHBITDEPTH
if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
vp9_highbd_build_inter_predictor(pre, pd->pre[ref].stride,
vp9_highbd_build_inter_predictor(pre, y_stride,
dst, pd->dst.stride,
&mi->bmi[i].as_mv[ref].as_mv,
&xd->block_refs[ref]->sf, width, height,
......@@ -1371,7 +1385,7 @@ static int64_t encode_inter_mb_segment(VP9_COMP *cpi,
mi_col * MI_SIZE + 4 * (i % 2),
mi_row * MI_SIZE + 4 * (i / 2), xd->bd);
} else {
vp9_build_inter_predictor(pre, pd->pre[ref].stride,
vp9_build_inter_predictor(pre, y_stride,
dst, pd->dst.stride,
&mi->bmi[i].as_mv[ref].as_mv,
&xd->block_refs[ref]->sf, width, height, ref,
......@@ -1380,7 +1394,7 @@ static int64_t encode_inter_mb_segment(VP9_COMP *cpi,
mi_row * MI_SIZE + 4 * (i / 2));
}
#else
vp9_build_inter_predictor(pre, pd->pre[ref].stride,
vp9_build_inter_predictor(pre, y_stride,
dst, pd->dst.stride,
&mi->bmi[i].as_mv[ref].as_mv,
&xd->block_refs[ref]->sf, width, height, ref,
......@@ -3803,6 +3817,13 @@ void vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi,
int64_t total_sse = INT_MAX;
int early_term = 0;
struct buf_2d backup_yv12[2][MAX_MB_PLANE];
const YV12_BUFFER_CONFIG *scaled_ref_frame[2] = {
vp9_get_scaled_ref_frame(cpi, vp9_ref_order[ref_index].ref_frame[0]),
vp9_get_scaled_ref_frame(cpi, vp9_ref_order[ref_index].ref_frame[1])
};
int ref;
ref_frame = vp9_ref_order[ref_index].ref_frame[0];
second_ref_frame = vp9_ref_order[ref_index].ref_frame[1];
......@@ -3858,16 +3879,6 @@ void vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi,
continue;
}
// TODO(jingning, jkoleszar): scaling reference frame not supported for
// sub8x8 blocks.
if (ref_frame > INTRA_FRAME &&
vp9_is_scaled(&cm->frame_refs[ref_frame - 1].sf))
continue;
if (second_ref_frame > INTRA_FRAME &&
vp9_is_scaled(&cm->frame_refs[second_ref_frame - 1].sf))
continue;
if (comp_pred)
mode_excluded = cm->reference_mode == SINGLE_REFERENCE;
else if (ref_frame != INTRA_FRAME)
......@@ -3946,6 +3957,19 @@ void vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi,
int pred_exists = 0;
int uv_skippable;
for (ref = 0; ref < 2; ++ref) {
if (scaled_ref_frame[ref]) {
int i;
// Swap out the reference frame for a version that's been scaled to
// match the resolution of the current frame, allowing the existing
// motion search code to be used without additional modifications.
for (i = 0; i < MAX_MB_PLANE; i++)
backup_yv12[ref][i] = xd->plane[i].pre[ref];
vp9_setup_pre_planes(xd, ref, scaled_ref_frame[ref], mi_row, mi_col,
NULL);
}
}
this_rd_thresh = (ref_frame == LAST_FRAME) ?
rd_opt->threshes[segment_id][bsize][THR_LAST] :
rd_opt->threshes[segment_id][bsize][THR_ALTR];
......@@ -4079,8 +4103,17 @@ void vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi,
BLOCK_8X8);
memset(x->skip_txfm, 0, sizeof(x->skip_txfm));
if (!super_block_uvrd(cpi, x, &rate_uv, &distortion_uv, &uv_skippable,
&uv_sse, BLOCK_8X8, tmp_best_rdu))
&uv_sse, BLOCK_8X8, tmp_best_rdu)) {
for (ref = 0; ref < 2; ++ref) {
if (scaled_ref_frame[ref]) {
// Restore the prediction frame pointers to their unscaled versions.
int i;
for (i = 0; i < MAX_MB_PLANE; ++i)
xd->plane[i].pre[ref] = backup_yv12[ref][i];
}
}
continue;
}
rate2 += rate_uv;
distortion2 += distortion_uv;
......@@ -4089,6 +4122,15 @@ void vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi,
}
}
for (ref = 0; ref < 2; ++ref) {
if (scaled_ref_frame[ref]) {
// Restore the prediction frame pointers to their unscaled versions.
int i;
for (i = 0; i < MAX_MB_PLANE; ++i)
xd->plane[i].pre[ref] = backup_yv12[ref][i];
}
}
if (cm->reference_mode == REFERENCE_MODE_SELECT)
rate2 += compmode_cost;
......
......@@ -48,8 +48,9 @@ static void set_good_speed_feature_framesize_dependent(VP9_COMP *cpi,
if (speed >= 1) {
if (MIN(cm->width, cm->height) >= 720) {
sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT
: DISABLE_ALL_INTER_SPLIT;
// sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT
// : DISABLE_ALL_INTER_SPLIT;
// sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
sf->partition_search_breakout_dist_thr = (1 << 23);
} else {
sf->disable_split_mask = DISABLE_COMPOUND_SPLIT;
......
......@@ -31,6 +31,8 @@ struct vp9_extracfg {
unsigned int tile_rows;
unsigned int arnr_max_frames;
unsigned int arnr_strength;
unsigned int min_gf_interval;
unsigned int max_gf_interval;
vp8e_tuning tuning;
unsigned int cq_level; // constrained quality level
unsigned int rc_max_intra_bitrate_pct;
......@@ -55,6 +57,8 @@ static struct vp9_extracfg default_extra_cfg = {
0, // tile_rows
7, // arnr_max_frames
5, // arnr_strength
0, // min_gf_interval; 0 -> default decision
0, // max_gf_interval; 0 -> default decision
VP8_TUNE_PSNR, // tuning
10, // cq_level
0, // rc_max_intra_bitrate_pct
......@@ -167,6 +171,12 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx,
RANGE_CHECK_HI(cfg, rc_resize_up_thresh, 100);
RANGE_CHECK_HI(cfg, rc_resize_down_thresh, 100);
RANGE_CHECK(cfg, g_pass, VPX_RC_ONE_PASS, VPX_RC_LAST_PASS);
RANGE_CHECK(extra_cfg, min_gf_interval, 0, (MAX_LAG_BUFFERS - 1));
RANGE_CHECK(extra_cfg, max_gf_interval, 0, (MAX_LAG_BUFFERS - 1));
if (extra_cfg->min_gf_interval > 0 && extra_cfg->max_gf_interval > 0) {
RANGE_CHECK(extra_cfg, max_gf_interval, extra_cfg->min_gf_interval,
(MAX_LAG_BUFFERS - 1));
}
if (cfg->rc_resize_allowed == 1) {
RANGE_CHECK(cfg, rc_scaled_width, 0, cfg->g_w);
......@@ -454,6 +464,8 @@ static vpx_codec_err_t set_encoder_config(
oxcf->color_space = extra_cfg->color_space;
oxcf->arnr_max_frames = extra_cfg->arnr_max_frames;
oxcf->arnr_strength = extra_cfg->arnr_strength;
oxcf->min_gf_interval = extra_cfg->min_gf_interval;
oxcf->max_gf_interval = extra_cfg->max_gf_interval;
oxcf->tuning = extra_cfg->tuning;
oxcf->content = extra_cfg->content;
......@@ -727,6 +739,20 @@ static vpx_codec_err_t ctrl_set_aq_mode(vpx_codec_alg_priv_t *ctx,
return update_extra_cfg(ctx, &extra_cfg);
}
static vpx_codec_err_t ctrl_set_min_gf_interval(vpx_codec_alg_priv_t *ctx,
va_list args) {
struct vp9_extracfg extra_cfg = ctx->extra_cfg;
extra_cfg.min_gf_interval = CAST(VP9E_SET_MIN_GF_INTERVAL, args);
return update_extra_cfg(ctx, &extra_cfg);
}
static vpx_codec_err_t ctrl_set_max_gf_interval(vpx_codec_alg_priv_t *ctx,
va_list args) {
struct vp9_extracfg extra_cfg = ctx->extra_cfg;
extra_cfg.max_gf_interval = CAST(VP9E_SET_MAX_GF_INTERVAL, args);
return update_extra_cfg(ctx, &extra_cfg);
}
static vpx_codec_err_t ctrl_set_frame_periodic_boost(vpx_codec_alg_priv_t *ctx,
va_list args) {
struct vp9_extracfg extra_cfg = ctx->extra_cfg;
......@@ -1444,6 +1470,8 @@ static vpx_codec_ctrl_fn_map_t encoder_ctrl_maps[] = {
{VP9E_SET_TUNE_CONTENT, ctrl_set_tune_content},
{VP9E_SET_COLOR_SPACE, ctrl_set_color_space},
{VP9E_SET_NOISE_SENSITIVITY, ctrl_set_noise_sensitivity},
{VP9E_SET_MIN_GF_INTERVAL, ctrl_set_min_gf_interval},
{VP9E_SET_MAX_GF_INTERVAL, ctrl_set_max_gf_interval},
// Getters
{VP8E_GET_LAST_QUANTIZER, ctrl_get_quantizer},
......
......@@ -518,6 +518,22 @@ enum vp8e_enc_control_id {
*/
VP9E_SET_TEMPORAL_LAYERING_MODE,
/*!\brief Codec control function to set minimum interval between GF/ARF frames
*
* By default the value is set as 4.
*
* Supported in codecs: VP9
*/
VP9E_SET_MIN_GF_INTERVAL,
/*!\brief Codec control function to set minimum interval between GF/ARF frames
*
* By default the value is set as 16.
*
* Supported in codecs: VP9
*/
VP9E_SET_MAX_GF_INTERVAL,
/*!\brief Codec control function to get an Active map back from the encoder.
*
* Supported in codecs: VP9
......@@ -716,6 +732,10 @@ VPX_CTRL_USE_TYPE(VP9E_SET_TUNE_CONTENT, int) /* vp9e_tune_content */
VPX_CTRL_USE_TYPE(VP9E_SET_COLOR_SPACE, int)
VPX_CTRL_USE_TYPE(VP9E_SET_MIN_GF_INTERVAL, unsigned int)
VPX_CTRL_USE_TYPE(VP9E_SET_MAX_GF_INTERVAL, unsigned int)
VPX_CTRL_USE_TYPE(VP9E_GET_ACTIVEMAP, vpx_active_map_t *)
/*! @} - end defgroup vp8_encoder */
#ifdef __cplusplus
......
......@@ -396,6 +396,12 @@ static const arg_def_t gf_cbr_boost_pct = ARG_DEF(
NULL, "gf-cbr-boost", 1, "Boost for Golden Frame in CBR mode (pct)");
static const arg_def_t max_inter_rate_pct = ARG_DEF(
NULL, "max-inter-rate", 1, "Max P-frame bitrate (pct)");
static const arg_def_t min_gf_interval = ARG_DEF(
NULL, "min-gf-interval", 1,
"min gf/arf frame interval (default 0, indicating in-built behavior)");
static const arg_def_t max_gf_interval = ARG_DEF(
NULL, "max-gf-interval", 1,
"max gf/arf frame interval (default 0, indicating in-built behavior)");
static const struct arg_enum_list color_space_enum[] = {
{ "unknown", VPX_CS_UNKNOWN },
......@@ -445,6 +451,7 @@ static const arg_def_t *vp9_args[] = {
&gf_cbr_boost_pct, &lossless,
&frame_parallel_decoding, &aq_mode, &frame_periodic_boost,
&noise_sens, &tune_content, &input_color_space,
&min_gf_interval, &max_gf_interval,
#if CONFIG_VP9 && CONFIG_VP9_HIGHBITDEPTH
&bitdeptharg, &inbitdeptharg,
#endif
......@@ -460,6 +467,7 @@ static const int vp9_arg_ctrl_map[] = {
VP9E_SET_LOSSLESS, VP9E_SET_FRAME_PARALLEL_DECODING, VP9E_SET_AQ_MODE,
VP9E_SET_FRAME_PERIODIC_BOOST, VP9E_SET_NOISE_SENSITIVITY,
VP9E_SET_TUNE_CONTENT, VP9E_SET_COLOR_SPACE,
VP9E_SET_MIN_GF_INTERVAL, VP9E_SET_MAX_GF_INTERVAL,
0
};
#endif
......