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