Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "media/capture/video/video_capture_device_client.h" | 5 #include "media/capture/video/video_capture_device_client.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 VideoCaptureDeviceClient::VideoCaptureDeviceClient( | 75 VideoCaptureDeviceClient::VideoCaptureDeviceClient( |
| 76 std::unique_ptr<VideoFrameReceiver> receiver, | 76 std::unique_ptr<VideoFrameReceiver> receiver, |
| 77 const scoped_refptr<VideoCaptureBufferPool>& buffer_pool, | 77 const scoped_refptr<VideoCaptureBufferPool>& buffer_pool, |
| 78 const VideoCaptureJpegDecoderFactoryCB& jpeg_decoder_factory) | 78 const VideoCaptureJpegDecoderFactoryCB& jpeg_decoder_factory) |
| 79 : receiver_(std::move(receiver)), | 79 : receiver_(std::move(receiver)), |
| 80 jpeg_decoder_factory_callback_(jpeg_decoder_factory), | 80 jpeg_decoder_factory_callback_(jpeg_decoder_factory), |
| 81 external_jpeg_decoder_initialized_(false), | 81 external_jpeg_decoder_initialized_(false), |
| 82 buffer_pool_(buffer_pool), | 82 buffer_pool_(buffer_pool), |
| 83 is_back_camera_(false), | |
| 83 last_captured_pixel_format_(media::PIXEL_FORMAT_UNKNOWN) {} | 84 last_captured_pixel_format_(media::PIXEL_FORMAT_UNKNOWN) {} |
| 84 | 85 |
| 85 VideoCaptureDeviceClient::~VideoCaptureDeviceClient() { | 86 VideoCaptureDeviceClient::~VideoCaptureDeviceClient() { |
| 86 // This should be on the platform auxiliary thread since | 87 // This should be on the platform auxiliary thread since |
| 87 // |external_jpeg_decoder_| need to be destructed on the same thread as | 88 // |external_jpeg_decoder_| need to be destructed on the same thread as |
| 88 // OnIncomingCapturedData. | 89 // OnIncomingCapturedData. |
| 89 } | 90 } |
| 90 | 91 |
| 91 void VideoCaptureDeviceClient::OnIncomingCapturedData( | 92 void VideoCaptureDeviceClient::OnIncomingCapturedData( |
| 92 const uint8_t* data, | 93 const uint8_t* data, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 const int new_unrotated_width = frame_format.frame_size.width() & ~1; | 127 const int new_unrotated_width = frame_format.frame_size.width() & ~1; |
| 127 const int new_unrotated_height = frame_format.frame_size.height() & ~1; | 128 const int new_unrotated_height = frame_format.frame_size.height() & ~1; |
| 128 | 129 |
| 129 int destination_width = new_unrotated_width; | 130 int destination_width = new_unrotated_width; |
| 130 int destination_height = new_unrotated_height; | 131 int destination_height = new_unrotated_height; |
| 131 if (rotation == 90 || rotation == 270) | 132 if (rotation == 90 || rotation == 270) |
| 132 std::swap(destination_width, destination_height); | 133 std::swap(destination_width, destination_height); |
| 133 | 134 |
| 134 DCHECK_EQ(0, rotation % 90) << " Rotation must be a multiple of 90, now: " | 135 DCHECK_EQ(0, rotation % 90) << " Rotation must be a multiple of 90, now: " |
| 135 << rotation; | 136 << rotation; |
| 137 | |
| 138 if (is_back_camera_) { | |
| 139 // For back camera, we need to rotate (360 - screen_rotation). | |
| 140 // Ex: when screen rotation is 90, we have to rotate the frame by 270 | |
| 141 // clockwise. | |
| 142 rotation = (360 - rotation) % 360; | |
|
wuchengli
2016/11/16 12:15:19
Can we calculate the right rotation in VideoCaptur
shenghao
2016/11/17 08:41:45
Done.
| |
| 143 } | |
| 144 | |
| 136 libyuv::RotationMode rotation_mode = libyuv::kRotate0; | 145 libyuv::RotationMode rotation_mode = libyuv::kRotate0; |
| 137 if (rotation == 90) | 146 if (rotation == 90) |
| 138 rotation_mode = libyuv::kRotate90; | 147 rotation_mode = libyuv::kRotate90; |
| 139 else if (rotation == 180) | 148 else if (rotation == 180) |
| 140 rotation_mode = libyuv::kRotate180; | 149 rotation_mode = libyuv::kRotate180; |
| 141 else if (rotation == 270) | 150 else if (rotation == 270) |
| 142 rotation_mode = libyuv::kRotate270; | 151 rotation_mode = libyuv::kRotate270; |
| 143 | 152 |
| 144 const gfx::Size dimensions(destination_width, destination_height); | 153 const gfx::Size dimensions(destination_width, destination_height); |
| 145 uint8_t *y_plane_data, *u_plane_data, *v_plane_data; | 154 uint8_t *y_plane_data, *u_plane_data, *v_plane_data; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 348 } | 357 } |
| 349 | 358 |
| 350 void VideoCaptureDeviceClient::OnLog(const std::string& message) { | 359 void VideoCaptureDeviceClient::OnLog(const std::string& message) { |
| 351 receiver_->OnLog(message); | 360 receiver_->OnLog(message); |
| 352 } | 361 } |
| 353 | 362 |
| 354 double VideoCaptureDeviceClient::GetBufferPoolUtilization() const { | 363 double VideoCaptureDeviceClient::GetBufferPoolUtilization() const { |
| 355 return buffer_pool_->GetBufferPoolUtilization(); | 364 return buffer_pool_->GetBufferPoolUtilization(); |
| 356 } | 365 } |
| 357 | 366 |
| 367 void VideoCaptureDeviceClient::SetCameraFacing(bool is_back_camera) { | |
| 368 is_back_camera_ = is_back_camera; | |
| 369 } | |
| 370 | |
| 358 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> | 371 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> |
| 359 VideoCaptureDeviceClient::ReserveI420OutputBuffer( | 372 VideoCaptureDeviceClient::ReserveI420OutputBuffer( |
| 360 const gfx::Size& dimensions, | 373 const gfx::Size& dimensions, |
| 361 media::VideoPixelStorage storage, | 374 media::VideoPixelStorage storage, |
| 362 uint8_t** y_plane_data, | 375 uint8_t** y_plane_data, |
| 363 uint8_t** u_plane_data, | 376 uint8_t** u_plane_data, |
| 364 uint8_t** v_plane_data) { | 377 uint8_t** v_plane_data) { |
| 365 DCHECK(storage == media::PIXEL_STORAGE_CPU); | 378 DCHECK(storage == media::PIXEL_STORAGE_CPU); |
| 366 DCHECK(dimensions.height()); | 379 DCHECK(dimensions.height()); |
| 367 DCHECK(dimensions.width()); | 380 DCHECK(dimensions.width()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 405 return; | 418 return; |
| 406 memcpy(buffer->data(), data, length); | 419 memcpy(buffer->data(), data, length); |
| 407 const VideoCaptureFormat output_format = | 420 const VideoCaptureFormat output_format = |
| 408 VideoCaptureFormat(frame_format.frame_size, frame_format.frame_rate, | 421 VideoCaptureFormat(frame_format.frame_size, frame_format.frame_rate, |
| 409 media::PIXEL_FORMAT_Y16, media::PIXEL_STORAGE_CPU); | 422 media::PIXEL_FORMAT_Y16, media::PIXEL_STORAGE_CPU); |
| 410 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time, | 423 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time, |
| 411 timestamp); | 424 timestamp); |
| 412 } | 425 } |
| 413 | 426 |
| 414 } // namespace media | 427 } // namespace media |
| OLD | NEW |