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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 if (buffer_id < 0) | 137 if (buffer_id < 0) |
138 return NULL; | 138 return NULL; |
139 | 139 |
140 base::Closure disposal_handler = base::Bind( | 140 base::Closure disposal_handler = base::Bind( |
141 &VideoCaptureBufferPool::RelinquishProducerReservation, | 141 &VideoCaptureBufferPool::RelinquishProducerReservation, |
142 this, | 142 this, |
143 buffer_id); | 143 buffer_id); |
144 | 144 |
145 Buffer* buffer = buffers_[buffer_id]; | 145 Buffer* buffer = buffers_[buffer_id]; |
146 // Wrap the buffer in a VideoFrame container. | 146 // Wrap the buffer in a VideoFrame container. |
147 uint8* base_ptr = static_cast<uint8*>(buffer->shared_memory.memory()); | |
148 size_t u_offset = size.GetArea(); | |
149 size_t v_offset = u_offset + u_offset / 4; | |
150 scoped_refptr<media::VideoFrame> frame = | 147 scoped_refptr<media::VideoFrame> frame = |
151 media::VideoFrame::WrapExternalYuvData( | 148 media::VideoFrame::WrapExternalSharedMemory( |
152 media::VideoFrame::YV12, // Actually it's I420, but equivalent here. | 149 media::VideoFrame::I420, |
153 size, gfx::Rect(size), size, | 150 size, |
154 size.width(), // y stride | 151 gfx::Rect(size), |
155 size.width() / 2, // u stride | 152 size, |
156 size.width() / 2, // v stride | 153 static_cast<uint8*>(buffer->shared_memory.memory()), |
157 base_ptr, // y address | |
158 base_ptr + u_offset, // u address | |
159 base_ptr + v_offset, // v address | |
160 base::TimeDelta(), // timestamp (unused). | |
161 buffer->shared_memory.handle(), | 154 buffer->shared_memory.handle(), |
| 155 base::TimeDelta(), |
162 disposal_handler); | 156 disposal_handler); |
163 | 157 |
164 if (buffer->rotation != rotation) { | 158 if (buffer->rotation != rotation) { |
165 // TODO(nick): Generalize the |rotation| mechanism. | 159 // TODO(nick): Generalize the |rotation| mechanism. |
166 media::FillYUV(frame.get(), 0, 128, 128); | 160 media::FillYUV(frame.get(), 0, 128, 128); |
167 buffer->rotation = rotation; | 161 buffer->rotation = rotation; |
168 } | 162 } |
169 | 163 |
170 return frame; | 164 return frame; |
171 } | 165 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 return buffer_id; | 200 return buffer_id; |
207 } | 201 } |
208 | 202 |
209 bool VideoCaptureBufferPool::IsAllocated() const { | 203 bool VideoCaptureBufferPool::IsAllocated() const { |
210 lock_.AssertAcquired(); | 204 lock_.AssertAcquired(); |
211 return !buffers_.empty(); | 205 return !buffers_.empty(); |
212 } | 206 } |
213 | 207 |
214 } // namespace content | 208 } // namespace content |
215 | 209 |
OLD | NEW |