Commit 141e77a5 authored by Miguel Casas's avatar Miguel Casas Committed by Commit Bot

VEA mojification: remove VEA use from PepperVideoEncoderHost

This CL removes using GPU accelerated decoding from PepperVEHost
to enable migrating the current IPC mechanism to Mojo (see
crrev.com/c/585512 and the bug).

Pepper UMA shows that there's barely any usage of this API [1].
Video encoding should have the possibility to fall back to
a software implementation, but this is only available for
VP8 and VP9 [2] (this is probably historical: H264/AVC1 software
encoding using //third_party/openh264 was only landed in 2016ish,
after this code was added); Android doesn't even have that
possibility [3] (and there's no openh264 in Android, see
crbug.com/719023). Moreover, Windows and Linux have no hw
encoding at all, Mac only supports h264, Android supports
h264 and VP8 (but might be disabled for certain models for
quality reasons IIRC).

PepperVideoEncoderHost was landed as part of crrev.com/905023005.

[1] https://uma.googleplex.com/timeline_v2?sid=02aca6e1540b804a771ae4194ecc4540
[2] https://cs.chromium.org/chromium/src/content/renderer/pepper/video_encoder_shim.cc?type=cs&sq=package:chromium&l=379
[3] https://cs.chromium.org/chromium/src/content/renderer/pepper/pepper_video_encoder_host.cc?type=cs&q=pepper_video_e&sq=package:chromium&l=304

