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_FILTERS_SOURCE_BUFFER_RANGE_H_ | 5 #ifndef MEDIA_FILTERS_SOURCE_BUFFER_RANGE_H_ |
6 #define MEDIA_FILTERS_SOURCE_BUFFER_RANGE_H_ | 6 #define MEDIA_FILTERS_SOURCE_BUFFER_RANGE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 19 matching lines...) Expand all Loading... |
30 | 30 |
31 // Policy for handling large gaps between buffers. Continuous media like | 31 // Policy for handling large gaps between buffers. Continuous media like |
32 // audio & video should use NO_GAPS_ALLOWED. Discontinuous media like | 32 // audio & video should use NO_GAPS_ALLOWED. Discontinuous media like |
33 // timed text should use ALLOW_GAPS because large differences in timestamps | 33 // timed text should use ALLOW_GAPS because large differences in timestamps |
34 // are common and acceptable. | 34 // are common and acceptable. |
35 enum GapPolicy { | 35 enum GapPolicy { |
36 NO_GAPS_ALLOWED, | 36 NO_GAPS_ALLOWED, |
37 ALLOW_GAPS | 37 ALLOW_GAPS |
38 }; | 38 }; |
39 | 39 |
40 // Buffers with the same timestamp are only allowed under certain conditions. | 40 // Sequential buffers with the same decode timestamp make sense under certain |
41 // More precisely, it is allowed in all situations except when the previous | 41 // conditions, typically when the first buffer is a keyframe. Due to some |
42 // frame is not a key frame and the current is a key frame. | 42 // atypical media append behaviors where a new keyframe might have the same |
43 // Examples of situations where DTS of two consecutive frames can be equal: | 43 // timestamp as a previous non-keyframe, the playback of the sequence might |
| 44 // involve some throwaway decode work. This method supports detecting this |
| 45 // situation so that callers can log warnings (it returns true in this case |
| 46 // only). |
| 47 // For all other cases, including more typical same-DTS sequences, this method |
| 48 // returns false. Examples of typical situations where DTS of two consecutive |
| 49 // frames can be equal: |
44 // - Video: VP8 Alt-Ref frames. | 50 // - Video: VP8 Alt-Ref frames. |
45 // - Video: IPBPBP...: DTS for I frame and for P frame can be equal. | 51 // - Video: IPBPBP...: DTS for I frame and for P frame can be equal. |
46 // - Text track cues that start at same time. | 52 // - Text track cues that start at same time. |
47 // Returns true if |prev_is_keyframe| and |current_is_keyframe| indicate a | 53 // Returns true if |prev_is_keyframe| and |current_is_keyframe| indicate a |
48 // same timestamp situation that is allowed. False is returned otherwise. | 54 // same timestamp situation that is atypical. False is returned otherwise. |
49 static bool AllowSameTimestamp(bool prev_is_keyframe, | 55 static bool IsUncommonSameTimestampSequence(bool prev_is_keyframe, |
50 bool current_is_keyframe); | 56 bool current_is_keyframe); |
51 | 57 |
52 // Creates a source buffer range with |new_buffers|. |new_buffers| cannot be | 58 // Creates a source buffer range with |new_buffers|. |new_buffers| cannot be |
53 // empty and the front of |new_buffers| must be a keyframe. | 59 // empty and the front of |new_buffers| must be a keyframe. |
54 // |media_segment_start_time| refers to the starting timestamp for the media | 60 // |range_start_time| refers to the starting timestamp for the coded frame |
55 // segment to which these buffers belong. | 61 // group to which these buffers belong. |
56 SourceBufferRange(GapPolicy gap_policy, | 62 SourceBufferRange(GapPolicy gap_policy, |
57 const BufferQueue& new_buffers, | 63 const BufferQueue& new_buffers, |
58 DecodeTimestamp media_segment_start_time, | 64 DecodeTimestamp range_start_time, |
59 const InterbufferDistanceCB& interbuffer_distance_cb); | 65 const InterbufferDistanceCB& interbuffer_distance_cb); |
60 | 66 |
61 ~SourceBufferRange(); | 67 ~SourceBufferRange(); |
62 | 68 |
63 // Appends |buffers| to the end of the range and updates |keyframe_map_| as | 69 // Appends |buffers| to the end of the range and updates |keyframe_map_| as |
64 // it encounters new keyframes. Assumes |buffers| belongs at the end of the | 70 // it encounters new keyframes. |
65 // range. | 71 // If |new_buffers_group_start_timestamp| is kNoDecodeTimestamp(), then the |
66 void AppendBuffersToEnd(const BufferQueue& buffers); | 72 // first buffer in |buffers| must come directly after the last buffer in this |
67 bool CanAppendBuffersToEnd(const BufferQueue& buffers) const; | 73 // range (within the fudge room). |
| 74 // If |new_buffers_group_start_timestamp| is set otherwise, then that time |
| 75 // must come directly after the last buffer in this range (within the fudge |
| 76 // room). The latter scenario is required when a muxed coded frame group has |
| 77 // such a large jagged start across tracks that its first buffer is not within |
| 78 // the fudge room, yet its group start was. |
| 79 void AppendBuffersToEnd(const BufferQueue& buffers, |
| 80 DecodeTimestamp new_buffers_group_start_timestamp); |
| 81 bool CanAppendBuffersToEnd( |
| 82 const BufferQueue& buffers, |
| 83 DecodeTimestamp new_buffers_group_start_timestamp) const; |
68 | 84 |
69 // Appends the buffers from |range| into this range. | 85 // Appends the buffers from |range| into this range. |
70 // The first buffer in |range| must come directly after the last buffer | 86 // The first buffer in |range| must come directly after the last buffer |
71 // in this range. | 87 // in this range. |
72 // If |transfer_current_position| is true, |range|'s |next_buffer_index_| | 88 // If |transfer_current_position| is true, |range|'s |next_buffer_index_| |
73 // is transfered to this SourceBufferRange. | 89 // is transfered to this SourceBufferRange. |
| 90 // Note: Use these only to merge existing ranges. |range|'s first buffer |
| 91 // timestamp must be adjacent to this range. No group start timestamp |
| 92 // adjacency is involved in these methods. |
74 void AppendRangeToEnd(const SourceBufferRange& range, | 93 void AppendRangeToEnd(const SourceBufferRange& range, |
75 bool transfer_current_position); | 94 bool transfer_current_position); |
76 bool CanAppendRangeToEnd(const SourceBufferRange& range) const; | 95 bool CanAppendRangeToEnd(const SourceBufferRange& range) const; |
77 | 96 |
78 // Updates |next_buffer_index_| to point to the Buffer containing |timestamp|. | 97 // Updates |next_buffer_index_| to point to the Buffer containing |timestamp|. |
79 // Assumes |timestamp| is valid and in this range. | 98 // Assumes |timestamp| is valid and in this range. |
80 void Seek(DecodeTimestamp timestamp); | 99 void Seek(DecodeTimestamp timestamp); |
81 | 100 |
82 // Updates |next_buffer_index_| to point to next keyframe after or equal to | 101 // Updates |next_buffer_index_| to point to next keyframe after or equal to |
83 // |timestamp|. | 102 // |timestamp|. |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 // Returns true if this range's buffered timespan completely overlaps the | 211 // Returns true if this range's buffered timespan completely overlaps the |
193 // buffered timespan of |range|. | 212 // buffered timespan of |range|. |
194 bool CompletelyOverlaps(const SourceBufferRange& range) const; | 213 bool CompletelyOverlaps(const SourceBufferRange& range) const; |
195 | 214 |
196 // Returns true if the end of this range contains buffers that overlaps with | 215 // Returns true if the end of this range contains buffers that overlaps with |
197 // the beginning of |range|. | 216 // the beginning of |range|. |
198 bool EndOverlaps(const SourceBufferRange& range) const; | 217 bool EndOverlaps(const SourceBufferRange& range) const; |
199 | 218 |
200 // Returns true if |timestamp| is the timestamp of the next buffer in | 219 // Returns true if |timestamp| is the timestamp of the next buffer in |
201 // sequence after |buffers_.back()|, false otherwise. | 220 // sequence after |buffers_.back()|, false otherwise. |
202 bool IsNextInSequence(DecodeTimestamp timestamp, bool is_key_frame) const; | 221 bool IsNextInSequence(DecodeTimestamp timestamp) const; |
203 | 222 |
204 // Adds all buffers which overlap [start, end) to the end of |buffers|. If | 223 // Adds all buffers which overlap [start, end) to the end of |buffers|. If |
205 // no buffers exist in the range returns false, true otherwise. | 224 // no buffers exist in the range returns false, true otherwise. |
206 bool GetBuffersInRange(DecodeTimestamp start, DecodeTimestamp end, | 225 bool GetBuffersInRange(DecodeTimestamp start, DecodeTimestamp end, |
207 BufferQueue* buffers); | 226 BufferQueue* buffers); |
208 | 227 |
209 size_t size_in_bytes() const { return size_in_bytes_; } | 228 size_t size_in_bytes() const { return size_in_bytes_; } |
210 | 229 |
211 private: | 230 private: |
212 typedef std::map<DecodeTimestamp, int> KeyframeMap; | 231 typedef std::map<DecodeTimestamp, int> KeyframeMap; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 | 287 |
269 // Index base of all positions in |keyframe_map_|. In other words, the | 288 // Index base of all positions in |keyframe_map_|. In other words, the |
270 // real position of entry |k| of |keyframe_map_| in the range is: | 289 // real position of entry |k| of |keyframe_map_| in the range is: |
271 // keyframe_map_[k] - keyframe_map_index_base_ | 290 // keyframe_map_[k] - keyframe_map_index_base_ |
272 int keyframe_map_index_base_; | 291 int keyframe_map_index_base_; |
273 | 292 |
274 // Index into |buffers_| for the next buffer to be returned by | 293 // Index into |buffers_| for the next buffer to be returned by |
275 // GetNextBuffer(), set to -1 before Seek(). | 294 // GetNextBuffer(), set to -1 before Seek(). |
276 int next_buffer_index_; | 295 int next_buffer_index_; |
277 | 296 |
278 // If the first buffer in this range is the beginning of a media segment, | 297 // If the first buffer in this range is the beginning of a coded frame group, |
279 // |media_segment_start_time_| is the time when the media segment begins. | 298 // |range_start_time_| is the time when the coded frame group begins. This is |
280 // |media_segment_start_time_| may be <= the timestamp of the first buffer in | 299 // especially important in muxed media where the first coded frames for each |
281 // |buffers_|. |media_segment_start_time_| is kNoTimestamp() if this range | 300 // track do not necessarily begin at the same time. |
282 // does not start at the beginning of a media segment, which can only happen | 301 // |range_start_time_| may be <= the timestamp of the first buffer in |
283 // garbage collection or after an end overlap that results in a split range | 302 // |buffers_|. |range_start_time_| is kNoDecodeTimestamp() if this range does |
284 // (we don't have a way of knowing the media segment timestamp for the new | 303 // not start at the beginning of a coded frame group, which can happen by |
285 // range). | 304 // range removal or split when we don't have a way of knowing, across |
286 DecodeTimestamp media_segment_start_time_; | 305 // potentially multiple muxed streams, the coded frame group start timestamp |
| 306 // for the new range. |
| 307 DecodeTimestamp range_start_time_; |
287 | 308 |
288 // Called to get the largest interbuffer distance seen so far in the stream. | 309 // Called to get the largest interbuffer distance seen so far in the stream. |
289 InterbufferDistanceCB interbuffer_distance_cb_; | 310 InterbufferDistanceCB interbuffer_distance_cb_; |
290 | 311 |
291 // Stores the amount of memory taken up by the data in |buffers_|. | 312 // Stores the amount of memory taken up by the data in |buffers_|. |
292 size_t size_in_bytes_; | 313 size_t size_in_bytes_; |
293 | 314 |
294 DISALLOW_COPY_AND_ASSIGN(SourceBufferRange); | 315 DISALLOW_COPY_AND_ASSIGN(SourceBufferRange); |
295 }; | 316 }; |
296 | 317 |
297 } // namespace media | 318 } // namespace media |
298 | 319 |
299 #endif // MEDIA_FILTERS_SOURCE_BUFFER_RANGE_H_ | 320 #endif // MEDIA_FILTERS_SOURCE_BUFFER_RANGE_H_ |
OLD | NEW |