[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef PPAPI_PROXY_PPB_AUDIO_PROXY_H_ |
| 6 | #define PPAPI_PROXY_PPB_AUDIO_PROXY_H_ |
| 7 | |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 8 | #include <utility> |
| 9 | |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 10 | #include "base/basictypes.h" |
| 11 | #include "base/shared_memory.h" |
| 12 | #include "base/sync_socket.h" |
| 13 | #include "ipc/ipc_platform_file.h" |
| 14 | #include "ppapi/c/pp_instance.h" |
| 15 | #include "ppapi/c/pp_module.h" |
| 16 | #include "ppapi/c/pp_resource.h" |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 17 | #include "ppapi/c/ppb_audio.h" |
| 18 | #include "ppapi/c/ppb_audio_config.h" |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 19 | #include "ppapi/cpp/completion_callback.h" |
| 20 | #include "ppapi/proxy/interface_proxy.h" |
| 21 | #include "ppapi/proxy/proxy_non_thread_safe_ref_count.h" |
| 22 | |
[email protected] | b9a5984 | 2011-01-15 01:04:00 | [diff] [blame] | 23 | struct PPB_Audio; |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 24 | |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 25 | namespace ppapi { |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 26 | |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame^] | 27 | class HostResource; |
| 28 | |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 29 | namespace proxy { |
| 30 | |
| 31 | class PPB_Audio_Proxy : public InterfaceProxy { |
| 32 | public: |
| 33 | PPB_Audio_Proxy(Dispatcher* dispatcher, const void* target_interface); |
| 34 | virtual ~PPB_Audio_Proxy(); |
| 35 | |
[email protected] | 465faa2 | 2011-02-08 16:31:46 | [diff] [blame] | 36 | static const Info* GetInfo(); |
| 37 | |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 38 | // Creates an Audio object in the plugin process. |
| 39 | static PP_Resource CreateProxyResource(PP_Instance instance_id, |
| 40 | PP_Resource config_id, |
| 41 | PPB_Audio_Callback audio_callback, |
| 42 | void* user_data); |
| 43 | |
| 44 | |
[email protected] | b9a5984 | 2011-01-15 01:04:00 | [diff] [blame] | 45 | const PPB_Audio* ppb_audio_target() const { |
| 46 | return static_cast<const PPB_Audio*>(target_interface()); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | // InterfaceProxy implementation. |
[email protected] | a95986a8 | 2010-12-24 06:19:28 | [diff] [blame] | 50 | virtual bool OnMessageReceived(const IPC::Message& msg); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 51 | |
| 52 | private: |
| 53 | // Plugin->renderer message handlers. |
| 54 | void OnMsgCreate(PP_Instance instance_id, |
[email protected] | 55cdf605 | 2011-05-13 19:22:53 | [diff] [blame] | 55 | int32_t sample_rate, |
| 56 | uint32_t sample_frame_count, |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 57 | ppapi::HostResource* result); |
| 58 | void OnMsgStartOrStop(const ppapi::HostResource& audio_id, bool play); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 59 | |
| 60 | // Renderer->plugin message handlers. |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 61 | void OnMsgNotifyAudioStreamCreated(const ppapi::HostResource& audio_id, |
[email protected] | 2031aeb | 2011-01-28 20:01:16 | [diff] [blame] | 62 | int32_t result_code, |
| 63 | IPC::PlatformFileForTransit socket_handle, |
| 64 | base::SharedMemoryHandle handle, |
| 65 | uint32_t length); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 66 | |
[email protected] | f24448db | 2011-01-27 20:40:39 | [diff] [blame] | 67 | void AudioChannelConnected(int32_t result, |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 68 | const ppapi::HostResource& resource); |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 69 | |
| 70 | // In the renderer, this is called in response to a stream created message. |
| 71 | // It will retrieve the shared memory and socket handles and place them into |
| 72 | // the given out params. The return value is a PPAPI error code. |
| 73 | // |
| 74 | // The input arguments should be initialized to 0 or -1, depending on the |
| 75 | // platform's default invalid handle values. On error, some of these |
| 76 | // arguments may be written to, and others may be untouched, depending on |
| 77 | // where the error occurred. |
| 78 | int32_t GetAudioConnectedHandles( |
[email protected] | be0a84b | 2011-08-13 04:18:44 | [diff] [blame] | 79 | const ppapi::HostResource& resource, |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 80 | IPC::PlatformFileForTransit* foreign_socket_handle, |
| 81 | base::SharedMemoryHandle* foreign_shared_memory_handle, |
| 82 | uint32_t* shared_memory_length); |
| 83 | |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame^] | 84 | pp::CompletionCallbackFactory<PPB_Audio_Proxy, |
| 85 | ProxyNonThreadSafeRefCount> callback_factory_; |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 86 | |
| 87 | DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Proxy); |
| 88 | }; |
| 89 | |
| 90 | } // namespace proxy |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame^] | 91 | } // namespace ppapi |
[email protected] | 5d84d01 | 2010-12-02 17:17:21 | [diff] [blame] | 92 | |
| 93 | #endif // PPAPI_PROXY_PPB_AUDIO_PROXY_H_ |