third_party: Roll libwebm snapshot.

4ff5785 cmake: Add C++11 move ctor and member initializer tests.
402ef4d cmake: remove argc and argv from C++11 test main fns.
cbe5c40 Restore original namespaces for mkvmuxer and mkvparser.
504e0f2 Mass file extension update.
79cb980 Android.mk: Update source file locations.
01db4c2 webmids: Move to common/ sub dir.
235ce59 mkvparser: Explicitly reference internal sources in includes.
f578419 mkvmuxer: Move sources to mkvmuxer/ sub dir.
5f1065e webvtt: Organize and clean up webvtt support.
7abe8ac cmake: Add missing dumpvtt target.
f2f87e2 Makefile.unix: Tidy things up.
12f6dc3 Use <stdint.h> types instead of custom typedefs.
0407360 mkvmuxer: Write last block in each Cluster with Duration
008aa63 mkvparser: move to mkvparser sub dir.
e64bf75 Namespace reorg: Make everything a child of libwebm.
5fdb386 cmake: move c++11 checks into build/cxx11_tests.cmake.
3672488 Copy reference block values in Frame::CopyFrom()
91ca780 reapply clang-format
8d34215 Merge "Clean up AddAudioTrack in muxer_tests"
90861d4 Clean up AddAudioTrack in muxer_tests
a9dfb3d Un-ignore webm files in testdata
c5b76d8 Extract PES parser from WebM2Pes tests.
16524e8 cmake: Add include-what-you-use integration.
7015af5 iwyu/vpxpes2ts: Update includes.
c1d6a70 iwyu/webm2pes: Update includes.
110e797 iwyu/libwebm_util: Update includes.
44e31fb iwyu/webm2pes_tests: Update includes.
d919f96 iwyu/mkvwriter: Update includes.
75790e1 iwyu/mkvparser: Update includes.
5f673ca iwyu/webm2pes_main: Update includes.
747244a iwyu/vpxpes2ts_main: Update includes.
94c985f iwyu/mkvmuxerutil: Update includes.
c365630 iwyu/mkvmuxer: Update includes.
b15b8ef iwyu/file_util: Update includes.
3dfba95 iwyu/hdr_util: Update includes.
baba8b1 iwyu/vttdemux: Update includes.
3212ec1 iwyu/webvttparser: Update includes.
b6d8d92 iwyu/sample_muxer_metadata: Update includes.
a9a1a01 iwyu/sample_muxer: Update includes.
e020ffd iwyu/sample: Update includes.
18834bc iwyu/parser_tests: Update includes.
9c00ae3 iwyu/muxer_tests: Update includes.
41a17eb iwyu/test_util: Update includes
b6174be muxer_tests: Fix windows brokenness.
e092515 file_util: Remove tmpnam() usage in MSVC.
b9dc4ac test_util: Don't pass NULL to std::string() in GetTestDataDir().
1f74651 webmts: Move PES/TS sources to m2ts sub directory.
1b895e9 Rename libwebm_utils to libwebm_util.
2fabcd3 sample_muxer: Replace std::tmpnam() with libwebm::GetTempFileName().
e6a0033 Add file_util.
87f9bea Move hdr_util to common.
1f64aaf cmake: Expand C++11 tests.
6dc81c1 muxer_tests: Die immediately when unable to prep for file writing.
521ce4d webm2pes: Fix type limit warning.
64c4163 vpxpes2ts: Fix sign-compare and type-limits warnings.
741ba68 muxer_tests: Replace std::tmpnam() with GetTempFileName().
6159e83 Merge "test_util: add missing include for close()"
ff81c74 parser_tests: Fix sign compare warnings.
163f57d test_util: add missing include for close()
7c89eb5 Merge "test_util: Remove tmpnam() usage on non-MSVC targets."
c4b8686 Merge "webm2pes_tests: Fix sign compare warnings."
9c9f546 Merge "muxer_tests: Fix sign compare warnings."
0fbefef webm2pes: Silence sign compare warnings.
599e4e8 cmake: Silence clang/gcc deprecation warnings.
82f376f test_util: Remove tmpnam() usage on non-MSVC targets.
4d31d6b webm2pes_tests: Fix sign compare warnings.
07ed7e0 muxer_tests: Fix sign compare warnings.
ae2fbfe parser_tests: Silence sign compare warning.
f488528 libwebm_utils: Silence sign compare warning.
777247b Add C++11 detection to cmake file.
9b89187 Add missing include to libwebm_utils.h.
421874a Merge "mkvmuxer: Fix GCC build."
dd6ab35 Set the mastering metadata on the muxers colour
8b61ef5 mkvmuxer: Fix GCC build.
353b050 Add hdr_util.
c92e080 mkvmuxer: Use kValueNotPresent in Colour/MasteringMetadata.
2d09128 Colour element: TransferFunction renamed to TransferCharacteristics.
f2fc28e Colour element: Matrix renamed to MatrixCoefficients.
e0b1135 cmake: Minor CMakeLists.txt refactor.
1e1872b Revert change from auto_ptr to unique_ptr in sample code.
d7fc382 Track updates to the proposed Matroska Colour spec.
99981ee sample(mkvparser): Output Colour element when present.
375e416 mkvmuxer: Fix Colour element support.
eaeca34 mkvmuxer: Fix bits per channel in the colour element.
1dab7f3 mkvparser: Avoid crash when encountering a Colour element.
a1517aa sample_muxer: copy the Colour element.
ea9dd94 Merge "webm2pes: Fix tests."
8635c5b Merge "mkvparser: Make omitted values detectable in the Colour element."
ae4ae7e mkvparser: Make omitted values detectable in the Colour element.
8c8cba6 webm2pes: Fix tests.
a281a22 mkvmuxer: Add support for the Colour element and its children.
41a9147 sample_muxer: clang-format include order fix.
939a64d Signal E_BUFFER_NOT_FULL in EBMLHeader::Parse
fb1406e mkvparser: Add support for the Colour element and its children.
22bfdf7 Merge "parser_tests: Add validation of cues."
b873000 parser_tests: Add validation of cues.
799891e Update .gitignore to include some new binaries
e051c60 Merge "Update muxer test gold files"
b81d5f0 Update muxer test gold files
48b1e9a mkvparser: clang format run
93c4690 webm2pes: Add PES packet parsing tests.
65ca38f Merge "test_util: Fix gcc build."
520ca6c Merge "parser_tests: Fix gcc build."
37a38ca test_util: Fix gcc build.
ee0ebba parser_tests: Fix gcc build.
c32f970 Replace auto_ptr usage with unique_ptr.
e569ab0 webm2pes/ts: Fix gcc build.
2e55d6c Merge "add bitcode embedding support for ios"
0cfb2dc add bitcode embedding support for ios
bb8cefd webm2ts: Converts WebM VPx video to a MPEG TS.
453bf44 webm2pes: Begin addition of tests.
9299bbb libwebm: Googletest integration.
3bec1ba Merge changes I7bcb5b3e,I8ce733be,I98a928ff,I71910f24
5c83bbe Fix ParseElementHeader to support 0 payload elements
be35869 libwebm_utils: Add FileDeleter.
d6db1e1 webm2pes: Add a WebM parser init method.
aa3593e webm2pes: Rename Convert to ConvertToFile().
e8fca12 webm2pes: Fix super frame splitting.
3cb96b6 webm2pes: Move main() and helper functions into their own files.
021432b webm2pes: Fix the linux build.
82ac5fc Remove RELEASE.TXT.
852e173 webm2pes: Split super frames and packetize large frames.
faf85c2 webm2pes: Refactor header/optional header writing.
7c19266 Add Webm2Pes.
01fdee4 mkvmuxer: Disallow AddTrack() after Tracks element is output.
1ad314e mkvparser: EBMLHeader::Parse: remove dead init

