| 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 |
| 11 #include <limits> | 11 #include <limits> |
| 12 #include <map> | 12 #include <map> |
| 13 #include <memory> |
| 13 #include <set> | 14 #include <set> |
| 14 #include <vector> | 15 #include <vector> |
| 15 | 16 |
| 16 #include "base/callback.h" | 17 #include "base/callback.h" |
| 17 #include "base/containers/hash_tables.h" | 18 #include "base/containers/hash_tables.h" |
| 18 #include "base/hash.h" | 19 #include "base/hash.h" |
| 19 #include "base/macros.h" | 20 #include "base/macros.h" |
| 20 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
| 21 #include "base/memory/scoped_ptr.h" | |
| 22 #include "base/single_thread_task_runner.h" | 22 #include "base/single_thread_task_runner.h" |
| 23 #include "build/build_config.h" | 23 #include "build/build_config.h" |
| 24 #include "media/base/data_buffer.h" | 24 #include "media/base/data_buffer.h" |
| 25 #include "media/blink/interval_map.h" | 25 #include "media/blink/interval_map.h" |
| 26 #include "media/blink/lru.h" | 26 #include "media/blink/lru.h" |
| 27 #include "media/blink/media_blink_export.h" | 27 #include "media/blink/media_blink_export.h" |
| 28 | 28 |
| 29 namespace media { | 29 namespace media { |
| 30 | 30 |
| 31 // Used to identify a block of data in the multibuffer. | 31 // Used to identify a block of data in the multibuffer. |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 | 244 |
| 245 // Calls PinRange for each range in |ranges|, convenience | 245 // Calls PinRange for each range in |ranges|, convenience |
| 246 // function for applying multiple changes to the pinned ranges. | 246 // function for applying multiple changes to the pinned ranges. |
| 247 void PinRanges(const IntervalMap<BlockId, int32_t>& ranges); | 247 void PinRanges(const IntervalMap<BlockId, int32_t>& ranges); |
| 248 | 248 |
| 249 // Increment max cache size by |size| (counted in blocks). | 249 // Increment max cache size by |size| (counted in blocks). |
| 250 void IncrementMaxSize(int32_t size); | 250 void IncrementMaxSize(int32_t size); |
| 251 | 251 |
| 252 // Caller takes ownership of 'provider', cache will | 252 // Caller takes ownership of 'provider', cache will |
| 253 // not call it anymore. | 253 // not call it anymore. |
| 254 scoped_ptr<DataProvider> RemoveProvider(DataProvider* provider); | 254 std::unique_ptr<DataProvider> RemoveProvider(DataProvider* provider); |
| 255 | 255 |
| 256 // Add a writer to this cache. Cache takes ownership, and may | 256 // Add a writer to this cache. Cache takes ownership, and may |
| 257 // destroy |provider| later. (Not during this call.) | 257 // destroy |provider| later. (Not during this call.) |
| 258 void AddProvider(scoped_ptr<DataProvider> provider); | 258 void AddProvider(std::unique_ptr<DataProvider> provider); |
| 259 | 259 |
| 260 // Transfer all data from |other| to this. | 260 // Transfer all data from |other| to this. |
| 261 void MergeFrom(MultiBuffer* other); | 261 void MergeFrom(MultiBuffer* other); |
| 262 | 262 |
| 263 // Accessors. | 263 // Accessors. |
| 264 const DataMap& map() const { return data_; } | 264 const DataMap& map() const { return data_; } |
| 265 int32_t block_size_shift() const { return block_size_shift_; } | 265 int32_t block_size_shift() const { return block_size_shift_; } |
| 266 | 266 |
| 267 // Callback which notifies us that a data provider has | 267 // Callback which notifies us that a data provider has |
| 268 // some data for us. Also called when it might be appropriate | 268 // some data for us. Also called when it might be appropriate |
| 269 // for a provider in a deferred state to wake up. | 269 // for a provider in a deferred state to wake up. |
| 270 void OnDataProviderEvent(DataProvider* provider); | 270 void OnDataProviderEvent(DataProvider* provider); |
| 271 | 271 |
| 272 protected: | 272 protected: |
| 273 // Create a new writer at |pos| and return it. | 273 // Create a new writer at |pos| and return it. |
| 274 // Users needs to implemement this method. | 274 // Users needs to implemement this method. |
| 275 virtual scoped_ptr<DataProvider> CreateWriter(const BlockId& pos) = 0; | 275 virtual std::unique_ptr<DataProvider> CreateWriter(const BlockId& pos) = 0; |
| 276 | 276 |
| 277 virtual bool RangeSupported() const = 0; | 277 virtual bool RangeSupported() const = 0; |
| 278 | 278 |
| 279 // Called when the cache becomes empty. Implementations can use this | 279 // Called when the cache becomes empty. Implementations can use this |
| 280 // as a signal for when we should free this object and any metadata | 280 // as a signal for when we should free this object and any metadata |
| 281 // that goes with it. | 281 // that goes with it. |
| 282 virtual void OnEmpty(); | 282 virtual void OnEmpty(); |
| 283 | 283 |
| 284 private: | 284 private: |
| 285 // For testing. | 285 // For testing. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 int32_t block_size_shift_; | 317 int32_t block_size_shift_; |
| 318 | 318 |
| 319 // Stores the actual data. | 319 // Stores the actual data. |
| 320 DataMap data_; | 320 DataMap data_; |
| 321 | 321 |
| 322 // Keeps track of readers waiting for data. | 322 // Keeps track of readers waiting for data. |
| 323 std::map<MultiBufferBlockId, std::set<Reader*>> readers_; | 323 std::map<MultiBufferBlockId, std::set<Reader*>> readers_; |
| 324 | 324 |
| 325 // Keeps track of writers by their position. | 325 // Keeps track of writers by their position. |
| 326 // The writers are owned by this class. | 326 // The writers are owned by this class. |
| 327 std::map<BlockId, scoped_ptr<DataProvider>> writer_index_; | 327 std::map<BlockId, std::unique_ptr<DataProvider>> writer_index_; |
| 328 | 328 |
| 329 // Gloabally shared LRU, decides which block to free next. | 329 // Gloabally shared LRU, decides which block to free next. |
| 330 scoped_refptr<GlobalLRU> lru_; | 330 scoped_refptr<GlobalLRU> lru_; |
| 331 | 331 |
| 332 // Keeps track of what blocks are pinned. If block p is pinned, | 332 // Keeps track of what blocks are pinned. If block p is pinned, |
| 333 // then pinned_[p] > 0. Pinned blocks cannot be freed and should not | 333 // then pinned_[p] > 0. Pinned blocks cannot be freed and should not |
| 334 // be present in |lru_|. | 334 // be present in |lru_|. |
| 335 IntervalMap<BlockId, int32_t> pinned_; | 335 IntervalMap<BlockId, int32_t> pinned_; |
| 336 | 336 |
| 337 // present_[block] should be 1 for all blocks that are present | 337 // present_[block] should be 1 for all blocks that are present |
| 338 // and 0 for all blocks that are not. Used to quickly figure out | 338 // and 0 for all blocks that are not. Used to quickly figure out |
| 339 // ranges of available/unavailable blocks without iterating. | 339 // ranges of available/unavailable blocks without iterating. |
| 340 IntervalMap<BlockId, int32_t> present_; | 340 IntervalMap<BlockId, int32_t> present_; |
| 341 | 341 |
| 342 DISALLOW_COPY_AND_ASSIGN(MultiBuffer); | 342 DISALLOW_COPY_AND_ASSIGN(MultiBuffer); |
| 343 }; | 343 }; |
| 344 | 344 |
| 345 } // namespace media | 345 } // namespace media |
| 346 | 346 |
| 347 #endif // MEDIA_BLINK_MULTIBUFFER_H_ | 347 #endif // MEDIA_BLINK_MULTIBUFFER_H_ |
| OLD | NEW |