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 &i420_intermediate_buffer_[0], | |
443 &i420_intermediate_buffer_[0] + num_pixels, | |
tommi (sloooow) - chröme
2013/09/11 12:32:44
what's the difference between this and &i420_inter
| |
444 &i420_intermediate_buffer_[0] + num_pixels * 5 / 4 , | |
445 frame_info_.width, | |
446 frame_info_.height); | |
447 RotatePackedYV12Frame( | |
448 &i420_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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
609 chopped_width_ = 1; | 621 chopped_width_ = 1; |
610 } else { | 622 } else { |
611 chopped_width_ = 0; | 623 chopped_width_ = 0; |
612 } | 624 } |
613 if (info.height & 1) { | 625 if (info.height & 1) { |
614 --frame_info_.height; | 626 --frame_info_.height; |
615 chopped_height_ = 1; | 627 chopped_height_ = 1; |
616 } else { | 628 } else { |
617 chopped_height_ = 0; | 629 chopped_height_ = 0; |
618 } | 630 } |
631 if ((frame_info_.color == media::PIXEL_FORMAT_NV21) && | |
632 (i420_intermediate_buffer_.get() == NULL)) { | |
633 i420_intermediate_buffer_.reset( | |
634 new uint8[frame_info_.width * frame_info_.height * 12 / 8]); | |
635 } | |
619 BrowserThread::PostTask(BrowserThread::IO, | 636 BrowserThread::PostTask(BrowserThread::IO, |
620 FROM_HERE, | 637 FROM_HERE, |
621 base::Bind(&VideoCaptureController::DoFrameInfoOnIOThread, this)); | 638 base::Bind(&VideoCaptureController::DoFrameInfoOnIOThread, this)); |
622 } | 639 } |
623 | 640 |
624 void VideoCaptureController::OnFrameInfoChanged( | 641 void VideoCaptureController::OnFrameInfoChanged( |
625 const media::VideoCaptureCapability& info) { | 642 const media::VideoCaptureCapability& info) { |
626 BrowserThread::PostTask(BrowserThread::IO, | 643 BrowserThread::PostTask(BrowserThread::IO, |
627 FROM_HERE, | 644 FROM_HERE, |
628 base::Bind(&VideoCaptureController::DoFrameInfoChangedOnIOThread, | 645 base::Bind(&VideoCaptureController::DoFrameInfoChangedOnIOThread, |
(...skipping 210 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 |