Chromium Code Reviews| Index: content/browser/renderer_host/media/video_capture_device_client.cc |
| diff --git a/content/browser/renderer_host/media/video_capture_device_client.cc b/content/browser/renderer_host/media/video_capture_device_client.cc |
| index 5aa16396c83e66557fedb9df031c0a6997524113..9c040e1adfd6015cacc41a9b4fb7342aa274afd0 100644 |
| --- a/content/browser/renderer_host/media/video_capture_device_client.cc |
| +++ b/content/browser/renderer_host/media/video_capture_device_client.cc |
| @@ -15,6 +15,7 @@ |
| #include "content/browser/gpu/gpu_data_manager_impl.h" |
| #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" |
| #include "content/browser/renderer_host/media/video_capture_controller.h" |
| +#include "content/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.h" |
| #include "content/common/gpu/client/context_provider_command_buffer.h" |
| #include "content/common/gpu/client/gl_helper.h" |
| #include "content/common/gpu/client/gpu_channel_host.h" |
| @@ -201,13 +202,17 @@ VideoCaptureDeviceClient::VideoCaptureDeviceClient( |
| const scoped_refptr<VideoCaptureBufferPool>& buffer_pool, |
| const scoped_refptr<base::SingleThreadTaskRunner>& capture_task_runner) |
| : controller_(controller), |
| + external_jpeg_decoder_initialized_(false), |
| buffer_pool_(buffer_pool), |
| capture_task_runner_(capture_task_runner), |
| last_captured_pixel_format_(media::PIXEL_FORMAT_UNKNOWN) { |
| DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| } |
| -VideoCaptureDeviceClient::~VideoCaptureDeviceClient() {} |
| +VideoCaptureDeviceClient::~VideoCaptureDeviceClient() { |
| + DCHECK(capture_task_runner_->BelongsToCurrentThread()); |
| + external_jpeg_decoder_.reset(); |
|
Pawel Osciak
2015/06/29 06:18:39
Not needed?
kcwu
2015/06/29 10:35:34
Replaced by a comment to explain the thread constr
|
| +} |
| void VideoCaptureDeviceClient::OnIncomingCapturedData( |
| const uint8* data, |
| @@ -221,6 +226,25 @@ void VideoCaptureDeviceClient::OnIncomingCapturedData( |
| OnLog("Pixel format: " + media::VideoCaptureFormat::PixelFormatToString( |
| frame_format.pixel_format)); |
| last_captured_pixel_format_ = frame_format.pixel_format; |
| + |
| + if (frame_format.pixel_format == media::PIXEL_FORMAT_MJPEG && |
| + VideoCaptureGpuJpegDecoder::Supported()) { |
| + if (!external_jpeg_decoder_initialized_) { |
| + external_jpeg_decoder_initialized_ = true; |
| + // base::Unretained is safe because |this| outlives |
| + // |external_jpeg_decoder_| and the callbacks are never called after |
| + // |external_jpeg_decoder_| is destroyed. |
| + external_jpeg_decoder_.reset(new VideoCaptureGpuJpegDecoder( |
| + base::Bind( |
| + &VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread, |
| + controller_), |
| + // TODO(kcwu): fallback to software decode if error. |
| + // https://crbug.com/503532 |
| + base::Bind(&VideoCaptureDeviceClient::OnError, |
| + base::Unretained(this)))); |
| + external_jpeg_decoder_->Initialize(); |
| + } |
| + } |
| } |
| if (!frame_format.IsValid()) |
| @@ -333,6 +357,14 @@ void VideoCaptureDeviceClient::OnIncomingCapturedData( |
| // paddings and/or alignments, but it cannot be smaller. |
| DCHECK_GE(static_cast<size_t>(length), frame_format.ImageAllocationSize()); |
| + if (external_jpeg_decoder_ && |
| + frame_format.pixel_format == media::PIXEL_FORMAT_MJPEG && rotation == 0 && |
|
Pawel Osciak
2015/06/29 06:18:39
Could we decode in HW and rotate afterwards using
kcwu
2015/06/29 10:35:34
Yes, however I'd prefer do it in another CL.
|
| + !flip && external_jpeg_decoder_->ReadyToDecode()) { |
| + external_jpeg_decoder_->DecodeCapturedData(data, length, frame_format, |
| + timestamp, buffer.Pass()); |
| + return; |
| + } |
| + |
| if (libyuv::ConvertToI420(data, |
| length, |
| yplane, |