| 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..0b0ed08d2e890f7a55776df3456d8767f443f570
|
| --- /dev/null
|
| +++ b/content/common/gpu/media/gpu_arc_video_service.cc
|
| @@ -0,0 +1,228 @@
|
| +// 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/bind.h"
|
| +#include "base/location.h"
|
| +#include "base/logging.h"
|
| +#include "base/single_thread_task_runner.h"
|
| +#include "base/synchronization/waitable_event.h"
|
| +#include "base/thread_task_runner_handle.h"
|
| +#include "content/common/gpu/gpu_channel_manager.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"
|
| +
|
| +// HACK remove this before commit
|
| +namespace media {
|
| +arc::ArcVideoAccelerator::Client::~Client() {}
|
| +}
|
| +
|
| +namespace content {
|
| +
|
| +// AcceleratorStub's all methods are running on arc thread.
|
| +class GpuArcVideoService::AcceleratorStub
|
| + : public IPC::Listener,
|
| + public IPC::Sender,
|
| + public media::arc::ArcVideoAccelerator::Client,
|
| + public base::NonThreadSafe {
|
| + public:
|
| + // |owner| outlives AcceleratorStub.
|
| + AcceleratorStub(GpuArcVideoService* owner)
|
| + : owner_(owner),
|
| +#if 0
|
| + accelerator_(new ArcVideoAcceleratorImp()),
|
| +#endif
|
| + arc_task_runner_(base::ThreadTaskRunnerHandle::Get()) {
|
| + }
|
| +
|
| + ~AcceleratorStub() override {
|
| + DCHECK(CalledOnValidThread());
|
| + accelerator_.reset();
|
| + channel_->Close();
|
| + }
|
| +
|
| + IPC::ChannelHandle CreateChannel(
|
| + base::WaitableEvent* shutdown_event,
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner) {
|
| + IPC::ChannelHandle handle;
|
| + 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(client_fd.Pass());
|
| +#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(CalledOnValidThread());
|
| + // RemoveClientOnArcThread will delete |this|.
|
| + owner_->RemoveClientOnArcThread(this);
|
| + }
|
| +
|
| + // ArcVideoAccelerator::Client implementation:
|
| + void onError(media::arc::ArcVideoAccelerator::Error error) override {
|
| + DCHECK(CalledOnValidThread());
|
| + channel_->Send(new ArcAcceleratorHostMsg_Error(error));
|
| + }
|
| +
|
| + void onBufferDone(media::arc::PortType port,
|
| + uint32_t index,
|
| + const media::arc::BufferMetadata& metadata) override {
|
| + DCHECK(CalledOnValidThread());
|
| + channel_->Send(new ArcAcceleratorHostMsg_BufferDone(port, index, metadata));
|
| + }
|
| +
|
| + void onOutputFormatChanged(const media::arc::VideoFormat& format) override {
|
| + DCHECK(CalledOnValidThread());
|
| + channel_->Send(new ArcAcceleratorHostMsg_OutputFormatChanged(format));
|
| + }
|
| +
|
| + // IPC::Listener implementation:
|
| + bool OnMessageReceived(const IPC::Message& msg) override {
|
| + DCHECK(CalledOnValidThread());
|
| +
|
| + IPC_BEGIN_MESSAGE_MAP(AcceleratorStub, msg)
|
| + IPC_MESSAGE_HANDLER(ArcAcceleratorMsg_Initialize, OnInitialize)
|
| + IPC_MESSAGE_HANDLER(ArcAcceleratorMsg_BindSharedBuffer,
|
| + OnBindSharedBuffer)
|
| + IPC_MESSAGE_HANDLER(ArcAcceleratorMsg_BindGraphicBuffer,
|
| + OnBindGraphicBuffer)
|
| + IPC_MESSAGE_HANDLER(ArcAcceleratorMsg_UseBuffer, OnUseBuffer)
|
| + IPC_MESSAGE_HANDLER(ArcAcceleratorMsg_SetBufferCount, OnSetBufferCount)
|
| + IPC_MESSAGE_HANDLER(ArcAcceleratorMsg_Reset, OnReset)
|
| + IPC_MESSAGE_HANDLER(ArcAcceleratorMsg_SetBufferFormat, OnSetBufferFormat)
|
| + IPC_MESSAGE_UNHANDLED(return false;)
|
| + IPC_END_MESSAGE_MAP()
|
| + return true;
|
| + }
|
| +
|
| + void OnInitialize(media::arc::DeviceType device_type, uint32_t* result) {
|
| + *result = accelerator_->initialize(device_type, this);
|
| + }
|
| +
|
| + void OnBindSharedBuffer(media::arc::PortType port,
|
| + uint32_t index,
|
| + base::FileDescriptor ashmem_fd,
|
| + size_t offset,
|
| + size_t length,
|
| + uint32_t* result) {
|
| + *result = accelerator_->bindSharedBuffer(port, index, ashmem_fd.fd, offset,
|
| + length);
|
| + }
|
| +
|
| + void OnBindGraphicBuffer(media::arc::PortType port,
|
| + uint32_t index,
|
| + base::FileDescriptor dmabuf_fd,
|
| + uint32_t* result) {
|
| + *result = accelerator_->bindGraphicBuffer(port, index, dmabuf_fd.fd);
|
| + }
|
| +
|
| + void OnUseBuffer(media::arc::PortType port,
|
| + uint32_t index,
|
| + const media::arc::BufferMetadata& metadata) {
|
| + accelerator_->useBuffer(port, index, metadata);
|
| + }
|
| +
|
| + void OnSetBufferCount(media::arc::PortType port,
|
| + size_t in_count,
|
| + size_t* out_count,
|
| + uint32_t* result) {
|
| + size_t count = in_count;
|
| + *result = accelerator_->setBufferCount(port, &count);
|
| + *out_count = count;
|
| + }
|
| +
|
| + void OnReset() { accelerator_->reset(); }
|
| +
|
| + void OnSetBufferFormat(media::arc::PortType port,
|
| + media::arc::BufferFormat format,
|
| + uint32_t* result) {
|
| + *result = accelerator_->setBufferFormat(port, format);
|
| + }
|
| +
|
| + private:
|
| + GpuArcVideoService* owner_;
|
| + scoped_ptr<media::arc::ArcVideoAccelerator> accelerator_;
|
| + scoped_ptr<IPC::SyncChannel> channel_;
|
| + const scoped_refptr<base::SingleThreadTaskRunner> arc_task_runner_;
|
| +};
|
| +
|
| +GpuArcVideoService::GpuArcVideoService(
|
| + IPC::Sender* gpu_channel_manager,
|
| + base::WaitableEvent* shutdown_event,
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner)
|
| + : gpu_channel_manager_(gpu_channel_manager),
|
| + shutdown_event_(shutdown_event),
|
| + io_task_runner_(io_task_runner),
|
| + task_runner_(base::ThreadTaskRunnerHandle::Get()),
|
| + arc_video_accelerator_thread_("ArcVideoAcceleratorThread") {}
|
| +
|
| +GpuArcVideoService::~GpuArcVideoService() {
|
| + DCHECK(CalledOnValidThread());
|
| +
|
| + if (!arc_video_accelerator_thread_.IsRunning())
|
| + return;
|
| +
|
| + base::WaitableEvent done(false, false);
|
| + arc_task_runner_->PostTask(
|
| + FROM_HERE, base::Bind(&GpuArcVideoService::RemoveAllClientsOnArcThread,
|
| + base::Unretained(this), base::Unretained(&done)));
|
| + done.Wait();
|
| +
|
| + arc_video_accelerator_thread_.Stop();
|
| +}
|
| +
|
| +void GpuArcVideoService::Initialize() {
|
| + DCHECK(CalledOnValidThread());
|
| +
|
| + arc_video_accelerator_thread_.Start();
|
| + arc_task_runner_ = arc_video_accelerator_thread_.task_runner();
|
| +}
|
| +
|
| +void GpuArcVideoService::CreateChannel() {
|
| + DCHECK(CalledOnValidThread());
|
| + DCHECK(arc_task_runner_);
|
| +
|
| + // It's safe to Unretained |this| because the thread is owned by |this|.
|
| + arc_task_runner_->PostTask(
|
| + FROM_HERE, base::Bind(&GpuArcVideoService::CreateClientOnArcThread,
|
| + base::Unretained(this)));
|
| +}
|
| +
|
| +void GpuArcVideoService::CreateClientOnArcThread() {
|
| + DCHECK(arc_task_runner_->BelongsToCurrentThread());
|
| + scoped_ptr<AcceleratorStub> stub(new AcceleratorStub(this));
|
| + accelerator_stubs_[stub.get()] = stub.Pass();
|
| +
|
| + IPC::ChannelHandle handle =
|
| + stub->CreateChannel(shutdown_event_, io_task_runner_);
|
| + gpu_channel_manager_->Send(
|
| + new GpuHostMsg_ArcVideoAcceleratorChannelCreated(handle));
|
| +}
|
| +
|
| +void GpuArcVideoService::RemoveClientOnArcThread(AcceleratorStub* stub) {
|
| + DCHECK(arc_task_runner_->BelongsToCurrentThread());
|
| + accelerator_stubs_.erase(stub);
|
| +}
|
| +
|
| +void GpuArcVideoService::RemoveAllClientsOnArcThread(
|
| + base::WaitableEvent* done) {
|
| + DCHECK(arc_task_runner_->BelongsToCurrentThread());
|
| + accelerator_stubs_.clear();
|
| + done->Signal();
|
| +}
|
| +
|
| +} // namespace content
|
|
|