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 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" | 5 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 DCHECK(buffer->held_by_producer); | 121 DCHECK(buffer->held_by_producer); |
122 return buffer_id; | 122 return buffer_id; |
123 } | 123 } |
124 } | 124 } |
125 return -1; // Buffer is not from our pool. | 125 return -1; // Buffer is not from our pool. |
126 } | 126 } |
127 | 127 |
128 scoped_refptr<media::VideoFrame> VideoCaptureBufferPool::ReserveI420VideoFrame( | 128 scoped_refptr<media::VideoFrame> VideoCaptureBufferPool::ReserveI420VideoFrame( |
129 const gfx::Size& size, | 129 const gfx::Size& size, |
130 int rotation) { | 130 int rotation) { |
131 if (static_cast<size_t>(size.GetArea() * 3 / 2) != GetMemorySize()) | 131 if (GetMemorySize() != |
| 132 media::VideoFrame::AllocationSize(media::VideoFrame::I420, size)) { |
132 return NULL; | 133 return NULL; |
| 134 } |
133 | 135 |
134 base::AutoLock lock(lock_); | 136 base::AutoLock lock(lock_); |
135 | 137 |
136 int buffer_id = ReserveForProducerInternal(); | 138 int buffer_id = ReserveForProducerInternal(); |
137 if (buffer_id < 0) | 139 if (buffer_id < 0) |
138 return NULL; | 140 return NULL; |
139 | 141 |
140 base::Closure disposal_handler = base::Bind( | 142 base::Closure disposal_handler = base::Bind( |
141 &VideoCaptureBufferPool::RelinquishProducerReservation, | 143 &VideoCaptureBufferPool::RelinquishProducerReservation, |
142 this, | 144 this, |
143 buffer_id); | 145 buffer_id); |
144 | 146 |
145 Buffer* buffer = buffers_[buffer_id]; | 147 Buffer* buffer = buffers_[buffer_id]; |
146 // Wrap the buffer in a VideoFrame container. | 148 // Wrap the buffer in a VideoFrame container. |
147 scoped_refptr<media::VideoFrame> frame = | 149 scoped_refptr<media::VideoFrame> frame = |
148 media::VideoFrame::WrapExternalSharedMemory( | 150 media::VideoFrame::WrapExternalSharedMemory( |
149 media::VideoFrame::I420, | 151 media::VideoFrame::I420, |
150 size, | 152 size, |
151 gfx::Rect(size), | 153 gfx::Rect(size), |
152 size, | 154 size, |
153 static_cast<uint8*>(buffer->shared_memory.memory()), | 155 static_cast<uint8*>(buffer->shared_memory.memory()), |
| 156 GetMemorySize(), |
154 buffer->shared_memory.handle(), | 157 buffer->shared_memory.handle(), |
155 base::TimeDelta(), | 158 base::TimeDelta(), |
156 disposal_handler); | 159 disposal_handler); |
157 | 160 |
158 if (buffer->rotation != rotation) { | 161 if (buffer->rotation != rotation) { |
159 // TODO(nick): Generalize the |rotation| mechanism. | 162 // TODO(nick): Generalize the |rotation| mechanism. |
160 media::FillYUV(frame.get(), 0, 128, 128); | 163 media::FillYUV(frame.get(), 0, 128, 128); |
161 buffer->rotation = rotation; | 164 buffer->rotation = rotation; |
162 } | 165 } |
163 | 166 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 return buffer_id; | 203 return buffer_id; |
201 } | 204 } |
202 | 205 |
203 bool VideoCaptureBufferPool::IsAllocated() const { | 206 bool VideoCaptureBufferPool::IsAllocated() const { |
204 lock_.AssertAcquired(); | 207 lock_.AssertAcquired(); |
205 return !buffers_.empty(); | 208 return !buffers_.empty(); |
206 } | 209 } |
207 | 210 |
208 } // namespace content | 211 } // namespace content |
209 | 212 |
OLD | NEW |