Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MEDIA_MP4_TRACK_RUN_ITERATOR_H_
6 #define MEDIA_MP4_TRACK_RUN_ITERATOR_H_
8 #include <vector>
9 #include <memory>
11 #include "mp4_demuxer/box_definitions.h"
12 #include "mp4_demuxer/cenc.h"
13 #include "nsAutoPtr.h"
15 namespace mp4_demuxer {
17 class DecryptConfig;
19 Microseconds MicrosecondsFromRational(int64_t numer, int64_t denom);
21 struct SampleInfo;
22 struct TrackRunInfo;
24 class TrackRunIterator {
25 public:
26 // Create a new TrackRunIterator. A reference to |moov| will be retained for
27 // the lifetime of this object.
28 TrackRunIterator(const Movie* moov);
29 ~TrackRunIterator();
31 void Reset();
33 // Sets up the iterator to handle all the runs from the current fragment.
34 bool Init(const MovieFragment& moof);
36 // Returns true if the properties of the current run or sample are valid.
37 bool IsRunValid() const;
38 bool IsSampleValid() const;
40 // Advance the properties to refer to the next run or sample. Requires that
41 // the current sample be valid.
42 void AdvanceRun();
43 void AdvanceSample();
45 // Returns true if this track run has auxiliary information and has not yet
46 // been cached. Only valid if IsRunValid().
47 bool AuxInfoNeedsToBeCached();
49 // Caches the CENC data from the given buffer. |buf| must be a buffer starting
50 // at the offset given by cenc_offset(), with a |size| of at least
51 // cenc_size(). Returns true on success, false on error.
52 //bool CacheAuxInfo(const uint8_t* buf, int size);
53 bool CacheAuxInfo(Stream* stream, int64_t moof_offset);
55 // Returns the maximum buffer location at which no data earlier in the stream
56 // will be required in order to read the current or any subsequent sample. You
57 // may clear all data up to this offset before reading the current sample
58 // safely. Result is in the same units as offset() (for Media Source this is
59 // in bytes past the the head of the MOOF box).
60 int64_t GetMaxClearOffset();
62 // Returns the minimum timestamp (or kInfiniteDuration if no runs present).
63 Microseconds GetMinDecodeTimestamp();
65 // Property of the current run. Only valid if IsRunValid().
66 uint32_t track_id() const;
67 int64_t aux_info_offset() const;
68 int aux_info_size() const;
69 bool is_encrypted() const;
70 bool is_audio() const;
71 // Only one is valid, based on the value of is_audio().
72 const AudioSampleEntry& audio_description() const;
73 const VideoSampleEntry& video_description() const;
75 // Properties of the current sample. Only valid if IsSampleValid().
76 int64_t sample_offset() const;
77 int sample_size() const;
78 Microseconds dts() const;
79 Microseconds cts() const;
80 Microseconds duration() const;
81 bool is_keyframe() const;
83 // Only call when is_encrypted() is true and AuxInfoNeedsToBeCached() is
84 // false. Result is owned by caller.
85 void GetDecryptConfig(nsAutoPtr<DecryptConfig>& config);
87 private:
88 void ResetRun();
89 const TrackEncryption& track_encryption() const;
91 const Movie* moov_;
93 std::vector<TrackRunInfo> runs_;
94 std::vector<TrackRunInfo>::const_iterator run_itr_;
95 std::vector<SampleInfo>::const_iterator sample_itr_;
97 std::vector<FrameCENCInfo> cenc_info_;
99 int64_t sample_dts_;
100 int64_t sample_offset_;
102 DISALLOW_COPY_AND_ASSIGN(TrackRunIterator);
103 };
105 } // namespace mp4_demuxer
107 #endif // MEDIA_MP4_TRACK_RUN_ITERATOR_H_