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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "content/browser/compositor/image_transport_factory.h" | 10 #include "content/browser/compositor/image_transport_factory.h" |
| 11 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 11 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" |
| 12 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" | 12 #include "content/browser/gpu/browser_gpu_memory_buffer_manager.h" |
| 13 #include "content/browser/gpu/gpu_data_manager_impl.h" | 13 #include "content/browser/gpu/gpu_data_manager_impl.h" |
| 14 #include "content/browser/renderer_host/gpu_jpeg_decoder.h" | |
| 14 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" | 15 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" |
| 15 #include "content/browser/renderer_host/media/video_capture_controller.h" | 16 #include "content/browser/renderer_host/media/video_capture_controller.h" |
| 16 #include "content/common/gpu/client/context_provider_command_buffer.h" | 17 #include "content/common/gpu/client/context_provider_command_buffer.h" |
| 17 #include "content/common/gpu/client/gl_helper.h" | 18 #include "content/common/gpu/client/gl_helper.h" |
| 18 #include "content/common/gpu/client/gpu_channel_host.h" | 19 #include "content/common/gpu/client/gpu_channel_host.h" |
| 19 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" | 20 #include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h" |
| 20 #include "content/common/gpu/gpu_process_launch_causes.h" | 21 #include "content/common/gpu/gpu_process_launch_causes.h" |
| 21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 22 #include "gpu/command_buffer/common/mailbox_holder.h" | 23 #include "gpu/command_buffer/common/mailbox_holder.h" |
| 23 #include "media/base/bind_to_current_loop.h" | 24 #include "media/base/bind_to_current_loop.h" |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 scoped_ptr<GLHelper> gl_helper_; | 194 scoped_ptr<GLHelper> gl_helper_; |
| 194 | 195 |
| 195 DISALLOW_COPY_AND_ASSIGN(TextureWrapHelper); | 196 DISALLOW_COPY_AND_ASSIGN(TextureWrapHelper); |
| 196 }; | 197 }; |
| 197 | 198 |
| 198 VideoCaptureDeviceClient::VideoCaptureDeviceClient( | 199 VideoCaptureDeviceClient::VideoCaptureDeviceClient( |
| 199 const base::WeakPtr<VideoCaptureController>& controller, | 200 const base::WeakPtr<VideoCaptureController>& controller, |
| 200 const scoped_refptr<VideoCaptureBufferPool>& buffer_pool, | 201 const scoped_refptr<VideoCaptureBufferPool>& buffer_pool, |
| 201 const scoped_refptr<base::SingleThreadTaskRunner>& capture_task_runner) | 202 const scoped_refptr<base::SingleThreadTaskRunner>& capture_task_runner) |
| 202 : controller_(controller), | 203 : controller_(controller), |
| 204 external_jpeg_decoder_initialized_(false), | |
| 203 buffer_pool_(buffer_pool), | 205 buffer_pool_(buffer_pool), |
| 204 capture_task_runner_(capture_task_runner), | 206 capture_task_runner_(capture_task_runner), |
| 205 last_captured_pixel_format_(media::PIXEL_FORMAT_UNKNOWN) { | 207 last_captured_pixel_format_(media::PIXEL_FORMAT_UNKNOWN) { |
| 206 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 208 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 207 } | 209 } |
| 208 | 210 |
| 209 VideoCaptureDeviceClient::~VideoCaptureDeviceClient() {} | 211 VideoCaptureDeviceClient::~VideoCaptureDeviceClient() { |
| 212 DCHECK(capture_task_runner_->BelongsToCurrentThread()); | |
| 213 external_jpeg_decoder_.reset(); | |
| 214 } | |
| 210 | 215 |
| 211 void VideoCaptureDeviceClient::OnIncomingCapturedData( | 216 void VideoCaptureDeviceClient::OnIncomingCapturedData( |
| 212 const uint8* data, | 217 const uint8* data, |
| 213 int length, | 218 int length, |
| 214 const VideoCaptureFormat& frame_format, | 219 const VideoCaptureFormat& frame_format, |
| 215 int rotation, | 220 int rotation, |
| 216 const base::TimeTicks& timestamp) { | 221 const base::TimeTicks& timestamp) { |
| 217 TRACE_EVENT0("video", "VideoCaptureDeviceClient::OnIncomingCapturedData"); | 222 TRACE_EVENT0("video", "VideoCaptureDeviceClient::OnIncomingCapturedData"); |
| 218 | 223 |
| 219 if (last_captured_pixel_format_ != frame_format.pixel_format) { | 224 if (last_captured_pixel_format_ != frame_format.pixel_format) { |
| 220 OnLog("Pixel format: " + media::VideoCaptureFormat::PixelFormatToString( | 225 OnLog("Pixel format: " + media::VideoCaptureFormat::PixelFormatToString( |
| 221 frame_format.pixel_format)); | 226 frame_format.pixel_format)); |
| 222 last_captured_pixel_format_ = frame_format.pixel_format; | 227 last_captured_pixel_format_ = frame_format.pixel_format; |
| 228 | |
| 229 if (frame_format.pixel_format == media::PIXEL_FORMAT_MJPEG && | |
| 230 !external_jpeg_decoder_initialized_) { | |
|
Pawel Osciak
2015/06/22 08:51:23
Perhaps instead:
if (format ==... && GpuJpegDecod
kcwu
2015/06/23 13:58:25
Done.
| |
| 231 external_jpeg_decoder_initialized_ = true; | |
| 232 if (GpuJpegDecoder::Supported()) { | |
| 233 // base::Unretained is safe because |this| outlives | |
| 234 // |external_jpeg_decoder_| and the callbacks are never called after | |
| 235 // |external_jpeg_decoder_| is destroyed. | |
| 236 external_jpeg_decoder_.reset(new GpuJpegDecoder( | |
| 237 base::Bind( | |
| 238 &VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread, | |
| 239 controller_), | |
| 240 // TODO(kcwu): fallback to software decode if error. | |
|
Pawel Osciak
2015/06/22 08:51:23
Please add a crbug.
kcwu
2015/06/23 13:58:25
Done.
| |
| 241 base::Bind(&VideoCaptureDeviceClient::OnError, | |
| 242 base::Unretained(this)))); | |
| 243 external_jpeg_decoder_->Initialize(); | |
| 244 } | |
| 245 } | |
| 223 } | 246 } |
| 224 | 247 |
| 225 if (!frame_format.IsValid()) | 248 if (!frame_format.IsValid()) |
| 226 return; | 249 return; |
| 227 | 250 |
| 228 // |chopped_{width,height} and |new_unrotated_{width,height}| are the lowest | 251 // |chopped_{width,height} and |new_unrotated_{width,height}| are the lowest |
| 229 // bit decomposition of {width, height}, grabbing the odd and even parts. | 252 // bit decomposition of {width, height}, grabbing the odd and even parts. |
| 230 const int chopped_width = frame_format.frame_size.width() & 1; | 253 const int chopped_width = frame_format.frame_size.width() & 1; |
| 231 const int chopped_height = frame_format.frame_size.height() & 1; | 254 const int chopped_height = frame_format.frame_size.height() & 1; |
| 232 const int new_unrotated_width = frame_format.frame_size.width() & ~1; | 255 const int new_unrotated_width = frame_format.frame_size.width() & ~1; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 origin_colorspace = libyuv::FOURCC_MJPG; | 349 origin_colorspace = libyuv::FOURCC_MJPG; |
| 327 break; | 350 break; |
| 328 default: | 351 default: |
| 329 NOTREACHED(); | 352 NOTREACHED(); |
| 330 } | 353 } |
| 331 | 354 |
| 332 // The input |length| can be greater than the required buffer size because of | 355 // The input |length| can be greater than the required buffer size because of |
| 333 // paddings and/or alignments, but it cannot be smaller. | 356 // paddings and/or alignments, but it cannot be smaller. |
| 334 DCHECK_GE(static_cast<size_t>(length), frame_format.ImageAllocationSize()); | 357 DCHECK_GE(static_cast<size_t>(length), frame_format.ImageAllocationSize()); |
| 335 | 358 |
| 359 if (external_jpeg_decoder_ && | |
| 360 frame_format.pixel_format == media::PIXEL_FORMAT_MJPEG && rotation == 0 && | |
| 361 !flip && external_jpeg_decoder_->ReadyToDecode()) { | |
| 362 external_jpeg_decoder_->DecodeCapturedData(data, length, frame_format, | |
| 363 timestamp, buffer.Pass()); | |
| 364 return; | |
| 365 } | |
| 366 | |
| 336 if (libyuv::ConvertToI420(data, | 367 if (libyuv::ConvertToI420(data, |
| 337 length, | 368 length, |
| 338 yplane, | 369 yplane, |
| 339 yplane_stride, | 370 yplane_stride, |
| 340 uplane, | 371 uplane, |
| 341 uv_plane_stride, | 372 uv_plane_stride, |
| 342 vplane, | 373 vplane, |
| 343 uv_plane_stride, | 374 uv_plane_stride, |
| 344 crop_x, | 375 crop_x, |
| 345 crop_y, | 376 crop_y, |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 679 void VideoCaptureDeviceClient::TextureWrapHelper::OnError( | 710 void VideoCaptureDeviceClient::TextureWrapHelper::OnError( |
| 680 const std::string& message) { | 711 const std::string& message) { |
| 681 DCHECK(capture_task_runner_->BelongsToCurrentThread()); | 712 DCHECK(capture_task_runner_->BelongsToCurrentThread()); |
| 682 DLOG(ERROR) << message; | 713 DLOG(ERROR) << message; |
| 683 BrowserThread::PostTask( | 714 BrowserThread::PostTask( |
| 684 BrowserThread::IO, FROM_HERE, | 715 BrowserThread::IO, FROM_HERE, |
| 685 base::Bind(&VideoCaptureController::DoErrorOnIOThread, controller_)); | 716 base::Bind(&VideoCaptureController::DoErrorOnIOThread, controller_)); |
| 686 } | 717 } |
| 687 | 718 |
| 688 } // namespace content | 719 } // namespace content |
| OLD | NEW |