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

Side by Side Diff: ppapi/shared_impl/ppb_audio_shared.cc

Issue 879403002: Plugin Power Saver: Mute throttled plugins. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 "ppapi/shared_impl/ppb_audio_shared.h" 5 #include "ppapi/shared_impl/ppb_audio_shared.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "ppapi/nacl_irt/public/irt_ppapi.h" 9 #include "ppapi/nacl_irt/public/irt_ppapi.h"
10 #include "ppapi/shared_impl/ppapi_globals.h" 10 #include "ppapi/shared_impl/ppapi_globals.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 callback_(sample_buffer, buffer_size_in_bytes, latency, user_data); 43 callback_(sample_buffer, buffer_size_in_bytes, latency, user_data);
44 } else if (callback_1_0_) { 44 } else if (callback_1_0_) {
45 callback_1_0_(sample_buffer, buffer_size_in_bytes, user_data); 45 callback_1_0_(sample_buffer, buffer_size_in_bytes, user_data);
46 } else { 46 } else {
47 NOTREACHED(); 47 NOTREACHED();
48 } 48 }
49 } 49 }
50 50
51 PPB_Audio_Shared::PPB_Audio_Shared() 51 PPB_Audio_Shared::PPB_Audio_Shared()
52 : playing_(false), 52 : playing_(false),
53 muted_for_power_saver_(false),
53 shared_memory_size_(0), 54 shared_memory_size_(0),
55 nacl_thread_id_(0),
54 nacl_thread_active_(false), 56 nacl_thread_active_(false),
55 user_data_(NULL), 57 user_data_(NULL),
56 client_buffer_size_bytes_(0), 58 client_buffer_size_bytes_(0),
57 bytes_per_second_(0), 59 bytes_per_second_(0),
58 buffer_index_(0) { 60 buffer_index_(0) {
59 } 61 }
60 62
61 PPB_Audio_Shared::~PPB_Audio_Shared() { 63 PPB_Audio_Shared::~PPB_Audio_Shared() {
62 // Shut down the socket to escape any hanging |Receive|s. 64 // Shut down the socket to escape any hanging |Receive|s.
63 if (socket_.get()) 65 if (socket_.get())
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 g_nacl_mode = true; 192 g_nacl_mode = true;
191 } 193 }
192 194
193 // static 195 // static
194 void PPB_Audio_Shared::SetThreadFunctions( 196 void PPB_Audio_Shared::SetThreadFunctions(
195 const struct PP_ThreadFunctions* functions) { 197 const struct PP_ThreadFunctions* functions) {
196 DCHECK(g_nacl_mode); 198 DCHECK(g_nacl_mode);
197 g_thread_functions = *functions; 199 g_thread_functions = *functions;
198 } 200 }
199 201
202 void PPB_Audio_Shared::SetMutedForPowerSaver(bool muted_for_power_saver) {
203 base::AutoLock lock(mute_lock_);
204 muted_for_power_saver_ = muted_for_power_saver;
205 }
206
207 bool PPB_Audio_Shared::IsMutedForPowerSaver() {
208 base::AutoLock lock(mute_lock_);
209 return muted_for_power_saver_;
210 }
211
200 // static 212 // static
201 void PPB_Audio_Shared::CallRun(void* self) { 213 void PPB_Audio_Shared::CallRun(void* self) {
202 PPB_Audio_Shared* audio = static_cast<PPB_Audio_Shared*>(self); 214 PPB_Audio_Shared* audio = static_cast<PPB_Audio_Shared*>(self);
203 audio->Run(); 215 audio->Run();
204 } 216 }
205 217
206 void PPB_Audio_Shared::Run() { 218 void PPB_Audio_Shared::Run() {
207 int pending_data = 0; 219 int pending_data = 0;
208 while (sizeof(pending_data) == 220 while (sizeof(pending_data) ==
209 socket_->Receive(&pending_data, sizeof(pending_data))) { 221 socket_->Receive(&pending_data, sizeof(pending_data))) {
210 // |buffer_index_| must track the number of Receive() calls. See the Send() 222 // |buffer_index_| must track the number of Receive() calls. See the Send()
211 // call below for why this is important. 223 // call below for why this is important.
212 ++buffer_index_; 224 ++buffer_index_;
213 if (pending_data < 0) 225 if (pending_data < 0)
214 break; 226 break;
215 227
216 { 228 {
217 TRACE_EVENT0("audio", "PPB_Audio_Shared::FireRenderCallback"); 229 TRACE_EVENT0("audio", "PPB_Audio_Shared::FireRenderCallback");
218 PP_TimeDelta latency = 230 PP_TimeDelta latency =
219 static_cast<double>(pending_data) / bytes_per_second_; 231 static_cast<double>(pending_data) / bytes_per_second_;
220 callback_.Run( 232 callback_.Run(
221 client_buffer_.get(), client_buffer_size_bytes_, latency, user_data_); 233 client_buffer_.get(), client_buffer_size_bytes_, latency, user_data_);
222 } 234 }
223 235
236 if (IsMutedForPowerSaver()) {
tommycli 2015/01/28 20:41:24 This doesn't actually work! As far as I can tell,
237 memset(client_buffer_.get(), 0, client_buffer_size_bytes_);
238 }
239
224 // Deinterleave the audio data into the shared memory as floats. 240 // Deinterleave the audio data into the shared memory as floats.
225 audio_bus_->FromInterleaved(client_buffer_.get(), 241 audio_bus_->FromInterleaved(client_buffer_.get(),
226 audio_bus_->frames(), 242 audio_bus_->frames(),
227 kBitsPerAudioOutputSample / 8); 243 kBitsPerAudioOutputSample / 8);
228 244
229 // Let the other end know which buffer we just filled. The buffer index is 245 // Let the other end know which buffer we just filled. The buffer index is
230 // used to ensure the other end is getting the buffer it expects. For more 246 // used to ensure the other end is getting the buffer it expects. For more
231 // details on how this works see AudioSyncReader::WaitUntilDataIsReady(). 247 // details on how this works see AudioSyncReader::WaitUntilDataIsReady().
232 size_t bytes_sent = socket_->Send(&buffer_index_, sizeof(buffer_index_)); 248 size_t bytes_sent = socket_->Send(&buffer_index_, sizeof(buffer_index_));
233 if (bytes_sent != sizeof(buffer_index_)) 249 if (bytes_sent != sizeof(buffer_index_))
234 break; 250 break;
235 } 251 }
236 } 252 }
237 253
238 } // namespace ppapi 254 } // namespace ppapi
OLDNEW
« ppapi/shared_impl/ppb_audio_shared.h ('K') | « ppapi/shared_impl/ppb_audio_shared.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698