diff options
-rwxr-xr-x | test/set_maps.sh | 59 | ||||
-rw-r--r-- | test/svc_test.cc | 576 | ||||
-rw-r--r-- | vp8/encoder/onyx_if.c | 12 | ||||
-rw-r--r-- | vp9/decoder/vp9_decoder.c | 64 | ||||
-rw-r--r-- | vp9/decoder/vp9_decoder.h | 19 | ||||
-rw-r--r-- | vp9/encoder/vp9_encoder.c | 83 | ||||
-rw-r--r-- | vp9/encoder/vp9_encoder.h | 45 | ||||
-rw-r--r-- | vp9/encoder/vp9_firstpass.c | 109 | ||||
-rw-r--r-- | vp9/encoder/vp9_pickmode.c | 113 | ||||
-rw-r--r-- | vp9/encoder/vp9_ratectrl.c | 1 | ||||
-rw-r--r-- | vp9/encoder/x86/vp9_dct_sse2.c | 4 | ||||
-rw-r--r-- | vp9/vp9_cx_iface.c | 59 | ||||
-rw-r--r-- | vp9/vp9_dx_iface.c | 79 | ||||
-rw-r--r-- | vpx/internal/vpx_codec_internal.h | 1 | ||||
-rw-r--r-- | vpx/src/vpx_image.c | 34 | ||||
-rw-r--r-- | vpxdec.c | 7 | ||||
-rw-r--r-- | vpxenc.c | 5 |
17 files changed, 700 insertions, 570 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/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c index d29dd3997..38b89997b 100644 --- a/vp8/encoder/onyx_if.c +++ b/vp8/encoder/onyx_if.c @@ -3303,15 +3303,17 @@ static void process_denoiser_mode_change(VP8_COMP *cpi) { int skip = 2; // Only select blocks for computing nmse that have been encoded // as ZERO LAST min_consec_zero_last frames in a row. - int min_consec_zero_last = 10; + // Scale with number of temporal layers. + int min_consec_zero_last = 8 / cpi->oxcf.number_of_layers; // Decision is tested for changing the denoising mode every // num_mode_change times this function is called. Note that this // function called every 8 frames, so (8 * num_mode_change) is number // of frames where denoising mode change is tested for switch. int num_mode_change = 15; // Framerate factor, to compensate for larger mse at lower framerates. - // TODO(marpan): Adjust this factor, - int fac_framerate = cpi->output_framerate < 25.0f ? 80 : 100; + // Use ref_framerate, which is full source framerate for temporal layers. + // TODO(marpan): Adjust this factor. + int fac_framerate = cpi->ref_framerate < 25.0f ? 80 : 100; int tot_num_blocks = cm->mb_rows * cm->mb_cols; int ystride = cpi->Source->y_stride; unsigned char *src = cpi->Source->y_buffer; @@ -3380,13 +3382,13 @@ static void process_denoiser_mode_change(VP8_COMP *cpi) { // num_mode_change. if (cpi->denoiser.nmse_source_diff_count == num_mode_change) { // Check for going up: from normal to aggressive mode. - if ((cpi->denoiser.denoiser_mode = kDenoiserOnYUV) && + if ((cpi->denoiser.denoiser_mode == kDenoiserOnYUV) && (cpi->denoiser.nmse_source_diff > cpi->denoiser.threshold_aggressive_mode)) { vp8_denoiser_set_parameters(&cpi->denoiser, kDenoiserOnYUVAggressive); } else { // Check for going down: from aggressive to normal mode. - if ((cpi->denoiser.denoiser_mode = kDenoiserOnYUVAggressive) && + if ((cpi->denoiser.denoiser_mode == kDenoiserOnYUVAggressive) && (cpi->denoiser.nmse_source_diff < cpi->denoiser.threshold_aggressive_mode)) { vp8_denoiser_set_parameters(&cpi->denoiser, kDenoiserOnYUV); 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/vp9_encoder.c b/vp9/encoder/vp9_encoder.c index 60f20c12d..ee0b99cf7 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_rc_buffer_sizes(rc, &cpi->oxcf); - // 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; - - 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); @@ -2004,19 +1998,41 @@ static void set_arf_sign_bias(VP9_COMP *cpi) { cm->ref_frame_sign_bias[ALTREF_FRAME] = arf_sign_bias; } +static void set_mv_search_params(VP9_COMP *cpi) { + const VP9_COMMON *const cm = &cpi->common; + const unsigned int max_mv_def = MIN(cm->width, cm->height); + + // Default based on max resolution. + cpi->mv_step_param = vp9_init_search_range(max_mv_def); + + if (cpi->sf.mv.auto_mv_step_size) { + if (frame_is_intra_only(cm)) { + // Initialize max_mv_magnitude for use in the first INTER frame + // after a key/intra-only frame. + cpi->max_mv_magnitude = max_mv_def; + } else { + if (cm->show_frame) + // Allow mv_steps to correspond to twice the max mv magnitude found + // in the previous frame, capped by the default max_mv_magnitude based + // on resolution. + cpi->mv_step_param = + vp9_init_search_range(MIN(max_mv_def, 2 * cpi->max_mv_magnitude)); + cpi->max_mv_magnitude = 0; + } + } +} + static void encode_frame_to_data_rate(VP9_COMP *cpi, size_t *size, uint8_t *dest, unsigned int *frame_flags) { VP9_COMMON *const cm = &cpi->common; + struct segmentation *const seg = &cm->seg; TX_SIZE t; int q; int top_index; int bottom_index; - const SPEED_FEATURES *const sf = &cpi->sf; - const unsigned int max_mv_def = MIN(cm->width, cm->height); - struct segmentation *const seg = &cm->seg; set_ext_overrides(cpi); cpi->Source = vp9_scale_if_required(cm, cpi->un_scaled_source, @@ -2042,24 +2058,7 @@ static void encode_frame_to_data_rate(VP9_COMP *cpi, // Set default state for segment based loop filter update flags. cm->lf.mode_ref_delta_update = 0; - // Initialize cpi->mv_step_param to default based on max resolution. - cpi->mv_step_param = vp9_init_search_range(max_mv_def); - // Initialize cpi->max_mv_magnitude and cpi->mv_step_param if appropriate. - if (sf->mv.auto_mv_step_size) { - if (frame_is_intra_only(cm)) { - // Initialize max_mv_magnitude for use in the first INTER frame - // after a key/intra-only frame. - cpi->max_mv_magnitude = max_mv_def; - } else { - if (cm->show_frame) - // Allow mv_steps to correspond to twice the max mv magnitude found - // in the previous frame, capped by the default max_mv_magnitude based - // on resolution. - cpi->mv_step_param = vp9_init_search_range(MIN(max_mv_def, 2 * - cpi->max_mv_magnitude)); - cpi->max_mv_magnitude = 0; - } - } + set_mv_search_params(cpi); // Set various flags etc to special state if it is a key frame. if (frame_is_intra_only(cm)) { diff --git a/vp9/encoder/vp9_encoder.h b/vp9/encoder/vp9_encoder.h index ec8ac82bb..7226a786d 100644 --- a/vp9/encoder/vp9_encoder.h +++ b/vp9/encoder/vp9_encoder.h @@ -82,36 +82,19 @@ typedef enum { } VPX_SCALING; typedef enum { - // Good Quality Fast Encoding. The encoder balances quality with the - // amount of time it takes to encode the output. (speed setting - // controls how fast) - ONE_PASS_GOOD = 1, - - // One Pass - Best Quality. The encoder places priority on the - // quality of the output over encoding speed. The output is compressed - // at the highest possible quality. This option takes the longest - // amount of time to encode. (speed setting ignored) - ONE_PASS_BEST = 2, - - // Two Pass - First Pass. The encoder generates a file of statistics - // for use in the second encoding pass. (speed setting controls how fast) - TWO_PASS_FIRST = 3, - - // Two Pass - Second Pass. The encoder uses the statistics that were - // generated in the first encoding pass to create the compressed - // output. (speed setting controls how fast) - TWO_PASS_SECOND_GOOD = 4, - - // Two Pass - Second Pass Best. The encoder uses the statistics that - // were generated in the first encoding pass to create the compressed - // output using the highest possible quality, and taking a - // longer amount of time to encode. (speed setting ignored) - TWO_PASS_SECOND_BEST = 5, - - // Realtime/Live Encoding. This mode is optimized for realtime - // encoding (for example, capturing a television signal or feed from - // a live camera). (speed setting controls how fast) - REALTIME = 6, + // Good Quality Fast Encoding. The encoder balances quality with the amount of + // time it takes to encode the output. Speed setting controls how fast. + GOOD, + + // The encoder places priority on the quality of the output over encoding + // speed. The output is compressed at the highest possible quality. This + // option takes the longest amount of time to encode. Speed setting ignored. + BEST, + + // Realtime/Live Encoding. This mode is optimized for realtime encoding (for + // example, capturing a television signal or feed from a live camera). Speed + // setting controls how fast. + REALTIME } MODE; typedef enum { @@ -241,7 +224,7 @@ static INLINE int is_lossless_requested(const VP9EncoderConfig *cfg) { } static INLINE int is_best_mode(MODE mode) { - return mode == ONE_PASS_BEST || mode == TWO_PASS_SECOND_BEST; + return mode == BEST; } typedef struct VP9_COMP { diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c index 36af81514..94bbe9c69 100644 --- a/vp9/encoder/vp9_firstpass.c +++ b/vp9/encoder/vp9_firstpass.c @@ -1095,12 +1095,10 @@ static double get_zero_motion_factor(const FIRSTPASS_STATS *frame) { // 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 @@ -1373,7 +1367,8 @@ static void allocate_gf_group_bits(VP9_COMP *cpi, int64_t gf_group_bits, double group_error, int gf_arf_bits) { RATE_CONTROL *const rc = &cpi->rc; const VP9EncoderConfig *const oxcf = &cpi->oxcf; - TWO_PASS *twopass = &cpi->twopass; + TWO_PASS *const twopass = &cpi->twopass; + GF_GROUP *const gf_group = &twopass->gf_group; FIRSTPASS_STATS frame_stats; int i; int frame_index = 1; @@ -1396,17 +1391,17 @@ static void allocate_gf_group_bits(VP9_COMP *cpi, int64_t gf_group_bits, // is also the golden frame. if (!key_frame) { if (rc->source_alt_ref_active) { - twopass->gf_group.update_type[0] = OVERLAY_UPDATE; - twopass->gf_group.rf_level[0] = INTER_NORMAL; - twopass->gf_group.bit_allocation[0] = 0; - twopass->gf_group.arf_update_idx[0] = arf_buffer_indices[0]; - twopass->gf_group.arf_ref_idx[0] = arf_buffer_indices[0]; + gf_group->update_type[0] = OVERLAY_UPDATE; + gf_group->rf_level[0] = INTER_NORMAL; + gf_group->bit_allocation[0] = 0; + gf_group->arf_update_idx[0] = arf_buffer_indices[0]; + gf_group->arf_ref_idx[0] = arf_buffer_indices[0]; } else { - twopass->gf_group.update_type[0] = GF_UPDATE; - twopass->gf_group.rf_level[0] = GF_ARF_STD; - twopass->gf_group.bit_allocation[0] = gf_arf_bits; - twopass->gf_group.arf_update_idx[0] = arf_buffer_indices[0]; - twopass->gf_group.arf_ref_idx[0] = arf_buffer_indices[0]; + gf_group->update_type[0] = GF_UPDATE; + gf_group->rf_level[0] = GF_ARF_STD; + gf_group->bit_allocation[0] = gf_arf_bits; + gf_group->arf_update_idx[0] = arf_buffer_indices[0]; + gf_group->arf_ref_idx[0] = arf_buffer_indices[0]; } // Step over the golden frame / overlay frame @@ -1421,25 +1416,25 @@ static void allocate_gf_group_bits(VP9_COMP *cpi, int64_t gf_group_bits, // Store the bits to spend on the ARF if there is one. if (rc->source_alt_ref_pending) { - twopass->gf_group.update_type[frame_index] = ARF_UPDATE; - twopass->gf_group.rf_level[frame_index] = GF_ARF_STD; - twopass->gf_group.bit_allocation[frame_index] = gf_arf_bits; - twopass->gf_group.arf_src_offset[frame_index] = + gf_group->update_type[frame_index] = ARF_UPDATE; + gf_group->rf_level[frame_index] = GF_ARF_STD; + gf_group->bit_allocation[frame_index] = gf_arf_bits; + gf_group->arf_src_offset[frame_index] = (unsigned char)(rc->baseline_gf_interval - 1); - twopass->gf_group.arf_update_idx[frame_index] = arf_buffer_indices[0]; - twopass->gf_group.arf_ref_idx[frame_index] = + gf_group->arf_update_idx[frame_index] = arf_buffer_indices[0]; + gf_group->arf_ref_idx[frame_index] = arf_buffer_indices[cpi->multi_arf_last_grp_enabled && rc->source_alt_ref_active]; ++frame_index; if (cpi->multi_arf_enabled) { // Set aside a slot for a level 1 arf. - twopass->gf_group.update_type[frame_index] = ARF_UPDATE; - twopass->gf_group.rf_level[frame_index] = GF_ARF_LOW; - twopass->gf_group.arf_src_offset[frame_index] = + gf_group->update_type[frame_index] = ARF_UPDATE; + gf_group->rf_level[frame_index] = GF_ARF_LOW; + gf_group->arf_src_offset[frame_index] = (unsigned char)((rc->baseline_gf_interval >> 1) - 1); - twopass->gf_group.arf_update_idx[frame_index] = arf_buffer_indices[1]; - twopass->gf_group.arf_ref_idx[frame_index] = arf_buffer_indices[0]; + gf_group->arf_update_idx[frame_index] = arf_buffer_indices[1]; + gf_group->arf_ref_idx[frame_index] = arf_buffer_indices[0]; ++frame_index; } } @@ -1469,16 +1464,16 @@ static void allocate_gf_group_bits(VP9_COMP *cpi, int64_t gf_group_bits, if (frame_index <= mid_frame_idx) arf_idx = 1; } - twopass->gf_group.arf_update_idx[frame_index] = arf_buffer_indices[arf_idx]; - twopass->gf_group.arf_ref_idx[frame_index] = arf_buffer_indices[arf_idx]; + gf_group->arf_update_idx[frame_index] = arf_buffer_indices[arf_idx]; + gf_group->arf_ref_idx[frame_index] = arf_buffer_indices[arf_idx]; target_frame_size = clamp(target_frame_size, 0, MIN(max_bits, (int)total_group_bits)); - twopass->gf_group.update_type[frame_index] = LF_UPDATE; - twopass->gf_group.rf_level[frame_index] = INTER_NORMAL; + gf_group->update_type[frame_index] = LF_UPDATE; + gf_group->rf_level[frame_index] = INTER_NORMAL; - twopass->gf_group.bit_allocation[frame_index] = target_frame_size; + gf_group->bit_allocation[frame_index] = target_frame_size; ++frame_index; } @@ -1486,23 +1481,23 @@ static void allocate_gf_group_bits(VP9_COMP *cpi, int64_t gf_group_bits, // We need to configure the frame at the end of the sequence + 1 that will be // the start frame for the next group. Otherwise prior to the call to // vp9_rc_get_second_pass_params() the data will be undefined. - twopass->gf_group.arf_update_idx[frame_index] = arf_buffer_indices[0]; - twopass->gf_group.arf_ref_idx[frame_index] = arf_buffer_indices[0]; + gf_group->arf_update_idx[frame_index] = arf_buffer_indices[0]; + gf_group->arf_ref_idx[frame_index] = arf_buffer_indices[0]; if (rc->source_alt_ref_pending) { - twopass->gf_group.update_type[frame_index] = OVERLAY_UPDATE; - twopass->gf_group.rf_level[frame_index] = INTER_NORMAL; + gf_group->update_type[frame_index] = OVERLAY_UPDATE; + gf_group->rf_level[frame_index] = INTER_NORMAL; // Final setup for second arf and its overlay. if (cpi->multi_arf_enabled) { - twopass->gf_group.bit_allocation[2] = - twopass->gf_group.bit_allocation[mid_frame_idx] + mid_boost_bits; - twopass->gf_group.update_type[mid_frame_idx] = OVERLAY_UPDATE; - twopass->gf_group.bit_allocation[mid_frame_idx] = 0; + gf_group->bit_allocation[2] = + gf_group->bit_allocation[mid_frame_idx] + mid_boost_bits; + gf_group->update_type[mid_frame_idx] = OVERLAY_UPDATE; + gf_group->bit_allocation[mid_frame_idx] = 0; } } else { - twopass->gf_group.update_type[frame_index] = GF_UPDATE; - twopass->gf_group.rf_level[frame_index] = GF_ARF_STD; + gf_group->update_type[frame_index] = GF_UPDATE; + gf_group->rf_level[frame_index] = GF_ARF_STD; } // Note whether multi-arf was enabled this group for next time. @@ -1828,6 +1823,7 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { int i, j; RATE_CONTROL *const rc = &cpi->rc; TWO_PASS *const twopass = &cpi->twopass; + GF_GROUP *const gf_group = &twopass->gf_group; const VP9EncoderConfig *const oxcf = &cpi->oxcf; const FIRSTPASS_STATS first_frame = *this_frame; const FIRSTPASS_STATS *const start_position = twopass->stats_in; @@ -1846,7 +1842,7 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { cpi->common.frame_type = KEY_FRAME; // Reset the GF group data structures. - vp9_zero(twopass->gf_group); + vp9_zero(*gf_group); // Is this a forced key frame by interval. rc->this_key_frame_forced = rc->next_key_frame_forced; @@ -2036,9 +2032,9 @@ static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { twopass->kf_group_bits -= kf_bits; // Save the bits to spend on the key frame. - twopass->gf_group.bit_allocation[0] = kf_bits; - twopass->gf_group.update_type[0] = KF_UPDATE; - twopass->gf_group.rf_level[0] = KF_STD; + gf_group->bit_allocation[0] = kf_bits; + gf_group->update_type[0] = KF_UPDATE; + gf_group->rf_level[0] = KF_STD; // Note the total error score of the kf group minus the key frame itself. twopass->kf_group_error_left = (int)(kf_group_err - kf_mod_err); @@ -2115,6 +2111,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { VP9_COMMON *const cm = &cpi->common; RATE_CONTROL *const rc = &cpi->rc; TWO_PASS *const twopass = &cpi->twopass; + GF_GROUP *const gf_group = &twopass->gf_group; int frames_left; FIRSTPASS_STATS this_frame; FIRSTPASS_STATS this_frame_copy; @@ -2136,10 +2133,10 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { // If this is an arf frame then we dont want to read the stats file or // advance the input pointer as we already have what we need. - if (twopass->gf_group.update_type[twopass->gf_group.index] == ARF_UPDATE) { + if (gf_group->update_type[gf_group->index] == ARF_UPDATE) { int target_rate; configure_buffer_updates(cpi); - target_rate = twopass->gf_group.bit_allocation[twopass->gf_group.index]; + target_rate = gf_group->bit_allocation[gf_group->index]; target_rate = vp9_rc_clamp_pframe_target_size(cpi, target_rate); rc->base_frame_target = target_rate; @@ -2237,7 +2234,7 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { configure_buffer_updates(cpi); - target_rate = twopass->gf_group.bit_allocation[twopass->gf_group.index]; + target_rate = gf_group->bit_allocation[gf_group->index]; if (cpi->common.frame_type == KEY_FRAME) target_rate = vp9_rc_clamp_iframe_target_size(cpi, target_rate); else 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/x86/vp9_dct_sse2.c b/vp9/encoder/x86/vp9_dct_sse2.c index 487deef42..b6bcdd94e 100644 --- a/vp9/encoder/x86/vp9_dct_sse2.c +++ b/vp9/encoder/x86/vp9_dct_sse2.c @@ -2891,11 +2891,11 @@ void vp9_fdct32x32_1_sse2(const int16_t *input, int16_t *output, int stride) { #define FDCT32x32_2D vp9_fdct32x32_rd_sse2 #define FDCT32x32_HIGH_PRECISION 0 #include "vp9/encoder/x86/vp9_dct32x32_sse2.c" -#undef FDCT32x32_2D #undef FDCT32x32_HIGH_PRECISION +#undef FDCT32x32_2D #define FDCT32x32_2D vp9_fdct32x32_sse2 #define FDCT32x32_HIGH_PRECISION 1 #include "vp9/encoder/x86/vp9_dct32x32_sse2.c" // NOLINT -#undef FDCT32x32_2D #undef FDCT32x32_HIGH_PRECISION +#undef FDCT32x32_2D diff --git a/vp9/vp9_cx_iface.c b/vp9/vp9_cx_iface.c index cdbb69b2d..08f68491d 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; @@ -334,17 +335,16 @@ static vpx_codec_err_t set_encoder_config( if (oxcf->init_framerate > 180) oxcf->init_framerate = 30; + oxcf->mode = BEST; + switch (cfg->g_pass) { case VPX_RC_ONE_PASS: - oxcf->mode = ONE_PASS_GOOD; oxcf->pass = 0; break; case VPX_RC_FIRST_PASS: - oxcf->mode = TWO_PASS_FIRST; oxcf->pass = 1; break; case VPX_RC_LAST_PASS: - oxcf->mode = TWO_PASS_SECOND_BEST; oxcf->pass = 2; break; } @@ -371,9 +371,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; @@ -718,31 +718,36 @@ static vpx_codec_err_t encoder_destroy(vpx_codec_alg_priv_t *ctx) { return VPX_CODEC_OK; } -static void pick_quickcompress_mode(vpx_codec_alg_priv_t *ctx, +static void pick_quickcompress_mode(vpx_codec_alg_priv_t *ctx, unsigned long duration, unsigned long deadline) { - // Use best quality mode if no deadline is given. - MODE new_qc = ONE_PASS_BEST; - - if (deadline) { - // Convert duration parameter from stream timebase to microseconds - const uint64_t duration_us = (uint64_t)duration * 1000000 * - (uint64_t)ctx->cfg.g_timebase.num / - (uint64_t)ctx->cfg.g_timebase.den; - - // If the deadline is more that the duration this frame is to be shown, - // use good quality mode. Otherwise use realtime mode. - new_qc = (deadline > duration_us) ? ONE_PASS_GOOD : REALTIME; - } + MODE new_mode = BEST; - if (ctx->cfg.g_pass == VPX_RC_FIRST_PASS) - new_qc = TWO_PASS_FIRST; - else if (ctx->cfg.g_pass == VPX_RC_LAST_PASS) - new_qc = (new_qc == ONE_PASS_BEST) ? TWO_PASS_SECOND_BEST - : TWO_PASS_SECOND_GOOD; + switch (ctx->cfg.g_pass) { + case VPX_RC_ONE_PASS: + if (deadline > 0) { + const vpx_codec_enc_cfg_t *const cfg = &ctx->cfg; + + // Convert duration parameter from stream timebase to microseconds. + const uint64_t duration_us = (uint64_t)duration * 1000000 * + (uint64_t)cfg->g_timebase.num /(uint64_t)cfg->g_timebase.den; + + // If the deadline is more that the duration this frame is to be shown, + // use good quality mode. Otherwise use realtime mode. + new_mode = (deadline > duration_us) ? GOOD : REALTIME; + } else { + new_mode = BEST; + } + break; + case VPX_RC_FIRST_PASS: + break; + case VPX_RC_LAST_PASS: + new_mode = deadline > 0 ? GOOD : BEST; + break; + } - if (ctx->oxcf.mode != new_qc) { - ctx->oxcf.mode = new_qc; + if (ctx->oxcf.mode != new_mode) { + ctx->oxcf.mode = new_mode; vp9_change_config(ctx->cpi, &ctx->oxcf); } } 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); @@ -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; @@ -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" |