| 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_gpu_jpeg_decoder.h" | 5 #include "content/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 18 #include "content/browser/gpu/browser_gpu_channel_host_factory.h" | 18 #include "content/browser/browser_main_loop.h" |
| 19 #include "content/browser/gpu/gpu_process_host.h" | 19 #include "content/browser/gpu/gpu_process_host.h" |
| 20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
| 22 #include "gpu/ipc/client/gpu_channel_host.h" |
| 22 #include "media/base/media_switches.h" | 23 #include "media/base/media_switches.h" |
| 23 #include "media/base/video_frame.h" | 24 #include "media/base/video_frame.h" |
| 24 #include "media/gpu/ipc/client/gpu_jpeg_decode_accelerator_host.h" | 25 #include "media/gpu/ipc/client/gpu_jpeg_decode_accelerator_host.h" |
| 25 #include "mojo/public/cpp/system/platform_handle.h" | 26 #include "mojo/public/cpp/system/platform_handle.h" |
| 26 | 27 |
| 27 namespace content { | 28 namespace content { |
| 28 | 29 |
| 29 VideoCaptureGpuJpegDecoder::VideoCaptureGpuJpegDecoder( | 30 VideoCaptureGpuJpegDecoder::VideoCaptureGpuJpegDecoder( |
| 30 DecodeDoneCB decode_done_cb, | 31 DecodeDoneCB decode_done_cb, |
| 31 base::Callback<void(const std::string&)> send_log_message_cb) | 32 base::Callback<void(const std::string&)> send_log_message_cb) |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 244 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 244 // TODO(c.padhi): Implement this, see http://crbug.com/699255. | 245 // TODO(c.padhi): Implement this, see http://crbug.com/699255. |
| 245 NOTIMPLEMENTED(); | 246 NOTIMPLEMENTED(); |
| 246 } | 247 } |
| 247 | 248 |
| 248 // static | 249 // static |
| 249 void VideoCaptureGpuJpegDecoder::EstablishGpuChannelOnUIThread( | 250 void VideoCaptureGpuJpegDecoder::EstablishGpuChannelOnUIThread( |
| 250 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 251 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 251 base::WeakPtr<VideoCaptureGpuJpegDecoder> weak_this) { | 252 base::WeakPtr<VideoCaptureGpuJpegDecoder> weak_this) { |
| 252 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 253 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 253 DCHECK(BrowserGpuChannelHostFactory::instance()); | |
| 254 | 254 |
| 255 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel( | 255 BrowserMainLoop::GetInstance() |
| 256 base::Bind(&VideoCaptureGpuJpegDecoder::GpuChannelEstablishedOnUIThread, | 256 ->gpu_channel_establish_factory() |
| 257 task_runner, weak_this)); | 257 ->EstablishGpuChannel(base::Bind( |
| 258 &VideoCaptureGpuJpegDecoder::GpuChannelEstablishedOnUIThread, |
| 259 task_runner, weak_this)); |
| 258 } | 260 } |
| 259 | 261 |
| 260 // static | 262 // static |
| 261 void VideoCaptureGpuJpegDecoder::GpuChannelEstablishedOnUIThread( | 263 void VideoCaptureGpuJpegDecoder::GpuChannelEstablishedOnUIThread( |
| 262 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 264 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 263 base::WeakPtr<VideoCaptureGpuJpegDecoder> weak_this, | 265 base::WeakPtr<VideoCaptureGpuJpegDecoder> weak_this, |
| 264 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) { | 266 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) { |
| 265 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 267 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 266 | 268 |
| 267 task_runner->PostTask( | 269 task_runner->PostTask( |
| 268 FROM_HERE, base::Bind(&VideoCaptureGpuJpegDecoder::FinishInitialization, | 270 FROM_HERE, base::Bind(&VideoCaptureGpuJpegDecoder::FinishInitialization, |
| 269 weak_this, std::move(gpu_channel_host))); | 271 weak_this, std::move(gpu_channel_host))); |
| 270 } | 272 } |
| 271 | 273 |
| 272 void VideoCaptureGpuJpegDecoder::FinishInitialization( | 274 void VideoCaptureGpuJpegDecoder::FinishInitialization( |
| 273 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) { | 275 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) { |
| 274 TRACE_EVENT0("gpu", "VideoCaptureGpuJpegDecoder::FinishInitialization"); | 276 TRACE_EVENT0("gpu", "VideoCaptureGpuJpegDecoder::FinishInitialization"); |
| 275 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 277 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 276 base::AutoLock lock(lock_); | 278 base::AutoLock lock(lock_); |
| 277 if (!gpu_channel_host) { | 279 if (!gpu_channel_host) { |
| 278 LOG(ERROR) << "Failed to establish GPU channel for JPEG decoder"; | 280 LOG(ERROR) << "Failed to establish GPU channel for JPEG decoder"; |
| 279 } else if (gpu_channel_host->gpu_info().jpeg_decode_accelerator_supported) { | 281 } else if (gpu_channel_host->gpu_info().jpeg_decode_accelerator_supported) { |
| 280 gpu_channel_host_ = std::move(gpu_channel_host); | 282 gpu_channel_host_ = std::move(gpu_channel_host); |
| 281 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner = | 283 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner = |
| 282 BrowserGpuChannelHostFactory::instance()->GetIOThreadTaskRunner(); | 284 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO); |
| 283 | 285 |
| 284 int32_t route_id = gpu_channel_host_->GenerateRouteID(); | 286 int32_t route_id = gpu_channel_host_->GenerateRouteID(); |
| 285 std::unique_ptr<media::GpuJpegDecodeAcceleratorHost> decoder( | 287 std::unique_ptr<media::GpuJpegDecodeAcceleratorHost> decoder( |
| 286 new media::GpuJpegDecodeAcceleratorHost(gpu_channel_host_.get(), | 288 new media::GpuJpegDecodeAcceleratorHost(gpu_channel_host_.get(), |
| 287 route_id, io_task_runner)); | 289 route_id, io_task_runner)); |
| 288 if (decoder->Initialize(this)) { | 290 if (decoder->Initialize(this)) { |
| 289 gpu_channel_host_->AddRouteWithTaskRunner( | 291 gpu_channel_host_->AddRouteWithTaskRunner( |
| 290 route_id, decoder->GetReceiver(), io_task_runner); | 292 route_id, decoder->GetReceiver(), io_task_runner); |
| 291 decoder_ = std::move(decoder); | 293 decoder_ = std::move(decoder); |
| 292 } else { | 294 } else { |
| 293 DLOG(ERROR) << "Failed to initialize JPEG decoder"; | 295 DLOG(ERROR) << "Failed to initialize JPEG decoder"; |
| 294 } | 296 } |
| 295 } | 297 } |
| 296 decoder_status_ = decoder_ ? INIT_PASSED : FAILED; | 298 decoder_status_ = decoder_ ? INIT_PASSED : FAILED; |
| 297 RecordInitDecodeUMA_Locked(); | 299 RecordInitDecodeUMA_Locked(); |
| 298 } | 300 } |
| 299 | 301 |
| 300 bool VideoCaptureGpuJpegDecoder::IsDecoding_Locked() const { | 302 bool VideoCaptureGpuJpegDecoder::IsDecoding_Locked() const { |
| 301 lock_.AssertAcquired(); | 303 lock_.AssertAcquired(); |
| 302 return !decode_done_closure_.is_null(); | 304 return !decode_done_closure_.is_null(); |
| 303 } | 305 } |
| 304 | 306 |
| 305 void VideoCaptureGpuJpegDecoder::RecordInitDecodeUMA_Locked() { | 307 void VideoCaptureGpuJpegDecoder::RecordInitDecodeUMA_Locked() { |
| 306 UMA_HISTOGRAM_BOOLEAN("Media.VideoCaptureGpuJpegDecoder.InitDecodeSuccess", | 308 UMA_HISTOGRAM_BOOLEAN("Media.VideoCaptureGpuJpegDecoder.InitDecodeSuccess", |
| 307 decoder_status_ == INIT_PASSED); | 309 decoder_status_ == INIT_PASSED); |
| 308 } | 310 } |
| 309 | 311 |
| 310 } // namespace content | 312 } // namespace content |
| OLD | NEW |