OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/common/gpu/media/gpu_arc_video_service.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "content/common/gpu/gpu_messages.h" |
| 9 #include "ipc/ipc_listener.h" |
| 10 #include "ipc/ipc_message_macros.h" |
| 11 #include "ipc/ipc_sync_channel.h" |
| 12 |
| 13 namespace content { |
| 14 |
| 15 // TODO(kcwu) implement ArcVideoAccelerator::Client. |
| 16 class GpuArcVideoService::AcceleratorStub : public IPC::Listener, |
| 17 public IPC::Sender { |
| 18 public: |
| 19 // |owner| outlives AcceleratorStub. |
| 20 explicit AcceleratorStub(GpuArcVideoService* owner) : owner_(owner) {} |
| 21 |
| 22 ~AcceleratorStub() override { |
| 23 DCHECK(thread_checker_.CalledOnValidThread()); |
| 24 channel_->Close(); |
| 25 } |
| 26 |
| 27 IPC::ChannelHandle CreateChannel( |
| 28 base::WaitableEvent* shutdown_event, |
| 29 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) { |
| 30 IPC::ChannelHandle handle = |
| 31 IPC::Channel::GenerateVerifiedChannelID("arc-video"); |
| 32 channel_ = IPC::SyncChannel::Create(handle, IPC::Channel::MODE_SERVER, this, |
| 33 io_task_runner, false, shutdown_event); |
| 34 #if defined(OS_POSIX) |
| 35 base::ScopedFD client_fd = channel_->TakeClientFileDescriptor(); |
| 36 DCHECK(client_fd.is_valid()); |
| 37 handle.socket = base::FileDescriptor(std::move(client_fd)); |
| 38 #endif |
| 39 return handle; |
| 40 } |
| 41 |
| 42 // IPC::Sender implementation: |
| 43 bool Send(IPC::Message* msg) override { |
| 44 DCHECK(msg); |
| 45 return channel_->Send(msg); |
| 46 } |
| 47 |
| 48 // IPC::Listener implementation: |
| 49 void OnChannelError() override { |
| 50 DCHECK(thread_checker_.CalledOnValidThread()); |
| 51 // RemoveClient will delete |this|. |
| 52 owner_->RemoveClient(this); |
| 53 } |
| 54 |
| 55 // IPC::Listener implementation: |
| 56 bool OnMessageReceived(const IPC::Message& msg) override { |
| 57 DCHECK(thread_checker_.CalledOnValidThread()); |
| 58 |
| 59 // TODO(kcwu) Add handlers here. |
| 60 return false; |
| 61 } |
| 62 |
| 63 private: |
| 64 base::ThreadChecker thread_checker_; |
| 65 GpuArcVideoService* const owner_; |
| 66 scoped_ptr<IPC::SyncChannel> channel_; |
| 67 }; |
| 68 |
| 69 GpuArcVideoService::GpuArcVideoService( |
| 70 base::WaitableEvent* shutdown_event, |
| 71 const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) |
| 72 : shutdown_event_(shutdown_event), io_task_runner_(io_task_runner) {} |
| 73 |
| 74 GpuArcVideoService::~GpuArcVideoService() { |
| 75 DCHECK(thread_checker_.CalledOnValidThread()); |
| 76 |
| 77 accelerator_stubs_.clear(); |
| 78 } |
| 79 |
| 80 void GpuArcVideoService::CreateChannel(const CreateChannelCallback& callback) { |
| 81 DCHECK(thread_checker_.CalledOnValidThread()); |
| 82 |
| 83 scoped_ptr<AcceleratorStub> stub(new AcceleratorStub(this)); |
| 84 |
| 85 IPC::ChannelHandle handle = |
| 86 stub->CreateChannel(shutdown_event_, io_task_runner_); |
| 87 accelerator_stubs_[stub.get()] = std::move(stub); |
| 88 |
| 89 callback.Run(handle); |
| 90 } |
| 91 |
| 92 void GpuArcVideoService::RemoveClient(AcceleratorStub* stub) { |
| 93 DCHECK(thread_checker_.CalledOnValidThread()); |
| 94 |
| 95 accelerator_stubs_.erase(stub); |
| 96 } |
| 97 |
| 98 } // namespace content |
OLD | NEW |