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

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: Add modifications to the example to expose different profiles 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/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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
170 // TODO(llandwerlin): Change API to use bool instead of
171 // PP_HardwareAcceleration
169 switch (supply) { 172 switch (supply) {
170 case PP_HARDWAREACCELERATION_ONLY: 173 case PP_HARDWAREACCELERATION_ONLY:
171 return (demand == PP_HARDWAREACCELERATION_ONLY || 174 return (demand == PP_HARDWAREACCELERATION_ONLY ||
172 demand == PP_HARDWAREACCELERATION_WITHFALLBACK); 175 demand == PP_HARDWAREACCELERATION_WITHFALLBACK);
173 case PP_HARDWAREACCELERATION_WITHFALLBACK: 176 case PP_HARDWAREACCELERATION_WITHFALLBACK:
174 return true; 177 return true;
175 case PP_HARDWAREACCELERATION_NONE: 178 case PP_HARDWAREACCELERATION_NONE:
176 return (demand == PP_HARDWAREACCELERATION_WITHFALLBACK || 179 return (demand == PP_HARDWAREACCELERATION_WITHFALLBACK ||
177 demand == PP_HARDWAREACCELERATION_NONE); 180 demand == PP_HARDWAREACCELERATION_NONE);
178 // No default case, to catch unhandled PP_HardwareAcceleration values. 181 // No default case, to catch unhandled PP_HardwareAcceleration values.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 gfx::Size input_size(input_visible_size.width, input_visible_size.height); 276 gfx::Size input_size(input_visible_size.width, input_visible_size.height);
274 if (input_size.IsEmpty()) 277 if (input_size.IsEmpty())
275 return PP_ERROR_BADARGUMENT; 278 return PP_ERROR_BADARGUMENT;
276 279
277 if (!IsInitializationValid(input_visible_size, output_profile, acceleration)) 280 if (!IsInitializationValid(input_visible_size, output_profile, acceleration))
278 return PP_ERROR_NOTSUPPORTED; 281 return PP_ERROR_NOTSUPPORTED;
279 282
280 int32_t error = PP_ERROR_NOTSUPPORTED; 283 int32_t error = PP_ERROR_NOTSUPPORTED;
281 initialize_reply_context_ = context->MakeReplyMessageContext(); 284 initialize_reply_context_ = context->MakeReplyMessageContext();
282 285
283 if (acceleration == PP_HARDWAREACCELERATION_ONLY || 286 if (acceleration != PP_HARDWAREACCELERATION_NONE) {
284 acceleration == PP_HARDWAREACCELERATION_WITHFALLBACK) {
285 if (InitializeHardware(media_input_format_, input_size, media_profile, 287 if (InitializeHardware(media_input_format_, input_size, media_profile,
286 initial_bitrate)) 288 initial_bitrate))
287 return PP_OK_COMPLETIONPENDING; 289 return PP_OK_COMPLETIONPENDING;
288 290
289 if (acceleration == PP_HARDWAREACCELERATION_ONLY) 291 if (acceleration == PP_HARDWAREACCELERATION_ONLY)
290 error = PP_ERROR_FAILED; 292 error = PP_ERROR_FAILED;
291 } 293 }
292 294
293 // TODO(llandwerlin): Software encoder. 295 if (acceleration != PP_HARDWAREACCELERATION_ONLY) {
296 encoder_.reset(new VideoEncoderShim(this));
297 if (encoder_->Initialize(media_input_format_, input_size, media_profile,
298 initial_bitrate, this))
299 return PP_OK_COMPLETIONPENDING;
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
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));
bbudge 2015/03/16 18:27:48 use brackets here please.
llandwerlin-old 2015/03/16 19:08:09 Done.
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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 void PepperVideoEncoderHost::NotifyPepperError(int32_t error) { 655 void PepperVideoEncoderHost::NotifyPepperError(int32_t error) {
643 DCHECK(RenderThreadImpl::current()); 656 DCHECK(RenderThreadImpl::current());
644 657
645 encoder_last_error_ = error; 658 encoder_last_error_ = error;
646 Close(); 659 Close();
647 host()->SendUnsolicitedReply( 660 host()->SendUnsolicitedReply(
648 pp_resource(), 661 pp_resource(),
649 PpapiPluginMsg_VideoEncoder_NotifyError(encoder_last_error_)); 662 PpapiPluginMsg_VideoEncoder_NotifyError(encoder_last_error_));
650 } 663 }
651 664
665 uint8_t* PepperVideoEncoderHost::ShmHandleToAddress(int32 buffer_id) {
666 DCHECK(RenderThreadImpl::current());
667 DCHECK_GE(buffer_id, 0);
668 DCHECK_LT(buffer_id, static_cast<int32>(shm_buffers_.size()));
669 return static_cast<uint8_t*>(shm_buffers_[buffer_id]->shm->memory());
670 }
671
652 } // namespace content 672 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698