| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/memory/shared_memory.h" | 6 #include "base/memory/shared_memory.h" |
| 7 #include "base/numerics/safe_math.h" | 7 #include "base/numerics/safe_math.h" |
| 8 #include "build/build_config.h" |
| 8 #include "content/common/gpu/client/command_buffer_proxy_impl.h" | 9 #include "content/common/gpu/client/command_buffer_proxy_impl.h" |
| 9 #include "content/common/gpu/media/gpu_video_accelerator_util.h" | 10 #include "content/common/gpu/media/gpu_video_accelerator_util.h" |
| 10 #include "content/common/pepper_file_util.h" | 11 #include "content/common/pepper_file_util.h" |
| 11 #include "content/public/renderer/renderer_ppapi_host.h" | 12 #include "content/public/renderer/renderer_ppapi_host.h" |
| 12 #include "content/renderer/pepper/gfx_conversion.h" | 13 #include "content/renderer/pepper/gfx_conversion.h" |
| 13 #include "content/renderer/pepper/host_globals.h" | 14 #include "content/renderer/pepper/host_globals.h" |
| 14 #include "content/renderer/pepper/pepper_video_encoder_host.h" | 15 #include "content/renderer/pepper/pepper_video_encoder_host.h" |
| 15 #include "content/renderer/pepper/video_encoder_shim.h" | 16 #include "content/renderer/pepper/video_encoder_shim.h" |
| 16 #include "content/renderer/render_thread_impl.h" | 17 #include "content/renderer/render_thread_impl.h" |
| 17 #include "media/base/bind_to_current_loop.h" | 18 #include "media/base/bind_to_current_loop.h" |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 NotifyPepperError(PP_ERROR_NOMEMORY); | 415 NotifyPepperError(PP_ERROR_NOMEMORY); |
| 415 return; | 416 return; |
| 416 } | 417 } |
| 417 | 418 |
| 418 // If the plugin already requested video frames, we can now answer | 419 // If the plugin already requested video frames, we can now answer |
| 419 // that request. | 420 // that request. |
| 420 if (get_video_frames_reply_context_.is_valid()) | 421 if (get_video_frames_reply_context_.is_valid()) |
| 421 AllocateVideoFrames(); | 422 AllocateVideoFrames(); |
| 422 } | 423 } |
| 423 | 424 |
| 424 void PepperVideoEncoderHost::BitstreamBufferReady(int32 buffer_id, | 425 void PepperVideoEncoderHost::BitstreamBufferReady(int32_t buffer_id, |
| 425 size_t payload_size, | 426 size_t payload_size, |
| 426 bool key_frame) { | 427 bool key_frame) { |
| 427 DCHECK(RenderThreadImpl::current()); | 428 DCHECK(RenderThreadImpl::current()); |
| 428 DCHECK(shm_buffers_[buffer_id]->in_use); | 429 DCHECK(shm_buffers_[buffer_id]->in_use); |
| 429 | 430 |
| 430 shm_buffers_[buffer_id]->in_use = false; | 431 shm_buffers_[buffer_id]->in_use = false; |
| 431 host()->SendUnsolicitedReply( | 432 host()->SendUnsolicitedReply( |
| 432 pp_resource(), | 433 pp_resource(), |
| 433 PpapiPluginMsg_VideoEncoder_BitstreamBufferReady( | 434 PpapiPluginMsg_VideoEncoder_BitstreamBufferReady( |
| 434 buffer_id, static_cast<uint32_t>(payload_size), key_frame)); | 435 buffer_id, static_cast<uint32_t>(payload_size), key_frame)); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 if (command_buffer_) | 493 if (command_buffer_) |
| 493 return true; | 494 return true; |
| 494 | 495 |
| 495 // There is no guarantee that we have a 3D context to work with. So | 496 // There is no guarantee that we have a 3D context to work with. So |
| 496 // we create a dummy command buffer to communicate with the gpu process. | 497 // we create a dummy command buffer to communicate with the gpu process. |
| 497 channel_ = RenderThreadImpl::current()->EstablishGpuChannelSync( | 498 channel_ = RenderThreadImpl::current()->EstablishGpuChannelSync( |
| 498 CAUSE_FOR_GPU_LAUNCH_PEPPERVIDEOENCODERACCELERATOR_INITIALIZE); | 499 CAUSE_FOR_GPU_LAUNCH_PEPPERVIDEOENCODERACCELERATOR_INITIALIZE); |
| 499 if (!channel_) | 500 if (!channel_) |
| 500 return false; | 501 return false; |
| 501 | 502 |
| 502 std::vector<int32> attribs(1, PP_GRAPHICS3DATTRIB_NONE); | 503 std::vector<int32_t> attribs(1, PP_GRAPHICS3DATTRIB_NONE); |
| 503 command_buffer_ = channel_->CreateOffscreenCommandBuffer( | 504 command_buffer_ = channel_->CreateOffscreenCommandBuffer( |
| 504 gfx::Size(), nullptr, GpuChannelHost::kDefaultStreamId, | 505 gfx::Size(), nullptr, GpuChannelHost::kDefaultStreamId, |
| 505 GpuChannelHost::kDefaultStreamPriority, attribs, GURL::EmptyGURL(), | 506 GpuChannelHost::kDefaultStreamPriority, attribs, GURL::EmptyGURL(), |
| 506 gfx::PreferIntegratedGpu); | 507 gfx::PreferIntegratedGpu); |
| 507 if (!command_buffer_) { | 508 if (!command_buffer_) { |
| 508 Close(); | 509 Close(); |
| 509 return false; | 510 return false; |
| 510 } | 511 } |
| 511 | 512 |
| 512 command_buffer_->SetContextLostCallback(media::BindToCurrentLoop( | 513 command_buffer_->SetContextLostCallback(media::BindToCurrentLoop( |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 get_video_frames_reply_context_ = ppapi::host::ReplyMessageContext(); | 617 get_video_frames_reply_context_ = ppapi::host::ReplyMessageContext(); |
| 617 } | 618 } |
| 618 | 619 |
| 619 scoped_refptr<media::VideoFrame> PepperVideoEncoderHost::CreateVideoFrame( | 620 scoped_refptr<media::VideoFrame> PepperVideoEncoderHost::CreateVideoFrame( |
| 620 uint32_t frame_id, | 621 uint32_t frame_id, |
| 621 const ppapi::host::ReplyMessageContext& reply_context) { | 622 const ppapi::host::ReplyMessageContext& reply_context) { |
| 622 DCHECK(RenderThreadImpl::current()); | 623 DCHECK(RenderThreadImpl::current()); |
| 623 | 624 |
| 624 ppapi::MediaStreamBuffer* buffer = buffer_manager_.GetBufferPointer(frame_id); | 625 ppapi::MediaStreamBuffer* buffer = buffer_manager_.GetBufferPointer(frame_id); |
| 625 DCHECK(buffer); | 626 DCHECK(buffer); |
| 626 uint32_t shm_offset = static_cast<uint8*>(buffer->video.data) - | 627 uint32_t shm_offset = static_cast<uint8_t*>(buffer->video.data) - |
| 627 static_cast<uint8*>(buffer_manager_.shm()->memory()); | 628 static_cast<uint8_t*>(buffer_manager_.shm()->memory()); |
| 628 | 629 |
| 629 scoped_refptr<media::VideoFrame> frame = | 630 scoped_refptr<media::VideoFrame> frame = |
| 630 media::VideoFrame::WrapExternalSharedMemory( | 631 media::VideoFrame::WrapExternalSharedMemory( |
| 631 media_input_format_, input_coded_size_, gfx::Rect(input_coded_size_), | 632 media_input_format_, input_coded_size_, gfx::Rect(input_coded_size_), |
| 632 input_coded_size_, static_cast<uint8*>(buffer->video.data), | 633 input_coded_size_, static_cast<uint8_t*>(buffer->video.data), |
| 633 buffer->video.data_size, buffer_manager_.shm()->handle(), shm_offset, | 634 buffer->video.data_size, buffer_manager_.shm()->handle(), shm_offset, |
| 634 base::TimeDelta()); | 635 base::TimeDelta()); |
| 635 frame->AddDestructionObserver( | 636 frame->AddDestructionObserver( |
| 636 base::Bind(&PepperVideoEncoderHost::FrameReleased, | 637 base::Bind(&PepperVideoEncoderHost::FrameReleased, |
| 637 weak_ptr_factory_.GetWeakPtr(), reply_context, frame_id)); | 638 weak_ptr_factory_.GetWeakPtr(), reply_context, frame_id)); |
| 638 return frame; | 639 return frame; |
| 639 } | 640 } |
| 640 | 641 |
| 641 void PepperVideoEncoderHost::FrameReleased( | 642 void PepperVideoEncoderHost::FrameReleased( |
| 642 const ppapi::host::ReplyMessageContext& reply_context, | 643 const ppapi::host::ReplyMessageContext& reply_context, |
| 643 uint32_t frame_id) { | 644 uint32_t frame_id) { |
| 644 DCHECK(RenderThreadImpl::current()); | 645 DCHECK(RenderThreadImpl::current()); |
| 645 | 646 |
| 646 ppapi::host::ReplyMessageContext context = reply_context; | 647 ppapi::host::ReplyMessageContext context = reply_context; |
| 647 context.params.set_result(encoder_last_error_); | 648 context.params.set_result(encoder_last_error_); |
| 648 host()->SendReply(context, PpapiPluginMsg_VideoEncoder_EncodeReply(frame_id)); | 649 host()->SendReply(context, PpapiPluginMsg_VideoEncoder_EncodeReply(frame_id)); |
| 649 } | 650 } |
| 650 | 651 |
| 651 void PepperVideoEncoderHost::NotifyPepperError(int32_t error) { | 652 void PepperVideoEncoderHost::NotifyPepperError(int32_t error) { |
| 652 DCHECK(RenderThreadImpl::current()); | 653 DCHECK(RenderThreadImpl::current()); |
| 653 | 654 |
| 654 encoder_last_error_ = error; | 655 encoder_last_error_ = error; |
| 655 Close(); | 656 Close(); |
| 656 host()->SendUnsolicitedReply( | 657 host()->SendUnsolicitedReply( |
| 657 pp_resource(), | 658 pp_resource(), |
| 658 PpapiPluginMsg_VideoEncoder_NotifyError(encoder_last_error_)); | 659 PpapiPluginMsg_VideoEncoder_NotifyError(encoder_last_error_)); |
| 659 } | 660 } |
| 660 | 661 |
| 661 uint8_t* PepperVideoEncoderHost::ShmHandleToAddress(int32 buffer_id) { | 662 uint8_t* PepperVideoEncoderHost::ShmHandleToAddress(int32_t buffer_id) { |
| 662 DCHECK(RenderThreadImpl::current()); | 663 DCHECK(RenderThreadImpl::current()); |
| 663 DCHECK_GE(buffer_id, 0); | 664 DCHECK_GE(buffer_id, 0); |
| 664 DCHECK_LT(buffer_id, static_cast<int32>(shm_buffers_.size())); | 665 DCHECK_LT(buffer_id, static_cast<int32_t>(shm_buffers_.size())); |
| 665 return static_cast<uint8_t*>(shm_buffers_[buffer_id]->shm->memory()); | 666 return static_cast<uint8_t*>(shm_buffers_[buffer_id]->shm->memory()); |
| 666 } | 667 } |
| 667 | 668 |
| 668 } // namespace content | 669 } // namespace content |
| OLD | NEW |