| Index: content/renderer/pepper/ppb_audio_impl.cc
|
| diff --git a/content/renderer/pepper/ppb_audio_impl.cc b/content/renderer/pepper/ppb_audio_impl.cc
|
| index b7fcf0d9c79156340466d3faef32852f819baecf..7b6ca571ecc71c549bd31c75fd1d28b978328f03 100644
|
| --- a/content/renderer/pepper/ppb_audio_impl.cc
|
| +++ b/content/renderer/pepper/ppb_audio_impl.cc
|
| @@ -30,7 +30,8 @@ namespace content {
|
| // PPB_Audio_Impl --------------------------------------------------------------
|
|
|
| PPB_Audio_Impl::PPB_Audio_Impl(PP_Instance instance)
|
| - : Resource(ppapi::OBJECT_IS_IMPL, instance), audio_(NULL) {}
|
| + : Resource(ppapi::OBJECT_IS_IMPL, instance), audio_(NULL) {
|
| +}
|
|
|
| PPB_Audio_Impl::~PPB_Audio_Impl() {
|
| // Calling ShutDown() makes sure StreamCreated cannot be called anymore and
|
| @@ -57,6 +58,17 @@ PP_Bool PPB_Audio_Impl::StartPlayback() {
|
| return PP_FALSE;
|
| if (playing())
|
| return PP_TRUE;
|
| +
|
| + // If plugin is in power saver mode, defer audio IPC communication.
|
| + PepperPluginInstanceImpl* instance = static_cast<PepperPluginInstanceImpl*>(
|
| + PepperPluginInstance::Get(pp_instance()));
|
| + if (instance->throttler() && instance->throttler()->power_saver_enabled()) {
|
| + if (!IsMutedForPowerSaver()) {
|
| + SetMutedForPowerSaver(true);
|
| + instance->throttler()->AddObserver(this);
|
| + }
|
| + }
|
| +
|
| SetStartPlaybackState();
|
| return PP_FromBool(audio_->StartPlayback());
|
| }
|
| @@ -69,6 +81,16 @@ PP_Bool PPB_Audio_Impl::StopPlayback() {
|
| if (!audio_->StopPlayback())
|
| return PP_FALSE;
|
| SetStopPlaybackState();
|
| +
|
| + if (IsMutedForPowerSaver()) {
|
| + SetMutedForPowerSaver(false);
|
| + PepperPluginInstanceImpl* instance = static_cast<PepperPluginInstanceImpl*>(
|
| + PepperPluginInstance::Get(pp_instance()));
|
| + if (instance && instance->throttler()) {
|
| + instance->throttler()->RemoveObserver(this);
|
| + }
|
| + }
|
| +
|
| return PP_TRUE;
|
| }
|
|
|
| @@ -85,13 +107,6 @@ int32_t PPB_Audio_Impl::Open(PP_Resource config,
|
| if (!instance)
|
| return PP_ERROR_FAILED;
|
|
|
| - // Prevent any throttling since we are playing audio. This stopgap prevents
|
| - // video from appearing 'frozen' while the audio track plays.
|
| - if (instance->throttler() && instance->throttler()->power_saver_enabled()) {
|
| - instance->throttler()->MarkPluginEssential(
|
| - PluginInstanceThrottler::UNTHROTTLE_METHOD_BY_AUDIO);
|
| - }
|
| -
|
| // When the stream is created, we'll get called back on StreamCreated().
|
| DCHECK(!audio_);
|
| audio_ = PepperPlatformAudioOutput::Create(
|
| @@ -132,4 +147,18 @@ void PPB_Audio_Impl::OnSetStreamInfo(
|
| enter.object()->GetSampleFrameCount());
|
| }
|
|
|
| +void PPB_Audio_Impl::OnPowerSaverStateChange(
|
| + PluginInstanceThrottler::PowerSaverState state) {
|
| + // Start deferred playback if necessary.
|
| + if (IsMutedForPowerSaver() &&
|
| + state == PluginInstanceThrottler::POWER_SAVER_MARKED_ESSENTIAL) {
|
| + SetMutedForPowerSaver(false);
|
| + PepperPluginInstanceImpl* instance = static_cast<PepperPluginInstanceImpl*>(
|
| + PepperPluginInstance::Get(pp_instance()));
|
| + if (instance->throttler()) {
|
| + instance->throttler()->RemoveObserver(this);
|
| + }
|
| + }
|
| +}
|
| +
|
| } // namespace content
|
|
|