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/threading/simple_thread.h" | 11 #include "base/threading/simple_thread.h" |
| 12 #include "media/base/audio_bus.h" | 12 #include "media/base/audio_bus.h" |
| 13 #include "ppapi/c/ppb_audio.h" | 13 #include "ppapi/c/ppb_audio.h" |
| 14 #include "ppapi/c/ppb_audio_config.h" | 14 #include "ppapi/c/ppb_audio_config.h" |
| 15 #include "ppapi/shared_impl/resource.h" | 15 #include "ppapi/shared_impl/resource.h" |
| 16 #include "ppapi/thunk/ppb_audio_api.h" | 16 #include "ppapi/thunk/ppb_audio_api.h" |
| 17 | 17 |
| 18 #if defined(OS_NACL) | 18 struct PP_ThreadFunctions; |
| 19 #include "ppapi/nacl_irt/public/irt_ppapi.h" | |
| 20 #endif | |
| 21 | 19 |
| 22 namespace ppapi { | 20 namespace ppapi { |
| 23 | 21 |
| 24 class PPAPI_SHARED_EXPORT AudioCallbackCombined { | 22 class PPAPI_SHARED_EXPORT AudioCallbackCombined { |
| 25 public: | 23 public: |
| 26 AudioCallbackCombined(); | 24 AudioCallbackCombined(); |
| 27 explicit AudioCallbackCombined(PPB_Audio_Callback_1_0 callback_1_0); | 25 explicit AudioCallbackCombined(PPB_Audio_Callback_1_0 callback_1_0); |
| 28 explicit AudioCallbackCombined(PPB_Audio_Callback callback); | 26 explicit AudioCallbackCombined(PPB_Audio_Callback callback); |
| 29 | 27 |
| 30 ~AudioCallbackCombined(); | 28 ~AudioCallbackCombined(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 78 base::SyncSocket::Handle socket_handle, | 76 base::SyncSocket::Handle socket_handle, |
| 79 PP_AudioSampleRate sample_rate, | 77 PP_AudioSampleRate sample_rate, |
| 80 int sample_frame_count); | 78 int sample_frame_count); |
| 81 | 79 |
| 82 // Returns whether a thread can be created on the client context. | 80 // Returns whether a thread can be created on the client context. |
| 83 // In trusted plugin, this should always return true, as it uses Chrome's | 81 // In trusted plugin, this should always return true, as it uses Chrome's |
| 84 // thread library. In NaCl plugin, this returns whether SetThreadFunctions | 82 // thread library. In NaCl plugin, this returns whether SetThreadFunctions |
| 85 // was invoked properly. | 83 // was invoked properly. |
| 86 static bool IsThreadFunctionReady(); | 84 static bool IsThreadFunctionReady(); |
| 87 | 85 |
| 88 #if defined(OS_NACL) | 86 // Sets whether this class is used for NaCl plugin. |
| 87 // If this is set to true, SetThreadFunctions() must be called before | |
| 88 // this class is used. | |
| 89 static void SetNaClMode(bool value); | |
|
bbudge
2014/04/21 17:01:51
Would it ever make sense for this to be called wit
hidehiko
2014/04/21 17:25:56
I see. Done.
| |
| 90 | |
| 89 // NaCl has a special API for IRT code to create threads that can call back | 91 // NaCl has a special API for IRT code to create threads that can call back |
| 90 // into user code. | 92 // into user code. |
| 91 static void SetThreadFunctions(const struct PP_ThreadFunctions* functions); | 93 static void SetThreadFunctions(const struct PP_ThreadFunctions* functions); |
| 92 #endif | |
| 93 | 94 |
| 94 private: | 95 private: |
| 95 // Starts execution of the audio thread. | 96 // Starts execution of the audio thread. |
| 96 void StartThread(); | 97 void StartThread(); |
| 97 | 98 |
| 98 // Stop execution of the audio thread. | 99 // Stop execution of the audio thread. |
| 99 void StopThread(); | 100 void StopThread(); |
| 100 | 101 |
| 101 // DelegateSimpleThread::Delegate implementation. Run on the audio thread. | 102 // DelegateSimpleThread::Delegate implementation. Run on the audio thread. |
| 102 virtual void Run(); | 103 virtual void Run(); |
| 103 | 104 |
| 104 // True if playing the stream. | 105 // True if playing the stream. |
| 105 bool playing_; | 106 bool playing_; |
| 106 | 107 |
| 107 // Socket used to notify us when audio is ready to accept new samples. This | 108 // Socket used to notify us when audio is ready to accept new samples. This |
| 108 // pointer is created in StreamCreated(). | 109 // pointer is created in StreamCreated(). |
| 109 scoped_ptr<base::CancelableSyncSocket> socket_; | 110 scoped_ptr<base::CancelableSyncSocket> socket_; |
| 110 | 111 |
| 111 // Sample buffer in shared memory. This pointer is created in | 112 // Sample buffer in shared memory. This pointer is created in |
| 112 // StreamCreated(). The memory is only mapped when the audio thread is | 113 // StreamCreated(). The memory is only mapped when the audio thread is |
| 113 // created. | 114 // created. |
| 114 scoped_ptr<base::SharedMemory> shared_memory_; | 115 scoped_ptr<base::SharedMemory> shared_memory_; |
| 115 | 116 |
| 116 // The size of the sample buffer in bytes. | 117 // The size of the sample buffer in bytes. |
| 117 size_t shared_memory_size_; | 118 size_t shared_memory_size_; |
| 118 | 119 |
| 119 #if !defined(OS_NACL) | |
| 120 // When the callback is set, this thread is spawned for calling it. | 120 // When the callback is set, this thread is spawned for calling it. |
| 121 scoped_ptr<base::DelegateSimpleThread> audio_thread_; | 121 scoped_ptr<base::DelegateSimpleThread> audio_thread_; |
| 122 #else | |
| 123 uintptr_t thread_id_; | 122 uintptr_t thread_id_; |
| 124 bool thread_active_; | 123 bool thread_active_; |
| 125 | 124 |
| 126 static void CallRun(void* self); | 125 static void CallRun(void* self); |
| 127 #endif | |
| 128 | 126 |
| 129 // Callback to call when audio is ready to accept new samples. | 127 // Callback to call when audio is ready to accept new samples. |
| 130 AudioCallbackCombined callback_; | 128 AudioCallbackCombined callback_; |
| 131 | 129 |
| 132 // User data pointer passed verbatim to the callback function. | 130 // User data pointer passed verbatim to the callback function. |
| 133 void* user_data_; | 131 void* user_data_; |
| 134 | 132 |
| 135 // AudioBus for shuttling data across the shared memory. | 133 // AudioBus for shuttling data across the shared memory. |
| 136 scoped_ptr<media::AudioBus> audio_bus_; | 134 scoped_ptr<media::AudioBus> audio_bus_; |
| 137 | 135 |
| 138 // Internal buffer for client's integer audio data. | 136 // Internal buffer for client's integer audio data. |
| 139 int client_buffer_size_bytes_; | 137 int client_buffer_size_bytes_; |
| 140 scoped_ptr<uint8_t[]> client_buffer_; | 138 scoped_ptr<uint8_t[]> client_buffer_; |
| 141 | 139 |
| 142 // The size (in bytes) of one second of audio data. Used to calculate latency. | 140 // The size (in bytes) of one second of audio data. Used to calculate latency. |
| 143 size_t bytes_per_second_; | 141 size_t bytes_per_second_; |
| 144 | 142 |
| 145 // Buffer index used to coordinate with the browser side audio receiver. | 143 // Buffer index used to coordinate with the browser side audio receiver. |
| 146 uint32_t buffer_index_; | 144 uint32_t buffer_index_; |
| 147 | 145 |
| 148 DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Shared); | 146 DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Shared); |
| 149 }; | 147 }; |
| 150 | 148 |
| 151 } // namespace ppapi | 149 } // namespace ppapi |
| 152 | 150 |
| 153 #endif // PPAPI_SHARED_IMPL_PPB_AUDIO_SHARED_H_ | 151 #endif // PPAPI_SHARED_IMPL_PPB_AUDIO_SHARED_H_ |
| OLD | NEW |