Commit 51a1cbfe authored by Vignesh Venkatasubramanian's avatar Vignesh Venkatasubramanian Committed by Gerrit Code Review
Browse files

Merge "third_party/libwebm: pull from upstream"

parents 75d05d5e c3378771
URL: https://chromium.googlesource.com/webm/libwebm
Version: a7118d8ec564e9db841da1eb01f547f3229f240a
Version: 249629d46c6e9391f25a90cff6d19075f47474cb
License: BSD
License File: LICENSE.txt
......
This diff is collapsed.
......@@ -15,7 +15,7 @@
// http://www.webmproject.org/code/specs/container/.
namespace mkvparser {
class IMkvReader;
class IMkvReader;
} // end namespace
namespace mkvmuxer {
......@@ -60,8 +60,8 @@ class IMkvWriter {
bool WriteEbmlHeader(IMkvWriter* writer);
// Copies in Chunk from source to destination between the given byte positions
bool ChunkedCopy(mkvparser::IMkvReader* source, IMkvWriter* dst,
int64 start, int64 size);
bool ChunkedCopy(mkvparser::IMkvReader* source, IMkvWriter* dst, int64 start,
int64 size);
///////////////////////////////////////////////////////////////
// Class to hold data the will be written to a block.
......@@ -74,8 +74,7 @@ class Frame {
bool Init(const uint8* frame, uint64 length);
// Copies |additional| data into |additional_|. Returns true on success.
bool AddAdditionalData(const uint8* additional, uint64 length,
uint64 add_id);
bool AddAdditionalData(const uint8* additional, uint64 length, uint64 add_id);
uint64 add_id() const { return add_id_; }
const uint8* additional() const { return additional_; }
......@@ -223,9 +222,7 @@ class Cues {
// ContentEncAESSettings element
class ContentEncAESSettings {
public:
enum {
kCTR = 1
};
enum { kCTR = 1 };
ContentEncAESSettings();
~ContentEncAESSettings() {}
......@@ -353,6 +350,10 @@ class Track {
seek_pre_roll_ = seek_pre_roll;
}
uint64 seek_pre_roll() const { return seek_pre_roll_; }
void set_default_duration(uint64 default_duration) {
default_duration_ = default_duration;
}
uint64 default_duration() const { return default_duration_; }
uint64 codec_private_length() const { return codec_private_length_; }
uint32 content_encoding_entries_size() const {
......@@ -360,7 +361,7 @@ class Track {
}
private:
// Track element names
// Track element names.
char* codec_id_;
uint8* codec_private_;
char* language_;
......@@ -371,6 +372,7 @@ class Track {
uint64 uid_;
uint64 codec_delay_;
uint64 seek_pre_roll_;
uint64 default_duration_;
// Size of the CodecPrivate data in bytes.
uint64 codec_private_length_;
......@@ -391,16 +393,13 @@ class VideoTrack : public Track {
// Supported modes for stereo 3D.
enum StereoMode {
kMono = 0,
kSideBySideLeftIsFirst = 1,
kTopBottomRightIsFirst = 2,
kTopBottomLeftIsFirst = 3,
kSideBySideLeftIsFirst = 1,
kTopBottomRightIsFirst = 2,
kTopBottomLeftIsFirst = 3,
kSideBySideRightIsFirst = 11
};
enum AlphaMode {
kNoAlpha = 0,
kAlpha = 1
};
enum AlphaMode { kNoAlpha = 0, kAlpha = 1 };
// The |seed| parameter is used to synthesize a UID for the track.
explicit VideoTrack(unsigned int* seed);
......@@ -484,10 +483,7 @@ class AudioTrack : public Track {
class Tracks {
public:
// Audio and video type defined by the Matroska specs.
enum {
kVideo = 0x1,
kAudio = 0x2
};
enum { kVideo = 0x1, kAudio = 0x2 };
// Opus, Vorbis, VP8, and VP9 codec ids defined by the Matroska specs.
static const char kOpusCodecId[];
static const char kVorbisCodecId[];
......@@ -544,8 +540,7 @@ class Chapter {
// Converts the nanosecond start and stop times of this chapter to
// their corresponding timecode values, and stores them that way.
void set_time(const Segment& segment,
uint64 start_time_ns,
void set_time(const Segment& segment, uint64 start_time_ns,
uint64 end_time_ns);
// Sets the uid for this chapter. Primarily used to enable
......@@ -568,9 +563,7 @@ class Chapter {
// http://www.iana.org/domains/root/db/
//
// The function returns false if the string could not be allocated.
bool add_string(const char* title,
const char* language,
const char* country);
bool add_string(const char* title, const char* language, const char* country);
private:
friend class Chapters;
......@@ -724,9 +717,7 @@ class Cluster {
// timecode: Absolute (not relative to cluster) timestamp of the
// frame, expressed in timecode units.
// is_key: Flag telling whether or not this frame is a key frame.
bool AddFrame(const uint8* frame,
uint64 length,
uint64 track_number,
bool AddFrame(const uint8* frame, uint64 length, uint64 track_number,
uint64 timecode, // timecode units (absolute)
bool is_key);
......@@ -743,14 +734,10 @@ class Cluster {
// abs_timecode: Absolute (not relative to cluster) timestamp of the
// frame, expressed in timecode units.
// is_key: Flag telling whether or not this frame is a key frame.
bool AddFrameWithAdditional(const uint8* frame,
uint64 length,
const uint8* additional,
uint64 additional_length,
uint64 add_id,
uint64 track_number,
uint64 abs_timecode,
bool is_key);
bool AddFrameWithAdditional(const uint8* frame, uint64 length,
const uint8* additional, uint64 additional_length,
uint64 add_id, uint64 track_number,
uint64 abs_timecode, bool is_key);
// Adds a frame to be output in the file. The frame is written out through
// |writer_| if successful. Returns true on success.
......@@ -763,12 +750,9 @@ class Cluster {
// abs_timecode: Absolute (not relative to cluster) timestamp of the
// frame, expressed in timecode units.
// is_key: Flag telling whether or not this frame is a key frame.
bool AddFrameWithDiscardPadding(const uint8* frame,
uint64 length,
int64 discard_padding,
uint64 track_number,
uint64 abs_timecode,
bool is_key);
bool AddFrameWithDiscardPadding(const uint8* frame, uint64 length,
int64 discard_padding, uint64 track_number,
uint64 abs_timecode, bool is_key);
// Writes a frame of metadata to the output medium; returns true on
// success.
......@@ -784,11 +768,8 @@ class Cluster {
// The metadata frame is written as a block group, with a duration
// sub-element but no reference time sub-elements (indicating that
// it is considered a keyframe, per Matroska semantics).
bool AddMetadata(const uint8* frame,
uint64 length,
uint64 track_number,
uint64 timecode, // timecode units (absolute)
uint64 duration); // timecode units
bool AddMetadata(const uint8* frame, uint64 length, uint64 track_number,
uint64 timecode, uint64 duration);
// Increments the size of the cluster's data in bytes.
void AddPayloadSize(uint64 size);
......@@ -809,34 +790,26 @@ class Cluster {
private:
// Signature that matches either of WriteSimpleBlock or WriteMetadataBlock
// in the muxer utilities package.
typedef uint64 (*WriteBlock)(IMkvWriter* writer,
const uint8* data,
uint64 length,
uint64 track_number,
int64 timecode,
uint64 generic_arg);
typedef uint64 (*WriteBlock)(IMkvWriter* writer, const uint8* data,
uint64 length, uint64 track_number,
int64 timecode, uint64 generic_arg);
// Signature that matches WriteBlockWithAdditional
// in the muxer utilities package.
typedef uint64 (*WriteBlockAdditional)(IMkvWriter* writer,
const uint8* data,
uint64 length,
const uint8* additional,
typedef uint64 (*WriteBlockAdditional)(IMkvWriter* writer, const uint8* data,
uint64 length, const uint8* additional,
uint64 add_id,
uint64 additional_length,
uint64 track_number,
int64 timecode,
uint64 track_number, int64 timecode,
uint64 is_key);
// Signature that matches WriteBlockWithDiscardPadding
// in the muxer utilities package.
typedef uint64 (*WriteBlockDiscardPadding)(IMkvWriter* writer,
const uint8* data,
uint64 length,
const uint8* data, uint64 length,
int64 discard_padding,
uint64 track_number,
int64 timecode,
uint64 is_key);
int64 timecode, uint64 is_key);
// Utility method that confirms that blocks can still be added, and that the
// cluster header has been written. Used by |DoWriteBlock*|. Returns true
......@@ -858,27 +831,20 @@ class Cluster {
int64 GetRelativeTimecode(int64 abs_timecode) const;
// Used to implement AddFrame and AddMetadata.
bool DoWriteBlock(const uint8* frame,
uint64 length,
uint64 track_number,
uint64 absolute_timecode,
uint64 generic_arg,
bool DoWriteBlock(const uint8* frame, uint64 length, uint64 track_number,
uint64 absolute_timecode, uint64 generic_arg,
WriteBlock write_block);
// Used to implement AddFrameWithAdditional
bool DoWriteBlockWithAdditional(const uint8* frame,
uint64 length,
bool DoWriteBlockWithAdditional(const uint8* frame, uint64 length,
const uint8* additional,
uint64 additional_length,
uint64 add_id,
uint64 track_number,
uint64 absolute_timecode,
uint64 additional_length, uint64 add_id,
uint64 track_number, uint64 absolute_timecode,
uint64 generic_arg,
WriteBlockAdditional write_block);
// Used to implement AddFrameWithDiscardPadding
bool DoWriteBlockWithDiscardPadding(const uint8* frame,
uint64 length,
bool DoWriteBlockWithDiscardPadding(const uint8* frame, uint64 length,
int64 discard_padding,
uint64 track_number,
uint64 absolute_timecode,
......@@ -993,6 +959,8 @@ class SegmentInfo {
uint64 timecode_scale() const { return timecode_scale_; }
void set_writing_app(const char* app);
const char* writing_app() const { return writing_app_; }
void set_date_utc(int64 date_utc) { date_utc_ = date_utc; }
int64 date_utc() const { return date_utc_; }
private:
// Segment Information element names.
......@@ -1004,6 +972,8 @@ class SegmentInfo {
uint64 timecode_scale_;
// Initially set to libwebm-%d.%d.%d.%d, major, minor, build, revision.
char* writing_app_;
// LLONG_MIN when DateUTC is not set.
int64 date_utc_;
// The file position of the duration element.
int64 duration_pos_;
......@@ -1019,10 +989,7 @@ class SegmentInfo {
// |Init| must be called before any other method in this class.
class Segment {
public:
enum Mode {
kLive = 0x1,
kFile = 0x2
};
enum Mode { kLive = 0x1, kFile = 0x2 };
enum CuesPosition {
kAfterClusters = 0x0, // Position Cues after Clusters - Default
......@@ -1070,11 +1037,8 @@ class Segment {
// functions.
// timestamp: Timestamp of the frame in nanoseconds from 0.
// is_key: Flag telling whether or not this frame is a key frame.
bool AddFrame(const uint8* frame,
uint64 length,
uint64 track_number,
uint64 timestamp_ns,
bool is_key);
bool AddFrame(const uint8* frame, uint64 length, uint64 track_number,
uint64 timestamp_ns, bool is_key);
// Writes a frame of metadata to the output medium; returns true on
// success.
......@@ -1090,11 +1054,8 @@ class Segment {
// The metadata frame is written as a block group, with a duration
// sub-element but no reference time sub-elements (indicating that
// it is considered a keyframe, per Matroska semantics).
bool AddMetadata(const uint8* frame,
uint64 length,
uint64 track_number,
uint64 timestamp_ns,
uint64 duration_ns);
bool AddMetadata(const uint8* frame, uint64 length, uint64 track_number,
uint64 timestamp_ns, uint64 duration_ns);
// Writes a frame with additional data to the output medium; returns true on
// success.
......@@ -1109,14 +1070,10 @@ class Segment {
// timestamp: Absolute timestamp of the frame, expressed in nanosecond
// units.
// is_key: Flag telling whether or not this frame is a key frame.
bool AddFrameWithAdditional(const uint8* frame,
uint64 length,
const uint8* additional,
uint64 additional_length,
uint64 add_id,
uint64 track_number,
uint64 timestamp,
bool is_key);
bool AddFrameWithAdditional(const uint8* frame, uint64 length,
const uint8* additional, uint64 additional_length,
uint64 add_id, uint64 track_number,
uint64 timestamp, bool is_key);
// Writes a frame with DiscardPadding to the output medium; returns true on
// success.
......@@ -1129,12 +1086,9 @@ class Segment {
// timestamp: Absolute timestamp of the frame, expressed in nanosecond
// units.
// is_key: Flag telling whether or not this frame is a key frame.
bool AddFrameWithDiscardPadding(const uint8* frame,
uint64 length,
int64 discard_padding,
uint64 track_number,
uint64 timestamp,
bool is_key);
bool AddFrameWithDiscardPadding(const uint8* frame, uint64 length,
int64 discard_padding, uint64 track_number,
uint64 timestamp, bool is_key);
// Writes a Frame to the output medium. Chooses the correct way of writing
// the frame (Block vs SimpleBlock) based on the parameters passed.
......@@ -1268,7 +1222,6 @@ class Segment {
// was necessary but creation was not successful.
bool DoNewClusterProcessing(uint64 track_num, uint64 timestamp_ns, bool key);
// Adjusts Cue Point values (to place Cues before Clusters) so that they
// reflect the correct offsets.
void MoveCuesBeforeClusters();
......@@ -1398,6 +1351,6 @@ class Segment {
LIBWEBM_DISALLOW_COPY_AND_ASSIGN(Segment);
};
} //end namespace mkvmuxer
} // end namespace mkvmuxer
#endif //MKVMUXER_HPP
#endif // MKVMUXER_HPP
// Copyright (c) 2012 The WebM project authors. All Rights Reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree. An additional intellectual property rights grant can be found
// in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.
#ifndef MKVMUXERTYPES_HPP
#define MKVMUXERTYPES_HPP
// Copied from Chromium basictypes.h
// A macro to disallow the copy constructor and operator= functions
// This should be used in the private: declarations for a class
#define LIBWEBM_DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)
namespace mkvmuxer {
typedef unsigned char uint8;
typedef short int16;
typedef int int32;
typedef unsigned int uint32;
typedef long long int64;
typedef unsigned long long uint64;
} //end namespace mkvmuxer
#endif // MKVMUXERTYPES_HPP
// Copyright (c) 2012 The WebM project authors. All Rights Reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree. An additional intellectual property rights grant can be found
// in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.
#ifndef MKVMUXERTYPES_HPP
#define MKVMUXERTYPES_HPP
// Copied from Chromium basictypes.h
// A macro to disallow the copy constructor and operator= functions
// This should be used in the private: declarations for a class
#define LIBWEBM_DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)
namespace mkvmuxer {
typedef unsigned char uint8;
typedef short int16;
typedef int int32;
typedef unsigned int uint32;
typedef long long int64;
typedef unsigned long long uint64;
} // end namespace mkvmuxer
#endif // MKVMUXERTYPES_HPP
......@@ -29,6 +29,13 @@
namespace mkvmuxer {
namespace {
// Date elements are always 8 octets in size.
const int kDateElementSize = 8;
} // namespace
int32 GetCodedUIntSize(uint64 value) {
if (value < 0x000000000000007FULL)
return 1;
......@@ -92,7 +99,7 @@ uint64 EbmlElementSize(uint64 type, uint64 value) {
return ebml_size;
}
uint64 EbmlElementSize(uint64 type, float /* value */ ) {
uint64 EbmlElementSize(uint64 type, float /* value */) {
// Size of EBML ID
uint64 ebml_size = GetUIntSize(type);
......@@ -137,6 +144,19 @@ uint64 EbmlElementSize(uint64 type, const uint8* value, uint64 size) {
return ebml_size;
}
uint64 EbmlDateElementSize(uint64 type, int64 value) {
// Size of EBML ID
uint64 ebml_size = GetUIntSize(type);
// Datasize
ebml_size += kDateElementSize;
// Size of Datasize
ebml_size++;
return ebml_size;
}
int32 SerializeInt(IMkvWriter* writer, int64 value, int32 size) {
if (!writer || size < 1 || size > 8)
return -1;
......@@ -302,9 +322,7 @@ bool WriteEbmlElement(IMkvWriter* writer, uint64 type, const char* value) {
return true;
}
bool WriteEbmlElement(IMkvWriter* writer,
uint64 type,
const uint8* value,
bool WriteEbmlElement(IMkvWriter* writer, uint64 type, const uint8* value,
uint64 size) {
if (!writer || !value || size < 1)
return false;
......@@ -321,12 +339,24 @@ bool WriteEbmlElement(IMkvWriter* writer,
return true;
}
uint64 WriteSimpleBlock(IMkvWriter* writer,
const uint8* data,
uint64 length,
uint64 track_number,
int64 timecode,
uint64 is_key) {
bool WriteEbmlDateElement(IMkvWriter* writer, uint64 type, int64 value) {
if (!writer)
return false;
if (WriteID(writer, type))
return false;
if (WriteUInt(writer, kDateElementSize))
return false;
if (SerializeInt(writer, value, kDateElementSize))
return false;
return true;
}
uint64 WriteSimpleBlock(IMkvWriter* writer, const uint8* data, uint64 length,
uint64 track_number, int64 timecode, uint64 is_key) {
if (!writer)
return false;
......@@ -372,7 +402,7 @@ uint64 WriteSimpleBlock(IMkvWriter* writer,
return 0;
const uint64 element_size =
GetUIntSize(kMkvSimpleBlock) + GetCodedUIntSize(size) + 4 + length;
GetUIntSize(kMkvSimpleBlock) + GetCodedUIntSize(size) + 4 + length;
return element_size;
}
......@@ -391,11 +421,8 @@ uint64 WriteSimpleBlock(IMkvWriter* writer,
// Duration size
// (duration payload)
//
uint64 WriteMetadataBlock(IMkvWriter* writer,
const uint8* data,
uint64 length,
uint64 track_number,
int64 timecode,
uint64 WriteMetadataBlock(IMkvWriter* writer, const uint8* data, uint64 length,
uint64 track_number, int64 timecode,
uint64 duration) {
// We don't backtrack when writing to the stream, so we must
// pre-compute the BlockGroup size, by summing the sizes of each
......@@ -487,47 +514,37 @@ uint64 WriteMetadataBlock(IMkvWriter* writer,
// 1 (Denotes Alpha)
// BlockAdditional
// Data
uint64 WriteBlockWithAdditional(IMkvWriter* writer,
const uint8* data,
uint64 length,
const uint8* additional,
uint64 additional_length,
uint64 add_id,
uint64 track_number,
int64 timecode,
uint64 WriteBlockWithAdditional(IMkvWriter* writer, const uint8* data,
uint64 length, const uint8* additional,
uint64 additional_length, uint64 add_id,
uint64 track_number, int64 timecode,
uint64 is_key) {
if (!data || !additional || length < 1 || additional_length < 1)
return 0;
const uint64 block_payload_size = 4 + length;
const uint64 block_elem_size = EbmlMasterElementSize(kMkvBlock,
block_payload_size) +
block_payload_size;
const uint64 block_additional_elem_size = EbmlElementSize(kMkvBlockAdditional,
additional,
additional_length);
const uint64 block_elem_size =
EbmlMasterElementSize(kMkvBlock, block_payload_size) + block_payload_size;
const uint64 block_additional_elem_size =
EbmlElementSize(kMkvBlockAdditional, additional, additional_length);
const uint64 block_addid_elem_size = EbmlElementSize(kMkvBlockAddID, add_id);
const uint64 block_more_payload_size = block_addid_elem_size +
block_additional_elem_size;
const uint64 block_more_elem_size = EbmlMasterElementSize(
kMkvBlockMore,
block_more_payload_size) +
block_more_payload_size;
const uint64 block_more_payload_size =
block_addid_elem_size + block_additional_elem_size;
const uint64 block_more_elem_size =
EbmlMasterElementSize(kMkvBlockMore, block_more_payload_size) +
block_more_payload_size;
const uint64 block_additions_payload_size = block_more_elem_size;
const uint64 block_additions_elem_size = EbmlMasterElementSize(
kMkvBlockAdditions,
block_additions_payload_size) +
block_additions_payload_size;
const uint64 block_group_payload_size = block_elem_size +
block_additions_elem_size;
const uint64 block_group_elem_size = EbmlMasterElementSize(
kMkvBlockGroup,
block_group_payload_size) +
block_group_payload_size;
const uint64 block_additions_elem_size =
EbmlMasterElementSize(kMkvBlockAdditions, block_additions_payload_size) +
block_additions_payload_size;
const uint64 block_group_payload_size =
block_elem_size + block_additions_elem_size;
const uint64 block_group_elem_size =
EbmlMasterElementSize(kMkvBlockGroup, block_group_payload_size) +
block_group_payload_size;
if (!WriteEbmlMasterElement(writer, kMkvBlockGroup,
block_group_payload_size))
if (!WriteEbmlMasterElement(writer, kMkvBlockGroup, block_group_payload_size))
return 0;
if (!WriteEbmlMasterElement(writer, kMkvBlock, block_payload_size))
......@@ -558,8 +575,8 @@ uint64 WriteBlockWithAdditional(IMkvWriter* writer,
if (!WriteEbmlElement(writer, kMkvBlockAddID, add_id))
return 0;
if (!WriteEbmlElement(writer, kMkvBlockAdditional,
additional, additional_length))
if (!WriteEbmlElement(writer, kMkvBlockAdditional, additional,
additional_length))
return 0;
return block_group_elem_size;
......@@ -571,31 +588,25 @@ uint64 WriteBlockWithAdditional(IMkvWriter* writer,
// Block
// Data
// DiscardPadding
uint64 WriteBlockWithDiscardPadding(IMkvWriter* writer,