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

Unified Diff: content/common/gpu/media/gpu_arc_video_service.cc

Issue 1451353002: Implement GpuArcVideoService for arc video accelerator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed dcheng's comments Created 4 years, 11 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/common/gpu/media/gpu_arc_video_service.cc
diff --git a/content/common/gpu/media/gpu_arc_video_service.cc b/content/common/gpu/media/gpu_arc_video_service.cc
new file mode 100644
index 0000000000000000000000000000000000000000..91d36980ad1e0a2fbdb9beb3a4272a0091d6c9dc
--- /dev/null
+++ b/content/common/gpu/media/gpu_arc_video_service.cc
@@ -0,0 +1,92 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/common/gpu/media/gpu_arc_video_service.h"
+
+#include "base/logging.h"
+#include "content/common/gpu/gpu_messages.h"
+#include "ipc/ipc_listener.h"
+#include "ipc/ipc_message_macros.h"
+#include "ipc/ipc_sync_channel.h"
+
+namespace content {
+
+// TODO(kcwu) implement ArcVideoAccelerator::Client.
+class GpuArcVideoService::AcceleratorStub : public IPC::Listener,
+ public IPC::Sender {
+ public:
+ // |owner| outlives AcceleratorStub.
+ explicit AcceleratorStub(GpuArcVideoService* owner) : owner_(owner) {}
+
+ ~AcceleratorStub() override {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ channel_->Close();
+ }
+
+ IPC::ChannelHandle CreateChannel(
+ base::WaitableEvent* shutdown_event,
+ const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) {
+ IPC::ChannelHandle handle =
+ IPC::Channel::GenerateVerifiedChannelID("arc-video");
+ channel_ = IPC::SyncChannel::Create(handle, IPC::Channel::MODE_SERVER, this,
+ io_task_runner, false, shutdown_event);
+ base::ScopedFD client_fd = channel_->TakeClientFileDescriptor();
+ DCHECK(client_fd.is_valid());
+ handle.socket = base::FileDescriptor(std::move(client_fd));
+ return handle;
+ }
+
+ // IPC::Sender implementation:
+ bool Send(IPC::Message* msg) override {
+ DCHECK(msg);
+ return channel_->Send(msg);
+ }
+
+ // IPC::Listener implementation:
+ void OnChannelError() override {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ // RemoveClient will delete |this|.
mdempsky 2016/01/09 01:07:05 Why not just do "delete this;"? RemoveClient does
kcwu 2016/01/09 03:22:04 We have to keep accelerator_stubs_ because GpuChan
+ owner_->RemoveClient(this);
+ }
+
+ // IPC::Listener implementation:
+ bool OnMessageReceived(const IPC::Message& msg) override {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ // TODO(kcwu) Add handlers here.
+ return false;
+ }
+
+ private:
+ base::ThreadChecker thread_checker_;
+ GpuArcVideoService* const owner_;
+ scoped_ptr<IPC::SyncChannel> channel_;
+};
+
+GpuArcVideoService::GpuArcVideoService(
+ base::WaitableEvent* shutdown_event,
+ const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
+ : shutdown_event_(shutdown_event), io_task_runner_(io_task_runner) {}
+
+GpuArcVideoService::~GpuArcVideoService() {}
+
+void GpuArcVideoService::CreateChannel(const CreateChannelCallback& callback) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ scoped_ptr<AcceleratorStub> stub(new AcceleratorStub(this));
+
+ IPC::ChannelHandle handle =
+ stub->CreateChannel(shutdown_event_, io_task_runner_);
+ accelerator_stubs_[stub.get()] = std::move(stub);
+
+ callback.Run(handle);
+}
+
+void GpuArcVideoService::RemoveClient(AcceleratorStub* stub) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ accelerator_stubs_.erase(stub);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698