Chromium Code Reviews| Index: media/gpu/gpu_video_encode_accelerator_factory.cc |
| diff --git a/media/gpu/gpu_video_encode_accelerator_factory.cc b/media/gpu/gpu_video_encode_accelerator_factory.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d0eb4273e94e06bb7d2bc007e3a1b3df08143daa |
| --- /dev/null |
| +++ b/media/gpu/gpu_video_encode_accelerator_factory.cc |
| @@ -0,0 +1,131 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
|
kcwu
2017/05/05 09:31:17
2017
Owen Lin
2017/05/11 08:09:29
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "media/gpu/gpu_video_encode_accelerator_factory.h" |
| + |
| +#include "base/memory/ptr_util.h" |
| +#include "gpu/command_buffer/service/gpu_preferences.h" |
|
kcwu
2017/05/05 09:31:17
already in gpu_video_encode_accelerator_factory.h
Owen Lin
2017/05/11 08:09:29
Done.
|
| +#include "media/gpu/gpu_video_accelerator_util.h" |
| +#include "media/gpu/media_gpu_export.h" |
|
kcwu
2017/05/05 09:31:17
already in gpu_video_encode_accelerator_factory.h
Owen Lin
2017/05/11 08:09:29
Done.
|
| + |
| +#if defined(OS_CHROMEOS) |
| +#if defined(USE_V4L2_CODEC) |
| +#include "media/gpu/v4l2_video_encode_accelerator.h" |
| +#endif |
| +#if defined(ARCH_CPU_X86_FAMILY) |
| +#include "media/gpu/vaapi_video_encode_accelerator.h" |
| +#endif |
| +#elif defined(OS_ANDROID) && BUILDFLAG(ENABLE_WEBRTC) |
| +#include "media/gpu/android_video_encode_accelerator.h" |
| +#elif defined(OS_MACOSX) |
| +#include "media/gpu/vt_video_encode_accelerator_mac.h" |
| +#elif defined(OS_WIN) |
| +#include "base/feature_list.h" |
| +#include "media/base/media_switches.h" |
| +#include "media/gpu/media_foundation_video_encode_accelerator_win.h" |
| +#endif |
| + |
| +namespace media { |
| + |
| +namespace { |
| +#if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) |
| +std::unique_ptr<VideoEncodeAccelerator> CreateV4L2VEA() { |
| + scoped_refptr<V4L2Device> device = V4L2Device::Create(); |
| + if (device) |
| + return base::WrapUnique<VideoEncodeAccelerator>( |
| + new V4L2VideoEncodeAccelerator(device)); |
| + return nullptr; |
| +} |
| +#endif |
| + |
| +#if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
| +std::unique_ptr<VideoEncodeAccelerator> CreateVaapiVEA() { |
| + return base::WrapUnique<VideoEncodeAccelerator>( |
| + new VaapiVideoEncodeAccelerator()); |
| +} |
| +#endif |
| + |
| +#if defined(OS_ANDROID) && BUILDFLAG(ENABLE_WEBRTC) |
| +std::unique_ptr<VideoEncodeAccelerator> CreateAndroidVEA() { |
| + return base::WrapUnique<VideoEncodeAccelerator>( |
| + new AndroidVideoEncodeAccelerator()); |
| +} |
| +#endif |
| + |
| +#if defined(OS_MACOSX) |
| +std::unique_ptr<VideoEncodeAccelerator> CreateVTVEA() { |
| + return base::WrapUnique<VideoEncodeAccelerator>( |
| + new VTVideoEncodeAccelerator()); |
| +} |
| +#endif |
| + |
| +#if defined(OS_WIN) |
| +std::unique_ptr<VideoEncodeAccelerator> CreateMFVEA() { |
| + return base::WrapUnique<VideoEncodeAccelerator>( |
| + new MediaFoundationVideoEncodeAccelerator()); |
| +} |
| +#endif |
| + |
| +using VEAFactoryFunction = std::unique_ptr<VideoEncodeAccelerator> (*)(); |
| + |
| +static std::vector<VEAFactoryFunction> GetVEAFactoryFunctions( |
|
kcwu
2017/05/05 09:31:17
This is in unnamed namespace, no need to specify "
Owen Lin
2017/05/11 08:09:29
Done.
|
| + const gpu::GpuPreferences& gpu_preferences) { |
| + // Array of Create..VEA() function pointers, potentially usable on current |
| + // platform. This list is ordered by priority, from most to least preferred, |
| + // if applicable. |
| + std::vector<VEAFactoryFunction> vea_factory_functions; |
| +#if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) |
| + vea_factory_functions.push_back(&CreateV4L2VEA); |
| +#endif |
| +#if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
| + if (!gpu_preferences.disable_vaapi_accelerated_video_encode) |
| + vea_factory_functions.push_back(&CreateVaapiVEA); |
| +#endif |
| +#if defined(OS_ANDROID) && BUILDFLAG(ENABLE_WEBRTC) |
| + if (!gpu_preferences.disable_web_rtc_hw_encoding) |
| + vea_factory_functions.push_back(&CreateAndroidVEA); |
| +#endif |
| +#if defined(OS_MACOSX) |
| + vea_factory_functions.push_back(&CreateVTVEA); |
| +#endif |
| +#if defined(OS_WIN) |
| + if (base::FeatureList::IsEnabled(kMediaFoundationH264Encoding)) |
| + vea_factory_functions.push_back(&CreateMediaFoundationVEA); |
| +#endif |
| + return vea_factory_functions; |
| +} |
| + |
| +} // anonymous namespace |
| + |
| +MEDIA_GPU_EXPORT std::unique_ptr<VideoEncodeAccelerator> |
| +GpuVideoEncodeAcceleratorFactory::CreateVEA( |
| + VideoPixelFormat input_format, |
| + const gfx::Size& input_visible_size, |
| + VideoCodecProfile output_profile, |
| + uint32_t initial_bitrate, |
| + VideoEncodeAccelerator::Client* client, |
| + const gpu::GpuPreferences& gpu_preferences) { |
| + for (const auto& create_vea : GetVEAFactoryFunctions(gpu_preferences)) { |
| + auto vea = create_vea(); |
| + if (vea && vea->Initialize(input_format, input_visible_size, output_profile, |
| + initial_bitrate, client)) |
| + return vea; |
| + } |
| + return nullptr; |
| +} |
| + |
| +MEDIA_GPU_EXPORT VideoEncodeAccelerator::SupportedProfiles |
| +GpuVideoEncodeAcceleratorFactory::GetSupportedProfiles( |
| + const gpu::GpuPreferences& gpu_preferences) { |
| + VideoEncodeAccelerator::SupportedProfiles profiles; |
| + for (const auto& create_vea : GetVEAFactoryFunctions(gpu_preferences)) { |
| + auto vea = create_vea(); |
| + if (vea) |
| + GpuVideoAcceleratorUtil::InsertUniqueEncodeProfiles( |
| + vea->GetSupportedProfiles(), &profiles); |
| + } |
| + return profiles; |
| +} |
| + |
| +} // namespace media |