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"
9 #include "media/formats/mp4/box_reader.h"
10 #include "media/formats/mp4/rcheck.h"
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
++) {
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
;
45 bool FrameCENCInfo::GetTotalSizeOfSubsamples(size_t* total_size
) const {
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