Change-Id: I4026f52f59c6f7644af49b0393af502079b2fbec
This commit is contained in:
Tom Finegan 2016-03-24 13:12:51 -07:00
Родитель bfc2a7e3a0
Коммит 80ddeb281a
25 изменённых файлов: 2516 добавлений и 1256 удалений

Просмотреть файл

@ -36,21 +36,30 @@ LIBYUV_SRCS += third_party/libyuv/include/libyuv/basic_types.h \
third_party/libyuv/source/scale_neon64.cc \
third_party/libyuv/source/scale_win.cc \
LIBWEBM_COMMON_SRCS += third_party/libwebm/webmids.hpp
LIBWEBM_COMMON_SRCS += third_party/libwebm/common/hdr_util.cc \
third_party/libwebm/common/hdr_util.h \
third_party/libwebm/common/webmids.h
LIBWEBM_MUXER_SRCS += third_party/libwebm/mkvmuxer.cpp \
third_party/libwebm/mkvmuxerutil.cpp \
third_party/libwebm/mkvwriter.cpp \
third_party/libwebm/mkvmuxer.hpp \
third_party/libwebm/mkvmuxertypes.hpp \
third_party/libwebm/mkvmuxerutil.hpp \
third_party/libwebm/mkvparser.hpp \
third_party/libwebm/mkvwriter.hpp
LIBWEBM_MUXER_SRCS += third_party/libwebm/mkvmuxer/mkvmuxer.cc \
third_party/libwebm/mkvmuxer/mkvmuxerutil.cc \
third_party/libwebm/mkvmuxer/mkvwriter.cc \
third_party/libwebm/mkvmuxer/mkvmuxer.h \
third_party/libwebm/mkvmuxer/mkvmuxertypes.h \
third_party/libwebm/mkvmuxer/mkvmuxerutil.h \
third_party/libwebm/mkvparser/mkvparser.h \
third_party/libwebm/mkvmuxer/mkvwriter.h
LIBWEBM_PARSER_SRCS = third_party/libwebm/mkvparser/mkvparser.cc \
third_party/libwebm/mkvparser/mkvreader.cc \
third_party/libwebm/mkvparser/mkvparser.h \
third_party/libwebm/mkvparser/mkvreader.h
# Add compile flags and include path for libwebm sources.
ifeq ($(CONFIG_WEBM_IO),yes)
CXXFLAGS += -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS
INC_PATH-yes += $(SRC_PATH_BARE)/third_party/libwebm
endif
LIBWEBM_PARSER_SRCS = third_party/libwebm/mkvparser.cpp \
third_party/libwebm/mkvreader.cpp \
third_party/libwebm/mkvparser.hpp \
third_party/libwebm/mkvreader.hpp
# List of examples to build. UTILS are tools meant for distribution
# while EXAMPLES demonstrate specific portions of the API.
@ -70,6 +79,7 @@ ifeq ($(CONFIG_LIBYUV),yes)
endif
ifeq ($(CONFIG_WEBM_IO),yes)
vpxdec.SRCS += $(LIBWEBM_COMMON_SRCS)
vpxdec.SRCS += $(LIBWEBM_MUXER_SRCS)
vpxdec.SRCS += $(LIBWEBM_PARSER_SRCS)
vpxdec.SRCS += webmdec.cc webmdec.h
endif
@ -93,6 +103,7 @@ endif
ifeq ($(CONFIG_WEBM_IO),yes)
vpxenc.SRCS += $(LIBWEBM_COMMON_SRCS)
vpxenc.SRCS += $(LIBWEBM_MUXER_SRCS)
vpxenc.SRCS += $(LIBWEBM_PARSER_SRCS)
vpxenc.SRCS += webmenc.cc webmenc.h
endif
vpxenc.GUID = 548DEC74-7A15-4B2B-AFC3-AA102E7C25C1

Просмотреть файл

