1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef INDEX_H_
#define INDEX_H_
#include "ByteStream.h"
#include "MediaData.h"
#include "MediaResource.h"
#include "MoofParser.h"
#include "mozilla/ResultVariant.h"
#include "MP4Interval.h"
#include "nsISupportsImpl.h"
#include "TimeUnits.h"
namespace mozilla {
class IndiceWrapper;
struct Sample;
struct CencSampleEncryptionInfoEntry;
class Index;
typedef int64_t Microseconds;
class SampleIterator {
public:
explicit SampleIterator(Index* aIndex);
~SampleIterator();
already_AddRefed<mozilla::MediaRawData> GetNext();
void Seek(Microseconds aTime);
Microseconds GetNextKeyframeTime();
private:
Sample* Get();
// Gets the sample description entry for the current moof, or nullptr if
// called without a valid current moof.
SampleDescriptionEntry* GetSampleDescriptionEntry();
CencSampleEncryptionInfoEntry* GetSampleEncryptionEntry();
// Determines the encryption scheme in use for the current sample. If the
// the scheme cannot be unambiguously determined, will return an error with
// the reason.
//
// Returns: Ok(CryptoScheme) if a crypto scheme, including None, can be
// determined, or Err(nsCString) if there is an issue determining the scheme.
Result<CryptoScheme, nsCString> GetEncryptionScheme();
void Next();
RefPtr<Index> mIndex;
friend class Index;
size_t mCurrentMoof;
size_t mCurrentSample;
};
class Index {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(Index)
struct Indice {
uint64_t start_offset;
uint64_t end_offset;
uint64_t start_composition;
uint64_t end_composition;
uint64_t start_decode;
bool sync;
};
struct MP4DataOffset {
MP4DataOffset(uint32_t aIndex, int64_t aStartOffset)
: mIndex(aIndex), mStartOffset(aStartOffset), mEndOffset(0) {}
bool operator==(int64_t aStartOffset) const {
return mStartOffset == aStartOffset;
}
bool operator!=(int64_t aStartOffset) const {
return mStartOffset != aStartOffset;
}
bool operator<(int64_t aStartOffset) const {
return mStartOffset < aStartOffset;
}
struct EndOffsetComparator {
bool Equals(const MP4DataOffset& a, const int64_t& b) const {
return a.mEndOffset == b;
}
bool LessThan(const MP4DataOffset& a, const int64_t& b) const {
return a.mEndOffset < b;
}
};
uint32_t mIndex;
int64_t mStartOffset;
int64_t mEndOffset;
MP4Interval<Microseconds> mTime;
};
Index(const mozilla::IndiceWrapper& aIndices, ByteStream* aSource,
uint32_t aTrackId, bool aIsAudio);
void UpdateMoofIndex(const mozilla::MediaByteRangeSet& aByteRanges,
bool aCanEvict);
void UpdateMoofIndex(const mozilla::MediaByteRangeSet& aByteRanges);
Microseconds GetEndCompositionIfBuffered(
const mozilla::MediaByteRangeSet& aByteRanges);
mozilla::media::TimeIntervals ConvertByteRangesToTimeRanges(
const mozilla::MediaByteRangeSet& aByteRanges);
uint64_t GetEvictionOffset(Microseconds aTime);
bool IsFragmented() { return !!mMoofParser; }
friend class SampleIterator;
private:
~Index();
void RegisterIterator(SampleIterator* aIterator);
void UnregisterIterator(SampleIterator* aIterator);
ByteStream* mSource;
FallibleTArray<Sample> mIndex;
FallibleTArray<MP4DataOffset> mDataOffset;
UniquePtr<MoofParser> mMoofParser;
nsTArray<SampleIterator*> mIterators;
// ConvertByteRangesToTimeRanges cache
mozilla::MediaByteRangeSet mLastCachedRanges;
mozilla::media::TimeIntervals mLastBufferedRanges;
bool mIsAudio;
};
} // namespace mozilla
#endif
|