| Index: content/common/gpu/client/ipc/chrome/chrome_gpu_video_decode_accelerator_host_ipc_transport.cc
|
| diff --git a/content/common/gpu/client/ipc/chrome/chrome_gpu_video_decode_accelerator_host_ipc_transport.cc b/content/common/gpu/client/ipc/chrome/chrome_gpu_video_decode_accelerator_host_ipc_transport.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1db6e22cd9bb88ac46d99a680298459e7dcfb6f9
|
| --- /dev/null
|
| +++ b/content/common/gpu/client/ipc/chrome/chrome_gpu_video_decode_accelerator_host_ipc_transport.cc
|
| @@ -0,0 +1,218 @@
|
| +// 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/client/ipc/chrome/chrome_gpu_video_decode_accelerator_host_ipc_transport.h"
|
| +
|
| +#include "content/common/gpu/client/ipc/chrome/chrome_gpu_channel_host_ipc_transport.h"
|
| +#include "content/common/gpu/gpu_messages.h"
|
| +
|
| +namespace content {
|
| +
|
| +// static
|
| +scoped_ptr<GpuVideoDecodeAcceleratorHostIPCTransport>
|
| +ChromeGpuVideoDecodeAcceleratorHostIPCTransport::Create() {
|
| + return make_scoped_ptr<GpuVideoDecodeAcceleratorHostIPCTransport>(
|
| + new ChromeGpuVideoDecodeAcceleratorHostIPCTransport());
|
| +}
|
| +
|
| +ChromeGpuVideoDecodeAcceleratorHostIPCTransport::
|
| + ~ChromeGpuVideoDecodeAcceleratorHostIPCTransport() {
|
| + if (channel_transport_ && route_id_ != MSG_ROUTING_NONE)
|
| + channel_transport_->RemoveRoute(route_id_);
|
| +}
|
| +
|
| +void ChromeGpuVideoDecodeAcceleratorHostIPCTransport::BindToService(
|
| + ChromeGpuChannelHostIPCTransport* channel_transport) {
|
| + channel_transport_ = channel_transport;
|
| + if (channel_transport_) {
|
| + route_id_ = channel_transport_->GenerateRouteID();
|
| + } else {
|
| + route_id_ = MSG_ROUTING_NONE;
|
| + }
|
| +}
|
| +
|
| +base::WeakPtr<ChromeGpuVideoDecodeAcceleratorHostIPCTransport>
|
| +ChromeGpuVideoDecodeAcceleratorHostIPCTransport::AsWeakPtr() {
|
| + return weak_factory_.GetWeakPtr();
|
| +}
|
| +
|
| +ChromeGpuVideoDecodeAcceleratorHostIPCTransport::
|
| + ChromeGpuVideoDecodeAcceleratorHostIPCTransport()
|
| + : channel_transport_(nullptr),
|
| + route_id_(MSG_ROUTING_NONE),
|
| + client_(nullptr),
|
| + weak_factory_(this) {}
|
| +
|
| +void ChromeGpuVideoDecodeAcceleratorHostIPCTransport::OnChannelError() {
|
| + if (channel_transport_) {
|
| + if (route_id_ != MSG_ROUTING_NONE)
|
| + channel_transport_->RemoveRoute(route_id_);
|
| + channel_transport_ = nullptr;
|
| + }
|
| + DLOG(ERROR) << "OnChannelError()";
|
| + PostNotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE);
|
| +}
|
| +
|
| +bool ChromeGpuVideoDecodeAcceleratorHostIPCTransport::OnMessageReceived(
|
| + const IPC::Message& msg) {
|
| + if (!client_)
|
| + return false;
|
| + bool handled = true;
|
| + IPC_BEGIN_MESSAGE_MAP(ChromeGpuVideoDecodeAcceleratorHostIPCTransport, msg)
|
| + IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderHostMsg_CdmAttached,
|
| + OnCdmAttached)
|
| + IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed,
|
| + OnBitstreamBufferProcessed)
|
| + IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers,
|
| + OnProvidePictureBuffer)
|
| + IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderHostMsg_PictureReady,
|
| + OnPictureReady)
|
| + IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderHostMsg_FlushDone, OnFlushDone)
|
| + IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderHostMsg_ResetDone, OnResetDone)
|
| + IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderHostMsg_ErrorNotification,
|
| + OnNotifyError)
|
| + IPC_MESSAGE_HANDLER(AcceleratedVideoDecoderHostMsg_DismissPictureBuffer,
|
| + OnDismissPictureBuffer)
|
| + IPC_MESSAGE_UNHANDLED(handled = false)
|
| + IPC_END_MESSAGE_MAP()
|
| + DCHECK(handled);
|
| + // See OnNotifyError for why |this| mustn't be used after OnNotifyError might
|
| + // have been called above.
|
| + return handled;
|
| +}
|
| +
|
| +bool ChromeGpuVideoDecodeAcceleratorHostIPCTransport::Send(
|
| + IPC::Message* message) {
|
| + DCHECK(channel_transport_);
|
| + if (channel_transport_) {
|
| + if (channel_transport_->Send(message)) {
|
| + return true;
|
| + } else {
|
| + uint32_t message_type = message->type();
|
| + DLOG(ERROR) << "Send(" << message_type << ") failed";
|
| + PostNotifyError(media::VideoDecodeAccelerator::PLATFORM_FAILURE);
|
| + return false;
|
| + }
|
| + }
|
| + // Callee takes ownership of message, regardless of whether Send is
|
| + // successful. See IPC::Sender.
|
| + delete message;
|
| + return false;
|
| +}
|
| +
|
| +void ChromeGpuVideoDecodeAcceleratorHostIPCTransport::PostNotifyError(
|
| + media::VideoDecodeAccelerator::Error error) {
|
| + DVLOG(2) << "PostNotifyError(): error=" << error;
|
| + base::ThreadTaskRunnerHandle::Get()->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(
|
| + &ChromeGpuVideoDecodeAcceleratorHostIPCTransport::OnNotifyError,
|
| + weak_factory_.GetWeakPtr(), error));
|
| +}
|
| +
|
| +bool ChromeGpuVideoDecodeAcceleratorHostIPCTransport::AssignPictureBuffers(
|
| + const std::vector<int32_t>& buffer_ids,
|
| + const std::vector<uint32_t>& texture_ids) {
|
| + DCHECK_NE(MSG_ROUTING_NONE, route_id_);
|
| + return Send(new AcceleratedVideoDecoderMsg_AssignPictureBuffers(
|
| + route_id_, buffer_ids, texture_ids));
|
| +}
|
| +
|
| +bool ChromeGpuVideoDecodeAcceleratorHostIPCTransport::Decode(
|
| + const VideoDecodeParams& params) {
|
| + return Send(new AcceleratedVideoDecoderMsg_Decode(route_id_, params));
|
| +}
|
| +
|
| +bool ChromeGpuVideoDecodeAcceleratorHostIPCTransport::Destroy() {
|
| + if (!channel_transport_)
|
| + return false;
|
| + DCHECK_NE(MSG_ROUTING_NONE, route_id_);
|
| + bool sent = Send(new AcceleratedVideoDecoderMsg_Destroy(route_id_));
|
| + channel_transport_->RemoveRoute(route_id_);
|
| + return sent;
|
| +}
|
| +
|
| +bool ChromeGpuVideoDecodeAcceleratorHostIPCTransport::Flush() {
|
| + DCHECK_NE(MSG_ROUTING_NONE, route_id_);
|
| + return Send(new AcceleratedVideoDecoderMsg_Flush(route_id_));
|
| +}
|
| +
|
| +bool ChromeGpuVideoDecodeAcceleratorHostIPCTransport::Reset() {
|
| + DCHECK_NE(MSG_ROUTING_NONE, route_id_);
|
| + return Send(new AcceleratedVideoDecoderMsg_Reset(route_id_));
|
| +}
|
| +
|
| +bool ChromeGpuVideoDecodeAcceleratorHostIPCTransport::ReusePictureBuffer(
|
| + int32_t picture_buffer_id) {
|
| + DCHECK_NE(MSG_ROUTING_NONE, route_id_);
|
| + return Send(new AcceleratedVideoDecoderMsg_ReusePictureBuffer(
|
| + route_id_, picture_buffer_id));
|
| +}
|
| +
|
| +bool ChromeGpuVideoDecodeAcceleratorHostIPCTransport::SetCdm(int cdm_id) {
|
| + DCHECK_NE(MSG_ROUTING_NONE, route_id_);
|
| + return Send(new AcceleratedVideoDecoderMsg_SetCdm(route_id_, cdm_id));
|
| +}
|
| +
|
| +void ChromeGpuVideoDecodeAcceleratorHostIPCTransport::SetClient(
|
| + GpuVideoDecodeAcceleratorHostIPCTransport::Client* client) {
|
| + client_ = client;
|
| +}
|
| +
|
| +void ChromeGpuVideoDecodeAcceleratorHostIPCTransport::OnCdmAttached(
|
| + bool success) {
|
| + if (client_)
|
| + client_->OnCdmAttached(success);
|
| +}
|
| +
|
| +void ChromeGpuVideoDecodeAcceleratorHostIPCTransport::
|
| + OnBitstreamBufferProcessed(int32_t bitstream_buffer_id) {
|
| + if (client_)
|
| + client_->OnBitstreamBufferProcessed(bitstream_buffer_id);
|
| +}
|
| +
|
| +void ChromeGpuVideoDecodeAcceleratorHostIPCTransport::OnProvidePictureBuffer(
|
| + uint32_t num_requested_buffers,
|
| + const gfx::Size& dimensions,
|
| + uint32_t texture_target) {
|
| + if (client_) {
|
| + client_->OnProvidePictureBuffer(num_requested_buffers, dimensions,
|
| + texture_target);
|
| + }
|
| +}
|
| +
|
| +void ChromeGpuVideoDecodeAcceleratorHostIPCTransport::OnDismissPictureBuffer(
|
| + int32_t picture_buffer_id) {
|
| + if (client_)
|
| + client_->OnDismissPictureBuffer(picture_buffer_id);
|
| +}
|
| +
|
| +void ChromeGpuVideoDecodeAcceleratorHostIPCTransport::OnPictureReady(
|
| + int32_t picture_buffer_id,
|
| + int32_t bitstream_buffer_id,
|
| + const gfx::Rect& visible_rect,
|
| + bool allow_overlay) {
|
| + if (client_) {
|
| + client_->OnPictureReady(picture_buffer_id, bitstream_buffer_id,
|
| + visible_rect, allow_overlay);
|
| + }
|
| +}
|
| +
|
| +void ChromeGpuVideoDecodeAcceleratorHostIPCTransport::OnFlushDone() {
|
| + if (client_)
|
| + client_->OnFlushDone();
|
| +}
|
| +
|
| +void ChromeGpuVideoDecodeAcceleratorHostIPCTransport::OnResetDone() {
|
| + if (client_)
|
| + client_->OnResetDone();
|
| +}
|
| +
|
| +void ChromeGpuVideoDecodeAcceleratorHostIPCTransport::OnNotifyError(
|
| + uint32_t error) {
|
| + if (client_)
|
| + client_->OnNotifyError(error);
|
| +}
|
| +
|
| +} // namespace content
|
|
|