| Index: media/blink/multibuffer.h
|
| diff --git a/media/blink/multibuffer.h b/media/blink/multibuffer.h
|
| index d469d43fc146f5c6c323bb371bfc4ecdbd4853e6..eb3530de7876e748c6e4b58d2e56939609e2fddf 100644
|
| --- a/media/blink/multibuffer.h
|
| +++ b/media/blink/multibuffer.h
|
| @@ -16,6 +16,7 @@
|
| #include "base/containers/hash_tables.h"
|
| #include "base/macros.h"
|
| #include "base/memory/ref_counted.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| #include "media/base/data_buffer.h"
|
| #include "media/blink/interval_map.h"
|
| #include "media/blink/lru.h"
|
| @@ -23,8 +24,14 @@
|
|
|
| namespace media {
|
|
|
| +// Used to identify a block of data in the multibuffer.
|
| +// Our blocks are 32kb (1 << 15), so our maximum cacheable file size
|
| +// is 1 << (15 + 31) = 64Tb
|
| typedef int32_t MultiBufferBlockId;
|
| class MultiBuffer;
|
| +
|
| +// This type is used to identify a block in the LRU, which is shared between
|
| +// multibuffers.
|
| typedef std::pair<MultiBuffer*, MultiBufferBlockId> MultiBufferGlobalBlockId;
|
|
|
| } // namespace media
|
| @@ -72,8 +79,6 @@ const int kMaxWaitForWriterOffset = 5;
|
| // This is the size of the look-behind region.
|
| const int kMaxWaitForReaderOffset = 50;
|
|
|
| -class MultiBuffer;
|
| -
|
| // MultiBuffers are multi-reader multi-writer cache/buffers with
|
| // prefetching and pinning. Data is stored internally in ref-counted
|
| // blocks of identical size. |block_size_shift| is log2 of the block
|
| @@ -119,9 +124,6 @@ class MEDIA_BLINK_EXPORT MultiBuffer {
|
| // DataBuffer.
|
| virtual scoped_refptr<DataBuffer> Read() = 0;
|
|
|
| - // |cb| is called every time Available() becomes true.
|
| - virtual void SetAvailableCallback(const base::Closure& cb) = 0;
|
| -
|
| // Ask the data provider to stop giving us data.
|
| // It's ok if the effect is not immediate.
|
| virtual void SetDeferred(bool deferred) = 0;
|
| @@ -229,8 +231,8 @@ class MEDIA_BLINK_EXPORT MultiBuffer {
|
| // not call it anymore.
|
| scoped_ptr<DataProvider> RemoveProvider(DataProvider* provider);
|
|
|
| - // Add a writer to this cache. Cache takes ownership and
|
| - // may choose to destroy it.
|
| + // Add a writer to this cache. Cache takes ownership, and may
|
| + // destroy |provider| later. (Not during this call.)
|
| void AddProvider(scoped_ptr<DataProvider> provider);
|
|
|
| // Transfer all data from |other| to this.
|
| @@ -240,13 +242,23 @@ class MEDIA_BLINK_EXPORT MultiBuffer {
|
| const DataMap& map() const { return data_; }
|
| int32_t block_size_shift() const { return block_size_shift_; }
|
|
|
| + // Callback which notifies us that a data provider has
|
| + // some data for us. Also called when it might be appropriate
|
| + // for a provider in a deferred state to wake up.
|
| + void OnDataProviderEvent(DataProvider* provider);
|
| +
|
| protected:
|
| // Create a new writer at |pos| and return it.
|
| // Users needs to implemement this method.
|
| - virtual DataProvider* CreateWriter(const BlockId& pos) = 0;
|
| + virtual scoped_ptr<DataProvider> CreateWriter(const BlockId& pos) = 0;
|
|
|
| virtual bool RangeSupported() const = 0;
|
|
|
| + // Called when the cache becomes empty. Implementations can use this
|
| + // as a signal for when we should free this object and any metadata
|
| + // that goes with it.
|
| + virtual void OnEmpty();
|
| +
|
| private:
|
| // For testing.
|
| friend class TestMultiBuffer;
|
| @@ -276,11 +288,6 @@ class MEDIA_BLINK_EXPORT MultiBuffer {
|
| void NotifyAvailableRange(const Interval<MultiBufferBlockId>& observer_range,
|
| const Interval<MultiBufferBlockId>& new_range);
|
|
|
| - // Callback which notifies us that a data provider has
|
| - // some data for us. Also called when it might be apprperiate
|
| - // for a provider in a deferred state to wake up.
|
| - void DataProviderEvent(DataProvider* provider);
|
| -
|
| // Max number of blocks.
|
| int64_t max_size_;
|
|
|
| @@ -295,8 +302,7 @@ class MEDIA_BLINK_EXPORT MultiBuffer {
|
|
|
| // Keeps track of writers by their position.
|
| // The writers are owned by this class.
|
| - // TODO(hubbe): Use ScopedPtrMap here. (must add upper/lower_bound first)
|
| - std::map<BlockId, DataProvider*> writer_index_;
|
| + std::map<BlockId, scoped_ptr<DataProvider>> writer_index_;
|
|
|
| // Gloabally shared LRU, decides which block to free next.
|
| scoped_refptr<GlobalLRU> lru_;
|
| @@ -310,6 +316,8 @@ class MEDIA_BLINK_EXPORT MultiBuffer {
|
| // and 0 for all blocks that are not. Used to quickly figure out
|
| // ranges of available/unavailable blocks without iterating.
|
| IntervalMap<BlockId, int32_t> present_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(MultiBuffer);
|
| };
|
|
|
| } // namespace media
|
|
|