OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/renderer/pepper/pepper_video_encoder_host.h" | 5 #include "content/renderer/pepper/pepper_video_encoder_host.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ptr_util.h" |
10 #include "base/memory/shared_memory.h" | 11 #include "base/memory/shared_memory.h" |
11 #include "base/numerics/safe_math.h" | 12 #include "base/numerics/safe_math.h" |
12 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
14 #include "content/common/pepper_file_util.h" | 15 #include "content/common/pepper_file_util.h" |
15 #include "content/public/renderer/renderer_ppapi_host.h" | 16 #include "content/public/renderer/renderer_ppapi_host.h" |
16 #include "content/renderer/pepper/gfx_conversion.h" | 17 #include "content/renderer/pepper/gfx_conversion.h" |
17 #include "content/renderer/pepper/host_globals.h" | 18 #include "content/renderer/pepper/host_globals.h" |
18 #include "content/renderer/pepper/video_encoder_shim.h" | 19 #include "content/renderer/pepper/video_encoder_shim.h" |
19 #include "content/renderer/render_thread_impl.h" | 20 #include "content/renderer/render_thread_impl.h" |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 for (uint32_t i = 0; i < kDefaultNumberOfBitstreamBuffers; ++i) { | 396 for (uint32_t i = 0; i < kDefaultNumberOfBitstreamBuffers; ++i) { |
396 std::unique_ptr<base::SharedMemory> shm( | 397 std::unique_ptr<base::SharedMemory> shm( |
397 RenderThread::Get()->HostAllocateSharedMemoryBuffer( | 398 RenderThread::Get()->HostAllocateSharedMemoryBuffer( |
398 output_buffer_size)); | 399 output_buffer_size)); |
399 | 400 |
400 if (!shm || !shm->Map(output_buffer_size)) { | 401 if (!shm || !shm->Map(output_buffer_size)) { |
401 shm_buffers_.clear(); | 402 shm_buffers_.clear(); |
402 break; | 403 break; |
403 } | 404 } |
404 | 405 |
405 shm_buffers_.push_back(new ShmBuffer(i, std::move(shm))); | 406 shm_buffers_.push_back(base::MakeUnique<ShmBuffer>(i, std::move(shm))); |
406 } | 407 } |
407 | 408 |
408 // Feed buffers to the encoder. | 409 // Feed buffers to the encoder. |
409 std::vector<SerializedHandle> handles; | 410 std::vector<SerializedHandle> handles; |
410 for (size_t i = 0; i < shm_buffers_.size(); ++i) { | 411 for (const auto& buffer : shm_buffers_) { |
411 encoder_->UseOutputBitstreamBuffer(shm_buffers_[i]->ToBitstreamBuffer()); | 412 encoder_->UseOutputBitstreamBuffer(buffer->ToBitstreamBuffer()); |
412 handles.push_back(SerializedHandle( | 413 handles.push_back(SerializedHandle( |
413 renderer_ppapi_host_->ShareSharedMemoryHandleWithRemote( | 414 renderer_ppapi_host_->ShareSharedMemoryHandleWithRemote( |
414 shm_buffers_[i]->shm->handle()), | 415 buffer->shm->handle()), |
415 output_buffer_size)); | 416 output_buffer_size)); |
416 } | 417 } |
417 | 418 |
418 host()->SendUnsolicitedReplyWithHandles( | 419 host()->SendUnsolicitedReplyWithHandles( |
419 pp_resource(), PpapiPluginMsg_VideoEncoder_BitstreamBuffers( | 420 pp_resource(), PpapiPluginMsg_VideoEncoder_BitstreamBuffers( |
420 static_cast<uint32_t>(output_buffer_size)), | 421 static_cast<uint32_t>(output_buffer_size)), |
421 handles); | 422 handles); |
422 | 423 |
423 if (!initialized_) { | 424 if (!initialized_) { |
424 // Tell the plugin that initialization has been successful if we | 425 // Tell the plugin that initialization has been successful if we |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 } | 680 } |
680 | 681 |
681 uint8_t* PepperVideoEncoderHost::ShmHandleToAddress(int32_t buffer_id) { | 682 uint8_t* PepperVideoEncoderHost::ShmHandleToAddress(int32_t buffer_id) { |
682 DCHECK(RenderThreadImpl::current()); | 683 DCHECK(RenderThreadImpl::current()); |
683 DCHECK_GE(buffer_id, 0); | 684 DCHECK_GE(buffer_id, 0); |
684 DCHECK_LT(buffer_id, static_cast<int32_t>(shm_buffers_.size())); | 685 DCHECK_LT(buffer_id, static_cast<int32_t>(shm_buffers_.size())); |
685 return static_cast<uint8_t*>(shm_buffers_[buffer_id]->shm->memory()); | 686 return static_cast<uint8_t*>(shm_buffers_[buffer_id]->shm->memory()); |
686 } | 687 } |
687 | 688 |
688 } // namespace content | 689 } // namespace content |
OLD | NEW |