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

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: Update after dcheng's review 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/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
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()) +
287 (buffer_offset - map_offset.ValueOrDie());
dcheng 2015/02/09 18:57:09 Use aligned_offset here too.
llandwerlin-old 2015/02/09 19:34:34 Done.
270 scoped_refptr<media::VideoFrame> frame = 288 scoped_refptr<media::VideoFrame> frame =
271 media::VideoFrame::WrapExternalPackedMemory( 289 media::VideoFrame::WrapExternalPackedMemory(
272 input_format_, 290 input_format_,
273 input_coded_size_, 291 input_coded_size_,
274 gfx::Rect(input_visible_size_), 292 gfx::Rect(input_visible_size_),
275 input_visible_size_, 293 input_visible_size_,
276 shm_memory, 294 shm_memory,
277 buffer_size, 295 buffer_size,
278 buffer_handle, 296 buffer_handle,
297 buffer_offset,
279 base::TimeDelta(), 298 base::TimeDelta(),
280 // It's turtles all the way down... 299 // It's turtles all the way down...
281 base::Bind(base::IgnoreResult(&base::MessageLoopProxy::PostTask), 300 base::Bind(base::IgnoreResult(&base::MessageLoopProxy::PostTask),
282 base::MessageLoopProxy::current(), 301 base::MessageLoopProxy::current(),
283 FROM_HERE, 302 FROM_HERE,
284 base::Bind(&GpuVideoEncodeAccelerator::EncodeFrameFinished, 303 base::Bind(&GpuVideoEncodeAccelerator::EncodeFrameFinished,
285 weak_this_factory_.GetWeakPtr(), 304 weak_this_factory_.GetWeakPtr(),
286 frame_id, 305 frame_id,
287 base::Passed(&shm)))); 306 base::Passed(&shm))));
288 307
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 stub_->channel()->Send(message); 368 stub_->channel()->Send(message);
350 } 369 }
351 370
352 void GpuVideoEncodeAccelerator::SendCreateEncoderReply(IPC::Message* message, 371 void GpuVideoEncodeAccelerator::SendCreateEncoderReply(IPC::Message* message,
353 bool succeeded) { 372 bool succeeded) {
354 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(message, succeeded); 373 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(message, succeeded);
355 Send(message); 374 Send(message);
356 } 375 }
357 376
358 } // namespace content 377 } // namespace content
OLDNEW
« no previous file with comments | « content/common/gpu/media/gpu_video_encode_accelerator.h ('k') | content/renderer/media/rtc_video_encoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698