Revert "third_party: Roll libwebm snapshot."

This reverts commit 808a560be6a71dd0d27f29c26f9fefb5e809d373.

causes build warnings under visual studio

Change-Id: I2e49a75d72469f316e8b01929b783e6f727f756c
This commit is contained in:
James Zern 2016-10-17 23:23:59 -07:00
parent f6980ca68e
commit 171e2ccf99
13 changed files with 488 additions and 1407 deletions

View File

@ -1,6 +1,5 @@
URL: https://chromium.googlesource.com/webm/libwebm
Version: fc5f88d3d1914e027456c069d91a0cd6c89dec85
Version: 32d5ac49414a8914ec1e1f285f3f927c6e8ec29d
License: BSD
License File: LICENSE.txt

View File

@ -14,7 +14,6 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <ios>
@ -22,23 +21,13 @@ namespace libwebm {
std::string GetTempFileName() {
#if !defined _MSC_VER && !defined __MINGW32__
std::string temp_file_name_template_str =
std::string(std::getenv("TEST_TMPDIR") ? std::getenv("TEST_TMPDIR") :
".") +
"/libwebm_temp.XXXXXX";
char* temp_file_name_template =
new char[temp_file_name_template_str.length() + 1];
memset(temp_file_name_template, 0, temp_file_name_template_str.length() + 1);
temp_file_name_template_str.copy(temp_file_name_template,
temp_file_name_template_str.length(), 0);
char temp_file_name_template[] = "libwebm_temp.XXXXXX";
int fd = mkstemp(temp_file_name_template);
std::string temp_file_name =
(fd != -1) ? std::string(temp_file_name_template) : std::string();
delete[] temp_file_name_template;
if (fd != -1) {
close(fd);
return std::string(temp_file_name_template);
}
return temp_file_name;
return std::string();
#else
char tmp_file_name[_MAX_PATH];
errno_t err = tmpnam_s(tmp_file_name);

View File

@ -7,15 +7,12 @@
// 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)
@ -32,9 +29,9 @@ bool MasteringMetadataValuePresent(double value) {
bool CopyMasteringMetadata(const mkvparser::MasteringMetadata& parser_mm,
mkvmuxer::MasteringMetadata* muxer_mm) {
if (MasteringMetadataValuePresent(parser_mm.luminance_max))
muxer_mm->set_luminance_max(parser_mm.luminance_max);
muxer_mm->luminance_max = parser_mm.luminance_max;
if (MasteringMetadataValuePresent(parser_mm.luminance_min))
muxer_mm->set_luminance_min(parser_mm.luminance_min);
muxer_mm->luminance_min = parser_mm.luminance_min;
PrimaryChromaticityPtr r_ptr(NULL);
PrimaryChromaticityPtr g_ptr(NULL);
@ -76,37 +73,34 @@ bool CopyColour(const mkvparser::Colour& parser_colour,
return false;
if (ColourValuePresent(parser_colour.matrix_coefficients))
muxer_colour->set_matrix_coefficients(parser_colour.matrix_coefficients);
muxer_colour->matrix_coefficients = parser_colour.matrix_coefficients;
if (ColourValuePresent(parser_colour.bits_per_channel))
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);
}
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;
if (ColourValuePresent(parser_colour.cb_subsampling_horz))
muxer_colour->set_cb_subsampling_horz(parser_colour.cb_subsampling_horz);
muxer_colour->cb_subsampling_horz = parser_colour.cb_subsampling_horz;
if (ColourValuePresent(parser_colour.cb_subsampling_vert))
muxer_colour->set_cb_subsampling_vert(parser_colour.cb_subsampling_vert);
muxer_colour->cb_subsampling_vert = parser_colour.cb_subsampling_vert;
if (ColourValuePresent(parser_colour.chroma_siting_horz))
muxer_colour->set_chroma_siting_horz(parser_colour.chroma_siting_horz);
muxer_colour->chroma_siting_horz = parser_colour.chroma_siting_horz;
if (ColourValuePresent(parser_colour.chroma_siting_vert))
muxer_colour->set_chroma_siting_vert(parser_colour.chroma_siting_vert);
muxer_colour->chroma_siting_vert = parser_colour.chroma_siting_vert;
if (ColourValuePresent(parser_colour.range))
muxer_colour->set_range(parser_colour.range);
if (ColourValuePresent(parser_colour.transfer_characteristics)) {
muxer_colour->set_transfer_characteristics(
parser_colour.transfer_characteristics);
}
muxer_colour->range = parser_colour.range;
if (ColourValuePresent(parser_colour.transfer_characteristics))
muxer_colour->transfer_characteristics =
parser_colour.transfer_characteristics;
if (ColourValuePresent(parser_colour.primaries))
muxer_colour->set_primaries(parser_colour.primaries);
muxer_colour->primaries = parser_colour.primaries;
if (ColourValuePresent(parser_colour.max_cll))
muxer_colour->set_max_cll(parser_colour.max_cll);
muxer_colour->max_cll = parser_colour.max_cll;
if (ColourValuePresent(parser_colour.max_fall))
muxer_colour->set_max_fall(parser_colour.max_fall);
muxer_colour->max_fall = parser_colour.max_fall;
if (parser_colour.mastering_metadata) {
mkvmuxer::MasteringMetadata muxer_mm;
@ -122,8 +116,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 :
// | |
@ -138,83 +132,51 @@ 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/
bool ParseVpxCodecPrivate(const uint8_t* private_data, int32_t length,
Vp9CodecFeatures* features) {
const int kVpxCodecPrivateMinLength = 3;
if (!private_data || !features || length < kVpxCodecPrivateMinLength)
return false;
int ParseVpxCodecPrivate(const uint8_t* private_data, int32_t length) {
const int kVpxCodecPrivateLength = 3;
if (!private_data || length != kVpxCodecPrivateLength)
return 0;
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;
const uint8_t id_byte = *private_data;
if (id_byte != 1)
return 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 kVpxProfileLength = 1;
const uint8_t length_byte = private_data[1];
if (length_byte != kVpxProfileLength)
return 0;
const int kNumLevels = 14;
const int levels[kNumLevels] = {10, 11, 20, 21, 30, 31, 40,
41, 50, 51, 52, 60, 61, 62};
const int level = static_cast<int>(private_data[2]);
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);
const int kNumLevels = 14;
const int levels[kNumLevels] = {10, 11, 20, 21, 30, 31, 40,
41, 50, 51, 52, 60, 61, 62};
return true;
for (int i = 0; i < kNumLevels; ++i) {
if (level == levels[i])
return level;
}
return 0;
}
} // namespace libwebm

View File

@ -28,25 +28,6 @@ namespace libwebm {
// TODO(tomfinegan): These should be moved to libwebm_utils once c++11 is
// required by libwebm.
// Features of the VP9 codec that may be set in the CodecPrivate of a VP9 video
// stream. A value of kValueNotPresent represents that the value was not set in
// the CodecPrivate.
struct Vp9CodecFeatures {
static const int kValueNotPresent;
Vp9CodecFeatures()
: profile(kValueNotPresent),
level(kValueNotPresent),
bit_depth(kValueNotPresent),
chroma_subsampling(kValueNotPresent) {}
~Vp9CodecFeatures() {}
int profile;
int level;
int bit_depth;
int chroma_subsampling;
};
typedef std::auto_ptr<mkvmuxer::PrimaryChromaticity> PrimaryChromaticityPtr;
bool CopyPrimaryChromaticity(const mkvparser::PrimaryChromaticity& parser_pc,
@ -62,9 +43,8 @@ bool ColourValuePresent(long long value);
bool CopyColour(const mkvparser::Colour& parser_colour,
mkvmuxer::Colour* muxer_colour);
// Returns true if |features| is set to one or more valid values.
bool ParseVpxCodecPrivate(const uint8_t* private_data, int32_t length,
Vp9CodecFeatures* features);
// Returns VP9 profile upon success or 0 upon failure.
int ParseVpxCodecPrivate(const uint8_t* private_data, int32_t length);
} // namespace libwebm

View File

@ -124,14 +124,6 @@ enum MkvId {
kMkvLuminanceMin = 0x55DA,
// end mastering metadata
// end colour
// projection
kMkvProjection = 0x7670,
kMkvProjectionType = 0x7671,
kMkvProjectionPrivate = 0x7672,
kMkvProjectionPoseYaw = 0x7673,
kMkvProjectionPosePitch = 0x7674,
kMkvProjectionPoseRoll = 0x7675,
// end projection
// audio
kMkvAudio = 0xE1,
kMkvSamplingFrequency = 0xB5,

File diff suppressed because it is too large Load Diff

View File

@ -64,12 +64,6 @@ class IMkvWriter {
LIBWEBM_DISALLOW_COPY_AND_ASSIGN(IMkvWriter);
};
// Writes out the EBML header for a WebM file, but allows caller to specify
// DocType. This function must be called before any other libwebm writing
// functions are called.
bool WriteEbmlHeader(IMkvWriter* writer, uint64_t doc_type_version,
const char* const doc_type);
// Writes out the EBML header for a WebM file. This function must be called
// before any other libwebm writing functions are called.
bool WriteEbmlHeader(IMkvWriter* writer, uint64_t doc_type_version);
@ -354,42 +348,26 @@ class ContentEncoding {
///////////////////////////////////////////////////////////////
// Colour element.
class PrimaryChromaticity {
public:
static const float kChromaticityMin;
static const float kChromaticityMax;
PrimaryChromaticity(float x_val, float y_val) : x_(x_val), y_(y_val) {}
PrimaryChromaticity() : x_(0), y_(0) {}
struct PrimaryChromaticity {
PrimaryChromaticity(float x_val, float y_val) : x(x_val), y(y_val) {}
PrimaryChromaticity() : x(0), y(0) {}
~PrimaryChromaticity() {}
// Returns sum of |x_id| and |y_id| element id sizes and payload sizes.
uint64_t PrimaryChromaticitySize(libwebm::MkvId x_id,
libwebm::MkvId y_id) const;
bool Valid() const;
uint64_t PrimaryChromaticityPayloadSize(libwebm::MkvId x_id,
libwebm::MkvId y_id) const;
bool Write(IMkvWriter* writer, libwebm::MkvId x_id,
libwebm::MkvId y_id) const;
float x() const { return x_; }
void set_x(float new_x) { x_ = new_x; }
float y() const { return y_; }
void set_y(float new_y) { y_ = new_y; }
private:
float x_;
float y_;
float x;
float y;
};
class MasteringMetadata {
public:
static const float kValueNotPresent;
static const float kMinLuminance;
static const float kMinLuminanceMax;
static const float kMaxLuminanceMax;
MasteringMetadata()
: luminance_max_(kValueNotPresent),
luminance_min_(kValueNotPresent),
: luminance_max(kValueNotPresent),
luminance_min(kValueNotPresent),
r_(NULL),
g_(NULL),
b_(NULL),
@ -403,7 +381,6 @@ class MasteringMetadata {
// Returns total size of the MasteringMetadata element.
uint64_t MasteringMetadataSize() const;
bool Valid() const;
bool Write(IMkvWriter* writer) const;
// Copies non-null chromaticity.
@ -416,21 +393,13 @@ class MasteringMetadata {
const PrimaryChromaticity* b() const { return b_; }
const PrimaryChromaticity* white_point() const { return white_point_; }
float luminance_max() const { return luminance_max_; }
void set_luminance_max(float luminance_max) {
luminance_max_ = luminance_max;
}
float luminance_min() const { return luminance_min_; }
void set_luminance_min(float luminance_min) {
luminance_min_ = luminance_min;
}
float luminance_max;
float luminance_min;
private:
// Returns size of MasteringMetadata child elements.
uint64_t PayloadSize() const;
float luminance_max_;
float luminance_min_;
PrimaryChromaticity* r_;
PrimaryChromaticity* g_;
PrimaryChromaticity* b_;
@ -439,90 +408,26 @@ class MasteringMetadata {
class Colour {
public:
enum MatrixCoefficients {
kGbr = 0,
kBt709 = 1,
kUnspecifiedMc = 2,
kReserved = 3,
kFcc = 4,
kBt470bg = 5,
kSmpte170MMc = 6,
kSmpte240MMc = 7,
kYcocg = 8,
kBt2020NonConstantLuminance = 9,
kBt2020ConstantLuminance = 10,
};
enum ChromaSitingHorz {
kUnspecifiedCsh = 0,
kLeftCollocated = 1,
kHalfCsh = 2,
};
enum ChromaSitingVert {
kUnspecifiedCsv = 0,
kTopCollocated = 1,
kHalfCsv = 2,
};
enum Range {
kUnspecifiedCr = 0,
kBroadcastRange = 1,
kFullRange = 2,
kMcTcDefined = 3, // Defined by MatrixCoefficients/TransferCharacteristics.
};
enum TransferCharacteristics {
kIturBt709Tc = 1,
kUnspecifiedTc = 2,
kReservedTc = 3,
kGamma22Curve = 4,
kGamma28Curve = 5,
kSmpte170MTc = 6,
kSmpte240MTc = 7,
kLinear = 8,
kLog = 9,
kLogSqrt = 10,
kIec6196624 = 11,
kIturBt1361ExtendedColourGamut = 12,
kIec6196621 = 13,
kIturBt202010bit = 14,
kIturBt202012bit = 15,
kSmpteSt2084 = 16,
kSmpteSt4281Tc = 17,
kAribStdB67Hlg = 18,
};
enum Primaries {
kReservedP0 = 0,
kIturBt709P = 1,
kUnspecifiedP = 2,
kReservedP3 = 3,
kIturBt470M = 4,
kIturBt470Bg = 5,
kSmpte170MP = 6,
kSmpte240MP = 7,
kFilm = 8,
kIturBt2020 = 9,
kSmpteSt4281P = 10,
kJedecP22Phosphors = 22,
};
static const uint64_t kValueNotPresent;
Colour()
: matrix_coefficients_(kValueNotPresent),
bits_per_channel_(kValueNotPresent),
chroma_subsampling_horz_(kValueNotPresent),
chroma_subsampling_vert_(kValueNotPresent),
cb_subsampling_horz_(kValueNotPresent),
cb_subsampling_vert_(kValueNotPresent),
chroma_siting_horz_(kValueNotPresent),
chroma_siting_vert_(kValueNotPresent),
range_(kValueNotPresent),
transfer_characteristics_(kValueNotPresent),
primaries_(kValueNotPresent),
max_cll_(kValueNotPresent),
max_fall_(kValueNotPresent),
: matrix_coefficients(kValueNotPresent),
bits_per_channel(kValueNotPresent),
chroma_subsampling_horz(kValueNotPresent),
chroma_subsampling_vert(kValueNotPresent),
cb_subsampling_horz(kValueNotPresent),
cb_subsampling_vert(kValueNotPresent),
chroma_siting_horz(kValueNotPresent),
chroma_siting_vert(kValueNotPresent),
range(kValueNotPresent),
transfer_characteristics(kValueNotPresent),
primaries(kValueNotPresent),
max_cll(kValueNotPresent),
max_fall(kValueNotPresent),
mastering_metadata_(NULL) {}
~Colour() { delete mastering_metadata_; }
// Returns total size of the Colour element.
uint64_t ColourSize() const;
bool Valid() const;
bool Write(IMkvWriter* writer) const;
// Deep copies |mastering_metadata|.
@ -532,124 +437,27 @@ class Colour {
return mastering_metadata_;
}
uint64_t matrix_coefficients() const { return matrix_coefficients_; }
void set_matrix_coefficients(uint64_t matrix_coefficients) {
matrix_coefficients_ = matrix_coefficients;
}
uint64_t bits_per_channel() const { return bits_per_channel_; }
void set_bits_per_channel(uint64_t bits_per_channel) {
bits_per_channel_ = bits_per_channel;
}
uint64_t chroma_subsampling_horz() const { return chroma_subsampling_horz_; }
void set_chroma_subsampling_horz(uint64_t chroma_subsampling_horz) {
chroma_subsampling_horz_ = chroma_subsampling_horz;
}
uint64_t chroma_subsampling_vert() const { return chroma_subsampling_vert_; }
void set_chroma_subsampling_vert(uint64_t chroma_subsampling_vert) {
chroma_subsampling_vert_ = chroma_subsampling_vert;
}
uint64_t cb_subsampling_horz() const { return cb_subsampling_horz_; }
void set_cb_subsampling_horz(uint64_t cb_subsampling_horz) {
cb_subsampling_horz_ = cb_subsampling_horz;
}
uint64_t cb_subsampling_vert() const { return cb_subsampling_vert_; }
void set_cb_subsampling_vert(uint64_t cb_subsampling_vert) {
cb_subsampling_vert_ = cb_subsampling_vert;
}
uint64_t chroma_siting_horz() const { return chroma_siting_horz_; }
void set_chroma_siting_horz(uint64_t chroma_siting_horz) {
chroma_siting_horz_ = chroma_siting_horz;
}
uint64_t chroma_siting_vert() const { return chroma_siting_vert_; }
void set_chroma_siting_vert(uint64_t chroma_siting_vert) {
chroma_siting_vert_ = chroma_siting_vert;
}
uint64_t range() const { return range_; }
void set_range(uint64_t range) { range_ = range; }
uint64_t transfer_characteristics() const {
return transfer_characteristics_;
}
void set_transfer_characteristics(uint64_t transfer_characteristics) {
transfer_characteristics_ = transfer_characteristics;
}
uint64_t primaries() const { return primaries_; }
void set_primaries(uint64_t primaries) { primaries_ = primaries; }
uint64_t max_cll() const { return max_cll_; }
void set_max_cll(uint64_t max_cll) { max_cll_ = max_cll; }
uint64_t max_fall() const { return max_fall_; }
void set_max_fall(uint64_t max_fall) { max_fall_ = max_fall; }
uint64_t matrix_coefficients;
uint64_t bits_per_channel;
uint64_t chroma_subsampling_horz;
uint64_t chroma_subsampling_vert;
uint64_t cb_subsampling_horz;
uint64_t cb_subsampling_vert;
uint64_t chroma_siting_horz;
uint64_t chroma_siting_vert;
uint64_t range;
uint64_t transfer_characteristics;
uint64_t primaries;
uint64_t max_cll;
uint64_t max_fall;
private:
// Returns size of Colour child elements.
uint64_t PayloadSize() const;
uint64_t matrix_coefficients_;
uint64_t bits_per_channel_;
uint64_t chroma_subsampling_horz_;
uint64_t chroma_subsampling_vert_;
uint64_t cb_subsampling_horz_;
uint64_t cb_subsampling_vert_;
uint64_t chroma_siting_horz_;
uint64_t chroma_siting_vert_;
uint64_t range_;
uint64_t transfer_characteristics_;
uint64_t primaries_;
uint64_t max_cll_;
uint64_t max_fall_;
MasteringMetadata* mastering_metadata_;
};
///////////////////////////////////////////////////////////////
// Projection element.
class Projection {
public:
enum ProjectionType {
kTypeNotPresent = -1,
kRectangular = 0,
kEquirectangular = 1,
kCubeMap = 2,
kMesh = 3,
};
static const uint64_t kValueNotPresent;
Projection()
: type_(kRectangular),
pose_yaw_(0.0),
pose_pitch_(0.0),
pose_roll_(0.0),
private_data_(NULL),
private_data_length_(0) {}
~Projection() { delete[] private_data_; }
uint64_t ProjectionSize() const;
bool Write(IMkvWriter* writer) const;
bool SetProjectionPrivate(const uint8_t* private_data,
uint64_t private_data_length);
ProjectionType type() const { return type_; }
void set_type(ProjectionType type) { type_ = type; }
float pose_yaw() const { return pose_yaw_; }
void set_pose_yaw(float pose_yaw) { pose_yaw_ = pose_yaw; }
float pose_pitch() const { return pose_pitch_; }
void set_pose_pitch(float pose_pitch) { pose_pitch_ = pose_pitch; }
float pose_roll() const { return pose_roll_; }
void set_pose_roll(float pose_roll) { pose_roll_ = pose_roll; }
uint8_t* private_data() const { return private_data_; }
uint64_t private_data_length() const { return private_data_length_; }
private:
// Returns size of VideoProjection child elements.
uint64_t PayloadSize() const;
ProjectionType type_;
float pose_yaw_;
float pose_pitch_;
float pose_roll_;
uint8_t* private_data_;
uint64_t private_data_length_;
};
///////////////////////////////////////////////////////////////
// Track element.
class Track {
@ -773,10 +581,6 @@ class VideoTrack : public Track {
uint64_t display_height() const { return display_height_; }
void set_display_width(uint64_t width) { display_width_ = width; }
uint64_t display_width() const { return display_width_; }
void set_pixel_height(uint64_t height) { pixel_height_ = height; }
uint64_t pixel_height() const { return pixel_height_; }
void set_pixel_width(uint64_t width) { pixel_width_ = width; }
uint64_t pixel_width() const { return pixel_width_; }
void set_crop_left(uint64_t crop_left) { crop_left_ = crop_left; }
uint64_t crop_left() const { return crop_left_; }
@ -801,11 +605,6 @@ class VideoTrack : public Track {
// Deep copies |colour|.
bool SetColour(const Colour& colour);
Projection* projection() { return projection_; };
// Deep copies |projection|.
bool SetProjection(const Projection& projection);
private:
// Returns the size in bytes of the Video element.
uint64_t VideoPayloadSize() const;
@ -813,8 +612,6 @@ class VideoTrack : public Track {
// Video track element names.
uint64_t display_height_;
uint64_t display_width_;
uint64_t pixel_height_;
uint64_t pixel_width_;
uint64_t crop_left_;
uint64_t crop_right_;
uint64_t crop_top_;
@ -826,7 +623,6 @@ class VideoTrack : public Track {
uint64_t width_;
Colour* colour_;
Projection* projection_;
LIBWEBM_DISALLOW_COPY_AND_ASSIGN(VideoTrack);
};
@ -874,10 +670,6 @@ class Tracks {
static const char kVp8CodecId[];
static const char kVp9CodecId[];
static const char kVp10CodecId[];
static const char kWebVttCaptionsId[];
static const char kWebVttDescriptionsId[];
static const char kWebVttMetadataId[];
static const char kWebVttSubtitlesId[];
Tracks();
~Tracks();
@ -1502,7 +1294,7 @@ class Segment {
kBeforeClusters = 0x1 // Position Cues before Clusters
};
const static uint32_t kDefaultDocTypeVersion = 4;
const static uint32_t kDefaultDocTypeVersion = 2;
const static uint64_t kDefaultMaxClusterDuration = 30000000000ULL;
Segment();
@ -1689,16 +1481,7 @@ class Segment {
Mode mode() const { return mode_; }
CuesPosition cues_position() const { return cues_position_; }
bool output_cues() const { return output_cues_; }
void set_estimate_file_duration(bool estimate_duration) {
estimate_file_duration_ = estimate_duration;
}
bool estimate_file_duration() const { return estimate_file_duration_; }
const SegmentInfo* segment_info() const { return &segment_info_; }
void set_duration(double duration) { duration_ = duration; }
double duration() const { return duration_; }
// Returns true when codec IDs are valid for WebM.
bool DocTypeIsWebm() const;
private:
// Checks if header information has been output and initialized. If not it
@ -1854,9 +1637,6 @@ class Segment {
// Last timestamp in nanoseconds by track number added to a cluster.
uint64_t last_track_timestamp_[kMaxTrackNumber];
// Number of frames written per track.
uint64_t track_frames_written_[kMaxTrackNumber];
// Maximum time in nanoseconds for a cluster duration. This variable is a
// guideline and some clusters may have a longer duration. Default is 30
// seconds.
@ -1885,9 +1665,6 @@ class Segment {
// Flag whether or not to write the Cluster Timecode using exactly 8 bytes.
bool fixed_size_cluster_timecode_;
// Flag whether or not to estimate the file duration.
bool estimate_file_duration_;
// The size of the EBML header, used to validate the header if
// WriteEbmlHeader() is called more than once.
int32_t ebml_header_size_;
@ -1905,9 +1682,6 @@ class Segment {
uint32_t doc_type_version_;
uint32_t doc_type_version_written_;
// If |duration_| is > 0, then explicitly set the duration of the segment.
double duration_;
// Pointer to the writer objects. Not owned by this class.
IMkvWriter* writer_cluster_;
IMkvWriter* writer_cues_;

View File

@ -31,20 +31,20 @@ namespace {
// Date elements are always 8 octets in size.
const int kDateElementSize = 8;
uint64 WriteBlock(IMkvWriter* writer, const Frame* const frame, int64 timecode,
uint64 timecode_scale) {
uint64 block_additional_elem_size = 0;
uint64 block_addid_elem_size = 0;
uint64 block_more_payload_size = 0;
uint64 block_more_elem_size = 0;
uint64 block_additions_payload_size = 0;
uint64 block_additions_elem_size = 0;
uint64_t WriteBlock(IMkvWriter* writer, const Frame* const frame,
int64_t timecode, uint64_t timecode_scale) {
uint64_t block_additional_elem_size = 0;
uint64_t block_addid_elem_size = 0;
uint64_t block_more_payload_size = 0;
uint64_t block_more_elem_size = 0;
uint64_t block_additions_payload_size = 0;
uint64_t block_additions_elem_size = 0;
if (frame->additional()) {
block_additional_elem_size =
EbmlElementSize(libwebm::kMkvBlockAdditional, frame->additional(),
frame->additional_length());
block_addid_elem_size = EbmlElementSize(
libwebm::kMkvBlockAddID, static_cast<uint64>(frame->add_id()));
block_addid_elem_size =
EbmlElementSize(libwebm::kMkvBlockAddID, frame->add_id());
block_more_payload_size =
block_addid_elem_size + block_additional_elem_size;
@ -58,33 +58,32 @@ uint64 WriteBlock(IMkvWriter* writer, const Frame* const frame, int64 timecode,
block_additions_payload_size;
}
uint64 discard_padding_elem_size = 0;
uint64_t discard_padding_elem_size = 0;
if (frame->discard_padding() != 0) {
discard_padding_elem_size =
EbmlElementSize(libwebm::kMkvDiscardPadding,
static_cast<int64>(frame->discard_padding()));
EbmlElementSize(libwebm::kMkvDiscardPadding, frame->discard_padding());
}
const uint64 reference_block_timestamp =
const uint64_t reference_block_timestamp =
frame->reference_block_timestamp() / timecode_scale;
uint64 reference_block_elem_size = 0;
uint64_t reference_block_elem_size = 0;
if (!frame->is_key()) {
reference_block_elem_size =
EbmlElementSize(libwebm::kMkvReferenceBlock, reference_block_timestamp);
}
const uint64 duration = frame->duration() / timecode_scale;
uint64 block_duration_elem_size = 0;
const uint64_t duration = frame->duration() / timecode_scale;
uint64_t block_duration_elem_size = 0;
if (duration > 0)
block_duration_elem_size =
EbmlElementSize(libwebm::kMkvBlockDuration, duration);
const uint64 block_payload_size = 4 + frame->length();
const uint64 block_elem_size =
const uint64_t block_payload_size = 4 + frame->length();
const uint64_t block_elem_size =
EbmlMasterElementSize(libwebm::kMkvBlock, block_payload_size) +
block_payload_size;
const uint64 block_group_payload_size =
const uint64_t block_group_payload_size =
block_elem_size + block_additions_elem_size + block_duration_elem_size +
discard_padding_elem_size + reference_block_elem_size;
@ -106,7 +105,7 @@ uint64 WriteBlock(IMkvWriter* writer, const Frame* const frame, int64 timecode,
if (SerializeInt(writer, 0, 1))
return 0;
if (writer->Write(frame->frame(), static_cast<uint32>(frame->length())))
if (writer->Write(frame->frame(), static_cast<uint32_t>(frame->length())))
return 0;
if (frame->additional()) {
@ -119,8 +118,7 @@ uint64 WriteBlock(IMkvWriter* writer, const Frame* const frame, int64 timecode,
block_more_payload_size))
return 0;
if (!WriteEbmlElement(writer, libwebm::kMkvBlockAddID,
static_cast<uint64>(frame->add_id())))
if (!WriteEbmlElement(writer, libwebm::kMkvBlockAddID, frame->add_id()))
return 0;
if (!WriteEbmlElement(writer, libwebm::kMkvBlockAdditional,
@ -131,7 +129,7 @@ uint64 WriteBlock(IMkvWriter* writer, const Frame* const frame, int64 timecode,
if (frame->discard_padding() != 0 &&
!WriteEbmlElement(writer, libwebm::kMkvDiscardPadding,
static_cast<int64>(frame->discard_padding()))) {
frame->discard_padding())) {
return false;
}
@ -150,38 +148,38 @@ uint64 WriteBlock(IMkvWriter* writer, const Frame* const frame, int64 timecode,
block_group_payload_size;
}
uint64 WriteSimpleBlock(IMkvWriter* writer, const Frame* const frame,
int64 timecode) {
uint64_t WriteSimpleBlock(IMkvWriter* writer, const Frame* const frame,
int64_t timecode) {
if (WriteID(writer, libwebm::kMkvSimpleBlock))
return 0;
const int32 size = static_cast<int32>(frame->length()) + 4;
const int32_t size = static_cast<int32_t>(frame->length()) + 4;
if (WriteUInt(writer, size))
return 0;
if (WriteUInt(writer, static_cast<uint64>(frame->track_number())))
if (WriteUInt(writer, static_cast<uint64_t>(frame->track_number())))
return 0;
if (SerializeInt(writer, timecode, 2))
return 0;
uint64 flags = 0;
uint64_t flags = 0;
if (frame->is_key())
flags |= 0x80;
if (SerializeInt(writer, flags, 1))
return 0;
if (writer->Write(frame->frame(), static_cast<uint32>(frame->length())))
if (writer->Write(frame->frame(), static_cast<uint32_t>(frame->length())))
return 0;
return GetUIntSize(libwebm::kMkvSimpleBlock) + GetCodedUIntSize(size) + 4 +
frame->length();
return static_cast<uint64_t>(GetUIntSize(libwebm::kMkvSimpleBlock) +
GetCodedUIntSize(size) + 4 + frame->length());
}
} // namespace
int32 GetCodedUIntSize(uint64 value) {
int32_t GetCodedUIntSize(uint64_t value) {
if (value < 0x000000000000007FULL)
return 1;
else if (value < 0x0000000000003FFFULL)
@ -199,7 +197,7 @@ int32 GetCodedUIntSize(uint64 value) {
return 8;
}
int32 GetUIntSize(uint64 value) {
int32_t GetUIntSize(uint64_t value) {
if (value < 0x0000000000000100ULL)
return 1;
else if (value < 0x0000000000010000ULL)
@ -217,26 +215,26 @@ int32 GetUIntSize(uint64 value) {
return 8;
}
int32 GetIntSize(int64 value) {
int32_t GetIntSize(int64_t value) {
// Doubling the requested value ensures positive values with their high bit
// set are written with 0-padding to avoid flipping the signedness.
const uint64 v = (value < 0) ? value ^ -1LL : value;
const uint64_t v = (value < 0) ? value ^ -1LL : value;
return GetUIntSize(2 * v);
}
uint64 EbmlMasterElementSize(uint64 type, uint64 value) {
uint64_t EbmlMasterElementSize(uint64_t type, uint64_t value) {
// Size of EBML ID
int32 ebml_size = GetUIntSize(type);
int32_t ebml_size = GetUIntSize(type);
// Datasize
ebml_size += GetCodedUIntSize(value);
return ebml_size;
return static_cast<uint64_t>(ebml_size);
}
uint64 EbmlElementSize(uint64 type, int64 value) {
uint64_t EbmlElementSize(uint64_t type, int64_t value) {
// Size of EBML ID
int32 ebml_size = GetUIntSize(type);
int32_t ebml_size = GetUIntSize(type);
// Datasize
ebml_size += GetIntSize(value);
@ -244,19 +242,20 @@ uint64 EbmlElementSize(uint64 type, int64 value) {
// Size of Datasize
ebml_size++;
return ebml_size;
return static_cast<uint64_t>(ebml_size);
}
uint64 EbmlElementSize(uint64 type, uint64 value) {
uint64_t EbmlElementSize(uint64_t type, uint64_t value) {
return EbmlElementSize(type, value, 0);
}
uint64 EbmlElementSize(uint64 type, uint64 value, uint64 fixed_size) {
uint64_t EbmlElementSize(uint64_t type, uint64_t value, uint64_t fixed_size) {
// Size of EBML ID
int32 ebml_size = GetUIntSize(type);
uint64_t ebml_size = static_cast<uint64_t>(GetUIntSize(type));
// Datasize
ebml_size += (fixed_size > 0) ? fixed_size : GetUIntSize(value);
ebml_size +=
(fixed_size > 0) ? fixed_size : static_cast<uint64_t>(GetUIntSize(value));
// Size of Datasize
ebml_size++;
@ -264,9 +263,9 @@ uint64 EbmlElementSize(uint64 type, uint64 value, uint64 fixed_size) {
return ebml_size;
}
uint64 EbmlElementSize(uint64 type, float /* value */) {
uint64_t EbmlElementSize(uint64_t type, float /* value */) {
// Size of EBML ID
uint64 ebml_size = GetUIntSize(type);
uint64_t ebml_size = static_cast<uint64_t>(GetUIntSize(type));
// Datasize
ebml_size += sizeof(float);
@ -277,12 +276,12 @@ uint64 EbmlElementSize(uint64 type, float /* value */) {
return ebml_size;
}
uint64 EbmlElementSize(uint64 type, const char* value) {
uint64_t EbmlElementSize(uint64_t type, const char* value) {
if (!value)
return 0;
// Size of EBML ID
uint64 ebml_size = GetUIntSize(type);
uint64_t ebml_size = static_cast<uint64_t>(GetUIntSize(type));
// Datasize
ebml_size += strlen(value);
@ -293,12 +292,12 @@ uint64 EbmlElementSize(uint64 type, const char* value) {
return ebml_size;
}
uint64 EbmlElementSize(uint64 type, const uint8* value, uint64 size) {
uint64_t EbmlElementSize(uint64_t type, const uint8_t* value, uint64_t size) {
if (!value)
return 0;
// Size of EBML ID
uint64 ebml_size = GetUIntSize(type);
uint64_t ebml_size = static_cast<uint64_t>(GetUIntSize(type));
// Datasize
ebml_size += size;
@ -309,9 +308,9 @@ uint64 EbmlElementSize(uint64 type, const uint8* value, uint64 size) {
return ebml_size;
}
uint64 EbmlDateElementSize(uint64 type) {
uint64_t EbmlDateElementSize(uint64_t type) {
// Size of EBML ID
uint64 ebml_size = GetUIntSize(type);
uint64_t ebml_size = static_cast<uint64_t>(GetUIntSize(type));
// Datasize
ebml_size += kDateElementSize;
@ -322,18 +321,18 @@ uint64 EbmlDateElementSize(uint64 type) {
return ebml_size;
}
int32 SerializeInt(IMkvWriter* writer, int64 value, int32 size) {
int32_t SerializeInt(IMkvWriter* writer, int64_t value, int32_t size) {
if (!writer || size < 1 || size > 8)
return -1;
for (int32 i = 1; i <= size; ++i) {
const int32 byte_count = size - i;
const int32 bit_count = byte_count * 8;
for (int32_t i = 1; i <= size; ++i) {
const int32_t byte_count = size - i;
const int32_t bit_count = byte_count * 8;
const int64 bb = value >> bit_count;
const uint8 b = static_cast<uint8>(bb);
const int64_t bb = value >> bit_count;
const uint8_t b = static_cast<uint8_t>(bb);
const int32 status = writer->Write(&b, 1);
const int32_t status = writer->Write(&b, 1);
if (status < 0)
return status;
@ -342,26 +341,26 @@ int32 SerializeInt(IMkvWriter* writer, int64 value, int32 size) {
return 0;
}
int32 SerializeFloat(IMkvWriter* writer, float f) {
int32_t SerializeFloat(IMkvWriter* writer, float f) {
if (!writer)
return -1;
assert(sizeof(uint32) == sizeof(float));
assert(sizeof(uint32_t) == sizeof(float));
// This union is merely used to avoid a reinterpret_cast from float& to
// uint32& which will result in violation of strict aliasing.
union U32 {
uint32 u32;
uint32_t u32;
float f;
} value;
value.f = f;
for (int32 i = 1; i <= 4; ++i) {
const int32 byte_count = 4 - i;
const int32 bit_count = byte_count * 8;
for (int32_t i = 1; i <= 4; ++i) {
const int32_t byte_count = 4 - i;
const int32_t bit_count = byte_count * 8;
const uint8 byte = static_cast<uint8>(value.u32 >> bit_count);
const uint8_t byte = static_cast<uint8_t>(value.u32 >> bit_count);
const int32 status = writer->Write(&byte, 1);
const int32_t status = writer->Write(&byte, 1);
if (status < 0)
return status;
@ -370,21 +369,21 @@ int32 SerializeFloat(IMkvWriter* writer, float f) {
return 0;
}
int32 WriteUInt(IMkvWriter* writer, uint64 value) {
int32_t WriteUInt(IMkvWriter* writer, uint64_t value) {
if (!writer)
return -1;
int32 size = GetCodedUIntSize(value);
int32_t size = GetCodedUIntSize(value);
return WriteUIntSize(writer, value, size);
}
int32 WriteUIntSize(IMkvWriter* writer, uint64 value, int32 size) {
int32_t WriteUIntSize(IMkvWriter* writer, uint64_t value, int32_t size) {
if (!writer || size < 0 || size > 8)
return -1;
if (size > 0) {
const uint64 bit = 1LL << (size * 7);
const uint64_t bit = 1LL << (size * 7);
if (value > (bit - 2))
return -1;
@ -392,11 +391,11 @@ int32 WriteUIntSize(IMkvWriter* writer, uint64 value, int32 size) {
value |= bit;
} else {
size = 1;
int64 bit;
int64_t bit;
for (;;) {
bit = 1LL << (size * 7);
const uint64 max = bit - 2;
const uint64_t max = bit - 2;
if (value <= max)
break;
@ -413,18 +412,18 @@ int32 WriteUIntSize(IMkvWriter* writer, uint64 value, int32 size) {
return SerializeInt(writer, value, size);
}
int32 WriteID(IMkvWriter* writer, uint64 type) {
int32_t WriteID(IMkvWriter* writer, uint64_t type) {
if (!writer)
return -1;
writer->ElementStartNotify(type, writer->Position());
const int32 size = GetUIntSize(type);
const int32_t size = GetUIntSize(type);
return SerializeInt(writer, type, size);
}
bool WriteEbmlMasterElement(IMkvWriter* writer, uint64 type, uint64 size) {
bool WriteEbmlMasterElement(IMkvWriter* writer, uint64_t type, uint64_t size) {
if (!writer)
return false;
@ -437,19 +436,19 @@ bool WriteEbmlMasterElement(IMkvWriter* writer, uint64 type, uint64 size) {
return true;
}
bool WriteEbmlElement(IMkvWriter* writer, uint64 type, uint64 value) {
bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, uint64_t value) {
return WriteEbmlElement(writer, type, value, 0);
}
bool WriteEbmlElement(IMkvWriter* writer, uint64 type, uint64 value,
uint64 fixed_size) {
bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, uint64_t value,
uint64_t fixed_size) {
if (!writer)
return false;
if (WriteID(writer, type))
return false;
uint64 size = GetUIntSize(value);
uint64_t size = static_cast<uint64_t>(GetUIntSize(value));
if (fixed_size > 0) {
if (size > fixed_size)
return false;
@ -458,30 +457,30 @@ bool WriteEbmlElement(IMkvWriter* writer, uint64 type, uint64 value,
if (WriteUInt(writer, size))
return false;
if (SerializeInt(writer, value, static_cast<int32>(size)))
if (SerializeInt(writer, value, static_cast<int32_t>(size)))
return false;
return true;
}
bool WriteEbmlElement(IMkvWriter* writer, uint64 type, int64 value) {
bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, int64_t value) {
if (!writer)
return false;
if (WriteID(writer, type))
return 0;
const uint64 size = GetIntSize(value);
const uint64_t size = GetIntSize(value);
if (WriteUInt(writer, size))
return false;
if (SerializeInt(writer, value, static_cast<int32>(size)))
if (SerializeInt(writer, value, static_cast<int32_t>(size)))
return false;
return true;
}
bool WriteEbmlElement(IMkvWriter* writer, uint64 type, float value) {
bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, float value) {
if (!writer)
return false;
@ -497,25 +496,25 @@ bool WriteEbmlElement(IMkvWriter* writer, uint64 type, float value) {
return true;
}
bool WriteEbmlElement(IMkvWriter* writer, uint64 type, const char* value) {
bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, const char* value) {
if (!writer || !value)
return false;
if (WriteID(writer, type))
return false;
const uint64 length = strlen(value);
const uint64_t length = strlen(value);
if (WriteUInt(writer, length))
return false;
if (writer->Write(value, static_cast<const uint32>(length)))
if (writer->Write(value, static_cast<const uint32_t>(length)))
return false;
return true;
}
bool WriteEbmlElement(IMkvWriter* writer, uint64 type, const uint8* value,
uint64 size) {
bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, const uint8_t* value,
uint64_t size) {
if (!writer || !value || size < 1)
return false;
@ -525,13 +524,13 @@ bool WriteEbmlElement(IMkvWriter* writer, uint64 type, const uint8* value,
if (WriteUInt(writer, size))
return false;
if (writer->Write(value, static_cast<uint32>(size)))
if (writer->Write(value, static_cast<uint32_t>(size)))
return false;
return true;
}
bool WriteEbmlDateElement(IMkvWriter* writer, uint64 type, int64 value) {
bool WriteEbmlDateElement(IMkvWriter* writer, uint64_t type, int64_t value) {
if (!writer)
return false;
@ -547,8 +546,8 @@ bool WriteEbmlDateElement(IMkvWriter* writer, uint64 type, int64 value) {
return true;
}
uint64 WriteFrame(IMkvWriter* writer, const Frame* const frame,
Cluster* cluster) {
uint64_t WriteFrame(IMkvWriter* writer, const Frame* const frame,
Cluster* cluster) {
if (!writer || !frame || !frame->IsValid() || !cluster ||
!cluster->timecode_scale())
return 0;
@ -557,7 +556,7 @@ uint64 WriteFrame(IMkvWriter* writer, const Frame* const frame,
// timecode for the cluster itself (remember that block timecode
// is a signed, 16-bit integer). However, as a simplification we
// only permit non-negative cluster-relative timecodes for blocks.
const int64 relative_timecode = cluster->GetRelativeTimecode(
const int64_t relative_timecode = cluster->GetRelativeTimecode(
frame->timestamp() / cluster->timecode_scale());
if (relative_timecode < 0 || relative_timecode > kMaxBlockTimecode)
return 0;
@ -568,19 +567,20 @@ uint64 WriteFrame(IMkvWriter* writer, const Frame* const frame,
cluster->timecode_scale());
}
uint64 WriteVoidElement(IMkvWriter* writer, uint64 size) {
uint64_t WriteVoidElement(IMkvWriter* writer, uint64_t size) {
if (!writer)
return false;
// Subtract one for the void ID and the coded size.
uint64 void_entry_size = size - 1 - GetCodedUIntSize(size - 1);
uint64 void_size = EbmlMasterElementSize(libwebm::kMkvVoid, void_entry_size) +
void_entry_size;
uint64_t void_entry_size = size - 1 - GetCodedUIntSize(size - 1);
uint64_t void_size =
EbmlMasterElementSize(libwebm::kMkvVoid, void_entry_size) +
void_entry_size;
if (void_size != size)
return 0;
const int64 payload_position = writer->Position();
const int64_t payload_position = writer->Position();
if (payload_position < 0)
return 0;
@ -590,29 +590,30 @@ uint64 WriteVoidElement(IMkvWriter* writer, uint64 size) {
if (WriteUInt(writer, void_entry_size))
return 0;
const uint8 value = 0;
for (int32 i = 0; i < static_cast<int32>(void_entry_size); ++i) {
const uint8_t value = 0;
for (int32_t i = 0; i < static_cast<int32_t>(void_entry_size); ++i) {
if (writer->Write(&value, 1))
return 0;
}
const int64 stop_position = writer->Position();
const int64_t stop_position = writer->Position();
if (stop_position < 0 ||
stop_position - payload_position != static_cast<int64>(void_size))
stop_position - payload_position != static_cast<int64_t>(void_size))
return 0;
return void_size;
}
void GetVersion(int32* major, int32* minor, int32* build, int32* revision) {
void GetVersion(int32_t* major, int32_t* minor, int32_t* build,
int32_t* revision) {
*major = 0;
*minor = 2;
*build = 1;
*revision = 0;
}
uint64 MakeUID(unsigned int* seed) {
uint64 uid = 0;
uint64_t MakeUID(unsigned int* seed) {
uint64_t uid = 0;
#ifdef __MINGW32__
srand(*seed);
@ -624,22 +625,21 @@ uint64 MakeUID(unsigned int* seed) {
// TODO(fgalligan): Move random number generation to platform specific code.
#ifdef _MSC_VER
(void)seed;
const int32 nn = rand();
const int32_t nn = rand();
#elif __ANDROID__
(void)seed;
int32 temp_num = 1;
int32_t temp_num = 1;
int fd = open("/dev/urandom", O_RDONLY);
if (fd != -1) {
read(fd, &temp_num, sizeof(temp_num));
close(fd);
}
const int32 nn = temp_num;
const int32_t nn = temp_num;
#elif defined __MINGW32__
const int32 nn = rand();
const int32_t nn = rand();
#else
const int32 nn = rand_r(seed);
const int32_t nn = rand_r(seed);
#endif
const int32 n = 0xFF & (nn >> 4); // throw away low-order bits
const int32_t n = 0xFF & (nn >> 4); // throw away low-order bits
uid |= n;
}
@ -647,97 +647,4 @@ uint64 MakeUID(unsigned int* seed) {
return uid;
}
bool IsMatrixCoefficientsValueValid(uint64_t value) {
switch (value) {
case mkvmuxer::Colour::kGbr:
case mkvmuxer::Colour::kBt709:
case mkvmuxer::Colour::kUnspecifiedMc:
case mkvmuxer::Colour::kReserved:
case mkvmuxer::Colour::kFcc:
case mkvmuxer::Colour::kBt470bg:
case mkvmuxer::Colour::kSmpte170MMc:
case mkvmuxer::Colour::kSmpte240MMc:
case mkvmuxer::Colour::kYcocg:
case mkvmuxer::Colour::kBt2020NonConstantLuminance:
case mkvmuxer::Colour::kBt2020ConstantLuminance:
return true;
}
return false;
}
bool IsChromaSitingHorzValueValid(uint64_t value) {
switch (value) {
case mkvmuxer::Colour::kUnspecifiedCsh:
case mkvmuxer::Colour::kLeftCollocated:
case mkvmuxer::Colour::kHalfCsh:
return true;
}
return false;
}
bool IsChromaSitingVertValueValid(uint64_t value) {
switch (value) {
case mkvmuxer::Colour::kUnspecifiedCsv:
case mkvmuxer::Colour::kTopCollocated:
case mkvmuxer::Colour::kHalfCsv:
return true;
}
return false;
}
bool IsColourRangeValueValid(uint64_t value) {
switch (value) {
case mkvmuxer::Colour::kUnspecifiedCr:
case mkvmuxer::Colour::kBroadcastRange:
case mkvmuxer::Colour::kFullRange:
case mkvmuxer::Colour::kMcTcDefined:
return true;
}
return false;
}
bool IsTransferCharacteristicsValueValid(uint64_t value) {
switch (value) {
case mkvmuxer::Colour::kIturBt709Tc:
case mkvmuxer::Colour::kUnspecifiedTc:
case mkvmuxer::Colour::kReservedTc:
case mkvmuxer::Colour::kGamma22Curve:
case mkvmuxer::Colour::kGamma28Curve:
case mkvmuxer::Colour::kSmpte170MTc:
case mkvmuxer::Colour::kSmpte240MTc:
case mkvmuxer::Colour::kLinear:
case mkvmuxer::Colour::kLog:
case mkvmuxer::Colour::kLogSqrt:
case mkvmuxer::Colour::kIec6196624:
case mkvmuxer::Colour::kIturBt1361ExtendedColourGamut:
case mkvmuxer::Colour::kIec6196621:
case mkvmuxer::Colour::kIturBt202010bit:
case mkvmuxer::Colour::kIturBt202012bit:
case mkvmuxer::Colour::kSmpteSt2084:
case mkvmuxer::Colour::kSmpteSt4281Tc:
case mkvmuxer::Colour::kAribStdB67Hlg:
return true;
}
return false;
}
bool IsPrimariesValueValid(uint64_t value) {
switch (value) {
case mkvmuxer::Colour::kReservedP0:
case mkvmuxer::Colour::kIturBt709P:
case mkvmuxer::Colour::kUnspecifiedP:
case mkvmuxer::Colour::kReservedP3:
case mkvmuxer::Colour::kIturBt470M:
case mkvmuxer::Colour::kIturBt470Bg:
case mkvmuxer::Colour::kSmpte170MP:
case mkvmuxer::Colour::kSmpte240MP:
case mkvmuxer::Colour::kFilm:
case mkvmuxer::Colour::kIturBt2020:
case mkvmuxer::Colour::kSmpteSt4281P:
case mkvmuxer::Colour::kJedecP22Phosphors:
return true;
}
return false;
}
} // namespace mkvmuxer

View File

@ -8,104 +8,87 @@
#ifndef MKVMUXER_MKVMUXERUTIL_H_
#define MKVMUXER_MKVMUXERUTIL_H_
#include "mkvmuxertypes.h"
#include "stdint.h"
#include <stdint.h>
namespace mkvmuxer {
class Cluster;
class Frame;
class IMkvWriter;
// TODO(tomfinegan): mkvmuxer:: integer types continue to be used here because
// changing them causes pain for downstream projects. It would be nice if a
// solution that allows removal of the mkvmuxer:: integer types while avoiding
// pain for downstream users of libwebm. Considering that mkvmuxerutil.{cc,h}
// are really, for the great majority of cases, EBML size calculation and writer
// functions, perhaps a more EBML focused utility would be the way to go as a
// first step.
const uint64 kEbmlUnknownValue = 0x01FFFFFFFFFFFFFFULL;
const int64 kMaxBlockTimecode = 0x07FFFLL;
const uint64_t kEbmlUnknownValue = 0x01FFFFFFFFFFFFFFULL;
const int64_t kMaxBlockTimecode = 0x07FFFLL;
// Writes out |value| in Big Endian order. Returns 0 on success.
int32 SerializeInt(IMkvWriter* writer, int64 value, int32 size);
int32_t SerializeInt(IMkvWriter* writer, int64_t value, int32_t size);
// Returns the size in bytes of the element.
int32 GetUIntSize(uint64 value);
int32 GetIntSize(int64 value);
int32 GetCodedUIntSize(uint64 value);
uint64 EbmlMasterElementSize(uint64 type, uint64 value);
uint64 EbmlElementSize(uint64 type, int64 value);
uint64 EbmlElementSize(uint64 type, uint64 value);
uint64 EbmlElementSize(uint64 type, float value);
uint64 EbmlElementSize(uint64 type, const char* value);
uint64 EbmlElementSize(uint64 type, const uint8* value, uint64 size);
uint64 EbmlDateElementSize(uint64 type);
int32_t GetUIntSize(uint64_t value);
int32_t GetIntSize(int64_t value);
int32_t GetCodedUIntSize(uint64_t value);
uint64_t EbmlMasterElementSize(uint64_t type, uint64_t value);
uint64_t EbmlElementSize(uint64_t type, int64_t value);
uint64_t EbmlElementSize(uint64_t type, uint64_t value);
uint64_t EbmlElementSize(uint64_t type, float value);
uint64_t EbmlElementSize(uint64_t type, const char* value);
uint64_t EbmlElementSize(uint64_t type, const uint8_t* value, uint64_t size);
uint64_t EbmlDateElementSize(uint64_t type);
// Returns the size in bytes of the element assuming that the element was
// written using |fixed_size| bytes. If |fixed_size| is set to zero, then it
// computes the necessary number of bytes based on |value|.
uint64 EbmlElementSize(uint64 type, uint64 value, uint64 fixed_size);
uint64_t EbmlElementSize(uint64_t type, uint64_t value, uint64_t fixed_size);
// Creates an EBML coded number from |value| and writes it out. The size of
// the coded number is determined by the value of |value|. |value| must not
// be in a coded form. Returns 0 on success.
int32 WriteUInt(IMkvWriter* writer, uint64 value);
int32_t WriteUInt(IMkvWriter* writer, uint64_t value);
// Creates an EBML coded number from |value| and writes it out. The size of
// the coded number is determined by the value of |size|. |value| must not
// be in a coded form. Returns 0 on success.
int32 WriteUIntSize(IMkvWriter* writer, uint64 value, int32 size);
int32_t WriteUIntSize(IMkvWriter* writer, uint64_t value, int32_t size);
// Output an Mkv master element. Returns true if the element was written.
bool WriteEbmlMasterElement(IMkvWriter* writer, uint64 value, uint64 size);
bool WriteEbmlMasterElement(IMkvWriter* writer, uint64_t value, uint64_t size);
// Outputs an Mkv ID, calls |IMkvWriter::ElementStartNotify|, and passes the
// ID to |SerializeInt|. Returns 0 on success.
int32 WriteID(IMkvWriter* writer, uint64 type);
int32_t WriteID(IMkvWriter* writer, uint64_t type);
// Output an Mkv non-master element. Returns true if the element was written.
bool WriteEbmlElement(IMkvWriter* writer, uint64 type, uint64 value);
bool WriteEbmlElement(IMkvWriter* writer, uint64 type, int64 value);
bool WriteEbmlElement(IMkvWriter* writer, uint64 type, float value);
bool WriteEbmlElement(IMkvWriter* writer, uint64 type, const char* value);
bool WriteEbmlElement(IMkvWriter* writer, uint64 type, const uint8* value,
uint64 size);
bool WriteEbmlDateElement(IMkvWriter* writer, uint64 type, int64 value);
bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, uint64_t value);
bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, int64_t value);
bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, float value);
bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, const char* value);
bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, const uint8_t* value,
uint64_t size);
bool WriteEbmlDateElement(IMkvWriter* writer, uint64_t type, int64_t value);
// Output an Mkv non-master element using fixed size. The element will be
// written out using exactly |fixed_size| bytes. If |fixed_size| is set to zero
// then it computes the necessary number of bytes based on |value|. Returns true
// if the element was written.
bool WriteEbmlElement(IMkvWriter* writer, uint64 type, uint64 value,
uint64 fixed_size);
bool WriteEbmlElement(IMkvWriter* writer, uint64_t type, uint64_t value,
uint64_t fixed_size);
// Output a Mkv Frame. It decides the correct element to write (Block vs
// SimpleBlock) based on the parameters of the Frame.
uint64 WriteFrame(IMkvWriter* writer, const Frame* const frame,
Cluster* cluster);
uint64_t WriteFrame(IMkvWriter* writer, const Frame* const frame,
Cluster* cluster);
// Output a void element. |size| must be the entire size in bytes that will be
// void. The function will calculate the size of the void header and subtract
// it from |size|.
uint64 WriteVoidElement(IMkvWriter* writer, uint64 size);
uint64_t WriteVoidElement(IMkvWriter* writer, uint64_t size);
// Returns the version number of the muxer in |major|, |minor|, |build|,
// and |revision|.
void GetVersion(int32* major, int32* minor, int32* build, int32* revision);
void GetVersion(int32_t* major, int32_t* minor, int32_t* build,
int32_t* revision);
// Returns a random number to be used for UID, using |seed| to seed
// the random-number generator (see POSIX rand_r() for semantics).
uint64 MakeUID(unsigned int* seed);
// Colour field validation helpers. All return true when |value| is valid.
bool IsMatrixCoefficientsValueValid(uint64_t value);
bool IsChromaSitingHorzValueValid(uint64_t value);
bool IsChromaSitingVertValueValid(uint64_t value);
bool IsColourRangeValueValid(uint64_t value);
bool IsTransferCharacteristicsValueValid(uint64_t value);
bool IsPrimariesValueValid(uint64_t value);
uint64_t MakeUID(unsigned int* seed);
} // namespace mkvmuxer

View File

@ -77,7 +77,7 @@ int32 MkvWriter::Position(int64 position) {
#ifdef _MSC_VER
return _fseeki64(file_, position, SEEK_SET);
#else
return fseeko(file_, static_cast<off_t>(position), SEEK_SET);
return fseek(file_, position, SEEK_SET);
#endif
}

View File

@ -25,7 +25,6 @@
namespace mkvparser {
const float MasteringMetadata::kValueNotPresent = FLT_MAX;
const long long Colour::kValueNotPresent = LLONG_MAX;
const float Projection::kValueNotPresent = FLT_MAX;
#ifdef MSC_COMPAT
inline bool isnan(double val) { return !!_isnan(val); }
@ -1476,8 +1475,6 @@ long Segment::Load() {
}
}
SeekHead::Entry::Entry() : id(0), pos(0), element_start(0), element_size(0) {}
SeekHead::SeekHead(Segment* pSegment, long long start, long long size_,
long long element_start, long long element_size)
: m_pSegment(pSegment),
@ -1769,7 +1766,18 @@ bool SeekHead::ParseEntry(IMkvReader* pReader, long long start, long long size_,
if ((pos + seekIdSize) > stop)
return false;
pEntry->id = ReadID(pReader, pos, len); // payload
// Note that the SeekId payload really is serialized
// as a "Matroska integer", not as a plain binary value.
// In fact, Matroska requires that ID values in the
// stream exactly match the binary representation as listed
// in the Matroska specification.
//
// This parser is more liberal, and permits IDs to have
// any width. (This could make the representation in the stream
// different from what's in the spec, but it doesn't matter here,
// since we always normalize "Matroska integer" values.)
pEntry->id = ReadUInt(pReader, pos, len); // payload
if (pEntry->id <= 0)
return false;
@ -5180,92 +5188,11 @@ bool Colour::Parse(IMkvReader* reader, long long colour_start,
return true;
}
bool Projection::Parse(IMkvReader* reader, long long start, long long size,
Projection** projection) {
if (!reader || *projection)
return false;
std::auto_ptr<Projection> projection_ptr(new Projection());
if (!projection_ptr.get())
return false;
const long long end = start + size;
long long read_pos = start;
while (read_pos < end) {
long long child_id = 0;
long long child_size = 0;
const long long status =
ParseElementHeader(reader, read_pos, end, child_id, child_size);
if (status < 0)
return false;
if (child_id == libwebm::kMkvProjectionType) {
long long projection_type = kTypeNotPresent;
projection_type = UnserializeUInt(reader, read_pos, child_size);
if (projection_type < 0)
return false;
projection_ptr->type = static_cast<ProjectionType>(projection_type);
} else if (child_id == libwebm::kMkvProjectionPrivate) {
unsigned char* data = SafeArrayAlloc<unsigned char>(1, child_size);
if (data == NULL)
return false;
const int status =
reader->Read(read_pos, static_cast<long>(child_size), data);
if (status) {
delete[] data;
return status;
}
projection_ptr->private_data = data;
projection_ptr->private_data_length = static_cast<size_t>(child_size);
} else {
double value = 0;
const long long value_parse_status =
UnserializeFloat(reader, read_pos, child_size, value);
if (value_parse_status < 0) {
return false;
}
switch (child_id) {
case libwebm::kMkvProjectionPoseYaw:
projection_ptr->pose_yaw = static_cast<float>(value);
break;
case libwebm::kMkvProjectionPosePitch:
projection_ptr->pose_pitch = static_cast<float>(value);
break;
case libwebm::kMkvProjectionPoseRoll:
projection_ptr->pose_roll = static_cast<float>(value);
break;
default:
return false;
}
}
read_pos += child_size;
if (read_pos > end)
return false;
}
*projection = projection_ptr.release();
return true;
}
VideoTrack::VideoTrack(Segment* pSegment, long long element_start,
long long element_size)
: Track(pSegment, element_start, element_size),
m_colour(NULL),
m_projection(NULL) {}
: Track(pSegment, element_start, element_size), m_colour(NULL) {}
VideoTrack::~VideoTrack() {
delete m_colour;
delete m_projection;
}
VideoTrack::~VideoTrack() { delete m_colour; }
long VideoTrack::Parse(Segment* pSegment, const Info& info,
long long element_start, long long element_size,
@ -5297,7 +5224,6 @@ long VideoTrack::Parse(Segment* pSegment, const Info& info,
const long long stop = pos + s.size;
Colour* colour = NULL;
Projection* projection = NULL;
while (pos < stop) {
long long id, size;
@ -5348,9 +5274,6 @@ long VideoTrack::Parse(Segment* pSegment, const Info& info,
} else if (id == libwebm::kMkvColour) {
if (!Colour::Parse(pReader, pos, size, &colour))
return E_FILE_FORMAT_INVALID;
} else if (id == libwebm::kMkvProjection) {
if (!Projection::Parse(pReader, pos, size, &projection))
return E_FILE_FORMAT_INVALID;
}
pos += size; // consume payload
@ -5382,7 +5305,6 @@ long VideoTrack::Parse(Segment* pSegment, const Info& info,
pTrack->m_stereo_mode = stereo_mode;
pTrack->m_rate = rate;
pTrack->m_colour = colour;
pTrack->m_projection = projection;
pResult = pTrack;
return 0; // success
@ -5483,8 +5405,6 @@ long VideoTrack::Seek(long long time_ns, const BlockEntry*& pResult) const {
Colour* VideoTrack::GetColour() const { return m_colour; }
Projection* VideoTrack::GetProjection() const { return m_projection; }
long long VideoTrack::GetWidth() const { return m_width; }
long long VideoTrack::GetHeight() const { return m_height; }
@ -6778,10 +6698,8 @@ Cluster::Cluster(Segment* pSegment, long idx, long long element_start
{}
Cluster::~Cluster() {
if (m_entries_count <= 0) {
delete[] m_entries;
if (m_entries_count <= 0)
return;
}
BlockEntry** i = m_entries;
BlockEntry** const j = m_entries + m_entries_count;

View File

@ -473,34 +473,6 @@ struct Colour {
MasteringMetadata* mastering_metadata;
};
struct Projection {
enum ProjectionType {
kTypeNotPresent = -1,
kRectangular = 0,
kEquirectangular = 1,
kCubeMap = 2,
kMesh = 3,
};
static const float kValueNotPresent;
Projection()
: type(kTypeNotPresent),
private_data(NULL),
private_data_length(0),
pose_yaw(kValueNotPresent),
pose_pitch(kValueNotPresent),
pose_roll(kValueNotPresent) {}
~Projection() { delete[] private_data; }
static bool Parse(IMkvReader* reader, long long element_start,
long long element_size, Projection** projection);
ProjectionType type;
unsigned char* private_data;
size_t private_data_length;
float pose_yaw;
float pose_pitch;
float pose_roll;
};
class VideoTrack : public Track {
VideoTrack(const VideoTrack&);
VideoTrack& operator=(const VideoTrack&);
@ -525,8 +497,6 @@ class VideoTrack : public Track {
Colour* GetColour() const;
Projection* GetProjection() const;
private:
long long m_width;
long long m_height;
@ -538,7 +508,6 @@ class VideoTrack : public Track {
double m_rate;
Colour* m_colour;
Projection* m_projection;
};
class AudioTrack : public Track {
@ -844,8 +813,6 @@ class SeekHead {
long Parse();
struct Entry {
Entry();
// the SeekHead entry payload
long long id;
long long pos;

View File

@ -117,7 +117,7 @@ int MkvReader::Read(long long offset, long len, unsigned char* buffer) {
if (status)
return -1; // error
#else
fseeko(m_file, static_cast<off_t>(offset), SEEK_SET);
fseek(m_file, offset, SEEK_SET);
#endif
const size_t size = fread(buffer, 1, len, m_file);
@ -128,4 +128,4 @@ int MkvReader::Read(long long offset, long len, unsigned char* buffer) {
return 0; // success
}
} // namespace mkvparser
} // namespace mkvparser