Add support to output sub-sample encryption information.

See http://wiki.webmproject.org/encryption/webm-subsample-encryption
for the format.

Change-Id: Ia5d6f3566b92c46911704108d3e86cd0fac9ee34
This commit is contained in:
Frank Galligan
2016-09-16 09:19:00 -07:00
parent 26f434423f
commit c97e3e7d60
3 changed files with 95 additions and 7 deletions

View File

@@ -12,6 +12,29 @@
namespace {
// Swaps unsigned 32 bit values to big endian if needed. Returns |value|
// unmodified if architecture is big endian. Returns swapped bytes of |value|
// if architecture is little endian. Returns 0 otherwise.
uint32_t swap32_check_little_endian(uint32_t value) {
// Check endianness.
union {
uint32_t val32;
uint8_t c[4];
} check;
check.val32 = 0x01234567U;
// Check for big endian.
if (check.c[3] == 0x67)
return value;
// Check for not little endian.
if (check.c[0] != 0x67)
return 0;
return value << 24 | ((value << 8) & 0x0000FF00U) |
((value >> 8) & 0x00FF0000U) | value >> 24;
}
// Swaps unsigned 64 bit values to big endian if needed. Returns |value|
// unmodified if architecture is big endian. Returns swapped bytes of |value|
// if architecture is little endian. Returns 0 otherwise.
@@ -43,6 +66,14 @@ uint64_t swap64_check_little_endian(uint64_t value) {
namespace libwebm {
uint32_t host_to_bigendian(uint32_t value) {
return swap32_check_little_endian(value);
}
uint32_t bigendian_to_host(uint32_t value) {
return swap32_check_little_endian(value);
}
uint64_t host_to_bigendian(uint64_t value) {
return swap64_check_little_endian(value);
}
@@ -51,4 +82,4 @@ uint64_t bigendian_to_host(uint64_t value) {
return swap64_check_little_endian(value);
}
} // namespace libwebm
} // namespace libwebm