OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/common/gpu/media/gpu_video_encode_accelerator.h" | 5 #include "content/common/gpu/media/gpu_video_encode_accelerator.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/message_loop/message_loop_proxy.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "content/common/gpu/gpu_channel.h" | 13 #include "content/common/gpu/gpu_channel.h" |
14 #include "content/common/gpu/gpu_messages.h" | 14 #include "content/common/gpu/gpu_messages.h" |
15 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
16 #include "ipc/ipc_message_macros.h" | 16 #include "ipc/ipc_message_macros.h" |
17 #include "media/base/limits.h" | 17 #include "media/base/limits.h" |
18 #include "media/base/video_frame.h" | 18 #include "media/base/video_frame.h" |
19 | 19 |
20 #if defined(OS_CHROMEOS) && defined(USE_X11) | 20 #if defined(OS_CHROMEOS) && defined(USE_X11) |
21 | 21 |
22 #if defined(ARCH_CPU_ARMEL) | 22 #if defined(ARCH_CPU_ARMEL) |
23 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" | 23 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" |
24 #elif defined(ARCH_CPU_X86_FAMILY) | 24 #elif defined(ARCH_CPU_X86_FAMILY) |
25 #include "content/common/gpu/media/v4l2_video_encode_accelerator.h" | |
25 #include "content/common/gpu/media/vaapi_video_encode_accelerator.h" | 26 #include "content/common/gpu/media/vaapi_video_encode_accelerator.h" |
26 #include "ui/gfx/x/x11_types.h" | 27 #include "ui/gfx/x/x11_types.h" |
27 #endif | 28 #endif |
28 | 29 |
29 #elif defined(OS_ANDROID) && defined(ENABLE_WEBRTC) | 30 #elif defined(OS_ANDROID) && defined(ENABLE_WEBRTC) |
30 #include "content/common/gpu/media/android_video_encode_accelerator.h" | 31 #include "content/common/gpu/media/android_video_encode_accelerator.h" |
31 #endif | 32 #endif |
32 | 33 |
33 namespace content { | 34 namespace content { |
34 | 35 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
88 if (input_visible_size.width() > media::limits::kMaxDimension || | 89 if (input_visible_size.width() > media::limits::kMaxDimension || |
89 input_visible_size.height() > media::limits::kMaxDimension || | 90 input_visible_size.height() > media::limits::kMaxDimension || |
90 input_visible_size.GetArea() > media::limits::kMaxCanvas) { | 91 input_visible_size.GetArea() > media::limits::kMaxCanvas) { |
91 DLOG(ERROR) << "GpuVideoEncodeAccelerator::Initialize(): " | 92 DLOG(ERROR) << "GpuVideoEncodeAccelerator::Initialize(): " |
92 "input_visible_size " << input_visible_size.ToString() | 93 "input_visible_size " << input_visible_size.ToString() |
93 << " too large"; | 94 << " too large"; |
94 SendCreateEncoderReply(init_done_msg, false); | 95 SendCreateEncoderReply(init_done_msg, false); |
95 return; | 96 return; |
96 } | 97 } |
97 | 98 |
98 encoder_ = CreateEncoder(); | 99 std::vector<GpuVideoEncodeAccelerator::CreateVEACb> |
99 if (!encoder_) { | 100 create_vea_cbs = CreateVEACbs(); |
100 DLOG(ERROR) | 101 // Try all possible encoders and use the first successful encoder. |
101 << "GpuVideoEncodeAccelerator::Initialize(): VEA creation failed"; | 102 for (size_t i = 0; i < create_vea_cbs.size(); ++i) { |
102 SendCreateEncoderReply(init_done_msg, false); | 103 encoder_ = create_vea_cbs[i].Run(); |
103 return; | 104 if (encoder_ && encoder_->Initialize(input_format, |
105 input_visible_size, | |
106 output_profile, | |
107 initial_bitrate, | |
108 this)) { | |
109 input_format_ = input_format; | |
110 input_visible_size_ = input_visible_size; | |
111 SendCreateEncoderReply(init_done_msg, true); | |
112 return; | |
113 } | |
104 } | 114 } |
105 if (!encoder_->Initialize(input_format, | 115 encoder_.reset(); |
106 input_visible_size, | 116 DLOG(ERROR) |
107 output_profile, | 117 << "GpuVideoEncodeAccelerator::Initialize(): VEA initialization failed"; |
108 initial_bitrate, | 118 SendCreateEncoderReply(init_done_msg, false); |
109 this)) { | |
110 DLOG(ERROR) | |
111 << "GpuVideoEncodeAccelerator::Initialize(): VEA initialization failed"; | |
112 SendCreateEncoderReply(init_done_msg, false); | |
113 return; | |
114 } | |
115 input_format_ = input_format; | |
116 input_visible_size_ = input_visible_size; | |
117 SendCreateEncoderReply(init_done_msg, true); | |
118 } | 119 } |
119 | 120 |
120 bool GpuVideoEncodeAccelerator::OnMessageReceived(const IPC::Message& message) { | 121 bool GpuVideoEncodeAccelerator::OnMessageReceived(const IPC::Message& message) { |
121 bool handled = true; | 122 bool handled = true; |
122 IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAccelerator, message) | 123 IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAccelerator, message) |
123 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_Encode, OnEncode) | 124 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_Encode, OnEncode) |
124 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_UseOutputBitstreamBuffer, | 125 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_UseOutputBitstreamBuffer, |
125 OnUseOutputBitstreamBuffer) | 126 OnUseOutputBitstreamBuffer) |
126 IPC_MESSAGE_HANDLER( | 127 IPC_MESSAGE_HANDLER( |
127 AcceleratedVideoEncoderMsg_RequestEncodingParametersChange, | 128 AcceleratedVideoEncoderMsg_RequestEncodingParametersChange, |
(...skipping 30 matching lines...) Expand all Loading... | |
158 DCHECK(stub_); | 159 DCHECK(stub_); |
159 stub_->channel()->RemoveRoute(host_route_id_); | 160 stub_->channel()->RemoveRoute(host_route_id_); |
160 stub_->RemoveDestructionObserver(this); | 161 stub_->RemoveDestructionObserver(this); |
161 encoder_.reset(); | 162 encoder_.reset(); |
162 delete this; | 163 delete this; |
163 } | 164 } |
164 | 165 |
165 // static | 166 // static |
166 std::vector<gpu::VideoEncodeAcceleratorSupportedProfile> | 167 std::vector<gpu::VideoEncodeAcceleratorSupportedProfile> |
167 GpuVideoEncodeAccelerator::GetSupportedProfiles() { | 168 GpuVideoEncodeAccelerator::GetSupportedProfiles() { |
168 scoped_ptr<media::VideoEncodeAccelerator> encoder = CreateEncoder(); | 169 std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles; |
169 if (!encoder) | 170 std::vector<GpuVideoEncodeAccelerator::CreateVEACb> |
170 return std::vector<gpu::VideoEncodeAcceleratorSupportedProfile>(); | 171 create_vea_cbs = CreateVEACbs(); |
171 return ConvertMediaToGpuProfiles(encoder->GetSupportedProfiles()); | 172 |
173 for (size_t i = 0; i < create_vea_cbs.size(); ++i) { | |
174 scoped_ptr<media::VideoEncodeAccelerator> encoder = create_vea_cbs[i].Run(); | |
175 if (!encoder) | |
176 continue; | |
177 std::vector<media::VideoEncodeAccelerator::SupportedProfile> | |
178 vea_profiles = encoder->GetSupportedProfiles(); | |
179 profiles.insert(profiles.end(), vea_profiles.begin(), vea_profiles.end()); | |
180 } | |
181 return ConvertMediaToGpuProfiles(profiles); | |
172 } | 182 } |
173 | 183 |
184 // static | |
174 std::vector<gpu::VideoEncodeAcceleratorSupportedProfile> | 185 std::vector<gpu::VideoEncodeAcceleratorSupportedProfile> |
175 GpuVideoEncodeAccelerator::ConvertMediaToGpuProfiles(const std::vector< | 186 GpuVideoEncodeAccelerator::ConvertMediaToGpuProfiles(const std::vector< |
176 media::VideoEncodeAccelerator::SupportedProfile>& media_profiles) { | 187 media::VideoEncodeAccelerator::SupportedProfile>& media_profiles) { |
177 std::vector<gpu::VideoEncodeAcceleratorSupportedProfile> profiles; | 188 std::vector<gpu::VideoEncodeAcceleratorSupportedProfile> profiles; |
178 for (size_t i = 0; i < media_profiles.size(); i++) { | 189 for (size_t i = 0; i < media_profiles.size(); i++) { |
179 gpu::VideoEncodeAcceleratorSupportedProfile profile; | 190 gpu::VideoEncodeAcceleratorSupportedProfile profile; |
180 profile.profile = | 191 profile.profile = |
181 static_cast<gpu::VideoCodecProfile>(media_profiles[i].profile); | 192 static_cast<gpu::VideoCodecProfile>(media_profiles[i].profile); |
182 profile.max_resolution = media_profiles[i].max_resolution; | 193 profile.max_resolution = media_profiles[i].max_resolution; |
183 profile.max_framerate_numerator = media_profiles[i].max_framerate_numerator; | 194 profile.max_framerate_numerator = media_profiles[i].max_framerate_numerator; |
184 profile.max_framerate_denominator = | 195 profile.max_framerate_denominator = |
185 media_profiles[i].max_framerate_denominator; | 196 media_profiles[i].max_framerate_denominator; |
186 profiles.push_back(profile); | 197 profiles.push_back(profile); |
187 } | 198 } |
188 return profiles; | 199 return profiles; |
189 } | 200 } |
190 | 201 |
202 // static | |
203 std::vector<GpuVideoEncodeAccelerator::CreateVEACb> | |
204 GpuVideoEncodeAccelerator::CreateVEACbs() { | |
205 std::vector<GpuVideoEncodeAccelerator::CreateVEACb> create_vea_cbs; | |
206 create_vea_cbs.push_back(base::Bind(&CreateV4L2VEA)); | |
Pawel Osciak
2015/01/02 01:49:15
Nit: please prepend with GpuVideoEncodeAccelerator
| |
207 create_vea_cbs.push_back(base::Bind(&CreateVaapiVEA)); | |
208 create_vea_cbs.push_back(base::Bind(&CreateAndroidVEA)); | |
209 return create_vea_cbs; | |
210 } | |
211 | |
212 // static | |
191 scoped_ptr<media::VideoEncodeAccelerator> | 213 scoped_ptr<media::VideoEncodeAccelerator> |
192 GpuVideoEncodeAccelerator::CreateEncoder() { | 214 GpuVideoEncodeAccelerator::CreateV4L2VEA() { |
193 scoped_ptr<media::VideoEncodeAccelerator> encoder; | 215 scoped_ptr<media::VideoEncodeAccelerator> encoder; |
194 #if defined(OS_CHROMEOS) && defined(USE_X11) | 216 #if defined(OS_CHROMEOS) && defined(USE_X11) |
195 #if defined(ARCH_CPU_ARMEL) | |
196 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); | 217 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); |
197 if (device) | 218 if (device) |
198 encoder.reset(new V4L2VideoEncodeAccelerator(device.Pass())); | 219 encoder.reset(new V4L2VideoEncodeAccelerator(device.Pass())); |
199 #elif defined(ARCH_CPU_X86_FAMILY) | 220 #endif |
221 return encoder.Pass(); | |
222 } | |
223 | |
224 // static | |
225 scoped_ptr<media::VideoEncodeAccelerator> | |
226 GpuVideoEncodeAccelerator::CreateVaapiVEA() { | |
227 scoped_ptr<media::VideoEncodeAccelerator> encoder; | |
228 #if defined(OS_CHROMEOS) && defined(USE_X11) && defined(ARCH_CPU_X86_FAMILY) | |
200 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 229 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
201 if (!cmd_line->HasSwitch(switches::kDisableVaapiAcceleratedVideoEncode)) | 230 if (!cmd_line->HasSwitch(switches::kDisableVaapiAcceleratedVideoEncode)) |
202 encoder.reset(new VaapiVideoEncodeAccelerator(gfx::GetXDisplay())); | 231 encoder.reset(new VaapiVideoEncodeAccelerator(gfx::GetXDisplay())); |
203 #endif | 232 #endif |
204 #elif defined(OS_ANDROID) && defined(ENABLE_WEBRTC) | 233 return encoder.Pass(); |
234 } | |
235 | |
236 // static | |
237 scoped_ptr<media::VideoEncodeAccelerator> | |
238 GpuVideoEncodeAccelerator::CreateAndroidVEA() { | |
239 scoped_ptr<media::VideoEncodeAccelerator> encoder; | |
240 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) | |
205 encoder.reset(new AndroidVideoEncodeAccelerator()); | 241 encoder.reset(new AndroidVideoEncodeAccelerator()); |
206 #endif | 242 #endif |
207 return encoder.Pass(); | 243 return encoder.Pass(); |
208 } | 244 } |
209 | 245 |
210 void GpuVideoEncodeAccelerator::OnEncode(int32 frame_id, | 246 void GpuVideoEncodeAccelerator::OnEncode(int32 frame_id, |
211 base::SharedMemoryHandle buffer_handle, | 247 base::SharedMemoryHandle buffer_handle, |
212 uint32 buffer_size, | 248 uint32 buffer_size, |
213 bool force_keyframe) { | 249 bool force_keyframe) { |
214 DVLOG(3) << "GpuVideoEncodeAccelerator::OnEncode(): frame_id=" << frame_id | 250 DVLOG(3) << "GpuVideoEncodeAccelerator::OnEncode(): frame_id=" << frame_id |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 stub_->channel()->Send(message); | 351 stub_->channel()->Send(message); |
316 } | 352 } |
317 | 353 |
318 void GpuVideoEncodeAccelerator::SendCreateEncoderReply(IPC::Message* message, | 354 void GpuVideoEncodeAccelerator::SendCreateEncoderReply(IPC::Message* message, |
319 bool succeeded) { | 355 bool succeeded) { |
320 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(message, succeeded); | 356 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(message, succeeded); |
321 Send(message); | 357 Send(message); |
322 } | 358 } |
323 | 359 |
324 } // namespace content | 360 } // namespace content |
OLD | NEW |