5 #include "packager/media/formats/mp4/cenc.h"
9 #include "packager/media/base/buffer_reader.h"
10 #include "packager/media/base/buffer_writer.h"
11 #include "packager/media/formats/mp4/rcheck.h"
16 bool IsIvSizeValid(
size_t iv_size) {
return iv_size == 8 || iv_size == 16; }
19 const size_t kSubsampleEntrySize =
sizeof(uint16_t) +
sizeof(uint32_t);
22 namespace edash_packager {
26 FrameCENCInfo::FrameCENCInfo() {}
27 FrameCENCInfo::FrameCENCInfo(
const std::vector<uint8_t>& iv) : iv_(iv) {
29 FrameCENCInfo::~FrameCENCInfo() {}
31 bool FrameCENCInfo::Parse(uint8_t iv_size, BufferReader* reader) {
34 RCHECK(IsIvSizeValid(iv_size));
37 RCHECK(reader->ReadToVector(&iv_, iv_size));
39 if (!reader->HasBytes(1))
42 uint16_t subsample_count;
43 RCHECK(reader->Read2(&subsample_count) &&
44 reader->HasBytes(subsample_count * kSubsampleEntrySize));
46 subsamples_.resize(subsample_count);
47 for (uint16_t i = 0; i < subsample_count; ++i) {
49 uint32_t cipher_bytes;
50 RCHECK(reader->Read2(&clear_bytes) &&
51 reader->Read4(&cipher_bytes));
52 subsamples_[i].clear_bytes = clear_bytes;
53 subsamples_[i].cipher_bytes = cipher_bytes;
58 void FrameCENCInfo::Write(BufferWriter* writer)
const {
60 DCHECK(IsIvSizeValid(iv_.size()));
61 writer->AppendVector(iv_);
63 uint16_t subsample_count = subsamples_.size();
64 if (subsample_count == 0)
66 writer->AppendInt(subsample_count);
68 for (uint16_t i = 0; i < subsample_count; ++i) {
69 writer->AppendInt(subsamples_[i].clear_bytes);
70 writer->AppendInt(subsamples_[i].cipher_bytes);
74 size_t FrameCENCInfo::ComputeSize()
const {
75 uint16_t subsample_count = subsamples_.size();
76 if (subsample_count == 0)
79 return iv_.size() +
sizeof(subsample_count) +
80 subsample_count * kSubsampleEntrySize;
83 size_t FrameCENCInfo::GetTotalSizeOfSubsamples()
const {
85 for (
size_t i = 0; i < subsamples_.size(); ++i) {
86 size += subsamples_[i].clear_bytes + subsamples_[i].cipher_bytes;