Chromium Code Reviews| 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 "content/common/gpu/client/command_buffer_proxy_impl.h" | 8 #include "content/common/gpu/client/command_buffer_proxy_impl.h" |
| 9 #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h" | 9 #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h" |
| 10 #include "content/public/renderer/renderer_ppapi_host.h" | 10 #include "content/public/renderer/renderer_ppapi_host.h" |
| 11 #include "content/renderer/pepper/gfx_conversion.h" | 11 #include "content/renderer/pepper/gfx_conversion.h" |
| 12 #include "content/renderer/pepper/host_globals.h" | 12 #include "content/renderer/pepper/host_globals.h" |
| 13 #include "content/renderer/pepper/pepper_video_encoder_host.h" | 13 #include "content/renderer/pepper/pepper_video_encoder_host.h" |
| 14 #include "content/renderer/pepper/video_encoder_shim.h" | |
| 14 #include "content/renderer/render_thread_impl.h" | 15 #include "content/renderer/render_thread_impl.h" |
| 15 #include "media/base/bind_to_current_loop.h" | 16 #include "media/base/bind_to_current_loop.h" |
| 16 #include "media/base/video_frame.h" | 17 #include "media/base/video_frame.h" |
| 17 #include "media/filters/gpu_video_accelerator_factories.h" | 18 #include "media/filters/gpu_video_accelerator_factories.h" |
| 18 #include "media/video/video_encode_accelerator.h" | 19 #include "media/video/video_encode_accelerator.h" |
| 19 #include "ppapi/c/pp_codecs.h" | 20 #include "ppapi/c/pp_codecs.h" |
| 20 #include "ppapi/c/pp_errors.h" | 21 #include "ppapi/c/pp_errors.h" |
| 21 #include "ppapi/c/pp_graphics_3d.h" | 22 #include "ppapi/c/pp_graphics_3d.h" |
| 22 #include "ppapi/host/dispatch_host_message.h" | 23 #include "ppapi/host/dispatch_host_message.h" |
| 23 #include "ppapi/host/ppapi_host.h" | 24 #include "ppapi/host/ppapi_host.h" |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 if (acceleration == PP_HARDWAREACCELERATION_ONLY || | 284 if (acceleration == PP_HARDWAREACCELERATION_ONLY || |
| 284 acceleration == PP_HARDWAREACCELERATION_WITHFALLBACK) { | 285 acceleration == PP_HARDWAREACCELERATION_WITHFALLBACK) { |
| 285 if (InitializeHardware(media_input_format_, input_size, media_profile, | 286 if (InitializeHardware(media_input_format_, input_size, media_profile, |
| 286 initial_bitrate)) | 287 initial_bitrate)) |
| 287 return PP_OK_COMPLETIONPENDING; | 288 return PP_OK_COMPLETIONPENDING; |
| 288 | 289 |
| 289 if (acceleration == PP_HARDWAREACCELERATION_ONLY) | 290 if (acceleration == PP_HARDWAREACCELERATION_ONLY) |
| 290 error = PP_ERROR_FAILED; | 291 error = PP_ERROR_FAILED; |
| 291 } | 292 } |
| 292 | 293 |
| 293 // TODO(llandwerlin): Software encoder. | 294 if (acceleration == PP_HARDWAREACCELERATION_NONE || |
| 295 acceleration == PP_HARDWAREACCELERATION_WITHFALLBACK) { | |
|
bbudge
2015/02/25 17:58:22
nit: The acceleration enum contains every possibil
llandwerlin-old
2015/02/26 13:02:13
Done.
| |
| 296 if (InitializeSoftware(media_input_format_, input_size, media_profile, | |
| 297 initial_bitrate)) | |
| 298 return PP_OK_COMPLETIONPENDING; | |
| 299 | |
| 300 error = PP_ERROR_FAILED; | |
| 301 } | |
| 302 | |
| 294 initialize_reply_context_ = ppapi::host::ReplyMessageContext(); | 303 initialize_reply_context_ = ppapi::host::ReplyMessageContext(); |
| 295 Close(); | 304 Close(); |
| 296 return error; | 305 return error; |
| 297 } | 306 } |
| 298 | 307 |
| 299 int32_t PepperVideoEncoderHost::OnHostMsgGetVideoFrames( | 308 int32_t PepperVideoEncoderHost::OnHostMsgGetVideoFrames( |
| 300 ppapi::host::HostMessageContext* context) { | 309 ppapi::host::HostMessageContext* context) { |
| 301 if (encoder_last_error_) | 310 if (encoder_last_error_) |
| 302 return encoder_last_error_; | 311 return encoder_last_error_; |
| 303 | 312 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 if (!EnsureGpuChannel()) | 456 if (!EnsureGpuChannel()) |
| 448 return; | 457 return; |
| 449 | 458 |
| 450 std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles = | 459 std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles = |
| 451 GpuVideoEncodeAcceleratorHost::ConvertGpuToMediaProfiles( | 460 GpuVideoEncodeAcceleratorHost::ConvertGpuToMediaProfiles( |
| 452 channel_->gpu_info().video_encode_accelerator_supported_profiles); | 461 channel_->gpu_info().video_encode_accelerator_supported_profiles); |
| 453 for (media::VideoEncodeAccelerator::SupportedProfile profile : profiles) | 462 for (media::VideoEncodeAccelerator::SupportedProfile profile : profiles) |
| 454 pp_profiles->push_back(PP_FromVideoEncodeAcceleratorSupportedProfile( | 463 pp_profiles->push_back(PP_FromVideoEncodeAcceleratorSupportedProfile( |
| 455 profile, PP_HARDWAREACCELERATION_ONLY)); | 464 profile, PP_HARDWAREACCELERATION_ONLY)); |
| 456 | 465 |
| 457 // TODO(llandwerlin): add software supported profiles. | 466 VideoEncoderShim software_encoder(this); |
| 467 profiles = software_encoder.GetSupportedProfiles(); | |
| 468 for (media::VideoEncodeAccelerator::SupportedProfile profile : profiles) | |
| 469 pp_profiles->push_back(PP_FromVideoEncodeAcceleratorSupportedProfile( | |
| 470 profile, PP_HARDWAREACCELERATION_NONE)); | |
| 458 } | 471 } |
| 459 | 472 |
| 460 bool PepperVideoEncoderHost::IsInitializationValid( | 473 bool PepperVideoEncoderHost::IsInitializationValid( |
| 461 const PP_Size& input_size, | 474 const PP_Size& input_size, |
| 462 PP_VideoProfile output_profile, | 475 PP_VideoProfile output_profile, |
| 463 PP_HardwareAcceleration acceleration) { | 476 PP_HardwareAcceleration acceleration) { |
| 464 DCHECK(RenderThreadImpl::current()); | 477 DCHECK(RenderThreadImpl::current()); |
| 465 | 478 |
| 466 std::vector<PP_VideoProfileDescription> profiles; | 479 std::vector<PP_VideoProfileDescription> profiles; |
| 467 GetSupportedProfiles(&profiles); | 480 GetSupportedProfiles(&profiles); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 | 535 |
| 523 encoder_ = command_buffer_->CreateVideoEncoder(); | 536 encoder_ = command_buffer_->CreateVideoEncoder(); |
| 524 if (!encoder_ || | 537 if (!encoder_ || |
| 525 !encoder_->Initialize(input_format, input_visible_size, output_profile, | 538 !encoder_->Initialize(input_format, input_visible_size, output_profile, |
| 526 initial_bitrate, this)) | 539 initial_bitrate, this)) |
| 527 return false; | 540 return false; |
| 528 | 541 |
| 529 return true; | 542 return true; |
| 530 } | 543 } |
| 531 | 544 |
| 545 bool PepperVideoEncoderHost::InitializeSoftware( | |
| 546 media::VideoFrame::Format input_format, | |
| 547 const gfx::Size& input_visible_size, | |
| 548 media::VideoCodecProfile output_profile, | |
| 549 uint32_t initial_bitrate) { | |
| 550 encoder_.reset(new VideoEncoderShim(this)); | |
|
bbudge
2015/02/25 17:58:22
DCHECK(!encoder_);
Or simply inline this method at
llandwerlin-old
2015/02/26 13:02:13
Done.
| |
| 551 return encoder_->Initialize(input_format, input_visible_size, output_profile, | |
| 552 initial_bitrate, this); | |
| 553 } | |
| 554 | |
| 532 void PepperVideoEncoderHost::Close() { | 555 void PepperVideoEncoderHost::Close() { |
| 533 DCHECK(RenderThreadImpl::current()); | 556 DCHECK(RenderThreadImpl::current()); |
| 534 | 557 |
| 535 encoder_ = nullptr; | 558 encoder_ = nullptr; |
| 536 if (command_buffer_) { | 559 if (command_buffer_) { |
| 537 DCHECK(channel_); | 560 DCHECK(channel_); |
| 538 channel_->DestroyCommandBuffer(command_buffer_); | 561 channel_->DestroyCommandBuffer(command_buffer_); |
| 539 command_buffer_ = nullptr; | 562 command_buffer_ = nullptr; |
| 540 } | 563 } |
| 541 } | 564 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 642 void PepperVideoEncoderHost::NotifyPepperError(int32_t error) { | 665 void PepperVideoEncoderHost::NotifyPepperError(int32_t error) { |
| 643 DCHECK(RenderThreadImpl::current()); | 666 DCHECK(RenderThreadImpl::current()); |
| 644 | 667 |
| 645 encoder_last_error_ = error; | 668 encoder_last_error_ = error; |
| 646 Close(); | 669 Close(); |
| 647 host()->SendUnsolicitedReply( | 670 host()->SendUnsolicitedReply( |
| 648 pp_resource(), | 671 pp_resource(), |
| 649 PpapiPluginMsg_VideoEncoder_NotifyError(encoder_last_error_)); | 672 PpapiPluginMsg_VideoEncoder_NotifyError(encoder_last_error_)); |
| 650 } | 673 } |
| 651 | 674 |
| 675 uint8_t* PepperVideoEncoderHost::ShmHandleToAddress(int32 buffer_id) { | |
| 676 DCHECK(RenderThreadImpl::current()); | |
| 677 DCHECK_LT(buffer_id, static_cast<int32>(shm_buffers_.size())); | |
|
bbudge
2015/02/25 17:58:22
since buffer_id is signed, you should check that i
llandwerlin-old
2015/02/26 13:02:13
Done.
| |
| 678 return static_cast<uint8_t*>(shm_buffers_[buffer_id]->shm->memory()); | |
| 679 } | |
| 680 | |
| 652 } // namespace content | 681 } // namespace content |
| OLD | NEW |