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

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: addressing nits 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_audio_controller.h"
8 #include "content/renderer/pepper/pepper_platform_audio_output.h" 9 #include "content/renderer/pepper/pepper_platform_audio_output.h"
9 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" 10 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
10 #include "content/renderer/pepper/plugin_instance_throttler_impl.h" 11 #include "content/renderer/pepper/plugin_instance_throttler_impl.h"
11 #include "content/renderer/render_frame_impl.h" 12 #include "content/renderer/render_frame_impl.h"
12 #include "content/renderer/render_view_impl.h"
13 #include "media/audio/audio_output_controller.h" 13 #include "media/audio/audio_output_controller.h"
14 #include "ppapi/c/pp_completion_callback.h" 14 #include "ppapi/c/pp_completion_callback.h"
15 #include "ppapi/c/ppb_audio.h" 15 #include "ppapi/c/ppb_audio.h"
16 #include "ppapi/c/ppb_audio_config.h" 16 #include "ppapi/c/ppb_audio_config.h"
17 #include "ppapi/shared_impl/resource_tracker.h" 17 #include "ppapi/shared_impl/resource_tracker.h"
18 #include "ppapi/thunk/enter.h" 18 #include "ppapi/thunk/enter.h"
19 #include "ppapi/thunk/ppb_audio_config_api.h" 19 #include "ppapi/thunk/ppb_audio_config_api.h"
20 #include "ppapi/thunk/thunk.h" 20 #include "ppapi/thunk/thunk.h"
21 21
22 using ppapi::PpapiGlobals; 22 using ppapi::PpapiGlobals;
(...skipping 14 matching lines...) Expand all
37 static_cast<PepperPluginInstanceImpl*>( 37 static_cast<PepperPluginInstanceImpl*>(
38 PepperPluginInstance::Get(pp_instance())); 38 PepperPluginInstance::Get(pp_instance()));
39 if (plugin_instance && plugin_instance->throttler()) { 39 if (plugin_instance && plugin_instance->throttler()) {
40 plugin_instance->throttler()->AddObserver(this); 40 plugin_instance->throttler()->AddObserver(this);
41 } 41 }
42 } 42 }
43 43
44 PPB_Audio_Impl::~PPB_Audio_Impl() { 44 PPB_Audio_Impl::~PPB_Audio_Impl() {
45 PepperPluginInstanceImpl* instance = static_cast<PepperPluginInstanceImpl*>( 45 PepperPluginInstanceImpl* instance = static_cast<PepperPluginInstanceImpl*>(
46 PepperPluginInstance::Get(pp_instance())); 46 PepperPluginInstance::Get(pp_instance()));
47 if (instance && instance->throttler()) { 47 if (instance) {
48 instance->throttler()->RemoveObserver(this); 48 if (instance->throttler()) {
49 instance->throttler()->RemoveObserver(this);
50 }
51 instance->audio_controller().RemoveInstance(this);
49 } 52 }
50 53
51 // Calling ShutDown() makes sure StreamCreated cannot be called anymore and 54 // Calling ShutDown() makes sure StreamCreated cannot be called anymore and
52 // releases the audio data associated with the pointer. Note however, that 55 // releases the audio data associated with the pointer. Note however, that
53 // until ShutDown returns, StreamCreated may still be called. This will be 56 // until ShutDown returns, StreamCreated may still be called. This will be
54 // OK since we'll just immediately clean up the data it stored later in this 57 // OK since we'll just immediately clean up the data it stored later in this
55 // destructor. 58 // destructor.
56 if (audio_) { 59 if (audio_) {
57 audio_->ShutDown(); 60 audio_->ShutDown();
58 audio_ = NULL; 61 audio_ = NULL;
(...skipping 17 matching lines...) Expand all
76 // If plugin is in power saver mode, defer audio IPC communication. 79 // If plugin is in power saver mode, defer audio IPC communication.
77 PepperPluginInstanceImpl* instance = static_cast<PepperPluginInstanceImpl*>( 80 PepperPluginInstanceImpl* instance = static_cast<PepperPluginInstanceImpl*>(
78 PepperPluginInstance::Get(pp_instance())); 81 PepperPluginInstance::Get(pp_instance()));
79 if (instance && instance->throttler() && 82 if (instance && instance->throttler() &&
80 instance->throttler()->power_saver_enabled()) { 83 instance->throttler()->power_saver_enabled()) {
81 instance->throttler()->NotifyAudioThrottled(); 84 instance->throttler()->NotifyAudioThrottled();
82 playback_throttled_ = true; 85 playback_throttled_ = true;
83 return PP_TRUE; 86 return PP_TRUE;
84 } 87 }
85 88
89 if (instance)
90 instance->audio_controller().AddInstance(this);
91
86 SetStartPlaybackState(); 92 SetStartPlaybackState();
87 return PP_FromBool(audio_->StartPlayback()); 93 return PP_FromBool(audio_->StartPlayback());
88 } 94 }
89 95
90 PP_Bool PPB_Audio_Impl::StopPlayback() { 96 PP_Bool PPB_Audio_Impl::StopPlayback() {
91 if (!audio_) 97 if (!audio_)
92 return PP_FALSE; 98 return PP_FALSE;
93 99
94 if (playback_throttled_) { 100 if (playback_throttled_) {
95 // If a start playback request is still deferred, we must fulfill it first 101 // If a start playback request is still deferred, we must fulfill it first
96 // to shut down the audio thread correctly. 102 // to shut down the audio thread correctly.
97 StartDeferredPlayback(); 103 StartDeferredPlayback();
98 } 104 }
99 105
106 PepperPluginInstanceImpl* instance = static_cast<PepperPluginInstanceImpl*>(
107 PepperPluginInstance::Get(pp_instance()));
108 if (instance)
109 instance->audio_controller().RemoveInstance(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()));
189 if (instance)
190 instance->audio_controller().AddInstance(this);
191
176 SetStartPlaybackState(); 192 SetStartPlaybackState();
177 audio_->StartPlayback(); 193 audio_->StartPlayback();
178 } 194 }
179 195
196 void PPB_Audio_Impl::SetVolume(double volume) {
197 if (audio_)
198 audio_->SetVolume(volume);
199 }
180 } // namespace content 200 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698