| 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/gpu/browser_gpu_channel_host_factory.h" |
| 19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/gpu_data_manager.h" |
| 21 #include "content/public/browser/gpu_service_registry.h" |
| 20 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
| 21 #include "media/base/media_switches.h" | 23 #include "media/base/media_switches.h" |
| 22 #include "media/base/video_frame.h" | 24 #include "media/base/video_frame.h" |
| 23 #include "media/gpu/ipc/client/gpu_jpeg_decode_accelerator_host.h" | |
| 24 #include "mojo/public/cpp/system/platform_handle.h" | 25 #include "mojo/public/cpp/system/platform_handle.h" |
| 25 | 26 |
| 26 namespace content { | 27 namespace content { |
| 27 | 28 |
| 28 VideoCaptureGpuJpegDecoder::VideoCaptureGpuJpegDecoder( | 29 VideoCaptureGpuJpegDecoder::VideoCaptureGpuJpegDecoder( |
| 29 DecodeDoneCB decode_done_cb, | 30 DecodeDoneCB decode_done_cb, |
| 30 base::Callback<void(const std::string&)> send_log_message_cb) | 31 base::Callback<void(const std::string&)> send_log_message_cb) |
| 31 : decode_done_cb_(std::move(decode_done_cb)), | 32 : decode_done_cb_(std::move(decode_done_cb)), |
| 32 send_log_message_cb_(std::move(send_log_message_cb)), | 33 send_log_message_cb_(std::move(send_log_message_cb)), |
| 33 has_received_decoded_frame_(false), | 34 has_received_decoded_frame_(false), |
| 34 next_bitstream_buffer_id_(0), | 35 next_bitstream_buffer_id_(0), |
| 35 in_buffer_id_(media::JpegDecodeAccelerator::kInvalidBitstreamBufferId), | 36 in_buffer_id_(media::JpegDecodeAccelerator::kInvalidBitstreamBufferId), |
| 36 decoder_status_(INIT_PENDING) {} | 37 decoder_status_(INIT_PENDING) {} |
| 37 | 38 |
| 38 VideoCaptureGpuJpegDecoder::~VideoCaptureGpuJpegDecoder() { | 39 VideoCaptureGpuJpegDecoder::~VideoCaptureGpuJpegDecoder() { |
| 39 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 40 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 40 | 41 |
| 41 // |decoder_| guarantees no more JpegDecodeAccelerator::Client callbacks | 42 // |decoder_| guarantees no more JpegDecodeAccelerator::Client callbacks |
| 42 // on IO thread after deletion. | 43 // on IO thread after deletion. |
| 43 decoder_.reset(); | 44 decoder_.reset(); |
| 44 | |
| 45 // |gpu_channel_host_| should outlive |decoder_|, so |gpu_channel_host_| | |
| 46 // must be released after |decoder_| has been destroyed. | |
| 47 gpu_channel_host_ = nullptr; | |
| 48 } | 45 } |
| 49 | 46 |
| 50 void VideoCaptureGpuJpegDecoder::Initialize() { | 47 void VideoCaptureGpuJpegDecoder::Initialize() { |
| 51 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 48 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 52 | 49 |
| 53 base::AutoLock lock(lock_); | 50 base::AutoLock lock(lock_); |
| 54 bool is_platform_supported = | 51 bool is_platform_supported = |
| 55 base::CommandLine::ForCurrentProcess()->HasSwitch( | 52 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 56 switches::kUseFakeJpegDecodeAccelerator); | 53 switches::kUseFakeJpegDecodeAccelerator); |
| 57 #if defined(OS_CHROMEOS) | 54 #if defined(OS_CHROMEOS) |
| 58 // Non-ChromeOS platforms do not support HW JPEG decode now. Do not establish | 55 // Non-ChromeOS platforms do not support HW JPEG decode now. Do not establish |
| 59 // gpu channel to avoid introducing overhead. | 56 // gpu channel to avoid introducing overhead. |
| 60 is_platform_supported = true; | 57 is_platform_supported = true; |
| 61 #endif | 58 #endif |
| 62 | 59 |
| 63 if (!is_platform_supported || | 60 if (!is_platform_supported || |
| 64 base::CommandLine::ForCurrentProcess()->HasSwitch( | 61 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 65 switches::kDisableAcceleratedMjpegDecode)) { | 62 switches::kDisableAcceleratedMjpegDecode)) { |
| 66 decoder_status_ = FAILED; | 63 decoder_status_ = FAILED; |
| 67 RecordInitDecodeUMA_Locked(); | 64 RecordInitDecodeUMA_Locked(); |
| 68 return; | 65 return; |
| 69 } | 66 } |
| 70 | 67 |
| 71 const scoped_refptr<base::SingleThreadTaskRunner> current_task_runner( | 68 const scoped_refptr<base::SingleThreadTaskRunner> current_task_runner( |
| 72 base::ThreadTaskRunnerHandle::Get()); | 69 base::ThreadTaskRunnerHandle::Get()); |
| 73 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 70 BrowserThread::PostTask( |
| 74 base::Bind(&EstablishGpuChannelOnUIThread, | 71 BrowserThread::IO, FROM_HERE, |
| 75 current_task_runner, AsWeakPtr())); | 72 base::Bind(&ConnectToGpuJpegDecodeAcceleratorOnIOThread, |
| 73 current_task_runner, AsWeakPtr())); |
| 76 } | 74 } |
| 77 | 75 |
| 78 VideoCaptureGpuJpegDecoder::STATUS VideoCaptureGpuJpegDecoder::GetStatus() | 76 VideoCaptureGpuJpegDecoder::STATUS VideoCaptureGpuJpegDecoder::GetStatus() |
| 79 const { | 77 const { |
| 80 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 78 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 81 base::AutoLock lock(lock_); | 79 base::AutoLock lock(lock_); |
| 82 return decoder_status_; | 80 return decoder_status_; |
| 83 } | 81 } |
| 84 | 82 |
| 85 void VideoCaptureGpuJpegDecoder::DecodeCapturedData( | 83 void VideoCaptureGpuJpegDecoder::DecodeCapturedData( |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 208 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 211 LOG(ERROR) << "Decode error, bitstream_buffer_id=" << bitstream_buffer_id | 209 LOG(ERROR) << "Decode error, bitstream_buffer_id=" << bitstream_buffer_id |
| 212 << ", error=" << error; | 210 << ", error=" << error; |
| 213 send_log_message_cb_.Run("Gpu Jpeg decoder failed"); | 211 send_log_message_cb_.Run("Gpu Jpeg decoder failed"); |
| 214 base::AutoLock lock(lock_); | 212 base::AutoLock lock(lock_); |
| 215 decode_done_closure_.Reset(); | 213 decode_done_closure_.Reset(); |
| 216 decoder_status_ = FAILED; | 214 decoder_status_ = FAILED; |
| 217 } | 215 } |
| 218 | 216 |
| 219 // static | 217 // static |
| 220 void VideoCaptureGpuJpegDecoder::EstablishGpuChannelOnUIThread( | 218 void VideoCaptureGpuJpegDecoder::ConnectToGpuJpegDecodeAcceleratorOnIOThread( |
| 221 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | 219 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, |
| 222 base::WeakPtr<VideoCaptureGpuJpegDecoder> weak_this) { | 220 base::WeakPtr<VideoCaptureGpuJpegDecoder> weak_this) { |
| 223 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 221 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 224 DCHECK(BrowserGpuChannelHostFactory::instance()); | |
| 225 | 222 |
| 226 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel( | 223 media::mojom::GpuJpegDecodeAcceleratorPtr remote_decoder; |
| 227 base::Bind(&VideoCaptureGpuJpegDecoder::GpuChannelEstablishedOnUIThread, | 224 BindInterfaceInGpuProcess(mojo::MakeRequest(&remote_decoder)); |
| 228 task_runner, weak_this)); | |
| 229 } | |
| 230 | |
| 231 // static | |
| 232 void VideoCaptureGpuJpegDecoder::GpuChannelEstablishedOnUIThread( | |
| 233 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | |
| 234 base::WeakPtr<VideoCaptureGpuJpegDecoder> weak_this, | |
| 235 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) { | |
| 236 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 237 | 225 |
| 238 task_runner->PostTask( | 226 task_runner->PostTask( |
| 239 FROM_HERE, base::Bind(&VideoCaptureGpuJpegDecoder::FinishInitialization, | 227 FROM_HERE, |
| 240 weak_this, std::move(gpu_channel_host))); | 228 base::Bind(&VideoCaptureGpuJpegDecoder::FinishInitialization, weak_this, |
| 229 base::Passed(remote_decoder.PassInterface()))); |
| 241 } | 230 } |
| 242 | 231 |
| 243 void VideoCaptureGpuJpegDecoder::FinishInitialization( | 232 void VideoCaptureGpuJpegDecoder::FinishInitialization( |
| 244 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) { | 233 media::mojom::GpuJpegDecodeAcceleratorPtrInfo remote_decoder_info) { |
| 245 TRACE_EVENT0("gpu", "VideoCaptureGpuJpegDecoder::FinishInitialization"); | 234 TRACE_EVENT0("gpu", "VideoCaptureGpuJpegDecoder::FinishInitialization"); |
| 246 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | 235 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); |
| 247 base::AutoLock lock(lock_); | 236 base::AutoLock lock(lock_); |
| 248 if (!gpu_channel_host) { | |
| 249 LOG(ERROR) << "Failed to establish GPU channel for JPEG decoder"; | |
| 250 } else if (gpu_channel_host->gpu_info().jpeg_decode_accelerator_supported) { | |
| 251 gpu_channel_host_ = std::move(gpu_channel_host); | |
| 252 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner = | |
| 253 BrowserGpuChannelHostFactory::instance()->GetIOThreadTaskRunner(); | |
| 254 | 237 |
| 255 int32_t route_id = gpu_channel_host_->GenerateRouteID(); | 238 if (GpuDataManager::GetInstance() |
| 256 std::unique_ptr<media::GpuJpegDecodeAcceleratorHost> decoder( | 239 ->GetGPUInfo() |
| 257 new media::GpuJpegDecodeAcceleratorHost(gpu_channel_host_.get(), | 240 .jpeg_decode_accelerator_supported) { |
| 258 route_id, io_task_runner)); | 241 auto decoder = base::MakeUnique<media::GpuJpegDecodeAcceleratorHost>( |
| 242 BrowserGpuChannelHostFactory::instance()->GetIOThreadTaskRunner(), |
| 243 std::move(remote_decoder_info)); |
| 259 if (decoder->Initialize(this)) { | 244 if (decoder->Initialize(this)) { |
| 260 gpu_channel_host_->AddRouteWithTaskRunner( | |
| 261 route_id, decoder->GetReceiver(), io_task_runner); | |
| 262 decoder_ = std::move(decoder); | 245 decoder_ = std::move(decoder); |
| 263 } else { | 246 } else { |
| 264 DLOG(ERROR) << "Failed to initialize JPEG decoder"; | 247 DLOG(ERROR) << "Failed to initialize JPEG decoder"; |
| 265 } | 248 } |
| 266 } | 249 } |
| 250 |
| 267 decoder_status_ = decoder_ ? INIT_PASSED : FAILED; | 251 decoder_status_ = decoder_ ? INIT_PASSED : FAILED; |
| 268 RecordInitDecodeUMA_Locked(); | 252 RecordInitDecodeUMA_Locked(); |
| 269 } | 253 } |
| 270 | 254 |
| 271 bool VideoCaptureGpuJpegDecoder::IsDecoding_Locked() const { | 255 bool VideoCaptureGpuJpegDecoder::IsDecoding_Locked() const { |
| 272 lock_.AssertAcquired(); | 256 lock_.AssertAcquired(); |
| 273 return !decode_done_closure_.is_null(); | 257 return !decode_done_closure_.is_null(); |
| 274 } | 258 } |
| 275 | 259 |
| 276 void VideoCaptureGpuJpegDecoder::RecordInitDecodeUMA_Locked() { | 260 void VideoCaptureGpuJpegDecoder::RecordInitDecodeUMA_Locked() { |
| 277 UMA_HISTOGRAM_BOOLEAN("Media.VideoCaptureGpuJpegDecoder.InitDecodeSuccess", | 261 UMA_HISTOGRAM_BOOLEAN("Media.VideoCaptureGpuJpegDecoder.InitDecodeSuccess", |
| 278 decoder_status_ == INIT_PASSED); | 262 decoder_status_ == INIT_PASSED); |
| 279 } | 263 } |
| 280 | 264 |
| 281 } // namespace content | 265 } // namespace content |
| OLD | NEW |