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 #ifndef PPAPI_SHARED_IMPL_PPB_AUDIO_SHARED_H_ | 5 #ifndef PPAPI_SHARED_IMPL_PPB_AUDIO_SHARED_H_ |
| 6 #define PPAPI_SHARED_IMPL_PPB_AUDIO_SHARED_H_ | 6 #define PPAPI_SHARED_IMPL_PPB_AUDIO_SHARED_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
| 10 #include "base/sync_socket.h" | 10 #include "base/sync_socket.h" |
| 11 #include "base/synchronization/lock.h" | |
| 11 #include "base/threading/simple_thread.h" | 12 #include "base/threading/simple_thread.h" |
| 12 #include "media/base/audio_bus.h" | 13 #include "media/base/audio_bus.h" |
| 13 #include "ppapi/c/ppb_audio.h" | 14 #include "ppapi/c/ppb_audio.h" |
| 14 #include "ppapi/c/ppb_audio_config.h" | 15 #include "ppapi/c/ppb_audio_config.h" |
| 15 #include "ppapi/shared_impl/resource.h" | 16 #include "ppapi/shared_impl/resource.h" |
| 16 #include "ppapi/thunk/ppb_audio_api.h" | 17 #include "ppapi/thunk/ppb_audio_api.h" |
| 17 | 18 |
| 18 struct PP_ThreadFunctions; | 19 struct PP_ThreadFunctions; |
| 19 | 20 |
| 20 namespace ppapi { | 21 namespace ppapi { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 | 86 |
| 86 // Configures this class to run in a NaCl plugin. | 87 // Configures this class to run in a NaCl plugin. |
| 87 // If called, SetThreadFunctions() must be called before calling | 88 // If called, SetThreadFunctions() must be called before calling |
| 88 // SetStartPlaybackState() on any instance of this class. | 89 // SetStartPlaybackState() on any instance of this class. |
| 89 static void SetNaClMode(); | 90 static void SetNaClMode(); |
| 90 | 91 |
| 91 // NaCl has a special API for IRT code to create threads that can call back | 92 // NaCl has a special API for IRT code to create threads that can call back |
| 92 // into user code. | 93 // into user code. |
| 93 static void SetThreadFunctions(const struct PP_ThreadFunctions* functions); | 94 static void SetThreadFunctions(const struct PP_ThreadFunctions* functions); |
| 94 | 95 |
| 96 protected: | |
| 97 // Configures if we zero out the audio buffers after each audio callback. | |
| 98 // This is a stopgap to mute individual plugins that in power saver mode. | |
| 99 void SetMutedForPowerSaver(bool muted_for_power_saver); | |
| 100 | |
| 101 bool IsMutedForPowerSaver(); | |
| 102 | |
| 95 private: | 103 private: |
| 96 // Starts execution of the audio thread. | 104 // Starts execution of the audio thread. |
| 97 void StartThread(); | 105 void StartThread(); |
| 98 | 106 |
| 99 // Stop execution of the audio thread. | 107 // Stop execution of the audio thread. |
| 100 void StopThread(); | 108 void StopThread(); |
| 101 | 109 |
| 102 // DelegateSimpleThread::Delegate implementation. Run on the audio thread. | 110 // DelegateSimpleThread::Delegate implementation. Run on the audio thread. |
| 103 virtual void Run(); | 111 virtual void Run(); |
| 104 | 112 |
| 105 // True if playing the stream. | 113 // True if playing the stream. |
| 106 bool playing_; | 114 bool playing_; |
| 107 | 115 |
| 116 // True if we mute the stream while continuing to play it (for power saver). | |
| 117 volatile bool muted_for_power_saver_; | |
|
piman
2015/01/28 21:58:50
Why volatile?
| |
| 118 base::Lock mute_lock_; | |
| 119 | |
| 108 // Socket used to notify us when audio is ready to accept new samples. This | 120 // Socket used to notify us when audio is ready to accept new samples. This |
| 109 // pointer is created in StreamCreated(). | 121 // pointer is created in StreamCreated(). |
| 110 scoped_ptr<base::CancelableSyncSocket> socket_; | 122 scoped_ptr<base::CancelableSyncSocket> socket_; |
| 111 | 123 |
| 112 // Sample buffer in shared memory. This pointer is created in | 124 // Sample buffer in shared memory. This pointer is created in |
| 113 // StreamCreated(). The memory is only mapped when the audio thread is | 125 // StreamCreated(). The memory is only mapped when the audio thread is |
| 114 // created. | 126 // created. |
| 115 scoped_ptr<base::SharedMemory> shared_memory_; | 127 scoped_ptr<base::SharedMemory> shared_memory_; |
| 116 | 128 |
| 117 // The size of the sample buffer in bytes. | 129 // The size of the sample buffer in bytes. |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 142 | 154 |
| 143 // Buffer index used to coordinate with the browser side audio receiver. | 155 // Buffer index used to coordinate with the browser side audio receiver. |
| 144 uint32_t buffer_index_; | 156 uint32_t buffer_index_; |
| 145 | 157 |
| 146 DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Shared); | 158 DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Shared); |
| 147 }; | 159 }; |
| 148 | 160 |
| 149 } // namespace ppapi | 161 } // namespace ppapi |
| 150 | 162 |
| 151 #endif // PPAPI_SHARED_IMPL_PPB_AUDIO_SHARED_H_ | 163 #endif // PPAPI_SHARED_IMPL_PPB_AUDIO_SHARED_H_ |
| OLD | NEW |