summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtest/set_maps.sh59
-rw-r--r--test/svc_test.cc576
-rw-r--r--vp9/decoder/vp9_decoder.c64
-rw-r--r--vp9/decoder/vp9_decoder.h19
-rw-r--r--vp9/encoder/arm/neon/vp9_quantize_neon.c43
-rw-r--r--vp9/encoder/vp9_encoder.c36
-rw-r--r--vp9/encoder/vp9_encoder.h8
-rw-r--r--vp9/encoder/vp9_firstpass.c61
-rw-r--r--vp9/encoder/vp9_pickmode.c113
-rw-r--r--vp9/encoder/vp9_ratectrl.c1
-rw-r--r--vp9/encoder/vp9_rdopt.c34
-rw-r--r--vp9/encoder/vp9_speed_features.c26
-rw-r--r--vp9/encoder/vp9_speed_features.h6
-rw-r--r--vp9/encoder/vp9_svc_layercontext.c9
-rw-r--r--vp9/vp9_cx_iface.c7
-rw-r--r--vp9/vp9_dx_iface.c79
-rw-r--r--vpx/internal/vpx_codec_internal.h1
-rw-r--r--vpx/src/vpx_image.c34
-rw-r--r--vpxdec.c10
-rw-r--r--vpxenc.c5
20 files changed, 682 insertions, 509 deletions
diff --git a/test/set_maps.sh b/test/set_maps.sh
new file mode 100755
index 000000000..e7c8d43fa
--- /dev/null
+++ b/test/set_maps.sh
@@ -0,0 +1,59 @@
+#!/bin/sh
+##
+## 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.
+##
+## This file tests the libvpx set_maps example. To add new tests to this file,
+## do the following:
+## 1. Write a shell function (this is your test).
+## 2. Add the function to set_maps_tests (on a new line).
+##
+. $(dirname $0)/tools_common.sh
+
+# Environment check: $YUV_RAW_INPUT is required, and set_maps must exist in
+# $LIBVPX_BIN_PATH.
+set_maps_verify_environment() {
+ if [ ! -e "${YUV_RAW_INPUT}" ]; then
+ echo "Libvpx test data must exist in LIBVPX_TEST_DATA_PATH."
+ return 1
+ fi
+ if [ -z "$(vpx_tool_path set_maps)" ]; then
+ elog "set_maps not found. It must exist in LIBVPX_BIN_PATH or its parent."
+ return 1
+ fi
+}
+
+# Runs set_maps using the codec specified by $1.
+set_maps() {
+ local encoder="$(vpx_tool_path set_maps)"
+ local codec="$1"
+ local output_file="${VPX_TEST_OUTPUT_DIR}/set_maps_${codec}.ivf"
+
+ eval "${VPX_TEST_PREFIX}" "${encoder}" "${codec}" "${YUV_RAW_INPUT_WIDTH}" \
+ "${YUV_RAW_INPUT_HEIGHT}" "${YUV_RAW_INPUT}" "${output_file}" \
+ ${devnull}
+
+ [ -e "${output_file}" ] || return 1
+}
+
+set_maps_vp8() {
+ if [ "$(vp8_encode_available)" = "yes" ]; then
+ set_maps vp8 || return 1
+ fi
+}
+
+set_maps_vp9() {
+ if [ "$(vp9_encode_available)" = "yes" ]; then
+ set_maps vp9 || return 1
+ fi
+}
+
+set_maps_tests="set_maps_vp8
+ set_maps_vp9"
+
+run_tests set_maps_verify_environment "${set_maps_tests}"
diff --git a/test/svc_test.cc b/test/svc_test.cc
index e9cf38def..1cb01a407 100644
--- a/test/svc_test.cc
+++ b/test/svc_test.cc
@@ -13,6 +13,9 @@
#include "test/codec_factory.h"
#include "test/decode_test_driver.h"
#include "test/i420_video_source.h"
+
+#include "vp9/decoder/vp9_decoder.h"
+
#include "vpx/svc_context.h"
#include "vpx/vp8cx.h"
#include "vpx/vpx_encoder.h"
@@ -21,6 +24,7 @@ namespace {
using libvpx_test::CodecFactory;
using libvpx_test::Decoder;
+using libvpx_test::DxDataIterator;
using libvpx_test::VP9CodecFactory;
class SvcTest : public ::testing::Test {
@@ -62,9 +66,213 @@ class SvcTest : public ::testing::Test {
}
virtual void TearDown() {
- vpx_svc_release(&svc_);
+ ReleaseEncoder();
delete(decoder_);
+ }
+
+ void InitializeEncoder() {
+ const vpx_codec_err_t res =
+ vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
+ EXPECT_EQ(VPX_CODEC_OK, res);
+ codec_initialized_ = true;
+ }
+
+ void ReleaseEncoder() {
+ vpx_svc_release(&svc_);
if (codec_initialized_) vpx_codec_destroy(&codec_);
+ codec_initialized_ = false;
+ }
+
+ void Pass1EncodeNFrames(const int n, const int layers,
+ std::string *const stats_buf) {
+ vpx_codec_err_t res;
+ size_t stats_size = 0;
+ const char *stats_data = NULL;
+
+ ASSERT_GT(n, 0);
+ ASSERT_GT(layers, 0);
+ svc_.spatial_layers = layers;
+ codec_enc_.g_pass = VPX_RC_FIRST_PASS;
+ InitializeEncoder();
+
+ libvpx_test::I420VideoSource video(test_file_name_, kWidth, kHeight,
+ codec_enc_.g_timebase.den,
+ codec_enc_.g_timebase.num, 0, 30);
+ video.Begin();
+
+ for (int i = 0; i < n; ++i) {
+ res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(),
+ video.duration(), VPX_DL_GOOD_QUALITY);
+ ASSERT_EQ(VPX_CODEC_OK, res);
+ stats_size = vpx_svc_get_rc_stats_buffer_size(&svc_);
+ EXPECT_GT(stats_size, 0U);
+ stats_data = vpx_svc_get_rc_stats_buffer(&svc_);
+ ASSERT_TRUE(stats_data != NULL);
+ stats_buf->append(stats_data, stats_size);
+ video.Next();
+ }
+
+ // Flush encoder and test EOS packet
+ res = vpx_svc_encode(&svc_, &codec_, NULL, video.pts(),
+ video.duration(), VPX_DL_GOOD_QUALITY);
+ stats_size = vpx_svc_get_rc_stats_buffer_size(&svc_);
+ EXPECT_GT(stats_size, 0U);
+ stats_data = vpx_svc_get_rc_stats_buffer(&svc_);
+ ASSERT_TRUE(stats_data != NULL);
+ stats_buf->append(stats_data, stats_size);
+
+ ReleaseEncoder();
+ }
+
+ void StoreFrames(const size_t max_frame_received,
+ struct vpx_fixed_buf *const outputs,
+ size_t *const frame_received) {
+ size_t frame_size;
+ while ((frame_size = vpx_svc_get_frame_size(&svc_)) > 0) {
+ ASSERT_LT(*frame_received, max_frame_received);
+
+ if (*frame_received == 0) {
+ EXPECT_EQ(1, vpx_svc_is_keyframe(&svc_));
+ }
+
+ outputs[*frame_received].buf = malloc(frame_size);
+ ASSERT_TRUE(outputs[*frame_received].buf != NULL);
+ memcpy(outputs[*frame_received].buf, vpx_svc_get_buffer(&svc_),
+ frame_size);
+ outputs[*frame_received].sz = frame_size;
+ ++(*frame_received);
+ }
+ }
+
+ void Pass2EncodeNFrames(std::string *const stats_buf,
+ const int n, const int layers,
+ struct vpx_fixed_buf *const outputs) {
+ vpx_codec_err_t res;
+ size_t frame_received = 0;
+
+ ASSERT_TRUE(outputs != NULL);
+ ASSERT_GT(n, 0);
+ ASSERT_GT(layers, 0);
+ svc_.spatial_layers = layers;
+ codec_enc_.rc_target_bitrate = 500;
+ if (codec_enc_.g_pass == VPX_RC_LAST_PASS) {
+ ASSERT_TRUE(stats_buf != NULL);
+ ASSERT_GT(stats_buf->size(), 0U);
+ codec_enc_.rc_twopass_stats_in.buf = &(*stats_buf)[0];
+ codec_enc_.rc_twopass_stats_in.sz = stats_buf->size();
+ }
+ InitializeEncoder();
+
+ libvpx_test::I420VideoSource video(test_file_name_, kWidth, kHeight,
+ codec_enc_.g_timebase.den,
+ codec_enc_.g_timebase.num, 0, 30);
+ video.Begin();
+
+ for (int i = 0; i < n; ++i) {
+ res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(),
+ video.duration(), VPX_DL_GOOD_QUALITY);
+ ASSERT_EQ(VPX_CODEC_OK, res);
+ StoreFrames(n, outputs, &frame_received);
+ video.Next();
+ }
+
+ // Flush Encoder
+ res = vpx_svc_encode(&svc_, &codec_, NULL, 0,
+ video.duration(), VPX_DL_GOOD_QUALITY);
+ EXPECT_EQ(VPX_CODEC_OK, res);
+ StoreFrames(n, outputs, &frame_received);
+
+ EXPECT_EQ(frame_received, (size_t)n);
+
+ ReleaseEncoder();
+ }
+
+ void DecodeNFrames(const struct vpx_fixed_buf *const inputs, const int n) {
+ int decoded_frames = 0;
+ int received_frames = 0;
+
+ ASSERT_TRUE(inputs != NULL);
+ ASSERT_GT(n, 0);
+
+ for (int i = 0; i < n; ++i) {
+ ASSERT_TRUE(inputs[i].buf != NULL);
+ ASSERT_GT(inputs[i].sz, 0U);
+ const vpx_codec_err_t res_dec =
+ decoder_->DecodeFrame(static_cast<const uint8_t *>(inputs[i].buf),
+ inputs[i].sz);
+ ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError();
+ ++decoded_frames;
+
+ DxDataIterator dec_iter = decoder_->GetDxData();
+ while (dec_iter.Next()) {
+ ++received_frames;
+ }
+ }
+ EXPECT_EQ(decoded_frames, n);
+ EXPECT_EQ(received_frames, n);
+ }
+
+ void DropEnhancementLayers(struct vpx_fixed_buf *const inputs,
+ const int num_super_frames,
+ const int remained_layers) {
+ ASSERT_TRUE(inputs != NULL);
+ ASSERT_GT(num_super_frames, 0);
+ ASSERT_GT(remained_layers, 0);
+
+ for (int i = 0; i < num_super_frames; ++i) {
+ uint32_t frame_sizes[8] = {0};
+ int frame_count = 0;
+ int frames_found = 0;
+ int frame;
+ ASSERT_TRUE(inputs[i].buf != NULL);
+ ASSERT_GT(inputs[i].sz, 0U);
+
+ vpx_codec_err_t res =
+ vp9_parse_superframe_index(static_cast<const uint8_t*>(inputs[i].buf),
+ inputs[i].sz, frame_sizes, &frame_count,
+ NULL, NULL);
+ ASSERT_EQ(VPX_CODEC_OK, res);
+
+ uint8_t *frame_data = static_cast<uint8_t *>(inputs[i].buf);
+ uint8_t *frame_start = frame_data;
+ for (frame = 0; frame < frame_count; ++frame) {
+ // Looking for a visible frame
+ if (frame_data[0] & 0x02) {
+ ++frames_found;
+ if (frames_found == remained_layers)
+ break;
+ }
+ frame_data += frame_sizes[frame];
+ }
+ ASSERT_LT(frame, frame_count);
+ if (frame == frame_count - 1)
+ continue;
+
+ frame_data += frame_sizes[frame];
+ uint8_t marker =
+ static_cast<const uint8_t *>(inputs[i].buf)[inputs[i].sz - 1];
+ const uint32_t mag = ((marker >> 3) & 0x3) + 1;
+ const size_t index_sz = 2 + mag * frame_count;
+ const size_t new_index_sz = 2 + mag * (frame + 1);
+ marker &= 0x0f8;
+ marker |= frame;
+ frame_data[0] = marker;
+ memcpy(frame_data + 1, frame_start + inputs[i].sz - index_sz + 1,
+ new_index_sz - 2);
+ frame_data[new_index_sz - 1] = marker;
+ inputs[i].sz = frame_data - frame_start + new_index_sz;
+ }
+ }
+
+ void FreeBitstreamBuffers(struct vpx_fixed_buf *const inputs, const int n) {
+ ASSERT_TRUE(inputs != NULL);
+ ASSERT_GT(n, 0);
+
+ for (int i = 0; i < n; ++i) {
+ free(inputs[i].buf);
+ inputs[i].buf = NULL;
+ inputs[i].sz = 0;
+ }
}
SvcContext svc_;
@@ -93,9 +301,7 @@ TEST_F(SvcTest, SvcInit) {
EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
svc_.spatial_layers = 0; // use default layers
- res = vpx_svc_init(&svc_, &codec_, codec_iface_, &codec_enc_);
- EXPECT_EQ(VPX_CODEC_OK, res);
- codec_initialized_ = true;
+ InitializeEncoder();
EXPECT_EQ(VPX_SS_DEFAULT_LAYERS, svc_.spatial_layers);
}
@@ -106,9 +312,7 @@ TEST_F(SvcTest, InitTwoLayers) {
EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
vpx_svc_set_scale_factors(&svc_, "4/16,16/16"); // valid scale values
- res = vpx_svc_init(&svc_, &codec_, codec_iface_, &codec_enc_);
- EXPECT_EQ(VPX_CODEC_OK, res);
- codec_initialized_ = true;
+ InitializeEncoder();
}
TEST_F(SvcTest, InvalidOptions) {
@@ -124,18 +328,15 @@ TEST_F(SvcTest, InvalidOptions) {
TEST_F(SvcTest, SetLayersOption) {
vpx_codec_err_t res = vpx_svc_set_options(&svc_, "layers=3");
EXPECT_EQ(VPX_CODEC_OK, res);
- res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
- EXPECT_EQ(VPX_CODEC_OK, res);
- codec_initialized_ = true;
+ InitializeEncoder();
EXPECT_EQ(3, svc_.spatial_layers);
}
TEST_F(SvcTest, SetMultipleOptions) {
vpx_codec_err_t res =
vpx_svc_set_options(&svc_, "layers=2 scale-factors=1/3,2/3");
- res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
EXPECT_EQ(VPX_CODEC_OK, res);
- codec_initialized_ = true;
+ InitializeEncoder();
EXPECT_EQ(2, svc_.spatial_layers);
}
@@ -149,9 +350,7 @@ TEST_F(SvcTest, SetScaleFactorsOption) {
res = vpx_svc_set_options(&svc_, "scale-factors=1/3,2/3");
EXPECT_EQ(VPX_CODEC_OK, res);
- res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
- EXPECT_EQ(VPX_CODEC_OK, res);
- codec_initialized_ = true;
+ InitializeEncoder();
}
TEST_F(SvcTest, SetQuantizersOption) {
@@ -162,9 +361,7 @@ TEST_F(SvcTest, SetQuantizersOption) {
EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
vpx_svc_set_options(&svc_, "quantizers=40,45");
- res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
- EXPECT_EQ(VPX_CODEC_OK, res);
- codec_initialized_ = true;
+ InitializeEncoder();
}
TEST_F(SvcTest, SetAutoAltRefOption) {
@@ -180,9 +377,7 @@ TEST_F(SvcTest, SetAutoAltRefOption) {
EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
vpx_svc_set_options(&svc_, "auto-alt-refs=0,1,1,1,0");
- res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
- EXPECT_EQ(VPX_CODEC_OK, res);
- codec_initialized_ = true;
+ InitializeEncoder();
}
TEST_F(SvcTest, SetQuantizers) {
@@ -200,9 +395,7 @@ TEST_F(SvcTest, SetQuantizers) {
res = vpx_svc_set_quantizers(&svc_, "40,30");
EXPECT_EQ(VPX_CODEC_OK, res);
- res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
- EXPECT_EQ(VPX_CODEC_OK, res);
- codec_initialized_ = true;
+ InitializeEncoder();
}
TEST_F(SvcTest, SetScaleFactors) {
@@ -220,121 +413,25 @@ TEST_F(SvcTest, SetScaleFactors) {
res = vpx_svc_set_scale_factors(&svc_, "4/16,16/16");
EXPECT_EQ(VPX_CODEC_OK, res);
- res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
- EXPECT_EQ(VPX_CODEC_OK, res);
- codec_initialized_ = true;
+ InitializeEncoder();
}
// Test that decoder can handle an SVC frame as the first frame in a sequence.
-TEST_F(SvcTest, FirstFrameHasLayers) {
- svc_.spatial_layers = 2;
- vpx_svc_set_scale_factors(&svc_, "4/16,16/16");
- vpx_svc_set_quantizers(&svc_, "40,30");
-
- vpx_codec_err_t res =
- vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
- EXPECT_EQ(VPX_CODEC_OK, res);
- codec_initialized_ = true;
-
- libvpx_test::I420VideoSource video(test_file_name_, kWidth, kHeight,
- codec_enc_.g_timebase.den,
- codec_enc_.g_timebase.num, 0, 30);
- video.Begin();
-
- res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(),
- video.duration(), VPX_DL_GOOD_QUALITY);
- EXPECT_EQ(VPX_CODEC_OK, res);
-
- if (vpx_svc_get_frame_size(&svc_) == 0) {
- // Flush encoder
- res = vpx_svc_encode(&svc_, &codec_, NULL, 0,
- video.duration(), VPX_DL_GOOD_QUALITY);
- EXPECT_EQ(VPX_CODEC_OK, res);
- }
-
- int frame_size = vpx_svc_get_frame_size(&svc_);
- EXPECT_GT(frame_size, 0);
- const vpx_codec_err_t res_dec = decoder_->DecodeFrame(
- static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), frame_size);
-
- // this test fails with a decoder error
- ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError();
+TEST_F(SvcTest, OnePassEncodeOneFrame) {
+ codec_enc_.g_pass = VPX_RC_ONE_PASS;
+ vpx_fixed_buf output = {0};
+ Pass2EncodeNFrames(NULL, 1, 2, &output);
+ DecodeNFrames(&output, 1);
+ FreeBitstreamBuffers(&output, 1);
}
-TEST_F(SvcTest, EncodeThreeFrames) {
- svc_.spatial_layers = 2;
- vpx_svc_set_scale_factors(&svc_, "4/16,16/16");
- vpx_svc_set_quantizers(&svc_, "40,30");
- int decoded_frames = 0;
- vpx_codec_err_t res_dec;
- int frame_size;
-
- vpx_codec_err_t res =
- vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
- ASSERT_EQ(VPX_CODEC_OK, res);
- codec_initialized_ = true;
-
- libvpx_test::I420VideoSource video(test_file_name_, kWidth, kHeight,
- codec_enc_.g_timebase.den,
- codec_enc_.g_timebase.num, 0, 30);
- // FRAME 0
- video.Begin();
- // This frame is a keyframe.
- res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(),
- video.duration(), VPX_DL_GOOD_QUALITY);
-
- if ((frame_size = vpx_svc_get_frame_size(&svc_)) > 0) {
- EXPECT_EQ((decoded_frames == 0), vpx_svc_is_keyframe(&svc_));
- res_dec = decoder_->DecodeFrame(
- static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), frame_size);
- ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError();
- ++decoded_frames;
- }
-
- // FRAME 1
- video.Next();
- // This is a P-frame.
- res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(),
- video.duration(), VPX_DL_GOOD_QUALITY);
- ASSERT_EQ(VPX_CODEC_OK, res);
-
- if ((frame_size = vpx_svc_get_frame_size(&svc_)) > 0) {
- EXPECT_EQ((decoded_frames == 0), vpx_svc_is_keyframe(&svc_));
- res_dec = decoder_->DecodeFrame(
- static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), frame_size);
- ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError();
- ++decoded_frames;
- }
-
- // FRAME 2
- video.Next();
- // This is a P-frame.
- res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(),
- video.duration(), VPX_DL_GOOD_QUALITY);
- ASSERT_EQ(VPX_CODEC_OK, res);
-
- if ((frame_size = vpx_svc_get_frame_size(&svc_)) > 0) {
- EXPECT_EQ((decoded_frames == 0), vpx_svc_is_keyframe(&svc_));
- res_dec = decoder_->DecodeFrame(
- static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), frame_size);
- ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError();
- ++decoded_frames;
- }
-
- // Flush encoder
- res = vpx_svc_encode(&svc_, &codec_, NULL, 0,
- video.duration(), VPX_DL_GOOD_QUALITY);
- EXPECT_EQ(VPX_CODEC_OK, res);
-
- while ((frame_size = vpx_svc_get_frame_size(&svc_)) > 0) {
- EXPECT_EQ((decoded_frames == 0), vpx_svc_is_keyframe(&svc_));
- res_dec = decoder_->DecodeFrame(
- static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), frame_size);
- ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError();
- ++decoded_frames;
- }
-
- EXPECT_EQ(decoded_frames, 3);
+TEST_F(SvcTest, OnePassEncodeThreeFrames) {
+ codec_enc_.g_pass = VPX_RC_ONE_PASS;
+ vpx_fixed_buf outputs[3];
+ memset(&outputs[0], 0, sizeof(outputs));
+ Pass2EncodeNFrames(NULL, 3, 2, &outputs[0]);
+ DecodeNFrames(&outputs[0], 3);
+ FreeBitstreamBuffers(&outputs[0], 3);
}
TEST_F(SvcTest, GetLayerResolution) {
@@ -342,14 +439,11 @@ TEST_F(SvcTest, GetLayerResolution) {
vpx_svc_set_scale_factors(&svc_, "4/16,8/16");
vpx_svc_set_quantizers(&svc_, "40,30");
- vpx_codec_err_t res =
- vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
- EXPECT_EQ(VPX_CODEC_OK, res);
- codec_initialized_ = true;
+ InitializeEncoder();
// ensure that requested layer is a valid layer
uint32_t layer_width, layer_height;
- res = vpx_svc_get_layer_resolution(&svc_, svc_.spatial_layers,
+ vpx_codec_err_t res = vpx_svc_get_layer_resolution(&svc_, svc_.spatial_layers,
&layer_width, &layer_height);
EXPECT_EQ(VPX_CODEC_INVALID_PARAM, res);
@@ -373,131 +467,113 @@ TEST_F(SvcTest, GetLayerResolution) {
EXPECT_EQ(kHeight * 8 / 16, layer_height);
}
-TEST_F(SvcTest, TwoPassEncode) {
+TEST_F(SvcTest, TwoPassEncode10Frames) {
// First pass encode
std::string stats_buf;
- svc_.spatial_layers = 2;
- codec_enc_.g_pass = VPX_RC_FIRST_PASS;
- vpx_svc_set_scale_factors(&svc_, "4/16,16/16");
- vpx_svc_set_quantizers(&svc_, "40,30");
+ Pass1EncodeNFrames(10, 2, &stats_buf);
+
+ // Second pass encode
+ codec_enc_.g_pass = VPX_RC_LAST_PASS;
+ vpx_fixed_buf outputs[10];
+ memset(&outputs[0], 0, sizeof(outputs));
+ Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]);
+ DecodeNFrames(&outputs[0], 10);
+ FreeBitstreamBuffers(&outputs[0], 10);
+}
+
+TEST_F(SvcTest, TwoPassEncode20FramesWithAltRef) {
+ // First pass encode
+ std::string stats_buf;
+ Pass1EncodeNFrames(20, 2, &stats_buf);
+
+ // Second pass encode
+ codec_enc_.g_pass = VPX_RC_LAST_PASS;
vpx_svc_set_options(&svc_, "auto-alt-refs=1,1");
+ vpx_fixed_buf outputs[20];
+ memset(&outputs[0], 0, sizeof(outputs));
+ Pass2EncodeNFrames(&stats_buf, 20, 2, &outputs[0]);
+ DecodeNFrames(&outputs[0], 20);
+ FreeBitstreamBuffers(&outputs[0], 20);
+}
- vpx_codec_err_t res =
- vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
- ASSERT_EQ(VPX_CODEC_OK, res);
- codec_initialized_ = true;
-
- libvpx_test::I420VideoSource video(test_file_name_, kWidth, kHeight,
- codec_enc_.g_timebase.den,
- codec_enc_.g_timebase.num, 0, 30);
- // FRAME 0
- video.Begin();
- res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(),
- video.duration(), VPX_DL_GOOD_QUALITY);
- ASSERT_EQ(VPX_CODEC_OK, res);
- size_t stats_size = vpx_svc_get_rc_stats_buffer_size(&svc_);
- EXPECT_GT(stats_size, 0U);
- const char *stats_data = vpx_svc_get_rc_stats_buffer(&svc_);
- ASSERT_TRUE(stats_data != NULL);
- stats_buf.append(stats_data, stats_size);
-
- // FRAME 1
- video.Next();
- res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(),
- video.duration(), VPX_DL_GOOD_QUALITY);
- stats_size = vpx_svc_get_rc_stats_buffer_size(&svc_);
- EXPECT_GT(stats_size, 0U);
- stats_data = vpx_svc_get_rc_stats_buffer(&svc_);
- ASSERT_TRUE(stats_data != NULL);
- stats_buf.append(stats_data, stats_size);
-
- // Flush encoder and test EOS packet
- res = vpx_svc_encode(&svc_, &codec_, NULL, video.pts(),
- video.duration(), VPX_DL_GOOD_QUALITY);
- stats_size = vpx_svc_get_rc_stats_buffer_size(&svc_);
- EXPECT_GT(stats_size, 0U);
- stats_data = vpx_svc_get_rc_stats_buffer(&svc_);
- ASSERT_TRUE(stats_data != NULL);
- stats_buf.append(stats_data, stats_size);
-
- // Tear down encoder
- vpx_svc_release(&svc_);
- vpx_codec_destroy(&codec_);
+TEST_F(SvcTest, TwoPassEncode2LayersDecodeBaseLayerOnly) {
+ // First pass encode
+ std::string stats_buf;
+ Pass1EncodeNFrames(10, 2, &stats_buf);
// Second pass encode
- int decoded_frames = 0;
- vpx_codec_err_t res_dec;
- int frame_size;
codec_enc_.g_pass = VPX_RC_LAST_PASS;
- vpx_svc_set_scale_factors(&svc_, "4/16,16/16");
- vpx_svc_set_quantizers(&svc_, "40,30");
vpx_svc_set_options(&svc_, "auto-alt-refs=1,1");
- codec_enc_.rc_twopass_stats_in.buf = &stats_buf[0];
- codec_enc_.rc_twopass_stats_in.sz = stats_buf.size();
+ vpx_fixed_buf outputs[10];
+ memset(&outputs[0], 0, sizeof(outputs));
+ Pass2EncodeNFrames(&stats_buf, 10, 2, &outputs[0]);
+ DropEnhancementLayers(&outputs[0], 10, 1);
+ DecodeNFrames(&outputs[0], 10);
+ FreeBitstreamBuffers(&outputs[0], 10);
+}
- res = vpx_svc_init(&svc_, &codec_, vpx_codec_vp9_cx(), &codec_enc_);
- ASSERT_EQ(VPX_CODEC_OK, res);
- codec_initialized_ = true;
-
- // FRAME 0
- video.Begin();
- // This frame is a keyframe.
- res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(),
- video.duration(), VPX_DL_GOOD_QUALITY);
- ASSERT_EQ(VPX_CODEC_OK, res);
-
- if ((frame_size = vpx_svc_get_frame_size(&svc_)) > 0) {
- EXPECT_EQ((decoded_frames == 0), vpx_svc_is_keyframe(&svc_));
- res_dec = decoder_->DecodeFrame(
- static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), frame_size);
- ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError();
- ++decoded_frames;
- }
+TEST_F(SvcTest, TwoPassEncode5LayersDecode54321Layers) {
+ // First pass encode
+ std::string stats_buf;
+ Pass1EncodeNFrames(10, 5, &stats_buf);
- // FRAME 1
- video.Next();
- // This is a P-frame.
- res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(),
- video.duration(), VPX_DL_GOOD_QUALITY);
- ASSERT_EQ(VPX_CODEC_OK, res);
-
- if ((frame_size = vpx_svc_get_frame_size(&svc_)) > 0) {
- EXPECT_EQ((decoded_frames == 0), vpx_svc_is_keyframe(&svc_));
- res_dec = decoder_->DecodeFrame(
- static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), frame_size);
- ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError();
- ++decoded_frames;
- }
+ // Second pass encode
+ codec_enc_.g_pass = VPX_RC_LAST_PASS;
+ vpx_svc_set_options(&svc_, "auto-alt-refs=0,1,1,1,0");
+ vpx_fixed_buf outputs[10];
+ memset(&outputs[0], 0, sizeof(outputs));
+ Pass2EncodeNFrames(&stats_buf, 10, 5, &outputs[0]);
+
+ DecodeNFrames(&outputs[0], 10);
+ DropEnhancementLayers(&outputs[0], 10, 4);
+ DecodeNFrames(&outputs[0], 10);
+ DropEnhancementLayers(&outputs[0], 10, 3);
+ DecodeNFrames(&outputs[0], 10);
+ DropEnhancementLayers(&outputs[0], 10, 2);
+ DecodeNFrames(&outputs[0], 10);
+ DropEnhancementLayers(&outputs[0], 10, 1);
+ DecodeNFrames(&outputs[0], 10);
+
+ FreeBitstreamBuffers(&outputs[0], 10);
+}
- // FRAME 2
- video.Next();
- // This is a P-frame.
- res = vpx_svc_encode(&svc_, &codec_, video.img(), video.pts(),
- video.duration(), VPX_DL_GOOD_QUALITY);
- ASSERT_EQ(VPX_CODEC_OK, res);
-
- if ((frame_size = vpx_svc_get_frame_size(&svc_)) > 0) {
- EXPECT_EQ((decoded_frames == 0), vpx_svc_is_keyframe(&svc_));
- res_dec = decoder_->DecodeFrame(
- static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), frame_size);
- ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError();
- ++decoded_frames;
- }
+TEST_F(SvcTest, TwoPassEncode2SNRLayers) {
+ // First pass encode
+ std::string stats_buf;
+ vpx_svc_set_options(&svc_, "scale-factors=1/1,1/1");
+ Pass1EncodeNFrames(20, 2, &stats_buf);
- // Flush encoder
- res = vpx_svc_encode(&svc_, &codec_, NULL, 0,
- video.duration(), VPX_DL_GOOD_QUALITY);
- EXPECT_EQ(VPX_CODEC_OK, res);
+ // Second pass encode
+ codec_enc_.g_pass = VPX_RC_LAST_PASS;
+ vpx_svc_set_options(&svc_,
+ "auto-alt-refs=1,1 scale-factors=1/1,1/1");
+ vpx_fixed_buf outputs[20];
+ memset(&outputs[0], 0, sizeof(outputs));
+ Pass2EncodeNFrames(&stats_buf, 20, 2, &outputs[0]);
+ DecodeNFrames(&outputs[0], 20);
+ FreeBitstreamBuffers(&outputs[0], 20);
+}
- while ((frame_size = vpx_svc_get_frame_size(&svc_)) > 0) {
- EXPECT_EQ((decoded_frames == 0), vpx_svc_is_keyframe(&svc_));
- res_dec = decoder_->DecodeFrame(
- static_cast<const uint8_t *>(vpx_svc_get_buffer(&svc_)), frame_size);
- ASSERT_EQ(VPX_CODEC_OK, res_dec) << decoder_->DecodeError();
- ++decoded_frames;
- }
+TEST_F(SvcTest, TwoPassEncode3SNRLayersDecode321Layers) {
+ // First pass encode
+ std::string stats_buf;
+ vpx_svc_set_options(&svc_, "scale-factors=1/1,1/1,1/1");
+ Pass1EncodeNFrames(20, 3, &stats_buf);
- EXPECT_EQ(decoded_frames, 3);
+ // Second pass encode
+ codec_enc_.g_pass = VPX_RC_LAST_PASS;
+ vpx_svc_set_options(&svc_,
+ "auto-alt-refs=1,1,1 scale-factors=1/1,1/1,1/1");
+ vpx_fixed_buf outputs[20];
+ memset(&outputs[0], 0, sizeof(outputs));
+ Pass2EncodeNFrames(&stats_buf, 20, 3, &outputs[0]);
+ DecodeNFrames(&outputs[0], 20);
+ DropEnhancementLayers(&outputs[0], 20, 2);
+ DecodeNFrames(&outputs[0], 20);
+ DropEnhancementLayers(&outputs[0], 20, 1);
+ DecodeNFrames(&outputs[0], 20);
+
+ FreeBitstreamBuffers(&outputs[0], 20);
}
} // namespace
diff --git a/vp9/decoder/vp9_decoder.c b/vp9/decoder/vp9_decoder.c
index 1a4155825..e79dcf371 100644
--- a/vp9/decoder/vp9_decoder.c
+++ b/vp9/decoder/vp9_decoder.c
@@ -314,3 +314,67 @@ int vp9_get_raw_frame(VP9Decoder *pbi, YV12_BUFFER_CONFIG *sd,
vp9_clear_system_state();
return ret;
}
+
+vpx_codec_err_t vp9_parse_superframe_index(const uint8_t *data,
+ size_t data_sz,
+ uint32_t sizes[8], int *count,
+ vpx_decrypt_cb decrypt_cb,
+ void *decrypt_state) {
+ // A chunk ending with a byte matching 0xc0 is an invalid chunk unless
+ // it is a super frame index. If the last byte of real video compression
+ // data is 0xc0 the encoder must add a 0 byte. If we have the marker but
+ // not the associated matching marker byte at the front of the index we have
+ // an invalid bitstream and need to return an error.
+
+ uint8_t marker;
+
+ assert(data_sz);
+ marker = read_marker(decrypt_cb, decrypt_state, data + data_sz - 1);
+ *count = 0;
+
+ if ((marker & 0xe0) == 0xc0) {
+ const uint32_t frames = (marker & 0x7) + 1;
+ const uint32_t mag = ((marker >> 3) & 0x3) + 1;
+ const size_t index_sz = 2 + mag * frames;
+
+ // This chunk is marked as having a superframe index but doesn't have
+ // enough data for it, thus it's an invalid superframe index.
+ if (data_sz < index_sz)
+ return VPX_CODEC_CORRUPT_FRAME;
+
+ {
+ const uint8_t marker2 = read_marker(decrypt_cb, decrypt_state,
+ data + data_sz - index_sz);
+
+ // This chunk is marked as having a superframe index but doesn't have
+ // the matching marker byte at the front of the index therefore it's an
+ // invalid chunk.
+ if (marker != marker2)
+ return VPX_CODEC_CORRUPT_FRAME;
+ }
+
+ {
+ // Found a valid superframe index.
+ uint32_t i, j;
+ const uint8_t *x = &data[data_sz - index_sz + 1];
+
+ // Frames has a maximum of 8 and mag has a maximum of 4.
+ uint8_t clear_buffer[32];
+ assert(sizeof(clear_buffer) >= frames * mag);
+ if (decrypt_cb) {
+ decrypt_cb(decrypt_state, x, clear_buffer, frames * mag);
+ x = clear_buffer;
+ }
+
+ for (i = 0; i < frames; ++i) {
+ uint32_t this_sz = 0;
+
+ for (j = 0; j < mag; ++j)
+ this_sz |= (*x++) << (j * 8);
+ sizes[i] = this_sz;
+ }
+ *count = frames;
+ }
+ }
+ return VPX_CODEC_OK;
+}
diff --git a/vp9/decoder/vp9_decoder.h b/vp9/decoder/vp9_decoder.h
index 223b66fc7..848d212e6 100644
--- a/vp9/decoder/vp9_decoder.h
+++ b/vp9/decoder/vp9_decoder.h
@@ -78,6 +78,25 @@ struct VP9Decoder *vp9_decoder_create();
void vp9_decoder_remove(struct VP9Decoder *pbi);
+static INLINE uint8_t read_marker(vpx_decrypt_cb decrypt_cb,
+ void *decrypt_state,
+ const uint8_t *data) {
+ if (decrypt_cb) {
+ uint8_t marker;
+ decrypt_cb(decrypt_state, data, &marker, 1);
+ return marker;
+ }
+ return *data;
+}
+
+// This function is exposed for use in tests, as well as the inlined function
+// "read_marker".
+vpx_codec_err_t vp9_parse_superframe_index(const uint8_t *data,
+ size_t data_sz,
+ uint32_t sizes[8], int *count,
+ vpx_decrypt_cb decrypt_cb,
+ void *decrypt_state);
+
#ifdef __cplusplus
} // extern "C"
#endif
diff --git a/vp9/encoder/arm/neon/vp9_quantize_neon.c b/vp9/encoder/arm/neon/vp9_quantize_neon.c
index 2d5ec79b3..8c13d0da6 100644
--- a/vp9/encoder/arm/neon/vp9_quantize_neon.c
+++ b/vp9/encoder/arm/neon/vp9_quantize_neon.c
@@ -28,7 +28,6 @@ void vp9_quantize_fp_neon(const int16_t *coeff_ptr, intptr_t count,
int16_t *dqcoeff_ptr, const int16_t *dequant_ptr,
int zbin_oq_value, uint16_t *eob_ptr,
const int16_t *scan, const int16_t *iscan) {
- int i;
// TODO(jingning) Decide the need of these arguments after the
// quantization process is completed.
(void)zbin_ptr;
@@ -39,7 +38,7 @@ void vp9_quantize_fp_neon(const int16_t *coeff_ptr, intptr_t count,
if (!skip_block) {
// Quantization pass: All coefficients with index >= zero_flag are
// skippable. Note: zero_flag can be zero.
-
+ int i;
const int16x8_t v_zero = vdupq_n_s16(0);
const int16x8_t v_one = vdupq_n_s16(1);
int16x8_t v_eobmax_76543210 = vdupq_n_s16(-1);
@@ -50,13 +49,37 @@ void vp9_quantize_fp_neon(const int16_t *coeff_ptr, intptr_t count,
v_round = vsetq_lane_s16(round_ptr[0], v_round, 0);
v_quant = vsetq_lane_s16(quant_ptr[0], v_quant, 0);
v_dequant = vsetq_lane_s16(dequant_ptr[0], v_dequant, 0);
-
- for (i = 0; i < count; i += 8) {
+ // process dc and the first seven ac coeffs
+ {
+ const int16x8_t v_iscan = vld1q_s16(&iscan[0]);
+ const int16x8_t v_coeff = vld1q_s16(&coeff_ptr[0]);
+ const int16x8_t v_coeff_sign = vshrq_n_s16(v_coeff, 15);
+ const int16x8_t v_tmp = vabaq_s16(v_round, v_coeff, v_zero);
+ const int32x4_t v_tmp_lo = vmull_s16(vget_low_s16(v_tmp),
+ vget_low_s16(v_quant));
+ const int32x4_t v_tmp_hi = vmull_s16(vget_high_s16(v_tmp),
+ vget_high_s16(v_quant));
+ const int16x8_t v_tmp2 = vcombine_s16(vshrn_n_s32(v_tmp_lo, 16),
+ vshrn_n_s32(v_tmp_hi, 16));
+ const uint16x8_t v_nz_mask = vceqq_s16(v_tmp2, v_zero);
+ const int16x8_t v_iscan_plus1 = vaddq_s16(v_iscan, v_one);
+ const int16x8_t v_nz_iscan = vbslq_s16(v_nz_mask, v_zero, v_iscan_plus1);
+ const int16x8_t v_qcoeff_a = veorq_s16(v_tmp2, v_coeff_sign);
+ const int16x8_t v_qcoeff = vsubq_s16(v_qcoeff_a, v_coeff_sign);
+ const int16x8_t v_dqcoeff = vmulq_s16(v_qcoeff, v_dequant);
+ v_eobmax_76543210 = vmaxq_s16(v_eobmax_76543210, v_nz_iscan);
+ vst1q_s16(&qcoeff_ptr[0], v_qcoeff);
+ vst1q_s16(&dqcoeff_ptr[0], v_dqcoeff);
+ v_round = vmovq_n_s16(round_ptr[1]);
+ v_quant = vmovq_n_s16(quant_ptr[1]);
+ v_dequant = vmovq_n_s16(dequant_ptr[1]);
+ }
+ // now process the rest of the ac coeffs
+ for (i = 8; i < count; i += 8) {
const int16x8_t v_iscan = vld1q_s16(&iscan[i]);
const int16x8_t v_coeff = vld1q_s16(&coeff_ptr[i]);
const int16x8_t v_coeff_sign = vshrq_n_s16(v_coeff, 15);
- const int16x8_t v_abs_coeff = vabsq_s16(v_coeff);
- const int16x8_t v_tmp = vqaddq_s16(v_abs_coeff, v_round);
+ const int16x8_t v_tmp = vabaq_s16(v_round, v_coeff, v_zero);
const int32x4_t v_tmp_lo = vmull_s16(vget_low_s16(v_tmp),
vget_low_s16(v_quant));
const int32x4_t v_tmp_hi = vmull_s16(vget_high_s16(v_tmp),
@@ -65,19 +88,13 @@ void vp9_quantize_fp_neon(const int16_t *coeff_ptr, intptr_t count,
vshrn_n_s32(v_tmp_hi, 16));
const uint16x8_t v_nz_mask = vceqq_s16(v_tmp2, v_zero);
const int16x8_t v_iscan_plus1 = vaddq_s16(v_iscan, v_one);
- const int16x8_t v_nz_iscan =
- vandq_s16(vmvnq_s16(vreinterpretq_s16_u16(v_nz_mask)), v_iscan_plus1);
+ const int16x8_t v_nz_iscan = vbslq_s16(v_nz_mask, v_zero, v_iscan_plus1);
const int16x8_t v_qcoeff_a = veorq_s16(v_tmp2, v_coeff_sign);
const int16x8_t v_qcoeff = vsubq_s16(v_qcoeff_a, v_coeff_sign);
const int16x8_t v_dqcoeff = vmulq_s16(v_qcoeff, v_dequant);
-
v_eobmax_76543210 = vmaxq_s16(v_eobmax_76543210, v_nz_iscan);
-
vst1q_s16(&qcoeff_ptr[i], v_qcoeff);
vst1q_s16(&dqcoeff_ptr[i], v_dqcoeff);
- v_round = vmovq_n_s16(round_ptr[1]);
- v_quant = vmovq_n_s16(quant_ptr[1]);
- v_dequant = vmovq_n_s16(dequant_ptr[1]);
}
{
const int16x4_t v_eobmax_3210 =
diff --git a/vp9/encoder/vp9_encoder.c b/vp9/encoder/vp9_encoder.c
index 60f20c12d..445608a3d 100644
--- a/vp9/encoder/vp9_encoder.c
+++ b/vp9/encoder/vp9_encoder.c
@@ -541,6 +541,20 @@ static void init_config(struct VP9_COMP *cpi, VP9EncoderConfig *oxcf) {
set_tile_limits(cpi);
}
+static void set_rc_buffer_sizes(RATE_CONTROL *rc,
+ const VP9EncoderConfig *oxcf) {
+ const int64_t bandwidth = oxcf->target_bandwidth;
+ const int64_t starting = oxcf->starting_buffer_level_ms;
+ const int64_t optimal = oxcf->optimal_buffer_level_ms;
+ const int64_t maximum = oxcf->maximum_buffer_size_ms;
+
+ rc->starting_buffer_level = starting * bandwidth / 1000;
+ rc->optimal_buffer_level = (optimal == 0) ? bandwidth / 8
+ : optimal * bandwidth / 1000;
+ rc->maximum_buffer_size = (maximum == 0) ? bandwidth / 8
+ : maximum * bandwidth / 1000;
+}
+
void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) {
VP9_COMMON *const cm = &cpi->common;
RATE_CONTROL *const rc = &cpi->rc;
@@ -574,28 +588,8 @@ void vp9_change_config(struct VP9_COMP *cpi, const VP9EncoderConfig *oxcf) {
}
cpi->encode_breakout = cpi->oxcf.encode_breakout;
- // local file playback mode == really big buffer
- if (cpi->oxcf.rc_mode == VPX_VBR) {
- cpi->oxcf.starting_buffer_level_ms = 60000;
- cpi->oxcf.optimal_buffer_level_ms = 60000;
- cpi->oxcf.maximum_buffer_size_ms = 240000;
- }
-
- rc->starting_buffer_level = cpi->oxcf.starting_buffer_level_ms *
- cpi->oxcf.target_bandwidth / 1000;
-
- // Set or reset optimal and maximum buffer levels.
- if (cpi->oxcf.optimal_buffer_level_ms == 0)
- rc->optimal_buffer_level = cpi->oxcf.target_bandwidth / 8;
- else
- rc->optimal_buffer_level = cpi->oxcf.optimal_buffer_level_ms *
- cpi->oxcf.target_bandwidth / 1000;
+ set_rc_buffer_sizes(rc, &cpi->oxcf);
- if (cpi->oxcf.maximum_buffer_size_ms == 0)
- rc->maximum_buffer_size = cpi->oxcf.target_bandwidth / 8;
- else
- rc->maximum_buffer_size = cpi->oxcf.maximum_buffer_size_ms *
- cpi->oxcf.target_bandwidth / 1000;
// Under a configuration change, where maximum_buffer_size may change,
// keep buffer level clipped to the maximum allowed buffer size.
rc->bits_off_target = MIN(rc->bits_off_target, rc->maximum_buffer_size);
diff --git a/vp9/encoder/vp9_encoder.h b/vp9/encoder/vp9_encoder.h
index 284ae9dc9..ec8ac82bb 100644
--- a/vp9/encoder/vp9_encoder.h
+++ b/vp9/encoder/vp9_encoder.h
@@ -495,14 +495,6 @@ static INLINE YV12_BUFFER_CONFIG *get_ref_frame_buffer(
.buf;
}
-// Intra only frames, golden frames (except alt ref overlays) and
-// alt ref frames tend to be coded at a higher than ambient quality
-static INLINE int frame_is_boosted(const VP9_COMP *cpi) {
- return frame_is_intra_only(&cpi->common) || cpi->refresh_alt_ref_frame ||
- (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref) ||
- vp9_is_upper_layer_key_frame(cpi);
-}
-
static INLINE int get_token_alloc(int mb_rows, int mb_cols) {
// TODO(JBB): double check we can't exceed this token count if we have a
// 32x32 transform crossing a boundary at a multiple of 16.
diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c
index 81ce5ea46..94bbe9c69 100644
--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -432,6 +432,8 @@ void vp9_first_pass(VP9_COMP *cpi) {
TWO_PASS *twopass = &cpi->twopass;
const MV zero_mv = {0, 0};
const YV12_BUFFER_CONFIG *first_ref_buf = lst_yv12;
+ LAYER_CONTEXT *const lc = is_spatial_svc(cpi) ?
+ &cpi->svc.layer_context[cpi->svc.spatial_layer_id] : 0;
#if CONFIG_FP_MB_STATS
if (cpi->use_fp_mb_stats) {
@@ -444,15 +446,14 @@ void vp9_first_pass(VP9_COMP *cpi) {
set_first_pass_params(cpi);
vp9_set_quantizer(cm, find_fp_qindex());
- if (is_spatial_svc(cpi)) {
+ if (lc != NULL) {
MV_REFERENCE_FRAME ref_frame = LAST_FRAME;
const YV12_BUFFER_CONFIG *scaled_ref_buf = NULL;
- twopass = &cpi->svc.layer_context[cpi->svc.spatial_layer_id].twopass;
+ twopass = &lc->twopass;
if (cpi->common.current_video_frame == 0) {
cpi->ref_frame_flags = 0;
} else {
- LAYER_CONTEXT *lc = &cpi->svc.layer_context[cpi->svc.spatial_layer_id];
if (lc->current_video_frame_in_layer == 0)
cpi->ref_frame_flags = VP9_GOLD_FLAG;
else
@@ -613,7 +614,7 @@ void vp9_first_pass(VP9_COMP *cpi) {
&unscaled_last_source_buf_2d);
// TODO(pengchong): Replace the hard-coded threshold
- if (raw_motion_error > 25 || is_spatial_svc(cpi)) {
+ if (raw_motion_error > 25 || lc != NULL) {
// Test last reference frame using the previous best mv as the
// starting point (best reference) for the search.
first_pass_motion_search(cpi, x, &best_ref_mv.as_mv, &mv.as_mv,
@@ -895,7 +896,7 @@ void vp9_first_pass(VP9_COMP *cpi) {
vp9_extend_frame_borders(new_yv12);
- if (is_spatial_svc(cpi)) {
+ if (lc != NULL) {
vp9_update_reference_frames(cpi);
} else {
// Swap frame pointers so last frame refers to the frame we just compressed.
@@ -1081,8 +1082,7 @@ static double get_prediction_decay_rate(const VP9_COMMON *cm,
// This function gives an estimate of how badly we believe the prediction
// quality is decaying from frame to frame.
-static double get_zero_motion_factor(const VP9_COMMON *cm,
- const FIRSTPASS_STATS *frame) {
+static double get_zero_motion_factor(const FIRSTPASS_STATS *frame) {
const double sr_ratio = frame->coded_error /
DOUBLE_DIVIDE_CHECK(frame->sr_coded_error);
const double zero_motion_pct = frame->pcnt_inter -
@@ -1095,12 +1095,10 @@ static double get_zero_motion_factor(const VP9_COMMON *cm,
// Function to test for a condition where a complex transition is followed
// by a static section. For example in slide shows where there is a fade
// between slides. This is to help with more optimal kf and gf positioning.
-static int detect_transition_to_still(TWO_PASS *twopass,
+static int detect_transition_to_still(const TWO_PASS *twopass,
int frame_interval, int still_interval,
double loop_decay_rate,
double last_decay_rate) {
- int trans_to_still = 0;
-
// Break clause to detect very still sections after motion
// For example a static image after a fade or other transition
// instead of a clean scene cut.
@@ -1108,26 +1106,22 @@ static int detect_transition_to_still(TWO_PASS *twopass,
loop_decay_rate >= 0.999 &&
last_decay_rate < 0.9) {
int j;
- const FIRSTPASS_STATS *position = twopass->stats_in;
- FIRSTPASS_STATS tmp_next_frame;
// Look ahead a few frames to see if static condition persists...
for (j = 0; j < still_interval; ++j) {
- if (EOF == input_stats(twopass, &tmp_next_frame))
+ const FIRSTPASS_STATS *stats = &twopass->stats_in[j];
+ if (stats >= twopass->stats_in_end)
break;
- if (tmp_next_frame.pcnt_inter - tmp_next_frame.pcnt_motion < 0.999)
+ if (stats->pcnt_inter - stats->pcnt_motion < 0.999)
break;
}
- reset_fpf_position(twopass, position);
-
// Only if it does do we signal a transition to still.
- if (j == still_interval)
- trans_to_still = 1;
+ return j == still_interval;
}
- return trans_to_still;
+ return 0;
}
// This function detects a flash through the high relative pcnt_second_ref
@@ -1555,8 +1549,6 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
vp9_clear_system_state();
vp9_zero(next_frame);
- gf_group_bits = 0;
-
// Load stats for the current frame.
mod_frame_err = calculate_modified_err(twopass, oxcf, this_frame);
@@ -1616,9 +1608,8 @@ static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
decay_accumulator = decay_accumulator * loop_decay_rate;
// Monitor for static sections.
- zero_motion_accumulator =
- MIN(zero_motion_accumulator,
- get_zero_motion_factor(&cpi->common, &next_frame));
+ zero_motion_accumulator = MIN(zero_motion_accumulator,
+ get_zero_motion_factor(&next_frame));
// Break clause to detect very still sections after motion. For example,
// a static image after a fade or other transition.
@@ -1989,9 +1980,8 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
break;
// Monitor for static sections.
- zero_motion_accumulator =
- MIN(zero_motion_accumulator,
- get_zero_motion_factor(&cpi->common, &next_frame));
+ zero_motion_accumulator =MIN(zero_motion_accumulator,
+ get_zero_motion_factor(&next_frame));
// For the first few frames collect data to decide kf boost.
if (i <= (rc->max_gf_interval * 2)) {
@@ -2127,10 +2117,10 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
FIRSTPASS_STATS this_frame_copy;
int target_rate;
- LAYER_CONTEXT *lc = NULL;
+ LAYER_CONTEXT *const lc = is_spatial_svc(cpi) ?
+ &cpi->svc.layer_context[cpi->svc.spatial_layer_id] : 0;
- if (is_spatial_svc(cpi)) {
- lc = &cpi->svc.layer_context[cpi->svc.spatial_layer_id];
+ if (lc != NULL) {
frames_left = (int)(twopass->total_stats.count -
lc->current_video_frame_in_layer);
} else {
@@ -2157,7 +2147,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
vp9_rc_set_frame_target(cpi, target_rate);
cm->frame_type = INTER_FRAME;
- if (is_spatial_svc(cpi)) {
+ if (lc != NULL) {
if (cpi->svc.spatial_layer_id == 0) {
lc->is_key_frame = 0;
} else {
@@ -2173,7 +2163,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
vp9_clear_system_state();
- if (is_spatial_svc(cpi) && twopass->kf_intra_err_min == 0) {
+ if (lc != NULL && twopass->kf_intra_err_min == 0) {
twopass->kf_intra_err_min = KF_MB_INTRA_MIN * cpi->common.MBs;
twopass->gf_intra_err_min = GF_MB_INTRA_MIN * cpi->common.MBs;
}
@@ -2181,8 +2171,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
if (cpi->oxcf.rc_mode == VPX_Q) {
twopass->active_worst_quality = cpi->oxcf.cq_level;
} else if (cm->current_video_frame == 0 ||
- (is_spatial_svc(cpi) &&
- lc->current_video_frame_in_layer == 0)) {
+ (lc != NULL && lc->current_video_frame_in_layer == 0)) {
// Special case code for first frame.
const int section_target_bandwidth = (int)(twopass->bits_left /
frames_left);
@@ -2208,7 +2197,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
cm->frame_type = INTER_FRAME;
}
- if (is_spatial_svc(cpi)) {
+ if (lc != NULL) {
if (cpi->svc.spatial_layer_id == 0) {
lc->is_key_frame = (cm->frame_type == KEY_FRAME);
if (lc->is_key_frame)
@@ -2239,7 +2228,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
}
rc->frames_till_gf_update_due = rc->baseline_gf_interval;
- if (!is_spatial_svc(cpi))
+ if (lc != NULL)
cpi->refresh_golden_frame = 1;
}
diff --git a/vp9/encoder/vp9_pickmode.c b/vp9/encoder/vp9_pickmode.c
index 6115f5a0f..e5469c831 100644
--- a/vp9/encoder/vp9_pickmode.c
+++ b/vp9/encoder/vp9_pickmode.c
@@ -17,6 +17,7 @@
#include "vpx_mem/vpx_mem.h"
+#include "vp9/common/vp9_blockd.h"
#include "vp9/common/vp9_common.h"
#include "vp9/common/vp9_mvref_common.h"
#include "vp9/common/vp9_reconinter.h"
@@ -343,6 +344,52 @@ static void encode_breakout_test(VP9_COMP *cpi, MACROBLOCK *x,
}
}
+struct estimate_block_intra_args {
+ VP9_COMP *cpi;
+ MACROBLOCK *x;
+ PREDICTION_MODE mode;
+ int rate;
+ int64_t dist;
+};
+
+static void estimate_block_intra(int plane, int block, BLOCK_SIZE plane_bsize,
+ TX_SIZE tx_size, void *arg) {
+ struct estimate_block_intra_args* const args = arg;
+ VP9_COMP *const cpi = args->cpi;
+ MACROBLOCK *const x = args->x;
+ MACROBLOCKD *const xd = &x->e_mbd;
+ struct macroblock_plane *const p = &x->plane[0];
+ struct macroblockd_plane *const pd = &xd->plane[0];
+ const BLOCK_SIZE bsize_tx = txsize_to_bsize[tx_size];
+ uint8_t *const src_buf_base = p->src.buf;
+ uint8_t *const dst_buf_base = pd->dst.buf;
+ const int src_stride = p->src.stride;
+ const int dst_stride = pd->dst.stride;
+ int i, j;
+ int rate;
+ int64_t dist;
+ unsigned int var_y, sse_y;
+ txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &i, &j);
+ assert(plane == 0);
+ (void) plane;
+
+ p->src.buf = &src_buf_base[4 * (j * src_stride + i)];
+ pd->dst.buf = &dst_buf_base[4 * (j * dst_stride + i)];
+ // Use source buffer as an approximation for the fully reconstructed buffer.
+ vp9_predict_intra_block(xd, block >> (2 * tx_size),
+ b_width_log2(plane_bsize),
+ tx_size, args->mode,
+ p->src.buf, src_stride,
+ pd->dst.buf, dst_stride,
+ i, j, 0);
+ // This procedure assumes zero offset from p->src.buf and pd->dst.buf.
+ model_rd_for_sb_y(cpi, bsize_tx, x, xd, &rate, &dist, &var_y, &sse_y);
+ p->src.buf = src_buf_base;
+ pd->dst.buf = dst_buf_base;
+ args->rate += rate;
+ args->dist += dist;
+}
+
static const THR_MODES mode_idx[MAX_REF_FRAMES - 1][4] = {
{THR_NEARESTMV, THR_NEARMV, THR_ZEROMV, THR_NEWMV},
{THR_NEARESTG, THR_NEARG, THR_ZEROG, THR_NEWG},
@@ -360,7 +407,6 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
PICK_MODE_CONTEXT *ctx) {
MACROBLOCKD *xd = &x->e_mbd;
MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
- struct macroblock_plane *const p = &x->plane[0];
struct macroblockd_plane *const pd = &xd->plane[0];
PREDICTION_MODE this_mode, best_mode = ZEROMV;
MV_REFERENCE_FRAME ref_frame, best_ref_frame = LAST_FRAME;
@@ -397,9 +443,9 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
(((mi_row + mi_col) >> bsl) +
get_chessboard_index(cm->current_video_frame)) & 0x1 : 0;
int const_motion[MAX_REF_FRAMES] = { 0 };
- int bh = num_4x4_blocks_high_lookup[bsize] << 2;
- int bw = num_4x4_blocks_wide_lookup[bsize] << 2;
- int pixels_in_block = bh * bw;
+ const int bh = num_4x4_blocks_high_lookup[bsize] << 2;
+ const int bw = num_4x4_blocks_wide_lookup[bsize] << 2;
+ const int pixels_in_block = bh * bw;
// For speed 6, the result of interp filter is reused later in actual encoding
// process.
// tmp[3] points to dst buffer, and the other 3 point to allocated buffers.
@@ -670,20 +716,11 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
// threshold.
if (!x->skip && best_rd > inter_mode_thresh &&
bsize <= cpi->sf.max_intra_bsize) {
- int i, j;
- const int width = num_4x4_blocks_wide_lookup[bsize];
- const int height = num_4x4_blocks_high_lookup[bsize];
+ struct estimate_block_intra_args args = { cpi, x, DC_PRED, 0, 0 };
- int rate2 = 0;
- int64_t dist2 = 0;
- const int dst_stride = cpi->sf.reuse_inter_pred_sby ? bw : pd->dst.stride;
- const int src_stride = p->src.stride;
- int block_idx = 0;
-
- TX_SIZE tmp_tx_size = MIN(max_txsize_lookup[bsize],
- tx_mode_to_biggest_tx_size[cpi->common.tx_mode]);
- const BLOCK_SIZE bsize_tx = txsize_to_bsize[tmp_tx_size];
- const int step = 1 << tmp_tx_size;
+ const TX_SIZE intra_tx_size =
+ MIN(max_txsize_lookup[bsize],
+ tx_mode_to_biggest_tx_size[cpi->common.tx_mode]);
if (cpi->sf.reuse_inter_pred_sby) {
pd->dst.buf = tmp[0].data;
@@ -691,44 +728,26 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
}
for (this_mode = DC_PRED; this_mode <= DC_PRED; ++this_mode) {
- uint8_t *const src_buf_base = p->src.buf;
- uint8_t *const dst_buf_base = pd->dst.buf;
- for (j = 0; j < height; j += step) {
- for (i = 0; i < width; i += step) {
- p->src.buf = &src_buf_base[4 * (j * src_stride + i)];
- pd->dst.buf = &dst_buf_base[4 * (j * dst_stride + i)];
- // Use source buffer as an approximation for the fully reconstructed
- // buffer
- vp9_predict_intra_block(xd, block_idx, b_width_log2(bsize),
- tmp_tx_size, this_mode,
- p->src.buf, src_stride,
- pd->dst.buf, dst_stride,
- i, j, 0);
- model_rd_for_sb_y(cpi, bsize_tx, x, xd, &rate, &dist, &var_y, &sse_y);
- rate2 += rate;
- dist2 += dist;
- ++block_idx;
- }
- }
- p->src.buf = src_buf_base;
- pd->dst.buf = dst_buf_base;
-
- rate = rate2;
- dist = dist2;
-
+ const TX_SIZE saved_tx_size = mbmi->tx_size;
+ args.mode = this_mode;
+ args.rate = 0;
+ args.dist = 0;
+ mbmi->tx_size = intra_tx_size;
+ vp9_foreach_transformed_block_in_plane(xd, bsize, 0,
+ estimate_block_intra, &args);
+ mbmi->tx_size = saved_tx_size;
+ rate = args.rate;
+ dist = args.dist;
rate += cpi->mbmode_cost[this_mode];
rate += intra_cost_penalty;
this_rd = RDCOST(x->rdmult, x->rddiv, rate, dist);
- if (cpi->sf.reuse_inter_pred_sby)
- pd->dst = orig_dst;
-
if (this_rd + intra_mode_cost < best_rd) {
best_rd = this_rd;
*returnrate = rate;
*returndistortion = dist;
mbmi->mode = this_mode;
- mbmi->tx_size = tmp_tx_size;
+ mbmi->tx_size = intra_tx_size;
mbmi->ref_frame[0] = INTRA_FRAME;
mbmi->uv_mode = this_mode;
mbmi->mv[0].as_int = INVALID_MV;
@@ -736,6 +755,8 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x,
x->skip_txfm[0] = skip_txfm;
}
}
+ if (cpi->sf.reuse_inter_pred_sby)
+ pd->dst = orig_dst;
}
return INT64_MAX;
diff --git a/vp9/encoder/vp9_ratectrl.c b/vp9/encoder/vp9_ratectrl.c
index 9da2adec4..b926a58f4 100644
--- a/vp9/encoder/vp9_ratectrl.c
+++ b/vp9/encoder/vp9_ratectrl.c
@@ -646,7 +646,6 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi,
int q;
if (frame_is_intra_only(cm)) {
- active_best_quality = rc->best_quality;
// Handle the special case for key frames forced when we have reached
// the maximum key frame interval. Here force the Q to a range
diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c
index 517674e5f..cfda964ce 100644
--- a/vp9/encoder/vp9_rdopt.c
+++ b/vp9/encoder/vp9_rdopt.c
@@ -490,24 +490,24 @@ static void choose_tx_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x,
{INT64_MAX, INT64_MAX},
{INT64_MAX, INT64_MAX},
{INT64_MAX, INT64_MAX}};
- TX_SIZE n, m;
+ int n, m;
int s0, s1;
const TX_SIZE max_mode_tx_size = tx_mode_to_biggest_tx_size[cm->tx_mode];
int64_t best_rd = INT64_MAX;
- TX_SIZE best_tx = TX_4X4;
+ TX_SIZE best_tx = max_tx_size;
const vp9_prob *tx_probs = get_tx_probs2(max_tx_size, xd, &cm->fc.tx_probs);
assert(skip_prob > 0);
s0 = vp9_cost_bit(skip_prob, 0);
s1 = vp9_cost_bit(skip_prob, 1);
- for (n = TX_4X4; n <= max_tx_size; n++) {
+ for (n = max_tx_size; n >= 0; n--) {
txfm_rd_in_plane(x, &r[n][0], &d[n], &s[n],
&sse[n], ref_best_rd, 0, bs, n,
cpi->sf.use_fast_coef_costing);
r[n][1] = r[n][0];
if (r[n][0] < INT_MAX) {
- for (m = 0; m <= n - (n == max_tx_size); m++) {
+ for (m = 0; m <= n - (n == (int) max_tx_size); m++) {
if (m == n)
r[n][1] += vp9_cost_zero(tx_probs[m]);
else
@@ -523,6 +523,13 @@ static void choose_tx_size_from_rd(VP9_COMP *cpi, MACROBLOCK *x,
rd[n][1] = RDCOST(x->rdmult, x->rddiv, r[n][1] + s0, d[n]);
}
+ // Early termination in transform size search.
+ if (cpi->sf.tx_size_search_breakout &&
+ (rd[n][1] == INT64_MAX ||
+ (n < (int) max_tx_size && rd[n][1] > rd[n + 1][1]) ||
+ s[n] == 1))
+ break;
+
if (rd[n][1] < best_rd) {
best_tx = n;
best_rd = rd[n][1];
@@ -2632,6 +2639,12 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
int64_t total_sse = INT64_MAX;
int early_term = 0;
+ this_mode = vp9_mode_order[mode_index].mode;
+ ref_frame = vp9_mode_order[mode_index].ref_frame[0];
+ if (ref_frame != INTRA_FRAME && !(inter_mode_mask & (1 << this_mode)))
+ continue;
+ second_ref_frame = vp9_mode_order[mode_index].ref_frame[1];
+
// Look at the reference frame of the best mode so far and set the
// skip mask to look at a subset of the remaining modes.
if (mode_index == mode_skip_start && best_mode_index >= 0) {
@@ -2653,6 +2666,13 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
break;
}
}
+
+ if (cpi->sf.alt_ref_search_fp && cpi->rc.is_src_frame_alt_ref) {
+ mode_skip_mask = 0;
+ if (!(ref_frame == ALTREF_FRAME && second_ref_frame == NONE))
+ continue;
+ }
+
if (mode_skip_mask & (1 << mode_index))
continue;
@@ -2661,12 +2681,6 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x,
rd_thresh_freq_fact[mode_index]))
continue;
- this_mode = vp9_mode_order[mode_index].mode;
- ref_frame = vp9_mode_order[mode_index].ref_frame[0];
- if (ref_frame != INTRA_FRAME && !(inter_mode_mask & (1 << this_mode)))
- continue;
- second_ref_frame = vp9_mode_order[mode_index].ref_frame[1];
-
if (cpi->sf.motion_field_mode_search) {
const int mi_width = MIN(num_8x8_blocks_wide_lookup[bsize],
tile->mi_col_end - mi_col);
diff --git a/vp9/encoder/vp9_speed_features.c b/vp9/encoder/vp9_speed_features.c
index 67b6e269e..57835ec3d 100644
--- a/vp9/encoder/vp9_speed_features.c
+++ b/vp9/encoder/vp9_speed_features.c
@@ -50,8 +50,20 @@ enum {
(1 << THR_GOLD)
};
+// Intra only frames, golden frames (except alt ref overlays) and
+// alt ref frames tend to be coded at a higher than ambient quality
+static int frame_is_boosted(const VP9_COMP *cpi) {
+ return frame_is_intra_only(&cpi->common) ||
+ cpi->refresh_alt_ref_frame ||
+ (cpi->refresh_golden_frame && !cpi->rc.is_src_frame_alt_ref) ||
+ vp9_is_upper_layer_key_frame(cpi);
+}
+
+
static void set_good_speed_feature(VP9_COMP *cpi, VP9_COMMON *cm,
SPEED_FEATURES *sf, int speed) {
+ const int boosted = frame_is_boosted(cpi);
+
sf->adaptive_rd_thresh = 1;
sf->recode_loop = (speed < 1) ? ALLOW_RECODE : ALLOW_RECODE_KFMAXBW;
sf->allow_skip_recode = 1;
@@ -59,8 +71,6 @@ static void set_good_speed_feature(VP9_COMP *cpi, VP9_COMMON *cm,
if (speed >= 1) {
sf->use_square_partition_only = !frame_is_intra_only(cm);
sf->less_rectangular_check = 1;
- sf->tx_size_search_method = frame_is_boosted(cpi) ? USE_FULL_RD
- : USE_LARGESTALL;
if (MIN(cm->width, cm->height) >= 720)
sf->disable_split_mask = cm->show_frame ? DISABLE_ALL_SPLIT
@@ -80,9 +90,14 @@ static void set_good_speed_feature(VP9_COMP *cpi, VP9_COMMON *cm,
sf->intra_uv_mode_mask[TX_32X32] = INTRA_DC_H_V;
sf->intra_y_mode_mask[TX_16X16] = INTRA_DC_H_V;
sf->intra_uv_mode_mask[TX_16X16] = INTRA_DC_H_V;
+
+ sf->tx_size_search_breakout = 1;
}
if (speed >= 2) {
+ sf->tx_size_search_method = frame_is_boosted(cpi) ? USE_FULL_RD
+ : USE_LARGESTALL;
+
if (MIN(cm->width, cm->height) >= 720) {
sf->lf_motion_threshold = LOW_MOTION_THRESHOLD;
sf->last_partitioning_redo_frequency = 3;
@@ -117,9 +132,10 @@ static void set_good_speed_feature(VP9_COMP *cpi, VP9_COMMON *cm,
sf->disable_split_mask = DISABLE_ALL_INTER_SPLIT;
}
sf->adaptive_pred_interp_filter = 0;
- sf->cb_partition_search = frame_is_boosted(cpi) ? 0 : 1;
+ sf->cb_partition_search = !boosted;
sf->cb_pred_filter_search = 1;
- sf->motion_field_mode_search = frame_is_boosted(cpi) ? 0 : 1;
+ sf->alt_ref_search_fp = 1;
+ sf->motion_field_mode_search = !boosted;
sf->lf_motion_threshold = LOW_MOTION_THRESHOLD;
sf->last_partitioning_redo_frequency = 3;
sf->recode_loop = ALLOW_RECODE_KFMAXBW;
@@ -347,6 +363,7 @@ void vp9_set_speed_features(VP9_COMP *cpi) {
sf->cb_pred_filter_search = 0;
sf->cb_partition_search = 0;
sf->motion_field_mode_search = 0;
+ sf->alt_ref_search_fp = 0;
sf->use_quant_fp = 0;
sf->reference_masking = 0;
sf->partition_search_type = SEARCH_PARTITION;
@@ -389,6 +406,7 @@ void vp9_set_speed_features(VP9_COMP *cpi) {
// Recode loop tolerence %.
sf->recode_tolerance = 25;
sf->default_interp_filter = SWITCHABLE;
+ sf->tx_size_search_breakout = 0;
if (oxcf->mode == REALTIME) {
set_rt_speed_feature(cpi, sf, oxcf->speed, oxcf->content);
diff --git a/vp9/encoder/vp9_speed_features.h b/vp9/encoder/vp9_speed_features.h
index 8edcb1d72..bad956da5 100644
--- a/vp9/encoder/vp9_speed_features.h
+++ b/vp9/encoder/vp9_speed_features.h
@@ -291,6 +291,8 @@ typedef struct SPEED_FEATURES {
int motion_field_mode_search;
+ int alt_ref_search_fp;
+
// Fast quantization process path
int use_quant_fp;
@@ -374,6 +376,10 @@ typedef struct SPEED_FEATURES {
// default interp filter choice
INTERP_FILTER default_interp_filter;
+
+ // Early termination in transform size search, which only applies while
+ // tx_size_search_method is USE_FULL_RD.
+ int tx_size_search_breakout;
} SPEED_FEATURES;
struct VP9_COMP;
diff --git a/vp9/encoder/vp9_svc_layercontext.c b/vp9/encoder/vp9_svc_layercontext.c
index fb52d1ab7..1d9bdd869 100644
--- a/vp9/encoder/vp9_svc_layercontext.c
+++ b/vp9/encoder/vp9_svc_layercontext.c
@@ -106,12 +106,9 @@ void vp9_update_layer_context_change_config(VP9_COMP *const cpi,
}
bitrate_alloc = (float)lc->target_bandwidth / target_bandwidth;
// Update buffer-related quantities.
- lrc->starting_buffer_level =
- (int64_t)(rc->starting_buffer_level * bitrate_alloc);
- lrc->optimal_buffer_level =
- (int64_t)(rc->optimal_buffer_level * bitrate_alloc);
- lrc->maximum_buffer_size =
- (int64_t)(rc->maximum_buffer_size * bitrate_alloc);
+ lrc->starting_buffer_level = rc->starting_buffer_level * bitrate_alloc;
+ lrc->optimal_buffer_level = rc->optimal_buffer_level * bitrate_alloc;
+ lrc->maximum_buffer_size = rc->maximum_buffer_size * bitrate_alloc;
lrc->bits_off_target = MIN(lrc->bits_off_target, lrc->maximum_buffer_size);
lrc->buffer_level = MIN(lrc->buffer_level, lrc->maximum_buffer_size);
// Update framerate-related quantities.
diff --git a/vp9/vp9_cx_iface.c b/vp9/vp9_cx_iface.c
index cdbb69b2d..553fec731 100644
--- a/vp9/vp9_cx_iface.c
+++ b/vp9/vp9_cx_iface.c
@@ -325,6 +325,7 @@ static vpx_codec_err_t set_encoder_config(
VP9EncoderConfig *oxcf,
const vpx_codec_enc_cfg_t *cfg,
const struct vp9_extracfg *extra_cfg) {
+ const int is_vbr = cfg->rc_end_usage == VPX_VBR;
oxcf->profile = cfg->g_profile;
oxcf->width = cfg->g_w;
oxcf->height = cfg->g_h;
@@ -371,9 +372,9 @@ static vpx_codec_err_t set_encoder_config(
oxcf->scaled_frame_width = cfg->rc_scaled_width;
oxcf->scaled_frame_height = cfg->rc_scaled_height;
- oxcf->maximum_buffer_size_ms = cfg->rc_buf_sz;
- oxcf->starting_buffer_level_ms = cfg->rc_buf_initial_sz;
- oxcf->optimal_buffer_level_ms = cfg->rc_buf_optimal_sz;
+ oxcf->maximum_buffer_size_ms = is_vbr ? 240000 : cfg->rc_buf_sz;
+ oxcf->starting_buffer_level_ms = is_vbr ? 60000 : cfg->rc_buf_initial_sz;
+ oxcf->optimal_buffer_level_ms = is_vbr ? 60000 : cfg->rc_buf_optimal_sz;
oxcf->drop_frames_water_mark = cfg->rc_dropframe_thresh;
diff --git a/vp9/vp9_dx_iface.c b/vp9/vp9_dx_iface.c
index 4372ac9e5..ee8290512 100644
--- a/vp9/vp9_dx_iface.c
+++ b/vp9/vp9_dx_iface.c
@@ -332,81 +332,6 @@ static vpx_codec_err_t decode_one(vpx_codec_alg_priv_t *ctx,
return VPX_CODEC_OK;
}
-static INLINE uint8_t read_marker(vpx_decrypt_cb decrypt_cb,
- void *decrypt_state,
- const uint8_t *data) {
- if (decrypt_cb) {
- uint8_t marker;
- decrypt_cb(decrypt_state, data, &marker, 1);
- return marker;
- }
- return *data;
-}
-
-static vpx_codec_err_t parse_superframe_index(const uint8_t *data,
- size_t data_sz,
- uint32_t sizes[8], int *count,
- vpx_decrypt_cb decrypt_cb,
- void *decrypt_state) {
- // A chunk ending with a byte matching 0xc0 is an invalid chunk unless
- // it is a super frame index. If the last byte of real video compression
- // data is 0xc0 the encoder must add a 0 byte. If we have the marker but
- // not the associated matching marker byte at the front of the index we have
- // an invalid bitstream and need to return an error.
-
- uint8_t marker;
-
- assert(data_sz);
- marker = read_marker(decrypt_cb, decrypt_state, data + data_sz - 1);
- *count = 0;
-
- if ((marker & 0xe0) == 0xc0) {
- const uint32_t frames = (marker & 0x7) + 1;
- const uint32_t mag = ((marker >> 3) & 0x3) + 1;
- const size_t index_sz = 2 + mag * frames;
-
- // This chunk is marked as having a superframe index but doesn't have
- // enough data for it, thus it's an invalid superframe index.
- if (data_sz < index_sz)
- return VPX_CODEC_CORRUPT_FRAME;
-
- {
- const uint8_t marker2 = read_marker(decrypt_cb, decrypt_state,
- data + data_sz - index_sz);
-
- // This chunk is marked as having a superframe index but doesn't have
- // the matching marker byte at the front of the index therefore it's an
- // invalid chunk.
- if (marker != marker2)
- return VPX_CODEC_CORRUPT_FRAME;
- }
-
- {
- // Found a valid superframe index.
- uint32_t i, j;
- const uint8_t *x = &data[data_sz - index_sz + 1];
-
- // Frames has a maximum of 8 and mag has a maximum of 4.
- uint8_t clear_buffer[32];
- assert(sizeof(clear_buffer) >= frames * mag);
- if (decrypt_cb) {
- decrypt_cb(decrypt_state, x, clear_buffer, frames * mag);
- x = clear_buffer;
- }
-
- for (i = 0; i < frames; ++i) {
- uint32_t this_sz = 0;
-
- for (j = 0; j < mag; ++j)
- this_sz |= (*x++) << (j * 8);
- sizes[i] = this_sz;
- }
- *count = frames;
- }
- }
- return VPX_CODEC_OK;
-}
-
static vpx_codec_err_t decoder_decode(vpx_codec_alg_priv_t *ctx,
const uint8_t *data, unsigned int data_sz,
void *user_priv, long deadline) {
@@ -424,8 +349,8 @@ static vpx_codec_err_t decoder_decode(vpx_codec_alg_priv_t *ctx,
// Reset flushed when receiving a valid frame.
ctx->flushed = 0;
- res = parse_superframe_index(data, data_sz, frame_sizes, &frame_count,
- ctx->decrypt_cb, ctx->decrypt_state);
+ res = vp9_parse_superframe_index(data, data_sz, frame_sizes, &frame_count,
+ ctx->decrypt_cb, ctx->decrypt_state);
if (res != VPX_CODEC_OK)
return res;
diff --git a/vpx/internal/vpx_codec_internal.h b/vpx/internal/vpx_codec_internal.h
index a7716d130..0f5ce3d68 100644
--- a/vpx/internal/vpx_codec_internal.h
+++ b/vpx/internal/vpx_codec_internal.h
@@ -347,7 +347,6 @@ struct vpx_codec_priv {
vpx_codec_priv_cb_pair_t put_slice_cb;
} dec;
struct {
- int tbd;
struct vpx_fixed_buf cx_data_dst_buf;
unsigned int cx_data_pad_before;
unsigned int cx_data_pad_after;
diff --git a/vpx/src/vpx_image.c b/vpx/src/vpx_image.c
index 8c7e3cfca..e20703a5e 100644
--- a/vpx/src/vpx_image.c
+++ b/vpx/src/vpx_image.c
@@ -8,38 +8,12 @@
* be found in the AUTHORS file in the root of the source tree.
*/
-
#include <stdlib.h>
#include <string.h>
+
#include "vpx/vpx_image.h"
#include "vpx/vpx_integer.h"
-
-#define ADDRESS_STORAGE_SIZE sizeof(size_t)
-/*returns an addr aligned to the byte boundary specified by align*/
-#define align_addr(addr,align) (void*)(((size_t)(addr) + ((align) - 1)) & (size_t)-(align))
-
-/* Memalign code is copied from vpx_mem.c */
-static void *img_buf_memalign(size_t align, size_t size) {
- void *addr,
- * x = NULL;
-
- addr = malloc(size + align - 1 + ADDRESS_STORAGE_SIZE);
-
- if (addr) {
- x = align_addr((unsigned char *)addr + ADDRESS_STORAGE_SIZE, (int)align);
- /* save the actual malloc address */
- ((size_t *)x)[-1] = (size_t)addr;
- }
-
- return x;
-}
-
-static void img_buf_free(void *memblk) {
- if (memblk) {
- void *addr = (void *)(((size_t *)memblk)[-1]);
- free(addr);
- }
-}
+#include "vpx_mem/vpx_mem.h"
static vpx_image_t *img_alloc_helper(vpx_image_t *img,
vpx_img_fmt_t fmt,
@@ -172,7 +146,7 @@ static vpx_image_t *img_alloc_helper(vpx_image_t *img,
if (alloc_size != (size_t)alloc_size)
goto fail;
- img->img_data = img_buf_memalign(buf_align, (size_t)alloc_size);
+ img->img_data = (uint8_t *)vpx_memalign(buf_align, (size_t)alloc_size);
img->img_data_owner = 1;
}
@@ -296,7 +270,7 @@ void vpx_img_flip(vpx_image_t *img) {
void vpx_img_free(vpx_image_t *img) {
if (img) {
if (img->img_data && img->img_data_owner)
- img_buf_free(img->img_data);
+ vpx_free(img->img_data);
if (img->self_allocd)
free(img);
diff --git a/vpxdec.c b/vpxdec.c
index faee42a0b..6c822abe7 100644
--- a/vpxdec.c
+++ b/vpxdec.c
@@ -15,13 +15,16 @@
#include <string.h>
#include <limits.h>
+#include "./vpx_config.h"
+
+#if CONFIG_LIBYUV
#include "third_party/libyuv/include/libyuv/scale.h"
+#endif
#include "./args.h"
#include "./ivfdec.h"
#define VPX_CODEC_DISABLE_COMPAT 1
-#include "./vpx_config.h"
#include "vpx/vpx_decoder.h"
#include "vpx_ports/mem_ops.h"
#include "vpx_ports/vpx_timer.h"
@@ -123,6 +126,7 @@ static const arg_def_t *vp8_pp_args[] = {
};
#endif
+#if CONFIG_LIBYUV
static INLINE int vpx_image_scale(vpx_image_t *src, vpx_image_t *dst,
FilterModeEnum mode) {
assert(src->fmt == VPX_IMG_FMT_I420);
@@ -137,6 +141,7 @@ static INLINE int vpx_image_scale(vpx_image_t *src, vpx_image_t *dst,
dst->d_w, dst->d_h,
mode);
}
+#endif
void usage_exit() {
int i;
@@ -538,7 +543,8 @@ int main_loop(int argc, const char **argv_) {
struct VpxDecInputContext input = {NULL, NULL};
struct VpxInputContext vpx_input_ctx;
#if CONFIG_WEBM_IO
- struct WebmInputContext webm_ctx = {0};
+ struct WebmInputContext webm_ctx;
+ memset(&(webm_ctx), 0, sizeof(webm_ctx));
input.webm_ctx = &webm_ctx;
#endif
input.vpx_input_ctx = &vpx_input_ctx;
diff --git a/vpxenc.c b/vpxenc.c
index 7e037a62c..b99e61a12 100644
--- a/vpxenc.c
+++ b/vpxenc.c
@@ -19,12 +19,15 @@
#include <stdlib.h>
#include <string.h>
+#if CONFIG_LIBYUV
+#include "third_party/libyuv/include/libyuv/scale.h"
+#endif
+
#include "vpx/vpx_encoder.h"
#if CONFIG_DECODERS
#include "vpx/vpx_decoder.h"
#endif
-#include "third_party/libyuv/include/libyuv/scale.h"
#include "./args.h"
#include "./ivfenc.h"
#include "./tools_common.h"