| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_BLINK_MULTIBUFFER_READER_H_ | 5 #ifndef MEDIA_BLINK_MULTIBUFFER_READER_H_ |
| 6 #define MEDIA_BLINK_MULTIBUFFER_READER_H_ | 6 #define MEDIA_BLINK_MULTIBUFFER_READER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 // stop until we fall below preload_low bytes. Note that preload can be | 71 // stop until we fall below preload_low bytes. Note that preload can be |
| 72 // set higher than max_buffer_forward, but the result is usually that | 72 // set higher than max_buffer_forward, but the result is usually that |
| 73 // some blocks will be freed between the current position and the preload | 73 // some blocks will be freed between the current position and the preload |
| 74 // position. | 74 // position. |
| 75 void SetPreload(int64_t preload_high, int64_t preload_low); | 75 void SetPreload(int64_t preload_high, int64_t preload_low); |
| 76 | 76 |
| 77 // Change how much data we pin to the cache. | 77 // Change how much data we pin to the cache. |
| 78 // The range [current_position - backward ... current_position + forward) | 78 // The range [current_position - backward ... current_position + forward) |
| 79 // will be locked in the cache. Calling Wait() or TryRead() with values | 79 // will be locked in the cache. Calling Wait() or TryRead() with values |
| 80 // larger than |forward| is not supported. | 80 // larger than |forward| is not supported. |
| 81 void SetMaxBuffer(int64_t backward, int64_t forward); | 81 void SetPinRange(int64_t backward, int64_t forward); |
| 82 |
| 83 // Set how much memory usage we target. This memory is added to the global |
| 84 // LRU and shared between all multibuffers. We may end up using more memory |
| 85 // if no memory can be freed due to pinning. |
| 86 void SetMaxBuffer(int64_t bytes); |
| 82 | 87 |
| 83 // Returns true if we are currently loading data. | 88 // Returns true if we are currently loading data. |
| 84 bool IsLoading() const; | 89 bool IsLoading() const; |
| 85 | 90 |
| 86 // Reader implementation. | 91 // Reader implementation. |
| 87 void NotifyAvailableRange(const Interval<MultiBufferBlockId>& range) override; | 92 void NotifyAvailableRange(const Interval<MultiBufferBlockId>& range) override; |
| 88 | 93 |
| 89 // Getters | 94 // Getters |
| 90 int64_t preload_high() const { return preload_high_; } | 95 int64_t preload_high() const { return preload_high_; } |
| 91 int64_t preload_low() const { return preload_low_; } | 96 int64_t preload_low() const { return preload_low_; } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 134 |
| 130 // Defer reading once we have this much data. | 135 // Defer reading once we have this much data. |
| 131 int64_t preload_high_; | 136 int64_t preload_high_; |
| 132 // Stop deferring once we have this much data. | 137 // Stop deferring once we have this much data. |
| 133 int64_t preload_low_; | 138 int64_t preload_low_; |
| 134 | 139 |
| 135 // Pin this much data in the cache from the current position. | 140 // Pin this much data in the cache from the current position. |
| 136 int64_t max_buffer_forward_; | 141 int64_t max_buffer_forward_; |
| 137 int64_t max_buffer_backward_; | 142 int64_t max_buffer_backward_; |
| 138 | 143 |
| 144 // The amount of buffer we've added to the global LRU. |
| 145 int64_t current_buffer_size_; |
| 146 |
| 139 // Currently pinned range. | 147 // Currently pinned range. |
| 140 Interval<MultiBuffer::BlockId> pinned_range_; | 148 Interval<MultiBuffer::BlockId> pinned_range_; |
| 141 | 149 |
| 142 // Current position in bytes. | 150 // Current position in bytes. |
| 143 int64_t pos_; | 151 int64_t pos_; |
| 144 | 152 |
| 145 // [block(pos_)..preload_pos_) are known to be in the cache. | 153 // [block(pos_)..preload_pos_) are known to be in the cache. |
| 146 // preload_pos_ is only allowed to point to a filled | 154 // preload_pos_ is only allowed to point to a filled |
| 147 // cache position if it is equal to end_ or pos_+preload_. | 155 // cache position if it is equal to end_ or pos_+preload_. |
| 148 // This is a pointer to a slot in the cache, so the unit is | 156 // This is a pointer to a slot in the cache, so the unit is |
| 149 // blocks. | 157 // blocks. |
| 150 MultiBufferBlockId preload_pos_; | 158 MultiBufferBlockId preload_pos_; |
| 151 | 159 |
| 152 // True if we've requested data from the cache by calling WaitFor(). | 160 // True if we've requested data from the cache by calling WaitFor(). |
| 153 bool loading_; | 161 bool loading_; |
| 154 | 162 |
| 155 // When Available() > current_wait_size_ we call cb_. | 163 // When Available() > current_wait_size_ we call cb_. |
| 156 int64_t current_wait_size_; | 164 int64_t current_wait_size_; |
| 157 base::Closure cb_; | 165 base::Closure cb_; |
| 158 | 166 |
| 159 // Progress callback. | 167 // Progress callback. |
| 160 base::Callback<void(int64_t, int64_t)> progress_callback_; | 168 base::Callback<void(int64_t, int64_t)> progress_callback_; |
| 161 | 169 |
| 162 base::WeakPtrFactory<MultiBufferReader> weak_factory_; | 170 base::WeakPtrFactory<MultiBufferReader> weak_factory_; |
| 163 }; | 171 }; |
| 164 | 172 |
| 165 } // namespace media | 173 } // namespace media |
| 166 | 174 |
| 167 #endif // MEDIA_BLINK_MULTIBUFFER_READER_H_ | 175 #endif // MEDIA_BLINK_MULTIBUFFER_READER_H_ |
| OLD | NEW |