Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(991)

Side by Side Diff: content/browser/renderer_host/media/video_capture_device_client.cc

Issue 1132683004: MJPEG acceleration for video capture, browser part (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mjpeg-2-gpu
Patch Set: fix gpu channel establish Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_) {
231 external_jpeg_decoder_initialized_ = true;
232 if (GpuJpegDecoder::Supported()) {
233 // base::Unretained is safe because |this| outlives
234 // |external_jpeg_decoder_|.
235 external_jpeg_decoder_.reset(new GpuJpegDecoder(
236 base::Bind(
237 &VideoCaptureController::DoIncomingCapturedVideoFrameOnIOThread,
238 controller_),
239 // TODO(kcwu): fallback to software decode if error.
240 base::Bind(&VideoCaptureDeviceClient::OnError,
241 base::Unretained(this))));
piman 2015/06/20 00:33:57 nit: can you add a comment about why Unretained is
kcwu 2015/06/20 00:47:08 line 233 does. Do you want me to explain it furthe
piman 2015/06/20 00:59:26 Oh, missed that. I guess that's fine... the main t
kcwu 2015/06/20 01:26:10 Done.
242 external_jpeg_decoder_->Initialize();
243 }
244 }
223 } 245 }
224 246
225 if (!frame_format.IsValid()) 247 if (!frame_format.IsValid())
226 return; 248 return;
227 249
228 // |chopped_{width,height} and |new_unrotated_{width,height}| are the lowest 250 // |chopped_{width,height} and |new_unrotated_{width,height}| are the lowest
229 // bit decomposition of {width, height}, grabbing the odd and even parts. 251 // bit decomposition of {width, height}, grabbing the odd and even parts.
230 const int chopped_width = frame_format.frame_size.width() & 1; 252 const int chopped_width = frame_format.frame_size.width() & 1;
231 const int chopped_height = frame_format.frame_size.height() & 1; 253 const int chopped_height = frame_format.frame_size.height() & 1;
232 const int new_unrotated_width = frame_format.frame_size.width() & ~1; 254 const int new_unrotated_width = frame_format.frame_size.width() & ~1;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 origin_colorspace = libyuv::FOURCC_MJPG; 348 origin_colorspace = libyuv::FOURCC_MJPG;
327 break; 349 break;
328 default: 350 default:
329 NOTREACHED(); 351 NOTREACHED();
330 } 352 }
331 353
332 // The input |length| can be greater than the required buffer size because of 354 // The input |length| can be greater than the required buffer size because of
333 // paddings and/or alignments, but it cannot be smaller. 355 // paddings and/or alignments, but it cannot be smaller.
334 DCHECK_GE(static_cast<size_t>(length), frame_format.ImageAllocationSize()); 356 DCHECK_GE(static_cast<size_t>(length), frame_format.ImageAllocationSize());
335 357
358 if (external_jpeg_decoder_ &&
359 frame_format.pixel_format == media::PIXEL_FORMAT_MJPEG && rotation == 0 &&
360 !flip && external_jpeg_decoder_->ReadyToDecode()) {
361 external_jpeg_decoder_->DecodeCapturedData(data, length, frame_format,
362 timestamp, buffer.Pass());
363 return;
364 }
365
336 if (libyuv::ConvertToI420(data, 366 if (libyuv::ConvertToI420(data,
337 length, 367 length,
338 yplane, 368 yplane,
339 yplane_stride, 369 yplane_stride,
340 uplane, 370 uplane,
341 uv_plane_stride, 371 uv_plane_stride,
342 vplane, 372 vplane,
343 uv_plane_stride, 373 uv_plane_stride,
344 crop_x, 374 crop_x,
345 crop_y, 375 crop_y,
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 void VideoCaptureDeviceClient::TextureWrapHelper::OnError( 709 void VideoCaptureDeviceClient::TextureWrapHelper::OnError(
680 const std::string& message) { 710 const std::string& message) {
681 DCHECK(capture_task_runner_->BelongsToCurrentThread()); 711 DCHECK(capture_task_runner_->BelongsToCurrentThread());
682 DLOG(ERROR) << message; 712 DLOG(ERROR) << message;
683 BrowserThread::PostTask( 713 BrowserThread::PostTask(
684 BrowserThread::IO, FROM_HERE, 714 BrowserThread::IO, FROM_HERE,
685 base::Bind(&VideoCaptureController::DoErrorOnIOThread, controller_)); 715 base::Bind(&VideoCaptureController::DoErrorOnIOThread, controller_));
686 } 716 }
687 717
688 } // namespace content 718 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/video_capture_device_client.h ('k') | content/common/gpu/gpu_process_launch_causes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698