Merge "third_party/libwebm: pull from upstream"

This commit is contained in:
Vignesh Venkatasubramanian
2014-05-06 11:15:57 -07:00
committed by Gerrit Code Review
13 changed files with 6930 additions and 8562 deletions

View File

@@ -1,5 +1,5 @@
URL: https://chromium.googlesource.com/webm/libwebm
Version: a7118d8ec564e9db841da1eb01f547f3229f240a
Version: 249629d46c6e9391f25a90cff6d19075f47474cb
License: BSD
License File: LICENSE.txt

File diff suppressed because it is too large Load Diff

View File

@@ -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_;
@@ -397,10 +399,7 @@ class VideoTrack : public Track {
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();

View File

@@ -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;
@@ -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;
@@ -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) +
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) +
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) +
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,
const uint8* data,
uint64 length,
int64 discard_padding,
uint64 track_number,
int64 timecode,
uint64 WriteBlockWithDiscardPadding(IMkvWriter* writer, const uint8* data,
uint64 length, int64 discard_padding,
uint64 track_number, int64 timecode,
uint64 is_key) {
if (!data || length < 1 || discard_padding <= 0)
return 0;
const uint64 block_payload_size = 4 + length;
const uint64 block_elem_size = EbmlMasterElementSize(kMkvBlock,
block_payload_size) +
block_payload_size;
const uint64 discard_padding_elem_size = EbmlElementSize(kMkvDiscardPadding,
discard_padding);
const uint64 block_group_payload_size = block_elem_size +
discard_padding_elem_size;
const uint64 block_group_elem_size = EbmlMasterElementSize(
kMkvBlockGroup,
block_group_payload_size) +
const uint64 block_elem_size =
EbmlMasterElementSize(kMkvBlock, block_payload_size) + block_payload_size;
const uint64 discard_padding_elem_size =
EbmlElementSize(kMkvDiscardPadding, discard_padding);
const uint64 block_group_payload_size =
block_elem_size + discard_padding_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))
@@ -635,8 +646,8 @@ uint64 WriteVoidElement(IMkvWriter* writer, uint64 size) {
// Subtract one for the void ID and the coded size.
uint64 void_entry_size = size - 1 - GetCodedUIntSize(size - 1);
uint64 void_size = EbmlMasterElementSize(kMkvVoid, void_entry_size) +
void_entry_size;
uint64 void_size =
EbmlMasterElementSize(kMkvVoid, void_entry_size) + void_entry_size;
if (void_size != size)
return 0;

View File

@@ -30,6 +30,7 @@ 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, int64 value);
// 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
@@ -52,10 +53,9 @@ int32 WriteID(IMkvWriter* writer, uint64 type);
bool WriteEbmlElement(IMkvWriter* writer, uint64 type, uint64 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,
bool WriteEbmlElement(IMkvWriter* writer, uint64 type, const uint8* value,
uint64 size);
bool WriteEbmlDateElement(IMkvWriter* writer, uint64 type, int64 value);
// Output an Mkv Simple Block.
// Inputs:
@@ -67,12 +67,8 @@ bool WriteEbmlElement(IMkvWriter* writer,
// timecode: Relative timecode of the Block. Only values in the
// range [0, 2^15) are permitted.
// is_key: Non-zero value specifies that frame is a key frame.
uint64 WriteSimpleBlock(IMkvWriter* writer,
const uint8* data,
uint64 length,
uint64 track_number,
int64 timecode,
uint64 is_key);
uint64 WriteSimpleBlock(IMkvWriter* writer, const uint8* data, uint64 length,
uint64 track_number, int64 timecode, uint64 is_key);
// Output a metadata keyframe, using a Block Group element.
// Inputs:
@@ -84,11 +80,8 @@ uint64 WriteSimpleBlock(IMkvWriter* writer,
// timecode Timecode of frame, relative to cluster timecode. Only
// values in the range [0, 2^15) are permitted.
// duration_timecode Duration of frame, using timecode units.
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_timecode);
// Output an Mkv Block with BlockAdditional data.
@@ -104,14 +97,10 @@ uint64 WriteMetadataBlock(IMkvWriter* writer,
// timecode: Relative timecode of the Block. Only values in the
// range [0, 2^15) are permitted.
// is_key: Non-zero value specifies that frame is a key frame.
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);
// Output an Mkv Block with a DiscardPadding element.
@@ -125,12 +114,9 @@ uint64 WriteBlockWithAdditional(IMkvWriter* writer,
// timecode: Relative timecode of the Block. Only values in the
// range [0, 2^15) are permitted.
// is_key: Non-zero value specifies that frame is a key frame.
uint64 WriteBlockWithDiscardPadding(IMkvWriter* writer,
const uint8* data,
uint64 length,
int64 discard_padding,
uint64 track_number,
int64 timecode,
uint64 WriteBlockWithDiscardPadding(IMkvWriter* writer, const uint8* data,
uint64 length, int64 discard_padding,
uint64 track_number, int64 timecode,
uint64 is_key);
// Output a void element. |size| must be the entire size in bytes that will be

File diff suppressed because it is too large Load Diff

View File

@@ -13,17 +13,16 @@
#include <cstdio>
#include <cstddef>
namespace mkvparser
{
namespace mkvparser {
const int E_FILE_FORMAT_INVALID = -2;
const int E_BUFFER_NOT_FULL = -3;
class IMkvReader
{
class IMkvReader {
public:
virtual int Read(long long pos, long len, unsigned char* buf) = 0;
virtual int Length(long long* total, long long* available) = 0;
protected:
virtual ~IMkvReader();
};
@@ -35,26 +34,19 @@ long long UnserializeUInt(IMkvReader*, long long pos, long long size);
long UnserializeFloat(IMkvReader*, long long pos, long long size, double&);
long UnserializeInt(IMkvReader*, long long pos, long len, long long& result);
long UnserializeString(
IMkvReader*,
long long pos,
long long size,
char*& str);
long UnserializeString(IMkvReader*, long long pos, long long size, char*& str);
long ParseElementHeader(
IMkvReader* pReader,
long ParseElementHeader(IMkvReader* pReader,
long long& pos, // consume id and size fields
long long stop, // if you know size of element's parent
long long& id,
long long& size);
long long& id, long long& size);
bool Match(IMkvReader*, long long&, unsigned long, long long&);
bool Match(IMkvReader*, long long&, unsigned long, unsigned char*&, size_t&);
void GetVersion(int& major, int& minor, int& build, int& revision);
struct EBMLHeader
{
struct EBMLHeader {
EBMLHeader();
~EBMLHeader();
long long m_version;
@@ -69,13 +61,11 @@ struct EBMLHeader
void Init();
};
class Segment;
class Track;
class Cluster;
class Block
{
class Block {
Block(const Block&);
Block& operator=(const Block&);
@@ -100,8 +90,7 @@ public:
int GetFrameCount() const; // to index frames: [0, count)
struct Frame
{
struct Frame {
long long pos; // absolute offset
long len;
@@ -124,9 +113,7 @@ protected:
const long long m_discard_padding;
};
class BlockEntry
{
class BlockEntry {
BlockEntry(const BlockEntry&);
BlockEntry& operator=(const BlockEntry&);
@@ -147,12 +134,9 @@ public:
protected:
Cluster* const m_pCluster;
const long m_index;
};
class SimpleBlock : public BlockEntry
{
class SimpleBlock : public BlockEntry {
SimpleBlock(const SimpleBlock&);
SimpleBlock& operator=(const SimpleBlock&);
@@ -165,24 +149,17 @@ public:
protected:
Block m_block;
};
class BlockGroup : public BlockEntry
{
class BlockGroup : public BlockEntry {
BlockGroup(const BlockGroup&);
BlockGroup& operator=(const BlockGroup&);
public:
BlockGroup(
Cluster*,
long index,
BlockGroup(Cluster*, long index,
long long block_start, // absolute pos of block's payload
long long block_size, // size of block's payload
long long prev,
long long next,
long long duration,
long long prev, long long next, long long duration,
long long discard_padding);
long Parse();
@@ -207,9 +184,7 @@ private:
// compressed with zlib or header stripping.
class ContentEncoding {
public:
enum {
kCTR = 1
};
enum { kCTR = 1 };
ContentEncoding();
~ContentEncoding();
@@ -262,8 +237,7 @@ public:
// starting offset of the ContentCompression payload. |size| is the size in
// bytes of the ContentCompression payload. |compression| is where the parsed
// values will be stored.
long ParseCompressionEntry(long long start,
long long size,
long ParseCompressionEntry(long long start, long long size,
IMkvReader* pReader,
ContentCompression* compression);
@@ -279,26 +253,22 @@ public:
// starting offset of the ContentEncAESSettings payload. |size| is the
// size in bytes of the ContentEncAESSettings payload. |encryption| is
// where the parsed values will be stored.
long ParseContentEncAESSettingsEntry(long long start,
long long size,
long ParseContentEncAESSettingsEntry(long long start, long long size,
IMkvReader* pReader,
ContentEncAESSettings* aes);
// Parses the ContentEncoding element from |pReader|. |start| is the
// starting offset of the ContentEncoding payload. |size| is the size in
// bytes of the ContentEncoding payload. Returns true on success.
long ParseContentEncodingEntry(long long start,
long long size,
long ParseContentEncodingEntry(long long start, long long size,
IMkvReader* pReader);
// Parses the ContentEncryption element from |pReader|. |start| is the
// starting offset of the ContentEncryption payload. |size| is the size in
// bytes of the ContentEncryption payload. |encryption| is where the parsed
// values will be stored.
long ParseEncryptionEntry(long long start,
long long size,
IMkvReader* pReader,
ContentEncryption* encryption);
long ParseEncryptionEntry(long long start, long long size,
IMkvReader* pReader, ContentEncryption* encryption);
unsigned long long encoding_order() const { return encoding_order_; }
unsigned long long encoding_scope() const { return encoding_scope_; }
@@ -323,26 +293,16 @@ private:
ContentEncoding& operator=(const ContentEncoding&);
};
class Track
{
class Track {
Track(const Track&);
Track& operator=(const Track&);
public:
class Info;
static long Create(
Segment*,
const Info&,
long long element_start,
long long element_size,
Track*&);
static long Create(Segment*, const Info&, long long element_start,
long long element_size, Track*&);
enum Type {
kVideo = 1,
kAudio = 2,
kSubtitle = 0x11,
kMetadata = 0x21
};
enum Type { kVideo = 1, kAudio = 2, kSubtitle = 0x11, kMetadata = 0x21 };
Segment* const m_pSegment;
const long long m_element_start;
@@ -364,14 +324,12 @@ public:
const BlockEntry* GetEOS() const;
struct Settings
{
struct Settings {
long long start;
long long size;
};
class Info
{
class Info {
public:
Info();
~Info();
@@ -409,15 +367,11 @@ public:
long ParseContentEncodingsEntry(long long start, long long size);
protected:
Track(
Segment*,
long long element_start,
long long element_size);
Track(Segment*, long long element_start, long long element_size);
Info m_info;
class EOSBlock : public BlockEntry
{
class EOSBlock : public BlockEntry {
public:
EOSBlock();
@@ -432,24 +386,15 @@ private:
ContentEncoding** content_encoding_entries_end_;
};
class VideoTrack : public Track
{
class VideoTrack : public Track {
VideoTrack(const VideoTrack&);
VideoTrack& operator=(const VideoTrack&);
VideoTrack(
Segment*,
long long element_start,
long long element_size);
VideoTrack(Segment*, long long element_start, long long element_size);
public:
static long Parse(
Segment*,
const Info&,
long long element_start,
long long element_size,
VideoTrack*&);
static long Parse(Segment*, const Info&, long long element_start,
long long element_size, VideoTrack*&);
long long GetWidth() const;
long long GetHeight() const;
@@ -462,26 +407,17 @@ private:
long long m_width;
long long m_height;
double m_rate;
};
class AudioTrack : public Track
{
class AudioTrack : public Track {
AudioTrack(const AudioTrack&);
AudioTrack& operator=(const AudioTrack&);
AudioTrack(
Segment*,
long long element_start,
long long element_size);
AudioTrack(Segment*, long long element_start, long long element_size);
public:
static long Parse(
Segment*,
const Info&,
long long element_start,
long long element_size,
AudioTrack*&);
static long Parse(Segment*, const Info&, long long element_start,
long long element_size, AudioTrack*&);
double GetSamplingRate() const;
long long GetChannels() const;
@@ -493,9 +429,7 @@ private:
long long m_bitDepth;
};
class Tracks
{
class Tracks {
Tracks(const Tracks&);
Tracks& operator=(const Tracks&);
@@ -506,11 +440,7 @@ public:
const long long m_element_start;
const long long m_element_size;
Tracks(
Segment*,
long long start,
long long size,
long long element_start,
Tracks(Segment*, long long start, long long size, long long element_start,
long long element_size);
~Tracks();
@@ -526,18 +456,12 @@ private:
Track** m_trackEntries;
Track** m_trackEntriesEnd;
long ParseTrackEntry(
long long payload_start,
long long payload_size,
long long element_start,
long long element_size,
long ParseTrackEntry(long long payload_start, long long payload_size,
long long element_start, long long element_size,
Track*&) const;
};
class Chapters
{
class Chapters {
Chapters(const Chapters&);
Chapters& operator=(const Chapters&);
@@ -548,12 +472,8 @@ public:
const long long m_element_start;
const long long m_element_size;
Chapters(
Segment*,
long long payload_start,
long long payload_size,
long long element_start,
long long element_size);
Chapters(Segment*, long long payload_start, long long payload_size,
long long element_start, long long element_size);
~Chapters();
@@ -562,17 +482,18 @@ public:
class Atom;
class Edition;
class Display
{
class Display {
friend class Atom;
Display();
Display(const Display&);
~Display();
Display& operator=(const Display&);
public:
const char* GetString() const;
const char* GetLanguage() const;
const char* GetCountry() const;
private:
void Init();
void ShallowCopy(Display&) const;
@@ -584,13 +505,13 @@ public:
char* m_country;
};
class Atom
{
class Atom {
friend class Edition;
Atom();
Atom(const Atom&);
~Atom();
Atom& operator=(const Atom&);
public:
unsigned long long GetUID() const;
const char* GetStringUID() const;
@@ -603,6 +524,7 @@ public:
int GetDisplayCount() const;
const Display* GetDisplay(int index) const;
private:
void Init();
void ShallowCopy(Atom&) const;
@@ -623,16 +545,17 @@ public:
int m_displays_count;
};
class Edition
{
class Edition {
friend class Chapters;
Edition();
Edition(const Edition&);
~Edition();
Edition& operator=(const Edition&);
public:
int GetAtomCount() const;
const Atom* GetAtom(int index) const;
private:
void Init();
void ShallowCopy(Edition&) const;
@@ -657,12 +580,9 @@ private:
Edition* m_editions;
int m_editions_size;
int m_editions_count;
};
class SegmentInfo
{
class SegmentInfo {
SegmentInfo(const SegmentInfo&);
SegmentInfo& operator=(const SegmentInfo&);
@@ -673,12 +593,8 @@ public:
const long long m_element_start;
const long long m_element_size;
SegmentInfo(
Segment*,
long long start,
long long size,
long long element_start,
long long element_size);
SegmentInfo(Segment*, long long start, long long size,
long long element_start, long long element_size);
~SegmentInfo();
@@ -698,9 +614,7 @@ private:
char* m_pTitleAsUTF8;
};
class SeekHead
{
class SeekHead {
SeekHead(const SeekHead&);
SeekHead& operator=(const SeekHead&);
@@ -711,19 +625,14 @@ public:
const long long m_element_start;
const long long m_element_size;
SeekHead(
Segment*,
long long start,
long long size,
long long element_start,
SeekHead(Segment*, long long start, long long size, long long element_start,
long long element_size);
~SeekHead();
long Parse();
struct Entry
{
struct Entry {
// the SeekHead entry payload
long long id;
long long pos;
@@ -738,8 +647,7 @@ public:
int GetCount() const;
const Entry* GetEntry(int idx) const;
struct VoidElement
{
struct VoidElement {
// absolute pos of Void ID
long long element_start;
@@ -757,17 +665,13 @@ private:
VoidElement* m_void_elements;
int m_void_element_count;
static bool ParseEntry(
IMkvReader*,
static bool ParseEntry(IMkvReader*,
long long pos, // payload
long long size,
Entry*);
long long size, Entry*);
};
class Cues;
class CuePoint
{
class CuePoint {
friend class Cues;
CuePoint(long, long long);
@@ -785,8 +689,7 @@ public:
long long GetTimeCode() const; // absolute but unscaled
long long GetTime(const Segment*) const; // absolute and scaled (ns units)
struct TrackPosition
{
struct TrackPosition {
long long m_track;
long long m_pos; // of cluster
long long m_block;
@@ -804,19 +707,12 @@ private:
long long m_timecode;
TrackPosition* m_track_positions;
size_t m_track_positions_count;
};
class Cues
{
class Cues {
friend class Segment;
Cues(
Segment*,
long long start,
long long size,
long long element_start,
Cues(Segment*, long long start, long long size, long long element_start,
long long element_size);
~Cues();
@@ -831,9 +727,7 @@ public:
const long long m_element_size;
bool Find( // lower bound of time_ns
long long time_ns,
const Track*,
const CuePoint*&,
long long time_ns, const Track*, const CuePoint*&,
const CuePoint::TrackPosition*&) const;
#if 0
@@ -848,8 +742,7 @@ public:
const CuePoint* GetLast() const;
const CuePoint* GetNext(const CuePoint*) const;
const BlockEntry* GetBlock(
const CuePoint*,
const BlockEntry* GetBlock(const CuePoint*,
const CuePoint::TrackPosition*) const;
bool LoadCuePoint() const;
@@ -865,12 +758,9 @@ private:
mutable long m_count;
mutable long m_preload_count;
mutable long long m_pos;
};
class Cluster
{
class Cluster {
friend class Segment;
Cluster(const Cluster&);
@@ -880,8 +770,7 @@ public:
Segment* const m_pSegment;
public:
static Cluster* Create(
Segment*,
static Cluster* Create(Segment*,
long index, // index in segment
long long off); // offset relative to segment
// long long element_size);
@@ -901,17 +790,13 @@ public:
long GetNext(const BlockEntry* curr, const BlockEntry*& next) const;
const BlockEntry* GetEntry(const Track*, long long ns = -1) const;
const BlockEntry* GetEntry(
const CuePoint&,
const BlockEntry* GetEntry(const CuePoint&,
const CuePoint::TrackPosition&) const;
// const BlockEntry* GetMaxKey(const VideoTrack*) const;
// static bool HasBlockEntries(const Segment*, long long);
static long HasBlockEntries(
const Segment*,
long long idoff,
long long& pos,
static long HasBlockEntries(const Segment*, long long idoff, long long& pos,
long& size);
long GetEntryCount() const;
@@ -922,10 +807,7 @@ public:
long GetEntry(long index, const mkvparser::BlockEntry*&) const;
protected:
Cluster(
Segment*,
long index,
long long element_start);
Cluster(Segment*, long index, long long element_start);
// long long element_size);
public:
@@ -956,12 +838,9 @@ private:
long CreateBlockGroup(long long start_offset, long long size,
long long discard_padding);
long CreateSimpleBlock(long long, long long);
};
class Segment
{
class Segment {
friend class Cues;
friend class Track;
friend class VideoTrack;
@@ -970,12 +849,9 @@ class Segment
Segment& operator=(const Segment&);
private:
Segment(
IMkvReader*,
long long elem_start,
Segment(IMkvReader*, long long elem_start,
// long long elem_size,
long long pos,
long long size);
long long pos, long long size);
public:
IMkvReader* const m_pReader;
@@ -998,10 +874,7 @@ public:
long LoadCluster(long long& pos, long& size); // load one cluster
long LoadCluster();
long ParseNext(
const Cluster* pCurr,
const Cluster*& pNext,
long long& pos,
long ParseNext(const Cluster* pCurr, const Cluster*& pNext, long long& pos,
long& size);
#if 0
@@ -1029,13 +902,10 @@ public:
const Cluster* FindOrPreloadCluster(long long pos);
long ParseCues(
long long cues_off, //offset relative to start of segment
long long& parse_pos,
long& parse_len);
long ParseCues(long long cues_off, // offset relative to start of segment
long long& parse_pos, long& parse_len);
private:
long long m_pos; // absolute file posn; what has been consumed so far
Cluster* m_pUnknownSize;
@@ -1060,16 +930,12 @@ private:
// void ParseSeekEntry(long long pos, long long size);
// void ParseCues(long long);
const BlockEntry* GetBlock(
const CuePoint&,
const CuePoint::TrackPosition&);
const BlockEntry* GetBlock(const CuePoint&, const CuePoint::TrackPosition&);
};
} // end namespace mkvparser
inline long mkvparser::Segment::LoadCluster()
{
inline long mkvparser::Segment::LoadCluster() {
long long pos;
long size;

View File

@@ -10,17 +10,11 @@
#include <cassert>
namespace mkvparser
{
namespace mkvparser {
MkvReader::MkvReader() :
m_file(NULL),
reader_owns_file_(true) {
}
MkvReader::MkvReader() : m_file(NULL), reader_owns_file_(true) {}
MkvReader::MkvReader(FILE* fp) :
m_file(fp),
reader_owns_file_(false) {
MkvReader::MkvReader(FILE* fp) : m_file(fp), reader_owns_file_(false) {
GetFileSize();
}
@@ -30,8 +24,7 @@ MkvReader::~MkvReader() {
m_file = NULL;
}
int MkvReader::Open(const char* fileName)
{
int MkvReader::Open(const char* fileName) {
if (fileName == NULL)
return -1;
@@ -83,17 +76,14 @@ bool MkvReader::GetFileSize() {
return true;
}
void MkvReader::Close()
{
if (m_file != NULL)
{
void MkvReader::Close() {
if (m_file != NULL) {
fclose(m_file);
m_file = NULL;
}
}
int MkvReader::Length(long long* total, long long* available)
{
int MkvReader::Length(long long* total, long long* available) {
if (m_file == NULL)
return -1;
@@ -106,8 +96,7 @@ int MkvReader::Length(long long* total, long long* available)
return 0;
}
int MkvReader::Read(long long offset, long len, unsigned char* buffer)
{
int MkvReader::Read(long long offset, long len, unsigned char* buffer) {
if (m_file == NULL)
return -1;

View File

@@ -12,16 +12,12 @@
#include "mkvparser.hpp"
#include <cstdio>
namespace mkvparser
{
namespace mkvparser {
class MkvReader : public IMkvReader
{
MkvReader(const MkvReader&);
MkvReader& operator=(const MkvReader&);
class MkvReader : public IMkvReader {
public:
MkvReader();
MkvReader(FILE* fp);
explicit MkvReader(FILE* fp);
virtual ~MkvReader();
int Open(const char*);
@@ -29,7 +25,10 @@ public:
virtual int Read(long long position, long length, unsigned char* buffer);
virtual int Length(long long* total, long long* available);
private:
MkvReader(const MkvReader&);
MkvReader& operator=(const MkvReader&);
// Determines the size of the file. This is called either by the constructor
// or by the Open function depending on file ownership. Returns true on

View File

@@ -16,15 +16,11 @@
namespace mkvmuxer {
MkvWriter::MkvWriter() : file_(NULL), writer_owns_file_(true) {
}
MkvWriter::MkvWriter() : file_(NULL), writer_owns_file_(true) {}
MkvWriter::MkvWriter(FILE* fp): file_(fp), writer_owns_file_(false) {
}
MkvWriter::MkvWriter(FILE* fp) : file_(fp), writer_owns_file_(false) {}
MkvWriter::~MkvWriter() {
Close();
}
MkvWriter::~MkvWriter() { Close(); }
int32 MkvWriter::Write(const void* buffer, uint32 length) {
if (!file_)
@@ -87,11 +83,8 @@ int32 MkvWriter::Position(int64 position) {
#endif
}
bool MkvWriter::Seekable() const {
return true;
}
bool MkvWriter::Seekable() const { return true; }
void MkvWriter::ElementStartNotify(uint64, int64) {
}
void MkvWriter::ElementStartNotify(uint64, int64) {}
} // namespace mkvmuxer

View File

@@ -20,7 +20,7 @@ namespace mkvmuxer {
class MkvWriter : public IMkvWriter {
public:
MkvWriter();
MkvWriter(FILE* fp);
explicit MkvWriter(FILE* fp);
virtual ~MkvWriter();
// IMkvWriter interface