| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_AUDIO_H_ | 5 #ifndef WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_AUDIO_H_ |
| 6 #define WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_AUDIO_H_ | 6 #define WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_AUDIO_H_ |
| 7 | 7 |
| 8 #include "base/ref_counted.h" | 8 #include "base/ref_counted.h" |
| 9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 10 #include "base/shared_memory.h" | 10 #include "base/shared_memory.h" |
| 11 #include "base/simple_thread.h" | 11 #include "base/simple_thread.h" |
| 12 #include "base/sync_socket.h" | 12 #include "base/sync_socket.h" |
| 13 #include "ppapi/c/dev/ppb_audio_dev.h" | 13 #include "ppapi/c/dev/ppb_audio_dev.h" |
| 14 #include "ppapi/c/dev/ppb_audio_config_dev.h" | 14 #include "ppapi/c/dev/ppb_audio_config_dev.h" |
| 15 #include "ppapi/c/dev/ppb_audio_trusted_dev.h" | 15 #include "ppapi/c/dev/ppb_audio_trusted_dev.h" |
| 16 #include "ppapi/c/pp_completion_callback.h" |
| 16 #include "webkit/glue/plugins/pepper_plugin_delegate.h" | 17 #include "webkit/glue/plugins/pepper_plugin_delegate.h" |
| 17 #include "webkit/glue/plugins/pepper_plugin_instance.h" | 18 #include "webkit/glue/plugins/pepper_plugin_instance.h" |
| 18 #include "webkit/glue/plugins/pepper_plugin_module.h" | 19 #include "webkit/glue/plugins/pepper_plugin_module.h" |
| 19 #include "webkit/glue/plugins/pepper_resource.h" | 20 #include "webkit/glue/plugins/pepper_resource.h" |
| 20 | 21 |
| 21 namespace pepper { | 22 namespace pepper { |
| 22 | 23 |
| 23 class PluginInstance; | 24 class PluginInstance; |
| 24 class PluginModule; | 25 class PluginModule; |
| 25 | 26 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 39 virtual AudioConfig* AsAudioConfig(); | 40 virtual AudioConfig* AsAudioConfig(); |
| 40 | 41 |
| 41 PP_AudioSampleRate_Dev sample_rate_; | 42 PP_AudioSampleRate_Dev sample_rate_; |
| 42 uint32_t sample_frame_count_; | 43 uint32_t sample_frame_count_; |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 class Audio : public Resource, | 46 class Audio : public Resource, |
| 46 public PluginDelegate::PlatformAudio::Client, | 47 public PluginDelegate::PlatformAudio::Client, |
| 47 public base::DelegateSimpleThread::Delegate { | 48 public base::DelegateSimpleThread::Delegate { |
| 48 public: | 49 public: |
| 49 explicit Audio(PluginModule* module); | 50 explicit Audio(PluginModule* module, PP_Instance instance_id); |
| 50 virtual ~Audio(); | 51 virtual ~Audio(); |
| 51 | 52 |
| 52 static const PPB_Audio_Dev* GetInterface(); | 53 static const PPB_Audio_Dev* GetInterface(); |
| 53 static const PPB_AudioTrusted_Dev* GetTrustedInterface(); | 54 static const PPB_AudioTrusted_Dev* GetTrustedInterface(); |
| 54 | 55 |
| 55 bool Init(PluginDelegate* plugin_delegate, PP_Resource config_id, | 56 bool Init(PluginDelegate* plugin_delegate, |
| 56 PPB_Audio_Callback callback, void* user_data); | 57 PP_Resource config_id, |
| 58 PPB_Audio_Callback user_callback, void* user_data); |
| 59 |
| 60 int32_t OpenTrusted(PluginDelegate* plugin_delegate, |
| 61 PP_Resource config_id, |
| 62 PP_CompletionCallback create_callback); |
| 57 | 63 |
| 58 PP_Resource GetCurrentConfiguration() { | 64 PP_Resource GetCurrentConfiguration() { |
| 59 return config_->GetReference(); | 65 return config_->GetReference(); |
| 60 } | 66 } |
| 61 | 67 |
| 68 PP_Instance pp_instance() { |
| 69 return pp_instance_; |
| 70 } |
| 71 |
| 72 int32_t GetSyncSocket(int* sync_socket); |
| 73 |
| 74 int32_t GetSharedMemory(int* shm_handle, int32_t* shm_size); |
| 75 |
| 62 bool StartPlayback(); | 76 bool StartPlayback(); |
| 63 | 77 |
| 64 bool StopPlayback(); | 78 bool StopPlayback(); |
| 65 | 79 |
| 66 // Resource override. | 80 // Resource override. |
| 67 virtual Audio* AsAudio(); | 81 virtual Audio* AsAudio(); |
| 68 | 82 |
| 69 private: | 83 private: |
| 70 // pepper::PluginDelegate::PlatformAudio::Client implementation. | 84 // pepper::PluginDelegate::PlatformAudio::Client implementation. |
| 71 virtual void StreamCreated(base::SharedMemoryHandle shared_memory_handle, | 85 virtual void StreamCreated(base::SharedMemoryHandle shared_memory_handle, |
| 72 size_t shared_memory_size_, | 86 size_t shared_memory_size_, |
| 73 base::SyncSocket::Handle socket); | 87 base::SyncSocket::Handle socket); |
| 74 // End of pepper::PluginDelegate::PlatformAudio::Client implementation. | 88 // End of pepper::PluginDelegate::PlatformAudio::Client implementation. |
| 75 | 89 |
| 76 // Audio thread. DelegateSimpleThread::Delegate implementation. | 90 // Audio thread. DelegateSimpleThread::Delegate implementation. |
| 77 virtual void Run(); | 91 virtual void Run(); |
| 78 // End of DelegateSimpleThread::Delegate implementation. | 92 // End of DelegateSimpleThread::Delegate implementation. |
| 79 | 93 |
| 80 // True if playing the stream. | 94 // True if playing the stream. |
| 81 bool playing_; | 95 bool playing_; |
| 82 | 96 |
| 83 // AudioConfig used for creating this Audio object. | 97 // AudioConfig used for creating this Audio object. |
| 84 scoped_refptr<AudioConfig> config_; | 98 scoped_refptr<AudioConfig> config_; |
| 85 | 99 |
| 100 // Instance id |
| 101 PP_Instance pp_instance_; |
| 102 |
| 86 // PluginDelegate audio object that we delegate audio IPC through. | 103 // PluginDelegate audio object that we delegate audio IPC through. |
| 87 scoped_ptr<PluginDelegate::PlatformAudio> audio_; | 104 PluginDelegate::PlatformAudio* audio_; |
| 88 | 105 |
| 89 // Socket used to notify us when audio is ready to accept new samples. This | 106 // Socket used to notify us when audio is ready to accept new samples. This |
| 90 // pointer is created in StreamCreated(). | 107 // pointer is created in StreamCreated(). |
| 91 scoped_ptr<base::SyncSocket> socket_; | 108 scoped_ptr<base::SyncSocket> socket_; |
| 92 | 109 |
| 93 // Sample buffer in shared memory. This pointer is created in | 110 // Sample buffer in shared memory. This pointer is created in |
| 94 // StreamCreated(). The memory is only mapped when the audio thread is | 111 // StreamCreated(). The memory is only mapped when the audio thread is |
| 95 // created. | 112 // created. |
| 96 scoped_ptr<base::SharedMemory> shared_memory_; | 113 scoped_ptr<base::SharedMemory> shared_memory_; |
| 97 | 114 |
| 98 // The size of the sample buffer in bytes. | 115 // The size of the sample buffer in bytes. |
| 99 size_t shared_memory_size_; | 116 size_t shared_memory_size_; |
| 100 | 117 |
| 101 // When the callback is set, this thread is spawned for calling it. | 118 // When the callback is set, this thread is spawned for calling it. |
| 102 scoped_ptr<base::DelegateSimpleThread> audio_thread_; | 119 scoped_ptr<base::DelegateSimpleThread> audio_thread_; |
| 103 | 120 |
| 104 // Callback to call when audio is ready to accept new samples. | 121 // Callback to call when audio is ready to accept new samples. |
| 105 volatile PPB_Audio_Callback callback_; | 122 volatile PPB_Audio_Callback callback_; |
| 106 | 123 |
| 107 // User data pointer passed verbatim to the callback function. | 124 // User data pointer passed verbatim to the callback function. |
| 108 void* user_data_; | 125 void* user_data_; |
| 126 |
| 127 // Is a create callback pending to fire? |
| 128 bool create_callback_pending_; |
| 129 |
| 130 // Trusted callback invoked from StreamCreated. |
| 131 PP_CompletionCallback create_callback_; |
| 109 }; | 132 }; |
| 110 | 133 |
| 111 } // namespace pepper | 134 } // namespace pepper |
| 112 | 135 |
| 113 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_AUDIO_H_ | 136 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_AUDIO_H_ |
| 114 | |
| OLD | NEW |