| Index: content/common/gpu/client/gpu_video_encode_accelerator_host.cc
|
| diff --git a/content/common/gpu/client/gpu_video_encode_accelerator_host.cc b/content/common/gpu/client/gpu_video_encode_accelerator_host.cc
|
| index 9002490e1dd21d51163285b5d5fa99bee9ee8a91..86e8923b7ff9b975e6f5236b3afd37dc7682fcee 100644
|
| --- a/content/common/gpu/client/gpu_video_encode_accelerator_host.cc
|
| +++ b/content/common/gpu/client/gpu_video_encode_accelerator_host.cc
|
| @@ -6,9 +6,12 @@
|
|
|
| #include "base/location.h"
|
| #include "base/logging.h"
|
| +#include "base/strings/stringprintf.h"
|
| +#include "base/thread_task_runner_handle.h"
|
| #include "content/common/gpu/client/gpu_channel_host.h"
|
| -#include "content/common/gpu/gpu_messages.h"
|
| +#include "content/common/gpu/client/ipc/command_buffer_ipc_transport.h"
|
| #include "content/common/gpu/media/gpu_video_accelerator_util.h"
|
| +#include "content/common/gpu/video_encode_params.h"
|
| #include "media/base/video_frame.h"
|
| #include "media/video/video_encode_accelerator.h"
|
| #include "ui/gfx/gpu_memory_buffer.h"
|
| @@ -17,56 +20,29 @@ namespace content {
|
|
|
| GpuVideoEncodeAcceleratorHost::GpuVideoEncodeAcceleratorHost(
|
| GpuChannelHost* channel,
|
| + scoped_ptr<GpuVideoEncodeAcceleratorHostIPCTransport> transport,
|
| CommandBufferProxyImpl* impl)
|
| : channel_(channel),
|
| - encoder_route_id_(MSG_ROUTING_NONE),
|
| - client_(NULL),
|
| + transport_(std::move(transport)),
|
| + client_(nullptr),
|
| impl_(impl),
|
| next_frame_id_(0),
|
| weak_this_factory_(this) {
|
| DCHECK(channel_);
|
| DCHECK(impl_);
|
| impl_->AddDeletionObserver(this);
|
| + transport_->SetClient(this);
|
| }
|
|
|
| GpuVideoEncodeAcceleratorHost::~GpuVideoEncodeAcceleratorHost() {
|
| DCHECK(CalledOnValidThread());
|
| - if (channel_ && encoder_route_id_ != MSG_ROUTING_NONE)
|
| - channel_->RemoveRoute(encoder_route_id_);
|
| + // TODO(fsamuel): Figure out message routing here.
|
| + // if (channel_ && encoder_route_id_ != MSG_ROUTING_NONE)
|
| + // channel_->RemoveRoute(encoder_route_id_);
|
| if (impl_)
|
| impl_->RemoveDeletionObserver(this);
|
| }
|
|
|
| -bool GpuVideoEncodeAcceleratorHost::OnMessageReceived(
|
| - const IPC::Message& message) {
|
| - bool handled = true;
|
| - IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAcceleratorHost, message)
|
| - IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderHostMsg_RequireBitstreamBuffers,
|
| - OnRequireBitstreamBuffers)
|
| - IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderHostMsg_NotifyInputDone,
|
| - OnNotifyInputDone)
|
| - IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderHostMsg_BitstreamBufferReady,
|
| - OnBitstreamBufferReady)
|
| - IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderHostMsg_NotifyError,
|
| - OnNotifyError)
|
| - 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;
|
| -}
|
| -
|
| -void GpuVideoEncodeAcceleratorHost::OnChannelError() {
|
| - DCHECK(CalledOnValidThread());
|
| - if (channel_) {
|
| - if (encoder_route_id_ != MSG_ROUTING_NONE)
|
| - channel_->RemoveRoute(encoder_route_id_);
|
| - channel_ = NULL;
|
| - }
|
| - PostNotifyError(FROM_HERE, kPlatformFailureError, "OnChannelError()");
|
| -}
|
| -
|
| media::VideoEncodeAccelerator::SupportedProfiles
|
| GpuVideoEncodeAcceleratorHost::GetSupportedProfiles() {
|
| DCHECK(CalledOnValidThread());
|
| @@ -81,7 +57,7 @@ bool GpuVideoEncodeAcceleratorHost::Initialize(
|
| const gfx::Size& input_visible_size,
|
| media::VideoCodecProfile output_profile,
|
| uint32_t initial_bitrate,
|
| - Client* client) {
|
| + media::VideoEncodeAccelerator::Client* client) {
|
| DCHECK(CalledOnValidThread());
|
| client_ = client;
|
| if (!impl_) {
|
| @@ -89,19 +65,14 @@ bool GpuVideoEncodeAcceleratorHost::Initialize(
|
| return false;
|
| }
|
|
|
| - int32_t route_id = channel_->GenerateRouteID();
|
| - channel_->AddRoute(route_id, weak_this_factory_.GetWeakPtr());
|
| -
|
| bool succeeded = false;
|
| - Send(new GpuCommandBufferMsg_CreateVideoEncoder(
|
| - impl_->route_id(), input_format, input_visible_size, output_profile,
|
| - initial_bitrate, route_id, &succeeded));
|
| + impl_->transport()->CreateVideoEncoder(transport_.get(), input_format,
|
| + input_visible_size, output_profile,
|
| + initial_bitrate, &succeeded);
|
| if (!succeeded) {
|
| - DLOG(ERROR) << "Send(GpuCommandBufferMsg_CreateVideoEncoder()) failed";
|
| - channel_->RemoveRoute(route_id);
|
| + DLOG(ERROR) << "CreateVidoEncoder() failed";
|
| return false;
|
| }
|
| - encoder_route_id_ = route_id;
|
| return true;
|
| }
|
|
|
| @@ -148,8 +119,7 @@ void GpuVideoEncodeAcceleratorHost::UseOutputBitstreamBuffer(
|
| buffer.id()));
|
| return;
|
| }
|
| - Send(new AcceleratedVideoEncoderMsg_UseOutputBitstreamBuffer(
|
| - encoder_route_id_, buffer.id(), handle, buffer.size()));
|
| + transport_->UseOutputBitstreamBuffer(buffer.id(), handle, buffer.size());
|
| }
|
|
|
| void GpuVideoEncodeAcceleratorHost::RequestEncodingParametersChange(
|
| @@ -158,25 +128,20 @@ void GpuVideoEncodeAcceleratorHost::RequestEncodingParametersChange(
|
| DCHECK(CalledOnValidThread());
|
| if (!channel_)
|
| return;
|
| -
|
| - Send(new AcceleratedVideoEncoderMsg_RequestEncodingParametersChange(
|
| - encoder_route_id_, bitrate, framerate));
|
| + transport_->RequestEncodingParametersChange(bitrate, framerate);
|
| }
|
|
|
| void GpuVideoEncodeAcceleratorHost::Destroy() {
|
| DCHECK(CalledOnValidThread());
|
| if (channel_)
|
| - Send(new AcceleratedVideoEncoderMsg_Destroy(encoder_route_id_));
|
| - client_ = NULL;
|
| + transport_->Destroy();
|
| + client_ = nullptr;
|
| delete this;
|
| }
|
|
|
| void GpuVideoEncodeAcceleratorHost::OnWillDeleteImpl() {
|
| DCHECK(CalledOnValidThread());
|
| - impl_ = NULL;
|
| -
|
| - // The CommandBufferProxyImpl is going away; error out this VEA.
|
| - OnChannelError();
|
| + impl_ = nullptr;
|
| }
|
|
|
| void GpuVideoEncodeAcceleratorHost::EncodeGpuMemoryBufferFrame(
|
| @@ -184,7 +149,7 @@ void GpuVideoEncodeAcceleratorHost::EncodeGpuMemoryBufferFrame(
|
| bool force_keyframe){
|
| DCHECK_EQ(media::VideoFrame::NumPlanes(media::PIXEL_FORMAT_I420),
|
| frame->gpu_memory_buffer_handles().size());
|
| - AcceleratedVideoEncoderMsg_Encode_Params2 params;
|
| + VideoEncodeParams2 params;
|
| params.frame_id = next_frame_id_;
|
| params.timestamp = frame->timestamp();
|
| bool requires_sync_point = false;
|
| @@ -202,8 +167,7 @@ void GpuVideoEncodeAcceleratorHost::EncodeGpuMemoryBufferFrame(
|
| }
|
| params.size = frame->coded_size();
|
| params.force_keyframe = force_keyframe;
|
| -
|
| - Send(new AcceleratedVideoEncoderMsg_Encode2(encoder_route_id_, params));
|
| + transport_->Encode2(params);
|
| }
|
|
|
| void GpuVideoEncodeAcceleratorHost::EncodeSharedMemoryFrame(
|
| @@ -216,7 +180,7 @@ void GpuVideoEncodeAcceleratorHost::EncodeSharedMemoryFrame(
|
| return;
|
| }
|
|
|
| - AcceleratedVideoEncoderMsg_Encode_Params params;
|
| + VideoEncodeParams params;
|
| params.frame_id = next_frame_id_;
|
| params.timestamp = frame->timestamp();
|
| params.buffer_handle =
|
| @@ -232,8 +196,7 @@ void GpuVideoEncodeAcceleratorHost::EncodeSharedMemoryFrame(
|
| params.buffer_size =
|
| media::VideoFrame::AllocationSize(frame->format(), frame->coded_size());
|
| params.force_keyframe = force_keyframe;
|
| -
|
| - Send(new AcceleratedVideoEncoderMsg_Encode(encoder_route_id_, params));
|
| + transport_->Encode(params);
|
| }
|
|
|
| void GpuVideoEncodeAcceleratorHost::PostNotifyError(
|
| @@ -250,15 +213,6 @@ void GpuVideoEncodeAcceleratorHost::PostNotifyError(
|
| weak_this_factory_.GetWeakPtr(), error));
|
| }
|
|
|
| -void GpuVideoEncodeAcceleratorHost::Send(IPC::Message* message) {
|
| - DCHECK(CalledOnValidThread());
|
| - uint32_t message_type = message->type();
|
| - if (!channel_->Send(message)) {
|
| - PostNotifyError(FROM_HERE, kPlatformFailureError,
|
| - base::StringPrintf("Send(%d) failed", message_type));
|
| - }
|
| -}
|
| -
|
| void GpuVideoEncodeAcceleratorHost::OnRequireBitstreamBuffers(
|
| uint32_t input_count,
|
| const gfx::Size& input_coded_size,
|
| @@ -290,7 +244,8 @@ void GpuVideoEncodeAcceleratorHost::OnNotifyInputDone(int32_t frame_id) {
|
| OnNotifyError(kPlatformFailureError);
|
| return;
|
| }
|
| - frame = NULL; // Not necessary but nice to be explicit; see fun-fact above.
|
| + frame =
|
| + nullptr; // Not necessary but nice to be explicit; see fun-fact above.
|
| }
|
|
|
| void GpuVideoEncodeAcceleratorHost::OnBitstreamBufferReady(
|
| @@ -315,7 +270,7 @@ void GpuVideoEncodeAcceleratorHost::OnNotifyError(Error error) {
|
|
|
| // Client::NotifyError() may Destroy() |this|, so calling it needs to be the
|
| // last thing done on this stack!
|
| - media::VideoEncodeAccelerator::Client* client = NULL;
|
| + media::VideoEncodeAccelerator::Client* client = nullptr;
|
| std::swap(client_, client);
|
| client->NotifyError(error);
|
| }
|
|
|