Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_MP4_TRACK_RUN_ITERATOR_H_ | 5 #ifndef MEDIA_MP4_TRACK_RUN_ITERATOR_H_ |
| 6 #define MEDIA_MP4_TRACK_RUN_ITERATOR_H_ | 6 #define MEDIA_MP4_TRACK_RUN_ITERATOR_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| 11 #include "media/base/decrypt_config.h" | |
|
xhwang
2012/06/27 19:37:43
Forward declaration of DecryptConfig instead of in
strobe_
2012/07/13 00:47:07
Done.
| |
| 11 #include "media/mp4/box_definitions.h" | 12 #include "media/mp4/box_definitions.h" |
| 12 #include "media/mp4/cenc.h" | 13 #include "media/mp4/cenc.h" |
| 13 | 14 |
| 14 namespace media { | 15 namespace media { |
| 15 namespace mp4 { | 16 namespace mp4 { |
| 16 | 17 |
| 17 using base::TimeDelta; | 18 using base::TimeDelta; |
| 18 | 19 |
| 19 base::TimeDelta TimeDeltaFromFrac(int64 numer, uint64 denom); | 20 base::TimeDelta TimeDeltaFromFrac(int64 numer, uint64 denom); |
| 20 | 21 |
| 21 struct SampleInfo { | 22 struct SampleInfo { |
| 22 int size; | 23 int size; |
| 23 TimeDelta duration; | 24 TimeDelta duration; |
| 24 TimeDelta cts_offset; | 25 TimeDelta cts_offset; |
| 25 bool is_keyframe; | 26 bool is_keyframe; |
| 26 }; | 27 }; |
| 27 | 28 |
| 28 struct TrackRunInfo { | 29 struct TrackRunInfo { |
| 29 uint32 track_id; | 30 uint32 track_id; |
| 30 std::vector<SampleInfo> samples; | 31 std::vector<SampleInfo> samples; |
| 31 TimeDelta start_dts; | 32 TimeDelta start_dts; |
| 32 int64 sample_start_offset; | 33 int64 sample_start_offset; |
| 33 | 34 |
| 34 bool is_encrypted; | 35 int64 aux_info_start_offset; |
| 35 int64 cenc_start_offset; | 36 int aux_info_default_size; |
| 36 int cenc_total_size; | 37 std::vector<uint8> aux_info_sizes; // Present if default_size == 0. |
| 37 uint8 default_cenc_size; | 38 int aux_info_total_size; |
| 38 // Only valid if default_cenc_size == 0. (In this case, infer the sample count | 39 |
| 39 // from the 'samples' parameter; they shall be the same.) | 40 TrackEncryption track_encryption; |
| 40 std::vector<uint8> cenc_sizes; | |
| 41 | 41 |
| 42 TrackRunInfo(); | 42 TrackRunInfo(); |
| 43 ~TrackRunInfo(); | 43 ~TrackRunInfo(); |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 class TrackRunIterator { | 46 class TrackRunIterator { |
| 47 public: | 47 public: |
| 48 TrackRunIterator(); | 48 TrackRunIterator(); |
| 49 ~TrackRunIterator(); | 49 ~TrackRunIterator(); |
| 50 | 50 |
| 51 void Reset(); | 51 void Reset(); |
| 52 | 52 |
| 53 // Sets up the iterator to handle all the runs from the current fragment. | 53 // Sets up the iterator to handle all the runs from the current fragment. |
| 54 bool Init(const Movie& moov, const MovieFragment& moof); | 54 bool Init(const Movie& moov, const MovieFragment& moof); |
| 55 | 55 |
| 56 // Returns true if the properties of the current run or sample are valid. | 56 // Returns true if the properties of the current run or sample are valid. |
| 57 bool RunValid() const; | 57 bool RunValid() const; |
| 58 bool SampleValid() const; | 58 bool SampleValid() const; |
| 59 | 59 |
| 60 // Advance the properties to refer to the next run or sample. Requires that | 60 // Advance the properties to refer to the next run or sample. Requires that |
| 61 // the current sample be valid. | 61 // the current sample be valid. |
| 62 void AdvanceRun(); | 62 void AdvanceRun(); |
| 63 void AdvanceSample(); | 63 void AdvanceSample(); |
| 64 | 64 |
| 65 // Returns true iff the track is encrypted and the common encryption sample | 65 // Returns true if this track run has auxiliary information and has not yet |
| 66 // auxiliary information has not yet been cached for the current track. | 66 // been cached. Only valid if RunValid(). |
| 67 bool NeedsCENC(); | 67 bool AuxInfoNeedsToBeCached(); |
| 68 | 68 |
| 69 // Cache the CENC data from the given buffer. | 69 // Cache the CENC data from the given buffer. |buf| must be a buffer starting |
|
xhwang
2012/06/27 19:37:43
Cache->Caches
strobe_
2012/07/13 00:47:07
Done.
| |
| 70 bool CacheCENC(const uint8* buf, int size); | 70 // at the offset given by cenc_offset(), with a |size| of at least |
| 71 // cenc_size(). Returns true on success, false on error. | |
| 72 bool CacheAuxInfo(const uint8* buf, int size); | |
| 71 | 73 |
| 72 // Returns the maximum buffer location at which no data earlier in the stream | 74 // Returns the maximum buffer location at which no data earlier in the stream |
| 73 // will be required in order to read the current or any subsequent sample. You | 75 // will be required in order to read the current or any subsequent sample. You |
| 74 // may clear all data up to this offset before reading the current sample | 76 // may clear all data up to this offset before reading the current sample |
| 75 // safely. Result is in the same units as offset() (for Media Source this is | 77 // safely. Result is in the same units as offset() (for Media Source this is |
| 76 // in bytes past the the head of the MOOF box). | 78 // in bytes past the the head of the MOOF box). |
| 77 int64 GetMaxClearOffset(); | 79 int64 GetMaxClearOffset(); |
| 78 | 80 |
| 79 // Returns the minimum timestamp (or kInfiniteDuration if no runs present). | 81 // Returns the minimum timestamp (or kInfiniteDuration if no runs present). |
| 80 TimeDelta GetMinDecodeTimestamp(); | 82 TimeDelta GetMinDecodeTimestamp(); |
| 81 | 83 |
| 82 // Property of the current run. Reqiures RunValid(). | 84 // Property of the current run. Only valid if RunValid(). |
| 83 uint32 track_id() const; | 85 uint32 track_id() const; |
| 86 int64 aux_info_offset() const; | |
| 87 int aux_info_size() const; | |
| 84 bool is_encrypted() const; | 88 bool is_encrypted() const; |
| 85 // Only valid if is_encrypted() is true. | |
| 86 int64 cenc_offset() const; | |
| 87 int cenc_size() const; | |
| 88 | 89 |
| 89 // Properties of the current sample. Requires SampleValid(). | 90 // Properties of the current sample. Only valid if SampleValid(). |
| 90 int64 offset() const; | 91 int64 sample_offset() const; |
| 91 int size() const; | 92 int sample_size() const; |
| 92 TimeDelta dts() const; | 93 TimeDelta dts() const; |
| 93 TimeDelta cts() const; | 94 TimeDelta cts() const; |
| 94 TimeDelta duration() const; | 95 TimeDelta duration() const; |
| 95 bool is_keyframe() const; | 96 bool is_keyframe() const; |
| 96 // Only valid if is_encrypted() is true and NeedsCENC() is false. | 97 |
| 97 const FrameCENCInfo& frame_cenc_info(); | 98 // Only call when is_encrypted() is true and AuxInfoNeedsToBeCached() is |
| 99 // false. | |
| 100 scoped_ptr<DecryptConfig> GetDecryptConfig(); | |
|
ddorwin
2012/07/03 21:03:47
I don't think we usually return (or pass) scoped_p
strobe_
2012/07/13 00:47:07
Done.
| |
| 98 | 101 |
| 99 private: | 102 private: |
| 100 void ResetRun(); | 103 void ResetRun(); |
| 101 std::vector<TrackRunInfo> runs_; | 104 std::vector<TrackRunInfo> runs_; |
| 102 std::vector<TrackRunInfo>::const_iterator run_itr_; | 105 std::vector<TrackRunInfo>::const_iterator run_itr_; |
| 103 | |
| 104 std::vector<SampleInfo>::const_iterator sample_itr_; | 106 std::vector<SampleInfo>::const_iterator sample_itr_; |
| 105 std::vector<uint8> cenc_cache_; | |
| 106 | 107 |
| 107 std::vector<int64> min_clear_offsets_; | 108 std::vector<int64> min_clear_offsets_; |
| 108 std::vector<int64>::const_iterator min_clear_offset_itr_; | 109 std::vector<int64>::const_iterator min_clear_offset_itr_; |
| 109 | 110 |
| 111 std::vector<FrameCENCInfo> cenc_info_; | |
| 112 | |
| 110 TimeDelta sample_dts_; | 113 TimeDelta sample_dts_; |
| 111 int64 sample_offset_; | 114 int64 sample_offset_; |
| 112 FrameCENCInfo frame_cenc_info_; | |
| 113 }; | 115 }; |
| 114 | 116 |
| 115 } // namespace mp4 | 117 } // namespace mp4 |
| 116 } // namespace media | 118 } // namespace media |
| 117 | 119 |
| 118 #endif // MEDIA_MP4_TRACK_RUN_ITERATOR_H_ | 120 #endif // MEDIA_MP4_TRACK_RUN_ITERATOR_H_ |
| OLD | NEW |