Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(635)

Side by Side Diff: content/common/gpu/media/gpu_video_encode_accelerator.cc

Issue 877353002: media: VideoFrame: add offset for shared memory buffers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add gpu-process ipc modification Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/sys_info.h"
12 #include "build/build_config.h" 13 #include "build/build_config.h"
13 #include "content/common/gpu/gpu_channel.h" 14 #include "content/common/gpu/gpu_channel.h"
14 #include "content/common/gpu/gpu_messages.h" 15 #include "content/common/gpu/gpu_messages.h"
15 #include "content/public/common/content_switches.h" 16 #include "content/public/common/content_switches.h"
16 #include "ipc/ipc_message_macros.h" 17 #include "ipc/ipc_message_macros.h"
17 #include "media/base/limits.h" 18 #include "media/base/limits.h"
18 #include "media/base/video_frame.h" 19 #include "media/base/video_frame.h"
19 20
20 #if defined(OS_CHROMEOS) 21 #if defined(OS_CHROMEOS)
21 #if defined(ARCH_CPU_ARMEL) || (defined(USE_OZONE) && defined(USE_V4L2_CODEC)) 22 #if defined(ARCH_CPU_ARMEL) || (defined(USE_OZONE) && defined(USE_V4L2_CODEC))
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 GpuVideoEncodeAccelerator::CreateAndroidVEA() { 239 GpuVideoEncodeAccelerator::CreateAndroidVEA() {
239 scoped_ptr<media::VideoEncodeAccelerator> encoder; 240 scoped_ptr<media::VideoEncodeAccelerator> encoder;
240 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) 241 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
241 encoder.reset(new AndroidVideoEncodeAccelerator()); 242 encoder.reset(new AndroidVideoEncodeAccelerator());
242 #endif 243 #endif
243 return encoder.Pass(); 244 return encoder.Pass();
244 } 245 }
245 246
246 void GpuVideoEncodeAccelerator::OnEncode(int32 frame_id, 247 void GpuVideoEncodeAccelerator::OnEncode(int32 frame_id,
247 base::SharedMemoryHandle buffer_handle, 248 base::SharedMemoryHandle buffer_handle,
249 uint32 buffer_offset,
248 uint32 buffer_size, 250 uint32 buffer_size,
249 bool force_keyframe) { 251 bool force_keyframe) {
250 DVLOG(3) << "GpuVideoEncodeAccelerator::OnEncode(): frame_id=" << frame_id 252 DVLOG(3) << "GpuVideoEncodeAccelerator::OnEncode(): frame_id=" << frame_id
251 << ", buffer_size=" << buffer_size 253 << ", buffer_size=" << buffer_size
252 << ", force_keyframe=" << force_keyframe; 254 << ", force_keyframe=" << force_keyframe;
253 if (!encoder_) 255 if (!encoder_)
254 return; 256 return;
255 if (frame_id < 0) { 257 if (frame_id < 0) {
256 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode(): invalid frame_id=" 258 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode(): invalid frame_id="
257 << frame_id; 259 << frame_id;
258 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); 260 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError);
259 return; 261 return;
260 } 262 }
261 263
264 off_t map_offset = buffer_offset -
265 (buffer_offset % base::SysInfo::VMAllocationGranularity());
266 size_t map_size = buffer_size + (buffer_offset - map_offset);
dcheng 2015/02/02 20:56:23 This calculation can trivially overflow. buffer_si
llandwerlin-old 2015/02/03 16:35:06 Done.
267
262 scoped_ptr<base::SharedMemory> shm( 268 scoped_ptr<base::SharedMemory> shm(
263 new base::SharedMemory(buffer_handle, true)); 269 new base::SharedMemory(buffer_handle, true));
264 if (!shm->Map(buffer_size)) { 270 if (!shm->MapAt(map_offset, map_size)) {
265 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode(): " 271 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode(): "
266 "could not map frame_id=" << frame_id; 272 "could not map frame_id=" << frame_id;
267 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); 273 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError);
268 return; 274 return;
269 } 275 }
270 276
271 uint8* shm_memory = reinterpret_cast<uint8*>(shm->memory()); 277 uint8* shm_memory = reinterpret_cast<uint8*>(shm->memory()) +
278 (buffer_offset - map_offset);
272 scoped_refptr<media::VideoFrame> frame = 279 scoped_refptr<media::VideoFrame> frame =
273 media::VideoFrame::WrapExternalPackedMemory( 280 media::VideoFrame::WrapExternalPackedMemory(
274 input_format_, 281 input_format_,
275 input_coded_size_, 282 input_coded_size_,
276 gfx::Rect(input_visible_size_), 283 gfx::Rect(input_visible_size_),
277 input_visible_size_, 284 input_visible_size_,
278 shm_memory, 285 shm_memory,
279 buffer_size, 286 buffer_size,
280 buffer_handle, 287 buffer_handle,
288 buffer_offset,
DaleCurtis 2015/01/30 18:44:59 This is unused from now no, no?
llandwerlin-old 2015/01/31 22:42:53 Yes, once in the gpu process this is unused. I jus
281 base::TimeDelta(), 289 base::TimeDelta(),
282 // It's turtles all the way down... 290 // It's turtles all the way down...
283 base::Bind(base::IgnoreResult(&base::MessageLoopProxy::PostTask), 291 base::Bind(base::IgnoreResult(&base::MessageLoopProxy::PostTask),
284 base::MessageLoopProxy::current(), 292 base::MessageLoopProxy::current(),
285 FROM_HERE, 293 FROM_HERE,
286 base::Bind(&GpuVideoEncodeAccelerator::EncodeFrameFinished, 294 base::Bind(&GpuVideoEncodeAccelerator::EncodeFrameFinished,
287 weak_this_factory_.GetWeakPtr(), 295 weak_this_factory_.GetWeakPtr(),
288 frame_id, 296 frame_id,
289 base::Passed(&shm)))); 297 base::Passed(&shm))));
290 298
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 stub_->channel()->Send(message); 359 stub_->channel()->Send(message);
352 } 360 }
353 361
354 void GpuVideoEncodeAccelerator::SendCreateEncoderReply(IPC::Message* message, 362 void GpuVideoEncodeAccelerator::SendCreateEncoderReply(IPC::Message* message,
355 bool succeeded) { 363 bool succeeded) {
356 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(message, succeeded); 364 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(message, succeeded);
357 Send(message); 365 Send(message);
358 } 366 }
359 367
360 } // namespace content 368 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698