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 scoped_refptr<V4L2Device> device = V4L2Device::Create(); | |
Pawel Osciak
2017/05/15 01:28:51
perhaps auto?
Owen Lin
2017/05/16 07:35:04
Done.
| |
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> CreateMFVEA() { | |
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 MEDIA_GPU_EXPORT std::unique_ptr<VideoEncodeAccelerator> | |
100 GpuVideoEncodeAcceleratorFactory::CreateVEA( | |
101 VideoPixelFormat input_format, | |
102 const gfx::Size& input_visible_size, | |
103 VideoCodecProfile output_profile, | |
104 uint32_t initial_bitrate, | |
105 VideoEncodeAccelerator::Client* client, | |
106 const gpu::GpuPreferences& gpu_preferences) { | |
107 for (const auto& create_vea : GetVEAFactoryFunctions(gpu_preferences)) { | |
108 auto vea = create_vea(); | |
109 if (vea && vea->Initialize(input_format, input_visible_size, output_profile, | |
110 initial_bitrate, client)) | |
111 return vea; | |
112 } | |
113 return nullptr; | |
114 } | |
115 | |
116 MEDIA_GPU_EXPORT VideoEncodeAccelerator::SupportedProfiles | |
117 GpuVideoEncodeAcceleratorFactory::GetSupportedProfiles( | |
118 const gpu::GpuPreferences& gpu_preferences) { | |
119 VideoEncodeAccelerator::SupportedProfiles profiles; | |
120 for (const auto& create_vea : GetVEAFactoryFunctions(gpu_preferences)) { | |
121 auto vea = create_vea(); | |
122 if (vea) | |
123 GpuVideoAcceleratorUtil::InsertUniqueEncodeProfiles( | |
124 vea->GetSupportedProfiles(), &profiles); | |
125 } | |
126 return profiles; | |
127 } | |
128 | |
129 } // namespace media | |
OLD | NEW |