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

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

Issue 2065513004: Expose flash playback status and volume control to content renderer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@audio_focus_manager
Patch Set: added TODO Created 4 years, 6 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 (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;
23 using ppapi::thunk::EnterResourceNoLock; 22 using ppapi::thunk::EnterResourceNoLock;
24 using ppapi::thunk::PPB_Audio_API; 23 using ppapi::thunk::PPB_Audio_API;
25 using ppapi::thunk::PPB_AudioConfig_API; 24 using ppapi::thunk::PPB_AudioConfig_API;
26 using ppapi::TrackedCallback; 25 using ppapi::TrackedCallback;
27 26
28 namespace content { 27 namespace content {
29 28
30 // PPB_Audio_Impl -------------------------------------------------------------- 29 // PPB_Audio_Impl --------------------------------------------------------------
31 30
32 PPB_Audio_Impl::PPB_Audio_Impl(PP_Instance instance) 31 PPB_Audio_Impl::PPB_Audio_Impl(PP_Instance instance)
33 : Resource(ppapi::OBJECT_IS_IMPL, instance), 32 : Resource(ppapi::OBJECT_IS_IMPL, instance),
34 audio_(NULL), 33 audio_(NULL),
35 playback_throttled_(false) { 34 playback_throttled_(false) {
36 PepperPluginInstanceImpl* plugin_instance = 35 PepperPluginInstanceImpl* plugin_instance =
37 static_cast<PepperPluginInstanceImpl*>( 36 static_cast<PepperPluginInstanceImpl*>(
38 PepperPluginInstance::Get(pp_instance())); 37 PepperPluginInstance::Get(pp_instance()));
39 if (plugin_instance && plugin_instance->throttler()) { 38 if (plugin_instance && plugin_instance->throttler()) {
40 plugin_instance->throttler()->AddObserver(this); 39 plugin_instance->throttler()->AddObserver(this);
41 } 40 }
41 static int32_t pepper_audio_id = 0;
42 pepper_audio_id_ = pepper_audio_id++;
42 } 43 }
43 44
44 PPB_Audio_Impl::~PPB_Audio_Impl() { 45 PPB_Audio_Impl::~PPB_Audio_Impl() {
45 PepperPluginInstanceImpl* instance = static_cast<PepperPluginInstanceImpl*>( 46 PepperPluginInstanceImpl* instance = static_cast<PepperPluginInstanceImpl*>(
46 PepperPluginInstance::Get(pp_instance())); 47 PepperPluginInstance::Get(pp_instance()));
47 if (instance && instance->throttler()) { 48 if (instance && instance->throttler()) {
48 instance->throttler()->RemoveObserver(this); 49 instance->throttler()->RemoveObserver(this);
49 } 50 }
50 51
51 // Calling ShutDown() makes sure StreamCreated cannot be called anymore and 52 // Calling ShutDown() makes sure StreamCreated cannot be called anymore and
(...skipping 24 matching lines...) Expand all
76 // If plugin is in power saver mode, defer audio IPC communication. 77 // If plugin is in power saver mode, defer audio IPC communication.
77 PepperPluginInstanceImpl* instance = static_cast<PepperPluginInstanceImpl*>( 78 PepperPluginInstanceImpl* instance = static_cast<PepperPluginInstanceImpl*>(
78 PepperPluginInstance::Get(pp_instance())); 79 PepperPluginInstance::Get(pp_instance()));
79 if (instance && instance->throttler() && 80 if (instance && instance->throttler() &&
80 instance->throttler()->power_saver_enabled()) { 81 instance->throttler()->power_saver_enabled()) {
81 instance->throttler()->NotifyAudioThrottled(); 82 instance->throttler()->NotifyAudioThrottled();
82 playback_throttled_ = true; 83 playback_throttled_ = true;
83 return PP_TRUE; 84 return PP_TRUE;
84 } 85 }
85 86
87 RenderFrameImpl* render_frame = instance->render_frame();
88 if (render_frame)
89 render_frame->PepperStartsPlayback(instance, this);
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()));
bbudge 2016/06/13 17:51:01 Check for null instance, or add a CHECK or DCHECK
Zhiqiang Zhang (Slow) 2016/06/14 14:15:26 Done.
107 RenderFrameImpl* render_frame = instance->render_frame();
108 if (render_frame)
109 render_frame->PepperStopsPlayback(instance, this);
110
100 if (!playing()) 111 if (!playing())
101 return PP_TRUE; 112 return PP_TRUE;
102 if (!audio_->StopPlayback()) 113 if (!audio_->StopPlayback())
103 return PP_FALSE; 114 return PP_FALSE;
104 SetStopPlaybackState(); 115 SetStopPlaybackState();
105 116
106 return PP_TRUE; 117 return PP_TRUE;
107 } 118 }
108 119
109 int32_t PPB_Audio_Impl::Open(PP_Resource config, 120 int32_t PPB_Audio_Impl::Open(PP_Resource config,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 !instance->throttler()->power_saver_enabled()) { 177 !instance->throttler()->power_saver_enabled()) {
167 // If we have become unthrottled, and we have a pending playback, start it. 178 // If we have become unthrottled, and we have a pending playback, start it.
168 StartDeferredPlayback(); 179 StartDeferredPlayback();
169 } 180 }
170 } 181 }
171 182
172 void PPB_Audio_Impl::StartDeferredPlayback() { 183 void PPB_Audio_Impl::StartDeferredPlayback() {
173 DCHECK(playback_throttled_); 184 DCHECK(playback_throttled_);
174 playback_throttled_ = false; 185 playback_throttled_ = false;
175 186
187 PepperPluginInstanceImpl* instance = static_cast<PepperPluginInstanceImpl*>(
188 PepperPluginInstance::Get(pp_instance()));
bbudge 2016/06/13 17:51:01 Ditto.
Zhiqiang Zhang (Slow) 2016/06/14 14:15:25 Done.
189 RenderFrameImpl* render_frame = instance->render_frame();
190 if (render_frame)
191 render_frame->PepperStartsPlayback(instance, this);
192
176 SetStartPlaybackState(); 193 SetStartPlaybackState();
177 audio_->StartPlayback(); 194 audio_->StartPlayback();
178 } 195 }
179 196
197 void PPB_Audio_Impl::SetVolume(double volume) {
198 audio_->SetVolume(volume);
199 }
180 } // namespace content 200 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698