[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 5 | #ifndef WEBKIT_PLUGINS_PPAPI_DEVICE_CONTEXT_AUDIO_H_ |
| 6 | #define WEBKIT_PLUGINS_PPAPI_DEVICE_CONTEXT_AUDIO_H_ |
[email protected] | 6f2e391 | 2010-11-05 14:45:44 | [diff] [blame] | 7 | |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 8 | #include "base/basictypes.h" |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 9 | #include "base/ref_counted.h" |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 10 | #include "base/shared_memory.h" |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 11 | #include "base/sync_socket.h" |
[email protected] | 0641727 | 2010-11-25 00:29:25 | [diff] [blame] | 12 | #include "ppapi/c/pp_completion_callback.h" |
[email protected] | b9a5984 | 2011-01-15 01:04:00 | [diff] [blame] | 13 | #include "ppapi/c/ppb_audio.h" |
| 14 | #include "ppapi/c/ppb_audio_config.h" |
| 15 | #include "ppapi/c/trusted/ppb_audio_trusted.h" |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 16 | #include "ppapi/shared_impl/audio_impl.h" |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 17 | #include "webkit/plugins/ppapi/plugin_delegate.h" |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 18 | #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 19 | #include "webkit/plugins/ppapi/resource.h" |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 20 | |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 21 | namespace webkit { |
| 22 | namespace ppapi { |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 23 | |
| 24 | class PluginInstance; |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 25 | |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 26 | class PPB_AudioConfig_Impl : public Resource { |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 27 | public: |
[email protected] | 859a7f3 | 2011-01-15 03:44:13 | [diff] [blame] | 28 | PPB_AudioConfig_Impl(PluginInstance* instance, |
[email protected] | b9a5984 | 2011-01-15 01:04:00 | [diff] [blame] | 29 | PP_AudioSampleRate sample_rate, |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 30 | uint32_t sample_frame_count); |
[email protected] | 39690e1 | 2010-10-05 21:58:45 | [diff] [blame] | 31 | size_t BufferSize(); |
[email protected] | b9a5984 | 2011-01-15 01:04:00 | [diff] [blame] | 32 | static const PPB_AudioConfig* GetInterface(); |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 33 | |
[email protected] | b9a5984 | 2011-01-15 01:04:00 | [diff] [blame] | 34 | PP_AudioSampleRate sample_rate() { return sample_rate_; } |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 35 | uint32_t sample_frame_count() { return sample_frame_count_; } |
| 36 | |
| 37 | private: |
| 38 | // Resource override. |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 39 | virtual PPB_AudioConfig_Impl* AsPPB_AudioConfig_Impl(); |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 40 | |
[email protected] | b9a5984 | 2011-01-15 01:04:00 | [diff] [blame] | 41 | PP_AudioSampleRate sample_rate_; |
[email protected] | 39690e1 | 2010-10-05 21:58:45 | [diff] [blame] | 42 | uint32_t sample_frame_count_; |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 43 | }; |
| 44 | |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 45 | // Some of the backend functionality of this class is implemented by the |
| 46 | // AudioImpl so it can be shared with the proxy. |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 47 | class PPB_Audio_Impl : public Resource, |
| 48 | public pp::shared_impl::AudioImpl, |
| 49 | public PluginDelegate::PlatformAudio::Client { |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 50 | public: |
[email protected] | 859a7f3 | 2011-01-15 03:44:13 | [diff] [blame] | 51 | explicit PPB_Audio_Impl(PluginInstance* instance); |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 52 | virtual ~PPB_Audio_Impl(); |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 53 | |
[email protected] | b9a5984 | 2011-01-15 01:04:00 | [diff] [blame] | 54 | static const PPB_Audio* GetInterface(); |
| 55 | static const PPB_AudioTrusted* GetTrustedInterface(); |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 56 | |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 57 | // PPB_Audio implementation. |
| 58 | bool Init(PluginDelegate* plugin_delegate, |
| 59 | PP_Resource config_id, |
| 60 | PPB_Audio_Callback user_callback, void* user_data); |
| 61 | PP_Resource GetCurrentConfig(); |
[email protected] | b0deb15 | 2010-08-31 17:37:35 | [diff] [blame] | 62 | bool StartPlayback(); |
[email protected] | b0deb15 | 2010-08-31 17:37:35 | [diff] [blame] | 63 | bool StopPlayback(); |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 64 | |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 65 | // PPB_Audio_Trusted implementation. |
| 66 | int32_t Open(PluginDelegate* plugin_delegate, |
| 67 | PP_Resource config_id, |
| 68 | PP_CompletionCallback create_callback); |
| 69 | int32_t GetSyncSocket(int* sync_socket); |
| 70 | int32_t GetSharedMemory(int* shm_handle, uint32_t* shm_size); |
| 71 | |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 72 | // Resource override. |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 73 | virtual PPB_Audio_Impl* AsPPB_Audio_Impl(); |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 74 | |
| 75 | private: |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 76 | // PluginDelegate::PlatformAudio::Client implementation. |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 77 | virtual void StreamCreated(base::SharedMemoryHandle shared_memory_handle, |
| 78 | size_t shared_memory_size_, |
| 79 | base::SyncSocket::Handle socket); |
[email protected] | b0deb15 | 2010-08-31 17:37:35 | [diff] [blame] | 80 | |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 81 | // AudioConfig used for creating this Audio object. |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 82 | scoped_refptr<PPB_AudioConfig_Impl> config_; |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 83 | |
[email protected] | 9ca245e | 2011-03-18 01:50:31 | [diff] [blame^] | 84 | // PluginDelegate audio object that we delegate audio IPC through. We don't |
| 85 | // own this pointer but are responsible for calling Shutdown on it. |
[email protected] | 0641727 | 2010-11-25 00:29:25 | [diff] [blame] | 86 | PluginDelegate::PlatformAudio* audio_; |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 87 | |
[email protected] | 0641727 | 2010-11-25 00:29:25 | [diff] [blame] | 88 | // Is a create callback pending to fire? |
| 89 | bool create_callback_pending_; |
| 90 | |
| 91 | // Trusted callback invoked from StreamCreated. |
| 92 | PP_CompletionCallback create_callback_; |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 93 | |
| 94 | // When a create callback is being issued, these will save the info for |
| 95 | // querying from the callback. The proxy uses this to get the handles to the |
| 96 | // other process instead of mapping them in the renderer. These will be |
| 97 | // invalid all other times. |
| 98 | scoped_ptr<base::SharedMemory> shared_memory_for_create_callback_; |
| 99 | size_t shared_memory_size_for_create_callback_; |
| 100 | scoped_ptr<base::SyncSocket> socket_for_create_callback_; |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 101 | |
| 102 | DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Impl); |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 103 | }; |
| 104 | |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 105 | } // namespace ppapi |
| 106 | } // namespace webkit |
[email protected] | 937df9511 | 2010-07-30 21:24:39 | [diff] [blame] | 107 | |
[email protected] | 0bd75368 | 2010-12-16 18:15:52 | [diff] [blame] | 108 | #endif // WEBKIT_PLUGINS_PPAPI_DEVICE_CONTEXT_AUDIO_H_ |