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

Side by Side Diff: content/renderer/pepper/pepper_video_encoder_host.cc

Issue 956893002: content: pepper: VideoEncoder: add software encoder support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Another android dep fix Created 5 years, 9 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 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/common/pepper_file_util.h" 10 #include "content/common/pepper_file_util.h"
11 #include "content/public/renderer/renderer_ppapi_host.h" 11 #include "content/public/renderer/renderer_ppapi_host.h"
12 #include "content/renderer/pepper/gfx_conversion.h" 12 #include "content/renderer/pepper/gfx_conversion.h"
13 #include "content/renderer/pepper/host_globals.h" 13 #include "content/renderer/pepper/host_globals.h"
14 #include "content/renderer/pepper/pepper_video_encoder_host.h" 14 #include "content/renderer/pepper/pepper_video_encoder_host.h"
15 #include "content/renderer/pepper/video_encoder_shim.h"
15 #include "content/renderer/render_thread_impl.h" 16 #include "content/renderer/render_thread_impl.h"
16 #include "media/base/bind_to_current_loop.h" 17 #include "media/base/bind_to_current_loop.h"
17 #include "media/base/video_frame.h" 18 #include "media/base/video_frame.h"
18 #include "media/renderers/gpu_video_accelerator_factories.h" 19 #include "media/renderers/gpu_video_accelerator_factories.h"
19 #include "media/video/video_encode_accelerator.h" 20 #include "media/video/video_encode_accelerator.h"
20 #include "ppapi/c/pp_codecs.h" 21 #include "ppapi/c/pp_codecs.h"
21 #include "ppapi/c/pp_errors.h" 22 #include "ppapi/c/pp_errors.h"
22 #include "ppapi/c/pp_graphics_3d.h" 23 #include "ppapi/c/pp_graphics_3d.h"
23 #include "ppapi/host/dispatch_host_message.h" 24 #include "ppapi/host/dispatch_host_message.h"
24 #include "ppapi/host/ppapi_host.h" 25 #include "ppapi/host/ppapi_host.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 pp_profile.profile = PP_FromMediaVideoProfile(profile.profile); 150 pp_profile.profile = PP_FromMediaVideoProfile(profile.profile);
150 pp_profile.max_resolution = PP_FromGfxSize(profile.max_resolution); 151 pp_profile.max_resolution = PP_FromGfxSize(profile.max_resolution);
151 pp_profile.max_framerate_numerator = profile.max_framerate_numerator; 152 pp_profile.max_framerate_numerator = profile.max_framerate_numerator;
152 pp_profile.max_framerate_denominator = profile.max_framerate_denominator; 153 pp_profile.max_framerate_denominator = profile.max_framerate_denominator;
153 pp_profile.acceleration = acceleration; 154 pp_profile.acceleration = acceleration;
154 return pp_profile; 155 return pp_profile;
155 } 156 }
156 157
157 bool PP_HardwareAccelerationCompatible(PP_HardwareAcceleration supply, 158 bool PP_HardwareAccelerationCompatible(PP_HardwareAcceleration supply,
158 PP_HardwareAcceleration demand) { 159 PP_HardwareAcceleration demand) {
160 // TODO(llandwerlin): Change API to use bool instead of
161 // PP_HardwareAcceleration
159 switch (supply) { 162 switch (supply) {
160 case PP_HARDWAREACCELERATION_ONLY: 163 case PP_HARDWAREACCELERATION_ONLY:
161 return (demand == PP_HARDWAREACCELERATION_ONLY || 164 return (demand == PP_HARDWAREACCELERATION_ONLY ||
162 demand == PP_HARDWAREACCELERATION_WITHFALLBACK); 165 demand == PP_HARDWAREACCELERATION_WITHFALLBACK);
163 case PP_HARDWAREACCELERATION_WITHFALLBACK: 166 case PP_HARDWAREACCELERATION_WITHFALLBACK:
164 return true; 167 return true;
165 case PP_HARDWAREACCELERATION_NONE: 168 case PP_HARDWAREACCELERATION_NONE:
166 return (demand == PP_HARDWAREACCELERATION_WITHFALLBACK || 169 return (demand == PP_HARDWAREACCELERATION_WITHFALLBACK ||
167 demand == PP_HARDWAREACCELERATION_NONE); 170 demand == PP_HARDWAREACCELERATION_NONE);
168 // No default case, to catch unhandled PP_HardwareAcceleration values. 171 // No default case, to catch unhandled PP_HardwareAcceleration values.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 gfx::Size input_size(input_visible_size.width, input_visible_size.height); 266 gfx::Size input_size(input_visible_size.width, input_visible_size.height);
264 if (input_size.IsEmpty()) 267 if (input_size.IsEmpty())
265 return PP_ERROR_BADARGUMENT; 268 return PP_ERROR_BADARGUMENT;
266 269
267 if (!IsInitializationValid(input_visible_size, output_profile, acceleration)) 270 if (!IsInitializationValid(input_visible_size, output_profile, acceleration))
268 return PP_ERROR_NOTSUPPORTED; 271 return PP_ERROR_NOTSUPPORTED;
269 272
270 int32_t error = PP_ERROR_NOTSUPPORTED; 273 int32_t error = PP_ERROR_NOTSUPPORTED;
271 initialize_reply_context_ = context->MakeReplyMessageContext(); 274 initialize_reply_context_ = context->MakeReplyMessageContext();
272 275
273 if (acceleration == PP_HARDWAREACCELERATION_ONLY || 276 if (acceleration != PP_HARDWAREACCELERATION_NONE) {
274 acceleration == PP_HARDWAREACCELERATION_WITHFALLBACK) {
275 if (InitializeHardware(media_input_format_, input_size, media_profile, 277 if (InitializeHardware(media_input_format_, input_size, media_profile,
276 initial_bitrate)) 278 initial_bitrate))
277 return PP_OK_COMPLETIONPENDING; 279 return PP_OK_COMPLETIONPENDING;
278 280
279 if (acceleration == PP_HARDWAREACCELERATION_ONLY) 281 if (acceleration == PP_HARDWAREACCELERATION_ONLY)
280 error = PP_ERROR_FAILED; 282 error = PP_ERROR_FAILED;
281 } 283 }
282 284
283 // TODO(llandwerlin): Software encoder. 285 #if defined(OS_ANDROID)
284 initialize_reply_context_ = ppapi::host::ReplyMessageContext(); 286 initialize_reply_context_ = ppapi::host::ReplyMessageContext();
285 Close(); 287 Close();
286 return error; 288 return error;
289 #else
290 if (acceleration != PP_HARDWAREACCELERATION_ONLY) {
291 encoder_.reset(new VideoEncoderShim(this));
292 if (encoder_->Initialize(media_input_format_, input_size, media_profile,
293 initial_bitrate, this))
294 return PP_OK_COMPLETIONPENDING;
295 error = PP_ERROR_FAILED;
296 }
297
298 initialize_reply_context_ = ppapi::host::ReplyMessageContext();
299 Close();
300 return error;
301 #endif
287 } 302 }
288 303
289 int32_t PepperVideoEncoderHost::OnHostMsgGetVideoFrames( 304 int32_t PepperVideoEncoderHost::OnHostMsgGetVideoFrames(
290 ppapi::host::HostMessageContext* context) { 305 ppapi::host::HostMessageContext* context) {
291 if (encoder_last_error_) 306 if (encoder_last_error_)
292 return encoder_last_error_; 307 return encoder_last_error_;
293 308
294 get_video_frames_reply_context_ = context->MakeReplyMessageContext(); 309 get_video_frames_reply_context_ = context->MakeReplyMessageContext();
295 AllocateVideoFrames(); 310 AllocateVideoFrames();
296 311
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 void PepperVideoEncoderHost::NotifyError( 443 void PepperVideoEncoderHost::NotifyError(
429 media::VideoEncodeAccelerator::Error error) { 444 media::VideoEncodeAccelerator::Error error) {
430 DCHECK(RenderThreadImpl::current()); 445 DCHECK(RenderThreadImpl::current());
431 NotifyPepperError(PP_FromMediaEncodeAcceleratorError(error)); 446 NotifyPepperError(PP_FromMediaEncodeAcceleratorError(error));
432 } 447 }
433 448
434 void PepperVideoEncoderHost::GetSupportedProfiles( 449 void PepperVideoEncoderHost::GetSupportedProfiles(
435 std::vector<PP_VideoProfileDescription>* pp_profiles) { 450 std::vector<PP_VideoProfileDescription>* pp_profiles) {
436 DCHECK(RenderThreadImpl::current()); 451 DCHECK(RenderThreadImpl::current());
437 452
438 if (!EnsureGpuChannel()) 453 std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles;
439 return;
440 454
441 std::vector<media::VideoEncodeAccelerator::SupportedProfile> profiles = 455 if (EnsureGpuChannel()) {
442 GpuVideoEncodeAcceleratorHost::ConvertGpuToMediaProfiles( 456 profiles = GpuVideoEncodeAcceleratorHost::ConvertGpuToMediaProfiles(
443 channel_->gpu_info().video_encode_accelerator_supported_profiles); 457 channel_->gpu_info().video_encode_accelerator_supported_profiles);
444 for (media::VideoEncodeAccelerator::SupportedProfile profile : profiles) 458 for (media::VideoEncodeAccelerator::SupportedProfile profile : profiles) {
459 pp_profiles->push_back(PP_FromVideoEncodeAcceleratorSupportedProfile(
460 profile, PP_HARDWAREACCELERATION_ONLY));
461 }
462 }
463
464 #if !defined(OS_ANDROID)
465 VideoEncoderShim software_encoder(this);
466 profiles = software_encoder.GetSupportedProfiles();
467 for (media::VideoEncodeAccelerator::SupportedProfile profile : profiles) {
445 pp_profiles->push_back(PP_FromVideoEncodeAcceleratorSupportedProfile( 468 pp_profiles->push_back(PP_FromVideoEncodeAcceleratorSupportedProfile(
446 profile, PP_HARDWAREACCELERATION_ONLY)); 469 profile, PP_HARDWAREACCELERATION_NONE));
447 470 }
448 // TODO(llandwerlin): add software supported profiles. 471 #endif
449 } 472 }
450 473
451 bool PepperVideoEncoderHost::IsInitializationValid( 474 bool PepperVideoEncoderHost::IsInitializationValid(
452 const PP_Size& input_size, 475 const PP_Size& input_size,
453 PP_VideoProfile output_profile, 476 PP_VideoProfile output_profile,
454 PP_HardwareAcceleration acceleration) { 477 PP_HardwareAcceleration acceleration) {
455 DCHECK(RenderThreadImpl::current()); 478 DCHECK(RenderThreadImpl::current());
456 479
457 std::vector<PP_VideoProfileDescription> profiles; 480 std::vector<PP_VideoProfileDescription> profiles;
458 GetSupportedProfiles(&profiles); 481 GetSupportedProfiles(&profiles);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 void PepperVideoEncoderHost::NotifyPepperError(int32_t error) { 657 void PepperVideoEncoderHost::NotifyPepperError(int32_t error) {
635 DCHECK(RenderThreadImpl::current()); 658 DCHECK(RenderThreadImpl::current());
636 659
637 encoder_last_error_ = error; 660 encoder_last_error_ = error;
638 Close(); 661 Close();
639 host()->SendUnsolicitedReply( 662 host()->SendUnsolicitedReply(
640 pp_resource(), 663 pp_resource(),
641 PpapiPluginMsg_VideoEncoder_NotifyError(encoder_last_error_)); 664 PpapiPluginMsg_VideoEncoder_NotifyError(encoder_last_error_));
642 } 665 }
643 666
667 uint8_t* PepperVideoEncoderHost::ShmHandleToAddress(int32 buffer_id) {
668 DCHECK(RenderThreadImpl::current());
669 DCHECK_GE(buffer_id, 0);
670 DCHECK_LT(buffer_id, static_cast<int32>(shm_buffers_.size()));
671 return static_cast<uint8_t*>(shm_buffers_[buffer_id]->shm->memory());
672 }
673
644 } // namespace content 674 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_video_encoder_host.h ('k') | content/renderer/pepper/video_encoder_shim.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698