| 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" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 if (input_visible_size.width() > media::limits::kMaxDimension || | 88 if (input_visible_size.width() > media::limits::kMaxDimension || |
| 89 input_visible_size.height() > media::limits::kMaxDimension || | 89 input_visible_size.height() > media::limits::kMaxDimension || |
| 90 input_visible_size.GetArea() > media::limits::kMaxCanvas) { | 90 input_visible_size.GetArea() > media::limits::kMaxCanvas) { |
| 91 DLOG(ERROR) << "GpuVideoEncodeAccelerator::Initialize(): " | 91 DLOG(ERROR) << "GpuVideoEncodeAccelerator::Initialize(): " |
| 92 "input_visible_size " << input_visible_size.ToString() | 92 "input_visible_size " << input_visible_size.ToString() |
| 93 << " too large"; | 93 << " too large"; |
| 94 SendCreateEncoderReply(init_done_msg, false); | 94 SendCreateEncoderReply(init_done_msg, false); |
| 95 return; | 95 return; |
| 96 } | 96 } |
| 97 | 97 |
| 98 CreateEncoder(); | 98 encoder_ = CreateEncoder(); |
| 99 if (!encoder_) { | 99 if (!encoder_) { |
| 100 DLOG(ERROR) | 100 DLOG(ERROR) |
| 101 << "GpuVideoEncodeAccelerator::Initialize(): VEA creation failed"; | 101 << "GpuVideoEncodeAccelerator::Initialize(): VEA creation failed"; |
| 102 SendCreateEncoderReply(init_done_msg, false); | 102 SendCreateEncoderReply(init_done_msg, false); |
| 103 return; | 103 return; |
| 104 } | 104 } |
| 105 if (!encoder_->Initialize(input_format, | 105 if (!encoder_->Initialize(input_format, |
| 106 input_visible_size, | 106 input_visible_size, |
| 107 output_profile, | 107 output_profile, |
| 108 initial_bitrate, | 108 initial_bitrate, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 DCHECK(stub_); | 158 DCHECK(stub_); |
| 159 stub_->channel()->RemoveRoute(host_route_id_); | 159 stub_->channel()->RemoveRoute(host_route_id_); |
| 160 stub_->RemoveDestructionObserver(this); | 160 stub_->RemoveDestructionObserver(this); |
| 161 encoder_.reset(); | 161 encoder_.reset(); |
| 162 delete this; | 162 delete this; |
| 163 } | 163 } |
| 164 | 164 |
| 165 // static | 165 // static |
| 166 std::vector<media::VideoEncodeAccelerator::SupportedProfile> | 166 std::vector<media::VideoEncodeAccelerator::SupportedProfile> |
| 167 GpuVideoEncodeAccelerator::GetSupportedProfiles() { | 167 GpuVideoEncodeAccelerator::GetSupportedProfiles() { |
| 168 std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles; | 168 scoped_ptr<media::VideoEncodeAccelerator> encoder = CreateEncoder(); |
| 169 | 169 if (!encoder) |
| 170 #if defined(OS_CHROMEOS) && defined(USE_X11) | 170 return std::vector<media::VideoEncodeAccelerator::SupportedProfile>(); |
| 171 #if defined(ARCH_CPU_ARMEL) | 171 return encoder->GetSupportedProfiles(); |
| 172 profiles = V4L2VideoEncodeAccelerator::GetSupportedProfiles(); | |
| 173 #elif defined(ARCH_CPU_X86_FAMILY) | |
| 174 profiles = VaapiVideoEncodeAccelerator::GetSupportedProfiles(); | |
| 175 #endif | |
| 176 #elif defined(OS_ANDROID) && defined(ENABLE_WEBRTC) | |
| 177 profiles = AndroidVideoEncodeAccelerator::GetSupportedProfiles(); | |
| 178 #endif | |
| 179 | |
| 180 // TODO(sheu): return platform-specific profiles. | |
| 181 return profiles; | |
| 182 } | 172 } |
| 183 | 173 |
| 184 void GpuVideoEncodeAccelerator::CreateEncoder() { | 174 scoped_ptr<media::VideoEncodeAccelerator> |
| 185 DCHECK(!encoder_); | 175 GpuVideoEncodeAccelerator::CreateEncoder() { |
| 176 scoped_ptr<media::VideoEncodeAccelerator> encoder; |
| 186 #if defined(OS_CHROMEOS) && defined(USE_X11) | 177 #if defined(OS_CHROMEOS) && defined(USE_X11) |
| 187 #if defined(ARCH_CPU_ARMEL) | 178 #if defined(ARCH_CPU_ARMEL) |
| 188 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); | 179 scoped_ptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); |
| 189 if (!device.get()) | 180 if (device) |
| 190 return; | 181 encoder.reset(new V4L2VideoEncodeAccelerator(device.Pass())); |
| 191 | |
| 192 encoder_.reset(new V4L2VideoEncodeAccelerator(device.Pass())); | |
| 193 #elif defined(ARCH_CPU_X86_FAMILY) | 182 #elif defined(ARCH_CPU_X86_FAMILY) |
| 194 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); | 183 const base::CommandLine* cmd_line = base::CommandLine::ForCurrentProcess(); |
| 195 if (!cmd_line->HasSwitch(switches::kDisableVaapiAcceleratedVideoEncode)) | 184 if (!cmd_line->HasSwitch(switches::kDisableVaapiAcceleratedVideoEncode)) |
| 196 encoder_.reset(new VaapiVideoEncodeAccelerator(gfx::GetXDisplay())); | 185 encoder.reset(new VaapiVideoEncodeAccelerator(gfx::GetXDisplay())); |
| 197 #endif | 186 #endif |
| 198 #elif defined(OS_ANDROID) && defined(ENABLE_WEBRTC) | 187 #elif defined(OS_ANDROID) && defined(ENABLE_WEBRTC) |
| 199 encoder_.reset(new AndroidVideoEncodeAccelerator()); | 188 encoder.reset(new AndroidVideoEncodeAccelerator()); |
| 200 #endif | 189 #endif |
| 190 return encoder.Pass(); |
| 201 } | 191 } |
| 202 | 192 |
| 203 void GpuVideoEncodeAccelerator::OnEncode(int32 frame_id, | 193 void GpuVideoEncodeAccelerator::OnEncode(int32 frame_id, |
| 204 base::SharedMemoryHandle buffer_handle, | 194 base::SharedMemoryHandle buffer_handle, |
| 205 uint32 buffer_size, | 195 uint32 buffer_size, |
| 206 bool force_keyframe) { | 196 bool force_keyframe) { |
| 207 DVLOG(3) << "GpuVideoEncodeAccelerator::OnEncode(): frame_id=" << frame_id | 197 DVLOG(3) << "GpuVideoEncodeAccelerator::OnEncode(): frame_id=" << frame_id |
| 208 << ", buffer_size=" << buffer_size | 198 << ", buffer_size=" << buffer_size |
| 209 << ", force_keyframe=" << force_keyframe; | 199 << ", force_keyframe=" << force_keyframe; |
| 210 if (!encoder_) | 200 if (!encoder_) |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 stub_->channel()->Send(message); | 298 stub_->channel()->Send(message); |
| 309 } | 299 } |
| 310 | 300 |
| 311 void GpuVideoEncodeAccelerator::SendCreateEncoderReply(IPC::Message* message, | 301 void GpuVideoEncodeAccelerator::SendCreateEncoderReply(IPC::Message* message, |
| 312 bool succeeded) { | 302 bool succeeded) { |
| 313 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(message, succeeded); | 303 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(message, succeeded); |
| 314 Send(message); | 304 Send(message); |
| 315 } | 305 } |
| 316 | 306 |
| 317 } // namespace content | 307 } // namespace content |
| OLD | NEW |