| 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/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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 | 70 |
| 73 // Sets the shared memory and socket handles. This will automatically start | 71 // Sets the shared memory and socket handles. This will automatically start |
| 74 // playback if we're currently set to play. | 72 // playback if we're currently set to play. |
| 75 void SetStreamInfo(PP_Instance instance, | 73 void SetStreamInfo(PP_Instance instance, |
| 76 base::SharedMemoryHandle shared_memory_handle, | 74 base::SharedMemoryHandle shared_memory_handle, |
| 77 size_t shared_memory_size, | 75 size_t shared_memory_size, |
| 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 #if defined(OS_NACL) | |
| 83 // NaCl has a special API for IRT code to create threads that can call back | 80 // NaCl has a special API for IRT code to create threads that can call back |
| 84 // into user code. | 81 // into user code. |
| 85 static void SetThreadFunctions(const struct PP_ThreadFunctions* functions); | 82 static void SetThreadFunctions(const struct PP_ThreadFunctions* functions); |
| 86 #endif | |
| 87 | 83 |
| 88 private: | 84 private: |
| 89 // Starts execution of the audio thread. | 85 // Starts execution of the audio thread. |
| 90 void StartThread(); | 86 void StartThread(); |
| 91 | 87 |
| 92 // Stop execution of the audio thread. | 88 // Stop execution of the audio thread. |
| 93 void StopThread(); | 89 void StopThread(); |
| 94 | 90 |
| 95 // DelegateSimpleThread::Delegate implementation. Run on the audio thread. | 91 // DelegateSimpleThread::Delegate implementation. Run on the audio thread. |
| 96 virtual void Run(); | 92 virtual void Run(); |
| 97 | 93 |
| 98 // True if playing the stream. | 94 // True if playing the stream. |
| 99 bool playing_; | 95 bool playing_; |
| 100 | 96 |
| 101 // Socket used to notify us when audio is ready to accept new samples. This | 97 // Socket used to notify us when audio is ready to accept new samples. This |
| 102 // pointer is created in StreamCreated(). | 98 // pointer is created in StreamCreated(). |
| 103 scoped_ptr<base::CancelableSyncSocket> socket_; | 99 scoped_ptr<base::CancelableSyncSocket> socket_; |
| 104 | 100 |
| 105 // Sample buffer in shared memory. This pointer is created in | 101 // Sample buffer in shared memory. This pointer is created in |
| 106 // StreamCreated(). The memory is only mapped when the audio thread is | 102 // StreamCreated(). The memory is only mapped when the audio thread is |
| 107 // created. | 103 // created. |
| 108 scoped_ptr<base::SharedMemory> shared_memory_; | 104 scoped_ptr<base::SharedMemory> shared_memory_; |
| 109 | 105 |
| 110 // The size of the sample buffer in bytes. | 106 // The size of the sample buffer in bytes. |
| 111 size_t shared_memory_size_; | 107 size_t shared_memory_size_; |
| 112 | 108 |
| 113 #if !defined(OS_NACL) | 109 #if !defined(OS_NACL) |
| 114 // When the callback is set, this thread is spawned for calling it. | 110 // When the callback is set, this thread is spawned for calling it. |
| 115 scoped_ptr<base::DelegateSimpleThread> audio_thread_; | 111 scoped_ptr<base::DelegateSimpleThread> audio_thread_; |
| 116 #else | 112 #endif |
| 117 uintptr_t thread_id_; | 113 uintptr_t thread_id_; |
| 118 bool thread_active_; | 114 bool thread_active_; |
| 119 | 115 |
| 120 static void CallRun(void* self); | 116 static void CallRun(void* self); |
| 121 #endif | |
| 122 | 117 |
| 123 // Callback to call when audio is ready to accept new samples. | 118 // Callback to call when audio is ready to accept new samples. |
| 124 AudioCallbackCombined callback_; | 119 AudioCallbackCombined callback_; |
| 125 | 120 |
| 126 // User data pointer passed verbatim to the callback function. | 121 // User data pointer passed verbatim to the callback function. |
| 127 void* user_data_; | 122 void* user_data_; |
| 128 | 123 |
| 129 // AudioBus for shuttling data across the shared memory. | 124 // AudioBus for shuttling data across the shared memory. |
| 130 scoped_ptr<media::AudioBus> audio_bus_; | 125 scoped_ptr<media::AudioBus> audio_bus_; |
| 131 | 126 |
| 132 // Internal buffer for client's integer audio data. | 127 // Internal buffer for client's integer audio data. |
| 133 int client_buffer_size_bytes_; | 128 int client_buffer_size_bytes_; |
| 134 scoped_ptr<uint8_t[]> client_buffer_; | 129 scoped_ptr<uint8_t[]> client_buffer_; |
| 135 | 130 |
| 136 // The size (in bytes) of one second of audio data. Used to calculate latency. | 131 // The size (in bytes) of one second of audio data. Used to calculate latency. |
| 137 size_t bytes_per_second_; | 132 size_t bytes_per_second_; |
| 138 | 133 |
| 139 // Buffer index used to coordinate with the browser side audio receiver. | 134 // Buffer index used to coordinate with the browser side audio receiver. |
| 140 uint32_t buffer_index_; | 135 uint32_t buffer_index_; |
| 141 | 136 |
| 142 DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Shared); | 137 DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Shared); |
| 143 }; | 138 }; |
| 144 | 139 |
| 145 } // namespace ppapi | 140 } // namespace ppapi |
| 146 | 141 |
| 147 #endif // PPAPI_SHARED_IMPL_PPB_AUDIO_SHARED_H_ | 142 #endif // PPAPI_SHARED_IMPL_PPB_AUDIO_SHARED_H_ |
| OLD | NEW |