@ -394,6 +394,12 @@ $(filter %$(ASM).o,$(OBJS-yes)): $(BUILD_PFX)vpx_config.asm
$(shell $(SRC_PATH_BARE)/build/make/version.sh "$(SRC_PATH_BARE)" $(BUILD_PFX)vpx_version.h)
CLEAN-OBJS += $(BUILD_PFX)vpx_version.h
#
# Add include path for libwebm sources.
#
ifeq ($(CONFIG_WEBM_IO),yes)
CXXFLAGS += -I$(SRC_PATH_BARE)/third_party/libwebm
endif
##
## libvpx test directives
@ -469,6 +475,7 @@ test_libvpx.$(VCPROJ_SFX): $(LIBVPX_TEST_SRCS) vpx.$(VCPROJ_SFX) gtest.$(VCPROJ_
$(if $(CONFIG_STATIC_MSVCRT),--static-crt) \
--out=$@ $(INTERNAL_CFLAGS) $(CFLAGS) \
-I. -I"$(SRC_PATH_BARE)/third_party/googletest/src/include" \
$(if $(CONFIG_WEBM_IO),-I"$(SRC_PATH_BARE)/third_party/libwebm") \
-L. -l$(CODEC_LIB) -l$(GTEST_LIB) $^
PROJECTS-$(CONFIG_MSVS) += test_libvpx.$(VCPROJ_SFX)

Просмотреть файл

@ -59,10 +59,10 @@ LIBVPX_TEST_SRCS-$(CONFIG_ENCODERS) += y4m_test.cc ../y4menc.c ../y4menc.h
## WebM Parsing
ifeq ($(CONFIG_WEBM_IO), yes)
LIBWEBM_PARSER_SRCS += ../third_party/libwebm/mkvparser.cpp
LIBWEBM_PARSER_SRCS += ../third_party/libwebm/mkvreader.cpp
LIBWEBM_PARSER_SRCS += ../third_party/libwebm/mkvparser.hpp
LIBWEBM_PARSER_SRCS += ../third_party/libwebm/mkvreader.hpp
LIBWEBM_PARSER_SRCS += ../third_party/libwebm/mkvparser/mkvparser.cc
LIBWEBM_PARSER_SRCS += ../third_party/libwebm/mkvparser/mkvreader.cc
LIBWEBM_PARSER_SRCS += ../third_party/libwebm/mkvparser/mkvparser.h
LIBWEBM_PARSER_SRCS += ../third_party/libwebm/mkvparser/mkvreader.h
LIBVPX_TEST_SRCS-$(CONFIG_DECODERS) += $(LIBWEBM_PARSER_SRCS)
LIBVPX_TEST_SRCS-$(CONFIG_DECODERS) += ../tools_common.h
LIBVPX_TEST_SRCS-$(CONFIG_DECODERS) += ../webmdec.cc

11
third_party/libwebm/Android.mk поставляемый
Просмотреть файл

@ -2,9 +2,10 @@ LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE:= libwebm
LOCAL_SRC_FILES:= mkvparser.cpp \
mkvreader.cpp \
mkvmuxer.cpp \
mkvmuxerutil.cpp \
mkvwriter.cpp
LOCAL_SRC_FILES:= common/hdr_util.cc \
mkvparser/mkvparser.cc \
mkvparser/mkvreader.cc \
mkvmuxer/mkvmuxer.cc \
mkvmuxer/mkvmuxerutil.cc \
mkvmuxer/mkvwriter.cc
include $(BUILD_STATIC_LIBRARY)

2
third_party/libwebm/README.libvpx поставляемый
Просмотреть файл

@ -1,5 +1,5 @@
URL: https://chromium.googlesource.com/webm/libwebm
Version: 476366249e1fda7710a389cd41c57db42305e0d4
Version: 4ff57859383705fa697fb1a15bab8ef728d0fa74
License: BSD
License File: LICENSE.txt

34
third_party/libwebm/RELEASE.TXT поставляемый
Просмотреть файл

@ -1,34 +0,0 @@
1.0.0.5
* Handled case when no duration
* Handled empty clusters
* Handled empty clusters when seeking
* Implemented check lacing bits
1.0.0.4
* Made Cues member variables mutables
* Defined against badly-formatted cue points
* Segment::GetCluster returns CuePoint too
* Separated cue-based searches
1.0.0.3
* Added Block::GetOffset() to get a frame's offset in a block
* Changed cluster count type from size_t to long
* Parsed SeekHead to find cues
* Allowed seeking beyond end of cluster cache
* Added not to attempt to reparse cues element
* Restructured Segment::LoadCluster
* Marked position of cues without parsing cues element
* Allowed cue points to be loaded incrementally
* Implemented to load lazily cue points as they're searched
* Merged Cues::LoadCuePoint into Cues::Find
* Lazy init cues
* Loaded cue point during find
1.0.0.2
* added support for Cues element
* seeking was improved
1.0.0.1
* fixed item 141
* added item 142
* added this file, RELEASE.TXT, to repository

67
third_party/libwebm/common/file_util.cc поставляемый Normal file
Просмотреть файл

@ -0,0 +1,67 @@
// Copyright (c) 2016 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.
#include "common/file_util.h"
#include <sys/stat.h>
#ifndef _MSC_VER
#include <unistd.h> // close()
#endif
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <ios>
namespace libwebm {
std::string GetTempFileName() {
#ifndef _MSC_VER
char temp_file_name_template[] = "libwebm_temp.XXXXXX";
int fd = mkstemp(temp_file_name_template);
if (fd != -1) {
close(fd);
return std::string(temp_file_name_template);
}
return std::string();
#else
char tmp_file_name[_MAX_PATH];
errno_t err = tmpnam_s(tmp_file_name);
if (err == 0) {
return std::string(tmp_file_name);
}
return std::string();
#endif
}
uint64_t GetFileSize(const std::string& file_name) {
uint64_t file_size = 0;
#ifndef _MSC_VER
struct stat st;
st.st_size = 0;
if (stat(file_name.c_str(), &st) == 0) {
#else
struct _stat st;
st.st_size = 0;
if (_stat(file_name.c_str(), &st) == 0) {
#endif
file_size = st.st_size;
}
return file_size;
}
TempFileDeleter::TempFileDeleter() { file_name_ = GetTempFileName(); }
TempFileDeleter::~TempFileDeleter() {
std::ifstream file(file_name_.c_str());
if (file.good()) {
file.close();
std::remove(file_name_.c_str());
}
}
} // namespace libwebm

41
third_party/libwebm/common/file_util.h поставляемый Normal file
Просмотреть файл

@ -0,0 +1,41 @@
// Copyright (c) 2016 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 LIBWEBM_COMMON_FILE_UTIL_H_
#define LIBWEBM_COMMON_FILE_UTIL_H_
#include <stdint.h>
#include <string>
#include "mkvmuxer/mkvmuxertypes.h" // LIBWEBM_DISALLOW_COPY_AND_ASSIGN()
namespace libwebm {
// Returns a temporary file name.
std::string GetTempFileName();
// Returns size of file specified by |file_name|, or 0 upon failure.
uint64_t GetFileSize(const std::string& file_name);
// Manages life of temporary file specified at time of construction. Deletes
// file upon destruction.
class TempFileDeleter {
public:
TempFileDeleter();
explicit TempFileDeleter(std::string file_name) : file_name_(file_name) {}
~TempFileDeleter();
const std::string& name() const { return file_name_; }
private:
std::string file_name_;
LIBWEBM_DISALLOW_COPY_AND_ASSIGN(TempFileDeleter);
};
} // namespace libwebm
#endif // LIBWEBM_COMMON_FILE_UTIL_H_

114
third_party/libwebm/common/hdr_util.cc поставляемый Normal file
Просмотреть файл

@ -0,0 +1,114 @@
// Copyright (c) 2016 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.
#include "hdr_util.h"
#include <cstddef>
#include <new>
#include "mkvparser/mkvparser.h"
namespace libwebm {
bool CopyPrimaryChromaticity(const mkvparser::PrimaryChromaticity& parser_pc,
PrimaryChromaticityPtr* muxer_pc) {
muxer_pc->reset(new (std::nothrow)
mkvmuxer::PrimaryChromaticity(parser_pc.x, parser_pc.y));
if (!muxer_pc->get())
return false;
return true;
}
bool MasteringMetadataValuePresent(double value) {
return value != mkvparser::MasteringMetadata::kValueNotPresent;
}
bool CopyMasteringMetadata(const mkvparser::MasteringMetadata& parser_mm,
mkvmuxer::MasteringMetadata* muxer_mm) {
if (MasteringMetadataValuePresent(parser_mm.luminance_max))
muxer_mm->luminance_max = parser_mm.luminance_max;
if (MasteringMetadataValuePresent(parser_mm.luminance_min))
muxer_mm->luminance_min = parser_mm.luminance_min;
PrimaryChromaticityPtr r_ptr(NULL);
PrimaryChromaticityPtr g_ptr(NULL);
PrimaryChromaticityPtr b_ptr(NULL);
PrimaryChromaticityPtr wp_ptr(NULL);
if (parser_mm.r) {
if (!CopyPrimaryChromaticity(*parser_mm.r, &r_ptr))
return false;
}
if (parser_mm.g) {
if (!CopyPrimaryChromaticity(*parser_mm.g, &g_ptr))
return false;
}
if (parser_mm.b) {
if (!CopyPrimaryChromaticity(*parser_mm.b, &b_ptr))
return false;
}
if (parser_mm.white_point) {
if (!CopyPrimaryChromaticity(*parser_mm.white_point, &wp_ptr))
return false;
}
if (!muxer_mm->SetChromaticity(r_ptr.get(), g_ptr.get(), b_ptr.get(),
wp_ptr.get())) {
return false;
}
return true;
}
bool ColourValuePresent(long long value) {
return value != mkvparser::Colour::kValueNotPresent;
}
bool CopyColour(const mkvparser::Colour& parser_colour,
mkvmuxer::Colour* muxer_colour) {
if (!muxer_colour)
return false;
if (ColourValuePresent(parser_colour.matrix_coefficients))
muxer_colour->matrix_coefficients = parser_colour.matrix_coefficients;
if (ColourValuePresent(parser_colour.bits_per_channel))
muxer_colour->bits_per_channel = parser_colour.bits_per_channel;
if (ColourValuePresent(parser_colour.chroma_subsampling_horz))
muxer_colour->chroma_subsampling_horz =
parser_colour.chroma_subsampling_horz;
if (ColourValuePresent(parser_colour.chroma_subsampling_vert))
muxer_colour->chroma_subsampling_vert =
parser_colour.chroma_subsampling_vert;
if (ColourValuePresent(parser_colour.cb_subsampling_horz))
muxer_colour->cb_subsampling_horz = parser_colour.cb_subsampling_horz;
if (ColourValuePresent(parser_colour.cb_subsampling_vert))
muxer_colour->cb_subsampling_vert = parser_colour.cb_subsampling_vert;
if (ColourValuePresent(parser_colour.chroma_siting_horz))
muxer_colour->chroma_siting_horz = parser_colour.chroma_siting_horz;
if (ColourValuePresent(parser_colour.chroma_siting_vert))
muxer_colour->chroma_siting_vert = parser_colour.chroma_siting_vert;
if (ColourValuePresent(parser_colour.range))
muxer_colour->range = parser_colour.range;
if (ColourValuePresent(parser_colour.transfer_characteristics))
muxer_colour->transfer_characteristics =
parser_colour.transfer_characteristics;
if (ColourValuePresent(parser_colour.primaries))
muxer_colour->primaries = parser_colour.primaries;
if (ColourValuePresent(parser_colour.max_cll))
muxer_colour->max_cll = parser_colour.max_cll;
if (ColourValuePresent(parser_colour.max_fall))
muxer_colour->max_fall = parser_colour.max_fall;
if (parser_colour.mastering_metadata) {
mkvmuxer::MasteringMetadata muxer_mm;
if (!CopyMasteringMetadata(*parser_colour.mastering_metadata, &muxer_mm))
return false;
if (!muxer_colour->SetMasteringMetadata(muxer_mm))
return false;
}
return true;
}
} // namespace libwebm

46
third_party/libwebm/common/hdr_util.h поставляемый Normal file
Просмотреть файл

@ -0,0 +1,46 @@
// Copyright (c) 2016 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 LIBWEBM_COMMON_HDR_UTIL_H_
#define LIBWEBM_COMMON_HDR_UTIL_H_
#include <memory>
#include "mkvmuxer/mkvmuxer.h"
namespace mkvparser {
struct Colour;
struct MasteringMetadata;
struct PrimaryChromaticity;
} // namespace mkvparser
namespace libwebm {
// Utility types and functions for working with the Colour element and its
// children. Copiers return true upon success. Presence functions return true
// when the specified element is present.
// TODO(tomfinegan): These should be moved to libwebm_utils once c++11 is
// required by libwebm.
typedef std::auto_ptr<mkvmuxer::PrimaryChromaticity> PrimaryChromaticityPtr;
bool CopyPrimaryChromaticity(const mkvparser::PrimaryChromaticity& parser_pc,
PrimaryChromaticityPtr* muxer_pc);
bool MasteringMetadataValuePresent(double value);
bool CopyMasteringMetadata(const mkvparser::MasteringMetadata& parser_mm,
mkvmuxer::MasteringMetadata* muxer_mm);
bool ColourValuePresent(long long value);
bool CopyColour(const mkvparser::Colour& parser_colour,
mkvmuxer::Colour* muxer_colour);
} // namespace libwebm
#endif // LIBWEBM_COMMON_HDR_UTIL_H_

Просмотреть файл

@ -6,10 +6,10 @@
// in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.
#ifndef WEBMIDS_HPP
#define WEBMIDS_HPP
#ifndef COMMON_WEBMIDS_H_
#define COMMON_WEBMIDS_H_
namespace mkvmuxer {
namespace libwebm {
enum MkvId {
kMkvEBML = 0x1A45DFA3,
@ -95,6 +95,35 @@ enum MkvId {
kMkvAspectRatioType = 0x54B3,
kMkvFrameRate = 0x2383E3,
// end video
// colour
kMkvColour = 0x55B0,
kMkvMatrixCoefficients = 0x55B1,
kMkvBitsPerChannel = 0x55B2,
kMkvChromaSubsamplingHorz = 0x55B3,
kMkvChromaSubsamplingVert = 0x55B4,
kMkvCbSubsamplingHorz = 0x55B5,
kMkvCbSubsamplingVert = 0x55B6,
kMkvChromaSitingHorz = 0x55B7,
kMkvChromaSitingVert = 0x55B8,
kMkvRange = 0x55B9,
kMkvTransferCharacteristics = 0x55BA,
kMkvPrimaries = 0x55BB,
kMkvMaxCLL = 0x55BC,
kMkvMaxFALL = 0x55BD,
// mastering metadata
kMkvMasteringMetadata = 0x55D0,
kMkvPrimaryRChromaticityX = 0x55D1,
kMkvPrimaryRChromaticityY = 0x55D2,
kMkvPrimaryGChromaticityX = 0x55D3,
kMkvPrimaryGChromaticityY = 0x55D4,
kMkvPrimaryBChromaticityX = 0x55D5,
kMkvPrimaryBChromaticityY = 0x55D6,
kMkvWhitePointChromaticityX = 0x55D7,
kMkvWhitePointChromaticityY = 0x55D8,
kMkvLuminanceMax = 0x55D9,
kMkvLuminanceMin = 0x55DA,
// end mastering metadata
// end colour
// audio
kMkvAudio = 0xE1,
kMkvSamplingFrequency = 0xB5,
@ -150,6 +179,6 @@ enum MkvId {
kMkvTagString = 0x4487
};
} // end namespace mkvmuxer
} // namespace libwebm
#endif // WEBMIDS_HPP
#endif // COMMON_WEBMIDS_H_

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -6,8 +6,8 @@
// 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
#ifndef MKVMUXER_MKVMUXERTYPES_H_
#define MKVMUXER_MKVMUXERTYPES_H_
// Copied from Chromium basictypes.h
// A macro to disallow the copy constructor and operator= functions
@ -16,15 +16,4 @@
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
#endif // MKVMUXER_MKVMUXERTYPES_HPP_

Просмотреть файл

@ -6,7 +6,7 @@
// in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.
#include "mkvmuxerutil.hpp"
#include "mkvmuxer/mkvmuxerutil.h"
#ifdef __ANDROID__
#include <fcntl.h>
@ -20,8 +20,9 @@
#include <ctime>
#include <new>
#include "mkvwriter.hpp"
#include "webmids.hpp"
#include "common/webmids.h"
#include "mkvmuxer/mkvmuxer.h"
#include "mkvmuxer/mkvwriter.h"
#ifdef _MSC_VER
// Disable MSVC warnings that suggest making code non-portable.
@ -35,64 +36,68 @@ 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());
block_addid_elem_size = EbmlElementSize(kMkvBlockAddID, frame->add_id());
block_additional_elem_size =
EbmlElementSize(libwebm::kMkvBlockAdditional, frame->additional(),
frame->additional_length());
block_addid_elem_size =
EbmlElementSize(libwebm::kMkvBlockAddID, frame->add_id());
block_more_payload_size =
block_addid_elem_size + block_additional_elem_size;
block_more_elem_size =
EbmlMasterElementSize(kMkvBlockMore, block_more_payload_size) +
EbmlMasterElementSize(libwebm::kMkvBlockMore, block_more_payload_size) +
block_more_payload_size;
block_additions_payload_size = block_more_elem_size;
block_additions_elem_size =
EbmlMasterElementSize(kMkvBlockAdditions,
EbmlMasterElementSize(libwebm::kMkvBlockAdditions,
block_additions_payload_size) +
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());
EbmlElementSize(libwebm::kMkvDiscardPadding, frame->discard_padding());
}
const uint64 reference_block_timestamp =
const uint64_t reference_block_timestamp =
frame->reference_block_timestamp() / timecode_scale;
uint64 reference_block_elem_size = 0;
uint64_t reference_block_elem_size = 0;
if (!frame->is_key()) {
reference_block_elem_size =
EbmlElementSize(kMkvReferenceBlock, reference_block_timestamp);
EbmlElementSize(libwebm::kMkvReferenceBlock, reference_block_timestamp);
}
const uint64 duration = frame->duration() / timecode_scale;
uint64 block_duration_elem_size = 0;
const uint64_t duration = frame->duration() / timecode_scale;
uint64_t block_duration_elem_size = 0;
if (duration > 0)
block_duration_elem_size = EbmlElementSize(kMkvBlockDuration, duration);
block_duration_elem_size =
EbmlElementSize(libwebm::kMkvBlockDuration, duration);
const uint64 block_payload_size = 4 + frame->length();
const uint64 block_elem_size =
EbmlMasterElementSize(kMkvBlock, block_payload_size) + block_payload_size;
const uint64_t block_payload_size = 4 + frame->length();
const uint64_t block_elem_size =
EbmlMasterElementSize(libwebm::kMkvBlock, block_payload_size) +
block_payload_size;
const uint64 block_group_payload_size =
const uint64_t block_group_payload_size =
block_elem_size + block_additions_elem_size + block_duration_elem_size +
discard_padding_elem_size + reference_block_elem_size;
if (!WriteEbmlMasterElement(writer, kMkvBlockGroup,
if (!WriteEbmlMasterElement(writer, libwebm::kMkvBlockGroup,
block_group_payload_size)) {
return 0;
}
if (!WriteEbmlMasterElement(writer, kMkvBlock, block_payload_size))
if (!WriteEbmlMasterElement(writer, libwebm::kMkvBlock, block_payload_size))
return 0;
if (WriteUInt(writer, frame->track_number()))
@ -105,77 +110,81 @@ 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()) {
if (!WriteEbmlMasterElement(writer, kMkvBlockAdditions,
if (!WriteEbmlMasterElement(writer, libwebm::kMkvBlockAdditions,
block_additions_payload_size)) {
return 0;
}
if (!WriteEbmlMasterElement(writer, kMkvBlockMore, block_more_payload_size))
if (!WriteEbmlMasterElement(writer, libwebm::kMkvBlockMore,
block_more_payload_size))
return 0;
if (!WriteEbmlElement(writer, kMkvBlockAddID, frame->add_id()))
if (!WriteEbmlElement(writer, libwebm::kMkvBlockAddID, frame->add_id()))
return 0;
if (!WriteEbmlElement(writer, kMkvBlockAdditional, frame->additional(),
frame->additional_length())) {
if (!WriteEbmlElement(writer, libwebm::kMkvBlockAdditional,
frame->additional(), frame->additional_length())) {
return 0;
}
}
if (frame->discard_padding() != 0 &&
!WriteEbmlElement(writer, kMkvDiscardPadding, frame->discard_padding())) {
!WriteEbmlElement(writer, libwebm::kMkvDiscardPadding,
frame->discard_padding())) {
return false;
}
if (!frame->is_key() &&
!WriteEbmlElement(writer, kMkvReferenceBlock,
!WriteEbmlElement(writer, libwebm::kMkvReferenceBlock,
reference_block_timestamp)) {
return false;
}
if (duration > 0 && !WriteEbmlElement(writer, kMkvBlockDuration, duration)) {
if (duration > 0 &&
!WriteEbmlElement(writer, libwebm::kMkvBlockDuration, duration)) {
return false;
}
return EbmlMasterElementSize(kMkvBlockGroup, block_group_payload_size) +
return EbmlMasterElementSize(libwebm::kMkvBlockGroup,
block_group_payload_size) +
block_group_payload_size;
}
uint64 WriteSimpleBlock(IMkvWriter* writer, const Frame* const frame,
int64 timecode) {
if (WriteID(writer, kMkvSimpleBlock))
uint64_t WriteSimpleBlock(IMkvWriter* writer, const Frame* const frame,
int64_t timecode) {
if (WriteID(writer, libwebm::kMkvSimpleBlock))
return 0;
const int32 size = static_cast<int32>(frame->length()) + 4;
const int32_t size = static_cast<int32_t>(frame->length()) + 4;
if (WriteUInt(writer, size))
return 0;
if (WriteUInt(writer, static_cast<uint64>(frame->track_number())))
if (WriteUInt(writer, static_cast<uint64_t>(frame->track_number())))
return 0;
if (SerializeInt(writer, timecode, 2))
return 0;
uint64 flags = 0;
uint64_t flags = 0;
if (frame->is_key())
flags |= 0x80;
if (SerializeInt(writer, flags, 1))
return 0;
if (writer->Write(frame->frame(), static_cast<uint32>(frame->length())))
if (writer->Write(frame->frame(), static_cast<uint32_t>(frame->length())))
return 0;
return GetUIntSize(kMkvSimpleBlock) + GetCodedUIntSize(size) + 4 +
return GetUIntSize(libwebm::kMkvSimpleBlock) + GetCodedUIntSize(size) + 4 +
frame->length();
}
} // namespace
int32 GetCodedUIntSize(uint64 value) {
int32_t GetCodedUIntSize(uint64_t value) {
if (value < 0x000000000000007FULL)
return 1;
else if (value < 0x0000000000003FFFULL)
@ -193,7 +202,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)
@ -211,16 +220,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);
@ -228,9 +237,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);
@ -241,9 +250,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);
@ -254,9 +263,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);
@ -267,12 +276,12 @@ uint64 EbmlElementSize(uint64 type, float /* value */) {
return ebml_size;
}
uint64 EbmlElementSize(uint64 type, const char* value) {
uint64_t EbmlElementSize(uint64_t type, const char* value) {
if (!value)
return 0;
// Size of EBML ID
uint64 ebml_size = GetUIntSize(type);
uint64_t ebml_size = GetUIntSize(type);
// Datasize
ebml_size += strlen(value);
@ -283,12 +292,12 @@ uint64 EbmlElementSize(uint64 type, const char* value) {
return ebml_size;
}
uint64 EbmlElementSize(uint64 type, const uint8* value, uint64 size) {
uint64_t EbmlElementSize(uint64_t type, const uint8_t* value, uint64_t size) {
if (!value)
return 0;
// Size of EBML ID
uint64 ebml_size = GetUIntSize(type);
uint64_t ebml_size = GetUIntSize(type);
// Datasize
ebml_size += size;
@ -299,9 +308,9 @@ uint64 EbmlElementSize(uint64 type, const uint8* value, uint64 size) {
return ebml_size;
}
uint64 EbmlDateElementSize(uint64 type) {
uint64_t EbmlDateElementSize(uint64_t type) {
// Size of EBML ID
uint64 ebml_size = GetUIntSize(type);
uint64_t ebml_size = GetUIntSize(type);
// Datasize
ebml_size += kDateElementSize;
@ -312,18 +321,18 @@ uint64 EbmlDateElementSize(uint64 type) {
return ebml_size;
}
int32 SerializeInt(IMkvWriter* writer, int64 value, int32 size) {
int32_t SerializeInt(IMkvWriter* writer, int64_t value, int32_t size) {
if (!writer || size < 1 || size > 8)
return -1;
for (int32 i = 1; i <= size; ++i) {
const int32 byte_count = size - i;
const int32 bit_count = byte_count * 8;
for (int32_t i = 1; i <= size; ++i) {
const int32_t byte_count = size - i;
const int32_t bit_count = byte_count * 8;
const int64 bb = value >> bit_count;
const uint8 b = static_cast<uint8>(bb);
const int64_t bb = value >> bit_count;
const uint8_t b = static_cast<uint8_t>(bb);
const int32 status = writer->Write(&b, 1);
const int32_t status = writer->Write(&b, 1);
if (status < 0)
return status;
@ -332,26 +341,26 @@ int32 SerializeInt(IMkvWriter* writer, int64 value, int32 size) {
return 0;
}
int32 SerializeFloat(IMkvWriter* writer, float f) {
int32_t SerializeFloat(IMkvWriter* writer, float f) {
if (!writer)
return -1;
assert(sizeof(uint32) == sizeof(float));
assert(sizeof(uint32_t) == sizeof(float));
// This union is merely used to avoid a reinterpret_cast from float& to
// uint32& which will result in violation of strict aliasing.
union U32 {
uint32 u32;
uint32_t u32;
float f;
} value;
value.f = f;
for (int32 i = 1; i <= 4; ++i) {
const int32 byte_count = 4 - i;
const int32 bit_count = byte_count * 8;
for (int32_t i = 1; i <= 4; ++i) {
const int32_t byte_count = 4 - i;
const int32_t bit_count = byte_count * 8;
const uint8 byte = static_cast<uint8>(value.u32 >> bit_count);
const uint8_t byte = static_cast<uint8_t>(value.u32 >> bit_count);
const int32 status = writer->Write(&byte, 1);
const int32_t status = writer->Write(&byte, 1);
if (status < 0)
return status;
@ -360,21 +369,21 @@ int32 SerializeFloat(IMkvWriter* writer, float f) {
return 0;
}
int32 WriteUInt(IMkvWriter* writer, uint64 value) {
int32_t WriteUInt(IMkvWriter* writer, uint64_t value) {
if (!writer)
return -1;
int32 size = GetCodedUIntSize(value);
int32_t size = GetCodedUIntSize(value);
return WriteUIntSize(writer, value, size);
}
int32 WriteUIntSize(IMkvWriter* writer, uint64 value, int32 size) {
int32_t WriteUIntSize(IMkvWriter* writer, uint64_t value, int32_t size) {
if (!writer || size < 0 || size > 8)
return -1;
if (size > 0) {
const uint64 bit = 1LL << (size * 7);
const uint64_t bit = 1LL << (size * 7);
if (value > (bit - 2))
return -1;
@ -382,11 +391,11 @@ int32 WriteUIntSize(IMkvWriter* writer, uint64 value, int32 size) {
value |= bit;
} else {
size = 1;
int64 bit;
int64_t bit;
for (;;) {
bit = 1LL << (size * 7);
const uint64 max = bit - 2;
const uint64_t max = bit - 2;
if (value <= max)
break;
@ -403,18 +412,18 @@ int32 WriteUIntSize(IMkvWriter* writer, uint64 value, int32 size) {
return SerializeInt(writer, value, size);
}
int32 WriteID(IMkvWriter* writer, uint64 type) {
int32_t WriteID(IMkvWriter* writer, uint64_t type) {
if (!writer)
return -1;
writer->ElementStartNotify(type, writer->Position());
const int32 size = GetUIntSize(type);
const int32_t size = GetUIntSize(type);
return SerializeInt(writer, type, size);
}
bool WriteEbmlMasterElement(IMkvWriter* writer, uint64 type, uint64 size) {
bool WriteEbmlMasterElement(IMkvWriter* writer, uint64_t type, uint64_t size) {
if (!writer)
return false;
@ -427,41 +436,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;
@ -477,25 +486,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;
@ -505,13 +514,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;
@ -527,8 +536,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;
@ -537,7 +546,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;
@ -548,53 +557,53 @@ uint64 WriteFrame(IMkvWriter* writer, const Frame* const frame,
cluster->timecode_scale());
}
uint64 WriteVoidElement(IMkvWriter* writer, uint64 size) {
uint64_t WriteVoidElement(IMkvWriter* writer, uint64_t size) {
if (!writer)
return false;
// Subtract one for the void ID and the coded size.
uint64 void_entry_size = size - 1 - GetCodedUIntSize(size - 1);
uint64 void_size =
EbmlMasterElementSize(kMkvVoid, void_entry_size) + void_entry_size;
uint64_t void_entry_size = size - 1 - GetCodedUIntSize(size - 1);
uint64_t void_size =
EbmlMasterElementSize(libwebm::kMkvVoid, void_entry_size) +
void_entry_size;
if (void_size != size)
return 0;
const int64 payload_position = writer->Position();
const int64_t payload_position = writer->Position();
if (payload_position < 0)
return 0;
if (WriteID(writer, kMkvVoid))
if (WriteID(writer, libwebm::kMkvVoid))
return 0;
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;
}
} // namespace mkvmuxer
mkvmuxer::uint64 mkvmuxer::MakeUID(unsigned int* seed) {
uint64 uid = 0;
uint64_t MakeUID(unsigned int* seed) {
uint64_t uid = 0;
#ifdef __MINGW32__
srand(*seed);
@ -606,24 +615,26 @@ mkvmuxer::uint64 mkvmuxer::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;
}
return uid;
}
} // namespace mkvmuxer

83
third_party/libwebm/mkvmuxer/mkvmuxerutil.h поставляемый Normal file
Просмотреть файл

@ -0,0 +1,83 @@
// 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 MKVMUXER_MKVMUXERUTIL_H_
#define MKVMUXER_MKVMUXERUTIL_H_
#include <stdint.h>
namespace mkvmuxer {
class Cluster;
class Frame;
class IMkvWriter;
const uint64_t kEbmlUnknownValue = 0x01FFFFFFFFFFFFFFULL;
const int64_t kMaxBlockTimecode = 0x07FFFLL;
// Writes out |value| in Big Endian order. Returns 0 on success.
int32_t SerializeInt(IMkvWriter* writer, int64_t value, int32_t size);
// Returns the size in bytes of the element.
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_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_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_t value, uint64_t size);
// Outputs an Mkv ID, calls |IMkvWriter::ElementStartNotify|, and passes the
// ID to |SerializeInt|. Returns 0 on success.
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_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_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_t WriteVoidElement(IMkvWriter* writer, uint64_t size);
// Returns the version number of the muxer in |major|, |minor|, |build|,
// and |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_t MakeUID(unsigned int* seed);
} // namespace mkvmuxer
#endif // MKVMUXER_MKVMUXERUTIL_H_

Просмотреть файл

@ -6,14 +6,12 @@
// in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.
#include "mkvwriter.hpp"
#include "mkvmuxer/mkvwriter.h"
#ifdef _MSC_VER
#include <share.h> // for _SH_DENYWR
#endif
#include <new>
namespace mkvmuxer {
MkvWriter::MkvWriter() : file_(NULL), writer_owns_file_(true) {}
@ -22,7 +20,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;
@ -61,7 +59,7 @@ void MkvWriter::Close() {
file_ = NULL;
}
int64 MkvWriter::Position() const {
int64_t MkvWriter::Position() const {
if (!file_)
return 0;
@ -72,7 +70,7 @@ int64 MkvWriter::Position() const {
#endif
}
int32 MkvWriter::Position(int64 position) {
int32_t MkvWriter::Position(int64_t position) {
if (!file_)
return -1;
@ -85,6 +83,6 @@ 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

Просмотреть файл

@ -6,13 +6,13 @@
// in the file PATENTS. All contributing project authors may
// be found in the AUTHORS file in the root of the source tree.
#ifndef MKVWRITER_HPP
#define MKVWRITER_HPP
#ifndef MKVMUXER_MKVWRITER_H_
#define MKVMUXER_MKVWRITER_H_
#include <stdio.h>
#include "mkvmuxer.hpp"
#include "mkvmuxertypes.hpp"
#include "mkvmuxer/mkvmuxer.h"
#include "mkvmuxer/mkvmuxertypes.h"
namespace mkvmuxer {
@ -24,11 +24,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
@ -46,6 +46,6 @@ class MkvWriter : public IMkvWriter {
LIBWEBM_DISALLOW_COPY_AND_ASSIGN(MkvWriter);
};
} // end namespace mkvmuxer
} // namespace mkvmuxer
#endif // MKVWRITER_HPP
#endif // MKVMUXER_MKVWRITER_H_

83
third_party/libwebm/mkvmuxerutil.hpp поставляемый
Просмотреть файл

@ -1,83 +0,0 @@
// 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 MKVMUXERUTIL_HPP
#define MKVMUXERUTIL_HPP
#include "mkvmuxer.hpp"
#include "mkvmuxertypes.hpp"
namespace mkvmuxer {
class IMkvWriter;
const uint64 kEbmlUnknownValue = 0x01FFFFFFFFFFFFFFULL;
const int64 kMaxBlockTimecode = 0x07FFFLL;
// Writes out |value| in Big Endian order. Returns 0 on success.
int32 SerializeInt(IMkvWriter* writer, int64 value, int32 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);
// 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);
// 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);
// Output an Mkv master element. Returns true if the element was written.
bool WriteEbmlMasterElement(IMkvWriter* writer, uint64 value, uint64 size);
// Outputs an Mkv ID, calls |IMkvWriter::ElementStartNotify|, and passes the
// ID to |SerializeInt|. Returns 0 on success.
int32 WriteID(IMkvWriter* writer, uint64 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);
// 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);
// 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);
// Returns the version number of the muxer in |major|, |minor|, |build|,
// and |revision|.
void GetVersion(int32* major, int32* minor, int32* build, int32* 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);
} // end namespace mkvmuxer
#endif // MKVMUXERUTIL_HPP

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -5,13 +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 MKVPARSER_HPP
#define MKVPARSER_HPP
#ifndef MKVPARSER_MKVPARSER_H_
#define MKVPARSER_MKVPARSER_H_
#include <cstddef>
#include <cstdio>
#include <cstdlib>
namespace mkvparser {
@ -28,8 +25,9 @@ class IMkvReader {
virtual ~IMkvReader();
};
template<typename Type> Type* SafeArrayAlloc(unsigned long long num_elements,
unsigned long long element_size);
template <typename Type>
Type* SafeArrayAlloc(unsigned long long num_elements,
unsigned long long element_size);
long long GetUIntLength(IMkvReader*, long long, long&);
long long ReadUInt(IMkvReader*, long long, long&);
long long ReadID(IMkvReader* pReader, long long pos, long& len);
@ -391,6 +389,90 @@ class Track {
ContentEncoding** content_encoding_entries_end_;
};
struct PrimaryChromaticity {
PrimaryChromaticity() : x(0), y(0) {}
~PrimaryChromaticity() {}
static bool Parse(IMkvReader* reader, long long read_pos,
long long value_size, bool is_x,
PrimaryChromaticity** chromaticity);
double x;
double y;
};
struct MasteringMetadata {
static const double kValueNotPresent;
MasteringMetadata()
: r(NULL),
g(NULL),
b(NULL),
white_point(NULL),
luminance_max(kValueNotPresent),
luminance_min(kValueNotPresent) {}
~MasteringMetadata() {
delete r;
delete g;
delete b;
delete white_point;
}
static bool Parse(IMkvReader* reader, long long element_start,
long long element_size,
MasteringMetadata** mastering_metadata);
PrimaryChromaticity* r;
PrimaryChromaticity* g;
PrimaryChromaticity* b;
PrimaryChromaticity* white_point;
double luminance_max;
double luminance_min;
};
struct Colour {
static const long long kValueNotPresent;
// Unless otherwise noted all values assigned upon construction are the
// equivalent of unspecified/default.
Colour()
: matrix_coefficients(kValueNotPresent),
bits_per_channel(kValueNotPresent),
chroma_subsampling_horz(kValueNotPresent),
chroma_subsampling_vert(kValueNotPresent),
cb_subsampling_horz(kValueNotPresent),
cb_subsampling_vert(kValueNotPresent),
chroma_siting_horz(kValueNotPresent),
chroma_siting_vert(kValueNotPresent),
range(kValueNotPresent),
transfer_characteristics(kValueNotPresent),
primaries(kValueNotPresent),
max_cll(kValueNotPresent),
max_fall(kValueNotPresent),
mastering_metadata(NULL) {}
~Colour() {
delete mastering_metadata;
mastering_metadata = NULL;
}
static bool Parse(IMkvReader* reader, long long element_start,
long long element_size, Colour** colour);
long long matrix_coefficients;
long long bits_per_channel;
long long chroma_subsampling_horz;
long long chroma_subsampling_vert;
long long cb_subsampling_horz;
long long cb_subsampling_vert;
long long chroma_siting_horz;
long long chroma_siting_vert;
long long range;
long long transfer_characteristics;
long long primaries;
long long max_cll;
long long max_fall;
MasteringMetadata* mastering_metadata;
};
class VideoTrack : public Track {
VideoTrack(const VideoTrack&);
VideoTrack& operator=(const VideoTrack&);
@ -398,6 +480,7 @@ class VideoTrack : public Track {
VideoTrack(Segment*, long long element_start, long long element_size);
public:
virtual ~VideoTrack();
static long Parse(Segment*, const Info&, long long element_start,
long long element_size, VideoTrack*&);
@ -412,6 +495,8 @@ class VideoTrack : public Track {
bool VetEntry(const BlockEntry*) const;
long Seek(long long time_ns, const BlockEntry*&) const;
Colour* GetColour() const;
private:
long long m_width;
long long m_height;
@ -421,6 +506,8 @@ class VideoTrack : public Track {
long long m_stereo_mode;
double m_rate;
Colour* m_colour;
};
class AudioTrack : public Track {
@ -1013,7 +1100,7 @@ class Segment {
const BlockEntry* GetBlock(const CuePoint&, const CuePoint::TrackPosition&);
};
} // end namespace mkvparser
} // namespace mkvparser
inline long mkvparser::Segment::LoadCluster() {
long long pos;
@ -1022,4 +1109,4 @@ inline long mkvparser::Segment::LoadCluster() {
return LoadCluster(pos, size);
}
#endif // MKVPARSER_HPP
#endif // MKVPARSER_MKVPARSER_H_

Просмотреть файл

@ -5,8 +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 "mkvreader.hpp"
#include "mkvparser/mkvreader.h"
#include <cassert>
@ -129,4 +128,4 @@ int MkvReader::Read(long long offset, long len, unsigned char* buffer) {
return 0; // success
}
} // end namespace mkvparser
} // namespace mkvparser

Просмотреть файл

@ -5,13 +5,13 @@
// 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 MKVPARSER_MKVREADER_H_
#define MKVPARSER_MKVREADER_H_
#ifndef MKVREADER_HPP
#define MKVREADER_HPP
#include "mkvparser.hpp"
#include <cstdio>
#include "mkvparser/mkvparser.h"
namespace mkvparser {
class MkvReader : public IMkvReader {
@ -40,6 +40,6 @@ class MkvReader : public IMkvReader {
bool reader_owns_file_;
};
} // end namespace mkvparser
} // namespace mkvparser
#endif // MKVREADER_HPP
#endif // MKVPARSER_MKVREADER_H_

Просмотреть файл

@ -13,8 +13,8 @@
#include <cstring>
#include <cstdio>
#include "third_party/libwebm/mkvparser.hpp"
#include "third_party/libwebm/mkvreader.hpp"
#include "third_party/libwebm/mkvparser/mkvparser.h"
#include "third_party/libwebm/mkvparser/mkvreader.h"
namespace {

Просмотреть файл

@ -11,9 +11,9 @@
#include <string>
#include "third_party/libwebm/mkvmuxer.hpp"
#include "third_party/libwebm/mkvmuxerutil.hpp"
#include "third_party/libwebm/mkvwriter.hpp"
#include "third_party/libwebm/mkvmuxer/mkvmuxer.h"
#include "third_party/libwebm/mkvmuxer/mkvmuxerutil.h"
#include "third_party/libwebm/mkvmuxer/mkvwriter.h"
namespace {
const uint64_t kDebugTrackUid = 0xDEADBEEF;