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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.cc
diff --git a/content/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.cc b/content/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.cc
index 0bf2749f96605a737f3ffc62184e08919c5cf6e3..4a8355c16fc9ff7281a40d385c40fe5b2213fd8f 100644
--- a/content/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.cc
+++ b/content/browser/renderer_host/media/video_capture_gpu_jpeg_decoder.cc
@@ -17,6 +17,7 @@
#include "build/build_config.h"
#include "content/browser/gpu/browser_gpu_channel_host_factory.h"
#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/gpu_data_manager.h"
#include "content/public/common/content_switches.h"
#include "media/base/media_switches.h"
#include "media/base/video_frame.h"
@@ -41,10 +42,6 @@ VideoCaptureGpuJpegDecoder::~VideoCaptureGpuJpegDecoder() {
// |decoder_| guarantees no more JpegDecodeAccelerator::Client callbacks
// on IO thread after deletion.
decoder_.reset();
-
- // |gpu_channel_host_| should outlive |decoder_|, so |gpu_channel_host_|
- // must be released after |decoder_| has been destroyed.
- gpu_channel_host_ = nullptr;
}
void VideoCaptureGpuJpegDecoder::Initialize() {
@@ -68,11 +65,20 @@ void VideoCaptureGpuJpegDecoder::Initialize() {
return;
}
- const scoped_refptr<base::SingleThreadTaskRunner> current_task_runner(
- base::ThreadTaskRunnerHandle::Get());
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- base::Bind(&EstablishGpuChannelOnUIThread,
- current_task_runner, AsWeakPtr()));
+ if (GpuDataManager::GetInstance()
+ ->GetGPUInfo()
+ .jpeg_decode_accelerator_supported) {
+ auto decoder = base::MakeUnique<media::GpuJpegDecodeAcceleratorHost>(
+ BrowserGpuChannelHostFactory::instance()->GetIOThreadTaskRunner());
+ if (decoder->Initialize(this)) {
+ decoder_ = std::move(decoder);
+ } else {
+ DLOG(ERROR) << "Failed to initialize JPEG decoder";
+ }
+ }
+
+ decoder_status_ = decoder_ ? INIT_PASSED : FAILED;
+ RecordInitDecodeUMA_Locked();
}
VideoCaptureGpuJpegDecoder::STATUS VideoCaptureGpuJpegDecoder::GetStatus()
@@ -216,58 +222,6 @@ void VideoCaptureGpuJpegDecoder::NotifyError(
decoder_status_ = FAILED;
}
-// static
-void VideoCaptureGpuJpegDecoder::EstablishGpuChannelOnUIThread(
- const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
- base::WeakPtr<VideoCaptureGpuJpegDecoder> weak_this) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- DCHECK(BrowserGpuChannelHostFactory::instance());
-
- BrowserGpuChannelHostFactory::instance()->EstablishGpuChannel(
- base::Bind(&VideoCaptureGpuJpegDecoder::GpuChannelEstablishedOnUIThread,
- task_runner, weak_this));
-}
-
-// static
-void VideoCaptureGpuJpegDecoder::GpuChannelEstablishedOnUIThread(
- const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
- base::WeakPtr<VideoCaptureGpuJpegDecoder> weak_this,
- scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
-
- task_runner->PostTask(
- FROM_HERE, base::Bind(&VideoCaptureGpuJpegDecoder::FinishInitialization,
- weak_this, std::move(gpu_channel_host)));
-}
-
-void VideoCaptureGpuJpegDecoder::FinishInitialization(
- scoped_refptr<gpu::GpuChannelHost> gpu_channel_host) {
- TRACE_EVENT0("gpu", "VideoCaptureGpuJpegDecoder::FinishInitialization");
- DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
- base::AutoLock lock(lock_);
- if (!gpu_channel_host) {
- LOG(ERROR) << "Failed to establish GPU channel for JPEG decoder";
- } else if (gpu_channel_host->gpu_info().jpeg_decode_accelerator_supported) {
- gpu_channel_host_ = std::move(gpu_channel_host);
- scoped_refptr<base::SingleThreadTaskRunner> io_task_runner =
- BrowserGpuChannelHostFactory::instance()->GetIOThreadTaskRunner();
-
- int32_t route_id = gpu_channel_host_->GenerateRouteID();
- std::unique_ptr<media::GpuJpegDecodeAcceleratorHost> decoder(
- new media::GpuJpegDecodeAcceleratorHost(gpu_channel_host_.get(),
- route_id, io_task_runner));
- if (decoder->Initialize(this)) {
- gpu_channel_host_->AddRouteWithTaskRunner(
- route_id, decoder->GetReceiver(), io_task_runner);
- decoder_ = std::move(decoder);
- } else {
- DLOG(ERROR) << "Failed to initialize JPEG decoder";
- }
- }
- decoder_status_ = decoder_ ? INIT_PASSED : FAILED;
- RecordInitDecodeUMA_Locked();
-}
-
bool VideoCaptureGpuJpegDecoder::IsDecoding_Locked() const {
lock_.AssertAcquired();
return !decode_done_closure_.is_null();

Powered by Google App Engine
This is Rietveld 408576698