Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_controller.h" | 5 #include "content/browser/renderer_host/media/video_capture_controller.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 #else | 389 #else |
| 390 void VideoCaptureController::OnIncomingCapturedFrame( | 390 void VideoCaptureController::OnIncomingCapturedFrame( |
| 391 const uint8* data, | 391 const uint8* data, |
| 392 int length, | 392 int length, |
| 393 base::Time timestamp, | 393 base::Time timestamp, |
| 394 int rotation, | 394 int rotation, |
| 395 bool flip_vert, | 395 bool flip_vert, |
| 396 bool flip_horiz) { | 396 bool flip_horiz) { |
| 397 DCHECK(frame_info_.color == media::PIXEL_FORMAT_I420 || | 397 DCHECK(frame_info_.color == media::PIXEL_FORMAT_I420 || |
| 398 frame_info_.color == media::PIXEL_FORMAT_YV12 || | 398 frame_info_.color == media::PIXEL_FORMAT_YV12 || |
| 399 frame_info_.color == media::PIXEL_FORMAT_NV21 || | |
| 399 (rotation == 0 && !flip_vert && !flip_horiz)); | 400 (rotation == 0 && !flip_vert && !flip_horiz)); |
| 400 | 401 |
| 401 TRACE_EVENT0("video", "VideoCaptureController::OnIncomingCapturedFrame"); | 402 TRACE_EVENT0("video", "VideoCaptureController::OnIncomingCapturedFrame"); |
| 402 | 403 |
| 403 scoped_refptr<media::VideoFrame> dst; | 404 scoped_refptr<media::VideoFrame> dst; |
| 404 { | 405 { |
| 405 base::AutoLock lock(buffer_pool_lock_); | 406 base::AutoLock lock(buffer_pool_lock_); |
| 406 if (!buffer_pool_.get()) | 407 if (!buffer_pool_.get()) |
| 407 return; | 408 return; |
| 408 dst = buffer_pool_->ReserveI420VideoFrame(gfx::Size(frame_info_.width, | 409 dst = buffer_pool_->ReserveI420VideoFrame(gfx::Size(frame_info_.width, |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 426 RotatePackedYV12Frame( | 427 RotatePackedYV12Frame( |
| 427 data, yplane, uplane, vplane, frame_info_.width, frame_info_.height, | 428 data, yplane, uplane, vplane, frame_info_.width, frame_info_.height, |
| 428 rotation, flip_vert, flip_horiz); | 429 rotation, flip_vert, flip_horiz); |
| 429 break; | 430 break; |
| 430 case media::PIXEL_FORMAT_YV12: | 431 case media::PIXEL_FORMAT_YV12: |
| 431 DCHECK(!chopped_width_ && !chopped_height_); | 432 DCHECK(!chopped_width_ && !chopped_height_); |
| 432 RotatePackedYV12Frame( | 433 RotatePackedYV12Frame( |
| 433 data, yplane, vplane, uplane, frame_info_.width, frame_info_.height, | 434 data, yplane, vplane, uplane, frame_info_.width, frame_info_.height, |
| 434 rotation, flip_vert, flip_horiz); | 435 rotation, flip_vert, flip_horiz); |
| 435 break; | 436 break; |
| 436 case media::PIXEL_FORMAT_NV21: | 437 case media::PIXEL_FORMAT_NV21: { |
| 437 DCHECK(!chopped_width_ && !chopped_height_); | 438 DCHECK(!chopped_width_ && !chopped_height_); |
| 438 media::ConvertNV21ToYUV(data, yplane, uplane, vplane, frame_info_.width, | 439 int num_pixels = frame_info_.width * frame_info_.height; |
| 439 frame_info_.height); | 440 media::ConvertNV21ToYUV( |
| 441 data, | |
| 442 &nv21_intermediate_buffer_[0], | |
| 443 &nv21_intermediate_buffer_[0] + num_pixels, | |
| 444 &nv21_intermediate_buffer_[0] + num_pixels * 5 / 4 , | |
|
Jói
2013/09/10 16:31:18
Perhaps I'm reading the NV21 spec wrong, but I tho
mcasas
2013/09/11 09:03:28
|data| is NV21 and follows your description.
nv21
| |
| 445 frame_info_.width, | |
| 446 frame_info_.height); | |
| 447 RotatePackedYV12Frame( | |
| 448 &nv21_intermediate_buffer_[0], yplane, uplane, vplane, | |
| 449 frame_info_.width, frame_info_.height, | |
| 450 rotation, flip_vert, flip_horiz); | |
| 440 break; | 451 break; |
| 452 } | |
| 441 case media::PIXEL_FORMAT_YUY2: | 453 case media::PIXEL_FORMAT_YUY2: |
| 442 DCHECK(!chopped_width_ && !chopped_height_); | 454 DCHECK(!chopped_width_ && !chopped_height_); |
| 443 if (frame_info_.width * frame_info_.height * 2 != length) { | 455 if (frame_info_.width * frame_info_.height * 2 != length) { |
| 444 // If |length| of |data| does not match the expected width and height | 456 // If |length| of |data| does not match the expected width and height |
| 445 // we can't convert the frame to I420. YUY2 is 2 bytes per pixel. | 457 // we can't convert the frame to I420. YUY2 is 2 bytes per pixel. |
| 446 break; | 458 break; |
| 447 } | 459 } |
| 448 | 460 |
| 449 media::ConvertYUY2ToYUV(data, yplane, uplane, vplane, frame_info_.width, | 461 media::ConvertYUY2ToYUV(data, yplane, uplane, vplane, frame_info_.width, |
| 450 frame_info_.height); | 462 frame_info_.height); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 596 | 608 |
| 597 void VideoCaptureController::OnError() { | 609 void VideoCaptureController::OnError() { |
| 598 BrowserThread::PostTask(BrowserThread::IO, | 610 BrowserThread::PostTask(BrowserThread::IO, |
| 599 FROM_HERE, | 611 FROM_HERE, |
| 600 base::Bind(&VideoCaptureController::DoErrorOnIOThread, this)); | 612 base::Bind(&VideoCaptureController::DoErrorOnIOThread, this)); |
| 601 } | 613 } |
| 602 | 614 |
| 603 void VideoCaptureController::OnFrameInfo( | 615 void VideoCaptureController::OnFrameInfo( |
| 604 const media::VideoCaptureCapability& info) { | 616 const media::VideoCaptureCapability& info) { |
| 605 frame_info_= info; | 617 frame_info_= info; |
| 618 if ((frame_info_.color == media::PIXEL_FORMAT_NV21) && | |
| 619 (nv21_intermediate_buffer_.get() == NULL)) { | |
| 620 nv21_intermediate_buffer_.reset( | |
| 621 new uint8[frame_info_.width * frame_info_.height * 12 / 8]); | |
|
Jói
2013/09/10 16:31:18
For a 1x1 frame, this calculation yields 1, wherea
mcasas
2013/09/11 09:03:28
It should be an even number, this is enforced righ
| |
| 622 } | |
| 606 // Handle cases when |info| has odd numbers for width/height. | 623 // Handle cases when |info| has odd numbers for width/height. |
| 607 if (info.width & 1) { | 624 if (info.width & 1) { |
| 608 --frame_info_.width; | 625 --frame_info_.width; |
| 609 chopped_width_ = 1; | 626 chopped_width_ = 1; |
| 610 } else { | 627 } else { |
| 611 chopped_width_ = 0; | 628 chopped_width_ = 0; |
| 612 } | 629 } |
| 613 if (info.height & 1) { | 630 if (info.height & 1) { |
| 614 --frame_info_.height; | 631 --frame_info_.height; |
| 615 chopped_height_ = 1; | 632 chopped_height_ = 1; |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 839 controller_clients_.push_back((*client_it)); | 856 controller_clients_.push_back((*client_it)); |
| 840 pending_clients_.erase(client_it++); | 857 pending_clients_.erase(client_it++); |
| 841 } | 858 } |
| 842 // Request the manager to start the actual capture. | 859 // Request the manager to start the actual capture. |
| 843 video_capture_manager_->Start(current_params_, this); | 860 video_capture_manager_->Start(current_params_, this); |
| 844 state_ = VIDEO_CAPTURE_STATE_STARTED; | 861 state_ = VIDEO_CAPTURE_STATE_STARTED; |
| 845 device_in_use_ = true; | 862 device_in_use_ = true; |
| 846 } | 863 } |
| 847 | 864 |
| 848 } // namespace content | 865 } // namespace content |
| OLD | NEW |