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