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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 PP_VideoProfileDescription pp_profile; | 159 PP_VideoProfileDescription pp_profile; |
159 pp_profile.profile = PP_FromMediaVideoProfile(profile.profile); | 160 pp_profile.profile = PP_FromMediaVideoProfile(profile.profile); |
160 pp_profile.max_resolution = PP_FromGfxSize(profile.max_resolution); | 161 pp_profile.max_resolution = PP_FromGfxSize(profile.max_resolution); |
161 pp_profile.max_framerate_numerator = profile.max_framerate_numerator; | 162 pp_profile.max_framerate_numerator = profile.max_framerate_numerator; |
162 pp_profile.max_framerate_denominator = profile.max_framerate_denominator; | 163 pp_profile.max_framerate_denominator = profile.max_framerate_denominator; |
163 pp_profile.acceleration = acceleration; | 164 pp_profile.acceleration = acceleration; |
164 return pp_profile; | 165 return pp_profile; |
165 } | 166 } |
166 | 167 |
167 bool PP_HardwareAccelerationCompatible(PP_HardwareAcceleration supply, | 168 bool PP_HardwareAccelerationCompatible(PP_HardwareAcceleration supply, |
168 PP_HardwareAcceleration demand) { | 169 PP_HardwareAcceleration demand) { |
bbudge
2015/03/02 20:01:06
Now that we know how merging supported profiles wi
llandwerlin-old
2015/03/03 15:23:27
Leaving this for another CL.
| |
169 switch (supply) { | 170 switch (supply) { |
170 case PP_HARDWAREACCELERATION_ONLY: | 171 case PP_HARDWAREACCELERATION_ONLY: |
171 return (demand == PP_HARDWAREACCELERATION_ONLY || | 172 return (demand == PP_HARDWAREACCELERATION_ONLY || |
172 demand == PP_HARDWAREACCELERATION_WITHFALLBACK); | 173 demand == PP_HARDWAREACCELERATION_WITHFALLBACK); |
173 case PP_HARDWAREACCELERATION_WITHFALLBACK: | 174 case PP_HARDWAREACCELERATION_WITHFALLBACK: |
174 return true; | 175 return true; |
175 case PP_HARDWAREACCELERATION_NONE: | 176 case PP_HARDWAREACCELERATION_NONE: |
176 return (demand == PP_HARDWAREACCELERATION_WITHFALLBACK || | 177 return (demand == PP_HARDWAREACCELERATION_WITHFALLBACK || |
177 demand == PP_HARDWAREACCELERATION_NONE); | 178 demand == PP_HARDWAREACCELERATION_NONE); |
178 // No default case, to catch unhandled PP_HardwareAcceleration values. | 179 // No default case, to catch unhandled PP_HardwareAcceleration values. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 gfx::Size input_size(input_visible_size.width, input_visible_size.height); | 274 gfx::Size input_size(input_visible_size.width, input_visible_size.height); |
274 if (input_size.IsEmpty()) | 275 if (input_size.IsEmpty()) |
275 return PP_ERROR_BADARGUMENT; | 276 return PP_ERROR_BADARGUMENT; |
276 | 277 |
277 if (!IsInitializationValid(input_visible_size, output_profile, acceleration)) | 278 if (!IsInitializationValid(input_visible_size, output_profile, acceleration)) |
278 return PP_ERROR_NOTSUPPORTED; | 279 return PP_ERROR_NOTSUPPORTED; |
279 | 280 |
280 int32_t error = PP_ERROR_NOTSUPPORTED; | 281 int32_t error = PP_ERROR_NOTSUPPORTED; |
281 initialize_reply_context_ = context->MakeReplyMessageContext(); | 282 initialize_reply_context_ = context->MakeReplyMessageContext(); |
282 | 283 |
283 if (acceleration == PP_HARDWAREACCELERATION_ONLY || | 284 if (acceleration != PP_HARDWAREACCELERATION_NONE) { |
284 acceleration == PP_HARDWAREACCELERATION_WITHFALLBACK) { | |
285 if (InitializeHardware(media_input_format_, input_size, media_profile, | 285 if (InitializeHardware(media_input_format_, input_size, media_profile, |
286 initial_bitrate)) | 286 initial_bitrate)) |
287 return PP_OK_COMPLETIONPENDING; | 287 return PP_OK_COMPLETIONPENDING; |
288 | 288 |
289 if (acceleration == PP_HARDWAREACCELERATION_ONLY) | 289 if (acceleration == PP_HARDWAREACCELERATION_ONLY) |
290 error = PP_ERROR_FAILED; | 290 error = PP_ERROR_FAILED; |
291 } | 291 } |
292 | 292 |
293 // TODO(llandwerlin): Software encoder. | 293 if (acceleration != PP_HARDWAREACCELERATION_ONLY) { |
294 encoder_.reset(new VideoEncoderShim(this)); | |
295 if (encoder_->Initialize(media_input_format_, input_size, media_profile, | |
296 initial_bitrate, this)) | |
297 return PP_OK_COMPLETIONPENDING; | |
298 error = PP_ERROR_FAILED; | |
299 } | |
300 | |
294 initialize_reply_context_ = ppapi::host::ReplyMessageContext(); | 301 initialize_reply_context_ = ppapi::host::ReplyMessageContext(); |
295 Close(); | 302 Close(); |
296 return error; | 303 return error; |
297 } | 304 } |
298 | 305 |
299 int32_t PepperVideoEncoderHost::OnHostMsgGetVideoFrames( | 306 int32_t PepperVideoEncoderHost::OnHostMsgGetVideoFrames( |
300 ppapi::host::HostMessageContext* context) { | 307 ppapi::host::HostMessageContext* context) { |
301 if (encoder_last_error_) | 308 if (encoder_last_error_) |
302 return encoder_last_error_; | 309 return encoder_last_error_; |
303 | 310 |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
447 if (!EnsureGpuChannel()) | 454 if (!EnsureGpuChannel()) |
448 return; | 455 return; |
449 | 456 |
450 std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles = | 457 std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles = |
451 GpuVideoEncodeAcceleratorHost::ConvertGpuToMediaProfiles( | 458 GpuVideoEncodeAcceleratorHost::ConvertGpuToMediaProfiles( |
452 channel_->gpu_info().video_encode_accelerator_supported_profiles); | 459 channel_->gpu_info().video_encode_accelerator_supported_profiles); |
453 for (media::VideoEncodeAccelerator::SupportedProfile profile : profiles) | 460 for (media::VideoEncodeAccelerator::SupportedProfile profile : profiles) |
454 pp_profiles->push_back(PP_FromVideoEncodeAcceleratorSupportedProfile( | 461 pp_profiles->push_back(PP_FromVideoEncodeAcceleratorSupportedProfile( |
455 profile, PP_HARDWAREACCELERATION_ONLY)); | 462 profile, PP_HARDWAREACCELERATION_ONLY)); |
456 | 463 |
457 // TODO(llandwerlin): add software supported profiles. | 464 VideoEncoderShim software_encoder(this); |
465 profiles = software_encoder.GetSupportedProfiles(); | |
466 for (media::VideoEncodeAccelerator::SupportedProfile profile : profiles) | |
467 pp_profiles->push_back(PP_FromVideoEncodeAcceleratorSupportedProfile( | |
468 profile, PP_HARDWAREACCELERATION_NONE)); | |
458 } | 469 } |
459 | 470 |
460 bool PepperVideoEncoderHost::IsInitializationValid( | 471 bool PepperVideoEncoderHost::IsInitializationValid( |
461 const PP_Size& input_size, | 472 const PP_Size& input_size, |
462 PP_VideoProfile output_profile, | 473 PP_VideoProfile output_profile, |
463 PP_HardwareAcceleration acceleration) { | 474 PP_HardwareAcceleration acceleration) { |
464 DCHECK(RenderThreadImpl::current()); | 475 DCHECK(RenderThreadImpl::current()); |
465 | 476 |
466 std::vector<PP_VideoProfileDescription> profiles; | 477 std::vector<PP_VideoProfileDescription> profiles; |
467 GetSupportedProfiles(&profiles); | 478 GetSupportedProfiles(&profiles); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
642 void PepperVideoEncoderHost::NotifyPepperError(int32_t error) { | 653 void PepperVideoEncoderHost::NotifyPepperError(int32_t error) { |
643 DCHECK(RenderThreadImpl::current()); | 654 DCHECK(RenderThreadImpl::current()); |
644 | 655 |
645 encoder_last_error_ = error; | 656 encoder_last_error_ = error; |
646 Close(); | 657 Close(); |
647 host()->SendUnsolicitedReply( | 658 host()->SendUnsolicitedReply( |
648 pp_resource(), | 659 pp_resource(), |
649 PpapiPluginMsg_VideoEncoder_NotifyError(encoder_last_error_)); | 660 PpapiPluginMsg_VideoEncoder_NotifyError(encoder_last_error_)); |
650 } | 661 } |
651 | 662 |
663 uint8_t* PepperVideoEncoderHost::ShmHandleToAddress(int32 buffer_id) { | |
664 DCHECK(RenderThreadImpl::current()); | |
665 DCHECK_GE(buffer_id, 0); | |
666 DCHECK_LT(buffer_id, static_cast<int32>(shm_buffers_.size())); | |
667 return static_cast<uint8_t*>(shm_buffers_[buffer_id]->shm->memory()); | |
668 } | |
669 | |
652 } // namespace content | 670 } // namespace content |
OLD | NEW |