Line data Source code
1 : /* This Source Code Form is subject to the terms of the Mozilla Public
2 : * License, v. 2.0. If a copy of the MPL was not distributed with this
3 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 :
5 : #include "mozilla/Unused.h"
6 : #include "mp4_demuxer/SinfParser.h"
7 : #include "mp4_demuxer/AtomType.h"
8 : #include "mp4_demuxer/Box.h"
9 :
10 : namespace mp4_demuxer {
11 :
12 0 : Sinf::Sinf(Box& aBox)
13 : : mDefaultIVSize(0)
14 0 : , mDefaultEncryptionType()
15 : {
16 0 : SinfParser parser(aBox);
17 0 : if (parser.GetSinf().IsValid()) {
18 0 : *this = parser.GetSinf();
19 : }
20 0 : }
21 :
22 0 : SinfParser::SinfParser(Box& aBox)
23 : {
24 0 : for (Box box = aBox.FirstChild(); box.IsAvailable(); box = box.Next()) {
25 0 : if (box.IsType("schm")) {
26 0 : ParseSchm(box);
27 0 : } else if (box.IsType("schi")) {
28 0 : ParseSchi(box);
29 : }
30 : }
31 0 : }
32 :
33 : void
34 0 : SinfParser::ParseSchm(Box& aBox)
35 : {
36 0 : BoxReader reader(aBox);
37 :
38 0 : if (reader->Remaining() < 8) {
39 0 : return;
40 : }
41 :
42 0 : mozilla::Unused << reader->ReadU32(); // flags -- ignore
43 0 : mSinf.mDefaultEncryptionType = reader->ReadU32();
44 : }
45 :
46 : void
47 0 : SinfParser::ParseSchi(Box& aBox)
48 : {
49 0 : for (Box box = aBox.FirstChild(); box.IsAvailable(); box = box.Next()) {
50 0 : if (box.IsType("tenc")) {
51 0 : ParseTenc(box);
52 : }
53 : }
54 0 : }
55 :
56 : void
57 0 : SinfParser::ParseTenc(Box& aBox)
58 : {
59 0 : BoxReader reader(aBox);
60 :
61 0 : if (reader->Remaining() < 24) {
62 0 : return;
63 : }
64 :
65 0 : mozilla::Unused << reader->ReadU32(); // flags -- ignore
66 :
67 0 : uint32_t isEncrypted = reader->ReadU24();
68 0 : mSinf.mDefaultIVSize = reader->ReadU8();
69 0 : memcpy(mSinf.mDefaultKeyID, reader->Read(16), 16);
70 : }
71 :
72 : }
|