diff options
32 files changed, 976 insertions, 397 deletions
diff --git a/build/make/gen_msvs_vcxproj.sh b/build/make/gen_msvs_vcxproj.sh index 4558aa1c1..7c8871ba2 100755 --- a/build/make/gen_msvs_vcxproj.sh +++ b/build/make/gen_msvs_vcxproj.sh @@ -28,6 +28,7 @@ Options: --lib Generate a project for creating a static library --dll Generate a project for creating a dll --static-crt Use the static C runtime (/MT) + --enable-werror Treat warnings as errors (/WX) --target=isa-os-cc Target specifier (required) --out=filename Write output to a file [stdout] --name=project_name Name of the project (required) @@ -233,6 +234,8 @@ for opt in "$@"; do ;; --static-crt) use_static_runtime=true ;; + --enable-werror) werror=true + ;; --ver=*) vs_ver="$optval" case "$optval" in @@ -492,7 +495,9 @@ generate_vcxproj() { tag_content PreprocessorDefinitions "WIN32;$debug;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE$extradefines;%(PreprocessorDefinitions)" tag_content RuntimeLibrary $runtime tag_content WarningLevel Level3 - # DebugInformationFormat + if ${werror:-false}; then + tag_content TreatWarningAsError true + fi close_tag ClCompile case "$proj_kind" in exe) @@ -689,6 +689,7 @@ process_toolchain() { 10|11|12) VCPROJ_SFX=vcxproj gen_vcproj_cmd=${source_path}/build/make/gen_msvs_vcxproj.sh + enabled werror && gen_vcproj_cmd="${gen_vcproj_cmd} --enable-werror" ;; esac all_targets="${all_targets} solution" diff --git a/test/active_map_test.cc b/test/active_map_test.cc new file mode 100644 index 000000000..6377e725a --- /dev/null +++ b/test/active_map_test.cc @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2014 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 <climits> +#include <vector> +#include "third_party/googletest/src/include/gtest/gtest.h" +#include "test/codec_factory.h" +#include "test/encode_test_driver.h" +#include "test/i420_video_source.h" +#include "test/util.h" + +namespace { + +class ActiveMapTest + : public ::libvpx_test::EncoderTest, + public ::libvpx_test::CodecTestWith2Params<libvpx_test::TestMode, int> { + protected: + static const int kWidth = 208; + static const int kHeight = 144; + + ActiveMapTest() : EncoderTest(GET_PARAM(0)) {} + virtual ~ActiveMapTest() {} + + virtual void SetUp() { + InitializeConfig(); + SetMode(GET_PARAM(1)); + cpu_used_ = GET_PARAM(2); + } + + virtual void PreEncodeFrameHook(::libvpx_test::VideoSource *video, + ::libvpx_test::Encoder *encoder) { + if (video->frame() == 1) { + encoder->Control(VP8E_SET_CPUUSED, cpu_used_); + } else if (video->frame() == 3) { + vpx_active_map_t map = {0}; + uint8_t active_map[9 * 13] = { + 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, + 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, + 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, + 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, + 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, + 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, + 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, + 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, + }; + map.cols = (kWidth + 15) / 16; + map.rows = (kHeight + 15) / 16; + ASSERT_EQ(map.cols, 13u); + ASSERT_EQ(map.rows, 9u); + map.active_map = active_map; + encoder->Control(VP8E_SET_ACTIVEMAP, &map); + } else if (video->frame() == 15) { + vpx_active_map_t map = {0}; + map.cols = (kWidth + 15) / 16; + map.rows = (kHeight + 15) / 16; + map.active_map = NULL; + encoder->Control(VP8E_SET_ACTIVEMAP, &map); + } + } + + int cpu_used_; +}; + +TEST_P(ActiveMapTest, Test) { + // Validate that this non multiple of 64 wide clip encodes + cfg_.g_lag_in_frames = 0; + cfg_.rc_target_bitrate = 400; + cfg_.rc_resize_allowed = 0; + cfg_.g_pass = VPX_RC_ONE_PASS; + cfg_.rc_end_usage = VPX_CBR; + cfg_.kf_max_dist = 90000; + + ::libvpx_test::I420VideoSource video("hantro_odd.yuv", kWidth, kHeight, 30, + 1, 0, 20); + + ASSERT_NO_FATAL_FAILURE(RunLoop(&video)); +} + +#define VP9_FACTORY \ + static_cast<const libvpx_test::CodecFactory *>(&libvpx_test::kVP9) + +VP9_INSTANTIATE_TEST_CASE(ActiveMapTest, + ::testing::Values(::libvpx_test::kRealTime), + ::testing::Range(0, 6)); +} // namespace diff --git a/test/borders_test.cc b/test/borders_test.cc index 5071541ab..b30be4580 100644 --- a/test/borders_test.cc +++ b/test/borders_test.cc @@ -21,6 +21,7 @@ class BordersTest : public ::libvpx_test::EncoderTest, public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> { protected: BordersTest() : EncoderTest(GET_PARAM(0)) {} + virtual ~BordersTest() {} virtual void SetUp() { InitializeConfig(); diff --git a/test/config_test.cc b/test/config_test.cc index 36c63302b..04931103d 100644 --- a/test/config_test.cc +++ b/test/config_test.cc @@ -20,6 +20,7 @@ class ConfigTest : public ::libvpx_test::EncoderTest, protected: ConfigTest() : EncoderTest(GET_PARAM(0)), frame_count_in_(0), frame_count_out_(0), frame_count_max_(0) {} + virtual ~ConfigTest() {} virtual void SetUp() { InitializeConfig(); diff --git a/test/cpu_speed_test.cc b/test/cpu_speed_test.cc index 569ff2605..be651b4fe 100644 --- a/test/cpu_speed_test.cc +++ b/test/cpu_speed_test.cc @@ -22,6 +22,7 @@ class CpuSpeedTest : public ::libvpx_test::EncoderTest, libvpx_test::TestMode, int> { protected: CpuSpeedTest() : EncoderTest(GET_PARAM(0)) {} + virtual ~CpuSpeedTest() {} virtual void SetUp() { InitializeConfig(); diff --git a/test/datarate_test.cc b/test/datarate_test.cc index 022223ffa..f673adc74 100644 --- a/test/datarate_test.cc +++ b/test/datarate_test.cc @@ -17,10 +17,12 @@ namespace { -class DatarateTest : public ::libvpx_test::EncoderTest, +class DatarateTestLarge : public ::libvpx_test::EncoderTest, public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> { public: - DatarateTest() : EncoderTest(GET_PARAM(0)) {} + DatarateTestLarge() : EncoderTest(GET_PARAM(0)) {} + + virtual ~DatarateTestLarge() {} protected: virtual void SetUp() { @@ -120,7 +122,7 @@ class DatarateTest : public ::libvpx_test::EncoderTest, size_t bits_in_last_frame_; }; -TEST_P(DatarateTest, BasicBufferModel) { +TEST_P(DatarateTestLarge, BasicBufferModel) { cfg_.rc_buf_initial_sz = 500; cfg_.rc_dropframe_thresh = 1; cfg_.rc_max_quantizer = 56; @@ -151,7 +153,7 @@ TEST_P(DatarateTest, BasicBufferModel) { } } -TEST_P(DatarateTest, ChangingDropFrameThresh) { +TEST_P(DatarateTestLarge, ChangingDropFrameThresh) { cfg_.rc_buf_initial_sz = 500; cfg_.rc_max_quantizer = 36; cfg_.rc_end_usage = VPX_CBR; @@ -179,13 +181,13 @@ TEST_P(DatarateTest, ChangingDropFrameThresh) { } } -class DatarateTestVP9 : public ::libvpx_test::EncoderTest, +class DatarateTestVP9Large : public ::libvpx_test::EncoderTest, public ::libvpx_test::CodecTestWith2Params<libvpx_test::TestMode, int> { public: - DatarateTestVP9() : EncoderTest(GET_PARAM(0)) {} + DatarateTestVP9Large() : EncoderTest(GET_PARAM(0)) {} protected: - virtual ~DatarateTestVP9() {} + virtual ~DatarateTestVP9Large() {} virtual void SetUp() { InitializeConfig(); @@ -358,7 +360,7 @@ class DatarateTestVP9 : public ::libvpx_test::EncoderTest, }; // Check basic rate targeting, -TEST_P(DatarateTestVP9, BasicRateTargeting) { +TEST_P(DatarateTestVP9Large, BasicRateTargeting) { cfg_.rc_buf_initial_sz = 500; cfg_.rc_buf_optimal_sz = 500; cfg_.rc_buf_sz = 1000; @@ -382,7 +384,7 @@ TEST_P(DatarateTestVP9, BasicRateTargeting) { } // Check basic rate targeting, -TEST_P(DatarateTestVP9, BasicRateTargeting444) { +TEST_P(DatarateTestVP9Large, BasicRateTargeting444) { ::libvpx_test::Y4mVideoSource video("rush_hour_444.y4m", 0, 140); cfg_.g_profile = 1; @@ -414,7 +416,7 @@ TEST_P(DatarateTestVP9, BasicRateTargeting444) { // as the drop frame threshold is increased, and (2) that the total number of // frame drops does not decrease as we increase frame drop threshold. // Use a lower qp-max to force some frame drops. -TEST_P(DatarateTestVP9, ChangingDropFrameThresh) { +TEST_P(DatarateTestVP9Large, ChangingDropFrameThresh) { cfg_.rc_buf_initial_sz = 500; cfg_.rc_buf_optimal_sz = 500; cfg_.rc_buf_sz = 1000; @@ -455,7 +457,7 @@ TEST_P(DatarateTestVP9, ChangingDropFrameThresh) { } // Check basic rate targeting for 2 temporal layers. -TEST_P(DatarateTestVP9, BasicRateTargeting2TemporalLayers) { +TEST_P(DatarateTestVP9Large, BasicRateTargeting2TemporalLayers) { cfg_.rc_buf_initial_sz = 500; cfg_.rc_buf_optimal_sz = 500; cfg_.rc_buf_sz = 1000; @@ -492,7 +494,7 @@ TEST_P(DatarateTestVP9, BasicRateTargeting2TemporalLayers) { } // Check basic rate targeting for 3 temporal layers. -TEST_P(DatarateTestVP9, BasicRateTargeting3TemporalLayers) { +TEST_P(DatarateTestVP9Large, BasicRateTargeting3TemporalLayers) { cfg_.rc_buf_initial_sz = 500; cfg_.rc_buf_optimal_sz = 500; cfg_.rc_buf_sz = 1000; @@ -533,7 +535,7 @@ TEST_P(DatarateTestVP9, BasicRateTargeting3TemporalLayers) { // Check basic rate targeting for 3 temporal layers, with frame dropping. // Only for one (low) bitrate with lower max_quantizer, and somewhat higher // frame drop threshold, to force frame dropping. -TEST_P(DatarateTestVP9, BasicRateTargeting3TemporalLayersFrameDropping) { +TEST_P(DatarateTestVP9Large, BasicRateTargeting3TemporalLayersFrameDropping) { cfg_.rc_buf_initial_sz = 500; cfg_.rc_buf_optimal_sz = 500; cfg_.rc_buf_sz = 1000; @@ -574,8 +576,8 @@ TEST_P(DatarateTestVP9, BasicRateTargeting3TemporalLayersFrameDropping) { } } -VP8_INSTANTIATE_TEST_CASE(DatarateTest, ALL_TEST_MODES); -VP9_INSTANTIATE_TEST_CASE(DatarateTestVP9, +VP8_INSTANTIATE_TEST_CASE(DatarateTestLarge, ALL_TEST_MODES); +VP9_INSTANTIATE_TEST_CASE(DatarateTestVP9Large, ::testing::Values(::libvpx_test::kOnePassGood, ::libvpx_test::kRealTime), ::testing::Range(2, 7)); diff --git a/test/encode_test_driver.h b/test/encode_test_driver.h index 8017a2a06..9526068da 100644 --- a/test/encode_test_driver.h +++ b/test/encode_test_driver.h @@ -16,6 +16,9 @@ #include "./vpx_config.h" #include "third_party/googletest/src/include/gtest/gtest.h" #include "vpx/vpx_encoder.h" +#if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER +#include "vpx/vp8cx.h" +#endif namespace libvpx_test { @@ -128,6 +131,13 @@ class Encoder { ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError(); } +#if CONFIG_VP8_ENCODER || CONFIG_VP9_ENCODER + void Control(int ctrl_id, vpx_active_map_t *arg) { + const vpx_codec_err_t res = vpx_codec_control_(&encoder_, ctrl_id, arg); + ASSERT_EQ(VPX_CODEC_OK, res) << EncoderError(); + } +#endif + void set_deadline(unsigned long deadline) { deadline_ = deadline; } diff --git a/test/error_resilience_test.cc b/test/error_resilience_test.cc index 4cd9efb86..89684f801 100644 --- a/test/error_resilience_test.cc +++ b/test/error_resilience_test.cc @@ -19,19 +19,20 @@ namespace { const int kMaxErrorFrames = 12; const int kMaxDroppableFrames = 12; -class ErrorResilienceTest : public ::libvpx_test::EncoderTest, +class ErrorResilienceTestLarge : public ::libvpx_test::EncoderTest, public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> { protected: - ErrorResilienceTest() : EncoderTest(GET_PARAM(0)), - psnr_(0.0), - nframes_(0), - mismatch_psnr_(0.0), - mismatch_nframes_(0), - encoding_mode_(GET_PARAM(1)) { + ErrorResilienceTestLarge() + : EncoderTest(GET_PARAM(0)), + psnr_(0.0), + nframes_(0), + mismatch_psnr_(0.0), + mismatch_nframes_(0), + encoding_mode_(GET_PARAM(1)) { Reset(); } - virtual ~ErrorResilienceTest() {} + virtual ~ErrorResilienceTestLarge() {} void Reset() { error_nframes_ = 0; @@ -144,7 +145,7 @@ class ErrorResilienceTest : public ::libvpx_test::EncoderTest, libvpx_test::TestMode encoding_mode_; }; -TEST_P(ErrorResilienceTest, OnVersusOff) { +TEST_P(ErrorResilienceTestLarge, OnVersusOff) { const vpx_rational timebase = { 33333333, 1000000000 }; cfg_.g_timebase = timebase; cfg_.rc_target_bitrate = 2000; @@ -179,7 +180,7 @@ TEST_P(ErrorResilienceTest, OnVersusOff) { // if we lose (i.e., drop before decoding) a set of droppable // frames (i.e., frames that don't update any reference buffers). // Check both isolated and consecutive loss. -TEST_P(ErrorResilienceTest, DropFramesWithoutRecovery) { +TEST_P(ErrorResilienceTestLarge, DropFramesWithoutRecovery) { const vpx_rational timebase = { 33333333, 1000000000 }; cfg_.g_timebase = timebase; cfg_.rc_target_bitrate = 500; @@ -235,7 +236,7 @@ TEST_P(ErrorResilienceTest, DropFramesWithoutRecovery) { #endif } -VP8_INSTANTIATE_TEST_CASE(ErrorResilienceTest, ONE_PASS_TEST_MODES); -VP9_INSTANTIATE_TEST_CASE(ErrorResilienceTest, ONE_PASS_TEST_MODES); +VP8_INSTANTIATE_TEST_CASE(ErrorResilienceTestLarge, ONE_PASS_TEST_MODES); +VP9_INSTANTIATE_TEST_CASE(ErrorResilienceTestLarge, ONE_PASS_TEST_MODES); } // namespace diff --git a/test/keyframe_test.cc b/test/keyframe_test.cc index 7ee289844..d8b21a14d 100644 --- a/test/keyframe_test.cc +++ b/test/keyframe_test.cc @@ -21,6 +21,7 @@ class KeyframeTest : public ::libvpx_test::EncoderTest, public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> { protected: KeyframeTest() : EncoderTest(GET_PARAM(0)) {} + virtual ~KeyframeTest() {} virtual void SetUp() { InitializeConfig(); diff --git a/test/superframe_test.cc b/test/superframe_test.cc index d91e7b10b..c0f542da8 100644 --- a/test/superframe_test.cc +++ b/test/superframe_test.cc @@ -21,6 +21,7 @@ class SuperframeTest : public ::libvpx_test::EncoderTest, protected: SuperframeTest() : EncoderTest(GET_PARAM(0)), modified_buf_(NULL), last_sf_pts_(0) {} + virtual ~SuperframeTest() {} virtual void SetUp() { InitializeConfig(); diff --git a/test/test.mk b/test/test.mk index bf6d055ff..00b35dca8 100644 --- a/test/test.mk +++ b/test/test.mk @@ -29,6 +29,7 @@ LIBVPX_TEST_SRCS-$(CONFIG_VP8_ENCODER) += cq_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP8_ENCODER) += keyframe_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_DECODER) += external_frame_buffer_test.cc +LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += active_map_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += borders_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += cpu_speed_test.cc LIBVPX_TEST_SRCS-$(CONFIG_VP9_ENCODER) += resize_test.cc diff --git a/test/vp9_lossless_test.cc b/test/vp9_lossless_test.cc index ad7ba44a8..7c3ba9f62 100644 --- a/test/vp9_lossless_test.cc +++ b/test/vp9_lossless_test.cc @@ -19,16 +19,17 @@ namespace { const int kMaxPsnr = 100; -class LossLessTest : public ::libvpx_test::EncoderTest, +class LosslessTestLarge : public ::libvpx_test::EncoderTest, public ::libvpx_test::CodecTestWithParam<libvpx_test::TestMode> { protected: - LossLessTest() : EncoderTest(GET_PARAM(0)), - psnr_(kMaxPsnr), - nframes_(0), - encoding_mode_(GET_PARAM(1)) { + LosslessTestLarge() + : EncoderTest(GET_PARAM(0)), + psnr_(kMaxPsnr), + nframes_(0), + encoding_mode_(GET_PARAM(1)) { } - virtual ~LossLessTest() {} + virtual ~LosslessTestLarge() {} virtual void SetUp() { InitializeConfig(); @@ -55,7 +56,7 @@ class LossLessTest : public ::libvpx_test::EncoderTest, libvpx_test::TestMode encoding_mode_; }; -TEST_P(LossLessTest, TestLossLessEncoding) { +TEST_P(LosslessTestLarge, TestLossLessEncoding) { const vpx_rational timebase = { 33333333, 1000000000 }; cfg_.g_timebase = timebase; cfg_.rc_target_bitrate = 2000; @@ -73,7 +74,7 @@ TEST_P(LossLessTest, TestLossLessEncoding) { EXPECT_GE(psnr_lossless, kMaxPsnr); } -TEST_P(LossLessTest, TestLossLessEncoding444) { +TEST_P(LosslessTestLarge, TestLossLessEncoding444) { libvpx_test::Y4mVideoSource video("rush_hour_444.y4m", 0, 10); cfg_.g_profile = 1; @@ -90,5 +91,5 @@ TEST_P(LossLessTest, TestLossLessEncoding444) { EXPECT_GE(psnr_lossless, kMaxPsnr); } -VP9_INSTANTIATE_TEST_CASE(LossLessTest, ALL_TEST_MODES); +VP9_INSTANTIATE_TEST_CASE(LosslessTestLarge, ALL_TEST_MODES); } // namespace diff --git a/vp9/common/vp9_blockd.h b/vp9/common/vp9_blockd.h index 84403ae15..b9e30fe9a 100644 --- a/vp9/common/vp9_blockd.h +++ b/vp9/common/vp9_blockd.h @@ -204,7 +204,6 @@ typedef struct RefBuffer { typedef struct macroblockd { struct macroblockd_plane plane[MAX_MB_PLANE]; - MODE_INFO *last_mi; int mode_info_stride; // A NULL indicates that the 8x8 is not part of the image @@ -255,7 +254,7 @@ static INLINE BLOCK_SIZE get_subsize(BLOCK_SIZE bsize, return subsize; } -extern const TX_TYPE mode2txfm_map[INTRA_MODES]; +extern const TX_TYPE intra_mode_to_tx_type_lookup[INTRA_MODES]; static INLINE TX_TYPE get_tx_type(PLANE_TYPE plane_type, const MACROBLOCKD *xd) { @@ -263,7 +262,7 @@ static INLINE TX_TYPE get_tx_type(PLANE_TYPE plane_type, if (plane_type != PLANE_TYPE_Y || is_inter_block(mbmi)) return DCT_DCT; - return mode2txfm_map[mbmi->mode]; + return intra_mode_to_tx_type_lookup[mbmi->mode]; } static INLINE TX_TYPE get_tx_type_4x4(PLANE_TYPE plane_type, @@ -273,7 +272,7 @@ static INLINE TX_TYPE get_tx_type_4x4(PLANE_TYPE plane_type, if (plane_type != PLANE_TYPE_Y || xd->lossless || is_inter_block(&mi->mbmi)) return DCT_DCT; - return mode2txfm_map[get_y_mode(mi, ib)]; + return intra_mode_to_tx_type_lookup[get_y_mode(mi, ib)]; } void vp9_setup_block_planes(MACROBLOCKD *xd, int ss_x, int ss_y); diff --git a/vp9/common/vp9_entropy.h b/vp9/common/vp9_entropy.h index f0097775b..15bf8ebb3 100644 --- a/vp9/common/vp9_entropy.h +++ b/vp9/common/vp9_entropy.h @@ -181,7 +181,7 @@ static const INLINE scan_order *get_scan(const MACROBLOCKD *xd, TX_SIZE tx_size, return &vp9_default_scan_orders[tx_size]; } else { const MB_PREDICTION_MODE mode = get_y_mode(mi, block_idx); - return &vp9_scan_orders[tx_size][mode2txfm_map[mode]]; + return &vp9_scan_orders[tx_size][intra_mode_to_tx_type_lookup[mode]]; } } diff --git a/vp9/common/vp9_mvref_common.c b/vp9/common/vp9_mvref_common.c index d179f4289..9f2c2dfac 100644 --- a/vp9/common/vp9_mvref_common.c +++ b/vp9/common/vp9_mvref_common.c @@ -188,12 +188,13 @@ static INLINE int is_inside(const TileInfo *const tile, // to try and find candidate reference vectors. static void find_mv_refs_idx(const VP9_COMMON *cm, const MACROBLOCKD *xd, const TileInfo *const tile, - MODE_INFO *mi, const MODE_INFO *prev_mi, - MV_REFERENCE_FRAME ref_frame, + MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame, int_mv *mv_ref_list, int block, int mi_row, int mi_col) { const int *ref_sign_bias = cm->ref_frame_sign_bias; int i, refmv_count = 0; + const MODE_INFO *prev_mi = cm->coding_use_prev_mi && cm->prev_mi ? + xd->prev_mi_8x8[0] : NULL; const POSITION *const mv_ref_search = mv_ref_blocks[mi->mbmi.sb_type]; const MB_MODE_INFO *const prev_mbmi = cm->coding_use_prev_mi && prev_mi ? &prev_mi->mbmi : NULL; @@ -282,11 +283,10 @@ static void find_mv_refs_idx(const VP9_COMMON *cm, const MACROBLOCKD *xd, void vp9_find_mv_refs(const VP9_COMMON *cm, const MACROBLOCKD *xd, const TileInfo *const tile, - MODE_INFO *mi, const MODE_INFO *prev_mi, - MV_REFERENCE_FRAME ref_frame, + MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame, int_mv *mv_ref_list, int mi_row, int mi_col) { - find_mv_refs_idx(cm, xd, tile, mi, prev_mi, ref_frame, mv_ref_list, -1, + find_mv_refs_idx(cm, xd, tile, mi, ref_frame, mv_ref_list, -1, mi_row, mi_col); } @@ -324,8 +324,8 @@ void vp9_append_sub8x8_mvs_for_idx(VP9_COMMON *cm, MACROBLOCKD *xd, assert(MAX_MV_REF_CANDIDATES == 2); - find_mv_refs_idx(cm, xd, tile, mi, xd->last_mi, mi->mbmi.ref_frame[ref], - mv_list, block, mi_row, mi_col); + find_mv_refs_idx(cm, xd, tile, mi, mi->mbmi.ref_frame[ref], mv_list, block, + mi_row, mi_col); near->as_int = 0; switch (block) { diff --git a/vp9/common/vp9_mvref_common.h b/vp9/common/vp9_mvref_common.h index 04cb000ef..903ac02bb 100644 --- a/vp9/common/vp9_mvref_common.h +++ b/vp9/common/vp9_mvref_common.h @@ -31,10 +31,8 @@ static INLINE void clamp_mv2(MV *mv, const MACROBLOCKD *xd) { void vp9_find_mv_refs(const VP9_COMMON *cm, const MACROBLOCKD *xd, const TileInfo *const tile, - MODE_INFO *mi, const MODE_INFO *prev_mi, - MV_REFERENCE_FRAME ref_frame, - int_mv *mv_ref_list, - int mi_row, int mi_col); + MODE_INFO *mi, MV_REFERENCE_FRAME ref_frame, + int_mv *mv_ref_list, int mi_row, int mi_col); // check a list of motion vectors by sad score using a number rows of pixels // above and a number cols of pixels in the left to select the one with best diff --git a/vp9/common/vp9_onyxc_int.h b/vp9/common/vp9_onyxc_int.h index 52889f75f..024b197a1 100644 --- a/vp9/common/vp9_onyxc_int.h +++ b/vp9/common/vp9_onyxc_int.h @@ -153,6 +153,10 @@ typedef struct VP9Common { MODE_INFO **prev_mi_grid_base; MODE_INFO **prev_mi_grid_visible; + // Each tile column has its own MODE_INFO stream. This array indexes them by + // tile column index. + MODE_INFO **mi_streams; + // Persistent mb segment id map used in prediction. unsigned char *last_frame_seg_map; diff --git a/vp9/common/vp9_reconinter.c b/vp9/common/vp9_reconinter.c index e357b367f..86548750e 100644 --- a/vp9/common/vp9_reconinter.c +++ b/vp9/common/vp9_reconinter.c @@ -244,6 +244,7 @@ void vp9_build_inter_predictors_sb(MACROBLOCKD *xd, int mi_row, int mi_col, // TODO(jingning): This function serves as a placeholder for decoder prediction // using on demand border extension. It should be moved to /decoder/ directory. static void dec_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) { struct macroblockd_plane *const pd = &xd->plane[plane]; @@ -265,15 +266,21 @@ static void dec_build_inter_predictors(MACROBLOCKD *xd, int plane, int block, ? (plane == 0 ? mi->bmi[block].as_mv[ref].as_mv : mi_mv_pred_q4(mi, ref)) : mi->mbmi.mv[ref].as_mv; + + // TODO(jkoleszar): This clamping is done in the incorrect place for the + // scaling case. It needs to be done on the scaled MV, not the pre-scaling + // MV. Note however that it performs the subsampling aware scaling so + // that the result is always q4. + // mv_precision precision is MV_PRECISION_Q4. + const MV mv_q4 = clamp_mv_to_umv_border_sb(xd, &mv, bw, bh, + pd->subsampling_x, + pd->subsampling_y); + MV32 scaled_mv; int xs, ys, x0, y0, x0_16, y0_16, frame_width, frame_height, buf_stride, subpel_x, subpel_y; uint8_t *ref_frame, *buf_ptr; const YV12_BUFFER_CONFIG *ref_buf = xd->block_refs[ref]->buf; - const MV mv_q4 = { - mv.row * (1 << (1 - pd->subsampling_y)), - mv.col * (1 << (1 - pd->subsampling_x)) - }; // Get reference frame pointer, width and height. if (plane == 0) { @@ -377,10 +384,10 @@ void vp9_dec_build_inter_predictors_sb(MACROBLOCKD *xd, int mi_row, int mi_col, assert(bsize == BLOCK_8X8); for (y = 0; y < num_4x4_h; ++y) for (x = 0; x < num_4x4_w; ++x) - dec_build_inter_predictors(xd, plane, i++, + dec_build_inter_predictors(xd, plane, i++, bw, bh, 4 * x, 4 * y, 4, 4, mi_x, mi_y); } else { - dec_build_inter_predictors(xd, plane, 0, + dec_build_inter_predictors(xd, plane, 0, bw, bh, 0, 0, bw, bh, mi_x, mi_y); } } diff --git a/vp9/common/vp9_reconintra.c b/vp9/common/vp9_reconintra.c index 86f4f3578..1b341dd7a 100644 --- a/vp9/common/vp9_reconintra.c +++ b/vp9/common/vp9_reconintra.c @@ -18,7 +18,7 @@ #include "vp9/common/vp9_reconintra.h" #include "vp9/common/vp9_onyxc_int.h" -const TX_TYPE mode2txfm_map[INTRA_MODES] = { +const TX_TYPE intra_mode_to_tx_type_lookup[INTRA_MODES] = { DCT_DCT, // DC ADST_DCT, // V DCT_ADST, // H diff --git a/vp9/decoder/vp9_decodeframe.c b/vp9/decoder/vp9_decodeframe.c index 1e203b19f..728d92dfb 100644 --- a/vp9/decoder/vp9_decodeframe.c +++ b/vp9/decoder/vp9_decodeframe.c @@ -195,16 +195,15 @@ static void alloc_tile_storage(VP9D_COMP *pbi, int tile_rows, int tile_cols) { const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols); int i, tile_row, tile_col; - CHECK_MEM_ERROR(cm, pbi->mi_streams, - vpx_realloc(pbi->mi_streams, tile_rows * tile_cols * - sizeof(*pbi->mi_streams))); + CHECK_MEM_ERROR(cm, cm->mi_streams, + vpx_realloc(cm->mi_streams, tile_rows * tile_cols * + sizeof(*cm->mi_streams))); for (tile_row = 0; tile_row < tile_rows; ++tile_row) { for (tile_col = 0; tile_col < tile_cols; ++tile_col) { TileInfo tile; vp9_tile_init(&tile, cm, tile_row, tile_col); - pbi->mi_streams[tile_row * tile_cols + tile_col] = - &cm->mi[tile.mi_row_start * cm->mode_info_stride - + tile.mi_col_start]; + cm->mi_streams[tile_row * tile_cols + tile_col] = + &cm->mi[tile.mi_row_start * cm->mode_info_stride + tile.mi_col_start]; } } @@ -346,10 +345,6 @@ static void set_offsets(VP9_COMMON *const cm, MACROBLOCKD *const xd, xd->mi_8x8 = cm->mi_grid_visible + offset; xd->prev_mi_8x8 = cm->prev_mi_grid_visible + offset; - - xd->last_mi = cm->coding_use_prev_mi && cm->prev_mi ? - xd->prev_mi_8x8[0] : NULL; - xd->mi_8x8[0] = xd->mi_stream + offset - tile_offset; xd->mi_8x8[0]->mbmi.sb_type = bsize; for (y = 0; y < y_mis; ++y) @@ -378,10 +373,10 @@ static void set_ref(VP9_COMMON *const cm, MACROBLOCKD *const xd, xd->corrupted |= ref_buffer->buf->corrupted; } -static void decode_modes_b(VP9_COMMON *const cm, MACROBLOCKD *const xd, - const TileInfo *const tile, - int mi_row, int mi_col, - vp9_reader *r, BLOCK_SIZE bsize) { +static void decode_block(VP9_COMMON *const cm, MACROBLOCKD *const xd, + const TileInfo *const tile, + int mi_row, int mi_col, + vp9_reader *r, BLOCK_SIZE bsize) { const int less8x8 = bsize < BLOCK_8X8; MB_MODE_INFO *mbmi; @@ -456,10 +451,10 @@ static PARTITION_TYPE read_partition(VP9_COMMON *cm, MACROBLOCKD *xd, int hbs, return p; } -static void decode_modes_sb(VP9_COMMON *const cm, MACROBLOCKD *const xd, - const TileInfo *const tile, - int mi_row, int mi_col, - vp9_reader* r, BLOCK_SIZE bsize) { +static void decode_partition(VP9_COMMON *const cm, MACROBLOCKD *const xd, + const TileInfo *const tile, + int mi_row, int mi_col, + vp9_reader* r, BLOCK_SIZE bsize) { const int hbs = num_8x8_blocks_wide_lookup[bsize] / 2; PARTITION_TYPE partition; BLOCK_SIZE subsize; @@ -470,27 +465,27 @@ static void decode_modes_sb(VP9_COMMON *const cm, MACROBLOCKD *const xd, partition = read_partition(cm, xd, hbs, mi_row, mi_col, bsize, r); subsize = get_subsize(bsize, partition); if (subsize < BLOCK_8X8) { - decode_modes_b(cm, xd, tile, mi_row, mi_col, r, subsize); + decode_block(cm, xd, tile, mi_row, mi_col, r, subsize); } else { switch (partition) { case PARTITION_NONE: - decode_modes_b(cm, xd, tile, mi_row, mi_col, r, subsize); + decode_block(cm, xd, tile, mi_row, mi_col, r, subsize); break; case PARTITION_HORZ: - decode_modes_b(cm, xd, tile, mi_row, mi_col, r, subsize); + decode_block(cm, xd, tile, mi_row, mi_col, r, subsize); if (mi_row + hbs < cm->mi_rows) - decode_modes_b(cm, xd, tile, mi_row + hbs, mi_col, r, subsize); + decode_block(cm, xd, tile, mi_row + hbs, mi_col, r, subsize); break; case PARTITION_VERT: - decode_modes_b(cm, xd, tile, mi_row, mi_col, r, subsize); + decode_block(cm, xd, tile, mi_row, mi_col, r, subsize); if (mi_col + hbs < cm->mi_cols) - decode_modes_b(cm, xd, tile, mi_row, mi_col + hbs, r, subsize); + decode_block(cm, xd, tile, mi_row, mi_col + hbs, r, subsize); break; case PARTITION_SPLIT: - decode_modes_sb(cm, xd, tile, mi_row, mi_col, r, subsize); - decode_modes_sb(cm, xd, tile, mi_row, mi_col + hbs, r, subsize); - decode_modes_sb(cm, xd, tile, mi_row + hbs, mi_col, r, subsize); - decode_modes_sb(cm, xd, tile, mi_row + hbs, mi_col + hbs, r, subsize); + decode_partition(cm, xd, tile, mi_row, mi_col, r, subsize); + decode_partition(cm, xd, tile, mi_row, mi_col + hbs, r, subsize); + decode_partition(cm, xd, tile, mi_row + hbs, mi_col, r, subsize); + decode_partition(cm, xd, tile, mi_row + hbs, mi_col + hbs, r, subsize); break; default: assert(0 && "Invalid partition type"); @@ -735,9 +730,11 @@ static void setup_frame_size_with_refs(VP9D_COMP *pbi, static void setup_tile_context(VP9D_COMP *const pbi, MACROBLOCKD *const xd, int tile_row, int tile_col) { + VP9_COMMON *const cm = &pbi->common; + const int tile_cols = 1 << cm->log2_tile_cols; int i; - const int tile_cols = 1 << pbi->common.log2_tile_cols; - xd->mi_stream = pbi->mi_streams[tile_row * tile_cols + tile_col]; + + xd->mi_stream = cm->mi_streams[tile_row * tile_cols + tile_col]; for (i = 0; i < MAX_MB_PLANE; ++i) { xd->above_context[i] = pbi->above_context[i]; @@ -770,7 +767,7 @@ static void decode_tile(VP9D_COMP *pbi, const TileInfo *const tile, vp9_zero(xd->left_seg_context); for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end; mi_col += MI_BLOCK_SIZE) { - decode_modes_sb(cm, xd, tile, mi_row, mi_col, r, BLOCK_64X64); + decode_partition(cm, xd, tile, mi_row, mi_col, r, BLOCK_64X64); } if (pbi->do_loopfilter_inline) { @@ -932,8 +929,8 @@ static int tile_worker_hook(void *arg1, void *arg2) { vp9_zero(tile_data->xd.left_seg_context); for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end; mi_col += MI_BLOCK_SIZE) { - decode_modes_sb(tile_data->cm, &tile_data->xd, tile, - mi_row, mi_col, &tile_data->bit_reader, BLOCK_64X64); + decode_partition(tile_data->cm, &tile_data->xd, tile, + mi_row, mi_col, &tile_data->bit_reader, BLOCK_64X64); } } return !tile_data->xd.corrupted; diff --git a/vp9/decoder/vp9_decodemv.c b/vp9/decoder/vp9_decodemv.c index 36bd32597..50686b3c5 100644 --- a/vp9/decoder/vp9_decodemv.c +++ b/vp9/decoder/vp9_decodemv.c @@ -432,7 +432,7 @@ static void read_inter_block_mode_info(VP9_COMMON *const cm, for (ref = 0; ref < 1 + is_compound; ++ref) { const MV_REFERENCE_FRAME frame = mbmi->ref_frame[ref]; - vp9_find_mv_refs(cm, xd, tile, mi, xd->last_mi, frame, mbmi->ref_mvs[frame], + vp9_find_mv_refs(cm, xd, tile, mi, frame, mbmi->ref_mvs[frame], mi_row, mi_col); } diff --git a/vp9/decoder/vp9_decoder.c b/vp9/decoder/vp9_decoder.c index 77985c9e7..a50f5be68 100644 --- a/vp9/decoder/vp9_decoder.c +++ b/vp9/decoder/vp9_decoder.c @@ -189,7 +189,7 @@ void vp9_remove_decompressor(VP9D_COMP *pbi) { vp9_loop_filter_dealloc(lf_sync, sb_rows); } - vpx_free(pbi->mi_streams); + vpx_free(pbi->common.mi_streams); vpx_free(pbi->above_context[0]); vpx_free(pbi->above_seg_context); vpx_free(pbi); diff --git a/vp9/decoder/vp9_decoder.h b/vp9/decoder/vp9_decoder.h index e6edaf91f..4cbff4516 100644 --- a/vp9/decoder/vp9_decoder.h +++ b/vp9/decoder/vp9_decoder.h @@ -73,10 +73,6 @@ typedef struct VP9Decompressor { VP9LfSync lf_row_sync; - /* Each tile column has its own MODE_INFO stream. This array indexes them by - tile column index. */ - MODE_INFO **mi_streams; - ENTROPY_CONTEXT *above_context[MAX_MB_PLANE]; PARTITION_CONTEXT *above_seg_context; } VP9D_COMP; diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index 358169dec..d0ada2f4e 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -150,6 +150,446 @@ static BLOCK_SIZE get_nonrd_var_based_fixed_partition(VP9_COMP *cpi, return BLOCK_16X16; } +// Lighter version of set_offsets that only sets the mode info +// pointers. +static inline void set_modeinfo_offsets(VP9_COMMON *const cm, + MACROBLOCKD *const xd, + int mi_row, + int mi_col) { + const int idx_str = xd->mode_info_stride * mi_row + mi_col; + xd->mi_8x8 = cm->mi_grid_visible + idx_str; + xd->prev_mi_8x8 = cm->prev_mi_grid_visible + idx_str; + // xd->last_mi = cm->prev_mi ? xd->prev_mi_8x8[0] : NULL; + xd->mi_8x8[0] = cm->mi + idx_str; +} + +static int is_block_in_mb_map(VP9_COMP *cpi, int mi_row, int mi_col, + BLOCK_SIZE bsize) { + VP9_COMMON *const cm = &cpi->common; + const int mb_rows = cm->mb_rows; + const int mb_cols = cm->mb_cols; + const int mb_row = mi_row >> 1; + const int mb_col = mi_col >> 1; + const int mb_width = num_8x8_blocks_wide_lookup[bsize] >> 1; + const int mb_height = num_8x8_blocks_high_lookup[bsize] >> 1; + int r, c; + if (bsize <= BLOCK_16X16) { + return cpi->active_map[mb_row * mb_cols + mb_col]; + } + for (r = 0; r < mb_height; ++r) { + for (c = 0; c < mb_width; ++c) { + int row = mb_row + r; + int col = mb_col + c; + if (row >= mb_rows || col >= mb_cols) + continue; + if (cpi->active_map[row * mb_cols + col]) + return 1; + } + } + return 0; +} + +static void set_offsets(VP9_COMP *cpi, const TileInfo *const tile, + int mi_row, int mi_col, BLOCK_SIZE bsize) { + MACROBLOCK *const x = &cpi->mb; + VP9_COMMON *const cm = &cpi->common; + MACROBLOCKD *const xd = &x->e_mbd; + MB_MODE_INFO *mbmi; + const int mi_width = num_8x8_blocks_wide_lookup[bsize]; + const int mi_height = num_8x8_blocks_high_lookup[bsize]; + const int mb_row = mi_row >> 1; + const int mb_col = mi_col >> 1; + const int idx_map = mb_row * cm->mb_cols + mb_col; + const struct segmentation *const seg = &cm->seg; + + set_skip_context(xd, cpi->above_context, cpi->left_context, mi_row, mi_col); + + // Activity map pointer + x->mb_activity_ptr = &cpi->mb_activity_map[idx_map]; + + if (cpi->active_map_enabled && !x->e_mbd.lossless) { + x->in_active_map = is_block_in_mb_map(cpi, mi_row, mi_col, bsize); + } else { + x->in_active_map = 1; + } + + set_modeinfo_offsets(cm, xd, mi_row, mi_col); + + mbmi = &xd->mi_8x8[0]->mbmi; + + // Set up destination pointers. + vp9_setup_dst_planes(xd, get_frame_new_buffer(cm), mi_row, mi_col); + + // Set up limit values for MV components. + // Mv beyond the range do not produce new/different prediction block. + x->mv_row_min = -(((mi_row + mi_height) * MI_SIZE) + VP9_INTERP_EXTEND); + x->mv_col_min = -(((mi_col + mi_width) * MI_SIZE) + VP9_INTERP_EXTEND); + x->mv_row_max = (cm->mi_rows - mi_row) * MI_SIZE + VP9_INTERP_EXTEND; + x->mv_col_max = (cm->mi_cols - mi_col) * MI_SIZE + VP9_INTERP_EXTEND; + + // Set up distance of MB to edge of frame in 1/8th pel units. + assert(!(mi_col & (mi_width - 1)) && !(mi_row & (mi_height - 1))); + set_mi_row_col(xd, tile, mi_row, mi_height, mi_col, mi_width, + cm->mi_rows, cm->mi_cols); + + // Set up source buffers. + vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col); + + // R/D setup. + x->rddiv = cpi->RDDIV; + x->rdmult = cpi->RDMULT; + + // Setup segment ID. + if (seg->enabled) { + if (cpi->oxcf.aq_mode != VARIANCE_AQ) { + const uint8_t *const map = seg->update_map ? cpi->segmentation_map + : cm->last_frame_seg_map; + mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); + } + vp9_init_plane_quantizers(cpi, x); + + if (seg->enabled && cpi->seg0_cnt > 0 && + !vp9_segfeature_active(seg, 0, SEG_LVL_REF_FRAME) && + vp9_segfeature_active(seg, 1, SEG_LVL_REF_FRAME)) { + cpi->seg0_progress = (cpi->seg0_idx << 16) / cpi->seg0_cnt; + } else { + const int y = mb_row & ~3; + const int x = mb_col & ~3; + const int p16 = ((mb_row & 1) << 1) + (mb_col & 1); + const int p32 = ((mb_row & 2) << 2) + ((mb_col & 2) << 1); + const int tile_progress = tile->mi_col_start * cm->mb_rows >> 1; + const int mb_cols = (tile->mi_col_end - tile->mi_col_start) >> 1; + + cpi->seg0_progress = ((y * mb_cols + x * 4 + p32 + p16 + tile_progress) + << 16) / cm->MBs; + } + + x->encode_breakout = cpi->segment_encode_breakout[mbmi->segment_id]; + } else { + mbmi->segment_id = 0; + x->encode_breakout = cpi->encode_breakout; + } +} + +static void duplicate_modeinfo_in_sb(VP9_COMMON * const cm, + MACROBLOCKD *const xd, + int mi_row, + int mi_col, + BLOCK_SIZE bsize) { + const int block_width = num_8x8_blocks_wide_lookup[bsize]; + const int block_height = num_8x8_blocks_high_lookup[bsize]; + const int mis = xd->mode_info_stride; + int i, j; + for (j = 0; j < block_height; ++j) + for (i = 0; i < block_width; ++i) { + if (mi_row + j < cm->mi_rows && mi_col + i < cm->mi_cols) + xd->mi_8x8[j * mis + i] = xd->mi_8x8[0]; + } +} + +static void set_block_size(VP9_COMP * const cpi, + const TileInfo *const tile, + int mi_row, int mi_col, + BLOCK_SIZE bsize) { + if (cpi->common.mi_cols > mi_col && cpi->common.mi_rows > mi_row) { + MACROBLOCKD *const xd = &cpi->mb.e_mbd; + set_modeinfo_offsets(&cpi->common, xd, mi_row, mi_col); + xd->mi_8x8[0]->mbmi.sb_type = bsize; + duplicate_modeinfo_in_sb(&cpi->common, xd, mi_row, mi_col, bsize); + } +} + +typedef struct { + int64_t sum_square_error; + int64_t sum_error; + int count; + int variance; +} var; + +typedef struct { + var none; + var horz[2]; + var vert[2]; +} partition_variance; + +typedef struct { + partition_variance part_variances; + var split[4]; +} v8x8; + +typedef struct { + partition_variance part_variances; + v8x8 split[4]; +} v16x16; + +typedef struct { + partition_variance part_variances; + v16x16 split[4]; +} v32x32; + +typedef struct { + partition_variance part_variances; + v32x32 split[4]; +} v64x64; + +typedef struct { + partition_variance *part_variances; + var *split[4]; +} variance_node; + +typedef enum { + V16X16, + V32X32, + V64X64, +} TREE_LEVEL; + +static void tree_to_node(void *data, BLOCK_SIZE bsize, variance_node *node) { + int i; + switch (bsize) { + case BLOCK_64X64: { + v64x64 *vt = (v64x64 *) data; + node->part_variances = &vt->part_variances; + for (i = 0; i < 4; i++) + node->split[i] = &vt->split[i].part_variances.none; + break; + } + case BLOCK_32X32: { + v32x32 *vt = (v32x32 *) data; + node->part_variances = &vt->part_variances; + for (i = 0; i < 4; i++) + node->split[i] = &vt->split[i].part_variances.none; + break; + } + case BLOCK_16X16: { + v16x16 *vt = (v16x16 *) data; + node->part_variances = &vt->part_variances; + for (i = 0; i < 4; i++) + node->split[i] = &vt->split[i].part_variances.none; + break; + } + case BLOCK_8X8: { + v8x8 *vt = (v8x8 *) data; + node->part_variances = &vt->part_variances; + for (i = 0; i < 4; i++) + node->split[i] = &vt->split[i]; + break; + } + default: { + assert(0); + } + } +} + +// Set variance values given sum square error, sum error, count. +static void fill_variance(int64_t s2, int64_t s, int c, var *v) { + v->sum_square_error = s2; + v->sum_error = s; + v->count = c; + if (c > 0) + v->variance = (int)(256 * + (v->sum_square_error - v->sum_error * v->sum_error / + v->count) / v->count); + else + v->variance = 0; +} + +void sum_2_variances(const var *a, const var *b, var *r) { + fill_variance(a->sum_square_error + b->sum_square_error, + a->sum_error + b->sum_error, a->count + b->count, r); +} + +static void fill_variance_tree(void *data, BLOCK_SIZE bsize) { + variance_node node; + tree_to_node(data, bsize, &node); + sum_2_variances(node.split[0], node.split[1], &node.part_variances->horz[0]); + sum_2_variances(node.split[2], node.split[3], &node.part_variances->horz[1]); + sum_2_variances(node.split[0], node.split[2], &node.part_variances->vert[0]); + sum_2_variances(node.split[1], node.split[3], &node.part_variances->vert[1]); + sum_2_variances(&node.part_variances->vert[0], &node.part_variances->vert[1], + &node.part_variances->none); +} + +static int set_vt_partitioning(VP9_COMP *cpi, + void *data, + const TileInfo *const tile, + BLOCK_SIZE bsize, + int mi_row, + int mi_col, + int mi_size) { + VP9_COMMON * const cm = &cpi->common; + variance_node vt; + const int block_width = num_8x8_blocks_wide_lookup[bsize]; + const int block_height = num_8x8_blocks_high_lookup[bsize]; + // TODO(debargha): Choose this more intelligently. + const int64_t threshold_multiplier = 25; + int64_t threshold = threshold_multiplier * cpi->common.base_qindex; + assert(block_height == block_width); + + tree_to_node(data, bsize, &vt); + + // Split none is available only if we have more than half a block size + // in width and height inside the visible image. + if (mi_col + block_width / 2 < cm->mi_cols && + mi_row + block_height / 2 < cm->mi_rows && + vt.part_variances->none.variance < threshold) { + set_block_size(cpi, tile, mi_row, mi_col, bsize); + return 1; + } + + // Vertical split is available on all but the bottom border. + if (mi_row + block_height / 2 < cm->mi_rows && + vt.part_variances->vert[0].variance < threshold && + vt.part_variances->vert[1].variance < threshold) { + BLOCK_SIZE subsize = get_subsize(bsize, PARTITION_VERT); + set_block_size(cpi, tile, mi_row, mi_col, subsize); + set_block_size(cpi, tile, mi_row, mi_col + block_width / 2, subsize); + return 1; + } + + // Horizontal split is available on all but the right border. + if (mi_col + block_width / 2 < cm->mi_cols && + vt.part_variances->horz[0].variance < threshold && + vt.part_variances->horz[1].variance < threshold) { + BLOCK_SIZE subsize = get_subsize(bsize, PARTITION_HORZ); + set_block_size(cpi, tile, mi_row, mi_col, subsize); + set_block_size(cpi, tile, mi_row + block_height / 2, mi_col, subsize); + return 1; + } + return 0; +} + +// TODO(debargha): Fix this function and make it work as expected. +static void choose_partitioning(VP9_COMP *cpi, + const TileInfo *const tile, + int mi_row, int mi_col) { + VP9_COMMON * const cm = &cpi->common; + MACROBLOCK *x = &cpi->mb; + MACROBLOCKD *xd = &cpi->mb.e_mbd; + + int i, j, k; + v64x64 vt; + uint8_t *s; + const uint8_t *d; + int sp; + int dp; + int pixels_wide = 64, pixels_high = 64; + int_mv nearest_mv, near_mv; + const YV12_BUFFER_CONFIG *yv12 = get_ref_frame_buffer(cpi, LAST_FRAME); + const struct scale_factors *const sf = &cm->frame_refs[LAST_FRAME - 1].sf; + + vp9_zero(vt); + set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); + + if (xd->mb_to_right_edge < 0) + pixels_wide += (xd->mb_to_right_edge >> 3); + if (xd->mb_to_bottom_edge < 0) + pixels_high += (xd->mb_to_bottom_edge >> 3); + + s = x->plane[0].src.buf; + sp = x->plane[0].src.stride; + + if (cm->frame_type != KEY_FRAME) { + vp9_setup_pre_planes(xd, 0, yv12, mi_row, mi_col, sf); + + xd->mi_8x8[0]->mbmi.ref_frame[0] = LAST_FRAME; + xd->mi_8x8[0]->mbmi.sb_type = BLOCK_64X64; + vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, + xd->mi_8x8[0]->mbmi.ref_mvs[LAST_FRAME], + &nearest_mv, &near_mv); + + xd->mi_8x8[0]->mbmi.mv[0] = nearest_mv; + vp9_build_inter_predictors_sby(xd, mi_row, mi_col, BLOCK_64X64); + + d = xd->plane[0].dst.buf; + dp = xd->plane[0].dst.stride; + } else { + d = VP9_VAR_OFFS; + dp = 0; + } + + // Fill in the entire tree of 8x8 variances for splits. + for (i = 0; i < 4; i++) { + const int x32_idx = ((i & 1) << 5); + const int y32_idx = ((i >> 1) << 5); + for (j = 0; j < 4; j++) { + const int x16_idx = x32_idx + ((j & 1) << 4); + const int y16_idx = y32_idx + ((j >> 1) << 4); + v16x16 *vst = &vt.split[i].split[j]; + for (k = 0; k < 4; k++) { + int x_idx = x16_idx + ((k & 1) << 3); + int y_idx = y16_idx + ((k >> 1) << 3); + unsigned int sse = 0; + int sum = 0; + if (x_idx < pixels_wide && y_idx < pixels_high) + vp9_get_sse_sum_8x8(s + y_idx * sp + x_idx, sp, + d + y_idx * dp + x_idx, dp, &sse, &sum); + fill_variance(sse, sum, 64, &vst->split[k].part_variances.none); + } + } + } + // Fill the rest of the variance tree by summing split partition values. + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + fill_variance_tree(&vt.split[i].split[j], BLOCK_16X16); + } + fill_variance_tree(&vt.split[i], BLOCK_32X32); + } + fill_variance_tree(&vt, BLOCK_64X64); + + // Now go through the entire structure, splitting every block size until + // we get to one that's got a variance lower than our threshold, or we + // hit 8x8. + if (!set_vt_partitioning(cpi, &vt, tile, BLOCK_64X64, + mi_row, mi_col, 8)) { + for (i = 0; i < 4; ++i) { + const int x32_idx = ((i & 1) << 2); + const int y32_idx = ((i >> 1) << 2); + if (!set_vt_partitioning(cpi, &vt.split[i], tile, BLOCK_32X32, + (mi_row + y32_idx), (mi_col + x32_idx), 4)) { + for (j = 0; j < 4; ++j) { + const int x16_idx = ((j & 1) << 1); + const int y16_idx = ((j >> 1) << 1); + // NOTE: This is a temporary hack to disable 8x8 partitions, + // since it works really bad - possibly due to a bug +#define DISABLE_8X8_VAR_BASED_PARTITION +#ifdef DISABLE_8X8_VAR_BASED_PARTITION + if (mi_row + y32_idx + y16_idx + 1 < cm->mi_rows && + mi_row + x32_idx + x16_idx + 1 < cm->mi_cols) { + set_block_size(cpi, tile, + (mi_row + y32_idx + y16_idx), + (mi_col + x32_idx + x16_idx), + BLOCK_16X16); + } else { + for (k = 0; k < 4; ++k) { + const int x8_idx = (k & 1); + const int y8_idx = (k >> 1); + set_block_size(cpi, tile, + (mi_row + y32_idx + y16_idx + y8_idx), + (mi_col + x32_idx + x16_idx + x8_idx), + BLOCK_8X8); + } + } +#else + if (!set_vt_partitioning(cpi, &vt.split[i].split[j], tile, + BLOCK_16X16, + (mi_row + y32_idx + y16_idx), + (mi_col + x32_idx + x16_idx), 2)) { + for (k = 0; k < 4; ++k) { + const int x8_idx = (k & 1); + const int y8_idx = (k >> 1); + set_block_size(cpi, tile, + (mi_row + y32_idx + y16_idx + y8_idx), + (mi_col + x32_idx + x16_idx + x8_idx), + BLOCK_8X8); + } + } +#endif + } + } + } + } +} + // Original activity measure from Tim T's code. static unsigned int tt_activity_measure(MACROBLOCK *x) { unsigned int sse; @@ -571,120 +1011,6 @@ void vp9_setup_src_planes(MACROBLOCK *x, const YV12_BUFFER_CONFIG *src, x->e_mbd.plane[i].subsampling_y); } -static int is_block_in_mb_map(VP9_COMP *cpi, int mi_row, int mi_col, - BLOCK_SIZE bsize) { - VP9_COMMON *const cm = &cpi->common; - const int mb_rows = cm->mb_rows; - const int mb_cols = cm->mb_cols; - const int mb_row = mi_row >> 1; - const int mb_col = mi_col >> 1; - const int mb_width = num_8x8_blocks_wide_lookup[bsize] >> 1; - const int mb_height = num_8x8_blocks_high_lookup[bsize] >> 1; - int r, c; - if (bsize <= BLOCK_16X16) { - return cpi->active_map[mb_row * mb_cols + mb_col]; - } - for (r = 0; r < mb_height; ++r) { - for (c = 0; c < mb_width; ++c) { - int row = mb_row + r; - int col = mb_col + c; - if (row >= mb_rows || col >= mb_cols) - continue; - if (cpi->active_map[row * mb_cols + col]) - return 1; - } - } - return 0; -} - -static void set_offsets(VP9_COMP *cpi, const TileInfo *const tile, - int mi_row, int mi_col, BLOCK_SIZE bsize) { - MACROBLOCK *const x = &cpi->mb; - VP9_COMMON *const cm = &cpi->common; - MACROBLOCKD *const xd = &x->e_mbd; - MB_MODE_INFO *mbmi; - const int idx_str = xd->mode_info_stride * mi_row + mi_col; - const int mi_width = num_8x8_blocks_wide_lookup[bsize]; - const int mi_height = num_8x8_blocks_high_lookup[bsize]; - const int mb_row = mi_row >> 1; - const int mb_col = mi_col >> 1; - const int idx_map = mb_row * cm->mb_cols + mb_col; - const struct segmentation *const seg = &cm->seg; - - set_skip_context(xd, cpi->above_context, cpi->left_context, mi_row, mi_col); - - // Activity map pointer - x->mb_activity_ptr = &cpi->mb_activity_map[idx_map]; - - if (cpi->active_map_enabled && !x->e_mbd.lossless) { - x->in_active_map = is_block_in_mb_map(cpi, mi_row, mi_col, bsize); - } else { - x->in_active_map = 1; - } - - xd->mi_8x8 = cm->mi_grid_visible + idx_str; - xd->prev_mi_8x8 = cm->prev_mi_grid_visible + idx_str; - - xd->last_mi = cm->prev_mi ? xd->prev_mi_8x8[0] : NULL; - - xd->mi_8x8[0] = cm->mi + idx_str; - - mbmi = &xd->mi_8x8[0]->mbmi; - - // Set up destination pointers - vp9_setup_dst_planes(xd, get_frame_new_buffer(cm), mi_row, mi_col); - - // Set up limit values for MV components - // mv beyond the range do not produce new/different prediction block - x->mv_row_min = -(((mi_row + mi_height) * MI_SIZE) + VP9_INTERP_EXTEND); - x->mv_col_min = -(((mi_col + mi_width) * MI_SIZE) + VP9_INTERP_EXTEND); - x->mv_row_max = (cm->mi_rows - mi_row) * MI_SIZE + VP9_INTERP_EXTEND; - x->mv_col_max = (cm->mi_cols - mi_col) * MI_SIZE + VP9_INTERP_EXTEND; - - // Set up distance of MB to edge of frame in 1/8th pel units - assert(!(mi_col & (mi_width - 1)) && !(mi_row & (mi_height - 1))); - set_mi_row_col(xd, tile, mi_row, mi_height, mi_col, mi_width, - cm->mi_rows, cm->mi_cols); - - /* set up source buffers */ - vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col); - - /* R/D setup */ - x->rddiv = cpi->RDDIV; - x->rdmult = cpi->RDMULT; - - /* segment ID */ - if (seg->enabled) { - if (cpi->oxcf.aq_mode != VARIANCE_AQ) { - const uint8_t *const map = seg->update_map ? cpi->segmentation_map - : cm->last_frame_seg_map; - mbmi->segment_id = vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); - } - vp9_init_plane_quantizers(cpi, x); - - if (seg->enabled && cpi->seg0_cnt > 0 && - !vp9_segfeature_active(seg, 0, SEG_LVL_REF_FRAME) && - vp9_segfeature_active(seg, 1, SEG_LVL_REF_FRAME)) { - cpi->seg0_progress = (cpi->seg0_idx << 16) / cpi->seg0_cnt; - } else { - const int y = mb_row & ~3; - const int x = mb_col & ~3; - const int p16 = ((mb_row & 1) << 1) + (mb_col & 1); - const int p32 = ((mb_row & 2) << 2) + ((mb_col & 2) << 1); - const int tile_progress = tile->mi_col_start * cm->mb_rows >> 1; - const int mb_cols = (tile->mi_col_end - tile->mi_col_start) >> 1; - - cpi->seg0_progress = ((y * mb_cols + x * 4 + p32 + p16 + tile_progress) - << 16) / cm->MBs; - } - - x->encode_breakout = cpi->segment_encode_breakout[mbmi->segment_id]; - } else { - mbmi->segment_id = 0; - x->encode_breakout = cpi->encode_breakout; - } -} - static void rd_pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, int mi_row, int mi_col, int *totalrate, int64_t *totaldist, @@ -1035,9 +1361,9 @@ static BLOCK_SIZE find_partition_size(BLOCK_SIZE bsize, // However, at the bottom and right borders of the image the requested size // may not be allowed in which case this code attempts to choose the largest // allowable partition. -static void set_partitioning(VP9_COMP *cpi, const TileInfo *const tile, - MODE_INFO **mi_8x8, int mi_row, int mi_col, - BLOCK_SIZE bsize) { +static void set_fixed_partitioning(VP9_COMP *cpi, const TileInfo *const tile, + MODE_INFO **mi_8x8, int mi_row, int mi_col, + BLOCK_SIZE bsize) { VP9_COMMON *const cm = &cpi->common; const int mis = cm->mode_info_stride; int row8x8_remaining = tile->mi_row_end - mi_row; @@ -2044,19 +2370,19 @@ static void encode_rd_sb_row(VP9_COMP *cpi, const TileInfo *const tile, cpi->mb.source_variance = UINT_MAX; if (cpi->sf.partition_search_type == FIXED_PARTITION) { set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); - set_partitioning(cpi, tile, mi_8x8, mi_row, mi_col, - cpi->sf.always_this_block_size); + set_fixed_partitioning(cpi, tile, mi_8x8, mi_row, mi_col, + cpi->sf.always_this_block_size); rd_use_partition(cpi, tile, mi_8x8, tp, mi_row, mi_col, BLOCK_64X64, &dummy_rate, &dummy_dist, 1); - } else if (cpi->sf.partition_search_type == VAR_BASED_FIXED_PARTITION || - cpi->sf.partition_search_type == VAR_BASED_PARTITION) { - // TODO(debargha): Implement VAR_BASED_PARTITION as a separate case. - // Currently both VAR_BASED_FIXED_PARTITION/VAR_BASED_PARTITION - // map to the same thing. + } else if (cpi->sf.partition_search_type == VAR_BASED_FIXED_PARTITION) { BLOCK_SIZE bsize; set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); bsize = get_rd_var_based_fixed_partition(cpi, mi_row, mi_col); - set_partitioning(cpi, tile, mi_8x8, mi_row, mi_col, bsize); + set_fixed_partitioning(cpi, tile, mi_8x8, mi_row, mi_col, bsize); + rd_use_partition(cpi, tile, mi_8x8, tp, mi_row, mi_col, BLOCK_64X64, + &dummy_rate, &dummy_dist, 1); + } else if (cpi->sf.partition_search_type == VAR_BASED_PARTITION) { + choose_partitioning(cpi, tile, mi_row, mi_col); rd_use_partition(cpi, tile, mi_8x8, tp, mi_row, mi_col, BLOCK_64X64, &dummy_rate, &dummy_dist, 1); } else { @@ -2333,14 +2659,40 @@ static void set_mode_info(MB_MODE_INFO *mbmi, BLOCK_SIZE bsize, mbmi->segment_id = 0; } -static void nonrd_use_partition(VP9_COMP *cpi, const TileInfo *const tile, - TOKENEXTRA **tp, int mi_row, int mi_col, - BLOCK_SIZE bsize, int *rate, int64_t *dist) { +static INLINE int get_block_row(int b32i, int b16i, int b8i) { + return ((b32i >> 1) << 2) + ((b16i >> 1) << 1) + (b8i >> 1); +} + +static INLINE int get_block_col(int b32i, int b16i, int b8i) { + return ((b32i & 1) << 2) + ((b16i & 1) << 1) + (b8i & 1); +} + +static void nonrd_pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, + int mi_row, int mi_col, + int *rate, int64_t *dist, + BLOCK_SIZE bsize) { VP9_COMMON *const cm = &cpi->common; MACROBLOCK *const x = &cpi->mb; - MACROBLOCKD *const xd = &cpi->mb.e_mbd; + MACROBLOCKD *const xd = &x->e_mbd; + set_offsets(cpi, tile, mi_row, mi_col, bsize); + xd->mi_8x8[0]->mbmi.sb_type = bsize; + if (!frame_is_intra_only(cm)) { + vp9_pick_inter_mode(cpi, x, tile, mi_row, mi_col, + rate, dist, bsize); + } else { + MB_PREDICTION_MODE intramode = DC_PRED; + set_mode_info(&xd->mi_8x8[0]->mbmi, bsize, intramode); + } + duplicate_modeinfo_in_sb(cm, xd, mi_row, mi_col, bsize); +} + +static void nonrd_use_fixed_partition(VP9_COMP *cpi, + const TileInfo *const tile, + TOKENEXTRA **tp, + int mi_row, int mi_col, + BLOCK_SIZE bsize, + int *rate, int64_t *dist) { int br, bc; - MB_PREDICTION_MODE mode = DC_PRED; int rows = MIN(MI_BLOCK_SIZE, tile->mi_row_end - mi_row); int cols = MIN(MI_BLOCK_SIZE, tile->mi_col_end - mi_col); @@ -2355,29 +2707,148 @@ static void nonrd_use_partition(VP9_COMP *cpi, const TileInfo *const tile, // find prediction mode for each 8x8 block for (br = 0; br < rows; br += bh) { for (bc = 0; bc < cols; bc += bw) { - const int row = mi_row + br; - const int col = mi_col + bc; - const BLOCK_SIZE bs = find_partition_size(bsize, rows - br, cols - bc, - &bh, &bw); - int i, j; + int row = mi_row + br; + int col = mi_col + bc; - set_offsets(cpi, tile, row, col, bs); - - if (cm->frame_type != KEY_FRAME) - vp9_pick_inter_mode(cpi, x, tile, row, col, &brate, &bdist, bs); - else - set_mode_info(&xd->mi_8x8[0]->mbmi, bs, mode); + BLOCK_SIZE bs = find_partition_size(bsize, rows - br, cols - bc, + &bh, &bw); + nonrd_pick_sb_modes(cpi, tile, row, col, &brate, &bdist, bs); *rate += brate; *dist += bdist; + } + } + encode_sb_rt(cpi, tile, tp, mi_row, mi_col, 1, BLOCK_64X64); +} - for (j = 0; j < bh; ++j) - for (i = 0; i < bw; ++i) - xd->mi_8x8[j * cm->mode_info_stride + i] = xd->mi_8x8[0]; +static void nonrd_pick_fixed_partition(VP9_COMP *cpi, + const TileInfo *const tile, + int mi_row, int mi_col, + BLOCK_SIZE bsize) { + MACROBLOCKD *const xd = &cpi->mb.e_mbd; + int br, bc; + int rows = MIN(MI_BLOCK_SIZE, tile->mi_row_end - mi_row); + int cols = MIN(MI_BLOCK_SIZE, tile->mi_col_end - mi_col); + + int bw = num_8x8_blocks_wide_lookup[bsize]; + int bh = num_8x8_blocks_high_lookup[bsize]; + + // Find prediction mode for each 8x8 block. + for (br = 0; br < rows; br += bh) { + for (bc = 0; bc < cols; bc += bw) { + int row = mi_row + br; + int col = mi_col + bc; + + BLOCK_SIZE bs = find_partition_size(bsize, rows - br, cols - bc, + &bh, &bw); + set_offsets(cpi, tile, row, col, bs); + xd->mi_8x8[0]->mbmi.sb_type = bs; + duplicate_modeinfo_in_sb(&cpi->common, xd, row, col, bs); } } } +static void nonrd_use_partition(VP9_COMP *cpi, + const TileInfo *const tile, + MODE_INFO **mi_8x8, + TOKENEXTRA **tp, + int mi_row, int mi_col, + BLOCK_SIZE bsize, + int *totrate, int64_t *totdist) { + VP9_COMMON *const cm = &cpi->common; + MACROBLOCK *const x = &cpi->mb; + const int bsl = b_width_log2(bsize), hbs = (1 << bsl) / 4; + const int mis = cm->mode_info_stride; + PARTITION_TYPE partition; + BLOCK_SIZE subsize; + int rate; + int64_t dist; + + if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) + return; + + if (bsize >= BLOCK_8X8) { + subsize = mi_8x8[0]->mbmi.sb_type; + } else { + subsize = BLOCK_4X4; + } + + partition = partition_lookup[bsl][subsize]; + + switch (partition) { + case PARTITION_NONE: + nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, subsize); + break; + case PARTITION_VERT: + *get_sb_index(x, subsize) = 0; + nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, subsize); + if (mi_col + hbs < cm->mi_cols) { + *get_sb_index(x, subsize) = 1; + nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col + hbs, + &rate, &dist, subsize); + if (rate != INT_MAX && dist != INT64_MAX && + *totrate != INT_MAX && *totdist != INT64_MAX) { + *totrate += rate; + *totdist += dist; + } + } + break; + case PARTITION_HORZ: + *get_sb_index(x, subsize) = 0; + nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, subsize); + if (mi_row + hbs < cm->mi_rows) { + *get_sb_index(x, subsize) = 1; + nonrd_pick_sb_modes(cpi, tile, mi_row + hbs, mi_col, + &rate, &dist, subsize); + if (rate != INT_MAX && dist != INT64_MAX && + *totrate != INT_MAX && *totdist != INT64_MAX) { + *totrate += rate; + *totdist += dist; + } + } + break; + case PARTITION_SPLIT: + subsize = get_subsize(bsize, PARTITION_SPLIT); + + *get_sb_index(x, subsize) = 0; + nonrd_use_partition(cpi, tile, mi_8x8, tp, mi_row, mi_col, + subsize, totrate, totdist); + *get_sb_index(x, subsize) = 1; + nonrd_use_partition(cpi, tile, mi_8x8 + hbs, tp, + mi_row, mi_col + hbs, subsize, + &rate, &dist); + if (rate != INT_MAX && dist != INT64_MAX && + *totrate != INT_MAX && *totdist != INT64_MAX) { + *totrate += rate; + *totdist += dist; + } + *get_sb_index(x, subsize) = 2; + nonrd_use_partition(cpi, tile, mi_8x8 + hbs * mis, tp, + mi_row + hbs, mi_col, subsize, + &rate, &dist); + if (rate != INT_MAX && dist != INT64_MAX && + *totrate != INT_MAX && *totdist != INT64_MAX) { + *totrate += rate; + *totdist += dist; + } + *get_sb_index(x, subsize) = 3; + nonrd_use_partition(cpi, tile, mi_8x8 + hbs * mis + hbs, tp, + mi_row + hbs, mi_col + hbs, subsize, + &rate, &dist); + if (rate != INT_MAX && dist != INT64_MAX && + *totrate != INT_MAX && *totdist != INT64_MAX) { + *totrate += rate; + *totdist += dist; + } + break; + default: + assert("Invalid partition type."); + } + + if (bsize == BLOCK_64X64) + encode_sb_rt(cpi, tile, tp, mi_row, mi_col, 1, bsize); +} + static void encode_nonrd_sb_row(VP9_COMP *cpi, const TileInfo *const tile, int mi_row, TOKENEXTRA **tp) { int mi_col; @@ -2395,21 +2866,23 @@ static void encode_nonrd_sb_row(VP9_COMP *cpi, const TileInfo *const tile, cpi->mb.source_variance = UINT_MAX; if (cpi->sf.partition_search_type == FIXED_PARTITION) { - nonrd_use_partition(cpi, tile, tp, mi_row, mi_col, - cpi->sf.always_this_block_size, - &dummy_rate, &dummy_dist); - encode_sb_rt(cpi, tile, tp, mi_row, mi_col, 1, BLOCK_64X64); - } else if (cpi->sf.partition_search_type == VAR_BASED_FIXED_PARTITION || - cpi->sf.partition_search_type == VAR_BASED_PARTITION) { - // TODO(debargha): Implement VAR_BASED_PARTITION as a separate case. - // Currently both VAR_BASED_FIXED_PARTITION/VAR_BASED_PARTITION - // map to the same thing. + nonrd_use_fixed_partition(cpi, tile, tp, mi_row, mi_col, + cpi->sf.always_this_block_size, + &dummy_rate, &dummy_dist); + } else if (cpi->sf.partition_search_type == VAR_BASED_FIXED_PARTITION) { BLOCK_SIZE bsize = get_nonrd_var_based_fixed_partition(cpi, mi_row, mi_col); - nonrd_use_partition(cpi, tile, tp, mi_row, mi_col, - bsize, &dummy_rate, &dummy_dist); - encode_sb_rt(cpi, tile, tp, mi_row, mi_col, 1, BLOCK_64X64); + nonrd_use_fixed_partition(cpi, tile, tp, mi_row, mi_col, + bsize, &dummy_rate, &dummy_dist); + } else if (cpi->sf.partition_search_type == VAR_BASED_PARTITION) { + const int idx_str = cpi->common.mode_info_stride * mi_row + mi_col; + MODE_INFO **mi_8x8 = cpi->common.mi_grid_visible + idx_str; + int dummy_rate; + int64_t dummy_dist; + choose_partitioning(cpi, tile, mi_row, mi_col); + nonrd_use_partition(cpi, tile, mi_8x8, tp, mi_row, mi_col, BLOCK_64X64, + &dummy_rate, &dummy_dist); } else { assert(0); } @@ -2434,8 +2907,6 @@ static void encode_frame_internal(VP9_COMP *cpi) { // required for vp9_frame_init_quantizer xd->mi_8x8[0] = cm->mi; - xd->last_mi = cm->prev_mi; - vp9_zero(cm->counts.mv); vp9_zero(cpi->coef_counts); vp9_zero(cm->counts.eob_branch); diff --git a/vp9/encoder/vp9_encodeframe.h b/vp9/encoder/vp9_encodeframe.h index f7d17c301..72343cdf2 100644 --- a/vp9/encoder/vp9_encodeframe.h +++ b/vp9/encoder/vp9_encodeframe.h @@ -18,11 +18,14 @@ extern "C" { struct macroblock; struct yv12_buffer_config; +struct VP9_COMP; void vp9_setup_src_planes(struct macroblock *x, const struct yv12_buffer_config *src, int mi_row, int mi_col); +void vp9_encode_frame(struct VP9_COMP *cpi); + #ifdef __cplusplus } // extern "C" #endif diff --git a/vp9/encoder/vp9_mcomp.c b/vp9/encoder/vp9_mcomp.c index 26f1a0289..1b28dee22 100644 --- a/vp9/encoder/vp9_mcomp.c +++ b/vp9/encoder/vp9_mcomp.c @@ -866,7 +866,7 @@ int vp9_square_search(const MACROBLOCK *x, do_init_search, 0, vfp, use_mvcost, center_mv, best_mv, square_num_candidates, square_candidates); -}; +} int vp9_fast_hex_search(const MACROBLOCK *x, MV *ref_mv, diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c index 3775a4259..10b44492c 100644 --- a/vp9/encoder/vp9_onyx_if.c +++ b/vp9/encoder/vp9_onyx_if.c @@ -28,6 +28,7 @@ #include "vp9/common/vp9_tile_common.h" #include "vp9/encoder/vp9_bitstream.h" +#include "vp9/encoder/vp9_encodeframe.h" #include "vp9/encoder/vp9_encodemv.h" #include "vp9/encoder/vp9_firstpass.h" #include "vp9/encoder/vp9_mbgraph.h" @@ -874,7 +875,7 @@ static void set_rt_speed_feature(VP9_COMMON *cm, if (speed >= 8) { int i; for (i = 0; i < BLOCK_SIZES; ++i) - sf->disable_inter_mode_mask[i] = 14; // only search NEARESTMV (0) + sf->disable_inter_mode_mask[i] = 14; // only search NEARESTMV (0) } } diff --git a/vp9/encoder/vp9_onyx_int.h b/vp9/encoder/vp9_onyx_int.h index 9b2e49976..0d41f6c9b 100644 --- a/vp9/encoder/vp9_onyx_int.h +++ b/vp9/encoder/vp9_onyx_int.h @@ -930,8 +930,6 @@ static YV12_BUFFER_CONFIG *get_ref_frame_buffer(VP9_COMP *cpi, ref_frame)]].buf; } -void vp9_encode_frame(VP9_COMP *cpi); - void vp9_set_speed_features(VP9_COMP *cpi); int vp9_calc_ss_err(const YV12_BUFFER_CONFIG *source, diff --git a/vp9/encoder/vp9_pickmode.c b/vp9/encoder/vp9_pickmode.c index 146e23d5a..cd4632696 100644 --- a/vp9/encoder/vp9_pickmode.c +++ b/vp9/encoder/vp9_pickmode.c @@ -207,14 +207,14 @@ static void model_rd_for_sb_y(VP9_COMP *cpi, BLOCK_SIZE bsize, struct macroblockd_plane *const pd = &xd->plane[0]; const BLOCK_SIZE bs = get_plane_block_size(bsize, pd); - (void) cpi->fn_ptr[bs].vf(p->src.buf, p->src.stride, - pd->dst.buf, pd->dst.stride, &sse); + int var = cpi->fn_ptr[bs].vf(p->src.buf, p->src.stride, + pd->dst.buf, pd->dst.stride, &sse); - vp9_model_rd_from_var_lapndz(sse, 1 << num_pels_log2_lookup[bs], + vp9_model_rd_from_var_lapndz(var + sse, 1 << num_pels_log2_lookup[bs], pd->dequant[1] >> 3, &rate, &dist); *out_rate_sum = rate; - *out_dist_sum = dist << 4; + *out_dist_sum = dist << 3; } // TODO(jingning) placeholder for inter-frame non-RD mode decision. @@ -250,7 +250,6 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, x->skip = 0; if (!x->in_active_map) x->skip = 1; - // initialize mode decisions *returnrate = INT_MAX; *returndistortion = INT64_MAX; @@ -264,6 +263,7 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, EIGHTTAP : cpi->common.interp_filter; mbmi->skip = 0; mbmi->segment_id = 0; + xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter); for (ref_frame = LAST_FRAME; ref_frame <= LAST_FRAME ; ++ref_frame) { x->pred_mv_sad[ref_frame] = INT_MAX; diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index 5fc867287..d0037759b 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -2332,8 +2332,7 @@ void vp9_setup_buffer_inter(VP9_COMP *cpi, MACROBLOCK *x, setup_pred_block(xd, yv12_mb[ref_frame], yv12, mi_row, mi_col, sf, sf); // Gets an initial list of candidate vectors from neighbours and orders them - vp9_find_mv_refs(cm, xd, tile, mi, xd->last_mi, ref_frame, candidates, - mi_row, mi_col); + vp9_find_mv_refs(cm, xd, tile, mi, ref_frame, candidates, mi_row, mi_col); // Candidate refinement carried out at encoder and decoder vp9_find_best_ref_mvs(xd, cm->allow_high_precision_mv, candidates, diff --git a/vp9/vp9_cx_iface.c b/vp9/vp9_cx_iface.c index a20209f9c..75c6c6e14 100644 --- a/vp9/vp9_cx_iface.c +++ b/vp9/vp9_cx_iface.c @@ -72,7 +72,7 @@ static const struct extraconfig_map extracfg_map[] = { struct vpx_codec_alg_priv { vpx_codec_priv_t base; vpx_codec_enc_cfg_t cfg; - struct vp9_extracfg vp8_cfg; + struct vp9_extracfg extra_cfg; VP9_CONFIG oxcf; VP9_COMP *cpi; unsigned char *cx_data; @@ -142,7 +142,7 @@ update_error_state(vpx_codec_alg_priv_t *ctx, static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, const vpx_codec_enc_cfg_t *cfg, - const struct vp9_extracfg *vp8_cfg) { + const struct vp9_extracfg *extra_cfg) { RANGE_CHECK(cfg, g_w, 1, 65535); /* 16 bits available */ RANGE_CHECK(cfg, g_h, 1, 65535); /* 16 bits available */ RANGE_CHECK(cfg, g_timebase.den, 1, 1000000000); @@ -151,12 +151,12 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, RANGE_CHECK_HI(cfg, rc_max_quantizer, 63); RANGE_CHECK_HI(cfg, rc_min_quantizer, cfg->rc_max_quantizer); - RANGE_CHECK_BOOL(vp8_cfg, lossless); - if (vp8_cfg->lossless) { + RANGE_CHECK_BOOL(extra_cfg, lossless); + if (extra_cfg->lossless) { RANGE_CHECK_HI(cfg, rc_max_quantizer, 0); RANGE_CHECK_HI(cfg, rc_min_quantizer, 0); } - RANGE_CHECK(vp8_cfg, aq_mode, 0, AQ_MODE_COUNT - 1); + RANGE_CHECK(extra_cfg, aq_mode, 0, AQ_MODE_COUNT - 1); RANGE_CHECK_HI(cfg, g_threads, 64); RANGE_CHECK_HI(cfg, g_lag_in_frames, MAX_LAG_BUFFERS); @@ -199,21 +199,19 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, ERROR("kf_min_dist not supported in auto mode, use 0 " "or kf_max_dist instead."); - RANGE_CHECK_BOOL(vp8_cfg, enable_auto_alt_ref); - RANGE_CHECK(vp8_cfg, cpu_used, -16, 16); - - RANGE_CHECK_HI(vp8_cfg, noise_sensitivity, 6); - - RANGE_CHECK(vp8_cfg, tile_columns, 0, 6); - RANGE_CHECK(vp8_cfg, tile_rows, 0, 2); - RANGE_CHECK_HI(vp8_cfg, sharpness, 7); - RANGE_CHECK(vp8_cfg, arnr_max_frames, 0, 15); - RANGE_CHECK_HI(vp8_cfg, arnr_strength, 6); - RANGE_CHECK(vp8_cfg, arnr_type, 1, 3); - RANGE_CHECK(vp8_cfg, cq_level, 0, 63); + RANGE_CHECK_BOOL(extra_cfg, enable_auto_alt_ref); + RANGE_CHECK(extra_cfg, cpu_used, -16, 16); + RANGE_CHECK_HI(extra_cfg, noise_sensitivity, 6); + RANGE_CHECK(extra_cfg, tile_columns, 0, 6); + RANGE_CHECK(extra_cfg, tile_rows, 0, 2); + RANGE_CHECK_HI(extra_cfg, sharpness, 7); + RANGE_CHECK(extra_cfg, arnr_max_frames, 0, 15); + RANGE_CHECK_HI(extra_cfg, arnr_strength, 6); + RANGE_CHECK(extra_cfg, arnr_type, 1, 3); + RANGE_CHECK(extra_cfg, cq_level, 0, 63); // TODO(yaowu): remove this when ssim tuning is implemented for vp9 - if (vp8_cfg->tuning == VP8_TUNE_SSIM) + if (extra_cfg->tuning == VP8_TUNE_SSIM) ERROR("Option --tune=ssim is not currently supported in VP9."); if (cfg->g_pass == VPX_RC_LAST_PASS) { @@ -262,20 +260,17 @@ static vpx_codec_err_t validate_img(vpx_codec_alg_priv_t *ctx, static vpx_codec_err_t set_vp9e_config(VP9_CONFIG *oxcf, - vpx_codec_enc_cfg_t cfg, - struct vp9_extracfg vp9_cfg) { - oxcf->version = cfg.g_profile; - oxcf->width = cfg.g_w; - oxcf->height = cfg.g_h; - /* guess a frame rate if out of whack, use 30 */ - oxcf->framerate = (double)(cfg.g_timebase.den) - / (double)(cfg.g_timebase.num); - - if (oxcf->framerate > 180) { + const vpx_codec_enc_cfg_t *cfg, + const struct vp9_extracfg *extra_cfg) { + oxcf->version = cfg->g_profile; + oxcf->width = cfg->g_w; + oxcf->height = cfg->g_h; + // guess a frame rate if out of whack, use 30 + oxcf->framerate = (double)cfg->g_timebase.den / cfg->g_timebase.num; + if (oxcf->framerate > 180) oxcf->framerate = 30; - } - switch (cfg.g_pass) { + switch (cfg->g_pass) { case VPX_RC_ONE_PASS: oxcf->mode = MODE_GOODQUALITY; break; @@ -287,87 +282,81 @@ static vpx_codec_err_t set_vp9e_config(VP9_CONFIG *oxcf, break; } - if (cfg.g_pass == VPX_RC_FIRST_PASS) { - oxcf->lag_in_frames = 0; - } else { - oxcf->lag_in_frames = cfg.g_lag_in_frames; - } + oxcf->lag_in_frames = cfg->g_pass == VPX_RC_FIRST_PASS ? 0 + : cfg->g_lag_in_frames; - oxcf->end_usage = USAGE_LOCAL_FILE_PLAYBACK; - if (cfg.rc_end_usage == VPX_CQ) + oxcf->end_usage = USAGE_LOCAL_FILE_PLAYBACK; + if (cfg->rc_end_usage == VPX_CQ) oxcf->end_usage = USAGE_CONSTRAINED_QUALITY; - else if (cfg.rc_end_usage == VPX_Q) + else if (cfg->rc_end_usage == VPX_Q) oxcf->end_usage = USAGE_CONSTANT_QUALITY; - else if (cfg.rc_end_usage == VPX_CBR) + else if (cfg->rc_end_usage == VPX_CBR) oxcf->end_usage = USAGE_STREAM_FROM_SERVER; - oxcf->target_bandwidth = cfg.rc_target_bitrate; - oxcf->rc_max_intra_bitrate_pct = vp9_cfg.rc_max_intra_bitrate_pct; + oxcf->target_bandwidth = cfg->rc_target_bitrate; + oxcf->rc_max_intra_bitrate_pct = extra_cfg->rc_max_intra_bitrate_pct; - oxcf->best_allowed_q = cfg.rc_min_quantizer; - oxcf->worst_allowed_q = cfg.rc_max_quantizer; - oxcf->cq_level = vp9_cfg.cq_level; + oxcf->best_allowed_q = cfg->rc_min_quantizer; + oxcf->worst_allowed_q = cfg->rc_max_quantizer; + oxcf->cq_level = extra_cfg->cq_level; oxcf->fixed_q = -1; - oxcf->under_shoot_pct = cfg.rc_undershoot_pct; - oxcf->over_shoot_pct = cfg.rc_overshoot_pct; + oxcf->under_shoot_pct = cfg->rc_undershoot_pct; + oxcf->over_shoot_pct = cfg->rc_overshoot_pct; - oxcf->maximum_buffer_size = cfg.rc_buf_sz; - oxcf->starting_buffer_level = cfg.rc_buf_initial_sz; - oxcf->optimal_buffer_level = cfg.rc_buf_optimal_sz; + oxcf->maximum_buffer_size = cfg->rc_buf_sz; + oxcf->starting_buffer_level = cfg->rc_buf_initial_sz; + oxcf->optimal_buffer_level = cfg->rc_buf_optimal_sz; - oxcf->drop_frames_water_mark = cfg.rc_dropframe_thresh; + oxcf->drop_frames_water_mark = cfg->rc_dropframe_thresh; - oxcf->two_pass_vbrbias = cfg.rc_2pass_vbr_bias_pct; - oxcf->two_pass_vbrmin_section = cfg.rc_2pass_vbr_minsection_pct; - oxcf->two_pass_vbrmax_section = cfg.rc_2pass_vbr_maxsection_pct; + oxcf->two_pass_vbrbias = cfg->rc_2pass_vbr_bias_pct; + oxcf->two_pass_vbrmin_section = cfg->rc_2pass_vbr_minsection_pct; + oxcf->two_pass_vbrmax_section = cfg->rc_2pass_vbr_maxsection_pct; - oxcf->auto_key = cfg.kf_mode == VPX_KF_AUTO - && cfg.kf_min_dist != cfg.kf_max_dist; - // oxcf->kf_min_dist = cfg.kf_min_dis; - oxcf->key_freq = cfg.kf_max_dist; + oxcf->auto_key = cfg->kf_mode == VPX_KF_AUTO && + cfg->kf_min_dist != cfg->kf_max_dist; - oxcf->cpu_used = vp9_cfg.cpu_used; - oxcf->encode_breakout = vp9_cfg.static_thresh; - oxcf->play_alternate = vp9_cfg.enable_auto_alt_ref; - oxcf->noise_sensitivity = vp9_cfg.noise_sensitivity; - oxcf->sharpness = vp9_cfg.sharpness; + oxcf->key_freq = cfg->kf_max_dist; - oxcf->two_pass_stats_in = cfg.rc_twopass_stats_in; - oxcf->output_pkt_list = vp9_cfg.pkt_list; + oxcf->cpu_used = extra_cfg->cpu_used; + oxcf->encode_breakout = extra_cfg->static_thresh; + oxcf->play_alternate = extra_cfg->enable_auto_alt_ref; + oxcf->noise_sensitivity = extra_cfg->noise_sensitivity; + oxcf->sharpness = extra_cfg->sharpness; - oxcf->arnr_max_frames = vp9_cfg.arnr_max_frames; - oxcf->arnr_strength = vp9_cfg.arnr_strength; - oxcf->arnr_type = vp9_cfg.arnr_type; + oxcf->two_pass_stats_in = cfg->rc_twopass_stats_in; + oxcf->output_pkt_list = extra_cfg->pkt_list; - oxcf->tuning = vp9_cfg.tuning; + oxcf->arnr_max_frames = extra_cfg->arnr_max_frames; + oxcf->arnr_strength = extra_cfg->arnr_strength; + oxcf->arnr_type = extra_cfg->arnr_type; - oxcf->tile_columns = vp9_cfg.tile_columns; - oxcf->tile_rows = vp9_cfg.tile_rows; + oxcf->tuning = extra_cfg->tuning; - oxcf->lossless = vp9_cfg.lossless; + oxcf->tile_columns = extra_cfg->tile_columns; + oxcf->tile_rows = extra_cfg->tile_rows; - oxcf->error_resilient_mode = cfg.g_error_resilient; - oxcf->frame_parallel_decoding_mode = vp9_cfg.frame_parallel_decoding_mode; + oxcf->lossless = extra_cfg->lossless; - oxcf->aq_mode = vp9_cfg.aq_mode; + oxcf->error_resilient_mode = cfg->g_error_resilient; + oxcf->frame_parallel_decoding_mode = extra_cfg->frame_parallel_decoding_mode; - oxcf->ss_number_layers = cfg.ss_number_layers; + oxcf->aq_mode = extra_cfg->aq_mode; + + oxcf->ss_number_layers = cfg->ss_number_layers; if (oxcf->ss_number_layers > 1) { - memcpy(oxcf->ss_target_bitrate, cfg.ss_target_bitrate, - sizeof(cfg.ss_target_bitrate)); + vp9_copy(oxcf->ss_target_bitrate, cfg->ss_target_bitrate); } else if (oxcf->ss_number_layers == 1) { oxcf->ss_target_bitrate[0] = (int)oxcf->target_bandwidth; } - oxcf->ts_number_layers = cfg.ts_number_layers; + oxcf->ts_number_layers = cfg->ts_number_layers; if (oxcf->ts_number_layers > 1) { - memcpy(oxcf->ts_target_bitrate, cfg.ts_target_bitrate, - sizeof(cfg.ts_target_bitrate)); - memcpy(oxcf->ts_rate_decimator, cfg.ts_rate_decimator, - sizeof(cfg.ts_rate_decimator)); + vp9_copy(oxcf->ts_target_bitrate, cfg->ts_target_bitrate); + vp9_copy(oxcf->ts_rate_decimator, cfg->ts_rate_decimator); } else if (oxcf->ts_number_layers == 1) { oxcf->ts_target_bitrate[0] = (int)oxcf->target_bandwidth; oxcf->ts_rate_decimator[0] = 1; @@ -420,11 +409,11 @@ static vpx_codec_err_t vp9e_set_config(vpx_codec_alg_priv_t *ctx, if ((cfg->g_lag_in_frames > ctx->cfg.g_lag_in_frames)) ERROR("Cannot increase lag_in_frames"); - res = validate_config(ctx, cfg, &ctx->vp8_cfg); + res = validate_config(ctx, cfg, &ctx->extra_cfg); if (res == VPX_CODEC_OK) { ctx->cfg = *cfg; - set_vp9e_config(&ctx->oxcf, ctx->cfg, ctx->vp8_cfg); + set_vp9e_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg); vp9_change_config(ctx->cpi, &ctx->oxcf); } @@ -458,35 +447,36 @@ static vpx_codec_err_t get_param(vpx_codec_alg_priv_t *ctx, static vpx_codec_err_t set_param(vpx_codec_alg_priv_t *ctx, int ctrl_id, va_list args) { - vpx_codec_err_t res = VPX_CODEC_OK; - struct vp9_extracfg xcfg = ctx->vp8_cfg; + vpx_codec_err_t res = VPX_CODEC_OK; + struct vp9_extracfg extra_cfg = ctx->extra_cfg; #define MAP(id, var) case id: var = CAST(id, args); break; switch (ctrl_id) { - MAP(VP8E_SET_CPUUSED, xcfg.cpu_used); - MAP(VP8E_SET_ENABLEAUTOALTREF, xcfg.enable_auto_alt_ref); - MAP(VP8E_SET_NOISE_SENSITIVITY, xcfg.noise_sensitivity); - MAP(VP8E_SET_SHARPNESS, xcfg.sharpness); - MAP(VP8E_SET_STATIC_THRESHOLD, xcfg.static_thresh); - MAP(VP9E_SET_TILE_COLUMNS, xcfg.tile_columns); - MAP(VP9E_SET_TILE_ROWS, xcfg.tile_rows); - MAP(VP8E_SET_ARNR_MAXFRAMES, xcfg.arnr_max_frames); - MAP(VP8E_SET_ARNR_STRENGTH, xcfg.arnr_strength); - MAP(VP8E_SET_ARNR_TYPE, xcfg.arnr_type); - MAP(VP8E_SET_TUNING, xcfg.tuning); - MAP(VP8E_SET_CQ_LEVEL, xcfg.cq_level); - MAP(VP8E_SET_MAX_INTRA_BITRATE_PCT, xcfg.rc_max_intra_bitrate_pct); - MAP(VP9E_SET_LOSSLESS, xcfg.lossless); - MAP(VP9E_SET_FRAME_PARALLEL_DECODING, xcfg.frame_parallel_decoding_mode); - MAP(VP9E_SET_AQ_MODE, xcfg.aq_mode); + MAP(VP8E_SET_CPUUSED, extra_cfg.cpu_used); + MAP(VP8E_SET_ENABLEAUTOALTREF, extra_cfg.enable_auto_alt_ref); + MAP(VP8E_SET_NOISE_SENSITIVITY, extra_cfg.noise_sensitivity); + MAP(VP8E_SET_SHARPNESS, extra_cfg.sharpness); + MAP(VP8E_SET_STATIC_THRESHOLD, extra_cfg.static_thresh); + MAP(VP9E_SET_TILE_COLUMNS, extra_cfg.tile_columns); + MAP(VP9E_SET_TILE_ROWS, extra_cfg.tile_rows); + MAP(VP8E_SET_ARNR_MAXFRAMES, extra_cfg.arnr_max_frames); + MAP(VP8E_SET_ARNR_STRENGTH, extra_cfg.arnr_strength); + MAP(VP8E_SET_ARNR_TYPE, extra_cfg.arnr_type); + MAP(VP8E_SET_TUNING, extra_cfg.tuning); + MAP(VP8E_SET_CQ_LEVEL, extra_cfg.cq_level); + MAP(VP8E_SET_MAX_INTRA_BITRATE_PCT, extra_cfg.rc_max_intra_bitrate_pct); + MAP(VP9E_SET_LOSSLESS, extra_cfg.lossless); + MAP(VP9E_SET_FRAME_PARALLEL_DECODING, + extra_cfg.frame_parallel_decoding_mode); + MAP(VP9E_SET_AQ_MODE, extra_cfg.aq_mode); } - res = validate_config(ctx, &ctx->cfg, &xcfg); + res = validate_config(ctx, &ctx->cfg, &extra_cfg); if (res == VPX_CODEC_OK) { - ctx->vp8_cfg = xcfg; - set_vp9e_config(&ctx->oxcf, ctx->cfg, ctx->vp8_cfg); + ctx->extra_cfg = extra_cfg; + set_vp9e_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg); vp9_change_config(ctx->cpi, &ctx->oxcf); } @@ -531,8 +521,8 @@ static vpx_codec_err_t vp9e_common_init(vpx_codec_ctx_t *ctx) { extracfg_map[i].usage && extracfg_map[i].usage != cfg->g_usage; i++) {} - priv->vp8_cfg = extracfg_map[i].cfg; - priv->vp8_cfg.pkt_list = &priv->pkt_list.head; + priv->extra_cfg = extracfg_map[i].cfg; + priv->extra_cfg.pkt_list = &priv->pkt_list.head; // Maximum buffer size approximated based on having multiple ARF. priv->cx_data_sz = priv->cfg.g_w * priv->cfg.g_h * 3 / 2 * 8; @@ -545,13 +535,13 @@ static vpx_codec_err_t vp9e_common_init(vpx_codec_ctx_t *ctx) { vp9_initialize_enc(); - res = validate_config(priv, &priv->cfg, &priv->vp8_cfg); + res = validate_config(priv, &priv->cfg, &priv->extra_cfg); if (res == VPX_CODEC_OK) { VP9_COMP *cpi; set_vp9e_config(&ctx->priv->alg_priv->oxcf, - ctx->priv->alg_priv->cfg, - ctx->priv->alg_priv->vp8_cfg); + &ctx->priv->alg_priv->cfg, + &ctx->priv->alg_priv->extra_cfg); cpi = vp9_create_compressor(&ctx->priv->alg_priv->oxcf); if (cpi == NULL) res = VPX_CODEC_MEM_ERROR; @@ -954,7 +944,7 @@ static vpx_image_t *vp9e_get_preview(vpx_codec_alg_priv_t *ctx) { flags.noise_level = ctx->preview_ppcfg.noise_level; } - if (0 == vp9_get_preview_raw_frame(ctx->cpi, &sd, &flags)) { + if (vp9_get_preview_raw_frame(ctx->cpi, &sd, &flags) == 0) { yuvconfig2image(&ctx->preview_img, &sd, NULL); return &ctx->preview_img; } else { @@ -965,7 +955,7 @@ static vpx_image_t *vp9e_get_preview(vpx_codec_alg_priv_t *ctx) { static vpx_codec_err_t vp9e_update_entropy(vpx_codec_alg_priv_t *ctx, int ctr_id, va_list args) { - int update = va_arg(args, int); + const int update = va_arg(args, int); vp9_update_entropy(ctx->cpi, update); return VPX_CODEC_OK; } @@ -973,7 +963,7 @@ static vpx_codec_err_t vp9e_update_entropy(vpx_codec_alg_priv_t *ctx, static vpx_codec_err_t vp9e_update_reference(vpx_codec_alg_priv_t *ctx, int ctr_id, va_list args) { - int update = va_arg(args, int); + const int update = va_arg(args, int); vp9_update_reference(ctx->cpi, update); return VPX_CODEC_OK; } @@ -981,7 +971,7 @@ static vpx_codec_err_t vp9e_update_reference(vpx_codec_alg_priv_t *ctx, static vpx_codec_err_t vp9e_use_reference(vpx_codec_alg_priv_t *ctx, int ctr_id, va_list args) { - int reference_flag = va_arg(args, int); + const int reference_flag = va_arg(args, int); vp9_use_as_reference(ctx->cpi, reference_flag); return VPX_CODEC_OK; } @@ -997,10 +987,9 @@ static vpx_codec_err_t vp9e_set_roi_map(vpx_codec_alg_priv_t *ctx, static vpx_codec_err_t vp9e_set_activemap(vpx_codec_alg_priv_t *ctx, int ctr_id, va_list args) { - vpx_active_map_t *data = va_arg(args, vpx_active_map_t *); + vpx_active_map_t *const map = va_arg(args, vpx_active_map_t *); - if (data) { - vpx_active_map_t *map = (vpx_active_map_t *)data; + if (map) { if (!vp9_set_active_map(ctx->cpi, map->active_map, map->rows, map->cols)) return VPX_CODEC_OK; else @@ -1011,15 +1000,13 @@ static vpx_codec_err_t vp9e_set_activemap(vpx_codec_alg_priv_t *ctx, } static vpx_codec_err_t vp9e_set_scalemode(vpx_codec_alg_priv_t *ctx, - int ctr_id, - va_list args) { - vpx_scaling_mode_t *scalemode = va_arg(args, vpx_scaling_mode_t *); + int ctr_id, va_list args) { + vpx_scaling_mode_t *const mode = va_arg(args, vpx_scaling_mode_t *); - if (scalemode != NULL) { - int res; - res = vp9_set_internal_size(ctx->cpi, - (VPX_SCALING)scalemode->h_scaling_mode, - (VPX_SCALING)scalemode->v_scaling_mode); + if (mode) { + const int res = vp9_set_internal_size(ctx->cpi, + (VPX_SCALING)mode->h_scaling_mode, + (VPX_SCALING)mode->v_scaling_mode); return (res == 0) ? VPX_CODEC_OK : VPX_CODEC_INVALID_PARAM; } else { return VPX_CODEC_INVALID_PARAM; @@ -1061,10 +1048,11 @@ static vpx_codec_err_t vp9e_set_svc_layer_id(vpx_codec_alg_priv_t *ctx, static vpx_codec_err_t vp9e_set_svc_parameters(vpx_codec_alg_priv_t *ctx, int ctr_id, va_list args) { - VP9_COMP *cpi = (VP9_COMP *)ctx->cpi; - vpx_svc_parameters_t *params = va_arg(args, vpx_svc_parameters_t *); + VP9_COMP *const cpi = ctx->cpi; + vpx_svc_parameters_t *const params = va_arg(args, vpx_svc_parameters_t *); - if (params == NULL) return VPX_CODEC_INVALID_PARAM; + if (params == NULL) + return VPX_CODEC_INVALID_PARAM; cpi->svc.spatial_layer_id = params->spatial_layer; cpi->svc.temporal_layer_id = params->temporal_layer; @@ -1079,7 +1067,7 @@ static vpx_codec_err_t vp9e_set_svc_parameters(vpx_codec_alg_priv_t *ctx, ctx->cfg.rc_max_quantizer = params->max_quantizer; ctx->cfg.rc_min_quantizer = params->min_quantizer; - set_vp9e_config(&ctx->oxcf, ctx->cfg, ctx->vp8_cfg); + set_vp9e_config(&ctx->oxcf, &ctx->cfg, &ctx->extra_cfg); vp9_change_config(ctx->cpi, &ctx->oxcf); return VPX_CODEC_OK; |