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 "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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 // This should be on the platform auxiliary thread since | 78 // This should be on the platform auxiliary thread since |
| 79 // |external_jpeg_decoder_| need to be destructed on the same thread as | 79 // |external_jpeg_decoder_| need to be destructed on the same thread as |
| 80 // OnIncomingCapturedData. | 80 // OnIncomingCapturedData. |
| 81 } | 81 } |
| 82 | 82 |
| 83 void VideoCaptureDeviceClient::OnIncomingCapturedData( | 83 void VideoCaptureDeviceClient::OnIncomingCapturedData( |
| 84 const uint8_t* data, | 84 const uint8_t* data, |
| 85 int length, | 85 int length, |
| 86 const VideoCaptureFormat& frame_format, | 86 const VideoCaptureFormat& frame_format, |
| 87 int rotation, | 87 int rotation, |
| 88 const base::TimeTicks& timestamp) { | 88 base::TimeTicks reference_time, |
| 89 base::TimeDelta timestamp) { | |
| 89 TRACE_EVENT0("video", "VideoCaptureDeviceClient::OnIncomingCapturedData"); | 90 TRACE_EVENT0("video", "VideoCaptureDeviceClient::OnIncomingCapturedData"); |
| 90 DCHECK_EQ(media::PIXEL_STORAGE_CPU, frame_format.pixel_storage); | 91 DCHECK_EQ(media::PIXEL_STORAGE_CPU, frame_format.pixel_storage); |
| 91 | 92 |
| 92 if (last_captured_pixel_format_ != frame_format.pixel_format) { | 93 if (last_captured_pixel_format_ != frame_format.pixel_format) { |
| 93 OnLog("Pixel format: " + | 94 OnLog("Pixel format: " + |
| 94 media::VideoPixelFormatToString(frame_format.pixel_format)); | 95 media::VideoPixelFormatToString(frame_format.pixel_format)); |
| 95 last_captured_pixel_format_ = frame_format.pixel_format; | 96 last_captured_pixel_format_ = frame_format.pixel_format; |
| 96 | 97 |
| 97 if (frame_format.pixel_format == media::PIXEL_FORMAT_MJPEG && | 98 if (frame_format.pixel_format == media::PIXEL_FORMAT_MJPEG && |
| 98 !external_jpeg_decoder_initialized_) { | 99 !external_jpeg_decoder_initialized_) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 DCHECK_GE(static_cast<size_t>(length), frame_format.ImageAllocationSize()); | 218 DCHECK_GE(static_cast<size_t>(length), frame_format.ImageAllocationSize()); |
| 218 | 219 |
| 219 if (external_jpeg_decoder_) { | 220 if (external_jpeg_decoder_) { |
| 220 const VideoCaptureGpuJpegDecoder::STATUS status = | 221 const VideoCaptureGpuJpegDecoder::STATUS status = |
| 221 external_jpeg_decoder_->GetStatus(); | 222 external_jpeg_decoder_->GetStatus(); |
| 222 if (status == VideoCaptureGpuJpegDecoder::FAILED) { | 223 if (status == VideoCaptureGpuJpegDecoder::FAILED) { |
| 223 external_jpeg_decoder_.reset(); | 224 external_jpeg_decoder_.reset(); |
| 224 } else if (status == VideoCaptureGpuJpegDecoder::INIT_PASSED && | 225 } else if (status == VideoCaptureGpuJpegDecoder::INIT_PASSED && |
| 225 frame_format.pixel_format == media::PIXEL_FORMAT_MJPEG && | 226 frame_format.pixel_format == media::PIXEL_FORMAT_MJPEG && |
| 226 rotation == 0 && !flip) { | 227 rotation == 0 && !flip) { |
| 227 external_jpeg_decoder_->DecodeCapturedData(data, length, frame_format, | 228 external_jpeg_decoder_->DecodeCapturedData( |
| 228 timestamp, std::move(buffer)); | 229 data, length, frame_format, reference_time, std::move(buffer)); |
| 229 return; | 230 return; |
| 230 } | 231 } |
| 231 } | 232 } |
| 232 | 233 |
| 233 if (libyuv::ConvertToI420(data, | 234 if (libyuv::ConvertToI420(data, |
| 234 length, | 235 length, |
| 235 y_plane_data, | 236 y_plane_data, |
| 236 yplane_stride, | 237 yplane_stride, |
| 237 u_plane_data, | 238 u_plane_data, |
| 238 uv_plane_stride, | 239 uv_plane_stride, |
| 239 v_plane_data, | 240 v_plane_data, |
| 240 uv_plane_stride, | 241 uv_plane_stride, |
| 241 crop_x, | 242 crop_x, |
| 242 crop_y, | 243 crop_y, |
| 243 frame_format.frame_size.width(), | 244 frame_format.frame_size.width(), |
| 244 (flip ? -1 : 1) * frame_format.frame_size.height(), | 245 (flip ? -1 : 1) * frame_format.frame_size.height(), |
| 245 new_unrotated_width, | 246 new_unrotated_width, |
| 246 new_unrotated_height, | 247 new_unrotated_height, |
| 247 rotation_mode, | 248 rotation_mode, |
| 248 origin_colorspace) != 0) { | 249 origin_colorspace) != 0) { |
| 249 DLOG(WARNING) << "Failed to convert buffer's pixel format to I420 from " | 250 DLOG(WARNING) << "Failed to convert buffer's pixel format to I420 from " |
| 250 << media::VideoPixelFormatToString(frame_format.pixel_format); | 251 << media::VideoPixelFormatToString(frame_format.pixel_format); |
| 251 return; | 252 return; |
| 252 } | 253 } |
| 253 | 254 |
| 254 const VideoCaptureFormat output_format = VideoCaptureFormat( | 255 const VideoCaptureFormat output_format = VideoCaptureFormat( |
| 255 dimensions, frame_format.frame_rate, | 256 dimensions, frame_format.frame_rate, |
| 256 media::PIXEL_FORMAT_I420, output_pixel_storage); | 257 media::PIXEL_FORMAT_I420, output_pixel_storage); |
| 257 OnIncomingCapturedBuffer(std::move(buffer), output_format, timestamp); | 258 OnIncomingCapturedBuffer(std::move(buffer), output_format, reference_time); |
|
miu
2016/05/18 22:35:40
See comment I made in video_capture_device.h. You'
qiangchen
2016/05/20 17:55:14
Done.
| |
| 258 } | 259 } |
| 259 | 260 |
| 260 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> | 261 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> |
| 261 VideoCaptureDeviceClient::ReserveOutputBuffer( | 262 VideoCaptureDeviceClient::ReserveOutputBuffer( |
| 262 const gfx::Size& frame_size, | 263 const gfx::Size& frame_size, |
| 263 media::VideoPixelFormat pixel_format, | 264 media::VideoPixelFormat pixel_format, |
| 264 media::VideoPixelStorage pixel_storage) { | 265 media::VideoPixelStorage pixel_storage) { |
| 265 DCHECK_GT(frame_size.width(), 0); | 266 DCHECK_GT(frame_size.width(), 0); |
| 266 DCHECK_GT(frame_size.height(), 0); | 267 DCHECK_GT(frame_size.height(), 0); |
| 267 // Currently, only I420 pixel format is supported. | 268 // Currently, only I420 pixel format is supported. |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kUPlane)); | 417 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kUPlane)); |
| 417 *v_plane_data = | 418 *v_plane_data = |
| 418 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kVPlane)); | 419 reinterpret_cast<uint8_t*>(buffer->data(VideoFrame::kVPlane)); |
| 419 return buffer; | 420 return buffer; |
| 420 } | 421 } |
| 421 NOTREACHED(); | 422 NOTREACHED(); |
| 422 return std::unique_ptr<Buffer>(); | 423 return std::unique_ptr<Buffer>(); |
| 423 } | 424 } |
| 424 | 425 |
| 425 } // namespace content | 426 } // namespace content |
| OLD | NEW |