| 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> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "media/base/stream_parser_buffer.h" | 15 #include "media/base/stream_parser_buffer.h" |
| 16 | 16 |
| 17 namespace media { | 17 namespace media { |
| 18 | 18 |
| 19 // Helper class representing a range of buffered data. All buffers in a | 19 // Helper class representing a continuous range of buffered data in the |
| 20 // SourceBufferRange are ordered sequentially in decode timestamp order with no | 20 // presentation timeline. All buffers in a SourceBufferRange are ordered |
| 21 // gaps. | 21 // sequentially in decode timestamp order with no gaps. |
| 22 class SourceBufferRange { | 22 class SourceBufferRange { |
| 23 public: | 23 public: |
| 24 // Returns the maximum distance in time between any buffer seen in this | 24 // Returns the maximum distance in time between any buffer seen in the stream |
| 25 // stream. Used to estimate the duration of a buffer if its duration is not | 25 // of which this range is a part. Used to estimate the duration of a buffer if |
| 26 // known. | 26 // its duration is not known, and in GetFudgeRoom() for determining whether a |
| 27 // time or coded frame is close enough to be considered part of this range. |
| 27 typedef base::Callback<base::TimeDelta()> InterbufferDistanceCB; | 28 typedef base::Callback<base::TimeDelta()> InterbufferDistanceCB; |
| 28 | 29 |
| 29 typedef StreamParser::BufferQueue BufferQueue; | 30 typedef StreamParser::BufferQueue BufferQueue; |
| 30 | 31 |
| 31 // Policy for handling large gaps between buffers. Continuous media like | 32 // Policy for handling large gaps between buffers. Continuous media like |
| 32 // audio & video should use NO_GAPS_ALLOWED. Discontinuous media like | 33 // audio & video should use NO_GAPS_ALLOWED. Discontinuous media like |
| 33 // timed text should use ALLOW_GAPS because large differences in timestamps | 34 // timed text should use ALLOW_GAPS because large differences in timestamps |
| 34 // are common and acceptable. | 35 // are common and acceptable. |
| 35 enum GapPolicy { | 36 enum GapPolicy { |
| 36 NO_GAPS_ALLOWED, | 37 NO_GAPS_ALLOWED, |
| 37 ALLOW_GAPS | 38 ALLOW_GAPS |
| 38 }; | 39 }; |
| 39 | 40 |
| 40 // Return the config ID for the buffer at |timestamp|. Precondition: callers | |
| 41 // must first verify CanSeekTo(timestamp) == true. | |
| 42 int GetConfigIdAtTime(DecodeTimestamp timestamp); | |
| 43 | |
| 44 // Return true if all buffers in range of [start, end] have the same config | |
| 45 // ID. Precondition: callers must first verify that | |
| 46 // CanSeekTo(start) == CanSeekTo(end) == true. | |
| 47 bool SameConfigThruRange(DecodeTimestamp start, DecodeTimestamp end); | |
| 48 | |
| 49 // Sequential buffers with the same decode timestamp make sense under certain | 41 // Sequential buffers with the same decode timestamp make sense under certain |
| 50 // conditions, typically when the first buffer is a keyframe. Due to some | 42 // conditions, typically when the first buffer is a keyframe. Due to some |
| 51 // atypical media append behaviors where a new keyframe might have the same | 43 // atypical media append behaviors where a new keyframe might have the same |
| 52 // timestamp as a previous non-keyframe, the playback of the sequence might | 44 // decode timestamp as a previous non-keyframe, the playback of the sequence |
| 53 // involve some throwaway decode work. This method supports detecting this | 45 // might involve some throwaway decode work. This method supports detecting |
| 54 // situation so that callers can log warnings (it returns true in this case | 46 // this situation so that callers can log warnings (it returns true in this |
| 55 // only). | 47 // case only). |
| 56 // For all other cases, including more typical same-DTS sequences, this method | 48 // For all other cases, including more typical same-DTS sequences, this method |
| 57 // returns false. Examples of typical situations where DTS of two consecutive | 49 // returns false. Examples of typical situations where DTS of two consecutive |
| 58 // frames can be equal: | 50 // frames can be equal: |
| 59 // - Video: VP8 Alt-Ref frames. | 51 // - Video: VP8 Alt-Ref frames. |
| 60 // - Video: IPBPBP...: DTS for I frame and for P frame can be equal. | 52 // - Video: IPBPBP...: DTS for I frame and for P frame can be equal. |
| 61 // - Text track cues that start at same time. | 53 // - Text track cues that start at same time. |
| 62 // Returns true if |prev_is_keyframe| and |current_is_keyframe| indicate a | 54 // Returns true if |prev_is_keyframe| and |current_is_keyframe| indicate a |
| 63 // same timestamp situation that is atypical. False is returned otherwise. | 55 // same timestamp situation that is atypical. False is returned otherwise. |
| 64 static bool IsUncommonSameTimestampSequence(bool prev_is_keyframe, | 56 static bool IsUncommonSameTimestampSequence(bool prev_is_keyframe, |
| 65 bool current_is_keyframe); | 57 bool current_is_keyframe); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 // timestamp must be adjacent to this range. No group start timestamp | 92 // timestamp must be adjacent to this range. No group start timestamp |
| 101 // adjacency is involved in these methods. | 93 // adjacency is involved in these methods. |
| 102 void AppendRangeToEnd(const SourceBufferRange& range, | 94 void AppendRangeToEnd(const SourceBufferRange& range, |
| 103 bool transfer_current_position); | 95 bool transfer_current_position); |
| 104 bool CanAppendRangeToEnd(const SourceBufferRange& range) const; | 96 bool CanAppendRangeToEnd(const SourceBufferRange& range) const; |
| 105 | 97 |
| 106 // Updates |next_buffer_index_| to point to the Buffer containing |timestamp|. | 98 // Updates |next_buffer_index_| to point to the Buffer containing |timestamp|. |
| 107 // Assumes |timestamp| is valid and in this range. | 99 // Assumes |timestamp| is valid and in this range. |
| 108 void Seek(DecodeTimestamp timestamp); | 100 void Seek(DecodeTimestamp timestamp); |
| 109 | 101 |
| 102 // Return the config ID for the buffer at |timestamp|. Precondition: callers |
| 103 // must first verify CanSeekTo(timestamp) == true. |
| 104 int GetConfigIdAtTime(DecodeTimestamp timestamp); |
| 105 |
| 106 // Return true if all buffers in range of [start, end] have the same config |
| 107 // ID. Precondition: callers must first verify that |
| 108 // CanSeekTo(start) == CanSeekTo(end) == true. |
| 109 bool SameConfigThruRange(DecodeTimestamp start, DecodeTimestamp end); |
| 110 |
| 110 // Updates |next_buffer_index_| to point to next keyframe after or equal to | 111 // Updates |next_buffer_index_| to point to next keyframe after or equal to |
| 111 // |timestamp|. | 112 // |timestamp|. |
| 112 void SeekAheadTo(DecodeTimestamp timestamp); | 113 void SeekAheadTo(DecodeTimestamp timestamp); |
| 113 | 114 |
| 114 // Updates |next_buffer_index_| to point to next keyframe strictly after | 115 // Updates |next_buffer_index_| to point to next keyframe strictly after |
| 115 // |timestamp|. | 116 // |timestamp|. |
| 116 void SeekAheadPast(DecodeTimestamp timestamp); | 117 void SeekAheadPast(DecodeTimestamp timestamp); |
| 117 | 118 |
| 118 // Seeks to the beginning of the range. | 119 // Seeks to the beginning of the range. |
| 119 void SeekToStart(); | 120 void SeekToStart(); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 | 326 |
| 326 // Stores the amount of memory taken up by the data in |buffers_|. | 327 // Stores the amount of memory taken up by the data in |buffers_|. |
| 327 size_t size_in_bytes_; | 328 size_t size_in_bytes_; |
| 328 | 329 |
| 329 DISALLOW_COPY_AND_ASSIGN(SourceBufferRange); | 330 DISALLOW_COPY_AND_ASSIGN(SourceBufferRange); |
| 330 }; | 331 }; |
| 331 | 332 |
| 332 } // namespace media | 333 } // namespace media |
| 333 | 334 |
| 334 #endif // MEDIA_FILTERS_SOURCE_BUFFER_RANGE_H_ | 335 #endif // MEDIA_FILTERS_SOURCE_BUFFER_RANGE_H_ |
| OLD | NEW |