| 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_PLUGINS_PPAPI_DEVICE_CONTEXT_AUDIO_H_ |
| 6 #define WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_AUDIO_H_ | 6 #define WEBKIT_PLUGINS_PPAPI_DEVICE_CONTEXT_AUDIO_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" |
| 8 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
| 9 #include "base/shared_memory.h" | 10 #include "base/shared_memory.h" |
| 10 #include "base/sync_socket.h" | 11 #include "base/sync_socket.h" |
| 11 #include "ppapi/c/dev/ppb_audio_dev.h" | 12 #include "ppapi/c/dev/ppb_audio_dev.h" |
| 12 #include "ppapi/c/dev/ppb_audio_config_dev.h" | 13 #include "ppapi/c/dev/ppb_audio_config_dev.h" |
| 13 #include "ppapi/c/dev/ppb_audio_trusted_dev.h" | 14 #include "ppapi/c/dev/ppb_audio_trusted_dev.h" |
| 14 #include "ppapi/c/pp_completion_callback.h" | 15 #include "ppapi/c/pp_completion_callback.h" |
| 15 #include "ppapi/shared_impl/audio_impl.h" | 16 #include "ppapi/shared_impl/audio_impl.h" |
| 16 #include "webkit/glue/plugins/pepper_plugin_delegate.h" | 17 #include "webkit/plugins/ppapi/plugin_delegate.h" |
| 17 #include "webkit/glue/plugins/pepper_plugin_instance.h" | 18 #include "webkit/plugins/ppapi/plugin_instance.h" |
| 18 #include "webkit/glue/plugins/pepper_plugin_module.h" | 19 #include "webkit/plugins/ppapi/plugin_module.h" |
| 19 #include "webkit/glue/plugins/pepper_resource.h" | 20 #include "webkit/plugins/ppapi/resource.h" |
| 20 | 21 |
| 21 namespace pepper { | 22 namespace webkit { |
| 23 namespace ppapi { |
| 22 | 24 |
| 23 class PluginInstance; | 25 class PluginInstance; |
| 24 class PluginModule; | 26 class PluginModule; |
| 25 | 27 |
| 26 class AudioConfig : public Resource { | 28 class PPB_AudioConfig_Impl : public Resource { |
| 27 public: | 29 public: |
| 28 AudioConfig(PluginModule* module, | 30 PPB_AudioConfig_Impl(PluginModule* module, |
| 29 PP_AudioSampleRate_Dev sample_rate, | 31 PP_AudioSampleRate_Dev sample_rate, |
| 30 uint32_t sample_frame_count); | 32 uint32_t sample_frame_count); |
| 31 size_t BufferSize(); | 33 size_t BufferSize(); |
| 32 static const PPB_AudioConfig_Dev* GetInterface(); | 34 static const PPB_AudioConfig_Dev* GetInterface(); |
| 33 | 35 |
| 34 PP_AudioSampleRate_Dev sample_rate() { return sample_rate_; } | 36 PP_AudioSampleRate_Dev sample_rate() { return sample_rate_; } |
| 35 uint32_t sample_frame_count() { return sample_frame_count_; } | 37 uint32_t sample_frame_count() { return sample_frame_count_; } |
| 36 | 38 |
| 37 private: | 39 private: |
| 38 // Resource override. | 40 // Resource override. |
| 39 virtual AudioConfig* AsAudioConfig(); | 41 virtual PPB_AudioConfig_Impl* AsPPB_AudioConfig_Impl(); |
| 40 | 42 |
| 41 PP_AudioSampleRate_Dev sample_rate_; | 43 PP_AudioSampleRate_Dev sample_rate_; |
| 42 uint32_t sample_frame_count_; | 44 uint32_t sample_frame_count_; |
| 43 }; | 45 }; |
| 44 | 46 |
| 45 // Some of the backend functionality of this class is implemented by the | 47 // Some of the backend functionality of this class is implemented by the |
| 46 // AudioImpl so it can be shared with the proxy. | 48 // AudioImpl so it can be shared with the proxy. |
| 47 class Audio : public Resource, | 49 class PPB_Audio_Impl : public Resource, |
| 48 public pp::shared_impl::AudioImpl, | 50 public pp::shared_impl::AudioImpl, |
| 49 public PluginDelegate::PlatformAudio::Client { | 51 public PluginDelegate::PlatformAudio::Client { |
| 50 public: | 52 public: |
| 51 explicit Audio(PluginModule* module, PP_Instance instance_id); | 53 explicit PPB_Audio_Impl(PluginModule* module, PP_Instance instance_id); |
| 52 virtual ~Audio(); | 54 virtual ~PPB_Audio_Impl(); |
| 53 | 55 |
| 54 static const PPB_Audio_Dev* GetInterface(); | 56 static const PPB_Audio_Dev* GetInterface(); |
| 55 static const PPB_AudioTrusted_Dev* GetTrustedInterface(); | 57 static const PPB_AudioTrusted_Dev* GetTrustedInterface(); |
| 56 | 58 |
| 57 PP_Instance pp_instance() { | 59 PP_Instance pp_instance() { |
| 58 return pp_instance_; | 60 return pp_instance_; |
| 59 } | 61 } |
| 60 | 62 |
| 61 // PPB_Audio implementation. | 63 // PPB_Audio implementation. |
| 62 bool Init(PluginDelegate* plugin_delegate, | 64 bool Init(PluginDelegate* plugin_delegate, |
| 63 PP_Resource config_id, | 65 PP_Resource config_id, |
| 64 PPB_Audio_Callback user_callback, void* user_data); | 66 PPB_Audio_Callback user_callback, void* user_data); |
| 65 PP_Resource GetCurrentConfig(); | 67 PP_Resource GetCurrentConfig(); |
| 66 bool StartPlayback(); | 68 bool StartPlayback(); |
| 67 bool StopPlayback(); | 69 bool StopPlayback(); |
| 68 | 70 |
| 69 // PPB_Audio_Trusted implementation. | 71 // PPB_Audio_Trusted implementation. |
| 70 int32_t Open(PluginDelegate* plugin_delegate, | 72 int32_t Open(PluginDelegate* plugin_delegate, |
| 71 PP_Resource config_id, | 73 PP_Resource config_id, |
| 72 PP_CompletionCallback create_callback); | 74 PP_CompletionCallback create_callback); |
| 73 int32_t GetSyncSocket(int* sync_socket); | 75 int32_t GetSyncSocket(int* sync_socket); |
| 74 int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size); | 76 int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size); |
| 75 | 77 |
| 76 // Resource override. | 78 // Resource override. |
| 77 virtual Audio* AsAudio(); | 79 virtual PPB_Audio_Impl* AsPPB_Audio_Impl(); |
| 78 | 80 |
| 79 private: | 81 private: |
| 80 // pepper::PluginDelegate::PlatformAudio::Client implementation. | 82 // PluginDelegate::PlatformAudio::Client implementation. |
| 81 virtual void StreamCreated(base::SharedMemoryHandle shared_memory_handle, | 83 virtual void StreamCreated(base::SharedMemoryHandle shared_memory_handle, |
| 82 size_t shared_memory_size_, | 84 size_t shared_memory_size_, |
| 83 base::SyncSocket::Handle socket); | 85 base::SyncSocket::Handle socket); |
| 84 | 86 |
| 85 // AudioConfig used for creating this Audio object. | 87 // AudioConfig used for creating this Audio object. |
| 86 scoped_refptr<AudioConfig> config_; | 88 scoped_refptr<PPB_AudioConfig_Impl> config_; |
| 87 | 89 |
| 88 // Plugin instance that owns this audio object. | 90 // Plugin instance that owns this audio object. |
| 89 PP_Instance pp_instance_; | 91 PP_Instance pp_instance_; |
| 90 | 92 |
| 91 // PluginDelegate audio object that we delegate audio IPC through. | 93 // PluginDelegate audio object that we delegate audio IPC through. |
| 92 PluginDelegate::PlatformAudio* audio_; | 94 PluginDelegate::PlatformAudio* audio_; |
| 93 | 95 |
| 94 // Is a create callback pending to fire? | 96 // Is a create callback pending to fire? |
| 95 bool create_callback_pending_; | 97 bool create_callback_pending_; |
| 96 | 98 |
| 97 // Trusted callback invoked from StreamCreated. | 99 // Trusted callback invoked from StreamCreated. |
| 98 PP_CompletionCallback create_callback_; | 100 PP_CompletionCallback create_callback_; |
| 99 | 101 |
| 100 // When a create callback is being issued, these will save the info for | 102 // When a create callback is being issued, these will save the info for |
| 101 // querying from the callback. The proxy uses this to get the handles to the | 103 // querying from the callback. The proxy uses this to get the handles to the |
| 102 // other process instead of mapping them in the renderer. These will be | 104 // other process instead of mapping them in the renderer. These will be |
| 103 // invalid all other times. | 105 // invalid all other times. |
| 104 scoped_ptr<base::SharedMemory> shared_memory_for_create_callback_; | 106 scoped_ptr<base::SharedMemory> shared_memory_for_create_callback_; |
| 105 size_t shared_memory_size_for_create_callback_; | 107 size_t shared_memory_size_for_create_callback_; |
| 106 scoped_ptr<base::SyncSocket> socket_for_create_callback_; | 108 scoped_ptr<base::SyncSocket> socket_for_create_callback_; |
| 109 |
| 110 DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Impl); |
| 107 }; | 111 }; |
| 108 | 112 |
| 109 } // namespace pepper | 113 } // namespace ppapi |
| 114 } // namespace webkit |
| 110 | 115 |
| 111 #endif // WEBKIT_GLUE_PLUGINS_PEPPER_DEVICE_CONTEXT_AUDIO_H_ | 116 #endif // WEBKIT_PLUGINS_PPAPI_DEVICE_CONTEXT_AUDIO_H_ |
| OLD | NEW |