Chromium Code Reviews| Index: content/common/gpu/media/gpu_video_encode_accelerator.cc |
| diff --git a/content/common/gpu/media/gpu_video_encode_accelerator.cc b/content/common/gpu/media/gpu_video_encode_accelerator.cc |
| index 12b473fcce23a5bd61f98c28a9b98d5e6419475e..40c1ff487b720315f9463a05a640db756edb88dc 100644 |
| --- a/content/common/gpu/media/gpu_video_encode_accelerator.cc |
| +++ b/content/common/gpu/media/gpu_video_encode_accelerator.cc |
| @@ -22,6 +22,7 @@ |
| #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/v4l2_video_encode_accelerator.h" |
| #include "content/common/gpu/media/vaapi_video_encode_accelerator.h" |
| #include "ui/gfx/x/x11_types.h" |
| #endif |
| @@ -95,26 +96,30 @@ void GpuVideoEncodeAccelerator::Initialize( |
| return; |
| } |
| - encoder_ = CreateEncoder(); |
| - if (!encoder_) { |
| + encoder_list_ = CreateEncoder(); |
| + if (!encoder_list_.size()) { |
|
Pawel Osciak
2014/12/26 01:11:35
if (encoder_list_.empty())
henryhsu
2014/12/26 08:40:40
Done.
|
| DLOG(ERROR) |
| << "GpuVideoEncodeAccelerator::Initialize(): VEA creation failed"; |
| SendCreateEncoderReply(init_done_msg, false); |
| return; |
| } |
| - if (!encoder_->Initialize(input_format, |
| - input_visible_size, |
| - output_profile, |
| - initial_bitrate, |
| - this)) { |
| - DLOG(ERROR) |
| - << "GpuVideoEncodeAccelerator::Initialize(): VEA initialization failed"; |
| - SendCreateEncoderReply(init_done_msg, false); |
| - return; |
| + for (size_t i = 0; i < encoder_list_.size(); ++i) { |
| + if (encoder_list_[i]->Initialize(input_format, |
| + input_visible_size, |
|
Pawel Osciak
2014/12/26 01:11:36
Indent.
henryhsu
2014/12/26 08:40:40
Done.
|
| + output_profile, |
| + initial_bitrate, |
| + this)) { |
| + encoder_ = encoder_list_[i]; |
|
Pawel Osciak
2014/12/26 01:11:36
Do we need to keep all the encoders, if we only us
henryhsu
2014/12/26 08:40:40
Done.
|
| + input_format_ = input_format; |
| + input_visible_size_ = input_visible_size; |
| + SendCreateEncoderReply(init_done_msg, true); |
| + return; |
| + } |
| } |
| - input_format_ = input_format; |
| - input_visible_size_ = input_visible_size; |
| - SendCreateEncoderReply(init_done_msg, true); |
| + encoder_ = NULL; |
| + DLOG(ERROR) |
| + << "GpuVideoEncodeAccelerator::Initialize(): VEA initialization failed"; |
| + SendCreateEncoderReply(init_done_msg, false); |
| } |
| bool GpuVideoEncodeAccelerator::OnMessageReceived(const IPC::Message& message) { |
| @@ -158,19 +163,27 @@ void GpuVideoEncodeAccelerator::OnWillDestroyStub() { |
| DCHECK(stub_); |
| stub_->channel()->RemoveRoute(host_route_id_); |
| stub_->RemoveDestructionObserver(this); |
| - encoder_.reset(); |
| + encoder_list_.clear(); |
| delete this; |
| } |
| // static |
| std::vector<gpu::VideoEncodeAcceleratorSupportedProfile> |
| GpuVideoEncodeAccelerator::GetSupportedProfiles() { |
| - scoped_ptr<media::VideoEncodeAccelerator> encoder = CreateEncoder(); |
| - if (!encoder) |
| + std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles; |
| + ScopedVector<media::VideoEncodeAccelerator> |
|
Pawel Osciak
2014/12/26 01:11:36
Is the newline needed?
henryhsu
2014/12/26 08:40:40
Done.
|
| + encoder_list = CreateEncoder(); |
| + if (!encoder_list.size()) |
|
Pawel Osciak
2014/12/26 01:11:36
if empty()
henryhsu
2014/12/26 08:40:40
Done.
|
| return std::vector<gpu::VideoEncodeAcceleratorSupportedProfile>(); |
| - return ConvertMediaToGpuProfiles(encoder->GetSupportedProfiles()); |
| + for (size_t i = 0; i < encoder_list.size(); ++i) { |
| + std::vector<media::VideoEncodeAccelerator::SupportedProfile> |
| + vea_profiles = encoder_list[i]->GetSupportedProfiles(); |
| + profiles.insert(profiles.end(), vea_profiles.begin(), vea_profiles.end()); |
|
Pawel Osciak
2014/12/26 01:11:36
This may result in profiles containing duplicates,
henryhsu
2014/12/26 08:40:40
How to decide which profile should be used when Vi
|
| + } |
| + return ConvertMediaToGpuProfiles(profiles); |
| } |
| +// static |
| std::vector<gpu::VideoEncodeAcceleratorSupportedProfile> |
| GpuVideoEncodeAccelerator::ConvertMediaToGpuProfiles(const std::vector< |
| media::VideoEncodeAccelerator::SupportedProfile>& media_profiles) { |
| @@ -188,23 +201,23 @@ GpuVideoEncodeAccelerator::ConvertMediaToGpuProfiles(const std::vector< |
| return profiles; |
| } |
| -scoped_ptr<media::VideoEncodeAccelerator> |
| +// static |
| +ScopedVector<media::VideoEncodeAccelerator> |
| GpuVideoEncodeAccelerator::CreateEncoder() { |
| - scoped_ptr<media::VideoEncodeAccelerator> encoder; |
| + ScopedVector<media::VideoEncodeAccelerator> encoder_list; |
| #if defined(OS_CHROMEOS) && defined(USE_X11) |
| -#if defined(ARCH_CPU_ARMEL) |
| scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); |
| if (device) |
| - encoder.reset(new V4L2VideoEncodeAccelerator(device.Pass())); |
| -#elif defined(ARCH_CPU_X86_FAMILY) |
| + encoder_list.push_back(new V4L2VideoEncodeAccelerator(device.Pass())); |
| +#if defined(ARCH_CPU_X86_FAMILY) |
| const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| if (!cmd_line->HasSwitch(switches::kDisableVaapiAcceleratedVideoEncode)) |
| - encoder.reset(new VaapiVideoEncodeAccelerator(gfx::GetXDisplay())); |
| + encoder_list.push_back(new VaapiVideoEncodeAccelerator(gfx::GetXDisplay())); |
| #endif |
| #elif defined(OS_ANDROID) && defined(ENABLE_WEBRTC) |
| - encoder.reset(new AndroidVideoEncodeAccelerator()); |
| + encoder_list.push_back(new AndroidVideoEncodeAccelerator()); |
| #endif |
| - return encoder.Pass(); |
| + return encoder_list.Pass(); |
| } |
| void GpuVideoEncodeAccelerator::OnEncode(int32 frame_id, |