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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 if (!buffer_pool_.get()) | 253 if (!buffer_pool_.get()) |
254 return NULL; | 254 return NULL; |
255 return buffer_pool_->ReserveI420VideoFrame(gfx::Size(frame_info_.width, | 255 return buffer_pool_->ReserveI420VideoFrame(gfx::Size(frame_info_.width, |
256 frame_info_.height), | 256 frame_info_.height), |
257 0); | 257 0); |
258 } | 258 } |
259 | 259 |
260 // Implements VideoCaptureDevice::EventHandler. | 260 // Implements VideoCaptureDevice::EventHandler. |
261 // OnIncomingCapturedFrame is called the thread running the capture device. | 261 // OnIncomingCapturedFrame is called the thread running the capture device. |
262 // I.e.- DirectShow thread on windows and v4l2_thread on Linux. | 262 // I.e.- DirectShow thread on windows and v4l2_thread on Linux. |
263 #if !defined(OS_IOS) && !defined(OS_ANDROID) | 263 #if !defined(OS_IOS) && !defined(OS_ANDROID) |
Ami GONE FROM CHROMIUM
2013/09/12 17:03:16
Why not use libyuv on clank?
I suspect you propaga
scherkus (not reviewing)
2013/09/12 17:26:49
+1
it's also unfortunate to introduce i420_interm
mcasas
2013/09/13 08:42:51
It all sounds good and I had a secret post-it to c
mcasas
2013/09/16 08:43:02
FWIW, http://crbug.com/292400 tracks the introduct
| |
264 void VideoCaptureController::OnIncomingCapturedFrame( | 264 void VideoCaptureController::OnIncomingCapturedFrame( |
265 const uint8* data, | 265 const uint8* data, |
266 int length, | 266 int length, |
267 base::Time timestamp, | 267 base::Time timestamp, |
268 int rotation, | 268 int rotation, |
269 bool flip_vert, | 269 bool flip_vert, |
270 bool flip_horiz) { | 270 bool flip_horiz) { |
271 TRACE_EVENT0("video", "VideoCaptureController::OnIncomingCapturedFrame"); | 271 TRACE_EVENT0("video", "VideoCaptureController::OnIncomingCapturedFrame"); |
272 | 272 |
273 scoped_refptr<media::VideoFrame> dst; | 273 scoped_refptr<media::VideoFrame> dst; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
393 #else | 393 #else |
394 void VideoCaptureController::OnIncomingCapturedFrame( | 394 void VideoCaptureController::OnIncomingCapturedFrame( |
395 const uint8* data, | 395 const uint8* data, |
396 int length, | 396 int length, |
397 base::Time timestamp, | 397 base::Time timestamp, |
398 int rotation, | 398 int rotation, |
399 bool flip_vert, | 399 bool flip_vert, |
400 bool flip_horiz) { | 400 bool flip_horiz) { |
401 DCHECK(frame_info_.color == media::PIXEL_FORMAT_I420 || | 401 DCHECK(frame_info_.color == media::PIXEL_FORMAT_I420 || |
402 frame_info_.color == media::PIXEL_FORMAT_YV12 || | 402 frame_info_.color == media::PIXEL_FORMAT_YV12 || |
403 frame_info_.color == media::PIXEL_FORMAT_NV21 || | |
403 (rotation == 0 && !flip_vert && !flip_horiz)); | 404 (rotation == 0 && !flip_vert && !flip_horiz)); |
404 | 405 |
405 TRACE_EVENT0("video", "VideoCaptureController::OnIncomingCapturedFrame"); | 406 TRACE_EVENT0("video", "VideoCaptureController::OnIncomingCapturedFrame"); |
406 | 407 |
407 scoped_refptr<media::VideoFrame> dst; | 408 scoped_refptr<media::VideoFrame> dst; |
408 { | 409 { |
409 base::AutoLock lock(buffer_pool_lock_); | 410 base::AutoLock lock(buffer_pool_lock_); |
410 if (!buffer_pool_.get()) | 411 if (!buffer_pool_.get()) |
411 return; | 412 return; |
412 dst = buffer_pool_->ReserveI420VideoFrame(gfx::Size(frame_info_.width, | 413 dst = buffer_pool_->ReserveI420VideoFrame(gfx::Size(frame_info_.width, |
(...skipping 17 matching lines...) Expand all Loading... | |
430 RotatePackedYV12Frame( | 431 RotatePackedYV12Frame( |
431 data, yplane, uplane, vplane, frame_info_.width, frame_info_.height, | 432 data, yplane, uplane, vplane, frame_info_.width, frame_info_.height, |
432 rotation, flip_vert, flip_horiz); | 433 rotation, flip_vert, flip_horiz); |
433 break; | 434 break; |
434 case media::PIXEL_FORMAT_YV12: | 435 case media::PIXEL_FORMAT_YV12: |
435 DCHECK(!chopped_width_ && !chopped_height_); | 436 DCHECK(!chopped_width_ && !chopped_height_); |
436 RotatePackedYV12Frame( | 437 RotatePackedYV12Frame( |
437 data, yplane, vplane, uplane, frame_info_.width, frame_info_.height, | 438 data, yplane, vplane, uplane, frame_info_.width, frame_info_.height, |
438 rotation, flip_vert, flip_horiz); | 439 rotation, flip_vert, flip_horiz); |
439 break; | 440 break; |
440 case media::PIXEL_FORMAT_NV21: | 441 case media::PIXEL_FORMAT_NV21: { |
441 DCHECK(!chopped_width_ && !chopped_height_); | 442 DCHECK(!chopped_width_ && !chopped_height_); |
442 media::ConvertNV21ToYUV(data, yplane, uplane, vplane, frame_info_.width, | 443 int num_pixels = frame_info_.width * frame_info_.height; |
444 media::ConvertNV21ToYUV(data, | |
445 &i420_intermediate_buffer_[0], | |
446 &i420_intermediate_buffer_[num_pixels], | |
447 &i420_intermediate_buffer_[num_pixels * 5 / 4], | |
448 frame_info_.width, | |
443 frame_info_.height); | 449 frame_info_.height); |
450 RotatePackedYV12Frame( | |
451 &i420_intermediate_buffer_[0], yplane, uplane, vplane, | |
452 frame_info_.width, frame_info_.height, | |
453 rotation, flip_vert, flip_horiz); | |
444 break; | 454 break; |
455 } | |
445 case media::PIXEL_FORMAT_YUY2: | 456 case media::PIXEL_FORMAT_YUY2: |
446 DCHECK(!chopped_width_ && !chopped_height_); | 457 DCHECK(!chopped_width_ && !chopped_height_); |
447 if (frame_info_.width * frame_info_.height * 2 != length) { | 458 if (frame_info_.width * frame_info_.height * 2 != length) { |
448 // If |length| of |data| does not match the expected width and height | 459 // If |length| of |data| does not match the expected width and height |
449 // we can't convert the frame to I420. YUY2 is 2 bytes per pixel. | 460 // we can't convert the frame to I420. YUY2 is 2 bytes per pixel. |
450 break; | 461 break; |
451 } | 462 } |
452 | 463 |
453 media::ConvertYUY2ToYUV(data, yplane, uplane, vplane, frame_info_.width, | 464 media::ConvertYUY2ToYUV(data, yplane, uplane, vplane, frame_info_.width, |
454 frame_info_.height); | 465 frame_info_.height); |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
613 chopped_width_ = 1; | 624 chopped_width_ = 1; |
614 } else { | 625 } else { |
615 chopped_width_ = 0; | 626 chopped_width_ = 0; |
616 } | 627 } |
617 if (info.height & 1) { | 628 if (info.height & 1) { |
618 --frame_info_.height; | 629 --frame_info_.height; |
619 chopped_height_ = 1; | 630 chopped_height_ = 1; |
620 } else { | 631 } else { |
621 chopped_height_ = 0; | 632 chopped_height_ = 0; |
622 } | 633 } |
634 if ((frame_info_.color == media::PIXEL_FORMAT_NV21) && | |
635 (i420_intermediate_buffer_.get() == NULL)) { | |
636 i420_intermediate_buffer_.reset( | |
scherkus (not reviewing)
2013/09/12 17:26:49
does this mean we're allocating memory for i420_in
mcasas
2013/09/13 08:42:51
I should guard it with the #ifdef - sigh.
mcasas
2013/09/16 08:43:02
Done.
| |
637 new uint8[frame_info_.width * frame_info_.height * 12 / 8]); | |
638 } | |
623 BrowserThread::PostTask(BrowserThread::IO, | 639 BrowserThread::PostTask(BrowserThread::IO, |
624 FROM_HERE, | 640 FROM_HERE, |
625 base::Bind(&VideoCaptureController::DoFrameInfoOnIOThread, this)); | 641 base::Bind(&VideoCaptureController::DoFrameInfoOnIOThread, this)); |
626 } | 642 } |
627 | 643 |
628 void VideoCaptureController::OnFrameInfoChanged( | 644 void VideoCaptureController::OnFrameInfoChanged( |
629 const media::VideoCaptureCapability& info) { | 645 const media::VideoCaptureCapability& info) { |
630 BrowserThread::PostTask(BrowserThread::IO, | 646 BrowserThread::PostTask(BrowserThread::IO, |
631 FROM_HERE, | 647 FROM_HERE, |
632 base::Bind(&VideoCaptureController::DoFrameInfoChangedOnIOThread, | 648 base::Bind(&VideoCaptureController::DoFrameInfoChangedOnIOThread, |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
843 controller_clients_.push_back((*client_it)); | 859 controller_clients_.push_back((*client_it)); |
844 pending_clients_.erase(client_it++); | 860 pending_clients_.erase(client_it++); |
845 } | 861 } |
846 // Request the manager to start the actual capture. | 862 // Request the manager to start the actual capture. |
847 video_capture_manager_->Start(current_params_, this); | 863 video_capture_manager_->Start(current_params_, this); |
848 state_ = VIDEO_CAPTURE_STATE_STARTED; | 864 state_ = VIDEO_CAPTURE_STATE_STARTED; |
849 device_in_use_ = true; | 865 device_in_use_ = true; |
850 } | 866 } |
851 | 867 |
852 } // namespace content | 868 } // namespace content |
OLD | NEW |