Commit 896b6a9b authored by John Koleszar's avatar John Koleszar

Merge snapshot 2 development history

Create a merge between the experimental development history and the
previously published snapshot.

Change-Id: If320df72a6bbefec53833626d08dbc9678be2d2d
parents 51dba57c a81baae7
......@@ -20,6 +20,7 @@ ifeq ($(target),)
all: .DEFAULT
clean:: .DEFAULT
install:: .DEFAULT
test:: .DEFAULT
# Note: md5sum is not installed on OS X, but openssl is. Openssl may not be
......@@ -78,12 +79,13 @@ qexec=$(if $(quiet),@)
%: %.o
%.asm:
%.a:
%: %.cc
#
# Common rules"
#
.PHONY: all-$(target)
all-$(target):
.PHONY: all
all:
.PHONY: clean
clean::
......@@ -94,6 +96,8 @@ clean::
dist:
.PHONY: install
install::
.PHONY: test
test::
$(BUILD_PFX)%.c.d: %.c
$(if $(quiet),@echo " [DEP] $@")
......@@ -104,6 +108,15 @@ $(BUILD_PFX)%.c.o: %.c
$(if $(quiet),@echo " [CC] $@")
$(qexec)$(CC) $(INTERNAL_CFLAGS) $(CFLAGS) -c -o $@ $<
$(BUILD_PFX)%.cc.d: %.cc
$(if $(quiet),@echo " [DEP] $@")
$(qexec)mkdir -p $(dir $@)
$(qexec)g++ $(INTERNAL_CFLAGS) $(CFLAGS) -M $< | $(fmt_deps) > $@
$(BUILD_PFX)%.cc.o: %.cc
$(if $(quiet),@echo " [CXX] $@")
$(qexec)g++ $(INTERNAL_CFLAGS) $(CFLAGS) -c -o $@ $<
$(BUILD_PFX)%.asm.d: %.asm
$(if $(quiet),@echo " [DEP] $@")
$(qexec)mkdir -p $(dir $@)
......@@ -175,7 +188,7 @@ cond_enabled=$(if $(filter yes,$($(1))), $(call enabled,$(2)))
find_file1=$(word 1,$(wildcard $(subst //,/,$(addsuffix /$(1),$(2)))))
find_file=$(foreach f,$(1),$(call find_file1,$(strip $(f)),$(strip $(2))) )
obj_pats=.c=.c.o $(AS_SFX)=$(AS_SFX).o
obj_pats=.c=.c.o $(AS_SFX)=$(AS_SFX).o .cc=.cc.o
objs=$(addprefix $(BUILD_PFX),$(foreach p,$(obj_pats),$(filter %.o,$(1:$(p))) ))
install_map_templates=$(eval $(call install_map_template,$(1),$(2)))
......@@ -196,6 +209,12 @@ $(1):
$(if $(quiet),@echo " [LD] $$@")
$(qexec)$$(LD) $$(strip $$(INTERNAL_LDFLAGS) $$(LDFLAGS) -o $$@ $(2) $(3) $$(extralibs))
endef
define linkerxx_template
$(1): $(filter-out -%,$(2))
$(1):
$(if $(quiet),@echo " [LD] $$@")
$(qexec)g++ $$(strip $$(INTERNAL_LDFLAGS) $$(LDFLAGS) -o $$@ $(2) $(3) $$(extralibs))
endef
# make-3.80 has a bug with expanding large input strings to the eval function,
# which was triggered in some cases by the following component of
# linker_template:
......@@ -359,6 +378,7 @@ ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
endif
BUILD_TARGETS += .docs .libs .bins
INSTALL_TARGETS += .install-docs .install-srcs .install-libs .install-bins
all-$(target): $(BUILD_TARGETS)
all: $(BUILD_TARGETS)
install:: $(INSTALL_TARGETS)
dist: $(INSTALL_TARGETS)
test::
......@@ -544,7 +544,7 @@ generate_vcproj() {
close_tag Configurations
open_tag Files
generate_filter srcs "Source Files" "c;def;odl;idl;hpj;bat;asm;asmx"
generate_filter srcs "Source Files" "c;cc;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"
......
......@@ -22,6 +22,7 @@ show_help(){
Advanced options:
${toggle_libs} don't build libraries
${toggle_examples} don't build examples
${toggle_unit_tests} build unit tests
--libc=PATH path to alternate libc
--as={yasm|nasm|auto} use specified assembler [auto, yasm preferred]
${toggle_fast_unaligned} don't use unaligned accesses, even when
......@@ -223,6 +224,15 @@ EXPERIMENT_LIST="
high_precision_mv
sixteenth_subpel_uv
comp_intra_pred
newentropy
newupdate
superblocks
expanded_coef_context
int_8x8fdct
newintramodes
adaptive_entropy
pred_filter
lossless
"
CONFIG_LIST="
external_build
......@@ -263,7 +273,7 @@ CONFIG_LIST="
small
postproc_visualizer
os_support
unit_tests
experimental
${EXPERIMENT_LIST}
"
......@@ -304,6 +314,7 @@ CMDLINE_SELECT="
static
small
postproc_visualizer
unit_tests
experimental
"
......@@ -324,7 +335,7 @@ process_cmdline() {
process_common_cmdline $opt
fi
;;
*) process_common_cmdline $opt
*) process_common_cmdline "$opt"
;;
esac
done
......
......@@ -17,6 +17,7 @@ else
ASM:=.asm
endif
CODEC_SRCS-yes += CHANGELOG
CODEC_SRCS-yes += libs.mk
include $(SRC_PATH_BARE)/vpx/vpx_codec.mk
......@@ -48,7 +49,6 @@ ifeq ($(CONFIG_VP8_DECODER),yes)
CODEC_SRCS-yes += $(addprefix $(VP8_PREFIX),$(call enabled,VP8_DX_SRCS))
CODEC_EXPORTS-yes += $(addprefix $(VP8_PREFIX),$(VP8_DX_EXPORTS))
CODEC_SRCS-yes += $(VP8_PREFIX)vp8dx.mk vpx/vp8.h vpx/vp8dx.h
CODEC_SRCS-$(ARCH_ARM) += $(VP8_PREFIX)vp8dx_arm.mk
INSTALL-LIBS-yes += include/vpx/vp8.h include/vpx/vp8dx.h
INSTALL_MAPS += include/vpx/% $(SRC_PATH_BARE)/$(VP8_PREFIX)/%
CODEC_DOC_SRCS += vpx/vp8.h vpx/vp8dx.h
......@@ -66,6 +66,7 @@ endif
ifeq ($(CONFIG_MSVS),yes)
CODEC_LIB=$(if $(CONFIG_STATIC_MSVCRT),vpxmt,vpxmd)
GTEST_LIB=$(if $(CONFIG_STATIC_MSVCRT),gtestmt,gtestmd)
# This variable uses deferred expansion intentionally, since the results of
# $(wildcard) may change during the course of the Make.
VS_PLATFORMS = $(foreach d,$(wildcard */Release/$(CODEC_LIB).lib),$(word 1,$(subst /, ,$(d))))
......@@ -100,6 +101,7 @@ ifeq ($(ARCH_X86)$(ARCH_X86_64),yes)
CODEC_SRCS-$(BUILD_LIBVPX) += vpx_ports/emms.asm
CODEC_SRCS-$(BUILD_LIBVPX) += vpx_ports/x86.h
CODEC_SRCS-$(BUILD_LIBVPX) += vpx_ports/x86_abi_support.asm
CODEC_SRCS-$(BUILD_LIBVPX) += third_party/x86inc/x86inc.asm
CODEC_SRCS-$(BUILD_LIBVPX) += vpx_ports/x86_cpuid.c
endif
CODEC_SRCS-$(ARCH_ARM) += vpx_ports/arm_cpudetect.c
......@@ -128,7 +130,7 @@ INSTALL-LIBS-$(CONFIG_STATIC) += $(LIBSUBDIR)/libvpx.a
INSTALL-LIBS-$(CONFIG_DEBUG_LIBS) += $(LIBSUBDIR)/libvpx_g.a
endif
CODEC_SRCS=$(call enabled,CODEC_SRCS)
CODEC_SRCS=$(filter-out %_test.cc,$(call enabled,CODEC_SRCS))
INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(CODEC_SRCS)
INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(call enabled,CODEC_EXPORTS)
......@@ -232,7 +234,7 @@ vpx.pc: config.mk libs.mk
$(qexec)echo '# pkg-config file from libvpx $(VERSION_STRING)' > $@
$(qexec)echo 'prefix=$(PREFIX)' >> $@
$(qexec)echo 'exec_prefix=$${prefix}' >> $@
$(qexec)echo 'libdir=$${prefix}/lib' >> $@
$(qexec)echo 'libdir=$${prefix}/$(LIBSUBDIR)' >> $@
$(qexec)echo 'includedir=$${prefix}/include' >> $@
$(qexec)echo '' >> $@
$(qexec)echo 'Name: vpx' >> $@
......@@ -240,7 +242,7 @@ vpx.pc: config.mk libs.mk
$(qexec)echo 'Version: $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)' >> $@
$(qexec)echo 'Requires:' >> $@
$(qexec)echo 'Conflicts:' >> $@
$(qexec)echo 'Libs: -L$${libdir} -lvpx' >> $@
$(qexec)echo 'Libs: -L$${libdir} -lvpx -lm' >> $@
$(qexec)echo 'Cflags: -I$${includedir}' >> $@
INSTALL-LIBS-yes += $(LIBSUBDIR)/pkgconfig/vpx.pc
INSTALL_MAPS += $(LIBSUBDIR)/pkgconfig/%.pc %.pc
......@@ -279,40 +281,48 @@ $(filter %$(ASM).o,$(OBJS-yes)): $(BUILD_PFX)vpx_config.asm
# Calculate platform- and compiler-specific offsets for hand coded assembly
#
OFFSET_PATTERN:='^[a-zA-Z0-9_]* EQU'
ifeq ($(filter icc gcc,$(TGT_CC)), $(TGT_CC))
$(BUILD_PFX)asm_com_offsets.asm: $(BUILD_PFX)$(VP8_PREFIX)common/asm_com_offsets.c.S
grep -w EQU $< | tr -d '$$\#' $(ADS2GAS) > $@
@echo " [CREATE] $@"
$(qexec)LC_ALL=C grep $(OFFSET_PATTERN) $< | tr -d '$$\#' $(ADS2GAS) > $@
$(BUILD_PFX)$(VP8_PREFIX)common/asm_com_offsets.c.S: $(VP8_PREFIX)common/asm_com_offsets.c
CLEAN-OBJS += $(BUILD_PFX)asm_com_offsets.asm $(BUILD_PFX)$(VP8_PREFIX)common/asm_com_offsets.c.S
$(BUILD_PFX)asm_enc_offsets.asm: $(BUILD_PFX)$(VP8_PREFIX)encoder/asm_enc_offsets.c.S
grep -w EQU $< | tr -d '$$\#' $(ADS2GAS) > $@
@echo " [CREATE] $@"
$(qexec)LC_ALL=C grep $(OFFSET_PATTERN) $< | tr -d '$$\#' $(ADS2GAS) > $@
$(BUILD_PFX)$(VP8_PREFIX)encoder/asm_enc_offsets.c.S: $(VP8_PREFIX)encoder/asm_enc_offsets.c
CLEAN-OBJS += $(BUILD_PFX)asm_enc_offsets.asm $(BUILD_PFX)$(VP8_PREFIX)encoder/asm_enc_offsets.c.S
$(BUILD_PFX)asm_dec_offsets.asm: $(BUILD_PFX)$(VP8_PREFIX)decoder/asm_dec_offsets.c.S
grep -w EQU $< | tr -d '$$\#' $(ADS2GAS) > $@
@echo " [CREATE] $@"
$(qexec)LC_ALL=C grep $(OFFSET_PATTERN) $< | tr -d '$$\#' $(ADS2GAS) > $@
$(BUILD_PFX)$(VP8_PREFIX)decoder/asm_dec_offsets.c.S: $(VP8_PREFIX)decoder/asm_dec_offsets.c
CLEAN-OBJS += $(BUILD_PFX)asm_dec_offsets.asm $(BUILD_PFX)$(VP8_PREFIX)decoder/asm_dec_offsets.c.S
else
ifeq ($(filter rvct,$(TGT_CC)), $(TGT_CC))
asm_com_offsets.asm: obj_int_extract
asm_com_offsets.asm: $(VP8_PREFIX)common/asm_com_offsets.c.o
./obj_int_extract rvds $< $(ADS2GAS) > $@
@echo " [CREATE] $@"
$(qexec)./obj_int_extract rvds $< $(ADS2GAS) > $@
OBJS-yes += $(VP8_PREFIX)common/asm_com_offsets.c.o
CLEAN-OBJS += asm_com_offsets.asm
$(filter %$(ASM).o,$(OBJS-yes)): $(BUILD_PFX)asm_com_offsets.asm
asm_enc_offsets.asm: obj_int_extract
asm_enc_offsets.asm: $(VP8_PREFIX)encoder/asm_enc_offsets.c.o
./obj_int_extract rvds $< $(ADS2GAS) > $@
@echo " [CREATE] $@"
$(qexec)./obj_int_extract rvds $< $(ADS2GAS) > $@
OBJS-yes += $(VP8_PREFIX)encoder/asm_enc_offsets.c.o
CLEAN-OBJS += asm_enc_offsets.asm
$(filter %$(ASM).o,$(OBJS-yes)): $(BUILD_PFX)asm_enc_offsets.asm
asm_dec_offsets.asm: obj_int_extract
asm_dec_offsets.asm: $(VP8_PREFIX)decoder/asm_dec_offsets.c.o
./obj_int_extract rvds $< $(ADS2GAS) > $@
@echo " [CREATE] $@"
$(qexec)./obj_int_extract rvds $< $(ADS2GAS) > $@
OBJS-yes += $(VP8_PREFIX)decoder/asm_dec_offsets.c.o
CLEAN-OBJS += asm_dec_offsets.asm
$(filter %$(ASM).o,$(OBJS-yes)): $(BUILD_PFX)asm_dec_offsets.asm
......@@ -327,6 +337,130 @@ CODEC_DOC_SRCS += vpx/vpx_codec.h \
vpx/vpx_encoder.h \
vpx/vpx_image.h
##
## libvpx test directives
##
ifeq ($(CONFIG_UNIT_TESTS),yes)
LIBVPX_TEST_DATA_PATH ?= .
include $(SRC_PATH_BARE)/test/test.mk
LIBVPX_TEST_SRCS=$(addprefix test/,$(call enabled,LIBVPX_TEST_SRCS))
LIBVPX_TEST_BINS=./test_libvpx
LIBVPX_TEST_DATA=$(addprefix $(LIBVPX_TEST_DATA_PATH)/,\
$(call enabled,LIBVPX_TEST_DATA))
libvpx_test_data_url=http://downloads.webmproject.org/test_data/libvpx/$(1)
$(LIBVPX_TEST_DATA):
@echo " [DOWNLOAD] $@"
$(qexec)trap 'rm -f $@' INT TERM &&\
curl -L -o $@ $(call libvpx_test_data_url,$(@F))
testdata:: $(LIBVPX_TEST_DATA)
$(qexec)if [ -x "$$(which sha1sum)" ]; then\
echo "Checking test data:";\
(cd $(LIBVPX_TEST_DATA_PATH); sha1sum -c)\
< $(SRC_PATH_BARE)/test/test-data.sha1; \
else\
echo "Skipping test data integrity check, sha1sum not found.";\
fi
ifeq ($(CONFIG_EXTERNAL_BUILD),yes)
ifeq ($(CONFIG_MSVS),yes)
gtest.vcproj: $(SRC_PATH_BARE)/third_party/googletest/src/src/gtest-all.cc
@echo " [CREATE] $@"
$(SRC_PATH_BARE)/build/make/gen_msvs_proj.sh \
--lib \
--target=$(TOOLCHAIN) \
$(if $(CONFIG_STATIC_MSVCRT),--static-crt) \
--name=gtest \
--proj-guid=EC00E1EC-AF68-4D92-A255-181690D1C9B1 \
--ver=$(CONFIG_VS_VERSION) \
--src-path-bare="$(SRC_PATH_BARE)" \
--out=gtest.vcproj $(SRC_PATH_BARE)/third_party/googletest/src/src/gtest-all.cc \
-I. -I"$(SRC_PATH_BARE)/third_party/googletest/src/include" -I"$(SRC_PATH_BARE)/third_party/googletest/src"
PROJECTS-$(CONFIG_MSVS) += gtest.vcproj
test_libvpx.vcproj: $(LIBVPX_TEST_SRCS)
@echo " [CREATE] $@"
$(SRC_PATH_BARE)/build/make/gen_msvs_proj.sh \
--exe \
--target=$(TOOLCHAIN) \
--name=test_libvpx \
--proj-guid=CD837F5F-52D8-4314-A370-895D614166A7 \
--ver=$(CONFIG_VS_VERSION) \
$(if $(CONFIG_STATIC_MSVCRT),--static-crt) \
--out=$@ $(INTERNAL_CFLAGS) $(CFLAGS) \
-I. -I"$(SRC_PATH_BARE)/third_party/googletest/src/include" \
-L. -l$(CODEC_LIB) -lwinmm -l$(GTEST_LIB) $^
ifeq ($(CONFIG_STATIC_MSVCRT),--static-crt)
lib_sfx=mt
else
lib_sfx=md
endif
define unit_test_vcproj_template
$(notdir $(1:.cc=.vcproj)): $(SRC_PATH_BARE)/$(1)
@echo " [vcproj] $$@"
$$(SRC_PATH_BARE)/build/make/gen_msvs_proj.sh\
--exe\
--target=$$(TOOLCHAIN)\
--name=$(notdir $(1:.cc=))\
--ver=$$(CONFIG_VS_VERSION)\
$$(if $$(CONFIG_STATIC_MSVCRT),--static-crt) \
--out=$$@ $$(INTERNAL_CFLAGS) $$(CFLAGS) \
-I. -I"$(SRC_PATH_BARE)/third_party/googletest/src/include" \
-L. -lvpxmd -lwinmm -lgtest$(lib_sfx) $$^
endef
$(foreach proj,$(LIBVPX_TEST_BINS),\
$(eval $(call unit_test_vcproj_template,$(proj))))
PROJECTS-$(CONFIG_MSVS) += test_libvpx.vcproj
test:: testdata
@set -e; for t in $(addprefix Win32/Release/,$(notdir $(LIBVPX_TEST_BINS:.cc=.exe))); do $$t; done
endif
else
include $(SRC_PATH_BARE)/third_party/googletest/gtest.mk
GTEST_SRCS := $(addprefix third_party/googletest/src/,$(call enabled,GTEST_SRCS))
GTEST_OBJS=$(call objs,$(GTEST_SRCS))
$(GTEST_OBJS) $(GTEST_OBJS:.o=.d): CFLAGS += -I$(SRC_PATH_BARE)/third_party/googletest/src
$(GTEST_OBJS) $(GTEST_OBJS:.o=.d): CFLAGS += -I$(SRC_PATH_BARE)/third_party/googletest/src/include
OBJS-$(BUILD_LIBVPX) += $(GTEST_OBJS)
LIBS-$(BUILD_LIBVPX) += $(BUILD_PFX)libgtest.a $(BUILD_PFX)libgtest_g.a
$(BUILD_PFX)libgtest_g.a: $(GTEST_OBJS)
LIBVPX_TEST_OBJS=$(sort $(call objs,$(LIBVPX_TEST_SRCS)))
$(LIBVPX_TEST_OBJS) $(LIBVPX_TEST_OBJS:.o=.d): CFLAGS += -I$(SRC_PATH_BARE)/third_party/googletest/src
$(LIBVPX_TEST_OBJS) $(LIBVPX_TEST_OBJS:.o=.d): CFLAGS += -I$(SRC_PATH_BARE)/third_party/googletest/src/include
OBJS-$(BUILD_LIBVPX) += $(LIBVPX_TEST_OBJS)
# Install test sources only if codec source is included
INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(patsubst $(SRC_PATH_BARE)/%,%,\
$(shell find $(SRC_PATH_BARE)/third_party/googletest -type f))
INSTALL-SRCS-$(CONFIG_CODEC_SRCS) += $(LIBVPX_TEST_SRCS)
$(foreach bin,$(LIBVPX_TEST_BINS),\
$(if $(BUILD_LIBVPX),$(eval $(bin): libvpx.a libgtest.a ))\
$(if $(BUILD_LIBVPX),$(eval $(call linkerxx_template,$(bin),\
$(LIBVPX_TEST_OBJS) \
-L. -lvpx -lgtest -lpthread -lm)\
)))\
$(if $(LIPO_LIBS),$(eval $(call lipo_bin_template,$(bin))))\
test:: $(LIBVPX_TEST_BINS) testdata
@set -e; for t in $(LIBVPX_TEST_BINS); do $$t; done
endif
endif
##
## documentation directives
##
CLEAN-OBJS += libs.doxy
DOCS-yes += libs.doxy
libs.doxy: $(CODEC_DOC_SRCS)
......
......@@ -13,11 +13,13 @@ vpx.sln: $(wildcard *.vcproj)
@echo " [CREATE] $@"
$(SRC_PATH_BARE)/build/make/gen_msvs_sln.sh \
$(if $(filter %vpx.vcproj,$^),\
$(foreach vcp,$(filter-out %vpx.vcproj %obj_int_extract.vcproj,$^),\
--dep=$(vcp:.vcproj=):vpx)) \
--dep=vpx:obj_int_extract \
--ver=$(CONFIG_VS_VERSION)\
--out=$@ $^
$(foreach vcp,$(filter-out %vpx.vcproj %gtest.vcproj %obj_int_extract.vcproj,$^),\
--dep=$(vcp:.vcproj=):vpx) \
$(foreach vcp,$(filter %_test.vcproj,$^),\
--dep=$(vcp:.vcproj=):gtest)) \
--dep=vpx:obj_int_extract \
--ver=$(CONFIG_VS_VERSION)\
--out=$@ $^
vpx.sln.mk: vpx.sln
@true
......
/*
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
* Copyright (c) 2012 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
......@@ -8,26 +8,30 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef LIBVPX_TEST_ACM_RANDOM_H_
#define LIBVPX_TEST_ACM_RANDOM_H_
#ifndef _littlend_h
#define _littlend_h
#include <stdlib.h>
#if defined(__cplusplus)
extern "C" {
#endif
#include "vpx/vpx_integer.h"
#define invert2(x) (x)
#define invert4(x) (x)
namespace libvpx_test {
#define low_byte(x) (unsigned char)x
#define mid1Byte(x) (unsigned char)(x >> 8)
#define mid2Byte(x) (unsigned char)(x >> 16)
#define high_byte(x) (unsigned char)(x >> 24)
class ACMRandom {
public:
explicit ACMRandom(int seed) { Reset(seed); }
#define SWAPENDS 0
void Reset(int seed) { srand(seed); }
#if defined(__cplusplus)
}
#endif
uint8_t Rand8(void) { return (rand() >> 8) & 0xff; }
#endif
int PseudoUniform(int range) { return (rand() >> 8) % range; }
int operator()(int n) { return PseudoUniform(n); }
static int DeterministicSeed(void) { return 0xbaba; }
};
} // namespace libvpx_test
#endif // LIBVPX_TEST_ACM_RANDOM_H_
/*
* Copyright (c) 2012 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "third_party/googletest/src/include/gtest/gtest.h"
extern "C" {
#include "vp8/encoder/boolhuff.h"
#include "vp8/decoder/dboolhuff.h"
}
#include "acm_random.h"
#include "vpx/vpx_integer.h"
using libvpx_test::ACMRandom;
namespace {
const int num_tests = 10;
} // namespace
TEST(VP8, TestBitIO) {
ACMRandom rnd(ACMRandom::DeterministicSeed());
for (int n = 0; n < num_tests; ++n) {
for (int method = 0; method <= 7; ++method) { // we generate various proba
const int bits_to_test = 1000;
uint8_t probas[bits_to_test];
for (int i = 0; i < bits_to_test; ++i) {
const int parity = i & 1;
probas[i] =
(method == 0) ? 0 : (method == 1) ? 255 :
(method == 2) ? 128 :
(method == 3) ? rnd.Rand8() :
(method == 4) ? (parity ? 0 : 255) :
// alternate between low and high proba:
(method == 5) ? (parity ? rnd(128) : 255 - rnd(128)) :
(method == 6) ?
(parity ? rnd(64) : 255 - rnd(64)) :
(parity ? rnd(32) : 255 - rnd(32));
}
for (int bit_method = 0; bit_method <= 3; ++bit_method) {
const int random_seed = 6432;
const int buffer_size = 10000;
ACMRandom bit_rnd(random_seed);
BOOL_CODER bw;
uint8_t bw_buffer[buffer_size];
vp8_start_encode(&bw, bw_buffer);
int bit = (bit_method == 0) ? 0 : (bit_method == 1) ? 1 : 0;
for (int i = 0; i < bits_to_test; ++i) {
if (bit_method == 2) {
bit = (i & 1);
} else if (bit_method == 3) {
bit = bit_rnd(2);
}
vp8_encode_bool(&bw, bit, static_cast<int>(probas[i]));
}
vp8_stop_encode(&bw);
BOOL_DECODER br;
vp8dx_start_decode(&br, bw_buffer, buffer_size);
bit_rnd.Reset(random_seed);
for (int i = 0; i < bits_to_test; ++i) {
if (bit_method == 2) {
bit = (i & 1);
} else if (bit_method == 3) {
bit = bit_rnd(2);
}
GTEST_ASSERT_EQ(vp8dx_decode_bool(&br, probas[i]), bit)
<< "pos: "<< i << " / " << bits_to_test
<< " bit_method: " << bit_method
<< " method: " << method;
}