| 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 "base/numerics/safe_math.h" |
| 13 #include "base/sys_info.h" |
| 12 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 13 #include "content/common/gpu/gpu_channel.h" | 15 #include "content/common/gpu/gpu_channel.h" |
| 14 #include "content/common/gpu/gpu_messages.h" | 16 #include "content/common/gpu/gpu_messages.h" |
| 15 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
| 16 #include "ipc/ipc_message_macros.h" | 18 #include "ipc/ipc_message_macros.h" |
| 17 #include "media/base/limits.h" | 19 #include "media/base/limits.h" |
| 18 #include "media/base/video_frame.h" | 20 #include "media/base/video_frame.h" |
| 19 | 21 |
| 20 #if defined(OS_CHROMEOS) | 22 #if defined(OS_CHROMEOS) |
| 21 #if defined(USE_V4L2_CODEC) | 23 #if defined(USE_V4L2_CODEC) |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 GpuVideoEncodeAccelerator::CreateAndroidVEA() { | 238 GpuVideoEncodeAccelerator::CreateAndroidVEA() { |
| 237 scoped_ptr<media::VideoEncodeAccelerator> encoder; | 239 scoped_ptr<media::VideoEncodeAccelerator> encoder; |
| 238 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) | 240 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) |
| 239 encoder.reset(new AndroidVideoEncodeAccelerator()); | 241 encoder.reset(new AndroidVideoEncodeAccelerator()); |
| 240 #endif | 242 #endif |
| 241 return encoder.Pass(); | 243 return encoder.Pass(); |
| 242 } | 244 } |
| 243 | 245 |
| 244 void GpuVideoEncodeAccelerator::OnEncode(int32 frame_id, | 246 void GpuVideoEncodeAccelerator::OnEncode(int32 frame_id, |
| 245 base::SharedMemoryHandle buffer_handle, | 247 base::SharedMemoryHandle buffer_handle, |
| 248 uint32 buffer_offset, |
| 246 uint32 buffer_size, | 249 uint32 buffer_size, |
| 247 bool force_keyframe) { | 250 bool force_keyframe) { |
| 248 DVLOG(3) << "GpuVideoEncodeAccelerator::OnEncode(): frame_id=" << frame_id | 251 DVLOG(3) << "GpuVideoEncodeAccelerator::OnEncode(): frame_id=" << frame_id |
| 249 << ", buffer_size=" << buffer_size | 252 << ", buffer_size=" << buffer_size |
| 250 << ", force_keyframe=" << force_keyframe; | 253 << ", force_keyframe=" << force_keyframe; |
| 251 if (!encoder_) | 254 if (!encoder_) |
| 252 return; | 255 return; |
| 253 if (frame_id < 0) { | 256 if (frame_id < 0) { |
| 254 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode(): invalid frame_id=" | 257 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode(): invalid frame_id=" |
| 255 << frame_id; | 258 << frame_id; |
| 256 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); | 259 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); |
| 257 return; | 260 return; |
| 258 } | 261 } |
| 259 | 262 |
| 263 uint32 aligned_offset = |
| 264 buffer_offset % base::SysInfo::VMAllocationGranularity(); |
| 265 base::CheckedNumeric<off_t> map_offset = buffer_offset; |
| 266 map_offset -= aligned_offset; |
| 267 base::CheckedNumeric<size_t> map_size = buffer_size; |
| 268 map_size += aligned_offset; |
| 269 |
| 270 if (!map_offset.IsValid() || !map_size.IsValid()) { |
| 271 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode():" |
| 272 << " invalid (buffer_offset,buffer_size)"; |
| 273 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); |
| 274 return; |
| 275 } |
| 276 |
| 260 scoped_ptr<base::SharedMemory> shm( | 277 scoped_ptr<base::SharedMemory> shm( |
| 261 new base::SharedMemory(buffer_handle, true)); | 278 new base::SharedMemory(buffer_handle, true)); |
| 262 if (!shm->Map(buffer_size)) { | 279 if (!shm->MapAt(map_offset.ValueOrDie(), map_size.ValueOrDie())) { |
| 263 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode(): " | 280 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode(): " |
| 264 "could not map frame_id=" << frame_id; | 281 "could not map frame_id=" << frame_id; |
| 265 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); | 282 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); |
| 266 return; | 283 return; |
| 267 } | 284 } |
| 268 | 285 |
| 269 uint8* shm_memory = reinterpret_cast<uint8*>(shm->memory()); | 286 uint8* shm_memory = reinterpret_cast<uint8*>(shm->memory()) + aligned_offset; |
| 270 scoped_refptr<media::VideoFrame> frame = | 287 scoped_refptr<media::VideoFrame> frame = |
| 271 media::VideoFrame::WrapExternalPackedMemory( | 288 media::VideoFrame::WrapExternalPackedMemory( |
| 272 input_format_, | 289 input_format_, |
| 273 input_coded_size_, | 290 input_coded_size_, |
| 274 gfx::Rect(input_visible_size_), | 291 gfx::Rect(input_visible_size_), |
| 275 input_visible_size_, | 292 input_visible_size_, |
| 276 shm_memory, | 293 shm_memory, |
| 277 buffer_size, | 294 buffer_size, |
| 278 buffer_handle, | 295 buffer_handle, |
| 296 buffer_offset, |
| 279 base::TimeDelta(), | 297 base::TimeDelta(), |
| 280 // It's turtles all the way down... | 298 // It's turtles all the way down... |
| 281 base::Bind(base::IgnoreResult(&base::MessageLoopProxy::PostTask), | 299 base::Bind(base::IgnoreResult(&base::MessageLoopProxy::PostTask), |
| 282 base::MessageLoopProxy::current(), | 300 base::MessageLoopProxy::current(), |
| 283 FROM_HERE, | 301 FROM_HERE, |
| 284 base::Bind(&GpuVideoEncodeAccelerator::EncodeFrameFinished, | 302 base::Bind(&GpuVideoEncodeAccelerator::EncodeFrameFinished, |
| 285 weak_this_factory_.GetWeakPtr(), | 303 weak_this_factory_.GetWeakPtr(), |
| 286 frame_id, | 304 frame_id, |
| 287 base::Passed(&shm)))); | 305 base::Passed(&shm)))); |
| 288 | 306 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 stub_->channel()->Send(message); | 367 stub_->channel()->Send(message); |
| 350 } | 368 } |
| 351 | 369 |
| 352 void GpuVideoEncodeAccelerator::SendCreateEncoderReply(IPC::Message* message, | 370 void GpuVideoEncodeAccelerator::SendCreateEncoderReply(IPC::Message* message, |
| 353 bool succeeded) { | 371 bool succeeded) { |
| 354 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(message, succeeded); | 372 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(message, succeeded); |
| 355 Send(message); | 373 Send(message); |
| 356 } | 374 } |
| 357 | 375 |
| 358 } // namespace content | 376 } // namespace content |
| OLD | NEW |