From b244f39627e23961112ee002ba687bfcdb55fbd9 Mon Sep 17 00:00:00 2001 From: "Nathan E. Egge" Date: Tue, 6 Sep 2016 23:48:43 -0400 Subject: [PATCH] Change return type of tell and tell_frac to uint32_t. The bit accounting functions aom_reader_tell() and aom_reader_tell_frac() return the number of bits and 1/8th bits respectively. This patch changes the return type from ptrdiff_t which is signed to uint32_t which is unsigned. The size_t type is not used since we only care about the number of bits or 1/8 bits per entropy coder context and we don't expect to code more than 512 megabits per tile. Change-Id: I84a119d1f52829dcbdb66a92656eacca06e42b11 --- aom_dsp/bitreader.h | 4 ++-- aom_dsp/daalaboolreader.c | 4 ++-- aom_dsp/daalaboolreader.h | 4 ++-- aom_dsp/dkboolreader.h | 8 +++++--- test/boolcoder_test.cc | 14 +++++++------- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/aom_dsp/bitreader.h b/aom_dsp/bitreader.h index 68e133930..d0282f563 100644 --- a/aom_dsp/bitreader.h +++ b/aom_dsp/bitreader.h @@ -103,7 +103,7 @@ static INLINE int aom_reader_has_error(aom_reader *r) { } // Returns the position in the bit reader in bits. -static INLINE ptrdiff_t aom_reader_tell(const aom_reader *r) { +static INLINE uint32_t aom_reader_tell(const aom_reader *r) { #if CONFIG_ANS (void)r; assert(0 && "aom_reader_tell() is unimplemented for ANS"); @@ -116,7 +116,7 @@ static INLINE ptrdiff_t aom_reader_tell(const aom_reader *r) { } // Returns the position in the bit reader in 1/8th bits. -static INLINE ptrdiff_t aom_reader_tell_frac(const aom_reader *r) { +static INLINE uint32_t aom_reader_tell_frac(const aom_reader *r) { #if CONFIG_ANS (void)r; assert(0 && "aom_reader_tell_frac() is unimplemented for ANS"); diff --git a/aom_dsp/daalaboolreader.c b/aom_dsp/daalaboolreader.c index f0da8eb1c..0fc7b14a5 100644 --- a/aom_dsp/daalaboolreader.c +++ b/aom_dsp/daalaboolreader.c @@ -28,10 +28,10 @@ const uint8_t *aom_daala_reader_find_end(daala_reader *r) { return r->buffer_end; } -ptrdiff_t aom_daala_reader_tell(const daala_reader *r) { +uint32_t aom_daala_reader_tell(const daala_reader *r) { return od_ec_dec_tell(&r->ec); } -ptrdiff_t aom_daala_reader_tell_frac(const daala_reader *r) { +uint32_t aom_daala_reader_tell_frac(const daala_reader *r) { return od_ec_dec_tell_frac(&r->ec); } diff --git a/aom_dsp/daalaboolreader.h b/aom_dsp/daalaboolreader.h index 10dc391d7..9d6cebdbe 100644 --- a/aom_dsp/daalaboolreader.h +++ b/aom_dsp/daalaboolreader.h @@ -36,8 +36,8 @@ typedef struct daala_reader daala_reader; int aom_daala_reader_init(daala_reader *r, const uint8_t *buffer, int size); const uint8_t *aom_daala_reader_find_end(daala_reader *r); -ptrdiff_t aom_daala_reader_tell(const daala_reader *r); -ptrdiff_t aom_daala_reader_tell_frac(const daala_reader *r); +uint32_t aom_daala_reader_tell(const daala_reader *r); +uint32_t aom_daala_reader_tell_frac(const daala_reader *r); static INLINE int aom_daala_read(daala_reader *r, int prob) { if (prob == 128) { diff --git a/aom_dsp/dkboolreader.h b/aom_dsp/dkboolreader.h index bc4b02f48..add480a5d 100644 --- a/aom_dsp/dkboolreader.h +++ b/aom_dsp/dkboolreader.h @@ -12,6 +12,7 @@ #ifndef AOM_DSP_DKBOOLREADER_H_ #define AOM_DSP_DKBOOLREADER_H_ +#include #include #include @@ -67,10 +68,11 @@ void aom_dk_reader_fill(struct aom_dk_reader *r); const uint8_t *aom_dk_reader_find_end(struct aom_dk_reader *r); -static INLINE ptrdiff_t aom_dk_reader_tell(const struct aom_dk_reader *r) { - const size_t bits_read = (r->buffer - r->buffer_start) * CHAR_BIT; +static INLINE uint32_t aom_dk_reader_tell(const struct aom_dk_reader *r) { + const uint32_t bits_read = (r->buffer - r->buffer_start) * CHAR_BIT; const int count = (r->count < LOTS_OF_BITS) ? r->count : r->count - LOTS_OF_BITS; + assert(r->buffer >= r->buffer_start); return bits_read - (count + CHAR_BIT); } @@ -78,7 +80,7 @@ static INLINE ptrdiff_t aom_dk_reader_tell(const struct aom_dk_reader *r) { 3 => 1/8th bits.*/ #define DK_BITRES (3) -static INLINE ptrdiff_t aom_dk_reader_tell_frac(const struct aom_dk_reader *r) { +static INLINE uint32_t aom_dk_reader_tell_frac(const struct aom_dk_reader *r) { uint32_t num_bits; uint32_t range; int l; diff --git a/test/boolcoder_test.cc b/test/boolcoder_test.cc index 1000f585a..ef295badc 100644 --- a/test/boolcoder_test.cc +++ b/test/boolcoder_test.cc @@ -110,15 +110,15 @@ TEST(AV1, TestTell) { aom_stop_encode(&bw); aom_reader br; aom_reader_init(&br, bw_buffer, kBufferSize, NULL, NULL); - ptrdiff_t last_tell = aom_reader_tell(&br); - ptrdiff_t last_tell_frac = aom_reader_tell_frac(&br); + uint32_t last_tell = aom_reader_tell(&br); + uint32_t last_tell_frac = aom_reader_tell_frac(&br); double frac_diff_total = 0; - GTEST_ASSERT_GE(aom_reader_tell(&br), 0); - GTEST_ASSERT_LE(aom_reader_tell(&br), 1); + GTEST_ASSERT_GE(aom_reader_tell(&br), 0u); + GTEST_ASSERT_LE(aom_reader_tell(&br), 1u); for (int i = 0; i < kSymbols; i++) { aom_read(&br, p, NULL); - ptrdiff_t tell = aom_reader_tell(&br); - ptrdiff_t tell_frac = aom_reader_tell_frac(&br); + uint32_t tell = aom_reader_tell(&br); + uint32_t tell_frac = aom_reader_tell_frac(&br); GTEST_ASSERT_GE(tell, last_tell) << "tell: " << tell << ", last_tell: " << last_tell; GTEST_ASSERT_GE(tell_frac, last_tell_frac) @@ -131,7 +131,7 @@ TEST(AV1, TestTell) { fabs(((tell_frac - last_tell_frac) / 8.0) + log2(probability)); last_tell_frac = tell_frac; } - const int expected = (int)(-kSymbols * log2(probability)); + const uint32_t expected = (uint32_t)(-kSymbols * log2(probability)); // Last tell should be close to the expected value. GTEST_ASSERT_LE(last_tell - expected, 20) << " last_tell: " << last_tell; // The average frac_diff error should be pretty small.