Roll src/third_party/WebKit 2dc4bc6:34469ea (svn 182261:182277)
[chromium-blink-merge.git] / media / formats / mp4 / cenc.cc
blob001b6d881611dc882d87fd2e1737886f3606054f
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "media/formats/mp4/cenc.h"
7 #include <cstring>
9 #include "media/formats/mp4/box_reader.h"
10 #include "media/formats/mp4/rcheck.h"
12 namespace media {
13 namespace mp4 {
15 FrameCENCInfo::FrameCENCInfo() {}
16 FrameCENCInfo::~FrameCENCInfo() {}
18 bool FrameCENCInfo::Parse(int iv_size, BufferReader* reader) {
19 const int kEntrySize = 6;
20 // Mandated by CENC spec
21 RCHECK(iv_size == 8 || iv_size == 16);
23 memset(iv, 0, sizeof(iv));
24 for (int i = 0; i < iv_size; i++)
25 RCHECK(reader->Read1(&iv[i]));
27 if (!reader->HasBytes(1)) return true;
29 uint16 subsample_count;
30 RCHECK(reader->Read2(&subsample_count) &&
31 reader->HasBytes(subsample_count * kEntrySize));
33 subsamples.resize(subsample_count);
34 for (int i = 0; i < subsample_count; i++) {
35 uint16 clear_bytes;
36 uint32 cypher_bytes;
37 RCHECK(reader->Read2(&clear_bytes) &&
38 reader->Read4(&cypher_bytes));
39 subsamples[i].clear_bytes = clear_bytes;
40 subsamples[i].cypher_bytes = cypher_bytes;
42 return true;
45 bool FrameCENCInfo::GetTotalSizeOfSubsamples(size_t* total_size) const {
46 size_t size = 0;
47 for (size_t i = 0; i < subsamples.size(); i++) {
48 size += subsamples[i].clear_bytes;
49 RCHECK(size >= subsamples[i].clear_bytes); // overflow
50 size += subsamples[i].cypher_bytes;
51 RCHECK(size >= subsamples[i].cypher_bytes); // overflow
53 *total_size = size;
54 return true;
57 } // namespace mp4
58 } // namespace media