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

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 Owen's comments: split GpuArcVideoServiceHost and named the new code arc::ArcVideoBridge Created 5 years 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..b0b5a4021339dbef086cce672ebb473b9845a9e5
--- /dev/null
+++ b/content/common/gpu/media/gpu_arc_video_service.cc
@@ -0,0 +1,98 @@
+// Copyright 2015 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);
+#if defined(OS_POSIX)
+ base::ScopedFD client_fd = channel_->TakeClientFileDescriptor();
+ DCHECK(client_fd.is_valid());
+ handle.socket = base::FileDescriptor(std::move(client_fd));
+#endif
+ 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|.
+ owner_->RemoveClient(this);
+ }
+
+ // IPC::Listener implementation:
+ bool OnMessageReceived(const IPC::Message& msg) override {
jbauman 2015/12/30 01:29:29 This seems reasonable, but have you considered usi
kcwu 2015/12/30 09:40:33 Yes, I will migrate to mojo later.
+ 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() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ accelerator_stubs_.clear();
Pawel Osciak 2015/12/30 07:39:15 Nit: do we need to call this explicitly? Should ha
kcwu 2015/12/30 09:40:33 Done.
+}
+
+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