| 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/numerics/safe_math.h" | 11 #include "base/numerics/safe_math.h" |
| 12 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" | 14 #include "content/common/gpu/client/gpu_memory_buffer_impl.h" |
| 15 #include "content/common/gpu/gpu_channel.h" | 15 #include "content/common/gpu/gpu_channel.h" |
| 16 #include "content/common/gpu/gpu_channel_manager.h" | |
| 17 #include "content/common/gpu/media/gpu_video_accelerator_util.h" | 16 #include "content/common/gpu/media/gpu_video_accelerator_util.h" |
| 18 #include "content/common/gpu/media/media_messages.h" | 17 #include "content/common/gpu/media/media_messages.h" |
| 19 #include "content/public/common/content_switches.h" | 18 #include "content/public/common/content_switches.h" |
| 20 #include "ipc/ipc_message_macros.h" | 19 #include "ipc/ipc_message_macros.h" |
| 21 #include "media/base/bind_to_current_loop.h" | 20 #include "media/base/bind_to_current_loop.h" |
| 22 #include "media/base/limits.h" | 21 #include "media/base/limits.h" |
| 23 #include "media/base/video_frame.h" | 22 #include "media/base/video_frame.h" |
| 24 | 23 |
| 25 #if defined(OS_CHROMEOS) | 24 #if defined(OS_CHROMEOS) |
| 26 #if defined(USE_V4L2_CODEC) | 25 #if defined(USE_V4L2_CODEC) |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 95 |
| 97 if (input_visible_size.width() > media::limits::kMaxDimension || | 96 if (input_visible_size.width() > media::limits::kMaxDimension || |
| 98 input_visible_size.height() > media::limits::kMaxDimension || | 97 input_visible_size.height() > media::limits::kMaxDimension || |
| 99 input_visible_size.GetArea() > media::limits::kMaxCanvas) { | 98 input_visible_size.GetArea() > media::limits::kMaxCanvas) { |
| 100 DLOG(ERROR) << "GpuVideoEncodeAccelerator::Initialize(): " | 99 DLOG(ERROR) << "GpuVideoEncodeAccelerator::Initialize(): " |
| 101 "input_visible_size " << input_visible_size.ToString() | 100 "input_visible_size " << input_visible_size.ToString() |
| 102 << " too large"; | 101 << " too large"; |
| 103 return false; | 102 return false; |
| 104 } | 103 } |
| 105 | 104 |
| 106 const gpu::GpuPreferences& gpu_preferences = | 105 std::vector<GpuVideoEncodeAccelerator::CreateVEAFp> |
| 107 stub_->channel()->gpu_channel_manager()->gpu_preferences(); | 106 create_vea_fps = CreateVEAFps(); |
| 108 | |
| 109 std::vector<GpuVideoEncodeAccelerator::CreateVEAFp> create_vea_fps = | |
| 110 CreateVEAFps(gpu_preferences); | |
| 111 // Try all possible encoders and use the first successful encoder. | 107 // Try all possible encoders and use the first successful encoder. |
| 112 for (size_t i = 0; i < create_vea_fps.size(); ++i) { | 108 for (size_t i = 0; i < create_vea_fps.size(); ++i) { |
| 113 encoder_ = (*create_vea_fps[i])(); | 109 encoder_ = (*create_vea_fps[i])(); |
| 114 if (encoder_ && encoder_->Initialize(input_format, | 110 if (encoder_ && encoder_->Initialize(input_format, |
| 115 input_visible_size, | 111 input_visible_size, |
| 116 output_profile, | 112 output_profile, |
| 117 initial_bitrate, | 113 initial_bitrate, |
| 118 this)) { | 114 this)) { |
| 119 input_format_ = input_format; | 115 input_format_ = input_format; |
| 120 input_visible_size_ = input_visible_size; | 116 input_visible_size_ = input_visible_size; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 void GpuVideoEncodeAccelerator::OnWillDestroyStub() { | 165 void GpuVideoEncodeAccelerator::OnWillDestroyStub() { |
| 170 DCHECK(stub_); | 166 DCHECK(stub_); |
| 171 stub_->channel()->RemoveRoute(host_route_id_); | 167 stub_->channel()->RemoveRoute(host_route_id_); |
| 172 stub_->RemoveDestructionObserver(this); | 168 stub_->RemoveDestructionObserver(this); |
| 173 encoder_.reset(); | 169 encoder_.reset(); |
| 174 delete this; | 170 delete this; |
| 175 } | 171 } |
| 176 | 172 |
| 177 // static | 173 // static |
| 178 gpu::VideoEncodeAcceleratorSupportedProfiles | 174 gpu::VideoEncodeAcceleratorSupportedProfiles |
| 179 GpuVideoEncodeAccelerator::GetSupportedProfiles( | 175 GpuVideoEncodeAccelerator::GetSupportedProfiles() { |
| 180 const gpu::GpuPreferences& gpu_preferences) { | |
| 181 media::VideoEncodeAccelerator::SupportedProfiles profiles; | 176 media::VideoEncodeAccelerator::SupportedProfiles profiles; |
| 182 std::vector<GpuVideoEncodeAccelerator::CreateVEAFp> create_vea_fps = | 177 std::vector<GpuVideoEncodeAccelerator::CreateVEAFp> |
| 183 CreateVEAFps(gpu_preferences); | 178 create_vea_fps = CreateVEAFps(); |
| 184 | 179 |
| 185 for (size_t i = 0; i < create_vea_fps.size(); ++i) { | 180 for (size_t i = 0; i < create_vea_fps.size(); ++i) { |
| 186 scoped_ptr<media::VideoEncodeAccelerator> | 181 scoped_ptr<media::VideoEncodeAccelerator> |
| 187 encoder = (*create_vea_fps[i])(); | 182 encoder = (*create_vea_fps[i])(); |
| 188 if (!encoder) | 183 if (!encoder) |
| 189 continue; | 184 continue; |
| 190 media::VideoEncodeAccelerator::SupportedProfiles vea_profiles = | 185 media::VideoEncodeAccelerator::SupportedProfiles vea_profiles = |
| 191 encoder->GetSupportedProfiles(); | 186 encoder->GetSupportedProfiles(); |
| 192 GpuVideoAcceleratorUtil::InsertUniqueEncodeProfiles( | 187 GpuVideoAcceleratorUtil::InsertUniqueEncodeProfiles( |
| 193 vea_profiles, &profiles); | 188 vea_profiles, &profiles); |
| 194 } | 189 } |
| 195 return GpuVideoAcceleratorUtil::ConvertMediaToGpuEncodeProfiles(profiles); | 190 return GpuVideoAcceleratorUtil::ConvertMediaToGpuEncodeProfiles(profiles); |
| 196 } | 191 } |
| 197 | 192 |
| 198 // static | 193 // static |
| 199 std::vector<GpuVideoEncodeAccelerator::CreateVEAFp> | 194 std::vector<GpuVideoEncodeAccelerator::CreateVEAFp> |
| 200 GpuVideoEncodeAccelerator::CreateVEAFps( | 195 GpuVideoEncodeAccelerator::CreateVEAFps() { |
| 201 const gpu::GpuPreferences& gpu_preferences) { | |
| 202 std::vector<GpuVideoEncodeAccelerator::CreateVEAFp> create_vea_fps; | 196 std::vector<GpuVideoEncodeAccelerator::CreateVEAFp> create_vea_fps; |
| 203 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) | |
| 204 create_vea_fps.push_back(&GpuVideoEncodeAccelerator::CreateV4L2VEA); | 197 create_vea_fps.push_back(&GpuVideoEncodeAccelerator::CreateV4L2VEA); |
| 205 #endif | 198 create_vea_fps.push_back(&GpuVideoEncodeAccelerator::CreateVaapiVEA); |
| 206 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | 199 create_vea_fps.push_back(&GpuVideoEncodeAccelerator::CreateAndroidVEA); |
| 207 if (!gpu_preferences.disable_vaapi_accelerated_video_encode) | |
| 208 create_vea_fps.push_back(&GpuVideoEncodeAccelerator::CreateVaapiVEA); | |
| 209 #endif | |
| 210 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) | |
| 211 if (!gpu_preferences.disable_web_rtc_hw_encoding) | |
| 212 create_vea_fps.push_back(&GpuVideoEncodeAccelerator::CreateAndroidVEA); | |
| 213 #endif | |
| 214 return create_vea_fps; | 200 return create_vea_fps; |
| 215 } | 201 } |
| 216 | 202 |
| 217 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) | |
| 218 // static | 203 // static |
| 219 scoped_ptr<media::VideoEncodeAccelerator> | 204 scoped_ptr<media::VideoEncodeAccelerator> |
| 220 GpuVideoEncodeAccelerator::CreateV4L2VEA() { | 205 GpuVideoEncodeAccelerator::CreateV4L2VEA() { |
| 221 scoped_ptr<media::VideoEncodeAccelerator> encoder; | 206 scoped_ptr<media::VideoEncodeAccelerator> encoder; |
| 207 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) |
| 222 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); | 208 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); |
| 223 if (device) | 209 if (device) |
| 224 encoder.reset(new V4L2VideoEncodeAccelerator(device)); | 210 encoder.reset(new V4L2VideoEncodeAccelerator(device)); |
| 211 #endif |
| 225 return encoder; | 212 return encoder; |
| 226 } | 213 } |
| 227 #endif | |
| 228 | 214 |
| 229 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | |
| 230 // static | 215 // static |
| 231 scoped_ptr<media::VideoEncodeAccelerator> | 216 scoped_ptr<media::VideoEncodeAccelerator> |
| 232 GpuVideoEncodeAccelerator::CreateVaapiVEA() { | 217 GpuVideoEncodeAccelerator::CreateVaapiVEA() { |
| 233 return make_scoped_ptr<media::VideoEncodeAccelerator>( | 218 scoped_ptr<media::VideoEncodeAccelerator> encoder; |
| 234 new VaapiVideoEncodeAccelerator()); | 219 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
| 220 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 221 if (!cmd_line->HasSwitch(switches::kDisableVaapiAcceleratedVideoEncode)) |
| 222 encoder.reset(new VaapiVideoEncodeAccelerator()); |
| 223 #endif |
| 224 return encoder; |
| 235 } | 225 } |
| 236 #endif | |
| 237 | 226 |
| 238 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) | |
| 239 // static | 227 // static |
| 240 scoped_ptr<media::VideoEncodeAccelerator> | 228 scoped_ptr<media::VideoEncodeAccelerator> |
| 241 GpuVideoEncodeAccelerator::CreateAndroidVEA() { | 229 GpuVideoEncodeAccelerator::CreateAndroidVEA() { |
| 242 return make_scoped_ptr<media::VideoEncodeAccelerator>( | 230 scoped_ptr<media::VideoEncodeAccelerator> encoder; |
| 243 new AndroidVideoEncodeAccelerator()); | 231 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) |
| 232 encoder.reset(new AndroidVideoEncodeAccelerator()); |
| 233 #endif |
| 234 return encoder; |
| 244 } | 235 } |
| 245 #endif | |
| 246 | 236 |
| 247 void GpuVideoEncodeAccelerator::OnEncode( | 237 void GpuVideoEncodeAccelerator::OnEncode( |
| 248 const AcceleratedVideoEncoderMsg_Encode_Params& params) { | 238 const AcceleratedVideoEncoderMsg_Encode_Params& params) { |
| 249 DVLOG(3) << "GpuVideoEncodeAccelerator::OnEncode: frame_id = " | 239 DVLOG(3) << "GpuVideoEncodeAccelerator::OnEncode: frame_id = " |
| 250 << params.frame_id << ", buffer_size=" << params.buffer_size | 240 << params.frame_id << ", buffer_size=" << params.buffer_size |
| 251 << ", force_keyframe=" << params.force_keyframe; | 241 << ", force_keyframe=" << params.force_keyframe; |
| 252 DCHECK_EQ(media::PIXEL_FORMAT_I420, input_format_); | 242 DCHECK_EQ(media::PIXEL_FORMAT_I420, input_format_); |
| 253 | 243 |
| 254 // Wrap into a SharedMemory in the beginning, so that |params.buffer_handle| | 244 // Wrap into a SharedMemory in the beginning, so that |params.buffer_handle| |
| 255 // is cleaned properly in case of an early return. | 245 // is cleaned properly in case of an early return. |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 Send(new AcceleratedVideoEncoderHostMsg_NotifyInputDone(host_route_id_, | 444 Send(new AcceleratedVideoEncoderHostMsg_NotifyInputDone(host_route_id_, |
| 455 frame_id)); | 445 frame_id)); |
| 456 // Just let |buffers| fall out of scope. | 446 // Just let |buffers| fall out of scope. |
| 457 } | 447 } |
| 458 | 448 |
| 459 void GpuVideoEncodeAccelerator::Send(IPC::Message* message) { | 449 void GpuVideoEncodeAccelerator::Send(IPC::Message* message) { |
| 460 stub_->channel()->Send(message); | 450 stub_->channel()->Send(message); |
| 461 } | 451 } |
| 462 | 452 |
| 463 } // namespace content | 453 } // namespace content |
| OLD | NEW |