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 the mode that this class is used for NaCl plugin. |
87 // If set, SetThreadFunctions() must be called before this class is used. | |
88 static void SetNaClMode(); | |
89 | |
89 // NaCl has a special API for IRT code to create threads that can call back | 90 // NaCl has a special API for IRT code to create threads that can call back |
90 // into user code. | 91 // into user code. |
91 static void SetThreadFunctions(const struct PP_ThreadFunctions* functions); | 92 static void SetThreadFunctions(const struct PP_ThreadFunctions* functions); |
92 #endif | |
93 | 93 |
94 private: | 94 private: |
95 // Starts execution of the audio thread. | 95 // Starts execution of the audio thread. |
96 void StartThread(); | 96 void StartThread(); |
97 | 97 |
98 // Stop execution of the audio thread. | 98 // Stop execution of the audio thread. |
99 void StopThread(); | 99 void StopThread(); |
100 | 100 |
101 // DelegateSimpleThread::Delegate implementation. Run on the audio thread. | 101 // DelegateSimpleThread::Delegate implementation. Run on the audio thread. |
102 virtual void Run(); | 102 virtual void Run(); |
103 | 103 |
104 // True if playing the stream. | 104 // True if playing the stream. |
105 bool playing_; | 105 bool playing_; |
106 | 106 |
107 // Socket used to notify us when audio is ready to accept new samples. This | 107 // Socket used to notify us when audio is ready to accept new samples. This |
108 // pointer is created in StreamCreated(). | 108 // pointer is created in StreamCreated(). |
109 scoped_ptr<base::CancelableSyncSocket> socket_; | 109 scoped_ptr<base::CancelableSyncSocket> socket_; |
110 | 110 |
111 // Sample buffer in shared memory. This pointer is created in | 111 // Sample buffer in shared memory. This pointer is created in |
112 // StreamCreated(). The memory is only mapped when the audio thread is | 112 // StreamCreated(). The memory is only mapped when the audio thread is |
113 // created. | 113 // created. |
114 scoped_ptr<base::SharedMemory> shared_memory_; | 114 scoped_ptr<base::SharedMemory> shared_memory_; |
115 | 115 |
116 // The size of the sample buffer in bytes. | 116 // The size of the sample buffer in bytes. |
117 size_t shared_memory_size_; | 117 size_t shared_memory_size_; |
118 | 118 |
119 #if !defined(OS_NACL) | |
120 // When the callback is set, this thread is spawned for calling it. | 119 // When the callback is set, this thread is spawned for calling it. |
121 scoped_ptr<base::DelegateSimpleThread> audio_thread_; | 120 scoped_ptr<base::DelegateSimpleThread> audio_thread_; |
122 #else | |
123 uintptr_t thread_id_; | 121 uintptr_t thread_id_; |
124 bool thread_active_; | 122 bool thread_active_; |
bbudge
2014/04/21 20:20:29
Suggestion: rename these nacl_thread_id_ and nacl_
hidehiko
2014/04/21 22:59:47
Done.
| |
125 | 123 |
126 static void CallRun(void* self); | 124 static void CallRun(void* self); |
127 #endif | |
128 | 125 |
129 // Callback to call when audio is ready to accept new samples. | 126 // Callback to call when audio is ready to accept new samples. |
130 AudioCallbackCombined callback_; | 127 AudioCallbackCombined callback_; |
131 | 128 |
132 // User data pointer passed verbatim to the callback function. | 129 // User data pointer passed verbatim to the callback function. |
133 void* user_data_; | 130 void* user_data_; |
134 | 131 |
135 // AudioBus for shuttling data across the shared memory. | 132 // AudioBus for shuttling data across the shared memory. |
136 scoped_ptr<media::AudioBus> audio_bus_; | 133 scoped_ptr<media::AudioBus> audio_bus_; |
137 | 134 |
138 // Internal buffer for client's integer audio data. | 135 // Internal buffer for client's integer audio data. |
139 int client_buffer_size_bytes_; | 136 int client_buffer_size_bytes_; |
140 scoped_ptr<uint8_t[]> client_buffer_; | 137 scoped_ptr<uint8_t[]> client_buffer_; |
141 | 138 |
142 // The size (in bytes) of one second of audio data. Used to calculate latency. | 139 // The size (in bytes) of one second of audio data. Used to calculate latency. |
143 size_t bytes_per_second_; | 140 size_t bytes_per_second_; |
144 | 141 |
145 // Buffer index used to coordinate with the browser side audio receiver. | 142 // Buffer index used to coordinate with the browser side audio receiver. |
146 uint32_t buffer_index_; | 143 uint32_t buffer_index_; |
147 | 144 |
148 DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Shared); | 145 DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Shared); |
149 }; | 146 }; |
150 | 147 |
151 } // namespace ppapi | 148 } // namespace ppapi |
152 | 149 |
153 #endif // PPAPI_SHARED_IMPL_PPB_AUDIO_SHARED_H_ | 150 #endif // PPAPI_SHARED_IMPL_PPB_AUDIO_SHARED_H_ |
OLD | NEW |