1 // Copyright (c) 2016 The WebM project authors. All Rights Reserved.
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS. All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree.
13 #include "mkvparser/mkvparser.h"
16 bool CopyPrimaryChromaticity(const mkvparser::PrimaryChromaticity& parser_pc,
17 PrimaryChromaticityPtr* muxer_pc) {
18 muxer_pc->reset(new (std::nothrow)
19 mkvmuxer::PrimaryChromaticity(parser_pc.x, parser_pc.y));
25 bool MasteringMetadataValuePresent(double value) {
26 return value != mkvparser::MasteringMetadata::kValueNotPresent;
29 bool CopyMasteringMetadata(const mkvparser::MasteringMetadata& parser_mm,
30 mkvmuxer::MasteringMetadata* muxer_mm) {
31 if (MasteringMetadataValuePresent(parser_mm.luminance_max))
32 muxer_mm->luminance_max = parser_mm.luminance_max;
33 if (MasteringMetadataValuePresent(parser_mm.luminance_min))
34 muxer_mm->luminance_min = parser_mm.luminance_min;
36 PrimaryChromaticityPtr r_ptr(NULL);
37 PrimaryChromaticityPtr g_ptr(NULL);
38 PrimaryChromaticityPtr b_ptr(NULL);
39 PrimaryChromaticityPtr wp_ptr(NULL);
42 if (!CopyPrimaryChromaticity(*parser_mm.r, &r_ptr))
46 if (!CopyPrimaryChromaticity(*parser_mm.g, &g_ptr))
50 if (!CopyPrimaryChromaticity(*parser_mm.b, &b_ptr))
53 if (parser_mm.white_point) {
54 if (!CopyPrimaryChromaticity(*parser_mm.white_point, &wp_ptr))
58 if (!muxer_mm->SetChromaticity(r_ptr.get(), g_ptr.get(), b_ptr.get(),
66 bool ColourValuePresent(long long value) {
67 return value != mkvparser::Colour::kValueNotPresent;
70 bool CopyColour(const mkvparser::Colour& parser_colour,
71 mkvmuxer::Colour* muxer_colour) {
75 if (ColourValuePresent(parser_colour.matrix_coefficients))
76 muxer_colour->matrix_coefficients = parser_colour.matrix_coefficients;
77 if (ColourValuePresent(parser_colour.bits_per_channel))
78 muxer_colour->bits_per_channel = parser_colour.bits_per_channel;
79 if (ColourValuePresent(parser_colour.chroma_subsampling_horz))
80 muxer_colour->chroma_subsampling_horz =
81 parser_colour.chroma_subsampling_horz;
82 if (ColourValuePresent(parser_colour.chroma_subsampling_vert))
83 muxer_colour->chroma_subsampling_vert =
84 parser_colour.chroma_subsampling_vert;
85 if (ColourValuePresent(parser_colour.cb_subsampling_horz))
86 muxer_colour->cb_subsampling_horz = parser_colour.cb_subsampling_horz;
87 if (ColourValuePresent(parser_colour.cb_subsampling_vert))
88 muxer_colour->cb_subsampling_vert = parser_colour.cb_subsampling_vert;
89 if (ColourValuePresent(parser_colour.chroma_siting_horz))
90 muxer_colour->chroma_siting_horz = parser_colour.chroma_siting_horz;
91 if (ColourValuePresent(parser_colour.chroma_siting_vert))
92 muxer_colour->chroma_siting_vert = parser_colour.chroma_siting_vert;
93 if (ColourValuePresent(parser_colour.range))
94 muxer_colour->range = parser_colour.range;
95 if (ColourValuePresent(parser_colour.transfer_characteristics))
96 muxer_colour->transfer_characteristics =
97 parser_colour.transfer_characteristics;
98 if (ColourValuePresent(parser_colour.primaries))
99 muxer_colour->primaries = parser_colour.primaries;
100 if (ColourValuePresent(parser_colour.max_cll))
101 muxer_colour->max_cll = parser_colour.max_cll;
102 if (ColourValuePresent(parser_colour.max_fall))
103 muxer_colour->max_fall = parser_colour.max_fall;
105 if (parser_colour.mastering_metadata) {
106 mkvmuxer::MasteringMetadata muxer_mm;
107 if (!CopyMasteringMetadata(*parser_colour.mastering_metadata, &muxer_mm))
109 if (!muxer_colour->SetMasteringMetadata(muxer_mm))
115 // Format of VPx private data:
117 // 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
118 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
119 // | ID Byte | Length | |
120 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
122 // : Bytes 1..Length of Codec Feature :
124 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
127 // ID byte is an unsigned byte.
133 // The X bit is reserved.
135 // Currently only profile level is supported. ID byte must be set to 1, and
136 // length must be 1. Supported values are:
153 // See the following link for more information:
154 // http://www.webmproject.org/vp9/profiles/
155 int ParseVpxCodecPrivate(const uint8_t* private_data, int32_t length) {
156 const int kVpxCodecPrivateLength = 3;
157 if (!private_data || length != kVpxCodecPrivateLength)
160 const uint8_t id_byte = *private_data;
164 const int kVpxProfileLength = 1;
165 const uint8_t length_byte = private_data[1];
166 if (length_byte != kVpxProfileLength)
169 const int level = static_cast<int>(private_data[2]);
171 const int kNumLevels = 14;
172 const int levels[kNumLevels] = {10, 11, 20, 21, 30, 31, 40,
173 41, 50, 51, 52, 60, 61, 62};
175 for (int i = 0; i < kNumLevels; ++i) {
176 if (level == levels[i])
182 } // namespace libwebm