Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/mp4/Box.h
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim:set ts=2 sw=2 sts=2 et cindent: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
 * License, v. 2.0. If a copy of the MPL was not distributed with this
5
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef BOX_H_
8
#define BOX_H_
9
10
#include <stdint.h>
11
#include "nsTArray.h"
12
#include "MediaResource.h"
13
#include "mozilla/EndianUtils.h"
14
#include "AtomType.h"
15
#include "BufferReader.h"
16
17
namespace mozilla {
18
class ByteStream;
19
20
class BoxContext
21
{
22
public:
23
  BoxContext(ByteStream* aSource, const MediaByteRangeSet& aByteRanges)
24
    : mSource(aSource), mByteRanges(aByteRanges)
25
0
  {
26
0
  }
27
28
  RefPtr<ByteStream> mSource;
29
  const MediaByteRangeSet& mByteRanges;
30
};
31
32
class Box
33
{
34
public:
35
  Box(BoxContext* aContext, uint64_t aOffset, const Box* aParent = nullptr);
36
  Box();
37
38
0
  bool IsAvailable() const { return !mRange.IsEmpty(); }
39
0
  uint64_t Offset() const { return mRange.mStart; }
40
0
  uint64_t Length() const { return mRange.mEnd - mRange.mStart; }
41
0
  uint64_t NextOffset() const { return mRange.mEnd; }
42
0
  const MediaByteRange& Range() const { return mRange; }
43
0
  const Box* Parent() const { return mParent; }
44
0
  bool IsType(const char* aType) const { return mType == AtomType(aType); }
45
46
  Box Next() const;
47
  Box FirstChild() const;
48
  nsTArray<uint8_t> Read() const;
49
  bool Read(nsTArray<uint8_t>* aDest, const MediaByteRange& aRange) const;
50
51
  static const uint64_t kMAX_BOX_READ;
52
53
0
  const nsTArray<uint8_t>& Header() const { return mHeader; }
54
55
private:
56
  bool Contains(MediaByteRange aRange) const;
57
  BoxContext* mContext;
58
  mozilla::MediaByteRange mRange;
59
  uint64_t mBodyOffset;
60
  uint64_t mChildOffset;
61
  AtomType mType;
62
  nsTArray<uint8_t> mHeader;
63
  const Box* mParent;
64
};
65
66
// BoxReader takes a copy of a box contents and serves through an AutoByteReader.
67
class MOZ_RAII BoxReader
68
{
69
public:
70
  explicit BoxReader(Box& aBox)
71
    : mBuffer(aBox.Read())
72
    , mReader(mBuffer.Elements(), mBuffer.Length())
73
0
  {
74
0
  }
75
0
  BufferReader* operator->() { return &mReader; }
76
77
private:
78
  nsTArray<uint8_t> mBuffer;
79
  BufferReader mReader;
80
};
81
}
82
83
#endif