OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "media/gpu/gpu_video_encode_accelerator_factory.h" |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 #include "media/gpu/gpu_video_accelerator_util.h" |
| 9 |
| 10 #if defined(OS_CHROMEOS) |
| 11 #if defined(USE_V4L2_CODEC) |
| 12 #include "media/gpu/v4l2_video_encode_accelerator.h" |
| 13 #endif |
| 14 #if defined(ARCH_CPU_X86_FAMILY) |
| 15 #include "media/gpu/vaapi_video_encode_accelerator.h" |
| 16 #endif |
| 17 #elif defined(OS_ANDROID) && BUILDFLAG(ENABLE_WEBRTC) |
| 18 #include "media/gpu/android_video_encode_accelerator.h" |
| 19 #elif defined(OS_MACOSX) |
| 20 #include "media/gpu/vt_video_encode_accelerator_mac.h" |
| 21 #elif defined(OS_WIN) |
| 22 #include "base/feature_list.h" |
| 23 #include "media/base/media_switches.h" |
| 24 #include "media/gpu/media_foundation_video_encode_accelerator_win.h" |
| 25 #endif |
| 26 |
| 27 namespace media { |
| 28 |
| 29 namespace { |
| 30 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) |
| 31 std::unique_ptr<VideoEncodeAccelerator> CreateV4L2VEA() { |
| 32 auto device = V4L2Device::Create(); |
| 33 if (device) |
| 34 return base::WrapUnique<VideoEncodeAccelerator>( |
| 35 new V4L2VideoEncodeAccelerator(device)); |
| 36 return nullptr; |
| 37 } |
| 38 #endif |
| 39 |
| 40 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
| 41 std::unique_ptr<VideoEncodeAccelerator> CreateVaapiVEA() { |
| 42 return base::WrapUnique<VideoEncodeAccelerator>( |
| 43 new VaapiVideoEncodeAccelerator()); |
| 44 } |
| 45 #endif |
| 46 |
| 47 #if defined(OS_ANDROID) && BUILDFLAG(ENABLE_WEBRTC) |
| 48 std::unique_ptr<VideoEncodeAccelerator> CreateAndroidVEA() { |
| 49 return base::WrapUnique<VideoEncodeAccelerator>( |
| 50 new AndroidVideoEncodeAccelerator()); |
| 51 } |
| 52 #endif |
| 53 |
| 54 #if defined(OS_MACOSX) |
| 55 std::unique_ptr<VideoEncodeAccelerator> CreateVTVEA() { |
| 56 return base::WrapUnique<VideoEncodeAccelerator>( |
| 57 new VTVideoEncodeAccelerator()); |
| 58 } |
| 59 #endif |
| 60 |
| 61 #if defined(OS_WIN) |
| 62 std::unique_ptr<VideoEncodeAccelerator> CreateMediaFoundationVEA() { |
| 63 return base::WrapUnique<VideoEncodeAccelerator>( |
| 64 new MediaFoundationVideoEncodeAccelerator()); |
| 65 } |
| 66 #endif |
| 67 |
| 68 using VEAFactoryFunction = std::unique_ptr<VideoEncodeAccelerator> (*)(); |
| 69 |
| 70 std::vector<VEAFactoryFunction> GetVEAFactoryFunctions( |
| 71 const gpu::GpuPreferences& gpu_preferences) { |
| 72 // Array of Create..VEA() function pointers, potentially usable on current |
| 73 // platform. This list is ordered by priority, from most to least preferred, |
| 74 // if applicable. |
| 75 std::vector<VEAFactoryFunction> vea_factory_functions; |
| 76 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) |
| 77 vea_factory_functions.push_back(&CreateV4L2VEA); |
| 78 #endif |
| 79 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
| 80 if (!gpu_preferences.disable_vaapi_accelerated_video_encode) |
| 81 vea_factory_functions.push_back(&CreateVaapiVEA); |
| 82 #endif |
| 83 #if defined(OS_ANDROID) && BUILDFLAG(ENABLE_WEBRTC) |
| 84 if (!gpu_preferences.disable_web_rtc_hw_encoding) |
| 85 vea_factory_functions.push_back(&CreateAndroidVEA); |
| 86 #endif |
| 87 #if defined(OS_MACOSX) |
| 88 vea_factory_functions.push_back(&CreateVTVEA); |
| 89 #endif |
| 90 #if defined(OS_WIN) |
| 91 if (base::FeatureList::IsEnabled(kMediaFoundationH264Encoding)) |
| 92 vea_factory_functions.push_back(&CreateMediaFoundationVEA); |
| 93 #endif |
| 94 return vea_factory_functions; |
| 95 } |
| 96 |
| 97 } // anonymous namespace |
| 98 |
| 99 // static |
| 100 MEDIA_GPU_EXPORT std::unique_ptr<VideoEncodeAccelerator> |
| 101 GpuVideoEncodeAcceleratorFactory::CreateVEA( |
| 102 VideoPixelFormat input_format, |
| 103 const gfx::Size& input_visible_size, |
| 104 VideoCodecProfile output_profile, |
| 105 uint32_t initial_bitrate, |
| 106 VideoEncodeAccelerator::Client* client, |
| 107 const gpu::GpuPreferences& gpu_preferences) { |
| 108 for (const auto& create_vea : GetVEAFactoryFunctions(gpu_preferences)) { |
| 109 auto vea = create_vea(); |
| 110 if (!vea) |
| 111 continue; |
| 112 if (!vea->Initialize(input_format, input_visible_size, output_profile, |
| 113 initial_bitrate, client)) { |
| 114 DLOG(ERROR) << "VEA initialize failed"; |
| 115 continue; |
| 116 } |
| 117 return vea; |
| 118 } |
| 119 return nullptr; |
| 120 } |
| 121 |
| 122 // static |
| 123 MEDIA_GPU_EXPORT VideoEncodeAccelerator::SupportedProfiles |
| 124 GpuVideoEncodeAcceleratorFactory::GetSupportedProfiles( |
| 125 const gpu::GpuPreferences& gpu_preferences) { |
| 126 VideoEncodeAccelerator::SupportedProfiles profiles; |
| 127 for (const auto& create_vea : GetVEAFactoryFunctions(gpu_preferences)) { |
| 128 auto vea = create_vea(); |
| 129 if (vea) |
| 130 GpuVideoAcceleratorUtil::InsertUniqueEncodeProfiles( |
| 131 vea->GetSupportedProfiles(), &profiles); |
| 132 } |
| 133 return profiles; |
| 134 } |
| 135 |
| 136 } // namespace media |
OLD | NEW |