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