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