| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_BUFFER_POOL_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_BUFFER_POOL_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_BUFFER_POOL_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_BUFFER_POOL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // | 76 // |
| 77 // If successful, the reserved buffer remains reserved (and writable by the | 77 // If successful, the reserved buffer remains reserved (and writable by the |
| 78 // producer) until ownership is transferred either to the consumer via | 78 // producer) until ownership is transferred either to the consumer via |
| 79 // HoldForConsumers(), or back to the pool with | 79 // HoldForConsumers(), or back to the pool with |
| 80 // RelinquishProducerReservation(). | 80 // RelinquishProducerReservation(). |
| 81 // | 81 // |
| 82 // On occasion, this call will decide to free an old buffer to make room for a | 82 // On occasion, this call will decide to free an old buffer to make room for a |
| 83 // new allocation at a larger size. If so, the ID of the destroyed buffer is | 83 // new allocation at a larger size. If so, the ID of the destroyed buffer is |
| 84 // returned via |buffer_id_to_drop|. | 84 // returned via |buffer_id_to_drop|. |
| 85 int ReserveForProducer(media::VideoPixelFormat format, | 85 int ReserveForProducer(media::VideoPixelFormat format, |
| 86 media::VideoPixelStorage storage, |
| 86 const gfx::Size& dimensions, | 87 const gfx::Size& dimensions, |
| 87 int* buffer_id_to_drop); | 88 int* buffer_id_to_drop); |
| 88 | 89 |
| 89 // Indicate that a buffer held for the producer should be returned back to the | 90 // Indicate that a buffer held for the producer should be returned back to the |
| 90 // pool without passing on to the consumer. This effectively is the opposite | 91 // pool without passing on to the consumer. This effectively is the opposite |
| 91 // of ReserveForProducer(). | 92 // of ReserveForProducer(). |
| 92 void RelinquishProducerReservation(int buffer_id); | 93 void RelinquishProducerReservation(int buffer_id); |
| 93 | 94 |
| 94 // Transfer a buffer from producer to consumer ownership. | 95 // Transfer a buffer from producer to consumer ownership. |
| 95 // |buffer_id| must be a buffer index previously returned by | 96 // |buffer_id| must be a buffer index previously returned by |
| (...skipping 13 matching lines...) Expand all Loading... |
| 109 class GpuMemoryBufferTracker; | 110 class GpuMemoryBufferTracker; |
| 110 class SharedMemTracker; | 111 class SharedMemTracker; |
| 111 // Generic class to keep track of the state of a given mappable resource. Each | 112 // Generic class to keep track of the state of a given mappable resource. Each |
| 112 // Tracker carries indication of pixel format and storage type. | 113 // Tracker carries indication of pixel format and storage type. |
| 113 class Tracker { | 114 class Tracker { |
| 114 public: | 115 public: |
| 115 static scoped_ptr<Tracker> CreateTracker(bool use_gmb); | 116 static scoped_ptr<Tracker> CreateTracker(bool use_gmb); |
| 116 | 117 |
| 117 Tracker() | 118 Tracker() |
| 118 : pixel_count_(0), held_by_producer_(false), consumer_hold_count_(0) {} | 119 : pixel_count_(0), held_by_producer_(false), consumer_hold_count_(0) {} |
| 119 virtual bool Init(media::VideoFrame::Format format, | 120 virtual bool Init(media::VideoPixelFormat format, |
| 120 media::VideoFrame::StorageType storage_type, | 121 media::VideoPixelStorage storage_type, |
| 121 const gfx::Size& dimensions) = 0; | 122 const gfx::Size& dimensions) = 0; |
| 122 virtual ~Tracker(); | 123 virtual ~Tracker(); |
| 123 | 124 |
| 124 size_t pixel_count() const { return pixel_count_; } | 125 size_t pixel_count() const { return pixel_count_; } |
| 125 void set_pixel_count(size_t count) { pixel_count_ = count; } | 126 void set_pixel_count(size_t count) { pixel_count_ = count; } |
| 126 media::VideoFrame::Format pixel_format() const { return pixel_format_; } | 127 media::VideoPixelFormat pixel_format() const { return pixel_format_; } |
| 127 void set_pixel_format(media::VideoFrame::Format format) { | 128 void set_pixel_format(media::VideoPixelFormat format) { |
| 128 pixel_format_ = format; | 129 pixel_format_ = format; |
| 129 } | 130 } |
| 130 media::VideoFrame::StorageType storage_type() const { | 131 media::VideoPixelStorage storage_type() const { |
| 131 return storage_type_; | 132 return storage_type_; |
| 132 } | 133 } |
| 133 void set_storage_type(media::VideoFrame::StorageType storage_type) { | 134 void set_storage_type(media::VideoPixelStorage storage_type) { |
| 134 storage_type_ = storage_type; | 135 storage_type_ = storage_type; |
| 135 } | 136 } |
| 136 bool held_by_producer() const { return held_by_producer_; } | 137 bool held_by_producer() const { return held_by_producer_; } |
| 137 void set_held_by_producer(bool value) { held_by_producer_ = value; } | 138 void set_held_by_producer(bool value) { held_by_producer_ = value; } |
| 138 int consumer_hold_count() const { return consumer_hold_count_; } | 139 int consumer_hold_count() const { return consumer_hold_count_; } |
| 139 void set_consumer_hold_count(int value) { consumer_hold_count_ = value; } | 140 void set_consumer_hold_count(int value) { consumer_hold_count_ = value; } |
| 140 | 141 |
| 141 // Returns a handle to the underlying storage, be that a block of Shared | 142 // Returns a handle to the underlying storage, be that a block of Shared |
| 142 // Memory, or a GpuMemoryBuffer. | 143 // Memory, or a GpuMemoryBuffer. |
| 143 virtual scoped_ptr<BufferHandle> GetBufferHandle() = 0; | 144 virtual scoped_ptr<BufferHandle> GetBufferHandle() = 0; |
| 144 // The actual size of the underlying backing resource. | 145 // The actual size of the underlying backing resource. |
| 145 virtual size_t mapped_size() const = 0; | 146 virtual size_t mapped_size() const = 0; |
| 146 | 147 |
| 147 virtual bool ShareToProcess(base::ProcessHandle process_handle, | 148 virtual bool ShareToProcess(base::ProcessHandle process_handle, |
| 148 base::SharedMemoryHandle* new_handle) = 0; | 149 base::SharedMemoryHandle* new_handle) = 0; |
| 149 | 150 |
| 150 private: | 151 private: |
| 151 size_t pixel_count_; | 152 size_t pixel_count_; |
| 152 media::VideoFrame::Format pixel_format_; | 153 media::VideoPixelFormat pixel_format_; |
| 153 media::VideoFrame::StorageType storage_type_; | 154 media::VideoPixelStorage storage_type_; |
| 154 // Indicates whether this Tracker is currently referenced by the producer. | 155 // Indicates whether this Tracker is currently referenced by the producer. |
| 155 bool held_by_producer_; | 156 bool held_by_producer_; |
| 156 // Number of consumer processes which hold this Tracker. | 157 // Number of consumer processes which hold this Tracker. |
| 157 int consumer_hold_count_; | 158 int consumer_hold_count_; |
| 158 }; | 159 }; |
| 159 | 160 |
| 160 friend class base::RefCountedThreadSafe<VideoCaptureBufferPool>; | 161 friend class base::RefCountedThreadSafe<VideoCaptureBufferPool>; |
| 161 virtual ~VideoCaptureBufferPool(); | 162 virtual ~VideoCaptureBufferPool(); |
| 162 | 163 |
| 163 int ReserveForProducerInternal(media::VideoPixelFormat format, | 164 int ReserveForProducerInternal(media::VideoPixelFormat format, |
| 165 media::VideoPixelStorage storage, |
| 164 const gfx::Size& dimensions, | 166 const gfx::Size& dimensions, |
| 165 int* tracker_id_to_drop); | 167 int* tracker_id_to_drop); |
| 166 | 168 |
| 167 Tracker* GetTracker(int buffer_id); | 169 Tracker* GetTracker(int buffer_id); |
| 168 | 170 |
| 169 // The max number of buffers that the pool is allowed to have at any moment. | 171 // The max number of buffers that the pool is allowed to have at any moment. |
| 170 const int count_; | 172 const int count_; |
| 171 | 173 |
| 172 // Protects everything below it. | 174 // Protects everything below it. |
| 173 mutable base::Lock lock_; | 175 mutable base::Lock lock_; |
| 174 | 176 |
| 175 // The ID of the next buffer. | 177 // The ID of the next buffer. |
| 176 int next_buffer_id_; | 178 int next_buffer_id_; |
| 177 | 179 |
| 178 // The buffers, indexed by the first parameter, a buffer id. | 180 // The buffers, indexed by the first parameter, a buffer id. |
| 179 using TrackerMap = std::map<int, Tracker*>; | 181 using TrackerMap = std::map<int, Tracker*>; |
| 180 TrackerMap trackers_; | 182 TrackerMap trackers_; |
| 181 | 183 |
| 182 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureBufferPool); | 184 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureBufferPool); |
| 183 }; | 185 }; |
| 184 | 186 |
| 185 } // namespace content | 187 } // namespace content |
| 186 | 188 |
| 187 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_BUFFER_POOL_H_ | 189 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_BUFFER_POOL_H_ |
| OLD | NEW |