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/shared_memory.h" | 9 #include "base/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 "ppapi/c/ppb_audio.h" | 12 #include "ppapi/c/ppb_audio.h" |
13 #include "ppapi/shared_impl/resource.h" | 13 #include "ppapi/shared_impl/resource.h" |
14 #include "ppapi/thunk/ppb_audio_api.h" | 14 #include "ppapi/thunk/ppb_audio_api.h" |
15 | 15 |
| 16 #if defined(OS_NACL) |
| 17 #include "native_client/src/untrusted/irt/irt_ppapi.h" |
| 18 #endif |
| 19 |
16 namespace ppapi { | 20 namespace ppapi { |
17 | 21 |
18 // Implements the logic to map shared memory and run the audio thread signaled | 22 // Implements the logic to map shared memory and run the audio thread signaled |
19 // from the sync socket. Both the proxy and the renderer implementation use | 23 // from the sync socket. Both the proxy and the renderer implementation use |
20 // this code. | 24 // this code. |
21 class PPAPI_SHARED_EXPORT PPB_Audio_Shared | 25 class PPAPI_SHARED_EXPORT PPB_Audio_Shared |
22 : public thunk::PPB_Audio_API, | 26 : public thunk::PPB_Audio_API, |
23 public base::DelegateSimpleThread::Delegate { | 27 public base::DelegateSimpleThread::Delegate { |
24 public: | 28 public: |
25 PPB_Audio_Shared(); | 29 PPB_Audio_Shared(); |
(...skipping 21 matching lines...) Expand all Loading... |
47 void SetStartPlaybackState(); | 51 void SetStartPlaybackState(); |
48 void SetStopPlaybackState(); | 52 void SetStopPlaybackState(); |
49 | 53 |
50 // Sets the shared memory and socket handles. This will automatically start | 54 // Sets the shared memory and socket handles. This will automatically start |
51 // playback if we're currently set to play. | 55 // playback if we're currently set to play. |
52 void SetStreamInfo(PP_Instance instance, | 56 void SetStreamInfo(PP_Instance instance, |
53 base::SharedMemoryHandle shared_memory_handle, | 57 base::SharedMemoryHandle shared_memory_handle, |
54 size_t shared_memory_size, | 58 size_t shared_memory_size, |
55 base::SyncSocket::Handle socket_handle); | 59 base::SyncSocket::Handle socket_handle); |
56 | 60 |
| 61 #if defined(OS_NACL) |
| 62 // NaCl has a special API for IRT code to create threads that can call back |
| 63 // into user code. |
| 64 static void SetThreadFunctions(const struct PP_ThreadFunctions* functions); |
| 65 #endif |
57 private: | 66 private: |
58 // Starts execution of the audio thread. | 67 // Starts execution of the audio thread. |
59 void StartThread(); | 68 void StartThread(); |
60 | 69 |
61 // Stop execution of the audio thread. | 70 // Stop execution of the audio thread. |
62 void StopThread(); | 71 void StopThread(); |
63 | 72 |
64 // DelegateSimpleThread::Delegate implementation. Run on the audio thread. | 73 // DelegateSimpleThread::Delegate implementation. Run on the audio thread. |
65 virtual void Run(); | 74 virtual void Run(); |
66 | 75 |
67 // True if playing the stream. | 76 // True if playing the stream. |
68 bool playing_; | 77 bool playing_; |
69 | 78 |
70 // Socket used to notify us when audio is ready to accept new samples. This | 79 // Socket used to notify us when audio is ready to accept new samples. This |
71 // pointer is created in StreamCreated(). | 80 // pointer is created in StreamCreated(). |
72 scoped_ptr<base::CancelableSyncSocket> socket_; | 81 scoped_ptr<base::CancelableSyncSocket> socket_; |
73 | 82 |
74 // Sample buffer in shared memory. This pointer is created in | 83 // Sample buffer in shared memory. This pointer is created in |
75 // StreamCreated(). The memory is only mapped when the audio thread is | 84 // StreamCreated(). The memory is only mapped when the audio thread is |
76 // created. | 85 // created. |
77 scoped_ptr<base::SharedMemory> shared_memory_; | 86 scoped_ptr<base::SharedMemory> shared_memory_; |
78 | 87 |
79 // The size of the sample buffer in bytes. | 88 // The size of the sample buffer in bytes. |
80 size_t shared_memory_size_; | 89 size_t shared_memory_size_; |
81 | 90 |
| 91 #if !defined(OS_NACL) |
82 // When the callback is set, this thread is spawned for calling it. | 92 // When the callback is set, this thread is spawned for calling it. |
83 scoped_ptr<base::DelegateSimpleThread> audio_thread_; | 93 scoped_ptr<base::DelegateSimpleThread> audio_thread_; |
| 94 #else |
| 95 uintptr_t thread_id_; |
| 96 bool thread_active_; |
| 97 |
| 98 static void CallRun(void* self); |
| 99 #endif |
84 | 100 |
85 // Callback to call when audio is ready to accept new samples. | 101 // Callback to call when audio is ready to accept new samples. |
86 PPB_Audio_Callback callback_; | 102 PPB_Audio_Callback callback_; |
87 | 103 |
88 // User data pointer passed verbatim to the callback function. | 104 // User data pointer passed verbatim to the callback function. |
89 void* user_data_; | 105 void* user_data_; |
90 | 106 |
91 DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Shared); | 107 DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Shared); |
92 }; | 108 }; |
93 | 109 |
94 } // namespace ppapi | 110 } // namespace ppapi |
95 | 111 |
96 #endif // PPAPI_SHARED_IMPL_PPB_AUDIO_SHARED_H_ | 112 #endif // PPAPI_SHARED_IMPL_PPB_AUDIO_SHARED_H_ |
OLD | NEW |