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. |
wolenetz
2014/04/09 21:53:47
nit: webm_cluster_parser_unittest could use some D
Sergey Ulanov
2014/04/10 02:00:49
Done.
| |
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(). |
89 base::TimeDelta estimated_next_frame_duration_; | 90 base::TimeDelta estimated_next_frame_duration_; |
90 }; | 91 }; |
91 | 92 |
92 typedef std::map<int, Track> TextTrackMap; | 93 typedef std::map<int, Track> TextTrackMap; |
93 | 94 |
94 public: | 95 public: |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 TextBufferQueueMap text_buffers_map_; | 190 TextBufferQueueMap text_buffers_map_; |
190 | 191 |
191 LogCB log_cb_; | 192 LogCB log_cb_; |
192 | 193 |
193 DISALLOW_IMPLICIT_CONSTRUCTORS(WebMClusterParser); | 194 DISALLOW_IMPLICIT_CONSTRUCTORS(WebMClusterParser); |
194 }; | 195 }; |
195 | 196 |
196 } // namespace media | 197 } // namespace media |
197 | 198 |
198 #endif // MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_ | 199 #endif // MEDIA_FORMATS_WEBM_WEBM_CLUSTER_PARSER_H_ |
OLD | NEW |