| OLD | NEW |
| 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_WEBM_WEBM_CLUSTER_PARSER_H_ | 5 #ifndef MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_ |
| 6 #define MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_ | 6 #define MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 return buffers_; | 36 return buffers_; |
| 37 } | 37 } |
| 38 | 38 |
| 39 // If |last_added_buffer_missing_duration_| is set, updates its duration | 39 // If |last_added_buffer_missing_duration_| is set, updates its duration |
| 40 // relative to |buffer|'s timestamp, and adds it to |buffers_| and unsets | 40 // relative to |buffer|'s timestamp, and adds it to |buffers_| and unsets |
| 41 // |last_added_buffer_missing_duration_|. Then, if |buffer| is missing | 41 // |last_added_buffer_missing_duration_|. Then, if |buffer| is missing |
| 42 // duration, saves |buffer| into |last_added_buffer_missing_duration_|, or | 42 // duration, saves |buffer| into |last_added_buffer_missing_duration_|, or |
| 43 // otherwise adds |buffer| to |buffers_|. | 43 // otherwise adds |buffer| to |buffers_|. |
| 44 bool AddBuffer(const scoped_refptr<StreamParserBuffer>& buffer); | 44 bool AddBuffer(const scoped_refptr<StreamParserBuffer>& buffer); |
| 45 | 45 |
| 46 // If |last_added_buffer_missing_duration_| is set, updates its duration | 46 // If |last_added_buffer_missing_duration_| is set, updates its duration to |
| 47 // to be the first non-kNoTimestamp() value of |default_duration_|, | 47 // be non-kNoTimestamp() value of |estimated_next_frame_duration_| or an |
| 48 // |estimated_next_frame_duration_|, or an arbitrary default, then adds it | 48 // arbitrary default, then adds it to |buffers_| and unsets |
| 49 // to |buffers_| and unsets |last_added_buffer_missing_duration_|. (This | 49 // |last_added_buffer_missing_duration_|. (This method helps stream parser |
| 50 // method helps stream parser emit all buffers in a media segment before | 50 // emit all buffers in a media segment before signaling end of segment.) |
| 51 // signaling end of segment.) | 51 void ApplyDurationEstimateIfNeeded(); |
| 52 void ApplyDurationDefaultOrEstimateIfNeeded(); | |
| 53 | 52 |
| 54 // Clears all buffer state, except a possibly held-aside buffer that is | 53 // Clears all buffer state, except a possibly held-aside buffer that is |
| 55 // missing duration. | 54 // missing duration. |
| 56 void ClearBuffersButKeepLastIfMissingDuration(); | 55 void ClearBuffersButKeepLastIfMissingDuration(); |
| 57 | 56 |
| 58 // Clears all buffer state, including any possibly held-aside buffer that | 57 // Clears all buffer state, including any possibly held-aside buffer that |
| 59 // was missing duration. | 58 // was missing duration. |
| 60 void Reset(); | 59 void Reset(); |
| 61 | 60 |
| 62 // Helper function used to inspect block data to determine if the | 61 // Helper function used to inspect block data to determine if the |
| 63 // block is a keyframe. | 62 // block is a keyframe. |
| 64 // |data| contains the bytes in the block. | 63 // |data| contains the bytes in the block. |
| 65 // |size| indicates the number of bytes in |data|. | 64 // |size| indicates the number of bytes in |data|. |
| 66 bool IsKeyframe(const uint8* data, int size) const; | 65 bool IsKeyframe(const uint8* data, int size) const; |
| 67 | 66 |
| 67 base::TimeDelta default_duration() const { return default_duration_; } |
| 68 |
| 68 private: | 69 private: |
| 69 // Helper that sanity-checks |buffer| duration, updates | 70 // Helper that sanity-checks |buffer| duration, updates |
| 70 // |estimated_next_frame_duration_|, and adds |buffer| to |buffers_|. | 71 // |estimated_next_frame_duration_|, and adds |buffer| to |buffers_|. |
| 71 // Returns false if |buffer| failed sanity check and therefore was not added | 72 // Returns false if |buffer| failed sanity check and therefore was not added |
| 72 // to |buffers_|. Returns true otherwise. | 73 // to |buffers_|. Returns true otherwise. |
| 73 bool QueueBuffer(const scoped_refptr<StreamParserBuffer>& buffer); | 74 bool QueueBuffer(const scoped_refptr<StreamParserBuffer>& buffer); |
| 74 | 75 |
| 75 // Helper that calculates the buffer duration to use in | 76 // Helper that calculates the buffer duration to use in |
| 76 // ApplyDurationDefaultOrEstimateIfNeeded(). | 77 // ApplyDurationEstimateIfNeeded(). |
| 77 base::TimeDelta GetDurationDefaultOrEstimate(); | 78 base::TimeDelta GetDurationEstimate(); |
| 78 | 79 |
| 79 int track_num_; | 80 int track_num_; |
| 80 std::deque<scoped_refptr<StreamParserBuffer> > buffers_; | 81 std::deque<scoped_refptr<StreamParserBuffer> > buffers_; |
| 81 bool is_video_; | 82 bool is_video_; |
| 82 scoped_refptr<StreamParserBuffer> last_added_buffer_missing_duration_; | 83 scoped_refptr<StreamParserBuffer> last_added_buffer_missing_duration_; |
| 83 | 84 |
| 84 // If kNoTimestamp(), then |estimated_next_frame_duration_| will be used. | 85 // If kNoTimestamp(), then |estimated_next_frame_duration_| will be used. |
| 85 base::TimeDelta default_duration_; | 86 base::TimeDelta default_duration_; |
| 86 // If kNoTimestamp(), then a default value will be used. This estimate is | 87 // If kNoTimestamp(), then a default value will be used. This estimate is |
| 87 // the maximum duration seen or derived so far for this track, and is valid | 88 // the maximum duration seen or derived so far for this track, and is valid |
| 88 // only if |default_duration_| is kNoTimestamp(). | 89 // only if |default_duration_| is kNoTimestamp(). |
| 90 // |
| 91 // TODO(wolenetz): Add unittests for duration estimation and default |
| 92 // duration handling. http://crbug.com/361786 . |
| 89 base::TimeDelta estimated_next_frame_duration_; | 93 base::TimeDelta estimated_next_frame_duration_; |
| 90 }; | 94 }; |
| 91 | 95 |
| 92 typedef std::map<int, Track> TextTrackMap; | 96 typedef std::map<int, Track> TextTrackMap; |
| 93 | 97 |
| 94 public: | 98 public: |
| 95 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; | 99 typedef std::deque<scoped_refptr<StreamParserBuffer> > BufferQueue; |
| 96 typedef std::map<TrackId, const BufferQueue> TextBufferQueueMap; | 100 typedef std::map<TrackId, const BufferQueue> TextBufferQueueMap; |
| 97 | 101 |
| 98 WebMClusterParser(int64 timecode_scale, | 102 WebMClusterParser(int64 timecode_scale, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 TextBufferQueueMap text_buffers_map_; | 193 TextBufferQueueMap text_buffers_map_; |
| 190 | 194 |
| 191 LogCB log_cb_; | 195 LogCB log_cb_; |
| 192 | 196 |
| 193 DISALLOW_IMPLICIT_CONSTRUCTORS(WebMClusterParser); | 197 DISALLOW_IMPLICIT_CONSTRUCTORS(WebMClusterParser); |
| 194 }; | 198 }; |
| 195 | 199 |
| 196 } // namespace media | 200 } // namespace media |
| 197 | 201 |
| 198 #endif // MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_ | 202 #endif // MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_ |
| OLD | NEW |