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

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

Issue 2924573002: [NotForReview] Convert accelerated JPEG Decoder IPC to Mojo
Patch Set: Created 3 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_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"
20 #include "content/public/common/content_switches.h" 21 #include "content/public/common/content_switches.h"
21 #include "media/base/media_switches.h" 22 #include "media/base/media_switches.h"
22 #include "media/base/video_frame.h" 23 #include "media/base/video_frame.h"
23 #include "media/gpu/ipc/client/gpu_jpeg_decode_accelerator_host.h" 24 #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 if (GpuDataManager::GetInstance()
72 base::ThreadTaskRunnerHandle::Get()); 69 ->GetGPUInfo()
73 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 70 .jpeg_decode_accelerator_supported) {
74 base::Bind(&EstablishGpuChannelOnUIThread, 71 auto decoder = base::MakeUnique<media::GpuJpegDecodeAcceleratorHost>(
75 current_task_runner, AsWeakPtr())); 72 BrowserGpuChannelHostFactory::instance()->GetIOThreadTaskRunner());
73 if (decoder->Initialize(this)) {
74 decoder_ = std::move(decoder);
75 } else {
76 DLOG(ERROR) << "Failed to initialize JPEG decoder";
77 }
78 }
79
80 decoder_status_ = decoder_ ? INIT_PASSED : FAILED;
81 RecordInitDecodeUMA_Locked();
76 } 82 }
77 83
78 VideoCaptureGpuJpegDecoder::STATUS VideoCaptureGpuJpegDecoder::GetStatus() 84 VideoCaptureGpuJpegDecoder::STATUS VideoCaptureGpuJpegDecoder::GetStatus()
79 const { 85 const {
80 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); 86 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
81 base::AutoLock lock(lock_); 87 base::AutoLock lock(lock_);
82 return decoder_status_; 88 return decoder_status_;
83 } 89 }
84 90
85 void VideoCaptureGpuJpegDecoder::DecodeCapturedData( 91 void VideoCaptureGpuJpegDecoder::DecodeCapturedData(
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 media::JpegDecodeAccelerator::Error error) { 215 media::JpegDecodeAccelerator::Error error) {
210 DCHECK_CURRENTLY_ON(BrowserThread::IO); 216 DCHECK_CURRENTLY_ON(BrowserThread::IO);
211 LOG(ERROR) << "Decode error, bitstream_buffer_id=" << bitstream_buffer_id 217 LOG(ERROR) << "Decode error, bitstream_buffer_id=" << bitstream_buffer_id
212 << ", error=" << error; 218 << ", error=" << error;
213 send_log_message_cb_.Run("Gpu Jpeg decoder failed"); 219 send_log_message_cb_.Run("Gpu Jpeg decoder failed");
214 base::AutoLock lock(lock_); 220 base::AutoLock lock(lock_);
215 decode_done_closure_.Reset(); 221 decode_done_closure_.Reset();
216 decoder_status_ = FAILED; 222 decoder_status_ = FAILED;
217 } 223 }
218 224
219 // static
220 void VideoCaptureGpuJpegDecoder::EstablishGpuChannelOnUIThread(
221 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
222 base::WeakPtr<VideoCaptureGpuJpegDecoder> weak_this) {
223 DCHECK_CURRENTLY_ON(BrowserThread::UI);
224 DCHECK(BrowserGpuChannelHostFactory::instance());
225
226 BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel(
227 base::Bind(&VideoCaptureGpuJpegDecoder::GpuChannelEstablishedOnUIThread,
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
238 task_runner->PostTask(
239 FROM_HERE, base::Bind(&VideoCaptureGpuJpegDecoder::FinishInitialization,
240 weak_this, std::move(gpu_channel_host)));
241 }
242
243 void VideoCaptureGpuJpegDecoder::FinishInitialization(
244 scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) {
245 TRACE_EVENT0("gpu", "VideoCaptureGpuJpegDecoder::FinishInitialization");
246 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
247 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
255 int32_t route_id = gpu_channel_host_->GenerateRouteID();
256 std::unique_ptr<media::GpuJpegDecodeAcceleratorHost> decoder(
257 new media::GpuJpegDecodeAcceleratorHost(gpu_channel_host_.get(),
258 route_id, io_task_runner));
259 if (decoder->Initialize(this)) {
260 gpu_channel_host_->AddRouteWithTaskRunner(
261 route_id, decoder->GetReceiver(), io_task_runner);
262 decoder_ = std::move(decoder);
263 } else {
264 DLOG(ERROR) << "Failed to initialize JPEG decoder";
265 }
266 }
267 decoder_status_ = decoder_ ? INIT_PASSED : FAILED;
268 RecordInitDecodeUMA_Locked();
269 }
270
271 bool VideoCaptureGpuJpegDecoder::IsDecoding_Locked() const { 225 bool VideoCaptureGpuJpegDecoder::IsDecoding_Locked() const {
272 lock_.AssertAcquired(); 226 lock_.AssertAcquired();
273 return !decode_done_closure_.is_null(); 227 return !decode_done_closure_.is_null();
274 } 228 }
275 229
276 void VideoCaptureGpuJpegDecoder::RecordInitDecodeUMA_Locked() { 230 void VideoCaptureGpuJpegDecoder::RecordInitDecodeUMA_Locked() {
277 UMA_HISTOGRAM_BOOLEAN("Media.VideoCaptureGpuJpegDecoder.InitDecodeSuccess", 231 UMA_HISTOGRAM_BOOLEAN("Media.VideoCaptureGpuJpegDecoder.InitDecodeSuccess",
278 decoder_status_ == INIT_PASSED); 232 decoder_status_ == INIT_PASSED);
279 } 233 }
280 234
281 } // namespace content 235 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698