2013-09-24 01:35:40 +00:00
|
|
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/media/formats/mp4/box_definitions.h"
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2014-09-30 23:52:58 +00:00
|
|
|
#include <limits>
|
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/base/logging.h"
|
|
|
|
#include "packager/media/base/bit_reader.h"
|
2016-01-15 21:40:44 +00:00
|
|
|
#include "packager/media/base/macros.h"
|
2016-04-06 23:21:45 +00:00
|
|
|
#include "packager/media/base/rcheck.h"
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/media/formats/mp4/box_buffer.h"
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2013-11-27 01:52:13 +00:00
|
|
|
namespace {
|
2014-09-30 21:52:21 +00:00
|
|
|
const uint32_t kFourCCSize = 4;
|
2013-11-27 01:52:13 +00:00
|
|
|
|
2014-10-15 21:56:12 +00:00
|
|
|
// Key Id size as defined in CENC spec.
|
|
|
|
const uint32_t kCencKeyIdSize = 16;
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
// 9 uint32_t in big endian formatted array.
|
|
|
|
const uint8_t kUnityMatrix[] = {0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0, 0, 0};
|
2013-11-27 01:52:13 +00:00
|
|
|
|
|
|
|
// Default entries for HandlerReference box.
|
|
|
|
const char kVideoHandlerName[] = "VideoHandler";
|
|
|
|
const char kAudioHandlerName[] = "SoundHandler";
|
2015-11-23 23:12:04 +00:00
|
|
|
const char kTextHandlerName[] = "TextHandler";
|
2013-11-27 01:52:13 +00:00
|
|
|
|
|
|
|
// Default values for VideoSampleEntry box.
|
2014-09-30 21:52:21 +00:00
|
|
|
const uint32_t kVideoResolution = 0x00480000; // 72 dpi.
|
|
|
|
const uint16_t kVideoFrameCount = 1;
|
|
|
|
const uint16_t kVideoDepth = 0x0018;
|
2013-11-27 01:52:13 +00:00
|
|
|
|
2015-10-27 00:52:57 +00:00
|
|
|
const uint32_t kCompressorNameSize = 32u;
|
2015-10-26 20:50:22 +00:00
|
|
|
const char kAvcCompressorName[] = "\012AVC Coding";
|
2015-10-29 00:26:29 +00:00
|
|
|
const char kHevcCompressorName[] = "\013HEVC Coding";
|
2015-10-26 20:50:22 +00:00
|
|
|
const char kVpcCompressorName[] = "\012VPC Coding";
|
2015-10-27 00:52:57 +00:00
|
|
|
|
2015-11-23 23:12:04 +00:00
|
|
|
// Using negative value as "not set". It is very unlikely that 2^31 cues happen
|
|
|
|
// at once.
|
|
|
|
const int kCueSourceIdNotSet = -1;
|
|
|
|
|
2016-04-12 22:39:10 +00:00
|
|
|
const size_t kInvalidIvSize = 1;
|
2015-12-21 18:34:21 +00:00
|
|
|
// According to ISO/IEC FDIS 23001-7: CENC spec, IV should be either
|
|
|
|
// 64-bit (8-byte) or 128-bit (16-byte).
|
2016-04-12 22:39:10 +00:00
|
|
|
// |per_sample_iv_size| of 0 means constant_iv is used.
|
2016-08-14 22:28:21 +00:00
|
|
|
bool IsIvSizeValid(uint8_t per_sample_iv_size) {
|
2016-04-12 22:39:10 +00:00
|
|
|
return per_sample_iv_size == 0 || per_sample_iv_size == 8 ||
|
|
|
|
per_sample_iv_size == 16;
|
2015-12-21 18:34:21 +00:00
|
|
|
}
|
|
|
|
|
2016-01-04 18:57:05 +00:00
|
|
|
// Default values to construct the following fields in ddts box. Values are set
|
|
|
|
// according to FFMPEG.
|
|
|
|
// bit(2) FrameDuration; // 3 = 4096
|
|
|
|
// bit(5) StreamConstruction; // 18
|
|
|
|
// bit(1) CoreLFEPresent; // 0 = none
|
|
|
|
// bit(6) CoreLayout; // 31 = ignore core layout
|
|
|
|
// bit(14) CoreSize; // 0
|
|
|
|
// bit(1) StereoDownmix // 0 = none
|
|
|
|
// bit(3) RepresentationType; // 4
|
|
|
|
// bit(16) ChannelLayout; // 0xf = 5.1 channel layout.
|
|
|
|
// bit(1) MultiAssetFlag // 0 = single asset
|
|
|
|
// bit(1) LBRDurationMod // 0 = ignore
|
|
|
|
// bit(1) ReservedBoxPresent // 0 = none
|
|
|
|
// bit(5) Reserved // 0
|
|
|
|
const uint8_t kDdtsExtraData[] = {0xe4, 0x7c, 0, 4, 0, 0x0f, 0};
|
|
|
|
|
2014-10-07 21:41:40 +00:00
|
|
|
// Utility functions to check if the 64bit integers can fit in 32bit integer.
|
2014-09-30 21:52:21 +00:00
|
|
|
bool IsFitIn32Bits(uint64_t a) {
|
2014-09-30 23:52:58 +00:00
|
|
|
return a <= std::numeric_limits<uint32_t>::max();
|
2014-09-30 21:52:21 +00:00
|
|
|
}
|
2014-10-07 21:41:40 +00:00
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
bool IsFitIn32Bits(int64_t a) {
|
2014-09-30 23:52:58 +00:00
|
|
|
return a <= std::numeric_limits<int32_t>::max() &&
|
|
|
|
a >= std::numeric_limits<int32_t>::min();
|
2014-09-30 21:52:21 +00:00
|
|
|
}
|
2014-10-07 21:41:40 +00:00
|
|
|
|
|
|
|
template <typename T1, typename T2>
|
|
|
|
bool IsFitIn32Bits(T1 a1, T2 a2) {
|
|
|
|
return IsFitIn32Bits(a1) && IsFitIn32Bits(a2);
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
2014-10-07 21:41:40 +00:00
|
|
|
|
|
|
|
template <typename T1, typename T2, typename T3>
|
|
|
|
bool IsFitIn32Bits(T1 a1, T2 a2, T3 a3) {
|
|
|
|
return IsFitIn32Bits(a1) && IsFitIn32Bits(a2) && IsFitIn32Bits(a3);
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2013-09-24 01:35:40 +00:00
|
|
|
namespace media {
|
|
|
|
namespace mp4 {
|
|
|
|
|
2015-12-21 23:10:17 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
TrackType FourCCToTrackType(FourCC fourcc) {
|
|
|
|
switch (fourcc) {
|
2016-04-06 23:21:45 +00:00
|
|
|
case FOURCC_vide:
|
2015-12-21 23:10:17 +00:00
|
|
|
return kVideo;
|
2016-04-06 23:21:45 +00:00
|
|
|
case FOURCC_soun:
|
2015-12-21 23:10:17 +00:00
|
|
|
return kAudio;
|
2016-04-06 23:21:45 +00:00
|
|
|
case FOURCC_text:
|
2015-12-21 23:10:17 +00:00
|
|
|
return kText;
|
|
|
|
default:
|
|
|
|
return kInvalid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FourCC TrackTypeToFourCC(TrackType track_type) {
|
|
|
|
switch (track_type) {
|
|
|
|
case kVideo:
|
2016-04-06 23:21:45 +00:00
|
|
|
return FOURCC_vide;
|
2015-12-21 23:10:17 +00:00
|
|
|
case kAudio:
|
2016-04-06 23:21:45 +00:00
|
|
|
return FOURCC_soun;
|
2015-12-21 23:10:17 +00:00
|
|
|
case kText:
|
2016-04-06 23:21:45 +00:00
|
|
|
return FOURCC_text;
|
2015-12-21 23:10:17 +00:00
|
|
|
default:
|
|
|
|
return FOURCC_NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-26 22:44:37 +00:00
|
|
|
bool IsProtectionSchemeSupported(FourCC scheme) {
|
|
|
|
return scheme == FOURCC_cenc || scheme == FOURCC_cens ||
|
|
|
|
scheme == FOURCC_cbc1 || scheme == FOURCC_cbcs;
|
|
|
|
}
|
|
|
|
|
2015-12-21 23:10:17 +00:00
|
|
|
} // namespace
|
|
|
|
|
2013-11-27 01:52:13 +00:00
|
|
|
FileType::FileType() : major_brand(FOURCC_NULL), minor_version(0) {}
|
2013-09-24 01:35:40 +00:00
|
|
|
FileType::~FileType() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC FileType::BoxType() const { return FOURCC_ftyp; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool FileType::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->ReadWriteFourCC(&major_brand) &&
|
|
|
|
buffer->ReadWriteUInt32(&minor_version));
|
|
|
|
size_t num_brands;
|
|
|
|
if (buffer->Reading()) {
|
2016-01-08 23:56:33 +00:00
|
|
|
RCHECK(buffer->BytesLeft() % sizeof(FourCC) == 0);
|
|
|
|
num_brands = buffer->BytesLeft() / sizeof(FourCC);
|
2013-11-27 01:52:13 +00:00
|
|
|
compatible_brands.resize(num_brands);
|
|
|
|
} else {
|
|
|
|
num_brands = compatible_brands.size();
|
|
|
|
}
|
|
|
|
for (size_t i = 0; i < num_brands; ++i)
|
|
|
|
RCHECK(buffer->ReadWriteFourCC(&compatible_brands[i]));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t FileType::ComputeSizeInternal() {
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + kFourCCSize + sizeof(minor_version) +
|
|
|
|
kFourCCSize * compatible_brands.size();
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC SegmentType::BoxType() const { return FOURCC_styp; }
|
2013-11-27 01:52:13 +00:00
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
ProtectionSystemSpecificHeader::ProtectionSystemSpecificHeader() {}
|
|
|
|
ProtectionSystemSpecificHeader::~ProtectionSystemSpecificHeader() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC ProtectionSystemSpecificHeader::BoxType() const { return FOURCC_pssh; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool ProtectionSystemSpecificHeader::ReadWriteInternal(BoxBuffer* buffer) {
|
2013-11-27 01:52:13 +00:00
|
|
|
if (buffer->Reading()) {
|
|
|
|
BoxReader* reader = buffer->reader();
|
|
|
|
DCHECK(reader);
|
|
|
|
raw_box.assign(reader->data(), reader->data() + reader->size());
|
2016-02-10 17:51:15 +00:00
|
|
|
} else {
|
|
|
|
DCHECK(!raw_box.empty());
|
|
|
|
buffer->writer()->AppendVector(raw_box);
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
2016-02-10 17:51:15 +00:00
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t ProtectionSystemSpecificHeader::ComputeSizeInternal() {
|
2016-02-10 17:51:15 +00:00
|
|
|
return raw_box.size();
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
SampleAuxiliaryInformationOffset::SampleAuxiliaryInformationOffset() {}
|
|
|
|
SampleAuxiliaryInformationOffset::~SampleAuxiliaryInformationOffset() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC SampleAuxiliaryInformationOffset::BoxType() const { return FOURCC_saio; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool SampleAuxiliaryInformationOffset::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
2013-11-27 01:52:13 +00:00
|
|
|
if (flags & 1)
|
|
|
|
RCHECK(buffer->IgnoreBytes(8)); // aux_info_type and parameter.
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
uint32_t count = static_cast<uint32_t>(offsets.size());
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt32(&count));
|
2013-09-24 01:35:40 +00:00
|
|
|
offsets.resize(count);
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
size_t num_bytes = (version == 1) ? sizeof(uint64_t) : sizeof(uint32_t);
|
|
|
|
for (uint32_t i = 0; i < count; ++i)
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt64NBytes(&offsets[i], num_bytes));
|
2013-09-24 01:35:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t SampleAuxiliaryInformationOffset::ComputeSizeInternal() {
|
2013-11-27 01:52:13 +00:00
|
|
|
// This box is optional. Skip it if it is empty.
|
2015-12-15 00:07:51 +00:00
|
|
|
if (offsets.size() == 0)
|
|
|
|
return 0;
|
|
|
|
size_t num_bytes = (version == 1) ? sizeof(uint64_t) : sizeof(uint32_t);
|
|
|
|
return HeaderSize() + sizeof(uint32_t) + num_bytes * offsets.size();
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
2013-11-27 01:52:13 +00:00
|
|
|
|
|
|
|
SampleAuxiliaryInformationSize::SampleAuxiliaryInformationSize()
|
|
|
|
: default_sample_info_size(0), sample_count(0) {}
|
2013-09-24 01:35:40 +00:00
|
|
|
SampleAuxiliaryInformationSize::~SampleAuxiliaryInformationSize() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC SampleAuxiliaryInformationSize::BoxType() const { return FOURCC_saiz; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool SampleAuxiliaryInformationSize::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
2013-11-27 01:52:13 +00:00
|
|
|
if (flags & 1)
|
|
|
|
RCHECK(buffer->IgnoreBytes(8));
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt8(&default_sample_info_size) &&
|
|
|
|
buffer->ReadWriteUInt32(&sample_count));
|
2013-09-24 01:35:40 +00:00
|
|
|
if (default_sample_info_size == 0)
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->ReadWriteVector(&sample_info_sizes, sample_count));
|
2013-09-24 01:35:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t SampleAuxiliaryInformationSize::ComputeSizeInternal() {
|
2013-11-27 01:52:13 +00:00
|
|
|
// This box is optional. Skip it if it is empty.
|
2015-12-15 00:07:51 +00:00
|
|
|
if (sample_count == 0)
|
|
|
|
return 0;
|
|
|
|
return HeaderSize() + sizeof(default_sample_info_size) +
|
|
|
|
sizeof(sample_count) +
|
|
|
|
(default_sample_info_size == 0 ? sample_info_sizes.size() : 0);
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2015-12-21 18:34:21 +00:00
|
|
|
SampleEncryptionEntry::SampleEncryptionEntry() {}
|
|
|
|
SampleEncryptionEntry::~SampleEncryptionEntry() {}
|
|
|
|
|
|
|
|
bool SampleEncryptionEntry::ReadWrite(uint8_t iv_size,
|
|
|
|
bool has_subsamples,
|
|
|
|
BoxBuffer* buffer) {
|
|
|
|
DCHECK(IsIvSizeValid(iv_size));
|
|
|
|
DCHECK(buffer);
|
|
|
|
|
|
|
|
RCHECK(buffer->ReadWriteVector(&initialization_vector, iv_size));
|
|
|
|
|
|
|
|
if (!has_subsamples) {
|
|
|
|
subsamples.clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-14 22:28:21 +00:00
|
|
|
uint16_t subsample_count = static_cast<uint16_t>(subsamples.size());
|
2015-12-21 18:34:21 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt16(&subsample_count));
|
|
|
|
RCHECK(subsample_count > 0);
|
|
|
|
subsamples.resize(subsample_count);
|
|
|
|
for (auto& subsample : subsamples) {
|
|
|
|
RCHECK(buffer->ReadWriteUInt16(&subsample.clear_bytes) &&
|
|
|
|
buffer->ReadWriteUInt32(&subsample.cipher_bytes));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SampleEncryptionEntry::ParseFromBuffer(uint8_t iv_size,
|
|
|
|
bool has_subsamples,
|
|
|
|
BufferReader* reader) {
|
|
|
|
DCHECK(IsIvSizeValid(iv_size));
|
|
|
|
DCHECK(reader);
|
|
|
|
|
|
|
|
initialization_vector.resize(iv_size);
|
|
|
|
RCHECK(reader->ReadToVector(&initialization_vector, iv_size));
|
|
|
|
|
|
|
|
if (!has_subsamples) {
|
|
|
|
subsamples.clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t subsample_count;
|
|
|
|
RCHECK(reader->Read2(&subsample_count));
|
|
|
|
RCHECK(subsample_count > 0);
|
|
|
|
subsamples.resize(subsample_count);
|
|
|
|
for (auto& subsample : subsamples) {
|
|
|
|
RCHECK(reader->Read2(&subsample.clear_bytes) &&
|
|
|
|
reader->Read4(&subsample.cipher_bytes));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t SampleEncryptionEntry::ComputeSize() const {
|
|
|
|
const uint32_t subsample_entry_size = sizeof(uint16_t) + sizeof(uint32_t);
|
2016-08-14 22:28:21 +00:00
|
|
|
const uint16_t subsample_count = static_cast<uint16_t>(subsamples.size());
|
2016-11-09 02:11:13 +00:00
|
|
|
return static_cast<uint32_t>(
|
|
|
|
initialization_vector.size() +
|
|
|
|
(subsample_count > 0
|
|
|
|
? (sizeof(subsample_count) + subsample_entry_size * subsample_count)
|
|
|
|
: 0));
|
2015-12-21 18:34:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t SampleEncryptionEntry::GetTotalSizeOfSubsamples() const {
|
|
|
|
uint32_t size = 0;
|
|
|
|
for (uint32_t i = 0; i < subsamples.size(); ++i)
|
|
|
|
size += subsamples[i].clear_bytes + subsamples[i].cipher_bytes;
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2016-04-12 22:39:10 +00:00
|
|
|
SampleEncryption::SampleEncryption() : iv_size(kInvalidIvSize) {}
|
2015-12-21 18:34:21 +00:00
|
|
|
SampleEncryption::~SampleEncryption() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC SampleEncryption::BoxType() const { return FOURCC_senc; }
|
2015-12-21 18:34:21 +00:00
|
|
|
|
|
|
|
bool SampleEncryption::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
|
|
|
|
|
|
|
// If we don't know |iv_size|, store sample encryption data to parse later
|
|
|
|
// after we know iv_size.
|
2016-04-12 22:39:10 +00:00
|
|
|
if (buffer->Reading() && iv_size == kInvalidIvSize) {
|
2016-01-08 23:56:33 +00:00
|
|
|
RCHECK(
|
|
|
|
buffer->ReadWriteVector(&sample_encryption_data, buffer->BytesLeft()));
|
2015-12-21 18:34:21 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!IsIvSizeValid(iv_size)) {
|
2016-04-12 22:39:10 +00:00
|
|
|
LOG(ERROR)
|
|
|
|
<< "IV_size can only be 8 or 16 or 0 for constant iv, but seeing "
|
|
|
|
<< iv_size;
|
2015-12-21 18:34:21 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
uint32_t sample_count =
|
|
|
|
static_cast<uint32_t>(sample_encryption_entries.size());
|
2015-12-21 18:34:21 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt32(&sample_count));
|
|
|
|
|
|
|
|
sample_encryption_entries.resize(sample_count);
|
|
|
|
for (auto& sample_encryption_entry : sample_encryption_entries) {
|
|
|
|
RCHECK(sample_encryption_entry.ReadWrite(
|
2016-08-14 22:28:21 +00:00
|
|
|
iv_size, (flags & kUseSubsampleEncryption) != 0, buffer) != 0);
|
2015-12-21 18:34:21 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t SampleEncryption::ComputeSizeInternal() {
|
|
|
|
const uint32_t sample_count =
|
|
|
|
static_cast<uint32_t>(sample_encryption_entries.size());
|
2015-12-21 18:34:21 +00:00
|
|
|
if (sample_count == 0) {
|
|
|
|
// Sample encryption box is optional. Skip it if it is empty.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DCHECK(IsIvSizeValid(iv_size));
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t box_size = HeaderSize() + sizeof(sample_count);
|
2015-12-21 18:34:21 +00:00
|
|
|
if (flags & kUseSubsampleEncryption) {
|
|
|
|
for (const SampleEncryptionEntry& sample_encryption_entry :
|
|
|
|
sample_encryption_entries) {
|
|
|
|
box_size += sample_encryption_entry.ComputeSize();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
box_size += sample_count * iv_size;
|
|
|
|
}
|
|
|
|
return box_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SampleEncryption::ParseFromSampleEncryptionData(
|
2016-08-14 22:28:21 +00:00
|
|
|
uint8_t iv_size,
|
2015-12-21 18:34:21 +00:00
|
|
|
std::vector<SampleEncryptionEntry>* sample_encryption_entries) const {
|
|
|
|
DCHECK(IsIvSizeValid(iv_size));
|
|
|
|
|
2016-01-29 21:23:12 +00:00
|
|
|
BufferReader reader(sample_encryption_data.data(),
|
2015-12-21 18:34:21 +00:00
|
|
|
sample_encryption_data.size());
|
|
|
|
uint32_t sample_count = 0;
|
|
|
|
RCHECK(reader.Read4(&sample_count));
|
|
|
|
|
|
|
|
sample_encryption_entries->resize(sample_count);
|
|
|
|
for (auto& sample_encryption_entry : *sample_encryption_entries) {
|
|
|
|
RCHECK(sample_encryption_entry.ParseFromBuffer(
|
2016-08-14 22:28:21 +00:00
|
|
|
iv_size, (flags & kUseSubsampleEncryption) != 0, &reader) != 0);
|
2015-12-21 18:34:21 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
OriginalFormat::OriginalFormat() : format(FOURCC_NULL) {}
|
|
|
|
OriginalFormat::~OriginalFormat() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC OriginalFormat::BoxType() const { return FOURCC_frma; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool OriginalFormat::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
return ReadWriteHeaderInternal(buffer) && buffer->ReadWriteFourCC(&format);
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t OriginalFormat::ComputeSizeInternal() {
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + kFourCCSize;
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SchemeType::SchemeType() : type(FOURCC_NULL), version(0) {}
|
|
|
|
SchemeType::~SchemeType() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC SchemeType::BoxType() const { return FOURCC_schm; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool SchemeType::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->ReadWriteFourCC(&type) &&
|
|
|
|
buffer->ReadWriteUInt32(&version));
|
2013-09-24 01:35:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t SchemeType::ComputeSizeInternal() {
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + kFourCCSize + sizeof(version);
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
2013-11-27 01:52:13 +00:00
|
|
|
|
|
|
|
TrackEncryption::TrackEncryption()
|
2016-04-12 22:39:10 +00:00
|
|
|
: default_is_protected(0),
|
|
|
|
default_per_sample_iv_size(0),
|
|
|
|
default_kid(16, 0),
|
|
|
|
default_crypt_byte_block(0),
|
|
|
|
default_skip_byte_block(0) {}
|
2013-09-24 01:35:40 +00:00
|
|
|
TrackEncryption::~TrackEncryption() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC TrackEncryption::BoxType() const { return FOURCC_tenc; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool TrackEncryption::ReadWriteInternal(BoxBuffer* buffer) {
|
2014-10-15 21:56:12 +00:00
|
|
|
if (!buffer->Reading()) {
|
|
|
|
if (default_kid.size() != kCencKeyIdSize) {
|
|
|
|
LOG(WARNING) << "CENC defines key id length of " << kCencKeyIdSize
|
|
|
|
<< " bytes; got " << default_kid.size()
|
|
|
|
<< ". Resized accordingly.";
|
|
|
|
default_kid.resize(kCencKeyIdSize);
|
|
|
|
}
|
2016-04-12 22:39:10 +00:00
|
|
|
RCHECK(default_crypt_byte_block < 16 && default_skip_byte_block < 16);
|
|
|
|
if (default_crypt_byte_block != 0 && default_skip_byte_block != 0) {
|
|
|
|
// Version 1 box is needed for pattern-based encryption.
|
|
|
|
version = 1;
|
|
|
|
}
|
2014-10-15 21:56:12 +00:00
|
|
|
}
|
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2016-04-12 22:39:10 +00:00
|
|
|
buffer->IgnoreBytes(1)); // reserved.
|
|
|
|
|
|
|
|
uint8_t pattern = default_crypt_byte_block << 4 | default_skip_byte_block;
|
|
|
|
RCHECK(buffer->ReadWriteUInt8(&pattern));
|
|
|
|
default_crypt_byte_block = pattern >> 4;
|
|
|
|
default_skip_byte_block = pattern & 0x0F;
|
|
|
|
|
|
|
|
RCHECK(buffer->ReadWriteUInt8(&default_is_protected) &&
|
|
|
|
buffer->ReadWriteUInt8(&default_per_sample_iv_size) &&
|
2014-10-15 21:56:12 +00:00
|
|
|
buffer->ReadWriteVector(&default_kid, kCencKeyIdSize));
|
2016-04-12 22:39:10 +00:00
|
|
|
|
|
|
|
if (default_is_protected == 1) {
|
|
|
|
if (default_per_sample_iv_size == 0) { // For constant iv.
|
2016-08-14 22:28:21 +00:00
|
|
|
uint8_t default_constant_iv_size =
|
|
|
|
static_cast<uint8_t>(default_constant_iv.size());
|
2016-04-12 22:39:10 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt8(&default_constant_iv_size));
|
|
|
|
RCHECK(default_constant_iv_size == 8 || default_constant_iv_size == 16);
|
|
|
|
RCHECK(buffer->ReadWriteVector(&default_constant_iv,
|
|
|
|
default_constant_iv_size));
|
2013-11-27 01:52:13 +00:00
|
|
|
} else {
|
2016-04-12 22:39:10 +00:00
|
|
|
RCHECK(default_per_sample_iv_size == 8 ||
|
|
|
|
default_per_sample_iv_size == 16);
|
|
|
|
RCHECK(default_constant_iv.empty());
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
2016-04-12 22:39:10 +00:00
|
|
|
} else {
|
|
|
|
// Expect |default_is_protected| to be 0, i.e. not protected. Other values
|
|
|
|
// of |default_is_protected| is not supported.
|
|
|
|
RCHECK(default_is_protected == 0);
|
|
|
|
RCHECK(default_per_sample_iv_size == 0);
|
2016-04-21 23:28:21 +00:00
|
|
|
RCHECK(default_constant_iv.empty());
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t TrackEncryption::ComputeSizeInternal() {
|
2016-04-12 22:39:10 +00:00
|
|
|
return HeaderSize() + sizeof(uint32_t) + kCencKeyIdSize +
|
|
|
|
(default_constant_iv.empty() ? 0 : (sizeof(uint8_t) +
|
|
|
|
default_constant_iv.size()));
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
SchemeInfo::SchemeInfo() {}
|
|
|
|
SchemeInfo::~SchemeInfo() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC SchemeInfo::BoxType() const { return FOURCC_schi; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool SchemeInfo::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) && buffer->PrepareChildren() &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->ReadWriteChild(&track_encryption));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t SchemeInfo::ComputeSizeInternal() {
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + track_encryption.ComputeSize();
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ProtectionSchemeInfo::ProtectionSchemeInfo() {}
|
|
|
|
ProtectionSchemeInfo::~ProtectionSchemeInfo() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC ProtectionSchemeInfo::BoxType() const { return FOURCC_sinf; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool ProtectionSchemeInfo::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->PrepareChildren() &&
|
|
|
|
buffer->ReadWriteChild(&format) &&
|
|
|
|
buffer->ReadWriteChild(&type));
|
2016-05-26 22:44:37 +00:00
|
|
|
if (IsProtectionSchemeSupported(type.type)) {
|
|
|
|
RCHECK(buffer->ReadWriteChild(&info));
|
|
|
|
} else {
|
|
|
|
DLOG(WARNING) << "Ignore unsupported protection scheme: "
|
|
|
|
<< FourCCToString(type.type);
|
|
|
|
}
|
2013-09-24 01:35:40 +00:00
|
|
|
// Other protection schemes are silently ignored. Since the protection scheme
|
|
|
|
// type can't be determined until this box is opened, we return 'true' for
|
|
|
|
// non-CENC protection scheme types. It is the parent box's responsibility to
|
|
|
|
// ensure that this scheme type is a supported one.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t ProtectionSchemeInfo::ComputeSizeInternal() {
|
2013-11-27 01:52:13 +00:00
|
|
|
// Skip sinf box if it is not initialized.
|
2015-12-15 00:07:51 +00:00
|
|
|
if (format.format == FOURCC_NULL)
|
|
|
|
return 0;
|
|
|
|
return HeaderSize() + format.ComputeSize() + type.ComputeSize() +
|
|
|
|
info.ComputeSize();
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
MovieHeader::MovieHeader()
|
|
|
|
: creation_time(0),
|
|
|
|
modification_time(0),
|
|
|
|
timescale(0),
|
|
|
|
duration(0),
|
2013-11-27 01:52:13 +00:00
|
|
|
rate(1 << 16),
|
|
|
|
volume(1 << 8),
|
2013-09-24 01:35:40 +00:00
|
|
|
next_track_id(0) {}
|
|
|
|
MovieHeader::~MovieHeader() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC MovieHeader::BoxType() const { return FOURCC_mvhd; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool MovieHeader::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
2013-11-27 01:52:13 +00:00
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
size_t num_bytes = (version == 1) ? sizeof(uint64_t) : sizeof(uint32_t);
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt64NBytes(&creation_time, num_bytes) &&
|
|
|
|
buffer->ReadWriteUInt64NBytes(&modification_time, num_bytes) &&
|
|
|
|
buffer->ReadWriteUInt32(×cale) &&
|
|
|
|
buffer->ReadWriteUInt64NBytes(&duration, num_bytes));
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
std::vector<uint8_t> matrix(kUnityMatrix,
|
|
|
|
kUnityMatrix + arraysize(kUnityMatrix));
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->ReadWriteInt32(&rate) &&
|
|
|
|
buffer->ReadWriteInt16(&volume) &&
|
|
|
|
buffer->IgnoreBytes(10) && // reserved
|
|
|
|
buffer->ReadWriteVector(&matrix, matrix.size()) &&
|
|
|
|
buffer->IgnoreBytes(24) && // predefined zero
|
|
|
|
buffer->ReadWriteUInt32(&next_track_id));
|
2013-09-24 01:35:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t MovieHeader::ComputeSizeInternal() {
|
2013-11-27 01:52:13 +00:00
|
|
|
version = IsFitIn32Bits(creation_time, modification_time, duration) ? 0 : 1;
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + sizeof(uint32_t) * (1 + version) * 3 +
|
|
|
|
sizeof(timescale) + sizeof(rate) + sizeof(volume) +
|
|
|
|
sizeof(next_track_id) + sizeof(kUnityMatrix) + 10 +
|
|
|
|
24; // 10 bytes reserved, 24 bytes predefined.
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
TrackHeader::TrackHeader()
|
|
|
|
: creation_time(0),
|
|
|
|
modification_time(0),
|
|
|
|
track_id(0),
|
|
|
|
duration(0),
|
2013-11-27 01:52:13 +00:00
|
|
|
layer(0),
|
|
|
|
alternate_group(0),
|
2013-09-24 01:35:40 +00:00
|
|
|
volume(-1),
|
|
|
|
width(0),
|
2013-11-27 01:52:13 +00:00
|
|
|
height(0) {
|
2017-03-15 19:42:00 +00:00
|
|
|
flags = kTrackEnabled | kTrackInMovie | kTrackInPreview;
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
2013-09-24 01:35:40 +00:00
|
|
|
TrackHeader::~TrackHeader() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC TrackHeader::BoxType() const { return FOURCC_tkhd; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool TrackHeader::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
2013-11-27 01:52:13 +00:00
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
size_t num_bytes = (version == 1) ? sizeof(uint64_t) : sizeof(uint32_t);
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt64NBytes(&creation_time, num_bytes) &&
|
|
|
|
buffer->ReadWriteUInt64NBytes(&modification_time, num_bytes) &&
|
|
|
|
buffer->ReadWriteUInt32(&track_id) &&
|
|
|
|
buffer->IgnoreBytes(4) && // reserved
|
|
|
|
buffer->ReadWriteUInt64NBytes(&duration, num_bytes));
|
|
|
|
|
|
|
|
if (!buffer->Reading()) {
|
|
|
|
// Set default value for volume, if track is audio, 0x100 else 0.
|
|
|
|
if (volume == -1)
|
|
|
|
volume = (width != 0 && height != 0) ? 0 : 0x100;
|
|
|
|
}
|
2014-09-30 21:52:21 +00:00
|
|
|
std::vector<uint8_t> matrix(kUnityMatrix,
|
|
|
|
kUnityMatrix + arraysize(kUnityMatrix));
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->IgnoreBytes(8) && // reserved
|
|
|
|
buffer->ReadWriteInt16(&layer) &&
|
|
|
|
buffer->ReadWriteInt16(&alternate_group) &&
|
|
|
|
buffer->ReadWriteInt16(&volume) &&
|
|
|
|
buffer->IgnoreBytes(2) && // reserved
|
|
|
|
buffer->ReadWriteVector(&matrix, matrix.size()) &&
|
|
|
|
buffer->ReadWriteUInt32(&width) &&
|
|
|
|
buffer->ReadWriteUInt32(&height));
|
2013-09-24 01:35:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t TrackHeader::ComputeSizeInternal() {
|
2013-11-27 01:52:13 +00:00
|
|
|
version = IsFitIn32Bits(creation_time, modification_time, duration) ? 0 : 1;
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + sizeof(track_id) +
|
|
|
|
sizeof(uint32_t) * (1 + version) * 3 + sizeof(layer) +
|
|
|
|
sizeof(alternate_group) + sizeof(volume) + sizeof(width) +
|
|
|
|
sizeof(height) + sizeof(kUnityMatrix) + 14; // 14 bytes reserved.
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
SampleDescription::SampleDescription() : type(kInvalid) {}
|
|
|
|
SampleDescription::~SampleDescription() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC SampleDescription::BoxType() const { return FOURCC_stsd; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool SampleDescription::ReadWriteInternal(BoxBuffer* buffer) {
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t count = 0;
|
2015-11-23 23:12:04 +00:00
|
|
|
switch (type) {
|
|
|
|
case kVideo:
|
2016-11-09 02:11:13 +00:00
|
|
|
count = static_cast<uint32_t>(video_entries.size());
|
2015-11-23 23:12:04 +00:00
|
|
|
break;
|
|
|
|
case kAudio:
|
2016-11-09 02:11:13 +00:00
|
|
|
count = static_cast<uint32_t>(audio_entries.size());
|
2015-11-23 23:12:04 +00:00
|
|
|
break;
|
|
|
|
case kText:
|
2016-11-09 02:11:13 +00:00
|
|
|
count = static_cast<uint32_t>(text_entries.size());
|
2015-11-23 23:12:04 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NOTIMPLEMENTED() << "SampleDecryption type " << type
|
|
|
|
<< " is not handled. Skipping.";
|
|
|
|
}
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->ReadWriteUInt32(&count));
|
|
|
|
|
|
|
|
if (buffer->Reading()) {
|
|
|
|
BoxReader* reader = buffer->reader();
|
|
|
|
DCHECK(reader);
|
|
|
|
video_entries.clear();
|
|
|
|
audio_entries.clear();
|
|
|
|
// Note: this value is preset before scanning begins. See comments in the
|
|
|
|
// Parse(Media*) function.
|
|
|
|
if (type == kVideo) {
|
|
|
|
RCHECK(reader->ReadAllChildren(&video_entries));
|
|
|
|
RCHECK(video_entries.size() == count);
|
|
|
|
} else if (type == kAudio) {
|
|
|
|
RCHECK(reader->ReadAllChildren(&audio_entries));
|
|
|
|
RCHECK(audio_entries.size() == count);
|
2015-11-23 23:12:04 +00:00
|
|
|
} else if (type == kText) {
|
2016-02-03 23:58:35 +00:00
|
|
|
RCHECK(reader->ReadAllChildren(&text_entries));
|
|
|
|
RCHECK(text_entries.size() == count);
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
} else {
|
2014-03-21 17:26:49 +00:00
|
|
|
DCHECK_LT(0u, count);
|
2013-11-27 01:52:13 +00:00
|
|
|
if (type == kVideo) {
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < count; ++i)
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(buffer->ReadWriteChild(&video_entries[i]));
|
2013-11-27 01:52:13 +00:00
|
|
|
} else if (type == kAudio) {
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < count; ++i)
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(buffer->ReadWriteChild(&audio_entries[i]));
|
2015-11-23 23:12:04 +00:00
|
|
|
} else if (type == kText) {
|
|
|
|
for (uint32_t i = 0; i < count; ++i)
|
2016-02-03 23:58:35 +00:00
|
|
|
RCHECK(buffer->ReadWriteChild(&text_entries[i]));
|
2013-11-27 01:52:13 +00:00
|
|
|
} else {
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t SampleDescription::ComputeSizeInternal() {
|
|
|
|
size_t box_size = HeaderSize() + sizeof(uint32_t);
|
2013-09-24 01:35:40 +00:00
|
|
|
if (type == kVideo) {
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < video_entries.size(); ++i)
|
2015-12-15 00:07:51 +00:00
|
|
|
box_size += video_entries[i].ComputeSize();
|
2013-09-24 01:35:40 +00:00
|
|
|
} else if (type == kAudio) {
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < audio_entries.size(); ++i)
|
2015-12-15 00:07:51 +00:00
|
|
|
box_size += audio_entries[i].ComputeSize();
|
2016-02-03 23:58:35 +00:00
|
|
|
} else if (type == kText) {
|
|
|
|
for (uint32_t i = 0; i < text_entries.size(); ++i)
|
|
|
|
box_size += text_entries[i].ComputeSize();
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
2015-12-15 00:07:51 +00:00
|
|
|
return box_size;
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
|
2013-10-08 17:37:58 +00:00
|
|
|
DecodingTimeToSample::DecodingTimeToSample() {}
|
|
|
|
DecodingTimeToSample::~DecodingTimeToSample() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC DecodingTimeToSample::BoxType() const { return FOURCC_stts; }
|
2013-10-08 17:37:58 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool DecodingTimeToSample::ReadWriteInternal(BoxBuffer* buffer) {
|
2016-11-09 02:11:13 +00:00
|
|
|
uint32_t count = static_cast<uint32_t>(decoding_time.size());
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->ReadWriteUInt32(&count));
|
2013-10-08 17:37:58 +00:00
|
|
|
|
|
|
|
decoding_time.resize(count);
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt32(&decoding_time[i].sample_count) &&
|
|
|
|
buffer->ReadWriteUInt32(&decoding_time[i].sample_delta));
|
2013-10-08 17:37:58 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t DecodingTimeToSample::ComputeSizeInternal() {
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + sizeof(uint32_t) +
|
|
|
|
sizeof(DecodingTime) * decoding_time.size();
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2013-10-08 17:37:58 +00:00
|
|
|
CompositionTimeToSample::CompositionTimeToSample() {}
|
|
|
|
CompositionTimeToSample::~CompositionTimeToSample() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC CompositionTimeToSample::BoxType() const { return FOURCC_ctts; }
|
2013-10-08 17:37:58 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool CompositionTimeToSample::ReadWriteInternal(BoxBuffer* buffer) {
|
2016-11-09 02:11:13 +00:00
|
|
|
uint32_t count = static_cast<uint32_t>(composition_offset.size());
|
2015-08-04 21:11:15 +00:00
|
|
|
if (!buffer->Reading()) {
|
|
|
|
// Determine whether version 0 or version 1 should be used.
|
|
|
|
// Use version 0 if possible, use version 1 if there is a negative
|
|
|
|
// sample_offset value.
|
|
|
|
version = 0;
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
|
|
|
if (composition_offset[i].sample_offset < 0) {
|
|
|
|
version = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->ReadWriteUInt32(&count));
|
2013-10-08 17:37:58 +00:00
|
|
|
|
|
|
|
composition_offset.resize(count);
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2015-08-04 21:11:15 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt32(&composition_offset[i].sample_count));
|
|
|
|
|
|
|
|
if (version == 0) {
|
|
|
|
uint32_t sample_offset = composition_offset[i].sample_offset;
|
|
|
|
RCHECK(buffer->ReadWriteUInt32(&sample_offset));
|
|
|
|
composition_offset[i].sample_offset = sample_offset;
|
|
|
|
} else {
|
|
|
|
int32_t sample_offset = composition_offset[i].sample_offset;
|
|
|
|
RCHECK(buffer->ReadWriteInt32(&sample_offset));
|
|
|
|
composition_offset[i].sample_offset = sample_offset;
|
|
|
|
}
|
2013-10-08 17:37:58 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t CompositionTimeToSample::ComputeSizeInternal() {
|
2013-11-27 01:52:13 +00:00
|
|
|
// This box is optional. Skip it if it is empty.
|
2015-12-15 00:07:51 +00:00
|
|
|
if (composition_offset.empty())
|
|
|
|
return 0;
|
|
|
|
// Structure CompositionOffset contains |sample_offset| (uint32_t) and
|
|
|
|
// |sample_offset| (int64_t). The actual size of |sample_offset| is
|
|
|
|
// 4 bytes (uint32_t for version 0 and int32_t for version 1).
|
2016-11-09 02:11:13 +00:00
|
|
|
const size_t kCompositionOffsetSize = sizeof(uint32_t) * 2;
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + sizeof(uint32_t) +
|
|
|
|
kCompositionOffsetSize * composition_offset.size();
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2013-10-08 17:37:58 +00:00
|
|
|
SampleToChunk::SampleToChunk() {}
|
|
|
|
SampleToChunk::~SampleToChunk() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC SampleToChunk::BoxType() const { return FOURCC_stsc; }
|
2013-10-08 17:37:58 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool SampleToChunk::ReadWriteInternal(BoxBuffer* buffer) {
|
2016-11-09 02:11:13 +00:00
|
|
|
uint32_t count = static_cast<uint32_t>(chunk_info.size());
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->ReadWriteUInt32(&count));
|
2013-10-08 17:37:58 +00:00
|
|
|
|
|
|
|
chunk_info.resize(count);
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt32(&chunk_info[i].first_chunk) &&
|
|
|
|
buffer->ReadWriteUInt32(&chunk_info[i].samples_per_chunk) &&
|
|
|
|
buffer->ReadWriteUInt32(&chunk_info[i].sample_description_index));
|
2013-10-08 17:37:58 +00:00
|
|
|
// first_chunk values are always increasing.
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(i == 0 ? chunk_info[i].first_chunk == 1
|
2013-10-08 17:37:58 +00:00
|
|
|
: chunk_info[i].first_chunk > chunk_info[i - 1].first_chunk);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t SampleToChunk::ComputeSizeInternal() {
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + sizeof(uint32_t) +
|
|
|
|
sizeof(ChunkInfo) * chunk_info.size();
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2013-10-08 17:37:58 +00:00
|
|
|
SampleSize::SampleSize() : sample_size(0), sample_count(0) {}
|
|
|
|
SampleSize::~SampleSize() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC SampleSize::BoxType() const { return FOURCC_stsz; }
|
2013-10-08 17:37:58 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool SampleSize::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->ReadWriteUInt32(&sample_size) &&
|
|
|
|
buffer->ReadWriteUInt32(&sample_count));
|
2013-10-08 17:37:58 +00:00
|
|
|
|
|
|
|
if (sample_size == 0) {
|
2013-11-27 01:52:13 +00:00
|
|
|
if (buffer->Reading())
|
|
|
|
sizes.resize(sample_count);
|
|
|
|
else
|
|
|
|
DCHECK(sample_count == sizes.size());
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < sample_count; ++i)
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt32(&sizes[i]));
|
2013-10-08 17:37:58 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t SampleSize::ComputeSizeInternal() {
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + sizeof(sample_size) + sizeof(sample_count) +
|
|
|
|
(sample_size == 0 ? sizeof(uint32_t) * sizes.size() : 0);
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CompactSampleSize::CompactSampleSize() : field_size(0) {}
|
2013-10-08 17:37:58 +00:00
|
|
|
CompactSampleSize::~CompactSampleSize() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC CompactSampleSize::BoxType() const { return FOURCC_stz2; }
|
2013-10-08 17:37:58 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool CompactSampleSize::ReadWriteInternal(BoxBuffer* buffer) {
|
2016-11-09 02:11:13 +00:00
|
|
|
uint32_t sample_count = static_cast<uint32_t>(sizes.size());
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->IgnoreBytes(3) &&
|
|
|
|
buffer->ReadWriteUInt8(&field_size) &&
|
|
|
|
buffer->ReadWriteUInt32(&sample_count));
|
2013-10-08 17:37:58 +00:00
|
|
|
|
|
|
|
// Reserve one more entry if field size is 4 bits.
|
2014-01-16 00:52:07 +00:00
|
|
|
sizes.resize(sample_count + (field_size == 4 ? 1 : 0), 0);
|
2013-10-08 17:37:58 +00:00
|
|
|
switch (field_size) {
|
|
|
|
case 4:
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < sample_count; i += 2) {
|
2013-11-27 01:52:13 +00:00
|
|
|
if (buffer->Reading()) {
|
2014-09-30 21:52:21 +00:00
|
|
|
uint8_t size = 0;
|
2014-01-16 00:52:07 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt8(&size));
|
2013-11-27 01:52:13 +00:00
|
|
|
sizes[i] = size >> 4;
|
2014-01-16 00:52:07 +00:00
|
|
|
sizes[i + 1] = size & 0x0F;
|
|
|
|
} else {
|
2014-03-21 17:26:49 +00:00
|
|
|
DCHECK_LT(sizes[i], 16u);
|
|
|
|
DCHECK_LT(sizes[i + 1], 16u);
|
2014-09-30 21:52:21 +00:00
|
|
|
uint8_t size = (sizes[i] << 4) | sizes[i + 1];
|
2014-01-16 00:52:07 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt8(&size));
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
2013-10-08 17:37:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 8:
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < sample_count; ++i) {
|
|
|
|
uint8_t size = sizes[i];
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt8(&size));
|
2013-10-08 17:37:58 +00:00
|
|
|
sizes[i] = size;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 16:
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < sample_count; ++i) {
|
|
|
|
uint16_t size = sizes[i];
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt16(&size));
|
2013-10-08 17:37:58 +00:00
|
|
|
sizes[i] = size;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
RCHECK(false);
|
|
|
|
}
|
|
|
|
sizes.resize(sample_count);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t CompactSampleSize::ComputeSizeInternal() {
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + sizeof(uint32_t) + sizeof(uint32_t) +
|
|
|
|
(field_size * sizes.size() + 7) / 8;
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2013-10-08 17:37:58 +00:00
|
|
|
ChunkOffset::ChunkOffset() {}
|
|
|
|
ChunkOffset::~ChunkOffset() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC ChunkOffset::BoxType() const { return FOURCC_stco; }
|
2013-10-08 17:37:58 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool ChunkOffset::ReadWriteInternal(BoxBuffer* buffer) {
|
2016-11-09 02:11:13 +00:00
|
|
|
uint32_t count = static_cast<uint32_t>(offsets.size());
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->ReadWriteUInt32(&count));
|
2013-10-08 17:37:58 +00:00
|
|
|
|
|
|
|
offsets.resize(count);
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < count; ++i)
|
|
|
|
RCHECK(buffer->ReadWriteUInt64NBytes(&offsets[i], sizeof(uint32_t)));
|
2013-10-08 17:37:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t ChunkOffset::ComputeSizeInternal() {
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + sizeof(uint32_t) + sizeof(uint32_t) * offsets.size();
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2013-10-08 17:37:58 +00:00
|
|
|
ChunkLargeOffset::ChunkLargeOffset() {}
|
|
|
|
ChunkLargeOffset::~ChunkLargeOffset() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC ChunkLargeOffset::BoxType() const { return FOURCC_co64; }
|
2013-10-08 17:37:58 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool ChunkLargeOffset::ReadWriteInternal(BoxBuffer* buffer) {
|
2016-11-09 02:11:13 +00:00
|
|
|
uint32_t count = static_cast<uint32_t>(offsets.size());
|
2013-11-27 01:52:13 +00:00
|
|
|
|
|
|
|
if (!buffer->Reading()) {
|
|
|
|
// Switch to ChunkOffset box if it is able to fit in 32 bits offset.
|
|
|
|
if (count == 0 || IsFitIn32Bits(offsets[count - 1])) {
|
|
|
|
ChunkOffset stco;
|
|
|
|
stco.offsets.swap(offsets);
|
|
|
|
DCHECK(buffer->writer());
|
|
|
|
stco.Write(buffer->writer());
|
|
|
|
stco.offsets.swap(offsets);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->ReadWriteUInt32(&count));
|
2013-10-08 17:37:58 +00:00
|
|
|
|
|
|
|
offsets.resize(count);
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < count; ++i)
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt64(&offsets[i]));
|
2013-10-08 17:37:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t ChunkLargeOffset::ComputeSizeInternal() {
|
|
|
|
uint32_t count = static_cast<uint32_t>(offsets.size());
|
2013-11-27 01:52:13 +00:00
|
|
|
int use_large_offset =
|
|
|
|
(count > 0 && !IsFitIn32Bits(offsets[count - 1])) ? 1 : 0;
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + sizeof(count) +
|
|
|
|
sizeof(uint32_t) * (1 + use_large_offset) * offsets.size();
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2013-10-08 17:37:58 +00:00
|
|
|
SyncSample::SyncSample() {}
|
|
|
|
SyncSample::~SyncSample() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC SyncSample::BoxType() const { return FOURCC_stss; }
|
2013-10-08 17:37:58 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool SyncSample::ReadWriteInternal(BoxBuffer* buffer) {
|
2016-11-09 02:11:13 +00:00
|
|
|
uint32_t count = static_cast<uint32_t>(sample_number.size());
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->ReadWriteUInt32(&count));
|
2013-10-08 17:37:58 +00:00
|
|
|
|
|
|
|
sample_number.resize(count);
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < count; ++i)
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt32(&sample_number[i]));
|
2013-10-08 17:37:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t SyncSample::ComputeSizeInternal() {
|
2013-11-27 01:52:13 +00:00
|
|
|
// Sync sample box is optional. Skip it if it is empty.
|
2015-12-15 00:07:51 +00:00
|
|
|
if (sample_number.empty())
|
|
|
|
return 0;
|
|
|
|
return HeaderSize() + sizeof(uint32_t) +
|
|
|
|
sizeof(uint32_t) * sample_number.size();
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2016-05-06 23:56:50 +00:00
|
|
|
CencSampleEncryptionInfoEntry::CencSampleEncryptionInfoEntry()
|
|
|
|
: is_protected(0),
|
|
|
|
per_sample_iv_size(0),
|
|
|
|
crypt_byte_block(0),
|
|
|
|
skip_byte_block(0) {}
|
|
|
|
CencSampleEncryptionInfoEntry::~CencSampleEncryptionInfoEntry() {};
|
|
|
|
|
|
|
|
bool CencSampleEncryptionInfoEntry::ReadWrite(BoxBuffer* buffer) {
|
|
|
|
if (!buffer->Reading()) {
|
|
|
|
if (key_id.size() != kCencKeyIdSize) {
|
|
|
|
LOG(WARNING) << "CENC defines key id length of " << kCencKeyIdSize
|
|
|
|
<< " bytes; got " << key_id.size()
|
|
|
|
<< ". Resized accordingly.";
|
|
|
|
key_id.resize(kCencKeyIdSize);
|
|
|
|
}
|
|
|
|
RCHECK(crypt_byte_block < 16 && skip_byte_block < 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
RCHECK(buffer->IgnoreBytes(1)); // reserved.
|
|
|
|
|
|
|
|
uint8_t pattern = crypt_byte_block << 4 | skip_byte_block;
|
|
|
|
RCHECK(buffer->ReadWriteUInt8(&pattern));
|
|
|
|
crypt_byte_block = pattern >> 4;
|
|
|
|
skip_byte_block = pattern & 0x0F;
|
|
|
|
|
|
|
|
RCHECK(buffer->ReadWriteUInt8(&is_protected) &&
|
|
|
|
buffer->ReadWriteUInt8(&per_sample_iv_size) &&
|
|
|
|
buffer->ReadWriteVector(&key_id, kCencKeyIdSize));
|
|
|
|
|
|
|
|
if (is_protected == 1) {
|
|
|
|
if (per_sample_iv_size == 0) { // For constant iv.
|
2016-08-14 22:28:21 +00:00
|
|
|
uint8_t constant_iv_size = static_cast<uint8_t>(constant_iv.size());
|
2016-05-06 23:56:50 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt8(&constant_iv_size));
|
|
|
|
RCHECK(constant_iv_size == 8 || constant_iv_size == 16);
|
|
|
|
RCHECK(buffer->ReadWriteVector(&constant_iv, constant_iv_size));
|
|
|
|
} else {
|
|
|
|
RCHECK(per_sample_iv_size == 8 || per_sample_iv_size == 16);
|
|
|
|
DCHECK(constant_iv.empty());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Expect |is_protected| to be 0, i.e. not protected. Other values of
|
|
|
|
// |is_protected| is not supported.
|
|
|
|
RCHECK(is_protected == 0);
|
|
|
|
RCHECK(per_sample_iv_size == 0);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t CencSampleEncryptionInfoEntry::ComputeSize() const {
|
2016-11-09 02:11:13 +00:00
|
|
|
return static_cast<uint32_t>(
|
|
|
|
sizeof(uint32_t) + kCencKeyIdSize +
|
|
|
|
(constant_iv.empty() ? 0 : (sizeof(uint8_t) + constant_iv.size())));
|
2016-05-06 23:56:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AudioRollRecoveryEntry::AudioRollRecoveryEntry(): roll_distance(0) {}
|
|
|
|
AudioRollRecoveryEntry::~AudioRollRecoveryEntry() {}
|
|
|
|
|
|
|
|
bool AudioRollRecoveryEntry::ReadWrite(BoxBuffer* buffer) {
|
|
|
|
RCHECK(buffer->ReadWriteInt16(&roll_distance));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t AudioRollRecoveryEntry::ComputeSize() const {
|
|
|
|
return sizeof(roll_distance);
|
|
|
|
}
|
|
|
|
|
|
|
|
SampleGroupDescription::SampleGroupDescription() : grouping_type(0) {}
|
|
|
|
SampleGroupDescription::~SampleGroupDescription() {}
|
|
|
|
FourCC SampleGroupDescription::BoxType() const { return FOURCC_sgpd; }
|
|
|
|
|
|
|
|
bool SampleGroupDescription::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
|
|
|
buffer->ReadWriteUInt32(&grouping_type));
|
|
|
|
|
|
|
|
switch (grouping_type) {
|
|
|
|
case FOURCC_seig:
|
|
|
|
return ReadWriteEntries(buffer, &cenc_sample_encryption_info_entries);
|
|
|
|
case FOURCC_roll:
|
|
|
|
return ReadWriteEntries(buffer, &audio_roll_recovery_entries);
|
|
|
|
default:
|
|
|
|
DCHECK(buffer->Reading());
|
2016-05-26 22:44:37 +00:00
|
|
|
DLOG(WARNING) << "Ignore unsupported sample group: "
|
|
|
|
<< FourCCToString(static_cast<FourCC>(grouping_type));
|
2016-05-06 23:56:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
bool SampleGroupDescription::ReadWriteEntries(BoxBuffer* buffer,
|
|
|
|
std::vector<T>* entries) {
|
|
|
|
uint32_t default_length = 0;
|
|
|
|
if (!buffer->Reading()) {
|
|
|
|
DCHECK(!entries->empty());
|
|
|
|
default_length = (*entries)[0].ComputeSize();
|
|
|
|
DCHECK_NE(default_length, 0u);
|
|
|
|
}
|
|
|
|
if (version == 1)
|
|
|
|
RCHECK(buffer->ReadWriteUInt32(&default_length));
|
|
|
|
if (version >= 2) {
|
|
|
|
NOTIMPLEMENTED() << "Unsupported SampleGroupDescriptionBox 'sgpd' version "
|
|
|
|
<< static_cast<int>(version);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
uint32_t count = static_cast<uint32_t>(entries->size());
|
2016-05-06 23:56:50 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt32(&count));
|
|
|
|
RCHECK(count != 0);
|
|
|
|
entries->resize(count);
|
|
|
|
|
|
|
|
for (T& entry : *entries) {
|
|
|
|
if (version == 1) {
|
|
|
|
uint32_t description_length = default_length;
|
|
|
|
if (buffer->Reading() && default_length == 0)
|
|
|
|
RCHECK(buffer->ReadWriteUInt32(&description_length));
|
|
|
|
RCHECK(entry.ReadWrite(buffer));
|
|
|
|
RCHECK(entry.ComputeSize() == description_length);
|
|
|
|
} else {
|
|
|
|
RCHECK(entry.ReadWrite(buffer));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t SampleGroupDescription::ComputeSizeInternal() {
|
2016-05-06 23:56:50 +00:00
|
|
|
// Version 0 is obsoleted, so always generate version 1 box.
|
|
|
|
version = 1;
|
|
|
|
size_t entries_size = 0;
|
|
|
|
switch (grouping_type) {
|
|
|
|
case FOURCC_seig:
|
|
|
|
for (const auto& entry : cenc_sample_encryption_info_entries)
|
|
|
|
entries_size += entry.ComputeSize();
|
|
|
|
break;
|
|
|
|
case FOURCC_roll:
|
|
|
|
for (const auto& entry : audio_roll_recovery_entries)
|
|
|
|
entries_size += entry.ComputeSize();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// This box is optional. Skip it if it is not used.
|
|
|
|
if (entries_size == 0)
|
|
|
|
return 0;
|
|
|
|
return HeaderSize() + sizeof(grouping_type) +
|
|
|
|
(version == 1 ? sizeof(uint32_t) : 0) + sizeof(uint32_t) +
|
|
|
|
entries_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
SampleToGroup::SampleToGroup() : grouping_type(0), grouping_type_parameter(0) {}
|
|
|
|
SampleToGroup::~SampleToGroup() {}
|
|
|
|
FourCC SampleToGroup::BoxType() const { return FOURCC_sbgp; }
|
|
|
|
|
|
|
|
bool SampleToGroup::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
|
|
|
buffer->ReadWriteUInt32(&grouping_type));
|
|
|
|
if (version == 1)
|
|
|
|
RCHECK(buffer->ReadWriteUInt32(&grouping_type_parameter));
|
|
|
|
|
|
|
|
if (grouping_type != FOURCC_seig && grouping_type != FOURCC_roll) {
|
|
|
|
DCHECK(buffer->Reading());
|
2016-05-26 22:44:37 +00:00
|
|
|
DLOG(WARNING) << "Ignore unsupported sample group: "
|
|
|
|
<< FourCCToString(static_cast<FourCC>(grouping_type));
|
2016-05-06 23:56:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
uint32_t count = static_cast<uint32_t>(entries.size());
|
2016-05-06 23:56:50 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt32(&count));
|
|
|
|
entries.resize(count);
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
|
|
|
RCHECK(buffer->ReadWriteUInt32(&entries[i].sample_count) &&
|
|
|
|
buffer->ReadWriteUInt32(&entries[i].group_description_index));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t SampleToGroup::ComputeSizeInternal() {
|
2016-05-06 23:56:50 +00:00
|
|
|
// This box is optional. Skip it if it is not used.
|
|
|
|
if (entries.empty())
|
|
|
|
return 0;
|
|
|
|
return HeaderSize() + sizeof(grouping_type) +
|
|
|
|
(version == 1 ? sizeof(grouping_type_parameter) : 0) +
|
|
|
|
sizeof(uint32_t) + entries.size() * sizeof(entries[0]);
|
|
|
|
}
|
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
SampleTable::SampleTable() {}
|
|
|
|
SampleTable::~SampleTable() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC SampleTable::BoxType() const { return FOURCC_stbl; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool SampleTable::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->PrepareChildren() &&
|
|
|
|
buffer->ReadWriteChild(&description) &&
|
|
|
|
buffer->ReadWriteChild(&decoding_time_to_sample) &&
|
|
|
|
buffer->TryReadWriteChild(&composition_time_to_sample) &&
|
|
|
|
buffer->ReadWriteChild(&sample_to_chunk));
|
|
|
|
|
|
|
|
if (buffer->Reading()) {
|
|
|
|
BoxReader* reader = buffer->reader();
|
|
|
|
DCHECK(reader);
|
|
|
|
|
|
|
|
// Either SampleSize or CompactSampleSize must present.
|
|
|
|
if (reader->ChildExist(&sample_size)) {
|
|
|
|
RCHECK(reader->ReadChild(&sample_size));
|
|
|
|
} else {
|
|
|
|
CompactSampleSize compact_sample_size;
|
|
|
|
RCHECK(reader->ReadChild(&compact_sample_size));
|
|
|
|
sample_size.sample_size = 0;
|
2016-11-09 02:11:13 +00:00
|
|
|
sample_size.sample_count =
|
|
|
|
static_cast<uint32_t>(compact_sample_size.sizes.size());
|
2013-11-27 01:52:13 +00:00
|
|
|
sample_size.sizes.swap(compact_sample_size.sizes);
|
|
|
|
}
|
2013-10-08 17:37:58 +00:00
|
|
|
|
2013-11-27 01:52:13 +00:00
|
|
|
// Either ChunkOffset or ChunkLargeOffset must present.
|
|
|
|
if (reader->ChildExist(&chunk_large_offset)) {
|
|
|
|
RCHECK(reader->ReadChild(&chunk_large_offset));
|
|
|
|
} else {
|
|
|
|
ChunkOffset chunk_offset;
|
|
|
|
RCHECK(reader->ReadChild(&chunk_offset));
|
|
|
|
chunk_large_offset.offsets.swap(chunk_offset.offsets);
|
|
|
|
}
|
2013-10-08 17:37:58 +00:00
|
|
|
} else {
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(buffer->ReadWriteChild(&sample_size) &&
|
|
|
|
buffer->ReadWriteChild(&chunk_large_offset));
|
2013-10-08 17:37:58 +00:00
|
|
|
}
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->TryReadWriteChild(&sync_sample));
|
2016-05-06 23:56:50 +00:00
|
|
|
if (buffer->Reading()) {
|
|
|
|
RCHECK(buffer->reader()->TryReadChildren(&sample_group_descriptions) &&
|
|
|
|
buffer->reader()->TryReadChildren(&sample_to_groups));
|
|
|
|
} else {
|
|
|
|
for (auto& sample_group_description : sample_group_descriptions)
|
|
|
|
RCHECK(buffer->ReadWriteChild(&sample_group_description));
|
|
|
|
for (auto& sample_to_group : sample_to_groups)
|
|
|
|
RCHECK(buffer->ReadWriteChild(&sample_to_group));
|
|
|
|
}
|
2013-10-08 17:37:58 +00:00
|
|
|
return true;
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t SampleTable::ComputeSizeInternal() {
|
|
|
|
size_t box_size = HeaderSize() + description.ComputeSize() +
|
|
|
|
decoding_time_to_sample.ComputeSize() +
|
|
|
|
composition_time_to_sample.ComputeSize() +
|
|
|
|
sample_to_chunk.ComputeSize() + sample_size.ComputeSize() +
|
|
|
|
chunk_large_offset.ComputeSize() +
|
|
|
|
sync_sample.ComputeSize();
|
2016-05-06 23:56:50 +00:00
|
|
|
for (auto& sample_group_description : sample_group_descriptions)
|
|
|
|
box_size += sample_group_description.ComputeSize();
|
|
|
|
for (auto& sample_to_group : sample_to_groups)
|
|
|
|
box_size += sample_to_group.ComputeSize();
|
|
|
|
return box_size;
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
EditList::EditList() {}
|
|
|
|
EditList::~EditList() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC EditList::BoxType() const { return FOURCC_elst; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool EditList::ReadWriteInternal(BoxBuffer* buffer) {
|
2016-11-09 02:11:13 +00:00
|
|
|
uint32_t count = static_cast<uint32_t>(edits.size());
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) && buffer->ReadWriteUInt32(&count));
|
2013-11-27 01:52:13 +00:00
|
|
|
edits.resize(count);
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
size_t num_bytes = (version == 1) ? sizeof(uint64_t) : sizeof(uint32_t);
|
|
|
|
for (uint32_t i = 0; i < count; ++i) {
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(
|
|
|
|
buffer->ReadWriteUInt64NBytes(&edits[i].segment_duration, num_bytes) &&
|
|
|
|
buffer->ReadWriteInt64NBytes(&edits[i].media_time, num_bytes) &&
|
|
|
|
buffer->ReadWriteInt16(&edits[i].media_rate_integer) &&
|
|
|
|
buffer->ReadWriteInt16(&edits[i].media_rate_fraction));
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
2013-11-27 01:52:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t EditList::ComputeSizeInternal() {
|
2013-11-27 01:52:13 +00:00
|
|
|
// EditList box is optional. Skip it if it is empty.
|
|
|
|
if (edits.empty())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
version = 0;
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < edits.size(); ++i) {
|
2013-11-27 01:52:13 +00:00
|
|
|
if (!IsFitIn32Bits(edits[i].segment_duration, edits[i].media_time)) {
|
|
|
|
version = 1;
|
|
|
|
break;
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + sizeof(uint32_t) +
|
|
|
|
(sizeof(uint32_t) * (1 + version) * 2 + sizeof(int16_t) * 2) *
|
|
|
|
edits.size();
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Edit::Edit() {}
|
|
|
|
Edit::~Edit() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC Edit::BoxType() const { return FOURCC_edts; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool Edit::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
return ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->PrepareChildren() &&
|
|
|
|
buffer->ReadWriteChild(&list);
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t Edit::ComputeSizeInternal() {
|
2013-11-27 01:52:13 +00:00
|
|
|
// Edit box is optional. Skip it if it is empty.
|
2015-12-15 00:07:51 +00:00
|
|
|
if (list.edits.empty())
|
|
|
|
return 0;
|
|
|
|
return HeaderSize() + list.ComputeSize();
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
|
2015-12-21 23:10:17 +00:00
|
|
|
HandlerReference::HandlerReference() : handler_type(FOURCC_NULL) {}
|
2013-09-24 01:35:40 +00:00
|
|
|
HandlerReference::~HandlerReference() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC HandlerReference::BoxType() const { return FOURCC_hdlr; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool HandlerReference::ReadWriteInternal(BoxBuffer* buffer) {
|
2014-09-30 21:52:21 +00:00
|
|
|
std::vector<uint8_t> handler_name;
|
2013-11-27 01:52:13 +00:00
|
|
|
if (!buffer->Reading()) {
|
2015-12-21 23:10:17 +00:00
|
|
|
switch (handler_type) {
|
2016-04-06 23:21:45 +00:00
|
|
|
case FOURCC_vide:
|
2015-12-21 23:10:17 +00:00
|
|
|
handler_name.assign(kVideoHandlerName,
|
|
|
|
kVideoHandlerName + arraysize(kVideoHandlerName));
|
|
|
|
break;
|
2016-04-06 23:21:45 +00:00
|
|
|
case FOURCC_soun:
|
2015-12-21 23:10:17 +00:00
|
|
|
handler_name.assign(kAudioHandlerName,
|
|
|
|
kAudioHandlerName + arraysize(kAudioHandlerName));
|
|
|
|
break;
|
2016-04-06 23:21:45 +00:00
|
|
|
case FOURCC_text:
|
2015-12-21 23:10:17 +00:00
|
|
|
handler_name.assign(kTextHandlerName,
|
|
|
|
kTextHandlerName + arraysize(kTextHandlerName));
|
|
|
|
break;
|
|
|
|
case FOURCC_ID32:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
return false;
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->IgnoreBytes(4) && // predefined.
|
2015-12-21 23:10:17 +00:00
|
|
|
buffer->ReadWriteFourCC(&handler_type));
|
|
|
|
if (!buffer->Reading()) {
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->IgnoreBytes(12) && // reserved.
|
|
|
|
buffer->ReadWriteVector(&handler_name, handler_name.size()));
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t HandlerReference::ComputeSizeInternal() {
|
|
|
|
size_t box_size = HeaderSize() + kFourCCSize + 16; // 16 bytes Reserved
|
2015-12-21 23:10:17 +00:00
|
|
|
switch (handler_type) {
|
2016-04-06 23:21:45 +00:00
|
|
|
case FOURCC_vide:
|
2015-12-21 23:10:17 +00:00
|
|
|
box_size += sizeof(kVideoHandlerName);
|
|
|
|
break;
|
2016-04-06 23:21:45 +00:00
|
|
|
case FOURCC_soun:
|
2015-12-21 23:10:17 +00:00
|
|
|
box_size += sizeof(kAudioHandlerName);
|
|
|
|
break;
|
2016-04-06 23:21:45 +00:00
|
|
|
case FOURCC_text:
|
2015-12-21 23:10:17 +00:00
|
|
|
box_size += sizeof(kTextHandlerName);
|
|
|
|
break;
|
|
|
|
case FOURCC_ID32:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NOTIMPLEMENTED();
|
2015-11-23 23:12:04 +00:00
|
|
|
}
|
|
|
|
return box_size;
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2015-12-21 23:10:17 +00:00
|
|
|
bool Language::ReadWrite(BoxBuffer* buffer) {
|
|
|
|
if (buffer->Reading()) {
|
|
|
|
// Read language codes into temp first then use BitReader to read the
|
|
|
|
// values. ISO-639-2/T language code: unsigned int(5)[3] language (2 bytes).
|
|
|
|
std::vector<uint8_t> temp;
|
|
|
|
RCHECK(buffer->ReadWriteVector(&temp, 2));
|
|
|
|
|
|
|
|
BitReader bit_reader(&temp[0], 2);
|
|
|
|
bit_reader.SkipBits(1);
|
|
|
|
char language[3];
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
CHECK(bit_reader.ReadBits(5, &language[i]));
|
|
|
|
language[i] += 0x60;
|
|
|
|
}
|
|
|
|
code.assign(language, 3);
|
|
|
|
} else {
|
|
|
|
// Set up default language if it is not set.
|
|
|
|
const char kUndefinedLanguage[] = "und";
|
|
|
|
if (code.empty())
|
|
|
|
code = kUndefinedLanguage;
|
|
|
|
DCHECK_EQ(code.size(), 3u);
|
|
|
|
|
|
|
|
// Lang format: bit(1) pad, unsigned int(5)[3] language.
|
|
|
|
uint16_t lang = 0;
|
|
|
|
for (int i = 0; i < 3; ++i)
|
|
|
|
lang |= (code[i] - 0x60) << ((2 - i) * 5);
|
|
|
|
RCHECK(buffer->ReadWriteUInt16(&lang));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Language::ComputeSize() const {
|
|
|
|
// ISO-639-2/T language code: unsigned int(5)[3] language (2 bytes).
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
ID3v2::ID3v2() {}
|
|
|
|
ID3v2::~ID3v2() {}
|
|
|
|
|
|
|
|
FourCC ID3v2::BoxType() const { return FOURCC_ID32; }
|
|
|
|
|
|
|
|
bool ID3v2::ReadWriteInternal(BoxBuffer* buffer) {
|
2018-05-07 22:57:56 +00:00
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) && language.ReadWrite(buffer) &&
|
|
|
|
buffer->ReadWriteVector(&id3v2_data, buffer->Reading()
|
|
|
|
? buffer->BytesLeft()
|
|
|
|
: id3v2_data.size()));
|
2015-12-21 23:10:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t ID3v2::ComputeSizeInternal() {
|
2018-05-07 22:57:56 +00:00
|
|
|
// Skip ID3v2 box generation if there is no id3 data.
|
|
|
|
return id3v2_data.size() == 0
|
|
|
|
? 0
|
|
|
|
: HeaderSize() + language.ComputeSize() + id3v2_data.size();
|
2015-12-21 23:10:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Metadata::Metadata() {}
|
|
|
|
Metadata::~Metadata() {}
|
|
|
|
|
|
|
|
FourCC Metadata::BoxType() const {
|
2016-04-06 23:21:45 +00:00
|
|
|
return FOURCC_meta;
|
2015-12-21 23:10:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Metadata::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
|
|
|
buffer->PrepareChildren() &&
|
|
|
|
buffer->ReadWriteChild(&handler) &&
|
|
|
|
buffer->TryReadWriteChild(&id3v2));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t Metadata::ComputeSizeInternal() {
|
|
|
|
size_t id3v2_size = id3v2.ComputeSize();
|
2015-12-21 23:10:17 +00:00
|
|
|
// Skip metadata box generation if there is no metadata box.
|
|
|
|
return id3v2_size == 0 ? 0
|
|
|
|
: HeaderSize() + handler.ComputeSize() + id3v2_size;
|
|
|
|
}
|
|
|
|
|
2016-05-25 01:07:14 +00:00
|
|
|
CodecConfiguration::CodecConfiguration() : box_type(FOURCC_NULL) {}
|
|
|
|
CodecConfiguration::~CodecConfiguration() {}
|
|
|
|
|
|
|
|
FourCC CodecConfiguration::BoxType() const {
|
|
|
|
// CodecConfiguration box should be parsed according to format recovered in
|
2015-10-27 00:52:57 +00:00
|
|
|
// VideoSampleEntry. |box_type| is determined dynamically there.
|
|
|
|
return box_type;
|
|
|
|
}
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2016-05-25 01:07:14 +00:00
|
|
|
bool CodecConfiguration::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
DCHECK_NE(box_type, FOURCC_NULL);
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
2016-05-25 01:07:14 +00:00
|
|
|
|
|
|
|
// VPCodecConfiguration box inherits from FullBox instead of Box. The extra 4
|
|
|
|
// bytes are handled here.
|
|
|
|
if (box_type == FOURCC_vpcC) {
|
2017-04-24 18:50:49 +00:00
|
|
|
// Only version 1 box is supported.
|
|
|
|
uint8_t vpcc_version = 1;
|
|
|
|
uint32_t version_flags = vpcc_version << 24;
|
2016-05-25 01:07:14 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt32(&version_flags));
|
2017-04-24 18:50:49 +00:00
|
|
|
vpcc_version = version_flags >> 24;
|
|
|
|
RCHECK(vpcc_version == 1);
|
2016-05-25 01:07:14 +00:00
|
|
|
}
|
|
|
|
|
2013-11-27 01:52:13 +00:00
|
|
|
if (buffer->Reading()) {
|
2015-11-23 23:12:04 +00:00
|
|
|
RCHECK(buffer->ReadWriteVector(&data, buffer->BytesLeft()));
|
2013-11-27 01:52:13 +00:00
|
|
|
} else {
|
|
|
|
RCHECK(buffer->ReadWriteVector(&data, data.size()));
|
|
|
|
}
|
|
|
|
return true;
|
2013-10-14 20:55:48 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t CodecConfiguration::ComputeSizeInternal() {
|
2015-12-15 00:07:51 +00:00
|
|
|
if (data.empty())
|
|
|
|
return 0;
|
2016-05-25 01:07:14 +00:00
|
|
|
DCHECK_NE(box_type, FOURCC_NULL);
|
|
|
|
return HeaderSize() + (box_type == FOURCC_vpcC ? 4 : 0) + data.size();
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
PixelAspectRatio::PixelAspectRatio() : h_spacing(0), v_spacing(0) {}
|
|
|
|
PixelAspectRatio::~PixelAspectRatio() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC PixelAspectRatio::BoxType() const { return FOURCC_pasp; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool PixelAspectRatio::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->ReadWriteUInt32(&h_spacing) &&
|
|
|
|
buffer->ReadWriteUInt32(&v_spacing));
|
2013-09-24 01:35:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t PixelAspectRatio::ComputeSizeInternal() {
|
2013-11-27 01:52:13 +00:00
|
|
|
// This box is optional. Skip it if it is not initialized.
|
2015-12-15 00:07:51 +00:00
|
|
|
if (h_spacing == 0 && v_spacing == 0)
|
|
|
|
return 0;
|
|
|
|
// Both values must be positive.
|
|
|
|
DCHECK(h_spacing != 0 && v_spacing != 0);
|
|
|
|
return HeaderSize() + sizeof(h_spacing) + sizeof(v_spacing);
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
VideoSampleEntry::VideoSampleEntry()
|
2013-11-27 01:52:13 +00:00
|
|
|
: format(FOURCC_NULL), data_reference_index(1), width(0), height(0) {}
|
2013-09-24 01:35:40 +00:00
|
|
|
|
|
|
|
VideoSampleEntry::~VideoSampleEntry() {}
|
|
|
|
FourCC VideoSampleEntry::BoxType() const {
|
2015-12-15 00:07:51 +00:00
|
|
|
if (format == FOURCC_NULL) {
|
|
|
|
LOG(ERROR) << "VideoSampleEntry should be parsed according to the "
|
|
|
|
<< "handler type recovered in its Media ancestor.";
|
|
|
|
}
|
|
|
|
return format;
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool VideoSampleEntry::ReadWriteInternal(BoxBuffer* buffer) {
|
2015-10-26 20:50:22 +00:00
|
|
|
std::vector<uint8_t> compressor_name;
|
2013-11-27 01:52:13 +00:00
|
|
|
if (buffer->Reading()) {
|
|
|
|
DCHECK(buffer->reader());
|
|
|
|
format = buffer->reader()->type();
|
|
|
|
} else {
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
2015-10-26 20:50:22 +00:00
|
|
|
|
|
|
|
const FourCC actual_format = GetActualFormat();
|
|
|
|
switch (actual_format) {
|
2016-04-06 23:21:45 +00:00
|
|
|
case FOURCC_avc1:
|
2017-03-23 18:34:20 +00:00
|
|
|
case FOURCC_avc3:
|
2015-10-26 20:50:22 +00:00
|
|
|
compressor_name.assign(
|
|
|
|
kAvcCompressorName,
|
|
|
|
kAvcCompressorName + arraysize(kAvcCompressorName));
|
|
|
|
break;
|
2016-04-06 23:21:45 +00:00
|
|
|
case FOURCC_hev1:
|
|
|
|
case FOURCC_hvc1:
|
2015-10-29 00:26:29 +00:00
|
|
|
compressor_name.assign(
|
|
|
|
kHevcCompressorName,
|
|
|
|
kHevcCompressorName + arraysize(kHevcCompressorName));
|
|
|
|
break;
|
2016-04-06 23:21:45 +00:00
|
|
|
case FOURCC_vp08:
|
|
|
|
case FOURCC_vp09:
|
|
|
|
case FOURCC_vp10:
|
2015-10-26 20:50:22 +00:00
|
|
|
compressor_name.assign(
|
|
|
|
kVpcCompressorName,
|
|
|
|
kVpcCompressorName + arraysize(kVpcCompressorName));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LOG(ERROR) << FourCCToString(actual_format) << " is not supported.";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
compressor_name.resize(kCompressorNameSize);
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t video_resolution = kVideoResolution;
|
|
|
|
uint16_t video_frame_count = kVideoFrameCount;
|
|
|
|
uint16_t video_depth = kVideoDepth;
|
|
|
|
int16_t predefined = -1;
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->IgnoreBytes(6) && // reserved.
|
|
|
|
buffer->ReadWriteUInt16(&data_reference_index) &&
|
|
|
|
buffer->IgnoreBytes(16) && // predefined 0.
|
|
|
|
buffer->ReadWriteUInt16(&width) &&
|
|
|
|
buffer->ReadWriteUInt16(&height) &&
|
|
|
|
buffer->ReadWriteUInt32(&video_resolution) &&
|
|
|
|
buffer->ReadWriteUInt32(&video_resolution) &&
|
|
|
|
buffer->IgnoreBytes(4) && // reserved.
|
|
|
|
buffer->ReadWriteUInt16(&video_frame_count) &&
|
2015-10-26 20:50:22 +00:00
|
|
|
buffer->ReadWriteVector(&compressor_name, kCompressorNameSize) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->ReadWriteUInt16(&video_depth) &&
|
|
|
|
buffer->ReadWriteInt16(&predefined));
|
|
|
|
|
2015-08-05 23:39:03 +00:00
|
|
|
RCHECK(buffer->PrepareChildren());
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2017-07-06 18:53:44 +00:00
|
|
|
// This has to happen before reading codec configuration box as the actual
|
|
|
|
// format is read from sinf.format.format, which is needed to parse the codec
|
|
|
|
// configuration box.
|
|
|
|
if (format == FOURCC_encv && buffer->Reading()) {
|
|
|
|
// Continue scanning until a supported protection scheme is found, or
|
|
|
|
// until we run out of protection schemes.
|
|
|
|
while (!IsProtectionSchemeSupported(sinf.type.type))
|
2016-05-26 22:44:37 +00:00
|
|
|
RCHECK(buffer->ReadWriteChild(&sinf));
|
|
|
|
}
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-10-27 00:52:57 +00:00
|
|
|
const FourCC actual_format = GetActualFormat();
|
2016-05-25 01:07:14 +00:00
|
|
|
if (buffer->Reading()) {
|
|
|
|
codec_configuration.box_type = GetCodecConfigurationBoxType(actual_format);
|
|
|
|
} else {
|
|
|
|
DCHECK_EQ(codec_configuration.box_type,
|
|
|
|
GetCodecConfigurationBoxType(actual_format));
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
2017-07-06 18:53:44 +00:00
|
|
|
if (codec_configuration.box_type == FOURCC_NULL)
|
|
|
|
return false;
|
2016-05-25 01:07:14 +00:00
|
|
|
|
|
|
|
RCHECK(buffer->ReadWriteChild(&codec_configuration));
|
2015-08-05 23:39:03 +00:00
|
|
|
RCHECK(buffer->TryReadWriteChild(&pixel_aspect));
|
2017-07-06 18:53:44 +00:00
|
|
|
|
|
|
|
// Somehow Edge does not support having sinf box before codec_configuration,
|
|
|
|
// box, so just do it in the end of VideoSampleEntry. See
|
|
|
|
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12658991/
|
|
|
|
if (format == FOURCC_encv && !buffer->Reading()) {
|
|
|
|
DCHECK(IsProtectionSchemeSupported(sinf.type.type));
|
|
|
|
RCHECK(buffer->ReadWriteChild(&sinf));
|
|
|
|
}
|
2013-09-24 01:35:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t VideoSampleEntry::ComputeSizeInternal() {
|
2016-05-25 01:07:14 +00:00
|
|
|
const FourCC actual_format = GetActualFormat();
|
|
|
|
if (actual_format == FOURCC_NULL)
|
|
|
|
return 0;
|
|
|
|
codec_configuration.box_type = GetCodecConfigurationBoxType(actual_format);
|
|
|
|
DCHECK_NE(codec_configuration.box_type, FOURCC_NULL);
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + sizeof(data_reference_index) + sizeof(width) +
|
|
|
|
sizeof(height) + sizeof(kVideoResolution) * 2 +
|
|
|
|
sizeof(kVideoFrameCount) + sizeof(kVideoDepth) +
|
|
|
|
pixel_aspect.ComputeSize() + sinf.ComputeSize() +
|
2016-05-25 01:07:14 +00:00
|
|
|
codec_configuration.ComputeSize() + kCompressorNameSize + 6 + 4 + 16 +
|
2015-12-15 00:07:51 +00:00
|
|
|
2; // 6 + 4 bytes reserved, 16 + 2 bytes predefined.
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2016-05-25 01:07:14 +00:00
|
|
|
FourCC VideoSampleEntry::GetCodecConfigurationBoxType(FourCC format) const {
|
|
|
|
switch (format) {
|
|
|
|
case FOURCC_avc1:
|
2017-03-23 18:34:20 +00:00
|
|
|
case FOURCC_avc3:
|
2016-05-25 01:07:14 +00:00
|
|
|
return FOURCC_avcC;
|
|
|
|
case FOURCC_hev1:
|
|
|
|
case FOURCC_hvc1:
|
|
|
|
return FOURCC_hvcC;
|
|
|
|
case FOURCC_vp08:
|
|
|
|
case FOURCC_vp09:
|
|
|
|
case FOURCC_vp10:
|
|
|
|
return FOURCC_vpcC;
|
|
|
|
default:
|
|
|
|
LOG(ERROR) << FourCCToString(format) << " is not supported.";
|
|
|
|
return FOURCC_NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-27 01:52:13 +00:00
|
|
|
ElementaryStreamDescriptor::ElementaryStreamDescriptor() {}
|
2013-09-24 01:35:40 +00:00
|
|
|
ElementaryStreamDescriptor::~ElementaryStreamDescriptor() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC ElementaryStreamDescriptor::BoxType() const { return FOURCC_esds; }
|
2013-11-27 01:52:13 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool ElementaryStreamDescriptor::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
2013-11-27 01:52:13 +00:00
|
|
|
if (buffer->Reading()) {
|
2014-09-30 21:52:21 +00:00
|
|
|
std::vector<uint8_t> data;
|
2015-11-23 23:12:04 +00:00
|
|
|
RCHECK(buffer->ReadWriteVector(&data, buffer->BytesLeft()));
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(es_descriptor.Parse(data));
|
2014-01-10 00:21:06 +00:00
|
|
|
if (es_descriptor.IsAAC()) {
|
|
|
|
RCHECK(aac_audio_specific_config.Parse(
|
|
|
|
es_descriptor.decoder_specific_info()));
|
|
|
|
}
|
2013-11-27 01:52:13 +00:00
|
|
|
} else {
|
|
|
|
DCHECK(buffer->writer());
|
|
|
|
es_descriptor.Write(buffer->writer());
|
|
|
|
}
|
|
|
|
return true;
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t ElementaryStreamDescriptor::ComputeSizeInternal() {
|
2013-11-27 01:52:13 +00:00
|
|
|
// This box is optional. Skip it if not initialized.
|
2015-12-15 00:07:51 +00:00
|
|
|
if (es_descriptor.object_type() == kForbidden)
|
|
|
|
return 0;
|
|
|
|
return HeaderSize() + es_descriptor.ComputeSize();
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
|
2016-01-04 18:57:05 +00:00
|
|
|
DTSSpecific::DTSSpecific()
|
|
|
|
: sampling_frequency(0),
|
|
|
|
max_bitrate(0),
|
|
|
|
avg_bitrate(0),
|
|
|
|
pcm_sample_depth(0) {}
|
2015-12-15 00:07:51 +00:00
|
|
|
DTSSpecific::~DTSSpecific() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC DTSSpecific::BoxType() const { return FOURCC_ddts; }
|
2015-12-07 19:56:07 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool DTSSpecific::ReadWriteInternal(BoxBuffer* buffer) {
|
2016-01-04 18:57:05 +00:00
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
|
|
|
buffer->ReadWriteUInt32(&sampling_frequency) &&
|
|
|
|
buffer->ReadWriteUInt32(&max_bitrate) &&
|
|
|
|
buffer->ReadWriteUInt32(&avg_bitrate) &&
|
|
|
|
buffer->ReadWriteUInt8(&pcm_sample_depth));
|
2015-12-07 19:56:07 +00:00
|
|
|
|
|
|
|
if (buffer->Reading()) {
|
2016-01-08 23:56:33 +00:00
|
|
|
RCHECK(buffer->ReadWriteVector(&extra_data, buffer->BytesLeft()));
|
2015-12-07 19:56:07 +00:00
|
|
|
} else {
|
2016-01-04 18:57:05 +00:00
|
|
|
if (extra_data.empty()) {
|
|
|
|
extra_data.assign(kDdtsExtraData,
|
|
|
|
kDdtsExtraData + sizeof(kDdtsExtraData));
|
|
|
|
}
|
|
|
|
RCHECK(buffer->ReadWriteVector(&extra_data, extra_data.size()));
|
2015-12-07 19:56:07 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t DTSSpecific::ComputeSizeInternal() {
|
2015-12-07 19:56:07 +00:00
|
|
|
// This box is optional. Skip it if not initialized.
|
2016-01-04 18:57:05 +00:00
|
|
|
if (sampling_frequency == 0)
|
2015-12-15 00:07:51 +00:00
|
|
|
return 0;
|
2016-01-04 18:57:05 +00:00
|
|
|
return HeaderSize() + sizeof(sampling_frequency) + sizeof(max_bitrate) +
|
|
|
|
sizeof(avg_bitrate) + sizeof(pcm_sample_depth) +
|
|
|
|
sizeof(kDdtsExtraData);
|
2015-12-07 19:56:07 +00:00
|
|
|
}
|
|
|
|
|
2016-01-08 23:56:33 +00:00
|
|
|
AC3Specific::AC3Specific() {}
|
|
|
|
AC3Specific::~AC3Specific() {}
|
|
|
|
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC AC3Specific::BoxType() const { return FOURCC_dac3; }
|
2016-01-08 23:56:33 +00:00
|
|
|
|
|
|
|
bool AC3Specific::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
|
|
|
buffer->ReadWriteVector(
|
|
|
|
&data, buffer->Reading() ? buffer->BytesLeft() : data.size()));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t AC3Specific::ComputeSizeInternal() {
|
2016-01-08 23:56:33 +00:00
|
|
|
// This box is optional. Skip it if not initialized.
|
|
|
|
if (data.empty())
|
|
|
|
return 0;
|
|
|
|
return HeaderSize() + data.size();
|
|
|
|
}
|
|
|
|
|
2016-02-09 00:22:01 +00:00
|
|
|
EC3Specific::EC3Specific() {}
|
2016-01-15 21:40:44 +00:00
|
|
|
EC3Specific::~EC3Specific() {}
|
|
|
|
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC EC3Specific::BoxType() const { return FOURCC_dec3; }
|
2016-01-15 21:40:44 +00:00
|
|
|
|
|
|
|
bool EC3Specific::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t size = buffer->Reading() ? buffer->BytesLeft() : data.size();
|
2016-01-15 21:40:44 +00:00
|
|
|
RCHECK(buffer->ReadWriteVector(&data, size));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t EC3Specific::ComputeSizeInternal() {
|
2016-01-15 21:40:44 +00:00
|
|
|
// This box is optional. Skip it if not initialized.
|
|
|
|
if (data.empty())
|
|
|
|
return 0;
|
|
|
|
return HeaderSize() + data.size();
|
|
|
|
}
|
|
|
|
|
2016-05-09 18:55:14 +00:00
|
|
|
OpusSpecific::OpusSpecific() : preskip(0) {}
|
|
|
|
OpusSpecific::~OpusSpecific() {}
|
|
|
|
|
|
|
|
FourCC OpusSpecific::BoxType() const { return FOURCC_dOps; }
|
|
|
|
|
|
|
|
bool OpusSpecific::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
|
|
|
if (buffer->Reading()) {
|
|
|
|
std::vector<uint8_t> data;
|
|
|
|
const int kMinOpusSpecificBoxDataSize = 11;
|
|
|
|
RCHECK(buffer->BytesLeft() >= kMinOpusSpecificBoxDataSize);
|
|
|
|
RCHECK(buffer->ReadWriteVector(&data, buffer->BytesLeft()));
|
|
|
|
preskip = data[2] + (data[3] << 8);
|
|
|
|
|
|
|
|
// https://tools.ietf.org/html/draft-ietf-codec-oggopus-06#section-5
|
|
|
|
BufferWriter writer;
|
|
|
|
writer.AppendInt(FOURCC_Opus);
|
|
|
|
writer.AppendInt(FOURCC_Head);
|
|
|
|
// The version must always be 1.
|
|
|
|
const uint8_t kOpusIdentificationHeaderVersion = 1;
|
|
|
|
data[0] = kOpusIdentificationHeaderVersion;
|
|
|
|
writer.AppendVector(data);
|
|
|
|
writer.SwapBuffer(&opus_identification_header);
|
|
|
|
} else {
|
|
|
|
// https://tools.ietf.org/html/draft-ietf-codec-oggopus-06#section-5
|
|
|
|
// The first 8 bytes is "magic signature".
|
|
|
|
const size_t kOpusMagicSignatureSize = 8u;
|
|
|
|
DCHECK_GT(opus_identification_header.size(), kOpusMagicSignatureSize);
|
|
|
|
// https://www.opus-codec.org/docs/opus_in_isobmff.html
|
|
|
|
// The version field shall be set to 0.
|
|
|
|
const uint8_t kOpusSpecificBoxVersion = 0;
|
|
|
|
buffer->writer()->AppendInt(kOpusSpecificBoxVersion);
|
|
|
|
buffer->writer()->AppendArray(
|
|
|
|
&opus_identification_header[kOpusMagicSignatureSize + 1],
|
|
|
|
opus_identification_header.size() - kOpusMagicSignatureSize - 1);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t OpusSpecific::ComputeSizeInternal() {
|
2016-05-09 18:55:14 +00:00
|
|
|
// This box is optional. Skip it if not initialized.
|
|
|
|
if (opus_identification_header.empty())
|
|
|
|
return 0;
|
|
|
|
// https://tools.ietf.org/html/draft-ietf-codec-oggopus-06#section-5
|
|
|
|
// The first 8 bytes is "magic signature".
|
|
|
|
const size_t kOpusMagicSignatureSize = 8u;
|
|
|
|
DCHECK_GT(opus_identification_header.size(), kOpusMagicSignatureSize);
|
|
|
|
return HeaderSize() + opus_identification_header.size() -
|
|
|
|
kOpusMagicSignatureSize;
|
|
|
|
}
|
|
|
|
|
2018-04-25 18:27:53 +00:00
|
|
|
FlacSpecific::FlacSpecific() {}
|
|
|
|
FlacSpecific::~FlacSpecific() {}
|
|
|
|
|
|
|
|
FourCC FlacSpecific::BoxType() const {
|
|
|
|
return FOURCC_dfLa;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FlacSpecific::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
|
|
|
size_t size = buffer->Reading() ? buffer->BytesLeft() : data.size();
|
|
|
|
RCHECK(buffer->ReadWriteVector(&data, size));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t FlacSpecific::ComputeSizeInternal() {
|
|
|
|
// This box is optional. Skip it if not initialized.
|
|
|
|
if (data.empty())
|
|
|
|
return 0;
|
|
|
|
return HeaderSize() + data.size();
|
|
|
|
}
|
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
AudioSampleEntry::AudioSampleEntry()
|
|
|
|
: format(FOURCC_NULL),
|
2013-11-27 01:52:13 +00:00
|
|
|
data_reference_index(1),
|
|
|
|
channelcount(2),
|
|
|
|
samplesize(16),
|
2013-09-24 01:35:40 +00:00
|
|
|
samplerate(0) {}
|
|
|
|
|
|
|
|
AudioSampleEntry::~AudioSampleEntry() {}
|
|
|
|
|
|
|
|
FourCC AudioSampleEntry::BoxType() const {
|
2015-12-15 00:07:51 +00:00
|
|
|
if (format == FOURCC_NULL) {
|
|
|
|
LOG(ERROR) << "AudioSampleEntry should be parsed according to the "
|
|
|
|
<< "handler type recovered in its Media ancestor.";
|
|
|
|
}
|
|
|
|
return format;
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool AudioSampleEntry::ReadWriteInternal(BoxBuffer* buffer) {
|
2013-11-27 01:52:13 +00:00
|
|
|
if (buffer->Reading()) {
|
|
|
|
DCHECK(buffer->reader());
|
|
|
|
format = buffer->reader()->type();
|
|
|
|
} else {
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert from integer to 16.16 fixed point for writing.
|
|
|
|
samplerate <<= 16;
|
|
|
|
RCHECK(buffer->IgnoreBytes(6) && // reserved.
|
|
|
|
buffer->ReadWriteUInt16(&data_reference_index) &&
|
|
|
|
buffer->IgnoreBytes(8) && // reserved.
|
|
|
|
buffer->ReadWriteUInt16(&channelcount) &&
|
|
|
|
buffer->ReadWriteUInt16(&samplesize) &&
|
|
|
|
buffer->IgnoreBytes(4) && // predefined.
|
|
|
|
buffer->ReadWriteUInt32(&samplerate));
|
|
|
|
// Convert from 16.16 fixed point to integer.
|
2013-09-24 01:35:40 +00:00
|
|
|
samplerate >>= 16;
|
|
|
|
|
2015-12-07 19:35:11 +00:00
|
|
|
RCHECK(buffer->PrepareChildren());
|
2017-07-06 18:53:44 +00:00
|
|
|
|
|
|
|
RCHECK(buffer->TryReadWriteChild(&esds));
|
|
|
|
RCHECK(buffer->TryReadWriteChild(&ddts));
|
|
|
|
RCHECK(buffer->TryReadWriteChild(&dac3));
|
|
|
|
RCHECK(buffer->TryReadWriteChild(&dec3));
|
|
|
|
RCHECK(buffer->TryReadWriteChild(&dops));
|
2018-04-25 18:27:53 +00:00
|
|
|
RCHECK(buffer->TryReadWriteChild(&dfla));
|
2017-07-06 18:53:44 +00:00
|
|
|
|
|
|
|
// Somehow Edge does not support having sinf box before codec_configuration,
|
|
|
|
// box, so just do it in the end of AudioSampleEntry. See
|
|
|
|
// https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12658991/
|
2016-05-26 22:44:37 +00:00
|
|
|
if (format == FOURCC_enca) {
|
|
|
|
if (buffer->Reading()) {
|
|
|
|
// Continue scanning until a supported protection scheme is found, or
|
|
|
|
// until we run out of protection schemes.
|
|
|
|
while (!IsProtectionSchemeSupported(sinf.type.type))
|
|
|
|
RCHECK(buffer->ReadWriteChild(&sinf));
|
|
|
|
} else {
|
|
|
|
DCHECK(IsProtectionSchemeSupported(sinf.type.type));
|
|
|
|
RCHECK(buffer->ReadWriteChild(&sinf));
|
|
|
|
}
|
|
|
|
}
|
2013-09-24 01:35:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t AudioSampleEntry::ComputeSizeInternal() {
|
2016-05-25 01:07:14 +00:00
|
|
|
if (GetActualFormat() == FOURCC_NULL)
|
|
|
|
return 0;
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + sizeof(data_reference_index) + sizeof(channelcount) +
|
|
|
|
sizeof(samplesize) + sizeof(samplerate) + sinf.ComputeSize() +
|
2016-01-08 23:56:33 +00:00
|
|
|
esds.ComputeSize() + ddts.ComputeSize() + dac3.ComputeSize() +
|
2018-04-25 18:27:53 +00:00
|
|
|
dec3.ComputeSize() + dops.ComputeSize() + dfla.ComputeSize() +
|
|
|
|
// Reserved and predefined bytes.
|
2016-01-08 23:56:33 +00:00
|
|
|
6 + 8 + // 6 + 8 bytes reserved.
|
|
|
|
4; // 4 bytes predefined.
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2015-11-23 23:12:04 +00:00
|
|
|
WebVTTConfigurationBox::WebVTTConfigurationBox() {}
|
|
|
|
WebVTTConfigurationBox::~WebVTTConfigurationBox() {}
|
|
|
|
|
|
|
|
FourCC WebVTTConfigurationBox::BoxType() const {
|
|
|
|
return FOURCC_vttC;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebVTTConfigurationBox::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
|
|
|
return buffer->ReadWriteString(
|
|
|
|
&config,
|
|
|
|
buffer->Reading() ? buffer->BytesLeft() : config.size());
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t WebVTTConfigurationBox::ComputeSizeInternal() {
|
2015-11-23 23:12:04 +00:00
|
|
|
return HeaderSize() + config.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
WebVTTSourceLabelBox::WebVTTSourceLabelBox() {}
|
|
|
|
WebVTTSourceLabelBox::~WebVTTSourceLabelBox() {}
|
|
|
|
|
|
|
|
FourCC WebVTTSourceLabelBox::BoxType() const {
|
|
|
|
return FOURCC_vlab;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool WebVTTSourceLabelBox::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
|
|
|
return buffer->ReadWriteString(&source_label, buffer->Reading()
|
|
|
|
? buffer->BytesLeft()
|
|
|
|
: source_label.size());
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t WebVTTSourceLabelBox::ComputeSizeInternal() {
|
2015-11-23 23:12:04 +00:00
|
|
|
if (source_label.empty())
|
|
|
|
return 0;
|
|
|
|
return HeaderSize() + source_label.size();
|
|
|
|
}
|
|
|
|
|
2016-02-03 23:58:35 +00:00
|
|
|
TextSampleEntry::TextSampleEntry() : format(FOURCC_NULL) {}
|
|
|
|
TextSampleEntry::~TextSampleEntry() {}
|
2015-11-23 23:12:04 +00:00
|
|
|
|
2016-02-03 23:58:35 +00:00
|
|
|
FourCC TextSampleEntry::BoxType() const {
|
|
|
|
if (format == FOURCC_NULL) {
|
|
|
|
LOG(ERROR) << "TextSampleEntry should be parsed according to the "
|
|
|
|
<< "handler type recovered in its Media ancestor.";
|
|
|
|
}
|
|
|
|
return format;
|
2015-11-23 23:12:04 +00:00
|
|
|
}
|
|
|
|
|
2016-02-03 23:58:35 +00:00
|
|
|
bool TextSampleEntry::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
if (buffer->Reading()) {
|
|
|
|
DCHECK(buffer->reader());
|
|
|
|
format = buffer->reader()->type();
|
|
|
|
} else {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
|
|
|
}
|
|
|
|
RCHECK(buffer->IgnoreBytes(6) && // reserved for SampleEntry.
|
|
|
|
buffer->ReadWriteUInt16(&data_reference_index));
|
|
|
|
|
|
|
|
if (format == FOURCC_wvtt) {
|
|
|
|
// TODO(rkuroiwa): Handle the optional MPEG4BitRateBox.
|
|
|
|
RCHECK(buffer->PrepareChildren() &&
|
|
|
|
buffer->ReadWriteChild(&config) &&
|
|
|
|
buffer->ReadWriteChild(&label));
|
|
|
|
}
|
2015-11-23 23:12:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t TextSampleEntry::ComputeSizeInternal() {
|
2015-11-23 23:12:04 +00:00
|
|
|
// 6 for the (anonymous) reserved bytes for SampleEntry class.
|
|
|
|
return HeaderSize() + 6 + sizeof(data_reference_index) +
|
|
|
|
config.ComputeSize() + label.ComputeSize();
|
|
|
|
}
|
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
MediaHeader::MediaHeader()
|
2015-12-21 23:10:17 +00:00
|
|
|
: creation_time(0), modification_time(0), timescale(0), duration(0) {}
|
2013-09-24 01:35:40 +00:00
|
|
|
MediaHeader::~MediaHeader() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC MediaHeader::BoxType() const { return FOURCC_mdhd; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool MediaHeader::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
2013-11-27 01:52:13 +00:00
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
uint8_t num_bytes = (version == 1) ? sizeof(uint64_t) : sizeof(uint32_t);
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt64NBytes(&creation_time, num_bytes) &&
|
|
|
|
buffer->ReadWriteUInt64NBytes(&modification_time, num_bytes) &&
|
|
|
|
buffer->ReadWriteUInt32(×cale) &&
|
2015-12-21 23:10:17 +00:00
|
|
|
buffer->ReadWriteUInt64NBytes(&duration, num_bytes) &&
|
|
|
|
language.ReadWrite(buffer) &&
|
|
|
|
buffer->IgnoreBytes(2)); // predefined.
|
2013-11-27 01:52:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t MediaHeader::ComputeSizeInternal() {
|
2013-11-27 01:52:13 +00:00
|
|
|
version = IsFitIn32Bits(creation_time, modification_time, duration) ? 0 : 1;
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + sizeof(timescale) +
|
2015-12-21 23:10:17 +00:00
|
|
|
sizeof(uint32_t) * (1 + version) * 3 + language.ComputeSize() +
|
|
|
|
2; // 2 bytes predefined.
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VideoMediaHeader::VideoMediaHeader()
|
|
|
|
: graphicsmode(0), opcolor_red(0), opcolor_green(0), opcolor_blue(0) {
|
2014-09-30 21:52:21 +00:00
|
|
|
const uint32_t kVideoMediaHeaderFlags = 1;
|
2013-11-27 01:52:13 +00:00
|
|
|
flags = kVideoMediaHeaderFlags;
|
|
|
|
}
|
|
|
|
VideoMediaHeader::~VideoMediaHeader() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC VideoMediaHeader::BoxType() const { return FOURCC_vmhd; }
|
2015-12-15 00:07:51 +00:00
|
|
|
bool VideoMediaHeader::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->ReadWriteUInt16(&graphicsmode) &&
|
|
|
|
buffer->ReadWriteUInt16(&opcolor_red) &&
|
|
|
|
buffer->ReadWriteUInt16(&opcolor_green) &&
|
|
|
|
buffer->ReadWriteUInt16(&opcolor_blue));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t VideoMediaHeader::ComputeSizeInternal() {
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + sizeof(graphicsmode) + sizeof(opcolor_red) +
|
|
|
|
sizeof(opcolor_green) + sizeof(opcolor_blue);
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SoundMediaHeader::SoundMediaHeader() : balance(0) {}
|
|
|
|
SoundMediaHeader::~SoundMediaHeader() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC SoundMediaHeader::BoxType() const { return FOURCC_smhd; }
|
2015-12-15 00:07:51 +00:00
|
|
|
bool SoundMediaHeader::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->ReadWriteUInt16(&balance) &&
|
|
|
|
buffer->IgnoreBytes(2)); // reserved.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t SoundMediaHeader::ComputeSizeInternal() {
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + sizeof(balance) + sizeof(uint16_t);
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
2013-10-14 20:55:48 +00:00
|
|
|
|
2015-11-23 23:12:04 +00:00
|
|
|
SubtitleMediaHeader::SubtitleMediaHeader() {}
|
|
|
|
SubtitleMediaHeader::~SubtitleMediaHeader() {}
|
|
|
|
|
|
|
|
FourCC SubtitleMediaHeader::BoxType() const { return FOURCC_sthd; }
|
|
|
|
|
|
|
|
bool SubtitleMediaHeader::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
return ReadWriteHeaderInternal(buffer);
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t SubtitleMediaHeader::ComputeSizeInternal() {
|
2015-11-23 23:12:04 +00:00
|
|
|
return HeaderSize();
|
|
|
|
}
|
|
|
|
|
2013-11-27 01:52:13 +00:00
|
|
|
DataEntryUrl::DataEntryUrl() {
|
2014-09-30 21:52:21 +00:00
|
|
|
const uint32_t kDataEntryUrlFlags = 1;
|
2013-11-27 01:52:13 +00:00
|
|
|
flags = kDataEntryUrlFlags;
|
|
|
|
}
|
|
|
|
DataEntryUrl::~DataEntryUrl() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC DataEntryUrl::BoxType() const { return FOURCC_url; }
|
2015-12-15 00:07:51 +00:00
|
|
|
bool DataEntryUrl::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
2013-11-27 01:52:13 +00:00
|
|
|
if (buffer->Reading()) {
|
2016-01-08 23:56:33 +00:00
|
|
|
RCHECK(buffer->ReadWriteVector(&location, buffer->BytesLeft()));
|
2013-11-27 01:52:13 +00:00
|
|
|
} else {
|
|
|
|
RCHECK(buffer->ReadWriteVector(&location, location.size()));
|
2013-10-14 20:55:48 +00:00
|
|
|
}
|
2013-11-27 01:52:13 +00:00
|
|
|
return true;
|
|
|
|
}
|
2013-10-14 20:55:48 +00:00
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t DataEntryUrl::ComputeSizeInternal() {
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + location.size();
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DataReference::DataReference() {
|
|
|
|
// Default 1 entry.
|
|
|
|
data_entry.resize(1);
|
|
|
|
}
|
|
|
|
DataReference::~DataReference() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC DataReference::BoxType() const { return FOURCC_dref; }
|
2015-12-15 00:07:51 +00:00
|
|
|
bool DataReference::ReadWriteInternal(BoxBuffer* buffer) {
|
2016-11-09 02:11:13 +00:00
|
|
|
uint32_t entry_count = static_cast<uint32_t>(data_entry.size());
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->ReadWriteUInt32(&entry_count));
|
|
|
|
data_entry.resize(entry_count);
|
|
|
|
RCHECK(buffer->PrepareChildren());
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < entry_count; ++i)
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->ReadWriteChild(&data_entry[i]));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t DataReference::ComputeSizeInternal() {
|
|
|
|
uint32_t count = static_cast<uint32_t>(data_entry.size());
|
|
|
|
size_t box_size = HeaderSize() + sizeof(count);
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < count; ++i)
|
2015-12-15 00:07:51 +00:00
|
|
|
box_size += data_entry[i].ComputeSize();
|
|
|
|
return box_size;
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DataInformation::DataInformation() {}
|
|
|
|
DataInformation::~DataInformation() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC DataInformation::BoxType() const { return FOURCC_dinf; }
|
2013-11-27 01:52:13 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool DataInformation::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
return ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->PrepareChildren() &&
|
|
|
|
buffer->ReadWriteChild(&dref);
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t DataInformation::ComputeSizeInternal() {
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + dref.ComputeSize();
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MediaInformation::MediaInformation() {}
|
|
|
|
MediaInformation::~MediaInformation() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC MediaInformation::BoxType() const { return FOURCC_minf; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool MediaInformation::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->PrepareChildren() &&
|
|
|
|
buffer->ReadWriteChild(&dinf) &&
|
|
|
|
buffer->ReadWriteChild(&sample_table));
|
2015-11-23 23:12:04 +00:00
|
|
|
switch (sample_table.description.type) {
|
|
|
|
case kVideo:
|
|
|
|
RCHECK(buffer->ReadWriteChild(&vmhd));
|
|
|
|
break;
|
|
|
|
case kAudio:
|
|
|
|
RCHECK(buffer->ReadWriteChild(&smhd));
|
|
|
|
break;
|
|
|
|
case kText:
|
2016-02-03 23:58:35 +00:00
|
|
|
RCHECK(buffer->TryReadWriteChild(&sthd));
|
2015-11-23 23:12:04 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
}
|
2013-11-27 01:52:13 +00:00
|
|
|
// Hint is not supported for now.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t MediaInformation::ComputeSizeInternal() {
|
|
|
|
size_t box_size =
|
2015-12-15 00:07:51 +00:00
|
|
|
HeaderSize() + dinf.ComputeSize() + sample_table.ComputeSize();
|
2015-11-23 23:12:04 +00:00
|
|
|
switch (sample_table.description.type) {
|
|
|
|
case kVideo:
|
|
|
|
box_size += vmhd.ComputeSize();
|
|
|
|
break;
|
|
|
|
case kAudio:
|
|
|
|
box_size += smhd.ComputeSize();
|
|
|
|
break;
|
|
|
|
case kText:
|
|
|
|
box_size += sthd.ComputeSize();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NOTIMPLEMENTED();
|
|
|
|
}
|
2015-12-15 00:07:51 +00:00
|
|
|
return box_size;
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Media::Media() {}
|
|
|
|
Media::~Media() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC Media::BoxType() const { return FOURCC_mdia; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool Media::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->PrepareChildren() &&
|
2015-12-21 23:10:17 +00:00
|
|
|
buffer->ReadWriteChild(&header));
|
2013-11-27 01:52:13 +00:00
|
|
|
if (buffer->Reading()) {
|
2015-12-21 23:10:17 +00:00
|
|
|
RCHECK(buffer->ReadWriteChild(&handler));
|
2013-11-27 01:52:13 +00:00
|
|
|
// Maddeningly, the HandlerReference box specifies how to parse the
|
|
|
|
// SampleDescription box, making the latter the only box (of those that we
|
|
|
|
// support) which cannot be parsed correctly on its own (or even with
|
|
|
|
// information from its strict ancestor tree). We thus copy the handler type
|
|
|
|
// to the sample description box *before* parsing it to provide this
|
|
|
|
// information while parsing.
|
2015-12-21 23:10:17 +00:00
|
|
|
information.sample_table.description.type =
|
|
|
|
FourCCToTrackType(handler.handler_type);
|
2013-11-27 01:52:13 +00:00
|
|
|
} else {
|
2015-12-21 23:10:17 +00:00
|
|
|
handler.handler_type =
|
|
|
|
TrackTypeToFourCC(information.sample_table.description.type);
|
|
|
|
RCHECK(handler.handler_type != FOURCC_NULL);
|
|
|
|
RCHECK(buffer->ReadWriteChild(&handler));
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
RCHECK(buffer->ReadWriteChild(&information));
|
2013-09-24 01:35:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t Media::ComputeSizeInternal() {
|
2015-12-21 23:10:17 +00:00
|
|
|
handler.handler_type =
|
|
|
|
TrackTypeToFourCC(information.sample_table.description.type);
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + header.ComputeSize() + handler.ComputeSize() +
|
|
|
|
information.ComputeSize();
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
Track::Track() {}
|
|
|
|
Track::~Track() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC Track::BoxType() const { return FOURCC_trak; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool Track::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->PrepareChildren() &&
|
|
|
|
buffer->ReadWriteChild(&header) &&
|
|
|
|
buffer->ReadWriteChild(&media) &&
|
2015-12-21 18:34:21 +00:00
|
|
|
buffer->TryReadWriteChild(&edit) &&
|
|
|
|
buffer->TryReadWriteChild(&sample_encryption));
|
2013-09-24 01:35:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t Track::ComputeSizeInternal() {
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + header.ComputeSize() + media.ComputeSize() +
|
|
|
|
edit.ComputeSize();
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
MovieExtendsHeader::MovieExtendsHeader() : fragment_duration(0) {}
|
|
|
|
MovieExtendsHeader::~MovieExtendsHeader() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC MovieExtendsHeader::BoxType() const { return FOURCC_mehd; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool MovieExtendsHeader::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
2014-09-30 21:52:21 +00:00
|
|
|
size_t num_bytes = (version == 1) ? sizeof(uint64_t) : sizeof(uint32_t);
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt64NBytes(&fragment_duration, num_bytes));
|
2013-09-24 01:35:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t MovieExtendsHeader::ComputeSizeInternal() {
|
2013-11-27 01:52:13 +00:00
|
|
|
// This box is optional. Skip it if it is not used.
|
2015-12-15 00:07:51 +00:00
|
|
|
if (fragment_duration == 0)
|
|
|
|
return 0;
|
|
|
|
version = IsFitIn32Bits(fragment_duration) ? 0 : 1;
|
|
|
|
return HeaderSize() + sizeof(uint32_t) * (1 + version);
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
TrackExtends::TrackExtends()
|
|
|
|
: track_id(0),
|
|
|
|
default_sample_description_index(0),
|
|
|
|
default_sample_duration(0),
|
|
|
|
default_sample_size(0),
|
|
|
|
default_sample_flags(0) {}
|
|
|
|
TrackExtends::~TrackExtends() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC TrackExtends::BoxType() const { return FOURCC_trex; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool TrackExtends::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->ReadWriteUInt32(&track_id) &&
|
|
|
|
buffer->ReadWriteUInt32(&default_sample_description_index) &&
|
|
|
|
buffer->ReadWriteUInt32(&default_sample_duration) &&
|
|
|
|
buffer->ReadWriteUInt32(&default_sample_size) &&
|
|
|
|
buffer->ReadWriteUInt32(&default_sample_flags));
|
2013-09-24 01:35:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t TrackExtends::ComputeSizeInternal() {
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + sizeof(track_id) +
|
|
|
|
sizeof(default_sample_description_index) +
|
|
|
|
sizeof(default_sample_duration) + sizeof(default_sample_size) +
|
|
|
|
sizeof(default_sample_flags);
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
MovieExtends::MovieExtends() {}
|
|
|
|
MovieExtends::~MovieExtends() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC MovieExtends::BoxType() const { return FOURCC_mvex; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool MovieExtends::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->PrepareChildren() &&
|
|
|
|
buffer->TryReadWriteChild(&header));
|
|
|
|
if (buffer->Reading()) {
|
|
|
|
DCHECK(buffer->reader());
|
|
|
|
RCHECK(buffer->reader()->ReadChildren(&tracks));
|
|
|
|
} else {
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < tracks.size(); ++i)
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(buffer->ReadWriteChild(&tracks[i]));
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
return true;
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t MovieExtends::ComputeSizeInternal() {
|
2013-11-27 01:52:13 +00:00
|
|
|
// This box is optional. Skip it if it does not contain any track.
|
2015-12-15 00:07:51 +00:00
|
|
|
if (tracks.size() == 0)
|
|
|
|
return 0;
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t box_size = HeaderSize() + header.ComputeSize();
|
2015-12-15 00:07:51 +00:00
|
|
|
for (uint32_t i = 0; i < tracks.size(); ++i)
|
|
|
|
box_size += tracks[i].ComputeSize();
|
|
|
|
return box_size;
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Movie::Movie() {}
|
2013-09-24 01:35:40 +00:00
|
|
|
Movie::~Movie() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC Movie::BoxType() const { return FOURCC_moov; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool Movie::ReadWriteInternal(BoxBuffer* buffer) {
|
2018-03-01 16:18:22 +00:00
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) && buffer->PrepareChildren() &&
|
|
|
|
buffer->ReadWriteChild(&header));
|
2013-11-27 01:52:13 +00:00
|
|
|
if (buffer->Reading()) {
|
|
|
|
BoxReader* reader = buffer->reader();
|
|
|
|
DCHECK(reader);
|
2018-03-01 16:18:22 +00:00
|
|
|
RCHECK(reader->ReadChildren(&tracks) && reader->TryReadChild(&extends) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
reader->TryReadChildren(&pssh));
|
|
|
|
} else {
|
2018-03-01 16:18:22 +00:00
|
|
|
// The 'meta' box is not well formed in the video captured by Android's
|
|
|
|
// default camera app: spec indicates that it is a FullBox but it is written
|
|
|
|
// as a Box. This results in the box failed to be parsed. See
|
|
|
|
// https://github.com/google/shaka-packager/issues/319 for details.
|
|
|
|
// We do not care the content of metadata box in the source content, so just
|
|
|
|
// skip reading the box.
|
|
|
|
RCHECK(buffer->TryReadWriteChild(&metadata));
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < tracks.size(); ++i)
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(buffer->ReadWriteChild(&tracks[i]));
|
2017-03-15 19:42:00 +00:00
|
|
|
RCHECK(buffer->TryReadWriteChild(&extends));
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < pssh.size(); ++i)
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(buffer->ReadWriteChild(&pssh[i]));
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t Movie::ComputeSizeInternal() {
|
|
|
|
size_t box_size = HeaderSize() + header.ComputeSize() +
|
|
|
|
metadata.ComputeSize() + extends.ComputeSize();
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < tracks.size(); ++i)
|
2015-12-15 00:07:51 +00:00
|
|
|
box_size += tracks[i].ComputeSize();
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < pssh.size(); ++i)
|
2015-12-15 00:07:51 +00:00
|
|
|
box_size += pssh[i].ComputeSize();
|
|
|
|
return box_size;
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TrackFragmentDecodeTime::TrackFragmentDecodeTime() : decode_time(0) {}
|
|
|
|
TrackFragmentDecodeTime::~TrackFragmentDecodeTime() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC TrackFragmentDecodeTime::BoxType() const { return FOURCC_tfdt; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool TrackFragmentDecodeTime::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
2014-09-30 21:52:21 +00:00
|
|
|
size_t num_bytes = (version == 1) ? sizeof(uint64_t) : sizeof(uint32_t);
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt64NBytes(&decode_time, num_bytes));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t TrackFragmentDecodeTime::ComputeSizeInternal() {
|
2013-11-27 01:52:13 +00:00
|
|
|
version = IsFitIn32Bits(decode_time) ? 0 : 1;
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + sizeof(uint32_t) * (1 + version);
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MovieFragmentHeader::MovieFragmentHeader() : sequence_number(0) {}
|
|
|
|
MovieFragmentHeader::~MovieFragmentHeader() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC MovieFragmentHeader::BoxType() const { return FOURCC_mfhd; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool MovieFragmentHeader::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
return ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->ReadWriteUInt32(&sequence_number);
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t MovieFragmentHeader::ComputeSizeInternal() {
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + sizeof(sequence_number);
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TrackFragmentHeader::TrackFragmentHeader()
|
|
|
|
: track_id(0),
|
|
|
|
sample_description_index(0),
|
|
|
|
default_sample_duration(0),
|
|
|
|
default_sample_size(0),
|
2013-11-27 01:52:13 +00:00
|
|
|
default_sample_flags(0) {}
|
2013-09-24 01:35:40 +00:00
|
|
|
|
|
|
|
TrackFragmentHeader::~TrackFragmentHeader() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC TrackFragmentHeader::BoxType() const { return FOURCC_tfhd; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool TrackFragmentHeader::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->ReadWriteUInt32(&track_id));
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-01-31 01:03:38 +00:00
|
|
|
if (flags & kBaseDataOffsetPresentMask) {
|
|
|
|
// MSE requires 'default-base-is-moof' to be set and
|
|
|
|
// 'base-data-offset-present' not to be set. We omit these checks as some
|
|
|
|
// valid files in the wild don't follow these rules, though they use moof as
|
|
|
|
// base.
|
|
|
|
uint64_t base_data_offset;
|
|
|
|
RCHECK(buffer->ReadWriteUInt64(&base_data_offset));
|
|
|
|
DLOG(WARNING) << "base-data-offset-present is not expected. Assumes "
|
|
|
|
"default-base-is-moof.";
|
2014-03-26 22:09:43 +00:00
|
|
|
}
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2013-11-27 01:52:13 +00:00
|
|
|
if (flags & kSampleDescriptionIndexPresentMask) {
|
|
|
|
RCHECK(buffer->ReadWriteUInt32(&sample_description_index));
|
|
|
|
} else if (buffer->Reading()) {
|
2013-09-24 01:35:40 +00:00
|
|
|
sample_description_index = 0;
|
|
|
|
}
|
|
|
|
|
2013-11-27 01:52:13 +00:00
|
|
|
if (flags & kDefaultSampleDurationPresentMask) {
|
|
|
|
RCHECK(buffer->ReadWriteUInt32(&default_sample_duration));
|
|
|
|
} else if (buffer->Reading()) {
|
2013-09-24 01:35:40 +00:00
|
|
|
default_sample_duration = 0;
|
|
|
|
}
|
|
|
|
|
2013-11-27 01:52:13 +00:00
|
|
|
if (flags & kDefaultSampleSizePresentMask) {
|
|
|
|
RCHECK(buffer->ReadWriteUInt32(&default_sample_size));
|
|
|
|
} else if (buffer->Reading()) {
|
2013-09-24 01:35:40 +00:00
|
|
|
default_sample_size = 0;
|
|
|
|
}
|
|
|
|
|
2013-11-27 01:52:13 +00:00
|
|
|
if (flags & kDefaultSampleFlagsPresentMask)
|
|
|
|
RCHECK(buffer->ReadWriteUInt32(&default_sample_flags));
|
2013-09-24 01:35:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t TrackFragmentHeader::ComputeSizeInternal() {
|
|
|
|
size_t box_size = HeaderSize() + sizeof(track_id);
|
2013-11-27 01:52:13 +00:00
|
|
|
if (flags & kSampleDescriptionIndexPresentMask)
|
2015-12-15 00:07:51 +00:00
|
|
|
box_size += sizeof(sample_description_index);
|
2013-11-27 01:52:13 +00:00
|
|
|
if (flags & kDefaultSampleDurationPresentMask)
|
2015-12-15 00:07:51 +00:00
|
|
|
box_size += sizeof(default_sample_duration);
|
2013-11-27 01:52:13 +00:00
|
|
|
if (flags & kDefaultSampleSizePresentMask)
|
2015-12-15 00:07:51 +00:00
|
|
|
box_size += sizeof(default_sample_size);
|
2013-11-27 01:52:13 +00:00
|
|
|
if (flags & kDefaultSampleFlagsPresentMask)
|
2015-12-15 00:07:51 +00:00
|
|
|
box_size += sizeof(default_sample_flags);
|
|
|
|
return box_size;
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TrackFragmentRun::TrackFragmentRun() : sample_count(0), data_offset(0) {}
|
2013-09-24 01:35:40 +00:00
|
|
|
TrackFragmentRun::~TrackFragmentRun() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC TrackFragmentRun::BoxType() const { return FOURCC_trun; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool TrackFragmentRun::ReadWriteInternal(BoxBuffer* buffer) {
|
2015-08-04 21:11:15 +00:00
|
|
|
if (!buffer->Reading()) {
|
|
|
|
// Determine whether version 0 or version 1 should be used.
|
|
|
|
// Use version 0 if possible, use version 1 if there is a negative
|
|
|
|
// sample_offset value.
|
|
|
|
version = 0;
|
|
|
|
if (flags & kSampleCompTimeOffsetsPresentMask) {
|
|
|
|
for (uint32_t i = 0; i < sample_count; ++i) {
|
|
|
|
if (sample_composition_time_offsets[i] < 0) {
|
|
|
|
version = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->ReadWriteUInt32(&sample_count));
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2013-11-27 01:52:13 +00:00
|
|
|
bool data_offset_present = (flags & kDataOffsetPresentMask) != 0;
|
|
|
|
bool first_sample_flags_present = (flags & kFirstSampleFlagsPresentMask) != 0;
|
|
|
|
bool sample_duration_present = (flags & kSampleDurationPresentMask) != 0;
|
|
|
|
bool sample_size_present = (flags & kSampleSizePresentMask) != 0;
|
|
|
|
bool sample_flags_present = (flags & kSampleFlagsPresentMask) != 0;
|
|
|
|
bool sample_composition_time_offsets_present =
|
|
|
|
(flags & kSampleCompTimeOffsetsPresentMask) != 0;
|
2013-09-24 01:35:40 +00:00
|
|
|
|
|
|
|
if (data_offset_present) {
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt32(&data_offset));
|
2013-09-24 01:35:40 +00:00
|
|
|
} else {
|
2014-03-26 22:09:43 +00:00
|
|
|
// NOTE: If the data-offset is not present, then the data for this run
|
2014-03-19 00:09:50 +00:00
|
|
|
// starts immediately after the data of the previous run, or at the
|
|
|
|
// base-data-offset defined by the track fragment header if this is the
|
|
|
|
// first run in a track fragment. If the data-offset is present, it is
|
|
|
|
// relative to the base-data-offset established in the track fragment
|
|
|
|
// header.
|
2013-11-27 01:52:13 +00:00
|
|
|
NOTIMPLEMENTED();
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
|
2016-08-14 22:28:21 +00:00
|
|
|
uint32_t first_sample_flags(0);
|
2013-11-27 01:52:13 +00:00
|
|
|
|
|
|
|
if (buffer->Reading()) {
|
|
|
|
if (first_sample_flags_present)
|
|
|
|
RCHECK(buffer->ReadWriteUInt32(&first_sample_flags));
|
|
|
|
|
|
|
|
if (sample_duration_present)
|
|
|
|
sample_durations.resize(sample_count);
|
|
|
|
if (sample_size_present)
|
|
|
|
sample_sizes.resize(sample_count);
|
|
|
|
if (sample_flags_present)
|
|
|
|
sample_flags.resize(sample_count);
|
|
|
|
if (sample_composition_time_offsets_present)
|
|
|
|
sample_composition_time_offsets.resize(sample_count);
|
|
|
|
} else {
|
|
|
|
if (first_sample_flags_present) {
|
|
|
|
first_sample_flags = sample_flags[0];
|
|
|
|
DCHECK(sample_flags.size() == 1);
|
|
|
|
RCHECK(buffer->ReadWriteUInt32(&first_sample_flags));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sample_duration_present)
|
|
|
|
DCHECK(sample_durations.size() == sample_count);
|
|
|
|
if (sample_size_present)
|
|
|
|
DCHECK(sample_sizes.size() == sample_count);
|
|
|
|
if (sample_flags_present)
|
|
|
|
DCHECK(sample_flags.size() == sample_count);
|
|
|
|
if (sample_composition_time_offsets_present)
|
|
|
|
DCHECK(sample_composition_time_offsets.size() == sample_count);
|
|
|
|
}
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < sample_count; ++i) {
|
2013-09-24 01:35:40 +00:00
|
|
|
if (sample_duration_present)
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt32(&sample_durations[i]));
|
2013-09-24 01:35:40 +00:00
|
|
|
if (sample_size_present)
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt32(&sample_sizes[i]));
|
2013-09-24 01:35:40 +00:00
|
|
|
if (sample_flags_present)
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->ReadWriteUInt32(&sample_flags[i]));
|
2015-08-04 21:11:15 +00:00
|
|
|
|
|
|
|
if (sample_composition_time_offsets_present) {
|
|
|
|
if (version == 0) {
|
|
|
|
uint32_t sample_offset = sample_composition_time_offsets[i];
|
|
|
|
RCHECK(buffer->ReadWriteUInt32(&sample_offset));
|
|
|
|
sample_composition_time_offsets[i] = sample_offset;
|
|
|
|
} else {
|
|
|
|
int32_t sample_offset = sample_composition_time_offsets[i];
|
|
|
|
RCHECK(buffer->ReadWriteInt32(&sample_offset));
|
|
|
|
sample_composition_time_offsets[i] = sample_offset;
|
|
|
|
}
|
|
|
|
}
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
|
2013-11-27 01:52:13 +00:00
|
|
|
if (buffer->Reading()) {
|
|
|
|
if (first_sample_flags_present) {
|
|
|
|
if (sample_flags.size() == 0) {
|
|
|
|
sample_flags.push_back(first_sample_flags);
|
|
|
|
} else {
|
|
|
|
sample_flags[0] = first_sample_flags;
|
|
|
|
}
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t TrackFragmentRun::ComputeSizeInternal() {
|
|
|
|
size_t box_size = HeaderSize() + sizeof(sample_count);
|
2013-11-27 01:52:13 +00:00
|
|
|
if (flags & kDataOffsetPresentMask)
|
2015-12-15 00:07:51 +00:00
|
|
|
box_size += sizeof(data_offset);
|
2013-11-27 01:52:13 +00:00
|
|
|
if (flags & kFirstSampleFlagsPresentMask)
|
2015-12-15 00:07:51 +00:00
|
|
|
box_size += sizeof(uint32_t);
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t fields = (flags & kSampleDurationPresentMask ? 1 : 0) +
|
|
|
|
(flags & kSampleSizePresentMask ? 1 : 0) +
|
|
|
|
(flags & kSampleFlagsPresentMask ? 1 : 0) +
|
|
|
|
(flags & kSampleCompTimeOffsetsPresentMask ? 1 : 0);
|
2015-12-15 00:07:51 +00:00
|
|
|
box_size += fields * sizeof(uint32_t) * sample_count;
|
|
|
|
return box_size;
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2015-01-31 01:03:38 +00:00
|
|
|
TrackFragment::TrackFragment() : decode_time_absent(false) {}
|
2013-09-24 01:35:40 +00:00
|
|
|
TrackFragment::~TrackFragment() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC TrackFragment::BoxType() const { return FOURCC_traf; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool TrackFragment::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->PrepareChildren() &&
|
2015-01-31 01:03:38 +00:00
|
|
|
buffer->ReadWriteChild(&header));
|
2013-11-27 01:52:13 +00:00
|
|
|
if (buffer->Reading()) {
|
|
|
|
DCHECK(buffer->reader());
|
2015-01-31 01:03:38 +00:00
|
|
|
decode_time_absent = !buffer->reader()->ChildExist(&decode_time);
|
|
|
|
if (!decode_time_absent)
|
|
|
|
RCHECK(buffer->ReadWriteChild(&decode_time));
|
2016-05-06 23:56:50 +00:00
|
|
|
RCHECK(buffer->reader()->TryReadChildren(&runs) &&
|
|
|
|
buffer->reader()->TryReadChildren(&sample_group_descriptions) &&
|
|
|
|
buffer->reader()->TryReadChildren(&sample_to_groups));
|
2013-11-27 01:52:13 +00:00
|
|
|
} else {
|
2015-01-31 01:03:38 +00:00
|
|
|
if (!decode_time_absent)
|
|
|
|
RCHECK(buffer->ReadWriteChild(&decode_time));
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < runs.size(); ++i)
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(buffer->ReadWriteChild(&runs[i]));
|
2016-05-06 23:56:50 +00:00
|
|
|
for (uint32_t i = 0; i < sample_to_groups.size(); ++i)
|
|
|
|
RCHECK(buffer->ReadWriteChild(&sample_to_groups[i]));
|
|
|
|
for (uint32_t i = 0; i < sample_group_descriptions.size(); ++i)
|
|
|
|
RCHECK(buffer->ReadWriteChild(&sample_group_descriptions[i]));
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
return buffer->TryReadWriteChild(&auxiliary_size) &&
|
2015-12-21 18:34:21 +00:00
|
|
|
buffer->TryReadWriteChild(&auxiliary_offset) &&
|
|
|
|
buffer->TryReadWriteChild(&sample_encryption);
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t TrackFragment::ComputeSizeInternal() {
|
|
|
|
size_t box_size = HeaderSize() + header.ComputeSize() +
|
|
|
|
decode_time.ComputeSize() + auxiliary_size.ComputeSize() +
|
|
|
|
auxiliary_offset.ComputeSize() +
|
|
|
|
sample_encryption.ComputeSize();
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < runs.size(); ++i)
|
2015-12-15 00:07:51 +00:00
|
|
|
box_size += runs[i].ComputeSize();
|
2016-05-06 23:56:50 +00:00
|
|
|
for (uint32_t i = 0; i < sample_group_descriptions.size(); ++i)
|
|
|
|
box_size += sample_group_descriptions[i].ComputeSize();
|
|
|
|
for (uint32_t i = 0; i < sample_to_groups.size(); ++i)
|
|
|
|
box_size += sample_to_groups[i].ComputeSize();
|
2015-12-15 00:07:51 +00:00
|
|
|
return box_size;
|
2013-09-24 01:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MovieFragment::MovieFragment() {}
|
|
|
|
MovieFragment::~MovieFragment() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC MovieFragment::BoxType() const { return FOURCC_moof; }
|
2013-09-24 01:35:40 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool MovieFragment::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->PrepareChildren() &&
|
|
|
|
buffer->ReadWriteChild(&header));
|
|
|
|
if (buffer->Reading()) {
|
|
|
|
BoxReader* reader = buffer->reader();
|
|
|
|
DCHECK(reader);
|
|
|
|
RCHECK(reader->ReadChildren(&tracks) &&
|
|
|
|
reader->TryReadChildren(&pssh));
|
|
|
|
} else {
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < tracks.size(); ++i)
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(buffer->ReadWriteChild(&tracks[i]));
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < pssh.size(); ++i)
|
2015-12-15 00:07:51 +00:00
|
|
|
RCHECK(buffer->ReadWriteChild(&pssh[i]));
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
2013-09-24 01:35:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t MovieFragment::ComputeSizeInternal() {
|
|
|
|
size_t box_size = HeaderSize() + header.ComputeSize();
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < tracks.size(); ++i)
|
2015-12-15 00:07:51 +00:00
|
|
|
box_size += tracks[i].ComputeSize();
|
2014-09-30 21:52:21 +00:00
|
|
|
for (uint32_t i = 0; i < pssh.size(); ++i)
|
2015-12-15 00:07:51 +00:00
|
|
|
box_size += pssh[i].ComputeSize();
|
|
|
|
return box_size;
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SegmentIndex::SegmentIndex()
|
|
|
|
: reference_id(0),
|
|
|
|
timescale(0),
|
|
|
|
earliest_presentation_time(0),
|
|
|
|
first_offset(0) {}
|
|
|
|
SegmentIndex::~SegmentIndex() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC SegmentIndex::BoxType() const { return FOURCC_sidx; }
|
2013-11-27 01:52:13 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool SegmentIndex::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
2013-11-27 01:52:13 +00:00
|
|
|
buffer->ReadWriteUInt32(&reference_id) &&
|
|
|
|
buffer->ReadWriteUInt32(×cale));
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
size_t num_bytes = (version == 1) ? sizeof(uint64_t) : sizeof(uint32_t);
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(
|
|
|
|
buffer->ReadWriteUInt64NBytes(&earliest_presentation_time, num_bytes) &&
|
|
|
|
buffer->ReadWriteUInt64NBytes(&first_offset, num_bytes));
|
|
|
|
|
2016-08-14 22:28:21 +00:00
|
|
|
uint16_t reference_count = static_cast<uint16_t>(references.size());
|
2013-11-27 01:52:13 +00:00
|
|
|
RCHECK(buffer->IgnoreBytes(2) && // reserved.
|
|
|
|
buffer->ReadWriteUInt16(&reference_count));
|
|
|
|
references.resize(reference_count);
|
|
|
|
|
2014-09-30 21:52:21 +00:00
|
|
|
uint32_t reference_type_size;
|
|
|
|
uint32_t sap;
|
|
|
|
for (uint32_t i = 0; i < reference_count; ++i) {
|
2013-11-27 01:52:13 +00:00
|
|
|
if (!buffer->Reading()) {
|
|
|
|
reference_type_size = references[i].referenced_size;
|
|
|
|
if (references[i].reference_type)
|
|
|
|
reference_type_size |= (1 << 31);
|
|
|
|
sap = (references[i].sap_type << 28) | references[i].sap_delta_time;
|
|
|
|
if (references[i].starts_with_sap)
|
|
|
|
sap |= (1 << 31);
|
|
|
|
}
|
|
|
|
RCHECK(buffer->ReadWriteUInt32(&reference_type_size) &&
|
|
|
|
buffer->ReadWriteUInt32(&references[i].subsegment_duration) &&
|
|
|
|
buffer->ReadWriteUInt32(&sap));
|
|
|
|
if (buffer->Reading()) {
|
|
|
|
references[i].reference_type = (reference_type_size >> 31) ? true : false;
|
|
|
|
references[i].referenced_size = reference_type_size & ~(1 << 31);
|
|
|
|
references[i].starts_with_sap = (sap >> 31) ? true : false;
|
|
|
|
references[i].sap_type =
|
|
|
|
static_cast<SegmentReference::SAPType>((sap >> 28) & 0x07);
|
|
|
|
references[i].sap_delta_time = sap & ~(0xF << 28);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t SegmentIndex::ComputeSizeInternal() {
|
2013-11-27 01:52:13 +00:00
|
|
|
version = IsFitIn32Bits(earliest_presentation_time, first_offset) ? 0 : 1;
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + sizeof(reference_id) + sizeof(timescale) +
|
|
|
|
sizeof(uint32_t) * (1 + version) * 2 + 2 * sizeof(uint16_t) +
|
|
|
|
3 * sizeof(uint32_t) * references.size();
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MediaData::MediaData() : data_size(0) {}
|
|
|
|
MediaData::~MediaData() {}
|
2016-04-06 23:21:45 +00:00
|
|
|
FourCC MediaData::BoxType() const { return FOURCC_mdat; }
|
2013-11-27 01:52:13 +00:00
|
|
|
|
2015-12-15 00:07:51 +00:00
|
|
|
bool MediaData::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
NOTIMPLEMENTED() << "Actual data is parsed and written separately.";
|
|
|
|
return false;
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t MediaData::ComputeSizeInternal() {
|
2015-12-15 00:07:51 +00:00
|
|
|
return HeaderSize() + data_size;
|
2013-11-27 01:52:13 +00:00
|
|
|
}
|
|
|
|
|
2015-11-23 23:12:04 +00:00
|
|
|
CueSourceIDBox::CueSourceIDBox() : source_id(kCueSourceIdNotSet) {}
|
|
|
|
CueSourceIDBox::~CueSourceIDBox() {}
|
|
|
|
|
|
|
|
FourCC CueSourceIDBox::BoxType() const { return FOURCC_vsid; }
|
|
|
|
|
|
|
|
bool CueSourceIDBox::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) && buffer->ReadWriteInt32(&source_id));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t CueSourceIDBox::ComputeSizeInternal() {
|
2015-11-23 23:12:04 +00:00
|
|
|
if (source_id == kCueSourceIdNotSet)
|
|
|
|
return 0;
|
|
|
|
return HeaderSize() + sizeof(source_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
CueTimeBox::CueTimeBox() {}
|
|
|
|
CueTimeBox::~CueTimeBox() {}
|
|
|
|
|
|
|
|
FourCC CueTimeBox::BoxType() const {
|
|
|
|
return FOURCC_ctim;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CueTimeBox::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
|
|
|
return buffer->ReadWriteString(
|
|
|
|
&cue_current_time,
|
|
|
|
buffer->Reading() ? buffer->BytesLeft() : cue_current_time.size());
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t CueTimeBox::ComputeSizeInternal() {
|
2015-11-23 23:12:04 +00:00
|
|
|
if (cue_current_time.empty())
|
|
|
|
return 0;
|
|
|
|
return HeaderSize() + cue_current_time.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
CueIDBox::CueIDBox() {}
|
|
|
|
CueIDBox::~CueIDBox() {}
|
|
|
|
|
|
|
|
FourCC CueIDBox::BoxType() const {
|
|
|
|
return FOURCC_iden;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CueIDBox::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
|
|
|
return buffer->ReadWriteString(
|
|
|
|
&cue_id, buffer->Reading() ? buffer->BytesLeft() : cue_id.size());
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t CueIDBox::ComputeSizeInternal() {
|
2015-11-23 23:12:04 +00:00
|
|
|
if (cue_id.empty())
|
|
|
|
return 0;
|
|
|
|
return HeaderSize() + cue_id.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
CueSettingsBox::CueSettingsBox() {}
|
|
|
|
CueSettingsBox::~CueSettingsBox() {}
|
|
|
|
|
|
|
|
FourCC CueSettingsBox::BoxType() const {
|
|
|
|
return FOURCC_sttg;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CueSettingsBox::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
|
|
|
return buffer->ReadWriteString(
|
|
|
|
&settings, buffer->Reading() ? buffer->BytesLeft() : settings.size());
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t CueSettingsBox::ComputeSizeInternal() {
|
2015-11-23 23:12:04 +00:00
|
|
|
if (settings.empty())
|
|
|
|
return 0;
|
|
|
|
return HeaderSize() + settings.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
CuePayloadBox::CuePayloadBox() {}
|
|
|
|
CuePayloadBox::~CuePayloadBox() {}
|
|
|
|
|
|
|
|
FourCC CuePayloadBox::BoxType() const {
|
|
|
|
return FOURCC_payl;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CuePayloadBox::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
|
|
|
return buffer->ReadWriteString(
|
|
|
|
&cue_text, buffer->Reading() ? buffer->BytesLeft() : cue_text.size());
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t CuePayloadBox::ComputeSizeInternal() {
|
2015-11-23 23:12:04 +00:00
|
|
|
return HeaderSize() + cue_text.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
VTTEmptyCueBox::VTTEmptyCueBox() {}
|
|
|
|
VTTEmptyCueBox::~VTTEmptyCueBox() {}
|
|
|
|
|
|
|
|
FourCC VTTEmptyCueBox::BoxType() const {
|
|
|
|
return FOURCC_vtte;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VTTEmptyCueBox::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
return ReadWriteHeaderInternal(buffer);
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t VTTEmptyCueBox::ComputeSizeInternal() {
|
2015-11-23 23:12:04 +00:00
|
|
|
return HeaderSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
VTTAdditionalTextBox::VTTAdditionalTextBox() {}
|
|
|
|
VTTAdditionalTextBox::~VTTAdditionalTextBox() {}
|
|
|
|
|
|
|
|
FourCC VTTAdditionalTextBox::BoxType() const {
|
|
|
|
return FOURCC_vtta;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VTTAdditionalTextBox::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer));
|
|
|
|
return buffer->ReadWriteString(
|
|
|
|
&cue_additional_text,
|
|
|
|
buffer->Reading() ? buffer->BytesLeft() : cue_additional_text.size());
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t VTTAdditionalTextBox::ComputeSizeInternal() {
|
2015-11-23 23:12:04 +00:00
|
|
|
return HeaderSize() + cue_additional_text.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
VTTCueBox::VTTCueBox() {}
|
|
|
|
VTTCueBox::~VTTCueBox() {}
|
|
|
|
|
|
|
|
FourCC VTTCueBox::BoxType() const {
|
|
|
|
return FOURCC_vttc;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VTTCueBox::ReadWriteInternal(BoxBuffer* buffer) {
|
|
|
|
RCHECK(ReadWriteHeaderInternal(buffer) &&
|
|
|
|
buffer->PrepareChildren() &&
|
2015-11-23 23:12:04 +00:00
|
|
|
buffer->TryReadWriteChild(&cue_source_id) &&
|
|
|
|
buffer->TryReadWriteChild(&cue_id) &&
|
|
|
|
buffer->TryReadWriteChild(&cue_time) &&
|
|
|
|
buffer->TryReadWriteChild(&cue_settings) &&
|
2015-11-23 23:12:04 +00:00
|
|
|
buffer->ReadWriteChild(&cue_payload));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-09 02:11:13 +00:00
|
|
|
size_t VTTCueBox::ComputeSizeInternal() {
|
2015-11-23 23:12:04 +00:00
|
|
|
return HeaderSize() + cue_source_id.ComputeSize() + cue_id.ComputeSize() +
|
|
|
|
cue_time.ComputeSize() + cue_settings.ComputeSize() +
|
|
|
|
cue_payload.ComputeSize();
|
|
|
|
}
|
|
|
|
|
2013-09-24 01:35:40 +00:00
|
|
|
} // namespace mp4
|
|
|
|
} // namespace media
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|