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