Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/mp4/SinfParser.cpp
Line
Count
Source (jump to first uncovered line)
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 "SinfParser.h"
7
#include "AtomType.h"
8
#include "Box.h"
9
#include "ByteStream.h"
10
11
namespace mozilla {
12
13
Sinf::Sinf(Box& aBox)
14
  : mDefaultIVSize(0)
15
  , mDefaultEncryptionType()
16
0
{
17
0
  SinfParser parser(aBox);
18
0
  if (parser.GetSinf().IsValid()) {
19
0
    *this = parser.GetSinf();
20
0
  }
21
0
}
22
23
SinfParser::SinfParser(Box& aBox)
24
0
{
25
0
  for (Box box = aBox.FirstChild(); box.IsAvailable(); box = box.Next()) {
26
0
    if (box.IsType("schm")) {
27
0
      mozilla::Unused << ParseSchm(box);
28
0
    } else if (box.IsType("schi")) {
29
0
      mozilla::Unused << ParseSchi(box);
30
0
    }
31
0
  }
32
0
}
33
34
Result<Ok, nsresult>
35
SinfParser::ParseSchm(Box& aBox)
36
0
{
37
0
  BoxReader reader(aBox);
38
0
39
0
  if (reader->Remaining() < 8) {
40
0
    return Err(NS_ERROR_FAILURE);
41
0
  }
42
0
43
0
  MOZ_TRY(reader->ReadU32()); // flags -- ignore
44
0
  MOZ_TRY_VAR(mSinf.mDefaultEncryptionType, reader->ReadU32());
45
0
  return Ok();
46
0
}
47
48
Result<Ok, nsresult>
49
SinfParser::ParseSchi(Box& aBox)
50
0
{
51
0
  for (Box box = aBox.FirstChild(); box.IsAvailable(); box = box.Next()) {
52
0
    if (box.IsType("tenc") && ParseTenc(box).isErr()) {
53
0
      return Err(NS_ERROR_FAILURE);
54
0
    }
55
0
  }
56
0
  return Ok();
57
0
}
58
59
Result<Ok, nsresult>
60
SinfParser::ParseTenc(Box& aBox)
61
0
{
62
0
  BoxReader reader(aBox);
63
0
64
0
  if (reader->Remaining() < 24) {
65
0
    return Err(NS_ERROR_FAILURE);
66
0
  }
67
0
68
0
  MOZ_TRY(reader->ReadU32()); // flags -- ignore
69
0
70
0
  uint32_t isEncrypted;
71
0
  MOZ_TRY_VAR(isEncrypted, reader->ReadU24());
72
0
  MOZ_TRY_VAR(mSinf.mDefaultIVSize, reader->ReadU8());
73
0
  memcpy(mSinf.mDefaultKeyID, reader->Read(16), 16);
74
0
  return Ok();
75
0
}
76
77
}