OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_device_client.h" | 5 #include "content/browser/renderer_host/media/video_capture_device_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
10 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" | 10 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 rotation_mode = libyuv::kRotate270; | 98 rotation_mode = libyuv::kRotate270; |
99 | 99 |
100 const gfx::Size dimensions(destination_width, destination_height); | 100 const gfx::Size dimensions(destination_width, destination_height); |
101 if (!VideoFrame::IsValidConfig(VideoFrame::I420, | 101 if (!VideoFrame::IsValidConfig(VideoFrame::I420, |
102 dimensions, | 102 dimensions, |
103 gfx::Rect(dimensions), | 103 gfx::Rect(dimensions), |
104 dimensions)) { | 104 dimensions)) { |
105 return; | 105 return; |
106 } | 106 } |
107 | 107 |
108 scoped_refptr<Buffer> buffer = ReserveOutputBuffer(VideoFrame::I420, | 108 const VideoCaptureFormat format(dimensions, 0.0, media::PIXEL_FORMAT_I420); |
109 dimensions); | 109 scoped_refptr<Buffer> buffer = ReserveOutputBuffer(format); |
110 if (!buffer.get()) | 110 if (!buffer.get()) |
111 return; | 111 return; |
112 | 112 |
113 uint8* const yplane = reinterpret_cast<uint8*>(buffer->data()); | 113 uint8* const yplane = reinterpret_cast<uint8*>(buffer->data()); |
114 uint8* const uplane = | 114 uint8* const uplane = |
115 yplane + VideoFrame::PlaneAllocationSize(VideoFrame::I420, | 115 yplane + VideoFrame::PlaneAllocationSize(VideoFrame::I420, |
116 VideoFrame::kYPlane, dimensions); | 116 VideoFrame::kYPlane, dimensions); |
117 uint8* const vplane = | 117 uint8* const vplane = |
118 uplane + VideoFrame::PlaneAllocationSize(VideoFrame::I420, | 118 uplane + VideoFrame::PlaneAllocationSize(VideoFrame::I420, |
119 VideoFrame::kUPlane, dimensions); | 119 VideoFrame::kUPlane, dimensions); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 size_t y_stride, | 236 size_t y_stride, |
237 size_t u_stride, | 237 size_t u_stride, |
238 size_t v_stride, | 238 size_t v_stride, |
239 const VideoCaptureFormat& frame_format, | 239 const VideoCaptureFormat& frame_format, |
240 int clockwise_rotation, | 240 int clockwise_rotation, |
241 const base::TimeTicks& timestamp) { | 241 const base::TimeTicks& timestamp) { |
242 TRACE_EVENT0("video", "VideoCaptureController::OnIncomingCapturedYuvData"); | 242 TRACE_EVENT0("video", "VideoCaptureController::OnIncomingCapturedYuvData"); |
243 DCHECK_EQ(frame_format.pixel_format, media::PIXEL_FORMAT_I420); | 243 DCHECK_EQ(frame_format.pixel_format, media::PIXEL_FORMAT_I420); |
244 DCHECK_EQ(clockwise_rotation, 0) << "Rotation not supported"; | 244 DCHECK_EQ(clockwise_rotation, 0) << "Rotation not supported"; |
245 | 245 |
246 scoped_refptr<Buffer> buffer = ReserveOutputBuffer(VideoFrame::I420, | 246 scoped_refptr<Buffer> buffer = ReserveOutputBuffer(frame_format); |
247 frame_format.frame_size); | |
248 if (!buffer.get()) | 247 if (!buffer.get()) |
249 return; | 248 return; |
250 | 249 |
251 // Blit (copy) here from y,u,v into buffer.data()). Needed so we can return | 250 // Blit (copy) here from y,u,v into buffer.data()). Needed so we can return |
252 // the parameter buffer synchronously to the driver. | 251 // the parameter buffer synchronously to the driver. |
253 const size_t y_plane_size = VideoFrame::PlaneAllocationSize(VideoFrame::I420, | 252 const size_t y_plane_size = VideoFrame::PlaneAllocationSize(VideoFrame::I420, |
254 VideoFrame::kYPlane, frame_format.frame_size); | 253 VideoFrame::kYPlane, frame_format.frame_size); |
255 const size_t u_plane_size = VideoFrame::PlaneAllocationSize( | 254 const size_t u_plane_size = VideoFrame::PlaneAllocationSize( |
256 VideoFrame::I420, VideoFrame::kUPlane, frame_format.frame_size); | 255 VideoFrame::I420, VideoFrame::kUPlane, frame_format.frame_size); |
257 uint8* const dst_y = reinterpret_cast<uint8*>(buffer->data()); | 256 uint8* const dst_y = reinterpret_cast<uint8*>(buffer->data()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 FROM_HERE, | 293 FROM_HERE, |
295 base::Bind( | 294 base::Bind( |
296 &VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread, | 295 &VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread, |
297 controller_, | 296 controller_, |
298 buffer, | 297 buffer, |
299 video_frame, | 298 video_frame, |
300 timestamp)); | 299 timestamp)); |
301 }; | 300 }; |
302 | 301 |
303 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> | 302 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> |
304 VideoCaptureDeviceClient::ReserveOutputBuffer(VideoFrame::Format format, | 303 VideoCaptureDeviceClient::ReserveOutputBuffer( |
305 const gfx::Size& dimensions) { | 304 const media::VideoCaptureFormat& format) { |
306 const size_t frame_bytes = VideoFrame::AllocationSize(format, dimensions); | 305 DCHECK(format.pixel_format == media::PIXEL_FORMAT_TEXTURE || |
307 if (format == VideoFrame::NATIVE_TEXTURE) { | 306 format.pixel_format == media::PIXEL_FORMAT_I420); |
308 DCHECK_EQ(dimensions.width(), 0); | 307 if (format.pixel_format == media::PIXEL_FORMAT_TEXTURE) { |
miu
2015/04/08 01:20:00
IMO, you should just delete lines 307-313 and repl
mcasas
2015/04/08 22:07:06
Done.
| |
309 DCHECK_EQ(dimensions.height(), 0); | 308 DCHECK_EQ(format.frame_size.width(), 0); |
309 DCHECK_EQ(format.frame_size.height(), 0); | |
310 } else { | 310 } else { |
311 DLOG_IF(ERROR, frame_bytes == 0) << "Error calculating allocation size"; | 311 DLOG_IF(ERROR, format.ImageAllocationSize() == 0) |
312 << "Error calculating allocation size"; | |
312 } | 313 } |
313 | 314 |
314 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId; | 315 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId; |
315 const int buffer_id = | 316 const int buffer_id = buffer_pool_->ReserveForProducer( |
316 buffer_pool_->ReserveForProducer(frame_bytes, &buffer_id_to_drop); | 317 format, &buffer_id_to_drop); |
317 if (buffer_id == VideoCaptureBufferPool::kInvalidId) | 318 if (buffer_id == VideoCaptureBufferPool::kInvalidId) |
318 return NULL; | 319 return NULL; |
319 void* data; | 320 void* data; |
320 size_t size; | 321 size_t size; |
321 buffer_pool_->GetBufferInfo(buffer_id, &data, &size); | 322 buffer_pool_->GetBufferInfo(buffer_id, &data, &size); |
322 | 323 |
323 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> output_buffer( | 324 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> output_buffer( |
324 new AutoReleaseBuffer(buffer_pool_, buffer_id, data, size)); | 325 new AutoReleaseBuffer(buffer_pool_, buffer_id, data, size)); |
325 | 326 |
326 if (buffer_id_to_drop != VideoCaptureBufferPool::kInvalidId) { | 327 if (buffer_id_to_drop != VideoCaptureBufferPool::kInvalidId) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 } | 365 } |
365 | 366 |
366 void VideoCaptureDeviceClient::OnLog( | 367 void VideoCaptureDeviceClient::OnLog( |
367 const std::string& message) { | 368 const std::string& message) { |
368 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 369 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
369 base::Bind(&VideoCaptureController::DoLogOnIOThread, | 370 base::Bind(&VideoCaptureController::DoLogOnIOThread, |
370 controller_, message)); | 371 controller_, message)); |
371 } | 372 } |
372 | 373 |
373 } // namespace content | 374 } // namespace content |
OLD | NEW |