Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/media/mp4/Index.h
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
#ifndef INDEX_H_
6
#define INDEX_H_
7
8
#include "MediaData.h"
9
#include "MediaResource.h"
10
#include "TimeUnits.h"
11
#include "MoofParser.h"
12
#include "MP4Interval.h"
13
#include "ByteStream.h"
14
#include "nsISupportsImpl.h"
15
16
template<class T> class nsAutoPtr;
17
18
namespace mozilla
19
{
20
class IndiceWrapper;
21
struct Sample;
22
struct CencSampleEncryptionInfoEntry;
23
24
class Index;
25
26
typedef int64_t Microseconds;
27
28
class SampleIterator
29
{
30
public:
31
  explicit SampleIterator(Index* aIndex);
32
  ~SampleIterator();
33
  already_AddRefed<mozilla::MediaRawData> GetNext();
34
  void Seek(Microseconds aTime);
35
  Microseconds GetNextKeyframeTime();
36
private:
37
  Sample* Get();
38
39
  CencSampleEncryptionInfoEntry* GetSampleEncryptionEntry();
40
41
  void Next();
42
  RefPtr<Index> mIndex;
43
  friend class Index;
44
  size_t mCurrentMoof;
45
  size_t mCurrentSample;
46
};
47
48
class Index
49
{
50
public:
51
  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Index)
52
53
  struct Indice
54
  {
55
    uint64_t start_offset;
56
    uint64_t end_offset;
57
    uint64_t start_composition;
58
    uint64_t end_composition;
59
    uint64_t start_decode;
60
    bool sync;
61
  };
62
63
  struct MP4DataOffset
64
  {
65
    MP4DataOffset(uint32_t aIndex, int64_t aStartOffset)
66
      : mIndex(aIndex)
67
      , mStartOffset(aStartOffset)
68
      , mEndOffset(0)
69
0
    {}
70
71
0
    bool operator==(int64_t aStartOffset) const {
72
0
      return mStartOffset == aStartOffset;
73
0
    }
74
75
    bool operator!=(int64_t aStartOffset) const {
76
      return mStartOffset != aStartOffset;
77
    }
78
79
0
    bool operator<(int64_t aStartOffset) const {
80
0
      return mStartOffset < aStartOffset;
81
0
    }
82
83
    struct EndOffsetComparator {
84
0
      bool Equals(const MP4DataOffset& a, const int64_t& b) const {
85
0
        return a.mEndOffset == b;
86
0
      }
87
88
0
      bool LessThan(const MP4DataOffset& a, const int64_t& b) const {
89
0
        return a.mEndOffset < b;
90
0
      }
91
    };
92
93
    uint32_t mIndex;
94
    int64_t mStartOffset;
95
    int64_t mEndOffset;
96
    MP4Interval<Microseconds> mTime;
97
  };
98
99
  Index(const mozilla::IndiceWrapper& aIndices,
100
        ByteStream* aSource,
101
        uint32_t aTrackId,
102
        bool aIsAudio);
103
104
  void UpdateMoofIndex(const mozilla::MediaByteRangeSet& aByteRanges,
105
                       bool aCanEvict);
106
  void UpdateMoofIndex(const mozilla::MediaByteRangeSet& aByteRanges);
107
  Microseconds GetEndCompositionIfBuffered(
108
    const mozilla::MediaByteRangeSet& aByteRanges);
109
  mozilla::media::TimeIntervals ConvertByteRangesToTimeRanges(
110
    const mozilla::MediaByteRangeSet& aByteRanges);
111
  uint64_t GetEvictionOffset(Microseconds aTime);
112
  bool IsFragmented() { return mMoofParser; }
113
114
  friend class SampleIterator;
115
116
private:
117
  ~Index();
118
  void RegisterIterator(SampleIterator* aIterator);
119
  void UnregisterIterator(SampleIterator* aIterator);
120
121
  ByteStream* mSource;
122
  FallibleTArray<Sample> mIndex;
123
  FallibleTArray<MP4DataOffset> mDataOffset;
124
  nsAutoPtr<MoofParser> mMoofParser;
125
  nsTArray<SampleIterator*> mIterators;
126
127
  // ConvertByteRangesToTimeRanges cache
128
  mozilla::MediaByteRangeSet mLastCachedRanges;
129
  mozilla::media::TimeIntervals mLastBufferedRanges;
130
  bool mIsAudio;
131
};
132
}
133
134
#endif