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

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(ARCH_CPU_ARMEL) || (defined(USE_OZONE) && defined(USE_V4L2_CODEC)) 23 #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() { 240 GpuVideoEncodeAccelerator::CreateAndroidVEA() {
239 scoped_ptr<media::VideoEncodeAccelerator> encoder; 241 scoped_ptr<media::VideoEncodeAccelerator> encoder;
240 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) 242 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
241 encoder.reset(new AndroidVideoEncodeAccelerator()); 243 encoder.reset(new AndroidVideoEncodeAccelerator());
242 #endif 244 #endif
243 return encoder.Pass(); 245 return encoder.Pass();
244 } 246 }
245 247
246 void GpuVideoEncodeAccelerator::OnEncode(int32 frame_id, 248 void GpuVideoEncodeAccelerator::OnEncode(int32 frame_id,
247 base::SharedMemoryHandle buffer_handle, 249 base::SharedMemoryHandle buffer_handle,
250 uint32 buffer_offset,
248 uint32 buffer_size, 251 uint32 buffer_size,
249 bool force_keyframe) { 252 bool force_keyframe) {
250 DVLOG(3) << "GpuVideoEncodeAccelerator::OnEncode(): frame_id=" << frame_id 253 DVLOG(3) << "GpuVideoEncodeAccelerator::OnEncode(): frame_id=" << frame_id
251 << ", buffer_size=" << buffer_size 254 << ", buffer_size=" << buffer_size
252 << ", force_keyframe=" << force_keyframe; 255 << ", force_keyframe=" << force_keyframe;
253 if (!encoder_) 256 if (!encoder_)
254 return; 257 return;
255 if (frame_id < 0) { 258 if (frame_id < 0) {
256 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode(): invalid frame_id=" 259 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode(): invalid frame_id="
257 << frame_id; 260 << frame_id;
258 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); 261 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError);
259 return; 262 return;
260 } 263 }
261 264
265 base::CheckedNumeric<off_t> map_offset = buffer_offset;
266 map_offset -= (buffer_offset % base::SysInfo::VMAllocationGranularity());
267 if (!map_offset.IsValid()) {
268 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode():"
269 << " invalid buffer_offset=" << buffer_offset;
270 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError);
271 return;
272 }
273 base::CheckedNumeric<size_t> map_size = buffer_size;
274 map_size += (static_cast<off_t>(buffer_offset) -
275 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.
276 if (!map_size.IsValid()) {
277 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode():"
278 << " invalid buffer_offset=" << buffer_offset
279 << " buffer_size=" << buffer_size;
280 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError);
281 return;
282 }
283
262 scoped_ptr<base::SharedMemory> shm( 284 scoped_ptr<base::SharedMemory> shm(
263 new base::SharedMemory(buffer_handle, true)); 285 new base::SharedMemory(buffer_handle, true));
264 if (!shm->Map(buffer_size)) { 286 if (!shm->MapAt(map_offset.ValueOrDie(), map_size.ValueOrDie())) {
265 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode(): " 287 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode(): "
266 "could not map frame_id=" << frame_id; 288 "could not map frame_id=" << frame_id;
267 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); 289 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError);
268 return; 290 return;
269 } 291 }
270 292
271 uint8* shm_memory = reinterpret_cast<uint8*>(shm->memory()); 293 uint8* shm_memory = reinterpret_cast<uint8*>(shm->memory()) +
294 (buffer_offset - map_offset.ValueOrDie());
272 scoped_refptr<media::VideoFrame> frame = 295 scoped_refptr<media::VideoFrame> frame =
273 media::VideoFrame::WrapExternalPackedMemory( 296 media::VideoFrame::WrapExternalPackedMemory(
274 input_format_, 297 input_format_,
275 input_coded_size_, 298 input_coded_size_,
276 gfx::Rect(input_visible_size_), 299 gfx::Rect(input_visible_size_),
277 input_visible_size_, 300 input_visible_size_,
278 shm_memory, 301 shm_memory,
279 buffer_size, 302 buffer_size,
280 buffer_handle, 303 buffer_handle,
304 buffer_offset,
281 base::TimeDelta(), 305 base::TimeDelta(),
282 // It's turtles all the way down... 306 // It's turtles all the way down...
283 base::Bind(base::IgnoreResult(&base::MessageLoopProxy::PostTask), 307 base::Bind(base::IgnoreResult(&base::MessageLoopProxy::PostTask),
284 base::MessageLoopProxy::current(), 308 base::MessageLoopProxy::current(),
285 FROM_HERE, 309 FROM_HERE,
286 base::Bind(&GpuVideoEncodeAccelerator::EncodeFrameFinished, 310 base::Bind(&GpuVideoEncodeAccelerator::EncodeFrameFinished,
287 weak_this_factory_.GetWeakPtr(), 311 weak_this_factory_.GetWeakPtr(),
288 frame_id, 312 frame_id,
289 base::Passed(&shm)))); 313 base::Passed(&shm))));
290 314
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 stub_->channel()->Send(message); 375 stub_->channel()->Send(message);
352 } 376 }
353 377
354 void GpuVideoEncodeAccelerator::SendCreateEncoderReply(IPC::Message* message, 378 void GpuVideoEncodeAccelerator::SendCreateEncoderReply(IPC::Message* message,
355 bool succeeded) { 379 bool succeeded) {
356 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(message, succeeded); 380 GpuCommandBufferMsg_CreateVideoEncoder::WriteReplyParams(message, succeeded);
357 Send(message); 381 Send(message);
358 } 382 }
359 383
360 } // namespace content 384 } // 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