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

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: addressed bbudge's comments 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 17 matching lines...) Expand all
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 && instance->throttler()) {
48 instance->throttler()->RemoveObserver(this); 48 instance->throttler()->RemoveObserver(this);
49 } 49 }
50 if (instance)
51 instance->audio_controller().RemoveInstance(this);
mlamouri (slow - plz ping) 2016/06/23 13:04:13 nit: you could do: ``` if (instance) { if (insta
Zhiqiang Zhang (Slow) 2016/06/23 14:50:29 Done.
50 52
51 // Calling ShutDown() makes sure StreamCreated cannot be called anymore and 53 // Calling ShutDown() makes sure StreamCreated cannot be called anymore and
52 // releases the audio data associated with the pointer. Note however, that 54 // releases the audio data associated with the pointer. Note however, that
53 // until ShutDown returns, StreamCreated may still be called. This will be 55 // 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 56 // OK since we'll just immediately clean up the data it stored later in this
55 // destructor. 57 // destructor.
56 if (audio_) { 58 if (audio_) {
57 audio_->ShutDown(); 59 audio_->ShutDown();
58 audio_ = NULL; 60 audio_ = NULL;
59 } 61 }
(...skipping 16 matching lines...) Expand all
76 // If plugin is in power saver mode, defer audio IPC communication. 78 // If plugin is in power saver mode, defer audio IPC communication.
77 PepperPluginInstanceImpl* instance = static_cast<PepperPluginInstanceImpl*>( 79 PepperPluginInstanceImpl* instance = static_cast<PepperPluginInstanceImpl*>(
78 PepperPluginInstance::Get(pp_instance())); 80 PepperPluginInstance::Get(pp_instance()));
79 if (instance && instance->throttler() && 81 if (instance && instance->throttler() &&
80 instance->throttler()->power_saver_enabled()) { 82 instance->throttler()->power_saver_enabled()) {
81 instance->throttler()->NotifyAudioThrottled(); 83 instance->throttler()->NotifyAudioThrottled();
82 playback_throttled_ = true; 84 playback_throttled_ = true;
83 return PP_TRUE; 85 return PP_TRUE;
84 } 86 }
85 87
88 if (instance)
89 instance->audio_controller().AddInstance(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()));
107 if (instance)
108 instance->audio_controller().RemoveInstance(this);
109
100 if (!playing()) 110 if (!playing())
101 return PP_TRUE; 111 return PP_TRUE;
102 if (!audio_->StopPlayback()) 112 if (!audio_->StopPlayback())
103 return PP_FALSE; 113 return PP_FALSE;
104 SetStopPlaybackState(); 114 SetStopPlaybackState();
105 115
106 return PP_TRUE; 116 return PP_TRUE;
107 } 117 }
108 118
109 int32_t PPB_Audio_Impl::Open(PP_Resource config, 119 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()) { 176 !instance->throttler()->power_saver_enabled()) {
167 // If we have become unthrottled, and we have a pending playback, start it. 177 // If we have become unthrottled, and we have a pending playback, start it.
168 StartDeferredPlayback(); 178 StartDeferredPlayback();
169 } 179 }
170 } 180 }
171 181
172 void PPB_Audio_Impl::StartDeferredPlayback() { 182 void PPB_Audio_Impl::StartDeferredPlayback() {
173 DCHECK(playback_throttled_); 183 DCHECK(playback_throttled_);
174 playback_throttled_ = false; 184 playback_throttled_ = false;
175 185
186 PepperPluginInstanceImpl* instance = static_cast<PepperPluginInstanceImpl*>(
187 PepperPluginInstance::Get(pp_instance()));
188 if (instance)
189 instance->audio_controller().RemoveInstance(this);
mlamouri (slow - plz ping) 2016/06/23 13:04:13 Shouldn't that be AddInstance?
Zhiqiang Zhang (Slow) 2016/06/23 14:50:29 Thanks! Done.
190
176 SetStartPlaybackState(); 191 SetStartPlaybackState();
177 audio_->StartPlayback(); 192 audio_->StartPlayback();
178 } 193 }
179 194
195 void PPB_Audio_Impl::SetVolume(double volume) {
196 if (audio_)
197 audio_->SetVolume(volume);
198 }
180 } // namespace content 199 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698