Bug: 736517
Change-Id: I3fc43f8e8e6178be39a347cc8630527f500bf7fc
Reviewed-on: https://chromium-review.googlesource.com/832768Reviewed-by: default avatarBill Budge <bbudge@chromium.org>
Commit-Queue: Miguel Casas <mcasas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#525211}
parent 9519547c
......@@ -21,12 +21,6 @@
#include "content/renderer/render_thread_impl.h"
#include "gpu/command_buffer/common/gles2_cmd_utils.h"
#include "gpu/ipc/client/command_buffer_proxy_impl.h"
#include "media/base/bind_to_current_loop.h"
#include "media/base/video_frame.h"
#include "media/gpu/gpu_video_accelerator_util.h"
#include "media/gpu/ipc/client/gpu_video_encode_accelerator_host.h"
#include "media/video/gpu_video_accelerator_factories.h"
#include "media/video/video_encode_accelerator.h"
#include "ppapi/c/pp_codecs.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/pp_graphics_3d.h"
......@@ -153,31 +147,16 @@ PP_VideoFrame_Format PP_FromMediaVideoFormat(media::VideoPixelFormat format) {
}
PP_VideoProfileDescription PP_FromVideoEncodeAcceleratorSupportedProfile(
media::VideoEncodeAccelerator::SupportedProfile profile,
PP_Bool hardware_accelerated) {
media::VideoEncodeAccelerator::SupportedProfile profile) {
PP_VideoProfileDescription pp_profile;
pp_profile.profile = PP_FromMediaVideoProfile(profile.profile);
pp_profile.max_resolution = PP_FromGfxSize(profile.max_resolution);
pp_profile.max_framerate_numerator = profile.max_framerate_numerator;
pp_profile.max_framerate_denominator = profile.max_framerate_denominator;
pp_profile.hardware_accelerated = hardware_accelerated;
pp_profile.hardware_accelerated = PP_FALSE;
return pp_profile;
}
bool PP_HardwareAccelerationCompatibleVideo(bool accelerated,
PP_HardwareAcceleration requested) {
switch (requested) {
case PP_HARDWAREACCELERATION_ONLY:
return accelerated;
case PP_HARDWAREACCELERATION_NONE:
return !accelerated;
case PP_HARDWAREACCELERATION_WITHFALLBACK:
return true;
// No default case, to catch unhandled PP_HardwareAcceleration values.
}
return false;
}
} // namespace
PepperVideoEncoderHost::ShmBuffer::ShmBuffer(
......@@ -187,8 +166,7 @@ PepperVideoEncoderHost::ShmBuffer::ShmBuffer(
DCHECK(this->shm);
}
PepperVideoEncoderHost::ShmBuffer::~ShmBuffer() {
}
PepperVideoEncoderHost::ShmBuffer::~ShmBuffer() {}
media::BitstreamBuffer PepperVideoEncoderHost::ShmBuffer::ToBitstreamBuffer() {
return media::BitstreamBuffer(id, shm->handle(), shm->mapped_size());
......@@ -200,12 +178,12 @@ PepperVideoEncoderHost::PepperVideoEncoderHost(RendererPpapiHost* host,
: ResourceHost(host->GetPpapiHost(), instance, resource),
renderer_ppapi_host_(host),
buffer_manager_(this),
encoder_(new VideoEncoderShim(this)),
initialized_(false),
encoder_last_error_(PP_ERROR_FAILED),
frame_count_(0),
media_input_format_(media::PIXEL_FORMAT_UNKNOWN),
weak_ptr_factory_(this) {
}
weak_ptr_factory_(this) {}
PepperVideoEncoderHost::~PepperVideoEncoderHost() {
Close();
......@@ -285,38 +263,18 @@ int32_t PepperVideoEncoderHost::OnHostMsgInitialize(
if (input_size.IsEmpty())
return PP_ERROR_BADARGUMENT;
if (!IsInitializationValid(input_visible_size, output_profile, acceleration))
if (acceleration == PP_HARDWAREACCELERATION_ONLY)
return PP_ERROR_NOTSUPPORTED;
int32_t error = PP_ERROR_NOTSUPPORTED;
initialize_reply_context_ = context->MakeReplyMessageContext();
if (acceleration != PP_HARDWAREACCELERATION_NONE) {
if (InitializeHardware(media_input_format_, input_size, media_profile,
initial_bitrate))
return PP_OK_COMPLETIONPENDING;
if (acceleration == PP_HARDWAREACCELERATION_ONLY)
error = PP_ERROR_FAILED;
if (encoder_->Initialize(media_input_format_, input_size, media_profile,
initial_bitrate, this)) {
return PP_OK_COMPLETIONPENDING;
}
#if defined(OS_ANDROID)
initialize_reply_context_ = ppapi::host::ReplyMessageContext();
Close();
return error;
#else
if (acceleration != PP_HARDWAREACCELERATION_ONLY) {
encoder_.reset(new VideoEncoderShim(this));
if (encoder_->Initialize(media_input_format_, input_size, media_profile,
initial_bitrate, this))
return PP_OK_COMPLETIONPENDING;
error = PP_ERROR_FAILED;
}
initialize_reply_context_ = ppapi::host::ReplyMessageContext();
Close();
return error;
#endif
return PP_ERROR_FAILED;
}
int32_t PepperVideoEncoderHost::OnHostMsgGetVideoFrames(
......@@ -467,100 +425,14 @@ void PepperVideoEncoderHost::NotifyError(
void PepperVideoEncoderHost::GetSupportedProfiles(
std::vector<PP_VideoProfileDescription>* pp_profiles) {
DCHECK(RenderThreadImpl::current());
DCHECK(encoder_);
media::VideoEncodeAccelerator::SupportedProfiles profiles;
if (EnsureGpuChannel()) {
profiles = media::GpuVideoAcceleratorUtil::ConvertGpuToMediaEncodeProfiles(
command_buffer_->channel()
->gpu_info()
.video_encode_accelerator_supported_profiles);
for (media::VideoEncodeAccelerator::SupportedProfile profile : profiles) {
if (profile.profile == media::VP9PROFILE_PROFILE1 ||
profile.profile == media::VP9PROFILE_PROFILE2 ||
profile.profile == media::VP9PROFILE_PROFILE3) {
continue;
}
pp_profiles->push_back(
PP_FromVideoEncodeAcceleratorSupportedProfile(profile, PP_TRUE));
}
}
#if !defined(OS_ANDROID)
VideoEncoderShim software_encoder(this);
profiles = software_encoder.GetSupportedProfiles();
for (media::VideoEncodeAccelerator::SupportedProfile profile : profiles) {
const media::VideoEncodeAccelerator::SupportedProfiles media_profiles =
encoder_->GetSupportedProfiles();
for (const auto& media_profile : media_profiles) {
pp_profiles->push_back(
PP_FromVideoEncodeAcceleratorSupportedProfile(profile, PP_FALSE));
}
#endif
}
bool PepperVideoEncoderHost::IsInitializationValid(
const PP_Size& input_size,
PP_VideoProfile output_profile,
PP_HardwareAcceleration acceleration) {
DCHECK(RenderThreadImpl::current());
std::vector<PP_VideoProfileDescription> profiles;
GetSupportedProfiles(&profiles);
for (const PP_VideoProfileDescription& profile : profiles) {
if (output_profile == profile.profile &&
input_size.width <= profile.max_resolution.width &&
input_size.height <= profile.max_resolution.height &&
PP_HardwareAccelerationCompatibleVideo(
profile.hardware_accelerated == PP_TRUE, acceleration))
return true;
PP_FromVideoEncodeAcceleratorSupportedProfile(media_profile));
}
return false;
}
bool PepperVideoEncoderHost::EnsureGpuChannel() {
DCHECK(RenderThreadImpl::current());
if (command_buffer_)
return true;
// There is no guarantee that we have a 3D context to work with. So
// we create a dummy command buffer to communicate with the gpu process.
scoped_refptr<gpu::GpuChannelHost> channel =
RenderThreadImpl::current()->EstablishGpuChannelSync();
if (!channel)
return false;
command_buffer_ = std::make_unique<gpu::CommandBufferProxyImpl>(
std::move(channel),
RenderThreadImpl::current()->GetGpuMemoryBufferManager(),
kGpuStreamIdDefault, base::ThreadTaskRunnerHandle::Get());
auto result = command_buffer_->Initialize(
gpu::kNullSurfaceHandle, nullptr, kGpuStreamPriorityDefault,
gpu::gles2::ContextCreationAttribHelper(), GURL::EmptyGURL());
if (result != gpu::ContextResult::kSuccess) {
Close();
return false;
}
command_buffer_->SetGpuControlClient(this);
return true;
}
bool PepperVideoEncoderHost::InitializeHardware(
media::VideoPixelFormat input_format,
const gfx::Size& input_visible_size,
media::VideoCodecProfile output_profile,
uint32_t initial_bitrate) {
DCHECK(RenderThreadImpl::current());
if (!EnsureGpuChannel())
return false;
encoder_.reset(
new media::GpuVideoEncodeAcceleratorHost(command_buffer_.get()));
return encoder_->Initialize(input_format, input_visible_size, output_profile,
initial_bitrate, this);
}
void PepperVideoEncoderHost::Close() {
......
......@@ -14,8 +14,8 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "content/common/content_export.h"
#include "content/renderer/pepper/video_encoder_shim.h"
#include "gpu/command_buffer/client/gpu_control_client.h"
#include "media/video/video_encode_accelerator.h"
#include "ppapi/c/pp_codecs.h"
#include "ppapi/c/ppb_video_frame.h"
#include "ppapi/host/host_message_context.h"
......@@ -30,11 +30,10 @@ class CommandBufferProxyImpl;
namespace content {
class RendererPpapiHost;
class VideoEncoderShim;
class CONTENT_EXPORT PepperVideoEncoderHost
: public ppapi::host::ResourceHost,
public media::VideoEncodeAccelerator::Client,
public VideoEncoderShim::Client,
public ppapi::MediaStreamBufferManager::Delegate,
public gpu::GpuControlClient {
public:
......@@ -60,7 +59,7 @@ class CONTENT_EXPORT PepperVideoEncoderHost
bool in_use;
};
// media::VideoEncodeAccelerator implementation.
// VideoEncoderShim implementation.
void RequireBitstreamBuffers(unsigned int input_count,
const gfx::Size& input_coded_size,
size_t output_buffer_size) override;
......@@ -135,7 +134,7 @@ class CONTENT_EXPORT PepperVideoEncoderHost
std::unique_ptr<gpu::CommandBufferProxyImpl> command_buffer_;
std::unique_ptr<media::VideoEncodeAccelerator> encoder_;
std::unique_ptr<VideoEncoderShim> encoder_;
// Whether the encoder has been successfully initialized.
bool initialized_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment