Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: content/browser/renderer_host/media/video_capture_device_client.cc

Issue 1064703002: VideoCaptureBufferPool: Refactor to allow support of non-ShMem backed buffers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: miu@s nits Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 scoped_refptr<Buffer> buffer =
109 dimensions); 109 ReserveOutputBuffer(media::PIXEL_FORMAT_I420, dimensions);
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
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 =
247 frame_format.frame_size); 247 ReserveOutputBuffer(frame_format.pixel_format, frame_format.frame_size);
248 if (!buffer.get()) 248 if (!buffer.get())
249 return; 249 return;
250 250
251 // Blit (copy) here from y,u,v into buffer.data()). Needed so we can return 251 // Blit (copy) here from y,u,v into buffer.data()). Needed so we can return
252 // the parameter buffer synchronously to the driver. 252 // the parameter buffer synchronously to the driver.
253 const size_t y_plane_size = VideoFrame::PlaneAllocationSize(VideoFrame::I420, 253 const size_t y_plane_size = VideoFrame::PlaneAllocationSize(VideoFrame::I420,
254 VideoFrame::kYPlane, frame_format.frame_size); 254 VideoFrame::kYPlane, frame_format.frame_size);
255 const size_t u_plane_size = VideoFrame::PlaneAllocationSize( 255 const size_t u_plane_size = VideoFrame::PlaneAllocationSize(
256 VideoFrame::I420, VideoFrame::kUPlane, frame_format.frame_size); 256 VideoFrame::I420, VideoFrame::kUPlane, frame_format.frame_size);
257 uint8* const dst_y = reinterpret_cast<uint8*>(buffer->data()); 257 uint8* const dst_y = reinterpret_cast<uint8*>(buffer->data());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 FROM_HERE, 294 FROM_HERE,
295 base::Bind( 295 base::Bind(
296 &VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread, 296 &VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread,
297 controller_, 297 controller_,
298 buffer, 298 buffer,
299 video_frame, 299 video_frame,
300 timestamp)); 300 timestamp));
301 }; 301 };
302 302
303 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> 303 scoped_refptr<media::VideoCaptureDevice::Client::Buffer>
304 VideoCaptureDeviceClient::ReserveOutputBuffer(VideoFrame::Format format, 304 VideoCaptureDeviceClient::ReserveOutputBuffer(media::VideoPixelFormat format,
305 const gfx::Size& dimensions) { 305 const gfx::Size& dimensions) {
306 const size_t frame_bytes = VideoFrame::AllocationSize(format, dimensions); 306 DCHECK(format == media::PIXEL_FORMAT_TEXTURE ||
307 if (format == VideoFrame::NATIVE_TEXTURE) { 307 format == media::PIXEL_FORMAT_I420 ||
308 DCHECK_EQ(dimensions.width(), 0); 308 format == media::PIXEL_FORMAT_ARGB);
309 DCHECK_EQ(dimensions.height(), 0); 309 DCHECK_GT(dimensions.width(), 0);
310 } else { 310 DCHECK_GT(dimensions.height(), 0);
311 DLOG_IF(ERROR, frame_bytes == 0) << "Error calculating allocation size";
312 }
313 311
314 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId; 312 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId;
315 const int buffer_id = 313 const int buffer_id =
316 buffer_pool_->ReserveForProducer(frame_bytes, &buffer_id_to_drop); 314 buffer_pool_->ReserveForProducer(format, dimensions, &buffer_id_to_drop);
317 if (buffer_id == VideoCaptureBufferPool::kInvalidId) 315 if (buffer_id == VideoCaptureBufferPool::kInvalidId)
318 return NULL; 316 return NULL;
319 void* data; 317 void* data;
320 size_t size; 318 size_t size;
321 buffer_pool_->GetBufferInfo(buffer_id, &data, &size); 319 buffer_pool_->GetBufferInfo(buffer_id, &data, &size);
322 320
323 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> output_buffer( 321 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> output_buffer(
324 new AutoReleaseBuffer(buffer_pool_, buffer_id, data, size)); 322 new AutoReleaseBuffer(buffer_pool_, buffer_id, data, size));
325 323
326 if (buffer_id_to_drop != VideoCaptureBufferPool::kInvalidId) { 324 if (buffer_id_to_drop != VideoCaptureBufferPool::kInvalidId) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 } 362 }
365 363
366 void VideoCaptureDeviceClient::OnLog( 364 void VideoCaptureDeviceClient::OnLog(
367 const std::string& message) { 365 const std::string& message) {
368 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 366 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
369 base::Bind(&VideoCaptureController::DoLogOnIOThread, 367 base::Bind(&VideoCaptureController::DoLogOnIOThread,
370 controller_, message)); 368 controller_, message));
371 } 369 }
372 370
373 } // namespace content 371 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698