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

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

Issue 1204843004: Revert of Video Capture: extract storage info from pixel format in VideoCaptureFormat. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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 <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 209
210 VideoCaptureDeviceClient::~VideoCaptureDeviceClient() {} 210 VideoCaptureDeviceClient::~VideoCaptureDeviceClient() {}
211 211
212 void VideoCaptureDeviceClient::OnIncomingCapturedData( 212 void VideoCaptureDeviceClient::OnIncomingCapturedData(
213 const uint8* data, 213 const uint8* data,
214 int length, 214 int length,
215 const VideoCaptureFormat& frame_format, 215 const VideoCaptureFormat& frame_format,
216 int rotation, 216 int rotation,
217 const base::TimeTicks& timestamp) { 217 const base::TimeTicks& timestamp) {
218 TRACE_EVENT0("video", "VideoCaptureDeviceClient::OnIncomingCapturedData"); 218 TRACE_EVENT0("video", "VideoCaptureDeviceClient::OnIncomingCapturedData");
219 DCHECK_EQ(frame_format.pixel_storage, media::PIXEL_STORAGE_CPU);
220 219
221 if (last_captured_pixel_format_ != frame_format.pixel_format) { 220 if (last_captured_pixel_format_ != frame_format.pixel_format) {
222 OnLog("Pixel format: " + 221 OnLog("Pixel format: " + media::VideoCaptureFormat::PixelFormatToString(
223 VideoCaptureFormat::PixelFormatToString(frame_format.pixel_format)); 222 frame_format.pixel_format));
224 last_captured_pixel_format_ = frame_format.pixel_format; 223 last_captured_pixel_format_ = frame_format.pixel_format;
225 } 224 }
226 225
227 if (!frame_format.IsValid()) 226 if (!frame_format.IsValid())
228 return; 227 return;
229 228
230 // |chopped_{width,height} and |new_unrotated_{width,height}| are the lowest 229 // |chopped_{width,height} and |new_unrotated_{width,height}| are the lowest
231 // bit decomposition of {width, height}, grabbing the odd and even parts. 230 // bit decomposition of {width, height}, grabbing the odd and even parts.
232 const int chopped_width = frame_format.frame_size.width() & 1; 231 const int chopped_width = frame_format.frame_size.width() & 1;
233 const int chopped_height = frame_format.frame_size.height() & 1; 232 const int chopped_height = frame_format.frame_size.height() & 1;
(...skipping 17 matching lines...) Expand all
251 250
252 const gfx::Size dimensions(destination_width, destination_height); 251 const gfx::Size dimensions(destination_width, destination_height);
253 if (!VideoFrame::IsValidConfig(VideoFrame::I420, 252 if (!VideoFrame::IsValidConfig(VideoFrame::I420,
254 VideoFrame::STORAGE_UNKNOWN, 253 VideoFrame::STORAGE_UNKNOWN,
255 dimensions, 254 dimensions,
256 gfx::Rect(dimensions), 255 gfx::Rect(dimensions),
257 dimensions)) { 256 dimensions)) {
258 return; 257 return;
259 } 258 }
260 259
261 scoped_ptr<Buffer> buffer(ReserveOutputBuffer( 260 scoped_ptr<Buffer> buffer(
262 dimensions, media::PIXEL_FORMAT_I420, media::PIXEL_STORAGE_CPU)); 261 ReserveOutputBuffer(media::PIXEL_FORMAT_I420, dimensions));
263 if (!buffer.get()) 262 if (!buffer.get())
264 return; 263 return;
265 264
266 const size_t y_plane_size = VideoFrame::PlaneSize( 265 const size_t y_plane_size = VideoFrame::PlaneSize(
267 VideoFrame::I420, VideoFrame::kYPlane, dimensions).GetArea(); 266 VideoFrame::I420, VideoFrame::kYPlane, dimensions).GetArea();
268 const size_t u_plane_size = VideoFrame::PlaneSize( 267 const size_t u_plane_size = VideoFrame::PlaneSize(
269 VideoFrame::I420, VideoFrame::kUPlane, dimensions).GetArea(); 268 VideoFrame::I420, VideoFrame::kUPlane, dimensions).GetArea();
270 uint8* const yplane = reinterpret_cast<uint8*>(buffer->data()); 269 uint8* const yplane = reinterpret_cast<uint8*>(buffer->data());
271 uint8* const uplane = yplane + y_plane_size; 270 uint8* const uplane = yplane + y_plane_size;
272 uint8* const vplane = uplane + u_plane_size; 271 uint8* const vplane = uplane + u_plane_size;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 uv_plane_stride, 343 uv_plane_stride,
345 crop_x, 344 crop_x,
346 crop_y, 345 crop_y,
347 frame_format.frame_size.width(), 346 frame_format.frame_size.width(),
348 (flip ? -1 : 1) * frame_format.frame_size.height(), 347 (flip ? -1 : 1) * frame_format.frame_size.height(),
349 new_unrotated_width, 348 new_unrotated_width,
350 new_unrotated_height, 349 new_unrotated_height,
351 rotation_mode, 350 rotation_mode,
352 origin_colorspace) != 0) { 351 origin_colorspace) != 0) {
353 DLOG(WARNING) << "Failed to convert buffer's pixel format to I420 from " 352 DLOG(WARNING) << "Failed to convert buffer's pixel format to I420 from "
354 << VideoCaptureFormat::PixelFormatToString( 353 << media::VideoCaptureFormat::PixelFormatToString(
355 frame_format.pixel_format); 354 frame_format.pixel_format);
356 return; 355 return;
357 } 356 }
358 357
359 const VideoCaptureFormat output_format = 358 OnIncomingCapturedBuffer(buffer.Pass(),
360 VideoCaptureFormat(dimensions, frame_format.frame_rate, 359 media::VideoCaptureFormat(dimensions,
361 media::PIXEL_FORMAT_I420, media::PIXEL_STORAGE_CPU); 360 frame_format.frame_rate,
362 OnIncomingCapturedBuffer(buffer.Pass(), output_format, timestamp); 361 media::PIXEL_FORMAT_I420),
362 timestamp);
363 } 363 }
364 364
365 void 365 void
366 VideoCaptureDeviceClient::OnIncomingCapturedYuvData( 366 VideoCaptureDeviceClient::OnIncomingCapturedYuvData(
367 const uint8* y_data, 367 const uint8* y_data,
368 const uint8* u_data, 368 const uint8* u_data,
369 const uint8* v_data, 369 const uint8* v_data,
370 size_t y_stride, 370 size_t y_stride,
371 size_t u_stride, 371 size_t u_stride,
372 size_t v_stride, 372 size_t v_stride,
373 const VideoCaptureFormat& frame_format, 373 const VideoCaptureFormat& frame_format,
374 int clockwise_rotation, 374 int clockwise_rotation,
375 const base::TimeTicks& timestamp) { 375 const base::TimeTicks& timestamp) {
376 TRACE_EVENT0("video", "VideoCaptureDeviceClient::OnIncomingCapturedYuvData"); 376 TRACE_EVENT0("video", "VideoCaptureDeviceClient::OnIncomingCapturedYuvData");
377 DCHECK_EQ(frame_format.pixel_format, media::PIXEL_FORMAT_I420); 377 DCHECK_EQ(frame_format.pixel_format, media::PIXEL_FORMAT_I420);
378 DCHECK_EQ(frame_format.pixel_storage, media::PIXEL_STORAGE_CPU);
379 DCHECK_EQ(clockwise_rotation, 0) << "Rotation not supported"; 378 DCHECK_EQ(clockwise_rotation, 0) << "Rotation not supported";
380 379
381 scoped_ptr<Buffer> buffer(ReserveOutputBuffer(frame_format.frame_size, 380 scoped_ptr<Buffer> buffer(
382 frame_format.pixel_format, 381 ReserveOutputBuffer(frame_format.pixel_format, frame_format.frame_size));
383 frame_format.pixel_storage));
384 if (!buffer.get()) 382 if (!buffer.get())
385 return; 383 return;
386 384
387 // Blit (copy) here from y,u,v into buffer.data()). Needed so we can return 385 // Blit (copy) here from y,u,v into buffer.data()). Needed so we can return
388 // the parameter buffer synchronously to the driver. 386 // the parameter buffer synchronously to the driver.
389 const size_t y_plane_size = VideoFrame::PlaneSize( 387 const size_t y_plane_size = VideoFrame::PlaneSize(
390 VideoFrame::I420, VideoFrame::kYPlane, frame_format.frame_size).GetArea(); 388 VideoFrame::I420, VideoFrame::kYPlane, frame_format.frame_size).GetArea();
391 const size_t u_plane_size = VideoFrame::PlaneSize( 389 const size_t u_plane_size = VideoFrame::PlaneSize(
392 VideoFrame::I420, VideoFrame::kUPlane, frame_format.frame_size).GetArea(); 390 VideoFrame::I420, VideoFrame::kUPlane, frame_format.frame_size).GetArea();
393 uint8* const dst_y = reinterpret_cast<uint8*>(buffer->data()); 391 uint8* const dst_y = reinterpret_cast<uint8*>(buffer->data());
(...skipping 19 matching lines...) Expand all
413 frame_format.frame_size.width(), 411 frame_format.frame_size.width(),
414 frame_format.frame_size.height())) { 412 frame_format.frame_size.height())) {
415 DLOG(WARNING) << "Failed to copy buffer"; 413 DLOG(WARNING) << "Failed to copy buffer";
416 return; 414 return;
417 } 415 }
418 416
419 OnIncomingCapturedBuffer(buffer.Pass(), frame_format, timestamp); 417 OnIncomingCapturedBuffer(buffer.Pass(), frame_format, timestamp);
420 }; 418 };
421 419
422 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> 420 scoped_ptr<media::VideoCaptureDevice::Client::Buffer>
423 VideoCaptureDeviceClient::ReserveOutputBuffer( 421 VideoCaptureDeviceClient::ReserveOutputBuffer(media::VideoPixelFormat format,
424 const gfx::Size& frame_size, 422 const gfx::Size& dimensions) {
425 media::VideoPixelFormat pixel_format, 423 DCHECK(format == media::PIXEL_FORMAT_I420 ||
426 media::VideoPixelStorage pixel_storage) { 424 format == media::PIXEL_FORMAT_TEXTURE ||
427 DCHECK(pixel_format == media::PIXEL_FORMAT_I420 || 425 format == media::PIXEL_FORMAT_GPUMEMORYBUFFER);
428 pixel_format == media::PIXEL_FORMAT_ARGB); 426 DCHECK_GT(dimensions.width(), 0);
429 DCHECK_GT(frame_size.width(), 0); 427 DCHECK_GT(dimensions.height(), 0);
430 DCHECK_GT(frame_size.height(), 0);
431 428
432 if (pixel_storage == media::PIXEL_STORAGE_GPUMEMORYBUFFER && 429 if (format == media::PIXEL_FORMAT_GPUMEMORYBUFFER && !texture_wrap_helper_) {
433 !texture_wrap_helper_) {
434 texture_wrap_helper_ = 430 texture_wrap_helper_ =
435 new TextureWrapHelper(controller_, capture_task_runner_); 431 new TextureWrapHelper(controller_, capture_task_runner_);
436 } 432 }
437 433
438 // TODO(mcasas): For PIXEL_STORAGE_GPUMEMORYBUFFER, find a way to indicate if
439 // it's a ShMem GMB or a DmaBuf GMB.
440 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId; 434 int buffer_id_to_drop = VideoCaptureBufferPool::kInvalidId;
441 const int buffer_id = buffer_pool_->ReserveForProducer( 435 const int buffer_id =
442 pixel_format, pixel_storage, frame_size, &buffer_id_to_drop); 436 buffer_pool_->ReserveForProducer(format, dimensions, &buffer_id_to_drop);
443 if (buffer_id == VideoCaptureBufferPool::kInvalidId) 437 if (buffer_id == VideoCaptureBufferPool::kInvalidId)
444 return NULL; 438 return NULL;
445 439
446 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> output_buffer( 440 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> output_buffer(
447 new AutoReleaseBuffer(buffer_pool_, buffer_id)); 441 new AutoReleaseBuffer(buffer_pool_, buffer_id));
448 442
449 if (buffer_id_to_drop != VideoCaptureBufferPool::kInvalidId) { 443 if (buffer_id_to_drop != VideoCaptureBufferPool::kInvalidId) {
450 BrowserThread::PostTask(BrowserThread::IO, 444 BrowserThread::PostTask(BrowserThread::IO,
451 FROM_HERE, 445 FROM_HERE,
452 base::Bind(&VideoCaptureController::DoBufferDestroyedOnIOThread, 446 base::Bind(&VideoCaptureController::DoBufferDestroyedOnIOThread,
453 controller_, buffer_id_to_drop)); 447 controller_, buffer_id_to_drop));
454 } 448 }
455 449
456 return output_buffer.Pass(); 450 return output_buffer.Pass();
457 } 451 }
458 452
459 void VideoCaptureDeviceClient::OnIncomingCapturedBuffer( 453 void VideoCaptureDeviceClient::OnIncomingCapturedBuffer(
460 scoped_ptr<Buffer> buffer, 454 scoped_ptr<Buffer> buffer,
461 const VideoCaptureFormat& frame_format, 455 const media::VideoCaptureFormat& frame_format,
462 const base::TimeTicks& timestamp) { 456 const base::TimeTicks& timestamp) {
463 if (frame_format.pixel_storage == media::PIXEL_STORAGE_GPUMEMORYBUFFER) { 457 if (frame_format.pixel_format == media::PIXEL_FORMAT_GPUMEMORYBUFFER) {
464 capture_task_runner_->PostTask( 458 capture_task_runner_->PostTask(
465 FROM_HERE, 459 FROM_HERE,
466 base::Bind(&TextureWrapHelper::OnIncomingCapturedGpuMemoryBuffer, 460 base::Bind(&TextureWrapHelper::OnIncomingCapturedGpuMemoryBuffer,
467 texture_wrap_helper_, 461 texture_wrap_helper_,
468 base::Passed(&buffer), 462 base::Passed(&buffer),
469 frame_format, 463 frame_format,
470 timestamp)); 464 timestamp));
471 } else { 465 } else {
472 DCHECK(frame_format.pixel_format == media::PIXEL_FORMAT_I420 || 466 DCHECK_EQ(frame_format.pixel_format, media::PIXEL_FORMAT_I420);
473 frame_format.pixel_format == media::PIXEL_FORMAT_ARGB);
474 scoped_refptr<VideoFrame> video_frame = 467 scoped_refptr<VideoFrame> video_frame =
475 VideoFrame::WrapExternalData( 468 VideoFrame::WrapExternalData(
476 VideoFrame::I420, 469 VideoFrame::I420,
477 frame_format.frame_size, 470 frame_format.frame_size,
478 gfx::Rect(frame_format.frame_size), 471 gfx::Rect(frame_format.frame_size),
479 frame_format.frame_size, 472 frame_format.frame_size,
480 reinterpret_cast<uint8*>(buffer->data()), 473 reinterpret_cast<uint8*>(buffer->data()),
481 VideoFrame::AllocationSize(VideoFrame::I420, 474 VideoFrame::AllocationSize(VideoFrame::I420,
482 frame_format.frame_size), 475 frame_format.frame_size),
483 base::TimeDelta()); 476 base::TimeDelta());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 capture_task_runner_->PostTask(FROM_HERE, 530 capture_task_runner_->PostTask(FROM_HERE,
538 base::Bind(&TextureWrapHelper::Init, this)); 531 base::Bind(&TextureWrapHelper::Init, this));
539 } 532 }
540 533
541 void 534 void
542 VideoCaptureDeviceClient::TextureWrapHelper::OnIncomingCapturedGpuMemoryBuffer( 535 VideoCaptureDeviceClient::TextureWrapHelper::OnIncomingCapturedGpuMemoryBuffer(
543 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer, 536 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer,
544 const media::VideoCaptureFormat& frame_format, 537 const media::VideoCaptureFormat& frame_format,
545 const base::TimeTicks& timestamp) { 538 const base::TimeTicks& timestamp) {
546 DCHECK(capture_task_runner_->BelongsToCurrentThread()); 539 DCHECK(capture_task_runner_->BelongsToCurrentThread());
547 DCHECK_EQ(frame_format.pixel_format, media::PIXEL_FORMAT_ARGB); 540 DCHECK_EQ(frame_format.pixel_format, media::PIXEL_FORMAT_GPUMEMORYBUFFER);
548 DCHECK_EQ(frame_format.pixel_storage, media::PIXEL_STORAGE_GPUMEMORYBUFFER);
549 if (!gl_helper_) { 541 if (!gl_helper_) {
550 // |gl_helper_| might not exist due to asynchronous initialization not 542 // |gl_helper_| might not exist due to asynchronous initialization not
551 // finished or due to termination in process after a context loss. 543 // finished or due to termination in process after a context loss.
552 DVLOG(1) << " Skipping ingress frame, no GL context."; 544 DVLOG(1) << " Skipping ingress frame, no GL context.";
553 return; 545 return;
554 } 546 }
555 547
556 gpu::gles2::GLES2Interface* gl = capture_thread_context_->ContextGL(); 548 gpu::gles2::GLES2Interface* gl = capture_thread_context_->ContextGL();
557 GLuint image_id = gl->CreateImageCHROMIUM(buffer->AsClientBuffer(), 549 GLuint image_id = gl->CreateImageCHROMIUM(buffer->AsClientBuffer(),
558 frame_format.frame_size.width(), 550 frame_format.frame_size.width(),
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 void VideoCaptureDeviceClient::TextureWrapHelper::OnError( 685 void VideoCaptureDeviceClient::TextureWrapHelper::OnError(
694 const std::string& message) { 686 const std::string& message) {
695 DCHECK(capture_task_runner_->BelongsToCurrentThread()); 687 DCHECK(capture_task_runner_->BelongsToCurrentThread());
696 DLOG(ERROR) << message; 688 DLOG(ERROR) << message;
697 BrowserThread::PostTask( 689 BrowserThread::PostTask(
698 BrowserThread::IO, FROM_HERE, 690 BrowserThread::IO, FROM_HERE,
699 base::Bind(&VideoCaptureController::DoErrorOnIOThread, controller_)); 691 base::Bind(&VideoCaptureController::DoErrorOnIOThread, controller_));
700 } 692 }
701 693
702 } // namespace content 694 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/video_capture_device_client.h ('k') | content/common/media/media_param_traits.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698