diff options
29 files changed, 887 insertions, 385 deletions
diff --git a/build/make/gen_msvs_proj.sh b/build/make/gen_msvs_proj.sh index 5936370a7..df9143595 100755 --- a/build/make/gen_msvs_proj.sh +++ b/build/make/gen_msvs_proj.sh @@ -162,7 +162,8 @@ generate_filter() { done done fi - if [ "$pat" == "c" ] || [ "$pat" == "cc" ] ; then + if [ "$pat" == "c" ] || \ + [ "$pat" == "cc" ] || [ "$pat" == "cpp" ]; then for plat in "${platforms[@]}"; do for cfg in Debug Release; do open_tag FileConfiguration \ @@ -561,7 +562,7 @@ generate_vcproj() { close_tag Configurations open_tag Files - generate_filter srcs "Source Files" "c;cc;def;odl;idl;hpj;bat;asm;asmx" + generate_filter srcs "Source Files" "c;cc;cpp;def;odl;idl;hpj;bat;asm;asmx" generate_filter hdrs "Header Files" "h;hm;inl;inc;xsd" generate_filter resrcs "Resource Files" "rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav" generate_filter resrcs "Build Files" "mk" diff --git a/build/make/gen_msvs_vcxproj.sh b/build/make/gen_msvs_vcxproj.sh index 7c8871ba2..23990a413 100755 --- a/build/make/gen_msvs_vcxproj.sh +++ b/build/make/gen_msvs_vcxproj.sh @@ -174,7 +174,8 @@ generate_filter() { done done close_tag CustomBuild - elif [ "$pat" == "c" ] || [ "$pat" == "cc" ] ; then + elif [ "$pat" == "c" ] || \ + [ "$pat" == "cc" ] || [ "$pat" == "cpp" ]; then open_tag ClCompile \ Include=".\\$f" # Separate file names with Condition? @@ -524,7 +525,7 @@ generate_vcxproj() { done open_tag ItemGroup - generate_filter "Source Files" "c;cc;def;odl;idl;hpj;bat;asm;asmx;s" + generate_filter "Source Files" "c;cc;cpp;def;odl;idl;hpj;bat;asm;asmx;s" close_tag ItemGroup open_tag ItemGroup generate_filter "Header Files" "h;hm;inl;inc;xsd" diff --git a/examples.mk b/examples.mk index 87be5a8c9..fa5d66cda 100644 --- a/examples.mk +++ b/examples.mk @@ -70,7 +70,7 @@ vp9_spatial_scalable_encoder.SRCS += vpxstats.c vpxstats.h vp9_spatial_scalable_encoder.GUID = 4A38598D-627D-4505-9C7B-D4020C84100D vp9_spatial_scalable_encoder.DESCRIPTION = Spatial Scalable Encoder -ifeq ($(CONFIG_SHARED),no) +ifneq ($(CONFIG_SHARED),yes) EXAMPLES-$(CONFIG_VP9_ENCODER) += resize_util.c endif diff --git a/examples/vpx_temporal_scalable_patterns.c b/examples/vpx_temporal_scalable_patterns.c index 3a4f05b92..5cb4ee9cf 100644 --- a/examples/vpx_temporal_scalable_patterns.c +++ b/examples/vpx_temporal_scalable_patterns.c @@ -575,6 +575,7 @@ int main(int argc, char **argv) { } else if (strncmp(encoder->name, "vp9", 3) == 0) { vpx_codec_control(&codec, VP8E_SET_CPUUSED, speed); vpx_codec_control(&codec, VP9E_SET_AQ_MODE, 3); + vpx_codec_control(&codec, VP9E_SET_FRAME_PERIODIC_BOOST, 0); vpx_codec_control(&codec, VP8E_SET_NOISE_SENSITIVITY, 0); if (vpx_codec_control(&codec, VP9E_SET_SVC, 1)) { die_codec(&codec, "Failed to set SVC"); diff --git a/test/datarate_test.cc b/test/datarate_test.cc index 1b921f0a1..e8604a6d7 100644 --- a/test/datarate_test.cc +++ b/test/datarate_test.cc @@ -570,9 +570,9 @@ TEST_P(DatarateTestVP9Large, BasicRateTargeting3TemporalLayersFrameDropping) { << " The datarate for the file is greater than target by too much, " "for layer: " << j; // Expect some frame drops in this test: for this 200 frames test, - // expect at least 10% and not more than 50% drops. + // expect at least 10% and not more than 60% drops. ASSERT_GE(num_drops_, 20); - ASSERT_LE(num_drops_, 100); + ASSERT_LE(num_drops_, 120); } } @@ -580,8 +580,5 @@ VP8_INSTANTIATE_TEST_CASE(DatarateTestLarge, ALL_TEST_MODES); VP9_INSTANTIATE_TEST_CASE(DatarateTestVP9Large, ::testing::Values(::libvpx_test::kOnePassGood, ::libvpx_test::kRealTime), - ::testing::Range(2, 5)); -// TODO(marpan): Speed 5 to 7 fails on one of these tests, for -// real-time mode. So for now test up to speed 4, and start at 2 -// (since speed 0 and 1 are slow). Enable more speeds when issue is fixed. + ::testing::Range(2, 7)); } // namespace diff --git a/test/tools_common.sh b/test/tools_common.sh new file mode 100755 index 000000000..cd7977156 --- /dev/null +++ b/test/tools_common.sh @@ -0,0 +1,437 @@ +#!/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 contains shell code shared by test scripts for libvpx tools. +set -e + +# Sets $VPX_TOOL_TEST to the name specified by positional parameter one. +test_begin() { + VPX_TOOL_TEST="${1}" +} + +# Clears the VPX_TOOL_TEST variable after confirming that $VPX_TOOL_TEST matches +# positional parameter one. +test_end() { + if [ "$1" != "${VPX_TOOL_TEST}" ]; then + echo "FAIL completed test mismatch!." + echo " completed test: ${1}" + echo " active test: ${VPX_TOOL_TEST}." + return 1 + fi + VPX_TOOL_TEST='<unset>' +} + +# Echoes the target configuration being tested. +test_configuration_target() { + vpx_config_mk="${LIBVPX_CONFIG_PATH}/config.mk" + # Find the TOOLCHAIN line, split it using ':=' as the field separator, and + # print the last field to get the value. Then pipe the value to tr to consume + # any leading/trailing spaces while allowing tr to echo the output to stdout. + awk -F ':=' '/TOOLCHAIN/ { print $NF }' "${vpx_config_mk}" | tr -d ' ' +} + +# Trap function used for failure reports and tool output directory removal. +# When the contents of $VPX_TOOL_TEST do not match the string '<unset>', reports +# failure of test stored in $VPX_TOOL_TEST. +cleanup() { + if [ -n "${VPX_TOOL_TEST}" ] && [ "${VPX_TOOL_TEST}" != '<unset>' ]; then + echo "FAIL: $VPX_TOOL_TEST" + fi + if [ -n "${VPX_TEST_OUTPUT_DIR}" ] && [ -d "${VPX_TEST_OUTPUT_DIR}" ]; then + rm -rf "${VPX_TEST_OUTPUT_DIR}" + fi +} + +# Echoes the git hash portion of the VERSION_STRING variable defined in +# $LIBVPX_CONFIG_PATH/config.mk to stdout, or the version number string when +# no git hash is contained in VERSION_STRING. +config_hash() { + vpx_config_mk="${LIBVPX_CONFIG_PATH}/config.mk" + # Find VERSION_STRING line, split it with "-g" and print the last field to + # output the git hash to stdout. + vpx_version=$(awk -F -g '/VERSION_STRING/ {print $NF}' "${vpx_config_mk}") + # Handle two situations here: + # 1. The default case: $vpx_version is a git hash, so echo it unchanged. + # 2. When being run a non-dev tree, the -g portion is not present in the + # version string: It's only the version number. + # In this case $vpx_version is something like 'VERSION_STRING=v1.3.0', so + # we echo only what is after the '='. + echo "${vpx_version##*=}" +} + +# Echoes the short form of the current git hash. +current_hash() { + if git --version > /dev/null 2>&1; then + (cd "$(dirname "${0}")" + git rev-parse --short HEAD) + else + # Return the config hash if git is unavailable: Fail silently, git hashes + # are used only for warnings. + config_hash + fi +} + +# Echoes warnings to stdout when git hash in vpx_config.h does not match the +# current git hash. +check_git_hashes() { + hash_at_configure_time=$(config_hash) + hash_now=$(current_hash) + + if [ "${hash_at_configure_time}" != "${hash_now}" ]; then + echo "Warning: git hash has changed since last configure." + fi +} + +# This script requires that the LIBVPX_BIN_PATH, LIBVPX_CONFIG_PATH, and +# LIBVPX_TEST_DATA_PATH variables are in the environment: Confirm that +# the variables are set and that they all evaluate to directory paths. +verify_vpx_test_environment() { + if [ ! -d "${LIBVPX_BIN_PATH}" ]; then + echo "The LIBVPX_BIN_PATH environment variable must be set." + return 1 + fi + if [ ! -d "${LIBVPX_CONFIG_PATH}" ]; then + echo "The LIBVPX_CONFIG_PATH environment variable must be set." + return 1 + fi + if [ ! -d "${LIBVPX_TEST_DATA_PATH}" ]; then + echo "The LIBVPX_TEST_DATA_PATH environment variable must be set." + return 1 + fi +} + +# Greps vpx_config.h in LIBVPX_CONFIG_PATH for positional parameter one, which +# should be a LIBVPX preprocessor flag. Echoes yes to stdout when the feature +# is available. +vpx_config_option_enabled() { + vpx_config_option="${1}" + vpx_config_file="${LIBVPX_CONFIG_PATH}/vpx_config.h" + config_line=$(grep "${vpx_config_option}" "${vpx_config_file}") + if echo "${config_line}" | egrep -q '1$'; then + echo yes + fi +} + +# Echoes yes when output of test_configuration_target() contains win32 or win64. +is_windows_target() { + if test_configuration_target \ + | grep -q -e win32 -e win64 > /dev/null 2>&1; then + echo yes + fi +} + +# Echoes yes to stdout when the file named by positional parameter one exists +# in LIBVPX_BIN_PATH, and is executable. +vpx_tool_available() { + tool_name="${1}" + if [ "$(is_windows_target)" = "yes" ]; then + tool_name="${tool_name}.exe" + fi + [ -x "${LIBVPX_BIN_PATH}/${1}" ] && echo yes +} + +# Echoes yes to stdout when vpx_config_option_enabled() reports yes for +# CONFIG_VP8_DECODER. +vp8_decode_available() { + [ "$(vpx_config_option_enabled CONFIG_VP8_DECODER)" = "yes" ] && echo yes +} + +# Echoes yes to stdout when vpx_config_option_enabled() reports yes for +# CONFIG_VP8_ENCODER. +vp8_encode_available() { + [ "$(vpx_config_option_enabled CONFIG_VP8_ENCODER)" = "yes" ] && echo yes +} + +# Echoes yes to stdout when vpx_config_option_enabled() reports yes for +# CONFIG_VP9_DECODER. +vp9_decode_available() { + [ "$(vpx_config_option_enabled CONFIG_VP9_DECODER)" = "yes" ] && echo yes +} + +# Echoes yes to stdout when vpx_config_option_enabled() reports yes for +# CONFIG_VP9_ENCODER. +vp9_encode_available() { + [ "$(vpx_config_option_enabled CONFIG_VP9_ENCODER)" = "yes" ] && echo yes +} + +# Echoes yes to stdout when vpx_config_option_enabled() reports yes for +# CONFIG_WEBM_IO. +webm_io_available() { + [ "$(vpx_config_option_enabled CONFIG_WEBM_IO)" = "yes" ] && echo yes +} + +# Echoes yes to stdout when vpxdec exists according to vpx_tool_available(). +vpxdec_available() { + [ -n $(vpx_tool_available vpxdec) ] && echo yes +} + +# Wrapper function for running vpxdec in noblit mode. Requires that +# LIBVPX_BIN_PATH points to the directory containing vpxdec. Positional +# parameter one is used as the input file path. Positional parameter two, when +# present, is interpreted as a boolean flag that means the input should be sent +# to vpxdec via pipe from cat instead of directly. +vpxdec() { + input="${1}" + pipe_input=${2} + + if [ $# -gt 2 ]; then + # shift away $1 and $2 so the remaining arguments can be passed to vpxdec + # via $@. + shift 2 + fi + + decoder="${LIBVPX_BIN_PATH}/vpxdec" + + if [ "$(is_windows_target)" = "yes" ]; then + decoder="${decoder}.exe" + fi + + if [ -z "${pipe_input}" ]; then + "${decoder}" "$input" --summary --noblit "$@" > /dev/null 2>&1 + else + cat "${input}" | "${decoder}" - --summary --noblit "$@" > /dev/null 2>&1 + fi +} + +# Echoes yes to stdout when vpxenc exists according to vpx_tool_available(). +vpxenc_available() { + [ -n $(vpx_tool_available vpxenc) ] && echo yes +} + +# Wrapper function for running vpxenc. Positional parameters are interpreted as +# follows: +# 1 - codec name +# 2 - input width +# 3 - input height +# 4 - number of frames to encode +# 5 - path to input file +# 6 - path to output file +# Note: The output file path must end in .ivf to output an IVF file. +# 7 - extra flags +# Note: Extra flags currently supports a special case: when set to "-" +# input is piped to vpxenc via cat. +vpxenc() { + encoder="${LIBVPX_BIN_PATH}/vpxenc" + codec="${1}" + width=${2} + height=${3} + frames=${4} + input=${5} + output="${VPX_TEST_OUTPUT_DIR}/${6}" + extra_flags=${7} + + if [ "$(is_windows_target)" = "yes" ]; then + encoder="${encoder}.exe" + fi + + # Because --ivf must be within the command line to get IVF from vpxenc. + if echo "${output}" | egrep -q 'ivf$'; then + use_ivf=--ivf + else + unset use_ivf + fi + + if [ "${extra_flags}" = "-" ]; then + pipe_input=yes + extra_flags=${8} + else + unset pipe_input + fi + + if [ -z "${pipe_input}" ]; then + "${encoder}" --codec=${codec} --width=${width} --height=${height} \ + --limit=${frames} ${use_ivf} ${extra_flags} --output="${output}" \ + "${input}" > /dev/null 2>&1 + else + cat "${input}" \ + | "${encoder}" --codec=${codec} --width=${width} --height=${height} \ + --limit=${frames} ${use_ivf} ${extra_flags} --output="${output}" - \ + > /dev/null 2>&1 + fi + + if [ ! -e "${output}" ]; then + # Return non-zero exit status: output file doesn't exist, so something + # definitely went wrong. + return 1 + fi +} + +# Filters strings from positional parameter one using the filter specified by +# positional parameter two. Filter behavior depends on the presence of a third +# positional parameter. When parameter three is present, strings that match the +# filter are excluded. When omitted, strings matching the filter are included. +# The filtered string is echoed to stdout. +filter_strings() { + strings=${1} + filter=${2} + exclude=${3} + + if [ -n "${exclude}" ]; then + # When positional parameter three exists the caller wants to remove strings. + # Tell grep to invert matches using the -v argument. + exclude='-v' + else + unset exclude + fi + + if [ -n "${filter}" ]; then + for s in ${strings}; do + if echo "${s}" | egrep -q ${exclude} "${filter}" > /dev/null 2>&1; then + filtered_strings="${filtered_strings} ${s}" + fi + done + else + filtered_strings="${strings}" + fi + echo "${filtered_strings}" +} + +# Runs user test functions passed via positional parameters one and two. +# Functions in positional parameter one are treated as environment verification +# functions and are run unconditionally. Functions in positional parameter two +# are run according to the rules specified in vpx_test_usage(). +run_tests() { + env_tests="verify_vpx_test_environment ${1}" + tests_to_filter="${2}" + + if [ "${VPX_TEST_RUN_DISABLED_TESTS}" != "yes" ]; then + # Filter out DISABLED tests. + tests_to_filter=$(filter_strings "${tests_to_filter}" ^DISABLED exclude) + fi + + if [ -n "${VPX_TEST_FILTER}" ]; then + # Remove tests not matching the user's filter. + tests_to_filter=$(filter_strings "${tests_to_filter}" ${VPX_TEST_FILTER}) + fi + + tests_to_run="${env_tests} ${tests_to_filter}" + + check_git_hashes + + # Run tests. + for test in ${tests_to_run}; do + test_begin "${test}" + "${test}" + [ "${VPX_TEST_VERBOSE_OUTPUT}" = "yes" ] && echo " PASS ${test}" + test_end "${test}" + done + + tested_config="$(test_configuration_target) @ $(current_hash)" + echo $(basename "${0%.*}"): Done, all tests pass for ${tested_config}. +} + +vpx_test_usage() { +cat << EOF + Usage: ${0##*/} [arguments] + --bin-path <path to libvpx binaries directory> + --config-path <path to libvpx config directory> + --filter <filter>: User test filter. Only tests matching filter are run. + --run-disabled-tests: Run disabled tests. + --help: Display this message and exit. + --test-data-path <path to libvpx test data directory> + --verbose: Verbose output. + + When the --bin-path option is not specified the script attempts to use + \$LIBVPX_BIN_PATH and then the current directory. + + When the --config-path option is not specified the script attempts to use + \$LIBVPX_CONFIG_PATH and then the current directory. + + When the -test-data-path option is not specified the script attempts to use + \$LIBVPX_TEST_DATA_PATH and then the current directory. +EOF +} + +# Returns non-zero (failure) when required environment variables are empty +# strings. +vpx_test_check_environment() { + if [ -z "${LIBVPX_BIN_PATH}" ] || \ + [ -z "${LIBVPX_CONFIG_PATH}" ] || \ + [ -z "${LIBVPX_TEST_DATA_PATH}" ]; then + return 1 + fi +} + +# Parse the command line. +while [ -n "$1" ]; do + case "$1" in + --bin-path) + LIBVPX_BIN_PATH="$2" + shift + ;; + --config-path) + LIBVPX_CONFIG_PATH="$2" + shift + ;; + --filter) + VPX_TEST_FILTER="$2" + shift + ;; + --run-disabled-tests) + VPX_TEST_RUN_DISABLED_TESTS=yes + ;; + --help) + vpx_test_usage + exit + ;; + --test-data-path) + LIBVPX_TEST_DATA_PATH="$2" + shift + ;; + --verbose) + VPX_TEST_VERBOSE_OUTPUT=yes + ;; + *) + vpx_test_usage + exit 1 + ;; + esac + shift +done + +# Handle running the tests from a build directory without arguments when running +# the tests on *nix/macosx. +LIBVPX_BIN_PATH="${LIBVPX_BIN_PATH:-.}" +LIBVPX_CONFIG_PATH="${LIBVPX_CONFIG_PATH:-.}" +LIBVPX_TEST_DATA_PATH="${LIBVPX_TEST_DATA_PATH:-.}" + +# Create a temporary directory for output files, and a trap to clean it up. +if [ -n "${TMPDIR}" ]; then + VPX_TEST_TEMP_ROOT="${TMPDIR}" +elif [ -n "${TEMPDIR}" ]; then + VPX_TEST_TEMP_ROOT="${TEMPDIR}" +else + VPX_TEST_TEMP_ROOT=/tmp +fi + +VPX_TEST_RAND=$(awk 'BEGIN { srand(); printf "%d\n",(rand() * 32768)}') +VPX_TEST_OUTPUT_DIR="${VPX_TEST_TEMP_ROOT}/vpx_test_${VPX_TEST_RAND}" + +if ! mkdir -p "${VPX_TEST_OUTPUT_DIR}" || \ + [ ! -d "${VPX_TEST_OUTPUT_DIR}" ]; then + echo "${0##*/}: Cannot create output directory, giving up." + echo "${0##*/}: VPX_TEST_OUTPUT_DIR=${VPX_TEST_OUTPUT_DIR}" + exit 1 +fi + +trap cleanup EXIT + +if [ "${VPX_TEST_VERBOSE_OUTPUT}" = "yes" ]; then +cat << EOF +$(basename "${0%.*}") test configuration: + LIBVPX_BIN_PATH=${LIBVPX_BIN_PATH} + LIBVPX_CONFIG_PATH=${LIBVPX_CONFIG_PATH} + LIBVPX_TEST_DATA_PATH=${LIBVPX_TEST_DATA_PATH} + VPX_TEST_OUTPUT_DIR=${VPX_TEST_OUTPUT_DIR} + VPX_TEST_VERBOSE_OUTPUT=${VPX_TEST_VERBOSE_OUTPUT} + VPX_TEST_FILTER=${VPX_TEST_FILTER} + VPX_TEST_RUN_DISABLED_TESTS=${VPX_TEST_RUN_DISABLED_TESTS} +EOF +fi diff --git a/test/vpxdec.sh b/test/vpxdec.sh new file mode 100755 index 000000000..d236f973b --- /dev/null +++ b/test/vpxdec.sh @@ -0,0 +1,65 @@ +#!/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 vpxdec. To add new tests to this file, do the following: +## 1. Write a shell function (this is your test). +## 2. Add the function to vpxdec_tests (on a new line). +## +. $(dirname $0)/tools_common.sh + +VP8_IVF_FILE="${LIBVPX_TEST_DATA_PATH}/vp80-00-comprehensive-001.ivf" +VP9_WEBM_FILE="${LIBVPX_TEST_DATA_PATH}/vp90-2-00-quantizer-00.webm" + +# Environment check: Make sure input is available. +vpxdec_verify_environment() { + if [ ! -e "${VP8_IVF_FILE}" ] || [ ! -e "${VP9_WEBM_FILE}" ]; then + echo "Libvpx test data must exist in LIBVPX_TEST_DATA_PATH." + return 1 + fi +} + +vpxdec_can_decode_vp8() { + if [ "$(vpxdec_available)" = "yes" ] && \ + [ "$(vp8_decode_available)" = "yes" ]; then + echo yes + fi +} + +vpxdec_can_decode_vp9() { + if [ "$(vpxdec_available)" = "yes" ] && \ + [ "$(vp9_decode_available)" = "yes" ]; then + echo yes + fi +} + +vpxdec_vp8_ivf() { + if [ "$(vpxdec_can_decode_vp8)" = "yes" ]; then + vpxdec "${VP8_IVF_FILE}" + fi +} + +vpxdec_vp8_ivf_pipe_input() { + if [ "$(vpxdec_can_decode_vp8)" = "yes" ]; then + vpxdec "${VP8_IVF_FILE}" - + fi +} + +vpxdec_vp9_webm() { + if [ "$(vpxdec_can_decode_vp9)" = "yes" ] && \ + [ "$(webm_io_available)" = "yes" ]; then + vpxdec "${VP9_WEBM_FILE}" + fi +} + +vpxdec_tests="vpxdec_vp8_ivf + vpxdec_vp8_ivf_pipe_input + vpxdec_vp9_webm" + +run_tests vpxdec_verify_environment "${vpxdec_tests}" diff --git a/test/vpxenc.sh b/test/vpxenc.sh new file mode 100755 index 000000000..89e4eb39c --- /dev/null +++ b/test/vpxenc.sh @@ -0,0 +1,96 @@ +#!/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 vpxenc using hantro_collage_w352h288.yuv as input. To add +## new tests to this file, do the following: +## 1. Write a shell function (this is your test). +## 2. Add the function to vpxenc_tests (on a new line). +## +. $(dirname $0)/tools_common.sh + +YUV_RAW_INPUT="${LIBVPX_TEST_DATA_PATH}/hantro_collage_w352h288.yuv" +YUV_RAW_INPUT_WIDTH=352 +YUV_RAW_INPUT_HEIGHT=288 +TEST_FRAMES=10 + +# Environment check: Make sure input is available. +vpxenc_verify_environment() { + if [ ! -e "${YUV_RAW_INPUT}" ]; then + echo "The file ${YUV_RAW_INPUT##*/} must exist in LIBVPX_TEST_DATA_PATH." + return 1 + fi +} + +vpxenc_can_encode_vp8() { + if [ "$(vpxenc_available)" = "yes" ] && \ + [ "$(vp8_encode_available)" = "yes" ]; then + echo yes + fi +} + +vpxenc_can_encode_vp9() { + if [ "$(vpxenc_available)" = "yes" ] && \ + [ "$(vp9_encode_available)" = "yes" ]; then + echo yes + fi +} + +vpxenc_vp8_ivf() { + if [ "$(vpxenc_can_encode_vp8)" = "yes" ]; then + vpxenc vp8 ${YUV_RAW_INPUT_WIDTH} ${YUV_RAW_INPUT_HEIGHT} ${TEST_FRAMES} \ + "${YUV_RAW_INPUT}" vp8.ivf + fi +} + +vpxenc_vp8_ivf_pipe_input() { + if [ "$(vpxenc_can_encode_vp8)" = "yes" ]; then + vpxenc vp8 ${YUV_RAW_INPUT_WIDTH} ${YUV_RAW_INPUT_HEIGHT} ${TEST_FRAMES} \ + "${YUV_RAW_INPUT}" vp8.ivf - + fi +} + +vpxenc_vp8_webm() { + if [ "$(vpxenc_can_encode_vp8)" = "yes" ] && + [ "$(webm_io_available)" = "yes" ] ; then + vpxenc vp8 ${YUV_RAW_INPUT_WIDTH} ${YUV_RAW_INPUT_HEIGHT} ${TEST_FRAMES} \ + "${YUV_RAW_INPUT}" vp8.webm + fi +} + +vpxenc_vp9_ivf() { + if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then + vpxenc vp9 ${YUV_RAW_INPUT_WIDTH} ${YUV_RAW_INPUT_HEIGHT} ${TEST_FRAMES} \ + "${YUV_RAW_INPUT}" vp9.ivf + fi +} + +vpxenc_vp9_webm() { + if [ "$(vpxenc_can_encode_vp9)" = "yes" ] && + [ "$(webm_io_available)" = "yes" ] ; then + vpxenc vp9 ${YUV_RAW_INPUT_WIDTH} ${YUV_RAW_INPUT_HEIGHT} ${TEST_FRAMES} \ + "${YUV_RAW_INPUT}" vp9.webm + fi +} + +DISABLED_vpxenc_vp9_ivf_lossless() { + if [ "$(vpxenc_can_encode_vp9)" = "yes" ]; then + vpxenc vp9 ${YUV_RAW_INPUT_WIDTH} ${YUV_RAW_INPUT_HEIGHT} ${TEST_FRAMES} \ + "${YUV_RAW_INPUT}" vp9_lossless.ivf --lossless + fi +} + +vpxenc_tests="vpxenc_vp8_ivf + vpxenc_vp8_webm + vpxenc_vp8_ivf_pipe_input + vpxenc_vp9_ivf + vpxenc_vp9_webm + DISABLED_vpxenc_vp9_ivf_lossless" + +run_tests vpxenc_verify_environment "${vpxenc_tests}" diff --git a/tools_common.h b/tools_common.h index 58894def0..549e895ec 100644 --- a/tools_common.h +++ b/tools_common.h @@ -22,10 +22,12 @@ #endif #if defined(_MSC_VER) -/* MSVS doesn't define off_t, and uses _f{seek,tell}i64. */ -typedef __int64 off_t; +/* MSVS uses _f{seek,tell}i64. */ #define fseeko _fseeki64 #define ftello _ftelli64 +typedef long _off_t; // NOLINT - MSVS compatible type +typedef __int64 off_t; // fseeki64 compatible type +#define _OFF_T_DEFINED #elif defined(_WIN32) /* MinGW defines off_t as long and uses f{seek,tell}o64/off64_t for large * files. */ diff --git a/vp8/common/loopfilter.c b/vp8/common/loopfilter.c index 19857a7e9..7a07e76fc 100644 --- a/vp8/common/loopfilter.c +++ b/vp8/common/loopfilter.c @@ -15,7 +15,6 @@ #include "onyxc_int.h" #include "vpx_mem/vpx_mem.h" -typedef unsigned char uc; static void lf_init_lut(loop_filter_info_n *lfi) { diff --git a/vp9/common/vp9_blockd.h b/vp9/common/vp9_blockd.h index 1f7e6329d..55320a6a4 100644 --- a/vp9/common/vp9_blockd.h +++ b/vp9/common/vp9_blockd.h @@ -231,8 +231,6 @@ typedef struct macroblockd { /* Inverse transform function pointers. */ void (*itxm_add)(const int16_t *input, uint8_t *dest, int stride, int eob); - const InterpKernel *interp_kernel; - int corrupted; DECLARE_ALIGNED(16, int16_t, dqcoeff[MAX_MB_PLANE][64 * 64]); diff --git a/vp9/common/vp9_reconinter.c b/vp9/common/vp9_reconinter.c index 0ab50d456..e722d6a3e 100644 --- a/vp9/common/vp9_reconinter.c +++ b/vp9/common/vp9_reconinter.c @@ -146,6 +146,7 @@ static void build_inter_predictors(MACROBLOCKD *xd, int plane, int block, struct macroblockd_plane *const pd = &xd->plane[plane]; const MODE_INFO *mi = xd->mi[0]; const int is_compound = has_second_ref(&mi->mbmi); + const InterpKernel *kernel = vp9_get_interp_kernel(mi->mbmi.interp_filter); int ref; for (ref = 0; ref < 1 + is_compound; ++ref) { @@ -193,8 +194,7 @@ static void build_inter_predictors(MACROBLOCKD *xd, int plane, int block, + (scaled_mv.col >> SUBPEL_BITS); inter_predictor(pre, pre_buf->stride, dst, dst_buf->stride, - subpel_x, subpel_y, sf, w, h, ref, xd->interp_kernel, - xs, ys); + subpel_x, subpel_y, sf, w, h, ref, kernel, xs, ys); } } @@ -250,6 +250,7 @@ static void dec_build_inter_predictors(MACROBLOCKD *xd, int plane, int block, struct macroblockd_plane *const pd = &xd->plane[plane]; const MODE_INFO *mi = xd->mi[0]; const int is_compound = has_second_ref(&mi->mbmi); + const InterpKernel *kernel = vp9_get_interp_kernel(mi->mbmi.interp_filter); int ref; for (ref = 0; ref < 1 + is_compound; ++ref) { @@ -377,7 +378,7 @@ static void dec_build_inter_predictors(MACROBLOCKD *xd, int plane, int block, } inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x, - subpel_y, sf, w, h, ref, xd->interp_kernel, xs, ys); + subpel_y, sf, w, h, ref, kernel, xs, ys); } } diff --git a/vp9/decoder/vp9_decodeframe.c b/vp9/decoder/vp9_decodeframe.c index 53f94f848..5a2e6f881 100644 --- a/vp9/decoder/vp9_decodeframe.c +++ b/vp9/decoder/vp9_decodeframe.c @@ -360,8 +360,6 @@ static void decode_block(VP9_COMMON *const cm, MACROBLOCKD *const xd, if (has_second_ref(mbmi)) set_ref(cm, xd, 1, mi_row, mi_col); - xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter); - // Prediction vp9_dec_build_inter_predictors_sb(xd, mi_row, mi_col, bsize); diff --git a/vp9/decoder/vp9_decoder.c b/vp9/decoder/vp9_decoder.c index c954a5d0e..b3e3f9c15 100644 --- a/vp9/decoder/vp9_decoder.c +++ b/vp9/decoder/vp9_decoder.c @@ -422,19 +422,12 @@ int vp9_get_raw_frame(VP9D_COMP *pbi, YV12_BUFFER_CONFIG *sd, #if CONFIG_VP9_POSTPROC ret = vp9_post_proc_frame(&pbi->common, sd, flags); #else - - if (pbi->common.frame_to_show) { *sd = *pbi->common.frame_to_show; sd->y_width = pbi->common.width; sd->y_height = pbi->common.height; sd->uv_width = sd->y_width >> pbi->common.subsampling_x; sd->uv_height = sd->y_height >> pbi->common.subsampling_y; - ret = 0; - } else { - ret = -1; - } - #endif /*!CONFIG_POSTPROC*/ vp9_clear_system_state(); return ret; diff --git a/vp9/encoder/vp9_bitstream.c b/vp9/encoder/vp9_bitstream.c index 7c811e2a3..4313418d4 100644 --- a/vp9/encoder/vp9_bitstream.c +++ b/vp9/encoder/vp9_bitstream.c @@ -484,12 +484,12 @@ static void write_modes(VP9_COMP *cpi, } } -static void build_tree_distribution(VP9_COMP *cpi, TX_SIZE tx_size) { +static void build_tree_distribution(VP9_COMP *cpi, TX_SIZE tx_size, + vp9_coeff_stats *coef_branch_ct) { vp9_coeff_probs_model *coef_probs = cpi->frame_coef_probs[tx_size]; vp9_coeff_count *coef_counts = cpi->coef_counts[tx_size]; unsigned int (*eob_branch_ct)[REF_TYPES][COEF_BANDS][COEFF_CONTEXTS] = cpi->common.counts.eob_branch[tx_size]; - vp9_coeff_stats *coef_branch_ct = cpi->frame_branch_ct[tx_size]; int i, j, k, l, m; for (i = 0; i < PLANE_TYPES; ++i) { @@ -512,16 +512,16 @@ static void build_tree_distribution(VP9_COMP *cpi, TX_SIZE tx_size) { } static void update_coef_probs_common(vp9_writer* const bc, VP9_COMP *cpi, - TX_SIZE tx_size) { + TX_SIZE tx_size, + vp9_coeff_stats *frame_branch_ct) { vp9_coeff_probs_model *new_frame_coef_probs = cpi->frame_coef_probs[tx_size]; vp9_coeff_probs_model *old_frame_coef_probs = cpi->common.fc.coef_probs[tx_size]; - vp9_coeff_stats *frame_branch_ct = cpi->frame_branch_ct[tx_size]; const vp9_prob upd = DIFF_UPDATE_PROB; const int entropy_nodes_update = UNCONSTRAINED_NODES; int i, j, k, l, t; switch (cpi->sf.use_fast_coef_updates) { - case 0: { + case TWO_LOOP: { /* dry run to see if there is any udpate at all needed */ int savings = 0; int update[2] = {0, 0}; @@ -596,14 +596,14 @@ static void update_coef_probs_common(vp9_writer* const bc, VP9_COMP *cpi, return; } - case 1: - case 2: { + case ONE_LOOP: + case ONE_LOOP_REDUCED: { const int prev_coef_contexts_to_update = - cpi->sf.use_fast_coef_updates == 2 ? COEFF_CONTEXTS >> 1 - : COEFF_CONTEXTS; + cpi->sf.use_fast_coef_updates == ONE_LOOP_REDUCED ? + COEFF_CONTEXTS >> 1 : COEFF_CONTEXTS; const int coef_band_to_update = - cpi->sf.use_fast_coef_updates == 2 ? COEF_BANDS >> 1 - : COEF_BANDS; + cpi->sf.use_fast_coef_updates == ONE_LOOP_REDUCED ? + COEF_BANDS >> 1 : COEF_BANDS; int updates = 0; int noupdates_before_first = 0; for (i = 0; i < PLANE_TYPES; ++i) { @@ -669,13 +669,15 @@ static void update_coef_probs(VP9_COMP *cpi, vp9_writer* w) { const TX_MODE tx_mode = cpi->common.tx_mode; const TX_SIZE max_tx_size = tx_mode_to_biggest_tx_size[tx_mode]; TX_SIZE tx_size; + vp9_coeff_stats frame_branch_ct[TX_SIZES][PLANE_TYPES]; + vp9_clear_system_state(); for (tx_size = TX_4X4; tx_size <= TX_32X32; ++tx_size) - build_tree_distribution(cpi, tx_size); + build_tree_distribution(cpi, tx_size, frame_branch_ct[tx_size]); for (tx_size = TX_4X4; tx_size <= max_tx_size; ++tx_size) - update_coef_probs_common(w, cpi, tx_size); + update_coef_probs_common(w, cpi, tx_size, frame_branch_ct[tx_size]); } static void encode_loopfilter(struct loopfilter *lf, diff --git a/vp9/encoder/vp9_encodeframe.c b/vp9/encoder/vp9_encodeframe.c index 42e1ac88f..67b8b0292 100644 --- a/vp9/encoder/vp9_encodeframe.c +++ b/vp9/encoder/vp9_encodeframe.c @@ -856,13 +856,22 @@ static void update_state(VP9_COMP *cpi, PICK_MODE_CONTEXT *ctx, *mi_addr = *mi; - // For in frame adaptive Q, check for reseting the segment_id and updating - // the cyclic refresh map. - if ((cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) && seg->enabled && - output_enabled) { - vp9_cyclic_refresh_update_segment(cpi, &xd->mi[0]->mbmi, - mi_row, mi_col, bsize, 1); - vp9_init_plane_quantizers(cpi, x); + // If segmentation in use + if (seg->enabled && output_enabled) { + // For in frame complexity AQ copy the segment id from the segment map. + if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { + const uint8_t *const map = seg->update_map ? cpi->segmentation_map + : cm->last_frame_seg_map; + mi_addr->mbmi.segment_id = + vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); + } + // Else for cyclic refresh mode update the segment map, set the segment id + // and then update the quantizer. + else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { + vp9_cyclic_refresh_update_segment(cpi, &xd->mi[0]->mbmi, + mi_row, mi_col, bsize, 1); + vp9_init_plane_quantizers(cpi, x); + } } max_plane = is_inter_block(mbmi) ? MAX_MB_PLANE : 1; @@ -3430,7 +3439,6 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled, } } else { set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); - xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter); if (cpi->oxcf.tuning == VP8_TUNE_SSIM) { // Adjust the zbin based on this MB rate. diff --git a/vp9/encoder/vp9_firstpass.c b/vp9/encoder/vp9_firstpass.c index 7ec52556e..26fc28004 100644 --- a/vp9/encoder/vp9_firstpass.c +++ b/vp9/encoder/vp9_firstpass.c @@ -61,6 +61,8 @@ #define MIN_GF_INTERVAL 4 #endif +#define DISABLE_RC_LONG_TERM_MEM + static void swap_yv12(YV12_BUFFER_CONFIG *a, YV12_BUFFER_CONFIG *b) { YV12_BUFFER_CONFIG temp = *a; *a = *b; @@ -2330,7 +2332,11 @@ void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { } void vp9_twopass_postencode_update(VP9_COMP *cpi) { +#ifdef DISABLE_RC_LONG_TERM_MEM + const uint64_t bits_used = cpi->rc.this_frame_target; +#else const uint64_t bits_used = cpi->rc.projected_frame_size; +#endif cpi->twopass.bits_left -= bits_used; cpi->twopass.bits_left = MAX(cpi->twopass.bits_left, 0); // Update bits left to the kf and gf groups to account for overshoot or diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c index f8427cffd..f4a6e6d4c 100644 --- a/vp9/encoder/vp9_onyx_if.c +++ b/vp9/encoder/vp9_onyx_if.c @@ -782,6 +782,26 @@ static void init_rate_control(const VP9_CONFIG *oxcf, int pass, rc->total_actual_bits = 0; rc->total_target_vs_actual = 0; + + rc->baseline_gf_interval = DEFAULT_GF_INTERVAL; + rc->frames_since_key = 8; // Sensible default for first frame. + rc->this_key_frame_forced = 0; + rc->next_key_frame_forced = 0; + rc->source_alt_ref_pending = 0; + rc->source_alt_ref_active = 0; + + rc->frames_till_gf_update_due = 0; + + rc->ni_av_qi = oxcf->worst_allowed_q; + rc->ni_tot_qi = 0; + rc->ni_frames = 0; + + rc->tot_q = 0.0; + rc->avg_q = vp9_convert_qindex_to_q(oxcf->worst_allowed_q); + + rc->rate_correction_factor = 1.0; + rc->key_frame_rate_correction_factor = 1.0; + rc->gf_rate_correction_factor = 1.0; } static void init_config(struct VP9_COMP *cpi, VP9_CONFIG *oxcf) { @@ -1002,7 +1022,7 @@ static void cal_nmvjointsadcost(int *mvjointsadcost) { mvjointsadcost[0] = 600; mvjointsadcost[1] = 300; mvjointsadcost[2] = 300; - mvjointsadcost[0] = 300; + mvjointsadcost[3] = 300; } static void cal_nmvsadcosts(int *mvsadcost[2]) { @@ -1158,7 +1178,6 @@ VP9_COMP *vp9_create_compressor(VP9_CONFIG *oxcf) { int i, j; VP9_COMP *const cpi = vpx_memalign(32, sizeof(VP9_COMP)); VP9_COMMON *const cm = cpi != NULL ? &cpi->common : NULL; - RATE_CONTROL *const rc = cpi != NULL ? &cpi->rc : NULL; if (!cm) return NULL; @@ -1189,8 +1208,6 @@ VP9_COMP *vp9_create_compressor(VP9_CONFIG *oxcf) { // Set reference frame sign bias for ALTREF frame to 1 (for now) cm->ref_frame_sign_bias[ALTREF_FRAME] = 1; - rc->baseline_gf_interval = DEFAULT_GF_INTERVAL; - cpi->gold_is_last = 0; cpi->alt_is_last = 0; cpi->gold_is_alt = 0; @@ -1226,13 +1243,6 @@ VP9_COMP *vp9_create_compressor(VP9_CONFIG *oxcf) { /*Initialize the feed-forward activity masking.*/ cpi->activity_avg = 90 << 12; cpi->key_frame_frequency = cpi->oxcf.key_freq; - - rc->frames_since_key = 8; // Sensible default for first frame. - rc->this_key_frame_forced = 0; - rc->next_key_frame_forced = 0; - - rc->source_alt_ref_pending = 0; - rc->source_alt_ref_active = 0; cpi->refresh_alt_ref_frame = 0; #if CONFIG_MULTIPLE_ARF @@ -1288,18 +1298,6 @@ VP9_COMP *vp9_create_compressor(VP9_CONFIG *oxcf) { cpi->first_time_stamp_ever = INT64_MAX; - rc->frames_till_gf_update_due = 0; - - rc->ni_av_qi = cpi->oxcf.worst_allowed_q; - rc->ni_tot_qi = 0; - rc->ni_frames = 0; - rc->tot_q = 0.0; - rc->avg_q = vp9_convert_qindex_to_q(cpi->oxcf.worst_allowed_q); - - rc->rate_correction_factor = 1.0; - rc->key_frame_rate_correction_factor = 1.0; - rc->gf_rate_correction_factor = 1.0; - cal_nmvjointsadcost(cpi->mb.nmvjointsadcost); cpi->mb.nmvcost[0] = &cpi->mb.nmvcosts[0][MV_MAX]; cpi->mb.nmvcost[1] = &cpi->mb.nmvcosts[1][MV_MAX]; @@ -3198,8 +3196,6 @@ int vp9_get_compressed_data(VP9_COMP *cpi, unsigned int *frame_flags, } set_ref_ptrs(cm, xd, LAST_FRAME, LAST_FRAME); - xd->interp_kernel = vp9_get_interp_kernel( - DEFAULT_INTERP_FILTER == SWITCHABLE ? EIGHTTAP : DEFAULT_INTERP_FILTER); if (cpi->oxcf.aq_mode == VARIANCE_AQ) { vp9_vaq_init(); diff --git a/vp9/encoder/vp9_onyx_int.h b/vp9/encoder/vp9_onyx_int.h index ab2612515..d9dbd53da 100644 --- a/vp9/encoder/vp9_onyx_int.h +++ b/vp9/encoder/vp9_onyx_int.h @@ -232,6 +232,9 @@ typedef struct { int lossless; AQ_MODE aq_mode; // Adaptive Quantization mode + // Enable feature to reduce the frame quantization every x frames. + int frame_periodic_boost; + // two pass datarate control int two_pass_vbrbias; // two pass datarate control tweaks int two_pass_vbrmin_section; @@ -385,7 +388,6 @@ typedef struct VP9_COMP { vp9_coeff_count coef_counts[TX_SIZES][PLANE_TYPES]; vp9_coeff_probs_model frame_coef_probs[TX_SIZES][PLANE_TYPES]; - vp9_coeff_stats frame_branch_ct[TX_SIZES][PLANE_TYPES]; struct vpx_codec_pkt_list *output_pkt_list; diff --git a/vp9/encoder/vp9_pickmode.c b/vp9/encoder/vp9_pickmode.c index 099add730..9c7e8c109 100644 --- a/vp9/encoder/vp9_pickmode.c +++ b/vp9/encoder/vp9_pickmode.c @@ -29,7 +29,7 @@ static void full_pixel_motion_search(VP9_COMP *cpi, MACROBLOCK *x, const TileInfo *const tile, BLOCK_SIZE bsize, int mi_row, int mi_col, - int_mv *tmp_mv) { + int_mv *tmp_mv, int *rate_mv) { MACROBLOCKD *xd = &x->e_mbd; MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0}}; @@ -128,12 +128,18 @@ static void full_pixel_motion_search(VP9_COMP *cpi, MACROBLOCK *x, for (i = 0; i < MAX_MB_PLANE; i++) xd->plane[i].pre[0] = backup_yv12[i]; } + + // calculate the bit cost on motion vector + mvp_full.row = tmp_mv->as_mv.row * 8; + mvp_full.col = tmp_mv->as_mv.col * 8; + *rate_mv = vp9_mv_bit_cost(&mvp_full, &ref_mv, + x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); } static void sub_pixel_motion_search(VP9_COMP *cpi, MACROBLOCK *x, const TileInfo *const tile, BLOCK_SIZE bsize, int mi_row, int mi_col, - MV *tmp_mv, int *rate_mv) { + MV *tmp_mv) { MACROBLOCKD *xd = &x->e_mbd; MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; struct buf_2d backup_yv12[MAX_MB_PLANE] = {{0}}; @@ -163,10 +169,6 @@ static void sub_pixel_motion_search(VP9_COMP *cpi, MACROBLOCK *x, x->nmvjointcost, x->mvcost, &dis, &x->pred_sse[ref]); - // calculate the bit cost on motion vector - *rate_mv = vp9_mv_bit_cost(tmp_mv, &ref_mv, - x->nmvjointcost, x->mvcost, MV_COST_WEIGHT); - if (scaled_ref_frame) { int i; for (i = 0; i < MAX_MB_PLANE; i++) @@ -188,12 +190,11 @@ static void model_rd_for_sb_y(VP9_COMP *cpi, BLOCK_SIZE bsize, struct macroblock_plane *const p = &x->plane[0]; struct macroblockd_plane *const pd = &xd->plane[0]; - const BLOCK_SIZE bs = get_plane_block_size(bsize, pd); - int var = cpi->fn_ptr[bs].vf(p->src.buf, p->src.stride, - pd->dst.buf, pd->dst.stride, &sse); + int var = cpi->fn_ptr[bsize].vf(p->src.buf, p->src.stride, + pd->dst.buf, pd->dst.stride, &sse); - vp9_model_rd_from_var_lapndz(sse + var, 1 << num_pels_log2_lookup[bs], + vp9_model_rd_from_var_lapndz(sse + var, 1 << num_pels_log2_lookup[bsize], pd->dequant[1] >> 3, &rate, &dist); *out_rate_sum = rate; *out_dist_sum = dist << 3; @@ -211,7 +212,6 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi; struct macroblock_plane *const p = &x->plane[0]; struct macroblockd_plane *const pd = &xd->plane[0]; - const BLOCK_SIZE block_size = get_plane_block_size(bsize, &xd->plane[0]); MB_PREDICTION_MODE this_mode, best_mode = ZEROMV; MV_REFERENCE_FRAME ref_frame, best_ref_frame = LAST_FRAME; int_mv frame_mv[MB_MODE_COUNT][MAX_REF_FRAMES]; @@ -255,13 +255,12 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, EIGHTTAP : cpi->common.interp_filter; mbmi->skip = 0; mbmi->segment_id = segment_id; - xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter); for (ref_frame = LAST_FRAME; ref_frame <= LAST_FRAME ; ++ref_frame) { x->pred_mv_sad[ref_frame] = INT_MAX; if (cpi->ref_frame_flags & flag_list[ref_frame]) { vp9_setup_buffer_inter(cpi, x, tile, - ref_frame, block_size, mi_row, mi_col, + ref_frame, bsize, mi_row, mi_col, frame_mv[NEARESTMV], frame_mv[NEARMV], yv12_mb); } frame_mv[NEWMV][ref_frame].as_int = INVALID_MV; @@ -301,17 +300,23 @@ int64_t vp9_pick_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, continue; if (this_mode == NEWMV) { + int rate_mode = 0; if (this_rd < (int64_t)(1 << num_pels_log2_lookup[bsize])) continue; full_pixel_motion_search(cpi, x, tile, bsize, mi_row, mi_col, - &frame_mv[NEWMV][ref_frame]); + &frame_mv[NEWMV][ref_frame], &rate_mv); if (frame_mv[NEWMV][ref_frame].as_int == INVALID_MV) continue; + rate_mode = x->inter_mode_cost[mbmi->mode_context[ref_frame]] + [INTER_OFFSET(this_mode)]; + if (RDCOST(x->rdmult, x->rddiv, rate_mv + rate_mode, 0) > best_rd) + continue; + sub_pixel_motion_search(cpi, x, tile, bsize, mi_row, mi_col, - &frame_mv[NEWMV][ref_frame].as_mv, &rate_mv); + &frame_mv[NEWMV][ref_frame].as_mv); } if (this_mode != NEARESTMV) diff --git a/vp9/encoder/vp9_ratectrl.c b/vp9/encoder/vp9_ratectrl.c index 21f423043..eb4db1a33 100644 --- a/vp9/encoder/vp9_ratectrl.c +++ b/vp9/encoder/vp9_ratectrl.c @@ -982,7 +982,7 @@ int vp9_rc_pick_q_and_bounds(const VP9_COMP *cpi, if (cpi->sf.use_nonrd_pick_mode) { if (q == 0) q++; - if (cpi->sf.force_ref_frame == 1) + if (cpi->sf.force_frame_boost == 1) q -= cpi->sf.max_delta_qindex; if (q < *bottom_index) diff --git a/vp9/encoder/vp9_rdopt.c b/vp9/encoder/vp9_rdopt.c index d758d3bf5..a3e513277 100644 --- a/vp9/encoder/vp9_rdopt.c +++ b/vp9/encoder/vp9_rdopt.c @@ -1559,6 +1559,8 @@ static int64_t encode_inter_mb_segment(VP9_COMP *cpi, int thisrate = 0, ref; const scan_order *so = &vp9_default_scan_orders[TX_4X4]; const int is_compound = has_second_ref(&mi->mbmi); + const InterpKernel *kernel = vp9_get_interp_kernel(mi->mbmi.interp_filter); + for (ref = 0; ref < 1 + is_compound; ++ref) { const uint8_t *pre = &pd->pre[ref].buf[raster_block_offset(BLOCK_8X8, i, pd->pre[ref].stride)]; @@ -1566,7 +1568,7 @@ static int64_t encode_inter_mb_segment(VP9_COMP *cpi, dst, pd->dst.stride, &mi->bmi[i].as_mv[ref].as_mv, &xd->block_refs[ref]->sf, width, height, ref, - xd->interp_kernel, MV_PRECISION_Q3, + kernel, MV_PRECISION_Q3, mi_col * MI_SIZE + 4 * (i % 2), mi_row * MI_SIZE + 4 * (i / 2)); } @@ -2544,6 +2546,7 @@ static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, int ite, ref; // Prediction buffer from second frame. uint8_t *second_pred = vpx_memalign(16, pw * ph * sizeof(uint8_t)); + const InterpKernel *kernel = vp9_get_interp_kernel(mbmi->interp_filter); // Do joint motion search in compound mode to get more accurate mv. struct buf_2d backup_yv12[2][MAX_MB_PLANE]; @@ -2597,7 +2600,7 @@ static void joint_motion_search(VP9_COMP *cpi, MACROBLOCK *x, &frame_mv[refs[!id]].as_mv, &xd->block_refs[!id]->sf, pw, ph, 0, - xd->interp_kernel, MV_PRECISION_Q3, + kernel, MV_PRECISION_Q3, mi_col * MI_SIZE, mi_row * MI_SIZE); // Compound motion search on first ref frame. @@ -2812,7 +2815,6 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, int j; int64_t rs_rd; mbmi->interp_filter = i; - xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter); rs = get_switchable_rate(x); rs_rd = RDCOST(x->rdmult, x->rddiv, rs, 0); @@ -2883,7 +2885,6 @@ static int64_t handle_inter_mode(VP9_COMP *cpi, MACROBLOCK *x, // Set the appropriate filter mbmi->interp_filter = cm->interp_filter != SWITCHABLE ? cm->interp_filter : *best_filter; - xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter); rs = cm->interp_filter == SWITCHABLE ? get_switchable_rate(x) : 0; if (pred_exists) { @@ -3394,7 +3395,6 @@ int64_t vp9_rd_pick_inter_mode_sb(VP9_COMP *cpi, MACROBLOCK *x, : cm->interp_filter; x->skip = 0; set_ref_ptrs(cm, xd, ref_frame, second_ref_frame); - xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter); // Select prediction reference frames. for (i = 0; i < MAX_MB_PLANE; i++) { @@ -3938,7 +3938,6 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, // them for this frame. mbmi->interp_filter = cm->interp_filter == SWITCHABLE ? EIGHTTAP : cm->interp_filter; - xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter); if (comp_pred) { if (!(cpi->ref_frame_flags & flag_list[second_ref_frame])) @@ -4061,7 +4060,6 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, int newbest, rs; int64_t rs_rd; mbmi->interp_filter = switchable_filter_index; - xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter); tmp_rd = rd_pick_best_mbsegmentation(cpi, x, tile, &mbmi->ref_mvs[ref_frame][0], second_ref, @@ -4126,7 +4124,6 @@ int64_t vp9_rd_pick_inter_mode_sub8x8(VP9_COMP *cpi, MACROBLOCK *x, mbmi->interp_filter = (cm->interp_filter == SWITCHABLE ? tmp_best_filter : cm->interp_filter); - xd->interp_kernel = vp9_get_interp_kernel(mbmi->interp_filter); if (!pred_exists) { // Handles the special case when a filter that is not in the // switchable list (bilinear, 6-tap) is indicated at the frame level diff --git a/vp9/encoder/vp9_speed_features.c b/vp9/encoder/vp9_speed_features.c index 6f1cdcae9..9ca1b5eda 100644 --- a/vp9/encoder/vp9_speed_features.c +++ b/vp9/encoder/vp9_speed_features.c @@ -13,17 +13,32 @@ #include "vp9/encoder/vp9_onyx_int.h" #include "vp9/encoder/vp9_speed_features.h" -#define ALL_INTRA_MODES 0x3FF -#define INTRA_DC_ONLY 0x01 -#define INTRA_DC_TM ((1 << TM_PRED) | (1 << DC_PRED)) -#define INTRA_DC_H_V ((1 << DC_PRED) | (1 << V_PRED) | (1 << H_PRED)) +#define ALL_INTRA_MODES ((1 << DC_PRED) | \ + (1 << V_PRED) | (1 << H_PRED) | \ + (1 << D45_PRED) | (1 << D135_PRED) | \ + (1 << D117_PRED) | (1 << D153_PRED) | \ + (1 << D207_PRED) | (1 << D63_PRED) | \ + (1 << TM_PRED)) +#define INTRA_DC_ONLY (1 << DC_PRED) +#define INTRA_DC_TM ((1 << TM_PRED) | (1 << DC_PRED)) +#define INTRA_DC_H_V ((1 << DC_PRED) | (1 << V_PRED) | (1 << H_PRED)) #define INTRA_DC_TM_H_V (INTRA_DC_TM | (1 << V_PRED) | (1 << H_PRED)) // Masks for partially or completely disabling split mode -#define DISABLE_ALL_SPLIT 0x3F -#define DISABLE_ALL_INTER_SPLIT 0x1F -#define DISABLE_COMPOUND_SPLIT 0x18 -#define LAST_AND_INTRA_SPLIT_ONLY 0x1E +#define DISABLE_ALL_INTER_SPLIT ((1 << THR_COMP_GA) | \ + (1 << THR_COMP_LA) | \ + (1 << THR_ALTR) | \ + (1 << THR_GOLD) | \ + (1 << THR_LAST)) + +#define DISABLE_ALL_SPLIT ((1 << THR_INTRA) | DISABLE_ALL_INTER_SPLIT) + +#define DISABLE_COMPOUND_SPLIT ((1 << THR_COMP_GA) | (1 << THR_COMP_LA)) + +#define LAST_AND_INTRA_SPLIT_ONLY ((1 << THR_COMP_GA) | \ + (1 << THR_COMP_LA) | \ + (1 << THR_ALTR) | \ + (1 << THR_GOLD)) static void set_good_speed_feature(VP9_COMP *cpi, VP9_COMMON *cm, @@ -96,7 +111,7 @@ static void set_good_speed_feature(VP9_COMP *cpi, sf->adaptive_rd_thresh = 3; sf->mode_skip_start = 6; - sf->use_fast_coef_updates = 2; + sf->use_fast_coef_updates = ONE_LOOP_REDUCED; sf->use_fast_coef_costing = 1; } // Additions or changes for speed 3 and above @@ -205,7 +220,7 @@ static void set_rt_speed_feature(VP9_COMMON *cm, sf->use_uv_intra_rd_estimate = 1; sf->skip_encode_sb = 1; sf->subpel_iters_per_step = 1; - sf->use_fast_coef_updates = 2; + sf->use_fast_coef_updates = ONE_LOOP_REDUCED; sf->adaptive_rd_thresh = 4; sf->mode_skip_start = 6; sf->allow_skip_recode = 0; @@ -244,10 +259,10 @@ static void set_rt_speed_feature(VP9_COMMON *cm, sf->min_partition_size = BLOCK_8X8; sf->partition_check = (cm->current_video_frame % sf->last_partitioning_redo_frequency == 1); - sf->force_ref_frame = + sf->force_frame_boost = cm->frame_type == KEY_FRAME || (cm->current_video_frame % (sf->last_partitioning_redo_frequency << 1) == 1); - sf->max_delta_qindex = 15; + sf->max_delta_qindex = (cm->frame_type == KEY_FRAME) ? 20 : 15; sf->partition_search_type = REFERENCE_PARTITION; sf->use_nonrd_pick_mode = 1; sf->search_method = FAST_DIAMOND; @@ -300,7 +315,7 @@ void vp9_set_speed_features(VP9_COMP *cpi) { sf->last_partitioning_redo_frequency = 4; sf->disable_split_mask = 0; sf->mode_search_skip_flags = 0; - sf->force_ref_frame = 0; + sf->force_frame_boost = 0; sf->max_delta_qindex = 0; sf->disable_split_var_thresh = 0; sf->disable_filter_search_var_thresh = 0; @@ -313,7 +328,7 @@ void vp9_set_speed_features(VP9_COMP *cpi) { sf->use_uv_intra_rd_estimate = 0; sf->allow_skip_recode = 0; sf->lpf_pick = LPF_PICK_FROM_FULL_IMAGE; - sf->use_fast_coef_updates = 0; + sf->use_fast_coef_updates = TWO_LOOP; sf->use_fast_coef_costing = 0; sf->mode_skip_start = MAX_MODES; // Mode index at which mode skip mask set sf->use_nonrd_pick_mode = 0; @@ -368,4 +383,8 @@ void vp9_set_speed_features(VP9_COMP *cpi) { if (sf->disable_split_mask == DISABLE_ALL_SPLIT) sf->adaptive_pred_interp_filter = 0; + + if (!cpi->oxcf.frame_periodic_boost) { + sf->max_delta_qindex = 0; + } } diff --git a/vp9/encoder/vp9_speed_features.h b/vp9/encoder/vp9_speed_features.h index 27b11c84e..922f8803e 100644 --- a/vp9/encoder/vp9_speed_features.h +++ b/vp9/encoder/vp9_speed_features.h @@ -113,6 +113,19 @@ typedef enum { VAR_BASED_PARTITION } PARTITION_SEARCH_TYPE; +typedef enum { + // Does a dry run to see if any of the contexts need to be updated or not, + // before the final run. + TWO_LOOP = 0, + + // No dry run conducted. + ONE_LOOP = 1, + + // No dry run, also only half the coef contexts and bands are updated. + // The rest are not updated at all. + ONE_LOOP_REDUCED = 2 +} FAST_COEFF_UPDATE; + typedef struct { // Frame level coding parameter update int frame_parameter_update; @@ -254,7 +267,7 @@ typedef struct { // Use finer quantizer in every other few frames that run variable block // partition type search. - int force_ref_frame; + int force_frame_boost; // Maximally allowed base quantization index fluctuation. int max_delta_qindex; @@ -291,7 +304,7 @@ typedef struct { // This feature limits the number of coefficients updates we actually do // by only looking at counts from 1/2 the bands. - int use_fast_coef_updates; // 0: 2-loop, 1: 1-loop, 2: 1-loop reduced + FAST_COEFF_UPDATE use_fast_coef_updates; // This flag controls the use of non-RD mode decision. int use_nonrd_pick_mode; diff --git a/vp9/encoder/vp9_temporal_filter.c b/vp9/encoder/vp9_temporal_filter.c index f8a641513..041027354 100644 --- a/vp9/encoder/vp9_temporal_filter.c +++ b/vp9/encoder/vp9_temporal_filter.c @@ -41,7 +41,10 @@ static void temporal_filter_predictors_mb_c(MACROBLOCKD *xd, struct scale_factors *scale, int x, int y) { const int which_mv = 0; - MV mv = { mv_row, mv_col }; + const MV mv = { mv_row, mv_col }; + const InterpKernel *const kernel = + vp9_get_interp_kernel(xd->mi[0]->mbmi.interp_filter); + enum mv_precision mv_precision_uv; int uv_stride; if (uv_block_size == 8) { @@ -58,7 +61,7 @@ static void temporal_filter_predictors_mb_c(MACROBLOCKD *xd, scale, 16, 16, which_mv, - xd->interp_kernel, MV_PRECISION_Q3, x, y); + kernel, MV_PRECISION_Q3, x, y); vp9_build_inter_predictor(u_mb_ptr, uv_stride, &pred[256], uv_block_size, @@ -66,7 +69,7 @@ static void temporal_filter_predictors_mb_c(MACROBLOCKD *xd, scale, uv_block_size, uv_block_size, which_mv, - xd->interp_kernel, mv_precision_uv, x, y); + kernel, mv_precision_uv, x, y); vp9_build_inter_predictor(v_mb_ptr, uv_stride, &pred[512], uv_block_size, @@ -74,7 +77,7 @@ static void temporal_filter_predictors_mb_c(MACROBLOCKD *xd, scale, uv_block_size, uv_block_size, which_mv, - xd->interp_kernel, mv_precision_uv, x, y); + kernel, mv_precision_uv, x, y); } void vp9_temporal_filter_apply_c(uint8_t *frame1, diff --git a/vp9/vp9_cx_iface.c b/vp9/vp9_cx_iface.c index a9fd8c11e..37a214e05 100644 --- a/vp9/vp9_cx_iface.c +++ b/vp9/vp9_cx_iface.c @@ -37,6 +37,7 @@ struct vp9_extracfg { unsigned int lossless; unsigned int frame_parallel_decoding_mode; AQ_MODE aq_mode; + unsigned int frame_periodic_boost; }; struct extraconfig_map { @@ -65,6 +66,7 @@ static const struct extraconfig_map extracfg_map[] = { 0, // lossless 0, // frame_parallel_decoding_mode NO_AQ, // aq_mode + 0, // frame_periodic_delta_q } } }; @@ -150,7 +152,7 @@ static vpx_codec_err_t validate_config(vpx_codec_alg_priv_t *ctx, RANGE_CHECK_HI(cfg, rc_min_quantizer, cfg->rc_max_quantizer); RANGE_CHECK_BOOL(extra_cfg, lossless); RANGE_CHECK(extra_cfg, aq_mode, 0, AQ_MODE_COUNT - 1); - + RANGE_CHECK(extra_cfg, frame_periodic_boost, 0, 1); RANGE_CHECK_HI(cfg, g_threads, 64); RANGE_CHECK_HI(cfg, g_lag_in_frames, MAX_LAG_BUFFERS); RANGE_CHECK(cfg, rc_end_usage, VPX_VBR, VPX_Q); @@ -360,6 +362,8 @@ static vpx_codec_err_t set_vp9e_config(VP9_CONFIG *oxcf, oxcf->aq_mode = extra_cfg->aq_mode; + oxcf->frame_periodic_boost = extra_cfg->frame_periodic_boost; + oxcf->ss_number_layers = cfg->ss_number_layers; if (oxcf->ss_number_layers > 1) { @@ -484,6 +488,7 @@ static vpx_codec_err_t set_param(vpx_codec_alg_priv_t *ctx, int ctrl_id, MAP(VP9E_SET_FRAME_PARALLEL_DECODING, extra_cfg.frame_parallel_decoding_mode); MAP(VP9E_SET_AQ_MODE, extra_cfg.aq_mode); + MAP(VP9E_SET_FRAME_PERIODIC_BOOST, extra_cfg.frame_periodic_boost); } res = validate_config(ctx, &ctx->cfg, &extra_cfg); @@ -1094,6 +1099,7 @@ static vpx_codec_ctrl_fn_map_t vp9e_ctf_maps[] = { {VP9E_SET_LOSSLESS, set_param}, {VP9E_SET_FRAME_PARALLEL_DECODING, set_param}, {VP9E_SET_AQ_MODE, set_param}, + {VP9E_SET_FRAME_PERIODIC_BOOST, set_param}, {VP9_GET_REFERENCE, get_reference}, {VP9E_SET_SVC, vp9e_set_svc}, {VP9E_SET_SVC_PARAMETERS, vp9e_set_svc_parameters}, diff --git a/vp9/vp9_dx_iface.c b/vp9/vp9_dx_iface.c index 271589c6b..7272205d9 100644 --- a/vp9/vp9_dx_iface.c +++ b/vp9/vp9_dx_iface.c @@ -23,27 +23,10 @@ #define VP9_CAP_POSTPROC (CONFIG_VP9_POSTPROC ? VPX_CODEC_CAP_POSTPROC : 0) typedef vpx_codec_stream_info_t vp9_stream_info_t; -/* Structures for handling memory allocations */ -typedef enum { - VP9_SEG_ALG_PRIV = 256, - VP9_SEG_MAX -} mem_seg_id_t; -#define NELEMENTS(x) ((int)(sizeof(x)/sizeof(x[0]))) - -static unsigned long priv_sz(const vpx_codec_dec_cfg_t *si, - vpx_codec_flags_t flags); - -static const mem_req_t vp9_mem_req_segs[] = { - {VP9_SEG_ALG_PRIV, 0, 8, VPX_CODEC_MEM_ZERO, priv_sz}, - {VP9_SEG_MAX, 0, 0, 0, NULL} -}; - struct vpx_codec_alg_priv { vpx_codec_priv_t base; - vpx_codec_mmap_t mmaps[NELEMENTS(vp9_mem_req_segs) - 1]; vpx_codec_dec_cfg_t cfg; vp9_stream_info_t si; - int defer_alloc; int decoder_init; struct VP9Decompressor *pbi; int postproc_cfg_set; @@ -66,80 +49,38 @@ struct vpx_codec_alg_priv { vpx_release_frame_buffer_cb_fn_t release_ext_fb_cb; }; -static unsigned long priv_sz(const vpx_codec_dec_cfg_t *si, - vpx_codec_flags_t flags) { - /* Although this declaration is constant, we can't use it in the requested - * segments list because we want to define the requested segments list - * before defining the private type (so that the number of memory maps is - * known) - */ - (void)si; - return sizeof(vpx_codec_alg_priv_t); -} - -static void vp9_init_ctx(vpx_codec_ctx_t *ctx, const vpx_codec_mmap_t *mmap) { - int i; - - ctx->priv = (vpx_codec_priv_t *)mmap->base; - ctx->priv->sz = sizeof(*ctx->priv); - ctx->priv->iface = ctx->iface; - ctx->priv->alg_priv = (struct vpx_codec_alg_priv *)mmap->base; - - for (i = 0; i < NELEMENTS(ctx->priv->alg_priv->mmaps); i++) - ctx->priv->alg_priv->mmaps[i].id = vp9_mem_req_segs[i].id; - - ctx->priv->alg_priv->mmaps[0] = *mmap; - ctx->priv->alg_priv->si.sz = sizeof(ctx->priv->alg_priv->si); - ctx->priv->init_flags = ctx->init_flags; - - if (ctx->config.dec) { - /* Update the reference to the config structure to an internal copy. */ - ctx->priv->alg_priv->cfg = *ctx->config.dec; - ctx->config.dec = &ctx->priv->alg_priv->cfg; - } -} - -static void vp9_finalize_mmaps(vpx_codec_alg_priv_t *ctx) { - /* nothing to clean up */ -} - static vpx_codec_err_t vp9_init(vpx_codec_ctx_t *ctx, vpx_codec_priv_enc_mr_cfg_t *data) { - vpx_codec_err_t res = VPX_CODEC_OK; - // This function only allocates space for the vpx_codec_alg_priv_t // structure. More memory may be required at the time the stream // information becomes known. if (!ctx->priv) { - vpx_codec_mmap_t mmap; - - mmap.id = vp9_mem_req_segs[0].id; - mmap.sz = sizeof(vpx_codec_alg_priv_t); - mmap.align = vp9_mem_req_segs[0].align; - mmap.flags = vp9_mem_req_segs[0].flags; - - res = vpx_mmap_alloc(&mmap); - if (!res) { - vp9_init_ctx(ctx, &mmap); - - ctx->priv->alg_priv->defer_alloc = 1; + void *base = vpx_memalign(32, sizeof(vpx_codec_alg_priv_t)); + if (base == NULL) + return VPX_CODEC_MEM_ERROR; + + memset(base, 0, sizeof(vpx_codec_alg_priv_t)); + ctx->priv = (vpx_codec_priv_t *)base; + ctx->priv->sz = sizeof(*ctx->priv); + ctx->priv->iface = ctx->iface; + ctx->priv->alg_priv = (vpx_codec_alg_priv_t *)base; + ctx->priv->alg_priv->si.sz = sizeof(ctx->priv->alg_priv->si); + ctx->priv->init_flags = ctx->init_flags; + + if (ctx->config.dec) { + // Update the reference to the config structure to an internal copy. + ctx->priv->alg_priv->cfg = *ctx->config.dec; + ctx->config.dec = &ctx->priv->alg_priv->cfg; } } - return res; + return VPX_CODEC_OK; } static vpx_codec_err_t vp9_destroy(vpx_codec_alg_priv_t *ctx) { - int i; - if (ctx->pbi) vp9_remove_decompressor(ctx->pbi); - for (i = NELEMENTS(ctx->mmaps) - 1; i >= 0; i--) { - if (ctx->mmaps[i].dtor) - ctx->mmaps[i].dtor(&ctx->mmaps[i]); - } - return VPX_CODEC_OK; } @@ -224,146 +165,122 @@ static vpx_codec_err_t update_error_state(vpx_codec_alg_priv_t *ctx, return error->error_code; } -static vpx_codec_err_t decode_one(vpx_codec_alg_priv_t *ctx, - const uint8_t **data, unsigned int data_sz, - void *user_priv, int64_t deadline) { - vpx_codec_err_t res = VPX_CODEC_OK; +static void init_buffer_callbacks(vpx_codec_alg_priv_t *ctx) { + VP9_COMMON *const cm = &ctx->pbi->common; - ctx->img_avail = 0; + cm->new_fb_idx = -1; // Set index to not initialized. - /* Determine the stream parameters. Note that we rely on peek_si to - * validate that we have a buffer that does not wrap around the top - * of the heap. - */ - if (!ctx->si.h) - res = ctx->base.iface->dec.peek_si(*data, data_sz, &ctx->si); + if (ctx->get_ext_fb_cb != NULL && ctx->release_ext_fb_cb != NULL) { + cm->get_fb_cb = ctx->get_ext_fb_cb; + cm->release_fb_cb = ctx->release_ext_fb_cb; + cm->cb_priv = ctx->ext_priv; + } else { + cm->get_fb_cb = vp9_get_frame_buffer; + cm->release_fb_cb = vp9_release_frame_buffer; + if (vp9_alloc_internal_frame_buffers(&cm->int_frame_buffers)) + vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, + "Failed to initialize internal frame buffers"); - /* Perform deferred allocations, if required */ - if (!res && ctx->defer_alloc) { - int i; + cm->cb_priv = &cm->int_frame_buffers; + } +} - for (i = 1; !res && i < NELEMENTS(ctx->mmaps); i++) { - vpx_codec_dec_cfg_t cfg; +static void set_default_ppflags(vp8_postproc_cfg_t *cfg) { + cfg->post_proc_flag = VP8_DEBLOCK | VP8_DEMACROBLOCK; + cfg->deblocking_level = 4; + cfg->noise_level = 0; +} - cfg.w = ctx->si.w; - cfg.h = ctx->si.h; - ctx->mmaps[i].id = vp9_mem_req_segs[i].id; - ctx->mmaps[i].sz = vp9_mem_req_segs[i].sz; - ctx->mmaps[i].align = vp9_mem_req_segs[i].align; - ctx->mmaps[i].flags = vp9_mem_req_segs[i].flags; +static void set_ppflags(const vpx_codec_alg_priv_t *ctx, + vp9_ppflags_t *flags) { + flags->post_proc_flag = +#if CONFIG_POSTPROC_VISUALIZER + (ctx->dbg_color_ref_frame_flag ? VP9D_DEBUG_CLR_FRM_REF_BLKS : 0) | + (ctx->dbg_color_mb_modes_flag ? VP9D_DEBUG_CLR_BLK_MODES : 0) | + (ctx->dbg_color_b_modes_flag ? VP9D_DEBUG_CLR_BLK_MODES : 0) | + (ctx->dbg_display_mv_flag ? VP9D_DEBUG_DRAW_MV : 0) | +#endif + ctx->postproc_cfg.post_proc_flag; - if (!ctx->mmaps[i].sz) - ctx->mmaps[i].sz = vp9_mem_req_segs[i].calc_sz(&cfg, - ctx->base.init_flags); + flags->deblocking_level = ctx->postproc_cfg.deblocking_level; + flags->noise_level = ctx->postproc_cfg.noise_level; +#if CONFIG_POSTPROC_VISUALIZER + flags->display_ref_frame_flag = ctx->dbg_color_ref_frame_flag; + flags->display_mb_modes_flag = ctx->dbg_color_mb_modes_flag; + flags->display_b_modes_flag = ctx->dbg_color_b_modes_flag; + flags->display_mv_flag = ctx->dbg_display_mv_flag; +#endif +} - res = vpx_mmap_alloc(&ctx->mmaps[i]); - } +static void init_decoder(vpx_codec_alg_priv_t *ctx) { + VP9D_CONFIG oxcf; + oxcf.width = ctx->si.w; + oxcf.height = ctx->si.h; + oxcf.version = 9; + oxcf.max_threads = ctx->cfg.threads; + oxcf.inv_tile_order = ctx->invert_tile_order; - if (!res) - vp9_finalize_mmaps(ctx); + ctx->pbi = vp9_create_decompressor(&oxcf); + if (ctx->pbi == NULL) + return; - ctx->defer_alloc = 0; - } + vp9_initialize_dec(); - /* Initialize the decoder instance on the first frame*/ - if (!res && !ctx->decoder_init) { - res = vpx_validate_mmaps(&ctx->si, ctx->mmaps, - vp9_mem_req_segs, NELEMENTS(vp9_mem_req_segs), - ctx->base.init_flags); - - if (!res) { - VP9D_CONFIG oxcf; - struct VP9Decompressor *optr; - - vp9_initialize_dec(); - - oxcf.width = ctx->si.w; - oxcf.height = ctx->si.h; - oxcf.version = 9; - oxcf.max_threads = ctx->cfg.threads; - oxcf.inv_tile_order = ctx->invert_tile_order; - optr = vp9_create_decompressor(&oxcf); - - // If postprocessing was enabled by the application and a - // configuration has not been provided, default it. - if (!ctx->postproc_cfg_set && - (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)) { - ctx->postproc_cfg.post_proc_flag = VP8_DEBLOCK | VP8_DEMACROBLOCK; - ctx->postproc_cfg.deblocking_level = 4; - ctx->postproc_cfg.noise_level = 0; - } + // If postprocessing was enabled by the application and a + // configuration has not been provided, default it. + if (!ctx->postproc_cfg_set && + (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC)) + set_default_ppflags(&ctx->postproc_cfg); - if (!optr) { - res = VPX_CODEC_ERROR; - } else { - VP9D_COMP *const pbi = (VP9D_COMP*)optr; - VP9_COMMON *const cm = &pbi->common; + init_buffer_callbacks(ctx); +} - // Set index to not initialized. - cm->new_fb_idx = -1; +static vpx_codec_err_t decode_one(vpx_codec_alg_priv_t *ctx, + const uint8_t **data, unsigned int data_sz, + void *user_priv, int64_t deadline) { + YV12_BUFFER_CONFIG sd = { 0 }; + int64_t time_stamp = 0, time_end_stamp = 0; + vp9_ppflags_t flags = {0}; + VP9_COMMON *cm = NULL; - if (ctx->get_ext_fb_cb != NULL && ctx->release_ext_fb_cb != NULL) { - cm->get_fb_cb = ctx->get_ext_fb_cb; - cm->release_fb_cb = ctx->release_ext_fb_cb; - cm->cb_priv = ctx->ext_priv; - } else { - cm->get_fb_cb = vp9_get_frame_buffer; - cm->release_fb_cb = vp9_release_frame_buffer; + ctx->img_avail = 0; - if (vp9_alloc_internal_frame_buffers(&cm->int_frame_buffers)) - vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, - "Failed to initialize internal frame buffers"); - cm->cb_priv = &cm->int_frame_buffers; - } + // Determine the stream parameters. Note that we rely on peek_si to + // validate that we have a buffer that does not wrap around the top + // of the heap. + if (!ctx->si.h) { + const vpx_codec_err_t res = + ctx->base.iface->dec.peek_si(*data, data_sz, &ctx->si); + if (res != VPX_CODEC_OK) + return res; + } - ctx->pbi = optr; - } - } + // Initialize the decoder instance on the first frame + if (!ctx->decoder_init) { + init_decoder(ctx); + if (ctx->pbi == NULL) + return VPX_CODEC_ERROR; ctx->decoder_init = 1; } - if (!res && ctx->pbi) { - VP9D_COMP *const pbi = ctx->pbi; - VP9_COMMON *const cm = &pbi->common; - YV12_BUFFER_CONFIG sd; - int64_t time_stamp = 0, time_end_stamp = 0; - vp9_ppflags_t flags = {0}; + cm = &ctx->pbi->common; - if (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC) { - flags.post_proc_flag = -#if CONFIG_POSTPROC_VISUALIZER - (ctx->dbg_color_ref_frame_flag ? VP9D_DEBUG_CLR_FRM_REF_BLKS : 0) | - (ctx->dbg_color_mb_modes_flag ? VP9D_DEBUG_CLR_BLK_MODES : 0) | - (ctx->dbg_color_b_modes_flag ? VP9D_DEBUG_CLR_BLK_MODES : 0) | - (ctx->dbg_display_mv_flag ? VP9D_DEBUG_DRAW_MV : 0) | -#endif - ctx->postproc_cfg.post_proc_flag; + if (vp9_receive_compressed_data(ctx->pbi, data_sz, data, deadline)) + return update_error_state(ctx, &cm->error); - flags.deblocking_level = ctx->postproc_cfg.deblocking_level; - flags.noise_level = ctx->postproc_cfg.noise_level; -#if CONFIG_POSTPROC_VISUALIZER - flags.display_ref_frame_flag = ctx->dbg_color_ref_frame_flag; - flags.display_mb_modes_flag = ctx->dbg_color_mb_modes_flag; - flags.display_b_modes_flag = ctx->dbg_color_b_modes_flag; - flags.display_mv_flag = ctx->dbg_display_mv_flag; -#endif - } + if (ctx->base.init_flags & VPX_CODEC_USE_POSTPROC) + set_ppflags(ctx, &flags); - if (vp9_receive_compressed_data(pbi, data_sz, data, deadline)) - res = update_error_state(ctx, &cm->error); + if (vp9_get_raw_frame(ctx->pbi, &sd, &time_stamp, &time_end_stamp, &flags)) + return update_error_state(ctx, &cm->error); - if (!res && 0 == vp9_get_raw_frame(pbi, &sd, &time_stamp, - &time_end_stamp, &flags)) { - yuvconfig2image(&ctx->img, &sd, user_priv); + yuvconfig2image(&ctx->img, &sd, user_priv); + ctx->img.fb_priv = cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv; + ctx->img_avail = 1; - ctx->img.fb_priv = cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer.priv; - ctx->img_avail = 1; - } - } - - return res; + return VPX_CODEC_OK; } static void parse_superframe_index(const uint8_t *data, size_t data_sz, @@ -496,75 +413,6 @@ static vpx_codec_err_t vp9_set_fb_fn( return VPX_CODEC_ERROR; } -static vpx_codec_err_t vp9_xma_get_mmap(const vpx_codec_ctx_t *ctx, - vpx_codec_mmap_t *mmap, - vpx_codec_iter_t *iter) { - vpx_codec_err_t res; - const mem_req_t *seg_iter = (const mem_req_t *)*iter; - - /* Get address of next segment request */ - do { - if (!seg_iter) - seg_iter = vp9_mem_req_segs; - else if (seg_iter->id != VP9_SEG_MAX) - seg_iter++; - - *iter = (vpx_codec_iter_t)seg_iter; - - if (seg_iter->id != VP9_SEG_MAX) { - mmap->id = seg_iter->id; - mmap->sz = seg_iter->sz; - mmap->align = seg_iter->align; - mmap->flags = seg_iter->flags; - - if (!seg_iter->sz) - mmap->sz = seg_iter->calc_sz(ctx->config.dec, ctx->init_flags); - - res = VPX_CODEC_OK; - } else { - res = VPX_CODEC_LIST_END; - } - } while (!mmap->sz && res != VPX_CODEC_LIST_END); - - return res; -} - -static vpx_codec_err_t vp9_xma_set_mmap(vpx_codec_ctx_t *ctx, - const vpx_codec_mmap_t *mmap) { - vpx_codec_err_t res = VPX_CODEC_MEM_ERROR; - int i, done; - - if (!ctx->priv) { - if (mmap->id == VP9_SEG_ALG_PRIV) { - if (!ctx->priv) { - vp9_init_ctx(ctx, mmap); - res = VPX_CODEC_OK; - } - } - } - - done = 1; - - if (!res && ctx->priv->alg_priv) { - for (i = 0; i < NELEMENTS(ctx->priv->alg_priv->mmaps); i++) { - if (ctx->priv->alg_priv->mmaps[i].id == mmap->id) - if (!ctx->priv->alg_priv->mmaps[i].base) { - ctx->priv->alg_priv->mmaps[i] = *mmap; - res = VPX_CODEC_OK; - } - - done &= (ctx->priv->alg_priv->mmaps[i].base != NULL); - } - } - - if (done && !res) { - vp9_finalize_mmaps(ctx->priv->alg_priv); - res = ctx->iface->init(ctx, NULL); - } - - return res; -} - static vpx_codec_err_t set_reference(vpx_codec_alg_priv_t *ctx, int ctr_id, va_list args) { vpx_ref_frame_t *const data = va_arg(args, vpx_ref_frame_t *); @@ -735,8 +583,8 @@ CODEC_INTERFACE(vpx_codec_vp9_dx) = { vp9_init, /* vpx_codec_init_fn_t init; */ vp9_destroy, /* vpx_codec_destroy_fn_t destroy; */ ctf_maps, /* vpx_codec_ctrl_fn_map_t *ctrl_maps; */ - vp9_xma_get_mmap, /* vpx_codec_get_mmap_fn_t get_mmap; */ - vp9_xma_set_mmap, /* vpx_codec_set_mmap_fn_t set_mmap; */ + NOT_IMPLEMENTED, /* vpx_codec_get_mmap_fn_t get_mmap; */ + NOT_IMPLEMENTED, /* vpx_codec_set_mmap_fn_t set_mmap; */ { // NOLINT vp9_peek_si, /* vpx_codec_peek_si_fn_t peek_si; */ vp9_get_si, /* vpx_codec_get_si_fn_t get_si; */ diff --git a/vpx/vp8cx.h b/vpx/vp8cx.h index 0b637d42f..8944a2664 100644 --- a/vpx/vp8cx.h +++ b/vpx/vp8cx.h @@ -192,6 +192,7 @@ enum vp8e_enc_control_id { VP9E_SET_TILE_ROWS, VP9E_SET_FRAME_PARALLEL_DECODING, VP9E_SET_AQ_MODE, + VP9E_SET_FRAME_PERIODIC_BOOST, VP9E_SET_SVC, VP9E_SET_SVC_PARAMETERS, @@ -364,6 +365,8 @@ VPX_CTRL_USE_TYPE(VP9E_SET_FRAME_PARALLEL_DECODING, unsigned int) VPX_CTRL_USE_TYPE(VP9E_SET_AQ_MODE, unsigned int) +VPX_CTRL_USE_TYPE(VP9E_SET_FRAME_PERIODIC_BOOST, unsigned int) + /*! @} - end defgroup vp8_encoder */ #ifdef __cplusplus } // extern "C" @@ -400,13 +400,17 @@ static const arg_def_t frame_parallel_decoding = ARG_DEF( NULL, "frame-parallel", 1, "Enable frame parallel decodability features"); static const arg_def_t aq_mode = ARG_DEF( NULL, "aq-mode", 1, - "Adaptive q mode (0: off (by default), 1: variance 2: complexity)"); + "Adaptive q mode (0: off (by default), 1: variance 2: complexity, " + "3: cyclic refresh)"); +static const arg_def_t frame_periodic_boost = ARG_DEF( + NULL, "frame_boost", 1, + "Enable frame periodic boost (0: off (by default), 1: on)"); static const arg_def_t *vp9_args[] = { &cpu_used, &auto_altref, &noise_sens, &sharpness, &static_thresh, &tile_cols, &tile_rows, &arnr_maxframes, &arnr_strength, &arnr_type, &tune_ssim, &cq_level, &max_intra_rate_pct, &lossless, - &frame_parallel_decoding, &aq_mode, + &frame_parallel_decoding, &aq_mode, &frame_periodic_boost, NULL }; static const int vp9_arg_ctrl_map[] = { @@ -416,6 +420,7 @@ static const int vp9_arg_ctrl_map[] = { VP8E_SET_ARNR_MAXFRAMES, VP8E_SET_ARNR_STRENGTH, VP8E_SET_ARNR_TYPE, VP8E_SET_TUNING, VP8E_SET_CQ_LEVEL, VP8E_SET_MAX_INTRA_BITRATE_PCT, VP9E_SET_LOSSLESS, VP9E_SET_FRAME_PARALLEL_DECODING, VP9E_SET_AQ_MODE, + VP9E_SET_FRAME_PERIODIC_BOOST, 0 }; #endif @@ -1498,7 +1503,7 @@ static void print_time(const char *label, int64_t etl) { etl -= mins * 60; secs = etl; - fprintf(stderr, "[%3s %2"PRId64":%02"PRId64": % 02"PRId64"] ", + fprintf(stderr, "[%3s %2"PRId64":%02"PRId64":%02"PRId64"] ", label, hours, mins, secs); } else { fprintf(stderr, "[%3s unknown] ", label); |