Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(565)

Side by Side Diff: media/mp4/track_run_iterator.h

Issue 10651006: Add Common Encryption support to BMFF, including subsample decryption. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add wrong subsample size test Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/media_export.h"
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 {
16
17 class DecryptConfig;
18
15 namespace mp4 { 19 namespace mp4 {
16 20
17 using base::TimeDelta; 21 using base::TimeDelta;
22 base::TimeDelta MEDIA_EXPORT TimeDeltaFromFrac(int64 numer, int64 denom);
18 23
19 base::TimeDelta TimeDeltaFromFrac(int64 numer, int64 denom); 24 struct SampleInfo;
25 struct TrackRunInfo;
20 26
21 struct SampleInfo { 27 class MEDIA_EXPORT TrackRunIterator {
22 int size;
23 TimeDelta duration;
24 TimeDelta cts_offset;
25 bool is_keyframe;
26 };
27
28 struct TrackRunInfo {
29 uint32 track_id;
30 std::vector<SampleInfo> samples;
31 TimeDelta start_dts;
32 int64 sample_start_offset;
33
34 bool is_encrypted;
35 int64 cenc_start_offset;
36 int cenc_total_size;
37 uint8 default_cenc_size;
38 // Only valid if default_cenc_size == 0. (In this case, infer the sample count
39 // from the 'samples' parameter; they shall be the same.)
40 std::vector<uint8> cenc_sizes;
41
42 TrackRunInfo();
43 ~TrackRunInfo();
44 };
45
46 class TrackRunIterator {
47 public: 28 public:
48 TrackRunIterator(); 29 TrackRunIterator();
49 ~TrackRunIterator(); 30 ~TrackRunIterator();
50 31
51 void Reset(); 32 void Reset();
52 33
53 // Sets up the iterator to handle all the runs from the current fragment. 34 // Sets up the iterator to handle all the runs from the current fragment.
54 bool Init(const Movie& moov, const MovieFragment& moof); 35 bool Init(const Movie& moov, const MovieFragment& moof);
55 36
56 // Returns true if the properties of the current run or sample are valid. 37 // Returns true if the properties of the current run or sample are valid.
57 bool RunValid() const; 38 bool RunIsValid() const;
ddorwin 2012/07/17 01:14:21 Is*
strobe_ 2012/07/19 02:43:35 Done.
58 bool SampleValid() const; 39 bool SampleIsValid() const;
59 40
60 // Advance the properties to refer to the next run or sample. Requires that 41 // Advance the properties to refer to the next run or sample. Requires that
61 // the current sample be valid. 42 // the current sample be valid.
62 void AdvanceRun(); 43 void AdvanceRun();
63 void AdvanceSample(); 44 void AdvanceSample();
64 45
65 // Returns true iff the track is encrypted and the common encryption sample 46 // 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. 47 // been cached. Only valid if RunIsValid().
67 bool NeedsCENC(); 48 bool AuxInfoNeedsToBeCached();
68 49
69 // Cache the CENC data from the given buffer. 50 // Caches the CENC data from the given buffer. |buf| must be a buffer starting
70 bool CacheCENC(const uint8* buf, int size); 51 // at the offset given by cenc_offset(), with a |size| of at least
52 // cenc_size(). Returns true on success, false on error.
53 bool CacheAuxInfo(const uint8* buf, int size);
71 54
72 // Returns the maximum buffer location at which no data earlier in the stream 55 // 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 56 // 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 57 // 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 58 // 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). 59 // in bytes past the the head of the MOOF box).
77 int64 GetMaxClearOffset(); 60 int64 GetMaxClearOffset();
78 61
79 // Returns the minimum timestamp (or kInfiniteDuration if no runs present). 62 // Returns the minimum timestamp (or kInfiniteDuration if no runs present).
80 TimeDelta GetMinDecodeTimestamp(); 63 TimeDelta GetMinDecodeTimestamp();
81 64
82 // Property of the current run. Reqiures RunValid(). 65 // Property of the current run. Only valid if RunIsValid().
83 uint32 track_id() const; 66 uint32 track_id() const;
67 int64 aux_info_offset() const;
68 int aux_info_size() const;
84 bool is_encrypted() const; 69 bool is_encrypted() const;
85 // Only valid if is_encrypted() is true.
86 int64 cenc_offset() const;
87 int cenc_size() const;
88 70
89 // Properties of the current sample. Requires SampleValid(). 71 // Properties of the current sample. Only valid if SampleIsValid().
90 int64 offset() const; 72 int64 sample_offset() const;
91 int size() const; 73 int sample_size() const;
92 TimeDelta dts() const; 74 TimeDelta dts() const;
93 TimeDelta cts() const; 75 TimeDelta cts() const;
94 TimeDelta duration() const; 76 TimeDelta duration() const;
95 bool is_keyframe() const; 77 bool is_keyframe() const;
96 // Only valid if is_encrypted() is true and NeedsCENC() is false. 78
97 const FrameCENCInfo& frame_cenc_info(); 79 // Only call when is_encrypted() is true and AuxInfoNeedsToBeCached() is
80 // false. Result is owned by caller.
81 scoped_ptr<DecryptConfig> GetDecryptConfig();
98 82
99 private: 83 private:
100 void ResetRun(); 84 void ResetRun();
101 std::vector<TrackRunInfo> runs_; 85 std::vector<TrackRunInfo> runs_;
102 std::vector<TrackRunInfo>::const_iterator run_itr_; 86 std::vector<TrackRunInfo>::const_iterator run_itr_;
87 std::vector<SampleInfo>::const_iterator sample_itr_;
103 88
104 std::vector<SampleInfo>::const_iterator sample_itr_; 89 std::vector<FrameCENCInfo> cenc_info_;
105 std::vector<uint8> cenc_cache_;
106 90
107 std::vector<int64> min_clear_offsets_; 91 int64 sample_dts_;
108 std::vector<int64>::const_iterator min_clear_offset_itr_;
109
110 TimeDelta sample_dts_;
111 int64 sample_offset_; 92 int64 sample_offset_;
112 FrameCENCInfo frame_cenc_info_;
113 }; 93 };
114 94
115 } // namespace mp4 95 } // namespace mp4
116 } // namespace media 96 } // namespace media
117 97
118 #endif // MEDIA_MP4_TRACK_RUN_ITERATOR_H_ 98 #endif // MEDIA_MP4_TRACK_RUN_ITERATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698