Skip to content

Commit

Permalink
Add VaapiVideoEncodeAccelerator for HW-accelerated video encode.
Browse files Browse the repository at this point in the history
Add an implementation of VideoEncodeAccelerator utilizing VA-API for
hardware encode on Intel-based ChromeOS platforms.

BUG=378962
TEST=video_encode_accelerator_unittest

Review URL: https://codereview.chromium.org/333253002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@279650 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
posciak@chromium.org committed Jun 25, 2014
1 parent 4e5e528 commit 9a6ea10
Show file tree
Hide file tree
Showing 26 changed files with 2,185 additions and 87 deletions.
1 change: 1 addition & 0 deletions chrome/browser/chromeos/login/chrome_restart_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ std::string DeriveCommandLine(const GURL& start_url,
::switches::kDisableWebRtcHWEncoding,
::switches::kEnableWebRtcHWVp8Encoding,
#endif
::switches::kEnableVaapiAcceleratedVideoEncode,
#if defined(USE_OZONE)
::switches::kOzonePlatform,
#endif
Expand Down
3 changes: 3 additions & 0 deletions content/browser/gpu/gpu_process_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,9 @@ bool GpuProcessHost::LaunchGpuProcess(const std::string& channel_id) {
#endif
switches::kEnableLogging,
switches::kEnableShareGroupAsyncTextureUpload,
#if defined(OS_CHROMEOS)
switches::kEnableVaapiAcceleratedVideoEncode,
#endif
switches::kGpuStartupDialog,
switches::kGpuSandboxAllowSysVShm,
switches::kGpuSandboxFailuresFatal,
Expand Down
3 changes: 3 additions & 0 deletions content/browser/renderer_host/render_process_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,9 @@ void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer(
#if defined(OS_WIN)
switches::kDisableDirectWrite,
switches::kEnableHighResolutionTime,
#endif
#if defined(OS_CHROMEOS)
switches::kEnableVaapiAcceleratedVideoEncode,
#endif
};
renderer_cmd->CopySwitchesFrom(browser_cmd, kSwitchNames,
Expand Down
25 changes: 22 additions & 3 deletions content/common/gpu/media/gpu_video_encode_accelerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,27 @@
#include "content/common/gpu/media/gpu_video_encode_accelerator.h"

#include "base/callback.h"
#include "base/command_line.h"
#include "base/logging.h"
#include "base/memory/shared_memory.h"
#include "base/message_loop/message_loop_proxy.h"
#include "build/build_config.h"
#include "content/common/gpu/gpu_channel.h"
#include "content/common/gpu/gpu_messages.h"
#include "content/public/common/content_switches.h"
#include "ipc/ipc_message_macros.h"
#include "media/base/limits.h"
#include "media/base/video_frame.h"

#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11)
#if defined(OS_CHROMEOS) && defined(USE_X11)

#if defined(ARCH_CPU_ARMEL)
#include "content/common/gpu/media/v4l2_video_encode_accelerator.h"
#elif defined(ARCH_CPU_X86_FAMILY)
#include "content/common/gpu/media/vaapi_video_encode_accelerator.h"
#include "ui/gfx/x/x11_types.h"
#endif

#elif defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
#include "content/common/gpu/media/android_video_encode_accelerator.h"
#endif
Expand Down Expand Up @@ -158,8 +167,12 @@ std::vector<media::VideoEncodeAccelerator::SupportedProfile>
GpuVideoEncodeAccelerator::GetSupportedProfiles() {
std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles;

#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11)
#if defined(OS_CHROMEOS) && defined(USE_X11)
#if defined(ARCH_CPU_ARMEL)
profiles = V4L2VideoEncodeAccelerator::GetSupportedProfiles();
#elif defined(ARCH_CPU_X86_FAMILY)
profiles = VaapiVideoEncodeAccelerator::GetSupportedProfiles();
#endif
#elif defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
profiles = AndroidVideoEncodeAccelerator::GetSupportedProfiles();
#endif
Expand All @@ -170,12 +183,18 @@ GpuVideoEncodeAccelerator::GetSupportedProfiles() {

void GpuVideoEncodeAccelerator::CreateEncoder() {
DCHECK(!encoder_);
#if defined(OS_CHROMEOS) && defined(ARCH_CPU_ARMEL) && defined(USE_X11)
#if defined(OS_CHROMEOS) && defined(USE_X11)
#if defined(ARCH_CPU_ARMEL)
scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder);
if (!device.get())
return;

encoder_.reset(new V4L2VideoEncodeAccelerator(device.Pass()));
#elif defined(ARCH_CPU_X86_FAMILY)
const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
if (cmd_line->HasSwitch(switches::kEnableVaapiAcceleratedVideoEncode))
encoder_.reset(new VaapiVideoEncodeAccelerator(gfx::GetXDisplay()));
#endif
#elif defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
encoder_.reset(new AndroidVideoEncodeAccelerator());
#endif
Expand Down
1 change: 1 addition & 0 deletions content/common/gpu/media/h264_dpb.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct H264Picture {
int frame_num_wrap;
int long_term_frame_idx;

media::H264SliceHeader::Type type;
bool idr; // IDR picture?
bool ref; // reference picture?
bool long_term; // long term reference picture?
Expand Down
2 changes: 2 additions & 0 deletions content/common/gpu/media/va.sigs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ const char *vaErrorStr(VAStatus error_status);
VAStatus vaGetConfigAttributes(VADisplay dpy, VAProfile profile, VAEntrypoint entrypoint, VAConfigAttrib *attrib_list, int num_attribs);
VAStatus vaInitialize(VADisplay dpy, int *major_version, int *minor_version);
VAStatus vaMapBuffer(VADisplay dpy, VABufferID buf_id, void **pbuf);
int vaMaxNumEntrypoints (VADisplay dpy);
int vaMaxNumProfiles(VADisplay dpy);
VAStatus vaQueryConfigEntrypoints (VADisplay dpy, VAProfile profile, VAEntrypoint *entrypoint_list, int *num_entrypoints);
VAStatus vaQueryConfigProfiles(VADisplay dpy, VAProfile *profile_list, int *num_profiles);
VAStatus vaRenderPicture(VADisplay dpy, VAContextID context, VABufferID *buffers, int num_buffers);
VAStatus vaSetDisplayAttributes(VADisplay dpy, VADisplayAttribute *attr_list, int num_attributes);
Expand Down
4 changes: 2 additions & 2 deletions content/common/gpu/media/vaapi_h264_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,8 @@ bool VaapiH264Decoder::DecodePicture() {
return false;
}

if (!vaapi_wrapper_->DecodeAndDestroyPendingBuffers(
dec_surface->va_surface()->id())) {
if (!vaapi_wrapper_->ExecuteAndDestroyPendingBuffers(
dec_surface->va_surface()->id())) {
DVLOG(1) << "Failed decoding picture";
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion content/common/gpu/media/vaapi_h264_decoder_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ bool VaapiH264DecoderLoop::Initialize(base::FilePath input_file,
media::VideoCodecProfile profile = media::H264PROFILE_BASELINE;
base::Closure report_error_cb =
base::Bind(&LogOnError, VaapiH264Decoder::VAAPI_ERROR);
wrapper_ = VaapiWrapper::Create(profile, x_display_, report_error_cb);
wrapper_ = VaapiWrapper::Create(
VaapiWrapper::kDecode, profile, x_display_, report_error_cb);
if (!wrapper_.get()) {
LOG(ERROR) << "Can't create vaapi wrapper";
return false;
Expand Down
4 changes: 3 additions & 1 deletion content/common/gpu/media/vaapi_video_decode_accelerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ bool VaapiVideoDecodeAccelerator::Initialize(media::VideoCodecProfile profile,
}

vaapi_wrapper_ = VaapiWrapper::Create(
profile, x_display_,
VaapiWrapper::kDecode,
profile,
x_display_,
base::Bind(&ReportToUMA, content::VaapiH264Decoder::VAAPI_ERROR));

if (!vaapi_wrapper_.get()) {
Expand Down
Loading

0 comments on commit 9a6ea10

Please sign in to comment.