| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 class CONTENT_EXPORT VideoCaptureBufferPool | 44 class CONTENT_EXPORT VideoCaptureBufferPool |
| 45 : public base::RefCountedThreadSafe<VideoCaptureBufferPool> { | 45 : public base::RefCountedThreadSafe<VideoCaptureBufferPool> { |
| 46 public: | 46 public: |
| 47 static const int kInvalidId; | 47 static const int kInvalidId; |
| 48 | 48 |
| 49 // Abstraction of a pool's buffer data buffer and size for clients. | 49 // Abstraction of a pool's buffer data buffer and size for clients. |
| 50 // TODO(emircan): See https://crbug.com/521059, refactor this class. | 50 // TODO(emircan): See https://crbug.com/521059, refactor this class. |
| 51 class BufferHandle { | 51 class BufferHandle { |
| 52 public: | 52 public: |
| 53 virtual ~BufferHandle() {} | 53 virtual ~BufferHandle() {} |
| 54 virtual size_t size() const = 0; | 54 virtual gfx::Size dimensions() const = 0; |
| 55 virtual size_t mapped_size() const = 0; |
| 55 virtual void* data(int plane) = 0; | 56 virtual void* data(int plane) = 0; |
| 56 virtual ClientBuffer AsClientBuffer(int plane) = 0; | 57 virtual ClientBuffer AsClientBuffer(int plane) = 0; |
| 57 #if defined(OS_POSIX) | 58 #if defined(OS_POSIX) |
| 58 virtual base::FileDescriptor AsPlatformFile() = 0; | 59 virtual base::FileDescriptor AsPlatformFile() = 0; |
| 59 #endif | 60 #endif |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 explicit VideoCaptureBufferPool(int count); | 63 explicit VideoCaptureBufferPool(int count); |
| 63 | 64 |
| 64 // One-time (per client/per-buffer) initialization to share a particular | 65 // One-time (per client/per-buffer) initialization to share a particular |
| 65 // buffer to a process. The size of the allocation is returned as | 66 // buffer to a process. The shared handle is returned as |new_handle|. |
| 66 // |memory_size|. | 67 bool ShareToProcess(int buffer_id, |
| 67 base::SharedMemoryHandle ShareToProcess(int buffer_id, | 68 int plane, |
| 68 base::ProcessHandle process_handle, | 69 base::ProcessHandle process_handle, |
| 69 size_t* memory_size); | 70 void* new_handle); |
| 70 | 71 |
| 71 // Try and obtain a BufferHandle for |buffer_id|. | 72 // Try and obtain a BufferHandle for |buffer_id|. |
| 72 scoped_ptr<BufferHandle> GetBufferHandle(int buffer_id); | 73 scoped_ptr<BufferHandle> GetBufferHandle(int buffer_id); |
| 73 | 74 |
| 74 // Reserve or allocate a buffer to support a packed frame of |dimensions| of | 75 // Reserve or allocate a buffer to support a packed frame of |dimensions| of |
| 75 // pixel |format| and return its id. This will fail (returning kInvalidId) if | 76 // pixel |format| and return its id. This will fail (returning kInvalidId) if |
| 76 // the pool already is at its |count| limit of the number of allocations, and | 77 // the pool already is at its |count| limit of the number of allocations, and |
| 77 // all allocated buffers are in use by the producer and/or consumers. | 78 // all allocated buffers are in use by the producer and/or consumers. |
| 78 // | 79 // |
| 79 // If successful, the reserved buffer remains reserved (and writable by the | 80 // If successful, the reserved buffer remains reserved (and writable by the |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 storage_type_ = storage_type; | 138 storage_type_ = storage_type; |
| 138 } | 139 } |
| 139 bool held_by_producer() const { return held_by_producer_; } | 140 bool held_by_producer() const { return held_by_producer_; } |
| 140 void set_held_by_producer(bool value) { held_by_producer_ = value; } | 141 void set_held_by_producer(bool value) { held_by_producer_ = value; } |
| 141 int consumer_hold_count() const { return consumer_hold_count_; } | 142 int consumer_hold_count() const { return consumer_hold_count_; } |
| 142 void set_consumer_hold_count(int value) { consumer_hold_count_ = value; } | 143 void set_consumer_hold_count(int value) { consumer_hold_count_ = value; } |
| 143 | 144 |
| 144 // Returns a handle to the underlying storage, be that a block of Shared | 145 // Returns a handle to the underlying storage, be that a block of Shared |
| 145 // Memory, or a GpuMemoryBuffer. | 146 // Memory, or a GpuMemoryBuffer. |
| 146 virtual scoped_ptr<BufferHandle> GetBufferHandle() = 0; | 147 virtual scoped_ptr<BufferHandle> GetBufferHandle() = 0; |
| 147 // The actual size of the underlying backing resource. | |
| 148 virtual size_t mapped_size() const = 0; | |
| 149 | 148 |
| 150 virtual bool ShareToProcess(base::ProcessHandle process_handle, | 149 virtual bool ShareToProcess(int plane, |
| 151 base::SharedMemoryHandle* new_handle) = 0; | 150 base::ProcessHandle process_handle, |
| 151 void* new_handle) = 0; |
| 152 | 152 |
| 153 private: | 153 private: |
| 154 size_t pixel_count_; | 154 size_t pixel_count_; |
| 155 media::VideoCapturePixelFormat pixel_format_; | 155 media::VideoCapturePixelFormat pixel_format_; |
| 156 media::VideoPixelStorage storage_type_; | 156 media::VideoPixelStorage storage_type_; |
| 157 // Indicates whether this Tracker is currently referenced by the producer. | 157 // Indicates whether this Tracker is currently referenced by the producer. |
| 158 bool held_by_producer_; | 158 bool held_by_producer_; |
| 159 // Number of consumer processes which hold this Tracker. | 159 // Number of consumer processes which hold this Tracker. |
| 160 int consumer_hold_count_; | 160 int consumer_hold_count_; |
| 161 }; | 161 }; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 182 // The buffers, indexed by the first parameter, a buffer id. | 182 // The buffers, indexed by the first parameter, a buffer id. |
| 183 using TrackerMap = std::map<int, Tracker*>; | 183 using TrackerMap = std::map<int, Tracker*>; |
| 184 TrackerMap trackers_; | 184 TrackerMap trackers_; |
| 185 | 185 |
| 186 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureBufferPool); | 186 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureBufferPool); |
| 187 }; | 187 }; |
| 188 | 188 |
| 189 } // namespace content | 189 } // namespace content |
| 190 | 190 |
| 191 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_BUFFER_POOL_H_ | 191 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_BUFFER_POOL_H_ |
| OLD | NEW |