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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 static const int kInvalidId; | 49 static const int kInvalidId; |
50 explicit VideoCaptureBufferPool(int count); | 50 explicit VideoCaptureBufferPool(int count); |
51 | 51 |
52 // One-time (per client/per-buffer) initialization to share a particular | 52 // One-time (per client/per-buffer) initialization to share a particular |
53 // buffer to a process. The size of the allocation is returned as | 53 // buffer to a process. The size of the allocation is returned as |
54 // |memory_size|. | 54 // |memory_size|. |
55 base::SharedMemoryHandle ShareToProcess(int buffer_id, | 55 base::SharedMemoryHandle ShareToProcess(int buffer_id, |
56 base::ProcessHandle process_handle, | 56 base::ProcessHandle process_handle, |
57 size_t* memory_size); | 57 size_t* memory_size); |
58 | 58 |
| 59 // Query the memory parameters of |buffer_id|. Fills in parameters in the |
| 60 // pointer arguments, and returns true iff the buffer exists. |
| 61 bool GetBufferInfo(int buffer_id, void** memory, size_t* size); |
| 62 |
59 // Reserve or allocate a buffer of at least |size| bytes and return its id. | 63 // Reserve or allocate a buffer of at least |size| bytes and return its id. |
60 // This will fail (returning kInvalidId) if the pool already is at its |count| | 64 // This will fail (returning kInvalidId) if the pool already is at its |count| |
61 // limit of the number of allocations, and all allocated buffers are in use by | 65 // limit of the number of allocations, and all allocated buffers are in use by |
62 // the producer and/or consumers. | 66 // the producer and/or consumers. |
63 // | 67 // |
64 // If successful, the reserved buffer remains reserved (and writable by the | 68 // If successful, the reserved buffer remains reserved (and writable by the |
65 // producer) until ownership is transferred either to the consumer via | 69 // producer) until ownership is transferred either to the consumer via |
66 // HoldForConsumers(), or back to the pool with | 70 // HoldForConsumers(), or back to the pool with |
67 // RelinquishProducerReservation(). | 71 // RelinquishProducerReservation(). |
68 // | 72 // |
(...skipping 10 matching lines...) Expand all Loading... |
79 // Transfer a buffer from producer to consumer ownership. | 83 // Transfer a buffer from producer to consumer ownership. |
80 // |buffer_id| must be a buffer index previously returned by | 84 // |buffer_id| must be a buffer index previously returned by |
81 // ReserveForProducer(), and not already passed to HoldForConsumers(). | 85 // ReserveForProducer(), and not already passed to HoldForConsumers(). |
82 void HoldForConsumers(int buffer_id, int num_clients); | 86 void HoldForConsumers(int buffer_id, int num_clients); |
83 | 87 |
84 // Indicate that one or more consumers are done with a particular buffer. This | 88 // Indicate that one or more consumers are done with a particular buffer. This |
85 // effectively is the opposite of HoldForConsumers(). Once the consumers are | 89 // effectively is the opposite of HoldForConsumers(). Once the consumers are |
86 // done, a buffer is returned to the pool for reuse. | 90 // done, a buffer is returned to the pool for reuse. |
87 void RelinquishConsumerHold(int buffer_id, int num_clients); | 91 void RelinquishConsumerHold(int buffer_id, int num_clients); |
88 | 92 |
89 // Detect whether a particular SharedMemoryHandle is exported by a buffer that | |
90 // belongs to this pool -- that is, whether it was reserved by an earlier call | |
91 // to ReserveForProducer(). If so, return its buffer_id. If not, return | |
92 // kInvalidId, indicating the buffer is not recognized (it may be a valid | |
93 // frame, but we didn't allocate it). | |
94 int RecognizeReservedBuffer(base::SharedMemoryHandle maybe_belongs_to_pool); | |
95 | |
96 // Return a buffer wrapped in a useful type. If a reallocation occurred, the | |
97 // ID of the destroyed buffer is returned via |buffer_id_to_drop|. | |
98 scoped_refptr<media::VideoFrame> ReserveI420VideoFrame( | |
99 const gfx::Size& size, | |
100 int rotation, | |
101 int* buffer_id_to_drop); | |
102 | |
103 int count() const { return count_; } | 93 int count() const { return count_; } |
104 | 94 |
105 private: | 95 private: |
106 friend class base::RefCountedThreadSafe<VideoCaptureBufferPool>; | 96 friend class base::RefCountedThreadSafe<VideoCaptureBufferPool>; |
107 | 97 |
108 // Per-buffer state. | 98 // Per-buffer state. |
109 struct Buffer { | 99 struct Buffer { |
110 Buffer(); | 100 Buffer(); |
111 | 101 |
112 // The memory created to be shared with renderer processes. | 102 // The memory created to be shared with renderer processes. |
113 base::SharedMemory shared_memory; | 103 base::SharedMemory shared_memory; |
114 | 104 |
115 // Rotation in degrees of the buffer. | |
116 // | |
117 // TODO(jiayl): Move this out of this class. Clients can track rotation | |
118 // state themselves by means of a map keyed by buffer_id. | |
119 int rotation; | |
120 | |
121 // Tracks whether this buffer is currently referenced by the producer. | 105 // Tracks whether this buffer is currently referenced by the producer. |
122 bool held_by_producer; | 106 bool held_by_producer; |
123 | 107 |
124 // Number of consumer processes which hold this shared memory. | 108 // Number of consumer processes which hold this shared memory. |
125 int consumer_hold_count; | 109 int consumer_hold_count; |
126 }; | 110 }; |
127 | 111 |
128 typedef std::map<int, Buffer*> BufferMap; | 112 typedef std::map<int, Buffer*> BufferMap; |
129 | 113 |
130 virtual ~VideoCaptureBufferPool(); | 114 virtual ~VideoCaptureBufferPool(); |
(...skipping 13 matching lines...) Expand all Loading... |
144 | 128 |
145 // The buffers, indexed by |buffer_id|. | 129 // The buffers, indexed by |buffer_id|. |
146 BufferMap buffers_; | 130 BufferMap buffers_; |
147 | 131 |
148 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureBufferPool); | 132 DISALLOW_IMPLICIT_CONSTRUCTORS(VideoCaptureBufferPool); |
149 }; | 133 }; |
150 | 134 |
151 } // namespace content | 135 } // namespace content |
152 | 136 |
153 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_BUFFER_POOL_H_ | 137 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_BUFFER_POOL_H_ |
OLD | NEW |