| 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 <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/basictypes.h" |
| 10 #include "base/callback.h" | 11 #include "base/callback.h" |
| 11 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 12 #include "media/base/stream_parser_buffer.h" | 13 #include "media/base/stream_parser_buffer.h" |
| 13 | 14 |
| 14 namespace media { | 15 namespace media { |
| 15 | 16 |
| 16 // Helper class representing a range of buffered data. All buffers in a | 17 // Helper class representing a range of buffered data. All buffers in a |
| 17 // SourceBufferRange are ordered sequentially in decode timestamp order with no | 18 // SourceBufferRange are ordered sequentially in decode timestamp order with no |
| 18 // gaps. | 19 // gaps. |
| 19 class SourceBufferRange { | 20 class SourceBufferRange { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // Returns true if everything in the range was deleted. Otherwise | 105 // Returns true if everything in the range was deleted. Otherwise |
| 105 // returns false. | 106 // returns false. |
| 106 bool TruncateAt(DecodeTimestamp timestamp, | 107 bool TruncateAt(DecodeTimestamp timestamp, |
| 107 BufferQueue* deleted_buffers, bool is_exclusive); | 108 BufferQueue* deleted_buffers, bool is_exclusive); |
| 108 // Deletes all buffers in range. | 109 // Deletes all buffers in range. |
| 109 void DeleteAll(BufferQueue* deleted_buffers); | 110 void DeleteAll(BufferQueue* deleted_buffers); |
| 110 | 111 |
| 111 // Deletes a GOP from the front or back of the range and moves these | 112 // Deletes a GOP from the front or back of the range and moves these |
| 112 // buffers into |deleted_buffers|. Returns the number of bytes deleted from | 113 // buffers into |deleted_buffers|. Returns the number of bytes deleted from |
| 113 // the range (i.e. the size in bytes of |deleted_buffers|). | 114 // the range (i.e. the size in bytes of |deleted_buffers|). |
| 114 int DeleteGOPFromFront(BufferQueue* deleted_buffers); | 115 size_t DeleteGOPFromFront(BufferQueue* deleted_buffers); |
| 115 int DeleteGOPFromBack(BufferQueue* deleted_buffers); | 116 size_t DeleteGOPFromBack(BufferQueue* deleted_buffers); |
| 116 | 117 |
| 117 // Gets the range of GOP to secure at least |bytes_to_free| from | 118 // Gets the range of GOP to secure at least |bytes_to_free| from |
| 118 // [|start_timestamp|, |end_timestamp|). | 119 // [|start_timestamp|, |end_timestamp|). |
| 119 // Returns the size of the buffers to secure if the buffers of | 120 // Returns the size of the buffers to secure if the buffers of |
| 120 // [|start_timestamp|, |end_removal_timestamp|) is removed. | 121 // [|start_timestamp|, |end_removal_timestamp|) is removed. |
| 121 // Will not update |end_removal_timestamp| if the returned size is 0. | 122 // Will not update |end_removal_timestamp| if the returned size is 0. |
| 122 int GetRemovalGOP( | 123 size_t GetRemovalGOP( |
| 123 DecodeTimestamp start_timestamp, DecodeTimestamp end_timestamp, | 124 DecodeTimestamp start_timestamp, DecodeTimestamp end_timestamp, |
| 124 int bytes_to_free, DecodeTimestamp* end_removal_timestamp); | 125 size_t bytes_to_free, DecodeTimestamp* end_removal_timestamp); |
| 125 | 126 |
| 126 // Indicates whether the GOP at the beginning or end of the range contains the | 127 // Indicates whether the GOP at the beginning or end of the range contains the |
| 127 // next buffer position. | 128 // next buffer position. |
| 128 bool FirstGOPContainsNextBufferPosition() const; | 129 bool FirstGOPContainsNextBufferPosition() const; |
| 129 bool LastGOPContainsNextBufferPosition() const; | 130 bool LastGOPContainsNextBufferPosition() const; |
| 130 | 131 |
| 131 // Updates |out_buffer| with the next buffer in presentation order. Seek() | 132 // Updates |out_buffer| with the next buffer in presentation order. Seek() |
| 132 // must be called before calls to GetNextBuffer(), and buffers are returned | 133 // must be called before calls to GetNextBuffer(), and buffers are returned |
| 133 // in order from the last call to Seek(). Returns true if |out_buffer| is | 134 // in order from the last call to Seek(). Returns true if |out_buffer| is |
| 134 // filled with a valid buffer, false if there is not enough data to fulfill | 135 // filled with a valid buffer, false if there is not enough data to fulfill |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 | 195 |
| 195 // Returns true if |timestamp| is the timestamp of the next buffer in | 196 // Returns true if |timestamp| is the timestamp of the next buffer in |
| 196 // sequence after |buffers_.back()|, false otherwise. | 197 // sequence after |buffers_.back()|, false otherwise. |
| 197 bool IsNextInSequence(DecodeTimestamp timestamp, bool is_key_frame) const; | 198 bool IsNextInSequence(DecodeTimestamp timestamp, bool is_key_frame) const; |
| 198 | 199 |
| 199 // Adds all buffers which overlap [start, end) to the end of |buffers|. If | 200 // Adds all buffers which overlap [start, end) to the end of |buffers|. If |
| 200 // no buffers exist in the range returns false, true otherwise. | 201 // no buffers exist in the range returns false, true otherwise. |
| 201 bool GetBuffersInRange(DecodeTimestamp start, DecodeTimestamp end, | 202 bool GetBuffersInRange(DecodeTimestamp start, DecodeTimestamp end, |
| 202 BufferQueue* buffers); | 203 BufferQueue* buffers); |
| 203 | 204 |
| 204 int size_in_bytes() const { return size_in_bytes_; } | 205 size_t size_in_bytes() const { return size_in_bytes_; } |
| 205 | 206 |
| 206 private: | 207 private: |
| 207 typedef std::map<DecodeTimestamp, int> KeyframeMap; | 208 typedef std::map<DecodeTimestamp, int> KeyframeMap; |
| 208 | 209 |
| 209 // Called during AppendBuffersToEnd to adjust estimated duration at the | 210 // Called during AppendBuffersToEnd to adjust estimated duration at the |
| 210 // end of the last append to match the delta in timestamps between | 211 // end of the last append to match the delta in timestamps between |
| 211 // the last append and the upcoming append. This is a workaround for | 212 // the last append and the upcoming append. This is a workaround for |
| 212 // WebM media where a duration is not always specified. | 213 // WebM media where a duration is not always specified. |
| 213 void AdjustEstimatedDurationForNewAppend(const BufferQueue& new_buffers); | 214 void AdjustEstimatedDurationForNewAppend(const BufferQueue& new_buffers); |
| 214 | 215 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 // does not start at the beginning of a media segment, which can only happen | 278 // does not start at the beginning of a media segment, which can only happen |
| 278 // garbage collection or after an end overlap that results in a split range | 279 // garbage collection or after an end overlap that results in a split range |
| 279 // (we don't have a way of knowing the media segment timestamp for the new | 280 // (we don't have a way of knowing the media segment timestamp for the new |
| 280 // range). | 281 // range). |
| 281 DecodeTimestamp media_segment_start_time_; | 282 DecodeTimestamp media_segment_start_time_; |
| 282 | 283 |
| 283 // Called to get the largest interbuffer distance seen so far in the stream. | 284 // Called to get the largest interbuffer distance seen so far in the stream. |
| 284 InterbufferDistanceCB interbuffer_distance_cb_; | 285 InterbufferDistanceCB interbuffer_distance_cb_; |
| 285 | 286 |
| 286 // Stores the amount of memory taken up by the data in |buffers_|. | 287 // Stores the amount of memory taken up by the data in |buffers_|. |
| 287 int size_in_bytes_; | 288 size_t size_in_bytes_; |
| 288 | 289 |
| 289 DISALLOW_COPY_AND_ASSIGN(SourceBufferRange); | 290 DISALLOW_COPY_AND_ASSIGN(SourceBufferRange); |
| 290 }; | 291 }; |
| 291 | 292 |
| 292 } // namespace media | 293 } // namespace media |
| 293 | 294 |
| 294 #endif // MEDIA_FILTERS_SOURCE_BUFFER_RANGE_H_ | 295 #endif // MEDIA_FILTERS_SOURCE_BUFFER_RANGE_H_ |
| OLD | NEW |