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_H_ | 5 #ifndef MEDIA_BLINK_MULTIBUFFER_H_ |
6 #define MEDIA_BLINK_MULTIBUFFER_H_ | 6 #define MEDIA_BLINK_MULTIBUFFER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 virtual ~DataProvider() {} | 107 virtual ~DataProvider() {} |
108 | 108 |
109 // Returns the block number that is to be returned | 109 // Returns the block number that is to be returned |
110 // by the next Read() call. | 110 // by the next Read() call. |
111 virtual MultiBufferBlockId Tell() const = 0; | 111 virtual MultiBufferBlockId Tell() const = 0; |
112 | 112 |
113 // Returns true if one (or more) blocks are | 113 // Returns true if one (or more) blocks are |
114 // availble to read. | 114 // availble to read. |
115 virtual bool Available() const = 0; | 115 virtual bool Available() const = 0; |
116 | 116 |
| 117 // Returns how many bytes are available, note that Available() may still |
| 118 // return false even if AvailableBytes() returns a value greater than |
| 119 // zero if less than a full block is available. |
| 120 virtual int64_t AvailableBytes() const = 0; |
| 121 |
117 // Returns the next block. Only valid if Available() | 122 // Returns the next block. Only valid if Available() |
118 // returns true. Last block might be of a smaller size | 123 // returns true. Last block might be of a smaller size |
119 // and after the last block we will get an end-of-stream | 124 // and after the last block we will get an end-of-stream |
120 // DataBuffer. | 125 // DataBuffer. |
121 virtual scoped_refptr<DataBuffer> Read() = 0; | 126 virtual scoped_refptr<DataBuffer> Read() = 0; |
122 | 127 |
123 // Ask the data provider to stop giving us data. | 128 // Ask the data provider to stop giving us data. |
124 // It's ok if the effect is not immediate. | 129 // It's ok if the effect is not immediate. |
125 virtual void SetDeferred(bool deferred) = 0; | 130 virtual void SetDeferred(bool deferred) = 0; |
126 }; | 131 }; |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 // Unpin block 4 & 5: PinRange(4, 6, -1); | 247 // Unpin block 4 & 5: PinRange(4, 6, -1); |
243 void PinRange(const BlockId& from, const BlockId& to, int32_t how_much); | 248 void PinRange(const BlockId& from, const BlockId& to, int32_t how_much); |
244 | 249 |
245 // Calls PinRange for each range in |ranges|, convenience | 250 // Calls PinRange for each range in |ranges|, convenience |
246 // function for applying multiple changes to the pinned ranges. | 251 // function for applying multiple changes to the pinned ranges. |
247 void PinRanges(const IntervalMap<BlockId, int32_t>& ranges); | 252 void PinRanges(const IntervalMap<BlockId, int32_t>& ranges); |
248 | 253 |
249 // Increment max cache size by |size| (counted in blocks). | 254 // Increment max cache size by |size| (counted in blocks). |
250 void IncrementMaxSize(int32_t size); | 255 void IncrementMaxSize(int32_t size); |
251 | 256 |
| 257 // Returns how many bytes have been received by the data providers at position |
| 258 // |block|, which have not yet been submitted to the multibuffer cache. |
| 259 // The returned number should be less than the size of one block. |
| 260 int64_t UncommittedBytesAt(const BlockId& block); |
| 261 |
252 // Caller takes ownership of 'provider', cache will | 262 // Caller takes ownership of 'provider', cache will |
253 // not call it anymore. | 263 // not call it anymore. |
254 std::unique_ptr<DataProvider> RemoveProvider(DataProvider* provider); | 264 std::unique_ptr<DataProvider> RemoveProvider(DataProvider* provider); |
255 | 265 |
256 // Add a writer to this cache. Cache takes ownership, and may | 266 // Add a writer to this cache. Cache takes ownership, and may |
257 // destroy |provider| later. (Not during this call.) | 267 // destroy |provider| later. (Not during this call.) |
258 void AddProvider(std::unique_ptr<DataProvider> provider); | 268 void AddProvider(std::unique_ptr<DataProvider> provider); |
259 | 269 |
260 // Transfer all data from |other| to this. | 270 // Transfer all data from |other| to this. |
261 void MergeFrom(MultiBuffer* other); | 271 void MergeFrom(MultiBuffer* other); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 // and 0 for all blocks that are not. Used to quickly figure out | 348 // and 0 for all blocks that are not. Used to quickly figure out |
339 // ranges of available/unavailable blocks without iterating. | 349 // ranges of available/unavailable blocks without iterating. |
340 IntervalMap<BlockId, int32_t> present_; | 350 IntervalMap<BlockId, int32_t> present_; |
341 | 351 |
342 DISALLOW_COPY_AND_ASSIGN(MultiBuffer); | 352 DISALLOW_COPY_AND_ASSIGN(MultiBuffer); |
343 }; | 353 }; |
344 | 354 |
345 } // namespace media | 355 } // namespace media |
346 | 356 |
347 #endif // MEDIA_BLINK_MULTIBUFFER_H_ | 357 #endif // MEDIA_BLINK_MULTIBUFFER_H_ |
OLD | NEW |