content/media/fmp4/demuxer/track_run_iterator.h

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

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

mercurial