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

Side by Side Diff: media/formats/mp4/box_reader.h

Issue 2815303006: Convert MediaLog from being ref counted to owned by WebMediaPlayer. (Closed)
Patch Set: Rebase. Created 3 years, 8 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
« no previous file with comments | « media/formats/mp4/box_definitions.cc ('k') | media/formats/mp4/box_reader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_FORMATS_MP4_BOX_READER_H_ 5 #ifndef MEDIA_FORMATS_MP4_BOX_READER_H_
6 #define MEDIA_FORMATS_MP4_BOX_READER_H_ 6 #define MEDIA_FORMATS_MP4_BOX_READER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <limits> 10 #include <limits>
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 ~BoxReader(); 94 ~BoxReader();
95 95
96 // Create a BoxReader from a buffer. Note that this function may return NULL 96 // Create a BoxReader from a buffer. Note that this function may return NULL
97 // if an intact, complete box was not available in the buffer. If |*err| is 97 // if an intact, complete box was not available in the buffer. If |*err| is
98 // set, there was a stream-level error when creating the box; otherwise, NULL 98 // set, there was a stream-level error when creating the box; otherwise, NULL
99 // values are only expected when insufficient data is available. 99 // values are only expected when insufficient data is available.
100 // 100 //
101 // |buf| is retained but not owned, and must outlive the BoxReader instance. 101 // |buf| is retained but not owned, and must outlive the BoxReader instance.
102 static BoxReader* ReadTopLevelBox(const uint8_t* buf, 102 static BoxReader* ReadTopLevelBox(const uint8_t* buf,
103 const size_t buf_size, 103 const size_t buf_size,
104 const scoped_refptr<MediaLog>& media_log, 104 MediaLog* media_log,
105 bool* err); 105 bool* err);
106 106
107 // Read the box header from the current buffer. This function returns true if 107 // Read the box header from the current buffer. This function returns true if
108 // there is enough data to read the header and the header is sane; that is, it 108 // there is enough data to read the header and the header is sane; that is, it
109 // does not check to ensure the entire box is in the buffer before returning 109 // does not check to ensure the entire box is in the buffer before returning
110 // true. The semantics of |*err| are the same as above. 110 // true. The semantics of |*err| are the same as above.
111 // 111 //
112 // |buf| is not retained. 112 // |buf| is not retained.
113 static bool StartTopLevelBox(const uint8_t* buf, 113 static bool StartTopLevelBox(const uint8_t* buf,
114 const size_t buf_size, 114 const size_t buf_size,
115 const scoped_refptr<MediaLog>& media_log, 115 MediaLog* media_log,
116 FourCC* type, 116 FourCC* type,
117 size_t* box_size, 117 size_t* box_size,
118 bool* err) WARN_UNUSED_RESULT; 118 bool* err) WARN_UNUSED_RESULT;
119 119
120 // Create a BoxReader from a buffer. |buf| must be the complete buffer, as 120 // Create a BoxReader from a buffer. |buf| must be the complete buffer, as
121 // errors are returned when sufficient data is not available. |buf| can start 121 // errors are returned when sufficient data is not available. |buf| can start
122 // with any type of box -- it does not have to be IsValidTopLevelBox(). 122 // with any type of box -- it does not have to be IsValidTopLevelBox().
123 // 123 //
124 // |buf| is retained but not owned, and must outlive the BoxReader instance. 124 // |buf| is retained but not owned, and must outlive the BoxReader instance.
125 static BoxReader* ReadConcatentatedBoxes(const uint8_t* buf, 125 static BoxReader* ReadConcatentatedBoxes(const uint8_t* buf,
126 const size_t buf_size); 126 const size_t buf_size);
127 127
128 // Returns true if |type| is recognized to be a top-level box, false 128 // Returns true if |type| is recognized to be a top-level box, false
129 // otherwise. This returns true for some boxes which we do not parse. 129 // otherwise. This returns true for some boxes which we do not parse.
130 // Helpful in debugging misaligned appends. 130 // Helpful in debugging misaligned appends.
131 static bool IsValidTopLevelBox(const FourCC& type, 131 static bool IsValidTopLevelBox(const FourCC& type, MediaLog* media_log);
132 const scoped_refptr<MediaLog>& media_log);
133 132
134 // Scan through all boxes within the current box, starting at the current 133 // Scan through all boxes within the current box, starting at the current
135 // buffer position. Must be called before any of the *Child functions work. 134 // buffer position. Must be called before any of the *Child functions work.
136 bool ScanChildren() WARN_UNUSED_RESULT; 135 bool ScanChildren() WARN_UNUSED_RESULT;
137 136
138 // Return true if child with type |child.BoxType()| exists. 137 // Return true if child with type |child.BoxType()| exists.
139 bool HasChild(Box* child) WARN_UNUSED_RESULT; 138 bool HasChild(Box* child) WARN_UNUSED_RESULT;
140 139
141 // Read exactly one child box from the set of children. The type of the child 140 // Read exactly one child box from the set of children. The type of the child
142 // will be determined by the BoxType() method of |child|. 141 // will be determined by the BoxType() method of |child|.
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 175
177 size_t box_size() const { 176 size_t box_size() const {
178 DCHECK(box_size_known_); 177 DCHECK(box_size_known_);
179 return box_size_; 178 return box_size_;
180 } 179 }
181 180
182 FourCC type() const { return type_; } 181 FourCC type() const { return type_; }
183 uint8_t version() const { return version_; } 182 uint8_t version() const { return version_; }
184 uint32_t flags() const { return flags_; } 183 uint32_t flags() const { return flags_; }
185 184
186 const scoped_refptr<MediaLog>& media_log() const { return media_log_; } 185 MediaLog* media_log() const { return media_log_; }
187 186
188 private: 187 private:
189 // Create a BoxReader from |buf|. |is_EOS| should be true if |buf| is 188 // Create a BoxReader from |buf|. |is_EOS| should be true if |buf| is
190 // complete stream (i.e. no additional data is expected to be appended). 189 // complete stream (i.e. no additional data is expected to be appended).
191 BoxReader(const uint8_t* buf, 190 BoxReader(const uint8_t* buf,
192 const size_t buf_size, 191 const size_t buf_size,
193 const scoped_refptr<MediaLog>& media_log, 192 MediaLog* media_log,
194 bool is_EOS); 193 bool is_EOS);
195 194
196 // Must be called immediately after init. If the return is false, this 195 // Must be called immediately after init. If the return is false, this
197 // indicates that the box header and its contents were not available in the 196 // indicates that the box header and its contents were not available in the
198 // stream or were nonsensical, and that the box must not be used further. In 197 // stream or were nonsensical, and that the box must not be used further. In
199 // this case, if |*err| is false, the problem was simply a lack of data, and 198 // this case, if |*err| is false, the problem was simply a lack of data, and
200 // should only be an error condition if some higher-level component knows that 199 // should only be an error condition if some higher-level component knows that
201 // no more data is coming (i.e. EOS or end of containing box). If |*err| is 200 // no more data is coming (i.e. EOS or end of containing box). If |*err| is
202 // true, the error is unrecoverable and the stream should be aborted. 201 // true, the error is unrecoverable and the stream should be aborted.
203 bool ReadHeader(bool* err); 202 bool ReadHeader(bool* err);
204 203
205 // Read all children, optionally checking FourCC. Returns true if all 204 // Read all children, optionally checking FourCC. Returns true if all
206 // children are successfully parsed and, if |check_box_type|, have the 205 // children are successfully parsed and, if |check_box_type|, have the
207 // correct box type for |T|. Note that this method is mutually exclusive 206 // correct box type for |T|. Note that this method is mutually exclusive
208 // with ScanChildren(). 207 // with ScanChildren().
209 template <typename T> 208 template <typename T>
210 bool ReadAllChildrenInternal(std::vector<T>* children, bool check_box_type); 209 bool ReadAllChildrenInternal(std::vector<T>* children, bool check_box_type);
211 210
212 scoped_refptr<MediaLog> media_log_; 211 MediaLog* media_log_;
213 size_t box_size_; 212 size_t box_size_;
214 bool box_size_known_; 213 bool box_size_known_;
215 FourCC type_; 214 FourCC type_;
216 uint8_t version_; 215 uint8_t version_;
217 uint32_t flags_; 216 uint32_t flags_;
218 217
219 typedef std::multimap<FourCC, BoxReader> ChildMap; 218 typedef std::multimap<FourCC, BoxReader> ChildMap;
220 219
221 // The set of child box FourCCs and their corresponding buffer readers. Only 220 // The set of child box FourCCs and their corresponding buffer readers. Only
222 // valid if scanned_ is true. 221 // valid if scanned_ is true.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 pos_ += child_reader.box_size(); 288 pos_ += child_reader.box_size();
290 } 289 }
291 290
292 return !err; 291 return !err;
293 } 292 }
294 293
295 } // namespace mp4 294 } // namespace mp4
296 } // namespace media 295 } // namespace media
297 296
298 #endif // MEDIA_FORMATS_MP4_BOX_READER_H_ 297 #endif // MEDIA_FORMATS_MP4_BOX_READER_H_
OLDNEW
« no previous file with comments | « media/formats/mp4/box_definitions.cc ('k') | media/formats/mp4/box_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698