Commit 9540d594 authored by Tom Finegan's avatar Tom Finegan

Support larger LEB128 integers.

Support values up to 2 ^ 56 - 1.

BUG=aomedia:1125

Change-Id: I7df39e5c918cc6f82d3911c8e91e0b5e529904d4
parent b4898193
......@@ -8,7 +8,6 @@
* Media Patent License 1.0 was not distributed with this source code in the
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
#ifndef AOM_AOM_INTEGER_H_
#define AOM_AOM_INTEGER_H_
......@@ -80,18 +79,18 @@ extern "C" {
#endif // __cplusplus
// Returns size of uint32_t when encoded using LEB128.
size_t aom_uleb_size_in_bytes(uint32_t value);
size_t aom_uleb_size_in_bytes(uint64_t value);
// Returns decoded LEB128 value.
void aom_uleb_decode(const uint8_t *buffer, size_t available, uint32_t *value);
void aom_uleb_decode(const uint8_t *buffer, size_t available, uint64_t *value);
// Encodes LEB128 integer. Returns 0 when successful, and -1 upon failure.
int aom_uleb_encode(uint32_t value, size_t available, uint8_t *coded_value,
int aom_uleb_encode(uint64_t value, size_t available, uint8_t *coded_value,
size_t *coded_size);
// Encodes LEB128 integer to size specified. Returns 0 when successful, and -1
// upon failure.
int aom_uleb_encode_fixed_size(uint32_t value, size_t available,
int aom_uleb_encode_fixed_size(uint64_t value, size_t available,
size_t pad_to_size, uint8_t *coded_value,
size_t *coded_size);
......
......@@ -10,12 +10,12 @@
*/
#include "aom/aom_integer.h"
static const size_t kMaximumLeb128Size = 4;
static const size_t kMaximumLeb128Value = 0xFFFFFFF; // 2^28 - 1
static const uint8_t kLeb128ByteMask = 0x7f; // Binary: 01111111
static const uint8_t kLeb128PadByte = 0x80; // Binary: 10000000
static const size_t kMaximumLeb128Size = 8;
static const uint64_t kMaximumLeb128Value = 0xFFFFFFFFFFFFFF; // 2 ^ 56 - 1
static const uint8_t kLeb128ByteMask = 0x7f; // Binary: 01111111
static const uint8_t kLeb128PadByte = 0x80; // Binary: 10000000
size_t aom_uleb_size_in_bytes(uint32_t value) {
size_t aom_uleb_size_in_bytes(uint64_t value) {
size_t size = 0;
do {
++size;
......@@ -23,7 +23,7 @@ size_t aom_uleb_size_in_bytes(uint32_t value) {
return size;
}
void aom_uleb_decode(const uint8_t *buffer, size_t available, uint32_t *value) {
void aom_uleb_decode(const uint8_t *buffer, size_t available, uint64_t *value) {
if (buffer && value) {
for (size_t i = 0; i < kMaximumLeb128Size && i < available; ++i) {
const uint8_t decoded_byte = *(buffer + i) & kLeb128ByteMask;
......@@ -33,7 +33,7 @@ void aom_uleb_decode(const uint8_t *buffer, size_t available, uint32_t *value) {
}
}
int aom_uleb_encode(uint32_t value, size_t available, uint8_t *coded_value,
int aom_uleb_encode(uint64_t value, size_t available, uint8_t *coded_value,
size_t *coded_size) {
const size_t leb_size = aom_uleb_size_in_bytes(value);
if (value > kMaximumLeb128Value || leb_size > kMaximumLeb128Size ||
......@@ -54,7 +54,7 @@ int aom_uleb_encode(uint32_t value, size_t available, uint8_t *coded_value,
return 0;
}
int aom_uleb_encode_fixed_size(uint32_t value, size_t available,
int aom_uleb_encode_fixed_size(uint64_t value, size_t available,
size_t pad_to_size, uint8_t *coded_value,
size_t *coded_size) {
if (!coded_value || !coded_size || available < pad_to_size ||
......
......@@ -22,7 +22,7 @@
#include "av1/decoder/decodeframe.h"
#if CONFIG_SCALABILITY
// picture prediction structures (0-12 are predefined) in scaiability metadata
// Picture prediction structures (0-12 are predefined) in scalability metadata.
typedef enum {
SCALABILITY_L1T2 = 0,
SCALABILITY_L1T3 = 1,
......@@ -281,7 +281,7 @@ void av1_decode_frame_from_obus(struct AV1Decoder *pbi, const uint8_t *data,
#if CONFIG_OBU_SIZING
// OBUs are preceded by an unsigned leb128 coded unsigned integer.
uint32_t u_obu_size = 0;
uint64_t u_obu_size = 0;
aom_uleb_decode(data, bytes_available, &u_obu_size);
const size_t obu_size = (size_t)u_obu_size;
const size_t length_field_size = aom_uleb_size_in_bytes(u_obu_size);
......
......@@ -18,7 +18,7 @@ const uint32_t kSizeTestNumValues = 6;
const uint32_t kSizeTestExpectedSizes[kSizeTestNumValues] = {
1, 1, 2, 3, 4, 5
};
const uint32_t kSizeTestInputs[kSizeTestNumValues] = {
const uint64_t kSizeTestInputs[kSizeTestNumValues] = {
0, 0x7f, 0x3fff, 0x1fffff, 0xffffff, 0x10000000
};
} // namespace
......@@ -26,8 +26,8 @@ const uint32_t kSizeTestInputs[kSizeTestNumValues] = {
TEST(AomLeb128, DecodeTest) {
const size_t num_leb128_bytes = 3;
const uint8_t leb128_bytes[num_leb128_bytes] = { 0xE5, 0x8E, 0x26 };
const uint32_t expected_value = 0x98765; // 624485
uint32_t value = 0;
const uint64_t expected_value = 0x98765; // 624485
uint64_t value = 0;
aom_uleb_decode(&leb128_bytes[0], num_leb128_bytes, &value);
ASSERT_EQ(expected_value, value);
......@@ -63,7 +63,7 @@ TEST(AomLeb128, EncDecTest) {
&bytes_written),
0);
ASSERT_EQ(bytes_written, 3u);
uint32_t decoded_value = 0;
uint64_t decoded_value = 0;
aom_uleb_decode(&write_buffer[0], bytes_written, &decoded_value);
ASSERT_EQ(value, decoded_value);
}
......@@ -96,7 +96,7 @@ TEST(AomLeb128, FixedSizeEncDecTest) {
&write_buffer[0], &bytes_written),
0);
ASSERT_EQ(bytes_written, 4u);
uint32_t decoded_value = 0;
uint64_t decoded_value = 0;
aom_uleb_decode(&write_buffer[0], bytes_written, &decoded_value);
ASSERT_EQ(value, decoded_value);
}
......
......@@ -170,8 +170,8 @@ bool DumpObu(const uint8_t *data, int length) {
}
#if CONFIG_OBU_SIZING
uint32_t obu_size = 0;
aom_uleb_decode(data + consumed, sizeof(obu_size), &obu_size);
uint64_t obu_size = 0;
aom_uleb_decode(data + consumed, remaining, &obu_size);
const int current_obu_length = static_cast<int>(obu_size);
const size_t length_field_size = aom_uleb_size_in_bytes(obu_size);
#else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment