summaryrefslogtreecommitdiff
path: root/third_party/libwebm/common/hdr_util.cc
diff options
context:
space:
mode:
authorJames Zern <jzern@google.com>2016-10-18 18:11:36 -0700
committerJames Zern <jzern@google.com>2016-10-18 18:11:36 -0700
commit68833c7f85781e8c667e37bc012ea322d88b2dc1 (patch)
treec03fa919f7cf195710f01a87f55fd999654562d7 /third_party/libwebm/common/hdr_util.cc
parenta60dd5c83a48f705db6060bc10d1b4cc5d75c53b (diff)
downloadlibvpx-68833c7f85781e8c667e37bc012ea322d88b2dc1.tar
libvpx-68833c7f85781e8c667e37bc012ea322d88b2dc1.tar.gz
libvpx-68833c7f85781e8c667e37bc012ea322d88b2dc1.tar.bz2
libvpx-68833c7f85781e8c667e37bc012ea322d88b2dc1.zip
third_party: roll libwebm snapshot
git log --no-merges 32d5ac4..9732ae9 9732ae9 EbmlElementSize: quiet uint64->int32 conv warning da04eba SetProjectionPrivate: quiet uint64->size_t conv warning 6db32d5 mkvparser,Projection::Parse: fix int->bool conv 3bb0dfa cosmetics: fix a couple lint warnings 0e179d6 update .clang-format fc5f88d Fix temp files being left on system. c04a134 Add support for overriding PixelWidth and PixelHeight. c0160e0 Add support to explicitly set segment duration. 02bc809 Add support to estimate file duration. c97e3e7 Add support to output sub-sample encryption information. 26f4344 MakeUID: quiet unused param warning in Android builds d6af52a Change check to fix compile error. 1720020 webm_parser: Add Mesh value for ProjectionType 78f2c5a webm_parser: Use ./ prefix for includes da62f65 webm_parser: Remove webm/ prefix from public includes e15e8f2 webm_parser: Update README build instructions 5023f2b mkvmuxer: Fix Colour::Valid() cf16204 mkvmuxer_tests: Actually test cue points in the cue point test. 93e9fb3 Validate Colour element values. 8036925 mkvparser_tests: Add Projection element test. f52d38c mkvparser_tests: Add Colour element test. 826436a mkvparser: minor SeekHead::Entry clean up. 24fb44a mkvmuxer_tests: Add Projection element test. 1e0a8ea mkvmuxer_tests: Add Colour element test. 0278616 mkvmuxer: Colour accessors/mutators. 2346f8f Add mkvparser wrapper functions. 54d6b6b webm_info: Add Projection element support. 65fee06 mkvmuxer_sample: Add support for Projection element. 9a3f2b5 mkvparser_sample: Add support for Projection element. 41e814a mkvparser: Add Projection element support. 483a0ff mkvmuxer: Add Projection element support. 676a713 Add support for the Projection element 725f362 mkvmuxer: Fix memory leak when Colour is set multiple times. fa182de mkvparser_sample: Add output of audio track codec private size. 8f521f2 mkvparser_tests: Add invalid BlockGroup test. 39137d7 Remove docs saying binary elements default to 0 80685d3 Do not skip over unknown elements at the root level c147504 Fix legacy Makefile. 58711e8 mkvparser_sample: Fix version info string. 837746f mkvparser_tests: Add invalid block test. 207cd80 Disambiguate sample sources and targets. a112d71 mkvparser_tests: Refactor invalid file loading code. 5dea33e Disambiguate test source and target names. 125049e parser_tests: Add another truncated chapter string test. 1de8d4c parser_tests: Add truncated chapter string test. ff8c2b6 parser_tests: Move cue validation to test_util. 4b0690f parser_tests: Add invalid lacing test. 9828e39 mkvmuxer: Set default doc type version to 4. 5495a59 webm_parser: Reference more files in CMakeLists.txt. 0c0ecd0 vpxpes_parser: Add start code emulation prevention support. 639a4bc webm2pes: Remove debug printfs(). 9a51102 webm2pes: fflush() in the correct conversion function. dc7f155 webm2pes: Track total bytes written. d518128 webm_parser: Enable usage of werror. e1fe762 webm2pes: Add test for mux/demux of large input. 1b24a79 vpxpes_parser: Read and store PTS when present. 6cf0a0f vpxpes_parser: Store frame payloads. 25d2602 webm_parser: Convert style to match the rest of libwebm 24be76d webm2pes: Replace VpxFrame with VideoFrame. b451c3b Add a basic video frame storage class. 05c90eb libwebm_util: Clarify error text in superframe parser. e6415af webm2pes: Make WritePesPacket() a public method. 8f840dd webm2pes: Move frame read out of PES packet write method. 448af97 webm2pes: Restore frame fragmentation support. f8bb714 cmake: Integrate new parsing API and tests. cb8ce0b Add a new incremental parsing API 900d322 vpxpes_parser/webm2pes: BCMV and PTS fixes. 4b73545 webm2pes: Add start code emulation prevention. 82903f3 Add column tiles and frame parallel to webm_info 5d91edf style_clean_up: Remove unnecessary parentheses a95aa4b vp9_level_stats: correct total_uncompressed_bits_ calculation f46566f mkvreader: Fix shorten-64-to-32 warning in 32 bit builds. 76630ca mkvwriter: Fix shorten-64-to-32 warning in 32 bit builds. a8ffbd4 webm2pes: Fix format specifier warnings. faf89d4 Add MaxLumaSampleRate grace percent to stats. d31e6c9 Fix profile 2 in vp9_header_parser. bd3ab3a Add flag to estimate last frame's duration to stats. c182ed9 Fix lint issue in hdr_util.h cc62ecd Add test for Cluster memory leak 196708a Change MaxLumaSampleRate to be based on frame resolution. cbd676b mkvmuxer: Fix leak when a Cluster isn't finalized 9a235e0 mkvmuxer: Set doctype to matroska when muxing non-WebM codecs. 47f2843 Add parsing support for new features in CodecPrivate. e3c9576 Add VP9 level output to webm_info. 5cf549f cmake: Log compiler flag at check time. bbaaf2d Add class to gather VP9 level stats. 8bb68c2 Add file to parse data from VP9 frames. 296429a Add support to parse VP9 profile. df3412f Add support for setting VP9 profile and level to sample_muxer. 87832d4 mkvmuxer: Fix Segment::Finalize in kLive mode 6df3e56 mkvmuxerutil.hpp: Add using directives for overloaded size utils. ec47928 mkvmuxerutil: Revert to using mkvmuxertypes. a1dc4f2 Fix parsing of VP9 level. 4e3d037 Add support to output Colour elements to webm_info. d3656fd muxer_tests: ignore iwyu re gtest-message.h e76dd5e Fix file name in mkvmuxertypes shim. 1be5889 Add temporary include shims at old file locations. 039df94 Add TEST_TMPDIR environment variable Change-Id: I84bc1401b0aad71ad6727b687f1bede9953a7a08
Diffstat (limited to 'third_party/libwebm/common/hdr_util.cc')
-rw-r--r--third_party/libwebm/common/hdr_util.cc168
1 files changed, 103 insertions, 65 deletions
diff --git a/third_party/libwebm/common/hdr_util.cc b/third_party/libwebm/common/hdr_util.cc
index e1a9842fb..e1618ce75 100644
--- a/third_party/libwebm/common/hdr_util.cc
+++ b/third_party/libwebm/common/hdr_util.cc
@@ -7,12 +7,15 @@
// be found in the AUTHORS file in the root of the source tree.
#include "hdr_util.h"
+#include <climits>
#include <cstddef>
#include <new>
#include "mkvparser/mkvparser.h"
namespace libwebm {
+const int Vp9CodecFeatures::kValueNotPresent = INT_MAX;
+
bool CopyPrimaryChromaticity(const mkvparser::PrimaryChromaticity& parser_pc,
PrimaryChromaticityPtr* muxer_pc) {
muxer_pc->reset(new (std::nothrow)
@@ -29,9 +32,9 @@ bool MasteringMetadataValuePresent(double value) {
bool CopyMasteringMetadata(const mkvparser::MasteringMetadata& parser_mm,
mkvmuxer::MasteringMetadata* muxer_mm) {
if (MasteringMetadataValuePresent(parser_mm.luminance_max))
- muxer_mm->luminance_max = parser_mm.luminance_max;
+ muxer_mm->set_luminance_max(parser_mm.luminance_max);
if (MasteringMetadataValuePresent(parser_mm.luminance_min))
- muxer_mm->luminance_min = parser_mm.luminance_min;
+ muxer_mm->set_luminance_min(parser_mm.luminance_min);
PrimaryChromaticityPtr r_ptr(NULL);
PrimaryChromaticityPtr g_ptr(NULL);
@@ -73,34 +76,37 @@ bool CopyColour(const mkvparser::Colour& parser_colour,
return false;
if (ColourValuePresent(parser_colour.matrix_coefficients))
- muxer_colour->matrix_coefficients = parser_colour.matrix_coefficients;
+ muxer_colour->set_matrix_coefficients(parser_colour.matrix_coefficients);
if (ColourValuePresent(parser_colour.bits_per_channel))
- muxer_colour->bits_per_channel = parser_colour.bits_per_channel;
- if (ColourValuePresent(parser_colour.chroma_subsampling_horz))
- muxer_colour->chroma_subsampling_horz =
- parser_colour.chroma_subsampling_horz;
- if (ColourValuePresent(parser_colour.chroma_subsampling_vert))
- muxer_colour->chroma_subsampling_vert =
- parser_colour.chroma_subsampling_vert;
+ muxer_colour->set_bits_per_channel(parser_colour.bits_per_channel);
+ if (ColourValuePresent(parser_colour.chroma_subsampling_horz)) {
+ muxer_colour->set_chroma_subsampling_horz(
+ parser_colour.chroma_subsampling_horz);
+ }
+ if (ColourValuePresent(parser_colour.chroma_subsampling_vert)) {
+ muxer_colour->set_chroma_subsampling_vert(
+ parser_colour.chroma_subsampling_vert);
+ }
if (ColourValuePresent(parser_colour.cb_subsampling_horz))
- muxer_colour->cb_subsampling_horz = parser_colour.cb_subsampling_horz;
+ muxer_colour->set_cb_subsampling_horz(parser_colour.cb_subsampling_horz);
if (ColourValuePresent(parser_colour.cb_subsampling_vert))
- muxer_colour->cb_subsampling_vert = parser_colour.cb_subsampling_vert;
+ muxer_colour->set_cb_subsampling_vert(parser_colour.cb_subsampling_vert);
if (ColourValuePresent(parser_colour.chroma_siting_horz))
- muxer_colour->chroma_siting_horz = parser_colour.chroma_siting_horz;
+ muxer_colour->set_chroma_siting_horz(parser_colour.chroma_siting_horz);
if (ColourValuePresent(parser_colour.chroma_siting_vert))
- muxer_colour->chroma_siting_vert = parser_colour.chroma_siting_vert;
+ muxer_colour->set_chroma_siting_vert(parser_colour.chroma_siting_vert);
if (ColourValuePresent(parser_colour.range))
- muxer_colour->range = parser_colour.range;
- if (ColourValuePresent(parser_colour.transfer_characteristics))
- muxer_colour->transfer_characteristics =
- parser_colour.transfer_characteristics;
+ muxer_colour->set_range(parser_colour.range);
+ if (ColourValuePresent(parser_colour.transfer_characteristics)) {
+ muxer_colour->set_transfer_characteristics(
+ parser_colour.transfer_characteristics);
+ }
if (ColourValuePresent(parser_colour.primaries))
- muxer_colour->primaries = parser_colour.primaries;
+ muxer_colour->set_primaries(parser_colour.primaries);
if (ColourValuePresent(parser_colour.max_cll))
- muxer_colour->max_cll = parser_colour.max_cll;
+ muxer_colour->set_max_cll(parser_colour.max_cll);
if (ColourValuePresent(parser_colour.max_fall))
- muxer_colour->max_fall = parser_colour.max_fall;
+ muxer_colour->set_max_fall(parser_colour.max_fall);
if (parser_colour.mastering_metadata) {
mkvmuxer::MasteringMetadata muxer_mm;
@@ -116,8 +122,8 @@ bool CopyColour(const mkvparser::Colour& parser_colour,
//
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-// | ID Byte | Length | |
-// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
+// | ID Byte | Length | |
+// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
// | |
// : Bytes 1..Length of Codec Feature :
// | |
@@ -132,51 +138,83 @@ bool CopyColour(const mkvparser::Colour& parser_colour,
//
// The X bit is reserved.
//
-// Currently only profile level is supported. ID byte must be set to 1, and
-// length must be 1. Supported values are:
-//
-// 10: Level 1
-// 11: Level 1.1
-// 20: Level 2
-// 21: Level 2.1
-// 30: Level 3
-// 31: Level 3.1
-// 40: Level 4
-// 41: Level 4.1
-// 50: Level 5
-// 51: Level 5.1
-// 52: Level 5.2
-// 60: Level 6
-// 61: Level 6.1
-// 62: Level 6.2
-//
// See the following link for more information:
// http://www.webmproject.org/vp9/profiles/
-int ParseVpxCodecPrivate(const uint8_t* private_data, int32_t length) {
- const int kVpxCodecPrivateLength = 3;
- if (!private_data || length != kVpxCodecPrivateLength)
- return 0;
-
- const uint8_t id_byte = *private_data;
- if (id_byte != 1)
- return 0;
-
- const int kVpxProfileLength = 1;
- const uint8_t length_byte = private_data[1];
- if (length_byte != kVpxProfileLength)
- return 0;
-
- const int level = static_cast<int>(private_data[2]);
-
- const int kNumLevels = 14;
- const int levels[kNumLevels] = {10, 11, 20, 21, 30, 31, 40,
- 41, 50, 51, 52, 60, 61, 62};
+bool ParseVpxCodecPrivate(const uint8_t* private_data, int32_t length,
+ Vp9CodecFeatures* features) {
+ const int kVpxCodecPrivateMinLength = 3;
+ if (!private_data || !features || length < kVpxCodecPrivateMinLength)
+ return false;
- for (int i = 0; i < kNumLevels; ++i) {
- if (level == levels[i])
- return level;
- }
+ const uint8_t kVp9ProfileId = 1;
+ const uint8_t kVp9LevelId = 2;
+ const uint8_t kVp9BitDepthId = 3;
+ const uint8_t kVp9ChromaSubsamplingId = 4;
+ const int kVpxFeatureLength = 1;
+ int offset = 0;
+
+ // Set features to not set.
+ features->profile = Vp9CodecFeatures::kValueNotPresent;
+ features->level = Vp9CodecFeatures::kValueNotPresent;
+ features->bit_depth = Vp9CodecFeatures::kValueNotPresent;
+ features->chroma_subsampling = Vp9CodecFeatures::kValueNotPresent;
+ do {
+ const uint8_t id_byte = private_data[offset++];
+ const uint8_t length_byte = private_data[offset++];
+ if (length_byte != kVpxFeatureLength)
+ return false;
+ if (id_byte == kVp9ProfileId) {
+ const int priv_profile = static_cast<int>(private_data[offset++]);
+ if (priv_profile < 0 || priv_profile > 3)
+ return false;
+ if (features->profile != Vp9CodecFeatures::kValueNotPresent &&
+ features->profile != priv_profile) {
+ return false;
+ }
+ features->profile = priv_profile;
+ } else if (id_byte == kVp9LevelId) {
+ const int priv_level = static_cast<int>(private_data[offset++]);
+
+ const int kNumLevels = 14;
+ const int levels[kNumLevels] = {10, 11, 20, 21, 30, 31, 40,
+ 41, 50, 51, 52, 60, 61, 62};
+
+ for (int i = 0; i < kNumLevels; ++i) {
+ if (priv_level == levels[i]) {
+ if (features->level != Vp9CodecFeatures::kValueNotPresent &&
+ features->level != priv_level) {
+ return false;
+ }
+ features->level = priv_level;
+ break;
+ }
+ }
+ if (features->level == Vp9CodecFeatures::kValueNotPresent)
+ return false;
+ } else if (id_byte == kVp9BitDepthId) {
+ const int priv_profile = static_cast<int>(private_data[offset++]);
+ if (priv_profile != 8 && priv_profile != 10 && priv_profile != 12)
+ return false;
+ if (features->bit_depth != Vp9CodecFeatures::kValueNotPresent &&
+ features->bit_depth != priv_profile) {
+ return false;
+ }
+ features->bit_depth = priv_profile;
+ } else if (id_byte == kVp9ChromaSubsamplingId) {
+ const int priv_profile = static_cast<int>(private_data[offset++]);
+ if (priv_profile != 0 && priv_profile != 2 && priv_profile != 3)
+ return false;
+ if (features->chroma_subsampling != Vp9CodecFeatures::kValueNotPresent &&
+ features->chroma_subsampling != priv_profile) {
+ return false;
+ }
+ features->chroma_subsampling = priv_profile;
+ } else {
+ // Invalid ID.
+ return false;
+ }
+ } while (offset + kVpxCodecPrivateMinLength <= length);
- return 0;
+ return true;
}
} // namespace libwebm