Use <stdint.h> types instead of custom typedefs.

Change-Id: Ia43b81649a14d0509aef2119be7a0ea9be955201
This commit is contained in:
Tom Finegan 2016-03-16 21:14:26 -07:00
parent 0407360dcf
commit 12f6dc34b4
14 changed files with 814 additions and 800 deletions

View File

@ -37,6 +37,9 @@ else ()
STRING "" FORCE)
endif ()
set(CMAKE_CXX_FLAGS "-D__STDC_CONSTANT_MACROS ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "-D__STDC_LIMIT_MACROS ${CMAKE_CXX_FLAGS}")
# mkvparser section.
# TODO(tomfinegan): move to mkvparser/CMakeLists.txt.
add_library(mkvparser STATIC

View File

@ -1,5 +1,5 @@
CXX := g++
CXXFLAGS := -W -Wall -g -MMD -MP
CXXFLAGS := -W -Wall -g -MMD -MP -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS
LIBWEBMA := libwebm.a
LIBWEBMSO := libwebm.so
WEBMOBJS := mkvmuxer.o mkvmuxerutil.o mkvwriter.o

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -16,17 +16,4 @@
TypeName(const TypeName&); \
void operator=(const TypeName&)
namespace libwebm {
// TODO(tomfinegan): These types are no longer necessary: drop these, and use
// cstdint/stdint.h types.
typedef unsigned char uint8;
typedef short int16;
typedef int int32;
typedef unsigned int uint32;
typedef long long int64;
typedef unsigned long long uint64;
} // namespace libwebm
#endif // MKVMUXERTYPES_HPP

View File

@ -12,6 +12,8 @@
#include <fcntl.h>
#endif
#include <stdint.h>
#include <cassert>
#include <cmath>
#include <cstdio>
@ -37,14 +39,14 @@ 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(
kMkvBlockAdditional, frame->additional(), frame->additional_length());
@ -62,30 +64,30 @@ 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(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(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(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(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;
@ -107,7 +109,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()) {
@ -146,29 +148,29 @@ 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, 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(kMkvSimpleBlock) + GetCodedUIntSize(size) + 4 +
@ -177,7 +179,7 @@ uint64 WriteSimpleBlock(IMkvWriter* writer, const Frame* const frame,
} // namespace
int32 GetCodedUIntSize(uint64 value) {
int32_t GetCodedUIntSize(uint64_t value) {
if (value < 0x000000000000007FULL)
return 1;
else if (value < 0x0000000000003FFFULL)
@ -195,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)
@ -213,16 +215,16 @@ 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);
@ -230,9 +232,9 @@ uint64 EbmlMasterElementSize(uint64 type, uint64 value) {
return 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);
@ -243,9 +245,9 @@ uint64 EbmlElementSize(uint64 type, int64 value) {
return ebml_size;
}
uint64 EbmlElementSize(uint64 type, uint64 value) {
uint64_t EbmlElementSize(uint64_t type, uint64_t value) {
// Size of EBML ID
int32 ebml_size = GetUIntSize(type);
int32_t ebml_size = GetUIntSize(type);
// Datasize
ebml_size += GetUIntSize(value);
@ -256,9 +258,9 @@ uint64 EbmlElementSize(uint64 type, uint64 value) {
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 = GetUIntSize(type);
// Datasize
ebml_size += sizeof(float);
@ -269,12 +271,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 = GetUIntSize(type);
// Datasize
ebml_size += strlen(value);
@ -285,12 +287,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 = GetUIntSize(type);
// Datasize
ebml_size += size;
@ -301,9 +303,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 = GetUIntSize(type);
// Datasize
ebml_size += kDateElementSize;
@ -314,18 +316,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;
@ -334,26 +336,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;
@ -362,21 +364,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;
@ -384,11 +386,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;
@ -405,18 +407,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;
@ -429,41 +431,41 @@ 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) {
if (!writer)
return false;
if (WriteID(writer, type))
return false;
const uint64 size = GetUIntSize(value);
const uint64_t size = GetUIntSize(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;
@ -479,25 +481,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;
@ -507,13 +509,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;
@ -529,8 +531,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;
@ -539,7 +541,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;
@ -550,19 +552,19 @@ 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 =
uint64_t void_entry_size = size - 1 - GetCodedUIntSize(size - 1);
uint64_t void_size =
EbmlMasterElementSize(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;
@ -572,29 +574,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);
@ -606,21 +609,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__
int32 temp_num = 1;
int32_t temp_num = 1;
int fd = open("/dev/urandom", O_RDONLY);
if (fd != -1) {
read(fd, &temp_num, sizeof(int32));
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;
}

View File

@ -5,11 +5,10 @@
// 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 MKVMUXERUTIL_HPP
#define MKVMUXERUTIL_HPP
#include "mkvmuxertypes.hpp"
#include <stdint.h>
namespace libwebm {
namespace mkvmuxer {
@ -17,67 +16,68 @@ class Cluster;
class Frame;
class IMkvWriter;
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);
// 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 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);
uint64_t MakeUID(unsigned int* seed);
} // namespace mkvmuxer
} // namespace libwebm

View File

@ -21,7 +21,7 @@ MkvWriter::MkvWriter(FILE* fp) : file_(fp), writer_owns_file_(false) {}
MkvWriter::~MkvWriter() { Close(); }
int32 MkvWriter::Write(const void* buffer, uint32 length) {
int32_t MkvWriter::Write(const void* buffer, uint32_t length) {
if (!file_)
return -1;
@ -60,7 +60,7 @@ void MkvWriter::Close() {
file_ = NULL;
}
int64 MkvWriter::Position() const {
int64_t MkvWriter::Position() const {
if (!file_)
return 0;
@ -71,7 +71,7 @@ int64 MkvWriter::Position() const {
#endif
}
int32 MkvWriter::Position(int64 position) {
int32_t MkvWriter::Position(int64_t position) {
if (!file_)
return -1;
@ -84,7 +84,7 @@ int32 MkvWriter::Position(int64 position) {
bool MkvWriter::Seekable() const { return true; }
void MkvWriter::ElementStartNotify(uint64, int64) {}
void MkvWriter::ElementStartNotify(uint64_t, int64_t) {}
} // namespace mkvmuxer
} // namespace libwebm

View File

@ -25,11 +25,11 @@ class MkvWriter : public IMkvWriter {
virtual ~MkvWriter();
// IMkvWriter interface
virtual int64 Position() const;
virtual int32 Position(int64 position);
virtual int64_t Position() const;
virtual int32_t Position(int64_t position);
virtual bool Seekable() const;
virtual int32 Write(const void* buffer, uint32 length);
virtual void ElementStartNotify(uint64 element_id, int64 position);
virtual int32_t Write(const void* buffer, uint32_t length);
virtual void ElementStartNotify(uint64_t element_id, int64_t position);
// Creates and opens a file for writing. |filename| is the name of the file
// to open. This function will overwrite the contents of |filename|. Returns

View File

@ -5,6 +5,7 @@
// 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.
#include <stdint.h>
#include <cstdio>
#include <cstdlib>
@ -158,8 +159,8 @@ int main(int argc, char* argv[]) {
bool cues_before_clusters = false;
bool cues_on_video_track = true;
bool cues_on_audio_track = false;
libwebm::uint64 max_cluster_duration = 0;
libwebm::uint64 max_cluster_size = 0;
uint64_t max_cluster_duration = 0;
uint64_t max_cluster_size = 0;
bool switch_tracks = false;
int audio_track_number = 0; // 0 tells muxer to decide.
int video_track_number = 0; // 0 tells muxer to decide.
@ -170,9 +171,9 @@ int main(int argc, char* argv[]) {
bool output_cues_block_number = true;
libwebm::uint64 display_width = 0;
libwebm::uint64 display_height = 0;
libwebm::uint64 stereo_mode = 0;
uint64_t display_width = 0;
uint64_t display_height = 0;
uint64_t stereo_mode = 0;
metadata_files_t metadata_files;
@ -207,8 +208,7 @@ int main(int argc, char* argv[]) {
cues_on_video_track = false;
} else if (!strcmp("-max_cluster_duration", argv[i]) && i < argc_check) {
const double seconds = strtod(argv[++i], &end);
max_cluster_duration =
static_cast<libwebm::uint64>(seconds * 1000000000.0);
max_cluster_duration = static_cast<uint64_t>(seconds * 1000000000.0);
} else if (!strcmp("-max_cluster_size", argv[i]) && i < argc_check) {
max_cluster_size = strtol(argv[++i], &end, 10);
} else if (!strcmp("-switch_tracks", argv[i]) && i < argc_check) {
@ -344,8 +344,8 @@ int main(int argc, char* argv[]) {
const libwebm::mkvparser::Tracks* const parser_tracks =
parser_segment->GetTracks();
unsigned long i = 0;
libwebm::uint64 vid_track = 0; // no track added
libwebm::uint64 aud_track = 0; // no track added
uint64_t vid_track = 0; // no track added
uint64_t aud_track = 0; // no track added
using libwebm::mkvparser::Track;

View File

@ -33,7 +33,7 @@ bool SampleMuxerMetadata::Load(const char* file, Kind kind) {
if (kind == kChapters)
return LoadChapters(file);
uint64 track_num;
uint64_t track_num;
if (!AddTrack(kind, &track_num)) {
printf("Unable to add track for WebVTT file \"%s\"\n", file);
@ -58,7 +58,7 @@ bool SampleMuxerMetadata::AddChapters() {
return true;
}
bool SampleMuxerMetadata::Write(int64 time_ns) {
bool SampleMuxerMetadata::Write(int64_t time_ns) {
typedef cues_set_t::iterator iter_t;
iter_t i = cues_set_.begin();
@ -174,8 +174,8 @@ bool SampleMuxerMetadata::AddChapter(const cue_t& cue) {
const time_ms_t stop_time_ms = cue.stop_time.presentation();
enum { kNsPerMs = 1000000 };
const uint64 start_time_ns = start_time_ms * kNsPerMs;
const uint64 stop_time_ns = stop_time_ms * kNsPerMs;
const uint64_t start_time_ns = start_time_ms * kNsPerMs;
const uint64_t stop_time_ns = stop_time_ms * kNsPerMs;
chapter->set_time(*segment_, start_time_ns, stop_time_ns);
@ -203,7 +203,7 @@ bool SampleMuxerMetadata::AddChapter(const cue_t& cue) {
return true;
}
bool SampleMuxerMetadata::AddTrack(Kind kind, uint64* track_num) {
bool SampleMuxerMetadata::AddTrack(Kind kind, uint64_t* track_num) {
*track_num = 0;
// Track number value 0 means "let muxer choose track number"
@ -252,7 +252,7 @@ bool SampleMuxerMetadata::AddTrack(Kind kind, uint64* track_num) {
}
bool SampleMuxerMetadata::Parse(const char* file, Kind /* kind */,
uint64 track_num) {
uint64_t track_num) {
libwebvtt::VttReader r;
int e = r.Open(file);
@ -361,26 +361,26 @@ void SampleMuxerMetadata::WriteCuePayload(const cue_t::payload_t& payload,
bool SampleMuxerMetadata::SortableCue::Write(mkvmuxer::Segment* segment) const {
// Cue start time expressed in milliseconds
const int64 start_ms = cue.start_time.presentation();
const int64_t start_ms = cue.start_time.presentation();
// Cue start time expressed in nanoseconds (MKV time)
const int64 start_ns = start_ms * 1000000;
const int64_t start_ns = start_ms * 1000000;
// Cue stop time expressed in milliseconds
const int64 stop_ms = cue.stop_time.presentation();
const int64_t stop_ms = cue.stop_time.presentation();
// Cue stop time expressed in nanonseconds
const int64 stop_ns = stop_ms * 1000000;
const int64_t stop_ns = stop_ms * 1000000;
// Metadata blocks always specify the block duration.
const int64 duration_ns = stop_ns - start_ns;
const int64_t duration_ns = stop_ns - start_ns;
std::string frame;
MakeFrame(cue, &frame);
typedef const uint8* data_t;
typedef const uint8_t* data_t;
const data_t buf = reinterpret_cast<data_t>(frame.data());
const uint64 len = frame.length();
const uint64_t len = frame.length();
mkvmuxer::Frame muxer_frame;
if (!muxer_frame.Init(buf, len))

View File

@ -9,6 +9,8 @@
#ifndef SAMPLE_MUXER_METADATA_H_ // NOLINT
#define SAMPLE_MUXER_METADATA_H_
#include <stdint.h>
#include <list>
#include <set>
#include <string>
@ -45,19 +47,19 @@ class SampleMuxerMetadata {
// Write any WebVTT cues whose time is less or equal to |time_ns| as
// a metadata block in its corresponding track. If |time_ns| is
// negative, write all remaining cues. Returns false on error.
bool Write(int64 time_ns);
bool Write(int64_t time_ns);
private:
typedef libwebvtt::Cue cue_t;
// Used to sort cues as they are loaded.
struct SortableCue {
bool operator>(int64 time_ns) const {
bool operator>(int64_t time_ns) const {
// Cue start time expressed in milliseconds
const int64 start_ms = cue.start_time.presentation();
const int64_t start_ms = cue.start_time.presentation();
// Cue start time expressed in nanoseconds (MKV time)
const int64 start_ns = start_ms * 1000000;
const int64_t start_ns = start_ms * 1000000;
return (start_ns > time_ns);
}
@ -76,7 +78,7 @@ class SampleMuxerMetadata {
// error.
bool Write(mkvmuxer::Segment* segment) const;
uint64 track_num;
uint64_t track_num;
cue_t cue;
};
@ -99,12 +101,12 @@ class SampleMuxerMetadata {
// Add a metadata track to the segment having the indicated |kind|,
// returning the |track_num| that has been chosen for this track.
// Returns false on error.
bool AddTrack(Kind kind, uint64* track_num);
bool AddTrack(Kind kind, uint64_t* track_num);
// Parse the WebVTT |file| having the indicated |kind| and
// |track_num|, adding each parsed cue to cues set. Returns false
// on error.
bool Parse(const char* file, Kind kind, uint64 track_num);
bool Parse(const char* file, Kind kind, uint64_t track_num);
// Converts a WebVTT cue to a Matroska metadata block.
static void MakeFrame(const cue_t& cue, std::string* frame);

View File

@ -5,8 +5,9 @@
// 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.
#include <stdint.h>
#include <array>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <iomanip>
@ -20,7 +21,6 @@
#include "common/file_util.h"
#include "common/libwebm_util.h"
#include "mkvmuxer.hpp"
#include "mkvmuxertypes.hpp"
#include "mkvparser/mkvreader.hpp"
#include "mkvwriter.hpp"
#include "testing/test_util.h"
@ -123,7 +123,7 @@ TEST_F(MuxerTest, SegmentInfo) {
info->set_duration(2.345);
EXPECT_STREQ(kAppString, info->muxing_app());
EXPECT_STREQ(kAppString, info->writing_app());
EXPECT_EQ(static_cast<uint64>(kTimeCodeScale), info->timecode_scale());
EXPECT_EQ(static_cast<uint64_t>(kTimeCodeScale), info->timecode_scale());
EXPECT_DOUBLE_EQ(2.345, info->duration());
AddVideoTrack();
@ -141,19 +141,19 @@ TEST_F(MuxerTest, AddTracks) {
VideoTrack* const video =
dynamic_cast<VideoTrack*>(segment_.GetTrackByNumber(kVideoTrackNumber));
ASSERT_TRUE(video != NULL);
EXPECT_EQ(static_cast<uint64>(kWidth), video->width());
EXPECT_EQ(static_cast<uint64>(kHeight), video->height());
EXPECT_EQ(static_cast<uint64_t>(kWidth), video->width());
EXPECT_EQ(static_cast<uint64_t>(kHeight), video->height());
video->set_name(kTrackName);
video->set_display_width(kWidth - 10);
video->set_display_height(kHeight - 10);
video->set_frame_rate(0.5);
EXPECT_STREQ(kTrackName, video->name());
const uint64 kDisplayWidth = kWidth - 10;
const uint64_t kDisplayWidth = kWidth - 10;
EXPECT_EQ(kDisplayWidth, video->display_width());
const uint64 kDisplayHeight = kHeight - 10;
const uint64_t kDisplayHeight = kHeight - 10;
EXPECT_EQ(kDisplayHeight, video->display_height());
EXPECT_DOUBLE_EQ(0.5, video->frame_rate());
EXPECT_EQ(static_cast<uint64>(kVideoTrackNumber), video->uid());
EXPECT_EQ(static_cast<uint64_t>(kVideoTrackNumber), video->uid());
// Add an Audio Track
const int aud_track =
@ -162,14 +162,14 @@ TEST_F(MuxerTest, AddTracks) {
AudioTrack* const audio =
dynamic_cast<AudioTrack*>(segment_.GetTrackByNumber(aud_track));
EXPECT_EQ(kSampleRate, audio->sample_rate());
EXPECT_EQ(static_cast<uint64>(kChannels), audio->channels());
EXPECT_EQ(static_cast<uint64_t>(kChannels), audio->channels());
ASSERT_TRUE(audio != NULL);
audio->set_name(kTrackName);
audio->set_bit_depth(kBitDepth);
audio->set_uid(kAudioTrackNumber);
EXPECT_STREQ(kTrackName, audio->name());
EXPECT_EQ(static_cast<uint64>(kBitDepth), audio->bit_depth());
EXPECT_EQ(static_cast<uint64>(kAudioTrackNumber), audio->uid());
EXPECT_EQ(static_cast<uint64_t>(kBitDepth), audio->bit_depth());
EXPECT_EQ(static_cast<uint64_t>(kAudioTrackNumber), audio->uid());
AddDummyFrameAndFinalize(kVideoTrackNumber);
CloseWriter();
@ -487,7 +487,7 @@ TEST_F(MuxerTest, CuesBeforeClusters) {
TEST_F(MuxerTest, MaxClusterSize) {
EXPECT_TRUE(SegmentInit(false, false));
AddVideoTrack();
const uint64 kMaxClusterSize = 20;
const uint64_t kMaxClusterSize = 20;
segment_.set_max_cluster_size(kMaxClusterSize);
EXPECT_EQ(kMaxClusterSize, segment_.max_cluster_size());
EXPECT_TRUE(segment_.AddFrame(dummy_data_, 1, kVideoTrackNumber, 0, false));
@ -512,7 +512,7 @@ TEST_F(MuxerTest, MaxClusterSize) {
TEST_F(MuxerTest, MaxClusterDuration) {
EXPECT_TRUE(SegmentInit(false, false));
AddVideoTrack();
const uint64 kMaxClusterDuration = 4000000;
const uint64_t kMaxClusterDuration = 4000000;
segment_.set_max_cluster_duration(kMaxClusterDuration);
EXPECT_EQ(kMaxClusterDuration, segment_.max_cluster_duration());
@ -537,9 +537,9 @@ TEST_F(MuxerTest, MaxClusterDuration) {
}
TEST_F(MuxerTest, SetCuesTrackNumber) {
const uint64 kTrackNumber = 10;
const uint64_t kTrackNumber = 10;
EXPECT_TRUE(SegmentInit(true, false));
const uint64 vid_track =
const uint64_t vid_track =
segment_.AddVideoTrack(kWidth, kHeight, kTrackNumber);
EXPECT_EQ(kTrackNumber, vid_track);
segment_.GetTrackByNumber(vid_track)->set_uid(kVideoTrackNumber);

View File

@ -8,8 +8,9 @@
#ifndef LIBWEBM_TESTING_TEST_UTIL_H_
#define LIBWEBM_TESTING_TEST_UTIL_H_
#include <stdint.h>
#include <cstddef>
#include <cstdint>
#include <string>
namespace libwebm {