Chromium Code Reviews| Index: content/common/gpu/media/gpu_video_encode_accelerator.cc |
| diff --git a/content/common/gpu/media/gpu_video_encode_accelerator.cc b/content/common/gpu/media/gpu_video_encode_accelerator.cc |
| index df16d97839ac9b14e8a407ce06d25622df1e873b..98d0406b2359e89bd7e12dedcaf8eadbb0afb6d4 100644 |
| --- a/content/common/gpu/media/gpu_video_encode_accelerator.cc |
| +++ b/content/common/gpu/media/gpu_video_encode_accelerator.cc |
| @@ -9,6 +9,8 @@ |
| #include "base/logging.h" |
| #include "base/memory/shared_memory.h" |
| #include "base/message_loop/message_loop_proxy.h" |
| +#include "base/numerics/safe_math.h" |
| +#include "base/sys_info.h" |
| #include "build/build_config.h" |
| #include "content/common/gpu/gpu_channel.h" |
| #include "content/common/gpu/gpu_messages.h" |
| @@ -245,6 +247,7 @@ GpuVideoEncodeAccelerator::CreateAndroidVEA() { |
| void GpuVideoEncodeAccelerator::OnEncode(int32 frame_id, |
| base::SharedMemoryHandle buffer_handle, |
| + uint32 buffer_offset, |
| uint32 buffer_size, |
| bool force_keyframe) { |
| DVLOG(3) << "GpuVideoEncodeAccelerator::OnEncode(): frame_id=" << frame_id |
| @@ -259,16 +262,36 @@ void GpuVideoEncodeAccelerator::OnEncode(int32 frame_id, |
| return; |
| } |
| + base::CheckedNumeric<off_t> map_offset = buffer_offset; |
| + map_offset -= (buffer_offset % base::SysInfo::VMAllocationGranularity()); |
| + if (!map_offset.IsValid()) { |
| + DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode():" |
| + << " invalid buffer_offset=" << buffer_offset; |
| + NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); |
| + return; |
| + } |
| + base::CheckedNumeric<size_t> map_size = buffer_size; |
| + map_size += (static_cast<off_t>(buffer_offset) - |
| + static_cast<off_t>(map_offset.ValueOrDie())); |
|
dcheng
2015/02/06 21:39:47
Let's avoid casting if we don't have to. It makes
llandwerlin-old
2015/02/09 14:48:47
Done.
|
| + if (!map_size.IsValid()) { |
| + DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode():" |
| + << " invalid buffer_offset=" << buffer_offset |
| + << " buffer_size=" << buffer_size; |
| + NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); |
| + return; |
| + } |
| + |
| scoped_ptr<base::SharedMemory> shm( |
| new base::SharedMemory(buffer_handle, true)); |
| - if (!shm->Map(buffer_size)) { |
| + if (!shm->MapAt(map_offset.ValueOrDie(), map_size.ValueOrDie())) { |
| DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode(): " |
| "could not map frame_id=" << frame_id; |
| NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); |
| return; |
| } |
| - uint8* shm_memory = reinterpret_cast<uint8*>(shm->memory()); |
| + uint8* shm_memory = reinterpret_cast<uint8*>(shm->memory()) + |
| + (buffer_offset - map_offset.ValueOrDie()); |
| scoped_refptr<media::VideoFrame> frame = |
| media::VideoFrame::WrapExternalPackedMemory( |
| input_format_, |
| @@ -278,6 +301,7 @@ void GpuVideoEncodeAccelerator::OnEncode(int32 frame_id, |
| shm_memory, |
| buffer_size, |
| buffer_handle, |
| + buffer_offset, |
| base::TimeDelta(), |
| // It's turtles all the way down... |
| base::Bind(base::IgnoreResult(&base::MessageLoopProxy::PostTask), |