Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/pepper/ppb_audio_impl.h" | 5 #include "content/renderer/pepper/ppb_audio_impl.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/renderer/pepper/pepper_platform_audio_output.h" | 8 #include "content/renderer/pepper/pepper_platform_audio_output.h" |
| 9 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 9 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 10 #include "content/renderer/pepper/plugin_instance_throttler_impl.h" | 10 #include "content/renderer/pepper/plugin_instance_throttler_impl.h" |
| 11 #include "content/renderer/render_frame_impl.h" | 11 #include "content/renderer/render_frame_impl.h" |
| 12 #include "content/renderer/render_view_impl.h" | |
| 13 #include "media/audio/audio_output_controller.h" | 12 #include "media/audio/audio_output_controller.h" |
| 14 #include "ppapi/c/pp_completion_callback.h" | 13 #include "ppapi/c/pp_completion_callback.h" |
| 15 #include "ppapi/c/ppb_audio.h" | 14 #include "ppapi/c/ppb_audio.h" |
| 16 #include "ppapi/c/ppb_audio_config.h" | 15 #include "ppapi/c/ppb_audio_config.h" |
| 17 #include "ppapi/shared_impl/resource_tracker.h" | 16 #include "ppapi/shared_impl/resource_tracker.h" |
| 18 #include "ppapi/thunk/enter.h" | 17 #include "ppapi/thunk/enter.h" |
| 19 #include "ppapi/thunk/ppb_audio_config_api.h" | 18 #include "ppapi/thunk/ppb_audio_config_api.h" |
| 20 #include "ppapi/thunk/thunk.h" | 19 #include "ppapi/thunk/thunk.h" |
| 21 | 20 |
| 22 using ppapi::PpapiGlobals; | 21 using ppapi::PpapiGlobals; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 // If plugin is in power saver mode, defer audio IPC communication. | 75 // If plugin is in power saver mode, defer audio IPC communication. |
| 77 PepperPluginInstanceImpl* instance = static_cast<PepperPluginInstanceImpl*>( | 76 PepperPluginInstanceImpl* instance = static_cast<PepperPluginInstanceImpl*>( |
| 78 PepperPluginInstance::Get(pp_instance())); | 77 PepperPluginInstance::Get(pp_instance())); |
| 79 if (instance && instance->throttler() && | 78 if (instance && instance->throttler() && |
| 80 instance->throttler()->power_saver_enabled()) { | 79 instance->throttler()->power_saver_enabled()) { |
| 81 instance->throttler()->NotifyAudioThrottled(); | 80 instance->throttler()->NotifyAudioThrottled(); |
| 82 playback_throttled_ = true; | 81 playback_throttled_ = true; |
| 83 return PP_TRUE; | 82 return PP_TRUE; |
| 84 } | 83 } |
| 85 | 84 |
| 85 if (instance) { | |
| 86 RenderFrameImpl* render_frame = instance->render_frame(); | |
| 87 if (render_frame) | |
| 88 render_frame->PepperStartsPlayback(instance, this); | |
| 89 } | |
| 90 | |
| 86 SetStartPlaybackState(); | 91 SetStartPlaybackState(); |
| 87 return PP_FromBool(audio_->StartPlayback()); | 92 return PP_FromBool(audio_->StartPlayback()); |
| 88 } | 93 } |
| 89 | 94 |
| 90 PP_Bool PPB_Audio_Impl::StopPlayback() { | 95 PP_Bool PPB_Audio_Impl::StopPlayback() { |
| 91 if (!audio_) | 96 if (!audio_) |
| 92 return PP_FALSE; | 97 return PP_FALSE; |
| 93 | 98 |
| 94 if (playback_throttled_) { | 99 if (playback_throttled_) { |
| 95 // If a start playback request is still deferred, we must fulfill it first | 100 // If a start playback request is still deferred, we must fulfill it first |
| 96 // to shut down the audio thread correctly. | 101 // to shut down the audio thread correctly. |
| 97 StartDeferredPlayback(); | 102 StartDeferredPlayback(); |
| 98 } | 103 } |
| 99 | 104 |
| 105 PepperPluginInstanceImpl* instance = static_cast<PepperPluginInstanceImpl*>( | |
| 106 PepperPluginInstance::Get(pp_instance())); | |
| 107 if (instance) { | |
| 108 RenderFrameImpl* render_frame = instance->render_frame(); | |
| 109 if (render_frame) | |
| 110 render_frame->PepperStopsPlayback(instance, this); | |
| 111 } | |
| 112 | |
| 100 if (!playing()) | 113 if (!playing()) |
| 101 return PP_TRUE; | 114 return PP_TRUE; |
| 102 if (!audio_->StopPlayback()) | 115 if (!audio_->StopPlayback()) |
| 103 return PP_FALSE; | 116 return PP_FALSE; |
| 104 SetStopPlaybackState(); | 117 SetStopPlaybackState(); |
| 105 | 118 |
| 106 return PP_TRUE; | 119 return PP_TRUE; |
| 107 } | 120 } |
| 108 | 121 |
| 109 int32_t PPB_Audio_Impl::Open(PP_Resource config, | 122 int32_t PPB_Audio_Impl::Open(PP_Resource config, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 !instance->throttler()->power_saver_enabled()) { | 179 !instance->throttler()->power_saver_enabled()) { |
| 167 // If we have become unthrottled, and we have a pending playback, start it. | 180 // If we have become unthrottled, and we have a pending playback, start it. |
| 168 StartDeferredPlayback(); | 181 StartDeferredPlayback(); |
| 169 } | 182 } |
| 170 } | 183 } |
| 171 | 184 |
| 172 void PPB_Audio_Impl::StartDeferredPlayback() { | 185 void PPB_Audio_Impl::StartDeferredPlayback() { |
| 173 DCHECK(playback_throttled_); | 186 DCHECK(playback_throttled_); |
| 174 playback_throttled_ = false; | 187 playback_throttled_ = false; |
| 175 | 188 |
| 189 PepperPluginInstanceImpl* instance = static_cast<PepperPluginInstanceImpl*>( | |
| 190 PepperPluginInstance::Get(pp_instance())); | |
|
bbudge
2016/06/14 17:19:13
null check for instance here.
Zhiqiang Zhang (Slow)
2016/06/14 17:28:56
Done.
| |
| 191 RenderFrameImpl* render_frame = instance->render_frame(); | |
| 192 if (render_frame) | |
| 193 render_frame->PepperStartsPlayback(instance, this); | |
| 194 | |
| 176 SetStartPlaybackState(); | 195 SetStartPlaybackState(); |
| 177 audio_->StartPlayback(); | 196 audio_->StartPlayback(); |
| 178 } | 197 } |
| 179 | 198 |
| 199 void PPB_Audio_Impl::SetVolume(double volume) { | |
|
bbudge
2016/06/14 17:19:13
Check that audio_ isn't null? See StopPlayback.
Zhiqiang Zhang (Slow)
2016/06/14 17:28:56
Done.
| |
| 200 audio_->SetVolume(volume); | |
| 201 } | |
| 180 } // namespace content | 202 } // namespace content |
| OLD | NEW |