Chromium Code Reviews| 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 |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..08f5037e069562b2a030383dd77fbafce14ed906 |
| --- /dev/null |
| +++ b/content/common/gpu/client/gpu_video_encode_accelerator_host.cc |
| @@ -0,0 +1,197 @@ |
| +// Copyright (c) 2013 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/gpu_video_encode_accelerator_host.h" |
| + |
| +#include "base/logging.h" |
| +#include "content/common/gpu/client/gpu_channel_host.h" |
| +#include "content/common/gpu/gpu_messages.h" |
| +#include "content/common/gpu/media/gpu_video_encode_accelerator.h" |
|
Ami GONE FROM CHROMIUM
2013/07/31 23:01:12
This seems unkosher. Why is renderer-side code in
sheu
2013/08/02 01:27:49
Yes this is slightly icky. My thought is that sin
|
| + |
| +namespace content { |
| + |
| +GpuVideoEncodeAcceleratorHost::GpuVideoEncodeAcceleratorHost( |
| + media::VideoEncodeAccelerator::Client* client, |
| + const scoped_refptr<GpuChannelHost>& gpu_channel_host, |
| + int32 route_id) |
| + : client_(client), channel_(gpu_channel_host), route_id_(route_id) {} |
| + |
| +GpuVideoEncodeAcceleratorHost::~GpuVideoEncodeAcceleratorHost() { |
| + if (channel_) |
| + channel_->RemoveRoute(route_id_); |
|
Ami GONE FROM CHROMIUM
2013/07/31 23:01:12
Can the AddRoute be done in the ctor for symmetry?
sheu
2013/08/02 01:27:49
Done.
|
| +} |
| + |
| +// static |
| +std::vector<media::VideoEncodeAccelerator::SupportedProfile> |
| +GpuVideoEncodeAcceleratorHost::GetSupportedProfiles() { |
| + return GpuVideoEncodeAccelerator::GetSupportedProfiles(); |
|
Ami GONE FROM CHROMIUM
2013/07/31 23:01:12
see above
|
| +} |
| + |
| +bool GpuVideoEncodeAcceleratorHost::OnMessageReceived( |
| + const IPC::Message& message) { |
| + bool handled = true; |
| + IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAcceleratorHost, message) |
| + IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderHostMsg_NotifyInitializeDone, |
| + OnNotifyInitializeDone) |
| + 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); |
| + return handled; |
| +} |
| + |
| +void GpuVideoEncodeAcceleratorHost::OnChannelError() { |
| + DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::OnChannelError()"; |
| + OnNotifyError(kPlatformFailureError); |
| + if (channel_) { |
| + channel_->RemoveRoute(route_id_); |
| + channel_ = NULL; |
| + } |
| +} |
| + |
| +void GpuVideoEncodeAcceleratorHost::Initialize( |
| + media::VideoFrame::Format input_format, |
| + const gfx::Size& input_resolution, |
| + media::VideoCodecProfile output_profile, |
| + int32 initial_bitrate) { |
| + if (!channel_) |
| + return; |
| + if (!Send(new AcceleratedVideoEncoderMsg_Initialize(route_id_, |
| + input_format, |
| + input_resolution, |
| + output_profile, |
| + initial_bitrate))) { |
| + DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::Initialize(): Send() failed"; |
| + } |
| +} |
| + |
| +void GpuVideoEncodeAcceleratorHost::Encode(const media::BitstreamBuffer& buffer, |
| + bool force_keyframe) { |
| + if (!channel_) |
| + return; |
| + base::SharedMemoryHandle handle = |
| + channel_->ShareToGpuProcess(buffer.handle()); |
| + if (!base::SharedMemory::IsHandleValid(handle)) { |
| + DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::Encode(): failed to " |
| + "duplicate buffer handle for GPU process: buffer.id()=" |
| + << buffer.id(); |
| + return; |
|
Ami GONE FROM CHROMIUM
2013/07/31 23:01:12
NotifyError?
sheu
2013/08/02 01:27:49
Done.
|
| + } |
| + if (!Send(new AcceleratedVideoEncoderMsg_Encode( |
| + route_id_, buffer.id(), handle, buffer.size(), force_keyframe))) { |
| + DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::Encode(): Send() failed: " |
| + << "buffer.id()=" << buffer.id(); |
| + } |
| +} |
| + |
| +void GpuVideoEncodeAcceleratorHost::UseOutputBitstreamBuffer( |
| + const media::BitstreamBuffer& buffer) { |
| + if (!channel_) |
| + return; |
| + base::SharedMemoryHandle handle = |
| + channel_->ShareToGpuProcess(buffer.handle()); |
| + if (!base::SharedMemory::IsHandleValid(handle)) { |
| + DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::UseOutputBitstreamBuffer(): " |
| + "failed to duplicate buffer handle for GPU process: " |
| + "buffer.id()=" << buffer.id(); |
|
Ami GONE FROM CHROMIUM
2013/07/31 23:01:12
NotifyError
sheu
2013/08/02 01:27:49
Done.
|
| + return; |
| + } |
| + if (!Send(new AcceleratedVideoEncoderMsg_UseOutputBitstreamBuffer( |
| + route_id_, buffer.id(), handle, buffer.size()))) { |
| + DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::UseOutputBitstreamBuffer(): " |
| + "Send() failed: buffer.id()=" << buffer.id(); |
| + } |
| +} |
| + |
| +void GpuVideoEncodeAcceleratorHost::RequestEncodingParameterChange( |
| + int32 bitrate) { |
| + if (!channel_) |
| + return; |
| + if (!Send(new AcceleratedVideoEncoderMsg_RequestEncodingParameterChange( |
| + route_id_, bitrate))) { |
| + DLOG(ERROR) |
| + << "GpuVideoEncodeAcceleratorHost::RequestEncodingParameterChange(): " |
| + "Send() failed"; |
| + } |
| +} |
| + |
| +void GpuVideoEncodeAcceleratorHost::Destroy() { |
| + if (channel_) |
|
Ami GONE FROM CHROMIUM
2013/07/31 23:01:12
braces on multiline if bodies
sheu
2013/08/02 01:27:49
Done.
|
| + if (!Send(new GpuChannelMsg_DestroyVideoEncoder(route_id_))) |
| + DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::Destroy(): Send() failed"; |
| + |
| + delete this; |
| +} |
| + |
| +void GpuVideoEncodeAcceleratorHost::OnNotifyInitializeDone() { |
| + DVLOG(2) << "GpuVideoEncodeAcceleratorHost::OnNotifyInitializeDone()"; |
| + if (client_) |
| + client_->NotifyInitializeDone(); |
| +} |
| + |
| +void GpuVideoEncodeAcceleratorHost::OnRequireBitstreamBuffers( |
| + int input_count, |
| + const gfx::Size& input_dimensions, |
| + uint32 output_size) { |
| + DVLOG(2) << "GpuVideoEncodeAcceleratorHost::OnRequireBitstreamBuffers(): " |
| + "input_count=" << input_count |
| + << ", input_dimensions=" << input_dimensions.width() |
| + << "x" << input_dimensions.height() |
| + << ", output_size=" << output_size; |
| + if (client_) { |
| + client_->RequireBitstreamBuffers( |
| + input_count, input_dimensions, output_size); |
| + } |
| +} |
| + |
| +void GpuVideoEncodeAcceleratorHost::OnNotifyInputDone( |
| + int32 bitstream_buffer_id) { |
| + DVLOG(3) << "GpuVideoEncodeAcceleratorHost::OnNotifyInputDone(): " |
| + "bitstream_buffer_id=" << bitstream_buffer_id; |
| + if (client_) |
| + client_->NotifyInputDone(bitstream_buffer_id); |
| +} |
| + |
| +void GpuVideoEncodeAcceleratorHost::OnBitstreamBufferReady( |
| + int32 bitstream_buffer_id, |
| + uint32 payload_size, |
| + bool key_frame) { |
| + DVLOG(3) << "GpuVideoEncodeAcceleratorHost::OnBitstreamBufferReady(): " |
| + "bitstream_buffer_id=" << bitstream_buffer_id |
| + << ", payload_size=" << payload_size |
| + << ", key_frame=" << key_frame; |
| + if (client_) |
| + client_->BitstreamBufferReady(bitstream_buffer_id, payload_size, key_frame); |
| +} |
| + |
| +void GpuVideoEncodeAcceleratorHost::OnNotifyError(Error error) { |
| + DVLOG(2) << "GpuVideoEncodeAcceleratorHost::OnNotifyError(): error=" << error; |
| + if (client_) { |
| + client_->NotifyError(error); |
| + client_ = NULL; |
| + } |
| +} |
| + |
| +bool GpuVideoEncodeAcceleratorHost::Send(IPC::Message* message) { |
| + if (!channel_) { |
| + DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::Send(): no channel"; |
| + delete message; |
| + return false; |
| + OnNotifyError(kPlatformFailureError); |
| + } else if (!channel_->Send(message)) { |
| + DLOG(ERROR) << "GpuVideoEncodeAcceleratorHost::Send(): sending failed"; |
| + OnNotifyError(kPlatformFailureError); |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| +} // namespace content |